Skip to content

Commit

Permalink
Remove pointer global psRendSurface
Browse files Browse the repository at this point in the history
Global pointer psRendSurface only ever contains &rendSurface (another
global), provided that it isn't undefined (isn't statically NULL
initialised).  So replace the use of this pointer with using
rendSurface.

Additionally remove function iV_RenderAssign, which only wraps the
psRendSurface assignment along with a debug() call, and inline it at its
only call-site.

Signed-off-by: Giel van Schijndel <giel@wz2100.net>
  • Loading branch information
Giel van Schijndel committed Oct 13, 2010
1 parent 681988a commit 5ab267a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 45 deletions.
2 changes: 0 additions & 2 deletions lib/ivis_common/rendmode.h
Expand Up @@ -27,11 +27,9 @@
#include "textdraw.h"

extern iSurface rendSurface;
extern iSurface *psRendSurface;

//*************************************************************************

extern void iV_RenderAssign(iSurface *s);
extern void iV_SurfaceDestroy(iSurface *s);
extern iSurface *iV_SurfaceCreate(int width, int height, uint8_t *buffer);

Expand Down
20 changes: 10 additions & 10 deletions lib/ivis_opengl/pieblitfunc.c
Expand Up @@ -109,20 +109,20 @@ void iV_Box(int x0,int y0, int x1, int y1, PIELIGHT colour)
pie_SetTexturePage(TEXPAGE_NONE);
pie_SetAlphaTest(false);

if (x0>psRendSurface->clip.right || x1<psRendSurface->clip.left ||
y0>psRendSurface->clip.bottom || y1<psRendSurface->clip.top)
if (x0>rendSurface.clip.right || x1<rendSurface.clip.left ||
y0>rendSurface.clip.bottom || y1<rendSurface.clip.top)
{
return;
}

if (x0<psRendSurface->clip.left)
x0 = psRendSurface->clip.left;
if (x1>psRendSurface->clip.right)
x1 = psRendSurface->clip.right;
if (y0<psRendSurface->clip.top)
y0 = psRendSurface->clip.top;
if (y1>psRendSurface->clip.bottom)
y1 = psRendSurface->clip.bottom;
if (x0<rendSurface.clip.left)
x0 = rendSurface.clip.left;
if (x1>rendSurface.clip.right)
x1 = rendSurface.clip.right;
if (y0<rendSurface.clip.top)
y0 = rendSurface.clip.top;
if (y1>rendSurface.clip.bottom)
y1 = rendSurface.clip.bottom;

{
const Vector2f vertices[] = {
Expand Down
12 changes: 6 additions & 6 deletions lib/ivis_opengl/piematrix.c
Expand Up @@ -325,8 +325,8 @@ int32_t pie_RotateProject(const Vector3i *v3d, Vector2i *v2d)
}
else
{
v2d->x = psRendSurface->xcentre + (v.x / zz);
v2d->y = psRendSurface->ycentre - (v.y / zz);
v2d->x = rendSurface.xcentre + (v.x / zz);
v2d->y = rendSurface.ycentre - (v.y / zz);
}

return zz;
Expand All @@ -342,8 +342,8 @@ void pie_PerspectiveBegin(void)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef(
(2 * psRendSurface->xcentre-width) / width,
(height - 2 * psRendSurface->ycentre) / height,
(2 * rendSurface.xcentre-width) / width,
(height - 2 * rendSurface.ycentre) / height,
0);
glFrustum(-xangle, xangle, -yangle, yangle, 330, 100000);
glScalef(1, 1, -1);
Expand Down Expand Up @@ -372,8 +372,8 @@ void pie_BeginInterface(void)

void pie_SetGeometricOffset(int x, int y)
{
psRendSurface->xcentre = x;
psRendSurface->ycentre = y;
rendSurface.xcentre = x;
rendSurface.ycentre = y;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/piemode.c
Expand Up @@ -81,7 +81,7 @@ BOOL pie_Initialise(void)
rendSurface.clip.bottom = pie_GetVideoBufferHeight();

pie_SetDefaultStates();
iV_RenderAssign(&rendSurface);
debug(LOG_3D, "xcentre %d; ycentre %d; buffer %p", rendSurface.xcentre, rendSurface.ycentre, rendSurface.buffer);

return true;
}
Expand Down
27 changes: 1 addition & 26 deletions lib/ivis_opengl/rendmode.c
Expand Up @@ -26,7 +26,6 @@
//*************************************************************************

iSurface rendSurface;
iSurface *psRendSurface;

//*************************************************************************
//***
Expand Down Expand Up @@ -60,34 +59,10 @@ iSurface *iV_SurfaceCreate(int width, int height, UBYTE *buffer)
return s;
}


// user must free s->buffer before calling
void iV_SurfaceDestroy(iSurface *s)
{
// if renderer assigned to surface
if (psRendSurface == s)
{
psRendSurface = NULL;
}

if (s)
{
if (&rendSurface != s)
free(s);
}
}


//*************************************************************************
//
// function pointers for render assign
//
//*************************************************************************

void iV_RenderAssign(iSurface *s)
{
/* Need to look into this - won't the unwanted called still set render surface? */
psRendSurface = s;

debug(LOG_3D, "iV_RenderAssign: xcentre %d; ycentre %d; buffer %p",
s->xcentre, s->ycentre, s->buffer);
}

0 comments on commit 5ab267a

Please sign in to comment.