Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 7e9acae

Browse files
committed
Fix several compiler warnings
1 parent 2e5c64d commit 7e9acae

File tree

20 files changed

+101
-52
lines changed

20 files changed

+101
-52
lines changed

src/libs/animation/src/animation_imp.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void AnimationImp::BuildAnimationMatrices()
240240

241241
// Auto normalization
242242
if (normBlend != 0.0f)
243+
{
243244
if (plCnt > 1)
244245
{
245246
normBlend = 1.0f / normBlend;
@@ -381,6 +382,7 @@ void AnimationImp::BuildAnimationMatrices()
381382
// for(int32_t j = 0; j < nbones; j++)
382383
// aniInfo->GetBone(j).BlendFrame(frame);
383384
}
385+
}
384386
for (int32_t j = 0; j < nbones; j++)
385387
{
386388
auto &bn = aniInfo->GetBone(j);

src/libs/battle_interface/src/battle_command.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ void BICommandList::Init()
272272
sscanf(pAList->GetAttribute("CommandNoteOffset"), "%d,%d", &m_NoteOffset.x, &m_NoteOffset.y);
273273

274274
// Setting values for arrows (up / down)
275-
if (attr = pAList->GetAttribute("UDArrow_Texture"))
275+
attr = pAList->GetAttribute("UDArrow_Texture");
276+
if (attr)
276277
m_sUpDownArrowTexture = attr;
277278
BIUtils::ReadRectFromAttr(pAList, "UDArrow_UV_Up", m_frUpArrowUV, m_frUpArrowUV);
278279
BIUtils::ReadRectFromAttr(pAList, "UDArrow_UV_Down", m_frDownArrowUV, m_frDownArrowUV);
@@ -283,7 +284,8 @@ void BICommandList::Init()
283284
BIUtils::ReadPosFromAttr(pAList, "UDArrow_Offset_Down", m_pntDownArrowOffset.x, m_pntDownArrowOffset.y,
284285
m_pntDownArrowOffset.x, m_pntDownArrowOffset.y);
285286

286-
if (attr = pAList->GetAttribute("LRArrow_Texture"))
287+
attr = pAList->GetAttribute("LRArrow_Texture");
288+
if (attr)
287289
m_sLeftRightArrowTexture = attr;
288290
BIUtils::ReadRectFromAttr(pAList, "LRArrow_UV_Left", m_frLeftArrowUV, m_frLeftArrowUV);
289291
BIUtils::ReadRectFromAttr(pAList, "LRArrow_UV_Right", m_frRightArrowUV, m_frRightArrowUV);
@@ -295,15 +297,17 @@ void BICommandList::Init()
295297
m_pntRightArrowOffset.x, m_pntRightArrowOffset.y);
296298

297299
// set values for the menu activity icon
298-
if (attr = pAList->GetAttribute("ActiveIcon_Texture"))
300+
attr = pAList->GetAttribute("ActiveIcon_Texture");
301+
if (attr)
299302
m_sActiveIconTexture = attr;
300303
BIUtils::ReadPosFromAttr(pAList, "ActiveIcon_Offset", m_pntActiveIconOffset.x, m_pntActiveIconOffset.y,
301304
m_pntActiveIconOffset.x, m_pntActiveIconOffset.y);
302305
BIUtils::ReadPosFromAttr(pAList, "ActiveIcon_Size", m_pntActiveIconSize.x, m_pntActiveIconSize.y,
303306
m_pntActiveIconSize.x, m_pntActiveIconSize.y);
304307
BIUtils::ReadRectFromAttr(pAList, "ActiveIcon_UV1", m_frActiveIconUV1, m_frActiveIconUV1);
305308
BIUtils::ReadRectFromAttr(pAList, "ActiveIcon_UV2", m_frActiveIconUV2, m_frActiveIconUV2);
306-
if (attr = pAList->GetAttribute("ActiveIcon_Note"))
309+
attr = pAList->GetAttribute("ActiveIcon_Note");
310+
if (attr)
307311
m_sActiveIconNote = attr;
308312
}
309313

src/libs/battle_interface/src/battle_sign.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ void BISignIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA)
164164

165165
pcTmp = pA->GetAttribute("fontoffset");
166166
if (pcTmp)
167-
sscanf(pcTmp, "%ld,%ld", &m_SignTextFontOffset.x, &m_SignTextFontOffset.y);
167+
{
168+
long x{}, y{};
169+
sscanf(pcTmp, "%ld,%ld", &x, &y);
170+
m_SignTextFontOffset.x = x;
171+
m_SignTextFontOffset.y = y;
172+
}
168173

