539 lines
17 KiB
C++
539 lines
17 KiB
C++
#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/Systems/DynamicsSystem.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/Components/Dynamics.h>
|
|
#include <LWE/Gui/LabelGui.h>
|
|
#include <LWE/Gui/SolidBoxGui.h>
|
|
#include <LWE/Gui/ButtonGui.h>
|
|
#include <LWE/Gui/ImgGui.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 <LWE/IO/HID/GenericInputHandler.h>
|
|
|
|
TestLevel::TestLevel()
|
|
: count(0), cooldown(0.0f)
|
|
{
|
|
}
|
|
|
|
TestLevel::TestLevel(const lwe::Str_8& id)
|
|
: Level(id), count(0), cooldown(0.0f)
|
|
{
|
|
}
|
|
|
|
TestLevel::TestLevel(const TestLevel& level)
|
|
: Level(level), count(0), cooldown(0.0f)
|
|
{
|
|
}
|
|
|
|
TestLevel& TestLevel::operator=(const TestLevel& level)
|
|
{
|
|
if (this == &level)
|
|
return *this;
|
|
|
|
Level::operator=(level);
|
|
|
|
count = 0;
|
|
cooldown = 0.0f;
|
|
|
|
return *this;
|
|
}
|
|
|
|
void TestLevel::SetupResources()
|
|
{
|
|
lwe::FontAtlas* arial_24 = new lwe::FontAtlas("Resources/Fonts/Arial_24.ehf");
|
|
AddResource(arial_24);
|
|
|
|
lwe::Model* vampire = new lwe::Model("Resources/Models/Vampire.ehm");
|
|
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));
|
|
|
|
lwe::Mesh* portrait = new lwe::Mesh("Portrait", lwe::portraitVerts, lwe::portraitIndices);
|
|
//portrait->Calculate();
|
|
AddResource(portrait);
|
|
|
|
lwe::Mesh* portraitGUI = new lwe::Mesh("PortraitGUI", lwe::portraitGuiVerts, lwe::portraitGuiIndices);
|
|
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"));
|
|
|
|
lwe::CubeMap* cm = new lwe::CubeMap("Resources/Textures/Skybox", "Skybox");
|
|
AddResource(cm);
|
|
|
|
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/sample.wav", lwe::DataType::FLOAT));
|
|
}
|
|
|
|
void TestLevel::Setup()
|
|
{
|
|
lwe::GameLoop* gl = (lwe::GameLoop*)GetParent();
|
|
if (!gl)
|
|
return;
|
|
|
|
/*
|
|
lwe::File configFile("Config.json", lwe::Mode::READ, lwe::Disposition::OPEN);
|
|
configFile.Initialize();
|
|
|
|
lwe::Json config(configFile.ReadStr(configFile.Size()), 0);
|
|
|
|
configFile.UnInitialize();
|
|
|
|
if (gl->GetWindow())
|
|
{
|
|
lwe::NetSystem* ns = new lwe::NetSystem(ehc::Disposition::ENDPOINT, *(lwe::JsonStr*)config.RetrieveValue("client.username"), 0);
|
|
ns->GetSocket()->SetAddressType(lwe::AddrType::IPV6);
|
|
ns->GetSocket()->EnableDropPackets(true);
|
|
ns->GetSocket()->SetMaxTimeout(*(lwe::JsonNum*)config.RetrieveValue("server_client.timeout"));
|
|
ns->GetSocket()->SetResendRate(*(lwe::JsonNum*)config.RetrieveValue("server_client.resendRate"));
|
|
|
|
AddSystem(ns);
|
|
}
|
|
else
|
|
{
|
|
lwe::NetSystem* ns = new lwe::NetSystem(ehc::Disposition::SERVICE, *(lwe::JsonStr*)config.RetrieveValue("server.identifier"), (lwe::UInt_32)*(lwe::JsonNum*)config.RetrieveValue("server.maxPlayers"));
|
|
ns->GetSocket()->SetAddressType(lwe::AddrType::IPV6);
|
|
ns->GetSocket()->EnableDropPackets(true);
|
|
ns->GetSocket()->SetMaxTimeout(*(lwe::JsonNum*)config.RetrieveValue("server_client.timeout"));
|
|
ns->GetSocket()->SetResendRate(*(lwe::JsonNum*)config.RetrieveValue("server_client.resendRate"));
|
|
|
|
ns->GetSocket()->SetActiveCb([](ehc::Socket* sock, ehc::Endpoint* end){
|
|
lwe::Level* lvl = (lwe::Level*)sock->GetParent("Level");
|
|
if (!lvl)
|
|
return;
|
|
|
|
lwe::Entity* ply = lvl->CreateEntity("Puppet", "Ply-" + end->GetId());
|
|
lwe::Networked* net = (lwe::Networked*)ply->GetComponent("Networked", "");
|
|
net->SetOwner(end->GetHashId());
|
|
|
|
lwe::Serializer puppetPayload(lwe::Endianness::LE);
|
|
puppetPayload.Write(lwe::Str_8::Hash_64("Puppet"));
|
|
puppetPayload.WriteStr(ply->GetId());
|
|
puppetPayload.Write(end->GetHashId());
|
|
puppetPayload.WriteVec3(ply->GetPos());
|
|
puppetPayload.WriteVec3(ply->GetRot());
|
|
puppetPayload.WriteVec3(ply->GetScale());
|
|
|
|
lwe::Serializer playerPayload(lwe::Endianness::LE);
|
|
playerPayload.Write(lwe::Str_8::Hash_64("Player"));
|
|
playerPayload.WriteStr(ply->GetId());
|
|
playerPayload.Write(end->GetHashId());
|
|
playerPayload.WriteVec3(ply->GetPos());
|
|
playerPayload.WriteVec3(ply->GetRot());
|
|
playerPayload.WriteVec3(ply->GetScale());
|
|
|
|
lwe::Array<ehc::Endpoint*> endpoints = sock->GetEndpoints(ehc::Disposition::ENDPOINT, ehc::Status::ACTIVE);
|
|
for (lwe::UInt_64 i = 0; i < endpoints.Size(); ++i)
|
|
{
|
|
if (endpoints[i] == end)
|
|
endpoints[i]->Send(false, true, true, "LWE", "CreateEnt", playerPayload);
|
|
else
|
|
{
|
|
lwe::Serializer otherPuppet(lwe::Endianness::LE);
|
|
otherPuppet.Write(lwe::Str_8::Hash_64("Puppet"));
|
|
otherPuppet.WriteStr("Ply-" + endpoints[i]->GetId());
|
|
playerPayload.Write(endpoints[i]->GetHashId());
|
|
otherPuppet.WriteVec3(ply->GetPos());
|
|
otherPuppet.WriteVec3(ply->GetRot());
|
|
otherPuppet.WriteVec3(ply->GetScale());
|
|
end->Send(false, true, true, "LWE", "CreateEnt", otherPuppet);
|
|
|
|
endpoints[i]->Send(false, true, true, "LWE", "CreateEnt", puppetPayload);
|
|
}
|
|
}
|
|
});
|
|
|
|
ns->GetSocket()->SetDisconnectedCb([](ehc::Socket* sock, ehc::Endpoint* end){
|
|
Level* lvl = (Level*)sock->GetParent("Level");
|
|
if (!lvl)
|
|
return;
|
|
|
|
lwe::Entity* ply = lvl->GetEntity("Ply-" + end->GetId());
|
|
if (!ply)
|
|
return;
|
|
|
|
lwe::Serializer payload(lwe::Endianness::LE);
|
|
payload.Write(ply->GetHashId());
|
|
|
|
lwe::Array<ehc::Endpoint*> endpoints = sock->GetEndpoints(ehc::Disposition::ENDPOINT, ehc::Status::ACTIVE);
|
|
for (lwe::UInt_64 i = 0; i < endpoints.Size(); ++i)
|
|
{
|
|
if (endpoints[i] == end)
|
|
continue;
|
|
|
|
endpoints[i]->Send(false, true, true, "LWE", "DeleteEnt", payload);
|
|
}
|
|
|
|
ply->Delete();
|
|
});
|
|
|
|
AddSystem(ns);
|
|
}
|
|
*/
|
|
|
|
AddSystem(new lwe::DynamicsSystem());
|
|
AddSystem(new lwe::RigidBodySystem());
|
|
AddSystem(new lwe::CameraSystem());
|
|
AddSystem(new lwe::SkyboxSystem());
|
|
AddSystem(new lwe::PhongSystem());
|
|
AddSystem(new lwe::SolidColorSystem());
|
|
AddSystem(new lwe::BillboardSystem());
|
|
|
|
lwe::LightSystem* ls = new lwe::LightSystem(true);
|
|
ls->SetAmbient({0.25f, 0.25f, 0.25f});
|
|
AddSystem(ls);
|
|
|
|
//AddSystem(new lwe::AudioSystem());
|
|
|
|
lwe::TimerSystem* timerSys = new lwe::TimerSystem();
|
|
AddSystem(timerSys);
|
|
|
|
lwe::GuiSystem* guiSys = new lwe::GuiSystem();
|
|
AddSystem(guiSys);
|
|
|
|
lwe::CollectionGui* stats = new lwe::CollectionGui("Stats");
|
|
stats->SetScale({250.0f, 127.0f});
|
|
|
|
stats->AddResource(new lwe::FontAtlas("Resources/Fonts/Arial_24.ehf"));
|
|
|
|
lwe::SolidBoxGui* bckgrd = new lwe::SolidBoxGui("Background");
|
|
bckgrd->SetScale({250.0f, 127.0f});
|
|
bckgrd->SetColor({0.0f, 0.0f, 0.0f, 0.5f});
|
|
stats->AddChild(bckgrd);
|
|
|
|
lwe::LabelGui* fps = new lwe::LabelGui("FPS", "Arial_24", "FPS: 0");
|
|
fps->SetColor({1.0f});
|
|
stats->AddChild(fps);
|
|
|
|
lwe::LabelGui* deltaTime = new lwe::LabelGui("DeltaTime", "Arial_24", "Delta Time: 0");
|
|
deltaTime->SetColor({1.0f});
|
|
deltaTime->SetPosition({0.0f, 24.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});
|
|
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});
|
|
stats->AddChild(playback);
|
|
|
|
lwe::LabelGui* volume = new lwe::LabelGui("Volume", "Arial_24", "Volume: 0");
|
|
volume->SetColor({1.0f});
|
|
volume->SetPosition({0.0f, 96.0f});
|
|
stats->AddChild(volume);
|
|
|
|
guiSys->AddGui(stats);
|
|
|
|
lwe::Serializer<lwe::UInt_64> args(lwe::Endianness::LE);
|
|
args.Write(stats);
|
|
args.SetOffset(0);
|
|
|
|
timerSys->Add({0, 1.0f, args, [](lwe::Timer* timer, lwe::Serializer<lwe::UInt_64>& args)
|
|
{
|
|
lwe::GameLoop* gl = (lwe::GameLoop*)timer->GetParent("GameLoop");
|
|
|
|
lwe::CollectionGui* stats = args.Read<lwe::CollectionGui*>();
|
|
args.SetOffset(0);
|
|
|
|
lwe::LabelGui* deltaTime = (lwe::LabelGui*)stats->GetChild("DeltaTime");
|
|
deltaTime->SetText("Delta Time: " + lwe::Str_8::FromNum(gl->GetRawDeltaTime()));
|
|
|
|
lwe::LabelGui* gbg = (lwe::LabelGui*)stats->GetChild("Garbage");
|
|
gbg->SetText("Garbage: " + lwe::Str_8::FromNum(lwe::GarbageCollector::Size()));
|
|
}});
|
|
|
|
lwe::ButtonGui* testBttn = new lwe::ButtonGui("Test", "Test");
|
|
testBttn->SetScale({200.0f, 50.0f});
|
|
testBttn->SetPosition({400.0f, 400.0f});
|
|
guiSys->AddGui(testBttn);
|
|
|
|
lwe::Entity* player = new lwe::Entity("Player");
|
|
|
|
//player->AddComponent(new lwe::Networked(true, false, lwe::EndpointOwner::ENDPOINT));
|
|
player->AddComponent(new lwe::Point3D("Head"));
|
|
player->AddComponent(new lwe::PlyController("Head"));
|
|
//player->AddComponent(new lwe::Health(100, 100));
|
|
|
|
lwe::SolidColor* plyMdl = new lwe::SolidColor("Cube", {0.0f, 0.0f, 1.0f}, "Cube", "");
|
|
plyMdl->SetDiffused(true);
|
|
plyMdl->SetScale({0.5f});
|
|
plyMdl->SetPos({0.0f, 0.0f, -0.5f});
|
|
//player->AddComponent(plyMdl);
|
|
|
|
AddTemplate(player);
|
|
|
|
lwe::Entity* plyPuppet = new lwe::Entity("Puppet");
|
|
plyPuppet->AddComponent(new lwe::OBB3D("Head"));
|
|
plyPuppet->AddComponent(new lwe::Camera("Head"));
|
|
plyPuppet->AddComponent(new lwe::Health(100, 100));
|
|
|
|
lwe::SolidColor* puppetMdl = new lwe::SolidColor("Cube", {0.0f, 0.0f, 1.0f}, "Cube", "");
|
|
puppetMdl->SetDiffused(true);
|
|
puppetMdl->SetScale({0.5f});
|
|
puppetMdl->SetPos({0.0f, 0.0f, -0.5f});
|
|
//plyPuppet->AddComponent(puppetMdl);
|
|
|
|
AddTemplate(plyPuppet);
|
|
|
|
CreateEntity(player->GetHashId(), "Player");
|
|
|
|
lwe::Entity* skyboxEnt = new lwe::Entity("Skybox");
|
|
|
|
lwe::Skybox* skybox = new lwe::Skybox("Skybox", "Skybox");
|
|
skyboxEnt->AddComponent(skybox);
|
|
|
|
AddEntity(skyboxEnt);
|
|
|
|
lwe::Entity* ent = new lwe::Entity("Main");
|
|
ent->SetScale({0.25f, 0.25f, 0.25f});
|
|
ent->SetPos({0.0f, -1.0f, 5.0f});
|
|
//ent->SetRot({-90.0f, 180.0f, 0.0f});
|
|
|
|
//ent->AddComponent(new lwe::Networked(false, false, lwe::EndpointOwner::SERVICE));
|
|
|
|
lwe::AudioSource3D* as = new lwe::AudioSource3D("Song", "sample", 20.0f);
|
|
as->Pause();
|
|
as->EnableLoop(true);
|
|
//as->EnablePanning(false);
|
|
//as->EnableAttenuation(false);
|
|
ent->AddComponent(as);
|
|
|
|
lwe::Sphere* sphere = new lwe::Sphere("Sphere", 5.0f);
|
|
ent->AddComponent(sphere);
|
|
|
|
/*
|
|
lwe::AudioSource* as2 = new lwe::AudioSource("Song2", "sample");
|
|
as2->Play();
|
|
ent->AddComponent(as2);
|
|
*/
|
|
|
|
lwe::Phong* ph = new lwe::Phong("Cube", "Vampire", "", "Character_Diffuse", "Character_Specular", "Character_Normal");
|
|
ph->SetAnimation("Test");
|
|
ent->AddComponent(ph);
|
|
|
|
AddEntity(ent);
|
|
|
|
lwe::Entity* sun = new lwe::Entity("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);
|
|
|
|
AddEntity(sun);
|
|
|
|
lwe::Entity* emergency = new lwe::Entity("Emergency");
|
|
emergency->SetPos({5.0f, 0.0f, 5.0f});
|
|
|
|
lwe::PointLight* pl = new lwe::PointLight("Light");
|
|
pl->SetColor({1.0f, 0.0f, 0.0f});
|
|
emergency->AddComponent(pl);
|
|
|
|
AddEntity(emergency);
|
|
|
|
lwe::Entity* testEnt = new lwe::Entity("Test");
|
|
|
|
lwe::Billboard* testBb = new lwe::Billboard("TestBB", "Character_Diffuse");
|
|
testEnt->AddComponent(testBb);
|
|
|
|
AddEntity(testEnt);
|
|
|
|
lwe::Entity* bullet = new lwe::Entity("Bullet");
|
|
bullet->SetScale({0.1f, 0.1f, 0.1f});
|
|
|
|
bullet->AddComponent(new lwe::Projectile(25));
|
|
bullet->AddComponent(new lwe::Dynamics(50.0f));
|
|
bullet->AddComponent(new lwe::Point3D("Tip"));
|
|
|
|
lwe::SolidColor* bulletMdl = new lwe::SolidColor("Mdl", {1.0f, 1.0f, 0.0f, 1.0f}, "Cube", "");
|
|
bullet->AddComponent(bulletMdl);
|
|
|
|
AddTemplate(bullet);
|
|
}
|
|
|
|
void TestLevel::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
|
|
{
|
|
lwe::GameLoop* gl = (lwe::GameLoop*)GetParent();
|
|
if (!gl)
|
|
return;
|
|
|
|
/*
|
|
lwe::NetSystem* ns = (lwe::NetSystem*)GetSystem("NetSystem");
|
|
if (!ns)
|
|
return;
|
|
|
|
lwe::File configFile("Config.json", lwe::Mode::READ, lwe::Disposition::OPEN);
|
|
configFile.Initialize();
|
|
|
|
lwe::Json config(configFile.ReadStr(configFile.Size()), 0);
|
|
|
|
configFile.UnInitialize();
|
|
|
|
if (gl->GetWindow())
|
|
{
|
|
lwe::Str_8 address = lwe::DNS::Resolve(lwe::AddrType::IPV6, *(lwe::JsonStr*)config.RetrieveValue("client.connectAddress"));
|
|
lwe::UInt_16 port = (lwe::UInt_16)*(lwe::JsonNum*) config.RetrieveValue("client.connectPort");
|
|
ns->GetSocket()->Connect(address, port);
|
|
|
|
EHS_LOG("Info", "TechDemo", 0, "Connecting to server, standby.");
|
|
}
|
|
else
|
|
{
|
|
lwe::Str_8 addr = ((lwe::JsonStr*)config.RetrieveValue("server.address"))->value;
|
|
if (addr.Size())
|
|
addr = lwe::DNS::Resolve(lwe::AddrType::IPV6, addr);
|
|
|
|
lwe::UInt_16 port = (lwe::UInt_16) *(lwe::JsonNum*) config.RetrieveValue("server.port");
|
|
ns->GetSocket()->Bind(addr, port);
|
|
|
|
EHS_LOG("Info", "TechDemo", 0, "Server successfully initialized with the id, \"" + ns->GetSocket()->GetId() + "\".");
|
|
}
|
|
*/
|
|
}
|
|
|
|
void TestLevel::OnUpdate(lwe::Input* input, const float delta)
|
|
{
|
|
lwe::GameLoop* gl = (lwe::GameLoop*)GetParent("GameLoop");
|
|
if (!gl)
|
|
return;
|
|
|
|
lwe::GenericInputHandler* handler = (lwe::GenericInputHandler*)input->GetHandler("GenericInputHandler");
|
|
if (!handler)
|
|
return;
|
|
|
|
const lwe::Mouse* mouse = handler->GetPrimaryMouse();
|
|
const lwe::Keyboard* keyboard = handler->GetPrimaryKeyboard();
|
|
|
|
lwe::Entity* ent = GetEntity("Main");
|
|
|
|
lwe::Entity* ply = GetEntity("Player");
|
|
if (ply)
|
|
{
|
|
lwe::PlyController* cam = (lwe::PlyController*)ply->GetComponent("PlyController", "Head");
|
|
if (cam)
|
|
{
|
|
lwe::CameraSystem* camSys = (lwe::CameraSystem*)GetSystem("CameraSystem");
|
|
if (camSys)
|
|
camSys->SetPrimary(ply->GetHashId(), cam->GetHashId());
|
|
|
|
if (cooldown <= 0.0f && mouse->IsDown(lwe::Mouse::LMB)) // Left Mouse Button
|
|
{
|
|
lwe::AudioSource* gunshot = new lwe::AudioSource("Gunshot_" + lwe::Str_8::FromNum(count), "Gunshot");
|
|
gunshot->SetVolume(1.0f);
|
|
ply->AddComponent(gunshot);
|
|
|
|
lwe::Entity* bullet = CreateEntity("Bullet", "Bullet_" + lwe::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());
|
|
|
|
lwe::Dynamics* dynamics = (lwe::Dynamics*)bullet->GetComponent("Dynamics");
|
|
dynamics->SetVelocity(cam->GetTransform().GetForward() * 100.0f);
|
|
|
|
cooldown = 0.15f;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (cooldown > 0.0f)
|
|
{
|
|
if (cooldown - delta < 0.0f)
|
|
cooldown = 0.0f;
|
|
else
|
|
cooldown -= delta;
|
|
}
|
|
|
|
lwe::GuiSystem* guiSys = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
|
if (!guiSys)
|
|
return;
|
|
|
|
lwe::CollectionGui* stats = (lwe::CollectionGui*)guiSys->GetGui("Stats");
|
|
if (!stats)
|
|
return;
|
|
|
|
lwe::LabelGui* fps = (lwe::LabelGui*)stats->GetChild("FPS");
|
|
fps->SetText("FPS: " + lwe::Str_8::FromNum(gl->GetTPS()));
|
|
|
|
lwe::AudioSource* source = (lwe::AudioSource*)ent->GetComponent("AudioSource3D", "Song");
|
|
if (!source)
|
|
return;
|
|
|
|
lwe::Audio* audio = (lwe::Audio*)GetResource("Audio", source->GetAudioHashId());
|
|
if (!audio)
|
|
return;
|
|
|
|
lwe::LabelGui* playback = (lwe::LabelGui*)stats->GetChild("Playback");
|
|
|
|
lwe::UInt_64 elapsed = source->GetFrameOffset() / audio->GetSampleRate();
|
|
lwe::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));
|
|
|
|
if (keyboard->IsJustReleased(lwe::Keyboard::Left))
|
|
source->SetVolume(source->GetVolume() - 0.25f);
|
|
|
|
if (keyboard->IsJustReleased(lwe::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()));
|
|
|
|
if (keyboard->IsJustReleased(lwe::Keyboard::P))
|
|
{
|
|
if (source->IsPlaying())
|
|
source->Pause();
|
|
else
|
|
source->Play();
|
|
}
|
|
|
|
if (keyboard->IsJustReleased(lwe::Keyboard::Backspace))
|
|
source->Reset();
|
|
}
|