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

Rewrite the ECS in C++ #142

Merged
merged 29 commits into from
Nov 20, 2023
Merged

Rewrite the ECS in C++ #142

merged 29 commits into from
Nov 20, 2023

Conversation

JackAshwell11
Copy link
Owner

@JackAshwell11 JackAshwell11 commented Oct 29, 2023

Description of Changes

This PR rewrites the Python ECS in C++ optimising the ECS design as well as offering a multitude of other improvements to the project structure and the generation module.

Type of Changes

Type
🐛 Bug Fix
✨ New Feature
🔨 Refactoring
📝 Miscellaneous

Tasks

  • Rewrite the ECS module and implement automated testing for it.
  • Add the Python bindings and stub files for the ECS module.
  • Update the Python project to work with the new ECS.
  • Refactor the generation module.
  • Add Clang-tidy and Clang-format to the C++ project Clang-tidy and Clang-format have been added, but Clang-tidy is currently not enabled in the CMake build and will be fixed at a later date.
  • Fix the CI build issues and add coverage Coverage is added, but the CI build issues will be fixed at a later date.
  • Add Python unit tests for the Python bindings This will be looked into at a later date.
  • Potentially switch to a package manager like Conan or vcpkg This will be looked into at a later date.

Added a bunch of components ready for the ECS conversion.
All the logic for the components, the entity component system, and the systems are done, just need to finish the tests and all the remaining errors/warnings.
Rearranged systems into systems/.

Moved SteeringMovement.walls into the registry.

Refactored all tests and improved some.

Fixed various typing and linting problems including changing Vec2d to a normal class.
…riable names.

Added __eq__ and __hash__ to Vec2d since removing the NamedTuple inheritance causes all the tests to fail as they couldn't compare two vectors or store the vectors in sets.

Added registry.update() to game.py so the systems can be updated.
Registry.create_game_object() now deep copies components to prevent modifications on one instance of a game object from affecting others.

Rewrote constructors.py, so it conforms to the new ECS design and allows for deep copies.

Added boolean parameter to HadesSprite to simplify the design for calculating the entity's force.

Fixed last remaining type errors.
…ON is now not needed and all files are listed in the root CMakeLists.txt.

Added SYSTEMS set to game_objects/__init__.py as well as fixing various runtime bugs related to game_objects.

Added submodules to binding.cpp.
…hat has the primitives for generation/ and game_objects/ at a later date.

Added addition to angle_between() since the Python modulo operator can handle negatives, but the C++ std::fmod cannot so the value needs to be positive.

Implemented steering.cpp and its tests.
Implemented components.hpp and its source file as well as its test file.

Added registry.hpp and implemented some of the methods.

Added base.hpp which needs to be implemented.

Private variables have an underscore postfix to differentiate them.

Improved CMakeLists.txt path variables.

Renamed Fixtures to the specific subdirectory name.
Moved hash_combine to base.hpp.

Improved documentation.

Still have a few things left to do and one more method to move out of Vec2d (which is causing some problems).
…l as made all members in GameObjectAttributeBase private.

Fixed all bugs and redesigned registry.hpp as well as implementing all tests for it.

Inline some stuff in primitives.hpp and steering.hpp.

Renamed all templates from class to typename.
… rest of the files for systems/.

Added type aliases for registry.hpp as well, as removing default constructors and renaming some method names.

Added .capacity() to Inventory component.

Improved Vec2d operators.

Removed test_int for TestGameObjectComponentTwo.
…hpp.

Renamed INCLUDE_PATH to INCLUDE_DIR.

Registry.cpp and registry.hpp now throws exceptions.

Changed Footprints to use a deque.

Added macros.hpp to abstract testing for an exception and message as well as moving all fixtures for game_objects/ to their individuals files.

Added documentation for each test.

Changed a few types.
…cpp as well as fixed a bug with test_inventory.cpp where the fixtures were called the same as in test_attacks.cpp creating a SEH exception.

