Improve code quality

- Overriding methods are clearly indicated with `override` keywords
- Remove redundant `virtual` keywords from destructors of subclasses
- Introduce `SPUnsupported()`, replacing most uses of
  `SPNotImplemented()`, which now serves as a dynamic "TODO" marker
This commit is contained in:
yvt 2018-10-13 14:43:17 +09:00
parent 176b217cd4
commit cfb972f944
35 changed files with 252 additions and 231 deletions

View File

@ -39,7 +39,7 @@ namespace spades {
public:
ALDevice();
virtual ~ALDevice();
~ALDevice();
static bool TryLoad();

View File

@ -36,17 +36,17 @@ namespace spades {
public:
NullDevice();
virtual client::IAudioChunk *RegisterSound(const char *name);
client::IAudioChunk *RegisterSound(const char *name) override;
virtual void SetGameMap(client::GameMap *);
void SetGameMap(client::GameMap *) override;
virtual void Play(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &);
virtual void PlayLocal(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &);
virtual void PlayLocal(client::IAudioChunk *, const client::AudioParam &);
void Play(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &) override;
void PlayLocal(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &) override;
void PlayLocal(client::IAudioChunk *, const client::AudioParam &) override;
virtual void Respatialize(const Vector3 &eye, const Vector3 &front, const Vector3 &up);
void Respatialize(const Vector3 &eye, const Vector3 &front, const Vector3 &up) override;
};
}
}

View File

@ -267,7 +267,7 @@ namespace spades {
std::shared_ptr<YsrBuffer> buffer;
protected:
virtual ~YsrAudioChunk() {}
~YsrAudioChunk() {}
public:
YsrAudioChunk(std::shared_ptr<YsrDriver> driver, IAudioStream *stream) {

View File

@ -53,24 +53,24 @@ namespace spades {
void Spatialize(const void *, void *);
protected:
virtual ~YsrDevice();
~YsrDevice();
public:
YsrDevice();
static bool TryLoadYsr();
virtual client::IAudioChunk *RegisterSound(const char *name);
client::IAudioChunk *RegisterSound(const char *name) override;
virtual void SetGameMap(client::GameMap *);
void SetGameMap(client::GameMap *) override;
virtual void Play(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &);
virtual void PlayLocal(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &);
virtual void PlayLocal(client::IAudioChunk *, const client::AudioParam &);
void Play(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &) override;
void PlayLocal(client::IAudioChunk *, const Vector3 &origin,
const client::AudioParam &) override;
void PlayLocal(client::IAudioChunk *, const client::AudioParam &) override;
virtual void Respatialize(const Vector3 &eye, const Vector3 &front, const Vector3 &up);
void Respatialize(const Vector3 &eye, const Vector3 &front, const Vector3 &up) override;
};
}
}

View File

