From 61d8512793e599298d1b81598b35c7ccdb5c63fa Mon Sep 17 00:00:00 2001 From: James Turk Date: Sat, 11 Oct 2003 16:21:49 +0000 Subject: [PATCH] fixes & doc errors --- src/ZE_ZEngine.cpp | 35 +++------------------ src/ZE_ZImage.cpp | 63 +++++++++++++++++-------------------- src/external/SDLGL_Util.cpp | 4 +-- 3 files changed, 36 insertions(+), 66 deletions(-) diff --git a/src/ZE_ZEngine.cpp b/src/ZE_ZEngine.cpp index 9cde7f2..02df9d4 100644 --- a/src/ZE_ZEngine.cpp +++ b/src/ZE_ZEngine.cpp @@ -13,7 +13,7 @@ \brief Central source file for ZEngine. Actual implementation of ZEngine singleton class, the core of ZEngine. -
$Id: ZE_ZEngine.cpp,v 1.61 2003/10/05 19:31:03 cozman Exp $
+
$Id: ZE_ZEngine.cpp,v 1.62 2003/10/11 16:21:49 cozman Exp $
\author James Turk **/ @@ -252,10 +252,6 @@ void ZEngine::CloseDisplay() Mix_CloseAudio(); #endif -#ifdef USE_PHYSFS - PHYSFS_deinit(); -#endif - SDL_Quit(); if(mErrlog != stderr && mErrlog != stdin) @@ -320,7 +316,7 @@ void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) { GLclampf r = red/255.0f, g = green/255.0f, b = blue/255.0f, a = alpha/255.0f; glClearColor(r,g,b,a); - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); } @@ -366,7 +362,7 @@ void ZEngine::Delay(Uint32 milliseconds) Uint32 ZEngine::GetTime() { - if(mPaused) //when paused time hasn't been added to mPausedTime + if(mPaused) //when paused time hasn't been added to mPausedTime yet return SDL_GetTicks() - (mPausedTime + (SDL_GetTicks() - mLastPause)); else return SDL_GetTicks() - mPausedTime; @@ -385,7 +381,7 @@ void ZEngine::UnpauseTimer() { if(mPaused) { - //mPaused time accumulates total time engine has been paused in all pauses + //mPaused time accumulates total time engine has been paused mPausedTime += (SDL_GetTicks() - mLastPause); mPaused = false; } @@ -495,7 +491,7 @@ bool ZEngine::MButtonPressed() bool ZEngine::MouseInRect(SDL_Rect *rect) { - //useful function, needed so much it made it in + //useful function, needed so much it made it into ZEngine return (mMouseX >= rect->x && mMouseX <= rect->x+rect->w && mMouseY >= rect->y && mMouseY <= rect->y+rect->h); } @@ -572,27 +568,6 @@ void ZEngine::SetEventFilter(SDL_EventFilter filter) mEventFilter = filter; } -#ifdef USE_PHYSFS - -void ZEngine::InitPhysFS(std::string argv) -{ - std::string::size_type pos; - PHYSFS_init(argv.c_str()); - - //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) - AddPhysFSDir(argv.substr(0,pos)); //everything up to last slash -} - -void ZEngine::AddPhysFSDir(std::string dir) -{ - PHYSFS_addToSearchPath(dir.c_str(),0); -} - -#endif //USE_PHYSFS - void ZEngine::SetErrorLog(bool logAll, std::string logFile) { mLogAllErrors = logAll; diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp index b725d25..a3da999 100644 --- a/src/ZE_ZImage.cpp +++ b/src/ZE_ZImage.cpp @@ -13,7 +13,7 @@ \brief Source file for ZImage. Implementation of ZImage, the Image class for ZEngine. -
$Id: ZE_ZImage.cpp,v 1.47 2003/09/24 02:03:18 cozman Exp $
+
$Id: ZE_ZImage.cpp,v 1.48 2003/10/11 16:21:50 cozman Exp $
\author James Turk **/ @@ -157,21 +157,19 @@ void ZImage::Attach(SDL_Surface *surface) Release(); //avoid most user inflicted memory leaks associated with ZImage - //surface conversion// - SDL_Surface *temp = surface; - surface = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this - if(surface) - { - FreeImage(temp); - } - else //can't convert - { - rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError())); - surface = temp; - } - if(surface) { + SDL_Surface *temp = SDL_DisplayFormatAlpha(surface); //TTF_RenderTextBlended relys on this + if(temp) //if conversion succeeds, free old surface + { + FreeImage(surface); + surface = temp; + } + else //can't convert, leave surface as is + { + rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError())); + } + rWidth = static_cast(surface->w); rHeight = static_cast(surface->h); rTexID = SDL_GL_LoadTexture(surface,coord); //major helper, not written by me, from libsdl.org @@ -211,10 +209,11 @@ void ZImage::SetAlpha(Uint8 alpha) void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) { - Uint32 color = SDL_MapRGB(rImage->format,red,green,blue); + Uint32 color; if(rImage) { + color = SDL_MapRGB(rImage->format,red,green,blue); if(SDL_SetColorKey(rImage, SDL_SRCCOLORKEY, color) < 0) rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError())); else @@ -344,10 +343,7 @@ void ZImage::DrawClipped(float x, float y, ZRect clipRect) const glEnd(); glColor4ub(255,255,255,255); //be responsible, return to standard color state } - else //doesn't contain nor intersect - { - //draw nothing - } + //otherwise it doesn't contain nor intersect, so nothing should be drawn } void ZImage::DrawClipped(float x, float y, ZRect clipRect, Uint8 vc[]) const @@ -434,22 +430,22 @@ bool ZImage::IsLoaded() const void ZImage::Attach(SDL_Surface *surface) { Release(); - - //surface conversion// - SDL_Surface *temp = surface; - surface = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this + if(surface) { - FreeImage(temp); - } - else //can't convert - { - rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError())); - surface = temp; - } + SDL_Surface *temp = SDL_DisplayFormatAlpha(surface); //TTF_RenderTextBlended relys on this + if(temp) //if conversion succeeds, free old surface + { + FreeImage(surface); + surface = temp; + } + else //can't convert, leave surface as is + { + rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError())); + } - if(surface) rImage = surface; + } else rEngine->ReportError(ZERR_NOIMAGE,"Attach"); } @@ -478,10 +474,11 @@ void ZImage::SetAlpha(Uint8 alpha) void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) { - Uint32 color = SDL_MapRGBA(rImage->format,red,green,blue,255); + Uint32 color; if(rImage) { + color = SDL_MapRGBA(rImage->format,red,green,blue,255); if(SDL_SetColorKey(rImage, SDL_RLEACCEL|SDL_SRCCOLORKEY, color) < 0) rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError())); //surface conversion// @@ -514,13 +511,11 @@ void ZImage::DrawClipped(int x, int y, ZRect clipRect) const ZRect img(static_cast(x),static_cast(y),static_cast(rImage->w),static_cast(rImage->h)); SDL_Rect inRect,imgRect; - imgRect = inRect = clipRect.Intersection(img).SDLrect(); inRect.x -= x; inRect.y -= y; SDL_BlitSurface(rImage, &inRect, rEngine->Display(), &imgRect); - //SDL_FillRect(rEngine->Display(), &inRect, SDL_MapRGB(rEngine->Display()->format,0,255,0)); } bool ZImage::IsLoaded() const diff --git a/src/external/SDLGL_Util.cpp b/src/external/SDLGL_Util.cpp index f794dc0..c102a89 100755 --- a/src/external/SDLGL_Util.cpp +++ b/src/external/SDLGL_Util.cpp @@ -1,4 +1,4 @@ -/*This code comes from testgl.c which is part of the SDL source distribution. +/*This code derived from testgl.c which is part of the SDL source distribution. Available at http://libsdl.org/ */ @@ -73,7 +73,7 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) } /* Create an OpenGL texture for the image */ - glGenTextures(1, &texture); //sometimes this returns a used ID?.. related to bug 723910 - ZImage Draws Wrong Image + glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);