Many actors but is a RTS

Usernoob

  • Posts: 27
Hi, long time without trying to making games.

Im trying to make a "Real Time Strategy" game, but i have a (maybe) the typical problem.

When the game have 100 or more actors the FPS go slow.

I change all the "updating" events to "do every 0.05 seconds" that help, but
is not sufficient.

All is simple graphics and only have a draw event thats draw the green bar of life (and other draw event for the minimap )

only 1 room/scene at moment, 16.000 x 8000 pixels

The actors are all always active ,because i need the enemy's workers farming and soldiers patrols out of the screen.
Maybe is for the minimap that create points of green or red for each enemy or ally unit.

Units (only allies at the moment) have each one a weapon that its "fixed" in the unit, can be this the cause? (is the only updating event)

IIt's hard imagine how to create a game like "starcraft" or "command and conquer" whit maybe 100, 200 or 500 actors.

Anyway, it's only a hobby.

merrak

  • *
  • Posts: 2521
100 doesn't seem like a lot. I routinely go into the hundreds and thousands and my actors are doing a lot more than what you described.

There are a lot of reasons you might be getting lag. The good news is there is almost always a solution. The bad news is you have to pinpoint the problem first. hxScout is a good tool for this purpose, but there's a bit of a learning curve to it.

Starcraft required a Pentium 90 MHz and 16MB of RAM. A lot of these kinds of speed issues have less to do with how fast the computer is and more to do with how well your code is optimized.

JeffreyDriver

  • *
  • Posts: 2163
Have you removed any collision shapes you don't need?  Lots of simultaneous collisions is a common cause of lag. Even if you think you do need collision shapes, look at a workaround. Should be quite easy for a rts.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

squeeb

  • Posts: 1554
Have you removed any collision shapes you don't need?  Lots of simultaneous collisions is a common cause of lag. Even if you think you do need collision shapes, look at a workaround. Should be quite easy for a rts.
Ahh.. good to know.. you mean if there are many things hitting each other at the same time can cause lag?

LIBERADO

  • *
  • Posts: 2660
@Usernoob, in the Game Settings, select the Simple Physics mode.
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

vicevicebingo

  • Posts: 58
Have you removed any collision shapes you don't need?  Lots of simultaneous collisions is a common cause of lag. Even if you think you do need collision shapes, look at a workaround. Should be quite easy for a rts.
http://www.stencyl.com/game/play/23202

But for someone wants to make collision to tile/terrain
better just go to sleep

Usernoob

  • Posts: 27
Good morning, thank for the answers.

Q: Have you removed any collision shapes you don't need?  Lots of simultaneous collisions is a common cause of lag. Even if you think you do need collision shapes, look at a workaround. Should be quite easy for a rts.

A: Yes, the units only have a collision whit ally ammo (bullets, misils) the game have 4 types of actors:
Ally (only colides whit enemy bullets)
Enemy (only colides whit ally bullets)
enemy bullets (sensor)
ally bullets (sensor)

Q: @Usernoob, in the Game Settings, select the Simple Physics mode.

A: Is already selected


Q: But for someone wants to make collision to tile/terrain
better just go to sleep

A: No tiles allready, just a scene to create and test units.

If i have time today i upload the "game" to show the problems.

Bombini

  • *
  • Posts: 1316
My guess would be that the drawing of the lifebars is the issue.

JeffreyDriver

  • *
  • Posts: 2163
Have you removed any collision shapes you don't need?  Lots of simultaneous collisions is a common cause of lag. Even if you think you do need collision shapes, look at a workaround. Should be quite easy for a rts.
Ahh.. good to know.. you mean if there are many things hitting each other at the same time can cause lag?

Yeah. If you experience lag it's a good place to start looking.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

vicevicebingo

  • Posts: 58

« Last Edit: September 10, 2018, 02:50:22 am by vicevicebingo »

Bombini

  • *
  • Posts: 1316
Have you removed any collision shapes you don't need?  Lots of simultaneous collisions is a common cause of lag. Even if you think you do need collision shapes, look at a workaround. Should be quite easy for a rts.

