Skip to content

Commit

Permalink
Index intermediate classes of GameObjects
Browse files Browse the repository at this point in the history
This allows for much more efficient implementations of GameObjectManager's
get_object_count and get_objects_by_type. Now, for example, counting all
BadGuy objects does not require scanning through all the unrelated objects.
  • Loading branch information
mstoeckl committed Jun 30, 2024
1 parent c1be0b7 commit fc686fa
Show file tree
Hide file tree
Showing 181 changed files with 241 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/badguy/angrystone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AngryStone final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Angry Stone"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(AngryStone)); }

protected:
virtual std::vector<Direction> get_allowed_directions() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class BadGuy : public MovingSprite,
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Badguy"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(Portable)).add(typeid(BadGuy)); }

virtual std::string get_overlay_size() const { return "1x1"; }

Expand Down
1 change: 1 addition & 0 deletions src/badguy/bomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Bomb final : public BadGuy
{
public:
Bomb(const Vector& pos, Direction dir, const std::string& custom_sprite = "images/creatures/mr_bomb/bomb.sprite" );
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Bomb)); }
virtual bool is_saveable() const override {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/badguy/bouncing_snowball.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BouncingSnowball final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Bouncing Snowball"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(BouncingSnowball)); }

virtual GameObjectTypes get_types() const override;
virtual std::string get_default_sprite_name() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/captainsnowball.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CaptainSnowball final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Captain Snowball"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(CaptainSnowball)); }
virtual bool is_snipable() const override { return true; }

bool might_climb(int width, int height) const;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/corrupted_granito.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CorruptedGranito final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Corrupted Granito"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(CorruptedGranito)); }
virtual bool is_snipable() const override { return true; }
virtual bool is_flammable() const override { return m_type != GRANITO; }

Expand Down
1 change: 1 addition & 0 deletions src/badguy/corrupted_granito_big.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CorruptedGranitoBig final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Corrupted Big Granito"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(CorruptedGranitoBig)); }

virtual bool is_snipable() const override { return false; }
virtual bool is_freezable() const override { return false; }
Expand Down
2 changes: 2 additions & 0 deletions src/badguy/crusher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Crusher final : public MovingSprite
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Crusher"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(Crusher)); }

virtual ObjectSettings get_settings() override;
GameObjectTypes get_types() const override;
Expand Down Expand Up @@ -115,6 +116,7 @@ class CrusherRoot : public MovingSprite
{
public:
CrusherRoot(Vector position, Crusher::Direction direction, float delay, int layer);
virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(CrusherRoot)); }

virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
virtual void update(float dt_sec) override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/crystallo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Crystallo final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Crystallo"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(Crystallo)); }

virtual void active_update(float dt_sec) override;
virtual bool is_flammable() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/dart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Dart final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Dart"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Dart)); }

virtual bool is_flammable() const override;

Expand Down
1 change: 1 addition & 0 deletions src/badguy/darttrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DartTrap final : public StickyBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Dart Trap"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return StickyBadguy::get_class_types().add(typeid(DartTrap)); }

virtual ObjectSettings get_settings() override;
virtual GameObjectTypes get_types() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/dispenser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Dispenser final : public BadGuy,
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Dispenser"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Dispenser)); }

virtual ObjectSettings get_settings() override;
virtual GameObjectTypes get_types() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/dive_mine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DiveMine final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Dive Mine"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(DiveMine)); }

protected:
virtual std::vector<Direction> get_allowed_directions() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/fish_chasing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FishChasing final : public FishSwimming
static std::string display_name() { return _("Chasing Fish"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual std::string get_overlay_size() const override { return "2x2"; }
virtual GameObjectClasses get_class_types() const override { return FishSwimming::get_class_types().add(typeid(FishChasing)); }
virtual ObjectSettings get_settings() override;

std::string get_default_sprite_name() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/fish_harmless.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FishHarmless final : public FishSwimming
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Harmless Fish"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return FishSwimming::get_class_types().add(typeid(FishHarmless)); }
virtual std::string get_overlay_size() const override { return "1x1"; }

GameObjectTypes get_types() const override { return {}; }
Expand Down
1 change: 1 addition & 0 deletions src/badguy/fish_jumping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FishJumping final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Jumping Fish"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(FishJumping)); }

protected:
virtual std::vector<Direction> get_allowed_directions() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/fish_swimming.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FishSwimming : public BadGuy
static std::string display_name() { return _("Swimming Fish"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual std::string get_overlay_size() const override { return "2x1"; }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(FishSwimming)); }
virtual ObjectSettings get_settings() override;

virtual GameObjectTypes get_types() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/flame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Flame final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Flame"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Flame)); }

virtual void stop_looping_sounds() override;
virtual void play_looping_sounds() override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/flyingsnowball.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FlyingSnowBall final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Flying Snowball"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(FlyingSnowBall)); }
virtual bool is_snipable() const override { return true; }

protected:
Expand Down
1 change: 1 addition & 0 deletions src/badguy/ghosttree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class GhostTree final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Ghost Tree"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(GhostTree)); }

virtual void on_flip(float height) override;

Expand Down
1 change: 1 addition & 0 deletions src/badguy/ghoul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Ghoul final : public BadGuy,
static std::string display_name() { return _("Ghoul"); }
std::string get_class_name() const override { return class_name(); }
std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Ghoul)); }
bool is_freezable() const override;
bool is_flammable() const override;
virtual bool is_snipable() const override { return true; }
Expand Down
1 change: 1 addition & 0 deletions src/badguy/goldbomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class GoldBomb final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Gold Bomb"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(GoldBomb)); }
virtual bool is_snipable() const override { return true; }

