From cedc57e32255928dc9afce962b5aebf49d6f0a21 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Fri, 11 Feb 2022 15:20:07 -0800 Subject: [PATCH] made std::shared_ptr and std::functional optional --- CMakeLists.txt | 12 +-- include/blah.h | 3 +- include/blah/app.h | 4 +- include/blah/common.h | 138 +++++++++++++++++++++----- include/blah/containers/stackvector.h | 6 +- include/blah/containers/str.h | 8 +- include/blah/containers/vector.h | 9 +- include/blah/graphics/batch.h | 2 +- include/blah/graphics/mesh.h | 2 +- include/blah/input.h | 1 - include/blah/time.h | 6 +- src/app.cpp | 23 +++-- src/common.cpp | 12 +-- src/graphics/mesh.cpp | 5 +- src/images/packer.cpp | 6 +- src/input.cpp | 38 +++---- src/internal/platform_sdl2.cpp | 99 +++++++----------- 17 files changed, 212 insertions(+), 162 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27942e0..487e199 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,14 +52,14 @@ target_include_directories(blah ) # Platform Variables -set(BLAH_PLATFORM_SDL2 true CACHE BOOL "Use SDL2 Platform Backend") -set(BLAH_PLATFORM_WIN32 false CACHE BOOL "Use Win32 Platform Backend") -set(BLAH_RENDERER_OPENGL true CACHE BOOL "Make OpenGL Renderer available") +option(BLAH_PLATFORM_SDL2 "Use SDL2 Platform Backend" ON) +option(BLAH_PLATFORM_WIN32 "Use Win32 Platform Backend" OFF) +option(BLAH_RENDERER_OPENGL "Make OpenGL Renderer available" ON) if (WIN32) - set(BLAH_RENDERER_D3D11 true CACHE BOOL "Make D3D11 Renderer available") -else() - set(BLAH_RENDERER_D3D11 false CACHE BOOL "Make D3D11 Renderer available") + option(BLAH_RENDERER_D3D11 "Make D3D11 Renderer available" ON) endif() +option(BLAH_NO_FUNCTIONAL "Don't use std::function" OFF) +option(BLAH_NO_SHARED_PTR "Don't use std::shared_ptr for Resources" OFF) set(LIBS "") diff --git a/include/blah.h b/include/blah.h index fb7aa71..99e474d 100644 --- a/include/blah.h +++ b/include/blah.h @@ -36,5 +36,4 @@ #include "blah/streams/bufferstream.h" #include "blah/streams/filestream.h" #include "blah/streams/memorystream.h" -#include "blah/streams/stream.h" -#include "blah/streams/endian.h" \ No newline at end of file +#include "blah/streams/stream.h" \ No newline at end of file diff --git a/include/blah/app.h b/include/blah/app.h index f0c6bdc..0d9d2fc 100644 --- a/include/blah/app.h +++ b/include/blah/app.h @@ -5,10 +5,10 @@ namespace Blah { // Application Event Functions - using AppEventFn = Func; + using AppEventFn = Func; // Application Logging Functions - using AppLogFn = Func; + using AppLogFn = Func; // Type of Renderer the Application is using enum class RendererType diff --git a/include/blah/common.h b/include/blah/common.h index f6708bc..5d3d590 100644 --- a/include/blah/common.h +++ b/include/blah/common.h @@ -1,45 +1,37 @@ #pragma once -#include // for integer types -#include // for size_t type -#include // for std::shared_ptr -#include // for std::function + +// In-Place constructor new, used by Vector/StackVector +#include // Asserts #if defined(DEBUG) || defined(_DEBUG) -#include // for abort -#define BLAH_ASSERT(condition, msg) \ - do { if (!(condition)) { Blah::Log::error("%s\n\tin %s:%d", (msg), __FILE__, __LINE__); abort(); } } while(0) +# include // for abort +# define BLAH_ASSERT(condition, msg) do { if (!(condition)) { Blah::Log::error("%s\n\tin %s:%d", (msg), __FILE__, __LINE__); abort(); } } while(0) #else -#define BLAH_ASSERT(condition, msg) \ - do { if (!(condition)) { Blah::Log::error("%s\n\tin %s:%d", (msg), __FILE__, __LINE__); } } while(0) -#endif - -// maximum length of a print/warn/error message -#ifndef BLAH_MESSAGE -#define BLAH_MESSAGE 1024 +# define BLAH_ASSERT(condition, msg) do { if (!(condition)) { Blah::Log::error("%s\n\tin %s:%d", (msg), __FILE__, __LINE__); } } while(0) #endif +// Numeric Types +#include // for integer types +#include // for size_t type namespace Blah { - using i8 = int8_t; + // Numeric Types + using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; - - using u8 = uint8_t; + using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; + using f32 = float; + using f64 = double; +} - template - using Ref = std::shared_ptr; - - template - using WeakRef = std::weak_ptr; - - template - using Func = std::function; - +// Logging +namespace Blah +{ namespace Log { enum class Category @@ -49,8 +41,100 @@ namespace Blah Error }; + constexpr int max_length = 1024; + void info(const char* message, ...); void warn(const char* message, ...); void error(const char* message, ...); } -} \ No newline at end of file +} + +// Initializer list, required for Vector/StackVector +#include +namespace Blah +{ + template using InitializerList = std::initializer_list; +} + +// Functional, for App Callbacks +#ifndef BLAH_NO_FUNCTIONAL +#include +namespace Blah +{ + template using Func = std::function; +} +#else +namespace Blah +{ + template using Func = Ret(*)(Args...); +} +#endif + +// Ref Counter, for Graphics & Input Resources +#ifndef BLAH_NO_SHARED_PTR +#include +namespace Blah +{ + template using Ref = std::shared_ptr; +} +#else +namespace Blah +{ + template + class Ref + { + template friend class Ref; + private: + T* m_instance; + i32* m_counter; + Ref(T* instance, i32* counter) : m_instance(instance), m_counter(counter) {} + + public: + Ref() : m_instance(nullptr), m_counter(nullptr) {} + + template + Ref(Y* instance) : Ref(static_cast(instance), new i32(1)) {} + Ref(const Ref& rhs) : Ref(rhs.m_instance, rhs.m_counter) { if (m_counter) (*m_counter)++; } + Ref(Ref&& rhs) : Ref(rhs.m_instance, rhs.m_counter) { rhs.m_instance = nullptr; rhs.m_counter = nullptr; } + + Ref& operator=(const Ref& rhs) + { + if (this != &rhs) + { + reset(); + m_instance = rhs.m_instance; m_counter = rhs.m_counter; + if (m_counter) (*m_counter)++; + } + return *this; + } + + Ref& operator=(Ref&& rhs) + { + if (this != &rhs) + { + reset(); + m_instance = rhs.m_instance; m_counter = rhs.m_counter; + rhs.m_instance = nullptr; rhs.m_counter = nullptr; + } + return *this; + } + + ~Ref() { reset(); } + + void reset() + { + if (m_counter) (*m_counter)--; + if (m_counter && (*m_counter) <= 0) { delete m_instance; delete m_counter; } + m_instance = nullptr; m_counter = nullptr; + } + + int use_count() const { return (m_counter ? (*m_counter) : 0); } + T* get() const { return m_instance; } + T* operator->() const { return m_instance; } + operator bool() const { return m_counter && (*m_counter) > 0; } + template bool operator==(const Ref& rhs) const { return m_counter == rhs.m_counter; } + template bool operator!=(const Ref& rhs) const { return m_counter != rhs.m_counter; } + template operator Ref() { if (m_counter) (*m_counter)++; return Ref(static_cast(m_instance), m_counter); } + }; +} +#endif \ No newline at end of file diff --git a/include/blah/containers/stackvector.h b/include/blah/containers/stackvector.h index e29892a..594d3d6 100644 --- a/include/blah/containers/stackvector.h +++ b/include/blah/containers/stackvector.h @@ -1,7 +1,5 @@ #pragma once #include -#include -#include namespace Blah { @@ -19,7 +17,7 @@ namespace Blah static constexpr size_t capacity = Capacity; StackVector(); - StackVector(const std::initializer_list& init); + StackVector(const InitializerList& list); StackVector(const StackVector& src); StackVector(StackVector&& src) noexcept; ~StackVector(); @@ -62,7 +60,7 @@ namespace Blah } template - inline StackVector::StackVector(const std::initializer_list& init) + inline StackVector::StackVector(const InitializerList& init) { m_count = 0; for (auto& it : init) diff --git a/include/blah/containers/str.h b/include/blah/containers/str.h index dd3d66d..873deda 100644 --- a/include/blah/containers/str.h +++ b/include/blah/containers/str.h @@ -1,14 +1,12 @@ #pragma once #include -#include -#include #include -#include +#include +#include namespace Blah { - template - class StrOf; + template class StrOf; using String = StrOf<64>; using FilePath = StrOf<260>; diff --git a/include/blah/containers/vector.h b/include/blah/containers/vector.h index 8061dd7..0004058 100644 --- a/include/blah/containers/vector.h +++ b/include/blah/containers/vector.h @@ -1,8 +1,6 @@ #pragma once #include -#include -#include -#include +#include namespace Blah { @@ -19,9 +17,9 @@ namespace Blah Vector(); Vector(int capacity); + Vector(const InitializerList& list); Vector(const Vector& src); Vector(Vector&& src) noexcept; - Vector(std::initializer_list list); ~Vector(); Vector& operator=(const Vector& src); @@ -98,9 +96,8 @@ namespace Blah src.m_count = 0; } - template - inline Vector::Vector(std::initializer_list list) + inline Vector::Vector(const InitializerList& list) { m_buffer = nullptr; m_count = m_capacity = 0; diff --git a/include/blah/graphics/batch.h b/include/blah/graphics/batch.h index b258352..b2f9731 100644 --- a/include/blah/graphics/batch.h +++ b/include/blah/graphics/batch.h @@ -123,7 +123,7 @@ namespace Blah void set_sampler(const TextureSampler& sampler); // Draws the batch to the given target - void render(const TargetRef& target = nullptr); + void render(const TargetRef& target = TargetRef()); // Draws the batch to the given target, with the provided matrix void render(const TargetRef& target, const Mat4x4f& matrix); diff --git a/include/blah/graphics/mesh.h b/include/blah/graphics/mesh.h index 1159424..6948f03 100644 --- a/include/blah/graphics/mesh.h +++ b/include/blah/graphics/mesh.h @@ -44,7 +44,7 @@ namespace Blah int stride = 0; VertexFormat() = default; - VertexFormat(std::initializer_list attributes, int stride = 0); + VertexFormat(const StackVector& attributes, int stride = 0); }; // Supported Vertex Index formats diff --git a/include/blah/input.h b/include/blah/input.h index 3e20b3f..8e61e09 100644 --- a/include/blah/input.h +++ b/include/blah/input.h @@ -1,5 +1,4 @@ #pragma once - #include #include #include diff --git a/include/blah/time.h b/include/blah/time.h index 1ac8d76..e870495 100644 --- a/include/blah/time.h +++ b/include/blah/time.h @@ -14,15 +14,15 @@ namespace Blah // uptime, in seconds extern double seconds; + // delta time from last frame + extern float delta; + // previous frame uptime, in ticks extern u64 previous_ticks; // previous frame uptime, in seconds extern double previous_seconds; - // delta time from last frame - extern float delta; - // time the application should pause for extern float pause_timer; diff --git a/src/app.cpp b/src/app.cpp index 0de1128..9ad5694 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -112,18 +112,12 @@ namespace } }; - BackBuffer app_backbuffer; - TargetRef app_backbuffer_ref = TargetRef(&app_backbuffer, [](BackBuffer*) {}); + TargetRef app_backbuffer; } bool App::run(const Config* c) { BLAH_ASSERT(!app_is_running, "The Application is already running"); - BLAH_ASSERT(c != nullptr, "The Application requires a valid Config"); - BLAH_ASSERT(c->name != nullptr, "The Application Name cannot be null"); - BLAH_ASSERT(c->width > 0 && c->height > 0, "The Width and Height must be larget than 0"); - BLAH_ASSERT(c->max_updates > 0, "Max Updates must be >= 1"); - BLAH_ASSERT(c->target_framerate > 0, "Target Framerate must be >= 1"); // copy config over app_config = *c; @@ -136,9 +130,19 @@ bool App::run(const Config* c) if (app_config.renderer_type == RendererType::None) app_config.renderer_type = Renderer::default_type(); + // exit out if setup is wrong + BLAH_ASSERT(c != nullptr, "The Application requires a valid Config"); + BLAH_ASSERT(c->name != nullptr, "The Application Name cannot be null"); + BLAH_ASSERT(c->width > 0 && c->height > 0, "The Width and Height must be larget than 0"); + BLAH_ASSERT(c->max_updates > 0, "Max Updates must be >= 1"); + BLAH_ASSERT(c->target_framerate > 0, "Target Framerate must be >= 1"); + if (app_is_running || c == nullptr || c->width <= 0 || c->height <= 0 || c->max_updates <= 0 || c->target_framerate <= 0) + return false; + // default values app_is_running = true; app_is_exiting = false; + app_backbuffer = TargetRef(new BackBuffer()); // initialize the system if (!Platform::init(app_config)) @@ -207,6 +211,7 @@ bool App::run(const Config* c) // clear static state app_is_running = false; app_is_exiting = false; + app_backbuffer = TargetRef(); Time::ticks = 0; Time::seconds = 0; @@ -286,7 +291,7 @@ Point App::get_backbuffer_size() { BLAH_ASSERT_RUNNING(); if (Renderer::instance) - return Point(app_backbuffer.width(), app_backbuffer.height()); + return Point(app_backbuffer->width(), app_backbuffer->height()); return Point(0, 0); } @@ -318,7 +323,7 @@ const RendererFeatures& App::renderer() const TargetRef& App::backbuffer() { BLAH_ASSERT_RUNNING(); - return app_backbuffer_ref; + return app_backbuffer; } void System::open_url(const char* url) diff --git a/src/common.cpp b/src/common.cpp index 7d95899..05b1769 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -7,10 +7,10 @@ using namespace Blah; void Log::info(const char* format, ...) { - char msg[BLAH_MESSAGE]; + char msg[max_length]; va_list ap; va_start(ap, format); - vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); + vsnprintf(msg, sizeof(char) * max_length, format, ap); va_end(ap); if (App::config().on_log) @@ -25,10 +25,10 @@ void Log::info(const char* format, ...) void Log::warn(const char* format, ...) { - char msg[BLAH_MESSAGE]; + char msg[max_length]; va_list ap; va_start(ap, format); - vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); + vsnprintf(msg, sizeof(char) * max_length, format, ap); va_end(ap); if (App::config().on_log) @@ -43,10 +43,10 @@ void Log::warn(const char* format, ...) void Log::error(const char* format, ...) { - char msg[BLAH_MESSAGE]; + char msg[max_length]; va_list ap; va_start(ap, format); - vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); + vsnprintf(msg, sizeof(char) * max_length, format, ap); va_end(ap); if (App::config().on_log) diff --git a/src/graphics/mesh.cpp b/src/graphics/mesh.cpp index bec8450..3b5864f 100644 --- a/src/graphics/mesh.cpp +++ b/src/graphics/mesh.cpp @@ -13,10 +13,9 @@ MeshRef Mesh::create() return MeshRef(); } -VertexFormat::VertexFormat(std::initializer_list attributes, int stride) +VertexFormat::VertexFormat(const StackVector& attr, int stride) { - for (auto& it : attributes) - this->attributes.push_back(it); + attributes = attr; if (stride <= 0) { diff --git a/src/images/packer.cpp b/src/images/packer.cpp index 7e8fa1d..ec9d7d8 100644 --- a/src/images/packer.cpp +++ b/src/images/packer.cpp @@ -160,9 +160,9 @@ void Packer::pack() sources[index++] = &m_entries[i]; std::sort(sources.begin(), sources.end(), [](Packer::Entry* a, Packer::Entry* b) - { - return a->packed.w * a->packed.h > b->packed.w * b->packed.h; - }); + { + return a->packed.w * a->packed.h > b->packed.w * b->packed.h; + }); } // make sure the largest isn't too large diff --git a/src/input.cpp b/src/input.cpp index 00610d2..bc22770 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -14,9 +14,9 @@ namespace { InputState g_empty_state; ControllerState g_empty_controller; - Vector> g_buttons; - Vector> g_axes; - Vector> g_sticks; + Vector> g_buttons; + Vector> g_axes; + Vector> g_sticks; String g_clipboard; } @@ -82,40 +82,42 @@ void Input::update_bindings() { for (int i = 0; i < g_buttons.size(); i++) { - if (g_buttons[i].use_count() <= 0) + // we're the only user, so remove it + if (g_buttons[i].use_count() <= 1) { g_buttons.erase(i); i--; } - else if (auto binding = g_buttons[i].lock()) + // keep updating + else { - binding->update(); + g_buttons[i]->update(); } } for (int i = 0; i < g_axes.size(); i++) { - if (g_axes[i].use_count() <= 0) + if (g_axes[i].use_count() <= 1) { g_axes.erase(i); i--; } - else if (auto binding = g_axes[i].lock()) + else { - binding->update(); + g_axes[i]->update(); } } for (int i = 0; i < g_sticks.size(); i++) { - if (g_sticks[i].use_count() <= 0) + if (g_sticks[i].use_count() <= 1) { g_sticks.erase(i); i--; } - else if (auto binding = g_sticks[i].lock()) + else { - binding->update(); + g_sticks[i]->update(); } } } @@ -397,22 +399,22 @@ void Input::set_clipboard(const String& text) ButtonBindingRef Input::register_binding(const ButtonBinding& binding) { - auto result = std::make_shared(binding); - g_buttons.push_back(WeakRef(result)); + auto result = Ref(new ButtonBinding(binding)); + g_buttons.push_back(result); return result; } AxisBindingRef Input::register_binding(const AxisBinding& binding) { - auto result = std::make_shared(binding); - g_axes.push_back(WeakRef(result)); + auto result = Ref(new AxisBinding(binding)); + g_axes.push_back(result); return result; } StickBindingRef Input::register_binding(const StickBinding& binding) { - auto result = std::make_shared(binding); - g_sticks.push_back(WeakRef(result)); + auto result = Ref(new StickBinding(binding)); + g_sticks.push_back(result); return result; } diff --git a/src/internal/platform_sdl2.cpp b/src/internal/platform_sdl2.cpp index b01dfa6..a2f7316 100644 --- a/src/internal/platform_sdl2.cpp +++ b/src/internal/platform_sdl2.cpp @@ -11,16 +11,16 @@ #include -// for File Reading/Writing +// for File Reading / Writing #include -namespace fs = std::filesystem; +// Windows requires a few extra includes #if _WIN32 #define WIN32_LEAN_AND_MEAN -#include +#include // for the following includes #include // for SetProcessDPIAware -#include // for file explore -#include +#include // for ShellExecute for dir_explore +#include // for SDL_SysWMinfo for D3D11 #endif // Macro defined by X11 conflicts with MouseButton enum @@ -40,50 +40,19 @@ namespace Blah } g_platform; // Blah SDL2 File - class SDL2File : public File + struct SDL2File : public File { - private: - SDL_RWops* m_handle; - - public: - SDL2File(SDL_RWops* handle) - { - m_handle = handle; - } - - ~SDL2File() - { - if (m_handle) - SDL_RWclose(m_handle); - } - - size_t length() override - { - return SDL_RWsize(m_handle); - } - - size_t position() override - { - return SDL_RWtell(m_handle); - } - - size_t seek(size_t position) override - { - return SDL_RWseek(m_handle, position, RW_SEEK_SET); - } - - size_t read(unsigned char* buffer, size_t length) override - { - return SDL_RWread(m_handle, buffer, sizeof(char), length); - } - - size_t write(const unsigned char* buffer, size_t length) override - { - return SDL_RWwrite(m_handle, buffer, sizeof(char), length); - } + SDL_RWops* handle; + SDL2File(SDL_RWops* handle) : handle(handle) { } + ~SDL2File() { if (handle) SDL_RWclose(handle); } + size_t length() override { return SDL_RWsize(handle); } + size_t position() override { return SDL_RWtell(handle); } + size_t seek(size_t position) override { return SDL_RWseek(handle, position, RW_SEEK_SET); } + size_t read(unsigned char* buffer, size_t length) override { return SDL_RWread(handle, buffer, sizeof(char), length); } + size_t write(const unsigned char* buffer, size_t length) override { return SDL_RWwrite(handle, buffer, sizeof(char), length); } }; - void sdl_log(void* userdata, int category, SDL_LogPriority priority, const char* message) + void blah_sdl_log(void* userdata, int category, SDL_LogPriority priority, const char* message) { if (priority <= SDL_LOG_PRIORITY_INFO) Log::info(message); @@ -93,7 +62,7 @@ namespace Blah Log::error(message); } - int sdl_find_joystick_index(SDL_Joystick** joysticks, SDL_JoystickID instance_id) + int blah_sdl_find_joystick_index(SDL_Joystick** joysticks, SDL_JoystickID instance_id) { for (int i = 0; i < Input::max_controllers; i++) if (joysticks[i] != nullptr && SDL_JoystickInstanceID(joysticks[i]) == instance_id) @@ -101,7 +70,7 @@ namespace Blah return -1; } - int sdl_find_gamepad_index(SDL_GameController** gamepads, SDL_JoystickID instance_id) + int blah_sdl_find_gamepad_index(SDL_GameController** gamepads, SDL_JoystickID instance_id) { for (int i = 0; i < Input::max_controllers; i++) { @@ -131,7 +100,7 @@ bool Platform::init(const Config& config) // TODO: // control this via some kind of config flag SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); - SDL_LogSetOutputFunction(sdl_log, nullptr); + SDL_LogSetOutputFunction(blah_sdl_log, nullptr); // Get SDL version SDL_version version; @@ -331,7 +300,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_JOYDEVICEREMOVED) { - auto index = sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); + auto index = blah_sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); if (index >= 0) { if (SDL_IsGameController(index) == SDL_FALSE) @@ -343,7 +312,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_JOYBUTTONDOWN) { - auto index = sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); + auto index = blah_sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); if (index >= 0) { if (SDL_IsGameController(index) == SDL_FALSE) @@ -352,7 +321,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_JOYBUTTONUP) { - auto index = sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); + auto index = blah_sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); if (index >= 0) { if (SDL_IsGameController(index) == SDL_FALSE) @@ -361,7 +330,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_JOYAXISMOTION) { - auto index = sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); + auto index = blah_sdl_find_joystick_index(g_platform.joysticks, event.jdevice.which); if (index >= 0) { if (SDL_IsGameController(index) == SDL_FALSE) @@ -392,7 +361,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { - auto index = sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); + auto index = blah_sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); if (index >= 0) { state.controllers[index].on_disconnect(); @@ -401,7 +370,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_CONTROLLERBUTTONDOWN) { - auto index = sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); + auto index = blah_sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); if (index >= 0) { Button button = Button::None; @@ -413,7 +382,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_CONTROLLERBUTTONUP) { - auto index = sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); + auto index = blah_sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); if (index >= 0) { Button button = Button::None; @@ -425,7 +394,7 @@ void Platform::update(InputState& state) } else if (event.type == SDL_CONTROLLERAXISMOTION) { - auto index = sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); + auto index = blah_sdl_find_gamepad_index(g_platform.gamepads, event.cdevice.which); if (index >= 0) { Axis axis = Axis::None; @@ -597,41 +566,41 @@ FileRef Platform::file_open(const char* path, FileMode mode) bool Platform::file_exists(const char* path) { - return fs::is_regular_file(path); + return std::filesystem::is_regular_file(path); } bool Platform::file_delete(const char* path) { - return fs::remove(path); + return std::filesystem::remove(path); } bool Platform::dir_create(const char* path) { - return fs::create_directories(path); + return std::filesystem::create_directories(path); } bool Platform::dir_exists(const char* path) { - return fs::is_directory(path); + return std::filesystem::is_directory(path); } bool Platform::dir_delete(const char* path) { - return fs::remove_all(path) > 0; + return std::filesystem::remove_all(path) > 0; } void Platform::dir_enumerate(Vector& list, const char* path, bool recursive) { - if (fs::is_directory(path)) + if (std::filesystem::is_directory(path)) { if (recursive) { - for (auto& p : fs::recursive_directory_iterator(path)) + for (auto& p : std::filesystem::recursive_directory_iterator(path)) list.emplace_back(p.path().string().c_str()); } else { - for (auto& p : fs::directory_iterator(path)) + for (auto& p : std::filesystem::directory_iterator(path)) list.emplace_back(p.path().string().c_str()); } }