Start of ECS - files added

NFD wrapped up behind utils FileSystem functions
gui_api_redesign
Joey Pollack 4 years ago
parent 36c67d57d7
commit d9f7a136e5

@ -69,6 +69,7 @@ set(LUNARIUM_SRC
"src/utils/high_resolution_timer.cpp" "src/utils/high_resolution_timer.cpp"
"src/utils/logger.cpp" "src/utils/logger.cpp"
"src/utils/op_res.cpp" "src/utils/op_res.cpp"
"src/utils/uuid.cpp"
"src/platform/window.cpp" "src/platform/window.cpp"
"src/platform/terminal.cpp" "src/platform/terminal.cpp"
"src/graphics/opengl/glGraphics.cpp" "src/graphics/opengl/glGraphics.cpp"
@ -87,6 +88,7 @@ set(LUNARIUM_SRC
"src/scripting/script_manager.cpp" "src/scripting/script_manager.cpp"
"src/scripting/coreAPI.cpp" "src/scripting/coreAPI.cpp"
"src/world/world.cpp" "src/world/world.cpp"
"src/world/entity.cpp"
) )
# add the executable # add the executable
@ -175,6 +177,7 @@ target_include_directories(${PROJECT_NAME}
PUBLIC external/glad/include PUBLIC external/glad/include
PUBLIC external/freetype/include PUBLIC external/freetype/include
PUBLIC external/box2d/include PUBLIC external/box2d/include
PUBLIC external/entt
PUBLIC external/nativefiledialog-extended/src/include PUBLIC external/nativefiledialog-extended/src/include
) )

66130
external/entt/entt.hpp vendored

File diff suppressed because it is too large Load Diff

@ -39,6 +39,8 @@ static_assert(sizeof(i64) == 8, "Expected i64 to be 8 bytes");
static_assert(sizeof(f32) == 4, "Expected f32 to be 4 bytes"); static_assert(sizeof(f32) == 4, "Expected f32 to be 4 bytes");
static_assert(sizeof(f64) == 8, "Expected f64 to be 8 bytes"); static_assert(sizeof(f64) == 8, "Expected f64 to be 8 bytes");
typedef u64 LUUID;
// Platform detection // Platform detection
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)

