2003-01-15 05:38:57 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
This file is Part of the ZEngine Library for 2D game development.
|
|
|
|
Copyright (C) 2002, 2003 James Turk
|
|
|
|
|
|
|
|
Licensed under a BSD-style license.
|
|
|
|
|
|
|
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
|
|
|
and the home of this Library is http://www.zengine.sourceforge.net
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2003-05-07 20:34:50 +00:00
|
|
|
/**
|
2003-01-16 04:47:35 +00:00
|
|
|
\file ZE_Utility.cpp
|
2003-01-15 05:38:57 +00:00
|
|
|
\brief Source file for ZEngine utility functions.
|
|
|
|
|
|
|
|
Source file containing open utilities for use inside and alongside ZEngine.
|
2003-06-11 05:51:15 +00:00
|
|
|
<br>$Id: ZE_Utility.cpp,v 1.9 2003/06/11 05:51:15 cozman Exp $<br>
|
2003-05-07 20:34:50 +00:00
|
|
|
\author James Turk
|
2003-01-15 05:38:57 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
#include "ZE_Utility.h"
|
|
|
|
|
|
|
|
namespace ZE
|
|
|
|
{
|
|
|
|
|
2003-06-11 00:15:07 +00:00
|
|
|
std::string FormatStr(const char *fmtstr, ...)
|
2003-01-15 05:38:57 +00:00
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
va_list args;
|
2003-06-11 05:51:15 +00:00
|
|
|
//simply puts args into the buffer using standard parsing rules
|
2003-01-15 05:38:57 +00:00
|
|
|
va_start(args,fmtstr);
|
|
|
|
vsprintf(buf, fmtstr, args);
|
|
|
|
va_end(args);
|
|
|
|
return buf;
|
|
|
|
}
|
2003-01-16 04:42:04 +00:00
|
|
|
|
2003-06-11 05:51:15 +00:00
|
|
|
//Each of the Free*s safely frees & NULLs the pointer
|
2003-04-28 02:00:38 +00:00
|
|
|
void FreeImage(SDL_Surface *&image)
|
|
|
|
{
|
|
|
|
if(image)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(image);
|
|
|
|
image = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_SDL_MIXER
|
|
|
|
|
|
|
|
void FreeSound(Mix_Chunk *&chunk)
|
|
|
|
{
|
|
|
|
if(chunk)
|
|
|
|
{
|
|
|
|
Mix_FreeChunk(chunk);
|
|
|
|
chunk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeMusic(Mix_Music *&music)
|
|
|
|
{
|
|
|
|
if(music)
|
|
|
|
{
|
|
|
|
Mix_FreeMusic(music);
|
|
|
|
music = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SDL_TTF
|
|
|
|
|
|
|
|
void FreeFont(TTF_Font *&font)
|
|
|
|
{
|
|
|
|
if(font)
|
|
|
|
{
|
|
|
|
TTF_CloseFont(font);
|
|
|
|
font = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2003-01-19 01:03:57 +00:00
|
|
|
}
|
|
|
|
|