Compare commits

..

3 Commits

38 changed files with 272 additions and 161 deletions

4
.gitignore vendored
View File

@ -45,6 +45,9 @@
*.cdi *.cdi
*.gdi *.gdi
# Other stuff that's a pain when doing cross-arch stuff
default/
# Assets # Assets
*.gz *.gz
*.png *.png
@ -55,6 +58,7 @@
*.ttf *.ttf
*.otf *.otf
*.bin *.bin
models/ models/
llm/ llm/
tmp/ tmp/

View File

@ -54,8 +54,8 @@ endif
INC_DIR += $(ENGINE_INC_DIR) INC_DIR += $(ENGINE_INC_DIR)
LIB_DIR += $(ENGINE_LIB_DIR) LIB_DIR += $(ENGINE_LIB_DIR)
INCS += -I$(ENGINE_INC_DIR) -I./dep/include/ #-I/mingw64/include/ INCS += -I$(ENGINE_INC_DIR) -I./dep/include/
LIBS += -L$(ENGINE_LIB_DIR) -L$(LIB_DIR)/$(PREFIX_PATH) -L$(LIB_DIR)/$(ARCH)/$(CC) -L$(LIB_DIR)/$(ARCH) #-L/mingw64/lib/ LIBS += -L$(ENGINE_LIB_DIR) -L$(LIB_DIR)/$(PREFIX_PATH)/ -L$(LIB_DIR)/$(ARCH)/$(CC)/ -L$(LIB_DIR)/$(ARCH)/
LINKS += $(UF_LIBS) $(EXT_LIBS) $(DEPS) LINKS += $(UF_LIBS) $(EXT_LIBS) $(DEPS)
DEPS += DEPS +=
@ -63,7 +63,7 @@ FLAGS += -DUF_DEV_ENV
ifneq (,$(findstring win64,$(ARCH))) ifneq (,$(findstring win64,$(ARCH)))
ifneq (,$(findstring -DUF_DEV_ENV,$(FLAGS))) ifneq (,$(findstring -DUF_DEV_ENV,$(FLAGS)))
REQ_DEPS += meshoptimizer toml xatlas curl ffx:fsr cpptrace vall_e dc:texconv # ncurses openvr draco discord bullet ultralight-ux REQ_DEPS += meshoptimizer toml xatlas curl ffx:fsr dc:texconv # vall_e cpptrace # openvr # ncurses draco discord bullet ultralight-ux
FLAGS += -march=native -g # -flto # -g FLAGS += -march=native -g # -flto # -g
endif endif
REQ_DEPS += $(RENDERER) json:nlohmann zlib luajit reactphysics simd ctti gltf imgui fmt freetype openal ogg wav REQ_DEPS += $(RENDERER) json:nlohmann zlib luajit reactphysics simd ctti gltf imgui fmt freetype openal ogg wav
@ -118,7 +118,11 @@ ifneq (,$(findstring opengl,$(REQ_DEPS)))
# OpenGL through GLEW # OpenGL through GLEW
else else
FLAGS += -DUF_USE_GLEW FLAGS += -DUF_USE_GLEW
DEPS += -lglew32 -lopengl32 -lglu32 ifneq (,$(findstring linux,$(ARCH)))
DEPS += -lGLU -lglut -lGLEW
else
DEPS += -lglew32 -lopengl32 -lglu32
endif
endif endif
endif endif
@ -376,7 +380,7 @@ $(EX_DLL): $(OBJS_DLL)
@echo "Setting defaults: $(ARCH).$(CC).$(RENDERER)" @echo "Setting defaults: $(ARCH).$(CC).$(RENDERER)"
$(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS $(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS
$(EXT_EX_DLL): $(OBJS_EXT_DLL) $(EXT_EX_DLL): $(OBJS_EXT_DLL)
$(CXX) -shared -Wl,-soname,$(BASE_EXT_DLL).$(LIB_EXTENSION) $(OBJS_EXT_DLL) $(EXT_LIBS) $(EXT_INCS) $(EXT_LINKS) -o $(EXT_EX_DLL) $(CXX) $(FLAGS) -shared -Wl,-soname,$(BASE_EXT_DLL).$(LIB_EXTENSION) $(OBJS_EXT_DLL) $(EXT_LIBS) $(EXT_INCS) $(EXT_LINKS) -o $(EXT_EX_DLL)
cp $(EXT_EX_DLL) $(EXT_IM_DLL) cp $(EXT_EX_DLL) $(EXT_IM_DLL)
else else
@ -394,7 +398,7 @@ $(EX_DLL): $(OBJS_DLL)
$(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS $(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS
$(EXT_EX_DLL): $(OBJS_EXT_DLL) $(EXT_EX_DLL): $(OBJS_EXT_DLL)
$(CXX) -shared -o $(EXT_EX_DLL) -Wl,--out-implib=$(EXT_IM_DLL) $(OBJS_EXT_DLL) $(EXT_LIBS) $(EXT_INCS) $(EXT_LINKS) $(CXX) $(FLAGS) -shared -o $(EXT_EX_DLL) -Wl,--out-implib=$(EXT_IM_DLL) $(OBJS_EXT_DLL) $(EXT_LIBS) $(EXT_INCS) $(EXT_LINKS)
cp $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_EXT_DLL).$(LIB_EXTENSION).a $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_EXT_DLL).a cp $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_EXT_DLL).$(LIB_EXTENSION).a $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_EXT_DLL).a
endif endif

View File

@ -33,7 +33,7 @@ void client::initialize() {
client::config["window"]["size"][1] = (size.y = resolution.y); client::config["window"]["size"][1] = (size.y = resolution.y);
} }
// Window title // Window title
uf::String title; { uf::stl::string title; {
title = client::config["window"]["title"].as<std::string>(); title = client::config["window"]["title"].as<std::string>();
} }
// Terminal window; // Terminal window;
@ -93,7 +93,7 @@ void client::initialize() {
uf::hooks.addHook( "window:Title.Changed", [&]( ext::json::Value& json ){ uf::hooks.addHook( "window:Title.Changed", [&]( ext::json::Value& json ){
if ( json["invoker"] != "os" ) { if ( json["invoker"] != "os" ) {
if ( !ext::json::isObject( json["window"] ) ) return; if ( !ext::json::isObject( json["window"] ) ) return;
uf::String title = json["window"]["title"].as<std::string>(); uf::stl::string title = json["window"]["title"].as<std::string>();
client::window.setTitle(title); client::window.setTitle(title);
} }
} ); } );

View File

@ -38,7 +38,7 @@ namespace ext {
UF_API void setRenderMode( ext::freetype::Glyph&, decltype(FT_RENDER_MODE_NORMAL) = FT_RENDER_MODE_NORMAL ); UF_API void setRenderMode( ext::freetype::Glyph&, decltype(FT_RENDER_MODE_NORMAL) = FT_RENDER_MODE_NORMAL );
UF_API bool load( ext::freetype::Glyph&, unsigned long ); UF_API bool load( ext::freetype::Glyph&, unsigned long );
UF_API bool load( ext::freetype::Glyph&, const uf::String& ); UF_API bool load( ext::freetype::Glyph&, const uf::stl::string& );
UF_API uf::stl::string getError( int ); UF_API uf::stl::string getError( int );
} }

