Skip to content

Commit

Permalink
Library: major codestyle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Nov 4, 2023
1 parent c7b391d commit 09eb8c8
Show file tree
Hide file tree
Showing 43 changed files with 486 additions and 477 deletions.
68 changes: 34 additions & 34 deletions sources/library/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,39 @@ void CApplication::Run()


// if can't obtain directly, find engine functions pointer arrays
m_BuildInfo.Initialize(engineDLL);
g_ClientModule.FindEngfuncs(m_BuildInfo);
g_ServerModule.FindEngfuncs(m_BuildInfo);
m_buildInfo.Initialize(engineDLL);
g_ClientModule.FindEngfuncs(m_buildInfo);
g_ServerModule.FindEngfuncs(m_buildInfo);
g_ServerModule.FindHandle();

InitializeConVars(engineDLL);
SetCurrentDisplayMode();
PrintTitleText();
m_Hooks.Apply();
m_hooks.Apply();

// load configuration file
g_pClientEngfuncs->pfnClientCmd("exec gsm_config.cfg");
}

void CApplication::InitializeDisplayModes()
{
m_pDisplayModes.clear();
m_pDisplayModes.push_back(std::make_shared<CModeFull>());
m_pDisplayModes.push_back(std::make_shared<CModeSpeedometer>());
m_pDisplayModes.push_back(std::make_shared<CModeEntityReport>());
m_pDisplayModes.push_back(std::make_shared<CModeMeasurement>());
m_pDisplayModes.push_back(std::make_shared<CModeFaceReport>());
m_pDisplayModes.push_back(std::make_shared<CModeAngleTracking>());
m_displayModes.clear();
m_displayModes.push_back(std::make_shared<CModeFull>());
m_displayModes.push_back(std::make_shared<CModeSpeedometer>());
m_displayModes.push_back(std::make_shared<CModeEntityReport>());
m_displayModes.push_back(std::make_shared<CModeMeasurement>());
m_displayModes.push_back(std::make_shared<CModeFaceReport>());
m_displayModes.push_back(std::make_shared<CModeAngleTracking>());
}

void CApplication::InitializePrimitivesRenderer()
{
m_pPrimitivesRenderer = std::make_shared<COpenGLPrimitivesRenderer>();
m_primitivesRenderer = std::make_shared<COpenGLPrimitivesRenderer>();
}

void CApplication::HandleChangelevel()
{
for (auto &mode : m_pDisplayModes) {
for (auto &mode : m_displayModes) {
mode->HandleChangelevel();
}
}
Expand Down Expand Up @@ -211,22 +211,22 @@ void CApplication::InitializeConVars(const SysUtils::ModuleInfo &engineLib)

void CApplication::SetCurrentDisplayMode()
{
DisplayModeIndex displayMode = Utils::GetCurrentDisplayMode();
for (auto &mode : m_pDisplayModes)
DisplayModeType displayMode = Utils::GetCurrentDisplayMode();
for (auto &mode : m_displayModes)
{
if (mode->GetModeIndex() == displayMode)
{
m_pCurrentDisplayMode = mode;
m_currentDisplayMode = mode;
return;
}
}
m_pCurrentDisplayMode = m_pDisplayModes[0];
m_currentDisplayMode = m_displayModes[0];
}

void CApplication::UpdateScreenInfo()
{
m_ScreenInfo.iSize = sizeof(m_ScreenInfo);
g_pClientEngfuncs->pfnGetScreenInfo(&m_ScreenInfo);
m_screenInfo.iSize = sizeof(m_screenInfo);
g_pClientEngfuncs->pfnGetScreenInfo(&m_screenInfo);
}

// should be updated only once in frame
Expand All @@ -238,17 +238,17 @@ void CApplication::UpdateSmoothFrametime()
const float k = 0.24f;
const float diffThreshold = 0.13f;
float currentTime = g_pClientEngfuncs->GetClientTime();
float timeDelta = currentTime - m_flLastClientTime;
float timeDelta = currentTime - m_lastClientTime;

if ((timeDelta - m_flLastFrameTime) > diffThreshold)
timeDelta = m_flLastFrameTime;
if ((timeDelta - m_lastFrameTime) > diffThreshold)
timeDelta = m_lastFrameTime;

m_flFrameTime += (timeDelta - m_flFrameTime) * k;
m_flLastFrameTime = m_flFrameTime;
m_flLastClientTime = currentTime;
m_frameTime += (timeDelta - m_frameTime) * k;
m_lastFrameTime = m_frameTime;
m_lastClientTime = currentTime;
#elif defined(FILTER_AVG_SIMPLE)
float currentTime = g_pClientEngfuncs->GetClientTime();
float timeDelta = currentTime - m_flLastClientTime;
float timeDelta = currentTime - m_lastClientTime;
static float buffer[FILTER_SIZE];
double sum = 0.0;

Expand All @@ -261,13 +261,13 @@ void CApplication::UpdateSmoothFrametime()
sum += buffer[i];
}

m_flLastClientTime = currentTime;
m_flFrameTime = sum / (double)FILTER_SIZE;
m_lastClientTime = currentTime;
m_frameTime = sum / (double)FILTER_SIZE;
#else
float currentTime = g_pClientEngfuncs->GetClientTime();
float timeDelta = currentTime - m_flLastClientTime;
m_flFrameTime = timeDelta;
m_flLastClientTime = currentTime;
float timeDelta = currentTime - m_lastClientTime;
m_frameTime = timeDelta;
m_lastClientTime = currentTime;
#endif
}

Expand All @@ -276,16 +276,16 @@ void CApplication::DisplayModeRender2D()
SetCurrentDisplayMode();
UpdateSmoothFrametime();
UpdateScreenInfo();
m_pCurrentDisplayMode->Render2D(m_flFrameTime, m_ScreenInfo.iWidth, m_ScreenInfo.iHeight, m_StringStack);
m_currentDisplayMode->Render2D(m_frameTime, m_screenInfo.iWidth, m_screenInfo.iHeight, m_stringStack);
}

void CApplication::DisplayModeRender3D()
{
SetCurrentDisplayMode();
m_pCurrentDisplayMode->Render3D();
m_currentDisplayMode->Render3D();
}

bool CApplication::KeyInput(int keyDown, int keyCode, const char *bindName)
{
return m_pCurrentDisplayMode->KeyInput(keyDown != 0, keyCode, bindName);
return m_currentDisplayMode->KeyInput(keyDown != 0, keyCode, bindName);
}
24 changes: 12 additions & 12 deletions sources/library/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class CApplication
void DisplayModeRender3D();
void HandleChangelevel();
bool KeyInput(int keyDown, int keyCode, const char *bindName);
inline const SCREENINFO& GetScreenInfo() const { return m_ScreenInfo; };
inline auto GetRenderer() const { return m_pPrimitivesRenderer; };
const SCREENINFO& GetScreenInfo() const { return m_screenInfo; };
auto GetRenderer() const { return m_primitivesRenderer; };

private:
CApplication() {
Expand All @@ -55,15 +55,15 @@ class CApplication
void UpdateScreenInfo();
void UpdateSmoothFrametime();

float m_flFrameTime;
float m_flLastFrameTime;
float m_flLastClientTime;
CHooks m_Hooks;
CBuildInfo m_BuildInfo;
SCREENINFO m_ScreenInfo = { 0 };
CStringStack m_StringStack = CStringStack(128);
std::shared_ptr<IDisplayMode> m_pCurrentDisplayMode = nullptr;
std::shared_ptr<IPrimitivesRenderer> m_pPrimitivesRenderer = nullptr;
std::vector<std::shared_ptr<IDisplayMode>> m_pDisplayModes;
float m_frameTime;
float m_lastFrameTime;
float m_lastClientTime;
CHooks m_hooks;
CBuildInfo m_buildInfo;
SCREENINFO m_screenInfo = { 0 };
CStringStack m_stringStack = CStringStack(128);
std::shared_ptr<IDisplayMode> m_currentDisplayMode = nullptr;
std::shared_ptr<IPrimitivesRenderer> m_primitivesRenderer = nullptr;
std::vector<std::shared_ptr<IDisplayMode>> m_displayModes;
};
extern CApplication &g_Application;
66 changes: 33 additions & 33 deletions sources/library/bounding_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ CBoundingBox::CBoundingBox(const vec3_t &vecMins, const vec3_t &vecMaxs)

vec3_t CBoundingBox::GetCenterPoint() const
{
return m_vecMins + m_vecSize / 2;
return m_mins + m_size / 2;
}

void CBoundingBox::SetCenterToPoint(const vec3_t &point)
{
Initialize(point - m_vecSize / 2, point + m_vecSize / 2);
Initialize(point - m_size / 2, point + m_size / 2);
}

