Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
PharaEthan committed Jan 13, 2024
1 parent 7b42ca5 commit 7e0f344
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 47 deletions.
71 changes: 31 additions & 40 deletions Client/src/Layer/RTypeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
Expand Down Expand Up @@ -70,68 +70,62 @@ 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);
}

void RTypeLayer::OnAttach() {
EXODIA_PROFILE_FUNCTION();

int port = GetPort();
int port = GetPort();
std::string ip = GetIp();
int serverPort = GetServerPort();
_Network = CreateScope<Network::Network>(_WorldNetwork, _IOContextManager, port);

if (port == -1)
return;
_Scene = CreateRef<Scene>("Stage 1");

// Create world
CurrentScene = GAME;
_Network = CreateScope<Network::Network>(_Scene->GetWorldPtr(), _IOContextManager, port);

// Create world
CollisionSystem *collisionSystem = new CollisionSystem();

Scenes[GAME] = CreateRef<Scene>();
Scenes[GAME]->RegisterSystem(new AnimationSystem());
Scenes[GAME]->RegisterSystem(new MovingSystem(1.5f));
Scenes[GAME]->RegisterSystem(collisionSystem);
Scenes[GAME]->RegisterSystem(new ClockSystem());

Scenes[GAME]->Subscribe<Exodia::Events::OnCollisionEntered>(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<Exodia::Events::OnCollisionEntered>(collisionSystem);

// Create the camera entity
GameObject cameraEntity = Scenes[GAME]->CreateEntity("Camera");
GameObject cameraEntity = _Scene->CreateEntity("Camera");

CameraComponent &camera = cameraEntity.AddComponent<CameraComponent>();

cameraEntity.GetComponent<TransformComponent>().Translation = {0.0f, 0.0f, 15.0f};

cameraEntity.GetComponent<TransformComponent>().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<ScriptComponent>().Bind("Star");
}

Scenes[CurrentScene]->OnRuntimeStart();
GameObject player = _Scene->CreateEntity("Player_0");

player.AddComponent<ScriptComponent>().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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -198,11 +190,10 @@ namespace RType {
}

bool RTypeLayer::OnKeyPressedEvent(KeyPressedEvent &event) {

int key = event.GetKeyCode();

Scenes[CurrentScene]->GetWorld().LockMutex();
Scenes[CurrentScene]->GetWorld().ForEach<ScriptComponent, TagComponent>(
_Scene->GetWorld().LockMutex();
_Scene->GetWorld().ForEach<ScriptComponent, TagComponent>(
[&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();
Expand All @@ -218,16 +209,16 @@ namespace RType {
}
(void)entity;
});
Scenes[CurrentScene]->GetWorld().UnlockMutex();
_Scene->GetWorld().UnlockMutex();

return true;
};

bool RTypeLayer::OnKeyReleasedEvent(KeyReleasedEvent &event) {
int key = event.GetKeyCode();

Scenes[CurrentScene]->GetWorld().LockMutex();
Scenes[CurrentScene]->GetWorld().ForEach<ScriptComponent, TagComponent>(
_Scene->GetWorld().LockMutex();
_Scene->GetWorld().ForEach<ScriptComponent, TagComponent>(
[&](Entity *entity, ComponentHandle<ScriptComponent> script, ComponentHandle<TagComponent> tag) {
ScriptComponent &sc = script.Get();
TagComponent &tc = tag.Get();
Expand All @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions Client/src/Layer/RTypeLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ namespace RType {
// Attributes //
////////////////
public:
inline static std::map<SceneType, Ref<Scene>> Scenes;
inline static SceneType CurrentScene;
inline static Ref<Scene> _Scene;

private:
// TODO: WARNING: This is a temporary solution
World *_WorldNetwork;
float _packetTimer = 0;
Network::IOContextManager _IOContextManager;
Scope<Network::Network> _Network;
Expand Down
2 changes: 0 additions & 2 deletions R-Type/src/Scripts/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
5 changes: 3 additions & 2 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7e0f344

Please sign in to comment.