123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "server/entities/ServerPlayer.h"
- #include "utils/Logger.h"
- ServerPlayer::ServerPlayer(Server::Client& client) : client(client) {
- }
- void ServerPlayer::tick() {
- if(!history.canRead()) {
- skip = true;
- return;
- }
- skip = false;
- Entity::tick();
- ControllerPacket cp = history.read();
- Quaternion q = getRotation();
- Vector3 up(0.0f, 1.0f, 0.0f);
- Vector3 back = q * Vector3(0.0f, 0.0f, -1.0f);
- back[1] = 0.0f;
- back.normalize();
- Vector3 right = back.cross(up);
- constexpr float speed = 0.1f;
- if(cp.has(ControllerPacket::Type::DOWN)) {
- addForce(back * speed);
- }
- if(cp.has(ControllerPacket::Type::UP)) {
- addForce(back * -speed);
- }
- if(cp.has(ControllerPacket::Type::LEFT)) {
- addForce(right * -speed);
- }
- if(cp.has(ControllerPacket::Type::RIGHT)) {
- addForce(right * speed);
- }
- if(cp.has(ControllerPacket::Type::JUMP) && isOnGround()) {
- addForce(up * 0.5f);
- }
- if(cp.has(ControllerPacket::Type::SNEAK)) {
- addForce(up * -speed);
- }
- constexpr float rotationSpeed = 4.0f;
- if(cp.has(ControllerPacket::Type::CAM_LEFT)) {
- addLengthAngle(-rotationSpeed);
- }
- if(cp.has(ControllerPacket::Type::CAM_RIGHT)) {
- addLengthAngle(rotationSpeed);
- }
- if(cp.has(ControllerPacket::Type::CAM_UP)) {
- addWidthAngle(-rotationSpeed * 0.5f);
- }
- if(cp.has(ControllerPacket::Type::CAM_DOWN)) {
- addWidthAngle(rotationSpeed * 0.5f);
- }
- }
- void ServerPlayer::onChat(InPacket& in) {
- (void)in;
- }
- void ServerPlayer::send(OutPacket& out) {
- client.send(out);
- }
- void ServerPlayer::onControllerPacket(const ControllerPacket& cp) {
- history.write(cp);
- }
|