Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions OpenDreamClient/Rendering/ClientDreamParticlesSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ private void HandleComponentRemove(EntityUid uid, DreamParticlesComponent compon
_particlesManager.DestroyParticleSystem(uid);
}

private ParticleSystemArgs GetParticleSystemArgs(DreamParticlesComponent component) {
private ParticleSystemArgs GetParticleSystemArgs(DreamParticlesComponent comp) {
DreamParticlesComponent.ParticleData data = comp.Data;
Func<Texture?> textureFunc;
if (component.TextureList.Length == 0)
if (data.TextureList.Length == 0)
textureFunc = () => Texture.White;
else {
List<DreamIcon> icons = new(component.TextureList.Length);
foreach (var appearance in component.TextureList) {
List<DreamIcon> icons = new(data.TextureList.Length);
foreach (var appearance in data.TextureList) {
DreamIcon icon = new(_renderTargetPool, _dreamInterfaceManager, _gameTiming, _clyde, _appearanceSystem);
icon.SetAppearance(appearance.MustGetId());
icons.Add(icon);
Expand All @@ -57,30 +58,30 @@ private ParticleSystemArgs GetParticleSystemArgs(DreamParticlesComponent compone
}

var perTick = (1f / 10f); // "Tick" refers to a BYOND standard tick of 0.1s. --DM Reference
var result = new ParticleSystemArgs(textureFunc, new Vector2i(component.Width, component.Height), (uint)component.Count, component.Spawning / perTick) {
Lifespan = () => (component.Lifespan?.Generate(_random) ?? 1f) * perTick,
Fadein = () => (component.FadeIn?.Generate(_random) ?? 0f) * perTick,
Fadeout = () => (component.FadeOut?.Generate(_random) ?? 0f) * perTick,
Color = component.Gradient.Length > 0
var result = new ParticleSystemArgs(textureFunc, new Vector2i(data.Width, data.Height), (uint)data.Count, data.Spawning / perTick) {
Lifespan = () => (data.Lifespan?.Generate(_random) ?? 1f) * perTick,
Fadein = () => (data.FadeIn?.Generate(_random) ?? 0f) * perTick,
Fadeout = () => (data.FadeOut?.Generate(_random) ?? 0f) * perTick,
Color = data.Gradient.Length > 0
? lifetime => {
var colorIndex = (int)(lifetime * component.Gradient.Length);
colorIndex = Math.Clamp(colorIndex, 0, component.Gradient.Length - 1);
return component.Gradient[colorIndex];
var colorIndex = (int)(lifetime * data.Gradient.Length);
colorIndex = Math.Clamp(colorIndex, 0, data.Gradient.Length - 1);
return data.Gradient[colorIndex];
}
: _ => Color.White,
Acceleration = (_, velocity) => { // TODO: Acceleration needs to only update every tick
var drift = (component.Drift?.GenerateVector3(_random) ?? Vector3.Zero);
var friction = (component.Friction?.GenerateVector3(_random) ?? Vector3.Zero); // TODO: Only calculated once per particle
var drift = (data.Drift?.GenerateVector3(_random) ?? Vector3.Zero);
var friction = (data.Friction?.GenerateVector3(_random) ?? Vector3.Zero); // TODO: Only calculated once per particle

return drift - (velocity * friction);
},
SpawnPosition = () => component.SpawnPosition?.GenerateVector3(_random) ?? Vector3.Zero,
SpawnVelocity = () => component.SpawnVelocity?.GenerateVector3(_random) ?? Vector3.Zero,
SpawnPosition = () => data.SpawnPosition?.GenerateVector3(_random) ?? Vector3.Zero,
SpawnVelocity = () => data.SpawnVelocity?.GenerateVector3(_random) ?? Vector3.Zero,
Transform = _ => { // TODO: Needs to only be performed every tick
var scale = component.Scale.GenerateVector2(_random);
var rotation = component.Rotation?.Generate(_random) ?? 0f;
var growth = component.Growth?.GenerateVector2(_random) ?? Vector2.Zero;
var spin = component.Spin?.Generate(_random) ?? 0f;
var scale = data.Scale.GenerateVector2(_random);
var rotation = data.Rotation?.Generate(_random) ?? 0f;
var growth = data.Growth?.GenerateVector2(_random) ?? Vector2.Zero;
var spin = data.Spin?.Generate(_random) ?? 0f;
return Matrix3x2.CreateScale(scale.X + growth.X, scale.Y + growth.Y) *
Matrix3x2.CreateRotation(rotation + spin);
},
Expand Down
44 changes: 25 additions & 19 deletions OpenDreamRuntime/Objects/Types/DreamObjectMovable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,32 @@ public class DreamObjectMovable : DreamObjectAtom {
private readonly TransformComponent _transformComponent;
private readonly MovableContentsList _contents;
private string? _screenLoc;
private DreamObjectParticles? _particles;

private string? ScreenLoc {
get => _screenLoc;
set => SetScreenLoc(value);
}

public DreamObjectParticles? Particles {
get;
set {
if(field == value)
return;

if(field is not null) {
field.DecRef();
field.RemoveOwner(this);
}

field = value;

if(value is not null) {
value.AddOwner(this);
value.IncRef();
}
}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}

public DreamObjectMovable(DreamObjectDefinition objectDefinition) : base(objectDefinition) {
Entity = AtomManager.CreateMovableEntity(this);
SpriteComponent = EntityManager.GetComponent<DMISpriteComponent>(Entity);
Expand Down Expand Up @@ -54,8 +73,7 @@ public override void Initialize(DreamProcArguments args) {
protected override void HandleDeletion() {
SetLoc(null);
WalkManager.StopWalks(this);
_particles?.Delete();
_particles = null;
Particles = null;
AtomManager.DeleteMovableEntity(this);

_contents.DecRef();
Expand Down Expand Up @@ -97,8 +115,8 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
value = new DreamValue(locs);
return true;
case "particles":
_particles?.IncRef();
value = new(_particles);
Particles?.IncRef();
value = new(Particles);
return true;
default:
return base.TryGetVar(varName, out value);
Expand Down Expand Up @@ -145,21 +163,9 @@ protected override void SetVar(string varName, DreamValue value) {
ScreenLoc = screenLoc;
break;
case "particles":
if (value.TryGetValueAsDreamObject<DreamObjectParticles>(out var particles)) {
if (_particles == particles)
break;

_particles?.Owner = null;
particles.IncRef();
_particles?.DecRef();
_particles = particles;
_particles.Owner = this;
} else {
_particles?.Owner = null;
_particles?.DecRef();
_particles = null;
}
value.TryGetValueAsDreamObject<DreamObjectParticles>(out var particles);

Particles = particles;
break;
default:
base.SetVar(varName, value);
Expand Down
Loading
Loading