Commit for 2021.12.27 18-55-51.7z

This commit is contained in:
mrq 2021-12-27 18:55:00 -06:00
parent b208cda203
commit 3bd7dc76b4
35 changed files with 268 additions and 222 deletions

View File

@ -30,7 +30,8 @@ EXT_LIB_NAME += ext
#VULKAN_SDK_PATH += /c/VulkanSDK/1.2.154.0/ #VULKAN_SDK_PATH += /c/VulkanSDK/1.2.154.0/
#VULKAN_SDK_PATH += /c/VulkanSDK/1.2.162.0/ #VULKAN_SDK_PATH += /c/VulkanSDK/1.2.162.0/
#VULKAN_SDK_PATH += /c/VulkanSDK/1.2.176.1/ #VULKAN_SDK_PATH += /c/VulkanSDK/1.2.176.1/
VULKAN_SDK_PATH += /c/VulkanSDK/1.2.182.0/ #VULKAN_SDK_PATH += /c/VulkanSDK/1.2.182.0/
VULKAN_SDK_PATH += /c/VulkanSDK/1.2.198.1/
#GLSL_VALIDATOR += $(VULKAN_SDK_PATH)/Bin32/glslangValidator #GLSL_VALIDATOR += $(VULKAN_SDK_PATH)/Bin32/glslangValidator
GLSL_VALIDATOR += $(VULKAN_SDK_PATH)/Bin32/glslc GLSL_VALIDATOR += $(VULKAN_SDK_PATH)/Bin32/glslc
@ -50,7 +51,7 @@ ifneq (,$(findstring win64,$(ARCH)))
FLAGS += FLAGS +=
DEPS += -lgdi32 DEPS += -lgdi32
else ifneq (,$(findstring dreamcast,$(ARCH))) else ifneq (,$(findstring dreamcast,$(ARCH)))
REQ_DEPS += opengl gldc json:nlohmann bullet lua freetype png zlib ctti ogg openal aldc # ogg openal meshoptimizer draco luajit ultralight-ux ncurses curl openvr discord REQ_DEPS += opengl gldc json:nlohmann lua reactphysics freetype png zlib ctti ogg openal aldc # bullet ogg openal meshoptimizer draco luajit ultralight-ux ncurses curl openvr discord
endif endif
ifneq (,$(findstring vulkan,$(REQ_DEPS))) ifneq (,$(findstring vulkan,$(REQ_DEPS)))
FLAGS += -DVK_USE_PLATFORM_WIN32_KHR -DUF_USE_VULKAN FLAGS += -DVK_USE_PLATFORM_WIN32_KHR -DUF_USE_VULKAN
@ -211,6 +212,9 @@ TARGET_SHADERS += $(patsubst %.glsl,%.spv,$(SRCS_SHADERS))
ifneq (,$(findstring dreamcast,$(ARCH))) ifneq (,$(findstring dreamcast,$(ARCH)))
#$(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi #$(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
$(ARCH): $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi $(ARCH): $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
SRCS_DLL = $(wildcard $(ENGINE_SRC_DIR)/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*/*/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*/*/*/*.cpp)
OBJS_DLL = $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS_DLL))
OBJS = $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS_EXT_DLL)) $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS)) OBJS = $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS_EXT_DLL)) $(patsubst %.cpp,%.$(ARCH).$(CC).o,$(SRCS))
DEPS += -lkallisti -lc -lm -lgcc -lstdc++ # -l$(LIB_NAME) -l$(EXT_LIB_NAME) DEPS += -lkallisti -lc -lm -lgcc -lstdc++ # -l$(LIB_NAME) -l$(EXT_LIB_NAME)
@ -218,12 +222,18 @@ DEPS += -lkallisti -lc -lm -lgcc -lstdc++ # -l$(LIB_NAME) -l$(EXT_LIB_NAME)
%.$(ARCH).$(CC).o: %.cpp %.$(ARCH).$(CC).o: %.cpp
$(CXX) $(FLAGS) $(INCS) -c $< -o $@ $(CXX) $(FLAGS) $(INCS) -c $< -o $@
$(EX_DLL): FLAGS += -DUF_EXPORTS -DEXT_EXPORTS -DJSON_DLL_BUILD $(EX_DLL): FLAGS += -DUF_EXPORTS -DJSON_DLL_BUILD
$(EX_DLL): $(OBJS_DLL) $(EX_DLL): $(OBJS_DLL)
$(KOS_AR) cru $@ $^ $(KOS_AR) cru $@ $^
$(KOS_RANLIB) $@ $(KOS_RANLIB) $@
cp $@ $(ENGINE_LIB_DIR)/$(ARCH)/$(CC)/$(BASE_DLL).a cp $@ $(ENGINE_LIB_DIR)/$(ARCH)/$(CC)/$(BASE_DLL).a
$(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS -DJSON_DLL_BUILD
$(EXT_EX_DLL): $(OBJS_EXT_DLL)
$(KOS_AR) cru $@ $^
$(KOS_RANLIB) $@
cp $@ $(ENGINE_LIB_DIR)/$(ARCH)/$(CC)/$(BASE_EXT_DLL).a
./bin/dreamcast/romdisk.img: ./bin/dreamcast/romdisk.img:
$(KOS_GENROMFS) -f ./bin/dreamcast/romdisk.img -d ./bin/dreamcast/romdisk/ -v $(KOS_GENROMFS) -f ./bin/dreamcast/romdisk.img -d ./bin/dreamcast/romdisk/ -v
@ -261,7 +271,6 @@ $(TARGET): $(OBJS)
endif endif
%.spv: %.glsl %.spv: %.glsl
# $(GLSL_VALIDATOR) -V -o $@ $<
$(GLSL_VALIDATOR) -std=450 -o $@ $< $(GLSL_VALIDATOR) -std=450 -o $@ $<
$(SPV_OPTIMIZER) --preserve-bindings --preserve-spec-constants -O $@ -o $@ $(SPV_OPTIMIZER) --preserve-bindings --preserve-spec-constants -O $@ -o $@

View File

@ -5,10 +5,6 @@
"assets": [ "assets": [
"./scripts/hud.lua" "./scripts/hud.lua"
], ],
"system": {
"clickable": false,
"hoverable": false
},
"transform": { "transform": {
"position": [ 0, 0, 0 ], "position": [ 0, 0, 0 ],
"rotation": { "rotation": {
@ -18,6 +14,7 @@
"scale": [ 16, 16, 16 ] "scale": [ 16, 16, 16 ]
}, },
"metadata": { "metadata": {
"clickable": false,
"hoverable": false,
} }
} }

View File

@ -6,10 +6,6 @@
{ "filename": "./textures/mp.png", "hash": "68e7c459f9aecd6815ff7df1e2eefa82db60a23713b0134f0bfc15d82f55453d" } { "filename": "./textures/mp.png", "hash": "68e7c459f9aecd6815ff7df1e2eefa82db60a23713b0134f0bfc15d82f55453d" }
// { "filename": "./textures/ss2.png" } // { "filename": "./textures/ss2.png" }
], ],
"system": {
"clickable": false,
"hoverable": false
},
"transform": { "transform": {
"position": [ 0, 0, 0 ], "position": [ 0, 0, 0 ],
"rotation": { "rotation": {
@ -20,6 +16,9 @@
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": { "metadata": {
"clickable": false,
"hoverable": false,
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
// "color": [ 0.8, 0.8, 1, 1 ], // "color": [ 0.8, 0.8, 1, 1 ],
// "color": [ 0.416, 0.573, 0.667, 1 ], // "color": [ 0.416, 0.573, 0.667, 1 ],

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": {
"clickable": false, "clickable": false,
"hoverable": false, "hoverable": false,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"color": [ 1, 1, 1, 0.8 ], "color": [ 1, 1, 1, 0.8 ],
"location": "", "location": "",

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": {
"clickable": false, "clickable": false,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"color": [ 1, 1, 1, 0.8 ], "color": [ 1, 1, 1, 0.8 ],
"location": "", "location": "",

View File

@ -6,10 +6,6 @@
"./scripts/menu.lua", "./scripts/menu.lua",
"./textures/menu.png" "./textures/menu.png"
], ],
"system": {
"clickable": true,
"hoverable": true
},
"transform": { "transform": {
"position": [ 0, 0, 0 ], "position": [ 0, 0, 0 ],
"rotation": { "rotation": {
@ -19,7 +15,9 @@
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": { "metadata": {
"experimental": true, "clickable": true,
"hoverable": true,
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"color": [ 1, 1, 1, 1 ], "color": [ 1, 1, 1, 1 ],
"location": "", "location": "",

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": {
"clickable": true, "clickable": true,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"location": "", "location": "",
"scaling": "relative", "scaling": "relative",

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": {
"clickable": true, "clickable": true,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"location": "", "location": "",
"scaling": "relative", "scaling": "relative",

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 1, 1, 1 ] "scale": [ 1, 1, 1 ]
}, },
"metadata": {
"clickable": false, "clickable": false,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"color": [ 1, 1, 1, 0.8 ], "color": [ 1, 1, 1, 0.8 ],
"location": "", "location": "",

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 0.156407, 0.0788377, 1 ] "scale": [ 0.156407, 0.0788377, 1 ]
}, },
"metadata": {
"clickable": true, "clickable": true,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"location": "", "location": "",
"scaling": "relative", "scaling": "relative",

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 0.156407, 0.0788377, 1 ] "scale": [ 0.156407, 0.0788377, 1 ]
}, },
"metadata": {
"clickable": true, "clickable": true,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"location": "", "location": "",
"scaling": "relative", "scaling": "relative",

View File

@ -141,7 +141,7 @@ ent:bind( "tick", function(self)
if child:uid() > 0 then if child:uid() > 0 then
local transform = child:getComponent("Transform") local transform = child:getComponent("Transform")
local metadata = child:getComponent("Metadata") local metadata = child:getComponent("Metadata")
local speed = metadata["hovered"] and 0.75 or 0.5 local speed = metadata["gui"]["hovered"] and 0.75 or 0.5
transform.position.y = transform.position.y + time.delta() * speed transform.position.y = transform.position.y + time.delta() * speed
if transform.position.y > 2 then if transform.position.y > 2 then
transform.position.y = -2 transform.position.y = -2
@ -155,7 +155,7 @@ ent:bind( "tick", function(self)
local metadata = children.circleIn:getComponent("Metadata") local metadata = children.circleIn:getComponent("Metadata")
-- rotation -- rotation
local speed = metadata["hovered"] and 0.25 or 0.0125 local speed = metadata["gui"]["hovered"] and 0.25 or 0.0125
static.time = (static.time or 0) + time.delta() * -speed static.time = (static.time or 0) + time.delta() * -speed
transform.orientation = Quaternion.axisAngle( Vector3f(0, 0, 1), static.time ) transform.orientation = Quaternion.axisAngle( Vector3f(0, 0, 1), static.time )
end end
@ -167,7 +167,7 @@ ent:bind( "tick", function(self)
local metadata = children.circleOut:getComponent("Metadata") local metadata = children.circleOut:getComponent("Metadata")
-- rotation -- rotation
local speed = metadata["hovered"] and 0.25 or 0.0125 local speed = metadata["gui"]["hovered"] and 0.25 or 0.0125
static.time = (static.time or 0) + time.delta() * speed static.time = (static.time or 0) + time.delta() * speed
transform.orientation = Quaternion.axisAngle( Vector3f(0, 0, 1), static.time ) transform.orientation = Quaternion.axisAngle( Vector3f(0, 0, 1), static.time )
end end

View File

@ -10,9 +10,10 @@
}, },
"scale": [ 0.156407, 0.0788377, 1 ] "scale": [ 0.156407, 0.0788377, 1 ]
}, },
"metadata": {
"clickable": true, "clickable": true,
"hoverable": true, "hoverable": true,
"metadata": {
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"location": "", "location": "",
"scaling": "relative", "scaling": "relative",

View File

@ -10,8 +10,10 @@
}, },
"scale": [ 0.43, 1, 1 ] "scale": [ 0.43, 1, 1 ]
}, },
"clickable": true,
"metadata": { "metadata": {
"clickable": true,
"hoverable": false,
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"color": [ 1, 1, 1, 0 ], "color": [ 1, 1, 1, 0 ],
"location": "", "location": "",

View File

@ -6,10 +6,6 @@
"behaviors": [ "behaviors": [
"GuiHtmlBehavior" "GuiHtmlBehavior"
], ],
"system": {
"clickable": true,
"hoverable": true
},
"transform": { "transform": {
"position": [ 0, 4, 0 ], "position": [ 0, 4, 0 ],
"rotation": { "rotation": {
@ -19,6 +15,9 @@
"scale": [ 2, 2, 2 ] "scale": [ 2, 2, 2 ]
}, },
"metadata": { "metadata": {
"clickable": true,
"hoverable": true,
"uv": [ 0, 0, 1, 1 ], "uv": [ 0, 0, 1, 1 ],
"color": [ 1, 1, 1, 1 ], "color": [ 1, 1, 1, 1 ],
"location": "", "location": "",

View File

@ -82,7 +82,7 @@ void client::initialize() {
client::window.setMousePosition(client::window.getSize()/2); client::window.setMousePosition(client::window.getSize()/2);
} }
}); });
uf::hooks.addHook( "window:Closed", [&]( ext::json::Value& json ){ uf::hooks.addHook( "window:Closed", [&]( pod::payloads::windowEvent& json ){
client::ready = false; client::ready = false;
} ); } );
uf::hooks.addHook( "window:Title.Changed", [&]( ext::json::Value& json ){ uf::hooks.addHook( "window:Title.Changed", [&]( ext::json::Value& json ){
@ -98,16 +98,17 @@ void client::initialize() {
if ( payload.invoker != "os" ) client::window.setSize(payload.window.size); if ( payload.invoker != "os" ) client::window.setSize(payload.window.size);
// Update viewport // Update viewport
if ( !ext::json::isArray( client::config["engine"]["ext"]["vulkan"]["framebuffer"]["size"] ) ) { if ( !ext::json::isArray( client::config["engine"]["ext"]["vulkan"]["framebuffer"]["size"] ) ) {
float scale = client::config["engine"]["ext"]["vulkan"]["framebuffer"]["size"].is<double>() ? client::config["engine"]["ext"]["vulkan"]["framebuffer"]["size"].as<float>() : 1; float scale = client::config["engine"]["ext"]["vulkan"]["framebuffer"]["size"].as<float>( 1 );
uf::renderer::settings::width = payload.window.size.x * scale; uf::renderer::settings::width = payload.window.size.x * scale;
uf::renderer::settings::height = payload.window.size.y * scale; uf::renderer::settings::height = payload.window.size.y * scale;
} }
uf::renderer::states::resized = true; uf::renderer::states::resized = true;
} ); } );
} }
#if !UF_ENV_DREAMCAST #if !UF_ENV_DREAMCAST
if ( client::config["window"]["mode"].as<std::string>() == "fullscreen" ) client::window.switchToFullscreen(); if ( client::config["window"]["mode"].as<std::string>() == "fullscreen" ) client::window.switchToFullscreen();
if ( client::config["window"]["mode"].as<std::string>() == "borderless" ) client::window.switchToFullscreen( true ); else if ( client::config["window"]["mode"].as<std::string>() == "borderless" ) client::window.switchToFullscreen( true );
#endif #endif
client::ready = true; client::ready = true;
@ -125,18 +126,7 @@ void client::tick() {
client::window.setMousePosition(client::window.getSize()/2); client::window.setMousePosition(client::window.getSize()/2);
auto current = client::window.getMousePosition(); auto current = client::window.getMousePosition();
auto size = client::window.getSize(); auto size = client::window.getSize();
#if 0
{
uf::Serializer payload;
payload["invoker"] = "client";
payload["mouse"]["delta"] = uf::vector::encode( previous - current );
payload["mouse"]["position"] = uf::vector::encode( current );
payload["mouse"]["size"] = uf::vector::encode( size );
payload["mouse"]["state"] = "???";
payload["type"] = "window:Mouse.Moved";
uf::hooks.call("window:Mouse.Moved", payload);
}
#endif
uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{ uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{
{ {
{ {

View File

@ -2,6 +2,8 @@
#include <uf/utils/io/iostream.h> #include <uf/utils/io/iostream.h>
#include <uf/utils/time/time.h> #include <uf/utils/time/time.h>
#include <uf/utils/mesh/mesh.h>
#include <uf/utils/window/payloads.h>
#include <uf/utils/memory/pool.h> #include <uf/utils/memory/pool.h>
#include <filesystem> #include <filesystem>
@ -46,7 +48,7 @@ namespace {
} }
} }
} }
#include <uf/utils/mesh/mesh.h>
int main(int argc, char** argv){ int main(int argc, char** argv){
for ( size_t i = 0; i < argc; ++i ) { for ( size_t i = 0; i < argc; ++i ) {
char* c_str = argv[i]; char* c_str = argv[i];
@ -76,14 +78,18 @@ int main(int argc, char** argv){
#if HANDLE_EXCEPTIONS #if HANDLE_EXCEPTIONS
try { try {
#endif #endif
/*
static bool first = false; if ( !first ) { first = true; static bool first = false; if ( !first ) { first = true;
uf::Serializer json; uf::Serializer json;
std::string hook = "window:Resized"; uf::hooks.call("window:Resized", pod::payloads::windowResized{
json["type"] = hook; {
json["invoker"] = "ext"; "window:Resized",
json["window"]["size"] = client::config["window"]["size"]; "os",
uf::hooks.call(hook, json); },
{ uf::vector::decode( client::config["window"]["size"], pod::Vector2ui{} ) },
});
} }
*/
#if UF_ENV_DREAMCAST #if UF_ENV_DREAMCAST
// UF_TIMER_MULTITRACE_START("Starting"); // UF_TIMER_MULTITRACE_START("Starting");
ext::render(); ext::render();

View File

@ -53,8 +53,8 @@ namespace spec {
void pushEvent( const uf::Hooks::name_t& name, const uf::stl::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 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::Serializer& payload );
void pushEvent( const uf::Hooks::name_t& name, const uf::Hooks::argument_t& payload ); void pushEvent( const uf::Hooks::name_t& name, const pod::Hook::userdata_t& payload );
void pushEvent( const uf::Hooks::argument_t& payload ); void pushEvent( const pod::Hook::userdata_t& payload );
template<typename T> void pushEvent( const uf::Hooks::name_t& name, const T& payload ); template<typename T> void pushEvent( const uf::Hooks::name_t& name, const T& payload );
bool pollEvents( bool block = false ); bool pollEvents( bool block = false );

View File

@ -1,6 +1,6 @@
template<typename T> template<typename T>
void spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const T& payload ) { void spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const T& payload ) {
pod::Hook::userdata_t userdata; auto& event = this->m_events.emplace();
userdata.create<T>( payload ); event.name = name;
this->pushEvent( name, userdata ); event.payload.create<T>(payload);
} }

