Skip to content

Commit

Permalink
Merge pull request #537 from Wargus/clean-up
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
Jarod42 authored Oct 11, 2023
2 parents e5d77df + d6e2d6d commit c1d1e0b
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/action/action_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void COrder_Attack::AttackTarget(CUnit &unit)
**
** @param unit Unit, for that the attack is handled.
*/
/* virtual */ void COrder_Attack::Execute(CUnit &unit)
void COrder_Attack::Execute(CUnit &unit) /* override */
{
Assert(this->HasGoal() || Map.Info.IsPointOnMap(this->goalPos));

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "actions.h"
#include "unit.h"

/* virtual */ void CAnimation_Attack::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Attack::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
unit.CurrentOrder()->OnAnimationAttack(unit);
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_die.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <stdio.h>

/* virtual */ void CAnimation_Die::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Die::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
if (unit.Anim.Unbreakable) {
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include "unit.h"

/* virtual */ void CAnimation_Goto::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Goto::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_ifvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static bool binOpXor(int lhs, int rhs) { return (bool)(lhs ^ rhs); }
static bool binOpNot(int lhs, int rhs = 0) { return (bool)(!lhs); }
static bool returnFalse(int, int) { return false; }

/* virtual */ void CAnimation_IfVar::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_IfVar::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include "unit.h"

/* virtual */ void CAnimation_Label::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Label::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
}
Expand Down
6 changes: 3 additions & 3 deletions src/animation/animation_luacallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <iterator>
#include <sstream>

/* virtual */ void CAnimation_LuaCallback::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_LuaCallback::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
Assert(cb);
Expand All @@ -59,13 +59,13 @@
/*
** s = "cbName cbArg1 [cbArgN ...]"
*/
/* virtual */ void CAnimation_LuaCallback::Init(std::string_view s, lua_State *l)
void CAnimation_LuaCallback::Init(std::string_view s, lua_State *l) /* override */
{
const auto space_pos = s.find(' ');
this->cbName = s.substr(0, space_pos);

lua_getglobal(l, cbName.c_str());
cb = new LuaCallback(l, -1);
cb = std::make_unique<LuaCallback>(l, -1);
lua_pop(l, 1);

if (space_pos == std::string_view::npos) {
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include "unit.h"

/* virtual */ void CAnimation_Move::Action(CUnit &unit, int &move, int /*scale*/) const
void CAnimation_Move::Action(CUnit &unit, int &move, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
Assert(!move);
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_randomgoto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <sstream>

/* virtual */ void CAnimation_RandomGoto::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_RandomGoto::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
4 changes: 3 additions & 1 deletion src/animation/animation_randomrotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include "animation/animation_rotate.h"
#include "unit.h"

/* virtual */ void CAnimation_RandomRotate::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_RandomRotate::Action(CUnit &unit,
int & /*move*/,
int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_randomsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <iterator>
#include <sstream>

/* virtual */ void CAnimation_RandomSound::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_RandomSound::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_randomwait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <sstream>

/* virtual */ void CAnimation_RandomWait::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_RandomWait::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_rotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void UnitRotate(CUnit &unit, int rotate)
UnitUpdateHeading(unit);
}

/* virtual */ void CAnimation_Rotate::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Rotate::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
5 changes: 3 additions & 2 deletions src/animation/animation_setplayervar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ static void SetPlayerData(const int player, std::string_view prop, std::string_v
}
}


/* virtual */ void CAnimation_SetPlayerVar::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_SetPlayerVar::Action(CUnit &unit,
int & /*move*/,
int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_setvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <stdio.h>
#include <sstream>

/* virtual */ void CAnimation_SetVar::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_SetVar::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);

Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "sound.h"
#include "unit.h"

/* virtual */ void CAnimation_Sound::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Sound::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
if (unit.IsVisible(*ThisPlayer) || ReplayRevealMap) {
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_unbreakable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include "unit.h"

/* virtual */ void CAnimation_Unbreakable::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Unbreakable::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
Assert(unit.Anim.Anim == this);
Assert(unit.Anim.Unbreakable ^ this->state);
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include "unit.h"

/* virtual */ void CAnimation_Wait::Action(CUnit &unit, int &/*move*/, int scale) const
void CAnimation_Wait::Action(CUnit &unit, int & /*move*/, int scale) const /* override */
{
Assert(unit.Anim.Anim == this);
unit.Anim.Wait = ParseAnimInt(unit, this->wait) << scale >> 8;
Expand Down
2 changes: 1 addition & 1 deletion src/animation/animation_wiggle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#include <sstream>

/* virtual */ void CAnimation_Wiggle::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
void CAnimation_Wiggle::Action(CUnit &unit, int & /*move*/, int /*scale*/) const /* override */
{
int x = ParseAnimInt(unit, this->x);
int y = ParseAnimInt(unit, this->y);
Expand Down
4 changes: 2 additions & 2 deletions src/include/animation/animation_luacallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
class CAnimation_LuaCallback : public CAnimation
{
public:
~CAnimation_LuaCallback() { delete cb; }
~CAnimation_LuaCallback() = default;

void Action(CUnit &unit, int &move, int scale) const override;
void Init(std::string_view s, lua_State *l) override;

private:
LuaCallback *cb = nullptr;
std::unique_ptr<LuaCallback> cb;
std::string cbName;
std::vector<std::string> cbArgs;
};
Expand Down
71 changes: 48 additions & 23 deletions src/include/ui/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ class CPopupContentTypeButtonInfo : public CPopupContentType
{
public:
CPopupContentTypeButtonInfo() = default;
virtual ~CPopupContentTypeButtonInfo() = default;
~CPopupContentTypeButtonInfo() override = default;

virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
void Draw(int x,
int y,
const CPopup &popup,
const unsigned int popupWidth,
const ButtonAction &button,
int *Costs) const override;

virtual int GetWidth(const ButtonAction &button, int *Costs) const;
virtual int GetHeight(const ButtonAction &button, int *Costs) const;
int GetWidth(const ButtonAction &button, int *Costs) const override;
int GetHeight(const ButtonAction &button, int *Costs) const override;

virtual void Parse(lua_State *l);

Expand All @@ -130,14 +135,19 @@ class CPopupContentTypeText : public CPopupContentType
{
public:
CPopupContentTypeText() = default;
virtual ~CPopupContentTypeText() = default;
~CPopupContentTypeText() override = default;

virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
void Draw(int x,
int y,
const CPopup &popup,
const unsigned int popupWidth,
const ButtonAction &button,
int *Costs) const override;

virtual int GetWidth(const ButtonAction &button, int *Costs) const;
virtual int GetHeight(const ButtonAction &button, int *Costs) const;
int GetWidth(const ButtonAction &button, int *Costs) const override;
int GetHeight(const ButtonAction &button, int *Costs) const override;

virtual void Parse(lua_State *l);
void Parse(lua_State *l) override;

private:
std::string Text; /// Text to display
Expand All @@ -149,14 +159,19 @@ class CPopupContentTypeCosts : public CPopupContentType
{
public:
CPopupContentTypeCosts() = default;
virtual ~CPopupContentTypeCosts() = default;
~CPopupContentTypeCosts() override = default;

virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
void Draw(int x,
int y,
const CPopup &popup,
const unsigned int popupWidth,
const ButtonAction &button,
int *Costs) const override;

virtual int GetWidth(const ButtonAction &button, int *Costs) const;
virtual int GetHeight(const ButtonAction &button, int *Costs) const;
int GetWidth(const ButtonAction &button, int *Costs) const override;
int GetHeight(const ButtonAction &button, int *Costs) const override;

virtual void Parse(lua_State *l);
void Parse(lua_State *l) override;

private:
CFont *Font = nullptr; /// Font to use.
Expand All @@ -167,14 +182,19 @@ class CPopupContentTypeLine : public CPopupContentType
{
public:
CPopupContentTypeLine() = default;
virtual ~CPopupContentTypeLine() = default;
~CPopupContentTypeLine() override = default;

virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
void Draw(int x,
int y,
const CPopup &popup,
const unsigned int popupWidth,
const ButtonAction &button,
int *Costs) const override;

virtual int GetWidth(const ButtonAction &button, int *Costs) const;
virtual int GetHeight(const ButtonAction &button, int *Costs) const;
int GetWidth(const ButtonAction &button, int *Costs) const override;
int GetHeight(const ButtonAction &button, int *Costs) const override;

virtual void Parse(lua_State *l);
void Parse(lua_State *l) override;

private:
IntColor Color = ColorWhite; /// Color used for line.
Expand All @@ -187,12 +207,17 @@ class CPopupContentTypeVariable : public CPopupContentType
public:
CPopupContentTypeVariable() = default;

virtual void Draw(int x, int y, const CPopup &popup, const unsigned int popupWidth, const ButtonAction &button, int *Costs) const;
void Draw(int x,
int y,
const CPopup &popup,
const unsigned int popupWidth,
const ButtonAction &button,
int *Costs) const override;

virtual int GetWidth(const ButtonAction &button, int *Costs) const;
virtual int GetHeight(const ButtonAction &button, int *Costs) const;
int GetWidth(const ButtonAction &button, int *Costs) const override;
int GetHeight(const ButtonAction &button, int *Costs) const override;

virtual void Parse(lua_State *l);
void Parse(lua_State *l) override;

private:
std::unique_ptr<IStringDesc> Text; /// Text to display.
Expand Down
9 changes: 4 additions & 5 deletions src/sound/sound_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static bool External_Volume(int volume, int oldVolume) {

/// Channels for sound effects and unit speech
struct SoundChannel {
Origin *Unit = nullptr; /// pointer to unit, who plays the sound, if any
std::unique_ptr<Origin> Unit; /// pointer to unit, who plays the sound, if any
void (*FinishedCallback)(int channel) = nullptr; /// Callback for when a sample finishes playing
};

Expand Down Expand Up @@ -288,7 +288,6 @@ static void ChannelFinished(int channel)
event.user.data1 = (void*) Channels[channel].FinishedCallback;
SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
}
delete Channels[channel].Unit;
Channels[channel].Unit = nullptr;
}

Expand Down Expand Up @@ -496,10 +495,10 @@ static int PlaySample(Mix_Chunk *sample, Origin *origin, void (*callback)(int ch
if (channel >= 0 && channel < MaxChannels) {
Channels[channel].FinishedCallback = callback;
if (origin && origin->Base) {
Origin *source = new Origin;
auto source = std::make_unique<Origin>();
source->Base = origin->Base;
source->Id = origin->Id;
Channels[channel].Unit = source;
Channels[channel].Unit = std::move(source);
}
}
}
Expand Down Expand Up @@ -675,7 +674,7 @@ bool SoundEnabled()
**
** @return false if failure, true if everything ok.
*/
static int InitSdlSound()
static bool InitSdlSound()
{
fs::path timidityCfg(StratagusLibPath);
timidityCfg = timidityCfg / "timidity" / "timidity.cfg";
Expand Down
Loading

0 comments on commit c1d1e0b

Please sign in to comment.