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 CALifeSpawnHeader::load (IReader &file_stream) { m_version = file_stream.r_u32(); R_ASSERT2 (XRAI_CURRENT_VERSION == m_version,"'game.spawn' version mismatch!"); file_stream.r (&m_guid,sizeof(m_guid)); file_stream.r (&m_graph_guid,sizeof(m_graph_guid)); m_count = file_stream.r_u32(); m_level_count = file_stream.r_u32(); }
//------------------------------------------------------------------------------ // 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 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; }
void SAINode::LoadStream(IReader& F, ESceneAIMapTool* tools) { u32 id; u16 pl; NodePosition np; F.r (&id,3); n1 = (SAINode*)tools->UnpackLink(id); F.r (&id,3); n2 = (SAINode*)tools->UnpackLink(id); F.r (&id,3); n3 = (SAINode*)tools->UnpackLink(id); F.r (&id,3); n4 = (SAINode*)tools->UnpackLink(id); pl = F.r_u16(); pvDecompress(Plane.n,pl); F.r (&np,sizeof(np)); tools->UnpackPosition(Pos,np,tools->m_AIBBox,tools->m_Params); Plane.build (Pos,Plane.n); flags.assign (F.r_u8()); }
void ppmd_initialize () { if (trained_model) trained_model->rewind (); static bool initialized = false; if (initialized) return; string_path file_name; FS.update_path (file_name,"$game_config$","mp\\!PPMd.mdl"); if (FS.exist(file_name)) { IReader *reader = FS.r_open(file_name); R_ASSERT (reader); u32 buffer_size = reader->length(); u8 *buffer = (u8*)xr_malloc(buffer_size); reader->r (buffer,buffer_size); FS.r_close (reader); trained_model = new stream(buffer,buffer_size); } initialized = true; if (StartSubAllocator(suballocator_size)) return; exit (-1); }
void CGameGraphBuilder::load_graph_points (const float &start, const float &amount) { Progress (start); Msg ("Loading graph points"); string_path spawn_file_name; strconcat (sizeof(spawn_file_name),spawn_file_name,*m_level_name,"level.spawn"); IReader *reader = FS.r_open(spawn_file_name); u32 id; NET_Packet net_packet; for ( IReader *chunk = reader->open_chunk_iterator(id); chunk; chunk = reader->open_chunk_iterator(id,chunk) ) { net_packet.B.count = chunk->length(); chunk->r (net_packet.B.data,net_packet.B.count); load_graph_point (net_packet); } FS.r_close (reader); Msg ("%d graph points loaded",graph().vertices().size()); Progress (start + amount); }
size_t ov_read_func(void *ptr, size_t size, size_t nmemb, void *datasource) { IReader* F = (IReader*)datasource; size_t exist_block = _max(0ul,iFloor(F->elapsed()/(float)size)); size_t read_block = _min(exist_block,nmemb); F->r (ptr,(int)(read_block*size)); return read_block; }
void CHOM::Load () { // Find and open file string_path fName; FS.update_path (fName,"$level$","level.hom"); if (!FS.exist(fName)) { Msg (" WARNING: Occlusion map '%s' not found.",fName); return; } Msg ("* Loading HOM: %s",fName); IReader* fs = FS.r_open(fName); IReader* S = fs->open_chunk(1); // Load tris and merge them CDB::Collector CL; while (!S->eof()) { HOM_poly P; S->r (&P,sizeof(P)); CL.add_face_packed_D (P.v1,P.v2,P.v3,P.flags,0.01f); } // Determine adjacency xr_vector<u32> adjacency; CL.calc_adjacency (adjacency); // Create RASTER-triangles m_pTris = xr_alloc<occTri> (u32(CL.getTS())); for (u32 it=0; it<CL.getTS(); it++) { CDB::TRI& clT = CL.getT()[it]; occTri& rT = m_pTris[it]; Fvector& v0 = CL.getV()[clT.verts[0]]; Fvector& v1 = CL.getV()[clT.verts[1]]; Fvector& v2 = CL.getV()[clT.verts[2]]; rT.adjacent[0] = (0xffffffff==adjacency[3*it+0])?((occTri*) (-1)):(m_pTris+adjacency[3*it+0]); rT.adjacent[1] = (0xffffffff==adjacency[3*it+1])?((occTri*) (-1)):(m_pTris+adjacency[3*it+1]); rT.adjacent[2] = (0xffffffff==adjacency[3*it+2])?((occTri*) (-1)):(m_pTris+adjacency[3*it+2]); rT.flags = clT.dummy; rT.area = Area (v0,v1,v2); if (rT.area<EPS_L) { Msg ("! Invalid HOM triangle (%f,%f,%f)-(%f,%f,%f)-(%f,%f,%f)",VPUSH(v0),VPUSH(v1),VPUSH(v2)); } rT.plane.build (v0,v1,v2); rT.skip = 0; rT.center.add(v0,v1).add(v2).div(3.f); } // Create AABB-tree m_pModel = xr_new<CDB::MODEL> (); m_pModel->build (CL.getV(),int(CL.getVS()),CL.getT(),int(CL.getTS())); bEnabled = TRUE; S->close (); FS.r_close (fs); }
bool CALifeSimulatorHeader::valid (IReader &file_stream) const { if (!file_stream.find_chunk(ALIFE_CHUNK_DATA)) return (false); u32 version; file_stream.r (&version, sizeof(version)); return (version>=2); }
bool ESceneCustomMTools::Load(IReader& F) { if (F.find_chunk(CHUNK_TOOLS_TAG)){ F.r_stringZ (m_ModifName); F.r (&m_ModifTime,sizeof(m_ModifTime)); }else{ m_ModifName = ""; m_ModifTime = 0; } return true; }
void st_LevelOptions::Read(IReader& F) { R_ASSERT(F.find_chunk(CHUNK_LO_VERSION)); DWORD vers = F.r_u32( ); if( vers < 0x00000008 ) { ELog.DlgMsg( mtError, "Skipping bad version of level options." ); return; } R_ASSERT(F.find_chunk(CHUNK_LO_NAMES)); F.r_stringZ (m_FNLevelPath); if (F.find_chunk(CHUNK_LO_PREFIX)) F.r_stringZ (m_LevelPrefix); R_ASSERT(F.find_chunk(CHUNK_LO_BOP)); F.r_stringZ (m_BOPText); if (F.find_chunk(CHUNK_LO_MAP_VER)) F.r_stringZ (m_map_version); vers = 0; if (F.find_chunk(CHUNK_LO_BP_VERSION)) vers = F.r_u32( ); if (CURRENT_LEVELOP_BP_VERSION==vers){ if (F.find_chunk(CHUNK_BUILD_PARAMS)) F.r(&m_BuildParams, sizeof(m_BuildParams)); }else{ ELog.DlgMsg (mtError, "Skipping bad version of build params."); m_BuildParams.Init(); } if (F.find_chunk(CHUNK_LIGHT_QUALITY)) { m_LightHemiQuality = F.r_u8(); m_LightSunQuality = F.r_u8(); } if (F.find_chunk(CHUNK_MAP_USAGE)) { if(vers > 0x00000008) { m_mapUsage.m_GameType.assign (F.r_u16()); }else { m_mapUsage.m_GameType.zero (); m_mapUsage.m_GameType.set (eGameIDDeathmatch , F.r_s32()); m_mapUsage.m_GameType.set (eGameIDTeamDeathmatch, F.r_s32()); m_mapUsage.m_GameType.set (eGameIDArtefactHunt, F.r_s32()); } } }
bool CEditShape::Load(IReader& F) { R_ASSERT(F.find_chunk(SHAPE_CHUNK_VERSION)); u16 vers = F.r_u16(); if (SHAPE_CURRENT_VERSION!=vers){ ELog.DlgMsg( mtError, "CEditShape: unsupported version. Object can't load."); return false; } inherited::Load (F); R_ASSERT(F.find_chunk(SHAPE_CHUNK_SHAPES)); shapes.resize (F.r_u32()); F.r (shapes.begin(),shapes.size()*sizeof(shape_def)); ComputeBounds(); return true; }
bool CEditShape::LoadStream(IReader& F) { R_ASSERT(F.find_chunk(SHAPE_CHUNK_VERSION)); u16 vers = F.r_u16(); inherited::LoadStream (F); R_ASSERT(F.find_chunk(SHAPE_CHUNK_SHAPES)); shapes.resize (F.r_u32()); F.r (shapes.begin(),shapes.size()*sizeof(shape_def)); if(F.find_chunk(SHAPE_CHUNK_DATA)) m_shape_type = F.r_u8(); ComputeBounds(); return true; }
void CResourceManager::OnDeviceCreate (LPCSTR shName) { #ifdef _EDITOR if (!FS.exist(shName)) return; #endif // Check if file is compressed already string32 ID = "shENGINE"; string32 id; IReader* F = FS.r_open(shName); R_ASSERT2 (F,shName); F->r (&id,8); if (0==strncmp(id,ID,8)) { FATAL ("Unsupported blender library. Compressed?"); } OnDeviceCreate (F); FS.r_close (F); }
//------------------------------------------------------------------------------------------------ // Scene //------------------------------------------------------------------------------------------------ BOOL EScene::LoadLevelPartLTX(ESceneToolBase* M, LPCSTR mn) { string_path map_name; strcpy(map_name, mn); if(!M->can_use_inifile()) return LoadLevelPart(M, map_name); int fnidx=0; while(FS.exist(map_name)) { IReader* R = FS.r_open (map_name); VERIFY (R); char ch; R->r (&ch,sizeof(ch)); bool b_is_inifile = (ch=='['); FS.r_close (R); if(!b_is_inifile) return LoadLevelPart(M, map_name); M->m_EditFlags.set(ESceneToolBase::flReadonly,FALSE); CInifile ini(map_name); // check level part GUID xrGUID guid; guid.LoadLTX (ini, "guid", "guid"); if (guid!=m_GUID) { ELog.DlgMsg (mtError,"Skipping invalid version of level part: '%s\\%s.part'",EFS.ExtractFileName(map_name).c_str(),M->ClassName()); return FALSE; } // read data M->LoadLTX (ini); ++fnidx; sprintf(map_name, "%s%d", mn, fnidx); } return TRUE; }
void CObjectSpace::Load () { IReader *F = FS.r_open ("$level$", "level.cform"); R_ASSERT (F); hdrCFORM H; F->r (&H,sizeof(hdrCFORM)); Fvector* verts = (Fvector*)F->pointer(); CDB::TRI* tris = (CDB::TRI*)(verts+H.vertcount); R_ASSERT (CFORM_CURRENT_VERSION==H.version); Static.build ( verts, H.vertcount, tris, H.facecount, build_callback ); m_BoundingVolume.set (H.aabb); g_SpatialSpace->initialize (H.aabb); g_SpatialSpacePhysic->initialize (H.aabb); Sound->set_geometry_occ ( &Static ); Sound->set_handler ( _sound_event ); FS.r_close (F); }
BOOL EScene::LoadLevelPart(ESceneToolBase* M, LPCSTR map_name) { if(M->can_use_inifile()) return LoadLevelPartLTX(M, map_name); if (FS.exist(map_name)) { // check locking M->m_EditFlags.set(ESceneToolBase::flReadonly,FALSE); IReader* R = FS.r_open (map_name); VERIFY (R); // check level part GUID R_ASSERT (R->find_chunk (CHUNK_TOOLS_GUID)); xrGUID guid; R->r (&guid,sizeof(guid)); if (guid!=m_GUID) { ELog.DlgMsg (mtError,"Skipping invalid version of level part: '%s\\%s.part'",EFS.ExtractFileName(map_name).c_str(),M->ClassName()); FS.r_close (R); return FALSE; } // read data IReader* chunk = R->open_chunk (CHUNK_TOOLS_DATA+M->ClassID); if(chunk!=NULL) { M->LoadStream (*chunk); chunk->close (); }else { ELog.DlgMsg (mtError,"Skipping corrupted version of level part: '%s\\%s.part'",EFS.ExtractFileName(map_name).c_str(),M->ClassName()); FS.r_close (R); return FALSE; } //success FS.r_close (R); return TRUE; } return TRUE; }
void STextureParams::Load(IReader& F) { R_ASSERT(F.find_chunk(THM_CHUNK_TEXTUREPARAM)); F.r (&fmt,sizeof(ETFormat)); flags.assign(F.r_u32()); border_color= F.r_u32(); fade_color = F.r_u32(); fade_amount = F.r_u32(); mip_filter = F.r_u32(); width = F.r_u32(); height = F.r_u32(); if (F.find_chunk(THM_CHUNK_TEXTURE_TYPE)){ type = (ETType)F.r_u32(); } if (F.find_chunk(THM_CHUNK_DETAIL_EXT)){ F.r_stringZ(detail_name); detail_scale = F.r_float(); } if (F.find_chunk(THM_CHUNK_MATERIAL)){ material = (ETMaterial)F.r_u32 (); material_weight = F.r_float (); } if (F.find_chunk(THM_CHUNK_BUMP)){ bump_virtual_height = F.r_float (); bump_mode = (ETBumpMode)F.r_u32 (); if (bump_mode<STextureParams::tbmNone){ bump_mode = STextureParams::tbmNone; //.. временно (до полного убирания Autogen) } F.r_stringZ (bump_name); } if (F.find_chunk(THM_CHUNK_EXT_NORMALMAP)) F.r_stringZ (ext_normal_map_name); if (F.find_chunk(THM_CHUNK_FADE_DELAY)) fade_delay = F.r_u8(); }
void CPatternFunction::vfLoadEF(LPCSTR caFileName) { string_path caPath; if (!FS.exist(caPath,"$game_ai$",caFileName)) { Msg ("! Evaluation function : File not found \"%s\"",caPath); R_ASSERT (false); return; } IReader *F = FS.r_open(caPath); F->r (&m_tEFHeader,sizeof(SEFHeader)); if (EFC_VERSION != m_tEFHeader.dwBuilderVersion) { FS.r_close (F); Msg ("! Evaluation function (%s) : Not supported version of the Evaluation Function Contructor",caPath); R_ASSERT (false); return; } F->r (&m_dwVariableCount,sizeof(m_dwVariableCount)); m_dwaAtomicFeatureRange = xr_alloc<u32>(m_dwVariableCount); ZeroMemory (m_dwaAtomicFeatureRange,m_dwVariableCount*sizeof(u32)); u32 *m_dwaAtomicIndexes = xr_alloc<u32>(m_dwVariableCount); ZeroMemory (m_dwaAtomicIndexes,m_dwVariableCount*sizeof(u32)); for (u32 i=0; i<m_dwVariableCount; ++i) { F->r(m_dwaAtomicFeatureRange + i,sizeof(u32)); if (i) m_dwaAtomicIndexes[i] = m_dwaAtomicIndexes[i-1] + m_dwaAtomicFeatureRange[i-1]; } m_dwaVariableTypes = xr_alloc<u32>(m_dwVariableCount); F->r (m_dwaVariableTypes,m_dwVariableCount*sizeof(u32)); F->r (&m_dwFunctionType,sizeof(u32)); F->r (&m_fMinResultValue,sizeof(float)); F->r (&m_fMaxResultValue,sizeof(float)); F->r (&m_dwPatternCount,sizeof(m_dwPatternCount)); m_tpPatterns = xr_alloc<SPattern>(m_dwPatternCount); m_dwaPatternIndexes = xr_alloc<u32>(m_dwPatternCount); ZeroMemory (m_dwaPatternIndexes,m_dwPatternCount*sizeof(u32)); m_dwParameterCount = 0; for (u32 i=0; i<m_dwPatternCount; ++i) { if (i) m_dwaPatternIndexes[i] = m_dwParameterCount; F->r (&(m_tpPatterns[i].dwCardinality),sizeof(m_tpPatterns[i].dwCardinality)); m_tpPatterns[i].dwaVariableIndexes = xr_alloc<u32>(m_tpPatterns[i].dwCardinality); F->r (m_tpPatterns[i].dwaVariableIndexes,m_tpPatterns[i].dwCardinality*sizeof(u32)); u32 m_dwComplexity = 1; for (int j=0; j<(int)m_tpPatterns[i].dwCardinality; ++j) m_dwComplexity *= m_dwaAtomicFeatureRange[m_tpPatterns[i].dwaVariableIndexes[j]]; m_dwParameterCount += m_dwComplexity; } m_faParameters = xr_alloc<float>(m_dwParameterCount); F->r (m_faParameters,m_dwParameterCount*sizeof(float)); FS.r_close (F); m_dwaVariableValues = xr_alloc<u32>(m_dwVariableCount); xr_free (m_dwaAtomicIndexes); ef_storage().m_fpaBaseFunctions[m_dwFunctionType] = this; _splitpath (caPath,0,0,m_caName,0); // Msg ("* Evaluation function \"%s\" is successfully loaded",m_caName); }
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; }
void read_levels(CInifile *Ini, xr_set<CLevelInfo> &levels, bool rebuild_graph, xr_vector<LPCSTR> *needed_levels) { LPCSTR _N,V; string_path caFileName, file_name; for (u32 k = 0; Ini->r_line("levels",k,&_N,&V); k++) { string256 N; strcpy_s(N,_N); strlwr (N); if (!Ini->section_exist(N)) { Msg ("! There is no section %s in the %s!",N,GAME_CONFIG); continue; } if (!Ini->line_exist(N,"name")) { Msg ("! There is no line \"name\" in the section %s!",N); continue; } if (!Ini->line_exist(N,"id")) { Msg ("! There is no line \"id\" in the section %s!",N); continue; } if (!Ini->line_exist(N,"offset")) { Msg ("! There is no line \"offset\" in the section %s!",N); continue; } u8 id = Ini->r_u8(N,"id"); LPCSTR _S = Ini->r_string(N,"name"); string256 S; strcpy_s (S,_S); strlwr (S); if (needed_levels) { bool found = false; xr_vector<LPCSTR>::const_iterator I = needed_levels->begin(); xr_vector<LPCSTR>::const_iterator E = needed_levels->end(); for ( ; I != E; ++I) if (!xr_strcmp(*I,S)) { found = true; break; } if (!found) continue; } { bool ok = true; xr_set<CLevelInfo>::const_iterator I = levels.begin(); xr_set<CLevelInfo>::const_iterator E = levels.end(); for ( ; I != E; ++I) { if (!xr_strcmp((*I).m_section,N)) { Msg ("! Duplicated line %s in section \"levels\" in the %s",N,GAME_CONFIG); ok = false; break; } if (!xr_strcmp((*I).m_name,S)) { Msg ("! Duplicated level name %s in the %s, sections %s, %s",S,GAME_CONFIG,*(*I).m_section,N); ok = false; break; } if ((*I).m_id == id) { Msg ("! Duplicated level id %d in the %s, section %s, level %s",id,GAME_CONFIG,N,S); ok = false; break; } } if (!ok) continue; } IReader *reader; // ai strconcat (sizeof(caFileName),caFileName,S,"\\",LEVEL_GRAPH_NAME); FS.update_path (file_name,"$game_levels$",caFileName); if (!FS.exist(file_name)) { Msg ("! There is no ai-map for the level %s! (level is not included into the game graph)",S); continue; } { reader = FS.r_open (file_name); CLevelGraph::CHeader header; reader->r (&header,sizeof(header)); FS.r_close (reader); if (header.version() != XRAI_CURRENT_VERSION) { Msg ("! AI-map for the level %s is incompatible (version mismatch)! (level is not included into the game graph)",S); continue; } } levels.insert (CLevelInfo(id,S,Ini->r_fvector3(N,"offset"),N)); } }
void EScene::LoadCompilerError(LPCSTR fn) { Tools->ClearDebugDraw(); /* CInifile ini(fn); string256 buff; LPCSTR sect; u32 sz, i; sect = "t-junction"; sz = ini.r_u32(sect,"count"); Tools->m_DebugDraw.m_Points.resize(sz); for(i=0; i<sz; ++i) { CLevelTool::SDebugDraw::Point& pt = Tools->m_DebugDraw.m_Points[i]; sprintf (buff,"%d_p",i); pt.p[0] = ini.r_fvector3(sect,buff); sprintf (buff,"%d_c",i); pt.c = ini.r_u32 (sect,buff); sprintf (buff,"%d_i",i); pt.i = ini.r_bool(sect,buff); sprintf (buff,"%d_m",i); pt.m = ini.r_bool(sect,buff); } sect = "m-edje"; sz = ini.r_u32(sect,"count"); Tools->m_DebugDraw.m_Lines.resize(sz); for(i=0; i<sz; ++i) { CLevelTool::SDebugDraw::Line& pt = Tools->m_DebugDraw.m_Lines[i]; sprintf (buff,"%d_p0",i); pt.p[0] = ini.r_fvector3(sect,buff); sprintf (buff,"%d_p1",i); pt.p[1] = ini.r_fvector3(sect,buff); sprintf (buff,"%d_c",i); pt.c = ini.r_u32 (sect,buff); sprintf (buff,"%d_i",i); pt.i = ini.r_bool(sect,buff); sprintf (buff,"%d_m",i); pt.m = ini.r_bool(sect,buff); } sect = "invalid_face"; sz = ini.r_u32(sect,"count"); Tools->m_DebugDraw.m_WireFaces.resize(sz); for(i=0; i<sz; ++i) { CLevelTool::SDebugDraw::Face& pt = Tools->m_DebugDraw.m_WireFaces[i]; sprintf (buff,"%d_p0",i); pt.p[0] = ini.r_fvector3(sect,buff); sprintf (buff,"%d_p1",i); pt.p[1] = ini.r_fvector3(sect,buff); sprintf (buff,"%d_p2",i); pt.p[2] = ini.r_fvector3(sect,buff); sprintf (buff,"%d_c",i); pt.c = ini.r_u32 (sect,buff); sprintf (buff,"%d_i",i); pt.i = ini.r_bool(sect,buff); sprintf (buff,"%d_m",i); pt.m = ini.r_bool(sect,buff); } */ IReader* F = FS.r_open(fn); Tools->ClearDebugDraw(); Fvector pt[3]; if (F->find_chunk(10)){ // lc error (TJ) Tools->m_DebugDraw.m_Points.resize(F->r_u32()); F->r(Tools->m_DebugDraw.m_Points.begin(),sizeof(CLevelTool::SDebugDraw::Point)*Tools->m_DebugDraw.m_Points.size()); }else if (F->find_chunk(0)){ // lc error (TJ) u32 cnt = F->r_u32(); for (u32 k=0;k<cnt; k++){ F->r(pt,sizeof(Fvector)); Tools->m_DebugDraw.AppendPoint(pt[0],0xff00ff00,true,true,"TJ"); } } /* if (F->find_chunk(11)){ // lc error (multiple edges) Tools->m_DebugDraw.m_Lines.resize(F->r_u32()); F->r(Tools->m_DebugDraw.m_Lines.begin(),sizeof(CLevelTool::SDebugDraw::Line)*Tools->m_DebugDraw.m_Lines.size()); }else if (F->find_chunk(1)){ // lc error (multiple edges) u32 cnt = F->r_u32(); for (u32 k=0;k<cnt; k++){ F->r(pt,sizeof(Fvector)*2); Tools->m_DebugDraw.AppendLine(pt[0],pt[1],0xff0000ff,false,false); } } */ if (F->find_chunk(12)){ // lc error (invalid faces) Tools->m_DebugDraw.m_WireFaces.resize(F->r_u32()); F->r(Tools->m_DebugDraw.m_WireFaces.begin(),sizeof(CLevelTool::SDebugDraw::Face)*Tools->m_DebugDraw.m_WireFaces.size()); }else if (F->find_chunk(2)){ // lc error (invalid faces) u32 cnt = F->r_u32(); for (u32 k=0;k<cnt; k++){ F->r(pt,sizeof(Fvector)*3); Tools->m_DebugDraw.AppendWireFace(pt[0],pt[1],pt[2]); } } FS.r_close(F); }
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 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; }
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); } } } }
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 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; }
CLevelGameGraph ( LPCSTR graph_file_name, LPCSTR raw_cross_table_file_name, CGameGraph::SLevel *tLevel, LPCSTR S, u32 dwOffset, u32 dwLevelID, CInifile *Ini ) { m_tLevel = *tLevel; m_dwOffset = dwOffset; m_tpLevelPoints.clear (); FILE_NAME caFileName; // loading graph strcpy_s (caFileName,graph_file_name); m_tpGraph = new CGameGraph(caFileName); strcpy_s (caFileName,raw_cross_table_file_name); CGameLevelCrossTable *l_tpCrossTable = new CGameLevelCrossTable(caFileName); CLevelGraph *l_tpAI_Map = new CLevelGraph(S); VERIFY2 (l_tpCrossTable->header().level_guid() == l_tpAI_Map->header().guid(), "cross table doesn't correspond to the AI-map, rebuild graph!"); VERIFY2 (l_tpCrossTable->header().game_guid() == m_tpGraph->header().guid(), "cross table doesn't correspond to the graph, rebuild graph!"); VERIFY2 (m_tpGraph->header().level(GameGraph::_LEVEL_ID(0)).guid() == l_tpAI_Map->header().guid(), "cross table doesn't correspond to the AI-map, rebuild graph!"); VERIFY (l_tpAI_Map->header().vertex_count() == l_tpCrossTable->header().level_vertex_count()); VERIFY (m_tpGraph->header().vertex_count() == l_tpCrossTable->header().game_vertex_count()); tLevel->m_guid = l_tpAI_Map->header().guid(); { for (GameGraph::_GRAPH_ID i=0, n = m_tpGraph->header().vertex_count(); i<n; ++i) if ((!l_tpAI_Map->valid_vertex_id(m_tpGraph->vertex(i)->level_vertex_id()) || (l_tpCrossTable->vertex(m_tpGraph->vertex(i)->level_vertex_id()).game_vertex_id() != i) || !l_tpAI_Map->inside(m_tpGraph->vertex(i)->level_vertex_id(),m_tpGraph->vertex(i)->level_point()))) { Msg ("! Graph doesn't correspond to the cross table"); R_ASSERT2 (false,"Graph doesn't correspond to the cross table"); } } m_tpVertices.resize (m_tpGraph->header().vertex_count()); GRAPH_VERTEX_IT B = m_tpVertices.begin(); GRAPH_VERTEX_IT I = B; GRAPH_VERTEX_IT E = m_tpVertices.end(); for ( ; I != E; I++) { (*I).tLocalPoint = m_tpGraph->vertex(int(I - B))->level_point(); (*I).tGlobalPoint.add (m_tpGraph->vertex(int(I - B))->game_point(),m_tLevel.offset()); (*I).tLevelID = dwLevelID; (*I).tNodeID = m_tpGraph->vertex(int(I - B))->level_vertex_id(); Memory.mem_copy ((*I).tVertexTypes,m_tpGraph->vertex(int(I - B))->vertex_type(),GameGraph::LOCATION_TYPE_COUNT*sizeof(GameGraph::_LOCATION_ID)); (*I).tNeighbourCount = m_tpGraph->vertex(int(I - B))->edge_count(); CGameGraph::const_iterator b,i,e; m_tpGraph->begin (int(I - B),i,e); (*I).tpaEdges = (CGameGraph::CEdge*)xr_malloc((*I).tNeighbourCount*sizeof(CGameGraph::CEdge)); b = i; for ( ; i != e; ++i) { GameGraph::CEdge &edge = (*I).tpaEdges[i - b]; edge = *i; VERIFY ((edge.vertex_id() + dwOffset) < (u32(1) << (8*sizeof(GameGraph::_GRAPH_ID)))); edge.m_vertex_id = (GameGraph::_GRAPH_ID)(edge.m_vertex_id + dwOffset); } (*I).dwPointOffset = 0; vfGenerateDeathPoints (int(I - B),l_tpCrossTable,l_tpAI_Map,(*I).tDeathPointCount); } xr_delete (l_tpCrossTable); xr_delete (l_tpAI_Map); // updating cross-table { strcpy_s (caFileName,raw_cross_table_file_name); CGameLevelCrossTable *tpCrossTable = new CGameLevelCrossTable(caFileName); xr_vector<CGameLevelCrossTable::CCell> tCrossTableUpdate; tCrossTableUpdate.resize(tpCrossTable->header().level_vertex_count()); for (int i=0; i<(int)tpCrossTable->header().level_vertex_count(); i++) { tCrossTableUpdate[i] = tpCrossTable->vertex(i); VERIFY (u32(tCrossTableUpdate[i].tGraphIndex) < tpCrossTable->header().game_vertex_count()); tCrossTableUpdate[i].tGraphIndex = tCrossTableUpdate[i].tGraphIndex + (GameGraph::_GRAPH_ID)dwOffset; } CGameLevelCrossTable::CHeader tCrossTableHeader; tCrossTableHeader.dwVersion = XRAI_CURRENT_VERSION; tCrossTableHeader.dwNodeCount = tpCrossTable->m_tCrossTableHeader.dwNodeCount; tCrossTableHeader.dwGraphPointCount = tpCrossTable->m_tCrossTableHeader.dwGraphPointCount; tCrossTableHeader.m_level_guid = tpCrossTable->m_tCrossTableHeader.m_level_guid; tCrossTableHeader.m_game_guid = tGraphHeader.m_guid; xr_delete (tpCrossTable); m_cross_table.w(&tCrossTableHeader,sizeof(tCrossTableHeader)); for (int i=0; i<(int)tCrossTableHeader.dwNodeCount; i++) m_cross_table.w(&(tCrossTableUpdate[i]),sizeof(tCrossTableUpdate[i])); } // fill vertex map { string_path fName; strconcat (sizeof(fName),fName,S,"level.spawn"); IReader *F = FS.r_open(fName); u32 id; IReader *O = F->open_chunk_iterator(id); for (int i=0; O; O = F->open_chunk_iterator(id,O)) { NET_Packet P; P.B.count = O->length(); O->r (P.B.data,P.B.count); u16 ID; P.r_begin (ID); R_ASSERT (M_SPAWN==ID); P.r_stringZ (fName); CSE_Abstract *E = F_entity_Create(fName); R_ASSERT3 (E,"Can't create entity.",fName); // E->Spawn_Read (P); CSE_ALifeGraphPoint *tpGraphPoint = smart_cast<CSE_ALifeGraphPoint*>(E); if (tpGraphPoint) { E->Spawn_Read (P); Fvector tVector; tVector = tpGraphPoint->o_Position; GameGraph::_GRAPH_ID tGraphID = GameGraph::_GRAPH_ID(-1); float fMinDistance = 1000000.f; { GRAPH_VERTEX_IT B = m_tpVertices.begin(); GRAPH_VERTEX_IT I = B; GRAPH_VERTEX_IT E = m_tpVertices.end(); for ( ; I != E; I++) { float fDistance = (*I).tLocalPoint.distance_to(tVector); if (fDistance < fMinDistance) { fMinDistance = fDistance; tGraphID = GameGraph::_GRAPH_ID(I - B); if (fMinDistance < EPS_L) break; } } } if (fMinDistance < EPS_L) { SConnectionVertex T; LPSTR S; S = xr_strdup(tpGraphPoint->name_replace()); T.caConnectName = xr_strdup(*tpGraphPoint->m_caConnectionPointName); T.dwLevelID = dwfGetIDByLevelName(Ini,*tpGraphPoint->m_caConnectionLevelName); // T.tGraphID = (GameGraph::_GRAPH_ID)i; // T.tOldGraphID = tGraphID; T.tOldGraphID = (GameGraph::_GRAPH_ID)i; T.tGraphID = tGraphID; bool ok = true; VERTEX_MAP::const_iterator II = m_tVertexMap.begin(); VERTEX_MAP::const_iterator EE = m_tVertexMap.end(); for ( ; II != EE; ++II) if (T.tOldGraphID == (*II).second.tOldGraphID) { ok = false; Msg ("Graph point %s is removed,because it has the same position as some another graph point",E->name_replace()); break; } if (ok) { m_tVertexMap.insert (mk_pair(S,T)); i++; } } } F_entity_Destroy (E); } if (i != m_tpGraph->header().vertex_count()) Msg ("Graph for the level %s doesn't correspond to the graph points from Level Editor! (%d : %d)",*m_tLevel.name(),i,m_tpGraph->header().vertex_count()); VERTEX_MAP::const_iterator I = m_tVertexMap.begin(); VERTEX_MAP::const_iterator E = m_tVertexMap.end(); for ( ; I != E; ++I) { R_ASSERT3 (!xr_strlen((*I).second.caConnectName) || ((*I).second.tGraphID < m_tpVertices.size()),"Rebuild graph for the level",*m_tLevel.name()); } // VERIFY3 (i == m_tpGraph->header().vertex_count(), "Rebuild graph for the level ",m_tLevel.name()); O->close (); FS.r_close (F); } };
void CKinematics::Load(const char* N, IReader *data, u32 dwFlags) { //Msg ("skeleton: %s",N); inherited::Load (N, data, dwFlags); pUserData = NULL; m_lod = NULL; // loading lods IReader* LD = data->open_chunk(OGF_S_LODS); if (LD) { string_path short_name; strcpy_s (short_name,sizeof(short_name),N); if (strext(short_name)) *strext(short_name)=0; // From stream { string_path lod_name; LD->r_string (lod_name, sizeof(lod_name)); //. strconcat (sizeof(name_load),name_load, short_name, ":lod:", lod_name.c_str()); m_lod = ::Render->model_CreateChild(lod_name, NULL); VERIFY3(m_lod,"Cant create LOD model for", N); //. VERIFY2 (m_lod->Type==MT_HIERRARHY || m_lod->Type==MT_PROGRESSIVE || m_lod->Type==MT_NORMAL,lod_name.c_str()); /* strconcat (name_load, short_name, ":lod:1"); m_lod = ::Render->model_CreateChild(name_load,LD); VERIFY (m_lod->Type==MT_SKELETON_GEOMDEF_PM || m_lod->Type==MT_SKELETON_GEOMDEF_ST); */ } LD->close (); } #ifndef _EDITOR // User data IReader* UD = data->open_chunk(OGF_S_USERDATA); pUserData = UD?xr_new<CInifile>(UD,FS.get_path("$game_config$")->m_Path):0; if (UD) UD->close(); #endif // Globals bone_map_N = xr_new<accel> (); bone_map_P = xr_new<accel> (); bones = xr_new<vecBones> (); bone_instances = NULL; // Load bones #pragma todo("container is created in stack!") xr_vector<shared_str> L_parents; R_ASSERT (data->find_chunk(OGF_S_BONE_NAMES)); visimask.zero (); int dwCount = data->r_u32(); // Msg ("!!! %d bones",dwCount); // if (dwCount >= 64) Msg ("!!! More than 64 bones is a crazy thing! (%d), %s",dwCount,N); VERIFY3 (dwCount < 64, "More than 64 bones is a crazy thing!",N); for (; dwCount; dwCount--) { string256 buf; // Bone u16 ID = u16(bones->size()); data->r_stringZ (buf,sizeof(buf)); strlwr(buf); CBoneData* pBone = CreateBoneData(ID); pBone->name = shared_str(buf); pBone->child_faces.resize (children.size()); bones->push_back (pBone); bone_map_N->push_back (mk_pair(pBone->name,ID)); bone_map_P->push_back (mk_pair(pBone->name,ID)); // It's parent data->r_stringZ (buf,sizeof(buf)); strlwr(buf); L_parents.push_back (buf); data->r (&pBone->obb,sizeof(Fobb)); visimask.set (u64(1)<<ID,TRUE); } std::sort (bone_map_N->begin(),bone_map_N->end(),pred_sort_N); std::sort (bone_map_P->begin(),bone_map_P->end(),pred_sort_P); // Attach bones to their parents iRoot = BI_NONE; for (u32 i=0; i<bones->size(); i++) { shared_str P = L_parents[i]; CBoneData* B = (*bones)[i]; if (!P||!P[0]) { // no parent - this is root bone R_ASSERT (BI_NONE==iRoot); iRoot = u16(i); B->SetParentID(BI_NONE); continue; } else { u16 ID = LL_BoneID(P); R_ASSERT (ID!=BI_NONE); (*bones)[ID]->children.push_back(B); B->SetParentID(ID); } } R_ASSERT (BI_NONE != iRoot); // Free parents L_parents.clear(); // IK data IReader* IKD = data->open_chunk(OGF_S_IKDATA); if (IKD){ for (u32 i=0; i<bones->size(); i++) { CBoneData* B = (*bones)[i]; u16 vers = (u16)IKD->r_u32(); IKD->r_stringZ (B->game_mtl_name); IKD->r (&B->shape,sizeof(SBoneShape)); B->IK_data.Import(*IKD,vers); Fvector vXYZ,vT; IKD->r_fvector3 (vXYZ); IKD->r_fvector3 (vT); B->bind_transform.setXYZi(vXYZ); B->bind_transform.translate_over(vT); B->mass = IKD->r_float(); IKD->r_fvector3 (B->center_of_mass); } // calculate model to bone converting matrix (*bones)[LL_GetBoneRoot()]->CalculateM2B(Fidentity); IKD->close(); } // after load process { for (u16 child_idx=0; child_idx<(u16)children.size(); child_idx++) LL_GetChild(child_idx)->AfterLoad (this,child_idx); } // unique bone faces { for (u32 bone_idx=0; bone_idx<bones->size(); bone_idx++) { CBoneData* B = (*bones)[bone_idx]; for (u32 child_idx=0; child_idx<children.size(); child_idx++){ CBoneData::FacesVec faces = B->child_faces[child_idx]; std::sort (faces.begin(),faces.end()); CBoneData::FacesVecIt new_end = std::unique(faces.begin(),faces.end()); faces.erase (new_end,faces.end()); B->child_faces[child_idx].clear_and_free(); B->child_faces[child_idx] = faces; } } } // reset update_callback Update_Callback = NULL; // reset update frame wm_frame = u32(-1); LL_Validate (); }