00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036
00037 #include "SO3SCOL.h"
00038
00039 #include "../SO3Material/SO3Material.h"
00040 #include "../SO3Material/SO3Texture.h"
00041 #include "../SO3SceneGraph/SO3Scene.h"
00042
00043
00054
00055 int SO3AddResourceLocationURL(mmachine m)
00056 {
00057 #ifdef SO3_DEBUG
00058 MMechostr(MSKDEBUG,"SO3AddResourceLocationURL\n");
00059 #endif
00060
00061 int p = MMpull(m);
00062 int group = MMget(m, 0);
00063 if(p == NIL)
00064 {
00065 MMset(m, 0, NIL);
00066 return 0;
00067 }
00068
00069 const char* resourceLocation = MMstartstr(m, MTOP(p));
00070
00071 std::string groupResource;
00072 if(group == NIL)
00073 groupResource = "General";
00074 else
00075 groupResource = std::string(MMstartstr(m,MTOP(group)));
00076
00077 try
00078 {
00079 if(!checkGroupExists(groupResource))
00080 {
00081 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourceLocation,"URL",groupResource);
00082 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupResource);
00083 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(groupResource);
00084 }
00085 else
00086 {
00087 Ogre::FileInfoListPtr finfo;
00088 Ogre::FileInfoList::iterator it;
00089 finfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(groupResource,"*");
00090 Ogre::ResourceGroupManager::getSingleton().clearResourceGroup(groupResource);
00091 for (it = finfo->begin(); it != finfo->end(); ++it)
00092 {
00093 if(!Ogre::ResourceGroupManager::getSingleton().resourceExists(groupResource,it->basename)) Ogre::ResourceGroupManager::getSingleton().addResourceLocation(it->archive->getName().c_str(),it->archive->getType(),groupResource);
00094 }
00095 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourceLocation,"URL",groupResource);
00096 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupResource);
00097 }
00098 MMset(m, 0, ITOM(1));
00099 return 0;
00100 }
00101 catch( Ogre::Exception &e )
00102 {
00103 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
00104 MMset(m, 0, NIL);
00105 return 0;
00106 }
00107 }
00108
00109
00120
00121 int SO3AddResourceLocationZIP(mmachine m)
00122 {
00123 #ifdef SO3_DEBUG
00124 MMechostr(MSKDEBUG,"SO3AddResourceLocationZIP\n");
00125 #endif
00126
00127 bool exists = false;
00128
00129 int p = MMpull(m);
00130 int group = MMget(m, 0);
00131 if(p == NIL)
00132 {
00133 MMset(m, 0, NIL);
00134 return 0;
00135 }
00136
00137 string pathStd = MMstartstr(m, MTOP(p));
00138 string resourceLocation = pathStd;
00139
00140 for(unsigned int i=0; i<pathStd.length(); i++)
00141 {
00142 if(pathStd.substr(i,1) == "\\")
00143 pathStd.replace(i,1,"/");
00144 }
00145
00146 std::string groupResource;
00147 if(group == NIL)
00148 groupResource = "General";
00149 else
00150 groupResource = std::string(MMstartstr(m,MTOP(group)));
00151 try
00152 {
00153 if(!checkGroupExists(groupResource))
00154 {
00155 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourceLocation,"Zip",groupResource);
00156 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupResource);
00157 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(groupResource);
00158 }
00159 else
00160 {
00161 Ogre::FileInfoListPtr finfo;
00162 Ogre::FileInfoList::iterator it;
00163 finfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(groupResource,"*");
00164 Ogre::ResourceGroupManager::getSingleton().clearResourceGroup(groupResource);
00165 for (it = finfo->begin(); it != finfo->end(); ++it)
00166 {
00167 if(!Ogre::ResourceGroupManager::getSingleton().resourceExists(groupResource,it->basename))
00168 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(it->archive->getName().c_str(),it->archive->getType(),groupResource);
00169 }
00170 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourceLocation,"Zip",groupResource);
00171 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupResource);
00172 }
00173 MMset(m,0,1);
00174 return 0;
00175 }
00176 catch( Ogre::Exception &e )
00177 {
00178 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
00179 MMset(m,0,0);
00180 return 0;
00181 }
00182 }
00183
00184
00194
00195 int SO3GroupCreate(mmachine m)
00196 {
00197 #ifdef SO3_DEBUG
00198 MMechostr(MSKDEBUG,"SO3GroupCreate\n");
00199 #endif
00200
00201 int group = MMpull(m);
00202 int s = MMget(m, 0);
00203 if((group == NIL)||(s == NIL))
00204 {
00205 MMset(m, 0, NIL);
00206 return 0;
00207 }
00208
00209 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00210 if(scene==NULL)
00211 {
00212 MMset(m, 0, NIL);
00213 return 0;
00214 }
00215
00216 std::string groupResource = std::string(MMstartstr(m, MTOP(group)));
00217
00218 if(checkGroupProtected(groupResource))
00219 {
00220 MMechostr(MSKDEBUG,"SO3Engine Exception : Group is Protected \n");
00221 MMset(m, 0, NIL);
00222 return 0;
00223 }
00224
00225 if(checkGroupExists(groupResource))
00226 {
00227 MMset(m, 0, NIL);
00228 return 0;
00229 }
00230
00231 try
00232 {
00233 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(groupResource, false);
00234 MMset(m, 0, ITOM(1));
00235 }
00236 catch( Ogre::Exception &e )
00237 {
00238 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
00239 MMset(m, 0, NIL);
00240 }
00241
00242
00247 packdir mypack = (packdir)SCgetExtra("FirstPack");
00248 string pathStd;
00249 std::vector<string> partitions;
00250
00251 while(mypack)
00252 {
00253 pathStd = mypack->path;
00254 for(unsigned int i = 0;i<pathStd.length();i++)
00255 {
00256 if(pathStd.substr(i,1) == "\\")
00257 pathStd.replace(i,1,"/");
00258 }
00259 partitions.push_back(pathStd);
00260 mypack = mypack->next;
00261 }
00262
00263 std::vector<string>::iterator iPartition = partitions.begin();
00264 while (iPartition != partitions.end())
00265 {
00266 Ogre::ResourceGroupManager::getSingleton().addResourceLocation((*iPartition), "FileSystem", groupResource, false);
00267
00268 iPartition++;
00269 }
00270
00271 return 0;
00272 }
00273
00274
00283
00284 int SO3GroupList(mmachine m)
00285 {
00286 #ifdef SO3_DEBUG
00287 MMechostr(MSKDEBUG,"SO3GroupList\n");
00288 #endif
00289
00290 unsigned int i,k;
00291 Ogre::String loc;
00292 Ogre::StringVector myStr;
00293
00294 int s = MMpull(m);
00295 if (s==NIL)
00296 {
00297 MMpush(m, NIL);
00298 return 0;
00299 }
00300
00301 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00302 if(scene==NULL)
00303 {
00304 MMpush(m, NIL);
00305 return 0;
00306 }
00307
00308 myStr = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
00309
00310 for(i = 0;i<myStr.size();i++)
00311 {
00312 loc = myStr[i];
00313 if(k=Mpushstrbloc(m,(char*)loc.c_str()))
00314 return k;
00315 }
00316
00317 if(MMpush(m,NIL))
00318 return MERRMEM;
00319
00320 for(i=0;i<myStr.size();i++)
00321 {
00322 if(MMpush(m,2*2))
00323 return MERRMEM;
00324 if(k=MBdeftab(m))
00325 return k;
00326 }
00327 return 0;
00328 }
00329
00330
00340 int SO3GroupDelete(mmachine m)
00341 {
00342 #ifdef SO3_DEBUG
00343 MMechostr(MSKDEBUG,"SO3GroupDelete\n");
00344 #endif
00345
00346 int group = MMpull(m);
00347 int s = MMget(m, 0);
00348 if((group == NIL) || (s == NIL))
00349 {
00350 MMset(m, 0, NIL);
00351 return 0;
00352 }
00353
00354 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00355 if(scene==NULL)
00356 {
00357 MMset(m, 0, NIL);
00358 return 0;
00359 }
00360
00361 std::string groupResource(MMstartstr(m,MTOP(group)));
00362
00363 if(checkGroupProtected(std::string(groupResource)))
00364 {
00365 MMechostr(MSKDEBUG,"SO3Engine Exception : Group is Protected \n");
00366 MMset(m, 0, NIL);
00367 return 0;
00368 }
00369
00370 if(!checkGroupExists(groupResource))
00371 {
00372 MMset(m, 0, NIL);
00373 return 0;
00374 }
00375
00376
00377 SGroupMaterialMap::const_iterator iGroupMatSearched = scene->listOfMaterial.find(groupResource);
00378 if(iGroupMatSearched != scene->listOfMaterial.end())
00379 {
00380 const SMaterialMap matmap = *(const_cast <const SMaterialMap*> (iGroupMatSearched->second));
00381 SMaterialMap::const_iterator iMaterialList = matmap.begin();
00382 while (iMaterialList != matmap.end())
00383 {
00384 int mat = OBJfindTH(m, SO3MATERIAL, (int)(iMaterialList->second));
00385
00386 if(mat!=NIL)
00387 mat = MMfetch(m,mat,OFFOBJMAG);
00388
00389 OBJdelTM(m, SO3MATERIAL, mat);
00390 iMaterialList++;
00391 }
00392 }
00393
00394 SGroupTextureMap::const_iterator iGroupTexSearched = scene->listOfTexture.find(groupResource);
00395 if(iGroupTexSearched != scene->listOfTexture.end())
00396 {
00397 const STextureMap texmap = *(const_cast <const STextureMap*> (iGroupTexSearched->second));
00398 STextureMap::const_iterator iTextureList = texmap.begin();
00399 while (iTextureList != texmap.end())
00400 {
00401 int tx = OBJfindTH(m, SO3TEXTURE, (int)(iTextureList->second));
00402
00403 if(tx!=NIL)
00404 tx = MMfetch(m,tx,OFFOBJMAG);
00405
00406 OBJdelTM(m,SO3TEXTURE,tx);
00407 iTextureList++;
00408 }
00409 }
00410
00411 try
00412 {
00413 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(groupResource);
00414 MMset(m, 0, ITOM(1));
00415 }
00416 catch( Ogre::Exception &e )
00417 {
00418 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
00419 MMset(m, 0, NIL);
00420 return 0;
00421 }
00422
00423 return 0;
00424 }
00425
00435 int SO3GroupReload(mmachine m)
00436 {
00437 #ifdef SO3_DEBUG
00438 MMechostr(MSKDEBUG,"SO3GroupReload\n");
00439 #endif
00440
00441 int group = MMpull(m);
00442 int s = MMget(m, 0);
00443 if((group == NIL) || (s == NIL))
00444 {
00445 MMset(m, 0, NIL);
00446 return 0;
00447 }
00448
00449 SScene* scene = (SScene*)MMfetch(m, MTOP(s), 0);
00450 if(scene==NULL)
00451 {
00452 MMset(m, 0, NIL);
00453 return 0;
00454 }
00455
00456 std::string groupResource(MMstartstr(m, MTOP(group)));
00457
00458 if(checkGroupProtected(std::string(groupResource)))
00459 {
00460 MMechostr(MSKDEBUG,"SO3Engine Exception : Group is Protected \n");
00461 MMset(m, 0, NIL);
00462 return 0;
00463 }
00464
00465 if(!checkGroupExists(groupResource))
00466 {
00467 MMset(m, 0, NIL);
00468 return 0;
00469 }
00470
00471 try
00472 {
00473 Ogre::ResourceGroupManager::getSingleton().unloadResourceGroup(groupResource);
00474 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupResource);
00475 Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(groupResource);
00476 scene->O3GpuProgramManager->reloadAll(true);
00477 scene->O3HighLevelGpuProgramManager->reloadAll(true);
00478 scene->O3TextureManager->reloadAll(true);
00479 scene->O3MaterialManager->reloadAll(true);
00480 scene->O3MeshManager->reloadAll(true);
00481 scene->ReloadEntities();
00482 MMset(m, 0, ITOM(1));
00483 }
00484 catch( Ogre::Exception &e )
00485 {
00486 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
00487 MMset(m, 0, NIL);
00488 return 0;
00489 }
00490
00491 return 0;
00492 }
00493
00504
00505 int SO3AddResourceLocationDirectory(mmachine m)
00506 {
00507 #ifdef SO3_DEBUG
00508 MMechostr(MSKDEBUG,"SO3AddResourceLocationDirectory\n");
00509 #endif
00510
00511 int p = MMpull(m);
00512 int group = MMget(m, 0);
00513 if(p == NIL)
00514 {
00515 MMset(m, 0, NIL);
00516 return 0;
00517 }
00518
00519 try
00520 {
00521 const char* groupResource;
00522 if(group == NIL)
00523 groupResource = "General";
00524 else
00525 groupResource = MMstartstr(m, MTOP(group));
00526
00527 const char* resourceLocation = MMstartstr(m,MTOP(p));
00528
00529
00530
00531 packdir mypack = (packdir)SCgetExtra("FirstPack");
00532 string pathStd;
00533 std::vector<string> partitions;
00534 while(mypack)
00535 {
00536 pathStd = mypack->path;
00537
00538 for(unsigned int i = 0;i<pathStd.length();i++)
00539 {
00540 if(pathStd.substr(i,1) == "\\") pathStd.replace(i,1,"/");
00541 }
00542
00543 partitions.push_back(pathStd);
00544 mypack = mypack->next;
00545 }
00546
00547
00548 std::vector<string>::reverse_iterator iPartition = partitions.rbegin();
00549 while (iPartition != partitions.rend())
00550 {
00551 (*iPartition) += resourceLocation;
00552 Ogre::ResourceGroupManager::getSingleton().addResourceLocation((*iPartition), "FileSystem", groupResource, true);
00553
00554 iPartition++;
00555 }
00556 MMset(m, 0, ITOM(1));
00557 return 0;
00558 }
00559 catch( Ogre::Exception &e )
00560 {
00561 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
00562 MMset(m, 0, NIL);
00563 return 0;
00564 }
00565
00566 return 0;
00567 }
00568
00569
00573 #define NBRESOURCESPKG 7
00574
00575
00579 char* RESOURCESname [ NBRESOURCESPKG ] =
00580 {
00581 "SO3GroupCreate",
00582 "SO3GroupDelete",
00583 "SO3GroupReload",
00584 "SO3GroupList",
00585 "SO3AddResourceLocationURL",
00586 "SO3AddResourceLocationZIP",
00587 "SO3AddResourceLocationDirectory"
00588 };
00589
00590
00594 int (*RESOURCESFunc[NBRESOURCESPKG])(mmachine m)=
00595 {
00596 SO3GroupCreate,
00597 SO3GroupDelete,
00598 SO3GroupReload,
00599 SO3GroupList,
00600 SO3AddResourceLocationURL,
00601 SO3AddResourceLocationZIP,
00602 SO3AddResourceLocationDirectory
00603 };
00604
00605
00609 int RESOURCESnarg [ NBRESOURCESPKG ] =
00610 {
00611 2,
00612 2,
00613 2,
00614 1,
00615 2,
00616 2,
00617 2
00618 };
00619
00620
00624 char* RESOURCESType[NBRESOURCESPKG]=
00625 {
00626 "fun [SO3_SCENE S] I",
00627 "fun [SO3_SCENE S] I",
00628 "fun [SO3_SCENE S] I",
00629 "fun [SO3_SCENE] [S r1]",
00630 "fun [S S] I",
00631 "fun [S P] I",
00632 "fun [S S] I"
00633 };
00634
00635
00641 int SCOLloadResources(mmachine m,cbmachine w)
00642 {
00643 return PKhardpak( m, "Resources", NBRESOURCESPKG, RESOURCESname, RESOURCESFunc, RESOURCESnarg, RESOURCESType );
00644 }
00645
00646
00651 int SCOLfreeResources()
00652 {
00653 return 0;
00654 }
00655