virtual void stop_looping_sounds() override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/granito.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Granito : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Granito"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(Granito)); }

virtual bool is_snipable() const override { return false; }
virtual bool is_freezable() const override { return false; }
Expand Down
1 change: 1 addition & 0 deletions src/badguy/granito_big.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GranitoBig final : public Granito
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Big Granito"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return Granito::get_class_types().add(typeid(GranitoBig)); }

virtual GameObjectTypes get_types() const override;

Expand Down
1 change: 1 addition & 0 deletions src/badguy/granito_giant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GranitoGiant final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Giant Granito"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(GranitoGiant)); }

virtual void kill_fall() override;

Expand Down
1 change: 1 addition & 0 deletions src/badguy/haywire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Haywire final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Haywire"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(Haywire)); }
virtual bool is_snipable() const override { return true; }

inline bool is_exploding() const { return m_is_exploding; }
Expand Down
1 change: 1 addition & 0 deletions src/badguy/igel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Igel final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Igel"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(Igel)); }

virtual bool is_freezable() const override { return true; }
virtual void unfreeze(bool melt = true) override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/jumpy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Jumpy final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Jumpy"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Jumpy)); }

GameObjectTypes get_types() const override;
std::string get_default_sprite_name() const override;
Expand Down
2 changes: 2 additions & 0 deletions src/badguy/kamikazesnowball.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class KamikazeSnowball : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Kamikaze Snowball"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(KamikazeSnowball)); }
virtual bool is_snipable() const override { return true; }

protected:
Expand Down Expand Up @@ -63,6 +64,7 @@ class LeafShot final : public KamikazeSnowball
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Leafshot"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return KamikazeSnowball::get_class_types().add(typeid(LeafShot)); }

virtual bool is_snipable() const override { return true; }

Expand Down
1 change: 1 addition & 0 deletions src/badguy/kugelblitz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Kugelblitz final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Kugelblitz"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Kugelblitz)); }

void explode();

Expand Down
3 changes: 3 additions & 0 deletions src/badguy/livefire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LiveFire : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Walking Flame"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(LiveFire)); }

private:
std::string death_sound;
Expand Down Expand Up @@ -70,6 +71,7 @@ class LiveFireAsleep final : public LiveFire
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Sleeping Flame"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return LiveFire::get_class_types().add(typeid(LiveFireAsleep)); }

private:
LiveFireAsleep(const LiveFireAsleep&) = delete;
Expand All @@ -88,6 +90,7 @@ class LiveFireDormant final : public LiveFire
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Dormant Flame"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return LiveFire::get_class_types().add(typeid(LiveFireDormant)); }

private:
LiveFireDormant(const LiveFireDormant&) = delete;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/mole.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Mole final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Mole"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(Mole)); }

virtual bool is_snipable() const override { return true; }

Expand Down
1 change: 1 addition & 0 deletions src/badguy/mole_rock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MoleRock final : public BadGuy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Mole's rock"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(MoleRock)); }

protected:
const BadGuy* parent; /**< collisions with this BadGuy will be ignored */
Expand Down
1 change: 1 addition & 0 deletions src/badguy/mrbomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MrBomb final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Mr. Bomb"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(MrBomb)); }
virtual bool is_snipable() const override { return true; }

GameObjectTypes get_types() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/mriceblock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MrIceBlock : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Mr. Iceblock"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(MrIceBlock)); }

virtual bool is_snipable() const override { return ice_state != ICESTATE_KICKED; }
virtual bool is_freezable() const override;
Expand Down
1 change: 1 addition & 0 deletions src/badguy/mrtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MrTree final : public WalkingBadguy
virtual std::string get_class_name() const override { return class_name(); }
static std::string display_name() { return _("Mr. Tree"); }
virtual std::string get_display_name() const override { return display_name(); }
virtual GameObjectClasses get_class_types() const override { return WalkingBadguy::get_class_types().add(typeid(MrTree)); }

GameObjectTypes get_types() const override;
std::string get_default_sprite_name() const override;
Expand Down
Loading

0 comments on commit fc686fa

Please sign in to comment.