bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s32 flags) { // write STL MESH header file->write("solid ",6); const core::stringc name(SceneManager->getMeshCache()->getMeshFilename(mesh)); file->write(name.c_str(),name.size()); file->write("\n\n",2); // write mesh buffers for (u32 i=0; i<mesh->getMeshBufferCount(); ++i) { IMeshBuffer* buffer = mesh->getMeshBuffer(i); if (buffer) { const u16 indexCount = buffer->getIndexCount(); switch(buffer->getVertexType()) { case video::EVT_STANDARD: { video::S3DVertex* vtx = (video::S3DVertex*)buffer->getVertices(); for (u32 j=0; j<indexCount; j+=3) writeFace(file, vtx[buffer->getIndices()[j]].Pos, vtx[buffer->getIndices()[j+1]].Pos, vtx[buffer->getIndices()[j+2]].Pos); } break; case video::EVT_2TCOORDS: { video::S3DVertex2TCoords* vtx = (video::S3DVertex2TCoords*)buffer->getVertices(); for (u32 j=0; j<indexCount; j+=3) writeFace(file, vtx[buffer->getIndices()[j]].Pos, vtx[buffer->getIndices()[j+1]].Pos, vtx[buffer->getIndices()[j+2]].Pos); } break; case video::EVT_TANGENTS: { video::S3DVertexTangents* vtx = (video::S3DVertexTangents*)buffer->getVertices(); for (u32 j=0; j<indexCount; j+=3) writeFace(file, vtx[buffer->getIndices()[j]].Pos, vtx[buffer->getIndices()[j+1]].Pos, vtx[buffer->getIndices()[j+2]].Pos); } break; } file->write("\n",1); } } file->write("endsolid ",9); file->write(name.c_str(),name.size()); return true; }
bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s32 flags) { // write STL MESH header file->write("solid ",6); const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh)); file->write(name.c_str(),name.size()); file->write("\n\n",2); // write mesh buffers for (u32 i=0; i<mesh->getMeshBufferCount(); ++i) { IMeshBuffer* buffer = mesh->getMeshBuffer(i); if (buffer) { const u32 indexCount = buffer->getIndexCount(); for (u32 j=0; j<indexCount; j+=3) { writeFace(file, buffer->getPosition(buffer->getIndices()[j]), buffer->getPosition(buffer->getIndices()[j+1]), buffer->getPosition(buffer->getIndices()[j+2])); } file->write("\n",1); } } file->write("endsolid ",9); file->write(name.c_str(),name.size()); return true; }
//! looks if file is in the same directory of path. returns offset of directory. //! 0 means in same directory. 1 means file is direct child of path s32 ioutils::isInSameDirectory(const core::stringc& path, const core::stringc& file) { s32 subA = 0; s32 subB = 0; s32 pos; if (path.size() && !path.equalsn(file, path.size())) return -1; pos = 0; while ((pos = path.findFirst('/', pos)) >= 0) { subA += 1; pos += 1; } pos = 0; while ((pos = file.findFirst('/', pos)) >= 0) { subB += 1; pos += 1; } return subB - subA; }
core::stringc CFileSystem::getAbsolutePath(const core::stringc& filename) const { c8 *p=0; #ifdef _IRR_WINDOWS_API_ #if !defined ( _WIN32_WCE ) c8 fpath[_MAX_PATH]; p = _fullpath( fpath, filename.c_str(), _MAX_PATH); #endif #elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) c8 fpath[4096]; fpath[0]=0; p = realpath(filename.c_str(), fpath); if (!p) { // content in fpath is undefined at this point if ('0'==fpath[0]) // seems like fpath wasn't altered { // at least remove a ./ prefix if ('.'==filename[0] && '/'==filename[1]) return filename.subString(2, filename.size()-2); else return filename; } else return core::stringc(fpath); } #endif return core::stringc(p); }
//! read the next token from file void CImageLoaderPPM::getNextToken(io::IReadFile* file, core::stringc& token) const { token = ""; c8 c; while(file->getPos()<file->getSize()) { file->read(&c, 1); if (c=='#') { while (c!='\n' && c!='\r' && (file->getPos()<file->getSize())) file->read(&c, 1); } else if (!core::isspace(c)) { token.append(c); break; } } while(file->getPos()<file->getSize()) { file->read(&c, 1); if (c=='#') { while (c!='\n' && c!='\r' && (file->getPos()<file->getSize())) file->read(&c, 1); } else if (!core::isspace(c)) token.append(c); else break; } }
s32 PlayerManager::getStatAsInteger(const core::stringw& key) const { const core::stringc s = getStat(key); if (s.empty()) return 0; return core::strtol10(s.c_str()); }
//! returns the base part of a filename, i.e. all except for the directory //! part. If no directory path is prefixed, the full name is returned. core::stringc CFileSystem::getFileBasename(const core::stringc& filename, bool keepExtension) const { // find last forward or backslash s32 lastSlash = filename.findLast('/'); const s32 lastBackSlash = filename.findLast('\\'); lastSlash = core::max_(lastSlash, lastBackSlash); // get number of chars after last dot s32 end = 0; if (!keepExtension) { // take care to search only after last slash to check only for // dots in the filename end = filename.findLast('.', lastSlash); if (end == -1) end=0; else end = filename.size()-end; } if ((u32)lastSlash < filename.size()) return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end); else if (end != 0) return filename.subString(0, filename.size()-end); else return filename; }
core::stringc GetContextPathFromFilename( const core::stringc& filename ) { core::stringc path; s32 i=filename.size()-1; while ( i >= 0 && filename[i] != '/' ) { i--; } path = filename.subString( 0, i+1 ); return path; }
//! returns the directory part of a filename, i.e. all until the first //! slash or backslash, excluding it. If no directory path is prefixed, a '.' //! is returned. core::stringc CFileSystem::getFileDir(const core::stringc& filename) const { // find last forward or backslash s32 lastSlash = filename.findLast('/'); const s32 lastBackSlash = filename.findLast('\\'); lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash; if ((u32)lastSlash < filename.size()) return filename.subString(0, lastSlash); else return "."; }
bool FileSceneNode::isanimesh(core::stringc name) { if ((name.subString(name.size() - 4, 4).equals_ignore_case(".md2")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".md3")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".obj")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".bsp")) || (name.subString(name.size() - 5, 5).equals_ignore_case(".my3d")) || (name.subString(name.size() - 5, 5).equals_ignore_case(".lmts")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".csm")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".oct"))) return true; return false; }
//! sets the caption of the window void CIrrDeviceWin32::setWindowCaption(const wchar_t* text) { DWORD dwResult; if (IsNonNTWindows) { const core::stringc s = text; SendMessageTimeout(HWnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(s.c_str()), SMTO_ABORTIFHUNG, 2000, &dwResult); } else SendMessageTimeoutW(HWnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text), SMTO_ABORTIFHUNG, 2000, &dwResult); }
//! deletes the path from a filename void CPakReader::deletePathFromFilename(core::stringc& filename) { // delete path from filename const c8* p = filename.c_str() + filename.size(); // search for path separator or beginning while (*p!='/' && *p!='\\' && p!=filename.c_str()) --p; if (p != filename.c_str()) { ++p; filename = p; } }
//! const c8* CTestSceneNode::getSceneCorePropertiesXMLString() { static core::stringc xmlstr; xmlstr = ""; if (getMaterialsCount() == 1) { const c8* mat_xml = SCENE_MANAGER.getMaterialXMLText(getMaterial(0)); xmlstr.append(mat_xml); } xmlstr.sprintf("<GeomPrimitive type=\"%s\" />\n", GeomPrimitiveTypeStr[m_GeomPrimitiveType]); return xmlstr.c_str(); }
bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, scene::IMesh* mesh, s32 flags) { // write STL MESH header file->write("binary ",7); const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh)); const s32 sizeleft = 73-name.size(); // 80 byte header if (sizeleft<0) file->write(name.c_str(),73); else { char* buf = new char[80]; memset(buf, 0, 80); file->write(name.c_str(),name.size()); file->write(buf,sizeleft); delete [] buf; } u32 facenum = 0; for (u32 j=0; j<mesh->getMeshBufferCount(); ++j) facenum += mesh->getMeshBuffer(j)->getIndexCount()/3; file->write(&facenum,4); // write mesh buffers for (u32 i=0; i<mesh->getMeshBufferCount(); ++i) { IMeshBuffer* buffer = mesh->getMeshBuffer(i); if (buffer) { const u32 indexCount = buffer->getIndexCount(); const u16 attributes = 0; for (u32 j=0; j<indexCount; j+=3) { const core::vector3df& v1 = buffer->getPosition(buffer->getIndices()[j]); const core::vector3df& v2 = buffer->getPosition(buffer->getIndices()[j+1]); const core::vector3df& v3 = buffer->getPosition(buffer->getIndices()[j+2]); const core::plane3df tmpplane(v1,v2,v3); file->write(&tmpplane.Normal, 12); file->write(&v1, 12); file->write(&v2, 12); file->write(&v3, 12); file->write(&attributes, 2); } } } return true; }
CShaderMaterial::CShaderMaterial(IrrlichtDevice* device, const core::stringc& name, io::path vsFile, core::stringc vsEntry, video::E_VERTEX_SHADER_TYPE vsType, io::path psFile, core::stringc psEntry, video::E_PIXEL_SHADER_TYPE psType, video::E_MATERIAL_TYPE baseMaterial) : Device(device), Name(name), PixelShaderFlags(0), VertexShaderFlags(0) { s32 userdata = 0; io::path vsPath; io::path psPath; // log action core::stringc msg = core::stringc("compiling material ") + name; Device->getLogger()->log(msg.c_str(), ELL_INFORMATION); // create destination path for (driver specific) shader files if(Device->getVideoDriver()->getDriverType() == video::EDT_OPENGL) { vsPath = core::stringc("./shaders/glsl/") + vsFile; psPath = core::stringc("./shaders/glsl/") + psFile; userdata = 1; } if(Device->getVideoDriver()->getDriverType() == video::EDT_DIRECT3D9) { vsPath=core::stringc("./shaders/hlsl/") + vsFile; psPath=core::stringc("./shaders/hlsl/") + psFile; userdata = 0; } // create shader material video::IGPUProgrammingServices* gpu = Device->getVideoDriver()->getGPUProgrammingServices(); s32 matID = gpu->addHighLevelShaderMaterialFromFiles( vsPath, vsEntry.c_str(), vsType, psPath, psEntry.c_str(), psType, this, baseMaterial, userdata); // set material type Material.MaterialType = (video::E_MATERIAL_TYPE)matID; // set the default texturenames and texture wrap // these are overridden by the effect.xml configuration for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i) { TextureName[i] = core::stringc("texture") + core::stringc(i); Material.TextureLayer[i].TextureWrapU = video::ETC_REPEAT; Material.TextureLayer[i].TextureWrapV = video::ETC_REPEAT; } }
bool FileSceneNode::isimg(core::stringc name) { if ((name.subString(name.size() - 4, 4).equals_ignore_case(".bmp")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".jpg")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".tga")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".pcx")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".png")) || (name.subString(name.size() - 4, 4).equals_ignore_case(".psd"))) return true; return false; }
//! deletes the path from a filename void CPakReader::deletePathFromFilename(core::stringc& filename) { // delete path from filename const c8* p = filename.c_str() + filename.size(); // suche ein slash oder den anfang. while (*p!='/' && *p!='\\' && p!=filename.c_str()) --p; core::stringc newName; if (p != filename.c_str()) { ++p; filename = p; } }
void CNPKReader::readString(core::stringc& name) { short stringSize; char buf[256]; File->read(&stringSize, 2); #ifdef __BIG_ENDIAN__ stringSize = os::Byteswap::byteswap(stringSize); #endif name.reserve(stringSize); while(stringSize) { const short next = core::min_(stringSize, (short)255); File->read(buf,next); buf[next]=0; name.append(buf); stringSize -= next; } }
Address::Address(core::stringc addr, core::stringc port) : resRoot(0), resActive(0) { Startup(); struct addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_protocol = SOCK_STREAM; int error = 0; error = getaddrinfo(addr.c_str(), port.c_str() , &hints, &resRoot); if(error) { printf("getaddrinfo failed... %s %s %s\n", addr.c_str(), port.c_str(), gai_strerror(error)); freeaddrinfo(resRoot); resRoot = resActive = 0; return; } };
core::stringc CMS3DMeshFileLoader::stripPathFromString(const core::stringc& inString, bool returnPath) const { s32 slashIndex=inString.findLast('/'); // forward slash s32 backSlash=inString.findLast('\\'); // back slash if (backSlash>slashIndex) slashIndex=backSlash; if (slashIndex==-1)//no slashes found { if (returnPath) return core::stringc(); //no path to return else return inString; } if (returnPath) return inString.subString(0, slashIndex + 1); else return inString.subString(slashIndex+1, inString.size() - (slashIndex+1)); }
/** * Check if we already have a config object for gamepad 'irr_id' as reported by * irrLicht, If no, create one. Returns true if new configuration was created, * otherwise false. */ bool DeviceManager::getConfigForGamepad(const int irr_id, const core::stringc& name, GamepadConfig **config) { bool found = false; bool configCreated = false; // Find appropriate configuration for(unsigned int n=0; n < m_gamepad_configs.size(); n++) { if(m_gamepad_configs[n].getName() == name.c_str()) { *config = m_gamepad_configs.get(n); found = true; } } // If we can't find an appropriate configuration then create one. if (!found) { if(irr_id < (int)(m_irrlicht_gamepads.size())) { *config = new GamepadConfig( name.c_str(), m_irrlicht_gamepads[irr_id].Axes, m_irrlicht_gamepads[irr_id].Buttons ); } #ifdef ENABLE_WIIUSE else // Wiimotes have a higher ID and do not refer to m_irrlicht_gamepads { // The Wiimote manager will set number of buttons and axis *config = new GamepadConfig(name.c_str()); } #endif // Add new config to list m_gamepad_configs.push_back(*config); configCreated = true; } return configCreated; }
core::stringc CFileSystem::getAbsolutePath(const core::stringc& filename) const { c8 *p=0; core::stringc ret; #ifdef _IRR_WINDOWS_API_ c8 fpath[_MAX_PATH]; p = _fullpath( fpath, filename.c_str(), _MAX_PATH); ret = p; #elif (defined(_IRR_POSIX_API_) || defined(MACOSX)) c8 fpath[4096]; p = realpath(filename.c_str(), fpath); ret = p; #endif return ret; }
core::stringc CHashMD5::quickHash(core::stringc str) { hash_start(); hash_append((u8*)str.c_str(), str.size()); u8 digest[16]; hash_finish(digest, 16); c8 retstr[33]; memset(retstr, 0, 33); c8* temp = retstr; for(int i = 0; i < 16; i++) { if((digest[i] & 0xff) > 0xf){ sprintf(temp, "%x", (digest[i] & 0xff)); }else{ sprintf(temp, "0%x", (digest[i] & 0xff)); } temp += 2; } core::stringc ret(retstr); return ret; };
void B3DMeshLoader::readString(core::stringc& newstring) { newstring=""; while (B3DFile->getPos() <= B3DFile->getSize()) { c8 character; B3DFile->read(&character, sizeof(character)); if (character==0) return; newstring.append(character); } }
const c8* CTextSceneNode::getSceneCorePropertiesXMLString() { core::stringc str; static core::stringc xmlstr; xmlstr = ""; if (getMaterialsCount() == 1) { const c8* mat_xml = SCENE_MANAGER.getMaterialXMLText(getMaterial(0)); xmlstr.append(mat_xml); } str.sprintf( "<Font filename=\"%s\" size=\"%d/\" />\n", m_Font->getFileName(), m_Font->getSize() ); xmlstr.append(str); str.sprintf( "<Text value=\"%s\" />\n", core::stringc(getText()).c_str() ); xmlstr.append(str); img::SColor c = getTextColor(); str.sprintf( "<TextColor value=\"%d,%d,%d,%d\" />\n", c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() ); xmlstr.append(str); return xmlstr.c_str(); }
bool CGUISkinSystem::populateTreeView(gui::IGUITreeView *control,const core::stringc& skinname) { bool ret = false; io::path oldpath = fs->getWorkingDirectory(); fs->changeWorkingDirectoryTo(skinsPath); registry = new CXMLRegistry(fs); if(!registry->loadFile(SKINSYSTEM_SKINFILE,skinname.c_str())) { return ret; } ret = registry->populateTreeView(control); delete registry; registry = NULL; fs->changeWorkingDirectoryTo(oldpath); return ret; }
//! returns the base part of a filename, i.e. all except for the directory //! part. If no directory path is prefixed, the full name is returned. core::stringc CFileSystem::getFileBasename(const core::stringc& filename, bool keepExtension) const { // find last forward or backslash s32 lastSlash = filename.findLast('/'); const s32 lastBackSlash = filename.findLast('\\'); lastSlash = core::max_(lastSlash, lastBackSlash); s32 end = 0; if (!keepExtension) { end = filename.findLast('.'); if (end == -1) end=0; else end = filename.size()-end; } if ((u32)lastSlash < filename.size()) return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end); else if (end != 0) return filename.subString(0, filename.size()-end); else return filename; }
void Translation::loadTextData(const core::stringc& fullPath) { //cout << "Translation file loaded : " << fullPath.c_str() << endl; wifstream textFile(fullPath.c_str(), ios::in); if (textFile) { //cout << "Processing translation file..." << endl; wchar_t currentChar; bool inTextIdentifier = true; bool inTextValue = false; core::stringc identifier = ""; core::stringw value = L""; while (textFile.get(currentChar)) { if (currentChar == '\n' || currentChar == '\r') { // Nouvelle traduction if (identifier != "") { //cout << "Added translation (" << identifier.c_str() << ") = (" << value.c_str() << ")" << endl; textData[identifier] = value; } identifier = ""; value = L""; inTextValue = false; inTextIdentifier = true; } else { if (inTextValue) { value.append(currentChar); } if (inTextIdentifier) { if (currentChar == '=') { // Passage de l'identifiant a la valeur inTextIdentifier = false; inTextValue = true; } else { identifier.append(currentChar); } } } } textFile.close(); } }
void Surface::load(BinaryFileReader* pReader) { flags = pReader->readLong(); pReader->readString(textureName); textureName.replace('\\', '/'); lightMapId = pReader->readLong(); pReader->readVec2f(&uvOffset); pReader->readVec2f(&uvScale); uvRotation = pReader->readFloat(); s32 vtxCount = pReader->readLong(); s32 triCount = pReader->readLong(); s32 lineCount = pReader->readLong(); for(s32 v = 0; v < vtxCount; v++) { vertices.push_back(Vertex()); vertices.getLast().load(pReader); } for(s32 t = 0; t < triCount; t++) { Triangle tri; pReader->readBuffer(&tri, sizeof(tri)); triangles.push_back(tri); } for(s32 l = 0; l < lineCount; l++) { Line line; pReader->readBuffer(&line,sizeof(line)); lines.push_back(line); } }
void World::SetSkyBox(const core::stringc &top, const core::stringc &bottom, const core::stringc &left, const core::stringc &right, const core::stringc &front, const core::stringc &back) { scene::ISceneManager *smgr = engine->GetIrrlichtDevice()->getSceneManager(); video::IVideoDriver *driver = engine->GetIrrlichtDevice()->getVideoDriver(); if (skyBoxNode) skyBoxNode->remove(); skyBoxNode = smgr->addSkyBoxSceneNode( driver->getTexture( top.c_str() ), driver->getTexture( bottom.c_str() ), driver->getTexture( left.c_str() ), driver->getTexture( right.c_str() ), driver->getTexture( front.c_str() ), driver->getTexture( back.c_str() ) ); SetSkyBoxShader(skyBoxShader); }