3. Contexts
core6 introduces a new concept called context. A context contains objectlists. Every object belongs to a context which means that the object is stored in the context's objectlists. A context is passed to an object's constructor and replaces the old concept of the creator:
- Old constructor: MyClass(BaseObject* creator) : BaseClass(creator) { ... }
- New constructor: MyClass(Context* context) : BaseClass(context) { ... }
Until now, Objectlists were a part of Identifiers. Because Identifiers are static, Objectlists were also static: there was only one Objectlist for each class. With the introduction of contexts this changes: There may be multiple contexts at the same time, either parallel (if they contain different objects) or hierarchical (if one context contains the other context and all of its objects).
Currently there are 3 classes in Orxonox which represent a context: Namespace, Level, and Scene. Namespace is a concept of the XML-Loader, but Level and Scene are part of the gameplay. This means that every level and every scene has its own object lists. Since scenes are also part of a level, their contexts build a hierarchy. Let me try to explain this:
Objects 1 and 2 are stored in the objectlists of Scene 1
and of Level 1. Objects 3 and 4 are stored in the objectlists of Scene 2 and also of Level 1. Scenes 1 and 2 are also stored in the objectlists of Level 1. Level 2 contains a completely different set of objects.
There is also a root-context. It is part of the framework and it is used whenever an object has no explicit context. It also serves as a root for all other contexts.
Currently contexts don't help a lot. However in future we may change some of our code. Consider the artificial intelligence which uses objectlists to find all enemies. Until now it iterated over the only static objectlist that existed. Now with core6, it iterates over the objectlist of the root-context. However it would be a lot more reasonable to iterate only over the objectlist of the scene because it makes absolutely no sense to attack enemies which reside in a different scene or even in a different level (remember that there is no interaction between scenes at all - different scene-graph, different physics - thus the AI would attack something that doesn't exist).
Thinking even more ahead I can imagine some sort of paging which splits space into multiple sectors (pages). Only objects in active pages are ticked and rendered (and considered by computationally expensive operations like AI and triggers). Until now, this would have been a difficult task. But with core6, each page could represent a context, which would make it trivial to iterate only over objects of active pages.
I hope this helps to understand the changes in core6. Every feedback is appreciated.