#include <cMap.h>
Public Member Functions | |
void | HandleEvent (bool state, int id) |
void | Render () |
calls DrawMap() | |
virtual bool | Process (tXmlParser::node cur) |
Passes on to all Process() functions of the base classes and calls Base::DisplayError() on failure. | |
Map () | |
default constructor | |
Private Types | |
enum | mode_t { MODE_STD, MODE_ZONE, MODE_CYCLE } |
mode is a var to manage minimap mode : More... | |
enum | rotation_t { ROTATION_FIXED, ROTATION_SPAWN, ROTATION_CYCLE, ROTATION_CAMERA } |
rotation mode More... | |
Private Member Functions | |
void | DrawRimWalls (tList< eWallRim > &list) |
Draws all the rim walls. | |
void | DrawWalls (tList< gNetPlayerWall > &list) |
Draws all player walls. | |
void | DrawObjects (tCoord scale) |
Draws all game objects. | |
void | DrawMap (bool rimWalls, bool cycleWalls, double cycleSize, double border, double x, double y, double w, double h, double rw, double rh, double ix, double iy) |
Draws the entire map. | |
void | ToggleMode (void) |
Toggles the display mode. | |
void | Apply (Mode const &mode) |
Private Attributes | |
mode_t | m_mode |
tCoord | m_centre |
float | m_zoom |
rotation_t | m_rotation |
int | m_toggleKey |
std::auto_ptr< Clipper > | m_clipper |
std::vector< Mode > | m_modes |
int | m_currentMode |
Friends | |
class | ClipperRect |
class | ClipperCircle |
Classes | |
class | Clipper |
class | ClipperCircle |
class | ClipperRect |
class | Mode |
Definition at line 50 of file cMap.h.
enum cWidget::Map::mode_t [private] |
mode is a var to manage minimap mode :
Definition at line 73 of file cMap.h.
00073 { 00074 MODE_STD, 00075 MODE_ZONE, 00076 MODE_CYCLE 00077 } mode_t;
enum cWidget::Map::rotation_t [private] |
rotation mode
Definition at line 79 of file cMap.h.
00079 { 00080 ROTATION_FIXED, 00081 ROTATION_SPAWN, 00082 ROTATION_CYCLE, 00083 ROTATION_CAMERA 00084 } rotation_t;
cWidget::Map::Map | ( | ) |
default constructor
Definition at line 463 of file cMap.cpp.
00463 : 00464 m_mode(MODE_STD), 00465 m_zoom(3), 00466 m_rotation(ROTATION_SPAWN), 00467 m_toggleKey(0), 00468 m_clipper(new ClipperRect()), 00469 m_currentMode(0) 00470 {}
Draws all the rim walls.
Definition at line 371 of file cMap.cpp.
References rGradient::BeginDraw(), rGradient::DrawPoint(), eCoord, eWall::EndPoint(), eWallRim::GetBounds(), eRectangle::GetHigh(), eRectangle::GetLow(), glBegin, glEnd, GrowingArrayBase::Len(), cWidget::WithBackground::m_background, m_mode, max(), MODE_STD, se_rimWallRubberBand, rGradient::SetGradientEdges(), sr_alphaBlend, tCoord::x, and tCoord::y.
Referenced by DrawMap().
00371 { 00372 if(sr_alphaBlend && m_mode == MODE_STD) { 00373 const eRectangle &bounds = eWallRim::GetBounds(); 00374 const tCoord dims = bounds.GetHigh() - bounds.GetLow(); 00375 const float max = fmax(dims.x, dims.y); // make sure we get a square 00376 m_background.SetGradientEdges(bounds.GetLow(), tCoord(bounds.GetLow().x + max, bounds.GetLow().y + max)); 00377 m_background.BeginDraw(); 00378 glBegin(GL_POLYGON); 00379 for(std::vector<tCoord>::iterator iter = se_rimWallRubberBand.begin(); iter != se_rimWallRubberBand.end(); ++iter) { 00380 m_background.DrawPoint(*iter); 00381 } 00382 m_background.DrawPoint(se_rimWallRubberBand.front()); 00383 glEnd(); 00384 } 00385 glDisable(GL_TEXTURE_2D); 00386 glColor4f(1, 1, 1, .5); 00387 glBegin(GL_LINES); 00388 { 00389 for (int i=list.Len()-1; i >= 0; --i) 00390 { 00391 eWallRim *wall = list[i]; 00392 eCoord begin = wall->EndPoint(0), end = wall->EndPoint(1); 00393 glVertex2f(begin.x, begin.y); 00394 glVertex2f(end.x, end.y); 00395 } 00396 00397 00398 } 00399 glEnd(); 00400 }
void cWidget::Map::DrawWalls | ( | tList< gNetPlayerWall > & | list | ) | [private] |
Draws all player walls.
Definition at line 402 of file cMap.cpp.
References gCycleMovement::Alive(), gRealColor::b, gNetPlayerWall::BegPos(), gCycle::color_, gNetPlayerWall::Coords(), gNetPlayerWall::Cycle(), eGameObject::DeathTime(), eCoord, gNetPlayerWall::EndPoint(), gNetPlayerWall::EndPos(), gRealColor::g, gCycleMovement::GetDistance(), glBegin, glEnd, GrowingArrayBase::Len(), gRealColor::r, se_GameTime(), gCycle::ThisWallsLength(), gCycle::WallsLength(), and gCycle::WallsStayUpDelay().
Referenced by DrawMap().
00402 { 00403 unsigned i, len=list.Len(); 00404 double currentTime = se_GameTime(); 00405 bool limitedLength = gCycle::WallsLength() > 0; 00406 double wallsStayUpDelay = gCycle::WallsStayUpDelay(); 00407 glBegin(GL_LINES); 00408 for(i=0; i<len; i++) { 00409 gNetPlayerWall *wall = list[i]; 00410 gCycle *cycle = wall->Cycle(); 00411 if(!cycle) continue; 00412 double wallsLength = cycle->ThisWallsLength(); 00413 double alpha = 1; 00414 if(!cycle->Alive() && wallsStayUpDelay >= 0) { 00415 alpha -= 2 * (currentTime - cycle->DeathTime() - wallsStayUpDelay); 00416 if(alpha <= 0) continue; 00417 } 00418 glColor4f(cycle->color_.r, cycle->color_.g, cycle->color_.b, alpha); 00419 double cycleDist = cycle->GetDistance(); 00420 double minDist = limitedLength && cycleDist > wallsLength ? cycleDist - wallsLength : 0; 00421 const eCoord &begPos = wall->EndPoint(0), &endPos = wall->EndPoint(1); 00422 tArray<gPlayerWallCoord> &coords = wall->Coords(); 00423 double begDist = wall->BegPos(); 00424 double lenDist = wall->EndPos() - begDist; 00425 unsigned j, numcoords = coords.Len(); 00426 if(numcoords < 2) continue; 00427 bool prevDangerous = coords[0].IsDangerous; 00428 double prevDist = coords[0].Pos; 00429 if(prevDist < minDist) prevDist = minDist; 00430 prevDist = (prevDist - begDist) / lenDist; 00431 for(j=1; j<numcoords; j++) { 00432 bool curDangerous = coords[j].IsDangerous; 00433 double curDist = coords[j].Pos; 00434 if(curDist < minDist) curDist = minDist; 00435 curDist = (curDist - begDist) / lenDist; 00436 if(prevDangerous) { 00437 glVertex2f(begPos.x + prevDist * (endPos.x - begPos.x), begPos.y + prevDist * (endPos.y - begPos.y)); 00438 glVertex2f(begPos.x + curDist * (endPos.x - begPos.x), begPos.y + curDist * (endPos.y - begPos.y)); 00439 } 00440 prevDangerous = curDangerous; 00441 prevDist = curDist; 00442 } 00443 } 00444 glEnd(); 00445 }
void cWidget::Map::DrawObjects | ( | tCoord | scale | ) | [private] |
Draws all game objects.
Definition at line 447 of file cMap.cpp.
References eGrid::CurrentGrid(), eGrid::GameObjects(), GrowingArrayBase::Len(), eGameObject::Render2D(), and tASSERT.
Referenced by DrawMap().
00447 { 00448 tList<eGameObject> const &gameObjects = eGrid::CurrentGrid()->GameObjects(); 00449 size_t len = gameObjects.Len(); 00450 for(size_t i = 0; i < len; ++i) { 00451 eGameObject const *obj = gameObjects(i); 00452 tASSERT(obj); 00453 obj->Render2D(scale); 00454 } 00455 }
void cWidget::Map::DrawMap | ( | bool | rimWalls, | |
bool | cycleWalls, | |||
double | cycleSize, | |||
double | border, | |||
double | x, | |||
double | y, | |||
double | w, | |||
double | h, | |||
double | rw, | |||
double | rh, | |||
double | ix, | |||
double | iy | |||
) | [private] |
Draws the entire map.
Definition at line 246 of file cMap.cpp.
References eCamera::CameraDir(), gCycle::Direction(), DrawObjects(), DrawRimWalls(), DrawWalls(), eWallRim::GetBounds(), cCockpit::GetFocusCycle(), eRectangle::GetHigh(), eRectangle::GetLow(), cCockpit::GetPlayer(), m_centre, m_clipper, cWidget::Base::m_Cockpit, m_mode, m_rotation, m_zoom, MODE_CYCLE, MODE_STD, MODE_ZONE, eGameObject::Position(), rotate(), ROTATION_CAMERA, ROTATION_CYCLE, ROTATION_SPAWN, se_rimWalls, sg_netPlayerWalls, sg_netPlayerWallsGridded, sg_Zones, gCycleMovement::SpawnDirection(), gCycleMovement::Speed(), tASSERT, tCoord::x, and tCoord::y.
Referenced by Render().
00249 { 00250 double pl_CurSpeed, min_dist2, dist2, rad, zoom = 1; 00251 tCoord pl_CurPos, rotate; // rotate will hold the cos and sin of the rotation to apply 00252 cCockpit* cp = m_Cockpit; 00253 if(!rimWalls && !cycleWalls) return; 00254 const eRectangle &bounds = eWallRim::GetBounds(); 00255 double lx = bounds.GetLow().x - border, hx = bounds.GetHigh().x + border; 00256 double ly = bounds.GetLow().y - border, hy = bounds.GetHigh().y + border; 00257 double mw = hx - lx, mh = hy - ly; 00258 double xpos, ypos, xscale, yscale; 00259 double xrat = (rw * mh) / (rh * mw); 00260 double yrat = (rh * mw) / (rw * mh); 00261 // set scale and position 00262 if(xrat > yrat) { 00263 xscale = (w * rh) / (mh * rw); 00264 yscale = h / mh; 00265 } else { 00266 xscale = w / mw; 00267 yscale = (h * rw) / (mw * rh); 00268 } 00269 rotate.x = 1; // no rotation 00270 rotate.y = 0; 00271 00272 //do the rotation 00273 switch(m_rotation) { 00274 case ROTATION_SPAWN: 00275 if(!cp->GetFocusCycle()) { break; } 00276 rotate = cp->GetFocusCycle()->SpawnDirection().Turn(0,-1); 00277 break; 00278 case ROTATION_CYCLE: 00279 if(!cp->GetFocusCycle()) { break; } 00280 rotate = cp->GetFocusCycle()->Direction().Turn(0,-1); 00281 break; 00282 case ROTATION_CAMERA: 00283 { 00284 ePlayer const *player = cp->GetPlayer(); 00285 if(!player) break; 00286 eCamera const *cam = player->cam; 00287 if(cam) { 00288 rotate = cam->CameraDir().Turn(0,-1); 00289 } else { 00290 rotate = tCoord(1, 0); 00291 } 00292 } 00293 break; 00294 default: 00295 rotate = tCoord(1, 0); 00296 break; 00297 } 00298 00299 // manage mode 00300 switch (m_mode) { 00301 case MODE_ZONE: 00302 if(!cp->GetFocusCycle()) { break; } 00303 pl_CurPos = cp->GetFocusCycle()->Position(); 00304 min_dist2 = (mw*mw+mh*mh)*1000; 00305 rad = 0; 00306 for(std::deque<gZone *>::const_iterator i = sg_Zones.begin(); i != sg_Zones.end(); ++i) { 00307 tASSERT(*i); 00308 tCoord const &position = (*i)->GetPosition(); 00309 const float radius = (*i)->GetRadius(); 00310 dist2 = (position-pl_CurPos).Norm(); 00311 if (dist2<min_dist2) { 00312 min_dist2 = dist2; 00313 m_centre = position; 00314 rad = radius; 00315 } 00316 } 00317 rad = (rad<15)?15:rad; 00318 zoom = (w>h)?h/(yscale*m_zoom*rad):w/(xscale*m_zoom*rad); 00319 zoom = (zoom<1)?1:zoom; 00320 // check if at least 1 zone was found, if not, toggle to mode 2 ... 00321 if (rad==0) { 00322 m_mode = MODE_CYCLE; 00323 } else { 00324 break; 00325 } 00326 case MODE_CYCLE: 00327 if(!cp->GetFocusCycle()) { break; } 00328 m_centre = cp->GetFocusCycle()->Position(); 00329 pl_CurSpeed = cp->GetFocusCycle()->Speed(); 00330 zoom = (w>h)?h/(yscale*m_zoom*pl_CurSpeed):w/(xscale*m_zoom*pl_CurSpeed); 00331 zoom = (zoom<1)?1:zoom; 00332 break; 00333 default : 00334 zoom = 1; 00335 m_centre.x = lx + mw / 2; 00336 m_centre.y = ly + mh / 2; 00337 break; 00338 } 00339 xscale *=zoom; 00340 yscale *=zoom; 00341 xpos = x - m_centre.x * xscale + w / 2; 00342 ypos = y - m_centre.y * yscale + h / 2; 00343 if(m_mode != MODE_STD) { 00344 m_clipper->Begin(*this, tCoord(x,y), tCoord(x+w, y+h)); 00345 } 00346 // set projection matrix 00347 glPushMatrix(); 00348 glTranslatef(xpos, ypos, 0); 00349 glScalef(xscale, yscale, 1); 00350 // translate and rotate 00351 GLfloat r[16] = { 00352 rotate.x, -rotate.y, 0, 0, 00353 rotate.y, rotate.x, 0, 0, 00354 0, 0, 1, 0, 00355 m_centre.x, m_centre.y, 0, 1}; 00356 glMultMatrixf(r); 00357 glTranslatef(-m_centre.x,-m_centre.y,0); 00358 if(rimWalls) 00359 DrawRimWalls(se_rimWalls); 00360 if(cycleWalls) { 00361 DrawWalls(sg_netPlayerWallsGridded); 00362 DrawWalls(sg_netPlayerWalls); 00363 } 00364 DrawObjects(tCoord((cycleSize * w) / (rw * xscale), (cycleSize * h) / (rh * yscale))); 00365 glPopMatrix(); 00366 if(m_mode != MODE_STD) { 00367 m_clipper->End(); 00368 } 00369 }
void cWidget::Map::ToggleMode | ( | void | ) | [private] |
Toggles the display mode.
Definition at line 457 of file cMap.cpp.
References Apply(), m_currentMode, and m_modes.
Referenced by HandleEvent().
00457 { 00458 if(m_modes.empty()) return; 00459 m_currentMode = (m_currentMode+1) % m_modes.size(); 00460 Apply(m_modes[m_currentMode]); 00461 }
void cWidget::Map::Apply | ( | Mode const & | mode | ) | [private] |
Definition at line 214 of file cMap.cpp.
References cWidget::Map::Mode::m_clipper, m_clipper, cWidget::Map::Mode::m_mode, m_mode, cWidget::Map::Mode::m_rotation, m_rotation, cWidget::Map::Mode::m_zoom, and m_zoom.
Referenced by Process(), and ToggleMode().
00214 { 00215 m_mode = mode.m_mode; 00216 m_rotation = mode.m_rotation; 00217 m_zoom = mode.m_zoom; 00218 m_clipper.reset((*mode.m_clipper)()); 00219 }
void cWidget::Map::HandleEvent | ( | bool | state, | |
int | id | |||
) | [virtual] |
Overwrite if you need to handle custom events (other than toggling)
state | true if the key was pressed, false if it was released | |
id | key id of the event that was received |
Reimplemented from cWidget::Base.
Definition at line 220 of file cMap.cpp.
References HandleEvent(), m_toggleKey, and ToggleMode().
00220 { 00221 if(id == m_toggleKey) { 00222 if(state) { 00223 ToggleMode(); 00224 } 00225 } else { 00226 Base::HandleEvent(state, id); 00227 } 00228 }
void cWidget::Map::Render | ( | ) | [virtual] |
calls DrawMap()
Implements cWidget::Base.
Definition at line 230 of file cMap.cpp.
References DrawMap(), glMatrixMode, cWidget::WithCoordinates::m_position, cWidget::WithCoordinates::m_size, sr_screenWidth, stc_forbidHudMap, tCoord::x, and tCoord::y.
00230 { 00231 // I haven't checked possible initial matrix state, so init to identity and modelview 00232 if(stc_forbidHudMap) return; // the server doesn't want us to do that 00233 glMatrixMode(GL_PROJECTION); 00234 glLoadIdentity(); 00235 glMatrixMode(GL_MODELVIEW); 00236 glLoadIdentity(); 00237 glDisable(GL_TEXTURE_2D); 00238 glDisable(GL_LIGHTING); 00239 glDisable(GL_LINE_SMOOTH); 00240 glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST); 00241 DrawMap(true, true, 00242 5.5, 0., 00243 m_position.x-m_size.x, m_position.y-m_size.y, 2.*m_size.x, 2.*m_size.y, 00244 sr_screenWidth*m_size.x, sr_screenWidth*m_size.y, .5, .5); 00245 }
bool cWidget::Map::Process | ( | tXmlParser::node | cur | ) | [virtual] |
Passes on to all Process() functions of the base classes and calls Base::DisplayError() on failure.
Reimplemented from cWidget::WithCoordinates.
Definition at line 168 of file cMap.cpp.
References cCockpit::AddEventHandler(), Apply(), cWidget::Base::DisplayError(), cWidget::Base::m_Cockpit, m_modes, m_toggleKey, cWidget::WithBackground::Process(), cWidget::WithForeground::Process(), and cWidget::WithCoordinates::Process().
00168 { 00169 if ( 00170 WithCoordinates ::Process(cur) || 00171 WithForeground ::Process(cur) || 00172 WithBackground ::Process(cur)) 00173 return true; 00174 if(cur.IsOfType("MapModes")) { 00175 int toggleKey; 00176 cur.GetProp("toggleKey", toggleKey); 00177 if(toggleKey > 0) { 00178 m_toggleKey = toggleKey; 00179 m_Cockpit->AddEventHandler(toggleKey, this); 00180 } 00181 for(cur = cur.GetFirstChild(); cur; ++cur) { 00182 if(cur.IsOfType("MapMode")) { 00183 m_modes.push_back(Mode(cur)); 00184 if(m_modes.size() == 1) { 00185 Apply(m_modes[0]); // apply the first mode and get rid of the defaults 00186 } 00187 } 00188 } 00189 return true; 00190 } 00191 DisplayError(cur); 00192 return false; 00193 }
friend class ClipperRect [friend] |
friend class ClipperCircle [friend] |
mode_t cWidget::Map::m_mode [private] |
tCoord cWidget::Map::m_centre [private] |
float cWidget::Map::m_zoom [private] |
rotation_t cWidget::Map::m_rotation [private] |
int cWidget::Map::m_toggleKey [private] |
std::auto_ptr<Clipper> cWidget::Map::m_clipper [private] |
std::vector<Mode> cWidget::Map::m_modes [private] |
int cWidget::Map::m_currentMode [private] |