MODULE: ParticleSystemManager v1.01

Started by jerakeen, Mon 26/01/2009 19:57:29

Previous topic - Next topic

jerakeen

Hi, for the last weeks i been working on it and now i share for you.

This module has been built to simulate effects like rain, waterfall, fire, smoke,
snow and others.

We can have some particle systems at the same time.
We can define some forces wich modifies particles velocity and position.
We can change color, transparency and scale of particles.
And we can choose between draw a particle system in the background of a room,
in a sprite or using an overlay.

Requires AGS V3.0.0 or later

Screenshots

Here is the module (Vers 1.00):
 
  Module ParticleSystemManager v1.00
 

And a demo (in AGS v3.1.1)

  ParticleSystemManager Demogame

  ParticleSystemManager Exe


Edit by Dualnames: Removed links that don't work

In the demo game you can do player walk around to see how slow or fast the game is using particle system.

When drawing particle system in a sprite, you can use this sprite in a room's object and do the player walk around and interact with it.

Remember that too many particles will slow down the game.

NOTE: There are some problems drawing transparent particle system in sprites


EDIT:

There is a new release of the module.
These are the changes:

<11-JAN-09> Jerakeen,

      Created original version

<08-APR-09> Jerakeen,

      Replaced RawSaveScreen by DrawingSurface functions.

<17-APR-09> abstauber,

      Add emitter_set_certain_sprites function and changes to manage
      the sprites of the first particles in the system.

<20-APR-09> Jerakeen,

      Add emitter_set_sprites_indexes function and changes to manage
      sprites with non consecutive index.

And here is the module:


   Module ParticleSystemManager v1.01 


Edit by Dualnames: Removed links that don't work


  Thanks to abstauber by the function emitter_set_certain_sprites and code modifications.

Enjoy it

GarageGothic

Looks very nice. However, I get 0 byte files when trying to download the demo and the demo source files :(

Ghost

Download works okay for me, and the module defenitely looks interesting. Thanks for sharing!

jerakeen

Try again the same links, it should work

GarageGothic

Yup, now it works. But I swear, I tried downloading each file four times earlier, both through direct click and right-click-save-as, and I all I got was "download finished" with a 0 byte file.

Great work jerakeen! The demo is very convincing.

jerakeen

Sorry, the links were broken and i upload the files again, then Ghost could download ok and you too.

I hope you found this module useful.

i'm sure i'll add some improvements in the future.

thanks

Khris

Nice work!
It looks like the snow and rain particles accelerate their fall though; this isn't true in real life and thus looks weird.

jerakeen

Quote from: KhrisMUC on Tue 27/01/2009 15:05:26
Nice work!
It looks like the snow and rain particles accelerate their fall though; this isn't true in real life and thus looks weird.

Thank you. This is only a demo. If you take a look to the code int Room1, you will see than changing initial velocity (emitter_set_velocity) and removing the force (action_add_force)  in y negative you'll achieve what you want.

Khris

Ah, ok, I didn't look at the source code yet.

Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Rocco

great work,  :)
covered nearly all circumstances.

Joe

This is INCREDIBLE!!! :o

I'm really really impressed. CONGRATULATIONS!!!
Copinstar © Oficial Site

redspark

I'm using AGS 3.1.2 SP1 and I get errors for RawScreenSave() and RawScreenRestore() in my project which was created in 3.1.2 SP1 but I don't get the errors when I compile the demo in this version of AGS.  According to the documentation, those functions are obsolete now.  I'm going to replace them with DrawingSurface functions but I'm pretty new to AGS and I'm not sure what I'm doing. ;)  Is there a better way to do this?  Thanks.

jerakeen

Quote from: redspark on Sat 04/04/2009 13:48:00
I'm using AGS 3.1.2 SP1 and I get errors for RawScreenSave() and RawScreenRestore() in my project which was created in 3.1.2 SP1 but I don't get the errors when I compile the demo in this version of AGS.  According to the documentation, those functions are obsolete now.  I'm going to replace them with DrawingSurface functions but I'm pretty new to AGS and I'm not sure what I'm doing. ;)  Is there a better way to do this?  Thanks.

