Archived
1
Fork 0

Fix compilation issues on GCC/Linux

This commit is contained in:
redstrate 2021-02-15 15:06:13 -05:00
parent 946080808d
commit 3e4cf70c8e
9 changed files with 39 additions and 80 deletions

View file

@ -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;
}

View file

@ -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));
}

View file

@ -1,5 +1,7 @@
#include "materialcompiler.hpp"
#include <cstring>
#include "file.hpp"
#include "log.hpp"
#include "engine.hpp"

View file

@ -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<Transform>(camera_object).get_world_position();
sceneInfo.camPos.w = 2.0f * camera.near * std::tanf(camera.fov * 0.5f) * (static_cast<float>(extent.width) / static_cast<float>(extent.height));
sceneInfo.camPos.w = 2.0f * camera.near * std::tan(camera.fov * 0.5f) * (static_cast<float>(extent.width) / static_cast<float>(extent.height));
sceneInfo.vp = camera.perspective * camera.view;
for(const auto [obj, light] : scene.get_all<Light>()) {

View file

@ -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)

View file

@ -6,6 +6,7 @@
#include <vector>
#include <random>
#include <unordered_map>
#include <cmath>
#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;
}

View file

@ -1,5 +1,7 @@
#include "string_utils.hpp"
#include <algorithm>
std::string remove_substring(const std::string_view string, const std::string_view substring) {
std::string result(string);

View file

@ -1,63 +1,11 @@
#include "file.hpp"
#include <array>
#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> 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 "";
}

View file

@ -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<int, int> platform::get_window_position(const int index) {
prism::Offset platform::get_window_position(const int index) {
}
std::tuple<int, int> platform::get_window_size(const int index) {
prism::Extent platform::get_window_size(const int index) {
}
std::tuple<int, int> 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<int, int> platform::get_cursor_position() {
prism::Offset platform::get_cursor_position() {
return {mouse_x, mouse_y};
}
std::tuple<int, int> 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;
}