-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from sdslabs/add-imgui
Add Editor
- Loading branch information
Showing
56 changed files
with
48,773 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mkdir build | ||
cd build | ||
del /F CMakeCache.txt | ||
cmake .. -G "Visual Studio 16 2019" -A x64 | ||
cmake .. -DBUILD_EDITOR=ON -G "Visual Studio 16 2019" -A x64 | ||
cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
file(GLOB_RECURSE EditorSource ./**.cpp) | ||
file(GLOB_RECURSE EditorHeaders ./**.h) | ||
|
||
add_definitions(-DROOTEX_EDITOR) | ||
add_executable(Editor ${EditorSource} ${EditorHeaders}) | ||
|
||
target_include_directories(Editor PUBLIC ../) | ||
target_link_libraries(Editor PUBLIC Rootex) | ||
|
||
add_custom_command(TARGET Editor POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${ALUT_DLL_LIBRARY} | ||
$<TARGET_FILE_DIR:Editor>) | ||
|
||
set_directory_properties(PROPERTIES | ||
VS_STARTUP_PROJECT Editor | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version = 1.0 | ||
|
||
project = "Rootex Editor" | ||
|
||
window = { | ||
x = 100, | ||
y = 100, | ||
width = 1920, | ||
height = 1080 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "editor.h" | ||
|
||
#include "core/renderer/rendering_device.h" | ||
|
||
#include "framework/components/visual/visual_component_graph.h" | ||
#include "framework/components/hierarchy_component.h" | ||
#include "framework/systems/render_system.h" | ||
|
||
void Editor::initialize(HWND hWnd) | ||
{ | ||
IMGUI_CHECKVERSION(); | ||
ImGui::CreateContext(); | ||
ImGuiIO& io = ImGui::GetIO(); | ||
ImGui_ImplWin32_Init(hWnd); | ||
ImGui_ImplDX11_Init(RenderingDevice::GetSingleton()->getDevice(), RenderingDevice::GetSingleton()->getContext()); | ||
ImGui::StyleColorsDark(); | ||
} | ||
|
||
void Editor::begin(VisualComponentGraph* visualGraph) | ||
{ | ||
ImGui_ImplDX11_NewFrame(); | ||
ImGui_ImplWin32_NewFrame(); | ||
ImGui::NewFrame(); | ||
ImGui::ShowDemoWindow(); | ||
} | ||
|
||
void explore(const HierarchyComponent* component) | ||
{ | ||
bool x; | ||
static bool y = false; | ||
ImGui::Button(std::to_string(component->getOwner()->getID()).c_str()); | ||
if (ImGui::IsItemClicked()) | ||
{ | ||
y = true; | ||
if (ImGui::BeginPopup("Info")) | ||
{ | ||
ImGui::OpenPopup("Popup"); | ||
ImGui::Text("This has %d components", component->getOwner()->getAllComponents().size()); | ||
ImGui::EndPopup(); | ||
} | ||
} | ||
|
||
for (auto&& child : component->getChildren()) | ||
{ | ||
explore(child->getComponent<HierarchyComponent>()); | ||
} | ||
} | ||
|
||
void Editor::displayVisualGraph(VisualComponentGraph* graph) | ||
{ | ||
if (ImGui::Begin("Visual Graph")) | ||
{ | ||
ImGui::SetNextWindowBgAlpha(1.0f); | ||
if (ImGui::Begin("Viewport")) | ||
{ | ||
ImGui::Image(RenderingDevice::GetSingleton()->getRenderTextureShaderResourceView(), { 1280, 720 }); | ||
} | ||
ImGui::End(); | ||
//explore(graph->getRoot()); | ||
} | ||
ImGui::End(); | ||
} | ||
|
||
void Editor::end(VisualComponentGraph* visualGraph) | ||
{ | ||
RenderingDevice::GetSingleton()->setTextureRenderTarget(); | ||
RenderSystem::GetSingleton()->render(visualGraph); | ||
RenderingDevice::GetSingleton()->setBackBufferRenderTarget(); | ||
ImGui::Render(); | ||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); | ||
} | ||
|
||
Editor::~Editor() | ||
{ | ||
ImGui_ImplDX11_Shutdown(); | ||
ImGui_ImplWin32_Shutdown(); | ||
ImGui::DestroyContext(); | ||
} | ||
|
||
Editor* Editor::GetSingleton() | ||
{ | ||
static Editor singleton; | ||
return &singleton; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
|
||
#include "vendor/ImGUI/imgui.h" | ||
#include "vendor/ImGUI/imgui_impl_dx11.h" | ||
#include "vendor/ImGUI/imgui_impl_win32.h" | ||
|
||
class VisualComponentGraph; | ||
|
||
class Editor | ||
{ | ||
Editor() = default; | ||
Editor(Editor&) = delete; | ||
~Editor(); | ||
|
||
public: | ||
static Editor* GetSingleton(); | ||
|
||
void initialize(HWND hWnd); | ||
void begin(VisualComponentGraph* visualGraph); | ||
void displayVisualGraph(VisualComponentGraph* graph); | ||
void end(VisualComponentGraph* visualGraph); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include "common/common.h" | ||
|
||
#include "core/audio/audio_source.h" | ||
#include "core/audio/audio_system.h" | ||
#include "core/audio/static_audio_buffer.h" | ||
#include "core/audio/streaming_audio_buffer.h" | ||
|
||
#include "core/input/input_manager.h" | ||
|
||
#include "core/renderer/buffer_format.h" | ||
#include "core/renderer/index_buffer.h" | ||
#include "core/renderer/material.h" | ||
#include "core/renderer/renderer.h" | ||
#include "core/renderer/shader_library.h" | ||
#include "core/renderer/vertex_buffer.h" | ||
|
||
#include "core/event_manager.h" | ||
#include "core/resource_loader.h" | ||
|
||
#include "framework/components/hierarchy_component.h" | ||
#include "framework/components/test_component.h" | ||
#include "framework/components/visual/diffuse_visual_component.h" | ||
#include "framework/components/visual/visual_component.h" | ||
#include "framework/components/visual/visual_component_graph.h" | ||
#include "framework/entity_factory.h" | ||
#include "framework/systems/debug_system.h" | ||
#include "framework/systems/light_system.h" | ||
#include "framework/systems/render_system.h" | ||
#include "framework/systems/test_system.h" | ||
|
||
#include "main/window.h" | ||
|
||
#include "os/os.h" | ||
#include "os/thread.h" | ||
#include "os/timer.h" | ||
|
||
#include "script/interpreter.h" | ||
|
||
#include "editor/editor.h" | ||
|
||
int main() | ||
{ | ||
OS::Initialize(); | ||
OS::PrintLine("Rootex Editor is starting: Build(" + OS::GetBuildDate() + "|" + OS::GetBuildTime() + ")"); | ||
OS::PrintLine("Starting from path: " + OS::GetAbsolutePath(".").generic_string()); | ||
|
||
AudioSystem::GetSingleton()->initialize(); | ||
|
||
LuaTextResourceFile* configFile = ResourceLoader::CreateLuaTextResourceFile("editor/config/config.lua"); | ||
LuaInterpreter interpreter; | ||
interpreter.loadExecuteScript(configFile); | ||
|
||
String projectName = interpreter.getGlobal("project"); | ||
OS::PrintLine("Loading Project: " + projectName); | ||
|
||
LuaVariable windowLua = interpreter.getGlobal("window"); | ||
Vector2 windowPosition = { windowLua["x"], windowLua["y"] }; | ||
Vector2 windowSize = { windowLua["width"], windowLua["height"] }; | ||
|
||
Ptr<Window> editorWindow(new Window( | ||
windowPosition.x, | ||
windowPosition.y, | ||
windowSize.x, | ||
windowSize.y, | ||
projectName, | ||
true)); | ||
|
||
InputManager::GetSingleton()->initialize(windowSize.x, windowSize.y); | ||
|
||
ShaderLibrary::MakeShaders(); | ||
|
||
Ref<VisualComponentGraph> visualGraph(new VisualComponentGraph()); | ||
Ref<RenderSystem> renderSystem(new RenderSystem()); | ||
Ref<LightSystem> lightSystem(new LightSystem()); | ||
|
||
Ref<Entity> cube = EntityFactory::GetSingleton()->createEntity(ResourceLoader::CreateLuaTextResourceFile("game/assets/test/cube.lua")); | ||
cube->getComponent<TransformComponent>()->addTransform(Matrix::CreateTranslation({ 0.0f, 0.0f, -5.0f })); | ||
visualGraph->addChild(cube); | ||
|
||
OS::PrintLine("Project loaded successfully: " + projectName); | ||
Editor::GetSingleton()->initialize(editorWindow->getWindowHandle()); | ||
|
||
std::optional<int> ret; | ||
while (true) | ||
{ | ||
if (ret = editorWindow->processMessages()) | ||
{ | ||
break; | ||
} | ||
|
||
AudioSystem::GetSingleton()->update(); | ||
InputManager::GetSingleton()->update(); | ||
EventManager::GetSingleton()->dispatchDeferred(); | ||
|
||
Editor::GetSingleton()->begin(visualGraph.get()); | ||
Editor::GetSingleton()->displayVisualGraph(visualGraph.get()); | ||
Editor::GetSingleton()->end(visualGraph.get()); | ||
|
||
editorWindow->swapBuffers(); | ||
editorWindow->clear(); | ||
} | ||
|
||
return ret.value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
window = { | ||
x = 100, | ||
y = 200, | ||
deltaX = 640, | ||
deltaY = 480, | ||
x = 0, | ||
y = 0, | ||
deltaX = 1920, | ||
deltaY = 1080, | ||
title = "Rootex" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.