Skip to content

Commit

Permalink
[10432] Rename ASSERT -> MANGOS_ASSERT and related fixes
Browse files Browse the repository at this point in the history
ASSERT hard use in predictable way because diff. 3rd party libs code
redefine it inf different ways and hard make sure that used in end
of mangos define version. This is real detected problem make some
expected assert checks ignored and so bugs not detected as expected from code.

In addition made related changes:
* Common.h header expected to be first include in any src/game/header except most simple cases.
* Related FILE.h header expected to be first include in FILE.cpp
* Fixed some absent includes and type forwards for safe build without PCH enabled.
* Avoid using MANGOS_ASSERT in src/framework code
  • Loading branch information
VladimirMangos committed Sep 2, 2010
1 parent 1a35175 commit 383cbc7
Show file tree
Hide file tree
Showing 77 changed files with 309 additions and 260 deletions.
14 changes: 8 additions & 6 deletions src/framework/GameSystem/NGrid.h
Expand Up @@ -26,6 +26,8 @@
#include "GameSystem/GridReference.h"
#include "Timer.h"

#include <cassert>

class GridInfo
{
public:
Expand Down Expand Up @@ -96,15 +98,15 @@ class MANGOS_DLL_DECL NGrid

const GridType& operator()(uint32 x, uint32 y) const
{
ASSERT(x < N);
ASSERT(y < N);
assert(x < N);
assert(y < N);
return i_cells[x][y];
}

GridType& operator()(uint32 x, uint32 y)
{
ASSERT(x < N);
ASSERT(y < N);
assert(x < N);
assert(y < N);
return i_cells[x][y];
}

Expand Down Expand Up @@ -185,8 +187,8 @@ class MANGOS_DLL_DECL NGrid

GridType& getGridType(const uint32& x, const uint32& y)
{
ASSERT(x < N);
ASSERT(y < N);
assert(x < N);
assert(y < N);
return i_cells[x][y];
}

Expand Down
3 changes: 2 additions & 1 deletion src/framework/GameSystem/TypeContainer.h
Expand Up @@ -24,6 +24,7 @@
* types of object at the same time.
*/

#include <cassert>
#include <map>
#include <vector>
#include "Platform/Define.h"
Expand Down Expand Up @@ -89,7 +90,7 @@ class TypeUnorderedMapContainer
}
else
{
ASSERT(i->second == obj && "Object with certain key already in but objects are different!");
assert(i->second == obj && "Object with certain key already in but objects are different!");
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/Utilities/LinkedReference/Reference.h
Expand Up @@ -54,7 +54,7 @@ class Reference : public LinkedListElement
// Create new link
void link(TO* toObj, FROM* fromObj)
{
ASSERT(fromObj); // fromObj MUST not be NULL
assert(fromObj); // fromObj MUST not be NULL
if (isValid())
unlink();

Expand Down
2 changes: 1 addition & 1 deletion src/game/AchievementMgr.cpp
Expand Up @@ -2164,7 +2164,7 @@ void AchievementGlobalMgr::LoadAchievementCriteriaList()
if(!criteria)
continue;

ASSERT(criteria->requiredType < ACHIEVEMENT_CRITERIA_TYPE_TOTAL && "Not updated ACHIEVEMENT_CRITERIA_TYPE_TOTAL?");
MANGOS_ASSERT(criteria->requiredType < ACHIEVEMENT_CRITERIA_TYPE_TOTAL && "Not updated ACHIEVEMENT_CRITERIA_TYPE_TOTAL?");

m_AchievementCriteriasByType[criteria->requiredType].push_back(criteria);
m_AchievementCriteriaListByAchievement[criteria->referredAchievement].push_back(criteria);
Expand Down
7 changes: 3 additions & 4 deletions src/game/AuctionHouseMgr.cpp
Expand Up @@ -16,14 +16,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "Common.h"
#include "AuctionHouseMgr.h"
#include "Database/DatabaseEnv.h"
#include "Database/SQLStorage.h"
#include "DBCStores.h"
#include "ProgressBar.h"

#include "AccountMgr.h"
#include "AuctionHouseMgr.h"
#include "Item.h"
#include "Language.h"
#include "Log.h"
Expand Down Expand Up @@ -439,8 +438,8 @@ void AuctionHouseMgr::LoadAuctions()

void AuctionHouseMgr::AddAItem( Item* it )
{
ASSERT( it );
ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end());
MANGOS_ASSERT( it );
MANGOS_ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end());
mAitems[it->GetGUIDLow()] = it;
}

Expand Down
4 changes: 3 additions & 1 deletion src/game/AuctionHouseMgr.h
Expand Up @@ -19,8 +19,10 @@
#ifndef _AUCTION_HOUSE_MGR_H
#define _AUCTION_HOUSE_MGR_H

