<commit_before>from enum import Enum
import copy
import time
import math
import ctypes

import numpy as np
from OpenGL.GL import *
from OpenGL.GLU import *

from PyEngine3D.Common import logger
from PyEngine3D.OpenGLContext import DispatchIndirectCommand, DispatchIndirectBuffer
from PyEngine3D.OpenGLContext import DrawElementsIndirectCommand, DrawElementIndirectBuffer
from PyEngine3D.OpenGLContext import ShaderStorageBuffer, InstanceBuffer, UniformBlock
from PyEngine3D.Utilities import *
from PyEngine3D.Common.Constants import *
from PyEngine3D.Common import logger, log_level, COMMAND
from PyEngine3D.App import CoreManager
from . import Model, BlendMode
from .RenderTarget import RenderTargets


class SpawnVolume(Enum):
    BOX = 0
    SPHERE = 1
    CONE = 2
    CYLINDER = 3


class VelocityType(Enum):
    RANDOM = 0
    SPAWN_DIRECTION = 1
    HURRICANE = 2


class AlignMode(Enum):
    NONE = 0
    BILLBOARD = 1
    VELOCITY_ALIGN = 2


class EffectManager(Singleton):
    def __init__(self):
        self.renderer = None
        self.effects = []
        self.active_effects = []
        self.render_effects = []
        self.resource_manager = None
        self.particle_instance_buffer = None
        self.alive_particle_count = 0
        self.test = 0

        self.material_gpu_particle_initialize = None
        self.material_gpu_particle_dispatch_indircet = None
        self.material_gpu_particle_spawn = None
        self.material_gpu_particle_update = None
        self.material_gpu_particle_draw_indirect = None
        self.material_gpu_particle_render = None

    def initialize(self, core_manager):
        self.renderer = core_manager.renderer
        self.resource_manager = core_manager.resource_manager

        self.particle_instance_buffer = InstanceBuffer(name="instance_buffer",
                                                       location_offset=5,
                                                       element_datas=[MATRIX4_IDENTITY,
                                                                      FLOAT4_ZERO,
                                                                      FLOAT4_ZERO])

        self.material_gpu_particle_initialize = self.resource_manager.get_material_instance('effect.gpu_particle_initialize')
        self.material_gpu_particle_dispatch_indircet = self.resource_manager.get_material_instance('effect.gpu_particle_dispatch_indirect')
        self.material_gpu_particle_spawn = self.resource_manager.get_material_instance('effect.gpu_particle_spawn')
        self.material_gpu_particle_update = self.resource_manager.get_material_instance('effect.gpu_particle_update')
        self.material_gpu_particle_draw_indirect = self.resource_manager.get_material_instance('effect.gpu_particle_draw_indirect')
        self.material_gpu_particle_render = self.resource_manager.get_material_instance('effect.gpu_particle_render')

    def get_save_data(self):
        return [effect.get_save_data() for effect in self.effects]

    def clear(self):
        for effect in self.effects:
            effect.destroy()

        self.effects = []
        self.active_effects = []

    def add_effect(self, effect):
        self.effects.append(effect)
        self.play_effect(effect)
        return effect

    def delete_effect(self, effect):
        self.destroy_effect(effect)
        self.effects.remove(effect)

    def play_effect(self, effect):
        if effect not in self.active_effects:
            self.active_effects.append(effect)
        effect.play()

    def destroy_effect(self, effect):
        if effect in self.active_effects:
            self.active_effects.remove(effect)
        effect.destroy()

    def notify_effect_info_changed(self, effect_info):
        for effect in self.effects:
            if effect_info == effect.effect_info:
                self.play_effect(effect)

    def notify_particle_info_changed(self, particle_info_name):
        for effect in self.effects:
            for emitter in effect.emitters:
                if particle_info_name == emitter.particle_info.name:
                    self.play_effect(effect)

    def render(self):
        prev_blend_mode = None
        main_camera = CoreManager.instance().scene_manager.main_camera
        cameara_position = main_camera.transform.get_pos()

        for effect in self.render_effects:
            for emitter in effect.emitters:
                particle_info = emitter.particle_info
                if not particle_info.enable or not emitter.alive:
                    continue

                # set blend mode
                if prev_blend_mode != particle_info.blend_mode:
                    if particle_info.blend_mode is BlendMode.BLEND:
                        glBlendEquation(GL_FUNC_ADD)
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
                    elif particle_info.blend_mode is BlendMode.ADDITIVE:
                        glBlendEquation(GL_FUNC_ADD)
                        glBlendFunc(GL_ONE, GL_ONE)
                    elif particle_info.blend_mode is BlendMode.MULTIPLY:
                        glBlendEquation(GL_FUNC_ADD)
                        glBlendFunc(GL_DST_COLOR, GL_ZERO)
                    elif particle_info.blend_mode is BlendMode.MULTIPLY:
                        glBlendEquation(GL_FUNC_SUBTRACT)
                        glBlendFunc(GL_ONE, GL_ONE)
                    prev_blend_mode = particle_info.blend_mode

                geometry = particle_info.mesh.get_geometry()

                # common<commit_msg>bug fixed<commit_after>from enum import Enum
import copy
import time
import math
import ctypes

import numpy as np
from OpenGL.GL import *
from OpenGL.GLU import *

