1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #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);
- Vector3 force;
- if(cp.has(ControllerPacket::Type::DOWN)) {
- force += back;
- }
- if(cp.has(ControllerPacket::Type::UP)) {
- force -= back;
- }
- if(cp.has(ControllerPacket::Type::LEFT)) {
- force -= right;
- }
- if(cp.has(ControllerPacket::Type::RIGHT)) {
- force += right;
- }
- if(force.squareLength() > 0.0f) {
- force.normalize();
- }
- addForce(force * 0.1f);
- if(cp.has(ControllerPacket::Type::JUMP) && isOnGround()) {
- addForce(up * (0.42f / 0.98f + 0.08f));
- }
- 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);
- }
|