2019-07-22 01:22:40 -07:00
|
|
|
//
|
|
|
|
// Created by aurailus on 11/01/19.
|
|
|
|
//
|
|
|
|
|
2019-08-24 17:39:35 -07:00
|
|
|
#pragma once
|
2019-07-22 01:22:40 -07:00
|
|
|
|
2020-07-06 18:34:59 -07:00
|
|
|
#include <memory>
|
|
|
|
#include <functional>
|
|
|
|
#include <glm/vec3.hpp>
|
|
|
|
|
2020-07-28 14:11:11 -07:00
|
|
|
#include "../Serializer.h"
|
|
|
|
#include "ServerConnection.h"
|
|
|
|
|
2020-07-06 18:34:59 -07:00
|
|
|
class Model;
|
|
|
|
class Player;
|
2020-07-28 14:11:11 -07:00
|
|
|
class Target;
|
2020-07-06 18:34:59 -07:00
|
|
|
class LocalWorld;
|
|
|
|
class PacketView;
|
2020-07-28 14:11:11 -07:00
|
|
|
class LocalSubgame;
|
|
|
|
enum class NetPlayerField;
|
2019-07-22 01:22:40 -07:00
|
|
|
|
|
|
|
class ClientNetworkInterpreter {
|
|
|
|
public:
|
2020-07-25 20:19:18 -07:00
|
|
|
ClientNetworkInterpreter(ServerConnection& connection, LocalSubgame& defs, Player& player);
|
2019-07-23 23:25:38 -07:00
|
|
|
ClientNetworkInterpreter(const ClientNetworkInterpreter& other) = default;
|
2019-07-22 01:22:40 -07:00
|
|
|
|
2020-03-15 14:26:39 -07:00
|
|
|
void init(LocalWorld* world, std::function<void(std::unique_ptr<PacketView>)> invCallback);
|
2020-02-19 15:20:59 -08:00
|
|
|
void update();
|
|
|
|
|
2020-07-28 14:11:11 -07:00
|
|
|
void blockPlace(Target& target);
|
|
|
|
void blockInteract(Target& target);
|
|
|
|
void blockPlaceOrInteract(Target& target);
|
2019-07-22 01:22:40 -07:00
|
|
|
|
2020-07-21 19:33:26 -07:00
|
|
|
void invWatch(const std::string& inv, const std::string& list);
|
|
|
|
void invUnwatch(const std::string& inv, const std::string& list);
|
|
|
|
void invInteractPrimary(const std::string& inv, const std::string& list, unsigned short ind);
|
|
|
|
void invInteractSecondary(const std::string& inv, const std::string& list, unsigned short ind);
|
2020-03-01 14:33:47 -08:00
|
|
|
|
2020-07-28 14:11:11 -07:00
|
|
|
template <typename T> void assertPlayerField(NetPlayerField field, T data) {
|
|
|
|
Serializer().append(static_cast<unsigned int>(field)).append<T>(data)
|
|
|
|
.packet(PacketType::THIS_PLAYER_INFO).sendTo(connection.getPeer(), PacketChannel::INTERACT);
|
|
|
|
}
|
|
|
|
|
2019-07-22 01:22:40 -07:00
|
|
|
int recvPackets = 0;
|
2020-02-19 15:20:59 -08:00
|
|
|
int serverSideChunkGens = 0;
|
2019-07-22 01:22:40 -07:00
|
|
|
private:
|
2020-03-15 14:26:39 -07:00
|
|
|
void receivedPacket(std::unique_ptr<PacketView> ePacket);
|
2020-02-27 17:23:42 -08:00
|
|
|
|
2020-02-19 15:20:59 -08:00
|
|
|
Player& player;
|
|
|
|
ServerConnection& connection;
|
2019-07-22 01:22:40 -07:00
|
|
|
|
2019-07-22 14:56:19 -07:00
|
|
|
LocalWorld* world = nullptr;
|
2020-02-01 15:47:18 -08:00
|
|
|
std::shared_ptr<Model> playerModel;
|
2020-02-19 15:20:59 -08:00
|
|
|
|
2020-03-15 14:26:39 -07:00
|
|
|
std::function<void(std::unique_ptr<PacketView>)> onInvPacket;
|
2019-07-22 01:22:40 -07:00
|
|
|
};
|
|
|
|
|