from PyEngine3D.Common import logger
from PyEngine3D.OpenGLContext import DispatchIndirectCommand, DispatchIndirectBuffer
from PyEngine3D.OpenGLContext import DrawElementsIndirectCommand, DrawElementIndirectBuffer
from PyEngine3D.OpenGLContext import ShaderStorageBuffer, InstanceBuffer, UniformBlock
from PyEngine3D.Utilities import *
from PyEngine3D.Common.Constants import *
from PyEngine3D.Common import logger, log_level, COMMAND
from PyEngine3D.App import CoreManager
from . import Model, BlendMode
from .RenderTarget import RenderTargets


class SpawnVolume(Enum):
    BOX = 0
    SPHERE = 1
    CONE = 2
    CYLINDER = 3


class VelocityType(Enum):
    RANDOM = 0
    SPAWN_DIRECTION = 1
    HURRICANE = 2


class AlignMode(Enum):
    NONE = 0
    BILLBOARD = 1
    VELOCITY_ALIGN = 2


class EffectManager(Singleton):
    def __init__(self):
        self.renderer = None
        self.effects = []
        self.active_effects = []
        self.render_effects = []
        self.resource_manager = None
        self.particle_instance_buffer = None
        self.alive_particle_count = 0
        self.test = 0

        self.material_gpu_particle_initialize = None
        self.material_gpu_particle_dispatch_indircet = None
        self.material_gpu_particle_spawn = None
        self.material_gpu_particle_update = None
        self.material_gpu_particle_draw_indirect = None
        self.material_gpu_particle_render = None

    def initialize(self, core_manager):
        self.renderer = core_manager.renderer
        self.resource_manager = core_manager.resource_manager

        self.particle_instance_buffer = InstanceBuffer(name="instance_buffer",
                                                       location_offset=5,
                                                       element_datas=[MATRIX4_IDENTITY,
                                                                      FLOAT4_ZERO,
                                                                      FLOAT4_ZERO])

        self.material_gpu_particle_initialize = self.resource_manager.get_material_instance('effect.gpu_particle_initialize')
        self.material_gpu_particle_dispatch_indircet = self.resource_manager.get_material_instance('effect.gpu_particle_dispatch_indirect')
        self.material_gpu_particle_spawn = self.resource_manager.get_material_instance('effect.gpu_particle_spawn')
        self.material_gpu_particle_update = self.resource_manager.get_material_instance('effect.gpu_particle_update')
        self.material_gpu_particle_draw_indirect = self.resource_manager.get_material_instance('effect.gpu_particle_draw_indirect')
        self.material_gpu_particle_render = self.resource_manager.get_material_instance('effect.gpu_particle_render')

    def get_save_data(self):
        return [effect.get_save_data() for effect in self.effects]

    def clear(self):
        for effect in self.effects:
            effect.destroy()

        self.effects = []
        self.active_effects = []

    def add_effect(self, effect):
        self.effects.append(effect)
        self.play_effect(effect)
        return effect

    def delete_effect(self, effect):
        self.destroy_effect(effect)
        self.effects.remove(effect)

    def play_effect(self, effect):
        if effect not in self.active_effects:
            self.active_effects.append(effect)
        effect.play()

    def destroy_effect(self, effect):
        if effect in self.active_effects:
            self.active_effects.remove(effect)
        effect.destroy()

    def notify_effect_info_changed(self, effect_info):
        for effect in self.effects:
            if effect_info == effect.effect_info:
                self.play_effect(effect)

    def notify_particle_info_changed(self, particle_info_name):
        for effect in self.effects:
            for emitter in effect.emitters:
                if particle_info_name == emitter.particle_info.name:
                    self.play_effect(effect)

    def render(self):
        prev_blend_mode = None
        main_camera = CoreManager.instance().scene_manager.main_camera
        cameara_position = main_camera.transform.get_pos()

        for effect in self.render_effects:
            for emitter in effect.emitters:
                particle_info = emitter.particle_info
                if not particle_info.enable or not emitter.alive:
                    continue

                # set blend mode
                if prev_blend_mode != particle_info.blend_mode:
                    if particle_info.blend_mode is BlendMode.BLEND:
                        glBlendEquation(GL_FUNC_ADD)
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
                    elif particle_info.blend_mode is BlendMode.ADDITIVE:
                        glBlendEquation(GL_FUNC_ADD)
                        glBlendFunc(GL_ONE, GL_ONE)
                    elif particle_info.blend_mode is BlendMode.MULTIPLY:
                        glBlendEquation(GL_FUNC_ADD)
                        glBlendFunc(GL_DST_COLOR, GL_ZERO)
                    elif particle_info.blend_mode is BlendMode.SUBTRACT:
                        glBlendEquation(GL_FUNC_SUBTRACT)
                        glBlendFunc(GL_ONE, GL_ONE)
                    prev_blend_mode = particle_info.blend_mode

                geometry = particle_info.mesh.get_geometry()

                # common
{'fraction_non_alphanumeric': 0.06062793215445687, 'fraction_numerical': 0.004330566582461205, 'mean_word_length': 2.306980906921241, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1850366', 'n_tokens_mistral': 3173, 'n_tokens_neox': 2955, 'n_words': 568}