From ac3dae980d49ab6ba229c2cbf1d5195493f60670 Mon Sep 17 00:00:00 2001 From: learn_more Date: Sat, 7 Dec 2013 16:47:03 +0100 Subject: [PATCH 1/3] log openal vendor after initializing. --- Sources/Audio/ALDevice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Audio/ALDevice.cpp b/Sources/Audio/ALDevice.cpp index fa3172f8..6529232a 100644 --- a/Sources/Audio/ALDevice.cpp +++ b/Sources/Audio/ALDevice.cpp @@ -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 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 strs = Split(ext, " "); SPLog("OpenAL ALC Extensions:"); From 1a42e828de764113584180e0e4410299a4d68d84 Mon Sep 17 00:00:00 2001 From: learn_more Date: Sat, 7 Dec 2013 16:58:39 +0100 Subject: [PATCH 2/3] ModeType instead of dynamic_cast for gamemodes (dynamic_cast is slowwww) --- Sources/Client/CTFGameMode.cpp | 2 +- Sources/Client/CTFGameMode.h | 2 +- Sources/Client/Client.cpp | 9 ++-- Sources/Client/ClientPlayer.cpp | 5 ++- Sources/Client/IGameMode.h | 10 +++++ Sources/Client/MapView.cpp | 11 +++-- Sources/Client/NetClient.cpp | 68 +++++++++++++++++++------------ Sources/Client/ScoreboardView.cpp | 6 ++- Sources/Client/TCGameMode.cpp | 2 +- Sources/Client/TCGameMode.h | 4 +- Sources/Client/TCProgressView.cpp | 7 +++- 11 files changed, 77 insertions(+), 49 deletions(-) diff --git a/Sources/Client/CTFGameMode.cpp b/Sources/Client/CTFGameMode.cpp index a525ae60..f5ed4c67 100644 --- a/Sources/Client/CTFGameMode.cpp +++ b/Sources/Client/CTFGameMode.cpp @@ -23,7 +23,7 @@ namespace spades { namespace client { - CTFGameMode::CTFGameMode() { + CTFGameMode::CTFGameMode() : IGameMode( m_CTF ) { SPADES_MARK_FUNCTION(); } diff --git a/Sources/Client/CTFGameMode.h b/Sources/Client/CTFGameMode.h index c4c841c5..7ffd1fae 100644 --- a/Sources/Client/CTFGameMode.h +++ b/Sources/Client/CTFGameMode.h @@ -20,7 +20,7 @@ #pragma once #include "IGameMode.h" -#include "../Core/Math.h" +#include namespace spades { namespace client { diff --git a/Sources/Client/Client.cpp b/Sources/Client/Client.cpp index ff705d6e..c2f667d3 100644 --- a/Sources/Client/Client.cpp +++ b/Sources/Client/Client.cpp @@ -1819,7 +1819,7 @@ namespace spades { void Client::DrawCTFObjects() { SPADES_MARK_FUNCTION(); - CTFGameMode *mode = dynamic_cast(world->GetMode()); + CTFGameMode *mode = static_cast(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(world->GetMode()); + TCGameMode *mode = static_cast(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(world->GetMode())){ + if( IGameMode::m_CTF == world->GetMode()->ModeType() ){ DrawCTFObjects(); - } - if(dynamic_cast(world->GetMode())){ + } else if( IGameMode::m_TC == world->GetMode()->ModeType() ){ DrawTCObjects(); } diff --git a/Sources/Client/ClientPlayer.cpp b/Sources/Client/ClientPlayer.cpp index ab4fec44..217f2cb0 100644 --- a/Sources/Client/ClientPlayer.cpp +++ b/Sources/Client/ClientPlayer.cpp @@ -717,8 +717,9 @@ namespace spades { // draw intel in ctf - CTFGameMode *ctfMode = dynamic_cast(world->GetMode()); - if(ctfMode){ + IGameMode* mode = world->GetMode(); + if( mode && IGameMode::m_CTF == mode->ModeType() ){ + CTFGameMode *ctfMode = static_cast(world->GetMode()); int tId = p->GetTeamId(); if(tId < 3){ CTFGameMode::Team& team = ctfMode->GetTeam(p->GetTeamId()); diff --git a/Sources/Client/IGameMode.h b/Sources/Client/IGameMode.h index 30e35e09..d152e880 100644 --- a/Sources/Client/IGameMode.h +++ b/Sources/Client/IGameMode.h @@ -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; } }; } } diff --git a/Sources/Client/MapView.cpp b/Sources/Client/MapView.cpp index a6223431..f2130eb0 100644 --- a/Sources/Client/MapView.cpp +++ b/Sources/Client/MapView.cpp @@ -400,8 +400,9 @@ namespace spades { } } - CTFGameMode *ctf = dynamic_cast(world->GetMode()); - if(ctf){ + IGameMode* mode = world->GetMode(); + if( mode && IGameMode::m_CTF == mode->ModeType() ) { + CTFGameMode *ctf = static_cast(mode); Handle intelIcon = renderer->RegisterImage("Gfx/Intel.tga"); Handle baseIcon = renderer->RegisterImage("Gfx/CTFBase.tga"); Handle medicalIcon = renderer->RegisterImage("Gfx/Medical.tga"); @@ -441,10 +442,8 @@ namespace spades { } } } - } - - TCGameMode *tc = dynamic_cast(world->GetMode()); - if(tc){ + } else if( mode && IGameMode::m_TC == mode->ModeType() ) { + TCGameMode *tc = static_cast(mode); Handle icon = renderer->RegisterImage("Gfx/TCTerritory.tga"); int cnt = tc->GetNumTerritories(); for(int i = 0; i < cnt; i++){ diff --git a/Sources/Client/NetClient.cpp b/Sources/Client/NetClient.cpp index 60eff5bc..3808e7e1 100644 --- a/Sources/Client/NetClient.cpp +++ b/Sources/Client/NetClient.cpp @@ -901,8 +901,9 @@ namespace spades { pos.y = reader.ReadFloat(); pos.z = reader.ReadFloat(); - CTFGameMode *ctf = dynamic_cast(GetWorld()->GetMode()); - if(ctf){ + IGameMode* mode = GetWorld()->GetMode(); + if( mode && IGameMode::m_CTF == mode->ModeType() ){ + CTFGameMode *ctf = static_cast(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(GetWorld()->GetMode()); - if(tc){ + } else if( mode && IGameMode::m_TC == mode->ModeType() ){ + TCGameMode *tc = static_cast(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(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(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(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(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(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(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(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(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(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(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); } diff --git a/Sources/Client/ScoreboardView.cpp b/Sources/Client/ScoreboardView.cpp index 1413e608..2d38130d 100644 --- a/Sources/Client/ScoreboardView.cpp +++ b/Sources/Client/ScoreboardView.cpp @@ -88,8 +88,10 @@ namespace spades { // no world return; } - ctf = dynamic_cast(world->GetMode()); - tc = dynamic_cast(world->GetMode()); + + IGameMode* mode = world->GetMode(); + ctf = IGameMode::m_CTF == mode->ModeType() ? static_cast(mode) : NULL; + tc = IGameMode::m_TC == mode->ModeType() ? static_cast(mode) : NULL; Handleimage; IFont *font; diff --git a/Sources/Client/TCGameMode.cpp b/Sources/Client/TCGameMode.cpp index e6fb930c..76a90746 100644 --- a/Sources/Client/TCGameMode.cpp +++ b/Sources/Client/TCGameMode.cpp @@ -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(); } diff --git a/Sources/Client/TCGameMode.h b/Sources/Client/TCGameMode.h index 2e414c26..732feed4 100644 --- a/Sources/Client/TCGameMode.h +++ b/Sources/Client/TCGameMode.h @@ -21,8 +21,8 @@ #pragma once #include "IGameMode.h" -#include "../Core/Math.h" -#include "../Core/Debug.h" +#include +#include #include namespace spades { diff --git a/Sources/Client/TCProgressView.cpp b/Sources/Client/TCProgressView.cpp index c3b985e2..d5977bad 100644 --- a/Sources/Client/TCProgressView.cpp +++ b/Sources/Client/TCProgressView.cpp @@ -68,8 +68,11 @@ namespace spades { lastTerritoryId = -1; return; } - TCGameMode *tc = dynamic_cast(w->GetMode()); - if(!tc) return; + IGameMode* mode = w->GetMode(); + if( !mode || IGameMode::m_TC != mode->ModeType() ){ + return; + } + TCGameMode *tc = static_cast(mode); float scrW = renderer->ScreenWidth(); float scrH = renderer->ScreenHeight(); From 3651097c7981bd616f82aa78e653f548d1f407ba Mon Sep 17 00:00:00 2001 From: learn_more Date: Sat, 7 Dec 2013 17:33:12 +0100 Subject: [PATCH 3/3] don't create a new vector on calling the function --- Sources/Client/World.cpp | 2 +- Sources/Client/World.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Client/World.cpp b/Sources/Client/World.cpp index 5af5c06b..3930bf6c 100644 --- a/Sources/Client/World.cpp +++ b/Sources/Client/World.cpp @@ -178,7 +178,7 @@ namespace spades { (color.z << 16) | (100UL << 24)); } - void World::DestroyBlock(std::vector pos){ + void World::DestroyBlock(std::vector& pos){ std::vector cells; for(size_t i = 0; i < pos.size(); i++){ const IntVector3& p = pos[i]; diff --git a/Sources/Client/World.h b/Sources/Client/World.h index f5bdc2c6..5512baf1 100644 --- a/Sources/Client/World.h +++ b/Sources/Client/World.h @@ -105,7 +105,7 @@ namespace spades { PlayerPersistent& GetPlayerPersistent(int index); void CreateBlock(IntVector3 pos, IntVector3 color); - void DestroyBlock(std::vector pos); + void DestroyBlock(std::vector& pos); struct WeaponRayCastResult { bool hit, startSolid;