Skip to content

Commit

Permalink
Fixed Spaces vs Tabs in all files
Browse files Browse the repository at this point in the history
Updated Network Code
Updated Submodule Engine
  • Loading branch information
NixAJ committed Jul 30, 2024
1 parent ef465f4 commit 5c0c006
Show file tree
Hide file tree
Showing 44 changed files with 1,598 additions and 1,695 deletions.
13 changes: 13 additions & 0 deletions Resources/Database/Characters.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
CREATE SEQUENCE IF NOT EXISTS public.characters_id_seq
INCREMENT 1
START 1
MINVALUE 1
MAXVALUE 9223372036854775807
CACHE 1;

ALTER SEQUENCE public.characters_id_seq
OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.characters
(
id bigint NOT NULL DEFAULT nextval('characters_id_seq'::regclass),
Expand All @@ -6,6 +16,9 @@ CREATE TABLE IF NOT EXISTS public.characters
CONSTRAINT characters_pkey PRIMARY KEY (id)
);

ALTER SEQUENCE public.characters_id_seq
OWNED BY public.characters.id;

INSERT INTO public.characters(
id, name, permissionlevel)
VALUES (1, 'dev', 5);
5 changes: 5 additions & 0 deletions Resources/Database/Updates/Characters_300720241722.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE public.characters
ADD position_x numeric NOT NULL DEFAULT 0.0,
ADD position_y numeric NOT NULL DEFAULT 0.0,
ADD position_z numeric NOT NULL DEFAULT 0.0,
ADD position_o numeric NOT NULL DEFAULT 0.0;
2 changes: 1 addition & 1 deletion Source/Server-Common/Server-Common.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local mod = Solution.Util.CreateModuleTable("Server-Common", { "base", "libpqxx" })
local mod = Solution.Util.CreateModuleTable("Server-Common", { "base", "fileformat", "input", "network", "gameplay", "luau-compiler", "luau-vm", "enkits", "refl-cpp", "utfcpp", "base64", "libpqxx" })

