void Game::DeleteObjects() { m_pConsole->DestroyContext(); delete IObjectUtils::GetUniqueObject( "MainObject" ); #ifdef _DEBUG // Do a check to verify that all objects have been destroyed at this point int totalObjectCount = 0; AUDynArray<IObjectConstructor*> constructors; m_pEnv->sys->pObjectFactorySystem->GetAll(constructors); for (size_t i=0; i<constructors.Size(); ++i) { IObjectConstructor* pConstructor = constructors[i]; size_t count = pConstructor->GetNumberConstructedObjects(); // Need to iterate through all objects and check if they're valid // since GetNumConstructedObjects isn't accurate, can return some null pointers for (size_t j=0; j<count; ++j) { if (pConstructor->GetConstructedObject(j) != NULL) { totalObjectCount++; } } // Do an assert check here so it's easy to figure out which object type wasn't deleted AU_ASSERT( totalObjectCount == 0 ); } #endif }
void EntitySystem::Reset() { AUDynArray<AUEntityId> entities; GetAll(entities); for (size_t i = 0; i < entities.Size(); ++i) { Destroy(entities[i]); } assert(m_Entities.size() == 0); }
bool Game::ProtectedUpdate(AUDynArray<AUEntityId> &entities, float fDeltaTime) { bool bSuccess = true; assert(!m_bHaveProgramError); __try { for (size_t i=0; i<entities.Size(); ++i) { IAUEntity* pEnt = m_pEnv->sys->pEntitySystem->Get(entities[i]); if (pEnt) // Safety check in case entity was deleted during this update by another object { IAUUpdateable* pUpdateable = pEnt->GetUpdateable(); if (pUpdateable) { // If dropped here after a runtime failure, your crash was likely // somewhere directly in the pUpdatable object's Update method pUpdateable->Update(fDeltaTime); } } } } __except( RuntimeExceptionFilter() ) { bSuccess = false; } return bSuccess; }
void AURenderContext::Render( IEntitySystem* pEntitySystem ) { //loop through setting matrices and calling render. pEntitySystem->GetAll( g_entities ); for( size_t i = 0; i < g_entities.Size(); ++i ) { IAUEntity* pEntity = pEntitySystem->Get( g_entities[ i ] ); IAURenderable* pRenderable = pEntity->GetRenderable(); if( pRenderable ) { glPushMatrix(); glMatrixMode(GL_MODELVIEW); // Translation const AUVec3f& t = pEntity->GetPosition(); glTranslatef( t.x, t.y, t.z ); // Rotation float fglMatrix[16]; pEntity->GetOrientation().LoadglObjectMatrix(fglMatrix); glMultMatrixf(fglMatrix); // Scale glEnable(GL_NORMALIZE); // Needed so normals don't get wrecked by scaling - not sure how costly it is though const AUVec3f& s = pEntity->GetScale(); glScalef( s.x, s.y, s.z ); pRenderable->Render(); glPopMatrix(); } } }
// returns 0 on success, -ve number of errors if there is an error and we should quit, // positive number of errors if there is an error but we should continue static int TestBuildFile( ICompilerLogger* pLog, RuntimeObjectSystem* pRTObjSys, const Path& file, ITestBuildNotifier* callback, bool bTestFileTracking ) { assert( callback ); if( pLog ) { pLog->LogInfo("Testing change to file: %s\n", file.c_str()); } int numErrors = 0; if( file.Exists() ) { if( bTestFileTracking ) { FileSystemUtils::filetime_t currTime = FileSystemUtils::GetCurrentTime(); FileSystemUtils::filetime_t oldModTime = file.GetLastWriteTime(); if( currTime == oldModTime ) { // some files may be auto-generated by the program, so may have just been created so won't // get a time change unless we force it. currTime += 1; } file.SetLastWriteTime( currTime ); // we must also change the directories time, as some of our watchers watch the dir Path directory = file.ParentPath(); directory.SetLastWriteTime( currTime ); for( int i=0; i<50; ++i ) { // wait up to 100 seconds (make configurable?) pRTObjSys->GetFileChangeNotifier()->Update( 1.0f ); // force update by using very large time delta if( pRTObjSys->GetIsCompiling() ) { break; } if( !callback->TestBuildWaitAndUpdate() ) { return -0xD1E; } } } else { AUDynArray<const char*> filelist; filelist.Add( file.c_str() ); pRTObjSys->OnFileChange( filelist ); } if( pRTObjSys->GetIsCompiling() ) { while( !pRTObjSys->GetIsCompiledComplete() ) { if( !callback->TestBuildWaitAndUpdate() ) { return -0xD1E; } } int numCurrLoadedModules = pRTObjSys->GetNumberLoadedModules(); if( pRTObjSys->LoadCompiledModule() ) { if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_SUCCESS ) ) { return -0xD1E; } return 0; } else { ++numErrors; if( pRTObjSys->GetNumberLoadedModules() == numCurrLoadedModules ) { if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_BUILD_FAILED ) ) { return -numErrors; } } else { // loaded the module but some other issue if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_OBJECT_SWAP_FAIL ) ) { return -numErrors; } } } } else { ++numErrors; if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_BUILD_NOT_STARTED ) ) { return -numErrors; } } } else { ++numErrors; if( !callback->TestBuildCallback( file.c_str(), TESTBUILDRRESULT_BUILD_FILE_GONE ) ) { return -numErrors; } } return numErrors; }