This commit is contained in:
Arron David Nelson 2024-01-26 09:01:01 -08:00
parent b21bc3d44d
commit a075538238
7 changed files with 194 additions and 229 deletions

2
.idea/editor.xml generated
View File

@ -31,7 +31,6 @@
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
@ -83,5 +82,6 @@
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINKAGE_SPECIFICATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
</component>
</project>

View File

@ -33,10 +33,12 @@ add_executable(TechDemo main.cpp Levels/TestLevel.cpp Levels/TestLevel.h Levels/
if (IS_OS_WINDOWS)
add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR)
elseif (IS_OS_LINUX)
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR)
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR LWE_WS_XCB)
endif()
target_link_directories(TechDemo PRIVATE "${USER_HOME_DIRECTORY}/Libraries/EHS/lib")
target_link_directories(TechDemo PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/lib")
target_include_directories(TechDemo PRIVATE "${USER_HOME_DIRECTORY}/Libraries/EHS/include")
target_include_directories(TechDemo PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/include")
find_package(Vulkan REQUIRED)

View File

@ -1,25 +1,25 @@
#include "MainMenu.h"
#include <LWE/IO/RenderWindow.h>
#include <LWE/GameLoop.h>
#include <LWE/Entity.h>
#include <LWE/IO/Model/Mesh.h>
#include <LWE/IO/FontAtlas.h>
#include <LWE/Systems/CameraSystem.h>
#include <LWE/Systems/RigidBodySystem.h>
#include <LWE/Systems/GuiSystem.h>
#include <LWE/Components/Camera.h>
#include <lwe/RenderWindow.h>
#include <lwe/GameLoop.h>
#include <lwe/Entity.h>
#include <lwe/gpu/GpuMesh.h>
#include <lwe/gpu/GpuFontAtlas.h>
#include <lwe/systems/CameraSystem.h>
#include <lwe/systems/RigidBodySystem.h>
#include <lwe/systems/GuiSystem.h>
#include <lwe/coms/Camera.h>
#include "TestLevel.h"
MainMenu::MainMenu(const lwe::Str_8& id)
MainMenu::MainMenu(const ehs::Str_8& id)
: Level(id)
{
}
void MainMenu::SetupResources()
void MainMenu::SetupResources(lwe::GpuInterface* inf)
{
Level::SetupResources();
Level::SetupResources(inf);
}
@ -31,12 +31,12 @@ void MainMenu::Setup()
AddSystem(new lwe::RigidBodySystem());
AddSystem(new lwe::GuiSystem());
lwe::Entity* cam = new lwe::Entity("Camera");
lwe::Entity cam("Camera");
lwe::Camera* com = new lwe::Camera("Main");
cam->AddComponent(com);
cam.AddComponent(com);
AddEntity(cam);
AddEntity((lwe::Entity&&)cam);
}
void MainMenu::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
@ -44,11 +44,11 @@ void MainMenu::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
Level::PostInitialize(cmdBuffer);
}
void MainMenu::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta)
void MainMenu::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta)
{
Level::OnUpdate(win, input, delta);
lwe::Vec2_f client = win->GetScale();
ehs::Vec2_f client = win->GetScale();
lwe::Entity* sp = GetEntity("SinglePlayer");
if (sp)

View File

@ -1,26 +1,23 @@
#pragma once
#include <LWE/LWE.h>
#include <LWE/LWE.h>
#include <LWE/Level.h>
#include <lwe/Level.h>
class MainMenu : public lwe::Level
{
public:
MainMenu() = default;
explicit MainMenu(const lwe::Str_8& id);
explicit MainMenu(const ehs::Str_8& id);
MainMenu(const MainMenu& level) = default;
MainMenu& operator=(const MainMenu& level) = default;
void SetupResources() override;
void SetupResources(lwe::GpuInterface* inf) override;
void Setup() override;
void PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) override;
void OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta) override;
void OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta) override;
};

View File

