3
3
using System . Drawing ;
4
4
using System . Numerics ;
5
5
using JetBrains . Annotations ;
6
+ using Robust . Shared . GameObjects ;
6
7
using Robust . Shared . Map ;
7
8
using Robust . Shared . Timing ;
8
9
@@ -15,19 +16,24 @@ namespace Robust.Client.Graphics
15
16
[ PublicAPI ]
16
17
public sealed class ParticlesManager
17
18
{
18
- private List < ParticleSystem > _particleSystems = new ( ) ;
19
+ private Dictionary < EntityUid , ParticleSystem > _particleSystems = new ( ) ;
19
20
public void FrameUpdate ( FrameEventArgs args )
20
21
{
21
- foreach ( var particleSys in _particleSystems )
22
+ foreach ( var particleSys in _particleSystems . Values )
22
23
{
23
24
particleSys . FrameUpdate ( args ) ;
24
25
}
25
26
}
26
27
27
- public ParticleSystem CreateParticleSystem ( ParticleSystemArgs args )
28
+ public void Render ( EntityUid uid , ParticlesComponent particlesComponent , DrawingHandleWorld drawingHandle , Robust . Shared . Maths . Angle eyeRotation , in Robust . Shared . Maths . Angle worldRotation , in Vector2 worldPosition )
29
+ {
30
+
31
+ }
32
+
33
+ public ParticleSystem CreateParticleSystem ( EntityUid entity , ParticleSystemArgs args )
28
34
{
29
35
var newSystem = new ParticleSystem ( args ) ;
30
- _particleSystems . Add ( newSystem ) ;
36
+ _particleSystems . Add ( entity , newSystem ) ;
31
37
return newSystem ;
32
38
}
33
39
@@ -115,7 +121,7 @@ public ParticleSystem(ParticleSystemArgs args)
115
121
_particleSystemSize = args . ParticleSystemSize ;
116
122
_particleCount = args . ParticleCount ;
117
123
_particlesPerSecond = args . ParticlesPerSecond ;
118
- _lowerBound = args . LowerDrawBound is null ? new Vector3 ( _particleSystemSize , float . MinValue ) : args . LowerDrawBound . Value ;
124
+ _lowerBound = args . LowerDrawBound is null ? new Vector3 ( - _particleSystemSize , float . MinValue ) : args . LowerDrawBound . Value ;
119
125
_upperBound = args . UpperDrawBound is null ? new Vector3 ( _particleSystemSize , float . MaxValue ) : args . UpperDrawBound . Value ;
120
126
_icon = args . Icon ;
121
127
_baseTransform = args . BaseTransform is null ? Matrix3x2 . Identity : args . BaseTransform . Value ;
@@ -129,6 +135,8 @@ public ParticleSystem(ParticleSystemArgs args)
129
135
_acceleration = args . Acceleration is null ? ( float lifetime ) => Vector3 . Zero : args . Acceleration ;
130
136
131
137
_particles = new Particle [ _particleCount ] ;
138
+ for ( int i = 0 ; i < _particleCount ; i ++ )
139
+ _particles [ i ] = new ( ) ;
132
140
}
133
141
134
142
public void FrameUpdate ( FrameEventArgs args )
@@ -144,12 +152,13 @@ public void FrameUpdate(FrameEventArgs args)
144
152
p . position += p . velocity * args . DeltaSeconds ;
145
153
if ( p . fadein > p . lifetime )
146
154
p . color = Color . FromArgb ( ( int ) Math . Clamp ( p . lifetime / p . fadein * 255 , 0 , 255 ) , p . color ) ;
147
- if ( p . fadeout < p . lifespan - p . lifetime )
155
+ if ( p . fadeout > p . lifespan - p . lifetime )
148
156
p . color = Color . FromArgb ( ( int ) Math . Clamp ( ( p . lifespan - p . lifetime ) / p . fadeout * 255 , 0 , 255 ) , p . color ) ;
149
157
150
158
if ( p . lifetime > p . lifespan || p . position . X > _upperBound . X || p . position . Y > _upperBound . Y || p . position . Z > _upperBound . Z || p . position . X < _lowerBound . X || p . position . Y < _lowerBound . Y || p . position . Z < _lowerBound . Z )
151
159
p . active = false ;
152
- } else if ( particlesSpawned < _particlesPerSecond ) {
160
+ }
161
+ if ( ! p . active && particlesSpawned < _particlesPerSecond * args . DeltaSeconds ) {
153
162
p . lifetime = 0 ;
154
163
p . texture = _icon ( ) ;
155
164
p . position = _spawnPosition ( ) ;
@@ -160,27 +169,24 @@ public void FrameUpdate(FrameEventArgs args)
160
169
p . fadein = _fadein ( ) ;
161
170
p . fadeout = _fadeout ( ) ;
162
171
p . active = true ;
172
+ particlesSpawned ++ ;
163
173
}
164
174
}
165
175
}
166
176
167
- public void Draw ( in OverlayDrawArgs args ) {
168
- if ( args . MapId == MapId . Nullspace )
169
- return ;
170
-
171
- var handle = args . WorldHandle ;
177
+ public void Draw ( DrawingHandleWorld handle ) {
172
178
foreach ( var particle in _particles )
173
179
{
174
180
if ( particle . active ) {
175
181
handle . SetTransform ( particle . transform ) ;
176
- handle . DrawTexture ( particle . texture , new Vector2 ( particle . position . X , particle . position . Y ) , particle . color ) ;
182
+ handle . DrawTexture ( particle . texture ! , new Vector2 ( particle . position . X , particle . position . Y ) , particle . color ) ;
177
183
}
178
184
}
179
185
}
180
186
}
181
187
182
- internal struct Particle {
183
- public Texture texture ;
188
+ internal sealed class Particle {
189
+ public Texture ? texture ;
184
190
public Vector3 position ;
185
191
public Vector3 velocity ;
186
192
public Matrix3x2 transform ;
0 commit comments