@@ -11,7 +11,6 @@ struct ParticleEffect
1111 u32 max_particles; // Max particles allowed in effect.
1212 u32 particles_allocated; // Actual allocated size.
1313 Particle* particles; // Actually, num_particles in size
14- void * real_ptr; // Base, possible not aligned pointer
1514 OnBirthParticleCB b_cb;
1615 OnDeadParticleCB d_cb;
1716 void * owner;
@@ -27,15 +26,11 @@ struct ParticleEffect
2726 max_particles = mp;
2827 particles_allocated = max_particles;
2928
30- real_ptr = xr_malloc (sizeof (Particle) * (max_particles + 1 ));
31-
32- particles = (Particle*)((uintptr_t )real_ptr + (64 - ((uintptr_t )real_ptr & 63 )));
33- // particles = static_cast<Particle*>(real_ptr);
34-
29+ particles = xr_alloc<Particle>(max_particles);
3530 // Msg("Allocated %u bytes (%u particles) with base address 0x%p", max_particles * sizeof(Particle), max_particles, particles);
3631 }
3732
38- ~ParticleEffect () { xr_free (real_ptr ); }
33+ ~ParticleEffect () { xr_free (particles ); }
3934
4035 int Resize (u32 max_count)
4136 {
@@ -52,23 +47,20 @@ struct ParticleEffect
5247 }
5348
5449 // Allocate particles.
55- void * new_real_ptr = xr_malloc (sizeof (Particle) * (max_count + 1 ));
56-
57- if (new_real_ptr == nullptr )
50+ Particle* new_particles = xr_alloc<Particle>(max_count);
51+ if (!new_particles)
5852 {
5953 // ERROR - Not enough memory. Just give all we've got.
6054 max_particles = particles_allocated;
6155 return max_particles;
6256 }
6357
64- Particle* new_particles = (Particle*)((uintptr_t )new_real_ptr + (64 - ((uintptr_t )new_real_ptr & 63 )));
65- Msg (" Re-allocated %u bytes (%u particles) with base address 0x%p" , max_count * sizeof (Particle), max_count, new_particles);
58+ // Msg("Re-allocated %u bytes (%u particles) with base address 0x%p", max_count * sizeof(Particle), max_count, new_particles);
6659
6760 CopyMemory (new_particles, particles, p_count * sizeof (Particle));
68- xr_free (real_ptr );
61+ xr_free (particles );
6962
7063 particles = new_particles;
71- real_ptr = new_real_ptr;
7264
7365 max_particles = max_count;
7466 particles_allocated = max_count;
0 commit comments