示例#1
0
        static void Main(string[] args)
        {
            //initialize variables
            eList         = new EntityList();
            serverHandler = new ServerHandler(eList);
            gm            = new GameManager(eList, serverHandler);

            //main game loop (server)
            long   lastTime      = nanoTime();
            double amountOfTicks = 60.0;
            double ns            = 1000000000 / amountOfTicks;
            double delta         = 0;
            long   timer         = currentTimeMillis();
            int    updates       = 0;

            while (true)
            {
                long now = nanoTime();
                delta   += (now - lastTime) / ns;
                lastTime = now;
                while (delta >= 1)
                {
                    serverHandler.update();
                    gm.tick();
                    updates++;
                    delta--;
                }
                if (currentTimeMillis() - timer > 1000)
                {
                    timer += 1000;
                    Console.WriteLine(updates);
                    updates = 0;
                }
            }
        }
 public GameManager(EntityList eList, ServerHandler sHandler)
 {
     this.eList    = eList;
     this.sHandler = sHandler;
 }