SpatialFear.SFUtils

00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
//=============================================================================
// Spatial Fear
// Class: SFUtils
// Description: This class offers some static funtion that aid in 
// UnrealScript and MOD development. !! Internal use only !!
//
//	- sfLog( string strMessage) writes a log entry with level 1
//	- sfLogEx(int nLevel, string strMessage) writes a log entry with passed level value
//  - sfError(string strMessage) writes a Spatial Fear error message to the log
//	- FormatFloat(float fValue) formats a float with the configured nFloatingPointPrecision for
//	string output (needed because of missing printf functionaly, will eventually be moved to C++)
//
// Author: Markus Nuebel
//=============================================================================

class SFUtils extends Object;

const  SF_LOG_INDENT=">>";
const  SF_LOG_PREFIX="SF: ";
const  SF_ERROR_PREFIX="SF ERROR: ";

var (SpatialFear) int LogLevel; // Current log level used for debug traces with sfLof functions. Default: 5
var (SpatialFear) int nFloatingPointPrecision; // Floating point precision used with FormatFloat function.


// Default logging is done on level 1
static function sfLog( string strMessage)
{
	sfLogEx(1, strMessage);
}

// Logs an entry with a specified log level
static function sfLogEx(int nLevel, string strMessage)
{
	local string	strLogPrefix;
	local int		i;

	if(nLevel > Default.LogLevel)
		return;

	// Build indention
	for(i=0; i<nLevel; i++)
			strLogPrefix = strLogPrefix $ SF_LOG_INDENT;
	strLogPrefix = strLogPrefix $ SF_LOG_PREFIX;

	log(strLogPrefix $ strMessage);
}

// Writes a Spatial Fear error to the console.
static function sfError(string strMessage)
{
	log(SF_ERROR_PREFIX $ strMessage);
}

// Format a float value for output
function static string FormatFloat(float fValue)
{
	local string strIn;
	local string strOut;
	strIn = string(fValue); 
	strOut = Left( strIn, Instr(strIn, ".") + class'SFUtils'.default.nFloatingPointPrecision ); 

	return strOut;
}


// Dynamically load a bunch of textures with the same prefix into the array arTextures. nCount is the number of textures to read
function static loadAnimatedTexture( SFArray Textures, int nCount, String strPrefix)
{
	local int		i;
	local string	strName;

	//class'SFUtils'.Static.sfLogEx(5, "SFUtils - loadAnimatedTexture: Loading textures : "$ strPrefix $ " Count: " $ nCount);
	
	for(i=0; i<nCount; i++)
	{
		strName					= strPrefix $ string(i);
		//class'SFUtils'.Static.sfLogEx(15, "SFUtils - loadAnimatedTexture: Loading texture: " $ strName);
		Textures.m_arTexture[i]	= Texture(DynamicLoadObject(strName, class'Texture'));
		// Check for success
		if(None == Textures.m_arTexture[i])
			class'SFUtils'.Static.sfError("SFUtils - loadAnimatedTexture: Failed loading texture: " $ strName);
	}
}

defaultproperties
{
     LogLevel=15
     nFloatingPointPrecision=3
}

class file time: 12/7/2003 3:58:24 PM - creation time: 12/7/2003 4:03:45 PM
Created with UnCodeX