예제 #1
0
 public EntityBuilder AddComponent <T>(IComponentData <T> data, WorkerRequirementSet writeAcl)
     where T : IComponentMetaclass
 {
     entity.Add(data);
     entityAcl.SetWriteAccess <T>(writeAcl);
     return(this);
 }
예제 #2
0
        public static Entity CreatePlayerEntityTemplate(List <string> clientAttributeSet,
                                                        Generated.Improbable.Vector3f position)
        {
            var clientSet = new WorkerRequirementSet(new Improbable.Collections.List <WorkerAttributeSet>()
            {
                new WorkerAttributeSet(clientAttributeSet as Improbable.Collections.List <string>)
            });

            var location              = new Improbable.Transform.Location(position.X, position.Y, position.Z);
            var rotation              = new Improbable.Transform.Quaternion(1, 0, 0, 0);
            var coordinates           = new Coordinates(0, 0, 0);
            var transformData         = new Improbable.Transform.Transform.Data(location, rotation, 0);
            var metadata              = new Metadata.Data(ArchetypeConfig.CharacterArchetype);
            var playerInput           = new Playground.PlayerInput.Data(0, 0, false);
            var playerHeartbeatClient = new Improbable.PlayerLifecycle.PlayerHeartbeatClient.Data();
            var playerHeartbeatServer = new Improbable.PlayerLifecycle.PlayerHeartbeatServer.Data();
            var prefab    = new Playground.Prefab.Data(ArchetypeConfig.CharacterArchetype);
            var archetype = new Playground.ArchetypeComponent.Data(ArchetypeConfig.CharacterArchetype);
            var launcher  = new Playground.Launcher.Data(100, 0);

            return(EntityBuilder.Begin()
                   .AddPositionComponent(coordinates, GameLogicSet)
                   .AddComponent(metadata, GameLogicSet)
                   .SetPersistence(false)
                   .SetReadAcl(AllWorkersSet)
                   .AddComponent(transformData, GameLogicSet)
                   .AddComponent(playerInput, clientSet)
                   .AddComponent(playerHeartbeatClient, clientSet)
                   .AddComponent(playerHeartbeatServer, GameLogicSet)
                   .AddComponent(prefab, GameLogicSet)
                   .AddComponent(archetype, GameLogicSet)
                   .AddComponent(launcher, GameLogicSet)
                   .Build());
        }
예제 #3
0
        /// <summary>
        ///     Gives workers that satisfy the given requirement set write permissions over the given component.
        /// </summary>
        /// <remarks>
        ///     Calling this multiple times for the same component will overwrite the existing requirement set.
        /// </remarks>
        public Acl SetWriteAccess <TComponent>(WorkerRequirementSet requirementSet) where TComponent : IComponentMetaclass
        {
            EnsureWritePermissionsAllocated();

            var id = Dynamic.GetComponentId <TComponent>();

            writePermissions[id] = requirementSet;
            return(this);
        }
 public static unsafe void Write(global::Improbable.Worker.Internal.GcHandlePool _pool,
                                 WorkerRequirementSet _data, global::Improbable.Worker.Internal.Pbio.Object *_obj)
 {
     if (_data.attributeSet != null)
     {
         for (int _i = 0; _i < _data.attributeSet.Count; ++_i)
         {
             global::Improbable.WorkerAttributeSet_Internal.Write(_pool, _data.attributeSet[_i], global::Improbable.Worker.Internal.Pbio.AddObject(_obj, 1));
         }
     }
 }
