bool AudioResourceManager::initialize()
{
    srand(time(NULL));
    Ogre::String path = Ogre::macBundlePath() + "/Contents/Resources/media/config/audio_events.xml";
    //xml_document<> doc;    // character type defaults to char
    FILE *audioConfigFile = fopen(path.data(), "r");
    
    std::vector<char> buffer;
    int c;
    while (EOF !=(c=getc(audioConfigFile))){
        buffer.push_back(c);
    }
   
    
    char buf[buffer.size()];
    for (int i = 0; i < buffer.size(); i++){
        buf[i] = buffer[i];
    }
    XMLDocument doc;
    doc.Parse(buf);

    XMLElement *eventIter = doc.FirstChildElement()->FirstChildElement();
    
    
    unsigned int currentHandle = 0;
    
    while (eventIter != NULL)
    {
        XMLNode *unitIter = eventIter->FirstChildElement()->NextSiblingElement();
        std::string eventName = eventIter->FirstChildElement()->GetText();
        
        while (unitIter != NULL) {
            AudioResource unit;
            
            unit.filename = unitIter->FirstChildElement("filename")->GetText();// first_node("filename")->value();
            printf("filename: %s\n", unit.filename.c_str());
            unit.panning = atof(unitIter->FirstChildElement("panning")->GetText());
            unit.pitch = atof(unitIter->FirstChildElement("pitch")->GetText());
            unit.looping = atoi(unitIter->FirstChildElement("looping")->GetText());
            unit.gain = atof(unitIter->FirstChildElement("gain")->GetText());
            unit.bufferHandle = -1;
            unit.sourceHandle = -1;
            if ( eventName == "apply_force_left" || eventName == "apply_force_right" || eventName=="fall_off") unit.canStop = false;
            else unit.canStop = true;
            alGenSources(1, &unit.sourceHandle);
            resources[eventName].push_back(unit);
            
            unitIter = unitIter->NextSibling();
        }
        
        eventIter = eventIter->NextSiblingElement();
    }
    return true;
}
Esempio n. 2
0
bool OgreDetourTileCache::saveAll(Ogre::String filename)
{
    if (!m_tileCache) {
        Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::saveAll("+filename+"). Could not save tilecache, no tilecache to save.");
        return false;
    }

       FILE* fp = fopen(filename.data(), "wb");
       if (!fp) {
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::saveAll("+filename+"). Could not save file.");
           return false;
       }

// Store header.
       TileCacheSetHeader header;
       header.magic = TILECACHESET_MAGIC;
       header.version = TILECACHESET_VERSION;
       header.numTiles = 0;
       for (int i = 0; i < m_tileCache->getTileCount(); ++i)
       {
               const dtCompressedTile* tile = m_tileCache->getTile(i);
               if (!tile || !tile->header || !tile->dataSize) continue;
               header.numTiles++;
       }
       memcpy(&header.cacheParams, m_tileCache->getParams(), sizeof(dtTileCacheParams));
       memcpy(&header.meshParams, m_recast->m_navMesh->getParams(), sizeof(dtNavMeshParams));
       memcpy(&header.recastConfig, &m_cfg, sizeof(rcConfig));
       fwrite(&header, sizeof(TileCacheSetHeader), 1, fp);

       // Store tiles.
       for (int i = 0; i < m_tileCache->getTileCount(); ++i)
       {
               const dtCompressedTile* tile = m_tileCache->getTile(i);
               if (!tile || !tile->header || !tile->dataSize) continue;

               TileCacheTileHeader tileHeader;
               tileHeader.tileRef = m_tileCache->getTileRef(tile);
               tileHeader.dataSize = tile->dataSize;
               fwrite(&tileHeader, sizeof(tileHeader), 1, fp);

               fwrite(tile->data, tile->dataSize, 1, fp);
       }

       fclose(fp);
       return true;
}
Esempio n. 3
0
Ogre::MaterialPtr AssetLoader::createMaterial(Ogre::String name, int index, aiMaterial* mat)
{
	Ogre::MaterialManager* omatMgr = Ogre::MaterialManager::getSingletonPtr();

	std::ostringstream matname;
	matname << name.data() << "_mat";
	matname.widen(4);
	matname.fill('0');
	matname << index;
	Ogre::String matName = matname.str();

	Ogre::ResourceManager::ResourceCreateOrRetrieveResult status = omatMgr->createOrRetrieve(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
	Ogre::MaterialPtr omat = status.first;

	aiColor4D clr(1.0, 1.0, 1.0, 1.0);
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_DIFFUSE, &clr);
	omat->getTechnique(0)->getPass(0)->setDiffuse(clr.r, clr.g, clr.b, clr.a);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_SPECULAR, &clr);
	omat->getTechnique(0)->getPass(0)->setSpecular(clr.r, clr.g, clr.b, clr.a);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_AMBIENT, &clr);
	omat->getTechnique(0)->getPass(0)->setAmbient(clr.r, clr.g, clr.b);
	
	aiGetMaterialColor(mat, AI_MATKEY_COLOR_EMISSIVE, &clr);
	omat->getTechnique(0)->getPass(0)->setSelfIllumination(clr.r, clr.g, clr.b);

	omat->getTechnique(0)->getPass(0)->setShadingMode(Ogre::SO_GOURAUD);
	omat->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	omat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
	omat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true);
	//omat->getTechnique(0)->getPass(0)->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	
	aiString path;
	aiReturn res = mat->GetTexture(aiTextureType_DIFFUSE, 0, &path);
	if (res == AI_SUCCESS) {
		Ogre::TextureUnitState* stateBase = omat->getTechnique(0)->getPass(0)->createTextureUnitState();
		stateBase->setColourOperation(Ogre::LBO_MODULATE);
		stateBase->setTextureName(path.data);
	}
	
	return omat;
}
Esempio n. 4
0
bool OgreDetourTileCache::loadAll(Ogre::String filename)
{
       FILE* fp = fopen(filename.data(), "rb");
       if (!fp) {
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). Could not open file.");
           return false;
       }

       // Read header.
       TileCacheSetHeader header;
       fread(&header, sizeof(TileCacheSetHeader), 1, fp);
       if (header.magic != TILECACHESET_MAGIC)
       {
           fclose(fp);
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). File does not appear to contain valid tilecache data.");
           return false;
       }
       if (header.version != TILECACHESET_VERSION)
       {
           fclose(fp);
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). File contains a different version of the tilecache data format ("+Ogre::StringConverter::toString(header.version)+" instead of "+Ogre::StringConverter::toString(TILECACHESET_VERSION)+").");
           return false;
       }

       m_recast->m_navMesh = dtAllocNavMesh();
       if (!m_recast->m_navMesh)
       {
           fclose(fp);
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). Could not allocate navmesh.");
           return false;
       }
       dtStatus status = m_recast->m_navMesh->init(&header.meshParams);
       if (dtStatusFailed(status))
       {
           fclose(fp);
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). Could not init navmesh.");
           return false;
       }

       m_tileCache = dtAllocTileCache();
       if (!m_tileCache)
       {
           fclose(fp);
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). Could not allocate tilecache.");
           return false;
       }
       status = m_tileCache->init(&header.cacheParams, m_talloc, m_tcomp, m_tmproc);
       if (dtStatusFailed(status))
       {
           fclose(fp);
           Ogre::LogManager::getSingletonPtr()->logMessage("Error: OgreDetourTileCache::loadAll("+filename+"). Could not init tilecache.");
           return false;
       }

       memcpy(&m_cfg, &header.recastConfig, sizeof(rcConfig));

       // Read tiles.
       for (int i = 0; i < header.numTiles; ++i)
       {
               TileCacheTileHeader tileHeader;
               fread(&tileHeader, sizeof(tileHeader), 1, fp);
               if (!tileHeader.tileRef || !tileHeader.dataSize)
                       break;

               unsigned char* data = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM);
               if (!data) break;
               memset(data, 0, tileHeader.dataSize);
               fread(data, tileHeader.dataSize, 1, fp);

               dtCompressedTileRef tile = 0;
               m_tileCache->addTile(data, tileHeader.dataSize, DT_COMPRESSEDTILE_FREE_DATA, &tile);

               if (tile)
                       m_tileCache->buildNavMeshTile(tile, m_recast->m_navMesh);
       }

       fclose(fp);


       // Init recast navmeshquery with created navmesh (in OgreRecast component)
       m_recast->m_navQuery = dtAllocNavMeshQuery();
       m_recast->m_navQuery->init(m_recast->m_navMesh, 2048);


       // Config
       // TODO handle this nicer, also inputGeom is not inited, making some functions crash
       m_cellSize = m_cfg.cs;
       m_tileSize = m_cfg.tileSize;

       // cache bounding box
       const float* bmin = m_cfg.bmin;
       const float* bmax = m_cfg.bmax;

       // Copy loaded config back to recast module
       memcpy(&m_recast->m_cfg, &m_cfg, sizeof(rcConfig));

       m_tileSize = m_cfg.tileSize;
       m_cellSize = m_cfg.cs;
       m_tcparams = header.cacheParams;

       // Determine grid size (number of tiles) based on bounding box and grid cell size
       int gw = 0, gh = 0;
       rcCalcGridSize(bmin, bmax, m_cellSize, &gw, &gh);   // Calculates total size of voxel grid
       const int ts = m_tileSize;
       const int tw = (gw + ts-1) / ts;    // Tile width
       const int th = (gh + ts-1) / ts;    // Tile height
       m_tw = tw;
       m_th = th;


       Ogre::LogManager::getSingletonPtr()->logMessage("Total Voxels: "+Ogre::StringConverter::toString(gw) + " x " + Ogre::StringConverter::toString(gh));
       Ogre::LogManager::getSingletonPtr()->logMessage("Tilesize: "+Ogre::StringConverter::toString(m_tileSize)+"  Cellsize: "+Ogre::StringConverter::toString(m_cellSize));
       Ogre::LogManager::getSingletonPtr()->logMessage("Tiles: "+Ogre::StringConverter::toString(m_tw)+" x "+Ogre::StringConverter::toString(m_th));


       // Max tiles and max polys affect how the tile IDs are caculated.
       // There are 22 bits available for identifying a tile and a polygon.
       int tileBits = rcMin((int)dtIlog2(dtNextPow2(tw*th*EXPECTED_LAYERS_PER_TILE)), 14);
       if (tileBits > 14) tileBits = 14;
       int polyBits = 22 - tileBits;
       m_maxTiles = 1 << tileBits;
       m_maxPolysPerTile = 1 << polyBits;
       Ogre::LogManager::getSingletonPtr()->logMessage("Max Tiles: " + Ogre::StringConverter::toString(m_maxTiles));
       Ogre::LogManager::getSingletonPtr()->logMessage("Max Polys: " + Ogre::StringConverter::toString(m_maxPolysPerTile));
       // End config ////

       buildInitialNavmesh();
       return true;
}