From 6726f7110260bbd5305c24df9d3742de2a1e2ab3 Mon Sep 17 00:00:00 2001 From: Krzysztof Jakubowski Date: Tue, 14 Jan 2025 23:17:28 +0100 Subject: [PATCH] Building editor under windows --- .gitignore | 3 +- src/editor.cpp | 73 ++++++++----- src/editor/entities_editor.cpp | 2 +- src/editor/group_editor.cpp | 2 - src/editor/tiles_editor.cpp | 2 +- src/game.cpp | 6 +- src/gfx/scene_renderer.cpp | 1 + windows/freeft.sln | 14 ++- windows/freeft_editor.vcxproj | 145 ++++++++++++++++++++++++++ windows/freeft_editor.vcxproj.filters | 66 ++++++++++++ windows/freeft_lib.vcxproj | 2 +- 11 files changed, 276 insertions(+), 40 deletions(-) create mode 100644 windows/freeft_editor.vcxproj create mode 100644 windows/freeft_editor.vcxproj.filters diff --git a/.gitignore b/.gitignore index b6d05603..5cbf517b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ /data/gui /media /windows/.vs -*.vcxproj.user \ No newline at end of file +/.vscode +*.vcxproj.user diff --git a/src/editor.cpp b/src/editor.cpp index 16a2e4b6..817d3bb9 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -25,9 +25,20 @@ #include "res_manager.h" #include "sys/config.h" -#include -#include + +#include "sys/gfx_device.h" + #include +#include + +#include +#include + +#ifdef FWK_PLATFORM_WINDOWS +#pragma comment(lib, "shlwapi.lib") +#pragma comment(lib, "mpg123.lib") +#pragma comment(lib, "OpenAL32.lib") +#endif using namespace ui; using game::EntityMap; @@ -64,11 +75,12 @@ static const char *s_load_dialog_names[] = { class EditorWindow : public Window { public: - EditorWindow(int2 res) - : Window(IRect(0, 0, res.x, res.y), ColorId::transparent), m_tile_map(m_level.tile_map), - m_entity_map(m_level.entity_map) { + EditorWindow(GfxDevice &gfx_device) + : Window(IRect(gfx_device.window_ref->size()), ColorId::transparent), + m_gfx_device(gfx_device), m_tile_map(m_level.tile_map), m_entity_map(m_level.entity_map) { m_maps_path = FilePath(ResManager::instance().dataPath()) / "maps"; m_left_width = width() / 5; + int2 res = gfx_device.window_ref->size(); m_mode = editing_tiles; m_tile_map.resize(int2(1024, 1024)); @@ -99,7 +111,7 @@ class EditorWindow : public Window { attach(m_group_editor); //loadMap("data/maps/Assault/Lost Vault_mod.xml"); - loadMap("data/maps/mission05_mod.xml"); + loadMap("data/maps/mission02.mod"); recreateEditors(); } @@ -215,7 +227,7 @@ class EditorWindow : public Window { void loadTileGroup(const char *file_name) { printf("Loading TileGroup: %s\n", file_name); if(access(file_name)) { - auto doc = move(XmlDocument::load(file_name).get()); //TODO + auto doc = std::move(XmlDocument::load(file_name).get()); //TODO m_group.loadFromXML(doc); } } @@ -239,27 +251,25 @@ class EditorWindow : public Window { //TODO: nie ma warninga ze nie udalo sie zapisac } - bool mainLoop(GlDevice &device) { - static double s_start_time = getTime(); - - Tile::setFrameCounter((int)((getTime() - s_start_time) * 15.0)); + bool mainLoop() { + Tile::setFrameCounter((int)((getTime() - m_start_time) * 15.0)); TextureCache::instance().nextFrame(); - clearColor(Color(0, 0, 0)); - Renderer2D out(IRect(device.windowSize()), Orient2D::y_down); - - process(device.inputState()); - draw(out); - - out.render(); + process(m_gfx_device.window_ref->inputState()); + int2 window_size = m_gfx_device.window_ref->size(); + Canvas2D canvas(IRect(window_size), Orient2D::y_up); + draw(canvas); + m_gfx_device.drawFrame(canvas).check(); + TextureCache::instance().nextFrame().check(); return true; } - static bool mainLoop(GlDevice &device, void *pthis) { - return ((EditorWindow *)pthis)->mainLoop(device); + static bool mainLoop(VulkanWindow &window, void *pthis) { + return ((EditorWindow *)pthis)->mainLoop(); } + GfxDevice &m_gfx_device; EditorMode m_mode; Level m_level; @@ -284,6 +294,7 @@ class EditorWindow : public Window { int m_left_width; FilePath m_maps_path; + double m_start_time = getTime(); }; void preloadTiles() { @@ -311,19 +322,27 @@ void preloadTiles() { printf("\n"); } -int main(int argc, char **argv) { +Ex exMain() { Config config("editor"); - GlDevice gl_device; - createWindow("editor", gl_device, config.resolution, config.window_pos, config.fullscreen_on); + auto gfx_device = EX_PASS(GfxDevice::create("editor", config)); - ResManager res_mgr; - TextureCache tex_cache; + ResManager res_mgr(gfx_device.device_ref); + TextureCache tex_cache(*gfx_device.device_ref); preloadTiles(); game::loadData(true); - EditorWindow window(gl_device.windowSize()); - gl_device.runMainLoop(EditorWindow::mainLoop, &window); + EditorWindow window(gfx_device); + gfx_device.window_ref->runMainLoop(&EditorWindow::mainLoop, &window); return 0; } + +int main(int argc, char **argv) { + auto result = exMain(); + if(!result) { + result.error().print(); + return 1; + } + return *result; +} diff --git a/src/editor/entities_editor.cpp b/src/editor/entities_editor.cpp index e8739cb7..dd86a557 100644 --- a/src/editor/entities_editor.cpp +++ b/src/editor/entities_editor.cpp @@ -356,7 +356,7 @@ void EntitiesEditor::drawContents(Canvas2D &out) const { renderer.addBox(overground_box, ColorId::yellow); } - renderer.render(); + renderer.render(out); if(m_mode == Mode::selecting && m_is_selecting) out.addRect(m_selection - m_view.pos(), ColorId::white); diff --git a/src/editor/group_editor.cpp b/src/editor/group_editor.cpp index 45b95a3c..4adbf638 100644 --- a/src/editor/group_editor.cpp +++ b/src/editor/group_editor.cpp @@ -6,7 +6,6 @@ #include "gfx/drawing.h" #include #include -#include #include using namespace game; @@ -191,7 +190,6 @@ void GroupEditor::drawContents(Canvas2D &out) const { entry.tile->draw(out, pos); } - GlTexture::unbind(); for(int n = 0; n < (int)m_tile_list.size(); n++) { const ui::TileList::Entry &entry = m_tile_list[n]; if(!entry.is_selected) diff --git a/src/editor/tiles_editor.cpp b/src/editor/tiles_editor.cpp index 1874346c..1cf69ea4 100644 --- a/src/editor/tiles_editor.cpp +++ b/src/editor/tiles_editor.cpp @@ -471,7 +471,7 @@ void TilesEditor::drawContents(Canvas2D &out) const { renderer.addBox(m_tile_map[m_selected_ids[i]].bbox); } } - renderer.render(); + renderer.render(out); out.setScissorRect(clippedRect()); out.setViewPos(-clippedRect().min() + m_view.pos()); diff --git a/src/game.cpp b/src/game.cpp index 4ac9e029..ffc26640 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -33,7 +33,7 @@ struct GameApp { GameApp(GfxDevice &gfx_device, io::PLoop main_loop) : m_gfx_device(gfx_device), m_main_loop(std::move(main_loop)) {} - bool main_loop() { + bool mainLoop() { double time = getTime(); double time_diff = (time - m_last_time); m_last_time = time; @@ -52,7 +52,7 @@ struct GameApp { return true; } - static bool main_loop(VulkanWindow &, void *ptr) { return ((GameApp *)ptr)->main_loop(); } + static bool mainLoop(VulkanWindow &, void *ptr) { return ((GameApp *)ptr)->mainLoop(); } private: GfxDevice &m_gfx_device; @@ -146,7 +146,7 @@ Ex exMain(int argc, char **argv) { } GameApp app(*gfx_device, std::move(main_loop)); - gfx_device->window_ref->runMainLoop(&GameApp::main_loop, &app); + gfx_device->window_ref->runMainLoop(&GameApp::mainLoop, &app); /* PTexture atlas = tex_cache.atlas(); Image tex; diff --git a/src/gfx/scene_renderer.cpp b/src/gfx/scene_renderer.cpp index ec0ca8a5..9fbaf79f 100644 --- a/src/gfx/scene_renderer.cpp +++ b/src/gfx/scene_renderer.cpp @@ -267,4 +267,5 @@ void SceneRenderer::render(Canvas2D &canvas) { canvas.setScissorRect(none); canvas.popViewMatrix(); + canvas.setMaterial({}); } diff --git a/windows/freeft.sln b/windows/freeft.sln index 202b3082..d3d5a571 100644 --- a/windows/freeft.sln +++ b/windows/freeft.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34221.43 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freeft_game", "freeft_game.vcxproj", "{12336274-6333-403E-82AB-E6C94D20F1EC}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "freeft_game.vcxproj", "{12336274-6333-403E-82AB-E6C94D20F1EC}" ProjectSection(ProjectDependencies) = postProject {D43B667A-D8CF-47A1-A576-FC05E7E6CA7B} = {D43B667A-D8CF-47A1-A576-FC05E7E6CA7B} EndProjectSection @@ -12,11 +12,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfwk", "..\libfwk\windows EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freeft_lib", "freeft_lib.vcxproj", "{D43B667A-D8CF-47A1-A576-FC05E7E6CA7B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freeft_lobby_server", "freeft_lobby_server.vcxproj", "{35293BDE-BFEF-4473-A77D-D5D61B566ED6}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lobby_server", "freeft_lobby_server.vcxproj", "{35293BDE-BFEF-4473-A77D-D5D61B566ED6}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freeft_res_viewer", "freeft_res_viewer.vcxproj", "{885E8700-C1E9-45D7-A3D5-4E417C17601F}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "editor", "freeft_res_viewer.vcxproj", "{885E8700-C1E9-45D7-A3D5-4E417C17601F}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "freeft_convert", "freeft_convert.vcxproj", "{AB30FA2A-796E-48F8-A4B4-9D7DADB32D0E}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "convert", "freeft_convert.vcxproj", "{AB30FA2A-796E-48F8-A4B4-9D7DADB32D0E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "res_viewer", "freeft_editor.vcxproj", "{B8CBEF6C-BD15-4749-B463-3AA5D6B7A691}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -48,6 +50,10 @@ Global {AB30FA2A-796E-48F8-A4B4-9D7DADB32D0E}.Debug|x64.Build.0 = Debug|x64 {AB30FA2A-796E-48F8-A4B4-9D7DADB32D0E}.Release|x64.ActiveCfg = Release|x64 {AB30FA2A-796E-48F8-A4B4-9D7DADB32D0E}.Release|x64.Build.0 = Release|x64 + {B8CBEF6C-BD15-4749-B463-3AA5D6B7A691}.Debug|x64.ActiveCfg = Debug|x64 + {B8CBEF6C-BD15-4749-B463-3AA5D6B7A691}.Debug|x64.Build.0 = Debug|x64 + {B8CBEF6C-BD15-4749-B463-3AA5D6B7A691}.Release|x64.ActiveCfg = Release|x64 + {B8CBEF6C-BD15-4749-B463-3AA5D6B7A691}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/windows/freeft_editor.vcxproj b/windows/freeft_editor.vcxproj new file mode 100644 index 00000000..fb805d48 --- /dev/null +++ b/windows/freeft_editor.vcxproj @@ -0,0 +1,145 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {B8CBEF6C-BD15-4749-B463-3AA5D6B7A691} + freeft + 10.0 + editor + + + + Application + true + ClangCL + Unicode + + + Application + false + ClangCL + true + Unicode + + + + + + + + + + + + + + + + + true + $(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\ + $(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\ + $(SolutionDir)\..\src;D:\libraries\x86_64\include;$(IncludePath) + editor + + + false + $(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\ + $(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\ + $(SolutionDir)\..\src;D:\libraries\x86_64\include;$(IncludePath) + editor + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpplatest + /wd4800 /wd4244 /wd4521 -Woverloaded-virtual -Wnon-virtual-dtor -Wno-reorder -Wuninitialized -Wno-unused-function -Werror=switch -Werror=delete-incomplete -Wno-unused-variable -Wno-unused-parameter -Wparentheses -Wno-overloaded-virtual -Wconstant-conversion -Werror=return-type -Werror=init-self -Werror=uninitialized -Wno-undefined-inline -Wno-unqualified-std-cast-call -Wno-unqualified-std-cast-call %(AdditionalOptions) + $(IntDir) + true + false + + + Console + true + %(AdditionalDependencies) + $(ProjectDir)..\$(TargetName)_dbg$(TargetExt) + + + PerMonitorHighDPIAware + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpplatest + /wd4800 /wd4244 /wd4521 -Woverloaded-virtual -Wnon-virtual-dtor -Wno-reorder -Wuninitialized -Wno-unused-function -Werror=switch -Werror=delete-incomplete -Wno-unused-variable -Wno-unused-parameter -Wparentheses -Wno-overloaded-virtual -Wconstant-conversion -Werror=return-type -Werror=init-self -Werror=uninitialized -Wno-undefined-inline -Wno-unqualified-std-cast-call -Wno-unqualified-std-cast-call %(AdditionalOptions) + $(IntDir) + true + false + + + Console + true + true + true + %(AdditionalDependencies) + $(ProjectDir)..\$(TargetName)$(TargetExt) + + + PerMonitorHighDPIAware + + + + + {d58f34be-ffcb-485f-9294-460ea261d0ed} + + + {d43b667a-d8cf-47a1-a576-fc05e7e6ca7b} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/windows/freeft_editor.vcxproj.filters b/windows/freeft_editor.vcxproj.filters new file mode 100644 index 00000000..b8bc44f0 --- /dev/null +++ b/windows/freeft_editor.vcxproj.filters @@ -0,0 +1,66 @@ + + + + + {38ba9653-9cf3-4952-92b0-c32375e37b39} + + + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + lib + + + \ No newline at end of file diff --git a/windows/freeft_lib.vcxproj b/windows/freeft_lib.vcxproj index 8ad48ba9..ec07e7bd 100644 --- a/windows/freeft_lib.vcxproj +++ b/windows/freeft_lib.vcxproj @@ -61,7 +61,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + FWK_PARANOID;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpplatest /wd4800 /wd4244 /wd4521 -Woverloaded-virtual -Wnon-virtual-dtor -Wno-reorder -Wuninitialized -Wno-unused-function -Werror=switch -Werror=delete-incomplete -Wno-unused-variable -Wno-unused-parameter -Wparentheses -Wno-overloaded-virtual -Wconstant-conversion -Werror=return-type -Werror=init-self -Werror=uninitialized -Wno-undefined-inline -Wno-unqualified-std-cast-call -Wno-unqualified-std-cast-call %(AdditionalOptions)