Hi, you can compile it changing some parameters in "General Settings" pane, in Scripting section there are 2 options: "Enforce new-style strings" and "Enforce object-based scripting". If you set both of them to false im sure it will compile using RawScreenSave() function.

I'll change this function in the future.

redspark

Ok.  I'll give that a try.  Thanks.

Dualnames

It works brilliantly, just wanting you to know that. It's fairly more customizable and user-friendly than Akumayo's Particle Engine. Not to mention its also faster. Akumayo's needed at least 2Ghz to work in a smooth way.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

jerakeen

Thanks Dualnames. But i think my module is sill sloooow.

Im trying to change some thing to improve it.

Dualnames

Quote from: jerakeen on Thu 09/04/2009 12:00:30
Thanks Dualnames. But i think my module is sill sloooow.

Im trying to change some thing to improve it.

Check Akumayos. That's slow. Mostly because of the rawdraw.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

jerakeen

Hi, there is a new version of the module, with minor changes.

redspark

Thank you!  I'm going to download this and give it a try.  Thanks again.

abstauber

Thanks for this new release (and mentioning me  := )!

I'm sure, there are a lot projects which will love your module. Any chance, you make something else this fancy?  ;D

jerakeen

i'm afraid not. I had no time to implement further changes right now.

I was thinking on implement something like rules, so when a condition is meet then an action or change on particles is done.

Something like if particle's age is greater than 12 change sprite, or if there are 20 particles on the system change the force.

i thing this will useful to make the system change, for example change fire into smoke.

But this will be to many code and i got no time by now.


DavidCB

There is a small problem in this new version of AGS, RawSaveScreen and RawRestoreScreen are unknown commands.
If you want to replace with DrawingSurface, you need global variables.

jerakeen

Quote from: DavidCB on Wed 10/06/2009 08:30:12
There is a small problem in this new version of AGS, RawSaveScreen and RawRestoreScreen are unknown commands.
If you want to replace with DrawingSurface, you need global variables.

I know, because of this, there is a new version of the module, in the original post there is a new link to the "release" ModuleParticleSystemManager v1.01

R4L

Hello, I don't mean to bump an old topic, but could you help me please?

I'm using AGS 3.1, and I'm trying to set up some rain to fall in a room. I'm following the readme, but I keep getting a parse error. I haven't scripted anything in a while, so it could be that I'm placing things in the wrong spots, or just flat out doing it wrong.

Here's my room script:

Code: ags
// room script file

int num_systems;

function CreateSystem (int 25, bool keep_track = false, enDrawType draw_type = dtBackground, int width = 640 , int height = 480);

function emitter_creation_mode (int system, enRepeatMode rmAllways, int max_rep, int 40, int 2);


I know something is wrong, I just can't figure it out. Any help is greatly appreciated. :)

Dualnames

Quote from: R4L on Mon 28/12/2009 14:51:07
Hello, I don't mean to bump an old topic, but could you help me please?

I'm using AGS 3.1, and I'm trying to set up some rain to fall in a room. I'm following the readme, but I keep getting a parse error. I haven't scripted anything in a while, so it could be that I'm placing things in the wrong spots, or just flat out doing it wrong.

Here's my room script:

Code: ags
// room script file

int num_systems;

function CreateSystem (int 25, bool keep_track = false, enDrawType draw_type = dtBackground, int width = 640 , int height = 480);

function emitter_creation_mode (int system, enRepeatMode rmAllways, int max_rep, int 40, int 2);


I know something is wrong, I just can't figure it out. Any help is greatly appreciated. :)

Here's what I'm using for Hitchhiker's

Code: ags


//I use the following part into a module.

ParticleSystemManager PS;
int wind_force_index;
float wind_force;



