예제 #1
0
        public void Swipe(double degree, Vector3 dir)
        {
            if (isInit())
            {
                Player.simulator.Simulation.Awakener.AwakenBody(golfBallRef.Handle);
                float force = 30;
                QuixConsole.Log("Swipé log", degree);
                Vector2 rot2d = Player.GetXYRotation();
                Vector3 rot   = new Vector3(rot2d.X, 0, rot2d.Y);

                /* golfBallRef.Velocity.Linear.Y += force;
                 * golfBallRef.Velocity.Linear.X -= rot.X*force;
                 * golfBallRef.Velocity.Linear.Z -= rot.Y*force;*/

                Quaternion quat   = QuaternionEx.CreateFromAxisAngle(rot, (float)degree);
                Matrix4x4  matrix = Matrix4x4.CreateFromQuaternion(quat);

                Vector3 result = Vector3.Transform(rot, matrix);

                QuixConsole.Log("direction", dir);

                dir.X *= -1;
                dir.Y *= -1;
                dir.Z *= -1;

                golfBallRef.Velocity.Linear.Y += dir.Y * force;
                golfBallRef.Velocity.Linear.X += dir.X * force;
                golfBallRef.Velocity.Linear.Z += dir.Z * force;

                QuixConsole.Log("Result", result);
            }
        }
예제 #2
0
 public void SetPositionToStartPoint()
 {
     QuixConsole.Log("Start position", (simulator.map.startPositions[0].AsBsonDocument["x"]));
     reference.Pose.Position.X = (float)simulator.map.startPositions[0].AsBsonDocument["x"].AsDouble;
     reference.Pose.Position.Y = (float)simulator.map.startPositions[0].AsBsonDocument["y"].AsDouble;
     reference.Pose.Position.Z = (float)simulator.map.startPositions[0].AsBsonDocument["z"].AsDouble;
 }
예제 #3
0
 public void Activate(bool active)
 {
     if (!isInit())
     {
         var timer = new PhyInterval(1, Player.simulator);
         timer.Completed += OnTick;
         golfBallRef      = Player.golfball.GetReference();
         vehicle          = new Vehicle(Player.golfball);
         Player.simulator.Simulation.Awakener.AwakenBody(golfBallRef.Handle);
     }
     if (isInit())
     {
         //golfBallRef.
         QuixConsole.Log("Gauntlet", active);
         vehicle.isActive = active;
         Player.simulator.Simulation.Awakener.AwakenBody(golfBallRef.Handle);
     }
     if (!hasStopped)
     {
         // Player.golfball.Stop();
         hasStopped = true;
     }
     if (!active)
     {
         hasStopped = false;
     }
 }
예제 #4
0
        private void CreateSimulator(ConnectionState socket)
        {
            QuixConsole.WriteLine("Create simulator");
            Simulator simulator = new Simulator(socket, this);

            socket.simulator = simulator;
        }
예제 #5
0
        private void _checkToChangeState(AgentState ms)
        {
            if (this.state != null)
            {
                //QuixConsole.Log("Check change");
                if (ms == this.state)
                {
                    this.state.OnRepeat();
                }
                else
                {
                    if (this.state != null)
                    {
                        this.state.OnDesactivate();
                    }

                    this.state = ms;
                    QuixConsole.Log("State", ms.GetType().ToString());
                    this.state.OnActivate();
                }
            }
            else
            {
                this.state = ms;
            }
        }
예제 #6
0
        public void Close()
        {
            QuixConsole.WriteLine("Closing Simulator");



            collidableMaterials.Dispose();

            objects.Clear();
            objectsHandlers.Clear();
            staticObjectsHandlers.Clear();

            //Simulation.Bodies.Dispose();
            // Simulation.Statics.Dispose();

            Simulation.Dispose();
            bufferPool.Clear();
            ThreadDispatcher.Dispose();

            //OnContactListeners.Clear();
            // OnStaticContactListeners.Clear();
            connectionState.Dispose();
            //server.isRunning = false;

            Disposed = true;
            gameLoop.Stop();

            //Dispose();
        }
예제 #7
0
 new public void SendCreateMessage()
 {
     if (state.instantiate)
     {
         QuixConsole.WriteLine(getJSON());
         simulator.SendMessage("create", getJSON(), connectionState.workSocket);
     }
 }