@ -1,62 +1,63 @@
#include "TestLevel.h"
#include <LWE/GarbageCollector.h>
#include <LWE/IO/Console.h>
#include <LWE/IO/File.h>
#include <LWE/IO/Socket/DNS.h>
#include <LWE/Json/Json.h>
#include <LWE/GameLoop.h>
#include <LWE/IO/RenderWindow.h>
#include <LWE/IO/Image/Img.h>
#include <LWE/IO/Model/Model.h>
#include <LWE/IO/FontAtlas.h>
#include <LWE/IO/CubeMap.h>
#include <LWE/IO/Audio/Audio.h>
#include <LWE/Systems/TimerSystem.h>
#include <LWE/Systems/GuiSystem.h>
#include <LWE/Systems/RigidBodySystem.h>
#include <LWE/Systems/GuiSystem.h>
#include <LWE/Systems/AudioSystem.h>
#include <LWE/Systems/CameraSystem.h>
#include <LWE/Systems/SkyboxSystem.h>
#include <LWE/Systems/LightSystem.h>
#include <LWE/Systems/SolidColorSystem.h>
#include <LWE/Systems/NetSystem.h>
#include <LWE/Systems/PhongSystem.h>
#include <LWE/Components/Camera.h>
#include <LWE/Components/PlyController.h>
#include <LWE/Components/Skybox.h>
#include <LWE/Components/AmbientPointLight.h>
#include <LWE/Components/PointLight.h>
#include <LWE/Components/SolidColor.h>
#include <LWE/Components/Phong.h>
#include "LWE/Timer.h"
#include <LWE/Components/AudioSource3D.h>
#include <LWE/Components/AABB2D.h>
#include <LWE/Components/Circle.h>
#include <LWE/Components/OBB3D.h>
#include <LWE/Components/Projectile.h>
#include <LWE/Components/Health.h>
#include <LWE/Components/Networked.h>
#include <LWE/Gui/LabelGui.h>
#include <LWE/Gui/SolidBoxGui.h>
#include <LWE/Gui/ButtonGui.h>
#include <LWE/Gui/CheckBoxGui.h>
#include <LWE/Gui/TextFieldGui.h>
#include <LWE/Gui/ImgGui.h>
#include <LWE/Gui/PanelGui.h>
#include <LWE/Gui/CollectionGui.h>
#include <LWE/Systems/BillboardSystem.h>
#include <LWE/Components/Billboard.h>
#include <LWE/IO/HID/Keyboard.h>
#include <LWE/IO/HID/Mouse.h>
#include <ehs/GarbageCollector.h>
#include <ehs/io/Console.h>
#include <ehs/io/File.h>
#include <ehs/io/socket/DNS.h>
#include <ehs/io/audio/Audio.h>
#include <ehs/io/hid/Keyboard.h>
#include <ehs/io/hid/Mouse.h>
#include <lwe/GameLoop.h>
#include <lwe/RenderWindow.h>
#include <lwe/gpu/GpuModel.h>
#include <lwe/gpu/GpuFontAtlas.h>
#include <lwe/gpu/GpuImg.h>
#include <lwe/gpu/GpuCubeMap.h>
#include <lwe/systems/TimerSystem.h>
#include <lwe/systems/GuiSystem.h>
#include <lwe/systems/RigidBodySystem.h>
#include <lwe/systems/GuiSystem.h>
#include <lwe/systems/AudioSystem.h>
#include <lwe/systems/CameraSystem.h>
#include <lwe/systems/SkyboxSystem.h>
#include <lwe/systems/LightSystem.h>
#include <lwe/systems/SolidColorSystem.h>
#include <lwe/systems/NetSystem.h>
#include <lwe/systems/PhongSystem.h>
#include <lwe/coms/Camera.h>
#include <lwe/coms/PlyController.h>
#include <lwe/coms/Skybox.h>
#include <lwe/coms/AmbientPointLight.h>
#include <lwe/coms/PointLight.h>
#include <lwe/coms/SolidColor.h>
#include <lwe/coms/Phong.h>
#include "lwe/Timer.h"
#include <lwe/coms/AudioSource3D.h>
#include <lwe/coms/AABB2D.h>
#include <lwe/coms/Circle.h>
#include <lwe/coms/OBB3D.h>
#include <lwe/coms/Projectile.h>
#include <lwe/coms/Health.h>
#include <lwe/coms/Networked.h>
#include <lwe/gui/LabelGui.h>
#include <lwe/gui/SolidBoxGui.h>
#include <lwe/gui/ButtonGui.h>
#include <lwe/gui/CheckBoxGui.h>
#include <lwe/gui/TextFieldGui.h>
#include <lwe/gui/ImgGui.h>
#include <lwe/gui/PanelGui.h>
#include <lwe/gui/CollectionGui.h>
#include <lwe/gui/WindowGui.h>
#include <lwe/systems/BillboardSystem.h>
#include <lwe/coms/Billboard.h>
TestLevel::TestLevel()
: count(0), cooldown(0.0f)
{
}
TestLevel::TestLevel(const lwe::Str_8& id)
TestLevel::TestLevel(const ehs::Str_8& id)
: Level(id), count(0), cooldown(0.0f)
{
}
@ -79,30 +80,30 @@ TestLevel& TestLevel::operator=(const TestLevel& level)
return *this;
}
void TestLevel::SetupResources()
void TestLevel::SetupResources(lwe::GpuInterface* inf)
{
lwe::FontAtlas* arial_24 = new lwe::FontAtlas("Resources/Fonts/Arial_24.ehf");
lwe::GpuFontAtlas* arial_24 = new lwe::GpuFontAtlas("resources/fonts/Arial_24.ehf", inf);
AddResource(arial_24);
lwe::Model* vampire = new lwe::Model("Resources/Models/Vampire.ehm");
vampire->Calculate();
lwe::GpuModel* vampire = new lwe::GpuModel("resources/models/Vampire.ehm", inf);
//vampire->Calculate();
AddResource(vampire);
AddResource(lwe::Img::FromFile_Heap("Resources/Textures/Character_Diffuse.png", lwe::IMG_ASPECT_COLOR));
AddResource(lwe::Img::FromFile_Heap("Resources/Textures/Character_Normal.png", lwe::IMG_ASPECT_COLOR));
AddResource(lwe::Img::FromFile_Heap("Resources/Textures/Character_Specular.png", lwe::IMG_ASPECT_COLOR));
AddResource(new lwe::GpuImg("resources/textures/Character_Diffuse.png", inf, lwe::IMG_ASPECT_COLOR));
AddResource(new lwe::GpuImg("resources/textures/Character_Normal.png", inf, lwe::IMG_ASPECT_COLOR));
AddResource(new lwe::GpuImg("Resources/Textures/Character_Specular.png", inf, lwe::IMG_ASPECT_COLOR));
lwe::Mesh* portrait = new lwe::Mesh("Portrait", lwe::portraitVerts, lwe::portraitIndices);
lwe::GpuMesh* portrait = new lwe::GpuMesh(inf, ehs::portrait);
//portrait->Calculate();
AddResource(portrait);
lwe::Mesh* portraitGUI = new lwe::Mesh("PortraitGUI", lwe::portraitGuiVerts, lwe::portraitGuiIndices);
lwe::GpuMesh* portraitGUI = new lwe::GpuMesh(inf, ehs::portraitGui);
AddResource(portraitGUI);
AddResource(new lwe::Model("Resources/Models/Cube.ehm"));
AddResource(new lwe::Model("Resources/Models/Sphere.ehm"));
AddResource(new lwe::Model("Resources/Models/PointLight.ehm"));
AddResource(new lwe::GpuModel("Resources/Models/Cube.ehm", inf));
AddResource(new lwe::GpuModel("Resources/Models/Sphere.ehm", inf));
AddResource(new lwe::GpuModel("Resources/Models/PointLight.ehm", inf));
lwe::CubeMap* cm = new lwe::CubeMap("Resources/Textures/Skybox", "Skybox");
lwe::GpuCubeMap* cm = new lwe::GpuCubeMap(inf, "Resources/Textures/Skybox", "Skybox");
AddResource(cm);
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/sample.wav", lwe::DataType::FLOAT));
@ -235,7 +236,7 @@ void TestLevel::Setup()
lwe::CollectionGui* stats = new lwe::CollectionGui("Stats");
stats->SetScale({250.0f, 127.0f});
stats->AddResource(new lwe::FontAtlas("Resources/Fonts/Arial_24.ehf"));
stats->AddResource(new lwe::GpuFontAtlas("resources/fonts/Arial_24.ehf", inf));
lwe::SolidBoxGui* bckgrd = new lwe::SolidBoxGui("Background");
bckgrd->SetScale({250.0f, 127.0f});
@ -248,31 +249,31 @@ void TestLevel::Setup()
lwe::LabelGui* deltaTime = new lwe::LabelGui("DeltaTime", "Arial_24", "Delta Time: 0");
deltaTime->SetColor({1.0f});
deltaTime->SetPosition({0.0f, 24.0f});
deltaTime->SetPosition({0.0f, 24.0f, 0.0f});
stats->AddChild(deltaTime);
lwe::LabelGui* gbg = new lwe::LabelGui("Garbage", "Arial_24", "Garbage: 0");
gbg->SetColor({1.0f});
gbg->SetPosition({0.0f, 48.0f});
gbg->SetPosition({0.0f, 48.0f, 0.0f});
stats->AddChild(gbg);
lwe::LabelGui* playback = new lwe::LabelGui("Playback", "Arial_24", "Playback: 0:0 / 0:0");
playback->SetColor({1.0f});
playback->SetPosition({0.0f, 72.0f});
playback->SetPosition({0.0f, 72.0f, 0.0f});
stats->AddChild(playback);
lwe::LabelGui* volume = new lwe::LabelGui("Volume", "Arial_24", "Volume: 0");
volume->SetColor({1.0f});
volume->SetPosition({0.0f, 96.0f});
volume->SetPosition({0.0f, 96.0f, 0.0f});
stats->AddChild(volume);
guiSys->AddGui(stats);
lwe::Serializer<lwe::UInt_64> args(lwe::Endianness::LE);
ehs::Serializer<ehs::UInt_64> args(ehs::Endianness::LE);
args.Write(stats);
args.SetOffset(0);
timerSys->Add({0, 1.0f, args, [](lwe::Timer* timer, lwe::Serializer<lwe::UInt_64>& args)
timerSys->Add({0, 1.0f, args, [](lwe::Timer* timer, ehs::Serializer<ehs::UInt_64>& args)
{
lwe::GameLoop* gl = (lwe::GameLoop*)timer->GetParent("GameLoop");
@ -280,16 +281,23 @@ void TestLevel::Setup()
args.SetOffset(0);
lwe::LabelGui* deltaTime = (lwe::LabelGui*)stats->GetChild("DeltaTime");
deltaTime->SetText("Delta Time: " + lwe::Str_8::FromNum(gl->GetRawDeltaTime()));
deltaTime->SetText("Delta Time: " + ehs::Str_8::FromNum(gl->GetRawDeltaTime()));
lwe::LabelGui* gbg = (lwe::LabelGui*)stats->GetChild("Garbage");
gbg->SetText("Garbage: " + lwe::Str_8::FromNum(lwe::GarbageCollector::Size()));
gbg->SetText("Garbage: " + ehs::Str_8::FromNum(ehs::GarbageCollector::Size()));
}});
/*
lwe::PanelGui* testPanel = new lwe::PanelGui("TestPanel");
testPanel->SetPosition({300.0f, 200.0f});
testPanel->SetPosition({300.0f, 200.0f, 0.0f});
testPanel->SetScale({400.0f, 400.0f});
guiSys->AddGui(testPanel);
*/
lwe::WindowGui* testWin = new lwe::WindowGui("TestWindow", "Hello world!");
testWin->SetPosition({300.0f, 200.0f, 0.0f});
testWin->SetScale({400.0f, 400.0f});
guiSys->AddGui(testWin);
lwe::Entity* player = new lwe::Entity("Player");
@ -304,7 +312,7 @@ void TestLevel::Setup()
plyMdl->SetPos({0.0f, 0.0f, -0.5f});
//player->AddComponent(plyMdl);
AddTemplate(player);
AddTemplate((lwe::Entity&&)player);
lwe::Entity* plyPuppet = new lwe::Entity("Puppet");
plyPuppet->AddComponent(new lwe::OBB3D("Head", 1.0f, 1.0f));
@ -317,7 +325,7 @@ void TestLevel::Setup()
puppetMdl->SetPos({0.0f, 0.0f, -0.5f});
//plyPuppet->AddComponent(puppetMdl);
AddTemplate(plyPuppet);
AddTemplate((lwe::Entity&&)plyPuppet);
CreateEntity(player->GetHashId(), "Player");
@ -326,7 +334,7 @@ void TestLevel::Setup()
lwe::Skybox* skybox = new lwe::Skybox("Skybox", "Skybox");
skyboxEnt->AddComponent(skybox);
AddEntity(skyboxEnt);
AddEntity((lwe::Entity&&)skyboxEnt);
lwe::Entity* ent = new lwe::Entity("Main");
ent->SetScale({0.25f, 0.25f, 0.25f});
@ -350,11 +358,11 @@ void TestLevel::Setup()
entCollider->SetPos({0.0f, 1.1f, 0.0f});
entCollider->SetCollidedCb([](lwe::RigidBody* a, lwe::RigidBody* b)
{
lwe::Entity* aOwner = (lwe::Entity*)a->GetParent();
lwe::Entity* aOwner = a->GetEntity();
lwe::Health* health = (lwe::Health*)aOwner->GetComponent("Health");
health->TakeDamage(10);
lwe::Entity* bOwner = (lwe::Entity*)b->GetParent();
lwe::Entity* bOwner = b->GetEntity();
bOwner->Delete();
if (health->GetHealth() <= 0)
@ -372,16 +380,16 @@ void TestLevel::Setup()
ph->SetAnimation("Test");
ent->AddComponent(ph);
AddEntity(ent);
AddEntity((lwe::Entity&&)ent);
lwe::Entity* sun = new lwe::Entity("Sun");
sun->SetPos({-5.0f, 0.0f, 5.0f});
lwe::Entity sun("Sun");
sun.SetPos({-5.0f, 0.0f, 5.0f});
lwe::AmbientPointLight* sunLight = new lwe::AmbientPointLight("Light");
sunLight->SetDiffuse({1.0f, 0.77254901960784313725490196078431f, 0.56078431372549019607843137254902f});
sun->AddComponent(sunLight);
sun.AddComponent(sunLight);
AddEntity(sun);
AddEntity((lwe::Entity&&)sun);
lwe::Entity* emergency = new lwe::Entity("Emergency");
emergency->SetPos({5.0f, 0.0f, 5.0f});
@ -390,14 +398,14 @@ void TestLevel::Setup()
pl->SetColor({1.0f, 0.0f, 0.0f});
emergency->AddComponent(pl);
AddEntity(emergency);
AddEntity((lwe::Entity&&)emergency);
lwe::Entity* testEnt = new lwe::Entity("Test");
lwe::Billboard* testBb = new lwe::Billboard("TestBB", "Character_Diffuse");
testEnt->AddComponent(testBb);
AddEntity(testEnt);
AddEntity((lwe::Entity&&)testEnt);
lwe::Entity* bullet = new lwe::Entity("Bullet");
bullet->SetScale({0.1f, 0.1f, 0.1f});
@ -411,7 +419,7 @@ void TestLevel::Setup()
lwe::SolidColor* bulletMdl = new lwe::SolidColor("Mdl", {1.0f, 1.0f, 0.0f, 1.0f}, "Cube", "");
bullet->AddComponent(bulletMdl);
AddTemplate(bullet);
AddTemplate((lwe::Entity&&)bullet);
}
void TestLevel::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
@ -454,21 +462,21 @@ void TestLevel::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
*/
}
void TestLevel::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta)
void TestLevel::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta)
{
lwe::GameLoop* gl = (lwe::GameLoop*)GetParent("GameLoop");
lwe::GameLoop* gl = GetParent();
if (!gl)
return;
const lwe::InputHandler* ih = win->GetInputHandler();
const ehs::InputHandler* ih = win->GetInputHandler();
if (!ih)
return;
const lwe::Mouse* mouse = (lwe::Mouse*)ih->GetDeviceByType(LWE_HID_MOUSE);
const ehs::Mouse* mouse = (ehs::Mouse*)ih->GetDeviceByType(EHS_HID_MOUSE);
if (!mouse)
return;
const lwe::Keyboard* keyboard = (lwe::Keyboard*)ih->GetDeviceByType(LWE_HID_KEYBOARD);
const ehs::Keyboard* keyboard = (ehs::Keyboard*)ih->GetDeviceByType(EHS_HID_KEYBOARD);
if (!keyboard)
return;
@ -476,7 +484,7 @@ void TestLevel::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float
if (!ent)
return;
ent->SetRot(ent->GetRot() + lwe::Vec3_f(50.0f) * delta);
ent->SetRot(ent->GetRot() + ehs::Vec3_f(50.0f) * delta);
lwe::Entity* ply = GetEntity("Player");
if (ply && win->IsCursorConstrained() && !win->IsCursorVisible())
@ -488,13 +496,13 @@ void TestLevel::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float
if (camSys)
camSys->SetPrimary(ply->GetHashId(), cam->GetHashId());
if (cooldown <= 0.0f && mouse->IsDown(lwe::Mouse::LMB)) // Left Mouse Button
if (cooldown <= 0.0f && mouse->IsDown(ehs::Mouse::LMB)) // Left Mouse Button
{
lwe::AudioSource* gunshot = new lwe::AudioSource("Gunshot_" + lwe::Str_8::FromNum(count), "Gunshot");
lwe::AudioSource* gunshot = new lwe::AudioSource("Gunshot_" + ehs::Str_8::FromNum(count), "Gunshot");
gunshot->SetVolume(1.0f);
ply->AddComponent(gunshot);
lwe::Entity* bullet = CreateEntity("Bullet", "Bullet_" + lwe::Str_8::FromNum(count++));
lwe::Entity* bullet = CreateEntity("Bullet", "Bullet_" + ehs::Str_8::FromNum(count++));
bullet->SetPos(ply->GetPos() + cam->GetTransform().GetForward() * 2.0f);
bullet->SetScale({0.1f, 0.1f, 0.1f});
bullet->SetRot(ply->GetRot());
@ -524,7 +532,7 @@ void TestLevel::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float
return;
lwe::LabelGui* fps = (lwe::LabelGui*)stats->GetChild("FPS");
fps->SetText("FPS: " + lwe::Str_8::FromNum(gl->GetTPS()));
fps->SetText("FPS: " + ehs::Str_8::FromNum(gl->GetTPS()));
lwe::AudioSource* source = (lwe::AudioSource*)ent->GetComponent("AudioSource3D", "Song");
if (!source)
@ -536,24 +544,24 @@ void TestLevel::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float
lwe::LabelGui* playback = (lwe::LabelGui*)stats->GetChild("Playback");
lwe::UInt_64 elapsed = source->GetFrameOffset() / audio->GetSampleRate();
lwe::UInt_64 duration = audio->GetFrameCount() / audio->GetSampleRate();
ehs::UInt_64 elapsed = source->GetFrameOffset() / audio->GetSampleRate();
ehs::UInt_64 duration = audio->GetFrameCount() / audio->GetSampleRate();
playback->SetText("Playback: " + lwe::Str_8::FromNum(elapsed / 60) + ":" + lwe::Str_8::FromNum(elapsed % 60) +
" / " + lwe::Str_8::FromNum(duration / 60) + ":" + lwe::Str_8::FromNum(duration % 60));
playback->SetText("Playback: " + ehs::Str_8::FromNum(elapsed / 60) + ":" + ehs::Str_8::FromNum(elapsed % 60) +
" / " + ehs::Str_8::FromNum(duration / 60) + ":" + ehs::Str_8::FromNum(duration % 60));
if (win->IsCursorConstrained() && !win->IsCursorVisible())
{
if (keyboard->IsJustReleased(lwe::Keyboard::Left))
if (keyboard->IsJustReleased(ehs::Keyboard::Left))
source->SetVolume(source->GetVolume() - 0.25f);
if (keyboard->IsJustReleased(lwe::Keyboard::Right))
if (keyboard->IsJustReleased(ehs::Keyboard::Right))
source->SetVolume(source->GetVolume() + 0.25f);
lwe::LabelGui* volume = (lwe::LabelGui*)stats->GetChild("Volume");
volume->SetText("Volume: " + lwe::Str_8::FromNum(source->GetVolume()));
volume->SetText("Volume: " + ehs::Str_8::FromNum(source->GetVolume()));
if (keyboard->IsJustReleased(lwe::Keyboard::P))
if (keyboard->IsJustReleased(ehs::Keyboard::P))
{
if (source->IsPlaying())
source->Pause();
@ -561,7 +569,7 @@ void TestLevel::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float
source->Play();
}
if (keyboard->IsJustReleased(lwe::Keyboard::Backspace))
if (keyboard->IsJustReleased(ehs::Keyboard::Backspace))
source->Reset();
}
}

View File

@ -1,31 +1,29 @@
#pragma once
#include <LWE/LWE.h>
#include <LWE/Json/Json.h>
#include <ehs/json/Json.h>
#include <LWE/LWE.h>
#include <LWE/Level.h>
#include <lwe/Level.h>
class TestLevel : public lwe::Level
{
private:
lwe::UInt_32 count;
ehs::UInt_32 count;
float cooldown;
public:
TestLevel();
explicit TestLevel(const lwe::Str_8& id);
explicit TestLevel(const ehs::Str_8& id);
TestLevel(const TestLevel& level);
TestLevel& operator=(const TestLevel& level);
void SetupResources() override;
void SetupResources(lwe::GpuInterface* inf) override;
void Setup() override;
void PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) override;
void OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta) override;
void OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta) override;
};