Lets dig a bit deeper on this one. Which ideas do you guys have to avoid collisions?
Obviously you can work with coordinates (example: bullet has similar coordinate like target to deal damage) but this only works with actors and not with tiles (in case the bullet should not go through tile because you cannot check if a specific tile has similar coordinates like target.

Other ideas?

Usernoob

  • Posts: 27
I have 2 ideas for a possible solution:

Option A: no bullets, no collisions. If a unit is in range the unit just damage the enemy unit ant the enemy loses life. And animation of shooting at same times.
Is like the marines of starcraft.
The bad thing is, units cant dodge, fast units loss one of his skills

Option 2: No collisions, if the bullet is too close to the enemy the bullet is destroyed and the enemy loses life.

The bad thing is, in need a list global atribute per any bullet type, or any kind of bullet have the same damage and maybe this is too slow, is lke if the actors have a circle shape collision.

I just got home, I'll try these things now if I can.

Thanks you all.

Usernoob

  • Posts: 27

Hello people, maybe it took me a long time to answer, but finally I found the problem.

All the actors have a "for each actor of group" and each unit compares its distance with ALL the units of the enemy side and the same with the enemy.

So when you have 200 units and 200 enemies each of your units has to do 200 operations, if you have 200 units it is 40.000 operations and another 40.000 for those of the enemy.

The solution would be not to calculate those of all the enemies but only the closest ones. How I do this?

With regions? Or the regioes also calculate all the actors of the group or type that you put them?

Possibly I start the project from  the begining, maybe this post helps someone.

PS: if instead of 200 enemies and 200 allies I only have 400 allies and 1-20 enemies the game works

JeffreyDriver

  • *
  • Posts: 2163
Easy Math extension. Search for 'Easy math'. It let you easily get the distance between actors. You can also use Pythagorean theorem using existing blocks in Stencyl.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

merrak

  • *
  • Posts: 2521
So when you have 200 units and 200 enemies each of your units has to do 200 operations, if you have 200 units it is 40.000 operations and another 40.000 for those of the enemy.

The number of floating point operations per second (FLOPS) a modern processor can handle is measured in the billions. I looked up a few processors and figured tens of billions is a good estimate. If you divide by 1,000 to get floating point operations per millisecond, you should be able to handle tens millions. To get 60 FPS you also have 16 milliseconds per frame to work with. While 80,000 operations sounds like a lot (rather, hundreds of thousands because you have to count each arithmetic step as a separate operation), it's really not. There's got to be more to this story.

Collision detection on the scale you're working at creates a lot of garbage... mainly in the form of vector class instances. If you've deduced that collision detection is the issue, and your game runs fine otherwise, then I'd expect garbage collection to be the culprit. One of the characteristics of this kind of lag is the game stutters--runs smoothly for a moment or two, then freezes for a bit... repeat. If you've noticed that, then that stutter is most likely the garbage collector doing its thing. Unfortunately, there's not a whole lot of easy fixes you can apply. The good solutions will require clever optimization of which collisions to check.

The good news is you don't need physics. Using Box2D to handle collisions in your case is like using a chainsaw to cut a slice of cheese. You're paying for features you're not going to use.

JeffreyDriver's suggestion sounds like the perfect solution to me. Using math with basic data types will cut out the garbage issue entirely. If you're using Stencyl 3.4, though, you might need to use code blocks (the ones in the 'advanced' tab that let you type code) to perform arithmetic. If I remember correctly, using the number attribute blocks and the math blocks creates code you don't need.

It's been a while since I've used older versions of Stencyl, so I might not be remembering right. Check the code that is created by your blocks by clicking on the "preview code" tab. If you see a lot of calls to a function "propertyChanged", then you'll need to cut those out. Most of the time their effect is negligible, but you're doing enough math that it's worth the effort to take them out. You can do that by typing the math operations yourself and setting attribute values using typed code--not using the math blocks or "set attribute to value" blocks.

I don't see this issue in my code using Stencyl 3.5... so if you're using the beta it's probably a non-issue entirely. In that case, just use the blocks if you prefer.

« Last Edit: September 25, 2018, 05:35:46 pm by merrak »