예제 #5
0
        /// <summary>
        ///     Gives workers that satisfy the given requirement set write permissions over the given component.
        /// </summary>
        /// <remarks>
        ///     Calling this multiple times for the same component will overwrite the existing requirement set.
        /// </remarks>
        public Acl SetWriteAccess(uint componentId, WorkerRequirementSet requirementSet)
        {
            if (!allComponentIds.Contains(componentId))
            {
                throw new InvalidOperationException(string.Format("{0} is an unknown component id", componentId));
            }

            EnsureWritePermissionsAllocated();
            writePermissions[componentId] = requirementSet;

            return(this);
        }
        private static Entity createEntity(string workerType, double X, double Y, bool currentAlive, UInt64 currentSequenceId, bool previousAlive, UInt64 previousSequenceId, Improbable.Collections.List <EntityId> neighborsList)
        {
            var entity = new Entity();
            //const string entityType = "Cell";
            string entityType = "Cell";

            if (currentAlive)
            {
                entityType = "Cell_Alive";
            }
            else
            {
                entityType = "Cell_Dead";
            }

            // Defines worker attribute requirements for workers that can read a component.
            // workers with an attribute of "client" OR workerType will have read access
            var readRequirementSet = new WorkerRequirementSet(
                new Improbable.Collections.List <WorkerAttributeSet>
            {
                new WorkerAttributeSet(new Improbable.Collections.List <string> {
                    workerType
                })
                //new WorkerAttributeSet(new Improbable.Collections.List<string> {"client"}),
            });

            // Defines worker attribute requirements for workers that can write to a component.
            // workers with an attribute of workerType will have write access
            var workerWriteRequirementSet = new WorkerRequirementSet(
                new Improbable.Collections.List <WorkerAttributeSet>
            {
                new WorkerAttributeSet(new Improbable.Collections.List <string> {
                    workerType
                }),
            });

            var writeAcl = new Improbable.Collections.Map <uint, WorkerRequirementSet>
            {
                { EntityAcl.ComponentId, workerWriteRequirementSet },
                { Position.ComponentId, workerWriteRequirementSet },
                { Metadata.ComponentId, workerWriteRequirementSet },
                { Life.ComponentId, workerWriteRequirementSet }
            };

            entity.Add(new EntityAcl.Data(readRequirementSet, writeAcl));
            // Needed for the entity to be persisted in snapshots.
            entity.Add(new Persistence.Data());
            entity.Add(new Metadata.Data(entityType)); //Can use metadata to do color setting for visualization in inspector
            entity.Add(new Position.Data(new Coordinates(X, 0, Y)));
            entity.Add(new Life.Data(currentAlive, currentSequenceId, previousAlive, previousSequenceId));
            entity.Add(new Neighbors.Data(neighborsList));
            return(entity);
        }
예제 #7
0
        static Entity CreateBaseEntity(Coordinates coord, string name, WorkerRequirementSet readAcl, Map <uint, WorkerRequirementSet> writeAcl)
        {
            var entity = new Entity();

            entity.Add(new Position.Data(coord));
            entity.Add(new Persistence.Data());
            entity.Add(new Metadata.Data(name));

            var aclData = new EntityAclData {
                readAcl           = readAcl,
                componentWriteAcl = writeAcl
            };

            entity.Add(new EntityAcl.Data(aclData));

            return(entity);
        }
예제 #8
0
        private static Entity createEntity(string workerType, Coordinates cord)
        {
            var          entity     = new Entity();
            const string entityType = "Cell";
            // Defines worker attribute requirements for workers that can read a component.
            // workers with an attribute of "client" OR workerType will have read access
            var readRequirementSet = new WorkerRequirementSet(
                new Improbable.Collections.List <WorkerAttributeSet>
            {
                new WorkerAttributeSet(new Improbable.Collections.List <string> {
                    workerType
                }),
                new WorkerAttributeSet(new Improbable.Collections.List <string> {
                    "client"
                }),
            });

            // Defines worker attribute requirements for workers that can write to a component.
            // workers with an attribute of workerType will have write access
            var workerWriteRequirementSet = new WorkerRequirementSet(
                new Improbable.Collections.List <WorkerAttributeSet>
            {
                new WorkerAttributeSet(new Improbable.Collections.List <string> {
                    workerType
                }),
            });

            var writeAcl = new Improbable.Collections.Map <uint, WorkerRequirementSet>
            {
                { EntityAcl.ComponentId, workerWriteRequirementSet },
                { Position.ComponentId, workerWriteRequirementSet },
                { Cell.IsAlive.ComponentId, workerWriteRequirementSet },
                { Metadata.ComponentId, workerWriteRequirementSet }
            };

            entity.Add(new EntityAcl.Data(readRequirementSet, writeAcl));
            // Needed for the entity to be persisted in snapshots.
            entity.Add(new Persistence.Data());
            entity.Add(new Cell.IsAlive.Data(true));
            entity.Add(new Metadata.Data(entityType));
            entity.Add(new Position.Data(cord));
            return(entity);
        }