169174
pcTmp = pA->GetAttribute("backtexturename");
170175
if (pcTmp)

src/libs/battle_interface/src/item_entity/item_entity.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ bool ItemEntity::Init()
2626
void ItemEntity::Realize(uint32_t delta_time)
2727
{
2828
if (m_bVisible && m_pModel)
29+
{
2930
if (m_bTieToLocator)
31+
{
3032
DrawIntoLocator();
33+
}
3134
else
35+
{
3236
m_pModel->ProcessStage(Stage::realize, delta_time);
37+
}
38+
}
3339
}
3440

3541
uint64_t ItemEntity::ProcessMessage(MESSAGE &message)
@@ -107,7 +113,8 @@ bool ItemEntity::ReadAndCreate()
107113
auto *const pcTechnique = BIUtils::GetStringFromAttr(AttributesPointer, "technique", "");
108114
if (pcModelName)
109115
{
110-
if (m_eidModel = core.CreateEntity("modelr"))
116+
m_eidModel = core.CreateEntity("modelr");
117+
if (m_eidModel)
111118
{
112119
core.Send_Message(m_eidModel, "ls", MSG_MODEL_LOAD_GEO, pcModelName);
113120
m_pModel = static_cast<MODEL *>(core.GetEntityPointer(m_eidModel));

src/libs/battle_interface/src/sea/battle_ship_sign.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA)
195195
// ugeen 150920
196196
pcTmp = pA->GetAttribute("sailorfontoffset");
197197
if (pcTmp)
198-
sscanf(pcTmp, "%ld,%ld", &m_SailorFontOffset.x, &m_SailorFontOffset.y);
198+
{
199+
long x{}, y{};
200+
sscanf(pcTmp, "%ld,%ld", &x, &y);
201+
m_SailorFontOffset.x = x;
202+
m_SailorFontOffset.y = y;
203+
}
199204

200205
pcTmp = pA->GetAttribute("shipnamefontid");
201206
if (pcTmp)
@@ -205,7 +210,12 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA)
205210

206211
pcTmp = pA->GetAttribute("shipnamefontoffset");
207212
if (pcTmp)
208-
sscanf(pcTmp, "%ld,%ld", &m_ShipNameFontOffset.x, &m_ShipNameFontOffset.y);
213+
{
214+
long x{}, y{};
215+
sscanf(pcTmp, "%ld,%ld", &x, &y);
216+
m_ShipNameFontOffset.x = x;
217+
m_ShipNameFontOffset.y = y;
218+
}
209219

210220
pcTmp = pA->GetAttribute("backtexturename");
211221
if (pcTmp)

