Skip to content

Commit

Permalink
Remove File, implement IFileSystem, tidy up raw ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
MattRyder committed Feb 17, 2018
1 parent 5e8b485 commit 4f8d46e
Show file tree
Hide file tree
Showing 67 changed files with 1,170 additions and 675 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Required to gen. symbols for GDB
set(CMAKE_BUILD_TYPE Debug)

# It should be building in an env directory, like MSVC, on unix
if(UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
endif()

option(COPY_DEMO_ASSETS "Copies demo assets for the Editor" ON)
option(BUILD_EDITOR "Builds the GibEditor" ON)
option(BUILD_TESTS "Build the test suite" ON)
Expand Down
5 changes: 4 additions & 1 deletion Editor/include/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace GibEditor

Components::Dock* GetDock() const;

static bool FlagMask(Flags x) { return static_cast<char>(x) != 0; };

private:
Flags flags = Flags::DEFAULT;
Components::Menubar* menubar;
Expand All @@ -43,6 +45,7 @@ namespace GibEditor
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;

void SetWindowShouldClose(bool value);

};

GIB_FLAGS(Editor::Flags)
}
13 changes: 6 additions & 7 deletions Editor/include/components/ContentBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
#include <map>
#include "nfd.h"

#include "File.h"
#include "Entity.h"
#include "IComponent.h"
#include "Observer.h"
#include "MeshService.h"
#include "scene/Node.h"
#include "renderer/Pipeline.h"
#include "MeshService.h"
#include "filesystem/IFileSystem.h"

