Esempio n. 1
0
void
daHud::BuildScoreLists()
{
	int newScore = m_gameMode->GetScore();
	int seconds = (int)m_gameMode->GetTimeLeft();
	
	if ( seconds < 0 )
		seconds = 0;
	
	if ( !m_scoreList || newScore != m_score )
	{
		if ( m_scoreList )
			delete m_scoreList;
		
		vsString scoreString = vsFormatString("%d", newScore);
		m_scoreList = vsBuiltInFont::CreateString( scoreString, 30.0f );
		m_score = newScore;
	}
	if ( !m_timeList || seconds != m_seconds )
	{
		if ( m_timeList )
			delete m_timeList;
		
		int minutes = seconds/60;
		seconds -= minutes*60;
		
		vsString timeString = vsFormatString("%01d:%02d", minutes, seconds);
		m_timeList = vsBuiltInFont::CreateString( timeString, 20.0f );
		m_seconds = seconds;
	}
}
Esempio n. 2
0
vsString
vsToken::AsString()
{
	vsString result = vsEmptyString;

	switch( m_type )
	{
		case Type_Label:
		case Type_String:
			result = m_string;
			break;
		case Type_NewLine:
			result = "\n";
			break;
		case Type_Float:
			result = vsFormatString("%f", m_float);
			break;
		case Type_Integer:
			result = vsFormatString("%d", m_int);
			break;
		case Type_Equals:
			result = "=";
			break;
		default:
			break;
	}

	return result;
}
void
astHud::BuildScoreLists()
{
	int newScore = m_parent->GetScore();
	int newHighScore = m_parent->GetHighScore();

	if ( !m_scoreList || newScore != m_score )
	{
		if ( m_scoreList )
			delete m_scoreList;

		vsString scoreString = vsFormatString("%08d", newScore);
		m_scoreList = vsBuiltInFont::CreateString( scoreString, 30.0f );
		m_score = newScore;
	}
	if ( !m_highScoreList || newHighScore != m_highScore )
	{
		if ( m_highScoreList )
			delete m_highScoreList;

		vsString highscoreString = vsFormatString("%08d", newHighScore);
		m_highScoreList = vsBuiltInFont::CreateString( highscoreString, 20.0f );
		m_highScore = newHighScore;
	}
}
Esempio n. 4
0
vsSocket::vsSocket(int port):
    m_privateIP(0),
    m_privatePort(0),
    //m_publicIP(0),
    //m_publicPort(0),
    m_listener(NULL)
{
    UNUSED(port);
#ifndef _WIN32
    vsLog("Opening socket");

    m_socket = socket(AF_INET, SOCK_DGRAM, 0);
    if ( m_socket == -1 )
    {
        perror("socket");
        vsAssert( m_socket != -1, vsFormatString("Socket error:  See console output for details" ) );
    }

    sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    memset(addr.sin_zero, '\0', sizeof addr.sin_zero);

    vsLog("Binding socket to port %d", port);

    int err = bind( m_socket, (sockaddr *)&addr, sizeof(addr) );
    if ( err == -1 )
    {
        perror("bind");
        vsAssert( m_socket != -1, vsFormatString("Bind error:  See console output for details" ) );
    }

    socklen_t addrSize = sizeof(addr);
    err = getsockname(m_socket, (sockaddr*)&addr, &addrSize);
    if ( err == -1 )
    {
        perror("getsockname");
        vsAssert( m_socket != -1, vsFormatString("Getsockname error:  See console output for details" ) );
    }

    m_privateIP = ntohl(addr.sin_addr.s_addr);
    m_privatePort = ntohs(addr.sin_port);

    if ( m_privateIP == 0 )	// should be
    {
        vsLog("Bind succeeded:  Listening on INADDR_ANY:%d", m_privatePort);
    }
    else
    {
        char * byte = (char *)&m_privateIP;
        vsLog("Bind succeeded:  Listening on %d.%d.%d.%d:%d", byte[0], byte[1], byte[2], byte[3], m_privatePort);
    }
#endif //_WIN32
}
Esempio n. 5
0
vsDisplayList *
vsDisplayList::Load( const vsString &filename )
{
//	int vec = filename.find(".vec");
//	int obj = filename.find(".obj");

	vsDisplayList *result = NULL;
	// check for a precompiled version of this file.

	{
		if ( vsFile::Exists(filename + vsString(".vec")) )
		{
			result = Load_Vec(filename);
			//result->Write_CVec(filename);
		}
		else if ( vsFile::Exists(filename + vsString(".obj")) )
		{
			result = Load_Obj(filename);
			//result->Write_CVec(filename);
		}
	}

	vsAssert(result, vsFormatString("Unable to load %s", filename.c_str()) );

	return result;
}
void
vsLocalisationTable::Init(const vsString &language)
{
	s_localisationTable = new vsHashTable<vsString>( 128 );

	vsString filename = vsFormatString("%s.xlat", language.c_str());

	if ( vsFile::Exists(filename) )
	{
		vsFile table(filename);

		vsString str;
		vsRecord r;

		while( table.Record(&r) )
		{
			if ( r.GetTokenCount() > 0 )
			{
				vsString label = r.GetLabel().AsString();
				vsString string = r.GetToken(0).AsString();

				s_localisationTable->AddItemWithKey(string, label);
			}
		}
	}
}
Esempio n. 7
0
void vsFailedAssert( const vsString &conditionStr, const vsString &msg, const char *file, int line )
{
	if ( !bAsserted )
	{
		// failed assertion..  trace out some information and then crash.
		bAsserted = true;
		vsString trimmedFile(file);
		size_t pos = trimmedFile.rfind('/');
		if ( pos )
		{
			trimmedFile = trimmedFile.substr(pos+1);
		}

		vsLog("Failed assertion:  %s", msg.c_str());
		vsLog("Failed condition: (%s)", conditionStr.c_str());
		vsLog("at %s:%d", trimmedFile.c_str(), line);
		vsLog_End();

		{
#if defined(_DEBUG)
			DEBUG_BREAK;
#else
			vsString mbString = vsFormatString("Failed assertion:  %s\nFailed condition: (%s)\nat %s:%d", msg.c_str(), conditionStr.c_str(), trimmedFile.c_str(), line);
			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Failed assertion", mbString.c_str(), NULL);
#endif
			CRASH;
		}
	}
	else
	{
		vsLog("Error:  Asserted while handling assertion!");
	}
}
Esempio n. 8
0
bool
vsFile::DeleteDirectory( const vsString &filename )
{
	if ( DirectoryExists(filename) )
	{
		vsArray<vsString> files;
        DirectoryContents(&files, filename);
		for ( int i = 0; i < files.ItemCount(); i++ )
		{
			vsString ff = vsFormatString("%s/%s", filename.c_str(), files[i].c_str());
			if ( vsFile::DirectoryExists( ff ) )
			{
				// it's a directory;  remove it!
				DeleteDirectory( ff );
			}
			else
			{
				// it's a file, delete it.
				Delete( ff );
			}
		}

		// I should now be empty, so delete me.
		return DeleteEmptyDirectory( filename );
	}
	return false;
}
Esempio n. 9
0
static void CheckFBO()
{
	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
	if (status == GL_FRAMEBUFFER_COMPLETE)
		return;

	status -= GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
	vsAssert(status == GL_FRAMEBUFFER_COMPLETE,vsFormatString("incomplete framebuffer object due to %s", c_enums[status]));
}
Esempio n. 10
0
vsString
fsRecord::ToString()
{
	vsString result = m_label;
	
	result += " ";
	
	for ( int i = 0; i < m_argCount; i++ )
	{
		if ( m_argType[i] == Arg_Float )
			result += vsFormatString("%f ", m_fArg[i]);
		else if ( m_argType[i] == Arg_Int )
			result += vsFormatString("%d ", m_iArg[i] );
		else
			vsAssert(0, "Unknown arg type!");
	}
	return result;
}
Esempio n. 11
0
void
vsFile::EnsureWriteDirectoryExists( const vsString &writeDirectoryName ) // static method
{
	if ( !DirectoryExists(writeDirectoryName) )
	{
		int mkdirResult = PHYSFS_mkdir( writeDirectoryName.c_str() );
		vsAssert( mkdirResult != 0, vsFormatString("Failed to create directory '%s%s%s': %s",
				PHYSFS_getWriteDir(), PHYSFS_getDirSeparator(), writeDirectoryName.c_str(), PHYSFS_getLastError()) );
	}
}
vsPreferences::vsPreferences(const vsString &filename_in)
{
	vsString filename = vsFormatString("%s.prefs",filename_in.c_str());
	m_filename = filename;
	
	m_preferenceList = new vsPreferenceObject;
	
	if ( fsFile::Exists(filename) )	// if the file exists, then read the current pref values out of it.
	{
		fsRecord record;
		fsFile prefsFile(filename);
		
		while( prefsFile.Record(&record) )
		{
			vsAssert( record.GetArgCount() == 3, vsFormatString("%s preference has wrong number of arguments!", record.GetLabel().c_str() ));
			
			AddPreference( record.GetLabel(), record.GetArgAsInt(0), record.GetArgAsInt(1), record.GetArgAsInt(2));
		}
	}
}
Esempio n. 13
0
vsTextureInternal::vsTextureInternal( const vsString &filename_in ):
	vsResource(filename_in),
	m_texture(0),
	m_depth(false),
	m_premultipliedAlpha(false)
{
	vsString filename = vsFile::GetFullFilename(filename_in);

	SDL_Surface *loadedImage = IMG_Load(filename.c_str());
	vsAssert(loadedImage != NULL, vsFormatString("Unable to load texture %s: %s", filename.c_str(), IMG_GetError()));
	ProcessSurface(loadedImage);
	SDL_FreeSurface(loadedImage);
}
vsString
vsLocalisationTable::GetTranslation( const vsString &key )
{
	vsString *str = s_localisationTable->FindItem(key);

	if ( str )
	{
		return *str;
	}
	else
	{
		return vsFormatString("<<%s>>", key.c_str());
	}
}
Esempio n. 15
0
vsNetClient::vsNetClient(const vsString &address, uint16_t port)
{
	hostent *h = gethostbyname( address.c_str() );
    if (h == NULL)
	{
#if !defined(_WIN32)	// todo:  Network errors under WinSock!
		herror("gethostbyname");
#endif
		vsAssert( h != NULL, vsFormatString("Gethostbyname error:  See console output for details" ) );
	}

	m_privateIP = ((struct in_addr *)h->h_addr)->s_addr;
	m_privatePort = port;
}
Esempio n. 16
0
vsRenderTarget::vsRenderTarget( Type t, const vsSurface::Settings &settings_in ):
	m_texture(NULL),
	m_renderBufferSurface(NULL),
	m_textureSurface(NULL),
	m_type(t)
{
	CheckGLError("RenderTarget");
	vsSurface::Settings settings = settings_in;

	if ( m_type == Type_Window )
	{
		m_textureSurface = new vsSurface( settings.width, settings.height );

		m_texWidth = 1.f;
		m_texHeight = 1.f;
	}
	else
	{
		//settings.width = vsNextPowerOfTwo(settings.width);
		//settings.height = vsNextPowerOfTwo(settings.height);
		if ( m_type == Type_Multisample )
		{
			vsSurface::Settings rbs = settings_in;
			rbs.mipMaps = false;
			m_renderBufferSurface = new vsSurface(rbs, false, true);
		}
		m_textureSurface = new vsSurface(settings, (t == Type_Depth), false);
		m_texWidth = 1.0;//settings.width / (float)vsNextPowerOfTwo(settings.width);
		m_texHeight = 1.0;//settings.height / (float)vsNextPowerOfTwo(settings.height);
	}

	m_viewportWidth = settings.width;
	m_viewportHeight = settings.height;

	m_bufferCount = settings.buffers;
	m_texture = new vsTexture*[m_bufferCount];
	for ( int i = 0; i < settings.buffers; i++ )
	{
		vsString name = vsFormatString("RenderTarget%d", s_renderTargetCount++);
		vsTextureInternal *ti = new vsTextureInternal(name, m_textureSurface, i, (t == Type_Depth));
		vsTextureManager::Instance()->Add(ti);
		m_texture[i] = new vsTexture(name);
	}

	Clear();
}
Esempio n. 17
0
vsFile::vsFile( const vsString &filename, vsFile::Mode mode ):
	m_mode(mode),
	m_length(0)
{
	vsAssert( !DirectoryExists(filename), vsFormatString("Attempted to open directory '%s' as a plain file", filename.c_str()) );

	if ( mode == MODE_Read )
		m_file = PHYSFS_openRead( filename.c_str() );
	else
		m_file = PHYSFS_openWrite( filename.c_str() );

	if ( m_file )
	{
		m_length = (size_t)PHYSFS_fileLength(m_file);
	}

	vsAssert( m_file != NULL, STR("Error opening file '%s':  %s", filename.c_str(), PHYSFS_getLastError()) );
}
Esempio n. 18
0
vsString
vsFile::GetFullFilename(const vsString &filename_in)
{
#if TARGET_OS_IPHONE
	vsString filename = filename_in;

	// find the slash, if any.
	int pos = filename.rfind("/");
	if ( pos != vsString::npos )
	{
		filename.erase(0,pos+1);
	}

	vsString result = vsFormatString("./%s",filename.c_str());
	return result;
#else
	vsString filename(filename_in);
	vsString dir = PHYSFS_getRealDir( filename.c_str() );
	return dir + "/" + filename;
#endif
}