Skip to content

Update to C++11 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ branches:
- master

before_install: sudo apt-get update -qq
install: sudo apt-get install -qq build-essential libsdl1.2debian libsdl-image1.2 libopenal1 libsdl1.2-dev libsdl-image1.2-dev libopenal-dev libvorbis-dev
install:
- sudo apt-get install -qq build-essential libsdl1.2debian libsdl-image1.2 libopenal1 libsdl1.2-dev libsdl-image1.2-dev libopenal-dev libvorbis-dev
- sudo apt-get install -qq g++-4.8
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
script: cd ./source/src; make all

notifications:
Expand Down
1 change: 1 addition & 0 deletions source/codeblocks/AssaultCube.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Option projectResourceIncludeDirsRelation="1" />
<Compiler>
<Add option="-fomit-frame-pointer" />
<Add option="-std=c++11" />
<Add option="-w" />
<Add option="-Ofast" />
</Compiler>
Expand Down
2 changes: 1 addition & 1 deletion source/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEBUG ?= 0
WARNINGS ?= 1
override CXXFLAGS += -fsigned-char
override CXXFLAGS += -fsigned-char --std=c++11
ifeq ($(DEBUG), 1)
override CXXFLAGS += -ggdb3 -D_DEBUG -Wextra
override WARNINGS = 1
Expand Down
38 changes: 19 additions & 19 deletions source/src/audiomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

VARF(audio, 0, 1, 1, initwarning("sound configuration", INIT_RESET, CHANGE_SOUND));
VARP(audiodebug, 0, 0, 1);
char *musicdonecmd = NULL;
char *musicdonecmd = nullptr;

VARFP(musicvol, 0, 128, 255, audiomgr.setmusicvol(musicvol));

// audio manager

audiomanager::audiomanager()
: nosound(true), currentpitch(1.0f), device(NULL), context(NULL), gamemusic(NULL) {}
: nosound(true), currentpitch(1.0f), device(nullptr), context(nullptr), gamemusic(nullptr) {}

void audiomanager::initsound()
{
Expand All @@ -24,19 +24,19 @@ void audiomanager::initsound()
}

nosound = true;
device = NULL;
context = NULL;
device = nullptr;
context = nullptr;

