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; }
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; }
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; }
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; }
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()); } }
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; }
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; }
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; }
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; }
bool luFile::isSameFile(const gkString& file1,const gkString& file2) { return wxFileName(file1.c_str()).SameAs(wxFileName(file2)); }