protected override void OnInitialize()
        {
            PostProcessor = new PostProcessor(GameManager.GraphicsDevice,
                                              CVars.Get <float>("screen_width"),
                                              CVars.Get <float>("screen_height"));
            PostProcessor.RegisterEvents(); // Responds to ResizeEvent; keep outside of RegisterListeners

            Camera = new Camera(CVars.Get <float>("screen_width"), CVars.Get <float>("screen_height"));
            Camera.RegisterEvents();
            DebugCamera = new DebugCamera(CVars.Get <float>("screen_width"), CVars.Get <float>("screen_height"));
            DebugCamera.RegisterEvents();

            VelocityParticleManager = new ParticleManager <VelocityParticleInfo>(1024 * 20, VelocityParticleInfo.UpdateParticle);
            ProcessManager.Attach(VelocityParticleManager);
            GPUParticleManager = new GPUParticleManager(GameManager.GraphicsDevice,
                                                        Content,
                                                        "effect_gpu_particle_velocity");
            GPUParticleManager.RegisterListeners();

            Engine = new Engine();
            InitSystems();
            InitDirectors();

            LoadContent();

            CreateEntities();

            base.OnInitialize();
        }
        protected override void OnKill()
        {
            PostProcessor.UnregisterEvents();
            Camera.UnregisterEvents();
            GPUParticleManager.UnregisterListeners();

            throw new Exception("This game state provides shared logic with all other game states and must not be killed.");
        }
 public ExplosionDirector(Engine engine, ContentManager content,
                          ProcessManager processManager,
                          ParticleManager <VelocityParticleInfo> cpuParticleManager,
                          GPUParticleManager gpuParticleManager)
     : base(engine, content, processManager)
 {
     _CPUParticleManager = cpuParticleManager;
     _gpuParticleManager = gpuParticleManager;
     _random             = new Random();
     _particleTexture    = content.Load <TextureAtlas>("complete_texture_atlas").GetRegion("texture_particle_velocity");
 }
    // Start is called before the first frame update
    void Start()
    {
        ReadDistributionFile(galaxyFolder + galaxyCPUFileSuffix);
        SetUpHSVStructures();

        cpu_particles_manager = GetComponent <CPUParticleManager>();
        if (cpu_particles_manager == null)
        {
            cpu_particles_manager = gameObject.AddComponent <CPUParticleManager>();
        }

        gpu_particles_manager = GetComponent <GPUParticleManager>();
        if (gpu_particles_manager == null)
        {
            gpu_particles_manager = gameObject.AddComponent <GPUParticleManager>();
        }
    }
    // メンバ関数
    #region private method
    // 初期化処理
    private void Initialize()
    {
        // パーティクルマネージャーを取得
        GPUParticleManager particle = GetComponent <GPUParticleManager>();

        // パーティクルマネージャーが見つかったか判定
        if (particle != null)
        {
            // パーティクルマネージャーの情報を取得する
            m_numParticles          = particle.GetParticleNum();
            m_particlesBuffer       = particle.GetParticleBuffer();
            m_activeParticlesBuffer = particle.GetActiveParticleBuffer();
            m_activeCountBuffer     = particle.GetParticleCountBuffer();
        }
        else
        {
            Debug.LogError("Particle Class Not Found!!" + typeof(GPUParticleManager).FullName);
        }

        // メッシュの頂点番号を取得
        int[] indices = _mesh.GetIndices(0);

        // 頂点データを取得
        VertexData[] vertexDatas = Enumerable.Range(0, _mesh.vertexCount).Select(b =>
        {
            return(new VertexData()
            {
                vertex = _mesh.vertices[b],
                normal = _mesh.normals[b],
                uv = _mesh.uv[b],
            });
        }).ToArray();

        // 頂点番号数を取得
        m_numMeshIndices = indices.Length;

        // バッファを生成
        m_meshVertexDatasBuffer = new ComputeBuffer(vertexDatas.Length, Marshal.SizeOf(typeof(VertexData)));
        m_meshIndicesBuffer     = new ComputeBuffer(indices.Length, Marshal.SizeOf(typeof(uint)));

        // バッファにデータを渡す
        m_meshVertexDatasBuffer.SetData(vertexDatas);
        m_meshIndicesBuffer.SetData(indices);
    }
        protected override void OnRender(float dt, float betweenFrameAlpha)
        {
            int enableFrameSmoothing = CVars.Get <bool>("graphics_frame_smoothing") ? 1 : 0;

            betweenFrameAlpha = betweenFrameAlpha * enableFrameSmoothing + (1 - enableFrameSmoothing);

            _fxaaPPE.Enabled = CVars.Get <bool>("graphics_fxaa");
            _smaaPPE.Enabled = CVars.Get <bool>("graphics_smaa");

            GameManager.GraphicsDevice.Clear(Color.Black);

            Camera camera = Camera;

#if DEBUG
            if (CVars.Get <bool>("debug_force_debug_camera"))
            {
                camera = DebugCamera;
            }
#endif

            PostProcessor.Begin();
            {
                RenderSystem.DrawEntities(Camera,
                                          Constants.Render.RENDER_GROUP_GAME_ENTITIES,
                                          dt,
                                          betweenFrameAlpha,
                                          camera);
                RenderSystem.SpriteBatch.Begin(SpriteSortMode.Deferred,
                                               null,
                                               null,
                                               null,
                                               null,
                                               null,
                                               camera.GetInterpolatedTransformMatrix(betweenFrameAlpha));
                if (!CVars.Get <bool>("particle_gpu_accelerated"))
                {
                    VelocityParticleManager.Draw(RenderSystem.SpriteBatch);
                }
                RenderSystem.SpriteBatch.End();
                if (CVars.Get <bool>("particle_gpu_accelerated"))
                {
                    GPUParticleManager.UpdateAndDraw(Camera, dt, betweenFrameAlpha, camera);
                }
            }
            // We have to defer drawing the post-processor results
            // because of unexpected behavior within MonoGame.
            RenderTarget2D postProcessingResult = PostProcessor.End(false);

            // Stars
            RenderSystem.DrawEntities(Camera,
                                      Constants.Render.RENDER_GROUP_STARS,
                                      dt,
                                      betweenFrameAlpha, camera);   // Stars
            RenderSystem.SpriteBatch.Begin();
            RenderSystem.SpriteBatch.Draw(postProcessingResult,
                                          postProcessingResult.Bounds,
                                          Color.White); // Post-processing results
            RenderSystem.SpriteBatch.End();
            // Shield Resource
            RenderSystem.DrawEntities(Camera,
                                      Constants.Render.RENDER_GROUP_NO_GLOW,
                                      dt,
                                      betweenFrameAlpha, camera);

#if DEBUG
            if (CVars.Get <bool>("debug_show_collision_shapes"))
            {
                CollisionDebugRenderSystem.Draw(camera.GetInterpolatedTransformMatrix(betweenFrameAlpha), dt);
            }
#endif
#if DEBUG
            if (CVars.Get <bool>("debug_show_render_culling"))
            {
                Camera debugCamera = CVars.Get <bool>("debug_force_debug_camera") ? DebugCamera : null;
                RenderCullingDebugRenderSystem.Draw(Camera, dt, debugCamera);
            }
#endif
#if DEBUG
            if (CVars.Get <bool>("debug_show_quad_trees"))
            {
                Camera debugCamera = CVars.Get <bool>("debug_force_debug_camera") ? DebugCamera : null;
                QuadTreeDebugRenderSystem.Draw(Camera, dt, debugCamera);
            }
#endif

            base.OnRender(dt, betweenFrameAlpha);
        }
    //int iteration = 0;

    // Start is called before the first frame update
    void Start()
    {
        manager = GetComponent <GPUParticleManager>();
    }