@ -8,6 +8,7 @@
#include "editor.h" #include "editor.h"
#include <utils/helpers.h>
#include "panel_manager.h" #include "panel_manager.h"
#include <core/core.h> #include <core/core.h>
#include <core/version.h> #include <core/version.h>
@ -25,7 +26,6 @@
// Tools // Tools
#include "tools/map_editor/map_editor.h" #include "tools/map_editor/map_editor.h"
#include <nfd.hpp>
using namespace lunarium::gui; using namespace lunarium::gui;
@ -203,21 +203,18 @@ namespace editor
{ {
if (ImGui::MenuItem("New Project")) if (ImGui::MenuItem("New Project"))
{ {
NFD::Guard nfdGuard; std::filesystem::path outPath;
// auto-freeing memory
NFD::UniquePath outPath;
// prepare filters for the dialog // prepare filters for the dialog
nfdfilteritem_t filterItem[1] = {{"Lunarium Project File", "lproj"}}; const FileSystem::FilterItem filterItem[1] = {{"Lunarium Project File", "lproj"}};
// show the dialog // show the dialog
nfdresult_t result = NFD::SaveDialog(outPath, filterItem, 1); FileSystem::DialogResult result = FileSystem::SaveFileDialog(outPath, filterItem, 1);
if (result == NFD_OKAY) if (result == FileSystem::DialogResult::OK)
{ {
std::filesystem::path the_path = outPath.get(); //std::filesystem::path the_path = outPath.get();
Logger::Info(LogCat, "Generating new project at %s", the_path.string().c_str()); Logger::Info(LogCat, "Generating new project at %s", outPath.string().c_str());
OpRes result = mProject.GenerateProject(the_path.filename().string(), the_path.parent_path()); OpRes result = mProject.GenerateProject(outPath.filename().string(), outPath.parent_path());
if (Failed(result)) if (Failed(result))
{ {
Logger::Error(LogCat, "Could not create a new project: %s", result.Description); Logger::Error(LogCat, "Could not create a new project: %s", result.Description);
@ -225,59 +222,54 @@ namespace editor
else else
{ {
((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))-> ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->
SetAssetDirectory(the_path.parent_path() / std::filesystem::path("contents/assets")); SetAssetDirectory(outPath.parent_path() / std::filesystem::path("contents/assets"));
} }
} }
else if (result == NFD_CANCEL) else if (result == FileSystem::DialogResult::CANCEL)
{ {
Logger::Info(LogCat, "User cancelled project create"); Logger::Info(LogCat, "User cancelled project create");
} }
else else
{ {
Logger::Error(LogCat, "Error getting project file location: %s", NFD::GetError()); Logger::Error(LogCat, "Error getting project file location: %s", FileSystem::GetError().c_str());
} }
} }
if (ImGui::MenuItem("Open Project")) if (ImGui::MenuItem("Open Project"))
{ {
NFD::Guard nfdGuard; std::filesystem::path outPath;
// auto-freeing memory
NFD::UniquePath outPath;
// prepare filters for the dialog // prepare filters for the dialog
nfdfilteritem_t filterItem[1] = {{"Lunarium Project File", "lproj"}}; FileSystem::FilterItem filterItem[1] = {{"Lunarium Project File", "lproj"}};
// show the dialog // show the dialog
nfdresult_t result = NFD::OpenDialog(outPath, filterItem, 1); FileSystem::DialogResult result = FileSystem::OpenFileDialog(outPath, filterItem, 1);
if (result == NFD_OKAY) if (result == FileSystem::DialogResult::OK)
{ {
std::filesystem::path the_path = outPath.get(); Logger::Info(LogCat, "Opening project: %s", outPath.string().c_str());
Logger::Info(LogCat, "Opening project: %s", the_path.string().c_str());
// Open project at mpPath // Open project at mpPath
if (Failed(mProject.LoadProject(the_path).LogIfFailed(Editor::LogCat))) if (Failed(mProject.LoadProject(outPath).LogIfFailed(Editor::LogCat)))
{ {
Logger::Error(LogCat, "Failed to load project: %s", the_path.string().c_str()); Logger::Error(LogCat, "Failed to load project: %s", outPath.string().c_str());
} }
else else
{ {
((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))-> ((AssetBrowser*)mPanelManager.GetPanel(mPanels.AssetBrowser))->
SetAssetDirectory(the_path.parent_path() / std::filesystem::path("contents/assets")); SetAssetDirectory(outPath.parent_path() / std::filesystem::path("contents/assets"));
} }
} }
else if (result == NFD_CANCEL) else if (result == FileSystem::DialogResult::CANCEL)
{ {
Logger::Info(LogCat, "User cancelled project open"); Logger::Info(LogCat, "User cancelled project open");
} }
else else
{ {
Logger::Error(LogCat, "Error getting project file location: %s", NFD::GetError()); Logger::Error(LogCat, "Error getting project file location: %s", FileSystem::GetError().c_str());
} }
} }

@ -17,7 +17,7 @@
#include <editor/contents/content_manager.h> #include <editor/contents/content_manager.h>
#include <editor/contents/tile_set.h> #include <editor/contents/tile_set.h>
#include <editor/contents/tile_map.h> #include <editor/contents/tile_map.h>
#include <nfd.hpp> #include <utils/helpers.h>
// Panels // Panels
#include "panels/map_canvas.h" #include "panels/map_canvas.h"
@ -217,24 +217,19 @@ namespace lunarium { namespace editor
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("Import Tile Set")) if (ImGui::MenuItem("Import Tile Set"))
{ {
NFD::Guard nfdGuard; std::filesystem::path outPath;
// auto-freeing memory
NFD::UniquePath outPath;
// prepare filters for the dialog // prepare filters for the dialog
nfdfilteritem_t filterItem[3] = {{"Image file", "png"}, {"Image File", "jpg"}, {"Image File", "jpeg"}}; FileSystem::FilterItem filterItem[3] = {{"Image file", "png"}, {"Image File", "jpg"}, {"Image File", "jpeg"}};
// show the dialog // show the dialog
nfdresult_t result = NFD::OpenDialog(outPath, filterItem, 3); FileSystem::DialogResult result = FileSystem::OpenFileDialog(outPath, filterItem, 3);
if (result == NFD_OKAY) if (result == FileSystem::DialogResult::OK)
{ {
std::filesystem::path the_path = outPath.get(); Logger::Info(Editor::LogCat, "Importing asset: %s", outPath.string().c_str());
Logger::Info(Editor::LogCat, "Importing asset: %s", the_path.string().c_str());
uint64_t id = 0; uint64_t id = 0;
ContentManager::GetInstance().ImportFile(the_path, mpEditor->GetAssetBrowserLocation() / the_path.filename(), AssetType::EATYPE_TILE_SET, id).LogIfFailed(Editor::LogCat); ContentManager::GetInstance().ImportFile(outPath, mpEditor->GetAssetBrowserLocation() / outPath.filename(), AssetType::EATYPE_TILE_SET, id).LogIfFailed(Editor::LogCat);
TileSet* ts = (TileSet*)ContentManager::GetInstance().GetAsset(id); TileSet* ts = (TileSet*)ContentManager::GetInstance().GetAsset(id);
ts->SetTileSize({16, 16}); // NOTE: Hardcoding the tile size for testing ts->SetTileSize({16, 16}); // NOTE: Hardcoding the tile size for testing
@ -248,7 +243,6 @@ namespace lunarium { namespace editor
mpMap->AddTileSet(ts->GetTileSetID(), ts); mpMap->AddTileSet(ts->GetTileSetID(), ts);
((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->AddTileSet(ts); ((TileSetView*)mPanelManager.GetPanel(mPanels.TileSetView))->AddTileSet(ts);
} }
} }
} }

@ -8,8 +8,9 @@
#include "helpers.h" #include "helpers.h"
#include "logger.h" #include "logger.h"
#include <nfd.hpp>
#include <algorithm> #include <algorithm>
#include <filesystem>
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
@ -62,6 +63,57 @@ namespace lunarium
return std::filesystem::create_directory(path); return std::filesystem::create_directory(path);
} }
FileSystem::DialogResult FileSystem::SaveFileDialog(std::filesystem::path& outPath, const FilterItem* filters,
u32 num_filters, const u8* default_path, const u8* default_name)
{
NFD::Guard nfdGuard;
NFD::UniquePath outPath_intern;
DialogResult result = (DialogResult) NFD::SaveDialog(outPath_intern, (const nfdu8filteritem_t*) filters, (nfdfiltersize_t)num_filters, (const nfdu8char_t*)default_path, (const nfdu8char_t*)default_name);
outPath = "";
if (result == DialogResult::OK)
{
outPath = outPath_intern.get();
}
return result;
}
FileSystem::DialogResult FileSystem::OpenFileDialog(std::filesystem::path& outPath, const FilterItem* filters,
u32 num_filters, const u8* default_path)
{
NFD::Guard nfdGuard;
NFD::UniquePath outPath_intern;
DialogResult result = (DialogResult) NFD::OpenDialog(outPath_intern, (const nfdu8filteritem_t*) filters,
(nfdfiltersize_t)num_filters, (const nfdu8char_t*)default_path);
outPath = "";
if (result == DialogResult::OK)
{
outPath = outPath_intern.get();
}
return result;
}
FileSystem::DialogResult FileSystem::PickDirectory(std::filesystem::path& outPath, const u8* default_path)
{
NFD::Guard nfdGuard;
NFD::UniquePath outPath_intern;
DialogResult result = (FileSystem::DialogResult) NFD::PickFolder(outPath_intern, (const nfdu8char_t*)default_path);
outPath = "";
if (result == DialogResult::OK)
{
outPath = outPath_intern.get();
}
return result;
}
std::string FileSystem::GetError()
{
return std::string(NFD::GetError());
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// MATH FUNCTIONS // MATH FUNCTIONS
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

@ -9,10 +9,12 @@
#ifndef HELPERS_H_ #ifndef HELPERS_H_
#define HELPERS_H_ #define HELPERS_H_
#include <core/common_defs.h>
#include <core/types.h> #include <core/types.h>
#include <LunariumConfig.h> #include <LunariumConfig.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <filesystem>
namespace lunarium namespace lunarium
{ {
@ -28,6 +30,30 @@ namespace lunarium
public: public:
static std::vector<std::string> GetFilesInDirectory(std::string path); static std::vector<std::string> GetFilesInDirectory(std::string path);
static bool MakeDir(std::string path); static bool MakeDir(std::string path);
// Dialog Wrappers
enum DialogResult
{
ERROR,
OK,
CANCEL,
};
struct FilterItem
{
const char* name;
const char* spec;
};
static DialogResult SaveFileDialog(std::filesystem::path& outPath, const FilterItem* filters = nullptr,
u32 num_filters = 0, const u8* default_path = nullptr, const u8* default_name = nullptr);
static DialogResult OpenFileDialog(std::filesystem::path& outPath, const FilterItem* filters = nullptr,
u32 num_filters = 0, const u8* default_path = nullptr);
static DialogResult PickDirectory(std::filesystem::path& outPath, const u8* default_path = nullptr);
static std::string GetError();
}; };
class Math class Math

@ -0,0 +1,19 @@
/******************************************************************************
* File - uuid.cpp
* Author - Joey Pollack
* Date - 2022/05/23 (y/m/d)
* Mod Date - 2022/05/23 (y/m/d)
* Description - Generates 64 bit uuids
******************************************************************************/
#include "uuid.h"
#include <ctime>
namespace lunarium
{
std::mt19937_64 UUID::mt64(time(nullptr));
LUUID UUID::GetID()
{
return mt64();
}
}

@ -0,0 +1,28 @@
/******************************************************************************
* File - uuid.h
* Author - Joey Pollack
* Date - 2022/05/23 (y/m/d)
* Mod Date - 2022/05/23 (y/m/d)
* Description - Generates 64 bit uuids
******************************************************************************/
#ifndef LUNARIUM_UUID_H_
#define LUNARIUM_UUID_H_
#include <core/common_defs.h>
#include <random>
namespace lunarium
{
class UUID
{
public:
static LUUID GetID();
private:
static std::mt19937_64 mt64;
};
}
#endif // LUNARIUM_UUID_H_

@ -0,0 +1,24 @@
/******************************************************************************
* File - components.h
* Author - Joey Pollack
* Date - 2022/05/24 (y/m/d)
* Mod Date - 2022/05/24 (y/m/d)
* Description - ECS component declarations
******************************************************************************/
#ifndef LUNARIUM_COMPONENTS_H_
#define LUNARIUM_COMPONENTS_H_
#include <core/common_defs.h>
#include <string>
namespace lunarium
{
struct LabelComponent
{
std::string Label
};
}
#endif // LUNARIUM_COMPONENTS_H_

@ -0,0 +1,18 @@
/******************************************************************************
* File - entity.cpp
* Author - Joey Pollack
* Date - 2022/05/23 (y/m/d)
* Mod Date - 2022/05/23 (y/m/d)
* Description - Provides functionality to work with world entities
******************************************************************************/
#include "entity.h"
namespace lunarium
{
Entity::Entity(entt::registry* r)
: mID(entt::null), mpRegistry(r)
{
}
}

@ -0,0 +1,27 @@
/******************************************************************************
* File - entity.h
* Author - Joey Pollack
* Date - 2022/05/23 (y/m/d)
* Mod Date - 2022/05/23 (y/m/d)
* Description - Provides functionality to work with world entities
******************************************************************************/
#ifndef LUNARIUM_ENTITY_H_
#define LUNARIUM_ENTITY_H_
#include <entt/entt.hpp>
namespace lunarium
{
class Entity
{
public:
Entity(entt::registry* r);
private:
entt::entity mID;
entt::registry* mpRegistry;
};
}
#endif // LUNARIUM_ENTITY_H_

@ -14,6 +14,7 @@
#include <core/types.h> #include <core/types.h>
#include <utils/op_res.h> #include <utils/op_res.h>
#include <entt/entt.hpp>
#include <vector> #include <vector>
#include <map> #include <map>
@ -23,13 +24,12 @@ namespace lunarium
class Graphics; class Graphics;
class Image; class Image;
class Script; class Script;
class Camera;
class GameObject;
} }
namespace lunarium namespace lunarium
{ {
class Camera;
class GameObject;
class World class World
{ {
public: public:
@ -52,12 +52,6 @@ namespace lunarium
void Render(Graphics* pGraphics) const; void Render(Graphics* pGraphics) const;
void RenderToTexture(Graphics* pGraphics, Image* pTexture) 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, Vec2i at); OpRes SetRegion(Region* region, Vec2i at);
Region* GetRegion(Vec2i at); Region* GetRegion(Vec2i at);
bool RemoveRegion(Vec2i at); bool RemoveRegion(Vec2i at);
@ -67,6 +61,7 @@ namespace lunarium
private: private:
entt::registry mECSRegistry;
Camera* mpCamera; Camera* mpCamera;
std::vector<GameObject*> mWorldObjects; std::vector<GameObject*> mWorldObjects;
lunarium::Script* mpWorldScript; lunarium::Script* mpWorldScript;

Loading…
Cancel
Save