src/libs/battle_interface/src/sea/island_descr.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ void ISLAND_DESCRIBER::SetIsland(ATTRIBUTES *pAIsland)
6565
{
6666
int32_t lTmp;
6767
if (pvdat->Get(lTmp, 0))
68+
{
6869
if (lTmp == 0)
6970
m_pLocators[i].locatorType = ISLAND_LOCATOR_LAND;
7071
else if (lTmp == 1)
7172
m_pLocators[i].locatorType = ISLAND_LOCATOR_FORT;
7273
else
7374
m_pLocators[i].locatorType = ISLAND_LOCATOR_TOWN;
75+
}
7476
if (pvdat->Get(lTmp, 1))
7577
m_pLocators[i].relation = lTmp;
7678
if (pvdat->Get(lTmp, 2))

src/libs/blot/src/blots.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ uint64_t Blots::ProcessMessage(MESSAGE &message)
7676
if (pCharAttributeRoot)
7777
{
7878
blotsInfo = pCharAttributeRoot->CreateSubAClass(pCharAttributeRoot, "ship.blots");
79-
char buf[32];
80-
sprintf_s(buf, "%i", BLOTS_MAX);
81-
blotsInfo->SetValue(buf);
79+
blotsInfo->SetValue(std::to_string(BLOTS_MAX));
8280
for (int32_t i = 0; i < BLOTS_MAX; i++)
8381
LoadBlot(i);
8482
}

src/libs/core/src/core_impl.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
class CoreImpl final : public CorePrivate
1414
{
1515
public:
16-
void Init();
16+
void Init() override;
1717

18-
void InitBase();
19-
void ReleaseBase();
18+
void InitBase() override;
19+
void ReleaseBase() override;
2020

21-
void CleanUp();
21+
void CleanUp() override;
2222

2323
void SetWindow(std::shared_ptr<storm::OSWindow> window) override;
2424
bool Initialize();
2525
void ResetCore();
26-
bool Run();
26+
bool Run() override;
2727
bool LoadClassesTable();
2828

2929
void ProcessExecute();
@@ -43,7 +43,7 @@ class CoreImpl final : public CorePrivate
4343
void EraseEntities();
4444
void ClearEvents();
4545
void *MakeClass(const char *class_name);
46-
void AppState(bool state);
46+
void AppState(bool state) override;
4747
uint32_t MakeHashValue(const char *string);
4848
VMA *FindVMA(const char *class_name);
4949
VMA *FindVMA(int32_t hash);
@@ -133,9 +133,9 @@ class CoreImpl final : public CorePrivate
133133
bool IsLayerFrozen(layer_index_t index) const override;
134134
void ForEachEntity(const std::function<void(entptr_t)>& f) override;
135135

136-
void collectCrashInfo() const;
136+
void collectCrashInfo() const override;
137137

138-
[[nodiscard]] bool initialized() const
138+
[[nodiscard]] bool initialized() const override
139139
{
140140
return Initialized;
141141
}

src/libs/core/src/data.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ void DATA::Set(const char *attribute_name, const char *attribute_value)
402402
return;
403403
}
404404

405-
AttributesClass = new ATTRIBUTES(pVCompiler->GetVSC());
405+
AttributesClass = new ATTRIBUTES(*pVCompiler->GetVSC());
406406
}
407-
AttributesClass->SetAttribute(attribute_name, attribute_value);
407+
AttributesClass->SetAttribute(std::string_view(attribute_name), std::string_view(attribute_value));
408408
// Attributes.SetAttribute(attribute_name,attribute_value);
409409
}
410410

@@ -2357,7 +2357,7 @@ ATTRIBUTES *DATA::GetAClass()
23572357
return nullptr;
23582358
}
23592359

2360-
AttributesClass = new ATTRIBUTES(pVCompiler->GetVSC());
2360+
AttributesClass = new ATTRIBUTES(*pVCompiler->GetVSC());
23612361
}
23622362
return AttributesClass;
23632363
}

src/libs/core/src/message.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#pragma once
2-
31
#include "message.h"
42

53
#include <algorithm>

src/libs/island/src/island.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "tga.h"
1010
#include <cstdio>
1111

12+
using storm::Sqr;
13+
1214
CREATE_CLASS(ISLAND)
1315

1416
CREATE_CLASS(CoastFoam)

src/libs/math/include/math3d.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ inline float sqrf(float f)
9494
// Random number
9595
inline float Rnd(float max = 1.0f)
9696
{
97-
return rand() * (max * (1.0f / RAND_MAX));
97+
return storm::RandomFloat(max);
9898
}
9999

100100
// Random number
101101
inline float RRnd(float min, float max)
102102
{
103-
return min + rand() * ((max - min) * (1.0f / RAND_MAX));
103+
return min + storm::RandomFloat(max - min);
104104
}
105105

106106
// Limit float

src/libs/math/include/math3d/vector.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
#pragma once
88

9-
#include <math.h>
10-
#include <stdlib.h>
9+
#include "../math_common.hpp"
10+
11+
#include <cstdlib>
1112

1213
#pragma pack(push, 1)
1314

@@ -1042,32 +1043,32 @@ inline Vector &Vector::Reflection(const Vector &normal)
10421043
// Fill with a unit vector with a random direction
10431044
inline Vector &Vector::Rand()
10441045
{
1045-
Make2D(rand() * ((2.0f * 3.141592654f) / RAND_MAX));
1046+
Make2D(storm::RandomFloat(2.0f * 3.141592654f));
10461047
y = z;
10471048
z = 0.0f;
1048-
return Rotate(rand() * ((2.0f * 3.141592654f) / RAND_MAX));
1049+
return Rotate(storm::RandomFloat(2.0f * 3.141592654f));
10491050
}
10501051

10511052
// Fill with unit vector with random direction in XZ
10521053
inline Vector &Vector::Rand2D()
10531054
{
1054-
return Make2D(rand() * ((2.0f * 3.141592654f) / RAND_MAX));
1055+
return Make2D(storm::RandomFloat(2.0f * 3.141592654f));
10551056
}
10561057

