Skip to content

Commit

Permalink
core: run clang-format over all files
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmuffin committed Oct 11, 2023
1 parent 71b0961 commit 2f4ab6e
Show file tree
Hide file tree
Showing 30 changed files with 861 additions and 1,336 deletions.
25 changes: 7 additions & 18 deletions src/core/engine_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@

#include "core/log.h"

namespace counterstrikesharp
{
namespace counterstrikesharp {

CTraceFilterHitAll g_HitAllFilter;

bool CSimpleTraceFilter::ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask)
{
bool CSimpleTraceFilter::ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask) {
// int index = ExcIndexFromBaseHandle(pServerEntity->GetRefEHandle());
// if (index == m_index_to_exclude)
// return false;

return true;
}

TraceType_t TraceFilterProxy::GetTraceType() const
{

TraceType_t TraceFilterProxy::GetTraceType() const {
auto nativeContext = fxNativeContext{};
auto scriptContext = ScriptContextRaw(nativeContext);

Expand All @@ -43,8 +39,7 @@ TraceType_t TraceFilterProxy::GetTraceType() const
return scriptContext.GetResult<TraceType_t>();
}

bool TraceFilterProxy::ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask)
{
bool TraceFilterProxy::ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask) {
return true;
// auto entity = ExcIndexFromBaseHandle(pServerEntity->GetRefEHandle());
// if (entity < 0)
Expand All @@ -67,14 +62,8 @@ bool TraceFilterProxy::ShouldHitEntity(IHandleEntity *pServerEntity, int content
return true;*/
}

void TraceFilterProxy::SetShouldHitEntityCallback(CallbackT cb)
{
m_cb_should_hit_entity = cb;
}
void TraceFilterProxy::SetShouldHitEntityCallback(CallbackT cb) { m_cb_should_hit_entity = cb; }

void TraceFilterProxy::SetGetTraceTypeCallback(CallbackT cb)
{
m_cb_get_trace_type = cb;
}
void TraceFilterProxy::SetGetTraceTypeCallback(CallbackT cb) { m_cb_get_trace_type = cb; }

} // namespace counterstrikesharp
} // namespace counterstrikesharp
39 changes: 13 additions & 26 deletions src/core/engine_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,33 @@

#include "scripting/callback_manager.h"

