-
Notifications
You must be signed in to change notification settings - Fork 20
Common Tasks
jacobdufault edited this page Jan 17, 2014
·
1 revision
You can use the EntityIndex or the TemplateIndex to lookup entities or templates (respectively) by their ids.
[JsonObject(MemberSerialization.OptIn)]
public class YourSystem: BaseSystem, Trigger.GlobalInput {
public Type[] InputTypes {
get { return new[] { typeof(SomeInputType) }; }
}
public void OnGlobalInput(IGameInput input) {
// a fictitious input type that supplies us with an entity UniqueId and a TemplateId to lookup
SomeInputType command = (SomeInputType)input;
int entityId = command.EntityId;
int templateId = command.TemplateId;
// here's how you retrieve entities and templates by id
IEntity entity = EntityIndex[entityId];
ITemplate template = TemplateIndex[templateId];
// do something with entity and template
}
}
You can use the Real type (in Forge.Utitlies) to simulate floating-point operations while maintaining determinism.
IEntity entity = /* get an entity from somewhere, eg, an update method (Trigger.Update) in a system */;
// get the previous position; only compiles if position data is versioned and has a previous state
entity.Previous<PositionData>();
// get the current position
entity.Current<PositionData>();
// get a reference to a PositionData instance that you can modify
entity.Modify<PositionData>();
These are actually extension methods and not part of the core IQueryableEntity API. The API is defined in terms of DataAccessors. Without the extension methods, getting the current data is still simple; it's just entity.Current(new DataAccessor(typeof(PositionData))
See BallCollisionSystem.GetExecutionOrdering in the sample.