-
Notifications
You must be signed in to change notification settings - Fork 1
Engine Class
The main Engine class connects all the engine components together into one. orchestrating them together. While you can choose whichever implementation you want for the graphics, or whether you want to use something like sound or not, it requires two components to always be present: A Graphics renderer and an Event Bus.
The engine requires an IGraphicsEngine to render everything and an IEventBus to notify about updates. The built in implementations like the one using Raylib is already set up to render it and notify an IEventBus for updates.
You may create your own engine components if you'd like, however when creating them do make sure to notify the event bus accordingly.
Engine components can only be set up upon class instantiation, to make sure nothing can randomly change one graphics engine to another mid game. To attach any engine components, you may do so when createing your instance:
var builder = new EngineBuilder();
builder.AddComponent<IGraphicsEngine, RaylibGraphicsEngine>(() => new RaylibGraphicsEngine(initParams), true);
builder.AddComponent<IEventBus, EventBus>();
builder.AddComponent<ISomething, Something>(true); // Using default parameterless constructor but also running in separate thread.If any core engine components are missing, the engine throws an exception warning which component is missing and shuts down.
Frequently updated components like a Graphics Engine or Physics Engine should be initialized in their own thread, making sure they don't interfere with one another.
It first starts the GraphicsEngine and then the rest of the components in the order they were attached.
The engine handles entities with Engine.CreateEntity(Entity entity) and Engine.RemoveEntity(Entity entity). If an entity is not passed to these methods then it will never be notified about updates and it can only add entities after it's running.
The engine automatically shuts down everything whenever there is a crash, but you may manually call it by using Engine.Instance.Shutdown(). This will shut down the graphics engine, then the physics engine, then any remaining components.