Skip to content

Commit

Permalink
test(reflection): cover comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoMendonc-a committed Feb 5, 2024
1 parent a4664c6 commit f0b525f
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 229 deletions.
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()
15 changes: 12 additions & 3 deletions core/include/cubos/core/ecs/blueprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,24 @@ namespace cubos::core::ecs
template <typename T>
using EntityMap = std::unordered_map<Entity, T, EntityHash>;

memory::UnorderedBimap<Entity, std::string, EntityHash> GetEntities() const
/// @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
}
memory::TypeMap<EntityMap<memory::AnyValue>> GetComponents() const

/// @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
}
memory::TypeMap<EntityMap<EntityMap<memory::AnyValue>>> GetRelations() const

/// @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
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/ser/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool JSONSerializer::decompose(const Type& type, const void* value)
{
if (type.get<FieldsTrait>().size() == 1)
{
// If there's a single field, read it directly.
// If there's a single field, write it directly.
if (!this->write(type.get<FieldsTrait>().begin()->type(),
type.get<FieldsTrait>().view(value).begin()->value))

Check warning on line 101 in core/src/data/ser/json.cpp

View check run for this annotation

Codecov / codecov/patch

core/src/data/ser/json.cpp#L100-L101

Added lines #L100 - L101 were not covered by tests
{
Expand Down
Loading

0 comments on commit f0b525f

Please sign in to comment.