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

Refactored entity serialization #163

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .github/workflows/build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ jobs:
-DECSTASY_INTEGRATIONS_SFML_BUILD_DEMO=TRUE
-DECSTASY_INTEGRATIONS_USER_ACTION=TRUE
-DECSTASY_THREAD_SAFE=TRUE
-DECSTASY_ENABLE_ENTITY_SERIALIZERS=FALSE

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j
Expand Down
4 changes: 0 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
"ECSTASY_THREAD_SAFE": {
"type": "BOOL",
"value": "TRUE"
},
"ECSTASY_ENABLE_ENTITY_SERIALIZERS": {
"type": "BOOL",
"value": "FALSE"
}
}
},
Expand Down
1 change: 0 additions & 1 deletion cmake/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ CMAKE_DEPENDENT_OPTION(ECSTASY_INTEGRATIONS_SFML_BUILD_DEMO "Build SFML integrat
CMAKE_DEPENDENT_OPTION(ECSTASY_INTEGRATIONS_USER_ACTION "User Action integration." OFF ECSTASY_INTEGRATIONS_EVENT OFF)

## Serializer formats
option(ECSTASY_ENABLE_ENTITY_SERIALIZERS "Enable serialization methods in I/AStorage classes" OFF)
option(ECSTASY_SERIALIZER_TOML "Build Toml serializer." OFF)

if (${ECSTASY_INTEGRATIONS_USER_ACTION})
Expand Down
1 change: 0 additions & 1 deletion doc/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,3 @@ _In case this documentation is not up to date with the [Options.cmake](/cmake/Op
| ECSTASY_INTEGRATIONS_SFML_BUILD_DEMO | Enable the Sfml integration demos. Requires **ECSTASY_INTEGRATIONS_SFML** | OFF |
| ECSTASY_INTEGRATIONS_USER_ACTION | Enable the User Actions integration. Requires **ECSTASY_INTEGRATIONS_EVENT** | OFF |
| ECSTASY_SERIALIZER_TOML | Enable the Toml Serializer. Force set if **ECSTASY_INTEGRATIONS_USER_ACTION** is set | OFF |
| ECSTASY_ENABLE_ENTITY_SERIALIZERS | **WIP** - Enable the serialization methods in I/AStorage classes. This allows easy entity (de)serialization. | OFF |
14 changes: 11 additions & 3 deletions doc/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,22 @@ Position &operator<<(RawSerializer &serializer)
}
```

#### Working with Entities (WIP)
If you need to (de)serialize the type from the save/update/loadEntity methods, you first need to register the type as serializable by the expected Serializer using the variadic macro @ref REGISTER_SERIALIZABLES

For example, if you want you type Position to be serializable by the RawSerializer and the (maybe to come) JsonSerializer:

```cpp
REGISTER_SERIALIZABLES(Position, RawSerializer, JsonSerializer)
```

#### Working with Entities

Since you can serialize any type, you can serialize entity components manually using the functions above.

If you define **ECSTASY_ENABLE_ENTITY_SERIALIZERS**, you can serialize an entire entity.
You can save entity components explicitly using the templated saveEntity method, or every registered components with the classic saveEntity method.

@warning
This is still work in progress and will certainly be refactored because the underlying code is shit.
To use the non templated `saveEntity` method, you need to register them using the @ref REGISTER_SERIALIZABLES macro (see below).

```cpp
RawSerializer serializer();
Expand Down
2 changes: 0 additions & 2 deletions src/ecstasy/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace ecstasy::thread
#endif
} // namespace ecstasy::thread

// Enable serialization methods in I/AStorage classes
#cmakedefine ECSTASY_ENABLE_ENTITY_SERIALIZERS
// Toml Serializer is available
#cmakedefine ECSTASY_SERIALIZER_TOML

Expand Down
17 changes: 15 additions & 2 deletions src/ecstasy/registry/Registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ namespace ecstasy
template <std::derived_from<ISystem> S>
S &getSystem()
{
return _storages.get<S>();
return _systems.get<S>();
}

///
Expand Down Expand Up @@ -1179,7 +1179,7 @@ namespace ecstasy
void runSystems(size_t group, size_t mask);

///
/// @brief Get a reference to the storages instances.
/// @brief Get a const reference to the storages instances.
///
/// @return constexpr const Instances<IStorage>& Const reference to the storages instance.
///
Expand All @@ -1191,6 +1191,19 @@ namespace ecstasy
return _storages;
}

///
/// @brief Get a reference to the storages instances.
///
/// @return constexpr Instances<IStorage>& Reference to the storages instance.
///
/// @author Andréas Leroux ([email protected])
/// @since 1.0.0 (2024-10-04)
///
constexpr Instances<IStorage> &getStorages()
{
return _storages;
}

private:
Instances<ResourceBase> _resources;
Instances<IStorage> _storages;
Expand Down
3 changes: 2 additions & 1 deletion src/ecstasy/serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ add_subdirectory(traits)

set(SRC
${SRC}
${INCROOT}/ComponentSerializer.hpp
${INCROOT}/EntityComponentSerializer.hpp
${INCROOT}/IEntityComponentSerializer.hpp
${INCROOT}/include.hpp
${INCROOT}/ISerializer.hpp
${INCROOT}/RawSerializer.hpp
Expand Down
270 changes: 0 additions & 270 deletions src/ecstasy/serialization/ComponentSerializer.hpp

This file was deleted.

Loading
Loading