So, while we might be the laziest people on the northern hemisphere we have actually made some progress on our engine. Alfred have been working on the c++ and wrapping side to expose more stuff. My efforts have been put into the other side of the engine, the stuff in C# and IronPython.
I have added a SpatialComponent that handles an objects position and rotation in the world. Coupled with this there is now a SpatialComponentManager that registers all SpatialComponents and enables us to do things like GetObjectsWithinRadius(x,y,z,r).
One fundamental problem is when some data in one component is needed in another component.
Like for example, our SpriteComponent needs a position (which i stored in the SpatialComponent)
The way we have "solved" it at this point is simply storing a reference to the SpatialComponent in the SpriteComponent and each frame reading the data from there. This is quite messy, but works, for now.
I have also thought a bit about how an actual game could be structured so a future editor could be built easily.
Game Folder Structure-- Templates (Contains Xml files with "templates" for entities. That is, the entities components and parameters)
-- Assets (Containing Models/Textures/Sounds/Music etc)-- Components (Containing pure python components referenceable in Templates. Not finished)-- Scenes (Xml files describing the different levels or stages in a game. With lists of templates and scripts, Not finished)-- boot.py (A python script that boots the game)
boot.py (reduces the amount of recompiles when we only change script files)engine.CreateEntity("Templates/TestEntity.xml", "TestEntity")
engine.CreateEntity("Templates/TriggerEntity.xml", "TriggerEntity")
The CreateEntity function parses the entity-template-xml-file passed and creates an Entity with the appropriate components. For now it's just an ugly switch clause that handles all component types separately. This needs to be streamlined. With a bit of Reflection magic it'll be a breeze.
An Entity Template: TriggerEntity.xml
(When instanced in the game this entity changes the background color when other entities are near)
<?xml version="1.0" encoding="utf-8" ?>
<template name="TriggerEntity">
<components>
<component type="SpatialComponent" />
<component type="SpriteComponent" Texture="Assets/Textures/Kid1.png" Size="64,64,0" />
<component type="ScriptComponent">
<![CDATA[
class TriggerClass:
"""TriggerClass"""
def EveryFrame(self, sender, args):
objects = engine.SpatialManager.GetObjectsWithinRadius(self.spatial, 300)
if (objects.Count > 0):
engine.Core.GraphicsEngineSetClearColor(255, 0, 0)
else:
engine.Core.GraphicsEngineSetClearColor(0, 128, 0)
def __init__(self):
self.spatial = entity.GetComponent("SpatialComponent")
self.spatial.X = 512
self.spatial.Y = 512
self.spatial.RotationZ = 90
engine.TestEveryFrame += self.EveryFrame
def __del__(self):
engine.TestEveryFrame -= self.EveryFrame
TriggerClass()
]]>
</component>
</components>
</template>