View File

@ -46,10 +46,11 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) {
} }
}); });
this->addHook( "object:Reload.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Reload.%UID%", [&](ext::json::Value& json){
this->callHook("object:UpdateMetadata.%UID%", json); this->callHook("object:Deserialize.%UID%", json);
}); });
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){
if ( ext::json::isNull( json ) ) return; if ( ext::json::isNull( json ) ) return;
if ( json["type"].as<uf::stl::string>() == "merge" ) { if ( json["type"].as<uf::stl::string>() == "merge" ) {
metadataJson.merge(json["value"], true); metadataJson.merge(json["value"], true);
} else if ( json["type"].as<uf::stl::string>() == "import" ) { } else if ( json["type"].as<uf::stl::string>() == "import" ) {
@ -99,9 +100,8 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) {
auto& metadata = this->getComponent<uf::ObjectBehavior::Metadata>(); auto& metadata = this->getComponent<uf::ObjectBehavior::Metadata>();
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
if ( ext::json::isObject(metadataJson["system"]["physics"]) ) { if ( ext::json::isObject(metadataJson["system"]["physics"]) ) {

View File

@ -53,7 +53,7 @@ void uf::GraphBehavior::initialize( uf::Object& self ) {
sceneMetadataJson["light"]["brightnessThreshold"] = graph.metadata["brightnessThreshold"]; sceneMetadataJson["light"]["brightnessThreshold"] = graph.metadata["brightnessThreshold"];
shouldUpdate = true; shouldUpdate = true;
} }
if ( shouldUpdate ) scene.callHook("object:UpdateMetadata.%UID%"); if ( shouldUpdate ) scene.callHook("object:Deserialize.%UID%");
// deferred shader loading // deferred shader loading
auto& transform = this->getComponent<pod::Transform<>>(); auto& transform = this->getComponent<pod::Transform<>>();

View File

@ -117,6 +117,11 @@ pod::Graph ext::gltf::load( const uf::stl::string& filename, const uf::Serialize
return uf::graph::load( filename, metadata ); return uf::graph::load( filename, metadata );
} }
#if UF_ENV_DREAMCAST
UF_EXCEPTION("glTF loading is highly discouraged on this platform:" << filename);
return {};
#endif
tinygltf::Model model; tinygltf::Model model;
tinygltf::TinyGLTF loader; tinygltf::TinyGLTF loader;

View File

@ -17,6 +17,7 @@ namespace binds {
else if ( type == UF_NS_GET_LAST(T) ) return sol::make_object( ext::lua::state, std::ref(self.getComponent<T>()) ); else if ( type == UF_NS_GET_LAST(T) ) return sol::make_object( ext::lua::state, std::ref(self.getComponent<T>()) );
if ( type == "Metadata" ) { if ( type == "Metadata" ) {
self.callHook( "object:Serialize.%UID%" );
auto& metadata = self.getComponent<uf::Serializer>(); auto& metadata = self.getComponent<uf::Serializer>();
auto decoded = ext::lua::decode( metadata ); auto decoded = ext::lua::decode( metadata );
if ( decoded ) { if ( decoded ) {
@ -39,11 +40,13 @@ namespace binds {
if ( type == "Metadata" ) { if ( type == "Metadata" ) {
auto encoded = ext::lua::encode( value.as<sol::table>() ); auto encoded = ext::lua::encode( value.as<sol::table>() );
if ( encoded ) { if ( encoded ) {
self.callHook( "object:Serialize.%UID%" );
auto& metadata = self.getComponent<uf::Serializer>(); auto& metadata = self.getComponent<uf::Serializer>();
uf::stl::string str = encoded.value(); uf::stl::string str = encoded.value();
uf::Serializer hooks = metadata["system"]["hooks"]; uf::Serializer hooks = metadata["system"]["hooks"];
metadata.merge( str, false ); metadata.merge( str, false );
metadata["system"]["hooks"] = hooks; metadata["system"]["hooks"] = hooks;
self.callHook( "object:Deserialize.%UID%" );
} }
} }
UF_LUA_UPDATE_COMPONENT(pod::Transform<>) UF_LUA_UPDATE_COMPONENT(pod::Transform<>)

View File

@ -59,11 +59,13 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, co
event.name = name; event.name = name;
event.payload.create<ext::json::Value>( uf::Serializer(payload) ); event.payload.create<ext::json::Value>( uf::Serializer(payload) );
} }
void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const uf::Hooks::argument_t& payload ) { void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::name_t& name, const pod::Hook::userdata_t& payload ) {
auto& event = this->m_events.emplace(); auto& event = this->m_events.emplace();
event.name = name; event.name = name;
event.payload = payload;
} }
void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::argument_t& payload ) { /*
void UF_API_CALL spec::uni::Window::pushEvent( const pod::Hook::userdata_t& payload ) {
struct Header { struct Header {
uf::stl::string type; uf::stl::string type;
}; };
@ -71,6 +73,7 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::Hooks::argument_t& payl
if ( !uf::hooks.exists(header.type) ) return; if ( !uf::hooks.exists(header.type) ) return;
this->m_events.push({ header.type, std::move(payload) }); this->m_events.push({ header.type, std::move(payload) });
} }
*/
void UF_API_CALL spec::uni::Window::processEvents() { void UF_API_CALL spec::uni::Window::processEvents() {
} }
bool UF_API_CALL spec::uni::Window::isKeyPressed(const uf::stl::string& key) { bool UF_API_CALL spec::uni::Window::isKeyPressed(const uf::stl::string& key) {

View File

@ -5,8 +5,8 @@
#include <uf/utils/window/payloads.h> #include <uf/utils/window/payloads.h>
#include <uf/utils/io/inputs.h> #include <uf/utils/io/inputs.h>
#define UF_USE_USERDATA 1 #define UF_HOOK_USE_USERDATA 1
#define UF_USE_JSON 1 #define UF_HOOK_USE_JSON 0
#if UF_ENV_WINDOWS && (!UF_USE_SFML || (UF_USE_SFML && UF_USE_SFML == 0)) #if UF_ENV_WINDOWS && (!UF_USE_SFML || (UF_USE_SFML && UF_USE_SFML == 0))
namespace { namespace {
@ -805,7 +805,7 @@ void UF_API_CALL spec::win32::Window::processEvents() {
} }
} }
}; };
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released"); json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released");
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -823,11 +823,11 @@ void UF_API_CALL spec::win32::Window::processEvents() {
event.key.code = code; event.key.code = code;
event.key.raw = key; event.key.raw = key;
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
this->pushEvent(event.type + "." + code, event); this->pushEvent(event.type + "." + code, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
json["key"]["code"] = code; json["key"]["code"] = code;
json["key"]["raw"] = key; json["key"]["raw"] = key;
this->pushEvent(event.type, json); this->pushEvent(event.type, json);
@ -847,14 +847,18 @@ bool UF_API_CALL spec::win32::Window::pollEvents( bool block ) {
auto& event = this->m_events.front(); auto& event = this->m_events.front();
if ( event.payload.is<uf::stl::string>() ) { if ( event.payload.is<uf::stl::string>() ) {
ext::json::Value payload = uf::Serializer( event.payload.as<uf::stl::string>() ); ext::json::Value payload = uf::Serializer( event.payload.as<uf::stl::string>() );
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else if ( event.payload.is<uf::Serializer>() ) { } else if ( event.payload.is<uf::Serializer>() ) {
uf::Serializer& payload = event.payload.as<uf::Serializer>(); uf::Serializer& payload = event.payload.as<uf::Serializer>();
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else if ( event.payload.is<ext::json::Value>() ) { } else if ( event.payload.is<ext::json::Value>() ) {
ext::json::Value& payload = event.payload.as<ext::json::Value>(); ext::json::Value& payload = event.payload.as<ext::json::Value>();
uf::hooks.call( "window:Event", payload );
uf::hooks.call( event.name, payload ); uf::hooks.call( event.name, payload );
} else { } else {
uf::hooks.call( "window:Event", event.payload );
uf::hooks.call( event.name, event.payload ); uf::hooks.call( event.name, event.payload );
} }
this->m_events.pop(); this->m_events.pop();
@ -945,10 +949,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
"window:Closed", "window:Closed",
"os", "os",
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -966,10 +970,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
}, },
{ this->m_lastSize }, { this->m_lastSize },
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -994,10 +998,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
}, },
{ this->m_lastSize }, { this->m_lastSize },
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1009,10 +1013,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
"window:Moved", "window:Moved",
"os", "os",
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1050,10 +1054,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
state state
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1096,10 +1100,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
uf::stl::string(utf8.begin(), utf8.end()), uf::stl::string(utf8.begin(), utf8.end()),
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1141,11 +1145,11 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
} }
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
this->pushEvent(event.type + "." + event.key.code, event); this->pushEvent(event.type + "." + event.key.code, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released"); json["type"] = event.type + "." + ((event.key.state == -1)?"Pressed":"Released");
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1181,10 +1185,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
delta, delta,
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1246,10 +1250,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
state state
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1284,10 +1288,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
-1 -1
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;
@ -1351,10 +1355,10 @@ void UF_API_CALL spec::win32::Window::processEvent(UINT message, WPARAM wParam,
0 0
} }
}; };
#if UF_USE_USERDATA #if UF_HOOK_USE_USERDATA
this->pushEvent(event.type, event); this->pushEvent(event.type, event);
#endif #endif
#if UF_USE_JSON #if UF_HOOK_USE_JSON
uf::Serializer json; uf::Serializer json;
json["type"] = event.type; json["type"] = event.type;
json["invoker"] = event.invoker; json["invoker"] = event.invoker;

