full review of source
This commit is contained in:
parent
7c63dd9981
commit
ad671c3e13
@ -13,7 +13,7 @@
|
|||||||
\brief Definition file for core ZEngine class.
|
\brief Definition file for core ZEngine class.
|
||||||
|
|
||||||
ZEngine Game Engine core Engine definition.
|
ZEngine Game Engine core Engine definition.
|
||||||
<br>$Id: ZE_ZEngine.h,v 1.40 2003/06/11 00:15:25 cozman Exp $<br>
|
<br>$Id: ZE_ZEngine.h,v 1.41 2003/06/11 05:51:32 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ class ZEngine
|
|||||||
//! Option controlling how logfile is used.
|
//! Option controlling how logfile is used.
|
||||||
bool mLogAllErrors;
|
bool mLogAllErrors;
|
||||||
//! C-style FILE* for error logging.
|
//! C-style FILE* for error logging.
|
||||||
FILE *mErrlog;
|
std::FILE *mErrlog;
|
||||||
//! Event filter, for users who need to process their own events.
|
//! Event filter, for users who need to process their own events.
|
||||||
SDL_EventFilter mEventFilter;
|
SDL_EventFilter mEventFilter;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
Definition file for ZError, the Error logging class for ZEngine.
|
Definition file for ZError, the Error logging class for ZEngine.
|
||||||
This class should never be used by the average user, it is used by ZEngine to store information on an error.
|
This class should never be used by the average user, it is used by ZEngine to store information on an error.
|
||||||
<br>$Id: ZE_ZError.h,v 1.11 2003/06/11 00:15:25 cozman Exp $<br>
|
<br>$Id: ZE_ZError.h,v 1.12 2003/06/11 05:51:32 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -102,13 +102,6 @@ class ZError
|
|||||||
**/
|
**/
|
||||||
ZError(ZErrorCode code=ZERR_NONE, std::string desc="", std::string file="", int line=0);
|
ZError(ZErrorCode code=ZERR_NONE, std::string desc="", std::string file="", int line=0);
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief Virtual Destructor.
|
|
||||||
|
|
||||||
Virtual destructor making future inheritance safe.
|
|
||||||
**/
|
|
||||||
virtual ~ZError();
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Set members of error object.
|
\brief Set members of error object.
|
||||||
|
|
||||||
|
@ -121,8 +121,9 @@ class ZFont
|
|||||||
\param r Red component of color (0-255).
|
\param r Red component of color (0-255).
|
||||||
\param g Green component of color (0-255).
|
\param g Green component of color (0-255).
|
||||||
\param b Blue component of color (0-255).
|
\param b Blue component of color (0-255).
|
||||||
|
\param a Alpha component of drawn font, including background if present. (0-255) (Optional, defaults to 255.)
|
||||||
**/
|
**/
|
||||||
void SetColor(Uint8 r, Uint8 g, Uint8 b);
|
void SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Set Background rColor.
|
\brief Set Background rColor.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Implementation file for VersinInfo class, simple class for containing and comparing
|
Implementation file for VersinInfo class, simple class for containing and comparing
|
||||||
version numbers.
|
version numbers.
|
||||||
<br>$Id: VersionInfo.cpp,v 1.3 2003/06/11 00:15:07 cozman Exp $<br>
|
<br>$Id: VersionInfo.cpp,v 1.4 2003/06/11 05:51:15 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ std::string VersionInfo::GetString() const
|
|||||||
|
|
||||||
bool VersionInfo::operator<(const VersionInfo &rhs) const
|
bool VersionInfo::operator<(const VersionInfo &rhs) const
|
||||||
{
|
{
|
||||||
|
//chained compares, compare numbers in order of importance
|
||||||
if(this->major < rhs.major)
|
if(this->major < rhs.major)
|
||||||
return true;
|
return true;
|
||||||
else if(this->major == rhs.major)
|
else if(this->major == rhs.major)
|
||||||
@ -38,24 +39,19 @@ bool VersionInfo::operator<(const VersionInfo &rhs) const
|
|||||||
return true;
|
return true;
|
||||||
else if(this->release == rhs.release)
|
else if(this->release == rhs.release)
|
||||||
{
|
{
|
||||||
if(this->extra.length() == 0 && rhs.extra.length() != 0)
|
return this->extra < rhs.extra; //just compare the strings at the end
|
||||||
return true;
|
|
||||||
else if(this->extra.length() && rhs.extra.length())
|
|
||||||
{
|
|
||||||
return this->extra[0] < rhs.extra[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return false; //if it reaches this point rhs is >=
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VersionInfo::operator==(const VersionInfo &rhs) const
|
bool VersionInfo::operator==(const VersionInfo &rhs) const
|
||||||
{
|
{
|
||||||
return this->GetString() == rhs.GetString();
|
return this->GetString() == rhs.GetString(); //only equal data produces equal strings
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VersionInfo::operator>(const VersionInfo &rhs) const
|
bool VersionInfo::operator>(const VersionInfo &rhs) const
|
||||||
{
|
{
|
||||||
return !((*this) < rhs || (*this) == rhs);
|
return !((*this) < rhs || (*this) == rhs); //if not < and not ==, must be >
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZEngine utility functions.
|
\brief Source file for ZEngine utility functions.
|
||||||
|
|
||||||
Source file containing open utilities for use inside and alongside ZEngine.
|
Source file containing open utilities for use inside and alongside ZEngine.
|
||||||
<br>$Id: ZE_Utility.cpp,v 1.8 2003/06/11 00:15:08 cozman Exp $<br>
|
<br>$Id: ZE_Utility.cpp,v 1.9 2003/06/11 05:51:15 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -26,13 +26,14 @@ std::string FormatStr(const char *fmtstr, ...)
|
|||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
va_list args;
|
va_list args;
|
||||||
|
//simply puts args into the buffer using standard parsing rules
|
||||||
va_start(args,fmtstr);
|
va_start(args,fmtstr);
|
||||||
vsprintf(buf, fmtstr, args);
|
vsprintf(buf, fmtstr, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Each of the Free*s safely frees & NULLs the pointer
|
||||||
void FreeImage(SDL_Surface *&image)
|
void FreeImage(SDL_Surface *&image)
|
||||||
{
|
{
|
||||||
if(image)
|
if(image)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZClient.
|
\brief Source file for ZClient.
|
||||||
|
|
||||||
Implementation file for ZClient, the TCP Client class for ZEngine.
|
Implementation file for ZClient, the TCP Client class for ZEngine.
|
||||||
<br>$Id: ZE_ZClient.cpp,v 1.8 2003/06/11 00:15:08 cozman Exp $<br>
|
<br>$Id: ZE_ZClient.cpp,v 1.9 2003/06/11 05:51:15 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ std::string num2dotted4(unsigned int num)
|
|||||||
int d=16777216; //2^24
|
int d=16777216; //2^24
|
||||||
int m;
|
int m;
|
||||||
|
|
||||||
|
//the dotted IP a.b.c.d = a256^3+b256^2+c256+d, this is the numeric ip algorithm in reverse
|
||||||
while(d > 0)
|
while(d > 0)
|
||||||
{
|
{
|
||||||
m = num/d;
|
m = num/d;
|
||||||
@ -41,13 +42,13 @@ std::string num2dotted4(unsigned int num)
|
|||||||
return FormatStr("%d.%d.%d.%d",ip[3],ip[2],ip[1],ip[0]);
|
return FormatStr("%d.%d.%d.%d",ip[3],ip[2],ip[1],ip[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZClient::ZClient(bool verbose)
|
ZClient::ZClient(bool verbose) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rSocket(NULL),
|
||||||
|
rSocketSet(NULL),
|
||||||
|
rVerbose(verbose),
|
||||||
|
rWaitTime(0)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rSocket = NULL;
|
|
||||||
rSocketSet = NULL;
|
|
||||||
rVerbose = verbose;
|
|
||||||
rWaitTime = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZClient::~ZClient()
|
ZClient::~ZClient()
|
||||||
@ -59,6 +60,7 @@ bool ZClient::Connect(char *server, Uint16 port)
|
|||||||
{
|
{
|
||||||
IPaddress ip;
|
IPaddress ip;
|
||||||
|
|
||||||
|
//see if the IP is reachable
|
||||||
if(SDLNet_ResolveHost(&ip,server,port) < 0)
|
if(SDLNet_ResolveHost(&ip,server,port) < 0)
|
||||||
rEngine->ReportError(ZERR_NET_CLIENT,FormatStr("Failed to resolve host: %s:%d",server,port));
|
rEngine->ReportError(ZERR_NET_CLIENT,FormatStr("Failed to resolve host: %s:%d",server,port));
|
||||||
else if(rVerbose)
|
else if(rVerbose)
|
||||||
@ -113,6 +115,7 @@ bool ZClient::Send(ZByte *data, int size)
|
|||||||
{
|
{
|
||||||
sent = SDLNet_TCP_Send(rSocket,data,size);
|
sent = SDLNet_TCP_Send(rSocket,data,size);
|
||||||
|
|
||||||
|
//send < size means that entire packet didn't send.. which is a problem
|
||||||
if(sent < size)
|
if(sent < size)
|
||||||
{
|
{
|
||||||
rEngine->ReportError(ZERR_NET_CLIENT,FormatStr("Failed to send data, closing socket: %s", SDLNet_GetError()));
|
rEngine->ReportError(ZERR_NET_CLIENT,FormatStr("Failed to send data, closing socket: %s", SDLNet_GetError()));
|
||||||
@ -137,8 +140,10 @@ int ZClient::Receive(ZByte *data)
|
|||||||
|
|
||||||
if(rSocket)
|
if(rSocket)
|
||||||
{
|
{
|
||||||
|
//check if data is waiting on the socket
|
||||||
if(SDLNet_CheckSockets(rSocketSet, rWaitTime) > 0 && SDLNet_SocketReady(rSocket))
|
if(SDLNet_CheckSockets(rSocketSet, rWaitTime) > 0 && SDLNet_SocketReady(rSocket))
|
||||||
{
|
{
|
||||||
|
//if recieved 0 (data was waiting) something happened
|
||||||
received = SDLNet_TCP_Recv(rSocket,data,MAX_MSG_LEN);
|
received = SDLNet_TCP_Recv(rSocket,data,MAX_MSG_LEN);
|
||||||
if(received <= 0)
|
if(received <= 0)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZConfigFile.
|
\brief Source file for ZConfigFile.
|
||||||
|
|
||||||
Implementation of ZConfigFile, the ZEngine INI-Style Config File.
|
Implementation of ZConfigFile, the ZEngine INI-Style Config File.
|
||||||
<br>$Id: ZE_ZConfigFile.cpp,v 1.11 2003/06/11 00:15:08 cozman Exp $<br>
|
<br>$Id: ZE_ZConfigFile.cpp,v 1.12 2003/06/11 05:51:15 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -30,12 +30,12 @@ std::string ZConfigFile::CleanString(std::string str) const
|
|||||||
//cycle through, only copy spaces and if a character is uppercase, convert it to lowercase
|
//cycle through, only copy spaces and if a character is uppercase, convert it to lowercase
|
||||||
for(std::string::size_type i = 0; i < str.length(); ++i)
|
for(std::string::size_type i = 0; i < str.length(); ++i)
|
||||||
{
|
{
|
||||||
if(!isspace(str[i]) || inQuotes)
|
if(!std::isspace(str[i]) || inQuotes) //if it's in quotes leave it be
|
||||||
{
|
{
|
||||||
if(str[i] == '\"')
|
if(str[i] == '\"')
|
||||||
inQuotes = !inQuotes;
|
inQuotes = !inQuotes; //each quote toggles the quote state
|
||||||
if(isupper(str[i]) && !inQuotes)
|
if(std::isupper(str[i]) && !inQuotes)
|
||||||
str[i] = static_cast<char>(tolower(str[i]));
|
str[i] = static_cast<char>(std::tolower(str[i]));
|
||||||
tmpStr += str[i];
|
tmpStr += str[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,6 +48,7 @@ bool ZConfigFile::Exists(std::string sec) const
|
|||||||
|
|
||||||
sec = CleanString(sec);
|
sec = CleanString(sec);
|
||||||
|
|
||||||
|
//check list for 'cleaned' version of string
|
||||||
for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter)
|
for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter)
|
||||||
{
|
{
|
||||||
if(CleanString((*secIter).section) == sec)
|
if(CleanString((*secIter).section) == sec)
|
||||||
@ -64,6 +65,7 @@ bool ZConfigFile::Exists(std::string sec, std::string var) const
|
|||||||
sec = CleanString(sec);
|
sec = CleanString(sec);
|
||||||
var = CleanString(var);
|
var = CleanString(var);
|
||||||
|
|
||||||
|
//first find section, then do same search for variable
|
||||||
for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter)
|
for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter)
|
||||||
{
|
{
|
||||||
if(CleanString((*secIter).section) == sec)
|
if(CleanString((*secIter).section) == sec)
|
||||||
@ -83,19 +85,19 @@ void ZConfigFile::SetVariable(std::string sec, std::string var, std::string val)
|
|||||||
std::list<ZCF_Section>::iterator secIter;
|
std::list<ZCF_Section>::iterator secIter;
|
||||||
std::list<ZCF_Variable>::iterator varIter;
|
std::list<ZCF_Variable>::iterator varIter;
|
||||||
|
|
||||||
if(Exists(CleanString(sec)))
|
if(Exists(CleanString(sec))) //if section exists find it
|
||||||
{
|
{
|
||||||
sec = CleanString(sec);
|
sec = CleanString(sec);
|
||||||
for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter)
|
for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter)
|
||||||
{
|
{
|
||||||
if(CleanString((*secIter).section) == sec) //if this is the section
|
if(CleanString((*secIter).section) == sec) //if this is the section
|
||||||
{
|
{
|
||||||
if(Exists(sec,var))
|
if(Exists(sec,var)) //if variable exists find it
|
||||||
{
|
{
|
||||||
var = CleanString(var);
|
var = CleanString(var);
|
||||||
for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter)
|
for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter)
|
||||||
{
|
{
|
||||||
if(CleanString((*varIter).var) == var) //if this is the variable
|
if(CleanString((*varIter).var) == var) //once variable found, set value
|
||||||
{
|
{
|
||||||
(*varIter).val = val;
|
(*varIter).val = val;
|
||||||
break; //break from this loop
|
break; //break from this loop
|
||||||
@ -124,6 +126,7 @@ void ZConfigFile::SetVariable(std::string sec, std::string var, std::string val)
|
|||||||
|
|
||||||
std::string ZConfigFile::GetVariable(std::string sec, std::string var, std::string defVal) const
|
std::string ZConfigFile::GetVariable(std::string sec, std::string var, std::string defVal) const
|
||||||
{
|
{
|
||||||
|
//finds variable in same manner as SetVariable, but if not found doesn't create, just returns default value
|
||||||
std::list<ZCF_Section>::const_iterator secIter;
|
std::list<ZCF_Section>::const_iterator secIter;
|
||||||
std::list<ZCF_Variable>::const_iterator varIter;
|
std::list<ZCF_Variable>::const_iterator varIter;
|
||||||
|
|
||||||
@ -157,11 +160,13 @@ std::string ZConfigFile::GetVariable(std::string sec, std::string var, std::stri
|
|||||||
return defVal; //if it gets to the end just return the default
|
return defVal; //if it gets to the end just return the default
|
||||||
}
|
}
|
||||||
|
|
||||||
ZConfigFile::ZConfigFile() {}
|
ZConfigFile::ZConfigFile()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ZConfigFile::ZConfigFile(std::string rFilename)
|
ZConfigFile::ZConfigFile(std::string rFilename)
|
||||||
{
|
{
|
||||||
Process(rFilename);
|
Process(rFilename); //process does all the work
|
||||||
}
|
}
|
||||||
|
|
||||||
ZConfigFile::~ZConfigFile()
|
ZConfigFile::~ZConfigFile()
|
||||||
@ -176,9 +181,9 @@ void ZConfigFile::Process(std::string filename)
|
|||||||
std::ifstream cfile(rFilename.c_str());
|
std::ifstream cfile(rFilename.c_str());
|
||||||
std::string section, str, var, tmp;
|
std::string section, str, var, tmp;
|
||||||
|
|
||||||
rFileLayout.clear();
|
rFileLayout.clear(); //layout must be cleared, in case variable is being used multiple times
|
||||||
|
|
||||||
while(!cfile.eof() && cfile.is_open())
|
while(!cfile.eof() && cfile.is_open()) //parses entire file
|
||||||
{
|
{
|
||||||
std::getline(cfile,str); //read in a line
|
std::getline(cfile,str); //read in a line
|
||||||
tmp = CleanString(str); //get a clean version
|
tmp = CleanString(str); //get a clean version
|
||||||
@ -195,6 +200,7 @@ void ZConfigFile::Process(std::string filename)
|
|||||||
cfile.close();
|
cfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//each get* gets the variable (stored as a string) from using GetVariable, then converts it to the desired format
|
||||||
float ZConfigFile::GetFloat(std::string section, std::string var, float defVal) const
|
float ZConfigFile::GetFloat(std::string section, std::string var, float defVal) const
|
||||||
{
|
{
|
||||||
std::string val;
|
std::string val;
|
||||||
@ -273,6 +279,7 @@ std::string ZConfigFile::GetString(std::string section, std::string var, std::st
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//each set* converts it's variable to a string, then places it in using SetVariable
|
||||||
void ZConfigFile::SetFloat(std::string section, std::string var, float val)
|
void ZConfigFile::SetFloat(std::string section, std::string var, float val)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
@ -315,6 +322,7 @@ void ZConfigFile::Flush()
|
|||||||
//in case the filename is already cleared somehow
|
//in case the filename is already cleared somehow
|
||||||
if(rFilename.length())
|
if(rFilename.length())
|
||||||
{
|
{
|
||||||
|
//open the file blanked out, to not duplicate entries
|
||||||
std::ofstream cfile(rFilename.c_str(), std::ios::out|std::ios::trunc);
|
std::ofstream cfile(rFilename.c_str(), std::ios::out|std::ios::trunc);
|
||||||
|
|
||||||
if(cfile)
|
if(cfile)
|
||||||
@ -343,7 +351,7 @@ void ZConfigFile::Flush()
|
|||||||
|
|
||||||
void ZConfigFile::Close()
|
void ZConfigFile::Close()
|
||||||
{
|
{
|
||||||
Flush();
|
Flush(); //when the file is closed it should be flushed to disk
|
||||||
rFilename = "";
|
rFilename = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Central source file for ZEngine.
|
\brief Central source file for ZEngine.
|
||||||
|
|
||||||
Actual implementation of ZEngine singleton class, the core of ZEngine.
|
Actual implementation of ZEngine singleton class, the core of ZEngine.
|
||||||
<br>$Id: ZE_ZEngine.cpp,v 1.45 2003/06/11 00:15:08 cozman Exp $<br>
|
<br>$Id: ZE_ZEngine.cpp,v 1.46 2003/06/11 05:51:15 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -25,46 +25,30 @@ namespace ZE
|
|||||||
VersionInfo ZEngine::Version(0,8,4,"dev");
|
VersionInfo ZEngine::Version(0,8,4,"dev");
|
||||||
ZEngine *ZEngine::sInstance=NULL;
|
ZEngine *ZEngine::sInstance=NULL;
|
||||||
|
|
||||||
ZEngine::ZEngine()
|
ZEngine::ZEngine() :
|
||||||
{
|
mInitialized(false), mWidth(800), mHeight(600), mBPP(-1), mFullscreen(true),
|
||||||
mInitialized = false;
|
|
||||||
mWidth = 800;
|
|
||||||
mHeight = 600;
|
|
||||||
mBPP = -1;
|
|
||||||
mFullscreen = true;
|
|
||||||
|
|
||||||
#ifdef USE_SDL_MIXER
|
#ifdef USE_SDL_MIXER
|
||||||
mRate = 22050;
|
mRate(22050), mStereo(false),
|
||||||
mStereo = false;
|
|
||||||
#endif
|
#endif
|
||||||
mNeedReload = false;
|
mNeedReload(false),mScreen(NULL),
|
||||||
|
mEventFilter(NULL), mActive(false), mQuit(false), mKeyIsPressed(NULL),
|
||||||
mScreen = NULL;
|
mMouseX(0), mMouseY(0), mMouseB(0),
|
||||||
|
mUnpauseOnActive(false), mPaused(false),
|
||||||
mEventFilter = NULL;
|
mDesiredFramerate(0), mNextUpdate(0), mLastPause(0), mPausedTime(0), mLastTime(0),
|
||||||
mActive = mQuit = false;
|
mSecPerFrame(0.0),
|
||||||
mKeyIsPressed = NULL;
|
mLogAllErrors(true), mErrlog(stderr)
|
||||||
mMouseX = mMouseY = 0;
|
{
|
||||||
mMouseB = 0;
|
|
||||||
|
|
||||||
for(int k = 0; k < SDLK_LAST; ++k)
|
for(int k = 0; k < SDLK_LAST; ++k)
|
||||||
mKeyPress[k] = false;
|
mKeyPress[k] = false;
|
||||||
|
|
||||||
mUnpauseOnActive = mPaused = false;
|
|
||||||
mDesiredFramerate = 0;
|
|
||||||
mNextUpdate = mLastPause = mPausedTime = mLastTime = 0;
|
|
||||||
mSecPerFrame = 0.0;
|
|
||||||
|
|
||||||
ZError::CreateStringTable();
|
ZError::CreateStringTable();
|
||||||
mLogAllErrors = true;
|
|
||||||
mErrlog = stderr;
|
|
||||||
|
|
||||||
SeedRandom(static_cast<unsigned long>(time(NULL)));
|
SeedRandom(static_cast<unsigned long>(time(NULL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEngine* ZEngine::GetInstance()
|
ZEngine* ZEngine::GetInstance()
|
||||||
{
|
{
|
||||||
if(!sInstance)
|
if(!sInstance) //first time through, gets new instance, each time after returns same one
|
||||||
sInstance = new ZEngine;
|
sInstance = new ZEngine;
|
||||||
|
|
||||||
return sInstance;
|
return sInstance;
|
||||||
@ -74,7 +58,7 @@ void ZEngine::ReleaseInstance()
|
|||||||
{
|
{
|
||||||
if(sInstance)
|
if(sInstance)
|
||||||
{
|
{
|
||||||
ZError::DestroyStringTable();
|
ZError::DestroyStringTable(); //part of fix to memory leak with static members
|
||||||
sInstance->CloseDisplay();
|
sInstance->CloseDisplay();
|
||||||
delete sInstance;
|
delete sInstance;
|
||||||
}
|
}
|
||||||
@ -107,6 +91,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
|
|||||||
|
|
||||||
if(!mInitialized)
|
if(!mInitialized)
|
||||||
{
|
{
|
||||||
|
//audio initialized just in case, must be initialized w/ video to work so InitSubsystem wasn't an option
|
||||||
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0)
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0)
|
||||||
{
|
{
|
||||||
ReportError(ZERR_SDL_INIT,SDL_GetError());
|
ReportError(ZERR_SDL_INIT,SDL_GetError());
|
||||||
@ -134,7 +119,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
|
|||||||
ReportError(ZERR_VIDMODE,FormatStr("%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",mBPP));
|
ReportError(ZERR_VIDMODE,FormatStr("%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",mBPP));
|
||||||
mBPP = -1;
|
mBPP = -1;
|
||||||
}
|
}
|
||||||
else
|
else //this decides correcr BPP
|
||||||
{
|
{
|
||||||
if(mBPP == -1)
|
if(mBPP == -1)
|
||||||
mBPP = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
|
mBPP = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
|
||||||
@ -152,6 +137,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//buffer sizes
|
||||||
switch (mBPP)
|
switch (mBPP)
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
@ -172,6 +158,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//key GL attributes
|
||||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
|
||||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
|
||||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
|
||||||
@ -297,7 +284,7 @@ void ZEngine::ToggleFullscreen()
|
|||||||
else
|
else
|
||||||
CreateDisplay(title);
|
CreateDisplay(title);
|
||||||
#endif
|
#endif
|
||||||
SetReloadNeed(true);
|
SetReloadNeed(true); //images need to be reloaded on fullscreen swap
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZEngine::Initialized()
|
bool ZEngine::Initialized()
|
||||||
@ -314,9 +301,11 @@ void ZEngine::Update()
|
|||||||
{
|
{
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
|
|
||||||
|
//keeps track of spf//
|
||||||
mSecPerFrame = (GetTime()-mLastTime)/1000.0;
|
mSecPerFrame = (GetTime()-mLastTime)/1000.0;
|
||||||
mLastTime = GetTime();
|
mLastTime = GetTime();
|
||||||
|
|
||||||
|
//framerate limiting//
|
||||||
if(mDesiredFramerate)
|
if(mDesiredFramerate)
|
||||||
{
|
{
|
||||||
if(mLastTime < mNextUpdate)
|
if(mLastTime < mNextUpdate)
|
||||||
@ -334,15 +323,17 @@ void ZEngine::Clear(float red, float green, float blue, float alpha)
|
|||||||
|
|
||||||
void ZEngine::SetGL2D()
|
void ZEngine::SetGL2D()
|
||||||
{
|
{
|
||||||
|
//disable unused features for 2D//
|
||||||
glPushAttrib(GL_ENABLE_BIT);
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
/* This allows alpha blending of 2D textures with the scene*/
|
// This allows alpha blending of 2D textures with the scene //
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
//setup viewport & ortho mode to emulate standard 2D API conventions
|
||||||
glViewport(0, 0, mWidth, mHeight);
|
glViewport(0, 0, mWidth, mHeight);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
@ -363,7 +354,7 @@ void ZEngine::Delay(Uint32 milliseconds)
|
|||||||
|
|
||||||
Uint32 ZEngine::GetTime()
|
Uint32 ZEngine::GetTime()
|
||||||
{
|
{
|
||||||
if(mPaused)
|
if(mPaused) //when paused time hasn't been added to mPausedTime
|
||||||
return SDL_GetTicks() - (mPausedTime + (SDL_GetTicks() - mLastPause));
|
return SDL_GetTicks() - (mPausedTime + (SDL_GetTicks() - mLastPause));
|
||||||
else
|
else
|
||||||
return SDL_GetTicks() - mPausedTime;
|
return SDL_GetTicks() - mPausedTime;
|
||||||
@ -382,6 +373,7 @@ void ZEngine::UnpauseTimer()
|
|||||||
{
|
{
|
||||||
if(mPaused)
|
if(mPaused)
|
||||||
{
|
{
|
||||||
|
//mPaused time accumulates total time engine has been paused in all pauses
|
||||||
mPausedTime += (SDL_GetTicks() - mLastPause);
|
mPausedTime += (SDL_GetTicks() - mLastPause);
|
||||||
mPaused = false;
|
mPaused = false;
|
||||||
}
|
}
|
||||||
@ -394,7 +386,7 @@ double ZEngine::GetFrameTime()
|
|||||||
|
|
||||||
double ZEngine::GetFramerate()
|
double ZEngine::GetFramerate()
|
||||||
{
|
{
|
||||||
return mSecPerFrame ? 1/mSecPerFrame : 0;
|
return mSecPerFrame ? 1/mSecPerFrame : 0; //avoid /0
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::SetDesiredFramerate(Uint8 rate)
|
void ZEngine::SetDesiredFramerate(Uint8 rate)
|
||||||
@ -450,7 +442,7 @@ bool ZEngine::KeyIsPressed(SDLKey key)
|
|||||||
bool ZEngine::KeyPress(SDLKey key)
|
bool ZEngine::KeyPress(SDLKey key)
|
||||||
{
|
{
|
||||||
bool temp = mKeyPress[key];
|
bool temp = mKeyPress[key];
|
||||||
mKeyPress[key] = false;
|
mKeyPress[key] = false; //checking removes the press, this is used to detect single presses
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,6 +478,7 @@ bool ZEngine::RButtonPressed()
|
|||||||
|
|
||||||
bool ZEngine::MouseInRect(SDL_Rect *rect)
|
bool ZEngine::MouseInRect(SDL_Rect *rect)
|
||||||
{
|
{
|
||||||
|
//useful function, needed so much it made it in
|
||||||
return (mMouseX >= rect->x && mMouseX <= rect->x+rect->w &&
|
return (mMouseX >= rect->x && mMouseX <= rect->x+rect->w &&
|
||||||
mMouseY >= rect->y && mMouseY <= rect->y+rect->h);
|
mMouseY >= rect->y && mMouseY <= rect->y+rect->h);
|
||||||
}
|
}
|
||||||
@ -498,8 +491,9 @@ void ZEngine::CheckEvents()
|
|||||||
{
|
{
|
||||||
if(!mEventFilter || mEventFilter(&event)) //if the filter returns 0 it is removing the event, it will not be processed
|
if(!mEventFilter || mEventFilter(&event)) //if the filter returns 0 it is removing the event, it will not be processed
|
||||||
{
|
{
|
||||||
switch(event.type)
|
switch(event.type) //only certain events are handled, mEventFilter can handle user requests
|
||||||
{
|
{
|
||||||
|
//these events try and catch all video changes, for potential surface loss
|
||||||
case SDL_VIDEOEXPOSE:
|
case SDL_VIDEOEXPOSE:
|
||||||
case SDL_ACTIVEEVENT:
|
case SDL_ACTIVEEVENT:
|
||||||
if(event.active.state & SDL_APPACTIVE || event.active.state & SDL_APPINPUTFOCUS)
|
if(event.active.state & SDL_APPACTIVE || event.active.state & SDL_APPINPUTFOCUS)
|
||||||
@ -525,6 +519,7 @@ void ZEngine::CheckEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
//SDL_KEYDOWN/UP messages manipulate the mKeyPress array, used for single presses
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
mKeyPress[event.key.keysym.sym] = true;
|
mKeyPress[event.key.keysym.sym] = true;
|
||||||
break;
|
break;
|
||||||
@ -540,7 +535,7 @@ void ZEngine::CheckEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mKeyIsPressed = SDL_GetKeyState(NULL); //recommended but not needed (says Sam)
|
mKeyIsPressed = SDL_GetKeyState(NULL); //recommended but not needed (says Sam on the list)
|
||||||
|
|
||||||
//Alt-X or Alt-F4
|
//Alt-X or Alt-F4
|
||||||
if((mKeyIsPressed[SDLK_x] || mKeyIsPressed[SDLK_F4]) &&
|
if((mKeyIsPressed[SDLK_x] || mKeyIsPressed[SDLK_F4]) &&
|
||||||
@ -562,9 +557,11 @@ void ZEngine::InitPhysFS(std::string argv)
|
|||||||
std::string::size_type pos;
|
std::string::size_type pos;
|
||||||
PHYSFS_init(argv.c_str());
|
PHYSFS_init(argv.c_str());
|
||||||
|
|
||||||
pos = argv.rfind(PHYSFS_getDirSeparator());
|
//example c:/home/games/agame/bin/agame.exe rfind finds the slash before the exe
|
||||||
|
//and the substr returns the root dir: c:/home/games/agame/bin/
|
||||||
|
pos = argv.rfind(PHYSFS_getDirSeparator()); //find last slash
|
||||||
if(pos != std::string::npos)
|
if(pos != std::string::npos)
|
||||||
AddPhysFSDir(argv.substr(0,pos));
|
AddPhysFSDir(argv.substr(0,pos)); //everything up to last slash
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::AddPhysFSDir(std::string dir)
|
void ZEngine::AddPhysFSDir(std::string dir)
|
||||||
@ -579,12 +576,13 @@ void ZEngine::SetErrorLog(bool logAll, std::string logFile)
|
|||||||
mLogAllErrors = logAll;
|
mLogAllErrors = logAll;
|
||||||
if(logFile.length())
|
if(logFile.length())
|
||||||
{
|
{
|
||||||
|
//stderr & stdout are special cases, and should be directed to their appropriate streams
|
||||||
if(logFile == "stderr")
|
if(logFile == "stderr")
|
||||||
mErrlog = stderr;
|
mErrlog = stderr;
|
||||||
else if(logFile == "stdout")
|
else if(logFile == "stdout")
|
||||||
mErrlog = stdout;
|
mErrlog = stdout;
|
||||||
else
|
else
|
||||||
mErrlog = fopen(logFile.c_str(),"w");
|
mErrlog = std::fopen(logFile.c_str(),"w");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,7 +593,7 @@ void ZEngine::ReportError(ZErrorCode code, std::string desc, std::string file, u
|
|||||||
if(mLogAllErrors)
|
if(mLogAllErrors)
|
||||||
{
|
{
|
||||||
LogError(mCurError);
|
LogError(mCurError);
|
||||||
fflush(mErrlog);
|
std::fflush(mErrlog);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mErrorQueue.push(mCurError);
|
mErrorQueue.push(mCurError);
|
||||||
@ -610,18 +608,17 @@ ZErrorCode ZEngine::GetLastError()
|
|||||||
|
|
||||||
void ZEngine::WriteLog(std::string str)
|
void ZEngine::WriteLog(std::string str)
|
||||||
{
|
{
|
||||||
fprintf(mErrlog,str.c_str());
|
std::fprintf(mErrlog,str.c_str());
|
||||||
fprintf(mErrlog,"\n");
|
std::fprintf(mErrlog,"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::LogError(ZError error)
|
void ZEngine::LogError(ZError error)
|
||||||
{
|
{
|
||||||
fprintf(mErrlog,error.LogString().c_str());
|
std::fprintf(mErrlog,error.LogString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::FlushErrors()
|
void ZEngine::FlushErrors()
|
||||||
{
|
{
|
||||||
mCurError.Create(ZERR_NONE);
|
|
||||||
while(!mErrorQueue.empty())
|
while(!mErrorQueue.empty())
|
||||||
{
|
{
|
||||||
LogError(mErrorQueue.front());
|
LogError(mErrorQueue.front());
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZError.
|
\brief Source file for ZError.
|
||||||
|
|
||||||
Implementation of ZError, the ZEngine internal error information storage class.
|
Implementation of ZError, the ZEngine internal error information storage class.
|
||||||
<br>$Id: ZE_ZError.cpp,v 1.9 2003/06/11 00:15:09 cozman Exp $<br>
|
<br>$Id: ZE_ZError.cpp,v 1.10 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -28,6 +28,7 @@ void ZError::CreateStringTable()
|
|||||||
{
|
{
|
||||||
if(!sErrorDesc)
|
if(!sErrorDesc)
|
||||||
{
|
{
|
||||||
|
//create error strings
|
||||||
sErrorDesc = new std::string[ZERR_LAST];
|
sErrorDesc = new std::string[ZERR_LAST];
|
||||||
sErrorDesc[ZERR_NONE] = "No Error. [%s]";
|
sErrorDesc[ZERR_NONE] = "No Error. [%s]";
|
||||||
sErrorDesc[ZERR_SDL_INTERNAL] = "SDL Error. [%s]";
|
sErrorDesc[ZERR_SDL_INTERNAL] = "SDL Error. [%s]";
|
||||||
@ -59,15 +60,8 @@ void ZError::DestroyStringTable()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZError::ZError(ZErrorCode code, std::string desc, std::string file, int line)
|
ZError::ZError(ZErrorCode code, std::string desc, std::string file, int line) :
|
||||||
{
|
rCode(code), rDescription(desc), rFilename(file), rLine(line)
|
||||||
rCode = code;
|
|
||||||
rDescription = desc;
|
|
||||||
rFilename = file;
|
|
||||||
rLine = line;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZError::~ZError()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,13 +82,14 @@ std::string ZError::LogString() const
|
|||||||
{
|
{
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
|
//if there is a description be sure to integrate it
|
||||||
msg = rDescription.length() ? FormatStr(sErrorDesc[rCode].c_str(),rDescription.c_str()) : sErrorDesc[rCode];
|
msg = rDescription.length() ? FormatStr(sErrorDesc[rCode].c_str(),rDescription.c_str()) : sErrorDesc[rCode];
|
||||||
|
|
||||||
if(rLine != 0)
|
if(rLine != 0) //if there is a line (there is also a filename)
|
||||||
return FormatStr(" -%s(%d): %s\n",rFilename.c_str(),rLine,msg.c_str());
|
return FormatStr(" -%s(%d): %s\n",rFilename.c_str(),rLine,msg.c_str());
|
||||||
else if(rFilename.length())
|
else if(rFilename.length()) //no line, just filename
|
||||||
return FormatStr(" -%s: %s\n",rFilename.c_str(),msg.c_str());
|
return FormatStr(" -%s: %s\n",rFilename.c_str(),msg.c_str());
|
||||||
else
|
else //just the message
|
||||||
return FormatStr(" -%s\n",msg.c_str());
|
return FormatStr(" -%s\n",msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZFont.
|
\brief Source file for ZFont.
|
||||||
|
|
||||||
Implementation of ZFont, the basic Font class for ZEngine.
|
Implementation of ZFont, the basic Font class for ZEngine.
|
||||||
<br>$Id: ZE_ZFont.cpp,v 1.11 2003/06/11 00:15:09 cozman Exp $<br>
|
<br>$Id: ZE_ZFont.cpp,v 1.12 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -24,18 +24,18 @@
|
|||||||
namespace ZE
|
namespace ZE
|
||||||
{
|
{
|
||||||
|
|
||||||
ZFont::ZFont()
|
ZFont::ZFont() :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rFont(NULL)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rFont = NULL;
|
|
||||||
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
|
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
|
||||||
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
|
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZFont::ZFont(std::string filename, int size)
|
ZFont::ZFont(std::string filename, int size) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rFont(NULL)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rFont = NULL;
|
|
||||||
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
|
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
|
||||||
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
|
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
|
||||||
Open(filename,size);
|
Open(filename,size);
|
||||||
@ -49,6 +49,7 @@ ZFont::~ZFont()
|
|||||||
void ZFont::Open(std::string filename, int size)
|
void ZFont::Open(std::string filename, int size)
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
|
rFilename = filename;
|
||||||
rFont = rEngine->LoadFont(filename,size);
|
rFont = rEngine->LoadFont(filename,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,19 +60,22 @@ void ZFont::Release()
|
|||||||
|
|
||||||
void ZFont::DrawText(std::string text, ZImage &image) const
|
void ZFont::DrawText(std::string text, ZImage &image) const
|
||||||
{
|
{
|
||||||
image.Attach(TTF_RenderText_Solid(rFont, text.c_str(), rColor));
|
image.Attach(TTF_RenderText_Blended(rFont, text.c_str(), rColor));
|
||||||
|
image.SetAlpha(rColor.unused); //the images alpha comes from the SetColor a parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZFont::DrawShadedText(std::string text, ZImage &image) const
|
void ZFont::DrawShadedText(std::string text, ZImage &image) const
|
||||||
{
|
{
|
||||||
image.Attach(TTF_RenderText_Shaded(rFont, text.c_str(), rColor, rBGColor));
|
image.Attach(TTF_RenderText_Shaded(rFont, text.c_str(), rColor, rBGColor));
|
||||||
|
image.SetAlpha(rColor.unused);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZFont::SetColor(Uint8 r, Uint8 g, Uint8 b)
|
void ZFont::SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||||
{
|
{
|
||||||
rColor.r = r;
|
rColor.r = r;
|
||||||
rColor.g = g;
|
rColor.g = g;
|
||||||
rColor.b = b;
|
rColor.b = b;
|
||||||
|
rColor.unused = a; //used in DrawText and DrawBlendedText
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZFont::SetBGColor(Uint8 r, Uint8 g, Uint8 b)
|
void ZFont::SetBGColor(Uint8 r, Uint8 g, Uint8 b)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZImage.
|
\brief Source file for ZImage.
|
||||||
|
|
||||||
Implementation of ZImage, the Image class for ZEngine.
|
Implementation of ZImage, the Image class for ZEngine.
|
||||||
<br>$Id: ZE_ZImage.cpp,v 1.34 2003/06/11 00:15:09 cozman Exp $<br>
|
<br>$Id: ZE_ZImage.cpp,v 1.35 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -22,51 +22,51 @@
|
|||||||
namespace ZE
|
namespace ZE
|
||||||
{
|
{
|
||||||
|
|
||||||
ZImage::ZImage()
|
ZImage::ZImage() :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rImage(NULL),
|
||||||
|
rAlpha(255)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rImage = NULL;
|
|
||||||
rAlpha = 255;
|
|
||||||
Release();
|
Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZImage::ZImage(const ZImage &rhs)
|
ZImage::ZImage(const ZImage &rhs) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rImage(NULL),
|
||||||
|
rAlpha(rhs.Alpha())
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rImage = NULL;
|
|
||||||
rAlpha = rhs.Alpha();
|
|
||||||
OpenFromImage(rhs.Surface(),0,0,(Sint16)rhs.Width(),(Sint16)rhs.Height());
|
OpenFromImage(rhs.Surface(),0,0,(Sint16)rhs.Width(),(Sint16)rhs.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
ZImage::ZImage(std::string filename)
|
ZImage::ZImage(std::string filename) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rImage(NULL),
|
||||||
|
rAlpha(255)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rImage = NULL;
|
|
||||||
rAlpha = 255;
|
|
||||||
Open(filename);
|
Open(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZImage::ZImage(SDL_Surface *surface)
|
ZImage::ZImage(SDL_Surface *surface) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rImage(NULL),
|
||||||
|
rAlpha(255)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rImage = NULL;
|
|
||||||
rAlpha = 255;
|
|
||||||
Attach(surface);
|
Attach(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZImage::ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
|
ZImage::ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rImage(NULL),
|
||||||
|
rAlpha(255)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rImage = NULL;
|
|
||||||
rAlpha = 255;
|
|
||||||
OpenFromImage(img,x,y,w,h);
|
OpenFromImage(img,x,y,w,h);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZImage::ZImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
|
ZImage::ZImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rImage(NULL),
|
||||||
|
rAlpha(255)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rImage = NULL;
|
|
||||||
rAlpha = 255;
|
|
||||||
OpenFromImage(img.Surface(),x,y,w,h); //call SDL_Surface* version instead of taking the long way
|
OpenFromImage(img.Surface(),x,y,w,h); //call SDL_Surface* version instead of taking the long way
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,15 +116,16 @@ void ZImage::OpenFromImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint
|
|||||||
OpenFromImage(img.Surface(),x,y,w,h);
|
OpenFromImage(img.Surface(),x,y,w,h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//attach is really the core of ZImage, everything calls it, it converts SDL_Surface->OpenGL Texture->ZImage
|
||||||
void ZImage::Attach(SDL_Surface *surface)
|
void ZImage::Attach(SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
GLfloat coord[4];
|
GLfloat coord[4];
|
||||||
|
|
||||||
Release(); //avoid most user inflicted memory leaks
|
Release(); //avoid most user inflicted memory leaks associated with ZImage
|
||||||
|
|
||||||
//surface conversion//
|
//surface conversion//
|
||||||
SDL_Surface *temp = surface;
|
SDL_Surface *temp = surface;
|
||||||
surface = SDL_DisplayFormatAlpha(temp);
|
surface = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this
|
||||||
if(surface)
|
if(surface)
|
||||||
{
|
{
|
||||||
FreeImage(temp);
|
FreeImage(temp);
|
||||||
@ -139,7 +140,7 @@ void ZImage::Attach(SDL_Surface *surface)
|
|||||||
{
|
{
|
||||||
rWidth = surface->w;
|
rWidth = surface->w;
|
||||||
rHeight = surface->h;
|
rHeight = surface->h;
|
||||||
rTexID = SDL_GL_LoadTexture(surface,coord);
|
rTexID = SDL_GL_LoadTexture(surface,coord); //major helper, not written by me, found on libsdl.org
|
||||||
rTexMinX = coord[0];
|
rTexMinX = coord[0];
|
||||||
rTexMinY = coord[1];
|
rTexMinY = coord[1];
|
||||||
rTexMaxX = coord[2];
|
rTexMaxX = coord[2];
|
||||||
@ -152,6 +153,7 @@ void ZImage::Attach(SDL_Surface *surface)
|
|||||||
|
|
||||||
void ZImage::Reload()
|
void ZImage::Reload()
|
||||||
{
|
{
|
||||||
|
//this little hack helps to reload images to OpenGL surfaces after loss
|
||||||
SDL_Surface *temp = rImage;
|
SDL_Surface *temp = rImage;
|
||||||
rImage = NULL;
|
rImage = NULL;
|
||||||
Attach(temp);
|
Attach(temp);
|
||||||
@ -159,10 +161,9 @@ void ZImage::Reload()
|
|||||||
|
|
||||||
void ZImage::Release()
|
void ZImage::Release()
|
||||||
{
|
{
|
||||||
|
//set everything back the way it came
|
||||||
if(glIsTexture(rTexID))
|
if(glIsTexture(rTexID))
|
||||||
{
|
|
||||||
glDeleteTextures(1,&rTexID);
|
glDeleteTextures(1,&rTexID);
|
||||||
}
|
|
||||||
rTexMinX = rTexMinY = rTexMaxX = rTexMaxY = 0.0f;
|
rTexMinX = rTexMinY = rTexMaxX = rTexMaxY = 0.0f;
|
||||||
rTexID = rWidth = rHeight = 0;
|
rTexID = rWidth = rHeight = 0;
|
||||||
FreeImage(rImage);
|
FreeImage(rImage);
|
||||||
@ -175,7 +176,6 @@ void ZImage::SetAlpha(Uint8 alpha)
|
|||||||
|
|
||||||
void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
||||||
{
|
{
|
||||||
SDL_Surface *temp=NULL;
|
|
||||||
Uint32 color = SDL_MapRGB(rImage->format,red,green,blue);
|
Uint32 color = SDL_MapRGB(rImage->format,red,green,blue);
|
||||||
|
|
||||||
if(rImage)
|
if(rImage)
|
||||||
@ -183,11 +183,7 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
|||||||
if(SDL_SetColorKey(rImage, SDL_SRCCOLORKEY, color) < 0)
|
if(SDL_SetColorKey(rImage, SDL_SRCCOLORKEY, color) < 0)
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
||||||
else
|
else
|
||||||
{
|
Reload(); //do the reattach hack, this gets a new OpenGL surface for the same image
|
||||||
temp = rImage;
|
|
||||||
rImage = NULL;
|
|
||||||
Attach(temp); //do the reattach
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey");
|
rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey");
|
||||||
@ -196,12 +192,14 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
|||||||
void ZImage::Flip(bool horizontal, bool vertical)
|
void ZImage::Flip(bool horizontal, bool vertical)
|
||||||
{
|
{
|
||||||
GLfloat temp;
|
GLfloat temp;
|
||||||
|
//all that a flip does is invert the Min/Max coordinates
|
||||||
if(horizontal)
|
if(horizontal)
|
||||||
{
|
{
|
||||||
temp = rTexMinX;
|
temp = rTexMinX;
|
||||||
rTexMinX = rTexMaxX;
|
rTexMinX = rTexMaxX;
|
||||||
rTexMaxX = temp;
|
rTexMaxX = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vertical)
|
if(vertical)
|
||||||
{
|
{
|
||||||
temp = rTexMinY;
|
temp = rTexMinY;
|
||||||
@ -210,6 +208,7 @@ void ZImage::Flip(bool horizontal, bool vertical)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stretching and resizing is very inexpensive, done via variables
|
||||||
void ZImage::Stretch(float xFactor, float yFactor)
|
void ZImage::Stretch(float xFactor, float yFactor)
|
||||||
{
|
{
|
||||||
rWidth = static_cast<unsigned int>(xFactor*rWidth);
|
rWidth = static_cast<unsigned int>(xFactor*rWidth);
|
||||||
@ -222,6 +221,7 @@ void ZImage::Resize(unsigned int width, unsigned int height)
|
|||||||
rHeight = height;
|
rHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this is available for other uses of ZEngine
|
||||||
void ZImage::Bind() const
|
void ZImage::Bind() const
|
||||||
{
|
{
|
||||||
if(rTexID)
|
if(rTexID)
|
||||||
@ -238,15 +238,15 @@ void ZImage::Draw(int x, int y) const
|
|||||||
|
|
||||||
void ZImage::Draw(float x, float y) const
|
void ZImage::Draw(float x, float y) const
|
||||||
{
|
{
|
||||||
glColor4ub(255,255,255,rAlpha);
|
glColor4ub(255,255,255,rAlpha); //sets the color correctly
|
||||||
Bind();
|
Bind();
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
glBegin(GL_TRIANGLE_STRIP); //triangle strips, speedier?
|
||||||
glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(x,y);
|
glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(x,y);
|
||||||
glTexCoord2f(rTexMaxX,rTexMinY); glVertex2f(x+rWidth,y);
|
glTexCoord2f(rTexMaxX,rTexMinY); glVertex2f(x+rWidth,y);
|
||||||
glTexCoord2f(rTexMinX,rTexMaxY); glVertex2f(x,y+rHeight);
|
glTexCoord2f(rTexMinX,rTexMaxY); glVertex2f(x,y+rHeight);
|
||||||
glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth,y+rHeight);
|
glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth,y+rHeight);
|
||||||
glEnd();
|
glEnd();
|
||||||
glColor4ub(255,255,255,255); //return to standard color state
|
glColor4ub(255,255,255,255); //be responsible, return to standard color state
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZImage::DrawRotated(int x, int y, float angle) const
|
void ZImage::DrawRotated(int x, int y, float angle) const
|
||||||
@ -256,16 +256,17 @@ void ZImage::DrawRotated(int x, int y, float angle) const
|
|||||||
|
|
||||||
void ZImage::DrawRotated(float x, float y, float angle) const
|
void ZImage::DrawRotated(float x, float y, float angle) const
|
||||||
{
|
{
|
||||||
float cX,cY; //center variables
|
//center point
|
||||||
|
float cX,cY;
|
||||||
cX = rWidth/2.0f;
|
cX = rWidth/2.0f;
|
||||||
cY = rHeight/2.0f;
|
cY = rHeight/2.0f;
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x+cX,y+cY,0);
|
glTranslatef(x+cX,y+cY,0); //translate to center
|
||||||
glRotatef(angle,0,0,1.0f);
|
glRotatef(angle,0,0,1.0f); //rotate on z axis, to keep x&y parallel to 2D plane
|
||||||
glColor4ub(255,255,255,rAlpha);
|
glColor4ub(255,255,255,rAlpha);
|
||||||
Bind();
|
Bind();
|
||||||
|
//draw is modified to be based around center//
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(-cX,-cY);
|
glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(-cX,-cY);
|
||||||
glTexCoord2f(rTexMaxX,rTexMinY); glVertex2f(-cX+rWidth,-cY);
|
glTexCoord2f(rTexMaxX,rTexMinY); glVertex2f(-cX+rWidth,-cY);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZMusic.
|
\brief Source file for ZMusic.
|
||||||
|
|
||||||
Implementation of ZMusic, the basic Music class for ZEngine.
|
Implementation of ZMusic, the basic Music class for ZEngine.
|
||||||
<br>$Id: ZE_ZMusic.cpp,v 1.9 2003/06/11 00:15:10 cozman Exp $<br>
|
<br>$Id: ZE_ZMusic.cpp,v 1.10 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -24,18 +24,19 @@
|
|||||||
namespace ZE
|
namespace ZE
|
||||||
{
|
{
|
||||||
|
|
||||||
const int ZMusic::LoopInfinite = -1;
|
//ZMusic is a very simple class, each call basically wraps a self-explanatory function of SDL_Mixer
|
||||||
|
const int ZMusic::LoopInfinite = -1; //constant for infinite, as used by SDL_Mixer
|
||||||
|
|
||||||
ZMusic::ZMusic()
|
ZMusic::ZMusic() :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rMusic(NULL)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rMusic = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMusic::ZMusic(std::string filename)
|
ZMusic::ZMusic(std::string filename) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rMusic(NULL)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rMusic = NULL;
|
|
||||||
Open(filename);
|
Open(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZRect.
|
\brief Source file for ZRect.
|
||||||
|
|
||||||
Implementation of ZRect, the Rectangle class for ZEngine.
|
Implementation of ZRect, the Rectangle class for ZEngine.
|
||||||
<br>$Id: ZE_ZRect.cpp,v 1.11 2003/05/13 01:31:30 cozman Exp $<br>
|
<br>$Id: ZE_ZRect.cpp,v 1.12 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -153,6 +153,7 @@ ZRect ZRect::Intersection(const ZRect &rect) const
|
|||||||
{
|
{
|
||||||
float tempX=0,tempY=0,tempW=0,tempH=0;
|
float tempX=0,tempY=0,tempW=0,tempH=0;
|
||||||
|
|
||||||
|
//can only grab the intersection if they intersect
|
||||||
if(Intersects(rect))
|
if(Intersects(rect))
|
||||||
{
|
{
|
||||||
tempX = rX > rect.X() ? rX : rect.X();
|
tempX = rX > rect.X() ? rX : rect.X();
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZServer.
|
\brief Source file for ZServer.
|
||||||
|
|
||||||
Implementation file for ZServer, the TCP Server class for ZEngine.
|
Implementation file for ZServer, the TCP Server class for ZEngine.
|
||||||
<br>$Id: ZE_ZServer.cpp,v 1.6 2003/05/13 01:31:30 cozman Exp $<br>
|
<br>$Id: ZE_ZServer.cpp,v 1.7 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -27,21 +27,17 @@ namespace ZE
|
|||||||
void ZServer::CloseSocket(int num)
|
void ZServer::CloseSocket(int num)
|
||||||
{
|
{
|
||||||
SDLNet_TCP_Close(rClientSockets[num]);
|
SDLNet_TCP_Close(rClientSockets[num]);
|
||||||
rClientSockets[num] = NULL;
|
rClientSockets[num] = NULL; //closed sockets should be NULL to mark them closed
|
||||||
if(rVerbose)
|
if(rVerbose)
|
||||||
rEngine->WriteLog(FormatStr("Closing socket #%d",num));
|
rEngine->WriteLog(FormatStr("Closing socket #%d",num));
|
||||||
}
|
}
|
||||||
|
|
||||||
ZServer::ZServer(bool v)
|
ZServer::ZServer(bool verbose)
|
||||||
|
{
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rSocket(NULL), rSocketSet(NULL), rClientSockets(NULL),
|
||||||
|
rMaxClients(0), rVerbose(verbose), rWaitTime(0)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
|
|
||||||
rSocket = NULL;
|
|
||||||
rSocketSet = NULL;
|
|
||||||
rClientSockets = NULL;
|
|
||||||
rMaxClients = 0;
|
|
||||||
rVerbose = v;
|
|
||||||
rWaitTime = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZServer::~ZServer()
|
ZServer::~ZServer()
|
||||||
@ -97,6 +93,7 @@ void ZServer::Stop()
|
|||||||
SDLNet_FreeSocketSet(rSocketSet);
|
SDLNet_FreeSocketSet(rSocketSet);
|
||||||
rSocketSet = NULL;
|
rSocketSet = NULL;
|
||||||
}
|
}
|
||||||
|
//each client must be let go, old memory leak
|
||||||
if(rClientSockets)
|
if(rClientSockets)
|
||||||
{
|
{
|
||||||
for(int i=0; i < rMaxClients; ++i)
|
for(int i=0; i < rMaxClients; ++i)
|
||||||
@ -160,6 +157,7 @@ void ZServer::CheckSockets()
|
|||||||
size = result;
|
size = result;
|
||||||
if(rVerbose)
|
if(rVerbose)
|
||||||
rEngine->WriteLog("ZServer: Mirroring data: ");
|
rEngine->WriteLog("ZServer: Mirroring data: ");
|
||||||
|
|
||||||
for(int j=0; j < rMaxClients; ++j)
|
for(int j=0; j < rMaxClients; ++j)
|
||||||
{
|
{
|
||||||
if(rClientSockets[j] && i != j) //send to open sockets that aren't the same
|
if(rClientSockets[j] && i != j) //send to open sockets that aren't the same
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZSound.
|
\brief Source file for ZSound.
|
||||||
|
|
||||||
Implementation of ZSound, the basic Sound class for ZEngine.
|
Implementation of ZSound, the basic Sound class for ZEngine.
|
||||||
<br>$Id: ZE_ZSound.cpp,v 1.9 2003/06/11 00:15:10 cozman Exp $<br>
|
<br>$Id: ZE_ZSound.cpp,v 1.10 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -24,20 +24,22 @@
|
|||||||
namespace ZE
|
namespace ZE
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//ZSound is almost exactly like ZMusic, when making changes check if that change should
|
||||||
|
//be applied to ZMusic as well, roughly 90% of the time it should be.
|
||||||
const int ZSound::LoopInfinite = -1;
|
const int ZSound::LoopInfinite = -1;
|
||||||
|
|
||||||
ZSound::ZSound()
|
ZSound::ZSound() :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rSound(NULL),
|
||||||
|
rChannelID(-1) //request channel ID
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rSound = NULL;
|
|
||||||
rChannelID = -1; //request channel ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZSound::ZSound(std::string filename)
|
ZSound::ZSound(std::string filename) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rSound(NULL),
|
||||||
|
rChannelID(-1) //request channel ID
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rSound = NULL;
|
|
||||||
rChannelID = -1; //request channel ID
|
|
||||||
Open(filename);
|
Open(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZTimer.
|
\brief Source file for ZTimer.
|
||||||
|
|
||||||
Implementation of ZTimer, the basic Timer class for ZEngine.
|
Implementation of ZTimer, the basic Timer class for ZEngine.
|
||||||
<br>$Id: ZE_ZTimer.cpp,v 1.8 2003/05/13 01:31:30 cozman Exp $<br>
|
<br>$Id: ZE_ZTimer.cpp,v 1.9 2003/06/11 05:51:16 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -30,11 +30,11 @@ Uint32 ZTimer::GetParentTime() const
|
|||||||
return SDL_GetTicks();
|
return SDL_GetTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZTimer::ZTimer(bool useZEngine)
|
ZTimer::ZTimer(bool useZEngine) :
|
||||||
|
rEngine(ZEngine::GetInstance()),
|
||||||
|
rUseZEngine(useZEngine),
|
||||||
|
rPaused(false)
|
||||||
{
|
{
|
||||||
rEngine = ZEngine::GetInstance();
|
|
||||||
rUseZEngine = useZEngine;
|
|
||||||
rPaused = false;
|
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +61,7 @@ void ZTimer::Unpause()
|
|||||||
{
|
{
|
||||||
if(rPaused)
|
if(rPaused)
|
||||||
{
|
{
|
||||||
|
//when unpausing update the total paused time by that pause
|
||||||
rPausedTime += (GetParentTime()-rLastPause);
|
rPausedTime += (GetParentTime()-rLastPause);
|
||||||
rPaused = false;
|
rPaused = false;
|
||||||
}
|
}
|
||||||
@ -68,10 +69,10 @@ void ZTimer::Unpause()
|
|||||||
|
|
||||||
Uint32 ZTimer::GetTime() const
|
Uint32 ZTimer::GetTime() const
|
||||||
{
|
{
|
||||||
if(rPaused)
|
if(rPaused) //when paused timer adjusted to subtract currently paused time
|
||||||
return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause));
|
return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause));
|
||||||
else
|
else
|
||||||
return GetParentTime() - rPausedTime;
|
return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZTimer::IsPaused() const
|
bool ZTimer::IsPaused() const
|
||||||
|
7
src/external/SDLGL_Util.cpp
vendored
7
src/external/SDLGL_Util.cpp
vendored
@ -4,14 +4,13 @@
|
|||||||
|
|
||||||
#include "external/SDLGL_Util.h"
|
#include "external/SDLGL_Util.h"
|
||||||
|
|
||||||
|
//finds nearest power of two (going up), needed for surfaces
|
||||||
int power_of_two(int input)
|
int power_of_two(int input)
|
||||||
{
|
{
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
|
||||||
while(value < input)
|
while(value < input) //texture coord must be >= input
|
||||||
{
|
value <<= 1; //value <<= 1 is the same as value *= 2
|
||||||
value <<= 1;
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZFontTest.cpp,v 1.11 2003/01/12 19:00:14 cozman Exp $*/
|
/*$Id: ZFontTest.cpp,v 1.12 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -42,7 +42,7 @@ void Test()
|
|||||||
//Open and Setup all the Fonts and Create Images//
|
//Open and Setup all the Fonts and Create Images//
|
||||||
ZImage text[6];
|
ZImage text[6];
|
||||||
ZFont almonte("data/almontew.ttf",48), axaxax("data/axaxax.ttf",32), betsy("data/betsy.ttf",64);
|
ZFont almonte("data/almontew.ttf",48), axaxax("data/axaxax.ttf",32), betsy("data/betsy.ttf",64);
|
||||||
almonte.SetColor(255,0,0);
|
almonte.SetColor(255,0,0,128);
|
||||||
almonte.DrawText("This is the font test.",text[0]);
|
almonte.DrawText("This is the font test.",text[0]);
|
||||||
axaxax.SetColor(0,255,255);
|
axaxax.SetColor(0,255,255);
|
||||||
axaxax.SetStyle(true,false,false);
|
axaxax.SetStyle(true,false,false);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZImageTest.cpp,v 1.17 2003/04/27 18:55:00 cozman Exp $*/
|
/*$Id: ZImageTest.cpp,v 1.18 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,7 +21,7 @@ bool Initialize()
|
|||||||
ZConfigFile cfg("tests.zcf");
|
ZConfigFile cfg("tests.zcf");
|
||||||
int w,h,bpp,rate;
|
int w,h,bpp,rate;
|
||||||
bool fs;
|
bool fs;
|
||||||
string title;
|
std::string title;
|
||||||
|
|
||||||
w = cfg.GetInt("ZImageTest","width",800);
|
w = cfg.GetInt("ZImageTest","width",800);
|
||||||
h = cfg.GetInt("ZImageTest","height",600);
|
h = cfg.GetInt("ZImageTest","height",600);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZMouseTest.cpp,v 1.12 2003/01/12 19:00:17 cozman Exp $*/
|
/*$Id: ZMouseTest.cpp,v 1.13 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,7 +21,7 @@ bool Initialize()
|
|||||||
ZConfigFile cfg("tests.zcf");
|
ZConfigFile cfg("tests.zcf");
|
||||||
int w,h,bpp,rate;
|
int w,h,bpp,rate;
|
||||||
bool fs;
|
bool fs;
|
||||||
string title;
|
std::string title;
|
||||||
|
|
||||||
w = cfg.GetInt("ZMouseTest","width",800);
|
w = cfg.GetInt("ZMouseTest","width",800);
|
||||||
h = cfg.GetInt("ZMouseTest","height",600);
|
h = cfg.GetInt("ZMouseTest","height",600);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZMusicTest.cpp,v 1.14 2003/02/10 05:16:30 cozman Exp $*/
|
/*$Id: ZMusicTest.cpp,v 1.15 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,7 +21,7 @@ bool Initialize()
|
|||||||
ZConfigFile cfg("tests.zcf");
|
ZConfigFile cfg("tests.zcf");
|
||||||
int w,h,bpp,rate;
|
int w,h,bpp,rate;
|
||||||
bool fs;
|
bool fs;
|
||||||
string title;
|
std::string title;
|
||||||
|
|
||||||
w = cfg.GetInt("ZMusicTest","width",800);
|
w = cfg.GetInt("ZMusicTest","width",800);
|
||||||
h = cfg.GetInt("ZMusicTest","height",600);
|
h = cfg.GetInt("ZMusicTest","height",600);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZRectTest.cpp,v 1.15 2003/01/12 19:00:21 cozman Exp $*/
|
/*$Id: ZRectTest.cpp,v 1.16 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,7 +21,7 @@ bool Initialize()
|
|||||||
ZConfigFile cfg("tests.zcf");
|
ZConfigFile cfg("tests.zcf");
|
||||||
int w,h,bpp,rate;
|
int w,h,bpp,rate;
|
||||||
bool fs;
|
bool fs;
|
||||||
string title;
|
std::string title;
|
||||||
|
|
||||||
w = cfg.GetInt("ZRectTest","Width",800);
|
w = cfg.GetInt("ZRectTest","Width",800);
|
||||||
h = cfg.GetInt("ZRectTest","height",600);
|
h = cfg.GetInt("ZRectTest","height",600);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZSoundTest.cpp,v 1.12 2003/02/10 05:16:30 cozman Exp $*/
|
/*$Id: ZSoundTest.cpp,v 1.13 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,7 +21,7 @@ bool Initialize()
|
|||||||
ZConfigFile cfg("tests.zcf");
|
ZConfigFile cfg("tests.zcf");
|
||||||
int w,h,bpp,rate;
|
int w,h,bpp,rate;
|
||||||
bool fs;
|
bool fs;
|
||||||
string title;
|
std::string title;
|
||||||
|
|
||||||
w = cfg.GetInt("ZSoundTest","width",800);
|
w = cfg.GetInt("ZSoundTest","width",800);
|
||||||
h = cfg.GetInt("ZSoundTest","height",600);
|
h = cfg.GetInt("ZSoundTest","height",600);
|
||||||
@ -39,7 +39,7 @@ void Test()
|
|||||||
{
|
{
|
||||||
ZEngine *engine = ZEngine::GetInstance();
|
ZEngine *engine = ZEngine::GetInstance();
|
||||||
|
|
||||||
string name[5] = { "monkey", "rooster", "kick", "carcrash", "whip" };
|
std::string name[5] = { "monkey", "rooster", "kick", "carcrash", "whip" };
|
||||||
ZSound sample[5];
|
ZSound sample[5];
|
||||||
ZFont font("data/almontew.ttf",48);
|
ZFont font("data/almontew.ttf",48);
|
||||||
ZImage text[6];
|
ZImage text[6];
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*$Id: ZTimerTest.cpp,v 1.12 2003/02/10 05:16:30 cozman Exp $*/
|
/*$Id: ZTimerTest.cpp,v 1.13 2003/06/11 05:51:47 cozman Exp $*/
|
||||||
|
|
||||||
#include <ZEngine.h>
|
#include <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,7 +21,7 @@ bool Initialize()
|
|||||||
ZConfigFile cfg("tests.zcf");
|
ZConfigFile cfg("tests.zcf");
|
||||||
int w,h,bpp,rate;
|
int w,h,bpp,rate;
|
||||||
bool fs;
|
bool fs;
|
||||||
string title;
|
std::string title;
|
||||||
|
|
||||||
w = cfg.GetInt("ZTimerTest","width",800);
|
w = cfg.GetInt("ZTimerTest","width",800);
|
||||||
h = cfg.GetInt("ZTimerTest","height",600);
|
h = cfg.GetInt("ZTimerTest","height",600);
|
||||||
@ -39,7 +39,7 @@ void Test()
|
|||||||
{
|
{
|
||||||
ZEngine *engine = ZEngine::GetInstance();
|
ZEngine *engine = ZEngine::GetInstance();
|
||||||
|
|
||||||
string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"};
|
std::string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"};
|
||||||
int curTimer = 0;
|
int curTimer = 0;
|
||||||
|
|
||||||
//Open and Setup Font and Create Images and Timers//
|
//Open and Setup Font and Create Images and Timers//
|
||||||
|
Loading…
Reference in New Issue
Block a user