CXSpritePtr XSpriteManager::createRes(const stringc& name, int flag) { CXSpritePtr sprite = new CXSprite(); if(sprite->LoadFromFile(name.c_str())) { sprite->setName(name); DBG("engineDbg_Res","create sprite name: %s", name.c_str()); } else { sprite = 0; DBG("engineDbg_Res","can not create sprite, name: %s", name.c_str()); } if(sprite.isValid()) { stringc baseName, exten, path; StringUtil::splitFullFilename(name, baseName, exten, path); baseName = path+baseName+".tga"; renderer::TextureManager& texMgr = renderer::TextureManager::getInstance(); sprite->SetTexture(texMgr.getRes(baseName)); } return sprite; }
//------------------------------------------------------------------------- // l o g M e s s a g e //------------------------------------------------------------------------- void CApplication::logMessage(stringc msg) { msg += "\n"; fputs(msg.c_str(), stdout); if(m_logFile) { m_logFile->write(msg.c_str(),msg.size()); m_logFile->write("\n",1); } }
Scenario::Scenario(IrrlichtDevice* dev, stringc file, stringc mapName) { device = dev; device->getFileSystem()->addZipFileArchive(file.c_str()); IAnimatedMesh* mesh = device->getSceneManager()->getMesh(mapName.c_str()); ISceneNode* node = device->getSceneManager()->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024); }
// ---------------------------------------------------------------------------- void Editor::writeStrc(FILE* fp, stringc str) { u8 size; size = str.size() + 1; fwrite(&size, sizeof(u8), 1, fp); fwrite(str.c_str(), sizeof(c8), size, fp); } // writeStrc
bool LoadLines( Container& container, const stringc& filename, const u32 LENGTH ) { /// open file FILE *f = fopen( filename.c_str(), "r"); if (!f) { printf ( "Could not open file.\n" ); return false; } /// create buffer c8* b = new c8[LENGTH]; if (!b) { printf ( "Sorry, but you are out of memory.\n" ); return false; } /// read line-count u32 lineCount = 0; while (fgets(b, LENGTH, f)) { lineCount++; } /// process line-count printf ( "Loaded file has %d container.\n", lineCount ); if (lineCount == 0) { fclose(f); return false; } /// reallocate container container.reallocate( lineCount ); container.set_used( 0 ); /// rewind fseek( f, 0L, SEEK_SET ); /// fill container while (fgets(b, LENGTH, f)) { container.push_back( stringc(b) ); } /// end fclose(f); if (b) delete b; return true; }
EffectHandler::SPostProcessingPair EffectHandler::obtainScreenQuadMaterialFromFile(const irr::core::stringc& filename, irr::video::E_MATERIAL_TYPE baseMaterial) { CShaderPreprocessor sPP(driver); sPP.addShaderDefine("SCREENX", core::stringc(ScreenRTTSize.Width)); sPP.addShaderDefine("SCREENY", core::stringc(ScreenRTTSize.Height)); video::E_VERTEX_SHADER_TYPE VertexLevel = driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0) ? EVST_VS_3_0 : EVST_VS_2_0; video::E_PIXEL_SHADER_TYPE PixelLevel = driver->queryFeature(video::EVDF_PIXEL_SHADER_3_0) ? EPST_PS_3_0 : EPST_PS_2_0; E_SHADER_EXTENSION shaderExt = (driver->getDriverType() == EDT_DIRECT3D9) ? ESE_HLSL : ESE_GLSL; video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices(); const stringc shaderString = sPP.ppShaderFF(filename.c_str()); ScreenQuadCB* SQCB = new ScreenQuadCB(this, true); s32 PostMat = gpu->addHighLevelShaderMaterial( sPP.ppShader(SCREEN_QUAD_V[shaderExt]).c_str(), "vertexMain", VertexLevel, shaderString.c_str(), "pixelMain", PixelLevel, SQCB, baseMaterial); SPostProcessingPair pPair(PostMat, SQCB); SQCB->drop(); return pPair; }
bool CLanguages::setLanguage(stringc lang) { m_Language->value = lang; bool found = false; for (u32 i=0; i< m_ListOfAvailableLanguages.size(); i++) { if(m_ListOfAvailableLanguages[i]->value.equals_ignore_case(lang)) { m_Language->name = m_ListOfAvailableLanguages[i]->name; m_Language->index = m_ListOfAvailableLanguages[i]->index; found = true; } } if(!found) { printf("Language '%s' not found! Setting english as default language.\n", lang.c_str()); m_Language->value = "en"; m_Language->name = "english"; m_Language->index = 0; } LoadStringTable(); return found; }
/// @brief SystemCall to stringc stringc SingleSysCall( const stringc& command, const u32 LENGTH ) { /// open pipe to shell command result FILE *f = popen( command.c_str(), "r"); if (!f) { printf ( "Could not open temporary file as bash script.\n" ); return stringc(""); } /// create linebuffer c8* buffer = new c8[LENGTH]; if (!buffer) { printf ( "Sorry, but you are out of memory.\n" ); return stringc(""); } u32 lineCount = 0; stringc s = ""; while (fgets(buffer, LENGTH, f)) { /* ... */ lineCount++; s += stringc(buffer); } delete buffer; pclose(f); return s; }
bool StoreLines( const Container& container, const stringc& filename ) { /// open file FILE *f = fopen( filename.c_str(), "w"); if (!f) { printf ( "Could not open temporary write-file.\n" ); return false; } u32 i = 0; while (f && i<container.size()) { fputs( container[i].c_str(), f ); // if ( container[i].size() > fputs( container[i].c_str(), f ) ) // { // printf ( "Maybe some error while reading [%d].\n", i ); // } fputs( "\n", f ); i++; } fclose( f ); f = 0; return true; }
bool StoreCall( const stringc& command, const stringc& filename, const u32 LENGTH ) { /// open shell-pipe FILE *_shell = popen( command.c_str(), "r"); if (!_shell) { printf ( "%s > %s\n", command.c_str(), filename.c_str() ); return false; } /// open write-file FILE *_file = fopen( filename.c_str(), "w"); if (!_file) { printf ( "Could not open write-file %s.\n", filename.c_str() ); return false; } printf ( "%s > %s OK\n", command.c_str(), filename.c_str() ); /// create linebuffer c8* _buffer = new c8[LENGTH]; if (!_buffer) { printf ( "Sorry, but you are out of memory.\n" ); return false; } u32 lineCount = 0; while (fgets(_buffer, LENGTH, _shell)) { fputs(_buffer, _file); lineCount++; } delete _buffer; pclose(_shell); fclose(_file); return true; }
s32 getSettingAsInteger(const stringw& key) const { //we implicitly cast to string instead of stringw because strtol10 does not accept wide strings const stringc s = getSetting(key); if (s.empty()) return 0; return strtol10(s.c_str()); }
__MY_CORE_LIB_API__ const c8* getSingletonsTableAsPrintableString() { _PrintableString.sprintf( "&Device = %p, Device = %p\n" "&PluginManager = %p, PluginManager = %p\n" "&Profiler = %p, Profiler = %p\n" "&Logger = %p, Logger = %p\n" "&FileSystem = %p, FileSystem = %p\n" "&InputDispatcher = %p, InputDispatcher = %p\n" "&CursorControl = %p, CursorControl = %p\n" "&TimerMain = %p, TimerMain = %p\n" "&TimerSecond = %p, TimerSecond = %p\n" "&MemStatus = %p, MemStatus = %p\n" "&SoundDriver = %p, SoundDriver = %p\n" "&CoreScriptManager = %p, CoreScriptManager = %p\n" "&ScriptManager = %p, ScriptManager = %p\n" "&DynamicManager = %p, DynamicManager = %p\n" "&SceneManager = %p, SceneManager = %p\n" "&PathFinderManager = %p, PathFinderManager = %p\n" "&LightGridManager = %p, LightGridManager = %p\n" "&MaterialsManager = %p, MaterialsManager = %p\n" "&CullingSystem = %p, CullingSystem = %p\n" "&ImageLibrary = %p, ImageLibrary = %p\n" "&VideoDriver = %p, VideoDriver = %p\n" "&GameManager = %p, GameManager = %p\n" "&GameAIModule = %p, GameAIModule = %p\n" "&GameEventsDispatcher = %p, GameEventsDispatcher = %p\n" "&GameTasksManager = %p, GameTasksManager = %p\n" "&ResourceManager = %p, ResourceManager = %p", &g_SingletonsTable.Ptrs.Device, g_SingletonsTable.Ptrs.Device, &g_SingletonsTable.Ptrs.PluginManager, g_SingletonsTable.Ptrs.PluginManager, &g_SingletonsTable.Ptrs.Profiler, g_SingletonsTable.Ptrs.Profiler, &g_SingletonsTable.Ptrs.Logger, g_SingletonsTable.Ptrs.Logger, &g_SingletonsTable.Ptrs.FileSystem, g_SingletonsTable.Ptrs.FileSystem, &g_SingletonsTable.Ptrs.InputDispatcher, g_SingletonsTable.Ptrs.InputDispatcher, &g_SingletonsTable.Ptrs.CursorControl, g_SingletonsTable.Ptrs.CursorControl, &g_SingletonsTable.Ptrs.TimerMain, g_SingletonsTable.Ptrs.TimerMain, &g_SingletonsTable.Ptrs.TimerSecond, g_SingletonsTable.Ptrs.TimerSecond, &g_SingletonsTable.Ptrs.MemStatus, g_SingletonsTable.Ptrs.MemStatus, &g_SingletonsTable.Ptrs.SoundDriver, g_SingletonsTable.Ptrs.SoundDriver, &g_SingletonsTable.Ptrs.CoreScriptManager, g_SingletonsTable.Ptrs.CoreScriptManager, &g_SingletonsTable.Ptrs.ScriptManager, g_SingletonsTable.Ptrs.ScriptManager, &g_SingletonsTable.Ptrs.DynamicManager, g_SingletonsTable.Ptrs.DynamicManager, &g_SingletonsTable.Ptrs.SceneManager, g_SingletonsTable.Ptrs.SceneManager, &g_SingletonsTable.Ptrs.PathFinderManager, g_SingletonsTable.Ptrs.PathFinderManager, &g_SingletonsTable.Ptrs.LightGridManager, g_SingletonsTable.Ptrs.LightGridManager, &g_SingletonsTable.Ptrs.MaterialsManager, g_SingletonsTable.Ptrs.MaterialsManager, &g_SingletonsTable.Ptrs.CullingSystem, g_SingletonsTable.Ptrs.CullingSystem, &g_SingletonsTable.Ptrs.ImageLibrary, g_SingletonsTable.Ptrs.ImageLibrary, &g_SingletonsTable.Ptrs.VideoDriver, g_SingletonsTable.Ptrs.VideoDriver, &g_SingletonsTable.Ptrs.GameManager, g_SingletonsTable.Ptrs.GameManager, &g_SingletonsTable.Ptrs.GameAIModule, g_SingletonsTable.Ptrs.GameAIModule, &g_SingletonsTable.Ptrs.GameEventsDispatcher, g_SingletonsTable.Ptrs.GameEventsDispatcher, &g_SingletonsTable.Ptrs.GameTasksManager, g_SingletonsTable.Ptrs.GameTasksManager, &g_SingletonsTable.Ptrs.ResourceManager, g_SingletonsTable.Ptrs.ResourceManager); return _PrintableString.c_str(); }
int CSLevel::loadPrefab(stringc filename) { CS_LOG(CSLOGTYPE::CSL_DEBUG, "Loading prefab %s", filename.c_str()); int id = 0; stringc dir(getApplication()->getDirectory("PrefabDirectory")); dir += filename; IXMLReader* reader = getDevice()->getFileSystem()->createXMLReader(filename); if (!reader) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to open prefab file %s", filename.c_str()); return -1; } // read file while (reader->read()) { switch (reader->getNodeType()) { case io::EXN_ELEMENT: stringw name = reader->getNodeName(); if (stringw("CSOBJECT") == name) { stringw type = reader->getAttributeValueSafe(L"TYPE"); CSObject* obj = getObjectFactory()->createObjectByType(stringc(type)); if (obj) { id = obj->getId(); IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); attr->read(reader, false); obj->deserializeAttributes(attr); obj->setId(id); obj->reCreate(); attr->drop(); } } } } reader->drop(); return id; }
bool CSLevel::savePrefab(CSObject* obj, stringc filename) { CS_LOG(CSLOGTYPE::CSL_DEBUG, "Saving prefab to file %s", filename.c_str()); CS_CHECK_BOOL(obj, CSLOGTYPE::CSL_WARNING, "Warning unable to save prefab. obj is not valid"); _chdir(getApplication()->getDirectory("PrefabDirectory").c_str()); IXMLWriter* writer = getDevice()->getFileSystem()->createXMLWriter(filename); if (!writer) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to create prefab file %s", filename.c_str()); return false; } writer->writeXMLHeader(); stringw name("CSOBJECT"); writer->writeElement(name.c_str(), false, L"TYPE", stringw(obj->getInfo()->getName()).c_str()); writer->writeLineBreak(); IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); SAttributeReadWriteOptions options; obj->serializeAttributes(attr, &options); if (attr->getAttributeCount() != 0) { attr->write(writer); writer->writeLineBreak(); } attr->drop(); writer->writeClosingTag(name.c_str()); writer->writeLineBreak(); writer->writeLineBreak(); writer->drop(); return true; }
// load the level objects from disk file bool CSLevel::loadFromDisk(stringc filename, bool destroyOld) { CS_LOG(CSLOGTYPE::CSL_DEBUG, "*************************** Loading level from file %s ***************************", filename.c_str()); if (destroyOld) clear(); // attempt to open the file IXMLReader* reader = getDevice()->getFileSystem()->createXMLReader(filename); if (!reader) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to open file %s", filename.c_str()); return false; } // read file while (reader->read()) { // based on the node type switch (reader->getNodeType()) { case io::EXN_ELEMENT: { // get the node name stringw name = reader->getNodeName(); // if this is an object definition if (stringw("CAMERA") == name) { stringw pos = reader->getAttributeValueSafe(L"POSITION"); stringw tar = reader->getAttributeValueSafe(L"TARGET"); if (getCamera()) { getCamera()->setPosition(stringcToVector3df(stringc(pos))); getCamera()->setTarget(stringcToVector3df(stringc(tar))); } else CS_LOG(CSLOGTYPE::CSL_WARNING, "no camera in game save file"); } // if this is an object definition if (stringw("CSOBJECT") == name) { // get the object type stringw type = reader->getAttributeValueSafe(L"TYPE"); // attempt to create the object CSObject* obj = getObjectFactory()->createObjectByType(stringc(type)); if (obj) { // load the attributes from the file IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); attr->read(reader, false); // let the object deserialize from the attributes obj->deserializeAttributes(attr); // recreate the object using the new attribtues obj->reCreate(); // drop the pointer attr->drop(); } } } } } // drop the reader reader->drop(); CS_LOG(CSLOGTYPE::CSL_DEBUG, "*************************** finished Loading level from file %s ***************************", filename.c_str()); // everything went fine return true; }
// save the level objects to disk file bool CSLevel::saveToDisk(stringc filename) { // log this event CS_LOG(CSLOGTYPE::CSL_DEBUG, "Saving game data - %s", filename.c_str()); // creat ethe xml writer IXMLWriter* writer = getDevice()->getFileSystem()->createXMLWriter(filename); if (!writer) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to create save file %s", filename.c_str()); return false; } // write the xml header writer->writeXMLHeader(); vector3df pos(0, 0, 0); vector3df tar(0, 0, 0); if (getCamera()) { pos = getCamera()->getPosition(); tar = getCamera()->getTarget(); } // write the camera position and target writer->writeLineBreak(); writer->writeElement(L"CAMERA", false, L"POSITION", stringw(vector3dfToStringc(pos)).c_str(), L"TARGET", stringw(vector3dfToStringc(tar)).c_str() ); writer->writeLineBreak(); writer->writeLineBreak(); // run through thte list of objects CSObject* obj = getObjectFactory()->getObjectManager()->getNextObject(true); while (obj) { // if this is not a debug object, then save it to disk if (!obj->getDebugObject()) { // write the node type stringw name("CSOBJECT"); writer->writeElement(name.c_str(), false, L"TYPE", stringw(obj->getInfo()->getName()).c_str()); writer->writeLineBreak(); // let the object serialize itself into our attributes structure IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); SAttributeReadWriteOptions options; obj->serializeAttributes(attr, &options); // if there are attributes if (attr->getAttributeCount() != 0) { // write the attributes to the xml file attr->write(writer); // make the file pretty writer->writeLineBreak(); } // drop the pointer attr->drop(); // finish writing the xml header / footer writer->writeClosingTag(name.c_str()); writer->writeLineBreak(); writer->writeLineBreak(); } // get the next object obj = getObjectFactory()->getObjectManager()->getNextObject(false); } // drop the pointer writer->drop(); // everything went fine return true; }
void NativeIrrlicht::setPath(std::string path) { gSdCardPath = path.c_str(); __android_log_print(ANDROID_LOG_INFO, "Irrlicht", "not handled %s", gSdCardPath.c_str()); }