Exemplo n.º 1
0
        private void main_loop()
        {
            long begin_time = stopwatch_.ElapsedTicks;

            // flip
            int updating_front = 1 - rendering_front_;

            // update
            if (!pause_)
            {
                // adaptive frame rate
                setFPS((int)(1f / elapsed_frame_time_));       // call here for stable DT during pause.

                if (Options.Instance.PerformanceMeter &&
                    InputManager.Instance.getButton(InputManager.Button.FFWPlus) > 0)
                {
                    fast_forward_ratio_ += 9;
                }
                if (InputManager.Instance.getButton(InputManager.Button.FFWMinus) > 0)
                {
                    fast_forward_ratio_ -= 9;
                }
                fast_forward_ratio_ = Mathf.Clamp(fast_forward_ratio_, 1, 10);

                for (var i = 0; i < fast_forward_ratio_; ++i)
                {
                    update_flow_speed(dt_);
                    TubeScroller.Instance.update(dt_, flow_speed_);
                    GameManager.Instance.update(dt_, update_time_);
                    Player.Instance.update(dt_, update_time_, flow_speed_);
                    TaskManager.Instance.update(dt_, update_time_, flow_speed_);
                    // lockon
                    bool locked = false;
                    if (player_.isNowLocking())
                    {
                        locked = LockTarget.checkAll(player_, update_time_);
                    }
                    // collision
                    MyCollider.calculate();

                    if (locked)
                    {
                        registSound(DrawBuffer.SE.Lockon);
                    }
                    if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0)
                    {
                        pause_ = true;
                        registBgm(DrawBuffer.BGM.Pause);
                        registMotion(DrawBuffer.Motion.Pause);
                    }
                    ++update_frame_;
                    update_time_ += dt_;
                }
            }
            else
            {
                if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0)
                {
                    pause_ = false;
                    registBgm(DrawBuffer.BGM.Resume);
                    registMotion(DrawBuffer.Motion.Resume);
                }
                else
                {
                    if (InputManager.Instance.getButton(InputManager.Button.Back) > 0)
                    {
                        long  elapsed_tick = stopwatch_.ElapsedTicks - pause_back_time_;
                        float elapsed      = (float)elapsed_tick / ((float)System.Diagnostics.Stopwatch.Frequency);
                        if (elapsed > 1f)
                        {
                            GameManager.Instance.setReplayMode(false);
                            restart();
                            pause_ = false;
                        }
                    }
                    else
                    {
                        pause_back_time_ = stopwatch_.ElapsedTicks;
                    }
                }
            }
            // profile
            update_tick_ = stopwatch_.ElapsedTicks - begin_time;
            begin_time   = stopwatch_.ElapsedTicks;

            // begin
            MyFont.Instance.begin();
            MySprite.Instance.begin();
            VRSprite.Instance.begin();
            Sight.Instance.begin();
            Beam.Instance.begin(updating_front);
            Beam2.Instance.begin(updating_front);
            Trail.Instance.begin(updating_front);
            Spark.Instance.begin();
            Explosion.Instance.begin();
            Hahen.Instance.begin();
            Shockwave.Instance.begin();
            Shield.Instance.begin();

            // renderUpdate
            draw_buffer_[updating_front].beginRender();
            my_camera_.renderUpdate(updating_front, ref draw_buffer_[updating_front]);
            player_.renderUpdate(updating_front, ref draw_buffer_[updating_front]);
            TaskManager.Instance.renderUpdate(updating_front, my_camera_, ref draw_buffer_[updating_front]);

            // debug info
            renderUpdate_debug_info(updating_front);

            // end
            Shield.Instance.end(updating_front);
            Shockwave.Instance.end(updating_front);
            Hahen.Instance.end(updating_front);
            Explosion.Instance.end(updating_front);
            Spark.Instance.end(updating_front);
            Trail.Instance.end();
            Beam2.Instance.end();
            Beam.Instance.end();
            Sight.Instance.end(updating_front);
            VRSprite.Instance.end(updating_front);
            MySprite.Instance.end(updating_front);
            MyFont.Instance.end(updating_front);

            render_update_tick_ = stopwatch_.ElapsedTicks - begin_time;
        }
