示例#1
0
void PDomain::Load(IReader& F)
{
	type		= PDomainEnum(F.r_u32());
	F.r_fvector3(v[0]);
	F.r_fvector3(v[1]);
	F.r_fvector3(v[2]);
}
示例#2
0
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;
}
示例#3
0
文件: glow.cpp 项目: OLR-xray/OLR-3.0
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;
}
示例#4
0
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);
    }
}
示例#5
0
void SHeliEnemy::load(IReader &input_packet)
{
	type				= (EHeliHuntState)input_packet.r_s16();
	input_packet.r_fvector3	(destEnemyPos);
	destEnemyID			= input_packet.r_u32();

	fire_trail_length_des	= input_packet.r_float();
	bUseFireTrail		= !!input_packet.r_u8();
}
示例#6
0
void CBone::Load_0(IReader& F)
{
	F.r_stringZ		(name);        	xr_strlwr(name);
	F.r_stringZ		(parent_name);	xr_strlwr(parent_name);
	F.r_stringZ		(wmap);
	F.r_fvector3	(rest_offset);
	F.r_fvector3	(rest_rotate);
	rest_length		= F.r_float();
   	std::swap		(rest_rotate.x,rest_rotate.y);
    Reset			();
}
示例#7
0
void CHelicopter::load(IReader &input_packet)
{
    m_movement.load				(input_packet);
    m_body.load					(input_packet);
    m_enemy.load				(input_packet);
    input_packet.r_fvector3		(XFORM().c);
    m_barrel_dir_tolerance		= input_packet.r_float();
    UseFireTrail				(m_enemy.bUseFireTrail);//force reloar disp params


    load_data		(m_use_rocket_on_attack, input_packet);
    load_data		(m_use_mgun_on_attack, input_packet);
    load_data		(m_min_rocket_dist, input_packet);
    load_data		(m_max_rocket_dist, input_packet);
    load_data		(m_min_mgun_dist, input_packet);
    load_data		(m_max_mgun_dist, input_packet);
    load_data		(m_time_between_rocket_attack, input_packet);
    load_data		(m_syncronize_rocket, input_packet);
}
示例#8
0
void CBone::Load_1(IReader& F)
{
	R_ASSERT(F.find_chunk(BONE_CHUNK_VERSION));
	u16	ver			= F.r_u16();

    if ((ver!=0x0001)&&(ver!=BONE_VERSION))
    	return;
    
	R_ASSERT(F.find_chunk(BONE_CHUNK_DEF));
	F.r_stringZ		(name);			xr_strlwr(name);
	F.r_stringZ		(parent_name);	xr_strlwr(parent_name);
	F.r_stringZ		(wmap);

	R_ASSERT(F.find_chunk(BONE_CHUNK_BIND_POSE));
	F.r_fvector3	(rest_offset);
	F.r_fvector3	(rest_rotate);
	rest_length		= F.r_float();

    if (ver==0x0001)
    	std::swap	(rest_rotate.x,rest_rotate.y);
    
    LoadData		(F);
}
示例#9
0
void CHitMemoryManager::load	(IReader &packet)
{
	if (!m_object->g_Alive())
		return;

	typedef CClientSpawnManager::CALLBACK_TYPE	CALLBACK_TYPE;
	CALLBACK_TYPE					callback;
	callback.bind					(&m_object->memory(),&CMemoryManager::on_requested_spawn);

	int								count = packet.r_u8();
	for (int i=0; i<count; ++i) {
		CDelayedHitObject			delayed_object;
		delayed_object.m_object_id	= packet.r_u16();

		CHitObject					&object = delayed_object.m_hit_object;
		object.m_object				= smart_cast<CEntityAlive*>(Level().Objects.net_Find(delayed_object.m_object_id));
		// object params
		object.m_object_params.m_level_vertex_id	= packet.r_u32();
		packet.r_fvector3			(object.m_object_params.m_position);
#ifdef USE_ORIENTATION
		packet.r_float				(object.m_object_params.m_orientation.yaw);
		packet.r_float				(object.m_object_params.m_orientation.pitch);
		packet.r_float				(object.m_object_params.m_orientation.roll);
#endif
		// self params
		object.m_self_params.m_level_vertex_id	= packet.r_u32();
		packet.r_fvector3			(object.m_self_params.m_position);
#ifdef USE_ORIENTATION
		packet.r_float				(object.m_self_params.m_orientation.yaw);
		packet.r_float				(object.m_self_params.m_orientation.pitch);
		packet.r_float				(object.m_self_params.m_orientation.roll);
#endif
#ifdef USE_LEVEL_TIME
		VERIFY						(Device.dwTimeGlobal >= object.m_level_time);
		object.m_level_time			= packet.r_u32();
		object.m_level_time			+= Device.dwTimeGlobal;
#endif // USE_LEVEL_TIME
#ifdef USE_LAST_LEVEL_TIME
		VERIFY						(Device.dwTimeGlobal >= object.m_last_level_time);
		object.m_last_level_time	= packet.r_u32();
		object.m_last_level_time	+= Device.dwTimeGlobal;
#endif // USE_LAST_LEVEL_TIME
#ifdef USE_FIRST_LEVEL_TIME
		VERIFY						(Device.dwTimeGlobal >= (*I).m_first_level_time);
		object.m_first_level_time	= packet.r_u32();
		object.m_first_level_time	+= Device.dwTimeGlobal;
#endif // USE_FIRST_LEVEL_TIME
		packet.r_fvector3			(object.m_direction);
		object.m_bone_index			= packet.r_u16();
		object.m_amount				= packet.r_float();

		if (object.m_object) {
			add						(object);
			continue;
		}

		m_delayed_objects.push_back	(delayed_object);

		const CClientSpawnManager::CSpawnCallback	*spawn_callback = Level().client_spawn_manager().callback(delayed_object.m_object_id,m_object->ID());
		if (!spawn_callback || !spawn_callback->m_object_callback)
			if(!g_dedicated_server)
				Level().client_spawn_manager().add	(delayed_object.m_object_id,m_object->ID(),callback);
#ifdef DEBUG
		else {
			if (spawn_callback && spawn_callback->m_object_callback) {
				VERIFY				(spawn_callback->m_object_callback == callback);
			}
		}
#endif // DEBUG
	}
}
示例#10
0
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;
}
示例#11
0
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;
}
示例#12
0
void game_sv_GameState::Create					(shared_str &options)
{
	string_path	fn_game;
	m_item_respawner.clear_respawns();
	if (FS.exist(fn_game, "$level$", "level.game")) 
	{
		IReader *F = FS.r_open	(fn_game);
		IReader *O = 0;

		// Load RPoints
		if (0!=(O = F->open_chunk	(RPOINT_CHUNK)))
		{ 
			for (int id=0; O->find_chunk(id); ++id)
			{
				RPoint					R;
				u8						team;
				u8						type;
				u16						GameType;
				shared_str				rp_profile;

				O->r_fvector3			(R.P);
				O->r_fvector3			(R.A);
				team					= O->r_u8	();	
				type					= O->r_u8	();
				GameType				= O->r_u16	();
				if(type==rptItemSpawn)
					O->r_stringZ		(rp_profile);

				if (GameType != EGameIDs(u16(-1)))
				{
					if ((Type() == eGameIDCaptureTheArtefact) && (GameType & eGameIDCaptureTheArtefact))
					{
						team = team - 1;
						R_ASSERT2( ((team >= 0) && (team < 4)) || 
							(type != rptActorSpawn), 
							"Problem with CTA Team indexes. Propably you have added rpoint of team 0 for cta game type.");
					}
					if ((!(GameType & eGameIDDeathmatch) && (Type() == eGameIDDeathmatch)) ||
						(!(GameType & eGameIDTeamDeathmatch) && (Type() == eGameIDTeamDeathmatch))	||
						(!(GameType & eGameIDArtefactHunt) && (Type() == eGameIDArtefactHunt)) ||
						(!(GameType & eGameIDCaptureTheArtefact) && (Type() == eGameIDCaptureTheArtefact))
						)
					{
						continue;
					};
				};
				switch (type)
				{
				case rptActorSpawn:
					{
						rpoints[team].push_back	(R);
						for (int i=0; i<int(rpoints[team].size())-1; i++)
						{
							RPoint rp = rpoints[team][i];
							float dist = R.P.distance_to_xz(rp.P)/2;
							if (dist<rpoints_MinDist[team])
								rpoints_MinDist[team] = dist;
							dist = R.P.distance_to(rp.P)/2;
							if (dist<rpoints_Dist[team])
								rpoints_Dist[team] = dist;
						};
					}break;
				case rptItemSpawn:
					{
						m_item_respawner.add_new_rpoint(rp_profile, R);
					}
				};
			};
			O->close();
		}

		FS.r_close	(F);
	}

	if (!g_dedicated_server)
	{
		// loading scripts
		ai().script_engine().remove_script_process(ScriptEngine::eScriptProcessorGame);
		string_path					S;
		FS.update_path				(S,"$game_config$","script.ltx");
		CInifile					*l_tpIniFile = xr_new<CInifile>(S);
		R_ASSERT					(l_tpIniFile);

		if( l_tpIniFile->section_exist( type_name() ) )
			if (l_tpIniFile->r_string(type_name(),"script"))
				ai().script_engine().add_script_process(ScriptEngine::eScriptProcessorGame,xr_new<CScriptProcess>("game",l_tpIniFile->r_string(type_name(),"script")));
			else
				ai().script_engine().add_script_process(ScriptEngine::eScriptProcessorGame,xr_new<CScriptProcess>("game",""));

		xr_delete					(l_tpIniFile);
	}

	//---------------------------------------------------------------------
	ConsoleCommands_Create();
	//---------------------------------------------------------------------
//	CCC_LoadCFG_custom*	pTmp = xr_new<CCC_LoadCFG_custom>("sv_");
//	pTmp->Execute				(Console->ConfigFile);
//	xr_delete					(pTmp);
	//---------------------------------------------------------------------
	LPCSTR		svcfg_ltx_name = "-svcfg ";
	if (strstr(Core.Params, svcfg_ltx_name))
	{
		string_path svcfg_name = "";
		int		sz = xr_strlen(svcfg_ltx_name);
		sscanf		(strstr(Core.Params,svcfg_ltx_name)+sz,"%[^ ] ",svcfg_name);
//		if (FS.exist(svcfg_name))
		{
			Console->ExecuteScript(svcfg_name);
		}
	};
	//---------------------------------------------------------------------
	ReadOptions(options);	
}
示例#13
0
//-----------------------------------------------------------------------
BOOL motions_value::load		(LPCSTR N, IReader *data, vecBones* bones)
{

	m_id						= N;

	bool bRes					= true;
	// Load definitions
	U16Vec rm_bones				(bones->size(),BI_NONE);
	IReader* MP 				= data->open_chunk(OGF_S_SMPARAMS);

	if (MP)
	{
		u16 vers 				= MP->r_u16();
		u16 part_bone_cnt		= 0;
		string128 				buf;
		R_ASSERT3				(vers<=xrOGF_SMParamsVersion,"Invalid OGF/OMF version:",N);
		
		// partitions
		u16						part_count;
		part_count 				= MP->r_u16();

		for (u16 part_i=0; part_i<part_count; part_i++)
		{
			CPartDef& PART		= m_partition[part_i];
			MP->r_stringZ		(buf,sizeof(buf));
			PART.Name			= _strlwr(buf);
			PART.bones.resize	(MP->r_u16());

			for (xr_vector<u32>::iterator b_it=PART.bones.begin(); b_it<PART.bones.end(); b_it++)
			{
				MP->r_stringZ	(buf,sizeof(buf));
				u16 m_idx 		= u16			(MP->r_u32());
				*b_it			= find_bone_id	(bones,buf);
#ifdef _EDITOR
				if (*b_it==BI_NONE )
                {
					bRes		= false;
					Msg			("! Can't find bone: '%s'", buf);
				}

				if (rm_bones.size() <= m_idx)
                {
					bRes		= false;
					Msg			("! Can't load: '%s' invalid bones count", N);
				}
#else
				VERIFY3			(*b_it!=BI_NONE,"Can't find bone:", buf);
#endif
				if (bRes)		rm_bones[m_idx] = u16(*b_it);
			}
			part_bone_cnt		= u16(part_bone_cnt + (u16)PART.bones.size());
		}

#ifdef _EDITOR
		if (part_bone_cnt!=(u16)bones->size()){
			bRes = false;
			Msg("! Different bone count[%s] [Object: '%d' <-> Motions: '%d']", N, bones->size(),part_bone_cnt);
		}
#else
		VERIFY3(part_bone_cnt==(u16)bones->size(),"Different bone count '%s'",N);
#endif
		if (bRes)
		{
			// motion defs (cycle&fx)
			u16 mot_count			= MP->r_u16();
            m_mdefs.resize			(mot_count);

			for (u16 mot_i=0; mot_i<mot_count; mot_i++)
			{
				MP->r_stringZ		(buf,sizeof(buf));
				shared_str nm		= _strlwr		(buf);
				u32 dwFlags			= MP->r_u32		();
				CMotionDef&	D		= m_mdefs[mot_i];
                D.Load				(MP,dwFlags,vers);
//.             m_mdefs.push_back	(D);
				
				if (dwFlags&esmFX)	
					m_fx.insert		(mk_pair(nm,mot_i));
				else				
					m_cycle.insert	(mk_pair(nm,mot_i));

                m_motion_map.insert	(mk_pair(nm,mot_i));
			}
		}
		MP->close();
	}else
	{
		xrDebug::Fatal	(DEBUG_INFO,"Old skinned model version unsupported! (%s)",N);
	}
	if (!bRes)	return false;

	// Load animation
	IReader*	MS		= data->open_chunk(OGF_S_MOTIONS);
	if (!MS) 			return false;

	u32			dwCNT	= 0;
	MS->r_chunk_safe	(0,&dwCNT,sizeof(dwCNT));
    VERIFY		(dwCNT<0x3FFF); // MotionID 2 bit - slot, 14 bit - motion index

	// set per bone motion size
	for (u32 i=0; i<bones->size(); i++)
		m_motions[bones->at(i)->name].resize(dwCNT);

	// load motions
	for (u16 m_idx=0; m_idx<(u16)dwCNT; m_idx++){
		string128			mname;
		R_ASSERT			(MS->find_chunk(m_idx+1));             
		MS->r_stringZ		(mname,sizeof(mname));
#ifdef _DEBUG        
		// sanity check
		xr_strlwr			(mname);
        accel_map::iterator I= m_motion_map.find(mname); 
        VERIFY3				(I!=m_motion_map.end(),"Can't find motion:",mname);
        VERIFY3				(I->second==m_idx,"Invalid motion index:",mname);
#endif
		u32 dwLen			= MS->r_u32();
		for (u32 i=0; i<bones->size(); i++){
			u16 bone_id		= rm_bones[i];
			VERIFY2			(bone_id!=BI_NONE,"Invalid remap index.");
			CMotion&		M	= m_motions[bones->at(bone_id)->name][m_idx];
			M.set_count			(dwLen);
			M.set_flags			(MS->r_u8());
            
            if (M.test_flag(flRKeyAbsent))	{
                CKeyQR* r 		= (CKeyQR*)MS->pointer();
				u32 crc_q		= crc32(r,sizeof(CKeyQR));
				M._keysR.create	(crc_q,1,r);
                MS->advance		(1 * sizeof(CKeyQR));
            }else{
                u32 crc_q		= MS->r_u32	();
                M._keysR.create	(crc_q,dwLen,(CKeyQR*)MS->pointer());
                MS->advance		(dwLen * sizeof(CKeyQR));
            }
            if (M.test_flag(flTKeyPresent))	
            {
                u32 crc_t		= MS->r_u32	();
                if(M.test_flag(flTKey16IsBit))
                {
                    M._keysT16.create	(crc_t,dwLen,(CKeyQT16*)MS->pointer());
                    MS->advance			(dwLen * sizeof(CKeyQT16));
                }else
                {
                    M._keysT8.create	(crc_t,dwLen,(CKeyQT8*)MS->pointer());
                    MS->advance			(dwLen * sizeof(CKeyQT8));
                };
                
                MS->r_fvector3	(M._sizeT);
                MS->r_fvector3	(M._initT);
            }else
            {
                MS->r_fvector3	(M._initT);
            }
		}
	}
//	Msg("Motions %d/%d %4d/%4d/%d, %s",p_cnt,m_cnt, m_load,m_total,m_r,N);
	MS->close();

	return bRes;
}
示例#14
0
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		();
}
示例#15
0
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;
}
示例#16
0
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;
}