예제 #9
0
        internal static Entity BasicScoutShip(string userDBId, string shipDBId, string clientWorkerId)
        {
            var clientRequirementSet = new WorkerRequirementSet(new List <WorkerAttributeSet> {
                new WorkerAttributeSet(new List <string>()
                {
                    "workerId:" + clientWorkerId
                })
            });

            var shipWriteACL = new Map <uint, WorkerRequirementSet>(defaultShipWriteACL)
            {
                { 102, clientRequirementSet },  //ClientConnection

                { 1500, clientRequirementSet }, //FlightController
                { 1501, clientRequirementSet }, //EnergyContoller
                { 1502, clientRequirementSet }, //TriggerContoller
                { 1503, clientRequirementSet }, //ToggleContoller
                { 1504, clientRequirementSet }, //TurretsContoller
                { 1505, clientRequirementSet }, //TargetingContoller
                //{ 1506, clientRequirementSet },//ScannersController
                { 1507, clientRequirementSet }, //FlaksController

                { 3500, clientRequirementSet }, //Crafting Controller
                { 3501, clientRequirementSet }, //Mapping Controller
            };

            var entity = new Entity();

            entity.Add(EntityAcl.Metaclass, new EntityAclData(defaultShipReadACL, shipWriteACL));
            entity.Add(Metadata.Metaclass, new MetadataData("StarterShip"));

            entity.Add(ClientConnection.Metaclass, new ClientConnectionData());
            entity.Add(Identification.Metaclass, new IdentificationData(userDBId, shipDBId, clientWorkerId));
            entity.Add(ExplorationPhysics.Metaclass, new ExplorationPhysicsData(null, null));

            entity.Add(Mobile.Metaclass, defaultShipMobileData);

            entity.Add(FlightController.Metaclass, new FlightControllerData(21));// 21 == no action in bits
            entity.Add(TriggerController.Metaclass, new TriggerControllerData());

            return(entity);
        }
예제 #10
0
        public static RequestId <CreateEntityRequest> CreateOsmNodeEntity(Dispatcher dispatcher, Connection connection, string name, Coordinates coords)
        {
            string entityType = name;
            var    entity     = new Entity();
            var    basicWorkerRequirementSet = new WorkerRequirementSet(
                new List <WorkerAttributeSet> {
                new WorkerAttributeSet(new List <string> {
                    "simulation"
                })
            }
                );
            var writeAcl = new Map <uint, WorkerRequirementSet> {
            };

            entity.Add(EntityAcl.Metaclass, new EntityAclData(basicWorkerRequirementSet, writeAcl));
            entity.Add(Persistence.Metaclass, new PersistenceData());
            entity.Add(Metadata.Metaclass, new MetadataData(entityType));
            entity.Add(Position.Metaclass, new PositionData(coords));
            return(connection.SendCreateEntityRequest(entity, new Option <EntityId>(), new Option <uint>()));
        }
예제 #11
0
    private static Entity CreatePlayerTemplate(CommandRequestOp <Automaton.Spawner.Commands.SpawnPlayer> op, Coordinates position)
    {
        var callerWorkerRequirementSet = new WorkerRequirementSet(new Improbable.Collections.List <WorkerAttributeSet> {
            new WorkerAttributeSet(op.CallerAttributeSet)
        });
        var gameWorkerAttr = new WorkerAttributeSet(new Improbable.Collections.List <string> {
            "GameWorker"
        });
        var clientWorkerAttr = new WorkerAttributeSet(new Improbable.Collections.List <string>()
        {
            "TPSClient"
        });

        var gameWorkerRequirementSet = new WorkerRequirementSet(new Improbable.Collections.List <WorkerAttributeSet> {
            gameWorkerAttr
        });

        var allRequirementSet = new WorkerRequirementSet(new Improbable.Collections.List <WorkerAttributeSet>
        {
            clientWorkerAttr,
            gameWorkerAttr
        });
        var writeAcl = new Map <uint, WorkerRequirementSet>
        {
            { Position.ComponentId, callerWorkerRequirementSet },
            { EntityAcl.ComponentId, gameWorkerRequirementSet },
            { Movement.ComponentId, callerWorkerRequirementSet },
            { Automaton.Player.Player.ComponentId, callerWorkerRequirementSet },
            { Score.ComponentId, gameWorkerRequirementSet }
        };
        Entity entity = new Entity();

        entity.Add(new EntityAcl.Data(/* read */ allRequirementSet, /* write */ writeAcl));
        entity.Add(new Metadata.Data("SpatialOsPlayer"));
        entity.Add(new Position.Data(position));
        entity.Add(new Movement.Data(false, new Quaternion(1, 0, 0, 0), false));
        entity.Add(new Automaton.Player.Player.Data());
        entity.Add(new Score.Data(0, 0));
        return(entity);
    }