View File

@ -92,10 +92,10 @@ bool uf::Image::open( const uf::stl::string& filename, bool flip ) {
uf::stl::string extension = uf::io::extension(filename); uf::stl::string extension = uf::io::extension(filename);
if ( extension != "dtex" ) { if ( extension != "dtex" ) {
uf::stl::string dtex = uf::string::replace( filename, ".png", ".dtex" ); uf::stl::string dtex = uf::string::replace( filename, ".png", ".dtex" );
if ( uf::io::exists(dtex) ) { if ( uf::io::exists(dtex) ) return this->open(dtex, flip);
// UF_MSG_DEBUG("Loading dtex instead for: " << filename);
return this->open(dtex, flip); UF_EXCEPTION("non-dtex loading is highly discouraged on this platform:" << filename);
} return false;
} }
#endif #endif
if ( !uf::io::exists(filename) ) UF_EXCEPTION("IO error: file does not exist: " + filename); if ( !uf::io::exists(filename) ) UF_EXCEPTION("IO error: file does not exist: " + filename);
@ -148,18 +148,6 @@ bool uf::Image::open( const uf::stl::string& filename, bool flip ) {
} }
} }
} else { UF_EXCEPTION("Image error: not a compressed texture: " << filename); return false; } } else { UF_EXCEPTION("Image error: not a compressed texture: " << filename); return false; }
/*
UF_MSG_DEBUG("DTEX Header: " << header.id[0] << header.id[1] << header.id[2] << header.id[3] << " | "
<< header.width << " x " << header.height << " | "
<< twiddled << " | "
<< compressed << " | "
<< mipmapped << " | "
<< strided << " | "
<< header.size << " | "
<< std::bitset<32>(format) << " | "
<< std::bitset<32>(this->m_format)
);
*/
} else } else
#endif #endif
{ {

View File

@ -51,7 +51,6 @@ namespace {
void ext::CraetureBehavior::initialize( uf::Object& self ) { void ext::CraetureBehavior::initialize( uf::Object& self ) {
this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){ this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){
if ( !uf::Asset::isExpected( payload, uf::Asset::Type::IMAGE ) ) return; if ( !uf::Asset::isExpected( payload, uf::Asset::Type::IMAGE ) ) return;
UF_MSG_DEBUG( "IMAGE: " << payload.filename );
uf::Scene& scene = uf::scene::getCurrentScene(); uf::Scene& scene = uf::scene::getCurrentScene();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>(); uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
@ -63,18 +62,13 @@ void ext::CraetureBehavior::initialize( uf::Object& self ) {
auto& metadata = this->getComponent<ext::CraetureBehavior::Metadata>(); auto& metadata = this->getComponent<ext::CraetureBehavior::Metadata>();
auto& metadataJson = this->getComponent<uf::Serializer>(); auto& metadataJson = this->getComponent<uf::Serializer>();
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
} }
void ext::CraetureBehavior::tick( uf::Object& self ) {} void ext::CraetureBehavior::tick( uf::Object& self ) {}
void ext::CraetureBehavior::render( uf::Object& self ){} void ext::CraetureBehavior::render( uf::Object& self ){}
void ext::CraetureBehavior::destroy( uf::Object& self ){} void ext::CraetureBehavior::destroy( uf::Object& self ){}
void ext::CraetureBehavior::Metadata::serialize( uf::Object& self, uf::Serializer& serializer ){ void ext::CraetureBehavior::Metadata::serialize( uf::Object& self, uf::Serializer& serializer ){}
void ext::CraetureBehavior::Metadata::deserialize( uf::Object& self, uf::Serializer& serializer ){}
}
void ext::CraetureBehavior::Metadata::deserialize( uf::Object& self, uf::Serializer& serializer ){
}
#undef this #undef this

View File

@ -99,9 +99,8 @@ void ext::LightBehavior::initialize( uf::Object& self ) {
renderMode.height = size.y; renderMode.height = size.y;
} }
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
} }
void ext::LightBehavior::tick( uf::Object& self ) { void ext::LightBehavior::tick( uf::Object& self ) {

View File

@ -118,9 +118,8 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
this->queueHook("discord.Activity.Update.%UID%", ext::json::null(), 1.0); this->queueHook("discord.Activity.Update.%UID%", ext::json::null(), 1.0);
#endif #endif
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
} }
void ext::PlayerBehavior::tick( uf::Object& self ) { void ext::PlayerBehavior::tick( uf::Object& self ) {

View File

@ -28,9 +28,8 @@ void ext::PlayerModelBehavior::initialize( uf::Object& self ) {
metadata.reference = &controllerTransform; metadata.reference = &controllerTransform;
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
} }
void ext::PlayerModelBehavior::tick( uf::Object& self ) { void ext::PlayerModelBehavior::tick( uf::Object& self ) {

View File

@ -194,9 +194,8 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) {
} }
#endif #endif
this->addHook( "object:UpdateMetadata.%UID%", [&]( ext::json::Value& json ){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
} }
void ext::ExtSceneBehavior::tick( uf::Object& self ) { void ext::ExtSceneBehavior::tick( uf::Object& self ) {

View File

@ -81,7 +81,6 @@ void ext::SoundEmitterBehavior::initialize( uf::Object& self ) {
}); });
this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){ this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){
if ( !uf::Asset::isExpected( payload, uf::Asset::Type::AUDIO ) ) return; if ( !uf::Asset::isExpected( payload, uf::Asset::Type::AUDIO ) ) return;
UF_MSG_DEBUG( "AUDIO: " << payload.filename );
if ( !assetLoader.has<uf::Audio>(payload.filename) ) return; if ( !assetLoader.has<uf::Audio>(payload.filename) ) return;

View File

@ -61,6 +61,8 @@ namespace {
"uv", "uv",
"weight", "weight",
"world", "world",
"clickable",
"hoverable"
}; };
} }
uf::stl::vector<pod::GlyphBox> ext::Gui::generateGlyphs( const uf::stl::string& _string ) { uf::stl::vector<pod::GlyphBox> ext::Gui::generateGlyphs( const uf::stl::string& _string ) {
@ -428,9 +430,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
auto& metadata = this->getComponent<ext::GuiBehavior::Metadata>(); auto& metadata = this->getComponent<ext::GuiBehavior::Metadata>();
auto& metadataJson = this->getComponent<uf::Serializer>(); auto& metadataJson = this->getComponent<uf::Serializer>();
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){ this->addHook( "asset:Load.%UID%", [&](pod::payloads::assetLoad& payload){
@ -442,15 +443,57 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
auto& image = assetLoader.get<uf::Image>(payload.filename); auto& image = assetLoader.get<uf::Image>(payload.filename);
this->as<ext::Gui>().load( image ); this->as<ext::Gui>().load( image );
}); });
if ( metadataJson["system"]["clickable"].as<bool>() ) {
if ( metadata.clickable ) {
uf::Timer<long long> clickTimer(false); uf::Timer<long long> clickTimer(false);
clickTimer.start( uf::Time<>(-1000000) ); clickTimer.start( uf::Time<>(-1000000) );
if ( !clickTimer.running() ) clickTimer.start(); if ( !clickTimer.running() ) clickTimer.start();
this->addHook( "window:Mouse.Click", [&](pod::payloads::windowMouseClick& payload){
if ( metadata.world ) return;
if ( !metadata.box.min && !metadata.box.max ) return;
bool clicked = false;
if ( payload.mouse.state == -1 ) {
pod::Vector2f click;
click.x = (float) payload.mouse.position.x / (float) ext::gui::size.current.x;
click.y = (float) payload.mouse.position.y / (float) ext::gui::size.current.y;
click.x = (click.x * 2.0f) - 1.0f;
click.y = (click.y * 2.0f) - 1.0f;
float x = click.x;
float y = click.y;
if (payload.invoker == "vr" ) {
x = payload.mouse.position.x;
y = payload.mouse.position.y;
}
clicked = ( metadata.box.min.x <= x && metadata.box.min.y <= y && metadata.box.max.x >= x && metadata.box.max.y >= y );
int minX = (metadata.box.min.x * 0.5f + 0.5f) * ext::gui::size.current.x;
int minY = (metadata.box.min.y * 0.5f + 0.5f) * ext::gui::size.current.y;
int maxX = (metadata.box.max.x * 0.5f + 0.5f) * ext::gui::size.current.x;
int maxY = (metadata.box.max.y * 0.5f + 0.5f) * ext::gui::size.current.y;
int mouseX = payload.mouse.position.x;
int mouseY = payload.mouse.position.y;
}
metadata.clicked = clicked;
if ( clicked ) this->callHook("gui:Clicked.%UID%", payload);
this->callHook("gui:Mouse.Clicked.%UID%", payload);
} );
this->addHook( "gui:Clicked.%UID%", [&](pod::payloads::windowMouseClick& payload){ this->addHook( "gui:Clicked.%UID%", [&](pod::payloads::windowMouseClick& payload){
UF_MSG_DEBUG("CLICKED");
if ( ext::json::isObject( metadataJson["events"]["click"] ) ) { if ( ext::json::isObject( metadataJson["events"]["click"] ) ) {
uf::Serializer event = metadataJson["events"]["click"]; uf::Serializer event = metadataJson["events"]["click"];
metadataJson["events"]["click"] = ext::json::array(); //Json::arrayValue; metadataJson["events"]["click"] = ext::json::array();
metadataJson["events"]["click"][0] = event; metadataJson["events"]["click"][0] = event;
} else if ( !ext::json::isArray( metadataJson["events"]["click"] ) ) { } else if ( !ext::json::isArray( metadataJson["events"]["click"] ) ) {
this->getParent().as<uf::Object>().callHook("gui:Clicked.%UID%", payload); this->getParent().as<uf::Object>().callHook("gui:Clicked.%UID%", payload);
@ -466,39 +509,47 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
} }
} }
}); });
this->addHook( "window:Mouse.Click", [&](pod::payloads::windowMouseClick& payload){ }
if ( metadata.hoverable ) {
uf::Timer<long long> hoverTimer(false);
hoverTimer.start( uf::Time<>(-1000000) );
this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload){
if ( metadata.world ) return; if ( metadata.world ) return;
if ( !metadata.box.min && !metadata.box.max ) return; if ( !metadata.box.min && !metadata.box.max ) return;
bool clicked = false; bool hovered = false;
if ( payload.mouse.state == -1 ) { pod::Vector2f click;
pod::Vector2f click; {
click.x = (float) payload.mouse.position.x / (float) ext::gui::size.current.x; click.x = (float) payload.mouse.position.x / (float) ext::gui::size.current.x;
click.y = (float) payload.mouse.position.y / (float) ext::gui::size.current.y; click.y = (float) payload.mouse.position.y / (float) ext::gui::size.current.y;
click.x = (click.x * 2.0f) - 1.0f; click.x = (click.x * 2.0f) - 1.0f;
click.y = (click.y * 2.0f) - 1.0f; click.y = (click.y * 2.0f) - 1.0f;
float x = click.x; float x = click.x;
float y = click.y; float y = click.y;
if (payload.invoker == "vr" ) { hovered = ( metadata.box.min.x <= x && metadata.box.min.y <= y && metadata.box.max.x >= x && metadata.box.max.y >= y );
x = payload.mouse.position.x;
y = payload.mouse.position.y; if ( hovered ) {
} int minX = (metadata.box.min.x * 0.5f + 0.5f) * ext::gui::size.current.x;
clicked = ( metadata.box.min.x <= x && metadata.box.min.y <= y && metadata.box.max.x >= x && metadata.box.max.y >= y ); int minY = (metadata.box.min.y * 0.5f + 0.5f) * ext::gui::size.current.y;
int maxX = (metadata.box.max.x * 0.5f + 0.5f) * ext::gui::size.current.x;
int maxY = (metadata.box.max.y * 0.5f + 0.5f) * ext::gui::size.current.y;
int mouseX = payload.mouse.position.x;
int mouseY = payload.mouse.position.y;
} }
metadata.hovered = hovered;
if ( hovered && hoverTimer.elapsed().asDouble() >= 1 ) {
hoverTimer.reset();
this->callHook("gui:Hovered.%UID%", payload);
} }
metadata.clicked = clicked; this->callHook("gui:Mouse.Moved.%UID%", payload);
metadataJson["clicked"] = clicked; });
if ( clicked ) this->callHook("gui:Clicked.%UID%", payload);
this->callHook("gui:Mouse.Clicked.%UID%", payload);
} );
}
if ( metadataJson["system"]["hoverable"].as<bool>() ) {
uf::Timer<long long> hoverTimer(false);
hoverTimer.start( uf::Time<>(-1000000) );
this->addHook( "gui:Hovered.%UID%", [&](ext::json::Value& json){ this->addHook( "gui:Hovered.%UID%", [&](ext::json::Value& json){
if ( ext::json::isObject( metadataJson["events"]["hover"] ) ) { if ( ext::json::isObject( metadataJson["events"]["hover"] ) ) {
uf::Serializer event = metadataJson["events"]["hover"]; uf::Serializer event = metadataJson["events"]["hover"];
@ -520,35 +571,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
} }
return; return;
}); });
this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload){
if ( this->getUid() == 0 ) return;
if ( !this->hasComponent<uf::Mesh>() ) return;
if ( metadata.world ) return;
if ( !metadata.box.min && !metadata.box.max ) return;
bool clicked = false;
bool down = payload.mouse.state == -1;
pod::Vector2f click; {
click.x = (float) payload.mouse.position.x / (float) ext::gui::size.current.x;
click.y = (float) payload.mouse.position.y / (float) ext::gui::size.current.y;
click.x = (click.x * 2.0f) - 1.0f;
click.y = (click.y * 2.0f) - 1.0f;
float x = click.x;
float y = click.y;
clicked = ( metadata.box.min.x <= x && metadata.box.min.y <= y && metadata.box.max.x >= x && metadata.box.max.y >= y );
} }
metadata.hovered = clicked;
if ( clicked && hoverTimer.elapsed().asDouble() >= 1 ) {
hoverTimer.reset();
this->callHook("gui:Hovered.%UID%", payload);
}
this->callHook("gui:Mouse.Moved.%UID%", payload);
} );
}
#if UF_USE_FREETYPE #if UF_USE_FREETYPE
if ( metadataJson["text settings"]["string"].is<uf::stl::string>() ) { if ( metadataJson["text settings"]["string"].is<uf::stl::string>() ) {
if ( ext::json::isNull( ::defaultSettings["metadata"] ) ) ::defaultSettings.readFromFile(uf::io::root+"/entities/gui/text/string.json"); if ( ext::json::isNull( ::defaultSettings["metadata"] ) ) ::defaultSettings.readFromFile(uf::io::root+"/entities/gui/text/string.json");
@ -559,9 +583,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
}); });
auto& metadataGlyph = this->getComponent<ext::GuiBehavior::GlyphMetadata>(); auto& metadataGlyph = this->getComponent<ext::GuiBehavior::GlyphMetadata>();
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadataGlyph.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
// metadataGlyph.deserialize(self, metadataJson); // metadataGlyph.deserialize(self, metadataJson);
this->addHook( "object:Reload.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Reload.%UID%", [&](ext::json::Value& json){
@ -727,7 +750,7 @@ void ext::GuiBehavior::tick( uf::Object& self ) {
if ( !graphic.initialized ) return; if ( !graphic.initialized ) return;
bool isGlyph = this->hasComponent<ext::GuiBehavior::GlyphMetadata>(); bool isGlyph = this->hasComponent<ext::GuiBehavior::GlyphMetadata>();
#if 0 && UF_USE_OPENGL #if UF_USE_OPENGL
auto model = uf::matrix::identity(); auto model = uf::matrix::identity();
auto uniformBuffer = graphic.getUniform(); auto uniformBuffer = graphic.getUniform();
pod::Uniform& uniform = *((pod::Uniform*) graphic.device->getBuffer(uniformBuffer.buffer)); pod::Uniform& uniform = *((pod::Uniform*) graphic.device->getBuffer(uniformBuffer.buffer));
@ -833,6 +856,24 @@ void ext::GuiBehavior::tick( uf::Object& self ) {
pod::Vector2f min = { 1, 1 }; pod::Vector2f min = { 1, 1 };
pod::Vector2f max = { -1, -1 }; pod::Vector2f max = { -1, -1 };
if ( this->hasComponent<uf::Mesh>() ) {
auto& mesh = this->getComponent<uf::Mesh>();
uf::Mesh::Attribute vertexAttribute;
for ( auto& attribute : mesh.vertex.attributes ) if ( attribute.descriptor.name == "position" ) { vertexAttribute = attribute; break; }
UF_ASSERT( vertexAttribute.descriptor.name == "position" );
for ( auto i = 0; i < mesh.vertex.count; ++i ) {
float* p = (float*) (vertexAttribute.pointer + i * vertexAttribute.stride );
pod::Vector4f position = { p[0], p[1], 0, 1 };
pod::Vector4f translated = uf::matrix::multiply<float>( model, position );
min.x = std::min( min.x, translated.x );
max.x = std::max( max.x, translated.x );
min.y = std::min( min.y, translated.y );
max.y = std::max( max.y, translated.y );
}
}
/* /*
if ( this->hasComponent<ext::Gui::mesh_t>() ) { if ( this->hasComponent<ext::Gui::mesh_t>() ) {
auto& mesh = this->getComponent<ext::Gui::mesh_t>(); auto& mesh = this->getComponent<ext::Gui::mesh_t>();
@ -877,7 +918,9 @@ void ext::GuiBehavior::Metadata::serialize( uf::Object& self, uf::Serializer& se
else if ( mode == 3 ) serializer["gui"]["projection"] = true; else if ( mode == 3 ) serializer["gui"]["projection"] = true;
serializer["box"]["min"] = uf::vector::encode( box.min ); serializer["box"]["min"] = uf::vector::encode( box.min );
serializer["box"]["max"] = uf::vector::encode( box.max ); serializer["box"]["max"] = uf::vector::encode( box.max );
serializer["gui"]["clickable"] = clickable;
serializer["gui"]["clicked"] = clicked; serializer["gui"]["clicked"] = clicked;
serializer["gui"]["hoverable"] = hoverable;
serializer["gui"]["hovered"] = hovered; serializer["gui"]["hovered"] = hovered;
serializer["gui"]["uv"] = uf::vector::encode( uv ); serializer["gui"]["uv"] = uf::vector::encode( uv );
serializer["gui"]["shader"] = shader; serializer["gui"]["shader"] = shader;
@ -906,7 +949,9 @@ void ext::GuiBehavior::Metadata::deserialize( uf::Object& self, uf::Serializer&
else if ( serializer["gui"]["projection"].as<bool>() ) mode = 3; else if ( serializer["gui"]["projection"].as<bool>() ) mode = 3;
box.min = uf::vector::decode( serializer["box"]["min"], box.min ); box.min = uf::vector::decode( serializer["box"]["min"], box.min );
box.max = uf::vector::decode( serializer["box"]["max"], box.max ); box.max = uf::vector::decode( serializer["box"]["max"], box.max );
clickable = serializer["gui"]["clickable"].as<bool>();
clicked = serializer["gui"]["clicked"].as<bool>(); clicked = serializer["gui"]["clicked"].as<bool>();
hoverable = serializer["gui"]["hoverable"].as<bool>();
hovered = serializer["gui"]["hovered"].as<bool>(); hovered = serializer["gui"]["hovered"].as<bool>();
uv = uf::vector::decode( serializer["gui"]["uv"], uv ); uv = uf::vector::decode( serializer["gui"]["uv"], uv );
shader = serializer["gui"]["shader"].as<int>(); shader = serializer["gui"]["shader"].as<int>();

View File

@ -20,7 +20,9 @@ namespace ext {
pod::Vector2f min = { 1, 1 }; pod::Vector2f min = { 1, 1 };
pod::Vector2f max = { -1, -1 }; pod::Vector2f max = { -1, -1 };
} box; } box;
bool clickable = false;
bool clicked = false; bool clicked = false;
bool hoverable = false;
bool hovered = false; bool hovered = false;
pod::Vector4f uv = {0, 0, 1, 1}; pod::Vector4f uv = {0, 0, 1, 1};

View File

@ -63,6 +63,7 @@ void ext::GuiManagerBehavior::initialize( uf::Object& self ) {
auto& metadata = controller.getComponent<ext::GuiManagerBehavior::Metadata>(); auto& metadata = controller.getComponent<ext::GuiManagerBehavior::Metadata>();
auto& metadataJson = controller.getComponent<uf::Serializer>(); auto& metadataJson = controller.getComponent<uf::Serializer>();
ext::gui::size.current = uf::vector::decode( ext::config["window"]["size"], pod::Vector2f{} );
this->addHook( "window:Resized", [&](pod::payloads::windowResized& payload){ this->addHook( "window:Resized", [&](pod::payloads::windowResized& payload){
ext::gui::size.current = payload.window.size; ext::gui::size.current = payload.window.size;
// ext::gui::size.reference = payload.window.size; // ext::gui::size.reference = payload.window.size;
@ -70,22 +71,20 @@ void ext::GuiManagerBehavior::initialize( uf::Object& self ) {
this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload){ this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload){
bool clicked = false; bool clicked = false;
pod::Vector2f click; { pod::Vector2f click;
click.x = (float) payload.mouse.position.x / (float) ext::gui::size.current.x; click.x = (float) payload.mouse.position.x / (float) ext::gui::size.current.x;
click.y = (float) payload.mouse.position.y / (float) ext::gui::size.current.y; click.y = (float) payload.mouse.position.y / (float) ext::gui::size.current.y;
click.x = (click.x * 2.0f) - 1.0f; click.x = (click.x * 2.0f) - 1.0f;
click.y = (click.y * 2.0f) - 1.0f; click.y = (click.y * 2.0f) - 1.0f;
float x = click.x; float x = click.x;
float y = click.y; float y = click.y;
}
if ( metadata.overlay.cursor.type == "mouse" ) { if ( metadata.overlay.cursor.type == "mouse" ) {
metadata.overlay.cursor.position = click; metadata.overlay.cursor.position = click;
} }
}); });
this->addHook( "object:UpdateMetadata.%UID%", [&](ext::json::Value& json){ this->addHook( "object:Serialize.%UID%", [&](ext::json::Value& json){ metadata.serialize(self, metadataJson); });
metadata.deserialize(self, metadataJson); this->addHook( "object:Deserialize.%UID%", [&](ext::json::Value& json){ metadata.deserialize(self, metadataJson); });
});
metadata.deserialize(self, metadataJson); metadata.deserialize(self, metadataJson);
} }
void ext::GuiManagerBehavior::tick( uf::Object& self ) { void ext::GuiManagerBehavior::tick( uf::Object& self ) {