Skip to content

Commit

Permalink
gh-67: add rtti system foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Apr 8, 2024
1 parent 03a5ab9 commit c5d78f7
Show file tree
Hide file tree
Showing 132 changed files with 1,845 additions and 533 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function(wmoge_game name)
add_executable(${name} ${arg_SOURCES} ${arg_ICON})
target_link_libraries(${name} PRIVATE ${arg_DEPENDENCIES})
target_include_directories(${name} PRIVATE ${arg_INCLUDES})
message(STATUS "Configure game executable <<${name}>>")
message(STATUS "Configure game executable '${name}' tyoe APPLICATION")
endfunction()

###########################################################
Expand Down
18 changes: 15 additions & 3 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(wmoge STATIC
core/array_view.hpp
core/async.cpp
core/async.hpp
core/buffered_vector.hpp
core/callback_queue.cpp
core/callback_queue.hpp
core/class.cpp
Expand All @@ -28,9 +29,8 @@ add_library(wmoge STATIC
core/crc32.hpp
core/data.cpp
core/data.hpp
core/fast_map.hpp
core/fast_set.hpp
core/fast_vector.hpp
core/flat_map.hpp
core/flat_set.hpp
core/log.cpp
core/log.hpp
core/mask.hpp
Expand Down Expand Up @@ -381,6 +381,18 @@ add_library(wmoge STATIC
resource/loaders/resource_loader_wav.hpp
resource/paks/resource_pak_fs.cpp
resource/paks/resource_pak_fs.hpp
rtti/callable.cpp
rtti/callable.hpp
rtti/class.cpp
rtti/class.hpp
rtti/enum.hpp
rtti/meta_data.hpp
rtti/struct.cpp
rtti/struct.hpp
rtti/traits.hpp
rtti/type_storage.cpp
rtti/type_storage.hpp
rtti/type.hpp
scene/scene_components.cpp
scene/scene_components.hpp
scene/scene_data.cpp
Expand Down
6 changes: 3 additions & 3 deletions engine/audio/openal/al_bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "audio/audio_bus.hpp"
#include "audio/audio_defs.hpp"
#include "audio/openal/al_playback.hpp"
#include "core/fast_set.hpp"
#include "core/flat_set.hpp"

#include <atomic>

Expand All @@ -54,14 +54,14 @@ namespace wmoge {
void set_pitch_scale(float value) override;
void get_playbacks(std::vector<Ref<AudioPlayback>>& playbacks) override;

fast_set<ALAudioPlayback*>& get_playbacks() { return m_playbacks; }
flat_set<ALAudioPlayback*>& get_playbacks() { return m_playbacks; }
AudioBusState get_state() { return m_state; }
float get_gain_scale() { return m_gain_scale; }
float get_pitch_scale() { return m_pitch_scale; }
class ALAudioEngine& get_engine() { return m_engine; }

private:
fast_set<ALAudioPlayback*> m_playbacks;
flat_set<ALAudioPlayback*> m_playbacks;
AudioBusState m_state = AudioBusState::Active;
float m_gain_scale = 1.0f;
float m_pitch_scale = 1.0f;
Expand Down
4 changes: 2 additions & 2 deletions engine/audio/openal/al_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "audio/openal/al_bus.hpp"
#include "audio/openal/al_defs.hpp"
#include "audio/openal/al_playback.hpp"
#include "core/fast_map.hpp"
#include "core/flat_map.hpp"

#include <mutex>

Expand Down Expand Up @@ -65,7 +65,7 @@ namespace wmoge {
bool init_caps();

private:
fast_map<Strid, Ref<ALAudioBus>> m_bus;
flat_map<Strid, Ref<ALAudioBus>> m_bus;
ALCdevice* m_device = nullptr;
ALCcontext* m_context = nullptr;
std::recursive_mutex m_mutex;
Expand Down
30 changes: 15 additions & 15 deletions engine/audio/openal/al_playback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "audio/audio_defs.hpp"
#include "audio/audio_playback.hpp"
#include "audio/openal/al_defs.hpp"
#include "core/fast_vector.hpp"
#include "core/buffered_vector.hpp"

namespace wmoge {

Expand Down Expand Up @@ -64,22 +64,22 @@ namespace wmoge {
void set_max_distance(float value) override;
void set_loop(bool value) override;

fast_vector<ALuint>& get_buffers() { return m_buffers; }
ALuint get_source() { return m_source; }
AudioPlaybackState get_state() { return m_state; }
float get_pitch_scale() { return m_pitch_scale; }
float get_gain() { return m_gain; }
class ALAudioBus* get_bus() { return m_bus; }
class ALAudioEngine& get_engine() { return m_engine; }
buffered_vector<ALuint>& get_buffers() { return m_buffers; }
ALuint get_source() { return m_source; }
AudioPlaybackState get_state() { return m_state; }
float get_pitch_scale() { return m_pitch_scale; }
float get_gain() { return m_gain; }
class ALAudioBus* get_bus() { return m_bus; }
class ALAudioEngine& get_engine() { return m_engine; }

private:
fast_vector<ALuint> m_buffers;
ALuint m_source = AL_NONE;
AudioPlaybackState m_state = AudioPlaybackState::Stopped;
float m_pitch_scale = 1.0f;
float m_gain = 1.0f;
class ALAudioBus* m_bus = nullptr;
class ALAudioEngine& m_engine;
buffered_vector<ALuint> m_buffers;
ALuint m_source = AL_NONE;
AudioPlaybackState m_state = AudioPlaybackState::Stopped;
float m_pitch_scale = 1.0f;
float m_gain = 1.0f;
class ALAudioBus* m_bus = nullptr;
class ALAudioEngine& m_engine;
};

}// namespace wmoge
Expand Down
20 changes: 10 additions & 10 deletions engine/core/async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#pragma once

#include "core/array_view.hpp"
#include "core/fast_vector.hpp"
#include "core/buffered_vector.hpp"
#include "core/ref.hpp"
#include "core/synchronization.hpp"

Expand Down Expand Up @@ -95,19 +95,19 @@ namespace wmoge {
std::lock_guard lock(m_mutex);
m_status.store(AsyncStatus::Failed);

fast_vector<AsyncCallback<T>> callbacks = std::move(m_callbacks);
buffered_vector<AsyncCallback<T>> callbacks = std::move(m_callbacks);
for (auto& c : callbacks) c(AsyncStatus::Failed, m_result);
fast_vector<Ref<AsyncStateBase>> deps = std::move(m_children);
buffered_vector<Ref<AsyncStateBase>> deps = std::move(m_children);
for (auto& d : deps) d->notify(AsyncStatus::Failed, this);
}
virtual void set_result(T&& result) {
std::lock_guard lock(m_mutex);
m_result = std::make_optional(std::forward<T>(result));
m_status.store(AsyncStatus::Ok);

fast_vector<AsyncCallback<T>> callbacks = std::move(m_callbacks);
buffered_vector<AsyncCallback<T>> callbacks = std::move(m_callbacks);
for (auto& c : callbacks) c(AsyncStatus::Ok, m_result);
fast_vector<Ref<AsyncStateBase>> deps = std::move(m_children);
buffered_vector<Ref<AsyncStateBase>> deps = std::move(m_children);
for (auto& d : deps) d->notify(AsyncStatus::Ok, this);
}

Expand Down Expand Up @@ -151,11 +151,11 @@ namespace wmoge {
}

protected:
fast_vector<AsyncCallback<T>> m_callbacks;
fast_vector<Ref<AsyncStateBase>> m_children;
std::optional<T> m_result;
std::atomic<AsyncStatus> m_status{AsyncStatus::InProcess};
SpinMutex m_mutex;
buffered_vector<AsyncCallback<T>> m_callbacks;
buffered_vector<Ref<AsyncStateBase>> m_children;
std::optional<T> m_result;
std::atomic<AsyncStatus> m_status{AsyncStatus::InProcess};
SpinMutex m_mutex;
};

/**
Expand Down
12 changes: 6 additions & 6 deletions engine/core/fast_vector.hpp → engine/core/buffered_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ namespace wmoge {

#ifdef WG_DEBUG
template<typename T, std::size_t MinCapacity = 4>
using fast_vector = std::vector<T>;
using buffered_vector = std::vector<T>;
#else
/**
* @brief Wrapper for ankerl vector with small vector optimization
*/
template<typename T, std::size_t MinCapacity = 4>
using fast_vector = ankerl::svector<T, MinCapacity>;
using buffered_vector = ankerl::svector<T, MinCapacity>;

template<typename T, std::size_t MinCapacity>
Status archive_write(Archive& archive, const fast_vector<T, MinCapacity>& vector) {
Status archive_write(Archive& archive, const buffered_vector<T, MinCapacity>& vector) {
WG_ARCHIVE_WRITE(archive, vector.size());
for (const auto& entry : vector) {
WG_ARCHIVE_WRITE(archive, entry);
Expand All @@ -55,7 +55,7 @@ namespace wmoge {
}

template<typename T, std::size_t MinCapacity>
Status archive_read(Archive& archive, fast_vector<T, MinCapacity>& vector) {
Status archive_read(Archive& archive, buffered_vector<T, MinCapacity>& vector) {
assert(vector.empty());
std::size_t size;
WG_ARCHIVE_READ(archive, size);
Expand All @@ -67,7 +67,7 @@ namespace wmoge {
}

template<typename T, std::size_t MinCapacity>
Status yaml_write(YamlNodeRef node, const fast_vector<T, MinCapacity>& vector) {
Status yaml_write(YamlNodeRef node, const buffered_vector<T, MinCapacity>& vector) {
WG_YAML_SEQ(node);
for (const T& value : vector) {
YamlNodeRef child = node.append_child();
Expand All @@ -77,7 +77,7 @@ namespace wmoge {
}

template<typename T, std::size_t MinCapacity>
Status yaml_read(const YamlConstNodeRef& node, fast_vector<T, MinCapacity>& vector) {
Status yaml_read(const YamlConstNodeRef& node, buffered_vector<T, MinCapacity>& vector) {
assert(vector.empty());
vector.resize(node.num_children());
std::size_t element_id = 0;
Expand Down
12 changes: 6 additions & 6 deletions engine/core/fast_map.hpp → engine/core/flat_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ namespace wmoge {

#ifdef WG_DEBUG
template<typename K, typename V>
using fast_map = std::unordered_map<K, V>;
using flat_map = std::unordered_map<K, V>;
#else
/**
* @brief wrapper for fast robin_hood unordered map
*/
template<typename K, typename V>
using fast_map = robin_hood::unordered_flat_map<K, V>;
using flat_map = robin_hood::unordered_flat_map<K, V>;

template<typename K, typename V>
Status archive_write(Archive& archive, const fast_map<K, V>& map) {
Status archive_write(Archive& archive, const flat_map<K, V>& map) {
WG_ARCHIVE_WRITE(archive, map.size());
for (const auto& entry : map) {
WG_ARCHIVE_WRITE(archive, entry.first);
Expand All @@ -56,7 +56,7 @@ namespace wmoge {
}

template<typename K, typename V>
Status archive_read(Archive& archive, fast_map<K, V>& map) {
Status archive_read(Archive& archive, flat_map<K, V>& map) {
assert(map.empty());
std::size_t size;
WG_ARCHIVE_READ(archive, size);
Expand All @@ -70,7 +70,7 @@ namespace wmoge {
}

template<typename K, typename V>
Status yaml_read(const YamlConstNodeRef& node, fast_map<K, V>& map) {
Status yaml_read(const YamlConstNodeRef& node, flat_map<K, V>& map) {
assert(map.empty());
map.reserve(node.num_children());
for (auto child = node.first_child(); child.valid(); child = child.next_sibling()) {
Expand All @@ -82,7 +82,7 @@ namespace wmoge {
}

template<typename K, typename V>
Status yaml_write(YamlNodeRef node, const fast_map<K, V>& map) {
Status yaml_write(YamlNodeRef node, const flat_map<K, V>& map) {
WG_YAML_SEQ(node);
for (const auto& entry : map) {
YamlNodeRef entry_child = node.append_child();
Expand Down
8 changes: 4 additions & 4 deletions engine/core/fast_set.hpp → engine/core/flat_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ namespace wmoge {

#ifdef WG_DEBUG
template<typename K>
using fast_set = std::unordered_set<K>;
using flat_set = std::unordered_set<K>;
#else
/**
* @brief wrapper for fast robin_hood unordered set
*/
template<typename K>
using fast_set = robin_hood::unordered_flat_set<K>;
using flat_set = robin_hood::unordered_flat_set<K>;

template<typename K>
Status archive_write(Archive& archive, const fast_set<K>& map) {
Status archive_write(Archive& archive, const flat_set<K>& map) {
archive << static_cast<int>(map.size());
for (const auto& entry : map) {
archive << entry;
Expand All @@ -54,7 +54,7 @@ namespace wmoge {
}

template<typename K>
Status archive_read(Archive& archive, fast_set<K>& map) {
Status archive_read(Archive& archive, flat_set<K>& map) {
assert(map.empty());
int size;
archive >> size;
Expand Down
6 changes: 3 additions & 3 deletions engine/core/mask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#pragma once

#include "core/fast_vector.hpp"
#include "core/buffered_vector.hpp"
#include "io/archive.hpp"
#include "io/yaml.hpp"

Expand Down Expand Up @@ -92,7 +92,7 @@ namespace wmoge {

template<typename T, int size>
Status yaml_read(const YamlConstNodeRef& node, Mask<T, size>& mask) {
fast_vector<T, size> flags;
buffered_vector<T, size> flags;
WG_YAML_READ(node, flags);

for (auto flag : flags) {
Expand All @@ -104,7 +104,7 @@ namespace wmoge {

template<typename T, int size>
Status yaml_write(YamlNodeRef node, const Mask<T, size>& mask) {
fast_vector<T, size> flags;
buffered_vector<T, size> flags;

mask.for_each([&](int, T flag) {
flags.push_back(flag);
Expand Down
Loading

0 comments on commit c5d78f7

Please sign in to comment.