• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

My 3D game is lagging with large rooms, even when they're completely empty

D

Daniel2210

Guest
I started working on my first ever 3D game a couple of days ago. Things were going pretty well until I started making the first room. It was a 5000x5000 room with 64x64 blocks composing the entire floor, so when I started up the game and noticed how bad the lag was, I thought it was just because I had so many instances running at one time. I added code that deactivated all instances that were 500 pixels away from the player, but the game still ran at around 10 FPS. After a lot of experimenting, I found out the lag had to do with the size of the room. I shrunk it down to 1000x1000 and the game ran at a comfortable 45-60 FPS. My suspicions about room size slowing down the game were confirmed when I placed only 5 instances in a 5000x5000 room and the game still ran at an unplayable 10 FPS.

Is there any way to counteract this, or am I forced to make my game with a series of rooms no bigger than 1000x1000? Any help would be appreciated.
 
D

Daniel2210

Guest
By that, do you mean the draw_set_projection line of code? If so, here it is: d3d_set_projection(x,y,z,x+100,y+100,z,0,0,1)
 

johnwo

Member
By that, do you mean the draw_set_projection line of code?
No, it's set with d3d_set_projection_ext(xfrom, yfrom, zfrom, xto, yto, zto, xup, yup, zup, angle, aspect, znear, zfar).
Also, make sure to use d3d_set_hidden(enable) and d3d_set_culling(enable).
Should the problem persist, use the debugger's Profiler to find CPU intensive code, then deal with it from there.

Best of luck!
 

FrostyCat

Redemption Seeker
So it never came to you that re-evaluating all of those instances for activation/deactivation is expensive? That could have easily offset the computational savings from not evaluating events in deactivated instances. You are stealing from Peter to pay Paul.
 
L

lovareth

Guest
@Roa yeah if Daniel2210 didn't using views, his game is currently draw in 5000x5000 pixels which is too much HD. correct me if im wrong
 
D

Daniel2210

Guest
@Roa yeah if Daniel2210 didn't using views, his game is currently draw in 5000x5000 pixels which is too much HD. correct me if im wrong
I've tried activating views, but when I start the game I just go to a black screen. I assume 3D views are different than 2D ones. Could anyone give me some guidance with this? I really appreciate all the answers and help so far.

So it never came to you that re-evaluating all of those instances for activation/deactivation is expensive? That could have easily offset the computational savings from not evaluating events in deactivated instances. You are stealing from Peter to pay Paul.
I said in my post the problem wasn't the amount of memory being used by the objects, but rather the size of the room. I could get rid of the deactivation code and the game would still run at the same FPS.
 

Roa

Member
yeah, instance activation is not that costly at all if you do it right, in CPU time that is.

But uhh.... did you try setting the draw color to white? That will eliminate the default black vertex colors from everything.
 

Roa

Member
Did you turn on 3d and do the basic stuff?

Code:
d3d_start();
d3d_set_texture_repeat(1);
draw_set_color(c_white);
oops, double post lol
 
D

Daniel2210

Guest
yeah, instance activation is not that costly at all if you do it right, in CPU time that is.

But uhh.... did you try setting the draw color to white? That will eliminate the default black vertex colors from everything.
Yeah, I'm already doing that. Do you know if there's any way to do views in 3D? I feel like that might be the problem.

Did you turn on 3d and do the basic stuff?

Code:
d3d_start();
d3d_set_texture_repeat(1);
draw_set_color(c_white);
oops, double post lol
I added the set_texture_repeat(1) code to the game and it's still laggy. :( I appreciate all the help you're giving me, though.
 
D

Daniel2210

Guest
Hmm, well I guess I'll start experimenting and see what I'm doing wrong with them, then. Thank you for your help, Roa!
 
L

lovareth

Guest
Hmm activating views doesn't make my game goes black so far.. I made some quick experiment with my 3d game. The 1st loaded room will become the default resolution of your game. You can try to resize your 1st room into smaller size like 640x480 or smaller.. By the way, i tried to change my 1st room into 10000x10000 and the game goes black haha.

Edit: Is your 1st room is the 3d room?
 

Roa

Member
If you want, you can PM me the source and I will take a look at it. I pretty much stay in 3d, so I know how to run through it and debug super quick.
 

FrostyCat

Redemption Seeker
I said in my post the problem wasn't the amount of memory being used by the objects, but rather the size of the room. I could get rid of the deactivation code and the game would still run at the same FPS.
But your room has a direct influence on the number of floor tile instances, and that's the problem you should be concerned about.

To tile a 5000x5000 room with 64x64 tile instances, you need ceil(5000/64)^2 = 6241 of them. But with a 1000x1000 room, you only need ceil(1000/64)^2 = 256. This is a huge 24-fold discrepancy in computational load.

And how would getting rid of the deactivation code help? That just replaces the albatross of evaluating 6241 floor tiles every step for activation with the albatross of 6241 floor tiles calling their draw events every step. This is what I mean by "stealing from Peter to pay Paul".

The only way you can make this work is to stop swarming the room with instances. Instead, use what Roa taught you to draw one floor with a repeating texture (see: texture_set_repeat()). Draw it only large enough for the player to not see the edge.
 
R

R34LD34L

Guest
Thats alot of stuff i hope your not using gamemaker's d3d stuff, and backface culling + hidden surface removal will help alongside going into the global game settings and changing interpolation to false, changing your texture page to 256x and putting your sleep margin at 30, oh and vertex buffers set to fast. If you wanna get a little bit more fancy you could make use of delta timing and frame skipping :eek:
 
F

F_Clowder

Guest
[...]To tile a 5000x5000 room with 64x64 tile instances, you need ceil(5000/64)^2 = 6241 of them. But with a 1000x1000 room, you only need ceil(1000/64)^2 = 256. This is a huge 24-fold discrepancy in computational load.[...]
This I understand. But why is the OP then still experiencing the issue with only 5 instances at 5000x5000?

[...] My suspicions about room size slowing down the game were confirmed when I placed only 5 instances in a 5000x5000 room and the game still ran at an unplayable 10 FPS.[...]
 
D

Daniel2210

Guest
I messed around with the view parameters for a few minutes and somehow got it working. The game runs at a smooth 45-60 FPS even with the entire room covered with 64x64 objects. I'm kind of embarrassed the problem was something so trivial. I apologize if I wasted everyone's time. XD It's really awesome to know there's so many people who are eagerly willing to help a noob like me out with their problems, though. I don't want to waste anyone's time like this again, so if any of you know of a good 3D learning resource, could you please link it to me? Thanks again, everyone. :D
 
Top