Skip to content

Commit

Permalink
Add member initialization to all pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Jan 25, 2024
1 parent 04f9903 commit 17a10f1
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/lib/game/data/map/mapfieldview.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class cMapFieldView
private:
const cMapField& mapField;
const sTerrain& terrain;
const cPlayer* player; // may be null
const cPlayer* player = nullptr; // may be null
};

#endif
7 changes: 2 additions & 5 deletions src/lib/game/logic/pathcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,9 @@ void cPathCalculator::expandNodes (sPathNode* ParentNode)
// when we have a group of units, the units will not block each other
if (group)
{
const auto& field = Map->getField (currentPosition);
// get the blocking unit
cVehicle* blockingUnit;
if (Vehicle->getStaticUnitData().factorAir > 0)
blockingUnit = Map->getField (currentPosition).getPlane();
else
blockingUnit = Map->getField (currentPosition).getVehicle();
cVehicle* blockingUnit = (Vehicle->getStaticUnitData().factorAir > 0) ? field.getPlane() : field.getVehicle();
// check whether the blocking unit is the group
bool isInGroup = ranges::contains (*group, blockingUnit);
if (!isInGroup) continue;
Expand Down
25 changes: 14 additions & 11 deletions src/lib/game/logic/pathcalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ struct sPathNode
/* x and y coords */
cPosition position;
/* the different cost types */
int costF, costG, costH;
int costF = 0;
int costG = 0;
int costH = 0;
/* previous node of this one in the hole path */
sPathNode* prev;
sPathNode* prev = nullptr;
};

