From acaa751e21d699fbb5dfe77325924703730aceac Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Mon, 23 Sep 2024 12:01:31 +0200 Subject: [PATCH 01/11] Add particle system manager class --- scripts/Globals.js | 4 +- scripts/_GameMaker.js | 2 +- scripts/functions/Function_Layers.js | 8 +- scripts/functions/Function_Particles.js | 15 +- scripts/yyParticle.js | 497 +++++++++++++++++------- scripts/yyRoom.js | 4 +- scripts/yySequence.js | 2 +- scripts/yyTypes.js | 10 + 8 files changed, 384 insertions(+), 158 deletions(-) diff --git a/scripts/Globals.js b/scripts/Globals.js index 1a21a055..b99ec19c 100644 --- a/scripts/Globals.js +++ b/scripts/Globals.js @@ -858,7 +858,7 @@ Audio_WebAudio=1, g_CurrentView =null, g_ParticleTextures =null, g_ParticleTypes =null, - g_ParticleSystems =null, + g_ParticleSystemManager =null, g_ActiveGrids =null, g_ActivePriorityQueues =null, g_BufferStorage = null, @@ -1166,7 +1166,7 @@ function InitAboyneGlobals() { g_ParticleChanges = []; // When a particle system changes depth g_ParticleTextures = []; g_ParticleTypes = []; - g_ParticleSystems = []; + g_ParticleSystemManager = new yyParticleSystemManager(); // @if function("ds_grid_*") g_ActiveGrids = new yyAllocate(5); // @endif diff --git a/scripts/_GameMaker.js b/scripts/_GameMaker.js index bd68855d..d2c3322e 100644 --- a/scripts/_GameMaker.js +++ b/scripts/_GameMaker.js @@ -1572,7 +1572,7 @@ function StartGame() function Run_EndGame(_reset) { g_ParticleTypes = []; - g_ParticleSystems = []; + g_ParticleSystemManager.RemoveAll(); types_created = 0; // Clear all instances - including persistant ones. diff --git a/scripts/functions/Function_Layers.js b/scripts/functions/Function_Layers.js index e4011bb5..1cb810d0 100644 --- a/scripts/functions/Function_Layers.js +++ b/scripts/functions/Function_Layers.js @@ -672,9 +672,11 @@ LayerManager.prototype.BuildTilemapElementRuntimeData = function( _room ,_layer, LayerManager.prototype.BuildParticleElementRuntimeData = function( _room ,_layer,_element) { // @if feature("particles") - if (_element.m_ps != -1 && _element.m_systemID == -1) + if (_element.m_ps != -1) { - CParticleSystem.Get(_element.m_ps).MakeInstance(_layer.m_id, false, _element); + var particleSystem = g_ParticleSystemManager.Get(_element.m_systemID); + if (!particleSystem) + CParticleSystem.Get(_element.m_ps).MakeInstance(_layer.m_id, false, _element, _element.m_systemID); } // @endif _element.m_bRuntimeDataInitialised=true; @@ -2028,7 +2030,7 @@ LayerManager.prototype.BuildRoomLayers = function(_room,_roomLayers) var pParticle = pLayer.particles[i]; var NewParticle = new CLayerParticleElement(); - NewParticle.m_systemID = -1; + NewParticle.m_systemID = pParticle.sId; NewParticle.m_ps = pParticle.sIndex; NewParticle.m_imageScaleX = pParticle.sXScale; NewParticle.m_imageScaleY = pParticle.sYScale; diff --git a/scripts/functions/Function_Particles.js b/scripts/functions/Function_Particles.js index 02979553..5c975872 100644 --- a/scripts/functions/Function_Particles.js +++ b/scripts/functions/Function_Particles.js @@ -15,6 +15,11 @@ // // ********************************************************************************************************************** +function PartSystemInstanceExists(_id) +{ + return (g_ParticleSystemManager.Get(yyGetInt32(_id)) != null); +} + function GetParticleSystemResourceIndex(_arg, _optional) { return yyGetRef(_arg, REFID_PARTICLESYSTEM, CParticleSystem.instances.length, CParticleSystem.instances, _optional); @@ -22,7 +27,7 @@ function GetParticleSystemResourceIndex(_arg, _optional) function GetParticleSystemInstanceIndex(_arg, _optional) { - return yyGetRef(_arg, REFID_PART_SYSTEM, g_ParticleSystems.length, g_ParticleSystems, _optional); + return yyGetRefFn(_arg, REFID_PART_SYSTEM, PartSystemInstanceExists, _optional); } function GetParticleEmitterIndex(_ps, _arg, _optional) @@ -31,7 +36,7 @@ function GetParticleEmitterIndex(_ps, _arg, _optional) var arr = null; if (!_optional) { - arr = g_ParticleSystems[_ps].emitters; + arr = g_ParticleSystemManager.Get(_ps).emitters; count = arr.length; } return yyGetRef(_arg, REFID_PART_EMITTER, count, arr, _optional); @@ -86,7 +91,7 @@ function ParticleSystemGetInfoImpl(_ind, _isInstance) { // Particle system INSTANCE _ind = GetParticleSystemInstanceIndex(_ind); - var pPS = g_ParticleSystems[_ind]; + var pPS = g_ParticleSystemManager.Get(_ind); if (pPS != null) { pPSI = new GMLObject(); @@ -508,9 +513,9 @@ function part_system_drawit(_ind) { ps = GetParticleSystemInstanceIndex(_ind); - if (!ParticleSystem_Exists(ps)) return; + var pSystem = g_ParticleSystemManager.Get(ps); - var pSystem = g_ParticleSystems[ps]; + if (pSystem == null) return; var matWorldOld = WebGL_GetMatrix(MATRIX_WORLD); diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index b7728d14..80abc45f 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -256,6 +256,7 @@ function yyParticleSystem() /**@constructor*/ function ParticleSystem_ClearClass() { + this.id = -1; this.m_resourceID = -1; // the id of the particle system resource that this system was created from this.created = false; // whether created @@ -391,16 +392,18 @@ CParticleSystem.prototype.GetIndex = function () /// /// The layer to use. A new one is created if not defined. /// +/// /// The index of the created instance. -CParticleSystem.prototype.MakeInstance = function (_layerID, _persistent, _pParticleEl) +CParticleSystem.prototype.MakeInstance = function (_layerID, _persistent, _pParticleEl, _systemID) { if (_layerID === undefined) _layerID = -1; if (_persistent === undefined) _persistent = true; if (_pParticleEl === undefined) _pParticleEl = null; + if (_systemID === undefined) _systemID = -1; var ps = (_pParticleEl == null) - ? ParticleSystem_Create(_layerID, _persistent) - : ParticleSystem_Create_OnLayer(_layerID, _persistent, _pParticleEl); + ? ParticleSystem_Create(_layerID, _persistent, _systemID) + : ParticleSystem_Create_OnLayer(_layerID, _persistent, _pParticleEl, _systemID); if (ps == -1) { @@ -408,7 +411,7 @@ CParticleSystem.prototype.MakeInstance = function (_layerID, _persistent, _pPart return ps; } - var system = g_ParticleSystems[ps]; + var system = g_ParticleSystemManager.Get(ps); system.m_resourceID = this.index; system.oldtonew = (this.drawOrder == 0); system.globalSpaceParticles = this.globalSpaceParticles; @@ -455,6 +458,195 @@ CParticleSystem.prototype.MakeInstance = function (_layerID, _persistent, _pPart return ps; }; + +PARTICLE_ID_ROOM_MIN = 0x00800000; + +function yyParticleSystemManager() +{ + this.particlesRoom = []; // Array of particle system instances placed into a room from the IDE + this.partsystems = []; // Particle system instances created on runtime +} + +// For user particle systems! +yyParticleSystemManager.prototype.GetNext = function () +{ + var id = 0; + while ((id < this.partsystems.length) && (this.partsystems[id] != null)) { id = id + 1; } + if (id == this.partsystems.length) + { + this.partsystems.length = id + 1; + this.partsystems.push(null); + } + + // assert(id < PARTICLE_ID_ROOM_MIN); // Run out of user particle system IDs! + + this.partsystems[id] = new yyParticleSystem(); + this.partsystems[id].id = id; + + return id; +}; + +// Only for room particle systems! +yyParticleSystemManager.prototype.Insert = function (id) +{ + // assert(id >= PARTICLE_ID_ROOM_MIN); + // assert(!this.Find(id)); + + var pos; + if (false) + { + // Linear search insert position + pos = 0; + while (pos < this.particlesRoom.length && this.particlesRoom[pos].id < id) + { + ++pos; + } + } + else + { + // Binary search insert position + var left = 0; + var right = this.particlesRoom.length; + while (left < right) + { + var mid = ~~(left + (right - left) / 2); + if (this.particlesRoom[mid].id < id) + { + left = mid + 1; + } + else + { + right = mid; + } + } + pos = left; + } + + this.particlesRoom.splice(pos, 0, new yyParticleSystem()); + this.particlesRoom[pos].id = id; +}; + +yyParticleSystemManager.prototype.Remove = function (id) +{ + // We don't have negative IDs + if (id < 0) + { + return; + } + + // Is a runtime created particle system instance + if (id < PARTICLE_ID_ROOM_MIN) + { + if (id >= this.partsystems.length) + { + // Outside of range of indices + return; + } + this.partsystems[id] = null; + return; + } + + // Is a IDE-placed particle system instance + var outData = { system: null, position: 0 }; + + if (!this.Find(id, outData)) + { + return; + } + + this.particlesRoom.splice(outData.position, 1); +}; + +yyParticleSystemManager.prototype.RemoveAll = function () +{ + this.particlesRoom = []; + this.partsystems = []; +}; + +// Returns a particle system instance with given ID or NULL if it doesn't exist. +yyParticleSystemManager.prototype.Get = function (id) +{ + // We don't have negative indices + if (id < 0) + { + return null; + } + + // Is a particle system instance created on runtime + if (id < PARTICLE_ID_ROOM_MIN) + { + if (id >= this.partsystems.length) + { + // Outside of range of indices + return null; + } + return this.partsystems[id]; + } + + // Is a IDE-placed particle system instance + var outData = { system: null, position: 0 }; + this.Find(id, outData); + return outData.system; +}; + +// Returns total number of existing particles +yyParticleSystemManager.prototype.Count = function () +{ + return (this.particlesRoom.length + this.partsystems.length); +}; + +// Returns a particle system instance at given index. Can be NULL, even when not outside of range of indices! +yyParticleSystemManager.prototype.At = function (index) +{ + if (index >= this.Count()) + { + return null; + } + + if (index >= this.particlesRoom.length) + { + return this.partsystems[index - this.particlesRoom.length]; + } + + return this.particlesRoom[index]; +}; + +yyParticleSystemManager.prototype.Find = function (id, outData) +{ + if (id < PARTICLE_ID_ROOM_MIN + || this.particlesRoom.length == 0) + { + return false; + } + + var left = 0; + var right = this.particlesRoom.length; + + while (left < right) + { + var mid = ~~(left + (right - left) / 2); + + if (this.particlesRoom[mid].id == id) + { + if (outData !== undefined) + { + outData.system = this.particlesRoom[mid]; + outData.position = mid; + } + return true; + } + else if (this.particlesRoom[mid].id < id) + { + left = mid + 1; + } + else + { + right = mid; + } + } + + return false; +}; // @endif particles // ############################################################################################# @@ -1503,9 +1695,10 @@ function ParticleSystem_Emitter_Create(_ps) { _ps = yyGetInt32(_ps); - if (!ParticleSystem_Exists(_ps)) return -1; + var pPartSys = g_ParticleSystemManager.Get(_ps); + if (pPartSys == null) + return -1; - var pPartSys = g_ParticleSystems[_ps]; var ind = 0; var emitter = null; @@ -1553,7 +1746,7 @@ function ParticleSystem_Emitter_Destroy(_ps, _ind) if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return false; - var emitter = g_ParticleSystems[_ps].emitters[_ind]; + var emitter = g_ParticleSystemManager.Get(_ps).emitters[_ind]; emitter.created = false; emitter.zombie = true; @@ -1574,10 +1767,13 @@ function ParticleSystem_Emitter_Destroy(_ps, _ind) function ParticleSystem_Emitter_DestroyAll(_ps) { _ps = yyGetInt32(_ps); - if (!ParticleSystem_Exists(_ps)) return false; - for (var i = g_ParticleSystems[_ps].emitters.length - 1; i >= 0; --i) + var particleSystem = g_ParticleSystemManager.Get(_ps); + if (particleSystem != null) { - ParticleSystem_Emitter_Destroy(_ps, i); + for (var i = particleSystem.emitters.length - 1; i >= 0; --i) + { + ParticleSystem_Emitter_Destroy(_ps, i); + } } return true; } @@ -1598,10 +1794,11 @@ function ParticleSystem_Emitter_Enable(_ps, _ind, _enable) _ps = yyGetInt32(_ps); _ind = yyGetInt32(_ind); - if (!ParticleSystem_Exists(_ps)) return; + var particleSystem = g_ParticleSystemManager.Get(_ps); + if (particleSystem == null) return; if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - g_ParticleSystems[_ps].emitters[_ind].enabled = yyGetBool(_enable); + particleSystem.emitters[_ind].enabled = yyGetBool(_enable); } // ############################################################################################# @@ -1620,9 +1817,9 @@ function ParticleSystem_Emitter_Exists(_ps, _ind) _ps = yyGetInt32(_ps); _ind = yyGetInt32(_ind); - if (!ParticleSystem_Exists(_ps)) return false; + var pPartSys = g_ParticleSystemManager.Get(_ps); + if (pPartSys == null) return false; - var pPartSys = g_ParticleSystems[_ps]; if (_ind < 0 || _ind >= pPartSys.emitters.length) return false; var pEmitter = pPartSys.emitters[_ind]; @@ -1650,7 +1847,7 @@ function ParticleSystem_Emitter_Clear(_ps, _ind) if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return false; - g_ParticleSystems[_ps].emitters[_ind].Reset(); + g_ParticleSystemManager.Get(_ps).emitters[_ind].Reset(); } @@ -1679,7 +1876,7 @@ function ParticleSystem_Emitter_Region(_ps, _ind, _xmin, _xmax, _ymin, _ymax, _s if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - var pEmitter = g_ParticleSystems[_ps].emitters[_ind]; + var pEmitter = g_ParticleSystemManager.Get(_ps).emitters[_ind]; pEmitter.xmin = yyGetReal(_xmin); pEmitter.xmax = yyGetReal(_xmax); @@ -1865,7 +2062,7 @@ function ParticleSystem_Emitter_Burst(_ps, _ind, _ptype, _numb) if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - var system = g_ParticleSystems[_ps]; + var system = g_ParticleSystemManager.Get(_ps); var emitter = system.emitters[_ind]; if (!emitter.enabled) return; @@ -1900,7 +2097,7 @@ function ParticleSystem_Emitter_Stream( _ps, _ind, _ptype, _numb) if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - var pEmitter = g_ParticleSystems[_ps].emitters[_ind]; + var pEmitter = g_ParticleSystemManager.Get(_ps).emitters[_ind]; pEmitter.parttype = yyGetInt32(_ptype); pEmitter.number = yyGetReal(_numb); @@ -1934,7 +2131,7 @@ function EmitterRandomizeDelay(_emitter) function ParticleSystem_Emitter_Delay( _ps, _ind, _delay_min, _delay_max, _delay_unit) { if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - var pEmitter = g_ParticleSystems[_ps].emitters[_ind]; + var pEmitter = g_ParticleSystemManager.Get(_ps).emitters[_ind]; pEmitter.delayMin = yyGetInt32(_delay_min); pEmitter.delayMax = yyGetReal(_delay_max); pEmitter.delayUnit = yyGetReal(_delay_unit); @@ -1969,7 +2166,7 @@ function EmitterRandomizeInterval(_emitter) function ParticleSystem_Emitter_Interval( _ps, _ind, _interval_min, _interval_max, _interval_unit) { if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - var pEmitter = g_ParticleSystems[_ps].emitters[_ind]; + var pEmitter = g_ParticleSystemManager.Get(_ps).emitters[_ind]; pEmitter.intervalMin = yyGetInt32(_interval_min); pEmitter.intervalMax = yyGetReal(_interval_max); pEmitter.intervalUnit = yyGetReal(_interval_unit); @@ -1989,7 +2186,7 @@ function ParticleSystem_Emitter_Relative(_ps, _ind, _enable) if (!ParticleSystem_Emitter_Exists(_ps, _ind)) return; - g_ParticleSystems[_ps].emitters[_ind].relative = yyGetBool(_enable); + g_ParticleSystemManager.Get(_ps).emitters[_ind].relative = yyGetBool(_enable); } @@ -2009,7 +2206,7 @@ function ParticleSystem_Emitter_Relative(_ps, _ind, _enable) // ############################################################################################# function ParticleSystem_Particles_Create(_ps, _x, _y, _parttype, _numb) { - var system = g_ParticleSystems[_ps]; + var system = g_ParticleSystemManager.Get(_ps); var em = -1; for (var i = 0; i < system.emitters.length; ++i) @@ -2046,7 +2243,9 @@ function ParticleSystem_Particles_Create(_ps, _x, _y, _parttype, _numb) // ############################################################################################# function ParticleSystem_Particles_Create_Color( _ps, _x, _y, _parttype, _col, _numb) { - if ( !ParticleSystem_Exists(_ps) ) { + var system = g_ParticleSystemManager.Get(_ps); + + if (system == null) { console.log( "part_particles_create :: particle system does not exist!" ); return; } // end if @@ -2055,8 +2254,6 @@ function ParticleSystem_Particles_Create_Color( _ps, _x, _y, _parttype, _col, _n return; } // end if - var system = g_ParticleSystems[_ps]; - var em = -1; for (var i = 0; i < system.emitters.length; ++i) { @@ -2094,7 +2291,9 @@ function ParticleSystem_Particles_Create_Color( _ps, _x, _y, _parttype, _col, _n // ############################################################################################# function ParticleSystem_Particles_Burst(_ps, _x, _y, _partsys) { - if (!ParticleSystem_Exists(_ps)) { + var system = g_ParticleSystemManager.Get(_ps); + + if (system == null) { console.log("part_particles_burst :: particle system does not exist!"); return; } // end if @@ -2106,7 +2305,6 @@ function ParticleSystem_Particles_Burst(_ps, _x, _y, _partsys) return; } // end if - var system = g_ParticleSystems[_ps]; var emitterCount = asset.emitters.length; var emittersEnabled = []; @@ -2144,8 +2342,10 @@ function ParticleSystem_Particles_Burst(_ps, _x, _y, _partsys) // ############################################################################################# function ParticleSystem_Particles_Clear(_ps) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return false; + _ps = yyGetInt32(_ps); + + var pPartSys = g_ParticleSystemManager.Get(_ps); + if(pPartSys == null) return false; for (var i = pPartSys.emitters.length - 1; i >= 0; --i) { @@ -2184,8 +2384,9 @@ function ParticleSystem_Particles_Delete(_pParticles, _index) // ############################################################################################# function ParticleSystem_Particles_Count( _ps ) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return 0 ; + _ps = yyGetInt32(_ps); + var pPartSys = g_ParticleSystemManager.Get(_ps); + if(pPartSys == null) return 0 ; var count = 0; for (var i = pPartSys.emitters.length - 1; i >= 0; --i) @@ -2241,28 +2442,32 @@ function ParticleSystem_Create_GetLayer(_layerID) return pPartEl; } -function ParticleSystem_Create_OnLayer(_layerID, _persistent, _pPartEl) +function ParticleSystem_Create_OnLayer(_layerID, _persistent, _pPartEl, _systemID) { - var index; - for (index = 0; index < g_ParticleSystems.length; ++index) + if (_systemID === undefined) _systemID = -1; + + var index = -1; + if (_systemID == -1) { - if (g_ParticleSystems[index] == null) - { - break; - } + index = g_ParticleSystemManager.GetNext(); + } + else + { + index = _systemID; + g_ParticleSystemManager.Insert(index); } - g_ParticleSystems[index] = new yyParticleSystem(); - g_ParticleSystems[index].id = index; // remember the ID - g_ParticleSystems[index].m_elementID = -1; + + var particleSystem = g_ParticleSystemManager.Get(index); + particleSystem.m_elementID = -1; ParticleSystem_Clear(index, false); _pPartEl.m_systemID = index; - g_ParticleSystems[index].m_elementID = _pPartEl.m_id; - g_ParticleSystems[index].m_volatile = !_persistent; + particleSystem.m_elementID = _pPartEl.m_id; + particleSystem.m_volatile = !_persistent; if (_layerID != -1) { - //g_ParticleSystems[index].m_origLayerID = _layerID; - g_ParticleSystems[index].depth = _pPartEl.m_layer.depth; + //particleSystem.m_origLayerID = _layerID; + particleSystem.depth = _pPartEl.m_layer.depth; } return index; @@ -2277,25 +2482,27 @@ function ParticleSystem_Create_OnLayer(_layerID, _persistent, _pPartEl) /// ID of the new particle system /// // ############################################################################################# -function ParticleSystem_Create(_layerID,_persistent) +function ParticleSystem_Create(_layerID, _persistent, _systemID) { if (_layerID == undefined) _layerID = -1; else _layerID = yyGetInt32(_layerID); - if (_persistent == undefined) _persistent = true; else _persistent = yyGetBool(_persistent); + + if (_systemID === undefined) + _systemID = -1; var pPartEl = ParticleSystem_Create_GetLayer(_layerID); if (pPartEl == null) return -1; - return ParticleSystem_Create_OnLayer(_layerID, _persistent, pPartEl); + return ParticleSystem_Create_OnLayer(_layerID, _persistent, pPartEl, _systemID); } // ############################################################################################# @@ -2310,9 +2517,7 @@ function ParticleSystem_Create(_layerID,_persistent) // ############################################################################################# function ParticleSystem_Exists( _ps ) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return false; - return true; + return (g_ParticleSystemManager.Get(yyGetInt32(_ps)) != null); } @@ -2331,18 +2536,19 @@ function ParticleSystem_Destroy( _ps ) { _ps = yyGetInt32(_ps); - var pPartSys = g_ParticleSystems[_ps]; - if (pPartSys == null || pPartSys == undefined) return; + var pPartSys = g_ParticleSystemManager.Get(_ps); + if (pPartSys == null) return; ParticleSystem_Clear(_ps, false); if (g_isZeus) { // Remove this from any layer it happens to be on - g_pLayerManager.RemoveElementById(g_RunRoom, g_ParticleSystems[_ps].m_elementID, true); + g_pLayerManager.RemoveElementById(g_RunRoom, pPartSys.m_elementID, true); } - g_ParticleSystems[_ps] = null; + g_ParticleSystemManager.Remove(_ps); + return true; } @@ -2354,12 +2560,14 @@ function ParticleSystem_Destroy( _ps ) // ############################################################################################# function ParticleSystem_DestroyAll() { - for (var i = 0; i < g_ParticleSystems.length; i++) - { - ParticleSystem_Destroy(i); - } - - g_ParticleSystems = []; + var count = g_ParticleSystemManager.Count(); + for (var i = 0; i < count; i++) + { + var particleSystem = g_ParticleSystemManager.Get(i); + if (particleSystem != null) + ParticleSystem_Destroy(particleSystem.id); + } + g_ParticleSystemManager.RemoveAll(); } @@ -2377,8 +2585,8 @@ function ParticleSystem_Clear(_ps, _reset_element_depth) { _ps = yyGetInt32(_ps); - var pPartSys = g_ParticleSystems[_ps]; - if (pPartSys == null || pPartSys == undefined) return; + var pPartSys = g_ParticleSystemManager.Get(_ps); + if (pPartSys == null) return; pPartSys.emitters = []; @@ -2417,11 +2625,12 @@ function ParticleSystem_Clear(_ps, _reset_element_depth) function ParticleSystem_GetLayer(_ps) { - if (!ParticleSystem_Exists(_ps)) - return -1; + var particleSystem = g_ParticleSystemManager.Get(_ps); + if (particleSystem == null) + return -1; var pLayer = null; - var elandlay = g_pLayerManager.GetElementAndLayerFromID(g_RunRoom, g_ParticleSystems[_ps].m_elementID); + var elandlay = g_pLayerManager.GetElementAndLayerFromID(g_RunRoom, particleSystem.m_elementID); if (elandlay == null) return -1; pLayer = elandlay.layer; @@ -2435,16 +2644,17 @@ function ParticleSystem_GetLayer(_ps) function ParticleSystem_Layer(_ps,_layerID) { - if (!ParticleSystem_Exists(_ps)) + var particleSystem = g_ParticleSystemManager.Get(_ps); + if (particleSystem == null) return; if (g_isZeus) { // Remove this from any layer it happens to be on and re-add it again - g_pLayerManager.RemoveElementById(g_RunRoom, g_ParticleSystems[_ps].m_elementID, true); + g_pLayerManager.RemoveElementById(g_RunRoom, particleSystem.m_elementID, true); var pPartEl = new CLayerParticleElement(); pPartEl.m_systemID = _ps; - //g_ParticleSystems[_ps].m_origLayerID = _layerID; // reset the associated layer id + //particleSystem.m_origLayerID = _layerID; // reset the associated layer id var room = g_pLayerManager.GetTargetRoomObj(); if (room != null) @@ -2456,18 +2666,18 @@ function ParticleSystem_Layer(_ps,_layerID) if (room == g_RunRoom) { - g_ParticleSystems[_ps].m_elementID = g_pLayerManager.AddNewElement(g_RunRoom, layer, pPartEl, true); - g_ParticleSystems[_ps].depth = layer.depth; // reset depth - if (g_ParticleSystems[_ps].m_elementID == -1) + particleSystem.m_elementID = g_pLayerManager.AddNewElement(g_RunRoom, layer, pPartEl, true); + particleSystem.depth = layer.depth; // reset depth + if (particleSystem.m_elementID == -1) { g_pLayerManager.RemoveElementById(g_RunRoom, pPartEl.m_id, true); } } } - if (g_ParticleSystems[_ps].m_elementID == -1) + if (particleSystem.m_elementID == -1) { - g_ParticleSystems[_ps].m_elementID = g_pLayerManager.AddNewElementAtDepth(g_RunRoom, g_ParticleSystems[_ps].depth, pPartEl, true, true); + particleSystem.m_elementID = g_pLayerManager.AddNewElementAtDepth(g_RunRoom, particleSystem.depth, pPartEl, true, true); } } } @@ -2486,8 +2696,9 @@ function ParticleSystem_Layer(_ps,_layerID) // ############################################################################################# function ParticleSystem_GlobalSpace(_ps, _enable) { - if (!ParticleSystem_Exists(_ps)) return; - g_ParticleSystems[_ps].globalSpaceParticles = _enable; + var particleSystem = g_ParticleSystemManager.Get(_ps); + if (particleSystem == null) return; + particleSystem.globalSpaceParticles = _enable; } // ############################################################################################# @@ -2501,16 +2712,15 @@ function ParticleSystem_GlobalSpace(_ps, _enable) /// // ############################################################################################# function ParticleSystem_ClearParticles() -{ - for (var ps = 0; ps < g_ParticleSystems.length; ps++) - { - if (!g_ParticleSystems.hasOwnProperty(ps)) continue; - - var pPartSys = g_ParticleSystems[ps]; - if (pPartSys) { - pPartSys.particles = []; - } - } +{ + var count = g_ParticleSystemManager.Count(); + for (var ps = 0; ps < count; ++ps) + { + var pPartSys = g_ParticleSystemManager.At(ps); + if (pPartSys) { + pPartSys.particles = []; + } + } } @@ -2527,9 +2737,8 @@ function ParticleSystem_ClearParticles() // ############################################################################################# function ParticleSystem_DrawOrder(_ps, _oldtonew) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return; - + var pPartSys = g_ParticleSystemManager.Get(yyGetInt32(_ps)); + if (pPartSys == null) return; pPartSys.oldtonew = _oldtonew; } @@ -2546,8 +2755,8 @@ function ParticleSystem_Depth(_ps, _depth) { _ps = yyGetInt32(_ps); - var pPartSys = g_ParticleSystems[_ps]; - if( pPartSys ==null || pPartSys==undefined ) return; + var pPartSys = g_ParticleSystemManager.Get(_ps); + if (pPartSys == null) return; pPartSys.id = _ps; pPartSys.depth = yyGetReal(_depth); @@ -2561,8 +2770,8 @@ function ParticleSystem_Depth(_ps, _depth) g_pLayerManager.RemoveElementById(g_RunRoom, pPartSys.m_elementID, true); var pPartEl = new CLayerParticleElement(); pPartEl.m_systemID = _ps; - g_ParticleSystems[_ps].m_origLayerID = -1; // scrub any associated layer ID if we're manually changing depth - g_ParticleSystems[_ps].m_elementID = g_pLayerManager.AddNewElementAtDepth(g_RunRoom, g_ParticleSystems[_ps].depth, pPartEl, true, true); + g_ParticleSystemManager.m_origLayerID = -1; // scrub any associated layer ID if we're manually changing depth + g_ParticleSystemManager.m_elementID = g_pLayerManager.AddNewElementAtDepth(g_RunRoom, g_ParticleSystemManager.depth, pPartEl, true, true); }*/ } @@ -2580,8 +2789,8 @@ function ParticleSystem_Depth(_ps, _depth) // ############################################################################################# function ParticleSystem_Color(_ps, _color, _alpha) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return; + var pPartSys = g_ParticleSystemManager.Get(yyGetInt32(_ps)); + if (pPartSys == null) return; pPartSys.color = yyGetInt32(_color); pPartSys.alpha = yyGetReal(_alpha); @@ -2601,8 +2810,8 @@ function ParticleSystem_Color(_ps, _color, _alpha) // ############################################################################################# function ParticleSystem_Position(_ps, _x, _y) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return; + var pPartSys = g_ParticleSystemManager.Get(yyGetInt32(_ps)); + if (pPartSys == null) return; pPartSys.xdraw = yyGetReal(_x); pPartSys.ydraw = yyGetReal(_y); @@ -2621,8 +2830,8 @@ function ParticleSystem_Position(_ps, _x, _y) // ############################################################################################# function ParticleSystem_Angle(_ps, _angle) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return; + var pPartSys = g_ParticleSystemManager.Get(yyGetInt32(_ps)); + if (pPartSys == null) return; pPartSys.angle = yyGetReal(_angle); } @@ -2640,8 +2849,8 @@ function ParticleSystem_Angle(_ps, _angle) // ############################################################################################# function ParticleSystem_AutomaticUpdate( _ps, _automatic) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return; + var pPartSys = g_ParticleSystemManager.Get(yyGetInt32(_ps)); + if (pPartSys == null) return; pPartSys.automaticupdate = yyGetBool(_automatic); } @@ -2659,9 +2868,8 @@ function ParticleSystem_AutomaticUpdate( _ps, _automatic) // ############################################################################################# function ParticleSystem_AutomaticDraw(_ps, _automatic) { - var pPartSys = g_ParticleSystems[yyGetInt32(_ps)]; - if( pPartSys ==null || pPartSys==undefined ) return; - + var pPartSys = g_ParticleSystemManager.Get(yyGetInt32(_ps)); + if (pPartSys == null) return; pPartSys.automaticdraw = yyGetBool(_automatic); } @@ -2684,7 +2892,7 @@ function HandleLife( _ps, _em ) var i = 0; var numb = 0; - var pPartSys = g_ParticleSystems[_ps]; + var pPartSys = g_ParticleSystemManager.Get(_ps); var pEmitter = pPartSys.emitters[_em]; var pParticles = pEmitter.particles; @@ -2760,7 +2968,7 @@ function HandleMotion( _ps, _em ) var rd = 0.0; var rs = 0.0; - var pPartSys = g_ParticleSystems[_ps]; + var pPartSys = g_ParticleSystemManager.Get(_ps); var pParticles = pPartSys.emitters[_em].particles; for( i=0; i0) { if (pPartSys.automaticdraw) @@ -3415,10 +3624,10 @@ function ParticleSystem_LargestDepth() function ParticleSystem_NextDepth(_d) { var Result = -1000000000; - - for(var i=0 ; i0) { if (pPartSys.automaticdraw) diff --git a/scripts/yyRoom.js b/scripts/yyRoom.js index d8e157f4..7e8fcb4b 100644 --- a/scripts/yyRoom.js +++ b/scripts/yyRoom.js @@ -2110,9 +2110,9 @@ yyRoom.prototype.DrawLayerParticleSystem = function(_rect,_layer,_el) // @if feature("particles") var ps = _el.m_systemID; - if (!ParticleSystem_Exists(ps)) return; + var pSystem = g_ParticleSystemManager.Get(ps); - var pSystem = g_ParticleSystems[ps]; + if (pSystem == null) return; if (!pSystem.automaticdraw) return; diff --git a/scripts/yySequence.js b/scripts/yySequence.js index 26c2ac25..f08ce541 100644 --- a/scripts/yySequence.js +++ b/scripts/yySequence.js @@ -6003,7 +6003,7 @@ yySequenceManager.prototype.HandleParticleTrackUpdate = function (_pEl, _pSeq, _ // Re-burst emitters when the sequence loops if (_pInst.m_wrapped) { - var pPartSys = g_ParticleSystems[ps]; + var pPartSys = g_ParticleSystemManager.Get(ps); var pEmitters = pPartSys.emitters; if (pEmitters) { diff --git a/scripts/yyTypes.js b/scripts/yyTypes.js index 74497d1a..f0a75c7c 100644 --- a/scripts/yyTypes.js +++ b/scripts/yyTypes.js @@ -389,6 +389,16 @@ function yyGetRef(_value, _ref, _maxNum, _array, _allowOutOfRange) { return ret; } +function yyGetRefFn(_value, _ref, _fnExists, _allowOutOfRange) { + var ret = yyGetRef(_value, _ref, 0, 0, true); + if (!_allowOutOfRange) { + if (_fnExists && !_fnExists(ret)) { + yyError("invalid reference to (" + RefName(_ref) + ")"); + } + } + return ret; +} + // ############################################################################################# /// Function: /// Converts the given type to a string if required and returns the result. From 905ed287b3d236424b4061077390da5e0e0e087c Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Mon, 23 Sep 2024 14:03:31 +0200 Subject: [PATCH 02/11] Add layer_particle_* functions --- scripts/functions/Function_Layers.js | 153 +++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/scripts/functions/Function_Layers.js b/scripts/functions/Function_Layers.js index 1cb810d0..e65381dc 100644 --- a/scripts/functions/Function_Layers.js +++ b/scripts/functions/Function_Layers.js @@ -3126,6 +3126,159 @@ function layer_sprite_get_y( arg1) }; +// Particle element funtions +function layerParticleGetElement(_paricle_element_id) +{ + var room = g_pLayerManager.GetTargetRoomObj(); + var el = g_pLayerManager.GetElementFromID(room, _paricle_element_id); + if ((el != null) && (el.m_type === eLayerElementType_ParticleSystem)) return el; + return null; +} + +function layer_particle_xscale(_paricle_element_id, _scale) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_imageScaleX = yyGetReal(_scale); + } +} + +function layer_particle_yscale(_paricle_element_id, _scale) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_imageScaleY = yyGetReal(_scale); + } +} + +function layer_particle_angle(_paricle_element_id, _angle) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_imageAngle = yyGetReal(_angle); + } +} + +function layer_particle_blend(_paricle_element_id, _col) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_imageBlend = ConvertGMColour(yyGetInt32(_col)); + } +} + +function layer_particle_alpha(_paricle_element_id, _alpha) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_imageAlpha = yyGetReal(_alpha); + } +} + +function layer_particle_x(_paricle_element_id, _x) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_x = yyGetReal(_x); + } +} + +function layer_particle_y(_paricle_element_id, _y) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + el.m_y = yyGetReal(_y); + } +} + +function layer_particle_get_system(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + var id = -1; + if (el != null) + { + id = el.m_systemID; + } + return MAKE_REF(REFID_PART_SYSTEM, (id != -1) ? id : 0xffffffff); +} + +function layer_particle_get_xscale(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_imageScaleX; + } + return 1; +} + +function layer_particle_get_yscale(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_imageScaleY; + } + return 1; +} + +function layer_particle_get_angle(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_imageAngle; + } + return 0; +} + +function layer_particle_get_blend(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_imageBlend; + } + return 0; +} + +function layer_particle_get_alpha(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_imageAlpha; + } + return 0; +} + +function layer_particle_get_x(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_x; + } + return 0; +} + +function layer_particle_get_y(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + if (el != null) + { + return el.m_y; + } + return 0; +} + // Text element functions function layerTextGetElement(_text_element_id) { From adade076162813aa0972f917db03317f4238ddb7 Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Mon, 23 Sep 2024 14:07:06 +0200 Subject: [PATCH 03/11] Fix getting particle systems --- scripts/yyParticle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index 80abc45f..34189d03 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -2563,7 +2563,7 @@ function ParticleSystem_DestroyAll() var count = g_ParticleSystemManager.Count(); for (var i = 0; i < count; i++) { - var particleSystem = g_ParticleSystemManager.Get(i); + var particleSystem = g_ParticleSystemManager.At(i); if (particleSystem != null) ParticleSystem_Destroy(particleSystem.id); } @@ -3548,7 +3548,7 @@ function ParticleSystem_RemoveAllFromLayers() pSystem.m_elementID = -1; } - ParticleSystem_Destroy(i); + ParticleSystem_Destroy(pSystem.id); persistentsystemlayernames[i] = null; continue; } From e566e131c2f6f58b63b48a8598a3ca1b7ee41afd Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Mon, 23 Sep 2024 14:36:28 +0200 Subject: [PATCH 04/11] Fix iterating particles when they're being destroyed --- scripts/yyParticle.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index 34189d03..593a152f 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -2561,11 +2561,16 @@ function ParticleSystem_Destroy( _ps ) function ParticleSystem_DestroyAll() { var count = g_ParticleSystemManager.Count(); + var index = 0; for (var i = 0; i < count; i++) { - var particleSystem = g_ParticleSystemManager.At(i); - if (particleSystem != null) - ParticleSystem_Destroy(particleSystem.id); + var particleSystem = g_ParticleSystemManager.At(index); + if (!particleSystem) + { + ++index; + continue; + } + ParticleSystem_Destroy(particleSystem.id); } g_ParticleSystemManager.RemoveAll(); } @@ -3517,11 +3522,17 @@ function ParticleSystem_RemoveAllFromLayers() var pscount = g_ParticleSystemManager.Count(); persistentsystemlayernames = new Array(pscount).fill(null); + var index = 0; + for (var i = 0; i < pscount; ++i) { - var pSystem = g_ParticleSystemManager.At(i); + var pSystem = g_ParticleSystemManager.At(index); - if (!pSystem) continue; + if (!pSystem) + { + ++index; + continue; + } // Get layer and element that the particle system is on var pLayer = null; From c294b6357ad84da58f4604ed97d5ba4384bbe2fa Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Tue, 24 Sep 2024 11:54:02 +0200 Subject: [PATCH 05/11] Implement function layer_particle_get_id --- scripts/functions/Function_Layers.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/functions/Function_Layers.js b/scripts/functions/Function_Layers.js index e65381dc..6b82729c 100644 --- a/scripts/functions/Function_Layers.js +++ b/scripts/functions/Function_Layers.js @@ -2039,7 +2039,7 @@ LayerManager.prototype.BuildRoomLayers = function(_room,_roomLayers) NewParticle.m_imageAlpha = ((pParticle.sBlend>>24)&0xff) / 255.0; NewParticle.m_x = pParticle.sX; NewParticle.m_y = pParticle.sY; - NewParticle.m_pName = pParticle.sName; + NewParticle.m_name = pParticle.sName; this.AddNewElement(_room, NewLayer, NewParticle, false); } @@ -3198,6 +3198,24 @@ function layer_particle_y(_paricle_element_id, _y) } } +function layer_particle_get_id(_layerid, _particlename) +{ + var room = g_pLayerManager.GetTargetRoomObj(); + if (room === null) return -1; + + var layer = layerGetObj(room, _layerid); + + if (layer != null) + { + var element = g_pLayerManager.GetElementFromName(layer, yyGetString(_particlename)); + if (element != null && element.m_type == eLayerElementType_ParticleSystem) + { + return element.m_id; + } + } + return -1; +} + function layer_particle_get_system(_paricle_element_id) { var el = layerParticleGetElement(_paricle_element_id); From 4fd6f75f4897d6f8e4b76ec63c6d3f9a1875a2af Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Wed, 25 Sep 2024 12:01:07 +0200 Subject: [PATCH 06/11] Fix iterating through particles in RemoveAllFromLayers --- scripts/yyParticle.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index 593a152f..833b3008 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -598,17 +598,17 @@ yyParticleSystemManager.prototype.Count = function () // Returns a particle system instance at given index. Can be NULL, even when not outside of range of indices! yyParticleSystemManager.prototype.At = function (index) { - if (index >= this.Count()) + if (index < 0 || index >= this.Count()) { return null; } - if (index >= this.particlesRoom.length) + if (index >= this.partsystems.length) { - return this.partsystems[index - this.particlesRoom.length]; + return this.particlesRoom[index - this.partsystems.length]; } - return this.particlesRoom[index]; + return this.partsystems[index]; }; yyParticleSystemManager.prototype.Find = function (id, outData) @@ -3526,13 +3526,9 @@ function ParticleSystem_RemoveAllFromLayers() for (var i = 0; i < pscount; ++i) { - var pSystem = g_ParticleSystemManager.At(index); + var pSystem = g_ParticleSystemManager.At(index++); - if (!pSystem) - { - ++index; - continue; - } + if (!pSystem) continue; // Get layer and element that the particle system is on var pLayer = null; @@ -3559,6 +3555,10 @@ function ParticleSystem_RemoveAllFromLayers() pSystem.m_elementID = -1; } + // TODO: Add particle system instance iterator??? + if (pSystem.id >= PARTICLE_ID_ROOM_MIN) + --index; + ParticleSystem_Destroy(pSystem.id); persistentsystemlayernames[i] = null; continue; From 54a50ad6184d890fecea7344213b9188d2a7f4ef Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Wed, 25 Sep 2024 14:32:27 +0200 Subject: [PATCH 07/11] Cache last found particle system, unify naming --- scripts/yyParticle.js | 51 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index 833b3008..b255ad49 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -463,25 +463,26 @@ PARTICLE_ID_ROOM_MIN = 0x00800000; function yyParticleSystemManager() { - this.particlesRoom = []; // Array of particle system instances placed into a room from the IDE - this.partsystems = []; // Particle system instances created on runtime + this.particlesRoom = []; // Array of particle system instances placed into a room from the IDE + this.cached = null; // Last particle system looked up with Find in Get + this.particlesRuntime = []; // Particle system instances created on runtime } // For user particle systems! yyParticleSystemManager.prototype.GetNext = function () { var id = 0; - while ((id < this.partsystems.length) && (this.partsystems[id] != null)) { id = id + 1; } - if (id == this.partsystems.length) + while ((id < this.particlesRuntime.length) && (this.particlesRuntime[id] != null)) { id = id + 1; } + if (id == this.particlesRuntime.length) { - this.partsystems.length = id + 1; - this.partsystems.push(null); + this.particlesRuntime.length = id + 1; + this.particlesRuntime.push(null); } // assert(id < PARTICLE_ID_ROOM_MIN); // Run out of user particle system IDs! - this.partsystems[id] = new yyParticleSystem(); - this.partsystems[id].id = id; + this.particlesRuntime[id] = new yyParticleSystem(); + this.particlesRuntime[id].id = id; return id; }; @@ -537,16 +538,21 @@ yyParticleSystemManager.prototype.Remove = function (id) // Is a runtime created particle system instance if (id < PARTICLE_ID_ROOM_MIN) { - if (id >= this.partsystems.length) + if (id >= this.particlesRuntime.length) { // Outside of range of indices return; } - this.partsystems[id] = null; + this.particlesRuntime[id] = null; return; } // Is a IDE-placed particle system instance + if (this.cached && this.cached.id == id) + { + this.cached = null; + } + var outData = { system: null, position: 0 }; if (!this.Find(id, outData)) @@ -560,7 +566,8 @@ yyParticleSystemManager.prototype.Remove = function (id) yyParticleSystemManager.prototype.RemoveAll = function () { this.particlesRoom = []; - this.partsystems = []; + this.cached = null; + this.particlesRuntime = []; }; // Returns a particle system instance with given ID or NULL if it doesn't exist. @@ -575,24 +582,32 @@ yyParticleSystemManager.prototype.Get = function (id) // Is a particle system instance created on runtime if (id < PARTICLE_ID_ROOM_MIN) { - if (id >= this.partsystems.length) + if (id >= this.particlesRuntime.length) { // Outside of range of indices return null; } - return this.partsystems[id]; + return this.particlesRuntime[id]; } // Is a IDE-placed particle system instance + if (this.cached && this.cached.id == id) + { + return this.cached; + } + var outData = { system: null, position: 0 }; - this.Find(id, outData); + if (this.Find(id, outData)) + { + this.cached = outData.system; + } return outData.system; }; // Returns total number of existing particles yyParticleSystemManager.prototype.Count = function () { - return (this.particlesRoom.length + this.partsystems.length); + return (this.particlesRoom.length + this.particlesRuntime.length); }; // Returns a particle system instance at given index. Can be NULL, even when not outside of range of indices! @@ -603,12 +618,12 @@ yyParticleSystemManager.prototype.At = function (index) return null; } - if (index >= this.partsystems.length) + if (index >= this.particlesRuntime.length) { - return this.particlesRoom[index - this.partsystems.length]; + return this.particlesRoom[index - this.particlesRuntime.length]; } - return this.partsystems[index]; + return this.particlesRuntime[index]; }; yyParticleSystemManager.prototype.Find = function (id, outData) From 08ad3a57a3c376a84ba2fbff1acf43ac00ba168a Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Wed, 25 Sep 2024 14:49:30 +0200 Subject: [PATCH 08/11] Fix rotation of global space particle systems --- scripts/yyParticle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index b255ad49..99b6a2f6 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -942,7 +942,7 @@ function CreateParticle(_system, _x, _y, _parttype) if (_system.globalSpaceParticles) { - Result.dir += RAD(Math.atan2(_system.matrix.m[_21], _system.matrix.m[_11])); + Result.dir += (180/Pi) * (Math.atan2(_system.matrix.m[_21], _system.matrix.m[_11])); } Result.ran = YYRandom(100000); From e1dffe93c3acafe74bec2e6001bbfd713d35a429 Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Wed, 25 Sep 2024 15:00:41 +0200 Subject: [PATCH 09/11] Fix iterating through particle systems in DestroyAll --- scripts/yyParticle.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/yyParticle.js b/scripts/yyParticle.js index 99b6a2f6..5c877455 100644 --- a/scripts/yyParticle.js +++ b/scripts/yyParticle.js @@ -2579,12 +2579,9 @@ function ParticleSystem_DestroyAll() var index = 0; for (var i = 0; i < count; i++) { - var particleSystem = g_ParticleSystemManager.At(index); - if (!particleSystem) - { - ++index; - continue; - } + var particleSystem = g_ParticleSystemManager.At(index++); + if (!particleSystem) continue; + if (particleSystem.id >= PARTICLE_ID_ROOM_MIN) --index; ParticleSystem_Destroy(particleSystem.id); } g_ParticleSystemManager.RemoveAll(); From 6b74605afe93131e8260dc7a84bb9b6c7995a6b4 Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Mon, 30 Sep 2024 14:28:10 +0200 Subject: [PATCH 10/11] Renamed layer_particle_get_system to layer_particle_get_instance --- scripts/functions/Function_Layers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/functions/Function_Layers.js b/scripts/functions/Function_Layers.js index 6b82729c..02daa16e 100644 --- a/scripts/functions/Function_Layers.js +++ b/scripts/functions/Function_Layers.js @@ -3216,7 +3216,7 @@ function layer_particle_get_id(_layerid, _particlename) return -1; } -function layer_particle_get_system(_paricle_element_id) +function layer_particle_get_instance(_paricle_element_id) { var el = layerParticleGetElement(_paricle_element_id); var id = -1; From 4ac5727c4d0a4ab8f3356d16a0699a06a2bdfaa7 Mon Sep 17 00:00:00 2001 From: Patrik Kraif Date: Mon, 30 Sep 2024 14:53:46 +0200 Subject: [PATCH 11/11] Add new layer_particle_get_system function --- scripts/functions/Function_Layers.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/functions/Function_Layers.js b/scripts/functions/Function_Layers.js index 02daa16e..32b11d70 100644 --- a/scripts/functions/Function_Layers.js +++ b/scripts/functions/Function_Layers.js @@ -3227,6 +3227,17 @@ function layer_particle_get_instance(_paricle_element_id) return MAKE_REF(REFID_PART_SYSTEM, (id != -1) ? id : 0xffffffff); } +function layer_particle_get_system(_paricle_element_id) +{ + var el = layerParticleGetElement(_paricle_element_id); + var id = -1; + if (el != null) + { + id = el.m_ps; + } + return MAKE_REF(REFID_PARTICLESYSTEM, (id != -1) ? id : 0xffffffff); +} + function layer_particle_get_xscale(_paricle_element_id) { var el = layerParticleGetElement(_paricle_element_id);