Custom resources
5 posters
Custom resources
Hey, I was just wondering if anyone knows the code to add an object to a specific resource rather than the standard 'everything' resource.
I.e. if I am running a section of code that duplicates an existing object, what do i write to add the duplicated object to the 'level' SIO2resource?
Thanks for any help, this problem has been my nemesis since I started using SIO2 (well, part of the despawning problem I had ages ago and still havent managed to fix )
I.e. if I am running a section of code that duplicates an existing object, what do i write to add the duplicated object to the 'level' SIO2resource?
Thanks for any help, this problem has been my nemesis since I started using SIO2 (well, part of the despawning problem I had ages ago and still havent managed to fix )
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: Custom resources
just bind the sio2->_SIO2resource handle to another SIO2resource then add whatever you want to it...
Re: Custom resources
Now what your saying seems really simple but its refusing to work.
This is what i do:
But when I run it I get a 'EXC_BAD_ACCESS' error here:
Sorry if I'm being really stupid but this is so frustrating Im losing the will to carry on with the project, i really need a pointer to show me where I'm going wrong.
Cheers
This is what i do:
- Code:
SIO2resource *level = NULL;
SIO2resource *playerentity = NULL;
...
...
sio2->_SIO2resource = playerentity;
...
//add player entity objects here
...
sio2->_SIO2resource = level;
...
run the script that duplicates the object here
...
{
static unsigned int i = 0;
if (i != level->n_object)
{
++TEST_VAL1;
}
++i;
}
But when I run it I get a 'EXC_BAD_ACCESS' error here:
- Code:
case SIO2_OBJECT:
{
//This next lines gets the error
while( i != _SIO2resource->n_object )
{
SIO2object *_SIO2object = ( SIO2object * )_SIO2resource->_SIO2object[ i ];
if( !sio2StringCmp( _SIO2object->name, _name ) )
{ return _SIO2resource->_SIO2object[ i ]; }
++i;
}
break;
}
Sorry if I'm being really stupid but this is so frustrating Im losing the will to carry on with the project, i really need a pointer to show me where I'm going wrong.
Cheers
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: Custom resources
Ahh, no I didn't realise that thankyou (thought now I'm getting the bad access error here):
1 thing I think may be giving me problems - does the resources struct refer to the 'blahblah.sio2' files? So if I want a resource called 'level' will I need a 'level.sio2' file, or can I keep all my objects in my main 'game.sio2' file?
- Code:
void sio2ResourceAddEntry( SIO2resource *_SIO2resource,
char *_str,
SIO2parsercallback *_root,
SIO2parsercallback *_custom )
{
++_SIO2resource->n_entry;
_SIO2resource->_SIO2entry = ( SIO2entry * ) realloc( _SIO2resource->_SIO2entry, _SIO2resource->n_entry * sizeof( SIO2entry ) );
sio2StringCpy( _SIO2resource->_SIO2entry[ _SIO2resource->n_entry - 1 ].str, _str );
_SIO2resource->_SIO2entry[ _SIO2resource->n_entry - 1 ].root = _root;
_SIO2resource->_SIO2entry[ _SIO2resource->n_entry - 1 ].custom = _custom;
}
1 thing I think may be giving me problems - does the resources struct refer to the 'blahblah.sio2' files? So if I want a resource called 'level' will I need a 'level.sio2' file, or can I keep all my objects in my main 'game.sio2' file?
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: Custom resources
No necessarily, personally I have like over a dozen .sio2, for each level, characters, UI etc... all with different name have no importance...
Re: Custom resources
Is there a tutorial that uses separate sio2resources that I can take a look at and see what's going wrong with mine?
Don Jaffa- Posts : 49
Join date : 2009-02-19
Re: Custom resources
I would also like to see a tutorial with multiple resources, as I really can;t seem to get my head around how to implement multiple resources.
A tutorial on that would be fantastic!!
A tutorial on that would be fantastic!!
monkeys- Posts : 8
Join date : 2009-07-22
Re: Custom resources
Every resources in the MeditationGarden are independent... the garden, bird, fish, butterfly, UI etc... its a great resource to learn how to mix everything together. I highly suggest it to you.
Last edited by sio2interactive on Fri Aug 07, 2009 9:16 pm; edited 1 time in total
Re: Custom resources
Just one quick question while we're on resources: why have you added a name to the resources in 1.4? I can't see it being used in anything but the init function
oioioi- Posts : 136
Join date : 2008-12-02
Location : Norway
Re: Custom resources
well when you have multiple SIO2resource handle that call sio2ResourceRender and suddenly it crash im sure you would like to know from which SIO2resource it come from not just something like 0xa828a0
Re: Custom resources
Hi, while I encourage everyone to sponsor Romain and I'm sure the source code to iZenGarden has a lot of cool tricks, I found it pretty straight forward to load multiple resources. My code is something like this (sorry, still at 1.3.5):
templateLoading():
Not sure if this helps you?
--doug
templateLoading():
- Code:
if( !sio2->_SIO2resource->n_entry )
{ sio2ResourceCreateDictionary( sio2->_SIO2resource ); }
if( !sio2->_SIO2resource->uf )
{
char scene_name [64];
sprintf(scene_name, "scene%02d.sio2", scene_number);
printf("Loading %s ...\n", scene_name);
sio2ResourceOpen( sio2->_SIO2resource, scene_name, 1 );
}
if( i != sio2->_SIO2resource->gi.number_entry )
{
sio2ResourceExtract( sio2->_SIO2resource, NULL );
++i;
}
else
{
sio2ResourceClose( sio2->_SIO2resource );
sio2ResourceOpen( sio2->_SIO2resource, "character.sio2", 1 );
int i = 0;
while( i != sio2->_SIO2resource->gi.number_entry )
{
sio2ResourceExtract( sio2->_SIO2resource, NULL );
++i;
}
sio2ResourceClose( sio2->_SIO2resource );
}
Not sure if this helps you?
--doug
yarri- Posts : 81
Join date : 2009-04-10
Similar topics
» Help With Custom Function in sio2_physic.cc
» Resources - Assets and Instances
» rendering multiple resources
» Tutorial 4 with custom model, lighting not right
» Using Multiple Resources and sio2 files
» Resources - Assets and Instances
» rendering multiple resources
» Tutorial 4 with custom model, lighting not right
» Using Multiple Resources and sio2 files
Permissions in this forum:
You cannot reply to topics in this forum