
Code: Select all
#define DONTDOIT
#include "rRender.h"
#include "gWall.h"
#include "gCycle.h"
#include "eAdvWall.h"
#include "eRectangle.h"
#include "eTimer.h"
#include "ePlayer.h"
extern tList<gNetPlayerWall> gridded_sg_netPlayerWalls;
static void DrawRimWalls(tList<eWallRim> &list) {
glColor4f(1, 1, 1, .5);
glBegin(GL_LINES);
unsigned i, len=list.Len();
for(i=0; i<len; i++) {
eWallRim *wall = list[i];
const eCoord &begin = wall->EndPoint(0), &end = wall->EndPoint(1);
glVertex2f(begin.x, begin.y);
glVertex2f(end.x, end.y);
}
glEnd();
}
static void DrawWalls(tList<gNetPlayerWall> &list) {
unsigned i, len=list.Len();
double currentTime = se_GameTime();
double wallsLength = gCycle::WallsLength();
double wallsStayUpDelay = gCycle::WallsStayUpDelay();
bool limitedLength = wallsLength > 0;
glBegin(GL_LINES);
for(i=0; i<len; i++) {
gNetPlayerWall *wall = list[i];
gCycle *cycle = wall->Cycle();
if(!cycle) continue;
double alpha = 1;
if(!cycle->Alive()) {
alpha -= 2 * (currentTime - cycle->DeathTime() - wallsStayUpDelay);
if(alpha <= 0) continue;
}
glColor4f(cycle->color_.r, cycle->color_.g, cycle->color_.b, alpha);
double cycleDist = cycle->GetDistance();
double minDist = limitedLength && cycleDist > wallsLength ? cycleDist - wallsLength : 0;
const eCoord &begPos = wall->EndPoint(0), &endPos = wall->EndPoint(1);
tArray<gPlayerWallCoord> &coords = wall->Coords();
double begDist = wall->BegPos();
double lenDist = wall->EndPos() - begDist;
unsigned j, numcoords = coords.Len();
if(numcoords < 2) continue;
bool prevDangerous = coords[0].IsDangerous;
double prevDist = coords[0].Pos;
if(prevDist < minDist) prevDist = minDist;
prevDist = (prevDist - begDist) / lenDist;
for(j=1; j<numcoords; j++) {
bool curDangerous = coords[j].IsDangerous;
double curDist = coords[j].Pos;
if(curDist < minDist) curDist = minDist;
curDist = (curDist - begDist) / lenDist;
glVertex2f((1 - prevDist) * begPos.x + prevDist * endPos.x, (1 - prevDist) * begPos.y + prevDist * endPos.y);
glVertex2f((1 - curDist) * begPos.x + curDist * endPos.x, (1 - curDist) * begPos.y + curDist * endPos.y);
prevDangerous = curDangerous;
prevDist = curDist;
}
}
glEnd();
}
static void DrawCycles(tList<ePlayerNetID> &list, double xscale, double yscale) {
unsigned i, len=list.Len();
double currentTime = se_GameTime();
for(i=0; i<len; i++) {
const gCycle *cycle = dynamic_cast<gCycle *>(list[i]->Object());
if(cycle) {
double alpha = 1;
if(!cycle->Alive()) {
alpha -= 2 * (currentTime - cycle->DeathTime());
if(alpha <= 0) continue;
}
glColor4f(cycle->color_.r, cycle->color_.g, cycle->color_.b, alpha);
eCoord pos = cycle->Position(), dir = cycle->Direction();
glPushMatrix();
GLfloat m[16] = {
xscale * dir.x, yscale * dir.y, 0, 0,
-xscale * dir.y, yscale * dir.x, 0, 0,
0, 0, 1, 0,
pos.x, pos.y, 0, 1
};
glMultMatrixf(m);
glBegin(GL_TRIANGLES);
glVertex2f(.5, 0);
glVertex2f(-.5, .5);
glVertex2f(-.5, -.5);
glEnd();
glPopMatrix();
}
}
}
/*
* rimWalls draw rim walls?
* cycleWalls draw cycle walls?
* cycles draw cycles?
* cycleSize size of cycles in real-world units
* border border around bounds
* x y w h the map will always fit in this rectangle
* rw rh width and height of the rectangle in real-world units
* ix iy position where inside?
*/
void DrawMap(bool rimWalls, bool cycleWalls, bool cycles,
double cycleSize, double border,
double x, double y, double w, double h,
double rw, double rh, double ix, double iy) {
if(!rimWalls && !cycleWalls && !cycles) return;
const eRectangle &bounds = eWallRim::GetBounds();
double lx = bounds.GetLow().x - border, hx = bounds.GetHigh().x + border;
double ly = bounds.GetLow().y - border, hy = bounds.GetHigh().y + border;
double mw = hx - lx, mh = hy - ly;
double xpos, ypos, xscale, yscale;
double xrat = (rw * mh) / (rh * mw);
double yrat = (rh * mw) / (rw * mh);
if(xrat > yrat) {
xscale = (w * rh) / (mh * rw);
yscale = h / mh;
xpos = x + ix * (w - w * yrat);
ypos = y;
} else {
xscale = w / mw;
yscale = (h * rw) / (mw * rh);
xpos = x;
ypos = y + iy * (h - h * xrat);
}
glPushMatrix();
GLfloat m[16] = {
xscale, 0, 0, 0,
0, yscale, 0, 0,
0, 0, 1, 0,
xpos - xscale * lx, ypos - yscale * ly, 0, 1
};
glMultMatrixf(m);
if(rimWalls)
DrawRimWalls(se_rimWalls);
if(cycleWalls) {
DrawWalls(gridded_sg_netPlayerWalls);
DrawWalls(sg_netPlayerWalls);
}
if(cycles)
DrawCycles(se_PlayerNetIDs, (cycleSize * w) / (rw * xscale), (cycleSize * h) / (rh * yscale));
glPopMatrix();
}
PS. I tend to use doubles all over the place. floats should be fine.