Basic 2D Game Engine
This is my second 2D game engine that I wrote for university, this time using C++, SFML, and ImGui.
To make this engine stand out from my previous 2D game engine, I decided to research and implement an important core game engine architectural pattern, being an Entity Component System, or ECS for short. ECS is a way for developers to fix the issue of inheritance within game engines. The issue being that objects within games, even objects that are very different from each other, may end up sharing a lot of data, leading to a massive amount of very specialised object classes. For example, say you wanted to create a base class for objects that are visible, such as for a Player class and or an Animal class to inherit from. Now say that you aslo want to create a trigger class, to trigger some sort of logic when the player enters it. To do this with simple inheritance, you'd have to have two base classes here, one for visible objects, and one for invisible objects. Both objects are going to have some data that's the same, say their position for example, which you'll have to manually define in each. Now say that you also decide that you want to have an Animal object, that inherits from the visible object base class, that also has an invisible trigger on it, say a horse with a trigger that makes the player start riding it. This is where inheritance begins to become an issue for game engines. Luckily ECS architecture is the most popular way to remedy the issue, being used in massive engines, such as Unity, and Godot 4. An ECS is made up of three core concepts, being entities, components, and systems. Entities no longer directly hold any logic or data, and are instead just a unique ID. Components are just containers of entity data, one example being a TransformComponent, which would hold position, rotation, and scale data for an object. Systems are containers of game logic, which act upon entities that have a specific set of components. For example, a MovementSystem would only act upon entities that have both a TransformComponent and a VelocityComponent assigned to them. This means that creating our horse object with a trigger, would be as easy as creating an entity, and assigning a TransformComponent, TriggerComponent, and SpriteComponent to it. An example of an object in my engine, using the ECS, is my player object. The player object has seven components, being a TransformComponent, a SpriteComponent, a PhysicsComponent, a MovementComponent, a BoundingBoxComponent, an AnimationComponent, and an InputComponent. Creating a complex object like this with inheritance would need it's own specialised class, and any logic within it would not be useable by any other objects. Where as any object in an ECS could use, for example, the SpriteComponent to draw, or the BoundingBoxComponent to handle simple box collisions.