Grid Sage Forums

Grid Sage Forums

  • January 16, 2018, 12:58:00 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search

News:

LINKS: Website | Steam | Wiki

Author Topic: Particle system implementation  (Read 101 times)

gilaseshud

  • Unaware
  • *
  • Posts: 1
    • View Profile
Particle system implementation
« on: December 27, 2017, 06:09:36 PM »

Hello everyone,

I'm trying to make a roguelike with an SDL-based terminal emulator much like what Cogmind uses. I really like how Cogmind uses UI animations, particles, and such to spice up what would otherwise just be static ASCII, so I've been trying to produce a similar system myself — albeit a much more basic version, obviously. I've read all of Kyzrati's dev writeups on the particle system that I can find, but I'd still like to understand further and I'm curious if anyone here knows anything more about it, or knows of other resources I could consult.

My understanding so far is as follows --- not sure if I'm right about all this, though.
* Based on this dev post, it seems that each particle in a system is a discrete object (i.e. "array of structs" rather than "struct of arrays" as I've seen in some particle systems).
* Since particles can do damage to other game objects they bump into, they are proper game objects, rather than just a graphical overlay.
* According to this lecture, the particle grid is finer than the visible game grid, with a 3x3 square of particle tiles per 1 game tile. Colors are blended into the game tiles to produce a smoother effect.

Right now I have two major questions. Firstly, how are particles used to produce interface animations? I can understand explosions, lasers, etc., but I'm curious how, for instance, the effect of tracing out the borders of UI windows is produced using the same system. I presume at a basic level it's just blending the interface elements with particle colors, but I don't know how the underlying particle systems would be structured.

Secondly, how much of a performance drain is a particle system like this? I've read in various places that Cogmind can use hundreds of particle systems simultaneously, which I presume means at least tens of thousands of particles. Is the amount high enough that you'd have to end up micromanaging things like memory locality? I want to make a realtime roguelike, and I wonder if high-resolution particles would cause too much slowdown in that case.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 2724
    • View Profile
    • Cogmind
Re: Particle system implementation
« Reply #1 on: December 29, 2017, 04:05:52 AM »

Welcome gilaseshud!

Not sure if you've checked out r/RoguelikeDev yet, but there are a lot of resources there in general, including our FAQ on animation systems (also #2).

For reference, I know a few devs have worked on something similar, or are doing so now, including for example rm-code (who hangs out in the r/Roguelikes Discord #roguelikedev channel) (github), and flagsdev, who unfortunately quit his Reactor 3 project years ago but he uses a nice particle system, too.

Honestly other people can do particles better than I can (my system is pretty hackish and limited compared to "proper" systems) so I don't really talk about the gritty details anywhere. All I did was get my basic understanding from online particle system tutorials, then apply that to the concept of having a finer grid than the main terminal display (so the particles move more smoothly), but even that concept actually came from X-Com: UFO Defense, based on their projectile collision implementation. I did projectiles shortly before deciding I needed some way to animate them. So my original purposes here was to simply draw some dots and lines moving around, but then I realized all the possibilities this system could have... and scripts were born...

You could very easily say I lucked into this whole thing :)

Particles are definitely objects and can collide with other objects, again just like the "LOFTEMPS.DAT" thing linked above. Specific to your questions:

1. Good question, though the answer is "pretty much the same way." All particles are controlled by scripts, the main difference in UI scripts being their particles can leave behind their color and style permanently. My weapon and UI particle scripts are so similar I can swap them between each other's system with little modification! The underlying systems don't have many other differences--they both just manage particle objects using variables like direction, speed, color, lifetime, etc. Other than the ability to leave behind their visible properties, UI particles also have no checks for collision with other objects (so they're even faster).

2. Tens of thousands of particles is enough for my purposes (yeah I get up in those numbers sometimes), though honestly I do my projectiles in the CPU, and if you're making a real-time game you're going to want to do all this rendering stuff on the GPU where it'll be much faster. There you could get way more particles without issue, it's just all beyond me so I stick to simple stuff. If you're looking to do "hi-res" stuff, GPU (and shaders, I presume) is the way to go. My method works specifically because it's low-res :P

Answer your questions? Still though, I think you'll be wanted to look for better solutions elsewhere if you're going real-time...
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames

zxc

  • Cogmind
  • *****
  • 1st place in the High Scores category during Alpha Challenge 2015 1st place in the Best Escapes category during Alpha Challenge 2015 Shared a Confirmed Combat Win Shared a Confirmed Stealth Win Bug Hunter Achievement leader in at least one category during Alpha Challenge 2015 Participated in the Alpha Challenge 2015 Wiki Contributor Weekly Seed Participant
  • Posts: 613
    • View Profile
Re: Particle system implementation
« Reply #2 on: December 30, 2017, 11:12:23 AM »

Luck? Yeah... I'm definitely gonna believe that...
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 2724
    • View Profile
    • Cogmind
Re: Particle system implementation
« Reply #3 on: December 30, 2017, 05:57:25 PM »

Haha no really! It just "happened." I didn't have the goal of creating anything like this particle system, i.e. imagining it beforehand, I just wanted to move some dots and colors around for bullets like I'd seen in other roguelikes and if I hadn't already been using the X-Com architecture (learned from UFOpaedia) it never would've looked as good as it does. Something like that was beyond what I could come up with myself.

You should see my earlier pre-X@COM projects, I've always been really bad at programming any visual stuff, but once I have an architecture in place I'm fairly good at designing with it.
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames