Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement save for scenebridge #949

Merged
merged 6 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 146 additions & 148 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

option(WITH_GLFW "With GLFW?" ON)
option(WITH_OPENGL "With OpenGL?" ON)
if (WITH_GLFW)
option(GLFW_USE_SUBMODULE "Compile GLFW from source?" ON)
endif ()

if(WITH_GLFW)
option(GLFW_USE_SUBMODULE "Compile GLFW from source?" ON)
endif()

option(WITH_OPENAL "With OpenAL?" ON)
option(GLM_USE_SUBMODULE "Compile GLM from source?" ON)

Expand All @@ -19,158 +21,155 @@ message("# Building core samples: " ${BUILD_CORE_SAMPLES})
message("# Building core tests: " ${BUILD_CORE_TESTS})

# Set core source files

set(CUBOS_CORE_SOURCE
"src/log.cpp"
"src/thread_pool.cpp"

"src/memory/stream.cpp"
"src/memory/standard_stream.cpp"
"src/memory/buffer_stream.cpp"
"src/memory/any_value.cpp"
"src/memory/any_vector.cpp"

"src/reflection/type.cpp"
"src/reflection/type_registry.cpp"
"src/reflection/traits/constructible.cpp"
"src/reflection/traits/fields.cpp"
"src/reflection/traits/array.cpp"
"src/reflection/traits/dictionary.cpp"
"src/reflection/traits/string_conversion.cpp"
"src/reflection/traits/nullable.cpp"
"src/reflection/traits/enum.cpp"
"src/reflection/external/primitives.cpp"
"src/reflection/external/cstring.cpp"
"src/reflection/external/string.cpp"
"src/reflection/external/string_view.cpp"
"src/reflection/external/uuid.cpp"
"src/reflection/external/glm.cpp"

"src/data/old/serializer.cpp"
"src/data/old/deserializer.cpp"
"src/data/old/json_serializer.cpp"
"src/data/old/json_deserializer.cpp"
"src/data/old/binary_serializer.cpp"
"src/data/old/binary_deserializer.cpp"
"src/data/old/package.cpp"
"src/data/old/context.cpp"

"src/data/fs/file.cpp"
"src/data/fs/file_system.cpp"
"src/data/fs/standard_archive.cpp"
"src/data/fs/embedded_archive.cpp"
"src/data/ser/serializer.cpp"
"src/data/ser/json.cpp"
"src/data/ser/debug.cpp"
"src/data/des/deserializer.cpp"
"src/data/des/json.cpp"

"src/io/window.cpp"
"src/io/cursor.cpp"
"src/io/glfw_window.hpp"
"src/io/glfw_window.cpp"
"src/io/keyboard.cpp"
"src/io/gamepad.cpp"

"src/gl/debug.cpp"
"src/gl/render_device.cpp"
"src/gl/ogl_render_device.hpp"
"src/gl/ogl_render_device.cpp"
"src/gl/util.cpp"

"src/al/audio_device.cpp"
"src/al/oal_audio_device.cpp"
"src/al/oal_audio_device.hpp"

"src/ecs/entity/entity.cpp"
"src/ecs/entity/hash.cpp"
"src/ecs/entity/archetype_graph.cpp"
"src/ecs/entity/archetype_id.cpp"
"src/ecs/entity/pool.cpp"

"src/ecs/table/column.cpp"
"src/ecs/table/dense/table.cpp"
"src/ecs/table/dense/registry.cpp"
"src/ecs/table/sparse_relation/id.cpp"
"src/ecs/table/sparse_relation/table.cpp"
"src/ecs/table/sparse_relation/registry.cpp"
"src/ecs/table/tables.cpp"

"src/ecs/system/access.cpp"
"src/ecs/system/system.cpp"
"src/ecs/system/options.cpp"
"src/ecs/system/dispatcher.cpp"
"src/ecs/system/arguments/commands.cpp"
"src/ecs/system/arguments/query.cpp"
"src/ecs/system/arguments/resources.cpp"
"src/ecs/system/arguments/world.cpp"

"src/ecs/query/term.cpp"
"src/ecs/query/data.cpp"
"src/ecs/query/filter.cpp"
"src/ecs/query/fetcher.cpp"
"src/ecs/query/opt.cpp"

"src/ecs/reflection.cpp"
"src/ecs/blueprint.cpp"
"src/ecs/world.cpp"
"src/ecs/command_buffer.cpp"
"src/ecs/types.cpp"
"src/ecs/cubos.cpp"

"src/geom/box.cpp"
"src/geom/capsule.cpp"
"src/log.cpp"
"src/thread_pool.cpp"

"src/memory/stream.cpp"
"src/memory/standard_stream.cpp"
"src/memory/buffer_stream.cpp"
"src/memory/any_value.cpp"
"src/memory/any_vector.cpp"

"src/reflection/type.cpp"
"src/reflection/type_registry.cpp"
"src/reflection/traits/constructible.cpp"
"src/reflection/traits/fields.cpp"
"src/reflection/traits/array.cpp"
"src/reflection/traits/dictionary.cpp"
"src/reflection/traits/string_conversion.cpp"
"src/reflection/traits/nullable.cpp"
"src/reflection/traits/enum.cpp"
"src/reflection/external/primitives.cpp"
"src/reflection/external/cstring.cpp"
"src/reflection/external/string.cpp"
"src/reflection/external/string_view.cpp"
"src/reflection/external/uuid.cpp"
"src/reflection/external/glm.cpp"

"src/data/old/serializer.cpp"
"src/data/old/deserializer.cpp"
"src/data/old/json_serializer.cpp"
"src/data/old/json_deserializer.cpp"
"src/data/old/binary_serializer.cpp"
"src/data/old/binary_deserializer.cpp"
"src/data/old/package.cpp"
"src/data/old/context.cpp"

"src/data/fs/file.cpp"
"src/data/fs/file_system.cpp"
"src/data/fs/standard_archive.cpp"
"src/data/fs/embedded_archive.cpp"
"src/data/ser/serializer.cpp"
"src/data/ser/json.cpp"
"src/data/ser/debug.cpp"
"src/data/des/deserializer.cpp"
"src/data/des/json.cpp"

"src/io/window.cpp"
"src/io/cursor.cpp"
"src/io/glfw_window.hpp"
"src/io/glfw_window.cpp"
"src/io/keyboard.cpp"
"src/io/gamepad.cpp"

"src/gl/debug.cpp"
"src/gl/render_device.cpp"
"src/gl/ogl_render_device.hpp"
"src/gl/ogl_render_device.cpp"
"src/gl/util.cpp"

"src/al/audio_device.cpp"
"src/al/oal_audio_device.cpp"
"src/al/oal_audio_device.hpp"

"src/ecs/entity/entity.cpp"
"src/ecs/entity/hash.cpp"
"src/ecs/entity/archetype_graph.cpp"
"src/ecs/entity/archetype_id.cpp"
"src/ecs/entity/pool.cpp"

"src/ecs/table/column.cpp"
"src/ecs/table/dense/table.cpp"
"src/ecs/table/dense/registry.cpp"
"src/ecs/table/sparse_relation/id.cpp"
"src/ecs/table/sparse_relation/table.cpp"
"src/ecs/table/sparse_relation/registry.cpp"
"src/ecs/table/tables.cpp"

"src/ecs/system/access.cpp"
"src/ecs/system/system.cpp"
"src/ecs/system/options.cpp"
"src/ecs/system/dispatcher.cpp"
"src/ecs/system/arguments/commands.cpp"
"src/ecs/system/arguments/query.cpp"
"src/ecs/system/arguments/resources.cpp"
"src/ecs/system/arguments/world.cpp"

"src/ecs/query/term.cpp"
"src/ecs/query/data.cpp"
"src/ecs/query/filter.cpp"
"src/ecs/query/fetcher.cpp"
"src/ecs/query/opt.cpp"

"src/ecs/reflection.cpp"
"src/ecs/blueprint.cpp"
"src/ecs/world.cpp"
"src/ecs/command_buffer.cpp"
"src/ecs/types.cpp"
"src/ecs/cubos.cpp"

"src/geom/box.cpp"
"src/geom/capsule.cpp"
)

