コード例 #1
0
ファイル: SaveGame.cpp プロジェクト: RobertBeckebans/fhDOOM
/*
 ===================
 idRestoreGame::ReadTraceModel
 ===================
 */
void idRestoreGame::ReadTraceModel( idTraceModel &trace ) {
	int j, k;

	ReadInt( (int&)trace.type );
	ReadInt( trace.numVerts );
	for ( j = 0; j < MAX_TRACEMODEL_VERTS; j++ ) {
		ReadVec3( trace.verts[j] );
	}
	ReadInt( trace.numEdges );
	for ( j = 0; j < (MAX_TRACEMODEL_EDGES+1); j++ ) {
		ReadInt( trace.edges[j].v[0] );
		ReadInt( trace.edges[j].v[1] );
		ReadVec3( trace.edges[j].normal );
	}
	ReadInt( trace.numPolys );
	for ( j = 0; j < MAX_TRACEMODEL_POLYS; j++ ) {
		ReadVec3( trace.polys[j].normal );
		ReadFloat( trace.polys[j].dist );
		ReadBounds( trace.polys[j].bounds );
		ReadInt( trace.polys[j].numEdges );
		for ( k = 0; k < MAX_TRACEMODEL_POLYEDGES; k++ ) {
			ReadInt( trace.polys[j].edges[k] );
		}
	}
	ReadVec3( trace.offset );
	ReadBounds( trace.bounds );
	ReadBool( trace.isConvex );
	// padding win32 native structs
	char tmp[3];
	file->Read( tmp, 3 );
}
コード例 #2
0
void idRestoreGame::ReadBox( idBox &box ) {
	idVec3 center, extents;
	idMat3 axis;
	ReadVec3( center );
	ReadVec3( extents );
	ReadMat3( axis );
	box = idBox( center, extents, axis );
}
コード例 #3
0
ファイル: SaveGame.cpp プロジェクト: RobertBeckebans/fhDOOM
/*
===================
idRestoreGame::ReadContactInfo
===================
*/
void idRestoreGame::ReadContactInfo( contactInfo_t &contactInfo ) {
	ReadInt( (int &)contactInfo.type );
	ReadVec3( contactInfo.point );
	ReadVec3( contactInfo.normal );
	ReadFloat( contactInfo.dist );
	ReadInt( contactInfo.contents );
	ReadMaterial( contactInfo.material );
	ReadInt( contactInfo.modelFeature );
	ReadInt( contactInfo.trmFeature );
	ReadInt( contactInfo.entityNum );
	ReadInt( contactInfo.id );
}
コード例 #4
0
/*
================
idRestoreGame::ReadRenderLight
================
*/
void idRestoreGame::ReadRenderLight( renderLight_t &renderLight ) {
	int index;
	int i;
	ReadMat3( renderLight.axis );
	ReadVec3( renderLight.origin );
	ReadInt( renderLight.suppressLightInViewID );
	ReadInt( renderLight.allowLightInViewID );
	ReadBool( renderLight.noShadows );
	ReadBool( renderLight.noSpecular );
	ReadBool( renderLight.pointLight );
	ReadBool( renderLight.parallel );
	ReadVec3( renderLight.lightRadius );
	ReadVec3( renderLight.lightCenter );
	ReadVec3( renderLight.target );
	ReadVec3( renderLight.right );
	ReadVec3( renderLight.up );
	ReadVec3( renderLight.start );
	ReadVec3( renderLight.end );
	// only idLight has a prelightModel and it's always based on the entityname, so we'll restore it there
	// ReadModel( renderLight.prelightModel );
	renderLight.prelightModel = NULL;
	ReadInt( renderLight.lightId );
	ReadMaterial( renderLight.shader );
	for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) {
		ReadFloat( renderLight.shaderParms[ i ] );
	}
	ReadInt( index );
	renderLight.referenceSound = gameSoundWorld->EmitterForIndex( index );
}
コード例 #5
0
/*
===================
idRestoreGame::ReadTrace
===================
*/
void idRestoreGame::ReadTrace( trace_t& trace )
{
	ReadFloat( trace.fraction );
	ReadVec3( trace.endpos );
	ReadMat3( trace.endAxis );
	ReadContactInfo( trace.c );
}
コード例 #6
0
/*
================
idRestoreGame::ReadRenderEntity
================
*/
void idRestoreGame::ReadRenderEntity( renderEntity_t& renderEntity )
{
	int i;
	int index;
	
	ReadModel( renderEntity.hModel );
	
	ReadInt( renderEntity.entityNum );
	ReadInt( renderEntity.bodyId );
	
	ReadBounds( renderEntity.bounds );
	
	// callback is set by class's Restore function
	renderEntity.callback = NULL;
	renderEntity.callbackData = NULL;
	
	ReadInt( renderEntity.suppressSurfaceInViewID );
	ReadInt( renderEntity.suppressShadowInViewID );
	ReadInt( renderEntity.suppressShadowInLightID );
	ReadInt( renderEntity.allowSurfaceInViewID );
	
	ReadVec3( renderEntity.origin );
	ReadMat3( renderEntity.axis );
	
	ReadMaterial( renderEntity.customShader );
	ReadMaterial( renderEntity.referenceShader );
	ReadSkin( renderEntity.customSkin );
	
	ReadInt( index );
	renderEntity.referenceSound = gameSoundWorld->EmitterForIndex( index );
	
	for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ )
	{
		ReadFloat( renderEntity.shaderParms[ i ] );
	}
	
	for( i = 0; i < MAX_RENDERENTITY_GUI; i++ )
	{
		ReadUserInterface( renderEntity.gui[ i ] );
	}
	
	// idEntity will restore "cameraTarget", which will be used in idEntity::Present to restore the remoteRenderView
	renderEntity.remoteRenderView = NULL;
	
	renderEntity.joints = NULL;
	renderEntity.numJoints = 0;
	
	ReadFloat( renderEntity.modelDepthHack );
	
	ReadBool( renderEntity.noSelfShadow );
	ReadBool( renderEntity.noShadow );
	ReadBool( renderEntity.noDynamicInteractions );
	ReadBool( renderEntity.weaponDepthHack );
	
	ReadInt( renderEntity.forceUpdate );
	
	ReadInt( renderEntity.timeGroup );
	ReadInt( renderEntity.xrayIndex );
}
コード例 #7
0
/*
================
idRestoreGame::ReadRefSound
================
*/
void idRestoreGame::ReadRefSound( refSound_t &refSound ) {
	int		index;
	ReadInt( index );
	refSound.referenceSound = gameSoundWorld->EmitterForIndex( index );
	ReadVec3( refSound.origin );
	ReadInt( refSound.listenerId );
	ReadSoundShader( refSound.shader );
	ReadFloat( refSound.diversity );
	ReadBool( refSound.waitfortrigger );
	ReadFloat( refSound.parms.minDistance );
	ReadFloat( refSound.parms.maxDistance );
	ReadFloat( refSound.parms.volume );
	ReadFloat( refSound.parms.shakes );
	ReadInt( refSound.parms.soundShaderFlags );
	ReadInt( refSound.parms.soundClass );
}
コード例 #8
0
/*
================
idRestoreGame::ReadRenderView
================
*/
void idRestoreGame::ReadRenderView( renderView_t &view ) {
	int i;
	ReadInt( view.viewID );
	ReadInt( view.x );
	ReadInt( view.y );
	ReadInt( view.width );
	ReadInt( view.height );
	ReadFloat( view.fov_x );
	ReadFloat( view.fov_y );
	ReadVec3( view.vieworg );
	ReadMat3( view.viewaxis );
	ReadBool( view.cramZNear );
	ReadInt( view.time );
	for( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) {
		ReadFloat( view.shaderParms[ i ] );
	}
}
コード例 #9
0
        bool ObjectReader::Read(std::string file_path, EG::Game::Scene *scene) {
            in.open(file_path.c_str(), std::ios::binary);

            // Read Object ID and Create Object
            unsigned int string_size = ReadUInt();
            std::string object_id = ReadString(string_size);
            object = new EG::Game::Object(object_id);
            

            // Read Transformation
            glm::mat4 transformation = ReadMat4();
            object->AddAttribute(new EG::Game::ObjectAttributeBasicTransformation(transformation));

            // Mesh/Materials
            unsigned int count = ReadUInt();
            for (unsigned int i = 0; i < count; i++) {
                EG::Graphics::RenderingMaterial *material = new EG::Graphics::RenderingMaterial();

                // Decal
                bool has_decal = ReadBool();
                if (has_decal) {
                    string_size = ReadUInt();
                    std::string decal_path = ReadString(string_size);
                    decal_path = EG::Utility::StringMethods::RemoveSpecialCharactersFromPathString(decal_path);
                    if (decal_path.size() > 2){
                        if (!(scene->GetTextureManager()->HasTexture(decal_path))){
                            scene->GetTextureManager()->AddTexture(decal_path, new EG::Graphics::Texture(decal_path));
                        }
                        material->SetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_DECAL, decal_path);
                    }
                }

                // Normal
                bool has_normal = ReadBool();
                if (has_normal) {
                    string_size = ReadUInt();
                    std::string normal_path = ReadString(string_size);
                    normal_path = EG::Utility::StringMethods::RemoveSpecialCharactersFromPathString(normal_path);
                    if (normal_path.size() > 2){
                        if (!(scene->GetTextureManager()->HasTexture(normal_path))){
                            scene->GetTextureManager()->AddTexture(normal_path, new EG::Graphics::Texture(normal_path));
                        }
                        material->SetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_NORMAL, normal_path);
                    }
                }

                // Height
                bool has_height = ReadBool();
                if (has_height) {
                    string_size = ReadUInt();
                    std::string height_path = ReadString(string_size);
                    height_path = EG::Utility::StringMethods::RemoveSpecialCharactersFromPathString(height_path);
                    if (height_path.size() > 2){
                        if (!(scene->GetTextureManager()->HasTexture(height_path))){
                            scene->GetTextureManager()->AddTexture(height_path, new EG::Graphics::Texture(height_path));
                        }
                        material->SetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_HEIGHT, height_path);
                    }
                }

                // Specular
                bool has_specular = ReadBool();
                if (has_specular) {
                    string_size = ReadUInt();
                    std::string specular_path = ReadString(string_size);
                    specular_path = EG::Utility::StringMethods::RemoveSpecialCharactersFromPathString(specular_path);
                    if (specular_path.size() > 2){
                        if (!(scene->GetTextureManager()->HasTexture(specular_path))){
                            scene->GetTextureManager()->AddTexture(specular_path, new EG::Graphics::Texture(specular_path));
                        }
                        material->SetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_SPECULAR, specular_path);
                    }
                }

                material->SetLit(ReadBool());
                material->SetCastsShadows(ReadBool());
                material->SetTranslucent(ReadBool());
                material->SetAmbient(ReadFloat());
                material->SetDiffuse(ReadFloat());
                material->SetSpecular(ReadFloat());
                material->SetSpecularExponent(ReadFloat());
                material->SetColor(ReadVec4());

                // Mesh Data
                string_size = ReadUInt();
                std::string mesh_id = ReadString(string_size);
                unsigned int vertex_count = ReadUInt();
                unsigned int strid = ReadUInt();

                float *vertices, *normals, *tex_coords, *binormals, *bitangents, *weights, *bone_indices;
                bool has_vertices = ReadBool();
                if (has_vertices) {
                    vertices = ReadFloatV(vertex_count * 4);
                }
                bool has_normals = ReadBool();
                if (has_normals) {
                    normals = ReadFloatV(vertex_count * 4);
                }
                bool has_tex_coords = ReadBool();
                if (has_tex_coords) {
                    tex_coords = ReadFloatV(vertex_count * 4);
                }
                bool has_binormals = ReadBool();
                if (has_binormals) {
                    binormals = ReadFloatV(vertex_count * 4);
                }
                bool has_bitangents = ReadBool();
                if (has_bitangents) {
                    bitangents = ReadFloatV(vertex_count * 4);
                }
                bool has_skeleton = ReadBool();
                if (has_skeleton) {
                    weights = ReadFloatV(vertex_count * 4);
                    bone_indices = ReadFloatV(vertex_count * 4);
                }

                EG::Graphics::Mesh *mesh = new EG::Graphics::Mesh(vertex_count, 4, vertices, has_vertices, tex_coords,
                                                                  has_tex_coords, normals, has_normals, binormals,
                                                                  has_binormals, bitangents, has_bitangents, weights,
                                                                  bone_indices, has_skeleton);
                scene->GetMeshManager()->Add(mesh_id, mesh);
                object->AddAttribute(new EG::Game::ObjectAttributeRenderingMesh(mesh_id, material));
            }

            // Read Animations
            bool has_animations = ReadBool();
            if (has_animations) {
                EG::Dynamics::Animations *animations = new EG::Dynamics::Animations;

                // Build Bind Pose
                unsigned int bone_count = ReadUInt();
                EG::Dynamics::Skeleton *bind_pose = new EG::Dynamics::Skeleton;
                std::map<unsigned int, unsigned int> parent_relations;
                for (unsigned int i = 0; i < bone_count; i++) {
                    unsigned int bone_id = ReadUInt();
                    unsigned int parent_bone_id = ReadUInt();
                    glm::mat4 offset = ReadMat4();
                    parent_relations[bone_id] = parent_bone_id;
                    bind_pose->AddBone(new EG::Dynamics::Bone(bone_id, offset));
                }
                std::map<unsigned int, unsigned int>::iterator riter = parent_relations.begin();
                while (riter != parent_relations.end()) {
                    unsigned int bone_id = riter->first;
                    unsigned int parent_bone_id = riter->second;
                    EG::Dynamics::Bone *bone = bind_pose->GetBone(bone_id);
                    if (parent_bone_id > 999) {
                        bind_pose->SetRoot(bone);
                    } else {
                        EG::Dynamics::Bone *parent_bone = bind_pose->GetBone(parent_bone_id);
                        parent_bone->AddChild(bone);
                    }
                    ++riter;
                }
                animations->SetBindPose(bind_pose);

                // Load Animations
                unsigned int animation_count = ReadUInt();
                for (unsigned int i = 0; i < animation_count; i++) {
                    string_size = ReadUInt();
                    std::string animation_name = ReadString(string_size);
                    float duration = ReadFloat();
                    EG::Dynamics::Animation *animation = new EG::Dynamics::Animation(animation_name, duration);
                    unsigned int bone_count = ReadUInt();
                    animation->SetBoneCount(bone_count);
                    for (unsigned int bi = 0; bi < bone_count; bi++) {
                        unsigned int bone_id = ReadUInt();

                        // Positions
                        unsigned int position_count = ReadUInt();
                        for (unsigned int pi = 0; pi < position_count; pi++) {
                            float time = ReadFloat();
                            glm::vec3 value = ReadVec3();
                            animation->AddBonePosition(bone_id, time, value);
                        }

                        // Scalings
                        unsigned int scaling_count = ReadUInt();
                        for (unsigned int si = 0; si < scaling_count; si++) {
                            float time = ReadFloat();
                            glm::vec3 value = ReadVec3();
                            animation->AddBoneScaling(bone_id, time, value);
                        }

                        // Rotations
                        unsigned int rotation_count = ReadUInt();
                        for (unsigned int ri = 0; ri < rotation_count; ri++) {
                            float time = ReadFloat();
                            glm::quat value = ReadQuat();
                            animation->AddBoneRotation(bone_id, time, value);
                        }
                    }
                    animations->Add(animation);
                }

                EG::Dynamics::AnimationState *animation_state = new EG::Dynamics::AnimationState(animations);
                object->AddAttribute(new EG::Game::ObjectAttributeControlAnimationState(animation_state));
            }

            in.close();
            return true;
        }
