Lightning - modular 2D game engine

Started by Cosmo, January 03, 2022, 01:37:19

Previous topic - Next topic

Cosmo

Lightning is a 2D (with future 3D extensions) game engine designed to be modular, fast, small, and easy to extend. Currently it is around 9 MB, with around 500 KB of actual engine code, split across several DLLs – with the bulk (currently ~230 KB) being located in Lightning.Core.dll, a .NET assembly containing the entire engine.

Lightning is designed around the concept of a DataModel. The DataModel is a strict object hierarchy (parents must be superclasses of the children, children must derive from the classes of their parent) that every single user-API exposed object is a part of. The DataModel is implemented as a static class – State (an InstanceCollection) is the first-level of the DataModel, and Instances are inserted into it or a child of it.

Insertion is controlled by the InstanceCollection class – a custom IEnumerable and IEnumerator implementation that will automatically add an Instance to the root of the DataModel, the Workspace, or its Parent. This is determined – for Parent – by a parameter passed to the Add method, but if an object can be added to the root of the DataModel or Workspace is determiend by its InstanceTags, attributes that are specific to each instance tag – if InstanceTags.ParentCanBeNull is part of the InstanceTags for this particular Instance class (as defined in the Attributes property for a particular Instance), it will be added to the root of the DataModel if Parent is null – if it is not present in the flags, it will be removed from the root of the DataModel.

When the DataModel is initialised or re-initialised (as a part of the game loading process) it initialises two Instances and places them into its children. One of these is the Workspace. which serves as the logical root of the DataModel, and the other is the ServiceControlManager. The ServiceControlManager contains the main loop and contains a collection of Services. A Service is like a process in many operating systems; it is polled on a regular basis and performs a particular set of functions for the engine. An infinite number of services can run – although only one of any particular type can run at once, like a Windows service process. Lightning's main loop is more simple than you may think – at its core, it simply calls Poll() on all running services. (the current version only contains one – RenderService, which handles rendering). Lightning can optionally (using a command line argument) be initialised without any services running, which has been used for a prototype IDE.

This also prevents individual services from crashing each other or the engine if things go wrong, with some services even able to be restarted. It also increases code quality, as rendering, audio, UI, physics (and soon scripting and lighting) are entirely separate from one another.

(Please read READ1ST.TXT before doing anything with this, and feel free to ask any questions!)

Edit: Cannot attach 7z files, so: https://drive.google.com/file/d/1fLMdnV38MXdS0bBfxRPtV6Ff39Aoe52v/view?usp=sharing