Hello,
I am creating a RTS game and want to use entity-system, but there are some questions confuse me.
My quesiton is How to implement space-partition in entitiy-system.
Imageine two approaches below “component-based OOP”vs “entitiy-system”
In “component-based OOP”: component is responsible for processing logic and using message passing to coupling module.
For instance, “SpacePartition” is used to improve querying unit performance in AI.
Entity have a PositionComponent which could SetPosition and SendSyncMessage (very like invoke directly).
SpacePartitionManager subscribe PositionMoveMessage on MessageBus and handle entity’s move in SpacePartition.
class PositionComponent
{
float x, y;
public SetPosition (x, y)
{
if (this.x!=x && this.y!=y)
{
x=y; y=y;
MessageBus.SendSyncMessage(new PositionMoveMessage(entID, x, y));
}
}
}
class SpacePartitionManager
{
void HandleMessage (PositionMoveMessage msg)
{
SpacePartition.Move(msg.entID, msg.x, msg.y); //change data in SpacePartition struct
}
}
In “entitiy-system”, we could not use message passing in component (message passingis OOP concept), component have DATA only!
class SpacePartitionSystem
{
NodeList<SpacePatitionNode> spacePartitionNodes
void Update()
{
foreach(var node in spacePartitionNodes)
{
node.partitionX = node.position.x / 10; // or however your partitioning logic works
node.partitionY = node.position.y / 10; // or however your partitioning logic works
}
}
}
class SpacePatitionNode
{
public PositionComponent position;
public SpacePartitionComponent spacePartition;
}
class SpacePartitionComponent
{
float partitionX;
float partitionY;
}
class PoisitionComponent
{
float x;
float y;
}
--
You received this message because you are subscribed to the Google Groups "Ash Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ash-framewor...@googlegroups.com.
Visit this group at http://groups.google.com/group/ash-framework.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ash Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ash-framewor...@googlegroups.com.
Visit this group at http://groups.google.com/group/ash-framework.
For more options, visit https://groups.google.com/d/optout.
void Update()
{
//...
//all unit ai system's update();
TeleportSystem.Update(); //<--- change UnitPositionComponent and UnitSpacePartitionComponent manually.
//before all navgation system update()
UnitPositionToNavigationPositionSystem.Update(); //since UnitPositionComponent has been changed in TeleportSystem.Update(), so we need synchronous data in NavigationComponent and NavSpacePartitionComponent.
//navgation systems update()
CrawlNavigationSystem.Update() //process moving change NavPositionComponent and SpacePartitionComponent manually.
VehicleNavigationSystem.Update() //process moving change
Nav
PositionComponent and
Nav
SpacePartitionComponent manually.
//after all navgation systems update()
UnitNavigationPositionTo
UnitPostion
System.Update(); //synchronous data back!
// all render system update()
RenderSystem.Update() // which will use UnitPositionComponent.
}
public class PositionComponent
{
private var _position : Vector3D;
public function get position() : Vector3D
{
return _position;
}
public function set position( value : Vector3D ) : void
{
_position = value;
changed = true;
}
public var changed : Boolean;
}
public class SpacePartitionComponent
{
// ...
}
public class SpacePartitionSystem extends System
{
// ...
override public function update( time : Number ) : void
{
for( node = nodes.head; node; node = node.next )
{
if( node.position.changed )
{
// recalculate space partition data in SpacePartitionComponent
node.position.changed = false;
}
}
}
}
public class PositionComponent
{
private var _position : Vector3D;
public function get position() : Vector3D
{
return _position;
}
public function set position( value : Vector3D ) : void
{
_position = value;
// recalculate space partition here
}
public var spacePartition;
}
public class PositionComponent
{
private var _position : Vector3D;
public function get position() : Vector3D
{
return _position;
}
public function set position( value : Vector3D ) : void
{
_position = value;
changed.dispatch( value );
}
public var changed : Signal1 = new Signal1( Vector3D );
}
public class SpacePartitionComponent
{
public var spacePartition;
public function positionChanged( position : Vector3D ) : void
{
// recalculate space partition
}
}
PositionComponent pc = new PositionComponent();
SpacePartitionComponent spc = new SpacePartitionComponent();
entity.add( pc );
entity.add( spc );
pc.changed.add( spc.positionChanged );
public class PositionComponent
{
private var _position : Vector3D;
public function get position() : Vector3D
{
return _position;
}
public function set position( value : Vector3D ) : void
{
_position = value;
changed = true;
}
public var changed : Boolean;
}
public class SpacePartitioning
{
public function update()
{
// update internal partitioning data based on which objects have changed position
}
}
SpacePartitioning sp = new SpacePartitioning();
NavigationSystem = new NavigationSystem( sp );
...