diff --git a/Makefile b/Makefile index 07c12804..5ddacebc 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,7 @@ ifneq (,$(findstring bullet,$(REQ_DEPS))) endif endif ifneq (,$(findstring simd,$(REQ_DEPS))) - FLAGS += -DUF_USE_SIMD #-march=native + FLAGS += -DUF_USE_SIMD -DUF_MATRIX_ALIGNED #-DUF_VECTOR_ALIGNED #-march=native endif ifneq (,$(findstring meshoptimizer,$(REQ_DEPS))) diff --git a/bin/data/config.json b/bin/data/config.json index 0c0c238c..021801c2 100644 --- a/bin/data/config.json +++ b/bin/data/config.json @@ -175,14 +175,16 @@ "streams by default": true }, "memory pool": { - "globalOverride": false, "subPools": true, + "alignment": 64, "size": "1024 MiB", + "STL allocator": true, "pools": { "entity": "256 MiB", "userdata": "256 MiB", "component": "256 MiB" - } + }, + "globalOverride": false }, "hook" : { "mode" : "Readable" diff --git a/bin/data/entities/player.json b/bin/data/entities/player.json index a1a24bc4..b561b602 100644 --- a/bin/data/entities/player.json +++ b/bin/data/entities/player.json @@ -45,11 +45,11 @@ }, "metadata": { "overlay": { - // "position": [ 0, 0, -3 ], - // "scale": [ -1.77778, -1, 1 ], - "position": [ 0, 0, -3 ], - "scale": [ 1.77778, -1, 1 ], - "orientation": [ 0, 0, 0, 1 ], + "transform": { + "position": [ 0, 0, -3 ], + "scale": [ 1.77778, -1, 1 ], + "orientation": [ 0, 0, 0, 1 ] + }, "floating": false, "enabled": true, "alpha": 1.0, diff --git a/client/client/ext.cpp b/client/client/ext.cpp index cd2d2298..43eedc1a 100644 --- a/client/client/ext.cpp +++ b/client/client/ext.cpp @@ -146,10 +146,14 @@ void client::tick() { } #endif uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{ - "window:Mouse.Moved", - "client", { - pod::Vector2ui{ size.x, size.y }, + { + "window:Mouse.Moved", + "client", + }, + { + pod::Vector2ui{ size.x, size.y }, + }, }, { current, diff --git a/client/main.cpp b/client/main.cpp index cca1ccf0..918cd257 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #if UF_NO_EXCEPTIONS #define HANDLE_EXCEPTIONS 0 diff --git a/engine/inc/uf/config.h b/engine/inc/uf/config.h index 8b9d867f..50aeae04 100644 --- a/engine/inc/uf/config.h +++ b/engine/inc/uf/config.h @@ -106,4 +106,5 @@ #endif #include "macros.h" -#include "simd.h" \ No newline at end of file +#include "simd.h" +#include "helpers.inl" \ No newline at end of file diff --git a/engine/inc/uf/engine/asset/asset.h b/engine/inc/uf/engine/asset/asset.h index 725d92e6..e2b3e292 100644 --- a/engine/inc/uf/engine/asset/asset.h +++ b/engine/inc/uf/engine/asset/asset.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include namespace uf { @@ -15,17 +15,17 @@ namespace uf { // URL or file path void processQueue(); - void cache( const std::string&, const std::string&, const std::string&, const std::string& ); - void load( const std::string&, const std::string&, const std::string&, const std::string& ); + void cache( const uf::stl::string&, const uf::stl::string&, const uf::stl::string&, const uf::stl::string& ); + void load( const uf::stl::string&, const uf::stl::string&, const uf::stl::string&, const uf::stl::string& ); - std::string cache( const std::string&, const std::string& = "", const std::string& = "" ); - std::string load( const std::string&, const std::string& = "", const std::string& = "" ); + uf::stl::string cache( const uf::stl::string&, const uf::stl::string& = "", const uf::stl::string& = "" ); + uf::stl::string load( const uf::stl::string&, const uf::stl::string& = "", const uf::stl::string& = "" ); - std::string getOriginal( const std::string& ); + uf::stl::string getOriginal( const uf::stl::string& ); template - std::vector& getContainer() { - return this->getComponent>(); + uf::stl::vector& getContainer() { + return this->getComponent>(); } template @@ -34,10 +34,10 @@ namespace uf { return container.size() > i; } template - bool has( const std::string& url ) { + bool has( const uf::stl::string& url ) { auto& container = this->getContainer(); if ( container.empty() ) return false; - std::string extension = uf::io::extension( url ); + uf::stl::string extension = uf::io::extension( url ); uf::Serializer& map = this->getComponent(); if ( ext::json::isNull( map[extension] ) ) return false; if ( ext::json::isNull( map[extension][url] ) ) return false; @@ -50,16 +50,16 @@ namespace uf { return container.at(i); } template - T& get( const std::string& url ) { - std::string extension = uf::io::extension( url ); + T& get( const uf::stl::string& url ) { + uf::stl::string extension = uf::io::extension( url ); uf::Serializer& map = this->getComponent(); size_t index = map[extension][url]["index"].as(0); return this->get(index); } template - T& add( const std::string& url, const T& copy ) { - std::string extension = uf::io::extension( url ); + T& add( const uf::stl::string& url, const T& copy ) { + uf::stl::string extension = uf::io::extension( url ); uf::Serializer& map = this->getComponent(); auto& container = this->getContainer(); if ( !ext::json::isNull( map[extension][url]["index"] ) ) return this->get(url); @@ -68,8 +68,8 @@ namespace uf { return container.back(); } template - T& add( const std::string& url, T&& move ) { - std::string extension = uf::io::extension( url ); + T& add( const uf::stl::string& url, T&& move ) { + uf::stl::string extension = uf::io::extension( url ); uf::Serializer& map = this->getComponent(); auto& container = this->getContainer(); @@ -80,19 +80,19 @@ namespace uf { } template - void remove( const std::string& url ) { + void remove( const uf::stl::string& url ) { if ( !this->has( url ) ) return; auto& container = this->getContainer(); - std::string extension = uf::io::extension( url ); + uf::stl::string extension = uf::io::extension( url ); uf::Serializer& map = this->getComponent(); std::size_t index = map[extension][url]["index"].as(); // container.erase( container.begin() + index ); // map[extension][url] = ext::json::null(); // map[extension][url]["erased"] = true; - std::string key = ""; - ext::json::forEach( map[extension], [&]( const std::string& k, ext::json::Value& v ) { + uf::stl::string key = ""; + ext::json::forEach( map[extension], [&]( const uf::stl::string& k, ext::json::Value& v ) { std::size_t i = v["index"].as(); if ( index == i && key != url ) key = k; }); diff --git a/engine/inc/uf/engine/asset/masterdata.h b/engine/inc/uf/engine/asset/masterdata.h index b84ad354..cd063013 100644 --- a/engine/inc/uf/engine/asset/masterdata.h +++ b/engine/inc/uf/engine/asset/masterdata.h @@ -5,17 +5,17 @@ namespace uf { class UF_API MasterData { protected: - std::string m_table; - std::string m_key; + uf::stl::string m_table; + uf::stl::string m_key; uf::Serializer m_data; static uf::Asset assetLoader; - static std::string root; + static uf::stl::string root; public: - uf::Serializer load( const std::string&, size_t ); - uf::Serializer load( const std::string&, const std::string& = "" ); - uf::Serializer get( const std::string& k = "" ) const; - const std::string& tableName() const; - const std::string& keyName() const; + uf::Serializer load( const uf::stl::string&, size_t ); + uf::Serializer load( const uf::stl::string&, const uf::stl::string& = "" ); + uf::Serializer get( const uf::stl::string& k = "" ) const; + const uf::stl::string& tableName() const; + const uf::stl::string& keyName() const; }; } \ No newline at end of file diff --git a/engine/inc/uf/engine/behavior/behavior.h b/engine/inc/uf/engine/behavior/behavior.h index 442b244d..b116fec6 100644 --- a/engine/inc/uf/engine/behavior/behavior.h +++ b/engine/inc/uf/engine/behavior/behavior.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace uf { @@ -14,7 +14,7 @@ namespace uf { namespace pod { struct UF_API Behavior { // typedef std::type_index type_t; - typedef std::string type_t; + typedef uf::stl::string type_t; typedef std::function function_t; type_t type = ""; //std::type_index(typeid(pod::Behavior)); @@ -28,7 +28,7 @@ namespace pod { namespace uf { class UF_API Behaviors : public uf::Component { protected: - typedef std::vector container_t; + typedef uf::stl::vector container_t; container_t m_behaviors; public: void initialize(); diff --git a/engine/inc/uf/engine/entity/entity.h b/engine/inc/uf/engine/entity/entity.h index 161afb5f..39f0fc14 100644 --- a/engine/inc/uf/engine/entity/entity.h +++ b/engine/inc/uf/engine/entity/entity.h @@ -3,17 +3,17 @@ #include #include #include -#include +#include #include -#include +#include namespace uf { class UF_API Object; class UF_API Entity : public uf::Behaviors { //friend class EntityBehavior; public: - typedef std::vector container_t; + typedef uf::stl::vector container_t; static uf::Entity null; static bool deleteChildrenOnDestroy; static bool deleteComponentsOnDestroy; @@ -24,7 +24,7 @@ namespace uf { uf::Entity::container_t m_children; std::size_t m_uid = 0; - std::string m_name = "Entity"; + uf::stl::string m_name = "Entity"; public: static uf::MemoryPool memoryPool; @@ -32,9 +32,9 @@ namespace uf { ~Entity(); // identifiers bool isValid() const; - const std::string& getName() const; + const uf::stl::string& getName() const; std::size_t getUid() const; - void setName( const std::string& ); + void setName( const uf::stl::string& ); // cast to other Entity classes, avoid nasty shit like *((uf::Object*) &entity) template T& as(); template const T& as() const; @@ -58,19 +58,19 @@ namespace uf { uf::Entity::container_t& getChildren(); const uf::Entity::container_t& getChildren() const; // use instantiate to allocate - void* operator new(size_t, const std::string& = ""); + void* operator new(size_t, const uf::stl::string& = ""); void operator delete(void*); // search - uf::Entity* findByName( const std::string& name ); + uf::Entity* findByName( const uf::stl::string& name ); uf::Entity* findByUid( std::size_t id ); - const uf::Entity* findByName( const std::string& name ) const; + const uf::Entity* findByName( const uf::stl::string& name ) const; const uf::Entity* findByUid( std::size_t id ) const; // filters void process( std::function ); void process( std::function, int depth = 0 ); // globals static uf::Entity* globalFindByUid( size_t id ); - static uf::Entity* globalFindByName( const std::string& name ); + static uf::Entity* globalFindByName( const uf::stl::string& name ); }; } diff --git a/engine/inc/uf/engine/graph/graph.h b/engine/inc/uf/engine/graph/graph.h index e10d8b1b..a16d82dc 100644 --- a/engine/inc/uf/engine/graph/graph.h +++ b/engine/inc/uf/engine/graph/graph.h @@ -23,12 +23,12 @@ namespace pod { /*alignas(16)*/ pod::Vector4f lerp = {0, 0, 1, 1}; } storage; - std::string name = ""; + uf::stl::string name = ""; uf::renderer::Texture2D texture; bool bind = false; }; struct UF_API Node { - std::string name = ""; + uf::stl::string name = ""; int32_t index = -1; int32_t skin = -1; @@ -36,7 +36,7 @@ namespace pod { int32_t mesh = -1; pod::Transform<> transform; - std::vector children; + uf::stl::vector children; uf::Object* entity = NULL; struct { @@ -50,7 +50,7 @@ namespace pod { // Node* node = NULL; pod::Node root; - std::vector nodes; + uf::stl::vector nodes; uf::Object* entity = NULL; @@ -58,23 +58,23 @@ namespace pod { int32_t instance = -1; } buffers; - std::string name = ""; + uf::stl::string name = ""; uf::graph::load_mode_t mode; uf::Serializer metadata; uf::Atlas atlas; - std::vector images; - std::vector samplers; - std::vector textures; - std::vector materials; - std::vector lights; - std::vector drawCalls; + uf::stl::vector images; + uf::stl::vector samplers; + uf::stl::vector textures; + uf::stl::vector materials; + uf::stl::vector lights; + uf::stl::vector drawCalls; - std::vector skins; - std::vector meshes; - std::unordered_map animations; + uf::stl::vector skins; + uf::stl::vector meshes; + uf::stl::unordered_map animations; - std::queue sequence; + std::queue sequence; struct { struct { bool loop = true; @@ -82,7 +82,7 @@ namespace pod { struct { float a = -std::numeric_limits::max(); float speed = 1 / 0.125f; - std::unordered_map, pod::Transform<>>> map; + uf::stl::unordered_map, pod::Transform<>>> map; } override; } animations; } settings; @@ -93,17 +93,17 @@ namespace uf { namespace graph { /* namespace { - extern UF_API std::vector storage; - extern UF_API std::vector indices; + extern UF_API uf::stl::vector storage; + extern UF_API uf::stl::vector indices; } materials; namespace { - extern UF_API std::vector storage; - extern UF_API std::vector indices; + extern UF_API uf::stl::vector storage; + extern UF_API uf::stl::vector indices; } textures; */ pod::Node* UF_API find( pod::Graph& graph, int32_t index ); - pod::Node* UF_API find( pod::Graph& graph, const std::string& name ); + pod::Node* UF_API find( pod::Graph& graph, const uf::stl::string& name ); pod::Matrix4f UF_API local( pod::Graph&, int32_t ); pod::Matrix4f UF_API matrix( pod::Graph&, int32_t ); @@ -115,17 +115,17 @@ namespace uf { void UF_API initialize( pod::Graph& graph ); void UF_API override( pod::Graph& ); - void UF_API animate( pod::Graph&, const std::string&, float = 1, bool = true ); + void UF_API animate( pod::Graph&, const uf::stl::string&, float = 1, bool = true ); void UF_API update( pod::Graph& ); void UF_API update( pod::Graph&, float ); void UF_API update( pod::Graph&, pod::Node& ); void UF_API destroy( pod::Graph& ); - pod::Graph UF_API load( const std::string&, uf::graph::load_mode_t = 0, const uf::Serializer& = ext::json::null() ); - void UF_API save( const pod::Graph&, const std::string& ); + pod::Graph UF_API load( const uf::stl::string&, uf::graph::load_mode_t = 0, const uf::Serializer& = ext::json::null() ); + void UF_API save( const pod::Graph&, const uf::stl::string& ); - std::string UF_API print( const pod::Graph& graph ); + uf::stl::string UF_API print( const pod::Graph& graph ); uf::Serializer UF_API stats( const pod::Graph& graph ); } } \ No newline at end of file diff --git a/engine/inc/uf/engine/graph/mesh.h b/engine/inc/uf/engine/graph/mesh.h index 9dd7f768..fbf22f1b 100644 --- a/engine/inc/uf/engine/graph/mesh.h +++ b/engine/inc/uf/engine/graph/mesh.h @@ -20,7 +20,7 @@ namespace uf { /*alignas(16)*/ pod::Vector3f tangent; /*alignas(8)*/ pod::Vector2ui id; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct Skinned { /*alignas(16)*/ pod::Vector3f position; @@ -32,7 +32,7 @@ namespace uf { /*alignas(16)*/ pod::Vector4ui joints; /*alignas(16)*/ pod::Vector4f weights; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; } typedef uf::BaseMesh mesh_t; diff --git a/engine/inc/uf/engine/graph/pod.h b/engine/inc/uf/engine/graph/pod.h index ced7fd3e..96bd25a6 100644 --- a/engine/inc/uf/engine/graph/pod.h +++ b/engine/inc/uf/engine/graph/pod.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -10,11 +10,11 @@ namespace pod { uf::renderer::Texture3D noise; uf::renderer::TextureCube skybox; struct { - std::vector id; - std::vector uv; - std::vector normal; - std::vector radiance; - std::vector depth; + uf::stl::vector id; + uf::stl::vector uv; + uf::stl::vector normal; + uf::stl::vector radiance; + uf::stl::vector depth; } voxels; }; @@ -25,7 +25,7 @@ namespace pod { /*alignas(4)*/ uint32_t textureSlot = 0; /*alignas(4)*/ uint32_t padding = 0; } storage; - std::string name = ""; + uf::stl::string name = ""; size_t verticesIndex = 0; size_t vertices = 0; size_t indicesIndex = 0; @@ -44,7 +44,7 @@ namespace pod { /*alignas(16)*/ pod::Matrix4f view; /*alignas(16)*/ pod::Matrix4f projection; }; - std::string name = ""; + uf::stl::string name = ""; pod::Vector3f color = { 1, 1, 1 }; float intensity = 1.0f; float range = 0.0f; @@ -69,29 +69,29 @@ namespace pod { /*alignas(4)*/ int32_t indexLightmap = -1; /*alignas(4)*/ int32_t modeAlpha = -1; } storage; - std::string name = ""; - std::string alphaMode = ""; + uf::stl::string name = ""; + uf::stl::string alphaMode = ""; }; struct UF_API Skin { - std::string name = ""; - std::vector joints; - std::vector inverseBindMatrices; + uf::stl::string name = ""; + uf::stl::vector joints; + uf::stl::vector inverseBindMatrices; }; struct UF_API Animation { struct Sampler { - std::string interpolator; - std::vector inputs; - std::vector outputs; + uf::stl::string interpolator; + uf::stl::vector inputs; + uf::stl::vector outputs; }; struct Channel { - std::string path; + uf::stl::string path; int32_t node; uint32_t sampler; }; - std::string name = ""; - std::vector samplers; - std::vector channels; + uf::stl::string name = ""; + uf::stl::vector samplers; + uf::stl::vector channels; float start = std::numeric_limits::max(); float end = std::numeric_limits::min(); float cur = 0; diff --git a/engine/inc/uf/engine/instantiator/instantiator.h b/engine/inc/uf/engine/instantiator/instantiator.h index 88262cda..0cd9a7a2 100644 --- a/engine/inc/uf/engine/instantiator/instantiator.h +++ b/engine/inc/uf/engine/instantiator/instantiator.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -13,7 +13,7 @@ namespace pod { struct UF_API Instantiator { typedef std::function function_t; - typedef std::vector behaviors_t; + typedef uf::stl::vector behaviors_t; function_t function; behaviors_t behaviors; }; @@ -21,24 +21,24 @@ namespace pod { template struct UF_API NamedTypes { typedef std::type_index type_t; - typedef std::unordered_map container_t; - typedef std::unordered_map map_t; + typedef uf::stl::unordered_map container_t; + typedef uf::stl::unordered_map map_t; container_t names; map_t map; - type_t getType( const std::string& name ); + type_t getType( const uf::stl::string& name ); template type_t getType(); - template std::string getName(); + template uf::stl::string getName(); - bool has( const std::string& name, bool = true ); + bool has( const uf::stl::string& name, bool = true ); template bool has( bool = true ); - template void add( const std::string& name, const C& c ); + template void add( const uf::stl::string& name, const C& c ); - C& get( const std::string& name ); + C& get( const uf::stl::string& name ); template C& get(); - C& operator[]( const std::string& name ); + C& operator[]( const uf::stl::string& name ); }; } @@ -46,7 +46,7 @@ namespace uf { namespace instantiator { extern UF_API pod::NamedTypes* objects; // extern UF_API pod::NamedTypes* behaviors; - extern UF_API std::unordered_map* behaviors; + extern UF_API uf::stl::unordered_map* behaviors; uf::Entity* UF_API alloc( size_t ); template T* alloc(); @@ -56,20 +56,20 @@ namespace uf { uf::Entity* UF_API reuse( size_t ); size_t UF_API collect( uint8_t = 0 ); - template void registerObject( const std::string& name ); - // template void registerBehavior( const std::string& name ); - template void registerBinding( const std::string& name ); - void UF_API registerBehavior( const std::string& name, const pod::Behavior& ); - void UF_API registerBinding( const std::string& object, const std::string& behavior ); + template void registerObject( const uf::stl::string& name ); + // template void registerBehavior( const uf::stl::string& name ); + template void registerBinding( const uf::stl::string& name ); + void UF_API registerBehavior( const uf::stl::string& name, const pod::Behavior& ); + void UF_API registerBinding( const uf::stl::string& object, const uf::stl::string& behavior ); - uf::Entity& UF_API instantiate( const std::string& ); + uf::Entity& UF_API instantiate( const uf::stl::string& ); template T& instantiate(); template T* _instantiate(); - void UF_API bind( const std::string&, uf::Entity& ); + void UF_API bind( const uf::stl::string&, uf::Entity& ); template void bind( uf::Entity& ); - void UF_API unbind( const std::string&, uf::Entity& ); + void UF_API unbind( const uf::stl::string&, uf::Entity& ); template void unbind( uf::Entity& ); }; } diff --git a/engine/inc/uf/engine/instantiator/instantiator.inl b/engine/inc/uf/engine/instantiator/instantiator.inl index 1f98d9c4..551e4779 100644 --- a/engine/inc/uf/engine/instantiator/instantiator.inl +++ b/engine/inc/uf/engine/instantiator/instantiator.inl @@ -1,7 +1,7 @@ #include template -typename pod::NamedTypes::type_t pod::NamedTypes::getType( const std::string& name ) { +typename pod::NamedTypes::type_t pod::NamedTypes::getType( const uf::stl::string& name ) { for ( auto pair : names ) if ( pair.second == name ) return pair.first; return getType(); } @@ -10,23 +10,23 @@ template typename pod::NamedTypes::type_t pod::NamedTypes::get return std::type_index(typeid(T)); } template -template std::string pod::NamedTypes::getName() { +template uf::stl::string pod::NamedTypes::getName() { return names[getType()]; } template -bool pod::NamedTypes::has( const std::string& name, bool useNames ) { +bool pod::NamedTypes::has( const uf::stl::string& name, bool useNames ) { return useNames ? names.count(getType(name)) > 0 : map.count(name) > 0; }template template bool pod::NamedTypes::has( bool useNames ) { return useNames ? names.count(getType()) > 0 : map.count(getName()) > 0; } template -template void pod::NamedTypes::add( const std::string& name, const C& c ) { +template void pod::NamedTypes::add( const uf::stl::string& name, const C& c ) { names[getType()] = name; map[name] = c; } template -C& pod::NamedTypes::get( const std::string& name ) { +C& pod::NamedTypes::get( const uf::stl::string& name ) { return map[name]; } template @@ -35,7 +35,7 @@ C& pod::NamedTypes::get() { return map[getName()]; } template -C& pod::NamedTypes::operator[]( const std::string& name ) { +C& pod::NamedTypes::operator[]( const uf::stl::string& name ) { return get(name); } @@ -44,7 +44,7 @@ T* uf::instantiator::alloc() { return (T*) alloc( sizeof(T) ); } -template void uf::instantiator::registerObject( const std::string& name ) { +template void uf::instantiator::registerObject( const uf::stl::string& name ) { if ( !objects ) objects = new pod::NamedTypes; auto& container = *uf::instantiator::objects; container.add(name, { @@ -57,7 +57,7 @@ template void uf::instantiator::registerObject( const std::string& n #endif } #if 0 -template void uf::instantiator::registerBehavior( const std::string& name ) { +template void uf::instantiator::registerBehavior( const uf::stl::string& name ) { if ( !behaviors ) behaviors = new pod::NamedTypes; auto& container = *uf::instantiator::behaviors; container.add(name, pod::Behavior{ @@ -73,7 +73,7 @@ template void uf::instantiator::registerBehavior( const std::string& #endif } #endif -template void uf::instantiator::registerBinding( const std::string& name ) { +template void uf::instantiator::registerBinding( const uf::stl::string& name ) { if ( !objects ) objects = new pod::NamedTypes; auto& container = *uf::instantiator::objects; auto& instantiator = container.get(); diff --git a/engine/inc/uf/engine/instantiator/macros.inl b/engine/inc/uf/engine/instantiator/macros.inl index cfe38e57..f1548638 100644 --- a/engine/inc/uf/engine/instantiator/macros.inl +++ b/engine/inc/uf/engine/instantiator/macros.inl @@ -31,7 +31,7 @@ namespace {\ #define UF_OBJECT_REGISTER_BEGIN( OBJ )\ namespace {\ static uf::StaticInitialization TOKEN_PASTE(STATIC_INITIALIZATION_, __LINE__)( []{\ - std::string name = UF_NS_GET_LAST(OBJ);\ + uf::stl::string name = UF_NS_GET_LAST(OBJ);\ uf::instantiator::registerObject( name ); #define UF_OBJECT_BIND_BEHAVIOR( BEHAVIOR )\ @@ -39,7 +39,7 @@ namespace {\ // uf::instantiator::registerBehavior( UF_NS_GET_LAST(BEHAVIOR) ); #define UF_OBJECT_REGISTER_BEHAVIOR( BEHAVIOR )\ - if ( !uf::instantiator::behaviors ) uf::instantiator::behaviors = new std::unordered_map;\ + if ( !uf::instantiator::behaviors ) uf::instantiator::behaviors = new uf::stl::unordered_map;\ uf::instantiator::registerBehavior(UF_NS_GET_LAST(BEHAVIOR), pod::Behavior{\ .type = BEHAVIOR::type,\ .initialize = BEHAVIOR::initialize,\ @@ -88,7 +88,7 @@ namespace {\ #define UF_OBJECT_REGISTER_BEGIN( OBJ )\ namespace {\ static uf::StaticInitialization REGISTER_EXT_ ## OBJ( []{\ - std::string name = #OBJ;\ + uf::stl::string name = #OBJ;\ uf::instantiator::registerObject( name ); #define UF_OBJECT_BIND_BEHAVIOR( BEHAVIOR )\ @@ -105,7 +105,7 @@ namespace {\ #define EXT_OBJECT_REGISTER_BEGIN( OBJ )\ namespace {\ static uf::StaticInitialization REGISTER_EXT_ ## OBJ( []{\ - std::string name = #OBJ;\ + uf::stl::string name = #OBJ;\ uf::instantiator::registerObject( name ); #define EXT_OBJECT_BIND_BEHAVIOR( BEHAVIOR )\ diff --git a/engine/inc/uf/engine/object/behavior.h b/engine/inc/uf/engine/object/behavior.h index b62c223e..45932a8b 100644 --- a/engine/inc/uf/engine/object/behavior.h +++ b/engine/inc/uf/engine/object/behavior.h @@ -5,9 +5,9 @@ #include #include -#include -#include -#include +#include +#include +#include namespace uf { namespace ObjectBehavior { @@ -19,18 +19,18 @@ namespace uf { void UF_API destroy( uf::Object& ); struct Metadata { struct Queued { - std::string name; + uf::stl::string name; ext::json::Value payload; double timeout; }; struct { size_t mtime = 0; bool enabled = false; - std::string source = ""; + uf::stl::string source = ""; } hotReload; struct { - std::unordered_map> bound; - std::vector queue; + uf::stl::unordered_map> bound; + uf::stl::vector queue; } hooks; struct { bool ignoreGraph = false; diff --git a/engine/inc/uf/engine/object/object.h b/engine/inc/uf/engine/object/object.h index 9299ee6f..324dc74d 100644 --- a/engine/inc/uf/engine/object/object.h +++ b/engine/inc/uf/engine/object/object.h @@ -16,40 +16,40 @@ namespace uf { Object(); bool reload( bool = false ); - bool load( const std::string&, bool = false ); + bool load( const uf::stl::string&, bool = false ); bool load( const uf::Serializer& ); uf::Object& loadChild( const uf::Serializer&, bool = true ); uf::Object* loadChildPointer( const uf::Serializer&, bool = true ); std::size_t loadChildUid( const uf::Serializer&, bool = true ); - uf::Object& loadChild( const std::string&, bool = true ); - uf::Object* loadChildPointer( const std::string&, bool = true ); - std::size_t loadChildUid( const std::string&, bool = true ); + uf::Object& loadChild( const uf::stl::string&, bool = true ); + uf::Object* loadChildPointer( const uf::stl::string&, bool = true ); + std::size_t loadChildUid( const uf::stl::string&, bool = true ); template T loadChild( const uf::Serializer&, bool = true ); template - T loadChild( const std::string&, bool = true ); + T loadChild( const uf::stl::string&, bool = true ); - std::string formatHookName( const std::string& name ); - static std::string formatHookName( const std::string& name, size_t uid, bool fetch = true ); + uf::stl::string formatHookName( const uf::stl::string& name ); + static uf::stl::string formatHookName( const uf::stl::string& name, size_t uid, bool fetch = true ); - void queueHook( const std::string&, const ext::json::Value& = ext::json::null(), double = 0 ); - uf::Hooks::return_t callHook( const std::string& ); - uf::Hooks::return_t callHook( const std::string&, const ext::json::Value& ); - uf::Hooks::return_t callHook( const std::string&, const uf::Serializer& ); + void queueHook( const uf::stl::string&, const ext::json::Value& = ext::json::null(), double = 0 ); + uf::Hooks::return_t callHook( const uf::stl::string& ); + uf::Hooks::return_t callHook( const uf::stl::string&, const ext::json::Value& ); + uf::Hooks::return_t callHook( const uf::stl::string&, const uf::Serializer& ); - template size_t addHook( const std::string& name, T function ); - template uf::Hooks::return_t callHook( const std::string& name, const T& payload ); + template size_t addHook( const uf::stl::string& name, T function ); + template uf::Hooks::return_t callHook( const uf::stl::string& name, const T& payload ); - std::string grabURI( const std::string& filename, const std::string& root = "" ); + uf::stl::string grabURI( const uf::stl::string& filename, const uf::stl::string& root = "" ); }; } namespace uf { namespace string { - std::string UF_API toString( const uf::Object& object ); + uf::stl::string UF_API toString( const uf::Object& object ); } } diff --git a/engine/inc/uf/engine/object/object.inl b/engine/inc/uf/engine/object/object.inl index b82bc0e3..2309eeba 100644 --- a/engine/inc/uf/engine/object/object.inl +++ b/engine/inc/uf/engine/object/object.inl @@ -8,7 +8,7 @@ T uf::Object::loadChild( const uf::Serializer& json, bool initialize ) { return this->loadChild(json, initialize); } template -T uf::Object::loadChild( const std::string& filename, bool initialize ) { +T uf::Object::loadChild( const uf::stl::string& filename, bool initialize ) { // T is size_t if ( typeid(T) == typeid(std::size_t) ) return this->loadChildUid(filename, initialize); // T is pointer @@ -17,8 +17,8 @@ T uf::Object::loadChild( const std::string& filename, bool initialize ) { return this->loadChild(filename, initialize); } template -size_t uf::Object::addHook( const std::string& name, T callback ) { - std::string parsed = this->formatHookName( name ); +size_t uf::Object::addHook( const uf::stl::string& name, T callback ) { + uf::stl::string parsed = this->formatHookName( name ); std::size_t id = uf::hooks.addHook( parsed, callback ); #if UF_ENTITY_METADATA_USE_JSON auto& metadata = this->getComponent(); @@ -30,7 +30,7 @@ size_t uf::Object::addHook( const std::string& name, T callback ) { return id; } template -uf::Hooks::return_t uf::Object::callHook( const std::string& name, const T& p ) { +uf::Hooks::return_t uf::Object::callHook( const uf::stl::string& name, const T& p ) { uf::Userdata payload; payload.create(p); return uf::hooks.call( this->formatHookName( name ), payload ); diff --git a/engine/inc/uf/engine/scene/behavior.h b/engine/inc/uf/engine/scene/behavior.h index 713fdee8..0778ed6a 100644 --- a/engine/inc/uf/engine/scene/behavior.h +++ b/engine/inc/uf/engine/scene/behavior.h @@ -9,7 +9,7 @@ namespace uf { void UF_API render( uf::Object& ); void UF_API destroy( uf::Object& ); struct Metadata { - std::vector graph; + uf::stl::vector graph; bool invalidationQueued = false; struct { uf::Entity* controller = NULL; diff --git a/engine/inc/uf/engine/scene/scene.h b/engine/inc/uf/engine/scene/scene.h index cde9fcc1..13d3fa4b 100644 --- a/engine/inc/uf/engine/scene/scene.h +++ b/engine/inc/uf/engine/scene/scene.h @@ -12,8 +12,8 @@ namespace uf { uf::Entity& getController(); const uf::Entity& getController() const; - const std::vector& getGraph(); - std::vector getGraph( bool ); + const uf::stl::vector& getGraph(); + uf::stl::vector getGraph( bool ); void invalidateGraph(); template T& getController() { @@ -25,18 +25,18 @@ namespace uf { }; namespace scene { - extern UF_API std::vector scenes; - // extern UF_API std::vector graph; + extern UF_API uf::stl::vector scenes; + // extern UF_API uf::stl::vector graph; // extern UF_API bool queuedInvalidation; // extern UF_API bool useGraph; // void UF_API invalidateGraph(); - // std::vector UF_API generateGraph( bool = false ); + // uf::stl::vector UF_API generateGraph( bool = false ); void UF_API invalidateGraphs(); Scene& UF_API getCurrentScene(); - Scene& UF_API loadScene( const std::string& name, const std::string& filename = "" ); - Scene& UF_API loadScene( const std::string& name, const uf::Serializer& ); + Scene& UF_API loadScene( const uf::stl::string& name, const uf::stl::string& filename = "" ); + Scene& UF_API loadScene( const uf::stl::string& name, const uf::Serializer& ); void UF_API unloadScene(); void UF_API tick(); diff --git a/engine/inc/uf/ext/ext.h b/engine/inc/uf/ext/ext.h index 1254667c..21098dc4 100644 --- a/engine/inc/uf/ext/ext.h +++ b/engine/inc/uf/ext/ext.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #if !defined(EXT_STATIC) #if defined(UF_ENV_WINDOWS) @@ -36,11 +36,11 @@ #define EXT_API EXT_API_IMPORT #endif -#include +#include #include namespace ext { extern bool EXT_API ready; - extern std::vector EXT_API arguments; + extern uf::stl::vector EXT_API arguments; extern uf::Serializer EXT_API config; extern void EXT_API load(); diff --git a/engine/inc/uf/ext/freetype/freetype.h b/engine/inc/uf/ext/freetype/freetype.h index cf69c954..fd57ec3e 100644 --- a/engine/inc/uf/ext/freetype/freetype.h +++ b/engine/inc/uf/ext/freetype/freetype.h @@ -29,8 +29,8 @@ namespace ext { UF_API bool initialized(); UF_API void terminate(); - UF_API ext::freetype::Glyph initialize( const std::string& ); - UF_API bool initialize( ext::freetype::Glyph&, const std::string& ); + UF_API ext::freetype::Glyph initialize( const uf::stl::string& ); + UF_API bool initialize( ext::freetype::Glyph&, const uf::stl::string& ); UF_API void destroy( ext::freetype::Glyph& ); UF_API void setPixelSizes( ext::freetype::Glyph&, int ); @@ -39,7 +39,7 @@ namespace ext { UF_API bool load( ext::freetype::Glyph&, unsigned long ); UF_API bool load( ext::freetype::Glyph&, const uf::String& ); - UF_API std::string getError( int ); + UF_API uf::stl::string getError( int ); } } diff --git a/engine/inc/uf/ext/glfw/glfw.h b/engine/inc/uf/ext/glfw/glfw.h index 018b2e2c..5cb626e8 100644 --- a/engine/inc/uf/ext/glfw/glfw.h +++ b/engine/inc/uf/ext/glfw/glfw.h @@ -5,8 +5,8 @@ #define GLFW_INCLUDE_VULKAN #include -#include -#include +#include +#include namespace ext { namespace glfw { @@ -14,16 +14,16 @@ namespace ext { protected: size_t m_width; size_t m_height; - std::string m_title; + uf::stl::string m_title; GLFWwindow* m_window; public: - void initialize( size_t width = 800, size_t height = 600, const std::string& title = "Window" ); + void initialize( size_t width = 800, size_t height = 600, const uf::stl::string& title = "Window" ); void createSurface( VkInstance instance, VkSurfaceKHR& surface ); void destroy(); bool loop(); void poll(); bool minimized(); - std::vector getExtensions( bool ); + uf::stl::vector getExtensions( bool ); operator GLFWwindow*(); }; } diff --git a/engine/inc/uf/ext/gltf/gltf.h b/engine/inc/uf/ext/gltf/gltf.h index 297c4090..a5254714 100644 --- a/engine/inc/uf/ext/gltf/gltf.h +++ b/engine/inc/uf/ext/gltf/gltf.h @@ -6,7 +6,7 @@ namespace ext { namespace gltf { - pod::Graph UF_API load( const std::string&, uf::graph::load_mode_t = 0, const uf::Serializer& = {} ); - void UF_API save( const std::string&, const pod::Graph& ); + pod::Graph UF_API load( const uf::stl::string&, uf::graph::load_mode_t = 0, const uf::Serializer& = {} ); + void UF_API save( const uf::stl::string&, const pod::Graph& ); } } \ No newline at end of file diff --git a/engine/inc/uf/ext/json/json.h b/engine/inc/uf/ext/json/json.h index f1deef1d..f2b2504b 100644 --- a/engine/inc/uf/ext/json/json.h +++ b/engine/inc/uf/ext/json/json.h @@ -30,29 +30,29 @@ namespace ext { // cares not about breaking void UF_API forEach( ext::json::Value& json, const std::function& function ); void UF_API forEach( ext::json::Value& json, const std::function& function ); - void UF_API forEach( ext::json::Value& json, const std::function& function ); + void UF_API forEach( ext::json::Value& json, const std::function& function ); // handles breaks void UF_API forEach( ext::json::Value& json, const std::function& function ); void UF_API forEach( ext::json::Value& json, const std::function& function ); - void UF_API forEach( ext::json::Value& json, const std::function& function ); + void UF_API forEach( ext::json::Value& json, const std::function& function ); // const void UF_API forEach( const ext::json::Value& json, const std::function& function ); void UF_API forEach( const ext::json::Value& json, const std::function& function ); void UF_API forEach( const ext::json::Value& json, const std::function& function ); - void UF_API forEach( const ext::json::Value& json, const std::function& function ); + void UF_API forEach( const ext::json::Value& json, const std::function& function ); void UF_API forEach( const ext::json::Value& json, const std::function& function ); - void UF_API forEach( const ext::json::Value& json, const std::function& function ); + void UF_API forEach( const ext::json::Value& json, const std::function& function ); ext::json::Value UF_API reencode( const ext::json::Value& json, const ext::json::EncodingSettings& settings ); ext::json::Value& UF_API reencode( ext::json::Value& json, const ext::json::EncodingSettings& settings ); - std::string UF_API encode( const ext::json::Value& json, bool pretty = true ); - std::string UF_API encode( const ext::json::Value& json, const ext::json::EncodingSettings& settings ); - ext::json::Value& UF_API decode( ext::json::Value& json, const std::string& str ); + uf::stl::string UF_API encode( const ext::json::Value& json, bool pretty = true ); + uf::stl::string UF_API encode( const ext::json::Value& json, const ext::json::EncodingSettings& settings ); + ext::json::Value& UF_API decode( ext::json::Value& json, const uf::stl::string& str ); #if UF_USE_LUA - std::string UF_API encode( const sol::table& table ); + uf::stl::string UF_API encode( const sol::table& table ); #endif } } \ No newline at end of file diff --git a/engine/inc/uf/ext/json/jsoncpp.h b/engine/inc/uf/ext/json/jsoncpp.h index 1c526b1b..62252bd8 100644 --- a/engine/inc/uf/ext/json/jsoncpp.h +++ b/engine/inc/uf/ext/json/jsoncpp.h @@ -32,7 +32,7 @@ namespace ext { inline Value object() { return Value(Json::objectValue); } inline Value null() { return Value(Json::nullValue); } - inline std::vector keys( const Value& v ) { return v.getMemberNames(); } + inline uf::stl::vector keys( const Value& v ) { return v.getMemberNames(); } } } diff --git a/engine/inc/uf/ext/json/nlohmann.h b/engine/inc/uf/ext/json/nlohmann.h index ecd0176e..bcb1c08f 100644 --- a/engine/inc/uf/ext/json/nlohmann.h +++ b/engine/inc/uf/ext/json/nlohmann.h @@ -2,6 +2,9 @@ #include +#include +#include + #include #include @@ -45,7 +48,7 @@ namespace ext { inline Value null() { return Value(); } Value& UF_API reserve( Value& value, size_t size ); - std::vector UF_API keys( const Value& v ); + uf::stl::vector UF_API keys( const Value& v ); } } /* @@ -90,7 +93,7 @@ template<> inline bool ext::json::Value::is(bool strict) const { retur template<> inline bool ext::json::Value::is(bool strict) const { return strict ? is_number_unsigned() : is_number(); } template<> inline bool ext::json::Value::is(bool strict) const { return strict ? is_number_float() : is_number(); } template<> inline bool ext::json::Value::is(bool strict) const { return strict ? is_number_float() : is_number(); } -template<> inline bool ext::json::Value::is(bool strict) const { return is_string(); } +template<> inline bool ext::json::Value::is(bool strict) const { return is_string(); } #if UF_ENV_DREAMCAST template<> inline bool ext::json::Value::is(bool strict) const { return strict ? is_number_integer() : is_number(); } @@ -116,7 +119,7 @@ template<> inline bool ext::json::Value::as() const { // implicit conversion if ( is_null() ) return false; // always return falce if ( is_number() ) return get(); // implicit conversion to bool - if ( is_string() ) return get() != ""; // true if not empty + if ( is_string() ) return get() != ""; // true if not empty if ( is_object() ) return !ext::json::keys( *this ).empty(); // true if not empty if ( is_array() ) return size() > 0; // true if not empty return false; diff --git a/engine/inc/uf/ext/json/rapidjson.h b/engine/inc/uf/ext/json/rapidjson.h index 0748de9d..7d4f4264 100644 --- a/engine/inc/uf/ext/json/rapidjson.h +++ b/engine/inc/uf/ext/json/rapidjson.h @@ -39,7 +39,7 @@ namespace ext { } inline Value null() { return Value(); } - std::vector UF_API keys( const Value& v ); + uf::stl::vector UF_API keys( const Value& v ); static rapidjson::Document::AllocatorType allocator; struct Document : public rapidjson::Document { @@ -53,7 +53,7 @@ namespace ext { } template ext::json::Value& ext::json::Value::operator[]( Args... args ) { - const std::string k(args...); + const uf::stl::string k(args...); auto key = rapidjson::StringRef(k.c_str()); auto it = ext::json::base_value::FindMember(key); if ( it != ext::json::base_value::MemberEnd() ) @@ -64,7 +64,7 @@ template ext::json::Value& ext::json::Value::operator[]( Args. return this->operator[](args...); } template const ext::json::Value& ext::json::Value::operator[]( Args... args ) const { - const std::string k(args...); + const uf::stl::string k(args...); auto key = rapidjson::StringRef(k.c_str()); auto it = ext::json::base_value::FindMember(key); if ( it != ext::json::base_value::MemberEnd() ) @@ -72,7 +72,7 @@ template const ext::json::Value& ext::json::Value::operator[]( return ext::json::base_value(); } -template<> inline ext::json::Value& ext::json::Value::operator=( std::string v ) { +template<> inline ext::json::Value& ext::json::Value::operator=( uf::stl::string v ) { ext::json::base_value::SetString( v.c_str(), ext::json::allocator ); return *this; } @@ -98,7 +98,7 @@ template<> inline ext::json::Value& ext::json::Value::operator=( double } template ext::json::Value& ext::json::Document::operator[]( Args... args ) { - const std::string k(args...); + const uf::stl::string k(args...); auto key = rapidjson::StringRef(k.c_str()); auto it = rapidjson::Document::FindMember(key); if ( it != rapidjson::Document::MemberEnd() ) @@ -109,7 +109,7 @@ template ext::json::Value& ext::json::Document::operator[]( Ar return this->operator[](args...); } template const ext::json::Value& ext::json::Document::operator[]( Args... args ) const { - const std::string k(args...); + const uf::stl::string k(args...); auto key = rapidjson::StringRef(k.c_str()); auto it = rapidjson::Document::FindMember(key); if ( it != rapidjson::Document::MemberEnd() ) @@ -123,14 +123,14 @@ template<> inline bool ext::json::Value::is() const { return IsInt64(); } template<> inline bool ext::json::Value::is() const { return IsUint64(); } template<> inline bool ext::json::Value::is() const { return IsDouble(); } template<> inline bool ext::json::Value::is() const { return IsDouble(); } -template<> inline bool ext::json::Value::is() const { return IsString(); } +template<> inline bool ext::json::Value::is() const { return IsString(); } template<> inline bool ext::json::Value::get() const { return GetBool(); } template<> inline int ext::json::Value::get() const { return GetInt(); } template<> inline size_t ext::json::Value::get() const { return GetUint64(); } template<> inline float ext::json::Value::get() const { return GetDouble(); } template<> inline double ext::json::Value::get() const { return GetDouble(); } -template<> inline std::string ext::json::Value::get() const { return GetString(); } +template<> inline uf::stl::string ext::json::Value::get() const { return GetString(); } template inline T ext::json::Value::as() const { if ( !is() ) return T(); @@ -140,7 +140,7 @@ template<> inline bool ext::json::Value::as() const { if ( is() ) return get(); if ( IsNull() ) return false; if ( IsNumber() ) return get() != 0; - if ( IsString() ) return get() != ""; + if ( IsString() ) return get() != ""; if ( IsObject() ) return !ext::json::keys( *this ).empty(); if ( IsArray() ) return size() > 0; return false; diff --git a/engine/inc/uf/ext/lua/lua.h b/engine/inc/uf/ext/lua/lua.h index db8d1f13..fc3af410 100644 --- a/engine/inc/uf/ext/lua/lua.h +++ b/engine/inc/uf/ext/lua/lua.h @@ -16,13 +16,13 @@ #endif #include -#include +#include #include #include namespace pod { struct UF_API LuaScript { - std::string file; + uf::stl::string file; sol::environment env; }; } @@ -30,23 +30,23 @@ namespace pod { namespace ext { namespace lua { extern UF_API sol::state state; - extern UF_API std::string main; - extern UF_API std::unordered_map modules; - extern UF_API std::vector>* onInitializationFunctions; + extern UF_API uf::stl::string main; + extern UF_API uf::stl::unordered_map modules; + extern UF_API uf::stl::vector>* onInitializationFunctions; void UF_API initialize(); void UF_API terminate(); void UF_API onInitialization( const std::function& ); - bool UF_API run( const std::string&, bool = true ); + bool UF_API run( const uf::stl::string&, bool = true ); - pod::LuaScript UF_API script( const std::string& ); + pod::LuaScript UF_API script( const uf::stl::string& ); bool UF_API run( const pod::LuaScript&, bool = true ); sol::table createTable(); - std::string sanitize( const std::string& dirty, int index = -1 ); - std::optional encode( sol::table table ); - std::optional decode( const std::string& string ); + uf::stl::string sanitize( const uf::stl::string& dirty, int index = -1 ); + std::optional encode( sol::table table ); + std::optional decode( const uf::stl::string& string ); } } diff --git a/engine/inc/uf/ext/lua/lua.inl b/engine/inc/uf/ext/lua/lua.inl index c72ac197..4e0fbc62 100644 --- a/engine/inc/uf/ext/lua/lua.inl +++ b/engine/inc/uf/ext/lua/lua.inl @@ -7,7 +7,7 @@ namespace {\ static uf::StaticInitialization TOKEN_PASTE(STATIC_INITIALIZATION_, __LINE__)( []{\ ext::lua::onInitialization( []{\ - std::string name = UF_NS_GET_LAST(type);\ + uf::stl::string name = UF_NS_GET_LAST(type);\ auto usertype = ext::lua::state.new_usertype(name); #define UF_LUA_REGISTER_USERTYPE_DEFINE_RT(k, v) usertype[#k] = v; diff --git a/engine/inc/uf/ext/ncurses/ncurses.h b/engine/inc/uf/ext/ncurses/ncurses.h index 1ee6d16e..11088cf6 100644 --- a/engine/inc/uf/ext/ncurses/ncurses.h +++ b/engine/inc/uf/ext/ncurses/ncurses.h @@ -2,7 +2,7 @@ #include -#include +#include namespace ext { class UF_API Ncurses { @@ -34,7 +34,7 @@ namespace ext { void UF_API_CALL delCh(); void UF_API_CALL addCh( char c ); void UF_API_CALL addStr(const char* c_str); - void UF_API_CALL addStr(const std::string str); + void UF_API_CALL addStr(const uf::stl::string str); void UF_API_CALL attrOn(int att); void UF_API_CALL attrOff(int att); @@ -47,7 +47,7 @@ namespace ext { inline int UF_API_CALL getChar() { return this->getCh(); } inline void UF_API_CALL delChar() { this->delCh(); } inline void UF_API_CALL addChar( char c ) { this->addCh( c ); } - inline void UF_API_CALL addString( const std::string& str ) { this->addStr( str.c_str() ); } + inline void UF_API_CALL addString( const uf::stl::string& str ) { this->addStr( str.c_str() ); } inline void UF_API_CALL attribute(int att, bool on = true) { on ? this->attrOn(att) : this->attrOff(att); } }; extern UF_API ext::Ncurses ncurses; diff --git a/engine/inc/uf/ext/oal/buffer.h b/engine/inc/uf/ext/oal/buffer.h index 5565f367..7b86cc06 100644 --- a/engine/inc/uf/ext/oal/buffer.h +++ b/engine/inc/uf/ext/oal/buffer.h @@ -11,7 +11,7 @@ namespace ext { namespace al { class UF_API Buffer { protected: - std::vector m_indices; + uf::stl::vector m_indices; public: // Buffer( size_t = 1 ); // ~Buffer(); diff --git a/engine/inc/uf/ext/oal/oal.h b/engine/inc/uf/ext/oal/oal.h index 9428396a..94bd9c70 100644 --- a/engine/inc/uf/ext/oal/oal.h +++ b/engine/inc/uf/ext/oal/oal.h @@ -7,8 +7,8 @@ #include #include -#include -#include +#include +#include #define AL_CHECK_RESULT(f) {\ (f);\ @@ -16,7 +16,7 @@ if ( error != AL_NO_ERROR ) UF_MSG_ERROR("AL error: " << ext::al::getError(error) << ": " << #f);\ } -// std::string errorString = alutGetErrorString(alutGetError()); +// uf::stl::string errorString = alutGetErrorString(alutGetError()); // if ( errorString != "No ALUT error found" ) UF_MSG_ERROR("AL error: " << errorString); #include "source.h" @@ -35,18 +35,18 @@ namespace ext { void UF_API listener( ALenum name, ALfloat x, ALfloat y, ALfloat z ); void UF_API listener( ALenum name, const ALfloat* f ); - void UF_API listener( const std::string& name, ALfloat x ); - void UF_API listener( const std::string& name, ALfloat x, ALfloat y, ALfloat z ); - void UF_API listener( const std::string& name, const ALfloat* f ); + void UF_API listener( const uf::stl::string& name, ALfloat x ); + void UF_API listener( const uf::stl::string& name, ALfloat x, ALfloat y, ALfloat z ); + void UF_API listener( const uf::stl::string& name, const ALfloat* f ); */ - std::string UF_API getError( ALenum = 0 ); + uf::stl::string UF_API getError( ALenum = 0 ); - uf::audio::Metadata* UF_API create( const std::string&, bool, uint8_t ); - uf::audio::Metadata* UF_API open( const std::string& ); - uf::audio::Metadata* UF_API open( const std::string&, bool ); - uf::audio::Metadata* UF_API load( const std::string& ); - uf::audio::Metadata* UF_API stream( const std::string& ); + uf::audio::Metadata* UF_API create( const uf::stl::string&, bool, uint8_t ); + uf::audio::Metadata* UF_API open( const uf::stl::string& ); + uf::audio::Metadata* UF_API open( const uf::stl::string&, bool ); + uf::audio::Metadata* UF_API load( const uf::stl::string& ); + uf::audio::Metadata* UF_API stream( const uf::stl::string& ); void UF_API update( uf::audio::Metadata& ); void UF_API close( uf::audio::Metadata* ); diff --git a/engine/inc/uf/ext/oal/source.h b/engine/inc/uf/ext/oal/source.h index 21b0a155..c08ddfd1 100644 --- a/engine/inc/uf/ext/oal/source.h +++ b/engine/inc/uf/ext/oal/source.h @@ -38,21 +38,21 @@ namespace ext { void set( ALenum name, ALint x, ALint y, ALint z ); void set( ALenum name, const ALint* f ); - void get( const std::string& name, ALfloat& x ); - void get( const std::string& name, ALfloat& x, ALfloat& y, ALfloat& z ); - void get( const std::string& name, ALfloat* f ); + void get( const uf::stl::string& name, ALfloat& x ); + void get( const uf::stl::string& name, ALfloat& x, ALfloat& y, ALfloat& z ); + void get( const uf::stl::string& name, ALfloat* f ); - void get( const std::string& name, ALint& x ); - void get( const std::string& name, ALint& x, ALint& y, ALint& z ); - void get( const std::string& name, ALint* f ); + void get( const uf::stl::string& name, ALint& x ); + void get( const uf::stl::string& name, ALint& x, ALint& y, ALint& z ); + void get( const uf::stl::string& name, ALint* f ); - void set( const std::string& name, ALfloat x ); - void set( const std::string& name, ALfloat x, ALfloat y, ALfloat z ); - void set( const std::string& name, const ALfloat* f ); + void set( const uf::stl::string& name, ALfloat x ); + void set( const uf::stl::string& name, ALfloat x, ALfloat y, ALfloat z ); + void set( const uf::stl::string& name, const ALfloat* f ); - void set( const std::string& name, ALint x ); - void set( const std::string& name, ALint x, ALint y, ALint z ); - void set( const std::string& name, const ALint* f ); + void set( const uf::stl::string& name, ALint x ); + void set( const uf::stl::string& name, ALint x, ALint y, ALint z ); + void set( const uf::stl::string& name, const ALint* f ); void play(); void stop(); diff --git a/engine/inc/uf/ext/opengl/buffer.h b/engine/inc/uf/ext/opengl/buffer.h index d9e55396..29721e34 100644 --- a/engine/inc/uf/ext/opengl/buffer.h +++ b/engine/inc/uf/ext/opengl/buffer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -59,7 +59,7 @@ namespace ext { void destroy(); }; struct UF_API Buffers { - std::vector buffers; + uf::stl::vector buffers; Device* device; // ~Buffers(); diff --git a/engine/inc/uf/ext/opengl/commands.h b/engine/inc/uf/ext/opengl/commands.h index 78115ad8..13c23b04 100644 --- a/engine/inc/uf/ext/opengl/commands.h +++ b/engine/inc/uf/ext/opengl/commands.h @@ -103,7 +103,7 @@ namespace ext { Device* device; size_t state = 0; - std::vector infos; + uf::stl::vector infos; std::mutex* mutex; void initialize( Device& device ); @@ -121,8 +121,8 @@ namespace ext { protected: pod::Matrix4f bindUniform( const Buffer::Descriptor& descriptor ); void drawIndexed( const InfoDraw& ); - // void draw( const InfoDraw&, const Info&, const std::vector& = {} ); - // void drawIndexed( const InfoDraw&, const Info&, const Info&, const std::vector& = {} ); + // void draw( const InfoDraw&, const Info&, const uf::stl::vector& = {} ); + // void drawIndexed( const InfoDraw&, const Info&, const Info&, const uf::stl::vector& = {} ); }; } } \ No newline at end of file diff --git a/engine/inc/uf/ext/opengl/device.h b/engine/inc/uf/ext/opengl/device.h index 10ed3bba..452e9ffe 100644 --- a/engine/inc/uf/ext/opengl/device.h +++ b/engine/inc/uf/ext/opengl/device.h @@ -25,7 +25,7 @@ namespace ext { enums::Command::type_t type; std::deque available; - std::vector pool; + uf::stl::vector pool; void allocate(); void allocate(size_t); diff --git a/engine/inc/uf/ext/opengl/graphic.h b/engine/inc/uf/ext/opengl/graphic.h index 2a09f5d1..d30007ce 100644 --- a/engine/inc/uf/ext/opengl/graphic.h +++ b/engine/inc/uf/ext/opengl/graphic.h @@ -19,7 +19,7 @@ namespace ext { #if !UF_USE_OPENGL_FIXED_FUNCTION GLuint pipeline; GLuint vertexArray; - std::vector descriptorSet; + uf::stl::vector descriptorSet; #endif struct Descriptor { @@ -30,7 +30,7 @@ namespace ext { struct { uf::Serializer json; - std::string type = ""; + uf::stl::string type = ""; bool process = true; } metadata; @@ -45,22 +45,22 @@ namespace ext { bool aliased = false; Device* device; - std::vector samplers; - std::vector textures; - std::vector shaders; + uf::stl::vector samplers; + uf::stl::vector textures; + uf::stl::vector shaders; struct Metadata { uf::Serializer json; - std::unordered_map shaders; + uf::stl::unordered_map shaders; } metadata; void initialize( Device& device ); void destroy(); - void attachShader( const std::string&, enums::Shader::type_t, const std::string& pipeline = "" ); - void initializeShaders( const std::vector>&, const std::string& pipeline = "" ); + void attachShader( const uf::stl::string&, enums::Shader::type_t, const uf::stl::string& pipeline = "" ); + void initializeShaders( const uf::stl::vector>&, const uf::stl::string& pipeline = "" ); - bool hasShader( const std::string& type, const std::string& pipeline = "" ); - Shader& getShader( const std::string& type, const std::string& pipeline = "" ); + bool hasShader( const uf::stl::string& type, const uf::stl::string& pipeline = "" ); + Shader& getShader( const uf::stl::string& type, const uf::stl::string& pipeline = "" ); bool validate(); }; @@ -70,14 +70,14 @@ namespace ext { bool initialized = false; bool process = true; Material material; - std::unordered_map pipelines; + uf::stl::unordered_map pipelines; struct { - std::unordered_map buffers; + uf::stl::unordered_map buffers; } metadata; ~Graphic(); - void initialize( const std::string& = "" ); + void initialize( const uf::stl::string& = "" ); void destroy(); template @@ -94,10 +94,10 @@ namespace ext { void record( CommandBuffer& commandBuffer, size_t pass = 0, size_t draw = 0 ); void record( CommandBuffer& commandBuffer, GraphicDescriptor& descriptor, size_t pass = 0, size_t draw = 0 ); - bool hasStorage( const std::string& name ); - Buffer* getStorageBuffer( const std::string& name ); - uf::Serializer getStorageJson( const std::string& name, bool cache = true ); - ext::opengl::userdata_t getStorageUserdata( const std::string& name, const ext::json::Value& payload ); + bool hasStorage( const uf::stl::string& name ); + Buffer* getStorageBuffer( const uf::stl::string& name ); + uf::Serializer getStorageJson( const uf::stl::string& name, bool cache = true ); + ext::opengl::userdata_t getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ); Buffer::Descriptor getUniform( size_t = 0 ) const; void updateUniform( void*, size_t, size_t = 0 ); diff --git a/engine/inc/uf/ext/opengl/opengl.h b/engine/inc/uf/ext/opengl/opengl.h index 2f74c061..e7167673 100644 --- a/engine/inc/uf/ext/opengl/opengl.h +++ b/engine/inc/uf/ext/opengl/opengl.h @@ -18,10 +18,10 @@ namespace ext { extern UF_API size_t viewCount; constexpr size_t maxViews = 6; - extern UF_API std::vector validationFilters; - extern UF_API std::vector requestedDeviceFeatures; - extern UF_API std::vector requestedDeviceExtensions; - extern UF_API std::vector requestedInstanceExtensions; + extern UF_API uf::stl::vector validationFilters; + extern UF_API uf::stl::vector requestedDeviceFeatures; + extern UF_API uf::stl::vector requestedDeviceExtensions; + extern UF_API uf::stl::vector requestedInstanceExtensions; extern UF_API ext::opengl::enums::Filter::type_t swapchainUpscaleFilter; @@ -31,7 +31,7 @@ namespace ext { extern UF_API bool individualPipelines; extern UF_API bool multithreadedCommandRecording; extern UF_API bool multithreadedCommandRendering; - extern UF_API std::string deferredMode; + extern UF_API uf::stl::string deferredMode; extern UF_API bool deferredReconstructPosition; extern UF_API bool deferredAliasOutputToSwapchain; extern UF_API bool multiview; @@ -61,14 +61,14 @@ namespace ext { extern UF_API std::mutex immediateModeMutex; extern UF_API RenderMode* currentRenderMode; - extern UF_API std::vector renderModes; - extern UF_API std::vector scenes; + extern UF_API uf::stl::vector renderModes; + extern UF_API uf::stl::vector scenes; - bool UF_API hasRenderMode( const std::string&, bool = true ); - RenderMode& UF_API addRenderMode( RenderMode*, const std::string& = "" ); - RenderMode& UF_API getRenderMode( const std::string&, bool = true ); - std::vector UF_API getRenderModes( const std::string&, bool = true ); - std::vector UF_API getRenderModes( const std::vector&, bool = true ); + bool UF_API hasRenderMode( const uf::stl::string&, bool = true ); + RenderMode& UF_API addRenderMode( RenderMode*, const uf::stl::string& = "" ); + RenderMode& UF_API getRenderMode( const uf::stl::string&, bool = true ); + uf::stl::vector UF_API getRenderModes( const uf::stl::string&, bool = true ); + uf::stl::vector UF_API getRenderModes( const uf::stl::vector&, bool = true ); void UF_API removeRenderMode( RenderMode*, bool = true ); void UF_API initialize( /*uint8_t = 0*/ ); @@ -76,11 +76,11 @@ namespace ext { void UF_API render(); void UF_API destroy(); void UF_API synchronize( uint8_t = 0b11 ); - std::string UF_API allocatorStats(); + uf::stl::string UF_API allocatorStats(); - ext::opengl::enums::Format::type_t UF_API formatFromString( const std::string& ); + ext::opengl::enums::Format::type_t UF_API formatFromString( const uf::stl::string& ); - std::string UF_API errorString(); - std::string UF_API errorString( GLenum ); + uf::stl::string UF_API errorString(); + uf::stl::string UF_API errorString( GLenum ); }; } \ No newline at end of file diff --git a/engine/inc/uf/ext/opengl/rendermode.h b/engine/inc/uf/ext/opengl/rendermode.h index f51a0d50..8ed741c9 100644 --- a/engine/inc/uf/ext/opengl/rendermode.h +++ b/engine/inc/uf/ext/opengl/rendermode.h @@ -17,10 +17,10 @@ namespace ext { struct { uf::Serializer json; - std::string name = ""; - std::string type = ""; - std::string target = ""; - std::vector outputs; + uf::stl::string name = ""; + uf::stl::string type = ""; + uf::stl::string target = ""; + uf::stl::vector outputs; uint8_t subpasses = 1; uint8_t samples = 1; @@ -36,21 +36,21 @@ namespace ext { RenderTarget renderTarget; GLhandle(VkSemaphore) renderCompleteSemaphore; - std::vector fences; + uf::stl::vector fences; std::thread::id mostRecentCommandPoolId; uf::ThreadUnique commands; virtual ~RenderMode(); // RAII - virtual const std::string getName() const; - virtual const std::string getType() const; + virtual const uf::stl::string getName() const; + virtual const uf::stl::string getType() const; virtual RenderTarget& getRenderTarget(size_t = 0); virtual const RenderTarget& getRenderTarget(size_t = 0) const; virtual const size_t blitters() const; virtual ext::opengl::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual CommandBuffer& getCommands(); virtual CommandBuffer& getCommands( std::thread::id ); @@ -60,9 +60,9 @@ namespace ext { virtual void initialize( Device& device ); virtual void createCommandBuffers(); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void bindPipelines(); - virtual void bindPipelines( const std::vector& graphics ); + virtual void bindPipelines( const uf::stl::vector& graphics ); virtual void tick(); virtual void render(); virtual void destroy(); diff --git a/engine/inc/uf/ext/opengl/rendermodes/base.h b/engine/inc/uf/ext/opengl/rendermodes/base.h index 014d35d0..9696e918 100644 --- a/engine/inc/uf/ext/opengl/rendermodes/base.h +++ b/engine/inc/uf/ext/opengl/rendermodes/base.h @@ -7,10 +7,10 @@ namespace ext { struct UF_API BaseRenderMode : public RenderMode { // virtual ~RenderMode(); // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual void initialize( Device& device ); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void tick(); virtual void render(); virtual void destroy(); diff --git a/engine/inc/uf/ext/opengl/rendermodes/compute.h b/engine/inc/uf/ext/opengl/rendermodes/compute.h index 55f9a618..8adeb108 100644 --- a/engine/inc/uf/ext/opengl/rendermodes/compute.h +++ b/engine/inc/uf/ext/opengl/rendermodes/compute.h @@ -10,10 +10,10 @@ namespace ext { pod::Vector2ui dispatchSize = { 32, 32 }; // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual const size_t blitters() const; virtual ext::opengl::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual void createCommandBuffers(); virtual void initialize( Device& device ); diff --git a/engine/inc/uf/ext/opengl/rendermodes/deferred.h b/engine/inc/uf/ext/opengl/rendermodes/deferred.h index 2f0e54f0..d1bef5ea 100644 --- a/engine/inc/uf/ext/opengl/rendermodes/deferred.h +++ b/engine/inc/uf/ext/opengl/rendermodes/deferred.h @@ -9,12 +9,12 @@ namespace ext { ext::opengl::Graphic blitter; // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual const size_t blitters() const; virtual ext::opengl::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void initialize( Device& device ); virtual void tick(); virtual void destroy(); diff --git a/engine/inc/uf/ext/opengl/rendermodes/rendertarget.h b/engine/inc/uf/ext/opengl/rendermodes/rendertarget.h index a02bab97..9f880768 100644 --- a/engine/inc/uf/ext/opengl/rendermodes/rendertarget.h +++ b/engine/inc/uf/ext/opengl/rendermodes/rendertarget.h @@ -8,18 +8,18 @@ namespace ext { struct UF_API RenderTargetRenderMode : public RenderMode { ext::opengl::Graphic blitter; // - const std::string getTarget() const; - void setTarget( const std::string& ); + const uf::stl::string getTarget() const; + void setTarget( const uf::stl::string& ); // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual const size_t blitters() const; virtual ext::opengl::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual GraphicDescriptor bindGraphicDescriptor( const GraphicDescriptor&, size_t = 0 ); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void initialize( Device& device ); virtual void tick(); virtual void destroy(); diff --git a/engine/inc/uf/ext/opengl/rendertarget.h b/engine/inc/uf/ext/opengl/rendertarget.h index 70500594..58621404 100644 --- a/engine/inc/uf/ext/opengl/rendertarget.h +++ b/engine/inc/uf/ext/opengl/rendertarget.h @@ -2,7 +2,7 @@ #include #include -#include +#include namespace ext { namespace opengl { @@ -28,31 +28,31 @@ namespace ext { GLhandle(VkPipelineColorBlendAttachmentState) blendState; }; - std::vector attachments; + uf::stl::vector attachments; struct Subpass { GLhandle(VkPipelineStageFlags) stage; GLhandle(VkAccessFlags) access; bool autoBuildPipeline; - std::vector colors; - std::vector inputs; - std::vector resolves; + uf::stl::vector colors; + uf::stl::vector inputs; + uf::stl::vector resolves; GLhandle(VkAttachmentReference) depth; }; - std::vector passes; + uf::stl::vector passes; bool initialized = false; Device* device = GL_NULL_HANDLE; GLhandle(VkRenderPass) renderPass = GL_NULL_HANDLE; - std::vector framebuffers; + uf::stl::vector framebuffers; uint32_t width = 0; uint32_t height = 0; uint8_t views = 1; // RAII void initialize( Device& device ); void destroy(); - void addPass( GLhandle(VkPipelineStageFlags), GLhandle(VkAccessFlags), const std::vector&, const std::vector&, const std::vector&, size_t, bool = true ); + void addPass( GLhandle(VkPipelineStageFlags), GLhandle(VkAccessFlags), const uf::stl::vector&, const uf::stl::vector&, const uf::stl::vector&, size_t, bool = true ); size_t attach( const Attachment::Descriptor& descriptor, Attachment* attachment = NULL ); }; } diff --git a/engine/inc/uf/ext/opengl/shader.h b/engine/inc/uf/ext/opengl/shader.h index 5d25ee68..9403f3fc 100644 --- a/engine/inc/uf/ext/opengl/shader.h +++ b/engine/inc/uf/ext/opengl/shader.h @@ -28,7 +28,7 @@ namespace ext { bool aliased = false; Device* device = NULL; - std::string filename = ""; + uf::stl::string filename = ""; #if !UF_USE_OPENGL_FIXED_FUNCTION GLuint module = GL_NULL_HANDLE; @@ -44,67 +44,67 @@ namespace ext { struct Metadata { uf::Serializer json; - std::string pipeline = ""; - std::string type = ""; + uf::stl::string pipeline = ""; + uf::stl::string type = ""; struct Definition { struct Texture { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; ext::opengl::enums::Image::viewType_t type{}; }; struct Uniform { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; }; struct Storage { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; }; struct PushConstant { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; }; - std::unordered_map textures; - std::unordered_map uniforms; - std::unordered_map storage; - std::unordered_map pushConstants; + uf::stl::unordered_map textures; + uf::stl::unordered_map uniforms; + uf::stl::unordered_map storage; + uf::stl::unordered_map pushConstants; } definitions; } metadata; ext::opengl::userdata_t specializationConstants; - std::vector pushConstants; - std::vector uniforms; + uf::stl::vector pushConstants; + uf::stl::vector uniforms; // ~Shader(); - void initialize( Device& device, const std::string&, enums::Shader::type_t stage ); + void initialize( Device& device, const uf::stl::string&, enums::Shader::type_t stage ); void destroy(); bool validate(); - bool hasUniform( const std::string& name ); + bool hasUniform( const uf::stl::string& name ); - Buffer* getUniformBuffer( const std::string& name ); - ext::opengl::userdata_t& getUniform( const std::string& name ); - uf::Serializer getUniformJson( const std::string& name, bool cache = true ); - ext::opengl::userdata_t getUniformUserdata( const std::string& name, const ext::json::Value& payload ); - bool updateUniform( const std::string& name ); - bool updateUniform( const std::string& name, const ext::opengl::userdata_t& ); - bool updateUniform( const std::string& name, const ext::json::Value& payload ); + Buffer* getUniformBuffer( const uf::stl::string& name ); + ext::opengl::userdata_t& getUniform( const uf::stl::string& name ); + uf::Serializer getUniformJson( const uf::stl::string& name, bool cache = true ); + ext::opengl::userdata_t getUniformUserdata( const uf::stl::string& name, const ext::json::Value& payload ); + bool updateUniform( const uf::stl::string& name ); + bool updateUniform( const uf::stl::string& name, const ext::opengl::userdata_t& ); + bool updateUniform( const uf::stl::string& name, const ext::json::Value& payload ); - bool hasStorage( const std::string& name ); - Buffer* getStorageBuffer( const std::string& name ); - uf::Serializer getStorageJson( const std::string& name, bool cache = true ); - ext::opengl::userdata_t getStorageUserdata( const std::string& name, const ext::json::Value& payload ); + bool hasStorage( const uf::stl::string& name ); + Buffer* getStorageBuffer( const uf::stl::string& name ); + uf::Serializer getStorageJson( const uf::stl::string& name, bool cache = true ); + ext::opengl::userdata_t getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ); #if UF_USE_OPENGL_FIXED_FUNCTION - static void bind( const std::string& name, const module_t& module ); + static void bind( const uf::stl::string& name, const module_t& module ); void execute( const Graphic& graphic, void* = NULL ); #endif }; diff --git a/engine/inc/uf/ext/opengl/texture.h b/engine/inc/uf/ext/opengl/texture.h index e6c69d9c..8d9540b0 100644 --- a/engine/inc/uf/ext/opengl/texture.h +++ b/engine/inc/uf/ext/opengl/texture.h @@ -76,11 +76,11 @@ namespace ext { void destroy(); bool generated() const; void loadFromFile( - const std::string& filename, + const uf::stl::string& filename, enums::Format::type_t format = enums::Format::R8G8B8A8_UNORM ); void loadFromFile( - const std::string& filename, + const uf::stl::string& filename, Device& device, enums::Format::type_t format = enums::Format::R8G8B8A8_UNORM ); diff --git a/engine/inc/uf/ext/openvr/openvr.h b/engine/inc/uf/ext/openvr/openvr.h index 5f6bf9fa..2e6f5a9e 100644 --- a/engine/inc/uf/ext/openvr/openvr.h +++ b/engine/inc/uf/ext/openvr/openvr.h @@ -25,11 +25,11 @@ namespace vr { namespace ext { namespace openvr { struct Driver { - std::string name; - std::string serial; - std::string manifest; + uf::stl::string name; + uf::stl::string serial; + uf::stl::string manifest; vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount]; - std::string types[vr::k_unMaxTrackedDeviceCount]; + uf::stl::string types[vr::k_unMaxTrackedDeviceCount]; vr::IVRRenderModels* renderModels; }; extern UF_API Driver driver; @@ -61,7 +61,7 @@ namespace ext { pod::Matrix4t<> UF_API hmdViewMatrix( vr::Hmd_Eye eye, const pod::Matrix4f& = uf::matrix::identity() ); pod::Matrix4t<> UF_API hmdProjectionMatrix( vr::Hmd_Eye, float = 0.1f, float = 1024.0f ); - uf::Serializer UF_API controllerState( vr::Controller_Hand, const std::string& = "" ); + uf::Serializer UF_API controllerState( vr::Controller_Hand, const uf::stl::string& = "" ); pod::Vector3f UF_API controllerPosition( vr::Controller_Hand, bool = false ); pod::Quaternion<> UF_API controllerQuaternion( vr::Controller_Hand, bool = false ); pod::Matrix4t<> UF_API controllerTranslationMatrix( vr::Controller_Hand, bool = false ); @@ -70,8 +70,8 @@ namespace ext { pod::Matrix4t<> UF_API controllerMatrix( vr::Controller_Hand, bool = false ); bool UF_API controllerActive( vr::Controller_Hand ); - bool UF_API requestRenderModel( const std::string& ); - uf::Graphic& UF_API getRenderModel( const std::string& ); + bool UF_API requestRenderModel( const uf::stl::string& ); + uf::Graphic& UF_API getRenderModel( const uf::stl::string& ); uf::Graphic& UF_API controllerRenderModel( vr::Controller_Hand ); void UF_API resetPosition(); diff --git a/engine/inc/uf/ext/ultralight/ultralight.h b/engine/inc/uf/ext/ultralight/ultralight.h index d6d9e3da..df9cbf46 100644 --- a/engine/inc/uf/ext/ultralight/ultralight.h +++ b/engine/inc/uf/ext/ultralight/ultralight.h @@ -3,8 +3,8 @@ #include #if UF_USE_ULTRALIGHT -#include -#include +#include +#include #include #include #include @@ -16,17 +16,17 @@ namespace pod { size_t uid = 0; ULView view; bool pending; - std::string html; + uf::stl::string html; pod::Vector2ui size; struct { - std::string load = ""; + uf::stl::string load = ""; } callbacks; }; } namespace ext { namespace ultralight { - // extern UF_API std::string resourcesDir; + // extern UF_API uf::stl::string resourcesDir; extern UF_API uint8_t log; extern UF_API double scale; @@ -35,12 +35,12 @@ namespace ext { void UF_API render(); void UF_API terminate(); - pod::HTML UF_API create( const std::string&, const pod::Vector2ui& ); - pod::HTML& UF_API create( pod::HTML&, const std::string&, const pod::Vector2ui& ); + pod::HTML UF_API create( const uf::stl::string&, const pod::Vector2ui& ); + pod::HTML& UF_API create( pod::HTML&, const uf::stl::string&, const pod::Vector2ui& ); void UF_API destroy( pod::HTML& ); - void UF_API on( pod::HTML&, const std::string&, const std::string& ); + void UF_API on( pod::HTML&, const uf::stl::string&, const uf::stl::string& ); void UF_API resize( pod::HTML&, const pod::Vector2ui& ); - void UF_API input( pod::HTML&, const std::string& ); + void UF_API input( pod::HTML&, const uf::stl::string& ); uf::Image UF_API capture( pod::HTML& ); } } diff --git a/engine/inc/uf/ext/vulkan/buffer.h b/engine/inc/uf/ext/vulkan/buffer.h index 74e28826..7f7bcb71 100644 --- a/engine/inc/uf/ext/vulkan/buffer.h +++ b/engine/inc/uf/ext/vulkan/buffer.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace ext { namespace vulkan { @@ -60,7 +60,7 @@ namespace ext { void aliasBuffer( const Buffer& ); }; struct UF_API Buffers { - std::vector buffers; + uf::stl::vector buffers; Device* device; // ~Buffers(); diff --git a/engine/inc/uf/ext/vulkan/device.h b/engine/inc/uf/ext/vulkan/device.h index 81bf2de7..5ff53102 100644 --- a/engine/inc/uf/ext/vulkan/device.h +++ b/engine/inc/uf/ext/vulkan/device.h @@ -15,9 +15,9 @@ namespace ext { VkPhysicalDevice physicalDevice; VkDevice logicalDevice; struct { - // std::unordered_map graphics; - // std::unordered_map compute; - // std::unordered_map transfer; + // uf::stl::unordered_map graphics; + // uf::stl::unordered_map compute; + // uf::stl::unordered_map transfer; uf::ThreadUnique graphics; uf::ThreadUnique compute; uf::ThreadUnique transfer; @@ -34,23 +34,23 @@ namespace ext { VkPhysicalDeviceMemoryProperties2 memoryProperties2; struct { - std::vector instance; - std::vector device; + uf::stl::vector instance; + uf::stl::vector device; } extensionProperties; struct { - std::vector instance; - std::vector device; + uf::stl::vector instance; + uf::stl::vector device; } supportedExtensions; VkPipelineCache pipelineCache; - std::vector queueFamilyProperties; + uf::stl::vector queueFamilyProperties; struct { - // std::unordered_map graphics; - // std::unordered_map present; - // std::unordered_map compute; - // std::unordered_map transfer; + // uf::stl::unordered_map graphics; + // uf::stl::unordered_map present; + // uf::stl::unordered_map compute; + // uf::stl::unordered_map transfer; uf::ThreadUnique graphics; uf::ThreadUnique present; uf::ThreadUnique compute; diff --git a/engine/inc/uf/ext/vulkan/graphic.h b/engine/inc/uf/ext/vulkan/graphic.h index 37fd2ce7..f6595996 100644 --- a/engine/inc/uf/ext/vulkan/graphic.h +++ b/engine/inc/uf/ext/vulkan/graphic.h @@ -26,7 +26,7 @@ namespace ext { struct { uf::Serializer json; - std::string type = ""; + uf::stl::string type = ""; bool process = true; } metadata; @@ -37,29 +37,29 @@ namespace ext { void record( Graphic& graphic, VkCommandBuffer, size_t = 0, size_t = 0 ); void destroy(); - std::vector getShaders( std::vector& ); + uf::stl::vector getShaders( uf::stl::vector& ); }; struct UF_API Material { bool aliased = false; Device* device; - std::vector samplers; - std::vector textures; - std::vector shaders; + uf::stl::vector samplers; + uf::stl::vector textures; + uf::stl::vector shaders; struct Metadata { uf::Serializer json; - std::unordered_map shaders; + uf::stl::unordered_map shaders; } metadata; void initialize( Device& device ); void destroy(); - void attachShader( const std::string&, VkShaderStageFlagBits, const std::string& pipeline = "" ); - void initializeShaders( const std::vector>&, const std::string& pipeline = "" ); + void attachShader( const uf::stl::string&, VkShaderStageFlagBits, const uf::stl::string& pipeline = "" ); + void initializeShaders( const uf::stl::vector>&, const uf::stl::string& pipeline = "" ); - bool hasShader( const std::string& type, const std::string& pipeline = "" ); - Shader& getShader( const std::string& type, const std::string& pipeline = "" ); + bool hasShader( const uf::stl::string& type, const uf::stl::string& pipeline = "" ); + Shader& getShader( const uf::stl::string& type, const uf::stl::string& pipeline = "" ); bool validate(); }; @@ -69,14 +69,14 @@ namespace ext { bool initialized = false; bool process = true; Material material; - std::unordered_map pipelines; + uf::stl::unordered_map pipelines; struct { - std::unordered_map buffers; + uf::stl::unordered_map buffers; } metadata; ~Graphic(); - void initialize( const std::string& = "" ); + void initialize( const uf::stl::string& = "" ); void destroy(); template @@ -93,10 +93,10 @@ namespace ext { void record( VkCommandBuffer commandBuffer, size_t pass = 0, size_t draw = 0 ); void record( VkCommandBuffer commandBuffer, GraphicDescriptor& descriptor, size_t pass = 0, size_t draw = 0 ); - bool hasStorage( const std::string& name ); - Buffer* getStorageBuffer( const std::string& name ); - uf::Serializer getStorageJson( const std::string& name, bool cache = true ); - ext::vulkan::userdata_t getStorageUserdata( const std::string& name, const ext::json::Value& payload ); + bool hasStorage( const uf::stl::string& name ); + Buffer* getStorageBuffer( const uf::stl::string& name ); + uf::Serializer getStorageJson( const uf::stl::string& name, bool cache = true ); + ext::vulkan::userdata_t getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ); }; } } diff --git a/engine/inc/uf/ext/vulkan/initializers.h b/engine/inc/uf/ext/vulkan/initializers.h index 74150c32..2005b28b 100644 --- a/engine/inc/uf/ext/vulkan/initializers.h +++ b/engine/inc/uf/ext/vulkan/initializers.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace ext { namespace vulkan { @@ -194,7 +194,7 @@ namespace ext { } inline VkDescriptorPoolCreateInfo descriptorPoolCreateInfo( - const std::vector& poolSizes, + const uf::stl::vector& poolSizes, uint32_t maxSets) { VkDescriptorPoolCreateInfo descriptorPoolInfo{}; @@ -241,7 +241,7 @@ namespace ext { } inline VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo( - const std::vector& bindings) + const uf::stl::vector& bindings) { VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo{}; descriptorSetLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; @@ -462,7 +462,7 @@ namespace ext { } inline VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( - const std::vector& pDynamicStates, + const uf::stl::vector& pDynamicStates, VkPipelineDynamicStateCreateFlags flags = 0) { VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo{}; diff --git a/engine/inc/uf/ext/vulkan/rendermode.h b/engine/inc/uf/ext/vulkan/rendermode.h index b8c70839..2ba23a3a 100644 --- a/engine/inc/uf/ext/vulkan/rendermode.h +++ b/engine/inc/uf/ext/vulkan/rendermode.h @@ -17,10 +17,10 @@ namespace ext { struct { uf::Serializer json; - std::string name = ""; - std::string type = ""; - std::string target = ""; - std::vector outputs; + uf::stl::string name = ""; + uf::stl::string type = ""; + uf::stl::string target = ""; + uf::stl::vector outputs; uint8_t subpasses = 1; uint8_t samples = 1; @@ -36,22 +36,22 @@ namespace ext { RenderTarget renderTarget; VkSemaphore renderCompleteSemaphore; - std::vector fences; + uf::stl::vector fences; - typedef std::vector commands_container_t; + typedef uf::stl::vector commands_container_t; std::thread::id mostRecentCommandPoolId; uf::ThreadUnique commands; virtual ~RenderMode(); // RAII - virtual const std::string getName() const; - virtual const std::string getType() const; + virtual const uf::stl::string getName() const; + virtual const uf::stl::string getType() const; virtual RenderTarget& getRenderTarget(size_t = 0); virtual const RenderTarget& getRenderTarget(size_t = 0) const; virtual const size_t blitters() const; virtual ext::vulkan::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual uf::Image screenshot(size_t = 0); @@ -62,9 +62,9 @@ namespace ext { virtual void initialize( Device& device ); virtual void createCommandBuffers(); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void bindPipelines(); - virtual void bindPipelines( const std::vector& graphics ); + virtual void bindPipelines( const uf::stl::vector& graphics ); virtual void tick(); virtual void render(); virtual void destroy(); diff --git a/engine/inc/uf/ext/vulkan/rendermodes/base.h b/engine/inc/uf/ext/vulkan/rendermodes/base.h index f39c4978..ce3274a9 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/base.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/base.h @@ -7,10 +7,10 @@ namespace ext { struct UF_API BaseRenderMode : RenderMode { // virtual ~RenderMode(); // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual void initialize( Device& device ); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void tick(); virtual void render(); virtual void destroy(); diff --git a/engine/inc/uf/ext/vulkan/rendermodes/compute.h b/engine/inc/uf/ext/vulkan/rendermodes/compute.h index 6736116e..2b27bb72 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/compute.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/compute.h @@ -10,10 +10,10 @@ namespace ext { pod::Vector2ui dispatchSize = { 32, 32 }; // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual const size_t blitters() const; virtual ext::vulkan::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual void createCommandBuffers(); virtual void initialize( Device& device ); diff --git a/engine/inc/uf/ext/vulkan/rendermodes/deferred.h b/engine/inc/uf/ext/vulkan/rendermodes/deferred.h index 9aed403f..449eb76b 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/deferred.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/deferred.h @@ -9,14 +9,14 @@ namespace ext { ext::vulkan::Graphic blitter; // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual const size_t blitters() const; virtual ext::vulkan::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual GraphicDescriptor bindGraphicDescriptor( const GraphicDescriptor&, size_t = 0 ); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void initialize( Device& device ); virtual void tick(); virtual void destroy(); diff --git a/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h b/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h index b6f46bf0..d6bf18df 100644 --- a/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h +++ b/engine/inc/uf/ext/vulkan/rendermodes/rendertarget.h @@ -9,11 +9,11 @@ namespace ext { ext::vulkan::Graphic blitter; typedef std::function callback_t; - std::unordered_map commandBufferCallbacks; + uf::stl::unordered_map commandBufferCallbacks; // - const std::string getTarget() const; - void setTarget( const std::string& ); + const uf::stl::string getTarget() const; + void setTarget( const uf::stl::string& ); void bindCallback( int32_t, const callback_t& ); @@ -21,14 +21,14 @@ namespace ext { constexpr static int32_t CALLBACK_END = -2; // RAII - virtual const std::string getType() const; + virtual const uf::stl::string getType() const; virtual const size_t blitters() const; virtual ext::vulkan::Graphic* getBlitter(size_t = 0); - virtual std::vector getBlitters(); + virtual uf::stl::vector getBlitters(); virtual GraphicDescriptor bindGraphicDescriptor( const GraphicDescriptor&, size_t = 0 ); - virtual void createCommandBuffers( const std::vector& graphics ); + virtual void createCommandBuffers( const uf::stl::vector& graphics ); virtual void initialize( Device& device ); virtual void tick(); virtual void destroy(); diff --git a/engine/inc/uf/ext/vulkan/rendertarget.h b/engine/inc/uf/ext/vulkan/rendertarget.h index 8279225e..8f2af904 100644 --- a/engine/inc/uf/ext/vulkan/rendertarget.h +++ b/engine/inc/uf/ext/vulkan/rendertarget.h @@ -19,12 +19,12 @@ namespace ext { VkImage image; VkDeviceMemory mem; VkImageView view; - std::vector views; + uf::stl::vector views; VmaAllocation allocation; VmaAllocationInfo allocationInfo; VkPipelineColorBlendAttachmentState blendState; }; - std::vector attachments; + uf::stl::vector attachments; struct Subpass { VkPipelineStageFlags stage; @@ -32,24 +32,24 @@ namespace ext { uint8_t layer; bool autoBuildPipeline; - std::vector colors; - std::vector inputs; - std::vector resolves; + uf::stl::vector colors; + uf::stl::vector inputs; + uf::stl::vector resolves; VkAttachmentReference depth; }; - std::vector passes; + uf::stl::vector passes; bool initialized = false; Device* device = VK_NULL_HANDLE; VkRenderPass renderPass = VK_NULL_HANDLE; - std::vector framebuffers; + uf::stl::vector framebuffers; uint32_t width = 0; uint32_t height = 0; uint8_t views = 1; // RAII void initialize( Device& device ); void destroy(); - void addPass( VkPipelineStageFlags, VkAccessFlags, const std::vector&, const std::vector&, const std::vector&, size_t, size_t = 0, bool = true ); + void addPass( VkPipelineStageFlags, VkAccessFlags, const uf::stl::vector&, const uf::stl::vector&, const uf::stl::vector&, size_t, size_t = 0, bool = true ); size_t attach( const Attachment::Descriptor& descriptor, Attachment* attachment = NULL ); }; } diff --git a/engine/inc/uf/ext/vulkan/shader.h b/engine/inc/uf/ext/vulkan/shader.h index a8bd7c26..c0d2a031 100644 --- a/engine/inc/uf/ext/vulkan/shader.h +++ b/engine/inc/uf/ext/vulkan/shader.h @@ -24,75 +24,75 @@ namespace ext { bool aliased = false; Device* device = NULL; - std::string filename = ""; + uf::stl::string filename = ""; VkShaderModule module = VK_NULL_HANDLE; VkPipelineShaderStageCreateInfo descriptor; - std::vector descriptorSetLayoutBindings; - std::vector specializationMapEntries; + uf::stl::vector descriptorSetLayoutBindings; + uf::stl::vector specializationMapEntries; VkSpecializationInfo specializationInfo; struct Metadata { uf::Serializer json; - std::string pipeline = ""; - std::string type = ""; + uf::stl::string pipeline = ""; + uf::stl::string type = ""; struct Definition { struct Texture { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; ext::vulkan::enums::Image::viewType_t type{}; }; struct Uniform { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; }; struct Storage { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; }; struct PushConstant { - std::string name = ""; + uf::stl::string name = ""; uint32_t index = 0; uint32_t binding = 0; uint32_t size = 0; }; - std::unordered_map textures; - std::unordered_map uniforms; - std::unordered_map storage; - std::unordered_map pushConstants; + uf::stl::unordered_map textures; + uf::stl::unordered_map uniforms; + uf::stl::unordered_map storage; + uf::stl::unordered_map pushConstants; } definitions; } metadata; ext::vulkan::userdata_t specializationConstants; - std::vector pushConstants; - std::vector uniforms; + uf::stl::vector pushConstants; + uf::stl::vector uniforms; // ~Shader(); - void initialize( Device& device, const std::string&, VkShaderStageFlagBits ); + void initialize( Device& device, const uf::stl::string&, VkShaderStageFlagBits ); void destroy(); bool validate(); - bool hasUniform( const std::string& name ); + bool hasUniform( const uf::stl::string& name ); - Buffer* getUniformBuffer( const std::string& name ); - ext::vulkan::userdata_t& getUniform( const std::string& name ); - uf::Serializer getUniformJson( const std::string& name, bool cache = true ); - ext::vulkan::userdata_t getUniformUserdata( const std::string& name, const ext::json::Value& payload ); - bool updateUniform( const std::string& name ); - bool updateUniform( const std::string& name, const ext::vulkan::userdata_t& ); - bool updateUniform( const std::string& name, const ext::json::Value& payload ); + Buffer* getUniformBuffer( const uf::stl::string& name ); + ext::vulkan::userdata_t& getUniform( const uf::stl::string& name ); + uf::Serializer getUniformJson( const uf::stl::string& name, bool cache = true ); + ext::vulkan::userdata_t getUniformUserdata( const uf::stl::string& name, const ext::json::Value& payload ); + bool updateUniform( const uf::stl::string& name ); + bool updateUniform( const uf::stl::string& name, const ext::vulkan::userdata_t& ); + bool updateUniform( const uf::stl::string& name, const ext::json::Value& payload ); - bool hasStorage( const std::string& name ); - Buffer* getStorageBuffer( const std::string& name ); - uf::Serializer getStorageJson( const std::string& name, bool cache = true ); - ext::vulkan::userdata_t getStorageUserdata( const std::string& name, const ext::json::Value& payload ); + bool hasStorage( const uf::stl::string& name ); + Buffer* getStorageBuffer( const uf::stl::string& name ); + uf::Serializer getStorageJson( const uf::stl::string& name, bool cache = true ); + ext::vulkan::userdata_t getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ); }; } } \ No newline at end of file diff --git a/engine/inc/uf/ext/vulkan/texture.h b/engine/inc/uf/ext/vulkan/texture.h index 871d38ed..701a6181 100644 --- a/engine/inc/uf/ext/vulkan/texture.h +++ b/engine/inc/uf/ext/vulkan/texture.h @@ -39,7 +39,7 @@ namespace ext { void initialize( Device& device ); void destroy(); - static std::vector samplers; + static uf::stl::vector samplers; static ext::vulkan::Sampler retrieve( const Descriptor& info ); }; @@ -84,13 +84,13 @@ namespace ext { uint32_t mipLevels ); void loadFromFile( - const std::string& filename, + const uf::stl::string& filename, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM, VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT, VkImageLayout imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ); void loadFromFile( - const std::string& filename, + const uf::stl::string& filename, Device& device, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM, VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT, diff --git a/engine/inc/uf/ext/vulkan/vulkan.h b/engine/inc/uf/ext/vulkan/vulkan.h index e3be6fe5..7e2d0f49 100644 --- a/engine/inc/uf/ext/vulkan/vulkan.h +++ b/engine/inc/uf/ext/vulkan/vulkan.h @@ -30,7 +30,7 @@ namespace ext { void* pUserData ); - std::string errorString( VkResult result ); + uf::stl::string errorString( VkResult result ); VkSampleCountFlagBits sampleCount( uint8_t ); void* alignedAlloc( size_t size, size_t alignment ); void alignedFree(void* data); @@ -45,10 +45,10 @@ namespace ext { extern UF_API size_t viewCount; constexpr size_t maxViews = 6; - extern UF_API std::vector validationFilters; - extern UF_API std::vector requestedDeviceFeatures; - extern UF_API std::vector requestedDeviceExtensions; - extern UF_API std::vector requestedInstanceExtensions; + extern UF_API uf::stl::vector validationFilters; + extern UF_API uf::stl::vector requestedDeviceFeatures; + extern UF_API uf::stl::vector requestedDeviceExtensions; + extern UF_API uf::stl::vector requestedInstanceExtensions; extern UF_API VkFilter swapchainUpscaleFilter; @@ -58,7 +58,7 @@ namespace ext { extern UF_API bool individualPipelines; extern UF_API bool multithreadedCommandRecording; extern UF_API bool multithreadedCommandRendering; - extern UF_API std::string deferredMode; + extern UF_API uf::stl::string deferredMode; extern UF_API bool deferredReconstructPosition; extern UF_API bool deferredAliasOutputToSwapchain; extern UF_API bool multiview; @@ -89,15 +89,15 @@ namespace ext { extern UF_API std::mutex mutex; extern UF_API RenderMode* currentRenderMode; - extern UF_API std::vector renderModes; - extern UF_API std::unordered_map renderModesMap; - extern UF_API std::vector scenes; + extern UF_API uf::stl::vector renderModes; + extern UF_API uf::stl::unordered_map renderModesMap; + extern UF_API uf::stl::vector scenes; - bool UF_API hasRenderMode( const std::string&, bool = true ); - RenderMode& UF_API addRenderMode( RenderMode*, const std::string& = "" ); - RenderMode& UF_API getRenderMode( const std::string&, bool = true ); - std::vector UF_API getRenderModes( const std::string&, bool = true ); - std::vector UF_API getRenderModes( const std::vector&, bool = true ); + bool UF_API hasRenderMode( const uf::stl::string&, bool = true ); + RenderMode& UF_API addRenderMode( RenderMode*, const uf::stl::string& = "" ); + RenderMode& UF_API getRenderMode( const uf::stl::string&, bool = true ); + uf::stl::vector UF_API getRenderModes( const uf::stl::string&, bool = true ); + uf::stl::vector UF_API getRenderModes( const uf::stl::vector&, bool = true ); void UF_API removeRenderMode( RenderMode*, bool = true ); void UF_API initialize( /*uint8_t = 0*/ ); @@ -105,7 +105,7 @@ namespace ext { void UF_API render(); void UF_API destroy(); void UF_API synchronize( uint8_t = 0b11 ); - std::string UF_API allocatorStats(); - ext::vulkan::enums::Format::type_t UF_API formatFromString( const std::string& ); + uf::stl::string UF_API allocatorStats(); + ext::vulkan::enums::Format::type_t UF_API formatFromString( const uf::stl::string& ); } } \ No newline at end of file diff --git a/engine/inc/uf/ext/zlib/zlib.h b/engine/inc/uf/ext/zlib/zlib.h index 4ce2ecba..347fb07d 100644 --- a/engine/inc/uf/ext/zlib/zlib.h +++ b/engine/inc/uf/ext/zlib/zlib.h @@ -3,30 +3,31 @@ #include #if UF_USE_ZLIB -#include +#include +#include namespace ext { namespace zlib { extern UF_API size_t bufferSize; /* - std::vector UF_API compress( const void*, size_t ); - std::vector UF_API decompress( const void*, size_t ); + uf::stl::vector UF_API compress( const void*, size_t ); + uf::stl::vector UF_API decompress( const void*, size_t ); template - std::vector UF_API compress( const std::vector& data ) { + uf::stl::vector UF_API compress( const uf::stl::vector& data ) { auto compressed = ext::zlib::compress( data.data(), data.size() ); - std::vector vector( compressed.size() / sizeof(T) ); + uf::stl::vector vector( compressed.size() / sizeof(T) ); memcpy( vector.data(), compressed.data(), compressed.size() ); } template - std::vector UF_API decompress( const std::vector& data ) { + uf::stl::vector UF_API decompress( const uf::stl::vector& data ) { auto compressed = ext::zlib::decompress( data.data(), data.size() ); - std::vector vector( compressed.size() / sizeof(T) ); + uf::stl::vector vector( compressed.size() / sizeof(T) ); memcpy( vector.data(), compressed.data(), compressed.size() ); } */ - std::vector UF_API decompressFromFile( const std::string& ); - size_t UF_API compressToFile( const std::string&, const void*, size_t ); + uf::stl::vector UF_API decompressFromFile( const uf::stl::string& ); + size_t UF_API compressToFile( const uf::stl::string&, const void*, size_t ); } } diff --git a/engine/inc/uf/helpers.inl b/engine/inc/uf/helpers.inl new file mode 100644 index 00000000..e69de29b diff --git a/engine/inc/uf/macros.h b/engine/inc/uf/macros.h index cc5c0382..375d5308 100644 --- a/engine/inc/uf/macros.h +++ b/engine/inc/uf/macros.h @@ -6,12 +6,13 @@ #define TIMER(x, ...) auto TOKEN_PASTE(TIMER, __LINE__) = []( double every = 1 ) {\ static uf::Timer timer(false);\ if ( !timer.running() ) {\ - timer.start(uf::Time(-x, uf::Time::seconds));\ + timer.start(uf::Time(-x * 1000, uf::Time::milliseconds));\ }\ double time = 0;\ if ( (time = timer.elapsed().asDouble()) >= every ) {\ timer.reset();\ }\ + static bool first = true; if ( first ) { first = false; return every; }\ return time;\ };\ double time = 0;\ @@ -39,9 +40,9 @@ #define UF_EXCEPTION(X) { UF_MSG_ERROR(X); } #else #define UF_EXCEPTION(X) {\ - std::stringstream str;\ + uf::stl::stringstream str;\ str << X;\ - std::string Y = str.str();\ + uf::stl::string Y = str.str();\ UF_MSG_ERROR(Y);\ throw std::runtime_error(Y);\ } diff --git a/engine/inc/uf/spec/controller/dreamcast.h b/engine/inc/uf/spec/controller/dreamcast.h index 1a1f30e3..8b455d4a 100644 --- a/engine/inc/uf/spec/controller/dreamcast.h +++ b/engine/inc/uf/spec/controller/dreamcast.h @@ -13,8 +13,8 @@ namespace spec { void UF_API terminate(); bool UF_API connected( size_t = 0 ); - bool UF_API pressed( const std::string&, size_t = 0 ); - float UF_API analog( const std::string&, size_t = 0 ); + bool UF_API pressed( const uf::stl::string&, size_t = 0 ); + float UF_API analog( const uf::stl::string&, size_t = 0 ); } } namespace controller = dreamcast::controller; diff --git a/engine/inc/uf/spec/controller/universal.h b/engine/inc/uf/spec/controller/universal.h index 024cec32..24c4e08e 100644 --- a/engine/inc/uf/spec/controller/universal.h +++ b/engine/inc/uf/spec/controller/universal.h @@ -1,7 +1,7 @@ #pragma once #include - +#include namespace spec { namespace uni { namespace controller { @@ -10,8 +10,8 @@ namespace spec { void UF_API terminate(); bool UF_API connected( size_t = 0 ); - bool UF_API pressed( const std::string&, size_t = 0 ); - float UF_API analog( const std::string&, size_t = 0 ); + bool UF_API pressed( const uf::stl::string&, size_t = 0 ); + float UF_API analog( const uf::stl::string&, size_t = 0 ); }; }; } \ No newline at end of file diff --git a/engine/inc/uf/spec/controller/windows.h b/engine/inc/uf/spec/controller/windows.h index b0a85336..d3bc352a 100644 --- a/engine/inc/uf/spec/controller/windows.h +++ b/engine/inc/uf/spec/controller/windows.h @@ -13,8 +13,8 @@ namespace spec { void UF_API terminate(); bool UF_API connected( size_t = 0 ); - bool UF_API pressed( const std::string&, size_t = 0 ); - float UF_API analog( const std::string&, size_t = 0 ); + bool UF_API pressed( const uf::stl::string&, size_t = 0 ); + float UF_API analog( const uf::stl::string&, size_t = 0 ); } } namespace controller = win32::controller; diff --git a/engine/inc/uf/spec/window/dreamcast.h b/engine/inc/uf/spec/window/dreamcast.h index 0607d1d1..a2c9ec95 100644 --- a/engine/inc/uf/spec/window/dreamcast.h +++ b/engine/inc/uf/spec/window/dreamcast.h @@ -54,7 +54,7 @@ namespace spec { /*virtual*/ bool UF_API hasFocus() const; // Update /*virtual*/ void UF_API processEvents(); - static /*virtual*/ bool UF_API isKeyPressed(const std::string&); + static /*virtual*/ bool UF_API isKeyPressed(const uf::stl::string&); bool UF_API pollEvents( bool block = false ); // Win32 specific functions void UF_API registerWindowClass(); diff --git a/engine/inc/uf/spec/window/universal.h b/engine/inc/uf/spec/window/universal.h index c58abdbe..29361da4 100644 --- a/engine/inc/uf/spec/window/universal.h +++ b/engine/inc/uf/spec/window/universal.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace spec { @@ -17,7 +17,7 @@ namespace spec { typedef pod::Vector2i vector_t; struct Event { - std::string name; + uf::stl::string name; pod::Hook::userdata_t payload; }; protected: @@ -49,7 +49,7 @@ namespace spec { // Update void processEvents();/* = 0;*/ - void pushEvent( const uf::Hooks::name_t& name, const std::string& payload ); + void pushEvent( const uf::Hooks::name_t& name, const uf::stl::string& payload ); void pushEvent( const uf::Hooks::name_t& name, const ext::json::Value& payload ); void pushEvent( const uf::Hooks::name_t& name, const uf::Serializer& payload ); void pushEvent( const uf::Hooks::name_t& name, const uf::Hooks::argument_t& payload ); @@ -57,7 +57,7 @@ namespace spec { template void pushEvent( const uf::Hooks::name_t& name, const T& payload ); bool pollEvents( bool block = false ); - static bool isKeyPressed( const std::string& ); + static bool isKeyPressed( const uf::stl::string& ); }; } } diff --git a/engine/inc/uf/spec/window/windows.h b/engine/inc/uf/spec/window/windows.h index 5a812101..b8523e27 100644 --- a/engine/inc/uf/spec/window/windows.h +++ b/engine/inc/uf/spec/window/windows.h @@ -61,7 +61,7 @@ namespace spec { /*virtual*/ bool UF_API_CALL hasFocus() const; // Update /*virtual*/ void UF_API_CALL processEvents(); - static /*virtual*/ bool UF_API_CALL isKeyPressed(const std::string&); + static /*virtual*/ bool UF_API_CALL isKeyPressed(const uf::stl::string&); bool UF_API_CALL pollEvents( bool block = false ); // Win32 specific functions void UF_API_CALL registerWindowClass(); @@ -72,10 +72,10 @@ namespace spec { static pod::Vector2ui UF_API_CALL getResolution(); void UF_API_CALL switchToFullscreen( bool borderless = false ); #if defined(UF_USE_VULKAN) && UF_USE_VULKAN == 1 - std::vector UF_API_CALL getExtensions( bool validationEnabled ); + uf::stl::vector UF_API_CALL getExtensions( bool validationEnabled ); void UF_API_CALL createSurface( VkInstance instance, VkSurfaceKHR& surface ); #endif - static std::string UF_API_CALL getKey(WPARAM key, LPARAM flags); + static uf::stl::string UF_API_CALL getKey(WPARAM key, LPARAM flags); }; } typedef spec::win32::Window Window; diff --git a/engine/inc/uf/utils/audio/audio.h b/engine/inc/uf/utils/audio/audio.h index ea8e6732..f291b264 100644 --- a/engine/inc/uf/utils/audio/audio.h +++ b/engine/inc/uf/utils/audio/audio.h @@ -14,8 +14,8 @@ typedef float ALfloat; #endif -#include -#include +#include +#include #include #include @@ -39,10 +39,10 @@ namespace uf { bool initialized() const; bool playing() const; - void open( const std::string& ); - void open( const std::string&, bool ); - void load( const std::string& ); - void stream( const std::string& ); + void open( const uf::stl::string& ); + void open( const uf::stl::string&, bool ); + void load( const uf::stl::string& ); + void stream( const uf::stl::string& ); void update(); void destroy(); @@ -72,7 +72,7 @@ namespace uf { float getVolume() const; void setVolume( float ); - const std::string& getFilename() const; + const uf::stl::string& getFilename() const; float getDuration() const; }; namespace audio { diff --git a/engine/inc/uf/utils/audio/emitter.h b/engine/inc/uf/utils/audio/emitter.h index 07c84119..8b76df95 100644 --- a/engine/inc/uf/utils/audio/emitter.h +++ b/engine/inc/uf/utils/audio/emitter.h @@ -4,21 +4,21 @@ namespace uf { class UF_API SoundEmitter { public: - typedef std::vector container_t; + typedef uf::stl::vector container_t; protected: uf::SoundEmitter::container_t m_container; public: ~SoundEmitter(); - bool has( const std::string& ) const; + bool has( const uf::stl::string& ) const; uf::Audio& add(); - uf::Audio& add( const std::string& ); - uf::Audio& load( const std::string& ); - uf::Audio& stream( const std::string& ); + uf::Audio& add( const uf::stl::string& ); + uf::Audio& load( const uf::stl::string& ); + uf::Audio& stream( const uf::stl::string& ); - uf::Audio& get( const std::string& ); - const uf::Audio& get( const std::string& ) const; + uf::Audio& get( const uf::stl::string& ); + const uf::Audio& get( const uf::stl::string& ) const; container_t& get(); const container_t& get() const; @@ -28,20 +28,20 @@ namespace uf { }; class UF_API MappedSoundEmitter { public: - typedef std::unordered_map container_t; + typedef uf::stl::unordered_map container_t; protected: uf::MappedSoundEmitter::container_t m_container; public: ~MappedSoundEmitter(); - bool has( const std::string& ) const; + bool has( const uf::stl::string& ) const; - uf::Audio& add( const std::string& ); - uf::Audio& load( const std::string& ); - uf::Audio& stream( const std::string& ); + uf::Audio& add( const uf::stl::string& ); + uf::Audio& load( const uf::stl::string& ); + uf::Audio& stream( const uf::stl::string& ); - uf::Audio& get( const std::string& ); - const uf::Audio& get( const std::string& ) const; + uf::Audio& get( const uf::stl::string& ); + const uf::Audio& get( const uf::stl::string& ) const; container_t& get(); const container_t& get() const; diff --git a/engine/inc/uf/utils/audio/metadata.h b/engine/inc/uf/utils/audio/metadata.h index 8902a3e9..86299392 100644 --- a/engine/inc/uf/utils/audio/metadata.h +++ b/engine/inc/uf/utils/audio/metadata.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -9,8 +9,8 @@ namespace uf { namespace audio { struct UF_API Metadata { - std::string filename = ""; - std::string extension = ""; + uf::stl::string filename = ""; + uf::stl::string extension = ""; struct { std::ifstream* file = NULL; void* handle = NULL; diff --git a/engine/inc/uf/utils/component/component.h b/engine/inc/uf/utils/component/component.h index 5faefc43..d4d0bd2b 100644 --- a/engine/inc/uf/utils/component/component.h +++ b/engine/inc/uf/utils/component/component.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #define UF_COMPONENT_POINTERED_USERDATA 0 @@ -12,8 +12,8 @@ namespace pod { struct UF_API Component { typedef std::size_t id_t; - typedef std::unordered_map container_t; - // typedef std::unordered_map alias_t; + typedef uf::stl::unordered_map container_t; + // typedef uf::stl::unordered_map alias_t; pod::Component::id_t id; #if UF_COMPONENT_POINTERED_USERDATA diff --git a/engine/inc/uf/utils/graphic/descriptor.h b/engine/inc/uf/utils/graphic/descriptor.h index 224e1073..6a24ce85 100644 --- a/engine/inc/uf/utils/graphic/descriptor.h +++ b/engine/inc/uf/utils/graphic/descriptor.h @@ -22,7 +22,7 @@ namespace ext { size_t size = 0; // sizeof(Vertex::position::type_t) size_t components = 0; // Vertex::position::size ext::RENDERER::enums::Type::type_t type = 0; // ext::RENDERER::typeToEnum() - std::string name = ""; + uf::stl::string name = ""; }; } } @@ -36,7 +36,7 @@ namespace uf { void* pointer = NULL; size_t length = 0; } vertex, index; - std::vector descriptor; + uf::stl::vector descriptor; } attributes; void generateIndices(); @@ -51,13 +51,13 @@ namespace ext { namespace RENDERER { struct UF_API GraphicDescriptor { #if UF_GRAPHIC_DESCRIPTOR_USE_STRING - typedef std::string hash_t; + typedef uf::stl::string hash_t; #else typedef size_t hash_t; #endif - std::string renderMode = ""; - std::string pipeline = ""; + uf::stl::string renderMode = ""; + uf::stl::string pipeline = ""; uint32_t renderTarget = 0; uint32_t subpass = 0; @@ -106,5 +106,5 @@ namespace ext { }, #define UF_VERTEX_DESCRIPTOR( TYPE, ... )\ - std::vector TYPE::descriptor = { __VA_ARGS__ }; + uf::stl::vector TYPE::descriptor = { __VA_ARGS__ }; \ No newline at end of file diff --git a/engine/inc/uf/utils/graphic/mesh.h b/engine/inc/uf/utils/graphic/mesh.h index 782c1e17..6968b5b9 100644 --- a/engine/inc/uf/utils/graphic/mesh.h +++ b/engine/inc/uf/utils/graphic/mesh.h @@ -9,7 +9,7 @@ namespace pod { /*alignas(16)*/ pod::Vector3f normal; /*alignas(16)*/ pod::Vector4f color; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_3F2F3F32B { /*alignas(16)*/ pod::Vector3f position; @@ -17,14 +17,14 @@ namespace pod { /*alignas(16)*/ pod::Vector3f normal; /*alignas(16)*/ pod::Vector4t color; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_3F3F3F { /*alignas(16)*/ pod::Vector3f position; /*alignas(16)*/ pod::Vector3f uv; /*alignas(16)*/ pod::Vector3f normal; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_3F2F3F1UI { /*alignas(16)*/ pod::Vector3f position; @@ -32,31 +32,31 @@ namespace pod { /*alignas(16)*/ pod::Vector3f normal; /*alignas(4)*/ pod::Vector1ui id; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_3F2F3F { /*alignas(16)*/ pod::Vector3f position; /*alignas(8)*/ pod::Vector2f uv; /*alignas(16)*/ pod::Vector3f normal; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_3F2F { /*alignas(16)*/ pod::Vector3f position; /*alignas(8)*/ pod::Vector2f uv; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_2F2F { /*alignas(8)*/ pod::Vector2f position; /*alignas(8)*/ pod::Vector2f uv; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; struct /*UF_API*/ Vertex_3F { /*alignas(16)*/ pod::Vector3f position; - static UF_API std::vector descriptor; + static UF_API uf::stl::vector descriptor; }; } diff --git a/engine/inc/uf/utils/hook/hook.h b/engine/inc/uf/utils/hook/hook.h index dba118dd..1fc95c0d 100644 --- a/engine/inc/uf/utils/hook/hook.h +++ b/engine/inc/uf/utils/hook/hook.h @@ -4,10 +4,10 @@ #include // uf::Userdata -#include // std::string +#include // uf::stl::string #include // std::function -#include // std::vector -#include // std::unordered_map +#include // uf::vector +#include // uf::unordered_map #include #include @@ -36,12 +36,12 @@ namespace pod { namespace uf { class UF_API Hooks { public: - typedef std::vector hooks_t; - typedef std::unordered_map container_t; + typedef uf::stl::vector hooks_t; + typedef uf::stl::unordered_map container_t; - typedef std::string name_t; + typedef uf::stl::string name_t; typedef pod::Hook::userdata_t argument_t; - typedef std::vector return_t; + typedef uf::stl::vector return_t; protected: static size_t uids; uf::Hooks::container_t m_container; @@ -51,7 +51,7 @@ namespace uf { void removeHook( const name_t& name, size_t uid ); return_t call( const name_t& name, const argument_t& payload ); - return_t call( const name_t& name, const std::string& = "" ); + return_t call( const name_t& name, const uf::stl::string& = "" ); return_t call( const name_t& name, const ext::json::Value& ); return_t call( const name_t& name, const uf::Serializer& ); @@ -74,7 +74,7 @@ namespace uf { namespace uf { namespace HookHandler { namespace Readable { - typedef std::function function_t; + typedef std::function function_t; } } } diff --git a/engine/inc/uf/utils/http/http.h b/engine/inc/uf/utils/http/http.h index e21388b1..ddbe4fb6 100644 --- a/engine/inc/uf/utils/http/http.h +++ b/engine/inc/uf/utils/http/http.h @@ -1,17 +1,17 @@ #pragma once #include -#include +#include namespace uf { struct UF_API Http { - std::string header; - std::string response; + uf::stl::string header; + uf::stl::string response; char* effective; long code; double elapsed; }; namespace http { - uf::Http UF_API get( const std::string& ); + uf::Http UF_API get( const uf::stl::string& ); } } \ No newline at end of file diff --git a/engine/inc/uf/utils/image/atlas.h b/engine/inc/uf/utils/image/atlas.h index caeb192a..9dfe8e70 100644 --- a/engine/inc/uf/utils/image/atlas.h +++ b/engine/inc/uf/utils/image/atlas.h @@ -1,12 +1,12 @@ #pragma once #include -#include +#include namespace uf { class UF_API Atlas { public: - typedef std::string hash_t; + typedef uf::stl::string hash_t; struct Identifier { size_t index; hash_t hash; @@ -17,8 +17,8 @@ namespace uf { pod::Vector2ui size = {}; pod::Vector2ui coord = {}; }; - typedef std::vector images_t; - typedef std::unordered_map atlas_t; + typedef uf::stl::vector images_t; + typedef uf::stl::unordered_map atlas_t; protected: uf::Image m_atlas; atlas_t m_tiles; @@ -28,7 +28,7 @@ namespace uf { hash_t addImage( const uint8_t*, const pod::Vector2ui&, std::size_t, std::size_t, bool = false, bool = false ); void generate(float padding = 1); - void generate( const std::vector&, float padding = 1); + void generate( const uf::stl::vector&, float padding = 1); void clear(bool = true); bool generated() const; @@ -45,8 +45,8 @@ namespace uf { #if 0 class UF_API HashAtlas { public: - typedef std::string hash_t; - typedef std::unordered_map images_t; + typedef uf::stl::string hash_t; + typedef uf::stl::unordered_map images_t; struct Identifier { hash_t hash; @@ -66,7 +66,7 @@ namespace uf { void generate( const images_t&, float padding = 1); void clear(); bool has( const uf::Image& ) const; - bool has( const std::string& ) const; + bool has( const uf::stl::string& ) const; pod::Vector2f mapUv( const pod::Vector2f&, const hash_t& ); diff --git a/engine/inc/uf/utils/image/image.h b/engine/inc/uf/utils/image/image.h index 43d4c8e9..f4fd1d6b 100644 --- a/engine/inc/uf/utils/image/image.h +++ b/engine/inc/uf/utils/image/image.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include "pixel.h" @@ -11,9 +11,9 @@ namespace uf { public: typedef pod::Vector2ui vec2_t; typedef pod::PixelRgba8 pixel_t; - typedef std::vector container_t; + typedef uf::stl::vector container_t; protected: - std::string m_filename; + uf::stl::string m_filename; Image::container_t m_pixels; Image::vec2_t m_dimensions; std::size_t m_bpp; @@ -28,7 +28,7 @@ namespace uf { Image( Image::container_t&& move, const Image::vec2_t& size ); // Move from vector of pixels Image( const Image::container_t& copy, const Image::vec2_t& size ); // Copy from vector of pixels - bool open( const std::string& filename, bool = true ); // from file + bool open( const uf::stl::string& filename, bool = true ); // from file void open( const std::istream& stream ); // from stream void move( Image::container_t&& move, const Image::vec2_t& size ); // move from vector of pixels void copy( const Image::container_t& copy, const Image::vec2_t& size ); // copy from vector of pixels @@ -40,7 +40,7 @@ namespace uf { void loadFromBuffer( const Image::pixel_t::type_t* pointer, const pod::Vector2ui& size, std::size_t bpp, std::size_t channels, bool flip = false ); void loadFromBuffer( const Image::container_t& container, const pod::Vector2ui& size, std::size_t bpp, std::size_t channels, bool flip = false ); - std::string getFilename() const; + uf::stl::string getFilename() const; Image::container_t& getPixels(); const Image::container_t& getPixels() const; @@ -57,16 +57,16 @@ namespace uf { std::size_t& getChannels(); std::size_t getChannels() const; - std::string getHash() const; + uf::stl::string getHash() const; size_t getFormat() const; Image::pixel_t at( const Image::vec2_t& at ); // Modifiers void flip(); void padToPowerOfTwo(); - bool save( const std::string& filename, bool flip = false ) const; // to file + bool save( const uf::stl::string& filename, bool flip = false ) const; // to file void save( std::ostream& stream ) const; // to stream - void convert( const std::string&, const std::string& = "rgba" ); + void convert( const uf::stl::string&, const uf::stl::string& = "rgba" ); Image overlay(const Image& top, const Image::vec2_t& corner = {} ) const; // Merges one image on top of another Image replace(const Image::pixel_t& from, const Image::pixel_t& to ) const; // Changes all pixel from one color (from), to another (to) Image subImage( const Image::vec2_t& start, const Image::vec2_t& end) const; // Crops an image diff --git a/engine/inc/uf/utils/io/file.h b/engine/inc/uf/utils/io/file.h index ef5dee20..7fbee3a9 100644 --- a/engine/inc/uf/utils/io/file.h +++ b/engine/inc/uf/utils/io/file.h @@ -1,48 +1,48 @@ #pragma once #include -#include -#include +#include +#include #include namespace uf { namespace io { - extern UF_API const std::string root; + extern UF_API const uf::stl::string root; - std::string UF_API absolute( const std::string& ); - std::string UF_API filename( const std::string& ); - std::string UF_API basename( const std::string& ); - std::string UF_API extension( const std::string& ); - std::string UF_API extension( const std::string&, int32_t ); - std::string UF_API directory( const std::string& ); - std::string UF_API sanitize( const std::string&, const std::string& = "" ); - size_t UF_API size( const std::string& ); + uf::stl::string UF_API absolute( const uf::stl::string& ); + uf::stl::string UF_API filename( const uf::stl::string& ); + uf::stl::string UF_API basename( const uf::stl::string& ); + uf::stl::string UF_API extension( const uf::stl::string& ); + uf::stl::string UF_API extension( const uf::stl::string&, int32_t ); + uf::stl::string UF_API directory( const uf::stl::string& ); + uf::stl::string UF_API sanitize( const uf::stl::string&, const uf::stl::string& = "" ); + size_t UF_API size( const uf::stl::string& ); - std::string UF_API readAsString( const std::string&, const std::string& = "" ); - std::vector UF_API readAsBuffer( const std::string&, const std::string& = "" ); + uf::stl::string UF_API readAsString( const uf::stl::string&, const uf::stl::string& = "" ); + uf::stl::vector UF_API readAsBuffer( const uf::stl::string&, const uf::stl::string& = "" ); - size_t UF_API write( const std::string& filename, const void*, size_t = SIZE_MAX ); - template inline size_t write( const std::string& filename, const std::vector& buffer, size_t size = SIZE_MAX ) { + size_t UF_API write( const uf::stl::string& filename, const void*, size_t = SIZE_MAX ); + template inline size_t write( const uf::stl::string& filename, const uf::stl::vector& buffer, size_t size = SIZE_MAX ) { return write( filename, buffer.data(), std::min( buffer.size(), size ) ); } - inline size_t write( const std::string& filename, const std::string& string, size_t size = SIZE_MAX ) { + inline size_t write( const uf::stl::string& filename, const uf::stl::string& string, size_t size = SIZE_MAX ) { return write( filename, string.c_str(), std::min( string.size(), size ) ); } - std::vector UF_API decompress( const std::string& ); + uf::stl::vector UF_API decompress( const uf::stl::string& ); - size_t UF_API compress( const std::string&, const void*, size_t = SIZE_MAX ); - template inline size_t compress( const std::string& filename, const std::vector& buffer, size_t size = SIZE_MAX ) { + size_t UF_API compress( const uf::stl::string&, const void*, size_t = SIZE_MAX ); + template inline size_t compress( const uf::stl::string& filename, const uf::stl::vector& buffer, size_t size = SIZE_MAX ) { return compress( filename, buffer.data(), std::min( buffer.size(), size ) ); } - inline size_t compress( const std::string& filename, const std::string& string, size_t size = SIZE_MAX ) { + inline size_t compress( const uf::stl::string& filename, const uf::stl::string& string, size_t size = SIZE_MAX ) { return compress( filename, string.c_str(), std::min( string.size(), size ) ); } - std::string UF_API hash( const std::string& ); - bool UF_API exists( const std::string& ); - size_t UF_API mtime( const std::string& ); - bool UF_API mkdir( const std::string& ); - std::string UF_API resolveURI( const std::string&, const std::string& = "" ); + uf::stl::string UF_API hash( const uf::stl::string& ); + bool UF_API exists( const uf::stl::string& ); + size_t UF_API mtime( const uf::stl::string& ); + bool UF_API mkdir( const uf::stl::string& ); + uf::stl::string UF_API resolveURI( const uf::stl::string&, const uf::stl::string& = "" ); } } \ No newline at end of file diff --git a/engine/inc/uf/utils/io/iostream.h b/engine/inc/uf/utils/io/iostream.h index 57cf772e..77700387 100644 --- a/engine/inc/uf/utils/io/iostream.h +++ b/engine/inc/uf/utils/io/iostream.h @@ -1,12 +1,12 @@ #pragma once #include -#include +#include #include #include -#include -#include +#include +#include #include #include @@ -18,7 +18,7 @@ namespace uf { short id; short foreground; short background; - std::string name; + uf::stl::string name; }; class UF_API Color { @@ -30,25 +30,25 @@ namespace uf { uf::IoStream& io; UF_API_CALL Manip1( uf::IoStream& ); public: - uf::IoStream& UF_API_CALL operator<<( const std::string& name ); + uf::IoStream& UF_API_CALL operator<<( const uf::stl::string& name ); }; class UF_API Manip2 { friend class uf::IoStream; friend class uf::IoStream::Color; protected: - std::string name; + uf::stl::string name; - UF_API_CALL Manip2( const std::string& = "" ); + UF_API_CALL Manip2( const uf::stl::string& = "" ); }; - uf::IoStream::Color::Manip2 UF_API_CALL operator()( const std::string& = "" ) const; - uf::IoStream& UF_API_CALL operator()( uf::IoStream&, const std::string& = "" ) const; + uf::IoStream::Color::Manip2 UF_API_CALL operator()( const uf::stl::string& = "" ) const; + uf::IoStream& UF_API_CALL operator()( uf::IoStream&, const uf::stl::string& = "" ) const; }; - typedef std::unordered_map color_container_t; + typedef uf::stl::unordered_map color_container_t; static bool ncurses; protected: - std::string m_currentColor; + uf::stl::string m_currentColor; uf::IoStream::color_container_t m_registeredColors; public: UF_API_CALL IoStream(); @@ -58,11 +58,11 @@ namespace uf { void UF_API_CALL terminate(); void UF_API_CALL clear(bool = true); void UF_API_CALL back(); - std::string getBuffer(); - std::vector getHistory(); + uf::stl::string getBuffer(); + uf::stl::vector getHistory(); char UF_API_CALL readChar(const bool& = true); - std::string UF_API_CALL readString(const bool& = true); + uf::stl::string UF_API_CALL readString(const bool& = true); uf::String UF_API_CALL readUString(const bool& = true); void UF_API_CALL operator>> (bool&); void UF_API_CALL operator>> (short&); @@ -77,13 +77,13 @@ namespace uf { void UF_API_CALL operator>> (float&); void UF_API_CALL operator>> (double&); void UF_API_CALL operator>> (long double&); - void UF_API_CALL operator>> (std::string&); + void UF_API_CALL operator>> (uf::stl::string&); void UF_API_CALL operator>> (uf::String&); std::istream& UF_API_CALL operator>> ( std::istream& ); friend std::istream& UF_API_CALL operator>> ( std::istream&, uf::IoStream& ); char UF_API_CALL writeChar(char); - const std::string& UF_API_CALL writeString(const std::string&); + const uf::stl::string& UF_API_CALL writeString(const uf::stl::string&); const uf::String& UF_API_CALL writeUString(const uf::String&); uf::IoStream& UF_API_CALL operator<< (const bool&); uf::IoStream& UF_API_CALL operator<< (const short&); @@ -98,7 +98,7 @@ namespace uf { uf::IoStream& UF_API_CALL operator<< (const float&); uf::IoStream& UF_API_CALL operator<< (const double&); uf::IoStream& UF_API_CALL operator<< (const long double&); - uf::IoStream& UF_API_CALL operator<< (const std::string&); + uf::IoStream& UF_API_CALL operator<< (const uf::stl::string&); uf::IoStream& UF_API_CALL operator<< (const uf::String&); uf::IoStream& UF_API_CALL operator<< (const char*); uf::IoStream& UF_API_CALL operator<< (const uf::Serializer& val); @@ -109,8 +109,8 @@ namespace uf { uf::IoStream::Color::Manip1 UF_API_CALL operator<< ( const uf::IoStream::Color& ); uf::IoStream& UF_API_CALL operator<< ( const uf::IoStream::Color::Manip2& ); - std::string UF_API_CALL getColor(); - void UF_API_CALL setColor( const std::string& ); + uf::stl::string UF_API_CALL getColor(); + void UF_API_CALL setColor( const uf::stl::string& ); }; extern UF_API uf::IoStream iostream; } \ No newline at end of file diff --git a/engine/inc/uf/utils/math/collision.h b/engine/inc/uf/utils/math/collision.h index 7db8db80..40170ffc 100644 --- a/engine/inc/uf/utils/math/collision.h +++ b/engine/inc/uf/utils/math/collision.h @@ -6,12 +6,12 @@ #include "./collision/boundingbox.h" #include "./collision/sphere.h" #include "./collision/mesh.h" -#include +#include namespace uf { class UF_API Collider { public: - typedef std::vector container_t; + typedef uf::stl::vector container_t; protected: uf::Collider::container_t m_container; public: @@ -24,7 +24,7 @@ namespace uf { std::size_t getSize() const; - std::vector intersects( const uf::Collider&, bool = false ) const; - std::vector intersects( const pod::Collider&, bool = false ) const; + uf::stl::vector intersects( const uf::Collider&, bool = false ) const; + uf::stl::vector intersects( const pod::Collider&, bool = false ) const; }; } \ No newline at end of file diff --git a/engine/inc/uf/utils/math/collision/boundingbox.h b/engine/inc/uf/utils/math/collision/boundingbox.h index c4792322..345a1a9d 100644 --- a/engine/inc/uf/utils/math/collision/boundingbox.h +++ b/engine/inc/uf/utils/math/collision/boundingbox.h @@ -19,7 +19,7 @@ namespace uf { pod::Vector3 max() const; pod::Vector3 closest( const pod::Vector3f& ) const; - virtual std::string type() const; + virtual uf::stl::string type() const; virtual pod::Vector3* expand() const; virtual pod::Vector3 support( const pod::Vector3& ) const; pod::Collider::Manifold intersects( const uf::BoundingBox& ) const; diff --git a/engine/inc/uf/utils/math/collision/gjk.h b/engine/inc/uf/utils/math/collision/gjk.h index de14c442..d9af755c 100644 --- a/engine/inc/uf/utils/math/collision/gjk.h +++ b/engine/inc/uf/utils/math/collision/gjk.h @@ -75,7 +75,7 @@ namespace pod { } }; virtual ~Collider(); - virtual std::string type() const; + virtual uf::stl::string type() const; virtual pod::Vector3* expand() const = 0; virtual pod::Vector3 support( const pod::Vector3& ) const = 0; pod::Collider::Manifold intersects( const pod::Collider& ) const; diff --git a/engine/inc/uf/utils/math/collision/mesh.h b/engine/inc/uf/utils/math/collision/mesh.h index 0ebb50b5..cfe3aab4 100644 --- a/engine/inc/uf/utils/math/collision/mesh.h +++ b/engine/inc/uf/utils/math/collision/mesh.h @@ -6,14 +6,14 @@ namespace uf { class UF_API MeshCollider : public pod::Collider { protected: - std::vector m_positions; + uf::stl::vector m_positions; public: - MeshCollider( const pod::Transform<>& = {}, const std::vector& = {} ); + MeshCollider( const pod::Transform<>& = {}, const uf::stl::vector& = {} ); - std::vector& getPositions(); - const std::vector& getPositions() const; + uf::stl::vector& getPositions(); + const uf::stl::vector& getPositions() const; - void setPositions( const std::vector& ); + void setPositions( const uf::stl::vector& ); template void setPositions( const uf::BaseMesh& mesh ) { @@ -26,7 +26,7 @@ namespace uf { } } - virtual std::string type() const; + virtual uf::stl::string type() const; virtual pod::Vector3* expand() const; virtual pod::Vector3 support( const pod::Vector3& ) const; }; diff --git a/engine/inc/uf/utils/math/collision/modular.h b/engine/inc/uf/utils/math/collision/modular.h index c515716b..0680c8c4 100644 --- a/engine/inc/uf/utils/math/collision/modular.h +++ b/engine/inc/uf/utils/math/collision/modular.h @@ -27,7 +27,7 @@ namespace uf { uint getSize() const; void setContainer( pod::Vector3*, uint ); - virtual std::string type() const; + virtual uf::stl::string type() const; virtual pod::Vector3* expand() const; virtual pod::Vector3 support( const pod::Vector3& ) const; }; diff --git a/engine/inc/uf/utils/math/collision/sphere.h b/engine/inc/uf/utils/math/collision/sphere.h index 4dc71ecc..02ea475e 100644 --- a/engine/inc/uf/utils/math/collision/sphere.h +++ b/engine/inc/uf/utils/math/collision/sphere.h @@ -16,7 +16,7 @@ namespace uf { void setRadius( float = 1.0f ); void setOrigin( const pod::Vector3& ); - virtual std::string type() const; + virtual uf::stl::string type() const; virtual pod::Vector3* expand() const; virtual pod::Vector3 support( const pod::Vector3& ) const; pod::Collider::Manifold intersects( const uf::SphereCollider& ) const; diff --git a/engine/inc/uf/utils/math/matrix.h b/engine/inc/uf/utils/math/matrix.h index c9c14801..a8b94cd8 100644 --- a/engine/inc/uf/utils/math/matrix.h +++ b/engine/inc/uf/utils/math/matrix.h @@ -9,7 +9,11 @@ #include "math.h" namespace pod { template - struct UF_API /*alignas(16)*/ Matrix { +#if UF_MATRIX_ALIGNED + struct /*UF_API*/ alignas(16) Matrix { +#else + struct /*UF_API*/ /*alignas(16)*/ Matrix { +#endif // n-dimensional/unspecialized matrix access T components[R*C] = {}; // T components[R][C] = {}; @@ -53,7 +57,7 @@ namespace uf { template pod::Matrix4t /*UF_API*/ identity(); template pod::Matrix4t /*UF_API*/ initialize( const T* ); - template pod::Matrix4t /*UF_API*/ initialize( const std::vector& ); + template pod::Matrix4t /*UF_API*/ initialize( const uf::stl::vector& ); template pod::Matrix /*UF_API*/ identityi(); // Equality checking @@ -104,7 +108,7 @@ namespace uf { template T& /*UF_API*/ copy( T& destination, const T& source ); template T& /*UF_API*/ copy( T& destination, typename T::type_t* const source ); - template std::string /*UF_API*/ toString( const pod::Matrix& v ); + template uf::stl::string /*UF_API*/ toString( const pod::Matrix& v ); template ext::json::Value /*UF_API*/ encode( const pod::Matrix& v, const ext::json::EncodingSettings& = {} ); template pod::Matrix& /*UF_API*/ decode( const ext::json::Value& v, pod::Matrix& ); template pod::Matrix /*UF_API*/ decode( const ext::json::Value& v, const pod::Matrix& = uf::matrix::identity() ); @@ -131,7 +135,7 @@ namespace uf { Matrix(const Matrix::pod_t& pod); // copies POD altogether Matrix(const T components[R][C]); // copies data into POD from 'components' (typed as C array) Matrix(const T components[R*C]); // copies data into POD from 'components' (typed as C array) - Matrix(const std::vector& components); // copies data into POD from 'components' (typed as std::matrix) + Matrix(const uf::stl::vector& components); // copies data into POD from 'components' (typed as std::matrix) // D-tor // Unneccesary // POD access @@ -189,7 +193,7 @@ namespace uf { namespace uf { namespace string { template - std::string /*UF_API*/ toString( const pod::Matrix& v ); + uf::stl::string /*UF_API*/ toString( const pod::Matrix& v ); } } namespace ext { diff --git a/engine/inc/uf/utils/math/matrix/class.inl b/engine/inc/uf/utils/math/matrix/class.inl index 16ee0831..27af2b0e 100644 --- a/engine/inc/uf/utils/math/matrix/class.inl +++ b/engine/inc/uf/utils/math/matrix/class.inl @@ -21,7 +21,7 @@ uf::Matrix::Matrix(const T components[R*C] ) { } // copies data into POD from 'components' (typed as std::matrix) template -uf::Matrix::Matrix(const std::vector& components ) { +uf::Matrix::Matrix(const uf::stl::vector& components ) { this->m_pod = uf::matrix::initialize( components ); } // D-tor diff --git a/engine/inc/uf/utils/math/matrix/matrix.inl b/engine/inc/uf/utils/math/matrix/matrix.inl index af16e0ad..61f2168f 100644 --- a/engine/inc/uf/utils/math/matrix/matrix.inl +++ b/engine/inc/uf/utils/math/matrix/matrix.inl @@ -2,7 +2,7 @@ #include "class.inl" template -std::string /*UF_API*/ uf::string::toString( const pod::Matrix& m ) { +uf::stl::string /*UF_API*/ uf::string::toString( const pod::Matrix& m ) { return uf::matrix::toString(m); } diff --git a/engine/inc/uf/utils/math/matrix/pod.inl b/engine/inc/uf/utils/math/matrix/pod.inl index e7277e90..8a162b7c 100644 --- a/engine/inc/uf/utils/math/matrix/pod.inl +++ b/engine/inc/uf/utils/math/matrix/pod.inl @@ -1,4 +1,4 @@ -#if __GNUC__ +#if !__clang__ && __GNUC__ #pragma GCC push_options #pragma GCC optimize ("unroll-loops") #endif @@ -47,7 +47,7 @@ const T* pod::Matrix::operator[](size_t i) const { */ template pod::Matrix4t /*UF_API*/ uf::matrix::identity() { - pod::Matrix4t matrix; + alignas(16) pod::Matrix4t matrix; #pragma unroll // GCC unroll 4 for ( uint_fast8_t c = 0; c < 4; ++c ) #pragma unroll // GCC unroll 4 @@ -57,7 +57,7 @@ pod::Matrix4t /*UF_API*/ uf::matrix::identity() { } template pod::Matrix4t /*UF_API*/ uf::matrix::initialize( const T* list ) { - pod::Matrix4t matrix; + alignas(16) pod::Matrix4t matrix; // memcpy(&matrix[0], list, sizeof(matrix)); #pragma unroll // GCC unroll 16 for ( uint_fast8_t i = 0; i < 16; ++i ) @@ -71,8 +71,8 @@ pod::Matrix4t /*UF_API*/ uf::matrix::initialize( const T* list ) { return matrix; } template -pod::Matrix4t /*UF_API*/ uf::matrix::initialize( const std::vector& list ) { - pod::Matrix4t matrix; +pod::Matrix4t /*UF_API*/ uf::matrix::initialize( const uf::stl::vector& list ) { + alignas(16) pod::Matrix4t matrix; if ( list.size() != 16 ) return matrix; // memcpy(&matrix[0], &list[0], sizeof(matrix)); #pragma unroll // GCC unroll 16 @@ -89,7 +89,7 @@ pod::Matrix4t /*UF_API*/ uf::matrix::initialize( const std::vector& list ) return matrix; } template pod::Matrix uf::matrix::identityi(){ - pod::Matrix matrix; + alignas(16) pod::Matrix matrix; #pragma unroll // GCC unroll T::columns for ( uint_fast8_t c = 0; c < T::columns; ++c ) @@ -149,7 +149,7 @@ template bool uf::matrix::equals( const T& left, const T& right ) { // Basic arithmetic // Multiplies two matrices of same type and size together template pod::Matrix uf::matrix::multiply( const pod::Matrix& left, const pod::Matrix& right ) { - pod::Matrix res; + alignas(16) pod::Matrix res; #if UF_USE_SIMD auto row1 = uf::simd::load(&left[0]); auto row2 = uf::simd::load(&left[4]); @@ -242,7 +242,7 @@ template pod::Matrix uf::matrix::multiply( const pod::Matrix< #endif } template pod::Matrix uf::matrix::multiply( const T& left, const U& right ) { - pod::Matrix res; + alignas(16) pod::Matrix res; #if 1 float* dstPtr = &res[0]; const float* leftPtr = &right[0]; @@ -279,16 +279,16 @@ template pod::Matrix T /*UF_API*/ uf::matrix::multiplyAll( const T& m, typename T::type_t scalar ) { - T matrix; +template T /*UF_API*/ uf::matrix::multiplyAll( const T& m, typename T::type_t scalar ) { + alignas(16) T matrix; #pragma unroll // GCC unroll T::rows * T::columns for ( uint_fast8_t i = 0; i < T::rows * T::columns; ++i ) matrix[i] = m[i] * scalar; return matrix; } -template T /*UF_API*/ uf::matrix::add( const T& lhs, const T& rhs ) { - T matrix; +template T /*UF_API*/ uf::matrix::add( const T& lhs, const T& rhs ) { + alignas(16) T matrix; #pragma unroll // GCC unroll T::rows * T::columns for ( uint_fast8_t i = 0; i < T::rows * T::columns; ++i ) matrix[i] = lhs[i] + rhs[i]; @@ -297,7 +297,7 @@ template T /*UF_API*/ uf::matrix::add( const T& lhs, co } // Transpose matrix template T uf::matrix::transpose( const T& matrix ) { - T transpose; + alignas(16) T transpose; #pragma unroll // GCC unroll T::rows for ( typename T::type_t r = 0; r < T::rows; ++r ) @@ -313,7 +313,8 @@ template T uf::matrix::inverse( const T& matrix ) { if ( T::rows != 4 || T::columns != 4 ) return matrix; const typename T::type_t* m = &matrix[0]; - typename T::type_t inv[16], det; + alignas(16) typename T::type_t inv[16]; + typename T::type_t det; uint_fast8_t i; inv[0] = m[5] * m[10] * m[15] - @@ -416,7 +417,7 @@ template T uf::matrix::inverse( const T& matrix ) { det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; if (det == 0) return matrix; det = 1.0 / det; - T inverted; + alignas(16) T inverted; #pragma unroll // GCC unroll 16 for ( i = 0; i < 16; ++i ) inverted[i] = inv[i] * det; @@ -439,7 +440,7 @@ template pod::Vector4t uf::matrix::multiply( const pod::Matrix4t< if ( div && res.w > 0 ) res /= res.w; return res; #else - auto res = pod::Vector4t{ + alignas(16) auto res = pod::Vector4t{ vector[0] * mat[0] + vector[1] * mat[4] + vector[2] * mat[8] + vector[3] * mat[12], vector[0] * mat[1] + vector[1] * mat[5] + vector[2] * mat[9] + vector[3] * mat[13], vector[0] * mat[2] + vector[1] * mat[6] + vector[2] * mat[10] + vector[3] * mat[14], @@ -455,14 +456,14 @@ template T& uf::matrix::invert( T& matrix ) { } // Complex arithmetic template T uf::matrix::translate( const T& matrix, const pod::Vector3t& vector ) { - T res = matrix; + alignas(16) T res = matrix; res[12] = vector.x; res[13] = vector.y; res[14] = vector.z; return res; } template T uf::matrix::rotate( const T& matrix, const pod::Vector3t& vector ) { - T res = matrix; + alignas(16) T res = matrix; if ( vector.x != 0 ) { res[5] = cos( vector.x ); res[6] = sin( vector.x ); @@ -486,7 +487,7 @@ template T uf::matrix::rotate( const T& matrix, const pod::Vector3t< return res; } template T uf::matrix::scale( const T& matrix, const pod::Vector3t& vector ) { - T res = matrix; + alignas(16) T res = matrix; res[0] = vector.x; res[5] = vector.y; res[10] = vector.z; @@ -529,7 +530,7 @@ template T& uf::matrix::scale( T& matrix, const pod::Vector3t pod::Matrix4t /*UF_API*/ uf::matrix::orthographic( T l, T r, T b, T t, T f, T n ) { - pod::Matrix4t m = uf::matrix::identity(); + alignas(16) pod::Matrix4t m = uf::matrix::identity(); m[0*4+0] = 2 / (r - l); m[1*4+1] = 2 / (t - b); m[2*4+2] = - 2 / (f - n); @@ -538,7 +539,7 @@ pod::Matrix4t /*UF_API*/ uf::matrix::orthographic( T l, T r, T b, T t, T f, T m[3*4+2] = - (f + n) / (f - n); return m; /* - std::vector m = { + uf::stl::vector m = { 2 / (r - l), 0, 0, 0, 0, 2 / (t - b), 0, 0, 0, 0, -2 / (f - n), 0, @@ -549,15 +550,14 @@ pod::Matrix4t /*UF_API*/ uf::matrix::orthographic( T l, T r, T b, T t, T f, T } template pod::Matrix4t /*UF_API*/ uf::matrix::orthographic( T l, T r, T b, T t ) { - std::vector m = { + return pod::Matrix4t({ 2 / (r - l), 0, 0, 0, 0, 2 / (t - b), 0, 0, 0, 0, 1, 0, -(r + l) / (r - l), -(t+b)/(t-b), 0, 1 - }; - return uf::matrix::initialize(m); + }); } -template +template pod::Matrix4t /*UF_API*/ uf::matrix::perspective( T fov, T raidou, T znear, T zfar ) { if ( uf::matrix::reverseInfiniteProjection ) { T f = static_cast(1) / tan( static_cast(0.5) * fov ); @@ -654,7 +654,7 @@ pod::Matrix& /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, template pod::Matrix /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, const pod::Matrix& _m ) { - pod::Matrix m = _m; + alignas(16) pod::Matrix m = _m; if ( ext::json::isArray(json) ) #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < R*C; ++i ) @@ -671,8 +671,8 @@ pod::Matrix /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, } template -std::string /*UF_API*/ uf::matrix::toString( const pod::Matrix& m ) { - std::stringstream ss; +uf::stl::string /*UF_API*/ uf::matrix::toString( const pod::Matrix& m ) { + uf::stl::stringstream ss; ss << "Matrix(\n\t"; #pragma unroll // GCC unroll C for ( uint_fast8_t c = 0; c < C; ++c ) { @@ -686,6 +686,6 @@ std::string /*UF_API*/ uf::matrix::toString( const pod::Matrix& m ) { return ss.str(); } -#if __GNUC__ +#if !__clang__ && __GNUC__ #pragma GCC pop_options #endif \ No newline at end of file diff --git a/engine/inc/uf/utils/math/physics/pod.inl b/engine/inc/uf/utils/math/physics/pod.inl index 022a408f..68883b3e 100644 --- a/engine/inc/uf/utils/math/physics/pod.inl +++ b/engine/inc/uf/utils/math/physics/pod.inl @@ -3,7 +3,7 @@ template pod::Transform& uf::physics::update( pod::Transform& physics.previous = transform; if ( physics.linear.acceleration != pod::Vector3t{0,0,0} ) - physics.linear.velocity += (physics.linear.acceleration*uf::physics::time::delta); + physics.linear.velocity += (physics.linear.acceleration * uf::physics::time::delta); if ( physics.rotational.acceleration != pod::Quaternion{0,0,0,0} ) { physics.rotational.velocity = uf::quaternion::multiply(physics.rotational.velocity, physics.rotational.acceleration*uf::physics::time::delta); } diff --git a/engine/inc/uf/utils/math/quaternion.h b/engine/inc/uf/utils/math/quaternion.h index ec3282dd..1f86069c 100644 --- a/engine/inc/uf/utils/math/quaternion.h +++ b/engine/inc/uf/utils/math/quaternion.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -94,7 +94,7 @@ public: Quaternion(T x, T y, T z, T w); // initializes POD to 'def' Quaternion(const Quaternion::pod_t& pod); // copies POD altogether Quaternion(const T components[4]); // copies data into POD from 'components' (typed as C array) - Quaternion(const std::vector& components); // copies data into POD from 'components' (typed as std::vector) + Quaternion(const uf::stl::vector& components); // copies data into POD from 'components' (typed as uf::stl::vector) // D-tor // Unneccesary // POD access @@ -140,7 +140,7 @@ public: inline uf::Quaternion getConjugate() const; inline uf::Quaternion getInverse() const; - inline std::string toString() const; + inline uf::stl::string toString() const; // Overloaded ops // Accessing via subscripts T& operator[](std::size_t i); diff --git a/engine/inc/uf/utils/math/quaternion/class.inl b/engine/inc/uf/utils/math/quaternion/class.inl index b9a00260..0ab81ec0 100644 --- a/engine/inc/uf/utils/math/quaternion/class.inl +++ b/engine/inc/uf/utils/math/quaternion/class.inl @@ -32,9 +32,9 @@ uf::Quaternion::Quaternion(const T components[4] ) : { } -// copies data into POD from 'components' (typed as std::vector) +// copies data into POD from 'components' (typed as uf::stl::vector) template -uf::Quaternion::Quaternion(const std::vector& components) { +uf::Quaternion::Quaternion(const uf::stl::vector& components) { memcpy( this->m_pod.components, &components[0], 4 ); } // D-tor @@ -203,7 +203,7 @@ inline uf::Quaternion uf::Quaternion::getInverse() const { return uf::quaternion::inverse(this->m_pod); } template -inline std::string uf::Quaternion::toString() const { +inline uf::stl::string uf::Quaternion::toString() const { return uf::vector::toString(this->m_pod); } // Overloaded ops diff --git a/engine/inc/uf/utils/math/rayt.h b/engine/inc/uf/utils/math/rayt.h index 5fa78f4d..3332318f 100644 --- a/engine/inc/uf/utils/math/rayt.h +++ b/engine/inc/uf/utils/math/rayt.h @@ -27,9 +27,9 @@ namespace pod { namespace uf { namespace primitive { - std::vector UF_API populate( const std::vector& cubes ); - std::vector UF_API populateEntirely( const std::vector& cubes ); - std::vector UF_API populateEntirely( const std::vector& trees, bool = false ); - void UF_API test( const std::vector& cubes, const std::vector& trees ); + uf::stl::vector UF_API populate( const uf::stl::vector& cubes ); + uf::stl::vector UF_API populateEntirely( const uf::stl::vector& cubes ); + uf::stl::vector UF_API populateEntirely( const uf::stl::vector& trees, bool = false ); + void UF_API test( const uf::stl::vector& cubes, const uf::stl::vector& trees ); } } \ No newline at end of file diff --git a/engine/inc/uf/utils/math/transform.h b/engine/inc/uf/utils/math/transform.h index dc4c73b1..9e3400aa 100644 --- a/engine/inc/uf/utils/math/transform.h +++ b/engine/inc/uf/utils/math/transform.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -56,7 +56,7 @@ namespace uf { template pod::Transform /*UF_API*/ fromMatrix( const pod::Matrix4t& matrix ); template pod::Transform& /*UF_API*/ reference( pod::Transform& transform, const pod::Transform& parent, bool reorient = true ); - template std::string /*UF_API*/ toString( const pod::Transform&, bool flatten = true ); + template uf::stl::string /*UF_API*/ toString( const pod::Transform&, bool flatten = true ); template ext::json::Value /*UF_API*/ encode( const pod::Transform&, bool flatten = true, const ext::json::EncodingSettings& = {} ); template pod::Transform& /*UF_API*/ decode( const ext::json::Value&, pod::Transform& ); template pod::Transform /*UF_API*/ decode( const ext::json::Value&, const pod::Transform& = {} ); @@ -67,7 +67,7 @@ namespace uf { namespace uf { namespace string { template - std::string toString( const pod::Transform& v, bool flatten = true ); + uf::stl::string toString( const pod::Transform& v, bool flatten = true ); } } namespace ext { diff --git a/engine/inc/uf/utils/math/transform/transform.inl b/engine/inc/uf/utils/math/transform/transform.inl index 12163054..fdcfcedc 100644 --- a/engine/inc/uf/utils/math/transform/transform.inl +++ b/engine/inc/uf/utils/math/transform/transform.inl @@ -152,9 +152,9 @@ template pod::Transform& /*UF_API*/ uf::transform::reference( pod } template // Normalizes a vector -std::string /*UF_API*/ uf::transform::toString( const pod::Transform& t, bool flatten ) { +uf::stl::string /*UF_API*/ uf::transform::toString( const pod::Transform& t, bool flatten ) { pod::Transform transform = flatten ? uf::transform::flatten(t) : t; - std::stringstream ss; + uf::stl::stringstream ss; ss << "Transform(" << uf::string::toString(transform.position) << "; " << uf::string::toString(transform.orientation) << ")"; return ss.str(); } diff --git a/engine/inc/uf/utils/math/vector.h b/engine/inc/uf/utils/math/vector.h index 0b79e7f4..ede6a46d 100644 --- a/engine/inc/uf/utils/math/vector.h +++ b/engine/inc/uf/utils/math/vector.h @@ -5,7 +5,7 @@ #include "math.h" #include -#include +#include #include #include #include @@ -34,12 +34,16 @@ namespace pod { Vector operator-( const Vector& vector ) const; // Subtraction between two vectors Vector operator*( const Vector& vector ) const; // Multiplication between two vectors Vector operator/( const Vector& vector ) const; // Division between two vectors + Vector operator+( T scalar ) const; // Multiplication with scalar + Vector operator-( T scalar ) const; // Multiplication with scalar Vector operator*( T scalar ) const; // Multiplication with scalar Vector operator/( T scalar ) const; // Division with scalar Vector& operator +=( const Vector& vector ); // Addition set between two vectors Vector& operator -=( const Vector& vector ); // Subtraction set between two vectors Vector& operator *=( const Vector& vector ); // Multiplication set between two vectors Vector& operator /=( const Vector& vector ); // Division set between two vectors + Vector& operator +=( T scalar ); // Multiplication set with scalar + Vector& operator -=( T scalar ); // Multiplication set with scalar Vector& operator *=( T scalar ); // Multiplication set with scalar Vector& operator /=( T scalar ); // Division set with scalar bool operator==( const Vector& vector ) const; // Equality check between two vectors (equals) @@ -51,7 +55,7 @@ namespace pod { template Vector& operator=( const Vector& vector ); template operator Vector(); - inline operator bool() const; + explicit inline operator bool() const; }; template using Vector1t = Vector; typedef Vector1t Vector1; @@ -106,7 +110,9 @@ namespace uf { template bool /*UF_API*/ equals( const T& left, const T& right ); // Equality check between two vectors (equals) // Basic arithmetic template T /*UF_API*/ add( const T& left, const T& right ); // Adds two vectors of same type and size together + template T /*UF_API*/ add( const T& left, const typename T::type_t& scalar ); // Adds two vectors of same type and size together template T /*UF_API*/ subtract( const T& left, const T& right ); // Subtracts two vectors of same type and size together + template T /*UF_API*/ subtract( const T& left, const typename T::type_t& scalar ); // Subtracts two vectors of same type and size together template T /*UF_API*/ multiply( const T& left, const T& right ); // Multiplies two vectors of same type and size together template T /*UF_API*/ multiply( const T& vector, const typename T::type_t& scalar ); // Multiplies this vector by a scalar template T /*UF_API*/ divide( const T& left, const T& right ); // Divides two vectors of same type and size together @@ -116,7 +122,9 @@ namespace uf { template T /*UF_API*/ negate( const T& vector ); // Flip sign of all components // Writes to first value template T& /*UF_API*/ add( T& left, const T& right ); // Adds two vectors of same type and size together + template T& /*UF_API*/ add( T& left, const typename T::type_t& scalar ); // Adds two vectors of same type and size together template T& /*UF_API*/ subtract( T& left, const T& right ); // Subtracts two vectors of same type and size together + template T& /*UF_API*/ subtract( T& left, const typename T::type_t& scalar ); // Subtracts two vectors of same type and size together template T& /*UF_API*/ multiply( T& left, const T& right ); // Multiplies two vectors of same type and size together template T& /*UF_API*/ multiply( T& vector, const typename T::type_t& scalar ); // Multiplies this vector by a scalar template T& /*UF_API*/ divide( T& left, const T& right ); // Divides two vectors of same type and size together @@ -142,7 +150,7 @@ namespace uf { template void /*UF_API*/ orthonormalize( T& x, T& y ); // Normalizes a vector template T /*UF_API*/ orthonormalize( const T& x, const T& y ); // Normalizes a vector - template std::string /*UF_API*/ toString( const T& vector ); // Parses a vector as a string + template uf::stl::string /*UF_API*/ toString( const T& vector ); // Parses a vector as a string template ext::json::Value encode( const pod::Vector& v, const ext::json::EncodingSettings& = {} ); // Parses a vector into a JSON value template pod::Vector& decode( const ext::json::Value& v, pod::Vector& ); // Parses a JSON value into a vector @@ -172,7 +180,7 @@ namespace uf { Vector(const Vector& v, T w); Vector(const Vector::pod_t& pod); // copies POD altogether Vector(const T components[N]); // copies data into POD from 'components' (typed as C array) - Vector(const std::vector& components); // copies data into POD from 'components' (typed as std::vector) + Vector(const uf::stl::vector& components); // copies data into POD from 'components' (typed as uf::stl::vector) // D-tor // Unneccesary // POD access @@ -190,7 +198,9 @@ namespace uf { bool isValid() const; // Checks if all components are valid (non NaN, inf, etc.) // Basic arithmetic inline uf::Vector& add( const Vector& vector ); // Adds two vectors of same type and size together + inline uf::Vector& add( T scalar ); // Adds two vectors of same type and size together inline uf::Vector& subtract( const Vector& vector ); // Subtracts two vectors of same type and size together + inline uf::Vector& subtract( T scalar ); // Subtracts two vectors of same type and size together inline uf::Vector& multiply( const Vector& vector ); // Multiplies two vectors of same type and size together inline uf::Vector& multiply( T scalar ); // Multiplies this vector by a scalar inline uf::Vector& divide( const Vector& vector ); // Divides two vectors of same type and size together @@ -212,7 +222,7 @@ namespace uf { inline uf::Vector& normalize(); // Normalizes a vector uf::Vector getNormalized() const; // Return a normalized vector - inline std::string toString() const; + inline uf::stl::string toString() const; // Overloaded ops // Accessing via subscripts T& operator[](std::size_t i); @@ -223,12 +233,16 @@ namespace uf { inline Vector operator-( const Vector& vector ) const; // Subtraction between two vectors inline Vector operator*( const Vector& vector ) const; // Multiplication between two vectors inline Vector operator/( const Vector& vector ) const; // Division between two vectors + inline Vector operator+( T scalar ) const; // Multiplication with scalar + inline Vector operator-( T scalar ) const; // Multiplication with scalar inline Vector operator*( T scalar ) const; // Multiplication with scalar inline Vector operator/( T scalar ) const; // Division with scalar inline Vector& operator +=( const Vector& vector ); // Addition set between two vectors inline Vector& operator -=( const Vector& vector ); // Subtraction set between two vectors inline Vector& operator *=( const Vector& vector ); // Multiplication set between two vectors inline Vector& operator /=( const Vector& vector ); // Division set between two vectors + inline Vector& operator +=( T scalar ); // Multiplication set with scalar + inline Vector& operator -=( T scalar ); // Multiplication set with scalar inline Vector& operator *=( T scalar ); // Multiplication set with scalar inline Vector& operator /=( T scalar ); // Division set with scalar inline bool operator==( const Vector& vector ) const; // Equality check between two vectors (equals) @@ -285,7 +299,7 @@ namespace uf { namespace uf { namespace string { template - std::string toString( const pod::Vector& v ); + uf::stl::string toString( const pod::Vector& v ); } } namespace ext { @@ -318,12 +332,16 @@ namespace pod { inline Vector operator-( const Vector& vector ) const; // Subtraction between two vectors inline Vector operator*( const Vector& vector ) const; // Multiplication between two vectors inline Vector operator/( const Vector& vector ) const; // Division between two vectors + inline Vector operator+( T scalar ) const; // Multiplication with scalar + inline Vector operator-( T scalar ) const; // Multiplication with scalar inline Vector operator*( T scalar ) const; // Multiplication with scalar inline Vector operator/( T scalar ) const; // Division with scalar inline Vector& operator +=( const Vector& vector ); // Addition set between two vectors inline Vector& operator -=( const Vector& vector ); // Subtraction set between two vectors inline Vector& operator *=( const Vector& vector ); // Multiplication set between two vectors inline Vector& operator /=( const Vector& vector ); // Division set between two vectors + inline Vector& operator +=( T scalar ); // Multiplication set with scalar + inline Vector& operator -=( T scalar ); // Multiplication set with scalar inline Vector& operator *=( T scalar ); // Multiplication set with scalar inline Vector& operator /=( T scalar ); // Division set with scalar inline bool operator==( const Vector& vector ) const; // Equality check between two vectors (equals) @@ -334,7 +352,7 @@ namespace pod { inline bool operator>=( const Vector& vector ) const; // Equality check between two vectors (greater than or equals) template Vector& operator=( const Vector& vector ); template operator Vector(); - inline operator bool() const; + explicit inline operator bool() const; #if 0 #if UF_USE_SIMD Vector& operator=( const __m128 ); @@ -364,12 +382,16 @@ namespace pod { inline Vector operator-( const Vector& vector ) const; // Subtraction between two vectors inline Vector operator*( const Vector& vector ) const; // Multiplication between two vectors inline Vector operator/( const Vector& vector ) const; // Division between two vectors + inline Vector operator+( T scalar ) const; // Multiplication with scalar + inline Vector operator-( T scalar ) const; // Multiplication with scalar inline Vector operator*( T scalar ) const; // Multiplication with scalar inline Vector operator/( T scalar ) const; // Division with scalar inline Vector& operator +=( const Vector& vector ); // Addition set between two vectors inline Vector& operator -=( const Vector& vector ); // Subtraction set between two vectors inline Vector& operator *=( const Vector& vector ); // Multiplication set between two vectors inline Vector& operator /=( const Vector& vector ); // Division set between two vectors + inline Vector& operator +=( T scalar ); // Multiplication set with scalar + inline Vector& operator -=( T scalar ); // Multiplication set with scalar inline Vector& operator *=( T scalar ); // Multiplication set with scalar inline Vector& operator /=( T scalar ); // Division set with scalar inline bool operator==( const Vector& vector ) const; // Equality check between two vectors (equals) @@ -380,7 +402,7 @@ namespace pod { inline bool operator>=( const Vector& vector ) const; // Equality check between two vectors (greater than or equals) template Vector& operator=( const Vector& vector ); template operator Vector(); - inline operator bool() const; + explicit inline operator bool() const; #if 0 #if UF_USE_SIMD Vector& operator=( const __m128 ); @@ -411,12 +433,16 @@ namespace pod { inline Vector operator-( const Vector& vector ) const; // Subtraction between two vectors inline Vector operator*( const Vector& vector ) const; // Multiplication between two vectors inline Vector operator/( const Vector& vector ) const; // Division between two vectors + inline Vector operator+( T scalar ) const; // Multiplication with scalar + inline Vector operator-( T scalar ) const; // Multiplication with scalar inline Vector operator*( T scalar ) const; // Multiplication with scalar inline Vector operator/( T scalar ) const; // Division with scalar inline Vector& operator +=( const Vector& vector ); // Addition set between two vectors inline Vector& operator -=( const Vector& vector ); // Subtraction set between two vectors inline Vector& operator *=( const Vector& vector ); // Multiplication set between two vectors inline Vector& operator /=( const Vector& vector ); // Division set between two vectors + inline Vector& operator +=( T scalar ); // Multiplication set with scalar + inline Vector& operator -=( T scalar ); // Multiplication set with scalar inline Vector& operator *=( T scalar ); // Multiplication set with scalar inline Vector& operator /=( T scalar ); // Division set with scalar inline bool operator==( const Vector& vector ) const; // Equality check between two vectors (equals) @@ -428,7 +454,7 @@ namespace pod { template Vector& operator=( const Vector& vector ); template operator Vector(); - inline operator bool() const; + explicit inline operator bool() const; #if 0 #if UF_USE_SIMD Vector& operator=( const __m128 ); @@ -437,7 +463,11 @@ namespace pod { #endif }; template +#if UF_VECTOR_ALIGNED + struct /*UF_API*/ alignas(16) Vector { +#else struct /*UF_API*/ /*alignas(16)*/ Vector { +#endif // XYZW access T x; T y; @@ -460,12 +490,16 @@ namespace pod { inline Vector operator-( const Vector& vector ) const; // Subtraction between two vectors inline Vector operator*( const Vector& vector ) const; // Multiplication between two vectors inline Vector operator/( const Vector& vector ) const; // Division between two vectors + inline Vector operator+( T scalar ) const; // Multiplication with scalar + inline Vector operator-( T scalar ) const; // Multiplication with scalar inline Vector operator*( T scalar ) const; // Multiplication with scalar inline Vector operator/( T scalar ) const; // Division with scalar inline Vector& operator +=( const Vector& vector ); // Addition set between two vectors inline Vector& operator -=( const Vector& vector ); // Subtraction set between two vectors inline Vector& operator *=( const Vector& vector ); // Multiplication set between two vectors inline Vector& operator /=( const Vector& vector ); // Division set between two vectors + inline Vector& operator +=( T scalar ); // Multiplication set with scalar + inline Vector& operator -=( T scalar ); // Multiplication set with scalar inline Vector& operator *=( T scalar ); // Multiplication set with scalar inline Vector& operator /=( T scalar ); // Division set with scalar inline bool operator==( const Vector& vector ) const; // Equality check between two vectors (equals) @@ -477,7 +511,7 @@ namespace pod { template Vector& operator=( const Vector& vector ); template operator Vector(); - inline operator bool() const; + explicit inline operator bool() const; #if 0 #if UF_USE_SIMD Vector& operator=( const __m128 ); diff --git a/engine/inc/uf/utils/math/vector/class.inl b/engine/inc/uf/utils/math/vector/class.inl index d13e1155..7013ed95 100644 --- a/engine/inc/uf/utils/math/vector/class.inl +++ b/engine/inc/uf/utils/math/vector/class.inl @@ -13,8 +13,8 @@ template // copies data into POD from 'com uf::Vector::Vector(const T components[N]) { this->set(&components[0]); } -template // copies data into POD from 'components' (typed as std::vector) -uf::Vector::Vector(const std::vector& components) { +template // copies data into POD from 'components' (typed as uf::stl::vector) +uf::Vector::Vector(const uf::stl::vector& components) { if ( components.size() >= N ) this->set(&components[0]); } // D-tor @@ -65,10 +65,18 @@ template // Adds two vectors of same type inline uf::Vector& uf::Vector::add( const Vector& vector ) { return uf::vector::add( this->m_pod, vector.data() ); } +template // Multiplies this vector by a scalar +inline uf::Vector& uf::Vector::add( T scalar ) { + return uf::vector::add( this->m_pod, scalar ); +} template // Subtracts two vectors of same type and size together inline uf::Vector& uf::Vector::subtract( const Vector& vector ) { return uf::vector::subtract( this->m_pod, vector.data() ); } +template // Multiplies this vector by a scalar +inline uf::Vector& uf::Vector::subtract( T scalar ) { + return uf::vector::subtract( this->m_pod, scalar ); +} template // Multiplies two vectors of same type and size together inline uf::Vector& uf::Vector::multiply( const Vector& vector ) { return uf::vector::multiply( this->m_pod, vector.data() ); @@ -142,7 +150,7 @@ uf::Vector uf::Vector::getNormalized() const { return uf::vector::normalize( this->m_pod ); } template // Return a string -std::string uf::Vector::toString() const { +uf::stl::string uf::Vector::toString() const { return uf::vector::toString( this->m_pod ); } // Overloaded ops @@ -176,6 +184,14 @@ inline uf::Vector uf::Vector::operator/( const uf::Vector& vector return uf::vector::divide( this->m_pod, vector.data() ); } template // Multiplication with scalar +inline uf::Vector uf::Vector::operator+( T scalar ) const { + return uf::vector::add( this->m_pod, scalar ); +} +template // Multiplication with scalar +inline uf::Vector uf::Vector::operator-( T scalar ) const { + return uf::vector::subtract( this->m_pod, scalar ); +} +template // Multiplication with scalar inline uf::Vector uf::Vector::operator*( T scalar ) const { return uf::vector::multiply( this->m_pod, scalar ); } @@ -200,6 +216,14 @@ inline uf::Vector& uf::Vector::operator /=( const uf::Vector& vec return uf::vector::divide( this->m_pod, vector.data() ); } template // Multiplication set with scalar +inline uf::Vector& uf::Vector::operator +=( T scalar ) { + return uf::vector::add( this->m_pod, scalar ); +} +template // Multiplication set with scalar +inline uf::Vector& uf::Vector::operator -=( T scalar ) { + return uf::vector::subtract( this->m_pod, scalar ); +} +template // Multiplication set with scalar inline uf::Vector& uf::Vector::operator *=( T scalar ) { return uf::vector::multiply( this->m_pod, scalar ); } diff --git a/engine/inc/uf/utils/math/vector/pod.inl b/engine/inc/uf/utils/math/vector/pod.inl index 59ca29f5..26d7231e 100644 --- a/engine/inc/uf/utils/math/vector/pod.inl +++ b/engine/inc/uf/utils/math/vector/pod.inl @@ -1,4 +1,4 @@ -#if __GNUC__ +#if !__clang__ && __GNUC__ #pragma GCC push_options #pragma GCC optimize ("unroll-loops") #endif @@ -20,7 +20,7 @@ template pod::Vector /*UF_API*/ uf::vector::copy( const pod::Vector& v ) { return v; } template pod::Vector /*UF_API*/ uf::vector::cast( const U& from ) { - pod::Vector to; + alignas(16) pod::Vector to; #pragma unroll // GCC unroll N for ( uint_fast8_t i = 0; i < N && i < U::size; ++i ) to[i] = from[i]; @@ -45,29 +45,51 @@ T /*UF_API*/ uf::vector::add( const T& left, const T& right ) { #if UF_USE_SIMD return uf::simd::add( left, right ); #endif - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = left[i] + right[i]; return res; } +template // Multiplies this vector by a scalar +T /*UF_API*/ uf::vector::add( const T& vector, const typename T::type_t& scalar ) { +#if UF_USE_SIMD + return uf::simd::add( vector, scalar ); +#endif + alignas(16) T res; + #pragma unroll // GCC unroll T::size + for ( uint_fast8_t i = 0; i < T::size; ++i ) + res[i] = vector[i] + scalar; + return res; +} template // Subtracts two vectors of same type and size together T /*UF_API*/ uf::vector::subtract( const T& left, const T& right ) { #if UF_USE_SIMD return uf::simd::sub( left, right ); #endif - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = left[i] - right[i]; return res; } +template // Multiplies this vector by a scalar +T /*UF_API*/ uf::vector::subtract( const T& vector, const typename T::type_t& scalar ) { +#if UF_USE_SIMD + return uf::simd::sub( vector, scalar ); +#endif + alignas(16) T res; + #pragma unroll // GCC unroll T::size + for ( uint_fast8_t i = 0; i < T::size; ++i ) + res[i] = vector[i] - scalar; + return res; +} template // Multiplies two vectors of same type and size together T /*UF_API*/ uf::vector::multiply( const T& left, const T& right ) { #if UF_USE_SIMD return uf::simd::mul( left, right ); #endif - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = left[i] * right[i]; @@ -78,7 +100,7 @@ T /*UF_API*/ uf::vector::multiply( const T& vector, const typename T::type_t& sc #if UF_USE_SIMD return uf::simd::mul( vector, scalar ); #endif - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = vector[i] * scalar; @@ -89,13 +111,13 @@ T /*UF_API*/ uf::vector::divide( const T& left, const T& right ) { #if UF_USE_SIMD return uf::simd::div( left, right ); #elif UF_ENV_DREAMCAST - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = MATH_Fast_Divide(left[i], right[i]); return res; #else - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = left[i] / right[i]; @@ -107,13 +129,13 @@ T /*UF_API*/ uf::vector::divide( const T& vector, const typename T::type_t& scal #if UF_USE_SIMD return uf::simd::div( vector, scalar ); #elif UF_ENV_DREAMCAST - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = MATH_Fast_Divide(vector[i], scalar); return res; #else - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = vector[i] / scalar; @@ -141,7 +163,7 @@ T /*UF_API*/ uf::vector::negate( const T& vector ) { #if UF_USE_SIMD return uf::simd::mul( vector, -1.f ); #endif - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = -vector[i]; @@ -158,6 +180,16 @@ T& /*UF_API*/ uf::vector::add( T& left, const T& right ) { left[i] += right[i]; return left; } +template // Multiplies this vector by a scalar +T& /*UF_API*/ uf::vector::add( T& vector, const typename T::type_t& scalar ) { +#if UF_USE_SIMD + return vector = uf::vector::add( (const T&) vector, scalar ); +#endif + #pragma unroll // GCC unroll T::size + for ( uint_fast8_t i = 0; i < T::size; ++i ) + vector[i] += scalar; + return vector; +} template // Subtracts two vectors of same type and size together T& /*UF_API*/ uf::vector::subtract( T& left, const T& right ) { #if UF_USE_SIMD @@ -168,6 +200,16 @@ T& /*UF_API*/ uf::vector::subtract( T& left, const T& right ) { left[i] -= right[i]; return left; } +template // Multiplies this vector by a scalar +T& /*UF_API*/ uf::vector::subtract( T& vector, const typename T::type_t& scalar ) { +#if UF_USE_SIMD + return vector = uf::vector::subtract( (const T&) vector, scalar ); +#endif + #pragma unroll // GCC unroll T::size + for ( uint_fast8_t i = 0; i < T::size; ++i ) + vector[i] -= scalar; + return vector; +} template // Multiplies two vectors of same type and size together T& /*UF_API*/ uf::vector::multiply( T& left, const T& right ) { #if UF_USE_SIMD @@ -243,7 +285,7 @@ T /*UF_API*/ uf::vector::lerp( const T& from, const T& to, double delta, bool cl delta = fmax( 0, fmin(1,delta) ); // from + ( ( to - from ) * delta ) #if UF_ENV_DREAMCAST - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = MATH_Lerp( from[i], to[i], delta ); @@ -258,7 +300,7 @@ T /*UF_API*/ uf::vector::lerp( const T& from, const T& to, const T& delta, bool //delta = fmax( 0, fmin(1,delta) ); // from + ( ( to - from ) * delta ) #if UF_ENV_DREAMCAST - T res; + alignas(16) T res; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < T::size; ++i ) res[i] = MATH_Lerp( from[i], to[i], delta[i] ); @@ -294,13 +336,13 @@ T /*UF_API*/ uf::vector::mix( const T& x, const T& y, double a, bool clamp ) { template // Compute the distance between two vectors (doesn't sqrt) typename T::type_t /*UF_API*/ uf::vector::distanceSquared( const T& a, const T& b ) { #if UF_ENV_DREAMCAST - T delta = uf::vector::subtract(b, a); + alignas(16) T delta = uf::vector::subtract(b, a); return MATH_Sum_of_Squares( UF_EZ_VEC4( delta, T::size ) ); #elif UF_USE_SIMD uf::simd::value delta = uf::simd::sub( b, a ); return uf::vector::sum( uf::simd::vector( uf::simd::mul( delta, delta ) ) ); #else - T delta = uf::vector::subtract(b, a); + alignas(16) T delta = uf::vector::subtract(b, a); uf::vector::multiply( delta, delta ); return uf::vector::sum(delta); #endif @@ -335,8 +377,8 @@ T /*UF_API*/ uf::vector::normalize( const T& vector ) { template // Normalizes a vector void /*UF_API*/ uf::vector::orthonormalize( T& normal, T& tangent ) { normal = uf::vector::normalize( normal ); - T norm = normal; - T tan = uf::vector::normalize( tangent ); + alignas(16) T norm = normal; + alignas(16) T tan = uf::vector::normalize( tangent ); tangent = uf::vector::subtract( tan, uf::vector::multiply( norm, uf::vector::dot( norm, tan ) ) ); tangent = uf::vector::normalize( tangent ); } @@ -347,8 +389,8 @@ T /*UF_API*/ uf::vector::orthonormalize( const T& x, const T& y ) { template // Normalizes a vector T /*UF_API*/ uf::vector::cross( const T& a, const T& b ) { #if UF_USE_SIMD - uf::simd::value x = a; - uf::simd::value y = b; + uf::simd::value x = a; + uf::simd::value y = b; #if SSE_INSTR_SET >= 7 uf::simd::value tmp0 = _mm_shuffle_ps(y,y,_MM_SHUFFLE(3,0,2,1)); uf::simd::value tmp1 = _mm_shuffle_ps(x,x,_MM_SHUFFLE(3,0,2,1)); @@ -368,17 +410,19 @@ T /*UF_API*/ uf::vector::cross( const T& a, const T& b ) { #elif UF_ENV_DREAMCAST auto res = MATH_Cross_Product( a.x, a.y, a.z, b.x, b.y, b.z ); return *((T*) &res); -#endif - return T{ +#else + alignas(16) T res{ a.y * b.z - b.y * a.z, a.z * b.x - b.z * a.x, a.x * b.y - b.x * a.y - }; + } + return res; +#endif } template // Normalizes a vector -std::string /*UF_API*/ uf::vector::toString( const T& v ) { +uf::stl::string /*UF_API*/ uf::vector::toString( const T& v ) { uint_fast8_t size = T::size; - std::stringstream ss; + uf::stl::stringstream ss; ss << "Vector("; #pragma unroll // GCC unroll T::size for ( uint_fast8_t i = 0; i < size; ++i ) { @@ -435,6 +479,6 @@ pod::Vector /*UF_API*/ uf::vector::decode( const ext::json::Value& json, co } return v; } -#if __GNUC__ +#if !__clang__ && __GNUC__ #pragma GCC pop_options #endif \ No newline at end of file diff --git a/engine/inc/uf/utils/math/vector/redundancy.inl b/engine/inc/uf/utils/math/vector/redundancy.inl index 988870b1..d2a01267 100644 --- a/engine/inc/uf/utils/math/vector/redundancy.inl +++ b/engine/inc/uf/utils/math/vector/redundancy.inl @@ -30,6 +30,14 @@ inline pod::Vector pod::Vector::operator/( const pod::Vector& vec return uf::vector::divide( *this, vector ); } template // Multiplication with scalar +inline pod::Vector pod::Vector::operator+( T scalar ) const { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector pod::Vector::operator-( T scalar ) const { + return uf::vector::subtract( *this, scalar ); +} +template // Multiplication with scalar inline pod::Vector pod::Vector::operator*( T scalar ) const { return uf::vector::multiply( *this, scalar ); } @@ -54,6 +62,14 @@ inline pod::Vector& pod::Vector::operator /=( const pod::Vector& return uf::vector::divide( *this, vector ); } template // Multiplication set with scalar +inline pod::Vector& pod::Vector::operator +=( T scalar ) { + return uf::vector::add( *this, scalar ); +} +template // Multiplication set with scalar +inline pod::Vector& pod::Vector::operator -=( T scalar ) { + return uf::vector::subtract( *this, scalar ); +} +template // Multiplication set with scalar inline pod::Vector& pod::Vector::operator *=( T scalar ) { return uf::vector::multiply( *this, scalar ); } @@ -137,6 +153,14 @@ inline pod::Vector pod::Vector::operator/( const pod::Vector& vec return uf::vector::divide( *this, vector ); } template // Multiplication with scalar +inline pod::Vector pod::Vector::operator+( T scalar ) const { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector pod::Vector::operator-( T scalar ) const { + return uf::vector::subtract( *this, scalar ); +} +template // Multiplication with scalar inline pod::Vector pod::Vector::operator*( T scalar ) const { return uf::vector::multiply( *this, scalar ); } @@ -160,6 +184,14 @@ template // Division set between two vectors inline pod::Vector& pod::Vector::operator /=( const pod::Vector& vector ) { return uf::vector::divide( *this, vector ); } +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator +=( T scalar ) { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator -=( T scalar ) { + return uf::vector::subtract( *this, scalar ); +} template // Multiplication set with scalar inline pod::Vector& pod::Vector::operator *=( T scalar ) { return uf::vector::multiply( *this, scalar ); @@ -243,6 +275,14 @@ inline pod::Vector pod::Vector::operator/( const pod::Vector& vec return uf::vector::divide( *this, vector ); } template // Multiplication with scalar +inline pod::Vector pod::Vector::operator+( T scalar ) const { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector pod::Vector::operator-( T scalar ) const { + return uf::vector::subtract( *this, scalar ); +} +template // Multiplication with scalar inline pod::Vector pod::Vector::operator*( T scalar ) const { return uf::vector::multiply( *this, scalar ); } @@ -266,6 +306,14 @@ template // Division set between two vectors inline pod::Vector& pod::Vector::operator /=( const pod::Vector& vector ) { return uf::vector::divide( *this, vector ); } +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator+=( T scalar ) { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator-=( T scalar ) { + return uf::vector::subtract( *this, scalar ); +} template // Multiplication set with scalar inline pod::Vector& pod::Vector::operator *=( T scalar ) { return uf::vector::multiply( *this, scalar ); @@ -349,6 +397,14 @@ inline pod::Vector pod::Vector::operator/( const pod::Vector& vec return uf::vector::divide( *this, vector ); } template // Multiplication with scalar +inline pod::Vector pod::Vector::operator+( T scalar ) const { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector pod::Vector::operator-( T scalar ) const { + return uf::vector::subtract( *this, scalar ); +} +template // Multiplication with scalar inline pod::Vector pod::Vector::operator*( T scalar ) const { return uf::vector::multiply( *this, scalar ); } @@ -372,6 +428,14 @@ template // Division set between two vectors inline pod::Vector& pod::Vector::operator /=( const pod::Vector& vector ) { return uf::vector::divide( *this, vector ); } +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator +=( T scalar ) { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator -=( T scalar ) { + return uf::vector::subtract( *this, scalar ); +} template // Multiplication set with scalar inline pod::Vector& pod::Vector::operator *=( T scalar ) { return uf::vector::multiply( *this, scalar ); @@ -459,6 +523,14 @@ template // Subtraction between two vectors inline pod::Vector pod::Vector::operator-( const pod::Vector& vector ) const { return uf::vector::subtract( *this, vector ); } +template // Multiplication with scalar +inline pod::Vector pod::Vector::operator+( T scalar ) const { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector pod::Vector::operator-( T scalar ) const { + return uf::vector::subtract( *this, scalar ); +} template // Multiplication between two vectors inline pod::Vector pod::Vector::operator*( const pod::Vector& vector ) const { return uf::vector::multiply( *this, vector ); @@ -491,6 +563,14 @@ template // Division set between two vectors inline pod::Vector& pod::Vector::operator /=( const pod::Vector& vector ) { return uf::vector::divide( *this, vector ); } +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator+=( T scalar ) { + return uf::vector::add( *this, scalar ); +} +template // Multiplication with scalar +inline pod::Vector& pod::Vector::operator-=( T scalar ) { + return uf::vector::subtract( *this, scalar ); +} template // Multiplication set with scalar inline pod::Vector& pod::Vector::operator *=( T scalar ) { return uf::vector::multiply( *this, scalar ); @@ -560,7 +640,7 @@ namespace uf { Vector(T x, T y); // initializes POD to 'def' Vector(const Vector::pod_t& pod); // copies POD altogether Vector(const T components[1]); // copies data into POD from 'components' (typed as C array) - Vector(const std::vector& components); // copies data into POD from 'components' (typed as std::vector) + Vector(const uf::stl::vector& components); // copies data into POD from 'components' (typed as uf::stl::vector) // D-tor // Unneccesary // POD access @@ -600,7 +680,7 @@ namespace uf { inline uf::Vector& normalize(); // Normalizes a vector uf::Vector getNormalized() const; // Return a normalized vector - inline std::string toString() const; + inline uf::stl::string toString() const; // Overloaded ops // Accessing via subscripts T& operator[](std::size_t i); @@ -651,7 +731,7 @@ namespace uf { Vector(T x, T y); // initializes POD to 'def' Vector(const Vector::pod_t& pod); // copies POD altogether Vector(const T components[2]); // copies data into POD from 'components' (typed as C array) - Vector(const std::vector& components); // copies data into POD from 'components' (typed as std::vector) + Vector(const uf::stl::vector& components); // copies data into POD from 'components' (typed as uf::stl::vector) // D-tor // Unneccesary // POD access @@ -691,7 +771,7 @@ namespace uf { inline uf::Vector& normalize(); // Normalizes a vector uf::Vector getNormalized() const; // Return a normalized vector - inline std::string toString() const; + inline uf::stl::string toString() const; // Overloaded ops // Accessing via subscripts T& operator[](std::size_t i); @@ -747,7 +827,7 @@ namespace uf { Vector(T x, T y, T z); // initializes POD to 'def' Vector(const Vector::pod_t& pod); // copies POD altogether Vector(const T components[3]); // copies data into POD from 'components' (typed as C array) - Vector(const std::vector& components); // copies data into POD from 'components' (typed as std::vector) + Vector(const uf::stl::vector& components); // copies data into POD from 'components' (typed as uf::stl::vector) // D-tor // Unneccesary // POD access @@ -787,7 +867,7 @@ namespace uf { inline uf::Vector& normalize(); // Normalizes a vector uf::Vector getNormalized() const; // Return a normalized vector - inline std::string toString() const; + inline uf::stl::string toString() const; // Overloaded ops // Accessing via subscripts T& operator[](std::size_t i); @@ -845,7 +925,7 @@ namespace uf { Vector(T x, T y, T z, T w); // initializes POD to 'def' Vector(const Vector::pod_t& pod); // copies POD altogether Vector(const T components[4]); // copies data into POD from 'components' (typed as C array) - Vector(const std::vector& components); // copies data into POD from 'components' (typed as std::vector) + Vector(const uf::stl::vector& components); // copies data into POD from 'components' (typed as uf::stl::vector) // D-tor // Unneccesary // POD access @@ -885,7 +965,7 @@ namespace uf { inline uf::Vector& normalize(); // Normalizes a vector uf::Vector getNormalized() const; // Return a normalized vector - inline std::string toString() const; + inline uf::stl::string toString() const; // Overloaded ops // Accessing via subscripts T& operator[](std::size_t i); @@ -935,8 +1015,8 @@ template // copies data into POD from 'components' (ty uf::Vector::Vector(const T components[1]) { this->set(&components[0]); } -template // copies data into POD from 'components' (typed as std::vector) -uf::Vector::Vector(const std::vector& components) { +template // copies data into POD from 'components' (typed as uf::stl::vector) +uf::Vector::Vector(const uf::stl::vector& components) { if ( components.size() >= 1 ) this->set(&components[0]); } // D-tor @@ -1067,7 +1147,7 @@ uf::Vector uf::Vector::getNormalized() const { return uf::vector::normalize( this->m_pod ); } template // Return a string -std::string uf::Vector::toString() const { +uf::stl::string uf::Vector::toString() const { return uf::vector::toString( this->m_pod ); } // Overloaded ops @@ -1178,8 +1258,8 @@ template // copies data into POD from 'components' (ty uf::Vector::Vector(const T components[2]) { this->set(&components[0]); } -template // copies data into POD from 'components' (typed as std::vector) -uf::Vector::Vector(const std::vector& components) { +template // copies data into POD from 'components' (typed as uf::stl::vector) +uf::Vector::Vector(const uf::stl::vector& components) { if ( components.size() >= 2 ) this->set(&components[0]); } // D-tor @@ -1310,7 +1390,7 @@ uf::Vector uf::Vector::getNormalized() const { return uf::vector::normalize( this->m_pod ); } template // Return a string -std::string uf::Vector::toString() const { +uf::stl::string uf::Vector::toString() const { return uf::vector::toString( this->m_pod ); } // Overloaded ops @@ -1423,8 +1503,8 @@ template // copies data into POD from 'components' (ty uf::Vector::Vector(const T components[3]) { this->set(&components[0]); } -template // copies data into POD from 'components' (typed as std::vector) -uf::Vector::Vector(const std::vector& components) { +template // copies data into POD from 'components' (typed as uf::stl::vector) +uf::Vector::Vector(const uf::stl::vector& components) { if ( components.size() >= 3 ) this->set(&components[0]); } // D-tor @@ -1555,7 +1635,7 @@ uf::Vector uf::Vector::getNormalized() const { return uf::vector::normalize( this->m_pod ); } template // Return a string -std::string uf::Vector::toString() const { +uf::stl::string uf::Vector::toString() const { return uf::vector::toString( this->m_pod ); } // Overloaded ops @@ -1669,8 +1749,8 @@ template // copies data into POD from 'components' (ty uf::Vector::Vector(const T components[4]) { this->set(&components[0]); } -template // copies data into POD from 'components' (typed as std::vector) -uf::Vector::Vector(const std::vector& components) { +template // copies data into POD from 'components' (typed as uf::stl::vector) +uf::Vector::Vector(const uf::stl::vector& components) { if ( components.size() >= 4 ) this->set(&components[0]); } // D-tor @@ -1801,7 +1881,7 @@ uf::Vector uf::Vector::getNormalized() const { return uf::vector::normalize( this->m_pod ); } template // Return a string -std::string uf::Vector::toString() const { +uf::stl::string uf::Vector::toString() const { return uf::vector::toString( this->m_pod ); } // Overloaded ops diff --git a/engine/inc/uf/utils/math/vector/simd.h b/engine/inc/uf/utils/math/vector/simd.h index 2638e123..bdb20a4a 100644 --- a/engine/inc/uf/utils/math/vector/simd.h +++ b/engine/inc/uf/utils/math/vector/simd.h @@ -35,7 +35,7 @@ namespace uf { }; template - class UF_API value { + class /**UF_API**/ alignas(16) value { private: // __m128 m_value; typedef typename traits::value value_type; diff --git a/engine/inc/uf/utils/math/vector/simd.inl b/engine/inc/uf/utils/math/vector/simd.inl index fff7a968..9544f595 100644 --- a/engine/inc/uf/utils/math/vector/simd.inl +++ b/engine/inc/uf/utils/math/vector/simd.inl @@ -1,3 +1,5 @@ +#include + template inline uf::simd::value::value() {} template @@ -82,14 +84,28 @@ inline pod::Vector uf::simd::vector( const uf::simd::value v ){ } inline uf::simd::value /*UF_API*/ uf::simd::load( const float* f ) { -#if 1 - return _mm_loadu_ps(f); -#else +#if UF_VECTOR_ALIGNED return _mm_load_ps(f); +#else + if ( uf::aligned(f, 16) ) return _mm_load_ps(f); +// UF_MSG_DEBUG( "Realigning... " << uf::aligned(f, 16) << " (" << f[0] << ", " << f[1] << ", " << f[2] << ", " << f[3] << ")" ); + + alignas(16) float s[4]; + memcpy( &s[0], f, sizeof(float) * 4 ); + return _mm_loadu_ps(s); #endif } inline void /*UF_API*/ uf::simd::store( uf::simd::value v, float* f ) { - _mm_store_ps(f, v); +#if UF_VECTOR_ALIGNED + return _mm_store_ps(f, v); +#else + if ( uf::aligned(f, 16) ) return _mm_store_ps(f, v); +// UF_MSG_DEBUG( "Realigning... " << uf::aligned(f, 16) << " (" << f[0] << ", " << f[1] << ", " << f[2] << ", " << f[3] << ")" ); + + alignas(16) float s[4]; + _mm_store_ps(&s[0], v); + memcpy( f, &s[0], sizeof(float) * 4 ); +#endif } inline uf::simd::value /*UF_API*/ uf::simd::set( float f ) { return _mm_set1_ps(f); @@ -139,9 +155,32 @@ inline float /*UF_API*/ uf::simd::dot( uf::simd::value x, uf::simd::value #endif } inline uf::simd::value /*UF_API*/ uf::simd::load( const int32_t* f ) { +#if SSE_INSTR_SET >= 3 +#if UF_VECTOR_ALIGNED + return _mm_load_si128(f); +#else + if ( uf::aligned(f, 16) ) return _mm_load_si128(f); + + alignas(16) int32_t s[4]; + memcpy( &s[0], f, sizeof(int32_t) * 4 ); + return _mm_load_si128(s); +#endif +#else return uf::simd::value( f[0], f[1], f[2], f[3] ); +#endif } inline void /*UF_API*/ uf::simd::store( uf::simd::value v, int32_t* f ) { +#if SSE_INSTR_SET >= 3 +#if UF_VECTOR_ALIGNED + return _mm_store_si128(f, v); +#else + if ( uf::aligned(f, 16) ) return _mm_store_si128(f, v); + + alignas(16) int32_t s[4]; + _mm_store_si128(&s[0], v); + memcpy( f, &s[0], sizeof(int32_t) * 4 ); +#endif +#else union { __m128i x; int32_t y[4]; @@ -151,6 +190,7 @@ inline void /*UF_API*/ uf::simd::store( uf::simd::value v, int32_t* f ) f[1] = kludge.y[1]; f[2] = kludge.y[2]; f[3] = kludge.y[3]; +#endif } inline uf::simd::value /*UF_API*/ uf::simd::set( int32_t f ) { return _mm_set1_epi32(f); @@ -206,9 +246,32 @@ inline int32_t /*UF_API*/ uf::simd::dot( uf::simd::value x, uf::simd::v } inline uf::simd::value /*UF_API*/ uf::simd::load( const uint32_t* f ) { +#if SSE_INSTR_SET >= 3 +#if UF_VECTOR_ALIGNED + return _mm_load_si128(f); +#else + if ( uf::aligned(f, 16) ) return _mm_load_si128(f); + + alignas(16) uint32_t s[4]; + memcpy( &s[0], f, sizeof(uint32_t) * 4 ); + return _mm_load_si128(s); +#endif +#else return uf::simd::value( f[0], f[1], f[2], f[3] ); +#endif } inline void /*UF_API*/ uf::simd::store( uf::simd::value v, uint32_t* f ) { +#if SSE_INSTR_SET >= 3 +#if UF_VECTOR_ALIGNED + return _mm_store_si128(f, v); +#else + if ( uf::aligned(f, 16) ) return _mm_store_si128(f, v); + + alignas(16) uint32_t s[4]; + _mm_store_si128(&s[0], v); + memcpy( f, &s[0], sizeof(uint32_t) * 4 ); +#endif +#else union { __m128i x; uint32_t y[4]; @@ -218,6 +281,7 @@ inline void /*UF_API*/ uf::simd::store( uf::simd::value v, uint32_t* f f[1] = kludge.y[1]; f[2] = kludge.y[2]; f[3] = kludge.y[3]; +#endif } inline uf::simd::value /*UF_API*/ uf::simd::set( uint32_t f ) { #if 0 diff --git a/engine/inc/uf/utils/math/vector/vector.inl b/engine/inc/uf/utils/math/vector/vector.inl index 8edb02e3..b5887cc7 100644 --- a/engine/inc/uf/utils/math/vector/vector.inl +++ b/engine/inc/uf/utils/math/vector/vector.inl @@ -2,7 +2,7 @@ #include "class.inl" template -std::string /*UF_API*/ uf::string::toString( const pod::Vector& v ) { +uf::stl::string /*UF_API*/ uf::string::toString( const pod::Vector& v ) { return uf::vector::toString(v); } diff --git a/engine/inc/uf/utils/memory/alignment.h b/engine/inc/uf/utils/memory/alignment.h new file mode 100644 index 00000000..26b631ed --- /dev/null +++ b/engine/inc/uf/utils/memory/alignment.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace uf { + inline bool aligned(const void* ptr, uintptr_t alignment) noexcept; + template inline bool aligned(const void* ptr) noexcept; + + inline uintptr_t alignment(const void* ptr, uintptr_t a) noexcept; + template inline uintptr_t alignment(const void* ptr) noexcept; + + inline uint8_t* realign(uint8_t* ptr, uintptr_t a) noexcept; + template inline uint8_t* realign(uint8_t* ptr) noexcept; +} + +#include "alignment.inl" \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/alignment.inl b/engine/inc/uf/utils/memory/alignment.inl new file mode 100644 index 00000000..8fad7423 --- /dev/null +++ b/engine/inc/uf/utils/memory/alignment.inl @@ -0,0 +1,22 @@ +inline bool uf::aligned(const void* ptr, uintptr_t alignment) noexcept { + return !( ((uintptr_t) ptr) % alignment ); +} +template inline bool uf::aligned(const void* ptr) noexcept { + return uf::aligned( ptr, alignof(T) ); +} + +inline uintptr_t uf::alignment(const void* ptr, uintptr_t a) noexcept { + return ((uintptr_t) ptr) % a; +} +template inline uintptr_t uf::alignment(const void* ptr) noexcept { + return uf::alignment( ptr, alignof(T) ); +} + +inline uint8_t* uf::realign(uint8_t* ptr, uintptr_t a) noexcept { + const uintptr_t r = uf::alignment(ptr, a); + if ( r != 0 ) ptr += a - r; + return ptr; +} +template inline uint8_t* uf::realign(uint8_t* ptr) noexcept { + return uf::realign( ptr, alignof(T) ); +} \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/allocator.h b/engine/inc/uf/utils/memory/allocator.h new file mode 100644 index 00000000..fa523053 --- /dev/null +++ b/engine/inc/uf/utils/memory/allocator.h @@ -0,0 +1,67 @@ +#pragma once + +#include + +#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE 1 +namespace uf { + namespace allocator { + extern UF_API bool useMemoryPool; + void* UF_API allocate( size_t n ); + void UF_API deallocate( void* p, size_t = 0 ); + } + + template + class Allocator { + public: + using value_type = T; + + template struct rebind {typedef Allocator other;}; + using pointer = value_type*; + using const_pointer = typename std::pointer_traits::template rebind; + using void_pointer = typename std::pointer_traits::template rebind; + using const_void_pointer = typename std::pointer_traits::template rebind; + using difference_type = typename std::pointer_traits::difference_type; + using size_type = std::make_unsigned_t; + + Allocator() noexcept {} // not required, unless used + template Allocator(Allocator const&) noexcept {} + + value_type* allocate( size_t n ); + void deallocate( value_type* p, size_t = 0 ) noexcept; + +// value_type* +// allocate(std::size_t n, const_void_pointer) { +// return allocate(n); +// } + +// template void construct(U* p, Args&& ...args) { +// ::new(p) U(std::forward(args)...); +// } + +// template void destroy(U* p) noexcept { +// p->~U(); +// } + +// size_t max_size() const noexcept { return std::numeric_limits::max(); } +// Allocator select_on_container_copy_construction() const { return *this; } + + using propagate_on_container_copy_assignment = std::false_type; + using propagate_on_container_move_assignment = std::false_type; + using propagate_on_container_swap = std::false_type; + using is_always_equal = std::is_empty; + + }; + + template + bool operator==(uf::Allocator const&, uf::Allocator const&) noexcept { + return true; + } + + template + bool operator!=(uf::Allocator const& x, uf::Allocator const& y) noexcept { + return !(x == y); + } +} + + +#include "allocator.inl" \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/allocator.inl b/engine/inc/uf/utils/memory/allocator.inl new file mode 100644 index 00000000..8f98bdf4 --- /dev/null +++ b/engine/inc/uf/utils/memory/allocator.inl @@ -0,0 +1,10 @@ +template +typename uf::Allocator::value_type* uf::Allocator::allocate( size_t n ) { +// return static_cast::value_type*>(::operator new (n*sizeof(typename uf::Allocator::value_type))); + return static_cast::value_type*>( uf::allocator::allocate( n * sizeof(typename uf::Allocator::value_type) ) ); +} +template +void uf::Allocator::deallocate( typename uf::Allocator::value_type* p, size_t size ) noexcept { +// ::operator delete(p); + return uf::allocator::deallocate( (void*) p, size ); +} \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/deque.h b/engine/inc/uf/utils/memory/deque.h new file mode 100644 index 00000000..c7dbddf1 --- /dev/null +++ b/engine/inc/uf/utils/memory/deque.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include "./allocator.h" + +#include + +namespace uf { + namespace stl { + template< + class T, + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE + class Allocator = std::allocator + #else + class Allocator = uf::Allocator + #endif + > + using deque = std::deque; + } +} \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/pool.h b/engine/inc/uf/utils/memory/pool.h new file mode 100644 index 00000000..d130355c --- /dev/null +++ b/engine/inc/uf/utils/memory/pool.h @@ -0,0 +1,100 @@ +#pragma once + +#include +#include +#include +#include +#include + +#define UF_MEMORYPOOL_INVALID_MALLOC 1 +#define UF_MEMORYPOOL_INVALID_FREE 1 + +namespace pod { + struct UF_API Userdata; + + struct UF_API Allocation { + size_t index = 0; + size_t size = 0; + void* pointer = NULL; + }; + + struct UF_API MemoryPool { + typedef std::vector allocations_t; + + size_t size; + uint8_t* pool; + + std::mutex mutex; + allocations_t allocations; + allocations_t cachedFreeAllocations; + }; +} + +namespace uf { + namespace memoryPool { + extern UF_API bool globalOverride; + extern UF_API bool subPool; + extern UF_API uint8_t alignment; + + size_t UF_API size( const pod::MemoryPool& ); + size_t UF_API allocated( const pod::MemoryPool& ); + uf::stl::string UF_API stats( const pod::MemoryPool& ); + void UF_API initialize( pod::MemoryPool&, size_t ); + void UF_API destroy( pod::MemoryPool& ); + + pod::Allocation UF_API allocate( pod::MemoryPool&, void*, size_t, size_t alignment = uf::memoryPool::alignment ); + void* UF_API alloc( pod::MemoryPool&, void*, size_t, size_t alignment = uf::memoryPool::alignment ); + inline void* alloc( pod::MemoryPool& pool, size_t size, void* data = NULL, size_t alignment = uf::memoryPool::alignment ) { return uf::memoryPool::alloc(pool, data, size, alignment); } + + pod::Allocation& UF_API fetch( pod::MemoryPool&, size_t, size_t = 0 ); + bool UF_API exists( pod::MemoryPool&, void*, size_t = 0 ); + bool UF_API free( pod::MemoryPool&, void*, size_t = 0 ); + + const pod::MemoryPool::allocations_t& UF_API allocations( const pod::MemoryPool& ); + + template T& alloc( pod::MemoryPool&, const T& = T()/*, size_t alignment = uf::memoryPool::alignment*/ ); + template pod::Allocation allocate( pod::MemoryPool&, const T& = T()/*, size_t alignment = uf::memoryPool::alignment*/ ); + template bool exists( pod::MemoryPool&, const T& = T() ); + template bool free( pod::MemoryPool&, const T& = T() ); + } +} + +namespace uf { + class UF_API MemoryPool { + protected: + pod::MemoryPool m_pod; + public: + MemoryPool( size_t = 0 ); + ~MemoryPool(); + + inline size_t size() const; + inline size_t allocated() const; + inline uf::stl::string stats() const; + inline void initialize( size_t size ); + inline void destroy(); + + inline pod::Allocation allocate( void* data, size_t size/*, size_t alignment = uf::memoryPool::alignment*/ ); + inline void* alloc( void* data, size_t size/*, size_t alignment = uf::memoryPool::alignment*/ ); + inline void* alloc( size_t size, void* data = NULL/*, size_t alignment = uf::memoryPool::alignment*/ ); + inline pod::Allocation& fetch( size_t index, size_t size = 0 ); + inline bool exists( void* data, size_t size = 0 ); + inline bool free( void* data, size_t size = 0 ); + + inline const pod::MemoryPool::allocations_t& allocations() const; + inline pod::MemoryPool& data(); + inline const pod::MemoryPool& data() const; + + template inline T& alloc( const T& data = T()/*, size_t alignment = uf::memoryPool::alignment*/ ); + template inline pod::Allocation allocate( const T& data = T()/*, size_t alignment = uf::memoryPool::alignment*/ ); + template inline bool exists( const T& data = T() ); + template inline bool free( const T& data = T() ); + }; +} + +namespace uf { + namespace memoryPool { + extern UF_API uf::MemoryPool global; + } +} + +#include "pool.inl" \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/pool.inl b/engine/inc/uf/utils/memory/pool.inl new file mode 100644 index 00000000..9d1ff9df --- /dev/null +++ b/engine/inc/uf/utils/memory/pool.inl @@ -0,0 +1,57 @@ +template +T& uf::memoryPool::alloc( pod::MemoryPool& pool, const T& data/*, size_t alignment*/ ) { + auto allocation = uf::memoryPool::allocate( pool, nullptr, sizeof(data), uf::memoryPool::alignment == 0 ? alignof(T) : uf::memoryPool::alignment ); + union { + uint8_t* from; + T* to; + } kludge; + kludge.from = (uint8_t*) allocation.pointer; + ::new (kludge.to) T(data); + return *kludge.to; +} +template +pod::Allocation uf::memoryPool::allocate( pod::MemoryPool& pool, const T& data/*, size_t alignment*/ ) { + auto allocation = uf::memoryPool::allocate( pool, nullptr, sizeof(data), uf::memoryPool::alignment == 0 ? alignof(T) : uf::memoryPool::alignment ); + if ( !allocation.pointer ) return allocation; + union { + uint8_t* from; + T* to; + } kludge; + kludge.from = (uint8_t*) allocation.pointer; + ::new (kludge.to) T(data); + return allocation; +} +template +bool uf::memoryPool::exists( pod::MemoryPool& pool, const T& data ) { + if ( std::is_pointer::value ) return uf::memoryPool::exists( pool, (void*) data ); + return uf::memoryPool::exists( pool, (void*) &data, sizeof(data) ); +// return uf::memoryPool::exists( pool, (void*) (std::is_pointer::value ? data : &data), sizeof(data) ); +} +template +bool uf::memoryPool::free( pod::MemoryPool& pool, const T& data ) { + if ( std::is_pointer::value ) return uf::memoryPool::free( pool, (void*) data ); + return uf::memoryPool::free( pool, (void*) &data, sizeof(data) ); +// return uf::memoryPool::free( pool, (void*) (std::is_pointer::value ? data : &data), sizeof(data) ); +} + +size_t uf::MemoryPool::size() const { return uf::memoryPool::size( m_pod ); } +size_t uf::MemoryPool::allocated() const { return uf::memoryPool::allocated( m_pod ); } +uf::stl::string uf::MemoryPool::stats() const { return uf::memoryPool::stats( m_pod ); } +void uf::MemoryPool::initialize( size_t size ) { return uf::memoryPool::initialize( m_pod, size ); } +void uf::MemoryPool::destroy() { return uf::memoryPool::destroy( m_pod ); } + +pod::Allocation uf::MemoryPool::allocate( void* data, size_t size/*, size_t alignment*/ ) { return uf::memoryPool::allocate( m_pod, data, size/*, alignment*/ ); } +void* uf::MemoryPool::alloc( void* data, size_t size/*, size_t alignment*/ ) { return uf::memoryPool::alloc( m_pod, data, size/*, alignment*/ ); } +void* uf::MemoryPool::alloc( size_t size, void* data/*, size_t alignment*/ ) { return uf::memoryPool::alloc( m_pod, data, size/*, alignment*/ ); } +pod::Allocation& uf::MemoryPool::fetch( size_t index, size_t size ) { return uf::memoryPool::fetch( m_pod, index, size ); } +bool uf::MemoryPool::exists( void* data, size_t size ) { return uf::memoryPool::exists( m_pod, data, size ); } +bool uf::MemoryPool::free( void* data, size_t size ) { return uf::memoryPool::free( m_pod, data, size ); } + +const pod::MemoryPool::allocations_t& uf::MemoryPool::allocations() const { return uf::memoryPool::allocations( m_pod ); } +inline pod::MemoryPool& uf::MemoryPool::data() { return m_pod; } +inline const pod::MemoryPool& uf::MemoryPool::data() const { return m_pod; } + +template T& uf::MemoryPool::alloc( const T& data/*, size_t alignment*/ ) { return uf::memoryPool::alloc( m_pod, data/*, alignment*/ ); } +template pod::Allocation uf::MemoryPool::allocate( const T& data/*, size_t alignment*/ ) { return uf::memoryPool::allocate( m_pod, data/*, alignment*/ ); } +template bool uf::MemoryPool::exists( const T& data ) { return uf::memoryPool::exists( m_pod, data ); } +template bool uf::MemoryPool::free( const T& data ) { return uf::memoryPool::free( m_pod, data ); } \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/queue.h b/engine/inc/uf/utils/memory/queue.h new file mode 100644 index 00000000..9a7837b7 --- /dev/null +++ b/engine/inc/uf/utils/memory/queue.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include "./allocator.h" +#include "./deque.h" + +#include + +namespace uf { + namespace stl { + template< + class T, + class Container = uf::stl::deque + > + using queue = std::queue; + } +} \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/string.h b/engine/inc/uf/utils/memory/string.h new file mode 100644 index 00000000..9b78cf5f --- /dev/null +++ b/engine/inc/uf/utils/memory/string.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "./allocator.h" + +#include + +namespace uf { + namespace stl { + template< + class CharT, + class Traits = std::char_traits, + class Allocator = std::allocator //uf::Allocator + > + using basic_string = std::basic_string; + using string = uf::stl::basic_string; + + template< + class CharT, + class Traits = std::char_traits, + class Allocator = std::allocator //uf::Allocator + > + using basic_stringstream = std::basic_stringstream; + using stringstream = uf::stl::basic_stringstream; + } +} \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/unordered_map.h b/engine/inc/uf/utils/memory/unordered_map.h new file mode 100644 index 00000000..ed84f1fc --- /dev/null +++ b/engine/inc/uf/utils/memory/unordered_map.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include "./allocator.h" + +#include + +namespace uf { + namespace stl { + template< + class Key, + class T, + class Hash = std::hash, + class KeyEqual = std::equal_to, + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE + class Allocator = std::allocator> + #else + class Allocator = uf::Allocator> + #endif + > + using unordered_map = std::unordered_map; + } +} \ No newline at end of file diff --git a/engine/inc/uf/utils/memory/vector.h b/engine/inc/uf/utils/memory/vector.h new file mode 100644 index 00000000..1f241379 --- /dev/null +++ b/engine/inc/uf/utils/memory/vector.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include "./allocator.h" + +#include + +namespace uf { + namespace stl { + template< + class T, + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE + class Allocator = std::allocator + #else + class Allocator = uf::Allocator + #endif + > + using vector = std::vector; + } +} \ No newline at end of file diff --git a/engine/inc/uf/utils/mempool/mempool.h b/engine/inc/uf/utils/mempool/mempool.h deleted file mode 100644 index 51315ef8..00000000 --- a/engine/inc/uf/utils/mempool/mempool.h +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#define UF_MEMORYPOOL_MUTEX 1 -#define UF_MEMORYPOOL_INVALID_MALLOC 0 -#define UF_MEMORYPOOL_INVALID_FREE 0 -#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE 0 -#define UF_MEMORYPOOL_CACHED_ALLOCATIONS 0 - -namespace pod { - struct UF_API Userdata; - struct UF_API Allocation { - size_t index = 0; - size_t size = 0; - void* pointer = NULL; - }; -} - -namespace uf { - class UF_API MemoryPool { - protected: - size_t m_size; - uint8_t* m_pool; - std::mutex m_mutex; - - typedef std::vector allocations_t; - allocations_t m_allocations; - allocations_t m_cachedFreeAllocations; - public: - static bool globalOverride; - static bool subPool; - static MemoryPool global; - - MemoryPool( size_t = 0 ); - ~MemoryPool(); - - size_t size() const; - size_t allocated() const; - std::string stats() const; - void initialize( size_t ); - void destroy(); - - pod::Allocation allocate( void*, size_t ); - void* alloc( void*, size_t ); - inline void* alloc( size_t size, void* data = NULL ) { return alloc(data, size); } - pod::Allocation& fetch( size_t, size_t = 0 ); - bool exists( void*, size_t = 0 ); - bool free( void*, size_t = 0 ); - - template T& alloc( const T& = T() ); - template pod::Allocation allocate( const T& = T() ); - template bool exists( const T& = T() ); - template bool free( const T& = T() ); - - const allocations_t& allocations() const; - /* - struct Iterator { - uf::MemoryPool& pool; - pod::Allocation& allocation; - pod::Allocation& next; - pod::Allocation& prev; - }; - Iterator begin(); - Iterator end(); - */ - }; -} - -#include "mempool.inl" \ No newline at end of file diff --git a/engine/inc/uf/utils/mempool/mempool.inl b/engine/inc/uf/utils/mempool/mempool.inl deleted file mode 100644 index d6b92808..00000000 --- a/engine/inc/uf/utils/mempool/mempool.inl +++ /dev/null @@ -1,36 +0,0 @@ -#include - -template -T& uf::MemoryPool::alloc( const T& data ) { - auto allocation = this->allocate( data ); - union { - uint8_t* from; - T* to; - } kludge; - kludge.from = (uint8_t*) allocation.pointer; - return *kludge.to; -} -template -pod::Allocation uf::MemoryPool::allocate( const T& data ) { - auto allocation = this->allocate( NULL, sizeof(data) ); - if ( !allocation.pointer ) return allocation; - union { - uint8_t* from; - T* to; - } kludge; - kludge.from = (uint8_t*) allocation.pointer; - ::new (kludge.to) T(data); - return allocation; -} -template -bool uf::MemoryPool::exists( const T& data ) { - if ( std::is_pointer::value ) return this->exists( (void*) data ); - return this->exists( (void*) &data, sizeof(data) ); -// return this->exists( (void*) (std::is_pointer::value ? data : &data), sizeof(data) ); -} -template -bool uf::MemoryPool::free( const T& data ) { - if ( std::is_pointer::value ) return this->free( (void*) data ); - return this->free( (void*) &data, sizeof(data) ); -// return this->free( (void*) (std::is_pointer::value ? data : &data), sizeof(data) ); -} \ No newline at end of file diff --git a/engine/inc/uf/utils/mesh/grid.h b/engine/inc/uf/utils/mesh/grid.h index c05e2463..f732d1ca 100644 --- a/engine/inc/uf/utils/mesh/grid.h +++ b/engine/inc/uf/utils/mesh/grid.h @@ -14,13 +14,13 @@ namespace uf { size_t count = 0; uint32_t* indices = NULL; #else - std::vector indices; + uf::stl::vector indices; #endif }; pod::Vector3ui m_size = {1,1,1}; pod::Vector3f m_center = {}; pod::Vector3f m_extent = {}; - std::vector m_nodes; + uf::stl::vector m_nodes; void initialize( const pod::Vector3f&, const pod::Vector3f&, const pod::Vector3ui& ); void destroy(); @@ -44,10 +44,10 @@ namespace uf { void initialize( const uf::BaseMesh& mesh, const pod::Vector3ui& ); template - std::vector get() const; + uf::stl::vector get() const; template - const std::vector& get( const pod::Vector3f& ) const; + const uf::stl::vector& get( const pod::Vector3f& ) const; const pod::Vector3f& center() const; const pod::Vector3f& extent() const; diff --git a/engine/inc/uf/utils/mesh/grid.inl b/engine/inc/uf/utils/mesh/grid.inl index ae6b7528..66eb4d72 100644 --- a/engine/inc/uf/utils/mesh/grid.inl +++ b/engine/inc/uf/utils/mesh/grid.inl @@ -17,8 +17,8 @@ void uf::MeshGrid::initialize( const uf::BaseMesh& mesh, const pod::Vector3 max.y = std::max( position.z, max.y ); max.z = std::max( position.y, max.z ); } - pod::Vector3f center = (max + min) / 2; - pod::Vector3f extent = (max - min) / 2; + pod::Vector3f center = (max + min) * 0.5f; + pod::Vector3f extent = (max - min) * 0.5f; // pre-generate nodes initialize( center, extent, size ); // fill our nodes @@ -36,15 +36,15 @@ void uf::MeshGrid::initialize( const uf::BaseMesh& mesh, const pod::Vector3 } } -template -std::vector uf::MeshGrid::get() const { +template +uf::stl::vector uf::MeshGrid::get() const { #if 0 auto& node = get( point ); - std::vector indices(node.count); + uf::stl::vector indices(node.count); for ( size_t i = 0; i < node.count; ++i ) indices[i] = node.indices[i]; return indices; #else - std::vector indices; + uf::stl::vector indices; for ( auto& node : this->m_nodes ) { indices.insert( indices.end(), node.indices.begin(), node.indices.end() ); } @@ -52,11 +52,11 @@ std::vector uf::MeshGrid::get() const { #endif } -template -const std::vector& uf::MeshGrid::get( const pod::Vector3f& point ) const { +template +const uf::stl::vector& uf::MeshGrid::get( const pod::Vector3f& point ) const { #if 0 auto& node = get( point ); - std::vector indices(node.count); + uf::stl::vector indices(node.count); for ( size_t i = 0; i < node.count; ++i ) indices[i] = node.indices[i]; return indices; #else diff --git a/engine/inc/uf/utils/mesh/mesh.h b/engine/inc/uf/utils/mesh/mesh.h index 3f172494..f49d2a21 100644 --- a/engine/inc/uf/utils/mesh/mesh.h +++ b/engine/inc/uf/utils/mesh/mesh.h @@ -6,7 +6,7 @@ #include #include -#include +#include #if UF_USE_VULKAN namespace uf { @@ -26,8 +26,8 @@ namespace uf { typedef U index_t; typedef vertex_t vertices_t; typedef index_t indices_t; - std::vector vertices; - std::vector indices; + uf::stl::vector vertices; + uf::stl::vector indices; void initialize( size_t = SIZE_MAX ); void destroy(); diff --git a/engine/inc/uf/utils/mesh/mesh.inl b/engine/inc/uf/utils/mesh/mesh.inl index 6b14ba80..9ee0d637 100644 --- a/engine/inc/uf/utils/mesh/mesh.inl +++ b/engine/inc/uf/utils/mesh/mesh.inl @@ -7,13 +7,13 @@ void uf::BaseMesh::initialize( size_t o ) { template void uf::BaseMesh::expand( bool check ) { if ( this->indices.empty() ) return; - std::vector _vertices = std::move( this->vertices ); + uf::stl::vector _vertices = std::move( this->vertices ); this->vertices.clear(); this->vertices.reserve( this->indices.size() ); if ( !check ) { for ( auto& index : this->indices ) this->vertices.emplace_back( _vertices[index] ); } else { - std::vector cache; + uf::stl::vector cache; bool valid = true; cache.reserve(3); for ( auto& index : this->indices ) { diff --git a/engine/inc/uf/utils/noise/noise.h b/engine/inc/uf/utils/noise/noise.h index 56f5e90d..f125e7b3 100644 --- a/engine/inc/uf/utils/noise/noise.h +++ b/engine/inc/uf/utils/noise/noise.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ namespace uf { class UF_API PerlinNoise { protected: std::size_t m_seed; - std::vector m_permutations; + uf::stl::vector m_permutations; public: typedef std::function callback_t; @@ -27,13 +27,13 @@ namespace uf { double fade(double t) const; double lerp(double t, double a, double b) const; double grad(int hash, double x, double y, double z) const; - std::vector collect( uint size, const pod::Vector3d& noiseCoeff, const callback_t& callback = [](double& n)->double{ + uf::stl::vector collect( uint size, const pod::Vector3d& noiseCoeff, const callback_t& callback = [](double& n)->double{ return n; } ); - std::vector collect( const pod::Vector2ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback = [](double& n)->double{ + uf::stl::vector collect( const pod::Vector2ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback = [](double& n)->double{ return n; } ); - std::vector collect( const pod::Vector3ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback = [](double& n)->double{ + uf::stl::vector collect( const pod::Vector3ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback = [](double& n)->double{ return n; } ); diff --git a/engine/inc/uf/utils/serialize/serializer.h b/engine/inc/uf/utils/serialize/serializer.h index a051187d..c71ec6a9 100644 --- a/engine/inc/uf/utils/serialize/serializer.h +++ b/engine/inc/uf/utils/serialize/serializer.h @@ -6,16 +6,16 @@ #include #include -#include +#include #include namespace uf { class UF_API Serializer : public ext::json::Document { public: - typedef std::string output_t; - typedef std::string input_t; + typedef uf::stl::string output_t; + typedef uf::stl::string input_t; - Serializer( const std::string& str = "{}" ); + Serializer( const uf::stl::string& str = "{}" ); Serializer( const ext::json::base_value& ); Serializer( const ext::json::Value& ); #if UF_USE_LUA @@ -24,7 +24,7 @@ namespace uf { Serializer::output_t serialize( bool pretty = false ) const; Serializer::output_t serialize( const ext::json::EncodingSettings& ) const; - void deserialize( const std::string& ); + void deserialize( const uf::stl::string& ); // serializeable template @@ -40,7 +40,7 @@ namespace uf { template static uf::Serializer toBase64( const T& input ) { // ensure this is a safe type to serialize - if ( !serializeable(input) ) return std::string(""); + if ( !serializeable(input) ) return uf::stl::string(""); pod::Userdata* userdata = uf::userdata::create(input); uf::Serializer res; res["base64"] = uf::userdata::toBase64( userdata ); @@ -53,31 +53,31 @@ namespace uf { // ensure this is a safe type to serialize if ( !serializeable(input) ) return T(); // ensure it's "proper" - if ( !input["base64"].is() ) return T(); - pod::Userdata* userdata = uf::userdata::fromBase64(input["base64"].as()); + if ( !input["base64"].is() ) return T(); + pod::Userdata* userdata = uf::userdata::fromBase64(input["base64"].as()); T res = uf::userdata::get( userdata ); uf::userdata::destroy( userdata ); return res; } - bool readFromFile( const std::string& from, const std::string& hash = "" ); - bool writeToFile( const std::string& to, const ext::json::EncodingSettings& = {} ) const; + bool readFromFile( const uf::stl::string& from, const uf::stl::string& hash = "" ); + bool writeToFile( const uf::stl::string& to, const ext::json::EncodingSettings& = {} ) const; void merge( const uf::Serializer& other, bool priority = true ); void import( const uf::Serializer& other ); - ext::json::Value& path( const std::string& ); + ext::json::Value& path( const uf::stl::string& ); operator Serializer::output_t(); operator Serializer::output_t() const; - uf::Serializer& operator=( const std::string& str ); + uf::Serializer& operator=( const uf::stl::string& str ); uf::Serializer& operator=( const ext::json::base_value& json ); uf::Serializer& operator=( const ext::json::Value& json ); #if UF_USE_LUA uf::Serializer& operator=( const sol::table& json ); #endif - uf::Serializer& operator<<( const std::string& str ); - uf::Serializer& operator>>( std::string& str ); - const uf::Serializer& operator>>( std::string& str ) const; + uf::Serializer& operator<<( const uf::stl::string& str ); + uf::Serializer& operator>>( uf::stl::string& str ); + const uf::Serializer& operator>>( uf::stl::string& str ) const; }; typedef Serializer Metadata; diff --git a/engine/inc/uf/utils/string/base64.h b/engine/inc/uf/utils/string/base64.h index 053d41c4..3ab398ae 100644 --- a/engine/inc/uf/utils/string/base64.h +++ b/engine/inc/uf/utils/string/base64.h @@ -2,28 +2,28 @@ #include -#include -#include +#include +#include #include namespace uf { namespace base64 { - UF_API std::string encode( const uint8_t*, std::size_t ); - UF_API std::vector decode( const std::string& ); + UF_API uf::stl::string encode( const uint8_t*, std::size_t ); + UF_API uf::stl::vector decode( const uf::stl::string& ); template - std::string encode( const T& input ) { + uf::stl::string encode( const T& input ) { return encode( (const uint8_t*) &input[0], input.size() * sizeof( input[0] ) ); } template - std::vector decode( const T& input ) { + uf::stl::vector decode( const T& input ) { return decode( (const uint8_t*) &input[0], input.size() * sizeof( input[0] ) ); } } namespace string { namespace base64 { - UF_API std::string encode( const std::string& ); - UF_API std::string decode( const std::string& ); + UF_API uf::stl::string encode( const uf::stl::string& ); + UF_API uf::stl::string decode( const uf::stl::string& ); } } } \ No newline at end of file diff --git a/engine/inc/uf/utils/string/encoding/ansi.h b/engine/inc/uf/utils/string/encoding/ansi.h index 4e8ca433..e1d72dd1 100644 --- a/engine/inc/uf/utils/string/encoding/ansi.h +++ b/engine/inc/uf/utils/string/encoding/ansi.h @@ -29,7 +29,7 @@ namespace uf { template static Input UF_API_CALL length(Input begin, Input end); // Encoding's name - static std::string UF_API_CALL getName() { return "ANSI"; } + static uf::stl::string UF_API_CALL getName() { return "ANSI"; } }; } } diff --git a/engine/inc/uf/utils/string/encoding/default.h b/engine/inc/uf/utils/string/encoding/default.h index 1ecd7b9d..16a1cd7e 100644 --- a/engine/inc/uf/utils/string/encoding/default.h +++ b/engine/inc/uf/utils/string/encoding/default.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace uf { namespace locale { @@ -37,7 +37,7 @@ namespace uf { template static Input UF_API_CALL length(Input begin, Input end); // Encoding's name - static std::string UF_API_CALL getName() { return "UTF-32"; } + static uf::stl::string UF_API_CALL getName() { return "UTF-32"; } }; } diff --git a/engine/inc/uf/utils/string/encoding/encoding_constructor.h b/engine/inc/uf/utils/string/encoding/encoding_constructor.h index 00ba9800..fbda46f3 100644 --- a/engine/inc/uf/utils/string/encoding/encoding_constructor.h +++ b/engine/inc/uf/utils/string/encoding/encoding_constructor.h @@ -26,7 +26,7 @@ namespace uf { \ template \ static Input UF_API_CALL length(Input begin, Input end); \ // Encoding's name \ - static std::string name = ENCODING_NAME; \ + static uf::stl::string name = ENCODING_NAME; \ }; \ } \ } \ No newline at end of file diff --git a/engine/inc/uf/utils/string/encoding/utf16.h b/engine/inc/uf/utils/string/encoding/utf16.h index 45e70492..d8e0630b 100644 --- a/engine/inc/uf/utils/string/encoding/utf16.h +++ b/engine/inc/uf/utils/string/encoding/utf16.h @@ -29,7 +29,7 @@ namespace uf { template static Input UF_API_CALL length(Input begin, Input end); // Encoding's name - static std::string UF_API_CALL getName() { return "UTF-16"; } + static uf::stl::string UF_API_CALL getName() { return "UTF-16"; } }; } } diff --git a/engine/inc/uf/utils/string/encoding/utf32.h b/engine/inc/uf/utils/string/encoding/utf32.h index 605ab728..97abfb85 100644 --- a/engine/inc/uf/utils/string/encoding/utf32.h +++ b/engine/inc/uf/utils/string/encoding/utf32.h @@ -27,7 +27,7 @@ namespace uf { template static Input UF_API_CALL length(Input begin, Input end); // Encoding's name - static std::string UF_API_CALL getName() { return "UTF-32"; } + static uf::stl::string UF_API_CALL getName() { return "UTF-32"; } }; } } diff --git a/engine/inc/uf/utils/string/encoding/utf8.h b/engine/inc/uf/utils/string/encoding/utf8.h index 605dd2cf..a9be64f3 100644 --- a/engine/inc/uf/utils/string/encoding/utf8.h +++ b/engine/inc/uf/utils/string/encoding/utf8.h @@ -29,7 +29,7 @@ namespace uf { template static Input UF_API_CALL length(Input begin, Input end); // Encoding's name - static std::string UF_API_CALL getName() { return "UTF-8"; } + static uf::stl::string UF_API_CALL getName() { return "UTF-8"; } }; } } diff --git a/engine/inc/uf/utils/string/ext.h b/engine/inc/uf/utils/string/ext.h index 09b38deb..d71f29ec 100644 --- a/engine/inc/uf/utils/string/ext.h +++ b/engine/inc/uf/utils/string/ext.h @@ -1,8 +1,8 @@ #pragma once #include -#include -#include +#include +#include #include #include "io.h" @@ -10,17 +10,17 @@ namespace uf { namespace string { - std::string UF_API replace( const std::string&, const std::string&, const std::string& ); - std::string UF_API lowercase( const std::string& ); - std::string UF_API uppercase( const std::string& ); - std::vector UF_API split( const std::string&, const std::string& ); - std::string UF_API si( double value, const std::string& unit, size_t precision = 3 ); - bool UF_API contains( const std::string&, const std::string& ); + uf::stl::string UF_API replace( const uf::stl::string&, const uf::stl::string&, const uf::stl::string& ); + uf::stl::string UF_API lowercase( const uf::stl::string& ); + uf::stl::string UF_API uppercase( const uf::stl::string& ); + uf::stl::vector UF_API split( const uf::stl::string&, const uf::stl::string& ); + uf::stl::string UF_API si( double value, const uf::stl::string& unit, size_t precision = 3 ); + bool UF_API contains( const uf::stl::string&, const uf::stl::string& ); template - std::string /*UF_API*/ join( const T&, const std::string& = "\n", bool = false ); + uf::stl::string /*UF_API*/ join( const T&, const uf::stl::string& = "\n", bool = false ); template - std::string /*UF_API*/ toString( const T& ); + uf::stl::string /*UF_API*/ toString( const T& ); } } diff --git a/engine/inc/uf/utils/string/ext.inl b/engine/inc/uf/utils/string/ext.inl index 304286b0..cc37bfeb 100644 --- a/engine/inc/uf/utils/string/ext.inl +++ b/engine/inc/uf/utils/string/ext.inl @@ -1,6 +1,6 @@ template -std::string /*UF_API*/ uf::string::join( const T& container, const std::string& token, bool trailing ) { - std::stringstream ss; +uf::stl::string /*UF_API*/ uf::string::join( const T& container, const uf::stl::string& token, bool trailing ) { + uf::stl::stringstream ss; size_t len = container.size(); for ( size_t i = 0; i < len; ++i ) { ss << container[i]; @@ -9,8 +9,8 @@ std::string /*UF_API*/ uf::string::join( const T& container, const std::string& return ss.str(); } template -std::string /*UF_API*/ uf::string::toString( const T& var ) { - std::stringstream ss; +uf::stl::string /*UF_API*/ uf::string::toString( const T& var ) { + uf::stl::stringstream ss; ss << &var; return ss.str(); } \ No newline at end of file diff --git a/engine/inc/uf/utils/string/hash.h b/engine/inc/uf/utils/string/hash.h index 7f3b6448..d34e3acb 100644 --- a/engine/inc/uf/utils/string/hash.h +++ b/engine/inc/uf/utils/string/hash.h @@ -2,16 +2,16 @@ #include -#include -#include +#include +#include #include #include namespace uf { namespace string { template - std::string sha256( const T& input ) { - // std::vector hash(picosha2::k_digest_size); + uf::stl::string sha256( const T& input ) { + // uf::stl::vector hash(picosha2::k_digest_size); // picosha2::hash256(input.begin(), input.end(), hash); // return picosha2::bytes_to_hex_string(hash.begin(), hash.end()); return picosha2::hash256_hex_string(input); diff --git a/engine/inc/uf/utils/string/locale.h b/engine/inc/uf/utils/string/locale.h index 5b556010..168ad77c 100644 --- a/engine/inc/uf/utils/string/locale.h +++ b/engine/inc/uf/utils/string/locale.h @@ -1,8 +1,9 @@ #include #include +#include namespace uf { namespace locale { - extern UF_API std::string current; + extern UF_API uf::stl::string current; }; } \ No newline at end of file diff --git a/engine/inc/uf/utils/string/rle.h b/engine/inc/uf/utils/string/rle.h index af4f7867..4264df48 100644 --- a/engine/inc/uf/utils/string/rle.h +++ b/engine/inc/uf/utils/string/rle.h @@ -2,13 +2,13 @@ #include -#include +#include #include namespace pod { template struct RLE { - typedef std::vector> string_t; + typedef uf::stl::vector> string_t; typedef U length_t; typedef T value_t; U length; @@ -19,9 +19,9 @@ namespace pod { namespace uf { namespace rle { template - typename pod::RLE::string_t encode( const std::vector& ); + typename pod::RLE::string_t encode( const uf::stl::vector& ); template - std::vector decode( const pod::RLE& ); + uf::stl::vector decode( const pod::RLE& ); } } @@ -30,7 +30,7 @@ namespace uf { /* namespace pod { struct RLE { - typedef std::vector string_t; + typedef uf::stl::vector string_t; uint16_t length; uint16_t value; }; @@ -38,11 +38,11 @@ namespace pod { namespace uf { namespace rle { - UF_API pod::RLE::string_t encode( const std::vector& ); - UF_API std::vector decode( const pod::RLE::string_t& ); + UF_API pod::RLE::string_t encode( const uf::stl::vector& ); + UF_API uf::stl::vector decode( const pod::RLE::string_t& ); - UF_API pod::RLE::string_t wrap( const std::vector& ); - UF_API std::vector unwrap( const pod::RLE::string_t& ); + UF_API pod::RLE::string_t wrap( const uf::stl::vector& ); + UF_API uf::stl::vector unwrap( const pod::RLE::string_t& ); } } */ \ No newline at end of file diff --git a/engine/inc/uf/utils/string/rle.inl b/engine/inc/uf/utils/string/rle.inl index f3e1e833..f61fc0e7 100644 --- a/engine/inc/uf/utils/string/rle.inl +++ b/engine/inc/uf/utils/string/rle.inl @@ -1,5 +1,5 @@ template -typename pod::RLE::string_t uf::rle::encode( const std::vector& source ) { +typename pod::RLE::string_t uf::rle::encode( const uf::stl::vector& source ) { typename pod::RLE::string_t destination; destination.reserve( source.size() ); @@ -13,8 +13,8 @@ typename pod::RLE::string_t uf::rle::encode( const std::vector& source ) return destination; } template -std::vector uf::rle::decode( const pod::RLE& source ) { - std::vector destination; +uf::stl::vector uf::rle::decode( const pod::RLE& source ) { + uf::stl::vector destination; for ( auto& s : source ) { destination.reserve( destination.size() + s.length ); diff --git a/engine/inc/uf/utils/string/string.h b/engine/inc/uf/utils/string/string.h index c95a62fd..f16316b8 100644 --- a/engine/inc/uf/utils/string/string.h +++ b/engine/inc/uf/utils/string/string.h @@ -3,7 +3,7 @@ #include #include "encoding.h" -#include +#include #include #include @@ -99,15 +99,15 @@ namespace uf { uf::String UF_API_CALL operator --(int); uf::String& UF_API_CALL operator -=( std::size_t i ); // Convert to standard string - UF_API_CALL operator std::string(); - UF_API_CALL operator std::string() const; + UF_API_CALL operator uf::stl::string(); + UF_API_CALL operator uf::stl::string() const; // Convert to standard wide string UF_API_CALL operator std::wstring(); UF_API_CALL operator std::wstring() const; // Write to an output stream friend std::ostream& operator <<( std::ostream& os, const uf::String& string ) { auto* pointer = string.getString().c_str(); - std::string str = (const char*) pointer; + uf::stl::string str = (const char*) pointer; return os << str; } }; diff --git a/engine/inc/uf/utils/string/utf.h b/engine/inc/uf/utils/string/utf.h index 0487a1aa..dbd9363b 100644 --- a/engine/inc/uf/utils/string/utf.h +++ b/engine/inc/uf/utils/string/utf.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include //// diff --git a/engine/inc/uf/utils/text/glyph.h b/engine/inc/uf/utils/text/glyph.h index 5b011bf9..c49c0ee5 100644 --- a/engine/inc/uf/utils/text/glyph.h +++ b/engine/inc/uf/utils/text/glyph.h @@ -2,7 +2,7 @@ #include #if UF_USE_FREETYPE -#include +#include #include #include @@ -23,9 +23,9 @@ namespace uf { ~Glyph(); bool generated(); - uint8_t* generate( const std::string&, unsigned long, uint = 48 ); + uint8_t* generate( const uf::stl::string&, unsigned long, uint = 48 ); uint8_t* generate( ext::freetype::Glyph&, unsigned long, uint = 48 ); - uint8_t* generate( const std::string&, const uf::String&, uint = 48 ); + uint8_t* generate( const uf::stl::string&, const uf::String&, uint = 48 ); uint8_t* generate( ext::freetype::Glyph&, const uf::String&, uint = 48 ); void generateSdf( uint8_t* ); diff --git a/engine/inc/uf/utils/thread/perthread.h b/engine/inc/uf/utils/thread/perthread.h index 63e9705c..118645a7 100644 --- a/engine/inc/uf/utils/thread/perthread.h +++ b/engine/inc/uf/utils/thread/perthread.h @@ -9,7 +9,7 @@ namespace uf { public: typedef T type_t; typedef std::thread::id id_t; - typedef std::unordered_map container_t; + typedef uf::stl::unordered_map container_t; protected: container_t m_container; public: diff --git a/engine/inc/uf/utils/thread/thread.h b/engine/inc/uf/utils/thread/thread.h index a5d8d93d..ceb3d106 100644 --- a/engine/inc/uf/utils/thread/thread.h +++ b/engine/inc/uf/utils/thread/thread.h @@ -4,22 +4,25 @@ #include #include -#include #include #include -#include + +#include +#include +#include + #include #include namespace pod { struct UF_API Thread { typedef std::function function_t; - typedef std::queue queue_t; - typedef std::vector container_t; + typedef uf::stl::queue queue_t; + typedef uf::stl::vector container_t; uint uid; double limiter; - std::string name; + uf::stl::string name; bool running, terminates; std::mutex* mutex; @@ -47,30 +50,30 @@ namespace uf { void UF_API tick( pod::Thread& ); // void UF_API tick( pod::Thread&, const std::function& = NULL ); - pod::Thread& UF_API fetchWorker( const std::string& name = "Aux" ); - void UF_API batchWorkers( const std::vector&, bool = true, const std::string& name = "Aux" ); + pod::Thread& UF_API fetchWorker( const uf::stl::string& name = "Aux" ); + void UF_API batchWorkers( const uf::stl::vector&, bool = true, const uf::stl::string& name = "Aux" ); void UF_API add( pod::Thread&, const pod::Thread::function_t&, bool = false ); void UF_API assertExecute( pod::Thread&, const pod::Thread::function_t& ); void UF_API process( pod::Thread& ); void UF_API wait( pod::Thread& ); - const std::string& UF_API name( const pod::Thread& ); + const uf::stl::string& UF_API name( const pod::Thread& ); uint UF_API uid( const pod::Thread& ); bool UF_API running( const pod::Thread& ); /* Acts on global threads */ - typedef std::vector container_t; + typedef uf::stl::vector container_t; extern UF_API uf::thread::container_t threads; void UF_API terminate(); - pod::Thread& UF_API create( const std::string& = "", bool = true, bool = true ); + pod::Thread& UF_API create( const uf::stl::string& = "", bool = true, bool = true ); void UF_API destroy( pod::Thread& ); bool UF_API has( uint ); - bool UF_API has( const std::string& ); + bool UF_API has( const uf::stl::string& ); pod::Thread& UF_API get( uint ); - pod::Thread& UF_API get( const std::string& ); + pod::Thread& UF_API get( const uf::stl::string& ); bool UF_API isMain(); } @@ -82,7 +85,7 @@ namespace uf { public: typedef std::function function_t; typedef std::queue queue_t; - typedef std::vector container_t; + typedef uf::stl::vector container_t; enum { TEMP = 0, @@ -95,14 +98,14 @@ namespace uf { bool m_shouldLock; bool m_terminateOnEmpty; std::mutex m_mutex; - std::string m_name; + uf::stl::string m_name; std::thread m_thread; uf::Thread::queue_t m_temps; uf::Thread::container_t m_consts; public: static uint fps; static uint thread_count; - Thread( const std::string& = "", bool = true, uint = 0 ); + Thread( const uf::stl::string& = "", bool = true, uint = 0 ); virtual ~Thread(); void start(); @@ -111,19 +114,19 @@ namespace uf { void process(); void quit(); - std::string toString() const; - const std::string& getName() const; + uf::stl::string toString() const; + const uf::stl::string& getName() const; uint getUid() const; const bool& isRunning() const; }; namespace thread { - typedef std::unordered_map container_t; + typedef uf::stl::unordered_map container_t; extern UF_API uf::thread::container_t threads; void UF_API add( uf::Thread* ); - uf::Thread& UF_API get( const std::string& ); - bool UF_API add( const std::string&, const uf::Thread::function_t&, uint = 0 ); - bool UF_API quit( const std::string& ); + uf::Thread& UF_API get( const uf::stl::string& ); + bool UF_API add( const uf::stl::string&, const uf::Thread::function_t&, uint = 0 ); + bool UF_API quit( const uf::stl::string& ); }; } */ \ No newline at end of file diff --git a/engine/inc/uf/utils/type/type.h b/engine/inc/uf/utils/type/type.h index a8c21b04..e8276978 100644 --- a/engine/inc/uf/utils/type/type.h +++ b/engine/inc/uf/utils/type/type.h @@ -2,18 +2,18 @@ #include #include -#include +#include #define UF_TYPE_REGISTER 1 -#include +#include namespace pod { struct UF_API TypeInfo { size_t hash; size_t size; struct { - std::string pretty; - std::string compiler; + uf::stl::string pretty; + uf::stl::string compiler; } name; }; } @@ -31,21 +31,21 @@ namespace uf { typedef std::type_index index_t; typedef pod::TypeInfo type_t; - extern UF_API std::unordered_map* types; + extern UF_API uf::stl::unordered_map* types; - void UF_API registerType( const index_t&, size_t = 0, const std::string& = "" ); + void UF_API registerType( const index_t&, size_t = 0, const uf::stl::string& = "" ); const pod::TypeInfo& UF_API getType( size_t ); const pod::TypeInfo& UF_API getType( const index_t& ); template const std::type_index getIndex(); template - void registerType( const std::string& pretty = "" ); + void registerType( const uf::stl::string& pretty = "" ); template const pod::TypeInfo& getType(); /* template const index_t getIndex(); - template void registerType( const std::string& = "" ); + template void registerType( const uf::stl::string& = "" ); template const pod::TypeInfo& getType(); */ } diff --git a/engine/inc/uf/utils/type/type.inl b/engine/inc/uf/utils/type/type.inl index e127fc29..a2bd6a6a 100644 --- a/engine/inc/uf/utils/type/type.inl +++ b/engine/inc/uf/utils/type/type.inl @@ -3,7 +3,7 @@ const std::type_index uf::typeInfo::getIndex() { return typeid(T); } template -void uf::typeInfo::registerType( const std::string& pretty ) { +void uf::typeInfo::registerType( const uf::stl::string& pretty ) { return registerType(getIndex(), sizeof(T), pretty); } template diff --git a/engine/inc/uf/utils/userdata/pointered.inl b/engine/inc/uf/utils/userdata/pointered.inl index ba212c18..e1eb86cd 100644 --- a/engine/inc/uf/utils/userdata/pointered.inl +++ b/engine/inc/uf/utils/userdata/pointered.inl @@ -19,8 +19,8 @@ namespace uf { template const T& get(const pod::PointeredUserdata& userdata, bool validate = uf::userdata::autoValidate ); template bool is(const pod::PointeredUserdata& userdata); - std::string UF_API toBase64( pod::PointeredUserdata& userdata ); - pod::PointeredUserdata UF_API fromBase64( const std::string& base64 ); + uf::stl::string UF_API toBase64( pod::PointeredUserdata& userdata ); + pod::PointeredUserdata UF_API fromBase64( const uf::stl::string& base64 ); // void move( pod::PointeredUserdata& to, pod::PointeredUserdata&& from ); // void copy( pod::PointeredUserdata& to, const pod::PointeredUserdata& from ); @@ -98,22 +98,22 @@ pod::PointeredUserdata uf::pointeredUserdata::create( const T& data ) { } template pod::PointeredUserdata uf::pointeredUserdata::create( uf::MemoryPool& requestedMemoryPool, const T& data ) { -// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : requestedMemoryPool; +// uf::MemoryPool& memoryPool = uf::memoryPool::global.size() > 0 ? uf::memoryPool::global : requestedMemoryPool; size_t len = sizeof(data); #if UF_MEMORYPOOL_INVALID_MALLOC - uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global; + uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::memoryPool::global; pod::PointeredUserdata userdata; userdata.len = len; - userdata.data = (uint8_t*) memoryPool.alloc( NULL, len ); + userdata.data = (uint8_t*) memoryPool.alloc( nullptr, len ); #else uf::MemoryPool* memoryPool = NULL; if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) memoryPool = &uf::memoryPool::global; pod::PointeredUserdata userdata; userdata.len = len; userdata.data = NULL; if ( memoryPool ) - userdata.data = (uint8_t*) memoryPool->alloc( NULL, len ); + userdata.data = (uint8_t*) memoryPool->alloc( nullptr, len ); else userdata.data = (uint8_t*) operator new( len ); // allocate data for the userdata struct, and then some } #endif diff --git a/engine/inc/uf/utils/userdata/userdata.h b/engine/inc/uf/utils/userdata/userdata.h index 6201ba6d..cd075159 100644 --- a/engine/inc/uf/utils/userdata/userdata.h +++ b/engine/inc/uf/utils/userdata/userdata.h @@ -2,11 +2,11 @@ #include -#include +#include #include #include -#include +#include #include #include @@ -39,8 +39,8 @@ namespace uf { template const T& get(const pod::Userdata* userdata, bool validate = uf::userdata::autoValidate ); template bool is(const pod::Userdata* userdata); - std::string UF_API toBase64( pod::Userdata* userdata ); - pod::Userdata* UF_API fromBase64( const std::string& base64 ); + uf::stl::string UF_API toBase64( pod::Userdata* userdata ); + pod::Userdata* UF_API fromBase64( const uf::stl::string& base64 ); // void move( pod::Userdata& to, pod::Userdata&& from ); // void copy( pod::Userdata& to, const pod::Userdata& from ); diff --git a/engine/inc/uf/utils/userdata/userdata.inl b/engine/inc/uf/utils/userdata/userdata.inl index f2def5d4..297dfcd2 100644 --- a/engine/inc/uf/utils/userdata/userdata.inl +++ b/engine/inc/uf/utils/userdata/userdata.inl @@ -7,19 +7,19 @@ pod::Userdata* uf::userdata::create( const T& data ) { } template pod::Userdata* uf::userdata::create( uf::MemoryPool& requestedMemoryPool, const T& data ) { -// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : requestedMemoryPool; +// uf::MemoryPool& memoryPool = uf::memoryPool::global.size() > 0 ? uf::memoryPool::global : requestedMemoryPool; size_t len = sizeof(data); size_t requestedLen = size( len ); #if UF_MEMORYPOOL_INVALID_MALLOC - uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global; - pod::Userdata* userdata = (pod::Userdata*) memoryPool.alloc( NULL, requestedLen ); + uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::memoryPool::global; + pod::Userdata* userdata = (pod::Userdata*) memoryPool.alloc( nullptr, requestedLen ); #else uf::MemoryPool* memoryPool = NULL; if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) memoryPool = &uf::memoryPool::global; pod::Userdata* userdata = NULL; if ( memoryPool ) - userdata = (pod::Userdata*) memoryPool->alloc( NULL, requestedLen ); + userdata = (pod::Userdata*) memoryPool->alloc( nullptr, requestedLen ); else userdata = (pod::Userdata*) operator new( requestedLen ); // allocate data for the userdata struct, and then some } #endif diff --git a/engine/inc/uf/utils/window/payloads.h b/engine/inc/uf/utils/window/payloads.h index dd24f38b..1ace3f90 100644 --- a/engine/inc/uf/utils/window/payloads.h +++ b/engine/inc/uf/utils/window/payloads.h @@ -2,14 +2,14 @@ #include -#include +#include #include namespace pod { namespace payloads { struct windowEvent { - std::string type = ""; - std::string invoker = ""; + uf::stl::string type = ""; + uf::stl::string invoker = ""; }; struct windowResized : public windowEvent { struct { @@ -24,12 +24,12 @@ namespace pod { struct windowTextEntered : public windowEvent { struct { uint32_t utf32; - std::string unicode; + uf::stl::string unicode; } text; }; struct windowKey : public windowEvent { struct { - std::string code; + uf::stl::string code; uint32_t raw; int_fast8_t state = -1; @@ -52,13 +52,13 @@ namespace pod { struct { pod::Vector2i position = {}; pod::Vector2i delta = {}; - std::string button = ""; + uf::stl::string button = ""; int_fast8_t state = 0; } mouse; }; struct windowMouseMoved : public windowResized { struct { - pod::Vector2ui position{}; + pod::Vector2i position{}; pod::Vector2i delta{}; int_fast8_t state{}; } mouse; diff --git a/engine/inc/uf/utils/window/window.h b/engine/inc/uf/utils/window/window.h index dd3fc96f..913794a6 100644 --- a/engine/inc/uf/utils/window/window.h +++ b/engine/inc/uf/utils/window/window.h @@ -44,11 +44,11 @@ namespace uf { void UF_API_CALL switchToFullscreen( bool borderless = false ); // Update #if defined(UF_USE_VULKAN) && UF_USE_VULKAN == 1 - std::vector getExtensions( bool validationEnabled = true ); + uf::stl::vector getExtensions( bool validationEnabled = true ); void createSurface( VkInstance instance, VkSurfaceKHR& surface ); #endif static bool focused; - static bool UF_API_CALL isKeyPressed(const std::string&); + static bool UF_API_CALL isKeyPressed(const uf::stl::string&); void UF_API_CALL processEvents(); bool UF_API_CALL pollEvents(bool block = false); bool UF_API_CALL setActive( bool active = true ); diff --git a/engine/src/engine/asset/asset.cpp b/engine/src/engine/asset/asset.cpp index 902e0c97..96a33a83 100644 --- a/engine/src/engine/asset/asset.cpp +++ b/engine/src/engine/asset/asset.cpp @@ -19,14 +19,14 @@ #include namespace { - bool retrieve( const std::string& url, const std::string& filename, const std::string& hash = "" ) { + bool retrieve( const uf::stl::string& url, const uf::stl::string& filename, const uf::stl::string& hash = "" ) { uf::Http http = uf::http::get( url ); if ( http.code < 200 || http.code > 300 ) { UF_MSG_ERROR("HTTP Error " << http.code << " on GET " << url); return false; } - std::string actual = hash; + uf::stl::string actual = hash; if ( hash != "" && (actual = uf::string::sha256(url)) != hash ) { UF_MSG_ERROR("HTTP hash mismatch on GET " << url << ": expected " << hash << ", got " << actual); return false; @@ -35,11 +35,11 @@ namespace { uf::io::write( "./" + filename, http.response ); return true; } - std::string hashed( const std::string& uri ) { + uf::stl::string hashed( const uf::stl::string& uri ) { return uf::string::sha256(uri); /* - std::size_t value = std::hash{}( uri ); - std::stringstream stream; + std::size_t value = std::hash{}( uri ); + uf::stl::stringstream stream; stream << std::hex << value; return stream.str(); */ @@ -48,11 +48,11 @@ namespace { std::mutex mutex; uint64_t uid = 0; struct Job { - std::string callback; - std::string type; - std::string uri; - std::string hash; - std::string category; + uf::stl::string callback; + uf::stl::string type; + uf::stl::string uri; + uf::stl::string hash; + uf::stl::string category; }; } @@ -64,15 +64,15 @@ void uf::Asset::processQueue() { while ( !jobs.empty() ) { auto job = jobs.front(); jobs.pop(); - std::string callback = job.callback; - std::string type = job.type; - std::string uri = job.uri; - std::string hash = job.hash; - std::string category = job.category; + uf::stl::string callback = job.callback; + uf::stl::string type = job.type; + uf::stl::string uri = job.uri; + uf::stl::string hash = job.hash; + uf::stl::string category = job.category; if ( uri == "" || callback == "" ) { continue; } - std::string filename = type == "cache" ? this->cache(uri, hash, category) : this->load(uri, hash, category); + uf::stl::string filename = type == "cache" ? this->cache(uri, hash, category) : this->load(uri, hash, category); if ( callback != "" && filename != "" ) { uf::Serializer payload; payload["filename"] = filename; @@ -83,24 +83,24 @@ void uf::Asset::processQueue() { } mutex.unlock(); } -void uf::Asset::cache( const std::string& callback, const std::string& uri, const std::string& hash, const std::string& category ) { +void uf::Asset::cache( const uf::stl::string& callback, const uf::stl::string& uri, const uf::stl::string& hash, const uf::stl::string& category ) { mutex.lock(); auto& jobs = this->getComponent>(); jobs.push({ callback, "cache", uri, hash, category }); mutex.unlock(); } -void uf::Asset::load( const std::string& callback, const std::string& uri, const std::string& hash, const std::string& category ) { +void uf::Asset::load( const uf::stl::string& callback, const uf::stl::string& uri, const uf::stl::string& hash, const uf::stl::string& category ) { mutex.lock(); auto& jobs = this->getComponent>(); jobs.push({ callback, "load", uri, hash, category }); mutex.unlock(); } -std::string uf::Asset::cache( const std::string& uri, const std::string& hash, const std::string& category ) { - std::string filename = uri; - std::string extension = uf::io::extension( uri ); +uf::stl::string uf::Asset::cache( const uf::stl::string& uri, const uf::stl::string& hash, const uf::stl::string& category ) { + uf::stl::string filename = uri; + uf::stl::string extension = uf::io::extension( uri ); if ( uri.substr(0,5) == "https" ) { - std::string hash = hashed( uri ); - std::string cached = uf::io::root + "/cache/http/" + hash + "." + extension; + uf::stl::string hash = hashed( uri ); + uf::stl::string cached = uf::io::root + "/cache/http/" + hash + "." + extension; if ( !uf::io::exists( cached ) && !retrieve( uri, cached, hash ) ) { UF_MSG_ERROR("Failed to preload `" + uri + "` (`" + cached + "`): HTTP error"); return ""; @@ -111,19 +111,19 @@ std::string uf::Asset::cache( const std::string& uri, const std::string& hash, c UF_MSG_ERROR("Failed to preload `" + filename + "`: Does not exist"); return ""; } - std::string actual = hash; + uf::stl::string actual = hash; if ( hash != "" && (actual = uf::io::hash( filename )) != hash ) { UF_MSG_ERROR("Failed to preload `" << filename << "`: Hash mismatch; expected " << hash << ", got " << actual); return ""; } return filename; } -std::string uf::Asset::load( const std::string& uri, const std::string& hash, const std::string& category ) { - std::string filename = uri; - std::string extension = uf::io::extension( uri ); +uf::stl::string uf::Asset::load( const uf::stl::string& uri, const uf::stl::string& hash, const uf::stl::string& category ) { + uf::stl::string filename = uri; + uf::stl::string extension = uf::io::extension( uri ); if ( uri.substr(0,5) == "https" ) { - std::string hash = hashed( uri ); - std::string cached = uf::io::root + "/cache/http/" + hash + "." + extension; + uf::stl::string hash = hashed( uri ); + uf::stl::string cached = uf::io::root + "/cache/http/" + hash + "." + extension; if ( !uf::io::exists( cached ) && !retrieve( uri, cached, hash ) ) { UF_MSG_ERROR("Failed to load `" + uri + "` (`" + cached + "`): HTTP error"); return ""; @@ -134,7 +134,7 @@ std::string uf::Asset::load( const std::string& uri, const std::string& hash, co UF_MSG_ERROR("Failed to load `" + filename + "`: Does not exist"); return ""; } - std::string actual = hash; + uf::stl::string actual = hash; if ( hash != "" && (actual = uf::io::hash( filename )) != hash ) { UF_MSG_ERROR("Failed to load `" << filename << "`: Hash mismatch; expected " << hash << ", got " << actual); return ""; @@ -199,14 +199,14 @@ std::string uf::Asset::load( const std::string& uri, const std::string& hash, co } return filename; } -std::string uf::Asset::getOriginal( const std::string& uri ) { - std::string extension = uf::io::extension( uri ); +uf::stl::string uf::Asset::getOriginal( const uf::stl::string& uri ) { + uf::stl::string extension = uf::io::extension( uri ); auto& map = this->getComponent(); if ( ext::json::isNull( map[extension][uri]["index"] ) ) return uri; std::size_t index = map[extension][uri]["index"].as(); - std::string key = uri; - ext::json::forEach( map[extension], [&]( const std::string& k, ext::json::Value& v ) { + uf::stl::string key = uri; + ext::json::forEach( map[extension], [&]( const uf::stl::string& k, ext::json::Value& v ) { std::size_t i = v["index"].as(); if ( index == i && key != uri ) key = k; }); diff --git a/engine/src/engine/asset/masterdata.cpp b/engine/src/engine/asset/masterdata.cpp index bb17f9d6..13e21b1a 100644 --- a/engine/src/engine/asset/masterdata.cpp +++ b/engine/src/engine/asset/masterdata.cpp @@ -1,31 +1,31 @@ #include #include -//std::string uf::MasterData::root = "https://el..xyz/mastertable/get/%TABLE%/%KEY%?.json"; -std::string uf::MasterData::root = uf::io::root + "/master/%TABLE%.json"; +//uf::stl::string uf::MasterData::root = "https://el..xyz/mastertable/get/%TABLE%/%KEY%?.json"; +uf::stl::string uf::MasterData::root = uf::io::root + "/master/%TABLE%.json"; uf::Asset uf::MasterData::assetLoader; -uf::Serializer uf::MasterData::load( const std::string& table, size_t key ) { +uf::Serializer uf::MasterData::load( const uf::stl::string& table, size_t key ) { return this->load( table, std::to_string(key) ); } -uf::Serializer uf::MasterData::load( const std::string& table, const std::string& key ) { +uf::Serializer uf::MasterData::load( const uf::stl::string& table, const uf::stl::string& key ) { this->m_table = table; this->m_key = key; - std::string url = uf::string::replace( root, "%TABLE%", table ); + uf::stl::string url = uf::string::replace( root, "%TABLE%", table ); url = uf::string::replace( url, "%KEY%", key ); - std::string filename = assetLoader.cache(url); + uf::stl::string filename = assetLoader.cache(url); if ( filename != "" ) this->m_data.readFromFile(filename); return this->get(); } -uf::Serializer uf::MasterData::get( const std::string& key ) const { - std::string k = (key == "" ? this->m_key : key); +uf::Serializer uf::MasterData::get( const uf::stl::string& key ) const { + uf::stl::string k = (key == "" ? this->m_key : key); if ( k != "" ) return this->m_data[k]; return this->m_data; } -const std::string& uf::MasterData::tableName() const { +const uf::stl::string& uf::MasterData::tableName() const { return this->m_table; } -const std::string& uf::MasterData::keyName() const { +const uf::stl::string& uf::MasterData::keyName() const { return this->m_key; } \ No newline at end of file diff --git a/engine/src/engine/entity/entity.cpp b/engine/src/engine/entity/entity.cpp index 408616e4..f8783f6d 100644 --- a/engine/src/engine/entity/entity.cpp +++ b/engine/src/engine/entity/entity.cpp @@ -60,24 +60,24 @@ uf::Entity::container_t& uf::Entity::getChildren() { const uf::Entity::container_t& uf::Entity::getChildren() const { return this->m_children; } -const std::string& uf::Entity::getName() const { +const uf::stl::string& uf::Entity::getName() const { return this->m_name; } -void uf::Entity::setName( const std::string& name ) { +void uf::Entity::setName( const uf::stl::string& name ) { this->m_name = name; } std::size_t uf::Entity::getUid() const { return this->m_uid; } -void* uf::Entity::operator new(size_t size, const std::string& type ) { +void* uf::Entity::operator new(size_t size, const uf::stl::string& type ) { return type != "" && size == sizeof(uf::Entity) ? &uf::instantiator::instantiate( type ) : uf::instantiator::alloc( size ); } void uf::Entity::operator delete( void* pointer ) { uf::instantiator::free( (uf::Entity*) pointer ); } -uf::Entity* uf::Entity::findByName( const std::string& name ) { +uf::Entity* uf::Entity::findByName( const uf::stl::string& name ) { for ( uf::Entity* entity : this->m_children ) { if ( entity->getName() == name ) return entity; uf::Entity* p = entity->findByName(name); @@ -94,7 +94,7 @@ uf::Entity* uf::Entity::findByUid( std::size_t id ) { return (uf::Entity*) NULL; }; -const uf::Entity* uf::Entity::findByName( const std::string& name ) const { +const uf::Entity* uf::Entity::findByName( const uf::stl::string& name ) const { for ( uf::Entity* entity : this->m_children ) { if ( entity->getName() == name ) return entity; uf::Entity* p = entity->findByName(name); @@ -132,7 +132,7 @@ uf::Entity* uf::Entity::globalFindByUid( size_t uid ) { } return NULL; } -uf::Entity* uf::Entity::globalFindByName( const std::string& name ) { +uf::Entity* uf::Entity::globalFindByName( const uf::stl::string& name ) { for ( auto& allocation : uf::Entity::memoryPool.allocations() ) { uf::Entity* entity = (uf::Entity*) allocation.pointer; if ( !entity->isValid() ) continue; diff --git a/engine/src/engine/graph/graph.cpp b/engine/src/engine/graph/graph.cpp index 0d6fb497..d0340b23 100644 --- a/engine/src/engine/graph/graph.cpp +++ b/engine/src/engine/graph/graph.cpp @@ -16,7 +16,7 @@ namespace { void initializeShaders( pod::Graph& graph, uf::Object& entity ) { auto& graphic = entity.getComponent(); - std::string root = uf::io::directory( graph.name ); + uf::stl::string root = uf::io::directory( graph.name ); size_t texture2Ds = 0; size_t texture3Ds = 0; for ( auto& texture : graphic.material.textures ) { @@ -26,9 +26,9 @@ namespace { // standard pipeline { - std::string vertexShaderFilename = graph.metadata["shaders"]["vertex"].as("/gltf/base.vert.spv"); - std::string geometryShaderFilename = graph.metadata["shaders"]["geometry"].as(""); - std::string fragmentShaderFilename = graph.metadata["shaders"]["fragment"].as("/gltf/base.frag.spv"); + uf::stl::string vertexShaderFilename = graph.metadata["shaders"]["vertex"].as("/gltf/base.vert.spv"); + uf::stl::string geometryShaderFilename = graph.metadata["shaders"]["geometry"].as(""); + uf::stl::string fragmentShaderFilename = graph.metadata["shaders"]["fragment"].as("/gltf/base.frag.spv"); if ( uf::renderer::settings::experimental::deferredSampling ) { fragmentShaderFilename = uf::string::replace( fragmentShaderFilename, "frag", "deferredSampling.frag" ); } @@ -54,7 +54,7 @@ namespace { auto& shader = graphic.material.getShader("vertex"); uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "PASSES" ) sc["value"] = (specializationConstants[i] = maxPasses); }); } @@ -64,12 +64,12 @@ namespace { auto& shader = graphic.material.getShader("fragment"); uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTextures); }); ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ - if ( t["name"].as() != "samplerTextures" ) return; + if ( t["name"].as() != "samplerTextures" ) return; size_t binding = t["binding"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding == binding ) layout.descriptorCount = maxTextures; @@ -80,9 +80,9 @@ namespace { } // vxgi pipeline if ( uf::renderer::settings::experimental::vxgi ) { - std::string vertexShaderFilename = graph.metadata["shaders"]["vertex"].as("/gltf/base.vert.spv"); - std::string geometryShaderFilename = graph.metadata["shaders"]["geometry"].as("/gltf/voxelize.geom.spv"); - std::string fragmentShaderFilename = graph.metadata["shaders"]["fragment"].as("/gltf/voxelize.frag.spv"); + uf::stl::string vertexShaderFilename = graph.metadata["shaders"]["vertex"].as("/gltf/base.vert.spv"); + uf::stl::string geometryShaderFilename = graph.metadata["shaders"]["geometry"].as("/gltf/voxelize.geom.spv"); + uf::stl::string fragmentShaderFilename = graph.metadata["shaders"]["fragment"].as("/gltf/voxelize.frag.spv"); if ( uf::renderer::settings::experimental::deferredSampling ) { // fragmentShaderFilename = uf::string::replace( fragmentShaderFilename, "frag", "deferredSampling.frag" ); } @@ -112,13 +112,13 @@ namespace { uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTextures); else if ( name == "CASCADES" ) sc["value"] = (specializationConstants[i] = maxCascades); }); ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ size_t binding = t["binding"].as(); - std::string name = t["name"].as(); + uf::stl::string name = t["name"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding != binding ) continue; if ( name == "samplerTextures" ) layout.descriptorCount = maxTextures; @@ -140,14 +140,14 @@ namespace { graphic.material.device = &uf::renderer::device; graphic.descriptor.frontFace = uf::renderer::enums::Face::CCW; graphic.descriptor.cullMode = !(graph.metadata["flags"]["INVERT"].as()) ? uf::renderer::enums::CullMode::BACK : uf::renderer::enums::CullMode::FRONT; - if ( graph.metadata["cull mode"].is() ) { - if ( graph.metadata["cull mode"].as() == "back" ) { + if ( graph.metadata["cull mode"].is() ) { + if ( graph.metadata["cull mode"].as() == "back" ) { graphic.descriptor.cullMode = uf::renderer::enums::CullMode::BACK; - } else if ( graph.metadata["cull mode"].as() == "front" ) { + } else if ( graph.metadata["cull mode"].as() == "front" ) { graphic.descriptor.cullMode = uf::renderer::enums::CullMode::FRONT; - } else if ( graph.metadata["cull mode"].as() == "none" ) { + } else if ( graph.metadata["cull mode"].as() == "none" ) { graphic.descriptor.cullMode = uf::renderer::enums::CullMode::NONE; - } else if ( graph.metadata["cull mode"].as() == "both" ) { + } else if ( graph.metadata["cull mode"].as() == "both" ) { graphic.descriptor.cullMode = uf::renderer::enums::CullMode::BOTH; } } @@ -199,7 +199,7 @@ pod::Matrix4f uf::graph::matrix( pod::Graph& graph, int32_t index ) { pod::Node* uf::graph::find( pod::Graph& graph, int32_t index ) { return 0 <= index && index < graph.nodes.size() ? &graph.nodes[index] : NULL; } -pod::Node* uf::graph::find( pod::Graph& graph, const std::string& name ) { +pod::Node* uf::graph::find( pod::Graph& graph, const uf::stl::string& name ) { for ( auto& node : graph.nodes ) if ( node.name == name ) return &node; return NULL; } @@ -211,9 +211,9 @@ void uf::graph::process( uf::Object& entity ) { void uf::graph::process( pod::Graph& graph ) { // using an atlas texture will not bind other textures // load lightmap, if requested - if ( graph.metadata["lightmap"].is() ) { + if ( graph.metadata["lightmap"].is() ) { // check if valid filename, if not it's a texture name - std::string f = uf::io::sanitize( graph.metadata["lightmap"].as(), uf::io::directory( graph.name ) ); + uf::stl::string f = uf::io::sanitize( graph.metadata["lightmap"].as(), uf::io::directory( graph.name ) ); if ( uf::io::exists( f ) ) { for ( auto& material : graph.materials ) { material.storage.indexLightmap = graph.textures.size(); @@ -258,8 +258,8 @@ void uf::graph::process( pod::Graph& graph ) { texture.storage.remap = -1; texture.storage.blend = 0; - if ( graph.metadata["filter"].is() ) { - std::string filter = graph.metadata["filter"].as(); + if ( graph.metadata["filter"].is() ) { + uf::stl::string filter = graph.metadata["filter"].as(); if ( filter == "NEAREST" ) { texture.texture.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; texture.texture.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; @@ -291,8 +291,8 @@ void uf::graph::process( pod::Graph& graph ) { auto& image = graph.images[i]; auto& texture = graph.textures[i]; texture.bind = true; - if ( graph.metadata["filter"].is() ) { - std::string filter = graph.metadata["filter"].as(); + if ( graph.metadata["filter"].is() ) { + uf::stl::string filter = graph.metadata["filter"].as(); if ( filter == "NEAREST" ) { texture.texture.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; texture.texture.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; @@ -313,7 +313,7 @@ void uf::graph::process( pod::Graph& graph ) { auto& graphic = graph.root.entity->getComponent(); - std::vector instances; + uf::stl::vector instances; instances.reserve( graph.nodes.size() ); for ( auto& node : graph.nodes ) { instances.emplace_back( uf::transform::model( node.transform ) ); @@ -342,7 +342,7 @@ void uf::graph::process( pod::Graph& graph ) { if ( graph.textures.empty() ) graph.textures.emplace_back(); // Materials storage buffer - std::vector materials( graph.materials.size() ); + uf::stl::vector materials( graph.materials.size() ); for ( size_t i = 0; i < graph.materials.size(); ++i ) { materials[i] = graph.materials[i].storage; } @@ -352,7 +352,7 @@ void uf::graph::process( pod::Graph& graph ) { uf::renderer::enums::Buffer::STORAGE ); // Texture storage buffer - std::vector textures( graph.textures.size() ); + uf::stl::vector textures( graph.textures.size() ); for ( size_t i = 0; i < graph.textures.size(); ++i ) { textures[i] = graph.textures[i].storage; } @@ -371,7 +371,7 @@ void uf::graph::process( pod::Graph& graph ) { if ( !entity->hasComponent() ) return; auto& metadata = entity->getComponent(); - std::string nodeName = metadata["system"]["graph"]["name"].as( entity->getName() ); + uf::stl::string nodeName = metadata["system"]["graph"]["name"].as( entity->getName() ); auto& transform = entity->getComponent>(); auto& mesh = entity->getComponent(); @@ -487,7 +487,7 @@ void uf::graph::process( pod::Graph& graph ) { if ( !ext::json::isNull( graph.metadata["tags"][nodeName] ) ) { auto& info = graph.metadata["tags"][nodeName]; if ( ext::json::isObject( info["collision"] ) ) { - std::string type = info["collision"]["type"].as(); + uf::stl::string type = info["collision"]["type"].as(); float mass = info["collision"]["mass"].as(); bool dynamic = !info["collision"]["static"].as(); bool recenter = info["collision"]["recenter"].as(); @@ -538,17 +538,17 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) if ( info["ignore"].as() ) { return; } - if ( info["action"].as() == "load" ) { - if ( info["filename"].is() ) { - std::string filename = uf::io::resolveURI( info["filename"].as(), graph.metadata["root"].as() ); + if ( info["action"].as() == "load" ) { + if ( info["filename"].is() ) { + uf::stl::string filename = uf::io::resolveURI( info["filename"].as(), graph.metadata["root"].as() ); entity.load(filename); } else if ( ext::json::isObject( info["payload"] ) ) { uf::Serializer json = info["payload"]; json["root"] = graph.metadata["root"]; entity.load(json); } - } else if ( info["action"].as() == "attach" ) { - std::string filename = uf::io::resolveURI( info["filename"].as(), graph.metadata["root"].as() ); + } else if ( info["action"].as() == "attach" ) { + uf::stl::string filename = uf::io::resolveURI( info["filename"].as(), graph.metadata["root"].as() ); auto& child = entity.loadChild( filename, false ); auto& childTransform = child.getComponent>(); auto flatten = uf::transform::flatten( node.transform ); @@ -584,7 +584,7 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) metadataLight["bias"] = graph.metadata["lights"]["bias"].as(); } // copy from tag information - ext::json::forEach( graph.metadata["tags"][node.name]["light"], [&]( const std::string& key, ext::json::Value& value ){ + ext::json::forEach( graph.metadata["tags"][node.name]["light"], [&]( const uf::stl::string& key, ext::json::Value& value ){ if ( key == "transform" ) return; metadataLight[key] = value; }); @@ -592,7 +592,7 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) auto& metadataJson = entity.getComponent(); entity.load("/light.json"); // copy - ext::json::forEach( metadataLight, [&]( const std::string& key, ext::json::Value& value ) { + ext::json::forEach( metadataLight, [&]( const uf::stl::string& key, ext::json::Value& value ) { metadataJson["light"][key] = value; }); break; @@ -616,8 +616,8 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) transform.orientation = uf::quaternion::multiply( transform.orientation, parsed.orientation ); } else { transform = uf::transform::decode( info["transform"], transform ); - if ( info["transform"]["parent"].is() ) { - auto* parentPointer = uf::graph::find( graph, info["transform"]["parent"].as() ); + if ( info["transform"]["parent"].is() ) { + auto* parentPointer = uf::graph::find( graph, info["transform"]["parent"].as() ); if ( parentPointer ) { auto& parentNode = *parentPointer; // entity already exists, bind to its transform @@ -662,7 +662,7 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) ); } // Materials storage buffer - std::vector materials( graph.materials.size() ); + uf::stl::vector materials( graph.materials.size() ); for ( size_t i = 0; i < graph.materials.size(); ++i ) { materials[i] = graph.materials[i].storage; } @@ -672,7 +672,7 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) uf::renderer::enums::Buffer::STORAGE ); // Texture storage buffer - std::vector textures( graph.textures.size() ); + uf::stl::vector textures( graph.textures.size() ); for ( size_t i = 0; i < graph.textures.size(); ++i ) { textures[i] = graph.textures[i].storage; // textures[i].remap = -1; @@ -708,7 +708,7 @@ void uf::graph::override( pod::Graph& graph ) { } // set our destination transform per node if ( !toNeutralPose ) { - std::string name = graph.sequence.front(); + uf::stl::string name = graph.sequence.front(); pod::Animation& animation = graph.animations[name]; for ( auto& channel : animation.channels ) { auto& override = graph.settings.animations.override.map[channel.node]; @@ -742,7 +742,7 @@ void uf::graph::initialize( pod::Graph& graph ) { }); } -void uf::graph::animate( pod::Graph& graph, const std::string& name, float speed, bool immediate ) { +void uf::graph::animate( pod::Graph& graph, const uf::stl::string& name, float speed, bool immediate ) { if ( !(graph.metadata["flags"]["SKINNED"].as()) ) return; if ( graph.animations.count( name ) > 0 ) { // if already playing, ignore it @@ -766,7 +766,7 @@ void uf::graph::update( pod::Graph& graph, float delta ) { if ( graph.sequence.empty() ) goto UPDATE; if ( graph.settings.animations.override.a >= 0 ) goto OVERRIDE; { - std::string name = graph.sequence.front(); + uf::stl::string name = graph.sequence.front(); pod::Animation* animation = &graph.animations[name]; // std::cout << "ANIMATION: " << name << "\t" << animation->cur << std::endl; animation->cur += delta * graph.settings.animations.speed; // * graph.settings.animations.override.speed; @@ -822,7 +822,7 @@ void uf::graph::update( pod::Graph& graph, pod::Node& node ) { pod::Matrix4f nodeMatrix = uf::graph::matrix( graph, node.index ); pod::Matrix4f inverseTransform = uf::matrix::inverse( nodeMatrix ); auto& skin = graph.skins[node.skin]; - std::vector joints; + uf::stl::vector joints; joints.reserve( skin.joints.size() ); for ( size_t i = 0; i < skin.joints.size(); ++i ) { joints.emplace_back( uf::matrix::identity() ); @@ -853,7 +853,7 @@ namespace { auto size = uf::vector::decode( json["size"], pod::Vector2ui{} ); size_t bpp = json["bpp"].as(); size_t channels = json["channels"].as(); - auto pixels = uf::base64::decode( json["data"].as() ); + auto pixels = uf::base64::decode( json["data"].as() ); image.loadFromBuffer( &pixels[0], size, bpp, channels, true ); return image; } @@ -863,7 +863,7 @@ namespace { pod::Texture decodeTexture( ext::json::Value& json, const pod::Graph& graph ) { pod::Texture texture; - texture.name = json["name"].as(); + texture.name = json["name"].as(); texture.storage.index = json["index"].is() ? json["index"].as() : -1; texture.storage.sampler = json["sampler"].is() ? json["sampler"].as() : -1; texture.storage.remap = json["remap"].is() ? json["remap"].as() : -1; @@ -890,8 +890,8 @@ namespace { pod::Material decodeMaterial( ext::json::Value& json, const pod::Graph& graph ) { pod::Material material; - material.name = json["name"].as(); - material.alphaMode = json["alphaMode"].as(); + material.name = json["name"].as(); + material.alphaMode = json["alphaMode"].as(); material.storage.colorBase = uf::vector::decode( json["base"], pod::Vector4f{} ); material.storage.colorEmissive = uf::vector::decode( json["emissive"], pod::Vector4f{} ); material.storage.factorMetallic = json["fMetallic"].as(); @@ -912,7 +912,7 @@ namespace { pod::Light decodeLight( ext::json::Value& json, const pod::Graph& graph ) { pod::Light light; - light.name = json["name"].as(); + light.name = json["name"].as(); light.color = uf::vector::decode( json["color"], pod::Vector3f{} ); light.intensity = json["intensity"].as(); light.range = json["range"].as(); @@ -924,13 +924,13 @@ namespace { pod::Animation decodeAnimation( ext::json::Value& json, const pod::Graph& graph ) { pod::Animation animation; - animation.name = json["name"].as(); + animation.name = json["name"].as(); animation.start = json["start"].as(); animation.end = json["end"].as(); ext::json::forEach( json["samplers"], [&]( ext::json::Value& value ){ auto& sampler = animation.samplers.emplace_back(); - sampler.interpolator = value["interpolator"].as(); + sampler.interpolator = value["interpolator"].as(); sampler.inputs.reserve( value["inputs"].size() ); ext::json::forEach( value["inputs"], [&]( ext::json::Value& input ){ @@ -945,7 +945,7 @@ namespace { ext::json::forEach( json["channels"], [&]( ext::json::Value& value ){ auto& channel = animation.channels.emplace_back(); - channel.path = value["path"].as(); + channel.path = value["path"].as(); channel.node = value["node"].as(); channel.sampler = value["sampler"].as(); }); @@ -957,7 +957,7 @@ namespace { pod::Skin decodeSkin( ext::json::Value& json, const pod::Graph& graph ) { pod::Skin skin; - skin.name = json["name"].as(); + skin.name = json["name"].as(); skin.joints.reserve( json["joints"].size() ); ext::json::forEach( json["joints"], [&]( ext::json::Value& value ){ @@ -1001,9 +1001,9 @@ namespace { } // vertices are encoded as a raw buffer, referenced as a filename - if ( json["vertices"].is() ) { - const std::string filename = json["vertices"].as(); - const std::string directory = uf::io::directory( graph.name ); + if ( json["vertices"].is() ) { + const uf::stl::string filename = json["vertices"].as(); + const uf::stl::string directory = uf::io::directory( graph.name ); const auto buffer = uf::io::readAsBuffer( directory + "/" + filename ); if ( ext::json::isObject( json["metadata"]["vertices"] ) ) { size_t actualValue = buffer.size() / sizeof(pod::Graph::Mesh::vertex_t); @@ -1034,9 +1034,9 @@ namespace { UF_MSG_ERROR("invalid vertices information encountered while decoding mesh: " << graph.name ); } // indices are encoded as a raw buffer, referenced as a filename - if ( json["indices"].is() ) { - const std::string filename = json["indices"].as(); - const std::string directory = uf::io::directory( graph.name ); + if ( json["indices"].is() ) { + const uf::stl::string filename = json["indices"].as(); + const uf::stl::string directory = uf::io::directory( graph.name ); const auto buffer = uf::io::readAsBuffer( directory + "/" + filename ); if ( ext::json::isObject( json["metadata"]["indices"] ) ) { size_t actualValue = buffer.size() / sizeof(pod::Graph::Mesh::index_t); @@ -1064,7 +1064,7 @@ namespace { pod::Node decodeNode( ext::json::Value& json, const pod::Graph& graph ) { pod::Node node = pod::Node{ - .name = json["name"].as(), + .name = json["name"].as(), .index = json["index"].as(), .skin = json["skin"].as(-1), .parent = json["parent"].as(-1), @@ -1082,7 +1082,7 @@ namespace { } } -pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t mode, const uf::Serializer& metadata ) { +pod::Graph uf::graph::load( const uf::stl::string& filename, uf::graph::load_mode_t mode, const uf::Serializer& metadata ) { #if UF_ENV_DREAMCAST #define UF_DEBUG_TIMER_MULTITRACE_START(...) UF_TIMER_MULTITRACE_START(__VA_ARGS__) #define UF_DEBUG_TIMER_MULTITRACE(...) UF_TIMER_MULTITRACE(__VA_ARGS__) @@ -1092,30 +1092,30 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t #define UF_DEBUG_TIMER_MULTITRACE(...) #define UF_DEBUG_TIMER_MULTITRACE_END(...) #endif - const std::string extension = uf::io::extension( filename ); + const uf::stl::string extension = uf::io::extension( filename ); if ( extension == "glb" || extension == "gltf" ) return ext::gltf::load( filename, mode, metadata ); - const std::string directory = uf::io::directory( filename ) + "/"; + const uf::stl::string directory = uf::io::directory( filename ) + "/"; pod::Graph graph; uf::Serializer serializer; UF_DEBUG_TIMER_MULTITRACE_START("Reading " << filename); serializer.readFromFile( filename ); // load metadata - graph.name = filename; //serializer["name"].as(); + graph.name = filename; //serializer["name"].as(); graph.mode = mode; // serializer["mode"].as(); graph.metadata = metadata; // serializer["metadata"]; #if UF_GRAPH_LOAD_MULTITHREAD - std::vector> jobs; + uf::stl::vector> jobs; jobs.emplace_back([&]{ // load mesh information UF_DEBUG_TIMER_MULTITRACE("Reading meshes..."); graph.meshes.reserve( serializer["meshes"].size() ); ext::json::forEach( serializer["meshes"], [&]( ext::json::Value& value ){ auto& mesh = graph.meshes.emplace_back(); - if ( value.is() ) { - UF_DEBUG_TIMER_MULTITRACE(directory + "/" + value.as()); + if ( value.is() ) { + UF_DEBUG_TIMER_MULTITRACE(directory + "/" + value.as()); uf::Serializer json; - json.readFromFile( directory + "/" + value.as() ); + json.readFromFile( directory + "/" + value.as() ); decode( json, mesh, graph ); } else { decode( value, mesh, graph ); @@ -1129,8 +1129,8 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t UF_DEBUG_TIMER_MULTITRACE("Reading atlas..."); auto& image = graph.atlas.getAtlas(); auto& value = serializer["atlas"]; - if ( value.is() ) { - std::string filename = directory + "/" + value.as(); + if ( value.is() ) { + uf::stl::string filename = directory + "/" + value.as(); UF_DEBUG_TIMER_MULTITRACE("Reading atlas " << filename); image.open(filename, false); } else { @@ -1143,8 +1143,8 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t graph.images.reserve( serializer["images"].size() ); ext::json::forEach( serializer["images"], [&]( ext::json::Value& value ){ auto& image = graph.images.emplace_back(); - if ( value.is() ) { - std::string filename = directory + "/" + value.as(); + if ( value.is() ) { + uf::stl::string filename = directory + "/" + value.as(); UF_DEBUG_TIMER_MULTITRACE("Reading image " << filename); image.open(filename, false); } else { @@ -1194,13 +1194,13 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t UF_DEBUG_TIMER_MULTITRACE("Reading animation information..."); graph.animations.reserve( serializer["animations"].size() ); ext::json::forEach( serializer["animations"], [&]( ext::json::Value& value ){ - if ( value.is() ) { + if ( value.is() ) { uf::Serializer json; - json.readFromFile( directory + "/" + value.as() ); - std::string key = json["name"].as(); + json.readFromFile( directory + "/" + value.as() ); + uf::stl::string key = json["name"].as(); decode( json, graph.animations[key], graph ); } else { - std::string key = value["name"].as(); + uf::stl::string key = value["name"].as(); decode( value, graph.animations[key], graph ); } }); @@ -1232,10 +1232,10 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t graph.meshes.reserve( serializer["meshes"].size() ); ext::json::forEach( serializer["meshes"], [&]( ext::json::Value& value ){ auto& mesh = graph.meshes.emplace_back(); - if ( value.is() ) { - UF_DEBUG_TIMER_MULTITRACE(directory + "/" + value.as()); + if ( value.is() ) { + UF_DEBUG_TIMER_MULTITRACE(directory + "/" + value.as()); uf::Serializer json; - json.readFromFile( directory + "/" + value.as() ); + json.readFromFile( directory + "/" + value.as() ); decode( json, mesh, graph ); } else { @@ -1248,8 +1248,8 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t UF_DEBUG_TIMER_MULTITRACE("Reading atlas..."); auto& image = graph.atlas.getAtlas(); auto& value = serializer["atlas"]; - if ( value.is() ) { - std::string filename = directory + "/" + value.as(); + if ( value.is() ) { + uf::stl::string filename = directory + "/" + value.as(); UF_DEBUG_TIMER_MULTITRACE("Reading atlas " << filename); image.open(filename, false); } else { @@ -1261,8 +1261,8 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t graph.images.reserve( serializer["images"].size() ); ext::json::forEach( serializer["images"], [&]( ext::json::Value& value ){ auto& image = graph.images.emplace_back(); - if ( value.is() ) { - std::string filename = directory + "/" + value.as(); + if ( value.is() ) { + uf::stl::string filename = directory + "/" + value.as(); UF_DEBUG_TIMER_MULTITRACE("Reading image " << filename); image.open(filename, false); } else { @@ -1297,13 +1297,13 @@ pod::Graph uf::graph::load( const std::string& filename, uf::graph::load_mode_t UF_DEBUG_TIMER_MULTITRACE("Reading animation information..."); graph.animations.reserve( serializer["animations"].size() ); ext::json::forEach( serializer["animations"], [&]( ext::json::Value& value ){ - if ( value.is() ) { + if ( value.is() ) { uf::Serializer json; - json.readFromFile( directory + "/" + value.as() ); - std::string key = json["name"].as(); + json.readFromFile( directory + "/" + value.as() ); + uf::stl::string key = json["name"].as(); decode( json, graph.animations[key], graph ); } else { - std::string key = value["name"].as(); + uf::stl::string key = value["name"].as(); decode( value, graph.animations[key], graph ); } }); @@ -1344,7 +1344,7 @@ namespace { bool combined = false; bool encodeBuffers = true; bool unwrap = true; - std::string filename = ""; + uf::stl::string filename = ""; }; uf::Serializer encode( const uf::Image& image, const EncodingSettings& settings ) { @@ -1477,12 +1477,12 @@ namespace { ext::json::reserve( json["indices"], mesh.indices.size() ); for ( auto& index : mesh.indices ) json["indices"].emplace_back(index); } else { - const std::string verticesFilename = settings.filename + ".vertices." + ( settings.compress ? "gz" : "bin" ); + const uf::stl::string verticesFilename = settings.filename + ".vertices." + ( settings.compress ? "gz" : "bin" ); uf::io::write( verticesFilename, mesh.vertices.data(), mesh.vertices.size() * sizeof(pod::Graph::Mesh::vertex_t) ); json["vertices"] = uf::io::filename( verticesFilename ); if ( !mesh.indices.empty() ) { - const std::string indicesFilename = settings.filename + ".indices." + ( settings.compress ? "gz" : "bin" ); + const uf::stl::string indicesFilename = settings.filename + ".indices." + ( settings.compress ? "gz" : "bin" ); uf::io::write( indicesFilename, mesh.indices.data(), mesh.indices.size() * sizeof(pod::Graph::Mesh::index_t) ); json["indices"] = uf::io::filename( indicesFilename ); } @@ -1503,18 +1503,20 @@ namespace { return json; } } -void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { - std::string directory = uf::io::directory( filename ) + "/" + uf::io::basename(filename) + "/"; - std::string target = uf::io::directory( filename ) + "/" + uf::io::basename(filename) + ".graph"; +void uf::graph::save( const pod::Graph& graph, const uf::stl::string& filename ) { + uf::stl::string directory = uf::io::directory( filename ) + "/" + uf::io::basename(filename) + "/"; + uf::stl::string target = uf::io::directory( filename ) + "/" + uf::io::basename(filename) + ".graph"; uf::Serializer serializer; uf::Serializer metadata; const ::EncodingSettings settings = ::EncodingSettings{ - /*.pretty = */graph.metadata["export"]["pretty"].as(), - /*.compress = */graph.metadata["export"]["compress"].as(), - /*.quantize = */graph.metadata["export"]["quantize"].as(), - /*.precision = */graph.metadata["export"]["precision"].as(), + { + /*.pretty = */graph.metadata["export"]["pretty"].as(), + /*.compress = */graph.metadata["export"]["compress"].as(), + /*.quantize = */graph.metadata["export"]["quantize"].as(), + /*.precision = */graph.metadata["export"]["precision"].as(), + }, /*.combined = */graph.metadata["export"]["combined"].as(), /*.encodeBuffers = */graph.metadata["export"]["encode buffers"].as(true), /*.unwrap = */graph.metadata["export"]["unwrap"].as(true), @@ -1528,13 +1530,13 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { } #if UF_GRAPH_LOAD_MULTITHREAD - std::vector> jobs; + uf::stl::vector> jobs; // store images jobs.emplace_back([&]{ if ( graph.atlas.generated() ) { auto& image = graph.atlas.getAtlas(); if ( !settings.combined ) { - // std::string f = "atlas" + ( settings.compress?".jpg":".png" ); + // uf::stl::string f = "atlas" + ( settings.compress?".jpg":".png" ); // serializer["atlas"] = f; image.save(directory + "/atlas.png"); serializer["atlas"] = "atlas.png"; @@ -1545,8 +1547,8 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { ext::json::reserve( serializer["images"], graph.images.size() ); if ( !settings.combined ) { for ( size_t i = 0; i < graph.images.size(); ++i ) { - // std::string f = "image."+std::to_string(i)+(settings.compress?".jpg":".png"); - std::string f = "image."+std::to_string(i)+".png"; + // uf::stl::string f = "image."+std::to_string(i)+(settings.compress?".jpg":".png"); + uf::stl::string f = "image."+std::to_string(i)+".png"; graph.images[i].save(directory + "/" + f); serializer["images"].emplace_back(f); } @@ -1584,7 +1586,7 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { ext::json::reserve( serializer["animations"], graph.animations.size() ); if ( !settings.combined ) { for ( auto pair : graph.animations ) { - std::string f = "animation."+pair.first+".json"; + uf::stl::string f = "animation."+pair.first+".json"; encode(pair.second, settings).writeToFile(directory+"/animation."+pair.first+".json", settings); serializer["animations"].emplace_back("animation."+pair.first+".json" + (settings.compress ? ".gz" : "")); } @@ -1632,7 +1634,7 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { if ( graph.atlas.generated() ) { auto& image = graph.atlas.getAtlas(); if ( !settings.combined ) { - // std::string f = "atlas" + ( settings.compress?".jpg":".png" ); + // uf::stl::string f = "atlas" + ( settings.compress?".jpg":".png" ); // serializer["atlas"] = f; image.save(directory + "/atlas.png"); serializer["atlas"] = "atlas.png"; @@ -1643,8 +1645,8 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { ext::json::reserve( serializer["images"], graph.images.size() ); if ( !settings.combined ) { for ( size_t i = 0; i < graph.images.size(); ++i ) { - // std::string f = "image."+std::to_string(i)+(settings.compress?".jpg":".png"); - std::string f = "image."+std::to_string(i)+".png"; + // uf::stl::string f = "image."+std::to_string(i)+(settings.compress?".jpg":".png"); + uf::stl::string f = "image."+std::to_string(i)+".png"; graph.images[i].save(directory + "/" + f); serializer["images"].emplace_back(f); } @@ -1667,7 +1669,7 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { ext::json::reserve( serializer["animations"], graph.animations.size() ); if ( !settings.combined ) { for ( auto pair : graph.animations ) { - std::string f = "animation."+pair.first+".json"; + uf::stl::string f = "animation."+pair.first+".json"; encode(pair.second, settings).writeToFile(directory+"/animation."+pair.first+".json", settings); serializer["animations"].emplace_back("animation."+pair.first+".json" + (settings.compress ? ".gz" : "")); } @@ -1705,8 +1707,8 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) { serializer.writeToFile( target, settings ); } -std::string uf::graph::print( const pod::Graph& graph ) { - std::stringstream ss; +uf::stl::string uf::graph::print( const pod::Graph& graph ) { + uf::stl::stringstream ss; ss << "Graph Data:" "\n\tImages: " << graph.images.size() << "" "\n\tTextures: " << graph.textures.size() << "" diff --git a/engine/src/engine/instantiator/instantiator.cpp b/engine/src/engine/instantiator/instantiator.cpp index 23bbd7f5..fac59bd5 100644 --- a/engine/src/engine/instantiator/instantiator.cpp +++ b/engine/src/engine/instantiator/instantiator.cpp @@ -5,7 +5,7 @@ pod::NamedTypes* uf::instantiator::objects = NULL; //pod::NamedTypes* uf::instantiator::behaviors = NULL; -std::unordered_map* uf::instantiator::behaviors = NULL; +uf::stl::unordered_map* uf::instantiator::behaviors = NULL; uf::Entity* uf::instantiator::reuse( size_t size ) { uf::Entity* laxed = NULL; @@ -48,16 +48,16 @@ size_t uf::instantiator::collect( uint8_t level ) { uf::Entity* uf::instantiator::alloc( size_t size ) { // auto* reused = reuse( size ); if ( reused ) return reused; #if UF_MEMORYPOOL_INVALID_MALLOC - uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::MemoryPool::global; - return (uf::Entity*) memoryPool.alloc( NULL, size ); + uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::memoryPool::global; + return (uf::Entity*) memoryPool.alloc( nullptr, size ); #else uf::Entity* pointer = NULL; uf::MemoryPool* memoryPool = NULL; if ( uf::Entity::memoryPool.size() > 0 ) memoryPool = &uf::Entity::memoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) - memoryPool = &uf::MemoryPool::global; - if ( memoryPool ) pointer = (uf::Entity*) memoryPool->alloc( NULL, size ); + else if ( uf::memoryPool::global.size() > 0 ) + memoryPool = &uf::memoryPool::global; + if ( memoryPool ) pointer = (uf::Entity*) memoryPool->alloc( nullptr, size ); else pointer = (uf::Entity*) malloc( size ); return pointer; #endif @@ -68,42 +68,42 @@ void uf::instantiator::free( uf::Entity* pointer ) { // pointer->destroyComponents(); #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::MemoryPool::global; + uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::memoryPool::global; memoryPool.free( pointer ); #else uf::MemoryPool* memoryPool = NULL; if ( uf::Entity::memoryPool.size() > 0 ) memoryPool = &uf::Entity::memoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) - memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) + memoryPool = &uf::memoryPool::global; if ( memoryPool ) memoryPool->free( pointer ); else ::free( pointer ); #endif } bool uf::instantiator::valid( uf::Entity* pointer ) { #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::MemoryPool::global; + uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::memoryPool::global; return memoryPool.exists( pointer ); #else uf::MemoryPool* memoryPool = NULL; if ( uf::Entity::memoryPool.size() > 0 ) memoryPool = &uf::Entity::memoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) - memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) + memoryPool = &uf::memoryPool::global; return memoryPool ? memoryPool->exists( pointer ) : pointer && pointer->isValid(); #endif } -void uf::instantiator::registerBehavior( const std::string& name, const pod::Behavior& behavior ) { - if ( !uf::instantiator::behaviors ) uf::instantiator::behaviors = new std::unordered_map;\ +void uf::instantiator::registerBehavior( const uf::stl::string& name, const pod::Behavior& behavior ) { + if ( !uf::instantiator::behaviors ) uf::instantiator::behaviors = new uf::stl::unordered_map;\ (*uf::instantiator::behaviors)[name] = behavior; #if UF_INSTANTIATOR_ANNOUNCE UF_MSG_DEBUG("Registered behavior for " << name << " | " << behavior.type); #endif } -void uf::instantiator::registerBinding( const std::string& object, const std::string& behavior ) { +void uf::instantiator::registerBinding( const uf::stl::string& object, const uf::stl::string& behavior ) { if ( !objects ) objects = new pod::NamedTypes; - if ( !behaviors ) behaviors = new std::unordered_map; + if ( !behaviors ) behaviors = new uf::stl::unordered_map; auto& instantiator = uf::instantiator::objects->get( object ); instantiator.behaviors.emplace_back( behavior ); @@ -112,7 +112,7 @@ void uf::instantiator::registerBinding( const std::string& object, const std::st #endif } -uf::Entity& uf::instantiator::instantiate( const std::string& name ) { +uf::Entity& uf::instantiator::instantiate( const uf::stl::string& name ) { if ( !uf::instantiator::objects->has( name ) ) { auto& object = uf::instantiator::instantiate(); return *((uf::Entity*) &object); @@ -123,7 +123,7 @@ uf::Entity& uf::instantiator::instantiate( const std::string& name ) { return entity; } -void uf::instantiator::bind( const std::string& name, uf::Entity& entity ) { +void uf::instantiator::bind( const uf::stl::string& name, uf::Entity& entity ) { // was actually a behavior name, single bind if ( !uf::instantiator::objects->has( name, false ) ) { if ( uf::instantiator::behaviors->count( name ) == 0 ) return; @@ -144,10 +144,10 @@ void uf::instantiator::bind( const std::string& name, uf::Entity& entity ) { } } -void uf::instantiator::unbind( const std::string& name, uf::Entity& entity ) { +void uf::instantiator::unbind( const uf::stl::string& name, uf::Entity& entity ) { // was actually a behavior name, single bind if ( !uf::instantiator::objects->has( name, false ) ) { - if ( !uf::instantiator::behaviors->count( name ) == 0 ) return; + if ( uf::instantiator::behaviors->count( name ) > 0 ) return; auto& behavior = (*uf::instantiator::behaviors)[name]; entity.removeBehavior(behavior); return; diff --git a/engine/src/engine/object/behavior.cpp b/engine/src/engine/object/behavior.cpp index f4dd6708..329f03aa 100644 --- a/engine/src/engine/object/behavior.cpp +++ b/engine/src/engine/object/behavior.cpp @@ -36,7 +36,7 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) { this->addHook( "object:TransformReferenceController.%UID%", [&](ext::json::Value& json){ auto& transform = this->getComponent>(); auto& controller = scene.getController(); - if ( json["target"].as() == "camera" ) { + if ( json["target"].as() == "camera" ) { auto& camera = controller.getComponent(); transform.reference = &camera.getTransform(); } else { @@ -45,21 +45,21 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) { }); this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ if ( ext::json::isNull( json ) ) return; - if ( json["type"].as() == "merge" ) { + if ( json["type"].as() == "merge" ) { metadataJson.merge(json["value"], true); - } else if ( json["type"].as() == "import" ) { + } else if ( json["type"].as() == "import" ) { metadataJson.import(json["value"]); - } else if ( json["path"].is() ) { - metadataJson.path(json["path"].as()) = json["value"]; + } else if ( json["path"].is() ) { + metadataJson.path(json["path"].as()) = json["value"]; } else { metadataJson.merge(json, true); } }); this->addHook( "asset:QueueLoad.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string hash = json["hash"].as(); - std::string category = json["category"].as(); - std::string callback = this->formatHookName("asset:FinishedLoad.%UID%"); + uf::stl::string filename = json["filename"].as(); + uf::stl::string hash = json["hash"].as(); + uf::stl::string category = json["category"].as(); + uf::stl::string callback = this->formatHookName("asset:FinishedLoad.%UID%"); if ( json["single threaded"].as() ) { assetLoader.load( filename, hash, category ); this->queueHook( callback, json ); @@ -72,8 +72,8 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) { this->queueHook("asset:Parsed.%UID%", json); }); this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); bool initialize = ext::json::isNull( json["initialize"] ) ? true : json["initialize"].as(); if ( category != "" && category != "entities" ) return; if ( category == "" && uf::io::extension(filename) != "json" ) return; @@ -108,7 +108,7 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) { }; metadata.deserialize = [&](){ metadata.transform.initial = this->getComponent>(); - metadata.transform.trackParent = metadataJson["system"]["transform"]["track"].as() == "parent"; + metadata.transform.trackParent = metadataJson["system"]["transform"]["track"].as() == "parent"; }; this->addHook( "object:UpdateMetadata.%UID%", metadata.deserialize); metadata.deserialize(); @@ -120,10 +120,10 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) { if ( !ext::json::isNull( metadataJson["system"]["physics"]["inertia"] ) ) { collider.inertia = uf::vector::decode( metadataJson["system"]["physics"]["inertia"], pod::Vector3f{} ); } - if ( metadataJson["system"]["physics"]["type"].as() == "BoundingBox" ) { + if ( metadataJson["system"]["physics"]["type"].as() == "BoundingBox" ) { pod::Vector3f corner = uf::vector::decode( metadataJson["system"]["physics"]["corner"], pod::Vector3f{0.5, 0.5, 0.5} ); ext::bullet::create( *this, corner, mass ); - } else if ( metadataJson["system"]["physics"]["type"].as() == "Capsule" ) { + } else if ( metadataJson["system"]["physics"]["type"].as() == "Capsule" ) { float radius = metadataJson["system"]["physics"]["radius"].as(); float height = metadataJson["system"]["physics"]["height"].as(); ext::bullet::create( *this, radius, height, mass ); @@ -143,7 +143,7 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) { void uf::ObjectBehavior::destroy( uf::Object& self ) { #if UF_ENTITY_METADATA_USE_JSON auto& metadata = this->getComponent(); - ext::json::forEach( metadata["system"]["hooks"]["bound"], [&]( const std::string& key, ext::json::Value& value ){ + ext::json::forEach( metadata["system"]["hooks"]["bound"], [&]( const uf::stl::string& key, ext::json::Value& value ){ ext::json::forEach( value, [&]( ext::json::Value& id ){ uf::hooks.removeHook(key, id.as()); }); @@ -221,7 +221,7 @@ void uf::ObjectBehavior::tick( uf::Object& self ) { auto& metadataJson = this->getComponent(); #if !UF_ENV_DREAMCAST if ( metadataJson["system"]["hot reload"]["enabled"].as() ) { - size_t mtime = uf::io::mtime( metadataJson["system"]["source"].as() ); + size_t mtime = uf::io::mtime( metadataJson["system"]["source"].as() ); if ( metadataJson["system"]["hot reload"]["mtime"].as() < mtime ) { metadataJson["system"]["hot reload"]["mtime"] = mtime; this->reload(); @@ -238,7 +238,7 @@ void uf::ObjectBehavior::tick( uf::Object& self ) { ext::json::forEach(queue, [&](ext::json::Value& member){ if ( !ext::json::isObject(member) ) return; uf::Serializer payload = member["payload"]; - std::string name = member["name"].as(); + uf::stl::string name = member["name"].as(); float timeout = member["timeout"].as(); if ( timeout < curTime ) this->callHook( name, payload ); else newQueue.emplace_back(member); diff --git a/engine/src/engine/object/behaviors/gltf.cpp b/engine/src/engine/object/behaviors/gltf.cpp index 98cceab0..8be050f4 100644 --- a/engine/src/engine/object/behaviors/gltf.cpp +++ b/engine/src/engine/object/behaviors/gltf.cpp @@ -18,15 +18,15 @@ UF_BEHAVIOR_REGISTER_CPP(uf::GltfBehavior) void uf::GltfBehavior::initialize( uf::Object& self ) { auto& metadata = this->getComponent(); this->addHook( "animation:Set.%UID%", [&](ext::json::Value& json){ - std::string name = json["name"].as(); + uf::stl::string name = json["name"].as(); if ( !this->hasComponent() ) return; auto& graph = this->getComponent(); uf::graph::animate( graph, name ); }); this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); if ( category != "" && category != "models" ) return; if ( category == "" && uf::io::extension(filename) != "gltf" && uf::io::extension(filename) != "glb" && uf::io::extension(filename) != "graph" ) return; auto& scene = uf::scene::getCurrentScene(); @@ -55,8 +55,8 @@ void uf::GltfBehavior::initialize( uf::Object& self ) { uf::graph::initialize( graph ); if ( graph.metadata["flags"]["SKINNED"].as() ) { - if ( metadata["model"]["animation"].is() ) { - uf::graph::animate( graph, metadata["model"]["animation"].as() ); + if ( metadata["model"]["animation"].is() ) { + uf::graph::animate( graph, metadata["model"]["animation"].as() ); } /* if ( metadata["model"]["print animations"].as() ) { @@ -101,7 +101,7 @@ void uf::GltfBehavior::tick( uf::Object& self ) { auto& mesh = this->getComponent(); if ( !(graph.metadata["flags"]["SEPARATE"].as()) ) { - std::vector instances( graph.nodes.size() ); + uf::stl::vector instances( graph.nodes.size() ); for ( size_t i = 0; i < graph.nodes.size(); ++i ) { auto& node = graph.nodes[i]; instances[i] = node.entity ? uf::transform::model( node.entity->getComponent>() ) : uf::transform::model( node.transform ); @@ -118,7 +118,7 @@ void uf::GltfBehavior::tick( uf::Object& self ) { auto& shader = graphic.material.getShader("vertex"); if ( !(graph.metadata["flags"]["SEPARATE"].as()) ) { - std::vector instances( graph.nodes.size() ); + uf::stl::vector instances( graph.nodes.size() ); for ( size_t i = 0; i < graph.nodes.size(); ++i ) { auto& node = graph.nodes[i]; instances[i] = node.entity ? uf::transform::model( node.entity->getComponent>() ) : uf::transform::model( node.transform ); @@ -140,7 +140,7 @@ void uf::GltfBehavior::tick( uf::Object& self ) { #if 0 if ( graphic.material.hasShader("vertex") && !(graph.metadata["flags"]["SEPARATE"].as()) ) { auto& shader = graphic.material.getShader("vertex"); - std::vector instances( graph.nodes.size() ); + uf::stl::vector instances( graph.nodes.size() ); for ( size_t i = 0; i < graph.nodes.size(); ++i ) { auto& node = graph.nodes[i]; instances[i] = node.entity ? uf::transform::model( node.entity->getComponent>() ) : uf::transform::model( node.transform ); diff --git a/engine/src/engine/object/behaviors/lua.cpp b/engine/src/engine/object/behaviors/lua.cpp index da2147e8..13bca37f 100644 --- a/engine/src/engine/object/behaviors/lua.cpp +++ b/engine/src/engine/object/behaviors/lua.cpp @@ -17,8 +17,8 @@ UF_BEHAVIOR_REGISTER_CPP(uf::LuaBehavior) void uf::LuaBehavior::initialize( uf::Object& self ) { #if UF_USE_LUA this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); if ( category != "" && category != "scripts" ) return; if ( category == "" && uf::io::extension(filename) != "lua" ) return; uf::Scene& scene = uf::scene::getCurrentScene(); diff --git a/engine/src/engine/object/object.cpp b/engine/src/engine/object/object.cpp index 87621a55..fbad2f50 100644 --- a/engine/src/engine/object/object.cpp +++ b/engine/src/engine/object/object.cpp @@ -20,7 +20,7 @@ UF_OBJECT_REGISTER_BEGIN(uf::Object) UF_OBJECT_REGISTER_BEHAVIOR(uf::ObjectBehavior) UF_OBJECT_REGISTER_END() uf::Object::Object() UF_BEHAVIOR_ENTITY_CPP_ATTACH(uf::Object) -void uf::Object::queueHook( const std::string& name, const ext::json::Value& payload, double timeout ) { +void uf::Object::queueHook( const uf::stl::string& name, const ext::json::Value& payload, double timeout ) { if ( !uf::Object::timer.running() ) uf::Object::timer.start(); double start = uf::Object::timer.elapsed().asDouble(); #if UF_ENTITY_METADATA_USE_JSON @@ -39,55 +39,55 @@ void uf::Object::queueHook( const std::string& name, const ext::json::Value& pay }); #endif } -std::string uf::Object::formatHookName( const std::string& n, size_t uid, bool fetch ) { +uf::stl::string uf::Object::formatHookName( const uf::stl::string& n, size_t uid, bool fetch ) { if ( fetch ) { uf::Object* object = (uf::Object*) uf::Entity::globalFindByUid( uid ); if ( object ) return object->formatHookName( n ); } - std::unordered_map formats = { + uf::stl::unordered_map formats = { {"%UID%", std::to_string(uid)}, }; - std::string name = n; + uf::stl::string name = n; for ( auto& pair : formats ) { name = uf::string::replace( name, pair.first, pair.second ); } return name; } -std::string uf::Object::formatHookName( const std::string& n ) { +uf::stl::string uf::Object::formatHookName( const uf::stl::string& n ) { size_t uid = this->getUid(); size_t parent = uid; if ( this->hasParent() ) { parent = this->getParent().getUid(); } - std::unordered_map formats = { + uf::stl::unordered_map formats = { {"%UID%", std::to_string(uid)}, {"%P-UID%", std::to_string(parent)}, }; - std::string name = n; + uf::stl::string name = n; for ( auto& pair : formats ) { name = uf::string::replace( name, pair.first, pair.second ); } return name; } -uf::Hooks::return_t uf::Object::callHook( const std::string& name ) { +uf::Hooks::return_t uf::Object::callHook( const uf::stl::string& name ) { return uf::hooks.call( this->formatHookName( name ), ext::json::null() ); } -uf::Hooks::return_t uf::Object::callHook( const std::string& name, const ext::json::Value& json ) { +uf::Hooks::return_t uf::Object::callHook( const uf::stl::string& name, const ext::json::Value& json ) { return uf::hooks.call( this->formatHookName( name ), json ); } -uf::Hooks::return_t uf::Object::callHook( const std::string& name, const uf::Serializer& serializer ) { +uf::Hooks::return_t uf::Object::callHook( const uf::stl::string& name, const uf::Serializer& serializer ) { return uf::hooks.call( this->formatHookName( name ), (const ext::json::Value&) serializer ); } -bool uf::Object::load( const std::string& f, bool inheritRoot ) { +bool uf::Object::load( const uf::stl::string& f, bool inheritRoot ) { uf::Serializer json; - std::string root = ""; + uf::stl::string root = ""; if ( inheritRoot && this->hasParent() ) { auto& parent = this->getParent(); uf::Serializer& metadata = parent.getComponent(); - root = metadata["system"]["root"].as(); + root = metadata["system"]["root"].as(); } - std::string filename = uf::io::resolveURI( f, root ); + uf::stl::string filename = uf::io::resolveURI( f, root ); if ( !json.readFromFile( filename ) ) return false; json["root"] = uf::io::directory(filename); @@ -104,15 +104,15 @@ bool uf::Object::load( const std::string& f, bool inheritRoot ) { bool uf::Object::reload( bool hard ) { uf::Serializer& metadata = this->getComponent(); - if ( !metadata["system"]["source"].is() ) return false; + if ( !metadata["system"]["source"].is() ) return false; uf::Serializer json; uf::Serializer payload; - std::string filename = metadata["system"]["source"].as(); + uf::stl::string filename = metadata["system"]["source"].as(); if ( !json.readFromFile( filename ) ) return false; if ( hard ) return this->load(filename); payload["old"] = metadata; - ext::json::forEach( json["metadata"], [&]( const std::string& key, const ext::json::Value& value ){ + ext::json::forEach( json["metadata"], [&]( const uf::stl::string& key, const ext::json::Value& value ){ metadata[key] = value; }); // update transform if requested @@ -131,20 +131,20 @@ bool uf::Object::load( const uf::Serializer& _json ) { uf::Serializer& metadata = this->getComponent(); uf::Serializer json = _json; // import - if ( json["import"].is() || json["include"].is() ) { + if ( json["import"].is() || json["include"].is() ) { uf::Serializer chain = json; - std::string root = json["root"].as(); + uf::stl::string root = json["root"].as(); uf::Serializer separated; separated["assets"] = json["assets"]; separated["behaviors"] = json["behaviors"]; do { - std::string filename = chain["import"].is() ? chain["import"].as() : chain["include"].as(); + uf::stl::string filename = chain["import"].is() ? chain["import"].as() : chain["include"].as(); filename = uf::io::resolveURI( filename, root ); chain.readFromFile( filename ); root = uf::io::directory( filename ); ext::json::forEach(chain["assets"], [&](ext::json::Value& value){ - if ( ext::json::isObject( value ) ) value["filename"] = uf::io::resolveURI( value["filename"].as(), root ); - else value = uf::io::resolveURI( value.as(), root ); + if ( ext::json::isObject( value ) ) value["filename"] = uf::io::resolveURI( value["filename"].as(), root ); + else value = uf::io::resolveURI( value.as(), root ); separated["assets"].emplace_back( value ); }); ext::json::forEach(chain["behaviors"], [&](ext::json::Value& value){ @@ -154,13 +154,13 @@ bool uf::Object::load( const uf::Serializer& _json ) { chain["behaviors"] = ext::json::null(); // merge table json.import( chain ); - } while ( chain["import"].is() || chain["include"].is() ); + } while ( chain["import"].is() || chain["include"].is() ); json["import"] = ext::json::null(); json["assets"] = separated["assets"]; json["behaviors"] = separated["behaviors"]; } // copy system table to base - ext::json::forEach( json["system"], [&](const std::string& key, const ext::json::Value& value){ + ext::json::forEach( json["system"], [&](const uf::stl::string& key, const ext::json::Value& value){ if ( ext::json::isNull( json[key] ) ) json[key] = value; }); @@ -174,7 +174,7 @@ bool uf::Object::load( const uf::Serializer& _json ) { #endif // Basic entity information // Set name - this->m_name = json["name"].is() ? json["name"].as() : json["type"].as(); + this->m_name = json["name"].is() ? json["name"].as() : json["type"].as(); uf::Scene& scene = uf::scene::getCurrentScene(); uf::Asset& assetLoader = scene.getComponent(); // Set transform @@ -187,7 +187,7 @@ bool uf::Object::load( const uf::Serializer& _json ) { if ( load && ext::json::isObject( json["transform"] ) ) { pod::Transform<>& transform = this->getComponent>(); transform = uf::transform::decode(json["transform"], transform); - if ( json["transform"]["reference"].as() == "parent" ) { + if ( json["transform"]["reference"].as() == "parent" ) { auto& parent = this->getParent().as(); transform.reference = &parent.getComponent>(); } @@ -214,7 +214,7 @@ bool uf::Object::load( const uf::Serializer& _json ) { } #define UF_OBJECT_LOAD_ASSET_HEADER(type)\ - std::string assetCategory = #type;\ + uf::stl::string assetCategory = #type;\ uf::Serializer target;\ bool override = false;\ if ( ext::json::isObject( metadata["system"]["assets"] ) ) {\ @@ -225,20 +225,20 @@ bool uf::Object::load( const uf::Serializer& _json ) { target = json["assets"][#type];\ } - std::vector rejects; + uf::stl::vector rejects; #define UF_OBJECT_LOAD_ASSET(...)\ bool isObject = ext::json::isObject( target[i] );\ - std::string canonical = "";\ - std::string hash = isObject ? target[i]["hash"].as() : "";\ - std::string f = isObject ? target[i]["filename"].as() : target[i].as();\ + uf::stl::string canonical = "";\ + uf::stl::string hash = isObject ? target[i]["hash"].as() : "";\ + uf::stl::string f = isObject ? target[i]["filename"].as() : target[i].as();\ float delay = isObject ? target[i]["delay"].as() : 0;\ - std::string category = isObject ? target[i]["category"].as() : "";\ + uf::stl::string category = isObject ? target[i]["category"].as() : "";\ bool bind = isObject && target[i]["bind"].is() ? target[i]["bind"].as() : true;\ - std::string filename = uf::io::resolveURI( f, json["root"].as() );\ + uf::stl::string filename = uf::io::resolveURI( f, json["root"].as() );\ bool singleThreaded = isObject ? target[i]["single threaded"].as() : false;\ bool overriden = isObject ? target[i]["override"].as() : false;\ - std::vector allowedExtensions = {__VA_ARGS__};\ - std::string extension = uf::io::extension(filename);\ + uf::stl::vector allowedExtensions = {__VA_ARGS__};\ + uf::stl::string extension = uf::io::extension(filename);\ if ( override && overriden ) {\ if ( category == "" ) continue;\ } else {\ @@ -299,7 +299,7 @@ bool uf::Object::load( const uf::Serializer& _json ) { } // Bind behaviors { - if ( json["type"].is() ) uf::instantiator::bind( json["type"].as(), *this ); + if ( json["type"].is() ) uf::instantiator::bind( json["type"].as(), *this ); uf::Serializer target; if ( ext::json::isArray( metadata["system"]["behaviors"] ) ) { @@ -308,16 +308,16 @@ bool uf::Object::load( const uf::Serializer& _json ) { target = json["behaviors"]; } for ( size_t i = 0; i < target.size(); ++i ) { - uf::instantiator::bind( target[i].as(), *this ); + uf::instantiator::bind( target[i].as(), *this ); } } uf::Serializer hooks = metadata["system"]["hooks"]; // Metadata if ( !ext::json::isNull( json["metadata"] ) ) { uf::Serializer& metadata = this->getComponent(); - if ( json["metadata"].is() ) { - std::string f = json["metadata"].as(); - std::string filename = uf::io::resolveURI( json["metadata"].as(), json["root"].as() ); + if ( json["metadata"].is() ) { + uf::stl::string f = json["metadata"].as(); + uf::stl::string filename = uf::io::resolveURI( json["metadata"].as(), json["root"].as() ); if ( !metadata.readFromFile(filename) ) return false; } else { metadata = json["metadata"]; @@ -331,12 +331,12 @@ bool uf::Object::load( const uf::Serializer& _json ) { { UF_OBJECT_LOAD_ASSET_HEADER(entities) for ( size_t i = 0; i < target.size(); ++i ) { - std::string canonical = ""; - std::string hash = ext::json::isObject( target[i] ) ? target[i]["hash"].as() : ""; - std::string f = ext::json::isObject( target[i] ) ? target[i]["filename"].as() : target[i].as(); + uf::stl::string canonical = ""; + uf::stl::string hash = ext::json::isObject( target[i] ) ? target[i]["hash"].as() : ""; + uf::stl::string f = ext::json::isObject( target[i] ) ? target[i]["filename"].as() : target[i].as(); float delay = ext::json::isObject( target[i] ) ? target[i]["delay"].as() : -1; - std::string category = ext::json::isObject( target[i] ) ? target[i]["category"].as() : "";\ - std::string filename = uf::io::resolveURI( f, json["root"].as() ); + uf::stl::string category = ext::json::isObject( target[i] ) ? target[i]["category"].as() : "";\ + uf::stl::string filename = uf::io::resolveURI( f, json["root"].as() ); if ( category != "" && category != assetCategory ) continue; if ( category == "" && uf::io::extension(filename) != "json" ) continue; if ( (canonical = assetLoader.load( filename, hash )) == "" ) continue; @@ -379,7 +379,7 @@ bool uf::Object::load( const uf::Serializer& _json ) { auto& lightTransform = light->getComponent>(); auto& lightMetadata = light->getComponent(); lightTransform = uf::transform::decode( json["transform"], lightTransform ); - ext::json::forEach( json, [&]( const std::string& key, ext::json::Value& value ){ + ext::json::forEach( json, [&]( const uf::stl::string& key, ext::json::Value& value ){ if ( key == "transform" ) return; lightMetadata["light"][key] = value; }); @@ -389,10 +389,10 @@ bool uf::Object::load( const uf::Serializer& _json ) { return true; } -uf::Object& uf::Object::loadChild( const std::string& f, bool initialize ) { +uf::Object& uf::Object::loadChild( const uf::stl::string& f, bool initialize ) { uf::Serializer& metadata = this->getComponent(); uf::Serializer json; - std::string filename = uf::io::resolveURI( f, metadata["system"]["root"].as() ); + uf::stl::string filename = uf::io::resolveURI( f, metadata["system"]["root"].as() ); if ( !json.readFromFile(filename) ) { return ::null; } @@ -412,7 +412,7 @@ uf::Object& uf::Object::loadChild( const std::string& f, bool initialize ) { } uf::Object& uf::Object::loadChild( const uf::Serializer& _json, bool initialize ) { uf::Serializer json = _json; - std::string type = json["type"].as(); + uf::stl::string type = json["type"].as(); if ( type == "" ) type = "Object"; if ( json["ignore"].as() ) return ::null; @@ -426,7 +426,7 @@ uf::Object& uf::Object::loadChild( const uf::Serializer& _json, bool initialize if ( initialize ) entity.initialize(); return object; } -uf::Object* uf::Object::loadChildPointer( const std::string& f, bool initialize ) { +uf::Object* uf::Object::loadChildPointer( const uf::stl::string& f, bool initialize ) { uf::Object* pointer = &this->loadChild(f, initialize); return pointer != &::null ? pointer : NULL; } @@ -434,7 +434,7 @@ uf::Object* uf::Object::loadChildPointer( const uf::Serializer& json, bool initi uf::Object* pointer = &this->loadChild(json, initialize); return pointer != &::null ? pointer : NULL; } -std::size_t uf::Object::loadChildUid( const std::string& f, bool initialize ) { +std::size_t uf::Object::loadChildUid( const uf::stl::string& f, bool initialize ) { uf::Object* pointer = this->loadChildPointer(f, initialize); return pointer ? pointer->getUid() : -1; } @@ -443,14 +443,14 @@ std::size_t uf::Object::loadChildUid( const uf::Serializer& json, bool initializ return pointer ? pointer->getUid() : -1; } -std::string uf::Object::grabURI( const std::string& filename, const std::string& root ) { +uf::stl::string uf::Object::grabURI( const uf::stl::string& filename, const uf::stl::string& root ) { return uf::io::resolveURI( filename, root ); } #include -std::string uf::string::toString( const uf::Object& object ) { - std::stringstream ss; +uf::stl::string uf::string::toString( const uf::Object& object ) { + uf::stl::stringstream ss; ss << object.getName() << ": " << object.getUid(); return ss.str(); } \ No newline at end of file diff --git a/engine/src/engine/scene/scene.cpp b/engine/src/engine/scene/scene.cpp index aa070146..7bfced79 100644 --- a/engine/src/engine/scene/scene.cpp +++ b/engine/src/engine/scene/scene.cpp @@ -51,7 +51,7 @@ void uf::Scene::invalidateGraph() { metadata.cached.renderMode = NULL; metadata.cached.controller = NULL; } -const std::vector& uf::Scene::getGraph() { +const uf::stl::vector& uf::Scene::getGraph() { // auto& metadata = this->getComponent(); if ( metadata.invalidationQueued ) { metadata.invalidationQueued = false; @@ -64,18 +64,18 @@ const std::vector& uf::Scene::getGraph() { uf::renderer::states::rebuild = true; return metadata.graph; } -std::vector uf::Scene::getGraph( bool reverse ) { +uf::stl::vector uf::Scene::getGraph( bool reverse ) { auto graph = this->getGraph(); if ( reverse ) std::reverse( graph.begin(), graph.end() ); return graph; } -std::vector uf::scene::scenes; -uf::Scene& uf::scene::loadScene( const std::string& name, const std::string& _filename ) { +uf::stl::vector uf::scene::scenes; +uf::Scene& uf::scene::loadScene( const uf::stl::string& name, const uf::stl::string& _filename ) { uf::Scene* scene = uf::instantiator::objects->has( name ) ? (uf::Scene*) &uf::instantiator::instantiate( name ) : new uf::Scene; uf::scene::scenes.emplace_back( scene ); - const std::string filename = _filename != "" ? _filename : ("/" + uf::string::lowercase(name) + "/scene.json"); + const uf::stl::string filename = _filename != "" ? _filename : ("/" + uf::string::lowercase(name) + "/scene.json"); scene->load(filename); if ( uf::renderer::settings::experimental::vxgi ) { uf::instantiator::bind( "VoxelizerBehavior", *scene ); @@ -83,7 +83,7 @@ uf::Scene& uf::scene::loadScene( const std::string& name, const std::string& _fi scene->initialize(); return *scene; } -uf::Scene& uf::scene::loadScene( const std::string& name, const uf::Serializer& data ) { +uf::Scene& uf::scene::loadScene( const uf::stl::string& name, const uf::Serializer& data ) { uf::Scene* scene = uf::instantiator::objects->has( name ) ? (uf::Scene*) &uf::instantiator::instantiate( name ) : new uf::Scene; uf::scene::scenes.emplace_back( scene ); if ( data != "" ) scene->load(data); diff --git a/engine/src/ext/bullet/bullet.cpp b/engine/src/ext/bullet/bullet.cpp index ac9baac6..86da5f92 100644 --- a/engine/src/ext/bullet/bullet.cpp +++ b/engine/src/ext/bullet/bullet.cpp @@ -71,7 +71,7 @@ namespace ext { btDiscreteDynamicsWorld* dynamicsWorld = NULL; btAlignedObjectArray collisionShapes; - std::unordered_map rigidBodyMap; + uf::stl::unordered_map rigidBodyMap; BulletDebugDrawer debugDrawer; } @@ -284,11 +284,11 @@ pod::Bullet& ext::bullet::create( uf::Object& object, const uf::BaseGeometry& me size_t indices = mesh.attributes.index.length; size_t indexStride = mesh.attributes.index.size; - void* indexPointer = (void*) mesh.attributes.index.pointer; + uint8_t* indexPointer = (uint8_t*) mesh.attributes.index.pointer; size_t vertices = mesh.attributes.vertex.length; size_t vertexStride = mesh.attributes.vertex.size; - void* vertexPointer = (void*) mesh.attributes.vertex.pointer; + uint8_t* vertexPointer = (uint8_t*) mesh.attributes.vertex.pointer; uf::renderer::VertexDescriptor vertexAttributePosition; for ( auto& attribute : mesh.attributes.descriptor ) { @@ -299,7 +299,7 @@ pod::Bullet& ext::bullet::create( uf::Object& object, const uf::BaseGeometry& me btTriangleMesh* bMesh = new btTriangleMesh( true, false ); bMesh->preallocateVertices( vertices ); for ( size_t currentIndex = 0; currentIndex < vertices; ++currentIndex ) { - void* vertexSrc = vertexPointer + (currentIndex * vertexStride); + uint8_t* vertexSrc = vertexPointer + (currentIndex * vertexStride); const pod::Vector3f& position = *((pod::Vector3f*) (vertexSrc + vertexAttributePosition.offset)); bMesh->findOrAddVertex( btVector3( position.x, position.y, position.z ), false ); } @@ -307,7 +307,7 @@ pod::Bullet& ext::bullet::create( uf::Object& object, const uf::BaseGeometry& me bMesh->preallocateIndices( indices ); for ( size_t currentIndex = 0; currentIndex < indices; ++currentIndex ) { uint32_t index = 0; - void* indexSrc = indexPointer + (currentIndex * indexStride); + uint8_t* indexSrc = indexPointer + (currentIndex * indexStride); switch ( indexStride ) { case sizeof( uint8_t): index = *(( uint8_t*) indexSrc); break; case sizeof(uint16_t): index = *((uint16_t*) indexSrc); break; diff --git a/engine/src/ext/discord/discord.cpp b/engine/src/ext/discord/discord.cpp index ea04c43c..cf4889cf 100644 --- a/engine/src/ext/discord/discord.cpp +++ b/engine/src/ext/discord/discord.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -95,7 +95,7 @@ void UF_API ext::discord::initialize(){ ::discord::ImageDimensions dims{}; state.core->ImageManager().GetDimensions(handle, &dims); std::cout << "Fetched " << dims.GetWidth() << "x" << dims.GetHeight() << " avatar!\n"; - std::vector data; + uf::stl::vector data; data.reserve(dims.GetWidth() * dims.GetHeight() * 4); uint8_t* d = data.data(); state.core->ImageManager().GetData(handle, d, data.size()); @@ -171,7 +171,7 @@ void UF_API ext::discord::initialize(){ std::int64_t userId, std::uint8_t* payload, std::uint32_t payloadLength) { - std::vector buffer{}; + uf::stl::vector buffer{}; buffer.resize(payloadLength); memcpy(buffer.data(), payload, payloadLength); std::cout << "Lobby message " << lobbyId << " from " << userId << " of length " @@ -198,21 +198,21 @@ void UF_API ext::discord::initialize(){ } { - if ( json["details"].is() ) canonical["details"] = json["details"]; - if ( json["state"].is() ) canonical["state"] = json["state"]; - if ( json["small image"].is() ) canonical["small image"] = json["small image"]; - if ( json["small text"].is() ) canonical["small text"] = json["small text"]; - if ( json["large image"].is() ) canonical["large image"] = json["large image"]; - if ( json["large text"].is() ) canonical["large text"] = json["large text"]; + if ( json["details"].is() ) canonical["details"] = json["details"]; + if ( json["state"].is() ) canonical["state"] = json["state"]; + if ( json["small image"].is() ) canonical["small image"] = json["small image"]; + if ( json["small text"].is() ) canonical["small text"] = json["small text"]; + if ( json["large image"].is() ) canonical["large image"] = json["large image"]; + if ( json["large text"].is() ) canonical["large text"] = json["large text"]; } ::discord::Activity activity{}; - if ( canonical["details"].is() ) activity.SetDetails(canonical["details"].asCString()); - if ( canonical["state"].is() ) activity.SetState(canonical["state"].asCString()); - if ( canonical["small image"].is() ) activity.GetAssets().SetSmallImage(canonical["small image"].asCString()); - if ( canonical["small text"].is() ) activity.GetAssets().SetSmallText(canonical["small text"].asCString()); - if ( canonical["large image"].is() ) activity.GetAssets().SetLargeImage(canonical["large image"].asCString()); - if ( canonical["large text"].is() ) activity.GetAssets().SetLargeText(canonical["large text"].asCString()); + if ( canonical["details"].is() ) activity.SetDetails(canonical["details"].asCString()); + if ( canonical["state"].is() ) activity.SetState(canonical["state"].asCString()); + if ( canonical["small image"].is() ) activity.GetAssets().SetSmallImage(canonical["small image"].asCString()); + if ( canonical["small text"].is() ) activity.GetAssets().SetSmallText(canonical["small text"].asCString()); + if ( canonical["large image"].is() ) activity.GetAssets().SetLargeImage(canonical["large image"].asCString()); + if ( canonical["large text"].is() ) activity.GetAssets().SetLargeText(canonical["large text"].asCString()); activity.SetType(::discord::ActivityType::Playing); state.core->ActivityManager().UpdateActivity(activity, [](::discord::Result result) { std::cout << ((result == ::discord::Result::Ok) ? "Succeeded" : "Failed") << " updating activity!\n"; diff --git a/engine/src/ext/freetype/freetype.cpp b/engine/src/ext/freetype/freetype.cpp index 5e9b20d7..b1a35e28 100644 --- a/engine/src/ext/freetype/freetype.cpp +++ b/engine/src/ext/freetype/freetype.cpp @@ -31,7 +31,7 @@ UF_API void ext::freetype::terminate() { FT_Done_FreeType(ext::freetype::library.library); } -UF_API ext::freetype::Glyph ext::freetype::initialize( const std::string& font ) { +UF_API ext::freetype::Glyph ext::freetype::initialize( const uf::stl::string& font ) { if ( !ext::freetype::initialized() ) ext::freetype::initialize(); ext::freetype::Glyph glyph; int error = 0; @@ -43,7 +43,7 @@ UF_API ext::freetype::Glyph ext::freetype::initialize( const std::string& font ) } return glyph; } -UF_API bool ext::freetype::initialize( ext::freetype::Glyph& glyph, const std::string& font ) { +UF_API bool ext::freetype::initialize( ext::freetype::Glyph& glyph, const uf::stl::string& font ) { if ( !ext::freetype::initialized() ) ext::freetype::initialize(); int error = 0; if ( (error = FT_New_Face( ext::freetype::library.library, font.c_str(), 0, &glyph.face )) ) { @@ -85,7 +85,7 @@ UF_API bool ext::freetype::load( ext::freetype::Glyph& glyph, const uf::String& return true; } -UF_API std::string ext::freetype::getError( int error ) { +UF_API uf::stl::string ext::freetype::getError( int error ) { #undef FTERRORS_H_ #define FT_ERRORDEF( e, v, s ) { e, s }, #define FT_ERROR_START_LIST { diff --git a/engine/src/ext/glfw/glfw.cpp b/engine/src/ext/glfw/glfw.cpp index 5f7c465c..d84e23d4 100644 --- a/engine/src/ext/glfw/glfw.cpp +++ b/engine/src/ext/glfw/glfw.cpp @@ -14,7 +14,7 @@ namespace { static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { if ( key == GLFW_KEY_W ) { uf::Serializer json; - std::string hook = "window:Key.W"; + uf::stl::string hook = "window:Key.W"; json["type"] = hook; json["invoker"] = "os"; json["state"] = action != 0; @@ -23,7 +23,7 @@ namespace { } } -void ext::glfw::Window::initialize( size_t width, size_t height, const std::string& title ) { +void ext::glfw::Window::initialize( size_t width, size_t height, const uf::stl::string& title ) { glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); this->m_window = glfwCreateWindow(this->m_width = width, this->m_height = height, (this->m_title = title).c_str(), nullptr, nullptr); @@ -55,10 +55,10 @@ bool ext::glfw::Window::minimized() { ext::glfw::Window::operator GLFWwindow*(){ return this->m_window; } -std::vector ext::glfw::Window::getExtensions( bool enableValidationLayers ) { +uf::stl::vector ext::glfw::Window::getExtensions( bool enableValidationLayers ) { uint32_t glfwExtensionCount = 0; const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); - std::vector supportedExtensions(glfwExtensions, glfwExtensions + glfwExtensionCount); + uf::stl::vector supportedExtensions(glfwExtensions, glfwExtensions + glfwExtensionCount); if ( enableValidationLayers ) supportedExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); /* diff --git a/engine/src/ext/gltf/gltf.cpp b/engine/src/ext/gltf/gltf.cpp index e94fb741..e4133d16 100644 --- a/engine/src/ext/gltf/gltf.cpp +++ b/engine/src/ext/gltf/gltf.cpp @@ -111,8 +111,8 @@ namespace { } } -pod::Graph ext::gltf::load( const std::string& filename, uf::graph::load_mode_t mode, const uf::Serializer& metadata ) { - std::string extension = uf::io::extension( filename ); +pod::Graph ext::gltf::load( const uf::stl::string& filename, uf::graph::load_mode_t mode, const uf::Serializer& metadata ) { + uf::stl::string extension = uf::io::extension( filename ); if ( extension != "glb" && extension != "gltf" ) { return uf::graph::load( filename, mode, metadata ); } @@ -120,7 +120,7 @@ pod::Graph ext::gltf::load( const std::string& filename, uf::graph::load_mode_t tinygltf::Model model; tinygltf::TinyGLTF loader; - std::string warn, err; + uf::stl::string warn, err; bool ret = extension == "glb" ? loader.LoadBinaryFromFile(&model, &err, &warn, filename) : loader.LoadASCIIFromFile(&model, &err, &warn, filename); pod::Graph graph; @@ -227,7 +227,7 @@ pod::Graph ext::gltf::load( const std::string& filename, uf::graph::load_mode_t } else { UF_MSG_WARNING("Unhandled alpha mode: " << material.alphaMode) } - if ( m.doubleSided && graph.metadata["cull mode"].as() == "auto" ) { + if ( m.doubleSided && graph.metadata["cull mode"].as() == "auto" ) { graph.metadata["cull mode"] = "none"; } } @@ -249,12 +249,12 @@ pod::Graph ext::gltf::load( const std::string& filename, uf::graph::load_mode_t dc.indicesIndex = mesh.indices.size(); struct Attribute { - std::string name = ""; + uf::stl::string name = ""; size_t components = 1; - std::vector buffer; - std::vector indices; + uf::stl::vector buffer; + uf::stl::vector indices; }; - std::unordered_map attributes = { + uf::stl::unordered_map attributes = { {"POSITION", {}}, {"TEXCOORD_0", {}}, {"NORMAL", {}}, diff --git a/engine/src/ext/json/json.cpp b/engine/src/ext/json/json.cpp index bfac36bb..99d0ba69 100644 --- a/engine/src/ext/json/json.cpp +++ b/engine/src/ext/json/json.cpp @@ -34,7 +34,7 @@ void ext::json::forEach( ext::json::Value& json, const std::function& function ) { +void ext::json::forEach( ext::json::Value& json, const std::function& function ) { // UF_ASSERT_SAFE( ext::json::isObject(json) ); for ( auto it = json.begin(); it != json.end(); ++it ) { function( it.key(), (ext::json::Value&) *it ); @@ -57,7 +57,7 @@ void ext::json::forEach( ext::json::Value& json, const std::function& function ) { +void ext::json::forEach( ext::json::Value& json, const std::function& function ) { // UF_ASSERT_SAFE( ext::json::isObject(json) ); for ( auto it = json.begin(); it != json.end(); ++it ) { bool breaks = false; @@ -72,7 +72,7 @@ void ext::json::forEach( const ext::json::Value& json, const std::function& function ) { +void ext::json::forEach( const ext::json::Value& json, const std::function& function ) { // UF_ASSERT_SAFE( ext::json::isObject(json) ); for ( auto it = json.begin(); it != json.end(); ++it ) { function( it.key(), (const ext::json::Value&) *it ); @@ -86,7 +86,7 @@ void ext::json::forEach( const ext::json::Value& json, const std::function& function ) { +void ext::json::forEach( const ext::json::Value& json, const std::function& function ) { // UF_ASSERT_SAFE( ext::json::isObject(json) ); for ( auto it = json.begin(); it != json.end(); ++it ) { bool breaks = false; @@ -112,8 +112,8 @@ void ext::json::forEach( const ext::json::Value& json, const std::function ext::json::keys( const ext::json::Value& v ) { - std::vector keys; +uf::stl::vector ext::json::keys( const ext::json::Value& v ) { + uf::stl::vector keys; if ( !ext::json::isObject( v ) ) return keys; for ( auto it = v.begin(); it != v.end(); ++it ) { keys.emplace_back(it.key()); @@ -128,7 +128,7 @@ ext::json::Value ext::json::reencode( const ext::json::Value& _x, const Encoding if ( settings.precision == 0 ) return _x; ext::json::Value x = _x; if ( x.is(true) ) { - std::stringstream str; + uf::stl::stringstream str; str << std::setprecision(settings.precision) << x.as(); // ext::json::decode( x, str.str() ); x = nlohmann::json::parse(str); @@ -140,7 +140,7 @@ ext::json::Value ext::json::reencode( const ext::json::Value& _x, const Encoding ext::json::Value& ext::json::reencode( ext::json::Value& x, const EncodingSettings& settings ) { if ( settings.precision == 0 ) return x; if ( x.is(true) ) { - std::stringstream str; + uf::stl::stringstream str; str << std::setprecision(settings.precision) << x.as(); // ext::json::decode( x, str.str() ); x = nlohmann::json::parse(str); @@ -150,17 +150,17 @@ ext::json::Value& ext::json::reencode( ext::json::Value& x, const EncodingSettin return x; } -std::string ext::json::encode( const ext::json::Value& json, bool pretty ) { +uf::stl::string ext::json::encode( const ext::json::Value& json, bool pretty ) { return ext::json::encode( json, ext::json::EncodingSettings{ .pretty = true } ); } -std::string ext::json::encode( const ext::json::Value& _json, const ext::json::EncodingSettings& settings ) { +uf::stl::string ext::json::encode( const ext::json::Value& _json, const ext::json::EncodingSettings& settings ) { ext::json::Value json = ext::json::reencode( _json, settings ); #if defined(UF_JSON_USE_NLOHMANN) && UF_JSON_USE_NLOHMANN return settings.pretty ? json.dump(1, '\t') : json.dump(); #elif defined(UF_JSON_USE_JSONCPP) && UF_JSON_USE_JSONCPP Json::FastWriter fast; Json::StyledWriter styled; - std::string output = settings.pretty ? styled.write(json) : fast.write(json); + uf::stl::string output = settings.pretty ? styled.write(json) : fast.write(json); if ( output.back() == '\n' ) output.pop_back(); return output; #elif defined(UF_JSON_USE_LUA) && UF_JSON_USE_LUA @@ -169,11 +169,11 @@ std::string ext::json::encode( const ext::json::Value& _json, const ext::json::E } #if UF_USE_LUA -std::string ext::json::encode( const sol::table& table ) { +uf::stl::string ext::json::encode( const sol::table& table ) { return ext::lua::state["json"]["encode"]( table ); } #endif -ext::json::Value& ext::json::decode( ext::json::Value& json, const std::string& str ) { +ext::json::Value& ext::json::decode( ext::json::Value& json, const uf::stl::string& str ) { #if defined(UF_JSON_USE_NLOHMANN) && UF_JSON_USE_NLOHMANN #if UF_NO_EXCEPTIONS json = nlohmann::json::parse(str, nullptr, true, true); diff --git a/engine/src/ext/lua/lua.cpp b/engine/src/ext/lua/lua.cpp index 7ae79dbb..91189bc6 100644 --- a/engine/src/ext/lua/lua.cpp +++ b/engine/src/ext/lua/lua.cpp @@ -1,8 +1,8 @@ #include #if UF_USE_LUA sol::state ext::lua::state; -std::string ext::lua::main = uf::io::root + "/scripts/main.lua"; -std::unordered_map ext::lua::modules; +uf::stl::string ext::lua::main = uf::io::root + "/scripts/main.lua"; +uf::stl::unordered_map ext::lua::modules; #include #include @@ -18,14 +18,14 @@ std::unordered_map ext::lua::modules; sol::table ext::lua::createTable() { return sol::table(ext::lua::state, sol::create); } -std::string ext::lua::sanitize( const std::string& dirty, int index ) { +uf::stl::string ext::lua::sanitize( const uf::stl::string& dirty, int index ) { auto split = uf::string::split( dirty, "::" ); if ( index < 0 ) index = split.size() + index; - std::string part = split.at(index); + uf::stl::string part = split.at(index); part = uf::string::replace( part, "<>", "" ); return part; } -std::optional ext::lua::encode( sol::table table ) { +std::optional ext::lua::encode( sol::table table ) { sol::protected_function fun = ext::lua::state["json"]["encode"]; auto result = fun( table ); if ( !result.valid() ) { @@ -35,7 +35,7 @@ std::optional ext::lua::encode( sol::table table ) { } return result; } -std::optional ext::lua::decode( const std::string& string ) { +std::optional ext::lua::decode( const uf::stl::string& string ) { sol::protected_function fun = ext::lua::state["json"]["decode"]; auto result = fun( string ); if ( !result.valid() ) { @@ -46,10 +46,10 @@ std::optional ext::lua::decode( const std::string& string ) { return result; } -std::vector>* ext::lua::onInitializationFunctions = NULL; +uf::stl::vector>* ext::lua::onInitializationFunctions = NULL; void ext::lua::onInitialization( const std::function& function ) { if ( !ext::lua::onInitializationFunctions ) { - ext::lua::onInitializationFunctions = new std::vector>; + ext::lua::onInitializationFunctions = new uf::stl::vector>; } auto& functions = *ext::lua::onInitializationFunctions; functions.emplace_back(function); @@ -58,7 +58,7 @@ void ext::lua::onInitialization( const std::function& function ) { namespace binds { namespace hook { - void add( const std::string& name, const sol::function& function ) { + void add( const uf::stl::string& name, const sol::function& function ) { uf::hooks.addHook( name, [function](ext::json::Value& json){ sol::table table = ext::lua::state["json"]["decode"]( json.dump() ); auto result = function( table ); @@ -68,7 +68,7 @@ namespace binds { } }); }; - void call( const std::string& name, sol::table table = ext::lua::createTable() ) { + void call( const uf::stl::string& name, sol::table table = ext::lua::createTable() ) { uf::Serializer payload = table; uf::hooks.call( name, (ext::json::Value&) payload ); return; @@ -94,18 +94,18 @@ namespace binds { }; } namespace string { - std::string extension( const std::string& filename ) { + uf::stl::string extension( const uf::stl::string& filename ) { return uf::io::extension( filename ); }; - std::string resolveURI( const std::string& filename, sol::variadic_args va ) { + uf::stl::string resolveURI( const uf::stl::string& filename, sol::variadic_args va ) { auto it = va.begin(); - std::string root = it != va.end() ? *(it++) : std::string(""); + uf::stl::string root = it != va.end() ? *(it++) : uf::stl::string(""); return uf::io::resolveURI( filename, root ); }; - std::string si( sol::variadic_args va ) { + uf::stl::string si( sol::variadic_args va ) { auto it = va.begin(); double value = *(it++); - std::string unit = *(it++); + uf::stl::string unit = *(it++); size_t precision = va.size() > 2 ? *(it++) : 3; return uf::string::si( value, unit, precision ); }; @@ -114,7 +114,7 @@ namespace binds { void print( sol::variadic_args va ) { size_t count = va.size(); for ( auto value : va ) { - std::string str = ext::lua::state["tostring"]( value ); + uf::stl::string str = ext::lua::state["tostring"]( value ); uf::iostream << str; if ( --count != 0 ) uf::iostream << "\t"; } @@ -132,18 +132,18 @@ namespace binds { double delta(){ return uf::physics::time::delta; }; } namespace json { - std::string pretty( const std::string& json ){ + uf::stl::string pretty( const uf::stl::string& json ){ uf::Serializer serializer = json; return serializer.serialize(); }; - sol::table readFromFile( const std::string& filename ){ + sol::table readFromFile( const uf::stl::string& filename ){ uf::Serializer serializer; serializer.readFromFile( filename ); - std::string string = serializer.serialize(false); + uf::stl::string string = serializer.serialize(false); auto decoded = ext::lua::decode( string ); return decoded ? decoded.value() : ext::lua::createTable(); }; - bool writeToFile( sol::table table, const std::string& path ) { + bool writeToFile( sol::table table, const uf::stl::string& path ) { if ( uf::io::extension(path) != "json" ) return false; auto encoded = ext::lua::encode( table ); if ( encoded ) { @@ -155,7 +155,7 @@ namespace binds { }; } namespace os { - std::string arch() { + uf::stl::string arch() { return UF_ENV; } } @@ -166,8 +166,8 @@ void ext::lua::initialize() { // load modules for ( auto pair : modules ) { - const std::string& name = pair.first; - const std::string& script = pair.second; + const uf::stl::string& name = pair.first; + const uf::stl::string& script = pair.second; if ( uf::io::extension(script) == "lua" ) { state.require_file(name, uf::io::resolveURI( script ), true); } else { @@ -238,7 +238,7 @@ void ext::lua::initialize() { } run(main); } -bool ext::lua::run( const std::string& s, bool safe ) { +bool ext::lua::run( const uf::stl::string& s, bool safe ) { // is file if ( uf::io::extension(s) == "lua" ) { if ( safe ) { @@ -267,7 +267,7 @@ bool ext::lua::run( const std::string& s, bool safe ) { return true; } -pod::LuaScript ext::lua::script( const std::string& filename ) { +pod::LuaScript ext::lua::script( const uf::stl::string& filename ) { pod::LuaScript script; script.file = filename; script.env = sol::environment( ext::lua::state, sol::create, ext::lua::state.globals() ); diff --git a/engine/src/ext/lua/usertypes/asset.cpp b/engine/src/ext/lua/usertypes/asset.cpp index 3c695edf..775ceed3 100644 --- a/engine/src/ext/lua/usertypes/asset.cpp +++ b/engine/src/ext/lua/usertypes/asset.cpp @@ -5,10 +5,10 @@ namespace binds { void load( uf::Asset& asset, sol::variadic_args va ) { auto it = va.begin(); - std::string callback = ""; - std::string uri = ""; - std::string hash = ""; - std::string category = ""; + uf::stl::string callback = ""; + uf::stl::string uri = ""; + uf::stl::string hash = ""; + uf::stl::string category = ""; if ( it != va.end() ) callback = *(it++); if ( it != va.end() ) uri = *(it++); if ( it != va.end() ) hash = *(it++); @@ -18,10 +18,10 @@ namespace binds { } void cache( uf::Asset& asset, sol::variadic_args va ) { auto it = va.begin(); - std::string callback = ""; - std::string uri = ""; - std::string hash = ""; - std::string category = ""; + uf::stl::string callback = ""; + uf::stl::string uri = ""; + uf::stl::string hash = ""; + uf::stl::string category = ""; if ( it != va.end() ) callback = *(it++); if ( it != va.end() ) uri = *(it++); if ( it != va.end() ) hash = *(it++); @@ -31,7 +31,7 @@ namespace binds { else asset.cache( callback, uri, hash, category ); } - std::string getOriginal( uf::Asset& asset, const std::string& n ) { + uf::stl::string getOriginal( uf::Asset& asset, const uf::stl::string& n ) { return asset.getOriginal( n ); } } diff --git a/engine/src/ext/lua/usertypes/audio.cpp b/engine/src/ext/lua/usertypes/audio.cpp index 87f595fe..f09108cd 100644 --- a/engine/src/ext/lua/usertypes/audio.cpp +++ b/engine/src/ext/lua/usertypes/audio.cpp @@ -3,7 +3,7 @@ #include UF_LUA_REGISTER_USERTYPE(uf::Audio, sol::call_constructor, sol::initializers( []( uf::Audio& self ){}, - []( uf::Audio& self, const std::string& filename = "", double volume = 1 ){ + []( uf::Audio& self, const uf::stl::string& filename = "", double volume = 1 ){ if ( filename != "" ) self.load(filename); self.setVolume(volume); }), diff --git a/engine/src/ext/lua/usertypes/object.cpp b/engine/src/ext/lua/usertypes/object.cpp index 70fec7c7..2dd20a59 100644 --- a/engine/src/ext/lua/usertypes/object.cpp +++ b/engine/src/ext/lua/usertypes/object.cpp @@ -8,10 +8,10 @@ #include namespace binds { - std::string formatHookName(uf::Object& self, const std::string n ){ + uf::stl::string formatHookName(uf::Object& self, const uf::stl::string n ){ return self.formatHookName(n); } - sol::object getComponent( uf::Object& self, const std::string& type ) { + sol::object getComponent( uf::Object& self, const uf::stl::string& type ) { #define UF_LUA_RETRIEVE_COMPONENT( T )\ else if ( type == UF_NS_GET_LAST(T) ) return sol::make_object( ext::lua::state, std::ref(self.getComponent()) ); @@ -29,7 +29,7 @@ namespace binds { UF_LUA_RETRIEVE_COMPONENT(uf::Camera) return sol::make_object( ext::lua::state, sol::lua_nil ); } - void setComponent(uf::Object& self, const std::string& type, sol::object value ) { + void setComponent(uf::Object& self, const uf::stl::string& type, sol::object value ) { #define UF_LUA_UPDATE_COMPONENT( T )\ else if ( type == UF_NS_GET_LAST(T) ) self.getComponent() = std::move(value.as()); @@ -37,7 +37,7 @@ namespace binds { auto encoded = ext::lua::encode( value.as() ); if ( encoded ) { auto& metadata = self.getComponent(); - std::string str = encoded.value(); + uf::stl::string str = encoded.value(); uf::Serializer hooks = metadata["system"]["hooks"]; metadata.merge( str, false ); metadata["system"]["hooks"] = hooks; @@ -48,7 +48,7 @@ namespace binds { UF_LUA_UPDATE_COMPONENT(uf::Asset) UF_LUA_UPDATE_COMPONENT(uf::Camera) } - bool bind(uf::Object& self, const std::string& type, sol::protected_function fun ) { + bool bind(uf::Object& self, const uf::stl::string& type, sol::protected_function fun ) { if ( !self.hasBehavior({.type = uf::LuaBehavior::type}) ) uf::instantiator::bind( "LuaBehavior", self ); pod::Behavior* behaviorPointer = NULL; auto& behaviors = self.getBehaviors(); @@ -84,7 +84,7 @@ namespace binds { static uf::Object null; return null; } - uf::Object& findByName( uf::Object& self, const std::string& index ){ + uf::Object& findByName( uf::Object& self, const uf::stl::string& index ){ auto* pointer = self.findByName( index ); if ( pointer ) return pointer->as(); static uf::Object null; @@ -98,7 +98,7 @@ namespace binds { self.removeChild( child ); return self; } - uf::Object& loadChild( uf::Object& self, const std::string& filename, bool init = true ) { + uf::Object& loadChild( uf::Object& self, const uf::stl::string& filename, bool init = true ) { auto* pointer = self.loadChildPointer( filename, init ); if ( pointer ) return pointer->as(); static uf::Object null; @@ -114,9 +114,9 @@ namespace binds { uf::Object& getParent( uf::Object& self ){ return self.getParent().as(); } - void addHook( uf::Object& self, const std::string& name, const sol::function& function ) { + void addHook( uf::Object& self, const uf::stl::string& name, const sol::function& function ) { self.addHook( name, [function](ext::json::Value& json){ - std::string payload = json.dump(); + uf::stl::string payload = json.dump(); auto decoded = ext::lua::decode( payload ); if ( !decoded ) return; sol::table table = decoded.value(); @@ -128,27 +128,27 @@ namespace binds { } }); } - void callHook( uf::Object& self, const std::string& name, sol::table table = ext::lua::createTable() ) { + void callHook( uf::Object& self, const uf::stl::string& name, sol::table table = ext::lua::createTable() ) { uf::Serializer payload = table; self.callHook( name, (ext::json::Value&) payload ); } - void queueHook( uf::Object& self, const std::string& name, sol::table table, float delay = 0.0f ) { + void queueHook( uf::Object& self, const uf::stl::string& name, sol::table table, float delay = 0.0f ) { uf::Serializer payload = table; self.queueHook( name, (ext::json::Value&) payload, delay ); } - std::string toString( uf::Object& self ) { + uf::stl::string toString( uf::Object& self ) { return self.getName() + ": " + std::to_string( self.getUid() ); } size_t getUid( const uf::Object& o ) { return o.getUid(); } - std::string getName( const uf::Object& o ) { return o.getName(); } + uf::stl::string getName( const uf::Object& o ) { return o.getName(); } } UF_LUA_REGISTER_USERTYPE(uf::Object, sol::call_constructor, sol::initializers( []( uf::Object& self, sol::object arg, bool init = true ){ - if ( arg.is() ) { - self.load( arg.as() ); + if ( arg.is() ) { + self.load( arg.as() ); } else if ( arg.is() ) { auto encoded = ext::lua::encode( arg.as() ); if ( encoded ) { @@ -183,8 +183,8 @@ namespace { ext::lua::onInitialization( []{ ext::lua::state.new_usertype(UF_NS_GET_LAST(uf::Object), sol::call_constructor, sol::initializers( []( uf::Object& self, sol::object arg, bool init = true ){ - if ( arg.is() ) { - self.load( arg.as() ); + if ( arg.is() ) { + self.load( arg.as() ); } else if ( arg.is() ) { auto encoded = ext::lua::encode( arg.as() ); if ( encoded ) { diff --git a/engine/src/ext/lua/usertypes/quaternion.cpp b/engine/src/ext/lua/usertypes/quaternion.cpp index 82a3b521..43236454 100644 --- a/engine/src/ext/lua/usertypes/quaternion.cpp +++ b/engine/src/ext/lua/usertypes/quaternion.cpp @@ -51,7 +51,7 @@ namespace binds { pod::Matrix4f matrix( const pod::Quaternion<>& q ) { return uf::quaternion::matrix( q ); } - std::string __tostring( const pod::Quaternion<>& self ) { + uf::stl::string __tostring( const pod::Quaternion<>& self ) { return uf::string::toString( self ); } } diff --git a/engine/src/ext/lua/usertypes/vector.cpp b/engine/src/ext/lua/usertypes/vector.cpp index 57874918..587bb756 100644 --- a/engine/src/ext/lua/usertypes/vector.cpp +++ b/engine/src/ext/lua/usertypes/vector.cpp @@ -40,7 +40,7 @@ namespace binds { float dot( const pod::Vector3f& left, const pod::Vector3f& right ) { return uf::vector::dot( left, right ); } - std::string toString( pod::Vector3f& self ) { + uf::stl::string toString( pod::Vector3f& self ) { return uf::string::toString( self ); } } @@ -81,7 +81,7 @@ namespace binds { float dot( const pod::Vector4f& left, const pod::Vector4f& right ) { return uf::vector::dot( left, right ); } - std::string toString( pod::Vector4f& self ) { + uf::stl::string toString( pod::Vector4f& self ) { return uf::string::toString( self ); } } diff --git a/engine/src/ext/meshopt/meshopt.cpp b/engine/src/ext/meshopt/meshopt.cpp index aadcdece..0e09547f 100644 --- a/engine/src/ext/meshopt/meshopt.cpp +++ b/engine/src/ext/meshopt/meshopt.cpp @@ -39,7 +39,7 @@ void ext::meshopt::optimize( uf::BaseGeometry& mesh, size_t o ) { memcpy( indices, mesh.attributes.index.pointer, indicesCount ); } - std::vector remap(verticesCount); + uf::stl::vector remap(verticesCount); verticesCount = meshopt_generateVertexRemap(&remap[0], (uint32_t*) indices, indicesCount ? indicesCount : verticesCount, (float*) vertices, verticesCount, mesh.attributes.vertex.size); mesh.resizeIndices(indicesCount); @@ -55,7 +55,7 @@ void ext::meshopt::optimize( uf::BaseGeometry& mesh, size_t o ) { auto vertices = std::move( this->vertices ); size_t valueCount = vertices.size(); - std::vector remap(valueCount); + uf::stl::vector remap(valueCount); size_t verticesCount = meshopt_generateVertexRemap(&remap[0], NULL, valueCount, &vertices[0], valueCount, sizeof(T)); this->indices.resize(valueCount); @@ -71,7 +71,7 @@ void ext::meshopt::optimize( uf::BaseGeometry& mesh, size_t o ) { auto vertices = std::move( this->vertices ); auto indices = std::move( this->indices ); - std::vector remap(indicesCount); + uf::stl::vector remap(indicesCount); verticesCount = meshopt_generateVertexRemap(&remap[0], &indices[0], indicesCount, &vertices[0], verticesCount, sizeof(T)); this->indices.resize(indicesCount); @@ -102,7 +102,7 @@ void ext::meshopt::optimize( uf::BaseGeometry& mesh, size_t o ) { auto vertices = std::move( this->vertices ); U indices = vertices.size(); -std::vector remap(indices); +uf::stl::vector remap(indices); size_t verticesCount = meshopt_generateVertexRemap(&remap[0], NULL, indices, &vertices[0], indices, sizeof(T)); this->indices.resize(indices); diff --git a/engine/src/ext/ncurses/ncurses.cpp b/engine/src/ext/ncurses/ncurses.cpp index 12002eca..a2a6e56a 100644 --- a/engine/src/ext/ncurses/ncurses.cpp +++ b/engine/src/ext/ncurses/ncurses.cpp @@ -95,7 +95,7 @@ void UF_API_CALL ext::Ncurses::addStr(const char* c_str) { // if ( !this->m_initialized ) return; waddstr((WINDOW*) this->m_window, c_str); } -void UF_API_CALL ext::Ncurses::addStr(const std::string str) { +void UF_API_CALL ext::Ncurses::addStr(const uf::stl::string str) { if ( !this->m_initialized ) this->initialize(); // if ( !this->m_initialized ) return; waddstr((WINDOW*) this->m_window, str.c_str()); @@ -146,7 +146,7 @@ void UF_API_CALL ext::Ncurses::clrToBot() {} void UF_API_CALL ext::Ncurses::delCh() {} void UF_API_CALL ext::Ncurses::addCh( char c ) {} void UF_API_CALL ext::Ncurses::addStr(const char* c_str) {} -void UF_API_CALL ext::Ncurses::addStr(const std::string str) {} +void UF_API_CALL ext::Ncurses::addStr(const uf::stl::string str) {} void UF_API_CALL ext::Ncurses::attrOn(int att) {} void UF_API_CALL ext::Ncurses::attrOff(int att) {} bool UF_API_CALL ext::Ncurses::hasColors() { return false; } diff --git a/engine/src/ext/oal/oal.cpp b/engine/src/ext/oal/oal.cpp index adb427e2..6cbcd802 100644 --- a/engine/src/ext/oal/oal.cpp +++ b/engine/src/ext/oal/oal.cpp @@ -2,7 +2,7 @@ #if defined(UF_USE_OPENAL) #include -#include +#include #include #include #include @@ -50,18 +50,18 @@ void ext::al::listener( ALenum name, ALfloat x ) { AL_CHECK_RESULT(alListenerf( void ext::al::listener( ALenum name, ALfloat x, ALfloat y, ALfloat z ) { AL_CHECK_RESULT(alListener3f( name, x, y, z )); } void ext::al::listener( ALenum name, const ALfloat* f ) { AL_CHECK_RESULT(alListenerfv( name, f )); } -void ext::al::listener( const std::string& string, ALfloat x ) { +void ext::al::listener( const uf::stl::string& string, ALfloat x ) { // alSourcef if ( string == "GAIN" ) return ext::al::listener( AL_GAIN, x ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::listener( const std::string& string, ALfloat x, ALfloat y, ALfloat z ) { +void ext::al::listener( const uf::stl::string& string, ALfloat x, ALfloat y, ALfloat z ) { // alSourcefv if ( string == "POSITION" ) return ext::al::listener( AL_POSITION, x, y, z ); if ( string == "VELOCITY" ) return ext::al::listener( AL_VELOCITY, x, y, z ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::listener( const std::string& string, const ALfloat* f ) { +void ext::al::listener( const uf::stl::string& string, const ALfloat* f ) { // alSourcefv if ( string == "POSITION" ) return ext::al::listener( AL_POSITION, f ); if ( string == "VELOCITY" ) return ext::al::listener( AL_VELOCITY, f ); @@ -69,7 +69,7 @@ void ext::al::listener( const std::string& string, const ALfloat* f ) { UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } #endif -std::string ext::al::getError( ALCenum error ) { +uf::stl::string ext::al::getError( ALCenum error ) { if ( !error ) error = alGetError(); switch (error) { case AL_NO_ERROR: return "AL_NO_ERROR"; @@ -81,11 +81,11 @@ std::string ext::al::getError( ALCenum error ) { } return "AL_UNKNOWN(" + std::to_string(error) + ")"; } -uf::audio::Metadata* ext::al::create( const std::string& filename, bool streamed, uint8_t buffers ) { +uf::audio::Metadata* ext::al::create( const uf::stl::string& filename, bool streamed, uint8_t buffers ) { #if UF_MEMORYPOOL_INVALID_MALLOC - uf::audio::Metadata* pointer = &uf::MemoryPool::global.alloc(); + uf::audio::Metadata* pointer = &uf::memoryPool::global.alloc(); #else - uf::MemoryPool* memoryPool = uf::MemoryPool::global.size() > 0 ? &uf::MemoryPool::global : NULL; + uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; uf::audio::Metadata* pointer = (memoryPool) ? &memoryPool->alloc() : new uf::audio::Metadata; #endif uf::audio::Metadata& metadata = *pointer; @@ -101,13 +101,13 @@ uf::audio::Metadata* ext::al::create( const std::string& filename, bool streamed metadata.al.source.set( AL_LOOPING, metadata.settings.loop ? AL_TRUE : AL_FALSE ); return pointer; } -uf::audio::Metadata* ext::al::open( const std::string& filename ) { +uf::audio::Metadata* ext::al::open( const uf::stl::string& filename ) { return ext::al::open( filename, uf::audio::streamsByDefault ); } -uf::audio::Metadata* ext::al::open( const std::string& filename, bool streams ) { +uf::audio::Metadata* ext::al::open( const uf::stl::string& filename, bool streams ) { return streams ? ext::al::stream( filename ) : ext::al::load( filename ); } -uf::audio::Metadata* ext::al::load( const std::string& filename ) { +uf::audio::Metadata* ext::al::load( const uf::stl::string& filename ) { uf::audio::Metadata* pointer = ext::al::create( filename, false, 1 ); uf::audio::Metadata& metadata = *pointer; @@ -115,7 +115,7 @@ uf::audio::Metadata* ext::al::load( const std::string& filename ) { return pointer; } -uf::audio::Metadata* ext::al::stream( const std::string& filename ) { +uf::audio::Metadata* ext::al::stream( const uf::stl::string& filename ) { uf::audio::Metadata* pointer = ext::al::create( filename, true, uf::audio::buffers ); uf::audio::Metadata& metadata = *pointer; @@ -131,9 +131,9 @@ void ext::al::close( uf::audio::Metadata* metadata ) { ext::al::close( *metadata ); #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool::global.free( metadata ); + uf::memoryPool::global.free( metadata ); #else - uf::MemoryPool* memoryPool = uf::MemoryPool::global.size() > 0 ? &uf::MemoryPool::global : NULL; + uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; if ( memoryPool ) memoryPool->free( metadata ); else delete metadata; #endif @@ -185,7 +185,7 @@ void ext::al::Source::get( ALenum name, ALint& x ) { AL_CHECK_RESULT(alGetSource void ext::al::Source::get( ALenum name, ALint& x, ALint& y, ALint& z ) { AL_CHECK_RESULT(alGetSource3i( this->m_index, name, &x, &y, &z )); } void ext::al::Source::get( ALenum name, ALint* f ) { AL_CHECK_RESULT(alGetSourceiv( this->m_index, name, f )); } -void ext::al::Source::get( const std::string& string, ALfloat& x ) { +void ext::al::Source::get( const uf::stl::string& string, ALfloat& x ) { // alSourcef if ( string == "PITCH" ) return this->get( AL_PITCH, x ); if ( string == "GAIN" ) return this->get( AL_GAIN, x ); @@ -200,21 +200,21 @@ void ext::al::Source::get( const std::string& string, ALfloat& x ) { if ( string == "SEC_OFFSET" ) return this->get( AL_SEC_OFFSET, x ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::get( const std::string& string, ALfloat& x, ALfloat& y, ALfloat& z ) { +void ext::al::Source::get( const uf::stl::string& string, ALfloat& x, ALfloat& y, ALfloat& z ) { // alSourcefv if ( string == "POSITION" ) return this->get( AL_POSITION, x, y, z ); if ( string == "VELOCITY" ) return this->get( AL_VELOCITY, x, y, z ); if ( string == "DIRECTION" ) return this->get( AL_DIRECTION, x, y, z ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::get( const std::string& string, ALfloat* f ) { +void ext::al::Source::get( const uf::stl::string& string, ALfloat* f ) { // alSourcefv if ( string == "POSITION" ) return this->get( AL_POSITION, f ); if ( string == "VELOCITY" ) return this->get( AL_VELOCITY, f ); if ( string == "DIRECTION" ) return this->get( AL_DIRECTION, f ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::get( const std::string& string, ALint& x ) { +void ext::al::Source::get( const uf::stl::string& string, ALint& x ) { // alSourcei if ( string == "SOURCE_RELATIVE" ) return this->get( AL_SOURCE_RELATIVE, x ); if ( string == "CONE_INNER_ANGLE" ) return this->get( AL_CONE_INNER_ANGLE, x ); @@ -224,14 +224,14 @@ void ext::al::Source::get( const std::string& string, ALint& x ) { if ( string == "SOURCE_STATE" ) return this->get( AL_SOURCE_STATE, x ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::get( const std::string& string, ALint& x, ALint& y, ALint& z ) { +void ext::al::Source::get( const uf::stl::string& string, ALint& x, ALint& y, ALint& z ) { // alSourceiv if ( string == "POSITION" ) return this->get( AL_POSITION, x, y, z ); if ( string == "VELOCITY" ) return this->get( AL_VELOCITY, x, y, z ); if ( string == "DIRECTION" ) return this->get( AL_DIRECTION, x, y, z ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::get( const std::string& string, ALint* f ) { +void ext::al::Source::get( const uf::stl::string& string, ALint* f ) { // alSourceiv if ( string == "POSITION" ) return this->get( AL_POSITION, f ); if ( string == "VELOCITY" ) return this->get( AL_VELOCITY, f ); @@ -246,7 +246,7 @@ void ext::al::Source::set( ALenum name, ALint x ) { AL_CHECK_RESULT(alSourcei( t void ext::al::Source::set( ALenum name, ALint x, ALint y, ALint z ) { AL_CHECK_RESULT(alSource3i( this->m_index, name, x, y, z )); } void ext::al::Source::set( ALenum name, const ALint* f ) { AL_CHECK_RESULT(alSourceiv( this->m_index, name, f )); } -void ext::al::Source::set( const std::string& string, ALfloat x ) { +void ext::al::Source::set( const uf::stl::string& string, ALfloat x ) { // alSourcef if ( string == "PITCH" ) return this->set( AL_PITCH, x ); if ( string == "GAIN" ) return this->set( AL_GAIN, x ); @@ -261,21 +261,21 @@ void ext::al::Source::set( const std::string& string, ALfloat x ) { if ( string == "SEC_OFFSET" ) return this->set( AL_SEC_OFFSET, x ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::set( const std::string& string, ALfloat x, ALfloat y, ALfloat z ) { +void ext::al::Source::set( const uf::stl::string& string, ALfloat x, ALfloat y, ALfloat z ) { // alSourcefv if ( string == "POSITION" ) return this->set( AL_POSITION, x, y, z ); if ( string == "VELOCITY" ) return this->set( AL_VELOCITY, x, y, z ); if ( string == "DIRECTION" ) return this->set( AL_DIRECTION, x, y, z ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::set( const std::string& string, const ALfloat* f ) { +void ext::al::Source::set( const uf::stl::string& string, const ALfloat* f ) { // alSourcefv if ( string == "POSITION" ) return this->set( AL_POSITION, f ); if ( string == "VELOCITY" ) return this->set( AL_VELOCITY, f ); if ( string == "DIRECTION" ) return this->set( AL_DIRECTION, f ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::set( const std::string& string, ALint x ) { +void ext::al::Source::set( const uf::stl::string& string, ALint x ) { // alSourcei if ( string == "SOURCE_RELATIVE" ) return this->set( AL_SOURCE_RELATIVE, x ); if ( string == "CONE_INNER_ANGLE" ) return this->set( AL_CONE_INNER_ANGLE, x ); @@ -285,14 +285,14 @@ void ext::al::Source::set( const std::string& string, ALint x ) { if ( string == "SOURCE_STATE" ) return this->set( AL_SOURCE_STATE, x ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::set( const std::string& string, ALint x, ALint y, ALint z ) { +void ext::al::Source::set( const uf::stl::string& string, ALint x, ALint y, ALint z ) { // alSourceiv if ( string == "POSITION" ) return this->set( AL_POSITION, x, y, z ); if ( string == "VELOCITY" ) return this->set( AL_VELOCITY, x, y, z ); if ( string == "DIRECTION" ) return this->set( AL_DIRECTION, x, y, z ); UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } -void ext::al::Source::set( const std::string& string, const ALint* f ) { +void ext::al::Source::set( const uf::stl::string& string, const ALint* f ) { // alSourceiv if ( string == "POSITION" ) return this->set( AL_POSITION, f ); if ( string == "VELOCITY" ) return this->set( AL_VELOCITY, f ); @@ -300,7 +300,7 @@ void ext::al::Source::set( const std::string& string, const ALint* f ) { UF_MSG_ERROR("AL error: Invalid enum requested: " << string); } #if 0 -void ext::al::Source::get( ALenum name, std::vector& parameters ) { +void ext::al::Source::get( ALenum name, uf::stl::vector& parameters ) { if ( !this->m_index ) this->initialize(); switch ( parameters.size() ) { case 1: AL_CHECK_RESULT(alGetSourcef( this->m_index, name, ¶meters[0] )); break; @@ -308,7 +308,7 @@ void ext::al::Source::get( ALenum name, std::vector& parameters ) { default: AL_CHECK_RESULT(alGetSourcefv( this->m_index, name, ¶meters[0] )); break; } } -void ext::al::Source::get( const std::string& string, std::vector& parameters ) { +void ext::al::Source::get( const uf::stl::string& string, uf::stl::vector& parameters ) { // alSourcef if ( string == "PITCH" ) return this->get( AL_PITCH, parameters ); if ( string == "GAIN" ) return this->get( AL_GAIN, parameters ); @@ -327,7 +327,7 @@ void ext::al::Source::get( const std::string& string, std::vector& para if ( string == "VELOCITY" ) return this->get( AL_VELOCITY, parameters ); if ( string == "DIRECTION" ) return this->get( AL_DIRECTION, parameters ); } -void ext::al::Source::get( ALenum name, std::vector& parameters ) { +void ext::al::Source::get( ALenum name, uf::stl::vector& parameters ) { if ( !this->m_index ) this->initialize(); switch ( parameters.size() ) { case 1: AL_CHECK_RESULT(alGetSourcei( this->m_index, name, ¶meters[0] )); break; @@ -335,7 +335,7 @@ void ext::al::Source::get( ALenum name, std::vector& parameters ) { default: AL_CHECK_RESULT(alGetSourceiv( this->m_index, name, ¶meters[0] )); break; } } -void ext::al::Source::get( const std::string& string, std::vector& parameters ) { +void ext::al::Source::get( const uf::stl::string& string, uf::stl::vector& parameters ) { // alSourcei if ( string == "SOURCE_RELATIVE" ) return this->get( AL_SOURCE_RELATIVE, parameters ); if ( string == "CONE_INNER_ANGLE" ) return this->get( AL_CONE_INNER_ANGLE, parameters ); @@ -350,7 +350,7 @@ void ext::al::Source::get( const std::string& string, std::vector& parame if ( string == "DIRECTION" ) return this->get( AL_DIRECTION, parameters ); } -void ext::al::Source::set( ALenum name, const std::vector& parameters ) { +void ext::al::Source::set( ALenum name, const uf::stl::vector& parameters ) { if ( !this->m_index ) this->initialize(); switch ( parameters.size() ) { case 1: AL_CHECK_RESULT(alSourcei( this->m_index, name, parameters[0] )); break; @@ -358,7 +358,7 @@ void ext::al::Source::set( ALenum name, const std::vector& parameters ) default: AL_CHECK_RESULT(alSourceiv( this->m_index, name, ¶meters[0] )); break; } } -void ext::al::Source::set( const std::string& string, const std::vector& parameters ) { +void ext::al::Source::set( const uf::stl::string& string, const uf::stl::vector& parameters ) { // alSourcef if ( string == "PITCH" ) return this->set( AL_PITCH, parameters ); if ( string == "GAIN" ) return this->set( AL_GAIN, parameters ); @@ -377,7 +377,7 @@ void ext::al::Source::set( const std::string& string, const std::vector if ( string == "VELOCITY" ) return this->set( AL_VELOCITY, parameters ); if ( string == "DIRECTION" ) return this->set( AL_DIRECTION, parameters ); } -void ext::al::Source::set( ALenum name, const std::vector& parameters ) { +void ext::al::Source::set( ALenum name, const uf::stl::vector& parameters ) { if ( !this->m_index ) this->initialize(); switch ( parameters.size() ) { case 1: AL_CHECK_RESULT(alSourcei( this->m_index, name, parameters[0] )); break; @@ -385,7 +385,7 @@ void ext::al::Source::set( ALenum name, const std::vector& parameters ) { default: AL_CHECK_RESULT(alSourceiv( this->m_index, name, ¶meters[0] )); break; } } -void ext::al::Source::set( const std::string& string, const std::vector& parameters ) { +void ext::al::Source::set( const uf::stl::string& string, const uf::stl::vector& parameters ) { // alSourcei if ( string == "SOURCE_RELATIVE" ) return this->set( AL_SOURCE_RELATIVE, parameters ); if ( string == "CONE_INNER_ANGLE" ) return this->set( AL_CONE_INNER_ANGLE, parameters ); diff --git a/engine/src/ext/opengl/commands.cpp b/engine/src/ext/opengl/commands.cpp index 7a98cde0..388b486c 100644 --- a/engine/src/ext/opengl/commands.cpp +++ b/engine/src/ext/opengl/commands.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -274,7 +274,7 @@ void ext::opengl::CommandBuffer::submit() { #if 0 CommandBuffer::Info* vertexBufferInfo = GL_NULL_HANDLE; CommandBuffer::Info* indexBufferInfo = GL_NULL_HANDLE; - std::vector textureInfos; + uf::stl::vector textureInfos; textureInfos.reserve(maxTextures); if ( state == 2 && VERBOSE_SUBMIT ) std::cout << "==== ["<& textureInfos ) { +void ext::opengl::CommandBuffer::draw( const ext::opengl::CommandBuffer::InfoDraw& drawInfo, const ext::opengl::CommandBuffer::Info& vertexBufferInfo, const uf::stl::vector& textureInfos ) { ext::opengl::Buffer::Descriptor vertexBuffer = {}; switch ( vertexBufferInfo.type ) { @@ -464,7 +464,7 @@ void ext::opengl::CommandBuffer::draw( const ext::opengl::CommandBuffer::InfoDra GL_BIND_POINTERS(); GL_ERROR_CHECK(glDrawArrays(GL_TRIANGLES, 0, vertices)); } else { - std::vector> sorted( textureInfos.size() ); + uf::stl::vector> sorted( textureInfos.size() ); for ( uf::renderer::index_t index = 0; index < vertices; ++index ) { uint8_t* vertex = vertexPointer + (index * vertexStride); @@ -513,7 +513,7 @@ void ext::opengl::CommandBuffer::draw( const ext::opengl::CommandBuffer::InfoDra GL_ERROR_CHECK(glBindTexture(info->descriptor.viewType, info->descriptor.image)); GL_DRAW_ARRAYS( vertexPointer, vertices ); } else { - std::vector> sorted( textureInfos.size() ); + uf::stl::vector> sorted( textureInfos.size() ); for ( uf::renderer::index_t index = 0; index < vertices; ++index ) { uint8_t* vertex = vertexPointer + (index * vertexStride); @@ -602,7 +602,7 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: // frustrum culling if ( ext::opengl::settings::experimental::frustrumCull ) { - std::vector unculled; + uf::stl::vector unculled; unculled.reserve(indices); for ( size_t currentIndex = 0; currentIndex < indices; currentIndex += 3 ) { const pod::Vector3f& positionA = *((pod::Vector3f*) ((vertexPointer + (indicesPointer[currentIndex+0] * vertexStride)) + drawInfo.attributes.position)); @@ -664,7 +664,7 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glDisableClientState(GL_VERTEX_ARRAY)); } #if 0 -void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::InfoDraw& drawInfo, const ext::opengl::CommandBuffer::Info& vertexBufferInfo, const ext::opengl::CommandBuffer::Info& indexBufferInfo, const std::vector& textureInfos ) { +void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::InfoDraw& drawInfo, const ext::opengl::CommandBuffer::Info& vertexBufferInfo, const ext::opengl::CommandBuffer::Info& indexBufferInfo, const uf::stl::vector& textureInfos ) { uf::Timer TIMER_TRACE; long long prevTime = 0; long long curTime = 0; @@ -770,7 +770,7 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glDrawElements(GL_TRIANGLES, indices, indicesType, indicesPointer)); } else { bool lightMapped = false; - std::vector> sorted( textureInfos.size() ); + uf::stl::vector> sorted( textureInfos.size() ); for ( size_t currentIndex = 0; currentIndex < indices; ++currentIndex ) { auto index = indicesPointer[currentIndex]; void* vertices = vertexPointer + (index * vertexStride); @@ -885,7 +885,7 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glBindTexture(info->descriptor.viewType, info->descriptor.image)); GL_DRAW_ELEMENTS( indicesPointer, indices ); } else { - std::vector> sorted( textureInfos.size() ); + uf::stl::vector> sorted( textureInfos.size() ); for ( size_t currentIndex = 0; currentIndex < indices; ++currentIndex ) { uf::renderer::index_t index = indicesPointer[currentIndex]; void* vertices = vertexPointer + (index * vertexStride); diff --git a/engine/src/ext/opengl/device.cpp b/engine/src/ext/opengl/device.cpp index 47fbbc15..31fcdf16 100644 --- a/engine/src/ext/opengl/device.cpp +++ b/engine/src/ext/opengl/device.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ #if UF_USE_OPENGL_FIXED_FUNCTION namespace { - std::vector localBuffers; + uf::stl::vector localBuffers; } #endif @@ -169,9 +169,9 @@ GLuint ext::opengl::Device::createBuffer( enums::Buffer::type_t usage, GLsizeipt index = ::localBuffers.size(); auto& buffer = ::localBuffers.emplace_back(); #if UF_MEMORYPOOL_INVALID_MALLOC - buffer = (void*) uf::MemoryPool::global.alloc( data, size ); + buffer = (void*) uf::memoryPool::global.alloc( data, size ); #else - uf::MemoryPool* memoryPool = uf::MemoryPool::global.size() > 0 ? &uf::MemoryPool::global : NULL; + uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; if ( memoryPool ) buffer = (void*) memoryPool->alloc( data, size ); else { @@ -200,9 +200,9 @@ void ext::opengl::Device::destroyBuffer( GLuint& index ) { auto& buffer = ::localBuffers[index]; if ( buffer ) { #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool::global.free( buffer ); + uf::memoryPool::global.free( buffer ); #else - uf::MemoryPool* memoryPool = uf::MemoryPool::global.size() > 0 ? &uf::MemoryPool::global : NULL; + uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; if ( memoryPool ) memoryPool->free( buffer ); else free( buffer ); #endif diff --git a/engine/src/ext/opengl/graphic.cpp b/engine/src/ext/opengl/graphic.cpp index 094fb1f6..24e11a61 100644 --- a/engine/src/ext/opengl/graphic.cpp +++ b/engine/src/ext/opengl/graphic.cpp @@ -94,11 +94,11 @@ void ext::opengl::Material::destroy() { textures.clear(); samplers.clear(); } -void ext::opengl::Material::attachShader( const std::string& filename, enums::Shader::type_t stage, const std::string& pipeline ) { +void ext::opengl::Material::attachShader( const uf::stl::string& filename, enums::Shader::type_t stage, const uf::stl::string& pipeline ) { auto& shader = shaders.emplace_back(); shader.initialize( *device, filename, stage ); - std::string type = "unknown"; + uf::stl::string type = "unknown"; switch ( stage ) { case uf::renderer::enums::Shader::VERTEX: type = "vertex"; break; case uf::renderer::enums::Shader::FRAGMENT: type = "fragment"; break; @@ -111,13 +111,13 @@ void ext::opengl::Material::attachShader( const std::string& filename, enums::Sh metadata.json["shaders"][pipeline][type]["filename"] = filename; metadata.shaders[pipeline+":"+type] = shaders.size() - 1; } -void ext::opengl::Material::initializeShaders( const std::vector>& layout, const std::string& pipeline ) { +void ext::opengl::Material::initializeShaders( const uf::stl::vector>& layout, const uf::stl::string& pipeline ) { shaders.clear(); shaders.reserve( layout.size() ); for ( auto& request : layout ) { attachShader( request.first, request.second, pipeline ); } } -bool ext::opengl::Material::hasShader( const std::string& type, const std::string& pipeline ) { +bool ext::opengl::Material::hasShader( const uf::stl::string& type, const uf::stl::string& pipeline ) { #if !UF_USE_OPENGL_FIXED_FUNCTION // return !ext::json::isNull( metadata["shaders"][type] ); return metadata.shaders.count(pipeline+":"+type) > 0; @@ -128,7 +128,7 @@ bool ext::opengl::Material::hasShader( const std::string& type, const std::strin return (bool) shader.module; #endif } -ext::opengl::Shader& ext::opengl::Material::getShader( const std::string& type, const std::string& pipeline ) { +ext::opengl::Shader& ext::opengl::Material::getShader( const uf::stl::string& type, const uf::stl::string& pipeline ) { UF_ASSERT( hasShader(type, pipeline) ); return shaders.at( metadata.shaders[pipeline+":"+type] ); /* @@ -148,7 +148,7 @@ bool ext::opengl::Material::validate() { ext::opengl::Graphic::~Graphic() { this->destroy(); } -void ext::opengl::Graphic::initialize( const std::string& renderModeName ) { +void ext::opengl::Graphic::initialize( const uf::stl::string& renderModeName ) { RenderMode& renderMode = ext::opengl::getRenderMode(renderModeName, true); this->descriptor.renderMode = renderModeName; @@ -255,7 +255,7 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript Buffer::Descriptor vertexBuffer = {}; Buffer::Descriptor indexBuffer = {}; Buffer::Descriptor uniformBuffer = {}; - std::vector storageBuffers; + uf::stl::vector storageBuffers; for ( auto& buffer : buffers ) { if ( buffer.usage & uf::renderer::enums::Buffer::VERTEX ) { vertexBuffer = buffer.descriptor; } @@ -311,7 +311,7 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript size_t offset = 0; size_t range = 0; }; - std::vector mappings; + uf::stl::vector mappings; TextureMapping currentMapping; pod::Texture::Storage* storageBufferTextures = NULL; @@ -396,13 +396,13 @@ void ext::opengl::Graphic::destroy() { ext::opengl::states::rebuild = true; } -bool ext::opengl::Graphic::hasStorage( const std::string& name ) { +bool ext::opengl::Graphic::hasStorage( const uf::stl::string& name ) { for ( auto& shader : material.shaders ) { if ( shader.hasStorage(name) ) return true; } return false; } -ext::opengl::Buffer* ext::opengl::Graphic::getStorageBuffer( const std::string& name ) { +ext::opengl::Buffer* ext::opengl::Graphic::getStorageBuffer( const uf::stl::string& name ) { size_t storageIndex = -1; for ( auto& shader : material.shaders ) { if ( !shader.hasStorage(name) ) continue; @@ -417,14 +417,14 @@ ext::opengl::Buffer* ext::opengl::Graphic::getStorageBuffer( const std::string& } return NULL; } -uf::Serializer ext::opengl::Graphic::getStorageJson( const std::string& name, bool cache ) { +uf::Serializer ext::opengl::Graphic::getStorageJson( const uf::stl::string& name, bool cache ) { for ( auto& shader : material.shaders ) { if ( !shader.hasStorage(name) ) continue; return shader.getStorageJson(name, cache); } return ext::json::null(); } -ext::opengl::userdata_t ext::opengl::Graphic::getStorageUserdata( const std::string& name, const ext::json::Value& payload ) { +ext::opengl::userdata_t ext::opengl::Graphic::getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ) { for ( auto& shader : material.shaders ) { if ( !shader.hasStorage(name) ) continue; return shader.getStorageUserdata(name, payload); @@ -472,21 +472,21 @@ void ext::opengl::Graphic::updateStorage( void* data, size_t size, size_t target #include void ext::opengl::GraphicDescriptor::parse( ext::json::Value& metadata ) { - if ( metadata["front face"].is() ) { - if ( metadata["front face"].as() == "ccw" ) { + if ( metadata["front face"].is() ) { + if ( metadata["front face"].as() == "ccw" ) { frontFace = uf::renderer::enums::Face::CCW; - } else if ( metadata["front face"].as() == "cw" ) { + } else if ( metadata["front face"].as() == "cw" ) { frontFace = uf::renderer::enums::Face::CW; } } - if ( metadata["cull mode"].is() ) { - if ( metadata["cull mode"].as() == "back" ) { + if ( metadata["cull mode"].is() ) { + if ( metadata["cull mode"].as() == "back" ) { cullMode = uf::renderer::enums::CullMode::BACK; - } else if ( metadata["cull mode"].as() == "front" ) { + } else if ( metadata["cull mode"].as() == "front" ) { cullMode = uf::renderer::enums::CullMode::FRONT; - } else if ( metadata["cull mode"].as() == "none" ) { + } else if ( metadata["cull mode"].as() == "none" ) { cullMode = uf::renderer::enums::CullMode::NONE; - } else if ( metadata["cull mode"].as() == "both" ) { + } else if ( metadata["cull mode"].as() == "both" ) { cullMode = uf::renderer::enums::CullMode::BOTH; } } @@ -586,7 +586,7 @@ ext::json::Value ext::opengl::definitionToJson(/*const*/ ext::json::Value& defin // is object if ( !ext::json::isNull(definition["members"]) ) { ext::json::forEach(definition["members"], [&](/*const*/ ext::json::Value& value){ - std::string key = uf::string::split(value["name"].as(), " ").back(); + uf::stl::string key = uf::string::split(value["name"].as(), " ").back(); member[key] = ext::opengl::definitionToJson(value); }); // is primitive @@ -622,13 +622,13 @@ ext::opengl::userdata_t ext::opengl::jsonToUserdata( const ext::json::Value& pay // JSON is ordered, we can just push directly #define UF_SHADER_TRACK_NAMES 0 #if UF_SHADER_TRACK_NAMES - std::vector variableName; + uf::stl::vector variableName; #endif std::function parse = [&]( const ext::json::Value& value ){ // is array or object #if UF_SHADER_TRACK_NAMES if ( ext::json::isObject(value) ) { - ext::json::forEach(value, [&]( const std::string& name, const ext::json::Value& member ){ + ext::json::forEach(value, [&]( const uf::stl::string& name, const ext::json::Value& member ){ #if UF_SHADER_TRACK_NAMES variableName.emplace_back(name); #endif @@ -656,7 +656,7 @@ ext::opengl::userdata_t ext::opengl::jsonToUserdata( const ext::json::Value& pay } #endif #if UF_SHADER_TRACK_NAMES - std::string path = uf::string::join(variableName, "."); + uf::stl::string path = uf::string::join(variableName, "."); path = uf::string::replace( path, ".[", "[" ); GL_VALIDATION_MESSAGE("[" << (byteBuffer - byteBufferStart) << " / "<< (byteBufferEnd - byteBuffer) <<"]\tInserting: " << path << " = " << value.dump()); #endif @@ -693,7 +693,7 @@ ext::opengl::userdata_t ext::opengl::jsonToUserdata( const ext::json::Value& pay #endif #else - auto pushValue = [&]( const std::string& primitive, const ext::json::Value& input ){ + auto pushValue = [&]( const uf::stl::string& primitive, const ext::json::Value& input ){ if ( primitive == "bool" ) { size_t size = sizeof(bool); // v["size"].as(); if ( byteBufferEnd < byteBuffer + size ) return false; // overflow @@ -773,40 +773,40 @@ ext::opengl::userdata_t ext::opengl::jsonToUserdata( const ext::json::Value& pay #define UF_SHADER_TRACK_NAMES 0 #if UF_SHADER_TRACK_NAMES bool SKIP_ADD = false; - std::vector variableName; + uf::stl::vector variableName; #endif std::function parseDefinition = [&](const ext::json::Value& input, const ext::json::Value& definition ){ #if UF_SHADER_TRACK_NAMES if ( SKIP_ADD ) { SKIP_ADD = false; } else { - auto split = uf::string::split(definition["name"].as(), " "); - std::string type = split.front(); - std::string name = split.back(); + auto split = uf::string::split(definition["name"].as(), " "); + uf::stl::string type = split.front(); + uf::stl::string name = split.back(); variableName.emplace_back(name); } #endif // is object if ( !ext::json::isNull(definition["members"]) ) { ext::json::forEach(definition["members"], [&](const ext::json::Value& member){ - std::string key = uf::string::split(member["name"].as(), " ").back(); + uf::stl::string key = uf::string::split(member["name"].as(), " ").back(); parseDefinition(input[key], member); }); // is array or primitive } else if ( !ext::json::isNull(definition["value"]) ) { // is object - auto split = uf::string::split(definition["name"].as(), " "); - std::string type = split.front(); - std::string name = split.back(); + auto split = uf::string::split(definition["name"].as(), " "); + uf::stl::string type = split.front(); + uf::stl::string name = split.back(); std::regex regex("^(?:(.+?)\\<)?(.+?)(?:\\>)?(?:\\[(\\d+)\\])?$"); std::smatch match; if ( !std::regex_search( type, match, regex ) ) { - std::cout << "Ill formatted typename: " << definition["name"].as() << std::endl; + std::cout << "Ill formatted typename: " << definition["name"].as() << std::endl; return; } - std::string vectorMatrix = match[1].str(); - std::string primitive = match[2].str(); - std::string arraySize = match[3].str(); + uf::stl::string vectorMatrix = match[1].str(); + uf::stl::string primitive = match[2].str(); + uf::stl::string arraySize = match[3].str(); if ( ext::json::isObject(input) ) { ext::json::Value cloned; cloned["name"] = definition["name"]; @@ -827,7 +827,7 @@ ext::opengl::userdata_t ext::opengl::jsonToUserdata( const ext::json::Value& pay // is primitive else { #if UF_SHADER_TRACK_NAMES - std::string path = uf::string::join(variableName, "."); + uf::stl::string path = uf::string::join(variableName, "."); path = uf::string::replace( path, ".[", "[" ); GL_VALIDATION_MESSAGE("[" << (byteBuffer - byteBufferStart) << " / "<< (byteBufferEnd - byteBuffer) <<"]\tInserting: " << path << " = (" << primitive << ") " << input.dump()); #endif diff --git a/engine/src/ext/opengl/opengl.cpp b/engine/src/ext/opengl/opengl.cpp index 5351ae22..e500a4de 100644 --- a/engine/src/ext/opengl/opengl.cpp +++ b/engine/src/ext/opengl/opengl.cpp @@ -20,10 +20,10 @@ bool ext::opengl::settings::validation = true; // constexpr size_t ext::opengl::settings::maxViews = 6; size_t ext::opengl::settings::viewCount = 2; -std::vector ext::opengl::settings::validationFilters; -std::vector ext::opengl::settings::requestedDeviceFeatures; -std::vector ext::opengl::settings::requestedDeviceExtensions; -std::vector ext::opengl::settings::requestedInstanceExtensions; +uf::stl::vector ext::opengl::settings::validationFilters; +uf::stl::vector ext::opengl::settings::requestedDeviceFeatures; +uf::stl::vector ext::opengl::settings::requestedDeviceExtensions; +uf::stl::vector ext::opengl::settings::requestedInstanceExtensions; ext::opengl::enums::Filter::type_t ext::opengl::settings::swapchainUpscaleFilter = ext::opengl::enums::Filter::LINEAR; @@ -32,7 +32,7 @@ bool ext::opengl::settings::experimental::waitOnRenderEnd = false; bool ext::opengl::settings::experimental::individualPipelines = true; bool ext::opengl::settings::experimental::multithreadedCommandRecording = true; bool ext::opengl::settings::experimental::multithreadedCommandRendering = false; -std::string ext::opengl::settings::experimental::deferredMode = ""; +uf::stl::string ext::opengl::settings::experimental::deferredMode = ""; bool ext::opengl::settings::experimental::deferredReconstructPosition = false; bool ext::opengl::settings::experimental::deferredAliasOutputToSwapchain = true; bool ext::opengl::settings::experimental::multiview = true; @@ -56,17 +56,17 @@ bool ext::opengl::states::resized = false; bool ext::opengl::states::rebuild = false; uint32_t ext::opengl::states::currentBuffer = 0; -std::vector ext::opengl::scenes; +uf::stl::vector ext::opengl::scenes; ext::opengl::RenderMode* ext::opengl::currentRenderMode = NULL; -std::vector ext::opengl::renderModes = { +uf::stl::vector ext::opengl::renderModes = { new ext::opengl::BaseRenderMode, }; -std::string UF_API ext::opengl::errorString() { +uf::stl::string UF_API ext::opengl::errorString() { return ext::opengl::errorString(glGetError()); } -std::string UF_API ext::opengl::errorString( GLenum error ) { - std::string str = ""; +uf::stl::string UF_API ext::opengl::errorString( GLenum error ) { + uf::stl::string str = ""; if (error == GL_NO_ERROR) return str; #if UF_ENV_DREAMCAST #else @@ -77,7 +77,7 @@ std::string UF_API ext::opengl::errorString( GLenum error ) { } ///// -bool ext::opengl::hasRenderMode( const std::string& name, bool isName ) { +bool ext::opengl::hasRenderMode( const uf::stl::string& name, bool isName ) { for ( auto& renderMode: ext::opengl::renderModes ) { if ( isName ) { if ( renderMode->getName() == name ) return true; @@ -88,7 +88,7 @@ bool ext::opengl::hasRenderMode( const std::string& name, bool isName ) { return false; } -ext::opengl::RenderMode& ext::opengl::addRenderMode( ext::opengl::RenderMode* mode, const std::string& name ) { +ext::opengl::RenderMode& ext::opengl::addRenderMode( ext::opengl::RenderMode* mode, const uf::stl::string& name ) { mode->metadata.name = name; renderModes.push_back(mode); if ( ext::opengl::settings::validation ) uf::iostream << "Adding RenderMode: " << name << ": " << mode->getType() << "\n"; @@ -96,7 +96,7 @@ ext::opengl::RenderMode& ext::opengl::addRenderMode( ext::opengl::RenderMode* mo ext::opengl::states::rebuild = true; return *mode; } -ext::opengl::RenderMode& ext::opengl::getRenderMode( const std::string& name, bool isName ) { +ext::opengl::RenderMode& ext::opengl::getRenderMode( const uf::stl::string& name, bool isName ) { RenderMode* target = renderModes[0]; for ( auto& renderMode: renderModes ) { if ( isName ) { @@ -115,11 +115,11 @@ ext::opengl::RenderMode& ext::opengl::getRenderMode( const std::string& name, bo // if ( ext::opengl::settings::validation ) uf::iostream << "Requesting RenderMode `" << name << "`, got `" << target->getName() << "` (" << target->getType() << ")" << "\n"; return *target; } -std::vector ext::opengl::getRenderModes( const std::string& name, bool isName ) { +uf::stl::vector ext::opengl::getRenderModes( const uf::stl::string& name, bool isName ) { return ext::opengl::getRenderModes({name}, isName); } -std::vector ext::opengl::getRenderModes( const std::vector& names, bool isName ) { - std::vector targets; +uf::stl::vector ext::opengl::getRenderModes( const uf::stl::vector& names, bool isName ) { + uf::stl::vector targets; for ( auto& renderMode: renderModes ) { if ( ( isName && std::find(names.begin(), names.end(), renderMode->getName()) != names.end() ) || std::find(names.begin(), names.end(), renderMode->getType()) != names.end() ) { targets.push_back(renderMode); @@ -140,7 +140,7 @@ void UF_API ext::opengl::initialize() { device.initialize(); // swapchain.initialize( device ); { - std::vector pixels = { + uf::stl::vector pixels = { 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, @@ -159,7 +159,7 @@ void UF_API ext::opengl::initialize() { renderMode->initialize(device); } - std::vector> jobs; + uf::stl::vector> jobs; for ( auto& renderMode : renderModes ) { if ( !renderMode ) continue; if ( settings::experimental::individualPipelines ) renderMode->bindPipelines(); @@ -321,7 +321,7 @@ void UF_API ext::opengl::tick(){ } renderMode->tick(); } - std::vector> jobs; + uf::stl::vector> jobs; for ( auto& renderMode : renderModes ) { if ( !renderMode ) continue; if ( ext::opengl::states::rebuild || renderMode->rebuild ) { @@ -412,11 +412,11 @@ void UF_API ext::opengl::synchronize( uint8_t flag ) { // vkDeviceWaitIdle( device ); } } -std::string UF_API ext::opengl::allocatorStats(){ +uf::stl::string UF_API ext::opengl::allocatorStats(){ return ""; } -ext::opengl::enums::Format::type_t ext::opengl::formatFromString( const std::string& string ) { - std::unordered_map table = { +ext::opengl::enums::Format::type_t ext::opengl::formatFromString( const uf::stl::string& string ) { + uf::stl::unordered_map table = { { "UNDEFINED", ext::opengl::enums::Format::UNDEFINED }, { "R4G4_UNORM_PACK8", ext::opengl::enums::Format::R4G4_UNORM_PACK8 }, { "R4G4B4A4_UNORM_PACK16", ext::opengl::enums::Format::R4G4B4A4_UNORM_PACK16 }, diff --git a/engine/src/ext/opengl/rendermode.cpp b/engine/src/ext/opengl/rendermode.cpp index 9811b8e6..f29c6b2d 100644 --- a/engine/src/ext/opengl/rendermode.cpp +++ b/engine/src/ext/opengl/rendermode.cpp @@ -19,12 +19,12 @@ ext::opengl::RenderMode::~RenderMode() { this->destroy(); } -const std::string ext::opengl::RenderMode::getType() const { +const uf::stl::string ext::opengl::RenderMode::getType() const { return ""; } -const std::string ext::opengl::RenderMode::getName() const { +const uf::stl::string ext::opengl::RenderMode::getName() const { // auto& metadata = *const_cast(&this->metadata); -// return metadata["name"].as(); +// return metadata["name"].as(); return metadata.name; } ext::opengl::RenderTarget& ext::opengl::RenderMode::getRenderTarget( size_t i ) { @@ -40,7 +40,7 @@ const size_t ext::opengl::RenderMode::blitters() const { ext::opengl::Graphic* ext::opengl::RenderMode::getBlitter( size_t i ) { return NULL; } -std::vector ext::opengl::RenderMode::getBlitters() { +uf::stl::vector ext::opengl::RenderMode::getBlitters() { return {}; } @@ -57,7 +57,7 @@ void ext::opengl::RenderMode::bindGraphicPushConstants( ext::opengl::Graphic* po void ext::opengl::RenderMode::createCommandBuffers() { this->execute = true; - std::vector graphics; + uf::stl::vector graphics; auto& scene = uf::scene::getCurrentScene(); auto& graph = scene.getGraph(); for ( auto entity : graph ) { @@ -84,13 +84,13 @@ ext::opengl::CommandBuffer& ext::opengl::RenderMode::getCommands( std::thread::i } return commands; } -void ext::opengl::RenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::opengl::RenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { } void ext::opengl::RenderMode::bindPipelines() { this->execute = true; - std::vector graphics; + uf::stl::vector graphics; auto& scene = uf::scene::getCurrentScene(); auto& graph = scene.getGraph(); for ( auto entity : graph ) { @@ -103,7 +103,7 @@ void ext::opengl::RenderMode::bindPipelines() { this->synchronize(); this->bindPipelines( graphics ); } -void ext::opengl::RenderMode::bindPipelines( const std::vector& graphics ) { +void ext::opengl::RenderMode::bindPipelines( const uf::stl::vector& graphics ) { for ( auto* pointer : graphics ) { auto& graphic = *pointer; for ( size_t currentPass = 0; currentPass < renderTarget.passes.size(); ++currentPass ) { diff --git a/engine/src/ext/opengl/rendermodes/base.cpp b/engine/src/ext/opengl/rendermodes/base.cpp index 1024fe4b..7c680514 100644 --- a/engine/src/ext/opengl/rendermodes/base.cpp +++ b/engine/src/ext/opengl/rendermodes/base.cpp @@ -9,10 +9,10 @@ #include #include -const std::string ext::opengl::BaseRenderMode::getType() const { +const uf::stl::string ext::opengl::BaseRenderMode::getType() const { return "Swapchain"; } -void ext::opengl::BaseRenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::opengl::BaseRenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { float width = this->width > 0 ? this->width : ext::opengl::settings::width; float height = this->height > 0 ? this->height : ext::opengl::settings::height; diff --git a/engine/src/ext/opengl/rendermodes/compute.cpp b/engine/src/ext/opengl/rendermodes/compute.cpp index 48d765c2..fd1d1345 100644 --- a/engine/src/ext/opengl/rendermodes/compute.cpp +++ b/engine/src/ext/opengl/rendermodes/compute.cpp @@ -15,7 +15,7 @@ #include -const std::string ext::opengl::ComputeRenderMode::getType() const { +const uf::stl::string ext::opengl::ComputeRenderMode::getType() const { return "Compute"; } const size_t ext::opengl::ComputeRenderMode::blitters() const { @@ -24,7 +24,7 @@ const size_t ext::opengl::ComputeRenderMode::blitters() const { ext::opengl::Graphic* ext::opengl::ComputeRenderMode::getBlitter( size_t i ) { return &this->blitter; } -std::vector ext::opengl::ComputeRenderMode::getBlitters() { +uf::stl::vector ext::opengl::ComputeRenderMode::getBlitters() { return { &this->blitter }; } diff --git a/engine/src/ext/opengl/rendermodes/deferred.cpp b/engine/src/ext/opengl/rendermodes/deferred.cpp index 14639b3b..8282233e 100644 --- a/engine/src/ext/opengl/rendermodes/deferred.cpp +++ b/engine/src/ext/opengl/rendermodes/deferred.cpp @@ -15,7 +15,7 @@ #include #include -const std::string ext::opengl::DeferredRenderMode::getType() const { +const uf::stl::string ext::opengl::DeferredRenderMode::getType() const { return "Deferred"; } const size_t ext::opengl::DeferredRenderMode::blitters() const { @@ -24,7 +24,7 @@ const size_t ext::opengl::DeferredRenderMode::blitters() const { ext::opengl::Graphic* ext::opengl::DeferredRenderMode::getBlitter( size_t i ) { return &this->blitter; } -std::vector ext::opengl::DeferredRenderMode::getBlitters() { +uf::stl::vector ext::opengl::DeferredRenderMode::getBlitters() { return { &this->blitter }; } @@ -37,7 +37,7 @@ void ext::opengl::DeferredRenderMode::tick() { void ext::opengl::DeferredRenderMode::destroy() { ext::opengl::RenderMode::destroy(); } -void ext::opengl::DeferredRenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::opengl::DeferredRenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { float width = this->width > 0 ? this->width : ext::opengl::settings::width; float height = this->height > 0 ? this->height : ext::opengl::settings::height; diff --git a/engine/src/ext/opengl/rendermodes/rendertarget.cpp b/engine/src/ext/opengl/rendermodes/rendertarget.cpp index f7e7568a..2ebd5e47 100644 --- a/engine/src/ext/opengl/rendermodes/rendertarget.cpp +++ b/engine/src/ext/opengl/rendermodes/rendertarget.cpp @@ -9,17 +9,17 @@ #include -const std::string ext::opengl::RenderTargetRenderMode::getTarget() const { +const uf::stl::string ext::opengl::RenderTargetRenderMode::getTarget() const { // auto& metadata = *const_cast(&this->metadata); -// return metadata["target"].as(); +// return metadata["target"].as(); return metadata.target; } -void ext::opengl::RenderTargetRenderMode::setTarget( const std::string& target ) { +void ext::opengl::RenderTargetRenderMode::setTarget( const uf::stl::string& target ) { // this->metadata["target"] = target; metadata.target = target; } -const std::string ext::opengl::RenderTargetRenderMode::getType() const { +const uf::stl::string ext::opengl::RenderTargetRenderMode::getType() const { return "RenderTarget"; } const size_t ext::opengl::RenderTargetRenderMode::blitters() const { @@ -28,7 +28,7 @@ const size_t ext::opengl::RenderTargetRenderMode::blitters() const { ext::opengl::Graphic* ext::opengl::RenderTargetRenderMode::getBlitter( size_t i ) { return &this->blitter; } -std::vector ext::opengl::RenderTargetRenderMode::getBlitters() { +uf::stl::vector ext::opengl::RenderTargetRenderMode::getBlitters() { return { &this->blitter }; } @@ -68,7 +68,7 @@ void ext::opengl::RenderTargetRenderMode::render() { } void ext::opengl::RenderTargetRenderMode::pipelineBarrier( GLhandle(VkCommandBuffer) commandBuffer, uint8_t state ) { } -void ext::opengl::RenderTargetRenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::opengl::RenderTargetRenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { float width = this->width > 0 ? this->width : ext::opengl::settings::width; float height = this->height > 0 ? this->height : ext::opengl::settings::height; diff --git a/engine/src/ext/opengl/rendertarget.cpp b/engine/src/ext/opengl/rendertarget.cpp index 44abad37..11865976 100644 --- a/engine/src/ext/opengl/rendertarget.cpp +++ b/engine/src/ext/opengl/rendertarget.cpp @@ -5,7 +5,7 @@ #include #include -void ext::opengl::RenderTarget::addPass( GLhandle(VkPipelineStageFlags) stage, GLhandle(VkAccessFlags) access, const std::vector& colors, const std::vector& inputs, const std::vector& resolves, size_t depth, bool autoBuildPipeline ) { +void ext::opengl::RenderTarget::addPass( GLhandle(VkPipelineStageFlags) stage, GLhandle(VkAccessFlags) access, const uf::stl::vector& colors, const uf::stl::vector& inputs, const uf::stl::vector& resolves, size_t depth, bool autoBuildPipeline ) { } size_t ext::opengl::RenderTarget::attach( const Attachment::Descriptor& descriptor, Attachment* attachment ) { return attachments.size()-1; diff --git a/engine/src/ext/opengl/shader.cpp b/engine/src/ext/opengl/shader.cpp index 9a2b141a..993aaf05 100644 --- a/engine/src/ext/opengl/shader.cpp +++ b/engine/src/ext/opengl/shader.cpp @@ -13,12 +13,12 @@ namespace { uint32_t VERTEX_BUFFER_BIND_ID = 0; #if UF_USE_OPENGL_FIXED_FUNCTION - std::unordered_map modules; + uf::stl::unordered_map modules; #endif } #if UF_USE_OPENGL_FIXED_FUNCTION -void ext::opengl::Shader::bind( const std::string& name, const module_t& module ) { +void ext::opengl::Shader::bind( const uf::stl::string& name, const module_t& module ) { ::modules[name] = module; } void ext::opengl::Shader::execute( const ext::opengl::Graphic& graphic, void* userdata ) { @@ -31,7 +31,7 @@ ext::opengl::Shader::~Shader() { if ( !aliased ) destroy(); } */ -void ext::opengl::Shader::initialize( ext::opengl::Device& device, const std::string& filename, enums::Shader::type_t stage ) { +void ext::opengl::Shader::initialize( ext::opengl::Device& device, const uf::stl::string& filename, enums::Shader::type_t stage ) { this->device = &device; descriptor.stage = stage; @@ -45,7 +45,7 @@ void ext::opengl::Shader::initialize( ext::opengl::Device& device, const std::st } // GPU-based shader execution #if !UF_USE_OPENGL_FIXED_FUNCTION - std::string glsl; + uf::stl::string glsl; { std::ifstream is(this->filename = filename, std::ios::binary | std::ios::in | std::ios::ate); if ( !is.is_open() ) { @@ -124,11 +124,11 @@ bool ext::opengl::Shader::validate() { #endif return valid; } -bool ext::opengl::Shader::hasUniform( const std::string& name ) { +bool ext::opengl::Shader::hasUniform( const uf::stl::string& name ) { // return !ext::json::isNull(metadata.json["definitions"]["uniforms"][name]); return metadata.definitions.uniforms.count(name) > 0; } -ext::opengl::Buffer* ext::opengl::Shader::getUniformBuffer( const std::string& name ) { +ext::opengl::Buffer* ext::opengl::Shader::getUniformBuffer( const uf::stl::string& name ) { if ( !hasUniform(name) ) return NULL; // size_t uniformIndex = metadata.json["definitions"]["uniforms"][name]["index"].as(); size_t uniformIndex = metadata.definitions.uniforms[name].index; @@ -139,7 +139,7 @@ ext::opengl::Buffer* ext::opengl::Shader::getUniformBuffer( const std::string& n } return NULL; } -ext::opengl::userdata_t& ext::opengl::Shader::getUniform( const std::string& name ) { +ext::opengl::userdata_t& ext::opengl::Shader::getUniform( const uf::stl::string& name ) { UF_ASSERT( hasUniform(name) ); return uniforms[metadata.definitions.uniforms[name].index]; /* @@ -154,12 +154,12 @@ ext::opengl::userdata_t& ext::opengl::Shader::getUniform( const std::string& nam return userdata; */ } -bool ext::opengl::Shader::updateUniform( const std::string& name ) { +bool ext::opengl::Shader::updateUniform( const uf::stl::string& name ) { if ( !hasUniform(name) ) return false; auto& uniform = getUniform(name); return updateUniform(name, uniform); } -bool ext::opengl::Shader::updateUniform( const std::string& name, const ext::opengl::userdata_t& userdata ) { +bool ext::opengl::Shader::updateUniform( const uf::stl::string& name, const ext::opengl::userdata_t& userdata ) { if ( !hasUniform(name) ) return false; auto* bufferObject = getUniformBuffer(name); if ( !bufferObject ) return false; @@ -169,18 +169,18 @@ bool ext::opengl::Shader::updateUniform( const std::string& name, const ext::ope return true; } -uf::Serializer ext::opengl::Shader::getUniformJson( const std::string& name, bool cache ) { +uf::Serializer ext::opengl::Shader::getUniformJson( const uf::stl::string& name, bool cache ) { if ( !hasUniform(name) ) return ext::json::null(); if ( cache && !ext::json::isNull(metadata.json["uniforms"][name]) ) return metadata.json["uniforms"][name]; auto& definition = metadata.json["definitions"]["uniforms"][name]; if ( cache ) return metadata.json["uniforms"][name] = definitionToJson(definition); return definitionToJson(definition); } -ext::opengl::userdata_t ext::opengl::Shader::getUniformUserdata( const std::string& name, const ext::json::Value& payload ) { +ext::opengl::userdata_t ext::opengl::Shader::getUniformUserdata( const uf::stl::string& name, const ext::json::Value& payload ) { if ( !hasUniform(name) ) return false; return jsonToUserdata(payload, metadata.json["definitions"]["uniforms"][name]); } -bool ext::opengl::Shader::updateUniform( const std::string& name, const ext::json::Value& payload ) { +bool ext::opengl::Shader::updateUniform( const uf::stl::string& name, const ext::json::Value& payload ) { if ( !hasUniform(name) ) return false; auto* bufferObject = getUniformBuffer(name); @@ -191,12 +191,12 @@ bool ext::opengl::Shader::updateUniform( const std::string& name, const ext::jso return true; } -bool ext::opengl::Shader::hasStorage( const std::string& name ) { +bool ext::opengl::Shader::hasStorage( const uf::stl::string& name ) { // return !ext::json::isNull(metadata["definitions"]["storage"][name]); return metadata.definitions.storage.count(name) > 0; } -ext::opengl::Buffer* ext::opengl::Shader::getStorageBuffer( const std::string& name ) { +ext::opengl::Buffer* ext::opengl::Shader::getStorageBuffer( const uf::stl::string& name ) { if ( !hasStorage(name) ) return NULL; // size_t storageIndex = metadata.json["definitions"]["storage"][name]["index"].as(); size_t storageIndex = metadata.definitions.storage[name].index; @@ -207,14 +207,14 @@ ext::opengl::Buffer* ext::opengl::Shader::getStorageBuffer( const std::string& n } return NULL; } -uf::Serializer ext::opengl::Shader::getStorageJson( const std::string& name, bool cache ) { +uf::Serializer ext::opengl::Shader::getStorageJson( const uf::stl::string& name, bool cache ) { if ( !hasStorage(name) ) return ext::json::null(); if ( cache && !ext::json::isNull(metadata.json["storage"][name]) ) return metadata.json["storage"][name]; auto& definition = metadata.json["definitions"]["storage"][name]; if ( cache ) return metadata.json["storage"][name] = definitionToJson(definition); return definitionToJson(definition); } -ext::opengl::userdata_t ext::opengl::Shader::getStorageUserdata( const std::string& name, const ext::json::Value& payload ) { +ext::opengl::userdata_t ext::opengl::Shader::getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ) { if ( !hasStorage(name) ) return false; return jsonToUserdata(payload, metadata.json["definitions"]["storage"][name]); } diff --git a/engine/src/ext/opengl/texture.cpp b/engine/src/ext/opengl/texture.cpp index d60ccbff..9fa6b5d4 100644 --- a/engine/src/ext/opengl/texture.cpp +++ b/engine/src/ext/opengl/texture.cpp @@ -75,7 +75,7 @@ void ext::opengl::Texture::destroy() { image = GL_NULL_HANDLE; } void ext::opengl::Texture::loadFromFile( - const std::string& filename, + const uf::stl::string& filename, enums::Format::type_t format ) { return loadFromFile( filename, ext::opengl::device, format ); @@ -87,7 +87,7 @@ void ext::opengl::Texture::loadFromImage( return loadFromImage( image, ext::opengl::device, format ); } void ext::opengl::Texture::loadFromFile( - const std::string& filename, + const uf::stl::string& filename, Device& device, enums::Format::type_t format ) { diff --git a/engine/src/ext/openvr/openvr.cpp b/engine/src/ext/openvr/openvr.cpp index 2437ceaa..fbe5ed36 100644 --- a/engine/src/ext/openvr/openvr.cpp +++ b/engine/src/ext/openvr/openvr.cpp @@ -26,20 +26,20 @@ uint8_t ext::openvr::dominantEye = 0; // toPort namespace { - std::string GetTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError = NULL) { + uf::stl::string GetTrackedDeviceString(vr::IVRSystem *pHmd, vr::TrackedDeviceIndex_t unDevice, vr::TrackedDeviceProperty prop, vr::TrackedPropertyError *peError = NULL) { uint32_t requiredBufferLen = pHmd->GetStringTrackedDeviceProperty(unDevice, prop, NULL, 0, peError); if( requiredBufferLen == 0 ) return ""; char *pchBuffer = new char[requiredBufferLen]; requiredBufferLen = pHmd->GetStringTrackedDeviceProperty(unDevice,prop,pchBuffer,requiredBufferLen,peError); - std::string sResult = pchBuffer; + uf::stl::string sResult = pchBuffer; delete[] pchBuffer; return sResult; } - std::string GetTrackedDeviceClassString(vr::ETrackedDeviceClass klass) { - std::string str = "Unknown class"; + uf::stl::string GetTrackedDeviceClassString(vr::ETrackedDeviceClass klass) { + uf::stl::string str = "Unknown class"; switch ( klass ) { case vr::TrackedDeviceClass_Invalid: // = 0, the ID was not valid. @@ -81,19 +81,19 @@ namespace { } devices; struct { - std::unordered_map actions; - std::unordered_map actionSets; - // std::vector inputs; - std::vector activeActionSets; + uf::stl::unordered_map actions; + uf::stl::unordered_map actionSets; + // uf::stl::vector inputs; + uf::stl::vector activeActionSets; } handles; struct QueuedRenderModel { vr::RenderModel_t* model; vr::RenderModel_TextureMap_t* texture; }; - std::unordered_map queuedRenderModels; - std::unordered_map renderModels; - std::vector renderModelNames; + uf::stl::unordered_map queuedRenderModels; + uf::stl::unordered_map renderModels; + uf::stl::vector renderModelNames; } bool ext::openvr::initialize( int stage ) { @@ -126,7 +126,7 @@ bool ext::openvr::initialize( int stage ) { for ( uint32_t i = vr::k_unTrackedDeviceIndex_Hmd; i < vr::k_unMaxTrackedDeviceCount; ++i ) { if ( !ext::openvr::context->IsTrackedDeviceConnected(i) ) continue; vr::ETrackedDeviceClass trackedDeviceClass = ext::openvr::context->GetTrackedDeviceClass(i); - std::string trackedDeviceType = ::GetTrackedDeviceClassString(trackedDeviceClass); + uf::stl::string trackedDeviceType = ::GetTrackedDeviceClassString(trackedDeviceClass); ext::openvr::driver.types[i] = trackedDeviceType; uf::iostream << "Tracking device " << i << " is connected " << "\n"; @@ -165,7 +165,7 @@ bool ext::openvr::initialize( int stage ) { if ( DEBUG_MARKER ) UF_MSG_DEBUG(ext::openvr::driver.manifest); for ( auto i = 0; i < manifest["action_sets"].size(); ++i ) { if ( DEBUG_MARKER ) UF_MSG_DEBUG(manifest["action_sets"][i]); - std::string name = manifest["action_sets"][i]["name"].as(); + uf::stl::string name = manifest["action_sets"][i]["name"].as(); vr::VRActionSetHandle_t handle; VR_CHECK_INPUT_RESULT( vr::VRInput()->GetActionSetHandle( name.c_str(), &handle ) ); handles.actionSets[name] = handle; @@ -173,7 +173,7 @@ bool ext::openvr::initialize( int stage ) { // handles.actionSets.push_back(handle); } for ( auto i = 0; i < manifest["actions"].size(); ++i ) { - std::string name = manifest["actions"][i]["name"].as(); + uf::stl::string name = manifest["actions"][i]["name"].as(); vr::VRActionHandle_t handle; VR_CHECK_INPUT_RESULT( vr::VRInput()->GetActionHandle( name.c_str(), &handle ) ); handles.actions[name] = handle; @@ -182,8 +182,8 @@ bool ext::openvr::initialize( int stage ) { // add haptics to hooks { - std::vector split = uf::string::split( name, "/" ); - std::string shortname = split.back(); + uf::stl::vector split = uf::string::split( name, "/" ); + uf::stl::string shortname = split.back(); split = uf::string::split( shortname, "." ); if ( split.front() == "hapticVibration" ) { if ( DEBUG_MARKER ) UF_MSG_DEBUG("Registered hook for haptic: " << ("VR:Haptics."+split.back())); @@ -206,7 +206,7 @@ bool ext::openvr::initialize( int stage ) { size_t strlen = vr::VRRenderModels()->GetRenderModelName( i, NULL, 0 ); char buffer[strlen]; vr::VRRenderModels()->GetRenderModelName( i, &buffer[0], strlen ); - std::string name = buffer; + uf::stl::string name = buffer; ::renderModelNames.push_back( name ); } } @@ -241,7 +241,7 @@ void ext::openvr::tick() { // load render model from api for ( auto& pair : ::queuedRenderModels ) { if ( DEBUG_MARKER ) UF_MSG_DEBUG("QUEUED: " << pair.first); - std::string name = pair.first; + uf::stl::string name = pair.first; auto& queued = pair.second; { vr::EVRRenderModelError status = vr::VRRenderModels()->LoadRenderModel_Async( name.c_str(), &queued.model ); @@ -330,7 +330,7 @@ void ext::openvr::tick() { } vr::VRInput()->UpdateActionState( handles.activeActionSets.data(), sizeof(vr::VRActiveActionSet_t), handles.activeActionSets.size() ); for ( auto pair : handles.actions ) { - std::string name = pair.first; + uf::stl::string name = pair.first; auto& handle = pair.second; // analog data { @@ -341,8 +341,8 @@ void ext::openvr::tick() { pod::Vector3f position = { data.x, data.y, data.z }; if ( data.bActive ) { uf::Serializer payload; - std::vector split = uf::string::split( name, "/" ); - std::string shortname = split.back(); + uf::stl::vector split = uf::string::split( name, "/" ); + uf::stl::string shortname = split.back(); split = uf::string::split( shortname, "." ); payload["name"] = split.front(); @@ -369,8 +369,8 @@ void ext::openvr::tick() { if ( vr::VRInputError_None == vr::VRInput()->GetDigitalActionData(handle, &data, sizeof(data), vr::k_ulInvalidInputValueHandle) ) { if ( data.bActive ) { uf::Serializer payload; - std::vector split = uf::string::split( name, "/" ); - std::string shortname = split.back(); + uf::stl::vector split = uf::string::split( name, "/" ); + uf::stl::string shortname = split.back(); split = uf::string::split( shortname, "." ); payload["name"] = split.front(); @@ -390,8 +390,8 @@ void ext::openvr::tick() { { vr::InputPoseActionData_t data; if ( vr::VRInputError_None == vr::VRInput()->GetPoseActionDataRelativeToNow(handle, vr::TrackingUniverseStanding, fPredictedSecondsFromNow, &data, sizeof(data), vr::k_ulInvalidInputValueHandle) ) { - std::vector split = uf::string::split( name, "/" ); - std::string shortname = split.back(); + uf::stl::vector split = uf::string::split( name, "/" ); + uf::stl::string shortname = split.back(); split = uf::string::split( shortname, "." ); if ( split.front() == "handPose" ) { if ( split.back() == "left" ) ::devices.controllers.left.active = data.bActive; @@ -419,7 +419,7 @@ void ext::openvr::tick() { } } } -bool ext::openvr::requestRenderModel( const std::string& name ) { +bool ext::openvr::requestRenderModel( const uf::stl::string& name ) { if ( DEBUG_MARKER ) UF_MSG_DEBUG("Requesting render model: " << name); if ( std::find( renderModelNames.begin(), renderModelNames.end(), name ) == renderModelNames.end() ) return false; if ( renderModels.count(name) == 1 ) return true; @@ -659,7 +659,7 @@ pod::Matrix4t<> ext::openvr::hmdProjectionMatrix( vr::Hmd_Eye eye, float zNear, } break; } } -uf::Serializer ext::openvr::controllerState( vr::Controller_Hand hand, const std::string& key ) { +uf::Serializer ext::openvr::controllerState( vr::Controller_Hand hand, const uf::stl::string& key ) { if ( hand == vr::Controller_Hand::Hand_Left ) return key == "" ? ::devices.controllers.left.state : ::devices.controllers.left.state[key]; else if ( hand == vr::Controller_Hand::Hand_Right ) return key == "" ? ::devices.controllers.right.state : ::devices.controllers.right.state[key]; return uf::Serializer(); @@ -718,7 +718,7 @@ bool ext::openvr::controllerActive( vr::Controller_Hand hand ) { else if ( hand == vr::Controller_Hand::Hand_Right ) return ::devices.controllers.right.active; return false; } -uf::Graphic& ext::openvr::getRenderModel( const std::string& name ) { +uf::Graphic& ext::openvr::getRenderModel( const uf::stl::string& name ) { return ::renderModels[name]; } uf::Graphic& ext::openvr::controllerRenderModel( vr::Controller_Hand hand ) { diff --git a/engine/src/ext/ultralight/ultralight.cpp b/engine/src/ext/ultralight/ultralight.cpp index 46421539..7bb42159 100644 --- a/engine/src/ext/ultralight/ultralight.cpp +++ b/engine/src/ext/ultralight/ultralight.cpp @@ -4,13 +4,13 @@ #include #include -// std::string ext::ultralight::resourcesDir = uf::io::root + "/resources/"; +// uf::stl::string ext::ultralight::resourcesDir = uf::io::root + "/resources/"; namespace { size_t uids = 0; ULRenderer renderer; - std::vector queue; + uf::stl::vector queue; void OnFinishLoading(void* user_data, ULView caller, unsigned long long frame_id, bool is_main_frame, ULString url) { if ( !is_main_frame ) return; pod::HTML& container = *((pod::HTML*) user_data); @@ -21,8 +21,8 @@ namespace { } } void ConsoleMessageCallback(void* user_data, ULView caller, ULMessageSource _source, ULMessageLevel _level, ULString _message, unsigned int line_number, unsigned int column_number, ULString source_id) { - std::string level = "?"; - std::string source = "?"; + uf::stl::string level = "?"; + uf::stl::string source = "?"; switch ( _level ) { case ULMessageLevel::kMessageLevel_Log: level = "Log"; break; case ULMessageLevel::kMessageLevel_Warning: level = "Warning"; break; @@ -55,7 +55,7 @@ namespace { namespace UL { struct String { ULString handle; - String( const std::string& str = "" ) { + String( const uf::stl::string& str = "" ) { handle = ulCreateString( str.c_str() ); } String( uint32_t c ) { @@ -81,15 +81,15 @@ namespace UL { struct KeyEvent { ULKeyEvent handle; - KeyEvent( const std::string& payload ) { + KeyEvent( const uf::stl::string& payload ) { uf::Serializer event = payload; ULKeyEventType type; - if ( event["key"]["state"].is() ) { - std::string s = event["key"]["state"].as(); + if ( event["key"]["state"].is() ) { + uf::stl::string s = event["key"]["state"].as(); if ( s == "Down" ) type = ULKeyEventType::kKeyEventType_RawKeyDown; else if ( s == "Up" ) type = ULKeyEventType::kKeyEventType_KeyUp; } - if ( event["type"].as() == "window:Text.Entered" ) { + if ( event["type"].as() == "window:Text.Entered" ) { type = ULKeyEventType::kKeyEventType_Char; uint32_t modifiers = 0; int32_t virtualKeyCode = 0; @@ -108,8 +108,8 @@ namespace UL { uint32_t modifiers = getModifiers( event["key"]["modifier"] ); int32_t virtualKeyCode = event["key"]["raw"].as(); int32_t nativeKeyCode = event["key"]["lparam"].as(); - std::string text = ""; //event["key"]["code"].as(); - std::string unmodifiedText = ""; //event["key"]["code"].as(); + uf::stl::string text = ""; //event["key"]["code"].as(); + uf::stl::string unmodifiedText = ""; //event["key"]["code"].as(); bool isKeypad = false; bool isAutoRepeat = false; bool isSystemKey = event["key"]["modifier"]["system"].as(); @@ -127,18 +127,18 @@ namespace UL { }; struct MouseEvent { ULMouseEvent handle; - MouseEvent( const std::string& payload ) { + MouseEvent( const uf::stl::string& payload ) { uf::Serializer event = payload; ULMouseEventType type = ULMouseEventType::kMouseEventType_MouseMoved; ULMouseButton button = ULMouseButton::kMouseButton_None; - if ( event["mouse"]["state"].is() ) { - std::string s = event["mouse"]["state"].as(); + if ( event["mouse"]["state"].is() ) { + uf::stl::string s = event["mouse"]["state"].as(); if ( s == "Up" ) type = ULMouseEventType::kMouseEventType_MouseUp; else if ( s == "Down" ) type = ULMouseEventType::kMouseEventType_MouseDown; } - if ( event["mouse"]["button"].is() ) { - std::string s = event["mouse"]["button"].as(); + if ( event["mouse"]["button"].is() ) { + uf::stl::string s = event["mouse"]["button"].as(); if ( s == "Left" ) button = ULMouseButton::kMouseButton_Left; else if ( s == "Middle" ) button = ULMouseButton::kMouseButton_Middle; else if ( s == "Right" ) button = ULMouseButton::kMouseButton_Right; @@ -158,7 +158,7 @@ namespace UL { }; struct ScrollEvent { ULScrollEvent handle; - ScrollEvent( const std::string& payload ) { + ScrollEvent( const uf::stl::string& payload ) { uf::Serializer event = payload; ULScrollEventType type = ULScrollEventType::kScrollEventType_ScrollByPixel; handle = ulCreateScrollEvent( type, 0, event["mouse"]["delta"].as() ); @@ -204,21 +204,21 @@ void ext::ultralight::terminate() { ulDestroyRenderer(renderer); } -pod::HTML ext::ultralight::create( const std::string& html, const pod::Vector2ui& size ) { +pod::HTML ext::ultralight::create( const uf::stl::string& html, const pod::Vector2ui& size ) { pod::HTML container; return create( container, html, size ); } -pod::HTML& ext::ultralight::create( pod::HTML& container, const std::string& html, const pod::Vector2ui& size ) { +pod::HTML& ext::ultralight::create( pod::HTML& container, const uf::stl::string& html, const pod::Vector2ui& size ) { container.uid = ++uids; container.view = ulCreateView(::renderer, size.x, size.y, false, 0, false); container.size = size; // is URI - if ( html.find("://") != std::string::npos ) { + if ( html.find("://") != uf::stl::string::npos ) { ulViewLoadURL(container.view, UL::String(html)); // is filename } else if ( uf::io::extension(html) == "html" ) { - std::string html = uf::io::readAsString( uf::io::resolveURI( html ) ); + uf::stl::string html = uf::io::readAsString( uf::io::resolveURI( html ) ); ulViewLoadHTML(container.view, UL::String(html)); // is HTML } else { @@ -233,7 +233,7 @@ pod::HTML& ext::ultralight::create( pod::HTML& container, const std::string& htm void ext::ultralight::destroy( pod::HTML& container ) { ulDestroyView(container.view); } -void ext::ultralight::on( pod::HTML& container, const std::string& name, const std::string& hook ) { +void ext::ultralight::on( pod::HTML& container, const uf::stl::string& name, const uf::stl::string& hook ) { if ( name == "load" ) container.callbacks.load = hook; } void ext::ultralight::resize( pod::HTML& container, const pod::Vector2ui& size ) { @@ -241,15 +241,15 @@ void ext::ultralight::resize( pod::HTML& container, const pod::Vector2ui& size ) container.pending = true; ulViewResize( container.view, size.x, size.y ); } -void ext::ultralight::input( pod::HTML& container, const std::string& payload ) { +void ext::ultralight::input( pod::HTML& container, const uf::stl::string& payload ) { uf::Serializer event = payload; // std::cout << payload << std::endl; - if ( event["type"].as() == "window:Key.Pressed" || event["type"].as() == "window:Key.Released" || event["type"].as() == "window:Text.Entered" ) { + if ( event["type"].as() == "window:Key.Pressed" || event["type"].as() == "window:Key.Released" || event["type"].as() == "window:Text.Entered" ) { ulViewFireKeyEvent( container.view, UL::KeyEvent( payload ) ); - } else if ( event["type"].as() == "window:Mouse.Moved" || event["type"].as() == "window:Mouse.Click" ) { + } else if ( event["type"].as() == "window:Mouse.Moved" || event["type"].as() == "window:Mouse.Click" ) { ulViewFireMouseEvent( container.view, UL::MouseEvent( payload ) ); - } else if ( event["type"].as() == "window:Mouse.Wheel" ) { + } else if ( event["type"].as() == "window:Mouse.Wheel" ) { ulViewFireScrollEvent( container.view, UL::ScrollEvent( payload ) ); } else { // std::cout << "Unknown event: " << event << std::endl; diff --git a/engine/src/ext/vorbis/vorbis.cpp b/engine/src/ext/vorbis/vorbis.cpp index 62a6fc82..74ed724d 100644 --- a/engine/src/ext/vorbis/vorbis.cpp +++ b/engine/src/ext/vorbis/vorbis.cpp @@ -6,7 +6,7 @@ #endif #include -#include +#include #include #include @@ -131,7 +131,7 @@ void ext::vorbis::load( uf::Audio::Metadata& metadata ) { int32_t read; char buffer[uf::audio::bufferSize]; - std::vector bytes; + uf::stl::vector bytes; do { read = ov_read( &vorbisFile, buffer, uf::audio::bufferSize, endian, 2, 1, &metadata.stream.bitStream ); bytes.insert( bytes.end(), buffer, buffer + read ); diff --git a/engine/src/ext/vulkan/device.cpp b/engine/src/ext/vulkan/device.cpp index a6c1d4a1..277b379f 100644 --- a/engine/src/ext/vulkan/device.cpp +++ b/engine/src/ext/vulkan/device.cpp @@ -14,37 +14,37 @@ namespace { #if UF_USE_OPENVR - void VRInstanceExtensions( std::vector& requested ) { + void VRInstanceExtensions( uf::stl::vector& requested ) { if ( !vr::VRCompositor() ) return; int32_t nBufferSize = vr::VRCompositor()->GetVulkanInstanceExtensionsRequired( nullptr, 0 ); if ( nBufferSize < 0 ) return; char pExtensionStr[nBufferSize]; pExtensionStr[0] = 0; vr::VRCompositor()->GetVulkanInstanceExtensionsRequired( pExtensionStr, nBufferSize ); - std::vector extensions = uf::string::split( pExtensionStr, " " ); + uf::stl::vector extensions = uf::string::split( pExtensionStr, " " ); for ( auto& str : extensions ) { // uf::iostream << str << "\n"; requested.push_back(str); } // requested.insert( requested.end(), extensions.begin(), extensions.end() ); } - void VRDeviceExtensions( VkPhysicalDevice_T* physicalDevice, std::vector& requested ) { + void VRDeviceExtensions( VkPhysicalDevice_T* physicalDevice, uf::stl::vector& requested ) { if ( !vr::VRCompositor() ) return; int32_t nBufferSize = vr::VRCompositor()->GetVulkanDeviceExtensionsRequired( physicalDevice, nullptr, 0 ); if ( nBufferSize < 0 ) return; char pExtensionStr[nBufferSize]; pExtensionStr[0] = 0; vr::VRCompositor()->GetVulkanDeviceExtensionsRequired( physicalDevice , pExtensionStr, nBufferSize ); - std::vector extensions = uf::string::split( pExtensionStr, " " ); + uf::stl::vector extensions = uf::string::split( pExtensionStr, " " ); for ( auto& str : extensions ) requested.push_back(str); // requested.insert( requested.end(), extensions.begin(), extensions.end() ); } #endif - void validateRequestedExtensions( const std::vector& extensionProperties, const std::vector& requestedExtensions, std::vector& supportedExtensions ) { + void validateRequestedExtensions( const uf::stl::vector& extensionProperties, const uf::stl::vector& requestedExtensions, uf::stl::vector& supportedExtensions ) { for ( auto& requestedExtension : requestedExtensions ) { bool found = false; for ( auto& extensionProperty : extensionProperties ) { - std::string extensionName = extensionProperty.extensionName; + uf::stl::string extensionName = extensionProperty.extensionName; if ( requestedExtension != extensionName ) continue; if ( std::find( supportedExtensions.begin(), supportedExtensions.end(), extensionName ) != supportedExtensions.end() ) { found = true; @@ -272,14 +272,14 @@ int ext::vulkan::Device::rate( VkPhysicalDevice device ) { if ( !deviceFeatures.geometryShader ) return 0; // { - const std::vector deviceExtensions = { + const uf::stl::vector deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; uint32_t extensionCount; vkEnumerateDeviceExtensionProperties( device, nullptr, &extensionCount, nullptr ); - std::vector availableExtensions( extensionCount ); + uf::stl::vector availableExtensions( extensionCount ); vkEnumerateDeviceExtensionProperties( device, nullptr, &extensionCount, availableExtensions.data() ); - std::set requiredExtensions( deviceExtensions.begin(), deviceExtensions.end() ); + std::set requiredExtensions( deviceExtensions.begin(), deviceExtensions.end() ); for ( const auto& extension : availableExtensions ) requiredExtensions.erase( extension.extensionName ); @@ -289,8 +289,8 @@ int ext::vulkan::Device::rate( VkPhysicalDevice device ) { // { VkSurfaceCapabilitiesKHR capabilities; - std::vector formats; - std::vector presentModes; + uf::stl::vector formats; + uf::stl::vector presentModes; vkGetPhysicalDeviceSurfaceCapabilitiesKHR( device, this->surface, &capabilities ); @@ -522,14 +522,14 @@ VkQueue& ext::vulkan::Device::getQueue( ext::vulkan::Device::QueueEnum queueEnum } void ext::vulkan::Device::initialize() { - const std::vector validationLayers = { + const uf::stl::vector validationLayers = { "VK_LAYER_KHRONOS_validation" }; // Assert validation layers if ( ext::vulkan::settings::validation ) { uint32_t layerCount; vkEnumerateInstanceLayerProperties(&layerCount, nullptr); - std::vector availableLayers(layerCount); + uf::stl::vector availableLayers(layerCount); vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); for ( const char* layerName : validationLayers ) { bool layerFound = false; @@ -543,7 +543,7 @@ void ext::vulkan::Device::initialize() { } // // Get extensions - std::vector requestedExtensions = window->getExtensions( ext::vulkan::settings::validation ); + uf::stl::vector requestedExtensions = window->getExtensions( ext::vulkan::settings::validation ); // Load any requested extensions requestedExtensions.insert( requestedExtensions.end(), ext::vulkan::settings::requestedInstanceExtensions.begin(), ext::vulkan::settings::requestedInstanceExtensions.end() ); #if UF_USE_OPENVR @@ -566,7 +566,7 @@ void ext::vulkan::Device::initialize() { } // Create instance { - std::vector instanceExtensions; + uf::stl::vector instanceExtensions; for ( auto& s : supportedExtensions.instance ) { if ( ext::vulkan::settings::validation ) uf::iostream << "Enabled instance extension: " << s << "\n"; @@ -600,7 +600,7 @@ void ext::vulkan::Device::initialize() { { ext::json::Value payload = ext::json::array(); for ( auto* c_str : instanceExtensions ) { - payload.emplace_back( std::string(c_str) ); + payload.emplace_back( uf::stl::string(c_str) ); } uf::hooks.call("vulkan:Instance.ExtensionsEnabled", payload); } @@ -627,7 +627,7 @@ void ext::vulkan::Device::initialize() { vkEnumeratePhysicalDevices( this->instance, &deviceCount, nullptr ); if ( deviceCount == 0 ) UF_EXCEPTION("Vulkan error: failed to find GPUs with Vulkan support!"); - std::vector devices(deviceCount); + uf::stl::vector devices(deviceCount); vkEnumeratePhysicalDevices( this->instance, &deviceCount, devices.data() ); // Use an ordered map to automatically sort candidates by increasing score std::multimap candidates; @@ -681,7 +681,7 @@ void ext::vulkan::Device::initialize() { { bool useSwapChain = true; VkQueueFlags requestedQueueTypes = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT; - std::vector requestedExtensions; + uf::stl::vector requestedExtensions; requestedExtensions.insert( requestedExtensions.end(), ext::vulkan::settings::requestedDeviceExtensions.begin(), ext::vulkan::settings::requestedDeviceExtensions.end() ); #if UF_USE_OPENVR // OpenVR Support @@ -703,7 +703,7 @@ void ext::vulkan::Device::initialize() { validateRequestedExtensions( extensionProperties.device, requestedExtensions, supportedExtensions.device ); } - std::vector deviceExtensions = { + uf::stl::vector deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; for ( auto& s : supportedExtensions.device ) { @@ -714,7 +714,7 @@ void ext::vulkan::Device::initialize() { // Desired queues need to be requested upon logical device creation // Due to differing queue family configurations of Vulkan implementations this can be a bit tricky, especially if the application // requests different queue types - std::vector queueCreateInfos{}; + uf::stl::vector queueCreateInfos{}; // Get queue family indices for the requested queue family types // Note that the indices may overlap depending on the implementation const float defaultQueuePriority(0.0f); @@ -806,7 +806,7 @@ void ext::vulkan::Device::initialize() { } { uf::Serializer payload = ext::json::array(); - for ( auto* c_str : deviceExtensions ) payload.emplace_back( std::string(c_str) ); + for ( auto* c_str : deviceExtensions ) payload.emplace_back( uf::stl::string(c_str) ); uf::hooks.call("vulkan:Device.ExtensionsEnabled", payload); } { @@ -861,7 +861,7 @@ void ext::vulkan::Device::initialize() { } // Set formats { - std::vector formats; + uf::stl::vector formats; uint32_t formatCount; vkGetPhysicalDeviceSurfaceFormatsKHR( this->physicalDevice, device.surface, &formatCount, nullptr); formats.resize( formatCount ); vkGetPhysicalDeviceSurfaceFormatsKHR( this->physicalDevice, device.surface, &formatCount, formats.data() ); @@ -904,7 +904,7 @@ void ext::vulkan::Device::initialize() { { // Since all depth formats may be optional, we need to find a suitable depth format to use // Start with the highest precision packed format - std::vector depthFormats = { + uf::stl::vector depthFormats = { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D24_UNORM_S8_UINT, @@ -927,7 +927,7 @@ void ext::vulkan::Device::initialize() { VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {}; pipelineCacheCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; - std::vector buffer; + uf::stl::vector buffer; // read from cache on disk if ( uf::io::exists( uf::io::root + "/cache/vulkan/cache.bin" ) ) { buffer = uf::io::readAsBuffer( uf::io::root + "/cache/vulkan/cache.bin" ); @@ -957,7 +957,7 @@ void ext::vulkan::Device::destroy() { size_t size{}; VK_CHECK_RESULT(vkGetPipelineCacheData(this->logicalDevice, this->pipelineCache, &size, NULL)); - std::vector data(size); + uf::stl::vector data(size); VK_CHECK_RESULT(vkGetPipelineCacheData(this->logicalDevice, this->pipelineCache, &size, data.data())); uf::io::write( uf::io::root + "/cache/vulkan/cache.bin", data ); diff --git a/engine/src/ext/vulkan/graphic.cpp b/engine/src/ext/vulkan/graphic.cpp index 15011796..c5b9d687 100644 --- a/engine/src/ext/vulkan/graphic.cpp +++ b/engine/src/ext/vulkan/graphic.cpp @@ -33,10 +33,10 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des RenderMode& renderMode = ext::vulkan::getRenderMode( descriptor.renderMode, true); auto& renderTarget = renderMode.getRenderTarget( descriptor.renderTarget ); { - std::vector descriptorSetLayoutBindings; - std::vector pushConstantRanges; - std::vector poolSizes; - std::unordered_map descriptorTypes; + uf::stl::vector descriptorSetLayoutBindings; + uf::stl::vector pushConstantRanges; + uf::stl::vector poolSizes; + uf::stl::unordered_map descriptorTypes; // for ( auto& shader : graphic.material.shaders ) { for ( auto* shaderPointer : shaders ) { @@ -131,7 +131,7 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des rasterizationState.depthBiasSlopeFactor = graphic.descriptor.depth.bias.slope; rasterizationState.depthBiasClamp = graphic.descriptor.depth.bias.clamp; - std::vector blendAttachmentStates; + uf::stl::vector blendAttachmentStates; VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT; if ( renderMode.getType() != "Swapchain" ) { @@ -195,7 +195,7 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des } - std::vector dynamicStateEnables = { + uf::stl::vector dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; @@ -206,7 +206,7 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des ); // Binding description - std::vector vertexBindingDescriptions = { + uf::stl::vector vertexBindingDescriptions = { ext::vulkan::initializers::vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, descriptor.geometry.attributes.vertex.size, @@ -215,7 +215,7 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des }; // Attribute descriptions // Describes memory layout and shader positions - std::vector vertexAttributeDescriptions = {}; + uf::stl::vector vertexAttributeDescriptions = {}; for ( auto& attribute : descriptor.geometry.attributes.descriptor ) { auto d = ext::vulkan::initializers::vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, @@ -232,7 +232,7 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des vertexInputState.vertexAttributeDescriptionCount = vertexAttributeDescriptions.size(); vertexInputState.pVertexAttributeDescriptions = vertexAttributeDescriptions.data(); - std::vector shaderDescriptors; + uf::stl::vector shaderDescriptors; for ( auto* shaderPointer : shaders ) { auto& shader = *shaderPointer; @@ -241,7 +241,7 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic, GraphicDescriptor& des bool invalidated = true; for ( size_t i = 0; i < len / 4; ++i ) { auto& payload = shader.metadata.json["specializationConstants"][i]; - std::string type = payload["type"].as(); + uf::stl::string type = payload["type"].as(); if ( type == "int32_t" ) { int32_t& v = ((int32_t*) s)[i]; // failsafe, because for some reason things break @@ -361,7 +361,7 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip RenderMode& renderMode = ext::vulkan::getRenderMode(descriptor.renderMode, true); auto& renderTarget = renderMode.getRenderTarget(descriptor.renderTarget ); - std::vector descriptorSetLayoutBindings; + uf::stl::vector descriptorSetLayoutBindings; auto shaders = getShaders( graphic.material.shaders ); for ( auto* shaderPointer : shaders ) { auto& shader = *shaderPointer; @@ -369,17 +369,17 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip } struct { - std::vector uniform; - std::vector storage; + uf::stl::vector uniform; + uf::stl::vector storage; - std::vector image; - std::vector image2D; - std::vector imageCube; - std::vector image3D; - std::vector imageUnknown; + uf::stl::vector image; + uf::stl::vector image2D; + uf::stl::vector imageCube; + uf::stl::vector image3D; + uf::stl::vector imageUnknown; - std::vector sampler; - std::vector input; + uf::stl::vector sampler; + uf::stl::vector input; } infos; if ( descriptor.subpass < renderTarget.passes.size() ) { @@ -414,8 +414,8 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip } size_t consumes = 0; -// std::vector types; - std::vector types; +// uf::stl::vector types; + uf::stl::vector types; for ( auto* shaderPointer : shaders ) { auto& shader = *shaderPointer; @@ -439,8 +439,8 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { consumes += layout.descriptorCount; - // std::string binding = std::to_string(layout.binding); - // std::string imageType = shader.metadata.json["definitions"]["textures"][binding]["type"].as(); + // uf::stl::string binding = std::to_string(layout.binding); + // uf::stl::string imageType = shader.metadata.json["definitions"]["textures"][binding]["type"].as(); ext::vulkan::enums::Image::viewType_t imageType = shader.metadata.definitions.textures[layout.binding].type; types.reserve(consumes); for ( size_t i = 0; i < layout.descriptorCount; ++i ) types.emplace_back(imageType); @@ -466,7 +466,7 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip while ( infos.imageUnknown.size() < maxTexturesUnknown ) infos.imageUnknown.push_back(Texture2D::empty.descriptor); for ( size_t i = infos.image.size(); i < consumes; ++i ) { - // std::string type = i < types.size() ? types[i] : ""; + // uf::stl::string type = i < types.size() ? types[i] : ""; ext::vulkan::enums::Image::viewType_t type = i < types.size() ? types[i] : ext::vulkan::enums::Image::viewType_t{}; if ( type == ext::vulkan::enums::Image::VIEW_TYPE_3D ) infos.image.push_back(Texture3D::empty.descriptor); else if ( type == ext::vulkan::enums::Image::VIEW_TYPE_CUBE ) infos.image.push_back(TextureCube::empty.descriptor); @@ -487,7 +487,7 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip auto inputInfo = infos.input.begin(); - std::vector writeDescriptorSets; + uf::stl::vector writeDescriptorSets; for ( auto* shaderPointer : shaders ) { auto& shader = *shaderPointer; @@ -510,8 +510,8 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip // if ( layout.descriptorCount == 1 ) UF_MSG_DEBUG(i.imageView << "\t" << (*imageInfo).imageLayout); #if 1 - // std::string binding = std::to_string(layout.binding); - // std::string imageType = shader.metadata.json["definitions"]["textures"][binding]["type"].as(); + // uf::stl::string binding = std::to_string(layout.binding); + // uf::stl::string imageType = shader.metadata.json["definitions"]["textures"][binding]["type"].as(); ext::vulkan::enums::Image::viewType_t imageType = shader.metadata.definitions.textures[layout.binding].type; if ( imageType == ext::vulkan::enums::Image::VIEW_TYPE_2D ) { UF_ASSERT_BREAK_MSG( image2DInfo != infos.image2D.end(), "Filename: " << shader.filename << "\tCount: " << layout.descriptorCount ) @@ -635,8 +635,8 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip if ( descriptor.pImageInfo[i].imageView == VK_NULL_HANDLE || descriptor.pImageInfo[i].imageLayout == VK_IMAGE_LAYOUT_UNDEFINED ) { VK_DEBUG_VALIDATION_MESSAGE("Null image view or layout is undefined, replacing with fallback texture..."); auto pointer = const_cast(&descriptor.pImageInfo[i]); - // std::string binding = std::to_string(descriptor.dstBinding); - // std::string imageType = ""; + // uf::stl::string binding = std::to_string(descriptor.dstBinding); + // uf::stl::string imageType = ""; ext::vulkan::enums::Image::viewType_t imageType{}; for ( auto* shaderPointer : shaders ) { auto& shader = *shaderPointer; @@ -645,7 +645,7 @@ void ext::vulkan::Pipeline::update( Graphic& graphic, GraphicDescriptor& descrip imageType = shader.metadata.definitions.textures[descriptor.dstBinding].type; // auto& info = shader.metadata.json["definitions"]["textures"][binding]; // if ( ext::json::isNull(info) ) continue; - // imageType = info["type"].as(); + // imageType = info["type"].as(); break; } if ( imageType == ext::vulkan::enums::Image::VIEW_TYPE_3D ) { @@ -715,9 +715,9 @@ void ext::vulkan::Pipeline::destroy() { descriptorSetLayout = VK_NULL_HANDLE; } } -std::vector ext::vulkan::Pipeline::getShaders( std::vector& shaders ) { - std::unordered_map map; - std::vector res; +uf::stl::vector ext::vulkan::Pipeline::getShaders( uf::stl::vector& shaders ) { + uf::stl::unordered_map map; + uf::stl::vector res; for ( auto& shader : shaders ) { if ( shader.metadata.pipeline != "" && shader.metadata.pipeline != metadata.type ) continue; map[shader.metadata.type] = &shader; @@ -740,7 +740,7 @@ void ext::vulkan::Material::destroy() { textures.clear(); samplers.clear(); } -void ext::vulkan::Material::attachShader( const std::string& filename, VkShaderStageFlagBits stage, const std::string& pipeline ) { +void ext::vulkan::Material::attachShader( const uf::stl::string& filename, VkShaderStageFlagBits stage, const uf::stl::string& pipeline ) { auto& shader = shaders.emplace_back(); shader.initialize( *device, filename, stage ); @@ -751,7 +751,7 @@ void ext::vulkan::Material::attachShader( const std::string& filename, VkShaderS sampler.initialize( *device ); } - std::string type = "unknown"; + uf::stl::string type = "unknown"; switch ( stage ) { case VK_SHADER_STAGE_VERTEX_BIT: type = "vertex"; break; case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: type = "tessellation_control"; break; @@ -775,17 +775,17 @@ void ext::vulkan::Material::attachShader( const std::string& filename, VkShaderS metadata.json["shaders"][pipeline][type]["filename"] = filename; metadata.shaders[pipeline+":"+type] = shaders.size() - 1; } -void ext::vulkan::Material::initializeShaders( const std::vector>& layout, const std::string& pipeline ) { +void ext::vulkan::Material::initializeShaders( const uf::stl::vector>& layout, const uf::stl::string& pipeline ) { shaders.clear(); shaders.reserve( layout.size() ); for ( auto& request : layout ) { attachShader( request.first, request.second, pipeline ); } } -bool ext::vulkan::Material::hasShader( const std::string& type, const std::string& pipeline ) { +bool ext::vulkan::Material::hasShader( const uf::stl::string& type, const uf::stl::string& pipeline ) { return metadata.shaders.count(pipeline+":"+type) > 0; // return !ext::json::isNull( metadata.json["shaders"][pipeline][type] ); } -ext::vulkan::Shader& ext::vulkan::Material::getShader( const std::string& type, const std::string& pipeline ) { +ext::vulkan::Shader& ext::vulkan::Material::getShader( const uf::stl::string& type, const uf::stl::string& pipeline ) { UF_ASSERT( hasShader(type, pipeline) ); return shaders.at( metadata.shaders[pipeline+":"+type] ); /* @@ -805,7 +805,7 @@ bool ext::vulkan::Material::validate() { ext::vulkan::Graphic::~Graphic() { this->destroy(); } -void ext::vulkan::Graphic::initialize( const std::string& renderModeName ) { +void ext::vulkan::Graphic::initialize( const uf::stl::string& renderModeName ) { RenderMode& renderMode = ext::vulkan::getRenderMode(renderModeName, true); // if ( !uf::Camera::USE_REVERSE_INFINITE_PROJECTION && descriptor.depth.operation == ext::vulkan::enums::Compare::GREATER_OR_EQUAL ) { @@ -951,13 +951,13 @@ void ext::vulkan::Graphic::destroy() { ext::vulkan::states::rebuild = true; } -bool ext::vulkan::Graphic::hasStorage( const std::string& name ) { +bool ext::vulkan::Graphic::hasStorage( const uf::stl::string& name ) { for ( auto& shader : material.shaders ) { if ( shader.hasStorage(name) ) return true; } return false; } -ext::vulkan::Buffer* ext::vulkan::Graphic::getStorageBuffer( const std::string& name ) { +ext::vulkan::Buffer* ext::vulkan::Graphic::getStorageBuffer( const uf::stl::string& name ) { size_t storageIndex = -1; for ( auto& shader : material.shaders ) { if ( !shader.hasStorage(name) ) continue; @@ -972,14 +972,14 @@ ext::vulkan::Buffer* ext::vulkan::Graphic::getStorageBuffer( const std::string& } return NULL; } -uf::Serializer ext::vulkan::Graphic::getStorageJson( const std::string& name, bool cache ) { +uf::Serializer ext::vulkan::Graphic::getStorageJson( const uf::stl::string& name, bool cache ) { for ( auto& shader : material.shaders ) { if ( !shader.hasStorage(name) ) continue; return shader.getStorageJson(name, cache); } return ext::json::null(); } -ext::vulkan::userdata_t ext::vulkan::Graphic::getStorageUserdata( const std::string& name, const ext::json::Value& payload ) { +ext::vulkan::userdata_t ext::vulkan::Graphic::getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ) { for ( auto& shader : material.shaders ) { if ( !shader.hasStorage(name) ) continue; return shader.getStorageUserdata(name, payload); @@ -989,21 +989,21 @@ ext::vulkan::userdata_t ext::vulkan::Graphic::getStorageUserdata( const std::str #include void ext::vulkan::GraphicDescriptor::parse( ext::json::Value& metadata ) { - if ( metadata["front face"].is() ) { - if ( metadata["front face"].as() == "ccw" ) { + if ( metadata["front face"].is() ) { + if ( metadata["front face"].as() == "ccw" ) { frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - } else if ( metadata["front face"].as() == "cw" ) { + } else if ( metadata["front face"].as() == "cw" ) { frontFace = VK_FRONT_FACE_CLOCKWISE; } } - if ( metadata["cull mode"].is() ) { - if ( metadata["cull mode"].as() == "back" ) { + if ( metadata["cull mode"].is() ) { + if ( metadata["cull mode"].as() == "back" ) { cullMode = VK_CULL_MODE_BACK_BIT; - } else if ( metadata["cull mode"].as() == "front" ) { + } else if ( metadata["cull mode"].as() == "front" ) { cullMode = VK_CULL_MODE_FRONT_BIT; - } else if ( metadata["cull mode"].as() == "none" ) { + } else if ( metadata["cull mode"].as() == "none" ) { cullMode = VK_CULL_MODE_NONE; - } else if ( metadata["cull mode"].as() == "both" ) { + } else if ( metadata["cull mode"].as() == "both" ) { cullMode = VK_CULL_MODE_FRONT_AND_BACK; } } diff --git a/engine/src/ext/vulkan/rendermode.cpp b/engine/src/ext/vulkan/rendermode.cpp index 5301462a..7db3b2d0 100644 --- a/engine/src/ext/vulkan/rendermode.cpp +++ b/engine/src/ext/vulkan/rendermode.cpp @@ -16,12 +16,12 @@ ext::vulkan::RenderMode::~RenderMode() { this->destroy(); } -const std::string ext::vulkan::RenderMode::getType() const { +const uf::stl::string ext::vulkan::RenderMode::getType() const { return ""; } -const std::string ext::vulkan::RenderMode::getName() const { +const uf::stl::string ext::vulkan::RenderMode::getName() const { // auto& metadata = *const_cast(&this->metadata); -// return metadata["name"].as(); +// return metadata["name"].as(); return metadata.name; } ext::vulkan::RenderTarget& ext::vulkan::RenderMode::getRenderTarget( size_t i ) { @@ -37,7 +37,7 @@ const size_t ext::vulkan::RenderMode::blitters() const { ext::vulkan::Graphic* ext::vulkan::RenderMode::getBlitter( size_t i ) { return NULL; } -std::vector ext::vulkan::RenderMode::getBlitters() { +uf::stl::vector ext::vulkan::RenderMode::getBlitters() { return {}; } @@ -170,7 +170,7 @@ ext::vulkan::GraphicDescriptor ext::vulkan::RenderMode::bindGraphicDescriptor( c void ext::vulkan::RenderMode::createCommandBuffers() { this->execute = true; - std::vector graphics; + uf::stl::vector graphics; auto& scene = uf::scene::getCurrentScene(); auto& graph = scene.getGraph(); for ( auto entity : graph ) { @@ -205,13 +205,13 @@ ext::vulkan::RenderMode::commands_container_t& ext::vulkan::RenderMode::getComma } return commands; } -void ext::vulkan::RenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::vulkan::RenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { } void ext::vulkan::RenderMode::bindPipelines() { this->execute = true; - std::vector graphics; + uf::stl::vector graphics; auto& scene = uf::scene::getCurrentScene(); auto& graph = scene.getGraph(); for ( auto entity : graph ) { @@ -224,7 +224,7 @@ void ext::vulkan::RenderMode::bindPipelines() { this->synchronize(); this->bindPipelines( graphics ); } -void ext::vulkan::RenderMode::bindPipelines( const std::vector& graphics ) { +void ext::vulkan::RenderMode::bindPipelines( const uf::stl::vector& graphics ) { for ( auto* pointer : graphics ) { auto& graphic = *pointer; for ( size_t currentPass = 0; currentPass < renderTarget.passes.size(); ++currentPass ) { diff --git a/engine/src/ext/vulkan/rendermodes/base.cpp b/engine/src/ext/vulkan/rendermodes/base.cpp index 18768282..6ba02340 100644 --- a/engine/src/ext/vulkan/rendermodes/base.cpp +++ b/engine/src/ext/vulkan/rendermodes/base.cpp @@ -9,7 +9,7 @@ #include namespace { - std::vector images; + uf::stl::vector images; } /* @@ -17,10 +17,10 @@ ext::vulkan::BaseRenderMode::~BaseRenderMode() { this->destroy(); } */ -const std::string ext::vulkan::BaseRenderMode::getType() const { +const uf::stl::string ext::vulkan::BaseRenderMode::getType() const { return "Swapchain"; } -void ext::vulkan::BaseRenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::vulkan::BaseRenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { if ( ext::vulkan::renderModes.size() > 1 ) return; auto windowSize = device->window->getSize(); diff --git a/engine/src/ext/vulkan/rendermodes/compute.cpp b/engine/src/ext/vulkan/rendermodes/compute.cpp index d08a348e..a929ea35 100644 --- a/engine/src/ext/vulkan/rendermodes/compute.cpp +++ b/engine/src/ext/vulkan/rendermodes/compute.cpp @@ -15,7 +15,7 @@ #include -const std::string ext::vulkan::ComputeRenderMode::getType() const { +const uf::stl::string ext::vulkan::ComputeRenderMode::getType() const { return "Compute"; } const size_t ext::vulkan::ComputeRenderMode::blitters() const { @@ -24,7 +24,7 @@ const size_t ext::vulkan::ComputeRenderMode::blitters() const { ext::vulkan::Graphic* ext::vulkan::ComputeRenderMode::getBlitter( size_t i ) { return &this->blitter; } -std::vector ext::vulkan::ComputeRenderMode::getBlitters() { +uf::stl::vector ext::vulkan::ComputeRenderMode::getBlitters() { return { &this->blitter }; } diff --git a/engine/src/ext/vulkan/rendermodes/deferred.cpp b/engine/src/ext/vulkan/rendermodes/deferred.cpp index 93916d6c..429cac0c 100644 --- a/engine/src/ext/vulkan/rendermodes/deferred.cpp +++ b/engine/src/ext/vulkan/rendermodes/deferred.cpp @@ -14,7 +14,7 @@ #include #include -const std::string ext::vulkan::DeferredRenderMode::getType() const { +const uf::stl::string ext::vulkan::DeferredRenderMode::getType() const { return "Deferred"; } const size_t ext::vulkan::DeferredRenderMode::blitters() const { @@ -23,7 +23,7 @@ const size_t ext::vulkan::DeferredRenderMode::blitters() const { ext::vulkan::Graphic* ext::vulkan::DeferredRenderMode::getBlitter( size_t i ) { return &this->blitter; } -std::vector ext::vulkan::DeferredRenderMode::getBlitters() { +uf::stl::vector ext::vulkan::DeferredRenderMode::getBlitters() { return { &this->blitter }; } @@ -44,7 +44,7 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { for ( size_t eye = 0; eye < metadata.eyes; ++eye ) { struct { size_t id, normals, uvs, albedo, depth, output, debug; - } attachments; + } attachments = {}; attachments.id = renderTarget.attach(RenderTarget::Attachment::Descriptor{ /*.format = */VK_FORMAT_R16G16_UINT, @@ -209,8 +209,8 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { blitter.initialize( this->getName() ); blitter.initializeMesh( mesh ); - std::string vertexShaderFilename = uf::io::root+"/shaders/display/subpass.vert.spv"; - std::string fragmentShaderFilename = uf::io::root+"/shaders/display/subpass.frag.spv"; + uf::stl::string vertexShaderFilename = uf::io::root+"/shaders/display/subpass.vert.spv"; + uf::stl::string fragmentShaderFilename = uf::io::root+"/shaders/display/subpass.frag.spv"; if ( uf::renderer::settings::experimental::vxgi ) { fragmentShaderFilename = uf::string::replace( fragmentShaderFilename, "frag", "vxgi.frag" ); } @@ -225,7 +225,7 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { {uf::io::resolveURI(fragmentShaderFilename), VK_SHADER_STAGE_FRAGMENT_BIT} }); /* - std::string fragmentShaderFilename = ( msaa <= 1 ) ? "no-msaa." : ""; + uf::stl::string fragmentShaderFilename = ( msaa <= 1 ) ? "no-msaa." : ""; if ( ext::vulkan::settings::experimental::vxgi ) { fragmentShaderFilename = ( msaa <= 1 ) ? "vxgi.no-msaa." : "vxgi."; } @@ -259,14 +259,14 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { */ uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTextures2D); else if ( name == "CUBEMAPS" ) sc["value"] = (specializationConstants[i] = maxTexturesCube); else if ( name == "CASCADES" ) sc["value"] = (specializationConstants[i] = maxCascades); }); ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ size_t binding = t["binding"].as(); - std::string name = t["name"].as(); + uf::stl::string name = t["name"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding != binding ) continue; if ( name == "samplerTextures" ) layout.descriptorCount = maxTextures2D; @@ -289,14 +289,14 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { */ uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTextures2D); else if ( name == "CUBEMAPS" ) sc["value"] = (specializationConstants[i] = maxTexturesCube); }); ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ size_t binding = t["binding"].as(); - std::string name = t["name"].as(); + uf::stl::string name = t["name"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding != binding ) continue; if ( name == "samplerTextures" ) layout.descriptorCount = maxTextures2D; @@ -305,10 +305,10 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) { }); } - std::vector lights(maxLights); - std::vector materials(maxTextures2D); - std::vector textures(maxTextures2D); - std::vector drawCalls(maxTextures2D); + uf::stl::vector lights(maxLights); + uf::stl::vector materials(maxTextures2D); + uf::stl::vector textures(maxTextures2D); + uf::stl::vector drawCalls(maxTextures2D); for ( auto& material : materials ) material.colorBase = {0,0,0,0}; @@ -372,7 +372,7 @@ ext::vulkan::GraphicDescriptor ext::vulkan::DeferredRenderMode::bindGraphicDescr ext::vulkan::GraphicDescriptor descriptor = ext::vulkan::RenderMode::bindGraphicDescriptor(reference, pass); return descriptor; } -void ext::vulkan::DeferredRenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::vulkan::DeferredRenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { float width = this->width > 0 ? this->width : ext::vulkan::settings::width; float height = this->height > 0 ? this->height : ext::vulkan::settings::height; @@ -389,7 +389,7 @@ void ext::vulkan::DeferredRenderMode::createCommandBuffers( const std::vector layers = ext::vulkan::getRenderModes(std::vector{"RenderTarget", "Compute"}, false); + uf::stl::vector layers = ext::vulkan::getRenderModes(uf::stl::vector{"RenderTarget", "Compute"}, false); auto& scene = uf::scene::getCurrentScene(); auto& sceneMetadata = scene.getComponent(); auto& commands = getCommands(); @@ -398,7 +398,7 @@ void ext::vulkan::DeferredRenderMode::createCommandBuffers( const std::vector clearValues; + uf::stl::vector clearValues; for ( auto& attachment : renderTarget.attachments ) { VkClearValue clearValue; if ( attachment.descriptor.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ) { @@ -504,7 +504,7 @@ void ext::vulkan::DeferredRenderMode::createCommandBuffers( const std::vector clearValues; clearValues.resize(2); + uf::stl::vector clearValues; clearValues.resize(2); clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } }; clearValues[1].depthStencil = { 1.0f, 0 }; diff --git a/engine/src/ext/vulkan/rendermodes/rendertarget.cpp b/engine/src/ext/vulkan/rendermodes/rendertarget.cpp index 074d01ce..33c0f231 100644 --- a/engine/src/ext/vulkan/rendermodes/rendertarget.cpp +++ b/engine/src/ext/vulkan/rendermodes/rendertarget.cpp @@ -8,12 +8,12 @@ #include #include -const std::string ext::vulkan::RenderTargetRenderMode::getTarget() const { +const uf::stl::string ext::vulkan::RenderTargetRenderMode::getTarget() const { // auto& metadata = *const_cast(&this->metadata); -// return metadata["target"].as(); +// return metadata["target"].as(); return metadata.target; } -void ext::vulkan::RenderTargetRenderMode::setTarget( const std::string& target ) { +void ext::vulkan::RenderTargetRenderMode::setTarget( const uf::stl::string& target ) { // this->metadata["target"] = target; metadata.target = target; } @@ -21,7 +21,7 @@ void ext::vulkan::RenderTargetRenderMode::bindCallback( int32_t subpass, const e commandBufferCallbacks[subpass] = callback; } -const std::string ext::vulkan::RenderTargetRenderMode::getType() const { +const uf::stl::string ext::vulkan::RenderTargetRenderMode::getType() const { return "RenderTarget"; } const size_t ext::vulkan::RenderTargetRenderMode::blitters() const { @@ -30,7 +30,7 @@ const size_t ext::vulkan::RenderTargetRenderMode::blitters() const { ext::vulkan::Graphic* ext::vulkan::RenderTargetRenderMode::getBlitter( size_t i ) { return &this->blitter; } -std::vector ext::vulkan::RenderTargetRenderMode::getBlitters() { +uf::stl::vector ext::vulkan::RenderTargetRenderMode::getBlitters() { return { &this->blitter }; } @@ -66,7 +66,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { renderTarget.views = metadata.subpasses; struct { size_t depth; - } attachments; + } attachments = {}; attachments.depth = renderTarget.attach(RenderTarget::Attachment::Descriptor{ /*.format = */ ext::vulkan::settings::formats::depth, @@ -91,7 +91,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { if ( metadata.type == "depth" || metadata.type == "vxgi" ) { struct { size_t depth; - } attachments; + } attachments = {}; attachments.depth = renderTarget.attach(RenderTarget::Attachment::Descriptor{ /*.format = */ ext::vulkan::settings::formats::depth, @@ -112,7 +112,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { } else if ( metadata.type == "single" ) { struct { size_t albedo, depth; - } attachments; + } attachments = {}; attachments.albedo = renderTarget.attach(RenderTarget::Attachment::Descriptor{ /*.format = */VK_FORMAT_R8G8B8A8_UNORM, @@ -141,7 +141,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { #if 0 struct { size_t albedo, normals, position, depth; - } attachments; + } attachments = {}; attachments.albedo = renderTarget.attach(RenderTarget::Attachment::Descriptor{ /*.format = */ ext::vulkan::settings::formats::color, @@ -196,7 +196,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { #else struct { size_t id, normals, uvs, albedo, depth, output; - } attachments; + } attachments = {}; attachments.id = renderTarget.attach(RenderTarget::Attachment::Descriptor{ /*.format = */VK_FORMAT_R16G16_UINT, @@ -320,23 +320,23 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { if ( ext::json::isArray( metadata.json["shaders"] ) ) { ext::json::forEach( metadata.json["shaders"], [&]( ext::json::Value& value ){ ext::vulkan::enums::Shader::type_t type{}; - std::string filename = ""; - std::string pipeline = ""; + uf::stl::string filename = ""; + uf::stl::string pipeline = ""; - if ( value.is() ) { - filename = value.as(); + if ( value.is() ) { + filename = value.as(); auto split = uf::string::split( filename, "." ); - std::string extension = split.back(); split.pop_back(); - std::string sType = split.back(); + uf::stl::string extension = split.back(); split.pop_back(); + uf::stl::string sType = split.back(); if ( sType == "vert" ) type = ext::vulkan::enums::Shader::VERTEX; else if ( sType == "frag" ) type = ext::vulkan::enums::Shader::FRAGMENT; else if ( sType == "geom" ) type = ext::vulkan::enums::Shader::GEOMETRY; else if ( sType == "comp" ) type = ext::vulkan::enums::Shader::COMPUTE; } else { - filename = value["filename"].as(); - pipeline = value["pipeline"].as(); - std::string sType = value["type"].as(); + filename = value["filename"].as(); + pipeline = value["pipeline"].as(); + uf::stl::string sType = value["type"].as(); if ( sType == "vertex" ) type = ext::vulkan::enums::Shader::VERTEX; else if ( sType == "fragment" ) type = ext::vulkan::enums::Shader::FRAGMENT; @@ -356,15 +356,15 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { blitter.material.attachShader( uf::io::root+filename, type, pipeline ); }); } else if ( ext::json::isObject( metadata.json["shaders"] ) ) { - ext::json::forEach( metadata.json["shaders"], [&]( const std::string& key, ext::json::Value& value ){ + ext::json::forEach( metadata.json["shaders"], [&]( const uf::stl::string& key, ext::json::Value& value ){ ext::vulkan::enums::Shader::type_t type{}; - std::string filename = ""; - std::string pipeline = ""; - if ( value.is() ) { - filename = value.as(); + uf::stl::string filename = ""; + uf::stl::string pipeline = ""; + if ( value.is() ) { + filename = value.as(); } else { - filename = value["filename"].as(); - pipeline = value["pipeline"].as(); + filename = value["filename"].as(); + pipeline = value["pipeline"].as(); } if ( key == "vertex" ) type = ext::vulkan::enums::Shader::VERTEX; else if ( key == "fragment" ) type = ext::vulkan::enums::Shader::FRAGMENT; @@ -386,8 +386,8 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { // do not attach if we're requesting no blitter shaders blitter.process = false; } else { - std::string vertexShaderFilename = uf::io::root+"/shaders/display/renderTarget.vert.spv"; - std::string fragmentShaderFilename = uf::io::root+"/shaders/display/renderTarget.frag.spv"; + uf::stl::string vertexShaderFilename = uf::io::root+"/shaders/display/renderTarget.vert.spv"; + uf::stl::string fragmentShaderFilename = uf::io::root+"/shaders/display/renderTarget.frag.spv"; if ( msaa > 1 ) { fragmentShaderFilename = uf::string::replace( fragmentShaderFilename, "frag", "msaa.frag" ); } @@ -414,7 +414,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTextures2D); else if ( name == "CUBEMAPS" ) sc["value"] = (specializationConstants[i] = maxTexturesCube); else if ( name == "CASCADES" ) sc["value"] = (specializationConstants[i] = maxCascades); @@ -422,7 +422,7 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ size_t binding = t["binding"].as(); - std::string name = t["name"].as(); + uf::stl::string name = t["name"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding != binding ) continue; if ( name == "samplerTextures" ) layout.descriptorCount = maxTextures2D; @@ -434,10 +434,10 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) { } }); - std::vector lights(maxLights); - std::vector materials(maxTextures2D); - std::vector textures(maxTextures2D); - std::vector drawCalls(maxTextures2D); + uf::stl::vector lights(maxLights); + uf::stl::vector materials(maxTextures2D); + uf::stl::vector textures(maxTextures2D); + uf::stl::vector drawCalls(maxTextures2D); for ( auto& material : materials ) material.colorBase = {0,0,0,0}; @@ -628,7 +628,7 @@ void ext::vulkan::RenderTargetRenderMode::pipelineBarrier( VkCommandBuffer comma attachment.descriptor.layout = imageMemoryBarrier.newLayout; } } -void ext::vulkan::RenderTargetRenderMode::createCommandBuffers( const std::vector& graphics ) { +void ext::vulkan::RenderTargetRenderMode::createCommandBuffers( const uf::stl::vector& graphics ) { // destroy if exists float width = this->width > 0 ? this->width : ext::vulkan::settings::width; float height = this->height > 0 ? this->height : ext::vulkan::settings::height; @@ -640,7 +640,7 @@ void ext::vulkan::RenderTargetRenderMode::createCommandBuffers( const std::vecto for (size_t i = 0; i < commands.size(); ++i) { VK_CHECK_RESULT(vkBeginCommandBuffer(commands[i], &cmdBufInfo)); { - std::vector clearValues; + uf::stl::vector clearValues; for ( size_t j = 0; j < renderTarget.views; ++j ) { for ( auto& attachment : renderTarget.attachments ) { VkClearValue clearValue; diff --git a/engine/src/ext/vulkan/rendertarget.cpp b/engine/src/ext/vulkan/rendertarget.cpp index d11c1c6a..eaa2d03f 100644 --- a/engine/src/ext/vulkan/rendertarget.cpp +++ b/engine/src/ext/vulkan/rendertarget.cpp @@ -5,7 +5,7 @@ #include #include -void ext::vulkan::RenderTarget::addPass( VkPipelineStageFlags stage, VkAccessFlags access, const std::vector& colors, const std::vector& inputs, const std::vector& resolves, size_t depth, size_t layer, bool autoBuildPipeline ) { +void ext::vulkan::RenderTarget::addPass( VkPipelineStageFlags stage, VkAccessFlags access, const uf::stl::vector& colors, const uf::stl::vector& inputs, const uf::stl::vector& resolves, size_t depth, size_t layer, bool autoBuildPipeline ) { Subpass pass; pass.stage = stage; pass.access = access; @@ -166,7 +166,7 @@ void ext::vulkan::RenderTarget::initialize( Device& device ) { // Create render pass if ( !renderPass ) { - std::vector attachments; attachments.reserve( this->attachments.size() ); + uf::stl::vector attachments; attachments.reserve( this->attachments.size() ); for ( size_t i = 0; i < this->views; ++i ) { for ( auto& attachment : this->attachments ) { VkAttachmentDescription description; @@ -197,8 +197,8 @@ void ext::vulkan::RenderTarget::initialize( Device& device ) { pass.depth.attachment += pass.layer * this->attachments.size(); } - std::vector descriptions; - std::vector dependencies; + uf::stl::vector descriptions; + uf::stl::vector dependencies; // dependency: transition from final VkSubpassDependency dependency; @@ -307,7 +307,7 @@ void ext::vulkan::RenderTarget::initialize( Device& device ) { /* uint32_t mask = 0; - std::vector masks; + uf::stl::vector masks; for ( size_t i = 0; i < this->views; ++i ) { mask |= (0b00000001 << i); } @@ -336,7 +336,7 @@ void ext::vulkan::RenderTarget::initialize( Device& device ) { RenderMode& base = ext::vulkan::getRenderMode( "Swapchain", false ); framebuffers.resize(ext::vulkan::swapchain.buffers); for ( size_t i = 0; i < framebuffers.size(); ++i ) { - std::vector attachmentViews; + uf::stl::vector attachmentViews; for ( size_t j = 0; j < this->views; ++j ) { for ( auto& attachment : this->attachments ) { if ( attachment.descriptor.aliased && attachment.descriptor.layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ) { diff --git a/engine/src/ext/vulkan/shader.cpp b/engine/src/ext/vulkan/shader.cpp index e1d5817d..26894ebb 100644 --- a/engine/src/ext/vulkan/shader.cpp +++ b/engine/src/ext/vulkan/shader.cpp @@ -20,7 +20,7 @@ ext::json::Value ext::vulkan::definitionToJson(/*const*/ ext::json::Value& defin // is object if ( !ext::json::isNull(definition["members"]) ) { ext::json::forEach(definition["members"], [&](/*const*/ ext::json::Value& value){ - std::string key = uf::string::split(value["name"].as(), " ").back(); + uf::stl::string key = uf::string::split(value["name"].as(), " ").back(); member[key] = ext::vulkan::definitionToJson(value); }); // is primitive @@ -56,13 +56,13 @@ ext::vulkan::userdata_t ext::vulkan::jsonToUserdata( const ext::json::Value& pay // JSON is ordered, we can just push directly #define UF_SHADER_TRACK_NAMES 0 #if UF_SHADER_TRACK_NAMES - std::vector variableName; + uf::stl::vector variableName; #endif std::function parse = [&]( const ext::json::Value& value ){ // is array or object #if UF_SHADER_TRACK_NAMES if ( ext::json::isObject(value) ) { - ext::json::forEach(value, [&]( const std::string& name, const ext::json::Value& member ){ + ext::json::forEach(value, [&]( const uf::stl::string& name, const ext::json::Value& member ){ #if UF_SHADER_TRACK_NAMES variableName.emplace_back(name); #endif @@ -90,7 +90,7 @@ ext::vulkan::userdata_t ext::vulkan::jsonToUserdata( const ext::json::Value& pay } #endif #if UF_SHADER_TRACK_NAMES - std::string path = uf::string::join(variableName, "."); + uf::stl::string path = uf::string::join(variableName, "."); path = uf::string::replace( path, ".[", "[" ); VK_VALIDATION_MESSAGE("[" << (byteBuffer - byteBufferStart) << " / "<< (byteBufferEnd - byteBuffer) <<"]\tInserting: " << path << " = " << value.dump()); #endif @@ -126,7 +126,7 @@ ext::vulkan::userdata_t ext::vulkan::jsonToUserdata( const ext::json::Value& pay VK_VALIDATION_MESSAGE("Iterator: " << (void*) byteBuffer << "\t" << (void*) byteBufferEnd << "\t" << (byteBufferEnd - byteBuffer)); #endif #else - auto pushValue = [&]( const std::string& primitive, const ext::json::Value& input ){ + auto pushValue = [&]( const uf::stl::string& primitive, const ext::json::Value& input ){ if ( primitive == "bool" ) { size_t size = sizeof(bool); // v["size"].as(); if ( byteBufferEnd < byteBuffer + size ) return false; // overflow @@ -207,40 +207,40 @@ ext::vulkan::userdata_t ext::vulkan::jsonToUserdata( const ext::json::Value& pay #define UF_SHADER_TRACK_NAMES 0 #if UF_SHADER_TRACK_NAMES bool SKIP_ADD = false; - std::vector variableName; + uf::stl::vector variableName; #endif std::function parseDefinition = [&](const ext::json::Value& input, const ext::json::Value& definition ){ #if UF_SHADER_TRACK_NAMES if ( SKIP_ADD ) { SKIP_ADD = false; } else { - auto split = uf::string::split(definition["name"].as(), " "); - std::string type = split.front(); - std::string name = split.back(); + auto split = uf::string::split(definition["name"].as(), " "); + uf::stl::string type = split.front(); + uf::stl::string name = split.back(); variableName.emplace_back(name); } #endif // is object if ( !ext::json::isNull(definition["members"]) ) { ext::json::forEach(definition["members"], [&](const ext::json::Value& member){ - std::string key = uf::string::split(member["name"].as(), " ").back(); + uf::stl::string key = uf::string::split(member["name"].as(), " ").back(); parseDefinition(input[key], member); }); // is array or primitive } else if ( !ext::json::isNull(definition["value"]) ) { // is object - auto split = uf::string::split(definition["name"].as(), " "); - std::string type = split.front(); - std::string name = split.back(); + auto split = uf::string::split(definition["name"].as(), " "); + uf::stl::string type = split.front(); + uf::stl::string name = split.back(); std::regex regex("^(?:(.+?)\\<)?(.+?)(?:\\>)?(?:\\[(\\d+)\\])?$"); std::smatch match; if ( !std::regex_search( type, match, regex ) ) { - std::cout << "Ill formatted typename: " << definition["name"].as() << std::endl; + std::cout << "Ill formatted typename: " << definition["name"].as() << std::endl; return; } - std::string vectorMatrix = match[1].str(); - std::string primitive = match[2].str(); - std::string arraySize = match[3].str(); + uf::stl::string vectorMatrix = match[1].str(); + uf::stl::string primitive = match[2].str(); + uf::stl::string arraySize = match[3].str(); if ( ext::json::isObject(input) ) { ext::json::Value cloned; cloned["name"] = definition["name"]; @@ -261,7 +261,7 @@ ext::vulkan::userdata_t ext::vulkan::jsonToUserdata( const ext::json::Value& pay // is primitive else { #if UF_SHADER_TRACK_NAMES - std::string path = uf::string::join(variableName, "."); + uf::stl::string path = uf::string::join(variableName, "."); path = uf::string::replace( path, ".[", "[" ); VK_VALIDATION_MESSAGE("[" << (byteBuffer - byteBufferStart) << " / "<< (byteBufferEnd - byteBuffer) <<"]\tInserting: " << path << " = (" << primitive << ") " << input.dump()); #endif @@ -285,11 +285,11 @@ ext::vulkan::userdata_t ext::vulkan::jsonToUserdata( const ext::json::Value& pay return userdata; } -void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::string& filename, VkShaderStageFlagBits stage ) { +void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const uf::stl::string& filename, VkShaderStageFlagBits stage ) { this->device = &device; ext::vulkan::Buffers::initialize( device ); - std::string spirv; + uf::stl::string spirv; { std::ifstream is(this->filename = filename, std::ios::binary | std::ios::in | std::ios::ate); @@ -337,7 +337,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st auto type = comp.get_type(type_id); - std::string name = ""; + uf::stl::string name = ""; size_t size = 1; ext::json::Value value; switch ( type.basetype ) { @@ -404,13 +404,13 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st const auto& type = comp.get_type(type_id); for ( auto& member_type_id : type.member_types ) { const auto& member_type = comp.get_type(member_type_id); - std::string name = comp.get_member_name(type.type_alias, payload.size()); + uf::stl::string name = comp.get_member_name(type.type_alias, payload.size()); if ( name == "" ) name = comp.get_member_name(type.parent_type, payload.size()); if ( name == "" ) name = comp.get_member_name(type_id, payload.size()); auto& entry = payload.emplace_back(); auto parsed = parseMember(member_type_id); - std::string type_name = parsed["name"]; + uf::stl::string type_name = parsed["name"]; entry["name"] = type_name + " " + name; if ( member_type.basetype == spirv_cross::SPIRType::BaseType::Struct ) { entry["struct"] = true; @@ -443,7 +443,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st const auto& type = comp.get_type(resource.type_id); const auto& base_type = comp.get_type(resource.base_type_id); const size_t binding = comp.get_decoration(resource.id, spv::DecorationBinding); - const std::string name = resource.name; + const uf::stl::string name = resource.name; size_t arraySize = 1; if ( !type.array.empty() ) { arraySize = type.array[0]; @@ -453,7 +453,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { - std::string tname = ""; + uf::stl::string tname = ""; ext::vulkan::enums::Image::viewType_t etype{}; switch ( type.image.dim ) { case spv::Dim::Dim1D: tname = "1D"; etype = ext::vulkan::enums::Image::VIEW_TYPE_1D; break; @@ -464,7 +464,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st case spv::Dim::DimBuffer: tname = "Buffer"; break; case spv::Dim::DimSubpassData: tname = "SubpassData"; break; } - std::string key = std::to_string(binding); + uf::stl::string key = std::to_string(binding); metadata.json["definitions"]["textures"][key]["name"] = name; metadata.json["definitions"]["textures"][key]["index"] = index; metadata.json["definitions"]["textures"][key]["binding"] = binding; @@ -548,7 +548,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st { uniforms.reserve( metadata.definitions.uniforms.size() ); - std::vector sizes( metadata.definitions.uniforms.size() ); + uf::stl::vector sizes( metadata.definitions.uniforms.size() ); for ( auto pair : metadata.definitions.uniforms ) { sizes[pair.second.index] = pair.second.size; } @@ -562,7 +562,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st const auto& type = comp.get_type(resource.type_id); const auto& base_type = comp.get_type(resource.base_type_id); const size_t binding = comp.get_decoration(resource.id, spv::DecorationBinding); - const std::string name = resource.name; + const uf::stl::string name = resource.name; size_t size = comp.get_declared_struct_size(type); if ( size <= 0 ) continue; // not a multiple of 4, for some reason @@ -624,7 +624,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st for ( const auto& constant : comp.get_specialization_constants() ) { const auto& value = comp.get_constant(constant.id); const auto& type = comp.get_type(value.constant_type); - std::string name = comp.get_name (constant.id); + uf::stl::string name = comp.get_name (constant.id); ext::json::Value member; @@ -663,7 +663,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st member["name"] = name; member["size"] = size; member["default"] = member["value"]; - VK_DEBUG_VALIDATION_MESSAGE("Specialization constant: " << member["type"].as() << " " << name << " = " << member["value"].dump() << "; at offset " << offset << " for shader " << filename ); + VK_DEBUG_VALIDATION_MESSAGE("Specialization constant: " << member["type"].as() << " " << name << " = " << member["value"].dump() << "; at offset " << offset << " for shader " << filename ); metadata.json["specializationConstants"].emplace_back(member); memcpy( &s[offset], &buffer, size ); @@ -738,11 +738,11 @@ bool ext::vulkan::Shader::validate() { } return valid; } -bool ext::vulkan::Shader::hasUniform( const std::string& name ) { +bool ext::vulkan::Shader::hasUniform( const uf::stl::string& name ) { // return !ext::json::isNull(metadata.json["definitions"]["uniforms"][name]); return metadata.definitions.uniforms.count(name) > 0; } -ext::vulkan::Buffer* ext::vulkan::Shader::getUniformBuffer( const std::string& name ) { +ext::vulkan::Buffer* ext::vulkan::Shader::getUniformBuffer( const uf::stl::string& name ) { if ( !hasUniform(name) ) return NULL; // size_t uniformIndex = metadata.json["definitions"]["uniforms"][name]["index"].as(); size_t uniformIndex = metadata.definitions.uniforms[name].index; @@ -753,7 +753,7 @@ ext::vulkan::Buffer* ext::vulkan::Shader::getUniformBuffer( const std::string& n } return NULL; } -ext::vulkan::userdata_t& ext::vulkan::Shader::getUniform( const std::string& name ) { +ext::vulkan::userdata_t& ext::vulkan::Shader::getUniform( const uf::stl::string& name ) { UF_ASSERT( hasUniform(name) ); return uniforms[metadata.definitions.uniforms[name].index]; /* @@ -764,12 +764,12 @@ ext::vulkan::userdata_t& ext::vulkan::Shader::getUniform( const std::string& nam return userdata; */ } -bool ext::vulkan::Shader::updateUniform( const std::string& name ) { +bool ext::vulkan::Shader::updateUniform( const uf::stl::string& name ) { if ( !hasUniform(name) ) return false; auto& uniform = getUniform(name); return updateUniform(name, uniform); } -bool ext::vulkan::Shader::updateUniform( const std::string& name, const ext::vulkan::userdata_t& userdata ) { +bool ext::vulkan::Shader::updateUniform( const uf::stl::string& name, const ext::vulkan::userdata_t& userdata ) { if ( !hasUniform(name) ) return false; auto* bufferObject = getUniformBuffer(name); if ( !bufferObject ) return false; @@ -779,18 +779,18 @@ bool ext::vulkan::Shader::updateUniform( const std::string& name, const ext::vul return true; } -uf::Serializer ext::vulkan::Shader::getUniformJson( const std::string& name, bool cache ) { +uf::Serializer ext::vulkan::Shader::getUniformJson( const uf::stl::string& name, bool cache ) { if ( !hasUniform(name) ) return ext::json::null(); if ( cache && !ext::json::isNull(metadata.json["uniforms"][name]) ) return metadata.json["uniforms"][name]; auto& definition = metadata.json["definitions"]["uniforms"][name]; if ( cache ) return metadata.json["uniforms"][name] = definitionToJson(definition); return definitionToJson(definition); } -ext::vulkan::userdata_t ext::vulkan::Shader::getUniformUserdata( const std::string& name, const ext::json::Value& payload ) { +ext::vulkan::userdata_t ext::vulkan::Shader::getUniformUserdata( const uf::stl::string& name, const ext::json::Value& payload ) { UF_ASSERT( hasUniform(name) ); return jsonToUserdata(payload, metadata.json["definitions"]["uniforms"][name]); } -bool ext::vulkan::Shader::updateUniform( const std::string& name, const ext::json::Value& payload ) { +bool ext::vulkan::Shader::updateUniform( const uf::stl::string& name, const ext::json::Value& payload ) { if ( !hasUniform(name) ) return false; auto* bufferObject = getUniformBuffer(name); @@ -801,12 +801,12 @@ bool ext::vulkan::Shader::updateUniform( const std::string& name, const ext::jso return true; } -bool ext::vulkan::Shader::hasStorage( const std::string& name ) { +bool ext::vulkan::Shader::hasStorage( const uf::stl::string& name ) { // return !ext::json::isNull(metadata.json["definitions"]["storage"][name]); return metadata.definitions.storage.count(name) > 0; } -ext::vulkan::Buffer* ext::vulkan::Shader::getStorageBuffer( const std::string& name ) { +ext::vulkan::Buffer* ext::vulkan::Shader::getStorageBuffer( const uf::stl::string& name ) { if ( !hasStorage(name) ) return NULL; // size_t storageIndex = metadata.json["definitions"]["storage"][name]["index"].as(); size_t storageIndex = metadata.definitions.storage[name].index; @@ -817,14 +817,14 @@ ext::vulkan::Buffer* ext::vulkan::Shader::getStorageBuffer( const std::string& n } return NULL; } -uf::Serializer ext::vulkan::Shader::getStorageJson( const std::string& name, bool cache ) { +uf::Serializer ext::vulkan::Shader::getStorageJson( const uf::stl::string& name, bool cache ) { if ( !hasStorage(name) ) return ext::json::null(); if ( cache && !ext::json::isNull(metadata.json["storage"][name]) ) return metadata.json["storage"][name]; auto& definition = metadata.json["definitions"]["storage"][name]; if ( cache ) return metadata.json["storage"][name] = definitionToJson(definition); return definitionToJson(definition); } -ext::vulkan::userdata_t ext::vulkan::Shader::getStorageUserdata( const std::string& name, const ext::json::Value& payload ) { +ext::vulkan::userdata_t ext::vulkan::Shader::getStorageUserdata( const uf::stl::string& name, const ext::json::Value& payload ) { if ( !hasStorage(name) ) return false; return jsonToUserdata(payload, metadata.json["definitions"]["storage"][name]); } diff --git a/engine/src/ext/vulkan/swapchain.cpp b/engine/src/ext/vulkan/swapchain.cpp index 897f6b22..1a418dc2 100644 --- a/engine/src/ext/vulkan/swapchain.cpp +++ b/engine/src/ext/vulkan/swapchain.cpp @@ -41,7 +41,7 @@ void ext::vulkan::Swapchain::initialize( Device& device ) { VK_CHECK_RESULT(vkGetPhysicalDeviceSurfacePresentModesKHR(device.physicalDevice, device.surface, &presentModeCount, NULL)); assert(presentModeCount > 0); - std::vector presentModes(presentModeCount); + uf::stl::vector presentModes(presentModeCount); VK_CHECK_RESULT(vkGetPhysicalDeviceSurfacePresentModesKHR(device.physicalDevice, device.surface, &presentModeCount, presentModes.data())); #if 1 if ( settings::experimental::vsync ) { @@ -125,7 +125,7 @@ void ext::vulkan::Swapchain::initialize( Device& device ) { // Find a supported composite alpha format (not all devices support alpha opaque) VkCompositeAlphaFlagBitsKHR compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; // Simply select the first composite alpha format available - std::vector compositeAlphaFlags = { + uf::stl::vector compositeAlphaFlags = { VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR, VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR, diff --git a/engine/src/ext/vulkan/texture.cpp b/engine/src/ext/vulkan/texture.cpp index 6bd11c61..16f74598 100644 --- a/engine/src/ext/vulkan/texture.cpp +++ b/engine/src/ext/vulkan/texture.cpp @@ -9,7 +9,7 @@ ext::vulkan::Texture2D ext::vulkan::Texture2D::empty; ext::vulkan::Texture3D ext::vulkan::Texture3D::empty; ext::vulkan::TextureCube ext::vulkan::TextureCube::empty; -std::vector ext::vulkan::Sampler::samplers; +uf::stl::vector ext::vulkan::Sampler::samplers; ext::vulkan::Sampler ext::vulkan::Sampler::retrieve( const ext::vulkan::Sampler::Descriptor& info ) { ext::vulkan::Sampler sampler; @@ -280,7 +280,7 @@ void ext::vulkan::Texture::setImageLayout( setImageLayout(cmdbuffer, image, oldImageLayout, newImageLayout, subresourceRange); } void ext::vulkan::Texture::loadFromFile( - const std::string& filename, + const uf::stl::string& filename, VkFormat format, VkImageUsageFlags imageUsageFlags, VkImageLayout imageLayout @@ -288,7 +288,7 @@ void ext::vulkan::Texture::loadFromFile( return loadFromFile( filename, ext::vulkan::device, format, imageUsageFlags, imageLayout ); } void ext::vulkan::Texture::loadFromFile( - const std::string& filename, + const uf::stl::string& filename, Device& device, VkFormat format, VkImageUsageFlags imageUsageFlags, @@ -321,7 +321,7 @@ void ext::vulkan::Texture::loadFromImage( format = VK_FORMAT_R8_UNORM; break; default: - UF_EXCEPTION("Vulkan error: unsupported BPP of " + image.getBpp() ); + UF_EXCEPTION("Vulkan error: unsupported BPP of " << image.getBpp() ); break; } break; @@ -332,7 +332,7 @@ void ext::vulkan::Texture::loadFromImage( format = VK_FORMAT_R8G8B8_UNORM; break; default: - UF_EXCEPTION("Vulkan error: unsupported BPP of " + image.getBpp() ); + UF_EXCEPTION("Vulkan error: unsupported BPP of " << image.getBpp() ); break; } break; @@ -343,12 +343,12 @@ void ext::vulkan::Texture::loadFromImage( format = VK_FORMAT_R8G8B8A8_UNORM; break; default: - UF_EXCEPTION("Vulkan error: unsupported BPP of " + image.getBpp() ); + UF_EXCEPTION("Vulkan error: unsupported BPP of " << image.getBpp() ); break; } break; default: - UF_EXCEPTION("Vulkan error: unsupported channels of " + image.getChannels() ); + UF_EXCEPTION("Vulkan error: unsupported channels of " << image.getChannels() ); break; } diff --git a/engine/src/ext/vulkan/vulkan.cpp b/engine/src/ext/vulkan/vulkan.cpp index 10a53bce..edc19c7e 100644 --- a/engine/src/ext/vulkan/vulkan.cpp +++ b/engine/src/ext/vulkan/vulkan.cpp @@ -19,10 +19,10 @@ bool ext::vulkan::settings::validation = true; // constexpr size_t ext::vulkan::settings::maxViews = 6; size_t ext::vulkan::settings::viewCount = 2; -std::vector ext::vulkan::settings::validationFilters; -std::vector ext::vulkan::settings::requestedDeviceFeatures; -std::vector ext::vulkan::settings::requestedDeviceExtensions; -std::vector ext::vulkan::settings::requestedInstanceExtensions; +uf::stl::vector ext::vulkan::settings::validationFilters; +uf::stl::vector ext::vulkan::settings::requestedDeviceFeatures; +uf::stl::vector ext::vulkan::settings::requestedDeviceExtensions; +uf::stl::vector ext::vulkan::settings::requestedInstanceExtensions; VkFilter ext::vulkan::settings::swapchainUpscaleFilter = VK_FILTER_LINEAR; @@ -31,7 +31,7 @@ bool ext::vulkan::settings::experimental::waitOnRenderEnd = false; bool ext::vulkan::settings::experimental::individualPipelines = true; bool ext::vulkan::settings::experimental::multithreadedCommandRecording = true; bool ext::vulkan::settings::experimental::multithreadedCommandRendering = false; -std::string ext::vulkan::settings::experimental::deferredMode = ""; +uf::stl::string ext::vulkan::settings::experimental::deferredMode = ""; bool ext::vulkan::settings::experimental::deferredReconstructPosition = false; bool ext::vulkan::settings::experimental::deferredAliasOutputToSwapchain = true; bool ext::vulkan::settings::experimental::multiview = true; @@ -56,12 +56,12 @@ bool ext::vulkan::states::resized = false; bool ext::vulkan::states::rebuild = false; uint32_t ext::vulkan::states::currentBuffer = 0; -std::vector ext::vulkan::scenes; +uf::stl::vector ext::vulkan::scenes; ext::vulkan::RenderMode* ext::vulkan::currentRenderMode = NULL; -std::vector ext::vulkan::renderModes = { +uf::stl::vector ext::vulkan::renderModes = { new ext::vulkan::BaseRenderMode, }; -std::unordered_map ext::vulkan::renderModesMap; +uf::stl::unordered_map ext::vulkan::renderModesMap; VkResult ext::vulkan::CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) { auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"); @@ -81,15 +81,15 @@ VKAPI_ATTR VkBool32 VKAPI_CALL ext::vulkan::debugCallback( void* pUserData ) { // if ( messageSeverity <= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT ) return VK_FALSE; - std::string message = pCallbackData->pMessage; + uf::stl::string message = pCallbackData->pMessage; for ( auto& filter : ext::vulkan::settings::validationFilters ) { - if ( message.find(filter) != std::string::npos ) return VK_FALSE; + if ( message.find(filter) != uf::stl::string::npos ) return VK_FALSE; } UF_MSG_ERROR("[Validation Layer] " << message); return VK_FALSE; } -std::string ext::vulkan::errorString( VkResult result ) { +uf::stl::string ext::vulkan::errorString( VkResult result ) { switch ( result ) { #define STR(r) case VK_ ##r: return #r STR(NOT_READY); @@ -152,7 +152,7 @@ void ext::vulkan::alignedFree(void* data) { #endif } -bool ext::vulkan::hasRenderMode( const std::string& name, bool isName ) { +bool ext::vulkan::hasRenderMode( const uf::stl::string& name, bool isName ) { if ( isName && ext::vulkan::renderModesMap.count(name) > 0 ) return true; for ( auto& renderMode: ext::vulkan::renderModes ) { if ( isName && renderMode->getName() == name ) return true; @@ -161,7 +161,7 @@ bool ext::vulkan::hasRenderMode( const std::string& name, bool isName ) { return false; } -ext::vulkan::RenderMode& ext::vulkan::addRenderMode( ext::vulkan::RenderMode* mode, const std::string& name ) { +ext::vulkan::RenderMode& ext::vulkan::addRenderMode( ext::vulkan::RenderMode* mode, const uf::stl::string& name ) { mode->metadata.name = name; renderModesMap[name] = renderModes.emplace_back(mode); VK_VALIDATION_MESSAGE("Adding RenderMode: " << name << ": " << mode->getType()); @@ -169,7 +169,7 @@ ext::vulkan::RenderMode& ext::vulkan::addRenderMode( ext::vulkan::RenderMode* mo ext::vulkan::states::rebuild = true; return *mode; } -ext::vulkan::RenderMode& ext::vulkan::getRenderMode( const std::string& name, bool isName ) { +ext::vulkan::RenderMode& ext::vulkan::getRenderMode( const uf::stl::string& name, bool isName ) { if ( isName && renderModesMap.count(name) > 0 ) return *renderModesMap[name]; RenderMode* target = renderModes[0]; for ( auto& renderMode: renderModes ) { @@ -189,12 +189,12 @@ ext::vulkan::RenderMode& ext::vulkan::getRenderMode( const std::string& name, bo // VK_VALIDATION_MESSAGE("Requesting RenderMode `" << name << "`, got `" << target->getName() << "` (" << target->getType() << ")"); return *target; } -std::vector ext::vulkan::getRenderModes( const std::string& name, bool isName ) { +uf::stl::vector ext::vulkan::getRenderModes( const uf::stl::string& name, bool isName ) { if ( isName && renderModesMap.count(name) > 0 ) return { renderModesMap[name] }; return ext::vulkan::getRenderModes({name}, isName); } -std::vector ext::vulkan::getRenderModes( const std::vector& names, bool isName ) { - std::vector targets; +uf::stl::vector ext::vulkan::getRenderModes( const uf::stl::vector& names, bool isName ) { + uf::stl::vector targets; for ( auto& renderMode: renderModes ) { if ( ( isName && std::find(names.begin(), names.end(), renderMode->getName()) != names.end() ) || std::find(names.begin(), names.end(), renderMode->getType()) != names.end() ) { targets.push_back(renderMode); @@ -204,7 +204,7 @@ std::vector ext::vulkan::getRenderModes( const std::ve } void ext::vulkan::removeRenderMode( ext::vulkan::RenderMode* mode, bool free ) { if ( !mode ) return; - std::string name = mode->getName(); + uf::stl::string name = mode->getName(); renderModes.erase( std::remove( renderModes.begin(), renderModes.end(), mode ), renderModes.end() ); renderModesMap.erase( name ); mode->destroy(); @@ -216,7 +216,7 @@ void ext::vulkan::initialize() { device.initialize(); swapchain.initialize( device ); { - std::vector pixels = { + uf::stl::vector pixels = { 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, }; @@ -225,7 +225,7 @@ void ext::vulkan::initialize() { Texture2D::empty.fromBuffers( (void*) &pixels[0], pixels.size(), ext::vulkan::enums::Format::R8G8B8A8_UNORM, 2, 2, ext::vulkan::device, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); } { - std::vector pixels = { + uf::stl::vector pixels = { 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, @@ -237,7 +237,7 @@ void ext::vulkan::initialize() { Texture3D::empty.fromBuffers( (void*) &pixels[0], pixels.size(), ext::vulkan::enums::Format::R8G8B8A8_UNORM, 2, 2, 2, 1, ext::vulkan::device, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_LAYOUT_GENERAL ); } { - std::vector pixels = { + uf::stl::vector pixels = { 255, 0, 255, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 255, @@ -264,7 +264,7 @@ void ext::vulkan::initialize() { if ( !renderMode ) continue; renderMode->initialize(device); } - std::vector> jobs; + uf::stl::vector> jobs; for ( auto& renderMode : renderModes ) { if ( !renderMode ) continue; if ( settings::experimental::individualPipelines ) renderMode->bindPipelines(); @@ -304,7 +304,7 @@ void ext::vulkan::tick() { renderMode->tick(); } - std::vector> jobs; + uf::stl::vector> jobs; for ( auto& renderMode : renderModes ) { if ( !renderMode ) continue; if ( ext::vulkan::states::rebuild || renderMode->rebuild ) { @@ -345,7 +345,7 @@ void ext::vulkan::render() { } #if 1 - std::vector> jobs; + uf::stl::vector> jobs; for ( auto& renderMode : renderModes ) { if ( !renderMode || !renderMode->execute ) continue; ext::vulkan::currentRenderMode = renderMode; @@ -431,16 +431,16 @@ void ext::vulkan::synchronize( uint8_t flag ) { vkDeviceWaitIdle( device ); } -std::string ext::vulkan::allocatorStats() { +uf::stl::string ext::vulkan::allocatorStats() { char* statsString = nullptr; vmaBuildStatsString(ext::vulkan::allocator, &statsString, true); - std::string result = statsString; + uf::stl::string result = statsString; vmaFreeStatsString(ext::vulkan::allocator, statsString); return result; } -ext::vulkan::enums::Format::type_t ext::vulkan::formatFromString( const std::string& string ) { - std::unordered_map table = { +ext::vulkan::enums::Format::type_t ext::vulkan::formatFromString( const uf::stl::string& string ) { + uf::stl::unordered_map table = { { "UNDEFINED", ext::vulkan::enums::Format::UNDEFINED }, { "R4G4_UNORM_PACK8", ext::vulkan::enums::Format::R4G4_UNORM_PACK8 }, { "R4G4B4A4_UNORM_PACK16", ext::vulkan::enums::Format::R4G4B4A4_UNORM_PACK16 }, diff --git a/engine/src/ext/zlib/zlib.cpp b/engine/src/ext/zlib/zlib.cpp index b25d44e8..34f30b83 100644 --- a/engine/src/ext/zlib/zlib.cpp +++ b/engine/src/ext/zlib/zlib.cpp @@ -5,8 +5,8 @@ size_t ext::zlib::bufferSize = 2048; /* -std::vector UF_API ext::zlib::compress( const void* data, size_t size ) { - std::vector buffer; +uf::stl::vector UF_API ext::zlib::compress( const void* data, size_t size ) { + uf::stl::vector buffer; // zlib struct z_stream defstream; @@ -26,14 +26,14 @@ std::vector UF_API ext::zlib::compress( const void* data, size_t size ) return buffer; } -std::vector UF_API ext::zlib::decompress( const void* data, size_t size ) { - std::vector buffer; +uf::stl::vector UF_API ext::zlib::decompress( const void* data, size_t size ) { + uf::stl::vector buffer; return buffer; } */ -std::vector UF_API ext::zlib::decompressFromFile( const std::string& filename ) { - std::vector buffer; +uf::stl::vector UF_API ext::zlib::decompressFromFile( const uf::stl::string& filename ) { + uf::stl::vector buffer; gzFile in = gzopen( filename.c_str(), "rb" ); if ( !in ) { @@ -53,7 +53,7 @@ std::vector UF_API ext::zlib::decompressFromFile( const std::string& fi gzclose( in ); return buffer; } -size_t UF_API ext::zlib::compressToFile( const std::string& filename, const void* data, size_t size ) { +size_t UF_API ext::zlib::compressToFile( const uf::stl::string& filename, const void* data, size_t size ) { gzFile out = gzopen( filename.c_str(), "wb" ); if ( !out ) { UF_MSG_ERROR("Zlib: failed to open file for write: " << filename); diff --git a/engine/src/spec/controller/dreamcast.cpp b/engine/src/spec/controller/dreamcast.cpp index 4ce523c5..3d353276 100644 --- a/engine/src/spec/controller/dreamcast.cpp +++ b/engine/src/spec/controller/dreamcast.cpp @@ -11,7 +11,7 @@ namespace { cont_state_t* state = NULL; } controller; - std::string GetKeyName( uint32_t code ) { + uf::stl::string GetKeyName( uint32_t code ) { switch ( code ) { case CONT_C: return "C"; case CONT_B: return "B"; @@ -32,8 +32,8 @@ namespace { } return ""; } - uint32_t GetKeyCode( const std::string& _name ) { - std::string name = uf::string::uppercase( _name ); + uint32_t GetKeyCode( const uf::stl::string& _name ) { + uf::stl::string name = uf::string::uppercase( _name ); if ( name == "C" ) return CONT_C; else if ( name == "B" ) return CONT_B; else if ( name == "A" ) return CONT_A; @@ -65,7 +65,7 @@ void spec::dreamcast::controller::tick() { if ( !::controller.device ) ::controller.device = maple_enum_type(0, MAPLE_FUNC_CONTROLLER); if ( ::controller.device ) ::controller.state = (cont_state_t*) maple_dev_status(::controller.device); #if 0 - std::vector str; + uf::stl::vector str; pod::Vector2f joystick = { analog("L_JOYSTICK_X"), analog("L_JOYSTICK_Y") }; if ( joystick ) str.emplace_back("Joystick: " + uf::vector::toString(joystick)); if ( pressed("C") ) str.emplace_back("C"); @@ -92,11 +92,11 @@ void spec::dreamcast::controller::terminate() { bool spec::dreamcast::controller::connected( size_t i ) { return ::controller.state; } -bool spec::dreamcast::controller::pressed( const std::string& str, size_t i ) { +bool spec::dreamcast::controller::pressed( const uf::stl::string& str, size_t i ) { if ( !::controller.state ) return false; return ::controller.state->buttons & GetKeyCode( str ); } -float spec::dreamcast::controller::analog( const std::string& str, size_t i ) { +float spec::dreamcast::controller::analog( const uf::stl::string& str, size_t i ) { #define NORMALIZE(X) ((float) (X) / (float) std::numeric_limits::max()) if ( !::controller.state ) return false; diff --git a/engine/src/spec/controller/universal.cpp b/engine/src/spec/controller/universal.cpp index fcfc27ee..a8810309 100644 --- a/engine/src/spec/controller/universal.cpp +++ b/engine/src/spec/controller/universal.cpp @@ -4,5 +4,5 @@ void spec::uni::controller::initialize() {} void spec::uni::controller::tick() {} void spec::uni::controller::terminate() {} bool spec::uni::controller::connected( size_t ) { return false; } -bool spec::uni::controller::pressed( const std::string&, size_t ) { return false; } -float spec::uni::controller::analog( const std::string&, size_t ) { return 0; } \ No newline at end of file +bool spec::uni::controller::pressed( const uf::stl::string&, size_t ) { return false; } +float spec::uni::controller::analog( const uf::stl::string&, size_t ) { return 0; } \ No newline at end of file diff --git a/engine/src/spec/controller/windows.cpp b/engine/src/spec/controller/windows.cpp index 4cdc578a..0f60de81 100644 --- a/engine/src/spec/controller/windows.cpp +++ b/engine/src/spec/controller/windows.cpp @@ -15,11 +15,11 @@ bool spec::win32::controller::connected( size_t i ) { #endif return false; } -bool spec::win32::controller::pressed( const std::string& _name, size_t i ) { - std::string name = uf::string::uppercase(_name); +bool spec::win32::controller::pressed( const uf::stl::string& _name, size_t i ) { + uf::stl::string name = uf::string::uppercase(_name); #if UF_USE_OPENVR if ( ext::openvr::context ) { - std::string key = ""; + uf::stl::string key = ""; if ( name == "R_DPAD_UP" ) { i = vr::Controller_Hand::Hand_Right; key = "dpadUp"; } else if ( name == "R_DPAD_DOWN" ) { i = vr::Controller_Hand::Hand_Right; key = "dpadDown"; } else if ( name == "R_DPAD_LEFT" ) { i = vr::Controller_Hand::Hand_Right; key = "dpadLeft"; } @@ -55,12 +55,12 @@ bool spec::win32::controller::pressed( const std::string& _name, size_t i ) { #endif return false; } -float spec::win32::controller::analog( const std::string& _name, size_t i ) { - std::string name = uf::string::uppercase(_name); +float spec::win32::controller::analog( const uf::stl::string& _name, size_t i ) { + uf::stl::string name = uf::string::uppercase(_name); #if UF_USE_OPENVR if ( ext::openvr::context ) { size_t offset = 0; - std::string key = ""; + uf::stl::string key = ""; if ( name == "R_JOYSTICK_X" ) { i = vr::Controller_Hand::Hand_Right; key = "thumbstick"; offset = 0; } else if ( name == "JOYSTICK_X" && i == vr::Controller_Hand::Hand_Right ) { key = "thumbstick"; offset = 0;} else if ( name == "R_JOYSTICK_Y" ) { i = vr::Controller_Hand::Hand_Right; key = "thumbstick"; offset = 1; } diff --git a/engine/src/spec/window/dreamcast.cpp b/engine/src/spec/window/dreamcast.cpp index 09f86b51..23bd5603 100644 --- a/engine/src/spec/window/dreamcast.cpp +++ b/engine/src/spec/window/dreamcast.cpp @@ -36,8 +36,8 @@ namespace { if ( !::keyboard.state ) return false; return ::keyboard.state->cond.modifiers & modifier; } - std::vector GetKeys() { - std::vector keys; + uf::stl::vector GetKeys() { + uf::stl::vector keys; keys.reserve(6); for ( size_t i = 0; i < MAX_PRESSED_KEYS && ::keyboard.state; ++i ) keys.emplace_back(::keyboard.state->cond.keys[i]); return keys; @@ -46,7 +46,7 @@ namespace { if ( !::keyboard.state || key < MAX_KBD_KEYS ) return 0; return ::keyboard.state->matrix[key]; } - std::string GetKeyName( uint8_t key ) { + uf::stl::string GetKeyName( uint8_t key ) { switch ( key ) { case KBD_KEY_A: return "A"; case KBD_KEY_B: return "B"; @@ -151,8 +151,8 @@ namespace { } return ""; } - uint8_t GetKeyCode( const std::string& _key ) { - std::string key = uf::string::uppercase(_key); + uint8_t GetKeyCode( const uf::stl::string& _key ) { + uf::stl::string key = uf::string::uppercase(_key); if ( key == "A" ) return KBD_KEY_A; else if ( key == "B" ) return KBD_KEY_B; @@ -363,7 +363,7 @@ void UF_API_CALL spec::dreamcast::Window::processEvents() { if ( ::mouse.device ) ::mouse.state = (mouse_state_t*) maple_dev_status(::mouse.device); /* Key inputs */ if ( this->m_asyncParse ) { - std::vector keys = GetKeys(); + uf::stl::vector keys = GetKeys(); pod::payloads::windowKey event{ "window:Key", "os", @@ -421,8 +421,8 @@ bool UF_API_CALL spec::dreamcast::Window::pollEvents( bool block ) { while ( !this->m_events.empty() ) { auto& event = this->m_events.front(); - if ( event.payload.is() ) { - ext::json::Value payload = uf::Serializer( event.payload.as() ); + if ( event.payload.is() ) { + ext::json::Value payload = uf::Serializer( event.payload.as() ); uf::hooks.call( event.name, payload ); } else if ( event.payload.is() ) { uf::Serializer& payload = event.payload.as(); @@ -465,7 +465,7 @@ pod::Vector2ui UF_API_CALL spec::dreamcast::Window::getResolution() { void UF_API_CALL spec::dreamcast::Window::switchToFullscreen( bool borderless ) { } -bool UF_API_CALL spec::dreamcast::Window::isKeyPressed(const std::string& key) { +bool UF_API_CALL spec::dreamcast::Window::isKeyPressed(const uf::stl::string& key) { auto code = GetKeyCode(key); auto keys = GetKeys(); for ( auto key : keys ) if ( key == code ) return true; diff --git a/engine/src/spec/window/universal.cpp b/engine/src/spec/window/universal.cpp index 777a39e1..6a4e13cc 100644 --- a/engine/src/spec/window/universal.cpp +++ b/engine/src/spec/window/universal.cpp @@ -25,14 +25,14 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::OptimalHook::name_t& na void UF_API_CALL spec::uni::Window::pushEvent( const uf::ReadableHook::argument_t& serialized ) { if ( !uf::hooks.prefersReadable() ) return; uf::Serializer json = serialized; - if ( !uf::hooks.exists(json["type"].as()) ) return; - this->m_events.readable.push({json["type"].as(), serialized}); + if ( !uf::hooks.exists(json["type"].as()) ) return; + this->m_events.readable.push({json["type"].as(), serialized}); } void UF_API_CALL spec::uni::Window::pushEvent( const uf::OptimalHook::argument_t& userdata ) { if ( uf::hooks.prefersReadable() ) return; // Header userdata struct Header { - std::string type; + uf::stl::string type; }; // Header header = userdata.get
(); const Header& header = uf::userdata::get
(userdata); @@ -44,7 +44,7 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::OptimalHook::argument_t this->m_events.optimal.back().argument = userdata; } */ -void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const std::string& payload ) { +void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const uf::stl::string& payload ) { auto& event = this->m_events.emplace(); event.name = name; event.payload.create( uf::Serializer(payload) ); @@ -65,7 +65,7 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, co } void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::argument_t& payload ) { struct Header { - std::string type; + uf::stl::string type; }; const Header& header = payload.get
(); if ( !uf::hooks.exists(header.type) ) return; @@ -73,7 +73,7 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::argument_t& payl } void UF_API_CALL spec::uni::Window::processEvents() { } -bool UF_API_CALL spec::uni::Window::isKeyPressed(const std::string& key) { +bool UF_API_CALL spec::uni::Window::isKeyPressed(const uf::stl::string& key) { return false; } bool UF_API_CALL spec::uni::Window::pollEvents( bool block ) { @@ -85,8 +85,8 @@ bool UF_API_CALL spec::uni::Window::pollEvents( bool block ) { // doesnt get used while ( !this->m_events.empty() ) { auto& event = this->m_events.front(); - if ( event.payload.is() ) { - ext::json::Value payload = uf::Serializer( event.payload.as() ); + if ( event.payload.is() ) { + ext::json::Value payload = uf::Serializer( event.payload.as() ); uf::hooks.call( "window:Event", payload ); uf::hooks.call( event.name, payload ); } else if ( event.payload.is() ) { diff --git a/engine/src/spec/window/unknown.cpp b/engine/src/spec/window/unknown.cpp index 5833b043..bbc88234 100644 --- a/engine/src/spec/window/unknown.cpp +++ b/engine/src/spec/window/unknown.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #ifdef UF_ENV_UNKNOWN diff --git a/engine/src/spec/window/windows.cpp b/engine/src/spec/window/windows.cpp index fd05003f..43c6132e 100644 --- a/engine/src/spec/window/windows.cpp +++ b/engine/src/spec/window/windows.cpp @@ -59,8 +59,8 @@ namespace { return DefWindowProcW(handle, message, wParam, lParam); } - std::vector GetKeys() { - std::vector keys; + uf::stl::vector GetKeys() { + uf::stl::vector keys; keys.reserve(8); if ( GetAsyncKeyState('A') & 0x8000 ) keys.push_back('A'); @@ -172,7 +172,7 @@ namespace { if ( GetAsyncKeyState(VK_XBUTTON2) & 0x8000 ) keys.push_back(VK_XBUTTON2); return keys; } - std::string _GetKeyName( WPARAM key, LPARAM flags = 0 ) { + uf::stl::string _GetKeyName( WPARAM key, LPARAM flags = 0 ) { #if 1 switch ( key ) { // Check the scancode to distinguish between left and right shift @@ -404,12 +404,12 @@ namespace { #endif return std::to_string((int) key); } - std::string GetKeyName( WPARAM key, LPARAM flags = 0 ) { + uf::stl::string GetKeyName( WPARAM key, LPARAM flags = 0 ) { return uf::string::uppercase( _GetKeyName( key, flags ) ); } - WPARAM GetKeyCode( const std::string& _name ) { - std::string name = uf::string::uppercase(_name); + WPARAM GetKeyCode( const uf::stl::string& _name ) { + uf::stl::string name = uf::string::uppercase(_name); if ( name == "A" ) return 'A'; else if ( name == "B" ) return 'B'; else if ( name == "C" ) return 'C'; @@ -702,7 +702,7 @@ void UF_API_CALL spec::win32::Window::setTitle( const spec::win32::Window::title void UF_API_CALL spec::win32::Window::setIcon( const spec::win32::Window::vector_t& size, uint8_t* pixels ) { // First destroy the previous one - std::vector iconPixels(size.x * size.y * 4); + uf::stl::vector iconPixels(size.x * size.y * 4); for (std::size_t i = 0; i < iconPixels.size() / 4; ++i) { iconPixels[i * 4 + 0] = pixels[i * 4 + 2]; iconPixels[i * 4 + 1] = pixels[i * 4 + 1]; @@ -718,7 +718,7 @@ void UF_API_CALL spec::win32::Window::setIcon( const spec::win32::Window::vector if ( this->m_icon ) DestroyIcon(this->m_icon); // RGBA -> BGRA - std::vector icon( uf::vector::product(size) * 4 ); + uf::stl::vector icon( uf::vector::product(size) * 4 ); for ( std::size_t i = 0; i < icon.size() / 4; ++i ) { icon[i * 4 + 0] = pixels[i * 4 + 2]; icon[i * 4 + 1] = pixels[i * 4 + 1]; @@ -773,10 +773,12 @@ void UF_API_CALL spec::win32::Window::processEvents() { } } /* Key inputs */ if ( this->m_asyncParse ) { - std::vector keys = GetKeys(); + uf::stl::vector keys = GetKeys(); pod::payloads::windowKey event{ - "window:Key", - "os", + { + "window:Key", + "os", + }, { "", 0, @@ -831,8 +833,8 @@ bool UF_API_CALL spec::win32::Window::pollEvents( bool block ) { while ( !this->m_events.empty() ) { auto& event = this->m_events.front(); - if ( event.payload.is() ) { - ext::json::Value payload = uf::Serializer( event.payload.as() ); + if ( event.payload.is() ) { + ext::json::Value payload = uf::Serializer( event.payload.as() ); uf::hooks.call( event.name, payload ); } else if ( event.payload.is() ) { uf::Serializer& payload = event.payload.as(); @@ -912,9 +914,9 @@ void UF_API_CALL spec::win32::Window::registerWindowClass() { void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, LPARAM lParam) { if (!this->m_handle) return; - std::string hook = "window:Unknown"; - std::string serialized = ""; - std::stringstream serializer; + uf::stl::string hook = "window:Unknown"; + uf::stl::string serialized = ""; + uf::stl::stringstream serializer; bool labelAsDelta = true; uf::Serializer json; @@ -946,8 +948,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, this->m_lastSize = this->getSize(); pod::payloads::windowResized event{ - "window:Resized", - "os", + { + "window:Resized", + "os", + }, { this->m_lastSize }, }; #if UF_USE_USERDATA @@ -972,8 +976,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, this->m_lastSize = this->getSize(); pod::payloads::windowResized event = { - "window:Resized", - "os", + { + "window:Resized", + "os", + }, { this->m_lastSize }, }; #if UF_USE_USERDATA @@ -1018,14 +1024,20 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, this->grabMouse(this->m_mouseGrabbed); SetCursor(this->m_cursor); } - pod::payloads::windowFocusedChanged event{ - "window:Focus.Changed", - "os", - }; + int_fast8_t state{}; switch ( message ) { - case WM_SETFOCUS: event.window.state = 1; break; - case WM_KILLFOCUS: event.window.state = -1; break; + case WM_SETFOCUS: state = 1; break; + case WM_KILLFOCUS: state = -1; break; } + pod::payloads::windowFocusedChanged event{ + { + "window:Focus.Changed", + "os", + }, + { + state + } + }; #if UF_USE_USERDATA this->pushEvent(event.type, event); #endif @@ -1063,11 +1075,13 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, uf::Utf32::toUtf8(utf32.begin(), utf32.end(), std::back_inserter(utf8)); pod::payloads::windowTextEntered event{ - "window:Text.Entered", - "os", + { + "window:Text.Entered", + "os", + }, { character, - std::string(utf8.begin(), utf8.end()), + uf::stl::string(utf8.begin(), utf8.end()), } }; #if UF_USE_USERDATA @@ -1098,21 +1112,23 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, case WM_SYSKEYUP: state = 1; break; } pod::payloads::windowKey event{ + { "window:Key", "os", - { - this->getKey(wParam, lParam), - wParam, - state, - false, - { - .alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0, - .ctrl = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0, - .shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0, - .sys = HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN)), - } + }, + { + this->getKey(wParam, lParam), + wParam, + state, + false, + { + .alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0, + .ctrl = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0, + .shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0, + .sys = HIWORD(GetAsyncKeyState(VK_LWIN)) || HIWORD(GetAsyncKeyState(VK_RWIN)), } - }; + } + }; #if UF_USE_USERDATA this->pushEvent(event.type, event); this->pushEvent(event.type + "." + event.key.code, event); @@ -1144,8 +1160,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, int16_t delta = static_cast(HIWORD(wParam)); pod::payloads::windowMouseWheel event{ - "window:Mouse.Wheel", - "os", + { + "window:Mouse.Wheel", + "os", + }, { pod::Vector2ui{ position.x, position.y }, delta, @@ -1174,7 +1192,7 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, static pod::Vector2i lastPosition = {}; const pod::Vector2i currentPosition = pod::Vector2ui{ static_cast(LOWORD(lParam)), static_cast(HIWORD(lParam)) }; - std::string button = ""; + uf::stl::string button = ""; int_fast8_t state = 0; switch ( message ) { @@ -1205,8 +1223,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, default: state = 0; break; } pod::payloads::windowMouseClick event{ - "window:Mouse.Click", - "os", + { + "window:Mouse.Click", + "os", + }, { currentPosition, currentPosition - lastPosition, @@ -1236,12 +1256,15 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, case WM_MOUSELEAVE: if ( this->m_mouseInside ) { this->m_mouseInside = false; - pod::payloads::windowMouseMoved event{ - "window:Mouse.Moved", - "os", { - {} + { + "window:Mouse.Moved", + "client", + }, + { + {}, + }, }, { {}, @@ -1300,17 +1323,20 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam, state = 1; } } - pod::payloads::windowMouseMoved event{ - "window:Mouse.Moved", - "os", { - pod::Vector2ui{ area.right, area.bottom }, + { + "window:Mouse.Moved", + "client", + }, + { + pod::Vector2ui{ area.right, area.bottom }, + }, }, { currentPosition, currentPosition - lastPosition, - state + 0 } }; #if UF_USE_USERDATA @@ -1385,15 +1411,15 @@ void UF_API_CALL spec::win32::Window::switchToFullscreen( bool borderless ) { fullscreenWindow = (void*) this; } -bool UF_API_CALL spec::win32::Window::isKeyPressed(const std::string& key) { +bool UF_API_CALL spec::win32::Window::isKeyPressed(const uf::stl::string& key) { return GetAsyncKeyState( GetKeyCode( key ) ) & 0x8000; } -std::string UF_API_CALL spec::win32::Window::getKey(WPARAM key, LPARAM flags) { +uf::stl::string UF_API_CALL spec::win32::Window::getKey(WPARAM key, LPARAM flags) { return GetKeyName( key, flags ); } #if defined(UF_USE_VULKAN) && UF_USE_VULKAN == 1 -std::vector UF_API_CALL spec::win32::Window::getExtensions( bool validationEnabled ) { - std::vector instanceExtensions = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; +uf::stl::vector UF_API_CALL spec::win32::Window::getExtensions( bool validationEnabled ) { + uf::stl::vector instanceExtensions = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; if ( validationEnabled ) instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); return instanceExtensions; } diff --git a/engine/src/utils/audio/audio.cpp b/engine/src/utils/audio/audio.cpp index 77cdf963..0ee46280 100644 --- a/engine/src/utils/audio/audio.cpp +++ b/engine/src/utils/audio/audio.cpp @@ -31,20 +31,20 @@ bool uf::Audio::playing() const { #endif } -void uf::Audio::open( const std::string& filename ) { +void uf::Audio::open( const uf::stl::string& filename ) { this->open( filename, uf::audio::streamsByDefault ); } -void uf::Audio::open( const std::string& filename, bool streamed ) { +void uf::Audio::open( const uf::stl::string& filename, bool streamed ) { streamed ? stream( filename ) : load( filename ); } -void uf::Audio::load( const std::string& filename ) { +void uf::Audio::load( const uf::stl::string& filename ) { if ( uf::audio::muted ) return; #if UF_USE_OPENAL if ( this->m_metadata ) ext::al::close( *this->m_metadata ); this->m_metadata = ext::al::load( filename ); #endif } -void uf::Audio::stream( const std::string& filename ) { +void uf::Audio::stream( const uf::stl::string& filename ) { if ( uf::audio::muted ) return; #if UF_USE_OPENAL if ( this->m_metadata ) ext::al::close( *this->m_metadata ); @@ -190,8 +190,8 @@ void uf::Audio::setMaxDistance( float v ) { float uf::Audio::getVolume() const { return this->getGain(); } void uf::Audio::setVolume( float v ) { return this->setGain( v ); } -const std::string& uf::Audio::getFilename() const { - const std::string null = ""; +const uf::stl::string& uf::Audio::getFilename() const { + static const uf::stl::string null = ""; return this->m_metadata ? this->m_metadata->filename : null; } float uf::Audio::getDuration() const { diff --git a/engine/src/utils/audio/emitter.cpp b/engine/src/utils/audio/emitter.cpp index d2dc2850..02570f95 100644 --- a/engine/src/utils/audio/emitter.cpp +++ b/engine/src/utils/audio/emitter.cpp @@ -9,38 +9,38 @@ uf::SoundEmitter::~SoundEmitter() { this->cleanup(true); } -bool uf::SoundEmitter::has( const std::string& filename ) const { +bool uf::SoundEmitter::has( const uf::stl::string& filename ) const { for ( auto& audio : this->m_container ) if ( audio.getFilename() == filename ) return true; return false; } uf::Audio& UF_API uf::SoundEmitter::add() { return this->m_container.emplace_back(); } -uf::Audio& UF_API uf::SoundEmitter::add( const std::string& filename ) { +uf::Audio& UF_API uf::SoundEmitter::add( const uf::stl::string& filename ) { // if ( this->has(filename) ) return this->get(filename); uf::Audio& sound = this->add(); sound.open(filename); return sound; } -uf::Audio& UF_API uf::SoundEmitter::load( const std::string& filename ) { +uf::Audio& UF_API uf::SoundEmitter::load( const uf::stl::string& filename ) { // if ( this->has(filename) ) return this->get(filename); uf::Audio& sound = this->add(); sound.load(filename); return sound; } -uf::Audio& UF_API uf::SoundEmitter::stream( const std::string& filename ) { +uf::Audio& UF_API uf::SoundEmitter::stream( const uf::stl::string& filename ) { // if ( this->has(filename) ) return this->get(filename); uf::Audio& sound = this->add(); sound.stream(filename); return sound; } -uf::Audio& UF_API uf::SoundEmitter::get( const std::string& filename ) { +uf::Audio& UF_API uf::SoundEmitter::get( const uf::stl::string& filename ) { if ( !this->has(filename) ) return this->add(filename); for ( auto& audio : this->m_container ) if ( audio.getFilename() == filename ) return audio; return this->add(); } -const uf::Audio& UF_API uf::SoundEmitter::get( const std::string& filename ) const { +const uf::Audio& UF_API uf::SoundEmitter::get( const uf::stl::string& filename ) const { for ( auto& audio : this->m_container ) if ( audio.getFilename() == filename ) return audio; return uf::audio::null; } @@ -65,10 +65,10 @@ void UF_API uf::SoundEmitter::cleanup( bool purge ) { uf::MappedSoundEmitter::~MappedSoundEmitter() { this->cleanup(true); } -bool uf::MappedSoundEmitter::has( const std::string& filename ) const { +bool uf::MappedSoundEmitter::has( const uf::stl::string& filename ) const { return this->m_container.count(filename) > 0; } -uf::Audio& UF_API uf::MappedSoundEmitter::add( const std::string& filename ) { +uf::Audio& UF_API uf::MappedSoundEmitter::add( const uf::stl::string& filename ) { if ( this->has(filename) ) return this->get(filename); uf::Audio& sound = this->m_container[filename]; @@ -76,14 +76,14 @@ uf::Audio& UF_API uf::MappedSoundEmitter::add( const std::string& filename ) { return sound; } -uf::Audio& UF_API uf::MappedSoundEmitter::load( const std::string& filename ) { +uf::Audio& UF_API uf::MappedSoundEmitter::load( const uf::stl::string& filename ) { if ( this->has(filename) ) return this->get(filename); uf::Audio& sound = this->m_container[filename]; sound.load(filename); return sound; } -uf::Audio& UF_API uf::MappedSoundEmitter::stream( const std::string& filename ) { +uf::Audio& UF_API uf::MappedSoundEmitter::stream( const uf::stl::string& filename ) { if ( this->has(filename) ) return this->get(filename); uf::Audio& sound = this->m_container[filename]; @@ -91,11 +91,11 @@ uf::Audio& UF_API uf::MappedSoundEmitter::stream( const std::string& filename ) return sound; } -uf::Audio& UF_API uf::MappedSoundEmitter::get( const std::string& filename ) { +uf::Audio& UF_API uf::MappedSoundEmitter::get( const uf::stl::string& filename ) { if ( !this->has(filename) ) return this->add(filename); return this->m_container[filename]; } -const uf::Audio& UF_API uf::MappedSoundEmitter::get( const std::string& filename ) const { +const uf::Audio& UF_API uf::MappedSoundEmitter::get( const uf::stl::string& filename ) const { return this->m_container.at(filename); } uf::MappedSoundEmitter::container_t& UF_API uf::MappedSoundEmitter::get() { diff --git a/engine/src/utils/hook/hook.cpp b/engine/src/utils/hook/hook.cpp index a5e6c1f4..f6a9a8ae 100644 --- a/engine/src/utils/hook/hook.cpp +++ b/engine/src/utils/hook/hook.cpp @@ -23,7 +23,7 @@ void uf::Hooks::removeHook( const uf::Hooks::name_t& name, size_t uid ) { } uf::Hooks::return_t uf::Hooks::call( const uf::Hooks::name_t& name, const pod::Hook::userdata_t& payload ) { auto& container = this->m_container[name]; - std::vector results; + uf::stl::vector results; results.reserve( container.size() ); for ( auto& hook : container ) { @@ -40,24 +40,24 @@ uf::Hooks::return_t uf::Hooks::call( const uf::Hooks::name_t& name, const pod::H return results; } -uf::Hooks::return_t uf::Hooks::call( const uf::Hooks::name_t& name, const std::string& s ) { +uf::Hooks::return_t uf::Hooks::call( const uf::Hooks::name_t& name, const uf::stl::string& s ) { pod::Hook::userdata_t payload; payload.create(); auto& value = payload.get(); value = uf::Serializer(s); -// payload.create( s ); +// payload.create( s ); return call(name, payload); } uf::Hooks::return_t uf::Hooks::call( const uf::Hooks::name_t& name, const ext::json::Value& s ) { pod::Hook::userdata_t payload; payload.create( s ); -// payload.create( ext::json::encode( s ) ); +// payload.create( ext::json::encode( s ) ); return call(name, payload); } uf::Hooks::return_t uf::Hooks::call( const uf::Hooks::name_t& name, const uf::Serializer& s ) { pod::Hook::userdata_t payload; payload.create( (const ext::json::Value&) s ); -// payload.create( s.serialize() ); +// payload.create( s.serialize() ); return call(name, payload); } // specialization: void function diff --git a/engine/src/utils/http/http.cpp b/engine/src/utils/http/http.cpp index 4b64c7e1..3f99734d 100644 --- a/engine/src/utils/http/http.cpp +++ b/engine/src/utils/http/http.cpp @@ -5,13 +5,13 @@ #include namespace { - size_t writeFunction(void *ptr, size_t size, size_t nmemb, std::string* data) { + size_t writeFunction(void *ptr, size_t size, size_t nmemb, uf::stl::string* data) { data->append((char*) ptr, size * nmemb); return size * nmemb; } } -uf::Http UF_API uf::http::get( const std::string& url ) { +uf::Http UF_API uf::http::get( const uf::stl::string& url ) { uf::Http http; #if UF_USE_CURL diff --git a/engine/src/utils/image/image.cpp b/engine/src/utils/image/image.cpp index 7c07c814..970158d6 100644 --- a/engine/src/utils/image/image.cpp +++ b/engine/src/utils/image/image.cpp @@ -72,7 +72,7 @@ uf::Image::Image( const Image::container_t& copy, const Image::vec2_t& size ) : } -std::string uf::Image::getFilename() const { +uf::stl::string uf::Image::getFilename() const { return this->m_filename; } @@ -86,11 +86,11 @@ std::string uf::Image::getFilename() const { ((((uint16_t)r & 0xf8) << 8) | (((uint16_t) g & 0xfc) << 3) | ((uint16_t) b >> 3)) // from file -bool uf::Image::open( const std::string& filename, bool flip ) { +bool uf::Image::open( const uf::stl::string& filename, bool flip ) { #if UF_ENV_DREAMCAST - std::string extension = uf::io::extension(filename); + uf::stl::string extension = uf::io::extension(filename); if ( extension != "dtex" ) { - std::string dtex = uf::string::replace( filename, ".png", ".dtex" ); + uf::stl::string dtex = uf::string::replace( filename, ".png", ".dtex" ); if ( uf::io::exists(dtex) ) { UF_MSG_DEBUG("Loading dtex instead for: " << filename); return this->open(dtex, flip); @@ -321,7 +321,7 @@ std::size_t uf::Image::getChannels() const { std::size_t uf::Image::getFormat() const { return this->m_format; } -std::string uf::Image::getHash() const { +uf::stl::string uf::Image::getHash() const { return uf::string::sha256( this->m_pixels ); } uf::Image::pixel_t uf::Image::at( const uf::Image::vec2_t& at ) { @@ -335,13 +335,13 @@ uf::Image::pixel_t uf::Image::at( const uf::Image::vec2_t& at ) { } // Modifiers // to file -bool uf::Image::save( const std::string& filename, bool flip ) const { +bool uf::Image::save( const uf::stl::string& filename, bool flip ) const { if ( this->m_pixels.empty() ) return false; uint w = this->m_dimensions.x; uint h = this->m_dimensions.y; auto* pixels = &this->m_pixels[0]; - std::string extension = uf::io::extension(filename); + uf::stl::string extension = uf::io::extension(filename); stbi_flip_vertically_on_write(flip); if ( extension == "png" ) { stbi_write_png(filename.c_str(), w, h, this->m_channels, &pixels[0], w * this->m_channels); @@ -355,7 +355,7 @@ void uf::Image::save( std::ostream& stream ) const { } #include -void uf::Image::convert( const std::string& from, const std::string& to ) { +void uf::Image::convert( const uf::stl::string& from, const uf::stl::string& to ) { uf::Image::container_t pixels = std::move(this->m_pixels); if ( uf::string::lowercase(to) != "rgba" ) { } else { diff --git a/engine/src/utils/io/file.cpp b/engine/src/utils/io/file.cpp index 7a9d3cbe..e81c8d47 100644 --- a/engine/src/utils/io/file.cpp +++ b/engine/src/utils/io/file.cpp @@ -18,28 +18,28 @@ #define GetCurrentDir getcwd #endif -const std::string uf::io::root = UF_IO_ROOT; +const uf::stl::string uf::io::root = UF_IO_ROOT; -std::string UF_API uf::io::absolute( const std::string& path ) { +uf::stl::string UF_API uf::io::absolute( const uf::stl::string& path ) { char buff[FILENAME_MAX]; GetCurrentDir( buff, FILENAME_MAX ); - return std::string(buff) + path; + return uf::stl::string(buff) + path; } -std::string UF_API uf::io::filename( const std::string& str ) { +uf::stl::string UF_API uf::io::filename( const uf::stl::string& str ) { return str.substr( str.find_last_of('/') + 1 ); } -std::string UF_API uf::io::basename( const std::string& filename ) { - std::string str = uf::io::filename( filename ); - std::string extension = uf::io::extension( filename ); +uf::stl::string UF_API uf::io::basename( const uf::stl::string& filename ) { + uf::stl::string str = uf::io::filename( filename ); + uf::stl::string extension = uf::io::extension( filename ); return uf::string::replace( str, "." + extension, "" ); } -std::string UF_API uf::io::extension( const std::string& str ) { - std::string filename = uf::io::filename(str); +uf::stl::string UF_API uf::io::extension( const uf::stl::string& str ) { + uf::stl::string filename = uf::io::filename(str); return filename.substr( filename.find_last_of('.') + 1 ); } -std::string UF_API uf::io::extension( const std::string& str, int32_t count ) { - std::string filename = uf::io::filename(str); - std::string extension = ""; +uf::stl::string UF_API uf::io::extension( const uf::stl::string& str, int32_t count ) { + uf::stl::string filename = uf::io::filename(str); + uf::stl::string extension = ""; auto split = uf::string::split( filename, "." ); size_t offset = split.size() - 1; if ( count < 0 ) { @@ -53,37 +53,37 @@ std::string UF_API uf::io::extension( const std::string& str, int32_t count ) { } return extension; } -std::string UF_API uf::io::directory( const std::string& str ) { +uf::stl::string UF_API uf::io::directory( const uf::stl::string& str ) { return str.substr( 0, str.find_last_of('/') ) + "/"; } -size_t UF_API uf::io::size( const std::string& filename ) { +size_t UF_API uf::io::size( const uf::stl::string& filename ) { std::ifstream is(filename, std::ios::binary | std::ios::in | std::ios::ate); if ( !is.is_open() ) return 0; is.seekg(0, std::ios::end); return is.tellg(); } -std::string UF_API uf::io::sanitize( const std::string& str, const std::string& _root ) { +uf::stl::string UF_API uf::io::sanitize( const uf::stl::string& str, const uf::stl::string& _root ) { // resolve %root% to hard root - std::string path = str; - std::string root = _root; + uf::stl::string path = str; + uf::stl::string root = _root; // append root to path if ( path.find("%root%") == 0 ) { path = uf::string::replace( path, "%root%", "" ); if ( root == "" ) root = uf::io::root; } - if ( path.find(root) == std::string::npos ) { + if ( path.find(root) == uf::stl::string::npos ) { path = root + "/" + path; } // flatten all "/./" { - std::string tmp; + uf::stl::string tmp; while ( path != (tmp = uf::string::replace(path, "/./", "/")) ) { path = tmp; } } // flatten all "//" { - std::string tmp; + uf::stl::string tmp; while ( path != (tmp = uf::string::replace(path, "//", "/")) ) { path = tmp; } @@ -91,10 +91,10 @@ std::string UF_API uf::io::sanitize( const std::string& str, const std::string& return path; } // would just use readAsBuffer and convert to string, but that's double the memory cost -std::string UF_API uf::io::readAsString( const std::string& _filename, const std::string& hash ) { - std::string buffer; - std::string filename = sanitize(_filename); - std::string extension = uf::io::extension( filename ); +uf::stl::string UF_API uf::io::readAsString( const uf::stl::string& _filename, const uf::stl::string& hash ) { + uf::stl::string buffer; + uf::stl::string filename = sanitize(_filename); + uf::stl::string extension = uf::io::extension( filename ); if ( extension == "gz" ) { auto decompressed = uf::io::decompress( filename ); buffer.reserve(decompressed.size()); @@ -108,17 +108,17 @@ std::string UF_API uf::io::readAsString( const std::string& _filename, const std is.seekg(0, std::ios::end); buffer.reserve(is.tellg()); is.seekg(0, std::ios::beg); buffer.assign((std::istreambuf_iterator(is)), std::istreambuf_iterator()); } - std::string expected = ""; + uf::stl::string expected = ""; if ( hash != "" && (expected = uf::string::sha256( buffer )) != hash ) { UF_MSG_ERROR("Error: Hash mismatch for file \"" << filename << "\"; expecting " << hash << ", got " << expected); return ""; } return buffer; } -std::vector UF_API uf::io::readAsBuffer( const std::string& _filename, const std::string& hash ) { - std::vector buffer; - std::string filename = sanitize(_filename); - std::string extension = uf::io::extension( filename ); +uf::stl::vector UF_API uf::io::readAsBuffer( const uf::stl::string& _filename, const uf::stl::string& hash ) { + uf::stl::vector buffer; + uf::stl::string filename = sanitize(_filename); + uf::stl::string extension = uf::io::extension( filename ); if ( extension == "gz" ) { buffer = uf::io::decompress( filename ); } else { @@ -130,16 +130,16 @@ std::vector UF_API uf::io::readAsBuffer( const std::string& _filename, is.seekg(0, std::ios::end); buffer.reserve(is.tellg()); is.seekg(0, std::ios::beg); buffer.assign((std::istreambuf_iterator(is)), std::istreambuf_iterator()); } - std::string expected = ""; + uf::stl::string expected = ""; if ( hash != "" && (expected = uf::string::sha256( buffer )) != hash ) { UF_MSG_ERROR("Error: Hash mismatch for file \"" << filename << "\"; expecting " << hash << ", got " << expected); - return std::vector(); + return uf::stl::vector(); } return buffer; } -size_t UF_API uf::io::write( const std::string& filename, const void* buffer, size_t size ) { - std::string extension = uf::io::extension( filename ); +size_t UF_API uf::io::write( const uf::stl::string& filename, const void* buffer, size_t size ) { + uf::stl::string extension = uf::io::extension( filename ); if ( extension == "gz" ) return uf::io::compress( filename, buffer, size ); std::ofstream output; @@ -150,52 +150,52 @@ size_t UF_API uf::io::write( const std::string& filename, const void* buffer, si } // indirection for different compression formats, currently only using zlib's gzFile shit -std::vector UF_API uf::io::decompress( const std::string& filename ) { +uf::stl::vector UF_API uf::io::decompress( const uf::stl::string& filename ) { return ext::zlib::decompressFromFile( filename ); } -size_t UF_API uf::io::compress( const std::string& filename, const void* buffer, size_t size ) { +size_t UF_API uf::io::compress( const uf::stl::string& filename, const void* buffer, size_t size ) { return ext::zlib::compressToFile( filename, buffer, size ); } -std::string UF_API uf::io::hash( const std::string& filename ) { +uf::stl::string UF_API uf::io::hash( const uf::stl::string& filename ) { return uf::string::sha256( uf::io::readAsBuffer( filename ) ); } -bool UF_API uf::io::exists( const std::string& _filename ) { - std::string filename = sanitize(_filename); +bool UF_API uf::io::exists( const uf::stl::string& _filename ) { + uf::stl::string filename = sanitize(_filename); static struct stat buffer; return stat(filename.c_str(), &buffer) == 0; } -size_t UF_API uf::io::mtime( const std::string& _filename ) { - std::string filename = sanitize(_filename); +size_t UF_API uf::io::mtime( const uf::stl::string& _filename ) { + uf::stl::string filename = sanitize(_filename); static struct stat buffer; if ( stat(filename.c_str(), &buffer) != 0 ) return -1; return buffer.st_mtime; } -bool UF_API uf::io::mkdir( const std::string& _filename ) { +bool UF_API uf::io::mkdir( const uf::stl::string& _filename ) { #if UF_ENV_DREAMCAST return false; #else - std::string filename = sanitize(_filename); + uf::stl::string filename = sanitize(_filename); int status = ::mkdir(filename.c_str()); return status != -1; #endif } -std::string UF_API uf::io::resolveURI( const std::string& filename, const std::string& _root ) { - std::string root = _root; +uf::stl::string UF_API uf::io::resolveURI( const uf::stl::string& filename, const uf::stl::string& _root ) { + uf::stl::string root = _root; if ( filename.substr(0,8) == "https://" ) return filename; - const std::string extension = uf::io::extension(filename); + const uf::stl::string extension = uf::io::extension(filename); // just sanitize if ( filename.find(uf::io::root) == 0 ) { return uf::io::sanitize( uf::io::filename( filename ), uf::io::directory( filename ) ); } if ( filename.find("%root%") == 0 ) { - const std::string f = uf::string::replace( filename, "%root%", uf::io::root ); + const uf::stl::string f = uf::string::replace( filename, "%root%", uf::io::root ); return uf::io::sanitize( uf::io::filename( f ), uf::io::directory( f ) ); } // if the filename contains an absolute path or if no root is provided if ( filename[0] == '/' || root == "" ) { - const std::string basename = uf::io::filename( filename ); - const std::string extensions = uf::io::extension( filename, -1 ); + const uf::stl::string basename = uf::io::filename( filename ); + const uf::stl::string extensions = uf::io::extension( filename, -1 ); if ( filename[0] == '/' && filename[1] == '/' ) root = uf::io::root; // else if ( uf::io::extension(filename, -1) == "graph.json" ) root = uf::io::root + "/models/"; // else if ( uf::io::extension(filename, -1) == "scene.json" ) root = uf::io::root + "/scenes/"; diff --git a/engine/src/utils/io/iostream.cpp b/engine/src/utils/io/iostream.cpp index 04c6e49f..758b6e10 100644 --- a/engine/src/utils/io/iostream.cpp +++ b/engine/src/utils/io/iostream.cpp @@ -10,15 +10,15 @@ #include #include -#include +#include namespace { struct { int character; - std::string temporary; + uf::stl::string temporary; struct { - std::string buffer; - std::vector history; + uf::stl::string buffer; + uf::stl::vector history; } input, output; struct { unsigned int buffer = 0; @@ -45,7 +45,7 @@ namespace { } else if ( ch < 32 || ch > 127 ) return; ::info.output.buffer += ch; } - void addStr( const std::string& str ) { + void addStr( const uf::stl::string& str ) { for ( auto x : str ) addCh(x); } void addUStr( const uf::String& str ) { @@ -119,10 +119,10 @@ void UF_API_CALL uf::IoStream::clear(bool all) { ext::ncurses.clear(); #endif } -std::string uf::IoStream::getBuffer() { +uf::stl::string uf::IoStream::getBuffer() { return ::info.output.buffer; } -std::vector uf::IoStream::getHistory() { +uf::stl::vector uf::IoStream::getHistory() { return ::info.output.history; } void UF_API_CALL uf::IoStream::back() { @@ -170,18 +170,18 @@ char UF_API_CALL uf::IoStream::readChar(const bool& loop) { return 0; #endif } -std::string UF_API_CALL uf::IoStream::readString(const bool& loop) { +uf::stl::string UF_API_CALL uf::IoStream::readString(const bool& loop) { #if UF_USE_NCURSES if ( !ext::ncurses.initialized() ) this->initialize(); - // static std::vector history; + // static uf::stl::vector history; #endif if ( !uf::IoStream::ncurses ) { - std::string in; + uf::stl::string in; std::getline(std::cin, in); return in; } #if UF_USE_NCURSES - /*std::string ::info.input.buffer; + /*uf::stl::string ::info.input.buffer; int ch; struct { int r = 0, c = 0; @@ -189,7 +189,7 @@ std::string UF_API_CALL uf::IoStream::readString(const bool& loop) { } home; unsigned int cursor = 0; - std::string ::info.temporary; + uf::stl::string ::info.temporary; int ::info.indices.history = -1;*/ ext::ncurses.getYX(::info.cursor.row, ::info.cursor.column); ext::ncurses.getMaxYX(::info.window.rows, ::info.window.columns); @@ -265,15 +265,15 @@ std::string UF_API_CALL uf::IoStream::readString(const bool& loop) { uf::String UF_API_CALL uf::IoStream::readUString(const bool& loop) { #if UF_USE_NCURSES if ( !ext::ncurses.initialized() ) this->initialize(); - // static std::vector history; + // static uf::stl::vector history; #endif if ( !uf::IoStream::ncurses ) { - std::string in; + uf::stl::string in; std::getline(std::cin, in); return in; } #if UF_USE_NCURSES - /*std::string ::info.input.buffer; + /*uf::stl::string ::info.input.buffer; int ch; struct { int r = 0, c = 0; @@ -281,7 +281,7 @@ uf::String UF_API_CALL uf::IoStream::readUString(const bool& loop) { } home; unsigned int cursor = 0; - std::string ::info.temporary; + uf::stl::string ::info.temporary; int ::info.indices.history = -1;*/ ext::ncurses.getYX(::info.cursor.row, ::info.cursor.column); ext::ncurses.getMaxYX(::info.window.rows, ::info.window.columns); @@ -406,15 +406,15 @@ char UF_API_CALL uf::IoStream::writeChar( char ch ) { return ch; #endif } -const std::string& UF_API_CALL uf::IoStream::writeString( const std::string& str ) { +const uf::stl::string& UF_API_CALL uf::IoStream::writeString( const uf::stl::string& str ) { #if UF_USE_NCURSES if ( !ext::ncurses.initialized() ) this->initialize(); #endif addStr(str); /* std::size_t needle; - std::string haystack = str; - while ( (needle = haystack.find('\n')) != std::string::npos ) { + uf::stl::string haystack = str; + while ( (needle = haystack.find('\n')) != uf::stl::string::npos ) { ::info.output.buffer += haystack.substr( 0, needle ); ::info.output.history.push_back(::info.output.buffer); ::info.output.buffer = ""; @@ -441,8 +441,8 @@ const uf::String& UF_API_CALL uf::IoStream::writeUString( const uf::String& str /* std::size_t needle; auto haystack = str.getString(); - while ( (needle = haystack.find('\n')) != std::string::npos ) { - ::info.output.buffer += std::string((const char*) haystack.substr( 0, needle ).c_str()); + while ( (needle = haystack.find('\n')) != uf::stl::string::npos ) { + ::info.output.buffer += uf::stl::string((const char*) haystack.substr( 0, needle ).c_str()); ::info.output.history.push_back(::info.output.buffer); ::info.output.buffer = ""; haystack = haystack.substr( needle + 1 ); @@ -460,85 +460,85 @@ const uf::String& UF_API_CALL uf::IoStream::writeUString( const uf::String& str } void UF_API_CALL uf::IoStream::operator>> (bool& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (char& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (short& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (unsigned short& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (int& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (unsigned int& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (unsigned long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (long long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (unsigned long long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (float& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (double& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } void UF_API_CALL uf::IoStream::operator>> (long double& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << this->readString(); ss >> val; } -void UF_API_CALL uf::IoStream::operator>> (std::string& val) { +void UF_API_CALL uf::IoStream::operator>> (uf::stl::string& val) { val = this->readString(); } void UF_API_CALL uf::IoStream::operator>> (uf::String& val) { val = this->readUString(); } std::istream& UF_API_CALL uf::IoStream::operator>> ( std::istream& is ) { - std::string input; + uf::stl::string input; is >> input; this->writeString(input); return is; } std::istream& UF_API_CALL operator>> ( std::istream& is, uf::IoStream& io ) { - std::string input; + uf::stl::string input; is >> input; io.writeString(input); return is; @@ -547,84 +547,84 @@ std::istream& UF_API_CALL operator>> ( std::istream& is, uf::IoStream& io ) { uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const bool& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const char& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const short& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const unsigned short& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const int& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const unsigned int& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const unsigned long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const long long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const unsigned long long& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const float& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const double& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const long double& val) { - std::stringstream ss; + uf::stl::stringstream ss; ss << val; this->writeString(ss.str()); return *this; } -uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const std::string& val) { +uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const uf::stl::string& val) { this->writeString(val); return *this; } @@ -633,7 +633,7 @@ uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const uf::String& val) { return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const char* cstr) { - this->writeString(std::string(cstr)); + this->writeString(uf::stl::string(cstr)); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const uf::Serializer& val) { @@ -641,27 +641,27 @@ uf::IoStream& UF_API_CALL uf::IoStream::operator<< (const uf::Serializer& val) { return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< (void* ptr) { - std::stringstream ss; + uf::stl::stringstream ss; ss << ptr; this->writeString(ss.str()); return *this; } uf::IoStream& UF_API_CALL uf::IoStream::operator<< ( std::ostream& os ) { - std::stringstream str; + uf::stl::stringstream str; str << os.rdbuf(); this->writeString( str.str() ); return *this; } std::ostream& UF_API_CALL operator<< ( std::ostream& os, uf::IoStream& io ) { - std::string output = io.readString(); + uf::stl::string output = io.readString(); os << output; return os; } -std::string uf::IoStream::getColor() { +uf::stl::string uf::IoStream::getColor() { return this->m_currentColor; } -void UF_API_CALL uf::IoStream::setColor( const std::string& str ) { +void UF_API_CALL uf::IoStream::setColor( const uf::stl::string& str ) { #if UF_USE_NCURSES if ( !uf::IoStream::ncurses ) return; if ( !ext::ncurses.initialized() ) this->initialize(); @@ -682,17 +682,17 @@ UF_API_CALL uf::IoStream::Color::Manip1::Manip1( uf::IoStream& _io ) : io(_io) { uf::IoStream::Color::Manip1 UF_API_CALL uf::IoStream::operator<< ( const uf::IoStream::Color& color) { return uf::IoStream::Color::Manip1(*this); } -uf::IoStream& UF_API_CALL uf::IoStream::Color::Manip1::operator<<( const std::string& name ) { +uf::IoStream& UF_API_CALL uf::IoStream::Color::Manip1::operator<<( const uf::stl::string& name ) { this->io.setColor(name); return this->io; } // manip via function call -UF_API_CALL uf::IoStream::Color::Manip2::Manip2( const std::string& _name ) : name(_name) {} -uf::IoStream::Color::Manip2 UF_API_CALL uf::IoStream::Color::operator()( const std::string& name ) const { +UF_API_CALL uf::IoStream::Color::Manip2::Manip2( const uf::stl::string& _name ) : name(_name) {} +uf::IoStream::Color::Manip2 UF_API_CALL uf::IoStream::Color::operator()( const uf::stl::string& name ) const { return uf::IoStream::Color::Manip2(name); } -uf::IoStream& UF_API_CALL uf::IoStream::Color::operator()( uf::IoStream& io, const std::string& name ) const { +uf::IoStream& UF_API_CALL uf::IoStream::Color::operator()( uf::IoStream& io, const uf::stl::string& name ) const { io.setColor(name); return io; } diff --git a/engine/src/utils/math/collider.cpp b/engine/src/utils/math/collider.cpp index e5db8fe1..d29ba2b3 100644 --- a/engine/src/utils/math/collider.cpp +++ b/engine/src/utils/math/collider.cpp @@ -28,19 +28,19 @@ std::size_t UF_API uf::Collider::getSize() const { return this->m_container.size(); } -std::vector UF_API uf::Collider::intersects( const uf::Collider& body, bool smart ) const { - std::vector manifolds; +uf::stl::vector UF_API uf::Collider::intersects( const uf::Collider& body, bool smart ) const { + uf::stl::vector manifolds; manifolds.reserve( this->m_container.size() * body.m_container.size() ); for ( const pod::Collider* pointer : body.m_container ) { - std::vector result = this->intersects( *pointer, smart ); + uf::stl::vector result = this->intersects( *pointer, smart ); manifolds.insert( manifolds.end(), result.begin(), result.end() ); } return manifolds; } -std::vector UF_API uf::Collider::intersects( const pod::Collider& body, bool smart ) const { +uf::stl::vector UF_API uf::Collider::intersects( const pod::Collider& body, bool smart ) const { // smart = false; - std::vector manifolds; + uf::stl::vector manifolds; for ( const pod::Collider* pointer : this->m_container ) { pod::Collider::Manifold& manifold = manifolds.emplace_back(); if ( !pointer ) continue; diff --git a/engine/src/utils/math/collision/boundingbox.cpp b/engine/src/utils/math/collision/boundingbox.cpp index 36bd562e..d0805843 100644 --- a/engine/src/utils/math/collision/boundingbox.cpp +++ b/engine/src/utils/math/collision/boundingbox.cpp @@ -65,7 +65,7 @@ pod::Vector3 uf::BoundingBox::closest( const pod::Vector3f& point ) const { return vector; } -std::string UF_API uf::BoundingBox::type() const { return "BoundingBox"; } +uf::stl::string UF_API uf::BoundingBox::type() const { return "BoundingBox"; } pod::Vector3* UF_API uf::BoundingBox::expand() const { pod::Vector3* raw = new pod::Vector3[8]; raw[0] = pod::Vector3{ this->m_corner.x, this->m_corner.y, this->m_corner.z}; diff --git a/engine/src/utils/math/collision/gjk.cpp b/engine/src/utils/math/collision/gjk.cpp index 1555ce11..009054c7 100644 --- a/engine/src/utils/math/collision/gjk.cpp +++ b/engine/src/utils/math/collision/gjk.cpp @@ -19,7 +19,7 @@ void pod::Simplex::set( const pod::Vector3& b, const pod::Vector3& c, const pod: } */ pod::Collider::~Collider(){} -std::string UF_API pod::Collider::type() const { return ""; } +uf::stl::string UF_API pod::Collider::type() const { return ""; } pod::Collider::Manifold UF_API pod::Collider::intersects( const pod::Collider& y ) const { const pod::Collider& x = *this; @@ -165,8 +165,8 @@ EPA: manifold.depth = 0.0f; manifold.normal = { 0, 0, 0 }; - std::vector triangles; - std::vector edges; + uf::stl::vector triangles; + uf::stl::vector edges; triangles.emplace_back( a, simplex.b, simplex.c ); triangles.emplace_back( a, simplex.b, simplex.d ); @@ -186,7 +186,7 @@ EPA: while ( iterations++ < iterations_cap ) { // find closest triangle to origin struct { - std::vector::iterator it; + uf::stl::vector::iterator it; float distance = 9E9; pod::Simplex::SupportPoint support; } closest = { triangles.begin() }; diff --git a/engine/src/utils/math/collision/mesh.cpp b/engine/src/utils/math/collision/mesh.cpp index e165f9a1..d72db1a3 100644 --- a/engine/src/utils/math/collision/mesh.cpp +++ b/engine/src/utils/math/collision/mesh.cpp @@ -1,19 +1,19 @@ #include -uf::MeshCollider::MeshCollider( const pod::Transform<>& transform, const std::vector& positions ) : m_positions(positions) { +uf::MeshCollider::MeshCollider( const pod::Transform<>& transform, const uf::stl::vector& positions ) : m_positions(positions) { this->setTransform(transform); } -std::string UF_API uf::MeshCollider::type() const { return "Mesh"; } +uf::stl::string UF_API uf::MeshCollider::type() const { return "Mesh"; } -std::vector& uf::MeshCollider::getPositions() { +uf::stl::vector& uf::MeshCollider::getPositions() { return this->m_positions; } -const std::vector& uf::MeshCollider::getPositions() const { +const uf::stl::vector& uf::MeshCollider::getPositions() const { return this->m_positions; } -void uf::MeshCollider::setPositions( const std::vector& positions ) { +void uf::MeshCollider::setPositions( const uf::stl::vector& positions ) { this->m_positions = positions; } diff --git a/engine/src/utils/math/collision/modular.cpp b/engine/src/utils/math/collision/modular.cpp index 97b39242..721f90f0 100644 --- a/engine/src/utils/math/collision/modular.cpp +++ b/engine/src/utils/math/collision/modular.cpp @@ -10,7 +10,7 @@ UF_API uf::ModularCollider::ModularCollider( uint len, pod::Vector3* container, UF_API uf::ModularCollider::~ModularCollider() { if ( this->m_container != NULL && this->m_should_free ) delete[] this->m_container; } -std::string UF_API uf::ModularCollider::type() const { return "Modular"; } +uf::stl::string UF_API uf::ModularCollider::type() const { return "Modular"; } void UF_API uf::ModularCollider::setExpand( const uf::ModularCollider::function_expand_t& expand ) { this->m_function_expand = expand; } diff --git a/engine/src/utils/math/collision/sphere.cpp b/engine/src/utils/math/collision/sphere.cpp index 5501458c..9f0de556 100644 --- a/engine/src/utils/math/collision/sphere.cpp +++ b/engine/src/utils/math/collision/sphere.cpp @@ -4,7 +4,7 @@ UF_API uf::SphereCollider::SphereCollider( float r, const pod::Vector3& origin ) this->m_radius = r; this->m_origin = origin; } -std::string UF_API uf::SphereCollider::type() const { return "Sphere"; } +uf::stl::string UF_API uf::SphereCollider::type() const { return "Sphere"; } float UF_API uf::SphereCollider::getRadius() const { return this->m_radius; } diff --git a/engine/src/utils/math/rayt.cpp b/engine/src/utils/math/rayt.cpp index 4049f640..e083e8f7 100644 --- a/engine/src/utils/math/rayt.cpp +++ b/engine/src/utils/math/rayt.cpp @@ -5,10 +5,10 @@ // compile-time assert to ensure objects are of same size, if using multiple types of objects // takes a vector of primitives and groups them under leaves (end point of a tree) -std::vector UF_API uf::primitive::populate( const std::vector& cubes ) { // assert(cubes.size() > 0); - std::vector trees; - std::vector copy; - std::vector alloced; +uf::stl::vector UF_API uf::primitive::populate( const uf::stl::vector& cubes ) { // assert(cubes.size() > 0); + uf::stl::vector trees; + uf::stl::vector copy; + uf::stl::vector alloced; copy.reserve( cubes.size() ); // std::cout << "Size: " << cubes.size() << std::endl; for ( const auto& cube : cubes ) { @@ -78,11 +78,11 @@ std::vector UF_API uf::primitive::populate( const std::vector UF_API uf::primitive::populateEntirely( const std::vector& trees, bool rooted ) { // assert(trees.size() > 0); +uf::stl::vector UF_API uf::primitive::populateEntirely( const uf::stl::vector& trees, bool rooted ) { // assert(trees.size() > 0); // generate first layer - std::vector tree = trees; - std::vector referred; - std::vector queue; + uf::stl::vector tree = trees; + uf::stl::vector referred; + uf::stl::vector queue; uint32_t iteration = 0; uint32_t start = 0; /* @@ -119,7 +119,7 @@ loop: { } // std::cout << std::endl; // grab the branches' primitives - std::vector enqueued; enqueued.reserve( queue.size() ); + uf::stl::vector enqueued; enqueued.reserve( queue.size() ); for ( uint32_t i : queue ) { pod::Tree t = tree.at(i); pod::Primitive primitive; @@ -129,7 +129,7 @@ loop: { enqueued.push_back( primitive ); } // create a parent tree - std::vector newTree = populate( enqueued ); + uf::stl::vector newTree = populate( enqueued ); // convert indices and type for ( auto& branch : newTree ) { branch.type = pod::Primitive::TREE; @@ -264,7 +264,7 @@ namespace { } } -void uf::primitive::test( const std::vector& cubes, const std::vector& trees ) { +void uf::primitive::test( const uf::stl::vector& cubes, const uf::stl::vector& trees ) { pod::Vector3f rayO = { 0, 5, 0 }; pod::Vector3f rayD = uf::vector::normalize( pod::Vector3f{ 0, -1, -0.25 } ); pod::Vector3f rayDRecip = { 1.0f / rayD.x, 1.0f / rayD.y, 1.0f / rayD.z }; diff --git a/engine/src/utils/memory/allocator.cpp b/engine/src/utils/memory/allocator.cpp new file mode 100644 index 00000000..1e5d121b --- /dev/null +++ b/engine/src/utils/memory/allocator.cpp @@ -0,0 +1,13 @@ +#include +#include + + +bool uf::allocator::useMemoryPool = false; +void* uf::allocator::allocate( size_t n ) { + return uf::allocator::useMemoryPool && uf::memoryPool::global.size() > 0 ? uf::memoryPool::global.alloc( nullptr, n ) : ::operator new( n ); +} + +void uf::allocator::deallocate( void* p, size_t n ) { + if ( uf::allocator::useMemoryPool && uf::memoryPool::global.size() > 0 ) uf::memoryPool::global.free( p ); + else ::operator delete(p); +} \ No newline at end of file diff --git a/engine/src/utils/memory/pool.cpp b/engine/src/utils/memory/pool.cpp new file mode 100644 index 00000000..9ce71597 --- /dev/null +++ b/engine/src/utils/memory/pool.cpp @@ -0,0 +1,327 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define UF_MEMORYPOOL_MUTEX 1 +#define UF_MEMORYPOOL_FETCH_STL_FIND 1 +#define UF_MEMORYPOOL_LAZY 1 +#define UF_MEMORYPOOL_CACHED_ALLOCATIONS 0 +#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE_DEPRECATED 0 + +#if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE_DEPRECATED +namespace { + uf::ThreadUnique globalOverrides; +} +#endif + +#define DEBUG_PRINT 0 +#if DEBUG_PRINT + #define UF_MSG_CONDITIONAL_PRINT(...) UF_MSG_DEBUG(__VA_ARGS__) +#else + #define UF_MSG_CONDITIONAL_PRINT(...) +#endif + +bool uf::memoryPool::globalOverride = true; +bool uf::memoryPool::subPool = true; +uint8_t uf::memoryPool::alignment = 64; +uf::MemoryPool uf::memoryPool::global; + +size_t uf::memoryPool::size( const pod::MemoryPool& pool ) { + return pool.size; +} +size_t uf::memoryPool::allocated( const pod::MemoryPool& pool ) { + size_t allocated = 0; + for ( auto& allocation : pool.allocations ) allocated += allocation.size; + return allocated; +} +uf::stl::string uf::memoryPool::stats( const pod::MemoryPool& pool ) { + uf::Serializer metadata; + + size_t size = uf::memoryPool::size( pool ); + size_t allocated = uf::memoryPool::allocated( pool ); + + metadata["size"] = size; + metadata["used"] = allocated; + metadata["free"] = size - allocated; + metadata["objects"] = pool.allocations.size(); + { + uf::stl::stringstream ss; ss << std::hex << (void*) pool.pool; + metadata["pool"] = ss.str(); + } + + return metadata; +} +void uf::memoryPool::initialize( pod::MemoryPool& pool, size_t size ) { + if ( size <= 0 ) return; + + if ( uf::memoryPool::size( pool ) > 0 ) uf::memoryPool::destroy( pool ); + pool.size = size; + + if ( uf::memoryPool::subPool && uf::memoryPool::global.size() > 0 && &pool != &uf::memoryPool::global.data() ) { + pool.pool = (uint8_t*) uf::memoryPool::global.alloc( nullptr, size ); + } else { + pool.pool = (uint8_t*) malloc( size ); + } + UF_ASSERT( pool.pool ); + memset( pool.pool, 0, size ); +} +void uf::memoryPool::destroy( pod::MemoryPool& pool ) { + if ( uf::memoryPool::size( pool ) <= 0 ) return; + if ( uf::memoryPool::subPool && &pool != &uf::memoryPool::global.data() ) { + uf::memoryPool::global.free( pool.pool ); + } else { + delete[] pool.pool; + } + pool.size = 0; + pool.pool = NULL; +} + +pod::Allocation uf::memoryPool::allocate( pod::MemoryPool& pool, void* data, size_t size, size_t alignment ) { +// alignment = MIN( alignment, uf::memoryPool::alignment ); +// alignment = uf::memoryPool::alignment; +#if UF_MEMORYPOOL_MUTEX + pool.mutex.lock(); +#endif + // find next available allocation + size_t index = 0; + size_t len = uf::memoryPool::size( pool ); + pod::Allocation allocation; + // pool not initialized + if ( len <= 0 ) { + UF_MSG_ERROR("cannot malloc, pool not initialized: " << size); + goto MANUAL_MALLOC; + } + + // an optimization by quickly reusing freed allocations seemed like a good idea + // but still have to iterate through allocation information + // to keep allocation information in order + + // check our cache of first +#if UF_MEMORYPOOL_CACHED_ALLOCATIONS + if ( !pool.cachedFreeAllocations.empty() ) { + auto it = pool.cachedFreeAllocations.begin(); + // check if any recently freed allocation is big enough for our new allocation + for ( ; it != pool.cachedFreeAllocations.end(); ++it ) { + // is aligned + if ( 0 < alignment && !uf::aligned( &pool.pool[0] + it->index, alignment ) ) continue; + // sized adequately + if ( it->size < size ) break; + } + // found a suitable allocation, use it + if ( it != pool.cachedFreeAllocations.end() ) { + index = it->index; + // find where to insert in our allocation table + auto next = pool.allocations.begin(); + while ( next != pool.allocations.end() ) { + if ( index + size < next->index ) break; + ++next; + } + // check if it was actually valid + if ( next != pool.allocations.end() ) { + // remove from cache + pool.cachedFreeAllocations.erase(it); + + // initialize allocation info + allocation.index = index; + allocation.size = size; + allocation.pointer = &pool.pool[0] + index; + + // security + if ( data ) memcpy( allocation.pointer, data, size ); + else memset( allocation.pointer, 0, size ); + + // overrides if we're overloading global new/delete + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE_DEPRECATED + globalOverrides.get() = true; + #endif + // register as allocated + pool.allocations.insert(next, allocation); + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE_DEPRECATED + globalOverrides.get() = false; + #endif + + goto RETURN; + } + } + } +#endif + { + // find any availble spots in-between existing allocations + auto next = pool.allocations.begin(); + size_t alignedSize = size; + for ( auto it = next; it != pool.allocations.end(); ++it ) { + // point to end of allocation + index = it->index + it->size; + // realign our index if requested + if ( 0 < alignment ) { + uintptr_t a = uf::alignment( &pool.pool[0] + index, alignment ); + uintptr_t o = a == 0 ? 0 : alignment - a; + index += o; + } + // hit the end of our allocations, break + if ( ++next == pool.allocations.end() ) break; + // target index is behind next allocated space, use it + if ( index < next->index ) break; + } + // no allocation found, OOM + if ( index + size > len ) { + UF_MSG_ERROR("MemoryPool: " << &pool << ": Out of Memory!"); + UF_MSG_ERROR("Trying to request " << size << " bytes of memory"); + UF_MSG_ERROR("Stats: " << uf::memoryPool::stats( pool )); + goto MANUAL_MALLOC; + } + + // initialize allocation info + allocation.index = index; + allocation.size = size; + allocation.pointer = &pool.pool[0] + index; + + // security + if ( data ) memcpy( allocation.pointer, data, size ); + else memset( allocation.pointer, 0, size ); + + // overrides if we're overloading global new/delete + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE_DEPRECATED + globalOverrides.get() = true; + #endif + // register as allocated + pool.allocations.insert(next, allocation); + #if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE_DEPRECATED + globalOverrides.get() = false; + #endif + } + goto RETURN; +MANUAL_MALLOC: +#if UF_MEMORYPOOL_INVALID_MALLOC + allocation.index = -1; + allocation.size = size; + allocation.pointer = malloc(size); +#else + UF_EXCEPTION("invalid malloc"); +#endif +RETURN: +#if UF_MEMORYPOOL_MUTEX + pool.mutex.unlock(); +#endif + UF_MSG_CONDITIONAL_PRINT("malloc'd: " << allocation.pointer << ", " << allocation.size << ", " << allocation.index); +// UF_ASSERT(allocation.pointer); + return allocation; +} +void* uf::memoryPool::alloc( pod::MemoryPool& pool, void* data, size_t size, size_t alignment ) { + auto allocation = uf::memoryPool::allocate( pool, data, size, alignment ); + return allocation.pointer; +} + +pod::Allocation& uf::memoryPool::fetch( pod::MemoryPool& pool, size_t index, size_t size ) { + static pod::Allocation missing; +#if UF_MEMORYPOOL_FETCH_STL_FIND + auto it = std::find_if( pool.allocations.begin(), pool.allocations.end(), [index, size]( const pod::Allocation& a ){ + return index == a.index && ((size > 0 && a.size == size) || (size == 0)); + }); + return it != pool.allocations.end() ? *it : missing; +#else + for ( auto& allocation : pool.allocations ) { + if ( index == allocation.index && ((size > 0 && allocation.size == size) || (size == 0)) ) return allocation; + } + return missing; +#endif +} +bool uf::memoryPool::exists( pod::MemoryPool& pool, void* pointer, size_t size ) { + // bound check +#if UF_MEMORYPOOL_LAZY +// return &pool.pool[0] <= pointer && &pool.pool[0] + pool.size < pointer + size; + if ( pointer < &pool.pool[0] ) return false; + if ( &pool.pool[0] + pool.size < pointer - size ) return false; + return true; +#else +// if ( !(&pool.pool[0] <= pointer && &pool.pool[0] + pool.size < pointer + size) ) return false; + if ( pointer < &pool.pool[0] ) return false; + if ( &pool.pool[0] + pool.size < pointer - size ) return false; + size_t index = (uint8_t*) pointer - &pool.pool[0]; + // size check + auto& allocation = uf::memoryPool::fetch( pool, index, size ); + return allocation.index == index && ((size > 0 && allocation.size == size) || (size == 0)); +#endif +} +bool uf::memoryPool::free( pod::MemoryPool& pool, void* pointer, size_t size ) { + // passed a NULL, for some reason + if ( !pointer ) return false; +#if UF_MEMORYPOOL_MUTEX + pool.mutex.lock(); +#endif + // fail if uninitialized or pointer is outside of our pool + if ( pool.size <= 0 || pointer < &pool.pool[0] || pointer >= &pool.pool[0] + pool.size ) { + UF_MSG_ERROR("cannot free: " << pointer << " | " << (pool.size <= 0) << " " << (pointer < &pool.pool[0]) << " " << (pointer >= &pool.pool[0] + pool.size)); + goto MANUAL_FREE; + } + { + // pointer arithmatic + size_t index = (uint8_t*) pointer - &pool.pool[0]; + auto it = pool.allocations.begin(); + pod::Allocation allocation; + // find our allocation in the allocation pool + for ( ; it != pool.allocations.end(); ++it ) { + if ( it->index != index ) continue; + allocation = *it; + break; + } + // pointer isn't actually allocated + if ( allocation.index != index ) { + UF_MSG_ERROR("cannot free, allocation not found: " << pointer); + goto MANUAL_FREE; + } + // size validation mismatch, do not free + if (size > 0 && allocation.size != size) { + UF_MSG_ERROR("cannot free, mismatched sized: " << pointer << " (" << size << " != " << allocation.size << ")"); + goto MANUAL_FREE; + } + UF_MSG_CONDITIONAL_PRINT("freed allocation: " << pointer << ", " << size << "\t" << allocation.pointer << ", " << allocation.size << ", " << allocation.index); + // remove from our allocation table... + pool.allocations.erase(it); + // ...but add it to our freed allocation cache + #if UF_MEMORYPOOL_CACHED_ALLOCATIONS + pool.cachedFreeAllocations.push_back(allocation); + #endif + #if UF_MEMORYPOOL_MUTEX + pool.mutex.unlock(); + #endif + return true; + } +MANUAL_FREE: +#if UF_MEMORYPOOL_MUTEX + pool.mutex.unlock(); +#endif +#if UF_MEMORYPOOL_INVALID_FREE + ::free(pointer); +#endif + return false; +} + +const pod::MemoryPool::allocations_t& uf::memoryPool::allocations( const pod::MemoryPool& pool ) { + return pool.allocations; +} +// +uf::MemoryPool::MemoryPool( size_t size ) { + if ( size > 0 ) this->initialize( size ); +} +uf::MemoryPool::~MemoryPool( ) { + this->destroy(); +} +// +#if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE +void* operator new( size_t n ) { + return uf::allocator::useMemoryPool && uf::memoryPool::global.size() > 0 ? uf::memoryPool::global.alloc( nullptr, n ) : malloc( n ); +} +void operator delete( void* p ) { + if ( uf::allocator::useMemoryPool && uf::memoryPool::global.size() > 0 ) uf::memoryPool::global.free( p ); + else free(p); +} +#endif \ No newline at end of file diff --git a/engine/src/utils/mempool/mempool.cpp b/engine/src/utils/mempool/mempool.cpp deleted file mode 100644 index 0b744d02..00000000 --- a/engine/src/utils/mempool/mempool.cpp +++ /dev/null @@ -1,321 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace { - uf::ThreadUnique globalOverrides; -} - -#define DEBUG_PRINT 0 - -bool uf::MemoryPool::globalOverride = true; -bool uf::MemoryPool::subPool = true; -uf::MemoryPool uf::MemoryPool::global; - -uf::MemoryPool::MemoryPool( size_t size ) { - if ( size > 0 ) this->initialize( size ); -} -uf::MemoryPool::~MemoryPool( ) { - this->destroy(); -} -size_t uf::MemoryPool::size() const { - return this->m_size; -} -size_t uf::MemoryPool::allocated() const { - size_t allocated = 0; - for ( auto& allocation : this->m_allocations ) { - allocated += allocation.size; - } - return allocated; -} -std::string uf::MemoryPool::stats() const { - uf::Serializer metadata; - - size_t size = this->size(); - size_t allocated = this->allocated(); - - metadata["size"] = size; - metadata["used"] = allocated; - metadata["free"] = size - allocated; - metadata["objects"] = this->m_allocations.size(); - { - std::stringstream ss; ss << std::hex << (void*) this->m_pool; - metadata["pool"] = ss.str(); - } - - return metadata; -} -void uf::MemoryPool::initialize( size_t size ) { - if ( size <= 0 ) return; - if ( this->size() > 0 ) this->destroy(); - this->m_size = size; - if ( uf::MemoryPool::subPool && uf::MemoryPool::global.size() > 0 && this != &uf::MemoryPool::global ) { - this->m_pool = (uint8_t*) uf::MemoryPool::global.alloc( NULL, size ); - } else { - this->m_pool = (uint8_t*) malloc( size ); - } - memset( this->m_pool, 0, size ); -} -void uf::MemoryPool::destroy() { - if ( this->size() <= 0 ) return; - if ( uf::MemoryPool::subPool && this != &uf::MemoryPool::global ) { - uf::MemoryPool::global.free( this->m_pool ); - } else { - delete[] this->m_pool; - } - this->m_size = 0; - this->m_pool = NULL; -} - -pod::Allocation uf::MemoryPool::allocate( void* data, size_t size ) { - if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.lock(); - // find next available allocation - size_t index = 0; - size_t len = this->size(); - pod::Allocation allocation; - // pool not initialized - if ( len <= 0 ) { - if ( DEBUG_PRINT ) UF_MSG_DEBUG("CANNOT MALLOC: " << size << ", POOL NOT INITIALIZED"); - goto MANUAL_MALLOC; - } - - // an optimization by quickly reusing free'd allocations seemed like a good idea - // but still have to iterate through allocation information - // to keep allocation information in order - - // check our cache of first -#if UF_MEMORYPOOL_CACHED_ALLOCATIONS - if ( !this->m_cachedFreeAllocations.empty() ) { - auto it = this->m_cachedFreeAllocations.begin(); - // check if any recently free'd allocation is big enough for our new allocation - for ( ; it != this->m_cachedFreeAllocations.end(); ++it ) { - if ( it->size < size ) break; - } - // found a suitable allocation, use it - if ( it != this->m_cachedFreeAllocations.end() ) { - index = it->index; - // find where to insert in our allocation table - auto next = this->m_allocations.begin(); - while ( next != this->m_allocations.end() ) { - if ( index + size < next->index ) break; - ++next; - } - // check if it was actually valid - if ( next != this->m_allocations.end() ) { - // initialize allocation info - allocation.index = index; - allocation.size = size; - allocation.pointer = &this->m_pool[0] + index; - - // security - if ( data ) memcpy( allocation.pointer, data, size ); - else memset( allocation.pointer, 0, size ); - - // overrides if we're overloading global new/delete - globalOverrides.get() = true; - // register as allocated - this->m_allocations.insert(next, allocation); - globalOverrides.get() = false; - - goto RETURN; - } - // remove from cache - this->m_cachedFreeAllocations.erase(it); - } - } -#endif - { - // find any availble spots in-between existing allocations - auto next = this->m_allocations.begin(); - for ( auto it = next; it != this->m_allocations.end(); ++it ) { - index = it->index + it->size; - if ( ++next == this->m_allocations.end() ) break; - // target index is behind next allocated space, use it - if ( index < next->index ) break; - } - // no allocation found, OOM - if ( index + size > len ) { - UF_MSG_DEBUG("MemoryPool: " << this << ": Out of Memory!"); - UF_MSG_DEBUG("Trying to request " << size << " bytes of memory"); - UF_MSG_DEBUG("Stats: " << this->stats()); - goto MANUAL_MALLOC; - } - - // initialize allocation info - allocation.index = index; - allocation.size = size; - allocation.pointer = &this->m_pool[0] + index; - - // security - if ( data ) memcpy( allocation.pointer, data, size ); - else memset( allocation.pointer, 0, size ); - - // overrides if we're overloading global new/delete - globalOverrides.get() = true; - // register as allocated - this->m_allocations.insert(next, allocation); - globalOverrides.get() = false; - } - goto RETURN; -MANUAL_MALLOC: - if ( UF_MEMORYPOOL_INVALID_MALLOC ) { - allocation.index = -1; - allocation.size = size; - allocation.pointer = malloc(size); - } else { - UF_EXCEPTION("INVALID MALLOC"); - } -RETURN: - if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.unlock(); - if ( DEBUG_PRINT ) UF_MSG_DEBUG("MALLOC'd: " << allocation.pointer << ", " << allocation.size << ", " << allocation.index); - return allocation; -} -void* uf::MemoryPool::alloc( void* data, size_t size ) { - auto allocation = this->allocate( data, size ); - return allocation.pointer; -} - -pod::Allocation& uf::MemoryPool::fetch( size_t index, size_t size ) { - static pod::Allocation missing; - for ( auto& allocation : this->m_allocations ) { - if ( index == allocation.index ) { - if ( (size > 0 && allocation.size == size) || (size == 0) ) return allocation; - } - } - return missing; -} -bool uf::MemoryPool::exists( void* pointer, size_t size ) { - // bound check - if ( pointer < &this->m_pool[0] ) return false; - size_t index = (uint8_t*) pointer - &this->m_pool[0]; - // size check - if ( size > 0 ) { - auto& allocation = this->fetch( index, size ); - return allocation.index == index && allocation.size == size; - } - return true; -} -bool uf::MemoryPool::free( void* pointer, size_t size ) { - if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.lock(); - // fail if uninitialized or pointer is outside of our pool - if ( this->m_size <= 0 || pointer < &this->m_pool[0] || pointer >= &this->m_pool[0] + this->m_size ) { - if ( DEBUG_PRINT ) UF_MSG_DEBUG("CANNOT FREE: " << pointer << ", ERROR: " << (this->m_size <= 0) << " " << (pointer < &this->m_pool[0]) << " " << (pointer >= &this->m_pool[0] + this->m_size)); - goto MANUAL_FREE; - } - { - // pointer arithmatic - size_t index = (uint8_t*) pointer - &this->m_pool[0]; - auto it = this->m_allocations.begin(); - pod::Allocation allocation; - // find our allocation in the allocation pool - for ( ; it != this->m_allocations.end(); ++it ) { - if ( it->index == index ) { - allocation = *it; - break; - } - } - // pointer isn't actually allocated - if ( allocation.index != index ) { - if ( DEBUG_PRINT ) UF_MSG_DEBUG("CANNOT FREE: " << pointer << ", NOT FOUND"); - goto MANUAL_FREE; - } - // size validation mismatch, do not free - if (size > 0 && allocation.size != size) { - if ( DEBUG_PRINT ) UF_MSG_DEBUG("CANNOT FREE: " << pointer << ", MISMATCHED SIZES (" << size << " != " << allocation.size << ")"); - goto MANUAL_FREE; - } - if ( DEBUG_PRINT ) UF_MSG_DEBUG("FREE'D ALLOCATION: " << pointer << ", " << size << "\t" << allocation.pointer << ", " << allocation.size << ", " << allocation.index); - // remove from our allocation table... - this->m_allocations.erase(it); - // ...but add it to our free'd allocation cache -#if UF_MEMORYPOOL_CACHED_ALLOCATIONS - this->m_cachedFreeAllocations.push_back(allocation); -#endif - if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.unlock(); - return true; - } -MANUAL_FREE: - if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.unlock(); - if ( UF_MEMORYPOOL_INVALID_FREE ) ::free(pointer); - return false; -} - -const uf::MemoryPool::allocations_t& uf::MemoryPool::allocations() const { - return this->m_allocations; -} -#if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE -void* operator new( size_t size ) { - if ( !uf::MemoryPool::globalOverride || globalOverrides.get() || uf::MemoryPool::global.size() <= 0 ) - return malloc(size); - return uf::MemoryPool::global.alloc( (void*) NULL, size ); -} -void operator delete( void* pointer ) { - if ( !uf::MemoryPool::globalOverride ) return ::free( pointer ); - uf::MemoryPool::global.free( pointer ); -} -#endif -/* -uf::MemoryPool::Iterator uf::MemoryPool::begin() { - static pod::Allocation end; - end = { - .index = 0 - .size = 0, - .pointer = this->m_pool - }; - struct { - pod::Allocation* begin = NULL; - pod::Allocation* end = NULL; - pod::Allocation* next = NULL; - } pointers; - pointers.begin = &end; - pointers.end = &end; - pointers.prev = &end; - - if ( this->m_allocations.size() > 0 ) { - auto it = this->m_allocations.begin(); - pointers.begin = &(*it++); - if ( it != this->m_allocations.end() ) - pointers.next = &(*it); - } - - return { - .pool = *this, - .allocation = *pointers.begin, - .prev = *pointers.end, - .next = *pointers.next - }; -} -uf::MemoryPool::Iterator uf::MemoryPool::end() { - static pod::Allocation end; - end = { - .index = this->m_size, - .size = this->m_size, - .pointer = this->m_pool + this->m_size; - } - struct { - pod::Allocation* end = NULL; - pod::Allocation* prev = NULL; - } pointers; - - if ( this->m_allocations.size() > 0 ) { - auto it = this->m_allocations.begin(); - pointers.end = &(*it++); - if ( it != this->m_allocations.end() ) - pointers.prev = &(*it); - } - pointers.prev = &end; - - return { - .pool = *this, - .allocation = *pointers.end, - .prev = *pointers.prev, - .next = *pointers.end - }; -} -*/ \ No newline at end of file diff --git a/engine/src/utils/mesh/grid.cpp b/engine/src/utils/mesh/grid.cpp index c5da4bd4..f40b0ca6 100644 --- a/engine/src/utils/mesh/grid.cpp +++ b/engine/src/utils/mesh/grid.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -29,9 +29,9 @@ void uf::MeshGrid::destroy() { #if 0 for ( auto& node : this->m_nodes ) { #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool::global.free( node.indices ); + uf::memoryPool::global.free( node.indices ); #else - uf::MemoryPool* memoryPool = uf::MemoryPool::global.size() > 0 ? &uf::MemoryPool::global : NULL; + uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; if ( memoryPool ) memoryPool->free( node.indices ); else free( node.indices ); #endif @@ -48,9 +48,9 @@ void uf::MeshGrid::allocate( uf::MeshGrid::Node& node, size_t indices ) { uint32_t* buffer = NULL; #if UF_MEMORYPOOL_INVALID_MALLOC - buffer = (void*) uf::MemoryPool::global.alloc( data, size ); + buffer = (void*) uf::memoryPool::global.alloc( data, size ); #else - uf::MemoryPool* memoryPool = uf::MemoryPool::global.size() > 0 ? &uf::MemoryPool::global : NULL; + uf::MemoryPool* memoryPool = uf::memoryPool::global.size() > 0 ? &uf::memoryPool::global : NULL; if ( memoryPool ) buffer = (void*) memoryPool->alloc( data, size ); else { diff --git a/engine/src/utils/noise/perlin.cpp b/engine/src/utils/noise/perlin.cpp index 085ed72f..d39bdd4a 100644 --- a/engine/src/utils/noise/perlin.cpp +++ b/engine/src/utils/noise/perlin.cpp @@ -72,8 +72,8 @@ double uf::PerlinNoise::grad(int hash, double x, double y, double z) const { v = h < 4 ? y : h == 12 || h == 14 ? x : z; return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } -std::vector uf::PerlinNoise::collect( uint size, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { - std::vector res; +uf::stl::vector uf::PerlinNoise::collect( uint size, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { + uf::stl::vector res; res.reserve( size ); for(unsigned int i = 0; i < size; ++i) { // x double x = (double)i/((double)size); @@ -84,8 +84,8 @@ std::vector uf::PerlinNoise::collect( uint size, const pod::Vector3d& no } return res; } -std::vector uf::PerlinNoise::collect( const pod::Vector2ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { - std::vector res; +uf::stl::vector uf::PerlinNoise::collect( const pod::Vector2ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { + uf::stl::vector res; res.reserve( size.x * size.y ); for(unsigned int i = 0; i < size.y; ++i) { // y for(unsigned int j = 0; j < size.x; ++j) { // x @@ -99,8 +99,8 @@ std::vector uf::PerlinNoise::collect( const pod::Vector2ui& size, const } return res; } -std::vector uf::PerlinNoise::collect( const pod::Vector3ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { - std::vector res; +uf::stl::vector uf::PerlinNoise::collect( const pod::Vector3ui& size, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { + uf::stl::vector res; res.reserve( size.x * size.y * size.z ); for(unsigned int Z = 0; Z < size.z; ++Z) { // z for(unsigned int Y = 0; Y < size.y; ++Y) { // y @@ -119,14 +119,14 @@ std::vector uf::PerlinNoise::collect( const pod::Vector3ui& size, const } double uf::PerlinNoise::sample( const pod::Vector3d& position, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { - std::vector res; + uf::stl::vector res; double n = this->noise(noiseCoeff.x * position.x, noiseCoeff.y * position.y, noiseCoeff.z * position.z); callback(n); return n; } double uf::PerlinNoise::sample( const pod::Vector3f& position, const pod::Vector3d& noiseCoeff, const callback_t& callback ) { - std::vector res; + uf::stl::vector res; double n = this->noise(noiseCoeff.x * position.x, noiseCoeff.y * position.y, noiseCoeff.z * position.z); callback(n); return n; diff --git a/engine/src/utils/serialize/serializer.cpp b/engine/src/utils/serialize/serializer.cpp index d8ef78fd..9315ec8d 100644 --- a/engine/src/utils/serialize/serializer.cpp +++ b/engine/src/utils/serialize/serializer.cpp @@ -9,7 +9,7 @@ #include #include -uf::Serializer::Serializer( const std::string& str ) { //: sol::table(ext::lua::state, sol::create) { +uf::Serializer::Serializer( const uf::stl::string& str ) { //: sol::table(ext::lua::state, sol::create) { this->deserialize(str); } #if UF_USE_LUA @@ -31,14 +31,14 @@ uf::Serializer::output_t uf::Serializer::serialize( bool pretty ) const { uf::Serializer::output_t uf::Serializer::serialize( const ext::json::EncodingSettings& settings ) const { return ext::json::encode( *this, settings ); } -void uf::Serializer::deserialize( const std::string& str ) { +void uf::Serializer::deserialize( const uf::stl::string& str ) { if ( str == "" ) return; ext::json::decode( *this, str ); } -bool uf::Serializer::readFromFile( const std::string& filename, const std::string& hash ) { +bool uf::Serializer::readFromFile( const uf::stl::string& filename, const uf::stl::string& hash ) { uf::String string; -// std::string filename = _filename + ( uf::io::exists(_filename + ".gz") ? ".gz" : "" ); +// uf::stl::string filename = _filename + ( uf::io::exists(_filename + ".gz") ? ".gz" : "" ); bool exists = uf::io::exists( filename ); if ( !exists ) { UF_MSG_ERROR("Failed to read JSON file `" << filename << "`: does not exist"); @@ -57,8 +57,8 @@ bool uf::Serializer::readFromFile( const std::string& filename, const std::strin this->deserialize(string); return true; } -bool uf::Serializer::writeToFile( const std::string& filename, const ext::json::EncodingSettings& settings ) const { - std::string buffer = this->serialize( settings ); +bool uf::Serializer::writeToFile( const uf::stl::string& filename, const ext::json::EncodingSettings& settings ) const { + uf::stl::string buffer = this->serialize( settings ); size_t written = uf::io::write( filename + ( settings.compress ? ".gz" : "" ) , buffer.c_str(), buffer.size() ); if ( !written ) UF_MSG_ERROR("Failed to write JSON file `" << filename << "`"); return written; @@ -86,7 +86,7 @@ void uf::Serializer::import( const uf::Serializer& other ) { uf::Serializer diff = nlohmann::json::diff(*this, other); uf::Serializer filtered; for ( size_t i = 0; i < diff.size(); ++i ) { - if ( diff[i]["op"].as() != "remove" ) + if ( diff[i]["op"].as() != "remove" ) filtered.emplace_back(diff[i]); } patch( filtered ); @@ -107,7 +107,7 @@ void uf::Serializer::import( const uf::Serializer& other ) { }; update(*this, other); } -ext::json::Value& uf::Serializer::path( const std::string& path ) { +ext::json::Value& uf::Serializer::path( const uf::stl::string& path ) { auto keys = uf::string::split(path, "."); ext::json::Value* traversal = this; for ( auto& key : keys ) { @@ -123,7 +123,7 @@ uf::Serializer::operator Serializer::output_t() const { return this->serialize(); } -uf::Serializer& uf::Serializer::operator=( const std::string& str ) { +uf::Serializer& uf::Serializer::operator=( const uf::stl::string& str ) { this->deserialize(str); return *this; } @@ -143,15 +143,15 @@ uf::Serializer& uf::Serializer::operator=( const ext::json::base_value& json ) { ext::json::Value::operator=(json); return *this; } -uf::Serializer& uf::Serializer::operator<<( const std::string& str ) { +uf::Serializer& uf::Serializer::operator<<( const uf::stl::string& str ) { this->deserialize(str); return *this; } -uf::Serializer& uf::Serializer::operator>>( std::string& str ) { +uf::Serializer& uf::Serializer::operator>>( uf::stl::string& str ) { str = this->serialize(); return *this; } -const uf::Serializer& uf::Serializer::operator>>( std::string& str ) const { +const uf::Serializer& uf::Serializer::operator>>( uf::stl::string& str ) const { str = this->serialize(); return *this; } \ No newline at end of file diff --git a/engine/src/utils/string/base64.cpp b/engine/src/utils/string/base64.cpp index e6176a67..b7e30b1a 100644 --- a/engine/src/utils/string/base64.cpp +++ b/engine/src/utils/string/base64.cpp @@ -12,7 +12,7 @@ static const int B64index[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 static const uint8_t base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -std::string uf::base64::encode( const uint8_t* src, size_t len ) { +uf::stl::string uf::base64::encode( const uint8_t* src, size_t len ) { uint8_t *out, *pos; const uint8_t *end, *in; @@ -21,9 +21,9 @@ std::string uf::base64::encode( const uint8_t* src, size_t len ) { olen = 4*((len + 2) / 3); if (olen < len) - return std::string(); + return uf::stl::string(); - std::string outStr; + uf::stl::string outStr; outStr.resize(olen); out = (uint8_t*)&outStr[0]; @@ -55,13 +55,13 @@ std::string uf::base64::encode( const uint8_t* src, size_t len ) { return outStr; } -// std::vector uf::base64::decode( const uint8_t* data, size_t len ) { -std::vector uf::base64::decode( const std::string& data ) { +// uf::stl::vector uf::base64::decode( const uint8_t* data, size_t len ) { +uf::stl::vector uf::base64::decode( const uf::stl::string& data ) { size_t len = data.size(); uint8_t* p = (uint8_t*) &data[0]; int pad = len > 0 && (len % 4 || p[len - 1] == '='); const size_t L = ((len + 3) / 4 - pad) * 4; - std::vector str(L / 4 * 3 + pad, '\0'); + uf::stl::vector str(L / 4 * 3 + pad, '\0'); for (size_t i = 0, j = 0; i < L; i += 4) { @@ -84,17 +84,17 @@ std::vector uf::base64::decode( const std::string& data ) { return str; } -std::string uf::string::base64::encode( const std::string& input ) { +uf::stl::string uf::string::base64::encode( const uf::stl::string& input ) { return uf::base64::encode( input ); } -std::string uf::string::base64::decode( const std::string& input ) { +uf::stl::string uf::string::base64::decode( const uf::stl::string& input ) { auto v = uf::base64::decode( input ); - return std::string( v.begin(), v.end() ); + return uf::stl::string( v.begin(), v.end() ); } /* -static const std::string base64_chars = +static const uf::stl::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; @@ -104,8 +104,8 @@ static inline bool is_base64(uint8_t c) { return (isalnum(c) || (c == '+') || (c == '/')); } -std::string uf::base64::encode(const uint8_t* buf, std::size_t bufLen) { - std::string ret; +uf::stl::string uf::base64::encode(const uint8_t* buf, std::size_t bufLen) { + uf::stl::string ret; int i = 0; int j = 0; uint8_t char_array_3[3]; @@ -145,13 +145,13 @@ std::string uf::base64::encode(const uint8_t* buf, std::size_t bufLen) { return ret; } -std::vector uf::base64::decode(const std::string& encoded_string) { +uf::stl::vector uf::base64::decode(const uf::stl::string& encoded_string) { int in_len = encoded_string.size(); int i = 0; int j = 0; int in_ = 0; uint8_t char_array_4[4], char_array_3[3]; - std::vector ret; + uf::stl::vector ret; while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { char_array_4[i++] = encoded_string[in_]; in_++; diff --git a/engine/src/utils/string/ext.cpp b/engine/src/utils/string/ext.cpp index d52bac89..1bec5baf 100644 --- a/engine/src/utils/string/ext.cpp +++ b/engine/src/utils/string/ext.cpp @@ -6,32 +6,32 @@ #include #include -std::string UF_API uf::string::lowercase( const std::string& str ) { - std::string lower = str; +uf::stl::string UF_API uf::string::lowercase( const uf::stl::string& str ) { + uf::stl::string lower = str; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); return lower; } -std::string UF_API uf::string::uppercase( const std::string& str ) { - std::string upper = str; +uf::stl::string UF_API uf::string::uppercase( const uf::stl::string& str ) { + uf::stl::string upper = str; std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper); return upper; } -std::vector UF_API uf::string::split( const std::string& str, const std::string& delim ) { - std::vector tokens; +uf::stl::vector UF_API uf::string::split( const uf::stl::string& str, const uf::stl::string& delim ) { + uf::stl::vector tokens; size_t prev = 0, pos = 0; do { pos = str.find(delim, prev); - if (pos == std::string::npos) pos = str.length(); - std::string token = str.substr(prev, pos-prev); + if (pos == uf::stl::string::npos) pos = str.length(); + uf::stl::string token = str.substr(prev, pos-prev); if (!token.empty()) tokens.push_back(token); prev = pos + delim.length(); } while (pos < str.length() && prev < str.length()); if ( tokens.empty() ) tokens.emplace_back(str); return tokens; /* - std::vector cont; + uf::stl::vector cont; size_t last = 0, next = 0; - while ((next = str.find(needle, last)) != std::string::npos) { + while ((next = str.find(needle, last)) != uf::stl::string::npos) { cont.push_back(str.substr(last, next-last)); last = next + 1; } @@ -40,8 +40,8 @@ std::vector UF_API uf::string::split( const std::string& str, const */ } /* -std::string UF_API uf::string::join( const std::vector& strings, const std::string& delim, bool trailing ) { - std::stringstream ss; +uf::stl::string UF_API uf::string::join( const uf::stl::vector& strings, const uf::stl::string& delim, bool trailing ) { + uf::stl::stringstream ss; size_t len = strings.size(); for ( size_t i = 0; i < len; ++i ) { ss << strings[i]; @@ -50,17 +50,17 @@ std::string UF_API uf::string::join( const std::vector& strings, co return ss.str(); } */ -std::string UF_API uf::string::replace( const std::string& string, const std::string& search, const std::string& replace ) { - std::string result = string; +uf::stl::string UF_API uf::string::replace( const uf::stl::string& string, const uf::stl::string& search, const uf::stl::string& replace ) { + uf::stl::string result = string; size_t start_pos = string.find(search); - if( start_pos == std::string::npos ) return result; + if( start_pos == uf::stl::string::npos ) return result; result.replace(start_pos, search.length(), replace); return result; } -bool UF_API uf::string::contains( const std::string& string, const std::string& search ) { - return string.find(search) != std::string::npos; +bool UF_API uf::string::contains( const uf::stl::string& string, const uf::stl::string& search ) { + return string.find(search) != uf::stl::string::npos; } -std::string UF_API uf::string::si( double value, const std::string& unit, size_t precision ) { +uf::stl::string UF_API uf::string::si( double value, const uf::stl::string& unit, size_t precision ) { int power = floor(std::log10( value )); double base = value / std::pow( 10, power ); @@ -103,9 +103,9 @@ std::string UF_API uf::string::si( double value, const std::string& unit, size_t // std::cout << base << " x 10^" << power << std::endl; - std::stringstream ss; + uf::stl::stringstream ss; ss << std::fixed << std::setprecision(precision) << base; - std::string string = ss.str(); + uf::stl::string string = ss.str(); switch ( power ) { case 24: string += "Y"; break; diff --git a/engine/src/utils/string/rle.cpp b/engine/src/utils/string/rle.cpp index 44542dea..5b4ae3c2 100644 --- a/engine/src/utils/string/rle.cpp +++ b/engine/src/utils/string/rle.cpp @@ -2,7 +2,7 @@ #include #include -pod::RLE::string_t uf::rle::encode( const std::vector& source ) { +pod::RLE::string_t uf::rle::encode( const uf::stl::vector& source ) { pod::RLE::string_t destination; destination.reserve( source.size() ); @@ -16,8 +16,8 @@ pod::RLE::string_t uf::rle::encode( const std::vector& source ) { return destination; } -std::vector uf::rle::decode( const pod::RLE::string_t& source ) { - std::vector destination; +uf::stl::vector uf::rle::decode( const pod::RLE::string_t& source ) { + uf::stl::vector destination; for ( auto& s : source ) { destination.reserve( destination.size() + s.length ); @@ -28,7 +28,7 @@ std::vector uf::rle::decode( const pod::RLE::string_t& source ) { return destination; } -pod::RLE::string_t uf::rle::wrap( const std::vector& source ) { +pod::RLE::string_t uf::rle::wrap( const uf::stl::vector& source ) { pod::RLE::string_t destination; destination.reserve( source.size() / 2 ); @@ -46,8 +46,8 @@ pod::RLE::string_t uf::rle::wrap( const std::vector& source ) { return destination; } -std::vector uf::rle::unwrap( const pod::RLE::string_t& source ) { - std::vector destination; +uf::stl::vector uf::rle::unwrap( const pod::RLE::string_t& source ) { + uf::stl::vector destination; destination.reserve( source.size() * 2 ); for ( auto& s : source ) { destination.push_back( s.length ); diff --git a/engine/src/utils/string/string.cpp b/engine/src/utils/string/string.cpp index c7f8fad4..955c3cdd 100644 --- a/engine/src/utils/string/string.cpp +++ b/engine/src/utils/string/string.cpp @@ -1,7 +1,7 @@ #include #include //uf::String uf::locale::current; -std::string uf::locale::current; +uf::stl::string uf::locale::current; UF_API_CALL uf::String::String() { } // ANSI literals/strings @@ -186,11 +186,11 @@ uf::String& UF_API_CALL uf::String::operator -=( std::size_t i ) { return *this; } // -UF_API_CALL uf::String::operator std::string() { - return std::string((char*) this->c_str()); +UF_API_CALL uf::String::operator uf::stl::string() { + return uf::stl::string((char*) this->c_str()); } -UF_API_CALL uf::String::operator std::string() const { - return std::string((const char*) this->c_str()); +UF_API_CALL uf::String::operator uf::stl::string() const { + return uf::stl::string((const char*) this->c_str()); } // UF_API_CALL uf::String::operator std::wstring() { diff --git a/engine/src/utils/text/glyph.cpp b/engine/src/utils/text/glyph.cpp index 9915e0f2..a67dcab7 100644 --- a/engine/src/utils/text/glyph.cpp +++ b/engine/src/utils/text/glyph.cpp @@ -6,7 +6,7 @@ uf::Glyph::~Glyph() { } // OpenGL ops -uint8_t* uf::Glyph::generate( const std::string& font, unsigned long c, uint size ) { +uint8_t* uf::Glyph::generate( const uf::stl::string& font, unsigned long c, uint size ) { ext::freetype::Glyph glyph = ext::freetype::initialize(font); return this->generate( glyph, c ); } @@ -59,7 +59,7 @@ uint8_t* uf::Glyph::generate( ext::freetype::Glyph& glyph, unsigned long c, uint if ( this->isSdf() ) this->generateSdf(this->m_buffer); return this->m_buffer; } -uint8_t* uf::Glyph::generate( const std::string& font, const uf::String& c, uint size ) { +uint8_t* uf::Glyph::generate( const uf::stl::string& font, const uf::String& c, uint size ) { ext::freetype::Glyph glyph = ext::freetype::initialize(font); return this->generate( glyph, c ); } diff --git a/engine/src/utils/thread/thread.cpp b/engine/src/utils/thread/thread.cpp index ea0f9ad2..a66efd94 100644 --- a/engine/src/utils/thread/thread.cpp +++ b/engine/src/utils/thread/thread.cpp @@ -49,14 +49,14 @@ void UF_API uf::thread::tick( pod::Thread& thread ) { } } -pod::Thread& UF_API uf::thread::fetchWorker( const std::string& name ) { +pod::Thread& UF_API uf::thread::fetchWorker( const uf::stl::string& name ) { static int current = 0; static int limit = uf::thread::workers; static uint threads = std::thread::hardware_concurrency(); int tries = 8; while ( --tries >= 0 ) { if ( ++current >= limit ) current = 0; - std::string thread = name; + uf::stl::string thread = name; if ( current > 0 ) thread += " " + std::to_string(current); bool exists = uf::thread::has(thread); auto& pod = exists ? uf::thread::get(thread) : uf::thread::create(thread, true); @@ -66,8 +66,8 @@ pod::Thread& UF_API uf::thread::fetchWorker( const std::string& name ) { auto& pod = exists ? uf::thread::get("Main" ) : uf::thread::create("Main", true); return pod; } -void UF_API uf::thread::batchWorkers( const std::vector& functions, bool wait, const std::string& name ) { - std::vector workers; +void UF_API uf::thread::batchWorkers( const uf::stl::vector& functions, bool wait, const uf::stl::string& name ) { + uf::stl::vector workers; for ( auto& function : functions ) { auto& worker = uf::thread::fetchWorker( name ); workers.emplace_back(&worker); @@ -169,7 +169,7 @@ void UF_API uf::thread::wait( pod::Thread& thread ) { */ } -const std::string& UF_API uf::thread::name( const pod::Thread& thread ) { +const uf::stl::string& UF_API uf::thread::name( const pod::Thread& thread ) { return thread.name; } uint UF_API uf::thread::uid( const pod::Thread& thread ) { @@ -185,7 +185,7 @@ void UF_API uf::thread::terminate() { uf::thread::destroy( thread ); } } -pod::Thread& UF_API uf::thread::create( const std::string& name, bool start, bool locks ) { +pod::Thread& UF_API uf::thread::create( const uf::stl::string& name, bool start, bool locks ) { pod::Thread* pointer = NULL; uf::thread::threads.emplace_back(pointer = new pod::Thread); pod::Thread& thread = *pointer; @@ -228,7 +228,7 @@ bool UF_API uf::thread::has( uint uid ) { for ( const pod::Thread* thread : uf::thread::threads ) if ( uf::thread::uid(*thread) == uid ) return true; return false; } -bool UF_API uf::thread::has( const std::string& name ) { +bool UF_API uf::thread::has( const uf::stl::string& name ) { for ( const pod::Thread* thread : uf::thread::threads ) if ( uf::thread::name(*thread) == name ) return true; return false; } @@ -236,7 +236,7 @@ pod::Thread& UF_API uf::thread::get( uint uid ) { for ( pod::Thread* thread : uf::thread::threads ) if ( uf::thread::uid(*thread) == uid ) return *thread; UF_EXCEPTION("Thread error: invalid call"); } -pod::Thread& UF_API uf::thread::get( const std::string& name ) { +pod::Thread& UF_API uf::thread::get( const uf::stl::string& name ) { for ( pod::Thread* thread : uf::thread::threads ) if ( uf::thread::name(*thread) == name ) return *thread; UF_EXCEPTION("Thread error: invalid call"); } diff --git a/engine/src/utils/type/type.cpp b/engine/src/utils/type/type.cpp index daced6a0..f14d3482 100644 --- a/engine/src/utils/type/type.cpp +++ b/engine/src/utils/type/type.cpp @@ -4,7 +4,7 @@ #include #include namespace { - std::string demangle( const std::string& mangled ) { + uf::stl::string demangle( const uf::stl::string& mangled ) { int status = -4; std::unique_ptr demangled{ @@ -15,7 +15,7 @@ namespace { /* int status; char* pointer = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status); - std::string demangled; + uf::stl::string demangled; demangled.copy( pointer, strlen(pointer) ); free(pointer); return demangled; @@ -23,9 +23,9 @@ namespace { } } -std::unordered_map* uf::typeInfo::types = NULL; -void uf::typeInfo::registerType( const index_t& index, size_t size, const std::string& pretty ) { - if ( !uf::typeInfo::types ) uf::typeInfo::types = new std::unordered_map; +uf::stl::unordered_map* uf::typeInfo::types = NULL; +void uf::typeInfo::registerType( const index_t& index, size_t size, const uf::stl::string& pretty ) { + if ( !uf::typeInfo::types ) uf::typeInfo::types = new uf::stl::unordered_map; bool exists = uf::typeInfo::types->count(index) > 0; auto& type = (*uf::typeInfo::types)[index]; if ( !exists || type.size < size ) type.size = size; @@ -36,7 +36,7 @@ void uf::typeInfo::registerType( const index_t& index, size_t size, const std::s // if ( !exists ) uf::iostream << "Registered type " << type.name.pretty << " (Mangled: " << type.name.compiler << ") of size " << size << "\n"; } const pod::TypeInfo& UF_API uf::typeInfo::getType( size_t hash ) { - if ( !uf::typeInfo::types ) uf::typeInfo::types = new std::unordered_map; + if ( !uf::typeInfo::types ) uf::typeInfo::types = new uf::stl::unordered_map; auto& types = *uf::typeInfo::types; for ( auto& pair : types ) { if ( pair.second.hash == hash ) return pair.second; @@ -45,6 +45,6 @@ const pod::TypeInfo& UF_API uf::typeInfo::getType( size_t hash ) { return null; } const pod::TypeInfo& uf::typeInfo::getType( const index_t& index ) { - if ( !uf::typeInfo::types ) uf::typeInfo::types = new std::unordered_map; + if ( !uf::typeInfo::types ) uf::typeInfo::types = new uf::stl::unordered_map; return (*uf::typeInfo::types)[index]; } \ No newline at end of file diff --git a/engine/src/utils/userdata/pointered.cpp b/engine/src/utils/userdata/pointered.cpp index 5a8faa43..7c76d2fc 100644 --- a/engine/src/utils/userdata/pointered.cpp +++ b/engine/src/utils/userdata/pointered.cpp @@ -26,15 +26,15 @@ pod::PointeredUserdata UF_API uf::pointeredUserdata::create( uf::MemoryPool& req if ( len <= 0 ) return {}; size_t requestedLen = size( len ); #if UF_MEMORYPOOL_INVALID_MALLOC - uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global; + uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::memoryPool::global; pod::PointeredUserdata userdata = { .len = requestedLen, - .data = memoryPool.alloc( data, requestedLen ), + .data = (uint8_t*) memoryPool.alloc( data, requestedLen ), }; #else uf::MemoryPool* memoryPool = {}; if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) memoryPool = &uf::memoryPool::global; pod::PointeredUserdata userdata = {}; if ( memoryPool ) userdata.data = (uint8_t*) memoryPool->alloc( data, requestedLen ); @@ -52,12 +52,12 @@ pod::PointeredUserdata UF_API uf::pointeredUserdata::create( uf::MemoryPool& req } void UF_API uf::pointeredUserdata::destroy( uf::MemoryPool& requestedMemoryPool, pod::PointeredUserdata& userdata ) { #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global; - memoryPool.free( userdata, size(userdata.len) ); + uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::memoryPool::global; + memoryPool.free( userdata.data, size(userdata.len) ); #else uf::MemoryPool* memoryPool = NULL; if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) memoryPool = &uf::memoryPool::global; if ( memoryPool ) memoryPool->free( userdata.data, size(userdata.len) ); else { @@ -77,11 +77,11 @@ pod::PointeredUserdata UF_API uf::pointeredUserdata::copy( uf::MemoryPool& reque return copied; } -std::string UF_API uf::pointeredUserdata::toBase64( pod::PointeredUserdata& userdata ) { +uf::stl::string UF_API uf::pointeredUserdata::toBase64( pod::PointeredUserdata& userdata ) { return uf::base64::encode( userdata.data, userdata.len ); } -pod::PointeredUserdata UF_API uf::pointeredUserdata::fromBase64( const std::string& base64 ) { - std::vector decoded = uf::base64::decode( base64 ); +pod::PointeredUserdata UF_API uf::pointeredUserdata::fromBase64( const uf::stl::string& base64 ) { + uf::stl::vector decoded = uf::base64::decode( base64 ); return uf::pointeredUserdata::create( decoded.size(), decoded.data() ); } // C-tor diff --git a/engine/src/utils/userdata/userdata.cpp b/engine/src/utils/userdata/userdata.cpp index f176c12a..074c5a1a 100644 --- a/engine/src/utils/userdata/userdata.cpp +++ b/engine/src/utils/userdata/userdata.cpp @@ -25,16 +25,16 @@ size_t uf::userdata::size( size_t len, size_t padding ) { } // -pod::Userdata* UF_API uf::userdata::create( uf::MemoryPool& requestedMemoryPool, std::size_t len, void* data ) { +pod::Userdata* UF_API uf::userdata::create( uf::MemoryPool& requestedMemoryPool, size_t len, void* data ) { if ( len <= 0 ) return NULL; size_t requestedLen = size( len ); #if UF_MEMORYPOOL_INVALID_MALLOC - uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global; + uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::memoryPool::global; pod::Userdata* userdata = (pod::Userdata*) memoryPool.alloc( data, requestedLen ); #else uf::MemoryPool* memoryPool = NULL; if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) memoryPool = &uf::memoryPool::global; pod::Userdata* userdata = NULL; if ( memoryPool ) userdata = (pod::Userdata*) memoryPool->alloc( data, requestedLen ); @@ -52,12 +52,12 @@ pod::Userdata* UF_API uf::userdata::create( uf::MemoryPool& requestedMemoryPool, } void UF_API uf::userdata::destroy( uf::MemoryPool& requestedMemoryPool, pod::Userdata* userdata ) { #if UF_MEMORYPOOL_INVALID_FREE - uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global; + uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::memoryPool::global; memoryPool.free( userdata, size(userdata->len) ); #else uf::MemoryPool* memoryPool = NULL; if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool; - else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global; + else if ( uf::memoryPool::global.size() > 0 ) memoryPool = &uf::memoryPool::global; if ( memoryPool ) memoryPool->free( userdata, size(userdata->len) ); else { @@ -75,11 +75,11 @@ pod::Userdata* UF_API uf::userdata::copy( uf::MemoryPool& requestedMemoryPool, c return copied; } -std::string UF_API uf::userdata::toBase64( pod::Userdata* userdata ) { +uf::stl::string UF_API uf::userdata::toBase64( pod::Userdata* userdata ) { return uf::base64::encode( userdata->data, userdata->len ); } -pod::Userdata* UF_API uf::userdata::fromBase64( const std::string& base64 ) { - std::vector decoded = uf::base64::decode( base64 ); +pod::Userdata* UF_API uf::userdata::fromBase64( const uf::stl::string& base64 ) { + uf::stl::vector decoded = uf::base64::decode( base64 ); return uf::userdata::create( decoded.size(), decoded.data() ); } // C-tor diff --git a/engine/src/utils/window/window.cpp b/engine/src/utils/window/window.cpp index 1135524d..dcf744a1 100644 --- a/engine/src/utils/window/window.cpp +++ b/engine/src/utils/window/window.cpp @@ -78,10 +78,10 @@ void UF_API_CALL uf::Window::setTitle( const spec::uni::Window::title_t& title ) this->m_window->setTitle(title); uf::Serializer json; - std::string hook = "window:Title.Changed"; + uf::stl::string hook = "window:Title.Changed"; json["type"] = hook; json["invoker"] = "os"; - json["window"]["title"] = std::string(title); + json["window"]["title"] = uf::stl::string(title); uf::hooks.call( hook, json ); } void UF_API_CALL uf::Window::setIcon( const spec::uni::Window::vector_t& size, uint8_t* pixels ) { @@ -127,7 +127,7 @@ void UF_API_CALL uf::Window::processEvents() { bool UF_API_CALL uf::Window::pollEvents( bool block ) { return this->m_window ? this->m_window->pollEvents(block) : false; } -bool UF_API_CALL uf::Window::isKeyPressed( const std::string& key ) { +bool UF_API_CALL uf::Window::isKeyPressed( const uf::stl::string& key ) { return uf::Window::focused && uf::Window::window_t::isKeyPressed(key); } bool UF_API_CALL uf::Window::setActive(bool active) { @@ -141,7 +141,7 @@ bool UF_API_CALL uf::Window::setActive(bool active) { return false; } #if UF_USE_VULKAN -std::vector UF_API_CALL uf::Window::getExtensions( bool x ) { +uf::stl::vector UF_API_CALL uf::Window::getExtensions( bool x ) { return this->m_window->getExtensions( x ); } void UF_API_CALL uf::Window::createSurface( VkInstance instance, VkSurfaceKHR& surface ) { diff --git a/ext/behaviors/baking/behavior.cpp b/ext/behaviors/baking/behavior.cpp index 512609e0..18c56db0 100644 --- a/ext/behaviors/baking/behavior.cpp +++ b/ext/behaviors/baking/behavior.cpp @@ -23,13 +23,13 @@ void ext::BakingBehavior::initialize( uf::Object& self ) { auto& metadataJson = this->getComponent(); auto& metadata = this->getComponent(); - metadata.names.model = this->grabURI( metadataJson["baking"]["model"].as(), metadataJson["system"]["root"].as() ); - if ( metadataJson["baking"]["output"]["model"].is() ) - metadata.names.output.model = this->grabURI( metadataJson["baking"]["output"]["model"].as(), metadataJson["system"]["root"].as() ); - metadata.names.output.map = this->grabURI( metadataJson["baking"]["output"]["map"].as(), metadataJson["system"]["root"].as() ); + metadata.names.model = this->grabURI( metadataJson["baking"]["model"].as(), metadataJson["system"]["root"].as() ); + if ( metadataJson["baking"]["output"]["model"].is() ) + metadata.names.output.model = this->grabURI( metadataJson["baking"]["output"]["model"].as(), metadataJson["system"]["root"].as() ); + metadata.names.output.map = this->grabURI( metadataJson["baking"]["output"]["map"].as(), metadataJson["system"]["root"].as() ); metadata.names.renderMode = "B:" + std::to_string((int) this->getUid()); - metadata.trigger.mode = metadataJson["baking"]["trigger"]["mode"].as(); - metadata.trigger.value = metadataJson["baking"]["trigger"]["value"].as(); + metadata.trigger.mode = metadataJson["baking"]["trigger"]["mode"].as(); + metadata.trigger.value = metadataJson["baking"]["trigger"]["value"].as(); if ( metadataJson["baking"]["resolution"].is() ) metadata.size = { metadataJson["baking"]["resolution"].as(), metadataJson["baking"]["resolution"].as() }; metadata.shadows = metadataJson["baking"]["shadows"].as(); @@ -93,8 +93,8 @@ void ext::BakingBehavior::initialize( uf::Object& self ) { texture.storage.remap = 0; texture.storage.blend = 0; - if ( graph.metadata["filter"].is() ) { - std::string filter = graph.metadata["filter"].as(); + if ( graph.metadata["filter"].is() ) { + uf::stl::string filter = graph.metadata["filter"].as(); if ( filter == "NEAREST" ) { texture.texture.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; texture.texture.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; @@ -119,8 +119,8 @@ void ext::BakingBehavior::initialize( uf::Object& self ) { auto& texture = graph.textures[i]; texture.bind = true; texture.storage.index = i; - if ( graph.metadata["filter"].is() ) { - std::string filter = graph.metadata["filter"].as(); + if ( graph.metadata["filter"].is() ) { + uf::stl::string filter = graph.metadata["filter"].as(); if ( filter == "NEAREST" ) { texture.texture.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST; texture.texture.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; @@ -149,7 +149,7 @@ void ext::BakingBehavior::initialize( uf::Object& self ) { for ( auto& m : graph.meshes ) mesh.insert(m); // Models storage buffer - std::vector instances; + uf::stl::vector instances; instances.reserve( graph.nodes.size() ); for ( auto& node : graph.nodes ) { instances.emplace_back( uf::transform::model( node.transform ) ); @@ -160,7 +160,7 @@ void ext::BakingBehavior::initialize( uf::Object& self ) { uf::renderer::enums::Buffer::STORAGE ); // Materials storage buffer - std::vector materials( graph.materials.size() ); + uf::stl::vector materials( graph.materials.size() ); for ( size_t i = 0; i < graph.materials.size(); ++i ) { materials[i] = graph.materials[i].storage; } @@ -170,7 +170,7 @@ void ext::BakingBehavior::initialize( uf::Object& self ) { uf::renderer::enums::Buffer::STORAGE ); // Texture storage buffer - std::vector textures( graph.textures.size() ); + uf::stl::vector textures( graph.textures.size() ); for ( size_t i = 0; i < graph.textures.size(); ++i ) { textures[i] = graph.textures[i].storage; } @@ -210,13 +210,13 @@ PREPARE: { graphic.initialize( metadata.names.renderMode ); graphic.initializeMesh( mesh ); - std::vector textures2D; + uf::stl::vector textures2D; textures2D.reserve( metadata.max.textures2D ); - std::vector textures3D; + uf::stl::vector textures3D; textures3D.reserve( metadata.max.textures3D ); - std::vector texturesCube; + uf::stl::vector texturesCube; texturesCube.reserve( metadata.max.texturesCube ); // attach lighting info @@ -232,10 +232,10 @@ PREPARE: { int32_t type = 0; bool shadows = false; }; - std::vector entities; + uf::stl::vector entities; entities.reserve(graph.size() / 2); - std::vector lights; + uf::stl::vector lights; lights.reserve(1024); int32_t shadowUpdateThreshold = metadata.max.shadows; // how many shadow maps we should update, based on range @@ -372,9 +372,9 @@ PREPARE: { // standard pipeline { - std::string vertexShaderFilename = "/gltf/baking/bake.vert.spv"; - std::string geometryShaderFilename = ""; - std::string fragmentShaderFilename = "/gltf/baking/bake.frag.spv"; + uf::stl::string vertexShaderFilename = "/gltf/baking/bake.vert.spv"; + uf::stl::string geometryShaderFilename = ""; + uf::stl::string fragmentShaderFilename = "/gltf/baking/bake.frag.spv"; if ( uf::renderer::settings::experimental::deferredSampling ) { fragmentShaderFilename = uf::string::replace( fragmentShaderFilename, "frag", "deferredSampling.frag" ); } @@ -396,7 +396,7 @@ PREPARE: { auto& shader = graphic.material.getShader("vertex"); uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "PASSES" ) sc["value"] = (specializationConstants[i] = maxPasses); }); } @@ -409,14 +409,14 @@ PREPARE: { auto& shader = graphic.material.getShader("fragment"); uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTextures2D); else if ( name == "CUBEMAPS" ) sc["value"] = (specializationConstants[i] = maxTexturesCube); else if ( name == "CASCADES" ) sc["value"] = (specializationConstants[i] = maxCascades); }); ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ size_t binding = t["binding"].as(); - std::string name = t["name"].as(); + uf::stl::string name = t["name"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding != binding ) continue; if ( name == "samplerTextures" ) layout.descriptorCount = maxTextures2D; @@ -430,12 +430,12 @@ PREPARE: { /* uint32_t* specializationConstants = (uint32_t*) (void*) &shader.specializationConstants; ext::json::forEach( shader.metadata.json["specializationConstants"], [&]( size_t i, ext::json::Value& sc ){ - std::string name = sc["name"].as(); + uf::stl::string name = sc["name"].as(); if ( name == "TEXTURES" ) sc["value"] = (specializationConstants[i] = maxTexture2Ds); }); ext::json::forEach( shader.metadata.json["definitions"]["textures"], [&]( ext::json::Value& t ){ - if ( t["name"].as() != "samplerTextures" ) return; + if ( t["name"].as() != "samplerTextures" ) return; size_t binding = t["binding"].as(); for ( auto& layout : shader.descriptorSetLayoutBindings ) { if ( layout.binding == binding ) layout.descriptorCount = maxTextures; @@ -456,7 +456,7 @@ SAVE: { renderMode.execute = false; UF_MSG_DEBUG("Baking..."); auto image = renderMode.screenshot(); - std::string filename = metadata.names.output.map; + uf::stl::string filename = metadata.names.output.map; bool status = image.save(filename); UF_MSG_DEBUG("Writing to " << filename << ": " << status); UF_MSG_DEBUG("Baked."); diff --git a/ext/behaviors/baking/behavior.h b/ext/behaviors/baking/behavior.h index c0988147..a1cc62e3 100644 --- a/ext/behaviors/baking/behavior.h +++ b/ext/behaviors/baking/behavior.h @@ -17,12 +17,12 @@ namespace ext { struct Metadata { pod::Vector2ui size = {}; struct { - std::string model = ""; + uf::stl::string model = ""; struct{ - std::string model = ""; - std::string map = "./lightmap.png"; + uf::stl::string model = ""; + uf::stl::string map = "./lightmap.png"; } output; - std::string renderMode = "Baker"; + uf::stl::string renderMode = "Baker"; } names; struct { size_t instance = 0; @@ -42,8 +42,8 @@ namespace ext { size_t update = 0; } previous; struct { - std::string mode = "key"; - std::string value = ""; + uf::stl::string mode = "key"; + uf::stl::string value = ""; } trigger; struct { bool renderMode = false; diff --git a/ext/behaviors/craeture/behavior.cpp b/ext/behaviors/craeture/behavior.cpp index 6dbf8d1e..518afb22 100644 --- a/ext/behaviors/craeture/behavior.cpp +++ b/ext/behaviors/craeture/behavior.cpp @@ -89,7 +89,7 @@ void ext::CraetureBehavior::initialize( uf::Object& self ) { uf::Scene& world = uf::scene::getCurrentScene(); uf::Serializer& masterdata = world.getComponent(); - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return; diff --git a/ext/behaviors/hands/behavior.cpp b/ext/behaviors/hands/behavior.cpp index 674b023a..3b8203a3 100644 --- a/ext/behaviors/hands/behavior.cpp +++ b/ext/behaviors/hands/behavior.cpp @@ -47,16 +47,16 @@ void ext::PlayerHandBehavior::initialize( uf::Object& self ) { { bool loaded = true; for ( auto it = metadata["hands"].begin(); it != metadata["hands"].end(); ++it ) { - std::string key = it.key(); - if ( !ext::openvr::requestRenderModel(metadata["hands"][key]["controller"]["model"].as()) ) loaded = false; + uf::stl::string key = it.key(); + if ( !ext::openvr::requestRenderModel(metadata["hands"][key]["controller"]["model"].as()) ) loaded = false; } if ( !loaded ) { this->addHook( "VR:Model.Loaded", [&](ext::json::Value& json){ - std::string name = json["name"].as(); - std::string side = ""; - if ( name == metadata["hands"]["left"]["controller"]["model"].as() ) { + uf::stl::string name = json["name"].as(); + uf::stl::string side = ""; + if ( name == metadata["hands"]["left"]["controller"]["model"].as() ) { side = "left"; - } else if ( name == metadata["hands"]["right"]["controller"]["model"].as() ) { + } else if ( name == metadata["hands"]["right"]["controller"]["model"].as() ) { side = "right"; }; if ( side == "" ) return; @@ -153,15 +153,15 @@ void ext::PlayerHandBehavior::initialize( uf::Object& self ) { }); } - std::vector vHands = { ::hands.left, ::hands.right }; + uf::stl::vector vHands = { ::hands.left, ::hands.right }; for ( auto pointer : vHands ) { auto& hand = *pointer; hand.addHook("VR:Input.Digital", [&](ext::json::Value& json){ - std::string side = &hand == hands.left ? "left" : "right"; - if ( json["hand"].as() != side ) return; + uf::stl::string side = &hand == hands.left ? "left" : "right"; + if ( json["hand"].as() != side ) return; // fire mouse click - if ( json["name"].as() == "click" ) { + if ( json["name"].as() == "click" ) { uf::Serializer payload; payload["type"] = "window:Mouse.Click"; @@ -175,11 +175,11 @@ void ext::PlayerHandBehavior::initialize( uf::Object& self ) { payload["mouse"]["button"] = side == "left" ? "Right" : "Left"; payload["mouse"]["state"] = json["state"].as() ? "Down": "Up"; - uf::hooks.call( payload["type"].as(), payload ); + uf::hooks.call( payload["type"].as(), payload ); } }); hand.addHook("world:Collision.%UID%", [&](ext::json::Value& json){ - std::string side = &hand == hands.left ? "left" : "right"; + uf::stl::string side = &hand == hands.left ? "left" : "right"; float mag = json["depth"].as(); uf::Serializer payload; @@ -386,9 +386,9 @@ void ext::PlayerHandBehavior::tick( uf::Object& self ) { } // raytrace pointer / hand collision { - std::vector handPointers = { ::hands.left, ::hands.right }; + uf::stl::vector handPointers = { ::hands.left, ::hands.right }; for ( auto pointer : handPointers ) { auto& hand = *pointer; - std::string side = &hand == ::hands.left ? "left" : "right"; + uf::stl::string side = &hand == ::hands.left ? "left" : "right"; if ( !ext::openvr::controllerActive( side == "left" ? vr::Controller_Hand::Hand_Left : vr::Controller_Hand::Hand_Right ) ) continue; { pod::Transform<>& transform = (side == "left" ? ::lines.left : ::lines.right)->getComponent>(); diff --git a/ext/behaviors/light/behavior.cpp b/ext/behaviors/light/behavior.cpp index b0103fc3..344e9532 100644 --- a/ext/behaviors/light/behavior.cpp +++ b/ext/behaviors/light/behavior.cpp @@ -10,7 +10,7 @@ namespace { struct { size_t current = 0; - std::vector lights; + uf::stl::vector lights; } roundRobin; const pod::Quaternion<> rotations[6] = { uf::quaternion::axisAngle( { 0, 1, 0 }, 1 * 1.57079633f ), // right @@ -47,7 +47,7 @@ void ext::LightBehavior::initialize( uf::Object& self ) { if ( !metadataJson["light"]["bias"]["constant"].is() ) { metadataJson["light"]["bias"]["constant"] = 0.00005f; } - if ( !metadataJson["light"]["type"].is() ) { + if ( !metadataJson["light"]["type"].is() ) { metadataJson["light"]["type"] = "point"; } if ( !ext::json::isArray( metadataJson["light"]["color"] ) ) { @@ -74,7 +74,7 @@ void ext::LightBehavior::initialize( uf::Object& self ) { renderMode.metadata.json["descriptor"]["depth bias"] = metadataJson["light"]["bias"]; renderMode.metadata.json["descriptor"]["renderMode"] = metadataJson["renderMode"]; - if ( metadataJson["light"]["type"].as() == "point" ) { + if ( metadataJson["light"]["type"].as() == "point" ) { metadataJson["light"]["fov"] = 90.0f; renderMode.metadata.subpasses = 6; } @@ -94,7 +94,7 @@ void ext::LightBehavior::initialize( uf::Object& self ) { camera.setProjection( uf::matrix::perspective( fov, (float) size.x / (float) size.y, radius.x, radius.y ) ); camera.update(true); - std::string name = "RT:" + std::to_string((int) this->getUid()); + uf::stl::string name = "RT:" + std::to_string((int) this->getUid()); uf::renderer::addRenderMode( &renderMode, name ); renderMode.blitter.process = false; renderMode.width = size.x; @@ -120,14 +120,14 @@ void ext::LightBehavior::initialize( uf::Object& self ) { metadata.power = metadataJson["light"]["power"].as(); metadata.bias = metadataJson["light"]["bias"]["shader"].as(); metadata.shadows = metadataJson["light"]["shadows"].as(); - metadata.renderer.mode = metadataJson["system"]["renderer"]["mode"].as(); + metadata.renderer.mode = metadataJson["system"]["renderer"]["mode"].as(); metadata.renderer.rendered = false; metadata.renderer.external = metadataJson["light"]["external update"].as(); metadata.renderer.limiter = metadataJson["system"]["renderer"]["timer"].as(); if ( metadataJson["light"]["type"].is() ) { metadata.type = metadataJson["light"]["type"].as(); - } else if ( metadataJson["light"]["type"].is() ) { - std::string lightType = metadataJson["light"]["type"].as(); + } else if ( metadataJson["light"]["type"].is() ) { + uf::stl::string lightType = metadataJson["light"]["type"].as(); if ( lightType == "point" ) metadata.type = 1; else if ( lightType == "spot" ) metadata.type = 2; } @@ -151,14 +151,14 @@ void ext::LightBehavior::tick( uf::Object& self ) { if ( !metadata.power ) metadata.power = metadataJson["light"]["power"].as(); if ( !metadata.bias ) metadata.bias = metadataJson["light"]["bias"]["shader"].as(); if ( !metadata.shadows ) metadata.shadows = metadataJson["light"]["shadows"].as(); - if ( metadata.renderer.mode == "" ) metadata.renderer.mode = metadataJson["system"]["renderer"]["mode"].as(); + if ( metadata.renderer.mode == "" ) metadata.renderer.mode = metadataJson["system"]["renderer"]["mode"].as(); if ( !metadata.renderer.external ) metadata.renderer.external = metadataJson["light"]["external update"].as(); if ( !metadata.renderer.limiter ) metadata.renderer.limiter = metadataJson["system"]["renderer"]["timer"].as(); if ( !metadata.type) { if ( metadataJson["light"]["type"].is() ) { metadata.type = metadataJson["light"]["type"].as(); - } else if ( metadataJson["light"]["type"].is() ) { - std::string lightType = metadataJson["light"]["type"].as(); + } else if ( metadataJson["light"]["type"].is() ) { + uf::stl::string lightType = metadataJson["light"]["type"].as(); if ( lightType == "point" ) metadata.type = 1; else if ( lightType == "spot" ) metadata.type = 2; } diff --git a/ext/behaviors/light/behavior.h b/ext/behaviors/light/behavior.h index fceca95f..30572ee8 100644 --- a/ext/behaviors/light/behavior.h +++ b/ext/behaviors/light/behavior.h @@ -21,7 +21,7 @@ namespace ext { bool shadows = false; int32_t type = 1; struct { - std::string mode = "in-range"; + uf::stl::string mode = "in-range"; float limiter = 0.0f; float timer = 0.0f; bool rendered = false; diff --git a/ext/behaviors/noise/behavior.cpp b/ext/behaviors/noise/behavior.cpp index fc58d234..136267bb 100644 --- a/ext/behaviors/noise/behavior.cpp +++ b/ext/behaviors/noise/behavior.cpp @@ -35,8 +35,8 @@ void ext::NoiseBehavior::initialize( uf::Object& self ) { pod::Vector3ui size = uf::vector::decode(metadata["size"], pod::Vector3ui{512, 512, 1}); pod::Vector3d coefficients = uf::vector::decode(metadata["coefficients"], pod::Vector3d{3.0, 3.0, 3.0}); - std::vector pixels(size.x * size.y * size.z); - std::vector perlins(size.x * size.y * size.z); + uf::stl::vector pixels(size.x * size.y * size.z); + uf::stl::vector perlins(size.x * size.y * size.z); #pragma omp parallel for for ( size_t z = 0; z < size.z; ++z ) { for ( size_t y = 0; y < size.y; ++y ) { diff --git a/ext/behaviors/player/behavior.cpp b/ext/behaviors/player/behavior.cpp index d328506e..57f25f2a 100644 --- a/ext/behaviors/player/behavior.cpp +++ b/ext/behaviors/player/behavior.cpp @@ -180,7 +180,7 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) { // for ( auto& member : json[""]["transients"] ) { ext::json::forEach(metadataJson[""]["transients"], [&](ext::json::Value& member){ if ( member["type"] != "player" ) return; - std::string id = member["id"].as(); + uf::stl::string id = member["id"].as(); metadataJson[""]["transients"][id]["hp"] = member["hp"]; metadataJson[""]["transients"][id]["mp"] = member["mp"]; }); @@ -204,7 +204,7 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) { if ( metadataJson["system"]["cooldown"].as() > uf::physics::time::current ) return; if ( !metadataJson["system"]["control"].as() ) return; - std::string state = metadataJson["system"]["state"].as(); + uf::stl::string state = metadataJson["system"]["state"].as(); if ( state != "" && state != "null" ) return; uf::Scene& scene = uf::scene::getCurrentScene(); @@ -214,7 +214,7 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) { uf::Serializer& pMetadata = entity->getComponent(); - std::string onCollision = pMetadata["system"]["onCollision"].as(); + uf::stl::string onCollision = pMetadata["system"]["onCollision"].as(); if ( onCollision == "battle" ) { uf::Serializer payload; @@ -256,10 +256,10 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) { #if UF_USE_DISCORD // Discord Integration this->addHook( "discord.Activity.Update.%UID%", [&](ext::json::Value& json){ - std::string leaderId = metadataJson[""]["party"][0].as(); + uf::stl::string leaderId = metadataJson[""]["party"][0].as(); uf::Serializer cardData = masterDataGet("Card", leaderId); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string leader = charaData["name"].as(); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string leader = charaData["name"].as(); uf::Serializer payload = json; payload["details"] = "Leader: " + leader; @@ -301,7 +301,7 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) { auto& metadataCamera = metadataJson["camera"]; auto& metadataCameraLimit = metadataCamera["limit"]; - metadata.system.menu = metadataSystem["menu"].as(); + metadata.system.menu = metadataSystem["menu"].as(); metadata.system.control = metadataSystem["control"].as(); metadata.system.crouching = metadataSystem["crouching"].as(); metadata.system.noclipped = metadataSystem["noclipped"].as(); @@ -402,8 +402,8 @@ void ext::PlayerBehavior::tick( uf::Object& self ) { bool floored = true; bool impulse = true; bool noclipped = false; - std::string menu = ""; - std::string targetAnimation = ""; + uf::stl::string menu = ""; + uf::stl::string targetAnimation = ""; } stats; auto& metadata = this->getComponent(); @@ -656,7 +656,7 @@ void ext::PlayerBehavior::tick( uf::Object& self ) { if ( stats.walking ) { auto& emitter = this->getComponent(); int cycle = rand() % metadata.audio.footstep.list.size(); - std::string filename = metadata.audio.footstep.list[cycle]; + uf::stl::string filename = metadata.audio.footstep.list[cycle]; uf::Audio& footstep = emitter.has(filename) ? emitter.get(filename) : emitter.load(filename); bool playing = false; diff --git a/ext/behaviors/player/behavior.h b/ext/behaviors/player/behavior.h index cfcacaec..6d49d791 100644 --- a/ext/behaviors/player/behavior.h +++ b/ext/behaviors/player/behavior.h @@ -28,7 +28,7 @@ namespace ext { } physics; bool control = true; - std::string menu = ""; + uf::stl::string menu = ""; bool crouching = false; bool noclipped = false; } system; @@ -42,7 +42,7 @@ namespace ext { } camera; struct { struct { - std::vector list; + uf::stl::vector list; float volume; } footstep; } audio; diff --git a/ext/behaviors/portal/behavior.cpp b/ext/behaviors/portal/behavior.cpp index 69e1b41c..8b074a89 100644 --- a/ext/behaviors/portal/behavior.cpp +++ b/ext/behaviors/portal/behavior.cpp @@ -59,7 +59,7 @@ void ext::PortalBehavior::initialize( uf::Object& self ) { } { auto& renderMode = this->getComponent(); - std::string name = "RT:" + std::to_string((int) this->getUid()); + uf::stl::string name = "RT:" + std::to_string((int) this->getUid()); uf::renderer::addRenderMode( &renderMode, name ); #if UF_USE_OPENVR if ( ext::openvr::enabled ) { diff --git a/ext/behaviors/scene/behavior.cpp b/ext/behaviors/scene/behavior.cpp index 9540cebd..018d9d80 100644 --- a/ext/behaviors/scene/behavior.cpp +++ b/ext/behaviors/scene/behavior.cpp @@ -42,8 +42,8 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { }); this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); if ( category != "" && (category != "audio" && category != "audio-stream") ) return; if ( category == "" && uf::io::extension(filename) != "ogg" ) return; @@ -70,7 +70,7 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { uf::Object* manager = (uf::Object*) this->globalFindByName("Gui Manager"); if ( !manager ) return; uf::Serializer payload; - std::string config = metadataJson["menus"]["pause"].is() ? metadataJson["menus"]["pause"].as() : "/scenes/worldscape/gui/pause/menu.json"; + uf::stl::string config = metadataJson["menus"]["pause"].is() ? metadataJson["menus"]["pause"].as() : "/scenes/worldscape/gui/pause/menu.json"; uf::Object& gui = manager->loadChild(config, false); payload["uid"] = gui.getUid(); @@ -80,8 +80,8 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { gui.initialize(); }); this->addHook( "world:Entity.LoadAsset", [&](ext::json::Value& json){ - std::string asset = json["asset"].as(); - std::string uid = json["uid"].as(); + uf::stl::string asset = json["asset"].as(); + uf::stl::string uid = json["uid"].as(); assetLoader.load(asset, "asset:Load." + uid); }); @@ -90,7 +90,7 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { metadata.shader.scalar = json["scalar"].as(); metadata.shader.parameters = uf::vector::decode( json["parameters"], metadata.shader.parameters ); ext::json::forEach( metadataJson["system"]["renderer"]["shader"]["parameters"], [&]( uint32_t i, const ext::json::Value& value ){ - if ( value.as() == "time" ) metadata.shader.time = i; + if ( value.as() == "time" ) metadata.shader.time = i; }); if ( 0 <= metadata.shader.time && metadata.shader.time < 4 ) { metadata.shader.parameters[metadata.shader.time] = uf::physics::time::current; @@ -130,8 +130,8 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { pod::Vector3ui size = uf::vector::decode(metadataJson["noise"]["size"], pod::Vector3ui{64, 64, 64}); pod::Vector3d coefficients = uf::vector::decode(metadataJson["noise"]["coefficients"], pod::Vector3d{3.0, 3.0, 3.0}); - std::vector pixels(size.x * size.y * size.z); - std::vector perlins(size.x * size.y * size.z); + uf::stl::vector pixels(size.x * size.y * size.z); + uf::stl::vector perlins(size.x * size.y * size.z); #pragma omp parallel for for ( uint32_t z = 0; z < size.z; ++z ) { for ( uint32_t y = 0; y < size.y; ++y ) { @@ -158,7 +158,7 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { } // initialize cubemap { - std::vector filenames = { + uf::stl::vector filenames = { uf::io::root+"/textures/skybox/front.png", uf::io::root+"/textures/skybox/back.png", uf::io::root+"/textures/skybox/up.png", @@ -167,7 +167,7 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { uf::io::root+"/textures/skybox/left.png", }; uf::Image::container_t pixels; - std::vector images(filenames.size()); + uf::stl::vector images(filenames.size()); pod::Vector2ui size = {0,0}; auto& texture = sceneTextures.skybox; @@ -250,7 +250,7 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { metadata.shader.scalar = metadataJson["system"]["renderer"]["shader"]["scalar"].as(); metadata.shader.parameters = uf::vector::decode( metadataJson["system"]["renderer"]["shader"]["parameters"], pod::Vector4f{0,0,0,0} ); ext::json::forEach( metadataJson["system"]["renderer"]["shader"]["parameters"], [&]( uint32_t i, const ext::json::Value& value ){ - if ( value.as() == "time" ) metadata.shader.time = i; + if ( value.as() == "time" ) metadata.shader.time = i; }); if ( 0 <= metadata.shader.time && metadata.shader.time < 4 ) { metadata.shader.parameters[metadata.shader.time] = uf::physics::time::current; @@ -349,9 +349,9 @@ void ext::ExtSceneBehavior::tick( uf::Object& self ) { float epsilon = 0.005f; if ( (current + epsilon >= end || !bgm.playing()) && !bgm.loops() ) { // intro to main transition - std::string filename = bgm.getFilename(); + uf::stl::string filename = bgm.getFilename(); filename = assetLoader.getOriginal(filename); - if ( filename.find("_intro") != std::string::npos ) { + if ( filename.find("_intro") != uf::stl::string::npos ) { assetLoader.load(uf::string::replace( filename, "_intro", "" ), this->formatHookName("asset:Load.%UID%")); // loop } else { @@ -382,22 +382,6 @@ void ext::ExtSceneBehavior::tick( uf::Object& self ) { if ( 0 <= metadata.shader.time && metadata.shader.time < 4 ) { metadata.shader.parameters[metadata.shader.time] = uf::physics::time::current; } - - TIMER(1, uf::Window::isKeyPressed("J") && ) { - UF_MSG_DEBUG("metadata.fog.color: " << uf::vector::toString( metadata.fog.color) ); - UF_MSG_DEBUG("metadata.fog.stepScale: " << metadata.fog.stepScale); - UF_MSG_DEBUG("metadata.fog.absorbtion: " << metadata.fog.absorbtion); - UF_MSG_DEBUG("metadata.fog.range: " << metadata.fog.range); - UF_MSG_DEBUG("metadata.fog.density.offset: " << uf::vector::toString( metadata.fog.density.offset ) ); - UF_MSG_DEBUG("metadata.fog.density.timescale: " << metadata.fog.density.timescale); - UF_MSG_DEBUG("metadata.fog.density.threshold: " << metadata.fog.density.threshold); - UF_MSG_DEBUG("metadata.fog.density.multiplier: " << metadata.fog.density.multiplier); - UF_MSG_DEBUG("metadata.fog.density.scale: " << metadata.fog.density.scale); - UF_MSG_DEBUG("metadata.shader.mode: " << (int) metadata.shader.mode); - UF_MSG_DEBUG("metadata.shader.scalar: " << (int) metadata.shader.scalar); - UF_MSG_DEBUG("metadata.shader.parameters: " << uf::vector::toString( metadata.shader.parameters ) ); - UF_MSG_DEBUG("metadata.shader.time: " << (int) metadata.shader.time); - } #endif /* Update lights */ if ( !uf::renderer::settings::experimental::vxgi ) { ext::ExtSceneBehavior::bindBuffers( *this ); @@ -427,7 +411,7 @@ void ext::ExtSceneBehavior::destroy( uf::Object& self ) { } } -void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& renderModeName, bool isCompute ) { +void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const uf::stl::string& renderModeName, bool isCompute ) { auto& graph = this->getGraph(); auto& controller = this->getController(); auto& camera = controller.getComponent(); @@ -438,7 +422,7 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re auto& metadataJson = this->getComponent(); auto& renderMode = uf::renderer::getRenderMode(renderModeName, true); - std::vector blitters = renderMode.getBlitters(); + uf::stl::vector blitters = renderMode.getBlitters(); #if UF_USE_OPENGL struct LightInfo { @@ -449,7 +433,7 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re float distance = 0; float power = 0; }; - std::vector entities; + uf::stl::vector entities; for ( auto entity : graph ) { if ( entity == this || entity == &controller || !entity->hasComponent() ) continue; auto& metadata = entity->getComponent(); @@ -558,33 +542,33 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re int32_t type = 0; bool shadows = false; }; - std::vector entities; + uf::stl::vector entities; entities.reserve(graph.size() / 2); // struct that contains our skybox cubemap, noise texture, and VXGI voxels auto& sceneTextures = this->getComponent(); - std::vector textures2D; + uf::stl::vector textures2D; textures2D.reserve( metadata.max.textures2D ); - std::vector textures3D; + uf::stl::vector textures3D; textures3D.reserve( metadata.max.textures3D ); - std::vector texturesCube; + uf::stl::vector texturesCube; texturesCube.reserve( metadata.max.texturesCube ); // lighting information - std::vector lights; + uf::stl::vector lights; lights.reserve( metadata.max.lights ); // material information - std::vector materials; + uf::stl::vector materials; materials.reserve( metadata.max.textures2D ); materials.emplace_back().colorBase = {0,0,0,0}; // setup our fallback material information // texture information - std::vector textures; + uf::stl::vector textures; textures.reserve( metadata.max.textures2D ); // drawcall information - std::vector drawCalls; + uf::stl::vector drawCalls; drawCalls.reserve( metadata.max.textures2D ); // traverse scene graph @@ -798,7 +782,7 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re auto& shader = graphic.material.getShader(isCompute ? "compute" : "fragment"); - std::vector previousTextures; + uf::stl::vector previousTextures; for ( auto& texture : graphic.material.textures ) previousTextures.emplace_back(texture.image); graphic.material.textures.clear(); diff --git a/ext/behaviors/scene/behavior.h b/ext/behaviors/scene/behavior.h index 6094a4cb..83f46c37 100644 --- a/ext/behaviors/scene/behavior.h +++ b/ext/behaviors/scene/behavior.h @@ -63,6 +63,6 @@ namespace ext { std::function deserialize; }; - void bindBuffers( uf::Object&, const std::string& = "", bool = false ); + void bindBuffers( uf::Object&, const uf::stl::string& = "", bool = false ); } } \ No newline at end of file diff --git a/ext/behaviors/scene/collision/behavior.cpp b/ext/behaviors/scene/collision/behavior.cpp index c02035f1..95c55689 100644 --- a/ext/behaviors/scene/collision/behavior.cpp +++ b/ext/behaviors/scene/collision/behavior.cpp @@ -49,8 +49,8 @@ void ext::SceneCollisionBehavior::tick( uf::Object& self ) { bool ignoreDuplicateTests = metadata["system"]["physics"]["optimizations"]["ignore duplicate tests"].as(); bool useWorkers = metadata["system"]["physics"]["use"]["worker"].as(); - std::vector> jobs; - std::vector entities; { + uf::stl::vector> jobs; + uf::stl::vector entities; { // update physics if ( updatePhysics ) { this->process([&]( uf::Entity* entity ) { @@ -112,14 +112,14 @@ void ext::SceneCollisionBehavior::tick( uf::Object& self ) { uf::Object* a = NULL; uf::Object* b = NULL; }; - std::unordered_map queued; + uf::stl::unordered_map queued; for ( auto* _a : entities ) { uf::Object& entityA = *_a; if ( ignoreStaticEntities && !entityA.hasComponent() ) continue; for ( auto* _b : entities ) { if ( _a == _b ) continue; uf::Object& entityB = *_b; - std::string hash = std::to_string(std::min( entityA.getUid(), entityB.getUid() )) + ":" + std::to_string(std::max( entityA.getUid(), entityB.getUid() )); + uf::stl::string hash = std::to_string(std::min( entityA.getUid(), entityB.getUid() )) + ":" + std::to_string(std::max( entityA.getUid(), entityB.getUid() )); if ( queued.count(hash) > 0 ) continue; queued[hash] = { @@ -173,7 +173,7 @@ void ext::SceneCollisionBehavior::tick( uf::Object& self ) { /* pod::Thread& thread = uf::thread::has("Physics") ? uf::thread::get("Physics") : uf::thread::create( "Physics", true, false ); auto function = [&]() -> int { - std::vector entities; + uf::stl::vector entities; // update physics if ( updatePhysics ) { this->process([&]( uf::Entity* entity ) { @@ -235,14 +235,14 @@ void ext::SceneCollisionBehavior::tick( uf::Object& self ) { uf::Object* a = NULL; uf::Object* b = NULL; }; - std::unordered_map queued; + uf::stl::unordered_map queued; for ( auto* _a : entities ) { uf::Object& entityA = *_a; if ( ignoreStaticEntities && !entityA.hasComponent() ) continue; for ( auto* _b : entities ) { if ( _a == _b ) continue; uf::Object& entityB = *_b; - std::string hash = std::to_string(std::min( entityA.getUid(), entityB.getUid() )) + ":" + std::to_string(std::max( entityA.getUid(), entityB.getUid() )); + uf::stl::string hash = std::to_string(std::min( entityA.getUid(), entityB.getUid() )) + ":" + std::to_string(std::max( entityA.getUid(), entityB.getUid() )); if ( queued.count(hash) > 0 ) continue; queued[hash] = { diff --git a/ext/behaviors/soundemitter/behavior.cpp b/ext/behaviors/soundemitter/behavior.cpp index 341b0fba..6c1bcc64 100644 --- a/ext/behaviors/soundemitter/behavior.cpp +++ b/ext/behaviors/soundemitter/behavior.cpp @@ -24,7 +24,7 @@ void ext::SoundEmitterBehavior::initialize( uf::Object& self ) { metadata["audio"]["epsilon"] = 0.001f; this->addHook( "sound:Stop.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); for ( size_t i = 0; i < sounds.size(); ++i ) { if ( sounds[i].getFilename() != filename ) continue; sounds[i].destroy(); @@ -44,7 +44,7 @@ void ext::SoundEmitterBehavior::initialize( uf::Object& self ) { if ( ext::json::isNull(json["unique"]) ) json["unique"] = metadata["audio"]["unique"]; metadata["sounds"].emplace_back(json); - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); bool unique = json["unique"].as(); bool exists = unique && emitter.has( filename ); @@ -66,8 +66,8 @@ void ext::SoundEmitterBehavior::initialize( uf::Object& self ) { float volume = 1.0f; if ( json["volume"].is() ) volume = json["volume"].as(); - else if ( json["volume"].is() ) { - std::string key = json["volume"].as(); + else if ( json["volume"].is() ) { + uf::stl::string key = json["volume"].as(); if ( sMetadata["volumes"][key].is() ) volume = sMetadata["volumes"][key].as(); } audio.setVolume(volume); @@ -75,8 +75,8 @@ void ext::SoundEmitterBehavior::initialize( uf::Object& self ) { audio.play(); }); this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); if ( category != "" && (category != "audio" && category != "audio-stream") ) return; if ( category == "" && uf::io::extension(filename) != "ogg" ) return; diff --git a/ext/behaviors/sprite/behavior.cpp b/ext/behaviors/sprite/behavior.cpp index 1ff44412..7f1eeeda 100644 --- a/ext/behaviors/sprite/behavior.cpp +++ b/ext/behaviors/sprite/behavior.cpp @@ -19,17 +19,17 @@ #include "../../scenes/worldscape//.h" namespace { - uf::Serializer masterTableGet( const std::string& table ) { + uf::Serializer masterTableGet( const uf::stl::string& table ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table]; } - uf::Serializer masterDataGet( const std::string& table, const std::string& key ) { + uf::Serializer masterDataGet( const uf::stl::string& table, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table][key]; } - inline int64_t parseInt( const std::string& str ) { + inline int64_t parseInt( const uf::stl::string& str ) { return atoi(str.c_str()); } } @@ -44,8 +44,8 @@ void ext::HousamoSpriteBehavior::initialize( uf::Object& self ) { this->addHook( "graphics:Assign.%UID%", [&](ext::json::Value& json){ metadata["system"]["control"] = false; - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); if ( category != "" && category != "images" ) return; if ( category == "" && uf::io::extension(filename) != "png" && uf::io::extension(filename) != "jpg" && uf::io::extension(filename) != "jpeg" ) return; @@ -93,17 +93,17 @@ void ext::HousamoSpriteBehavior::initialize( uf::Object& self ) { }); { - std::string id = metadata[""]["party"][0].as(); + uf::stl::string id = metadata[""]["party"][0].as(); uf::Serializer member = metadata[""]["transients"][id]; uf::Serializer cardData = masterDataGet("Card", id); - std::string name = cardData["filename"].as(); - if ( member["skin"].is() ) name += "_" + member["skin"].as(); - std::string filename = "https://cdn..xyz//unity/Android/fg/fg_" + name + ".png"; + uf::stl::string name = cardData["filename"].as(); + if ( member["skin"].is() ) name += "_" + member["skin"].as(); + uf::stl::string filename = "https://cdn..xyz//unity/Android/fg/fg_" + name + ".png"; if ( cardData["internal"].as() ) { filename = uf::io::root+"/smtsamo/fg/fg_" + name + ".png"; } - metadata["orientation"] = cardData["orientation"].as() == "" ? "portrait" : "landscape"; + metadata["orientation"] = cardData["orientation"].as() == "" ? "portrait" : "landscape"; assetLoader.load(filename, "asset:Load." + std::to_string(this->getUid()) ); } diff --git a/ext/behaviors/voxelizer/behavior.cpp b/ext/behaviors/voxelizer/behavior.cpp index f3aee059..1b29b449 100644 --- a/ext/behaviors/voxelizer/behavior.cpp +++ b/ext/behaviors/voxelizer/behavior.cpp @@ -51,7 +51,7 @@ void ext::VoxelizerBehavior::initialize( uf::Object& self ) { metadata.extents.min = uf::vector::decode( ext::config["engine"]["scenes"]["vxgi"]["extents"]["min"], pod::Vector3f{-32, -32, -32} ); metadata.extents.max = uf::vector::decode( ext::config["engine"]["scenes"]["vxgi"]["extents"]["max"], pod::Vector3f{ 32, 32, 32} ); - // std::vector empty(metadata.voxelSize.x * metadata.voxelSize.y * metadata.voxelSize.z * sizeof(uint8_t) * 4); + // uf::stl::vector empty(metadata.voxelSize.x * metadata.voxelSize.y * metadata.voxelSize.z * sizeof(uint8_t) * 4); const bool HDR = false; for ( size_t i = 0; i < metadata.cascades; ++i ) { auto& id = sceneTextures.voxels.id.emplace_back(); @@ -87,7 +87,7 @@ void ext::VoxelizerBehavior::initialize( uf::Object& self ) { renderMode.width = metadata.fragmentSize.x; renderMode.height = metadata.fragmentSize.y; - std::string computeShaderFilename = "/shaders/display/vxgi.comp.spv"; + uf::stl::string computeShaderFilename = "/shaders/display/vxgi.comp.spv"; if ( renderMode.metadata.samples > 1 ) { computeShaderFilename = uf::string::replace( computeShaderFilename, "frag", "msaa.frag" ); } diff --git a/ext/behaviors/voxelizer/behavior.h b/ext/behaviors/voxelizer/behavior.h index cd6376a2..5e65f41e 100644 --- a/ext/behaviors/voxelizer/behavior.h +++ b/ext/behaviors/voxelizer/behavior.h @@ -19,7 +19,7 @@ namespace ext { pod::Vector3ui fragmentSize = { 0, 0 }; pod::Vector3ui voxelSize = { 0, 0, 0 }; pod::Vector3ui dispatchSize = { 0, 0, 0 }; - std::string renderModeName = "VXGI"; + uf::stl::string renderModeName = "VXGI"; size_t cascades = 0; float cascadePower = 0; diff --git a/ext/gui/behavior.cpp b/ext/gui/behavior.cpp index c18f0dab..0bb88961 100644 --- a/ext/gui/behavior.cpp +++ b/ext/gui/behavior.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -35,13 +35,13 @@ namespace { #if UF_USE_FREETYPE struct { ext::freetype::Glyph glyph; - std::unordered_map> cache; + uf::stl::unordered_map> cache; } glyphs; #endif - std::string defaultRenderMode = "Gui"; + uf::stl::string defaultRenderMode = "Gui"; uf::Serializer defaultSettings; - std::vector metadataKeys = { + uf::stl::vector metadataKeys = { "alpha", "color", "depth", @@ -61,11 +61,11 @@ namespace { "world", }; } -std::vector ext::Gui::generateGlyphs( const std::string& _string ) { - std::vector gs; +uf::stl::vector ext::Gui::generateGlyphs( const uf::stl::string& _string ) { + uf::stl::vector gs; #if UF_USE_FREETYPE uf::Object& gui = *this; - std::string string = _string; + uf::stl::string string = _string; auto& metadata = gui.getComponent(); auto& metadataGlyph = gui.getComponent(); auto& metadataJson = gui.getComponent(); @@ -73,8 +73,8 @@ std::vector ext::Gui::generateGlyphs( const std::string& _string metadata.deserialize(); metadataGlyph.deserialize(); -// std::string font = uf::io::root+"/fonts/" + metadataJson["text settings"]["font"].as(); - std::string font = uf::io::root+"/fonts/" + metadataGlyph.font; +// uf::stl::string font = uf::io::root+"/fonts/" + metadataJson["text settings"]["font"].as(); + uf::stl::string font = uf::io::root+"/fonts/" + metadataGlyph.font; if ( ::glyphs.cache[font].empty() ) { ext::freetype::initialize( ::glyphs.glyph, font ); } @@ -109,7 +109,7 @@ std::vector ext::Gui::generateGlyphs( const std::string& _string } box; struct { - std::vector container; + uf::stl::vector container; std::size_t index = 0; } colors; } stat; @@ -120,24 +120,24 @@ std::vector ext::Gui::generateGlyphs( const std::string& _string unsigned long COLORCONTROL = 0x7F; { - std::string text = string; + uf::stl::string text = string; std::regex regex("\\%\\#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})\\%"); - std::unordered_map colors; + uf::stl::unordered_map colors; std::smatch match; bool matched = false; int maxTries = 128; while ( (matched = std::regex_search( text, match, regex )) && --maxTries > 0 ) { struct { - std::string str; + uf::stl::string str; int dec; } r, g, b; r.str = match[1].str(); g.str = match[2].str(); b.str = match[3].str(); - { std::stringstream stream; stream << r.str; stream >> std::hex >> r.dec; } - { std::stringstream stream; stream << g.str; stream >> std::hex >> g.dec; } - { std::stringstream stream; stream << b.str; stream >> std::hex >> b.dec; } + { uf::stl::stringstream stream; stream << r.str; stream >> std::hex >> r.dec; } + { uf::stl::stringstream stream; stream << g.str; stream >> std::hex >> g.dec; } + { uf::stl::stringstream stream; stream << b.str; stream >> std::hex >> b.dec; } pod::Vector3f color = { r.dec / 255.0f, g.dec / 255.0f, b.dec / 255.0f }; @@ -159,7 +159,7 @@ std::vector ext::Gui::generateGlyphs( const std::string& _string // Find tallest glyph for new line for ( auto it = str.begin(); it != str.end(); ++it ) { unsigned long c = *it; if ( c == '\n' ) continue; if ( c == '\t' ) continue; if ( c == 0x01 ) continue; - std::string key = ""; { + uf::stl::string key = ""; { key += std::to_string(c) + ";"; key += std::to_string(metadataGlyph.padding[0]) + ","; key += std::to_string(metadataGlyph.padding[1]) + ";"; @@ -210,7 +210,7 @@ std::vector ext::Gui::generateGlyphs( const std::string& _string } else if ( c == COLORCONTROL ) { continue; } - std::string key = ""; { + uf::stl::string key = ""; { key += std::to_string(c) + ";"; key += std::to_string(metadataGlyph.padding[0]) + ","; key += std::to_string(metadataGlyph.padding[1]) + ";"; @@ -268,7 +268,7 @@ std::vector ext::Gui::generateGlyphs( const std::string& _string ++stat.colors.index; continue; } - std::string key = ""; { + uf::stl::string key = ""; { key += std::to_string(c) + ";"; key += std::to_string(metadataGlyph.padding[0]) + ","; key += std::to_string(metadataGlyph.padding[1]) + ";"; @@ -332,7 +332,7 @@ void ext::Gui::load( const uf::Image& image ) { pod::Vector2f raidou = { 1, 1 }; bool modified = false; - if ( metadataJson["mode"].as() == "flat" ) { + if ( metadataJson["mode"].as() == "flat" ) { if ( ext::json::isNull(metadataJson["projection"]) ) metadataJson["projection"] = false; if ( ext::json::isNull(metadataJson["flip uv"]) ) metadataJson["flip uv"] = true; if ( ext::json::isNull(metadataJson["front face"]) ) metadataJson["front face"] = "ccw"; @@ -355,8 +355,8 @@ void ext::Gui::load( const uf::Image& image ) { } if ( metadata.depth != 0.0f ) for ( auto& v : mesh.vertices ) v.position.z = metadata.depth; - if ( metadataJson["scaling"].is() ) { - std::string mode = metadataJson["scaling"].as(); + if ( metadataJson["scaling"].is() ) { + uf::stl::string mode = metadataJson["scaling"].as(); if ( mode == "mesh" ) { // raidou.x = (float) image.getDimensions().x / image.getDimensions().y; raidou.y = (float) image.getDimensions().y / image.getDimensions().x; @@ -370,26 +370,26 @@ void ext::Gui::load( const uf::Image& image ) { transform.scale.x = raidou.x; transform.scale.y = raidou.y; } - if ( metadataJson["layer"].is() ) { - graphic.initialize( metadataJson["layer"].as() ); + if ( metadataJson["layer"].is() ) { + graphic.initialize( metadataJson["layer"].as() ); } else if ( !ext::json::isNull( metadataJson["gui layer"] ) && !metadataJson["gui layer"].as() ) { graphic.initialize(); - } else if ( metadataJson["gui layer"].is() ) { - graphic.initialize( metadataJson["gui layer"].as() ); + } else if ( metadataJson["gui layer"].is() ) { + graphic.initialize( metadataJson["gui layer"].as() ); } else { graphic.initialize( ::defaultRenderMode ); } graphic.initializeMesh( mesh ); struct { - std::string vertex = uf::io::root+"/shaders/gui/base.vert.spv"; - std::string fragment = uf::io::root+"/shaders/gui/base.frag.spv"; + uf::stl::string vertex = uf::io::root+"/shaders/gui/base.vert.spv"; + uf::stl::string fragment = uf::io::root+"/shaders/gui/base.frag.spv"; } filenames; - std::string suffix = ""; { - std::string _ = scene.getComponent()["shaders"]["gui"]["suffix"].as(); + uf::stl::string suffix = ""; { + uf::stl::string _ = scene.getComponent()["shaders"]["gui"]["suffix"].as(); if ( _ != "" ) suffix = _ + "."; } - if ( metadataJson["shaders"]["vertex"].is() ) filenames.vertex = metadataJson["shaders"]["vertex"].as(); - if ( metadataJson["shaders"]["fragment"].is() ) filenames.fragment = metadataJson["shaders"]["fragment"].as(); + if ( metadataJson["shaders"]["vertex"].is() ) filenames.vertex = metadataJson["shaders"]["vertex"].as(); + if ( metadataJson["shaders"]["fragment"].is() ) filenames.fragment = metadataJson["shaders"]["fragment"].as(); else if ( suffix != "" ) filenames.fragment = uf::io::root+"/shaders/gui/"+suffix+"base.frag.spv"; graphic.material.initializeShaders({ @@ -467,8 +467,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { metadata.deserialize(); this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){ - std::string filename = json["filename"].as(); - std::string category = json["category"].as(); + uf::stl::string filename = json["filename"].as(); + uf::stl::string category = json["category"].as(); if ( category != "" && category != "images" ) return; if ( category == "" && uf::io::extension(filename) != "png" && uf::io::extension(filename) != "jpg" && uf::io::extension(filename) != "jpeg" ) return; @@ -496,16 +496,16 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { uf::Serializer event = metadataJson["events"]["click"][i]; uf::Serializer payload = event["payload"]; if ( event["delay"].is() ) { - this->queueHook(event["name"].as(), payload, event["delay"].as()); + this->queueHook(event["name"].as(), payload, event["delay"].as()); } else { - this->callHook(event["name"].as(), payload ); + this->callHook(event["name"].as(), payload ); } } }); this->addHook( "window:Mouse.Click", [&](ext::json::Value& json){ if ( metadata.world ) return; if ( !metadata.box.min && !metadata.box.max ) return; - bool down = json["mouse"]["state"].as() == "Down"; + bool down = json["mouse"]["state"].as() == "Down"; bool clicked = false; if ( down ) { pod::Vector2ui position = uf::vector::decode( json["mouse"]["position"], pod::Vector2ui{} ); { @@ -557,9 +557,9 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { uf::Serializer payload = event["payload"]; float delay = event["delay"].as(); if ( event["delay"].is() ) { - this->queueHook(event["name"].as(), payload, event["delay"].as()); + this->queueHook(event["name"].as(), payload, event["delay"].as()); } else { - this->callHook(event["name"].as(), payload ); + this->callHook(event["name"].as(), payload ); } } return; @@ -572,7 +572,7 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { if ( !metadata.box.min && !metadata.box.max ) return; bool clicked = false; - bool down = json["mouse"]["state"].as() == "Down"; + bool down = json["mouse"]["state"].as() == "Down"; pod::Vector2ui position = uf::vector::decode( json["mouse"]["position"], pod::Vector2ui{} ); pod::Vector2f click; { click.x = (float) position.x / (float) ext::gui::size.current.x; @@ -596,10 +596,10 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { } ); } #if UF_USE_FREETYPE - if ( metadataJson["text settings"]["string"].is() ) { + if ( metadataJson["text settings"]["string"].is() ) { if ( ext::json::isNull( ::defaultSettings["metadata"] ) ) ::defaultSettings.readFromFile(uf::io::root+"/entities/gui/text/string.json"); - ext::json::forEach(::defaultSettings["metadata"]["text settings"], [&]( const std::string& key, ext::json::Value& value ){ + ext::json::forEach(::defaultSettings["metadata"]["text settings"], [&]( const uf::stl::string& key, ext::json::Value& value ){ if ( ext::json::isNull( metadataJson["text settings"][key] ) ) metadataJson["text settings"][key] = value; }); @@ -634,8 +634,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { if ( !ext::json::isNull( metadataJson[key] ) ) metadataJson["gui"][key] = metadataJson[key]; if ( !ext::json::isNull( metadataJson["text settings"][key] ) ) metadataJson["gui"][key] = metadataJson["text settings"][key]; } - metadataGlyph.font = metadataJson["gui"]["font"].as(); - metadataGlyph.string = metadataJson["gui"]["string"].as(); + metadataGlyph.font = metadataJson["gui"]["font"].as(); + metadataGlyph.string = metadataJson["gui"]["string"].as(); metadataGlyph.scale = metadataJson["gui"]["scale"].as(); metadataGlyph.padding = uf::vector::decode( metadataJson["gui"]["padding"], metadataGlyph.padding ); @@ -646,18 +646,18 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { metadataGlyph.shadowbox = metadataJson["gui"]["shadowbox"].as(); metadataGlyph.stroke = uf::vector::decode( metadataJson["gui"]["stroke"], metadataGlyph.stroke ); - metadataGlyph.origin = metadataJson["gui"]["origin"].as(); - metadataGlyph.align = metadataJson["gui"]["align"].as(); - metadataGlyph.direction = metadataJson["gui"]["direction"].as(); + metadataGlyph.origin = metadataJson["gui"]["origin"].as(); + metadataGlyph.align = metadataJson["gui"]["align"].as(); + metadataGlyph.direction = metadataJson["gui"]["direction"].as(); }; this->addHook( "object:UpdateMetadata.%UID%", metadataGlyph.deserialize); #if 0 metadataGlyph.deserialize(); { - std::vector glyphs = this->as().generateGlyphs(); + uf::stl::vector glyphs = this->as().generateGlyphs(); - std::string font = uf::io::root+"/fonts/" + metadataGlyph.font; - std::string key = ""; { + uf::stl::string font = uf::io::root+"/fonts/" + metadataGlyph.font; + uf::stl::string key = ""; { key += std::to_string(metadataGlyph.padding[0]) + ","; key += std::to_string(metadataGlyph.padding[1]) + ";"; key += std::to_string(metadataGlyph.spread) + ";"; @@ -671,7 +671,7 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { auto& mesh = this->getComponent(); auto& graphic = this->getComponent(); - if ( metadataJson["mode"].as() == "flat" ) { + if ( metadataJson["mode"].as() == "flat" ) { if ( ext::json::isNull(metadataJson["projection"]) ) metadataJson["projection"] = false; if ( ext::json::isNull(metadataJson["front face"]) ) metadataJson["front face"] = "ccw"; #if UF_USE_OPENGL @@ -687,7 +687,7 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { graphic.descriptor.parse( metadataJson ); mesh.vertices.reserve( glyphs.size() * 6 ); - std::unordered_map glyphHashMap; + uf::stl::unordered_map glyphHashMap; for ( auto& g : glyphs ) { auto glyphKey = std::to_string((uint64_t) g.code) + ";"+key; auto& glyph = ::glyphs.cache[font][glyphKey]; @@ -742,16 +742,16 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { graphic.initialize( ::defaultRenderMode ); graphic.initializeMesh( mesh ); - std::string suffix = ""; { - std::string _ = scene.getComponent()["shaders"]["gui"]["suffix"].as(); + uf::stl::string suffix = ""; { + uf::stl::string _ = scene.getComponent()["shaders"]["gui"]["suffix"].as(); if ( _ != "" ) suffix = _ + "."; } struct { - std::string vertex = uf::io::root+"/shaders/gui/text.vert.spv"; - std::string fragment = uf::io::root+"/shaders/gui/text.frag.spv"; + uf::stl::string vertex = uf::io::root+"/shaders/gui/text.vert.spv"; + uf::stl::string fragment = uf::io::root+"/shaders/gui/text.frag.spv"; } filenames; - if ( metadataJson["shaders"]["vertex"].is() ) filenames.vertex = metadataJson["shaders"]["vertex"].as(); - if ( metadataJson["shaders"]["fragment"].is() ) filenames.fragment = metadataJson["shaders"]["fragment"].as(); + if ( metadataJson["shaders"]["vertex"].is() ) filenames.vertex = metadataJson["shaders"]["vertex"].as(); + if ( metadataJson["shaders"]["fragment"].is() ) filenames.fragment = metadataJson["shaders"]["fragment"].as(); else if ( suffix != "" ) filenames.fragment = uf::io::root+"/shaders/gui/text."+suffix+"frag.spv"; graphic.material.initializeShaders({ @@ -765,21 +765,21 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { this->queueHook( "gui:UpdateString.%UID%"); }); this->addHook( "gui:UpdateString.%UID%", [&](ext::json::Value& json){ - ext::json::forEach(::defaultSettings["metadata"]["text settings"], [&]( const std::string& key, ext::json::Value& value ){ + ext::json::forEach(::defaultSettings["metadata"]["text settings"], [&]( const uf::stl::string& key, ext::json::Value& value ){ if ( ext::json::isNull( metadataJson["text settings"][key] ) ) metadataJson["text settings"][key] = value; }); - if ( json["string"].is() ) metadataJson["text settings"]["string"] = json["string"]; - std::string string = metadataJson["text settings"]["string"].as(); + if ( json["string"].is() ) metadataJson["text settings"]["string"] = json["string"]; + uf::stl::string string = metadataJson["text settings"]["string"].as(); auto& metadataGlyph = this->getComponent(); bool first = metadataGlyph.string == "" || json["first"].as(); metadataGlyph.deserialize(); - std::vector glyphs = this->as().generateGlyphs( string ); - std::string font = uf::io::root+"/fonts/" + metadataGlyph.font; - std::string key = ""; { + uf::stl::vector glyphs = this->as().generateGlyphs( string ); + uf::stl::string font = uf::io::root+"/fonts/" + metadataGlyph.font; + uf::stl::string key = ""; { key += std::to_string(metadataGlyph.padding[0]) + ","; key += std::to_string(metadataGlyph.padding[1]) + ";"; key += std::to_string(metadataGlyph.spread) + ";"; @@ -802,7 +802,7 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { } mesh.vertices.reserve( glyphs.size() * 6 ); - std::unordered_map glyphHashMap; + uf::stl::unordered_map glyphHashMap; for ( auto& g : glyphs ) { auto glyphKey = std::to_string((uint64_t) g.code) + ";"+key; auto& glyph = ::glyphs.cache[font][glyphKey]; @@ -857,16 +857,16 @@ void ext::GuiBehavior::initialize( uf::Object& self ) { graphic.initialize( ::defaultRenderMode ); graphic.initializeMesh( mesh ); - std::string suffix = ""; { - std::string _ = scene.getComponent()["shaders"]["gui"]["suffix"].as(); + uf::stl::string suffix = ""; { + uf::stl::string _ = scene.getComponent()["shaders"]["gui"]["suffix"].as(); if ( _ != "" ) suffix = _ + "."; } struct { - std::string vertex = uf::io::root+"/shaders/gui/text.vert.spv"; - std::string fragment = uf::io::root+"/shaders/gui/text.frag.spv"; + uf::stl::string vertex = uf::io::root+"/shaders/gui/text.vert.spv"; + uf::stl::string fragment = uf::io::root+"/shaders/gui/text.frag.spv"; } filenames; - if ( metadataJson["shaders"]["vertex"].is() ) filenames.vertex = metadataJson["shaders"]["vertex"].as(); - if ( metadataJson["shaders"]["fragment"].is() ) filenames.fragment = metadataJson["shaders"]["fragment"].as(); + if ( metadataJson["shaders"]["vertex"].is() ) filenames.vertex = metadataJson["shaders"]["vertex"].as(); + if ( metadataJson["shaders"]["fragment"].is() ) filenames.fragment = metadataJson["shaders"]["fragment"].as(); else if ( suffix != "" ) filenames.fragment = uf::io::root+"/shaders/gui/text."+suffix+"frag.spv"; graphic.material.initializeShaders({ diff --git a/ext/gui/behavior.h b/ext/gui/behavior.h index 2f57f06d..33943584 100644 --- a/ext/gui/behavior.h +++ b/ext/gui/behavior.h @@ -35,8 +35,8 @@ namespace ext { std::function deserialize; }; struct GlyphMetadata { - std::string font = ""; - std::string string = ""; + uf::stl::string font = ""; + uf::stl::string string = ""; float scale = 0; pod::Vector2f padding = {0,0}; @@ -48,9 +48,9 @@ namespace ext { bool shadowbox = false; pod::Vector4f stroke = {0,0,0,0}; - std::string origin = ""; - std::string align = ""; - std::string direction = ""; + uf::stl::string origin = ""; + uf::stl::string align = ""; + uf::stl::string direction = ""; std::function serialize; std::function deserialize; diff --git a/ext/gui/gui.h b/ext/gui/gui.h index 36880df4..d128aef6 100644 --- a/ext/gui/gui.h +++ b/ext/gui/gui.h @@ -25,7 +25,7 @@ namespace ext { typedef uf::BaseMesh mesh_t; typedef uf::BaseMesh glyph_mesh_t; // Gui(); - std::vector generateGlyphs( const std::string& = "" ); + uf::stl::vector generateGlyphs( const uf::stl::string& = "" ); void load( const uf::Image& ); }; namespace gui { diff --git a/ext/gui/html/behavior.cpp b/ext/gui/html/behavior.cpp index 5ffe4cc4..d4fb6971 100644 --- a/ext/gui/html/behavior.cpp +++ b/ext/gui/html/behavior.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -52,8 +52,8 @@ void ext::GuiHtmlBehavior::initialize( uf::Object& self ) { // size.y = ext::config["window"]["size"]["y"].as(); size = uf::vector::decode( ext::config["window"]["size"], pod::Vector2ui{} ); } - page = ext::ultralight::create( page, metadata["html"].as(), size); - std::string onLoad = this->formatHookName("html:Load.%UID%"); + page = ext::ultralight::create( page, metadata["html"].as(), size); + uf::stl::string onLoad = this->formatHookName("html:Load.%UID%"); if ( metadata["wait for load"].as() ) { ext::ultralight::on(page, "load", onLoad); this->addHook( onLoad, [&](ext::json::Value& json){ @@ -80,7 +80,7 @@ void ext::GuiHtmlBehavior::initialize( uf::Object& self ) { }); this->addHook( "window:Key", [&](ext::json::Value& json){ - if ( json["type"].as() == "window:Text.Entered" ) return; + if ( json["type"].as() == "window:Text.Entered" ) return; if ( metadata["ignore inputs"].as() ) return; ext::ultralight::input( page, json ); }); diff --git a/ext/gui/manager/behavior.cpp b/ext/gui/manager/behavior.cpp index dee4e2b3..796472ea 100644 --- a/ext/gui/manager/behavior.cpp +++ b/ext/gui/manager/behavior.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -50,31 +50,26 @@ void ext::GuiManagerBehavior::initialize( uf::Object& self ) { // add gui render mode if ( !uf::renderer::hasRenderMode( "Gui", true ) ) { auto& renderMode = this->getComponent(); - std::string name = "Gui"; + uf::stl::string name = "Gui"; uf::renderer::addRenderMode( &renderMode, name ); renderMode.blitter.descriptor.subpass = 1; } - auto& metadataJson = this->getComponent(); - auto& assetLoader = this->getComponent(); + auto& scene = uf::scene::getCurrentScene(); + auto& controller = scene.getController(); + auto& metadata = controller.getComponent(); + auto& metadataJson = controller.getComponent(); this->addHook( "window:Resized", [&](ext::json::Value& json){ - - pod::Vector2ui size = uf::vector::decode( json["window"]["size"], pod::Vector2ui{} ); { - // size.x = json["window"]["size"]["x"].as(); - // size.y = json["window"]["size"]["y"].as(); - } + pod::Vector2ui size = uf::vector::decode( json["window"]["size"], pod::Vector2ui{} ); ext::gui::size.current = size; // ext::gui::size.reference = size; } ); this->addHook( "window:Mouse.Moved", [&](ext::json::Value& json){ - - bool down = json["mouse"]["state"].as() == "Down"; bool clicked = false; - pod::Vector2ui position = uf::vector::decode( json["mouse"]["position"], pod::Vector2ui{} ); { - // position.x = json["mouse"]["position"]["x"].as() > 0 ? json["mouse"]["position"]["x"].as() : 0; - // position.y = json["mouse"]["position"]["y"].as() > 0 ? json["mouse"]["position"]["y"].as() : 0; - } + bool down = json["mouse"]["state"].as() == "Down"; + pod::Vector2ui position = uf::vector::decode( json["mouse"]["position"], pod::Vector2ui{} ); + pod::Vector2f click; { click.x = (float) position.x / (float) ext::gui::size.current.x; click.y = (float) position.y / (float) ext::gui::size.current.y; @@ -83,27 +78,40 @@ void ext::GuiManagerBehavior::initialize( uf::Object& self ) { float x = click.x; float y = click.y; } - - { - auto& scene = uf::scene::getCurrentScene(); - auto& controller = scene.getController(); - auto& metadata = controller.getComponent(); - auto& metadataJson = controller.getComponent(); - // if ( metadata.cursor.type == "mouse" ) metadata.cursor.position = click; - if ( metadataJson["overlay"]["cursor"]["type"].as() == "mouse" ) { - metadataJson["overlay"]["cursor"]["position"] = uf::vector::encode( click ); - } + if ( metadata.overlay.cursor.type == "mouse" ) { + metadata.overlay.cursor.position = click; } }); + + metadata.serialize = [&](){ + metadataJson["overlay"]["enabled"] = metadata.overlay.enabled; + metadataJson["overlay"]["floating"] = metadata.overlay.floating; + metadataJson["overlay"]["transform"] = uf::transform::encode( metadata.overlay.transform ); + + metadataJson["overlay"]["cursor"]["type"] = metadata.overlay.cursor.type; + metadataJson["overlay"]["cursor"]["enabled"] = metadata.overlay.cursor.enabled; + metadataJson["overlay"]["cursor"]["position"] = uf::vector::encode( metadata.overlay.cursor.position ); + metadataJson["overlay"]["cursor"]["radius"] = metadata.overlay.cursor.radius; + metadataJson["overlay"]["cursor"]["color"] = uf::vector::encode( metadata.overlay.cursor.color ); + }; + metadata.deserialize = [&](){ + metadata.overlay.enabled = metadataJson["overlay"]["enabled"].as( metadata.overlay.enabled ); + metadata.overlay.floating = metadataJson["overlay"]["floating"].as( metadata.overlay.floating ); + metadata.overlay.transform = uf::transform::decode( metadataJson["overlay"]["transform"], metadata.overlay.transform ); + + metadata.overlay.cursor.type = metadataJson["overlay"]["cursor"]["type"].as( metadata.overlay.cursor.type ); + metadata.overlay.cursor.enabled = metadataJson["overlay"]["cursor"]["enabled"].as( metadata.overlay.cursor.enabled ); + metadata.overlay.cursor.position = uf::vector::decode( metadataJson["overlay"]["cursor"]["position"], metadata.overlay.cursor.position ); + metadata.overlay.cursor.radius = metadataJson["overlay"]["cursor"]["radius"].as( metadata.overlay.cursor.radius ); + metadata.overlay.cursor.color = uf::vector::decode( metadataJson["overlay"]["cursor"]["color"], metadata.overlay.cursor.color ); + }; + this->addHook( "object:UpdateMetadata.%UID%", metadata.deserialize); + metadata.deserialize(); } void ext::GuiManagerBehavior::tick( uf::Object& self ) { } void ext::GuiManagerBehavior::render( uf::Object& self ){ #if UF_USE_VULKAN - auto& scene = uf::scene::getCurrentScene(); - auto& controller = scene.getController(); - auto& camera = controller.getComponent(); - auto& metadataJson = controller.getComponent(); uf::renderer::RenderTargetRenderMode* renderModePointer = NULL; if ( this->hasComponent() ) { @@ -117,6 +125,16 @@ void ext::GuiManagerBehavior::render( uf::Object& self ){ if ( !blitter.initialized ) return; if ( !blitter.material.hasShader("fragment") ) return; + auto& scene = uf::scene::getCurrentScene(); + auto& controller = scene.getController(); + auto& camera = controller.getComponent(); + auto& metadata = this->getComponent(); + auto& metadataJson = controller.getComponent(); +#if UF_ENTITY_METADATA_USE_JSON + metadata.deserialize(); +#else + if ( metadata.overlay.cursor.type == "" && metadata.deserialize ) metadata.deserialize(); +#endif struct UniformDescriptor { struct { /*alignas(16)*/ pod::Matrix4f models[2]; @@ -128,26 +146,22 @@ void ext::GuiManagerBehavior::render( uf::Object& self ){ } cursor; // /*alignas(8)*/ pod::Vector2f alpha; }; - + auto& shader = blitter.material.getShader("vertex"); auto& uniform = shader.getUniform("UBO"); auto& uniforms = uniform.get(); for ( size_t i = 0; i < 2; ++i ) { - pod::Transform<> transform; - transform.position = uf::vector::decode( metadataJson["overlay"]["position"], transform.position ); - transform.scale = uf::vector::decode( metadataJson["overlay"]["scale"], transform.scale ); - transform.orientation = uf::vector::decode( metadataJson["overlay"]["orientation"], transform.orientation ); #if UF_USE_OPENVR - if ( ext::openvr::enabled && metadataJson["overlay"]["enabled"].as() ) { - if ( metadataJson["overlay"]["floating"].as() ) { - pod::Matrix4f model = uf::transform::model( transform ); + if ( ext::openvr::enabled && metadata.overlay.enabled ) { + if ( metadata.overlay.floating ) { + pod::Matrix4f model = uf::transform::model( metadata.overlay.transform ); uniforms.matrices.models[i] = camera.getProjection(i) * ext::openvr::hmdEyePositionMatrix( i == 0 ? vr::Eye_Left : vr::Eye_Right ) * model; } else { auto translation = uf::matrix::translate( uf::matrix::identity(), camera.getTransform().position + controller.getComponent>().position ); auto rotation = uf::quaternion::matrix( controller.getComponent>().orientation ); - pod::Matrix4f model = translation * rotation * uf::transform::model( transform ); + pod::Matrix4f model = translation * rotation * uf::transform::model( metadata.overlay.transform ); uniforms.matrices.models[i] = camera.getProjection(i) * camera.getView(i) * model; } } else { @@ -158,22 +172,11 @@ void ext::GuiManagerBehavior::render( uf::Object& self ){ uniforms.matrices.models[i] = model; } - - pod::Vector3f cursorSize = { 0, 0 }; - if ( metadataJson["overlay"]["cursor"]["enabled"].as() ) { - uniforms.cursor.position.x = (metadataJson["overlay"]["cursor"]["position"][0].as() + 1.0f) * 0.5f; //(::mouse.position.x + 1.0f) * 0.5f; - uniforms.cursor.position.y = (metadataJson["overlay"]["cursor"]["position"][1].as() + 1.0f) * 0.5f; //(::mouse.position.y + 1.0f) * 0.5f; - - cursorSize.x = metadataJson["overlay"]["cursor"]["radius"].as(); - cursorSize.y = metadataJson["overlay"]["cursor"]["radius"].as(); - - cursorSize = uf::matrix::multiply( uf::matrix::inverse( uf::matrix::scale( uf::matrix::identity() , transform.scale) ), cursorSize ); - - uniforms.cursor.radius.x = cursorSize.x; - uniforms.cursor.radius.y = cursorSize.y; + if ( metadata.overlay.cursor.enabled ) { + uniforms.cursor.position = metadata.overlay.cursor.position * 0.5f + 0.5f; + uniforms.cursor.radius = uf::matrix::multiply( uf::matrix::inverse( uf::matrix::scale( uf::matrix::identity() , metadata.overlay.transform.scale) ), pod::Vector3f{ metadata.overlay.cursor.radius, metadata.overlay.cursor.radius, 0 } ); } - - uniforms.cursor.color = uf::vector::decode( metadataJson["overlay"]["cursor"]["color"], pod::Vector4f{0,0,0,0} ); + uniforms.cursor.color = metadata.overlay.cursor.color; } shader.updateUniform( "UBO", uniform ); diff --git a/ext/gui/manager/behavior.h b/ext/gui/manager/behavior.h index 9d45bdc1..e95b8e82 100644 --- a/ext/gui/manager/behavior.h +++ b/ext/gui/manager/behavior.h @@ -14,7 +14,22 @@ namespace ext { void render( uf::Object& ); void destroy( uf::Object& ); struct Metadata { + struct { + struct { + uf::stl::string type = ""; + pod::Vector4f color{}; + pod::Vector3f position{}; + float radius{}; + bool enabled{}; + } cursor; + bool enabled{}; + bool floating{}; + pod::Transform<> transform; + } overlay; + + std::function serialize; + std::function deserialize; }; } } \ No newline at end of file diff --git a/ext/inits/persistence.inl b/ext/inits/persistence.inl index 541c2c81..238dcdf3 100644 --- a/ext/inits/persistence.inl +++ b/ext/inits/persistence.inl @@ -3,7 +3,7 @@ /* Read persistent data */ if ( false ) { struct { bool exists = false; - std::string filename = uf::io::root+"/persistent.json"; + uf::stl::string filename = uf::io::root+"/persistent.json"; } file; struct { uf::Serializer file; @@ -13,12 +13,12 @@ // persistent.window.size.x = config.file["window"]["size"]["x"].as(); // persistent.window.size.y = config.file["window"]["size"]["y"].as(); if ( config.file["window"]["title"] != "null" ) { - persistent.window.title = config.file["window"]["title"].as(); + persistent.window.title = config.file["window"]["title"].as(); } /* Update window size */ { uf::Serializer json; - std::string hook = "window:Resized"; + uf::stl::string hook = "window:Resized"; json["type"] = hook; json["invoker"] = "ext"; json["window"]["size"] = uf::vector::encode( persistent.window.size ); @@ -29,10 +29,10 @@ } /* Update window title */ { uf::Serializer json; - std::string hook = "window:Title.Changed"; + uf::stl::string hook = "window:Title.Changed"; json["type"] = hook; json["invoker"] = "ext"; - json["window"]["title"] = std::string(persistent.window.title); + json["window"]["title"] = uf::stl::string(persistent.window.title); uf::hooks.call(hook, json); } } diff --git a/ext/main.cpp b/ext/main.cpp index 51a243f6..b1092fd7 100644 --- a/ext/main.cpp +++ b/ext/main.cpp @@ -27,7 +27,7 @@ #include -#include +#include #include #include @@ -46,7 +46,7 @@ #include bool ext::ready = false; -std::vector ext::arguments; +uf::stl::vector ext::arguments; uf::Serializer ext::config; namespace { @@ -55,7 +55,7 @@ namespace { std::ofstream output; struct { - std::string output = uf::io::root+"/logs/output.txt"; + uf::stl::string output = uf::io::root+"/logs/output.txt"; } filenames; } io; @@ -78,7 +78,7 @@ namespace { } namespace { - std::string getConfig() { + uf::stl::string getConfig() { #if 1 return uf::io::readAsString(uf::io::root+"/config.json"); #else @@ -92,7 +92,7 @@ namespace { struct { bool exists = false; - std::string filename = uf::io::root+"/config.json"; + uf::stl::string filename = uf::io::root+"/config.json"; } file; /* Read from file */ { file.exists = config.file.readFromFile(file.filename); @@ -159,8 +159,8 @@ void EXT_API ext::initialize() { std::regex regex("^--(.+?)=(.+?)$"); std::smatch match; if ( std::regex_search( arg, match, regex ) ) { - std::string keyString = match[1].str(); - std::string valueString = match[2].str(); + uf::stl::string keyString = match[1].str(); + uf::stl::string valueString = match[2].str(); uf::Serializer value; value.deserialize(valueString); ::config.path(keyString) = value; modified = true; @@ -195,13 +195,13 @@ void EXT_API ext::initialize() { /* Set memory pool sizes */ { auto deduceSize = []( const ext::json::Value& value )->size_t{ if ( value.is() ) return value.as(); - if ( value.is() ) { - std::string str = value.as(); + if ( value.is() ) { + uf::stl::string str = value.as(); std::regex regex("^(\\d+) ?((?:K|M|G)?(?:i?B)?)$"); std::smatch match; if ( std::regex_search( str, match, regex ) ) { size_t requested = std::stoi( match[1].str() ); - std::string prefix = match[2].str(); + uf::stl::string prefix = match[2].str(); switch ( prefix.at(0) ) { case 'K': return requested * 1024; case 'M': return requested * 1024 * 1024; @@ -212,28 +212,30 @@ void EXT_API ext::initialize() { } return 0; }; - { - size_t size = deduceSize( ::config["engine"]["memory pool"]["size"] ); - uf::MemoryPool::globalOverride = ::config["engine"]["memory pool"]["globalOverride"].as( uf::MemoryPool::globalOverride ); - UF_MSG_DEBUG("Requesting " << (size_t) size << " bytes for global memory pool: " << &uf::MemoryPool::global); - uf::MemoryPool::global.initialize( size ); - uf::MemoryPool::subPool = ::config["engine"]["memory pool"]["subPools"].as(); - if ( size <= 0 || uf::MemoryPool::subPool ) { - { - size_t size = deduceSize( ::config["engine"]["memory pool"]["pools"]["component"] ); - UF_MSG_DEBUG("Requesting " << (int) size << " bytes for component memory pool: " << &uf::component::memoryPool); - uf::component::memoryPool.initialize( size ); - } - { - size_t size = deduceSize( ::config["engine"]["memory pool"]["pools"]["userdata"] ); - UF_MSG_DEBUG("Requesting " << (int) size << " bytes for userdata memory pool: " << &uf::userdata::memoryPool); - uf::userdata::memoryPool.initialize( size ); - } - { - size_t size = deduceSize( ::config["engine"]["memory pool"]["pools"]["entity"] ); - UF_MSG_DEBUG("Requesting " << (int) size << " bytes for entity memory pool: " << &uf::Entity::memoryPool); - uf::Entity::memoryPool.initialize( size ); - } + // set memory pool alignment requirements + uf::memoryPool::alignment = ::config["engine"]["memory pool"]["alignment"].as( uf::memoryPool::alignment ); + // uf::allocator::useMemoryPool = ::config["engine"]["memory pool"]["STL allocator"].as( uf::allocator::useMemoryPool ); + // set memory pool sizes + size_t size = deduceSize( ::config["engine"]["memory pool"]["size"] ); + uf::memoryPool::globalOverride = ::config["engine"]["memory pool"]["globalOverride"].as( uf::memoryPool::globalOverride ); + UF_MSG_DEBUG("Requesting " << (size_t) size << " bytes for global memory pool: " << &uf::memoryPool::global); + uf::memoryPool::global.initialize( size ); + uf::memoryPool::subPool = ::config["engine"]["memory pool"]["subPools"].as( uf::memoryPool::subPool ); + if ( size <= 0 || uf::memoryPool::subPool ) { + { + size_t size = deduceSize( ::config["engine"]["memory pool"]["pools"]["component"] ); + UF_MSG_DEBUG("Requesting " << (int) size << " bytes for component memory pool: " << &uf::component::memoryPool); + uf::component::memoryPool.initialize( size ); + } + { + size_t size = deduceSize( ::config["engine"]["memory pool"]["pools"]["userdata"] ); + UF_MSG_DEBUG("Requesting " << (int) size << " bytes for userdata memory pool: " << &uf::userdata::memoryPool); + uf::userdata::memoryPool.initialize( size ); + } + { + size_t size = deduceSize( ::config["engine"]["memory pool"]["pools"]["entity"] ); + UF_MSG_DEBUG("Requesting " << (int) size << " bytes for entity memory pool: " << &uf::Entity::memoryPool); + uf::Entity::memoryPool.initialize( size ); } } } @@ -245,13 +247,13 @@ void EXT_API ext::initialize() { metadata["system"]["config"] = ::config; } - if ( ::config["engine"]["limiters"]["framerate"].as() == "auto" && ::config["window"]["refresh rate"].is() ) { + if ( ::config["engine"]["limiters"]["framerate"].as() == "auto" && ::config["window"]["refresh rate"].is() ) { double scale = 1.0; size_t refreshRate = ::config["window"]["refresh rate"].as(); ::config["engine"]["limiters"]["framerate"] = refreshRate * scale; UF_MSG_DEBUG("Setting framerate cap to " << (int) refreshRate * scale); } - if ( ::config["engine"]["threads"]["frame limiter"].as() == "auto" && ::config["window"]["refresh rate"].is() ) { + if ( ::config["engine"]["threads"]["frame limiter"].as() == "auto" && ::config["window"]["refresh rate"].is() ) { double scale = 2.0; size_t refreshRate = ::config["window"]["refresh rate"].as(); ::config["engine"]["threads"]["frame limiter"] = refreshRate * scale; @@ -270,13 +272,13 @@ void EXT_API ext::initialize() { uf::physics::time::clamp = limit != 0 ? 1.0 / limit : 0; } // Mute audio - uf::audio::muted = ::config["engine"]["audio"]["mute"].as( uf::audio::muted ); - uf::audio::streamsByDefault = ::config["engine"]["audio"]["streams by default"].as( uf::audio::streamsByDefault ); - uf::audio::bufferSize = ::config["engine"]["audio"]["buffers"]["size"].as( uf::audio::bufferSize ); - uf::audio::buffers = ::config["engine"]["audio"]["buffers"]["count"].as( uf::audio::buffers ); + uf::audio::muted = ::config["engine"]["audio"]["mute"].as( uf::audio::muted ); + uf::audio::streamsByDefault = ::config["engine"]["audio"]["streams by default"].as( uf::audio::streamsByDefault ); + uf::audio::bufferSize = ::config["engine"]["audio"]["buffers"]["size"].as( uf::audio::bufferSize ); + uf::audio::buffers = ::config["engine"]["audio"]["buffers"]["count"].as( uf::audio::buffers ); // Set worker threads - if ( ::config["engine"]["threads"]["workers"].as() == "auto" ) { + if ( ::config["engine"]["threads"]["workers"].as() == "auto" ) { auto threads = std::max( 1, (int) std::thread::hardware_concurrency() - 1 ); ::config["engine"]["threads"]["workers"] = threads; UF_MSG_DEBUG("Using " << threads << " worker threads"); @@ -284,68 +286,68 @@ void EXT_API ext::initialize() { #if UF_USE_BULLET // set bullet parameters - ext::bullet::debugDrawEnabled = ::config["engine"]["ext"]["bullet"]["debug draw"]["enabled"].as( ext::bullet::debugDrawEnabled ); - ext::bullet::debugDrawRate = ::config["engine"]["ext"]["bullet"]["debug draw"]["rate"].as( ext::bullet::debugDrawRate ); - ext::bullet::iterations = ::config["engine"]["ext"]["bullet"]["iterations"].as( ext::bullet::iterations ); - ext::bullet::substeps = ::config["engine"]["ext"]["bullet"]["substeps"].as( ext::bullet::substeps ); - ext::bullet::timescale = ::config["engine"]["ext"]["bullet"]["timescale"].as( ext::bullet::timescale ); - ext::bullet::defaultMaxCollisionAlgorithmPoolSize = ::config["engine"]["ext"]["bullet"]["pool size"]["max collision algorithm"].as( ext::bullet::defaultMaxCollisionAlgorithmPoolSize ); - ext::bullet::defaultMaxPersistentManifoldPoolSize = ::config["engine"]["ext"]["bullet"]["pool size"]["max persistent manifold"].as( ext::bullet::defaultMaxPersistentManifoldPoolSize ); + ext::bullet::debugDrawEnabled = ::config["engine"]["ext"]["bullet"]["debug draw"]["enabled"].as( ext::bullet::debugDrawEnabled ); + ext::bullet::debugDrawRate = ::config["engine"]["ext"]["bullet"]["debug draw"]["rate"].as( ext::bullet::debugDrawRate ); + ext::bullet::iterations = ::config["engine"]["ext"]["bullet"]["iterations"].as( ext::bullet::iterations ); + ext::bullet::substeps = ::config["engine"]["ext"]["bullet"]["substeps"].as( ext::bullet::substeps ); + ext::bullet::timescale = ::config["engine"]["ext"]["bullet"]["timescale"].as( ext::bullet::timescale ); + ext::bullet::defaultMaxCollisionAlgorithmPoolSize = ::config["engine"]["ext"]["bullet"]["pool size"]["max collision algorithm"].as( ext::bullet::defaultMaxCollisionAlgorithmPoolSize ); + ext::bullet::defaultMaxPersistentManifoldPoolSize = ::config["engine"]["ext"]["bullet"]["pool size"]["max persistent manifold"].as( ext::bullet::defaultMaxPersistentManifoldPoolSize ); #endif uf::thread::workers = ::config["engine"]["threads"]["workers"].as(); { #if UF_USE_VULKAN - std::string RENDERER = "vulkan"; + uf::stl::string RENDERER = "vulkan"; #elif UF_USE_OPENGL - std::string RENDERER = "opengl"; + uf::stl::string RENDERER = "opengl"; #else - std::string RENDERER = "software"; + uf::stl::string RENDERER = "software"; #endif - uf::renderer::settings::validation = ::config["engine"]["ext"][RENDERER]["validation"]["enabled"].as( uf::renderer::settings::validation ); - uf::renderer::settings::msaa = ::config["engine"]["ext"][RENDERER]["framebuffer"]["msaa"].as( uf::renderer::settings::msaa ); + uf::renderer::settings::validation = ::config["engine"]["ext"][RENDERER]["validation"]["enabled"].as( uf::renderer::settings::validation ); + uf::renderer::settings::msaa = ::config["engine"]["ext"][RENDERER]["framebuffer"]["msaa"].as( uf::renderer::settings::msaa ); if ( ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"].is() ) { - float scale = ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"].as(1.0f); + float scale = ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"].as(1.0f); uf::renderer::settings::width *= scale; uf::renderer::settings::height *= scale; } else if ( ext::json::isArray( ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"] ) ) { uf::renderer::settings::width = ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"][0].as(); uf::renderer::settings::height = ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"][1].as(); - std::string filter = ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"][2].as(); + uf::stl::string filter = ::config["engine"]["ext"][RENDERER]["framebuffer"]["size"][2].as(); if ( uf::string::lowercase( filter ) == "nearest" ) uf::renderer::settings::swapchainUpscaleFilter = uf::renderer::enums::Filter::NEAREST; else if ( uf::string::lowercase( filter ) == "linear" ) uf::renderer::settings::swapchainUpscaleFilter = uf::renderer::enums::Filter::LINEAR; } - uf::Entity::deleteChildrenOnDestroy = ::config["engine"]["debug"]["entity"]["delete children on destroy"].as( uf::Entity::deleteChildrenOnDestroy ); - uf::Entity::deleteComponentsOnDestroy = ::config["engine"]["debug"]["entity"]["delete components on destroy"].as( uf::Entity::deleteComponentsOnDestroy ); + uf::Entity::deleteChildrenOnDestroy = ::config["engine"]["debug"]["entity"]["delete children on destroy"].as( uf::Entity::deleteChildrenOnDestroy ); + uf::Entity::deleteComponentsOnDestroy = ::config["engine"]["debug"]["entity"]["delete components on destroy"].as( uf::Entity::deleteComponentsOnDestroy ); for ( int i = 0; i < ::config["engine"]["ext"][RENDERER]["validation"]["filters"].size(); ++i ) { - uf::renderer::settings::validationFilters.push_back( ::config["engine"]["ext"][RENDERER]["validation"]["filters"][i].as() ); + uf::renderer::settings::validationFilters.emplace_back( ::config["engine"]["ext"][RENDERER]["validation"]["filters"][i].as() ); } for ( int i = 0; i < ::config["engine"]["ext"][RENDERER]["extensions"]["device"].size(); ++i ) { - uf::renderer::settings::requestedDeviceExtensions.push_back( ::config["engine"]["ext"][RENDERER]["extensions"]["device"][i].as() ); + uf::renderer::settings::requestedDeviceExtensions.emplace_back( ::config["engine"]["ext"][RENDERER]["extensions"]["device"][i].as() ); } for ( int i = 0; i < ::config["engine"]["ext"][RENDERER]["extensions"]["instance"].size(); ++i ) { - uf::renderer::settings::requestedInstanceExtensions.push_back( ::config["engine"]["ext"][RENDERER]["extensions"]["instance"][i].as() ); + uf::renderer::settings::requestedInstanceExtensions.emplace_back( ::config["engine"]["ext"][RENDERER]["extensions"]["instance"][i].as() ); } for ( int i = 0; i < ::config["engine"]["ext"][RENDERER]["features"].size(); ++i ) { - uf::renderer::settings::requestedDeviceFeatures.push_back( ::config["engine"]["ext"][RENDERER]["features"][i].as() ); + uf::renderer::settings::requestedDeviceFeatures.emplace_back( ::config["engine"]["ext"][RENDERER]["features"][i].as() ); } - uf::renderer::settings::experimental::rebuildOnTickBegin = ::config["engine"]["ext"][RENDERER]["experimental"]["rebuild on tick begin"].as( uf::renderer::settings::experimental::rebuildOnTickBegin ); - uf::renderer::settings::experimental::waitOnRenderEnd = ::config["engine"]["ext"][RENDERER]["experimental"]["wait on render end"].as( uf::renderer::settings::experimental::waitOnRenderEnd ); - uf::renderer::settings::experimental::individualPipelines = ::config["engine"]["ext"][RENDERER]["experimental"]["individual pipelines"].as( uf::renderer::settings::experimental::individualPipelines ); - uf::renderer::settings::experimental::multithreadedCommandRecording = ::config["engine"]["ext"][RENDERER]["experimental"]["multithreaded command recording"].as( uf::renderer::settings::experimental::multithreadedCommandRecording ); - uf::renderer::settings::experimental::multithreadedCommandRendering = ::config["engine"]["ext"][RENDERER]["experimental"]["multithreaded command rendering"].as( uf::renderer::settings::experimental::multithreadedCommandRendering ); - uf::renderer::settings::experimental::deferredMode = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred mode"].as( uf::renderer::settings::experimental::deferredMode ); - uf::renderer::settings::experimental::deferredReconstructPosition = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred reconstruct position"].as( uf::renderer::settings::experimental::deferredReconstructPosition ); - uf::renderer::settings::experimental::deferredAliasOutputToSwapchain = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred alias output to swapchain"].as( uf::renderer::settings::experimental::deferredAliasOutputToSwapchain ); - uf::renderer::settings::experimental::vsync = ::config["engine"]["ext"][RENDERER]["experimental"]["vsync"].as( uf::renderer::settings::experimental::vsync ); - uf::renderer::settings::experimental::hdr = ::config["engine"]["ext"][RENDERER]["experimental"]["hdr"].as( uf::renderer::settings::experimental::hdr ); - uf::renderer::settings::experimental::vxgi = ::config["engine"]["ext"][RENDERER]["experimental"]["vxgi"].as( uf::renderer::settings::experimental::vxgi ); - uf::renderer::settings::experimental::deferredSampling = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred sampling"].as( uf::renderer::settings::experimental::deferredSampling ); - #define JSON_TO_VKFORMAT( key ) if ( ::config["engine"]["ext"][RENDERER]["formats"][#key].is() ) {\ - std::string format = ::config["engine"]["ext"][RENDERER]["formats"][#key].as();\ + uf::renderer::settings::experimental::rebuildOnTickBegin = ::config["engine"]["ext"][RENDERER]["experimental"]["rebuild on tick begin"].as( uf::renderer::settings::experimental::rebuildOnTickBegin ); + uf::renderer::settings::experimental::waitOnRenderEnd = ::config["engine"]["ext"][RENDERER]["experimental"]["wait on render end"].as( uf::renderer::settings::experimental::waitOnRenderEnd ); + uf::renderer::settings::experimental::individualPipelines = ::config["engine"]["ext"][RENDERER]["experimental"]["individual pipelines"].as( uf::renderer::settings::experimental::individualPipelines ); + uf::renderer::settings::experimental::multithreadedCommandRecording = ::config["engine"]["ext"][RENDERER]["experimental"]["multithreaded command recording"].as( uf::renderer::settings::experimental::multithreadedCommandRecording ); + uf::renderer::settings::experimental::multithreadedCommandRendering = ::config["engine"]["ext"][RENDERER]["experimental"]["multithreaded command rendering"].as( uf::renderer::settings::experimental::multithreadedCommandRendering ); + uf::renderer::settings::experimental::deferredMode = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred mode"].as( uf::renderer::settings::experimental::deferredMode ); + uf::renderer::settings::experimental::deferredReconstructPosition = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred reconstruct position"].as( uf::renderer::settings::experimental::deferredReconstructPosition ); + uf::renderer::settings::experimental::deferredAliasOutputToSwapchain = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred alias output to swapchain"].as( uf::renderer::settings::experimental::deferredAliasOutputToSwapchain ); + uf::renderer::settings::experimental::vsync = ::config["engine"]["ext"][RENDERER]["experimental"]["vsync"].as( uf::renderer::settings::experimental::vsync ); + uf::renderer::settings::experimental::hdr = ::config["engine"]["ext"][RENDERER]["experimental"]["hdr"].as( uf::renderer::settings::experimental::hdr ); + uf::renderer::settings::experimental::vxgi = ::config["engine"]["ext"][RENDERER]["experimental"]["vxgi"].as( uf::renderer::settings::experimental::vxgi ); + uf::renderer::settings::experimental::deferredSampling = ::config["engine"]["ext"][RENDERER]["experimental"]["deferred sampling"].as( uf::renderer::settings::experimental::deferredSampling ); + #define JSON_TO_VKFORMAT( key ) if ( ::config["engine"]["ext"][RENDERER]["formats"][#key].is() ) {\ + uf::stl::string format = ::config["engine"]["ext"][RENDERER]["formats"][#key].as();\ format = uf::string::replace( uf::string::uppercase(format), " ", "_" );\ uf::renderer::settings::formats::key = uf::renderer::formatFromString( format );\ } @@ -362,10 +364,10 @@ void EXT_API ext::initialize() { #if UF_USE_LUA /* Lua */ { - ext::lua::main = ::config["engine"]["ext"]["lua"]["main"].as(); + ext::lua::main = ::config["engine"]["ext"]["lua"]["main"].as(); for ( auto it = ::config["engine"]["ext"]["lua"]["modules"].begin(); it != ::config["engine"]["ext"]["lua"]["modules"].end(); ++it ) { - std::string key = it.key(); - ext::lua::modules[key] = ::config["engine"]["ext"]["lua"]["modules"][key].as(); + uf::stl::string key = it.key(); + ext::lua::modules[key] = ::config["engine"]["ext"]["lua"]["modules"][key].as(); } ext::lua::initialize(); } @@ -378,16 +380,16 @@ void EXT_API ext::initialize() { #endif #if UF_USE_OPENVR - ext::openvr::enabled = ::config["engine"]["ext"]["vr"]["enable"].as( ext::openvr::enabled ); - ext::openvr::swapEyes = ::config["engine"]["ext"]["vr"]["swap eyes"].as( ext::openvr::swapEyes ); + ext::openvr::enabled = ::config["engine"]["ext"]["vr"]["enable"].as( ext::openvr::enabled ); + ext::openvr::swapEyes = ::config["engine"]["ext"]["vr"]["swap eyes"].as( ext::openvr::swapEyes ); if ( ::config["engine"]["ext"]["vr"]["dominant eye"].is() ) { ext::openvr::dominantEye = ::config["engine"]["ext"]["vr"]["dominant eye"].as(); - } else if ( ::config["engine"]["ext"]["vr"]["dominant eye"].as() == "left" ) ext::openvr::dominantEye = 0; - else if ( ::config["engine"]["ext"]["vr"]["dominant eye"].as() == "right" ) ext::openvr::dominantEye = 1; + } else if ( ::config["engine"]["ext"]["vr"]["dominant eye"].as() == "left" ) ext::openvr::dominantEye = 0; + else if ( ::config["engine"]["ext"]["vr"]["dominant eye"].as() == "right" ) ext::openvr::dominantEye = 1; - ext::openvr::driver.manifest = ::config["engine"]["ext"]["vr"]["manifest"].as(); + ext::openvr::driver.manifest = ::config["engine"]["ext"]["vr"]["manifest"].as(); if ( ext::openvr::enabled ) ::config["engine"]["render modes"]["stereo deferred"] = true; #endif @@ -499,7 +501,7 @@ void EXT_API ext::initialize() { uf::hooks.call("game:Scene.Cleanup"); // uf::scene::unloadScene(); - auto& scene = uf::scene::loadScene( json["scene"].as() ); + auto& scene = uf::scene::loadScene( json["scene"].as() ); auto& metadata = scene.getComponent(); metadata["system"]["config"] = ::config; @@ -562,7 +564,7 @@ void EXT_API ext::tick() { TIMER(1, uf::Window::isKeyPressed("P") && ) { // uf::iostream << uf::renderer::allocatorStats() << "\n"; uf::iostream << "==== Memory Pool Information ===="; - if ( uf::MemoryPool::global.size() > 0 ) uf::iostream << "\nGlobal Memory Pool: " << uf::MemoryPool::global.stats(); + if ( uf::memoryPool::global.size() > 0 ) uf::iostream << "\nGlobal Memory Pool: " << uf::memoryPool::global.stats(); if ( uf::Entity::memoryPool.size() > 0 ) uf::iostream << "\nEntity Memory Pool: " << uf::Entity::memoryPool.stats(); if ( uf::component::memoryPool.size() > 0 ) uf::iostream << "\nComponents Memory Pool: " << uf::component::memoryPool.stats(); if ( uf::userdata::memoryPool.size() > 0 ) uf::iostream << "\nUserdata Memory Pool: " << uf::userdata::memoryPool.stats(); @@ -766,7 +768,7 @@ void EXT_API ext::terminate() { /* Write persistent data */ if ( false ) { struct { bool exists = false; - std::string filename = uf::io::root+"/persistent.json"; + uf::stl::string filename = uf::io::root+"/persistent.json"; } file; struct { uf::Serializer file; diff --git a/ext/scenes/raytrace/behavior.cpp b/ext/scenes/raytrace/behavior.cpp index 32d30cff..7850bc0c 100644 --- a/ext/scenes/raytrace/behavior.cpp +++ b/ext/scenes/raytrace/behavior.cpp @@ -32,7 +32,7 @@ void ext::RayTracingSceneBehavior::initialize( uf::Object& self ) { { auto& renderMode = this->getComponent(); - std::string name = "C:RT:" + std::to_string((int) this->getUid()); + uf::stl::string name = "C:RT:" + std::to_string((int) this->getUid()); uf::renderer::addRenderMode( &renderMode, name ); if ( ext::json::isArray( metadata["light"]["shadows"]["resolution"] ) ) { renderMode.width = metadata["light"]["shadows"]["resolution"][0].as(); @@ -50,7 +50,7 @@ void ext::RayTracingSceneBehavior::initialize( uf::Object& self ) { pod::Vector3ui _pad; }; - std::vector shapes; + uf::stl::vector shapes; { shapes.push_back( {{1.75f, -0.5f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f}, 32.0f, 1} ); shapes.push_back( {{0.0f, 1.0f, -0.5f, 1.0f }, {0.65f, 0.77f, 0.97f}, 32.0f, 1} ); @@ -150,7 +150,7 @@ void ext::RayTracingSceneBehavior::tick( uf::Object& self ) { uniforms->fog.range.y = metadata["light"]["fog"]["range"][1].as(); } - std::vector entities; + uf::stl::vector entities; std::function filter = [&]( uf::Entity* entity ) { if ( !entity || entity->getName() != "Light" ) return; entities.push_back(entity); diff --git a/ext/scenes/worldscape/behavior.cpp b/ext/scenes/worldscape/behavior.cpp index 70eed296..e85288f7 100644 --- a/ext/scenes/worldscape/behavior.cpp +++ b/ext/scenes/worldscape/behavior.cpp @@ -26,7 +26,7 @@ void ext::WorldScapeSceneBehavior::initialize( uf::Object& self ) { uf::Asset& assetLoader = this->getComponent(); /* Grab master data */ { - std::vector tables = { + uf::stl::vector tables = { "Card", "Chara", "Skill", @@ -42,7 +42,7 @@ void ext::WorldScapeSceneBehavior::initialize( uf::Object& self ) { static uf::Timer timer(false); if ( !timer.running() ) timer.start(); /* - this->addHook( "world:Battle.Prepare", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Prepare", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Entity& player = this->getController(); @@ -64,7 +64,7 @@ void ext::WorldScapeSceneBehavior::initialize( uf::Object& self ) { return "true"; }); - this->addHook( "world:Battle.Start", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Start", [&](const uf::stl::string& event)->uf::stl::string{ if ( timer.elapsed().asDouble() < 1 ) return "false"; timer.reset(); uf::Object* guiManager = (uf::Object*) this->globalFindByName("Gui Manager"); @@ -79,7 +79,7 @@ void ext::WorldScapeSceneBehavior::initialize( uf::Object& self ) { uf::Serializer payload; return payload; }); - this->addHook( "world:Battle.End", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.End", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; ext::HousamoBattle* battleManager = (ext::HousamoBattle*) this->globalFindByName("Battle Manager"); if ( !battleManager ) return "false"; @@ -90,7 +90,7 @@ void ext::WorldScapeSceneBehavior::initialize( uf::Object& self ) { return "true"; }); - this->addHook( "menu:Dialogue.Start", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.Start", [&](const uf::stl::string& event)->uf::stl::string{ if ( timer.elapsed().asDouble() < 1 ) return "false"; timer.reset(); uf::Object* guiManager = (uf::Object*) this->globalFindByName("Gui Manager"); @@ -103,7 +103,7 @@ void ext::WorldScapeSceneBehavior::initialize( uf::Object& self ) { dialogueManager->callHook("menu:Dialogue.Start.%UID%", json); return json; }); - this->addHook( "menu:Dialogue.End", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.End", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; ext::DialogueManager* dialogueManager = (ext::DialogueManager*) this->globalFindByName("Dialogue Manager"); if ( !dialogueManager ) return "false"; diff --git a/ext/scenes/worldscape/gui/battle.cpp b/ext/scenes/worldscape/gui/battle.cpp index 851ad7a5..46374d28 100644 --- a/ext/scenes/worldscape/gui/battle.cpp +++ b/ext/scenes/worldscape/gui/battle.cpp @@ -14,7 +14,7 @@ #include "..//battle.h" #include -#include +#include //#include @@ -36,42 +36,42 @@ namespace { ext::Gui* critCutInBackground; ext::Gui* critCutIn; - std::vector partyMemberButtons(5); -// std::vector partyMemberIcons(5); -// std::vector partyMemberTexts(5); - std::vector particles; + uf::stl::vector partyMemberButtons(5); +// uf::stl::vector partyMemberIcons(5); +// uf::stl::vector partyMemberTexts(5); + uf::stl::vector particles; ext::HousamoBattle* battleManager; - uf::Serializer masterTableGet( const std::string& table ) { + uf::Serializer masterTableGet( const uf::stl::string& table ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table]; } - uf::Serializer masterDataGet( const std::string& table, const std::string& key ) { + uf::Serializer masterDataGet( const uf::stl::string& table, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table][key]; } - inline int64_t parseInt( const std::string& str ) { + inline int64_t parseInt( const uf::stl::string& str ) { return atoi(str.c_str()); } - inline std::string colorString( const std::string& hex ) { + inline uf::stl::string colorString( const uf::stl::string& hex ) { return "%#" + hex + "%"; } - void playSound( ext::GuiBattle& entity, const std::string& id, const std::string& key ) { + void playSound( ext::GuiBattle& entity, const uf::stl::string& id, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& masterdata = scene.getComponent(); uf::Serializer cardData = masterDataGet("Card", id); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string name = charaData["filename"].as(); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string name = charaData["filename"].as(); if ( name == "none" ) return; - std::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; + uf::stl::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; if ( charaData["internal"].as() ) { url = "/smtsamo/voice/voice_" + name + "_" + key + ".ogg"; } @@ -79,7 +79,7 @@ namespace { uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid())); } - void playSound( ext::GuiBattle& entity, std::size_t uid, const std::string& key ) { + void playSound( ext::GuiBattle& entity, std::size_t uid, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& pMetadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); @@ -87,29 +87,29 @@ namespace { uf::Entity* = scene.findByUid(uid); if ( ! ) return; uf::Serializer& metadata = ->getComponent(); - std::string id = metadata[""]["id"].as(); + uf::stl::string id = metadata[""]["id"].as(); playSound( entity, id, key ); } - void playSound( ext::GuiBattle& entity, const std::string& key ) { + void playSound( ext::GuiBattle& entity, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); - std::string url = uf::io::root+"/audio/ui/" + key + ".ogg"; + uf::stl::string url = uf::io::root+"/audio/ui/" + key + ".ogg"; uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid())); } - void playMusic( ext::GuiBattle& entity, const std::string& filename ) { + void playMusic( ext::GuiBattle& entity, const uf::stl::string& filename ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Asset& assetLoader = scene.getComponent(); uf::Serializer& masterdata = scene.getComponent(); assetLoader.load(filename, "asset:Load." + std::to_string(scene.getUid())); } - std::string getKeyFromIndex( uf::Serializer& object, uint64_t index ) { + uf::stl::string getKeyFromIndex( uf::Serializer& object, uint64_t index ) { uint64_t i = 0; - std::string key = ""; + uf::stl::string key = ""; for ( auto it = object.begin(); it != object.end(); ++it ) { if ( i++ == index ) key = it.key(); } @@ -123,23 +123,23 @@ namespace { struct { int selection = 0; int selectionsMax = 3; - std::vector invalids; + uf::stl::vector invalids; } skill; struct { int selection = 0; int selectionsMax = 3; - std::vector invalids; + uf::stl::vector invalids; uf::Serializer current; } actions; struct { int selection = 0; int selectionsMax = 3; - std::vector invalids; + uf::stl::vector invalids; uf::Serializer current; } targets; uf::Serializer currentMember; uf::Serializer previousMember; - std::string state = "open"; + uf::stl::string state = "open"; bool initialized = false; }; static BattleStats stats; @@ -153,12 +153,12 @@ void ext::GuiBattle::initialize() { uf::Serializer& metadata = this->getComponent(); battleManager = (ext::HousamoBattle*) this->getRootParent().findByName( "Battle Manager" ); - partyMemberButtons = std::vector(5); + partyMemberButtons = uf::stl::vector(5); - this->addHook( "asset:Cache.SFX." + std::to_string(this->getUid()), [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.SFX." + std::to_string(this->getUid()), [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -177,10 +177,10 @@ void ext::GuiBattle::initialize() { return "true"; }); - this->addHook( "asset:Cache.Voice." + std::to_string(this->getUid()), [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.Voice." + std::to_string(this->getUid()), [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -240,7 +240,7 @@ void ext::GuiBattle::initialize() { turnCounters->initialize(); } - this->addHook("world:Battle.TurnStart.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.TurnStart.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; @@ -251,11 +251,11 @@ void ext::GuiBattle::initialize() { return "true"; }); - this->addHook("world:Battle.Damage.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.Damage.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; - std::string uid = json["target"]["uid"].as(); - std::string damage = json["target"]["damage"].as(); + uf::stl::string uid = json["target"]["uid"].as(); + uf::stl::string damage = json["target"]["damage"].as(); pod::Transform<> pTransform; pTransform.position = { 0, 0, 0 }; @@ -268,7 +268,7 @@ void ext::GuiBattle::initialize() { if ( pointer->getUid() == 0 ) continue; if ( pointer->getName() == "Menu: Party Member Icon" ) { uf::Serializer& pMetadata = pointer->getComponent(); - if ( pMetadata[""]["uid"].as() != uid ) continue; + if ( pMetadata[""]["uid"].as() != uid ) continue; pTransform = pointer->getComponent>(); pTransform.position.y -= (0.1); } @@ -278,7 +278,7 @@ void ext::GuiBattle::initialize() { this->addChild(*particle); uf::Serializer& pMetadata = particle->getComponent(); particle->as().load("./damageText.json", true); - std::string color = json["color"].is() ? json["color"].as() : "FF0000"; + uf::stl::string color = json["color"].is() ? json["color"].as() : "FF0000"; pMetadata["text settings"]["string"] = "%#"+color+"%" + damage; pod::Transform<>& transform = particle->getComponent>(); transform = pTransform; @@ -288,9 +288,9 @@ void ext::GuiBattle::initialize() { return "true"; }); - this->addHook("world:Battle.Message.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.Message.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; - std::string message = json["message"].as(); + uf::stl::string message = json["message"].as(); if ( battleMessage ) { battleMessage->destroy(); @@ -308,7 +308,7 @@ void ext::GuiBattle::initialize() { return "true"; }); - this->addHook("world:Battle.RemoveOnCrit.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.RemoveOnCrit.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { if ( critCutInBackground && critCutInBackground->getUid() != 0 ) { critCutInBackground->destroy(); this->removeChild(*critCutInBackground); @@ -323,7 +323,7 @@ void ext::GuiBattle::initialize() { } return "true"; }); - this->addHook("world:Battle.OnCrit.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.OnCrit.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; if ( critCutInBackground && critCutInBackground->getUid() != 0 ) { critCutInBackground->destroy(); @@ -348,9 +348,9 @@ void ext::GuiBattle::initialize() { this->addChild(*critCutIn); uf::Serializer& pMetadata = critCutIn->getComponent(); - uf::Serializer cardData = masterDataGet("Card", json["id"].as()); - pMetadata["system"]["assets"][0] = "/smtsamo/ci/ci_"+ cardData["filename"].as() +".png"; - if ( !uf::io::exists( pMetadata["system"]["assets"][0].as() ) ) pMetadata["system"]["assets"][0] = ext::json::null(); + uf::Serializer cardData = masterDataGet("Card", json["id"].as()); + pMetadata["system"]["assets"][0] = "/smtsamo/ci/ci_"+ cardData["filename"].as() +".png"; + if ( !uf::io::exists( pMetadata["system"]["assets"][0].as() ) ) pMetadata["system"]["assets"][0] = ext::json::null(); critCutIn->as().load("./critCutIn.json", true); critCutIn->initialize(); } @@ -360,7 +360,7 @@ void ext::GuiBattle::initialize() { return "true"; }); - this->addHook("world:Battle.Update.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.Update.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; { @@ -430,10 +430,10 @@ void ext::GuiBattle::initialize() { breaks = true; return; } - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - std::string name = cardData["filename"].as(); - if ( member["skin"].is() ) name += "_" + member["skin"].as(); - std::string filename = "https://cdn..xyz//unity/Android/icon/icon_" + name + ".png"; + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::stl::string name = cardData["filename"].as(); + if ( member["skin"].is() ) name += "_" + member["skin"].as(); + uf::stl::string filename = "https://cdn..xyz//unity/Android/icon/icon_" + name + ".png"; if ( cardData["internal"].as() ) { filename = "/smtsamo/icon/icon_" + name + ".png"; } @@ -470,7 +470,7 @@ void ext::GuiBattle::initialize() { partyMemberButton->addChild(*partyMemberText); uf::Serializer& pMetadata = partyMemberText->getComponent(); partyMemberText->as().load("./partyMemberText.json", true); - pMetadata["text settings"]["string"] = "" + colorString("00FF00") + "" + member["hp"].as() + "\n" + colorString("0000FF") + "" + member["mp"].as(); + pMetadata["text settings"]["string"] = "" + colorString("00FF00") + "" + member["hp"].as() + "\n" + colorString("0000FF") + "" + member["mp"].as(); pMetadata[""] = member; pod::Transform<>& transform = partyMemberText->getComponent>(); transform.position = bTransform.position; @@ -549,7 +549,7 @@ void ext::GuiBattle::initialize() { partyMemberButton->addChild(*partyMemberText); uf::Serializer& pMetadata = partyMemberText->getComponent(); partyMemberText->as().load("./partyMemberText.json", true); - pMetadata["text settings"]["string"] = "" + colorString("FF0000") + "" + member["hp"].as() + "\n" + colorString("0000FF") + "" + member["mp"].as(); + pMetadata["text settings"]["string"] = "" + colorString("FF0000") + "" + member["hp"].as() + "\n" + colorString("0000FF") + "" + member["mp"].as(); pMetadata[""] = member; pod::Transform<>& transform = partyMemberText->getComponent>(); transform.position = bTransform.position; @@ -617,7 +617,7 @@ void ext::GuiBattle::initialize() { return "true"; }); - this->addHook("menu:Close.%UID%", [&]( const std::string& event ) -> std::string { + this->addHook("menu:Close.%UID%", [&]( const uf::stl::string& event ) -> uf::stl::string { // kill this->getParent().removeChild(*this); this->destroy(); @@ -638,15 +638,15 @@ void ext::GuiBattle::tick() { static uf::Timer timer(false); static float timeout = 1.0f; if ( !timer.running() ) timer.start(); - static std::string queuedAction; + static uf::stl::string queuedAction; std::function postParseResult = [&]( uf::Serializer& result ) { if ( result["end"].as() ) bMetadata["system"]["closing"] = true; if ( !ext::json::isNull( result["timeout"] ) ) timeout = result["timeout"].as(); else timeout = 1; // modify timeout based on string length - if ( result["message"].is() && !ext::json::isNull( result["target"] ) ) { - uint64_t size = result["message"].as().size(); + if ( result["message"].is() && !ext::json::isNull( result["target"] ) ) { + uint64_t size = result["message"].as().size(); float modified = size * 0.025f; if ( timeout < modified ) timeout = modified; } @@ -670,31 +670,31 @@ void ext::GuiBattle::tick() { return; } stats.currentMember = member; - std::string string = ""; + uf::stl::string string = ""; std::size_t counter = 0; std::size_t start = stats.skill.selection; stats.actions.invalids.clear(); stats.currentMember["skills"] = ext::json::array(); for ( int i = 0; i < member["skills"].size(); ++i ) { - std::string id = member["skills"][i].as(); + uf::stl::string id = member["skills"][i].as(); uf::Serializer skillData = masterDataGet("Skill", id); bool add = false; if ( skillData["type"].as() > 0 && skillData["type"].as() < 16 ) add = true; if ( add ) stats.currentMember["skills"].emplace_back(id); } - std::string skillDescription = ""; + uf::stl::string skillDescription = ""; for ( int i = start; i < stats.currentMember["skills"].size(); ++i ) { - std::string id = stats.currentMember["skills"][i].as(); - std::string text = ""; + uf::stl::string id = stats.currentMember["skills"][i].as(); + uf::stl::string text = ""; if ( std::find( stats.skill.invalids.begin(), stats.skill.invalids.end(), id ) != stats.skill.invalids.end() ) continue; if ( ++counter > stats.skill.selectionsMax ) break; - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); uf::Serializer skillData = masterDataGet("Skill", id); if ( id != "0" ) { - text = skillData["name"].as(); + text = skillData["name"].as(); } else { text = "攻撃"; } @@ -703,34 +703,34 @@ void ext::GuiBattle::tick() { } else { text = "" + colorString("FF0000") + "" + text; - skillDescription = skillData["effect"].as(); + skillDescription = skillData["effect"].as(); if ( skillData["mp"].is() ) { int64_t cost = skillData["mp"].as(); - skillDescription = skillData["effect"].as() + "\nCost: " + colorString("0000FF") + ""+std::to_string(cost)+" MP" + colorString("FFFFFF") + ""; + skillDescription = skillData["effect"].as() + "\nCost: " + colorString("0000FF") + ""+std::to_string(cost)+" MP" + colorString("FFFFFF") + ""; } if ( skillData["hp%"].is() ) { int64_t cost = skillData["hp%"].as(); cost = member["max hp"].as() * ( cost / 100.0f ); - skillDescription = skillData["effect"].as() + "\nCost: " + colorString("00FF00") + ""+std::to_string(cost)+" HP" + colorString("FFFFFF") + ""; + skillDescription = skillData["effect"].as() + "\nCost: " + colorString("00FF00") + ""+std::to_string(cost)+" HP" + colorString("FFFFFF") + ""; } } string += "\n" + text; } if ( stats.currentMember["skills"].size() > stats.skill.selectionsMax ) { for ( int i = 0; i < stats.currentMember["skills"].size(); ++i ) { - std::string id = stats.currentMember["skills"][i].as(); - std::string text = ""; + uf::stl::string id = stats.currentMember["skills"][i].as(); + uf::stl::string text = ""; if ( std::find( stats.skill.invalids.begin(), stats.skill.invalids.end(), id ) != stats.skill.invalids.end() ) continue; if ( ++counter > stats.skill.selectionsMax ) break; if ( id != "0" ) { - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); uf::Serializer skillData = masterDataGet("Skill", id); - text = skillData["name"].as(); + text = skillData["name"].as(); } else { - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); text = "攻撃"; } @@ -768,13 +768,13 @@ void ext::GuiBattle::tick() { return; } stats.actions.current = actions; - std::string string = ""; + uf::stl::string string = ""; std::size_t counter = 0; std::size_t start = stats.actions.selection; auto keys = ext::json::keys( actions ); for ( int i = start; i < keys.size(); ++i ) { - std::string key = getKeyFromIndex( actions, i ); - std::string text = actions[key].as(); + uf::stl::string key = getKeyFromIndex( actions, i ); + uf::stl::string text = actions[key].as(); if ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), key ) != stats.actions.invalids.end() ) continue; if ( ++counter > stats.actions.selectionsMax ) break; if ( i != stats.actions.selection ) text = "" + colorString("FFFFFF") + "" + text; @@ -783,8 +783,8 @@ void ext::GuiBattle::tick() { } if ( keys.size() > stats.actions.selectionsMax ) { for ( int i = 0; i < keys.size(); ++i ) { - std::string key = getKeyFromIndex( actions, i ); - std::string text = actions[key].as(); + uf::stl::string key = getKeyFromIndex( actions, i ); + uf::stl::string text = actions[key].as(); if ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), key ) != stats.actions.invalids.end() ) continue; if ( ++counter > stats.actions.selectionsMax ) break; if ( i != stats.actions.selection ) text = "" + colorString("FFFFFF") + "" + text; @@ -816,16 +816,16 @@ void ext::GuiBattle::tick() { return; } stats.targets.current = actions; - std::string string = ""; + uf::stl::string string = ""; std::size_t counter = 0; std::size_t start = stats.targets.selection; stats.skill.invalids.clear(); stats.actions.invalids.clear(); - std::string targetDescription = ""; + uf::stl::string targetDescription = ""; for ( int i = start; i < actions.size(); ++i ) { - uf::Serializer cardData = masterDataGet("Card", actions[i]["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string text = charaData["name"].as(); + uf::Serializer cardData = masterDataGet("Card", actions[i]["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string text = charaData["name"].as(); if ( std::find( stats.targets.invalids.begin(), stats.targets.invalids.end(), text ) != stats.targets.invalids.end() ) continue; if ( ++counter > stats.targets.selectionsMax ) break; if ( i != stats.targets.selection ) text = "" + colorString("FFFFFF") + "" + text; @@ -834,9 +834,9 @@ void ext::GuiBattle::tick() { } if ( actions.size() > stats.targets.selectionsMax ) { for ( int i = 0; i < actions.size(); ++i ) { - uf::Serializer cardData = masterDataGet("Card", actions[i]["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string text = charaData["name"].as(); + uf::Serializer cardData = masterDataGet("Card", actions[i]["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string text = charaData["name"].as(); if ( std::find( stats.targets.invalids.begin(), stats.targets.invalids.end(), text ) != stats.targets.invalids.end() ) continue; if ( ++counter > stats.targets.selectionsMax ) break; if ( i != stats.targets.selection ) text = "" + colorString("FFFFFF") + "" + text; @@ -856,12 +856,12 @@ void ext::GuiBattle::tick() { } if ( queuedAction == "analyze" ) { uf::Serializer payload; - payload["uid"] = stats.targets.current[stats.targets.selection]["uid"].as(); - // if ( payload["uid"].as() == "") + payload["uid"] = stats.targets.current[stats.targets.selection]["uid"].as(); + // if ( payload["uid"].as() == "") payload["action"] = "analyze"; uf::Serializer result = battleManager->callHook("world:Battle.Action.%UID%", payload)[0].as(); - targetDescription = result["message"].as(); + targetDescription = result["message"].as(); } if ( targetDescription != "" ) { uf::Serializer payload; @@ -874,7 +874,7 @@ void ext::GuiBattle::tick() { if ( !stats.initialized ) { stats.initialized = true; uf::Serializer& metadata = this->getComponent(); - this->addHook("world:Battle.Turn.%UID%", [&](const std::string& event) -> std::string { + this->addHook("world:Battle.Turn.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; uf::Serializer payload; payload["action"] = "turn-start"; @@ -895,9 +895,9 @@ void ext::GuiBattle::tick() { if ( ext::json::isNull( result["uid"] ) ) return "false"; uint64_t uid = result["uid"].as(); - renderCommandOptions(std::string("")); - renderSkillOptions(std::string("")); - renderTargetOptions(std::string("")); + renderCommandOptions(uf::stl::string("")); + renderSkillOptions(uf::stl::string("")); + renderTargetOptions(uf::stl::string("")); payload = uf::Serializer{}; payload["uid"] = uid; @@ -926,7 +926,7 @@ void ext::GuiBattle::tick() { if ( metadata["system"]["closing"].as() ) { if ( alpha >= 1.0f ) { uf::Asset assetLoader; - std::string canonical = assetLoader.load(uf::io::root+"/audio/ui/menu close.ogg"); + uf::stl::string canonical = assetLoader.load(uf::io::root+"/audio/ui/menu close.ogg"); uf::Audio& sfx = assetLoader.get(canonical); sfx.setVolume(masterdata["volumes"]["sfx"].as()); sfx.play(); @@ -1204,7 +1204,7 @@ void ext::GuiBattle::tick() { do { --stats.targets.selection; if ( stats.targets.selection < 0 ) { stats.targets.selection = stats.targets.current.size() - 1; } - } while ( std::find( stats.targets.invalids.begin(), stats.targets.invalids.end(), stats.targets.current[stats.targets.selection]["id"].as() ) != stats.targets.invalids.end() ); + } while ( std::find( stats.targets.invalids.begin(), stats.targets.invalids.end(), stats.targets.current[stats.targets.selection]["id"].as() ) != stats.targets.invalids.end() ); } } else if ( keys.down ) { @@ -1214,7 +1214,7 @@ void ext::GuiBattle::tick() { do { ++stats.targets.selection; if ( stats.targets.selection >= stats.targets.current.size() ) { stats.targets.selection = 0; } - } while ( std::find( stats.targets.invalids.begin(), stats.targets.invalids.end(), stats.targets.current[stats.targets.selection]["id"].as() ) != stats.targets.invalids.end() ); + } while ( std::find( stats.targets.invalids.begin(), stats.targets.invalids.end(), stats.targets.current[stats.targets.selection]["id"].as() ) != stats.targets.invalids.end() ); } } else released = true; @@ -1230,9 +1230,9 @@ void ext::GuiBattle::tick() { } } else if ( keys.back && timer.elapsed().asDouble() >= timeout ) { playSound(*this, "menu close"); - renderTargetOptions(std::string("")); + renderTargetOptions(uf::stl::string("")); if ( queuedAction == "analyze" ) { - renderSkillOptions(std::string("")); + renderSkillOptions(uf::stl::string("")); renderCommandOptions(stats.actions.current); } else renderSkillOptions(stats.currentMember); timer.reset(); @@ -1249,9 +1249,9 @@ void ext::GuiBattle::tick() { uf::Serializer result = battleManager->callHook("world:Battle.Action.%UID%", payload)[0].as(); postParseResult(result); - renderTargetOptions(std::string("")); - renderCommandOptions(std::string("")); - renderSkillOptions(std::string("")); + renderTargetOptions(uf::stl::string("")); + renderCommandOptions(uf::stl::string("")); + renderSkillOptions(uf::stl::string("")); timer.reset(); stats.state = "waiting"; @@ -1281,7 +1281,7 @@ void ext::GuiBattle::tick() { do { --stats.skill.selection; if ( stats.skill.selection < 0 ) { stats.skill.selection = stats.currentMember["skills"].size()- 1; } - } while ( std::find( stats.skill.invalids.begin(), stats.skill.invalids.end(), stats.currentMember["skills"][stats.skill.selection].as() ) != stats.skill.invalids.end() ); + } while ( std::find( stats.skill.invalids.begin(), stats.skill.invalids.end(), stats.currentMember["skills"][stats.skill.selection].as() ) != stats.skill.invalids.end() ); } } else if ( keys.down ) { @@ -1291,7 +1291,7 @@ void ext::GuiBattle::tick() { do { ++stats.skill.selection; if ( stats.skill.selection >= stats.currentMember["skills"].size()) { stats.skill.selection = 0; } - } while ( std::find( stats.skill.invalids.begin(), stats.skill.invalids.end(), stats.currentMember["skills"][stats.skill.selection].as() ) != stats.skill.invalids.end() ); + } while ( std::find( stats.skill.invalids.begin(), stats.skill.invalids.end(), stats.currentMember["skills"][stats.skill.selection].as() ) != stats.skill.invalids.end() ); } } else released = true; @@ -1304,14 +1304,14 @@ void ext::GuiBattle::tick() { } } else if ( keys.back && timer.elapsed().asDouble() >= timeout ) { playSound(*this, "menu close"); - renderSkillOptions(std::string("")); + renderSkillOptions(uf::stl::string("")); renderCommandOptions(stats.actions.current); timer.reset(); } else if ( keys.select && timer.elapsed().asDouble() >= timeout ) { playSound(*this, "menu close"); bool allRanged = false; - renderSkillOptions(std::string("")); - renderCommandOptions(std::string("")); + renderSkillOptions(uf::stl::string("")); + renderCommandOptions(uf::stl::string("")); uf::Serializer payload; @@ -1320,7 +1320,7 @@ void ext::GuiBattle::tick() { payload["skill"] = stats.currentMember["skills"][stats.skill.selection]; uf::Serializer result = battleManager->callHook("world:Battle.Action.%UID%", payload)[0].as(); - std::string skillId = stats.currentMember["skills"][stats.skill.selection].as(); + uf::stl::string skillId = stats.currentMember["skills"][stats.skill.selection].as(); uf::Serializer skillData = masterDataGet("Skill", skillId); if ( result["range"].is() ) skillData["range"] = result["range"]; if ( skillData["range"].as() > 1 ) { @@ -1363,7 +1363,7 @@ void ext::GuiBattle::tick() { do { --stats.actions.selection; if ( stats.actions.selection < 0 ) { stats.actions.selection = stats.actions.current.size() - 1; } - } while ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), stats.actions.current[stats.actions.selection].as() ) != stats.actions.invalids.end() ); + } while ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), stats.actions.current[stats.actions.selection].as() ) != stats.actions.invalids.end() ); } } else if ( keys.down ) { @@ -1373,7 +1373,7 @@ void ext::GuiBattle::tick() { do { ++stats.actions.selection; if ( stats.actions.selection >= stats.actions.current.size() ) { stats.actions.selection = 0; } - } while ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), stats.actions.current[stats.actions.selection].as() ) != stats.actions.invalids.end() ); + } while ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), stats.actions.current[stats.actions.selection].as() ) != stats.actions.invalids.end() ); } } else released = true; @@ -1392,7 +1392,7 @@ void ext::GuiBattle::tick() { } else if ( keys.select && timer.elapsed().asDouble() >= timeout ) { playSound(*this, "menu close"); uf::Serializer payload; - std::string action = stats.actions.current[stats.actions.selection].as(); + uf::stl::string action = stats.actions.current[stats.actions.selection].as(); payload["action"] = action; if ( payload["action"] == "member-attack" ) { payload["uid"] = stats.currentMember["uid"]; @@ -1403,7 +1403,7 @@ void ext::GuiBattle::tick() { postParseResult(result); timer.reset(); - renderCommandOptions(std::string("")); + renderCommandOptions(uf::stl::string("")); stats.state = "waiting"; if ( result["invalid"].as() ) { @@ -1411,7 +1411,7 @@ void ext::GuiBattle::tick() { renderCommandOptions(stats.actions.current); // this->queueHook("world:Battle.Turn.%UID%", ext::json::null(), timeout); } else if ( payload["action"] == "member-attack" ) { - renderSkillOptions(std::string("")); + renderSkillOptions(uf::stl::string("")); stats.state = "waiting"; this->queueHook("world:Battle.Turn.%UID%", ext::json::null(), timeout); } else if ( payload["action"] == "member-skill" ) { @@ -1470,7 +1470,7 @@ void ext::GuiBattle::tick() { } else if ( keys.select && timer.elapsed().asDouble() >= timeout ) { playSound(*this, "menu close"); uf::Serializer payload; - std::string action = getKeyFromIndex(stats.actions.current, stats.actions.selection); + uf::stl::string action = getKeyFromIndex(stats.actions.current, stats.actions.selection); action = uf::io::extension(action); payload["action"] = action; payload["uid"] = stats.currentMember["uid"]; @@ -1490,7 +1490,7 @@ void ext::GuiBattle::tick() { postParseResult(result); timer.reset(); - renderCommandOptions(std::string("")); + renderCommandOptions(uf::stl::string("")); queuedAction = action; stats.state = "waiting"; @@ -1498,7 +1498,7 @@ void ext::GuiBattle::tick() { stats.actions.invalids.push_back(action); renderCommandOptions(stats.actions.current); } else if ( payload["action"] == "member-attack" ) { - renderSkillOptions(std::string("")); + renderSkillOptions(uf::stl::string("")); stats.state = "waiting"; this->queueHook("world:Battle.Turn.%UID%", ext::json::null(), timeout); } else if ( payload["action"] == "member-skill" ) { diff --git a/ext/scenes/worldscape/gui/dialogue.cpp b/ext/scenes/worldscape/gui/dialogue.cpp index 3431b242..48af49b7 100644 --- a/ext/scenes/worldscape/gui/dialogue.cpp +++ b/ext/scenes/worldscape/gui/dialogue.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include //#include @@ -31,28 +31,28 @@ namespace { ext::DialogueManager* dialogueManager; - uf::Serializer masterTableGet( const std::string& table ) { + uf::Serializer masterTableGet( const uf::stl::string& table ) { auto& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table]; } - uf::Serializer masterDataGet( const std::string& table, const std::string& key ) { + uf::Serializer masterDataGet( const uf::stl::string& table, const uf::stl::string& key ) { auto& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table][key]; } - inline int64_t parseInt( const std::string& str ) { + inline int64_t parseInt( const uf::stl::string& str ) { return atoi(str.c_str()); } - void playSound( ext::GuiDialogue& entity, const std::string& id, const std::string& key ) { + void playSound( ext::GuiDialogue& entity, const uf::stl::string& id, const uf::stl::string& key ) { auto& scene = uf::scene::getCurrentScene(); uf::Serializer& masterdata = scene.getComponent(); uf::Serializer cardData = masterDataGet("Card", id); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string name = charaData["filename"].as(); - std::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string name = charaData["filename"].as(); + uf::stl::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; if ( charaData["internal"].as() ) { url = "/smtsamo/voice/voice_" + name + "_" + key + ".ogg"; } @@ -60,7 +60,7 @@ namespace { uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid())); } - void playSound( ext::GuiDialogue& entity, std::size_t uid, const std::string& key ) { + void playSound( ext::GuiDialogue& entity, std::size_t uid, const uf::stl::string& key ) { auto& scene = uf::scene::getCurrentScene(); uf::Serializer& pMetadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); @@ -68,29 +68,29 @@ namespace { uf::Entity* = scene.findByUid(uid); if ( ! ) return; uf::Serializer& metadata = ->getComponent(); - std::string id = metadata[""]["id"].as(); + uf::stl::string id = metadata[""]["id"].as(); playSound( entity, id, key ); } - void playSound( ext::GuiDialogue& entity, const std::string& key ) { + void playSound( ext::GuiDialogue& entity, const uf::stl::string& key ) { auto& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); - std::string url = uf::io::root+"/audio/ui/" + key + ".ogg"; + uf::stl::string url = uf::io::root+"/audio/ui/" + key + ".ogg"; uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid())); } - void playMusic( ext::GuiDialogue& entity, const std::string& filename ) { + void playMusic( ext::GuiDialogue& entity, const uf::stl::string& filename ) { auto& scene = uf::scene::getCurrentScene(); uf::Asset& assetLoader = scene.getComponent(); uf::Serializer& masterdata = scene.getComponent(); assetLoader.load(filename, "asset:Load." + std::to_string(scene.getUid())); } - std::string getKeyFromIndex( uf::Serializer& object, uint64_t index ) { + uf::stl::string getKeyFromIndex( uf::Serializer& object, uint64_t index ) { uint64_t i = 0; - std::string key = ""; + uf::stl::string key = ""; for ( auto it = object.begin(); it != object.end(); ++it ) { if ( i++ == index ) key = it.key(); } @@ -104,11 +104,11 @@ namespace { struct { int selection = 0; int selectionsMax = 3; - std::vector invalids; + uf::stl::vector invalids; uf::Serializer current; - std::string index = "0"; + uf::stl::string index = "0"; } actions; - std::string state = "open"; + uf::stl::string state = "open"; bool initialized = false; }; static DialogueStats stats; @@ -122,10 +122,10 @@ void ext::GuiDialogue::initialize() { uf::Serializer& metadata = this->getComponent(); dialogueManager = (ext::DialogueManager*) this->getRootParent().findByName( "Dialogue Manager" ); - this->addHook( "asset:Cache.SFX." + std::to_string(this->getUid()), [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.SFX." + std::to_string(this->getUid()), [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -141,10 +141,10 @@ void ext::GuiDialogue::initialize() { return "true"; }); - this->addHook( "asset:Cache.Voice." + std::to_string(this->getUid()), [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.Voice." + std::to_string(this->getUid()), [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -168,7 +168,7 @@ void ext::GuiDialogue::initialize() { uf::hooks.call("window:Mouse.Lock"); } - this->addHook("menu:Close.%UID%", [&]( const std::string& event ) -> std::string { + this->addHook("menu:Close.%UID%", [&]( const uf::stl::string& event ) -> uf::stl::string { // kill this->getParent().removeChild(*this); this->destroy(); @@ -194,7 +194,7 @@ void ext::GuiDialogue::tick() { if ( result["end"].as() ) bMetadata["system"]["closing"] = true; if ( !ext::json::isNull( result["timeout"] ) ) timeout = result["timeout"].as(); else timeout = 1; - if ( result["message"].as() != "" ) { + if ( result["message"].as() != "" ) { if ( dialogueMessage ) { dialogueMessage->destroy(); this->removeChild(*dialogueMessage); @@ -204,7 +204,7 @@ void ext::GuiDialogue::tick() { this->addChild(*dialogueMessage); uf::Serializer& pMetadata = dialogueMessage->getComponent(); dialogueMessage->as().load("./dialogue-text.json", true); - pMetadata["text settings"]["string"] = result["message"].as(); + pMetadata["text settings"]["string"] = result["message"].as(); dialogueMessage->initialize(); } timer.reset(); @@ -222,13 +222,13 @@ void ext::GuiDialogue::tick() { return; } stats.actions.current = actions; - std::string string = ""; + uf::stl::string string = ""; std::size_t counter = 0; std::size_t start = stats.actions.selection; auto keys = ext::json::keys( actions ); for ( int i = start; i < keys.size(); ++i ) { - std::string key = getKeyFromIndex( actions, i ); - std::string text = actions[key].as(); + uf::stl::string key = getKeyFromIndex( actions, i ); + uf::stl::string text = actions[key].as(); if ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), key ) != stats.actions.invalids.end() ) continue; if ( ++counter > stats.actions.selectionsMax ) break; if ( i != stats.actions.selection ) text = "%#FFFFFF%" + text; @@ -237,8 +237,8 @@ void ext::GuiDialogue::tick() { } if ( keys.size() > stats.actions.selectionsMax ) { for ( int i = 0; i < keys.size(); ++i ) { - std::string key = getKeyFromIndex( actions, i ); - std::string text = actions[key].as(); + uf::stl::string key = getKeyFromIndex( actions, i ); + uf::stl::string text = actions[key].as(); if ( std::find( stats.actions.invalids.begin(), stats.actions.invalids.end(), key ) != stats.actions.invalids.end() ) continue; if ( ++counter > stats.actions.selectionsMax ) break; if ( i != stats.actions.selection ) text = "%#FFFFFF%" + text; @@ -260,7 +260,7 @@ void ext::GuiDialogue::tick() { if ( !stats.initialized ) { stats.initialized = true; - this->addHook("menu:Dialogue.Turn.%UID%", [&](const std::string& event) -> std::string { + this->addHook("menu:Dialogue.Turn.%UID%", [&](const uf::stl::string& event) -> uf::stl::string { uf::Serializer json = event; uf::Serializer payload; payload["action"] = "dialogue-select"; @@ -268,7 +268,7 @@ void ext::GuiDialogue::tick() { uf::Serializer result = dialogueManager->callHook("menu:Dialogue.Action.%UID%", payload)[0].as(); postParseResult(result); - // renderDialogueOptions(std::string("")); + // renderDialogueOptions(uf::stl::string("")); renderDialogueOptions(result["actions"]); return "true"; @@ -281,7 +281,7 @@ void ext::GuiDialogue::tick() { if ( metadata["system"]["closing"].as() ) { if ( alpha >= 1.0f ) { uf::Asset assetLoader; - std::string canonical = assetLoader.load(uf::io::root+"/audio/ui/menu close.ogg"); + uf::stl::string canonical = assetLoader.load(uf::io::root+"/audio/ui/menu close.ogg"); uf::Audio& sfx = assetLoader.get(canonical); sfx.setVolume(masterdata["volumes"]["sfx"].as()); sfx.play(); @@ -369,12 +369,12 @@ void ext::GuiDialogue::tick() { } else if ( keys.select && timer.elapsed().asDouble() >= timeout ) { playSound(*this, "menu close"); uf::Serializer payload; - std::string action = getKeyFromIndex(stats.actions.current, stats.actions.selection); + uf::stl::string action = getKeyFromIndex(stats.actions.current, stats.actions.selection); payload["action"] = "dialogue-select"; payload["index"] = action; stats.actions.index = action; - renderDialogueOptions(std::string("")); + renderDialogueOptions(uf::stl::string("")); timer.reset(); diff --git a/ext/scenes/worldscape/housamo/battle.cpp b/ext/scenes/worldscape/housamo/battle.cpp index b124249d..07a18033 100644 --- a/ext/scenes/worldscape/housamo/battle.cpp +++ b/ext/scenes/worldscape/housamo/battle.cpp @@ -21,40 +21,40 @@ namespace { ext::Gui* gui; - std::string previousMusic; + uf::stl::string previousMusic; - uf::Serializer masterTableGet( const std::string& table ) { + uf::Serializer masterTableGet( const uf::stl::string& table ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table]; } - uf::Serializer masterDataGet( const std::string& table, const std::string& key ) { + uf::Serializer masterDataGet( const uf::stl::string& table, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table][key]; } - inline int64_t parseInt( const std::string& str ) { + inline int64_t parseInt( const uf::stl::string& str ) { return atoi(str.c_str()); } - inline std::string colorString( const std::string& hex ) { + inline uf::stl::string colorString( const uf::stl::string& hex ) { return "%#" + hex + "%"; } } namespace { - void playSound( ext::HousamoBattle& entity, const std::string& id, const std::string& key ) { + void playSound( ext::HousamoBattle& entity, const uf::stl::string& id, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& masterdata = scene.getComponent(); uf::Serializer cardData = masterDataGet("Card", id); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string name = charaData["filename"].as(); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string name = charaData["filename"].as(); if ( name == "none" ) return; - std::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; + uf::stl::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; if ( charaData["internal"].as() ) { url = uf::io::root+"/smtsamo/voice/voice_" + name + "_" + key + ".ogg"; } @@ -62,7 +62,7 @@ namespace { uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid())); } - void playSound( ext::HousamoBattle& entity, std::size_t uid, const std::string& key ) { + void playSound( ext::HousamoBattle& entity, std::size_t uid, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& pMetadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); @@ -70,20 +70,20 @@ namespace { uf::Entity* = scene.findByUid(uid); if ( ! ) return; uf::Serializer& metadata = ->getComponent(); - std::string id = metadata[""]["id"].as(); + uf::stl::string id = metadata[""]["id"].as(); playSound( entity, id, key ); } - void playSound( ext::HousamoBattle& entity, const std::string& key ) { + void playSound( ext::HousamoBattle& entity, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); - std::string url = uf::io::root+"/audio/ui/" + key + ".ogg"; + uf::stl::string url = uf::io::root+"/audio/ui/" + key + ".ogg"; uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid())); } - void playMusic( ext::HousamoBattle& entity, const std::string& filename ) { + void playMusic( ext::HousamoBattle& entity, const uf::stl::string& filename ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Asset& assetLoader = scene.getComponent(); uf::Serializer& masterdata = scene.getComponent(); @@ -100,7 +100,7 @@ namespace { uf::Audio sfx; uf::Audio voice; - std::vector transients; + uf::stl::vector transients; } void ext::HousamoBattle::initialize() { uf::Object::initialize(); @@ -110,18 +110,18 @@ void ext::HousamoBattle::initialize() { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = this->getComponent(); -// std::vector& transients = this->getComponent>(); +// uf::stl::vector& transients = this->getComponent>(); this->m_name = "Battle Manager"; // asset loading - this->addHook( "asset:Cache.Voice.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.Voice.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = this->getComponent(); uf::Serializer& masterdata = scene.getComponent(); - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -134,13 +134,13 @@ void ext::HousamoBattle::initialize() { return "true"; }); - this->addHook( "asset:Cache.SFX.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.SFX.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& masterdata = scene.getComponent(); - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -153,21 +153,21 @@ void ext::HousamoBattle::initialize() { return "true"; }); - this->addHook( "asset:Music.Load.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Music.Load.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string filename = ""; + uf::stl::string filename = ""; if ( ext::json::isArray( json["music"] ) ) { int ri = floor(rand() % json["music"].size()); - filename = json["music"][ri].as(); - } else if ( json["music"].is() ) { - filename = json["music"].as(); + filename = json["music"][ri].as(); + } else if ( json["music"].is() ) { + filename = json["music"].as(); } if ( filename != "" ) playMusic(*this, filename); return "true"; }); // bind events - this->addHook( "world:Battle.Start.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Start.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; metadata["battle"] = json["battle"]; @@ -196,7 +196,7 @@ void ext::HousamoBattle::initialize() { // for ( auto& id : metadata["battle"]["player"]["party"] ) { ext::json::forEach(metadata["battle"]["player"]["party"], [&](ext::json::Value& id){ uint64_t uid = transients.size(); - auto& member = metadata["battle"]["player"]["transients"][id.as()]; + auto& member = metadata["battle"]["player"]["transients"][id.as()]; member["uid"] = uid; ext::Housamo* transient = new ext::Housamo; @@ -214,7 +214,7 @@ void ext::HousamoBattle::initialize() { // for ( auto& id : metadata["battle"]["enemy"]["party"] ) { ext::json::forEach(metadata["battle"]["enemy"]["party"], [&](ext::json::Value& id){ uint64_t uid = transients.size(); - auto& member = metadata["battle"]["enemy"]["transients"][id.as()]; + auto& member = metadata["battle"]["enemy"]["transients"][id.as()]; member["uid"] = uid; ext::Housamo* transient = new ext::Housamo; @@ -237,12 +237,12 @@ void ext::HousamoBattle::initialize() { ext::json::forEach(metadata["skills"], [&](ext::json::Value& member){ // for ( auto& skillId : member["skills"] ) { ext::json::forEach(member["skills"], [&](ext::json::Value& skillId){ - uf::Serializer skillData = masterDataGet("Skill", skillId.as()); + uf::Serializer skillData = masterDataGet("Skill", skillId.as()); if ( skillData["type"].as() != 16 ) return; // for ( auto& status : skillData["statuses"] ) { ext::json::forEach(skillData["status"], [&](ext::json::Value& status){ - std::string target = status["target"].as(); - std::string statusId = status["id"].as(); + uf::stl::string target = status["target"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); float r = (rand() % 100) / 100.0; @@ -255,18 +255,18 @@ void ext::HousamoBattle::initialize() { // apply status uf::Serializer targets; if ( target == "self" ) { - targets.emplace_back(member["uid"].as()); + targets.emplace_back(member["uid"].as()); } else if ( target == "enemy" ) { // for ( auto& tmember : metadata["battle"]["transients"] ) { ext::json::forEach(metadata["battle"]["transients"], [&](ext::json::Value& tmember){ if ( tmember["type"] == member["type"] ) return; - targets.emplace_back(tmember["uid"].as()); + targets.emplace_back(tmember["uid"].as()); }); } else if ( target == "ally" ) { // for ( auto& tmember : metadata["battle"]["transients"] ) { ext::json::forEach(metadata["battle"]["transients"], [&](ext::json::Value& tmember){ if ( tmember["type"] != member["type"] ) return; - targets.emplace_back(tmember["uid"].as()); + targets.emplace_back(tmember["uid"].as()); }); } // for ( auto& target : targets ) { @@ -276,12 +276,12 @@ void ext::HousamoBattle::initialize() { statusPayload["modifier"] = status["modifier"]; statusPayload["turns"] = status["turns"].is() ? status["turns"] : statusData["turns"]; - metadata["battle"]["transients"][target.as()]["statuses"].emplace_back(statusPayload); + metadata["battle"]["transients"][target.as()]["statuses"].emplace_back(statusPayload); - uf::Serializer cardData = masterDataGet( "Card", metadata["battle"]["transients"][target.as()]["id"].as() ); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet( "Card", metadata["battle"]["transients"][target.as()]["id"].as() ); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - payload["message"] = payload["message"].as() + "\nApplied "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + " to " + charaData["name"].as(); + payload["message"] = payload["message"].as() + "\nApplied "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + " to " + charaData["name"].as(); }); }); }); @@ -290,7 +290,7 @@ void ext::HousamoBattle::initialize() { payload["battle"] = metadata["battle"]; return payload; }); - this->addHook( "world:Battle.Gui.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Gui.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ ext::Gui* guiManager = (ext::Gui*) this->globalFindByName("Gui Manager"); ext::Gui* guiMenu = new ext::GuiBattle; guiManager->addChild(*guiMenu); @@ -306,13 +306,13 @@ void ext::HousamoBattle::initialize() { return "true"; }); // json.action and json.uid - this->addHook( "world:Battle.Action.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Action.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string hookName = ""; + uf::stl::string hookName = ""; uf::Serializer payload; - std::string action = json["action"].as(); + uf::stl::string action = json["action"].as(); // dead check struct { @@ -398,16 +398,16 @@ void ext::HousamoBattle::initialize() { { // for ( auto it = metadata["battle"]["transients"].begin(); it != metadata["battle"]["transients"].end(); ++it ) { - // std::string key = it.key(); - ext::json::forEach(metadata["battle"]["transients"], [&](const std::string& key, ext::json::Value& member){ + // uf::stl::string key = it.key(); + ext::json::forEach(metadata["battle"]["transients"], [&](const uf::stl::string& key, ext::json::Value& member){ if ( key == "" || ext::json::isNull( member["type"] ) ) metadata["battle"].erase(key); }); } /* remove dead */ if ( false ) { // for ( auto it = metadata["battle"]["transients"].begin(); it != metadata["battle"]["transients"].end(); ++it ) { - // std::string key = it.key(); - ext::json::forEach(metadata["battle"]["transients"], [&](const std::string& key, ext::json::Value& member){ + // uf::stl::string key = it.key(); + ext::json::forEach(metadata["battle"]["transients"], [&](const uf::stl::string& key, ext::json::Value& member){ if ( metadata["battle"]["transients"][key]["hp"].as() > 0 ) return; // metadata["battle"]["transients"].erase(key); }); @@ -427,24 +427,24 @@ void ext::HousamoBattle::initialize() { return result; }); - this->addHook( "world:Battle.AI.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.AI.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; // default to attack - std::string queuedSkillId = "0"; + uf::stl::string queuedSkillId = "0"; if ( json["uid"] == "" ) { json["skill"] = "0"; return json; } - auto& member = metadata["battle"]["transients"][json["uid"].as()]; + auto& member = metadata["battle"]["transients"][json["uid"].as()]; // deduce member state struct { - std::vector ailments; + uf::stl::vector ailments; int ndas = 0; float factor = 0.0f; } stats; // for ( auto& status : member["statuses"] ) { ext::json::forEach(metadata["statuses"], [&](ext::json::Value& status){ - std::string id = status["id"].as(); + uf::stl::string id = status["id"].as(); if ( id == "0" ) return; stats.ailments.push_back(id); if ( id == "6" ) ++stats.ndas; @@ -454,7 +454,7 @@ void ext::HousamoBattle::initialize() { possibilities = ext::json::array(); // for ( auto& skillId : member["skills"] ) { ext::json::forEach(metadata["skills"], [&](ext::json::Value& skillId, bool breaks){ - uf::Serializer skillData = masterDataGet("Skill", skillId.as()); + uf::Serializer skillData = masterDataGet("Skill", skillId.as()); // not recarms std::cout << skillData["name"] << ": "; if ( skillId == "81" || skillId == "82" ) { @@ -477,13 +477,13 @@ void ext::HousamoBattle::initialize() { return; } // do not use same skills - if ( std::find(member["used skills"].begin(), member["used skills"].end(), skillId.as()) != member["used skills"].end() ) { + if ( std::find(member["used skills"].begin(), member["used skills"].end(), skillId.as()) != member["used skills"].end() ) { std::cout << "\tRecently Used" << std::endl; return; } // grants additional turns if ( skillData["turns+"].is() ) { - queuedSkillId = skillId.as(); + queuedSkillId = skillId.as(); std::cout << "\tCan gain turns" << std::endl; breaks = true; return; @@ -491,14 +491,14 @@ void ext::HousamoBattle::initialize() { } else if ( member["hp"].as() / member["max hp"].as() < 0.3f ) { if ( skillData["type"] != "14" ) return; if ( stats.factor < skillData["power"].as() ) { - queuedSkillId = skillId.as(); + queuedSkillId = skillId.as(); stats.factor = skillData["power"].as(); std::cout << "\tCan heal" << std::endl; } // remove debuffs } else if ( skillId == "200" ) { if ( stats.ndas * 75.0f > stats.factor ) { - queuedSkillId = skillId.as(); + queuedSkillId = skillId.as(); stats.factor = stats.ndas * 75.0f; std::cout << "\tCan Dekunda" << std::endl; } @@ -507,14 +507,14 @@ void ext::HousamoBattle::initialize() { // remove negative ailment (fear, etc) // for ( auto& status : skillData["statuses"] ) { ext::json::forEach(skillData["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; } // remove statuses if ( statusData["type"] == "remove" && std::find( stats.ailments.begin(), stats.ailments.end(), statusId ) != stats.ailments.end() ) { - queuedSkillId = skillId.as(); + queuedSkillId = skillId.as(); stats.factor = 150.0f; std::cout << "\tCan remove status " << statusData["name"] << std::endl; } @@ -531,25 +531,25 @@ void ext::HousamoBattle::initialize() { if ( queuedSkillId == "0" && possibilities.size() > 0 ) { possibilities.emplace_back("0"); int ri = floor(rand() % possibilities.size()); - queuedSkillId = possibilities[ri].as(); + queuedSkillId = possibilities[ri].as(); auto queuedSkillData = masterDataGet( "Skill", queuedSkillId ); - std::cout << "Picked " << queuedSkillData["name"].as() << std::endl; + std::cout << "Picked " << queuedSkillData["name"].as() << std::endl; } json["skill"] = queuedSkillId; return json; }); - this->addHook( "world:Battle.GetTargets.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.GetTargets.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Serializer payload; payload["targets"] = ext::json::array(); - auto& member = metadata["battle"]["transients"][json["uid"].as()]; - if ( json["skill"].is() ) { - std::string skillId = json["skill"].as(); + auto& member = metadata["battle"]["transients"][json["uid"].as()]; + if ( json["skill"].is() ) { + uf::stl::string skillId = json["skill"].as(); if ( json["skill"] == "0" ) { // for ( auto& status : member["statuses"] ) { ext::json::forEach(member["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -557,18 +557,18 @@ void ext::HousamoBattle::initialize() { if ( statusData["skill"] != skillId ) return; if ( statusData["range"].is() ) json["range"] = statusData["range"]; }); - } else if ( !json["type"].is() ) { + } else if ( !json["type"].is() ) { uf::Serializer skillData = masterDataGet( "Skill", skillId ); - json["type"] = skillData["target"].as(); + json["type"] = skillData["target"].as(); if ( json["type"] == "" ) json["type"] = "enemy"; } } else { json["type"] = "all"; } - if ( json["type"].is() ) { + if ( json["type"].is() ) { if ( json["type"] == "self" ) { - payload["targets"].emplace_back( metadata["battle"]["transients"][json["uid"].as()] ); + payload["targets"].emplace_back( metadata["battle"]["transients"][json["uid"].as()] ); } else { for ( auto& m : metadata["battle"]["transients"] ) { if ( json["type"] == "ally" && m["type"] != member["type"] ) continue; @@ -579,7 +579,7 @@ void ext::HousamoBattle::initialize() { } return payload; }); - this->addHook( "world:Battle.Escape.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Escape.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer payload; float r = (rand() % 100) / 100.0; if ( r > 0.9 ) { @@ -593,7 +593,7 @@ void ext::HousamoBattle::initialize() { } return payload; }); - this->addHook( "world:Battle.Talk.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Talk.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer payload; float r = (rand() % 100) / 100.0; payload["message"] = ""; @@ -601,26 +601,26 @@ void ext::HousamoBattle::initialize() { payload["invalid"] = true; uf::Serializer target; - std::string name; + uf::stl::string name; // for ( auto& member : metadata["battle"]["transients"] ) { ext::json::forEach(metadata["battle"]["transients"], [&](ext::json::Value& member, bool breaks){ if ( member["type"] != "enemy" ) return; target = (ext::json::Value&) member; size_t uid = member["uid"].as(); - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - name = charaData["name"].as(); + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + name = charaData["name"].as(); breaks = true; }); if ( target ) { - playSound(*this, target["id"].as(), r > 0.5 ? "turn" : "battlestart"); + playSound(*this, target["id"].as(), r > 0.5 ? "turn" : "battlestart"); payload["message"] = ""+colorString("FF0000") + "" + name + ""+colorString("FFFFFF") + " speaks."; } return payload; }); - this->addHook( "world:Battle.OnHit.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.OnHit.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uint64_t uid = json["uid"].as(); ext::Housamo* transient = transients.at(uid); @@ -642,12 +642,12 @@ void ext::HousamoBattle::initialize() { hMetadata["color"][3] = color[3]; return "true"; }); - this->addHook( "world:Battle.Turn.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Turn.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; bool found = false; uint64_t turnPlayer = json["uid"].as(); - std::string name = ""; + uf::stl::string name = ""; auto& turnState = metadata["battle"]["turn"]; { if ( turnState["counter"].as() <= 0 ) { @@ -661,7 +661,7 @@ void ext::HousamoBattle::initialize() { bool locked = false; // for ( auto& status : member["statuses"] ) { ext::json::forEach(member["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -695,7 +695,7 @@ void ext::HousamoBattle::initialize() { bool locked = false; // for ( auto& status : member["statuses"] ) { ext::json::forEach(member["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -727,10 +727,10 @@ void ext::HousamoBattle::initialize() { } payload["uid"] = turnPlayer; - auto& member = metadata["battle"]["transients"][payload["uid"].as()]; - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - name = charaData["name"].as(); + auto& member = metadata["battle"]["transients"][payload["uid"].as()]; + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + name = charaData["name"].as(); payload["message"] = "What will "+colorString("FF0000") + "" + name + ""+colorString("FFFFFF") + " do?"; // @@ -744,7 +744,7 @@ void ext::HousamoBattle::initialize() { if ( turnState["start of turn"].as() ) { /* remove dead */ if ( false ) { for ( auto it = metadata["battle"]["transients"].begin(); it != metadata["battle"]["transients"].end(); ++it ) { - std::string key = it.key(); + uf::stl::string key = it.key(); if ( metadata["battle"]["transients"][key]["hp"].as() > 0 ) continue; // metadata["battle"]["transients"].erase(key); } @@ -756,33 +756,33 @@ void ext::HousamoBattle::initialize() { member["used skills"] = ext::json::array(); if ( member["type"] != turnState["phase"] ) return; auto& statuses = member["statuses"]; -// std::cout << "Before: " << member["uid"].as() << ": " << statuses << std::endl; +// std::cout << "Before: " << member["uid"].as() << ": " << statuses << std::endl; // for ( int i = 0; i < statuses.size(); ++i ) { ext::json::forEach(statuses, [&](size_t i, ext::json::Value& status){ - uf::Serializer statusData = masterDataGet("Status", status["id"].as()); + uf::Serializer statusData = masterDataGet("Status", status["id"].as()); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; } - uf::Serializer cardData = masterDataGet( "Card", member["id"].as() ); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet( "Card", member["id"].as() ); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); if ( statusData["hp"].is() ) { int64_t hp = statusData["hp"].as(); member["hp"] = member["hp"].as() + hp; - payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + " gained "+colorString("00FF00") + ""+ std::to_string(hp) +" HP"+colorString("FFFFFF") + " from "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + ""; + payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + " gained "+colorString("00FF00") + ""+ std::to_string(hp) +" HP"+colorString("FFFFFF") + " from "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + ""; } if ( statusData["hp%"].is() ) { int64_t hp = member["max hp"].as() * (statusData["hp%"].as() / 100.0f); if ( member["max hp"].as() < member["hp"].as() + hp ) hp = member["max hp"].as() - member["hp"].as(); member["hp"] = member["hp"].as() + hp; - if ( hp > 0 ) payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + " gained "+colorString("00FF00") + ""+ std::to_string(hp) +" HP"+colorString("FFFFFF") + " from "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + ""; + if ( hp > 0 ) payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + " gained "+colorString("00FF00") + ""+ std::to_string(hp) +" HP"+colorString("FFFFFF") + " from "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + ""; } if ( statusData["mp"].is() ) { int64_t mp = statusData["mp"].as(); member["mp"] = member["mp"].as() + mp; if ( member["max mp"].as() < member["mp"].as() + mp ) mp = member["max mp"].as() - member["mp"].as(); - payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + " gained "+colorString("0000FF") + ""+ std::to_string(mp) +" MP"+colorString("FFFFFF") + " from "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + ""; + payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + " gained "+colorString("0000FF") + ""+ std::to_string(mp) +" MP"+colorString("FFFFFF") + " from "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + ""; } if ( statusData["lock"].is() ) { skipped = true; @@ -791,11 +791,11 @@ void ext::HousamoBattle::initialize() { uf::Serializer newStatuses; for ( int i = statuses.size() - 1; i >= 0; --i ) { auto& status = statuses[i]; - uf::Serializer statusData = masterDataGet("Status", status["id"].as()); + uf::Serializer statusData = masterDataGet("Status", status["id"].as()); if ( !ext::json::isNull( status["turns"] ) ) { status["turns"] = status["turns"].as() - 1; if ( status["turns"].as() < 0 ) { - if ( statusData["id"] != "0" ) payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + " wore off."; + if ( statusData["id"] != "0" ) payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + " wore off."; } else { newStatuses.emplace_back(status); } @@ -804,13 +804,13 @@ void ext::HousamoBattle::initialize() { } } statuses = newStatuses; -// std::cout << "After: " << member["uid"].as() << ": " << statuses << std::endl; +// std::cout << "After: " << member["uid"].as() << ": " << statuses << std::endl; }); } { for ( auto it = metadata["battle"]["transients"].begin(); it != metadata["battle"]["transients"].end(); ++it ) { - std::string key = it.key(); + uf::stl::string key = it.key(); if ( key == "" || ext::json::isNull( (*it)["type"] ) ) metadata["battle"].erase(key); } } @@ -823,7 +823,7 @@ void ext::HousamoBattle::initialize() { if ( skipped ) payload["skipped"] = true; /* - std::vector list = { + uf::stl::vector list = { "member-attack", "member-skill", "inventory", @@ -848,21 +848,21 @@ void ext::HousamoBattle::initialize() { payload[""] = member; return payload; }); - this->addHook( "world:Battle.Attack.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Attack.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string skillId = json["skill"].as(); + uf::stl::string skillId = json["skill"].as(); uf::Serializer skillData = masterDataGet("Skill", skillId); // ext::Housamo* transient = transients.at(uid); - auto& member = metadata["battle"]["transients"][json["uid"].as()]; + auto& member = metadata["battle"]["transients"][json["uid"].as()]; uf::Serializer payload; payload["message"] = ""; // modify skill data based on statuses // for ( auto& status : member["statuses"] ) { ext::json::forEach(member["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -884,7 +884,7 @@ void ext::HousamoBattle::initialize() { json["target"].emplace_back( m["uid"].as() ); }); } else { - std::vector targets; + uf::stl::vector targets; // for ( auto& m : metadata["battle"]["transients"] ) { ext::json::forEach(member["battle"]["transients"], [&](ext::json::Value& m){ if ( skillData["target"] == "ally" && m["type"] != member["type"] ) return; @@ -898,19 +898,19 @@ void ext::HousamoBattle::initialize() { } uf::Serializer elementData; - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string elementId; + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string elementId; float basePower = member["type"] == "enemy" ? 1.2f : 1.0f; if ( skillId != "0" ) { - payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + ": "+colorString("7777FF") + "" + skillData["name"].as() + colorString("FFFFFF"); + payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + ": "+colorString("7777FF") + "" + skillData["name"].as() + colorString("FFFFFF"); - elementId = skillData["type"].as(); + elementId = skillData["type"].as(); elementData = masterDataGet("Element", elementId); } else { - payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + ": "+colorString("7777FF") + "攻撃" + colorString("FFFFFF"); + payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "" + charaData["name"].as() + ""+colorString("FFFFFF") + ": "+colorString("7777FF") + "攻撃" + colorString("FFFFFF"); elementId = "0"; if ( cardData["weapon_type"] == "1" ) elementId = "1"; // slash @@ -945,7 +945,7 @@ void ext::HousamoBattle::initialize() { // for ( auto& status : member["statuses"] ) { ext::json::forEach(member["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -968,17 +968,17 @@ void ext::HousamoBattle::initialize() { hpCost = member["max hp"].as() * ( hpCost / 100.0f ); if ( mp < mpCost ) { - payload["message"] = "Not enough MP to use `"+colorString("FF0000") + ""+skillData["name"].as()+""+colorString("FFFFFF") + "`."; + payload["message"] = "Not enough MP to use `"+colorString("FF0000") + ""+skillData["name"].as()+""+colorString("FFFFFF") + "`."; payload["timeout"] = 2.0f; if ( member["type"] != "enemy" ) { payload["invalid"] = true; } return payload; } else if ( mpCost > 0 ) { - metadata["battle"]["transients"][member["uid"].as()]["mp"] = mp - mpCost; + metadata["battle"]["transients"][member["uid"].as()]["mp"] = mp - mpCost; } if ( hp < hpCost ) { - payload["message"] = "Not enough HP to use `"+colorString("FF0000") + ""+skillData["name"].as()+""+colorString("FFFFFF") + "`."; + payload["message"] = "Not enough HP to use `"+colorString("FF0000") + ""+skillData["name"].as()+""+colorString("FFFFFF") + "`."; payload["timeout"] = 2.0f; if ( member["type"] != "enemy" ) { payload["invalid"] = true; @@ -988,7 +988,7 @@ void ext::HousamoBattle::initialize() { skillData = masterDataGet("Skill", skillId); } } else if ( hpCost > 0 ) { - metadata["battle"]["transients"][member["uid"].as()]["hp"] = hp - hpCost; + metadata["battle"]["transients"][member["uid"].as()]["hp"] = hp - hpCost; { uf::Serializer payload; payload["uid"] = member["uid"]; @@ -1001,21 +1001,21 @@ void ext::HousamoBattle::initialize() { if ( skillData["turns+"].is() ) { member["used skills"].emplace_back(skillId); - payload["message"] = payload["message"].as() + "\nGained "+colorString("FF0000") + ""+skillData["turns+"].as()+""+colorString("FFFFFF") + " additional turns!"; + payload["message"] = payload["message"].as() + "\nGained "+colorString("FF0000") + ""+skillData["turns+"].as()+""+colorString("FFFFFF") + " additional turns!"; metadata["battle"]["turn"]["counter"] = metadata["battle"]["turn"]["counter"].as() + skillData["turns+"].as(); } // for ( auto& targetId : json["target"] ) { ext::json::forEach(json["target"], [&](ext::json::Value& targetId){ - uf::Serializer target = metadata["battle"]["transients"][targetId.as()]; + uf::Serializer target = metadata["battle"]["transients"][targetId.as()]; float power = basePower; float morePower = 0; float probability = skillData["proc"].is() ? skillData["proc"].as() / 100.0f : 1.0f; // modify probability from statuses - // for ( auto& status : metadata["battle"]["transients"][json["uid"].as()]["statuses"] ) { - ext::json::forEach(metadata["battle"]["transients"][json["uid"].as()]["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + // for ( auto& status : metadata["battle"]["transients"][json["uid"].as()]["statuses"] ) { + ext::json::forEach(metadata["battle"]["transients"][json["uid"].as()]["statuses"], [&](ext::json::Value& status){ + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -1033,13 +1033,13 @@ void ext::HousamoBattle::initialize() { if ( statusData["proc+"].is() ) { float moreProb = statusData["proc+"].as() / 100.0f; probability += moreProb; - payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(moreProb*100)) + "%"+colorString("FF0000") + " more probability"+colorString("FFFFFF") + ""; + payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(moreProb*100)) + "%"+colorString("FF0000") + " more probability"+colorString("FFFFFF") + ""; } }); // find attack modifying statuses on attacker - // for ( auto& status : metadata["battle"]["transients"][json["uid"].as()]["statuses"] ) { - ext::json::forEach(metadata["battle"]["transients"][json["uid"].as()]["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + // for ( auto& status : metadata["battle"]["transients"][json["uid"].as()]["statuses"] ) { + ext::json::forEach(metadata["battle"]["transients"][json["uid"].as()]["statuses"], [&](ext::json::Value& status){ + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -1059,13 +1059,13 @@ void ext::HousamoBattle::initialize() { if ( statusData["power"].is() ) { float adjust = statusData["power"].as() / 100.0f; morePower += adjust; - // payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(adjust*100)) + "%"+colorString("FF0000") + " more power"+colorString("FFFFFF") + ""; + // payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(adjust*100)) + "%"+colorString("FF0000") + " more power"+colorString("FFFFFF") + ""; } }); // find defense modifying statuses on target - // for ( auto& status : metadata["battle"]["transients"][targetId.as()]["statuses"] ) { - ext::json::forEach(metadata["battle"]["transients"][targetId.as()]["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + // for ( auto& status : metadata["battle"]["transients"][targetId.as()]["statuses"] ) { + ext::json::forEach(metadata["battle"]["transients"][targetId.as()]["statuses"], [&](ext::json::Value& status){ + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -1083,10 +1083,10 @@ void ext::HousamoBattle::initialize() { if ( statusData["defense"].is() ) { float adjust = statusData["defense"].as() / 100.0f; morePower -= adjust; - // payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(adjust*100)) + "%"+colorString("FF0000") + " more defense"+colorString("FFFFFF") + ""; + // payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(adjust*100)) + "%"+colorString("FF0000") + " more defense"+colorString("FFFFFF") + ""; } }); - // if ( morePower != 0 ) payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(morePower*100)) + "%"+colorString("FF0000") + " power modifier"+colorString("FFFFFF") + ""; + // if ( morePower != 0 ) payload["message"] = payload["message"].as() + "\n"+colorString("FF00FF") + "" + std::to_string((int)(morePower*100)) + "%"+colorString("FF0000") + " power modifier"+colorString("FFFFFF") + ""; float r = (rand() % 100) / 100.0; // missed @@ -1099,14 +1099,14 @@ void ext::HousamoBattle::initialize() { } bool repel = false; - std::function affinityCheck = [&]( const std::string& targetId ) { + std::function affinityCheck = [&]( const uf::stl::string& targetId ) { auto& target = metadata["battle"]["transients"][targetId]; - uf::Serializer cardData = masterDataGet("Card", target["id"].as()); + uf::Serializer cardData = masterDataGet("Card", target["id"].as()); uf::Serializer affinity = cardData["affinity"][elementId]; // affinity change check // for ( auto& status : target["statuses"] ) { ext::json::forEach(target["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -1123,19 +1123,19 @@ void ext::HousamoBattle::initialize() { if ( !ext::json::isNull( statusData["affinity"] ) ) { if ( !ext::json::isNull( statusData["affinity"][elementId] ) ) affinity = statusData["affinity"][elementId]; - // payload["message"] = payload["message"].as() + "\naffinity modifier."+colorString("FFFFFF") + ""; + // payload["message"] = payload["message"].as() + "\naffinity modifier."+colorString("FFFFFF") + ""; } }); if ( !ext::json::isNull( affinity ) ) { - std::string affinityStr = affinity.as(); + uf::stl::string affinityStr = affinity.as(); if ( repel && affinityStr == "repel" ) affinityStr = "null"; - if ( affinityStr == "weak" ) { payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Weak!\n"; morePower *= 2.0f; } - else if ( affinityStr == "strong" ) { payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Strong!\n"; morePower *= 0.5f; } - else if ( affinityStr == "drain" ) { turnEffects.endTurn = true; payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Drain!\n"; morePower *= -1.0f; } - else if ( affinityStr == "null" ) { turnEffects.loseTurn = 2; payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Nulled!\n"; morePower *= 0; } - else if ( affinityStr == "repel" ) { turnEffects.endTurn = true; payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Repelled!\n"; repel = true; + if ( affinityStr == "weak" ) { payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Weak!\n"; morePower *= 2.0f; } + else if ( affinityStr == "strong" ) { payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Strong!\n"; morePower *= 0.5f; } + else if ( affinityStr == "drain" ) { turnEffects.endTurn = true; payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Drain!\n"; morePower *= -1.0f; } + else if ( affinityStr == "null" ) { turnEffects.loseTurn = 2; payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Nulled!\n"; morePower *= 0; } + else if ( affinityStr == "repel" ) { turnEffects.endTurn = true; payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + "Repelled!\n"; repel = true; // check again - affinityCheck(json["uid"].as()); + affinityCheck(json["uid"].as()); } else { affinityStr = ""; } @@ -1147,7 +1147,7 @@ void ext::HousamoBattle::initialize() { showMessage( payload ); } } - }; affinityCheck(target["uid"].as()); + }; affinityCheck(target["uid"].as()); power += morePower; @@ -1191,10 +1191,10 @@ void ext::HousamoBattle::initialize() { } bool critted = false; - std::function applyDamage = [&]( const std::string& targetId ) { + std::function applyDamage = [&]( const uf::stl::string& targetId ) { auto& target = metadata["battle"]["transients"][targetId]; - uf::Serializer cardData = masterDataGet("Card", target["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet("Card", target["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); int curHp = target["hp"].as(); bool isCrit = ((rand() % 100) / 100.0) < 0.1; if ( damage == 0 ) isCrit = false; @@ -1232,7 +1232,7 @@ void ext::HousamoBattle::initialize() { int mpDrain = target["max mp"].as() * ratio; if ( target["mp"].as() > mpDrain ) mpDrain = target["mp"].as(); target["mp"] = target["mp"].as() - mpDrain; - payload["message"] = payload["message"].as() + "\n " + colorString("0000FF") + std::to_string(mpDrain); + payload["message"] = payload["message"].as() + "\n " + colorString("0000FF") + std::to_string(mpDrain); showMessage( payload ); @@ -1250,7 +1250,7 @@ void ext::HousamoBattle::initialize() { damage = oldDamage; if ( curHp <= 0 ) { - payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + ""+ charaData["name"].as() +" "+colorString("FFFFFF") + "died!"; + payload["message"] = payload["message"].as() + "\n"+colorString("FF0000") + ""+ charaData["name"].as() +" "+colorString("FFFFFF") + "died!"; target["hp"] = 0; uf::Serializer statusPayload; @@ -1258,12 +1258,12 @@ void ext::HousamoBattle::initialize() { target["statuses"] = ext::json::array(); target["statuses"].emplace_back(statusPayload); } - }; applyDamage(repel ? json["uid"].as() : target["uid"].as()); + }; applyDamage(repel ? json["uid"].as() : target["uid"].as()); // counter statuses if ( !repel ) { - // for ( auto& status : metadata["battle"]["transients"][target["uid"].as()]["statuses"] ) { - ext::json::forEach(metadata["battle"]["transients"][target["uid"].as()]["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + // for ( auto& status : metadata["battle"]["transients"][target["uid"].as()]["statuses"] ) { + ext::json::forEach(metadata["battle"]["transients"][target["uid"].as()]["statuses"], [&](ext::json::Value& status){ + uf::stl::string statusId = status["id"].as(); if ( statusId != "19" ) return; uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { @@ -1281,8 +1281,8 @@ void ext::HousamoBattle::initialize() { if ( statusData["proc"].is() ) { float r = (rand() % 100) / 100.0; if ( r <= statusData["proc"].as() / 100.0f ) { - applyDamage(json["uid"].as()); - payload["message"] = payload["message"].as() + "\nCountered!"; + applyDamage(json["uid"].as()); + payload["message"] = payload["message"].as() + "\nCountered!"; } } }); @@ -1291,8 +1291,8 @@ void ext::HousamoBattle::initialize() { { // for ( auto& status : skillData["statuses"] ) { ext::json::forEach(skillData["statuses"], [&](ext::json::Value& status){ - std::string target = status["target"].as(); - std::string statusId = status["id"].as(); + uf::stl::string target = status["target"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); if ( skillData["type"].as() == 16 ) return; float r = (rand() % 100) / 100.0; @@ -1309,16 +1309,16 @@ void ext::HousamoBattle::initialize() { uf::Serializer targets; if ( target == "self" ) { - targets.emplace_back(json["uid"].as()); + targets.emplace_back(json["uid"].as()); // } else if ( target == "enemy" || target == "ally" ) { } else { - targets.emplace_back(targetId.as()); + targets.emplace_back(targetId.as()); } // for ( auto& target : targets ) { ext::json::forEach(targets, [&](ext::json::Value& target){ // remove status(es) if ( status["type"] == "remove" ) { - for ( auto& statusC : metadata["battle"]["transients"][target.as()]["statuses"] ) { + for ( auto& statusC : metadata["battle"]["transients"][target.as()]["statuses"] ) { if ( statusC["id"] == statusId ) { statusC = ext::json::null(); statusC["id"] = 0; @@ -1333,20 +1333,20 @@ void ext::HousamoBattle::initialize() { statusPayload["modifier"] = status["modifier"]; statusPayload["turns"] = status["turns"].is() ? status["turns"] : statusData["turns"]; - metadata["battle"]["transients"][target.as()]["statuses"].emplace_back(statusPayload); + metadata["battle"]["transients"][target.as()]["statuses"].emplace_back(statusPayload); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; } - uf::Serializer cardData = masterDataGet( "Card", metadata["battle"]["transients"][target.as()]["id"].as() ); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet( "Card", metadata["battle"]["transients"][target.as()]["id"].as() ); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - // payload["message"] = payload["message"].as() + "\nApplied "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + " to " + charaData["name"].as(); + // payload["message"] = payload["message"].as() + "\nApplied "+colorString("FF0000") + "" + statusData["name"].as() + ""+colorString("FFFFFF") + " to " + charaData["name"].as(); { uf::Serializer payload; payload["uid"] = targetId; - payload["message"] = skillData["name"].as(); + payload["message"] = skillData["name"].as(); payload["color"] = "9900FF"; showMessage( payload ); } @@ -1358,9 +1358,9 @@ void ext::HousamoBattle::initialize() { float r = (rand() % 100) / 100.0; // if ( r < 0.5 ) { if ( r < 1.0 ) { - playSound(*this, member["id"].as(), r > 0.25 ? "attack" : "skill"); + playSound(*this, member["id"].as(), r > 0.25 ? "attack" : "skill"); } else { - playSound(*this, target["id"].as(), r > 0.75 ? "damagedsmall" : "damagedlarge"); + playSound(*this, target["id"].as(), r > 0.75 ? "damagedsmall" : "damagedlarge"); } for ( int i = 0; i < 16; ++i ) { uf::Serializer payload; @@ -1408,34 +1408,34 @@ void ext::HousamoBattle::initialize() { payload["timeout"] = 2.0f; return payload; }); - this->addHook( "world:Battle.Get.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.Get.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - auto& member = metadata["battle"]["transients"][json["uid"].as()]; + auto& member = metadata["battle"]["transients"][json["uid"].as()]; /* ext::Housamo* transient = transients.at(uid); uf::Serializer& member = transient->getComponent(); */ - std::string message; + uf::stl::string message; - uf::Serializer cardData = masterDataGet("Card", member["id"].as()); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::Serializer cardData = masterDataGet("Card", member["id"].as()); + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); uf::Serializer affinity = cardData["affinity"]; - std::string name = charaData["name"].as(); + uf::stl::string name = charaData["name"].as(); if ( member["type"] == "player" ) message += colorString("00FF00"); else if ( member["type"] == "enemy" ) message += colorString("FF0000"); else message += colorString("AAAAAA"); - message += name + colorString("FFFFFF") + ": " + member["type"].as(); + message += name + colorString("FFFFFF") + ": " + member["type"].as(); - message += "\n" + colorString("FF0000") + "HP: " + member["hp"].as(); - message += "\n" + colorString("0000FF") + "MP: " + member["mp"].as(); + message += "\n" + colorString("FF0000") + "HP: " + member["hp"].as(); + message += "\n" + colorString("0000FF") + "MP: " + member["mp"].as(); message += "\n" + colorString("9900FF") + "Ailments" + colorString("FFFFFF") + ":"; // for ( auto& status : member["statuses"] ) { ext::json::forEach(member["statuses"], [&](ext::json::Value& status){ - std::string statusId = status["id"].as(); + uf::stl::string statusId = status["id"].as(); uf::Serializer statusData = masterDataGet("Status", statusId); for ( auto it = status["modifier"].begin(); it != status["modifier"].end(); ++it ) { statusData[it.key()] = *it; @@ -1445,17 +1445,17 @@ void ext::HousamoBattle::initialize() { for ( auto it = statusData["affinity"].begin(); it != statusData["affinity"].end(); ++it ) { affinity[it.key()] = *it; } - message += "\n\t" + statusData["name"].as() + (ext::json::isNull( status["turns"] ) ? "" : " (Turns: " + status["turns"].as() + ")" ); + message += "\n\t" + statusData["name"].as() + (ext::json::isNull( status["turns"] ) ? "" : " (Turns: " + status["turns"].as() + ")" ); }); message += "\n" + colorString("9900FF") + "Affinities" + colorString("FFFFFF") + ":"; // for ( auto it = affinity.begin(); it != affinity.end(); ++it ) { - // std::string elementId = it.key(); - // std::string value = it->as(); - ext::json::forEach(affinity, [&](const std::string& elementId, ext::json::Value& value){ + // uf::stl::string elementId = it.key(); + // uf::stl::string value = it->as(); + ext::json::forEach(affinity, [&](const uf::stl::string& elementId, ext::json::Value& value){ uf::Serializer elementData = masterDataGet("Element", elementId); - message += "\n\t" + elementData["name"].as() + ": " + value.as(); + message += "\n\t" + elementData["name"].as() + ": " + value.as(); }); uf::Serializer payload; @@ -1464,7 +1464,7 @@ void ext::HousamoBattle::initialize() { payload["message"] = message; return payload; }); - this->addHook( "world:Battle.End.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "world:Battle.End.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; // play music /* @@ -1509,7 +1509,7 @@ void ext::HousamoBattle::initialize() { payload["end"] = true; return payload; /* - if ( json["action"].as() == "killed" ) { + if ( json["action"].as() == "killed" ) { // play death sound playSound(*this, metadata["battle"]["enemy"]["uid"].as(), "killed"); // kill diff --git a/ext/scenes/worldscape/housamo/dialogue.cpp b/ext/scenes/worldscape/housamo/dialogue.cpp index 36b985b5..f353fd1c 100644 --- a/ext/scenes/worldscape/housamo/dialogue.cpp +++ b/ext/scenes/worldscape/housamo/dialogue.cpp @@ -21,30 +21,30 @@ namespace { ext::Gui* gui; - uf::Serializer masterTableGet( const std::string& table ) { + uf::Serializer masterTableGet( const uf::stl::string& table ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table]; } - uf::Serializer masterDataGet( const std::string& table, const std::string& key ) { + uf::Serializer masterDataGet( const uf::stl::string& table, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table][key]; } - inline int64_t parseInt( const std::string& str ) { + inline int64_t parseInt( const uf::stl::string& str ) { return atoi(str.c_str()); } } namespace { - void playSound( ext::DialogueManager& entity, const std::string& id, const std::string& key ) { + void playSound( ext::DialogueManager& entity, const uf::stl::string& id, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& masterdata = scene.getComponent(); uf::Serializer cardData = masterDataGet("Card", id); - uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); - std::string name = charaData["filename"].as(); - std::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; + uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].as()); + uf::stl::string name = charaData["filename"].as(); + uf::stl::string url = "https://cdn..xyz//unity/Android/voice/voice_" + name + "_"+key+".ogg"; std::cout << url << std::endl; @@ -55,7 +55,7 @@ namespace { uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid())); } - void playSound( ext::DialogueManager& entity, std::size_t uid, const std::string& key ) { + void playSound( ext::DialogueManager& entity, std::size_t uid, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& pMetadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); @@ -63,20 +63,20 @@ namespace { uf::Entity* = scene.findByUid(uid); if ( ! ) return; uf::Serializer& metadata = ->getComponent(); - std::string id = metadata[""]["id"].as(); + uf::stl::string id = metadata[""]["id"].as(); playSound( entity, id, key ); } - void playSound( ext::DialogueManager& entity, const std::string& key ) { + void playSound( ext::DialogueManager& entity, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = entity.getComponent(); uf::Serializer& masterdata = scene.getComponent(); - std::string url = "./" + key + ".ogg"; + uf::stl::string url = "./" + key + ".ogg"; uf::Asset& assetLoader = scene.getComponent(); assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid())); } - void playMusic( ext::DialogueManager& entity, const std::string& filename ) { + void playMusic( ext::DialogueManager& entity, const uf::stl::string& filename ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Asset& assetLoader = scene.getComponent(); uf::Serializer& masterdata = scene.getComponent(); @@ -86,7 +86,7 @@ namespace { uf::Audio sfx; uf::Audio voice; - std::vector transients; + uf::stl::vector transients; } void ext::DialogueManager::initialize() { uf::Object::initialize(); @@ -95,18 +95,18 @@ void ext::DialogueManager::initialize() { transients.clear(); uf::Serializer& metadata = this->getComponent(); -// std::vector& transients = this->getComponent>(); +// uf::stl::vector& transients = this->getComponent>(); this->m_name = "Dialogue Manager"; // asset loading - this->addHook( "asset:Cache.Voice.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.Voice.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& metadata = this->getComponent(); uf::Serializer& masterdata = scene.getComponent(); - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -119,13 +119,13 @@ void ext::DialogueManager::initialize() { return "true"; }); - this->addHook( "asset:Cache.SFX.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Cache.SFX.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& masterdata = scene.getComponent(); - std::string filename = json["filename"].as(); + uf::stl::string filename = json["filename"].as(); if ( uf::io::extension(filename) != "ogg" ) return "false"; @@ -138,24 +138,24 @@ void ext::DialogueManager::initialize() { return "true"; }); - this->addHook( "asset:Music.Load.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Music.Load.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - if ( json["music"].is() ) playMusic(*this, json["music"].as()); + if ( json["music"].is() ) playMusic(*this, json["music"].as()); return "true"; }); - this->addHook( "asset:Sfx.Load.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Sfx.Load.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - if ( json["sfx"].is() ) playSound(*this, json["sfx"].as()); + if ( json["sfx"].is() ) playSound(*this, json["sfx"].as()); return "true"; }); - this->addHook( "asset:Voice.Load.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "asset:Voice.Load.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - if ( ext::json::isObject( json["voice"] ) ) playSound(*this, json["voice"]["id"].as(), json["voice"]["key"].as()); + if ( ext::json::isObject( json["voice"] ) ) playSound(*this, json["voice"]["id"].as(), json["voice"]["key"].as()); return "true"; }); // bind events - this->addHook( "menu:Dialogue.Start.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.Start.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; { metadata["dialogue"] = json["dialogue"]; @@ -173,7 +173,7 @@ void ext::DialogueManager::initialize() { payload["dialogue"] = metadata["dialogue"]; return payload; }); - this->addHook( "menu:Dialogue.Gui.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.Gui.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ ext::Gui* guiManager = (ext::Gui*) this->globalFindByName("Gui Manager"); ext::Gui* guiMenu = new ext::GuiDialogue; guiManager->addChild(*guiMenu); @@ -189,13 +189,13 @@ void ext::DialogueManager::initialize() { return "true"; }); // json.action and json.uid - this->addHook( "menu:Dialogue.Action.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.Action.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; - std::string hookName = ""; + uf::stl::string hookName = ""; uf::Serializer payload; - std::string action = json["action"].as(); + uf::stl::string action = json["action"].as(); if ( action == "dialogue-select" ) { payload = json; @@ -212,21 +212,21 @@ void ext::DialogueManager::initialize() { return result; }); - this->addHook( "menu:Dialogue.Turn.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.Turn.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; uf::Serializer payload; - std::string index = json["index"].as(); + uf::stl::string index = json["index"].as(); uf::Serializer part = metadata["dialogue"][index]; if ( part["quit"].as() ) return this->callHook("menu:Dialogue.End.%UID%")[0].as(); payload["message"] = part["message"]; payload["actions"] = part["actions"]; - if ( part["music"].is() ) { + if ( part["music"].is() ) { uf::Serializer pload; pload["music"] = part["music"]; this->queueHook( "asset:Music.Load.%UID%", pload ); } - if ( part["sfx"].is() ) { + if ( part["sfx"].is() ) { uf::Serializer pload; pload["sfx"] = part["sfx"]; this->queueHook( "asset:Sfx.Load.%UID%", pload ); @@ -242,11 +242,11 @@ void ext::DialogueManager::initialize() { // for ( auto hook : part["hooks"] ) { ext::json::forEach(part["hooks"], [&](ext::json::Value& hook){ hook["payload"]["uid"] = metadata["uid"]; - this->queueHook( hook["name"].as(), uf::Serializer{hook["payload"]}, hook["timeout"].as() ); + this->queueHook( hook["name"].as(), uf::Serializer{hook["payload"]}, hook["timeout"].as() ); }); return payload; }); - this->addHook( "menu:Dialogue.End.%UID%", [&](const std::string& event)->std::string{ + this->addHook( "menu:Dialogue.End.%UID%", [&](const uf::stl::string& event)->uf::stl::string{ uf::Serializer json = event; // play music uf::Scene& scene = uf::scene::getCurrentScene(); diff --git a/ext/scenes/worldscape/housamo/housamo.cpp b/ext/scenes/worldscape/housamo/housamo.cpp index ec7daf7b..06629e25 100644 --- a/ext/scenes/worldscape/housamo/housamo.cpp +++ b/ext/scenes/worldscape/housamo/housamo.cpp @@ -5,17 +5,17 @@ #include namespace { - uf::Serializer masterTableGet( const std::string& table ) { + uf::Serializer masterTableGet( const uf::stl::string& table ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table]; } - uf::Serializer masterDataGet( const std::string& table, const std::string& key ) { + uf::Serializer masterDataGet( const uf::stl::string& table, const uf::stl::string& key ) { uf::Scene& scene = uf::scene::getCurrentScene(); uf::Serializer& mastertable = scene.getComponent(); return mastertable["system"]["mastertable"][table][key]; } - inline int64_t parseInt( const std::string& str ) { + inline int64_t parseInt( const uf::stl::string& str ) { return atoi(str.c_str()); } } @@ -39,58 +39,58 @@ void ext::Housamo::initialize() { * "skin": "skin1" }, */ - std::string id = metadata[""]["id"].as(); - uint64_t lv = !ext::json::isNull( metadata[""]["level"] ) ? parseInt(metadata[""]["level"].as()) : parseInt(metadata[""]["lv"].as()); - uint64_t sl = !ext::json::isNull( metadata[""]["skill level"] ) ? parseInt(metadata[""]["skill level"].as()) : parseInt(metadata[""]["sl"].as()); - uint64_t jingi = parseInt(metadata[""]["jingi"].as()); - uint64_t limit = parseInt(metadata[""]["limit"].as()); - uint64_t str = parseInt(metadata[""]["str"].as()); - uint64_t mag = parseInt(metadata[""]["mag"].as()); - uint64_t vit = parseInt(metadata[""]["vit"].as()); - uint64_t agi = parseInt(metadata[""]["agi"].as()); - int64_t hp = ext::json::isNull( metadata[""]["hp"] ) ? -1 : parseInt(metadata[""]["hp"].as()); - int64_t mp = ext::json::isNull( metadata[""]["mp"] ) ? -1 : parseInt(metadata[""]["mp"].as()); + uf::stl::string id = metadata[""]["id"].as(); + uint64_t lv = !ext::json::isNull( metadata[""]["level"] ) ? parseInt(metadata[""]["level"].as()) : parseInt(metadata[""]["lv"].as()); + uint64_t sl = !ext::json::isNull( metadata[""]["skill level"] ) ? parseInt(metadata[""]["skill level"].as()) : parseInt(metadata[""]["sl"].as()); + uint64_t jingi = parseInt(metadata[""]["jingi"].as()); + uint64_t limit = parseInt(metadata[""]["limit"].as()); + uint64_t str = parseInt(metadata[""]["str"].as()); + uint64_t mag = parseInt(metadata[""]["mag"].as()); + uint64_t vit = parseInt(metadata[""]["vit"].as()); + uint64_t agi = parseInt(metadata[""]["agi"].as()); + int64_t hp = ext::json::isNull( metadata[""]["hp"] ) ? -1 : parseInt(metadata[""]["hp"].as()); + int64_t mp = ext::json::isNull( metadata[""]["mp"] ) ? -1 : parseInt(metadata[""]["mp"].as()); - std::vector skills; + uf::stl::vector skills; for ( auto i = 0; i < metadata[""]["skills"].size(); ++i ) { - skills.push_back(metadata[""]["skills"][i].as()); + skills.push_back(metadata[""]["skills"][i].as()); } uf::Serializer cardData = masterDataGet("Card",id); /* { - uint64_t base = parseInt(cardData["base_hp"].as()); - uint64_t max = parseInt(cardData["max_hp"].as()); - uint64_t maxlv = parseInt(cardData["max_lv"].as()); + uint64_t base = parseInt(cardData["base_hp"].as()); + uint64_t max = parseInt(cardData["max_hp"].as()); + uint64_t maxlv = parseInt(cardData["max_lv"].as()); max_hp += ( (max - base) * (lv - 1) / (maxlv - 1) ) + base; max_hp /= 20.0f; } { - uint64_t base = parseInt(cardData["base_mp"].as()); - uint64_t max = parseInt(cardData["max_mp"].as()); - uint64_t maxlv = parseInt(cardData["max_lv"].as()); + uint64_t base = parseInt(cardData["base_mp"].as()); + uint64_t max = parseInt(cardData["max_mp"].as()); + uint64_t maxlv = parseInt(cardData["max_lv"].as()); max_mp += ( (max - base) * (lv - 1) / (maxlv - 1) ) + base; } */ { float scale = 3.0f; if ( str == 0 ) { - uint64_t base = parseInt(cardData["base_atk"].as()); - uint64_t max = parseInt(cardData["max_atk"].as()); - uint64_t maxlv = parseInt(cardData["max_lv"].as()); + uint64_t base = parseInt(cardData["base_atk"].as()); + uint64_t max = parseInt(cardData["max_atk"].as()); + uint64_t maxlv = parseInt(cardData["max_lv"].as()); str = ( (max - base) * (lv - 1) / (maxlv - 1) ) + base; str /= scale * 100.0f; } if ( mag == 0 ) { - uint64_t base = parseInt(cardData["base_atk"].as()); - uint64_t max = parseInt(cardData["max_atk"].as()); - uint64_t maxlv = parseInt(cardData["max_lv"].as()); + uint64_t base = parseInt(cardData["base_atk"].as()); + uint64_t max = parseInt(cardData["max_atk"].as()); + uint64_t maxlv = parseInt(cardData["max_lv"].as()); mag = ( (max - base) * (lv - 1) / (maxlv - 1) ) + base; mag /= scale * 100.0f; } if ( vit == 0 ) { - uint64_t base = parseInt(cardData["base_hp"].as()); - uint64_t max = parseInt(cardData["max_hp"].as()); - uint64_t maxlv = parseInt(cardData["max_lv"].as()); + uint64_t base = parseInt(cardData["base_hp"].as()); + uint64_t max = parseInt(cardData["max_hp"].as()); + uint64_t maxlv = parseInt(cardData["max_lv"].as()); vit = ( (max - base) * (lv - 1) / (maxlv - 1) ) + base; vit /= scale * 100.0f; } @@ -98,14 +98,14 @@ void ext::Housamo::initialize() { uint64_t max_hp = (lv + vit) * 6; uint64_t max_mp = (mag + lv) * 3; - if ( metadata[""]["max hp"].is() ) max_hp = parseInt(metadata[""]["max hp"].as()); - if ( metadata[""]["max mp"].is() ) max_mp = parseInt(metadata[""]["max mp"].as()); + if ( metadata[""]["max hp"].is() ) max_hp = parseInt(metadata[""]["max hp"].as()); + if ( metadata[""]["max mp"].is() ) max_mp = parseInt(metadata[""]["max mp"].as()); if ( hp == -1 ) hp = max_hp; if ( mp == -1 ) mp = max_mp; if ( limit == 0 ) { uint64_t baseL0 = 0; - switch ( parseInt(cardData["rarity"].as() ) ) { + switch ( parseInt(cardData["rarity"].as() ) ) { case 1: baseL0 = 20; break; case 2: baseL0 = 25; break; case 3: baseL0 = 30; break; @@ -122,7 +122,7 @@ void ext::Housamo::initialize() { for ( auto i = 0; i < cardData["skill_id"].size(); ++i ) { int learn = cardData["skill_learn_lv"][i].as(); if ( lv < learn ) break; - skills.push_back(cardData["skill_id"][i].as()); + skills.push_back(cardData["skill_id"][i].as()); } } diff --git a/ext/scenes/worldscape/terrain/behavior.cpp b/ext/scenes/worldscape/terrain/behavior.cpp index 315a1380..11a67274 100644 --- a/ext/scenes/worldscape/terrain/behavior.cpp +++ b/ext/scenes/worldscape/terrain/behavior.cpp @@ -31,8 +31,8 @@ void ext::TerrainBehavior::initialize( uf::Object& self ) { std::size_t seed = 0; if ( metadata["terrain"]["seed"].is() ) { seed = metadata["terrain"]["seed"].as(); - } else if ( metadata["terrain"]["seed"].is() ) { - seed = std::hash{}( metadata["terrain"]["seed"].as() ); + } else if ( metadata["terrain"]["seed"].is() ) { + seed = std::hash{}( metadata["terrain"]["seed"].as() ); } { std::cout << "Seed: " << seed << std::endl; @@ -45,11 +45,11 @@ void ext::TerrainBehavior::initialize( uf::Object& self ) { modifiers["region"]["size"] = metadata["region"]["size"]; modifiers["region"]["subdivisions"] = metadata["region"]["subdivisions"]; modifiers["region"]["modulus"] = metadata["region"]["modulus"]; - std::string input = modifiers; + uf::stl::string input = modifiers; metadata["system"]["hash"] = uf::string::sha256( input ); - uf::io::mkdir(uf::io::root+"/save/" + metadata["system"]["hash"].as() + "/"); - uf::io::mkdir(uf::io::root+"/save/" + metadata["system"]["hash"].as() + "/regions/"); + uf::io::mkdir(uf::io::root+"/save/" + metadata["system"]["hash"].as() + "/"); + uf::io::mkdir(uf::io::root+"/save/" + metadata["system"]["hash"].as() + "/regions/"); } // setup maze @@ -81,11 +81,11 @@ void ext::TerrainBehavior::initialize( uf::Object& self ) { }); this->addHook( "terrain:Post-Initialize.%UID%", [&](ext::json::Value& json){ if ( metadata["terrain"]["unified"].as() ) { - std::string textureFilename = ""; { + uf::stl::string textureFilename = ""; { uf::Asset assetLoader; for ( uint i = 0; i < metadata["system"]["assets"].size(); ++i ) { if ( textureFilename != "" ) break; - std::string filename = this->grabURI( metadata["system"]["assets"][i].as(), metadata["system"]["root"].as() ); + uf::stl::string filename = this->grabURI( metadata["system"]["assets"][i].as(), metadata["system"]["root"].as() ); textureFilename = assetLoader.cache( filename ); } } @@ -99,8 +99,8 @@ void ext::TerrainBehavior::initialize( uf::Object& self ) { texture.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; texture.loadFromFile( textureFilename ); - std::string suffix = ""; { - std::string _ = this->getRootParent().getComponent()["shaders"]["region"]["suffix"].as(); + uf::stl::string suffix = ""; { + uf::stl::string _ = this->getRootParent().getComponent()["shaders"]["region"]["suffix"].as(); if ( _ != "" ) suffix = _ + "."; } graphic.material.initializeShaders({ @@ -124,24 +124,24 @@ void ext::TerrainBehavior::tick( uf::Object& self ) { uf::Serializer& metadata = this->getComponent(); pod::Thread& mainThread = uf::thread::has("Main") ? uf::thread::get("Main") : uf::thread::create( "Main", false, true ); // lambda to transition from a resolving state - auto transitionState = [&]( ext::Terrain& that, const std::string& next, bool unresolved ){ + auto transitionState = [&]( ext::Terrain& that, const uf::stl::string& next, bool unresolved ){ uf::Serializer& metadata = that.getComponent(); // uf::thread::add( mainThread, [&]() -> int { - // std::cout << "Transitioning: " << metadata["system"]["state"].as() << " -> "; + // std::cout << "Transitioning: " << metadata["system"]["state"].as() << " -> "; metadata["system"]["state"] = unresolved ? next : "open"; metadata["system"]["modified"] = unresolved; - // std::cout << metadata["system"]["state"].as() << std::endl; + // std::cout << metadata["system"]["state"].as() << std::endl; // return 0;}, true ); }; // lambda to transition into a resolving state auto transitionResolvingState = [&]( ext::Terrain& that ){ uf::Serializer& metadata = that.getComponent(); - // std::cout << "Resolving: " << metadata["system"]["state"].as() << " -> "; - metadata["system"]["state"] = "resolving:" + metadata["system"]["state"].as(); - // std::cout << metadata["system"]["state"].as() << std::endl; + // std::cout << "Resolving: " << metadata["system"]["state"].as() << " -> "; + metadata["system"]["state"] = "resolving:" + metadata["system"]["state"].as(); + // std::cout << metadata["system"]["state"].as() << std::endl; }; // lambda for sorting regions, nearest to farthest, from the controller - auto sortRegions = [&]( uf::Object& controller, std::vector& regions ){ + auto sortRegions = [&]( uf::Object& controller, uf::stl::vector& regions ){ const pod::Vector3& position = controller.getComponent>().position; std::sort( regions.begin(), regions.end(), [&]( const uf::Object* l, const uf::Object* r ){ if ( !l ) return false; if ( !r ) return true; @@ -173,7 +173,7 @@ void ext::TerrainBehavior::tick( uf::Object& self ) { } // remove regions too far { - std::vector locations; + uf::stl::vector locations; for ( uf::Entity* region : this->getChildren() ) { if ( !region || region->getName() != "Region" ) continue; const pod::Transform<>& transform = region->getComponent>(); pod::Vector3i location = { @@ -207,7 +207,7 @@ void ext::TerrainBehavior::tick( uf::Object& self ) { // initialize new regions if ( metadata["system"]["state"] == "initialize" ) { transitionResolvingState(*this); uf::thread::add( uf::thread::fetchWorker(), [&]() -> int { - std::vector regions; + uf::stl::vector regions; // retrieve changed regions for ( uf::Entity* region : this->getChildren() ) { if ( !region ) continue; uf::Serializer& metadata = region->getComponent(); diff --git a/ext/scenes/worldscape/terrain/generator.cpp b/ext/scenes/worldscape/terrain/generator.cpp index 016e79a4..ae44838c 100644 --- a/ext/scenes/worldscape/terrain/generator.cpp +++ b/ext/scenes/worldscape/terrain/generator.cpp @@ -95,15 +95,15 @@ void ext::TerrainGenerator::generate( uf::Object& region ){ ambientLight.b *= tMetadata["region"]["light"]["ambient"][2].as(); } */ - std::string base = region.getParent().getComponent()["system"]["hash"].as(); - std::string filename = uf::io::root+"/save/" + base + "/regions/" + std::to_string(location.x) + "." + std::to_string(location.y) + "." + std::to_string(location.z) + ".json"; + uf::stl::string base = region.getParent().getComponent()["system"]["hash"].as(); + uf::stl::string filename = uf::io::root+"/save/" + base + "/regions/" + std::to_string(location.x) + "." + std::to_string(location.y) + "." + std::to_string(location.z) + ".json"; // old region, load save if ( uf::io::exists( filename ) ) { uf::Serializer save; save.readFromFile(filename); // ID - if ( save["voxels"]["id"]["base64"].is() ) { - std::string base64 = save["voxels"]["id"]["base64"].as(); + if ( save["voxels"]["id"]["base64"].is() ) { + uf::stl::string base64 = save["voxels"]["id"]["base64"].as(); auto raw = uf::base64::decode( base64 ); if ( save["voxels"]["id"]["rle"].as() ) { @@ -118,8 +118,8 @@ void ext::TerrainGenerator::generate( uf::Object& region ){ this->unwrapVoxel(); } // Lighting - if ( save["voxels"]["lighting"]["base64"].is() ) { - std::string base64 = save["voxels"]["lighting"]["base64"].as(); + if ( save["voxels"]["lighting"]["base64"].is() ) { + uf::stl::string base64 = save["voxels"]["lighting"]["base64"].as(); auto raw = uf::base64::decode( base64 ); if ( save["voxels"]["lighting"]["rle"].as() ) { @@ -330,13 +330,13 @@ void ext::TerrainGenerator::writeToFile() { this->wrapLight(); uf::Serializer serializer; - std::string base = this->m_terrain ? this->m_terrain->getComponent()["system"]["hash"].as() : "UNKNOWN"; - std::string filename = uf::io::root+"/save/" + base + "/regions/" + std::to_string(this->m_location.x) + "." + std::to_string(this->m_location.y) + "." + std::to_string(this->m_location.z) + ".json"; + uf::stl::string base = this->m_terrain ? this->m_terrain->getComponent()["system"]["hash"].as() : "UNKNOWN"; + uf::stl::string filename = uf::io::root+"/save/" + base + "/regions/" + std::to_string(this->m_location.x) + "." + std::to_string(this->m_location.y) + "." + std::to_string(this->m_location.z) + ".json"; { // encode as base64, json safe serializer["voxels"]["id"]["base64"] = uf::base64::encode( this->m_voxels.id.rle ); // hash of raw data for data integrity - serializer["voxels"]["id"]["hash"] = uf::string::sha256( uf::base64::decode(serializer["voxels"]["id"]["rle"]["base64"].as()) ); + serializer["voxels"]["id"]["hash"] = uf::string::sha256( uf::base64::decode(serializer["voxels"]["id"]["rle"]["base64"].as()) ); serializer["voxels"]["id"]["rle"] = true; serializer["voxels"]["id"]["swizzle"] = this->m_voxels.id.swizzle; } @@ -344,7 +344,7 @@ void ext::TerrainGenerator::writeToFile() { // encode as base64, json safe serializer["voxels"]["lighting"]["base64"] = uf::base64::encode( this->m_voxels.lighting.rle ); // hash of raw data for data integrity - serializer["voxels"]["lighting"]["hash"] = uf::string::sha256( uf::base64::decode(serializer["voxels"]["lighting"]["rle"]["base64"].as()) ); + serializer["voxels"]["lighting"]["hash"] = uf::string::sha256( uf::base64::decode(serializer["voxels"]["lighting"]["rle"]["base64"].as()) ); serializer["voxels"]["lighting"]["rle"] = true; serializer["voxels"]["lighting"]["swizzle"] = this->m_voxels.lighting.swizzle; } @@ -354,7 +354,7 @@ void ext::TerrainGenerator::writeToFile() { this->destroy(); } -std::vector ext::TerrainGenerator::getRawVoxels() { +uf::stl::vector ext::TerrainGenerator::getRawVoxels() { return this->m_voxels.id.raw; } const pod::RLE::string_t& ext::TerrainGenerator::getVoxels() const { @@ -641,7 +641,7 @@ void ext::TerrainGenerator::wrapVoxel() { if ( this->m_voxels.id.raw.empty() ) r raw_id[position.x][position.y][position.z] = this->m_voxels.id.raw[i]; } - std::vector buffer; + uf::stl::vector buffer; buffer.reserve( this->m_size.x * this->m_size.y * this->m_size.z ); // use YZX @@ -708,7 +708,7 @@ void ext::TerrainGenerator::wrapLight() { if ( this->m_voxels.lighting.raw.empty raw_lighting[position.x][position.y][position.z] = this->m_voxels.lighting.raw[i]; } - std::vector buffer; + uf::stl::vector buffer; buffer.reserve( this->m_size.x * this->m_size.y * this->m_size.z ); // use YZX @@ -1006,7 +1006,7 @@ void ext::TerrainGenerator::light( int x, int y, int z, const ext::TerrainVoxel: light.g = (self.getLight( node.position ) >> 8) & 0xF; light.b = (self.getLight( node.position ) >> 4) & 0xF; - std::vector positions = { + uf::stl::vector positions = { node.position + pod::Vector3i{-1, 0, 0 }, node.position + pod::Vector3i{ 1, 0, 0 }, node.position + pod::Vector3i{ 0,-1, 0 }, @@ -1098,7 +1098,7 @@ void ext::TerrainGenerator::light( int x, int y, int z, const ext::TerrainVoxel: light.g = (this->getLight( node ) >> 8) & 0xF; light.b = (this->getLight( node ) >> 4) & 0xF; - std::vector positions = { + uf::stl::vector positions = { this->wrapPosition(node + pod::Vector3i{-1, 0, 0 }), this->wrapPosition(node + pod::Vector3i{ 1, 0, 0 }), this->wrapPosition(node + pod::Vector3i{ 0,-1, 0 }), @@ -1150,7 +1150,7 @@ void ext::TerrainGenerator::light( int x, int y, int z, const ext::TerrainVoxel: ext::TerrainVoxel voxel = ext::TerrainVoxel::atlas( this->getVoxel( node ) ); ext::TerrainVoxel::light_t light = (this->getLight( node ) >> 12) & 0xF; - std::vector positions = { + uf::stl::vector positions = { node + pod::Vector3i{-1, 0, 0 }, node + pod::Vector3i{ 1, 0, 0 }, node + pod::Vector3i{ 0,-1, 0 }, @@ -1188,7 +1188,7 @@ void ext::TerrainGenerator::light( int x, int y, int z, const ext::TerrainVoxel: ext::TerrainVoxel voxel = ext::TerrainVoxel::atlas( this->getVoxel( node ) ); ext::TerrainVoxel::light_t light = (this->getLight( node ) >> 8) & 0xF; - std::vector positions = { + uf::stl::vector positions = { node + pod::Vector3i{-1, 0, 0 }, node + pod::Vector3i{ 1, 0, 0 }, node + pod::Vector3i{ 0,-1, 0 }, @@ -1226,7 +1226,7 @@ void ext::TerrainGenerator::light( int x, int y, int z, const ext::TerrainVoxel: ext::TerrainVoxel voxel = ext::TerrainVoxel::atlas( this->getVoxel( node ) ); ext::TerrainVoxel::light_t light = (this->getLight( node ) >> 4) & 0xF; - std::vector positions = { + uf::stl::vector positions = { node + pod::Vector3i{-1, 0, 0 }, node + pod::Vector3i{ 1, 0, 0 }, node + pod::Vector3i{ 0,-1, 0 }, @@ -1288,7 +1288,7 @@ void ext::TerrainGenerator::updateLight(){ // this->wrapLight(); // this->writeToFile(); } -void ext::TerrainGenerator::rasterize( std::vector& vertices, const uf::Object& region, bool applyTransform ){ +void ext::TerrainGenerator::rasterize( uf::stl::vector& vertices, const uf::Object& region, bool applyTransform ){ if ( this->m_voxels.id.rle.empty() ) return; this->writeToFile(); diff --git a/ext/scenes/worldscape/terrain/generator.h b/ext/scenes/worldscape/terrain/generator.h index 9f427dc4..25490ae7 100644 --- a/ext/scenes/worldscape/terrain/generator.h +++ b/ext/scenes/worldscape/terrain/generator.h @@ -23,12 +23,12 @@ namespace ext { }; struct { struct { - std::vector raw; + uf::stl::vector raw; pod::RLE::string_t rle; Swizzle swizzle = Swizzle::YZX; } id; struct { - std::vector raw; + uf::stl::vector raw; pod::RLE::string_t rle; Swizzle swizzle = Swizzle::YZX; } lighting; @@ -54,10 +54,10 @@ namespace ext { void updateLight(); void generate( uf::Object& ); - void rasterize( std::vector& vertices, const uf::Object&, bool = false ); - // void vectorize( std::vector&, const uf::Object& ); + void rasterize( uf::stl::vector& vertices, const uf::Object&, bool = false ); + // void vectorize( uf::stl::vector&, const uf::Object& ); - std::vector getRawVoxels(); + uf::stl::vector getRawVoxels(); const pod::RLE::string_t& getVoxels() const; pod::Vector3i unwrapIndex( int64_t, Swizzle = DEFAULT_SWIZZLE ) const; diff --git a/ext/scenes/worldscape/terrain/maze.cpp b/ext/scenes/worldscape/terrain/maze.cpp index c2a02988..4ca9a072 100644 --- a/ext/scenes/worldscape/terrain/maze.cpp +++ b/ext/scenes/worldscape/terrain/maze.cpp @@ -3,7 +3,7 @@ #include "Maze.h" #include -#include +#include #include #include #include @@ -115,7 +115,7 @@ void ext::Maze::build(){ // The room sets - std::map> room_set; + std::map> room_set; // The mapping of connected rooms std::map merged_room_sets; @@ -176,7 +176,7 @@ void ext::Maze::build(){ // EASTERN WALL REMOVED // Get set of eastern room - std::vector next_room_position_set = room_set[get(row, col+1, floor)]; + uf::stl::vector next_room_position_set = room_set[get(row, col+1, floor)]; // Add set of eastern room to this set. room_set[room_value].insert(room_set[room_value].end(), next_room_position_set.begin(), next_room_position_set.end() ); @@ -377,10 +377,10 @@ void ext::Maze::print(){ */ // Maze map canvas - std::string map_drawing[2 * WIDTH + 1][HEIGHT]; + uf::stl::string map_drawing[2 * WIDTH + 1][HEIGHT]; - std::string wall_row = "+"; - std::string room_row = "|"; + uf::stl::string wall_row = "+"; + uf::stl::string room_row = "|"; // Make a row of walls and rooms for (int col = 0; col < LENGTH; col++){ diff --git a/ext/scenes/worldscape/terrain/maze.h b/ext/scenes/worldscape/terrain/maze.h index e112d066..66b23111 100644 --- a/ext/scenes/worldscape/terrain/maze.h +++ b/ext/scenes/worldscape/terrain/maze.h @@ -7,7 +7,7 @@ namespace ext { protected: double EAST_WALL_THRESHOLD; double SOUTH_WALL_THRESHOLD; - std::vector< std::tuple > passages; + uf::stl::vector< std::tuple > passages; typedef std::tuple pos; int get(int, int, int); @@ -26,7 +26,7 @@ namespace ext { static const uint8_t SOUTH = 16; // 00 01 00 00; static const uint8_t CEIL = 32; // 00 10 00 00; - std::vector cells; + uf::stl::vector cells; int& operator()(int row, int col, int floor){ return cells.at(col + LENGTH*row + LENGTH*WIDTH*floor); diff --git a/ext/scenes/worldscape/terrain/region.cpp b/ext/scenes/worldscape/terrain/region.cpp index b22f3096..9d7f3b88 100644 --- a/ext/scenes/worldscape/terrain/region.cpp +++ b/ext/scenes/worldscape/terrain/region.cpp @@ -28,12 +28,12 @@ void ext::RegionBehavior::initialize( uf::Object& self ) { metadata["region"]["initialized"] = true; if ( !metadata["terrain"]["unified"].as() ) { - std::string textureFilename = ""; { + uf::stl::string textureFilename = ""; { uf::Serializer& metadata = this->getParent().getComponent(); uf::Asset assetLoader; for ( uint i = 0; i < metadata["system"]["assets"].size(); ++i ) { if ( textureFilename != "" ) break; - std::string filename = this->grabURI( metadata["system"]["assets"][i].as(), metadata["system"]["root"].as() ); + uf::stl::string filename = this->grabURI( metadata["system"]["assets"][i].as(), metadata["system"]["root"].as() ); textureFilename = assetLoader.cache( filename ); } } @@ -48,8 +48,8 @@ void ext::RegionBehavior::initialize( uf::Object& self ) { texture.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST; texture.loadFromFile( textureFilename ); - std::string suffix = ""; { - std::string _ = this->getRootParent().getComponent()["shaders"]["region"]["suffix"].as(); + uf::stl::string suffix = ""; { + uf::stl::string _ = this->getRootParent().getComponent()["shaders"]["region"]["suffix"].as(); if ( _ != "" ) suffix = _ + "."; } @@ -303,7 +303,7 @@ void ext::RegionBehavior::tick( uf::Object& self ) { } auto function = [&]() -> int { - std::vector entities; + uf::stl::vector entities; // update physics if ( updatePhysics ) { std::function filter = [&]( uf::Entity* entity ) { @@ -371,7 +371,7 @@ void ext::RegionBehavior::tick( uf::Object& self ) { voxelPosition.y += size.y / 2.0f + 1; voxelPosition.z += size.z / 2.0f; - std::vector positions = { + uf::stl::vector positions = { { voxelPosition.x, voxelPosition.y, voxelPosition.z }, { voxelPosition.x - 1, voxelPosition.y, voxelPosition.z }, { voxelPosition.x + 1, voxelPosition.y, voxelPosition.z }, @@ -463,7 +463,7 @@ void ext::RegionBehavior::tick( uf::Object& self ) { bool useWorkers = sMetadata["system"]["physics"]["use"]["worker"].as(); pod::Thread& thread = uf::thread::has("Physics") ? uf::thread::get("Physics") : uf::thread::create( "Physics", true, false ); auto function = [&]() -> int { - std::vector entities; + uf::stl::vector entities; std::function filter = [&]( uf::Entity* entity ) { auto& metadata = entity->getComponent(); if ( !ext::json::isNull( metadata["system"]["physics"]["collision"] ) && !metadata["system"]["physics"]["collision"].as() ) return; @@ -516,7 +516,7 @@ void ext::RegionBehavior::tick( uf::Object& self ) { voxelPosition.z += size.z / 2.0f; uf::Collider collider; - std::vector positions = { + uf::stl::vector positions = { { voxelPosition.x, voxelPosition.y, voxelPosition.z }, { voxelPosition.x - 1, voxelPosition.y, voxelPosition.z }, { voxelPosition.x + 1, voxelPosition.y, voxelPosition.z }, @@ -567,14 +567,14 @@ void ext::RegionBehavior::tick( uf::Object& self ) { uf::Object* a = NULL; uf::Object* b = NULL; }; - std::unordered_map queued; + uf::stl::unordered_map queued; for ( auto* _a : entities ) { uf::Object& entityA = *_a; if ( ignoreStaticEntities && !entityA.hasComponent() ) continue; for ( auto* _b : entities ) { if ( _a == _b ) continue; uf::Object& entityB = *_b; - std::string hash = std::to_string(std::min( entityA.getUid(), entityB.getUid() )) + ":" + std::to_string(std::max( entityA.getUid(), entityB.getUid() )); + uf::stl::string hash = std::to_string(std::min( entityA.getUid(), entityB.getUid() )) + ":" + std::to_string(std::max( entityA.getUid(), entityB.getUid() )); if ( queued.count(hash) > 0 ) continue; queued[hash] = { .a = _a, diff --git a/ext/scenes/worldscape/terrain/terrain.cpp b/ext/scenes/worldscape/terrain/terrain.cpp index fe27d085..02127f69 100644 --- a/ext/scenes/worldscape/terrain/terrain.cpp +++ b/ext/scenes/worldscape/terrain/terrain.cpp @@ -21,7 +21,7 @@ #include namespace { - std::unordered_map region_table; + uf::stl::unordered_map region_table; } UF_OBJECT_REGISTER_BEGIN(ext::Terrain) @@ -31,7 +31,7 @@ UF_OBJECT_REGISTER_BEGIN(ext::Terrain) UF_OBJECT_REGISTER_END() void ext::Terrain::relocateChildren() { uf::Scene& scene = uf::scene::getCurrentScene(); - std::vector entities; + uf::stl::vector entities; scene.process( [&]( uf::Entity* entity ) { if ( !entity || entity->getUid() == 0 ) return; uf::Serializer& metadata = entity->getComponent(); diff --git a/ext/scenes/worldscape/terrain/voxel.cpp b/ext/scenes/worldscape/terrain/voxel.cpp index e98649bb..04d9e01d 100644 --- a/ext/scenes/worldscape/terrain/voxel.cpp +++ b/ext/scenes/worldscape/terrain/voxel.cpp @@ -480,8 +480,8 @@ ext::TerrainVoxelStair::TerrainVoxelStair() : ext::TerrainVoxel( 5, true, true, ext::TerrainVoxelLava::TerrainVoxelLava() : ext::TerrainVoxel( 6, true, true, {0, 2}, 0xFFFF ) {} // -const std::vector& ext::TerrainVoxel::atlas() { - static std::vector atlas; +const uf::stl::vector& ext::TerrainVoxel::atlas() { + static uf::stl::vector atlas; if ( atlas.size() == 0 ) { atlas.push_back( ext::TerrainVoxel() ); atlas.push_back( ext::TerrainVoxelFloor() ); @@ -494,9 +494,9 @@ const std::vector& ext::TerrainVoxel::atlas() { return atlas; } ext::TerrainVoxel ext::TerrainVoxel::atlas( ext::TerrainVoxel::uid_t uid ) { - std::vector atlas = ext::TerrainVoxel::atlas(); + uf::stl::vector atlas = ext::TerrainVoxel::atlas(); static ext::TerrainVoxel base; - for ( std::vector::iterator it = atlas.begin(); it != atlas.end(); ++it ) { + for ( uf::stl::vector::iterator it = atlas.begin(); it != atlas.end(); ++it ) { if ( it->uid() == uid ) return *it; } return base; diff --git a/ext/scenes/worldscape/terrain/voxel.h b/ext/scenes/worldscape/terrain/voxel.h index c86ecebb..4dd1695b 100644 --- a/ext/scenes/worldscape/terrain/voxel.h +++ b/ext/scenes/worldscape/terrain/voxel.h @@ -21,10 +21,10 @@ namespace ext { ext::TerrainVoxel::light_t m_light = 0x0000; public: struct Model { - struct { std::vector left, right, top, bottom, front, back; } position; - struct { std::vector left, right, top, bottom, front, back; } uv; - struct { std::vector left, right, top, bottom, front, back; } normal; - struct { std::vector left, right, top, bottom, front, back; } color; + struct { uf::stl::vector left, right, top, bottom, front, back; } position; + struct { uf::stl::vector left, right, top, bottom, front, back; } uv; + struct { uf::stl::vector left, right, top, bottom, front, back; } normal; + struct { uf::stl::vector left, right, top, bottom, front, back; } color; }; TerrainVoxel( ext::TerrainVoxel::uid_t = 0, bool = false, bool = false, pod::Vector2ui = {0, 0}, ext::TerrainVoxel::light_t = 0x0000 ); @@ -32,7 +32,7 @@ namespace ext { virtual ~TerrainVoxel(); static pod::Vector2ui size(); - static const std::vector& atlas(); + static const uf::stl::vector& atlas(); static ext::TerrainVoxel atlas( ext::TerrainVoxel::uid_t ); virtual bool opaque() const; diff --git a/makefiles/win64.clang.make b/makefiles/win64.clang.make index ea31acc3..e478b5f9 100644 --- a/makefiles/win64.clang.make +++ b/makefiles/win64.clang.make @@ -1,4 +1,4 @@ ARCH = win64 PREFIX = clang CC = clang++ -FLAGS += -Wno-unknown-pragmas -std=c++17 -g -Wall -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder-ctor -Wno-ignored-attributes -Wno-c++11-narrowing -fcolor-diagnostics \ No newline at end of file +FLAGS += -Wno-unknown-pragmas -std=c++17 -O3 -Wall -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder-ctor -Wno-ignored-attributes -Wno-c++11-narrowing -fcolor-diagnostics -fansi-escape-codes \ No newline at end of file