// list available devices
if(alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
if(alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
{
const ALCchar *devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
const ALCchar *devices = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
if(devices)
{
string d;
copystring(d, "Audio devices: ");

// null separated device string
// nullptr separated device string
for(const ALchar *c = devices; c[strlen(c)+1]; c += strlen(c)+1)
{
if(c!=devices) concatstring(d, ", ");
Expand All @@ -48,11 +48,11 @@ void audiomanager::initsound()

// open device
const char *devicename = getalias("openaldevice");
device = alcOpenDevice(devicename && devicename[0] ? devicename : NULL);
device = alcOpenDevice(devicename && devicename[0] ? devicename : nullptr);

if(device)
{
context = alcCreateContext(device, NULL);
context = alcCreateContext(device, nullptr);
if(context)
{
alcMakeContextCurrent(context);
Expand Down Expand Up @@ -188,7 +188,7 @@ void audiomanager::registermusic(char *name)
musics.add(newstring(name));
}

int audiomanager::findsound(char *name, int vol, vector<soundconfig> &sounds)
int audiomanager::findsound(char *name, int vol, vect<soundconfig> &sounds)
{
loopv(sounds)
{
Expand All @@ -197,7 +197,7 @@ int audiomanager::findsound(char *name, int vol, vector<soundconfig> &sounds)
return -1;
}

int audiomanager::addsound(char *name, int vol, int maxuses, bool loop, vector<soundconfig> &sounds, bool load, int audibleradius)
int audiomanager::addsound(char *name, int vol, int maxuses, bool loop, vect<soundconfig> &sounds, bool load, int audibleradius)
{
if(nosound) return -1;
if(!soundvol) return -1;
Expand Down Expand Up @@ -271,7 +271,7 @@ void audiomanager::soundcleanup()
sourcescheduler::instance().reset();

// shutdown openal
alcMakeContextCurrent(NULL);
alcMakeContextCurrent(nullptr);
if(context) alcDestroyContext(context);
if(device) alcCloseDevice(device);
}
Expand Down Expand Up @@ -363,7 +363,7 @@ void audiomanager::updateplayerfootsteps(playerent *p)
// manage looping sounds
location *audiomanager::updateloopsound(int sound, bool active, float vol)
{
location *l = locations.find(sound, NULL, gamesounds);
location *l = locations.find(sound, nullptr, gamesounds);
if(!l && active) l = _playsound(sound, camerareference(), SP_HIGH, 0.0f, true);
else if(l && !active) l->drop();
if(l && vol != 1.0f) l->src->gain(vol);
Expand Down Expand Up @@ -430,7 +430,7 @@ COMMAND(soundtest, "");

// sound configuration

soundconfig::soundconfig(sbuffer *b, int vol, int maxuses, bool loop, int audibleradius)
soundconfig::soundconfig(sbuffer *b=nullptr, int vol=0, int maxuses=0, bool loop=false, int audibleradius=0)
{
buf = b;
this->vol = vol > 0 ? vol : 100;
Expand All @@ -452,7 +452,7 @@ void soundconfig::ondetach()
uses--;
}

vector<soundconfig> gamesounds, mapsounds;
vect<soundconfig> gamesounds, mapsounds;

void audiomanager::detachsounds(playerent *owner)
{
Expand All @@ -466,8 +466,8 @@ VARP(maxsoundsatonce, 0, 32, 100);

location *audiomanager::_playsound(int n, const worldobjreference &r, int priority, float offset, bool loop)
{
if(nosound || !soundvol) return NULL;
if(soundmuted(n)) return NULL;
if(nosound || !soundvol) return nullptr;
if(soundmuted(n)) return nullptr;
DEBUGVAR(n);
DEBUGVAR(priority);

Expand All @@ -480,7 +480,7 @@ location *audiomanager::_playsound(int n, const worldobjreference &r, int priori
if(maxsoundsatonce && soundsatonce>maxsoundsatonce)
{
DEBUGVAR(soundsatonce);
return NULL;
return nullptr;
}
}

Expand Down Expand Up @@ -617,7 +617,7 @@ void audiomanager::updateaudio()
if(musicdonecmd)
{
char *cmd = musicdonecmd;
musicdonecmd = NULL;
musicdonecmd = nullptr;
execute(cmd);
delete[] cmd;
}
Expand Down
8 changes: 4 additions & 4 deletions source/src/bot/ac_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void CACBot::Spawn()
m_iStrafeTime = m_iStrafeCheckDelay = 0;
m_iMoveDir = DIR_NONE;

m_pPrevEnemy = NULL;
m_pPrevEnemy = nullptr;
m_iCombatNavTime = 0;
m_iSPMoveTime = 0;
m_iEnemySearchDelay = 0;
Expand All @@ -46,13 +46,13 @@ void CACBot::Spawn()
m_bShootAtFeet = (RandomLong(1, 100) <= m_pBotSkill->sShootAtFeetWithRLPercent);
m_iHuntDelay = 0;
m_vHuntLocation = m_vPrevHuntLocation = g_vecZero;
m_pHuntTarget = NULL;
m_pHuntTarget = nullptr;
m_fPrevHuntDist = 0.0f;
m_iHuntLastTurnLessTime = m_iHuntPlayerUpdateTime = m_iHuntPauseTime = 0;

m_iLastJumpPad = 0;
m_pTargetEnt = NULL;
m_pTargetFlag = NULL;
m_pTargetEnt = nullptr;
m_pTargetFlag = nullptr;
m_iCheckTeleporterDelay = m_iCheckJumppadsDelay = 0;
m_iCheckEntsDelay = 0;
m_iCheckFlagsDelay = 0;
Expand Down
20 changes: 10 additions & 10 deletions source/src/bot/ac_bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight)
*/

float flDist;
entity *pNewTargetEnt = NULL;
waypoint_s *pWptNearBot = NULL, *pBestWpt = NULL;
entity *pNewTargetEnt = nullptr;
waypoint_s *pWptNearBot = nullptr, *pBestWpt = nullptr;
short sScore, sHighestScore = 0;

if ((WaypointClass.m_iWaypointCount >= 1) && bUseWPs)
Expand Down Expand Up @@ -228,7 +228,7 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight)
if (f > 100.0f) f = 100.0f;
sScore += ((100 - short(f)) / 2);

waypoint_s *pWptNearEnt = NULL;
waypoint_s *pWptNearEnt = nullptr;
// If this entity isn't visible check if there is a nearby waypoint
if (!IsReachable(o, flMaxHeight))//(!IsVisible(o))
{
Expand All @@ -245,7 +245,7 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight)
}

// Score on visibility
if (pWptNearEnt == NULL) // Ent is visible
if (pWptNearEnt == nullptr) // Ent is visible
sScore += 30;
else
sScore += 15;
Expand All @@ -256,7 +256,7 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight)
if (pWptNearEnt)
pBestWpt = pWptNearEnt;
else
pBestWpt = NULL; // Best ent so far doesn't need any waypoints
pBestWpt = nullptr; // Best ent so far doesn't need any waypoints

sHighestScore = sScore;
pNewTargetEnt = &ents[i];
Expand Down Expand Up @@ -288,8 +288,8 @@ entity *CACBot::SearchForFlags(bool bUseWPs, float flRange, float flMaxHeight)
- Distance
*/
float flDist;
entity *pNewTargetFlag = NULL;
waypoint_s *pWptNearBot = NULL, *pBestWpt = NULL;
entity *pNewTargetFlag = nullptr;
waypoint_s *pWptNearBot = nullptr, *pBestWpt = nullptr;
short sScore, sHighestScore = 0;
vec vNewGoal = g_vecZero;

Expand Down Expand Up @@ -327,7 +327,7 @@ entity *CACBot::SearchForFlags(bool bUseWPs, float flRange, float flMaxHeight)
if (ff > 100.0f) ff = 100.0f;
sScore += ((100 - short(ff)) / 2);

waypoint_s *pWptNearEnt = NULL;
waypoint_s *pWptNearEnt = nullptr;
// If this flag entity isn't visible check if there is a nearby waypoint
if (!IsReachable(o, flMaxHeight))//(!IsVisible(o))
{
Expand All @@ -344,15 +344,15 @@ entity *CACBot::SearchForFlags(bool bUseWPs, float flRange, float flMaxHeight)
}

// Score on visibility
if (pWptNearEnt == NULL) // Ent is visible
if (pWptNearEnt == nullptr) // Ent is visible
sScore += 6;
else
sScore += 3;

if(sScore > sHighestScore)
{
if (pWptNearEnt) pBestWpt = pWptNearEnt;
else pBestWpt = NULL; // best flag doesn't need any waypoints
else pBestWpt = nullptr; // best flag doesn't need any waypoints

vNewGoal = o;
pNewTargetFlag = &e;
Expand Down
22 changes: 11 additions & 11 deletions source/src/bot/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void CBot::Spawn()
// Init all bot variables

m_pMyEnt->targetyaw = m_pMyEnt->targetpitch = 0.0f;
m_pMyEnt->enemy = NULL;
m_pMyEnt->enemy = nullptr;
m_pMyEnt->maxspeed = 22.0f;
m_pMyEnt->pBot = this;

Expand All @@ -85,7 +85,7 @@ void CBot::Spawn()
m_iStrafeTime = m_iStrafeCheckDelay = 0;
m_iMoveDir = DIR_NONE;

m_pPrevEnemy = NULL;
m_pPrevEnemy = nullptr;
m_iCombatNavTime = 0;
m_iSPMoveTime = 0;
m_iEnemySearchDelay = 0;
Expand All @@ -95,16 +95,16 @@ void CBot::Spawn()
m_bShootAtFeet = (RandomLong(1, 100) <= m_pBotSkill->sShootAtFeetWithRLPercent);
m_iHuntDelay = 0;
m_vHuntLocation = m_vPrevHuntLocation = g_vecZero;
m_pHuntTarget = NULL;
m_pHuntTarget = nullptr;
m_fPrevHuntDist = 0.0f;
m_iHuntLastTurnLessTime = m_iHuntPlayerUpdateTime = m_iHuntPauseTime = 0;
m_iLookAroundDelay = m_iLookAroundTime = m_iLookAroundUpdateTime = 0;
m_fLookAroundYaw = 0.0f;
m_bLookLeft = false;

m_iLastJumpPad = 0;
m_pTargetEnt = NULL;
m_pTargetFlag = NULL;
m_pTargetEnt = nullptr;
m_pTargetFlag = nullptr;
while(!m_UnreachableEnts.Empty()) delete m_UnreachableEnts.Pop();
m_iCheckTeleporterDelay = m_iCheckJumppadsDelay = 0;
m_iCheckEntsDelay = 0;
Expand Down Expand Up @@ -309,7 +309,7 @@ bool CBot::SelectGun(int Gun)
bool CBot::IsVisible(entity *e, bool CheckPlayers)
{
vec v(e->x, e->y, e->z);
return ::IsVisible(m_pMyEnt->o, v, (CheckPlayers) ? m_pMyEnt : NULL);
return ::IsVisible(m_pMyEnt->o, v, (CheckPlayers) ? m_pMyEnt : nullptr);
}

bool CBot::IsVisible(vec o, int Dir, float flDist, bool CheckPlayers, float *pEndDist)
Expand Down Expand Up @@ -394,23 +394,23 @@ void CBot::ResetCurrentTask()
switch (m_eCurrentBotState)
{
case STATE_ENEMY:
m_pMyEnt->enemy = NULL;
m_pTargetEnt = NULL;
m_pMyEnt->enemy = nullptr;
m_pTargetEnt = nullptr;
m_iCombatNavTime = m_iMoveDir = 0;
m_bCombatJump = false;
m_vGoal = g_vecZero;
break;
case STATE_FLAG:
m_pTargetFlag = NULL;
m_pTargetFlag = nullptr;
m_vGoal = g_vecZero;
break;
case STATE_ENT:
m_pTargetEnt = NULL;
m_pTargetEnt = nullptr;
m_vGoal = g_vecZero;
break;
case STATE_SP:
m_iSPMoveTime = m_iMoveDir = 0;
m_pTargetEnt = NULL;
m_pTargetEnt = nullptr;
m_vGoal = g_vecZero;
break;
case STATE_NORMAL:
Expand Down
6 changes: 3 additions & 3 deletions source/src/bot/bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ class CBot
void CheckFOV(void);
bool IsVisible(const vec &o, bool CheckPlayers = false) { return ::IsVisible(m_pMyEnt->o, o,
(CheckPlayers) ? m_pMyEnt :
NULL); };
nullptr); };
bool IsVisible(playerent *d, bool CheckPlayers = false) { return ::IsVisible(m_pMyEnt->o, d->o,
(CheckPlayers) ?
m_pMyEnt : NULL); };
m_pMyEnt : nullptr); };
bool IsVisible(entity *e, bool CheckPlayers = false);
bool IsVisible(vec o, int Dir, float flDist, bool CheckPlayers, float *pEndDist = NULL);
bool IsVisible(vec o, int Dir, float flDist, bool CheckPlayers, float *pEndDist = nullptr);
bool IsVisible(int Dir, float flDist, bool CheckPlayers)
{ return IsVisible(m_pMyEnt->o, Dir, flDist, CheckPlayers); };
bool IsInFOV(const vec &o);
Expand Down
Loading