made std::shared_ptr and std::functional optional

This commit is contained in:
Noel Berry 2022-02-11 15:20:07 -08:00
parent 0c809f8085
commit cedc57e322
17 changed files with 212 additions and 162 deletions

View File

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

View File

@ -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"
#include "blah/streams/stream.h"

View File

@ -5,10 +5,10 @@
namespace Blah
{
// Application Event Functions
using AppEventFn = Func<void()>;
using AppEventFn = Func<void>;
// Application Logging Functions
using AppLogFn = Func<void(const char* message, Log::Category category)>;
using AppLogFn = Func<void, const char*, Log::Category>;
// Type of Renderer the Application is using
enum class RendererType

View File

@ -1,45 +1,37 @@
#pragma once
#include <cstdint> // for integer types
#include <cstddef> // for size_t type
#include <memory> // for std::shared_ptr
#include <functional> // for std::function
// In-Place constructor new, used by Vector/StackVector
#include <new>
// Asserts
#if defined(DEBUG) || defined(_DEBUG)
#include <cstdlib> // 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 <stdlib.h> // 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 <stdint.h> // for integer types
#include <stddef.h> // 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<typename T>
using Ref = std::shared_ptr<T>;
template<typename T>
using WeakRef = std::weak_ptr<T>;
template<typename T>
using Func = std::function<T>;
// 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, ...);
}
}
}
// Initializer list, required for Vector/StackVector
#include <initializer_list>
namespace Blah
{
template<typename T> using InitializerList = std::initializer_list<T>;
}
// Functional, for App Callbacks
#ifndef BLAH_NO_FUNCTIONAL
#include <functional>
namespace Blah
{
template<class Ret, class...Args> using Func = std::function<Ret(Args...)>;
}
#else
namespace Blah
{
template<class Ret, class...Args> using Func = Ret(*)(Args...);
}
#endif
// Ref Counter, for Graphics & Input Resources
#ifndef BLAH_NO_SHARED_PTR
#include <memory>
namespace Blah
{
template<typename T> using Ref = std::shared_ptr<T>;
}
#else
namespace Blah
{
template<typename T>
class Ref
{
template<class Y> 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<class Y>
Ref(Y* instance) : Ref(static_cast<T*>(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<class Y> bool operator==(const Ref<Y>& rhs) const { return m_counter == rhs.m_counter; }
template<class Y> bool operator!=(const Ref<Y>& rhs) const { return m_counter != rhs.m_counter; }
template<class Y> operator Ref<Y>() { if (m_counter) (*m_counter)++; return Ref<Y>(static_cast<Y*>(m_instance), m_counter); }
};
}
#endif

View File

@ -1,7 +1,5 @@
#pragma once
#include <blah/common.h>
#include <new>
#include <initializer_list>
namespace Blah
{
@ -19,7 +17,7 @@ namespace Blah
static constexpr size_t capacity = Capacity;
StackVector();
StackVector(const std::initializer_list<T>& init);
StackVector(const InitializerList<T>& list);
StackVector(const StackVector& src);
StackVector(StackVector&& src) noexcept;
~StackVector();
@ -62,7 +60,7 @@ namespace Blah
}
template<class T, size_t Capacity>
inline StackVector<T, Capacity>::StackVector(const std::initializer_list<T>& init)
inline StackVector<T, Capacity>::StackVector(const InitializerList<T>& init)
{
m_count = 0;
for (auto& it : init)

View File

@ -1,14 +1,12 @@
#pragma once
#include <blah/common.h>
#include <stdarg.h>
#include <cstdio>
#include <blah/containers/vector.h>
#include <functional>
#include <stdarg.h>
#include <stdio.h>
namespace Blah
{
template<int T>
class StrOf;
template<int T> class StrOf;
using String = StrOf<64>;
using FilePath = StrOf<260>;

View File

@ -1,8 +1,6 @@
#pragma once
#include <blah/common.h>
#include <initializer_list>
#include <new>
#include <cstring>
#include <string.h>
namespace Blah
{
@ -19,9 +17,9 @@ namespace Blah
Vector();
Vector(int capacity);
Vector(const InitializerList<T>& list);
Vector(const Vector& src);
Vector(Vector&& src) noexcept;
Vector(std::initializer_list<T> list);
~Vector();
Vector& operator=(const Vector& src);
@ -98,9 +96,8 @@ namespace Blah
src.m_count = 0;
}
template<class T>
inline Vector<T>::Vector(std::initializer_list<T> list)
inline Vector<T>::Vector(const InitializerList<T>& list)
{
m_buffer = nullptr;
m_count = m_capacity = 0;

View File

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

View File

@ -44,7 +44,7 @@ namespace Blah
int stride = 0;
VertexFormat() = default;
VertexFormat(std::initializer_list<VertexAttribute> attributes, int stride = 0);
VertexFormat(const StackVector<VertexAttribute, 16>& attributes, int stride = 0);
};
// Supported Vertex Index formats

View File

@ -1,5 +1,4 @@
#pragma once
#include <blah/common.h>
#include <blah/numerics/spatial.h>
#include <blah/containers/str.h>

View File

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

View File

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

View File

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

View File

@ -13,10 +13,9 @@ MeshRef Mesh::create()
return MeshRef();
}
VertexFormat::VertexFormat(std::initializer_list<VertexAttribute> attributes, int stride)
VertexFormat::VertexFormat(const StackVector<VertexAttribute, 16>& attr, int stride)
{
for (auto& it : attributes)
this->attributes.push_back(it);
attributes = attr;
if (stride <= 0)
{

View File

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

View File

@ -14,9 +14,9 @@ namespace
{
InputState g_empty_state;
ControllerState g_empty_controller;
Vector<WeakRef<ButtonBinding>> g_buttons;
Vector<WeakRef<AxisBinding>> g_axes;
Vector<WeakRef<StickBinding>> g_sticks;
Vector<Ref<ButtonBinding>> g_buttons;
Vector<Ref<AxisBinding>> g_axes;
Vector<Ref<StickBinding>> 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<ButtonBinding>(binding);
g_buttons.push_back(WeakRef<ButtonBinding>(result));
auto result = Ref<ButtonBinding>(new ButtonBinding(binding));
g_buttons.push_back(result);
return result;
}
AxisBindingRef Input::register_binding(const AxisBinding& binding)
{
auto result = std::make_shared<AxisBinding>(binding);
g_axes.push_back(WeakRef<AxisBinding>(result));
auto result = Ref<AxisBinding>(new AxisBinding(binding));
g_axes.push_back(result);
return result;
}
StickBindingRef Input::register_binding(const StickBinding& binding)
{
auto result = std::make_shared<StickBinding>(binding);
g_sticks.push_back(WeakRef<StickBinding>(result));
auto result = Ref<StickBinding>(new StickBinding(binding));
g_sticks.push_back(result);
return result;
}

View File

@ -11,16 +11,16 @@
#include <SDL.h>
// for File Reading/Writing
// for File Reading / Writing
#include <filesystem>
namespace fs = std::filesystem;
// Windows requires a few extra includes
#if _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windows.h> // for the following includes
#include <winuser.h> // for SetProcessDPIAware
#include <shellapi.h> // for file explore
#include <SDL_syswm.h>
#include <shellapi.h> // for ShellExecute for dir_explore
#include <SDL_syswm.h> // 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<FilePath>& 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());
}
}