//-----------------------------------------------------------------------
    void ParticleSystemManager::parseNewAffector(const String& type, DataStreamPtr& stream, ParticleSystem* sys)
    {
        // Create new affector
        ParticleAffector* pAff = sys->addAffector(type);
        // Parse affector details
        String line;

        while(!stream->eof())
        {
            line = stream->getLine();
            // Ignore comments & blanks
            if (!(line.length() == 0 || line.substr(0,2) == "//"))
            {
                if (line == "}")
                {
                    // Finished affector
                    break;
                }
                else
                {
                    // Attribute
                    StringUtil::toLowerCase(line);
                    parseAffectorAttrib(line, pAff);
                }
            }
        }
    }
Пример #2
0
	virtual GpuProgramPtr generateFragmentShader(Perm permutation)
	{
		/// Create shader
		if (mMasterSource.empty())
		{
			DataStreamPtr ptrMasterSource = ResourceGroupManager::getSingleton().openResource(
				 "DeferredShading/post/LightMaterial_ps.cg"
				, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
			assert(ptrMasterSource.isNull()==false);
			mMasterSource = ptrMasterSource->getAsString();
		}

		assert(mMasterSource.empty()==false);

		// Create name
		String name = mBaseName+StringConverter::toString(permutation)+"_ps";		

		// Create shader object
		HighLevelGpuProgramPtr ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram(
			name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			"cg", GPT_FRAGMENT_PROGRAM);
		ptrProgram->setSource(mMasterSource);
		ptrProgram->setParameter("entry_point","main");
	    ptrProgram->setParameter("profiles","ps_2_x arbfp1");
		// set up the preprocessor defines
		// Important to do this before any call to get parameters, i.e. before the program gets loaded
		ptrProgram->setParameter("compile_arguments", getPPDefines(permutation));

		setUpBaseParameters(ptrProgram->getDefaultParameters());

		return GpuProgramPtr(ptrProgram);
	}
	//-----------------------------------------------------------------------
	void CGUIParticleSystemManager::parseNewEmitter(const CGUIString& type, DataStreamPtr& stream, CGUIParticleSystem* sys)
	{
		// Create new emitter
		CGUIParticleEmitter* pEmit = sys->addEmitter(type);
		// Parse emitter details
		CGUIString line;

		while(!stream->eof())
		{
			line = stream->getLine();
			// Ignore comments & blanks
			if (!(line.length() == 0 || line.substr(0,2) == "//"))
			{
				if (line == "}")
				{
					// Finished emitter
					break;
				}
				else
				{
					// Attribute
					StringUtil::toLowerCase(line);
					parseEmitterAttrib(line, pEmit);
				}
			}
		}



	}
Пример #4
0
Ogre::DataStreamPtr TerrainGeometryManager::getPageConfig(int x, int z)
{
	String cfg = getPageConfigFilename(x, z);

	try
	{
		LOG("loading page config for page " + XZSTR(x,z) + " : " + cfg);
		DataStreamPtr ds = ResourceGroupManager::getSingleton().openResource(cfg, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

		if (!ds.isNull() && ds->isReadable())
		{
			return ds;
		}
	} catch (...)
	{

	}

	LOG("error loading page config for page " + XZSTR(x,z) + " : " + cfg);

	if (x != 0 || z != 0)
	{
		LOG("loading default page config: " + cfg + " instead");
		return getPageConfig(0, 0);
	}

	return DataStreamPtr();
}
Пример #5
0
// OgreScriptBuilder
int OgreScriptBuilder::LoadScriptSection(const char *filename)
{
	// Open the script file
	string scriptFile = filename;

	DataStreamPtr ds;
	try
	{
		ds = ResourceGroupManager::getSingleton().openResource(scriptFile, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

	} catch(Ogre::Exception e)
	{
		LOG("exception upon loading script file: " + e.getFullDescription());
		return -1;
	}

	// Read the entire file
	string code;
	code.resize(ds->size());
	ds->read(&code[0], ds->size());

	// hash it
	{
		char hash_result[250];
		memset(hash_result, 0, 249);
		RoR::CSHA1 sha1;
		sha1.UpdateHash((uint8_t *)code.c_str(), (uint32_t)code.size());
		sha1.Final();
		sha1.ReportHash(hash_result, RoR::CSHA1::REPORT_HEX_SHORT);
		hash = String(hash_result);
	}

	return ProcessScriptSection(code.c_str(), filename);
}
Пример #6
0
    //---------------------------------------------------------------------
    void GpuProgramManager::loadMicrocodeCache( DataStreamPtr stream )
    {
        mMicrocodeCache.clear();

        // write the size of the array
        uint32 sizeOfArray = 0;
        stream->read(&sizeOfArray, sizeof(uint32));
        
        // loop the array and load it

        for ( uint32 i = 0 ; i < sizeOfArray ; i++ )
        {
            String nameOfShader;
            // loads the name of the shader
            uint32 stringLength  = 0;
            stream->read(&stringLength, sizeof(uint32));
            nameOfShader.resize(stringLength);              
            stream->read(&nameOfShader[0], stringLength);

            // loads the microcode
            uint32 microcodeLength = 0;
            stream->read(&microcodeLength, sizeof(uint32));     

            Microcode microcodeOfShader(OGRE_NEW MemoryDataStream(nameOfShader, microcodeLength));      
            microcodeOfShader->seek(0);
            stream->read(microcodeOfShader->getPtr(), microcodeLength);

            mMicrocodeCache.insert(make_pair(nameOfShader, microcodeOfShader));
        }

        // if cache is not modified, mark it as clean.
        mCacheDirty = false;
        
    }
size_t FileInterfaceOgre3D::Read(void* buffer, size_t size, Rocket::Core::FileHandle file)
{
	if (!file) return 0;

	DataStreamPtr stream = *(DataStreamPtr*)(file);	
	return stream->read(buffer, size);	
}
	time_t ScriptSerializerManager::getBinaryTimeStamp(const String& filename) {
		DataStreamPtr stream = mCacheArchive->open(filename);
		ScriptBlock::ScriptHeader header;
		stream->read(reinterpret_cast<char*>(&header), sizeof(ScriptBlock::ScriptHeader));
		stream->close();
		return header.lastModifiedTime;
	}
Пример #9
0
void MeshLoader_v0::ReadAnimStream(SubMesh * sm, DataStreamPtr & stream)
{
    VertexDeclarationPtr decl = sm->GetVertexStream()->GetDeclaration();
    VertexBufferPtr buffer;
    int stride = 0;

    chunk ck;
    while (ReadChunk(ck, stream) &&
        (ck.id == MC_STREAM_DECLARATION ||
         ck.id == MC_STREAM_VERTEX_DATA))
    {
        switch (ck.id)
        {
        case MC_STREAM_DECLARATION:
            ReadDeclaration(_ANIM_STREAM, decl, stream);
            break;

        case MC_STREAM_VERTEX_DATA:
            ReadVertexStream(buffer, stride, sm->GetVertexStream()->GetCount(), stream);
            break;
        }
    }

    sm->GetVertexStream()->Bind(_ANIM_STREAM, buffer, stride);

    //skip
    if (!stream->Eof())
        stream->Skip(-MC_CHUNK_SIZE);
}
Пример #10
0
void MeshLoader_v0::ReadIndexStream(SubMesh * sm, DataStreamPtr & stream)
{
    int count = sm->GetIndexStream()->GetCount();
    unsigned char stride;
    bool index16 = true;;

    stream->Read(&stride, sizeof(unsigned char));

    switch (stride)
    {
    case sizeof(short):
        index16 = true;
        break;

    case sizeof(int):
        index16 = false;
        break;

    default:
        EXCEPTION_DEBUG(0, "invalid index format.");
        break;
    }

    IndexBufferPtr pIndexBuffer = VideoBufferManager::Instance()->CreateIndexBuffer(stride * count, index16);
    void * indices;

    int start;
    stream->Read(&start, sizeof(int));

    indices = pIndexBuffer->Lock(0, 0, LOCK_DISCARD);
    stream->Read(indices, stride * count);
    pIndexBuffer->Unlock();

    sm->GetIndexStream()->Bind(pIndexBuffer, start);
}
	void ScriptSerializerManager::initializeConfig(const String& configFileName) {
		ConfigFile configFile;
		Archive* workingDirectory =  ArchiveManager::getSingleton().load(".", "FileSystem");
		if (workingDirectory->exists(configFileName)) {
			DataStreamPtr configStream = workingDirectory->open(configFileName);
			configFile.load(configStream);
			configStream->close();
		}
		else {
			stringstream message;
			message << "WARNING: Cannot find Script Cache config file:" << configFileName << ". Using default values";
			LogManager::getSingleton().logMessage(message.str());
		}

		binaryScriptExtension = configFile.getSetting("extension", "ScriptCache", ".sbin");
		scriptCacheLocation = configFile.getSetting("location", "ScriptCache", ".scriptCache");
		shaderCacheFilename = configFile.getSetting("filename", "ShaderCache", "ShaderCache");
		String searchExtensions = configFile.getSetting("searchExtensions", "ScriptCache", "program material particle compositor os pu");

		istringstream extensions(searchExtensions);
		String extension;
		while (extensions >> extension) {
			stringstream pattern;
			pattern << "*." << extension << binaryScriptExtension;
			ScriptCompilerManager::getSingleton().addScriptPattern(pattern.str());
		}
	}
Пример #12
0
    //---------------------------------------------------------------------
    Codec::DecodeResult PVRTCCodec::decode(DataStreamPtr& stream) const
    {
		// Assume its a pvr 2 header
		PVRTCTexHeaderV2 headerV2;
		stream->read(&headerV2, sizeof(PVRTCTexHeaderV2));
		stream->seek(0);

		if (PVR2_MAGIC == headerV2.pvrTag)
		{			
			return decodeV2(stream);
		}

		// Try it as pvr 3 header
		PVRTCTexHeaderV3 headerV3;
		stream->read(&headerV3, sizeof(PVRTCTexHeaderV3));
		stream->seek(0);

		if (PVR3_MAGIC == headerV3.version)
		{
			return decodeV3(stream);
		}

		
		OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
                        "This is not a PVR2 / PVR3 file!", "PVRTCCodec::decode");
    }
	//---------------------------------------------------------------------
	void GpuProgramManager::loadMicrocodeCache( DataStreamPtr stream )
	{
		mMicrocodeCache.clear();

		// write the size of the array
		size_t sizeOfArray = 0;
		stream->read(&sizeOfArray, sizeof(size_t));
		
		// loop the array and load it

		for ( size_t i = 0 ; i < sizeOfArray ; i++ )
		{
			String nameOfShader;
			// loads the name of the shader
			size_t stringLength  = 0;
			stream->read(&stringLength, sizeof(size_t));
			nameOfShader.resize(stringLength);				
			stream->read(&nameOfShader[0], stringLength);

			// loads the microcode
			size_t microcodeLength = 0;
			stream->read(&microcodeLength, sizeof(size_t));		

			Microcode microcodeOfShader(OGRE_NEW MemoryDataStream(nameOfShader, microcodeLength)); 		
			microcodeOfShader->seek(0);
			stream->read(microcodeOfShader->getPtr(), microcodeLength);

			mMicrocodeCache.insert(make_pair(nameOfShader, microcodeOfShader));
		}
	}
Пример #14
0
//-----------------------------------------------------------------------
void OldMaterialReader::parseNewTextureLayer(DataStreamPtr& stream, MaterialPtr& pMat)
{
	String line;
	TextureUnitState* pLayer;

	pLayer = pMat->getTechnique(0)->getPass(0)->createTextureUnitState("");


	while (!stream->eof())
	{
		line = stream->getLine();
		// Ignore comments & blanks
		if (line.length() != 0 && !(line.substr(0,2) == "//"))
		{
			if (line == "}")
			{
				// end of layer
				return;
			}
			else
			{
				parseLayerAttrib(line, pMat, pLayer);
			}
		}


	}
}
Пример #15
0
void generateHashFromDataStream(DataStreamPtr &ds, Ogre::String &hash)
{
	size_t location = ds->tell();
	// copy whole file into a buffer
	uint8_t *buf = 0;
	ds->seek(0); // from start
	// alloc buffer
	uint32_t bufSize = ds->size();
	buf = (uint8_t *)malloc(bufSize+1);
	// read into buffer
	ds->read(buf, bufSize);

	// and build the hash over it
	char hash_result[250];
	memset(hash_result, 0, 249);

	{
		RoR::CSHA1 sha1;
		sha1.UpdateHash(buf, bufSize);
		sha1.Final();
		sha1.ReportHash(hash_result, RoR::CSHA1::REPORT_HEX_SHORT);
	}

	// revert DS to previous position
	ds->seek(location);
	// release memory
	free(buf);
	buf = 0;
	
	hash = String(hash_result);
}
Rocket::Core::FileHandle FileInterfaceOgre3D::Open(const Rocket::Core::String& path)
{
	DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(path.CString());
	if (stream.isNull())
		return 0;	

	return (Rocket::Core::FileHandle)(new DataStreamPtr(stream));
}
size_t FileInterfaceOgre3D::Tell(Rocket::Core::FileHandle file)
{
	if (!file) return 0;

	DataStreamPtr stream = *(DataStreamPtr*)(file);	

	return stream->tell();
}
	void ScriptSerializerManager::saveShaderCache() {
#ifdef USE_MICROCODE_SHADERCACHE
		// A previously cached shader file exists.  load it
		DataStreamPtr shaderCache = mCacheArchive->create(shaderCacheFilename);
		mShaderSerializer->saveCache(shaderCache);
		shaderCache->close();
#endif
	}
	AbstractNodeListPtr ScriptSerializerManager::loadAstFromDisk(const String& filename) {
		DataStreamPtr stream = mCacheArchive->open(filename);
		ScriptSerializer* serializer = OGRE_NEW ScriptSerializer();
		AbstractNodeListPtr ast = serializer->deserialize(stream);
		OGRE_DELETE serializer;
		stream->close();
		return ast;
	}
	void ScriptSerializerManager::saveAstToDisk(const String& filename, size_t scriptTimestamp, const AbstractNodeListPtr& ast) {
		// A text script was just parsed. Save the compiled AST to disk
		DataStreamPtr stream = mCacheArchive->create(filename);
		ScriptSerializer* serializer = OGRE_NEW ScriptSerializer();
		serializer->serialize(stream, ast, scriptTimestamp);
		OGRE_DELETE serializer;
		stream->close();
	}
Пример #21
0
    //---------------------------------------------------------------------    
	Codec::DecodeResult PVRTCCodec::decodeV2(DataStreamPtr& stream) const
	{
		PVRTCTexHeaderV2 header;
        uint32 flags = 0, formatFlags = 0;
        size_t numFaces = 1; // Assume one face until we know otherwise

        ImageData *imgData = OGRE_NEW ImageData();
		MemoryDataStreamPtr output;

        // Read the PVRTC header
        stream->read(&header, sizeof(PVRTCTexHeaderV2));

        // Get format flags
        flags = header.flags;
        flipEndian(reinterpret_cast<void*>(flags), sizeof(uint32));
        formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK;

        uint32 bitmaskAlpha = header.bitmaskAlpha;
        flipEndian(reinterpret_cast<void*>(bitmaskAlpha), sizeof(uint32));

        if (formatFlags == kPVRTextureFlagTypePVRTC_4 || formatFlags == kPVRTextureFlagTypePVRTC_2)
        {
            if (formatFlags == kPVRTextureFlagTypePVRTC_4)
            {
                imgData->format = bitmaskAlpha ? PF_PVRTC_RGBA4 : PF_PVRTC_RGB4;
            }
            else if (formatFlags == kPVRTextureFlagTypePVRTC_2)
            {
                imgData->format = bitmaskAlpha ? PF_PVRTC_RGBA2 : PF_PVRTC_RGB2;
            }

            imgData->depth = 1;
            imgData->width = header.width;
            imgData->height = header.height;
            imgData->num_mipmaps = static_cast<ushort>(header.numMipmaps);

            // PVRTC is a compressed format
            imgData->flags |= IF_COMPRESSED;
        }

        // 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(OGRE_NEW MemoryDataStream(imgData->size));

		// Now deal with the data
		void *destPtr = output->getPtr();
        stream->read(destPtr, imgData->size);
        destPtr = static_cast<void*>(static_cast<uchar*>(destPtr));

		DecodeResult ret;
		ret.first = output;
		ret.second = CodecDataPtr(imgData);

		return ret;
	}
Пример #22
0
    //-----------------------------------------------------------------------
    void OverlayManager::skipToNextOpenBrace(DataStreamPtr& stream)
    {
        String line;
        while (!stream->eof() && line != "{")
        {
            line = stream->getLine();
        }

    }
Пример #23
0
    void Serializer::backpedalChunkHeader(DataStreamPtr& stream)
    {
        if (!stream->eof()){
            stream->skip(-(int)calcChunkHeaderSize());
        }
#if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE
        mChunkSizeStack.back() = stream->tell();
#endif
    }
Пример #24
0
    //-----------------------------------------------------------------------
    void ConfigFile::load(const DataStreamPtr& stream, const String& separators, 
        bool trimWhitespace)
    {
        /* Clear current settings map */
        clear();

        String currentSection = StringUtil::BLANK;
        SettingsMultiMap* currentSettings = OGRE_NEW_T(SettingsMultiMap, MEMCATEGORY_GENERAL)();
        mSettings[currentSection] = currentSettings;


        /* Process the file line for line */
        String line, optName, optVal;
        while (!stream->eof())
        {
            line = stream->getLine();
            /* Ignore comments & blanks */
            if (line.length() > 0 && line.at(0) != '#' && line.at(0) != '@')
            {
                if (line.at(0) == '[' && line.at(line.length()-1) == ']')
                {
                    // Section
                    currentSection = line.substr(1, line.length() - 2);
					SettingsBySection::const_iterator seci = mSettings.find(currentSection);
					if (seci == mSettings.end())
					{
						currentSettings = OGRE_NEW_T(SettingsMultiMap, MEMCATEGORY_GENERAL)();
						mSettings[currentSection] = currentSettings;
					}
					else
					{
						currentSettings = seci->second;
					} 
                }
                else
                {
                    /* Find the first seperator character and split the string there */
					Ogre::String::size_type separator_pos = line.find_first_of(separators, 0);
                    if (separator_pos != Ogre::String::npos)
                    {
                        optName = line.substr(0, separator_pos);
                        /* Find the first non-seperator character following the name */
                        Ogre::String::size_type nonseparator_pos = line.find_first_not_of(separators, separator_pos);
                        /* ... and extract the value */
                        /* Make sure we don't crash on an empty setting (it might be a valid value) */
                        optVal = (nonseparator_pos == Ogre::String::npos) ? "" : line.substr(nonseparator_pos);
                        if (trimWhitespace)
                        {
                            StringUtil::trim(optVal);
                            StringUtil::trim(optName);
                        }
                        currentSettings->insert(SettingsMultiMap::value_type(optName, optVal));
                    }
                }
            }
        }
    }
Пример #25
0
	void MActorRes::LoadImp(DataStreamPtr stream)
	{
		mActor = EMotionFX::IMPORTER.LoadActor((unsigned char*)stream->GetData(), stream->Size(), mSourceName.c_str());

		if (mActor)
		{
			_init();
		}
	}
Пример #26
0
	//-----------------------------------------------------------------------
	void CGUIParticleSystemManager::skipToNextOpenBrace(DataStreamPtr& stream)
	{
		CGUIString line;
		while (!stream->eof() && line != "{")
		{
			line = stream->getLine();
		}

	}
Пример #27
0
void SoundScriptManager::skipToNextOpenBrace(DataStreamPtr& stream)
{
    String line = "";

    while (!stream->eof() && line != "{")
    {
        line = stream->getLine();
    }
}
Пример #28
0
    //-----------------------------------------------------------------------
    void ParticleSystemManager::skipToNextCloseBrace(DataStreamPtr& stream)
    {
        String line;
        while (!stream->eof() && line != "}")
        {
            line = stream->getLine();
        }

    }
Пример #29
0
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());
                    }
                }
            }
        }
    }
}
Пример #30
0
Ogre::String TerrainGeometryManager::getPageHeightmap(int x, int z)
{
	DataStreamPtr ds = getPageConfig(x, z);

	if (ds.isNull())
		return "";

	char buf[4096];
	ds->readLine(buf, 4096);
	return String(buf);
}