Exemplo n.º 2
0
        private void main_loop()
        {
            long begin_time = stopwatch_.ElapsedTicks;

            // flip
            int updating_front = 1 - rendering_front_;

            // begin
            Sight.Instance.begin();
            MySprite.Instance.begin();
            MyFont.Instance.begin();
            Beam.Instance.begin(updating_front);
            Trail.Instance.begin(updating_front);
            Spark.Instance.begin();
            Explosion.Instance.begin();
            Hahen.Instance.begin();

            // update
            bool locked = false;

            if (!pause_)
            {
                GameManager.Instance.update(dt_, update_time_);
                TaskManager.Instance.update(dt_, update_time_);
                // lockon
                locked = LockTarget.checkAll(player_);
                Sight.Instance.updateAll(dt_);
                // HUD
                HUD.Instance.update(dt_, update_time_);
                // collision
                MyCollider.calculate();

                if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0)
                {
                    pause_ = true;
                }
                ++update_frame_;
                update_time_ += dt_;
            }
            else
            {
                if (InputManager.Instance.getButton(InputManager.Button.Pause) > 0)
                {
                    pause_ = false;
                }
            }
            if (locked)
            {
                registSound(DrawBuffer.SE.Lockon);
            }
            update_tick_ = stopwatch_.ElapsedTicks - begin_time;
            begin_time   = stopwatch_.ElapsedTicks;

            // renderUpdate
            draw_buffer_[updating_front].beginRender();
            TaskManager.Instance.renderUpdate(updating_front, ref draw_buffer_[updating_front]);

            // HUD
            HUD.Instance.renderUpdate(updating_front);

            render_update_tick_ = stopwatch_.ElapsedTicks - begin_time;
            // debug info
            if (Options.Instance.PerformanceMeter)
            {
                {
                    MyFont.Instance.putNumber(updating_front, (int)update_frame_, 8 /* keta */, 0.5f /* scale */,
                                              -440f, 270f, MyFont.Type.Green);
                }
                {
                    int gc_count = System.GC.CollectionCount(0 /* generation */) - gc_start_count_;
                    MyFont.Instance.putNumber(updating_front, gc_count, 8 /* keta */, 0.5f /* scale */,
                                              -440f, 254f, MyFont.Type.Red);
                }
                if (used_heap_size_ != 0)
                {
                    int bytes = (int)used_heap_size_;
                    MyFont.Instance.putNumber(updating_front, bytes, 9 /* keta */, 0.5f /* scale */,
                                              -340f, 254f, MyFont.Type.Red);
                }
                if (mono_heap_size_ != 0)
                {
                    int bytes = (int)mono_heap_size_;
                    MyFont.Instance.putNumber(updating_front, bytes, 9 /* keta */, 0.5f /* scale */,
                                              -240f, 254f, MyFont.Type.Red);
                }
                if (mono_used_size_ != 0)
                {
                    int bytes = (int)mono_used_size_;
                    MyFont.Instance.putNumber(updating_front, bytes, 9 /* keta */, 0.5f /* scale */,
                                              -140f, 254f, MyFont.Type.Red);
                }
                {
                    int task_count = TaskManager.Instance.getCount();
                    MyFont.Instance.putNumber(updating_front, task_count, 8 /* keta */, 0.5f /* scale */,
                                              -440f, 238f, MyFont.Type.Blue);
                }

                var height   = 5f;
                var length   = 440f;
                var badget   = 16.666f;
                var update_y = 262f;
                var render_y = 254f;
                {
                    var rect0b = new Rect(-length * 0.5f, update_y, length, height);
                    MySprite.Instance.put(updating_front, ref rect0b, MySprite.Kind.Square, MySprite.Type.Black);

                    var update_ratio = (float)update_tick_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget);
                    var rect1b       = new Rect(length * (update_ratio * 0.5f - 1f), update_y,
                                                length * update_ratio, height);
                    MySprite.Instance.put(updating_front, ref rect1b, MySprite.Kind.Square, MySprite.Type.Blue);

                    var render_update_ratio = (float)render_update_tick_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget);
                    var rect2b = new Rect(length * (update_ratio - 1f + render_update_ratio * 0.5f), update_y,
                                          length * update_ratio, height);
                    MySprite.Instance.put(updating_front, ref rect2b, MySprite.Kind.Square, MySprite.Type.Green);
                }