10571058
// Fill with random values in a given ABB
10581059
inline Vector &Vector::Rand(const Vector &min, const Vector &max)
10591060
{
1060-
x = min.x + rand() * ((max.x - min.x) * (1.0f / RAND_MAX));
1061-
y = min.y + rand() * ((max.y - min.y) * (1.0f / RAND_MAX));
1062-
z = min.z + rand() * ((max.z - min.z) * (1.0f / RAND_MAX));
1061+
x = min.x + storm::RandomFloat(max.x - min.x);
1062+
x = min.y + storm::RandomFloat(max.y - min.y);
1063+
x = min.z + storm::RandomFloat(max.z - min.z);
10631064
return *this;
10641065
}
10651066

10661067
// Fill with random values in a given sphere
10671068
inline Vector &Vector::Rand(const Vector &pos, float radius)
10681069
{
10691070
Rand();
1070-
*this *= rand() * (radius * (1.0f / RAND_MAX));
1071+
*this *= storm::RandomFloat(radius);
10711072
return *this;
10721073
}
10731074

src/libs/math/include/math_common.hpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include <cmath>
4+
5+
#ifdef SQR
6+
#undef SQR
7+
#endif
8+
9+
#define SQR(x) ::storm::Sqr(x)
10+
#define FRAND(x) ::storm::RandomFloat(x)
11+
12+
namespace storm {
13+
14+
constexpr const float kRandMaxFloat = static_cast<float>(RAND_MAX);
15+
16+
inline float RandomFloat(const float x) {
17+
return x * static_cast<float>(rand()) / storm::kRandMaxFloat;
18+
}
19+
20+
template<typename T>
21+
inline T Sqr(const T x) {
22+
return x * x;
23+
}
24+
25+
} // namespace storm

src/libs/math/include/math_inlines.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma once
22

3+
#include "math_common.hpp"
4+
35
#include <cstdint>
46
#include <cmath>
57

68
#include <xmmintrin.h>
79

810
#include "c_vector.h"
911

10-
#define SQR(a) ((a) * (a))
11-
#define FRAND(x) ((x) * (float)rand() / (float)RAND_MAX)
1212
#define SIGN(x) ((x) < 0 ? -1.0f : 1.0f)
1313
#define SIGNZ(x) ((x) == 0.0f ? 0.0f : ((x) < 0.0f ? -1.0f : 1.0f))
1414
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
@@ -63,11 +63,6 @@ template <class T> T Max(T t1, T t2)
6363
return ((t1 > t2) ? t1 : t2);
6464
};
6565

66-
template <class T> T Sqr(T t1)
67-
{
68-
return (t1 * t1);
69-
};
70-
7166
constexpr float PI = 3.14159265358979323846f;
7267
constexpr float PIm2 = (PI * 2.0f);
7368
constexpr float PId2 = (PI / 2.0f);

src/libs/math/include/types3d.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#pragma once
22

3+
#include "math_common.hpp"
4+
35
#pragma pack(push)
46
#pragma pack(1)
57

6-
#ifdef SQR
7-
#undef SQR
8-
#endif
9-
10-
#define SQR(x) ((x) * (x))
11-
128
typedef struct
139
{
1410
float x;

src/libs/sea/src/sea.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "tga.h"
1313
#include "v_file_service.h"
1414

15+
using storm::Sqr;
16+
1517
CREATE_CLASS(SEA)
1618

1719
//#define OLD_WORLD_POS

src/libs/sea_ai/src/ai_balls.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "math_inlines.h"
44
#include "shared/messages.h"
55

6+
using storm::Sqr;
7+
68
AIBalls *AIBalls::pAIBalls = nullptr;
79

810
AIBalls::AIBalls()

src/libs/util/include/utf8.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ inline int Utf8ToCodepoint(const char *utf8)
114114
if (u0 >= 0xC0 && u0 <= 0xDF)
115115
return (u0 - 192) * 64 + (u1 - 128);
116116

117-
if (utf8[0] == 0xed && (utf8[1] & 0xa0) == 0xa0)
117+
if (u0 == 0xed && (u1 & 0xa0) == 0xa0)
118118
return -1; // code points, 0xd800 to 0xdfff
119119

120120
if (l < 3)

0 commit comments

Comments
 (0)