function ParticleEffects(int effect) {
if (effect==1) {//Smoke Effect
int s;    
s = PS.CreateSystem(240, false, dtBackground);
PS.emitter_creation_mode(s, rmAllways, 0, 1, 25);
PS.emitter_set_position(s, ptPoint,16.5, 41.0); 
PS.emitter_set_sprite (s, 931, 941);
PS.emitter_set_velocity (s, 10, 30, 270, 310);
PS.emitter_set_transparency (s, 71, 99);
PS.emitter_set_age (s, 100, 200);
wind_force = 1.5;
wind_force_index = PS.action_add_force (s, ftConstant, wind_force, 0.0);
PS.action_add_force (s, ftRandom, -2.0, 0.0, 2.0, 0.0);
PS.action_set_transparency_evolution (s, 100, 7); 
PS.action_set_bound_box (s, 0, 0, 320, 120);
}
if (effect==2) {//Wind Effect
int s;
s = PS.CreateSystem(100, false, dtBackground);
PS.emitter_set_sprite (s, 432, 435);
PS.action_set_bound_box (s, 0, 0, 320, 200);
PS.emitter_creation_mode (s, rmAllways, 0, 1, 10);
PS.emitter_set_velocity (s, 15, 20, 290, 320);
PS.action_add_force (s, ftConstant, 9.8, 0.0);
PS.emitter_set_position (s, ptBox, 0.0, 0.0, 320.0, 240.0);
PS.emitter_set_transparency (s, 45, 99);
PS.emitter_set_age (s, 0, 60);
}
if (effect==3) {//Explosion
int s;
s = PS.CreateSystem(350, false, dtBackground);
PS.emitter_set_sprite (s, 386, 388);
PS.emitter_creation_mode (s, rmNumberOfTimes, 1, 1, 350);
PS.action_set_bound_box (s, 0, 0, 640, 480);
PS.emitter_set_position (s, ptPoint, 80.0, 105.0);
PS.emitter_set_velocity (s, 10, 70, 0, 360);
PS.emitter_set_transparency (s, 20, 90);
PS.emitter_set_age (s, 200, 300);
PS.action_add_force (s, ftConstant, 0.0, 8.0);
}
}


//Inside a room's script I do this:

function room_Load() {
ParticleEffect(1);//Just once because the effect is already set to run constantly
}

