Grid container added

World system started
Gui_Panel_Refactor
Joeyrp 4 years ago
parent bc8f6d253f
commit fff5c18842

@ -124,6 +124,9 @@ add_subdirectory(src/run_modes/tester)
# add run mode editor
add_subdirectory(src/run_modes/editor)
# add run mode editor
add_subdirectory(src/run_modes/game)
target_include_directories(${PROJECT_NAME}
PUBLIC "${PROJECT_BINARY_DIR}"
PUBLIC src
@ -151,7 +154,11 @@ target_link_directories(${PROJECT_NAME}
PRIVATE external/box2d/bin
)
target_link_libraries(${PROJECT_NAME} box2d glfw glad glm dearimgui utils assets lua_static pugixml freetype tester editor)
target_link_libraries(${PROJECT_NAME} box2d glfw glad glm dearimgui utils assets lua_static pugixml freetype tester game)
if (NOT NO_EDITOR)
target_link_libraries(${PROJECT_NAME} editor)
endif()
if(WIN32)
target_link_libraries(${PROJECT_NAME} opengl32.lib)

@ -58,6 +58,8 @@ Core:
Script Managment class:
☐ Manage LUA states
☐ Initialize new scripts
☐ Run given script with given state
☐ Add any generated errors to the Script object
Interface Class:
☐ Provide Methods that give access to the C++ code

@ -36,5 +36,6 @@ Editor:
☐ Flood Fill
Asset Viewer:
☐ Put files into a table with columns for the file Properties
Properties:

@ -243,8 +243,7 @@ namespace lunarium
}
// Initialize the Run Mode
result = mpRunMode->Initialize();
if (Failed(result))
if (Failed(mpRunMode->Initialize()))
{
Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR,
"Could not initialize the Run Mode: %s", result.Description.c_str());

@ -0,0 +1,20 @@
/******************************************************************************
* File - camera.h
* Author - Joey Pollack
* Date - 2022/01/25 (y/m/d)
* Mod Date - 2022/01/25 (y/m/d)
* Description - A 2D camera to be used with the World
******************************************************************************/
#ifndef CAMERA_H_
#define CAMERA_H_
namespace lunarium
{
class Camera
{
// TODO: class Camera
};
}
#endif // CAMERA_H_

@ -86,7 +86,7 @@ namespace lunarium
ImGui::Separator();
ImVec2 iconSize(mpNewFolderIcon->GetWidth(), mpNewFolderIcon->GetHeight());
if (ImGui::ImageButton((ImTextureID) mpNewFolderIcon->GetGLTextureID(), iconSize))
if (ImGui::ImageButton((ImTextureID) mpNewFolderIcon->GetGLTextureID64(), iconSize))
{
ImGui::OpenPopup("New Folder Name");
memset(mDirNameBuffer, 0, mBufferSize);
@ -105,7 +105,7 @@ namespace lunarium
ImGui::SameLine();
iconSize = ImVec2(mpUpFolderIcon->GetWidth(), mpUpFolderIcon->GetHeight());
if (ImGui::ImageButton((ImTextureID) mpUpFolderIcon->GetGLTextureID(), iconSize))
if (ImGui::ImageButton((ImTextureID) mpUpFolderIcon->GetGLTextureID64(), iconSize))
{
mCurrentDirectory = mCurrentDirectory.parent_path();
ReloadItems();
@ -207,7 +207,7 @@ namespace lunarium
if (std::filesystem::is_directory(mItemsInDir[i]))
{
ImVec2 size(mpFolderIcon->GetWidth(), mpFolderIcon->GetHeight());
ImTextureID id = (ImTextureID) mpFolderIcon->GetGLTextureID();
ImTextureID id = (ImTextureID) mpFolderIcon->GetGLTextureID64();
ImGui::Image(id, size);
ImGui::SameLine();
}

@ -71,6 +71,11 @@ namespace lunarium
return mGLTextureID;
}
unsigned long long Image::GetGLTextureID64() const
{
return (unsigned long long) mGLTextureID;
}
int Image::GetWidth() const
{
return mWidth;

@ -23,6 +23,7 @@ namespace lunarium
~Image();
unsigned int GetGLTextureID() const;
unsigned long long GetGLTextureID64() const;
int GetWidth() const;
int GetHeight() const;
ImageFormat GetFormat() const;

@ -0,0 +1,34 @@
/******************************************************************************
* File - script.h
* Author - Joey Pollack
* Date - 2022/01/18 (y/m/d)
* Mod Date - 2022/01/18 (y/m/d)
* Description - Holds data for a LUA script
******************************************************************************/
#ifndef SCRIPT_H_
#define SCRIPT_H_
#include "asset.h"
#include <string>
#include <vector>
namespace lunarium
{
class Script : public Asset
{
public:
void SetScript(const char* script);
const char* GetScript() const;
void AddError(std::string error);
const std::vector<std::string>* GetErrors() const;
private:
char* mpScript;
std::vector<std::string> mScriptErrors;
};
}
#endif // SCRIPT_H_

@ -0,0 +1,86 @@
/******************************************************************************
* File - grid.h
* Author - Joey Pollack
* Date - 2022/01/25 (y/m/d)
* Mod Date - 2022/01/25 (y/m/d)
* Description - A 2D fixed-size array of data. Size must be set when
* this container is created and can not be changed later.
******************************************************************************/
#ifndef GRID_H_
#define GRID_H_
#include "types.h"
namespace lunarium
{
template<typename T>
class Grid
{
public:
Grid(Sizei size);
T* operator[](Point2Di at);
T GetAt(Point2Di at);
void SetAt(Point2Di at, T value);
void SetAll(T value);
private:
struct Node
{
T Data;
};
Sizei mSize;
Node** mGrid;
};
////////////////////////////////////////////////////////////
// IMPLEMENTATION
////////////////////////////////////////////////////////////
template<typename T>
Grid<T>::Grid(Sizei size)
: mSize(size)
{
mGrid = new Node*[size.Width];
for (int i = 0; i < size.Width; i++)
{
mGrid[i] = new Node[size.Height];
}
}
template<typename T>
T* Grid<T>::operator[](Point2Di at)
{
return &mGrid[at.X][at.Y].Data;
}
template<typename T>
T Grid<T>::GetAt(Point2Di at)
{
return mGrid[at.X][at.Y].Data;
}
template<typename T>
void Grid<T>::SetAt(Point2Di at, T value)
{
mGrid[at.X][at.Y].Data = value;
}
template<typename T>
void Grid<T>::SetAll(T value)
{
for (int i = 0; i < mSize.Width; i++)
{
for (int j = 0; j < mSize.Height; j++)
{
mGrid[i][j].Data = value;
}
}
}
}
#endif GRID_H_

@ -50,10 +50,10 @@ namespace lunarium
return res.Type == ResultType::OK;
}
bool Failed(OpRes&& res)
{
return res.Type == ResultType::FAIL;
}
// bool Failed(OpRes&& res)
// {
// return res.Type == ResultType::FAIL;
// }
bool Failed(OpRes& res)
{

@ -42,7 +42,7 @@ namespace lunarium
bool IsOK(OpRes&& res);
bool IsOK(OpRes& res);
bool Failed(OpRes&& res);
//bool Failed(OpRes&& res);
bool Failed(OpRes& res);
}

@ -50,6 +50,14 @@ namespace lunarium
void Editor::OnTick(double delta)
{
for (auto iter = mPanels.begin(); iter != mPanels.end(); iter++)
{
if (iter->second->IsOpen())
{
iter->second->Update(delta);
}
}
HandleMenuEvents();
}

@ -60,33 +60,15 @@ namespace lunarium
float xPos = ImGui::GetCursorPosX();
float left = xPos;
// NOTE: Magic - file icon window size
float icon_width = 125.0f;
float icon_height = 80.0f;
// Display each file in a row
for(auto const& dir_entry: std::filesystem::directory_iterator{mSelectedDir})
{
if (!std::filesystem::is_directory(dir_entry))
{
ImGui::SetNextWindowSize(ImVec2(icon_width, icon_height));
ImGui::SetNextWindowPos(ImVec2(xPos, yPos));
// NOTE: BeginChild here is returning false for some reason
// ImGui::BeginChild("file", ImVec2(icon_width, icon_height), false, ImGuiWindowFlags_NoCollapse);
// TODO: Add file icon, make selection system
// TODO: Turn into a table with file properties as columns
ImGui::TextWrapped(dir_entry.path().filename().string().c_str());
// ImGui::EndChild();
// Move to the next space or down a line and back to the left side
xPos += icon_width + 10;
if (xPos > wind_size.x * 0.85f)
{
xPos = left;
yPos += icon_height + 10;
}
}
}
}

@ -46,6 +46,12 @@ namespace lunarium
h = mHeight;
}
void Panel::Update(float dt)
{
}
void Panel::UpdateMetaInfo()
{
ImVec2 p = ImGui::GetWindowPos();

@ -28,6 +28,7 @@ namespace lunarium
Panel(PanelType type, bool isOpen = false);
PanelType GetType() const;
virtual void Update(float dt);
virtual bool DoFrame() = 0;
void SetOpen(bool isOpen);
bool IsOpen();

@ -0,0 +1,13 @@
add_library(game world/world.cpp)
target_include_directories(game
PUBLIC "${PROJECT_BINARY_DIR}"
PUBLIC ./
PUBLIC ../../
PUBLIC ../../internal_libs
PUBLIC ../../../external/glm
PUBLIC ../../../external/glad/include
PUBLIC ../../../external/glfw/include
PUBLIC ../../../external/box2d/include
PUBLIC ../../../external/pugixml/src
)

@ -0,0 +1,20 @@
/******************************************************************************
* File - object.h
* Author - Joey Pollack
* Date - 2022/01/25 (y/m/d)
* Mod Date - 2022/01/25 (y/m/d)
* Description - The base object for all in-game objects
******************************************************************************/
#ifndef OBJECT_H_
#define OBJECT_H_
namespace lunarium
{
class GameObject
{
};
}
#endif // OBJECT_H_

@ -0,0 +1,101 @@
/******************************************************************************
* File - world.cpp
* Author - Joey Pollack
* Date - 2022/01/12 (y/m/d)
* Mod Date - 2022/01/20 (y/m/d)
* Description - Manages a game "world". A world is made up of regions which
* are subdivisions of the world. Each region contains: a set
* of images for the maps layers, a list of objects that spawn
* in this region and static collision data.
******************************************************************************/
#include "world.h"
#include <object/object.h>
#include <assets/types/script.h>
#include <assets/types/image.h>
#include <graphics/igraphics.h>
#include <graphics/camera.h>
namespace lunarium
{
World::World(Camera* pCam, Sizei region_size)
: mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mRegions(region_size)
{
mActiveRegion = { 0, 0 };
mRegions.SetAll(nullptr);
}
void World::OnLoad()
{
// TODO: Call OnLoad in the world script and on each region script
}
void World::OnUnload()
{
// TODO: Call OnUnLoad in the world script and on each region script
}
void World::Update(float dt)
{
// TODO: Call Update in the world script and on each region script
}
void World::Render(Graphics* pGraphics) const
{
// TODO: Call Render in the world script and on each region
}
void World::RenderToTexture(Graphics* pGraphics, Image* pTexture) const
{
}
// void World::AddGameObject(GameObject* pObj)
// {
// }
// bool World::RemoveGameObject(GameObject* pObj)
// {
// }
OpRes World::SetRegion(Region* region, Point2Di at)
{
if (*mRegions[at] != nullptr)
{
return OpRes::Fail("World::SetRegion failed because a region already exists at (%n, %n)", at.X, at.Y);
}
*mRegions[at] = region;
return OpRes::OK();
}
World::Region* World::GetRegion(Point2Di at)
{
return *mRegions[at];
}
bool World::RemoveRegion(Point2Di at)
{
if (*mRegions[at] == nullptr)
{
return false;
}
*mRegions[at] = nullptr;
return true;
}
void World::SetWorldScript(Script* pScript)
{
mpWorldScript = pScript;
}
Script* World::GetWorldScript()
{
return mpWorldScript;
}
}

@ -2,7 +2,7 @@
* File - world.h
* Author - Joey Pollack
* Date - 2022/01/12 (y/m/d)
* Mod Date - 2022/01/12 (y/m/d)
* Mod Date - 2022/01/20 (y/m/d)
* Description - Manages a game "world". A world is made up of regions which
* are subdivisions of the world. Each region contains: a set
* of images for the maps layers, a list of objects that spawn
@ -15,6 +15,8 @@
#include <vector>
#include <map>
#include <utils/types.h>
#include <utils/opRes.h>
#include <utils/grid.h>
namespace lunarium
{
@ -37,18 +39,35 @@ namespace lunarium
public: // INTERFACE
World(Camera* pCam, Sizei region_size);
void OnLoad();
void OnUnload();
void Update(float dt);
void Render(Graphics* pGraphics);
void RenderToTexture(Graphics* pGraphics, Image* pTexture);
void Render(Graphics* pGraphics) const;
void RenderToTexture(Graphics* pGraphics, Image* pTexture) const;
// Game objects should probably be added/removed from the regions directly
// No World-wide game objects
// Unless I can think of a good reason why they would be useful
// void AddGameObject(GameObject* pObj);
// bool RemoveGameObject(GameObject* pObj);
OpRes SetRegion(Region* region, Point2Di at);
Region* GetRegion(Point2Di at);
bool RemoveRegion(Point2Di at);
void SetWorldScript(Script* pScript);
Script* GetWorldScript();
private:
Camera* mpCamera;
std::vector<GameObject*> mWorldObjects;
std::vector<Script*> mWorldScripts; // Maybe just want 1 script?
Script* mpWorldScript;
Sizei mRegionSize;
std::map<Point2Di, Region*> mRegions;
Grid<Region*> mRegions;
Point2Di mActiveRegion;
};

@ -17,10 +17,16 @@
namespace lunarium
{
SimpleRenderScene::SimpleRenderScene(uint32_t logCat)
: BaseScene(logCat)
: BaseScene(logCat), mGrid({10, 10})
{
}
SimpleRenderScene::~SimpleRenderScene()
{
delete *mGrid[{5, 5}];
}
void SimpleRenderScene::OnLoad()
{
Logger::Log(mLogCat, LogLevel::INFO, "Running Simple Render Test Scene");
@ -33,6 +39,9 @@ namespace lunarium
angle = 0.0f;
box_angle = 0.0f;
// Setup the grid container
*mGrid[{5, 5}] = new GridTestObj {5, "This is grid space 5, 5"};
}
void SimpleRenderScene::OnTick(double delta)
@ -108,5 +117,7 @@ namespace lunarium
g->DrawBox(Rectangle::MakeFromTopLeft(0.0f, 0.0f, (float)mImageSize.Width, (float)mImageSize.Height), Color(0.0f, 0.0f, 0.0f, 1.0f), 1.0f, angle);
g->DrawBox(Rectangle(400, 400, 128.0f, 128.0f), Color(0.0f, 1.0f, 0.0f, 1.0f), 2.0f, box_angle);
g->DrawString((*mGrid[{5, 5,}])->msg.c_str(), Rectangle::MakeFromTopLeft(200.0f, 500.0f, 500.0f, 200.0f), Color(0.5f, 0.0f, 0.75f, 1.0f));
}
}

@ -11,6 +11,8 @@
#include "baseScene.h"
#include <utils/types.h>
#include <utils/grid.h>
#include <string>
namespace lunarium
{
@ -19,6 +21,7 @@ namespace lunarium
{
public:
SimpleRenderScene(uint32_t logCat);
~SimpleRenderScene();
virtual void OnLoad();
virtual void OnTick(double delta);
virtual void OnRender(IGraphics* g);
@ -30,6 +33,14 @@ namespace lunarium
Image* mpRenderedImage;
float angle;
float box_angle;
struct GridTestObj
{
int X;
std::string msg;
};
Grid<GridTestObj*> mGrid;
};
}

Loading…
Cancel
Save