A Small Problem
3 posters
A Small Problem
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
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
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: A Small Problem
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
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- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: A Small Problem
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.
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;
Re: A Small Problem
Ahh man that sounds perfect
Thanks loads, I will get on with implementing this asap
Thanks loads, I will get on with implementing this asap
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: A Small Problem
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
Thanks
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
Thanks
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: A Small Problem
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
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
Re: A Small Problem
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:
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)
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
Similar topics
» how to paste a small images inside SIO2widget's SIO2image
» Passing Through Static Object (Beating my iPod seems to help)
» md2 problem!
» Camera problems
» Rendering error between two meshes
» Passing Through Static Object (Beating my iPod seems to help)
» md2 problem!
» Camera problems
» Rendering error between two meshes
Permissions in this forum:
You cannot reply to topics in this forum