예제 #12
0
        private static RequestId <CreateEntityRequest> CreateVehicleEntity(Dispatcher dispatcher, Connection connection, bool bus, string busVehicleId)
        {
            string entityType = bus ? "Bus" : "Car";
            var    entity     = new Entity();

            // This requirement set matches any worker with the attribute "simulation".
            var basicWorkerRequirementSet = new WorkerRequirementSet(
                new List <WorkerAttributeSet> {
                new WorkerAttributeSet(new List <string> {
                    "simulation"
                })
            }
                );

            // Give authority over Position and EntityAcl to any physics worker, and over PlayerControls to the caller worker.
            var writeAcl = new Map <uint, WorkerRequirementSet>
            {
                { Position.ComponentId, basicWorkerRequirementSet },
                { Car.ComponentId, basicWorkerRequirementSet },
                { EntityAcl.ComponentId, basicWorkerRequirementSet },
                { Bus.ComponentId, basicWorkerRequirementSet }
            };

            entity.Add(EntityAcl.Metaclass,
                       new EntityAclData(/* read */ basicWorkerRequirementSet, /* write */ writeAcl));

            entity.Add(Persistence.Metaclass, new PersistenceData());
            entity.Add(Metadata.Metaclass, new MetadataData(entityType));
            entity.Add(Position.Metaclass, new PositionData(new Coordinates(0, -99.99, 0)));
            entity.Add(Car.Metaclass, new CarData(99999, 99999, 99999));
            if (bus)
            {
                entity.Add(Bus.Metaclass, new BusData(busVehicleId, new List <string>(), new Map <string, string>()));
            }

            return(connection.SendCreateEntityRequest(entity, new Option <EntityId>(), new Option <uint>()));
        }
예제 #13
0
        public static RequestId <CreateEntityRequest> CreateBusStopEntity(Dispatcher dispatcher, Connection connection, string name, Coordinates coords, String atcoCode)
        {
            string entityType = name;
            var    entity     = new Entity();
            var    basicWorkerRequirementSet = new WorkerRequirementSet(
                new List <WorkerAttributeSet> {
                new WorkerAttributeSet(new List <string> {
                    "simulation"
                })
            }
                );
            var writeAcl = new Map <uint, WorkerRequirementSet>
            {
                { BusStop.ComponentId, basicWorkerRequirementSet },
                { EntityAcl.ComponentId, basicWorkerRequirementSet },
            };

            entity.Add(EntityAcl.Metaclass, new EntityAclData(basicWorkerRequirementSet, writeAcl));
            entity.Add(Persistence.Metaclass, new PersistenceData());
            entity.Add(Metadata.Metaclass, new MetadataData(entityType));
            entity.Add(Position.Metaclass, new PositionData(coords));
            entity.Add(BusStop.Metaclass, new BusStopData(atcoCode, MapReader.originX, MapReader.originY, MapReader.offsetX, MapReader.offsetY));
            return(connection.SendCreateEntityRequest(entity, new Option <EntityId>(), new Option <uint>()));
        }
예제 #14
0
 /// <inheritdoc cref="IPositionAdder.AddPositionComponent" />
 public IMetadataAdder AddPositionComponent(Coordinates position, WorkerRequirementSet writeAcl)
 {
     entity.Add(new Position.Data(position));
     entityAcl.SetWriteAccess <Position>(writeAcl);
     return(this);
 }
예제 #15
0
 /// <inheritdoc cref="IComponentAdder.AddComponent" />
 public IComponentAdder AddComponent <C>(IComponentData <C> data, WorkerRequirementSet writeAcl) where C : IComponentMetaclass
 {
     entity.Add(data);
     entityAcl.SetWriteAccess <C>(writeAcl);
     return(this);
 }
예제 #16
0
 /// <inheritdoc cref="IComponentAdder.SetEntityAclComponentWriteAccess" />
 public IComponentAdder SetEntityAclComponentWriteAccess(WorkerRequirementSet writeAcl)
 {
     entityAcl.SetWriteAccess <EntityAcl>(writeAcl);
     return(this);
 }
예제 #17
0
 /// <inheritdoc cref="IReadAclSetter.SetReadAcl" />
 public IComponentAdder SetReadAcl(WorkerRequirementSet readAcl)
 {
     entityAcl.SetReadAccess(readAcl);
     return(this);
 }
예제 #18
0
 public EntityBuilder SetReadAcl(WorkerRequirementSet readAcl)
 {
     entityAcl.SetReadAccess(readAcl);
     return(this);
 }
예제 #19
0
 /// <summary>
 ///     Gives workers that satisfy the given requirement set read permissions over the given component.
 /// </summary>
 /// <remarks>
 ///     Calling this multiple times will overwrite the existing requirement set.
 /// </remarks>
 public Acl SetReadAccess(WorkerRequirementSet requirementSet)
 {
     readPermissions = requirementSet;
     return(this);
 }