예제 #8
0
 public void Jump(MoveMessage message)
 {
     if (!Agent.IsLocked())
     {
         QuixConsole.Log("Jump");
         Agent.ChangeState(jumpState);
         Agent.Lock(130);
     }
 }
예제 #9
0
 private void LoadMeshes()
 {
     LoadMesh("Stadiums/CrocoLoco/piedra1");
     LoadMesh("Stadiums/CrocoLoco/piedra2");
     LoadMesh("Stadiums/CrocoLoco/stand_croco");
     LoadMesh("Stadiums/CrocoLoco/start_position");
     LoadMesh("newt");
     QuixConsole.Log("Reload meshes");
 }
예제 #10
0
        public void OnActivate()
        {
            // throw new NotImplementedException();
            PhyTimeOut timeOut = new PhyTimeOut(10, player.simulator);

            timeOut.Completed += SendMessage;
            Snap();
            QuixConsole.Log("Snapped state");
        }
예제 #11
0
 public void ChangeState(AgentState state)
 {
     QuixConsole.Log("Is locked", isLocked, state, lockedTime);
     if (!this.isLocked)
     {
         //QuixConsole.Log("Changing state to",state.GetType().ToString());
         this._checkToChangeState(state);
     }
 }
예제 #12
0
        internal void Shoot(string data)
        {
            QuixConsole.WriteLine(data);
            ShootMessage j2 = JsonConvert.DeserializeObject <ShootMessage>(data);
            //objects[]
            Player2 onb2 = (Player2)simulator.users[j2.client].player;

            // Simulation.Awakener.AwakenBody(ob.bodyHandle);
            onb2.Shoot(j2);
        }
예제 #13
0
        internal void UseGauntlet(string data)
        {
            QuixConsole.Log("Use gauntlet", data);
            GauntletMessage j2 = JsonConvert.DeserializeObject <GauntletMessage>(data);
            //objects[]
            Player2 onb2 = (Player2)simulator.users[j2.client].player;

            // Simulation.Awakener.AwakenBody(ob.bodyHandle);
            onb2.UseGauntlet(j2.active);
        }
예제 #14
0
        internal void Swipe(string data)
        {
            QuixConsole.Log("Swiping", data);
            SwipeMessage j2 = JsonConvert.DeserializeObject <SwipeMessage>(data);
            //objects[]
            Player2 onb2 = (Player2)simulator.users[j2.client].player;

            // Simulation.Awakener.AwakenBody(ob.bodyHandle);
            onb2.Swipe(j2.degree, j2.direction);
        }
예제 #15
0
        public DataBase()
        {
            QuixConsole.WriteLine("Init Database");
            MongoClient dbClient = new MongoClient("mongodb://localhost/golf");

            database = dbClient.GetDatabase("golf");
            maps     = database.GetCollection <MapMongo>("maps");


            //GetMap("arena");
        }
예제 #16
0
        internal void Update(TimeSpan gameTime)
        {
            //Console.WriteLine(gameTime.TotalSeconds);
            handleWorkers();
            Simulation.Timestep(1 / 10f, ThreadDispatcher);

            ArrayList bodies = new ArrayList();
            var       set    = Simulation.Bodies.Sets[0];

            if (t == tMax)
            {
                // createObjects();
                t = 0;
            }
            t++;


            for (var bodyIndex = 0; bodyIndex < set.Count; ++bodyIndex)
            {
                try
                {
                    //var handle = set.IndexToHandle[bodyIndex];
                    // if(objects.ContainsValue())
                    var handle = set.IndexToHandle[bodyIndex];
                    if (objectsHandlers[handle].state.instantiate)
                    {
                        bodies.Add(objectsHandlers[handle].getJSON());
                    }
                }
                catch (KeyNotFoundException e)
                {
                    QuixConsole.WriteLine("Key not found");
                }
            }


            foreach (var item in staticObjectsHandlers)
            {
                if (item.Value.needUpdate)
                {
                    bodies.Add(item.Value.getJSON());
                    item.Value.needUpdate = false;
                }
            }

            if (bodies.Count > 0)
            {
                SendMessage("update", JsonConvert.SerializeObject(bodies), connectionState.workSocket);
            }

            commandReader.ReadCommand();
        }
