コード例 #1
0
void gkEngine::loadResources(const gkString& name)
{
	if (name.empty()) return;

	try
	{
		Ogre::ConfigFile fp;
		fp.load(name);

		Ogre::ResourceGroupManager* resourceManager = Ogre::ResourceGroupManager::getSingletonPtr();
		Ogre::ConfigFile::SectionIterator cit = fp.getSectionIterator();

		while (cit.hasMoreElements())
		{
			gkString elementname = cit.peekNextKey();
			Ogre::ConfigFile::SettingsMultiMap* ptr = cit.getNext();
			for (Ogre::ConfigFile::SettingsMultiMap::iterator dit = ptr->begin(); dit != ptr->end(); ++dit)
				resourceManager->addResourceLocation(dit->second, dit->first, elementname);
		}
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
	}
	catch (Ogre::Exception& e)
	{
		gkLogMessage("Engine: Failed to load resource file!\n" << e.getDescription());
	}
}
コード例 #2
0
bool gkResourceGroupManager::initRTShaderSystem(const gkString& shaderLang, const gkString& shaderCachePath, bool hasFixedCapability)
{
#ifdef OGREKIT_USE_RTSHADER_SYSTEM
	GK_ASSERT( m_materialLoader == 0);

	m_materialLoader = new gkMaterialLoader();

	Ogre::RTShader::ShaderGenerator::initialize();
	
	Ogre::RTShader::ShaderGenerator::getSingleton().setTargetLanguage(shaderLang);
	if (!shaderCachePath.empty())
		Ogre::RTShader::ShaderGenerator::getSingleton().setShaderCachePath(shaderCachePath);

	Ogre::RTShader::ShaderGenerator* shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
	GK_ASSERT(shaderGenerator);

	if (!hasFixedCapability)
	{
		gkMaterialLoader::createRTSSMaterial("BaseWhite");
		gkMaterialLoader::createRTSSMaterial("BaseWhiteNoLighting", false);
		gkMaterialLoader::createRTSSMaterial("World", false);
	}
	return true;

#else
	return false;
#endif

}
コード例 #3
0
ファイル: Main.cpp プロジェクト: Ali-il/gamekit
bool OgreKit::init(const gkString& blend)
{
	gkPrintf("----------- OgreKit Android Demo init -----------------");
	LOG_FOOT;

	gkString cfgfname;	
	// Parse command line
	m_blend = gkDefaultBlend;
	if (!blend.empty()) m_blend = blend;

	getPrefs().debugFps = true;
	getPrefs().wintitle = gkString("OgreKit Demo (Press Escape to exit)[") + m_blend + gkString("]");
	getPrefs().blendermat=true;
	//getPrefs().shaderCachePath="/sdcard/gamekit";
	getPrefs().enableshadows=false;
	getPrefs().viewportOrientation="portrait";
	//	m_prefs.disableSound=false;
	gkPath path = cfgfname;	

	LOG_FOOT;

	// overide settings if found
	if (path.isFileInBundle())
		getPrefs().load(path.getPath());

	LOG_FOOT;

	m_inited = initialize();
	LOG_FOOT;
	//gkMessageManager::getSingleton().addListener(this);
	return m_inited;
}
コード例 #4
0
ファイル: gsPhysics.cpp プロジェクト: Ali-il/gamekit
bool gsRayTest::cast(gsRay& ray, const gkString& prop, gsGameObject* excludeObj)
{
	if (prop.empty() && !excludeObj)
		return m_ray->collides(ray);
	else{
		xrayFilter xray(excludeObj?excludeObj->get():0, prop, "");
		gkVector3 from(ray.getOrigin());
		gkVector3 to(ray.getOrigin()+ray.getDirection()*100);
		return m_ray->collides(from,to,xray);
	}
}
コード例 #5
0
ファイル: liUtils.cpp プロジェクト: Ali-il/gamekit
int parseScalarArray(liScalarVec &v, const gkString& str, const gkString& delims)
{
	if (str.empty()) return 0;

	liStrVec sv = strSplit(str, delims);
	v.clear(); v.reserve(sv.size());
	for (size_t i = 0; i < sv.size(); i++)
		v.push_back(Ogre::StringConverter::parseReal(sv[i]));

	return v.size();
}
コード例 #6
0
ファイル: liUtils.cpp プロジェクト: Ali-il/gamekit
void splitFileName(const gkString& path, gkString& dir, gkString& base, gkString& ext)
{
	if (path.empty()) return;
	if (path == "." || path == "..")
	{
		dir = path;
		return;
	}

	gkString fpath = path, fname;

	char delim = '/';

	bool bdelim = fpath.find_last_of('\\') != gkString::npos;
	bool fdelim = fpath.find_last_of('/')  != gkString::npos;

	if (bdelim) 
	{
		if (fdelim) //normalize to \ to /
			std::replace(fpath.begin(), fpath.end(), '\\', '/');
		else
			delim = '\\';
	} 

	size_t i = fpath.find_last_of(delim);

	if (i != gkString::npos) 
	{
		dir = fpath.substr(0, i);
		fname = fpath.substr(i+1, path.size()-1);
	} 
	else 
	{
		dir.clear();
		fname = fpath;
	}

	i = fname.find_last_of('.');
	if (i != gkString::npos) 
	{
		base = fname.substr(0, i);
		ext = fname.substr(i+1, fname.size()-1);
	} 
	else 
	{
		base = fname;
		ext.clear();
	}
}
コード例 #7
0
bool gkPhysicsController::sensorTest(gkGameObject* ob, const gkString& prop, const gkString& material, bool onlyActor, bool testAllMaterials)
{
	GK_ASSERT(ob);

	if (onlyActor)
	{
		if (ob->getProperties().isActor())
		{
			if (prop.empty() && material.empty())
				return true;

			if (!prop.empty())
			{
				if (ob->hasVariable(prop))
					return true;
			}
			else if (!material.empty())
			{
				if (ob->hasSensorMaterial(material, !testAllMaterials))
					return true;
			}
		}
	}
	else
	{
		if (prop.empty() && material.empty())
			return true;

		if (!prop.empty())
		{
			if (ob->hasVariable(prop))
				return true;
		}
		else if (!material.empty())
		{
			if (ob->hasSensorMaterial(material, !testAllMaterials))
				return true;
		}
	}

	return false;
}
コード例 #8
0
ファイル: luFile.cpp プロジェクト: Draion/Gamekit
bool luProjectFile::create(const gkString& fileName, const gkString& projName)
{
	m_projFileName = luFile::getAbsolutePath(fileName);
	m_projDir = luFile::getDirName(m_projFileName);
	

	if (projName.empty())
		m_projName = luFile::getFileNameBase(fileName);
	else
		m_projName = projName;

	m_projVer = VERSION;
	m_startLuaFile = "";
	m_files.clear();	

	setModified();

	return true;
}
コード例 #9
0
bool gkPhysicsController::collidesWith(const gkString& name, gkContactInfo* cpy, bool emptyFilter)
{

	if (!m_localContacts.empty())
	{
		if (name.empty() && emptyFilter)
		{
			if (cpy) *cpy = m_localContacts.at(0);
			return true;
		}


		UTsize i, s;
		gkContactInfo::Array::Pointer p;

		i = 0;
		s = m_localContacts.size();
		p = m_localContacts.ptr();

		while (i < s)
		{
			GK_ASSERT(p[i].collider);
			gkGameObject* gobj = p[i].collider->getObject();

			if (name.find(gobj->getName()) != gkString::npos)
			{
				if (cpy) *cpy = p[i];
				return true;
			}

			++i;
		}
	}

	return false;
}
コード例 #10
0
bool gkPhysicsController::sensorCollides(const gkString& prop, const gkString& material, bool onlyActor, bool testAllMaterials, utArray<gkGameObject*>* collisionList)
{
	if (collisionList){
		collisionList->clear();
	}
	if (onlyActor && !m_object->getProperties().isActor())
		return false;


	if (!m_localContacts.empty())
	{
		if (!collisionList && prop.empty() && material.empty())
		{
			// there are contacts and we do not care about property, nor empty, nor we need a list of objects (list = NULL)
			// any filter
			return true;
		}

		UTsize i, s;
		gkContactInfo::Array::Pointer p;

		i = 0;
		s = m_localContacts.size();
		p = m_localContacts.ptr();

		while (i < s)
		{
			GK_ASSERT(p[i].collider);
			gkGameObject* gobj = p[i].collider->getObject();


			if (onlyActor)
			{

				if (prop.empty() && material.empty())
					return true;

				if (gobj->getProperties().isActor())
				{
					if (!prop.empty())
					{
						if (gobj->hasVariable(prop)){
							if (!collisionList){
								return true;
							}
							else if (collisionList->find(gobj)==UT_NPOS)
								collisionList->push_back(gobj);
						}
					}
					else if (!material.empty())
					{
						if (gobj->hasSensorMaterial(material, !testAllMaterials))
						{
							if (!collisionList)
							{
								return true;
							}
							else if (collisionList->find(gobj)==UT_NPOS){
								collisionList->push_back(gobj);
							}
						}
					}
				}
			}
			else
			{
				if (prop.empty() && material.empty())
					if (!collisionList)
					{
						return true;
					}
					else if (collisionList->find(gobj)==UT_NPOS)
					{
						collisionList->push_back(gobj);
					}

				if (!prop.empty())
				{
					if (gobj->hasVariable(prop))
					{
						if (!collisionList)
						{
							return true;
						}
						else if (collisionList->find(gobj)==UT_NPOS)
						{
							collisionList->push_back(gobj);
						}
					}
				}
				else if (!material.empty())
				{
					if (gobj->hasSensorMaterial(material, !testAllMaterials)){
						if (!collisionList)
						{
							return true;
						}
						else if (collisionList->find(gobj)==UT_NPOS)
						{
							collisionList->push_back(gobj);
						}
					}
				}
			}

			++i;
		}
	}
	if (!collisionList)
		return false;
	else if (collisionList->empty())
		return false;
	else
		return true;
}
コード例 #11
0
bool gkCompositorManager::setCompositorChain(gkCompositorOp op, const gkString& compositorName, gkViewport *viewport)
{
	GK_ASSERT(viewport && viewport->getViewport());

	bool found = false;

	Ogre::Viewport *vp = viewport->getViewport(); 

	int width = vp->getActualWidth(), height = vp->getActualHeight();

	Ogre::CompositorChain *chain = Ogre::CompositorManager::getSingleton().getCompositorChain(vp); assert(chain);
	for (size_t i = 0; i < chain->getNumCompositors(); i++) 
	{
		Ogre::CompositorInstance *ci = chain->getCompositor(i); assert(ci);
		bool match = (compositorName == ci->getCompositor()->getName());
		
		if (op == GK_COMPOSITOR_OP_REPLACE) 
			ci->setEnabled(match);
		else if 
			(op == GK_COMPOSITOR_OP_RESET) ci->setEnabled(false);
		else if 
			(match) ci->setEnabled(op == GK_COMPOSITOR_OP_ADD);
		
		if (!found && match) found = true;
	}

	if (op == GK_COMPOSITOR_OP_DEL || op == GK_COMPOSITOR_OP_RESET) 
		return true;

	if (!compositorName.empty() && !found) //create new compositor
	{ 
		if (compositorName == GK_COMPOSITOR_HEAT_VISION && !m_heatVisionInited) 
			m_heatVisionInited = gkOgreCompositorHelper::createHeatVisionCompositor();
		else if (compositorName == GK_COMPOSITOR_MOTION_BLUR && !m_motionBlurInited)
			m_motionBlurInited = gkOgreCompositorHelper::createMotionBlurCompositor();

		Ogre::CompositorManager& compMgr = Ogre::CompositorManager::getSingleton();

		Ogre::CompositorInstance* instance = compMgr.addCompositor(vp, compositorName, 0);
		if (instance) 
		{
			if (compositorName == GK_COMPOSITOR_HALFTONE && !m_halftonInited) 
				m_halftonInited = gkOgreCompositorHelper::createHalftoneTexture();
			else if (compositorName == GK_COMPOSITOR_DITHER && !m_ditherInited) 
				m_ditherInited = gkOgreCompositorHelper::createDitherTexture(width, height);			

			instance->setEnabled(true);

			gkPrintf("[COMP] add new compositor: %s", compositorName.c_str());

			return true;
		} 
		else 
		{
			gkPrintf("[COMP] %s - FAILED. check compositor name.", compositorName.c_str());
			return false;
		}
	}

	return false;
}
コード例 #12
0
ファイル: gkTextManager.cpp プロジェクト: carriercomm/gamekit
void gkTextManager::parseScripts(const gkString& group)
{

	gkResourceManager::ResourceIterator iter = getResourceIterator();
	while (iter.hasMoreElements())
	{
		gkTextFile* tf = static_cast<gkTextFile*>(iter.getNext().second);

		if (!group.empty() && tf->getGroupName() != group) continue;

		const gkString& buf = tf->getText();
		const int type = tf->getType();


#ifdef OGREKIT_COMPILE_OGRE_SCRIPTS

		try
		{

			if (type == TT_MATERIAL)
			{
				Ogre::DataStreamPtr memStream(
				    OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size()));

				Ogre::MaterialManager::getSingleton().parseScript(memStream, group);

			}
			else if (type == TT_PARTICLE)
			{
				Ogre::DataStreamPtr memStream(
				    OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size()));


				Ogre::ParticleSystemManager::getSingleton().parseScript(memStream, group);
			}
			else if (type == TT_FONT)
			{
				// Note: font must be an external file (.ttf anyway (texture fonts are not tested) )
				Ogre::DataStreamPtr memStream(
				    OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size()));

				Ogre::FontManager::getSingleton().parseScript(memStream, group);
			}
			else if (type == TT_COMPOSIT)
			{
				Ogre::DataStreamPtr memStream(
				    OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size()));

				Ogre::CompositorManager::getSingleton().parseScript(memStream, group);
			}
		}
		catch (Ogre::Exception& e)
		{
			gkLogMessage("TextManager: " << e.getDescription());
			continue;
		}



		if (type == TT_BFONT)
		{
			utMemoryStream stream;
			stream.open(buf.c_str(), buf.size(), utStream::SM_READ);

			gkFontManager::getSingleton().parseScript(&stream);
		}
#endif
#ifdef OGREKIT_USE_LUA

		if (type == TT_LUA)
			gkLuaManager::getSingleton().createFromText(gkResourceName(tf->getResourceName().getName(), group), buf);
#endif
	}

#ifdef OGREKIT_COMPILE_OGRE_SCRIPTS

	// Overlays are a dependant script. (.material .font)

	try
	{

		TextArray overlays;
		getTextFiles(overlays, TT_OVERLAY);



		TextArray::Iterator it = overlays.iterator();
		while (it.hasMoreElements())
		{
			gkTextFile* tf = (gkTextFile*)it.getNext();

			const gkString& buf = tf->getText();
			const int type = tf->getType();

			Ogre::DataStreamPtr memStream(
			    OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size()));


			Ogre::OverlayManager::getSingleton().parseScript(memStream, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		}
	}
	catch (Ogre::Exception& e)
	{
		gkLogMessage("TextManager: " << e.getDescription());
	}

#endif

}