namespace GibEditor
{
namespace Components
{
class ContentBrowser : public IComponent
{
GibEngine::Scene::Node* rootSceneNode;
std::shared_ptr<GibEngine::Scene::Node> rootSceneNode;
GibEngine::Renderer::Pipeline* pipeline;
std::shared_ptr<GibEngine::FileSystem::IFileSystem> fileSystem;

Observer* contentDirectoryObserver;
std::map<GibEngine::Entity::Type, std::vector<GibEngine::File*>> availableContent;
std::vector<std::string> meshFileList;

json11::Json defaultGenerationData;

void SetupAvailableContentMap();

public:
ContentBrowser(GibEngine::Scene::Node* rootSceneNode, GibEngine::Renderer::Pipeline* pipeline);
ContentBrowser(std::shared_ptr<GibEngine::FileSystem::IFileSystem> fileSystem, std::shared_ptr<GibEngine::Scene::Node> rootSceneNode, GibEngine::Renderer::Pipeline* pipeline);
~ContentBrowser();

void Render() override;
Expand Down
4 changes: 2 additions & 2 deletions Editor/include/components/Dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace GibEditor
POINT_LIGHT,
};

Dock(GibEngine::Scene::Node* rootSceneNode, GibEngine::Renderer::Pipeline* pipeline);
Dock(std::shared_ptr<GibEngine::FileSystem::IFileSystem> fileSystem, std::shared_ptr<GibEngine::Scene::Node> rootSceneNode, GibEngine::Renderer::Pipeline* pipeline);
virtual void Render() override;

Dock::Type GetSelectedDock() const;

private:
GibEngine::Scene::Node* rootSceneNode;
std::shared_ptr<GibEngine::Scene::Node> rootSceneNode;
GibEngine::Renderer::Pipeline* pipeline;

Components::ContentBrowser* cbrowser = nullptr;
Expand Down
73 changes: 39 additions & 34 deletions Editor/include/components/EntityInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,43 @@ namespace GibEditor
// Render the Database state of the scene node:
ImGui::Text("Database Record");

if (sceneNode->GetDatabaseRecord() != nullptr)
{
auto dbRec = sceneNode->GetDatabaseRecord();

switch (dbRec->GetState())
{
case GibEngine::World::DatabaseRecord::State::CLEAN:
ImGui::TextColored(colorSuccess, "Node CLEAN");
break;
case GibEngine::World::DatabaseRecord::State::DELETED:
ImGui::TextColored(colorDanger, "Node DELETED");
break;
case GibEngine::World::DatabaseRecord::State::DIRTY:
ImGui::TextColored(colorWarn, "Node DIRTY");
break;
}
auto dbRec = sceneNode->GetDatabaseRecord();

switch (dbRec->GetEntityState())
{
case GibEngine::World::DatabaseRecord::State::CLEAN:
ImGui::TextColored(colorSuccess, "Entity CLEAN");
break;
case GibEngine::World::DatabaseRecord::State::DELETED:
ImGui::TextColored(colorDanger, "Entity DELETED");
break;
case GibEngine::World::DatabaseRecord::State::DIRTY:
ImGui::TextColored(colorWarn, "Entity DIRTY");
break;
}
switch (dbRec.GetState())
{
case GibEngine::World::DatabaseRecord::State::NEW:
ImGui::TextColored(colorPrimary, "Node NEW");
break;
case GibEngine::World::DatabaseRecord::State::CLEAN:
ImGui::TextColored(colorSuccess, "Node CLEAN");
break;
case GibEngine::World::DatabaseRecord::State::DELETED:
ImGui::TextColored(colorDanger, "Node DELETED");
break;
case GibEngine::World::DatabaseRecord::State::DIRTY:
ImGui::TextColored(colorWarn, "Node DIRTY");
break;
}

ImGui::Dummy(ImVec2(ImGui::GetWindowSize().x, 15));
switch (dbRec.GetEntityState())
{
case GibEngine::World::DatabaseRecord::State::NEW:
ImGui::TextColored(colorPrimary, "Entity NEW");
break;
case GibEngine::World::DatabaseRecord::State::CLEAN:
ImGui::TextColored(colorSuccess, "Entity CLEAN");
break;
case GibEngine::World::DatabaseRecord::State::DELETED:
ImGui::TextColored(colorDanger, "Entity DELETED");
break;
case GibEngine::World::DatabaseRecord::State::DIRTY:
ImGui::TextColored(colorWarn, "Entity DIRTY");
break;
}

ImGui::Dummy(ImVec2(ImGui::GetWindowSize().x, 15));


RenderTransformNode();
ImGui::Dummy(ImVec2(ImGui::GetWindowSize().x, 30));

Expand Down Expand Up @@ -99,6 +103,7 @@ namespace GibEditor
const ImVec4 colorSuccess = ImVec4(0.439f, 0.972f, 0.227f, 1.0f);
const ImVec4 colorWarn = ImVec4(0.972f, 0.862f, 0.227f, 1.0f);
const ImVec4 colorDanger = ImVec4(0.972f, 0.227f, 0.227f, 1.0f);
const ImVec4 colorPrimary = ImVec4(0.509, 0.780, 0.972, 1.0f);

GibEngine::Scene::Node* sceneNode = nullptr;
bool sceneNodeIsDirty = false;
Expand All @@ -123,13 +128,13 @@ namespace GibEditor
{
matrix[3] = glm::vec4(pos[0], pos[1], pos[2], 1.0f);
sceneNode->SetLocalTransform(matrix);
sceneNode->SetNodeDirty();
sceneNode->SetNodeState(GibEngine::World::DatabaseRecord::State::DIRTY);
}

if (ImGui::DragFloat("Rotation Y", &rot.y, INCREMENT_SLOWEST, 0, 0.1))
{
sceneNode->RotateY(rot.y);
sceneNode->SetNodeDirty();
sceneNode->SetNodeState(GibEngine::World::DatabaseRecord::State::DIRTY);
}

if (ImGui::DragFloat3("Scale", glm::value_ptr(scale), INCREMENT_SLOW, -1000.0f, 1000.0f))
Expand All @@ -139,7 +144,7 @@ namespace GibEditor
matrix[2][2] = scale[2];

sceneNode->SetLocalTransform(matrix);
sceneNode->SetNodeDirty();
sceneNode->SetNodeState(GibEngine::World::DatabaseRecord::State::DIRTY);
}
}

Expand Down Expand Up @@ -214,8 +219,8 @@ namespace GibEditor
char skyboxNameBuf[SKYBOX_INPUT_LEN] = { 0 };
char skyboxTextureExt[SKYBOX_INPUT_LEN] = { 0 };

memcpy(skyboxNameBuf, skybox->GetName(), SKYBOX_INPUT_LEN);
memcpy(skyboxTextureExt, skybox->GetExtension(), SKYBOX_INPUT_LEN);
memcpy(skyboxNameBuf, skybox->GetName().c_str(), SKYBOX_INPUT_LEN);
memcpy(skyboxTextureExt, skybox->GetExtension().c_str(), SKYBOX_INPUT_LEN);

if (ImGui::InputText("Skybox Name", skyboxNameBuf, SKYBOX_INPUT_LEN))
{
Expand Down
6 changes: 3 additions & 3 deletions Editor/include/components/Menubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace GibEditor
{
class Menubar : IComponent
{
GibEngine::Scene::Node* rootSceneNode;
std::shared_ptr<GibEngine::Scene::Node> rootSceneNode;
std::function<void()> exitCallback, newWorldCallbackFunc, openFileDialogCallbackFunc, toggleUiRenderCallbackFunc;
std::function<void(GibEngine::Scene::Node*)> saveFileDialogCallbackFunc;

public:
Menubar(GibEngine::Scene::Node*);
Menubar(std::shared_ptr<GibEngine::Scene::Node> node);
virtual void Render() override;

void SetSceneNode(GibEngine::Scene::Node* node);
void SetSceneNode(std::shared_ptr<GibEngine::Scene::Node> node);

void SetOnNewWorldCallback(const std::function<void()>& newWorldCallbackFunc);
void SetOnExitCallback(const std::function<void()>& exitCallbackFunc);
Expand Down
39 changes: 23 additions & 16 deletions Editor/src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ GibEditor::Editor::Editor(int argc, char** argv)
auto openWorldFileCallback = [&]() -> void
{
nfdchar_t* outPath = nullptr;
nfdresult_t res = NFD_OpenDialog("gwo", GibEngine::File::GetWorkingDirectory().c_str(), &outPath);
nfdresult_t res = NFD_OpenDialog("gwo", GetFileSystem()->GetWorkingDirectory().c_str(), &outPath);

if (res == NFD_OKAY)
{
GibEngine::Logger::Instance->info("Loading World: {}", outPath);
GibEngine::World::Database* db = new GibEngine::World::Database(outPath, true);
GibEngine::World::Database* db = new GibEngine::World::Database(outPath, fileSystem, true);

this->rootSceneNode = db->LoadLevel(1);
this->rootSceneNode = std::shared_ptr<GibEngine::Scene::Node>(db->LoadLevel(1));

dock = new Components::Dock(this->rootSceneNode, this->GetRenderPipeline());
dock = new Components::Dock(this->GetFileSystem(), this->rootSceneNode, this->GetRenderPipeline());

db->Disconnect();
delete db;
Expand All @@ -30,7 +30,7 @@ GibEditor::Editor::Editor(int argc, char** argv)

auto newWorldCallback = [&]() -> void
{
GibEngine::Scene::Node* rootNode = CreateWorld();
std::shared_ptr<GibEngine::Scene::Node> rootNode = CreateWorld();

// Generate a plane for the Editor:
json11::Json planeGenerationData = json11::Json::object
Expand All @@ -41,16 +41,14 @@ GibEditor::Editor::Editor(int argc, char** argv)
{ "IntervalSize", 5 }
};

auto planeNode = GibEngine::MeshService::Generate(&planeGenerationData);
auto planeNode = GibEngine::MeshService::Generate(planeGenerationData);
rootNode->AddChildNode(planeNode);

SetSceneRoot(rootNode);
menubar->SetSceneNode(rootNode);

delete dock;
dock = new Components::Dock(rootNode, this->GetRenderPipeline());


dock = new Components::Dock(this->GetFileSystem(), rootNode, this->GetRenderPipeline());
};

auto toggleUiRenderCallback = [&]() -> void
Expand All @@ -61,12 +59,12 @@ GibEditor::Editor::Editor(int argc, char** argv)
auto saveWorldCallback = [&](GibEngine::Scene::Node* node) -> void
{
nfdchar_t* outPath = nullptr;
nfdresult_t res = NFD_SaveDialog("gwo", GibEngine::File::GetWorkingDirectory().c_str(), &outPath);
nfdresult_t res = NFD_SaveDialog("gwo", GetFileSystem()->GetWorkingDirectory().c_str(), &outPath);

if (res == NFD_OKAY)
{
GibEngine::Logger::Instance->info("Saving World: {}", outPath);
GibEngine::World::Database* db = new GibEngine::World::Database(outPath);
GibEngine::World::Database* db = new GibEngine::World::Database(outPath, this->GetFileSystem());

if (db->SaveLevel(node))
{
Expand All @@ -86,7 +84,7 @@ GibEditor::Editor::Editor(int argc, char** argv)
menubar->SetOnSaveFileDialogCallback(saveWorldCallback);
menubar->SetToggleUiRenderCallback(toggleUiRenderCallback);

dock = new Components::Dock(rootSceneNode, GetRenderPipeline());
dock = new Components::Dock(this->GetFileSystem(), rootSceneNode, GetRenderPipeline());

statusBar = new Components::StatusBar();
}
Expand All @@ -102,10 +100,15 @@ void GibEditor::Editor::Render()
{
Game::Render();

if (FlagMask(flags & Flags::DISABLE_UI_RENDER))
{
return;
}

ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiSetCond_Always);

auto framebuffer = GetRenderPipeline()->GetFramebuffer();
ImGui::SetNextWindowSize(ImVec2(framebuffer->GetBufferWidth(), framebuffer->GetBufferHeight() - ImGui::GetTextLineHeightWithSpacing()), ImGuiSetCond_Always);
ImGui::SetNextWindowSize(ImVec2(framebuffer->GetBufferWidth(), framebuffer->GetBufferHeight() - ImGui::GetFontSize() * 2), ImGuiSetCond_Always);

if (ImGui::Begin("MainMenuWindow", (bool*)0, ROOT_PANEL_FLAGS))
{
Expand All @@ -116,8 +119,8 @@ void GibEditor::Editor::Render()
}

auto padding = ImGui::GetStyle().WindowPadding;
ImGui::SetNextWindowPos(ImVec2(0, framebuffer->GetBufferHeight() - ImGui::GetTextLineHeightWithSpacing()));
ImGui::SetNextWindowSize(ImVec2(framebuffer->GetBufferWidth(), ImGui::GetTextLineHeightWithSpacing()));
ImGui::SetNextWindowPos(ImVec2(0, framebuffer->GetBufferHeight() - ImGui::GetFontSize() * 2));
ImGui::SetNextWindowSize(ImVec2(framebuffer->GetBufferWidth(), ImGui::GetFontSize() * 2));
if (ImGui::Begin("StatusBarWindow", 0, ROOT_PANEL_FLAGS))
{
if (ImGui::BeginMenuBar())
Expand All @@ -133,6 +136,10 @@ void GibEditor::Editor::Render()
}

ImGui::Text("Frame Render: %.5fms (%i FPS)", lastReadDeltaTime, GetFramesPerSecond());
ImGui::SameLine();

ImVec4 vsyncColor = (config.vsyncEnabled) ? ImVec4(0.305, 0.949, 0.250, 1.0) : ImVec4(0.949, 0.250, 0.368, 1.0);
ImGui::TextColored(vsyncColor, "VSYNC");

ImGui::EndMenuBar();
}
Expand All @@ -158,7 +165,7 @@ void GibEditor::Editor::Update()

inputManager->SetUpdatingMouseState(isGameConsumingMouseInput);

if (keydownInterval > 0.05f)
if (keydownInterval > 0.5f)
{
if (inputManager->GetKeyboardState()[GLFW_KEY_TAB])
{
Expand Down
6 changes: 1 addition & 5 deletions Editor/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ int main(int argc, char** argv)
void SetupImGuiStyle()
{
ImGuiIO& io = ImGui::GetIO();

GibEngine::File* uiFontFile = GibEngine::File::GetFontFile("Arimo-Regular.ttf");
io.Fonts->AddFontFromFileTTF(uiFontFile->GetPath(), 24.0f);
io.Fonts->AddFontFromFileTTF("../../Assets/Fonts/Arimo-Regular.ttf", 24.0f);

ImGuiStyle& style = ImGui::GetStyle();

Expand Down Expand Up @@ -96,6 +94,4 @@ void SetupImGuiStyle()
style.Colors[ImGuiCol_Column] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.15f, 0.31f, 0.38f, 1.00f);
style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.15f, 0.31f, 0.61f, 1.00f);

delete uiFontFile;
}
Loading

0 comments on commit 4f8d46e

Please sign in to comment.