Ejemplo n.º 1
0
 public IEnumerable <T> AtObject <T>(IPositionComponent ph, float radius) where T : IGameObjectComponent
 {
     return(from pos in AtPosition(ph.Position, radius)
            let obj = repository.GetGameObject(pos)
                      where obj.HasComponent <T>()
                      select obj.GetComponent <T>());
 }
        private void raycastEntity(IPositionComponent ent, Ray ray, RaycastResult newResult)
        {
            throw new NotImplementedException();
            //bool abort = !ent.Physical.Visible && !RaycastInvisible;

            //if (ent.Physical.Mesh == null) abort = true;
            //if (abort)
            //{
            //    newResult.Set(null, ent);
            //    return;
            //}

            //var transformed = ray.Transform(Matrix.Invert(ent.Physical.ObjectMatrix * ent.Physical.WorldMatrix));


            ////TODO: do course boundingbox check
            //var bb = TW.Assets.GetBoundingBox(ent.Physical.Mesh);
            //if (!transformed.xna().Intersects(bb.xna()).HasValue)
            //{
            //    newResult.Set(null, ent);
            //    return;
            //}



            //Vector3 v1, v2, v3;
            //var distance = MeshRaycaster.RaycastMesh(ent.Physical.Mesh, transformed, out v1, out v2, out v3);


            //newResult.Set(distance, ent);
            //newResult.V1 = Vector3.TransformCoordinate(v1, ent.Physical.WorldMatrix);
            //newResult.V2 = Vector3.TransformCoordinate(v2, ent.Physical.WorldMatrix);
            //newResult.V3 = Vector3.TransformCoordinate(v3, ent.Physical.WorldMatrix);
        }
Ejemplo n.º 3
0
 public RelativePositionComponent(IPositionComponent decorated)
 {
     this.decorated   = decorated;
     RelativeRotation = Quaternion.Identity;
     RelativePosition = new Vector3();
     parent           = nullComponent;
 }
Ejemplo n.º 4
0
        private void AddNode(IPositionComponent posComponent)
        {
            if (_root == null)
            {
                _root = new KdNode(posComponent, 0);
                return;
            }

            var current       = _root;
            var parent        = _root;
            var isRightBranch = false;

            while (current != null)
            {
                var splittedCurrent = GetSplited(current.Level, current.Key.Position);
                var splittedNew     = GetSplited(current.Level, posComponent.Position);

                isRightBranch = splittedCurrent < splittedNew;

                parent  = current;
                current = isRightBranch ? current.RightNode : current.LeftNode;
            }

            var newNode = new KdNode(posComponent, parent.Level + 1, parent);

            if (isRightBranch)
            {
                parent.RightNode = newNode;
            }
            else
            {
                parent.LeftNode = newNode;
            }
        }
Ejemplo n.º 5
0
 public IslandPart(IPositionComponent physical, IMeshRenderComponent renderComponent, BasicPhysicsPart physics, IslandMeshFactory islandMeshFactory)
 {
     Physical          = physical;
     RenderComponent   = renderComponent;
     Physics           = physics;
     IslandMeshFactory = islandMeshFactory;
 }
Ejemplo n.º 6
0
 public ItemPart(IPositionComponent physical, IMeshRenderComponent renderComponent, Random random)
 {
     Physical        = physical;
     RenderComponent = renderComponent;
     Random          = random;
     InStorage       = true;
 }
Ejemplo n.º 7
0
        public Vector3?GetPointTargetedOnObject(IPositionComponent obj)
        {
            var ray      = TW.Data.Get <CameraInfo>().GetCenterScreenRay();
            var localRay = ray.Transform(Matrix.Invert(obj.GetWorldMatrix()));
            var dist     = localRay.xna().Intersects(obj.LocalBoundingBox.xna());

            return(dist.With(d => Vector3.TransformCoordinate(localRay.GetPoint(d), obj.GetWorldMatrix())));
        }
Ejemplo n.º 8
0
 public RobotPlayerNormalMovementPart(IUserMovementInput movementInput, ISimulationEngine simulationEngine, IWorldLocator worldLocator, IPositionComponent physical, BasicPhysicsPart physics)
 {
     MovementInput    = movementInput;
     SimulationEngine = simulationEngine;
     WorldLocator     = worldLocator;
     Physical         = physical;
     Physics          = physics;
 }
