Moderators: Despellanion, Dr. Best

Optimizing strategy. guide

TheStolenbattenberg
Advanced Member
TheStolenbattenberg
Advanced Member
Joined: 9:56 PM - Jan 14, 2013

10:33 PM - Feb 06, 2014 #1

I'll update this when I find new ways of getting the most out of U3D, for now there's this.

#1 - Step event optimizing:
More specifically, the function 'Step();'

Now, as far as I know, all Step(); does is resend variables, like x, y, z etc... But lets say the object doesn't move, it's static furniture or a building... Why would you need to waste processing on sending variables which it already has?

You don't. If the object doesn't move, take the Step(); function from the step event, and put it at the very end of the create event.

Comparason:
wrote:Room with 400 objects WITH pointless Step(); = 124FPS
Room with 400 objects WITHOUT pointless Step(); = 745FPS

This works with collision, and light sources appear to detect it too, and I think other things may be possible but you'll have to try one of the tactics below.

Okay, this is a good example of a way you can save in an object which can step but doesn't always need to: A door which can be locked/unlocked...

do something like this at the START of the step event:

Code: Select all

if(isLocked == true) { exit; }else
{
    //CODE IN HERE!
}
If you need something to always step, but it doesn't always need to be checked (lets say the function 'UpdateLightmap();' )
put it in a infinite - alarm, with the time set to one second or something.


#2 - Draw Text optimizing:
There was no need for a subtitle, but I wanted one.

Now this is an interesting one because it's not really obvious to everyone that it would be of any benefit., I used this a lot in normal 2D, and it was nice to recently find that it works good in U3D too.

If you're drawing a lot of text, you'll probably be doing it wrong. My guess is that you're doing it this way:

Code: Select all

DrawText(1, 2, 2,"FPS:"+string(fps), 0);
DrawText(1, 2, 2+16,"DMX:"+string(display_mouse_get_x()), 0);
DrawText(1, 2, 2+32,"WMX:"+string(window_mouse_get_x()), 0);
Well that's a horrible way of doing it, that's 3 seperate calls to DrawText, and when you're optimizing, every frame you can save is more graphics for you to play with!
This is a more efficient way you can draw multiple lines of text to the screen.

Code: Select all

DrawText( 
1,
2, 2,
"
FPS: " + string(fps) + "
DMX: " + string(display_mouse_get_x()) + "
WMX: " + string(window_mouse_get_x()) + "
",
0
);
Also You'll notice in that last one I tried to use as little characters as possible, that's because most text drawing functions in 3D, use 3D polygons with the letter assigned to them, for each letter. So the less characters, the better. If this isn't true for U3D someone tell me so I can edit this one, I'm just going from general knowledge. (EDIT: Turns out it does use polygons!)

I've not actually checked the performance increase, but in theory, having 1 draw call rather than 3, will be better, since you're not calling the DLL 3 separate times.

Although this isn't related to optimizing as such, using this way also means your line spaces will always be the same, and you can re-position them all at the same time.


#3 - Level Streaming:
The pros and cons, not how to do it

This one can be a little hard to set up, and I can't really explain a good or bad way to do it since it depends on the type of game you're going with.
The way I do it is by not placing a single object in the room, and letting my 'RoomControl' object do it all. in a game where you have rooms, with doors, you can check if the door is visible. You could also use portals, though I've never done that.

If you don't know what level streaming is, it's where you make the level load as you go, a lot of games on the PS1 did this, but the only game I can think to tell you of which I know executed this really well, is King's Field. They used level streaming in 1995, to make a fully 3D game, in reasonable quality, without loading.

I made some scripts which can help you setup a level streaming system, they're also made so you can combined them with the 'step event' optimizing told in #1.
[+] Spoiler

Code: Select all

/**instance_create_3d,
 * Arguments:
 * objectid, roomid,
 * x, y, z,
 * step
 */
var inst;
inst = instance_create(argument2,argument3,argument0);
inst.z = argument4;
if(argument5 == 1)
{
    with(inst) {SetObjectRoom(argument1); Step();}
}else{
    with(inst) {SetObjectRoom(argument1);}
}

