void CSoundManager::CleanupSounds() { FS_FileSet M_BASE; FS_FileSet M_THUM; FS_FileSet M_GAME; FS_FileSet M_GAME_DEL; FS_FileSet M_THM_DEL; FS.file_list (M_BASE,_sounds_, FS_ListFiles|FS_ClampExt,"*.wav"); FS.file_list (M_THUM,_sounds_, FS_ListFiles|FS_ClampExt,"*.thm"); FS.file_list (M_GAME,_game_sounds_, FS_ListFiles|FS_ClampExt,"*.ogg"); FS_FileSetIt it; FS_FileSetIt _E; // check source exist it = M_GAME.begin(); _E = M_GAME.end(); for (; it!=_E; it++){ xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); FS_FileSetIt bs = M_BASE.find(base_name); if (bs==M_BASE.end()) M_GAME_DEL.insert (*it); } it = M_THUM.begin(); _E = M_THUM.end(); for (; it!=_E; it++){ xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); FS_FileSetIt bs = M_BASE.find(base_name); if (bs==M_BASE.end()) M_THM_DEL.insert (*it); } SPBItem* pb = UI->ProgressStart(M_GAME_DEL.size()+M_THM_DEL.size(),"Cleanup sounds..."); // mark game del sounds it = M_GAME_DEL.begin(); _E = M_GAME_DEL.end(); for (; it!=_E; it++){ xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); string_path fn; FS.update_path (fn,_game_sounds_,EFS.ChangeFileExt(base_name,".ogg").c_str()); EFS.MarkFile (fn,true); pb->Inc (); } // mark thm sounds it = M_THM_DEL.begin(); _E = M_THM_DEL.end(); for (; it!=_E; it++){ xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); string_path fn; FS.update_path (fn,_sounds_,EFS.ChangeFileExt(base_name,".thm").c_str()); EFS.MarkFile (fn,true); pb->Inc (); } UI->ProgressEnd (pb); }
void CBone::Load_0(IReader& F) { F.r_stringZ (name); xr_strlwr(name); F.r_stringZ (parent_name); xr_strlwr(parent_name); F.r_stringZ (wmap); F.r_fvector3 (rest_offset); F.r_fvector3 (rest_rotate); rest_length = F.r_float(); std::swap (rest_rotate.x,rest_rotate.y); Reset (); }
CCommandVar CActorTools::CommandImport(CCommandVar p1, CCommandVar p2) { xr_string temp_fn = p1.IsString()?xr_string(p1):xr_string(""); if(p1.IsString()||EFS.GetOpenName(_import_,temp_fn)) { FS_Path* pp = FS.get_path(_import_); if (temp_fn.npos!=temp_fn.find(pp->m_Path)) { //. andy temp_fn = xr_string(temp_fn.c_str()+strlen(FS.get_path(_import_)->m_Path)); xr_strlwr(temp_fn); if (!Tools->IfModified()) return FALSE; ExecCommand( COMMAND_CLEAR ); CTimer T; T.Start(); if (!ATools->Import(NULL/*_import_*/,temp_fn.c_str())) return FALSE; m_LastFileName = temp_fn.c_str(); ELog.Msg(mtInformation,"Object '%s' successfully imported. Loading time - %3.2f(s).",m_LastFileName.c_str(),T.GetElapsed_sec()); if (ExecCommand( COMMAND_SAVE,temp_fn,1 )){ xr_string mfn; mfn = temp_fn; //. andy FS.update_path(mfn,_import_,temp_fn.c_str()); EFS.MarkFile(mfn.c_str(),true); }else{ ExecCommand( COMMAND_CLEAR ); } return TRUE; }else{ ELog.Msg (mtError,"Invalid file path. "); } } return FALSE; }
void CBone::LoadData(IReader& F) { R_ASSERT(F.find_chunk(BONE_CHUNK_DEF)); F.r_stringZ (name); xr_strlwr(name); R_ASSERT(F.find_chunk(BONE_CHUNK_MATERIAL)); F.r_stringZ (game_mtl); R_ASSERT(F.find_chunk(BONE_CHUNK_SHAPE)); F.r (&shape,sizeof(SBoneShape)); if (F.find_chunk(BONE_CHUNK_FLAGS)) IK_data.ik_flags.assign(F.r_u32()); R_ASSERT(F.find_chunk(BONE_CHUNK_IK_JOINT)); IK_data.type = (EJointType)F.r_u32(); F.r (IK_data.limits,sizeof(SJointLimit)*3); IK_data.spring_factor = F.r_float(); IK_data.damping_factor = F.r_float(); if (F.find_chunk(BONE_CHUNK_IK_JOINT_BREAK)){ IK_data.break_force = F.r_float(); IK_data.break_torque= F.r_float(); } if (F.find_chunk(BONE_CHUNK_IK_JOINT_FRICTION)){ IK_data.friction = F.r_float(); } if (F.find_chunk(BONE_CHUNK_MASS)){ mass = F.r_float(); F.r_fvector3(center_of_mass); } }
void CSMotion::Save(IWriter& F) { CCustomMotion::Save(F); F.w_u16 (EOBJ_SMOTION_VERSION); F.w_s8 (m_Flags.get()); F.w_u16 (m_BoneOrPart); F.w_float (fSpeed); F.w_float (fAccrue); F.w_float (fFalloff); F.w_float (fPower); F.w_u16 ((u16)bone_mots.size()); for(BoneMotionIt bm_it=bone_mots.begin(); bm_it!=bone_mots.end(); bm_it++) { xr_strlwr (bm_it->name); F.w_stringZ (bm_it->name); F.w_u8 (bm_it->m_Flags.get()); for (int ch=0; ch<ctMaxChannel; ch++) bm_it->envs[ch]->Save(F); } u32 sz = marks.size(); F.w_u32 (sz); for(u32 i=0; i<sz; ++i) marks[i].Save(&F); }
CCommandVar CActorTools::CommandSave(CCommandVar p1, CCommandVar p2) { if (p2==1){ xr_string temp_fn = ATools->m_LastFileName.c_str(); if (EFS.GetSaveName ( _objects_, temp_fn )){ temp_fn = EFS.ChangeFileExt(temp_fn,".object"); return ExecCommand(COMMAND_SAVE,temp_fn,0); } }else{ if (p1.IsInteger()) return ExecCommand(COMMAND_SAVE,xr_string(ATools->m_LastFileName.c_str()),0); xr_string temp_fn = xr_string(p1); if (temp_fn.empty()){ return ExecCommand(COMMAND_SAVE,temp_fn,1); }else{ xr_strlwr (temp_fn); EFS.UnlockFile (temp_fn.c_str()); CTimer T; T.Start(); CCommandVar res; if (Tools->Save(temp_fn.c_str())){ ELog.Msg (mtInformation,"Object '%s' successfully saved. Saving time - %3.2f(s).",m_LastFileName.c_str(),T.GetElapsed_sec()); m_LastFileName = temp_fn.c_str(); EPrefs->AppendRecentFile (m_LastFileName.c_str()); ExecCommand (COMMAND_UPDATE_CAPTION); res = TRUE; }else{ res = FALSE; } EFS.LockFile (temp_fn.c_str()); return res; } } return FALSE; }
void CSE_Visual::set_visual (LPCSTR name, bool load) { string_path tmp; strcpy (tmp,name); if (strext(tmp)) *strext(tmp) = 0; xr_strlwr (tmp); visual_name = tmp; }
//--------------------------------------------------------------------------- // actor commands //--------------------------------------------------------------------------- CCommandVar CActorTools::CommandLoad(CCommandVar p1, CCommandVar p2) { xr_string temp_fn = p1.IsString()?xr_string(p1):xr_string(""); if(!p1.IsString()){ temp_fn = ChangeFileExt(m_LastFileName,"").c_str(); if (!EFS.GetOpenName ( _objects_, temp_fn )) return FALSE; } if( temp_fn.size() ){ xr_strlwr (temp_fn); if (!IfModified()) return FALSE; if (!FS.exist(temp_fn.c_str())){ Msg ("#!Can't load file: %s",temp_fn.c_str()); return FALSE; } ExecCommand (COMMAND_CLEAR); BOOL bReadOnly = !FS.can_modify_file(temp_fn.c_str()); m_Flags.set (flReadOnlyMode,bReadOnly); if (bReadOnly || EFS.CheckLocking(temp_fn.c_str(),false,true)) Msg ("#!Object '%s' opened in readonly mode.",temp_fn.c_str()); /* shared_str locker; if ((false==bReadOnly) && EFS.CheckLocking(_objects_,temp_fn.c_str(),false,true,&locker)){ Log ("#!Object opened in readonly mode. Locked by user:"******"#!You don't have permisions to modify object:",temp_fn.c_str()); } */ // set enable ... m_Props->SetReadOnly (bReadOnly); fraLeftBar->SetReadOnly (bReadOnly); CTimer T; T.Start(); if (!Load(temp_fn.c_str())){ return FALSE; } m_LastFileName = temp_fn.c_str(); ELog.Msg(mtInformation,"Object '%s' successfully loaded. Loading time - %3.2f(s).",m_LastFileName.c_str(),T.GetElapsed_sec()); EPrefs->AppendRecentFile(m_LastFileName.c_str()); ExecCommand (COMMAND_UPDATE_CAPTION); ExecCommand (COMMAND_UPDATE_PROPERTIES); // lock if (!bReadOnly) EFS.LockFile(m_LastFileName.c_str()); UndoClear(); UndoSave(); } return TRUE; }
void ReplaceSpaceAndLowerCase(shared_str& s) { if (*s){ char* _s = xr_strdup(*s); char* lp = _s; while(lp[0]){if (lp[0]==' ') lp[0]='_'; lp++;} xr_strlwr (_s); s = _s; xr_free (_s); } }
void CLevel::PrefetchSound (LPCSTR name) { // preprocess sound name string_path tmp; strcpy_s (tmp,name); xr_strlwr (tmp); if (strext(tmp)) *strext(tmp)=0; shared_str snd_name = tmp; // find in registry SoundRegistryMapIt it = sound_registry.find(snd_name); // if find failed - preload sound if (it==sound_registry.end()) sound_registry[snd_name].create(snd_name.c_str(),st_Effect,sg_SourceType); }
void CBone::Load_1(IReader& F) { R_ASSERT(F.find_chunk(BONE_CHUNK_VERSION)); u16 ver = F.r_u16(); if ((ver!=0x0001)&&(ver!=BONE_VERSION)) return; R_ASSERT(F.find_chunk(BONE_CHUNK_DEF)); F.r_stringZ (name); xr_strlwr(name); F.r_stringZ (parent_name); xr_strlwr(parent_name); F.r_stringZ (wmap); R_ASSERT(F.find_chunk(BONE_CHUNK_BIND_POSE)); F.r_fvector3 (rest_offset); F.r_fvector3 (rest_rotate); rest_length = F.r_float(); if (ver==0x0001) std::swap (rest_rotate.x,rest_rotate.y); LoadData (F); }
//////////////////////////////////////////////////////////////////////////// // CSE_Visual //////////////////////////////////////////////////////////////////////////// CSE_Visual::CSE_Visual (LPCSTR name) { if(name) { string_path tmp; strcpy (tmp, name); if(strext(tmp)) *strext(tmp) =0; xr_strlwr (tmp); visual_name = tmp; }else visual_name = NULL; startup_animation = "$editor"; flags.zero (); }
void CObject::Load (LPCSTR section ) { // Name R_ASSERT (section); cName_set (section); cNameSect_set (section); // Visual and light-track if (pSettings->line_exist(section,"visual")){ string_path tmp; strcpy (tmp, pSettings->r_string(section,"visual")); if(strext(tmp)) *strext(tmp) =0; xr_strlwr (tmp); cNameVisual_set (tmp); } setVisible (false); }
AnsiString CFolderHelper::GenerateName(LPCSTR _pref, int dgt_cnt, TFindObjectByName cb, bool allow_pref_name, bool allow_) { VERIFY (!cb.empty()); AnsiString result; int counter = 0; // test exist name xr_string pref = _pref; xr_strlwr (pref); if (allow_pref_name&&pref.size()){ result = pref.c_str(); bool res; cb (result.c_str(),res); if (!res)return result; } // generate new name string256 prefix = {"name"}; string32 mask; sprintf (mask,"%%s%s%%0%dd",allow_?"_":"",dgt_cnt); int pref_dgt_cnt = dgt_cnt+(allow_?1:0); int pref_size = pref.size(); if (pref_size>pref_dgt_cnt){ strcpy (prefix, pref.c_str()); bool del_suff = false; if (allow_&&(prefix[pref_size-pref_dgt_cnt]=='_')){ del_suff = true; for (int i=pref_size-pref_dgt_cnt+1; i<pref_size; i++) if (!isdigit(prefix[i])){ del_suff=false; break; } } if (del_suff) prefix[pref_size-pref_dgt_cnt] = 0; } bool res; do{ result.sprintf (mask, prefix, counter++); //"%s%04d" res = false; cb (result.c_str(),res); }while(res); return result; }
void xrSASH::LoopNative() { string_path in_file; FS.update_path(in_file, "$app_data_root$", m_strBenchCfgName); CInifile ini(in_file); IReader* R = FS.r_open(in_file); if (R) { FS.r_close(R); int test_count = ini.line_count("benchmark"); LPCSTR test_name, t; shared_str test_command; for (int i = 0; i < test_count; ++i) { ini.r_line("benchmark", i, &test_name, &t); //xr_strcpy(g_sBenchmarkName, test_name); test_command = ini.r_string_wb("benchmark", test_name); u32 cmdSize = test_command.size() + 1; Core.Params = (char*)xr_realloc(Core.Params, cmdSize); xr_strcpy(Core.Params, cmdSize, test_command.c_str()); xr_strlwr(Core.Params); RunBenchmark(test_name); // Output results ReportNative(test_name); } } else Msg("oa:: Native path can't find \"%s\" config file.", in_file); FlushLog(); }
void CCharacterInfo::load_shared (LPCSTR) { const ITEM_DATA& item_data = *id_to_index::GetById(m_ProfileId); CUIXml* pXML = item_data._xml; pXML->SetLocalRoot (pXML->GetRoot()); XML_NODE* item_node = pXML->NavigateToNode(id_to_index::tag_name, item_data.pos_in_file); R_ASSERT3(item_node, "profile id=", *item_data.id); pXML->SetLocalRoot(item_node); LPCSTR spec_char = pXML->Read("specific_character", 0, NULL); if(!spec_char) { data()->m_CharacterId = NULL; LPCSTR char_class = pXML->Read ("class", 0, NULL); if(char_class) { char* buf_str = xr_strdup(char_class); xr_strlwr(buf_str); data()->m_Class = buf_str; xr_free(buf_str); } else data()->m_Class = NO_CHARACTER_CLASS; data()->m_Rank = pXML->ReadInt ("rank", 0, NO_RANK); data()->m_Reputation = pXML->ReadInt ("reputation", 0, NO_REPUTATION); } else data()->m_CharacterId = spec_char; }
//------------------------------------------------------------------------------ // возвращает список не синхронизированных (модифицированных) текстур // source_list - содержит список текстур с расширениями // sync_list - реально сохраненные файлы (после использования освободить) //------------------------------------------------------------------------------ void CSoundManager::SynchronizeSounds(bool sync_thm, bool sync_game, bool bForceGame, FS_FileSet* source_list, AStringVec* sync_list, FS_FileSet* modif_map) { FS_FileSet M_BASE; FS_FileSet M_THUM; FS_FileSet M_GAME; if (source_list) M_BASE = *source_list; else FS.file_list(M_BASE,_sounds_,FS_ListFiles|FS_ClampExt,"*.wav"); if (M_BASE.empty()) return; if (sync_thm) FS.file_list(M_THUM,_sounds_,FS_ListFiles|FS_ClampExt,"*.thm"); if (sync_game) FS.file_list(M_GAME,_game_sounds_,FS_ListFiles|FS_ClampExt,"*.ogg"); bool bProgress = M_BASE.size()>1; int m_age = time(NULL); SPBItem* pb = 0; if (bProgress) pb = UI->ProgressStart(M_BASE.size(),"Synchronize sounds..."); FS_FileSetIt it=M_BASE.begin(); FS_FileSetIt _E = M_BASE.end(); for (; it!=_E; it++){ BOOL bUpdated = FALSE; xr_string base_name = EFS.ChangeFileExt(it->name,""); xr_strlwr(base_name); string_path fn; FS.update_path (fn,_sounds_,EFS.ChangeFileExt(base_name,".wav").c_str()); if (!FS.exist(fn)) continue; FS_FileSetIt th = M_THUM.find(base_name); bool bThm = ((th==M_THUM.end()) || ((th!=M_THUM.end())&&(th->time_write!=it->time_write))); FS_FileSetIt gm = M_GAME.find(base_name); bool bGame = bThm || ((gm==M_GAME.end()) || ((gm!=M_GAME.end())&&(gm->time_write!=it->time_write))); ESoundThumbnail* THM = 0; // backup base sound // check thumbnail if (sync_thm&&bThm){ THM = xr_new<ESoundThumbnail>(it->name.c_str()); THM->Save (m_age); bUpdated = TRUE; } // check game sounds if (bForceGame||(sync_game&&bGame)){ if (!THM) THM = xr_new<ESoundThumbnail>(it->name.c_str()); R_ASSERT(THM); string_path src_name; strconcat (sizeof(src_name),src_name, base_name.c_str(), ".wav"); FS.update_path (src_name,_sounds_,src_name); string_path game_name; strconcat (sizeof(game_name),game_name, base_name.c_str(), ".ogg"); FS.update_path (game_name,_game_sounds_,game_name); MakeGameSound (THM,src_name,game_name); if (sync_list) sync_list->push_back(base_name.c_str()); if (modif_map) modif_map->insert(*it); bUpdated = TRUE; } if (THM) xr_delete(THM); if (UI->NeedAbort()) break; if (bProgress) pb->Inc (bUpdated?xr_string(base_name+" - UPDATED.").c_str():"",bUpdated); if (bUpdated){ string_path wav_fn,thm_fn,ogg_fn; FS.update_path (wav_fn,_sounds_, EFS.ChangeFileExt(base_name,".wav").c_str()); FS.update_path (thm_fn,_sounds_, EFS.ChangeFileExt(base_name,".thm").c_str()); FS.update_path (ogg_fn,_game_sounds_, EFS.ChangeFileExt(base_name,".ogg").c_str()); FS.set_file_age (wav_fn,m_age); FS.set_file_age (thm_fn,m_age); FS.set_file_age (ogg_fn,m_age); } } if (bProgress) UI->ProgressEnd(pb); }
bool CSMotion::Load(IReader& F) { CCustomMotion::Load(F); u16 vers = F.r_u16(); if (vers==0x0004){ m_BoneOrPart= u16(F.r_u32()&0xffff); m_Flags.set (esmFX,F.r_u8()); m_Flags.set (esmStopAtEnd,F.r_u8()); fSpeed = F.r_float(); fAccrue = F.r_float(); fFalloff = F.r_float(); fPower = F.r_float(); bone_mots.resize(F.r_u32()); string64 temp_buf; for(BoneMotionIt bm_it=bone_mots.begin(); bm_it!=bone_mots.end(); bm_it++){ bm_it->SetName (itoa(int(bm_it-bone_mots.begin()),temp_buf,10)); bm_it->m_Flags.assign((u8)F.r_u32()); for (int ch=0; ch<ctMaxChannel; ch++){ bm_it->envs[ch] = xr_new<CEnvelope> (); bm_it->envs[ch]->Load_1(F); } } }else{ if (vers==0x0005){ m_Flags.assign ((u8)F.r_u32()); m_BoneOrPart= u16(F.r_u32()&0xffff); fSpeed = F.r_float(); fAccrue = F.r_float(); fFalloff = F.r_float(); fPower = F.r_float(); bone_mots.resize(F.r_u32()); string64 buf; for(BoneMotionIt bm_it=bone_mots.begin(); bm_it!=bone_mots.end(); bm_it++){ F.r_stringZ (buf,sizeof(buf)); bm_it->SetName (buf); bm_it->m_Flags.assign((u8)F.r_u32()); for (int ch=0; ch<ctMaxChannel; ch++){ bm_it->envs[ch] = xr_new<CEnvelope> (); bm_it->envs[ch]->Load_1(F); } } }else{ if (vers!=EOBJ_SMOTION_VERSION) return false; m_Flags.assign (F.r_u8()); m_BoneOrPart= F.r_u16(); fSpeed = F.r_float(); fAccrue = F.r_float(); fFalloff = F.r_float(); fPower = F.r_float(); bone_mots.resize(F.r_u16()); string64 buf; for(BoneMotionIt bm_it=bone_mots.begin(); bm_it!=bone_mots.end(); bm_it++){ F.r_stringZ (buf,sizeof(buf)); bm_it->SetName (buf); bm_it->m_Flags.assign(F.r_u8()); for (int ch=0; ch<ctMaxChannel; ch++){ bm_it->envs[ch] = xr_new<CEnvelope> (); bm_it->envs[ch]->Load_2(F); } } } } for(BoneMotionIt bm_it=bone_mots.begin(); bm_it!=bone_mots.end(); bm_it++) xr_strlwr (bm_it->name); return true; }
//----------------------------------------------------------------------- BOOL motions_value::load (LPCSTR N, IReader *data, vecBones* bones) { m_id = N; bool bRes = true; // Load definitions U16Vec rm_bones (bones->size(),BI_NONE); IReader* MP = data->open_chunk(OGF_S_SMPARAMS); if (MP) { u16 vers = MP->r_u16(); u16 part_bone_cnt = 0; string128 buf; R_ASSERT3 (vers<=xrOGF_SMParamsVersion,"Invalid OGF/OMF version:",N); // partitions u16 part_count; part_count = MP->r_u16(); for (u16 part_i=0; part_i<part_count; part_i++) { CPartDef& PART = m_partition[part_i]; MP->r_stringZ (buf,sizeof(buf)); PART.Name = _strlwr(buf); PART.bones.resize (MP->r_u16()); for (xr_vector<u32>::iterator b_it=PART.bones.begin(); b_it<PART.bones.end(); b_it++) { MP->r_stringZ (buf,sizeof(buf)); u16 m_idx = u16 (MP->r_u32()); *b_it = find_bone_id (bones,buf); #ifdef _EDITOR if (*b_it==BI_NONE ) { bRes = false; Msg ("! Can't find bone: '%s'", buf); } if (rm_bones.size() <= m_idx) { bRes = false; Msg ("! Can't load: '%s' invalid bones count", N); } #else VERIFY3 (*b_it!=BI_NONE,"Can't find bone:", buf); #endif if (bRes) rm_bones[m_idx] = u16(*b_it); } part_bone_cnt = u16(part_bone_cnt + (u16)PART.bones.size()); } #ifdef _EDITOR if (part_bone_cnt!=(u16)bones->size()){ bRes = false; Msg("! Different bone count[%s] [Object: '%d' <-> Motions: '%d']", N, bones->size(),part_bone_cnt); } #else VERIFY3(part_bone_cnt==(u16)bones->size(),"Different bone count '%s'",N); #endif if (bRes) { // motion defs (cycle&fx) u16 mot_count = MP->r_u16(); m_mdefs.resize (mot_count); for (u16 mot_i=0; mot_i<mot_count; mot_i++) { MP->r_stringZ (buf,sizeof(buf)); shared_str nm = _strlwr (buf); u32 dwFlags = MP->r_u32 (); CMotionDef& D = m_mdefs[mot_i]; D.Load (MP,dwFlags,vers); //. m_mdefs.push_back (D); if (dwFlags&esmFX) m_fx.insert (mk_pair(nm,mot_i)); else m_cycle.insert (mk_pair(nm,mot_i)); m_motion_map.insert (mk_pair(nm,mot_i)); } } MP->close(); }else { xrDebug::Fatal (DEBUG_INFO,"Old skinned model version unsupported! (%s)",N); } if (!bRes) return false; // Load animation IReader* MS = data->open_chunk(OGF_S_MOTIONS); if (!MS) return false; u32 dwCNT = 0; MS->r_chunk_safe (0,&dwCNT,sizeof(dwCNT)); VERIFY (dwCNT<0x3FFF); // MotionID 2 bit - slot, 14 bit - motion index // set per bone motion size for (u32 i=0; i<bones->size(); i++) m_motions[bones->at(i)->name].resize(dwCNT); // load motions for (u16 m_idx=0; m_idx<(u16)dwCNT; m_idx++){ string128 mname; R_ASSERT (MS->find_chunk(m_idx+1)); MS->r_stringZ (mname,sizeof(mname)); #ifdef _DEBUG // sanity check xr_strlwr (mname); accel_map::iterator I= m_motion_map.find(mname); VERIFY3 (I!=m_motion_map.end(),"Can't find motion:",mname); VERIFY3 (I->second==m_idx,"Invalid motion index:",mname); #endif u32 dwLen = MS->r_u32(); for (u32 i=0; i<bones->size(); i++){ u16 bone_id = rm_bones[i]; VERIFY2 (bone_id!=BI_NONE,"Invalid remap index."); CMotion& M = m_motions[bones->at(bone_id)->name][m_idx]; M.set_count (dwLen); M.set_flags (MS->r_u8()); if (M.test_flag(flRKeyAbsent)) { CKeyQR* r = (CKeyQR*)MS->pointer(); u32 crc_q = crc32(r,sizeof(CKeyQR)); M._keysR.create (crc_q,1,r); MS->advance (1 * sizeof(CKeyQR)); }else{ u32 crc_q = MS->r_u32 (); M._keysR.create (crc_q,dwLen,(CKeyQR*)MS->pointer()); MS->advance (dwLen * sizeof(CKeyQR)); } if (M.test_flag(flTKeyPresent)) { u32 crc_t = MS->r_u32 (); if(M.test_flag(flTKey16IsBit)) { M._keysT16.create (crc_t,dwLen,(CKeyQT16*)MS->pointer()); MS->advance (dwLen * sizeof(CKeyQT16)); }else { M._keysT8.create (crc_t,dwLen,(CKeyQT8*)MS->pointer()); MS->advance (dwLen * sizeof(CKeyQT8)); }; MS->r_fvector3 (M._sizeT); MS->r_fvector3 (M._initT); }else { MS->r_fvector3 (M._initT); } } } // Msg("Motions %d/%d %4d/%4d/%d, %s",p_cnt,m_cnt, m_load,m_total,m_r,N); MS->close(); return bRes; }
void xrLoad(LPCSTR name, bool draft_mode) { FS.get_path ("$level$")->_set ((LPSTR)name); string256 N; if (!draft_mode) { // shaders string_path N; FS.update_path (N,"$game_data$","shaders_xrlc.xr"); g_shaders_xrlc = xr_new<Shader_xrLC_LIB> (); g_shaders_xrlc->Load (N); // Load CFORM { strconcat (sizeof(N),N,name,"build.cform"); IReader* fs = FS.r_open(N); R_ASSERT (fs->find_chunk(0)); hdrCFORM H; fs->r (&H,sizeof(hdrCFORM)); R_ASSERT (CFORM_CURRENT_VERSION==H.version); Fvector* verts = (Fvector*)fs->pointer(); CDB::TRI* tris = (CDB::TRI*)(verts+H.vertcount); Level.build ( verts, H.vertcount, tris, H.facecount ); Level.syncronize (); Msg("* Level CFORM: %dK",Level.memory()/1024); g_rc_faces.resize (H.facecount); R_ASSERT(fs->find_chunk(1)); fs->r (&*g_rc_faces.begin(),g_rc_faces.size()*sizeof(b_rc_face)); LevelBB.set (H.aabb); FS.r_close (fs); } // Load level data { strconcat (sizeof(N),N,name,"build.prj"); IReader* fs = FS.r_open (N); IReader* F; // Version u32 version; fs->r_chunk (EB_Version,&version); R_ASSERT (XRCL_CURRENT_VERSION >= 17); R_ASSERT (XRCL_CURRENT_VERSION <= 18); // Header b_params Params; fs->r_chunk (EB_Parameters,&Params); // Load level data transfer("materials", g_materials, *fs, EB_Materials); transfer("shaders_xrlc",g_shader_compile, *fs, EB_Shaders_Compile); // process textures Status ("Processing textures..."); { Surface_Init (); F = fs->open_chunk (EB_Textures); u32 tex_count = F->length()/sizeof(b_texture); for (u32 t=0; t<tex_count; t++) { Progress (float(t)/float(tex_count)); b_texture TEX; F->r (&TEX,sizeof(TEX)); b_BuildTexture BT; CopyMemory (&BT,&TEX,sizeof(TEX)); // load thumbnail string128 &N = BT.name; LPSTR extension = strext(N); if (extension) *extension = 0; xr_strlwr (N); if (0==xr_strcmp(N,"level_lods")) { // HACK for merged lod textures BT.dwWidth = 1024; BT.dwHeight = 1024; BT.bHasAlpha= TRUE; BT.pSurface = 0; } else { xr_strcat (N,".thm"); IReader* THM = FS.r_open("$game_textures$",N); // if (!THM) continue; R_ASSERT2 (THM, N); // version u32 version = 0; R_ASSERT (THM->r_chunk(THM_CHUNK_VERSION,&version)); // if( version!=THM_CURRENT_VERSION ) FATAL ("Unsupported version of THM file."); // analyze thumbnail information R_ASSERT(THM->find_chunk(THM_CHUNK_TEXTUREPARAM)); THM->r (&BT.THM.fmt,sizeof(STextureParams::ETFormat)); BT.THM.flags.assign (THM->r_u32()); BT.THM.border_color = THM->r_u32(); BT.THM.fade_color = THM->r_u32(); BT.THM.fade_amount = THM->r_u32(); BT.THM.mip_filter = THM->r_u32(); BT.THM.width = THM->r_u32(); BT.THM.height = THM->r_u32(); BOOL bLOD=FALSE; if (N[0]=='l' && N[1]=='o' && N[2]=='d' && N[3]=='\\') bLOD = TRUE; // load surface if it has an alpha channel or has "implicit lighting" flag BT.dwWidth = BT.THM.width; BT.dwHeight = BT.THM.height; BT.bHasAlpha = BT.THM.HasAlphaChannel(); BT.pSurface = 0; if (!bLOD) { if (BT.bHasAlpha || BT.THM.flags.test(STextureParams::flImplicitLighted)) { clMsg ("- loading: %s",N); u32 w=0, h=0; BT.pSurface = Surface_Load(N,w,h); R_ASSERT2 (BT.pSurface,"Can't load surface"); if ((w != BT.dwWidth) || (h != BT.dwHeight)) Msg ("! THM doesn't correspond to the texture: %dx%d -> %dx%d", BT.dwWidth, BT.dwHeight, w, h); BT.Vflip (); } else { // Free surface memory } } } // save all the stuff we've created g_textures.push_back (BT); } } } } // // Load emitters // { // strconcat (N,name,"level.game"); // IReader *F = FS.r_open(N); // IReader *O = 0; // if (0!=(O = F->open_chunk (AIPOINT_CHUNK))) { // for (int id=0; O->find_chunk(id); id++) { // Emitters.push_back(Fvector()); // O->r_fvector3 (Emitters.back()); // } // O->close(); // } // } // // Load lights { strconcat (sizeof(N),N,name,"build.prj"); IReader* F = FS.r_open(N); R_ASSERT2 (F,"There is no file 'build.prj'!"); IReader &fs= *F; // Version u32 version; fs.r_chunk (EB_Version,&version); R_ASSERT (XRCL_CURRENT_VERSION >= 17); R_ASSERT (XRCL_CURRENT_VERSION <= 18); // Header b_params Params; fs.r_chunk (EB_Parameters,&Params); // Lights (Static) { F = fs.open_chunk(EB_Light_static); b_light_static temp; u32 cnt = F->length()/sizeof(temp); for (u32 i=0; i<cnt; i++) { R_Light RL; F->r (&temp,sizeof(temp)); Flight& L = temp.data; if (_abs(L.range) > 10000.f) { Msg ("! BAD light range : %f",L.range); L.range = L.range > 0.f ? 10000.f : -10000.f; } // type if (L.type == D3DLIGHT_DIRECTIONAL) RL.type = LT_DIRECT; else RL.type = LT_POINT; // generic properties RL.position.set (L.position); RL.direction.normalize_safe (L.direction); RL.range = L.range*1.1f; RL.range2 = RL.range*RL.range; RL.attenuation0 = L.attenuation0; RL.attenuation1 = L.attenuation1; RL.attenuation2 = L.attenuation2; RL.amount = L.diffuse.magnitude_rgb (); RL.tri[0].set (0,0,0); RL.tri[1].set (0,0,0); RL.tri[2].set (0,0,0); // place into layer if (0==temp.controller_ID) g_lights.push_back (RL); } F->close (); } } // Init params // g_params.Init (); // Load initial map from the Level Editor { string_path file_name; strconcat (sizeof(file_name),file_name,name,"build.aimap"); IReader *F = FS.r_open(file_name); R_ASSERT2 (F, file_name); R_ASSERT (F->open_chunk(E_AIMAP_CHUNK_VERSION)); R_ASSERT (F->r_u16() == E_AIMAP_VERSION); R_ASSERT (F->open_chunk(E_AIMAP_CHUNK_BOX)); F->r (&LevelBB,sizeof(LevelBB)); R_ASSERT (F->open_chunk(E_AIMAP_CHUNK_PARAMS)); F->r (&g_params,sizeof(g_params)); R_ASSERT (F->open_chunk(E_AIMAP_CHUNK_NODES)); u32 N = F->r_u32(); R_ASSERT2 (N < ((u32(1) << u32(MAX_NODE_BIT_COUNT)) - 2),"Too many nodes!"); g_nodes.resize (N); hdrNODES H; H.version = XRAI_CURRENT_VERSION; H.count = N+1; H.size = g_params.fPatchSize; H.size_y = 1.f; H.aabb = LevelBB; typedef BYTE NodeLink[3]; for (u32 i=0; i<N; i++) { NodeLink id; u16 pl; SNodePositionOld _np; NodePosition np; for (int j=0; j<4; ++j) { F->r (&id,3); g_nodes[i].n[j] = (*LPDWORD(&id)) & 0x00ffffff; } pl = F->r_u16(); pvDecompress (g_nodes[i].Plane.n,pl); F->r (&_np,sizeof(_np)); CNodePositionConverter(_np,H,np); g_nodes[i].Pos = vertex_position(np,LevelBB,g_params); g_nodes[i].Plane.build(g_nodes[i].Pos,g_nodes[i].Plane.n); } F->close (); if (!strstr(Core.Params,"-keep_temp_files")) DeleteFile (file_name); } }