FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Small Problem

3 posters

Go down

A Small Problem Empty A Small Problem

Post  Don Jaffa Thu Feb 26, 2009 11:54 am

I am testing the engine atm, seeing what I am capable of by running an edited version of tutorial 9 - making a simple 'collect pickups avoid obstacles' style game. I have managed to get objects spawning at a set position, then moving past the player on the y axis - but I am having trouble working out how to get them to de-spawn after they have moved past the player (and are thus effectively out of the game).

Is there a way to delete any object (spawned using sio2ObjectDuplicate) that goes past a certain position on the y axis? Or if not how would I write something that will check each object that has been spawned in turn then delete the ones that have moved past the player?

Any help would be greatly appreciated Razz

Don Jaffa

Posts : 49
Join date : 2009-02-19

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  meteors Thu Feb 26, 2009 12:13 pm

Write a function to iterate through all existing objects, and check their location.

If y > whatever, then delete it.

I'm not sure if there's a native SIO2 method to iterate though sio2object duplicates. You could simply add each new object to an array, or better yet an STL::vector.


Best,
-joshua
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  sio2interactive Thu Feb 26, 2009 3:50 pm

Please do not use any STL vector... they are extremely slow compare to whatever mechanism you will write using C...

If you are always going forward on the Y axis, you can check the SIO2object->dst of each object if the dst if negative it means that you pass that object and you can now delete it.

That should do the trick:

1. Update to the latest version on SVN

2.

Code:




      unsigned int i = 0,
             cnt = 0;
      
      void **_SIO2object;
      
      SIO2object *ptr;

      i = 0;
      
      // If you are using multiple SIO2resource
      // make sure that the appropriate one is bind.
      sio2->_SIO2resource = level;
      
      while( i != level->n_object )
      {
         ptr = ( SIO2object * )level->_SIO2object[ i ];

         if( ptr->dst < 0.0f )
         {
            printf( "%s:%f\n", ptr->name, ptr->dst );
            
            ++cnt;
            _SIO2object = ( void ** ) realloc( _SIO2object, cnt * sizeof( void * ) );
         
            _SIO2object[ cnt - 1 ] = ptr;
         }

         ++i;
      }


      i = 0;
      while( i != cnt )
      {
         ptr = ( SIO2object * )_SIO2object[ i ];
         
         if( sio2IsEnabled( ptr->flags, SIO2_OBJECT_ACTOR ) )
         {
            sio2PhysicRemoveObject( sio2->_SIO2physic, ptr );
         }

         ptr = sio2ObjectFree( ptr );

         ++i;
      }   
      
      // Bind back the old resource?
      sio2->_SIO2resource = player;

sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  Don Jaffa Fri Feb 27, 2009 5:27 am

Ahh man that sounds perfect Razz

Thanks loads, I will get on with implementing this asap Very Happy Very Happy Very Happy

Don Jaffa

Posts : 49
Join date : 2009-02-19

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  Don Jaffa Sun Mar 08, 2009 12:17 pm

Ok after trying to implement this code, failing, leaving it for a while to work on other aspects of the game, coming back to it and still not getting it to work i have to admit I feel like I am not understanding something crucial to the engine.

Basically my problem is with these 2 lines of code:

// If you are using multiple SIO2resource
// make sure that the appropriate one is bind.
sio2->_SIO2resource = level;

// Bind back the old resource?
sio2->_SIO2resource = player;

How do I refer to my level? Using the .sio2 file doesn't seem to work and if I need to select a resource that I have created since the game began (as i don't really want to de-spawn the object that is being copied as it's dst will be 0) what code would I need to use?

I assume refering back to the player at the end will be done using the ' SIO2object *object = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/player" );' section of code or something similar, is this right?

Any help would be greatly appreciated Very Happy

Thanks

Don Jaffa

Posts : 49
Join date : 2009-02-19

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  sio2interactive Mon Mar 09, 2009 10:11 pm

Ok, basically you got an SIO2resource struct, this struct is basically like a resource manager everything that you load from .sio2 will be store there (every handles). So basically you can load multiple .sio2 to 1 SIO2resource the idea is that before you load / unload stuff you bind the SIO2resource, you can keep separated SIO2resource depending on what you want to do and bind handle to the main sio2 handle ex:

SIO2resource *level = NULL;
SIO2resource *player = NULL;
...
Initialize both level & player
...

sio2->_SIO2resource = level;

load the level

sio2->_SIO2resource = player

load the player

...
...
sio2->_SIO2resource = level;

unload the level

sio2->_SIO2resource = player;

unload the player
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  Don Jaffa Sun Apr 19, 2009 5:23 am

As you can probably see from looking at the dates on this thread this has been my nemesis in terms of code when it comes to sio2, so any help will be greatly appreciated.

Basically I understand about the resource structure (I think) but I can't work out how to add certain objects to specific structures (Unless it works like all info from a .sio2 file goes to a specific resource and if you want something to go to a different resource it needs to be in a different .sio2 - kinda implied in the last post).

My code to spawn an object is as follows:

Code:
{SIO2object *obstacle = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/Cube" );
         
                        obstacle->_btRigidBody->setActivationState( ACTIVE_TAG );
         
         if( (COUNTER % 10) == 0)
            
         {   static unsigned int i = 0;
            
            char name[ SIO2_MAX_CHAR ];
            
            //duplicate_object = !duplicate_object;
            
            // Create a name for our new object
            sprintf( name, "%s_%d", obstacle->name, i );
            
            // Give a little offset so it'll be duplicated
            // right on top of the current selection
            obstacle->_SIO2transform->loc->x = ( (tmp_pos.x - 50) + (100 * (rand() / ((double)RAND_MAX + 1))) );
            obstacle->_SIO2transform->loc->y = ( tmp_pos.y + 125 );
            obstacle->_SIO2transform->loc->z = 4;
            
            // Select the new object created...
            obstacle = sio2ObjectDuplicate( obstacle, obstacle->_SIO2transform, name, 1 );
            
            obstacle->_btRigidBody->setLinearVelocity( btVector3( 0, -80, 0) );
            ++i;
         }
      }


Basically just an adjusted version of the tutorial 06 code - can anyone give me some pointers on how to add these objects to the 'level' resource? Or If I have to make a separate .sio2 file to have them as a separate resource how do I go about coding this in? This problem is the only thinking keeping me from testing on device so any help would be very, very greatly appreciated.

(if anyone else thinks of a way to incorporate despawning the items above that is easier to do/based on a positional system would be very helpful also - I swear this problem is the only thing thats stopping me from making any progress)

Don Jaffa

Posts : 49
Join date : 2009-02-19

Back to top Go down

A Small Problem Empty Re: A Small Problem

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum