LagomActorFactory::LagomActorFactory(const std::string& name) : XMLResourceData(name), MovementSpeed(GetFloatByName(sPropMovementSpeed)), RotationSpeed(GetFloatByName(sPropRotationSpeed)), CollisionRange(GetFloatByName(sPropCollisionRange)), GroundOffset(GetFloatByName(sPropGroundOffset)), Health(GetFloatByName(sPropHealth)), HealthRegeneration(GetFloatByName(sPropHealthRegeneration)), Energy(GetFloatByName(sPropEnergy)), EnergyDischarge(GetFloatByName(sPropEnergyDischarge)), MeshScale(GetVector3ByName(sPropMeshScale)), PointValue(GetFloatByName(sPropPointValue)), ScoreValue(GetFloatByName(sPropScoreValue)), ConstructionCooldown(GetFloatByName(sPropConstructionCooldown)), Mesh(GetStringByName(sPropMesh)), Material(GetStringByName(sPropMaterial)), EnergyDischargeSize(GetFloatByName(sPropEnergyDischargeSize)), EnergyDischargeMaterial(GetStringByName(sPropEnergyDischargeMaterial)), DeathSound(GetStringByName(sPropDeathSound)), DeathParticleSize(GetIntByName(sPropDeathParticleSize)), Name(GetRootName()) { }
bool Model_OBJ_Physics_Static::LoadAsset(const std::string &name) { assert(!m_loaded); std::ifstream fromFile(name); if(!fromFile.is_open()) { std::cerr << "Could not load model file " << name << std::endl; return false; } std::string rootName(GetRootName(name)); std::vector<Vec3f> filePositions; std::vector<Vec2f> fileTexCoords; std::vector<Vec3f> fileNormals; std::vector<Vec2f> texCoords; std::vector<Vec3f> normals; // Hash map for linking indices to vertex array index for attributes std::unordered_map<IndexSet, unsigned int, IndexSet> indexToVertex; // Initial extremes m_aabb.m_lowerBound = Vec3f(9999.0f, 9999.0f, 9999.0f); m_aabb.m_upperBound = Vec3f(-9999.0f, -9999.0f, -9999.0f); int currentObj = -1; std::unordered_map<std::string, unsigned int> matReferences; while(!fromFile.eof()) { // Read line header std::string line; getline(fromFile, line); std::stringstream ss(line); std::string header; ss >> header; if(header == "v") { // Add vertex float x, y, z; ss >> x >> y >> z; filePositions.push_back(Vec3f(x, y, z)); // Expand AABB if(x < m_aabb.m_lowerBound.x) m_aabb.m_lowerBound.x = x; if(y < m_aabb.m_lowerBound.y) m_aabb.m_lowerBound.y = y; if(z < m_aabb.m_lowerBound.z) m_aabb.m_lowerBound.z = z; if(x > m_aabb.m_upperBound.x) m_aabb.m_upperBound.x = x; if(y > m_aabb.m_upperBound.y) m_aabb.m_upperBound.y = y; if(z > m_aabb.m_upperBound.z) m_aabb.m_upperBound.z = z; } else if(header == "vt")
BOOLEAN InitTileCache( ) { UINT32 cnt; GETFILESTRUCT FileInfo; INT16 sFiles = 0; gpTileCache = (TILE_CACHE_ELEMENT *)MemAlloc( sizeof( TILE_CACHE_ELEMENT ) * guiMaxTileCacheSize ); // Zero entries for ( cnt = 0; cnt < guiMaxTileCacheSize; cnt++ ) { gpTileCache[ cnt ].pImagery = NULL; gpTileCache[ cnt ].sStructRefID = -1; } guiCurTileCacheSize = 0; // OK, look for JSD files in the tile cache directory and // load any we find.... if( GetFileFirst("TILECACHE\\*.jsd", &FileInfo) ) { while( GetFileNext(&FileInfo) ) { sFiles++; } GetFileClose(&FileInfo); } // Allocate memory... if ( sFiles > 0 ) { cnt = 0; guiNumTileCacheStructs = sFiles; gpTileCacheStructInfo = (TILE_CACHE_STRUCT *)MemAlloc( sizeof( TILE_CACHE_STRUCT ) * sFiles ); // Loop through and set filenames if( GetFileFirst("TILECACHE\\*.jsd", &FileInfo) ) { while( GetFileNext(&FileInfo) ) { sprintf( gpTileCacheStructInfo[ cnt ].Filename, "TILECACHE\\%s", FileInfo.zFileName ); // Get root name GetRootName( gpTileCacheStructInfo[ cnt ].zRootName, gpTileCacheStructInfo[ cnt ].Filename ); // Load struc data.... gpTileCacheStructInfo[ cnt ].pStructureFileRef = LoadStructureFile( gpTileCacheStructInfo[ cnt ].Filename ); #ifdef JA2TESTVERSION if ( gpTileCacheStructInfo[ cnt ].pStructureFileRef == NULL ) { SET_ERROR( "Cannot load tilecache JSD: %s", gpTileCacheStructInfo[ cnt ].Filename ); } #endif if ( _stricmp( gpTileCacheStructInfo[ cnt ].zRootName, "l_dead1" ) == 0 ) { giDefaultStructIndex = cnt; } cnt++; } GetFileClose(&FileInfo); } } return( TRUE ); }
INT32 GetCachedTile( const STR8 cFilename ) { UINT32 cnt; UINT32 ubLowestIndex = 0; INT16 sMostHits = (INT16)15000; // Check to see if surface exists already for ( cnt = 0; cnt < guiCurTileCacheSize; cnt++ ) { if ( gpTileCache[ cnt ].pImagery != NULL ) { if ( _stricmp( gpTileCache[ cnt ].zName, cFilename ) == 0 ) { // Found surface, return gpTileCache[ cnt ].sHits++; return( (INT32)cnt ); } } } // Check if max size has been reached if ( guiCurTileCacheSize == guiMaxTileCacheSize ) { // cache out least used file for ( cnt = 0; cnt < guiCurTileCacheSize; cnt++ ) { if ( gpTileCache[ cnt ].sHits < sMostHits ) { sMostHits = gpTileCache[ cnt ].sHits; ubLowestIndex = cnt; } } // Bump off lowest index DeleteTileSurface( gpTileCache[ ubLowestIndex ].pImagery ); // Decrement gpTileCache[ ubLowestIndex ].sHits = 0; gpTileCache[ ubLowestIndex ].pImagery = NULL; gpTileCache[ ubLowestIndex ].sStructRefID = -1; } // If here, Insert at an empty slot // Find an empty slot for ( cnt = 0; cnt < guiMaxTileCacheSize; cnt++ ) { if ( gpTileCache[ cnt ].pImagery == NULL ) { // Insert here gpTileCache[ cnt ].pImagery = LoadTileSurface( cFilename ); if ( gpTileCache[ cnt ].pImagery == NULL ) { return( -1 ); } strcpy( gpTileCache[ cnt ].zName, cFilename ); gpTileCache[ cnt ].sHits = 1; // Get root name GetRootName( gpTileCache[ cnt ].zRootName, cFilename ); gpTileCache[ cnt ].sStructRefID = FindCacheStructDataIndex( gpTileCache[ cnt ].zRootName ); // ATE: Add z-strip info if ( gpTileCache[ cnt ].sStructRefID != -1 ) { AddZStripInfoToVObject( gpTileCache[ cnt ].pImagery->vo, gpTileCacheStructInfo[ gpTileCache[ cnt ].sStructRefID ].pStructureFileRef, TRUE, 0 ); } if ( gpTileCache[ cnt ].pImagery->pAuxData != NULL ) { gpTileCache[ cnt ].ubNumFrames = gpTileCache[ cnt ].pImagery-> pAuxData->ubNumberOfFrames; } else { gpTileCache[ cnt ].ubNumFrames = 1; } // Has our cache size increased? if ( cnt >= guiCurTileCacheSize ) { guiCurTileCacheSize = cnt + 1;; } return( cnt ); } } // Can't find one! return( -1 ); }