Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a SceneGraph class which for now is just a simple list implementation, and the only optimization I've planned so far is a check is something like this:

//GetDistance returns the distance between 2 objects
float maxViewDistance = 10.0f;

for(int i = 0; i < sceneList.count; i++)
{
    if(GetDistance(sceneList[i], playerObject) < maxViewDistance)
    {
        Renderer.Draw(sceneList[i]);
    }
}

I plan on filling the SceneList when loading the game from a file which has a bunch of objectIDs and their positions, and then loading each object data (like .FBX, .BMP) somewhere (in another file). But since I don't intend on having loading screens (except when the game starts), wouldn't it become too much to iterate when drawing? For example if I have a sceneList with a million objects for the entire game, even if it's just checking an if for each objects, wouldn't that hurt performance?

I was thinking in making a sublist that will get populated only for the objects I'm currently drawing (that are less than the maxDistance I set), but then I'd need to update this subList everytime the player takes a step, and I'd need to check for all objects in my entire objectList to see which are going to be draw next, so I don't think it'll help anyhow.

Also, for physics, I was also iterating through my sceneList and forcing every object to my physics rules (only gravity for now), but if I add for collision checks, what's the best way to do it?

//Inside my game update function
for(int i = 0; i < sceneList.count; i++)
{
    UpdatePhysics(sceneList[i]);
}

[...]

void UpdatePhysics(Object* object)
{
    //I'd need to check for collisions against **all** objects inside my sceneList again? Isn't there a better way to do this?
}

How games such as WoW (open world with no loading screens between large amounts of zones) do? And for Physics, such as Deus Ex, where any object you throw in the air will be affected by gravity and will have collision against wherever is in it's path?

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.