bool CGroupObject::Load(IReader& F) { u32 version = 0; char buf[1024]; R_ASSERT(F.r_chunk(GROUPOBJ_CHUNK_VERSION,&version)); if (version!=GROUPOBJ_CURRENT_VERSION){ ELog.DlgMsg( mtError, "CGroupObject: unsupported file version. Object can't load."); return false; } CCustomObject::Load(F); F.r_chunk(GROUPOBJ_CHUNK_FLAGS,&m_Flags); // objects if (IsOpened()){ m_PObjects = xr_new<SStringVec>(); R_ASSERT(F.find_chunk(GROUPOBJ_CHUNK_OPEN_OBJECT_LIST)); u32 cnt = F.r_u32(); xr_string tmp; for (u32 k=0; k<cnt; k++){ F.r_stringZ (tmp); m_PObjects->push_back (tmp); } }else{ Scene->ReadObjects(F,GROUPOBJ_CHUNK_OBJECT_LIST,AppendObjectCB,0); } VERIFY(m_Objects.size()||(0!=m_PObjects)); if (F.find_chunk(GROUPOBJ_CHUNK_REFERENCE)) F.r_stringZ (m_ReferenceName); return true; }
bool CGroupObject::LoadStream(IReader& F) { u16 version=0; R_ASSERT(F.r_chunk(GROUPOBJ_CHUNK_VERSION,&version)); if (version<0x0011) { ELog.DlgMsg( mtError, "CGroupObject: unsupported file version. Object can't load."); return false; } CCustomObject::LoadStream(F); Flags32 tmp_flags; tmp_flags.zero(); if(version<0x0012) F.r_chunk(GROUPOBJ_CHUNK_FLAGS,&tmp_flags); // objects if (tmp_flags.test(1<<0)) { //old format, opened group ELog.DlgMsg( mtError, "old format, opened group"); return false; /* R_ASSERT(F.find_chunk(GROUPOBJ_CHUNK_OPEN_OBJECT_LIST)); u32 cnt = F.r_u32(); for (u32 k=0; k<cnt; ++k) { m_ObjectsInGroup.resize (m_ObjectsInGroup.size()+1); F.r_stringZ (m_ObjectsInGroup.back().ObjectName); } */ }else { Scene->ReadObjectsStream(F,GROUPOBJ_CHUNK_OBJECT_LIST,AppendObjectLoadCB,0); } VERIFY(m_ObjectsInGroup.size()); if (F.find_chunk(GROUPOBJ_CHUNK_REFERENCE)) { shared_str rn; F.r_stringZ (rn); SetRefName(rn.c_str()); } if(version<0x0012) { for (ObjectsInGroup::iterator it=m_ObjectsInGroup.begin(); it!=m_ObjectsInGroup.end(); ++it) if(it->pObject) { it->pObject->m_CO_Flags.set(flObjectInGroup, TRUE); it->pObject->m_CO_Flags.set(flObjectInGroupUnique, TRUE); } } return true; }
bool ESceneLightTools::Load(IReader& F) { u16 version = 0; if(F.r_chunk(CHUNK_VERSION,&version)) if( version!=LIGHT_TOOLS_VERSION ){ ELog.DlgMsg( mtError, "%s tools: Unsupported version.",ClassDesc()); return false; } if (!inherited::Load(F)) return false; if (F.find_chunk(CHUNK_FLAGS)) m_Flags.assign (F.r_u32()); if (F.find_chunk(CHUNK_SUN_SHADOW)){ F.r_u8 (); F.r_fvector2 (m_SunShadowDir); } if (F.find_chunk(CHUNK_LCONTROLS_LAST)) lcontrol_last_idx = F.r_u32(); IReader* R = F.open_chunk(CHUNK_LCONTROLS); if (R){ while (!R->eof()){ shared_str l_name; R->r_stringZ(l_name); u32 l_idx = R->r_u32(); AppendLightControl(l_name.c_str(),&l_idx); } R->close (); } return true; }
bool CGlow::Load(IReader& F) { u32 version = 0; R_ASSERT(F.r_chunk(GLOW_CHUNK_VERSION,&version)); if((version!=0x0011)&&(version!=GLOW_VERSION)){ ELog.DlgMsg( mtError, "CGlow: Unsupported version."); return false; } CCustomObject::Load(F); if (F.find_chunk(GLOW_CHUNK_SHADER)){ F.r_stringZ (m_ShaderName); } R_ASSERT(F.find_chunk(GLOW_CHUNK_TEXTURE)); F.r_stringZ (m_TexName); R_ASSERT(F.find_chunk(GLOW_CHUNK_PARAMS)); m_fRadius = F.r_float(); if (version==0x0011){ F.r_fvector3 (FPosition); UpdateTransform(); } if (F.find_chunk(GLOW_CHUNK_FLAGS)) m_Flags.assign (F.r_u16()); return true; }
void recalculation::check_files( u32 check_sum ) { string_path N,L; FS.update_path ( L, "$level$", "level.details" ); FS.update_path ( N, "$level$", "recalculation_data_slots.details" ); if( ! FS.exist( L ) ) { FS.file_delete( N ); return; } IReader* R = FS.r_open ( "$level$", "recalculation_data_slots.details" ); if( R ) { u32 check; R->r_chunk( 0, &check ); if( check != check_sum ) FS.file_delete( N ); else recalculate = true; FS.r_close( R ) ; } }
bool ESceneObjectTools::Load(IReader& F) { u16 version = 0; if(F.r_chunk(CHUNK_VERSION,&version)){ if( version!=OBJECT_TOOLS_VERSION ){ ELog.DlgMsg( mtError, "%s tools: Unsupported version.",ClassDesc()); return false; } } if (!inherited::Load(F)) return false; if (F.find_chunk(CHUNK_FLAGS)) m_Flags.assign(F.r_u32()); if (F.find_chunk(CHUNK_APPEND_RANDOM)){ F.r_fvector3(m_AppendRandomMinScale); F.r_fvector3(m_AppendRandomMaxScale); F.r_fvector3(m_AppendRandomMinRotation); F.r_fvector3(m_AppendRandomMaxRotation); int cnt = F.r_u32(); if (cnt){ shared_str buf; for (int i=0; i<cnt; i++){ F.r_stringZ (buf); m_AppendRandomObjects.push_back (buf); } } }; m_Flags.set(flAppendRandom,FALSE); return true; }
void global_slots_data:: Load ( ) { // Load .details // copy //if() IReader* R = FS.r_open ( "$level$", "build.details" ); R->r_chunk ( 0, &dtH ); R->seek ( 0 ); u32 check_sum = crc32( R-> pointer(), R->length()); recalculation_data.load( check_sum ); if( !recalculation_data.recalculating() ) { IWriter* W = FS.w_open ( "$level$", "level.details" ); W->w ( R->pointer(), R->length() ); FS.w_close ( W ); } FS.r_close ( R ); // re-open string_path N; FS.update_path ( N, "$level$", "level.details" ); dtFS = xr_new<CVirtualFileRW> ( N ); R_ASSERT ( dtH.version()==DETAIL_VERSION ); dtFS->find_chunk ( 2 ); dtS = (DetailSlot*)dtFS->pointer(); }
bool EParticlesObject::Load(IReader& F) { u32 version = 0; R_ASSERT(F.r_chunk(CPSOBJECT_CHUNK_VERSION,&version)); if( version!=CPSOBJECT_VERSION ){ ELog.DlgMsg( mtError, "PSObject: Unsupported version."); return false; } inherited::Load(F); R_ASSERT(F.find_chunk(CPSOBJECT_CHUNK_REFERENCE)); F.r_stringZ(m_RefName); if (!Compile(*m_RefName)){ ELog.DlgMsg( mtError, "EParticlesObject: '%s' not found in library", *m_RefName ); return false; } if (F.find_chunk(CPSOBJECT_CHUNK_PARAMS)){ //. if (m_Particles) m_Particles->m_RT_Flags.set(F.r_u32()); } return true; }
bool ESceneAIMapTool::LoadStream(IReader& F) { inherited::LoadStream (F); u16 version = 0; R_ASSERT(F.r_chunk(AIMAP_CHUNK_VERSION,&version)); if( version!=AIMAP_VERSION ){ ELog.DlgMsg( mtError, "AIMap: Unsupported version."); return false; } R_ASSERT(F.find_chunk(AIMAP_CHUNK_FLAGS)); F.r (&m_Flags,sizeof(m_Flags)); R_ASSERT(F.find_chunk(AIMAP_CHUNK_BOX)); F.r (&m_AIBBox,sizeof(m_AIBBox)); R_ASSERT(F.find_chunk(AIMAP_CHUNK_PARAMS)); F.r (&m_Params,sizeof(m_Params)); R_ASSERT(F.find_chunk(AIMAP_CHUNK_NODES)); m_Nodes.resize (F.r_u32()); for (AINodeIt it=m_Nodes.begin(); it!=m_Nodes.end(); it++){ *it = xr_new<SAINode>(); (*it)->LoadStream (F,this); } DenumerateNodes (); if (F.find_chunk(AIMAP_CHUNK_INTERNAL_DATA)){ m_VisRadius = F.r_float(); m_BrushSize = F.r_u32(); } if (F.find_chunk(AIMAP_CHUNK_INTERNAL_DATA2)){ m_SmoothHeight = F.r_float(); } // snap objects if (F.find_chunk(AIMAP_CHUNK_SNAP_OBJECTS)){ shared_str buf; int cnt = F.r_u32(); if (cnt){ for (int i=0; i<cnt; i++){ F.r_stringZ (buf); CCustomObject* O = Scene->FindObjectByName(buf.c_str(),OBJCLASS_SCENEOBJECT); if (!O) ELog.Msg(mtError,"AIMap: Can't find snap object '%s'.",buf.c_str()); else m_SnapObjects.push_back(O); } } } hash_FillFromNodes (); return true; }
//------------------------------------------------------------------------------ // I/O part //------------------------------------------------------------------------------ BOOL CPGDef::Load(IReader& F) { R_ASSERT (F.find_chunk(PGD_CHUNK_VERSION)); u16 version = F.r_u16(); if (version!=PGD_VERSION){ Log ("!Unsupported PG version. Load failed."); return FALSE; } R_ASSERT (F.find_chunk(PGD_CHUNK_NAME)); F.r_stringZ (m_Name); F.r_chunk (PGD_CHUNK_FLAGS,&m_Flags); if (F.find_chunk(PGD_CHUNK_EFFECTS)){ m_Effects.resize(F.r_u32()); for (EffectIt it=m_Effects.begin(); it!=m_Effects.end(); it++){ *it = xr_new<SEffect>(); F.r_stringZ ((*it)->m_EffectName); F.r_stringZ ((*it)->m_OnPlayChildName); F.r_stringZ ((*it)->m_OnBirthChildName); F.r_stringZ ((*it)->m_OnDeadChildName); (*it)->m_Time0 = F.r_float(); (*it)->m_Time1 = F.r_float(); (*it)->m_Flags.assign (F.r_u32()); } }else{ //.??? убрать через некоторое время R_ASSERT (F.find_chunk(PGD_CHUNK_EFFECTS2)); m_Effects.resize(F.r_u32()); for (EffectIt it=m_Effects.begin(); it!=m_Effects.end(); it++){ *it = xr_new<SEffect>(); F.r_stringZ ((*it)->m_EffectName); F.r_stringZ ((*it)->m_OnPlayChildName); (*it)->m_Time0 = F.r_float(); (*it)->m_Time1 = F.r_float(); (*it)->m_Flags.assign (F.r_u32()); } } if (F.find_chunk(PGD_CHUNK_TIME_LIMIT)){ m_fTimeLimit= F.r_float(); } #ifdef _EDITOR if (F.find_chunk(PGD_CHUNK_OWNER)){ F.r_stringZ (m_OwnerName); F.r_stringZ (m_ModifName); F.r (&m_CreateTime,sizeof(m_CreateTime)); F.r (&m_ModifTime,sizeof(m_ModifTime)); } #endif return TRUE; }
bool ESceneLightTools::LoadSelection(IReader& F) { u16 version = 0; R_ASSERT(F.r_chunk(CHUNK_VERSION,&version)); if( version!=LIGHT_TOOLS_VERSION ){ ELog.DlgMsg( mtError, "%s tools: Unsupported version.",ClassDesc()); return false; } return inherited::LoadSelection(F); }
bool ESceneCustomOTools::LoadSelection(IReader& F) { int count = 0; F.r_chunk (CHUNK_OBJECT_COUNT,&count); SPBItem* pb = UI->ProgressStart(count,AnsiString().sprintf("Loading %s's...",ClassDesc()).c_str()); Scene->ReadObjects(F,CHUNK_OBJECTS,OnLoadSelectionAppendObject,pb); UI->ProgressEnd(pb); return true; }
bool EScenePSTools::Load(IReader& F) { u16 version = 0; if(F.r_chunk(CHUNK_VERSION,&version)) if( version!=PS_TOOLS_VERSION ){ ELog.DlgMsg( mtError, "%s tools: Unsupported version.",ClassDesc()); return false; } if (!inherited::Load(F)) return false; return true; }
bool EScene::LoadSelection( LPCSTR fname ) { u32 version = 0; VERIFY( fname ); xr_string full_name; full_name = fname; ELog.Msg( mtInformation, "EScene: loading part %s...", fname ); bool res = true; if (FS.exist(full_name.c_str())){ SelectObjects( false ); IReader* F = FS.r_open(full_name.c_str()); // Version R_ASSERT(F->r_chunk(CHUNK_VERSION, &version)); if (version!=CURRENT_FILE_VERSION){ ELog.DlgMsg( mtError, "EScene: unsupported file version. Can't load Level."); UI->UpdateScene(); FS.r_close(F); return false; } // Objects if (!ReadObjectsStream(*F,CHUNK_OBJECT_LIST,OnLoadSelectionAppendObject,0)) { ELog.DlgMsg(mtError,"EScene. Failed to load selection."); res = false; } SceneToolsMapPairIt _I = m_SceneTools.begin(); SceneToolsMapPairIt _E = m_SceneTools.end(); for (; _I!=_E; _I++) if (_I->second&&_I->second->IsEnabled()&&_I->second->IsEditable()){ IReader* chunk = F->open_chunk(CHUNK_TOOLS_DATA+_I->first); if (chunk){ _I->second->LoadSelection(*chunk); chunk->close (); } } // Synchronize SynchronizeObjects(); FS.r_close(F); } return res; }
bool ESceneSpawnTool::LoadStream(IReader& F) { u16 version = 0; if(F.r_chunk(CHUNK_VERSION,&version)) if( version!=SPAWN_TOOLS_VERSION ){ ELog.DlgMsg( mtError, "%s tools: Unsupported version.",ClassDesc()); return false; } if (!inherited::LoadStream(F)) return false; if (F.find_chunk(CHUNK_FLAGS)) m_Flags.assign (F.r_u32()); return true; }
bool ESoundEnvironment::LoadStream(IReader& F) { u16 version = 0; R_ASSERT(F.r_chunk(SOUND_CHUNK_VERSION,&version)); if(version!=SOUND_ENV_VERSION){ ELog.DlgMsg( mtError, "ESoundSource: Unsupported version."); return false; } inherited::LoadStream (F); R_ASSERT(F.find_chunk(SOUND_CHUNK_ENV_REFS)); F.r_stringZ (m_EnvInner); F.r_stringZ (m_EnvOuter); return true; }
bool ETextureThumbnail::Load(LPCSTR src_name, LPCSTR path) { string_path fn; strcpy(fn,EFS.ChangeFileExt(src_name?src_name:m_Name.c_str(),".thm").c_str() ); if (path) FS.update_path(fn,path,fn); else { FS.update_path (fn,_game_textures_,fn); } if (!FS.exist(fn)) return false; IReader* F = FS.r_open(fn); u16 version = 0; R_ASSERT(F->r_chunk(THM_CHUNK_VERSION,&version)); if( version!=THM_TEXTURE_VERSION ){ Msg ("!Thumbnail: Unsupported version."); return false; } /* IReader* D = F->open_chunk(THM_CHUNK_DATA); R_ASSERT(D); m_Pixels.resize (THUMB_SIZE); D->r (m_Pixels.begin(),THUMB_SIZE*sizeof(u32)); D->close (); */ R_ASSERT (F->find_chunk(THM_CHUNK_TYPE)); m_Type = THMType(F->r_u32()); R_ASSERT (m_Type==ETTexture); m_TexParams.Load(*F); m_Age = FS.get_file_age(fn); FS.r_close (F); SetValid (); return true; }
bool EScene::Load(LPCSTR map_name, bool bUndo) { u32 version = 0; if (!map_name||(0==map_name[0])) return false; xr_string full_name; full_name = map_name; ELog.Msg( mtInformation, "EScene: loading '%s'", map_name); if (FS.exist(full_name.c_str())) { CTimer T; T.Start(); // read main level IReader* F = FS.r_open(full_name.c_str()); VERIFY(F); // Version R_ASSERT (F->r_chunk(CHUNK_VERSION, &version)); if (version!=CURRENT_FILE_VERSION) { ELog.DlgMsg( mtError, "EScene: unsupported file version. Can't load Level."); UI->UpdateScene(); FS.r_close(F); return false; } // Lev. ops. IReader* LOP = F->open_chunk(CHUNK_LEVELOP); if (LOP) { m_LevelOp.Read (*LOP); LOP->close (); }else { ELog.DlgMsg (mtError, "Skipping old version of level options.\nCheck level options after loading."); } // if (F->find_chunk(CHUNK_CAMERA)) { Fvector hpb, pos; F->r_fvector3 (hpb); F->r_fvector3 (pos); EDevice.m_Camera.Set(hpb,pos); EDevice.m_Camera.SetStyle(EDevice.m_Camera.GetStyle()); } if (F->find_chunk(CHUNK_TOOLS_GUID)) { F->r (&m_GUID,sizeof(m_GUID)); } if (F->find_chunk(CHUNK_LEVEL_TAG)) { F->r_stringZ (m_OwnerName); F->r (&m_CreateTime,sizeof(m_CreateTime)); }else { m_OwnerName = ""; m_CreateTime = 0; } DWORD obj_cnt = 0; if (F->find_chunk(CHUNK_OBJECT_COUNT)) obj_cnt = F->r_u32(); SPBItem* pb = UI->ProgressStart(obj_cnt,"Loading objects..."); ReadObjectsStream (*F,CHUNK_OBJECT_LIST,OnLoadAppendObject,pb); UI->ProgressEnd (pb); SceneToolsMapPairIt _I = m_SceneTools.begin(); SceneToolsMapPairIt _E = m_SceneTools.end(); for (; _I!=_E; ++_I) { if (_I->second) { IReader* chunk = F->open_chunk(CHUNK_TOOLS_DATA+_I->first); if (chunk){ _I->second->LoadStream(*chunk); chunk->close (); }else{ if (!bUndo && _I->second->IsEnabled() && (_I->first!=OBJCLASS_DUMMY)) { LoadLevelPart (_I->second,LevelPartName(map_name,_I->first).c_str()); } } } } // snap list if (F->find_chunk(CHUNK_SNAPOBJECTS)) { shared_str buf; int cnt = F->r_u32(); if (cnt) { for (int i=0; i<cnt; ++i) { F->r_stringZ (buf); CCustomObject* O = FindObjectByName(buf.c_str(),OBJCLASS_SCENEOBJECT); if (!O) ELog.Msg(mtError,"EScene: Can't find snap object '%s'.",buf.c_str()); else m_ESO_SnapObjects.push_back(O); } } UpdateSnapList(); } Msg("EScene: %d objects loaded, %3.2f sec", ObjCount(), T.GetElapsed_sec() ); UI->UpdateScene(true); FS.r_close(F); SynchronizeObjects(); if (!bUndo) m_RTFlags.set(flRT_Unsaved|flRT_Modified,FALSE); return true; }else { ELog.Msg(mtError,"Can't find file: '%s'",map_name); } return false; }
bool CEditableObject::Load(IReader& F) { bool bRes = true; do{ u32 version = 0; shared_str buf; shared_str sh_name; R_ASSERT(F.r_chunk(EOBJ_CHUNK_VERSION,&version)); if (version!=EOBJ_CURRENT_VERSION){ ELog.DlgMsg( mtError, "CEditableObject: unsupported file version. Object can't load."); bRes = false; break; } R_ASSERT(F.r_chunk(EOBJ_CHUNK_FLAGS, &m_Flags.flags)); if (F.find_chunk (EOBJ_CHUNK_CLASSSCRIPT)){ F.r_stringZ (m_ClassScript); } if (F.find_chunk (EOBJ_CHUNK_LODS)){ F.r_stringZ (m_LODs); } // surfaces if (F.find_chunk(EOBJ_CHUNK_SURFACES3)){ u32 cnt = F.r_u32(); m_Surfaces.resize(cnt); for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ *s_it = xr_new<CSurface>(); F.r_stringZ (buf); (*s_it)->SetName (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetShader (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetShaderXRLC (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetGameMtl (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetTexture (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetVMap (buf.c_str()); (*s_it)->m_Flags.assign(F.r_u32()); (*s_it)->SetFVF (F.r_u32()); cnt = F.r_u32(); if (cnt>1) ELog.DlgMsg(mtError,"Object surface '%s' has more than one TC's.",buf.c_str()); R_ASSERT(1<=cnt); } }else if (F.find_chunk(EOBJ_CHUNK_SURFACES2)){ u32 cnt = F.r_u32(); m_Surfaces.resize(cnt); for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ *s_it = xr_new<CSurface>(); F.r_stringZ (buf); (*s_it)->SetName (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetShader (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetShaderXRLC (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetTexture (buf.c_str()); F.r_stringZ (buf); (*s_it)->SetVMap (buf.c_str()); (*s_it)->m_Flags.assign(F.r_u32()); (*s_it)->SetFVF (F.r_u32()); cnt = F.r_u32(); if (cnt>1) ELog.DlgMsg(mtError,"Object surface '%s' has more than one TC's.",buf.c_str()); R_ASSERT(1<=cnt); } }else{ R_ASSERT(F.find_chunk(EOBJ_CHUNK_SURFACES)); u32 cnt = F.r_u32(); m_Surfaces.resize(cnt); for (SurfaceIt s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ *s_it = xr_new<CSurface>(); F.r_stringZ(buf); (*s_it)->SetName(buf.c_str()); F.r_stringZ(sh_name); (*s_it)->m_Flags.set(CSurface::sf2Sided,!!F.r_u8()); (*s_it)->SetFVF (F.r_u32()); cnt = F.r_u32(); if (cnt>1) ELog.DlgMsg(mtError,"Object surface '%s' has more than one TC's.",buf.c_str()); R_ASSERT(1<=cnt); F.r_stringZ (buf); (*s_it)->SetTexture(buf.c_str()); F.r_stringZ (buf); (*s_it)->SetVMap(buf.c_str()); (*s_it)->SetShader (sh_name.c_str()); (*s_it)->SetShaderXRLC ("default"); } // surfaces xrlc part if(F.find_chunk(EOBJ_CHUNK_SURFACES_XRLC)) for (s_it=m_Surfaces.begin(); s_it!=m_Surfaces.end(); s_it++){ F.r_stringZ(buf); (*s_it)->SetShaderXRLC(buf.c_str()); } } // Load meshes IReader* OBJ = F.open_chunk(EOBJ_CHUNK_EDITMESHES); if(OBJ){ IReader* M = OBJ->open_chunk(0); for (int count=1; M; count++) { CEditableMesh* mesh=xr_new<CEditableMesh>(this); if (mesh->LoadMesh(*M)) m_Meshes.push_back(mesh); else{ ELog.DlgMsg( mtError, "CEditableObject: Can't load mesh '%s'!", *mesh->m_Name ); xr_delete(mesh); bRes = false; } M->close(); if (!bRes) break; M = OBJ->open_chunk(count); } OBJ->close(); } // bones if (bRes){ IReader* B_CHUNK = F.open_chunk(EOBJ_CHUNK_BONES2); if (B_CHUNK){ int chunk = 0; IReader* O; while (0!=(O=B_CHUNK->open_chunk(chunk++))){ m_Bones.push_back(xr_new<CBone>()); m_Bones.back()->Load_1(*O); O->close(); } B_CHUNK->close(); PrepareBones(); }else if (F.find_chunk(EOBJ_CHUNK_BONES)){ m_Bones.resize(F.r_u32()); for (BoneIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++){ *b_it = xr_new<CBone>(); (*b_it)->Load_0(F); } PrepareBones(); } // skeleton motions if (F.find_chunk(EOBJ_CHUNK_SMOTIONS)){ m_SMotions.resize(F.r_u32()); for (SMotionIt s_it=m_SMotions.begin(); s_it!=m_SMotions.end(); s_it++){ *s_it = xr_new<CSMotion>(); if (!(*s_it)->Load(F)){ Log ("!Motions has different version. Load failed."); xr_delete(*s_it); m_SMotions.clear(); break; } // resort bone_mots (*s_it)->SortBonesBySkeleton(m_Bones); } } if (F.find_chunk(EOBJ_CHUNK_SMOTIONS2)){ F.r_stringZ (m_SMotionRefs); } } // bone parts if (bRes){ if (F.find_chunk(EOBJ_CHUNK_BONEPARTS)){ m_BoneParts.resize(F.r_u32()); bool bBPok = true; for (BPIt bp_it=m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++){ F.r_stringZ (buf); bp_it->alias=buf; bp_it->bones.resize(F.r_u32()); for (RStringVecIt s_it=bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++){ int idx = F.r_u32(); if ((idx>=0)&&(idx<(int)m_Bones.size())){ *s_it = m_Bones[idx]->Name(); }else{ Log ("!Invalid bone parts.",GetName()); bBPok = false; break; } } if (!bBPok) break; } if (!bBPok) m_BoneParts.clear(); if (!m_BoneParts.empty()&&!VerifyBoneParts()) Log ("!Invalid bone parts. Found duplicate bones in object '%s'.",GetName()); }else if (F.find_chunk(EOBJ_CHUNK_BONEPARTS2)){ m_BoneParts.resize(F.r_u32()); for (BPIt bp_it=m_BoneParts.begin(); bp_it!=m_BoneParts.end(); bp_it++){ F.r_stringZ (buf); bp_it->alias=buf; bp_it->bones.resize(F.r_u32()); for (RStringVecIt s_it=bp_it->bones.begin(); s_it!=bp_it->bones.end(); s_it++) F.r_stringZ(*s_it); } if (!m_BoneParts.empty()&&!VerifyBoneParts()) Log ("!Invalid bone parts. Found duplicate bones in object '%s'.",GetName()); } } if (bRes){ if (F.find_chunk (EOBJ_CHUNK_ACTORTRANSFORM)){ F.r_fvector3 (a_vPosition); F.r_fvector3 (a_vRotate); } if (F.find_chunk (EOBJ_CHUNK_DESC)){ F.r_stringZ (m_CreateName); F.r (&m_CreateTime,sizeof(m_CreateTime)); F.r_stringZ (m_ModifName); F.r (&m_ModifTime,sizeof(m_ModifTime)); } ResetSAnimation(); } if (!bRes) break; UpdateBox (); VerifyMeshNames (); }while(0); return bRes; }
bool CLight::Load(IReader& F) { u32 version = 0; string1024 buf; R_ASSERT(F.r_chunk(LIGHT_CHUNK_VERSION,&version)); if((version!=0x0010)&&(version!=LIGHT_VERSION)){ ELog.DlgMsg( mtError, "CLight: Unsupported version."); return false; } CCustomObject::Load(F); if (F.find_chunk(LIGHT_CHUNK_PARAMS)){ m_Type = (ELight::EType)F.r_u32(); F.r_fcolor (m_Color); m_Brightness = F.r_float(); m_Range = F.r_float(); m_Attenuation0 = F.r_float(); m_Attenuation1 = F.r_float(); m_Attenuation2 = F.r_float(); m_Cone = F.r_float(); m_VirtualSize = F.r_float(); }else{ R_ASSERT(F.find_chunk(LIGHT_CHUNK_D3D_PARAMS)); Flight d3d; F.r (&d3d,sizeof(d3d)); m_Type = (ELight::EType)d3d.type; m_Color.set (d3d.diffuse); PPosition = d3d.position; m_Range = d3d.range; m_Attenuation0 = d3d.attenuation0; m_Attenuation1 = d3d.attenuation1; m_Attenuation2 = d3d.attenuation2; m_Cone = d3d.phi; R_ASSERT(F.r_chunk(LIGHT_CHUNK_BRIGHTNESS,&m_Brightness)); } R_ASSERT(F.r_chunk(LIGHT_CHUNK_USE_IN_D3D,&m_UseInD3D)); if(version==0x0010){ if (F.find_chunk(LIGHT_CHUNK_ROTATE)){ F.r_fvector3(FRotation); }else{ FRotation.set(0,0,0); } } if (F.find_chunk(LIGHT_CHUNK_FLAG)) F.r(&m_Flags.flags,sizeof(m_Flags)); if (F.find_chunk(LIGHT_CHUNK_LCONTROL)) F.r(&m_LControl,sizeof(m_LControl)); if (D3DLIGHT_DIRECTIONAL==m_Type){ ESceneLightTools* lt = dynamic_cast<ESceneLightTools*>(ParentTools); VERIFY(lt); lt->m_SunShadowDir.set(FRotation.x,FRotation.y); ELog.DlgMsg( mtError, "CLight: Can't load sun."); return false; } if (F.find_chunk(LIGHT_CHUNK_ANIMREF)){ F.r_stringZ(buf,sizeof(buf)); m_pAnimRef = LALib.FindItem(buf); if (!m_pAnimRef) ELog.Msg(mtError, "Can't find light animation: %s",buf); } if (F.find_chunk(LIGHT_CHUNK_FALLOFF_TEXTURE)){ F.r_stringZ(m_FalloffTex); } if (F.find_chunk(LIGHT_CHUNK_FUZZY_DATA)){ m_FuzzyData = xr_new<SFuzzyData>(); m_FuzzyData->Load(F); m_Flags.set(ELight::flPointFuzzy,TRUE); }else{ m_Flags.set(ELight::flPointFuzzy,FALSE); } UpdateTransform (); return true; }
bool EDetailManager::LoadStream(IReader& F) { inherited::LoadStream (F); string256 buf; R_ASSERT (F.find_chunk(DETMGR_CHUNK_VERSION)); u32 version = F.r_u32(); if (version!=DETMGR_VERSION){ ELog.Msg(mtError,"EDetailManager: unsupported version."); return false; } if (F.find_chunk(DETMGR_CHUNK_FLAGS)) m_Flags.assign(F.r_u32()); // header R_ASSERT (F.r_chunk(DETMGR_CHUNK_HEADER,&dtH)); // slots R_ASSERT (F.find_chunk(DETMGR_CHUNK_SLOTS)); int slot_cnt = F.r_u32(); if (slot_cnt)dtSlots= xr_alloc<DetailSlot>(slot_cnt); m_Selected.resize (slot_cnt); F.r (dtSlots,slot_cnt*sizeof(DetailSlot)); // objects if (!LoadColorIndices(F)){ ELog.DlgMsg (mtError,"EDetailManager: Some objects removed. Reinitialize objects.",buf); InvalidateSlots (); } // internal // bbox R_ASSERT (F.r_chunk(DETMGR_CHUNK_BBOX,&m_BBox)); // snap objects if (F.find_chunk(DETMGR_CHUNK_SNAP_OBJECTS)){ int snap_cnt = F.r_u32(); if (snap_cnt){ for (int i=0; i<snap_cnt; i++){ F.r_stringZ (buf,sizeof(buf)); CCustomObject* O = Scene->FindObjectByName(buf,OBJCLASS_SCENEOBJECT); if (!O) ELog.Msg(mtError,"EDetailManager: Can't find snap object '%s'.",buf); else m_SnapObjects.push_back(O); } } } if (F.find_chunk(DETMGR_CHUNK_DENSITY)) ps_r__Detail_density= F.r_float(); // base texture if(F.find_chunk(DETMGR_CHUNK_BASE_TEXTURE)){ F.r_stringZ (buf,sizeof(buf)); if (m_Base.LoadImage(buf)){ m_Base.CreateShader(); m_RTFlags.set(flRTGenerateBaseMesh,TRUE); }else{ ELog.Msg(mtError,"EDetailManager: Can't find base texture '%s'.",buf); ClearSlots(); ClearBase(); } } InvalidateCache (); return true; }
void Startup(LPSTR lpCmdLine) { char cmd[512],name[256]; BOOL bModifyOptions = FALSE; strcpy(cmd,lpCmdLine); strlwr(cmd); if (strstr(cmd,"-?") || strstr(cmd,"-h")) { Help(); return; } if (strstr(cmd,"-f")==0) { Help(); return; } if (strstr(cmd,"-o")) bModifyOptions = TRUE; if (strstr(cmd,"-gi")) b_radiosity = TRUE; if (strstr(cmd,"-noise")) b_noise = TRUE; if (strstr(cmd,"-nosun")) b_nosun = TRUE; // Give a LOG-thread a chance to startup //_set_sbh_threshold(1920); InitCommonControls (); thread_spawn (logThread, "log-update", 1024*1024,0); Sleep (150); // Faster FPU SetPriorityClass (GetCurrentProcess(),NORMAL_PRIORITY_CLASS); /* u32 dwMin = 1800*(1024*1024); u32 dwMax = 1900*(1024*1024); if (0==SetProcessWorkingSetSize(GetCurrentProcess(),dwMin,dwMax)) { clMsg("*** Failed to expand working set"); }; */ // Load project name[0]=0; sscanf(strstr(cmd,"-f")+2,"%s",name); string256 prjName; FS.update_path (prjName,"$game_levels$",strconcat(prjName,name,"\\build.prj")); string256 phaseName; Phase (strconcat(phaseName,"Reading project [",name,"]...")); string256 inf; extern HWND logWindow; IReader* F = FS.r_open(prjName); if (NULL==F){ sprintf (inf,"Build failed!\nCan't find level: '%s'",name); clMsg (inf); MessageBox (logWindow,inf,"Error!",MB_OK|MB_ICONERROR); return; } // Version u32 version; F->r_chunk (EB_Version,&version); clMsg ("version: %d",version); R_ASSERT(XRCL_CURRENT_VERSION==version); // Header b_params Params; F->r_chunk (EB_Parameters,&Params); // Show options if needed if (bModifyOptions) { Phase ("Project options..."); HMODULE L = LoadLibrary ("xrLC_Options.dll"); void* P = GetProcAddress (L,"_frmScenePropertiesRun"); R_ASSERT (P); xrOptions* O = (xrOptions*)P; int R = O(&Params,version,false); FreeLibrary (L); if (R==2) { ExitProcess(0); } } // Conversion Phase ("Converting data structures..."); pBuild = xr_new<CBuild>(); pBuild->Load (Params,*F); xr_delete (F); // Call for builder string256 lfn; CTimer dwStartupTime; dwStartupTime.Start(); FS.update_path (lfn,_game_levels_,name); pBuild->Run (lfn); xr_delete (pBuild); // Show statistic extern std::string make_time(u32 sec); u32 dwEndTime = dwStartupTime.GetElapsed_ms(); sprintf (inf,"Time elapsed: %s",make_time(dwEndTime/1000).c_str()); clMsg ("Build succesful!\n%s",inf); MessageBox (logWindow,inf,"Congratulation!",MB_OK|MB_ICONINFORMATION); // Close log bClose = TRUE; Sleep (500); }
bool ESoundSource::Load(IReader& F) { u32 version = 0; if(F.r_chunk(SOUND_CHUNK_VERSION,&version)){ if(version!=SOUND_SOURCE_VERSION){ ELog.Msg( mtError, "ESoundSource: Unsupported version."); return false; } }else return false; inherited::Load (F); R_ASSERT(F.find_chunk(SOUND_CHUNK_TYPE)); m_Type = ESoundType(F.r_u32()); R_ASSERT(F.find_chunk(SOUND_CHUNK_SOURCE_NAME)); F.r_stringZ (m_WAVName); if (F.find_chunk(SOUND_CHUNK_SOURCE_PARAMS3)){ m_Params.base_volume = 1.f; F.r_fvector3 (m_Params.position); m_Params.volume = F.r_float(); m_Params.freq = F.r_float(); m_Params.min_distance = F.r_float(); m_Params.max_distance = F.r_float(); m_Params.max_ai_distance= F.r_float(); }else if (F.find_chunk(SOUND_CHUNK_SOURCE_PARAMS2)){ m_Params.base_volume = 1.f; F.r_fvector3 (m_Params.position); m_Params.volume = F.r_float(); m_Params.freq = F.r_float(); m_Params.min_distance = F.r_float(); m_Params.max_distance = F.r_float(); m_Params.max_ai_distance= F.r_float(); }else{ if (!F.find_chunk(SOUND_CHUNK_SOURCE_PARAMS)){ ELog.DlgMsg( mtError, "ESoundSource: Can't load Sound Source '%s'. Unsupported version.",*m_WAVName); return false; } m_Params.base_volume = 1.f; F.r_fvector3 (m_Params.position); m_Params.volume = F.r_float(); m_Params.freq = F.r_float(); m_Params.min_distance = F.r_float(); m_Params.max_distance = F.r_float(); m_Params.max_ai_distance= m_Params.max_distance; } if(F.find_chunk(SOUND_CHUNK_SOURCE_FLAGS)) F.r (&m_Flags,sizeof(m_Flags)); if(F.find_chunk(SOUND_CHUNK_GAME_PARAMS)){ F.r_fvector2 (m_RandomPause); F.r_fvector2 (m_ActiveTime); F.r_fvector2 (m_PlayTime); } ResetSource (); switch (m_Type){ case stStaticSource: if (m_Flags.is(flPlaying)) Play(); if (m_Flags.is(flSimulating)) Simulate(); break; default: THROW; } return true; }
void global_claculation_data::xrLoad() { string_path N; FS.update_path ( N, "$game_data$", "shaders_xrlc.xr" ); g_shaders_xrlc = new Shader_xrLC_LIB(); g_shaders_xrlc->Load ( N ); // Load CFORM { FS.update_path (N,"$level$","build.cform"); IReader* fs = FS.r_open("$level$","build.cform"); 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); RCAST_Model.build ( verts, H.vertcount, tris, H.facecount ); Msg("* Level CFORM: %dK",RCAST_Model.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); } { slots_data.Load( ); } // Lights { IReader* fs = FS.r_open("$level$","build.lights"); IReader* F; u32 cnt; R_Light* L; // rgb F = fs->open_chunk (0); cnt = F->length()/sizeof(R_Light); L = (R_Light*)F->pointer(); g_lights.rgb.assign (L,L+cnt); F->close (); // hemi F = fs->open_chunk (1); cnt = F->length()/sizeof(R_Light); L = (R_Light*)F->pointer(); g_lights.hemi.assign(L,L+cnt); F->close (); // sun F = fs->open_chunk (2); cnt = F->length()/sizeof(R_Light); L = (R_Light*)F->pointer(); g_lights.sun.assign (L,L+cnt); F->close (); FS.r_close (fs); } // Load level data { IReader* fs = FS.r_open ("$level$","build.prj"); IReader* F; // Version u32 version; fs->r_chunk (EB_Version,&version); R_ASSERT(XRCL_CURRENT_VERSION==version); // Header fs->r_chunk (EB_Parameters,&g_params); // Load level data transfer("materials", g_materials, *fs, EB_Materials); transfer("shaders_xrlc",g_shader_compile, *fs, EB_Shaders_Compile); post_process_materials( *g_shaders_xrlc, g_shader_compile, g_materials ); // process textures #ifdef DEBUG xr_vector<b_texture> dbg_textures; #endif 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)); #ifdef DEBUG dbg_textures.push_back( TEX ); #endif b_BuildTexture BT; CopyMemory (&BT,&TEX,sizeof(TEX)); // load thumbnail LPSTR N = BT.name; if (strchr(N,'.')) *(strchr(N,'.')) = 0; 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 { strcat (N,".thm"); IReader* THM = FS.r_open("$game_textures$",N); 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); } } } }
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); } }
bool CEditableMesh::LoadMesh(IReader& F){ u32 version=0; R_ASSERT(F.r_chunk(EMESH_CHUNK_VERSION,&version)); if (version!=EMESH_CURRENT_VERSION){ ELog.DlgMsg( mtError, "CEditableMesh: unsuported file version. Mesh can't load."); return false; } R_ASSERT(F.find_chunk(EMESH_CHUNK_MESHNAME)); F.r_stringZ (m_Name); R_ASSERT(F.r_chunk(EMESH_CHUNK_BBOX,&m_Box)); R_ASSERT(F.r_chunk(EMESH_CHUNK_FLAGS,&m_Flags)); F.r_chunk(EMESH_CHUNK_BOP,&m_Ops); R_ASSERT(F.find_chunk(EMESH_CHUNK_VERTS)); m_VertCount = F.r_u32(); if (m_VertCount<3){ Log ("!CEditableMesh: Vertices<3."); return false; } m_Verts = xr_alloc<Fvector>(m_VertCount); F.r (m_Verts, m_VertCount*sizeof(Fvector)); R_ASSERT(F.find_chunk(EMESH_CHUNK_FACES)); m_FaceCount = F.r_u32(); m_Faces = xr_alloc<st_Face>(m_FaceCount); if (m_FaceCount==0){ Log ("!CEditableMesh: Faces==0."); return false; } F.r (m_Faces, m_FaceCount*sizeof(st_Face)); m_SGs = xr_alloc<u32>(m_FaceCount); Memory.mem_fill32 (m_SGs,m_Flags.is(flSGMask)?0:u32(-1),m_FaceCount); u32 sg_chunk_size = F.find_chunk(EMESH_CHUNK_SG); if (sg_chunk_size){ VERIFY (m_FaceCount*sizeof(u32)==sg_chunk_size); F.r (m_SGs, m_FaceCount*sizeof(u32)); } R_ASSERT(F.find_chunk(EMESH_CHUNK_VMREFS)); m_VMRefs.resize (F.r_u32()); int sz_vmpt = sizeof(st_VMapPt); for (VMRefsIt r_it=m_VMRefs.begin(); r_it!=m_VMRefs.end(); r_it++){ r_it->count = F.r_u8(); r_it->pts = xr_alloc<st_VMapPt>(r_it->count); F.r (r_it->pts, sz_vmpt*r_it->count); } R_ASSERT(F.find_chunk(EMESH_CHUNK_SFACE)); string128 surf_name; u32 sface_cnt = F.r_u16(); // surface-face count for (u32 sp_i=0; sp_i<sface_cnt; sp_i++){ F.r_stringZ (surf_name,sizeof(surf_name)); int surf_id; CSurface* surf = m_Parent->FindSurfaceByName(surf_name, &surf_id); VERIFY(surf); IntVec& face_lst = m_SurfFaces[surf]; face_lst.resize (F.r_u32()); if (face_lst.empty()){ Log ("!Empty surface found: %s",surf->_Name()); return false; } F.r (&*face_lst.begin(), face_lst.size()*sizeof(int)); std::sort (face_lst.begin(),face_lst.end()); } if(F.find_chunk(EMESH_CHUNK_VMAPS_2)){ m_VMaps.resize (F.r_u32()); for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++){ *vm_it = xr_new<st_VMap>(); F.r_stringZ ((*vm_it)->name); (*vm_it)->dim = F.r_u8(); (*vm_it)->polymap=F.r_u8(); (*vm_it)->type = F.r_u8(); (*vm_it)->resize(F.r_u32()); F.r ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize()); F.r ((*vm_it)->getVIdata(), (*vm_it)->VIdatasize()); if ((*vm_it)->polymap) F.r ((*vm_it)->getPIdata(), (*vm_it)->PIdatasize()); } }else{ if(F.find_chunk(EMESH_CHUNK_VMAPS_1)){ m_VMaps.resize (F.r_u32()); for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++){ *vm_it = xr_new<st_VMap>(); F.r_stringZ ((*vm_it)->name); (*vm_it)->dim = F.r_u8(); (*vm_it)->type = F.r_u8(); (*vm_it)->resize(F.r_u32()); F.r ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize() ); } }else{ R_ASSERT(F.find_chunk(EMESH_CHUNK_VMAPS_0)); m_VMaps.resize (F.r_u32()); for (VMapIt vm_it=m_VMaps.begin(); vm_it!=m_VMaps.end(); vm_it++){ *vm_it = xr_new<st_VMap>(); F.r_stringZ ((*vm_it)->name); (*vm_it)->dim = 2; (*vm_it)->type = vmtUV; (*vm_it)->resize(F.r_u32()); F.r ((*vm_it)->getVMdata(), (*vm_it)->VMdatasize() ); } } // update vmaps RebuildVMaps(); } #ifdef _EDITOR if (!EPrefs->object_flags.is(epoDeffLoadRB)){ GenerateFNormals (); GenerateAdjacency (); GenerateVNormals (); GenerateRenderBuffers(); UnloadFNormals (); UnloadAdjacency (); UnloadVNormals (); } if (!EPrefs->object_flags.is(epoDeffLoadCF)) GenerateCFModel(); #endif Optimize(false); RebuildVMaps(); return true; }