Separates out the tile map into it's own class

Refactors some file names and locations (igraphics.h -> graphics.h, types.h/cpp moved to core)
Gui_Panel_Refactor
Joeyrp 4 years ago
parent 7e6f2907f2
commit f4e5de912d

@ -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"

@ -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);

@ -19,15 +19,15 @@ namespace lunarium
// POINT
////////////////////////////////////////////////////////////
template <typename T>
struct Point2D
struct Vec2
{
T X;
T Y;
};
typedef Point2D<int> Point2Di;
typedef Point2D<unsigned> Point2Du;
typedef Point2D<float> Point2Df;
typedef Vec2<int> Vec2i;
typedef Vec2<unsigned> Vec2u;
typedef Vec2<float> Vec2f;
///////////////////////////////////////////////////////
// SIZE

@ -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 <utils/types.h>
#include <core/types.h>
#include <utils/opRes.h>
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;

@ -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)
{

@ -9,7 +9,7 @@
#ifndef OGLGRAPHICS_H_
#define OGLGRAPHICS_H_
#include "../igraphics.h"
#include "../graphics.h"
#include <glad/gl.h>
#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);

@ -16,7 +16,7 @@
#include <glad/gl.h>
#include "glShader.h"
#include <utils/opRes.h>
#include <utils/types.h>
#include <core/types.h>
#include <glm/glm.hpp>
struct FT_LibraryRec_;

@ -10,7 +10,7 @@
#include "dataManager.h"
#include <core/core.h>
#include <graphics/igraphics.h>
#include <graphics/graphics.h>
#include <assets/types/image.h>
// ASSETS

@ -14,7 +14,7 @@
#include <map>
#include <assets/types/asset.h>
#include <utils/opRes.h>
#include <utils/types.h>
#include <core/types.h>
namespace lunarium
{

@ -13,7 +13,7 @@
#include <cstring>
#include <core/core.h>
#include <assets/types/image.h>
#include <graphics/igraphics.h>
#include <graphics/graphics.h>
#include <internal_data/dataManager.h>
#include <utils/stb/stb_image.h>
#include "dearimgui/imgui.h"

@ -50,7 +50,6 @@ namespace gui
protected:
void UpdateMetaInfo();
};
}
}
}}
#endif // PANEL_H_

@ -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
)

@ -12,7 +12,7 @@
#ifndef GRID_H_
#define GRID_H_
#include "types.h"
#include <core/types.h>
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<typename T>
T* Grid<T>::operator[](Point2Di at)
T* Grid<T>::operator[](Vec2i at)
{
return &mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data;
}
template<typename T>
T Grid<T>::GetAt(Point2Di at)
T Grid<T>::GetAt(Vec2i at)
{
return mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data;
}
template<typename T>
void Grid<T>::SetAt(Point2Di at, T value)
void Grid<T>::SetAt(Vec2i at, T value)
{
mGrid[at.X + mHalfSize.Width][at.Y + mHalfSize.Height].Data = value;
}

@ -9,7 +9,7 @@
#ifndef HELPERS_H_
#define HELPERS_H_
#include "types.h"
#include <core/types.h>
#include <LunariumConfig.h>
#include <string>
#include <vector>

@ -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})

@ -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,9 +253,17 @@ namespace editor
if (mDoSaveProject)
{
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))
{

@ -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);
};
}

@ -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();
}

@ -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);

@ -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
{

@ -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;

@ -8,10 +8,15 @@
#include "map_editor.h"
#include <core/core.h>
#include <graphics/graphics.h>
#include <editor/editor.h>
#include <gui/panel.h>
#include <gui/dearimgui/imgui.h>
// 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();
}

@ -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 <gui/dearimgui/imgui.h>
#include <core/core.h>
#include <graphics/graphics.h>
#include <assets/types/image.h>
#include <string>
#include <sstream>
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;
}
}}

@ -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 <gui/panel.h>
#include "../tile_map.h"
#include <core/types.h>
#include <string>
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_

@ -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 <core/core.h>
#include <graphics/graphics.h>
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)
{
}
}}

@ -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 <core/types.h>
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_

@ -13,7 +13,7 @@
#include <object/object.h>
#include <assets/types/script.h>
#include <assets/types/image.h>
#include <graphics/igraphics.h>
#include <graphics/graphics.h>
#include <graphics/camera.h>
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)
{

@ -14,7 +14,7 @@
#include <vector>
#include <map>
#include <utils/types.h>
#include <core/types.h>
#include <utils/opRes.h>
#include <utils/grid.h>
@ -32,7 +32,7 @@ namespace lunarium
struct Region
{
Script* mRegionScript;
Point2Di mCoords;
Vec2i mCoords;
std::vector<GameObject*> mObjects;
std::vector<Image*> 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<Region*> mRegions;
Point2Di mActiveRegion;
Vec2i mActiveRegion;
};

@ -8,7 +8,7 @@
#include "physicsScene.h"
#include <core/core.h>
#include <graphics/igraphics.h>
#include <graphics/graphics.h>
#include <utils/logger.h>
namespace lunarium

@ -10,7 +10,7 @@
#include <core/core.h>
#include <utils/helpers.h>
#include <utils/logger.h>
#include <graphics/igraphics.h>
#include <graphics/graphics.h>
#include <input/inputManager.h>
#include <assets/types/image.h>
#include <utils/stb/std_image_write.h>

@ -10,7 +10,7 @@
#define SIMPLE_RENDER_SCENE_H_
#include "baseScene.h"
#include <utils/types.h>
#include <core/types.h>
#include <utils/grid.h>
#include <string>

@ -12,7 +12,7 @@
#include <core/core.h>
#include <utils/logger.h>
#include <graphics/igraphics.h>
#include <graphics/graphics.h>
#include <LunariumConfig.h>
namespace lunarium

@ -10,7 +10,7 @@
#define TESTER_H_
#include <core/iRunMode.h>
#include <utils/types.h>
#include <core/types.h>
#include "scenes/baseScene.h"
namespace lunarium

Loading…
Cancel
Save