diff --git a/CMakeLists.txt b/CMakeLists.txt index 7feb7f8..bfaefd4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ macro(manual_download) set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "" FORCE) set(BUILD_EXTERNAL OFF CACHE BOOL "" FORCE) set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE) + set(USE_MSVC_RUNTIME_LIBRARY_DLL ON CACHE BOOL "" FORCE) add_definitions(-DLUA_USE_APPLE) diff --git a/engine/asset/include/asset.hpp b/engine/asset/include/asset.hpp index 86dd681..1fe35b9 100644 --- a/engine/asset/include/asset.hpp +++ b/engine/asset/include/asset.hpp @@ -13,7 +13,7 @@ namespace std { template <> struct hash { std::size_t operator()(const file::Path& k) const { - return hash()(k); + return (std::hash()(k.string())); } }; } diff --git a/engine/asset/include/material_nodes.hpp b/engine/asset/include/material_nodes.hpp index 444f160..57a8f08 100644 --- a/engine/asset/include/material_nodes.hpp +++ b/engine/asset/include/material_nodes.hpp @@ -1,8 +1,8 @@ #pragma once #include "renderer.hpp" +#include "assetptr.hpp" -class Texture; class MaterialNode; enum class DataType { @@ -29,6 +29,8 @@ inline bool operator==(const MaterialConnector& a, const MaterialConnector& b) { return a.name == b.name; } +class Texture; + struct MaterialProperty { std::string name; DataType type; diff --git a/engine/asset/src/asset.cpp b/engine/asset/src/asset.cpp index a3ce23c..22903f1 100644 --- a/engine/asset/src/asset.cpp +++ b/engine/asset/src/asset.cpp @@ -30,7 +30,7 @@ std::unique_ptr load_mesh(const file::Path path) { } auto mesh = std::make_unique(); - mesh->path = path; + mesh->path = path.string(); enum MeshType : int { Static, @@ -221,7 +221,7 @@ std::unique_ptr load_texture(const file::Path path) { Expects(height > 0); auto texture = std::make_unique(); - texture->path = path; + texture->path = path.string(); texture->width = width; texture->height = height; @@ -264,7 +264,7 @@ std::unique_ptr load_material(const file::Path path) { file->read_as_stream() >> j; auto mat = std::make_unique(); - mat->path = path; + mat->path = path.string(); if(!j.count("version") || j["version"] != 2) { console::error(System::Core, "Material {} failed the version check!", path); diff --git a/engine/core/include/components.hpp b/engine/core/include/components.hpp index 285e9c1..025b139 100755 --- a/engine/core/include/components.hpp +++ b/engine/core/include/components.hpp @@ -1,7 +1,6 @@ #pragma once #include "assetptr.hpp" -#include "screen.hpp" class btCollisionShape; class btRigidBody; @@ -93,12 +92,16 @@ struct Light { struct Camera { float fov = 75.0f; - float near = 0.1f; - float exposure = 1.0; + float near = 1.0f; + float exposure = 1.0f; Matrix4x4 view, perspective; }; +namespace ui { + class Screen; +} + struct UI { int width = 1920, height = 1080; diff --git a/engine/core/include/engine.hpp b/engine/core/include/engine.hpp index 6586d4d..8fefd67 100755 --- a/engine/core/include/engine.hpp +++ b/engine/core/include/engine.hpp @@ -8,7 +8,7 @@ #include #include -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) #include #endif @@ -199,7 +199,7 @@ public: @param identifier The identifier of the new window. @param extent The extent of the window. */ - void add_window(void* native_handle, const int identifier, const Extent extent); + void add_window(void* native_handle, const int identifier, const prism::Extent extent); /** Removes the window from engine management. Should be called before the window is actually closed. @param identifier The identifier of the window to remove. @@ -210,7 +210,7 @@ public: @param identifier The window that has been resized. @param extent The new extent of the window. */ - void resize(const int identifier, const Extent extent); + void resize(const int identifier, const prism::Extent extent); /** Called when a key has been pressed. @param keyCode A platform-specific key code. @@ -231,7 +231,7 @@ public: @param offset The mouse position relative to the window where the click occured. @note This function is only intended for debug purposes and all production code should be using the Input system instead. */ - void process_mouse_down(const int button, const Offset offset); + void process_mouse_down(const int button, const prism::Offset offset); /** Pushes a UI event for the current screen. Does nothing if there is no screen set. @param name The name of the event. @@ -323,7 +323,7 @@ public: /// If physics should upate. This is a control indepentent of the pause state. bool update_physics = true; -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) sol::state lua; #endif @@ -349,7 +349,7 @@ private: struct Window { int identifier = -1; - Extent extent; + prism::Extent extent; bool quitRequested = false; std::unique_ptr renderer = nullptr; diff --git a/engine/core/include/file.hpp b/engine/core/include/file.hpp index 75eb545..c266e0a 100755 --- a/engine/core/include/file.hpp +++ b/engine/core/include/file.hpp @@ -7,6 +7,8 @@ #include #include +#include "log.hpp" + namespace file { enum class Domain { System, @@ -130,4 +132,11 @@ namespace file { inline Path internal_domain = "/internal", app_domain = "/app"; } +namespace console { + inline void internal_format(std::string& msg, const file::Path& arg) { + auto pos = msg.find_first_of("{}"); + msg.replace(pos, 2, arg.string()); + } +} + inline std::array domain_data; diff --git a/engine/core/include/physics.hpp b/engine/core/include/physics.hpp index 81bb0c3..740683e 100755 --- a/engine/core/include/physics.hpp +++ b/engine/core/include/physics.hpp @@ -1,15 +1,7 @@ #pragma once -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Weverything" - -#if defined(PLATFORM_MACOS) || defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) #include -#else -#include -#endif #include -#pragma clang diagnostic pop #include "vector.hpp" #include "object.hpp" diff --git a/engine/core/include/platform.hpp b/engine/core/include/platform.hpp index 3fc81e6..281057e 100755 --- a/engine/core/include/platform.hpp +++ b/engine/core/include/platform.hpp @@ -73,7 +73,7 @@ namespace platform { @note On platforms that do not support the Windowing feature, calling open_window more than once is not supported. In this case, the same identifier is returned. @return A valid window identifier. */ - int open_window(const std::string_view title, const Rectangle rect, const WindowFlags flags); + int open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags); /** Closes a window. @param index The window to close. @@ -90,19 +90,19 @@ namespace platform { float get_monitor_dpi(); /// Get the monitor resolution. - Rectangle get_monitor_resolution(); + prism::Rectangle get_monitor_resolution(); /// Get the monitor work area. For example on macOS this may exclude the areas of the menu bar and dock. - Rectangle get_monitor_work_area(); + prism::Rectangle get_monitor_work_area(); /// Get the window position. - Offset get_window_position(const int index); + prism::Offset get_window_position(const int index); /// Get the window size, note that in hidpi scenarios this is the non-scaled resolution. - Extent get_window_size(const int index); + prism::Extent get_window_size(const int index); /// Get the window's drawable size. Always use this instead of manually multiplying the window size by the content scale. - Extent get_window_drawable_size(const int index); + prism::Extent get_window_drawable_size(const int index); /// Query whether or not the window is focused. bool is_window_focused(const int index); @@ -111,10 +111,10 @@ namespace platform { void set_window_focused(const int index); /// Sets the window position to the offset provided. - void set_window_position(const int index, const Offset offset); + void set_window_position(const int index, const prism::Offset offset); /// Sets the window to the specified size. The platform will handle the subsequent resize events. - void set_window_size(const int index, const Extent extent); + void set_window_size(const int index, const prism::Extent extent); /// Sets the window title. void set_window_title(const int index, const std::string_view title); @@ -126,10 +126,10 @@ namespace platform { int get_keycode(const InputButton key); /// Returns the current moue cursor position, relative to the window. - Offset get_cursor_position(); + prism::Offset get_cursor_position(); /// Returns the current moue cursor position, relative to the monitor. - Offset get_screen_cursor_position(); + prism::Offset get_screen_cursor_position(); /// Queries whether or not the mouse button requested is pressed or not. bool get_mouse_button_down(const int button); diff --git a/engine/core/include/scene.hpp b/engine/core/include/scene.hpp index f719f18..b8989f6 100755 --- a/engine/core/include/scene.hpp +++ b/engine/core/include/scene.hpp @@ -5,7 +5,7 @@ #include #include -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) #include #endif @@ -258,7 +258,7 @@ public: // script std::string script_path; -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) sol::environment env; #endif }; diff --git a/engine/core/include/screen.hpp b/engine/core/include/screen.hpp index 14f4261..ed5ba45 100755 --- a/engine/core/include/screen.hpp +++ b/engine/core/include/screen.hpp @@ -5,7 +5,7 @@ #include #include -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) #include #endif @@ -36,7 +36,7 @@ namespace ui { void add_listener(const std::string& id, std::function callback); - Extent extent; + prism::Extent extent; bool view_changed = false; GFXBuffer* glyph_buffer = nullptr; @@ -45,7 +45,7 @@ namespace ui { std::string script_path; -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) sol::environment env; #endif }; diff --git a/engine/core/src/engine.cpp b/engine/core/src/engine.cpp index 68462bf..bf16786 100755 --- a/engine/core/src/engine.cpp +++ b/engine/core/src/engine.cpp @@ -148,7 +148,7 @@ Scene* Engine::load_scene(const file::Path path) { for(auto& [obj, toParent] : parentQueue) scene->get(obj).parent = scene->find_object(toParent); -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) scene->env = sol::environment(lua, sol::create, lua.globals()); scene->env["scene"] = scene.get(); @@ -163,7 +163,7 @@ Scene* Engine::load_scene(const file::Path path) { _scenes.push_back(std::move(scene)); _current_scene = _scenes.back().get(); - _path_to_scene[path] = _scenes.back().get(); + _path_to_scene[path.string()] = _scenes.back().get(); return _scenes.back().get(); } @@ -402,7 +402,7 @@ void Engine::save_prefab(const Object root, const std::string_view path) { out << j; } -void Engine::add_window(void* native_handle, const int identifier, const Extent extent) { +void Engine::add_window(void* native_handle, const int identifier, const prism::Extent extent) { Expects(native_handle != nullptr); Expects(identifier >= 0); @@ -429,7 +429,7 @@ void Engine::remove_window(const int identifier) { }); } -void Engine::resize(const int identifier, const Extent extent) { +void Engine::resize(const int identifier, const prism::Extent extent) { Expects(identifier >= 0); auto window = get_window(identifier); @@ -466,7 +466,7 @@ void Engine::process_key_up(const unsigned int keyCode) { _imgui->process_key_up(keyCode); } -void Engine::process_mouse_down(const int button, const Offset offset) { +void Engine::process_mouse_down(const int button, const prism::Offset offset) { Expects(offset.x >= 0); Expects(offset.y >= 0); @@ -820,7 +820,7 @@ void Engine::stop_animation(Object target) { } void Engine::create_lua_interface() { -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table, sol::lib::string, sol::lib::math); lua.new_usertype("Cutscene"); diff --git a/engine/core/src/file.cpp b/engine/core/src/file.cpp index 5b0d2b3..8e4ef99 100755 --- a/engine/core/src/file.cpp +++ b/engine/core/src/file.cpp @@ -23,7 +23,7 @@ std::optional file::open(const file::Path path, const bool binary_mo fixed_path = domain_data[static_cast(Domain::Internal)] / path.lexically_relative(root_path(path)); } - FILE* file = fopen(fixed_path.c_str(), binary_mode ? "rb" : "r"); + FILE* file = fopen(fixed_path.string().c_str(), binary_mode ? "rb" : "r"); if(file == nullptr) { console::error(System::File, "Failed to open file handle from {}!", path); return {}; diff --git a/engine/core/src/screen.cpp b/engine/core/src/screen.cpp index b46afed..6886ee2 100755 --- a/engine/core/src/screen.cpp +++ b/engine/core/src/screen.cpp @@ -78,7 +78,7 @@ void ui::Screen::process_mouse(const int x, const int y) { Expects(x >= 0); Expects(y >= 0); -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) for(auto& element : elements) { if(x > element.absolute_x && y > element.absolute_y && @@ -196,7 +196,7 @@ ui::Screen::Screen(const file::Path path) { elements.push_back(ue); } -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) env = sol::environment(engine->lua, sol::create, engine->lua.globals()); env["screen"] = this; @@ -213,7 +213,7 @@ void ui::Screen::add_listener(const std::string& id, std::function callb } void ui::Screen::process_event(const std::string& type, const std::string data) { -#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) +#if !defined(PLATFORM_IOS) && !defined(PLATFORM_TVOS) && !defined(PLATFORM_WINDOWS) auto func = env["process_event"]; func(type, data); #endif diff --git a/engine/gfx/CMakeLists.txt b/engine/gfx/CMakeLists.txt index 5845c7c..ebe5354 100755 --- a/engine/gfx/CMakeLists.txt +++ b/engine/gfx/CMakeLists.txt @@ -2,6 +2,7 @@ set(CMAKE_FOLDER "GFX Backends") add_library(GFX INTERFACE) target_include_directories(GFX INTERFACE public) +target_link_libraries(GFX INTERFACE Utility) add_custom_target(GFXInterface SOURCES public/gfx.hpp diff --git a/engine/gfx/public/gfx_commandbuffer.hpp b/engine/gfx/public/gfx_commandbuffer.hpp index 3f2a370..b6cefcd 100755 --- a/engine/gfx/public/gfx_commandbuffer.hpp +++ b/engine/gfx/public/gfx_commandbuffer.hpp @@ -18,7 +18,7 @@ struct GFXRenderPassBeginInfo { float r = 0.0f, g = 0.0f, b = 0.0f, a = 0.0f; } clear_color; - Rectangle render_area; + prism::Rectangle render_area; GFXRenderPass* render_pass = nullptr; GFXFramebuffer* framebuffer = nullptr; @@ -132,7 +132,7 @@ struct GFXDrawCommand { } set_viewport; struct SetScissorData { - Rectangle rect; + prism::Rectangle rect; } set_scissor; struct GenerateMipmapData { @@ -284,7 +284,7 @@ public: commands.push_back(command); } - void set_scissor(const Rectangle rect) { + void set_scissor(const prism::Rectangle rect) { GFXDrawCommand command; command.type = GFXCommandType::SetScissor; command.data.set_scissor.rect = rect; diff --git a/engine/gfx/vulkan/include/gfx_vulkan.hpp b/engine/gfx/vulkan/include/gfx_vulkan.hpp index 1b8ac44..27a5e46 100755 --- a/engine/gfx/vulkan/include/gfx_vulkan.hpp +++ b/engine/gfx/vulkan/include/gfx_vulkan.hpp @@ -52,7 +52,7 @@ public: // misc operations GFXSize get_alignment(const GFXSize size) override; - void render(GFXCommandBuffer* command_buffer, const int identifier) override; + void submit(GFXCommandBuffer* command_buffer, const int identifier) override; private: void createInstance(std::vector layers, std::vector extensions); diff --git a/engine/gfx/vulkan/src/gfx_vulkan.cpp b/engine/gfx/vulkan/src/gfx_vulkan.cpp index 8e41fed..7512d0a 100755 --- a/engine/gfx/vulkan/src/gfx_vulkan.cpp +++ b/engine/gfx/vulkan/src/gfx_vulkan.cpp @@ -542,16 +542,16 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate vkDeviceWaitIdle(device); // setup shader modules - auto vertex_shader = file::read_file(FileDomain::ShaderData, std::string(info.shaders.vertex_path.data()) + ".spv"); + auto vertex_shader = file::open(file::internal_domain / (std::string(info.shaders.vertex_path) + ".spv")); vertex_shader->read_all(); - auto fragment_shader = file::read_file(FileDomain::ShaderData, std::string(info.shaders.fragment_path.data()) + ".spv"); + auto fragment_shader = file::open(file::internal_domain / (std::string(info.shaders.fragment_path) + ".spv")); fragment_shader->read_all(); - auto vertex_module = createShaderModule(vertex_shader->unsigned_data(), vertex_shader->size()); + auto vertex_module = createShaderModule(vertex_shader->cast_data(), vertex_shader->size()); name_object(device, VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)vertex_module, info.shaders.vertex_path); - auto fragment_module = createShaderModule(fragment_shader->unsigned_data(), fragment_shader->size()); + auto fragment_module = createShaderModule(fragment_shader->cast_data(), fragment_shader->size()); name_object(device, VK_OBJECT_TYPE_SHADER_MODULE, (uint64_t)fragment_module, info.shaders.fragment_path); VkPipelineShaderStageCreateInfo vertShaderStageInfo = {}; @@ -754,7 +754,7 @@ GFXSize GFXVulkan::get_alignment(GFXSize size) { return (size + minUboAlignment / 2) & ~int(minUboAlignment - 1); } -void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) { +void GFXVulkan::submit(GFXCommandBuffer *command_buffer, const int identifier) { vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, std::numeric_limits::max()); uint32_t imageIndex = 0; @@ -831,8 +831,8 @@ void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) { vkCmdSetScissor(commandBuffers[imageIndex], 0, 1, &scissor); } - renderPassInfo.renderArea.offset = { command.data.set_render_pass.viewport.x, command.data.set_render_pass.viewport.y }; - renderPassInfo.renderArea.extent = { command.data.set_render_pass.viewport.width, command.data.set_render_pass.viewport.height }; + renderPassInfo.renderArea.offset = { command.data.set_render_pass.render_area.offset.x, command.data.set_render_pass.render_area.offset.y }; + renderPassInfo.renderArea.extent = { command.data.set_render_pass.render_area.extent.width, command.data.set_render_pass.render_area.extent.height }; std::vector clearColors; if (renderPass != nullptr) { @@ -888,7 +888,7 @@ void GFXVulkan::render(GFXCommandBuffer *command_buffer, const int identifier) { case GFXCommandType::SetPushConstant: { if(currentPipeline != nullptr) - vkCmdPushConstants(commandBuffers[imageIndex], currentPipeline->layout, VK_SHADER_STAGE_ALL, 0, command.data.set_push_constant.size, command.data.set_push_constant.bytes); + vkCmdPushConstants(commandBuffers[imageIndex], currentPipeline->layout, VK_SHADER_STAGE_ALL, 0, command.data.set_push_constant.size, command.data.set_push_constant.bytes.data()); } break; case GFXCommandType::BindShaderBuffer: diff --git a/engine/log/include/log.hpp b/engine/log/include/log.hpp index ca64ef7..7c53350 100755 --- a/engine/log/include/log.hpp +++ b/engine/log/include/log.hpp @@ -21,8 +21,12 @@ enum class Level { }; namespace console { - template - void internal_format(std::string& msg, const Arg& arg) { + inline void internal_format(std::string& msg, const std::string& arg) { + auto pos = msg.find_first_of("{}"); + msg.replace(pos, 2, arg); + } + + inline void internal_format(std::string& msg, const char*& arg) { auto pos = msg.find_first_of("{}"); msg.replace(pos, 2, arg); } @@ -33,7 +37,7 @@ namespace console { void internal_print(const Level level, const System system, const std::string_view format, Args&&... args) { auto msg = std::string(format); - ((internal_format(msg, args)), ...); + ((internal_format(msg, args)), ...); process_message(level, system, msg); } diff --git a/engine/renderer/include/DirStackIncluder.h b/engine/renderer/include/DirStackIncluder.h index 6055de1..f9ea572 100755 --- a/engine/renderer/include/DirStackIncluder.h +++ b/engine/renderer/include/DirStackIncluder.h @@ -136,6 +136,6 @@ protected: // If no path markers, return current working directory. // Otherwise, strip file name and return path leading up to it. virtual std::string getDirectory(const std::string) const { - return file::get_domain_path(file::Domain::Internal); + return file::get_domain_path(file::Domain::Internal).string(); } }; diff --git a/engine/renderer/include/gaussianhelper.hpp b/engine/renderer/include/gaussianhelper.hpp index 89d1e5b..b00b131 100755 --- a/engine/renderer/include/gaussianhelper.hpp +++ b/engine/renderer/include/gaussianhelper.hpp @@ -11,7 +11,7 @@ class GFXTexture; class GaussianHelper { public: - GaussianHelper(GFX* gfx, const Extent extent); + GaussianHelper(GFX* gfx, const prism::Extent extent); GFXTexture* render(GFXCommandBuffer* commandBuffer,GFXTexture* source); @@ -23,5 +23,5 @@ public: GFXFramebuffer* fboA = nullptr, *fboB = nullptr; private: - Extent extent; + prism::Extent extent; }; diff --git a/engine/renderer/include/imguipass.hpp b/engine/renderer/include/imguipass.hpp index f3da4b7..4c1d351 100755 --- a/engine/renderer/include/imguipass.hpp +++ b/engine/renderer/include/imguipass.hpp @@ -15,7 +15,7 @@ class ImGuiPass : public Pass { public: void initialize() override; - void resize(const Extent extent) override; + void resize(const prism::Extent extent) override; void render_post(GFXCommandBuffer* command_buffer, const int index) override; diff --git a/engine/renderer/include/pass.hpp b/engine/renderer/include/pass.hpp index 889b50a..bb288a9 100755 --- a/engine/renderer/include/pass.hpp +++ b/engine/renderer/include/pass.hpp @@ -17,7 +17,7 @@ public: virtual void initialize() {} - virtual void resize([[maybe_unused]] const Extent extent) {} + virtual void resize([[maybe_unused]] const prism::Extent extent) {} virtual void render_scene([[maybe_unused]] Scene& scene, [[maybe_unused]] GFXCommandBuffer* commandBuffer) {} diff --git a/engine/renderer/include/renderer.hpp b/engine/renderer/include/renderer.hpp index 4c27b8f..b7592f3 100755 --- a/engine/renderer/include/renderer.hpp +++ b/engine/renderer/include/renderer.hpp @@ -2,6 +2,8 @@ #include #include +#include + #include "file.hpp" #include "pass.hpp" #include "matrix.hpp" @@ -85,8 +87,8 @@ class Renderer { public: Renderer(GFX* gfx, const bool enable_imgui = true); - void resize(const Extent extent); - void resize_viewport(const Extent extent); + void resize(const prism::Extent extent); + void resize_viewport(const prism::Extent extent); void set_screen(ui::Screen* screen); void init_screen(ui::Screen* screen); @@ -145,15 +147,15 @@ public: GFXTexture* viewportColorTexture = nullptr; bool viewport_mode = false; - Extent viewport_extent; + prism::Extent viewport_extent; bool gui_only_mode = false; - Extent get_extent() const { + prism::Extent get_extent() const { return viewport_mode ? viewport_extent : extent; } - Extent get_render_extent() const { + prism::Extent get_render_extent() const { const auto extent = get_extent(); return {static_cast(std::max(int(extent.width * render_options.render_scale), 1)), @@ -186,7 +188,7 @@ private: void createBRDF(); GFX* gfx = nullptr; - Extent extent; + prism::Extent extent; ui::Screen* current_screen = nullptr; diff --git a/engine/renderer/include/smaapass.hpp b/engine/renderer/include/smaapass.hpp index 1821f58..9c7056d 100755 --- a/engine/renderer/include/smaapass.hpp +++ b/engine/renderer/include/smaapass.hpp @@ -26,7 +26,7 @@ private: void create_pipelines(); void create_offscreen_resources(); - Extent extent; + prism::Extent extent; Renderer* renderer = nullptr; GFXTexture* area_image = nullptr; diff --git a/engine/renderer/src/gaussianhelper.cpp b/engine/renderer/src/gaussianhelper.cpp index 4158563..b3727c2 100755 --- a/engine/renderer/src/gaussianhelper.cpp +++ b/engine/renderer/src/gaussianhelper.cpp @@ -3,7 +3,7 @@ #include "gfx_commandbuffer.hpp" #include "gfx.hpp" -GaussianHelper::GaussianHelper(GFX* gfx, const Extent extent) : extent(extent) { +GaussianHelper::GaussianHelper(GFX* gfx, const prism::Extent extent) : extent(extent) { // render pass GFXRenderPassCreateInfo renderPassInfo = {}; renderPassInfo.attachments.push_back(GFXPixelFormat::RGBA_32F); diff --git a/engine/renderer/src/imguipass.cpp b/engine/renderer/src/imguipass.cpp index c67ad49..e77c6ba 100755 --- a/engine/renderer/src/imguipass.cpp +++ b/engine/renderer/src/imguipass.cpp @@ -21,7 +21,7 @@ void ImGuiPass::initialize() { create_font_texture(); } -void ImGuiPass::resize(const Extent extent) { +void ImGuiPass::resize(const prism::Extent extent) { GFXGraphicsPipelineCreateInfo createInfo; createInfo.label = "ImGui"; createInfo.shaders.vertex_path = "imgui.vert"; diff --git a/engine/renderer/src/renderer.cpp b/engine/renderer/src/renderer.cpp index 8074eb3..2772bf0 100755 --- a/engine/renderer/src/renderer.cpp +++ b/engine/renderer/src/renderer.cpp @@ -97,7 +97,7 @@ Renderer::Renderer(GFX* gfx, const bool enable_imgui) : gfx(gfx) { createBRDF(); } -void Renderer::resize(const Extent extent) { +void Renderer::resize(const prism::Extent extent) { this->extent = extent; if(!viewport_mode) { @@ -117,7 +117,7 @@ void Renderer::resize(const Extent extent) { pass->resize(extent); } -void Renderer::resize_viewport(const Extent extent) { +void Renderer::resize_viewport(const prism::Extent extent) { this->viewport_extent = extent; createOffscreenResources(); diff --git a/engine/renderer/src/shadercompiler.cpp b/engine/renderer/src/shadercompiler.cpp index 5c00797..0f9c7bb 100755 --- a/engine/renderer/src/shadercompiler.cpp +++ b/engine/renderer/src/shadercompiler.cpp @@ -2,7 +2,7 @@ #include -#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) +#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) || defined(PLATFORM_WINDOWS) #include #include #include @@ -112,22 +112,20 @@ const TBuiltInResource DefaultTBuiltInResource = { /* .maxTaskWorkGroupSizeY_NV = */ 1, /* .maxTaskWorkGroupSizeZ_NV = */ 1, /* .maxMeshViewCountNV = */ 4, - -#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) - /* .maxDualSourceDrawBuffersEXT = */ 1, -#endif - - /* .limits = */ { - /* .nonInductiveForLoops = */ 1, - /* .whileLoops = */ 1, - /* .doWhileLoops = */ 1, - /* .generalUniformIndexing = */ 1, - /* .generalAttributeMatrixVectorIndexing = */ 1, - /* .generalVaryingIndexing = */ 1, - /* .generalSamplerIndexing = */ 1, - /* .generalVariableIndexing = */ 1, - /* .generalConstantMatrixVectorIndexing = */ 1, -}}; + /* .maxDualSourceDrawBuffersEXT = */ 4, + + /* .limits = */ TLimits{ + /* .nonInductiveForLoops = */ true, + /* .whileLoops = */ true, + /* .doWhileLoops = */ true, + /* .generalUniformIndexing = */ true, + /* .generalAttributeMatrixVectorIndexing = */ true, + /* .generalVaryingIndexing = */ true, + /* .generalSamplerIndexing = */ true, + /* .generalVariableIndexing = */ true, + /* .generalConstantMatrixVectorIndexing = */ true, + }}; + const std::vector CompileGLSL(const std::string& filename, EShLanguage ShaderType, bool skinned, bool cubemap) { std::string newString = "#version 430 core\n"; @@ -163,7 +161,7 @@ const std::vector CompileGLSL(const std::string& filename, EShLang EShMessages messages = (EShMessages) (EShMsgSpvRules); DirStackFileIncluder includer; - includer.pushExternalLocalDirectory(file::get_domain_path(file::Domain::Internal)); + includer.pushExternalLocalDirectory(file::get_domain_path(file::Domain::Internal).string()); if (!Shader.parse(&Resources, 100, false, (EShMessages)0, includer)) { std::cout << Shader.getInfoLog() << std::endl; diff --git a/engine/utility/include/common.hpp b/engine/utility/include/common.hpp index 24fb256..b64afb5 100755 --- a/engine/utility/include/common.hpp +++ b/engine/utility/include/common.hpp @@ -2,28 +2,30 @@ #include -/// A 2D extent. -struct Extent { - Extent() : width(0), height(0) {} - Extent(const uint32_t width, const uint32_t height) : width(width), height(height) {} - - uint32_t width = 0, height = 0; -}; +namespace prism { + /// A 2D extent. + struct Extent { + Extent() : width(0), height(0) {} + Extent(const uint32_t width, const uint32_t height) : width(width), height(height) {} -/// A 2D offset. -struct Offset { - Offset() : x(0), y(0) {} - Offset(const int32_t x, const int32_t y) : x(x), y(y) {} - - int32_t x = 0, y = 0; -}; + uint32_t width = 0, height = 0; + }; -/// A 2D rectangle defined by a offset and an etent. -struct Rectangle { - Rectangle() {} - Rectangle(const Offset offset, const Extent extent) : offset(offset), extent(extent) {} - Rectangle(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) : offset(x, y), extent(width, height) {} - - Offset offset; - Extent extent; -}; + /// A 2D offset. + struct Offset { + Offset() : x(0), y(0) {} + Offset(const int32_t x, const int32_t y) : x(x), y(y) {} + + int32_t x = 0, y = 0; + }; + + /// A 2D rectangle defined by a offset and an etent. + struct Rectangle { + Rectangle() {} + Rectangle(const Offset offset, const Extent extent) : offset(offset), extent(extent) {} + Rectangle(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) : offset(x, y), extent(width, height) {} + + Offset offset; + Extent extent; + }; +} diff --git a/extern/imgui/include/imconfig.h b/extern/imgui/include/imconfig.h index 3fc7f5e..0ac4faa 100644 --- a/extern/imgui/include/imconfig.h +++ b/extern/imgui/include/imconfig.h @@ -68,10 +68,10 @@ // This will be inlined as part of ImVec2 and ImVec4 class declarations. #define IM_VEC2_CLASS_EXTRA \ - ImVec2(const Offset& f) { x = static_cast(f.x); y = static_cast(f.y); } \ - operator Offset() const { return Offset(static_cast(x), static_cast(y)); } \ - ImVec2(const Extent& f) { x = static_cast(f.width); y = static_cast(f.height); } \ - operator Extent() const { return Extent(static_cast(x), static_cast(y)); } + ImVec2(const prism::Offset& f) { x = static_cast(f.x); y = static_cast(f.y); } \ + operator prism::Offset() const { return prism::Offset(static_cast(x), static_cast(y)); } \ + ImVec2(const prism::Extent& f) { x = static_cast(f.width); y = static_cast(f.height); } \ + operator prism::Extent() const { return prism::Extent(static_cast(x), static_cast(y)); } /*#define IM_VEC4_CLASS_EXTRA \ ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ diff --git a/platforms/windows/file.cpp b/platforms/windows/file.cpp index f1564b2..8a71936 100755 --- a/platforms/windows/file.cpp +++ b/platforms/windows/file.cpp @@ -1,63 +1,9 @@ #include "file.hpp" -#include - -#include "string_utils.hpp" - -#include "log.hpp" - -struct DomainData { - std::string path; -}; - -std::array domain_data; - -void file::initialize_domain(const FileDomain domain, const AccessMode mode, const std::string_view path) { - domain_data[(int)domain].path = path; +void file::set_domain_path(const file::Domain domain, const file::Path path) { + domain_data[(int)domain] = path.string(); } -std::string file::clean_path(const std::string_view path) { - auto p = replaceSubstring(std::string(path), "%20", " "); - p = replaceSubstring(p, "%7C", "|"); - - // this is a path returned by an editor, so skip it - // TODO: find a better way to do this!! NOO!! - if (p.find("file:///") != std::string::npos) - return p.substr(7, p.length()); - else - return p; -} - -/* - * converts an absolute path to a domain relative one - */ -std::string file::get_relative_path(const FileDomain domain, const std::string_view path) { - auto p = removeSubstring(std::string(path), domain_data[(int)domain].path + "/"); - - return p; -} - -std::string file::get_writeable_path(const std::string_view path) { - return std::string(path); -} - -std::optional file::read_file(const FileDomain domain, const std::string_view path, bool binary_mode) { - auto s = std::string(path); - s = domain_data[(int)domain].path + "/" + s; - - FILE* file = fopen(s.c_str(), binary_mode ? "rb" : "r"); - if (file == nullptr) { - console::error(System::File, "Failed to open file handle from {}!", s); - return {}; - } - - File f; - f.handle = file; - - return f; -} - -std::string file::get_file_path(const FileDomain domain, const std::string_view path) { - auto s = std::string(path); - return domain_data[(int)domain].path + "/" + s; -} +file::Path file::get_writeable_directory() { + return ""; +} \ No newline at end of file diff --git a/platforms/windows/main.cpp.in b/platforms/windows/main.cpp.in index a5bc177..096b834 100755 --- a/platforms/windows/main.cpp.in +++ b/platforms/windows/main.cpp.in @@ -2,57 +2,22 @@ #define UNICODE #endif -#include +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include #include +#undef far +#undef near #include "platform.hpp" #include -#include -#include -typedef HGLRC WINAPI wglCreateContextAttribsARB_type(HDC hdc, HGLRC hShareContext, - const int *attribList); -wglCreateContextAttribsARB_type *wglCreateContextAttribsARB; - -// See https://www.opengl.org/registry/specs/ARB/wgl_create_context.txt for all values -#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 - -#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 - -typedef BOOL WINAPI wglChoosePixelFormatARB_type(HDC hdc, const int *piAttribIList, - const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -wglChoosePixelFormatARB_type *wglChoosePixelFormatARB; - -// See https://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt for all values -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 - -#define WGL_FULL_ACCELERATION_ARB 0x2027 -#define WGL_TYPE_RGBA_ARB 0x202B - -#if @IS_GAME@ -#include <@GAME_INCLUDE@> -#else -#include <@EDITOR_INCLUDE@> -#endif +#include <@APP_INCLUDE@> #include GFX* ginterface = nullptr; -#if @IS_GAME@ -@GAME_CLASS@* game = nullptr; -#else -@EDITOR_CLASS@* editor = nullptr; -#endif +@APP_CLASS@* app = nullptr; HINSTANCE instance = NULL; HWND window = NULL; @@ -64,11 +29,7 @@ int defaultWidth, defaultHeight; bool shouldConfineMouse = false; -#include - -#pragma comment (lib, "opengl32.lib") - -const wchar_t CLASS_NAME[] = L"@GAME_NAME@"; +const wchar_t CLASS_NAME[] = L"@APP_NAME@"; wchar_t* convertToUnicode(const char* str) { size_t ret = 0; @@ -81,24 +42,22 @@ wchar_t* convertToUnicode(const char* str) { return buf; } -void platform::openWindow(const char* title, int x, int y, int width, int height, WindowFlags flags) { - RECT wr = {0, 0, width, height}; +int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) { + RECT wr = {rect.offset.x, rect.offset.y, rect.extent.width, rect.extent.height}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); - defaultWidth = width; - defaultHeight = height; + defaultWidth = rect.extent.width; + defaultHeight = rect.extent.height; - std::string new_title = title + std::string(" (") + ginterface->getName() + ")"; - - wchar_t* title_uni = convertToUnicode(new_title.c_str()); + wchar_t* title_uni = convertToUnicode(title.data()); window = CreateWindowEx( 0, CLASS_NAME, title_uni, flags == WindowFlags::Resizable ? WS_OVERLAPPEDWINDOW : (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX), // Window style - x, - y, + rect.offset.x, + rect.offset.y, wr.right - wr.left, wr.bottom - wr.top, NULL, @@ -111,16 +70,18 @@ void platform::openWindow(const char* title, int x, int y, int width, int height ShowWindow(window, cmdShow); - engine->addWindow(window, width, height); + engine->add_window(window, 0, rect.extent); + + return 0; } -void platform::closeWindow() { +void platform::close_window(const int identifier) { // does nothing } bool showingCursor = true; -void platform::setCaptureMouse(bool capture) { +void platform::capture_mouse(const bool capture) { shouldConfineMouse = capture; // the reason why we do this is because windows expects a ShowCursor(false) to be followed by a ShowCursor(true), @@ -135,7 +96,7 @@ void platform::setCaptureMouse(bool capture) { } } -std::tuple platform::getCursorPosition() { +prism::Offset platform::get_cursor_position() { POINT p; GetCursorPos(&p); ScreenToClient(window, &p); @@ -143,105 +104,26 @@ std::tuple platform::getCursorPosition() { return {p.x, p.y}; } -std::tuple platform::getWindowPosition() { +prism::Offset platform::get_window_position(const int identifier) { RECT rect; GetWindowRect(window, &rect); return {rect.left, rect.top}; } -std::tuple platform::getWindowSize() { +prism::Extent platform::get_window_size(const int identifier) { RECT rect; GetClientRect(window, &rect); int width = rect.right - rect.left; int height = rect.bottom- rect.top; - return {width, height}; + return {static_cast(width), static_cast(height)}; } -static void -init_opengl_extensions(void) -{ - // Before we can load extensions, we need a dummy OpenGL context, created using a dummy window. - // We use a dummy window because you can only set the pixel format for a window once. For the - // real window, we want to use wglChoosePixelFormatARB (so we can potentially specify options - // that aren't available in PIXELFORMATDESCRIPTOR), but we can't load and use that before we - // have a context. - WNDCLASSA window_class = {}; - window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - window_class.lpfnWndProc = DefWindowProcA; - window_class.hInstance = GetModuleHandle(0); - window_class.lpszClassName = "Dummy_WGL_djuasiodwa"; - - if (!RegisterClassA(&window_class)) { - fmt::print("Failed to register dummy OpenGL window.\n"); - } - - HWND dummy_window = CreateWindowExA( - 0, - window_class.lpszClassName, - "Dummy OpenGL Window", - 0, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - 0, - 0, - window_class.hInstance, - 0); - - if (!dummy_window) { - fmt::print("Failed to create dummy OpenGL window.\n"); - } - - HDC dummy_dc = GetDC(dummy_window); - - PIXELFORMATDESCRIPTOR pfd = {}; - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - pfd.cColorBits = 32; - pfd.cAlphaBits = 8; - pfd.iLayerType = PFD_MAIN_PLANE; - pfd.cDepthBits = 24; - pfd.cStencilBits = 8; - - int pixel_format = ChoosePixelFormat(dummy_dc, &pfd); - if (!pixel_format) { - fmt::print("Failed to find a suitable pixel format.\n"); - } - if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) { - fmt::print("Failed to set the pixel format."); - } - - HGLRC dummy_context = wglCreateContext(dummy_dc); - if (!dummy_context) { - fmt::print("Failed to create a dummy OpenGL rendering context.\n"); - } - - if (!wglMakeCurrent(dummy_dc, dummy_context)) { - fmt::print("Failed to activate dummy OpenGL rendering context.\n"); - } - - wglCreateContextAttribsARB = (wglCreateContextAttribsARB_type*)wglGetProcAddress( - "wglCreateContextAttribsARB"); - wglChoosePixelFormatARB = (wglChoosePixelFormatARB_type*)wglGetProcAddress( - "wglChoosePixelFormatARB"); - - wglMakeCurrent(dummy_dc, 0); - wglDeleteContext(dummy_context); - ReleaseDC(dummy_window, dummy_dc); - DestroyWindow(dummy_window); -} - - LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) -{ +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) { AllocConsole(); FILE* stream; freopen_s(&stream, "CONOUT$", "w", stdout); @@ -258,30 +140,21 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow instance = hInstance; cmdShow = nCmdShow; - engine = new Engine(); + engine = new Engine(0, nullptr); ginterface = new GFXVulkan(); - if(ginterface->initialize()) { - engine->setGFX(ginterface); + if(ginterface->initialize(GFXCreateInfo())) { + engine->set_gfx(ginterface); } else { return -1; } - #if @IS_GAME@ - game = new @GAME_CLASS@(); - engine->setGame(game); - #else - editor = new @EDITOR_CLASS@(); - engine->setEditor(editor); - #endif + app = new @APP_CLASS@(); + engine->set_app(app); - app::open(engine); + app_main(engine); - #if @IS_GAME@ - game->initializeRender(); - #else - editor->initializeRender(); - #endif + app->initialize_render(); MSG msg = { }; while (GetMessage(&msg, NULL, 0, 0)) @@ -290,11 +163,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow DispatchMessage(&msg); } - #if @IS_GAME@ - delete game; - #else - delete editor; - #endif + delete app; delete ginterface; delete engine; @@ -308,59 +177,9 @@ int timeout = 0; LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { - case WM_CREATE: - { - if(ginterface->requiredContext() == GFXContext::OpenGL) { - fmt::print("Creating OpenGL context...\n"); - - init_opengl_extensions(); - - PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), - 1, - PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags - PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette. - 32, // Colordepth of the framebuffer. - 0, 0, 0, 0, 0, 0, - 0, - 0, - 0, - 0, 0, 0, 0, - 24, // Number of bits for the depthbuffer - 8, // Number of bits for the stencilbuffer - 0, // Number of Aux buffers in the framebuffer. - PFD_MAIN_PLANE, - 0, - 0, 0, 0 - }; - - HDC ourWindowHandleToDeviceContext = GetDC(hwnd); - - int letWindowsChooseThisPixelFormat; - letWindowsChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext, &pfd); - SetPixelFormat(ourWindowHandleToDeviceContext,letWindowsChooseThisPixelFormat, &pfd); - - int attribs[] = - { - WGL_CONTEXT_MAJOR_VERSION_ARB, 4, - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - 0, - }; - - HGLRC ourOpenGLRenderingContext = wglCreateContextAttribsARB(ourWindowHandleToDeviceContext,0, attribs); - wglMakeCurrent (ourWindowHandleToDeviceContext, ourOpenGLRenderingContext); - - windowDC = GetDC(hwnd); - - MessageBoxA(0,(char*)glGetString(GL_VERSION), "OPENGL VERSION",0); - } - } - return 0; case WM_DESTROY: { - engine->prepareQuit(); + engine->prepare_quit(); PostQuitMessage(0); } return 0; @@ -388,19 +207,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) HCURSOR arrowCursor = LoadCursor(NULL, IDC_ARROW); SetCursor(arrowCursor); - #if @IS_GAME@ - - #else - editor->beginFrame(); - #endif + engine->begin_frame(1.0f / 60.0f); engine->update(1.0f / 60.0f); - engine->render(); + engine->render(0); - if(ginterface->requiredContext() == GFXContext::OpenGL) - SwapBuffers(windowDC); - - if(engine->isQuitting()) { - engine->prepareQuit(); + if(engine->is_quitting()) { + engine->prepare_quit(); PostQuitMessage(0); } } @@ -410,41 +222,17 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) int xPos = GET_X_LPARAM(lParam); int yPos = GET_Y_LPARAM(lParam); - engine->processMouse(0, xPos, yPos); - } - return 0; - case WM_LBUTTONUP: - { - engine->processMouseReleased(0); - } - return 0; - case WM_RBUTTONDOWN: - { - - engine->processMouse(1, 0, 0); - } - return 0; - case WM_RBUTTONUP: - { - engine->processMouseReleased(1); - } - return 0; - case WM_MOUSEMOVE: - { - int xPos = GET_X_LPARAM(lParam); - int yPos = GET_Y_LPARAM(lParam); - - engine->processMouseMove(xPos, yPos); + engine->process_mouse_down(0, {xPos, yPos}); } return 0; case WM_KEYDOWN: { - engine->processKey((unsigned int)wParam); + engine->process_key_down((unsigned int)wParam); } return 0; case WM_KEYUP: { - engine->processKeyUp((unsigned int)wParam); + engine->process_key_up((unsigned int)wParam); } return 0; case WM_SIZE: @@ -458,7 +246,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if(width == defaultWidth && height == defaultHeight) { // don't resize when the window was first created!! } else { - engine->resize(width, height); + engine->resize(0, {static_cast(width), static_cast(height)}); } } @@ -468,8 +256,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return DefWindowProc(hwnd, uMsg, wParam, lParam); } -void platform::setWindowTitle(const char* title) { - std::string new_title = title + std::string(" (") + ginterface->getName() + ")"; - - SetWindowTextA(window, new_title.c_str()); +void platform::set_window_title(const int identifier, const std::string_view title) { + SetWindowTextA(window, title.data()); } \ No newline at end of file diff --git a/platforms/windows/windows.cpp b/platforms/windows/windows.cpp index c20ef57..f52c051 100755 --- a/platforms/windows/windows.cpp +++ b/platforms/windows/windows.cpp @@ -39,7 +39,7 @@ int platform::get_keycode(const InputButton key) { return inputToKeyCode[key]; } -void platform::open_dialog(const bool existing, const std::function returnFunction) { +void platform::open_dialog(const bool existing, const std::function returnFunction, const bool openDirectory) { const auto openDialog = [returnFunction] { const int BUFSIZE = 1024; char buffer[BUFSIZE] = { 0 };