Skip to content

Commit 3017930

Browse files
committed
Spring cleaning
1 parent 4ce6016 commit 3017930

31 files changed

Lines changed: 166 additions & 286 deletions

‎CMakeLists.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ set(PROJECT_FILES
7373
"src/game/entities/characters/character/Hands.h"
7474
"src/game/entities/characters/CharacterNPC.cpp"
7575
"src/game/entities/characters/CharacterNPC.h"
76-
"src/game/weapons/laser/LaserWeapon.cpp"
77-
"src/game/weapons/laser/LaserWeapon.h"
7876
"src/game/entities/item/ItemEntity.cpp"
7977
"src/game/entities/item/ItemEntity.h"
8078
"src/Protocol.h"

‎src/GameReference.cpp‎

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -147,68 +147,6 @@ bool GameReference::Initialize() {
147147
m_GameWorld = new GameWorld(this, 50, 30);
148148
m_Controllers = new GameControllers();
149149

150-
Assets* decals = Assets::Get();
151-
152-
Hands::ms_FistTexture = decals->GetTexture("entities.fist");
153-
ItemEntity::ms_TextureGlock = decals->GetTexture("entities.items.glock");
154-
ItemEntity::ms_TextureShotgun = decals->GetTexture("entities.items.shotgun");
155-
ItemEntity::ms_TextureBurst = decals->GetTexture("entities.items.burst");
156-
ItemEntity::ms_TextureSniper = decals->GetTexture("entities.items.sniper");
157-
ItemEntity::ms_TexturesMinigun[0] = decals->GetTexture("entities.items.minigun1");
158-
ItemEntity::ms_TexturesMinigun[1] = decals->GetTexture("entities.items.minigun2");
159-
ItemEntity::ms_TexturesMinigun[2] = decals->GetTexture("entities.items.minigun3");
160-
ItemEntity::ms_TexturesMinigun[3] = decals->GetTexture("entities.items.minigun4");
161-
Projectile::ms_TextureGlock = decals->GetTexture("entities.projectiles.glockbullet");
162-
Projectile::ms_TextureBurst = decals->GetTexture("entities.projectiles.burstbullet");
163-
Projectile::ms_TextureShotgun = decals->GetTexture("entities.projectiles.shotgunbullet");
164-
Projectile::ms_TextureSniper = decals->GetTexture("entities.projectiles.shotgunbullet");
165-
Projectile::ms_TextureMinigun = decals->GetTexture("entities.projectiles.minigunbullet");
166-
AmmoBox::ms_TextureGlock = decals->GetTexture("entities.glockammo");
167-
AmmoBox::ms_TextureShotgun = decals->GetTexture("entities.shotgunammo");
168-
AmmoBox::ms_TextureBurst = decals->GetTexture("entities.burstammo");
169-
AmmoBox::ms_TextureMinigun = decals->GetTexture("entities.minigunammo");
170-
Crate::ms_TextureBox = decals->GetTexture("entities.ammocrate");
171-
Crate::ms_TextureBreakingBox1 = decals->GetTexture("entities.rts_crate_breaking_1");
172-
Crate::ms_TextureBreakingBox2 = decals->GetTexture("entities.rts_crate_breaking_2");
173-
Error::ms_TextureErrorInvincible = decals->GetTexture("entities.invincible");
174-
Error::ms_TextureErrorSpiky = decals->GetTexture("entities.cactus");
175-
Error::ms_TextureErrorSlowDown = decals->GetTexture("entities.clock");
176-
Error::ms_TextureErrorDisorianted = decals->GetTexture("entities.disorianted");
177-
Error::ms_TextureErrorHealersParadise = decals->GetTexture("entities.healer");
178-
Error::ms_TextureErrorConfusingHP = decals->GetTexture("entities.confusion");
179-
Error::ms_TextureErrorRanged = decals->GetTexture("entities.ranged");
180-
Error::ms_TextureError = decals->GetTexture("entities.golden_apple");
181-
182-
// Load sounds
183-
Sound* Basic_Death = decals->GetSound("basic_death");
184-
Sound* FailReloadSound = decals->GetSound("failreload");
185-
Sound* GlockShootSound = decals->GetSound("glockshoot");
186-
GlockShootSound->SetVolume(64); // max 128
187-
Sound* GlockClickSound = decals->GetSound("gunclick");
188-
GlockClickSound->SetVolume(32); // max 128
189-
Sound* ShotgunShootSound = decals->GetSound("shotgunshoot");
190-
Sound* BurstShootSound = decals->GetSound("shootburst");
191-
Sound* ShotgunReloadSound = decals->GetSound("shotgunreload");
192-
193-
WeaponGlock::ms_ShootSound = GlockShootSound;
194-
WeaponGlock::ms_ClickSound = FailReloadSound;
195-
WeaponGlock::ms_ReloadSound = ShotgunReloadSound;
196-
ProjectileWeapon::ms_NoAmmo = GlockClickSound;
197-
WeaponShotgun::ms_ShootSound = ShotgunShootSound;
198-
WeaponShotgun::ms_ClickSound = FailReloadSound;
199-
WeaponShotgun::ms_ReloadSound = ShotgunReloadSound;
200-
WeaponBurst::ms_ShootSound = BurstShootSound;
201-
WeaponBurst::ms_ClickSound = FailReloadSound;
202-
WeaponBurst::ms_ReloadSound = ShotgunReloadSound;
203-
WeaponSniper::ms_ShootSound = nullptr;
204-
WeaponSniper::ms_ClickSound = nullptr;
205-
WeaponSniper::ms_ReloadSound = nullptr;
206-
WeaponMinigun::ms_ShootSound = BurstShootSound;
207-
WeaponMinigun::ms_ClickSound = FailReloadSound;
208-
WeaponMinigun::ms_ReloadSound = ShotgunReloadSound;
209-
Crate::ms_BoxSound = decals->GetSound("boxhit");
210-
Crate::ms_HitSound = decals->GetSound("entities.character.hurt1");
211-
212150
m_Draw->SetWorld(m_GameWorld);
213151
Character::ms_BotNamePlate = new TextSurface(m_GameWorld->GameWindow()->Assetz(),
214152
m_GameWorld->GameWindow()->Assetz()->TextHandler()->GetMainFont(),

‎src/client/Assets.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,11 @@ LoadedSound::LoadedSound(std::string sound_key)
284284
m_Sound = nullptr;
285285

286286
Assets::RequireSound(this);
287-
std::cout << FString("Created LoadedSound(%s)", m_Key.c_str()) << std::endl;
288287
}
288+
289+
Sound* LoadedSound::GetSound() const {
290+
if (m_Sound == nullptr)
291+
throw std::runtime_error(FString("GetSound '%s' was nullptr", m_Key.c_str()));
292+
293+
return m_Sound;
294+
}

‎src/client/Assets.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ class LoadedSound {
131131

132132
// Getting
133133
[[nodiscard]] const std::string& Key() const { return m_Key; }
134-
[[nodiscard]] Sound* GetSound() const { return m_Sound; }
134+
[[nodiscard]] Sound* GetSound() const;
135135

136136
};

‎src/game/entities/AmmoBox.cpp‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#include "characters/character/Character.h"
66
#include <cmath>
77
#include <iostream>
8-
Texture* AmmoBox::ms_TextureGlock = nullptr;
9-
Texture* AmmoBox::ms_TextureShotgun = nullptr;
10-
Texture* AmmoBox::ms_TextureBurst = nullptr;
11-
Texture* AmmoBox::ms_TextureMinigun = nullptr;
8+
9+
LoadedTexture AmmoBox::sTextureGlock("entities.glockammo");
10+
LoadedTexture AmmoBox::sTextureShotgun("entities.shotgunammo");
11+
LoadedTexture AmmoBox::sTextureBurst("entities.burstammo");
12+
LoadedTexture AmmoBox::sTextureMinigun("entities.minigunammo");
1213
// Sound* AmmoBox::ms_PickupSounds[7] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
1314

1415
AmmoBox::AmmoBox(GameWorld* world,
@@ -26,10 +27,10 @@ AmmoBox::AmmoBox(GameWorld* world,
2627
m_AmmoCount = AmmoCount;
2728
m_Type = type;
2829

29-
if (type == AMMO_GLOCK) m_Texture = &ms_TextureGlock;
30-
else if (type == AMMO_SHOTGUN) m_Texture = &ms_TextureShotgun;
31-
else if (type == AMMO_BURST) m_Texture = &ms_TextureBurst;
32-
else if (type == AMMO_MINIGUN) m_Texture = &ms_TextureMinigun;
30+
if (type == AMMO_GLOCK) m_Texture = sTextureGlock.GetTexture();
31+
else if (type == AMMO_SHOTGUN) m_Texture = sTextureShotgun.GetTexture();
32+
else if (type == AMMO_BURST) m_Texture = sTextureBurst.GetTexture();
33+
else if (type == AMMO_MINIGUN) m_Texture = sTextureMinigun.GetTexture();
3334
}
3435
void AmmoBox::TickPickup() {
3536
// Check if position collides any of the players
@@ -80,5 +81,5 @@ void AmmoBox::Draw() {
8081
float(m_Core.Size.x),
8182
float(m_Core.Size.y) };
8283

83-
Render->RenderTextureFCamera((*m_Texture)->SDLTexture(), nullptr, DrawRect);
84+
Render->RenderTextureFCamera(m_Texture->SDLTexture(), nullptr, DrawRect);
8485
}

‎src/game/entities/AmmoBox.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ class AmmoBox : public Entity {
1919
protected:
2020
unsigned int m_AmmoCount;
2121
AmmoType m_Type;
22-
Texture** m_Texture;
22+
Texture* m_Texture;
2323

2424
// Ticking
2525
void TickPickup();
2626

2727
public:
28-
static Texture* ms_TextureGlock;
29-
static Texture* ms_TextureShotgun;
30-
static Texture* ms_TextureBurst;
31-
static Texture* ms_TextureMinigun;
28+
static LoadedTexture sTextureGlock;
29+
static LoadedTexture sTextureShotgun;
30+
static LoadedTexture sTextureBurst;
31+
static LoadedTexture sTextureMinigun;
3232
// static Sound* ms_PickupSounds[7];
3333

3434
AmmoBox(GameWorld* world,

‎src/game/entities/Crate.cpp‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#include "characters/character/Character.h"
55
#include "Crate.h"
66
#include <iostream>
7-
Texture* Crate::ms_TextureBox = nullptr;
8-
Texture* Crate::ms_TextureBreakingBox1 = nullptr;
9-
Texture* Crate::ms_TextureBreakingBox2 = nullptr;
10-
Sound* Crate::ms_HitSound = nullptr;
11-
Sound* Crate::ms_BoxSound = nullptr;
7+
LoadedSound Crate::sHitSound("entities.character.hurt1");
8+
LoadedSound Crate::sBoxSound("boxhit");
9+
LoadedTexture Crate::sBoxTexture("entities.ammocrate");
10+
LoadedTexture Crate::sBreakingBox1Texture("entities.rts_crate_breaking_1");
11+
LoadedTexture Crate::sBreakingBox2Texture("entities.rts_crate_breaking_2");
1212

1313
Crate::Crate(GameWorld* world,
1414
const Vec2d& start_pos,
@@ -25,7 +25,7 @@ Crate::Crate(GameWorld* world,
2525
m_World = world;
2626
m_Alive = true;
2727
m_DropType = RandomDrop;
28-
m_Texture = &ms_TextureBox;
28+
m_Texture = sBoxTexture.GetTexture();
2929

3030
auto Random = m_World->GameWindow()->Random();
3131
float RandomFloat = Random->PercentageFloat();
@@ -51,12 +51,12 @@ Crate::~Crate()
5151
}
5252

5353
void Crate::Damage(double value, Entity* damager) {
54-
Sound* BoxHitSound = ms_BoxSound;
54+
Sound* BoxHitSound = sBoxSound.GetSound();
5555
BoxHitSound->PlaySound();
5656
m_HealthComponent.ChangeHealthBy(-value);
5757

58-
if (m_HealthComponent.m_Health < 10) m_Texture = &ms_TextureBreakingBox2;
59-
else if (m_HealthComponent.m_Health < 20) m_Texture = &ms_TextureBreakingBox1;
58+
if (m_HealthComponent.m_Health < 10) m_Texture = sBreakingBox2Texture.GetTexture();
59+
else if (m_HealthComponent.m_Health < 20) m_Texture = sBreakingBox1Texture.GetTexture();
6060
}
6161

6262
void Crate::Heal(double value) {
@@ -69,7 +69,7 @@ void Crate::Tick() {
6969
// Die
7070
if (!m_HealthComponent.IsAlive()) {
7171
m_Alive = false;
72-
ms_HitSound->PlaySound();
72+
sHitSound.GetSound()->PlaySound();
7373
if (m_DropType != ERROR) {
7474
auto Ammo_type = m_World->GameWindow()->Random()->UnsignedInt() % 4;
7575
new AmmoBox(m_World, AmmoType(Ammo_type), m_Core.Pos, 20);
@@ -90,5 +90,5 @@ void Crate::Draw() {
9090
float(m_Core.Size.x),
9191
float(m_Core.Size.y) };
9292

93-
Render->RenderTextureFCamera((*m_Texture)->SDLTexture(), nullptr, DrawRect);
93+
Render->RenderTextureFCamera(m_Texture->SDLTexture(), nullptr, DrawRect);
9494
}

‎src/game/entities/Crate.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class Crate : public Entity {
2020
friend class GameWorld;
2121
DropType m_DropType;
2222
int m_ErrorType;
23-
Texture** m_Texture;
23+
Texture* m_Texture;
2424

2525
public:
26-
static Sound* ms_HitSound;
27-
static Sound* ms_BoxSound;
28-
static Texture* ms_TextureBox;
29-
static Texture* ms_TextureBreakingBox1;
30-
static Texture* ms_TextureBreakingBox2;
26+
static LoadedSound sHitSound;
27+
static LoadedSound sBoxSound;
28+
static LoadedTexture sBoxTexture;
29+
static LoadedTexture sBreakingBox1Texture;
30+
static LoadedTexture sBreakingBox2Texture;
3131

3232
Crate(GameWorld* world,
3333
const Vec2d& start_pos,

‎src/game/entities/Error.cpp‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
#include <random>
77
#include <string>
88

9-
Texture* Error::ms_TextureErrorDisorianted = nullptr;
10-
Texture* Error::ms_TextureErrorSpiky = nullptr;
11-
Texture* Error::ms_TextureErrorConfusingHP = nullptr;
12-
Texture* Error::ms_TextureErrorInvincible = nullptr;
13-
Texture* Error::ms_TextureErrorHealersParadise = nullptr;
14-
Texture* Error::ms_TextureErrorRanged = nullptr;
15-
Texture* Error::ms_TextureErrorSlowDown = nullptr;
16-
Texture* Error::ms_TextureErrorDangerousRecoil = nullptr;
17-
Texture* Error::ms_TextureError = nullptr;
9+
LoadedTexture Error::sTextureErrorDisorianted("entities.disorianted");
10+
LoadedTexture Error::sTextureErrorSpiky("entities.cactus");
11+
LoadedTexture Error::sTextureErrorConfusingHP("entities.confusion");
12+
LoadedTexture Error::sTextureErrorInvincible("entities.invincible");
13+
LoadedTexture Error::sTextureErrorHealersParadise("entities.healer");
14+
LoadedTexture Error::sTextureErrorRanged("entities.ranged");
15+
LoadedTexture Error::sTextureErrorSlowDown("entities.clock");
16+
LoadedTexture Error::sTextureErrorDangerousRecoil("entities.golden_apple");
17+
LoadedSound Error::ms_PickupSounds[7] = {
18+
LoadedSound(""),
19+
LoadedSound(""),
20+
LoadedSound(""),
21+
LoadedSound(""),
22+
LoadedSound(""),
23+
LoadedSound(""),
24+
LoadedSound(""),
25+
};
1826

1927
Error::Error(GameWorld* world, const Vec2d& start_pos, int typeID)
2028
: Entity(world,
@@ -27,14 +35,14 @@ Error::Error(GameWorld* world, const Vec2d& start_pos, int typeID)
2735
false) {
2836

2937
m_Type = static_cast<ErrorType>(typeID);
30-
if (m_Type == SPIKY) m_Texture = ms_TextureErrorSpiky;
31-
else if (m_Type == INVINCIBLE) m_Texture = ms_TextureErrorInvincible;
32-
else if (m_Type == SLOW_DOWN) m_Texture = ms_TextureErrorSlowDown;
33-
else if (m_Type == HEALERS_PARADISE) m_Texture = ms_TextureErrorHealersParadise;
34-
else if (m_Type == DISORIANTED) m_Texture = ms_TextureErrorDisorianted;
35-
else if (m_Type == CONFUSING_HP) m_Texture = ms_TextureErrorConfusingHP;
36-
else if (m_Type == RANGED) m_Texture = ms_TextureErrorRanged;
37-
else m_Texture = ms_TextureError;
38+
if (m_Type == SPIKY) m_Texture = sTextureErrorSpiky.GetTexture();
39+
else if (m_Type == INVINCIBLE) m_Texture = sTextureErrorInvincible.GetTexture();
40+
else if (m_Type == SLOW_DOWN) m_Texture = sTextureErrorSlowDown.GetTexture();
41+
else if (m_Type == HEALERS_PARADISE) m_Texture = sTextureErrorHealersParadise.GetTexture();
42+
else if (m_Type == DISORIANTED) m_Texture = sTextureErrorDisorianted.GetTexture();
43+
else if (m_Type == CONFUSING_HP) m_Texture = sTextureErrorConfusingHP.GetTexture();
44+
else if (m_Type == RANGED) m_Texture = sTextureErrorRanged.GetTexture();
45+
else m_Texture = sTextureErrorDangerousRecoil.GetTexture();
3846
}
3947

4048
void Error::TickPickup(double x, double y) {

‎src/game/entities/Error.h‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ class Error : public Entity {
3131
void TickPickup(double x, double y);
3232

3333
public:
34-
static Sound* ms_HitSound;
35-
static Texture* ms_TextureError;
36-
static Texture* ms_TextureErrorDisorianted;
37-
static Texture* ms_TextureErrorSpiky;
38-
static Texture* ms_TextureErrorConfusingHP;
39-
static Texture* ms_TextureErrorInvincible;
40-
static Texture* ms_TextureErrorHealersParadise;
41-
static Texture* ms_TextureErrorRanged;
42-
static Texture* ms_TextureErrorSlowDown;
43-
static Texture* ms_TextureErrorDangerousRecoil;
44-
static Sound* ms_PickupSounds[7];
34+
static LoadedTexture sTextureErrorDisorianted;
35+
static LoadedTexture sTextureErrorSpiky;
36+
static LoadedTexture sTextureErrorConfusingHP;
37+
static LoadedTexture sTextureErrorInvincible;
38+
static LoadedTexture sTextureErrorHealersParadise;
39+
static LoadedTexture sTextureErrorRanged;
40+
static LoadedTexture sTextureErrorSlowDown;
41+
static LoadedTexture sTextureErrorDangerousRecoil;
42+
static LoadedSound ms_PickupSounds[7];
4543

4644
Error(GameWorld* world, const Vec2d& start_pos, int typeID);
4745

0 commit comments

Comments
 (0)