Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualserumas

Posted 23 April 2013 - 04:03 AM

All found grid implementations I found, even in book are damw far away from perfectness

After lots of optimizations and experiments I found routine that works finiest and its stil on optimizations

but main loop would look like this:

 

loop
{

//objects update
for(all objects)  //dead,alive, and waiting to be inserted in game world
{
     if(obj.is_dead()){delete obj;continue;}
     if(obj.mut_insert())obj.set_acative();
     if(obj.active)
     {	
        obj.move_object();
        obj.find_bounding_box();
        bool update = obj.find_out_does_it_needs_to_be_updated_in_grid(); //not accessing grid data, maybe tricky or very easy, it depends
        if(update)
        {
            obj.update_id++;
            grid.add(obj);
        }
    }
}
//grid update and collisions
for(all cells in grid)
{
     for(all objects in cell)
     {
          if(cell_obj->obj->update_id!=cell_obj->update_id)delete cell_obj; //delete all elements with old id's
          
     }
     sort_cell_objects_by_box_left_up_corner_x(cell);
     do_collision_like_sweep_and_prune(cell);//with some tricks its easy to avoid dublicate checks so we dont need to check neighbur cells so even object size differences do not mater
}

}

So its main simple main loop.

Some of optimization could be done for example:

do cell objects delete sort and check for collision in one loop  (possible allmost done)

find bounding box without resuming all object vectors (done with only 2 vectors)

object insertation could be done in grid.collision routine() becouse on insert you must check if it lands on free space


#4serumas

Posted 23 April 2013 - 04:02 AM

All found grid implementations I found, even in book are damw far away from perfectness

After lots of optimizations and experiments I found routine that works finiest and its stil on optimizations

but main loop would look like this:

 

loop
{

//objects update
for(all objects)  //dead,alive, and waiting to be inserted in game world
{
     if(obj.is_dead()){delete obj;continue;}
     if(obj.mut_insert())obj.set_acative();
     if(obj.active)
     {	
        obj.move_object();
        obj.find_bounding_box();
        bool update = obj.find_out_does_it_needs_to_be_updated_in_grid(); //not accessing grid data, maybe tricky or very easy, it depends
        if(update)
        {
            obj.update_id++;
            grid.add(obj);
        }
    }
}
//grid update and collisions
for(all cells in grid)
{
     for(all objects in cell)
     {
          if(cell_obj->obj->update_id!=cell_obj->update_id)delete cell_obj; //delete all elements with old id's
          
     }
     sort_cell_objects_by_box_left_up_corner_x(cell);
     do_collision_like_sweep_and_prune(cell);//with some tricks its easy to avoid dublicate checks so we dont need to check neighbur cells so even object size differences do not mater
}

}

So its main simple main loop.

Some of optimization could be done for example:

do cell objects delete sort and check for collision in one loop

find bounding box without resuming all object vectors

object insertation could be done in grid.collision routine() becouse on insert you must check if it lands on free space


#3serumas

Posted 23 April 2013 - 03:56 AM

All found grid implementations I found, even in book are damw far away from perfectness

After lots of optimizations and experiments I found routine that works finiest and its stil on optimizations

but main loop would look like this:

 

loop
{

//objects update
for(all objects)  //dead,alive, and waiting to be inserted in game world
{
     if(obj.is_dead()){delete obj;continue;}
     if(obj.mut_insert())obj.set_acative();
     if(obj.active)
     {	
        obj.move_object();
        obj.find_bounding_box();
        bool update = obj.find_out_does_it_needs_to_be_updated_in_grid(); //not accessing grid data, maybe tricky or very easy, it depends
        if(update)
        {
            obj.update_id++;
            grid.add(obj);
        }
    }
}
//grid update and collisions
for(all cells in grid)
{
     for(all objects in cell)
     {
          if(cell_obj->obj->update_id!=cell_obj->update_id)delete cell_obj; //delete all elements with old id's
          
     }
     sort_cell_objects_by_box_left_up_corner_x(cell);
     do_collision_like_sweep_and_prune(cell);//with some tricks its easy to avoid dublicate checks so we dont need to check neighbur cells so even object size differences do not mater
}

}

So its main simple main loop.

Some of optimization could be done for example:

do cell objects delete sort and check for collision in one loop

find bounding box without resuming all object vectors


#2serumas

Posted 23 April 2013 - 03:52 AM

All found grid implementations I found, even in book are damw far away from perfectness

After lots of optimizations and experiments I found routine that works finiest and its stil on optimizations

but main loop would look like this:

 

loop
{

//objects update
for(all objects)  //dead,alive, and waiting to be inserted in game world
{
     if(obj.is_dead()){delete obj;continue;}
     if(obj.mut_insert())obj.set_acative();
     if(obj.active)
     {	
        obj.move_object();
        obj.find_bounding_box();
        bool update = obj.find_out_does_it_needs_to_be_updated_in_grid(); //not accessing grid data, maybe tricky or very easy, it depends
        if(update)
        {
            obj.update_id++;
            grid.add(obj);
        }
    }
}
//grid update and collisions
for(all cells in grid)
{
     for(all objects in cell)
     {
          if(cell_obj->obj->update_id!=cell_obj->update_id)delete cell_obj; //delete all elements with old id's
          
     }
     sort_cell_objects_by_box_left_up_corner_x(cell);
     do_collision_like_sweep_and_prune(cell);//with some tricks its easy to avoid dublicate checks so we dont need to check neighbur cells so even object size differences do not mater
}

}

#1serumas

Posted 23 April 2013 - 03:51 AM

All found grid implementations I found, even in book are damw far away from perfectness

After lots of optimizations and experiments I found routine that works finiest and its stil on optimizations

but main loop would look like this:

 

loop
{

//objects update
for(all objects)  //dead,alive, and waiting to be inserted in game world
{
     if(obj.is_dead()){delete obj;continue;}
     if(obj.mut_insert())obj.set_acative();
     if(obj.active)
     {	
        obj.move_object();
        obj.find_bounding_box();
        bool update = obj.find_out_does_it_needs_to_be_updated_in_grid(); //not accessing grid data, tricky but its possible
        if(update)
        {
            obj.update_id++;
            grid.add(obj);
        }
    }
}
//grid update and collisions
for(all cells in grid)
{
     for(all objects in cell)
     {
          if(cell_obj->obj->update_id!=cell_obj->update_id)delete cell_obj; //delete all elements with old id's
          
     }
     sort_cell_objects_by_box_left_up_corner_x(cell);
     do_collision_like_sweep_and_prune(cell);//with some tricks its easy to avoid dublicate checks so we dont need to check neighbur cells so even object size differences do not mater
}

}

PARTNERS