generated from Persson-dev/Godot-Xmake
Compare commits
4 Commits
1bd053aba3
...
backup
| Author | SHA1 | Date | |
|---|---|---|---|
| 62c96af003 | |||
| eb85b13ac7 | |||
| d7e80e05de | |||
| f7d0103dbf |
@@ -32,9 +32,9 @@ class World : public godot::Node3D, public protocol::PacketHandler {
|
||||
float m_PassedTime;
|
||||
|
||||
|
||||
void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
||||
void RemovePlayer(PlayerID a_PlayerId);
|
||||
void SetPlayerPositionAndRotation(
|
||||
virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
||||
virtual void RemovePlayer(PlayerID a_PlayerId);
|
||||
virtual void SetPlayerPositionAndRotation(
|
||||
PlayerID a_PlayerId, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity);
|
||||
};
|
||||
} // namespace blitz
|
||||
@@ -20,7 +20,7 @@ class Player : public godot::CharacterBody3D {
|
||||
Player();
|
||||
~Player();
|
||||
|
||||
void _ready();
|
||||
void _ready() override;
|
||||
virtual void _physics_process(float delta);
|
||||
void animate(float delta);
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ class ServerWorld : public World {
|
||||
void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override;
|
||||
|
||||
void SyncPlayersPos();
|
||||
|
||||
protected:
|
||||
virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
@@ -152,7 +152,7 @@ void FirstPersonPlayer::UpdatePosition(float delta) {
|
||||
void FirstPersonPlayer::UpdateFOV(float a_Delta) {
|
||||
float velocityClamped = Math::clamp(get_velocity().length(), MIN_FOV_VELOCITY, MAX_FOV_VELOCITY);
|
||||
float targetFOV = BASE_FOV + FOV_CHANGE * velocityClamped;
|
||||
m_Camera->set_fov(Math::lerp(m_Camera->get_fov(), targetFOV, a_Delta * FOV_TRANSITION));
|
||||
m_Camera->set_fov(Math::lerp(static_cast<float>(m_Camera->get_fov()), targetFOV, a_Delta * FOV_TRANSITION));
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::UpdateAnimation(float delta) {
|
||||
|
||||
@@ -20,7 +20,10 @@ using namespace godot;
|
||||
|
||||
void Player::_bind_methods() {}
|
||||
|
||||
Player::Player() : m_PeerId(0) {}
|
||||
Player::Player() : m_PeerId(0) {
|
||||
// we set the player to an invalid position
|
||||
set_position({-99999, -999999, -999999});
|
||||
}
|
||||
|
||||
Player::~Player() {}
|
||||
|
||||
@@ -31,9 +34,6 @@ void Player::_ready() {
|
||||
DEV_ASSERT(m_Mesh);
|
||||
DEV_ASSERT(m_AnimationTree);
|
||||
|
||||
set_position({0, 0, 0});
|
||||
set_velocity({0, 0, 0});
|
||||
|
||||
animate(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <blitz/godot/NetworkInterface.h>
|
||||
#include <client/Player.h>
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
@@ -41,7 +42,23 @@ void ServerWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotatio
|
||||
if (data.m_Player != a_PlayerPos.m_Sender)
|
||||
return;
|
||||
|
||||
Player* player = GetPlayerById(data.m_Player);
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
if ((data.m_Position - player->get_position()).length() > 10) {
|
||||
UtilityFunctions::print(
|
||||
"Player ", data.m_Player, " moved too fast ! (from ", player->get_position(), " to ", data.m_Position, ")");
|
||||
return;
|
||||
}
|
||||
|
||||
SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity);
|
||||
}
|
||||
|
||||
void ServerWorld::AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName) {
|
||||
World::AddPlayer(a_PlayerId, a_PlayerName);
|
||||
Player* player = GetPlayerById(a_PlayerId);
|
||||
player->set_position({0, 0, 0});
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user