Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411488 Posts in 69377 Topics- by 58433 Members - Latest Member: Bohdan_Zoshchenko

April 29, 2024, 03:31:55 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Neutralising off-screen objects.
Pages: [1]
Print
Author Topic: Neutralising off-screen objects.  (Read 1575 times)
gunmaggot
Guest
« on: January 25, 2010, 02:44:07 AM »

I'm in the process of repurposing pgil's awesome GM pcg level builder and I've hit a snag:  When I converted sections of wall he'd designated as tiles into solid objects (I want them all to be destructable), this had the predictable result of making things run very slowly. 
One option I have is to make the level way smaller - I will probably make it smaller anyway - but I was wondering if there was some way of getting the program to forget about the blocks when they're out of sight ... maybe converting them to tiles? 
I know freezing enemies when they leave the viewing area is good practice when trying to free up resources - is there something like that which could help?  Thanks!
Logged
pgil
Guest
« Reply #1 on: January 25, 2010, 10:30:39 AM »

How are you disabling enemies? The easiest way to disable every object outside the view is to use this in the player's step event:

instance_deactivate_all(true)
instance_activate_region(view_xview[0]-32,view_yview[0]-32,width,height,true)

(replace bold stuff with your own values)

That deactivates all objects, then re-activates only the objects that are within the region you specify.

Usually it's a godd idea to give solid blocks a larger active area than everything else, so you might want to try this:


instance_deactivate_all(true)
instance_activate_region(view_xview[0]-32,view_yview[0]-32,width,height,true)
instance_activate_object(ob_block)
instance_deactivate_region(view_xview[0]-64,view_yview[0]-64,width+64,height+64,false,true)

(if you don't give blocks some extra active space, sometimes enemies can walk into the empty space of a deactivated block, just before being deactivated themselves, causing them to get stuck once the blocks are re-activated).

Sorry for the sloppy code. It should be right but i didn't test it, so check the manual or ask here if it's not working  Beer!
Logged
gunmaggot
Guest
« Reply #2 on: January 25, 2010, 05:39:26 PM »

Thanks for your help! Again!  The code works, for sure - it also massively speeds up the level generation process, which is a nice twofer.  The second piece of code improves the game speed a bit, but it still chugs a lot.  The first piece is smoother, but still spotty.  I can only imagine what it's going to be like when I add everything else ( Bangai-o

is the closest analog to the game I'm trying to make Sad ).

EDIT: When I bump up the room speed, things are back to being smooth (it was on 30, now it's 90).  I don't know what the potential repercussions of changing that could be, but they could be a pain - one idea I had for the scoring system awards points for how low the player can make the framerate go.  Would that matter?

EDIT 2: No matter how high I bump the room speed, the improved code with the wider buffer for the blocks runs slow.  I might have to add a little something to the enemy code to somehow make sure they don't get stuck in blocks.

I'll try deactivating all the ob_frees from inside the BUILD object because they're not doing anything outside that, but to be honest I can't think how - I believe I may be seriously getting ahead of myself here and need to properly learn GML before I can tackle this project or I'll just keep coming back here to code-beg. Sad
« Last Edit: January 25, 2010, 06:02:04 PM by gunmaggot » Logged
gunmaggot
Guest
« Reply #3 on: January 25, 2010, 11:16:38 PM »

Now, for whatever reason, the further the player object gets from its starting position, the quicker the game runs (I'm pretty sure that's what's happening here). I think I'll go and have a walk before getting back to it.
« Last Edit: January 25, 2010, 11:20:12 PM by gunmaggot » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic