Skip to content

GMB-7626: Particle system names from the room editor usable in code + new layer_particle_*() functions #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions scripts/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/_GameMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ function StartGame()
function Run_EndGame(_reset) {

g_ParticleTypes = [];
g_ParticleSystems = [];
g_ParticleSystemManager.RemoveAll();
types_created = 0;

// Clear all instances - including persistant ones.
Expand Down
192 changes: 188 additions & 4 deletions scripts/functions/Function_Layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -2037,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);
}
Expand Down Expand Up @@ -3124,6 +3126,188 @@ 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_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_instance(_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_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);
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)
{
Expand Down
15 changes: 10 additions & 5 deletions scripts/functions/Function_Particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
//
// **********************************************************************************************************************

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);
}

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)
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
Loading