enum class ePathDestinationType
Expand All @@ -54,9 +56,9 @@ class cPathDestHandler
{
ePathDestinationType type;

const cVehicle* srcVehicle;
const cVehicle* srcVehicle = nullptr;

const cUnit* destUnit;
const cUnit* destUnit = nullptr;
cPosition destination;

public:
Expand Down Expand Up @@ -90,23 +92,24 @@ class cPathCalculator
static int calcNextCost (const cPosition& source, const cPosition& destination, const cVehicle*, const T* map);

/* the map on which the path will be calculated */
const cMapView* Map;
const cMapView* Map = nullptr;
/* the moving vehicle */
const cVehicle* Vehicle;
const cVehicle* Vehicle = nullptr;
/* if more then one vehicle is moving in a group this is the list of all moving vehicles */
const std::vector<cVehicle*>* group;
const std::vector<cVehicle*>* group = nullptr;
/* source and destination coords */
cPosition source;
bool bPlane, bShip;
bool bPlane = false;
bool bShip = false;
std::unique_ptr<cPathDestHandler> destHandler;

private:
/* memoryblocks for the nodes */
std::vector<std::vector<sPathNode>> MemBlocks;
/* number of blocks */
int blocknum;
int blocknum = 0;
/* restsize of the last block */
int blocksize;
int blocksize = 0;

/* heaplist where all nodes are sorted by there costF value */
std::vector<sPathNode*> nodesHeap;
Expand All @@ -115,7 +118,7 @@ class cPathCalculator
/* closed nodes map */
std::vector<sPathNode*> closedList;
/* number of nodes saved on the heaplist; equal to number of nodes in the openlist */
int heapCount;
int heapCount = 0;
/**
* expands the nodes around the overgiven one
*@author alzi alias DoctorDeath
Expand Down
2 changes: 1 addition & 1 deletion src/lib/input/keyboard/keycombination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
static const struct
{
SDL_Keycode key;
const char* name;
const char* name = nullptr;
} keyNames[] =
{

Expand Down
4 changes: 2 additions & 2 deletions src/lib/mapdownloader/mapdownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ bool MapDownload::isMapOriginal (const std::filesystem::path& mapFilename, int32

const struct
{
const char* filename;
int32_t checksum;
const char* filename = nullptr;
int32_t checksum = 0;
} maps[] =
{
{"bottleneck.wrl", 344087468},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/video/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,12 @@ static void drawStetchedLine (Type* srcPixelData, int srcWidth, Type* destPixelD
SDL_Surface* scaleSurface (SDL_Surface* scr, SDL_Surface* dest, int width, int height)
{
if (width <= 0 || height <= 0 || !scr) return nullptr;
SDL_Surface* surface;

// can not enlage an existing surface
if (width > scr->w && dest) width = scr->w;
if (height > scr->h && dest) height = scr->h;

SDL_Surface* surface = nullptr;
// generate new surface if necessary
if (dest == nullptr)
surface = SDL_CreateRGBSurface (0, width, height, scr->format->BitsPerPixel, scr->format->Rmask, scr->format->Gmask, scr->format->Bmask, scr->format->Amask);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utility/string/roman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ std::string to_roman (unsigned int value)
{
struct romandata_t
{
unsigned int value;
char const* numeral;
unsigned int value = 0;
char const* numeral = nullptr;
};
const struct romandata_t romandata[] =
{
Expand Down
16 changes: 7 additions & 9 deletions src/ui/graphical/game/widgets/chatbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,19 @@ class cChatBox : public cWidget

cSignal<void (const std::string&)> commandEntered;

private:
void sendCommand();
void createBackground();

private:
cSignalConnectionManager signalConnectionManager;

UniqueSurface nonFocusBackground;
UniqueSurface focusBackground;

cLineEdit* chatLineEdit;

cListView<ChatListItemType>* chatList;

cListView<PlayerListItemType>* playersList;

void sendCommand();

void createBackground();
cLineEdit* chatLineEdit = nullptr;
cListView<ChatListItemType>* chatList = nullptr;
cListView<PlayerListItemType>* playersList = nullptr;
};

//------------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions src/ui/graphical/game/widgets/debugoutputwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ void cDebugOutputWidget::trace()
if (!gameMap->getArea().withinOrTouches (mouse->getPosition())) return;

const auto mapPosition = gameMap->getMapTilePosition (mouse->getPosition());

const cMapField* field;
const cMapField* field = nullptr;

if (debugTraceServer && server)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class cMenuControllerMultiplayerHotSeat : public cRunnable, public std::enable_s

cApplication& application;

cWindowPlayerSelection* windowPlayerSelection;
cWindow* firstWindow;
cWindowPlayerSelection* windowPlayerSelection = nullptr;
cWindow* firstWindow = nullptr;

std::shared_ptr<cLocalHotSeatGameNew> game;

Expand Down
6 changes: 3 additions & 3 deletions src/ui/graphical/menu/widgets/combobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class cComboBox : public cWidget
UniqueSurface listViewBackground;
UniqueSurface lineEditBackground;

cListView<cTextListViewItem>* listView;
cCheckBox* downButton;
cLineEdit* lineEdit;
cListView<cTextListViewItem>* listView = nullptr;
cCheckBox* downButton = nullptr;
cLineEdit* lineEdit = nullptr;

size_t maxVisibleItems;

Expand Down
9 changes: 3 additions & 6 deletions src/ui/graphical/menu/widgets/scrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ class cScrollBar : public cWidget
private:
cSignalConnectionManager signalConnectionManager;

cPushButton* forwardButton;
cPushButton* backButton;
cPushButton* forwardButton = nullptr;
cPushButton* backButton = nullptr;

cSlider* slider;
cSlider* slider = nullptr;

eScrollBarStyle style;

eOrientationType orientation;

size_t range;
size_t offset;
};

#endif // ui_graphical_menu_widgets_scrollbarH
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class cChatBoxLandingPlayerListViewItem : public cAbstractListViewItem
cSignalConnectionManager signalConnectionManager;
cSignalConnectionManager managerSignalConnectionManager;

cLabel* nameLabel;
cImage* colorImage;
cImage* readyImage;
cLabel* nameLabel = nullptr;
cImage* colorImage = nullptr;
cImage* readyImage = nullptr;

const cPlayerLandingStatus& playerLandingStatus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class cLobbyChatBoxListViewItem : public cAbstractListViewItem
void handleResized (const cPosition& oldSize) override;

private:
cLabel* messageLabel;
cLabel* prefixLabel;
cLabel* messageLabel = nullptr;
cLabel* prefixLabel = nullptr;
};

#endif // ui_graphical_menu_widgets_special_lobbychatboxlistviewitemH
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class cLobbyPlayerListViewItem : public cAbstractListViewItem
private:
cSignalConnectionManager signalConnectionManager;

cLabel* nameLabel;
cImage* colorImage;
cImage* readyImage;
cLabel* nameLabel = nullptr;
cImage* colorImage = nullptr;
cImage* readyImage = nullptr;

std::shared_ptr<cPlayerBasicData> player;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/graphical/menu/widgets/special/textlistviewitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class cTextListViewItem : public cAbstractListViewItem
void handleResized (const cPosition& oldSize) override;

protected:
cLabel* label;
cLabel* label = nullptr;
};

#endif // ui_graphical_menu_widgets_special_textlistviewitemH
4 changes: 2 additions & 2 deletions src/ui/graphical/menu/widgets/special/unitlistviewitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class cUnitListViewItem : public cAbstractListViewItem
const sID& getUnitId() const { return unitId; }

protected:
cImage* unitImage;
cLabel* nameLabel;
cImage* unitImage = nullptr;
cLabel* nameLabel = nullptr;

private:
sID unitId;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/graphical/menu/widgets/special/unitlistviewitembuy.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class cUnitListViewItemBuy : public cUnitListViewItem
void showPrice();

private:
int cost;
cLabel* costLabel;
int cost = 0;
cLabel* costLabel = nullptr;
};

#endif // ui_graphical_menu_widgets_special_unitlistviewitembuyH
4 changes: 2 additions & 2 deletions src/ui/graphical/menu/widgets/special/unitlistviewitemcargo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class cUnitListViewItemCargo : public cUnitListViewItem
void updateCargoLabel();

private:
cLabel* cargoLabel;
cLabel* cargoLabel = nullptr;
int cargo = 0;
int cargoMax;
int cargoMax = 0;
};

#endif // ui_graphical_menu_widgets_special_unitlistviewitemcargoH
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class cWindowAdvancedHangar : public cWindowHangar

// TODO: the following widgets should be private instead.
// They are protect at the moment because some inheriting windows need to move/resize the widgets.
cListView<SelectedUnitItemType>* selectedUnitList;
cPushButton* selectedListUpButton;
cPushButton* selectedListDownButton;
cListView<SelectedUnitItemType>* selectedUnitList = nullptr;
cPushButton* selectedListUpButton = nullptr;
cPushButton* selectedListDownButton = nullptr;

cSignal<void (SelectedUnitItemType*)> selectedUnitSelectionChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class cWindowBuildBuildings : public cWindowHangar

const cVehicle& vehicle;

cBuildSpeedHandlerWidget* speedHandler;
cBuildSpeedHandlerWidget* speedHandler = nullptr;
cLabel* titleLabel = nullptr;
cPushButton* pathButton = nullptr;

Expand Down
18 changes: 9 additions & 9 deletions src/ui/graphical/menu/windows/windowhangar/windowhangar.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class cWindowHangar : public cWindow

// TODO: the following widgets should be private instead.
// They are protect at the moment because some inheriting windows need to move/resize the widgets.
cListView<cUnitListViewItemBuy>* selectionUnitList;
cListView<cUnitListViewItemBuy>* selectionUnitList = nullptr;

cPushButton* okButton;
cPushButton* backButton;
cPushButton* selectionListUpButton;
cPushButton* selectionListDownButton;
cPushButton* okButton = nullptr;
cPushButton* backButton = nullptr;
cPushButton* selectionListUpButton = nullptr;
cPushButton* selectionListDownButton = nullptr;

cSignal<void (const cUnitListViewItemBuy&)> selectionUnitClickedSecondTime;

Expand All @@ -87,12 +87,12 @@ class cWindowHangar : public cWindow
std::unique_ptr<cPlayer> temporaryPlayer;
const cPlayer& player;

cImage* infoImage;
cLabel* infoLabel;
cImage* infoImage = nullptr;
cLabel* infoLabel = nullptr;

cUnitDetails* unitDetails;
cUnitDetails* unitDetails = nullptr;

cCheckBox* infoTextCheckBox;
cCheckBox* infoTextCheckBox = nullptr;

void initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void cWindowLandingUnitSelection::setActiveUnit (const sID& unitId)
{
cWindowAdvancedHangar<cUnitListViewItemCargo>::setActiveUnit (unitId);

cUnitUpgrade* unitUpgrade;
cUnitUpgrade* unitUpgrade = nullptr;
auto iter = unitUpgrades.find (unitId);
if (iter == unitUpgrades.end())
{
Expand Down
4 changes: 2 additions & 2 deletions src/ui/graphical/menu/windows/windowreports/windowreports.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ class cWindowReports : public cWindow
cPushButton* downButton = nullptr;

cFrame* unitsFrame = nullptr;
cListView<cReportUnitListViewItem>* unitsList;
cListView<cReportUnitListViewItem>* unitsList = nullptr;

cFrame* disadvantagesFrame = nullptr;
cListView<cReportDisadvantagesListViewItem>* disadvantagesList = nullptr;

cFrame* scoreFrame = nullptr;
cPlot<int, int>* scorePlot;
cPlot<int, int>* scorePlot = nullptr;

cFrame* reportsFrame = nullptr;
cListView<cReportMessageListViewItem>* reportsList = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void cWindowStorage::updateUnitsWidgets()
{
unitNames[positionIndex]->setText ("");

SDL_Surface* srcSurface;
SDL_Surface* srcSurface = nullptr;
if (canStoreShips)
srcSurface = GraphicsData.gfx_edock.get();
else if (canStorePlanes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void cWindowUpgrades::setActiveUnit (const sID& unitId)
{
cWindowHangar::setActiveUnit (unitId);

cUnitUpgrade* unitUpgrade;
cUnitUpgrade* unitUpgrade = nullptr;
auto iter = unitUpgrades.find (unitId);
if (iter == unitUpgrades.end())
{
Expand Down
Loading

0 comments on commit 17a10f1

Please sign in to comment.