@ -391,22 +391,22 @@ namespace spades {
void NetLog(const char *format, ...);
protected:
virtual ~Client();
~Client();
public:
Client(IRenderer *, IAudioDevice *, const ServerAddress &host, FontManager *);
virtual void RunFrame(float dt);
void RunFrame(float dt) override;
virtual void Closing();
virtual void MouseEvent(float x, float y);
virtual void WheelEvent(float x, float y);
virtual void KeyEvent(const std::string &, bool down);
virtual void TextInputEvent(const std::string &);
virtual void TextEditingEvent(const std::string &, int start, int len);
virtual bool AcceptsTextInput();
virtual AABB2 GetTextInputRect();
virtual bool NeedsAbsoluteMouseCoordinate();
void Closing() override;
void MouseEvent(float x, float y) override;
void WheelEvent(float x, float y) override;
void KeyEvent(const std::string &, bool down) override;
void TextInputEvent(const std::string &) override;
void TextEditingEvent(const std::string &, int start, int len) override;
bool AcceptsTextInput() override;
AABB2 GetTextInputRect() override;
bool NeedsAbsoluteMouseCoordinate() override;
void SetWorld(World *);
World *GetWorld() const { return world.get(); }
@ -418,7 +418,7 @@ namespace spades {
SceneDefinition GetLastSceneDef() { return lastSceneDef; }
IAudioDevice *GetAudioDevice() { return audioDevice; }
virtual bool WantsToBeClosed();
bool WantsToBeClosed() override;
bool IsMuted();
void PlayerSentChatMessage(Player *, bool global, const std::string &);
@ -439,38 +439,38 @@ namespace spades {
void PlayerJoinedTeam(Player *);
void PlayerSpawned(Player *);
virtual void PlayerObjectSet(int);
virtual void PlayerMadeFootstep(Player *);
virtual void PlayerJumped(Player *);
virtual void PlayerLanded(Player *, bool hurt);
virtual void PlayerFiredWeapon(Player *);
virtual void PlayerDryFiredWeapon(Player *);
virtual void PlayerReloadingWeapon(Player *);
virtual void PlayerReloadedWeapon(Player *);
virtual void PlayerChangedTool(Player *);
virtual void PlayerThrownGrenade(Player *, Grenade *);
virtual void PlayerMissedSpade(Player *);
virtual void PlayerRestocked(Player *);
void PlayerObjectSet(int) override;
void PlayerMadeFootstep(Player *) override;
void PlayerJumped(Player *) override;
void PlayerLanded(Player *, bool hurt) override;
void PlayerFiredWeapon(Player *) override;
void PlayerDryFiredWeapon(Player *) override;
void PlayerReloadingWeapon(Player *) override;
void PlayerReloadedWeapon(Player *) override;
void PlayerChangedTool(Player *) override;
void PlayerThrownGrenade(Player *, Grenade *) override;
void PlayerMissedSpade(Player *) override;
void PlayerRestocked(Player *) override;
/** @deprecated use BulletHitPlayer */
virtual void PlayerHitBlockWithSpade(Player *, Vector3 hitPos, IntVector3 blockPos,
IntVector3 normal);
virtual void PlayerKilledPlayer(Player *killer, Player *victim, KillType);
void PlayerHitBlockWithSpade(Player *, Vector3 hitPos, IntVector3 blockPos,
IntVector3 normal) override;
void PlayerKilledPlayer(Player *killer, Player *victim, KillType) override;
virtual void BulletHitPlayer(Player *hurtPlayer, HitType, Vector3 hitPos, Player *by);
virtual void BulletHitBlock(Vector3, IntVector3 blockPos, IntVector3 normal);
virtual void AddBulletTracer(Player *player, Vector3 muzzlePos, Vector3 hitPos);
virtual void GrenadeExploded(Grenade *);
virtual void GrenadeBounced(Grenade *);
virtual void GrenadeDroppedIntoWater(Grenade *);
void BulletHitPlayer(Player *hurtPlayer, HitType, Vector3 hitPos, Player *by) override;
void BulletHitBlock(Vector3, IntVector3 blockPos, IntVector3 normal) override;
void AddBulletTracer(Player *player, Vector3 muzzlePos, Vector3 hitPos) override;
void GrenadeExploded(Grenade *) override;
void GrenadeBounced(Grenade *) override;
void GrenadeDroppedIntoWater(Grenade *) override;
virtual void BlocksFell(std::vector<IntVector3>);
void BlocksFell(std::vector<IntVector3>) override;
virtual void LocalPlayerPulledGrenadePin();
virtual void LocalPlayerBlockAction(IntVector3, BlockActionType type);
virtual void LocalPlayerCreatedLineBlock(IntVector3, IntVector3);
virtual void LocalPlayerHurt(HurtType type, bool sourceGiven, Vector3 source);
virtual void LocalPlayerBuildError(BuildFailureReason reason);
void LocalPlayerPulledGrenadePin() override;
void LocalPlayerBlockAction(IntVector3, BlockActionType type) override;
void LocalPlayerCreatedLineBlock(IntVector3, IntVector3) override;
void LocalPlayerHurt(HurtType type, bool sourceGiven, Vector3 source) override;
void LocalPlayerBuildError(BuildFailureReason reason) override;
};
}
}

View File