Ejemplo n.º 9
0
 public PiratePart(EnemyBehaviourFactory behaviourFactory, EnemyBrain brain, IPositionComponent Physical)
 {
     this.behaviourFactory = behaviourFactory;
     this.Brain            = brain;
     this.Physical         = Physical;
     behaviourTree         = CreateBehaviourTree();
     agent = new BehaviourTreeAgent(behaviourTree);
     Brain.LookDistance  = 20;
     Brain.ShootDistance = 5;
     Brain.ShootInterval = 2;
     Brain.GunDamage     = 20;
 }
 public EnemyBehaviourFactory(EnemyBrain brain,
                              ISimulationEngine simulationEngine,
                              IWorldLocator worldLocator,
                              TraderPart.IItemFactory itemFactory,
                              Random random,
                              IPositionComponent physical)
 {
     this.Brain       = brain;
     SimulationEngine = simulationEngine;
     WorldLocator     = worldLocator;
     ItemFactory      = itemFactory;
     Random           = random;
     Physical         = physical;
 }
Ejemplo n.º 11
0
        public RobotPlayerPart(IWorldLocator worldLocator,
                               RobotPlayerNormalMovementPart normalMovement,
                               ISimulationEngine simulationEngine,
                               PrototypeObjectsFactory prototypeObjectsFactory,
                               IMeshRenderComponent meshRenderComponent,
                               IPositionComponent physical)
        {
            WorldLocator            = worldLocator;
            NormalMovement          = normalMovement;
            SimulationEngine        = simulationEngine;
            PrototypeObjectsFactory = prototypeObjectsFactory;
            MeshRenderComponent     = meshRenderComponent;
            Physical = physical;

            Items  = new List <ItemPart>();
            Health = 100;
        }
Ejemplo n.º 12
0
        private void Insert(IPositionComponent posComponent, XNode node = null)
        {
            if (_root == null)
            {
                _root = new XNode(posComponent);
                return;
            }

            if (node == null)
            {
                node = _root;
            }

            if (node.Key.Position.X > posComponent.Position.X)
            {
                if (node.LeftNode == null)
                {
                    node.LeftNode = new XNode(posComponent);
                }
                else
                {
                    Insert(posComponent, node.LeftNode);
                }
            }
            else
            {
                if (node.RightNode == null)
                {
                    node.RightNode = new XNode(posComponent);
                }
                else
                {
                    Insert(posComponent, node.RightNode);
                }
            }

            BalanceParent(node);
            _count++;
        }
Ejemplo n.º 13
0
        private void Insert(IPositionComponent pos, KdNode node = null)
        {
            if (_root == null)
            {
                _root = new KdNode(pos, 0);
                return;
            }

            var parent       = node ?? _root;
            var splitParent  = parent.Level % 2 == 0 ? parent.Key.Position.X : parent.Key.Position.Y;
            var splitCurrent = parent.Level % 2 == 0 ? pos.Position.X : pos.Position.Y;

            if (splitCurrent < splitParent)
            {
                if (parent.LeftNode != null)
                {
                    Insert(pos, parent.LeftNode);
                }
                else
                {
                    var newNode = new KdNode(pos, parent.Level + 1, parent);
                    parent.LeftNode = newNode;
                }
            }
            else
            {
                if (parent.RightNode != null)
                {
                    Insert(pos, parent.RightNode);
                }
                else
                {
                    var newNode = new KdNode(pos, parent.Level + 1, parent);
                    parent.RightNode = newNode;
                }
            }
        }
 /// <summary>
 /// Note: replace physical with a moveto delegate?(Action{Vector3})
 /// </summary>
 /// <param name="brain"></param>
 /// <param name="engine"></param>
 /// <param name="ph"></param>
 public MoveToDestinationBehaviour(EnemyBrain brain, ISimulationEngine engine, IPositionComponent ph)
 {
     this.brain  = brain;
     this.engine = engine;
     this.ph     = ph;
 }
Ejemplo n.º 15
0
 internal XNode(IPositionComponent positionComponent)
 {
     Key         = positionComponent;
     HeightLevel = 1;
 }
