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.

Resource Management

2 posters

Go down

Resource Management Empty Resource Management

Post  Cobbler Tue Feb 03, 2009 12:16 am

I have several scenes (startup screen, intro, various levels, game over screen and a highscore screen) exported to separate .sio2 files. Is there an example on how to switch the SIO2 resource at run-time? From looking at the code I don't think I can have several resource files loaded/instantiated at the same time.

Cobbler

Posts : 15
Join date : 2009-02-01

Back to top Go down

Resource Management Empty Re: Resource Management

Post  sio2interactive Tue Feb 03, 2009 1:13 am

Of course... by default the current resources included in the .SIO2 file will be append to the SIO2resource attached to the main sio2 pointer ( sio2->_SIO2resource ).

in example from sio2SoundInit:

sio2ResourceAdd( sio2->_SIO2resource,
SIO2_SOUND,
( void * )_SIO2sound );

After that is just a question to bind / load / unload the appropriate one that you want. In addition has you might have noticed all "resource" operation take a SIO2resource pointer... So it make it more flexible and can also be loaded in a separate thread (however be careful to the GenID function that absolutely need to be called with the thread where your GL_CONTEXT is, that's the only thing that you have to pay attention).

Cheers,
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Resource Management Empty Re: Resource Management

Post  Cobbler Tue Feb 03, 2009 7:36 pm

Thanks, it's a bit clearer but I still can't get it working.

I've moved the Resource loading code in tutorial 6 into a separate class (attached below). The class keeps a SIO2Resource pointer. None of the resources show up but if I set sio2->_SIO2Resource to be m_SIO2resource it works. I assume this is because only sio2->_SIO2Resource is used when the engine culls and renders, etc.

Am I supposed to call sio2ResourceAdd() for each resource in the resource file I just loaded (and sio2ResourceDel() later) or is there a function that will do that?





Code:

class ResourceHolder
{
public:
   ResourceHolder(char* name)
   {
      m_num_extracted = 0;
      m_SIO2resource = sio2ResourceInit();
      sio2ResourceCreateDictionary(m_SIO2resource );
      sio2ResourceOpen(m_SIO2resource, name, 1);
   }
   
   bool ExtractResources()
   {
      if( m_num_extracted<m_SIO2resource->gi.number_entry )
      {
         sio2ResourceExtract( m_SIO2resource );
         ++m_num_extracted;
      }
      
      if( m_num_extracted==m_SIO2resource->gi.number_entry )
      {
         sio2ResourceClose(m_SIO2resource );
         return true;         
      }
      else
      {
         return false;
      }
   }
   
   float Progress() const
   {
      return (float)m_num_extracted / (float)m_SIO2resource->gi.number_entry;
   }

   ~ResourceHolder()
   {
      sio2ResourceUnloadAll( m_SIO2resource );
      sio2ResourceFree(m_SIO2resource );
   }

   void Start()
   {
      sio2ResourceBindAllImages(m_SIO2resource);
      sio2ResourceBindAllMaterials(m_SIO2resource);
      sio2ResourceBindAllInstances(m_SIO2resource);
      sio2ResourceBindAllMatrix(m_SIO2resource);
      sio2ResourceBindAllPhysicObjects(m_SIO2resource, sio2->_SIO2physic );
      sio2ResourceGenId(m_SIO2resource );
      
      sio2->_SIO2camera = ( SIO2camera * )sio2ResourceGet( m_SIO2resource, SIO2_CAMERA, "camera/Camera" );
      sio2CameraSetPerspective( sio2->_SIO2camera, sio2->_SIO2window );
      sio2->_SIO2camera->rad = 1.0f;
      sio2->_SIO2camera->mass  = 75.0f;
      sio2->_SIO2camera->height = 1.84f;
      sio2PhysicAddCamera( sio2->_SIO2physic, sio2->_SIO2camera );
      sio2->_SIO2camera->_btRigidBody->setFriction( 0.50f );
      sio2->_SIO2camera->_btRigidBody->setRestitution( 0.0f );
      sio2PhysicPlay( sio2->_SIO2physic );
      sio2->_SIO2window->fps = 60;
   }

private:
   SIO2resource* m_SIO2resource;
   int m_num_extracted;
};

Cobbler

Posts : 15
Join date : 2009-02-01

Back to top Go down

Resource Management Empty Re: Resource Management

Post  sio2interactive Tue Feb 03, 2009 8:28 pm

I've moved the Resource loading code in tutorial 6 into a separate class (attached below). The class keeps a SIO2Resource pointer. None of the resources show up but if I set sio2->_SIO2Resource to be m_SIO2resource it works. I assume this is because only sio2->_SIO2Resource is used when the engine culls and renders, etc.

>> Take a look at the source below... The functions receive a SIO2resource pointer, its up to you to tell SIO2 which one to use... In this case im using the handle provided by the sio2 struct but its up to you to pass which one to use...


Code:


         sio2ResourceCull( sio2->_SIO2resource,
                       sio2->_SIO2camera );         

         sio2ResourceRender( sio2->_SIO2resource,
                        sio2->_SIO2window,
                        sio2->_SIO2camera,
                        SIO2_RENDER_SOLID_OBJECT );



Am I supposed to call sio2ResourceAdd() for each resource in the resource file I just loaded (and sio2ResourceDel() later) or is there a function that will do that?

>> Its all handled automatically, the only rule is when you construct / destroy resources make sure that it is handled by sio2->_SIO2resource handle... that's all, which one you want to bind its up to you...
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Resource Management Empty Re: Resource Management

Post  Cobbler Tue Feb 03, 2009 9:40 pm

Of course!

I actually saw that a little while after posting the question Embarassed Too much new stuff all at once and XCode is just driving me crazy Very Happy

So something like the following could be a solution if I need several resources to be active at once?
Code:

std:vector<SIO2resource*> resources;
for( size_t i=0; i<resources.size(); ++i )
{
  sio2ResourceCull( resources[i], sio2->_SIO2camera );       
  sio2ResourceRender( resources[i], sio2->_SIO2window, sio2->_SIO2camera, SIO2_RENDER_SOLID_OBJECT );
}

Cobbler

Posts : 15
Join date : 2009-02-01

Back to top Go down

Resource Management Empty Re: Resource Management

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