bool OgitorWorld::LoadGlobalObject(const String_t &type, const Register::Table &dict) { if((type.compare("Caelum Object") == 0) || (type.compare("Viewport Object") == 0)) { return true; } else if(type.compare("OctreeSceneManager") == 0) { auto &render = OgreEngine::Render::GetInstance(); render.SetAmbientColor(Register::GetColour(dict, "ambient")); return true; } else if(type.compare("Terrain Group Object") == 0) { m_pclTerrainGroupTable = &dict; return true; } else if(type.compare("Terrain Page Object") == 0) { m_pclTerrainPageTable = &dict; return true; } return false; }
bool zip::ZipArchiveInput::ReadFile( String_t const& fileName, Byte_t*& pMemoryBlock, size_t& size ) { String_t fileNameKey = fileName; if( !m_caseSensitive ) for (size_t i = 0; i < fileNameKey.size(); ++i ) fileNameKey[i] = _ttolower( fileNameKey[i] ); NameToEntry_t::const_iterator keyValue = m_nameToEntry.find( fileNameKey ); if( keyValue == m_nameToEntry.end() ) { m_errorMessage << "file " << fileNameKey << " not found in the zip index" << std::endl; return false; } ZipEntry const& zipEntry = keyValue->second; unz_file_pos pos; pos.pos_in_zip_directory = zipEntry.pos_in_zip_directory; pos.num_of_file = zipEntry.num_of_file; int err = unzGoToFilePos( uf, &pos ); if( err != UNZ_OK ) { m_errorMessage << "Can't go to file " << fileName << std::endl; return false; } return ReadCurrentFile( fileName, pMemoryBlock, size ); }
bool OgitorWorld::LoadStaticObject(StaticObject_s &object, const String_t &name, const String_t &type, const Register::Table &dict) { TempStaticObject_s temp; temp.m_fParent = dict.TryGetString(PH_ENTITY_KEY_PARENT_NODE, object.strParent) && (object.strParent.compare(PH_WORLD_SCENE_MANAGER_NAME) != 0); temp.m_strName = name; if(type.compare("Node Object") == 0) { this->LoadNodeObject(temp, dict); } else if(type.compare("Light Object") == 0) { this->LoadLightObject(temp, dict); } else if(type.compare("Entity Object") == 0) { this->LoadEntityObject(temp, dict); } else { LogMakeStream() << "[OgitorWorld::LoadStaticObject] Error, unknown static object type: " << type << "\n"; return false; } temp.Commit(object); //Check if we have a directional light after commit, to avoid dangling pointers if((object.m_pclLight != NULL) && (object.m_pclLight->getType() == Ogre::Light::LT_DIRECTIONAL)) m_pclTerrainLight = object.m_pclLight; return true; }
bool Phobos::System::KeyboardInputDevice::TryGetActionId(const String_t &name, UInt_t &out) const { if(name.length() == 1) { Char_t ch = name[0]; if(IS_ASCII_CHAR(ch)) { out = static_cast<UInt_t>(ch); return true; } else return false; } else { UInt_t i = 0; for(;stInputKeyNames_g[i].pstrzName != NULL; ++i) { if(name.compare(stInputKeyNames_g[i].pstrzName) == 0) { out = stInputKeyNames_g[i].uKey; return true; } } return false; } }
bool zip::ZipArchiveInput::Index() { static const int UNZ_MAXFILENAMEINZIP = 256; int err = unzGoToFirstFile(uf); if( err != UNZ_OK ) { m_errorMessage << "Can't go to first file" << std::endl; return false; } while (err == UNZ_OK) { char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; err = unzGetCurrentFileInfo64(uf, NULL, szCurrentFileName, sizeof(szCurrentFileName)-1,NULL,0,NULL,0); if(err == UNZ_OK) { #ifdef SCARAB_WCHAR_MODE String_t fileNameKey = utf_convert::as_wide( szCurrentFileName ); #else String_t fileNameKey = szCurrentFileName; #endif if( !m_caseSensitive ) for (size_t i = 0; i < fileNameKey.size(); ++i ) fileNameKey[i] = _ttolower( fileNameKey[i] ); unz_file_pos pos; err = unzGetFilePos( uf, &pos ); if( err != UNZ_OK ) { m_errorMessage << "Can't get file position for " << fileNameKey << std::endl; return false; } ZipEntry zipEntry; zipEntry.pos_in_zip_directory = pos.pos_in_zip_directory; zipEntry.num_of_file = pos.num_of_file; m_nameToEntry.insert( std::make_pair( fileNameKey, zipEntry ) ); err = unzGoToNextFile(uf); if( err != UNZ_OK && err != UNZ_END_OF_LIST_OF_FILE ) { m_errorMessage << "Can't go to next file" << std::endl; return false; } } else { m_errorMessage << "Can't get file info" << std::endl; return false; } } return err == UNZ_END_OF_LIST_OF_FILE; }
void Phobos::Register::Table::SetString(const String_t &key, const String_t &value) { CheckForKeyword(key); m_mapValues[key] = Value_s(value); if(key.compare(INHERIT_KEY) == 0) { m_strInherit = value; m_pclInherit = NULL; } if(key.compare(BASE_HIVE_KEY) == 0) { m_strBaseHive = value; m_pclInherit = NULL; } }
void Phobos::Engine::PluginManager::OnUpdate() { if(!m_fSystemReady) return; while(!m_lstPluginsToActivate.empty()) { String_t pluginName; pluginName.swap(m_lstPluginsToActivate.front()); m_lstPluginsToActivate.pop_front(); PluginInstance *plugin = static_cast<PluginInstance *>(this->TryGetChild(pluginName)); if(plugin) { plugin->Init(); } } }
void Phobos::Register::Table::SetCharMatrix(const String_t &key, const String_t &data, UInt16_t numRows, UInt16_t numColumns) { CheckForKeyword(key); this->CheckInvalidKey(key, parszStringOnlyKeys_g, "should be string data, not matrix"); if(numRows * numColumns == 0) { PH_RAISE(INVALID_PARAMETER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", "Matrix cannot be empty"); } if(numRows * numColumns != data.length()) { std::stringstream stream; stream << "Matrix data size (" << data.length() << ") does not match width (" << numColumns << ") and height (" << numRows << ") parameters"; PH_RAISE(INVALID_PARAMETER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", stream.str()); } m_mapValues[key] = Value_s(data, numRows, numColumns); }
void Phobos::Register::Table::CheckInvalidKey(const String_t &key, const char *keys[], const char *message) const { for(int i = 0;keys[i]; ++i) { if(key.compare(keys[i]) == 0) { std::stringstream stream; stream << "Value " << key << " " << message; PH_RAISE(INVALID_PARAMETER_EXCEPTION, "Phobos::Register::Table::CheckInvalidKey", stream.str()); } } }
int32_t equals(String_t* self, String_t* anObject) { if (self == anObject) { return 1; } String_t *anotherString = (String_t*) anObject; int32_t n = self->length(self); if (n == anotherString->length(anotherString)) { char* v1 = self->toString(self); char* v2 = anotherString->toString(anotherString); int i = 0; while (n-- != 0) { if (v1[i] != v2[i]) { return 0; } i++; } return 1; } return 0; }
void Phobos::System::WindowSDL::Open(const String_t &name, const UIntSize_t &size, void *parentWindow) { SDL_Init(SDL_INIT_VIDEO); SDL_EnableUNICODE(1); #ifdef PH_WIN32 unsigned int flags = 0; HWND parent = reinterpret_cast<HWND>(parentWindow); if(parent) flags = SDL_NOFRAME | SDL_RESIZABLE; SDL_SetVideoMode(size.m_tWidth, size.m_tHeight, 32, flags); if(parent) { HWND sdlHwnd = reinterpret_cast<HWND>(this->GetHandler()); //not 100% trusted, but give us an extra check if(!IsWindow(parent)) { PH_RAISE(INVALID_PARAMETER_EXCEPTION, "[WindowSDL::Open]", "Invalid parent window handle"); } RECT parentRec; GetClientRect(parent, &parentRec); //SetWindowPos( sdlHwnd, parent, 0, 0, parentRec.right, parentRec.bottom, ( 0 /*SWP_NOSIZE*/ | SWP_SHOWWINDOW )); MoveWindow(sdlHwnd, 0, 0, parentRec.right, parentRec.bottom, true); SetParent(sdlHwnd, parent); //SetWindowLong(sdlHwnd, GWL_STYLE, WS_MAXIMIZE); } #else SDL_SetVideoMode(rect.tWidth, rect.tHeight, 0, SDL_OPENGL); #endif #ifdef PH_LINUX SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); #endif SDL_WM_SetCaption(name.c_str(), NULL); }
bool read_string( const String_t& s, Value_t& value ) { typename String_t::const_iterator begin = s.begin(); return read_range( begin, s.end(), value ); }
void read_string_or_throw( const String_t& s, Value_t& value ) { add_posn_iter_and_read_range_or_throw( s.begin(), s.end(), value ); }
void Phobos::Register::Table::Load(Parser &parser) { String_t idName; String_t value; ParserTokens_e token = parser.GetToken(&value); if(token != TOKEN_OPEN_BRACE) RaiseParseException(parser, TOKEN_OPEN_BRACE, token, value, "Phobos::Register::Table::Load"); for(;;) { token = parser.GetToken(&value); if(token == TOKEN_CLOSE_BRACE) break; idName.clear(); //Accepts name in the format: //model= //RenderCompoenent.model= for(;;) { if(token != TOKEN_ID) RaiseParseException(parser, TOKEN_ID, token, value, "Phobos::Register::Table::Load"); idName.append(value); token = parser.GetToken(&value); if(token == TOKEN_DOT) { idName.append(value); token = parser.GetToken(&value); continue; } if(token == TOKEN_EQUAL) break; RaiseParseException(parser, TOKEN_EQUAL, token, value, "Phobos::Register::Table::Load"); } token = parser.GetToken(&value); switch(token) { case TOKEN_ID: if(value.compare("new") == 0) { this->ParseSpecialValue(idName, parser); break; } //not special, just store it //fall thought case TOKEN_NUMBER: case TOKEN_STRING: this->SetString(idName, value); break; default: RaiseParseException(parser, TOKEN_STRING, token, idName, "Phobos::Register::Table::Load"); break; } token = parser.GetToken(&value); if(token != TOKEN_SEMI_COLON) RaiseParseException(parser, TOKEN_SEMI_COLON, token, value, "Phobos::Register::Table::Load"); } }
void Phobos::Register::Table::ParseSpecialValue(const String_t &idName, Parser &parser) { String_t type; ParserTokens_e token; if((token = parser.GetToken(&type)) != TOKEN_ID) { RaiseParseException(parser, TOKEN_ID, token, type, "Phobos::Register::Table::ParseSpecialValue"); } if(type.compare("CharMatrix") == 0) { if((token = parser.GetToken(NULL)) != TOKEN_OPEN_PAREN) { RaiseParseException(parser, TOKEN_OPEN_PAREN, token, type, "Phobos::Register::Table::ParseSpecialValue"); } String_t matrix; String_t row; UInt16_t numColumns = 0; UInt16_t numRows = 0; bool first = true; for(;;) { token = parser.GetToken(&row); if(token == TOKEN_CLOSE_PAREN) { if(first) { //do not allow empty matrix RaiseParseException(parser, "matrix data", "closing parenthesis", "Phobos::Register::Table::ParseSpecialValue"); } this->SetCharMatrix(idName, matrix, numRows, numColumns); break; } else if(token == TOKEN_STRING) { if(first) { numColumns = row.length(); if(numColumns == 0) PH_RAISE(PARSER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", "Matrix cannot be empty"); first = false; } else if(numColumns != row.length()) { PH_RAISE(PARSER_EXCEPTION, "Phobos::Register::Table::ParseSpecialValue", "Matrix rows should always have the same length"); } matrix.append(row); ++numRows; } else { RaiseParseException(parser, TOKEN_STRING, token, row, "Phobos::Register::Table::ParseSpecialValue"); } } } else { RaiseParseException(parser, " valid especial type, ie CharMatrix", type.c_str(), "Phobos::Register::Table::ParseSpecialValue"); } }
bool hatch::RegistryParser::ParseFile( Registry& registry, RegistryAction& action ) { if( !SkipEndLines() ) { m_errorMessage << "Parameters expected after 'file {'"; return false; } bool process = true; do { if( m_tokenizer.IsWord() ) { const char* key = m_tokenizer.GetWord(); if( Cmp( "action", key ) ) { String_t value; if( !ParseWordValue( value ) ) { m_errorMessage << "for action"; return false; } if( !dung::StringToAction( value.c_str(), action.action ) ) { m_errorMessage << _T("Unknown action ") << value; return false; } } else if( Cmp( "diff_path", key ) ) { if( !ParseStringValue( action.diff_path ) ) { m_errorMessage << _T("for diff_path"); return false; } } else if( Cmp( "old_path", key ) ) { if( !ParseStringValue( action.old_path ) ) { m_errorMessage << _T("for old_path"); return false; } } else if( Cmp( "new_path", key ) ) { if( !ParseStringValue( action.new_path ) ) { m_errorMessage << "for new_path"; return false; } } else if( Cmp( "diff_method", key ) ) { if( !ParseWordValue( action.diff_method ) ) { m_errorMessage << "for diff_method"; return false; } } else if( Cmp( "old_sha1", key ) ) { String_t value; if( !ParseStringValue( value ) ) { m_errorMessage << "for old_sha1"; return false; } if( !dung::StringToSHA1( value.c_str(), action.oldSha1 )) { m_errorMessage << "Can't convert " << value << " to old_sha1"; return false; } SCARAB_ASSERT( dung::SHA1_TO_TSTRING( action.oldSha1 ) == value ); } else if( Cmp( "new_sha1", key ) ) { String_t value; if( !ParseStringValue( value ) ) { m_errorMessage << "for new_sha1"; return false; } if( !dung::StringToSHA1( value.c_str(), action.newSha1 )) { m_errorMessage << "Can't convert " << value << " to new_sha1"; return false; } SCARAB_ASSERT( dung::SHA1_TO_TSTRING( action.newSha1 ) == value ); } else if( Cmp( "old_size", key ) ) { String_t value; if( !ParseNumValue( value ) ) { m_errorMessage << "for old_size"; return false; } action.oldSize = _tchar_to_long( value.c_str() ); } else if( Cmp( "new_size", key ) ) { String_t value; if( !ParseNumValue( value ) ) { m_errorMessage << "for new_size"; return false; } action.newSize = _tchar_to_long( value.c_str() ); } } else if( m_tokenizer.IsSymbol() && m_tokenizer.GetSymbol() == '}' ) return true; if( !m_tokenizer.ParseNext() ) { m_errorMessage << "'}' expected for 'file'"; process = false; } } while( process ); return false; }