Solution.Util.CreateStaticLib(mod.Name, Solution.Projects.Current.BinDir, mod.Dependencies, function()
local defines = { "_CRT_SECURE_NO_WARNINGS", "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS" }
Expand Down
1 change: 1 addition & 0 deletions Source/Server-Common/Server-Common/Database/DBController.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <Base/Types.h>
#include <Base/Memory/SharedPool.h>
#include <Base/Util/DebugHandler.h>

#include <pqxx/pqxx>

Expand Down
4 changes: 2 additions & 2 deletions Source/Server-Game/Server-Game.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local mod = Solution.Util.CreateModuleTable("Server-Game", { "base", "fileformat", "input", "network", "luau-compiler", "luau-vm", "enkits", "refl-cpp", "utfcpp", "base64", "server-common" })
local mod = Solution.Util.CreateModuleTable("Server-Game", { "server-common" })

Solution.Util.CreateConsoleApp(mod.Name, Solution.Projects.Current.BinDir, mod.Dependencies, function()
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS", "WIN32_LEAN_AND_MEAN", "NOMINMAX" }
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS" }

Solution.Util.SetLanguage("C++")
Solution.Util.SetCppDialect(20)
Expand Down
260 changes: 130 additions & 130 deletions Source/Server-Game/Server-Game/Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ AutoCVar_Int CVAR_CpuReportDetailLevel(CVarCategory::Client, "cpuReportDetailLev
Application::Application() : _messagesInbound(256), _messagesOutbound(256) { }
Application::~Application()
{
delete _ecsScheduler;
delete _taskScheduler;
delete _ecsScheduler;
delete _taskScheduler;
}

void Application::Start()
{
if (_isRunning)
return;
if (_isRunning)
return;

_isRunning = true;
_isRunning = true;

std::thread applicationThread = std::thread(&Application::Run, this);
applicationThread.detach();
std::thread applicationThread = std::thread(&Application::Run, this);
applicationThread.detach();
}

void Application::Stop()
{
if (!_isRunning)
return;
if (!_isRunning)
return;

NC_LOG_INFO("Application : Shutdown Initiated");
Cleanup();
NC_LOG_INFO("Application : Shutdown Complete");
NC_LOG_INFO("Application : Shutdown Initiated");
Cleanup();
NC_LOG_INFO("Application : Shutdown Complete");

MessageOutbound message(MessageOutbound::Type::Exit);
_messagesOutbound.enqueue(message);
MessageOutbound message(MessageOutbound::Type::Exit);
_messagesOutbound.enqueue(message);
}

void Application::Cleanup()
Expand All @@ -56,136 +56,136 @@ void Application::Cleanup()

void Application::PassMessage(MessageInbound& message)
{
_messagesInbound.enqueue(message);
_messagesInbound.enqueue(message);
}

bool Application::TryGetMessageOutbound(MessageOutbound& message)
{
bool messageFound = _messagesOutbound.try_dequeue(message);
return messageFound;
bool messageFound = _messagesOutbound.try_dequeue(message);
return messageFound;
}

void Application::Run()
{
//tracy::SetThreadName("Application Thread");

if (Init())
{
Timer timer;
while (true)
{
f32 deltaTime = timer.GetDeltaTime();
timer.Tick();

if (!Tick(deltaTime))
break;

bool limitTickRate = CVAR_TickRateLimit.Get() == 1;
if (limitTickRate)
{
f32 targetTickRate = Math::Max(static_cast<f32>(CVAR_TickRateLimitTarget.Get()), 10.0f);
f32 targetDelta = 1.0f / targetTickRate;

for (deltaTime = timer.GetDeltaTime(); deltaTime < targetDelta; deltaTime = timer.GetDeltaTime())
{
std::this_thread::yield();
}
}

//FrameMark;
}
}

Stop();
//tracy::SetThreadName("Application Thread");

if (Init())
{
Timer timer;
while (true)
{
f32 deltaTime = timer.GetDeltaTime();
timer.Tick();

if (!Tick(deltaTime))
break;

bool limitTickRate = CVAR_TickRateLimit.Get() == 1;
if (limitTickRate)
{
f32 targetTickRate = Math::Max(static_cast<f32>(CVAR_TickRateLimitTarget.Get()), 10.0f);
f32 targetDelta = 1.0f / targetTickRate;

for (deltaTime = timer.GetDeltaTime(); deltaTime < targetDelta; deltaTime = timer.GetDeltaTime())
{
std::this_thread::yield();
}
}

//FrameMark;
}
}

Stop();
}

bool Application::Init()
{
// Setup CVar Config
{
std::filesystem::path currentPath = std::filesystem::current_path();
NC_LOG_INFO("Current Path : {}", currentPath.string());
std::filesystem::create_directories("Data/Config");

nlohmann::ordered_json fallback;
fallback["version"] = JsonUtils::CVAR_VERSION;
if (JsonUtils::LoadFromPathOrCreate(_cvarJson, fallback, "Data/Config/CVar.json"))
{
JsonUtils::VerifyCVarsOrFallback(_cvarJson, fallback);
JsonUtils::LoadCVarsFromJson(_cvarJson);
JsonUtils::SaveCVarsToJson(_cvarJson);
JsonUtils::SaveToPath(_cvarJson, "Data/Config/CVar.json");
}
}

// Print CPU info
CPUInfo cpuInfo = CPUInfo::Get();
cpuInfo.Print(CVAR_CpuReportDetailLevel.Get());

_taskScheduler = new enki::TaskScheduler();
_taskScheduler->Initialize();
ServiceLocator::SetTaskScheduler(_taskScheduler);

_registries.gameRegistry = new entt::registry();
ServiceLocator::SetEnttRegistries(&_registries);

_ecsScheduler = new ECS::Scheduler();
_ecsScheduler->Init(*_registries.gameRegistry);

Scripting::LuaUtil::DoString("print(\"Hello World :o\")");
return true;
// Setup CVar Config
{
std::filesystem::path currentPath = std::filesystem::current_path();
NC_LOG_INFO("Current Path : {}", currentPath.string());
std::filesystem::create_directories("Data/Config");

nlohmann::ordered_json fallback;
fallback["version"] = JsonUtils::CVAR_VERSION;
if (JsonUtils::LoadFromPathOrCreate(_cvarJson, fallback, "Data/Config/CVar.json"))
{
JsonUtils::VerifyCVarsOrFallback(_cvarJson, fallback);
JsonUtils::LoadCVarsFromJson(_cvarJson);
JsonUtils::SaveCVarsToJson(_cvarJson);
JsonUtils::SaveToPath(_cvarJson, "Data/Config/CVar.json");
}
}

// Print CPU info
CPUInfo cpuInfo = CPUInfo::Get();
cpuInfo.Print(CVAR_CpuReportDetailLevel.Get());

_taskScheduler = new enki::TaskScheduler();
_taskScheduler->Initialize();
ServiceLocator::SetTaskScheduler(_taskScheduler);

_registries.gameRegistry = new entt::registry();
ServiceLocator::SetEnttRegistries(&_registries);

_ecsScheduler = new ECS::Scheduler();
_ecsScheduler->Init(*_registries.gameRegistry);

Scripting::LuaUtil::DoString("print(\"Hello World :o\")");
return true;
}

bool Application::Tick(f32 deltaTime)
{
MessageInbound message;
while (_messagesInbound.try_dequeue(message))
{
assert(message.type != MessageInbound::Type::Invalid);

switch (message.type)
{
case MessageInbound::Type::Print:
{
NC_LOG_INFO("{}", message.data);
break;
}

case MessageInbound::Type::Ping:
{
MessageOutbound pongMessage(MessageOutbound::Type::Pong);
_messagesOutbound.enqueue(pongMessage);

NC_LOG_INFO("Main Thread -> Application Thread : Ping");
break;
}

case MessageInbound::Type::DoString:
{
if (!Scripting::LuaUtil::DoString(message.data))
{
NC_LOG_ERROR("Failed to run Lua DoString");
}
break;
}

case MessageInbound::Type::Exit:
return false;

default: break;
}
}

_ecsScheduler->Update(*_registries.gameRegistry, deltaTime);

if (CVarSystem::Get()->IsDirty())
{
JsonUtils::SaveCVarsToJson(_cvarJson);
JsonUtils::SaveToPath(_cvarJson, "Data/Config/CVar.json");

CVarSystem::Get()->ClearDirty();
}

return true;
MessageInbound message;
while (_messagesInbound.try_dequeue(message))
{
assert(message.type != MessageInbound::Type::Invalid);

switch (message.type)
{
case MessageInbound::Type::Print:
{
NC_LOG_INFO("{}", message.data);
break;
}

case MessageInbound::Type::Ping:
{
MessageOutbound pongMessage(MessageOutbound::Type::Pong);
_messagesOutbound.enqueue(pongMessage);

NC_LOG_INFO("Main Thread -> Application Thread : Ping");
break;
}

case MessageInbound::Type::DoString:
{
if (!Scripting::LuaUtil::DoString(message.data))
{
NC_LOG_ERROR("Failed to run Lua DoString");
}
break;
}

case MessageInbound::Type::Exit:
return false;

default: break;
}
}

_ecsScheduler->Update(*_registries.gameRegistry, deltaTime);

if (CVarSystem::Get()->IsDirty())
{
JsonUtils::SaveCVarsToJson(_cvarJson);
JsonUtils::SaveToPath(_cvarJson, "Data/Config/CVar.json");

CVarSystem::Get()->ClearDirty();
}

return true;
}
Loading

0 comments on commit 5c0c006

Please sign in to comment.