//I use the following part of code to auto-remove particles when a room changes.
function on_event (EventType event, int data) {
if (event==eEventLeaveRoom) {
if ((data==11) || (data==23)|| (data==26)|| (data==36)|| (data==35)|| (data==34) || (data==28) || (data==19)) {// Rooms
while (PS.num_systems) {
PS.DeleteLastSystem();
}
}



Hope that helps a little.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

R4L

Thanks Dualnames. I'd rather not copy the code, because I'd like to figure it out myself and get back into coding, but it's confusing me too much. :)

Thanks again.

FrancoFranchi

Sorry for bumping an old thread, but does anyone have a mirror of this file (and the demo)?  Didn't realise AGS could do this and its given me some new inspirations.

Dualnames

#28
Not sure if I changed the demo or not. But here it as officially distributed:

http://www.mediafire.com/file/z3mtmy1wzhw/ParticleSystemManager.zip

EDIT: This is version 1.00 and not the last that Jerakeen distributed.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

cubehouse

I don't know what is up with this 2dadventures website, it's destroyed a load of plugins and modules.

Has anybody got the latest version? Or at least a clue how to fix the RawRestoreScreen() problem?

Calin Leafshade

i think you can actually just delete that line and everything still works

cubehouse

Quote from: Calin Leafshade on Mon 28/06/2010 18:16:06
i think you can actually just delete that line and everything still works

nah, it leaves trails of the particles behind - it needs to reload the original background before it redraws the particles on it (looks cool, but not my intended effect ;) )

cubehouse

#32
Ok, gave editing it a shot to update it to (I'm using 3.2, so can't confirm for other versions).

Basically, in the script, add this variable (below line "int num_systems;"):
Code: ags

DrawingSurface *orig;


Replace:
Code: ags

RawRestoreScreen ( );

With:
Code: ags

DrawingSurface *back = Room.GetDrawingSurfaceForBackground();
back.DrawSurface(orig);


Replace:
Code: ags

RawSaveScreen();

With:
Code: ags

orig = Room.GetDrawingSurfaceForBackground();
orig = orig.CreateCopy();

tzachs

Hi, this is an awesome module, with many functions, unfortunately it slowed down my character walk speed immensely so I won't be able to use it for my current game.

Anyways, just wanted to report what I believe to be a small bug.
In ParticlesSystem::Delete (), the following line should be added:
  num_sprites -= this.num_spr;

This will avoid crashing the game if it runs a lot of particle effects througout the game...

Joe

Quote from: tzachs on Mon 26/07/2010 22:34:57
unfortunately it slowed down my character walk speed immensely so I won't be able to use it for my current game.

I think if you activate the 'split resource files' option then your game won't slow that much.
Copinstar © Oficial Site

tzachs

Thanks for the suggestion, I tried 1Mb split, it may have improved a bit, I'm not quite sure, but it's still too slow...

AGD2

Sorry for the bump, but I was wondering if anyone knows how to get this module working so that the particle system gets drawn on to a dynamic sprite/drawing surface, which could then be displayed on a room object (so you could set baselines and have the particles disappear behind walkbehinds etc.)?

Sadly, even after implementing cubehouse's code in the above post, using s = PS.CreateSystem(300, false, dtSprite); will result in no particles showing up in the game. Any ideas? Thanks!

jerakeen

Hi, Right now i can't help with this. I don't remember  anything  about the module :sad:

in fact i hadn't read the whole post and i don't know if the old link is working, so here is the link to the last version i had.

Particle System Manager v0101

I hope it will useful to you.

i'm sorry i can't help.

bye

jerakeen

Pd. Give me some time, please, to upload again the examples and other files, and read and study them to see if i can help.
There was some time since i was in AGS world ...

AGD2

Excellent, thanks for the updated module, jerakeen! :)

Running this under the latest AGS 3.3.0 beta, there was an issue with all the particles being drawn as blue cups (default sprite) and it was also very slow. It was possible to work around this by replacing this line:

AllParticlesSystems[num_system].num_spr = max_slot - min_slot + 1;

With these two lines:

  AllParticlesSystems[num_system].num_spr = max_slot - min_slot;
  AllParticlesSystems[num_system].num_spr ++;


The included readme.txt file also brought my attention to the existence of this function:

QuoteDynamicSprite *GetSystemSprite (int system);

    Returns the sprite of the system if we draw on sprite or Overlay.
    We can use later this sprite in a Room's object so player can walk behind and
    in front of the system.

However, I can't figure out how to get that dynamic sprite showing on a room object. If I do this:

object[4].Graphic=PS.GetSystemSprite(s);

... it obviously doesn't work, so if you get a chance to look over it, that would be highly appreciated!

PS. The readme.txt also says " NOTE: Drawing particles transparent on a sprite or overlay doesn't work properly", but even if I set it to draw on dtSprite and set the particles transparency to 0, the particle system still doesn't visibly show in the game.


Monsieur OUXX

#40
I also found another bug. There seems to be an issue with function DrawingSurface.DrawImage(...) when the transparency given in parameter is 0. It crashes the game brutally, even in Debug mode.

The issue happens at this script line of the module :

Spoiler

Code: ags

surface.DrawImage (FloatToInt ( AllParticles[i].x ), FloatToInt ( AllParticles[i].y ), sprite.Graphic, AllParticles[i].transparency, width, height);

[close]

If you want to avoid the error, then simply make sure that the transparency is never exactly zero.
For example you can add those two lines of script just before the line causing the error :


Spoiler

Code: ags

if (AllParticles[i].transparency ==0)
    AllParticles[i].transparency = 1;

surface.DrawImage (FloatToInt ( AllParticles[i].x ), FloatToInt ( AllParticles[i].y ), sprite.Graphic, AllParticles[i].transparency, width, height);

