@@ -11,7 +11,6 @@ struct ParticleEffect
11
11
u32 max_particles; // Max particles allowed in effect.
12
12
u32 particles_allocated; // Actual allocated size.
13
13
Particle* particles; // Actually, num_particles in size
14
- void * real_ptr; // Base, possible not aligned pointer
15
14
OnBirthParticleCB b_cb;
16
15
OnDeadParticleCB d_cb;
17
16
void * owner;
@@ -27,15 +26,11 @@ struct ParticleEffect
27
26
max_particles = mp;
28
27
particles_allocated = max_particles;
29
28
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);
35
30
// Msg("Allocated %u bytes (%u particles) with base address 0x%p", max_particles * sizeof(Particle), max_particles, particles);
36
31
}
37
32
38
- ~ParticleEffect () { xr_free (real_ptr ); }
33
+ ~ParticleEffect () { xr_free (particles ); }
39
34
40
35
int Resize (u32 max_count)
41
36
{
@@ -52,23 +47,20 @@ struct ParticleEffect
52
47
}
53
48
54
49
// 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)
58
52
{
59
53
// ERROR - Not enough memory. Just give all we've got.
60
54
max_particles = particles_allocated;
61
55
return max_particles;
62
56
}
63
57
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);
66
59
67
60
CopyMemory (new_particles, particles, p_count * sizeof (Particle));
68
- xr_free (real_ptr );
61
+ xr_free (particles );
69
62
70
63
particles = new_particles;
71
- real_ptr = new_real_ptr;
72
64
73
65
max_particles = max_count;
74
66
particles_allocated = max_count;
0 commit comments