Hello everyone,
As some of you may already know, I spent some time designing a small game framework
in order to help me with my future projects. Unfortunately, because of the
university entry exams, I didn't really have a lot of time to spend on it.
Now that the exams are almost finished I thought I should start working seriously on
the actual design of the framework. I did make a prototype but C++ didn't prove that great for prototyping.
I am now making a prototype in Python and I will port it to C++ if the performance proves inadequate.
My goal is not to make a framework with incredible performance. What I want to achieve is a core which will allow me to easily implement features, without worrying about dependencies and coupling while also keeping the maintainable code to the minimum.
I have settled on a self-registration entity-component system where the entities register to the systems according to the components that they hold. All the registration functionality should remain hidden and the user should only have to provide a registration condition for each system.
Here is a small example in Python:
import veritas_framework as vf
class TestComponent:
pass
class TestSystem(vf.System):
def registration_condition(self, entity):
return entity.has_component(TestComponent) # Take note that we use the type here
def update(self, delta=0):
for entity in self.entities:
print "updated"
engine = vf.Engine()
test_system = TestSystem()
engine.add_to_systems(test_system) # Here we use the object
engine.add_to_pipeline(test_system)
entity = vf.Entity(engine) # The entity will signal the engine when it updates it's components
engine.update() # Nothing happens
test_comp = TestComponent()
entity.add_component(test_comp) # Passing an object again
engine.update() # Prints "updated"
entity.remove_component(TestComponent) # Here we use the type
engine.update() # Nothing happens
What I am having troubles with is small inconsistencies in the design.
We actually pass the objects when we add a system or a component but we use the types
to remove them or test if they exist.
This is because both the engine and the entity classes should only
keep 1 object per system or component type accordingly. I think this is not obvious with the current design.
One way to solve this is to actually use the type when we add a system/component and the function would return
the created object for further manipulation, however I am not sure whether this is acceptable .
Any help is much appreciated!
~Veritas