TechDemo/main.cpp
2024-07-24 00:51:03 -07:00

132 lines
3.2 KiB
C++

#include <ehs/Str.h>
#include <ehs/Log.h>
#include <ehs/GC.h>
#include <ehs/Array.h>
#include <ehs/io/File.h>
#include <ehs/io/Console.h>
#include <ehs/system/Thread.h>
#include <ehs/json/Json.h>
#include <ehs/io/img/PNG.h>
#include <lwe/RenderWindow.h>
#include <lwe/gpu/GpuDevice.h>
#include <lwe/gpu/GpuInterface.h>
#include <lwe/GameLoop.h>
#include <vulkan/vulkan.h>
#include "Levels/MainMenu.h"
#include "Levels/TestLevel.h"
ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
{
*appName = "TechDemo";
*appVerId = "Release";
*appVer = {1, 0, 0};
ehs::Log::EnableImmediateMode(true);
ehs::File configFile("Config.json", ehs::Mode::READ_WRITE, ehs::Disposition::OPEN_PERSISTENT);
if (!configFile.Size())
{
ehs::JsonObj root;
ehs::JsonObj server;
server.AddVar({"identifier", ""});
server.AddVar({"address", ""});
server.AddVar({"port", 7840});
server.AddVar({"maxPlayers", 0});
root.AddVar({"server", server});
ehs::JsonObj client;
client.AddVar({"username", ""});
client.AddVar({"connectAddress", ""});
client.AddVar({"connectPort", 7840});
root.AddVar({"client", client});
ehs::JsonObj server_client;
server_client.AddVar({"timeout", 5});
server_client.AddVar({"resendRate", 0.5f});
root.AddVar({"server_client", server_client});
ehs::JsonObj engine;
engine.AddVar({"threadCount", 0});
engine.AddVar({"timeLocked", true});
engine.AddVar({"maxTPS", 60});
root.AddVar({"engine", engine});
ehs::Json config(root);
configFile.WriteStr_8(config.ToStr(false));
configFile.Release();
return 0;
}
ehs::Json config(configFile.ReadStr_8(configFile.Size()), 0);
configFile.Release();
ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8();
if (args.Size() > 1 && ehs::Str_8::Cmp(args[1], "-server"))
{
ehs::Console::Attach();
ehs::Console::SetTitle_8("TechDemo");
EHS_LOG(ehs::LogType::INFO, 0, "Initializing server, standby.");
lwe::GameLoop gl((ehs::UInt_8)*(ehs::JsonNum*)config.RetrieveValue("engine.threadCount"), 0);
gl.EnableTimeLock(*(ehs::JsonBool*)config.RetrieveValue("engine.timeLocked"));
gl.SetMaxTPS((ehs::UInt_32)*(ehs::JsonNum*)config.RetrieveValue("engine.maxTPS"));
gl.AddLevel(new MainMenu("MainMenu"));
gl.Initialize();
gl.Start();
gl.UnInitialize();
}
else
{
ehs::Console::Attach();
lwe::RenderWindow::AddExtensions();
lwe::GpuInstance::Initialize(true);
lwe::GpuDevice device = std::move(lwe::GpuDevice::GetBest());
lwe::GpuQueueFamily* family = device.GetQueueFamily(lwe::QueueType::GRAPHICS);
lwe::GpuInterface inf(&device);
lwe::RenderWindow::AddExtensions(&inf);
lwe::GpuQueue primary(family, &inf, 1.0f);
inf.Initialize();
lwe::RenderWindow win(&inf, &primary);
win.Create_8(ehs::GetAppName_8(), {0, 0}, {1024, 768});
win.Show();
lwe::GameLoop gl(&win, (ehs::UInt_8)*(ehs::JsonNum*)config.RetrieveValue("engine.threadCount"), 0);
gl.EnableTimeLock(*(ehs::JsonBool*)config.RetrieveValue("engine.timeLocked"));
gl.SetMaxTPS((ehs::UInt_32)*(ehs::JsonNum*)config.RetrieveValue("engine.maxTPS"));
gl.AddLevel(new TestLevel("Test"));
gl.Initialize();
gl.Start();
gl.UnInitialize();
win.Close();
inf.Release();
lwe::GpuInstance::Release();
}
ehs::Console::Free();
return 0;
}