Beispiel #1
0
        public static void Load(string filename)
        {
            if (filename.ToLowerInvariant() == _currentMap)
            {
                return;
            }

            _currentMap = filename.ToLowerInvariant();

            ConVar.SetValue("mapname", Path.GetFileNameWithoutExtension(filename));

            Stream       mapFile = FileSystem.OpenCopy(filename);
            BinaryReader reader  = new BinaryReader(mapFile);

            GBMPHeader header = new GBMPHeader();

            header.Read(reader);

            if (header.Magic != 0x504D4247 || header.Version != 500)
            {
                throw new InvalidOperationException("this isn't a GBMP v.500");
            }

            while (!mapFile.EndOfStream())
            {
                GBMPChunk chunk = new GBMPChunk();
                chunk.Read(reader);

                if (chunk.Type == 0x50414D44) // DMAP
                {
                    LoadCompressedMap(mapFile);
                }
                else if (chunk.Type == 0x5448474C) // LGHT
                {
                    LoadLights(mapFile, (chunk.Size / 16));
                }
                else
                {
                    mapFile.Position += chunk.Size;
                }
            }

            mapFile.Close();

            CellManager.InitializeFromMap();
        }
Beispiel #2
0
        /// <summary>
        /// Per-frame server processing function
        /// </summary>
        public static void Process()
        {
            if (!ConVar.GetValue <bool>("sv_running"))
            {
                return;
            }

            CellManager.Recenter(from client in _clients
                                 where client != null && client.Entity != null
                                 select client.Entity.Position);

            _residualTime += Game.FrameMsec;

            // 20 FPS = 50msec intervals
            while (_residualTime > 50)
            {
                _residualTime -= 50;
                _serverTime   += 50;

                ProcessGame();
            }
        }
Beispiel #3
0
        public static void Process()
        {
            // limit FPS and handle events
            int  minMsec = (com_maxFPS.GetValue <int>() > 0) ? (1000 / com_maxFPS.GetValue <int>()) : 1;
            uint msec    = 0;

            do
            {
                _frameTime = EventSystem.HandleEvents();

                msec = _frameTime - _lastTime;
            } while (msec < minMsec);

            // handle time scaling
            var scale = timescale.GetValue <float>();

            msec = (uint)(msec * scale);

            if (msec < 1)
            {
                msec = 1;
            }
            else if (msec > 5000)
            {
                msec = 5000;
            }

            if (msec > 500)
            {
                Log.Write(LogLevel.Info, "Hitch warning: {0} msec frame time", msec);
            }

            DeltaTime = msec / 1000f;
            FrameMsec = msec;

            _lastTime = _frameTime;

            // process the command buffer
            Command.ExecuteBuffer();

            // handle network stuff
            NetManager.Process();

            // process game stuff
            Server.Process();

            // process client
            Client.Process();

            // more stuff (needs to be moved)
            Camera.Process();

            if (!sv_running.GetValue <bool>())
            {
                CellManager.Recenter(new[] { Camera.MainCamera.Position });
            }

            Renderer2D.InitPerFrame();
            FontManager.SetColor(Color.White);

            // camera moving
            DebugCamera.Process();

            ConsoleRenderer.Process();

            // render stuff
            if (Renderer.MakeDeviceAvailable())
            {
                Renderer.Clear();

                if (Client.State == Client.ClientState.Ingame)
                {
                    DeferredRenderer.Render3DStuff(Renderer.Device);
                }

                Renderer2D.Render(Renderer.Device);
                Renderer.Device.Present();
            }
        }