Skip to content

Commit

Permalink
okay, particles are being rendered in opendream
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Feb 5, 2025
1 parent 9eea9ee commit eabf039
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

namespace Robust.Shared.GameObjects;

Expand Down
13 changes: 10 additions & 3 deletions Robust.Client/GameObjects/EntitySystems/ClientParticlesSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ public sealed class ClientParticlesSystem : SharedParticlesSystem

public override void Initialize() {
base.Initialize();
SubscribeLocalEvent<ParticlesComponent, ComponentGetState>(OnParticlesComponentGetState);
//SubscribeLocalEvent<ParticlesComponent, ComponentGetState>(OnParticlesComponentGetState);
SubscribeLocalEvent<ParticlesComponent, ComponentAdd>(HandleComponentAdd);
SubscribeLocalEvent<ParticlesComponent, ComponentRemove>(HandleComponentRemove);
}


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

component.particlesSystem = _particlesManager.CreateParticleSystem(particleSystemArgs);
component.particlesSystem = _particlesManager.CreateParticleSystem(uid, particleSystemArgs);

}

private void HandleComponentRemove(EntityUid uid, ParticlesComponent component, ref ComponentRemove args)
{
}
}
}
36 changes: 21 additions & 15 deletions Robust.Client/Graphics/Particles/ParticlesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.Numerics;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Timing;

Expand All @@ -15,19 +16,24 @@ namespace Robust.Client.Graphics
[PublicAPI]
public sealed class ParticlesManager
{
private List<ParticleSystem> _particleSystems = new();
private Dictionary<EntityUid,ParticleSystem> _particleSystems = new();
public void FrameUpdate(FrameEventArgs args)
{
foreach (var particleSys in _particleSystems)
foreach (var particleSys in _particleSystems.Values)
{
particleSys.FrameUpdate(args);
}
}

public ParticleSystem CreateParticleSystem(ParticleSystemArgs args)
public void Render(EntityUid uid, ParticlesComponent particlesComponent, DrawingHandleWorld drawingHandle, Robust.Shared.Maths.Angle eyeRotation, in Robust.Shared.Maths.Angle worldRotation, in Vector2 worldPosition)
{

}

public ParticleSystem CreateParticleSystem(EntityUid entity, ParticleSystemArgs args)
{
var newSystem = new ParticleSystem(args);
_particleSystems.Add(newSystem);
_particleSystems.Add(entity, newSystem);
return newSystem;
}

Expand Down Expand Up @@ -115,7 +121,7 @@ public ParticleSystem(ParticleSystemArgs args)
_particleSystemSize = args.ParticleSystemSize;
_particleCount = args.ParticleCount;
_particlesPerSecond = args.ParticlesPerSecond;
_lowerBound = args.LowerDrawBound is null ? new Vector3(_particleSystemSize, float.MinValue) : args.LowerDrawBound.Value;
_lowerBound = args.LowerDrawBound is null ? new Vector3(-_particleSystemSize, float.MinValue) : args.LowerDrawBound.Value;
_upperBound = args.UpperDrawBound is null ? new Vector3(_particleSystemSize, float.MaxValue) : args.UpperDrawBound.Value;
_icon = args.Icon;
_baseTransform = args.BaseTransform is null ? Matrix3x2.Identity : args.BaseTransform.Value;
Expand All @@ -129,6 +135,8 @@ public ParticleSystem(ParticleSystemArgs args)
_acceleration = args.Acceleration is null ? (float lifetime) => Vector3.Zero : args.Acceleration;

_particles = new Particle[_particleCount];
for(int i=0; i<_particleCount; i++)
_particles[i] = new();
}

public void FrameUpdate(FrameEventArgs args)
Expand All @@ -144,12 +152,13 @@ public void FrameUpdate(FrameEventArgs args)
p.position += p.velocity*args.DeltaSeconds;
if(p.fadein > p.lifetime)
p.color = Color.FromArgb((int)Math.Clamp(p.lifetime/p.fadein * 255, 0, 255), p.color);
if(p.fadeout < p.lifespan-p.lifetime)
if(p.fadeout > p.lifespan-p.lifetime)
p.color = Color.FromArgb((int)Math.Clamp((p.lifespan-p.lifetime)/p.fadeout* 255, 0, 255), p.color);

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)
p.active = false;
} else if (particlesSpawned < _particlesPerSecond) {
}
if (!p.active && particlesSpawned < _particlesPerSecond*args.DeltaSeconds) {
p.lifetime = 0;
p.texture = _icon();
p.position = _spawnPosition();
Expand All @@ -160,27 +169,24 @@ public void FrameUpdate(FrameEventArgs args)
p.fadein = _fadein();
p.fadeout = _fadeout();
p.active = true;
particlesSpawned++;
}
}
}

public void Draw(in OverlayDrawArgs args){
if (args.MapId == MapId.Nullspace)
return;

var handle = args.WorldHandle;
public void Draw(DrawingHandleWorld handle){
foreach (var particle in _particles)
{
if(particle.active){
handle.SetTransform(particle.transform);
handle.DrawTexture(particle.texture, new Vector2(particle.position.X, particle.position.Y), particle.color);
handle.DrawTexture(particle.texture!, new Vector2(particle.position.X, particle.position.Y), particle.color);
}
}
}
}

internal struct Particle {
public Texture texture;
internal sealed class Particle {
public Texture? texture;
public Vector3 position;
public Vector3 velocity;
public Matrix3x2 transform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

namespace Robust.Shared.GameObjects;

public abstract class SharedParticlesSystem : EntitySystem {
}
public abstract class SharedParticlesSystem : EntitySystem {}

0 comments on commit eabf039

Please sign in to comment.