Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Optimizing strategy. guide; Optimizing yo shiz
Topic Started: Feb 7 2014, 12:33 AM (562 Views)
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
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:
Quote:
 
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:
 
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:
 
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:
 
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: click to toggle
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.
Edited by TheStolenbattenberg, Feb 8 2014, 11:52 PM.
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?
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
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.
Offline Profile Quote Post Goto Top
 
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
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?
Offline Profile Quote Post Goto Top
 
RonBurgundy
Member Avatar
Forum Borat
[ *  *  *  *  *  * ]
TheStolenbattenberg
Feb 7 2014, 12:33 AM

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:
 
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:
 
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:
Edited by RonBurgundy, Feb 8 2014, 06:05 AM.
!!! DEFEND POP PUNK !!!
Offline Profile Quote Post Goto Top
 
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
RonBurgundy
Feb 8 2014, 06:04 AM
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?
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
I think this topic would be more at home in the tutorials forum. Unfortunately I only have the power to delete topics.
Offline Profile Quote Post Goto Top
 
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
Despellanion
Feb 9 2014, 12:33 AM
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?
Offline Profile Quote Post Goto Top
 
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
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?
Offline Profile Quote Post Goto Top
 
luenardi
Member Avatar
Cofee Machines Rock
[ *  *  *  *  *  * ]
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.
Posted Image

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


www.recall.co.nr
Offline Profile Quote Post Goto Top
 
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
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:
 

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?
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
This code would never compile in any other language so I corrected it for you ;)

Code:
 

if(fps==room_speed)
{
alarm[0] = room_speed-(fps-1);
}else{
alarm[0] = max(room_speed-fps);
}
Offline Profile Quote Post Goto Top
 
TheStolenbattenberg
Member Avatar
Advanced Member
[ *  *  * ]
Thank you, I can't believe I made that mistake... xD

I normally always use syntax that's compatible with C++ where possible, I guess it's because I only woke up about 20 minutes before I wrote that.
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?
Offline Profile Quote Post Goto Top
 
Despellanion
Member Avatar
Forum God
[ *  *  *  *  *  * ]
TheStolenbattenberg
May 1 2014, 04:57 PM
Thank you, I can't believe I made that mistake... xD

I normally always use syntax that's compatible with C++ where possible, I guess it's because I only woke up about 20 minutes before I wrote that.
The code was correct in GML-terms, but not otherwise. It's still good practice to use correct code even though Game Maker doesn't know what correct code is.
Edited by Despellanion, May 1 2014, 05:27 PM.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Tutorials and examples · Next Topic »
Add Reply