Reformatted some stuff and refactored some other bits to improve definitions and code quality.

Changed get_kinematic_object to return a pointer.

Removed GameObjectAttributeException and GameObjectAttributeBase's boolean has() methods are now public instead of private since it created an issue.
Moved all systems to being stateful instead of some static methods.

Optimised some definitions and methods and moved some things around.

Improve the raycast lambda function.

Renamed all Fixtures to Fixture.

Added more type aliases to registry.hpp.
…the Stat class and split up into multiple separate components and systems. This includes the ArmourRegenSystem, the DamageSystem and the UpgradeSystem. We still have to implement the EffectSystem though.

Added extra implementation of Registry::get_component allowing the user to pass in a std::type_index.

Updated dependencies.

Renamed base.hpp to hash_combine.hpp.
…e leftover time if delta time covers multiple intervals and will apply the status effect on subsequent updates.

Moved Stat and all of its subclasses to a separate stats.hpp header.

Changed some comments, includes and documentation.

Optimised a few things.
…arate.

Changed Registry::create_game_object, so it now just creates the game object. This lead to the creation of add_component which adds a component to a given game object. Also changed the add_system method to work similarly to add_component.

Added all bindings for game_objects/ and started working on stub files. Just have a bug with create_game_object.

Modified a few definitions, includes, docs and comments to be more up to date and improved.

Renamed Inventory::capacity() to Inventory::get_capacity().
Rearranged CMakeLists.txt and made all compiler warnings appear as errors.
…timised and is inline with game_objects/.

Changed the structure of CMakeLists.txt by moving some statements around, making it much easier to understand and more flexible.

Got clang-tidy and cppcheck to run during CMake build. However, I'm not too sure about their configurations, so they're disabled for now and can be enabled at a later date.

Changed the ordering of include statements to conform to the Google style.
pre-commit-ci bot and others added 8 commits October 29, 2023 21:00
Made SystemBase a class and added get_registry() to access the registry attribute. Also changed the constructor to use a pointer instead of a reference as well as making all update() methods const.

Modified all components to just hold data and not have any methods. If a struct has any methods, it becomes a class.

Simplified the AttackSystem design to not use AttackResult.

Updated a few tests that only worked in Debug mode, but failed in Release mode.

Solved a few clang-tidy and cppcheck linting errors, but there's still more to go.

Modified a few comments to be easier to read and understand.

Added const to a few other variables and optimised various bits.
Changed and removed some comments, definitions, and constructors, so they're more efficient and easier to use.

Fixed coverage configuration. It should now generate the coverage files for gcov (which still needs to be setup).

Used list initialisation wherever possible.

Reformatted .clang-tidy.
Started transitioning the Python project to use the new C++ ECS.

Nearly completed the stub files for the C++ project. The bindings do need a bit of rearranging to make them easier to use and to remove unnecessary stuff.

There's just a few registry methods left to bind, but that may require a redesign.
…rk better with the python bindings.

Added type traits for components and systems to deduce their name for the collections on compile time. This avoids the use of typeid() and ensures that the program won't compile if a component or system hasn't implemented the trait.

Started fixing the remaining python binding code.
…rrectly works. This did require removing some attributes for some components in Python, but they probably won't be used.

Updated all the stub files and rearranged the binding modules, so they're easier to understand.

Updated the Python project to use the new C++ ECS.

Renamed the C++ project's test directory to tests to be more in-line with the Python project.

Added CMakePresets.json and improved .gitignore.

Rewrote RegistryError to provide more helpful error messages.

Added some more tests to the C++ project and made sure all the existing ones pass on MSVC and GCC.
Improved .gitignore even more.

Fixed the Python CI test errors. The remaining C++ CI build errors will be fixed at a later date.
@JackAshwell11 JackAshwell11 merged commit 149cfe3 into main Nov 20, 2023
3 of 10 checks passed
@JackAshwell11 JackAshwell11 deleted the ecs-cpp-rewrite branch November 20, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant