diff --git a/Client/src/Layer/RTypeLayer.cpp b/Client/src/Layer/RTypeLayer.cpp index 869ec06d..5c155ac1 100644 --- a/Client/src/Layer/RTypeLayer.cpp +++ b/Client/src/Layer/RTypeLayer.cpp @@ -19,7 +19,7 @@ namespace RType { // Constructor & Destructor // ////////////////////////////// - RTypeLayer::RTypeLayer() : Layer("R-Type"), _WorldNetwork(Exodia::World::CreateWorld()), _Network(nullptr){}; + RTypeLayer::RTypeLayer() : Layer("R-Type"), _Network(nullptr) {}; ///////////// // Methods // @@ -70,8 +70,7 @@ namespace RType { return port; } - void RTypeLayer::ConnectToServer(int port, std::string ip, int serverPort) { - (void)port; + void RTypeLayer::ConnectToServer(UNUSED(int port), std::string ip, int serverPort) { _Network->Loop(); _Network->SendAskConnect(ip, (short)serverPort); } @@ -79,59 +78,54 @@ namespace RType { void RTypeLayer::OnAttach() { EXODIA_PROFILE_FUNCTION(); - int port = GetPort(); + int port = GetPort(); std::string ip = GetIp(); int serverPort = GetServerPort(); - _Network = CreateScope(_WorldNetwork, _IOContextManager, port); if (port == -1) return; + _Scene = CreateRef("Stage 1"); - // Create world - CurrentScene = GAME; + _Network = CreateScope(_Scene->GetWorldPtr(), _IOContextManager, port); + // Create world CollisionSystem *collisionSystem = new CollisionSystem(); - Scenes[GAME] = CreateRef(); - Scenes[GAME]->RegisterSystem(new AnimationSystem()); - Scenes[GAME]->RegisterSystem(new MovingSystem(1.5f)); - Scenes[GAME]->RegisterSystem(collisionSystem); - Scenes[GAME]->RegisterSystem(new ClockSystem()); - - Scenes[GAME]->Subscribe(collisionSystem); - Scenes[GAME]->OnViewportResize(Application::Get().GetWindow().GetWidth(), - Application::Get().GetWindow().GetHeight()); + _Scene->RegisterSystem(new AnimationSystem()); + _Scene->RegisterSystem(new MovingSystem(1.5f)); + _Scene->RegisterSystem(collisionSystem); + _Scene->RegisterSystem(new ClockSystem()); - // TODO: Temp code + _Scene->Subscribe(collisionSystem); // Create the camera entity - GameObject cameraEntity = Scenes[GAME]->CreateEntity("Camera"); + GameObject cameraEntity = _Scene->CreateEntity("Camera"); CameraComponent &camera = cameraEntity.AddComponent(); - cameraEntity.GetComponent().Translation = {0.0f, 0.0f, 15.0f}; - + cameraEntity.GetComponent().Translation = { 0.0f, 0.0f, 15.0f }; camera.Camera.SetProjectionType(SceneCamera::ProjectionType::Perspective); - camera.Camera.SetViewportSize(Application::Get().GetWindow().GetWidth(), - Application::Get().GetWindow().GetHeight()); for (int i = 0; i < 60; i++) { - GameObject star = Scenes[GAME]->CreateEntity("Star" + std::to_string(i)); + GameObject star = _Scene->CreateEntity("Star" + std::to_string(i)); star.AddComponent().Bind("Star"); } - Scenes[CurrentScene]->OnRuntimeStart(); + GameObject player = _Scene->CreateEntity("Player_0"); + + player.AddComponent().Bind("Player"); - _Network->SetWorld(Scenes[CurrentScene]->GetWorldPtr()); + _Scene->OnViewportResize(Application::Get().GetWindow().GetWidth(), Application::Get().GetWindow().GetHeight()); + _Scene->OnRuntimeStart(); ConnectToServer(port, ip, serverPort); } void RTypeLayer::OnDetach() { EXODIA_PROFILE_FUNCTION(); + _Network->SendDisconnect(); - EXODIA_CORE_ERROR("RTypeLayer::OnDetach()"); } void RTypeLayer::OnUpdate(Exodia::Timestep ts) { @@ -147,17 +141,15 @@ namespace RType { Exodia::RenderCommand::Clear(); } - // Update - if (CurrentScene == GAME) { - }; - _packetTimer += ts; + if (_packetTimer >= 1) { _Network->SendPacketInfo(); _packetTimer = 0; } + // Update the world - Scenes[CurrentScene]->OnUpdateRuntime(ts); + _Scene->OnUpdateRuntime(ts); } void RTypeLayer::OnImGUIRender() { @@ -198,11 +190,10 @@ namespace RType { } bool RTypeLayer::OnKeyPressedEvent(KeyPressedEvent &event) { - int key = event.GetKeyCode(); - Scenes[CurrentScene]->GetWorld().LockMutex(); - Scenes[CurrentScene]->GetWorld().ForEach( + _Scene->GetWorld().LockMutex(); + _Scene->GetWorld().ForEach( [&](Entity *entity, ComponentHandle script, ComponentHandle tag) { ScriptComponent &sc = script.Get(); TagComponent &tc = tag.Get(); @@ -218,7 +209,7 @@ namespace RType { } (void)entity; }); - Scenes[CurrentScene]->GetWorld().UnlockMutex(); + _Scene->GetWorld().UnlockMutex(); return true; }; @@ -226,8 +217,8 @@ namespace RType { bool RTypeLayer::OnKeyReleasedEvent(KeyReleasedEvent &event) { int key = event.GetKeyCode(); - Scenes[CurrentScene]->GetWorld().LockMutex(); - Scenes[CurrentScene]->GetWorld().ForEach( + _Scene->GetWorld().LockMutex(); + _Scene->GetWorld().ForEach( [&](Entity *entity, ComponentHandle script, ComponentHandle tag) { ScriptComponent &sc = script.Get(); TagComponent &tc = tag.Get(); @@ -243,14 +234,14 @@ namespace RType { (void)entity; }); - Scenes[CurrentScene]->GetWorld().UnlockMutex(); + _Scene->GetWorld().UnlockMutex(); return false; }; bool RTypeLayer::OnWindowResizeEvent(WindowResizeEvent &event) { - if (Scenes[CurrentScene] != nullptr) - Scenes[CurrentScene]->OnViewportResize(event.GetWidth(), event.GetHeight()); + if (_Scene != nullptr) + _Scene->OnViewportResize(event.GetWidth(), event.GetHeight()); return true; } diff --git a/Client/src/Layer/RTypeLayer.hpp b/Client/src/Layer/RTypeLayer.hpp index 7cdb5b88..40dc06d5 100644 --- a/Client/src/Layer/RTypeLayer.hpp +++ b/Client/src/Layer/RTypeLayer.hpp @@ -49,12 +49,10 @@ namespace RType { // Attributes // //////////////// public: - inline static std::map> Scenes; - inline static SceneType CurrentScene; + inline static Ref _Scene; private: // TODO: WARNING: This is a temporary solution - World *_WorldNetwork; float _packetTimer = 0; Network::IOContextManager _IOContextManager; Scope _Network; diff --git a/R-Type/src/Scripts/Player/Player.cpp b/R-Type/src/Scripts/Player/Player.cpp index 655074b6..d26295d9 100644 --- a/R-Type/src/Scripts/Player/Player.cpp +++ b/R-Type/src/Scripts/Player/Player.cpp @@ -272,10 +272,8 @@ namespace RType { } if (keycode == Key::W) { // Up - _State = State::MOVE_UP; velocity.Velocity.y = 5.0f; } else if (keycode == Key::S) { // Down - _State = State::MOVE_DOWN; velocity.Velocity.y = -5.0f; } } diff --git a/imgui.ini b/imgui.ini index 3d36958a..11f8a767 100644 --- a/imgui.ini +++ b/imgui.ini @@ -4,8 +4,9 @@ Size=400,400 Collapsed=0 [Window][R-Type Statistics] -Pos=18,17 -Size=189,218 +ViewportPos=1658,144 +ViewportId=0xCBF0614C +Size=229,397 Collapsed=0 [Docking][Data]