Ejemplo n.º 16
0
 public KdNode(IPositionComponent positionComponent, int lvl, KdNode parent = null)
 {
     Level      = lvl;
     Key        = positionComponent;
     ParentNode = parent;
 }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            int portStart = int.Parse(args[0]);
            int capacity  = int.Parse(args[1]);

            var tickRate = TimeSpan.FromMilliseconds(10); // 100 ticks per second

            var world         = new World();
            var timeComponent = new World.Entity.TimeComponent(new World.Entity(world))
            {
                deltaTime = tickRate.TotalSeconds
            };

            _ = new World.Entity.ConsoleBufferComponent(new World.Entity(world))
            {
                consoleBuffer = new byte[120, 32]
            };

            var server = new Server <(World, int), (float, float)>(
                initialClientState: (0f, 0f),
                serverStatesByTick: world,
                serverStateDiffer: new World.Differ(),
                clientStateDiffer: new Vector2Differ(),
                portStart: portStart,
                capacity: capacity,
                sendInterval: TimeSpan.FromSeconds(0.1));

            var velocityComponents = new IVelocityComponent[capacity];
            var positionComponents = new IPositionComponent[capacity];
            var viewComponents     = new IViewComponent[capacity];

            FixedTimer(tick => {
                lock (world) {
                    for (int i = 0; i < capacity; ++i)
                    {
                        int port = portStart + i;

                        if (server.GetClientConnected(port))
                        {
                            if (velocityComponents[i] == null)
                            {
                                var entity            = new World.Entity(world);
                                velocityComponents[i] = new World.Entity.VelocityComponent(entity)
                                {
                                    speed = 10f
                                };
                                positionComponents[i] = new World.Entity.PositionComponent(entity)
                                {
                                    x = Console.WindowWidth / 2,
                                    y = Console.WindowHeight / 2
                                };
                                viewComponents[i] = new World.Entity.ViewComponent(entity)
                                {
                                    avatar = new[] { '@', '#', '$', '%' }[i]
                                };
                            }

                            var input = server.GetClientState(port);
                            velocityComponents[i].deltaX = input.Item1;
                            velocityComponents[i].deltaY = input.Item2;

                            Console.SetCursorPosition(0, i * 2);
                            Console.Write($@"velocity: ({velocityComponents[i].deltaX}, {velocityComponents[i].deltaY})
position: ({positionComponents[i].x}, {positionComponents[i].y})");
                        }
                        else
                        {
                            if (velocityComponents[i] != null)
                            {
                                velocityComponents[i].Dispose();
                                velocityComponents[i] = null;
                            }

                            if (positionComponents[i] != null)
                            {
                                positionComponents[i].Dispose();
                                positionComponents[i] = null;
                            }

                            if (viewComponents[i] != null)
                            {
                                viewComponents[i].Dispose();
                                viewComponents[i] = null;
                            }
                        }
                    }

                    ((IServerWorld)world).Tick(tick);
                    server.serverTick = tick;
                }
            }, tickRate, new CancellationToken());
        }
Ejemplo n.º 18
0
 public RotateOnTheSpotScript(ISimulationEngine engine, IPositionComponent position)
 {
     this.engine   = engine;
     this.position = position;
 }
 public ProximityChaseEnemyPart(EnemyBehaviourFactory behaviourFactory, EnemyBrain brain, IPositionComponent Physical)
 {
     BehaviourFactory    = behaviourFactory;
     behaviourTree       = CreateBehaviourTree();
     agent               = new BehaviourTreeAgent(behaviourTree);
     GunChargedTime      = -1;
     brain.LookDistance  = 20;
     brain.ShootDistance = 5;
     brain.ShootInterval = 2;
     brain.GunDamage     = 20;
     Brain               = brain;
     this.Physical       = Physical;
 }
 public GenerationSourcePart(GenerationPart generationPart, IPositionComponent physical, IMeshRenderComponent meshRenderComponent)
 {
     GenerationPart      = generationPart;
     Physical            = physical;
     MeshRenderComponent = meshRenderComponent;
 }
Ejemplo n.º 21
0
 private void tilePositionComponent_PositionChanged(IPositionComponent sender, PositionEventArgs e)
 {
     this.TilePosition = GetTilePosition(e.NewPosition);
 }
 private void positionProvider_PositionChanged(IPositionComponent sender, PositionEventArgs e)
 {
     PositionChanged?.Invoke(sender, e);
 }
 public AttachedPositionComponent(IPositionComponent positionProvider)
 {
     this.PositionComponent = positionProvider;
 }
Ejemplo n.º 24
0
 public TraderVisualizerPart(TraderPart traderPart, IMeshRenderComponent physical, IPositionComponent positionComponent)
 {
     this.PositionComponent = positionComponent;
     TraderPart             = traderPart;
     Physical = physical;
 }
 public static Matrix GetWorldMatrix(this IPositionComponent obj)
 {
     return(Matrix.RotationQuaternion(obj.Rotation) * Matrix.Translation(obj.Position));
 }