|
-
Jan 2nd, 2003, 07:25 AM
#1
Thread Starter
New Member
Placing objects in a collection.
I'm programming a game now. I designed a small engine to make the programming of the game some faster.
I make a class, if I want to render a bird, I place the mesh into the object of that class. That object goes into a collection.
Another function renders the collections. But not all the objects have to be rendered all the time, because they are out the sight for example.
What is faster?
1. Placing all the objects that have to be rendered in another collection so the renderfunction renders the whole collection. I have to transfer objects from one collection to another often then.
Code:
Sub transfer()
for i = 1 to collection1.count
if calculatevisible(collection1.item(i)) then collection2.add collection1.item(i)
next i
End sub
Sub Render()
for j = 1 to collection2.count
collection2.item(j).render
next j
End sub
calculatevisible calculates that the object is in sight or not.
2. Or just adding a parameter to the objects so the renderer can see when it has to be rendered:
Code:
for i = 1 to collection.count
If collection.item(i).visible then collection.item(i).render
Next i
Last edited by Douchekop; Jan 2nd, 2003 at 10:03 AM.
-
Jan 2nd, 2003, 11:59 PM
#2
Frenzied Member
Changing that much objects around a collection might be too slow, I would go for the 2nd method. Why don't you try both and check the framerate to see if it's true?
-
Jan 3rd, 2003, 09:49 AM
#3
Addicted Member
You never want to render objects that aren't visible so that pretty much settles it.
-
Jan 3rd, 2003, 02:40 PM
#4
Thread Starter
New Member
@ Machaira: Both don't, so I don't understand your point.
I am not gonna check both systems because that takes a lot of time. From my point of view, the second way is faster so I will use that one...
-
Jan 4th, 2003, 03:21 PM
#5
Good Ol' Platypus
The 2nd method. A possible speed increase would come from using a visible parameter (as you have shown), and only calling calculatevisible when the object or screen has updated.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jan 4th, 2003, 03:33 PM
#6
Frenzied Member
Hmm, you could, for example, check only 20 or so ebjects each frame, so you wouldn't have to loop trough a lot of them which would decrease the game speed more than drawing a couple of objects that shouldn't be drawn... but that might cause an object that was supposed to be drawn to not be drawn (cuz we still haven't detected that iit's visible, it's visible but we still haven't checked it) so it may not be that good... what do you think Sas?
Hey, maybe we could merge both methods, having 2 arrays of Longs (indexes in the collection of objects) : one for visible objects and another one for invisible objects. Swapping indexes around wouldn't be as slow as adding/removing objects from an array and this way you could check if every invisible object is now visible, but not if every visible object is now invisible (like I said above, only check a few of them each frame). Or maybe I'm overcomplicating something really simple hehe
-
Jan 4th, 2003, 03:44 PM
#7
Frenzied Member
I still think that the best method would be having a grid, like a tile map, and each tile, or area, would have a number of objects. The only objects loaded and drawn are the ones in the player's area, and all areas adjacent to it (if you can see up to 3 or 4 areas in front of you, maybe you could load all the areas inside a radius of 3 or 4 areas around the player too, this way you could have smaller areas like 10 meters or something - loading a level would be extremelly fast and travelling trough the game world would be very smooth because loading new parts of the level, or completely new levels, was made progressively on the background with no need for progress bars saying "please wait, loading level").
Hmm, and if areas that were loaded and are no longer visible were not unloaded, but left in memory (still not visible of course), going back to other areas wouldn't require the game to access the disk again to load those areas again 
I know some games use this technique, so it's not new or anything, but still it's not that common, game developers usually prefer the level 1, level 2, etc aproach.
-
Jan 4th, 2003, 04:10 PM
#8
Good Ol' Platypus
The if statement is definately the bottleneck here (or the checkvisible - depends on when and the frequency it's called at).
I've thought of a way to draw this well. It's a software clipper. Is this game 2D? If it's not, you'll have to get into advanced topics like quadtrees and octtrees (maybe only 1 t). You draw every object, but you do it this way (pseudocode):
Code:
bool visi, visix, visiy
long int x, y, width, height
## filter out < 0 x and y
visix = not(abs(x) - x)
visiy = not(abs(y) - y)
## filter out > width x and > height y
visix = visix and not(x >= width)
visiy = visiy and not(y >= height)
## merge
visi = visix and visiy
## check
if visi then render()
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|