Exemplo n.º 1
0
bool getTok(const gkString& buf, const gkString& dim, gkString& tok, size_t &start)
{
	const size_t size = buf.size();
	const size_t dimsize = dim.size();

	size_t pos = gkString::npos;

	while (start < size) 
	{
		pos = buf.find(dim, start);
		
		if (pos == gkString::npos) 
			pos = size;
		
		if (start == pos)
			start += dimsize; 
		else
			break;
	}

	if (start >= size) return false;

	tok.assign(&buf[start], pos-start);
	start = pos + dimsize;

	return true;
}
Exemplo n.º 2
0
BOM getTextBom(gkString& line, bool removeBom) 
{
	size_t len = line.size();
	BOM bom = getTextEncoding(line.c_str(), len);
	if (bom != BOM_NONE && removeBom) {
		//strip bom
		line = line.substr(getBOMLength(bom));
	}
	return bom;
}
Exemplo n.º 3
0
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();
	}
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
bool gkAndroidApp::setup(void) {
    AAssetManager* assetMgr = m_state->activity->assetManager;
    if (assetMgr) {
        Ogre::ArchiveManager::getSingleton().addArchiveFactory(new Ogre::APKFileSystemArchiveFactory(assetMgr));
        Ogre::ArchiveManager::getSingleton().addArchiveFactory(new Ogre::APKZipArchiveFactory(assetMgr));
        Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/", "APKFileSystem",
                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    }

    Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().
            openResource(m_blend, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    if (stream.isNull()) {
        gkPrintf("Error: Can't open file %s.\n", m_blend.c_str());
        return false;
    }

    size_t size = stream->size();
    char* buf = new char[size];
    stream->read(buf, size);

    gkBlendFile* blend = gkBlendLoader::getSingleton().loadFromMemory(buf,size,gkBlendLoader::LO_ALL_SCENES);
    gkScene* scene = blend->getMainScene();
    if (!scene) {
        gkPrintf("No usable scenes found in blend.\n");
        return false;
    }

    scene->createInstance();
    scene->getMainCamera()->getCamera()->setAutoAspectRatio(true);

    return true;
}
Exemplo n.º 6
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());
	}
}
Exemplo n.º 7
0
bool getAttrib(const TiXmlElement* XMLNode, const gkString& attrib, bool& value)
{
	if (!XMLNode || !XMLNode->Attribute(attrib)) return false;

	value = parseBool(XMLNode->Attribute(attrib.c_str()));
	return true;
}
Exemplo n.º 8
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

}
Exemplo n.º 9
0
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);
	}
}
Exemplo n.º 10
0
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();
}
Exemplo n.º 11
0
//-- gkString
//from ogre3d StringUtil
liStrVec strSplit( const gkString& str, const gkString& delims, UTuint32 maxSplits)
{
	liStrVec ret;
    // Pre-allocate some space for performance
    ret.reserve(maxSplits ? maxSplits+1 : 10);    // 10 is guessed capacity for most case

    unsigned int numSplits = 0;

    // Use STL methods 
    size_t start, pos;
    start = 0;
    do 
    {
        pos = str.find_first_of(delims, start);
        if (pos == start)
        {
            // Do nothing
            start = pos + 1;
        }
        else if (pos == gkString::npos || (maxSplits && numSplits == maxSplits))
        {
            // Copy the rest of the gkString
            ret.push_back( str.substr(start) );
            break;
        }
        else
        {
            // Copy up to delimiter
            ret.push_back( str.substr(start, pos - start) );
            start = pos + 1;
        }
        // parse up to next real data
        start = str.find_first_not_of(delims, start);
        ++numSplits;

    } while (pos != gkString::npos);



    return ret;
}
Exemplo n.º 12
0
int gkTextManager::getTextType(const gkString& name)
{
	int i = 0;
	while (TextItemMap[i].name != 0)
	{
		if (name.find(TextItemMap[i].name) != name.npos)
			return TextItemMap[i].type;
		++i;
	}
	return TT_ANY;

}
Exemplo n.º 13
0
void gkGUIManager::loadFont(const gkString& name) {
    gkFont *fnt = gkFontManager::getSingleton().getByName<gkFont>(name);

    if (fnt)
    {
        Rocket::Core::FontDatabase::LoadFontFace((const unsigned char*)fnt->getData(), fnt->getSize());
    }
    else
    {
        Rocket::Core::FontDatabase::LoadFontFace(name.c_str());
    }
}
Exemplo n.º 14
0
bool xmlConfig::load(const gkString &fileName)
{
	if (!openSections(fileName, mSections, "config")) {
		gkPrintf("[XML] Can't open file: '%s'", fileName.c_str());
		return false;
	}
	
	mLoaded = true;
	mFileName = fileName;

	return mLoaded;
}
Exemplo n.º 15
0
void gkDynamicsWorld::exportBullet(const gkString& fileName)
{
	int maxSerializeBufferSize = 1024 * 1024 * 5;

	btDefaultSerializer*    serializer = new btDefaultSerializer(maxSerializeBufferSize);
	m_dynamicsWorld->serialize(serializer);

	FILE* file = fopen(fileName.c_str(), "wb");
	fwrite(serializer->getBufferPointer(), serializer->getCurrentBufferSize(), 1, file);

	fclose(file);
	delete serializer;
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
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;
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
bool openXMLDocument(const gkString& fileName, TiXmlDocument &XMLDoc, const gkString& resGroupName)
{
	try
	{
		//open from file
		if (!Ogre::ResourceGroupManager::getSingletonPtr())
			return openXMLDocumentOnFile(fileName, XMLDoc);

		//open from resource

		// Strip the path
		gkString basename, path;
		Ogre::StringUtil::splitFilename(fileName, basename, path);

		Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().
			openResource( basename, resGroupName );

		gkString data = pStream->getAsString();
		// Open the .scene File
		
		XMLDoc.Parse( data.c_str() );
		pStream->close();
		pStream.setNull();

		if (XMLDoc.Error())
		{			
			gkPrintf("[XML] Error - The TiXmlDocument reported an error: %s", XMLDoc.ErrorDesc());
			return false;
		}
	} 
	catch(Ogre::Exception &e) 
	{		
		gkPrintf("[XML] Error - creating TiXmlDocument %s %s", fileName.c_str(), e.getDescription().c_str());
		return false;
	}

	return true;
}
Exemplo n.º 20
0
gkString strToUpper(const gkString& str) 
{
    gkString ss(str);
    std::transform(str.begin(), str.end(), ss.begin(), toupper);
	return ss;
}
Exemplo n.º 21
0
bool luFile::isSameFile(const gkString& file1,const gkString& file2)
{
	return wxFileName(file1.c_str()).SameAs(wxFileName(file2));
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
int OgreKit::setup(int argc, char** argv)
{
	int winsize_x		= 800;
	int winsize_y		= 600;
	m_prefs.wintitle	= gkString("OgreKit Demo (Press Escape to exit)[") + m_blend + gkString("]");


	gkString cfgfname;

	// Parse command line
	try
	{
		TCLAP::CmdLine cmdl("Ogrekit", ' ', "n/a");
		cmdl.setExceptionHandling(false);

		//cfg arguments

		TCLAP::ValueArg<std::string>	rendersystem_arg		("r", "rendersystem",			"Set rendering system. (gl, d3d9, d3d10, d3d11)", false, "", "string"); //default GL
		TCLAP::ValueArg<std::string>	viewportOrientation_arg	("",  "viewportorientation",	"Set viewport orientation.", false, m_prefs.viewportOrientation, "string"); 
		TCLAP::ValueArg<std::string>	log_arg					("",  "log",					"Set log file name.", false, m_prefs.log, "string"); 
		TCLAP::ValueArg<bool>			verbose_arg				("v", "verbose",				"Enable verbose log.", false, m_prefs.verbose, "bool");
		TCLAP::ValueArg<int>			winsize_x_arg			("",  "width",					"Set window width.", false, winsize_x, "int");
		TCLAP::ValueArg<int>			winsize_y_arg			("",  "height",					"Set window height.", false, winsize_y, "int");
		TCLAP::ValueArg<std::string>	wintitle_arg			("",  "wintitle",				"Set window title.", false, m_prefs.wintitle, "string"); 
		TCLAP::ValueArg<bool>			fullscreen_arg			("f", "fullscreen",				"Enable fullscreen mode.", false, m_prefs.fullscreen, "bool");
		TCLAP::ValueArg<std::string>	framingType_arg			("",  "framingtype",			"Set viewport framing type. (extend, crop, letterbox)", false, "", "string");
		TCLAP::ValueArg<std::string>	resources_arg			("",  "resources",				"Set resouces.", false, m_prefs.resources, "string");
		TCLAP::ValueArg<bool>			blendermat_arg			("",  "blendmat",				"Convert meshes using blender materials.", false, m_prefs.blendermat, "bool");
		TCLAP::ValueArg<bool>			matblending_arg			("",  "matblending",			"Enable material pass blending mode.", false, m_prefs.matblending, "bool");		
		TCLAP::ValueArg<bool>			grapInput_arg			("g", "grabinput",				"Grap mouse input.", false, m_prefs.grabInput, "bool");
		TCLAP::ValueArg<bool>			debugFps_arg			("d", "debugfps",				"Display debug fps.", false, m_prefs.debugFps, "bool");
		TCLAP::ValueArg<bool>			vsync_arg				("", "vsync",					"enable vertical-sync.", false, m_prefs.vsync, "bool");
		TCLAP::ValueArg<int>			vsyncrate_arg			("",  "vsync-rate",				"Set vsync-rate ", 0, m_prefs.vsyncRate, "int");

		TCLAP::ValueArg<bool>			debugPhysics_arg		("p", "debugphysics",			"Display debug physics.", false, m_prefs.debugPhysics, "bool");
		TCLAP::ValueArg<bool>			debugPhysicsAabb_arg	("a", "debugphysicsaabb",		"Display debug physics aabb.", false, m_prefs.debugPhysicsAabb, "bool");
		TCLAP::ValueArg<bool>			buildStaticGeometry_arg	("",  "buildinstances",			"Build Static Geometry.", false, m_prefs.buildStaticGeometry, "bool");
		TCLAP::ValueArg<bool>			useBulletDbvt_arg		("",  "frustumculling",			"Enable view frustum culling by dbvt.", false, m_prefs.useBulletDbvt, "bool");
		TCLAP::ValueArg<bool>			showDebugProps_arg		("t", "showdebugprops",			"Show debug props.", false, m_prefs.showDebugProps, "bool");
		TCLAP::ValueArg<bool>			debugSounds_arg			("",  "debugsounds",			"Debug sounds.", false, m_prefs.debugSounds, "bool");
		TCLAP::ValueArg<bool>			disableSound_arg		("s", "disablesound",			"Disable sounds.", false, m_prefs.disableSound, "bool");
		TCLAP::ValueArg<bool>			fsaa_arg				("",  "fsaa",					"Enable fsaa.", false, m_prefs.fsaa, "bool");
		TCLAP::ValueArg<int>			fsaaSamples_arg			("",  "fsaasSamples",			"Set fsaa samples.", false, m_prefs.fsaaSamples, "int");
		TCLAP::ValueArg<bool>			enableshadows_arg		("",  "enableshadows",			"Enable Shadows.", false, m_prefs.enableshadows, "bool");
		TCLAP::ValueArg<int>			defaultMipMap_arg		("",  "defaultmipmap",			"Set default mipMap.", false, m_prefs.defaultMipMap, "int");
		TCLAP::ValueArg<std::string>	shadowtechnique_arg		("",  "shadowtechnique",		"Set shadow technique.", false, m_prefs.shadowtechnique, "string"); 
		TCLAP::ValueArg<std::string>	colourshadow_arg		("",  "colourshadow",			"Set shadow colour.", false, "", "string"); 
		TCLAP::ValueArg<float>			fardistanceshadow_arg	("",  "fardistanceshadow",		"Set far distance shadow.", false, m_prefs.fardistanceshadow, "float"); 
		TCLAP::ValueArg<std::string>	shaderCachePath_arg		("",  "shadercachepath",		"RTShaderSystem cache file path.", false, m_prefs.shaderCachePath, "string"); 
		

		cmdl.add(rendersystem_arg);
		cmdl.add(viewportOrientation_arg);
		cmdl.add(log_arg);
		cmdl.add(verbose_arg);
		cmdl.add(winsize_x_arg);
		cmdl.add(winsize_y_arg);
		cmdl.add(wintitle_arg);
		cmdl.add(fullscreen_arg);
		cmdl.add(framingType_arg);
		cmdl.add(resources_arg);
		cmdl.add(blendermat_arg);
		cmdl.add(matblending_arg);
		cmdl.add(grapInput_arg);
		cmdl.add(debugFps_arg);
		cmdl.add(debugPhysics_arg);	
		cmdl.add(vsync_arg);
		cmdl.add(vsyncrate_arg);
		cmdl.add(debugPhysicsAabb_arg);	
		cmdl.add(buildStaticGeometry_arg);
		cmdl.add(useBulletDbvt_arg);
		cmdl.add(showDebugProps_arg);
		cmdl.add(debugSounds_arg);
		cmdl.add(disableSound_arg);
		cmdl.add(fsaa_arg);
		cmdl.add(fsaaSamples_arg);
		cmdl.add(enableshadows_arg);
		cmdl.add(defaultMipMap_arg);
		cmdl.add(shadowtechnique_arg);
		cmdl.add(colourshadow_arg);
		cmdl.add(fardistanceshadow_arg);
		cmdl.add(shaderCachePath_arg);

		//input file arguments
		
		TCLAP::ValueArg<std::string>			cfgfname_arg("c", "config-file", "Startup configuration file (.cfg) to use.", false, gkDefaultConfig, "string");
		TCLAP::UnlabeledValueArg<std::string>	bfname_arg("blender-file", "Blender file to launch as game.", false, gkDefaultBlend, "string");

		cmdl.add(cfgfname_arg);
		cmdl.add(bfname_arg);

		cmdl.parse( argc, argv );

		cfgfname						= cfgfname_arg.getValue();
		m_blend							= bfname_arg.getValue();

		m_prefs.rendersystem			= gkUserDefs::getOgreRenderSystem(rendersystem_arg.getValue());
		m_prefs.viewportOrientation		= viewportOrientation_arg.getValue();
		//m_prefs.sceneManager			= sceneManager_arg.getValue();
		m_prefs.log						= log_arg.getValue();
		m_prefs.verbose					= verbose_arg.getValue();

		m_prefs.winsize					= gkVector2(winsize_x_arg.getValue(), winsize_y_arg.getValue());
		m_prefs.wintitle				= wintitle_arg.getValue();

		m_prefs.fullscreen				= fullscreen_arg.getValue();
		m_prefs.framingType				= gkUserDefs::getViewportFramingType(framingType_arg.getValue());
		m_prefs.resources				= resources_arg.getValue();
		m_prefs.blendermat				= blendermat_arg.getValue();
		m_prefs.matblending				= matblending_arg.getValue();
		m_prefs.grabInput				= grapInput_arg.getValue();
		m_prefs.debugFps				= debugFps_arg.getValue();
		m_prefs.debugPhysics			= debugPhysics_arg.getValue();
		m_prefs.debugPhysicsAabb		= debugPhysicsAabb_arg.getValue();
		m_prefs.buildStaticGeometry		= buildStaticGeometry_arg.getValue();
		m_prefs.useBulletDbvt			= useBulletDbvt_arg.getValue();
		m_prefs.showDebugProps			= showDebugProps_arg.getValue();
		m_prefs.debugSounds				= debugSounds_arg.getValue();
		m_prefs.disableSound			= disableSound_arg.getValue();

		m_prefs.vsync					= vsync_arg.getValue();
		m_prefs.vsyncRate				= vsyncrate_arg.getValue();

		m_prefs.fsaa					= fsaa_arg.getValue();
		m_prefs.fsaaSamples				= fsaaSamples_arg.getValue();
		m_prefs.enableshadows			= enableshadows_arg.getValue();
		m_prefs.defaultMipMap			= defaultMipMap_arg.getValue();
		m_prefs.shadowtechnique			= shadowtechnique_arg.getValue();
		m_prefs.fardistanceshadow		= fardistanceshadow_arg.getValue();	
		m_prefs.shaderCachePath			= shaderCachePath_arg.getValue();

		if (colourshadow_arg.isSet())
			m_prefs.colourshadow		= Ogre::StringConverter::parseColourValue(colourshadow_arg.getValue());

#ifdef __APPLE__
		if (m_blend.find("-psn") != gkString::npos)
			m_blend = gkDefaultBlend;
#endif

	}
	catch (TCLAP::ArgException& e)
	{
		std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
		return -1;
	}
	catch (TCLAP::ExitException&)
	{
		// just return and exit app
		return -1;
	}
	catch (...)
	{
		std::cerr << "Unknown exception." << std::endl;
		return -1;
	}



	gkPath path = cfgfname;

	// overide settings if found
	if (path.isFile())
		m_prefs.load(path.getPath());

	return 0;
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
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

}
Exemplo n.º 26
0
bool OgreKit::setup(void)
{
	LOG_FOOT;
	  
	if (assetMgr)
	{
#if USE_APK_ARCHIVE
		Ogre::ArchiveManager::getSingleton().addArchiveFactory(new Ogre::APKFileSystemArchiveFactory(assetMgr));
		Ogre::ArchiveManager::getSingleton().addArchiveFactory(new Ogre::APKZipArchiveFactory(assetMgr));

		Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/", "APKFileSystem",  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
#endif
	}

#if USE_APK_ARCHIVE
	Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(m_blend, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	if (stream.isNull())
	{
		gkPrintf("Error: Can't open file %s.", m_blend.c_str());
		return false;
	}

	size_t size = stream->size();
	char* buf = new char[size];
	stream->read(buf, size);

	gkBlendFile* blend = gkBlendLoader::getSingleton().loadFromMemory(buf,size,gkBlendLoader::LO_ALL_SCENES);	
#else
	gkBlendFile* blend = gkBlendLoader::getSingleton().loadFile(m_blend,gkBlendLoader::LO_ALL_SCENES); //, "", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);	
#endif
	if (!blend)
	{
		LOGI("File loading failed.\n");
		return false;
	}

	LOG_FOOT;

	m_scene = blend->getMainScene();
	if (!m_scene)
	{
		LOGI("No usable scenes found in blend.\n");
		return false;
	}

	LOG_FOOT;

	m_scene->createInstance();

	LOG_FOOT;
	
	m_scene->getMainCamera()->getCamera()->setAutoAspectRatio(true);

	// add input hooks
	gkWindow* win = gkWindowSystem::getSingleton().getMainWindow();
	m_input = static_cast<OIS::AndroidInputManager*>(win->getInputManager());

	LOG_FOOT;


	return true;
}