Skip to content

Commit eabf039

Browse files
committed
okay, particles are being rendered in opendream
1 parent 9eea9ee commit eabf039

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

Robust.Client/GameObjects/Components/Renderable/ParticlesComponent.cs

-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
4-
using Robust.Client.GameObjects;
51
using Robust.Client.Graphics;
6-
using Robust.Shared.GameStates;
7-
using Robust.Shared.Serialization.Manager.Attributes;
8-
using Robust.Shared.ViewVariables;
92

103
namespace Robust.Shared.GameObjects;
114

Robust.Client/GameObjects/EntitySystems/ClientParticlesSystem.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public sealed class ClientParticlesSystem : SharedParticlesSystem
1919

2020
public override void Initialize() {
2121
base.Initialize();
22-
SubscribeLocalEvent<ParticlesComponent, ComponentGetState>(OnParticlesComponentGetState);
22+
//SubscribeLocalEvent<ParticlesComponent, ComponentGetState>(OnParticlesComponentGetState);
23+
SubscribeLocalEvent<ParticlesComponent, ComponentAdd>(HandleComponentAdd);
24+
SubscribeLocalEvent<ParticlesComponent, ComponentRemove>(HandleComponentRemove);
2325
}
2426

2527

26-
private void OnParticlesComponentGetState(EntityUid uid, ParticlesComponent component, ref ComponentGetState args)
28+
private void HandleComponentAdd(EntityUid uid, ParticlesComponent component, ref ComponentAdd args)
2729
{
2830
//do a lookup for some yaml thing or some such based on particle type
2931
ParticleSystemArgs particleSystemArgs = new(
@@ -35,9 +37,14 @@ private void OnParticlesComponentGetState(EntityUid uid, ParticlesComponent comp
3537
particleSystemArgs.Acceleration = (float lifetime) => new Vector3(lifetime);
3638
particleSystemArgs.SpawnPosition = () => new Vector3(new Random().NextFloat()*200, 0, 0);
3739
particleSystemArgs.Color = (float lifetime) => Color.Red;
40+
particleSystemArgs.ParticleCount=1000;
3841

39-
component.particlesSystem = _particlesManager.CreateParticleSystem(particleSystemArgs);
42+
component.particlesSystem = _particlesManager.CreateParticleSystem(uid, particleSystemArgs);
4043

4144
}
45+
46+
private void HandleComponentRemove(EntityUid uid, ParticlesComponent component, ref ComponentRemove args)
47+
{
48+
}
4249
}
4350
}

Robust.Client/Graphics/Particles/ParticlesManager.cs

+21-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.Numerics;
55
using JetBrains.Annotations;
6+
using Robust.Shared.GameObjects;
67
using Robust.Shared.Map;
78
using Robust.Shared.Timing;
89

@@ -15,19 +16,24 @@ namespace Robust.Client.Graphics
1516
[PublicAPI]
1617
public sealed class ParticlesManager
1718
{
18-
private List<ParticleSystem> _particleSystems = new();
19+
private Dictionary<EntityUid,ParticleSystem> _particleSystems = new();
1920
public void FrameUpdate(FrameEventArgs args)
2021
{
21-
foreach (var particleSys in _particleSystems)
22+
foreach (var particleSys in _particleSystems.Values)
2223
{
2324
particleSys.FrameUpdate(args);
2425
}
2526
}
2627

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)
2834
{
2935
var newSystem = new ParticleSystem(args);
30-
_particleSystems.Add(newSystem);
36+
_particleSystems.Add(entity, newSystem);
3137
return newSystem;
3238
}
3339

@@ -115,7 +121,7 @@ public ParticleSystem(ParticleSystemArgs args)
115121
_particleSystemSize = args.ParticleSystemSize;
116122
_particleCount = args.ParticleCount;
117123
_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;
119125
_upperBound = args.UpperDrawBound is null ? new Vector3(_particleSystemSize, float.MaxValue) : args.UpperDrawBound.Value;
120126
_icon = args.Icon;
121127
_baseTransform = args.BaseTransform is null ? Matrix3x2.Identity : args.BaseTransform.Value;
@@ -129,6 +135,8 @@ public ParticleSystem(ParticleSystemArgs args)
129135
_acceleration = args.Acceleration is null ? (float lifetime) => Vector3.Zero : args.Acceleration;
130136

131137
_particles = new Particle[_particleCount];
138+
for(int i=0; i<_particleCount; i++)
139+
_particles[i] = new();
132140
}
133141

134142
public void FrameUpdate(FrameEventArgs args)
@@ -144,12 +152,13 @@ public void FrameUpdate(FrameEventArgs args)
144152
p.position += p.velocity*args.DeltaSeconds;
145153
if(p.fadein > p.lifetime)
146154
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)
148156
p.color = Color.FromArgb((int)Math.Clamp((p.lifespan-p.lifetime)/p.fadeout* 255, 0, 255), p.color);
149157

150158
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)
151159
p.active = false;
152-
} else if (particlesSpawned < _particlesPerSecond) {
160+
}
161+
if (!p.active && particlesSpawned < _particlesPerSecond*args.DeltaSeconds) {
153162
p.lifetime = 0;
154163
p.texture = _icon();
155164
p.position = _spawnPosition();
@@ -160,27 +169,24 @@ public void FrameUpdate(FrameEventArgs args)
160169
p.fadein = _fadein();
161170
p.fadeout = _fadeout();
162171
p.active = true;
172+
particlesSpawned++;
163173
}
164174
}
165175
}
166176

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){
172178
foreach (var particle in _particles)
173179
{
174180
if(particle.active){
175181
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);
177183
}
178184
}
179185
}
180186
}
181187

182-
internal struct Particle {
183-
public Texture texture;
188+
internal sealed class Particle {
189+
public Texture? texture;
184190
public Vector3 position;
185191
public Vector3 velocity;
186192
public Matrix3x2 transform;

Robust.Shared/GameObjects/Systems/ParticlesComponentSystem.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33

44
namespace Robust.Shared.GameObjects;
55

6-
public abstract class SharedParticlesSystem : EntitySystem {
7-
}
6+
public abstract class SharedParticlesSystem : EntitySystem {}

0 commit comments

Comments
 (0)