# Create core library

add_library(cubos-core ${CUBOS_CORE_SOURCE})
target_include_directories(cubos-core PUBLIC "include")
target_compile_definitions(cubos-core PUBLIC
-DCUBOS_CORE_ECS_MAX_COMPONENTS=${CUBOS_CORE_ECS_MAX_COMPONENTS}
-DCUBOS_CORE_DISPATCHER_MAX_CONDITIONS=${CUBOS_CORE_DISPATCHER_MAX_CONDITIONS}
-DCUBOS_CORE_ECS_MAX_COMPONENTS=${CUBOS_CORE_ECS_MAX_COMPONENTS}
-DCUBOS_CORE_DISPATCHER_MAX_CONDITIONS=${CUBOS_CORE_DISPATCHER_MAX_CONDITIONS}
)
cubos_common_target_options(cubos-core)

# Link dependencies
if(WITH_OPENGL)
set(GLAD_SOUURCES_DIR "lib/glad")
add_subdirectory("${GLAD_SOUURCES_DIR}/cmake" glad_cmake SYSTEM)
glad_add_library(glad REPRODUCIBLE API gl:core=3.3)
target_link_libraries(cubos-core PRIVATE glad)
target_compile_definitions(cubos-core PRIVATE WITH_OPENGL)
endif()

if (WITH_OPENGL)
set(GLAD_SOUURCES_DIR "lib/glad")
add_subdirectory("${GLAD_SOUURCES_DIR}/cmake" glad_cmake SYSTEM)
glad_add_library(glad REPRODUCIBLE API gl:core=3.3)
target_link_libraries(cubos-core PRIVATE glad)
target_compile_definitions(cubos-core PRIVATE WITH_OPENGL)
endif ()

if (WITH_GLFW)
if (GLFW_USE_SUBMODULE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/glfw)
else ()
find_package(glfw3 REQUIRED)
endif ()

target_link_libraries(cubos-core PRIVATE glfw)
target_compile_definitions(cubos-core PRIVATE WITH_GLFW)
endif ()

if (WITH_OPENAL)
set(ALSOFT_UTILS OFF CACHE BOOL "" FORCE)
set(ALSOFT_NO_CONFIG_UTIL OFF CACHE BOOL "" FORCE)
set(ALSOFT_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/openal-soft)
target_include_directories(cubos-core PRIVATE lib/openal-soft/include)
target_link_libraries(cubos-core PRIVATE OpenAL)
target_compile_definitions(cubos-core PRIVATE WITH_OPENAL)
if(WITH_GLFW)
if(GLFW_USE_SUBMODULE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/glfw)
else()
find_package(glfw3 REQUIRED)
endif()

target_link_libraries(cubos-core PRIVATE glfw)
target_compile_definitions(cubos-core PRIVATE WITH_GLFW)
endif()

if (GLM_USE_SUBMODULE)
add_subdirectory(lib/glm SYSTEM)
else ()
find_package(glm REQUIRED)
endif ()
if(WITH_OPENAL)
set(ALSOFT_UTILS OFF CACHE BOOL "" FORCE)
set(ALSOFT_NO_CONFIG_UTIL OFF CACHE BOOL "" FORCE)
set(ALSOFT_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/openal-soft)
target_include_directories(cubos-core PRIVATE lib/openal-soft/include)
target_link_libraries(cubos-core PRIVATE OpenAL)
target_compile_definitions(cubos-core PRIVATE WITH_OPENAL)
endif()

if(GLM_USE_SUBMODULE)
add_subdirectory(lib/glm SYSTEM)
else()
find_package(glm REQUIRED)
endif()

set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(lib/json)
Expand All @@ -186,12 +185,11 @@ target_link_libraries(cubos-core PUBLIC glm::glm nlohmann_json::nlohmann_json ${
target_link_libraries(cubos-core PRIVATE Threads::Threads)

# Add core tests

if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_CORE_TESTS)
add_subdirectory(tests)
endif ()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_CORE_TESTS)
add_subdirectory(tests)
endif()

# Add core samples
if (BUILD_CORE_SAMPLES)
add_subdirectory(samples)
endif ()
if(BUILD_CORE_SAMPLES)
add_subdirectory(samples)
endif()
31 changes: 23 additions & 8 deletions core/include/cubos/core/ecs/blueprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@
/// @param relation Relation.
using Relate = void (*)(void* userData, Entity fromEntity, Entity toEntity, memory::AnyValue relation);

/// @brief Constructs.
Blueprint();

/// @brief Move constructs.
/// @param other Blueprint to move from.
Blueprint(Blueprint&& other) noexcept;

/// @brief Creates a new entity in the blueprint and returns it.
///
/// An entity with the same name must not exist. The name must be @ref validEntityName
Expand Down Expand Up @@ -166,10 +159,32 @@
/// @return Whether the name is valid.
static bool validEntityName(const std::string& name);

private:
template <typename T>
using EntityMap = std::unordered_map<Entity, T, EntityHash>;

/// @brief Gets the map relating entities to their name
/// @return Bimap relating entities and names
memory::UnorderedBimap<Entity, std::string, EntityHash> entities() const

Check warning on line 167 in core/include/cubos/core/ecs/blueprint.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/ecs/blueprint.hpp#L167

Added line #L167 was not covered by tests
{
return mBimap;

Check warning on line 169 in core/include/cubos/core/ecs/blueprint.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/ecs/blueprint.hpp#L169

Added line #L169 was not covered by tests
}

/// @brief Gets the map relating types of components to maps of entities to the component values.
/// @return TypeMap of an EntityMap to component values
memory::TypeMap<EntityMap<memory::AnyValue>> components() const

Check warning on line 174 in core/include/cubos/core/ecs/blueprint.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/ecs/blueprint.hpp#L174

Added line #L174 was not covered by tests
{
return mComponents;

Check warning on line 176 in core/include/cubos/core/ecs/blueprint.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/ecs/blueprint.hpp#L176

Added line #L176 was not covered by tests
}

/// @brief Gets the map relating types of relations to maps of entities to maps of entities to the component
/// values.
/// @return TypeMap of an EntityMap to another EntityMap to component values
memory::TypeMap<EntityMap<EntityMap<memory::AnyValue>>> relations() const

Check warning on line 182 in core/include/cubos/core/ecs/blueprint.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/ecs/blueprint.hpp#L182

Added line #L182 was not covered by tests
{
return mRelations;

Check warning on line 184 in core/include/cubos/core/ecs/blueprint.hpp

View check run for this annotation

Codecov / codecov/patch

core/include/cubos/core/ecs/blueprint.hpp#L184

Added line #L184 was not covered by tests
}

private:
/// @brief Maps entities to their names.
memory::UnorderedBimap<Entity, std::string, EntityHash> mBimap;

Expand Down
4 changes: 4 additions & 0 deletions core/include/cubos/core/memory/any_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ namespace cubos::core::memory
/// @param other Value.
AnyValue(AnyValue&& other) noexcept;

/// @brief Copy constructs.
/// @param other Value.
AnyValue(const AnyValue& other) noexcept;

/// @brief Move assignment.
/// @param other Value.
AnyValue& operator=(AnyValue&& other) noexcept;
Expand Down
Loading
Loading