make world abstract
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m36s

This commit is contained in:
2024-08-19 16:19:45 +02:00
parent 3cebb70289
commit a092f6fbc1
14 changed files with 180 additions and 65 deletions

View File

@@ -0,0 +1,38 @@
#include <server/ServerWorld.h>
#include <blitz/godot/NetworkInterface.h>
#include <client/Player.h>
#include <godot_cpp/classes/engine.hpp>
namespace blitz {
using namespace godot;
void ServerWorld::_bind_methods() {}
ServerWorld::ServerWorld() {}
ServerWorld::~ServerWorld() {}
void ServerWorld::_process(float delta) {
#if DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint())
return;
#endif
m_PassedTime += delta;
if (m_PassedTime < 0.05f)
return;
SyncPlayersPos();
}
void ServerWorld::SyncPlayersPos() {
for (int i = 0; i < m_Players->get_child_count(); i++) {
Player* player = Object::cast_to<Player>(m_Players->get_child(i));
DEV_ASSERT(player);
m_NetworkInterface->BroadcastPacket(
protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()}));
}
}
} // namespace blitz