[close]


==========

However the issue mentionned by AGD2 remains : Sprites are drawn as blue cups.



the issue was found, it's not caused by the module.
 

Crimson Wizard

#41
Quote from: Monsieur OUXX on Tue 25/03/2014 18:13:49
However the issue mentionned by AGD2 remains : Sprites are drawn as blue cups.


I do not observe this effect, particles are drawn as normal sprites for me.

My code:
Code: ags


function room_AfterFadeIn()
{
  ParticleSystemManager pm;
  int psys = pm.CreateSystem(100, false, dtOverlay);
  pm.emitter_creation_mode(psys, rmAllways, 100, 100, 5);
  pm.emitter_set_position(psys, ptCirle, 100.0, 50.0, 150.0);
  pm.emitter_set_sprite(psys, 0,  10);
  pm.emitter_set_age(psys, 100, 5000);
}


Also I have no problem with transparency being 0... In fact transparency = 0 is default value for DrawImage function.
Does it happen to you if you call DrawImage yourself?

Can you post example of initialization code that causes such effect?

Monsieur OUXX

#42
In the meantime I found the cause and it's really really stupid : DrawImage fails on backgrounds (with weird side effects) when you didn't explicitly set a background image for your room. I assumed the engine would just generate a black image. It doesn't. Any attempt to use the result of Room.GetDrawingSurfaceFromBackground() creates unpredictable effects.





==============
On a different topic :
Reupload of version 1.1 : http://www.adventuregamestudio.co.uk/forums/index.php?topic=50356.msg636486336#msg636486336


 

xil

Hey!

