Commit for 2020.09.26.7z

This commit is contained in:
mrq 2020-09-26 00:00:00 -05:00
parent 177bc46065
commit 0b88b27065
74 changed files with 1390 additions and 445 deletions

View File

@ -44,8 +44,8 @@ layout (binding = 0) uniform UBO {
} ubo;
void fog( inout vec3 i ) {
vec3 color = vec3( 0, 0, 0 );
float inner = 8, outer = 64;
vec3 color = vec3( 0.1, 0.1, 0.1 );
float inner = 4, outer = 32;
float distance = length(-position.eye);
float factor = (distance - inner) / (outer - inner);
factor = clamp( factor, 0.0, 1.0 );

View File

@ -3,6 +3,8 @@
#include <uf/utils/io/iostream.h>
#include <uf/utils/time/time.h>
#include <uf/utils/mempool/mempool.h>
int main(int argc, char** argv){
std::atexit([]{
uf::iostream << "Termination via std::atexit()!" << "\n";

View File

@ -6,13 +6,14 @@
#include <vector>
#include <functional>
#include <uf/utils/mempool/mempool.h>
namespace uf {
class UF_API Entity : public uf::Component {
public:
typedef std::vector<uf::Entity*> container_t;
protected:
static uf::Entity null;
static std::vector<uf::Entity*> entities;
static std::size_t uids;
uf::Entity* m_parent = NULL;
@ -21,6 +22,7 @@ namespace uf {
std::size_t m_uid = 0;
std::string m_name = "Entity";
public:
static uf::MemoryPool memoryPool;
Entity( bool = false );
virtual ~Entity();
@ -45,6 +47,9 @@ namespace uf {
virtual void tick();
virtual void render();
void* operator new(size_t, const std::string& = "");
void operator delete(void*);
template<typename T=uf::Entity> void initialize();
template<typename T=uf::Entity> void destroy();
template<typename T=uf::Entity> void tick();
@ -58,37 +63,8 @@ namespace uf {
void process( std::function<void(uf::Entity*, int)>, int depth = 0 );
// void process( std::function<void(const uf::Entity*)> ) const ;
// void process( std::function<void(const uf::Entity*, int)>, int depth = 0 ) const;
static uf::Entity* globalFindByUid( size_t id );
static uf::Entity* globalFindByName( const std::string& name );
};
/*
namespace uf {
class UF_API Entity : public uf::Component {
public:
typedef std::vector<uf::Entity*> container_t;
protected:
static uf::Entity null;
uf::Entity* m_parent = NULL;
uf::Entity::container_t m_children;
public:
Entity();
virtual ~Entity();
template<typename T=uf::Entity> T& getParent();
template<typename T=uf::Entity> T& getRootParent();
template<typename T=uf::Entity> const T& getParent() const;
template<typename T=uf::Entity> const T& getRootParent() const;
void setParent( uf::Entity& parent = null );
void addChild( uf::Entity& child );
virtual void initialize();
virtual void destroy();
virtual void tick();
virtual void render();
};
*/
}
#include "entity.inl"

View File

@ -27,26 +27,17 @@ namespace uf {
extern UF_API std::unordered_map<std::type_index, std::string>* names;
extern UF_API std::unordered_map<std::string, function_t>* map;
template<typename T>
void add( const std::string& name ) {
if ( !names ) names = new std::unordered_map<std::type_index, std::string>;
if ( !map ) map = new std::unordered_map<std::string, function_t>;
auto& names = *uf::instantiator::names;
auto& map = *uf::instantiator::map;
names[std::type_index(typeid(T))] = name;
map[name] = [](){
return new T;
};
std::cout << "Registered instantiation for " << name << std::endl;
}
uf::Entity* UF_API alloc( size_t );
void UF_API free( uf::Entity* );
uf::Entity* UF_API instantiate( const std::string& );
template<typename T>
T& instantiate() {
auto& names = *uf::instantiator::names;
return *((T*) uf::instantiator::instantiate( names[std::type_index(typeid(T))] ));
}
template<typename T> void add( const std::string& name );
template<typename T> T* alloc();
template<typename T> T& instantiate( size_t size );
template<typename T> T& instantiate();
template<typename T> T* _instantiate();
};
}
}
#include "instantiator.inl"

View File

@ -0,0 +1,32 @@
template<typename T>
T* uf::instantiator::alloc() {
return (T*) alloc( sizeof(T) );
// return new T;
}
template<typename T>
void uf::instantiator::add( const std::string& name ) {
if ( !names ) names = new std::unordered_map<std::type_index, std::string>;
if ( !map ) map = new std::unordered_map<std::string, function_t>;
auto& names = *uf::instantiator::names;
auto& map = *uf::instantiator::map;
names[std::type_index(typeid(T))] = name;
map[name] = _instantiate<T>;
std::cout << "Registered instantiation for " << name << std::endl;
}
template<typename T>
T& uf::instantiator::instantiate( size_t size ) {
T* entity = alloc<T>();
::new (entity) T();
return *entity;
}
template<typename T>
T& uf::instantiator::instantiate() {
return instantiate<T>( sizeof(T) );
}
template<typename T>
T* uf::instantiator::_instantiate() {
return &instantiate<T>( sizeof(T) );
}

View File

@ -0,0 +1,7 @@
#pragma once
#if defined(UF_USE_VULKAN) && UF_USE_VULKAN == 1
#include "vulkan.h"
#elif defined(UF_USE_OPENGL) && UF_USE_OPENGL == 1
#include "opengl.h"
#endif

View File

@ -0,0 +1,13 @@
#pragma once
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/graphic.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/ext/vulkan/rendermodes/deferred.h>
#include <uf/ext/vulkan/rendermodes/compute.h>
#include <uf/ext/vulkan/rendermodes/stereoscopic_deferred.h>
#include <uf/ext/vulkan/rendertarget.h>
namespace spec {
namespace renderer = ext::vulkan;
}

View File

@ -19,6 +19,7 @@ namespace pod {
}
namespace uf {
namespace component {
extern UF_API uf::MemoryPool memoryPool;
template<typename T> pod::Component::id_t type();
template<typename T> bool is( const pod::Component& );
}

View File

@ -86,7 +86,14 @@ template<typename T> T& uf::Component::addComponent( const T& data ) {
pod::Component::id_t id = this->getType<T>();
pod::Component& component = this->m_container[id];
component.userdata = uf::userdata::create(data);
component.userdata = uf::userdata::create(uf::component::memoryPool, data);
/*
if ( uf::component::memoryPool.size() > 0 ) {
component.userdata = uf::userdata::create(uf::component::memoryPool, data);
} else {
component.userdata = uf::userdata::create(data);
}
*/
component.id = id;
T* pointer = &uf::userdata::get<T>(component.userdata);
@ -96,5 +103,21 @@ template<typename T> void uf::Component::deleteComponent() {
if ( !this->hasComponent<T>() ) return;
pod::Component::id_t id = this->getType<T>();
pod::Component& component = this->m_container[id];
uf::userdata::destroy(component.userdata);
uf::userdata::destroy(uf::component::memoryPool, component.userdata);
/*
if ( uf::component::memoryPool.size() > 0 ) {
uf::userdata::destroy(component.userdata);
} else {
uf::userdata::destroy(uf::component::memoryPool, component.userdata);
}
*/
// uf::userdata::destroy(uf::component::memoryPool, component.userdata);
/*
if ( component.userdata->pointer ) {
uf::userdata::destroy(uf::component::memoryPool, component.userdata);
} else {
uf::userdata::destroy(component.userdata);
}
*/
}

View File

@ -0,0 +1,72 @@
#pragma once
#include <uf/config.h>
#include <stdint.h>
#include <vector>
#include <string>
#include <mutex>
#define UF_MEMORYPOOL_MUTEX 1
#define UF_MEMORYPOOL_INVALID_MALLOC 0
#define UF_MEMORYPOOL_INVALID_FREE 0
#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE 0
namespace pod {
struct UF_API Userdata;
struct UF_API Allocation {
size_t index = 0;
size_t size = 0;
void* pointer = NULL;
};
}
namespace uf {
class UF_API MemoryPool {
protected:
size_t m_size;
uint8_t* m_pool;
std::mutex m_mutex;
typedef std::vector<pod::Allocation> allocations_t;
allocations_t m_allocations;
public:
static bool globalOverride;
static bool subPool;
static MemoryPool global;
MemoryPool( size_t = 0 );
~MemoryPool();
size_t size() const;
size_t allocated() const;
std::string stats() const;
void initialize( size_t );
void destroy();
pod::Allocation allocate( void*, size_t );
void* alloc( void*, size_t );
inline void* alloc( size_t size, void* data = NULL ) { return alloc(data, size); }
pod::Allocation& fetch( size_t, size_t = 0 );
bool exists( void*, size_t = 0 );
bool free( void*, size_t = 0 );
template<typename T> T& alloc( const T& = T() );
template<typename T> pod::Allocation allocate( const T& = T() );
template<typename T> bool exists( const T& = T() );
template<typename T> bool free( const T& = T() );
const allocations_t& allocations() const;
/*
struct Iterator {
uf::MemoryPool& pool;
pod::Allocation& allocation;
pod::Allocation& next;
pod::Allocation& prev;
};
Iterator begin();
Iterator end();
*/
};
}
#include "mempool.inl"

View File

@ -0,0 +1,33 @@
template<typename T>
T& uf::MemoryPool::alloc( const T& data ) {
auto allocation = this->allocate( data );
union {
uint8_t* from;
T* to;
} static kludge;
return *kludge.to;
}
template<typename T>
pod::Allocation uf::MemoryPool::allocate( const T& data ) {
auto allocation = this->allocate( NULL, sizeof(data) );
if ( !allocation.pointer ) return allocation;
union {
uint8_t* from;
T* to;
} static kludge;
kludge.from = (uint8_t*) allocation.pointer;
::new (kludge.to) T(data);
return allocation;
}
template<typename T>
bool uf::MemoryPool::exists( const T& data ) {
if ( std::is_pointer<T>::value ) return this->exists( (void*) data );
return this->exists( (void*) &data, sizeof(data) );
// return this->exists( (void*) (std::is_pointer<T>::value ? data : &data), sizeof(data) );
}
template<typename T>
bool uf::MemoryPool::free( const T& data ) {
if ( std::is_pointer<T>::value ) return this->free( (void*) data );
return this->free( (void*) &data, sizeof(data) );
// return this->free( (void*) (std::is_pointer<T>::value ? data : &data), sizeof(data) );
}

View File

@ -0,0 +1,7 @@
#pragma once
#include <uf/spec/renderer/universal.h>
namespace uf {
namespace renderer = spec::renderer;
}

View File

@ -0,0 +1,13 @@
#pragma once
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/graphic.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/ext/vulkan/rendermodes/deferred.h>
#include <uf/ext/vulkan/rendermodes/compute.h>
#include <uf/ext/vulkan/rendermodes/stereoscopic_deferred.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
namespace uf {
namespace renderer = ext::vulkan;
}

View File

@ -6,7 +6,6 @@
namespace uf {
namespace string {
std::string UF_API filename( const std::string& );
std::string UF_API extension( const std::string& );
std::string UF_API directory( const std::string& );

View File

@ -1,11 +1,17 @@
#pragma once
#include <uf/config.h>
#include <uf/utils/mempool/mempool.h>
#include <stdint.h>
#include <cstddef>
#include <string>
#include <algorithm>
#define UF_USERDATA_POOLED 0
#define UF_USERDATA_KLUDGE 0
namespace pod {
struct UF_API Userdata {
std::size_t len = 0;
@ -15,8 +21,9 @@ namespace pod {
namespace uf {
namespace userdata {
pod::Userdata* UF_API create( std::size_t len );
pod::Userdata* UF_API create( std::size_t len, void* data );
extern UF_API uf::MemoryPool memoryPool;
pod::Userdata* UF_API create( std::size_t len, void* data = NULL );
void UF_API destroy( pod::Userdata* userdata );
template<typename T> pod::Userdata* create( const T& data = T() );
@ -28,6 +35,11 @@ namespace uf {
// void move( pod::Userdata& to, pod::Userdata&& from );
// void copy( pod::Userdata& to, const pod::Userdata& from );
// usage with MemoryPool
pod::Userdata* UF_API create( uf::MemoryPool&, std::size_t len, void* data = NULL );
template<typename T> pod::Userdata* create( uf::MemoryPool&, const T& data = T() );
void UF_API destroy( uf::MemoryPool&, pod::Userdata* userdata );
}
}

View File

@ -3,32 +3,112 @@
// Allows copy via assignment!
template<typename T>
pod::Userdata* uf::userdata::create( const T& data ) {
void* pointer = operator new( sizeof(pod::Userdata) + sizeof(uint8_t) * (sizeof data) );
return uf::userdata::create<T>( uf::userdata::memoryPool, data );
/*
if ( uf::userdata::memoryPool.size() > 0 ) {
return uf::userdata::create<T>( uf::userdata::memoryPool, data );
} else {
#if UF_USERDATA_KLUDGE
void* pointer = operator new( sizeof(pod::Userdata) + sizeof data );
pod::Userdata* userdata = (pod::Userdata*) pointer;
userdata->len = sizeof data;
//memcpy( userdata->data, &data, sizeof data );
//new (userdata->data) T(data);
userdata->pointer = NULL;
union {
uint8_t* from;
T* to;
} static kludge;
kludge.from = userdata->data;
new (kludge.to) T(data);
::new (kludge.to) T(data);
return userdata;
#else
pod::Userdata* userdata = new pod::Userdata;
userdata->len = sizeof data;
userdata->data = (uint8_t*) operator new(userdata->len);
union {
uint8_t* from;
T* to;
} static kludge;
kludge.from = userdata->data;
::new (kludge.to) T(data);
return userdata;
#endif
}
*/
}
template<typename T>
pod::Userdata* uf::userdata::create( uf::MemoryPool& requestedMemoryPool, const T& data ) {
// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : requestedMemoryPool;
#if UF_MEMORYPOOL_INVALID_MALLOC
uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global;
pod::Userdata* userdata = (pod::Userdata*) memoryPool.alloc( NULL, sizeof(pod::Userdata) + sizeof(data) );
#else
uf::MemoryPool* memoryPool = NULL;
if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool;
else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global;
pod::Userdata* userdata = NULL;
if ( memoryPool )
userdata = (pod::Userdata*) memoryPool->alloc( NULL, sizeof(pod::Userdata) + sizeof(data) );
else
userdata = (pod::Userdata*) operator new( sizeof(pod::Userdata) + sizeof(data) ); // allocate data for the userdata struct, and then some }
#endif
userdata->len = sizeof(data);
union {
uint8_t* from;
T* to;
} static kludge;
kludge.from = userdata->data;
::new (kludge.to) T(data);
return userdata;
/*
std::size_t len = sizeof data; // get size of data
// void* pointer = malloc( sizeof(pod::Userdata) + sizeof(uint8_t) * len ); // allocate data for the userdata struct, and then some
void* pointer = operator new( sizeof(pod::Userdata) + sizeof(uint8_t) * (len) ); // allocate data for the userdata struct, and then some
pod::Userdata* userdata = (pod::Userdata*) pointer;
userdata->len = len; // don't forget to store its data's length!
// Allows warningless conversion from placeholder storage type to userdata type
uf::MemoryPool* memoryPool = NULL;
if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool;
else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global;
pod::Userdata* userdata;
if ( memoryPool )
userdata = (pod::Userdata*) memoryPool->alloc( NULL, sizeof(pod::Userdata) + sizeof(data) );
else {
userdata = uf::userdata::create( requestedMemoryPool, sizeof(data), NULL );
}
userdata->len = sizeof(data);
#if UF_USERDATA_KLUDGE
userdata->pointer = NULL;
#endif
union {
uint8_t* from;
T* to;
} static kludge;
kludge.from = userdata->data;
new (kludge.to) T(data); // copy via placement new w/ copy constructor
return userdata; // return address of userdata
::new (kludge.to) T(data);
return userdata;
*/
/*
if ( uf::userdata::memoryPool.size() > 0 ) {
// pod::Userdata* userdata = uf::userdata::create( memoryPool, sizeof(pod::Userdata) + sizeof(data), NULL );
void* pointer = uf::userdata::memoryPool.alloc( NULL, sizeof(pod::Userdata) + sizeof(data) );
pod::Userdata* userdata = (pod::Userdata*) pointer;
userdata->len = sizeof(data);
#if UF_USERDATA_KLUDGE
userdata->pointer = NULL;
#endif
union {
uint8_t* from;
T* to;
} static kludge;
kludge.from = userdata->data;
::new (kludge.to) T(data);
return userdata;
} else {
if ( memoryPool.size() <= 0 ) return uf::userdata::create<T>(data);
pod::Userdata* userdata = new pod::Userdata;
auto allocation = memoryPool.allocate( data );
userdata->len = allocation.size;
#if UF_USERDATA_KLUDGE
userdata->pointer = (uint8_t*) allocation.pointer;
#else
userdata->data = (uint8_t*) allocation.pointer;
#endif
return userdata;
}
*/
}
// Easy way to get the userdata as a reference
@ -50,7 +130,7 @@ const T& uf::userdata::get( const pod::Userdata* userdata ) {
union {
uint8_t* original;
const T* casted;
} cast;
} static cast;
cast.original = userdata->data;
return *cast.casted;
}
@ -66,7 +146,7 @@ T& uf::Userdata::get() {
union {
uint8_t* original;
T* casted;
} cast;
} static cast;
cast.original = this->m_pod->data;
return *cast.casted;
}
@ -76,7 +156,7 @@ const T& uf::Userdata::get() const {
union {
uint8_t* original;
const T* casted;
} cast;
} static cast;
cast.original = this->m_pod->data;
return *cast.casted;
}

View File

@ -1,11 +1,11 @@
#include <uf/engine/entity/entity.h>
#include <uf/engine/instantiator/instantiator.h>
#include <uf/utils/io/iostream.h>
uf::Entity uf::Entity::null;
std::vector<uf::Entity*> uf::Entity::entities;
std::size_t uf::Entity::uids = 0;
uf::Entity::Entity(bool shouldInitialize){
uf::MemoryPool uf::Entity::memoryPool;
uf::Entity::Entity( bool shouldInitialize ){
if ( shouldInitialize ) this->initialize();
}
uf::Entity::~Entity(){
@ -26,15 +26,10 @@ uf::Entity& uf::Entity::addChild( uf::Entity& child ) {
return child;
}
void uf::Entity::removeChild( uf::Entity& child ) {
for ( uf::Entity::container_t::iterator it = this->m_children.begin(); it != this->m_children.end(); ++it ) {
uf::Entity* entity = *it;
if ( &child == entity ) {
*it = NULL;
it = this->m_children.erase( it );
child.setParent();
return;
}
}
auto it = std::find( this->m_children.begin(), this->m_children.end(), &child );
if ( it == this->m_children.end() ) return;
this->m_children.erase(it);
child.setParent();
}
void uf::Entity::moveChild( uf::Entity& child ) {
if ( !child.m_parent ) return;
@ -55,10 +50,7 @@ std::size_t uf::Entity::getUid() const {
return this->m_uid;
}
void uf::Entity::initialize(){
if ( this->m_uid == 0 ) {
uf::Entity::entities.push_back(this);
this->m_uid = ++uf::Entity::uids;
}
if ( this->m_uid == 0 ) this->m_uid = ++uf::Entity::uids;
}
void uf::Entity::destroy(){
for ( uf::Entity* kv : this->m_children ) {
@ -66,18 +58,14 @@ void uf::Entity::destroy(){
if ( kv->getUid() == 0 ) continue;
kv->destroy();
kv->setParent();
delete kv;
}
this->m_children.clear();
{
auto it = std::find(uf::Entity::entities.begin(), uf::Entity::entities.end(), this);
if ( it != uf::Entity::entities.end() ) {
uf::Entity::entities.erase(it);
// *it = NULL;
}
}
this->m_uid = 0;
/*
auto it = std::find(uf::Entity::entities.begin(), uf::Entity::entities.end(), this);
if ( it != uf::Entity::entities.end() ) uf::Entity::entities.erase(it);
*/
}
void uf::Entity::tick(){
for ( uf::Entity* kv : this->m_children ) {
@ -94,6 +82,13 @@ void uf::Entity::render(){
}
}
void* uf::Entity::operator new(size_t size, const std::string& type ) {
return type != "" && size == sizeof(uf::Entity) ? uf::instantiator::instantiate( type ) : uf::instantiator::alloc( size );
}
void uf::Entity::operator delete( void* pointer ) {
uf::instantiator::free( (uf::Entity*) pointer );
}
uf::Entity* uf::Entity::findByName( const std::string& name ) {
for ( uf::Entity* entity : this->getChildren() ) {
if ( entity->getName() == name ) return entity;
@ -158,11 +153,25 @@ void uf::Entity::process( std::function<void(const uf::Entity*, int)> fn, int de
}
}
*/
uf::Entity* uf::Entity::globalFindByUid( size_t uid ) {
for ( auto& allocation : uf::Entity::memoryPool.allocations() ) {
uf::Entity* entity = (uf::Entity*) allocation.pointer;
if ( entity->getUid() == uid ) return entity;
}
return NULL;
}
uf::Entity* uf::Entity::globalFindByName( const std::string& name ) {
for ( auto& allocation : uf::Entity::memoryPool.allocations() ) {
uf::Entity* entity = (uf::Entity*) allocation.pointer;
if ( entity->getUid() == 0 ) continue;
if ( entity->getName() == name ) return entity;
}
/*
for ( uf::Entity* e : uf::Entity::entities ) {
if ( !e ) continue;
if ( e->getUid() == 0 ) continue;
if ( e->getName() == name ) return e;
}
*/
return NULL;
}

View File

@ -4,9 +4,61 @@
std::unordered_map<std::type_index, std::string>* uf::instantiator::names = NULL;
std::unordered_map<std::string, uf::instantiator::function_t>* uf::instantiator::map = NULL;
uf::Entity* uf::instantiator::alloc( size_t size ) {
/*
uf::Entity* pointer = (uf::Entity*) uf::Entity::memoryPool.alloc( NULL, size );
std::cout << "malloc uf::Entity: "<< pointer <<" (size: " << size << ")" << std::endl;
return pointer;
*/
// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : uf::Entity::memoryPool;
#if UF_MEMORYPOOL_INVALID_MALLOC
uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::MemoryPool::global;
return (uf::Entity*) memoryPool.alloc( NULL, size );
#else
uf::Entity* pointer = NULL;
uf::MemoryPool* memoryPool = NULL;
if ( uf::Entity::memoryPool.size() > 0 )
memoryPool = &uf::Entity::memoryPool;
else if ( uf::MemoryPool::global.size() > 0 )
memoryPool = &uf::MemoryPool::global;
if ( memoryPool ) pointer = (uf::Entity*) memoryPool->alloc( NULL, size );
else pointer = (uf::Entity*) malloc( size );
return pointer;
#endif
/*
uf::Entity* pointer = ( memoryPool.size() <= 0 ) ? (uf::Entity*) ::malloc( size ) : (uf::Entity*) memoryPool.alloc( NULL, size );
// std::cout << "malloc uf::Entity: "<< pointer <<" (size: " << size << ")" << std::endl;
return pointer;
*/
/*
std::cout << "malloc uf::Entity (size: " << size << ")" << std::endl;
if ( memoryPool.size() <= 0 ) return (uf::Entity*) ::malloc( size );
return (uf::Entity*) memoryPool.alloc( NULL, size );
*/
}
void uf::instantiator::free( uf::Entity* pointer ) {
// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : uf::Entity::memoryPool;
#if UF_MEMORYPOOL_INVALID_FREE
uf::MemoryPool& memoryPool = uf::Entity::memoryPool.size() > 0 ? uf::Entity::memoryPool : uf::MemoryPool::global;
memoryPool.free( pointer );
#else
uf::MemoryPool* memoryPool = NULL;
if ( uf::Entity::memoryPool.size() > 0 )
memoryPool = &uf::Entity::memoryPool;
else if ( uf::MemoryPool::global.size() > 0 )
memoryPool = &uf::MemoryPool::global;
if ( memoryPool ) memoryPool->free( pointer );
else ::free( pointer );
#endif
/*
// std::cout << "free uf::Entity: " << pointer << std::endl;
if ( !uf::Entity::memoryPool.free( pointer ) )
::free(pointer);
*/
}
uf::Entity* uf::instantiator::instantiate( const std::string& name ) {
// std::cout << "instantiating " << name << std::endl;
auto& map = *uf::instantiator::map;
// assert it's already in map
assert( map.count(name) > 0 );
return map[name]();
}

View File

@ -154,7 +154,7 @@ void uf::Scene::tick() {
light.type.x = metadata["light"]["type"].asUInt64();
light.type.y = metadata["light"]["shadows"]["enabled"].asBool();
if ( !hasCompute && entity->hasComponent<ext::vulkan::RenderTargetRenderMode>() ) {
auto& renderMode = entity->getComponent<ext::vulkan::RenderTargetRenderMode>();
auto& renderTarget = renderMode.renderTarget;
@ -250,12 +250,23 @@ const uf::Entity* uf::Scene::getController() const {
return cachedController = this->findByName("Player");
// return this;
}
#include <regex>
std::vector<uf::Scene*> uf::scene::scenes;
uf::Scene& uf::scene::loadScene( const std::string& name, const std::string& filename ) {
uf::Scene* scene = (uf::Scene*) uf::instantiator::instantiate( name );
uf::scene::scenes.push_back(scene);
scene->load(filename != "" ? filename : "./scenes/"+uf::string::lowercase(name)+"/scene.json");
std::string target = name;
std::regex regex("^(TestScene_?)?(.+?)(_?Scene)?$");
std::smatch match;
if ( std::regex_search( target, match, regex ) ) {
target = match[2];
}
target = uf::string::lowercase( target );
scene->load(filename != "" ? filename : "./scenes/" + target + "/scene.json");
scene->initialize();
return *scene;
}

View File

@ -15,10 +15,11 @@ ext::vulkan::Shader::~Shader() {
if ( !aliased ) destroy();
}
*/
void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::string& filename, VkShaderStageFlagBits stage ) {
void ext::vulkan::Shader::initialize( ext::vulkan::Device& _device, const std::string& filename, VkShaderStageFlagBits stage ) {
auto& device = &_device ? _device : ext::vulkan::device;
this->device = &device;
ext::vulkan::Buffers::initialize( device );
aliased = false;
this->device = &device;
std::string spirv;
@ -61,9 +62,11 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st
auto parseResource = [&]( const spirv_cross::Resource& resource, VkDescriptorType descriptorType ) {
switch ( descriptorType ) {
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: {
auto& uniform = uniforms.emplace_back();
const auto& base_type = comp.get_type(resource.base_type_id);
uniform.create( comp.get_declared_struct_size(base_type) );
size_t size = comp.get_declared_struct_size(base_type);
if ( size <= 0 ) break;
auto& uniform = uniforms.emplace_back();
uniform.create( size );
} break;
/*
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: {
@ -96,12 +99,12 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st
#undef LOOP_RESOURCES
for ( const auto& resource : res.push_constant_buffers ) {
auto& pushConstant = pushConstants.emplace_back();
const auto& type = comp.get_type(resource.base_type_id);
size_t size = comp.get_declared_struct_size(type);
if ( size <= 0 ) continue;
auto& pushConstant = pushConstants.emplace_back();
pushConstant.create( size );
}
size_t specializationSize = 0;
for ( const auto& constant : comp.get_specialization_constants() ) {
@ -171,7 +174,7 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st
} );
}
// update uniform buffers
// update uniform buffers
for ( auto& uniform : uniforms ) {
pod::Userdata& userdata = uniform.data();
initializeBuffer(
@ -182,7 +185,6 @@ void ext::vulkan::Shader::initialize( ext::vulkan::Device& device, const std::st
false
);
}
}
void ext::vulkan::Shader::destroy() {
@ -218,12 +220,17 @@ void ext::vulkan::Pipeline::initialize( Graphic& graphic ) {
std::size_t offset = 0;
for ( auto& pushConstant : shader.pushConstants ) {
size_t len = pushConstant.data().len;
if ( len <= 0 || len > device.properties.limits.maxPushConstantsSize ) {
std::cout << "INVALID PUSH CONSTANT LEN OF : " << len << " FOR " << shader.filename << std::endl;
len = 4;
}
pushConstantRanges.push_back(ext::vulkan::initializers::pushConstantRange(
shader.descriptor.stage,
pushConstant.data().len,
len,
offset
));
offset += pushConstant.data().len;
offset += len;
}
}
for ( auto& descriptor : descriptorSetLayoutBindings ) {

View File

@ -11,8 +11,14 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::ReadableHook::name_t& n
this->m_events.readable.push({name, argument});
}
void UF_API_CALL spec::uni::Window::pushEvent( const uf::OptimalHook::name_t& name, const uf::OptimalHook::argument_t& argument ) {
if ( uf::hooks.prefersReadable() ) return;
if ( !uf::hooks.exists(name) ) return;
if ( uf::hooks.prefersReadable() ) {
uf::userdata::destroy(argument);
return;
}
if ( !uf::hooks.exists(name) ) {
uf::userdata::destroy(argument);
return;
}
this->m_events.optimal.push({name});
this->m_events.optimal.back().argument = argument;
}
@ -31,7 +37,10 @@ void UF_API_CALL spec::uni::Window::pushEvent( const uf::OptimalHook::argument_t
// Header header = userdata.get<Header>();
const Header& header = uf::userdata::get<Header>(userdata);
this->m_events.optimal.push({header.type});
if ( !uf::hooks.exists(header.type) ) return;
if ( !uf::hooks.exists(header.type) ) {
uf::userdata::destroy(userdata);
return;
}
this->m_events.optimal.back().argument = userdata;
}
void UF_API_CALL spec::uni::Window::processEvents() {

View File

@ -1,9 +1,17 @@
#include <uf/utils/component/component.h>
UF_API uf::MemoryPool uf::component::memoryPool;
uf::Component::~Component() {
for ( auto& kv : this->m_container ) {
pod::Component& component = kv.second;
uf::userdata::destroy(component.userdata);
uf::userdata::destroy(uf::component::memoryPool, component.userdata);
/*
if ( uf::component::memoryPool.size() > 0 ) {
uf::userdata::destroy(uf::component::memoryPool, component.userdata);
} else {
uf::userdata::destroy(component.userdata);
}
*/
}
}

View File

@ -0,0 +1,258 @@
#include <uf/utils/mempool/mempool.h>
#include <uf/utils/userdata/userdata.h>
#include <cstring>
#include <iostream>
#include <sstream>
#include <uf/utils/serialize/serializer.h>
namespace {
bool IGNORE_GLOBAL_MEMORYPOOL = false;
}
#define DEBUG_PRINT 0
bool uf::MemoryPool::globalOverride = true;
bool uf::MemoryPool::subPool = true;
uf::MemoryPool uf::MemoryPool::global;
uf::MemoryPool::MemoryPool( size_t size ) {
if ( size > 0 ) this->initialize( size );
}
uf::MemoryPool::~MemoryPool( ) {
this->destroy();
}
size_t uf::MemoryPool::size() const {
return this->m_size;
}
size_t uf::MemoryPool::allocated() const {
size_t allocated = 0;
for ( auto& allocation : this->m_allocations ) {
allocated += allocation.size;
}
return allocated;
}
std::string uf::MemoryPool::stats() const {
uf::Serializer metadata;
size_t size = this->size();
size_t allocated = this->allocated();
metadata["size"] = size;
metadata["used"] = allocated;
metadata["free"] = size - allocated;
metadata["objects"] = this->m_allocations.size();
{
std::stringstream ss;
ss << std::hex << (void*) this->m_pool;
metadata["pool"] = ss.str();
}
return metadata;
}
void uf::MemoryPool::initialize( size_t size ) {
if ( size <= 0 ) return;
if ( this->size() > 0 ) this->destroy();
// this->m_pool = (uint8_t*) malloc( size );
// this->m_allocations.reserve( 128 );
this->m_size = size;
if ( uf::MemoryPool::subPool && uf::MemoryPool::global.size() > 0 && this != &uf::MemoryPool::global ) {
this->m_pool = (uint8_t*) uf::MemoryPool::global.alloc( NULL, size );
} else {
this->m_pool = (uint8_t*) malloc( size );
}
// this->m_pool = (uint8_t*) operator new( size );
memset( this->m_pool, 0, size );
}
void uf::MemoryPool::destroy() {
if ( this->size() <= 0 ) return;
// ::free(this->m_pool);
if ( uf::MemoryPool::subPool && this != &uf::MemoryPool::global ) {
uf::MemoryPool::global.free( this->m_pool );
} else {
delete[] this->m_pool;
}
this->m_size = 0;
this->m_pool = NULL;
}
pod::Allocation uf::MemoryPool::allocate( void* data, size_t size ) {
if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.lock();
// find next available allocation
// RLE-esque
size_t index = 0;
size_t len = this->size();
pod::Allocation allocation;
if ( len <= 0 ) {
if ( DEBUG_PRINT ) std::cout << "CANNOT MALLOC: " << size << ", POOL NOT INITIALIZED" << std::endl;
goto MANUAL_MALLOC;
}
// find any availble spots in-between existing allocations
{
auto next = this->m_allocations.begin();
for ( auto it = next; it != this->m_allocations.end(); ++it ) {
index = it->index + it->size;
if ( ++next == this->m_allocations.end() ) break;
if ( index < next->index ) break;
}
if ( index + size > len ) {
std::cout << "MemoryPool: " << this << ": Out of Memory!" << std::endl;
goto MANUAL_MALLOC;
}
allocation.index = index;
allocation.size = size;
allocation.pointer = &this->m_pool[0] + index;
if ( data ) memcpy( allocation.pointer, data, size );
else memset( allocation.pointer, 0, size );
IGNORE_GLOBAL_MEMORYPOOL = true;
this->m_allocations.insert(next, allocation);
IGNORE_GLOBAL_MEMORYPOOL = false;
}
goto RETURN;
MANUAL_MALLOC:
if ( UF_MEMORYPOOL_INVALID_MALLOC ) {
allocation.index = -1;
allocation.size = size;
allocation.pointer = malloc(size);
} else {
throw;
}
RETURN:
if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.unlock();
if ( DEBUG_PRINT ) std::cout << "MALLOC'd: " << allocation.pointer << ", " << allocation.size << ", " << allocation.index << std::endl;
return allocation;
}
void* uf::MemoryPool::alloc( void* data, size_t size ) {
auto allocation = this->allocate( data, size );
return allocation.pointer;
}
pod::Allocation& uf::MemoryPool::fetch( size_t index, size_t size ) {
static pod::Allocation missing;
for ( auto& allocation : this->m_allocations ) {
if ( index == allocation.index ) {
if ( (size > 0 && allocation.size == size) || (size == 0) ) return allocation;
}
}
return missing;
}
bool uf::MemoryPool::exists( void* pointer, size_t size ) {
// bound check
if ( pointer < &this->m_pool[0] ) return false;
size_t index = (uint8_t*) pointer - &this->m_pool[0];
// size check
if ( size > 0 ) {
auto& allocation = this->fetch( index, size );
return allocation.index == index && allocation.size == size;
}
return true;
}
bool uf::MemoryPool::free( void* pointer, size_t size ) {
if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.lock();
if ( this->m_size <= 0 || pointer < &this->m_pool[0] || pointer >= &this->m_pool[0] + this->m_size ) {
if ( DEBUG_PRINT ) std::cout << "CANNOT FREE: " << pointer << ", ERROR: " << (this->m_size <= 0) << " " << (pointer < &this->m_pool[0]) << " " << (pointer >= &this->m_pool[0] + this->m_size) << std::endl;
goto MANUAL_FREE;
}
{
size_t index = (uint8_t*) pointer - &this->m_pool[0];
auto it = this->m_allocations.begin();
pod::Allocation allocation;
for ( ; it != this->m_allocations.end(); ++it ) {
if ( it->index == index ) {
allocation = *it;
break;
}
}
// if ( allocation.index != index || (size > 0 && allocation.size != size) ) {
if ( allocation.index != index ) {
if ( DEBUG_PRINT ) std::cout << "CANNOT FREE: " << pointer << ", NOT FOUND" << std::endl;
goto MANUAL_FREE;
}
if (size > 0 && allocation.size != size) {
if ( DEBUG_PRINT ) std::cout << "CANNOT FREE: " << pointer << ", MISMATCHED SIZES (" << size << " != " << allocation.size << ")" << std::endl;
goto MANUAL_FREE;
}
if ( DEBUG_PRINT ) std::cout << "FREE'D ALLOCATION: " << pointer << ", " << size << "\t" << allocation.pointer << ", " << allocation.size << ", " << allocation.index << std::endl;
this->m_allocations.erase(it);
if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.unlock();
return true;
}
MANUAL_FREE:
if ( UF_MEMORYPOOL_MUTEX ) this->m_mutex.unlock();
if ( UF_MEMORYPOOL_INVALID_FREE ) ::free(pointer);
return false;
}
const uf::MemoryPool::allocations_t& uf::MemoryPool::allocations() const {
return this->m_allocations;
}
#if UF_MEMORYPOOL_OVERRIDE_NEW_DELETE
void* operator new( size_t size ) {
if ( !uf::MemoryPool::globalOverride || IGNORE_GLOBAL_MEMORYPOOL || uf::MemoryPool::global.size() <= 0 )
return malloc(size);
return uf::MemoryPool::global.alloc( (void*) NULL, size );
}
void operator delete( void* pointer ) {
if ( !uf::MemoryPool::globalOverride ) return ::free( pointer );
uf::MemoryPool::global.free( pointer );
}
#endif
/*
uf::MemoryPool::Iterator uf::MemoryPool::begin() {
static pod::Allocation end;
end = {
.index = 0
.size = 0,
.pointer = this->m_pool
};
struct {
pod::Allocation* begin = NULL;
pod::Allocation* end = NULL;
pod::Allocation* next = NULL;
} pointers;
pointers.begin = &end;
pointers.end = &end;
pointers.prev = &end;
if ( this->m_allocations.size() > 0 ) {
auto it = this->m_allocations.begin();
pointers.begin = &(*it++);
if ( it != this->m_allocations.end() )
pointers.next = &(*it);
}
return {
.pool = *this,
.allocation = *pointers.begin,
.prev = *pointers.end,
.next = *pointers.next
};
}
uf::MemoryPool::Iterator uf::MemoryPool::end() {
static pod::Allocation end;
end = {
.index = this->m_size,
.size = this->m_size,
.pointer = this->m_pool + this->m_size;
}
struct {
pod::Allocation* end = NULL;
pod::Allocation* prev = NULL;
} pointers;
if ( this->m_allocations.size() > 0 ) {
auto it = this->m_allocations.begin();
pointers.end = &(*it++);
if ( it != this->m_allocations.end() )
pointers.prev = &(*it);
}
pointers.prev = &end;
return {
.pool = *this,
.allocation = *pointers.end,
.prev = *pointers.prev,
.next = *pointers.end
};
}
*/

View File

@ -0,0 +1 @@
#include <uf/utils/renderer/renderer.h>

View File

@ -2,6 +2,7 @@
#include <uf/utils/string/base64.h> // base64
#include <cstdlib> // malloc, free
#include <cstring> // memcpy
#include <iostream>
// Description: Allows abstract creation of anything
// Use: hook subsystem for passing hook data
@ -9,24 +10,129 @@
* [?] create a singleton class to destroy any remaining userdata
*/
// Constructs a pod::Userdata struct with it's
pod::Userdata* UF_API uf::userdata::create( std::size_t len ) {
std::vector<uint8_t> empty( len, 0 );
return create( len, empty.data() );
}
uf::MemoryPool uf::userdata::memoryPool;
// Constructs a pod::Userdata struct
pod::Userdata* UF_API uf::userdata::create( std::size_t len, void* data ) {
if ( !data ) return NULL;
void* pointer = operator new( sizeof(pod::Userdata) + sizeof(uint8_t) * len ); // allocate data for the userdata struct, and then some
return uf::userdata::create( uf::userdata::memoryPool, len, data );
/*
if ( uf::userdata::memoryPool.size() > 0 ) return uf::userdata::create( uf::userdata::memoryPool, len, data );
#if UF_USERDATA_KLUDGE
void* pointer = operator new( sizeof(pod::Userdata) + len ); // allocate data for the userdata struct, and then some
// void* pointer = malloc( sizeof(pod::Userdata) + sizeof(uint8_t) * len ); // allocate data for the userdata struct, and then some
pod::Userdata& userdata = *(pod::Userdata*) pointer; // cast to reference
memcpy( userdata.data, data, len ); // copy contents from data to Userdata's data
if ( data ) memcpy( userdata.data, data, len ); // copy contents from data to Userdata's data
else memset( userdata.data, 0, len );
userdata.len = len; // don't forget to store its data's length!
userdata.pointer = NULL; //&userdata.data[0];
return &userdata; // return address of userdata
#else
pod::Userdata* userdata = new pod::Userdata;
userdata->len = len;
userdata->data = (uint8_t*) operator new(len);
if ( data ) memcpy( userdata->data, data, len );
else memset( userdata->data, 0, len );
return userdata;
#endif
*/
}
void UF_API uf::userdata::destroy( pod::Userdata* userdata ) {
// free(userdata);
return uf::userdata::destroy( uf::userdata::memoryPool, userdata );
/*
if ( uf::userdata::memoryPool.size() > 0 ) return uf::userdata::destroy( uf::userdata::memoryPool, userdata );
#if UF_USERDATA_KLUDGE
if ( userdata->pointer ) return; // allocated with a pool, do not free
delete[] userdata;
#else
delete[] userdata->data;
userdata->len = 0;
userdata->data = NULL;
delete userdata;
#endif
*/
}
//
pod::Userdata* UF_API uf::userdata::create( uf::MemoryPool& requestedMemoryPool, std::size_t len, void* data ) {
if ( len <= 0 ) return NULL;
// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : requestedMemoryPool;
#if UF_MEMORYPOOL_INVALID_MALLOC
uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global;
pod::Userdata* userdata = (pod::Userdata*) memoryPool.alloc( data, sizeof(pod::Userdata) + len );
#else
uf::MemoryPool* memoryPool = NULL;
if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool;
else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global;
pod::Userdata* userdata = NULL;
if ( memoryPool )
userdata = (pod::Userdata*) memoryPool->alloc( data, sizeof(pod::Userdata) + len );
else {
userdata = (pod::Userdata*) operator new( sizeof(pod::Userdata) + len ); // allocate data for the userdata struct, and then some
if ( data ) memcpy( userdata->data, data, len );
else memset( userdata->data, 0, len );
}
#endif
userdata->len = len;
return userdata;
/*
if ( uf::userdata::memoryPool.size() > 0 ) {
auto allocation = uf::userdata::memoryPool.allocate( NULL, sizeof(pod::Userdata) + len );
pod::Userdata* userdata = (pod::Userdata*) allocation.pointer;
if ( data ) memcpy( userdata->data, data, len );
else memset( userdata->data, 0, len );
userdata->len = len;
#if UF_USERDATA_KLUDGE
userdata->pointer = NULL;
#endif
return userdata;
} else {
if ( memoryPool.size() <= 0 ) return uf::userdata::create( len, data );
pod::Userdata* userdata = new pod::Userdata;
auto allocation = memoryPool.allocate( data, len );
userdata->len = allocation.size;
#if UF_USERDATA_KLUDGE
userdata->pointer = (uint8_t*) allocation.pointer;
#else
userdata->data = (uint8_t*) allocation.pointer;
#endif
return userdata;
}
*/
}
#include <iostream>
void UF_API uf::userdata::destroy( uf::MemoryPool& requestedMemoryPool, pod::Userdata* userdata ) {
// uf::MemoryPool& memoryPool = uf::MemoryPool::global.size() > 0 ? uf::MemoryPool::global : requestedMemoryPool;
#if UF_MEMORYPOOL_INVALID_FREE
uf::MemoryPool& memoryPool = requestedMemoryPool.size() > 0 ? requestedMemoryPool : uf::MemoryPool::global;
memoryPool.free( userdata, sizeof(pod::Userdata) + userdata->len );
#else
uf::MemoryPool* memoryPool = NULL;
if ( requestedMemoryPool.size() > 0 ) memoryPool = &requestedMemoryPool;
else if ( uf::MemoryPool::global.size() > 0 ) memoryPool = &uf::MemoryPool::global;
if ( memoryPool ) memoryPool->free( userdata, sizeof(pod::Userdata) + userdata->len );
else {
// free(userdata);
delete[] userdata;
}
#endif
/*
if ( uf::userdata::memoryPool.size() > 0 ) {
memoryPool.free( userdata, sizeof(pod::Userdata) + userdata->len );
userdata->len = 0;
} else {
#if UF_USERDATA_KLUDGE
if ( !userdata->pointer ) {
uf::userdata::destroy( userdata );
return;
}
#endif
memoryPool.free( userdata->data, userdata->len );
delete userdata;
}
*/
}
std::string UF_API uf::userdata::toBase64( pod::Userdata* userdata ) {
return uf::base64::encode( userdata->data, userdata->len );
}
@ -49,25 +155,29 @@ uf::Userdata::Userdata( Userdata&& move ) :
}
// Copy c-tor
uf::Userdata::Userdata( const Userdata& copy ) {
if ( copy.m_pod ) this->create( copy.m_pod->len, copy.m_pod->data );
if ( copy.m_pod && copy.m_pod->len ) this->create( copy.m_pod->len, copy.m_pod->data );
}
// Creates the POD
pod::Userdata* uf::Userdata::create( std::size_t len ) {
if ( len <= 0 ) return NULL;
this->destroy();
return this->m_pod = uf::userdata::create( len );
return this->m_pod = uf::userdata::create( len, NULL );
}
pod::Userdata* uf::Userdata::create( std::size_t len, void* data ) {
if ( len <= 0 ) return NULL;
this->destroy();
return this->m_pod = uf::userdata::create( len, data );
}
void uf::Userdata::move( Userdata&& move ) {
// if ( this->m_pod && move.m_pod ) uf::userdata::move( *this->m_pod, *move.m_pod );
std::cout << "MOVE: " << this << " <- " << &move << ", " << this->m_pod << " <- " << move.m_pod << std::endl;
this->m_pod = move.m_pod;
move.m_pod = NULL;;
move.m_pod = NULL;
}
void uf::Userdata::copy( const Userdata& copy ) {
// if ( this->m_pod && copy.m_pod ) uf::userdata::copy( *this->m_pod, *copy.m_pod );
std::cout << "COPY: " << this << " <- " << &copy << ", " << this->m_pod << " <- " << copy.m_pod << std::endl;
if ( copy.m_pod ) this->create( copy.m_pod->len, copy.m_pod->data );
}
// D-tor
@ -95,10 +205,14 @@ bool uf::Userdata::initialized() const {
}
// Overloaded ops
uf::Userdata::operator void*() {
return this->m_pod ? (void*) this->m_pod->data : NULL;
// return this->m_pod ? (void*) this->m_pod->data : NULL;
if ( !this->m_pod ) return NULL;
return this->m_pod->data;
}
uf::Userdata::operator void*() const {
return this->m_pod ? (void*) this->m_pod->data : NULL;
// return this->m_pod ? (void*) this->m_pod->data : NULL;
if ( !this->m_pod ) return NULL;
return this->m_pod->data;
}
uf::Userdata::operator bool() const {

View File

@ -18,9 +18,7 @@
#include <locale>
#include <codecvt>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/graphic.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/openvr/openvr.h>
#include <uf/utils/http/http.h>
@ -40,8 +38,8 @@ namespace {
struct {
pod::Vector2ui current = {
ext::vulkan::width,
ext::vulkan::height,
uf::renderer::width,
uf::renderer::height,
};
pod::Vector2ui reference = {
1280,
@ -1022,7 +1020,7 @@ void ext::Gui::render() {
auto& scene = this->getRootParent<uf::Scene>();
auto& controller = *scene.getController();
auto& camera = controller.getComponent<uf::Camera>();
auto* renderMode = (ext::vulkan::RenderTargetRenderMode*) &ext::vulkan::getRenderMode("Gui");
auto* renderMode = (uf::renderer::RenderTargetRenderMode*) &uf::renderer::getRenderMode("Gui");
if ( renderMode->getName() == "Gui" ) {
auto& blitter = renderMode->blitter;
auto& metadata = controller.getComponent<uf::Serializer>();
@ -1062,7 +1060,7 @@ void ext::Gui::render() {
metadata["overlay"]["orientation"][2].asFloat(),
metadata["overlay"]["orientation"][3].asFloat(),
};
if ( ext::openvr::enabled && (metadata["overlay"]["enabled"].asBool() || ext::vulkan::getRenderMode("Stereoscopic Deferred", true).getType() == "Stereoscopic Deferred" )) {
if ( ext::openvr::enabled && (metadata["overlay"]["enabled"].asBool() || uf::renderer::getRenderMode("Stereoscopic Deferred", true).getType() == "Stereoscopic Deferred" )) {
if ( metadata["overlay"]["floating"].asBool() ) {
pod::Matrix4f model = uf::transform::model( transform );
uniforms.matrices.models[i] = camera.getProjection(i) * ext::openvr::hmdEyePositionMatrix( i == 0 ? vr::Eye_Left : vr::Eye_Right ) * model;

View File

@ -31,15 +31,14 @@
#include <fstream>
#include <iostream>
#include <regex>
#include "ext.h"
#include <uf/engine/scene/scene.h>
#include <uf/engine/asset/asset.h>
#include <uf/ext/vulkan/rendermodes/deferred.h>
#include <uf/ext/vulkan/rendermodes/compute.h>
#include <uf/ext/vulkan/rendermodes/stereoscopic_deferred.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/discord/discord.h>
#include <uf/ext/openvr/openvr.h>
@ -86,8 +85,53 @@ void EXT_API ext::initialize() {
}
::config = ext::getConfig();
/* Parse config */ {
// Set memory pool sizes
{
auto deduceSize = []( auto& value )->size_t{
if ( value.isNumeric() ) return value.asUInt64();
if ( value.isString() ) {
std::string str = value.asString();
std::regex regex("^(\\d+) ?((?:K|M|G)?(?:i?B)?)$");
std::smatch match;
if ( std::regex_search( str, match, regex ) ) {
size_t requested = std::stoi( match[1].str() );
std::string prefix = match[2].str();
switch ( prefix.at(0) ) {
case 'K': return requested * 1024;
case 'M': return requested * 1024 * 1024;
case 'G': return requested * 1024 * 1024 * 1024;
}
return requested;
}
}
return 0;
};
{
size_t size = deduceSize( ::config["engine"]["memory pool"]["size"] );
uf::MemoryPool::globalOverride = ::config["engine"]["memory pool"]["globalOverride"].asBool();
std::cout << "Requesting " << (int) size << " bytes for global memory pool: " << &uf::MemoryPool::global << std::endl;
uf::MemoryPool::global.initialize( size );
uf::MemoryPool::subPool = ::config["engine"]["memory pool"]["subPools"].asBool();
if ( size <= 0 || uf::MemoryPool::subPool ) {
{
size_t size = deduceSize( ::config["engine"]["memory pools"]["component"] );
std::cout << "Requesting " << (int) size << " bytes for component memory pool: " << &uf::component::memoryPool << std::endl;
uf::component::memoryPool.initialize( size );
}
{
size_t size = deduceSize( ::config["engine"]["memory pools"]["userdata"] );
std::cout << "Requesting " << (int) size << " bytes for userdata memory pool: " << &uf::userdata::memoryPool << std::endl;
uf::userdata::memoryPool.initialize( size );
}
{
size_t size = deduceSize( ::config["engine"]["memory pools"]["entity"] );
std::cout << "Requesting " << (int) size << " bytes for entity memory pool: " << &uf::Entity::memoryPool << std::endl;
uf::Entity::memoryPool.initialize( size );
}
}
}
}
/* Frame limiter */ {
double limit = ::config["engine"]["frame limit"].asDouble();
if ( limit != 0 )
@ -103,19 +147,19 @@ void EXT_API ext::initialize() {
// Set worker threads
uf::thread::workers = ::config["engine"]["worker threads"].asUInt64();
// Enable valiation layer
ext::vulkan::validation = ::config["engine"]["ext"]["vulkan"]["validation"]["enabled"].asBool();
uf::renderer::validation = ::config["engine"]["ext"]["vulkan"]["validation"]["enabled"].asBool();
for ( int i = 0; i < ::config["engine"]["ext"]["vulkan"]["validation"]["filters"].size(); ++i ) {
ext::vulkan::validationFilters.push_back( ::config["engine"]["ext"]["vulkan"]["validation"]["filters"][i].asString() );
uf::renderer::validationFilters.push_back( ::config["engine"]["ext"]["vulkan"]["validation"]["filters"][i].asString() );
}
for ( int i = 0; i < ::config["engine"]["ext"]["vulkan"]["extensions"]["device"].size(); ++i ) {
ext::vulkan::requestedDeviceExtensions.push_back( ::config["engine"]["ext"]["vulkan"]["extensions"]["device"][i].asString() );
uf::renderer::requestedDeviceExtensions.push_back( ::config["engine"]["ext"]["vulkan"]["extensions"]["device"][i].asString() );
}
for ( int i = 0; i < ::config["engine"]["ext"]["vulkan"]["extensions"]["instance"].size(); ++i ) {
ext::vulkan::requestedInstanceExtensions.push_back( ::config["engine"]["ext"]["vulkan"]["extensions"]["instance"][i].asString() );
uf::renderer::requestedInstanceExtensions.push_back( ::config["engine"]["ext"]["vulkan"]["extensions"]["instance"][i].asString() );
}
for ( int i = 0; i < ::config["engine"]["ext"]["vulkan"]["features"].size(); ++i ) {
ext::vulkan::requestedDeviceFeatures.push_back( ::config["engine"]["ext"]["vulkan"]["features"][i].asString() );
uf::renderer::requestedDeviceFeatures.push_back( ::config["engine"]["ext"]["vulkan"]["features"][i].asString() );
}
ext::openvr::enabled = ::config["engine"]["ext"]["vr"]["enable"].asBool();
ext::openvr::swapEyes = ::config["engine"]["ext"]["vr"]["swap eyes"].asBool();
@ -131,30 +175,30 @@ void EXT_API ext::initialize() {
/* Create initial scene (kludge) */ {
uf::Scene* scene = new uf::Scene;
uf::scene::scenes.push_back(scene);
auto& metadata = scene->getComponent<uf::Serializer>();
uf::Scene& scene = uf::instantiator::instantiate<uf::Scene>(); //new uf::Scene;
uf::scene::scenes.push_back(&scene);
auto& metadata = scene.getComponent<uf::Serializer>();
metadata["system"]["config"] = ::config;
}
/* Initialize Vulkan */ {
// ext::vulkan::width = ::config["window"]["size"]["x"].asInt();
// ext::vulkan::height = ::config["window"]["size"]["y"].asInt();
// uf::renderer::width = ::config["window"]["size"]["x"].asInt();
// uf::renderer::height = ::config["window"]["size"]["y"].asInt();
// setup render mode
if ( ::config["engine"]["render modes"]["gui"].asBool() ) {
auto* renderMode = new ext::vulkan::RenderTargetRenderMode;
ext::vulkan::addRenderMode( renderMode, "Gui" );
auto* renderMode = new uf::renderer::RenderTargetRenderMode;
uf::renderer::addRenderMode( renderMode, "Gui" );
renderMode->blitter.descriptor.subpass = 1;
}
if ( ::config["engine"]["render modes"]["stereo deferred"].asBool() )
ext::vulkan::addRenderMode( new ext::vulkan::StereoscopicDeferredRenderMode, "" );
uf::renderer::addRenderMode( new uf::renderer::StereoscopicDeferredRenderMode, "" );
else if ( ::config["engine"]["render modes"]["deferred"].asBool() )
ext::vulkan::addRenderMode( new ext::vulkan::DeferredRenderMode, "" );
uf::renderer::addRenderMode( new uf::renderer::DeferredRenderMode, "" );
// if ( ::config["engine"]["render modes"]["compute"].asBool() )
// ext::vulkan::addRenderMode( new ext::vulkan::ComputeRenderMode, "C:RT:0" );
// uf::renderer::addRenderMode( new uf::renderer::ComputeRenderMode, "C:RT:0" );
if ( ext::openvr::enabled ) {
ext::openvr::initialize();
@ -162,14 +206,14 @@ void EXT_API ext::initialize() {
uint32_t width, height;
ext::openvr::recommendedResolution( width, height );
auto& renderMode = ext::vulkan::getRenderMode("Stereoscopic Deferred", true);
auto& renderMode = uf::renderer::getRenderMode("Stereoscopic Deferred", true);
renderMode.width = width;
renderMode.height = height;
std::cout << "Recommended VR Resolution: " << width << ", " << height << std::endl;
}
ext::vulkan::initialize();
uf::renderer::initialize();
}
/* */ {
pod::Thread& threadMain = uf::thread::has("Main") ? uf::thread::get("Main") : uf::thread::create( "Main", false, true );
@ -237,7 +281,7 @@ void EXT_API ext::tick() {
}
uf::iostream << "\n";
};
for ( uf::Scene* scene : ext::vulkan::scenes ) {
for ( uf::Scene* scene : uf::renderer::scenes ) {
if ( !scene ) continue;
std::cout << "Scene: " << scene->getName() << ": " << scene << std::endl;
scene->process(filter, 1);
@ -248,7 +292,21 @@ void EXT_API ext::tick() {
static uf::Timer<long long> timer(false);
if ( !timer.running() ) timer.start();
if ( uf::Window::isKeyPressed("P") && timer.elapsed().asDouble() >= 1 ) { timer.reset();
uf::iostream << ext::vulkan::allocatorStats() << "\n";
// uf::iostream << uf::renderer::allocatorStats() << "\n";
if ( uf::MemoryPool::global.size() > 0 ) uf::iostream << "Global Memory Pool:\n" << uf::MemoryPool::global.stats() << "\n";
if ( uf::Entity::memoryPool.size() > 0 ) uf::iostream << "Entity Memory Pool:\n" << uf::Entity::memoryPool.stats() << "\n";
if ( uf::component::memoryPool.size() > 0 ) uf::iostream << "Components Memory Pool:\n" << uf::component::memoryPool.stats() << "\n";
if ( uf::userdata::memoryPool.size() > 0 ) uf::iostream << "Userdata Memory Pool:\n" << uf::userdata::memoryPool.stats() << "\n";
/*
size_t size = uf::component::memoryPool.size();
size_t allocated = uf::component::memoryPool.allocated();
uf::iostream << "Memory Pools:\n"
<< "\tComponents:\n"
<< "\t\tSize : " << size << "\n"
<< "\t\tAllocated: " << allocated << "\n"
<< "\t\tFree : " << (size-allocated)
<< "\n";
*/
}
}
/* Attempt to reset VR position */ {
@ -301,7 +359,7 @@ void EXT_API ext::tick() {
}
/* Update vulkan */ {
ext::vulkan::tick();
uf::renderer::tick();
}
/* Discord */ if ( ::config["engine"]["ext"]["discord"]["enable"].asBool() ) {
ext::discord::tick();
@ -322,7 +380,7 @@ void EXT_API ext::tick() {
void EXT_API ext::render() {
// uf::scene::render();
ext::vulkan::render();
uf::renderer::render();
/* OpenVR */ if ( ext::openvr::context ) {
ext::openvr::submit();
@ -338,7 +396,7 @@ void EXT_API ext::terminate() {
}
/* Close vulkan */ {
ext::vulkan::destroy();
uf::renderer::destroy();
}
@ -385,25 +443,28 @@ std::string EXT_API ext::getConfig() {
file.exists = config.file.readFromFile(file.filename);
}
/* Initialize default configuration */ {
config.fallback["window"]["terminal"]["ncurses"] = true;
config.fallback["window"]["terminal"]["visible"] = true;
config.fallback["window"]["title"] = "Grimgram";
config.fallback["window"]["icon"] = "";
config.fallback["window"]["size"]["x"] = 0;
config.fallback["window"]["size"]["y"] = 0;
config.fallback["window"]["visible"] = true;
// config.fallback["window"]["fullscreen"] = false;
config.fallback["window"]["mode"] = "windowed";
config.fallback["window"]["cursor"]["visible"] = true;
config.fallback["window"]["cursor"]["center"] = false;
config.fallback["window"]["keyboard"]["repeat"] = true;
config.fallback["window"]["terminal"]["ncurses"] = true;
config.fallback["window"]["terminal"]["visible"] = true;
config.fallback["window"]["title"] = "Grimgram";
config.fallback["window"]["icon"] = "";
config.fallback["window"]["size"]["x"] = 0;
config.fallback["window"]["size"]["y"] = 0;
config.fallback["window"]["visible"] = true;
// config.fallback["window"]["fullscreen"] = false;
config.fallback["window"]["mode"] = "windowed";
config.fallback["window"]["cursor"]["visible"] = true;
config.fallback["window"]["cursor"]["center"] = false;
config.fallback["window"]["keyboard"]["repeat"] = true;
config.fallback["engine"]["scenes"]["start"] = "StartMenu";
config.fallback["engine"]["scenes"]["max lights"] = 32;
config.fallback["engine"]["hook"]["mode"] = "Readable";
config.fallback["engine"]["frame limit"] = 60;
config.fallback["engine"]["delta limit"] = 120;
config.fallback["engine"]["worker threads"] = 1;
config.fallback["engine"]["scenes"]["start"] = "StartMenu";
config.fallback["engine"]["scenes"]["max lights"] = 32;
config.fallback["engine"]["hook"]["mode"] = "Readable";
config.fallback["engine"]["frame limit"] = 60;
config.fallback["engine"]["delta limit"] = 120;
config.fallback["engine"]["worker threads"] = 1;
config.fallback["engine"]["memory pool"]["size"] = "512 MiB";
config.fallback["engine"]["memory pool"]["globalOverride"] = false;
config.fallback["engine"]["memory pool"]["subPools"] = true;
}
/* Merge */ if ( file.exists ){
config.merged = config.file;

View File

@ -1,4 +1,5 @@
#include "scene.h"
#include <uf/utils/time/time.h>
#include <uf/utils/io/iostream.h>
#include <uf/utils/math/vector.h>
@ -12,10 +13,8 @@
#include <uf/engine/asset/asset.h>
#include <uf/engine/asset/masterdata.h>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/rendermodes/deferred.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/ext/vulkan/rendermodes/stereoscopic_deferred.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/gltf/gltf.h>
#include <uf/utils/math/collision.h>
@ -23,8 +22,8 @@
#include "../../ext.h"
#include "../../gui/gui.h"
EXT_OBJECT_REGISTER_CPP(TestScene)
void ext::TestScene::initialize() {
EXT_OBJECT_REGISTER_CPP(TestScene_Map)
void ext::TestScene_Map::initialize() {
uf::Scene::initialize();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Asset& assetLoader = this->getComponent<uf::Asset>();
@ -59,7 +58,7 @@ void ext::TestScene::initialize() {
ext::Gui* manager = (ext::Gui*) this->findByName("Gui Manager");
if ( !manager ) return "false";
uf::Serializer payload;
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/world/gui/pause/menu.json", false)).asUInt64() );
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/worldscape/gui/pause/menu.json", false)).asUInt64() );
uf::Serializer& metadata = gui->getComponent<uf::Serializer>();
metadata["menu"] = json["menu"];
gui->initialize();
@ -68,8 +67,8 @@ void ext::TestScene::initialize() {
}
/* store viewport size */ {
metadata["window"]["size"]["x"] = ext::vulkan::width;
metadata["window"]["size"]["y"] = ext::vulkan::height;
metadata["window"]["size"]["x"] = uf::renderer::width;
metadata["window"]["size"]["y"] = uf::renderer::height;
this->addHook( "window:Resized", [&](const std::string& event)->std::string{
uf::Serializer json = event;
@ -94,10 +93,10 @@ void ext::TestScene::initialize() {
}
}
void ext::TestScene::render() {
void ext::TestScene_Map::render() {
uf::Scene::render();
}
void ext::TestScene::tick() {
void ext::TestScene_Map::tick() {
uf::Scene::tick();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();

View File

@ -6,7 +6,7 @@
#include <uf/engine/scene/scene.h>
namespace ext {
class EXT_API TestScene : public uf::Scene {
class EXT_API TestScene_Map : public uf::Scene {
public:
virtual void initialize();
virtual void tick();

View File

@ -0,0 +1,173 @@
#include "scene.h"
#include <uf/utils/time/time.h>
#include <uf/utils/io/iostream.h>
#include <uf/utils/math/vector.h>
#include <uf/utils/math/transform.h>
#include <uf/utils/window/window.h>
#include <uf/utils/audio/audio.h>
#include <uf/utils/thread/thread.h>
#include <uf/utils/camera/camera.h>
#include <uf/engine/asset/asset.h>
#include <uf/engine/asset/masterdata.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/gltf/gltf.h>
#include <uf/utils/math/collision.h>
#include "../../ext.h"
#include "../../gui/gui.h"
EXT_OBJECT_REGISTER_CPP(TestScene_MarchingCubes)
void ext::TestScene_MarchingCubes::initialize() {
uf::Scene::initialize();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Asset& assetLoader = this->getComponent<uf::Asset>();
this->addHook( "system:Quit.%UID%", [&](const std::string& event)->std::string{
std::cout << event << std::endl;
ext::ready = false;
return "true";
});
{
static uf::Timer<long long> timer(false);
if ( !timer.running() ) timer.start();
this->addHook( "world:Entity.LoadAsset", [&](const std::string& event)->std::string{
uf::Serializer json = event;
std::string asset = json["asset"].asString();
std::string uid = json["uid"].asString();
assetLoader.load(asset, "asset:Load." + uid);
return "true";
});
}
{
static uf::Timer<long long> timer(false);
if ( !timer.running() ) timer.start();
this->addHook( "menu:Pause", [&](const std::string& event)->std::string{
if ( timer.elapsed().asDouble() < 1 ) return "false";
timer.reset();
uf::Serializer json = event;
ext::Gui* manager = (ext::Gui*) this->findByName("Gui Manager");
if ( !manager ) return "false";
uf::Serializer payload;
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/worldscape/gui/pause/menu.json", false)).asUInt64() );
uf::Serializer& metadata = gui->getComponent<uf::Serializer>();
metadata["menu"] = json["menu"];
gui->initialize();
return payload;
});
}
/* store viewport size */ {
metadata["window"]["size"]["x"] = uf::renderer::width;
metadata["window"]["size"]["y"] = uf::renderer::height;
this->addHook( "window:Resized", [&](const std::string& event)->std::string{
uf::Serializer json = event;
pod::Vector2ui size; {
size.x = json["window"]["size"]["x"].asUInt64();
size.y = json["window"]["size"]["y"].asUInt64();
}
metadata["window"] = json["window"];
return "true";
});
}
// lock control
{
uf::Serializer payload;
payload["state"] = true;
uf::hooks.call("window:Mouse.CursorVisibility", payload);
uf::hooks.call("window:Mouse.Lock");
}
}
void ext::TestScene_MarchingCubes::render() {
uf::Scene::render();
}
void ext::TestScene_MarchingCubes::tick() {
uf::Scene::tick();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Asset& assetLoader = this->getComponent<uf::Asset>();
/* Regain control if nothing requests it */ {
ext::Gui* menu = (ext::Gui*) this->findByName("Gui: Menu");
if ( !menu ) {
uf::Serializer payload;
payload["state"] = false;
uf::hooks.call("window:Mouse.CursorVisibility", payload);
uf::hooks.call("window:Mouse.Lock");
}
}
/* Updates Sound Listener */ {
pod::Transform<>& transform = this->getController()->getComponent<pod::Transform<>>();
ext::oal.listener( "POSITION", { transform.position.x, transform.position.y, transform.position.z } );
ext::oal.listener( "VELOCITY", { 0, 0, 0 } );
ext::oal.listener( "ORIENTATION", { 0, 0, 1, 1, 0, 0 } );
}
/* Collision */ {
bool local = false;
bool sort = false;
bool useStrongest = false;
// pod::Thread& thread = uf::thread::fetchWorker();
pod::Thread& thread = uf::thread::has("Physics") ? uf::thread::get("Physics") : uf::thread::create( "Physics", true, false );
auto function = [&]() -> int {
std::vector<uf::Object*> entities;
std::function<void(uf::Entity*)> filter = [&]( uf::Entity* entity ) {
auto& metadata = entity->getComponent<uf::Serializer>();
if ( !metadata["system"]["physics"]["collision"].isNull() && !metadata["system"]["physics"]["collision"].asBool() ) return;
if ( entity->hasComponent<uf::Collider>() )
entities.push_back((uf::Object*) entity);
};
this->process(filter);
auto onCollision = []( pod::Collider::Manifold& manifold, uf::Object* a, uf::Object* b ){
uf::Serializer payload;
payload["normal"][0] = manifold.normal.x;
payload["normal"][1] = manifold.normal.y;
payload["normal"][2] = manifold.normal.z;
payload["entity"] = b->getUid();
payload["depth"] = -manifold.depth;
a->callHook("world:Collision.%UID%", payload);
payload["entity"] = a->getUid();
payload["depth"] = manifold.depth;
b->callHook("world:Collision.%UID%", payload);
};
auto testColliders = [&]( uf::Collider& colliderA, uf::Collider& colliderB, uf::Object* a, uf::Object* b, bool useStrongest ){
pod::Collider::Manifold strongest;
auto manifolds = colliderA.intersects(colliderB);
for ( auto manifold : manifolds ) {
if ( manifold.colliding && manifold.depth > 0 ) {
if ( !useStrongest ) onCollision(manifold, a, b);
else if ( strongest.depth < manifold.depth ) strongest = manifold;
}
}
if ( useStrongest && strongest.colliding ) onCollision(strongest, a, b);
};
// collide with others
for ( auto* _a : entities ) {
uf::Object& entityA = *_a;
for ( auto* _b : entities ) { if ( _a == _b ) continue;
uf::Object& entityB = *_b;
testColliders( entityA.getComponent<uf::Collider>(), entityB.getComponent<uf::Collider>(), &entityA, &entityB, useStrongest );
}
}
return 0;
};
if ( local ) function(); else uf::thread::add( thread, function, true );
}
}

View File

@ -0,0 +1,15 @@
#pragma once
#include <uf/config.h>
#include <uf/ext/ext.h>
#include <uf/engine/object/object.h>
#include <uf/engine/scene/scene.h>
namespace ext {
class EXT_API TestScene_MarchingCubes : public uf::Scene {
public:
virtual void initialize();
virtual void tick();
virtual void render();
};
}

View File

@ -13,11 +13,7 @@
#include <uf/engine/asset/asset.h>
#include <uf/engine/asset/masterdata.h>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/rendermodes/deferred.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/ext/vulkan/rendermodes/compute.h>
#include <uf/ext/vulkan/rendermodes/stereoscopic_deferred.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/gltf/gltf.h>
#include <uf/utils/math/collision.h>
@ -25,16 +21,16 @@
#include "../../ext.h"
#include "../../gui/gui.h"
EXT_OBJECT_REGISTER_CPP(RaytracedScene)
void ext::RaytracedScene::initialize() {
EXT_OBJECT_REGISTER_CPP(TestScene_RayTracing)
void ext::TestScene_RayTracing::initialize() {
uf::Scene::initialize();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Asset& assetLoader = this->getComponent<uf::Asset>();
{
auto& renderMode = this->getComponent<ext::vulkan::ComputeRenderMode>();
auto& renderMode = this->getComponent<uf::renderer::ComputeRenderMode>();
std::string name = "C:RT:" + std::to_string((int) this->getUid());
ext::vulkan::addRenderMode( &renderMode, name );
uf::renderer::addRenderMode( &renderMode, name );
if ( metadata["light"]["shadows"]["resolution"].isArray() ) {
renderMode.width = metadata["light"]["shadows"]["resolution"][0].asUInt64();
renderMode.height = metadata["light"]["shadows"]["resolution"][1].asUInt64();
@ -66,7 +62,7 @@ void ext::RaytracedScene::initialize() {
shapes.push_back( {{-1.0f, 0.0f, 0.0f, roomDim}, {1.0f, 0.0f, 0.0f}, 32.0f, 2} );
shapes.push_back( {{1.0f, 0.0f, 0.0f, roomDim}, {0.0f, 1.0f, 0.0f}, 32.0f, 2} );
}
renderMode.compute.device = &ext::vulkan::device;
renderMode.compute.device = &uf::renderer::device;
renderMode.compute.initializeBuffer(
(void*) shapes.data(),
shapes.size() * sizeof(Shape),
@ -107,7 +103,7 @@ void ext::RaytracedScene::initialize() {
ext::Gui* manager = (ext::Gui*) this->findByName("Gui Manager");
if ( !manager ) return "false";
uf::Serializer payload;
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/world/gui/pause/menu.json", false)).asUInt64() );
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/worldscape/gui/pause/menu.json", false)).asUInt64() );
uf::Serializer& metadata = gui->getComponent<uf::Serializer>();
metadata["menu"] = json["menu"];
gui->initialize();
@ -116,8 +112,8 @@ void ext::RaytracedScene::initialize() {
}
/* store viewport size */ {
metadata["window"]["size"]["x"] = ext::vulkan::width;
metadata["window"]["size"]["y"] = ext::vulkan::height;
metadata["window"]["size"]["x"] = uf::renderer::width;
metadata["window"]["size"]["y"] = uf::renderer::height;
this->addHook( "window:Resized", [&](const std::string& event)->std::string{
uf::Serializer json = event;
@ -142,24 +138,24 @@ void ext::RaytracedScene::initialize() {
}
}
void ext::RaytracedScene::render() {
void ext::TestScene_RayTracing::render() {
uf::Scene::render();
}
void ext::RaytracedScene::destroy() {
if ( this->hasComponent<ext::vulkan::ComputeRenderMode>() ) {
auto& renderMode = this->getComponent<ext::vulkan::ComputeRenderMode>();
ext::vulkan::removeRenderMode( &renderMode, false );
void ext::TestScene_RayTracing::destroy() {
if ( this->hasComponent<uf::renderer::ComputeRenderMode>() ) {
auto& renderMode = this->getComponent<uf::renderer::ComputeRenderMode>();
uf::renderer::removeRenderMode( &renderMode, false );
}
uf::Scene::destroy();
}
void ext::RaytracedScene::tick() {
void ext::TestScene_RayTracing::tick() {
uf::Scene::tick();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Asset& assetLoader = this->getComponent<uf::Asset>();
#if 1
if ( this->hasComponent<ext::vulkan::ComputeRenderMode>() ) {
auto& renderMode = this->getComponent<ext::vulkan::ComputeRenderMode>();
if ( this->hasComponent<uf::renderer::ComputeRenderMode>() ) {
auto& renderMode = this->getComponent<uf::renderer::ComputeRenderMode>();
/* Add lights to scene */ if ( renderMode.compute.initialized ) {
struct UniformDescriptor {
alignas(16) pod::Matrix4f matrices[2];
@ -202,7 +198,7 @@ void ext::RaytracedScene::tick() {
if ( !entity || entity->getName() != "Light" ) return;
entities.push_back(entity);
};
for ( uf::Scene* scene : ext::vulkan::scenes ) { if ( !scene ) continue;
for ( uf::Scene* scene : uf::renderer::scenes ) { if ( !scene ) continue;
scene->process(filter);
}
{

View File

@ -6,7 +6,7 @@
#include <uf/engine/scene/scene.h>
namespace ext {
class EXT_API RaytracedScene : public uf::Scene {
class EXT_API TestScene_RayTracing : public uf::Scene {
public:
virtual void initialize();
virtual void tick();

View File

@ -12,7 +12,7 @@
#include <uf/engine/asset/asset.h>
#include <uf/engine/asset/masterdata.h>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/openvr/openvr.h>
#include "../../ext.h"
@ -112,8 +112,8 @@ void ext::StartMenu::initialize() {
});
/* store viewport size */ {
metadata["window"]["size"]["x"] = ext::vulkan::width;
metadata["window"]["size"]["y"] = ext::vulkan::height;
metadata["window"]["size"]["x"] = uf::renderer::width;
metadata["window"]["size"]["y"] = uf::renderer::height;
this->addHook( "window:Resized", [&](const std::string& event)->std::string{
uf::Serializer json = event;

View File

@ -15,7 +15,8 @@
#include "..//battle.h"
#include "../terrain/generator.h"
#include "../world.h"
#include "../scene.h"
#include <uf/engine/asset/asset.h>
EXT_OBJECT_REGISTER_CPP(Craeture)
@ -100,7 +101,7 @@ void ext::Craeture::initialize() {
this->addHook( "asset:Cache.Sound.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& world = uf::scene::getCurrentScene();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
std::string filename = json["filename"].asString();
@ -137,8 +138,8 @@ void ext::Craeture::initialize() {
if ( metadata["timers"]["hurt"].asFloat() < timer.elapsed().asDouble() ) {
metadata["timers"]["hurt"] = timer.elapsed().asDouble() + 1.0f;
ext::World& world = this->getRootParent<ext::World>();
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache("./data/audio/battle/hurt.ogg", "asset:Cache.Sound." + std::to_string(this->getUid()));
}
@ -167,7 +168,7 @@ void ext::Craeture::tick() {
uf::Object::tick();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& world = uf::scene::getCurrentScene();
uf::Serializer& pMetadata = world.getController()->getComponent<uf::Serializer>();
if ( !pMetadata["system"]["control"].asBool() ) return;

View File

@ -8,7 +8,7 @@
#include <uf/utils/camera/camera.h>
#include <uf/utils/string/ext.h>
// #include <uf/gl/glyph/glyph.h>
#include "../world.h"
#include "..//battle.h"
#include <uf/engine/asset/asset.h>
@ -42,18 +42,15 @@ namespace {
ext::HousamoBattle* battleManager;
ext::World* world;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -64,9 +61,8 @@ namespace {
}
void playSound( ext::GuiBattle& entity, const std::string& id, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer cardData = masterDataGet("Card", id);
uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].asString());
@ -79,39 +75,36 @@ namespace {
url = "/smtsamo/voice/voice_" + name + "_" + key + ".ogg";
}
uf::Asset& assetLoader = world->getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid()));
}
void playSound( ext::GuiBattle& entity, std::size_t uid, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& pMetadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Entity* = world->findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ! ) return;
uf::Serializer& metadata = ->getComponent<uf::Serializer>();
std::string id = metadata[""]["id"].asString();
playSound( entity, id, key );
}
void playSound( ext::GuiBattle& entity, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string url = "./data/audio/ui/" + key + ".ogg";
uf::Asset& assetLoader = world->getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid()));
}
void playMusic( ext::GuiBattle& entity, const std::string& filename ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
uf::Asset& assetLoader = world->getComponent<uf::Asset>();
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
assetLoader.load(filename, "asset:Load." + std::to_string(world->getUid()));
assetLoader.load(filename, "asset:Load." + std::to_string(scene.getUid()));
}
std::string getKeyFromIndex( uf::Serializer& object, uint64_t index ) {
uint64_t i = 0;
@ -155,6 +148,7 @@ namespace {
void ext::GuiBattle::initialize() {
ext::Gui::initialize();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
battleManager = (ext::HousamoBattle*) this->getRootParent().findByName( "Battle Manager" );
@ -168,7 +162,7 @@ void ext::GuiBattle::initialize() {
if ( uf::string::extension(filename) != "ogg" ) return "false";
if ( filename == "" ) return "false";
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Audio& sfx = this->getComponent<uf::SoundEmitter>().add(filename);
/*
uf::Audio& sfx = this->getComponent<uf::Audio>();
@ -190,7 +184,7 @@ void ext::GuiBattle::initialize() {
if ( uf::string::extension(filename) != "ogg" ) return "false";
if ( filename == "" ) return "false";
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Audio& voice = this->getComponent<uf::Audio>();
if ( voice.playing() ) voice.stop();
voice = uf::Audio();
@ -631,8 +625,8 @@ void ext::GuiBattle::initialize() {
void ext::GuiBattle::tick() {
if ( !battleManager ) return;
ext::World& world = this->getRootParent<ext::World>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer& bMetadata = this->getComponent<uf::Serializer>();
static float alpha = 0.0f;

View File

@ -20,7 +20,6 @@
#include <sys/stat.h>
#include <fstream>
#include "../world.h"
#include "..//dialogue.h"
namespace {
@ -31,18 +30,14 @@ namespace {
ext::DialogueManager* dialogueManager;
ext::World* world;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
auto& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
auto& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -50,9 +45,8 @@ namespace {
}
void playSound( ext::GuiDialogue& entity, const std::string& id, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
auto& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer cardData = masterDataGet("Card", id);
uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].asString());
@ -62,39 +56,36 @@ namespace {
url = "/smtsamo/voice/voice_" + name + "_" + key + ".ogg";
}
uf::Asset& assetLoader = world->getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid()));
}
void playSound( ext::GuiDialogue& entity, std::size_t uid, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
auto& scene = uf::scene::getCurrentScene();
uf::Serializer& pMetadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Entity* = world->findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ! ) return;
uf::Serializer& metadata = ->getComponent<uf::Serializer>();
std::string id = metadata[""]["id"].asString();
playSound( entity, id, key );
}
void playSound( ext::GuiDialogue& entity, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
auto& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string url = "./data/audio/ui/" + key + ".ogg";
uf::Asset& assetLoader = world->getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid()));
}
void playMusic( ext::GuiDialogue& entity, const std::string& filename ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return;
uf::Asset& assetLoader = world->getComponent<uf::Asset>();
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
auto& scene = uf::scene::getCurrentScene();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
assetLoader.load(filename, "asset:Load." + std::to_string(world->getUid()));
assetLoader.load(filename, "asset:Load." + std::to_string(scene.getUid()));
}
std::string getKeyFromIndex( uf::Serializer& object, uint64_t index ) {
uint64_t i = 0;
@ -126,6 +117,7 @@ namespace {
void ext::GuiDialogue::initialize() {
ext::Gui::initialize();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
dialogueManager = (ext::DialogueManager*) this->getRootParent().findByName( "Dialogue Manager" );
@ -137,7 +129,7 @@ void ext::GuiDialogue::initialize() {
if ( uf::string::extension(filename) != "ogg" ) return "false";
if ( filename == "" ) return "false";
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Audio& sfx = this->getComponent<uf::Audio>();
if ( sfx.playing() ) sfx.stop();
sfx = uf::Audio();
@ -156,7 +148,7 @@ void ext::GuiDialogue::initialize() {
if ( uf::string::extension(filename) != "ogg" ) return "false";
if ( filename == "" ) return "false";
uf::Serializer& masterdata = world->getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Audio& voice = this->getComponent<uf::Audio>();
if ( voice.playing() ) voice.stop();
voice = uf::Audio();
@ -188,8 +180,8 @@ void ext::GuiDialogue::initialize() {
void ext::GuiDialogue::tick() {
if ( !dialogueManager ) return;
ext::World& world = this->getRootParent<ext::World>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer& bMetadata = this->getComponent<uf::Serializer>();
static float alpha = 0.0f;

View File

@ -12,16 +12,13 @@
#include <unordered_map>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/graphic.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/utils/http/http.h>
#include <uf/utils/audio/audio.h>
#include <sys/stat.h>
#include <fstream>
#include "../world.h"
namespace {
ext::Gui* mainText;
ext::Gui* commandText;
@ -37,7 +34,7 @@ namespace {
namespace {
void playSound( ext::GuiWorldPauseMenu& entity, const std::string& key ) {
uf::Scene& scene = entity.getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
@ -47,17 +44,14 @@ namespace {
assetLoader.cache(url, "asset:Cache." + std::to_string(entity.getUid()));
}
uf::Scene* scene;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !scene ) scene = (uf::Scene*) &uf::scene::getCurrentScene();
if ( !scene ) return std::string();
uf::Serializer& mastertable = scene->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !scene ) scene = (uf::Scene*) &uf::scene::getCurrentScene();
if ( !scene ) return std::string();
uf::Serializer& mastertable = scene->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -70,7 +64,7 @@ EXT_OBJECT_REGISTER_CPP(GuiWorldPauseMenu)
void ext::GuiWorldPauseMenu::initialize() {
ext::Gui::initialize();
uf::Scene& scene = this->getRootParent<uf::Scene>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();

View File

@ -9,32 +9,28 @@
#include <uf/utils/graphic/mesh.h>
#include <uf/utils/window/window.h>
#include <uf/utils/camera/camera.h>
#include <uf/ext/vulkan/graphic.h>
#include <uf/ext/vulkan/device.h>
#include <uf/ext/vulkan/swapchain.h>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/utils/image/image.h>
#include <uf/utils/audio/audio.h>
#include "../world.h"
#include "../gui/battle.h"
#include <uf/engine/asset/asset.h>
namespace {
ext::World* world;
ext::Gui* gui;
std::string previousMusic;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -49,8 +45,8 @@ namespace {
namespace {
void playSound( ext::HousamoBattle& entity, const std::string& id, const std::string& key ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer cardData = masterDataGet("Card", id);
uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].asString());
@ -63,43 +59,43 @@ namespace {
url = "./data/smtsamo/voice/voice_" + name + "_" + key + ".ogg";
}
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid()));
}
void playSound( ext::HousamoBattle& entity, std::size_t uid, const std::string& key ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& pMetadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Entity* = world.findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ! ) return;
uf::Serializer& metadata = ->getComponent<uf::Serializer>();
std::string id = metadata[""]["id"].asString();
playSound( entity, id, key );
}
void playSound( ext::HousamoBattle& entity, const std::string& key ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string url = "./data/audio/ui/" + key + ".ogg";
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid()));
}
void playMusic( ext::HousamoBattle& entity, const std::string& filename ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Audio& audio = world.getComponent<uf::Audio>();
uf::Audio& audio = scene.getComponent<uf::Audio>();
if ( audio.playing() ) {
uf::Serializer& metadata = world.getComponent<uf::Serializer>();
uf::Serializer& metadata = scene.getComponent<uf::Serializer>();
metadata["previous bgm"]["filename"] = audio.getFilename();
metadata["previous bgm"]["timestamp"] = audio.getTime();
}
assetLoader.load(filename, "asset:Load." + std::to_string(world.getUid()));
assetLoader.load(filename, "asset:Load." + std::to_string(scene.getUid()));
}
uf::Audio sfx;
@ -112,6 +108,7 @@ void ext::HousamoBattle::initialize() {
gui = NULL;
transients.clear();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
// std::vector<ext::Housamo>& transients = this->getComponent<std::vector<ext::Housamo>>();
@ -120,9 +117,9 @@ void ext::HousamoBattle::initialize() {
// asset loading
this->addHook( "asset:Cache.Voice.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string filename = json["filename"].asString();
@ -140,8 +137,8 @@ void ext::HousamoBattle::initialize() {
this->addHook( "asset:Cache.SFX.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;
ext::World& world = this->getRootParent<ext::World>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string filename = json["filename"].asString();
@ -613,7 +610,7 @@ void ext::HousamoBattle::initialize() {
uf::Serializer& member = transient->getComponent<uf::Serializer>();
uint64_t entid = metadata["battle"]["enemy"]["uid"].asUInt64();
uf::Entity* = this->getRootParent<ext::World>().findByUid(entid);
uf::Entity* = scene.findByUid(entid);
if ( ! ) return "false";
uf::Serializer& hMetadata = ->getComponent<uf::Serializer>();
uint64_t phase = json["phase"].asUInt64();
@ -1436,8 +1433,8 @@ void ext::HousamoBattle::initialize() {
std::cout << "Previous BGM: " << previousMusic << std::endl;
playMusic(*this, previousMusic);
*/
ext::World& world = this->getRootParent<ext::World>();
world.callHook("world:Music.LoadPrevious.%UID%");
uf::Scene& scene = uf::scene::getCurrentScene();
scene.callHook("world:Music.LoadPrevious.%UID%");
gui->callHook("menu:Close.%UID%");
// cleanup
@ -1453,9 +1450,9 @@ void ext::HousamoBattle::initialize() {
// playSound(*this, metadata["battle"]["enemy"]["uid"].asUInt64(), "killed");
// kill
{
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
std::size_t uid = metadata["battle"]["enemy"]["uid"].asUInt64();
uf::Entity* = world.findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ) {
uf::Object& parent = ->getParent<uf::Object>();
->destroy();
@ -1479,9 +1476,9 @@ void ext::HousamoBattle::initialize() {
playSound(*this, metadata["battle"]["enemy"]["uid"].asUInt64(), "killed");
// kill
{
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
std::size_t uid = metadata["battle"]["enemy"]["uid"].asUInt64();
uf::Entity* = world.findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ) {
uf::Object& parent = ->getParent<uf::Object>();
->destroy();
@ -1492,9 +1489,9 @@ void ext::HousamoBattle::initialize() {
// clear battle data on player
{
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
std::size_t uid = metadata["battle"]["player"]["uid"].asUInt64();
uf::Entity* = world.findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ) {
uf::Serializer& pMetadata = ->getComponent<uf::Serializer>();
pMetadata["system"].removeMember("battle");

View File

@ -17,23 +17,19 @@
#include <uf/utils/audio/audio.h>
#include <uf/engine/asset/asset.h>
#include "../world.h"
#include "../gui/dialogue.h"
namespace {
ext::World* world;
ext::Gui* gui;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -43,8 +39,8 @@ namespace {
namespace {
void playSound( ext::DialogueManager& entity, const std::string& id, const std::string& key ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Serializer cardData = masterDataGet("Card", id);
uf::Serializer charaData = masterDataGet("Chara", cardData["character_id"].asString());
@ -57,36 +53,36 @@ namespace {
url = "./data/smtsamo/voice/voice_" + name + "_" + key + ".ogg";
}
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.Voice." + std::to_string(entity.getUid()));
}
void playSound( ext::DialogueManager& entity, std::size_t uid, const std::string& key ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& pMetadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Entity* = world.findByUid(uid);
uf::Entity* = scene.findByUid(uid);
if ( ! ) return;
uf::Serializer& metadata = ->getComponent<uf::Serializer>();
std::string id = metadata[""]["id"].asString();
playSound( entity, id, key );
}
void playSound( ext::DialogueManager& entity, const std::string& key ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = entity.getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string url = "./" + key + ".ogg";
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
assetLoader.cache(url, "asset:Cache.SFX." + std::to_string(entity.getUid()));
}
void playMusic( ext::DialogueManager& entity, const std::string& filename ) {
ext::World& world = entity.getRootParent<ext::World>();
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
assetLoader.load(filename, "asset:Load." + std::to_string(world.getUid()));
assetLoader.load(filename, "asset:Load." + std::to_string(scene.getUid()));
}
uf::Audio sfx;
@ -107,9 +103,9 @@ void ext::DialogueManager::initialize() {
// asset loading
this->addHook( "asset:Cache.Voice.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string filename = json["filename"].asString();
@ -127,8 +123,8 @@ void ext::DialogueManager::initialize() {
this->addHook( "asset:Cache.SFX.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;
ext::World& world = this->getRootParent<ext::World>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
std::string filename = json["filename"].asString();
@ -253,8 +249,8 @@ void ext::DialogueManager::initialize() {
this->addHook( "menu:Dialogue.End.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;
// play music
ext::World& world = this->getRootParent<ext::World>();
world.callHook("world:Music.LoadPrevious.%UID%");
uf::Scene& scene = uf::scene::getCurrentScene();
scene.callHook("world:Music.LoadPrevious.%UID%");
gui->callHook("menu:Close.%UID%");
this->callHook("menu:Dialogue.End");

View File

@ -1,21 +1,17 @@
#include ".h"
#include <uf/engine/scene/scene.h>
#include <uf/utils/serialize/serializer.h>
#include "../world.h"
namespace {
ext::World* world;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {

View File

@ -8,30 +8,24 @@
#include <uf/utils/graphic/graphic.h>
#include <uf/utils/window/window.h>
#include <uf/utils/camera/camera.h>
#include <uf/ext/vulkan/graphic.h>
#include <uf/ext/vulkan/device.h>
#include <uf/ext/vulkan/swapchain.h>
#include <uf/ext/vulkan/vulkan.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/utils/image/image.h>
#include "../world.h"
#include <uf/engine/asset/asset.h>
#include "battle.h"
#include ".h"
namespace {
ext::World* world;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -49,10 +43,10 @@ void ext::HousamoSprite::initialize() {
// this->addAlias<uf::Mesh, uf::MeshBase>();
}
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
uf::Serializer& masterdata = world.getComponent<uf::Serializer>();
uf::Asset& assetLoader = world.getComponent<uf::Asset>();
uf::Serializer& masterdata = scene.getComponent<uf::Serializer>();
uf::Asset& assetLoader = scene.getComponent<uf::Asset>();
this->addHook( "graphics:Assign.%UID%", [&](const std::string& event)->std::string{
uf::Serializer json = event;

View File

@ -1,7 +1,7 @@
#include "light.h"
#include <uf/ext/vulkan/rendertarget.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/utils/math/transform.h>
#include <uf/utils/math/physics.h>
#include <uf/utils/camera/camera.h>
@ -13,9 +13,9 @@ void ext::Light::initialize() {
auto& transform = this->getComponent<pod::Transform<>>();
auto& camera = this->getComponent<uf::Camera>();
if ( metadata["light"]["shadows"]["enabled"].asBool() ) {
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
std::string name = "RT:" + std::to_string((int) this->getUid());
ext::vulkan::addRenderMode( &renderMode, name );
uf::renderer::addRenderMode( &renderMode, name );
if ( metadata["light"]["shadows"]["resolution"].isArray() ) {
renderMode.width = metadata["light"]["shadows"]["resolution"][0].asUInt64();
renderMode.height = metadata["light"]["shadows"]["resolution"][1].asUInt64();
@ -45,8 +45,8 @@ void ext::Light::initialize() {
void ext::Light::tick() {
uf::Object::tick();
if ( this->hasComponent<ext::vulkan::RenderTargetRenderMode>() ) {
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
if ( this->hasComponent<uf::renderer::RenderTargetRenderMode>() ) {
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
renderMode.target = "";
}
@ -55,21 +55,24 @@ void ext::Light::tick() {
pod::Physics& physics = this->getComponent<pod::Physics>();
transform = uf::physics::update( transform, physics );
}
{
uf::transform::rotate( transform, {0, 1, 0}, uf::physics::time::delta );
}
auto& camera = this->getComponent<uf::Camera>();
auto& metadata = this->getComponent<uf::Serializer>();
if ( metadata["light"]["external update"].isNull() || (!metadata["light"]["external update"].isNull() && !metadata["light"]["external update"].asBool()) ) {
// if ( metadata["light"]["external update"].isNull() || (!metadata["light"]["external update"].isNull() && !metadata["light"]["external update"].asBool()) ) {
for ( std::size_t i = 0; i < 2; ++i ) {
camera.setView( uf::matrix::inverse( uf::transform::model( transform ) ), i );
}
}
// }
}
void ext::Light::render() {
uf::Object::render();
}
void ext::Light::destroy() {
if ( this->hasComponent<ext::vulkan::RenderTargetRenderMode>() ) {
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
ext::vulkan::removeRenderMode( &renderMode, false );
if ( this->hasComponent<uf::renderer::RenderTargetRenderMode>() ) {
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
uf::renderer::removeRenderMode( &renderMode, false );
}
uf::Object::destroy();
}

View File

@ -12,7 +12,6 @@
#include <uf/ext/openvr/openvr.h>
#include "../terrain/generator.h"
#include "../world.h"
namespace {
struct {

View File

@ -14,21 +14,16 @@
#include "../gui/pause.h"
#include "../gui/battle.h"
#include "..//.h"
#include "../world.h"
namespace {
ext::World* world;
uf::Serializer masterTableGet( const std::string& table ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table];
}
uf::Serializer masterDataGet( const std::string& table, const std::string& key ) {
if ( !world ) world = (ext::World*) uf::Entity::globalFindByName("World");
if ( !world ) return std::string();
uf::Serializer& mastertable = world->getComponent<uf::Serializer>();
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Serializer& mastertable = scene.getComponent<uf::Serializer>();
return mastertable["system"]["mastertable"][table][key];
}
inline int64_t parseInt( const std::string& str ) {
@ -226,8 +221,8 @@ void ext::Player::initialize() {
std::string state = metadata["system"]["state"].asString();
if ( state != "" && state != "null" ) return "false";
ext::World& world = this->getRootParent<ext::World>();
uf::Entity* entity = world.findByUid(json["entity"].asUInt64());
uf::Scene& scene = uf::scene::getCurrentScene();
uf::Entity* entity = scene.findByUid(json["entity"].asUInt64());
if ( !entity ) return "false";
@ -301,7 +296,7 @@ void ext::Player::tick() {
pod::Transform<>& transform = this->getComponent<pod::Transform<>>();
pod::Physics& physics = this->getComponent<pod::Physics>();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
ext::World& world = this->getRootParent<ext::World>();
uf::Scene& scene = uf::scene::getCurrentScene();
struct {
bool running = uf::Window::isKeyPressed("LShift");

View File

@ -14,10 +14,9 @@
#include <uf/ext/openvr/openvr.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/utils/renderer/renderer.h>
#include "../terrain/generator.h"
#include "../world.h"
namespace {
@ -68,9 +67,9 @@ void ext::Portal::initialize() {
camera = controller.getComponent<uf::Camera>();
}
{
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
std::string name = "RT:" + std::to_string((int) this->getUid());
ext::vulkan::addRenderMode( &renderMode, name );
uf::renderer::addRenderMode( &renderMode, name );
if ( ext::openvr::enabled ) {
ext::openvr::initialize();
@ -85,7 +84,7 @@ void ext::Portal::initialize() {
void ext::Portal::tick() {
uf::Object::tick();
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
renderMode.target = "";
auto& scene = uf::scene::getCurrentScene();
@ -124,7 +123,7 @@ void ext::Portal::tick() {
void ext::Portal::render() {
uf::Object::render();
{
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
auto& blitter = renderMode.blitter;
auto& transform = this->getComponent<pod::Transform<>>();
@ -171,7 +170,7 @@ void ext::Portal::render() {
}
}
void ext::Portal::destroy() {
auto& renderMode = this->getComponent<ext::vulkan::RenderTargetRenderMode>();
ext::vulkan::removeRenderMode( &renderMode, false );
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
uf::renderer::removeRenderMode( &renderMode, false );
uf::Object::destroy();
}

View File

@ -1,4 +1,5 @@
#include "world.h"
#include "scene.h"
#include <uf/utils/time/time.h>
#include <uf/utils/io/iostream.h>
#include <uf/utils/math/vector.h>
@ -23,14 +24,11 @@
#include ".//battle.h"
#include ".//dialogue.h"
#include <uf/ext/vulkan/vulkan.h>
#include <uf/ext/vulkan/rendermodes/deferred.h>
#include <uf/ext/vulkan/rendermodes/rendertarget.h>
#include <uf/ext/vulkan/rendermodes/stereoscopic_deferred.h>
#include <uf/utils/renderer/renderer.h>
#include <uf/ext/openvr/openvr.h>
EXT_OBJECT_REGISTER_CPP(World)
void ext::World::initialize() {
EXT_OBJECT_REGISTER_CPP(TestScene_WorldScape)
void ext::TestScene_WorldScape::initialize() {
uf::Scene::initialize();
this->m_name = "World";
// this->load("./scenes/world/scene.json");
@ -114,7 +112,7 @@ void ext::World::initialize() {
ext::Gui* manager = (ext::Gui*) this->findByName("Gui Manager");
if ( !manager ) return "false";
uf::Serializer payload;
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/world/gui/pause/menu.json", false)).asUInt64() );
ext::Gui* gui = (ext::Gui*) manager->findByUid( (payload["uid"] = manager->loadChild("/scenes/worldscape/gui/pause/menu.json", false)).asUInt64() );
uf::Serializer& metadata = gui->getComponent<uf::Serializer>();
metadata["menu"] = json["menu"];
gui->initialize();
@ -204,8 +202,8 @@ void ext::World::initialize() {
});
/* store viewport size */ {
metadata["window"]["size"]["x"] = ext::vulkan::width;
metadata["window"]["size"]["y"] = ext::vulkan::height;
metadata["window"]["size"]["x"] = uf::renderer::width;
metadata["window"]["size"]["y"] = uf::renderer::height;
this->addHook( "window:Resized", [&](const std::string& event)->std::string{
uf::Serializer json = event;
@ -230,7 +228,7 @@ void ext::World::initialize() {
}
}
void ext::World::tick() {
void ext::TestScene_WorldScape::tick() {
uf::Scene::tick();
uf::Serializer& metadata = this->getComponent<uf::Serializer>();
@ -271,9 +269,18 @@ void ext::World::tick() {
static uf::Timer<long long> timer(false);
if ( !timer.running() ) timer.start();
if ( uf::Window::isKeyPressed("U") && timer.elapsed().asDouble() >= 1 ) { timer.reset();
uf::iostream << "Current size: " << uf::Entity::entities.size() << " | UIDs: " << uf::Entity::uids << "\n";
auto& allocations = uf::Entity::memoryPool.allocations();
uf::iostream << "Current size: " << allocations.size() << " | UIDs: " << uf::Entity::uids << "\n";
uint orphans = 0;
uint empty = 0;
for ( auto& allocation : allocations ) {
uf::Entity* e = (uf::Entity*) allocation.pointer;
if ( !e->hasParent() ) {
++orphans;
uf::iostream << "Orphan: " << e->getName() << ": " << e << "\n";
}
}
/*
for ( uf::Entity* e : uf::Entity::entities ) {
if ( e && !e->hasParent() ) {
++orphans;
@ -281,6 +288,7 @@ void ext::World::tick() {
}
if ( !e ) ++empty;
}
*/
uf::iostream << "Orphans: " << orphans << "\n";
uf::iostream << "Empty: " << empty << "\n";
}
@ -295,6 +303,6 @@ void ext::World::tick() {
}
}
void ext::World::render() {
void ext::TestScene_WorldScape::render() {
uf::Scene::render();
}

View File

@ -7,7 +7,7 @@
#include <uf/engine/scene/scene.h>
namespace ext {
class EXT_API World : public uf::Scene {
class EXT_API TestScene_WorldScape : public uf::Scene {
public:
virtual void initialize();
virtual void tick();

View File

@ -55,7 +55,7 @@ namespace ext {
void generate( ext::Region& );
void rasterize( std::vector<TerrainGenerator::mesh_t::vertex_t>& vertices, const ext::Region& );
// void vectorize( std::vector<ext::vulkan::ComputeGraphic::Cube>&, const ext::Region& );
// void vectorize( std::vector<uf::renderer::ComputeGraphic::Cube>&, const ext::Region& );
std::vector<ext::TerrainVoxel::uid_t> getRawVoxels();
const pod::RLE<ext::TerrainVoxel::uid_t>::string_t& getVoxels() const;

View File

@ -1,6 +1,5 @@
#include "region.h"
#include "../world.h"
#include "../../../ext.h"
#include "generator.h"
#include "..//sprite.h"
@ -63,8 +62,14 @@ void ext::Region::initialize() {
std::string _ = this->getRootParent<uf::Scene>().getComponent<uf::Serializer>()["shaders"]["region"]["suffix"].asString();
if ( _ != "" ) suffix = _ + ".";
}
/*
graphic.material.attachShader("./data/shaders/terrain.stereo.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
graphic.material.attachShader("./data/shaders/terrain."+suffix+"frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
*/
graphic.material.initializeShaders({
{"./data/shaders/terrain.stereo.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
{"./data/shaders/terrain."+suffix+"frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
});
}
this->addHook( "region:Generate.%UID%", [&](const std::string& event)->std::string{

View File

@ -3,7 +3,6 @@
#include "../../../ext.h"
#include <uf/engine/asset/asset.h>
#include "../../world/world.h"
#include "generator.h"
#include "region.h"
@ -485,8 +484,8 @@ bool ext::Terrain::exists( const pod::Vector3i& position ) const {
}
bool ext::Terrain::inBounds( const pod::Vector3i& position ) const {
const ext::World& parent = this->getRootParent<ext::World>();
const pod::Transform<>& player = parent.getController()->getComponent<pod::Transform<>>();
const uf::Scene& scene = uf::scene::getCurrentScene();
const pod::Transform<>& player = scene.getController()->getComponent<pod::Transform<>>();
const uf::Serializer& metadata = this->getComponent<uf::Serializer>();
pod::Vector3ui size = {
metadata["region"]["size"][0].asUInt(),
@ -521,8 +520,8 @@ void ext::Terrain::generate( bool single ) {
metadata["region"]["size"][2].asInt(),
};
ext::World& parent = this->getRootParent<ext::World>();
const pod::Transform<>& player = parent.getController()->getComponent<pod::Transform<>>();
uf::Scene& scene = uf::scene::getCurrentScene();
const pod::Transform<>& player = scene.getController()->getComponent<pod::Transform<>>();
pod::Vector3i location = {
(int) player.position.x / size.x,
(int) player.position.y / size.y,
@ -578,8 +577,9 @@ void ext::Terrain::generate( const pod::Vector3i& position ) {
if ( this->exists(position) ) return;
if ( !this->inBounds(position) ) return;
uf::Entity* base = new ext::Region; this->addChild(*base); {
ext::Region& region = *((ext::Region*)base);
// uf::Entity* base = new ext::Region;
auto& region = uf::instantiator::instantiate<ext::Region>();
this->addChild(region); {
uf::Serializer& m = region.getComponent<uf::Serializer>(); // = metadata;
m["system"]["root"] = metadata["system"]["root"];
m["system"]["source"] = metadata["system"]["source"];