コード例 #1
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();
        }
コード例 #2
0
        private void CreateSimulator(ConnectionState socket)
        {
            QuixConsole.WriteLine("Create simulator");
            Simulator simulator = new Simulator(socket, this);

            socket.simulator = simulator;
        }
コード例 #3
0
 new public void SendCreateMessage()
 {
     if (state.instantiate)
     {
         QuixConsole.WriteLine(getJSON());
         simulator.SendMessage("create", getJSON(), connectionState.workSocket);
     }
 }
コード例 #4
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);
        }
コード例 #5
0
ファイル: DataBase.cs プロジェクト: ciberchico420/QuixPhysics
        public DataBase()
        {
            QuixConsole.WriteLine("Init Database");
            MongoClient dbClient = new MongoClient("mongodb://localhost/golf");

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


            //GetMap("arena");
        }
コード例 #6
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();
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: ciberchico420/QuixPhysics
 public void Shoot(ShootMessage message)
 {
     if (Agent.ActualState() == snappedState)
     {
         QuixConsole.WriteLine("Shotting");
         shotState.message = message;
         Agent.ChangeState(shotState);
         Agent.Lock(130);
     }
     else
     {
     }
 }
コード例 #8
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);
        }
コード例 #9
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...");
        }
コード例 #10
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);
            }
        }
コード例 #11
0
 public CrocoLoco()
 {
     QuixConsole.WriteLine("Crocoloco");
 }