Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Split radar frustum coordinate calculation from drawing operation.

  • Loading branch information...
commit def1e4ffa5ddaaac0dbe784a0811970354937759 1 parent 7a3338c
Per Inge Mathisen authored
25 lib/ivis_opengl/piefunc.cpp
@@ -37,13 +37,12 @@
37 37 static GFX *skyboxGfx = NULL;
38 38
39 39 #define VW_VERTICES 5
40   -void pie_DrawViewingWindow(Vector3i *v, PIELIGHT colour)
41   -{
42   - Vector3i pieVrts[VW_VERTICES];
43   - SDWORD i;
  40 +static Vector3i pieVrts[VW_VERTICES];
  41 +static PIELIGHT pieColour;
44 42
45   - pie_SetTexturePage(TEXPAGE_NONE);
46   - pie_SetRendMode(REND_ALPHA);
  43 +void pie_SetViewingWindow(Vector3i *v, PIELIGHT colour)
  44 +{
  45 + pieColour = colour;
47 46
48 47 pieVrts[0] = v[1];
49 48 pieVrts[0].z = INTERFACE_DEPTH; // cull triangles with off screen points
@@ -58,6 +57,15 @@ void pie_DrawViewingWindow(Vector3i *v, PIELIGHT colour)
58 57 pieVrts[3].z = INTERFACE_DEPTH;
59 58
60 59 pieVrts[4] = pieVrts[0];
  60 +}
  61 +
  62 +void pie_DrawViewingWindow()
  63 +{
  64 + SDWORD i;
  65 + PIELIGHT colour = pieColour;
  66 +
  67 + pie_SetTexturePage(TEXPAGE_NONE);
  68 + pie_SetRendMode(REND_ALPHA);
61 69
62 70 glColor4ub(colour.byte.r, colour.byte.g, colour.byte.b, colour.byte.a >> 1);
63 71 glBegin(GL_TRIANGLE_FAN);
@@ -153,8 +161,3 @@ void pie_DrawSkybox(float scale)
153 161
154 162 glPopAttrib();
155 163 }
156   -
157   -UBYTE pie_ByteScale(UBYTE a, UBYTE b)
158   -{
159   - return ((UDWORD)a * (UDWORD)b) >> 8;
160   -}
7 lib/ivis_opengl/piefunc.h
@@ -33,9 +33,10 @@
33 33 #include "lib/ivis_opengl/piedef.h"
34 34 #include "lib/ivis_opengl/pieclip.h"
35 35
36   -extern UBYTE pie_ByteScale(UBYTE a, UBYTE b) WZ_DECL_CONST;
37   -extern void pie_TransColouredTriangle(Vector3f *vrt, PIELIGHT c);
38   -extern void pie_DrawViewingWindow(Vector3i *v, PIELIGHT colour);
  36 +void pie_TransColouredTriangle(Vector3f *vrt, PIELIGHT c);
  37 +
  38 +void pie_SetViewingWindow(Vector3i *v, PIELIGHT colour);
  39 +void pie_DrawViewingWindow();
39 40
40 41 void pie_DrawSkybox(float scale);
41 42 void pie_Skybox_Init();
62 src/radar.cpp
@@ -57,6 +57,7 @@ bool rotateRadar; ///< Rotate the radar?
57 57 static PIELIGHT colRadarAlly, colRadarMe, colRadarEnemy;
58 58 static PIELIGHT tileColours[MAX_TILES];
59 59 static UDWORD *radarBuffer = NULL;
  60 +static Vector3i playerpos;
60 61
61 62 PIELIGHT clanColours[]=
62 63 { // see frontend2.png for team color order.
@@ -105,10 +106,11 @@ static float RadarZoomMultiplier = 1.0f;
105 106 static UDWORD radarBufferSize = 0;
106 107 static int frameSkip = 0;
107 108
108   -static void DrawRadarTiles(void);
109   -static void DrawRadarObjects(void);
110   -static void DrawRadarExtras(float pixSizeH, float pixSizeV);
111   -static void DrawNorth(void);
  109 +static void DrawRadarTiles();
  110 +static void DrawRadarObjects();
  111 +static void DrawRadarExtras();
  112 +static void DrawNorth();
  113 +static void setViewingWindow();
112 114
113 115 static void radarSize(int ZoomLevel)
114 116 {
@@ -128,16 +130,17 @@ static void radarSize(int ZoomLevel)
128 130 debug(LOG_WZ, "radar=(%u,%u) tex=(%u,%u) size=(%u,%u)", radarCenterX, radarCenterY, radarTexWidth, radarTexHeight, radarWidth, radarHeight);
129 131 }
130 132
131   -void radarInitVars(void)
  133 +void radarInitVars()
132 134 {
133 135 radarTexWidth = 0;
134 136 radarTexHeight = 0;
135 137 RadarZoom = DEFAULT_RADARZOOM;
136 138 debug(LOG_WZ, "Resetting radar zoom to %u", RadarZoom);
137 139 radarSize(RadarZoom);
  140 + playerpos = Vector3i(-1, -1, -1);
138 141 }
139 142
140   -bool InitRadar(void)
  143 +bool InitRadar()
141 144 {
142 145 // Ally/enemy/me colors
143 146 colRadarAlly = WZCOL_YELLOW;
@@ -152,7 +155,7 @@ bool InitRadar(void)
152 155 return true;
153 156 }
154 157
155   -bool resizeRadar(void)
  158 +bool resizeRadar()
156 159 {
157 160 if (radarBuffer)
158 161 {
@@ -175,11 +178,12 @@ bool resizeRadar(void)
175 178 radarSize(RadarZoom);
176 179 pie_SetRadar(-radarWidth/2.0 - 1, -radarHeight/2.0 - 1, radarWidth, radarHeight,
177 180 radarTexWidth, radarTexHeight, rotateRadar || (RadarZoom % 16 != 0));
  181 + setViewingWindow();
178 182
179 183 return true;
180 184 }
181 185
182   -bool ShutdownRadar(void)
  186 +bool ShutdownRadar()
183 187 {
184 188 pie_ShutdownRadar();
185 189
@@ -210,7 +214,7 @@ void SetRadarZoom(uint8_t ZoomLevel)
210 214 resizeRadar();
211 215 }
212 216
213   -uint8_t GetRadarZoom(void)
  217 +uint8_t GetRadarZoom()
214 218 {
215 219 return RadarZoom;
216 220 }
@@ -257,13 +261,20 @@ void CalcRadarPosition(int mX, int mY, int *PosX, int *PosY)
257 261 *PosY = sPosY;
258 262 }
259 263
260   -void drawRadar(void)
  264 +void drawRadar()
261 265 {
262 266 float pixSizeH, pixSizeV;
263 267
  268 + CalcRadarPixelSize(&pixSizeH, &pixSizeV);
  269 +
264 270 ASSERT_OR_RETURN(, radarBuffer, "No radar buffer allocated");
265 271
266   - CalcRadarPixelSize(&pixSizeH, &pixSizeV);
  272 + // Do not recalculate frustum window coordinates if position or zoom does not change
  273 + if (playerpos.x != player.p.x || playerpos.y != player.p.y || playerpos.z != player.p.z)
  274 + {
  275 + setViewingWindow();
  276 + }
  277 + playerpos = player.p; // cache position
267 278
268 279 if (frameSkip <= 0)
269 280 {
@@ -283,15 +294,15 @@ void drawRadar(void)
283 294 DrawNorth();
284 295 }
285 296 pie_RenderRadar();
286   - pie_MatBegin();
287   - pie_TRANSLATE(-radarWidth/2 - 1, -radarHeight/2 - 1, 0);
288   - DrawRadarExtras(pixSizeH, pixSizeV);
289   - pie_MatEnd();
  297 + pie_MatBegin();
  298 + pie_TRANSLATE(-radarWidth/2 - 1, -radarHeight/2 - 1, 0);
  299 + DrawRadarExtras();
  300 + pie_MatEnd();
290 301 drawRadarBlips(-radarWidth/2.0 - 1, -radarHeight/2.0 - 1, pixSizeH, pixSizeV);
291 302 pie_MatEnd();
292 303 }
293 304
294   -static void DrawNorth(void)
  305 +static void DrawNorth()
295 306 {
296 307 iV_DrawImage(IntImages, RADAR_NORTH, -((radarWidth / 2.0) + iV_GetImageWidth(IntImages, RADAR_NORTH) + 1), -(radarHeight / 2.0));
297 308 }
@@ -386,7 +397,7 @@ static PIELIGHT appliedRadarColour(RADAR_DRAW_MODE radarDrawMode, MAPTILE *WTile
386 397 }
387 398
388 399 /** Draw the map tiles on the radar. */
389   -static void DrawRadarTiles(void)
  400 +static void DrawRadarTiles()
390 401 {
391 402 SDWORD x, y;
392 403
@@ -409,7 +420,7 @@ static void DrawRadarTiles(void)
409 420 }
410 421
411 422 /** Draw the droids and structure positions on the radar. */
412   -static void DrawRadarObjects(void)
  423 +static void DrawRadarObjects()
413 424 {
414 425 UBYTE clan;
415 426 PIELIGHT playerCol;
@@ -576,13 +587,17 @@ static SDWORD getLengthAdjust( void )
576 587 }
577 588
578 589 /** Draws a Myth/FF7 style viewing window */
579   -static void drawViewingWindow(int x, int y, float pixSizeH, float pixSizeV)
  590 +static void setViewingWindow()
580 591 {
  592 + float pixSizeH, pixSizeV;
581 593 Vector3i v[4], tv[4], centre;
582 594 int shortX, longX, yDrop, yDropVar;
583 595 int dif = getDistanceAdjust();
584 596 int dif2 = getLengthAdjust();
585 597 PIELIGHT colour;
  598 + CalcRadarPixelSize(&pixSizeH, &pixSizeV);
  599 + int x = player.p.x * pixSizeH / TILE_UNITS;
  600 + int y = player.p.z * pixSizeV / TILE_UNITS;
586 601
587 602 shortX = ((visibleTiles.x / 4) - (dif / 6)) * pixSizeH;
588 603 longX = ((visibleTiles.x / 2) - (dif / 4)) * pixSizeH;
@@ -630,15 +645,12 @@ static void drawViewingWindow(int x, int y, float pixSizeH, float pixSizeV)
630 645 }
631 646
632 647 /* Send the four points to the draw routine and the clip box params */
633   - pie_DrawViewingWindow(tv, colour);
  648 + pie_SetViewingWindow(tv, colour);
634 649 }
635 650
636   -static void DrawRadarExtras(float pixSizeH, float pixSizeV)
  651 +static void DrawRadarExtras()
637 652 {
638   - int viewX = player.p.x*pixSizeH / TILE_UNITS;
639   - int viewY = player.p.z*pixSizeV / TILE_UNITS;
640   -
641   - drawViewingWindow(viewX, viewY, pixSizeH, pixSizeV);
  653 + pie_DrawViewingWindow();
642 654 RenderWindowFrame(FRAME_RADAR, -1, -1, radarWidth + 2, radarHeight + 2);
643 655 }
644 656

0 comments on commit def1e4f

Please sign in to comment.
Something went wrong with that request. Please try again.