From 3e4cf70c8e91dd6b326a343b7a51a4c43fa3c71c Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Mon, 15 Feb 2021 15:06:13 -0500 Subject: [PATCH] Fix compilation issues on GCC/Linux --- engine/core/src/engine.cpp | 2 +- engine/gfx/vulkan/src/gfx_vulkan.cpp | 4 +- engine/renderer/src/materialcompiler.cpp | 2 + engine/renderer/src/renderer.cpp | 2 +- engine/utility/CMakeLists.txt | 1 + engine/utility/include/utility.hpp | 3 +- engine/utility/src/string_utils.cpp | 2 + platforms/linux/file.cpp | 60 ++---------------------- platforms/linux/main.cpp.in | 43 +++++++++-------- 9 files changed, 39 insertions(+), 80 deletions(-) diff --git a/engine/core/src/engine.cpp b/engine/core/src/engine.cpp index 7d96e3b..3ab6093 100755 --- a/engine/core/src/engine.cpp +++ b/engine/core/src/engine.cpp @@ -348,7 +348,7 @@ void Engine::save_cutscene(const std::string_view path) { j["shots"].push_back(s); } - std::ofstream out(path); + std::ofstream out(path.data()); out << j; } diff --git a/engine/gfx/vulkan/src/gfx_vulkan.cpp b/engine/gfx/vulkan/src/gfx_vulkan.cpp index 5291022..a12c357 100755 --- a/engine/gfx/vulkan/src/gfx_vulkan.cpp +++ b/engine/gfx/vulkan/src/gfx_vulkan.cpp @@ -691,7 +691,7 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate const bool vertex_use_shader_source = info.shaders.vertex_path.empty(); if (vertex_use_shader_source) { - auto& vertex_shader_vector = info.shaders.vertex_src.as_bytecode(); + auto vertex_shader_vector = info.shaders.vertex_src.as_bytecode(); vertex_module = createShaderModule(vertex_shader_vector.data(), vertex_shader_vector.size() * sizeof(uint32_t)); } @@ -717,7 +717,7 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate const bool fragment_use_shader_source = info.shaders.fragment_path.empty(); if (fragment_use_shader_source) { - auto& fragment_shader_vector = info.shaders.fragment_src.as_bytecode(); + auto fragment_shader_vector = info.shaders.fragment_src.as_bytecode(); fragment_module = createShaderModule(fragment_shader_vector.data(), fragment_shader_vector.size() * sizeof(uint32_t)); } diff --git a/engine/renderer/src/materialcompiler.cpp b/engine/renderer/src/materialcompiler.cpp index 08e973d..c07c779 100755 --- a/engine/renderer/src/materialcompiler.cpp +++ b/engine/renderer/src/materialcompiler.cpp @@ -1,5 +1,7 @@ #include "materialcompiler.hpp" +#include + #include "file.hpp" #include "log.hpp" #include "engine.hpp" diff --git a/engine/renderer/src/renderer.cpp b/engine/renderer/src/renderer.cpp index ca9564c..c98d77f 100755 --- a/engine/renderer/src/renderer.cpp +++ b/engine/renderer/src/renderer.cpp @@ -414,7 +414,7 @@ void Renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj sceneInfo.lightspace = scene.lightSpace; sceneInfo.options = Vector4(1, 0, 0, 0); sceneInfo.camPos = scene.get(camera_object).get_world_position(); - sceneInfo.camPos.w = 2.0f * camera.near * std::tanf(camera.fov * 0.5f) * (static_cast(extent.width) / static_cast(extent.height)); + sceneInfo.camPos.w = 2.0f * camera.near * std::tan(camera.fov * 0.5f) * (static_cast(extent.width) / static_cast(extent.height)); sceneInfo.vp = camera.perspective * camera.view; for(const auto [obj, light] : scene.get_all()) { diff --git a/engine/utility/CMakeLists.txt b/engine/utility/CMakeLists.txt index 478ce2e..75323b9 100755 --- a/engine/utility/CMakeLists.txt +++ b/engine/utility/CMakeLists.txt @@ -14,3 +14,4 @@ set(SRC add_library(Utility ${SRC}) target_link_libraries(Utility PUBLIC Math magic_enum) target_include_directories(Utility PUBLIC include) +set_engine_properties(Utility) diff --git a/engine/utility/include/utility.hpp b/engine/utility/include/utility.hpp index adfddff..c3f512e 100755 --- a/engine/utility/include/utility.hpp +++ b/engine/utility/include/utility.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "vector.hpp" @@ -102,7 +103,7 @@ namespace utility { Vector3 linear = sRGB; for(auto& component : linear.data) { if(component > 0.04045f) { - component = std::powf((component + 0.055) / (1.055), 2.4f); + component = std::pow((component + 0.055) / (1.055), 2.4f); } else if (component <= 0.04045) { component /= 12.92f; } diff --git a/engine/utility/src/string_utils.cpp b/engine/utility/src/string_utils.cpp index 10547a7..56d7bdb 100644 --- a/engine/utility/src/string_utils.cpp +++ b/engine/utility/src/string_utils.cpp @@ -1,5 +1,7 @@ #include "string_utils.hpp" +#include + std::string remove_substring(const std::string_view string, const std::string_view substring) { std::string result(string); diff --git a/platforms/linux/file.cpp b/platforms/linux/file.cpp index e12da6d..ae7de43 100644 --- a/platforms/linux/file.cpp +++ b/platforms/linux/file.cpp @@ -1,63 +1,11 @@ #include "file.hpp" -#include - #include "string_utils.hpp" -#include "log.hpp" - -void file::initialize_domain(const FileDomain domain, const AccessMode mode, const std::string_view path) { - auto p = replace_substring(std::string(path), "{resource_dir}/", ""); - - domain_data[(int)domain] = file::clean_path(p); +void file::set_domain_path(const file::Domain domain, const file::Path path) { + domain_data[(int)domain] = replace_substring(path.string(), "{resource_dir}/", ""); } -std::string file::clean_path(const std::string_view path) { - auto p = replace_substring(std::string(path), "%20", " "); - p = replace_substring(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 = remove_substring(std::string(path), domain_data[(int)domain] + "/"); - - return p; -} - -/* - * Returns the path inside of the game's writable directory. - * path - the path to use. - */ -std::string file::get_writeable_path(const std::string_view path) { - return std::string(path.data()); -} - -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] + "/" + 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] + "/" + s; +file::Path file::get_writeable_directory() { + return ""; } diff --git a/platforms/linux/main.cpp.in b/platforms/linux/main.cpp.in index 12ab161..b9600b8 100755 --- a/platforms/linux/main.cpp.in +++ b/platforms/linux/main.cpp.in @@ -56,7 +56,7 @@ static inline xcb_intern_atom_reply_t* intern_atom_helper(xcb_connection_t *conn return xcb_intern_atom_reply(conn, cookie, NULL); } -int platform::open_window(const std::string_view title, const int x, const int y, const int width, const int height, const WindowFlags flags) { +int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) { auto& win = window_connections.emplace_back(); win.connection = connection; @@ -79,7 +79,7 @@ int platform::open_window(const std::string_view title, const int x, const int y win.window = xcb_generate_id(connection); cookie = xcb_create_window(win.connection, XCB_COPY_FROM_PARENT, win.window, screen->root, - x, y, width, height, + rect.offset.x, rect.offset.y, rect.extent.width, rect.extent.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, @@ -101,7 +101,7 @@ int platform::open_window(const std::string_view title, const int x, const int y xcb_map_window(connection, win.window); xcb_flush(connection); - engine->add_window((void*)&win, 0, width, height); + engine->add_window((void*)&win, 0, rect.extent); app->initialize_render(); return window_connections.size() - 1; @@ -121,30 +121,31 @@ float platform::get_monitor_dpi() { return 1.0; } -platform::Rect platform::get_monitor_resolution() { +prism::Rectangle platform::get_monitor_resolution() { } -platform::Rect platform::get_monitor_work_area() { +prism::Rectangle platform::get_monitor_work_area() { } -std::tuple platform::get_window_position(const int index) { +prism::Offset platform::get_window_position(const int index) { } -std::tuple platform::get_window_size(const int index) { +prism::Extent platform::get_window_size(const int index) { } -std::tuple platform::get_window_drawable_size(const int index) { +prism::Extent platform::get_window_drawable_size(const int index) { } + bool platform::is_window_focused(const int index) { } void platform::set_window_focused(const int index) { } -void platform::set_window_position(const int index, const int x, const int y) { +void platform::set_window_position(const int index, const prism::Offset offset) { } -void platform::set_window_size(const int index, const int w, const int h) { +void platform::set_window_size(const int index, const prism::Extent extent) { } void platform::set_window_title(const int index, const std::string_view title) { @@ -166,11 +167,11 @@ int platform::get_keycode(const InputButton key) { return inputToKeyCode[key]; } -std::tuple platform::get_cursor_position() { +prism::Offset platform::get_cursor_position() { return {mouse_x, mouse_y}; } -std::tuple platform::get_screen_cursor_position() { +prism::Offset platform::get_screen_cursor_position() { return {mouse_x, mouse_y}; } @@ -278,7 +279,7 @@ int main(int argc, char* argv[]) { { auto ev = (xcb_motion_notify_event_t *)event; - engine->process_mouse_move(ev->event_x, ev->event_y); + //engine->process_mouse_move(ev->event_x, ev->event_y); mouse_x = ev->event_x; mouse_y = ev->event_y; @@ -291,7 +292,7 @@ int main(int argc, char* argv[]) { if(press->detail == 3) index = 1; - engine->process_mouse(index, press->event_x, press->event_y); + //engine->process_mouse(index, press->event_x, press->event_y); mouse_down[index] = true; @@ -306,7 +307,7 @@ int main(int argc, char* argv[]) { if(press->detail == 3) index = 1; - engine->process_mouse_released(index); + //engine->process_mouse_released(index); mouse_down[index] = false; } @@ -315,21 +316,21 @@ int main(int argc, char* argv[]) { { const xcb_configure_notify_event_t *cfgEvent = (const xcb_configure_notify_event_t *)event; - engine->resize(0, cfgEvent->width, cfgEvent->height); + engine->resize(0, {cfgEvent->width, cfgEvent->height}); } break; case XCB_KEY_PRESS: { const xcb_key_release_event_t *keyEvent = (const xcb_key_release_event_t *)event; - engine->process_key(keyEvent->detail); + //engine->process_key(keyEvent->detail); } break; case XCB_KEY_RELEASE: { const xcb_key_release_event_t *keyEvent = (const xcb_key_release_event_t *)event; - engine->process_key_up(keyEvent->detail); + //engine->process_key_up(keyEvent->detail); } break; } @@ -341,9 +342,13 @@ int main(int argc, char* argv[]) { break; engine->update(1.0 / 60.0); - engine->begin_frame(); + engine->begin_frame(1.0 / 60.0); engine->render(0); } return 0; } + +PlatformTheme platform::get_theme() { + return PlatformTheme::Light; +}