Results 1 to 8 of 8

Thread: Placing objects in a collection.

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    Netherlands
    Posts
    12

    Question 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.

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    You never want to render objects that aren't visible so that pretty much settles it.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    Netherlands
    Posts
    12
    @ 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...

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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
  •  



Click Here to Expand Forum to Full Width