Revision: 2675 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2675&view=rev Author: rorthomas Date: 2012-05-26 01:58:41 +0000 (Sat, 26 May 2012) Log Message: ----------- moved more stuff around
Modified Paths: -------------- trunk/source/main/gameplay/RoRFrameListener.cpp trunk/source/main/gameplay/RoRFrameListener.h trunk/source/main/gameplay/terrain/TerrainManager.cpp trunk/source/main/gameplay/terrain/TerrainManager.h trunk/source/main/gameplay/terrain/TerrainObjectManager.cpp trunk/source/main/gameplay/terrain/TerrainObjectManager.h Modified: trunk/source/main/gameplay/RoRFrameListener.cpp =================================================================== --- trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-26 01:51:30 UTC (rev 2674) +++ trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-26 01:58:41 UTC (rev 2675) @@ -727,13 +727,6 @@ } } -void RoRFrameListener::setGravity(float value) -{ - gravity = value; - BeamFactory::getSingleton().recalcGravityMasses(); -} - - // Constructor takes a RenderWindow because it uses that to determine input context RoRFrameListener::RoRFrameListener(AppState *parentState, RenderWindow* win, Camera* cam, SceneManager* scm, Root* root, bool isEmbedded, Ogre::String inputhwnd) : clutch(0), @@ -1283,542 +1276,8 @@ } -void RoRFrameListener::unloadObject(const char* instancename) -{ - if (loadedObjects.find(std::string(instancename)) == loadedObjects.end()) - { - LOG("unable to unload object: " + std::string(instancename)); - return; - } - loaded_object_t obj = loadedObjects[std::string(instancename)]; - // check if it was already deleted - if (!obj.enabled) - return; - - // unload any collision tris - if (obj.collTris.size() > 0) - { - for(std::vector<int>::iterator it = obj.collTris.begin(); it != obj.collTris.end(); it++) - { - collisions->removeCollisionTri(*it); - } - } - - // and any collision boxes - if (obj.collBoxes.size() > 0) - { - for(std::vector<int>::iterator it = obj.collBoxes.begin(); it != obj.collBoxes.end(); it++) - { - collisions->removeCollisionBox(*it); - } - } - - obj.sceneNode->detachAllObjects(); - obj.sceneNode->setVisible(false); - obj.enabled = false; -} - -void RoRFrameListener::loadObject(const char* name, float px, float py, float pz, float rx, float ry, float rz, SceneNode * bakeNode, const char* instancename, bool enable_collisions, int scripthandler, const char *type, bool uniquifyMaterial) -{ - ScopeLog log("object_"+String(name)); - if (type && !strcmp(type, "grid")) - { - // some fast grid object hacks :) - for(int x=0;x<500;x+=50) - for(int z=0;z<500;z+=50) - loadObject(name, px+x, py, pz+z, rx, ry, rz, bakeNode, 0, enable_collisions, scripthandler, 0); - return; - } - - // nice idea, but too many random hits - //if (abs(rx+1) < 0.001) rx = Math::RangeRandom(0, 360); - //if (abs(ry+1) < 0.001) ry = Math::RangeRandom(0, 360); - //if (abs(rz+1) < 0.001) rz = Math::RangeRandom(0, 360); - - if (strnlen(name, 250)==0) - return; - - //FILE *fd; - char fname[1024] = {}; - char oname[1024] = {}; - char mesh[1024] = {}; - char line[1024] = {}; - char collmesh[1024] = {}; - float scx = 0, scy = 0, scz = 0; - float lx = 0, hx = 0, ly = 0, hy = 0, lz = 0, hz = 0; - float srx = 0, sry = 0, srz = 0; - float drx = 0, dry = 0, drz = 0; - float fcx = 0, fcy = 0, fcz = 0; - bool forcecam=false; - bool ismovable=false; - - int event_filter = EVENT_ALL; - Quaternion rotation = Quaternion(Degree(rx), Vector3::UNIT_X)*Quaternion(Degree(ry), Vector3::UNIT_Y)*Quaternion(Degree(rz), Vector3::UNIT_Z); - - // try to load with UID first! - String odefgroup = ""; - String odefname = ""; - bool odefFound = false; - if (terrainUID != "" && !CACHE.stringHasUID(name)) - { - sprintf(fname,"%s-%s.odef", terrainUID.c_str(), name); - odefname = String(fname); - bool exists = ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(odefname); - if (exists) - { - odefgroup = ResourceGroupManager::getSingleton().findGroupContainingResource(odefname); - odefFound = true; - } - } - - if (!odefFound) - { - sprintf(fname,"%s.odef", name); - odefname = String(fname); - bool exists = ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(odefname); - if (exists) - { - odefgroup = ResourceGroupManager::getSingleton().findGroupContainingResource(odefname); - odefFound = true; - } - } - - - if (!CACHE.checkResourceLoaded(odefname, odefgroup)) - if (!odefFound) - { - LOG("Error while loading Terrain: could not find required .odef file: " + odefname + ". Ignoring entry."); - return; - } - - DataStreamPtr ds=ResourceGroupManager::getSingleton().openResource(odefname, odefgroup); - - ds->readLine(mesh, 1023); - if (String(mesh) == "LOD") - { - // LOD line is obsolete - ds->readLine(mesh, 1023); - } - - //scale - ds->readLine(line, 1023); - sscanf(line, "%f, %f, %f",&scx,&scy,&scz); - sprintf(oname,"object%i(%s)", objcounter,name); - objcounter++; - - - SceneNode *tenode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); - bool background_loading = BSETTING("Background Loading", false); - - MeshObject *mo = NULL; - if (String(mesh) != "none") - mo = new MeshObject(mSceneMgr, mesh, oname, tenode, NULL, background_loading); - - //mo->setQueryFlags(OBJECTS_MASK); - //tenode->attachObject(te); - tenode->setScale(scx,scy,scz); - tenode->setPosition(px,py,pz); - tenode->rotate(rotation); - tenode->pitch(Degree(-90)); - tenode->setVisible(true); - - // register in map - loaded_object_t *obj = &loadedObjects[std::string(instancename)]; - obj->instanceName = std::string(instancename); - obj->loadType = 0; - obj->enabled = true; - obj->sceneNode = tenode; - obj->collTris.clear(); - - - if (mo && uniquifyMaterial && instancename) - { - for(unsigned int i = 0; i < mo->getEntity()->getNumSubEntities(); i++) - { - SubEntity *se = mo->getEntity()->getSubEntity(i); - String matname = se->getMaterialName(); - String newmatname = matname + "/" + String(instancename); - //LOG("subentity " + TOSTRING(i) + ": "+ matname + " -> " + newmatname); - se->getMaterial()->clone(newmatname); - se->setMaterialName(newmatname); - } - } - - //String meshGroup = ResourceGroupManager::getSingleton().findGroupContainingResource(mesh); - //MeshPtr mainMesh = mo->getMesh(); - - //collision box(es) - bool virt=false; - bool rotating=false; - bool classic_ref=true; - // everything is of concrete by default - ground_model_t *gm = collisions->getGroundModelByString("concrete"); - char eventname[256]; - eventname[0]=0; - while (!ds->eof()) - { - size_t ll=ds->readLine(line, 1023); - - // little workaround to trim it - String lineStr = String(line); - Ogre::StringUtil::trim(lineStr); - - const char* ptline = lineStr.c_str(); - if (ll==0 || line[0]=='/' || line[0]==';') continue; - - if (!strcmp("end",ptline)) break; - if (!strcmp("movable", ptline)) {ismovable=true;continue;}; - if (!strcmp("localizer-h", ptline)) - { - localizers[free_localizer].position=Vector3(px,py,pz); - localizers[free_localizer].rotation=rotation; - localizers[free_localizer].type=Autopilot::LOCALIZER_HORIZONTAL; - free_localizer++; - continue; - } - if (!strcmp("localizer-v", ptline)) - { - localizers[free_localizer].position=Vector3(px,py,pz); - localizers[free_localizer].rotation=rotation; - localizers[free_localizer].type=Autopilot::LOCALIZER_VERTICAL; - free_localizer++; - continue; - } - if (!strcmp("localizer-ndb", ptline)) - { - localizers[free_localizer].position=Vector3(px,py,pz); - localizers[free_localizer].rotation=rotation; - localizers[free_localizer].type=Autopilot::LOCALIZER_NDB; - free_localizer++; - continue; - } - if (!strcmp("localizer-vor", ptline)) - { - localizers[free_localizer].position=Vector3(px,py,pz); - localizers[free_localizer].rotation=rotation; - localizers[free_localizer].type=Autopilot::LOCALIZER_VOR; - free_localizer++; - continue; - } - if (!strcmp("standard", ptline)) {classic_ref=false;tenode->pitch(Degree(90));continue;}; - if (!strncmp("sound", ptline, 5)) - { -#ifdef USE_OPENAL - if (!SoundScriptManager::getSingleton().isDisabled()) - { - char tmp[255]=""; - sscanf(ptline, "sound %s", tmp); - SoundScriptInstance *sound = SoundScriptManager::getSingleton().createInstance(tmp, MAX_TRUCKS+1, tenode); - sound->setPosition(tenode->getPosition(), Vector3::ZERO); - sound->start(); - } -#endif //USE_OPENAL - continue; - } - if (!strcmp("beginbox", ptline) || !strcmp("beginmesh", ptline)) - { - drx=dry=drz=0.0; - rotating=false; - virt=false; - forcecam=false; - event_filter=EVENT_NONE; - eventname[0]=0; - collmesh[0]=0; - gm = collisions->getGroundModelByString("concrete"); - continue; - }; - if (!strncmp("boxcoords", ptline, 9)) - { - sscanf(ptline, "boxcoords %f, %f, %f, %f, %f, %f",&lx,&hx,&ly,&hy,&lz, &hz); - continue; - } - if (!strncmp("mesh", ptline, 4)) - { - sscanf(ptline, "mesh %s",collmesh); - continue; - } - if (!strncmp("rotate", ptline, 6)) - { - sscanf(ptline, "rotate %f, %f, %f",&srx, &sry, &srz); - rotating=true; - continue; - } - if (!strncmp("forcecamera", ptline, 11)) - { - sscanf(ptline, "forcecamera %f, %f, %f",&fcx, &fcy, &fcz); - forcecam=true; - continue; - } - if (!strncmp("direction", ptline, 9)) - { - sscanf(ptline, "direction %f, %f, %f",&drx, &dry, &drz); - continue; - } - if (!strncmp("frictionconfig", ptline, 14) && strlen(ptline) > 15) - { - // load a custom friction config - collisions->loadGroundModelsConfigFile(String(ptline + 15)); - continue; - } - if ((!strncmp("stdfriction", ptline, 11) || !strncmp("usefriction", ptline, 11)) && strlen(ptline) > 12) - { - String modelName = String(ptline + 12); - gm = collisions->getGroundModelByString(modelName); - continue; - } - if (!strcmp("virtual", ptline)) {virt=true;continue;}; - if (!strncmp("event", ptline, 5)) - { - char ts[256]; - ts[0]=0; - sscanf(ptline, "event %s %s",eventname, ts); - if (!strncmp(ts, "avatar", 6)) - event_filter=EVENT_AVATAR; - else if (!strncmp(ts, "truck", 5)) - event_filter=EVENT_TRUCK; - else if (!strncmp(ts, "airplane", 8)) - event_filter=EVENT_AIRPLANE; - else if (!strncmp(ts, "delete", 8)) - event_filter=EVENT_DELETE; - - if (!strncmp(ts, "shoptruck", 9)) - terrainHasTruckShop=true; - - // fallback - if (strlen(ts) == 0) - event_filter=EVENT_ALL; - - continue; - } - //resp=sscanf(ptline, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %c",&lx,&hx,&ly, &hy,&lz, &hz, &srx, &sry, &srz,&type); - if (!strcmp("endbox", ptline)) - { - if (enable_collisions) - { - int boxnum = collisions->addCollisionBox(tenode, rotating, virt,px,py,pz,rx,ry,rz,lx,hx,ly,hy,lz,hz,srx,sry,srz,eventname, instancename, forcecam, Vector3(fcx, fcy, fcz), scx, scy, scz, drx, dry, drz, event_filter, scripthandler); - obj->collBoxes.push_back((boxnum)); - } - continue; - } - if (!strcmp("endmesh", ptline)) - { - collisions->addCollisionMesh(collmesh, Vector3(px,py,pz), tenode->getOrientation(), Vector3(scx, scy, scz), gm, &(obj->collTris)); - continue; - } - - if (!strncmp("particleSystem", ptline, 14) && tenode) - { - float x=0, y=0, z=0, scale=0; - char pname[255]="", sname[255]=""; - int res = sscanf(ptline, "particleSystem %f, %f, %f, %f, %s %s", &scale, &x, &y, &z, pname, sname); - if (res != 6) continue; - - // hacky: prevent duplicates - String paname = String(pname); - while(mSceneMgr->hasParticleSystem(paname)) - paname += "_"; - - // create particle system - ParticleSystem* pParticleSys = mSceneMgr->createParticleSystem(paname, String(sname)); - pParticleSys->setCastShadows(false); - pParticleSys->setVisibilityFlags(DEPTHMAP_DISABLED); // disable particles in depthmap - - // Some affectors may need its instance name (e.g. for script feedback purposes) -#ifdef USE_ANGELSCRIPT - unsigned short affCount = pParticleSys->getNumAffectors(); - ParticleAffector* pAff; - for(unsigned short i = 0; i<affCount; ++i) - { - pAff = pParticleSys->getAffector(i); - if (pAff->getType()=="ExtinguishableFire") - ((ExtinguishableFireAffector*)pAff)->setInstanceName(obj->instanceName); - } -#endif // USE_ANGELSCRIPT - - SceneNode *sn = tenode->createChildSceneNode(); - sn->attachObject(pParticleSys); - sn->pitch(Degree(90)); - continue; - } - - if (!strncmp("setMeshMaterial", ptline, 15)) - { - char mat[256]=""; - sscanf(ptline, "setMeshMaterial %s", mat); - if (mo->getEntity() && strnlen(mat,250)>0) - { - mo->getEntity()->setMaterialName(String(mat)); - // load it - //MaterialManager::getSingleton().load(String(mat), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - } - continue; - } - if (!strncmp("generateMaterialShaders", ptline, 23)) - { - char mat[256]=""; - sscanf(ptline, "generateMaterialShaders %s", mat); - if (BSETTING("Use RTShader System", false)) - { - Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(String(mat), Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME); - Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, String(mat)); - } - - continue; - } - if (!strncmp("playanimation", ptline, 13) && mo) - { - char animname[256]=""; - float speedfactorMin = 0, speedfactorMax = 0; - sscanf(ptline, "playanimation %f, %f, %s", &speedfactorMin, &speedfactorMax, animname); - if (tenode && mo->getEntity() && strnlen(animname,250)>0) - { - AnimationStateSet *s = mo->getEntity()->getAllAnimationStates(); - if (!s->hasAnimationState(String(animname))) - { - LOG("ODEF: animation '" + String(animname) + "' for mesh: '" + String(mesh) + "' in odef file '" + String(name) + ".odef' not found!"); - continue; - } - animated_object_t ao; - ao.node = tenode; - ao.ent = mo->getEntity(); - ao.speedfactor = speedfactorMin; - if (speedfactorMin != speedfactorMax) - ao.speedfactor = Math::RangeRandom(speedfactorMin, speedfactorMax); - ao.anim = 0; - try - { - ao.anim = mo->getEntity()->getAnimationState(String(animname)); - } catch (...) - { - ao.anim = 0; - } - if (!ao.anim) - { - LOG("ODEF: animation '" + String(animname) + "' for mesh: '" + String(mesh) + "' in odef file '" + String(name) + ".odef' not found!"); - continue; - } - ao.anim->setEnabled(true); - animatedObjects.push_back(ao); - } - continue; - } - if (!strncmp("drawTextOnMeshTexture", ptline, 21) && mo) - { - if (!mo->getEntity()) - continue; - String matName = mo->getEntity()->getSubEntity(0)->getMaterialName(); - MaterialPtr m = MaterialManager::getSingleton().getByName(matName); - if (m.getPointer() == 0) - { - LOG("ODEF: problem with drawTextOnMeshTexture command: mesh material not found: "+String(fname)+" : "+String(ptline)); - continue; - } - String texName = m->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName(); - Texture* background = (Texture *)TextureManager::getSingleton().getByName(texName).getPointer(); - if (!background) - { - LOG("ODEF: problem with drawTextOnMeshTexture command: mesh texture not found: "+String(fname)+" : "+String(ptline)); - continue; - } - - static int textureNumber = 0; - textureNumber++; - char tmpTextName[256]="", tmpMatName[256]=""; - sprintf(tmpTextName, "TextOnTexture_%d_Texture", textureNumber); - sprintf(tmpMatName, "TextOnTexture_%d_Material", textureNumber); // Make sure the texture is not WRITE_ONLY, we need to read the buffer to do the blending with the font (get the alpha for example) - TexturePtr texture = TextureManager::getSingleton().createManual(tmpTextName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (Ogre::uint)background->getWidth(), (Ogre::uint)background->getHeight(), MIP_UNLIMITED , PF_X8R8G8B8, Ogre::TU_STATIC|Ogre::TU_AUTOMIPMAP, new ResourceBuffer()); - if (texture.getPointer() == 0) - { - LOG("ODEF: problem with drawTextOnMeshTexture command: could not create texture: "+String(fname)+" : "+String(ptline)); - continue; - } - - float x=0, y=0, w=0, h=0; - float a=0, r=0, g=0, b=0; - char fontname[256]=""; - char text[256]=""; - char option='l'; - int res = sscanf(ptline, "drawTextOnMeshTexture %f, %f, %f, %f, %f, %f, %f, %f, %c, %s %s", &x, &y, &w, &h, &r, &g, &b, &a, &option, fontname, text); - if (res < 11) - { - LOG("ODEF: problem with drawTextOnMeshTexture command: "+String(fname)+" : "+String(ptline)); - continue; - } - - // cehck if we got a template argument - if (!strncmp(text, "{{argument1}}", 13)) - strncpy(text, instancename, 250); - - // replace '_' with ' ' - char *text_pointer = text; - while (*text_pointer!=0) {if (*text_pointer=='_') *text_pointer=' ';text_pointer++;}; - - Font* font = (Font *)FontManager::getSingleton().getByName(String(fontname)).getPointer(); - if (!font) - { - LOG("ODEF: problem with drawTextOnMeshTexture command: font not found: "+String(fname)+" : "+String(ptline)); - continue; - } - - - //Draw the background to the new texture - texture->getBuffer()->blit(background->getBuffer()); - - x = background->getWidth() * x; - y = background->getHeight() * y; - w = background->getWidth() * w; - h = background->getHeight() * h; - - Image::Box box = Image::Box((size_t)x, (size_t)y, (size_t)(x+w), (size_t)(y+h)); - WriteToTexture(String(text), texture, box, font, ColourValue(r, g, b, a), option); - - // we can save it to disc for debug purposes: - //SaveImage(texture, "test.png"); - - m->clone(tmpMatName); - MaterialPtr mNew = MaterialManager::getSingleton().getByName(tmpMatName); - mNew->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(tmpTextName); - - mo->getEntity()->setMaterialName(String(tmpMatName)); - continue; - } - - LOG("ODEF: unknown command in "+String(fname)+" : "+String(ptline)); - } - - //add icons if type is set -#ifdef USE_MYGUI - String typestr = ""; - if (type && surveyMap) - { - typestr = String(type); - // hack for raceways - if (!strcmp(name, "chp-checkpoint")) - typestr = "checkpoint"; - if (!strcmp(name, "chp-start")) - typestr = "racestart"; - if (!strncmp(name, "road", 4)) - typestr = "road"; - - if (typestr != String("") && typestr != String("road") && typestr != String("sign")) - { - MapEntity *e = surveyMap->createMapEntity(typestr); - if (e) - { - e->setVisibility(true); - e->setPosition(px, pz); - e->setRotation(Radian(ry)); - - if (String(name) != String("")) - e->setDescription(String(instancename)); - } - } - } -#endif //USE_MYGUI -} - void updateCruiseControl(Beam* curr_truck, float dt) { if (INPUTENGINE.getEventValue(EV_TRUCK_BRAKE) > 0.05f || @@ -5464,19 +4923,6 @@ } } -void RoRFrameListener::initHDR() -{ - Viewport *vp = mCamera->getViewport(); - Ogre::CompositorInstance *instance = Ogre::CompositorManager::getSingleton().addCompositor(vp, "HDR", 0); - Ogre::CompositorManager::getSingleton().setCompositorEnabled(vp, "HDR", true); - - // HDR needs a special listener - hdrListener = new HDRListener(); - instance->addListener(hdrListener); - hdrListener->notifyViewportSize(vp->getActualWidth(), vp->getActualHeight()); - hdrListener->notifyCompositor(instance); -} - void RoRFrameListener::hideGUI(bool visible) { Beam *curr_truck = BeamFactory::getSingleton().getCurrentTruck(); Modified: trunk/source/main/gameplay/RoRFrameListener.h =================================================================== --- trunk/source/main/gameplay/RoRFrameListener.h 2012-05-26 01:51:30 UTC (rev 2674) +++ trunk/source/main/gameplay/RoRFrameListener.h 2012-05-26 01:58:41 UTC (rev 2675) @@ -246,7 +246,7 @@ void gridScreenshots(Ogre::RenderWindow* pRenderWindow, Ogre::Camera* pCamera, const int& pGridSize, const Ogre::String& path, const Ogre::String& pFileName, const Ogre::String& pFileExtention, const bool& pStitchGridImages); void initDust(); - void initHDR(); + void initSoftShadows(); void initializeCompontents(); void updateGUI(float dt); // update engine panel @@ -265,10 +265,6 @@ public: // public methods - static float getGravity() { return gravity; }; - static void setGravity(float value); - - Collisions *getCollisions() { return collisions; }; Network *getNetwork() { return net; }; Ogre::RenderWindow *getRenderWindow() { return mWindow; }; @@ -277,8 +273,6 @@ Ogre::String saveTerrainMesh(); OverlayWrapper *getOverlayWrapper() { return ow; }; - Water *getWater() { return w; }; - Envmap *getEnvmap() { return envmap; }; bool RTSSgenerateShadersForMaterial(Ogre::String curMaterialName, Ogre::String normalTextureName); bool frameEnded(const Ogre::FrameEvent& evt); @@ -296,10 +290,11 @@ void hideGUI(bool visible); void hideMap(); void initTrucks(bool loadmanual, Ogre::String selected, Ogre::String selectedExtension = Ogre::String(), std::vector<Ogre::String> *truckconfig=0, bool enterTruck=false, Skin *skin=NULL); + void loadNewTerrain(Ogre::String terrainfile); void loadClassicTerrain(Ogre::String terrainfile); void loadNetTerrain(char *preselected_map); - void loadObject(const char* name, float px, float py, float pz, float rx, float ry, float rz, Ogre::SceneNode * bakeNode, const char* instancename, bool enable_collisions=true, int scripthandler=-1, const char *type=0, bool uniquifyMaterial=false); + void loadTerrain(Ogre::String terrainfile); void netDisconnectTruck(int number); void pauseSim(bool value); @@ -313,7 +308,6 @@ void showspray(bool s); void shutdown_final(); void startTimer(); - void unloadObject(const char* name); void updateRacingGUI(); void windowResized(Ogre::RenderWindow* rw); // this needs to be public so we can call it manually in embedded mode Modified: trunk/source/main/gameplay/terrain/TerrainManager.cpp =================================================================== --- trunk/source/main/gameplay/terrain/TerrainManager.cpp 2012-05-26 01:51:30 UTC (rev 2674) +++ trunk/source/main/gameplay/terrain/TerrainManager.cpp 2012-05-26 01:58:41 UTC (rev 2675) @@ -550,3 +550,14 @@ ScriptEngine::getSingleton().activateLogging(); #endif } + +void TerrainManager::setGravity(float value) +{ + gravity = value; + BeamFactory::getSingleton().recalcGravityMasses(); +} + +static float TerrainManager::getGravity() +{ + return gravity; +} Modified: trunk/source/main/gameplay/terrain/TerrainManager.h =================================================================== --- trunk/source/main/gameplay/terrain/TerrainManager.h 2012-05-26 01:51:30 UTC (rev 2674) +++ trunk/source/main/gameplay/terrain/TerrainManager.h 2012-05-26 01:58:41 UTC (rev 2675) @@ -31,6 +31,14 @@ void loadTerrain(Ogre::String filename); + void setGravity(float value); + float getGravity(); + + + inline Collisions *getCollisions() { return collisions; }; + inline Water *getWater() { return w; }; + inline Envmap *getEnvmap() { return envmap; }; + protected: // members Ogre::SceneManager *mSceneMgr; @@ -62,6 +70,7 @@ Ogre::Vector3 startPosition; bool useCaelum; int farclip; + float gravity; Ogre::Light *mainLight; Modified: trunk/source/main/gameplay/terrain/TerrainObjectManager.cpp =================================================================== --- trunk/source/main/gameplay/terrain/TerrainObjectManager.cpp 2012-05-26 01:51:30 UTC (rev 2674) +++ trunk/source/main/gameplay/terrain/TerrainObjectManager.cpp 2012-05-26 01:58:41 UTC (rev 2675) @@ -603,3 +603,539 @@ } } + +void TerrainObjectManager::unloadObject(const char* instancename) +{ + if (loadedObjects.find(std::string(instancename)) == loadedObjects.end()) + { + LOG("unable to unload object: " + std::string(instancename)); + return; + } + + loaded_object_t obj = loadedObjects[std::string(instancename)]; + + // check if it was already deleted + if (!obj.enabled) + return; + + // unload any collision tris + if (obj.collTris.size() > 0) + { + for(std::vector<int>::iterator it = obj.collTris.begin(); it != obj.collTris.end(); it++) + { + collisions->removeCollisionTri(*it); + } + } + + // and any collision boxes + if (obj.collBoxes.size() > 0) + { + for(std::vector<int>::iterator it = obj.collBoxes.begin(); it != obj.collBoxes.end(); it++) + { + collisions->removeCollisionBox(*it); + } + } + + obj.sceneNode->detachAllObjects(); + obj.sceneNode->setVisible(false); + obj.enabled = false; +} + +void TerrainObjectManager::loadObject(const char* name, float px, float py, float pz, float rx, float ry, float rz, SceneNode * bakeNode, const char* instancename, bool enable_collisions, int scripthandler, const char *type, bool uniquifyMaterial) +{ + ScopeLog log("object_"+String(name)); + if (type && !strcmp(type, "grid")) + { + // some fast grid object hacks :) + for(int x=0;x<500;x+=50) + for(int z=0;z<500;z+=50) + loadObject(name, px+x, py, pz+z, rx, ry, rz, bakeNode, 0, enable_collisions, scripthandler, 0); + return; + } + + // nice idea, but too many random hits + //if (abs(rx+1) < 0.001) rx = Math::RangeRandom(0, 360); + //if (abs(ry+1) < 0.001) ry = Math::RangeRandom(0, 360); + //if (abs(rz+1) < 0.001) rz = Math::RangeRandom(0, 360); + + if (strnlen(name, 250)==0) + return; + + //FILE *fd; + char fname[1024] = {}; + char oname[1024] = {}; + char mesh[1024] = {}; + char line[1024] = {}; + char collmesh[1024] = {}; + float scx = 0, scy = 0, scz = 0; + float lx = 0, hx = 0, ly = 0, hy = 0, lz = 0, hz = 0; + float srx = 0, sry = 0, srz = 0; + float drx = 0, dry = 0, drz = 0; + float fcx = 0, fcy = 0, fcz = 0; + bool forcecam=false; + bool ismovable=false; + + int event_filter = EVENT_ALL; + Quaternion rotation = Quaternion(Degree(rx), Vector3::UNIT_X)*Quaternion(Degree(ry), Vector3::UNIT_Y)*Quaternion(Degree(rz), Vector3::UNIT_Z); + + // try to load with UID first! + String odefgroup = ""; + String odefname = ""; + bool odefFound = false; + if (terrainUID != "" && !CACHE.stringHasUID(name)) + { + sprintf(fname,"%s-%s.odef", terrainUID.c_str(), name); + odefname = String(fname); + bool exists = ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(odefname); + if (exists) + { + odefgroup = ResourceGroupManager::getSingleton().findGroupContainingResource(odefname); + odefFound = true; + } + } + + if (!odefFound) + { + sprintf(fname,"%s.odef", name); + odefname = String(fname); + bool exists = ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(odefname); + if (exists) + { + odefgroup = ResourceGroupManager::getSingleton().findGroupContainingResource(odefname); + odefFound = true; + } + } + + + if (!CACHE.checkResourceLoaded(odefname, odefgroup)) + if (!odefFound) + { + LOG("Error while loading Terrain: could not find required .odef file: " + odefname + ". Ignoring entry."); + return; + } + + DataStreamPtr ds=ResourceGroupManager::getSingleton().openResource(odefname, odefgroup); + + ds->readLine(mesh, 1023); + if (String(mesh) == "LOD") + { + // LOD line is obsolete + ds->readLine(mesh, 1023); + } + + //scale + ds->readLine(line, 1023); + sscanf(line, "%f, %f, %f",&scx,&scy,&scz); + sprintf(oname,"object%i(%s)", objcounter,name); + objcounter++; + + + SceneNode *tenode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); + bool background_loading = BSETTING("Background Loading", false); + + MeshObject *mo = NULL; + if (String(mesh) != "none") + mo = new MeshObject(mSceneMgr, mesh, oname, tenode, NULL, background_loading); + + //mo->setQueryFlags(OBJECTS_MASK); + //tenode->attachObject(te); + tenode->setScale(scx,scy,scz); + tenode->setPosition(px,py,pz); + tenode->rotate(rotation); + tenode->pitch(Degree(-90)); + tenode->setVisible(true); + + // register in map + loaded_object_t *obj = &loadedObjects[std::string(instancename)]; + obj->instanceName = std::string(instancename); + obj->loadType = 0; + obj->enabled = true; + obj->sceneNode = tenode; + obj->collTris.clear(); + + + if (mo && uniquifyMaterial && instancename) + { + for(unsigned int i = 0; i < mo->getEntity()->getNumSubEntities(); i++) + { + SubEntity *se = mo->getEntity()->getSubEntity(i); + String matname = se->getMaterialName(); + String newmatname = matname + "/" + String(instancename); + //LOG("subentity " + TOSTRING(i) + ": "+ matname + " -> " + newmatname); + se->getMaterial()->clone(newmatname); + se->setMaterialName(newmatname); + } + } + + //String meshGroup = ResourceGroupManager::getSingleton().findGroupContainingResource(mesh); + //MeshPtr mainMesh = mo->getMesh(); + + //collision box(es) + bool virt=false; + bool rotating=false; + bool classic_ref=true; + // everything is of concrete by default + ground_model_t *gm = collisions->getGroundModelByString("concrete"); + char eventname[256]; + eventname[0]=0; + while (!ds->eof()) + { + size_t ll=ds->readLine(line, 1023); + + // little workaround to trim it + String lineStr = String(line); + Ogre::StringUtil::trim(lineStr); + + const char* ptline = lineStr.c_str(); + if (ll==0 || line[0]=='/' || line[0]==';') continue; + + if (!strcmp("end",ptline)) break; + if (!strcmp("movable", ptline)) {ismovable=true;continue;}; + if (!strcmp("localizer-h", ptline)) + { + localizers[free_localizer].position=Vector3(px,py,pz); + localizers[free_localizer].rotation=rotation; + localizers[free_localizer].type=Autopilot::LOCALIZER_HORIZONTAL; + free_localizer++; + continue; + } + if (!strcmp("localizer-v", ptline)) + { + localizers[free_localizer].position=Vector3(px,py,pz); + localizers[free_localizer].rotation=rotation; + localizers[free_localizer].type=Autopilot::LOCALIZER_VERTICAL; + free_localizer++; + continue; + } + if (!strcmp("localizer-ndb", ptline)) + { + localizers[free_localizer].position=Vector3(px,py,pz); + localizers[free_localizer].rotation=rotation; + localizers[free_localizer].type=Autopilot::LOCALIZER_NDB; + free_localizer++; + continue; + } + if (!strcmp("localizer-vor", ptline)) + { + localizers[free_localizer].position=Vector3(px,py,pz); + localizers[free_localizer].rotation=rotation; + localizers[free_localizer].type=Autopilot::LOCALIZER_VOR; + free_localizer++; + continue; + } + if (!strcmp("standard", ptline)) {classic_ref=false;tenode->pitch(Degree(90));continue;}; + if (!strncmp("sound", ptline, 5)) + { +#ifdef USE_OPENAL + if (!SoundScriptManager::getSingleton().isDisabled()) + { + char tmp[255]=""; + sscanf(ptline, "sound %s", tmp); + SoundScriptInstance *sound = SoundScriptManager::getSingleton().createInstance(tmp, MAX_TRUCKS+1, tenode); + sound->setPosition(tenode->getPosition(), Vector3::ZERO); + sound->start(); + } +#endif //USE_OPENAL + continue; + } + if (!strcmp("beginbox", ptline) || !strcmp("beginmesh", ptline)) + { + drx=dry=drz=0.0; + rotating=false; + virt=false; + forcecam=false; + event_filter=EVENT_NONE; + eventname[0]=0; + collmesh[0]=0; + gm = collisions->getGroundModelByString("concrete"); + continue; + }; + if (!strncmp("boxcoords", ptline, 9)) + { + sscanf(ptline, "boxcoords %f, %f, %f, %f, %f, %f",&lx,&hx,&ly,&hy,&lz, &hz); + continue; + } + if (!strncmp("mesh", ptline, 4)) + { + sscanf(ptline, "mesh %s",collmesh); + continue; + } + if (!strncmp("rotate", ptline, 6)) + { + sscanf(ptline, "rotate %f, %f, %f",&srx, &sry, &srz); + rotating=true; + continue; + } + if (!strncmp("forcecamera", ptline, 11)) + { + sscanf(ptline, "forcecamera %f, %f, %f",&fcx, &fcy, &fcz); + forcecam=true; + continue; + } + if (!strncmp("direction", ptline, 9)) + { + sscanf(ptline, "direction %f, %f, %f",&drx, &dry, &drz); + continue; + } + if (!strncmp("frictionconfig", ptline, 14) && strlen(ptline) > 15) + { + // load a custom friction config + collisions->loadGroundModelsConfigFile(String(ptline + 15)); + continue; + } + if ((!strncmp("stdfriction", ptline, 11) || !strncmp("usefriction", ptline, 11)) && strlen(ptline) > 12) + { + String modelName = String(ptline + 12); + gm = collisions->getGroundModelByString(modelName); + continue; + } + if (!strcmp("virtual", ptline)) {virt=true;continue;}; + if (!strncmp("event", ptline, 5)) + { + char ts[256]; + ts[0]=0; + sscanf(ptline, "event %s %s",eventname, ts); + if (!strncmp(ts, "avatar", 6)) + event_filter=EVENT_AVATAR; + else if (!strncmp(ts, "truck", 5)) + event_filter=EVENT_TRUCK; + else if (!strncmp(ts, "airplane", 8)) + event_filter=EVENT_AIRPLANE; + else if (!strncmp(ts, "delete", 8)) + event_filter=EVENT_DELETE; + + if (!strncmp(ts, "shoptruck", 9)) + terrainHasTruckShop=true; + + // fallback + if (strlen(ts) == 0) + event_filter=EVENT_ALL; + + continue; + } + //resp=sscanf(ptline, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %c",&lx,&hx,&ly, &hy,&lz, &hz, &srx, &sry, &srz,&type); + if (!strcmp("endbox", ptline)) + { + if (enable_collisions) + { + int boxnum = collisions->addCollisionBox(tenode, rotating, virt,px,py,pz,rx,ry,rz,lx,hx,ly,hy,lz,hz,srx,sry,srz,eventname, instancename, forcecam, Vector3(fcx, fcy, fcz), scx, scy, scz, drx, dry, drz, event_filter, scripthandler); + obj->collBoxes.push_back((boxnum)); + } + continue; + } + if (!strcmp("endmesh", ptline)) + { + collisions->addCollisionMesh(collmesh, Vector3(px,py,pz), tenode->getOrientation(), Vector3(scx, scy, scz), gm, &(obj->collTris)); + continue; + } + + if (!strncmp("particleSystem", ptline, 14) && tenode) + { + float x=0, y=0, z=0, scale=0; + char pname[255]="", sname[255]=""; + int res = sscanf(ptline, "particleSystem %f, %f, %f, %f, %s %s", &scale, &x, &y, &z, pname, sname); + if (res != 6) continue; + + // hacky: prevent duplicates + String paname = String(pname); + while(mSceneMgr->hasParticleSystem(paname)) + paname += "_"; + + // create particle system + ParticleSystem* pParticleSys = mSceneMgr->createParticleSystem(paname, String(sname)); + pParticleSys->setCastShadows(false); + pParticleSys->setVisibilityFlags(DEPTHMAP_DISABLED); // disable particles in depthmap + + // Some affectors may need its instance name (e.g. for script feedback purposes) +#ifdef USE_ANGELSCRIPT + unsigned short affCount = pParticleSys->getNumAffectors(); + ParticleAffector* pAff; + for(unsigned short i = 0; i<affCount; ++i) + { + pAff = pParticleSys->getAffector(i); + if (pAff->getType()=="ExtinguishableFire") + ((ExtinguishableFireAffector*)pAff)->setInstanceName(obj->instanceName); + } +#endif // USE_ANGELSCRIPT + + SceneNode *sn = tenode->createChildSceneNode(); + sn->attachObject(pParticleSys); + sn->pitch(Degree(90)); + continue; + } + + if (!strncmp("setMeshMaterial", ptline, 15)) + { + char mat[256]=""; + sscanf(ptline, "setMeshMaterial %s", mat); + if (mo->getEntity() && strnlen(mat,250)>0) + { + mo->getEntity()->setMaterialName(String(mat)); + // load it + //MaterialManager::getSingleton().load(String(mat), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + } + continue; + } + if (!strncmp("generateMaterialShaders", ptline, 23)) + { + char mat[256]=""; + sscanf(ptline, "generateMaterialShaders %s", mat); + if (BSETTING("Use RTShader System", false)) + { + Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(String(mat), Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME); + Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, String(mat)); + } + + continue; + } + if (!strncmp("playanimation", ptline, 13) && mo) + { + char animname[256]=""; + float speedfactorMin = 0, speedfactorMax = 0; + sscanf(ptline, "playanimation %f, %f, %s", &speedfactorMin, &speedfactorMax, animname); + if (tenode && mo->getEntity() && strnlen(animname,250)>0) + { + AnimationStateSet *s = mo->getEntity()->getAllAnimationStates(); + if (!s->hasAnimationState(String(animname))) + { + LOG("ODEF: animation '" + String(animname) + "' for mesh: '" + String(mesh) + "' in odef file '" + String(name) + ".odef' not found!"); + continue; + } + animated_object_t ao; + ao.node = tenode; + ao.ent = mo->getEntity(); + ao.speedfactor = speedfactorMin; + if (speedfactorMin != speedfactorMax) + ao.speedfactor = Math::RangeRandom(speedfactorMin, speedfactorMax); + ao.anim = 0; + try + { + ao.anim = mo->getEntity()->getAnimationState(String(animname)); + } catch (...) + { + ao.anim = 0; + } + if (!ao.anim) + { + LOG("ODEF: animation '" + String(animname) + "' for mesh: '" + String(mesh) + "' in odef file '" + String(name) + ".odef' not found!"); + continue; + } + ao.anim->setEnabled(true); + animatedObjects.push_back(ao); + } + continue; + } + if (!strncmp("drawTextOnMeshTexture", ptline, 21) && mo) + { + if (!mo->getEntity()) + continue; + String matName = mo->getEntity()->getSubEntity(0)->getMaterialName(); + MaterialPtr m = MaterialManager::getSingleton().getByName(matName); + if (m.getPointer() == 0) + { + LOG("ODEF: problem with drawTextOnMeshTexture command: mesh material not found: "+String(fname)+" : "+String(ptline)); + continue; + } + String texName = m->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName(); + Texture* background = (Texture *)TextureManager::getSingleton().getByName(texName).getPointer(); + if (!background) + { + LOG("ODEF: problem with drawTextOnMeshTexture command: mesh texture not found: "+String(fname)+" : "+String(ptline)); + continue; + } + + static int textureNumber = 0; + textureNumber++; + char tmpTextName[256]="", tmpMatName[256]=""; + sprintf(tmpTextName, "TextOnTexture_%d_Texture", textureNumber); + sprintf(tmpMatName, "TextOnTexture_%d_Material", textureNumber); // Make sure the texture is not WRITE_ONLY, we need to read the buffer to do the blending with the font (get the alpha for example) + TexturePtr texture = TextureManager::getSingleton().createManual(tmpTextName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, (Ogre::uint)background->getWidth(), (Ogre::uint)background->getHeight(), MIP_UNLIMITED , PF_X8R8G8B8, Ogre::TU_STATIC|Ogre::TU_AUTOMIPMAP, new ResourceBuffer()); + if (texture.getPointer() == 0) + { + LOG("ODEF: problem with drawTextOnMeshTexture command: could not create texture: "+String(fname)+" : "+String(ptline)); + continue; + } + + float x=0, y=0, w=0, h=0; + float a=0, r=0, g=0, b=0; + char fontname[256]=""; + char text[256]=""; + char option='l'; + int res = sscanf(ptline, "drawTextOnMeshTexture %f, %f, %f, %f, %f, %f, %f, %f, %c, %s %s", &x, &y, &w, &h, &r, &g, &b, &a, &option, fontname, text); + if (res < 11) + { + LOG("ODEF: problem with drawTextOnMeshTexture command: "+String(fname)+" : "+String(ptline)); + continue; + } + + // cehck if we got a template argument + if (!strncmp(text, "{{argument1}}", 13)) + strncpy(text, instancename, 250); + + // replace '_' with ' ' + char *text_pointer = text; + while (*text_pointer!=0) {if (*text_pointer=='_') *text_pointer=' ';text_pointer++;}; + + Font* font = (Font *)FontManager::getSingleton().getByName(String(fontname)).getPointer(); + if (!font) + { + LOG("ODEF: problem with drawTextOnMeshTexture command: font not found: "+String(fname)+" : "+String(ptline)); + continue; + } + + + //Draw the background to the new texture + texture->getBuffer()->blit(background->getBuffer()); + + x = background->getWidth() * x; + y = background->getHeight() * y; + w = background->getWidth() * w; + h = background->getHeight() * h; + + Image::Box box = Image::Box((size_t)x, (size_t)y, (size_t)(x+w), (size_t)(y+h)); + WriteToTexture(String(text), texture, box, font, ColourValue(r, g, b, a), option); + + // we can save it to disc for debug purposes: + //SaveImage(texture, "test.png"); + + m->clone(tmpMatName); + MaterialPtr mNew = MaterialManager::getSingleton().getByName(tmpMatName); + mNew->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(tmpTextName); + + mo->getEntity()->setMaterialName(String(tmpMatName)); + continue; + } + + LOG("ODEF: unknown command in "+String(fname)+" : "+String(ptline)); + } + + //add icons if type is set +#ifdef USE_MYGUI + String typestr = ""; + if (type && surveyMap) + { + typestr = String(type); + // hack for raceways + if (!strcmp(name, "chp-checkpoint")) + typestr = "checkpoint"; + if (!strcmp(name, "chp-start")) + typestr = "racestart"; + if (!strncmp(name, "road", 4)) + typestr = "road"; + + if (typestr != String("") && typestr != String("road") && typestr != String("sign")) + { + MapEntity *e = surveyMap->createMapEntity(typestr); + if (e) + { + e->setVisibility(true); + e->setPosition(px, pz); + e->setRotation(Radian(ry)); + + if (String(name) != String("")) + e->setDescription(String(instancename)); + } + } + } +#endif //USE_MYGUI +} \ No newline at end of file Modified: trunk/source/main/gameplay/terrain/TerrainObjectManager.h =================================================================== --- trunk/source/main/gameplay/terrain/TerrainObjectManager.h 2012-05-26 01:51:30 UTC (rev 2674) +++ trunk/source/main/gameplay/terrain/TerrainObjectManager.h 2012-05-26 01:58:41 UTC (rev 2675) @@ -35,6 +35,9 @@ Ogre::SceneManager *mSceneMgr; TerrainManager *terrainManager; + void loadObject(const char* name, float px, float py, float pz, float rx, float ry, float rz, Ogre::SceneNode * bakeNode, const char* instancename, bool enable_collisions=true, int scripthandler=-1, const char *type=0, bool uniquifyMaterial=false); + void unloadObject(const char* name); + }; #endif // TERRAINOBJECTMANAGER_H__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel