2019-08-24 17:39:35 -07:00
|
|
|
#pragma once
|
2018-12-15 23:55:36 -08:00
|
|
|
|
2020-01-09 21:04:31 -08:00
|
|
|
#include "World.h"
|
|
|
|
|
2021-08-04 22:17:40 -07:00
|
|
|
#include "client/Window.h"
|
2021-06-20 17:50:45 -07:00
|
|
|
#include "client/gui/DebugGui.h"
|
2020-08-13 00:55:18 -07:00
|
|
|
#include "world/dim/LocalDimension.h"
|
|
|
|
#include "client/conn/ClientNetworkInterpreter.h"
|
2018-12-15 23:55:36 -08:00
|
|
|
|
2020-07-28 14:11:11 -07:00
|
|
|
class Renderer;
|
2021-08-03 16:02:34 -07:00
|
|
|
class PerfTimer;
|
2020-07-30 22:07:00 -07:00
|
|
|
class LocalPlayer;
|
2020-07-28 14:11:11 -07:00
|
|
|
class LocalSubgame;
|
2020-07-30 22:07:00 -07:00
|
|
|
class LocalInventoryRefs;
|
2020-02-20 11:23:12 -08:00
|
|
|
class WorldInterpolationStream;
|
2019-06-04 00:05:52 -07:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/**
|
|
|
|
* Manages the local active dimension,
|
|
|
|
* and communication between the client and the server.
|
|
|
|
*/
|
|
|
|
|
2020-01-09 21:04:31 -08:00
|
|
|
class LocalWorld : public World {
|
2020-12-03 16:26:57 -08:00
|
|
|
public:
|
2021-08-03 16:02:34 -07:00
|
|
|
|
2021-07-07 15:39:04 -07:00
|
|
|
LocalWorld(SubgamePtr game, ServerConnection& conn, Renderer& window, vec<string>& perfSections);
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Initializes the world, binding callbacks to the network handler. */
|
|
|
|
void init();
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-04 22:17:40 -07:00
|
|
|
/** Sets the player's dimension to the default one, if it exists. */
|
2020-11-08 22:57:34 -08:00
|
|
|
bool updatePlayerDimension();
|
|
|
|
|
2021-08-04 22:17:40 -07:00
|
|
|
/** Updates the dimension and the player, reads incoming packets, and commits decoded chunks. */
|
2021-08-03 16:02:34 -07:00
|
|
|
void update(f64 delta, vec<usize>& perfTimings, PerfTimer& perf);
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Queues a packet to be read. */
|
|
|
|
void handleWorldPacket(uptr<PacketView> p);
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Reads a player entity packet, and updates the required entity. */
|
|
|
|
void handlePlayerEntPacket(uptr<PacketView> p);
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Triggers a callback in lua for the provided mod message. */
|
|
|
|
void handleModMessage(const string& channel, const string& message);
|
2020-12-06 23:34:25 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Sets a chunk in the current dimension. */
|
|
|
|
void commitChunk(sptr<Chunk> chunk);
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Sends a mod message to the server on the channel specified. */
|
|
|
|
virtual void sendMessage(const string& channel, const string& message) override;
|
2020-12-03 16:26:57 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Creates a new dimension with the identifier and biomes provided. */
|
|
|
|
virtual DimensionPtr createDimension(const string& identifier, std::unordered_set<string>& biomes) override;
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Gets the active dimension. */
|
2020-11-08 22:57:34 -08:00
|
|
|
DimensionPtr getActiveDimension();
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Sets the active dimension. */
|
2020-11-08 22:57:34 -08:00
|
|
|
void setActiveDimension(DimensionPtr);
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Gets the local player. */
|
2020-11-08 22:57:34 -08:00
|
|
|
PlayerPtr getPlayer();
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Returns a reference to the local inventory refs. */
|
2020-11-08 22:57:34 -08:00
|
|
|
virtual InventoryRefsPtr getRefs() override;
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Returns a reference to the network handler. */
|
2020-11-08 22:57:34 -08:00
|
|
|
ClientNetworkInterpreter& getNet();
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** Renders the visible chunks to the screen. */
|
|
|
|
void drawChunks();
|
|
|
|
|
|
|
|
/** Renders the entities to the screen. */
|
2021-06-20 17:50:45 -07:00
|
|
|
void drawEntities();
|
2021-08-03 16:02:34 -07:00
|
|
|
|
|
|
|
/** Renders the interface to the screen using an orthographic projection. */
|
2021-06-20 17:50:45 -07:00
|
|
|
void drawInterface();
|
2020-12-03 16:26:57 -08:00
|
|
|
|
|
|
|
private:
|
2021-08-03 16:02:34 -07:00
|
|
|
|
|
|
|
/** A reference to the renderer. */
|
2020-11-08 22:57:34 -08:00
|
|
|
Renderer& renderer;
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** The network handler. */
|
2020-11-08 22:57:34 -08:00
|
|
|
ClientNetworkInterpreter net;
|
2021-08-03 16:02:34 -07:00
|
|
|
|
|
|
|
/** The local inventories. */
|
|
|
|
sptr<LocalInventoryRefs> refs;
|
|
|
|
|
|
|
|
/** The local player. */
|
2020-11-08 22:57:34 -08:00
|
|
|
PlayerPtr player;
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** The debug interface. */
|
2021-08-19 13:33:08 -07:00
|
|
|
// DebugGui debugGui;
|
2020-11-08 22:57:34 -08:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** The number of chunks that were interpolated last frome. */
|
|
|
|
u32 lastInterpolations = 0;
|
|
|
|
|
|
|
|
/** Whether or not the hud should be visible. */
|
2021-06-20 17:50:45 -07:00
|
|
|
bool hudVisible = true;
|
2021-08-03 16:02:34 -07:00
|
|
|
|
|
|
|
/** Whether or not the debug interface should be visible. */
|
2021-06-20 17:50:45 -07:00
|
|
|
bool debugVisible = true;
|
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** A pointer to the active dimension. */
|
|
|
|
sptr<LocalDimension> activeDimension = nullptr;
|
|
|
|
|
2021-08-23 23:31:29 -07:00
|
|
|
// Window::RCBLock lock;
|
2021-08-04 22:17:40 -07:00
|
|
|
|
2021-08-03 16:02:34 -07:00
|
|
|
/** A reference to the world gen stream. */
|
2021-08-04 22:17:40 -07:00
|
|
|
// sptr<WorldInterpolationStream> worldGenStream;
|
2018-12-15 23:55:36 -08:00
|
|
|
};
|