コード例 #10
0
void idRestoreGame::ReadBounds( idBounds &bounds ) {
	ReadVec3( bounds[0] );
	ReadVec3( bounds[1] );
}
コード例 #11
0
ファイル: MaxScene.cpp プロジェクト: joeriedel/Crow
bool MaxScene::Load(const char *filename)
{
	this->meshes.clear();
	this->mins = vec3::bogus_max;
	this->maxs = vec3::bogus_min;
	this->origin = vec3::zero;

	FILE *fp = fopen(filename, "rb");
	if (!fp)
		return false;
	
	U32 id, version;

	fread(&id, sizeof(U32), 1, fp);
	fread(&version, sizeof(U32), 1, fp);

	if (id != Id || (version < Version2 || version > Version))
	{
		fclose(fp);
		return false;
	}

	MatVec mats;
	U32 n;

	// materials.
	std::vector<std::string> matnames;

	fread(&n, sizeof(U32), 1, fp);

	for (U32 i = 0; i < n; ++i)
	{
		Material m;
		m.name = ReadString(fp);
		fread(&m.flags, sizeof(U32), 1, fp);
		
		if (m.flags & 1) // multisub
		{
			U32 z;
			fread(&z, sizeof(U32), 1, fp);
			for (U32 j = 0; j < z; ++j)
			{
				Material::Sub s;
				fread(&s.id, sizeof(U32), 1, fp);
				s.name = ReadString(fp);
				s.emitId = (UReg)matnames.size();
				matnames.push_back(s.name);
				m.subs.insert(Material::SubHash::value_type(s.id, s));
			}
		}
		else
		{
			m.emitId = (UReg)matnames.size();
			matnames.push_back(m.name);
		}
		
		mats.push_back(m);
	}

	if (version > Version2) // load cameras (tread discards all this)
	{
		fread(&n, sizeof(U32), 1, fp);
		for (U32 i = 0; i < n; ++i)
		{
			U32 unused, z;
			ReadString(fp);
			fread(&unused, sizeof(U32), 1, fp);
			fread(&unused, sizeof(U32), 1, fp);

			fread(&z, sizeof(U32), 1, fp);
			fread(&unused, sizeof(U32), 1, fp);

			for (U32 k = 0; k < z; ++k)
			{
				ReadString(fp);
				fread(&unused, sizeof(U32), 1, fp);
				fread(&unused, sizeof(U32), 1, fp);
				U32 numFrames;
				fread(&numFrames, sizeof(U32), 1, fp);
				for (U32 j = 0; j < numFrames; ++j)
				{
					fread(&unused, sizeof(U32), 1, fp);
					ReadBoneTM(fp);
					ReadString(fp);
				}
			}
		}
	}

	// entities

	fread(&n, sizeof(U32), 1, fp);

	TriModel mdl;
	
	for (U32 i = 0; i < n; ++i)
	{
		ReadString(fp);
		U32 unused;
		fread(&unused, sizeof(U32), 1, fp);
		origin += ReadVec3(fp);

		U32 z;
		fread(&z, sizeof(U32), 1, fp);

		std::vector<int> skelBoneCounts;
		skelBoneCounts.reserve(z);

		// skels.
		for (U32 j = 0; j < z; ++j)
		{
			U32 numBones;
			fread(&numBones, sizeof(U32), 1, fp);
			skelBoneCounts.push_back(numBones);

			for (U32 b = 0; b < numBones; ++b)
			{
				ReadString(fp);
				fread(&unused, sizeof(U32), 1, fp);
				ReadMat3(fp);
			}
		}

		fread(&z, sizeof(U32), 1, fp);

		for (U32 j = 0; j < z; ++j)
		{
			Material *m = 0;
			U32 flags;
			S32 skel;

			fread(&mdl.id, sizeof(int), 1, fp);
			fread(&flags, sizeof(U32), 1, fp);
			fread(&skel, sizeof(S32), 1, fp);

			if (flags & HasMaterialFlag) // has material
			{
				U32 idx;
				fread(&idx, sizeof(U32), 1, fp);
				m = &mats[idx];
			}

			/*if (flags & 0x40000000)
			{
				mdl.contents = Map::ContentsDetail;
			}
			else if (flags & 0x20000000)
			{
				mdl.contents = Map::ContentsAreaportal;
			}
			else
			{
				mdl.contents = Map::ContentsSolid;
			}

			if (!(flags & 0x00800000))
			{
				mdl.contents |= Map::ContentsNoClip;
			}

			if (!(flags & 0x00400000))
			{
				mdl.contents |= Map::ContentsNoDraw;
			}*/

			if (flags&(HasMeshFlag|HasAnimsFlag))
				ReadTriModel(fp, version, mdl, flags, skel >= 0 ? skelBoneCounts[skel] : 0);

			if (!mdl.tris.empty())
			{
				for (TriFaceVec::iterator it = mdl.tris.begin(); it != mdl.tris.end(); ++it)
				{
					if (m)
					{
						Material::SubHash::iterator sub = m->subs.find((U32)it->mat);
						if (sub != m->subs.end())
						{
							it->mat = (int)sub->second.emitId;
						}
						else
						{
							it->mat = m->emitId;
						}
					}
					else
					{
						it->mat = -1;
					}
				}

				Build(matnames, mdl, this->meshes, this->mins, this->maxs);
			}
		}
	}

	this->origin /= (float)n;

	fclose(fp);

	return true;
}