Draw event- what is more efficient?

L

LV154

Guest
I've been developing a top down shooter with 3D buildings and each object had its own draw event. After reading advice on optimising performance it seems that the less draw events called, the better. So I did exactly that, created a building_drawer_obj and placed all the draw commands for all 3D buildings into one draw event.

I don't know whether this was a very stupid thing to do because many objects are deactivated when outside the view. As far as I know this includes the building objects and so their draw events aren't called and gamemaker has to process through less code at a time. The building_drawer_obj is activated and so code that calls for a deactivated building to be drawn seems rather sloppy.

I wanted to ask for some input from members who understand how gamemaker works and executes code better than I do (I know next to nothing in that area).. Would it be best to move specific pieces of code back to their native objects, or keep it in one big draw event?
 

Simon Gust

Member
If you have it like this
Code:
with (object)
{
  // draw stuff
}
Any instances that are inactive should not run their with().
Alternatively you could instead of deactivating objects, mark them as invisible and their draw event will also not be run.
 

sylvain_l

Member
you could go even "kinkier" than what @Simon Gust suggest by splitting the drawing to avoid texture swap. (batching is often already a good point in that way, but somtimes you can go further)

If you have your assets split onto more than one texture page (also count if you are using surfaces for any puprose at one point). You want to limit as much as you can texture swaps (if any of your object draw imply a swap). So as much as respecting depth of each drawn object allow you could gain potentially some extra doing something like;

Code:
with (object)
{
  // draw stuff that use the same texture page 1
}
//than do another pass
with (object)
{
  // you get only one swap for first draw that change to the texture page 2 than
// all the draw stuff that use the same texture page 2 is drawn without additionnal texture swap :)
}

of course, first rule is to reorganize the content of your texture pages to avoid if possible the use of such convoluted technic
 

Yal

šŸ§ *penguin noises*
GMC Elder
  • Deactivated objects basically don't exist, they won't run any code and with-loops will skip over them. (with loops basically goes through a list of all active objects, inactive objects are moved to a different list)
  • The draw event is skipped altogether if an instance is not visible, but if it's visible but off-screen the draw event is run as normally (since you can potentially draw stuff anywhere and there's no easy way for GM to check if it's gonna be possible to see something in the view or not)
  • The main resource hog when doing 3D drawing usually is the CPU telling the GPU what to do, this gets a lot faster if you use models rather than drawing every wall/floor using d3d_draw_* functions since the model is stored in the GPU's memory so you don't need to transfer tons of vertex data 60 times per second. It might even be faster to add ALL the buildings to a 3D model at room start and then draw that than to deactivate buildings and draw them piecemeal.
  • If you use models, only create them once and then use the same model throughout - if you recreate it each step you lose the speed benefit the model would've given you.
I hope this answers your questions, tell me if I missed something :p
 
Top