Skip to content

Commit

Permalink
fixed particle renderer, minor improvements in update loops for parti…
Browse files Browse the repository at this point in the history
…cles
  • Loading branch information
Kovak committed Feb 8, 2014
1 parent bbe07e2 commit ed48fa8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions kivent_cython/kivent_cython/cmesh.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ cdef class CMesh(VertexInstruction):
cdef long vcount = self.vcount
cdef vsize = self.batch.vbo.vertex_format.vsize
cdef long icount = self.icount
print 'start update', vcount, vsize, icount
self.batch.set_data(vertices, <int>(vcount / vsize), indices, <int>icount)
print 'end update'


property mode:
'''VBO Mode used for drawing vertices/indices. Can be one of 'points',
Expand Down
7 changes: 1 addition & 6 deletions kivent_cython/kivent_cython/particle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ cdef class keParticleManager:
cdef unsigned short * indice_info
particles = <keParticle *>self.particles_ptr
frame_info = <float *>self.frame_info_ptr
print '1'
if frame_info != NULL:
free(frame_info)
frame_info = NULL
Expand All @@ -147,19 +146,17 @@ cdef class keParticleManager:
self.frame_info_ptr = frame_ptr = <void *>malloc(sizeof(float) *
number_of_particles * 4 * 12)
self.v_count = <long>number_of_particles * 4 * 12
indices_ptr = <void *>malloc(
self.indice_info_ptr = indices_ptr = <void *>malloc(
sizeof(unsigned short) * number_of_particles * 6)
self.i_count = <long>number_of_particles * 6
if not frame_ptr or not indices_ptr:
raise MemoryError()
print '2'
indice_info = <unsigned short *>indices_ptr
frame_info = <float *>frame_ptr
self.last_frame_count = number_of_particles
cdef unsigned short offset
cdef int indice_offset
cdef int index
print '3'
for i in range(number_of_particles):
offset = 4 * i
indice_offset = i*6
Expand Down Expand Up @@ -239,7 +236,6 @@ cdef class keParticleManager:
scale = render_info.scale/w
x0, y0 = tex_info.u0, tex_info.v0
x1, y1 = tex_info.u1, tex_info.v1
print '4'
frame_info[index] = -w
frame_info[index+1] = -h
frame_info[index+2] = x0
Expand Down Expand Up @@ -289,7 +285,6 @@ cdef class keParticleManager:
frame_info[index+46] = color.a
frame_info[index+47] = scale
particles[i] = particle
print '5'
if particle.current_time >= particle.total_time:
self._expire_particle(particle.particle_id)

Expand Down
9 changes: 6 additions & 3 deletions kivent_cython/kivent_cython/particlemanager.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ class ParticleManager(GameSystem):
particle_configs = pm.particle_configs
unused_particle_effects = self.unused_particle_effects
up = unused_particle_effects.pop
get_emitter = pm.get_emitter
add_emitter = pm.add_emitter
load_particle_system_with_emitter = pm.load_particle_system_with_emitter
for particle_effect in entity_component_dict:
config = entity_component_dict[particle_effect]['particle_file']
if not config in particle_configs:
pm.load_particle_config(config)
if len(unused_particle_effects) > 0:
emitter = up()
else:
emitter = pm.get_emitter()
pm.add_emitter(emitter)
emitter = get_emitter()
add_emitter(emitter)
entity_component_dict[particle_effect]['particle_system'] = (
particle_system) = pm.load_particle_system_with_emitter(
particle_system) = load_particle_system_with_emitter(
emitter, config)
entity_component_dict[
particle_effect]['particle_system_on'] = False
Expand Down
6 changes: 4 additions & 2 deletions kivent_cython/kivent_cython/renderers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ class DynamicRenderer(Renderer):
cdef dict entity
cdef dict system_data
cdef list to_render = []
tr_a = to_render.append
tr_r = to_render.remove
for entity_id in entity_ids:
entity = entities[entity_id]
if system_id not in entity:
Expand All @@ -349,9 +351,9 @@ class DynamicRenderer(Renderer):
if system_data['on_screen'] and not entity_id in on_screen:
system_data['on_screen'] = False
if entity_id in on_screen:
to_render.append(entity_id)
tr_a(entity_id)
if system_data['on_screen'] and not system_data['render']:
to_render.remove(entity_id)
tr_r(entity_id)
return to_render


Expand Down

0 comments on commit ed48fa8

Please sign in to comment.