generated from Persson-dev/Godot-Xmake
make world abstract
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m36s
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m36s
This commit is contained in:
38
src/server/ServerWorld.cpp
Normal file
38
src/server/ServerWorld.cpp
Normal 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
|
||||
Reference in New Issue
Block a user