#include "Common.h"
#include "SharedDefines.h"
#include "Policies/Singleton.h"
#include "DBCStructure.h"

class Item;
class Player;
Expand Down Expand Up @@ -86,7 +88,7 @@ class AuctionHouseObject

void AddAuction(AuctionEntry *ah)
{
ASSERT( ah );
MANGOS_ASSERT( ah );
AuctionsMap[ah->Id] = ah;
}

Expand Down
5 changes: 2 additions & 3 deletions src/game/Bag.cpp
Expand Up @@ -16,7 +16,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "Common.h"
#include "Bag.h"
#include "ObjectMgr.h"
#include "Database/DatabaseEnv.h"
Expand Down Expand Up @@ -136,7 +135,7 @@ uint32 Bag::GetFreeSlots() const

void Bag::RemoveItem( uint8 slot, bool /*update*/ )
{
ASSERT(slot < MAX_BAG_SIZE);
MANGOS_ASSERT(slot < MAX_BAG_SIZE);

if (m_bagslot[slot])
m_bagslot[slot]->SetContainer(NULL);
Expand All @@ -147,7 +146,7 @@ void Bag::RemoveItem( uint8 slot, bool /*update*/ )

void Bag::StoreItem( uint8 slot, Item *pItem, bool /*update*/ )
{
ASSERT(slot < MAX_BAG_SIZE);
MANGOS_ASSERT(slot < MAX_BAG_SIZE);

if( pItem )
{
Expand Down
7 changes: 4 additions & 3 deletions src/game/Bag.h
Expand Up @@ -19,12 +19,13 @@
#ifndef MANGOS_BAG_H
#define MANGOS_BAG_H

// Maximum 36 Slots ( (CONTAINER_END - CONTAINER_FIELD_SLOT_1)/2
#define MAX_BAG_SIZE 36 // 2.0.12

#include "Common.h"
#include "ItemPrototype.h"
#include "Item.h"

// Maximum 36 Slots ( (CONTAINER_END - CONTAINER_FIELD_SLOT_1)/2
#define MAX_BAG_SIZE 36 // 2.0.12

class Bag : public Item
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGround.h
Expand Up @@ -393,7 +393,7 @@ class BattleGround
void SetBgMap(BattleGroundMap* map) { m_Map = map; }
BattleGroundMap* GetBgMap()
{
ASSERT(m_Map);
MANGOS_ASSERT(m_Map);
return m_Map;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGroundAB.cpp
Expand Up @@ -252,7 +252,7 @@ int32 BattleGroundAB::_GetNodeNameId(uint8 node)
case BG_AB_NODE_LUMBER_MILL:return LANG_BG_AB_NODE_LUMBER_MILL;
case BG_AB_NODE_GOLD_MINE: return LANG_BG_AB_NODE_GOLD_MINE;
default:
ASSERT(0);
MANGOS_ASSERT(0);
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/game/BattleGroundAB.h
Expand Up @@ -18,7 +18,8 @@
#ifndef __BATTLEGROUNDAB_H
#define __BATTLEGROUNDAB_H

class BattleGround;
#include "Common.h"
#include "BattleGround.h"

enum BG_AB_WorldStates
{
Expand Down
34 changes: 17 additions & 17 deletions src/game/BattleGroundAV.cpp
Expand Up @@ -210,7 +210,7 @@ void BattleGroundAV::HandleQuestComplete(uint32 questid, Player *player)
void BattleGroundAV::UpdateScore(BattleGroundTeamId team, int32 points )
{
// note: to remove reinforcements points must be negative, for adding reinforcements points must be positive
ASSERT( team == BG_TEAM_ALLIANCE || team == BG_TEAM_HORDE);
MANGOS_ASSERT( team == BG_TEAM_ALLIANCE || team == BG_TEAM_HORDE);
m_TeamScores[team] += points; // m_TeamScores is int32 - so no problems here

if (points < 0)
Expand Down Expand Up @@ -449,7 +449,7 @@ void BattleGroundAV::ChangeMineOwner(uint8 mine, uint32 team)
// TODO implement quest 7122
// mine=0 northmine, mine=1 southmine
// TODO changing the owner should result in setting respawntime to infinite for current creatures (they should fight the new ones), spawning new mine owners creatures and changing the chest - objects so that the current owning team can use them
ASSERT(mine == BG_AV_NORTH_MINE || mine == BG_AV_SOUTH_MINE);
MANGOS_ASSERT(mine == BG_AV_NORTH_MINE || mine == BG_AV_SOUTH_MINE);
if (m_Mine_Owner[mine] == int8(team))
return;

Expand Down Expand Up @@ -533,7 +533,7 @@ void BattleGroundAV::EventPlayerClickedOnFlag(Player *source, GameObject* target

void BattleGroundAV::EventPlayerDefendsPoint(Player* player, BG_AV_Nodes node)
{
ASSERT(GetStatus() == STATUS_IN_PROGRESS);
MANGOS_ASSERT(GetStatus() == STATUS_IN_PROGRESS);

uint32 team = GetTeamIndexByTeamId(player->GetTeam());

Expand All @@ -543,7 +543,7 @@ void BattleGroundAV::EventPlayerDefendsPoint(Player* player, BG_AV_Nodes node)
{
// until snowfall doesn't belong to anyone it is better handled in assault - code (best would be to have a special function
// for neutral nodes.. but doing this just for snowfall will be a bit to much i think
ASSERT(node == BG_AV_NODES_SNOWFALL_GRAVE); // currently the only neutral grave
MANGOS_ASSERT(node == BG_AV_NODES_SNOWFALL_GRAVE); // currently the only neutral grave
EventPlayerAssaultsPoint(player, node);
return;
}
Expand Down Expand Up @@ -659,9 +659,9 @@ void BattleGroundAV::UpdateNodeWorldState(BG_AV_Nodes node)

void BattleGroundAV::SendMineWorldStates(uint32 mine)
{
ASSERT(mine == BG_AV_NORTH_MINE || mine == BG_AV_SOUTH_MINE);
ASSERT(m_Mine_PrevOwner[mine] == BG_TEAM_ALLIANCE || m_Mine_PrevOwner[mine] == BG_TEAM_HORDE || m_Mine_PrevOwner[mine] == BG_AV_NEUTRAL_TEAM);
ASSERT(m_Mine_Owner[mine] == BG_TEAM_ALLIANCE || m_Mine_Owner[mine] == BG_TEAM_HORDE || m_Mine_Owner[mine] == BG_AV_NEUTRAL_TEAM);
MANGOS_ASSERT(mine == BG_AV_NORTH_MINE || mine == BG_AV_SOUTH_MINE);
MANGOS_ASSERT(m_Mine_PrevOwner[mine] == BG_TEAM_ALLIANCE || m_Mine_PrevOwner[mine] == BG_TEAM_HORDE || m_Mine_PrevOwner[mine] == BG_AV_NEUTRAL_TEAM);
MANGOS_ASSERT(m_Mine_Owner[mine] == BG_TEAM_ALLIANCE || m_Mine_Owner[mine] == BG_TEAM_HORDE || m_Mine_Owner[mine] == BG_AV_NEUTRAL_TEAM);

UpdateWorldState(BG_AV_MineWorldStates[mine][m_Mine_Owner[mine]], 1);
if (m_Mine_Owner[mine] != m_Mine_PrevOwner[mine])
Expand Down Expand Up @@ -725,11 +725,11 @@ uint32 BattleGroundAV::GetNodeName(BG_AV_Nodes node)

void BattleGroundAV::AssaultNode(BG_AV_Nodes node, uint32 team)
{
ASSERT(team < 3); // alliance:0, horde:1, neutral:2
ASSERT(m_Nodes[node].TotalOwner != team);
ASSERT(m_Nodes[node].Owner != team);
MANGOS_ASSERT(team < 3); // alliance:0, horde:1, neutral:2
MANGOS_ASSERT(m_Nodes[node].TotalOwner != team);
MANGOS_ASSERT(m_Nodes[node].Owner != team);
// only assault an assaulted node if no totalowner exists:
ASSERT(m_Nodes[node].State != POINT_ASSAULTED || m_Nodes[node].TotalOwner == BG_AV_NEUTRAL_TEAM);
MANGOS_ASSERT(m_Nodes[node].State != POINT_ASSAULTED || m_Nodes[node].TotalOwner == BG_AV_NEUTRAL_TEAM);
// the timer gets another time, if the previous owner was 0 == Neutral
m_Nodes[node].Timer = (m_Nodes[node].PrevOwner != BG_AV_NEUTRAL_TEAM) ? BG_AV_CAPTIME : BG_AV_SNOWFALL_FIRSTCAP;
m_Nodes[node].PrevOwner = m_Nodes[node].Owner;
Expand All @@ -740,7 +740,7 @@ void BattleGroundAV::AssaultNode(BG_AV_Nodes node, uint32 team)

void BattleGroundAV::DestroyNode(BG_AV_Nodes node)
{
ASSERT(m_Nodes[node].State == POINT_ASSAULTED);
MANGOS_ASSERT(m_Nodes[node].State == POINT_ASSAULTED);

m_Nodes[node].TotalOwner = m_Nodes[node].Owner;
m_Nodes[node].PrevOwner = m_Nodes[node].Owner;
Expand All @@ -751,7 +751,7 @@ void BattleGroundAV::DestroyNode(BG_AV_Nodes node)

void BattleGroundAV::InitNode(BG_AV_Nodes node, uint32 team, bool tower)
{
ASSERT(team < 3); // alliance:0, horde:1, neutral:2
MANGOS_ASSERT(team < 3); // alliance:0, horde:1, neutral:2
m_Nodes[node].TotalOwner = team;
m_Nodes[node].Owner = team;
m_Nodes[node].PrevOwner = team;
Expand All @@ -767,10 +767,10 @@ void BattleGroundAV::InitNode(BG_AV_Nodes node, uint32 team, bool tower)

void BattleGroundAV::DefendNode(BG_AV_Nodes node, uint32 team)
{
ASSERT(team < 3); // alliance:0, horde:1, neutral:2
ASSERT(m_Nodes[node].TotalOwner == team);
ASSERT(m_Nodes[node].Owner != team);
ASSERT(m_Nodes[node].State != POINT_CONTROLLED);
MANGOS_ASSERT(team < 3); // alliance:0, horde:1, neutral:2
MANGOS_ASSERT(m_Nodes[node].TotalOwner == team);
MANGOS_ASSERT(m_Nodes[node].Owner != team);
MANGOS_ASSERT(m_Nodes[node].State != POINT_CONTROLLED);
m_Nodes[node].PrevOwner = m_Nodes[node].Owner;
m_Nodes[node].Owner = team;
m_Nodes[node].PrevState = m_Nodes[node].State;
Expand Down
3 changes: 2 additions & 1 deletion src/game/BattleGroundAV.h
Expand Up @@ -19,7 +19,8 @@
#ifndef __BATTLEGROUNDAV_H
#define __BATTLEGROUNDAV_H

class BattleGround;
#include "Common.h"
#include "BattleGround.h"

#define BG_AV_MAX_NODE_DISTANCE 25 // distance in which players are still counted in range of a banner (for alliance towers this is calculated from the center of the tower)

Expand Down
24 changes: 21 additions & 3 deletions src/game/Camera.cpp
@@ -1,3 +1,21 @@
/*
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "Camera.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
Expand All @@ -13,7 +31,7 @@ Camera::Camera(Player* pl) : m_owner(*pl), m_source(pl)
Camera::~Camera()
{
// view of camera should be already reseted to owner (RemoveFromWorld -> Event_RemovedFromWorld -> ResetView)
ASSERT(m_source == &m_owner);
MANGOS_ASSERT(m_source == &m_owner);

// for symmetry with constructor and way to make viewpoint's list empty
m_source->GetViewPoint().Detach(this);
Expand All @@ -37,7 +55,7 @@ void Camera::UpdateForCurrentViewPoint()

void Camera::SetView(WorldObject *obj)
{
ASSERT(obj);
MANGOS_ASSERT(obj);

if (m_source == obj)
return;
Expand Down Expand Up @@ -83,7 +101,7 @@ void Camera::ResetView()
void Camera::Event_AddedToWorld()
{
GridType* grid = m_source->GetViewPoint().m_grid;
ASSERT(grid);
MANGOS_ASSERT(grid);
grid->AddWorldObject(this);

UpdateVisibilityForOwner();
Expand Down
18 changes: 18 additions & 0 deletions src/game/Camera.h
@@ -1,7 +1,25 @@
/*
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef MANGOSSERVER_CAMERA_H
#define MANGOSSERVER_CAMERA_H

#include "Common.h"
#include "GridDefines.h"

class ViewPoint;
Expand Down
3 changes: 2 additions & 1 deletion src/game/CellImpl.h
Expand Up @@ -19,6 +19,7 @@
#ifndef MANGOS_CELLIMPL_H
#define MANGOS_CELLIMPL_H

#include "Common.h"
#include "Cell.h"
#include "Map.h"
#include <cmath>
Expand Down Expand Up @@ -108,7 +109,7 @@ Cell::Visit(const CellPair &standing_cell, TypeContainerVisitor<T, CONTAINER> &v
}
default:
{
ASSERT( false );
MANGOS_ASSERT( false );
break;
}
}
Expand Down

2 comments on commit 383cbc7

@Lynx3d
Copy link
Contributor

@Lynx3d Lynx3d commented on 383cbc7 Sep 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you will never understand how assert() actually works...

@alexrp
Copy link

@alexrp alexrp commented on 383cbc7 Sep 2, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the hell would you make assert do nothing?

That's just stupid.

Please sign in to comment.