summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/Radar.cpp181
1 files changed, 113 insertions, 68 deletions
diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp
index 4bb9c966..473f4dae 100644
--- a/src/core/Radar.cpp
+++ b/src/core/Radar.cpp
@@ -184,6 +184,75 @@ void GetTextureCorners(int32 x, int32 y, CVector2D *out)
out[3].y = RADAR_TILE_SIZE * (y);
}
+uint8 CRadar::CalculateBlipAlpha(float dist)
+{
+ if (FrontEndMenuManager.m_bMenuMapActive)
+ return 255;
+
+ if (dist <= 1.0f)
+ return 255;
+
+ if (dist <= 10.0f)
+ return (128.0f * ((dist - 1.0f) / 9.0f)) + ((1.0f - (dist - 1.0f) / 9.0f) * 255.0f);
+
+ return 128;
+}
+
+void CRadar::ChangeBlipBrightness(int32 i, int32 bright)
+{
+ int index = GetActualBlipArrayIndex(i);
+ if (index != -1)
+ ms_RadarTrace[index].m_bDim = bright != 1;
+}
+
+void CRadar::ChangeBlipColour(int32 i, int32 color)
+{
+ int index = GetActualBlipArrayIndex(i);
+ if (index != -1)
+ ms_RadarTrace[index].m_nColor = color;
+}
+
+void CRadar::ChangeBlipDisplay(int32 i, eBlipDisplay display)
+{
+ int index = GetActualBlipArrayIndex(i);
+ if (index != -1)
+ ms_RadarTrace[index].m_eBlipDisplay = display;
+}
+
+void CRadar::ChangeBlipScale(int32 i, int32 scale)
+{
+ int index = GetActualBlipArrayIndex(i);
+ if (index != -1)
+ ms_RadarTrace[index].m_wScale = scale;
+}
+
+void CRadar::ClearBlip(int32 i)
+{
+ int index = GetActualBlipArrayIndex(i);
+ if (index != -1) {
+ SetRadarMarkerState(index, false);
+ ms_RadarTrace[index].m_bInUse = false;
+ ms_RadarTrace[index].m_eBlipType = BLIP_NONE;
+ ms_RadarTrace[index].m_eBlipDisplay = BLIP_DISPLAY_NEITHER;
+ ms_RadarTrace[index].m_eRadarSprite = RADAR_SPRITE_NONE;
+ }
+}
+
+void CRadar::ClearBlipForEntity(eBlipType type, int32 id)
+{
+ for (int i = 0; i < NUMRADARBLIPS; i++) {
+ if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) {
+ SetRadarMarkerState(i, false);
+ ms_RadarTrace[i].m_bInUse = false;
+ ms_RadarTrace[i].m_eBlipType = BLIP_NONE;
+ ms_RadarTrace[i].m_eBlipDisplay = BLIP_DISPLAY_NEITHER;
+ ms_RadarTrace[i].m_eRadarSprite = RADAR_SPRITE_NONE;
+ }
+ };
+}
+
+// Why not a proper clipping algorithm?
+#ifdef THIS_IS_STUPID
bool IsPointInsideRadar(const CVector2D &point)
{
@@ -264,74 +333,6 @@ int LineRadarBoxCollision(CVector2D &out, const CVector2D &p1, const CVector2D &
return edge;
}
-uint8 CRadar::CalculateBlipAlpha(float dist)
-{
- if (FrontEndMenuManager.m_bMenuMapActive)
- return 255;
-
- if (dist <= 1.0f)
- return 255;
-
- if (dist <= 10.0f)
- return (128.0f * ((dist - 1.0f) / 9.0f)) + ((1.0f - (dist - 1.0f) / 9.0f) * 255.0f);
-
- return 128;
-}
-
-void CRadar::ChangeBlipBrightness(int32 i, int32 bright)
-{
- int index = GetActualBlipArrayIndex(i);
- if (index != -1)
- ms_RadarTrace[index].m_bDim = bright != 1;
-}
-
-void CRadar::ChangeBlipColour(int32 i, int32 color)
-{
- int index = GetActualBlipArrayIndex(i);
- if (index != -1)
- ms_RadarTrace[index].m_nColor = color;
-}
-
-void CRadar::ChangeBlipDisplay(int32 i, eBlipDisplay display)
-{
- int index = GetActualBlipArrayIndex(i);
- if (index != -1)
- ms_RadarTrace[index].m_eBlipDisplay = display;
-}
-
-void CRadar::ChangeBlipScale(int32 i, int32 scale)
-{
- int index = GetActualBlipArrayIndex(i);
- if (index != -1)
- ms_RadarTrace[index].m_wScale = scale;
-}
-
-void CRadar::ClearBlip(int32 i)
-{
- int index = GetActualBlipArrayIndex(i);
- if (index != -1) {
- SetRadarMarkerState(index, false);
- ms_RadarTrace[index].m_bInUse = false;
- ms_RadarTrace[index].m_eBlipType = BLIP_NONE;
- ms_RadarTrace[index].m_eBlipDisplay = BLIP_DISPLAY_NEITHER;
- ms_RadarTrace[index].m_eRadarSprite = RADAR_SPRITE_NONE;
- }
-}
-
-void CRadar::ClearBlipForEntity(eBlipType type, int32 id)
-{
- for (int i = 0; i < NUMRADARBLIPS; i++) {
- if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) {
- SetRadarMarkerState(i, false);
- ms_RadarTrace[i].m_bInUse = false;
- ms_RadarTrace[i].m_eBlipType = BLIP_NONE;
- ms_RadarTrace[i].m_eBlipDisplay = BLIP_DISPLAY_NEITHER;
- ms_RadarTrace[i].m_eRadarSprite = RADAR_SPRITE_NONE;
- }
- };
-}
-
-// Why not a proper clipping algorithm?
int CRadar::ClipRadarPoly(CVector2D *poly, const CVector2D *rect)
{
CVector2D corners[4] = {
@@ -410,6 +411,50 @@ int CRadar::ClipRadarPoly(CVector2D *poly, const CVector2D *rect)
return n;
}
+#else
+
+int
+ClipPolyPlane(const CVector2D *in, int nin, CVector2D *out, CVector *plane)
+{
+ int j;
+ int nout;
+ int x1, x2;
+ float d1, d2, t;
+
+ nout = 0;
+ for(j = 0; j < nin; j++){
+ x1 = j;
+ x2 = (j+1) % nin;
+
+ d1 = plane->x*in[x1].x + plane->y*in[x1].y + plane->z;
+ d2 = plane->x*in[x2].x + plane->y*in[x2].y + plane->z;
+ if(d1*d2 < 0.0f){
+ t = d1/(d1 - d2);
+ out[nout++] = in[x1]*(1.0f-t) + in[x2]*t;
+ }
+ if(d2 >= 0.0f)
+ out[nout++] = in[x2];
+ }
+ return nout;
+}
+
+int CRadar::ClipRadarPoly(CVector2D *poly, const CVector2D *rect)
+{
+ CVector planes[4] = {
+ CVector(-1.0f, 0.0f, 1.0f),
+ CVector( 1.0f, 0.0f, 1.0f),
+ CVector(0.0f, -1.0f, 1.0f),
+ CVector(0.0f, 1.0f, 1.0f)
+ };
+ CVector2D tmp[8];
+ int n;
+ if(n = ClipPolyPlane(rect, 4, tmp, &planes[0]), n == 0) return 0;
+ if(n = ClipPolyPlane(tmp, n, poly, &planes[1]), n == 0) return 0;
+ if(n = ClipPolyPlane(poly, n, tmp, &planes[2]), n == 0) return 0;
+ if(n = ClipPolyPlane(tmp, n, poly, &planes[3]), n == 0) return 0;
+ return n;
+}
+#endif
bool CRadar::DisplayThisBlip(int32 counter)
{