Merge pull request #102 from learn-more/master
remove some dynamic_cast code
This commit is contained in:
commit
983019f187
@ -363,10 +363,6 @@ namespace spades {
|
||||
Internal() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
SPLog("OpenAL Info:");
|
||||
SPLog(" Vendor: %s", al::qalGetString(AL_VENDOR));
|
||||
SPLog(" Version: %s", al::qalGetString(AL_VERSION));
|
||||
SPLog(" Renderer: %s", al::qalGetString(AL_RENDERER));
|
||||
if(al::qalGetString(AL_EXTENSIONS)){
|
||||
std::vector<std::string> strs = Split(al::qalGetString(AL_EXTENSIONS), " ");
|
||||
SPLog("OpenAL Extensions:");
|
||||
@ -407,7 +403,11 @@ namespace spades {
|
||||
|
||||
SPRaise("Failed to open OpenAL device.");
|
||||
}
|
||||
|
||||
SPLog("OpenAL Info:");
|
||||
SPLog(" Vendor: %s", al::qalGetString(AL_VENDOR));
|
||||
SPLog(" Version: %s", al::qalGetString(AL_VERSION));
|
||||
SPLog(" Renderer: %s", al::qalGetString(AL_RENDERER));
|
||||
|
||||
if(ext = al::qalcGetString(alDevice, ALC_EXTENSIONS)){
|
||||
std::vector<std::string> strs = Split(ext, " ");
|
||||
SPLog("OpenAL ALC Extensions:");
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
CTFGameMode::CTFGameMode() {
|
||||
CTFGameMode::CTFGameMode() : IGameMode( m_CTF ) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "IGameMode.h"
|
||||
#include "../Core/Math.h"
|
||||
#include <Core/Math.h>
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
|
@ -1819,7 +1819,7 @@ namespace spades {
|
||||
|
||||
void Client::DrawCTFObjects() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
CTFGameMode *mode = dynamic_cast<CTFGameMode *>(world->GetMode());
|
||||
CTFGameMode *mode = static_cast<CTFGameMode *>(world->GetMode());
|
||||
int tId;
|
||||
IModel *base = renderer->RegisterModel("Models/MapObjects/CheckPoint.kv6");
|
||||
IModel *intel = renderer->RegisterModel("Models/MapObjects/Intel.kv6");
|
||||
@ -1849,7 +1849,7 @@ namespace spades {
|
||||
|
||||
void Client::DrawTCObjects() {
|
||||
SPADES_MARK_FUNCTION();
|
||||
TCGameMode *mode = dynamic_cast<TCGameMode *>(world->GetMode());
|
||||
TCGameMode *mode = static_cast<TCGameMode *>(world->GetMode());
|
||||
int tId;
|
||||
IModel *base = renderer->RegisterModel("Models/MapObjects/CheckPoint.kv6");
|
||||
int cnt = mode->GetNumTerritories();
|
||||
@ -1948,10 +1948,9 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
if(dynamic_cast<CTFGameMode *>(world->GetMode())){
|
||||
if( IGameMode::m_CTF == world->GetMode()->ModeType() ){
|
||||
DrawCTFObjects();
|
||||
}
|
||||
if(dynamic_cast<TCGameMode *>(world->GetMode())){
|
||||
} else if( IGameMode::m_TC == world->GetMode()->ModeType() ){
|
||||
DrawTCObjects();
|
||||
}
|
||||
|
||||
|
@ -717,8 +717,9 @@ namespace spades {
|
||||
|
||||
|
||||
// draw intel in ctf
|
||||
CTFGameMode *ctfMode = dynamic_cast<CTFGameMode *>(world->GetMode());
|
||||
if(ctfMode){
|
||||
IGameMode* mode = world->GetMode();
|
||||
if( mode && IGameMode::m_CTF == mode->ModeType() ){
|
||||
CTFGameMode *ctfMode = static_cast<CTFGameMode *>(world->GetMode());
|
||||
int tId = p->GetTeamId();
|
||||
if(tId < 3){
|
||||
CTFGameMode::Team& team = ctfMode->GetTeam(p->GetTeamId());
|
||||
|
@ -24,7 +24,17 @@ namespace spades {
|
||||
namespace client {
|
||||
class IGameMode {
|
||||
public:
|
||||
enum Mode {
|
||||
m_CTF = 0,
|
||||
m_TC = 1
|
||||
};
|
||||
private:
|
||||
Mode mMode;
|
||||
public:
|
||||
|
||||
IGameMode( Mode mode ) : mMode(mode) {;}
|
||||
virtual ~IGameMode() {}
|
||||
Mode ModeType() const { return mMode; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -400,8 +400,9 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
CTFGameMode *ctf = dynamic_cast<CTFGameMode *>(world->GetMode());
|
||||
if(ctf){
|
||||
IGameMode* mode = world->GetMode();
|
||||
if( mode && IGameMode::m_CTF == mode->ModeType() ) {
|
||||
CTFGameMode *ctf = static_cast<CTFGameMode *>(mode);
|
||||
Handle<IImage> intelIcon = renderer->RegisterImage("Gfx/Intel.tga");
|
||||
Handle<IImage> baseIcon = renderer->RegisterImage("Gfx/CTFBase.tga");
|
||||
Handle<IImage> medicalIcon = renderer->RegisterImage("Gfx/Medical.tga");
|
||||
@ -441,10 +442,8 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TCGameMode *tc = dynamic_cast<TCGameMode *>(world->GetMode());
|
||||
if(tc){
|
||||
} else if( mode && IGameMode::m_TC == mode->ModeType() ) {
|
||||
TCGameMode *tc = static_cast<TCGameMode *>(mode);
|
||||
Handle<IImage> icon = renderer->RegisterImage("Gfx/TCTerritory.tga");
|
||||
int cnt = tc->GetNumTerritories();
|
||||
for(int i = 0; i < cnt; i++){
|
||||
|
@ -901,8 +901,9 @@ namespace spades {
|
||||
pos.y = reader.ReadFloat();
|
||||
pos.z = reader.ReadFloat();
|
||||
|
||||
CTFGameMode *ctf = dynamic_cast<CTFGameMode *>(GetWorld()->GetMode());
|
||||
if(ctf){
|
||||
IGameMode* mode = GetWorld()->GetMode();
|
||||
if( mode && IGameMode::m_CTF == mode->ModeType() ){
|
||||
CTFGameMode *ctf = static_cast<CTFGameMode *>(mode);
|
||||
switch(type){
|
||||
case BLUE_BASE:
|
||||
ctf->GetTeam(0).basePos = pos;
|
||||
@ -917,10 +918,8 @@ namespace spades {
|
||||
ctf->GetTeam(1).flagPos = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TCGameMode *tc = dynamic_cast<TCGameMode *>(GetWorld()->GetMode());
|
||||
if(tc){
|
||||
} else if( mode && IGameMode::m_TC == mode->ModeType() ){
|
||||
TCGameMode *tc = static_cast<TCGameMode *>(mode);
|
||||
if(type >= tc->GetNumTerritories()){
|
||||
SPRaise("Invalid territory id specified: %d (max = %d)", (int)type, tc->GetNumTerritories() - 1);
|
||||
}
|
||||
@ -1278,17 +1277,20 @@ namespace spades {
|
||||
bool winning = reader.ReadByte() != 0;
|
||||
int state = reader.ReadByte();
|
||||
|
||||
TCGameMode *mode = dynamic_cast<TCGameMode *>(GetWorld()->GetMode());
|
||||
if(!mode) SPRaise("Not TC");
|
||||
IGameMode* mode = GetWorld()->GetMode();
|
||||
if( mode->ModeType() != IGameMode::m_TC ) {
|
||||
SPRaise("Received PacketTypeTerritoryCapture in non-TC gamemode");
|
||||
}
|
||||
TCGameMode *tc = static_cast<TCGameMode *>(mode);
|
||||
|
||||
if(territoryId >= mode->GetNumTerritories()){
|
||||
if(territoryId >= tc->GetNumTerritories()){
|
||||
SPRaise("Invalid territory id %d specified (max = %d)", territoryId,
|
||||
mode->GetNumTerritories()-1);
|
||||
tc->GetNumTerritories()-1);
|
||||
}
|
||||
|
||||
client->TeamCapturedTerritory(state, territoryId);
|
||||
|
||||
TCGameMode::Territory *t = mode->GetTerritory(territoryId);
|
||||
TCGameMode::Territory *t = tc->GetTerritory(territoryId);
|
||||
|
||||
t->ownerTeamId = state;
|
||||
t->progressBasePos = 0.f;
|
||||
@ -1307,18 +1309,21 @@ namespace spades {
|
||||
int rate = (int8_t)reader.ReadByte();
|
||||
float progress = reader.ReadFloat();
|
||||
|
||||
TCGameMode *mode = dynamic_cast<TCGameMode *>(GetWorld()->GetMode());
|
||||
if(!mode) SPRaise("Not TC");
|
||||
IGameMode* mode = GetWorld()->GetMode();
|
||||
if( mode->ModeType() != IGameMode::m_TC ) {
|
||||
SPRaise("Received PacketTypeProgressBar in non-TC gamemode");
|
||||
}
|
||||
TCGameMode *tc = static_cast<TCGameMode *>(mode);
|
||||
|
||||
if(territoryId >= mode->GetNumTerritories()){
|
||||
if(territoryId >= tc->GetNumTerritories()){
|
||||
SPRaise("Invalid territory id %d specified (max = %d)", territoryId,
|
||||
mode->GetNumTerritories()-1);
|
||||
tc->GetNumTerritories()-1);
|
||||
}
|
||||
|
||||
if(progress < -0.1f || progress > 1.1f)
|
||||
SPRaise("Progress value out of range(%f)", progress);
|
||||
|
||||
TCGameMode::Territory *t = mode->GetTerritory(territoryId);
|
||||
TCGameMode::Territory *t = tc->GetTerritory(territoryId);
|
||||
|
||||
t->progressBasePos = progress;
|
||||
t->progressRate = (float)rate * TC_CAPTURE_RATE;
|
||||
@ -1329,13 +1334,16 @@ namespace spades {
|
||||
case PacketTypeIntelCapture:
|
||||
{
|
||||
if(!GetWorld()) SPRaise("No world");
|
||||
CTFGameMode *mode = dynamic_cast<CTFGameMode *>(GetWorld()->GetMode());
|
||||
if(!mode) SPRaise("Not CTF");
|
||||
IGameMode* mode = GetWorld()->GetMode();
|
||||
if( mode->ModeType() != IGameMode::m_CTF ) {
|
||||
SPRaise("Received PacketTypeIntelCapture in non-TC gamemode");
|
||||
}
|
||||
CTFGameMode *ctf = static_cast<CTFGameMode *>(mode);
|
||||
Player *p = GetPlayer(reader.ReadByte());
|
||||
client->PlayerCapturedIntel(p);
|
||||
GetWorld()->GetPlayerPersistent(p->GetId()).kills += 10;
|
||||
mode->GetTeam(p->GetTeamId()).hasIntel = false;
|
||||
mode->GetTeam(p->GetTeamId()).score++;
|
||||
ctf->GetTeam(p->GetTeamId()).hasIntel = false;
|
||||
ctf->GetTeam(p->GetTeamId()).score++;
|
||||
|
||||
bool winning = reader.ReadByte() != 0;
|
||||
if(winning)
|
||||
@ -1345,9 +1353,12 @@ namespace spades {
|
||||
case PacketTypeIntelPickup:
|
||||
{
|
||||
Player *p = GetPlayer(reader.ReadByte());
|
||||
CTFGameMode *mode = dynamic_cast<CTFGameMode *>(GetWorld()->GetMode());
|
||||
if(!mode) SPRaise("Not CTF");
|
||||
CTFGameMode::Team& team = mode->GetTeam(p->GetTeamId());
|
||||
IGameMode* mode = GetWorld()->GetMode();
|
||||
if( mode->ModeType() != IGameMode::m_CTF ) {
|
||||
SPRaise("Received PacketTypeIntelPickup in non-TC gamemode");
|
||||
}
|
||||
CTFGameMode *ctf = static_cast<CTFGameMode *>(mode);
|
||||
CTFGameMode::Team& team = ctf->GetTeam(p->GetTeamId());
|
||||
team.hasIntel = true;
|
||||
team.carrier = p->GetId();
|
||||
client->PlayerPickedIntel(p);
|
||||
@ -1356,9 +1367,12 @@ namespace spades {
|
||||
case PacketTypeIntelDrop:
|
||||
{
|
||||
Player *p = GetPlayer(reader.ReadByte());
|
||||
CTFGameMode *mode = dynamic_cast<CTFGameMode *>(GetWorld()->GetMode());
|
||||
if(!mode) SPRaise("Not CTF");
|
||||
CTFGameMode::Team& team = mode->GetTeam(p->GetTeamId());
|
||||
IGameMode* mode = GetWorld()->GetMode();
|
||||
if( mode->ModeType() != IGameMode::m_CTF ) {
|
||||
SPRaise("Received PacketTypeIntelPickup in non-TC gamemode");
|
||||
}
|
||||
CTFGameMode *ctf = static_cast<CTFGameMode *>(mode);
|
||||
CTFGameMode::Team& team = ctf->GetTeam(p->GetTeamId());
|
||||
team.hasIntel = false;
|
||||
|
||||
Vector3 pos;
|
||||
@ -1366,7 +1380,7 @@ namespace spades {
|
||||
pos.y = reader.ReadFloat();
|
||||
pos.z = reader.ReadFloat();
|
||||
|
||||
mode->GetTeam(1 - p->GetTeamId()).flagPos = pos;
|
||||
ctf->GetTeam(1 - p->GetTeamId()).flagPos = pos;
|
||||
|
||||
client->PlayerDropIntel(p);
|
||||
}
|
||||
|
@ -88,8 +88,10 @@ namespace spades {
|
||||
// no world
|
||||
return;
|
||||
}
|
||||
ctf = dynamic_cast<CTFGameMode *>(world->GetMode());
|
||||
tc = dynamic_cast<TCGameMode *>(world->GetMode());
|
||||
|
||||
IGameMode* mode = world->GetMode();
|
||||
ctf = IGameMode::m_CTF == mode->ModeType() ? static_cast<CTFGameMode *>(mode) : NULL;
|
||||
tc = IGameMode::m_TC == mode->ModeType() ? static_cast<TCGameMode *>(mode) : NULL;
|
||||
|
||||
Handle<IImage>image;
|
||||
IFont *font;
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace spades {
|
||||
namespace client {
|
||||
TCGameMode::TCGameMode(World *w): world(w) {
|
||||
TCGameMode::TCGameMode(World *w): IGameMode( m_TC ), world(w) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
}
|
||||
|
@ -21,8 +21,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "IGameMode.h"
|
||||
#include "../Core/Math.h"
|
||||
#include "../Core/Debug.h"
|
||||
#include <Core/Math.h>
|
||||
#include <Core/Debug.h>
|
||||
#include <vector>
|
||||
|
||||
namespace spades {
|
||||
|
@ -68,8 +68,11 @@ namespace spades {
|
||||
lastTerritoryId = -1;
|
||||
return;
|
||||
}
|
||||
TCGameMode *tc = dynamic_cast<TCGameMode *>(w->GetMode());
|
||||
if(!tc) return;
|
||||
IGameMode* mode = w->GetMode();
|
||||
if( !mode || IGameMode::m_TC != mode->ModeType() ){
|
||||
return;
|
||||
}
|
||||
TCGameMode *tc = static_cast<TCGameMode *>(mode);
|
||||
|
||||
float scrW = renderer->ScreenWidth();
|
||||
float scrH = renderer->ScreenHeight();
|
||||
|
@ -178,7 +178,7 @@ namespace spades {
|
||||
(color.z << 16) |
|
||||
(100UL << 24));
|
||||
}
|
||||
void World::DestroyBlock(std::vector<spades::IntVector3> pos){
|
||||
void World::DestroyBlock(std::vector<spades::IntVector3>& pos){
|
||||
std::vector<CellPos> cells;
|
||||
for(size_t i = 0; i < pos.size(); i++){
|
||||
const IntVector3& p = pos[i];
|
||||
|
@ -105,7 +105,7 @@ namespace spades {
|
||||
PlayerPersistent& GetPlayerPersistent(int index);
|
||||
|
||||
void CreateBlock(IntVector3 pos, IntVector3 color);
|
||||
void DestroyBlock(std::vector<IntVector3> pos);
|
||||
void DestroyBlock(std::vector<IntVector3>& pos);
|
||||
|
||||
struct WeaponRayCastResult {
|
||||
bool hit, startSolid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user