It's *working* right now but i still have some questions :
Networking :
Not really a problem here but i'm still wondering if i'm doing it "right", I'm currently having a NetworkSystem which is filling components with network datas and then other systems will do their job. Basically my filling-datas pattern looks like that :
*New data is arriving with item ID*
allNetEntities = getAllEntitiesPossessingComponent(CNet);
for netEntity in allNetEntities {
net = getComponent(netEntity, CNet)
if net.id == itemID {
pos = getComponent(netEntity, CPosition)
pos.x = itemX
pos.y = itemY
}
}
I'm not into performances optimizations yet but it's a bit ugly, i guess the way to go would be add a NetworkSystem method like addNetEntity(entity, ID) populating a collection of some sort and then getting the item through that list. It seems totally logical but i'm mainly trying to see if i'm going to hit a wall of anti-e/s patterns at some point.
Events :
I'm not comfortable with using an event system here and i don't really know how to handle that myself.
Let's say i'm having a CHealthBar component which contains hp datas and i want to add a little animation when a player is losing health.
An idea that come to mind is just to update that hp data and let the system throws an animation when it detects that newHp < oldHp but it means that the system will always check for that condition. Again it looks like premature optimization but i'm more looking for nice habits.
Another idea would be to play with components which might be a bit more elegant : If the client is receiving new hp data he could update the CHealthBar component and adding a new CNewHp component, which will be handled by the HealthBarSystem and then removed. i'm still having that constant check to do in my loop though.
HealthBar parent/child:
Still with that HealthBar i'm wondering how you attach entities together. That's what i'm doing right now.
[source lang="jscript"]// Playervar playerSprite = DrawableSystem.getBitmapFromFile("player_healer_walking1");var player = this.game.em.createEntity();this.game.em.addComponent(player, new CPosition(netx, nety));this.game.em.addComponent(player, new CNet(id, netx, nety));var pdrawable = this.game.em.addComponent(player, new CDrawable(playerSprite, this.game));// Healthbarvar barSprite = new Bar(0x6CF048, 50, 8);var healthbar = this.game.em.createEntity();this.game.em.addComponent(healthbar, new CHealthBar(player)); // Reference to parent player entitythis.game.em.addComponent(healthbar, new CDrawable(barSprite, pdrawable.sprite));this.game.em.addComponent(healthbar, new CPosition(-25, -40));[/source]
Graphically : Right now my CDrawable takes two arguments, the sprite object and the parent sprite object. Here i don't really respect the rule of data-only components since the constructor is actually doing parent.addChild(child), that's an exception I made and i'm not really proud of it since i will eventually need a method to remove that component from the screen; I used to do that differently by just calling drawableSystem.addOnScreen(component), is that better ?
Events/Graphic datas : Since i don't really know how to handle events i'm a bit stuck on where to put initialization code. In the snippet above i'm writing new Bar() and passing it to my CDrawable component but Adam (from T-Machine) doesn't seem to talk about sad and lonely classes going around your code. I want to put that in the component constructor since it doesn't contain any logic code and is actually *datas* even if i'm initializing stuff in it but i'm not sure about that. Or it could be a method in the system but would need to be abstracted IMO.
Relationship : When the client is receiving new hp datas i need to update that component. I'm having an ID for each player so i need to reach that hp entity starting from the player entity. In my example above the player component doesn't know about the hp component whereas the hp component does know who's its owner, it works, but it's a bit weird to update that hp component.
Pseudo-code :
allHpComponents = getComponents(CHealthBar)
for hpComponent in allHpComponents {
id = getComponentFromEntity(hpComponent.parent, CNet)
if id == netId {
hpComponent.hp = newHp
}
}
I'm having the same kind of code than my network one, the only workaround i can see is to have another component called CHealthBarEntity added to the player entity and redirecting to the healthBar entity, how dirty does that look ?






