void CTilegenAction_EnsureRoomExists::Execute( CLayoutSystem *pLayoutSystem ) { const char *pFullRoomName = m_pRoomNameExpression ? m_pRoomNameExpression->Evaluate( pLayoutSystem->GetFreeVariables() ) : NULL; if ( !pFullRoomName ) { Log_Warning( LOG_TilegenLayoutSystem, "Room name expression invalid.\n" ); pLayoutSystem->OnError(); return; } char themeName[MAX_TILEGEN_IDENTIFIER_LENGTH]; char roomName[MAX_TILEGEN_IDENTIFIER_LENGTH]; if ( !CLevelTheme::SplitThemeAndRoom( pFullRoomName, themeName, MAX_TILEGEN_IDENTIFIER_LENGTH, roomName, MAX_TILEGEN_IDENTIFIER_LENGTH ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Could not split theme name from room (full name: %s).\n", pFullRoomName ); pLayoutSystem->OnError(); return; } CLevelTheme *pLevelTheme = CLevelTheme::FindTheme( themeName ); if ( pLevelTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", themeName ); pLayoutSystem->OnError(); return; } if ( pLevelTheme->FindRoom( roomName ) == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Room %s not found.\n", roomName ); pLayoutSystem->OnError(); return; } }
/** * \brief Take a backup of a set of file descriptors */ void *VFS_SaveHandles(int NumFDs, int *FDs) { tVFS_Handle *ret; const int max_handles = *Threads_GetMaxFD(NULL); // Check if this process has any handles if( MM_GetPhysAddr( gaUserHandles ) == 0 ) return NULL; // Allocate ret = malloc( NumFDs * sizeof(tVFS_Handle) ); if( !ret ) return NULL; if( NumFDs > max_handles ) NumFDs = max_handles; // Take copies of the handles if( FDs == NULL ) { memcpy(ret, gaUserHandles, NumFDs * sizeof(tVFS_Handle)); } else { for( int i = 0; i < NumFDs; i ++ ) { if( FDs[i] < -1 ) { Log_Warning("VFS", "VFS_SaveHandles - Slot %i error FD (%i<0), ignorning", i, FDs[i]); memset(&ret[i], 0, sizeof(tVFS_Handle)); continue ; } int fd = FDs[i] & (VFS_KERNEL_FLAG - 1); tVFS_Handle *h = VFS_GetHandle(fd); if(!h) { Log_Warning("VFS", "VFS_SaveHandles - Invalid FD 0x%x (%i) in slot %i", fd, FDs[i], i ); free(ret); return NULL; } // Log("%i: Duplicate FD %i (%p)", i, fd, h->Node); memcpy( &ret[i], h, sizeof(tVFS_Handle) ); } } // Reference nodes/mounts for( int i = 0; i < NumFDs; i ++ ) { tVFS_Handle *h = &ret[i]; // Reference node if( !h->Node ) continue ; // Debug("VFS_SaveHandles: %i %p", i, h->Node); _ReferenceNode(h->Node); h->Mount->OpenHandleCount ++; } return ret; }
void *CFreeVariableMap::GetFreeVariableDisallowNULL( const char *pName ) const { int nIndex = Find( pName ); if ( nIndex == InvalidIndex() ) { Log_Warning( LOG_TilegenLayoutSystem, "Free variable '%s' not found.\n", pName ); void *pLayoutSystem = GetFreeVariableOrNULL( "LayoutSystem" ); if ( pLayoutSystem != NULL ) { ( ( CLayoutSystem * ) pLayoutSystem )->OnError(); } return NULL; } void *pPtr = Element( nIndex ); if ( pPtr == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Free variable '%s' found, but value is NULL or 0.\n", pName ); void *pLayoutSystem = GetFreeVariableOrNULL( "LayoutSystem" ); if ( pLayoutSystem != NULL ) { ( ( CLayoutSystem * ) pLayoutSystem )->OnError(); } } return pPtr; }
void CTilegenAction_LoadLayout::Execute( CLayoutSystem *pLayoutSystem ) { CMapLayout *pMapLayout = new CMapLayout(); if ( !pMapLayout->LoadMapLayout( m_LayoutFilename ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Unable to load map layout '%s'.\n", m_LayoutFilename ); pLayoutSystem->OnError(); return; } for ( int i = 0; i < pMapLayout->m_PlacedRooms.Count(); ++ i ) { CRoom *pRoom = pMapLayout->m_PlacedRooms[i]; CRoomCandidate roomCandidate( pRoom->m_pRoomTemplate, pRoom->m_iPosX, pRoom->m_iPosY, NULL ); if ( !pLayoutSystem->TryPlaceRoom( &roomCandidate ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Unable to place room template '%s' at position (%d, %d) based on data from layout file '%s'.\n", pRoom->m_pRoomTemplate->GetFullName(), pRoom->m_iPosX, pRoom->m_iPosY, m_LayoutFilename ); pLayoutSystem->OnError(); return; } Log_Msg( LOG_TilegenLayoutSystem, "Chose room candidate %s at position (%d, %d).\n", pRoom->m_pRoomTemplate->GetFullName(), pRoom->m_iPosX, pRoom->m_iPosY ); } }
void *EmitSound( const char *pSoundName ) { if ( developer.GetBool() ) { // Ensure the sound is valid int nSoundIndex = g_pSoundEmitterSystem->GetSoundIndex( pSoundName ); if ( !g_pSoundEmitterSystem->IsValidIndex( nSoundIndex ) ) { Log_Warning( LOG_GameUI, "Attempted to play invalid sound \"%s\"\n", pSoundName ); return NULL; } const char *pSourceFile = g_pSoundEmitterSystem->GetSourceFileForSound( nSoundIndex ); if ( !Q_stristr( pSourceFile, "game_sounds_ui.txt" ) ) { Log_Warning( LOG_GameUI, "Attempted to play invalid sound \"%s\". This sound must be defined\n" "in game_sounds_ui.txt but was defined in \"%s\" instead.\n", pSoundName, pSourceFile ); return NULL; } } // Pull data from parameters CSoundParameters params; HSOUNDSCRIPTHANDLE handle = SOUNDEMITTER_INVALID_HANDLE; if ( !soundemitterbase->GetParametersForSoundEx( pSoundName, handle, params, GENDER_NONE, true ) ) { Log_Warning( LOG_GameUI, "Attempted to play invalid sound \"%s\"\n", pSoundName ); return NULL; } if ( !params.soundname[0] ) { Log_Warning( LOG_GameUI, "Attempted to play invalid sound \"%s\", which has no .wav!\n", pSoundName ); return NULL; } float st = 0.0f; if ( params.delay_msec != 0.0f ) { st = gpGlobals->curtime + (float)params.delay_msec / 1000.f; } CLocalPlayerFilter filter; enginesound->EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, params.channel, params.soundname, params.volume, (soundlevel_t)params.soundlevel, 0, // flags params.pitch, NULL, NULL, NULL, true, st ); return (void*)enginesound->GetGuidForLastSoundEmitted(); }
/** * \brief Take a backup of a set of file descriptors */ void *VFS_SaveHandles(int NumFDs, int *FDs) { tVFS_Handle *ret; int i; int max_handles = *Threads_GetMaxFD(); // Check if this process has any handles if( MM_GetPhysAddr( gaUserHandles ) == 0 ) return NULL; // Allocate ret = malloc( NumFDs * sizeof(tVFS_Handle) ); if( !ret ) return NULL; if( NumFDs > max_handles ) NumFDs = max_handles; // Take copies of the handles for( i = 0; i < NumFDs; i ++ ) { tVFS_Handle *h; if( FDs == NULL ) h = &gaUserHandles[i]; else if( FDs[i] == -1 ) { Log_Warning("VFS", "VFS_SaveHandles - Slot %i error FD (-1), ignorning", i); memset(&ret[i], 0, sizeof(tVFS_Handle)); continue ; } else { h = VFS_GetHandle(FDs[i] & (VFS_KERNEL_FLAG - 1)); if(!h) { Log_Warning("VFS", "VFS_SaveHandles - Invalid FD %i", FDs[i] & (VFS_KERNEL_FLAG - 1) ); free(ret); return NULL; } } memcpy( &ret[i], h, sizeof(tVFS_Handle) ); // Reference node if( !h->Node ) continue ; _ReferenceNode(h->Node); h->Mount->OpenHandleCount ++; } return ret; }
tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments) { tVFS_Node *ret; tNativeFS *info; DIR *dp; dp = opendir(Device); if(!dp) { Log_Warning("NativeFS", "ERROR: Unable to open device root '%s'", Device); return NULL; } // Check if directory exists // Parse flags from arguments info = malloc(sizeof(tNativeFS)); info->InodeHandle = Inode_GetHandle(NULL); info->bReadOnly = 0; // Create node ret = malloc(sizeof(tVFS_Node)); memset(ret, 0, sizeof(tVFS_Node)); ret->Data = strdup(Device); ret->ImplInt = strlen(ret->Data); ret->ImplPtr = info; ret->Inode = (Uint64)(tVAddr)dp; ret->Flags = VFS_FFLAG_DIRECTORY; ret->Type = &gNativeFS_DirNodeType; return ret; }
/** * \brief Delete a device from the DevFS folder */ void DevFS_DelDevice(tDevFS_Driver *Device) { tDevFS_Driver *prev = NULL, *dev; SHORTLOCK( &glDevFS_ListLock ); // Search list for device for(dev = gDevFS_Drivers; dev && dev != Device; prev = dev, dev = dev->Next ); // Check if it was found if(dev) { if(prev) prev->Next = Device->Next; else gDevFS_Drivers = Device->Next; } else Log_Warning("DevFS", "Attempted to unregister device %p '%s' which was not registered", Device, Device->Name); SHORTREL( &glDevFS_ListLock ); }
int IRQ_AddHandler(int IRQ, tIRQ_Handler Handler, void *Ptr) { if( IRQ < 0 || IRQ >= N_IRQS-32 ) { return 1; } IRQ += 32; // 32 internal IRQs // - Enable IRQ, clear pending and send to CPU 1 only gpGIC_DistributorBase[GICD_ISENABLER0+IRQ/32] = 1 << (IRQ & (32-1)); ((Uint8*)&gpGIC_DistributorBase[GICD_ITARGETSR0])[IRQ] = 1; gpGIC_DistributorBase[GICD_ICPENDR0+IRQ/32] = 1 << (IRQ & (32-1)); // TODO: Does the GIC need to handle IRQ sharing? if( gaIRQ_Handlers[IRQ] ) { Log_Warning("GIC", "IRQ %i already handled by %p, %p ignored", IRQ, gaIRQ_Handlers[IRQ], Handler); return 2; } gaIRQ_Handlers[IRQ] = Handler; gaIRQ_HandlerData[IRQ] = Ptr; Log_Debug("GIC", "IRQ %i handled by %p(%p)", IRQ, Handler, Ptr); // DEBUG! Trip the interrupt gpGIC_DistributorBase[GICD_ISPENDR0+IRQ/32] = 1 << (IRQ & (32-1)); return 0; }
void CTilegenAction_AddRoomCandidates::Execute( CLayoutSystem *pLayoutSystem ) { if ( m_pLevelTheme == NULL ) { const char *pThemeName = m_pThemeNameExpression->Evaluate( pLayoutSystem->GetFreeVariables() ); m_pLevelTheme = CLevelTheme::FindTheme( pThemeName ); if ( m_pLevelTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", pThemeName ); pLayoutSystem->OnError(); return; } } CUtlVector< const CRoomTemplate * > validRoomTemplates; BuildRoomTemplateList( pLayoutSystem, m_pLevelTheme, m_pRoomTemplateFilter, m_bExcludeGlobalFilters, &validRoomTemplates ); const CRoomTemplate **ppRoomTemplates = const_cast< const CRoomTemplate ** >( validRoomTemplates.Base() ); BuildRoomCandidateList( pLayoutSystem, ppRoomTemplates, validRoomTemplates.Count(), m_pExitFilter, m_pRoomCandidateFilter, m_pRoomCandidateFilterAction, m_pRoomCandidateFilterCondition, m_bExcludeGlobalFilters ); }
void Threads_Glue_SemInit(void **Ptr, int Val) { *Ptr = SDL_CreateSemaphore(Val); if( !*Ptr ) { Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError()); } }
void CTilegenAction_AddInstances::Execute( CLayoutSystem *pLayoutSystem ) { CFreeVariableMap *pFreeVariables = pLayoutSystem->GetFreeVariables(); int nInstanceCount = m_pInstanceCount->Evaluate( pFreeVariables ); CMapLayout *pMapLayout = pLayoutSystem->GetMapLayout(); CUtlVector< int > validCandidates; for ( int i = 0; i < pMapLayout->m_PlacedRooms.Count(); ++ i ) { pLayoutSystem->GetFreeVariables()->SetOrCreateFreeVariable( "RoomTemplate", ( void * )pMapLayout->m_PlacedRooms[i]->m_pRoomTemplate ); if ( m_pRoomTemplateFilter == NULL || m_pRoomTemplateFilter->Evaluate( pFreeVariables ) ) { validCandidates.AddToTail( i ); } pLayoutSystem->GetFreeVariables()->SetOrCreateFreeVariable( "RoomTemplate", NULL ); } if ( validCandidates.Count() == 0 ) { // No valid candidates found, bail Log_Warning( LOG_TilegenLayoutSystem, "No valid candidates found for rule %s.\n", GetTypeName() ); return; } for ( int i = 0; i < nInstanceCount; ++ i ) { CInstanceSpawn *pInstanceSpawn = &pMapLayout->m_InstanceSpawns[pMapLayout->m_InstanceSpawns.AddToTail( m_InstanceSpawn )]; char indexString[15]; Q_snprintf( indexString, _countof( indexString ), "%02d", i ); pInstanceSpawn->FixupValues( "%N", indexString ); pInstanceSpawn->SetPlacedRoomIndex( validCandidates[pLayoutSystem->GetRandomInt( 0, validCandidates.Count() - 1 )] ); pInstanceSpawn->SetRandomSeed( pLayoutSystem->GetRandomInt( 1, 1000000000 ) ); } }
bool CInstanceSpawn::LoadFromKeyValues( KeyValues *pKeyValues ) { const char *pFilename = pKeyValues->GetString( "filename", NULL ); if ( pFilename == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "No 'filename' specified in CInstanceSpawn block.\n" ); return false; } Q_strncpy( m_InstanceFilename, pFilename, _countof( m_InstanceFilename ) ); const char *pType = pKeyValues->GetString( "type", NULL ); if ( pType == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "No 'type' specified in CInstanceSpawn block.\n" ); return false; } else { if ( Q_stricmp( pType, "add_at_random_node" ) == 0 ) { m_InstanceSpawningMethod = ISM_ADD_AT_RANDOM_NODE; } else { Log_Warning( LOG_TilegenLayoutSystem, "Invalid 'type' specified in CInstanceSpaw block.\n" ); return false; } } m_nPlacedRoomIndex = pKeyValues->GetInt( "room_index", -1 ); m_nRandomSeed = pKeyValues->GetInt( "random_seed", 0 ); for ( KeyValues *pReplaceKV = pKeyValues->GetFirstSubKey(); pReplaceKV != NULL; pReplaceKV = pReplaceKV->GetNextKey() ) { if ( Q_stricmp( pReplaceKV->GetName(), "key_value" ) == 0 ) { const char *pKey = pReplaceKV->GetString( "key", "" ); const char *pValue = pReplaceKV->GetString( "value", "" ); int nIndex = m_AdditionalKeyValues.AddToTail(); Q_strncpy( m_AdditionalKeyValues[nIndex].m_Key, pKey, MAX_TILEGEN_IDENTIFIER_LENGTH ); Q_strncpy( m_AdditionalKeyValues[nIndex].m_Value, pValue, MAX_TILEGEN_IDENTIFIER_LENGTH ); } } return true; }
bool CTilegenAction_PlaceComponent::LoadRoomPlacementsFromKeyValues( KeyValues *pKeyValues, CUtlVector< RoomPlacementInfo_t > *pRooms ) { for ( KeyValues *pRoomKV = pKeyValues->GetFirstSubKey(); pRoomKV != NULL; pRoomKV = pRoomKV->GetNextKey() ) { if ( Q_stricmp( pRoomKV->GetName(), "room" ) == 0 ) { const char *pFullRoomName = pRoomKV->GetString( "room_name", NULL ); if ( pFullRoomName == NULL ) { return false; } // A negative or omitted value means random placement float flFraction = pRoomKV->GetFloat( "fraction", -1.0f ); pRooms->AddToTail(); RoomPlacementInfo_t *pRoom = &pRooms->Element( pRooms->Count() - 1 ); pRoom->m_flPlacementFraction = flFraction; char themeName[MAX_TILEGEN_IDENTIFIER_LENGTH]; char roomName[MAX_TILEGEN_IDENTIFIER_LENGTH]; if ( !CLevelTheme::SplitThemeAndRoom( pFullRoomName, themeName, MAX_TILEGEN_IDENTIFIER_LENGTH, roomName, MAX_TILEGEN_IDENTIFIER_LENGTH ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Could not split theme name from room (full name: %s).\n", pFullRoomName ); return false; } CLevelTheme *pTheme = CLevelTheme::FindTheme( themeName ); if ( pTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", themeName ); return false; } pRoom->m_pRoomTemplate = pTheme->FindRoom( roomName ); if ( pRoom->m_pRoomTemplate == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Room %s not found.\n", roomName ); return false; } } } return true; }
bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMissing ) { if ( !g_pScriptVM ) { return false; } if ( !pszScriptName || !*pszScriptName ) { Log_Warning( LOG_VScript, "Cannot run script: NULL script name\n" ); return false; } // Prevent infinite recursion in VM if ( g_ScriptServerRunScriptDepth > 16 ) { Log_Warning( LOG_VScript, "IncludeScript stack overflow\n" ); return false; } g_ScriptServerRunScriptDepth++; HSCRIPT hScript = VScriptCompileScript( pszScriptName, bWarnMissing ); bool bSuccess = false; if ( hScript ) { #ifdef GAME_DLL if ( gpGlobals->maxClients == 1 ) { CBaseEntity *pPlayer = UTIL_GetLocalPlayer(); if ( pPlayer ) { g_pScriptVM->SetValue( "player", pPlayer->GetScriptInstance() ); } } #endif bSuccess = ( g_pScriptVM->Run( hScript, hScope ) != SCRIPT_ERROR ); if ( !bSuccess ) { Log_Warning( LOG_VScript, "Error running script named %s\n", pszScriptName ); Assert( "Error running script" ); } } g_ScriptServerRunScriptDepth--; return bSuccess; }
/** * \fn int VFS_Symlink(const char *Name, const char *Link) * \brief Creates a symlink called \a Name to \a Link * \param Name Name of symbolic link * \param Link Destination of symbolic link */ int VFS_Symlink(const char *Name, const char *Link) { char *realLink; int fp; ENTER("sName sLink", Name, Link); // Get absolue path name realLink = VFS_GetAbsPath( Link ); if(!realLink) { Log_Warning("VFS", "Path '%s' is badly formed", Link); errno = EINVAL; LEAVE('i', -1); return -1; } LOG("realLink = '%s'", realLink); // Make node if( VFS_MkNod(Name, VFS_FFLAG_SYMLINK) != 0 ) { Log_Warning("VFS", "Unable to create link node '%s'", Name); free(realLink); // errno is set by VFS_MkNod LEAVE('i', -2); return -2; // Make link node } // Write link address fp = VFS_Open(Name, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_NOLINK); if( fp == -1 ) { Log_Warning("VFS", "Unable to open newly created symlink '%s'", Name); free(realLink); LEAVE('i', -3); return -3; } VFS_Write(fp, strlen(realLink), realLink); VFS_Close(fp); free(realLink); LEAVE('i', 1); return 1; }
void CLayoutSystem::BeginGeneration( CMapLayout *pMapLayout ) { if ( m_States.GetStateCount() == 0 ) { Log_Warning( LOG_TilegenLayoutSystem, "No states in layout system!\n" ); OnError(); return; } // Reset random generator int nSeed; m_Random = CUniformRandomStream(); if ( m_nRandomSeed != 0 ) { nSeed = m_nRandomSeed; } else { // @TODO: this is rather unscientific, but it gets us desired randomness for now. nSeed = RandomInt( 1, 1000000000 ); } m_Random.SetSeed( nSeed ); Log_Msg( LOG_TilegenLayoutSystem, "Beginning generation with random seed " ); Log_Msg( LOG_TilegenLayoutSystem, Color( 255, 255, 0, 255 ), "%d.\n", nSeed ); m_bLayoutError = false; m_bGenerating = true; m_nIterations = 0; m_nUselessIterations = 0; m_pMapLayout = pMapLayout; m_pCurrentState = m_States.GetState( 0 ); m_OpenExits.RemoveAll(); m_ActionData.RemoveAll(); m_FreeVariables.RemoveAll(); // Initialize with sentinel value ActionData_t nullActionData = { 0 }; m_ActionData.Insert( NULL, nullActionData ); for ( int i = 0; i < m_TilegenListeners.Count(); ++ i ) { m_TilegenListeners[i]->OnBeginGeneration( this, GetFreeVariables() ); } if ( m_pGlobalActionState != NULL ) { m_pGlobalActionState->OnBeginGeneration( this ); } m_States.OnBeginGeneration(); GetFreeVariables()->SetOrCreateFreeVariable( "LayoutSystem", this ); GetFreeVariables()->SetOrCreateFreeVariable( "MapLayout", GetMapLayout() ); }
//----------------------------------------------------------------------------- // Precaches all game UI sounds //----------------------------------------------------------------------------- void CGameUIGameSystem::PrecacheGameUISounds() { // Precache all UI sounds. These must exist in the game_sounds_ui.txt script file KeyValues *pUIGameSounds = new KeyValues( "Game Instructor Counts" ); if ( !pUIGameSounds->LoadFromFile( g_pFullFileSystem, "scripts/game_sounds_ui.txt", "GAME" ) ) { pUIGameSounds->deleteThis(); return; } for ( KeyValues *pKey = pUIGameSounds; pKey; pKey = pKey->GetNextKey() ) { const char *pSoundName = pKey->GetName(); int nSoundIndex = soundemitterbase->GetSoundIndex( pSoundName ); if ( !soundemitterbase->IsValidIndex( nSoundIndex ) ) { Log_Warning( LOG_GameUI, "GameUI: Unable to precache gamesound \"%s\"\n", pSoundName ); continue; } CSoundParametersInternal *pInternal = soundemitterbase->InternalGetParametersForSound( nSoundIndex ); if ( !pInternal ) { Log_Warning( LOG_GameUI, "GameUI: Unable to precache gamesound \"%s\"\n", pSoundName ); continue; } int nWaveCount = pInternal->NumSoundNames(); if ( !nWaveCount ) { Log_Warning( LOG_GameUI, "GameUI: game_sounds_ui.txt entry '%s' has no waves listed under 'wave' or 'rndwave' key!!!\n", pSoundName ); continue; } for( int nWave = 0; nWave < nWaveCount; ++nWave ) { const char *pWavName = soundemitterbase->GetWaveName( pInternal->GetSoundNames()[ nWave ].symbol ); enginesound->PrecacheSound( pWavName, true, true ); } } pUIGameSounds->deleteThis(); }
bool CTilegenAction_PlaceComponent::LoadFromKeyValues( KeyValues *pKeyValues ) { KeyValues *pMandatoryRoomsKV = pKeyValues->FindKey( "mandatory_rooms" ); if ( pMandatoryRoomsKV != NULL ) { LoadRoomPlacementsFromKeyValues( pMandatoryRoomsKV, &m_MandatoryRooms ); } KeyValues *pOptionalRoomsKV = pKeyValues->FindKey( "optional_rooms" ); if ( pOptionalRoomsKV != NULL ) { LoadRoomPlacementsFromKeyValues( pOptionalRoomsKV, &m_OptionalRooms ); } if ( m_OptionalRooms.Count() >= m_nMaxTotalOptionalRooms ) { return false; } m_nMinOptionalRooms = pKeyValues->GetInt( "min", 0 ); m_nMaxOptionalRooms = pKeyValues->GetInt( "max", 0 ); m_bExcludeGlobalFilters = pKeyValues->GetBool( "exclude_global_filters", false ); // Load optional exit & room candidate filters. bool bSuccess = true; bSuccess &= CreateExpressionFromKeyValuesBlock( pKeyValues, "exit_filter", GetTypeName(), &m_pExitFilter, true ); bSuccess &= CreateExpressionFromKeyValuesBlock( pKeyValues, "room_candidate_filter", GetTypeName(), &m_pRoomCandidateFilter, true ); if ( pKeyValues->FindKey( "room_candidate_filter_action" ) != NULL ) { bSuccess &= CreateActionAndConditionFromKeyValuesBlock( pKeyValues, "room_candidate_filter_action", GetTypeName(), &m_pRoomCandidateFilterAction, &m_pRoomCandidateFilterCondition ); } // Load up the nested "connector_room_candidates" block. // This is the same block found in a CTilegenAction_AddConnectorRoomCandidates instance. // This block contains logic to add room candidates KeyValues *pAddConnectorRoomCandidatesKV = pKeyValues->FindKey( "connector_room_candidates" ); if ( pAddConnectorRoomCandidatesKV != NULL ) { ITilegenAction *pAction; ITilegenExpression< bool > *pCondition; bSuccess &= CreateActionAndConditionFromKeyValuesBlock( pAddConnectorRoomCandidatesKV, "action", GetTypeName(), &pAction, &pCondition ); if ( pCondition != NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Action specified in 'connector_room_candidates' block of %s must not have a nested condition.\n", GetTypeName() ); return false; } m_pAddConnectorRoomCandidates = new CTilegenAction_AddConnectorRoomCandidates( pAction ); } m_pChooseCandidate = new CTilegenAction_ChooseCandidate( false ); return bSuccess; }
/** * Bind renderbuffer. */ void Renderbuffer::bind() const { #if defined(SANITY_CHECK) // Warning! This may spam your logs! if(!isValid()) { Log_Warning(Dumb::Module::Render, "You are trying to bind an invalid texture for target %s", GetTextureTargetName(_target)); } else { GLuint bound; glGetIntegerv(GL_RENDERBUFFER_BINDING, (GLint*)&bound); if(bound && (bound != _id)) { Log_Warning(Dumb::Module::Render, "Renderbuffer %d is currently bound.", bound); } } #endif // SANITY_CHECK glBindRenderbuffer(GL_RENDERBUFFER, _id); }
bool CTilegenAction_LoadLayout::LoadFromKeyValues( KeyValues *pKeyValues ) { const char *pFilename = pKeyValues->GetString( "filename", NULL ); if ( pFilename == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "No 'filename' specified in %s.\n", GetTypeName() ); return false; } Q_strncpy( m_LayoutFilename, pFilename, _countof( m_LayoutFilename ) ); return true; }
const char *CTilegenExpression_ExtractRoomName::DirectEvaluate( CFreeVariableMap *pContext, const CTilegenExpression_ExtractRoomName::ParameterType &pFullRoomName ) { char themeName[MAX_TILEGEN_IDENTIFIER_LENGTH]; char roomName[MAX_TILEGEN_IDENTIFIER_LENGTH]; if ( !CLevelTheme::SplitThemeAndRoom( pFullRoomName, themeName, MAX_TILEGEN_IDENTIFIER_LENGTH, roomName, MAX_TILEGEN_IDENTIFIER_LENGTH ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Could not split theme name from room (full name: %s).\n", pFullRoomName ); return NULL; } return pContext->m_StringPool.Allocate( roomName ); }
/** * Unbind renderbuffer. */ void Renderbuffer::unbind() const { #if defined(SANITY_CHECK) // Warning! This may spam your logs! GLuint bound; glGetIntegerv(GL_RENDERBUFFER_BINDING, (GLint*)&bound); if(bound != _id) { if(bound) { Log_Warning(Dumb::Module::Render, "You are trying to unbind renderbuffer %d whereas the current bound renderbuffer is %d", _id, bound); Log_Warning(Dumb::Module::Render, "If you really want to unbind the currently bound renderbuffer use Renderbuffer::unbindAll() (static) instead."); } else { Log_Warning(Dumb::Module::Render, "No renderbuffer bound."); } } #endif // SANITY_CHECK glBindRenderbuffer(GL_RENDERBUFFER, 0); }
void blman_delete_record_by_node(blman *self, blidxnode *node) { uint8 *block = blman_get_block(self, node->m_blockNumber); // E_BLS deleteStatus = Block_DeleteRecordByKey(block, node->m_key); if(deleteStatus != eBLS_OK) { Log_Warning(__FUNCTION__, "Trying to delete non-existant key: " I64FMTD " in block number: %u", node->m_key, node->m_blockNumber); } avl_delete(self->blockIndex, node); blidxnode_destroy(node, self->blockIndex->avl_param); }
void CLayoutSystem::TransitionToState( const char *pStateName ) { CTilegenState *pState = m_States.FindState( pStateName ); if ( pState == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Tilegen state %s not found.\n", pStateName ); OnError(); } else { TransitionToState( pState ); } }
bool CTilegenAction_PlaceComponent::PlaceRoom( CLayoutSystem *pLayoutSystem, const CRoomTemplate *pRoomTemplate ) { int nNumTries = 0; while ( nNumTries < 10 ) { BuildRoomCandidateList( pLayoutSystem, &pRoomTemplate, 1, m_pExitFilter, m_pRoomCandidateFilter, m_pRoomCandidateFilterAction, m_pRoomCandidateFilterCondition, m_bExcludeGlobalFilters ); CUtlVector< CRoomCandidate > *pRoomCandidateList = pLayoutSystem->GetRoomCandidateList(); if ( pRoomCandidateList->Count() > 0 ) { pLayoutSystem->ExecuteAction( m_pChooseCandidate, NULL ); return true; } else { Log_Msg( LOG_TilegenLayoutSystem, "Unable to place component room %s, attempting to place connector room.\n", pRoomTemplate->GetFullName() ); if ( !PlaceConnectorRoom( pLayoutSystem, pRoomTemplate ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Unable to place connector piece to connect to component room %s.\n", pRoomTemplate->GetFullName() ); return false; } } ++ nNumTries; } Log_Warning( LOG_TilegenLayoutSystem, "Unable to place component room %s after %d tries.\n", pRoomTemplate->GetFullName(), nNumTries ); return false; }
bool CTilegenAction_AddConnectorRoomCandidates::LoadFromKeyValues( KeyValues *pKeyValues ) { bool bSuccess = true; bSuccess &= CreateExpressionFromKeyValuesBlock( pKeyValues, "theme", GetTypeName(), &m_pTargetThemeNameExpression ); bSuccess &= CreateExpressionFromKeyValuesBlock( pKeyValues, "room_template_filter", GetTypeName(), &m_pTargetRoomTemplateFilter ); ITilegenExpression< bool > *pCondition; KeyValues *pAddConnectorRoomCandidatesKV = pKeyValues->FindKey( "connector_room_candidates" ); if ( pAddConnectorRoomCandidatesKV == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Key 'connector_room_candidates' not found when parsing 'CTilegenAction_AddConnectorRoomCandidates'.\n" ); return false; } bSuccess &= CreateActionAndConditionFromKeyValuesBlock( pAddConnectorRoomCandidatesKV, "action", GetTypeName(), &m_pAddConnectorCandidates, &pCondition ); if ( pCondition != NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Action specified in 'connector_room_candidates' block of 'CTilegenAction_AddConnectorRoomCandidates' must not have a nested condition.\n" ); return false; } return bSuccess; }
const CRoomTemplate *CTilegenExpression_RoomTemplateFromName::DirectEvaluate( CFreeVariableMap *pContext, const CTilegenExpression_RoomTemplateFromName::ParameterType &pName ) { char themeName[MAX_TILEGEN_IDENTIFIER_LENGTH]; char roomName[MAX_TILEGEN_IDENTIFIER_LENGTH]; if ( !CLevelTheme::SplitThemeAndRoom( pName, themeName, MAX_TILEGEN_IDENTIFIER_LENGTH, roomName, MAX_TILEGEN_IDENTIFIER_LENGTH ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Could not split theme name from room (full name: %s).\n", pName ); return NULL; } CLevelTheme *pTheme = CLevelTheme::FindTheme( themeName ); if ( pTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Could not find theme '%s'.\n", themeName ); return NULL; } CRoomTemplate *pTemplate = pTheme->FindRoom( roomName ); if ( pTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Could not find room '%s' in theme '%s'.\n", roomName, themeName ); return NULL; } return pTemplate; }
/** * \fn int DevFS_AddDevice(tDevFS_Driver *Device) */ int DevFS_AddDevice(tDevFS_Driver *Device) { int ret = 0; tDevFS_Driver *dev; ENTER("pDevice", Device); LOG("Device->Name = '%s'", Device->Name); SHORTLOCK( &glDevFS_ListLock ); // Check if the device is already registered or the name is taken for( dev = gDevFS_Drivers; dev; dev = dev->Next ) { if(dev == Device) break; if(strcmp(dev->Name, Device->Name) == 0) break; } if(dev) { if(dev == Device) Log_Warning("DevFS", "Device %p '%s' attempted to register itself twice", dev, dev->Name); else Log_Warning("DevFS", "Device %p attempted to register '%s' which was owned by %p", Device, dev->Name, dev); ret = -1; // Error } else { Device->Next = gDevFS_Drivers; gDevFS_Drivers = Device; gDevFS_RootNode.Size ++; ret = giDevFS_NextID ++; } SHORTREL( &glDevFS_ListLock ); LEAVE('i', ret); return ret; }
void CTilegenAction_AddRoomCandidatesAtLocation::Execute( CLayoutSystem *pLayoutSystem ) { if ( m_pLevelTheme == NULL ) { const char *pThemeName = m_pThemeNameExpression->Evaluate( pLayoutSystem->GetFreeVariables() ); if ( pThemeName == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "No theme name specified.\n" ); pLayoutSystem->OnError(); return; } m_pLevelTheme = CLevelTheme::FindTheme( pThemeName ); if ( m_pLevelTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", pThemeName ); pLayoutSystem->OnError(); return; } } int nX = m_pXExpression->Evaluate( pLayoutSystem->GetFreeVariables() ); int nY = m_pYExpression->Evaluate( pLayoutSystem->GetFreeVariables() ); for ( int i = 0; i < m_pLevelTheme->m_RoomTemplates.Count(); ++ i ) { if ( pLayoutSystem->GetMapLayout()->TemplateFits( m_pLevelTheme->m_RoomTemplates[i], nX, nY, false ) ) { pLayoutSystem->GetFreeVariables()->SetOrCreateFreeVariable( "RoomTemplate", m_pLevelTheme->m_RoomTemplates[i] ); if ( m_pRoomTemplateFilter == NULL || m_pRoomTemplateFilter->Evaluate( pLayoutSystem->GetFreeVariables() ) ) { TryAddRoomCandidate( CRoomCandidate( m_pLevelTheme->m_RoomTemplates[i], nX, nY, NULL ), pLayoutSystem->GetRoomCandidateList() ); } pLayoutSystem->GetFreeVariables()->SetOrCreateFreeVariable( "RoomTemplate", NULL ); } } }