void SoundScriptManager::parseScript(DataStreamPtr& stream, const String& groupName) { SoundScriptTemplate* sst = 0; String line = ""; std::vector<String> vecparams; LOG("SoundScriptManager: Parsing script "+stream->getName()); while (!stream->eof()) { line = RoR::Utils::SanitizeUtf8String(stream->getLine()); // ignore comments & blanks if (!(line.length() == 0 || line.substr(0, 2) == "//")) { if (sst == 0) { // no current SoundScript // so first valid data should be a SoundScript name LOG("SoundScriptManager: creating template "+line); sst = createTemplate(line, groupName, stream->getName()); if (!sst) { // there is a name collision for this Sound Script LOG("SoundScriptManager: Error, this sound script is already defined: "+line); skipToNextOpenBrace(stream); skipToNextCloseBrace(stream); continue; } // skip to and over next { skipToNextOpenBrace(stream); } else { // already in a ss if (line == "}") { // finished ss sst = 0; } else { // attribute // split params on space Ogre::StringVector veclineparams = StringUtil::split(line, "\t ", 0); if (!sst->setParameter(veclineparams)) { LOG("Bad SoundScript attribute line: '" + line + "' in " + stream->getName()); } } } } } }
//--------------------------------------------------------------------- void GpuProgramManager::saveMicrocodeCache( DataStreamPtr stream ) const { if (!stream->isWriteable()) { OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Unable to write to stream " + stream->getName(), "GpuProgramManager::saveMicrocodeCache"); } // write the size of the array size_t sizeOfArray = mMicrocodeCache.size(); stream->write(&sizeOfArray, sizeof(size_t)); // loop the array and save it MicrocodeMap::const_iterator iter = mMicrocodeCache.begin(); MicrocodeMap::const_iterator iterE = mMicrocodeCache.end(); for ( ; iter != iterE ; iter++ ) { // saves the name of the shader { const String & nameOfShader = iter->first; size_t stringLength = nameOfShader.size(); stream->write(&stringLength, sizeof(size_t)); stream->write(&nameOfShader[0], stringLength); } // saves the microcode { const Microcode & microcodeOfShader = iter->second; size_t microcodeLength = microcodeOfShader->size(); stream->write(µcodeLength, sizeof(size_t)); stream->write(microcodeOfShader->getPtr(), microcodeLength); } } }
void SkinManager::parseScript(DataStreamPtr& stream, const String& groupName) { try { String line = ""; Skin *pSkin = 0; while(!stream->eof()) { line = stream->getLine(); // Ignore blanks & comments if (!line.length() || line.substr(0, 2) == "//") { continue; } if (!pSkin) { // No current skin // So first valid data should be skin name #ifdef ROR_USE_OGRE_1_9 pSkin = (Skin *)createResource(line, groupName).getPointer(); #else pSkin = (Skin *)create(line, groupName).getPointer(); #endif if (pSkin) { pSkin->_notifyOrigin(stream->getName()); stream->skipLine("{"); } } else { // Already in skin if (line == "}") { // Finished //addImpl((Ogre::ResourcePtr)pSkin); pSkin = 0; // NB skin isn't loaded until required } else { ParseSkinAttribute(line, pSkin); } } } } catch(Ogre::ItemIdentityException e) { // this catches duplicates -> to be ignored // this happens since we load the full skin data off the cache, so we don't need // to re-add it to the SkinManager return; } }
//----------------------------------------------------------------------------------- void HlmsManager::parseScript(DataStreamPtr& stream, const String& groupName) { vector<char>::type fileData; fileData.resize( stream->size() + 1 ); if( !fileData.empty() ) { stream->read( &fileData[0], stream->size() ); //Add null terminator just in case (to prevent bad input) fileData.back() = '\0'; HlmsJson hlmsJson( this ); hlmsJson.loadMaterials( stream->getName(), groupName, &fileData[0] ); } }
//--------------------------------------------------------------------- void SkeletonSerializer::exportSkeleton(const Skeleton* pSkeleton, DataStreamPtr stream, SkeletonVersion ver, Endian endianMode) { setWorkingVersion(ver); // Decide on endian mode determineEndianness(endianMode); String msg; mStream = stream; if (!stream->isWriteable()) { OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Unable to write to stream " + stream->getName(), "SkeletonSerializer::exportSkeleton"); } writeFileHeader(); // Write main skeleton data LogManager::getSingleton().logMessage("Exporting bones.."); writeSkeleton(pSkeleton, ver); LogManager::getSingleton().logMessage("Bones exported."); // Write all animations unsigned short numAnims = pSkeleton->getNumAnimations(); LogManager::getSingleton().stream() << "Exporting animations, count=" << numAnims; for (unsigned short i = 0; i < numAnims; ++i) { Animation* pAnim = pSkeleton->getAnimation(i); LogManager::getSingleton().stream() << "Exporting animation: " << pAnim->getName(); writeAnimation(pSkeleton, pAnim, ver); LogManager::getSingleton().logMessage("Animation exported."); } // Write links Skeleton::LinkedSkeletonAnimSourceIterator linkIt = pSkeleton->getLinkedSkeletonAnimationSourceIterator(); while(linkIt.hasMoreElements()) { const LinkedSkeletonAnimationSource& link = linkIt.getNext(); writeSkeletonAnimationLink(pSkeleton, link); } }
//----------------------------------------------------------------------------------- void HlmsManager::loadMaterials( const String &filename, const String &groupName ) { DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource( filename, groupName ); vector<char>::type fileData; fileData.resize( stream->size() + 1 ); if( !fileData.empty() ) { stream->read( &fileData[0], stream->size() ); //Add null terminator just in case (to prevent bad input) fileData.back() = '\0'; HlmsJson hlmsJson( this ); hlmsJson.loadMaterials( stream->getName(), groupName, &fileData[0] ); } }
//--------------------------------------------------------------------- void FontManager::parseScript(DataStreamPtr& stream, const String& groupName) { String line; FontPtr pFont; while( !stream->eof() ) { line = stream->getLine(); // Ignore blanks & comments if( !line.length() || line.substr( 0, 2 ) == "//" ) { continue; } else { if (pFont.isNull()) { // No current font // So first valid data should be font name if (StringUtil::startsWith(line, "font ")) { // chop off the 'particle_system ' needed by new compilers line = line.substr(5); } pFont = create(line, groupName); pFont->_notifyOrigin(stream->getName()); // Skip to and over next { stream->skipLine("{"); } else { // Already in font if (line == "}") { // Finished pFont.setNull(); // NB font isn't loaded until required } else { parseAttribute(line, pFont); } } } } }
void Serializer::popInnerChunk(const DataStreamPtr& stream) { #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE if (!mChunkSizeStack.empty()){ size_t pos = stream->tell(); if (pos != static_cast<size_t>(mChunkSizeStack.back()) && !stream->eof() && mReportChunkErrors){ LogManager::getSingleton().logMessage("Corrupted chunk detected! Stream name: " + stream->getName()); } mChunkSizeStack.pop_back(); } #endif }
//--------------------------------------------------------------------- unsigned short Serializer::readChunk(DataStreamPtr& stream) { #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE size_t pos = stream->tell(); #endif unsigned short id; readShorts(stream, &id, 1); readInts(stream, &mCurrentstreamLen, 1); #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE if (!mChunkSizeStack.empty() && !stream->eof()){ if (pos != static_cast<size_t>(mChunkSizeStack.back()) && mReportChunkErrors){ LogManager::getSingleton().logMessage("Corrupted chunk detected! Stream name: '" + stream->getName() + "' Chunk id: " + StringConverter::toString(id)); } mChunkSizeStack.back() = pos + mCurrentstreamLen; } #endif return id; }
//--------------------------------------------------------------------- void OverlayManager::parseScript(DataStreamPtr& stream, const String& groupName) { // check if we've seen this script before (can happen if included // multiple times) if (!stream->getName().empty() && mLoadedScripts.find(stream->getName()) != mLoadedScripts.end()) { LogManager::getSingleton().logMessage( "Skipping loading overlay include: '" + stream->getName() + " as it is already loaded."); return; } String line; Overlay* pOverlay = 0; bool skipLine; while(!stream->eof()) { bool isATemplate = false; skipLine = false; line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (line.substr(0,8) == "#include") { vector<String>::type params = StringUtil::split(line, "\t\n ()<>"); DataStreamPtr includeStream = ResourceGroupManager::getSingleton().openResource( params[1], groupName); parseScript(includeStream, groupName); continue; } if (!pOverlay) { // No current overlay // check to see if there is a template if (line.substr(0,8) == "template") { isATemplate = true; } else { // So first valid data should be overlay name if (StringUtil::startsWith(line, "overlay ")) { // chop off the 'particle_system ' needed by new compilers line = line.substr(8); } pOverlay = create(line); pOverlay->_notifyOrigin(stream->getName()); // Skip to and over next { skipToNextOpenBrace(stream); skipLine = true; } } if ((pOverlay && !skipLine) || isATemplate) { // Already in overlay vector<String>::type params = StringUtil::split(line, "\t\n ()"); if (line == "}") { // Finished overlay pOverlay = 0; } else if (parseChildren(stream,line, pOverlay, isATemplate, NULL)) { } else { // Attribute if (!isATemplate) { parseAttrib(line, pOverlay); } } } } } // record as parsed mLoadedScripts.insert(stream->getName()); }
//----------------------------------------------------------------------- void ParticleSystemManager::parseScript(DataStreamPtr& stream, const String& groupName) { #if OGRE_USE_NEW_COMPILERS == 1 ScriptCompilerManager::getSingleton().parseScript(stream, groupName); #else // OGRE_USE_NEW_COMPILERS String line; ParticleSystem* pSys; std::vector<String> vecparams; pSys = 0; while(!stream->eof()) { line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (pSys == 0) { // No current system // So first valid data should be a system name if (StringUtil::startsWith(line, "particle_system ")) { // chop off the 'particle_system ' needed by new compilers line = line.substr(16); } pSys = createTemplate(line, groupName); pSys->_notifyOrigin(stream->getName()); // Skip to and over next { skipToNextOpenBrace(stream); } else { // Already in a system if (line == "}") { // Finished system pSys = 0; } else if (line.substr(0,7) == "emitter") { // new emitter // Get typename vecparams = StringUtil::split(line, "\t "); if (vecparams.size() < 2) { // Oops, bad emitter LogManager::getSingleton().logMessage("Bad particle system emitter line: '" + line + "' in " + pSys->getName()); skipToNextCloseBrace(stream); } skipToNextOpenBrace(stream); parseNewEmitter(vecparams[1], stream, pSys); } else if (line.substr(0,8) == "affector") { // new affector // Get typename vecparams = StringUtil::split(line, "\t "); if (vecparams.size() < 2) { // Oops, bad affector LogManager::getSingleton().logMessage("Bad particle system affector line: '" + line + "' in " + pSys->getName()); skipToNextCloseBrace(stream); } skipToNextOpenBrace(stream); parseNewAffector(vecparams[1],stream, pSys); } else { // Attribute parseAttrib(line, pSys); } } } } #endif // OGRE_USE_NEW_COMPILERS }
void LuaManager::parseScript(DataStreamPtr& stream, const String&) { currentFileName = stream->getName(); doString(stream->getAsString()); }
//--------------------------------------------------------------------- Codec::DecodeResult ILImageCodec::decode(DataStreamPtr& input) const { // DevIL variables ILuint ImageName; ILint ImageFormat, BytesPerPixel, ImageType; ImageData* imgData = new ImageData(); MemoryDataStreamPtr output; // Load the image ilGenImages( 1, &ImageName ); ilBindImage( ImageName ); // Put it right side up ilEnable(IL_ORIGIN_SET); ilSetInteger(IL_ORIGIN_MODE, IL_ORIGIN_UPPER_LEFT); // Keep DXTC(compressed) data if present ilSetInteger(IL_KEEP_DXTC_DATA, IL_TRUE); // Load image from stream, cache into memory MemoryDataStream memInput(input); ilLoadL( mIlType, memInput.getPtr(), static_cast< ILuint >(memInput.size())); // Check if everything was ok ILenum PossibleError = ilGetError() ; if( PossibleError != IL_NO_ERROR ) { OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, "IL Error", iluErrorString(PossibleError) ) ; } ImageFormat = ilGetInteger( IL_IMAGE_FORMAT ); ImageType = ilGetInteger( IL_IMAGE_TYPE ); // Convert image if ImageType is incompatible with us (double or long) if(ImageType != IL_BYTE && ImageType != IL_UNSIGNED_BYTE && ImageType != IL_FLOAT && ImageType != IL_UNSIGNED_SHORT && ImageType != IL_SHORT) { ilConvertImage(ImageFormat, IL_FLOAT); ImageType = IL_FLOAT; } // Converted paletted images if(ImageFormat == IL_COLOUR_INDEX) { ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE); ImageFormat = IL_BGRA; ImageType = IL_UNSIGNED_BYTE; } // Now sets some variables BytesPerPixel = ilGetInteger( IL_IMAGE_BYTES_PER_PIXEL ); imgData->format = ILUtil::ilFormat2OgreFormat( ImageFormat, ImageType ); imgData->width = ilGetInteger( IL_IMAGE_WIDTH ); imgData->height = ilGetInteger( IL_IMAGE_HEIGHT ); imgData->depth = ilGetInteger( IL_IMAGE_DEPTH ); imgData->num_mipmaps = ilGetInteger ( IL_NUM_MIPMAPS ); imgData->flags = 0; if(imgData->format == PF_UNKNOWN) { std::stringstream err; err << "Unsupported devil format ImageFormat=" << std::hex << ImageFormat << " ImageType="<< ImageType << std::dec; ilDeleteImages( 1, &ImageName ); OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, err.str(), "ILImageCodec::decode" ) ; } // Check for cubemap //ILuint cubeflags = ilGetInteger ( IL_IMAGE_CUBEFLAGS ); size_t numFaces = ilGetInteger ( IL_NUM_IMAGES ) + 1; if(numFaces == 6) imgData->flags |= IF_CUBEMAP; else numFaces = 1; // Support only 1 or 6 face images for now // Keep DXT data (if present at all and the GPU supports it) ILuint dxtFormat = ilGetInteger( IL_DXTC_DATA_FORMAT ); if(dxtFormat != IL_DXT_NO_COMP && Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability( RSC_TEXTURE_COMPRESSION_DXT )) { imgData->format = ILUtil::ilFormat2OgreFormat( dxtFormat, ImageType ); imgData->flags |= IF_COMPRESSED; // Validate that this devil version saves DXT mipmaps if(imgData->num_mipmaps>0) { ilBindImage(ImageName); ilActiveMipmap(1); if((size_t)ilGetInteger( IL_DXTC_DATA_FORMAT ) != dxtFormat) { imgData->num_mipmaps=0; LogManager::getSingleton().logMessage( "Warning: Custom mipmaps for compressed image "+input->getName()+" were ignored because they are not loaded by this DevIL version"); } } } // Calculate total size from number of mipmaps, faces and size imgData->size = Image::calculateSize(imgData->num_mipmaps, numFaces, imgData->width, imgData->height, imgData->depth, imgData->format); // Bind output buffer output.bind(new MemoryDataStream(imgData->size)); size_t offset = 0; // Dimensions of current mipmap size_t width = imgData->width; size_t height = imgData->height; size_t depth = imgData->depth; // Transfer data for(size_t mip=0; mip<=imgData->num_mipmaps; ++mip) { for(size_t i = 0; i < numFaces; ++i) { ilBindImage(ImageName); if(numFaces > 1) ilActiveImage(i); if(imgData->num_mipmaps > 0) ilActiveMipmap(mip); /// Size of this face size_t imageSize = PixelUtil::getMemorySize( width, height, depth, imgData->format); if(imgData->flags & IF_COMPRESSED) { // Compare DXT size returned by DevIL with our idea of the compressed size if(imageSize == ilGetDXTCData(NULL, 0, dxtFormat)) { // Retrieve data from DevIL ilGetDXTCData((unsigned char*)output->getPtr()+offset, imageSize, dxtFormat); } else { LogManager::getSingleton().logMessage( "Warning: compressed image "+input->getName()+" size mismatch, devilsize="+StringConverter::toString(ilGetDXTCData(NULL, 0, dxtFormat))+" oursize="+ StringConverter::toString(imageSize)); } } else { /// Retrieve data from DevIL PixelBox dst(width, height, depth, imgData->format, (unsigned char*)output->getPtr()+offset); ILUtil::toOgre(dst); } offset += imageSize; } /// Next mip if(width!=1) width /= 2; if(height!=1) height /= 2; if(depth!=1) depth /= 2; } // Restore IL state ilDisable(IL_ORIGIN_SET); ilDisable(IL_FORMAT_SET); ilDeleteImages( 1, &ImageName ); DecodeResult ret; ret.first = output; ret.second = CodecDataPtr(imgData); return ret; }