Skip to content

Commit

Permalink
Building editor under windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nadult committed Jan 14, 2025
1 parent d44f803 commit 6726f71
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
/data/gui
/media
/windows/.vs
*.vcxproj.user
/.vscode
*.vcxproj.user
73 changes: 46 additions & 27 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@

#include "res_manager.h"
#include "sys/config.h"
#include <fwk/gfx/gl_device.h>
#include <fwk/gfx/opengl.h>

#include "sys/gfx_device.h"

#include <fwk/sys/on_fail.h>
#include <fwk/vulkan/vulkan_window.h>

#include <fwk/libs_msvc.h>
#include <fwk/vulkan/vulkan_window.h>

#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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -284,6 +294,7 @@ class EditorWindow : public Window {

int m_left_width;
FilePath m_maps_path;
double m_start_time = getTime();
};

void preloadTiles() {
Expand Down Expand Up @@ -311,19 +322,27 @@ void preloadTiles() {
printf("\n");
}

int main(int argc, char **argv) {
Ex<int> 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;
}
2 changes: 1 addition & 1 deletion src/editor/entities_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions src/editor/group_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "gfx/drawing.h"
#include <algorithm>
#include <cstring>
#include <fwk/gfx/gl_texture.h>
#include <tuple>

using namespace game;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/editor/tiles_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -146,7 +146,7 @@ Ex<int> 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;
Expand Down
1 change: 1 addition & 0 deletions src/gfx/scene_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,5 @@ void SceneRenderer::render(Canvas2D &canvas) {

canvas.setScissorRect(none);
canvas.popViewMatrix();
canvas.setMaterial({});
}
14 changes: 10 additions & 4 deletions windows/freeft.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
145 changes: 145 additions & 0 deletions windows/freeft_editor.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{B8CBEF6C-BD15-4749-B463-3AA5D6B7A691}</ProjectGuid>
<RootNamespace>freeft</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>editor</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\libfwk\windows\shared_libraries.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\libfwk\windows\shared_libraries.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>
<IncludePath>$(SolutionDir)\..\src;D:\libraries\x86_64\include;$(IncludePath)</IncludePath>
<TargetName>editor</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\..\build\$(ProjectName)-$(Platform)-$(Configuration)\</IntDir>
<IncludePath>$(SolutionDir)\..\src;D:\libraries\x86_64\include;$(IncludePath)</IncludePath>
<TargetName>editor</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<AdditionalOptions>/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)</AdditionalOptions>
<ObjectFileName>$(IntDir)</ObjectFileName>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ExceptionHandling>false</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(ProjectDir)..\$(TargetName)_dbg$(TargetExt)</OutputFile>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<AdditionalOptions>/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)</AdditionalOptions>
<ObjectFileName>$(IntDir)</ObjectFileName>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ExceptionHandling>false</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(ProjectDir)..\$(TargetName)$(TargetExt)</OutputFile>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\libfwk\windows\libfwk.vcxproj">
<Project>{d58f34be-ffcb-485f-9294-460ea261d0ed}</Project>
</ProjectReference>
<ProjectReference Include="freeft_lib.vcxproj">
<Project>{d43b667a-d8cf-47a1-a576-fc05e7e6ca7b}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\editor.cpp" />
<ClCompile Include="..\src\editor\entities_editor.cpp" />
<ClCompile Include="..\src\editor\entities_pad.cpp" />
<ClCompile Include="..\src\editor\group_editor.cpp" />
<ClCompile Include="..\src\editor\group_pad.cpp" />
<ClCompile Include="..\src\editor\tiles_editor.cpp" />
<ClCompile Include="..\src\editor\tiles_pad.cpp" />
<ClCompile Include="..\src\editor\tile_group.cpp" />
<ClCompile Include="..\src\editor\tile_selector.cpp" />
<ClCompile Include="..\src\editor\view.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\editor\entities_editor.h" />
<ClInclude Include="..\src\editor\entities_pad.h" />
<ClInclude Include="..\src\editor\group_editor.h" />
<ClInclude Include="..\src\editor\group_pad.h" />
<ClInclude Include="..\src\editor\tiles_editor.h" />
<ClInclude Include="..\src\editor\tiles_pad.h" />
<ClInclude Include="..\src\editor\tile_group.h" />
<ClInclude Include="..\src\editor\tile_selector.h" />
<ClInclude Include="..\src\editor\view.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit 6726f71

Please sign in to comment.