@ -220,7 +220,7 @@ namespace spades {
public:
CorpseUpdateDispatch(Client *c, float dt) : client(c), dt(dt) {}
virtual void Run() {
void Run() override {
for (auto &c : client->corpses) {
for (int i = 0; i < 4; i++)
c->Update(dt / 4.f);

View File

@ -45,8 +45,8 @@ namespace spades {
SPADES_MARK_FUNCTION();
bmp.Set(new Bitmap(512, 512), false);
}
virtual Bitmap *GetFramebuffer() { return bmp; }
virtual void Swap() {
Bitmap *GetFramebuffer() override { return bmp; }
void Swap() override {
// nothing to do here
}
};

View File

@ -67,7 +67,7 @@ namespace spades {
FindResult FindGlyph(uint32_t);
protected:
virtual ~FallbackFontRenderer();
~FallbackFontRenderer();
public:
FallbackFontRenderer(IRenderer *renderer, FallbackFontManager *manager);

View File

@ -43,8 +43,13 @@ namespace spades {
IFont(IRenderer *);
virtual Vector2 Measure(const std::string &) = 0;
/** Draws text.
* @param color Non-premultiplied alpha color value. */
/**
* Draws a specified string.
*
* @param offset Specifies the origin point of the rendered string.
* @param scale Scaling factor relative to the default size of the font.
* @param color A non-premultiplied alpha color value.
*/
virtual void Draw(const std::string &, Vector2 offset, float scale, Vector4 color) = 0;
virtual void DrawShadow(const std::string &message, const Vector2 &offset, float scale,
const Vector4 &color, const Vector4 &shadowColor);

View File

@ -27,7 +27,7 @@ namespace spades {
class RendererModelModelRegistrar : public ScriptObjectRegistrar {
public:
RendererModelModelRegistrar() : ScriptObjectRegistrar("RendererModelModel") {}
virtual void Register(ScriptManager *manager, Phase phase) {
void Register(ScriptManager *manager, Phase phase) override {
asIScriptEngine *eng = manager->GetEngine();
int r;
eng->SetDefaultNamespace("spades");

View File

@ -46,7 +46,7 @@ namespace spades {
float yMin, yMax;
protected:
virtual ~Quake3Font();
~Quake3Font();
public:
Quake3Font(IRenderer *, IImage *texture, const int *map, int glyphHeight,
@ -57,4 +57,4 @@ namespace spades {
void SetGlyphYRange(float yMin, float yMax);
};
}
}
}

View File

@ -200,14 +200,14 @@ namespace spades {
class RifleWeapon3 : public Weapon {
public:
RifleWeapon3(World *w, Player *p) : Weapon(w, p) {}
virtual std::string GetName() { return "Rifle"; }
virtual float GetDelay() { return 0.5f; }
virtual int GetClipSize() { return 10; }
virtual int GetMaxStock() { return 50; }
virtual float GetReloadTime() { return 2.5f; }
virtual bool IsReloadSlow() { return false; }
virtual WeaponType GetWeaponType() { return RIFLE_WEAPON; }
virtual int GetDamage(HitType type, float distance) {
std::string GetName() override { return "Rifle"; }
float GetDelay() override { return 0.5f; }
int GetClipSize() override { return 10; }
int GetMaxStock() override { return 50; }
float GetReloadTime() override { return 2.5f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return RIFLE_WEAPON; }
int GetDamage(HitType type, float distance) override {
switch (type) {
case HitTypeTorso: return 49;
case HitTypeHead: return 100;
@ -217,24 +217,24 @@ namespace spades {
default: SPAssert(false); return 0;
}
}
virtual Vector3 GetRecoil() {
Vector3 GetRecoil() override {
return MakeVector3(0.025f, 0.05f, 0.f); // measured
}
virtual float GetSpread() { return 0.012f; } // measured (standing, crouched)
virtual int GetPelletSize() { return 1; }
float GetSpread() override { return 0.012f; } // measured (standing, crouched)
int GetPelletSize() override { return 1; }
};
class SMGWeapon3 : public Weapon {
public:
SMGWeapon3(World *w, Player *p) : Weapon(w, p) {}
virtual std::string GetName() { return "SMG"; }
virtual float GetDelay() { return 0.11f; }
virtual int GetClipSize() { return 30; }
virtual int GetMaxStock() { return 120; }
virtual float GetReloadTime() { return 2.5f; }
virtual bool IsReloadSlow() { return false; }
virtual WeaponType GetWeaponType() { return SMG_WEAPON; }
virtual int GetDamage(HitType type, float distance) {
std::string GetName() override { return "SMG"; }
float GetDelay() override { return 0.11f; }
int GetClipSize() override { return 30; }
int GetMaxStock() override { return 120; }
float GetReloadTime() override { return 2.5f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return SMG_WEAPON; }
int GetDamage(HitType type, float distance) override {
switch (type) {
case HitTypeTorso: return 29;
case HitTypeHead: return 75;
@ -244,24 +244,24 @@ namespace spades {
default: SPAssert(false); return 0;
}
}
virtual Vector3 GetRecoil() {
Vector3 GetRecoil() override {
return MakeVector3(0.01f, 0.0125f, 0.f); // measured
}
virtual float GetSpread() { return 0.025f; } // measured (standing, crouched)
virtual int GetPelletSize() { return 1; }
float GetSpread() override { return 0.025f; } // measured (standing, crouched)
int GetPelletSize() override { return 1; }
};
class ShotgunWeapon3 : public Weapon {
public:
ShotgunWeapon3(World *w, Player *p) : Weapon(w, p) {}
virtual std::string GetName() { return "Shotgun"; }
virtual float GetDelay() { return 1.f; }
virtual int GetClipSize() { return 6; }
virtual int GetMaxStock() { return 48; }
virtual float GetReloadTime() { return 0.5f; }
virtual bool IsReloadSlow() { return true; }
virtual WeaponType GetWeaponType() { return SHOTGUN_WEAPON; }
virtual int GetDamage(HitType type, float distance) {
std::string GetName() override { return "Shotgun"; }
float GetDelay() override { return 1.f; }
int GetClipSize() override { return 6; }
int GetMaxStock() override { return 48; }
float GetReloadTime() override { return 0.5f; }
bool IsReloadSlow() override { return true; }
WeaponType GetWeaponType() override { return SHOTGUN_WEAPON; }
int GetDamage(HitType type, float distance) override {
switch (type) {
case HitTypeTorso: return 27;
case HitTypeHead: return 37;
@ -274,24 +274,24 @@ namespace spades {
default: SPAssert(false); return 0;
}
}
virtual Vector3 GetRecoil() {
Vector3 GetRecoil() override {
return MakeVector3(0.05f, 0.1f, 0.f); // measured
}
virtual float GetSpread() { return 0.024f; }
virtual int GetPelletSize() { return 8; }
float GetSpread() override { return 0.024f; }
int GetPelletSize() override { return 8; }
};
class RifleWeapon4 : public Weapon {
public:
RifleWeapon4(World *w, Player *p) : Weapon(w, p) {}
virtual std::string GetName() { return "Rifle"; }
virtual float GetDelay() { return 0.6f; }
virtual int GetClipSize() { return 8; }
virtual int GetMaxStock() { return 48; }
virtual float GetReloadTime() { return 2.5f; }
virtual bool IsReloadSlow() { return false; }
virtual WeaponType GetWeaponType() { return RIFLE_WEAPON; }
virtual int GetDamage(HitType type, float distance) {
std::string GetName() override { return "Rifle"; }
float GetDelay() override { return 0.6f; }
int GetClipSize() override { return 8; }
int GetMaxStock() override { return 48; }
float GetReloadTime() override { return 2.5f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return RIFLE_WEAPON; }
int GetDamage(HitType type, float distance) override {
switch (type) {
// These are the 0.75 damage values.
// To be honest, we don't need this information, as the server decides the
@ -306,25 +306,25 @@ namespace spades {
default: SPAssert(false); return 0;
}
}
virtual Vector3 GetRecoil() {
Vector3 GetRecoil() override {
// FIXME: needs to measured
return MakeVector3(0.0001f, 0.075f, 0.f);
}
virtual float GetSpread() { return 0.004f; }
virtual int GetPelletSize() { return 1; }
float GetSpread() override { return 0.004f; }
int GetPelletSize() override { return 1; }
};
class SMGWeapon4 : public Weapon {
public:
SMGWeapon4(World *w, Player *p) : Weapon(w, p) {}
virtual std::string GetName() { return "SMG"; }
virtual float GetDelay() { return 0.1f; }
virtual int GetClipSize() { return 30; }
virtual int GetMaxStock() { return 150; }
virtual float GetReloadTime() { return 2.5f; }
virtual bool IsReloadSlow() { return false; }
virtual WeaponType GetWeaponType() { return SMG_WEAPON; }
virtual int GetDamage(HitType type, float distance) {
std::string GetName() override { return "SMG"; }
float GetDelay() override { return 0.1f; }
int GetClipSize() override { return 30; }
int GetMaxStock() override { return 150; }
float GetReloadTime() override { return 2.5f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return SMG_WEAPON; }
int GetDamage(HitType type, float distance) override {
switch (type) {
case HitTypeTorso: return 29;
case HitTypeHead: return 75;
@ -334,25 +334,25 @@ namespace spades {
default: SPAssert(false); return 0;
}
}
virtual Vector3 GetRecoil() {
Vector3 GetRecoil() override {
// FIXME: needs to measured
return MakeVector3(0.00005f, 0.0125f, 0.f);
}
virtual float GetSpread() { return 0.012f; }
virtual int GetPelletSize() { return 1; }
float GetSpread() override { return 0.012f; }
int GetPelletSize() override { return 1; }
};
class ShotgunWeapon4 : public Weapon {
public:
ShotgunWeapon4(World *w, Player *p) : Weapon(w, p) {}
virtual std::string GetName() { return "Shotgun"; }
virtual float GetDelay() { return 0.8f; }
virtual int GetClipSize() { return 8; }
virtual int GetMaxStock() { return 48; }
virtual float GetReloadTime() { return 0.4f; }
virtual bool IsReloadSlow() { return true; }
virtual WeaponType GetWeaponType() { return SHOTGUN_WEAPON; }
virtual int GetDamage(HitType type, float distance) {
std::string GetName() override { return "Shotgun"; }
float GetDelay() override { return 0.8f; }
int GetClipSize() override { return 8; }
int GetMaxStock() override { return 48; }
float GetReloadTime() override { return 0.4f; }
bool IsReloadSlow() override { return true; }
WeaponType GetWeaponType() override { return SHOTGUN_WEAPON; }
int GetDamage(HitType type, float distance) override {
switch (type) {
case HitTypeTorso: return 27;
case HitTypeHead: return 37;
@ -362,12 +362,12 @@ namespace spades {
default: SPAssert(false); return 0;
}
}
virtual Vector3 GetRecoil() {
Vector3 GetRecoil() override {
// FIXME: needs to measured
return MakeVector3(0.0002f, 0.075f, 0.f);
}
virtual float GetSpread() { return 0.036f; }
virtual int GetPelletSize() { return 8; }
float GetSpread() override { return 0.036f; }
int GetPelletSize() override { return 8; }
};
Weapon *Weapon::CreateWeapon(WeaponType type, Player *p, const GameProperties &gp) {

View File

@ -246,7 +246,7 @@ namespace spades {
public:
DispatchThread(GlobalDispatchThreadPool &pool) : pool{pool} {
}
virtual void Run() throw() {
void Run() noexcept override {
SPADES_MARK_FUNCTION();
while (true) {
SyncQueueEntry *ent = pool.globalQueue.Wait();

View File

@ -54,7 +54,7 @@ namespace spades {
public:
DeflateStream(IStream *stream, CompressMode mode, bool autoClose = false);
virtual ~DeflateStream();
~DeflateStream();
int ReadByte() override;
size_t Read(void *, size_t bytes) override;

View File

@ -45,8 +45,18 @@ namespace spades {
#define SPRaise(fmt, val...) throw ::spades::Exception(__FILE__, __LINE__, fmt, ##val)
#endif
/**
* Raises a "not implemented" exception.
*
* This serves as a dynamic "TODO" marker. Mere occurrences of this macro don't mean there are
* missing features. They have to be *reachable*.
*
* Do not use this to indicate unreachable code! Use `SPUnreachable` instead in such cases.
*/
#define SPNotImplemented() SPRaise("Not implemented")
#define SPUnsupported() SPRaise("Unsupported")
#define SPUnreachable() SPRaise("Internal error; unreachable code")
#define SPInvalidArgument(name) SPRaise("Invalid argument: %s", name)

View File

@ -27,7 +27,7 @@
namespace spades {
IStream::~IStream() {}
int IStream::ReadByte() { SPNotImplemented(); }
int IStream::ReadByte() { SPUnsupported(); }
size_t IStream::Read(void *out, size_t bytes) {
SPADES_MARK_FUNCTION();
@ -66,7 +66,7 @@ namespace spades {
void IStream::WriteByte(int) {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
void IStream::Write(const void *inp, size_t bytes) {
@ -84,13 +84,13 @@ namespace spades {
Write(str.data(), str.size());
}
uint64_t IStream::GetPosition() { SPNotImplemented(); }
uint64_t IStream::GetPosition() { SPUnsupported(); }
void IStream::SetPosition(uint64_t pos) { SPNotImplemented(); }
void IStream::SetPosition(uint64_t pos) { SPUnsupported(); }
uint64_t IStream::GetLength() { SPNotImplemented(); }
uint64_t IStream::GetLength() { SPUnsupported(); }
void IStream::SetLength(uint64_t) { SPNotImplemented(); }
void IStream::SetLength(uint64_t) { SPUnsupported(); }
uint16_t IStream::ReadLittleShort() {
SPADES_MARK_FUNCTION();

View File

@ -50,25 +50,25 @@ namespace spades {
};
public:
virtual bool CanLoad() { return false; }
virtual bool CanSave() { return true; }
bool CanLoad() override { return false; }
bool CanSave() override { return true; }
virtual bool CheckExtension(const std::string &filename) {
bool CheckExtension(const std::string &filename) override {
return EndsWith(filename, ".jpg") || EndsWith(filename, ".jpeg") ||
EndsWith(filename, ".jpe");
}
virtual std::string GetName() {
std::string GetName() override {
static std::string name("JPEG Exporter");
return name;
}
virtual Bitmap *Load(IStream *str) {
Bitmap *Load(IStream *str) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnreachable();
}
virtual void Save(IStream *stream, Bitmap *bmp) {
void Save(IStream *stream, Bitmap *bmp) override {
SPADES_MARK_FUNCTION();
jpge::params params;

View File

@ -39,26 +39,26 @@ namespace spades {
public:
PngWriter() : IBitmapCodec() { png_init(nullptr, nullptr); }
virtual bool CanLoad() { return false; }
bool CanLoad() override { return false; }
virtual bool CanSave() { return true; }
bool CanSave() override { return true; }
virtual bool CheckExtension(const std::string &filename) {
bool CheckExtension(const std::string &filename) override {
return EndsWith(filename, ".png");
}
virtual std::string GetName() {
std::string GetName() override {
static std::string name("libpng exporter");
return name;
}
virtual Bitmap *Load(IStream *str) {
Bitmap *Load(IStream *str) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnreachable();
}
virtual void Save(IStream *stream, Bitmap *bmp) {
void Save(IStream *stream, Bitmap *bmp) override {
SPADES_MARK_FUNCTION();
int err;

View File

@ -105,7 +105,7 @@ namespace spades {
void SdlFileStream::SetLength(uint64_t len) {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
void SdlFileStream::Flush() {

View File

@ -32,16 +32,12 @@
namespace spades {
class SdlImageReader : public IBitmapCodec {
public:
virtual std::string GetName() = 0;
virtual SDL_Surface *LoadSdlImage(const std::string &data) = 0;
virtual bool CanLoad() { return true; }
virtual bool CanSave() { return false; }
bool CanLoad() override { return true; }
bool CanSave() override { return false; }
virtual bool CheckExtension(const std::string &) = 0;
virtual Bitmap *Load(IStream *stream) {
Bitmap *Load(IStream *stream) override {
SPADES_MARK_FUNCTION();
// read all
@ -89,9 +85,9 @@ namespace spades {
}
}
virtual void Save(IStream *, Bitmap *) {
void Save(IStream *, Bitmap *) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnreachable();
}
};
@ -109,9 +105,9 @@ namespace spades {
class SdlImageImageReader : public SdlImageReader {
public:
virtual std::string GetName() { return "SDL_image Image Reader"; }
std::string GetName() override { return "SDL_image Image Reader"; }
virtual SDL_Surface *LoadSdlImage(const std::string &data) {
SDL_Surface *LoadSdlImage(const std::string &data) override {
StringSdlRWops ops(data);
int flags = IMG_INIT_PNG | IMG_INIT_JPG;
int initted = IMG_Init(flags);
@ -125,7 +121,7 @@ namespace spades {
return s;
}
virtual bool CheckExtension(const std::string &fn) {
bool CheckExtension(const std::string &fn) override {
return EndsWith(fn, ".png") || EndsWith(fn, ".jpg") || EndsWith(fn, ".tif") ||
EndsWith(fn, ".bmp");
}

View File

@ -41,19 +41,19 @@ typedef unsigned char byte;
namespace spades {
class TargaReader : public IBitmapCodec {
public:
virtual bool CanLoad() { return true; }
virtual bool CanSave() { return false; }
bool CanLoad() override { return true; }
bool CanSave() override { return false; }
virtual bool CheckExtension(const std::string &filename) {
bool CheckExtension(const std::string &filename) override {
return EndsWith(filename, ".tga");
}
virtual std::string GetName() {
std::string GetName() override {
static std::string name("Quake 3 Derived Targa Importer");
return name;
}
virtual Bitmap *Load(IStream *str) {
Bitmap *Load(IStream *str) override {
SPADES_MARK_FUNCTION();
unsigned columns, rows, numPixels;
@ -313,9 +313,9 @@ namespace spades {
return bmp;
}
virtual void Save(IStream *stream, Bitmap *bmp) {
void Save(IStream *stream, Bitmap *bmp) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnreachable();
}
};

View File

@ -1288,24 +1288,24 @@ void tga_free_buffers(tga_image *img)
namespace spades {
class TargaWriter : public IBitmapCodec {
public:
virtual bool CanLoad() { return false; }
virtual bool CanSave() { return true; }
bool CanLoad() override { return false; }
bool CanSave() override { return true; }
virtual bool CheckExtension(const std::string &filename) {
bool CheckExtension(const std::string &filename) override {
return EndsWith(filename, ".tga");
}
virtual std::string GetName() {
std::string GetName() override {
static std::string name("dmr.ath.cx Targa Exporter");
return name;
}
virtual Bitmap *Load(IStream *str) {
Bitmap *Load(IStream *str) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnreachable();
}
virtual void Save(IStream *stream, Bitmap *bmp) {
void Save(IStream *stream, Bitmap *bmp) override {
SPADES_MARK_FUNCTION();
tga_image img;

View File

@ -106,11 +106,11 @@ namespace spades {
SPRaise("Failed to create Windows TLS key");
}
}
virtual ~Win32ThreadLocalStorageImpl() { TlsFree(key); }
~Win32ThreadLocalStorageImpl() { TlsFree(key); }
virtual void Set(void *value) { TlsSetValue(key, value); }
void Set(void *value) override { TlsSetValue(key, value); }
virtual void *Get() { return TlsGetValue(key); }
void *Get() override { return TlsGetValue(key); }
};
ThreadLocalStorageImpl *ThreadLocalStorageImpl::Create() {
@ -127,15 +127,15 @@ namespace spades {
SPRaise("Failed to create PThread TLS key");
}
}
virtual ~PThreadThreadLocalStorageImpl() { pthread_key_delete(key); }
~PThreadThreadLocalStorageImpl() { pthread_key_delete(key); }
virtual void Set(void *value) {
void Set(void *value) override {
if (pthread_setspecific(key, value)) {
SPRaise("Failed to set TLS value");
}
}
virtual void *Get() { return pthread_getspecific(key); }
void *Get() override { return pthread_getspecific(key); }
};
ThreadLocalStorageImpl *ThreadLocalStorageImpl::Create() {

View File

@ -53,7 +53,7 @@ namespace spades {
internal = ThreadLocalStorageImpl::Create();
internal->destructor = this;
}
virtual ~ThreadLocalStorage() {
~ThreadLocalStorage() {
// FIXME: should support deleting tls?
}
void operator=(T *ptr) { internal->Set(reinterpret_cast<void *>(ptr)); }
@ -66,14 +66,14 @@ namespace spades {
}
T *operator->() { return GetPointer(); }
operator T *() { return GetPointer(); }
virtual void Destruct(void *) {}
void Destruct(void *) override {}
};
template <typename T> class AutoDeletedThreadLocalStorage : public ThreadLocalStorage<T> {
public:
AutoDeletedThreadLocalStorage() : ThreadLocalStorage<T>() {}
AutoDeletedThreadLocalStorage(std::string name) : ThreadLocalStorage<T>(name) {}
virtual void Destruct(void *v) { delete reinterpret_cast<T *>(v); }
void Destruct(void *v) override { delete reinterpret_cast<T *>(v); }
void operator=(T *ptr) { *static_cast<ThreadLocalStorage<T> *>(this) = ptr; }
};

View File

@ -54,7 +54,7 @@ namespace spades {
SPADES_MARK_FUNCTION();
}
virtual ~ZipFileInputStream() {
~ZipFileInputStream() {
SPADES_MARK_FUNCTION();
if (streaming) {
unzCloseCurrentFile(zip);
@ -84,7 +84,7 @@ namespace spades {
}
}
virtual int ReadByte() {
int ReadByte() override {
SPADES_MARK_FUNCTION();
int byte;
if (streaming) {
@ -109,7 +109,7 @@ namespace spades {
}
return byte;
}
virtual size_t Read(void *buf, size_t bytes) {
size_t Read(void *buf, size_t bytes) override {
SPADES_MARK_FUNCTION();
size_t outBytes;
if (streaming) {
@ -132,33 +132,33 @@ namespace spades {
return outBytes;
}
virtual void WriteByte(int) {
void WriteByte(int) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
virtual void Write(const void *, size_t bytes) {
void Write(const void *, size_t bytes) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
virtual void Write(const std::string &) {
void Write(const std::string &) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
virtual uint64_t GetPosition() { return pos; }
virtual void SetPosition(uint64_t) {
uint64_t GetPosition() override { return pos; }
void SetPosition(uint64_t) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
virtual uint64_t GetLength() {
uint64_t GetLength() override {
SPADES_MARK_FUNCTION();
ForceCloseUnzipFile();
return pos + remainingData.size() - remDataPos;
}
virtual void SetLength(uint64_t) {
void SetLength(uint64_t) override {
SPADES_MARK_FUNCTION();
SPNotImplemented();
SPUnsupported();
}
};

View File

@ -18,6 +18,7 @@
*/
#include <atomic>
#include <cstdlib>
#include <Client/GameMap.h>
@ -33,9 +34,9 @@ namespace spades {
GLAmbientShadowRenderer *renderer;
public:
volatile bool done;
UpdateDispatch(GLAmbientShadowRenderer *r) : renderer(r) { done = false; }
virtual void Run() {
std::atomic<bool> done {false};
UpdateDispatch(GLAmbientShadowRenderer *r) : renderer(r) { }
void Run() override {
SPADES_MARK_FUNCTION();
renderer->UpdateDirtyChunks();

View File

@ -18,6 +18,7 @@
*/
#include <atomic>
#include <cstdlib>
#include <Client/GameMap.h>
@ -39,9 +40,9 @@ namespace spades {
GLRadiosityRenderer *renderer;
public:
volatile bool done;
UpdateDispatch(GLRadiosityRenderer *r) : renderer(r) { done = false; }
virtual void Run() {
std::atomic<bool> done {false};
UpdateDispatch(GLRadiosityRenderer *r) : renderer(r) { }
void Run() override {
SPADES_MARK_FUNCTION();
// Enable FPE
@ -351,7 +352,7 @@ namespace spades {
}
void GLRadiosityRenderer::Update() {
if (GetNumDirtyChunks() > 0 && (dispatch == NULL || dispatch->done)) {
if (GetNumDirtyChunks() > 0 && (dispatch == NULL || dispatch->done.load())) {
if (dispatch) {
dispatch->Join();
delete dispatch;

View File

@ -220,9 +220,9 @@ namespace spades {
}
}
}
virtual ~FFTWaveTank() { kiss_fft_free(fft); }
~FFTWaveTank() { kiss_fft_free(fft); }
virtual void Run() {
void Run() override {
// advance cells
for (int x = 0; x < Size; x++) {
for (int y = 0; y <= SizeHalf; y++) {
@ -350,14 +350,14 @@ namespace spades {
std::fill(velocity, velocity + size * size, 0.f);
}
virtual ~StandardWaveTank() {
~StandardWaveTank() {
delete[] height;
delete[] heightFiltered;
delete[] velocity;
}
virtual void Run() {
void Run() override {
// advance time
for (int i = 0; i < samples; i++)
height[i] += velocity[i] * dt;

View File

@ -30,8 +30,16 @@ namespace spades {
~SWPort() {}
public:
/**
* Returns a `Bitmap` on which the scene is rendered.
*/
virtual Bitmap *GetFramebuffer() = 0;
/**
* Presents the contents of the framebuffer (returned by
* `GetFramebuffer`) to the screen.
*/
virtual void Swap() = 0;
};
}
}
}

View File

@ -228,8 +228,8 @@ namespace spades {
spades::ServerAddress addr;
protected:
virtual spades::gui::View *CreateView(spades::client::IRenderer *renderer,
spades::client::IAudioDevice *audio) {
spades::gui::View *CreateView(spades::client::IRenderer *renderer,
spades::client::IAudioDevice *audio) override {
Handle<client::FontManager> fontManager(new client::FontManager(renderer), false);
return new spades::client::Client(renderer, audio, addr, fontManager);
}
@ -243,8 +243,8 @@ namespace spades {
void StartMainScreen() {
class ConcreteRunner : public spades::gui::Runner {
protected:
virtual spades::gui::View *CreateView(spades::client::IRenderer *renderer,
spades::client::IAudioDevice *audio) {
spades::gui::View *CreateView(spades::client::IRenderer *renderer,
spades::client::IAudioDevice *audio) override {
Handle<client::FontManager> fontManager(new client::FontManager(renderer), false);
return new spades::gui::MainScreen(renderer, audio, fontManager);
}

View File

@ -72,7 +72,7 @@ namespace spades {
Runner *r;
protected:
virtual View *CreateView(client::IRenderer *renderer, client::IAudioDevice *dev) {
View *CreateView(client::IRenderer *renderer, client::IAudioDevice *dev) override {
return r->CreateView(renderer, dev);
}

View File

@ -329,7 +329,7 @@ namespace spades {
}
protected:
virtual ~SDLSWPort() {
~SDLSWPort() {
if (surface && SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface);
}
@ -355,8 +355,8 @@ namespace spades {
}
SetFramebufferBitmap();
}
virtual Bitmap *GetFramebuffer() { return framebuffer; }
virtual void Swap() {
Bitmap *GetFramebuffer() override { return framebuffer; }
void Swap() override {
if (adjusted) {
int sy = (surface->h - actualH) >> 1;
int sx = (surface->w - actualW) >> 1;

View File

@ -265,11 +265,11 @@ namespace spades {
StartupScreenHelper *helper;
protected:
virtual auto GetRendererType() -> RendererType { return RendererType::SW; }
virtual client::IAudioDevice *CreateAudioDevice() {
auto GetRendererType() -> RendererType override { return RendererType::SW; }
client::IAudioDevice *CreateAudioDevice() override {
return new audio::NullDevice();
}
virtual View *CreateView(client::IRenderer *renderer, client::IAudioDevice *dev) {
View *CreateView(client::IRenderer *renderer, client::IAudioDevice *dev) override {
Handle<client::FontManager> fontManager(new client::FontManager(renderer),
false);
view.Set(new StartupScreen(renderer, dev, helper, fontManager), true);

View File

@ -66,7 +66,7 @@ namespace spades {
bool openGLCapable;
protected:
virtual ~StartupScreenHelper();
~StartupScreenHelper();
public:
StartupScreenHelper();

View File

@ -36,7 +36,7 @@ namespace spades{
}
public:
PackageUpdateManagerRegistrar() : ScriptObjectRegistrar("PackageUpdateManager") {}
virtual void Register(ScriptManager *manager, Phase phase) {
void Register(ScriptManager *manager, Phase phase) override {
asIScriptEngine *eng = manager->GetEngine();
int r;
eng->SetDefaultNamespace("spades");