138
main.cpp
View File

@ -1,44 +1,28 @@
#include <LWE/LWE.h>
#include <LWE/Str.h>
#include <LWE/Log.h>
#include <LWE/GarbageCollector.h>
#include <LWE/Array.h>
#include <LWE/IO/File.h>
#include <LWE/IO/Console.h>
#include <LWE/System/Thread.h>
#include <LWE/Json/Json.h>
#include <LWE/IO/Image/PNG.h>
#include <LWE/Gpu/GpuDevice.h>
#include <LWE/Gpu/GpuInterface.h>
#include <LWE/IO/RenderWindow.h>
#include <LWE/GameLoop.h>
#include <LWE/IO/HID/Wooting.h>
#include <ehs/Str.h>
#include <ehs/Log.h>
#include <ehs/GarbageCollector.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"
bool running = true;
lwe::UInt_32 GcCb(void* params)
void LogRaised(const ehs::Log& log)
{
while (running)
{
lwe::GarbageCollector::Poll();
lwe::Thread::SleepFor(50);
}
ehs::Array<ehs::Str_8> tags = log.GetTags();
lwe::GarbageCollector::Dump();
return 0;
}
void LogRaised(const lwe::Log& log)
{
lwe::Array<lwe::Str_8> tags = log.GetTags();
lwe::Str_8 result = "{";
ehs::Str_8 result = "{";
if (log.HasTag("Info"))
{
@ -48,63 +32,63 @@ void LogRaised(const lwe::Log& log)
}
else
{
for (lwe::UInt_32 i = 0; i < tags.Size(); ++i)
for (ehs::UInt_32 i = 0; i < tags.Size(); ++i)
{
result += tags[i];
if (i != tags.Size() - 1)
result += ", ";
}
result += "} (" + lwe::Str_8::FromNum(log.GetCode()) + "): " + log.GetMsg();
result += "} (" + ehs::Str_8::FromNum(log.GetCode()) + "): " + log.GetMsg();
}
lwe::Console::Write_8(result);
ehs::Console::Write_8(result);
if (log.HasTag("Error"))
{
lwe::Console::Read_8();
ehs::Console::Read_8();
}
}
lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVer)
ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
{
*appName = "TechDemo";
*appVerId = "Release";
*appVer = {1, 0, 0};
lwe::Log::SetCallback(LogRaised);
ehs::Log::SetCallback(LogRaised);
lwe::File configFile("Config.json", lwe::Mode::READ_WRITE, lwe::Disposition::OPEN_PERSISTENT);
ehs::File configFile("Config.json", ehs::Mode::READ_WRITE, ehs::Disposition::OPEN_PERSISTENT);
if (!configFile.Size())
{
lwe::JsonObj root;
ehs::JsonObj root;
lwe::JsonObj server;
ehs::JsonObj server;
server.AddVar({"identifier", ""});
server.AddVar({"address", ""});
server.AddVar({"port", 7840});
server.AddVar({"maxPlayers", 0});
root.AddVar({"server", server});
lwe::JsonObj client;
ehs::JsonObj client;
client.AddVar({"username", ""});
client.AddVar({"connectAddress", ""});
client.AddVar({"connectPort", 7840});
root.AddVar({"client", client});
lwe::JsonObj server_client;
ehs::JsonObj server_client;
server_client.AddVar({"timeout", 5});
server_client.AddVar({"resendRate", 0.5f});
root.AddVar({"server_client", server_client});
lwe::JsonObj engine;
ehs::JsonObj engine;
engine.AddVar({"threadCount", 0});
engine.AddVar({"timeLocked", true});
engine.AddVar({"maxTPS", 60});
root.AddVar({"engine", engine});
lwe::Json config(root);
ehs::Json config(root);
configFile.WriteStr_8(config.ToStr(false));
@ -113,47 +97,36 @@ lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVe
return 0;
}
lwe::Json config(configFile.ReadStr_8(configFile.Size()), 0);
ehs::Json config(configFile.ReadStr_8(configFile.Size()), 0);
configFile.Release();
lwe::Vector<lwe::Str_8> args = lwe::Console::GetArgs_8();
if (args.Size() > 1 && lwe::Str_8::Cmp(args[1], "-server"))
ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8();
if (args.Size() > 1 && ehs::Str_8::Cmp(args[1], "-server"))
{
lwe::Console::Attach();
ehs::Console::Attach();
lwe::Console::SetTitle_8("TechDemo");
ehs::Console::SetTitle_8("TechDemo");
LWE_LOG("Info", 0, "Initializing server, standby.");
EHS_LOG("Info", 0, "Initializing server, standby.");
lwe::GameLoop gl((lwe::UInt_8)*(lwe::JsonNum*)config.RetrieveValue("engine.threadCount"), 0);
gl.EnableTimeLock(*(lwe::JsonBool*)config.RetrieveValue("engine.timeLocked"));
gl.SetMaxTPS((lwe::UInt_32)*(lwe::JsonNum*)config.RetrieveValue("engine.maxTPS"));
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"));
lwe::Frame mainFrame("Main");
gl.AddFrame(&mainFrame);
mainFrame.AddLevel(new MainMenu("MainMenu"));
lwe::GarbageCollector::SetStride(1000);
lwe::GarbageCollector::SetMax(10);
lwe::Thread gcThread;
gcThread.Start(GcCb, nullptr);
gl.AddLevel(new MainMenu("MainMenu"));
gl.Initialize();
gl.Start();
gl.UnInitialize();
running = false;
gcThread.Join();
}
else
{
lwe::Console::Attach();
ehs::Console::Attach();
#if defined(LWE_OS_WINDOWS)
#if defined(EHS_OS_WINDOWS)
lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
#elif defined(LWE_OS_LINUX)
#elif defined(EHS_OS_LINUX)
lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
#endif
@ -171,22 +144,14 @@ lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVe
inf.Initialize();
lwe::RenderWindow win(&inf, &primary);
win.Create_8(lwe::GetAppName_8(), {0, 0}, {1024, 768});
win.Create_8(ehs::GetAppName_8(), {0, 0}, {1024, 768});
win.Show();
lwe::GameLoop gl(&win, (lwe::UInt_8)*(lwe::JsonNum*)config.RetrieveValue("engine.threadCount"), 0);
gl.EnableTimeLock(*(lwe::JsonBool*)config.RetrieveValue("engine.timeLocked"));
gl.SetMaxTPS((lwe::UInt_32)*(lwe::JsonNum*)config.RetrieveValue("engine.maxTPS"));
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"));
lwe::Frame mainFrame("Main");
gl.AddFrame(&mainFrame);
mainFrame.AddLevel(new TestLevel("Test"));
lwe::GarbageCollector::SetStride(1000);
lwe::GarbageCollector::SetMax(10);
lwe::Thread gcThread;
gcThread.Start(GcCb, nullptr);
gl.AddLevel(new TestLevel("Test"));
gl.Initialize();
gl.Start();
@ -194,17 +159,12 @@ lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVe
win.Close();
running = false;
gcThread.Join();
inf.Release();
lwe::GpuInstance::Release();
//lwe::AudioEngine::UnInitialize();
}
lwe::Console::Free();
ehs::Console::Free();
return 0;
}