feat: sync entity direction and rotate models accordingly

Move direction into the transform component and include it in server-to-client entity updates. Client now sets transform direction from the network message and uses it to compute yaw for model rotation, so entities visually face their movement direction. Refactor net_utils to support arbitrary Vec3 fields.
This commit is contained in:
2026-08-04 10:46:31 +08:00
parent 6b1f9d7354
commit e2bbc2d57f
12 changed files with 37 additions and 18 deletions

View File

@@ -35,6 +35,7 @@ private:
struct UpdateInfo {
EntityID id;
glm::vec3 pos;
glm::vec3 direction;
};
using EntityMap = tbb::concurrent_hash_map<EntityID, entt::entity>;

View File

@@ -12,8 +12,6 @@ struct BaseServerCreature {
Movement movement{};
Direction direction{};
Gravity gravity{};
Health health{};

View File

@@ -11,9 +11,11 @@ class Camera;
class ModelRender {
public:
ModelRender(Renderer& renderer);
void render_model(ModelID id, const glm::vec3& pos, Camera& camera);
void render_model(ModelID id, const glm::vec3& pos, float yaw,
Camera& camera);
void shadow_pass(ModelID id, const glm::vec3& pos, Camera& camera);
void shadow_pass(ModelID id, const glm::vec3& pos, float yaw,
Camera& camera);
private:
Renderer& m_renderer;

View File

@@ -5,16 +5,19 @@
#include "glm/ext/vector_float3.hpp"
namespace Cubed {
namespace Tools {
template <Ptr T> void set_net_pos(T ptr, const glm::vec3& pos) {
Vec3* p = ptr->mutable_pos();
inline void set_net_vec3(Vec3* p, const glm::vec3& pos) {
p->set_x(pos.x);
p->set_y(pos.y);
p->set_z(pos.z);
}
inline glm::vec3 get_net_pos(const Vec3* p) {
template <Ptr T> void set_net_pos(T ptr, const glm::vec3& pos) {
set_net_vec3(ptr->mutable_pos(), pos);
}
inline glm::vec3 get_net_vec3(const Vec3* p) {
return glm::vec3{p->x(), p->y(), p->z()};
}
inline glm::vec3 get_net_pos(const Vec3& p) {
inline glm::vec3 get_net_vec3(const Vec3& p) {
return glm::vec3{p.x(), p.y(), p.z()};
}
} // namespace Tools