Esempio n. 1
0
        static void RunOutgame(RegisterMemory rmem)
        {
            try
            {
                GameTime.Update();
                GUCTimer.Update(GameTime.Ticks);

                GameTime.Update();
                GameClient.Update();

                GameTime.Update();
                InputHandler.Update();

                if (!ShowConnectionAttempts())
                {
                    if (!outgameStarted)
                    {
                        outgameStarted = true;
                        VobRenderArgs.Init();
                        ScriptManager.Interface.StartOutgame();
                    }

                    GameTime.Update();
                    ScriptManager.Interface.Update(GameTime.Ticks);
                }

                #region Gothic

                WinApi.Process.CDECLCALL <WinApi.NullReturnCall>(0x5053E0); // void __cdecl sysEvent(void)

                using (zColor color = zColor.Create(0, 0, 0, 0))
                    zCRenderer.Vid_Clear(color, 3);

                zCRenderer.BeginFrame();
                zCView.GetScreen().Render();
                zCRenderer.EndFrame();
                zCRenderer.Vid_Blit(1, 0, 0);
                zCSndSys_MSS.DoSoundUpdate();

                #endregion

                if (fpsWatch.IsRunning)
                {
                    long diff = 8 * TimeSpan.TicksPerMillisecond - fpsWatch.Elapsed.Ticks;
                    if (diff > 0)
                    {
                        Thread.Sleep((int)(diff / TimeSpan.TicksPerMillisecond));
                    }
                }
                fpsWatch.Restart();
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Esempio n. 2
0
        static void RunServer()
        {
            try
            {
                TimeStat  timeAll         = new TimeStat();
                LockTimer perfUpdateTimer = new LockTimer(60 * 1000);
                perfUpdateTimer.Trigger();

                while (true)
                {
                    timeAll.Start();

                    GameTime.Update();
                    OnTick?.Invoke();

                    GameTime.Update();
                    GUCTimer.Update(GameTime.Ticks); // move to new thread?

                    //Run the dispatcher
                    GUCDispatcher.Execute();


                    GameTime.Update();
                    GameServer.Update(); //process received packets

                    GameTime.Update();
                    WorldObjects.World.ForEach(w => w.OnTick(GameTime.Ticks));

                    long elapsed = timeAll.Stop();
                    if (perfUpdateTimer.IsReady)
                    {
                        Logger.Log("Performance: {0:0}ms avg, {1:0}ms max. RAM: {2:0.0}MB", timeAll.Average, timeAll.Maximum, Process.GetCurrentProcess().PrivateMemorySize64 / 1000000d);
                        timeAll.Reset();
                    }

                    long diff = (updateRate - elapsed) / TimeSpan.TicksPerMillisecond;
                    if (diff > 0)
                    {
                        Thread.Sleep((int)diff);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.Source + "<br>" + e.Message + "<br>" + e.StackTrace);
            }
        }
Esempio n. 3
0
        static void RunIngame(RegisterMemory rmem)
        {
            try
            {
                spikeWatch.Restart();
                // Update Timers
                GameTime.Update();
                GUCTimer.Update(GameTime.Ticks);

                // Do networking, read packets
                GameTime.Update();
                GameClient.Update();

                // handle peripherals' input
                GameTime.Update();
                InputHandler.Update();

                if (!ShowConnectionAttempts())
                {
                    if (!ingameStarted)
                    {
                        ingameStarted = true;
                        ScriptManager.Interface.StartIngame();
                    }

                    // ClientScripts update
                    GameTime.Update();
                    ScriptManager.Interface.Update(GameTime.Ticks);

                    if (GameClient.Client.IsIngame)
                    {
                        // Update worlds
                        GameTime.Update();
                        World.UpdateWorlds(GameTime.Ticks);
                    }

                    // Check spectator stuff
                    GameTime.Update();
                    GameClient.UpdateSpectator(GameTime.Ticks);

                    // check player hero
                    GameTime.Update();
                    NPC.UpdateHero(GameTime.Ticks);
                }

                // update guc sounds
                GameTime.Update();
                SoundHandler.Update3DSounds();

                spikeWatch.Stop();
                if (spikeTimer.IsReady)
                {
                    spikeLongest = 0;
                }
                if (spikeLongest < spikeWatch.Elapsed.Ticks)
                {
                    spikeLongest = spikeWatch.Elapsed.Ticks;
                }

                if (fpsWatch.IsRunning)
                {
                    long diff;
                    if ((diff = 8 * TimeSpan.TicksPerMillisecond - fpsWatch.Elapsed.Ticks) > 0)
                    {
                        Thread.Sleep((int)(diff / TimeSpan.TicksPerMillisecond));
                    }
                }
                lastElapsed = fpsWatch.Elapsed.Ticks;
                fpsWatch.Restart();
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }