Create ClientModHandler, rename Local/ServerDefs to Client/ServerGame
parent
3c128c95d6
commit
9c48fb694d
|
@ -107,8 +107,8 @@ set(ZEPHA_SRC
|
|||
def/texture/TextureAtlas.h
|
||||
def/texture/AtlasRef.h
|
||||
world/region/MapBlock.h
|
||||
def/LocalDefs.cpp
|
||||
def/LocalDefs.h
|
||||
def/ClientGame.cpp
|
||||
def/ClientGame.h
|
||||
world/region/Region.cpp
|
||||
world/region/MapBlock.cpp
|
||||
util/Util.h
|
||||
|
@ -117,8 +117,8 @@ set(ZEPHA_SRC
|
|||
game/hud/components/compound/GUILabelledGraph.cpp
|
||||
game/entity/world/ParticleEntity.cpp
|
||||
game/entity/world/ParticleEntity.h
|
||||
def/ServerDefs.cpp
|
||||
def/ServerDefs.h
|
||||
def/ServerGame.cpp
|
||||
def/ServerGame.h
|
||||
def/ServerDefinitionAtlas.cpp
|
||||
def/ServerDefinitionAtlas.h
|
||||
def/item/BlockDef.cpp
|
||||
|
@ -295,6 +295,6 @@ set(ZEPHA_SRC
|
|||
lua/VenusParser.h
|
||||
lua/ErrorFormatter.cpp
|
||||
lua/ErrorFormatter.h
|
||||
util/RIE.h lua/api/type/ServerLuaPlayer.cpp lua/api/type/ServerLuaPlayer.h lua/api/type/sServerLuaPlayer.h lua/api/modules/register_on.h lua/api/functions/trigger_event.h lua/parser/ServerModHandler.cpp lua/parser/ServerModHandler.h)
|
||||
util/RIE.h lua/api/type/ServerLuaPlayer.cpp lua/api/type/ServerLuaPlayer.h lua/api/type/sServerLuaPlayer.h lua/api/modules/register_on.h lua/api/functions/trigger_event.h lua/parser/ServerModHandler.cpp lua/parser/ServerModHandler.h lua/parser/LocalModHandler.cpp lua/parser/LocalModHandler.h)
|
||||
|
||||
add_library (Zepha_Core ${ZEPHA_SRC})
|
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Created by aurailus on 18/04/19.
|
||||
//
|
||||
|
||||
#include "ClientGame.h"
|
||||
|
||||
//Note: This constructor is only for *uninitialized* LocalDef objects!
|
||||
ClientGame::ClientGame(const ClientGame ©) : ClientGame(copy.tex_path) {}
|
||||
|
||||
ClientGame::ClientGame(const std::string& path) :
|
||||
tex_path(path),
|
||||
|
||||
parser(),
|
||||
biomes(),
|
||||
textures(2048),
|
||||
defs(textures) {
|
||||
|
||||
textures.loadDirectory(tex_path);
|
||||
}
|
||||
|
||||
void ClientGame::init(LocalWorld &world, Player& player) {
|
||||
parser.init(*this, world, player);
|
||||
}
|
||||
|
||||
void ClientGame::update(double delta, bool* keys) {
|
||||
parser.update(delta, keys);
|
||||
}
|
|
@ -10,20 +10,20 @@
|
|||
#include "texture/TextureAtlas.h"
|
||||
#include "../lua/parser/LocalLuaParser.h"
|
||||
|
||||
class LocalDefs {
|
||||
class ClientGame {
|
||||
public:
|
||||
explicit LocalDefs(const std::string& tex_path);
|
||||
LocalDefs(const LocalDefs& copy);
|
||||
explicit ClientGame(const std::string& tex_path);
|
||||
ClientGame(const ClientGame& copy);
|
||||
|
||||
void init(LocalWorld &world, Player& player);
|
||||
void update(double delta, bool* keys);
|
||||
|
||||
~LocalDefs() = default;
|
||||
~ClientGame() = default;
|
||||
|
||||
std::string tex_path;
|
||||
|
||||
TextureAtlas textures;
|
||||
LocalLuaParser luaApi;
|
||||
LocalLuaParser parser;
|
||||
LocalDefinitionAtlas defs;
|
||||
LocalBiomeAtlas biomes;
|
||||
ModelStore models;
|
|
@ -1,27 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 18/04/19.
|
||||
//
|
||||
|
||||
#include "LocalDefs.h"
|
||||
|
||||
//Note: This constructor is only for *uninitialized* LocalDef objects!
|
||||
LocalDefs::LocalDefs(const LocalDefs ©) : LocalDefs(copy.tex_path) {}
|
||||
|
||||
LocalDefs::LocalDefs(const std::string& path) :
|
||||
tex_path(path),
|
||||
|
||||
luaApi(),
|
||||
biomes(),
|
||||
textures(2048),
|
||||
defs(textures) {
|
||||
|
||||
textures.loadDirectory(tex_path);
|
||||
}
|
||||
|
||||
void LocalDefs::init(LocalWorld &world, Player& player) {
|
||||
luaApi.init(*this, world, player);
|
||||
}
|
||||
|
||||
void LocalDefs::update(double delta, bool* keys) {
|
||||
luaApi.update(delta, keys);
|
||||
}
|
|
@ -2,10 +2,10 @@
|
|||
// Created by aurailus on 10/06/19.
|
||||
//
|
||||
|
||||
#include "ServerDefs.h"
|
||||
#include "ServerGame.h"
|
||||
#include "../server/conn/ClientList.h"
|
||||
|
||||
ServerDefs::ServerDefs(const std::string& subgame, const std::string& execPath) {
|
||||
ServerGame::ServerGame(const std::string& subgame, const std::string& execPath) {
|
||||
size_t exec = execPath.find_last_of('/');
|
||||
std::string gamePath = execPath.substr(0, exec + 1);
|
||||
subgamePath += "subgames/" + subgame + "/";
|
||||
|
@ -20,10 +20,10 @@ ServerDefs::ServerDefs(const std::string& subgame, const std::string& execPath)
|
|||
}
|
||||
}
|
||||
|
||||
void ServerDefs::init(ServerWorld &world) {
|
||||
luaApi.init(*this, world, subgamePath);
|
||||
void ServerGame::init(ServerWorld &world) {
|
||||
parser.init(*this, world, subgamePath);
|
||||
}
|
||||
|
||||
void ServerDefs::update(double delta, ClientList& clients) {
|
||||
luaApi.update(delta);
|
||||
void ServerGame::update(double delta, ClientList& clients) {
|
||||
parser.update(delta);
|
||||
}
|
|
@ -13,19 +13,19 @@
|
|||
class ServerWorld;
|
||||
class ClientList;
|
||||
|
||||
class ServerDefs {
|
||||
class ServerGame {
|
||||
public:
|
||||
ServerDefs(const std::string& subgame, const std::string& execPath);
|
||||
ServerGame(const std::string& subgame, const std::string& execPath);
|
||||
void init(ServerWorld& world);
|
||||
|
||||
void update(double delta, ClientList& clients);
|
||||
|
||||
~ServerDefs() = default;
|
||||
~ServerGame() = default;
|
||||
std::string subgamePath = "";
|
||||
|
||||
ServerDefinitionAtlas defs;
|
||||
ServerLuaParser luaApi;
|
||||
ServerBiomeAtlas biomes;
|
||||
AssetStorage assets;
|
||||
ServerLuaParser parser;
|
||||
ServerBiomeAtlas biomes;
|
||||
AssetStorage assets;
|
||||
};
|
||||
|
|
@ -10,8 +10,8 @@
|
|||
#include <noise/noise.h>
|
||||
|
||||
#include "MapGenJob.h"
|
||||
#include "../LocalDefs.h"
|
||||
#include "BiomeAtlas.h"
|
||||
#include "../ClientGame.h"
|
||||
#include "../../world/chunk/BlockChunk.h"
|
||||
|
||||
using namespace noise;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include "AtlasRef.h"
|
||||
#include "../LocalDefs.h"
|
||||
#include "../ClientGame.h"
|
||||
|
||||
class Font {
|
||||
public:
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "graph/Renderer.h"
|
||||
#include "scene/net/ClientNetworkInterpreter.h"
|
||||
#include "../def/LocalDefs.h"
|
||||
#include "../def/ClientGame.h"
|
||||
#include "scene/net/ServerConnection.h"
|
||||
|
||||
class ClientState {
|
||||
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
Renderer& renderer;
|
||||
ServerConnection connection {};
|
||||
LocalDefs defs;
|
||||
ClientGame defs;
|
||||
|
||||
std::string desiredState = "this";
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "Collidable.h"
|
||||
|
||||
Collidable::Collidable(LocalWorld &world, LocalDefs& defs, const SelectionBox& collisionBox) :
|
||||
Collidable::Collidable(LocalWorld &world, ClientGame& defs, const SelectionBox& collisionBox) :
|
||||
world(world),
|
||||
defs(defs),
|
||||
collisionBox(collisionBox) {}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
class Collidable {
|
||||
public:
|
||||
Collidable(LocalWorld& world, LocalDefs& defs, const SelectionBox& collisionBox);
|
||||
Collidable(LocalWorld& world, ClientGame& defs, const SelectionBox& collisionBox);
|
||||
|
||||
void moveCollide(float stepUpAmount = 0);
|
||||
bool isOnGround();
|
||||
|
@ -17,7 +17,7 @@ public:
|
|||
glm::vec3 vel {};
|
||||
protected:
|
||||
LocalWorld& world;
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
SelectionBox collisionBox {};
|
||||
private:
|
||||
bool collidesAt(glm::vec3& pos, float stepUpMax = 0);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "BlockCrackEntity.h"
|
||||
|
||||
|
||||
BlockCrackEntity::BlockCrackEntity(LocalDefs &defs, glm::vec3 blockPos, unsigned int blockID) :
|
||||
BlockCrackEntity::BlockCrackEntity(ClientGame &defs, glm::vec3 blockPos, unsigned int blockID) :
|
||||
defs(defs),
|
||||
blockPos(blockPos),
|
||||
blockID(blockID) {
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "../Entity.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
#include "../../../def/ClientGame.h"
|
||||
|
||||
class BlockCrackEntity : public Entity {
|
||||
public:
|
||||
explicit BlockCrackEntity(LocalDefs &defs, glm::vec3 blockPos, unsigned int blockID);
|
||||
explicit BlockCrackEntity(ClientGame &defs, glm::vec3 blockPos, unsigned int blockID);
|
||||
|
||||
void update();
|
||||
void setNewDamage(float damage);
|
||||
|
@ -25,5 +25,5 @@ private:
|
|||
void addFaces(unsigned int &indOffset, std::vector<EntityVertex> &vertices, std::vector<unsigned int> &indices, std::vector<MeshPart> &meshParts);
|
||||
|
||||
std::vector<std::shared_ptr<AtlasRef>> crackedFaces;
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "../../def/texture/Font.h"
|
||||
#include "components/compound/GUIInventoryList.h"
|
||||
|
||||
DebugGui::DebugGui(glm::vec2 bufferSize, LocalDefs& defs) :
|
||||
DebugGui::DebugGui(glm::vec2 bufferSize, ClientGame& defs) :
|
||||
displayMode(0) {
|
||||
|
||||
auto fpsHistogramRef = defs.textures["histogram"];
|
||||
|
@ -71,7 +71,7 @@ void DebugGui::positionElements(glm::vec2 bufferSize) {
|
|||
get<GUILabelledGraph>("gpuGraph")->setPos({bufferWidth - 254, 90 + 80});
|
||||
}
|
||||
|
||||
void DebugGui::update(Player& player, LocalWorld& world, LocalDefs& defs, double fps, int /*chunks*/, int drawCalls, int ssGen, int ssPack) {
|
||||
void DebugGui::update(Player& player, LocalWorld& world, ClientGame& defs, double fps, int /*chunks*/, int drawCalls, int ssGen, int ssPack) {
|
||||
|
||||
{ //Top Right Graphs
|
||||
get<GUILabelledGraph>("fpsGraph")->pushValue(static_cast<float>(fps));
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
class DebugGui : public GUIContainer {
|
||||
public:
|
||||
DebugGui(glm::vec2 bufferSize, LocalDefs& atlas);
|
||||
DebugGui(glm::vec2 bufferSize, ClientGame& atlas);
|
||||
|
||||
void bufferResized(glm::vec2 bufferSize);
|
||||
void changeVisibilityState(int state);
|
||||
void positionElements(glm::vec2 bufferSize);
|
||||
|
||||
void update(Player& player, LocalWorld& world, LocalDefs& defs, double fps, int chunks, int drawCalls, int ssGen, int ssPack);
|
||||
void update(Player& player, LocalWorld& world, ClientGame& defs, double fps, int chunks, int drawCalls, int ssGen, int ssPack);
|
||||
private:
|
||||
int displayMode;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "GameGui.h"
|
||||
#include "components/compound/GUIInventoryList.h"
|
||||
|
||||
GameGui::GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize, LocalDefs& defs, Renderer& renderer) :
|
||||
GameGui::GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize, ClientGame& defs, Renderer& renderer) :
|
||||
menuRoot(std::make_shared<GUIContainer>("__luaroot")),
|
||||
handList(std::make_shared<GUIInventoryList>("hand")),
|
||||
builder(inventory, hand, defs, menuRoot),
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
class GameGui : public GUIContainer {
|
||||
public:
|
||||
explicit GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize, LocalDefs& defs, Renderer& renderer);
|
||||
explicit GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize, ClientGame& defs, Renderer& renderer);
|
||||
void winResized(glm::ivec2 win);
|
||||
|
||||
void update(double delta) override;
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
void drawViginette(Renderer& renderer);
|
||||
private:
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
Renderer& renderer;
|
||||
|
||||
glm::ivec2 win {};
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
class GameGuiBuilder : public GuiBuilder {
|
||||
public:
|
||||
GameGuiBuilder(Inventory& inventory, InventoryList& hand, LocalDefs& defs, std::shared_ptr<GUIContainer> root) :
|
||||
GameGuiBuilder(Inventory& inventory, InventoryList& hand, ClientGame& defs, std::shared_ptr<GUIContainer> root) :
|
||||
inventory(inventory), hand(hand), GuiBuilder(defs, root) {};
|
||||
|
||||
std::shared_ptr<GUIComponent> createComponent(SerializedGuiElem& data) override;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "GuiBuilder.h"
|
||||
|
||||
GuiBuilder::GuiBuilder(LocalDefs& defs, std::shared_ptr<GUIContainer> root) :
|
||||
GuiBuilder::GuiBuilder(ClientGame& defs, std::shared_ptr<GUIContainer> root) :
|
||||
defs(defs), root(root) {}
|
||||
|
||||
void GuiBuilder::setGui(const std::string& menu, const std::map<std::string, ComponentCallbacks>& callbacks) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "SerializedGuiElem.h"
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
#include "components/basic/GUIRect.h"
|
||||
#include "components/basic/GUIText.h"
|
||||
#include "components/basic/GUIModel.h"
|
||||
|
@ -20,7 +20,7 @@ public:
|
|||
GUIComponent::callback left {}, right {}, hover {};
|
||||
};
|
||||
|
||||
GuiBuilder(LocalDefs& defs, std::shared_ptr<GUIContainer> root);
|
||||
GuiBuilder(ClientGame& defs, std::shared_ptr<GUIContainer> root);
|
||||
void setGui(const std::string& menu, const std::map<std::string, ComponentCallbacks>& callbacks = {});
|
||||
void build(glm::ivec2 win);
|
||||
void clear(bool clrCallbacks = true);
|
||||
|
@ -50,5 +50,5 @@ protected:
|
|||
|
||||
std::shared_ptr<GUIContainer> root;
|
||||
std::vector<SerializedGuiElem> components {};
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
GUIInventoryList::GUIInventoryList(const std::string &key) : GUIContainer(key) {}
|
||||
|
||||
void GUIInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList &list, InventoryList& hand, LocalDefs &defs) {
|
||||
void GUIInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList &list, InventoryList& hand, ClientGame &defs) {
|
||||
this->list = &list;
|
||||
this->hand = &hand;
|
||||
this->defs = &defs;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../basic/GUIContainer.h"
|
||||
#include "../../../../def/LocalDefs.h"
|
||||
#include "../../../../def/ClientGame.h"
|
||||
#include "../basic/GUIRect.h"
|
||||
#include "../basic/GUIInventoryItem.h"
|
||||
#include "../../../../def/texture/Font.h"
|
||||
|
@ -17,7 +17,7 @@ public:
|
|||
GUIInventoryList(const std::string& key);
|
||||
~GUIInventoryList() override;
|
||||
|
||||
void create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList& list, InventoryList& hand, LocalDefs& defs);
|
||||
void create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 innerPadding, InventoryList& list, InventoryList& hand, ClientGame& defs);
|
||||
|
||||
void setHoverCallback(const callback& hoverCallback) override;
|
||||
void setLeftClickCallback(const callback& leftClickCallback) override;
|
||||
|
@ -32,6 +32,6 @@ private:
|
|||
|
||||
InventoryList* list;
|
||||
InventoryList* hand;
|
||||
LocalDefs* defs;
|
||||
ClientGame* defs;
|
||||
glm::ivec2 innerPadding;
|
||||
};
|
||||
|
|
|
@ -90,10 +90,10 @@ void ConnectScene::update() {
|
|||
if (p.type == PacketType::MODS) {
|
||||
auto luaMod = LuaMod::fromPacket(p);
|
||||
statusText->setText(statusText->getText() + "Received mod " + luaMod.config.name + ".\n");
|
||||
state.defs.luaApi.mods.push_back(std::move(luaMod));
|
||||
state.defs.parser.getHandler().addLuaMod(std::move(luaMod));
|
||||
}
|
||||
else if (p.type == PacketType::MOD_ORDER) {
|
||||
state.defs.luaApi.modsOrder = d.read<std::vector<std::string>>();
|
||||
state.defs.parser.getHandler().setModsOrder(d.read<std::vector<std::string>>());
|
||||
|
||||
statusText->setText(statusText->getText() + "Done downloading mods.\nReceived the mods order.\nDownloading media...\n");
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "../entity/world/WireframeEntity.h"
|
||||
#include "../entity/world/BlockCrackEntity.h"
|
||||
#include "../entity/Model.h"
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
|
||||
class GameScene : public Scene {
|
||||
public:
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
void cleanup() override;
|
||||
public:
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
|
||||
glm::vec3 playerPos;
|
||||
Player player;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
//#include "../../graph/drawable/DrawableGroup.h"
|
||||
//#include "../../../util/net/Address.h"
|
||||
|
||||
ClientNetworkInterpreter::ClientNetworkInterpreter(ServerConnection &connection, LocalDefs &defs, Player& player) :
|
||||
ClientNetworkInterpreter::ClientNetworkInterpreter(ServerConnection &connection, ClientGame &defs, Player& player) :
|
||||
world(nullptr),
|
||||
player(player),
|
||||
connection(connection),
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
class ClientNetworkInterpreter {
|
||||
public:
|
||||
ClientNetworkInterpreter(ServerConnection& connection, LocalDefs& defs, Player& player);
|
||||
ClientNetworkInterpreter(ServerConnection& connection, ClientGame& defs, Player& player);
|
||||
ClientNetworkInterpreter(const ClientNetworkInterpreter& other) = default;
|
||||
|
||||
void init(LocalWorld* world);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "LocalWorld.h"
|
||||
#include "../net/ClientNetworkInterpreter.h"
|
||||
|
||||
LocalWorld::LocalWorld(LocalDefs& defs, glm::vec3* playerPos, ClientNetworkInterpreter* server) :
|
||||
LocalWorld::LocalWorld(ClientGame& defs, glm::vec3* playerPos, ClientNetworkInterpreter* server) :
|
||||
dimension(defs),
|
||||
defs(defs),
|
||||
server(server),
|
||||
|
@ -149,13 +149,13 @@ void LocalWorld::localSetBlock(glm::ivec3 pos, unsigned int block) {
|
|||
if (block == LocalDefinitionAtlas::AIR) {
|
||||
auto def = defs.defs.blockFromId(getBlock(pos));
|
||||
if (def.callbacks.count(Callback::BREAK_CLIENT)) {
|
||||
def.callbacks[Callback::BREAK_CLIENT](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::BREAK_CLIENT](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto def = defs.defs.blockFromId(block);
|
||||
if (def.callbacks.count(Callback::PLACE_CLIENT)) {
|
||||
def.callbacks[Callback::PLACE_CLIENT](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::PLACE_CLIENT](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "../../../util/Space.h"
|
||||
#include "../../../util/Vec.h"
|
||||
#include "../../../world/LocalDimension.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
#include "../../../def/ClientGame.h"
|
||||
#include "../../../world/block/PointedThing.h"
|
||||
#include "../../../game/graph/drawable/DrawableGroup.h"
|
||||
#include "../../entity/world/BlockCrackEntity.h"
|
||||
|
@ -34,7 +34,7 @@ class ClientNetworkInterpreter;
|
|||
|
||||
class LocalWorld : public World {
|
||||
public:
|
||||
LocalWorld(LocalDefs& defs, glm::vec3* playerPos, ClientNetworkInterpreter* server);
|
||||
LocalWorld(ClientGame& defs, glm::vec3* playerPos, ClientNetworkInterpreter* server);
|
||||
|
||||
void init();
|
||||
void update(double delta) override;
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
int renderChunks(Renderer &render);
|
||||
void renderEntities(Renderer &renderer);
|
||||
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
LocalDimension dimension;
|
||||
|
||||
int lastGenUpdates = 0;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "../../../world/LocalDimension.h"
|
||||
|
||||
MeshGenStream::MeshGenStream(LocalDefs &defs, LocalDimension &dimension) :
|
||||
MeshGenStream::MeshGenStream(ClientGame &defs, LocalDimension &dimension) :
|
||||
defs(defs),
|
||||
dimension(dimension) {
|
||||
|
||||
|
@ -34,7 +34,7 @@ MeshGenStream::MeshGenStream(LocalDefs &defs, LocalDimension &dimension) :
|
|||
}
|
||||
}
|
||||
|
||||
MeshGenStream::Thread::Thread(LocalDefs &defs, std::array<NoiseSample, 3>& offsetSamplers) :
|
||||
MeshGenStream::Thread::Thread(ClientGame &defs, std::array<NoiseSample, 3>& offsetSamplers) :
|
||||
defs(defs), offsetSamplers(offsetSamplers) {
|
||||
thread = std::thread(MeshGenStream::threadFunction, this);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "../../../world/chunk/BlockChunk.h"
|
||||
#include "../../../def/LocalDefinitionAtlas.h"
|
||||
#include "../../../util/Vec.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
#include "../../../def/ClientGame.h"
|
||||
|
||||
class LocalDimension;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public:
|
|||
static const int THREADS = 2;
|
||||
static const int TOTAL_QUEUE_SIZE = THREADS * THREAD_QUEUE_SIZE;
|
||||
|
||||
explicit MeshGenStream(LocalDefs& defs, LocalDimension& dimension);
|
||||
explicit MeshGenStream(ClientGame& defs, LocalDimension& dimension);
|
||||
~MeshGenStream();
|
||||
|
||||
bool spaceInQueue();
|
||||
|
@ -46,9 +46,9 @@ public:
|
|||
};
|
||||
|
||||
struct Thread {
|
||||
explicit Thread(LocalDefs &defs, std::array<NoiseSample, 3>& offsetSampler);
|
||||
explicit Thread(ClientGame &defs, std::array<NoiseSample, 3>& offsetSampler);
|
||||
|
||||
LocalDefs &defs;
|
||||
ClientGame &defs;
|
||||
std::array<NoiseSample, 3>& offsetSamplers;
|
||||
|
||||
std::thread thread {};
|
||||
|
@ -62,7 +62,7 @@ private:
|
|||
static void threadFunction(Thread* thread);
|
||||
|
||||
LocalDimension& dimension;
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
|
||||
std::array<NoiseSample, 3> noiseSampler;
|
||||
std::vector<glm::vec3> queuedTasks;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "Player.h"
|
||||
|
||||
Player::Player(LocalWorld& world, LocalDefs& defs, Renderer& renderer) :
|
||||
Player::Player(LocalWorld& world, ClientGame& defs, Renderer& renderer) :
|
||||
Collidable(world, defs, {{-0.3, 0, -0.3}, {0.3, 1.8, 0.3}}),
|
||||
|
||||
hand(defs.defs, "hand", 1, 1),
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
static constexpr float BLOCK_DAMAGE = 0.36f;
|
||||
static constexpr float BLOCK_INTERVAL = 0.02f;
|
||||
|
||||
Player(LocalWorld& world, LocalDefs& defs, Renderer& renderer);
|
||||
Player(LocalWorld& world, ClientGame& defs, Renderer& renderer);
|
||||
void update(Input &input, double delta, glm::vec2 mouseDelta);
|
||||
~Player();
|
||||
|
||||
|
@ -70,7 +70,7 @@ private:
|
|||
void breakBlock(Input& input, double delta);
|
||||
|
||||
Renderer& renderer;
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
|
||||
InventoryList hand;
|
||||
Inventory inventory;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "WorldInterpolationStream.h"
|
||||
|
||||
WorldInterpolationStream::WorldInterpolationStream(unsigned int seed, LocalDefs& defs) {
|
||||
WorldInterpolationStream::WorldInterpolationStream(unsigned int seed, ClientGame& defs) {
|
||||
// gen(seed, defs.defs) {
|
||||
queuedTasks.reserve(1024);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
static const int THREAD_QUEUE_SIZE = 128;
|
||||
static const int THREADS = 2;
|
||||
|
||||
WorldInterpolationStream(unsigned int seed, LocalDefs& defs);
|
||||
WorldInterpolationStream(unsigned int seed, ClientGame& defs);
|
||||
~WorldInterpolationStream();
|
||||
|
||||
//Add `p` to the pre-thread queue.
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "../../../../world/chunk/BlockChunk.h"
|
||||
#include "MeshGenerator.h"
|
||||
|
||||
MeshGenerator::MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs, std::shared_ptr<BlockChunk> chunk,
|
||||
MeshGenerator::MeshGenerator(MeshDetails* meshDetails, ClientGame& defs, std::shared_ptr<BlockChunk> chunk,
|
||||
std::array<std::shared_ptr<BlockChunk>, 6> adjacent,
|
||||
std::array<NoiseSample, 3>& blockOffsets, bool hi) :
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
|
||||
#include "../../../../def/LocalDefs.h"
|
||||
#include "../../../../def/ClientGame.h"
|
||||
#include "../../../../def/gen/NoiseSample.h"
|
||||
|
||||
class MeshDetails;
|
||||
|
@ -17,7 +17,7 @@ class BlockChunk;
|
|||
|
||||
class MeshGenerator {
|
||||
public:
|
||||
MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs,
|
||||
MeshGenerator(MeshDetails* meshDetails, ClientGame& defs,
|
||||
std::shared_ptr<BlockChunk> chunk, std::array<std::shared_ptr<BlockChunk>, 6> adjacent,
|
||||
std::array<NoiseSample, 3>& blockOffsets, bool hi);
|
||||
private:
|
||||
|
@ -26,7 +26,7 @@ private:
|
|||
|
||||
unsigned int indOffset = 0;
|
||||
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
LocalDefinitionAtlas& atlas;
|
||||
MeshDetails* meshDetails;
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../type/LocalLuaEntity.h"
|
||||
#include "../../../def/ServerDefs.h"
|
||||
#include "../../../def/ServerGame.h"
|
||||
#include "../../../server/world/ServerWorld.h"
|
||||
#include "../../../game/scene/world/LocalWorld.h"
|
||||
|
||||
namespace Api {
|
||||
static int entities_ind = 0;
|
||||
|
||||
static void add_entity_c(sol::state& lua, sol::table& core, LocalDefs& defs, LocalWorld& world) {
|
||||
static void add_entity_c(sol::state& lua, sol::table& core, ClientGame& defs, LocalWorld& world) {
|
||||
core["entities"] = lua.create_table();
|
||||
|
||||
core.set_function("add_entity", [&](sol::optional<std::string> identifier, sol::optional<sol::table> pos, sol::object staticData) {
|
||||
|
@ -51,7 +51,7 @@ namespace Api {
|
|||
});
|
||||
}
|
||||
|
||||
static void add_entity_s(sol::state& lua, sol::table& core, ServerDefs& defs, ServerWorld& world) {
|
||||
static void add_entity_s(sol::state& lua, sol::table& core, ServerGame& defs, ServerWorld& world) {
|
||||
core["entities"] = lua.create_table();
|
||||
|
||||
core.set_function("add_entity", [&](sol::optional<std::string> identifier, sol::optional<sol::table> pos, sol::object staticData) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "../../../game/scene/world/LocalWorld.h"
|
||||
|
||||
namespace Api {
|
||||
static void remove_entity_c(sol::state& lua, sol::table& core, LocalDefs& defs, LocalWorld& world) {
|
||||
static void remove_entity_c(sol::state& lua, sol::table& core, ClientGame& defs, LocalWorld& world) {
|
||||
core.set_function("remove_entity", [&](sol::table entity) {
|
||||
auto object = entity.get<sol::optional<std::shared_ptr<LocalLuaEntity>>>("object");
|
||||
if (!object) throw "Attempting to remove an invalid entity object.";
|
||||
|
@ -25,7 +25,7 @@ namespace Api {
|
|||
});
|
||||
}
|
||||
|
||||
static void remove_entity_s(sol::state& lua, sol::table& core, ServerDefs& defs, ServerWorld& world) {
|
||||
static void remove_entity_s(sol::state& lua, sol::table& core, ServerGame& defs, ServerWorld& world) {
|
||||
core.set_function("remove_entity", [&](sol::table entity) {
|
||||
auto object = entity.get<sol::optional<std::shared_ptr<ServerLuaEntity>>>("object");
|
||||
if (!object) throw "Attempting to remove an invalid entity object.";
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../../game/entity/Entity.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
#include "../../../def/ClientGame.h"
|
||||
#include "LocalLuaAnimationManager.h"
|
||||
|
||||
class LocalLuaEntity {
|
||||
public:
|
||||
LocalLuaEntity(std::unique_ptr<Entity> entity, unsigned int id, LocalDefs& defs) :
|
||||
LocalLuaEntity(std::unique_ptr<Entity> entity, unsigned int id, ClientGame& defs) :
|
||||
entity(std::move(entity)), id(id), defs(defs), manager(*this->entity) {}
|
||||
|
||||
std::unique_ptr<Entity> entity = nullptr;
|
||||
unsigned int id;
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
|
||||
LocalLuaAnimationManager manager;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <sol2/sol.hpp>
|
||||
|
||||
#include "LuaInventory.h"
|
||||
#include "../../../def/LocalDefs.h"
|
||||
#include "../../../def/ClientGame.h"
|
||||
#include "../../../game/scene/world/Player.h"
|
||||
|
||||
class LocalLuaPlayer {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "ServerLocalLuaEntity.h"
|
||||
|
||||
ServerLocalLuaEntity::ServerLocalLuaEntity(unsigned int id, LocalDefs &defs, const std::string &appearance,
|
||||
ServerLocalLuaEntity::ServerLocalLuaEntity(unsigned int id, ClientGame &defs, const std::string &appearance,
|
||||
const std::string &arg1, const std::string &arg2) :
|
||||
|
||||
id(id),
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "../../../def/LocalDefs.h"
|
||||
#include "../../../def/ClientGame.h"
|
||||
#include "../../../game/entity/Entity.h"
|
||||
|
||||
class ServerLocalLuaEntity {
|
||||
public:
|
||||
ServerLocalLuaEntity(unsigned int id, LocalDefs& defs, const std::string& appearance, const std::string& arg1, const std::string& arg2);
|
||||
ServerLocalLuaEntity(unsigned int id, ClientGame& defs, const std::string& appearance, const std::string& arg1, const std::string& arg2);
|
||||
|
||||
void setDisplayType(const std::string& type, const std::string& arg, const std::string& arg2);
|
||||
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
std::unique_ptr<Entity> entity = std::make_unique<Entity>();
|
||||
unsigned int id;
|
||||
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
|
||||
#include <memory>
|
||||
#include "../../../server/world/ServerEntity.h"
|
||||
#include "../../../def/ServerDefs.h"
|
||||
#include "../../../def/ServerGame.h"
|
||||
|
||||
class ServerLuaEntity {
|
||||
public:
|
||||
ServerLuaEntity(std::unique_ptr<ServerEntity> entity, unsigned int id, ServerDefs& defs) :
|
||||
ServerLuaEntity(std::unique_ptr<ServerEntity> entity, unsigned int id, ServerGame& defs) :
|
||||
entity(std::move(entity)), id(id), defs(defs) {}
|
||||
|
||||
std::unique_ptr<ServerEntity> entity = nullptr;
|
||||
unsigned int id;
|
||||
ServerDefs& defs;
|
||||
ServerGame& defs;
|
||||
|
||||
void snap_pos(const sol::table& pos);
|
||||
void set_pos(const sol::table& pos);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "LuaItemStack.h"
|
||||
|
||||
namespace ClientApi {
|
||||
void item_stack(sol::state& lua) {
|
||||
static void item_stack(sol::state& lua) {
|
||||
lua.new_usertype<LuaItemStack>("ItemStack",
|
||||
sol::constructors<LuaItemStack(sol::table), LuaItemStack(std::string, unsigned short)>(),
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
//
|
||||
|
||||
#include "../ErrorFormatter.h"
|
||||
#include "../register/RegisterBlocks.h"
|
||||
#include "../register/RegisterItems.h"
|
||||
#include "../register/RegisterBiomes.h"
|
||||
#include "../register/RegisterKeybinds.h"
|
||||
|
||||
#include "LocalLuaParser.h"
|
||||
|
||||
#include "../register/RegisterBlocks.h"
|
||||
#include "../register/RegisterItems.h"
|
||||
#include "../register/RegisterKeybinds.h"
|
||||
#include "../register/RegisterBiomes.h"
|
||||
|
||||
// Types
|
||||
#include "../api/type/LocalLuaPlayer.h"
|
||||
#include "../api/type/cLocalLuaEntity.h"
|
||||
#include "../api/type/cLuaLocalPlayer.h"
|
||||
|
@ -18,6 +18,7 @@
|
|||
#include "../api/type/cLuaItemStack.h"
|
||||
#include "../api/type/cLocalLuaAnimationManager.h"
|
||||
|
||||
// Modules
|
||||
#include "../api/modules/delay.h"
|
||||
#include "../api/modules/register_block.h"
|
||||
#include "../api/modules/register_blockmodel.h"
|
||||
|
@ -31,32 +32,43 @@
|
|||
#include "../api/modules/remove_entity.h"
|
||||
#include "../api/modules/register_keybind.h"
|
||||
|
||||
// Functions
|
||||
#include "../api/functions/trigger_event.h"
|
||||
#include "../api/functions/update_entities.h"
|
||||
|
||||
void LocalLuaParser::init(LocalDefs& defs, LocalWorld& world, Player& player) {
|
||||
//Load Base Libraries
|
||||
void LocalLuaParser::init(ClientGame& defs, LocalWorld& world, Player& player) {
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table);
|
||||
|
||||
//Define Panic Callback
|
||||
// lua_atpanic(lua, sol::c_call<decltype(&LuaParser::override_panic), &LuaParser::override_panic>);
|
||||
loadApi(defs, world, player);
|
||||
handler.executeMods(std::bind(&LocalLuaParser::runFileSandboxed, this, std::placeholders::_1));
|
||||
|
||||
//Load Modules
|
||||
loadModules(defs, world, player);
|
||||
|
||||
//Load Mods
|
||||
loadMods();
|
||||
|
||||
//Register Blocks
|
||||
registerDefinitions(defs);
|
||||
registerDefs(defs);
|
||||
}
|
||||
|
||||
void LocalLuaParser::loadModules(LocalDefs &defs, LocalWorld &world, Player& player) {
|
||||
void LocalLuaParser::update(double delta, bool* keys) {
|
||||
LuaParser::update(delta);
|
||||
|
||||
this->delta += delta;
|
||||
while (this->delta > double(UPDATE_STEP)) {
|
||||
manager.triggerKeybinds();
|
||||
core["__builtin"]["update_entities"](double(UPDATE_STEP));
|
||||
this->delta -= double(UPDATE_STEP);
|
||||
}
|
||||
|
||||
manager.update(keys);
|
||||
}
|
||||
|
||||
LocalModHandler& LocalLuaParser::getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
void LocalLuaParser::loadApi(ClientGame &defs, LocalWorld &world, Player& player) {
|
||||
//Create Zepha Table
|
||||
core = lua.create_table();
|
||||
lua["zepha"] = core;
|
||||
core["__builtin"] = lua.create_table();
|
||||
|
||||
//Load Types
|
||||
// Types
|
||||
ClientApi::entity(lua);
|
||||
ClientApi::animation_manager(lua);
|
||||
ClientApi::local_player(lua);
|
||||
|
@ -66,7 +78,7 @@ void LocalLuaParser::loadModules(LocalDefs &defs, LocalWorld &world, Player& pla
|
|||
core["client"] = true;
|
||||
core["player"] = LocalLuaPlayer(player);
|
||||
|
||||
//Load Modules
|
||||
// Modules
|
||||
Api::delay (core, delayed_functions);
|
||||
|
||||
Api::register_block (lua, core);
|
||||
|
@ -83,49 +95,21 @@ void LocalLuaParser::loadModules(LocalDefs &defs, LocalWorld &world, Player& pla
|
|||
Api::add_entity_c (lua, core, defs, world);
|
||||
Api::remove_entity_c (lua, core, defs, world);
|
||||
|
||||
// Functions
|
||||
Api::update_entities(lua);
|
||||
|
||||
//Sandbox the dofile function
|
||||
// Create sandboxed runfile()
|
||||
lua["dofile"] = lua["loadfile"] = sol::nil;
|
||||
lua.set_function("runfile", &LocalLuaParser::runFileSandboxed, this);
|
||||
}
|
||||
|
||||
void LocalLuaParser::loadMods() {
|
||||
//Load "base" if it exists.
|
||||
for (const std::string& modName : modsOrder) {
|
||||
if (modName == "base") {
|
||||
runFileSandboxed(modName + "/main");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::string& modName : modsOrder) {
|
||||
if (modName != "base") {
|
||||
runFileSandboxed(modName + "/main");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocalLuaParser::registerDefinitions(LocalDefs &defs) {
|
||||
void LocalLuaParser::registerDefs(ClientGame &defs) {
|
||||
RegisterBlocks ::client(core, defs);
|
||||
RegisterItems ::client(core, defs);
|
||||
RegisterBiomes ::client(core, defs);
|
||||
RegisterKeybinds::client(core, manager);
|
||||
}
|
||||
|
||||
void LocalLuaParser::update(double delta, bool* keys) {
|
||||
LuaParser::update(delta);
|
||||
|
||||
this->delta += delta;
|
||||
while (this->delta > double(UPDATE_STEP)) {
|
||||
core["__builtin"]["update_entities"](double(UPDATE_STEP));
|
||||
manager.triggerKeybinds();
|
||||
this->delta -= double(UPDATE_STEP);
|
||||
}
|
||||
|
||||
manager.update(keys);
|
||||
}
|
||||
|
||||
sol::protected_function_result LocalLuaParser::errorCallback(lua_State*, sol::protected_function_result errPfr) {
|
||||
sol::error err = errPfr;
|
||||
std::string errString = err.what();
|
||||
|
@ -143,7 +127,7 @@ sol::protected_function_result LocalLuaParser::errorCallback(lua_State*, sol::pr
|
|||
std::string fileName = errString.substr(0, lineNumStart);
|
||||
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
|
||||
|
||||
for (auto& mod : mods) {
|
||||
for (const auto& mod : handler.cGetMods()) {
|
||||
if (mod.config.name == modString) {
|
||||
for (auto& file : mod.files) {
|
||||
if (file.path == fileName) {
|
||||
|
@ -163,9 +147,9 @@ sol::protected_function_result LocalLuaParser::runFileSandboxed(std::string file
|
|||
size_t modname_length = file.find('/');
|
||||
std::string modname = file.substr(0, modname_length);
|
||||
|
||||
for (LuaMod& mod : mods) {
|
||||
for (const LuaMod& mod : handler.cGetMods()) {
|
||||
if (strncmp(mod.config.name.c_str(), modname.c_str(), modname_length) == 0) {
|
||||
for (LuaModFile& f : mod.files) {
|
||||
for (const LuaModFile& f : mod.files) {
|
||||
if (f.path == file) {
|
||||
|
||||
sol::environment env(lua, sol::create, lua.globals());
|
||||
|
@ -173,10 +157,8 @@ sol::protected_function_result LocalLuaParser::runFileSandboxed(std::string file
|
|||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
auto pfr = lua.safe_script(f.file, env, std::bind(&LocalLuaParser::errorCallback, this,
|
||||
return lua.safe_script(f.file, env, std::bind(&LocalLuaParser::errorCallback, this,
|
||||
std::placeholders::_1, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
|
||||
return pfr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,4 +166,4 @@ sol::protected_function_result LocalLuaParser::runFileSandboxed(std::string file
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,33 +4,29 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cute_files/cute_files.h>
|
||||
#include "../LuaParser.h"
|
||||
#include "LocalModHandler.h"
|
||||
#include "../LuaMod.h"
|
||||
#include "../LuaParser.h"
|
||||
#include "../LuaInputManager.h"
|
||||
|
||||
class LocalDefs;
|
||||
class ClientGame;
|
||||
class LocalWorld;
|
||||
class Player;
|
||||
|
||||
class LocalLuaParser : public LuaParser {
|
||||
public:
|
||||
void init(LocalDefs& defs, LocalWorld& world, Player& player);
|
||||
|
||||
void loadModules(LocalDefs& defs, LocalWorld& world, Player& player);
|
||||
void loadMods();
|
||||
void registerDefinitions(LocalDefs &defs);
|
||||
|
||||
void init(ClientGame& defs, LocalWorld& world, Player& player);
|
||||
void update(double delta, bool* keys);
|
||||
|
||||
~LocalLuaParser() = default;
|
||||
|
||||
std::vector<LuaMod> mods;
|
||||
std::vector<std::string> modsOrder;
|
||||
LocalModHandler& getHandler();
|
||||
private:
|
||||
void loadApi(ClientGame& defs, LocalWorld& world, Player& player);
|
||||
void registerDefs(ClientGame &defs);
|
||||
|
||||
sol::protected_function_result errorCallback(lua_State*, sol::protected_function_result errPfr);
|
||||
sol::protected_function_result runFileSandboxed(std::string file);
|
||||
|
||||
double delta = 0;
|
||||
LuaInputManager manager;
|
||||
LocalModHandler handler;
|
||||
double delta = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// Created by aurailus on 2020-02-19.
|
||||
//
|
||||
|
||||
#include "LocalModHandler.h"
|
||||
|
||||
void LocalModHandler::addLuaMod(const LuaMod& mod) {
|
||||
mods.emplace_back(mod);
|
||||
}
|
||||
|
||||
void LocalModHandler::setModsOrder(const std::vector<std::string>& order) {
|
||||
modsOrder = order;
|
||||
}
|
||||
|
||||
void LocalModHandler::executeMods(std::function<void(std::string)> run) {
|
||||
for (std::string& modName : modsOrder) {
|
||||
if (modName == "base") {
|
||||
run(modName + "/main");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (std::string& modName : modsOrder) {
|
||||
if (modName != "base") run(modName + "/main");
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<LuaMod> &LocalModHandler::cGetMods() const {
|
||||
return mods;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// Created by aurailus on 2020-02-19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include "../LuaMod.h"
|
||||
|
||||
class LocalModHandler {
|
||||
public:
|
||||
void addLuaMod(const LuaMod& mod);
|
||||
void setModsOrder(const std::vector<std::string>& order);
|
||||
|
||||
void executeMods(std::function<void(std::string)> run);
|
||||
const std::vector<LuaMod>& cGetMods() const;
|
||||
private:
|
||||
std::vector<LuaMod> mods;
|
||||
std::vector<std::string> modsOrder;
|
||||
};
|
|
@ -16,6 +16,7 @@
|
|||
#include "../api/type/sServerLuaPlayer.h"
|
||||
#include "../api/type/sServerLuaEntity.h"
|
||||
#include "../api/type/cLuaInventory.h"
|
||||
#include "../api/type/cLuaItemStack.h"
|
||||
|
||||
// Modules
|
||||
#include "../api/modules/delay.h"
|
||||
|
@ -37,7 +38,7 @@
|
|||
#include "../api/functions/update_entities.h"
|
||||
|
||||
|
||||
void ServerLuaParser::init(ServerDefs& defs, ServerWorld& world, std::string path) {
|
||||
void ServerLuaParser::init(ServerGame& defs, ServerWorld& world, std::string path) {
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table);
|
||||
|
||||
loadApi(defs, world);
|
||||
|
@ -90,22 +91,23 @@ void ServerLuaParser::playerDisconnected(std::shared_ptr<ServerClient> client) {
|
|||
}
|
||||
}
|
||||
|
||||
void ServerLuaParser::loadApi(ServerDefs &defs, ServerWorld &world) {
|
||||
void ServerLuaParser::loadApi(ServerGame &defs, ServerWorld &world) {
|
||||
//Create Zepha Table
|
||||
core = lua.create_table();
|
||||
lua["zepha"] = core;
|
||||
core["__builtin"] = lua.create_table();
|
||||
|
||||
//Load Types
|
||||
// Types
|
||||
ServerApi::entity(lua);
|
||||
ServerApi::server_player(lua);
|
||||
ClientApi::inventory(lua);
|
||||
ClientApi::item_stack(lua);
|
||||
|
||||
core["server"] = true;
|
||||
core["players"] = lua.create_table();
|
||||
|
||||
//Load Modules
|
||||
Api::delay(core, delayed_functions);
|
||||
// Modules
|
||||
Api::delay (core, delayed_functions);
|
||||
|
||||
Api::register_block (lua, core);
|
||||
Api::register_blockmodel (lua, core);
|
||||
|
@ -122,15 +124,16 @@ void ServerLuaParser::loadApi(ServerDefs &defs, ServerWorld &world) {
|
|||
Api::add_entity_s (lua, core, defs, world);
|
||||
Api::remove_entity_s (lua, core, defs, world);
|
||||
|
||||
// Functions
|
||||
Api::trigger_event(lua);
|
||||
Api::update_entities(lua);
|
||||
|
||||
//Sandbox the dofile function
|
||||
// Create sandboxed runfile()
|
||||
lua["dofile"] = lua["loadfile"] = sol::nil;
|
||||
lua.set_function("runfile", &ServerLuaParser::runFileSandboxed, this);
|
||||
}
|
||||
|
||||
void ServerLuaParser::registerDefs(ServerDefs &defs) {
|
||||
void ServerLuaParser::registerDefs(ServerGame &defs) {
|
||||
RegisterBlocks::server(core, defs);
|
||||
RegisterItems ::server(core, defs);
|
||||
RegisterBiomes::server(core, defs);
|
||||
|
@ -183,9 +186,8 @@ sol::protected_function_result ServerLuaParser::runFileSandboxed(const std::stri
|
|||
env["_FILE"] = f.path;
|
||||
env["_MODNAME"] = mod.config.name;
|
||||
|
||||
auto pfr = lua.safe_script(f.file, env, std::bind(&ServerLuaParser::errorCallback, this,
|
||||
return lua.safe_script(f.file, env, std::bind(&ServerLuaParser::errorCallback, this,
|
||||
std::placeholders::_1, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
|
||||
return pfr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../LuaParser.h"
|
||||
#include "ServerModHandler.h"
|
||||
#include "../LuaParser.h"
|
||||
#include "../../server/conn/ServerClient.h"
|
||||
|
||||
class ServerDefs;
|
||||
class ServerGame;
|
||||
class ServerWorld;
|
||||
class EnetPeer;
|
||||
|
||||
class ServerLuaParser : public LuaParser {
|
||||
public:
|
||||
void init(ServerDefs& defs, ServerWorld& world, std::string rootPath);
|
||||
void init(ServerGame& defs, ServerWorld& world, std::string rootPath);
|
||||
void update(double delta) override;
|
||||
|
||||
void sendModsPacket(ENetPeer* peer) const;
|
||||
|
@ -22,8 +21,8 @@ public:
|
|||
void playerConnected(std::shared_ptr<ServerClient> client);
|
||||
void playerDisconnected(std::shared_ptr<ServerClient> client);
|
||||
private:
|
||||
void loadApi(ServerDefs& defs, ServerWorld& world);
|
||||
void registerDefs(ServerDefs &defs);
|
||||
void loadApi(ServerGame& defs, ServerWorld& world);
|
||||
void registerDefs(ServerGame &defs);
|
||||
|
||||
sol::protected_function_result errorCallback(lua_State*, sol::protected_function_result errPfr);
|
||||
sol::protected_function_result runFileSandboxed(const std::string& file);
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
#include <gzip/compress.hpp>
|
||||
|
||||
#include "../VenusParser.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../util/net/Serializer.h"
|
||||
|
||||
#include "ServerModHandler.h"
|
||||
|
||||
void ServerModHandler::loadMods(ServerDefs& defs, const std::string &path) {
|
||||
void ServerModHandler::loadMods(ServerGame& defs, const std::string &path) {
|
||||
auto modDirs = findModDirectories(path);
|
||||
mods = initializeLuaMods(modDirs);
|
||||
|
||||
|
@ -176,7 +176,7 @@ std::vector<LuaMod> ServerModHandler::initializeLuaMods(const std::list<std::str
|
|||
return mods;
|
||||
}
|
||||
|
||||
void ServerModHandler::loadTextures(ServerDefs &defs, const std::vector<LuaMod>& mods) {
|
||||
void ServerModHandler::loadTextures(ServerGame &defs, const std::vector<LuaMod>& mods) {
|
||||
cf_dir_t dir;
|
||||
for (const LuaMod& mod : mods) {
|
||||
std::string root = mod.modPath + "/textures";
|
||||
|
@ -221,7 +221,7 @@ void ServerModHandler::loadTextures(ServerDefs &defs, const std::vector<LuaMod>&
|
|||
}
|
||||
}
|
||||
|
||||
void ServerModHandler::loadModels(ServerDefs &defs, const std::vector<LuaMod>& mods) {
|
||||
void ServerModHandler::loadModels(ServerGame &defs, const std::vector<LuaMod>& mods) {
|
||||
cf_dir_t dir;
|
||||
for (const LuaMod& mod : mods) {
|
||||
std::string root = mod.modPath + "/models";
|
||||
|
|
|
@ -8,18 +8,18 @@
|
|||
#include <string>
|
||||
#include "../LuaMod.h"
|
||||
|
||||
class ServerDefs;
|
||||
class ServerGame;
|
||||
|
||||
class ServerModHandler {
|
||||
public:
|
||||
void loadMods(ServerDefs& defs, const std::string& path);
|
||||
void loadMods(ServerGame& defs, const std::string& path);
|
||||
void executeMods(std::function<void(std::string)> run);
|
||||
const std::vector<LuaMod>& cGetMods() const;
|
||||
private:
|
||||
static std::list<std::string> findModDirectories(const std::string& path);
|
||||
static std::vector<LuaMod> initializeLuaMods(const std::list<std::string> modDirs);
|
||||
static void loadTextures(ServerDefs &defs, const std::vector<LuaMod>& mods);
|
||||
static void loadModels(ServerDefs &defs, const std::vector<LuaMod>& mods);
|
||||
static void loadTextures(ServerGame &defs, const std::vector<LuaMod>& mods);
|
||||
static void loadModels(ServerGame &defs, const std::vector<LuaMod>& mods);
|
||||
static void organizeDependencies(std::vector<LuaMod>& mods);
|
||||
static void serializeMods(std::vector<LuaMod>& mods);
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <noise/module/modulebase.h>
|
||||
#include <noise/module/add.h>
|
||||
#include <noise/module/module.h>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterBiomes {
|
||||
|
@ -302,12 +302,12 @@ namespace RegisterBiomes {
|
|||
}
|
||||
}
|
||||
|
||||
static void server(sol::table& core, ServerDefs& defs) {
|
||||
static void server(sol::table& core, ServerGame& defs) {
|
||||
registerBiomes(core.get<sol::table>("registered_biomes"), defs.defs, defs.biomes);
|
||||
defs.biomes.generateVoronoi();
|
||||
}
|
||||
|
||||
static void client(sol::table& core, LocalDefs& defs) {
|
||||
static void client(sol::table& core, ClientGame& defs) {
|
||||
registerBiomes(core.get<sol::table>("registered_biomes"), defs.defs, defs.biomes);
|
||||
defs.biomes.generateVoronoi();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterBlocks {
|
||||
|
@ -321,12 +321,12 @@ namespace RegisterBlocks {
|
|||
}
|
||||
}
|
||||
|
||||
static void server(sol::table& core, ServerDefs& defs) {
|
||||
static void server(sol::table& core, ServerGame& defs) {
|
||||
registerBlocks(core.get<sol::table>("registered_blocks"),
|
||||
core.get<sol::table>("registered_blockmodels"), defs.defs, nullptr);
|
||||
}
|
||||
|
||||
static void client(sol::table& core, LocalDefs& defs) {
|
||||
static void client(sol::table& core, ClientGame& defs) {
|
||||
registerBlocks(core.get<sol::table>("registered_blocks"),
|
||||
core.get<sol::table>("registered_blockmodels"), defs.defs, &defs.textures);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterItems {
|
||||
|
@ -57,11 +57,11 @@ namespace RegisterItems {
|
|||
}
|
||||
}
|
||||
|
||||
static void server(sol::table& core, ServerDefs& defs) {
|
||||
static void server(sol::table& core, ServerGame& defs) {
|
||||
registerItems(core.get<sol::table>("registered_items"), defs.defs, nullptr);
|
||||
}
|
||||
|
||||
static void client(sol::table& core, LocalDefs& defs) {
|
||||
static void client(sol::table& core, ClientGame& defs) {
|
||||
registerItems(core.get<sol::table>("registered_items"), defs.defs, &defs.textures);
|
||||
}
|
||||
};
|
|
@ -5,8 +5,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
|
||||
namespace RegisterKeybinds {
|
||||
|
@ -32,7 +32,7 @@ namespace RegisterKeybinds {
|
|||
}
|
||||
}
|
||||
|
||||
// static void server(sol::table& core, ServerDefs& defs) {
|
||||
// static void server(sol::table& core, ServerGame& defs) {
|
||||
// registerItems(core.get<sol::table>("registered_items"), defs.defs, nullptr);
|
||||
// }
|
||||
|
||||
|
|
|
@ -129,13 +129,13 @@ void Server::handlePlayerPacket(ServerClient &client, Packet& p) {
|
|||
if (block == DefinitionAtlas::AIR) {
|
||||
auto def = defs.defs.blockFromId(worldBlock);
|
||||
if (def.callbacks.count(Callback::BREAK)) {
|
||||
def.callbacks[Callback::BREAK](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::BREAK](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto def = defs.defs.blockFromId(block);
|
||||
if (def.callbacks.count(Callback::PLACE)) {
|
||||
def.callbacks[Callback::PLACE](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::PLACE](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "conn/ClientList.h"
|
||||
#include "world/ServerWorld.h"
|
||||
#include "config/ServerConfig.h"
|
||||
#include "../def/ServerDefs.h"
|
||||
#include "../def/ServerGame.h"
|
||||
#include "../util/net/NetHandler.h"
|
||||
|
||||
class ServerClient;
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
private:
|
||||
bool alive = true;
|
||||
|
||||
ServerDefs defs;
|
||||
ServerGame defs;
|
||||
ServerWorld world;
|
||||
NetHandler handler;
|
||||
ClientList clientList;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "ServerConfig.h"
|
||||
|
||||
ServerConfig::ServerConfig(ServerDefs &defs) : defs(defs) {}
|
||||
ServerConfig::ServerConfig(ServerGame &defs) : defs(defs) {}
|
||||
|
||||
void ServerConfig::init() {
|
||||
blockIdentifierList.reserve(static_cast<unsigned long>(defs.defs.size()));
|
||||
|
@ -42,7 +42,7 @@ bool ServerConfig::handlePacket(ServerClient& client, Packet& r) {
|
|||
}
|
||||
|
||||
case PacketType::MODS: {
|
||||
defs.luaApi.sendModsPacket(client.peer);
|
||||
defs.parser.sendModsPacket(client.peer);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,20 +6,20 @@
|
|||
|
||||
#include "../conn/ServerClient.h"
|
||||
#include "../asset/AssetType.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../util/net/Packet.h"
|
||||
#include "../../util/net/Serializer.h"
|
||||
|
||||
class ServerConfig {
|
||||
public:
|
||||
explicit ServerConfig(ServerDefs& defs);
|
||||
explicit ServerConfig(ServerGame& defs);
|
||||
|
||||
void init();
|
||||
|
||||
//Bool: Create player
|
||||
bool handlePacket(ServerClient &client, Packet& p);
|
||||
private:
|
||||
ServerDefs& defs;
|
||||
ServerGame& defs;
|
||||
std::vector<std::string> blockIdentifierList {};
|
||||
std::vector<std::string> biomeIdentifierList {};
|
||||
};
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include "ClientList.h"
|
||||
#include "../../util/net/Serializer.h"
|
||||
#include "../../util/net/NetHandler.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
|
||||
|
||||
ClientList::ClientList(ServerDefs& defs) :
|
||||
ClientList::ClientList(ServerGame& defs) :
|
||||
defs(defs) {}
|
||||
|
||||
void ClientList::handleConnect(ENetEvent e) {
|
||||
|
@ -27,7 +27,7 @@ void ClientList::handleDisconnect(ENetEvent e) {
|
|||
|
||||
for (unsigned int i = 0; i < clients.size(); i++) {
|
||||
if (clients[i]->cid == cid) {
|
||||
defs.luaApi.playerDisconnected(clients[i]);
|
||||
defs.parser.playerDisconnected(clients[i]);
|
||||
clients.erase(clients.begin() + i);
|
||||
break;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void ClientList::createPlayer(std::shared_ptr<ServerClient> c) {
|
|||
c->hasPlayer = true;
|
||||
c->setUsername("TEMPORaRY");
|
||||
|
||||
defs.luaApi.playerConnected(c);
|
||||
defs.parser.playerConnected(c);
|
||||
|
||||
Packet p(PacketType::THIS_PLAYER_INFO);
|
||||
p.data = Serializer()
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
class ClientList {
|
||||
public:
|
||||
explicit ClientList(ServerDefs& defs);
|
||||
explicit ClientList(ServerGame& defs);
|
||||
|
||||
void handleConnect(ENetEvent e);
|
||||
void handleDisconnect(ENetEvent e);
|
||||
|
@ -19,5 +19,5 @@ public:
|
|||
|
||||
std::vector<std::shared_ptr<ServerClient>> clients;
|
||||
private:
|
||||
ServerDefs& defs;
|
||||
ServerGame& defs;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "ServerWorld.h"
|
||||
|
||||
ServerWorld::ServerWorld(unsigned int seed, ServerDefs& defs, ClientList& clients) :
|
||||
ServerWorld::ServerWorld(unsigned int seed, ServerGame& defs, ClientList& clients) :
|
||||
clientList(clients),
|
||||
seed(seed),
|
||||
defs(defs) {
|
||||
|
@ -176,13 +176,13 @@ void ServerWorld::setBlock(glm::ivec3 pos, unsigned int block) {
|
|||
if (block == DefinitionAtlas::AIR) {
|
||||
auto def = defs.defs.blockFromId(oldBlock);
|
||||
if (def.callbacks.count(Callback::DESTRUCT)) {
|
||||
def.callbacks[Callback::DESTRUCT](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::DESTRUCT](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto def = defs.defs.blockFromId(block);
|
||||
if (def.callbacks.count(Callback::CONSTRUCT)) {
|
||||
def.callbacks[Callback::CONSTRUCT](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::CONSTRUCT](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,13 +213,13 @@ void ServerWorld::setBlock(glm::ivec3 pos, unsigned int block) {
|
|||
if (block == DefinitionAtlas::AIR) {
|
||||
auto def = defs.defs.blockFromId(oldBlock);
|
||||
if (def.callbacks.count(Callback::AFTER_DESTRUCT)) {
|
||||
def.callbacks[Callback::AFTER_DESTRUCT](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::AFTER_DESTRUCT](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto def = defs.defs.blockFromId(block);
|
||||
if (def.callbacks.count(Callback::AFTER_CONSTRUCT)) {
|
||||
def.callbacks[Callback::AFTER_CONSTRUCT](defs.luaApi.vecToTable(pos));
|
||||
def.callbacks[Callback::AFTER_CONSTRUCT](defs.parser.vecToTable(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <unordered_set>
|
||||
#include "WorldGenStream.h"
|
||||
#include "../conn/ClientList.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
#include "../../game/scene/world/World.h"
|
||||
#include "../../world/ServerDimension.h"
|
||||
|
||||
|
@ -16,7 +16,7 @@ public:
|
|||
const static int MB_GEN_H = 3;
|
||||
const static int MB_GEN_V = 3;
|
||||
|
||||
explicit ServerWorld(unsigned int seed, ServerDefs& defs, ClientList& clients);
|
||||
explicit ServerWorld(unsigned int seed, ServerGame& defs, ClientList& clients);
|
||||
|
||||
void init();
|
||||
void update(double delta) override;
|
||||
|
@ -41,7 +41,7 @@ private:
|
|||
std::vector<glm::vec3> generateQueueList;
|
||||
|
||||
unsigned int seed;
|
||||
ServerDefs& defs;
|
||||
ServerGame& defs;
|
||||
ClientList& clientList;
|
||||
|
||||
unsigned int generatedChunks = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
|
||||
WorldGenStream::WorldGenStream(unsigned int seed, ServerDefs& atlas) : gen(seed, atlas.defs, atlas.biomes) {
|
||||
WorldGenStream::WorldGenStream(unsigned int seed, ServerGame& atlas) : gen(seed, atlas.defs, atlas.biomes) {
|
||||
queuedTasks.reserve((unsigned long) TOTAL_QUEUE_SIZE);
|
||||
|
||||
threads.reserve(THREADS);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "../../util/Vec.h"
|
||||
#include "../../def/gen/MapGen.h"
|
||||
#include "../../world/chunk/BlockChunk.h"
|
||||
#include "../../def/ServerDefs.h"
|
||||
#include "../../def/ServerGame.h"
|
||||
|
||||
class WorldGenStream {
|
||||
public:
|
||||
|
@ -21,7 +21,7 @@ public:
|
|||
static const int THREADS = 4;
|
||||
static const int TOTAL_QUEUE_SIZE = THREADS * THREAD_QUEUE_SIZE;
|
||||
|
||||
explicit WorldGenStream(unsigned int seed, ServerDefs& defs);
|
||||
explicit WorldGenStream(unsigned int seed, ServerGame& defs);
|
||||
~WorldGenStream();
|
||||
|
||||
//Attempt to add `pos` to the pre-thread queue.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "LocalDimension.h"
|
||||
|
||||
LocalDimension::LocalDimension(LocalDefs &defs) : defs(defs), meshGenStream(std::make_unique<MeshGenStream>(defs, *this)) {}
|
||||
LocalDimension::LocalDimension(ClientGame &defs) : defs(defs), meshGenStream(std::make_unique<MeshGenStream>(defs, *this)) {}
|
||||
|
||||
void LocalDimension::update(double delta, glm::vec3 playerPos) {
|
||||
finishMeshes();
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
class LocalDimension : public Dimension {
|
||||
public:
|
||||
explicit LocalDimension(LocalDefs& defs);
|
||||
explicit LocalDimension(ClientGame& defs);
|
||||
void update(double delta, glm::vec3 playerPos);
|
||||
|
||||
void setChunk(std::shared_ptr<BlockChunk> chunk) override;
|
||||
|
@ -49,7 +49,7 @@ private:
|
|||
void attemptMeshChunk(const std::shared_ptr<BlockChunk>& chunk, bool updateAdjacents = true);
|
||||
bool getAdjacentExists(glm::vec3 pos, bool updateAdjacents);
|
||||
|
||||
LocalDefs& defs;
|
||||
ClientGame& defs;
|
||||
|
||||
std::unique_ptr<MeshGenStream> meshGenStream = nullptr;
|
||||
std::vector<glm::vec3> pendingMesh {};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../def/LocalDefs.h"
|
||||
#include "../../def/ClientGame.h"
|
||||
|
||||
class PointedThing {
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue