diff --git a/CMakeLists.txt b/CMakeLists.txt index 399dd86..43e972c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/docs/core.todo b/docs/core.todo index d2da579..1a7c853 100644 --- a/docs/core.todo +++ b/docs/core.todo @@ -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 diff --git a/docs/editor.todo b/docs/editor.todo index dae5b32..084a188 100644 --- a/docs/editor.todo +++ b/docs/editor.todo @@ -36,5 +36,6 @@ Editor: ☐ Flood Fill Asset Viewer: + ☐ Put files into a table with columns for the file Properties Properties: \ No newline at end of file diff --git a/src/core/core.cpp b/src/core/core.cpp index ba7779e..4576210 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -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()); diff --git a/src/graphics/camera.h b/src/graphics/camera.h new file mode 100644 index 0000000..dd60067 --- /dev/null +++ b/src/graphics/camera.h @@ -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_ \ No newline at end of file diff --git a/src/gui/fileBrowser.cpp b/src/gui/fileBrowser.cpp index 13f4081..2663794 100644 --- a/src/gui/fileBrowser.cpp +++ b/src/gui/fileBrowser.cpp @@ -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(); } diff --git a/src/internal_libs/assets/types/image.cpp b/src/internal_libs/assets/types/image.cpp index f3b44fe..5e2429e 100644 --- a/src/internal_libs/assets/types/image.cpp +++ b/src/internal_libs/assets/types/image.cpp @@ -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; diff --git a/src/internal_libs/assets/types/image.h b/src/internal_libs/assets/types/image.h index 4e69307..6f2839f 100644 --- a/src/internal_libs/assets/types/image.h +++ b/src/internal_libs/assets/types/image.h @@ -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; diff --git a/src/internal_libs/assets/types/script.h b/src/internal_libs/assets/types/script.h new file mode 100644 index 0000000..be71dac --- /dev/null +++ b/src/internal_libs/assets/types/script.h @@ -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 +#include + +namespace lunarium +{ + class Script : public Asset + { + public: + void SetScript(const char* script); + const char* GetScript() const; + + void AddError(std::string error); + const std::vector* GetErrors() const; + private: + + char* mpScript; + std::vector mScriptErrors; + }; +} + +#endif // SCRIPT_H_ \ No newline at end of file diff --git a/src/internal_libs/utils/grid.h b/src/internal_libs/utils/grid.h new file mode 100644 index 0000000..48136ca --- /dev/null +++ b/src/internal_libs/utils/grid.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 + 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 + Grid::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 + T* Grid::operator[](Point2Di at) + { + return &mGrid[at.X][at.Y].Data; + } + + template + T Grid::GetAt(Point2Di at) + { + return mGrid[at.X][at.Y].Data; + } + + template + void Grid::SetAt(Point2Di at, T value) + { + mGrid[at.X][at.Y].Data = value; + } + + template + void Grid::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_ \ No newline at end of file diff --git a/src/internal_libs/utils/opRes.cpp b/src/internal_libs/utils/opRes.cpp index 312c025..f42c3f1 100644 --- a/src/internal_libs/utils/opRes.cpp +++ b/src/internal_libs/utils/opRes.cpp @@ -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) { diff --git a/src/internal_libs/utils/opRes.h b/src/internal_libs/utils/opRes.h index e4dbaa0..324e841 100644 --- a/src/internal_libs/utils/opRes.h +++ b/src/internal_libs/utils/opRes.h @@ -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); } diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index 02a4f36..0216287 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -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(); } diff --git a/src/run_modes/editor/panels/assetBrowser.cpp b/src/run_modes/editor/panels/assetBrowser.cpp index ede42b3..8d1b4e4 100644 --- a/src/run_modes/editor/panels/assetBrowser.cpp +++ b/src/run_modes/editor/panels/assetBrowser.cpp @@ -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; - } } } } diff --git a/src/run_modes/editor/panels/iPanel.cpp b/src/run_modes/editor/panels/iPanel.cpp index 6f74a24..db205d1 100644 --- a/src/run_modes/editor/panels/iPanel.cpp +++ b/src/run_modes/editor/panels/iPanel.cpp @@ -46,6 +46,12 @@ namespace lunarium h = mHeight; } + + void Panel::Update(float dt) + { + + } + void Panel::UpdateMetaInfo() { ImVec2 p = ImGui::GetWindowPos(); diff --git a/src/run_modes/editor/panels/iPanel.h b/src/run_modes/editor/panels/iPanel.h index cbe821d..634b653 100644 --- a/src/run_modes/editor/panels/iPanel.h +++ b/src/run_modes/editor/panels/iPanel.h @@ -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(); diff --git a/src/run_modes/game/CMakeLists.txt b/src/run_modes/game/CMakeLists.txt new file mode 100644 index 0000000..31d5e0a --- /dev/null +++ b/src/run_modes/game/CMakeLists.txt @@ -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 +) \ No newline at end of file diff --git a/src/run_modes/game/object/object.h b/src/run_modes/game/object/object.h new file mode 100644 index 0000000..c5d0af9 --- /dev/null +++ b/src/run_modes/game/object/object.h @@ -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_ \ No newline at end of file diff --git a/src/run_modes/game/world/world.cpp b/src/run_modes/game/world/world.cpp new file mode 100644 index 0000000..c30a834 --- /dev/null +++ b/src/run_modes/game/world/world.cpp @@ -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 +#include +#include +#include +#include + +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; + } + +} \ No newline at end of file diff --git a/src/game/world/world.h b/src/run_modes/game/world/world.h similarity index 61% rename from src/game/world/world.h rename to src/run_modes/game/world/world.h index 4fe4692..5d84fed 100644 --- a/src/game/world/world.h +++ b/src/run_modes/game/world/world.h @@ -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 #include #include +#include +#include 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 mWorldObjects; - std::vector mWorldScripts; // Maybe just want 1 script? + Script* mpWorldScript; Sizei mRegionSize; - std::map mRegions; + Grid mRegions; + Point2Di mActiveRegion; }; diff --git a/src/run_modes/tester/scenes/simpleRenderScene.cpp b/src/run_modes/tester/scenes/simpleRenderScene.cpp index 414e6a3..8dc37ad 100644 --- a/src/run_modes/tester/scenes/simpleRenderScene.cpp +++ b/src/run_modes/tester/scenes/simpleRenderScene.cpp @@ -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)); } } \ No newline at end of file diff --git a/src/run_modes/tester/scenes/simpleRenderScene.h b/src/run_modes/tester/scenes/simpleRenderScene.h index 0dd707e..140e0be 100644 --- a/src/run_modes/tester/scenes/simpleRenderScene.h +++ b/src/run_modes/tester/scenes/simpleRenderScene.h @@ -11,6 +11,8 @@ #include "baseScene.h" #include +#include +#include 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 mGrid; }; }