diff --git a/CMakeLists.txt b/CMakeLists.txt index e2d5256..0202af2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(LUNARIUM_SRC "src/core/core.cpp" "src/core/state.cpp" "src/core/version.cpp" +"src/core/types.cpp" "src/core/core_console.cpp" "src/core/iRunMode.cpp" "src/window/window.cpp" diff --git a/src/core/core.cpp b/src/core/core.cpp index 6a9de6a..63c0c60 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -342,6 +342,11 @@ namespace lunarium con->SetOpen(!con->IsOpen()); } + if (Core::Input().IsKeyPressed(KeyCode::F3, true)) + { + mbShowGuiDemo = !mbShowGuiDemo; + } + // RENDER if (mbMidTextureRender) @@ -360,6 +365,11 @@ namespace lunarium con->DoFrame(); } + if (mbShowGuiDemo) + { + mGUI.ShowDemoWindow(mbShowGuiDemo); + } + // Run mode mpRunMode->OnRender(mpGraphics); diff --git a/src/internal_libs/utils/types.cpp b/src/core/types.cpp similarity index 100% rename from src/internal_libs/utils/types.cpp rename to src/core/types.cpp diff --git a/src/internal_libs/utils/types.h b/src/core/types.h similarity index 94% rename from src/internal_libs/utils/types.h rename to src/core/types.h index b1a6c71..c013f57 100644 --- a/src/internal_libs/utils/types.h +++ b/src/core/types.h @@ -19,15 +19,15 @@ namespace lunarium // POINT //////////////////////////////////////////////////////////// template - struct Point2D + struct Vec2 { T X; T Y; }; - typedef Point2D Point2Di; - typedef Point2D Point2Du; - typedef Point2D Point2Df; + typedef Vec2 Vec2i; + typedef Vec2 Vec2u; + typedef Vec2 Vec2f; /////////////////////////////////////////////////////// // SIZE diff --git a/src/graphics/igraphics.h b/src/graphics/graphics.h similarity index 95% rename from src/graphics/igraphics.h rename to src/graphics/graphics.h index b7509a5..d22dd7c 100644 --- a/src/graphics/igraphics.h +++ b/src/graphics/graphics.h @@ -1,5 +1,5 @@ /****************************************************************************** -* File - IGraphics.h +* File - graphics.h * Author - Joey Pollack * Date - 2021/09/02 (y/m/d) * Mod Date - 2021/09/02 (y/m/d) @@ -10,7 +10,7 @@ #ifndef IGRAPHICS_H_ #define IGRAPHICS_H_ -#include +#include #include namespace lunarium @@ -48,6 +48,7 @@ namespace lunarium virtual Color GetClearColor() const = 0; virtual int CreateRenderTexture(int width, int height, int channels) = 0; + virtual void DestroyRenderTexture(int texture) = 0; // Draw Methods virtual void DrawFilledPolygon(float* pVerts, int numVerts, Color color, glm::vec2 position, float angle = 0.0f) = 0; diff --git a/src/graphics/opengl/glGraphics.cpp b/src/graphics/opengl/glGraphics.cpp index 62309e5..8878459 100644 --- a/src/graphics/opengl/glGraphics.cpp +++ b/src/graphics/opengl/glGraphics.cpp @@ -107,7 +107,7 @@ namespace lunarium // Clean up frame buffers for (auto iter = mFrameBuffers.begin(); iter != mFrameBuffers.end(); iter++) { - delete iter->second; + DestroyRenderTexture(iter->first); } mFrameBuffers.clear(); @@ -262,6 +262,20 @@ namespace lunarium return next_id; } + void OglGraphics::DestroyRenderTexture(int texture) + { + if (mFrameBuffers.find(texture) == mFrameBuffers.end()) + { + return; + } + + FrameBuffer* rm = mFrameBuffers[texture]; + mFrameBuffers.erase(texture); + + glDeleteFramebuffers(1, &rm->FBO); + delete rm; + } + // Draw Methods void OglGraphics::DrawLine(glm::vec2 point1, glm::vec2 point2, Color color, float lineWidth, float angle) { diff --git a/src/graphics/opengl/glGraphics.h b/src/graphics/opengl/glGraphics.h index b14b959..113a3d1 100644 --- a/src/graphics/opengl/glGraphics.h +++ b/src/graphics/opengl/glGraphics.h @@ -9,7 +9,7 @@ #ifndef OGLGRAPHICS_H_ #define OGLGRAPHICS_H_ -#include "../igraphics.h" +#include "../graphics.h" #include #include "glShader.h" #include "glText.h" @@ -44,6 +44,7 @@ namespace lunarium virtual Color GetClearColor() const; virtual int CreateRenderTexture(int width, int height, int channels); + virtual void DestroyRenderTexture(int texture); // Draw Methods virtual void DrawFilledPolygon(float* pVerts, int numVerts, Color color, glm::vec2 position, float angle = 0.0f); diff --git a/src/graphics/opengl/glText.h b/src/graphics/opengl/glText.h index f300265..5a142b4 100644 --- a/src/graphics/opengl/glText.h +++ b/src/graphics/opengl/glText.h @@ -16,7 +16,7 @@ #include #include "glShader.h" #include -#include +#include #include struct FT_LibraryRec_; diff --git a/src/internal_data/dataManager.cpp b/src/internal_data/dataManager.cpp index 35d4af5..2b08850 100644 --- a/src/internal_data/dataManager.cpp +++ b/src/internal_data/dataManager.cpp @@ -10,7 +10,7 @@ #include "dataManager.h" #include -#include +#include #include // ASSETS diff --git a/src/internal_libs/assets/loaders/assetIndex.h b/src/internal_libs/assets/loaders/assetIndex.h index af22cb0..427c4bf 100644 --- a/src/internal_libs/assets/loaders/assetIndex.h +++ b/src/internal_libs/assets/loaders/assetIndex.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include namespace lunarium { diff --git a/src/internal_libs/gui/file_browser.cpp b/src/internal_libs/gui/file_browser.cpp index 262a05c..bd5d4fe 100644 --- a/src/internal_libs/gui/file_browser.cpp +++ b/src/internal_libs/gui/file_browser.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include "dearimgui/imgui.h" diff --git a/src/internal_libs/gui/panel.h b/src/internal_libs/gui/panel.h index d1f1d5c..b8df3a6 100644 --- a/src/internal_libs/gui/panel.h +++ b/src/internal_libs/gui/panel.h @@ -50,7 +50,6 @@ namespace gui protected: void UpdateMetaInfo(); }; -} -} +}} #endif // PANEL_H_ \ No newline at end of file diff --git a/src/internal_libs/utils/CMakeLists.txt b/src/internal_libs/utils/CMakeLists.txt index 7bb1b3b..07459bb 100644 --- a/src/internal_libs/utils/CMakeLists.txt +++ b/src/internal_libs/utils/CMakeLists.txt @@ -1,8 +1,9 @@ add_library(utils stb/stb_image_write.cpp stb/stb_image.cpp args.cpp binaryFileBuffer.cpp frameCounter.cpp - helpers.cpp highResTimer.cpp logger.cpp opRes.cpp types.cpp) + helpers.cpp highResTimer.cpp logger.cpp opRes.cpp) target_include_directories(utils PUBLIC "${PROJECT_BINARY_DIR}" + PUBLIC ../../ PUBLIC ../../../external/glm PUBLIC ../../../external/box2d/include ) diff --git a/src/internal_libs/utils/grid.h b/src/internal_libs/utils/grid.h index 279fe07..c3ae810 100644 --- a/src/internal_libs/utils/grid.h +++ b/src/internal_libs/utils/grid.h @@ -12,7 +12,7 @@ #ifndef GRID_H_ #define GRID_H_ -#include "types.h" +#include namespace lunarium { @@ -22,9 +22,9 @@ namespace lunarium public: Grid(Sizei size); - T* operator[](Point2Di at); - T GetAt(Point2Di at); - void SetAt(Point2Di at, T value); + T* operator[](Vec2i at); + T GetAt(Vec2i at); + void SetAt(Vec2i at, T value); void SetAll(T value); @@ -60,19 +60,19 @@ namespace lunarium } template - T* Grid::operator[](Point2Di at) + T* Grid::operator[](Vec2i at) { return &mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data; } template - T Grid::GetAt(Point2Di at) + T Grid::GetAt(Vec2i at) { return mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data; } template - void Grid::SetAt(Point2Di at, T value) + void Grid::SetAt(Vec2i at, T value) { mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data = value; } diff --git a/src/internal_libs/utils/helpers.h b/src/internal_libs/utils/helpers.h index 19f58dc..fa84b6e 100644 --- a/src/internal_libs/utils/helpers.h +++ b/src/internal_libs/utils/helpers.h @@ -9,7 +9,7 @@ #ifndef HELPERS_H_ #define HELPERS_H_ -#include "types.h" +#include #include #include #include diff --git a/src/run_modes/editor/CMakeLists.txt b/src/run_modes/editor/CMakeLists.txt index 8611309..fe8366c 100644 --- a/src/run_modes/editor/CMakeLists.txt +++ b/src/run_modes/editor/CMakeLists.txt @@ -10,6 +10,8 @@ set(EDITOR_SRC "panels/worldView.cpp" "panels/propertiesView.cpp" "tools/map_editor/map_editor.cpp" +"tools/map_editor/tile_map.cpp" +"tools/map_editor/panels/map_canvas.cpp" ) add_library(editor ${EDITOR_SRC}) diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index 94c3701..71c1d66 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -35,7 +35,7 @@ namespace editor { Editor::Editor() - : mLogCat(-1), mpFileBrowser(nullptr), mpPath(nullptr), mDoNewProject(false), mDoOpenProject(false), + : mLogCat(-1), mpPath(nullptr), mDoNewProject(false), mDoOpenProject(false), mDoSaveProject(false), mDoSaveAs(false), mNextWindowID(0), mpMapEditor(nullptr) { } @@ -56,10 +56,10 @@ namespace editor return res; } - mPanelManager.AddPanel(gui::PanelType::PT_ASSET_BROWSER, new AssetBrowser("")).LogIfFailed(mLogCat); - mPanelManager.AddPanel(gui::PanelType::PT_WORLD_TREE, new WorldTree()).LogIfFailed(mLogCat); - mPanelManager.AddPanel(gui::PanelType::PT_WORLD_VIEW, new WorldView()).LogIfFailed(mLogCat); - mPanelManager.AddPanel(gui::PanelType::PT_PROPERTIES_VIEW, new PropertiesView()).LogIfFailed(mLogCat); + mPanelManager.AddPanel(new AssetBrowser("")).LogIfFailed(mLogCat); + mPanelManager.AddPanel(new WorldTree()).LogIfFailed(mLogCat); + mPanelManager.AddPanel(new WorldView()).LogIfFailed(mLogCat); + mPanelManager.AddPanel(new PropertiesView()).LogIfFailed(mLogCat); return OpRes::OK(); } @@ -253,8 +253,16 @@ namespace editor if (mDoSaveProject) { - - mDoSaveProject = false; + if (!mProject.IsLoaded()) + { + mDoSaveAs = true; + mDoSaveProject = false; + } + else + { + //mProject.SaveProject(); + mDoSaveProject = false; + } } if (mDoSaveAs) @@ -313,10 +321,10 @@ namespace editor } ImGui::Separator(); - HanelOpenPanel("Asset Browser", gui::PanelType::PT_ASSET_BROWSER); - HanelOpenPanel("World Tree", gui::PanelType::PT_WORLD_TREE); - HanelOpenPanel("World View", gui::PanelType::PT_WORLD_VIEW); - HanelOpenPanel("Properties", gui::PanelType::PT_PROPERTIES_VIEW); + HandleOpenPanel("Asset Browser", gui::PanelType::PT_ASSET_BROWSER); + HandleOpenPanel("World Tree", gui::PanelType::PT_WORLD_TREE); + HandleOpenPanel("World View", gui::PanelType::PT_WORLD_VIEW); + HandleOpenPanel("Properties", gui::PanelType::PT_PROPERTIES_VIEW); ImGui::EndMenu(); } @@ -351,7 +359,7 @@ namespace editor } - void Editor::HanelOpenPanel(const char* name, gui::PanelType type) + void Editor::HandleOpenPanel(const char* name, gui::PanelType type) { if (ImGui::MenuItem(name)) { diff --git a/src/run_modes/editor/editor.h b/src/run_modes/editor/editor.h index 52d51bd..2e4b0b5 100644 --- a/src/run_modes/editor/editor.h +++ b/src/run_modes/editor/editor.h @@ -82,7 +82,7 @@ namespace lunarium void DestroyTools(); void HandleMenuEvents(); - void HanelOpenPanel(const char* name, gui::PanelType type); + void HandleOpenPanel(const char* name, gui::PanelType type); }; } diff --git a/src/run_modes/editor/panel_manager.cpp b/src/run_modes/editor/panel_manager.cpp index 019f4f0..6e7f1db 100644 --- a/src/run_modes/editor/panel_manager.cpp +++ b/src/run_modes/editor/panel_manager.cpp @@ -52,14 +52,14 @@ namespace lunarium { namespace editor } - OpRes PanelManager::AddPanel(gui::PanelType type, gui::Panel* panel) + OpRes PanelManager::AddPanel(gui::Panel* panel) { - if (mPanels.find(type) != mPanels.end()) + if (mPanels.find(panel->GetType()) != mPanels.end()) { return OpRes::Fail("Cannot add panel - panel already exists. Panel Name: %s", panel->GetName()); } - mPanels[type] = panel; + mPanels[panel->GetType()] = panel; return OpRes::OK(); } diff --git a/src/run_modes/editor/panel_manager.h b/src/run_modes/editor/panel_manager.h index b18f1e3..2493394 100644 --- a/src/run_modes/editor/panel_manager.h +++ b/src/run_modes/editor/panel_manager.h @@ -30,7 +30,7 @@ namespace editor void Shutdown(); // Panel interface - OpRes AddPanel(gui::PanelType type, gui::Panel* panel); + OpRes AddPanel(gui::Panel* panel); void OpenPanel(gui::PanelType type); void ClosePanel(gui::PanelType type); bool IsOpen(gui::PanelType type); diff --git a/src/run_modes/editor/project/project.cpp b/src/run_modes/editor/project/project.cpp index 46104c2..3c621ee 100644 --- a/src/run_modes/editor/project/project.cpp +++ b/src/run_modes/editor/project/project.cpp @@ -79,6 +79,11 @@ namespace lunarium mIsLoaded = false; } + void Project::SaveProject() + { + // HACK LOGGING lol + OpRes::Fail("Project::SaveProject not implemented yet").LogIfFailed(0); + } const std::string& Project::GetName() const { diff --git a/src/run_modes/editor/project/project.h b/src/run_modes/editor/project/project.h index cf56015..4347410 100644 --- a/src/run_modes/editor/project/project.h +++ b/src/run_modes/editor/project/project.h @@ -29,6 +29,7 @@ namespace lunarium /// location should be the full path including the project file OpRes LoadProject(std::filesystem::path location); void UnloadCurrentProject(); + void SaveProject(); bool IsLoaded() const; const std::string& GetName() const; diff --git a/src/run_modes/editor/tools/map_editor/map_editor.cpp b/src/run_modes/editor/tools/map_editor/map_editor.cpp index d90dbab..7c49649 100644 --- a/src/run_modes/editor/tools/map_editor/map_editor.cpp +++ b/src/run_modes/editor/tools/map_editor/map_editor.cpp @@ -8,10 +8,15 @@ #include "map_editor.h" +#include +#include #include #include #include +// Panels +#include "panels/map_canvas.h" + namespace lunarium { namespace editor { MapEditor::MapEditor() @@ -34,6 +39,8 @@ namespace lunarium { namespace editor return OpRes::Fail("Could not initialize the panel manager!"); } + mPanelManager.AddPanel(new MapCanvas(this)).LogIfFailed(mpEditor->GetLogCat()); + Open(); return OpRes::OK(); @@ -47,6 +54,8 @@ namespace lunarium { namespace editor void MapEditor::OnTick(double delta) { mPanelManager.OnTick(delta); + + ((MapCanvas*)mPanelManager.GetPanel(gui::PanelType::PT_MAP_CANVAS))->Render(&Core::Graphics()); } bool MapEditor::OnRender(lunarium::IGraphics* g) @@ -68,9 +77,11 @@ namespace lunarium { namespace editor } DoMenu(); - mPanelManager.RenderPanels(); + mPanelManager.MakeDockSpaces(); ImGui::End(); + + mPanelManager.RenderPanels(); return true; } @@ -133,6 +144,22 @@ namespace lunarium { namespace editor ImGui::EndMenu(); } + if (ImGui::BeginMenu("Windows")) + { + if (ImGui::MenuItem("Reset Window Docking")) + { + mPanelManager.ResetDocking(); + } + ImGui::Separator(); + + // HanelOpenPanel("Asset Browser", gui::PanelType::PT_ASSET_BROWSER); + // HanelOpenPanel("World Tree", gui::PanelType::PT_WORLD_TREE); + // HanelOpenPanel("World View", gui::PanelType::PT_WORLD_VIEW); + // HanelOpenPanel("Properties", gui::PanelType::PT_PROPERTIES_VIEW); + + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); } diff --git a/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp b/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp new file mode 100644 index 0000000..a009b54 --- /dev/null +++ b/src/run_modes/editor/tools/map_editor/panels/map_canvas.cpp @@ -0,0 +1,113 @@ +/****************************************************************************** +* File - map_canvas.cpp +* Author - Joey Pollack +* Date - 2022/02/14 (y/m/d) +* Mod Date - 2022/02/14 (y/m/d) +* Description - the canvas panel for painting map tiles +******************************************************************************/ + +#include "map_canvas.h" +#include "../map_editor.h" +#include +#include +#include +#include + +#include +#include + +namespace lunarium { namespace editor +{ + MapCanvas::MapCanvas(MapEditor* editor) + : Panel(gui::PanelType::PT_MAP_CANVAS, "Map Canvas", gui::PanelDockZone::DDZ_CENTER, true), + mpMapEditor(editor), mpCanvasImage(nullptr), mMap(nullptr), mSelectedTile({-1, -1}) + { + + } + + void MapCanvas::Update(float delta) + { + + } + + bool MapCanvas::DoFrame() + { + if (!mIsOpen) + return false; + + if (!ImGui::Begin(GetName(), &mIsOpen)) + { + ImGui::End(); + return false; + } + + ImVec2 pos = ImGui::GetWindowPos(); + ImVec2 size = ImGui::GetWindowSize(); + + // Adjust for the tab bar + pos.y += ImGui::GetFrameHeight(); + size.y -= ImGui::GetFrameHeight(); + ImGuiIO& io = ImGui::GetIO(); + float x = io.MousePos.x - pos.x; + float y = io.MousePos.y - pos.y; + + + + std::ostringstream oss; + oss << "Mouse Position on Panel: "; + if (x < 0.0f || y < 0.0f || x > size.x || y > size.y) + { + oss << "OUTSIDE PANEL"; + } + else + { + oss << "(" << x << ", " << y << ")"; + } + + oss << "\nFrameHeight: " << ImGui::GetFrameHeight(); + oss <<"\nFrameHeightWithSpacing: " << ImGui::GetFrameHeightWithSpacing(); + mMouseStatusInfo = oss.str(); + + //ImGui::Text(mMouseStatusInfo.c_str()); + if (mpCanvasImage) + { + ImGui::Image((ImTextureID)mpCanvasImage->GetGLTextureID64(), ImVec2(mpCanvasImage->GetWidth(), mpCanvasImage->GetHeight())); + } + + ImGui::End(); + return mIsOpen; + } + + void MapCanvas::Render(lunarium::IGraphics* g) + { + // Render tile map + mMap->Render(g); + + // Render grid if it's turned on + } + + + void MapCanvas::SetTileMap(TileMap* pMap) + { + mMap = pMap; + } + + void MapCanvas::SetCanvasImage(Image* image) + { + mpCanvasImage = image; + } + + void MapCanvas::SetSelectedTile(TileRef tile) + { + mSelectedTile = tile; + } + + TileRef MapCanvas::GetSelectedTile() const + { + return mSelectedTile; + } + + + + +}} \ No newline at end of file diff --git a/src/run_modes/editor/tools/map_editor/panels/map_canvas.h b/src/run_modes/editor/tools/map_editor/panels/map_canvas.h new file mode 100644 index 0000000..c7a5068 --- /dev/null +++ b/src/run_modes/editor/tools/map_editor/panels/map_canvas.h @@ -0,0 +1,49 @@ +/****************************************************************************** +* File - map_canvas.h +* Author - Joey Pollack +* Date - 2022/02/14 (y/m/d) +* Mod Date - 2022/02/14 (y/m/d) +* Description - the canvas panel for painting map tiles +******************************************************************************/ + +#ifndef MAP_CANVAS_H_ +#define MAP_CANVAS_H_ + +#include +#include "../tile_map.h" +#include +#include + +namespace lunarium { class Image; class IGraphics; } + +namespace lunarium { namespace editor +{ + class MapEditor; + + class MapCanvas : public gui::Panel + { + public: + MapCanvas(MapEditor* editor); + void Update(float delta); + bool DoFrame(); + void Render(lunarium::IGraphics* g); + + void SetTileMap(TileMap* pMap); + void SetCanvasImage(Image* image); + + void SetSelectedTile(TileRef tile); + TileRef GetSelectedTile() const; + + private: + MapEditor* mpMapEditor; + std::string mMouseStatusInfo; + Image* mpCanvasImage; + TileMap* mMap; + TileRef mSelectedTile; + + private: + + }; +}} + +#endif // MAP_CANVAS_H_ \ No newline at end of file diff --git a/src/run_modes/editor/tools/map_editor/tile_map.cpp b/src/run_modes/editor/tools/map_editor/tile_map.cpp new file mode 100644 index 0000000..773fa01 --- /dev/null +++ b/src/run_modes/editor/tools/map_editor/tile_map.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** +* File - tile_map.h +* Author - Joey Pollack +* Date - 2022/02/15 (y/m/d) +* Mod Date - 2022/02/15 (y/m/d) +* Description - Contains a single tile map +******************************************************************************/ + +#include "tile_map.h" +#include +#include + +namespace lunarium { namespace editor +{ + void TileMap::ClearMap() + { + for(int i = 0; i < mSizeInTiles.Width; i++) + { + for (int j = 0; j < mSizeInTiles.Height; j++) + { + mpMap[i][j] = { -1, -1 }; + } + } + } + + void TileMap::ResizeMap(Sizei size) + { + TileRef** new_map = new TileRef*[size.Width]; + for(int i = 0; i < size.Width; i++) + { + new_map[i] = new TileRef[size.Height]; + } + + int smaller_width = mSizeInTiles.Width < size.Width ? mSizeInTiles.Width : size.Width; + int smaller_height = mSizeInTiles.Height < size.Height ? mSizeInTiles.Height : size.Height; + + for(int i = 0; i < smaller_width; i++) + { + for (int j = 0; j < smaller_height; j++) + { + new_map[i][j] = mpMap[i][j]; + } + } + + for(int i = 0; i < mSizeInTiles.Width; i++) + { + delete[] mpMap[i]; + } + + delete[] mpMap; + mSizeInTiles = size; + mpMap = new_map; + } + + + void TileMap::Render(lunarium::IGraphics* g) + { + + } +}} diff --git a/src/run_modes/editor/tools/map_editor/tile_map.h b/src/run_modes/editor/tools/map_editor/tile_map.h new file mode 100644 index 0000000..91baec7 --- /dev/null +++ b/src/run_modes/editor/tools/map_editor/tile_map.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* File - tile_map.h +* Author - Joey Pollack +* Date - 2022/02/15 (y/m/d) +* Mod Date - 2022/02/15 (y/m/d) +* Description - Contains a single tile map +******************************************************************************/ + +#ifndef TILE_MAP_H_ +#define TILE_MAP_H_ + +#include + +namespace lunarium { class IGraphics; } + +namespace lunarium { namespace editor +{ + // Allows tiles from multiple tilesets to be used in one map + // A tile ID of -1 will mean "no tile" and result in a transparent spot + // when rendered + struct TileRef + { + int TileSetID; + int TileID; + }; + + class TileMap + { + public: + void SetTile(TileRef, Vec2i location); + TileRef GetTile(Vec2i location); + + void ClearMap(); + void ResizeMap(Sizei size); + + // Call during render to texture phase + void Render(lunarium::IGraphics* g); + + private: + TileRef** mpMap; + Sizei mSizeInTiles; + + }; +}} + +#endif // TILE_MAP_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 index a85ab07..61207fd 100644 --- a/src/run_modes/game/world/world.cpp +++ b/src/run_modes/game/world/world.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include namespace lunarium @@ -61,7 +61,7 @@ namespace lunarium // } - OpRes World::SetRegion(Region* region, Point2Di at) + OpRes World::SetRegion(Region* region, Vec2i at) { if (*mRegions[at] != nullptr) { @@ -82,12 +82,12 @@ namespace lunarium return OpRes::OK(); } - World::Region* World::GetRegion(Point2Di at) + World::Region* World::GetRegion(Vec2i at) { return *mRegions[at]; } - bool World::RemoveRegion(Point2Di at) + bool World::RemoveRegion(Vec2i at) { if (*mRegions[at] == nullptr) { diff --git a/src/run_modes/game/world/world.h b/src/run_modes/game/world/world.h index 54183dc..1379bc2 100644 --- a/src/run_modes/game/world/world.h +++ b/src/run_modes/game/world/world.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ namespace lunarium struct Region { Script* mRegionScript; - Point2Di mCoords; + Vec2i mCoords; std::vector mObjects; std::vector mLayers; }; @@ -53,9 +53,9 @@ namespace lunarium // void AddGameObject(GameObject* pObj); // bool RemoveGameObject(GameObject* pObj); - OpRes SetRegion(Region* region, Point2Di at); - Region* GetRegion(Point2Di at); - bool RemoveRegion(Point2Di at); + OpRes SetRegion(Region* region, Vec2i at); + Region* GetRegion(Vec2i at); + bool RemoveRegion(Vec2i at); void SetWorldScript(Script* pScript); Script* GetWorldScript(); @@ -68,7 +68,7 @@ namespace lunarium Sizei mRegionSize; // in pixels Sizei mWorldSize; // num regions ex. 10x10 Grid mRegions; - Point2Di mActiveRegion; + Vec2i mActiveRegion; }; diff --git a/src/run_modes/tester/scenes/physicsScene.cpp b/src/run_modes/tester/scenes/physicsScene.cpp index 5af2f29..c9cce93 100644 --- a/src/run_modes/tester/scenes/physicsScene.cpp +++ b/src/run_modes/tester/scenes/physicsScene.cpp @@ -8,7 +8,7 @@ #include "physicsScene.h" #include -#include +#include #include namespace lunarium diff --git a/src/run_modes/tester/scenes/simpleRenderScene.cpp b/src/run_modes/tester/scenes/simpleRenderScene.cpp index 3c81025..b0ee66a 100644 --- a/src/run_modes/tester/scenes/simpleRenderScene.cpp +++ b/src/run_modes/tester/scenes/simpleRenderScene.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/run_modes/tester/scenes/simpleRenderScene.h b/src/run_modes/tester/scenes/simpleRenderScene.h index 3d36b1b..bc2854c 100644 --- a/src/run_modes/tester/scenes/simpleRenderScene.h +++ b/src/run_modes/tester/scenes/simpleRenderScene.h @@ -10,7 +10,7 @@ #define SIMPLE_RENDER_SCENE_H_ #include "baseScene.h" -#include +#include #include #include diff --git a/src/run_modes/tester/tester.cpp b/src/run_modes/tester/tester.cpp index 4a16b7e..7a4c7b8 100644 --- a/src/run_modes/tester/tester.cpp +++ b/src/run_modes/tester/tester.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include namespace lunarium diff --git a/src/run_modes/tester/tester.h b/src/run_modes/tester/tester.h index 18fc08d..61e5dc0 100644 --- a/src/run_modes/tester/tester.h +++ b/src/run_modes/tester/tester.h @@ -10,7 +10,7 @@ #define TESTER_H_ #include -#include +#include #include "scenes/baseScene.h" namespace lunarium