CBoundingBox CBoundingBox::GetUnion(const CBoundingBox &operand) const
{
CBoundingBox currentBoxCopy(m_vecMins, m_vecMaxs);
CBoundingBox currentBoxCopy(m_mins, m_maxs);
currentBoxCopy.CombineWith(operand);
return currentBoxCopy;
}
Expand All @@ -46,8 +46,8 @@ void CBoundingBox::CombineWith(const CBoundingBox &operand)
{
vec3_t unionMins;
vec3_t unionMaxs;
const vec3_t &currMins = m_vecMins;
const vec3_t &currMaxs = m_vecMaxs;
const vec3_t &currMins = m_mins;
const vec3_t &currMaxs = m_maxs;
const vec3_t &operandMins = operand.GetMins();
const vec3_t &operandMaxs = operand.GetMaxs();

Expand All @@ -64,64 +64,64 @@ void CBoundingBox::CombineWith(const CBoundingBox &operand)

void CBoundingBox::ExpandToPoint(const vec3_t &point)
{
if (point.x < m_vecMins.x)
m_vecMins.x = point.x;
if (point.y < m_vecMins.y)
m_vecMins.y = point.y;
if (point.z < m_vecMins.z)
m_vecMins.z = point.z;

if (point.x > m_vecMaxs.x)
m_vecMaxs.x = point.x;
if (point.y > m_vecMaxs.y)
m_vecMaxs.y = point.y;
if (point.z > m_vecMaxs.z)
m_vecMaxs.z = point.z;

Initialize(m_vecMins, m_vecMaxs);
if (point.x < m_mins.x)
m_mins.x = point.x;
if (point.y < m_mins.y)
m_mins.y = point.y;
if (point.z < m_mins.z)
m_mins.z = point.z;

if (point.x > m_maxs.x)
m_maxs.x = point.x;
if (point.y > m_maxs.y)
m_maxs.y = point.y;
if (point.z > m_maxs.z)
m_maxs.z = point.z;

Initialize(m_mins, m_maxs);
}

bool CBoundingBox::Contains(const CBoundingBox &operand) const
{
const vec3_t &mins = operand.GetMins();
const vec3_t &maxs = operand.GetMaxs();

if (mins.x < m_vecMins.x || mins.x > m_vecMaxs.x)
if (mins.x < m_mins.x || mins.x > m_maxs.x)
return false;
if (mins.y < m_vecMins.y || mins.y > m_vecMaxs.y)
if (mins.y < m_mins.y || mins.y > m_maxs.y)
return false;
if (mins.z < m_vecMins.z || mins.z > m_vecMaxs.z)
if (mins.z < m_mins.z || mins.z > m_maxs.z)
return false;

if (maxs.x < m_vecMins.x || maxs.x > m_vecMaxs.x)
if (maxs.x < m_mins.x || maxs.x > m_maxs.x)
return false;
if (maxs.y < m_vecMins.y || maxs.y > m_vecMaxs.y)
if (maxs.y < m_mins.y || maxs.y > m_maxs.y)
return false;
if (maxs.z < m_vecMins.z || maxs.z > m_vecMaxs.z)
if (maxs.z < m_mins.z || maxs.z > m_maxs.z)
return false;

return true;
}

bool CBoundingBox::ContainsPoint(const vec3_t &point) const
{
if (point.x < m_vecMins.x || point.x > m_vecMaxs.x)
if (point.x < m_mins.x || point.x > m_maxs.x)
return false;
if (point.y < m_vecMins.y || point.y > m_vecMaxs.y)
if (point.y < m_mins.y || point.y > m_maxs.y)
return false;
if (point.z < m_vecMins.z || point.z > m_vecMaxs.z)
if (point.z < m_mins.z || point.z > m_maxs.z)
return false;
return true;
}

double CBoundingBox::GetSurfaceArea() const
{
return 2.0 * (m_vecSize.x * m_vecSize.y + m_vecSize.y * m_vecSize.z + m_vecSize.x * m_vecSize.z);
return 2.0 * (m_size.x * m_size.y + m_size.y * m_size.z + m_size.x * m_size.z);
}

void CBoundingBox::Initialize(const vec3_t &vecMins, const vec3_t &vecMaxs)
{
m_vecMins = vecMins;
m_vecMaxs = vecMaxs;
m_vecSize = vecMaxs - vecMins;
m_mins = vecMins;
m_maxs = vecMaxs;
m_size = vecMaxs - vecMins;
}
12 changes: 6 additions & 6 deletions sources/library/bounding_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class CBoundingBox
bool Contains(const CBoundingBox &operand) const;
bool ContainsPoint(const vec3_t &point) const;

inline const vec3_t &GetSize() const { return m_vecSize; };
inline const vec3_t &GetMins() const { return m_vecMins; };
inline const vec3_t &GetMaxs() const { return m_vecMaxs; };
const vec3_t &GetSize() const { return m_size; };
const vec3_t &GetMins() const { return m_mins; };
const vec3_t &GetMaxs() const { return m_maxs; };

private:
void Initialize(const vec3_t &vecMins, const vec3_t &vecMaxs);

vec3_t m_vecMins = vec3_t(0, 0, 0);
vec3_t m_vecMaxs = vec3_t(0, 0, 0);
vec3_t m_vecSize = vec3_t(0, 0, 0);
vec3_t m_mins = vec3_t(0, 0, 0);
vec3_t m_maxs = vec3_t(0, 0, 0);
vec3_t m_size = vec3_t(0, 0, 0);
};
1 change: 1 addition & 0 deletions sources/library/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CBuildInfo
PrecacheSound,
Count, // keep this last
};
static const size_t k_functionsCount = static_cast<size_t>(FunctionType::Count);

CBuildInfo();
~CBuildInfo();
Expand Down
4 changes: 2 additions & 2 deletions sources/library/build_info_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ GNU General Public License for more details.

bool CBuildInfo::Entry::Validate() const
{
if (m_iClientEngfuncsOffset > 0) {
if (m_clientEngfuncsOffset > 0) {
return true;
}

for (size_t i = 0; i < static_cast<size_t>(FunctionType::PrecacheModel); ++i) // check only client-side functions
{
const CMemoryPattern &pattern = m_FunctionPatterns[i];
const CMemoryPattern &pattern = m_functionPatterns[i];
if (!pattern.IsInitialized()) {
return false;
}
Expand Down
Loading

0 comments on commit 09eb8c8

Please sign in to comment.