public ServerEngine(int serverPort, int maxClients/*map name, etc*/)
        {
            // Server creation
            elapsedTime = 0;
            commands = new ConcurrentQueue<Command.Command>();
            updatedPositions = new ConcurrentQueue<KeyValuePair<Player, Position>>();
            newPlayers = new ConcurrentQueue<Player>();
            communication = new ENetServer(serverPort, maxClients, this);
            communication.Launch();

            // Environment initialization
            //XMLReader xmlTest = new XMLReader("../../../map_official.xml");
            XMLReader xmlTest = new XMLReader("xml/map.xml");
            Constants.Instance.init();

            Map map = new Map(xmlTest.upperLeft, xmlTest.lowerRight, xmlTest.listObstacle, xmlTest.listWall);
            Player player = new Player("Champ");

            environment = GameEnvironment.Instance;
            environment.init(map, player);

            pengine = new PhysicsEngine(environment.Map);

            Character character = new Character("swattds", pengine, new Vector2(200, 100), new Vector2(75, 75), 55);

            //Character redshirt = new Character("Redshirt", pengine, new Vector2(400, 100), new Vector2(100, 100));
            player.addCharacter(character);
            //player.addCharacter(redshirt);
        }
 public LightEnvironment(GameEnvironment ge)
 {
     map = ge.Map;
     players = new List<LightPlayer>();
     foreach (Player p in ge.Players)
     {
         players.Add(new LightPlayer(p));
     }
 }
        public Game1(ServerEngine eng)
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            //graphics.PreferredBackBufferWidth = 800;
            //graphics.PreferredBackBufferHeight = 600;

            graphics.PreferredBackBufferWidth = 1024;
            graphics.PreferredBackBufferHeight = 768;
            gengine = eng;
            environment = gengine.getEnvironment();
        }
 public Game1(ClientEngine eng)
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     //graphics.PreferredBackBufferWidth = 600;//1024;
     //graphics.PreferredBackBufferHeight = 480;//768;
     graphics.PreferredBackBufferWidth = 1024;
     graphics.PreferredBackBufferHeight = 768;
     gengine = eng;
     while (!eng.ready)
     {
         // horrible
     }
     environment = gengine.getEnvironment();
 }
        public void setEnvironment(LightEnvironment env)
        {
            Player local = new Player("Georges"); // TODO : change this

            environment = GameEnvironment.Instance;
            environment.init(env.map, local);

            pengine = new PhysicsEngine(environment.Map);

            //Character character = new Character("patate", pengine, new Vector2(150, 300), new Vector2(50, 50));
            Character character = new Character("swattds", pengine, new Vector2(150, 300), new Vector2(75, 75), 55);
            local.addCharacter(character);

            foreach (LightPlayer lp in env.players)
            {
                Player p = new Player(lp.name);
                Character c = new Character(lp.character.textureName, pengine, lp.character.position, lp.character.size, lp.character.size.X);
                p.addCharacter(c);
                environment.AddPlayer(p);
            }

            // Sending local info to server
            communication.SendReliable(new LightPlayer(local), NetFrame.FrameType.player);

            ready = true;
        }
        /// <summary>
        /// Draws the entities previously added to the entity list
        /// </summary>
        public void Draw(GameEnvironment environment)
        {
            updateCameraPosition();

            spriteBatch.Begin(); // TODO rm useless?

            //graphicDevice.Clear(Color.CornflowerBlue);
            //graphicDevice.Clear(Color.Black);
            //graphicDevice.Clear(Color.DarkGray);
            graphicDevice.Clear(MapView.groundColor);

            // Drawing vision cone
            Vision vision = VisionView.Draw(this, spriteBatch, graphics, cameraPosition, new CQT.Model.Point(followedCharacter.body.position), followedCharacter.getRotation(), map.getVisionBlockingLines());

            // Blood
            foreach (Polyline pl in environment.bloodStains)
            {
                AddPolygon(pl, Color.DarkRed);
            }

            // Drawing map
            if (map != null && followedCharacter.isAlive)
            {
                MapView.Draw(map, this);
            }

            /*
            // Drawing sprites
            foreach (Entity e in entities)
            {
                EntityView.Draw(spriteBatch, cache, cameraPosition, e);
            }
            */

            Color bulletColor = Color.Red;

            foreach (Model.Line l in environment.bulletTrails)
            {
                /*AddLine(l, bulletColor);
                AddLine(l.TranslatePerpendicular(1), bulletColor);*/
                Line currentLine = l;
                const int thickness = 4;
                for (int i = 0; i < thickness; i++)
                {
                    AddLine(currentLine, bulletColor);
                    if (i != thickness - 1)
                        currentLine = currentLine.TranslatePerpendicular(.8f);
                }
                AddLine(l.TranslatePerpendicular(.8f*(thickness/2f)), Color.Yellow);
            }
            environment.bulletTrails.Clear();

            foreach (Model.Point pt in environment.bulletSparks)
            {
                //AddPoint(pt, Color.Yellow);
                //AddTriangle(pt.asVector, Color.Yellow);
                float siz = 25;
                AddTriangle(
                    pt.Translated(nextVector2(siz)),
                    pt.Translated(nextVector2(siz)),
                    pt.Translated(nextVector2(siz)),
                bulletColor);
                AddTriangle(
                    pt.Translated(nextVector2(siz/2)),
                    pt.Translated(nextVector2(siz/2)),
                    pt.Translated(nextVector2(siz/2)),
                Color.Yellow);
            }
            environment.bulletSparks.Clear();

            spriteBatch.End();

            // Drawing primitives
            // Game coordinates -> Screen coordinates
            basicEffect.View = Matrix.CreateTranslation(cameraPosition.X, cameraPosition.Y, 0);
            basicEffect.CurrentTechnique.Passes[0].Apply();

            graphicDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList,
                triangles.ToArray(), 0, triangles.Count / 3);
            foreach (List<VertexPositionColor> pl in polylines)
            {
                graphicDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, pl.ToArray(), 0, pl.Count - 1);
            }
            graphicDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, lines.ToArray(), 0, lines.Count / 2);

            spriteBatch.Begin();
            // Drawing sprites
            foreach (Entity e in entities)
            {
                EntityView.Draw(spriteBatch, cache, cameraPosition, e, e == followedCharacter? null: vision);
            }
            spriteBatch.End();

            entities.Clear();
            lines.Clear();
            polylines.Clear();
            triangles.Clear();
        }