Just a quick question (it might be about dynamic sprites in general but I'm not sure).

I'm running a 320x180 game and want to generate particles onto a 640x360 dynamic sprite - is this possible? I can only seem to get it to generate particles in a 320x180 bounding box, no matter what values I change :(

It's almost like the particles can only ever generate within a box set to the 320x180 resolution? E.g If I start generating particles on my 640x360 sprite and then move it 100 pixels to the left, the particles will disappear 100 pixels before reaching the right side of the screen.

Code:
Code: ags

ParticleSystemManager PS;
DynamicSprite *sprStars;

function room_Load(){
  sprStars = DynamicSprite.Create(640, 360, true);
  
  s = PS.CreateSystem(300, false, dtSprite, 640, 360);
  
  PS.emitter_creation_mode (s, rmAllways, 0, 1, 1);
  PS.emitter_set_position (s, ptPoint, 160.0, 180.0);
  PS.emitter_set_velocity (s, 1, 3, 0, 360);
  PS.emitter_set_transparency (s, 0, 0);
  PS.emitter_set_age (s, 900, 900);
  PS.emitter_set_sprite (s, 11, 11);
  PS.emitter_set_scale (s, 100, 100);
  
  PS.action_set_bound_box (s, 0, 0, 320, 360);
  PS.action_add_force (s, ftParticleDirection, 0.3, 0.3);
  PS.action_set_scale_evolution (s, 100, 1);
}

function room_RepExec(){
  sprStars = PS.GetSystemSprite(0);
  oStars.Graphic = sprStars.Graphic;
}


Any ideas? I'm happy to provide a test game if anyone would be so kind as to have a look :)
Calico Reverie - Independent Game Development, Pixel Art & Other Stuff
Games: Mi - Starlit Grave - IAMJASON - Aractaur - blind to siberia - Wrong Channel - Memoriae - Point Of No Return

xil

I finally got a bit of time to investigate this properly and it seems as though it's just hard-coded into the module. On the off-chance that anyone else needs something similar to this weird behaviour, I have explained below where to edit/patch.

Line 784-787:

Code: ags

// if particle is on screen
if (FloatToInt (AllParticles[i].x) >= 0 && FloatToInt (AllParticles[i].x) < Room.Width &&
    FloatToInt (AllParticles[i].y) >= 0 && FloatToInt (AllParticles[i].y) < Room.Height)
{


For my purposes I just changed Room.Width and Room.Height to what I needed and voila, particles can be generated off screen so that when I move my object that I am rendering onto, they are shown without an issue. :)
Calico Reverie - Independent Game Development, Pixel Art & Other Stuff
Games: Mi - Starlit Grave - IAMJASON - Aractaur - blind to siberia - Wrong Channel - Memoriae - Point Of No Return

MyEakinBack

I'm so glad you figured this out. I'm have a feeling this is going to come in handy sometime.
completed: Beyond Eternity

Monsieur OUXX

Yes, this module has issues with scrolling backgrounds or anything bigger than 320x200, because it's hard-coded. Xil, it's a pity I saw your posts too late because I had corrected the issues in the version of this module that I use in my own game. I made other changes too, but xil if you have the opportunity you should upload your version of the module.
 

cat

#47
Hi!

I've tried this awesome module in Cogliostro's version and the effect looks awesome!

I just don't know how to stop if afterwards. I start the effect like this:

Code: ags

int s;    // system identifier
s = PS.CreateSystem(140, false, dtBackground);

PS.emitter_creation_mode (s, rmAllways, 0, 2, 1);
PS.emitter_set_position (s, ptPoint, 315.0, 95.0);
PS.emitter_set_velocity (s, 90, 140, 240, 300);
PS.emitter_set_age (s, 130, 140);
PS.emitter_set_sprite (s, 1, 1);
PS.emitter_set_scale(s, 50, 100);

PS.action_set_bound_box (s, 0, 0, 640, 270);
PS.action_add_force (s, ftConstant, 0.0, 9.8);  

WaitSeconds(4.0);

while (PS.num_systems)
{
   PS.DeleteLastSystem();
}


The problem is, that all sprites stay stuck on screen after the effect is ended. How can I remove them?

Edit:

Ok, I've added
Code: ags

PS.emitter_set_age (s, 0, 0);      
WaitSeconds(3.0);

before the cleanup. It looks better, but there is now still one sprite flickering at the origin. Is ist possible, to just turn it off and wait, until all sprites are gone?

Vincent

Hi, I am not sure if this could be helpful but you could try to check the particle transparency so far.

Code: ags

PS.emitter_set_transparency (s, 100, 100); 



Code: ags

PS.action_set_transparency_evolution (s, 100, 5); 


I hope it helps :)

cat


cat

Quote from: Vincent on Tue 12/04/2016 22:39:37
Code: ags

PS.emitter_set_transparency (s, 100, 100); 


Thanks, this did the trick! :)

Vincent

I am glad to hear that you've solved it. :)

Monsieur OUXX

If I recall, this module is not compatible with scrolling backgrounds, but it's rather easy to tweak to make it work, provided you know AGS well. It would be a good idea to post an update version. Also it's useful to replace the hard-coded width and height with System.ViewportWidth or such (forgot the exact name)
 

cat

This module has problems with multiple backgrounds. To solve this, you have to change the module script:

Replace every occurrence of
Code: ags

Room.GetDrawingSurfaceForBackground();

with
Code: ags

Room.GetDrawingSurfaceForBackground(GetBackgroundFrame());


I am setting the frame of the background in room_Load, which seems to happen after event == eEventEnterRoomBeforeFadein in the module. So, the frame was not set yet.
What I did to solve this, is adding the following function to the module:
Code: ags

function ParticleSystemManager::RefreshBackground ()
{
   orig = Room.GetDrawingSurfaceForBackground(GetBackgroundFrame());
   orig = orig.CreateCopy();
}

I call this after setting the background frame of the room.

Vincent

:@cat:

I had this issue for a long time but I never mentioned about it on this thread before.
I followed your instructions and it works wonderfully fine.
Thank you so much, I appreciated it very much.

The only thing that now remains to be pointed out is the fact that you can not change the background (repeatedly) without that all the particles remain on the screen... or probably somehow there could be a workaround to do that...

SMF spam blocked by CleanTalk