public void Preallocation() { void BuildEntity(IEntityFactory entityFactory) { var init = entityFactory.BuildEntity <TestEntityDescriptor>(new EGID(0, @group)); init.Init(new UnmanagedComponent() { test = 2 }); } var generateEntityFactory = _enginesRoot.GenerateEntityFactory(); generateEntityFactory.PreallocateEntitySpace <TestEntityDescriptor>(group, 100); generateEntityFactory.BuildEntity <TestEntityDescriptor>(new EGID(0, group)); _simpleEntitiesSubmissionScheduler.SubmitEntities(); //warm up method _simpleEntitiesSubmissionScheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_simpleEntitiesSubmissionScheduler); generateEntityFactory = _enginesRoot.GenerateEntityFactory(); generateEntityFactory.PreallocateEntitySpace <TestEntityDescriptor>(group, 100); Assert.That(() => BuildEntity(generateEntityFactory), Is.Not.AllocatingGCMemory()); Assert.That(_simpleEntitiesSubmissionScheduler.SubmitEntities, Is.Not.AllocatingGCMemory()); _enginesRoot.Dispose(); }
private EntitiesDB GetEntitiesDbFromEnginesRoot(EnginesRoot enginesRoot) { return((EntitiesDB)enginesRoot.GetType() .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .First(x => x.Name == "_entitiesDB") .GetValue(enginesRoot)); }
public void Setup() { _simpleEntitiesSubmissionScheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_simpleEntitiesSubmissionScheduler); _testEngine = new TestEngine(@group); _enginesRoot.AddEngine(_testEngine); }
void CompositionRoot <T>() { var unityEntitySubmissionScheduler = new UnityEntitiesSubmissionScheduler("oop-abstraction"); _enginesRoot = new EnginesRoot(unityEntitySubmissionScheduler); var moveCubesEngine = new MoveCubesEngine(); var moveSpheresEngine = new MoveSpheresEngine(); var selectParentEngine = new SelectNewParentEngine(); var listOfEnginesToTick = new FasterList <IStepEngine>(new IStepEngine[] { moveCubesEngine , moveSpheresEngine , selectParentEngine }); var tickingEnginesGroup = new TickingEnginesGroup(listOfEnginesToTick); _enginesRoot.AddEngine(tickingEnginesGroup); _enginesRoot.AddEngine(moveCubesEngine); _enginesRoot.AddEngine(moveSpheresEngine); _enginesRoot.AddEngine(selectParentEngine); OOPManagerCompositionRoot.Compose(_enginesRoot, listOfEnginesToTick, NUMBER_OF_SPHERES); }
public DebugRoot(EnginesRoot root) { EnginesRoot = root; //Engines = (HashSet<IEngine>) EnginesField.GetValue(root); Root = (FasterDictionary <ExclusiveGroupStruct, FasterDictionary <RefWrapperType, ITypeSafeDictionary> >)EntityDBField.GetValue(root); Process(); }
void CreateUnityECSWorldForSvelto(SimpleEntitiesSubmissionScheduler scheduler, EnginesRoot enginesRoot) { world = new World("Svelto<>UECS world"); var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems); World.DefaultGameObjectInjectionWorld = world; //This is the UECS group that takes care of all the UECS systems that creates entities //it also submits Svelto entities _sveltoUecsEntitiesSubmissionGroup = new SveltoUECSEntitiesSubmissionGroup(scheduler); //This is the group that handles the UECS sync systems that copy the svelto entities values to UECS entities enginesRoot.AddEngine(_sveltoUecsEntitiesSubmissionGroup); world.AddSystem(_sveltoUecsEntitiesSubmissionGroup); _syncSveltoToUecsGroup = new SyncSveltoToUECSGroup(); enginesRoot.AddEngine(_syncSveltoToUecsGroup); _syncUecsToSveltoGroup = new SyncUECSToSveltoGroup(); enginesRoot.AddEngine(_syncUecsToSveltoGroup); //This is the group that handles the UECS sync systems that copy the UECS entities values to svelto entities //enginesRoot.AddEngine(new SveltoUECSEntitiesSubmissionGroup(scheduler, world)); enginesRoot.AddEngine(this); _enginesRoot = enginesRoot; }
void ICompositionRoot.OnContextCreated(UnityContext contextHolder) { var tasksCount = NumberOfEntities.value; #if FIRST_TIER_EXAMPLE || SECOND_TIER_EXAMPLE || THIRD_TIER_EXAMPLE var boidDescriptor = new BoidEntityDescriptor(new[] { new Boid() }); #else var boidDescriptor = new BoidEntityDescriptor(); #endif #if DONT_TRY_THIS_AT_HOME for (int i = 0; i < tasksCount; i++) { GameObject crazyness = new GameObject(); crazyness.AddComponent <UnityWay>(); } #else IEnginesRoot enginesRoot; IEntityFactory entityFactory = (enginesRoot = new EnginesRoot(new UnitySumbmissionNodeScheduler())) as IEntityFactory; var boidsEngine = new BoidsEngine(); enginesRoot.AddEngine(boidsEngine); _contextNotifier.AddFrameworkDestructionListener(boidsEngine); for (int i = 0; i < tasksCount; i++) { entityFactory.BuildEntity(i, boidDescriptor); } entityFactory.BuildEntity(0, new GenericEntityDescriptor <PrintTimeNode>(contextHolder.GetComponentInChildren <PrintIteration>())); #endif }
public static ICompositionRoot EnableSveltoDebugWindow(this ICompositionRoot compositionRoot, EnginesRoot enginesRoot) { CompositionRoot = compositionRoot; EnginesRoot = enginesRoot; return(compositionRoot); }
public DebugRoot(EnginesRoot root) { EnginesRoot = root; Engines = (HashSet <IEngine>)EnginesField.GetValue(root); Root = (FasterDictionary <uint, Dictionary <Type, ITypeSafeDictionary> >)EntityDBField.GetValue(root); Process(); }
public void OnContextInitialized <T>(T contextHolder) { QualitySettings.vSyncCount = -1; _enginesRoot = new EnginesRoot(new UnityEntitySubmissionScheduler()); //add the engines we are going to use var generateEntityFactory = _enginesRoot.GenerateEntityFactory(); var foodEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(Resources.Load("Sphere") as GameObject, _world); _world.EntityManager.AddComponent <UnityECSFoodGroup>(foodEntity); var doofusEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(Resources.Load("Capsule") as GameObject, _world); _world.EntityManager.AddComponent <UnityECSDoofusesGroup>(doofusEntity); _enginesRoot.AddEngine(new PlaceFoodOnClickEngine(foodEntity, generateEntityFactory)); _enginesRoot.AddEngine(new SpawningDoofusEngine(doofusEntity, generateEntityFactory)); AddEngine(new LookingForFoodDoofusesEngine()); _enginesRoot.AddEngine(new SpawnUnityEntityOnSveltoEntityEngine(_world)); AddEngine(new VelocityToPositionDoofusesEngine()); _enginesRoot.AddEngine(new ConsumingFoodEngine(_enginesRoot.GenerateEntityFunctions())); AddEngine(new RenderingDataSynchronizationEngine()); }
public CompositionRoot(IGraphics graphics) { _simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler(); _graphics = graphics; _schedulerReporter = new EngineSchedulerReporter(); _scheduler = new EngineScheduler(_schedulerReporter, _simpleSubmissionEntityViewScheduler); var enginesRoot = new EnginesRoot(_simpleSubmissionEntityViewScheduler); var entityFactory = enginesRoot.GenerateEntityFactory(); var debugPhysicsDrawEngine = new DebugPhysicsDrawEngine(_graphics); enginesRoot.AddEngine(debugPhysicsDrawEngine); scheduler.RegisterScheduledGraphicsEngine(debugPhysicsDrawEngine); var applyVelocityToRigidBodiesEngine = new ApplyVelocityToRigidBodiesEngine(); var detectDynamicBoxVsBoxCollisionsEngine = new DynamicBoxVsBoxCollisionsEngine(); var detectDynamicVsKinematicBoxVsBoxCollisionsEngine = new DynamicVsKinematicBoxVsBoxCollisionsEngine(); enginesRoot.AddEngine(applyVelocityToRigidBodiesEngine); enginesRoot.AddEngine(detectDynamicBoxVsBoxCollisionsEngine); enginesRoot.AddEngine(detectDynamicVsKinematicBoxVsBoxCollisionsEngine); ((IEngineScheduler)_scheduler).RegisterScheduledPhysicsEngine(applyVelocityToRigidBodiesEngine); ((IEngineScheduler)_scheduler).RegisterScheduledPhysicsEngine(detectDynamicBoxVsBoxCollisionsEngine); ((IEngineScheduler)_scheduler).RegisterScheduledPhysicsEngine(detectDynamicVsKinematicBoxVsBoxCollisionsEngine); //Entities can be created in the composition root, but it's a strategy ok only for simple scenarios. //Normally factory engines are used instead. AddEntities(entityFactory, _simpleSubmissionEntityViewScheduler); }
public DebugRoot AddRootToTree(EnginesRoot root) { var debugRoot = new DebugRoot(root); DebugRoots.Add(debugRoot); return(debugRoot); }
public SveltoOnDOTSEnginesGroup(EnginesRoot enginesRoot) { DBC.ECS.Check.Require(enginesRoot.scheduler is SimpleEntitiesSubmissionScheduler , "The Engines root must use a EntitiesSubmissionScheduler scheduler implementation"); CreateUnityECSWorldForSvelto(enginesRoot.scheduler as SimpleEntitiesSubmissionScheduler, enginesRoot); }
public void OnContextInitialized <T>(T contextHolder) { QualitySettings.vSyncCount = -1; _enginesRoot = new EnginesRoot(new UnityEntitySubmissionScheduler()); var context = contextHolder as SveltoContext; //add the engines we are going to use World world = World.Active; var generateEntityFactory = _enginesRoot.GenerateEntityFactory(); _enginesRoot.AddEngine(new PlaceFoodOnClickEngine(GameObjectConversionUtility.ConvertGameObjectHierarchy( context.food, world), generateEntityFactory)); _enginesRoot.AddEngine(new SpawningDoofusEngine (GameObjectConversionUtility.ConvertGameObjectHierarchy(context.capsule, world), generateEntityFactory)); _enginesRoot.AddEngine(new LookingForFoodDoofusesEngine(_enginesRoot.GenerateEntityFunctions())); _enginesRoot.AddEngine(new ConsumingFoodEngine(_enginesRoot.GenerateEntityFunctions())); _enginesRoot.AddEngine(new SpawnUnityEntityOnSveltoEntityEngine(world)); _enginesRoot.AddEngine(new VelocityToPositionDoofusesEngine()); _enginesRoot.AddEngine(new DieOfHungerDoofusesEngine(_enginesRoot.GenerateEntityFunctions())); var renderingDataSynchronizationEngine = new RenderingDataSynchronizationEngine(world); _enginesRoot.AddEngine(renderingDataSynchronizationEngine); }
public SimpleContext() { //An EnginesRoot holds all the engines created. it needs a EntitySubmissionScheduler to know when to //add the EntityViews generated inside the EntityDB. var simpleSubmissionEntityViewScheduler = new SimpleSubmissionEntityViewScheduler(); _enginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler); //an EnginesRoot must never be injected inside other classes only IEntityFactory and IEntityFunctions //implementation can var entityFactory = _enginesRoot.GenerateEntityFactory(); var entityFunctions = _enginesRoot.GenerateEntityFunctions(); //Add the Engine to manage the SimpleEntities var behaviourForEntityClassEngine = new BehaviourForEntityClassEngine(entityFunctions); _enginesRoot.AddEngine(behaviourForEntityClassEngine); //build Entity with ID 1 in group 0 entityFactory.BuildEntity <SimpleEntityDescriptor>(new EGID(0, ExclusiveGroups.group0)); //as we are using a basic scheduler, we need to schedule the entity submission ourselves simpleSubmissionEntityViewScheduler.SubmitEntities(); //twice as we want the Swap that is executed after the first submission, to be executed too simpleSubmissionEntityViewScheduler.SubmitEntities(); //as we don't have any ticking system for this basic example, we tick explicitly behaviourForEntityClassEngine.Update(); Console.Log("Done - click any button to quit"); System.Console.ReadKey(); Environment.Exit(0); }
public void OnContextInitialized <T>(T contextHolder) { // Create engine root. _submissionScheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_submissionScheduler); // Initialize UECS. _world = new World("SveltoWorld"); var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default); DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(_world, systems); World.DefaultGameObjectInjectionWorld = _world; var syncGroup = new SyncSveltoToUECSGroup(); _world.AddSystem(syncGroup); AddTickEngine(syncGroup); var uecsTickGroup = new PureUECSSystemsGroup(_world); AddTickEngine(uecsTickGroup); // Initialize SECS var entityFactory = _enginesRoot.GenerateEntityFactory(); }
public SetupEngines(EnginesRoot enginesRoot, IEntityFactory entityFactory, bool isMobile, string persistentDataPath) { this.enginesRoot = enginesRoot; this.entityFactory = entityFactory; setupStep = new SetupStep(steps, engines); setupSequence = new SetupSequence(sequences, steps, engines); createAddEngine = new CreateAddEngine(enginesRoot, engines, sequences, isMobile, persistentDataPath); }
public DebugRoot(EnginesRoot root) { EnginesRoot = root; Engines = (FasterList <IEngine>)EnginesField.GetValue(root); Root = (FasterDictionary <uint, FasterDictionary <RefWrapper <Type>, ITypeSafeDictionary> >)EntityDBField.GetValue(root); LocatorMap = (FasterDictionary <uint, FasterDictionary <uint, EntityLocator> >)EgidMapField.GetValue(root); Process(); }
public SetupEngines(EnginesRoot enginesRoot, IEntityFactory entityFactory) { this.enginesRoot = enginesRoot; this.entityFactory = entityFactory; setupStep = new SetupStep(steps, engines); setupSequence = new SetupSequence(sequences, steps, engines); createAddEngine = new CreateAddEngine(enginesRoot, engines, sequences); }
public void Init() { _scheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_scheduler); _factory = _enginesRoot.GenerateEntityFactory(); _functions = _enginesRoot.GenerateEntityFunctions(); _entitiesDB = _enginesRoot; }
public void Init() { _scheduler = new SimpleEntitiesSubmissionScheduler(); _root = new EnginesRoot(_scheduler); _factory = _root.GenerateEntityFactory(); _engine = new TestEngine(); _root.AddEngine(_engine); }
private void SetupEnginesAndEntities() { _EnginesRoot = new EnginesRoot(new UnitySumbmissionEntityViewScheduler()); _EntityFactory = _EnginesRoot.GenerateEntityFactory(); IEntityFunctions entityFunctions = _EnginesRoot.GenerateEntityFunctions(); GameObjectFactory gameObjectFactory = new GameObjectFactory(); Sequencer damageSequence = new Sequencer(); Sequencer roundSequence = new Sequencer(); ITime time = new Time(); //Construct Tank(Player) engines TankSpawnerEngine tankSpawnerEngine = new TankSpawnerEngine(gameObjectFactory, _EntityFactory); TankMovementEngine tankMovementEngine = new TankMovementEngine(time); TankHudEngine tankHudEngine = new TankHudEngine(); HealthEngine healthEngine = new HealthEngine(damageSequence); //Construct Weapon engines ShellSpawnerEngine shellSpawnerEngine = new ShellSpawnerEngine(gameObjectFactory, _EntityFactory, time); ShellDamageEngine shellDamageEngine = new ShellDamageEngine(damageSequence); //Construct Camera engines CameraEngine cameraEngine = new CameraEngine(time); //Add tanks engines _EnginesRoot.AddEngine(tankSpawnerEngine); _EnginesRoot.AddEngine(new TankInputEngine()); _EnginesRoot.AddEngine(tankMovementEngine); _EnginesRoot.AddEngine(new TankMovementEffectsEngine()); _EnginesRoot.AddEngine(tankHudEngine); _EnginesRoot.AddEngine(healthEngine); //Add weapon engines _EnginesRoot.AddEngine(new TankShootingEngine()); _EnginesRoot.AddEngine(shellSpawnerEngine); _EnginesRoot.AddEngine(shellDamageEngine); //Add camera engines _EnginesRoot.AddEngine(cameraEngine); damageSequence.SetSequence( new Steps { { shellDamageEngine, new To { new IStep[] { healthEngine } } }, { healthEngine, new To { { (int)DamageCondition.DAMAGE, new IStep[] { tankHudEngine } }, { (int)DamageCondition.DEAD, new IStep[] { tankMovementEngine } } } } } ); }
public CreateAddEngine( EnginesRoot enginesRoot, Dictionary <string, IEngine> engines, Dictionary <string, Sequencer> sequences) { this.enginesRoot = enginesRoot; this.engines = engines; this.sequences = sequences; }
public void TestSerializingWithEntityViewStructsAndFactories() { var init = _entityFactory.BuildEntity <SerializableEntityDescriptorWithViews>( 0, NamedGroup1.Group, new[] { new Implementor(1) }); init.Init(new EntityStructSerialized() { value = 5 }); init.Init(new EntityStructSerialized2() { value = 4 }); init.Init(new EntityStructPartiallySerialized() { value1 = 3 }); _simpleSubmissionEntityViewScheduler.SubmitEntities(); FasterList <byte> bytes = new FasterList <byte>(); var generateEntitySerializer = _enginesRoot.GenerateEntitySerializer(); var simpleSerializationData = new SimpleSerializationData(bytes); generateEntitySerializer.SerializeEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData , (int)SerializationType.Storage); SimpleEntitiesSubmissionScheduler simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler(); var newEnginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler); _neverDoThisIsJustForTheTest = new TestEngine(); newEnginesRoot.AddEngine(_neverDoThisIsJustForTheTest); simpleSerializationData.Reset(); generateEntitySerializer = newEnginesRoot.GenerateEntitySerializer(); DeserializationFactory factory = new DeserializationFactory(); generateEntitySerializer.RegisterSerializationFactory <SerializableEntityDescriptorWithViews>(factory); generateEntitySerializer.DeserializeNewEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData , (int)SerializationType.Storage); simpleSubmissionEntityViewScheduler.SubmitEntities(); Assert.That( _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized>(0, NamedGroup1.Group).value , Is.EqualTo(5)); Assert.That( _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized2>(0, NamedGroup1.Group).value , Is.EqualTo(4)); Assert.That(_neverDoThisIsJustForTheTest .entitiesDB.QueryEntity <EntityStructPartiallySerialized>(0, NamedGroup1.Group).value1 , Is.EqualTo(3)); newEnginesRoot.Dispose(); }
public void AddEnginesRoot(EnginesRoot root) { // if (root is EnginesRootNamed named) // { // EnginesRootDebugNames[root] = named.Name; // } var debugRoot = DebugInfo.AddRootToTree(root); OnAddEnginesRoot?.Invoke(debugRoot); }
private void SetupEnginesAndComponents() { _entityFactory = _enginesRoot = new EnginesRoot(); GameObjectFactory factory = new GameObjectFactory(); var ballMoveEngine = new BallMoveEngine(); var playerPaddleMovementEngine = new PlayerPaddleMoveEngine(); AddEngine(playerPaddleMovementEngine); AddEngine(ballMoveEngine); }
public void AddEnginesRoot(EnginesRoot root, string rootName = null) { if (string.IsNullOrEmpty(rootName) == false) { EnginesRootDebugNames[root] = rootName; } var debugRoot = DebugInfo.AddRootToTree(root); OnAddEnginesRoot?.Invoke(debugRoot); }
public void Init() { _scheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_scheduler); _factory = _enginesRoot.GenerateEntityFactory(); _functions = _enginesRoot.GenerateEntityFunctions(); _neverdoThisEngine = new TestEngine(); _enginesRoot.AddEngine(_neverdoThisEngine); }
public void OnContextCreated <T>(T contextHolder) { QualitySettings.vSyncCount = -1; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; _simpleSubmitScheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_simpleSubmitScheduler); _mainLoop = new MainLoop(_enginesToTick); }
public void Init() { _simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler(); _enginesRoot = new EnginesRoot(_simpleSubmissionEntityViewScheduler); _testEngine = new TestEngine(); _enginesRoot.AddEngine(_testEngine); _entityFactory = _enginesRoot.GenerateEntityFactory(); _enginesRoot.GenerateEntityFunctions(); var id = _idStart; for (uint i = 0; i < _groupCount; i++) { for (int j = 0; j < _entityCountPerGroup; j++) { _entityFactory.BuildEntity <EntityDescriptorWithComponentAndViewComponent>( new EGID(id++, _group + i), new object[] { new TestFloatValue(1f), new TestIntValue(1) }); _entityFactory.BuildEntity <EntityDescriptorViewComponentWithString>( new EGID(id++, _group + i), new object[] { new TestStringValue("test") }); } } _simpleSubmissionEntityViewScheduler.SubmitEntities(); foreach (var((buffer, count), _) in _testEngine.entitiesDB.QueryEntities <TestEntityViewComponent>()) { for (int i = 0; i < count; i++) { buffer[i].TestFloatValue.Value += buffer[i].ID.entityID; buffer[i].TestIntValue.Value += (int)buffer[i].ID.entityID; } } foreach (var((buffer, count), _) in _testEngine .entitiesDB.QueryEntities <TestEntityComponent>()) { for (int i = 0; i < count; i++) { buffer[i].floatValue = 1 + buffer[i].ID.entityID; buffer[i].intValue = 1 + (int)buffer[i].ID.entityID; } } foreach (var((buffer, count), _) in _testEngine .entitiesDB.QueryEntities <TestEntityViewComponentString>()) { for (int i = 0; i < count; i++) { buffer[i].TestStringValue.Value = (1 + buffer[i].ID.entityID).ToString(); } } }