View File

@ -81,11 +81,13 @@ namespace ext {
size_t initializeBuffer( const void*, GLsizeiptr, GLenum, bool = false ); size_t initializeBuffer( const void*, GLsizeiptr, GLenum, bool = false );
bool updateBuffer( const void*, GLsizeiptr, const Buffer&, bool = false ) const; bool updateBuffer( const void*, GLsizeiptr, const Buffer&, bool = false ) const;
/*
inline size_t initializeBuffer( void* data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) data, length, usage, alias ); } inline size_t initializeBuffer( void* data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) data, length, usage, alias ); }
template<typename T> inline size_t initializeBuffer( const T& data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, length, usage, alias ); } template<typename T> inline size_t initializeBuffer( const T& data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, length, usage, alias ); }
template<typename T> inline size_t initializeBuffer( const T& data, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, static_cast<GLsizeiptr>(sizeof(T)), usage, alias ); } template<typename T> inline size_t initializeBuffer( const T& data, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, static_cast<GLsizeiptr>(sizeof(T)), usage, alias ); }
inline bool updateBuffer( const void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( data, length, buffers.at(index), alias ); } inline bool updateBuffer( const void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( data, length, buffers.at(index), alias ); }
*/
/* /*
inline bool updateBuffer( const void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( data, length, buffers.at(index), alias ); } inline bool updateBuffer( const void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( data, length, buffers.at(index), alias ); }
inline bool updateBuffer( void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( (const void*) data, length, index, alias ); } inline bool updateBuffer( void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( (const void*) data, length, index, alias ); }

View File

@ -4,13 +4,6 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <vk_mem_alloc.h> #include <vk_mem_alloc.h>
#if UF_ENV_LINUX
#ifdef Success
#undef Success
#undef None
#endif
#endif
#include <typeinfo> #include <typeinfo>
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>

View File

@ -8,6 +8,9 @@ namespace spec {
typedef spec::unknown::Context Context; typedef spec::unknown::Context Context;
} }
#else #else
#include <GL/glx.h>
namespace spec { namespace spec {
namespace x11 { namespace x11 {
class UF_API_VAR Context : public spec::uni::Context { class UF_API_VAR Context : public spec::uni::Context {

View File

@ -8,3 +8,4 @@
// defines which implementation to use // defines which implementation to use
// #include UF_ENV_HEADER // #include UF_ENV_HEADER
// //

View File

@ -11,9 +11,17 @@
#if UF_USE_VULKAN #if UF_USE_VULKAN
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <vulkan/vulkan_xlib.h> // #include <vulkan/vulkan_xlib.h>
#elif UF_USE_OPENGL #elif UF_USE_OPENGL
#include <GL/glx.h> // #include <GL/glx.h>
#endif
// these macros interfere with other things
#ifdef Success
#undef Success
#endif
#ifdef None
#undef None
#endif #endif
namespace spec { namespace spec {
@ -47,6 +55,7 @@ namespace spec {
void UF_API_CALL create(const vector_t& size, const title_t& title = L"Window"); void UF_API_CALL create(const vector_t& size, const title_t& title = L"Window");
void UF_API_CALL terminate(); void UF_API_CALL terminate();
Display* UF_API_CALL getDisplay() const;
handle_t UF_API_CALL getHandle() const; handle_t UF_API_CALL getHandle() const;
vector_t UF_API_CALL getPosition() const; vector_t UF_API_CALL getPosition() const;
vector_t UF_API_CALL getSize() const; vector_t UF_API_CALL getSize() const;
@ -91,4 +100,5 @@ namespace spec {
namespace uf { namespace uf {
using Window = spec::x11::Window; using Window = spec::x11::Window;
} }
#endif #endif

View File

@ -14,7 +14,7 @@ namespace spec {
public: public:
typedef void* handle_t; typedef void* handle_t;
typedef void* context_t; typedef void* context_t;
typedef uf::String title_t; typedef uf::stl::string title_t;
typedef pod::Vector2i vector_t; typedef pod::Vector2i vector_t;
struct Event { struct Event {

View File

@ -39,8 +39,8 @@ namespace spec {
// C-tors // C-tors
UF_API_CALL Window(); UF_API_CALL Window();
UF_API_CALL Window( spec::win32::Window::handle_t ); UF_API_CALL Window( spec::win32::Window::handle_t );
UF_API_CALL Window( const spec::win32::Window::vector_t& size, const spec::win32::Window::title_t& title = L"Window" ); UF_API_CALL Window( const spec::win32::Window::vector_t& size, const spec::win32::Window::title_t& title = "Window" );
/*virtual*/ void UF_API_CALL create( const spec::win32::Window::vector_t& size, const spec::win32::Window::title_t& title = L"Window" ); /*virtual*/ void UF_API_CALL create( const spec::win32::Window::vector_t& size, const spec::win32::Window::title_t& title = "Window" );
// D-tors // D-tors
/*virtual*/ ~Window(); /*virtual*/ ~Window();
void UF_API_CALL terminate(); void UF_API_CALL terminate();

View File

@ -64,7 +64,9 @@ namespace uf {
char UF_API_CALL readChar(const bool& = true); char UF_API_CALL readChar(const bool& = true);
uf::stl::string UF_API_CALL readString(const bool& = true); uf::stl::string UF_API_CALL readString(const bool& = true);
#if UF_USE_DEPRECATED_STRING
uf::String UF_API_CALL readUString(const bool& = true); uf::String UF_API_CALL readUString(const bool& = true);
#endif
void UF_API_CALL operator>> (bool&); void UF_API_CALL operator>> (bool&);
void UF_API_CALL operator>> (short&); void UF_API_CALL operator>> (short&);
void UF_API_CALL operator>> (unsigned short&); void UF_API_CALL operator>> (unsigned short&);
@ -79,13 +81,17 @@ namespace uf {
void UF_API_CALL operator>> (double&); void UF_API_CALL operator>> (double&);
void UF_API_CALL operator>> (long double&); void UF_API_CALL operator>> (long double&);
void UF_API_CALL operator>> (uf::stl::string&); void UF_API_CALL operator>> (uf::stl::string&);
#if UF_USE_DEPRECATED_STRING
void UF_API_CALL operator>> (uf::String&); void UF_API_CALL operator>> (uf::String&);
#endif
std::istream& UF_API_CALL operator>> ( std::istream& ); std::istream& UF_API_CALL operator>> ( std::istream& );
friend std::istream& UF_API_CALL operator>> ( std::istream&, uf::IoStream& ); friend std::istream& UF_API_CALL operator>> ( std::istream&, uf::IoStream& );
char UF_API_CALL writeChar(char); char UF_API_CALL writeChar(char);
const uf::stl::string& UF_API_CALL writeString(const uf::stl::string&); const uf::stl::string& UF_API_CALL writeString(const uf::stl::string&);
#if UF_USE_DEPRECATED_STRING
const uf::String& UF_API_CALL writeUString(const uf::String&); const uf::String& UF_API_CALL writeUString(const uf::String&);
#endif
uf::IoStream& UF_API_CALL operator<< (const bool&); uf::IoStream& UF_API_CALL operator<< (const bool&);
uf::IoStream& UF_API_CALL operator<< (const short&); uf::IoStream& UF_API_CALL operator<< (const short&);
uf::IoStream& UF_API_CALL operator<< (const unsigned short&); uf::IoStream& UF_API_CALL operator<< (const unsigned short&);
@ -100,7 +106,9 @@ namespace uf {
uf::IoStream& UF_API_CALL operator<< (const double&); uf::IoStream& UF_API_CALL operator<< (const double&);
uf::IoStream& UF_API_CALL operator<< (const long double&); uf::IoStream& UF_API_CALL operator<< (const long double&);
uf::IoStream& UF_API_CALL operator<< (const uf::stl::string&); uf::IoStream& UF_API_CALL operator<< (const uf::stl::string&);
#if UF_USE_DEPRECATED_STRING
uf::IoStream& UF_API_CALL operator<< (const uf::String&); uf::IoStream& UF_API_CALL operator<< (const uf::String&);
#endif
uf::IoStream& UF_API_CALL operator<< (const char*); uf::IoStream& UF_API_CALL operator<< (const char*);
uf::IoStream& UF_API_CALL operator<< (const uf::Serializer& val); uf::IoStream& UF_API_CALL operator<< (const uf::Serializer& val);
uf::IoStream& UF_API_CALL operator<< ( void* ); uf::IoStream& UF_API_CALL operator<< ( void* );

View File

@ -649,7 +649,7 @@ template<typename T, size_t R, size_t C>
pod::Matrix<T,R,C>& /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, pod::Matrix<T,R,C>& m ) { pod::Matrix<T,R,C>& /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, pod::Matrix<T,R,C>& m ) {
if ( ext::json::isArray(json) ) if ( ext::json::isArray(json) )
#pragma unroll // GCC unroll T::size #pragma unroll // GCC unroll T::size
for ( uint_fast8_t i = 0; i < R*C; ++i ) for ( uint_fast8_t i = 0; i < R*C && i < json.size(); ++i )
m[i] = json[i].as<T>(m[i]); m[i] = json[i].as<T>(m[i]);
else if ( ext::json::isObject(json) ) { else if ( ext::json::isObject(json) ) {
uint_fast8_t i = 0; uint_fast8_t i = 0;
@ -667,7 +667,7 @@ pod::Matrix<T,R,C> /*UF_API*/ uf::matrix::decode( const ext::json::Value& json,
ALIGN16 pod::Matrix<T,R,C> m = _m; ALIGN16 pod::Matrix<T,R,C> m = _m;
if ( ext::json::isArray(json) ) if ( ext::json::isArray(json) )
#pragma unroll // GCC unroll T::size #pragma unroll // GCC unroll T::size
for ( uint_fast8_t i = 0; i < R*C; ++i ) for ( uint_fast8_t i = 0; i < R*C && i < json.size(); ++i )
m[i] = json[i].as<T>(_m[i]); m[i] = json[i].as<T>(_m[i]);
else if ( ext::json::isObject(json) ) { else if ( ext::json::isObject(json) ) {
uint_fast8_t i = 0; uint_fast8_t i = 0;

View File

@ -572,7 +572,7 @@ template<typename T, size_t N>
pod::Vector<T,N>& /*UF_API*/ uf::vector::decode( const ext::json::Value& json, pod::Vector<T,N>& v ) { pod::Vector<T,N>& /*UF_API*/ uf::vector::decode( const ext::json::Value& json, pod::Vector<T,N>& v ) {
if ( ext::json::isArray(json) ) if ( ext::json::isArray(json) )
#pragma unroll // GCC unroll T::size #pragma unroll // GCC unroll T::size
for ( auto i = 0; i < N; ++i ) for ( auto i = 0; i < N && i < json.size(); ++i )
v[i] = json[i].as<T>(v[i]); v[i] = json[i].as<T>(v[i]);
else if ( ext::json::isObject(json) ) { else if ( ext::json::isObject(json) ) {
auto i = 0; auto i = 0;
@ -589,7 +589,7 @@ pod::Vector<T,N> /*UF_API*/ uf::vector::decode( const ext::json::Value& json, co
pod::Vector<T,N> v = _v; pod::Vector<T,N> v = _v;
if ( ext::json::isArray(json) ) if ( ext::json::isArray(json) )
#pragma unroll // GCC unroll T::size #pragma unroll // GCC unroll T::size
for ( auto i = 0; i < N; ++i ) for ( auto i = 0; i < N && i < json.size(); ++i )
v[i] = json[i].as<T>(_v[i]); v[i] = json[i].as<T>(_v[i]);
else if ( ext::json::isObject(json) ) { else if ( ext::json::isObject(json) ) {
auto i = 0; auto i = 0;

View File

@ -7,12 +7,17 @@
#include <locale> #include <locale>
#include <cstring> #include <cstring>
#if UF_USE_DEPRECATED_STRING
namespace uf { namespace uf {
class UF_API String { class UF_API String {
public: public:
typedef uf::locale::Utf8 encoding_t; typedef uf::locale::Utf8 encoding_t;
typedef uf::String::encoding_t::literal_t literal_t; typedef uf::String::encoding_t::literal_t literal_t;
#if __clang__
typedef std::basic_string<char> string_t;
#else
typedef std::basic_string<literal_t> string_t; typedef std::basic_string<literal_t> string_t;
#endif
typedef uf::String::string_t::iterator iterator_t; typedef uf::String::string_t::iterator iterator_t;
typedef uf::String::string_t::const_iterator const_iterator_t; typedef uf::String::string_t::const_iterator const_iterator_t;
@ -111,4 +116,5 @@ namespace uf {
return os << str; return os << str;
} }
}; };
} }
#endif

View File

@ -25,8 +25,8 @@ namespace uf {
bool generated(); bool generated();
uint8_t* generate( const uf::stl::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( ext::freetype::Glyph&, unsigned long, uint = 48 );
uint8_t* generate( const uf::stl::string&, const uf::String&, uint = 48 ); uint8_t* generate( const uf::stl::string&, const uf::stl::string&, uint = 48 );
uint8_t* generate( ext::freetype::Glyph&, const uf::String&, uint = 48 ); uint8_t* generate( ext::freetype::Glyph&, const uf::stl::string&, uint = 48 );
void generateSdf( uint8_t* ); void generateSdf( uint8_t* );
// Get // Get

View File

@ -135,11 +135,13 @@ bool uf::pointeredUserdata::is( const pod::PointeredUserdata& userdata ) {
} }
template<typename T> const pod::UserdataTraits& uf::pointeredUserdata::registerTrait() { template<typename T> const pod::UserdataTraits& uf::pointeredUserdata::registerTrait() {
auto& trait = uf::userdata::traits[UF_USERDATA_CTTI(T)]; auto& trait = uf::userdata::traits[UF_USERDATA_CTTI(T)];
trait.name = TYPE_NAME(T); #if UF_DEBUG
trait.name = TYPE_NAME(T); // this sometimes causes a crash but this is only needed for debugging anywys
#endif
trait.constructor = &uf::userdata::construct<T>; trait.constructor = &uf::userdata::construct<T>;
trait.destructor = &uf::userdata::destruct<T>; trait.destructor = &uf::userdata::destruct<T>;
return trait;} return trait;
// }
// No need to cast data to a pointer AND get the data's size! // No need to cast data to a pointer AND get the data's size!
template<typename T> template<typename T>
pod::PointeredUserdata& uf::PointeredUserdata::create( const T& data ) { pod::PointeredUserdata& uf::PointeredUserdata::create( const T& data ) {

View File

@ -53,7 +53,7 @@ uf::Serializer uf::config;
namespace { namespace {
struct { struct {
uf::String input; uf::stl::string input;
std::ofstream output; std::ofstream output;
struct { struct {

View File

@ -196,9 +196,12 @@ namespace {
if ( maxTries == 0 ) text += "\n(error formatting)"; if ( maxTries == 0 ) text += "\n(error formatting)";
string = text; string = text;
} }
#if 0
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert;
std::wstring str = convert.from_bytes(string); std::wstring str = convert.from_bytes(string);
#else
std::u8string str(string.begin(), string.end());
#endif
if ( str.size() == 0 ) return gs; if ( str.size() == 0 ) return gs;
// Calculate statistics // Calculate statistics

View File

@ -15,7 +15,6 @@
#include <uf/utils/io/inputs.h> #include <uf/utils/io/inputs.h>
#include <sstream> #include <sstream>
#include <stdfloat>
#include "../scene/behavior.h" #include "../scene/behavior.h"
// #include "../../gui/manager/behavior.h" // #include "../../gui/manager/behavior.h"

View File

@ -1509,7 +1509,7 @@ void uf::graph::render( pod::Graph::Storage& storage ) {
storage.buffers.camera.update( (const void*) &viewport, sizeof(pod::Camera::Viewports) ); storage.buffers.camera.update( (const void*) &viewport, sizeof(pod::Camera::Viewports) );
#if UF_USE_VULKAN #if UF_USE_VULKAN
if ( !renderMode || !renderMode->hasBuffer("camera") ) return; if ( !renderMode || !renderMode->hasBuffer("camera") || renderMode->getType() == "Swapchain" ) return; // for some reason causes clang ASAN to cry
auto& buffer = renderMode->getBuffer("camera"); auto& buffer = renderMode->getBuffer("camera");
buffer.update( (const void*) &viewport, sizeof(pod::Camera::Viewports) ); buffer.update( (const void*) &viewport, sizeof(pod::Camera::Viewports) );
#endif #endif

View File

@ -2,6 +2,40 @@
#if UF_USE_FREETYPE #if UF_USE_FREETYPE
#include <uf/ext/freetype/freetype.h> #include <uf/ext/freetype/freetype.h>
namespace {
unsigned long first_codepoint(const std::u8string& str) {
if (str.empty()) throw std::runtime_error("Empty string");
const unsigned char* bytes = reinterpret_cast<const unsigned char*>(str.data());
unsigned char b0 = bytes[0];
unsigned long codepoint = 0;
int extra_bytes = 0;
if (b0 < 0x80) {
return b0;
} else if ((b0 >> 5) == 0x6) {
codepoint = b0 & 0x1F;
extra_bytes = 1;
} else if ((b0 >> 4) == 0xE) {
codepoint = b0 & 0x0F;
extra_bytes = 2;
} else if ((b0 >> 3) == 0x1E) {
codepoint = b0 & 0x07;
extra_bytes = 3;
} else {
UF_EXCEPTION("Invalid UTF-8 start byte");
}
for (int i = 0; i < extra_bytes; ++i) {
unsigned char bx = bytes[i+1];
if ((bx >> 6) != 0x2) UF_EXCEPTION("Invalid continuation byte");
codepoint = (codepoint << 6) | (bx & 0x3F);
}
return codepoint;
}
}
ext::freetype::Library ext::freetype::library; ext::freetype::Library ext::freetype::library;
ext::freetype::Library::Library() : loaded(false) { ext::freetype::Library::Library() : loaded(false) {
@ -81,8 +115,12 @@ bool ext::freetype::load( ext::freetype::Glyph& glyph, unsigned long c ) {
} }
return true; return true;
} }
bool ext::freetype::load( ext::freetype::Glyph& glyph, const uf::String& string ) { bool ext::freetype::load( ext::freetype::Glyph& glyph, const uf::stl::string& string ) {
#if UF_USE_DEPRECATED_STRING
unsigned long c = string.translate<uf::locale::Utf32>().at(0); unsigned long c = string.translate<uf::locale::Utf32>().at(0);
#else
unsigned long c = first_codepoint( std::u8string( string.begin(), string.end() ) );
#endif
int error = 0; int error = 0;
if ( (error = FT_Load_Char(glyph.face, FT_Get_Char_Index(glyph.face, c), FT_LOAD_RENDER) )) { if ( (error = FT_Load_Char(glyph.face, FT_Get_Char_Index(glyph.face, c), FT_LOAD_RENDER) )) {
std::cout << "Error #" << ext::freetype::getError(error) << ": FreeType failed to load glyph `" << c << "`" << std::endl; std::cout << "Error #" << ext::freetype::getError(error) << ": FreeType failed to load glyph `" << c << "`" << std::endl;
@ -94,8 +132,8 @@ bool ext::freetype::load( ext::freetype::Glyph& glyph, const uf::String& string
uf::stl::string ext::freetype::getError( int error ) { uf::stl::string ext::freetype::getError( int error ) {
#undef FTERRORS_H_ #undef FTERRORS_H_
#define FT_ERRORDEF( e, v, s ) { e, s }, #define FT_ERRORDEF( e, v, s ) { e, s },
#define FT_ERROR_START_LIST { #define FT_ERROR_START_LIST {
#define FT_ERROR_END_LIST { 0, NULL } }; #define FT_ERROR_END_LIST { 0, NULL } };
const struct FTErrors { const struct FTErrors {
int err_code; int err_code;

View File

@ -1,99 +0,0 @@
#include <uf/ext/lua/lua.h>
#if UF_USE_LUA
#include <uf/utils/math/quaternion.h>
namespace {
typedef pod::Quaternion<> Quaternion;
}
namespace binds {
float index( const ::Quaternion& self, size_t index ) {
return self[index];
}
::Quaternion lookAt( const pod::Vector3f& at, const pod::Vector3f& up ) {
return uf::quaternion::lookAt( at, up );
}
::Quaternion normalize( const ::Quaternion& self ) {
return uf::quaternion::normalize( self );
}
::Quaternion multiply( const ::Quaternion& left, const ::Quaternion& right ) {
return uf::quaternion::multiply( left, right );
}
::Quaternion axisAngle( sol::object arg, float angle ){
if ( arg.is<pod::Vector3f>() ) {
return uf::quaternion::axisAngle( arg.as<pod::Vector3f>(), angle );
} else if ( arg.is<sol::table>() ) {
sol::table table = arg.as<sol::table>();
return uf::quaternion::axisAngle( pod::Vector3f{ table[0], table[1], table[2] }, angle );
}
return ::Quaternion{};
}
pod::Vector3f rotate( const ::Quaternion& left, const pod::Vector3f& right ) {
return uf::quaternion::rotate( left, right );
}
::Quaternion eulerAngles( const ::Quaternion& quaternion ) {
return uf::quaternion::eulerAngles( quaternion );
}
::Quaternion conjugate( const ::Quaternion& quaternion ) {
return uf::quaternion::conjugate( quaternion );
}
::Quaternion inverse( const ::Quaternion& quaternion ) {
return uf::quaternion::inverse( quaternion );
}
float pitch( const ::Quaternion& quaternion ) {
return uf::quaternion::pitch( quaternion );
}
float yaw( const ::Quaternion& quaternion ) {
return uf::quaternion::yaw( quaternion );
}
float roll( const ::Quaternion& quaternion ) {
return uf::quaternion::roll( quaternion );
}
::Quaternion slerp( const ::Quaternion& left, const ::Quaternion& right, float a ) {
return uf::quaternion::slerp( left, right, a );
}
pod::Matrix4f matrix( const ::Quaternion& q ) {
return uf::quaternion::matrix( q );
}
uf::stl::string __tostring( const ::Quaternion& self ) {
return uf::string::toString( self );
}
}
#include <uf/ext/lua/component.h>
UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(::Quaternion,
sol::call_constructor, sol::initializers(
[]( ::Quaternion& self ) {
return self = {0,0,0,1};
},
[]( ::Quaternion& self, const ::Quaternion& copy ) {
return self = copy;
},
[]( ::Quaternion& self, float x, float y, float z, float w ) {
return self = uf::vector::create(x, y, z, w);
}
),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::x),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::y),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::z),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::w),
UF_LUA_REGISTER_USERTYPE_DEFINE( v, UF_LUA_C_FUN(::binds::index) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( lookAt, UF_LUA_C_FUN(::binds::lookAt) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( normalize, UF_LUA_C_FUN(::binds::normalize) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( multiply, UF_LUA_C_FUN(::binds::multiply) ),
sol::meta_function::multiplication, UF_LUA_C_FUN(::binds::multiply),
UF_LUA_REGISTER_USERTYPE_DEFINE(axisAngle, UF_LUA_C_FUN(::binds::axisAngle) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( rotate, UF_LUA_C_FUN( ::binds::rotate ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( eulerAngles, UF_LUA_C_FUN( ::binds::eulerAngles ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( conjugate, UF_LUA_C_FUN( ::binds::conjugate ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( inverse, UF_LUA_C_FUN( ::binds::inverse ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( pitch, UF_LUA_C_FUN( ::binds::pitch ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( yaw, UF_LUA_C_FUN( ::binds::yaw ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( roll, UF_LUA_C_FUN( ::binds::roll ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( slerp, UF_LUA_C_FUN( ::binds::slerp ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( matrix, UF_LUA_C_FUN( ::binds::matrix ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN( ::binds::__tostring ) )
)
#endif

View File

@ -1,6 +1,12 @@
#include <uf/ext/lua/lua.h> #include <uf/ext/lua/lua.h>
#if UF_USE_LUA #if UF_USE_LUA
#include <uf/utils/math/vector.h> #include <uf/utils/math/vector.h>
#include <uf/utils/math/quaternion.h>
namespace {
// I don't remember specifically why beyond having the name drop the <> despite it getting culled anyways in last_ns or whatever
typedef pod::Quaternion<> Quaternion;
}
namespace binds { namespace binds {
namespace v3f { namespace v3f {
@ -165,4 +171,94 @@ UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(pod::Vector4f,
UF_LUA_REGISTER_USERTYPE_DEFINE( dot, UF_LUA_C_FUN(::binds::v4f::dot) ), UF_LUA_REGISTER_USERTYPE_DEFINE( dot, UF_LUA_C_FUN(::binds::v4f::dot) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN(::binds::v4f::toString) ) UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN(::binds::v4f::toString) )
) )
// need to handle quaternions here because it may get initialized after the above on systems where static initialization order is undefined (Linux)
namespace binds {
float index( const ::Quaternion& self, size_t index ) {
return self[index];
}
::Quaternion lookAt( const pod::Vector3f& at, const pod::Vector3f& up ) {
return uf::quaternion::lookAt( at, up );
}
::Quaternion normalize( const ::Quaternion& self ) {
return uf::quaternion::normalize( self );
}
::Quaternion multiply( const ::Quaternion& left, const ::Quaternion& right ) {
return uf::quaternion::multiply( left, right );
}
::Quaternion axisAngle( sol::object arg, float angle ){
if ( arg.is<pod::Vector3f>() ) {
return uf::quaternion::axisAngle( arg.as<pod::Vector3f>(), angle );
} else if ( arg.is<sol::table>() ) {
sol::table table = arg.as<sol::table>();
return uf::quaternion::axisAngle( pod::Vector3f{ table[0], table[1], table[2] }, angle );
}
return ::Quaternion{};
}
pod::Vector3f rotate( const ::Quaternion& left, const pod::Vector3f& right ) {
return uf::quaternion::rotate( left, right );
}
::Quaternion eulerAngles( const ::Quaternion& quaternion ) {
return uf::quaternion::eulerAngles( quaternion );
}
::Quaternion conjugate( const ::Quaternion& quaternion ) {
return uf::quaternion::conjugate( quaternion );
}
::Quaternion inverse( const ::Quaternion& quaternion ) {
return uf::quaternion::inverse( quaternion );
}
float pitch( const ::Quaternion& quaternion ) {
return uf::quaternion::pitch( quaternion );
}
float yaw( const ::Quaternion& quaternion ) {
return uf::quaternion::yaw( quaternion );
}
float roll( const ::Quaternion& quaternion ) {
return uf::quaternion::roll( quaternion );
}
::Quaternion slerp( const ::Quaternion& left, const ::Quaternion& right, float a ) {
return uf::quaternion::slerp( left, right, a );
}
pod::Matrix4f matrix( const ::Quaternion& q ) {
return uf::quaternion::matrix( q );
}
uf::stl::string __tostring( const ::Quaternion& self ) {
return uf::string::toString( self );
}
}
UF_LUA_REGISTER_USERTYPE_AND_COMPONENT(::Quaternion,
sol::call_constructor, sol::initializers(
[]( ::Quaternion& self ) {
return self = {0,0,0,1};
},
[]( ::Quaternion& self, const ::Quaternion& copy ) {
return self = copy;
},
[]( ::Quaternion& self, float x, float y, float z, float w ) {
return self = uf::vector::create(x, y, z, w);
}
),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::x),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::y),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::z),
UF_LUA_REGISTER_USERTYPE_MEMBER(::Quaternion::w),
UF_LUA_REGISTER_USERTYPE_DEFINE( v, UF_LUA_C_FUN(::binds::index) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( lookAt, UF_LUA_C_FUN(::binds::lookAt) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( normalize, UF_LUA_C_FUN(::binds::normalize) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( multiply, UF_LUA_C_FUN(::binds::multiply) ),
sol::meta_function::multiplication, UF_LUA_C_FUN(::binds::multiply),
UF_LUA_REGISTER_USERTYPE_DEFINE( axisAngle, UF_LUA_C_FUN(::binds::axisAngle) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( rotate, UF_LUA_C_FUN( ::binds::rotate ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( eulerAngles, UF_LUA_C_FUN( ::binds::eulerAngles ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( conjugate, UF_LUA_C_FUN( ::binds::conjugate ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( inverse, UF_LUA_C_FUN( ::binds::inverse ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( pitch, UF_LUA_C_FUN( ::binds::pitch ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( yaw, UF_LUA_C_FUN( ::binds::yaw ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( roll, UF_LUA_C_FUN( ::binds::roll ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( slerp, UF_LUA_C_FUN( ::binds::slerp ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( matrix, UF_LUA_C_FUN( ::binds::matrix ) ),
UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, UF_LUA_C_FUN( ::binds::__tostring ) )
)
#endif #endif

View File

@ -209,6 +209,8 @@ void ext::al::close( uf::audio::Metadata& metadata ) {
} }
void ext::al::listener( const pod::Transform<>& transform ) { void ext::al::listener( const pod::Transform<>& transform ) {
if ( uf::audio::muted ) return;
float o[6] = { transform.forward.x, transform.forward.y, transform.forward.z, transform.up.x, transform.up.y, transform.up.z }; float o[6] = { transform.forward.x, transform.forward.y, transform.forward.z, transform.up.x, transform.up.y, transform.up.z };
AL_CHECK_RESULT(alListener3f( AL_POSITION, transform.position.x, transform.position.y, transform.position.z )); AL_CHECK_RESULT(alListener3f( AL_POSITION, transform.position.x, transform.position.y, transform.position.z ));
AL_CHECK_RESULT(alListener3f( AL_VELOCITY, 0, 0, 0 )); AL_CHECK_RESULT(alListener3f( AL_VELOCITY, 0, 0, 0 ));

View File

@ -103,7 +103,7 @@ void ext::opengl::Buffer::allocate( const CreateInfo& bufferCreateInfo ) {
this->destroy(); this->destroy();
if ( !device ) device = &ext::opengl::device; if ( !device ) device = &ext::opengl::device;
this->buffer = device->createBuffer( bufferCreateInfo.usage, bufferCreateInfo.size, nullptr, bufferCreateInfo.aliased ); this->buffer = device->createBuffer( bufferCreateInfo.usage, bufferCreateInfo.size, NULL, bufferCreateInfo.aliased );
this->usage = bufferCreateInfo.usage; this->usage = bufferCreateInfo.usage;
this->size = bufferCreateInfo.size; this->size = bufferCreateInfo.size;

View File

@ -77,7 +77,7 @@ GLhandle(VkColorSpaceKHR) ext::opengl::settings::formats::colorSpace;
ext::opengl::enums::Format::type_t ext::opengl::settings::formats::color = ext::opengl::enums::Format::R8G8B8A8_UNORM; ext::opengl::enums::Format::type_t ext::opengl::settings::formats::color = ext::opengl::enums::Format::R8G8B8A8_UNORM;
ext::opengl::enums::Format::type_t ext::opengl::settings::formats::depth = ext::opengl::enums::Format::D32_SFLOAT; ext::opengl::enums::Format::type_t ext::opengl::settings::formats::depth = ext::opengl::enums::Format::D32_SFLOAT;
ext::opengl::Device* ext::opengl::device = NULL; ext::opengl::Device ext::opengl::device;
std::mutex ext::opengl::mutex; std::mutex ext::opengl::mutex;
std::mutex ext::opengl::immediateModeMutex; std::mutex ext::opengl::immediateModeMutex;
@ -505,8 +505,6 @@ void ext::opengl::destroy() {
// swapchain.destroy(); // swapchain.destroy();
device.destroy(); device.destroy();
ext::opengl::mutex.unlock(); ext::opengl::mutex.unlock();
delete device;
} }
void ext::opengl::synchronize( uint8_t flag ) { void ext::opengl::synchronize( uint8_t flag ) {
if ( flag & 0b01 ) { if ( flag & 0b01 ) {

View File

@ -82,7 +82,7 @@ void ext::opengl::Shader::initialize( ext::opengl::Device& device, const uf::stl
} }
} }
if ( metadata.autoInitializeUniformBuffers ) { if ( metadata.autoInitializeUniformBuffers ) {
initializeBuffer( nullptr, sizeof(pod::Uniform), uf::renderer::enums::Buffer::UNIFORM ); initializeBuffer( NULL, sizeof(pod::Uniform), uf::renderer::enums::Buffer::UNIFORM );
} }
#endif #endif
} }

View File

@ -43,7 +43,7 @@ namespace {
case ULMessageSource::kMessageSource_ContentBlocker: source = "ContentBlocker"; break; case ULMessageSource::kMessageSource_ContentBlocker: source = "ContentBlocker"; break;
case ULMessageSource::kMessageSource_Other: source = "Other"; break; case ULMessageSource::kMessageSource_Other: source = "Other"; break;
} }
uf::String message; { uf::stl::string message; {
size_t len = ulStringGetLength(_message); size_t len = ulStringGetLength(_message);
const ULChar16* data = ulStringGetData(_message); const ULChar16* data = ulStringGetData(_message);
for ( size_t i = 0; i < len; ++i ) message += data[i]; for ( size_t i = 0; i < len; ++i ) message += data[i];

View File

@ -8,6 +8,9 @@
#include <GL/glx.h> #include <GL/glx.h>
#include <GL/glxext.h> #include <GL/glxext.h>
#define None 0L
#define Success 0
spec::x11::Context::Context( uni::Context* shared, const Context::Settings& settings ) : spec::x11::Context::Context( uni::Context* shared, const Context::Settings& settings ) :
uni::Context(NULL, true, settings), uni::Context(NULL, true, settings),
m_display(nullptr), m_display(nullptr),
@ -16,7 +19,7 @@ spec::x11::Context::Context( uni::Context* shared, const Context::Settings& sett
{ {
m_display = XOpenDisplay(NULL); m_display = XOpenDisplay(NULL);
if (!m_display) { if (!m_display) {
std::cerr << "Failed to open X display\n"; UF_MSG_ERROR("Failed to open X display");
return; return;
} }
@ -26,7 +29,8 @@ spec::x11::Context::Context( uni::Context* shared, const Context::Settings& sett
XSetWindowAttributes swa; XSetWindowAttributes swa;
swa.event_mask = StructureNotifyMask; swa.event_mask = StructureNotifyMask;
m_window = XCreateSimpleWindow(m_display, RootWindow(m_display, scr), 0, 0, 1, 1, 0, 0, 0); m_window = XCreateSimpleWindow(m_display, RootWindow(m_display, scr), 0, 0, 1, 1, 0, 0, 0);
XMapWindow(m_display, m_window);
//XMapWindow(m_display, m_window);
this->create(shared); this->create(shared);
} }
@ -62,7 +66,7 @@ void spec::x11::Context::create( uni::Context* shared ) {
int scr = DefaultScreen(m_display); int scr = DefaultScreen(m_display);
XVisualInfo* vi = glXChooseVisual(m_display, scr, attribs); XVisualInfo* vi = glXChooseVisual(m_display, scr, attribs);
if (!vi) { if (!vi) {
std::cerr << "Failed to choose visual\n"; UF_MSG_ERROR("Failed to choose visual");
return; return;
} }
@ -70,7 +74,7 @@ void spec::x11::Context::create( uni::Context* shared ) {
m_context = glXCreateContext(m_display, vi, sharedCtx, True); m_context = glXCreateContext(m_display, vi, sharedCtx, True);
if (!m_context) { if (!m_context) {
std::cerr << "glXCreateContext failed\n"; UF_MSG_ERROR("glXCreateContext failed");
} }
} }

View File

@ -14,6 +14,13 @@
#define UF_HOOK_USE_USERDATA 1 #define UF_HOOK_USE_USERDATA 1
#define UF_HOOK_USE_JSON 0 #define UF_HOOK_USE_JSON 0
#if UF_USE_VULKAN
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_xlib.h>
#elif UF_USE_OPENGL
#include <GL/glx.h>
#endif
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
@ -23,6 +30,9 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#define None 0L
#define Success 0
namespace { namespace {
Display *globalDisplay = nullptr; Display *globalDisplay = nullptr;
int windowCount = 0; int windowCount = 0;
@ -239,6 +249,9 @@ void spec::x11::Window::terminate() {
#endif #endif
} }
Display* spec::x11::Window::getDisplay() const {
return m_display;
}
spec::x11::Window::handle_t spec::x11::Window::getHandle() const { spec::x11::Window::handle_t spec::x11::Window::getHandle() const {
return m_handle; return m_handle;
} }
@ -1053,6 +1066,9 @@ void spec::x11::Window::processEvents() {
pod::payloads::windowMouseMoved move{ pod::payloads::windowMouseMoved move{
{{"window:Mouse.Moved", "client"}, {getSize()}}, {{"window:Mouse.Moved", "client"}, {getSize()}},
{current, current - last, 0}}; {current, current - last, 0}};
if ( current == last ) break;
this->pushEvent(move.type, move); this->pushEvent(move.type, move);
last = current; last = current;

View File

@ -519,7 +519,7 @@ void spec::win32::Window::create( const spec::win32::Window::vector_t& _size, co
this->m_handle = CreateWindowW( this->m_handle = CreateWindowW(
className.c_str(), className.c_str(),
std::wstring(title).c_str(), std::wstring(title.begin(), title.end()).c_str(),
winStyle, winStyle,
position.x, position.x,
position.y, position.y,
@ -636,8 +636,8 @@ void spec::win32::Window::setSize( const spec::win32::Window::vector_t& size ) {
} }
void spec::win32::Window::setTitle( const spec::win32::Window::title_t& title ) { void spec::win32::Window::setTitle( const spec::win32::Window::title_t& title ) {
SetWindowTextW(this->m_handle, std::wstring(title).c_str()); SetWindowTextW(this->m_handle, std::wstring(title.begin(), title.end()).c_str());
// SetWindowTextW(this->m_handle, (wchar_t*) std::wstring(title).c_str()); // SetWindowTextW(this->m_handle, (wchar_t*) std::wstring(title.begin(), title.end()).c_str());
} }
void spec::win32::Window::setIcon( const spec::win32::Window::vector_t& size, uint8_t* pixels ) { void spec::win32::Window::setIcon( const spec::win32::Window::vector_t& size, uint8_t* pixels ) {
// First destroy the previous one // First destroy the previous one
@ -1067,6 +1067,7 @@ void spec::win32::Window::processEvent(UINT message, WPARAM wParam, LPARAM lPara
} break; } break;
// Text event // Text event
case WM_CHAR: if ( /*true ||*/ this->m_syncParse ) { case WM_CHAR: if ( /*true ||*/ this->m_syncParse ) {
#if 0
if (this->m_keyRepeatEnabled || ((lParam & (1 << 30)) == 0)) { if (this->m_keyRepeatEnabled || ((lParam & (1 << 30)) == 0)) {
// Get the code of the typed character // Get the code of the typed character
uint32_t character = static_cast<uint32_t>(wParam); uint32_t character = static_cast<uint32_t>(wParam);
@ -1084,7 +1085,7 @@ void spec::win32::Window::processEvent(UINT message, WPARAM wParam, LPARAM lPara
this->m_surrogate = 0; this->m_surrogate = 0;
} }
std::basic_string<uint32_t> utf32; utf32+=character; std::basic_string<uint32_t> utf32; utf32+=character;
std::basic_string<uint8_t> utf8; utf8.reserve(utf32.length()); std::basic_string<char> utf8; utf8.reserve(utf32.length());
uf::Utf32::toUtf8(utf32.begin(), utf32.end(), std::back_inserter(utf8)); uf::Utf32::toUtf8(utf32.begin(), utf32.end(), std::back_inserter(utf8));
pod::payloads::windowTextEntered event{ pod::payloads::windowTextEntered event{
@ -1110,6 +1111,7 @@ void spec::win32::Window::processEvent(UINT message, WPARAM wParam, LPARAM lPara
#endif #endif
} }
} }
#endif
} break; } break;
case WM_KEYDOWN: case WM_KEYDOWN:
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:

View File

@ -105,11 +105,15 @@ void uf::MappedAudioEmitter::update() {
} }
} }
void uf::MappedAudioEmitter::cleanup( bool purge ) { void uf::MappedAudioEmitter::cleanup( bool purge ) {
for ( auto& pair : this->m_container ) { for ( auto it = this->m_container.begin(); it != this->m_container.end(); ) {
if ( purge || !pair.second.playing() ) { auto& pair = *it;
if (purge || !pair.second.playing()) {
pair.second.stop(); pair.second.stop();
pair.second.destroy(); pair.second.destroy();
this->m_container.erase(pair.first); // because cleanup might only happen on nonplaying audio (for some reason) we're erasing here instead of just clearing the container
it = this->m_container.erase(it);
} else {
++it;
} }
} }
} }

View File

@ -48,9 +48,11 @@ namespace {
void addStr( const uf::stl::string& str ) { void addStr( const uf::stl::string& str ) {
for ( auto x : str ) addCh(x); for ( auto x : str ) addCh(x);
} }
#if UF_USE_DEPRECATED_STRING
void addUStr( const uf::String& str ) { void addUStr( const uf::String& str ) {
for ( auto x : str.getString() ) addCh(x); for ( auto x : str.getString() ) addCh(x);
} }
#endif
}; };
bool uf::IoStream::ncurses = false; bool uf::IoStream::ncurses = false;
uf::IoStream uf::iostream; uf::IoStream uf::iostream;
@ -94,14 +96,16 @@ uf::stl::string uf::IoStream::readString(const bool& loop) {
// ::info.input.history.push_back( str ); // ::info.input.history.push_back( str );
return str; return str;
} }
#if UF_USE_DEPRECATED_STRING
uf::String uf::IoStream::readUString(const bool& loop) { uf::String uf::IoStream::readUString(const bool& loop) {
uf::stl::string str; uf::stl::string str;
std::getline(std::cin, str); std::getline(std::cin, str);
addUStr(str); addStr(str);
// ::info.input.history.push_back( str ); // ::info.input.history.push_back( str );
return str; return str;
} }
#endif
char uf::IoStream::writeChar( char ch ) { char uf::IoStream::writeChar( char ch ) {
addCh(ch); addCh(ch);
@ -118,6 +122,7 @@ const uf::stl::string& uf::IoStream::writeString( const uf::stl::string& str ) {
// ::info.input.history.push_back( str ); // ::info.input.history.push_back( str );
return str; return str;
} }
#if UF_USE_DEPRECATED_STRING
const uf::String& uf::IoStream::writeUString( const uf::String& str ) { const uf::String& uf::IoStream::writeUString( const uf::String& str ) {
addUStr(str); addUStr(str);
@ -125,6 +130,7 @@ const uf::String& uf::IoStream::writeUString( const uf::String& str ) {
// ::info.input.history.push_back( str ); // ::info.input.history.push_back( str );
return str; return str;
} }
#endif
void uf::IoStream::operator>> (bool& val) { void uf::IoStream::operator>> (bool& val) {
uf::stl::stringstream ss; uf::stl::stringstream ss;
@ -195,9 +201,11 @@ void uf::IoStream::operator>> (long double& val) {
void uf::IoStream::operator>> (uf::stl::string& val) { void uf::IoStream::operator>> (uf::stl::string& val) {
val = this->readString(); val = this->readString();
} }
#if UF_USE_DEPRECATED_STRING
void uf::IoStream::operator>> (uf::String& val) { void uf::IoStream::operator>> (uf::String& val) {
val = this->readUString(); val = this->readUString();
} }
#endif
std::istream& uf::IoStream::operator>> ( std::istream& is ) { std::istream& uf::IoStream::operator>> ( std::istream& is ) {
uf::stl::string input; uf::stl::string input;
is >> input; is >> input;
@ -295,10 +303,12 @@ uf::IoStream& uf::IoStream::operator<< (const uf::stl::string& val) {
this->writeString(val); this->writeString(val);
return *this; return *this;
} }
#if UF_USE_DEPRECATED_STRING
uf::IoStream& uf::IoStream::operator<< (const uf::String& val) { uf::IoStream& uf::IoStream::operator<< (const uf::String& val) {
this->writeUString(val); this->writeUString(val);
return *this; return *this;
} }
#endif
uf::IoStream& uf::IoStream::operator<< (const char* cstr) { uf::IoStream& uf::IoStream::operator<< (const char* cstr) {
this->writeString(uf::stl::string(cstr)); this->writeString(uf::stl::string(cstr));
return *this; return *this;

View File

@ -154,8 +154,10 @@ pod::Allocation uf::memoryPool::allocate( pod::MemoryPool& pool, size_t size, si
{ {
// find any availble spots in-between existing allocations // find any availble spots in-between existing allocations
auto next = pool.allocations.begin(); auto next = pool.allocations.begin();
// no allocations;
if ( pool.allocations.empty() ) {
// beginning is big enough to fit // beginning is big enough to fit
if ( pointer + size < next->pointer ) { } else if ( pointer + size < next->pointer ) {
} else { } else {
for ( auto it = next; it != pool.allocations.end(); ++it ) { for ( auto it = next; it != pool.allocations.end(); ++it ) {
// ignore invalid indexes // ignore invalid indexes

View File

@ -1,7 +1,9 @@
#include <uf/utils/string/string.h> #include <uf/utils/string/string.h>
#include <uf/utils/string/encoding.h> #include <uf/utils/string/encoding.h>
//uf::String uf::locale::current;
uf::stl::string uf::locale::current; uf::stl::string uf::locale::current;
#if UF_USE_DEPRECATED_STRING
uf::String::String() { uf::String::String() {
} }
// ANSI literals/strings // ANSI literals/strings
@ -222,4 +224,5 @@ uf::String::operator std::wstring() const {
std::wstring w_str; std::wstring w_str;
for ( auto c : this->m_string ) w_str += c; for ( auto c : this->m_string ) w_str += c;
return w_str; return w_str;
} }
#endif

View File

@ -59,11 +59,11 @@ uint8_t* uf::Glyph::generate( ext::freetype::Glyph& glyph, unsigned long c, uint
if ( this->isSdf() ) this->generateSdf(this->m_buffer); if ( this->isSdf() ) this->generateSdf(this->m_buffer);
return this->m_buffer; return this->m_buffer;
} }
uint8_t* uf::Glyph::generate( const uf::stl::string& font, const uf::String& c, uint size ) { uint8_t* uf::Glyph::generate( const uf::stl::string& font, const uf::stl::string& c, uint size ) {
ext::freetype::Glyph glyph = ext::freetype::initialize(font); ext::freetype::Glyph glyph = ext::freetype::initialize(font);
return this->generate( glyph, c ); return this->generate( glyph, c );
} }
uint8_t* uf::Glyph::generate( ext::freetype::Glyph& glyph, const uf::String& c, uint size ) { uint8_t* uf::Glyph::generate( ext::freetype::Glyph& glyph, const uf::stl::string& c, uint size ) {
ext::freetype::setPixelSizes( glyph, size ); ext::freetype::setPixelSizes( glyph, size );
if ( !ext::freetype::load( glyph, c ) ) return NULL; if ( !ext::freetype::load( glyph, c ) ) return NULL;
if ( this->m_buffer ) { if ( this->m_buffer ) {

View File

@ -3,6 +3,6 @@ CDIR =
CC = clang CC = clang
CXX = clang++ CXX = clang++
OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS # -flto # -march=native OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS # -flto # -march=native
WARNINGS = -Wall -Wno-pointer-arith -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder-ctor -Wno-ignored-attributes -Wno-c++11-narrowing -Wno-unknown-pragmas -Wno-nullability-completeness -Wno-defaulted-function-deleted -Wno-mismatched-tags WARNINGS = -Wall -Wno-deprecated-literal-operator -Wno-pointer-arith -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder-ctor -Wno-ignored-attributes -Wno-c++11-narrowing -Wno-unknown-pragmas -Wno-nullability-completeness -Wno-defaulted-function-deleted -Wno-mismatched-tags
SANITIZE = -fsanitize=address # -fuse-ld=lld -fno-omit-frame-pointer SANITIZE = -fsanitize=address # -fuse-ld=lld -fno-omit-frame-pointer
FLAGS += -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) $(SANITIZE) -fcolor-diagnostics -fansi-escape-codes FLAGS += -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) $(SANITIZE) -fcolor-diagnostics -fansi-escape-codes