#if UNITY_PSP2 || UNITY_PS4
                {
                    var render_ratio = (float)render_tick_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget);
                    var rect0b       = new Rect(-length * 0.5f, render_y, length, height);
                    MySprite.Instance.put(updating_front, ref rect0b, MySprite.Kind.Square, MySprite.Type.Black);
                    var rect1b = new Rect(length * (render_ratio * 0.5f - 1f), render_y, length * render_ratio, height);
                    MySprite.Instance.put(updating_front, ref rect1b, MySprite.Kind.Square, MySprite.Type.Red);

                    var render_ratio_begin = (float)render_tick3_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget);
                    var render_ratio_end   = (float)render_tick4_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget);
                    var render_ratio_len   = render_ratio_end - render_ratio_begin;
                    var rect2b             = new Rect(length * (render_ratio_len * 0.5f - 1f + render_ratio_begin * 0.5f), render_y,
                                                      length * (render_ratio_len), height);
                    MySprite.Instance.put(updating_front, ref rect2b, MySprite.Kind.Square, MySprite.Type.Magenta);
                }
#else
                {
                    var render_ratio = (float)render_tick2_ * 1000f / ((float)System.Diagnostics.Stopwatch.Frequency * badget);
                    var rect0b       = new Rect(-length * 0.5f, render_y, length, height);
                    MySprite.Instance.put(updating_front, ref rect0b, MySprite.Kind.Square, MySprite.Type.Black);
                    var rect1b = new Rect(length * (render_ratio * 0.5f - 1f), render_y, length * render_ratio, height);
                    MySprite.Instance.put(updating_front, ref rect1b, MySprite.Kind.Square, MySprite.Type.Red);
                }
#endif
            }

            // end
            Hahen.Instance.end(updating_front);
            Explosion.Instance.end(updating_front);
            Spark.Instance.end(updating_front);
            Trail.Instance.end();
            Beam.Instance.end();
            MyFont.Instance.end(updating_front);
            MySprite.Instance.end(updating_front);
            Sight.Instance.end(updating_front);
        }
Exemplo n.º 3
0
        private void main_loop()
        {
            PerformanceMeter.Instance.beginUpdate();
            int updating_front = get_front();

            // fetch
            Controller.Instance.fetch(updating_front, update_time_);

            var controller = Controller.Instance.getLatest();

            if (!pause_ && controller.isPauseButtonDown())
            {
                pause_ = true;
            }
#if UNITY_EDITOR
            else if (pause_ && controller.isPauseButtonDown())
            {
                pause_ = false;
            }
#endif

            // update
            if (!pause_)
            {
                int loop_num = 1;
                if (PerformanceMeter.Instance.wasSlowLoop())
                {
                    loop_num = 2;
                }
                for (var loop = 0; loop < loop_num; ++loop)
                {
                    GameManager.Instance.update(dt_, update_time_);
                    TaskManager.Instance.update(dt_, update_time_);
                    MyCollider.calculate();
                    WaterSplash.Instance.update(update_time_);
                    ++update_frame_;
                    update_time_ += dt_;
                }
            }
            PerformanceMeter.Instance.endUpdate();

            PerformanceMeter.Instance.beginRenderUpdate();
            CameraBase current_camera = spectator_mode_ ? spectator_camera_ : my_camera_;
            // begin
            MySprite.Instance.begin();
            MyFont.Instance.begin();
            Spark.Instance.begin();
            Beam.Instance.begin(updating_front);
            Beam2.Instance.begin(updating_front);
            Explosion.Instance.begin();
            Hahen.Instance.begin();
            Shield.Instance.begin();
            Sight.Instance.begin(updating_front);

            // renderUpdate
            draw_buffer_[updating_front].beginRender();
            WaterSurface.Instance.renderUpdate(updating_front);
            WaterSplash.Instance.renderUpdate(updating_front);
            TaskManager.Instance.renderUpdate(updating_front,
                                              current_camera,
                                              ref draw_buffer_[updating_front]);
            draw_buffer_[updating_front].endRender();

            // performance meter
#if UTJ_MULTI_THREADED
            bool multi_threading = true;
#else
            bool multi_threading = false;
#endif
            PerformanceMeter.Instance.drawMeters(updating_front, multi_threading);

            // end
            Sight.Instance.end(updating_front, current_camera);
            Shield.Instance.end(updating_front);
            Hahen.Instance.end(updating_front);
            Explosion.Instance.end(updating_front);
            Beam2.Instance.end();
            Beam.Instance.end();
            Spark.Instance.end(updating_front);
            MyFont.Instance.end(updating_front);
            MySprite.Instance.end(updating_front);

            PerformanceMeter.Instance.endRenderUpdate();
        }