예제 #17
0
 private bool IsAnyPlayerVisible(TimeData arg)
 {
     foreach (var user in crocoLoco.simulator.users)
     {
         var distance = Vector3.Distance(crocoLoco.reference.Pose.Position, user.Value.player.reference.Pose.Position);
         QuixConsole.Log(distance);
         if (distance < properties.watchLength)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #18
0
        private void CreateUser()
        {
            User s = new User(state.owner, this);

            if (!simulator.users.ContainsKey(state.owner))
            {
                simulator.users.Add(state.owner, s);
            }
            else
            {
                QuixConsole.Log("User has been already added");
            }
        }
예제 #19
0
 public void Shoot(ShootMessage message)
 {
     if (Agent.ActualState() == snappedState)
     {
         QuixConsole.WriteLine("Shotting");
         shotState.message = message;
         Agent.ChangeState(shotState);
         Agent.Lock(130);
     }
     else
     {
     }
 }
예제 #20
0
        public void ReadCallback(IAsyncResult ar)
        {
            ConnectionState state   = (ConnectionState)ar.AsyncState;
            String          content = String.Empty;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.

            Socket handler = state.workSocket;


            // Read data from the client socket.
            if (handler.Connected)
            {
                try{
                    int bytesRead = handler.EndReceive(ar);



                    if (bytesRead > 0)
                    {
                        // There  might be more data, so store the data received so far.
                        state.sb.Append(Encoding.ASCII.GetString(
                                            state.buffer, 0, bytesRead));

                        // Check for end-of-file tag. If it is not there, read
                        // more data.
                        content = state.sb.ToString();

                        var splited = content.Split("<L@>");

                        for (int a = 0; a < splited.Length; a++)
                        {
                            if (state.simulator != null)
                            {
                                if (splited[a] != "")
                                {
                                    state.simulator.commandReader.AddCommandToBeRead(splited[a]);
                                }
                            }
                        }
                        state.sb.Clear();
                        handler.BeginReceive(state.buffer, 0, ConnectionState.BufferSize, 0,
                                             new AsyncCallback(ReadCallback), state);
                    }
                }catch (SocketException e) {
                    QuixConsole.Log("Socket exception", e);
                }
            }
        }
예제 #21
0
 public void Tick()
 {
     if (this.state != null)
     {
         this.state.Tick();
     }
     if (this.isLocked)
     {
         if (this.lockedTick == this.lockedTime)
         {
             QuixConsole.Log("unLocked", lockedTick);
             this.Unlock();
         }
         this.lockedTick++;
     }
 }
예제 #22
0
        public PhyObject Create(ObjectState state)
        {
            PhyObject phy = null;

            if (state.uID == null || objects.ContainsKey(state.uID))
            {
                state.uID = PhyObject.createUID();
            }
            if (state is BoxState)
            {
                if (state.isMesh)
                {
                    phy = CreateMesh((BoxState)state);
                }
                else
                {
                    phy = CreateBox((BoxState)state);
                }
            }
            if (state is SphereState)
            {
                phy = CreateSphere((SphereState)state);
            }

            if (phy.material == default(SimpleMaterial))
            {
                collidableMaterials.Allocate(phy.bodyHandle) = new SimpleMaterial
                {
                    FrictionCoefficient     = .1f,
                    MaximumRecoveryVelocity = float.MaxValue,
                    SpringSettings          = new SpringSettings(1f, 1.5f)
                };
            }

            if (!objects.ContainsKey(state.uID))
            {
                objects.Add(state.uID, phy);
            }
            else
            {
                QuixConsole.WriteLine("Objects already had that key");
            }
            return(phy);
        }
예제 #23
0
        public void StartListening()
        {
            IPAddress  ipAddress     = IPAddress.Parse("127.0.0.1");
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 1337);

            // Create a TCP/IP socket.
            Socket listener = new Socket(ipAddress.AddressFamily,
                                         SocketType.Stream, ProtocolType.Tcp);


            //Simulator simulator = new Simulator(new ConnectionState(), this);
            // Bind the socket to the local endpoint and listen for incoming connections.
            try
            {
                listener.Bind(localEndPoint);
                listener.Listen();
                QuixConsole.Log("QuixPhysicsServer is", "running");

                while (isRunning)
                {
                    // Set the event to nonsignaled state.
                    allDone.Reset();

                    // Start an asynchronous socket to listen for connections.
                    QuixConsole.WriteLine("Waiting for a connection...");
                    listener.BeginAccept(
                        new AsyncCallback(AcceptCallback),
                        listener);

                    // Wait until a connection is made before continuing.
                    allDone.WaitOne();
                }
            }
            catch (Exception e)
            {
                QuixConsole.WriteLine(e.ToString());
            }

            QuixConsole.WriteLine("\nPress ENTER to continue...");
        }
예제 #24
0
 private void Jump()
 {
     QuixConsole.Log("Jumping!");
     phy.reference.Awake              = true;
     phy.reference.Velocity.Linear.Y += 50;
 }
예제 #25
0
 public CrocoLoco()
 {
     QuixConsole.WriteLine("Crocoloco");
 }
예제 #26
0
        internal void ReadCommand()
        {
            //Console.WriteLine("Read command: {0}", v);

            try
            {
                foreach (var item in commandsList)
                {
                    JsonSerializerSettings setting = new JsonSerializerSettings();
                    setting.CheckAdditionalContent = false;

                    Newtonsoft.Json.Linq.JObject message = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>((string)item, setting);
                    string type = (string)message["type"];
                    switch (type)
                    {
                    case "create":

                        // Console.WriteLine(message);

                        if (message["data"]["halfSize"] != null)
                        {
                            BoxState ob = JsonConvert.DeserializeObject <BoxState>(((object)message["data"]).ToString());
                            simulator.Create(ob);
                        }

                        if (message["data"]["radius"] != null)
                        {
                            SphereState ob = JsonConvert.DeserializeObject <SphereState>(((object)message["data"]).ToString());
                            simulator.Create(ob);
                            break;
                        }

                        break;

                    case "createBoxes":
                        //Console.WriteLine("Create boxes");
                        // simulator.boxToCreate = 10;
                        simulator.createObjects();
                        break;

                    case "gauntlet":

                        UseGauntlet(((object)message["data"]).ToString());
                        break;

                    case "move":

                        MoveMessage j = JsonConvert.DeserializeObject <MoveMessage>(((object)message["data"]).ToString());
                        //objects[]
                        Player2 onb = (Player2)simulator.users[j.client].player;
                        // Simulation.Awakener.AwakenBody(ob.bodyHandle);
                        onb.Move(j);

                        break;

                    case "rotate":
                        MoveMessage j2 = JsonConvert.DeserializeObject <MoveMessage>(((object)message["data"]).ToString());
                        //objects[]
                        Player2 onb2 = (Player2)simulator.users[j2.client].player;
                        // Simulation.Awakener.AwakenBody(ob.bodyHandle);
                        onb2.Rotate(j2);
                        break;

                    case "jump":
                        Jump(((object)message["data"]).ToString());
                        break;

                    case "shoot":
                        Shoot(((object)message["data"]).ToString());
                        break;

                    case "swipe":
                        Swipe(((object)message["data"]).ToString());
                        break;

                    case "generateMap":

                        var map = this.simulator.server.dataBase.GetMap((string)message["data"]);
                        this.simulator.map = map;

                        foreach (var obj in map.objects)
                        {
                            //obj.ToJson();
                            if (obj.Contains("halfSize"))
                            {
                                obj["halfSize"].AsBsonDocument.Remove("__refId");
                                obj.Remove("_id");
                                var stri = JsonConvert.DeserializeObject <BoxState>(obj.ToJson());
                                stri.quaternion = JsonConvert.DeserializeObject <Quaternion>(obj["quat"].ToJson());

                                this.simulator.Create(stri);
                            }
                            if (obj.Contains("radius"))
                            {
                                // obj["radius"].AsBsonDocument.Remove("__refId");
                                obj.Remove("_id");
                                var stri = JsonConvert.DeserializeObject <SphereState>(obj.ToJson());
                                stri.quaternion = JsonConvert.DeserializeObject <Quaternion>(obj["quat"].ToJson());

                                this.simulator.Create(stri);
                            }
                        }
                        break;

                    case "close":
                        //Console.WriteLine("Close");
                        simulator.Close();

                        break;

                    default:
                        QuixConsole.WriteLine("Command not registred " + type);
                        break;
                    }
                }

                commandsList.Clear();
            }
            catch (InvalidOperationException e)
            {
                QuixConsole.Log("Collection was modifieded", e);
            }
            catch (JsonReaderException e)
            {
                QuixConsole.Log("Json Problem ", e);
            }
            catch (Exception e) {
                QuixConsole.WriteLine(e);
            }
        }