Ejemplo n.º 1
0
        public static Thread GetRunLoopThread(EntityEngine engine = null, bool generateMembers = false)
        {
            bool nullEngine = false;

            if (engine == null)
            {
                engine = new EntityEngine(); nullEngine = true;
            }

            if (generateMembers || nullEngine)
            {
                engine.GenerateManagers();
                engine.GenerateFrameRate();
            }

            if (engine.IsEngineReady)
            {
                return(new Thread(() =>
                {
                    engine.manualTickAllowed = false;
                    engine.Start();
                    while (engine.IsRunning)
                    {
                        if (!engine.IsPaused)
                        {
                            if (engine.engineFrameTick())
                            {
                                engine.OnEngineFrameTick(engine, new Events.EngineFrameTickEventArgs {
                                });
                            }
                        }
                    }
                    engine.manualTickAllowed = true;
                }));
            }
            else
            {
                engine.RaiseErrorEvent(new Events.ErrorEventArgs
                {
                    errorLevel = Events.ErrorEventArgs.ErrorLevel.Error,
                    message    = "Engine not ready to start"
                });
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static bool RunLoop(EntityEngine engine = null, bool generateMembers = false)
        {
            bool nullEngine = false;

            if (engine == null)
            { engine = new EntityEngine(); nullEngine = true; }

            if (generateMembers || nullEngine)
            {
                engine.GenerateManagers();
                engine.GenerateFrameRate();
            }

            if (engine.IsEngineReady)
            {
                engine.manualTickAllowed = false;
                engine.Start();
                while (engine.IsRunning)
                {
                    if (!engine.IsPaused)
                    {
                        if (engine.engineFrameTick())
                            engine.OnEngineFrameTick(engine, new Events.EngineFrameTickEventArgs { });
                    }
                }
                engine.manualTickAllowed = true;
                return true;
            }
            else
            {
                engine.RaiseErrorEvent(new Events.ErrorEventArgs {
                    errorLevel = Events.ErrorEventArgs.ErrorLevel.Error,
                    message = "Engine not ready to start"
                });
                return false;
            }
        }