//---------------------------------------------------------------------- void MC_TextureManager::destroy (void) { if (masterTextureNodes) { //----------------------------------------------------- // Traverses list of texture nodes and frees each one. long usedCount = 0; for (long i=0;i<MC_MAXTEXTURES;i++) masterTextureNodes[i].destroy(); // Destroy for nodes whacks GOS Handle currentUsedTextures = usedCount; //Can this have been the damned bug all along!? } gos_PushCurrentHeap(MidLevelRenderer::Heap); delete MidLevelRenderer::MLRTexturePool::Instance; MidLevelRenderer::MLRTexturePool::Instance = NULL; delete theClipper; theClipper = NULL; gos_PopCurrentHeap(); //------------------------------------------------------ // Shutdown the GOS FX and MLR. gos_PushCurrentHeap(gosFX::Heap); delete gosFX::EffectLibrary::Instance; gosFX::EffectLibrary::Instance = NULL; delete effectStream; effectStream = NULL; delete gosFX::LightManager::Instance; gosFX::LightManager::Instance = NULL; gos_PopCurrentHeap(); //------------------------------------------ // free SystemHeap Memory g_systemHeap->Free(masterTextureNodes); masterTextureNodes = NULL; g_systemHeap->Free(masterVertexNodes); masterVertexNodes = NULL; delete textureCacheHeap; textureCacheHeap = NULL; delete textureStringHeap; textureStringHeap = NULL; }
//------------------------------------------------------------------------------ // gosFX::CardCloud::CardCloud( Specification* spec, uint32_t flags ): SpinningCloud(DefaultData, spec, flags) { Check_Object(spec); //Verify(gos_GetCurrentHeap() == Heap); gos_PushCurrentHeap(MidLevelRenderer::Heap); m_cloudImplementation = new MidLevelRenderer::MLRCardCloud(spec->m_maxParticleCount); Register_Object(m_cloudImplementation); gos_PopCurrentHeap(); uint32_t index = spec->m_maxParticleCount * sizeof(Particle); m_P_vertices = Cast_Pointer(Stuff::Point3D*, &m_data[index]); index += 4 * spec->m_maxParticleCount * sizeof(Stuff::Point3D); m_P_color = Cast_Pointer(Stuff::RGBAColor*, &m_data[index]); index += spec->m_maxParticleCount * sizeof(Stuff::RGBAColor); m_P_uvs = Cast_Pointer(Stuff::Vector2DOf<float>*, &m_data[index]); m_cloudImplementation->SetData( Cast_Pointer(pcsize_t, &m_activeParticleCount), m_P_vertices, m_P_color, m_P_uvs ); }
void __stdcall TerminateGameEngine() { if(pMechlopedia) delete pMechlopedia; if(userInput) delete userInput; if(soundSystem) delete soundSystem; if(pLogData) delete pLogData; //------------------------------------------------ // shutdown the MC Texture Manager. if(mcTextureManager) { mcTextureManager->destroy(); delete mcTextureManager; mcTextureManager = nullptr; } //-------------------------------------------------------------- // End the SystemHeap and globalHeapList if(systemHeap) { systemHeap->destroy(); delete systemHeap; systemHeap = nullptr; } if(globalHeapList) { globalHeapList->destroy(); delete globalHeapList; globalHeapList = nullptr; } //---------------------------------------------------- // Shutdown the MLR and associated stuff libraries //---------------------------------------------------- gos_PushCurrentHeap(gosFX::Heap); delete effectStream; delete gosFX::LightManager::Instance; gos_PopCurrentHeap(); // //------------------- // Turn off libraries //------------------- // gosFX::TerminateClasses(); MidLevelRenderer::TerminateClasses(); Stuff::TerminateClasses(); //Redundant. Something else is shutting this down. //GOS sure does think its bad to delete something multiple times though. //Even though it simply never is! //gos_DeleteFont(gosFontHandle); gos_CloseResourceDLL(gosResourceHandle); // //-------------------------- // Turn off the fast Files //-------------------------- // FastFileFini(); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRTexturePool* MLRTexturePool::Make(MemoryStream *stream) { Check_Object(stream); gos_PushCurrentHeap(Heap); MLRTexturePool *pool = new MLRTexturePool(stream); gos_PopCurrentHeap(); return pool; }
//------------------------------------------------------------------------------ // gosFX::PointCloud* gosFX::PointCloud::Make( Specification* spec, uint32_t flags ) { Check_Object(spec); gos_PushCurrentHeap(Heap); PointCloud* cloud = new gosFX::PointCloud(spec, flags); gos_PopCurrentHeap(); return cloud; }
//------------------------------------------------------------------------------ // gosFX::PointCloud__Specification* gosFX::PointCloud__Specification::Make( Stuff::MemoryStream* stream, int32_t gfx_version ) { Check_Object(stream); gos_PushCurrentHeap(Heap); PointCloud__Specification* spec = new gosFX::PointCloud__Specification(stream, gfx_version); gos_PopCurrentHeap(); return spec; }
//------------------------------------------------------------------------------ // gosFX::ShapeCloud* gosFX::ShapeCloud::Make( Specification *spec, unsigned flags ) { Check_Object(spec); gos_PushCurrentHeap(Heap); ShapeCloud *cloud = new gosFX::ShapeCloud(spec, flags); gos_PopCurrentHeap(); return cloud; }
//------------------------------------------------------------------------------ // gosFX::Effect* gosFX::Effect::Make( Specification *spec, unsigned flags ) { Check_Object(spec); gos_PushCurrentHeap(Heap); Effect *effect = new gosFX::Effect(DefaultData, spec, flags); gos_PopCurrentHeap(); return effect; }
//------------------------------------------------------------------------------ // gosFX::Event* gosFX::Event::Make( Stuff::MemoryStream *stream, int gfx_version ) { Check_Object(stream); gos_PushCurrentHeap(Heap); Event *event = new Event(stream, gfx_version); gos_PopCurrentHeap(); return event; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLR_I_L_TMesh* MLR_I_L_TMesh::Make( MemoryStream *stream, int version ) { Check_Object(stream); gos_PushCurrentHeap(Heap); MLR_I_L_TMesh *mesh = new MLR_I_L_TMesh(DefaultData, stream, version); gos_PopCurrentHeap(); return mesh; }
//------------------------------------------------------------------------------ // gosFX::Effect__Specification* gosFX::Effect__Specification::Make( Stuff::MemoryStream *stream, int gfx_version ) { Check_Object(stream); gos_PushCurrentHeap(Heap); Effect__Specification *spec = new gosFX::Effect__Specification(EffectClassID, stream, gfx_version); gos_PopCurrentHeap(); return spec; }
//------------------------------------------------------------------------------ // void gosFX::ShapeCloud__Specification::Copy(ShapeCloud__Specification *spec) { Check_Object(this); Check_Object(spec); SpinningCloud__Specification::Copy(spec); gos_PushCurrentHeap(Heap); m_radius = spec->m_radius; m_shape = spec->m_shape; gos_PopCurrentHeap(); Check_Object(m_shape); m_shape->AttachReference(); }
//------------------------------------------------------------------------------ // void gosFX::CardCloud__Specification::Copy(CardCloud__Specification* spec) { Check_Object(this); Check_Object(spec); SpinningCloud__Specification::Copy(spec); gos_PushCurrentHeap(Heap); m_halfHeight = spec->m_halfHeight; m_aspectRatio = spec->m_aspectRatio; m_pIndex = spec->m_pIndex; m_UOffset = spec->m_UOffset; m_VOffset = spec->m_VOffset; m_USize = spec->m_USize; m_VSize = spec->m_VSize; m_animated = spec->m_animated; m_width = spec->m_width; gos_PopCurrentHeap(); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRSorter::MLRSorter(ClassData *class_data, MLRTexturePool *tp): RegisteredClass(class_data) { Verify(gos_GetCurrentHeap() == Heap); texturePool = tp; gos_PushCurrentHeap(StaticHeap); rawDrawData.SetLength(Limits::Max_Number_Primitives_Per_Frame); #ifdef CalDraw for(int i=0;i<MLRState::PriorityCount;i++) { lastUsedInBucketNotDrawn[i] = 0; priorityBucketsNotDrawn[i].SetLength(Limits::Max_Number_Primitives_Per_Frame + Limits::Max_Number_ScreenQuads_Per_Frame); } drawData.SetLength(Limits::Max_Number_Primitives_Per_Frame); #endif gos_PopCurrentHeap(); }
//------------------------------------------------------------------------------ // gosFX::Card::Card( Specification *spec, unsigned flags ): Singleton(DefaultData, spec, flags), m_cardCount(1) { Check_Object(spec); Verify(gos_GetCurrentHeap() == Heap); gos_PushCurrentHeap(MidLevelRenderer::Heap); m_cardCloud = new MidLevelRenderer::MLRCardCloud(1); Register_Object(m_cardCloud); gos_PopCurrentHeap(); m_cardCloud->SetData( &m_cardCount, m_vertices, m_colors, m_uvs ); }
//------------------------------------------------------------------------------ // void gosFX::Effect__Specification::Copy(Effect__Specification *spec) { Check_Object(this); Check_Object(spec); gos_PushCurrentHeap(Heap); Verify(spec->m_class == m_class); m_name = spec->m_name; // //---------------------------------------------- // Copy the events after delete our current ones //---------------------------------------------- // Stuff::ChainIteratorOf<Event*> old_events(&m_events); old_events.DeletePlugs(); Stuff::ChainIteratorOf<Event*> new_events(&spec->m_events); Event* event; while ((event = new_events.ReadAndNext()) != NULL) { Check_Object(event); Event *new_event = new Event(*event); Register_Object(new_event); AdoptEvent(new_event); } // //--------------------------------------------------- // Now copy the curves, variance modes, and MLR state //--------------------------------------------------- // m_lifeSpan = spec->m_lifeSpan; m_minimumChildSeed = spec->m_minimumChildSeed; m_maximumChildSeed = spec->m_maximumChildSeed; m_state = spec->m_state; gos_PopCurrentHeap(); }
//------------------------------------------------------------------------------ // void gosFX::ParticleCloud__Specification::Copy(ParticleCloud__Specification *spec) { Check_Object(this); Check_Object(spec); Verify(gos_GetCurrentHeap() == Heap); Effect__Specification::Copy(spec); // //---------------- // Copy the curves //---------------- // gos_PushCurrentHeap(Heap); m_startingPopulation = spec->m_startingPopulation; m_particlesPerSecond = spec->m_particlesPerSecond; m_emitterSizeX = spec->m_emitterSizeX; m_emitterSizeY = spec->m_emitterSizeY; m_emitterSizeZ = spec->m_emitterSizeZ; m_minimumDeviation = spec->m_minimumDeviation; m_maximumDeviation = spec->m_maximumDeviation; m_startingSpeed = spec->m_startingSpeed; m_pLifeSpan = spec->m_pLifeSpan; m_pEtherVelocityX = spec->m_pEtherVelocityX; m_pEtherVelocityY = spec->m_pEtherVelocityY; m_pEtherVelocityZ = spec->m_pEtherVelocityZ; m_pAccelerationX = spec->m_pAccelerationX; m_pAccelerationY = spec->m_pAccelerationY; m_pAccelerationZ = spec->m_pAccelerationZ; m_pDrag = spec->m_pDrag; m_pRed = spec->m_pRed; m_pGreen = spec->m_pGreen; m_pBlue = spec->m_pBlue; m_pAlpha = spec->m_pAlpha; m_maxParticleCount = spec->m_maxParticleCount; gos_PopCurrentHeap(); }
inline GOSVertexPool::GOSVertexPool() { Verify(gos_GetCurrentHeap() == Heap); lastUsed = 0; lastUsed2uv = 0; lastUsedIndex = 0; gos_PushCurrentHeap(StaticHeap); vertices.SetLength(Limits::Max_Number_Vertices_Per_Frame+4*Limits::Max_Number_ScreenQuads_Per_Frame+1); vertices2uv.SetLength(Limits::Max_Number_Vertices_Per_Frame+4*Limits::Max_Number_ScreenQuads_Per_Frame+1); indices.SetLength(Limits::Max_Number_Vertices_Per_Frame+16); verticesDB.SetLength(2*Limits::Max_Number_Vertices_Per_Mesh); vertices2uvDB.SetLength(2*Limits::Max_Number_Vertices_Per_Mesh); indicesDB.SetLength(2*Limits::Max_Number_Vertices_Per_Mesh); gos_PopCurrentHeap(); vertexAlignment=32-( (int)vertices.GetData() & 31 ); vertexAlignment2uv=32-( (int)vertices2uv.GetData() & 31 ); indicesAlignment=32-( (int)indices.GetData() & 31 ); }
//------------------------------------------------------------------------------ // gosFX::PointCloud::PointCloud( Specification* spec, uint32_t flags ): ParticleCloud(DefaultData, spec, flags) { Check_Object(spec); //Verify(gos_GetCurrentHeap() == Heap); gos_PushCurrentHeap(MidLevelRenderer::Heap); m_cloudImplementation = new MidLevelRenderer::MLRPointCloud(spec->m_maxParticleCount); Register_Object(m_cloudImplementation); gos_PopCurrentHeap(); uint32_t index = spec->m_maxParticleCount * sizeof(Particle); m_P_localTranslation = Cast_Pointer(Stuff::Point3D*, &m_data[index]); index += spec->m_maxParticleCount * sizeof(Stuff::Point3D); m_P_color = Cast_Pointer(Stuff::RGBAColor*, &m_data[index]); m_cloudImplementation->SetData( Cast_Pointer(pcsize_t, &m_activeParticleCount), m_P_localTranslation, m_P_color ); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // DatabaseHandle::DatabaseHandle( const char* filename, bool read_only ) { // //----------------------------------------------------- // Create the database heap if it doesn't already exist //----------------------------------------------------- // m_fileName = filename; if (!Database::FilesOpened++) Database_Heap = gos_CreateMemoryHeap("Database", 0); gos_PushCurrentHeap(Database_Heap); m_currentRecord = 0; m_currentPointer = NULL; m_dirtyFlag = false; // //-------------------------------------------- // If the file is read only, our job is simple //-------------------------------------------- // m_readOnly = read_only; if (m_readOnly) { if (gos_DoesFileExist(filename)) { FileStream::IsRedirected = false; DWORD size; m_handle = gos_OpenMemoryMappedFile( filename, reinterpret_cast<BYTE**>(&m_dataBase), &size ); if (m_dataBase->m_tag != Database::e_Tag) STOP(("Invalid database file \"%s\"", filename)); if (m_dataBase->m_version > Database::e_Version) STOP(("Application must be recompiled to use database \"%s\"", filename)); m_baseAddress = reinterpret_cast<DWORD>(m_dataBase); Check_Object(m_dataBase); } else STOP(("Database \"%s\" does not exist", filename)); } // //------------------------------------------------------------- // The file is not read only, so see if we load it or create it //------------------------------------------------------------- // else { m_handle = NULL; if (gos_DoesFileExist(filename)) { DWORD size; gos_GetFile( filename, reinterpret_cast<BYTE**>(&m_dataBase), &size ); FileStream::IsRedirected = false; Check_Pointer(m_dataBase); if (m_dataBase->m_tag != Database::e_Tag || m_dataBase->m_version > Database::e_Version || m_dataBase->m_version == 1) { gos_Free(m_dataBase); PAUSE(("Bad database file! Press 'Continue' to rebuild", filename)); m_dataBase = new(gos_Malloc(sizeof(Database), Database_Heap)) Database; m_baseAddress = 0; } else { m_baseAddress = reinterpret_cast<DWORD>(m_dataBase); Check_Object(m_dataBase); } } // //------------------------------------------ // The file doesn't exist, so create it here //------------------------------------------ // else { m_dataBase = new(gos_Malloc(sizeof(Database), Database_Heap)) Database; m_baseAddress = 0; } } gos_PopCurrentHeap(); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void RecordHandle::Replace() { Check_Object(this); gos_PushCurrentHeap(Database_Heap); // //------------------ // Find our database //------------------ // Check_Object(m_databaseHandle); Verify(!m_databaseHandle->m_readOnly); m_databaseHandle->m_dirtyFlag = true; // //---------------------- // Unhook the old record //---------------------- // Check_Object(m_record); const_cast<Record*>(m_record)->Unhook(this); // //--------------------------------------------------- // Figure out how long the name is and its hash value //--------------------------------------------------- // DWORD record_hash, name_length; if (m_name) { record_hash = GenerateHash(m_name); name_length = strlen(m_name); Verify(name_length > 0); } else { record_hash = 0; name_length = 0; } // //------------------ // Set up the record //------------------ // Record *data = new(new BYTE[sizeof(*m_record) + m_length + name_length]) Record(this, record_hash, name_length); Check_Object(data); m_data = &data->m_name[name_length+1]; if (m_name) m_name = data->m_name; m_timeStamp = data->m_lastModified; // //------------------ // Update statistics //------------------ // if (m_record->m_mustFree) delete const_cast<Record*>(m_record); m_record = data; gos_PopCurrentHeap(); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void RecordHandle::Add() { Check_Object(this); gos_PushCurrentHeap(Database_Heap); // //------------------ // Find our database //------------------ // Check_Object(m_databaseHandle); Verify(!m_databaseHandle->m_readOnly); m_databaseHandle->m_dirtyFlag = true; Database* db = m_databaseHandle->m_dataBase; Check_Object(db); // //------------------------------------------- // Make sure the record doesn't already exist //------------------------------------------- // Verify(!m_record); #ifdef _ARMOR if (m_name) { RecordHandle dup_check = *this; if (dup_check.FindName()) STOP(( "Duplicate Record" )); } #endif // //------------------ // Set the record index //------------------ // m_ID=db->m_nextRecordID++; // //--------------------------------------------------- // Figure out how long the name is and its hash value //--------------------------------------------------- // DWORD record_hash, name_length; if (m_name) { record_hash = GenerateHash(m_name); name_length = strlen(m_name); Verify(name_length > 0); } else { record_hash = 0; name_length = 0; } // //------------------ // Set up the record //------------------ // Verify(!m_record); Record *data = new(new BYTE[sizeof(*m_record) + m_length + name_length]) Record(this, record_hash, name_length); Check_Object(data); m_data = &data->m_name[name_length+1]; if (m_name) m_name = data->m_name; m_timeStamp = data->m_lastModified; // //------------------ // Update statistics //------------------ // m_record = data; gos_PopCurrentHeap(); }
//------------------------------------------------------------------------------ // bool gosFX::Effect::Execute(ExecuteInfo *info) { Check_Object(this); Check_Pointer(info); Verify(IsExecuted()); gos_PushCurrentHeap(Heap); // //----------------------------------------------------- // If a new seed is provided, override the current seed //----------------------------------------------------- // if (info->m_seed != -1.0f) { Verify(info->m_seed>=0.0f && info->m_seed<1.0f); m_seed = info->m_seed; } // //-------------------------------------------- // Figure out the new age and clear the bounds //-------------------------------------------- // Stuff::Scalar age = m_age + static_cast<Stuff::Scalar>(info->m_time - m_lastRan) * m_ageRate; Verify(age >= 0.0f && age >= m_age); *info->m_bounds = Stuff::OBB::Identity; // //-------------------------------- // Update the effectToWorld matrix //-------------------------------- // Check_Object(info->m_parentToWorld); m_localToWorld.Multiply(m_localToParent, *info->m_parentToWorld); // //-------------------------------------------------- // Check to see if the top event needs to be handled //-------------------------------------------------- // Check_Object(m_specification); Event *event; while ((event = m_event.GetCurrent()) != NULL) { Check_Object(event); if (event->m_time > m_age) break; // //------------------------------------------------------------- // This event needs to go, so spawn and bump the effect pointer //------------------------------------------------------------- // unsigned flags = ExecuteFlag; if ((event->m_flags&SimulationModeMask) == ParentSimulationMode) { Verify((m_flags&SimulationModeMask) != ParentSimulationMode); flags |= m_flags&SimulationModeMask; } else flags |= event->m_flags&SimulationModeMask; Effect* effect = EffectLibrary::Instance->MakeEffect( event->m_effectID, flags ); Register_Object(effect); m_children.Add(effect); m_event.Next(); // //--------------------------------------------- // Now set the info for starting the new effect //--------------------------------------------- // effect->m_localToParent = event->m_localToParent; Stuff::Scalar min_seed = m_specification->m_minimumChildSeed.ComputeValue(m_age, m_seed); Stuff::Scalar seed_range = m_specification->m_maximumChildSeed.ComputeValue(m_age, m_seed) - min_seed; Stuff::Scalar seed = Stuff::Random::GetFraction()*seed_range + min_seed; Clamp(seed, 0.0f, 1.0f); ExecuteInfo local_info( info->m_time, &m_localToWorld, NULL, seed ); effect->Start(&local_info); } // //------------------------------------------------------------ // Execute all the children. If any of them finish, kill them //------------------------------------------------------------ // Stuff::ChainIteratorOf<gosFX::Effect*> children(&m_children); gosFX::Effect *child; Stuff::OBB child_obb = Stuff::OBB::Identity; ExecuteInfo child_info( info->m_time, &m_localToWorld, &child_obb ); child_info.m_bounds = &child_obb; while ((child = children.ReadAndNext()) != NULL) { Check_Object(child); if (!child->Execute(&child_info)) { Unregister_Object(child); delete child; } // //-------------------------------------------------------------- // Merge the bounding sphere of the child into the bounds of the // parent //-------------------------------------------------------------- // Stuff::OBB parent_bounds; parent_bounds.Multiply(child_obb, m_localToParent); info->m_bounds->Union(*info->m_bounds, parent_bounds); } Check_Object(info->m_bounds); // //---------------------------------------------------------------------- // Set the new time, then if we have run the course of the effect, start // over if we loop, otherwise wait for our children to finish before // killing ourselves //---------------------------------------------------------------------- // m_lastRan = info->m_time; m_age = age; if (m_age >= 1.0f) { if (IsLooped()) Start(info); else if (HasFinished()) Kill(); } // //---------------------------------- // Tell our parent if we need to die //---------------------------------- // gos_PopCurrentHeap(); return IsExecuted(); }
//--------------------------------------------------------------------------- void __stdcall InitializeGameEngine() { gosResourceHandle = gos_OpenResourceDLL("mc2res.dll"); char temp[256]; cLoadString(IDS_FLOAT_HELP_FONT, temp, 255); PSTR pStr = strstr(temp, ","); if(pStr) { gosFontScale = atoi(pStr + 2); *pStr = 0; } char path [256]; strcpy(path, "assets\\graphics\\"); strcat(path, temp); gosFontHandle = gos_LoadFont(path); //------------------------------------------------------------- // Find the CDPath in the registry and save it off so I can // look in CD Install Path for files. //Changed for the shared source release, just set to current directory //uint32_t maxPathLength = 1023; //gos_LoadDataFromRegistry("CDPath", CDInstallPath, &maxPathLength); //if (!maxPathLength) // strcpy(CDInstallPath,"..\\"); strcpy(CDInstallPath, ".\\"); cLoadString(IDS_MC2_FILEMISSING, FileMissingString, 511); cLoadString(IDS_MC2_CDMISSING, CDMissingString, 1023); cLoadString(IDS_MC2_MISSING_TITLE, MissingTitleString, 255); //-------------------------------------------------------------- // Start the SystemHeap and globalHeapList globalHeapList = new HeapList; gosASSERT(globalHeapList != nullptr); globalHeapList->init(); globalHeapList->update(); //Run Instrumentation into GOS Debugger Screen systemHeap = new UserHeap; gosASSERT(systemHeap != nullptr); systemHeap->init(systemHeapSize, "SYSTEM"); float doubleClickThreshold = 0.2f; int32_t dragThreshold = .016667; //-------------------------------------------------------------- // Read in System.CFG FitIniFile systemFile; #ifdef _DEBUG int32_t systemOpenResult = #endif systemFile.open("system.cfg"); #ifdef _DEBUG if(systemOpenResult != NO_ERROR) { char Buffer[256]; gos_GetCurrentPath(Buffer, 256); STOP(("Cannot find \"system.cfg\" file in %s", Buffer)); } #endif { #ifdef _DEBUG int32_t systemBlockResult = #endif systemFile.seekBlock("systemHeap"); gosASSERT(systemBlockResult == NO_ERROR); { int32_t result = systemFile.readIdULong("systemHeapSize", systemHeapSize); result; gosASSERT(result == NO_ERROR); } #ifdef _DEBUG int32_t systemPathResult = #endif systemFile.seekBlock("systemPaths"); gosASSERT(systemPathResult == NO_ERROR); { int32_t result = systemFile.readIdString("terrainPath", terrainPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("artPath", artPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("fontPath", fontPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("savePath", savePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("spritePath", spritePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("shapesPath", shapesPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("soundPath", soundPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("objectPath", objectPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("cameraPath", cameraPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("tilePath", tilePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("missionPath", missionPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("warriorPath", warriorPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("profilePath", profilePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("interfacepath", interfacePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("moviepath", moviePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("CDsoundPath", CDsoundPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("CDmoviepath", CDmoviePath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("tglPath", tglPath, 79); gosASSERT(result == NO_ERROR); result = systemFile.readIdString("texturePath", texturePath, 79); gosASSERT(result == NO_ERROR); } #ifdef _DEBUG int32_t fastFileResult = #endif systemFile.seekBlock("FastFiles"); gosASSERT(fastFileResult == NO_ERROR); { int32_t result = systemFile.readIdLong("NumFastFiles", maxFastFiles); if(result != NO_ERROR) maxFastFiles = 0; if(maxFastFiles) { fastFiles = (FastFile**)malloc(maxFastFiles * sizeof(FastFile*)); memset(fastFiles, 0, maxFastFiles * sizeof(FastFile*)); int32_t fileNum = 0; char fastFileId[10]; char fileName[100]; sprintf(fastFileId, "File%d", fileNum); while(systemFile.readIdString(fastFileId, fileName, 99) == NO_ERROR) { bool result = FastFileInit(fileName); if(!result) STOP(("Unable to startup fastfiles. Probably an old one in the directory!!")); fileNum++; sprintf(fastFileId, "File%d", fileNum); } } } } systemFile.close(); //-------------------------------------------------------------- // Read in Prefs.cfg bool fullScreen = false; FitIniFilePtr prefs = new FitIniFile; #ifdef _DEBUG int32_t prefsOpenResult = #endif prefs->open("prefs.cfg"); gosASSERT(prefsOpenResult == NO_ERROR); { #ifdef _DEBUG int32_t prefsBlockResult = #endif prefs->seekBlock("MechCommander2"); gosASSERT(prefsBlockResult == NO_ERROR); { int32_t filterSetting; int32_t result = prefs->readIdLong("FilterState", filterSetting); if(result == NO_ERROR) { switch(filterSetting) { default: case 0: FilterState = gos_FilterNone; break; case 1: FilterState = gos_FilterBiLinear; break; case 2: FilterState = gos_FilterTriLinear; break; } } result = prefs->readIdLong("TerrainTextureRes", TERRAIN_TXM_SIZE); if(result != NO_ERROR) TERRAIN_TXM_SIZE = 64; result = prefs->readIdLong("ObjectTextureRes", ObjectTextureSize); if(result != NO_ERROR) ObjectTextureSize = 128; result = prefs->readIdLong("Brightness", gammaLevel); if(result != NO_ERROR) gammaLevel = 0; // store volume settings in global variable since soundsystem // does not exist yet. These will be set in SoundSystem::init() result = prefs->readIdLong("DigitalMasterVolume", DigitalMasterVolume); if(result != NO_ERROR) DigitalMasterVolume = 255; result = prefs->readIdLong("MusicVolume", MusicVolume); if(result != NO_ERROR) MusicVolume = 64; result = prefs->readIdLong("RadioVolume", RadioVolume); if(result != NO_ERROR) RadioVolume = 64; result = prefs->readIdLong("SFXVolume", sfxVolume); if(result != NO_ERROR) sfxVolume = 64; result = prefs->readIdFloat("DoubleClickThreshold", doubleClickThreshold); if(result != NO_ERROR) doubleClickThreshold = 0.2f; result = prefs->readIdLong("DragThreshold", dragThreshold); if(result != NO_ERROR) dragThreshold = .016667; result = prefs->readIdULong("BaseVertexColor", BaseVertexColor); if(result != NO_ERROR) BaseVertexColor = 0x00000000; result = prefs->readIdBoolean("FullScreen", fullScreen); if(result != NO_ERROR) fullScreen = true; result = prefs->readIdLong("Rasterizer", renderer); if(result != NO_ERROR) renderer = 0; if((renderer < 0) || (renderer > 3)) renderer = 0; } } prefs->close(); delete prefs; prefs = nullptr; //------------------------------- // Used to output debug stuff! // Mondo COOL! // simply do this in the code and stuff goes to the file called mc2.output // DEBUG_STREAM << thing_you_want_to_output // // IMPORTANT NOTE: Stuff::InitializeClasses(); MidLevelRenderer::InitializeClasses(8192 * 4, 1024, 0, 0, true); gosFX::InitializeClasses(); gos_PushCurrentHeap(MidLevelRenderer::Heap); MidLevelRenderer::TGAFilePool* pool = new MidLevelRenderer::TGAFilePool("data\\Effects\\"); MidLevelRenderer::MLRTexturePool::Instance = new MidLevelRenderer::MLRTexturePool(pool); MidLevelRenderer::MLRSortByOrder* cameraSorter = new MidLevelRenderer::MLRSortByOrder(MidLevelRenderer::MLRTexturePool::Instance); theClipper = new MidLevelRenderer::MLRClipper(0, cameraSorter); gos_PopCurrentHeap(); //------------------------------------------------------ // Start the GOS FX. gos_PushCurrentHeap(gosFX::Heap); gosFX::EffectLibrary::Instance = new gosFX::EffectLibrary(); Check_Object(gosFX::EffectLibrary::Instance); FullPathFileName effectsName; effectsName.init(effectsPath, "mc2.fx", ""); File effectFile; int32_t result = effectFile.open(effectsName); if(result != NO_ERROR) STOP(("Could not find MC2.fx")); int32_t effectsSize = effectFile.fileSize(); puint8_t effectsData = (puint8_t)systemHeap->Malloc(effectsSize); effectFile.read(effectsData, effectsSize); effectFile.close(); effectStream = new Stuff::MemoryStream(effectsData, effectsSize); gosFX::EffectLibrary::Instance->Load(effectStream); gosFX::LightManager::Instance = new gosFX::LightManager(); gos_PopCurrentHeap(); systemHeap->Free(effectsData); //------------------------------------------------ // Fire up the MC Texture Manager. mcTextureManager = new MC_TextureManager; mcTextureManager->start(); //Startup the vertex array pool mcTextureManager->startVertices(500000); //-------------------------------------------------- // Setup Mouse Parameters from Prefs.CFG userInput = new UserInput; userInput->init(); userInput->setMouseDoubleClickThreshold(doubleClickThreshold); userInput->setMouseDragThreshold(dragThreshold); userInput->initMouseCursors("cursors"); userInput->setMouseCursor(mState_NORMAL); userInput->mouseOn(); // now the sound system soundSystem = new GameSoundSystem; soundSystem->init(); ((SoundSystem*)soundSystem)->init("sound"); sndSystem = soundSystem; // for things in the lib that use sound soundSystem->playDigitalMusic(LOGISTICS_LOOP); pLogData = new LogisticsData; pLogData->init(); pMechlopedia = new Mechlopedia; pMechlopedia->init(); pMechlopedia->begin(); }
//------------------------------------------------------------------------------ // void gosFX::Effect::Start(ExecuteInfo *info) { Check_Object(this); Check_Pointer(info); gos_PushCurrentHeap(Heap); // //--------------------------------------------------------------------- // Don't override m_lastran if we are issuing a Start command while the // effect is already running //--------------------------------------------------------------------- // if (!IsExecuted() || m_lastRan == -1.0) m_lastRan = info->m_time; SetExecuteOn(); // //------------------------------------------- // If no seed was provided, pick one randomly //------------------------------------------- // m_seed = (info->m_seed == -1.0f) ? Stuff::Random::GetFraction() : info->m_seed; Verify(m_seed >= 0.0f && m_seed <= 1.0f); // //-------------------------------------------------------------------- // Figure out how long the emitter will live and its initial age based // upon the effect seed //-------------------------------------------------------------------- // Check_Object(m_specification); if (info->m_age == -1.0f) { Stuff::Scalar lifetime = m_specification->m_lifeSpan.ComputeValue(m_seed, 0.0f); Min_Clamp(lifetime, 0.033333f); m_ageRate = 1.0f / lifetime; m_age = 0; } else { m_age = info->m_age; m_ageRate = info->m_ageRate; Verify(m_age >= 0.0f && m_age <= 1.0f); } // //-------------------- // Set up the matrices //-------------------- // Check_Object(info->m_parentToWorld); m_localToWorld.Multiply(m_localToParent, *info->m_parentToWorld); // //------------------------- // Set up the event pointer //------------------------- // m_event.First(); gos_PopCurrentHeap(); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRShape* MLRLightMap::CreateLightMapShape() { Check_Object(stream); gos_PushCurrentHeap(Heap); MLRShape *ret = new MLRShape(20); Register_Object(ret); MLR_I_C_TMesh *ctmesh = NULL; void *ptr, *end = stream->GetPointer(); MLRClippingState currentClippingState; MLRState currentState, masterState; unsigned short stride; int i; Stuff::Point3D *coords = NULL; Stuff::RGBAColor color; Stuff::RGBAColor *colors = NULL; Vector2DScalar *texCoords = NULL; int numGOSVertices = 0; int msd; MemoryStreamData type; stream->Rewind(); ptr = stream->GetPointer(); while(ptr < end) { *stream >> msd; type = static_cast<MemoryStreamData>(msd); switch(msd) { case Matrix4D: // not this time *stream >> i; break; case ClippingState: // not this time *stream >> i; break; case MasterRenderState: // not this time masterState.Load(stream, Current_MLR_Version); break; case LightMapRenderState: { MLRState state; state.Load(stream, Current_MLR_Version); if(numGOSVertices && (state != currentState)) { if(ctmesh!=NULL) { ctmesh->SetSubprimitiveLengths(NULL, numGOSVertices/3); ctmesh->FlashClipCoords(numGOSVertices); ctmesh->FlashClipTexCoords(numGOSVertices); ctmesh->FlashClipColors(numGOSVertices); ctmesh->SetReferenceState(currentState); ctmesh->TheIndexer(numGOSVertices); ctmesh->FindFacePlanes(); ret->Add(ctmesh); ctmesh->DetachReference(); ctmesh = NULL; } } currentState = state; } break; case Polygon: { if(ctmesh == NULL) { ctmesh = new MLR_I_C_TMesh; numGOSVertices = 0; } *stream >> stride; Verify(stride==3); *stream >> color; #if COLOR_AS_DWORD DWORD argb = 0xffffffff; argb = GOSCopyColor(&color); #endif coords = (Stuff::Point3D *)stream->GetPointer(); stream->AdvancePointer(stride*sizeof(Stuff::Point3D)); texCoords = (Vector2DScalar *)stream->GetPointer(); stream->AdvancePointer(stride*sizeof(Vector2DScalar)); for(i=0;i<stride;i++,numGOSVertices++) { ctmesh->SetClipCoord(coords[i], numGOSVertices); ctmesh->SetClipTexCoord(texCoords[i], numGOSVertices); #if COLOR_AS_DWORD ctmesh->SetClipColor(argb, numGOSVertices); #else ctmesh->SetClipColor(color, numGOSVertices); #endif } } break; case PolygonWithColor: { if(ctmesh == NULL) { ctmesh = new MLR_I_C_TMesh; numGOSVertices = 0; } *stream >> stride; Verify(stride<=Limits::Max_Number_Vertices_Per_Polygon); coords = (Stuff::Point3D *)stream->GetPointer(); stream->AdvancePointer(stride*sizeof(Stuff::Point3D)); colors = (Stuff::RGBAColor *)stream->GetPointer(); stream->AdvancePointer(stride*sizeof(Stuff::RGBAColor)); texCoords = (Vector2DScalar *)stream->GetPointer(); stream->AdvancePointer(stride*sizeof(Vector2DScalar)); for(i=0;i<stride;i++,numGOSVertices++) { ctmesh->SetClipCoord(coords[i], numGOSVertices); ctmesh->SetClipTexCoord(texCoords[i], numGOSVertices); #if COLOR_AS_DWORD #error not implemented yet #else ctmesh->SetClipColor(colors[i], numGOSVertices); #endif } } break; } ptr = stream->GetPointer(); } if(ctmesh!=NULL) { ctmesh->SetSubprimitiveLengths(NULL, numGOSVertices/3); ctmesh->FlashClipCoords(numGOSVertices); ctmesh->FlashClipTexCoords(numGOSVertices); ctmesh->FlashClipColors(numGOSVertices); ctmesh->SetReferenceState(currentState); ctmesh->TheIndexer(numGOSVertices); ctmesh->FindFacePlanes(); ret->Add(ctmesh); ctmesh->DetachReference(); } gos_PopCurrentHeap(); return ret; }
//---------------------------------------------------------------------- void MC_TextureManager::flush (bool justTextures) { if (masterTextureNodes) { //----------------------------------------------------- // Traverses list of texture nodes and frees each one. long usedCount = 0; for (long i=0;i<MC_MAXTEXTURES;i++) { if (!masterTextureNodes[i].neverFLUSH) masterTextureNodes[i].destroy(); // Destroy for nodes whacks GOS Handle } currentUsedTextures = usedCount; //Can this have been the damned bug all along!? } //If we just wanted to free up RAM, just return and let the MUNGA stuff go later. if (justTextures) return; gos_PushCurrentHeap(MidLevelRenderer::Heap); delete MidLevelRenderer::MLRTexturePool::Instance; MidLevelRenderer::MLRTexturePool::Instance = NULL; delete theClipper; theClipper = NULL; gos_PopCurrentHeap(); //------------------------------------------------------ // Shutdown the GOS FX and MLR. gos_PushCurrentHeap(gosFX::Heap); delete gosFX::EffectLibrary::Instance; gosFX::EffectLibrary::Instance = NULL; delete effectStream; effectStream = NULL; delete gosFX::LightManager::Instance; gosFX::LightManager::Instance = NULL; gos_PopCurrentHeap(); //------------------------------------------------------ //Restart MLR and the GOSFx gos_PushCurrentHeap(MidLevelRenderer::Heap); MidLevelRenderer::TGAFilePool *pool = new MidLevelRenderer::TGAFilePool("data\\tgl\\128\\"); MidLevelRenderer::MLRTexturePool::Instance = new MidLevelRenderer::MLRTexturePool(pool); MidLevelRenderer::MLRSortByOrder *cameraSorter = new MidLevelRenderer::MLRSortByOrder(MidLevelRenderer::MLRTexturePool::Instance); theClipper = new MidLevelRenderer::MLRClipper(0, cameraSorter); gos_PopCurrentHeap(); //------------------------------------------------------ // ReStart the GOS FX. gos_PushCurrentHeap(gosFX::Heap); gosFX::EffectLibrary::Instance = new gosFX::EffectLibrary(); Check_Object(gosFX::EffectLibrary::Instance); FullPathFileName effectsName; effectsName.init(effectsPath,"mc2.fx",""); File effectFile; long result = effectFile.open(effectsName); if (result != NO_ERR) STOP(("Could not find MC2.fx")); long effectsSize = effectFile.fileSize(); MemoryPtr effectsData = (MemoryPtr)g_systemHeap->Malloc(effectsSize); effectFile.read(effectsData,effectsSize); effectFile.close(); effectStream = new Stuff::MemoryStream(effectsData,effectsSize); gosFX::EffectLibrary::Instance->Load(effectStream); gosFX::LightManager::Instance = new gosFX::LightManager(); gos_PopCurrentHeap(); g_systemHeap->Free(effectsData); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRTexture* MLRTexturePool::Add(const char *tn, int instance) { MString textureName(tn); int i, j, textureNameHashValue = textureName.GetHashValue(); for(i=0;i<lastHandle;i++) { int first = i<<instanceDepth; bool yo = false; for(j=first;j<first+instanceMax;j++) { if( textureArray[j] && textureArray[j]->textureNameHashValue == textureNameHashValue ) { yo = 1; } } if(yo == false) { continue; } for(j=first;j<first+instanceMax;j++) { if( textureArray[j] && textureArray[j]->instance == instance) { return textureArray[j]; } } for(j=first;j<first+instanceMax;j++) { if(!textureArray[j]) { gos_PushCurrentHeap(Heap); textureArray[j] = new MLRTexture( this, textureName, instance, j+1 ); Register_Object(textureArray[j]); gos_PopCurrentHeap(); storedTextures++; unLoadedImages = true; return textureArray[j]; } } STOP(("Asked for too much image instances !")); } int newHandle; gos_PushCurrentHeap(Heap); if(firstFreeHandle < lastFreeHandle) { newHandle = (freeHandle[firstFreeHandle&(handleMax-1)])<<instanceDepth; textureArray[newHandle] = new MLRTexture( this, textureName, instance, newHandle+1 ); storedTextures++; firstFreeHandle++; } else { Verify( ((lastHandle<<instanceDepth)+1) < MLRState::TextureMask ); newHandle = lastHandle<<instanceDepth; textureArray[newHandle] = new MLRTexture( this, textureName, instance, newHandle+1 ); storedTextures++; lastHandle++; } Register_Object(textureArray[newHandle]); gos_PopCurrentHeap(); unLoadedImages = true; return textureArray[newHandle]; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRTexture* MLRTexturePool::Add(GOSImage *image) { MString textureName; textureName = image->GetName(); int i, j, textureNameHashValue = textureName.GetHashValue(); for(i=0;i<lastHandle;i++) { int first = i<<instanceDepth; for(j=first;j<first+instanceMax;j++) { if( textureArray[j] && textureArray[j]->textureNameHashValue == textureNameHashValue ) { Verify(image == textureArray[j]->GetImage()); return textureArray[j]; // STOP(("Image allready in texture pool !")); } } } int newHandle; gos_PushCurrentHeap(Heap); if(firstFreeHandle < lastFreeHandle) { newHandle = (freeHandle[firstFreeHandle&(handleMax-1)])<<instanceDepth; textureArray[newHandle] = new MLRTexture( this, image, newHandle+1 ); storedTextures++; firstFreeHandle++; } else { Verify( ((lastHandle<<instanceDepth)+1) < MLRState::TextureMask ); newHandle = lastHandle<<instanceDepth; textureArray[newHandle] = new MLRTexture( this, image, newHandle+1 ); storedTextures++; lastHandle++; } Register_Object(textureArray[newHandle]); gos_PopCurrentHeap(); return textureArray[newHandle]; }