return inst;

Code: Select all

/**instance_set_rotation,
 * Arguments:
 * instanceID,
 * rotx, roty, rotz
 */
with(argument0)
{
    rotx = argument1;
    roty = argument2;
    rotz = argument3;
    Step();
}
You don't have to give credit on those, it's not credit worthy.
Now that hopefully helped a little bit, though it's probably the least documented I'm going to write, because it should be obvious, it's more just scripts to help you.


#4 - Model Triangle and Vertices count:
This should be obvious...

U3D doesn't handle large amounts of triangles very well, so try and keep your models having low counts... You gotta ask your self some simple questions,
1) Do I need that sphere no one can actually see?
2) Does this wall need to be in 16 parts?
3) Can I use the same vertices to make this triangle?

If the answer to any of these is no, then fix it. If you take a look at my work in progress game called 'Seven' You'll see it's got a pretty nice looking level, would you be shocked if I told you that I only used 99 Triangles, and 153 Vertices, and that's not a square. The best advice I can give you is don't think that low poly has to mean it's crap, you can have awesome levels with detail if you don't waste your polygons on things like walls, which you should only need 2 triangles for (if there's no holes).

That's it for now, hopefully this will actually help someone rather than just bug people who already knew this.
Ashes to ashes, Dust to dust... Honor to glory; And iron to rust. Hate to bloodshed, From rise to fall... If I never have to die; Am I alive at all?
Quote
Like
Share

Despellanion
Forum God
Joined: 8:41 PM - Mar 26, 2006

11:14 PM - Feb 06, 2014 #2

Some good pointers. Probably obvious for most of us old timers around here, but very useful for beginners to U3D.
And yes, DrawText uses polygons.
Quote
Like
Share

TheStolenbattenberg
Advanced Member
TheStolenbattenberg
Advanced Member
Joined: 9:56 PM - Jan 14, 2013

11:29 PM - Feb 06, 2014 #3

I'm a slow learner myself, so I'm just starting to pull away from having to reference the manual every time I want to do simple stuff, and start to experiment more. Knew about using text for a long time, mostly because I used to optimize my 2D stuff so much it was getting hard to understand, heh. I thought about using step in that way myself when I was trying to sleep. Sucks having an active mind.

Thanks for clearing that up with the DrawText. I figured it did as much from when I was messing with DirectX a while back.
Ashes to ashes, Dust to dust... Honor to glory; And iron to rust. Hate to bloodshed, From rise to fall... If I never have to die; Am I alive at all?
Quote
Like
Share

RonBurgundy
Forum God
Joined: 9:49 PM - Sep 24, 2009

4:04 AM - Feb 08, 2014 #4

TheStolenbattenberg wrote: If you're drawing a lot of text, you'll probably be doing it wrong. My guess is that you're doing it this way:
[/color]

Code: Select all

DrawText(1, 2, 2,"FPS:"+string(fps), 0);
DrawText(1, 2, 2+16,"DMX:"+string(display_mouse_get_x()), 0);
DrawText(1, 2, 2+32,"WMX:"+string(window_mouse_get_x()), 0);
Well that's a horrible way of doing it, that's 3 seperate calls to DrawText, and when you're optimizing, every frame you can save is more graphics for you to play with!
This is a more efficient way you can draw multiple lines of text to the screen.

Code: Select all

DrawText( 
1,
2, 2,
"
FPS: " + string(fps) + "
DMX: " + string(display_mouse_get_x()) + "
WMX: " + string(window_mouse_get_x()) + "
",
0
);
Also You'll notice in that last one I tried to use as little characters as possible, that's because most text drawing functions in 3D, use 3D polygons with the letter assigned to them, for each letter. So the less characters, the better. If this isn't true for U3D someone tell me so I can edit this one, I'm just going from general knowledge. (EDIT: Turns out it does use polygons!)

I've not actually checked the performance increase, but in theory, having 1 draw call rather than 3, will be better, since you're not calling the DLL 3 separate times.

Although this isn't related to optimizing as such, using this way also means your line spaces will always be the same, and you can re-position them all at the same time.



That's it for now, hopefully this will actually help someone rather than just bug people who already knew this.
Wow ya know, I never thought of that nice! Of course we know making less calls to ultimate 3D is beneficial, however I definitely missed this so thanks for the tip! :thumb_up:
!!! DEFEND POP PUNK !!!
Quote
Like
Share

TheStolenbattenberg
Advanced Member
TheStolenbattenberg
Advanced Member
Joined: 9:56 PM - Jan 14, 2013

9:55 PM - Feb 08, 2014 #5

RonBurgundy wrote:Wow ya know, I never thought of that nice! Of course we know making less calls to ultimate 3D is beneficial, however I definitely missed this so thanks for the tip! :thumb_up:
No problem, I'm glad it was of use to someone!

---

I added some more stratagies to the top post, they're more game design tactics, and most probably already know them, but I wouldn't be surprised if a few don't.
There's also some scripts to help out with #3.
Ashes to ashes, Dust to dust... Honor to glory; And iron to rust. Hate to bloodshed, From rise to fall... If I never have to die; Am I alive at all?
Quote
Like
Share

Despellanion
Forum God
Joined: 8:41 PM - Mar 26, 2006

10:33 PM - Feb 08, 2014 #6

I think this topic would be more at home in the tutorials forum. Unfortunately I only have the power to delete topics.
Quote
Like
Share

TheStolenbattenberg
Advanced Member
TheStolenbattenberg
Advanced Member
Joined: 9:56 PM - Jan 14, 2013

1:13 AM - Feb 09, 2014 #7

Despellanion wrote:I think this topic would be more at home in the tutorials forum. Unfortunately I only have the power to delete topics.
I thought about that after I first posted it, but couldn't move it.
Ashes to ashes, Dust to dust... Honor to glory; And iron to rust. Hate to bloodshed, From rise to fall... If I never have to die; Am I alive at all?
Quote
Like
Share

TheStolenbattenberg
Advanced Member
TheStolenbattenberg
Advanced Member
Joined: 9:56 PM - Jan 14, 2013

2:28 PM - Feb 18, 2014 #8

Today I noticed the 'GetInstanceID' from ray tracing added in that small update doesn't work if you delete the instance after U3D loads it, since it uses Game Maker object IDs. I've created a way to work around that, although a little hacked. I'll post it later.
Ashes to ashes, Dust to dust... Honor to glory; And iron to rust. Hate to bloodshed, From rise to fall... If I never have to die; Am I alive at all?
Quote
Like
Share

luenardi
Forum God
luenardi
Forum God
Joined: 8:53 PM - Dec 29, 2007

8:20 AM - Apr 15, 2014 #9

As soon as I get or find a version of GM that runs on win 8.1 without much hassle I will dive into the details of optimizing code and so on.

For your perception no.
But my universe has no such limits.


www.recall.co.nr
Quote
Like
Share

TheStolenbattenberg
Advanced Member
TheStolenbattenberg
Advanced Member
Joined: 9:56 PM - Jan 14, 2013

1:42 PM - May 01, 2014 #10

I was messing around today while creating a more advanced API for U3D, and stumbled upon a way to create some basic frame skipping in all version of GM U3D supports (though I might be able to make a better version for studio).

Here's the steps,

First, in your control object, remove the external call to u3d render, and place it in alarm[0].
In the create event, set the alarm trigger to 1.

At the end of alarm[0], place this.

Code: Select all

if(fps=room_speed)
{
    alarm[0] = room_speed-(fps-1)
}else{
    alarm[0] = max(room_speed-fps)
}
I've tested this and it works pretty good, but it's advised to keep your games FPS at no more than 60, or when it skips frames, it'll look really bad.
Try checking if your FPS is below 60 if you want higher, then only using frame-skipping if it is.

Enjoy!
Ashes to ashes, Dust to dust... Honor to glory; And iron to rust. Hate to bloodshed, From rise to fall... If I never have to die; Am I alive at all?
Quote
Like
Share