namespace counterstrikesharp
{
class TraceFilterProxy : public ITraceFilter
{
public:
TraceFilterProxy()
{
}
namespace counterstrikesharp {
class TraceFilterProxy : public ITraceFilter {
public:
TraceFilterProxy() {}
bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask);
TraceType_t GetTraceType() const;

void SetShouldHitEntityCallback(CallbackT cb);
void SetGetTraceTypeCallback(CallbackT cb);

private:
private:
CallbackT m_cb_should_hit_entity;
CallbackT m_cb_get_trace_type;
};

class CSimpleTraceFilter : public ITraceFilter
{
public:
CSimpleTraceFilter(int index) : m_index_to_exclude(index)
{
}
class CSimpleTraceFilter : public ITraceFilter {
public:
CSimpleTraceFilter(int index)
: m_index_to_exclude(index) {}
bool ShouldHitEntity(IHandleEntity *pServerEntity, int contentsMask);

TraceType_t GetTraceType() const
{
return TRACE_EVERYTHING;
}
TraceType_t GetTraceType() const { return TRACE_EVERYTHING; }

private:
private:
int m_index_to_exclude = -1;
};

enum RayType
{
RayType_EndPoint,
RayType_Infinite
};
enum RayType { RayType_EndPoint, RayType_Infinite };

} // namespace counterstrikesharp
} // namespace counterstrikesharp
54 changes: 19 additions & 35 deletions src/core/global_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,34 @@

#pragma once

namespace counterstrikesharp
{
class GlobalClass
{
public:
namespace counterstrikesharp {
class GlobalClass {
public:
virtual ~GlobalClass() = default;

GlobalClass()
{
GlobalClass() {
m_pGlobalClassNext = GlobalClass::head;
GlobalClass::head = this;
}

public:
virtual void OnStartup()
{
}
virtual void OnShutdown()
{
}
virtual void OnAllInitialized()
{
}
virtual void OnAllInitialized_Post()
{
}
virtual void OnLevelChange(const char *mapName)
{
}
virtual void OnLevelEnd()
{
}
public:
virtual void OnStartup() {}
virtual void OnShutdown() {}
virtual void OnAllInitialized() {}
virtual void OnAllInitialized_Post() {}
virtual void OnLevelChange(const char *mapName) {}
virtual void OnLevelEnd() {}

public:
public:
GlobalClass *m_pGlobalClassNext;
static GlobalClass *head;
};
} // namespace counterstrikesharp
} // namespace counterstrikesharp

#define CALL_GLOBAL_LISTENER(func) \
GlobalClass *pBase = GlobalClass::head; \
pBase = GlobalClass::head; \
while (pBase) \
{ \
pBase->func; \
pBase = pBase->m_pGlobalClassNext; \
#define CALL_GLOBAL_LISTENER(func) \
GlobalClass *pBase = GlobalClass::head; \
pBase = GlobalClass::head; \
while (pBase) { \
pBase->func; \
pBase = pBase->m_pGlobalClassNext; \
}
21 changes: 8 additions & 13 deletions src/core/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
#include "utils/virtual.h"
#include <public/game/server/iplayerinfo.h>

namespace counterstrikesharp
{
namespace counterstrikesharp {

namespace globals
{
namespace globals {
IVEngineServer *engine = nullptr;
IGameEventManager2 *gameEventManager = nullptr;
IGameEventSystem *gameEventSystem = nullptr;
Expand Down Expand Up @@ -47,31 +45,28 @@ CGlobalEntityList *globalEntityList = nullptr;
CounterStrikeSharpMMPlugin *mmPlugin = nullptr;
SourceHook::Impl::CSourceHookImpl source_hook_impl;
SourceHook::ISourceHook *source_hook = &source_hook_impl;
ISmmAPI* ismm = nullptr;
ISmmAPI *ismm = nullptr;

// Custom Managers
CallbackManager callbackManager;
EventManager eventManager;
PlayerManager playerManager;
TimerSystem timerSystem;

void Initialize()
{
void Initialize() {
gameEventManager = (IGameEventManager2 *)(CALL_VIRTUAL(uintptr_t, 91, server) - 8);

CSSHARP_CORE_TRACE("[GLOBALS] globals::gameEventManager: {0}", (void *)gameEventManager);
}

int source_hook_pluginid = 0;
CGlobalVars *getGlobalVars()
{
CGlobalVars *getGlobalVars() {
INetworkGameServer *server = networkServerService->GetIGameServer();

if (!server)
return nullptr;
if (!server) return nullptr;

return networkServerService->GetIGameServer()->GetGlobals();
}

} // namespace globals
} // namespace counterstrikesharp
} // namespace globals
} // namespace counterstrikesharp
10 changes: 4 additions & 6 deletions src/core/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class ICvar;
class IGameEventSystem;
class CounterStrikeSharpMMPlugin;

namespace counterstrikesharp
{
namespace counterstrikesharp {
class EntityListener;
class EventManager;
class UserMessageManager;
Expand All @@ -41,8 +40,7 @@ class TimerSystem;
class ChatCommands;
class HookManager;

namespace globals
{
namespace globals {

extern IVEngineServer *engine;
extern IGameEventManager2 *gameEventManager;
Expand Down Expand Up @@ -90,9 +88,9 @@ void Initialize();
// and active) otherwise that'll be nullptr!
CGlobalVars *getGlobalVars();

} // namespace globals
} // namespace globals

} // namespace counterstrikesharp
} // namespace counterstrikesharp

#undef SH_GLOB_SHPTR
#define SH_GLOB_SHPTR counterstrikesharp::globals::source_hook
Expand Down
15 changes: 6 additions & 9 deletions src/core/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>

namespace counterstrikesharp
{
namespace counterstrikesharp {
std::shared_ptr<spdlog::logger> Log::m_core_logger;

void Log::Init()
{
void Log::Init() {
std::vector<spdlog::sink_ptr> logSinks;
auto ansiColorSink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_mt>();
ansiColorSink->set_color(spdlog::level::trace, ansiColorSink->yellow);
logSinks.emplace_back(ansiColorSink);
logSinks.emplace_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("counterstrikesharp.log", true));
logSinks.emplace_back(
std::make_shared<spdlog::sinks::basic_file_sink_mt>("counterstrikesharp.log", true));

logSinks[0]->set_pattern("%^[%T.%e] %n: %v%$");
logSinks[1]->set_pattern("[%T.%e] [%l] %n: %v");


m_core_logger = std::make_shared<spdlog::logger>("CSSharp", begin(logSinks), end(logSinks));
spdlog::register_logger(m_core_logger);
m_core_logger->set_level(spdlog::level::trace);
m_core_logger->flush_on(spdlog::level::info);
}

void Log::Close()
{
void Log::Close() {
spdlog::drop("CSSharp");
m_core_logger = nullptr;
}
} // namespace counterstrikesharp
} // namespace counterstrikesharp
17 changes: 6 additions & 11 deletions src/core/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
#include <spdlog/fmt/ostr.h>
#include <spdlog/spdlog.h>

namespace counterstrikesharp
{
class Log
{
public:
namespace counterstrikesharp {
class Log {
public:
static void Init();
static void Close();

static std::shared_ptr<spdlog::logger> &GetCoreLogger()
{
return m_core_logger;
}
static std::shared_ptr<spdlog::logger> &GetCoreLogger() { return m_core_logger; }

private:
private:
static std::shared_ptr<spdlog::logger> m_core_logger;
};
} // namespace counterstrikesharp
} // namespace counterstrikesharp

#define CSSHARP_CORE_TRACE(...) ::counterstrikesharp::Log::GetCoreLogger()->trace(__VA_ARGS__)
#define CSSHARP_CORE_DEBUG(...) _ ::counterstrikesharp::Log::GetCoreLogger()->debug(__VA_ARGS__)
Expand Down
Loading

0 comments on commit 2f4ab6e

Please sign in to comment.