コード例 #1
0
/*
================
VorbisStream::~VorbisStream
================
*/
VorbisStream::~VorbisStream() {
	if ( data ) {
		OG_ASSERT( numInUse == 0 );
		audioFS->FreeFile( data );
		data = OG_NULL;
	}
}
コード例 #2
0
/*
================
TLS_Index::TLS_Index
================
*/
TLS_Index::TLS_Index() : data(OG_NULL) {
	pthread_key_t key;
	int result = pthread_key_create( &key, OG_NULL );
	OG_ASSERT( result == 0 );

	if ( result == 0 )
		data = new pthread_key_t(key);
}
コード例 #3
0
/*
================
Format::OnAppend
================
*/
void Format::OnAppend( void ) {
	// This assert gets triggered when you add more parameters than where specified in the format.
	//! @todo	add an error here ?
	OG_ASSERT( paramCount < numFormatEntries );
	if ( paramCount < numFormatEntries ) {
		FormatEntry *entry = GetFormatEntry( paramCount++ );
		if ( entry )
			TryPrint( "%s", entry->append );
	}
}
コード例 #4
0
/*
================
Format::CheckVariableInput
================
*/
bool Format::CheckVariableInput( void ) {
	// This assert gets triggered when you add more parameters than where specified in the format.
	//! @todo	add an error here ?
	OG_ASSERT( paramCount != -1 && paramCount < numFormatEntries );
	if ( paramCount < numFormatEntries ) {
		FormatEntry *entry = GetFormatEntry( paramCount );
		if ( entry && entry->takeInput == 2 ) {
			entry->takeInput = 1;
			return true;
		}
	}
	return false;
}
コード例 #5
0
/*
================
CmdSystemEx::PrintUsage
================
*/
void CmdSystemEx::PrintUsage( const char *buf ) const {
	if ( !buf )
		return;

	String command = buf;
	command.StripLeadingWhitespaces();

	if ( command.IsEmpty() )
		return;

	CmdArgs args(buf);

	OG_ASSERT( args.Argc() > 0 );

	// Find the command and call its usage func
	int i = cmdList.Find( args.Argv(0) );
	if ( i != -1 )
		cmdList[i].usage->ShowUsage();
}
コード例 #6
0
/*
================
AudioStream::UpdateStream
================
*/
void AudioStream::UpdateStream( AudioSource *src ) {
	OG_ASSERT( src->streamData != OG_NULL );

	if ( outSize > AUDIOSRC_STREAM_LIMIT ) {
		int processed;
		alGetSourcei( src->alSourceNum, AL_BUFFERS_PROCESSED, &processed );

		ALuint buffer;
		while( processed-- ) {
			alSourceUnqueueBuffers( src->alSourceNum, 1, &buffer );
			CheckAlErrors();

			if ( !UploadData( src->streamData, buffer, AUDIOSRC_BUFFERSIZE ) )
				return;

			alSourceQueueBuffers( src->alSourceNum, 1, &buffer );
			CheckAlErrors();
		}
	}

	return;
}
コード例 #7
0
/*
================
Format::Reset
================
*/
void Format::Reset( bool keep, const char *fmt ) {
	floatPrecision = -1;
	fillChar = ' ';

	if ( keep ) {
		if ( !hasFormat ) {
			offset = 0;
			paramCount = -1;
		} else {
			offset = strlen( fmtBuffer );
			memcpy( buffer, fmtBuffer, offset );
			if ( paramCount > 0 )
				paramCount = 0;

			FormatEntry *entry = firstFormatEntry;
			while( entry ) {
				if ( entry->takeInput == 1 )
					entry->takeInput = 2;
				entry = entry->next;
			}
		}
		buffer[offset] = '\0';
		return;
	}
	DeleteFormatEntries();

	hasFormat = (fmt != OG_NULL);
	if ( !hasFormat ) {
		offset = 0;
		paramCount = -1;
		fmtBuffer[0] = '\0';
	} else {
		strcpy( fmtBuffer, fmt );
		fmtBuffer[255] = '\0';

		int end;
		offset = -1;
		for( int r=0, w=0; fmtBuffer[r] != '\0'; r++, w++ ) {
			if ( fmtBuffer[r] == '$' ) {
				if ( fmtBuffer[r+1] == '$' )
					r++;
				else {
					FormatEntry *entry = new FormatEntry;
					if ( firstFormatEntry == OG_NULL )
						firstFormatEntry = lastFormatEntry = entry;
					else
						lastFormatEntry = lastFormatEntry->next = entry;
					numFormatEntries++;

					entry->fieldWidth = 0;
					end = r;
					if ( fmtBuffer[r+1] == '?' ) {
						entry->takeInput = 2;
						r++;
					} else if ( fmtBuffer[r+1] == '+' || fmtBuffer[r+1] == '-' ) {
						bool negative = fmtBuffer[r+1] == '-';
						entry->takeInput = 0;
						for ( r += 2; String::IsDigit(fmtBuffer[r]); r++ )
							entry->fieldWidth = 10 * entry->fieldWidth + (fmtBuffer[r] - '0');
						if ( negative )
							entry->fieldWidth *= -1;
						r--;
					}
					if ( fmtBuffer[r+1] == '*' ) {
						fmtBuffer[w] = '\0';
						if ( offset == -1 ) {
							memcpy( buffer, fmtBuffer, r );
							offset = end;
						}
						r++;
						entry->append = fmtBuffer + r + 1;
						w = r;
						continue;
					}
					OG_DEBUG_BREAK()
					//! @todo	error ?
				}
			}
			fmtBuffer[w] = fmtBuffer[r];
		}
		// This assert gets triggered when you have no parameters specified in the format.
		//! @todo	add an error here ?
		OG_ASSERT( offset != -1 );
		if ( offset != -1 ) {
			paramCount = 0;
		} else {
			// no params specified, act like this is the first parameter
			offset = strlen( fmtBuffer );
			memcpy( buffer, fmtBuffer, offset );
			paramCount = -1;
		}
	}
	buffer[offset] = '\0';
}
コード例 #8
0
/*
================
TLS_Index::GetValue
================
*/
void *TLS_Index::GetValue( void ) const {
	OG_ASSERT( data != OG_NULL );
	return pthread_getspecific( *static_cast<pthread_key_t *>(data) );
}
コード例 #9
0
/*
================
TLS_Index::SetValue
================
*/
void TLS_Index::SetValue( void *value ) const {
	OG_ASSERT( data != OG_NULL );
	pthread_setspecific( *static_cast<pthread_key_t *>(data), data );
}
コード例 #10
0
/*
================
Lexer::UnreadToken
================
*/
void Lexer::UnreadToken( void ) {
	OG_ASSERT( !tokIsUnread );
	tokIsUnread = true;
}
コード例 #11
0
/*
================
WavStream::~WavStream
================
*/
WavStream::~WavStream() {
	OG_ASSERT( numInUse == 0 );
	delete[] data;
}
コード例 #12
0
/*
================
CmdSystemEx::CompleteCmd
================
*/
const char *CmdSystemEx::CompleteCmd( const char *buf, argCompletionCB_t callback ) {
	static String returnBuffer;
	if ( !buf )
		return "";

	completionBuffer = buf;
	completionBuffer.StripLeadingWhitespaces();

	if ( completionBuffer.IsEmpty() )
		return "";

	int bufLen = completionBuffer.Length();
	completionList.Clear();

	int i;
	if( completionBuffer.Find(" ") != String::INVALID_POSITION ) {
		CmdArgs args(buf);

		OG_ASSERT( args.Argc() > 0 );

		// Find the command and call its completion func
		const char *arg0 = args.Argv(0);
		i = cmdList.Find( arg0 );
		if ( i != -1 ) {
			if ( cmdList[i].completion )
				cmdList[i].completion->Complete(args, CompletionCallback);
		}
		else
			cvarSystemEx->CompleteCVar( args, CompletionCallback );
	} else {
		// Find all commands that start with buf
		for( i = cmdList.MatchPrefix( buf, bufLen ); i != -1; i = cmdList.MatchPrefix( buf, bufLen, i ) )
			completionList.Append( cmdList.GetKey(i) );

		// Find all cvars that start with buf
		cvarSystemEx->CompleteCVar(buf, bufLen, completionList);
	}
	if ( completionList.IsEmpty() )
		return completionBuffer.c_str();

	int numEntries = completionList.Num();

	// Only one option, so return it straight
	if ( numEntries == 1 )
		return completionList[0].c_str();

	// Convert to lowercase for faster comparison, then strip the input and calculate the shortest length
	int shortest = 1023;
	String lowerBuf = completionBuffer;
	lowerBuf.ToLower();
	StringList newList;
	for( i=0; i<numEntries; i++ ) {
		newList.Append( completionList[i] );
		newList[i].ToLower();
		newList[i].StripLeadingOnce(lowerBuf.c_str());
		if ( newList[i].Length() < shortest )
			shortest = newList[i].Length();
	}

	returnBuffer.Clear();
	if ( shortest == 0 )
		completionList[0].Left( completionBuffer.Length(), returnBuffer );
	else {
		// Find the first not matching char
		int pos;
		const String &firstStr = newList[0];
		for( pos=0; pos<shortest; pos++ ) {
			// Check if all chars at this position match
			for( i=1; i<numEntries; i++ ) {
				if ( firstStr.Cmpn( newList[i].c_str(), pos ) != 0 )
					break;
			}
			// One did not match
			if ( i < numEntries )
				break;
		}
		completionList[0].Left( completionBuffer.Length()+pos-1, returnBuffer );
	}

	// Send the list back and print it in the console
	Console::Print( Format( "]$*\n" ) << returnBuffer );
	Format complete( "    $*\n" );
	for( i=0; i<numEntries; i++ ) {
		if ( callback )
			callback( completionList[i].c_str() );
		Console::Print( complete << completionList[i] );
		complete.Reset();
	}
	return returnBuffer.c_str();
}