Jump to content


Photo

Activating objects/region


  • Please log in to reply
7 replies to this topic

#1 Znyx

Znyx

    GMC Member

  • New Member
  • 56 posts
  • Version:Unknown

Posted 30 December 2011 - 11:22 AM

I hope this is the right forum...

Anyways im making an game with randomly generated worlds and i found out when i generate very large worlds(24.500x24.500 pixels) i get ALOT of fps drop when i play(The larger the room, the larger the fps drop!). First i thought it was a flaw in my engine itself but after like an hour of testing/experimenting if found out the thief of the fps drop was unexpectingly the instance_activate_object() and instance_activate_region().

Im using an alarm to every secound activate the instances so every sec my fps drops below 30 which in turn is a really "choppy" gameplay lol.
When i increase the alarm to say 10 sec i get the fps drop once each 10 sec so it has to be that function that is slow...
  • 0

#2

  • Guests

Posted 30 December 2011 - 07:37 PM

Just how many instances are you creating, and activating/deactivating all the time?

#3 DanRedux

DanRedux

    GMC Member

  • GMC Member
  • 1403 posts
  • Version:GM:Studio

Posted 30 December 2011 - 08:52 PM

These functions deter fps drops, but are not a barrier to them.

You should ALWAYS be combining solids with nearby solids. Every 30x30 grid of solid blocks should be combined into a single, large sprite with precise collisions on.
  • 0

#4 Znyx

Znyx

    GMC Member

  • New Member
  • 56 posts
  • Version:Unknown

Posted 31 December 2011 - 12:32 AM

Just how many instances are you creating, and activating/deactivating all the time?


On the biggest map i allow the player to create it have around 200.000 - 250.000 instances but no more than 100-200 is active at the same time, and i dont activate/deactivate each step i have an alarm set to 30 (1 sec).
Each time it updates i get huge fps drops. From around 200fps -> 25
Also in that alarm im activating 2 regions and 4 objects, and i dont get noticible drops on smaller maps.
  • 0

#5

  • Guests

Posted 31 December 2011 - 06:29 PM

ouch.... Remember, every time you activate a a "region", it has to check every instance to see if it's IN that region. That's a LOT to check. I wouldn't even bother creating them until I needed them, then kill them off once you're done with them.

Break the world up into screens/regions/buckets. And as you enter a bucket, start the creation of instances - you needed do them all at once, do a few a frame. Same for deletion.

#6 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1909 posts
  • Version:GM:Studio

Posted 31 December 2011 - 06:50 PM

These functions deter fps drops, but are not a barrier to them.

You should ALWAYS be combining solids with nearby solids. Every 30x30 grid of solid blocks should be combined into a single, large sprite with precise collisions on.


I'm not doubting you, and not to derail the topic, but I have a question about this I had actually posted a topic for. Is this tested? I'm sure if all the original solids were using precise collisions it would be guaranteed faster, but if they were using bounding boxes, is it the same. What's faster a few hundred bounding box tests are one MASSIVE pixel perfect test?

Back on topic... if you are generating this world at run-time, it is probably a safe bet it is somehow grid-based. Could you convert it to not even work with objects directly, rather a massive array(or group of arrays). That is bound to be faster than using objects, whether you combined then or not.
  • 0

#7 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 8105 posts
  • Version:GM:Studio

Posted 31 December 2011 - 09:20 PM

People need to re-think how they do things in GM:HTML5, compared to how they did things in GM:Windows.

Activating/deactivating is one of those things.

With GM:Windows, if you had a lot of instances and each of those instances had a lot of interpreted GML then the cost of running compiled activate/deactivate instructions is minor compared to the savings of not running the deactivated interpreted code within each of the deactivated instances.

With GM:HTML5 there no longer is the compiled runner functions vs the interpreted GML gain/loss.

Our GML gets converted to javascript and has the same potential performance as the YYG's supplied "runner" code.

This doesn't mean that deactivating instances might not offer potential speed gains, but the cost of activating/deactivating is much higher relative to the savings. Things like this will be a huge consideration for porting to HTML5 and future versions of GM.

[EDIT] Didn't notice this post was in GM8.1.

Edited by NakedPaulToast, 31 December 2011 - 09:28 PM.

  • 0

#8 Znyx

Znyx

    GMC Member

  • New Member
  • 56 posts
  • Version:Unknown

Posted 01 January 2012 - 03:21 PM

Thanks, that explained what i needed to know. Im rewriting the engine to generate chunks of objects on the fly. By only adding this to the water objects i reduced the instances with like 50% and the game runs a lots faster now :D Though the codes needs some tweaking and such and later to be added for more objects.

Thanks alot this saved me the project!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users