Reimplement server entities, generic LuaEntity baseclass.
parent
e9c95e8042
commit
5d46a12077
|
@ -3,7 +3,7 @@
|
|||
-- Otherwise, calls zepha.block_place and returned the function's returned values.
|
||||
function zepha.block_interact_or_place(player, target, stack)
|
||||
local stack = stack or player:get_wield_stack()
|
||||
local target_block = player.dim:get_block(target.pos)
|
||||
local target_block = target.dim:get_block(target.pos)
|
||||
local target_def = zepha.registered_blocks[target_block]
|
||||
local stack_def = zepha.registered_blocks[stack and stack.name or nil]
|
||||
|
||||
|
@ -24,7 +24,7 @@ end
|
|||
-- Interacts with the targeted block. Returns true if the block has an on_interact or
|
||||
-- on_interact_client callback, returns false otherwise.
|
||||
function zepha.block_interact(player, target)
|
||||
local block = player.dim:get_block(target.pos)
|
||||
local block = target.dim:get_block(target.pos)
|
||||
local def = zepha.registered_blocks[block]
|
||||
|
||||
local args = { target.dim, target.pos, player }
|
||||
|
@ -44,12 +44,15 @@ function zepha.block_place(player, target, stack)
|
|||
local stack_def = zepha.registered_blocks[stack and stack.name or nil]
|
||||
if stack == nil or stack_def == nil then return stack, nil end
|
||||
|
||||
player.dim:set_block(target.pos_above, stack.name)
|
||||
target.dim:set_block(target.pos_above, stack.name)
|
||||
|
||||
stack.count = stack.count - 1
|
||||
return stack, target.pos_above
|
||||
end
|
||||
|
||||
-- zepha.block_hit(player: Player, target: Target): float, float
|
||||
-- Hits the block at `target` using the player's wielded item.
|
||||
-- Returns the damage done followed by the timeout before the next hit can begin.
|
||||
function zepha.block_hit(player, target)
|
||||
local block = player.dim:get_block(target.pos)
|
||||
local def = zepha.registered_blocks[block]
|
||||
|
@ -58,7 +61,31 @@ function zepha.block_hit(player, target)
|
|||
if not def then return 0, 0.1 end
|
||||
|
||||
local damage, timeout = zepha.get_hit_impact(player, block)
|
||||
player.dim:add_block_damage(target.pos, damage)
|
||||
local total_damage = target.dim:add_block_damage(target.pos, damage)
|
||||
|
||||
local health = (def.tool_props or {}).health == nil and -1 or (def.tool_props or {}).health
|
||||
local broken = health ~= -1 and total_damage > health
|
||||
|
||||
if broken then zepha.block_break(player, target) end
|
||||
|
||||
return damage, timeout
|
||||
end
|
||||
|
||||
-- zepha.block_break(player: Player, target: Target):
|
||||
-- Breaks the block at `target`.
|
||||
function zepha.block_break(player, target)
|
||||
local block = player.dim:get_block(target.pos)
|
||||
local def = zepha.registered_blocks[block] or {}
|
||||
|
||||
local args = { target.dim, target.pos, player }
|
||||
|
||||
local cb = zepha.server and "on_break" or "on_break_client"
|
||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
||||
zepha.trigger(cb, unpack(args))
|
||||
|
||||
target.dim:set_block(target.pos, "air")
|
||||
|
||||
local cb = zepha.server and "after_break" or "after_break_client"
|
||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
||||
zepha.trigger(cb, unpack(args))
|
||||
end
|
|
@ -216,27 +216,19 @@ add_library(Zepha_Core
|
|||
lua/ServerModHandler.cpp
|
||||
lua/ServerModHandler.h
|
||||
lua/usertype/cAnimationManager.h
|
||||
lua/usertype/cLuaEntity.h
|
||||
lua/usertype/LocalLuaAnimationManager.cpp
|
||||
lua/usertype/LocalLuaAnimationManager.cpp
|
||||
lua/usertype/LocalLuaAnimationManager.h
|
||||
lua/usertype/LocalLuaEntity.cpp
|
||||
lua/usertype/LocalLuaEntity.h
|
||||
lua/usertype/Player.cpp
|
||||
lua/usertype/Player.cpp
|
||||
lua/usertype/Player.h
|
||||
lua/usertype/LuaGuiElement.cpp
|
||||
lua/usertype/LuaGuiElement.h
|
||||
lua/usertype/ItemStack.cpp
|
||||
lua/usertype/ItemStack.h
|
||||
lua/usertype/ServerLocalLuaEntity.cpp
|
||||
lua/usertype/ServerLocalLuaEntity.h
|
||||
lua/usertype/ServerLuaEntity.cpp
|
||||
lua/usertype/ServerLuaEntity.h
|
||||
lua/usertype/Inventory.cpp
|
||||
lua/usertype/Inventory.cpp
|
||||
lua/usertype/Inventory.h
|
||||
lua/usertype/InventoryList.cpp
|
||||
lua/usertype/InventoryList.h
|
||||
lua/usertype/sLuaEntity.h
|
||||
net/Address.h
|
||||
net/Address.h
|
||||
net/client/ClientNetworkInterpreter.cpp
|
||||
net/client/ClientNetworkInterpreter.h
|
||||
net/client/ServerConnection.cpp
|
||||
|
@ -263,8 +255,8 @@ add_library(Zepha_Core
|
|||
net/server/LocalServerInstance.h
|
||||
net/server/Server.cpp
|
||||
net/server/Server.h
|
||||
net/server/world/ServerEntity.cpp
|
||||
net/server/world/ServerEntity.h
|
||||
net/server/world/ServerLuaEntity.cpp
|
||||
net/server/world/ServerLuaEntity.h
|
||||
net/server/world/ServerGenStream.cpp
|
||||
net/server/world/ServerGenStream.h
|
||||
net/server/world/ServerPacketStream.cpp
|
||||
|
@ -321,4 +313,4 @@ add_library(Zepha_Core
|
|||
game/entity/Collision.cpp
|
||||
game/entity/Collision.h
|
||||
net/server/conn/ServerClient.cpp
|
||||
net/server/conn/ServerClient.h lua/modules/Dimension.cpp lua/modules/Dimension.h util/CovariantPtr.h)
|
||||
net/server/conn/ServerClient.h lua/modules/Dimension.cpp lua/modules/Dimension.h util/CovariantPtr.h lua/usertype/Entity.cpp lua/usertype/Entity.h game/entity/LuaEntity.cpp game/entity/LuaEntity.h game/entity/LocalLuaEntity.cpp game/entity/LocalLuaEntity.h)
|
|
@ -11,7 +11,7 @@ ClientState::ClientState(const std::string& path, Renderer& renderer) :
|
|||
defs(path + "assets\\textures") {}
|
||||
#else
|
||||
ClientState::ClientState(const std::string &path, Renderer &renderer) :
|
||||
path(path),
|
||||
renderer(renderer),
|
||||
defs(path + "/assets/textures") {}
|
||||
path(path),
|
||||
renderer(renderer),
|
||||
game(path + "/assets/textures") {}
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
Renderer& renderer;
|
||||
ServerConnection connection {};
|
||||
LocalSubgame defs;
|
||||
LocalSubgame game;
|
||||
|
||||
unsigned int seed = 0;
|
||||
|
||||
|
|
|
@ -10,13 +10,15 @@
|
|||
#include "Model.h"
|
||||
#include "AnimationSegment.h"
|
||||
#include "../graph/Renderer.h"
|
||||
#include "../graph/meshtypes/EntityMesh.h"
|
||||
|
||||
DrawableEntity::DrawableEntity() : model(std::make_shared<Model>()) {}
|
||||
|
||||
DrawableEntity::DrawableEntity(std::shared_ptr<Model> model) :
|
||||
animState(*model),
|
||||
model(model) {}
|
||||
DrawableEntity::DrawableEntity(SubgamePtr game, DimensionPtr dim) :
|
||||
Entity(game, dim),
|
||||
model(std::make_shared<Model>()) {}
|
||||
|
||||
DrawableEntity::DrawableEntity(SubgamePtr game, DimensionPtr dim, std::shared_ptr<Model> model) :
|
||||
Entity(game, dim),
|
||||
model(model), animState(*model) {}
|
||||
|
||||
void DrawableEntity::setModel(std::shared_ptr<Model> model) {
|
||||
animState = AnimationState(*model);
|
||||
|
@ -154,4 +156,4 @@ void DrawableEntity::cleanup() {
|
|||
|
||||
DrawableEntity::~DrawableEntity() {
|
||||
cleanup();
|
||||
}
|
||||
}
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
class DrawableEntity : virtual public Entity, public Drawable {
|
||||
public:
|
||||
DrawableEntity();
|
||||
DrawableEntity(const DrawableEntity& o) = delete;
|
||||
explicit DrawableEntity(std::shared_ptr<Model> model);
|
||||
DrawableEntity() = default;
|
||||
DrawableEntity(SubgamePtr game, DimensionPtr dim);
|
||||
explicit DrawableEntity(SubgamePtr game, DimensionPtr dim, std::shared_ptr<Model> model);
|
||||
|
||||
void update(double delta) override;
|
||||
void setModel(std::shared_ptr<Model> model);
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
|
||||
#include "Entity.h"
|
||||
|
||||
unsigned int Entity::getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void Entity::setId(unsigned int id) {
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
glm::vec3 Entity::getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
@ -20,6 +28,14 @@ void Entity::setVel(glm::vec3 velocity) {
|
|||
this->vel = velocity;
|
||||
}
|
||||
|
||||
glm::vec3 Entity::getRot() {
|
||||
return rot;
|
||||
}
|
||||
|
||||
void Entity::setRot(glm::vec3 rot) {
|
||||
this->rot = rot;
|
||||
}
|
||||
|
||||
glm::vec3 Entity::getVisualOffset() {
|
||||
return visualOff;
|
||||
}
|
||||
|
@ -62,4 +78,16 @@ void Entity::setScale(float scale) {
|
|||
|
||||
void Entity::setScale(glm::vec3 scale) {
|
||||
this->scale = scale;
|
||||
}
|
||||
}
|
||||
|
||||
DimensionPtr Entity::getDim() {
|
||||
return dim;
|
||||
}
|
||||
|
||||
void Entity::setDim(DimensionPtr dim) {
|
||||
this->dim = dim;
|
||||
}
|
||||
|
||||
SubgamePtr Entity::getGame() {
|
||||
return game;
|
||||
}
|
||||
|
|
|
@ -6,16 +6,23 @@
|
|||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "../../util/CovariantPtr.h"
|
||||
#include "../../def/item/SelectionBox.h"
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity() = default;
|
||||
Entity(SubgamePtr game, DimensionPtr dim) : game(game), dim(dim) {};
|
||||
|
||||
virtual glm::vec3 getPos();
|
||||
virtual void setPos(glm::vec3 position);
|
||||
|
||||
virtual glm::vec3 getVel();
|
||||
virtual void setVel(glm::vec3 velocity);
|
||||
|
||||
virtual glm::vec3 getRot();
|
||||
virtual void setRot(glm::vec3 rot);
|
||||
|
||||
virtual glm::vec3 getVisualOffset();
|
||||
virtual void setVisualOffset(glm::vec3 vs);
|
||||
|
||||
|
@ -32,7 +39,20 @@ public:
|
|||
virtual void setScale(float scale);
|
||||
virtual void setScale(glm::vec3 scale);
|
||||
|
||||
virtual unsigned int getId();
|
||||
virtual void setId(unsigned int id);
|
||||
|
||||
virtual DimensionPtr getDim();
|
||||
virtual void setDim(DimensionPtr dim);
|
||||
|
||||
SubgamePtr getGame();
|
||||
|
||||
protected:
|
||||
SubgamePtr game = nullptr;
|
||||
DimensionPtr dim = nullptr;
|
||||
|
||||
unsigned int id = 0;
|
||||
|
||||
glm::vec3 pos {};
|
||||
glm::vec3 vel {};
|
||||
glm::vec3 rot {};
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-05.
|
||||
//
|
||||
|
||||
#include "LocalLuaEntity.h"
|
||||
|
||||
#include "../../def/ItemDef.h"
|
||||
#include "../../def/LocalSubgame.h"
|
||||
#include "../../def/DefinitionAtlas.h"
|
||||
|
||||
LocalLuaEntity::LocalLuaEntity(SubgamePtr game, DimensionPtr dim) :
|
||||
LuaEntity(game, dim), DrawableEntity(game, dim), Entity(game, dim) {}
|
||||
|
||||
void LocalLuaEntity::setAppearance(const std::string &dMode, const std::string &argA, const std::string &argB) {
|
||||
if (dMode == "gameobject" && (argA == "block" || argA == "craftitem")) {
|
||||
ItemDef& def = getGame()->getDefs().fromStr(argB);
|
||||
setModel(def.entityModel);
|
||||
}
|
||||
else if (dMode == "model" && !argB.empty()) {
|
||||
auto model = std::make_shared<Model>();
|
||||
model->fromSerialized(getGame().l()->models.models[argA], { getGame().l()->textures[argB] });
|
||||
setModel(model);
|
||||
}
|
||||
else throw std::runtime_error("Invalid appearance arguments specified.");
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-05.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LuaEntity.h"
|
||||
#include "DrawableEntity.h"
|
||||
|
||||
class LocalLuaEntity : public virtual DrawableEntity, public LuaEntity {
|
||||
public:
|
||||
LocalLuaEntity(SubgamePtr game, DimensionPtr dim);
|
||||
|
||||
virtual void setAppearance(const std::string& dMode, const std::string& argA, const std::string& argB) override;
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-05.
|
||||
//
|
||||
|
||||
#include "LuaEntity.h"
|
||||
|
||||
LuaEntity::LuaEntity(SubgamePtr game, DimensionPtr dim) : Entity(game, dim) {}
|
|
@ -0,0 +1,14 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-05.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Entity.h"
|
||||
|
||||
class LuaEntity : public virtual Entity {
|
||||
public:
|
||||
LuaEntity(SubgamePtr game, DimensionPtr dim);
|
||||
|
||||
virtual void setAppearance(const std::string& dMode, const std::string& argA, const std::string& argB) = 0;
|
||||
};
|
|
@ -9,7 +9,8 @@
|
|||
#include "../../../def/item/BlockDef.h"
|
||||
#include "../../../def/texture/AtlasRef.h"
|
||||
|
||||
ParticleEntity::ParticleEntity(glm::vec3 pos, BlockDef &block) : DrawableEntity(std::make_shared<Model>()) {
|
||||
ParticleEntity::ParticleEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, BlockDef &block) :
|
||||
DrawableEntity(game, dim, std::make_shared<Model>()), Entity(game, dim) {
|
||||
setPos(pos + glm::vec3(.5,.3,.5));
|
||||
|
||||
std::set<std::shared_ptr<AtlasRef>>& textureRefs = block.model.textureRefs;
|
||||
|
|
|
@ -10,7 +10,7 @@ class BlockDef;
|
|||
|
||||
class ParticleEntity : public DrawableEntity {
|
||||
public:
|
||||
ParticleEntity(glm::vec3 pos, BlockDef& block);
|
||||
ParticleEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, BlockDef& block);
|
||||
|
||||
void update(double delta, glm::vec3 player);
|
||||
void draw(Renderer& renderer) override;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
class PlayerEntity : public DrawableEntity {
|
||||
public:
|
||||
PlayerEntity(Subgame& game, Dimension* dim, glm::vec3 pos, unsigned int id, const std::shared_ptr<Model>& model) :
|
||||
DrawableEntity(model), id(id) {
|
||||
PlayerEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, unsigned int id, const std::shared_ptr<Model>& model) :
|
||||
DrawableEntity(game, dim, model), Entity(game, dim), id(id) {
|
||||
setPos(pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
|
||||
class WireframeEntity : public DrawableEntity {
|
||||
public:
|
||||
WireframeEntity(glm::vec3 color) : DrawableEntity(std::make_shared<Model>()), color(color) {};
|
||||
WireframeEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 color) :
|
||||
DrawableEntity(game, dim, std::make_shared<Model>()), Entity(game, dim),
|
||||
color(color) {};
|
||||
|
||||
void updateMesh(const std::vector<SelectionBox>& boxes, float width);
|
||||
private:
|
||||
|
|
|
@ -73,7 +73,7 @@ void GuiInventoryList::setCallback(CallbackType type, const callback& cb) {
|
|||
if (cb) cb(down, pos);
|
||||
|
||||
if (type == GuiComponent::CallbackType::HOVER) this->hoverEvent(down, pos);
|
||||
else this->interactEvent(pos, type == GuiComponent::CallbackType::PRIMARY);
|
||||
else if (down) this->interactEvent(pos, type == GuiComponent::CallbackType::PRIMARY);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,9 @@ void ServerInventory::createList(const std::string &name, unsigned short length,
|
|||
lists.emplace(name, std::make_shared<ServerInventoryList>(game, clients, name, this->name, length, width));
|
||||
}
|
||||
|
||||
//void ServerInventory::sendDirtyLists() {
|
||||
// for (auto& list : lists) {
|
||||
// if (list.second->dirty) {
|
||||
// list.second->sendAll();
|
||||
// list.second->dirty = false;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
void ServerInventory::sendDirtyLists() {
|
||||
for (auto& l : lists) {
|
||||
auto list = std::static_pointer_cast<ServerInventoryList>(l.second);
|
||||
if (list->dirty) list->sendToAll();
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
virtual void createList(const std::string& name, unsigned short length, unsigned short width) override;
|
||||
|
||||
// void sendDirtyLists();
|
||||
void sendDirtyLists();
|
||||
private:
|
||||
ServerClients& clients;
|
||||
};
|
||||
|
|
|
@ -50,4 +50,6 @@ void ServerInventoryList::sendToAll() {
|
|||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ ServerInventoryRefs::ServerInventoryRefs(SubgamePtr game, ServerClients& clients
|
|||
InventoryRefs(game), clients(clients) {}
|
||||
|
||||
void ServerInventoryRefs::update() {
|
||||
// for (auto& inv : inventories)
|
||||
// std::static_pointer_cast<ServerInventory>(inv.second)->sendDirtyLists();
|
||||
for (auto& inv : inventories)
|
||||
std::static_pointer_cast<ServerInventory>(inv.second)->sendDirtyLists();
|
||||
}
|
||||
|
||||
InventoryPtr ServerInventoryRefs::createInventory(const std::string &inv) {
|
||||
|
|
|
@ -21,7 +21,7 @@ ConnectScene::ConnectScene(ClientState &state, Address addr) : Scene(state),
|
|||
|
||||
state.renderer.setClearColor(10, 10, 10);
|
||||
|
||||
Font f(state.defs.textures, state.defs.textures["font"]);
|
||||
Font f(state.game.textures, state.game.textures["font"]);
|
||||
|
||||
auto statusText = std::make_shared<GuiText>("statusText");
|
||||
statusText->create({2, 2}, {}, {}, {1, 1, 1, 1}, f);
|
||||
|
@ -42,7 +42,7 @@ ConnectScene::ConnectScene(ClientState &state, Address addr) : Scene(state),
|
|||
}
|
||||
|
||||
void ConnectScene::update() {
|
||||
state.defs.textures.update();
|
||||
state.game.textures.update();
|
||||
|
||||
switch (connectState) {
|
||||
default:
|
||||
|
@ -88,7 +88,7 @@ void ConnectScene::update() {
|
|||
auto statusText = components.get<GuiText>("statusText");
|
||||
statusText->setText(statusText->getText() + "Received block index-identifier table.\n");
|
||||
|
||||
state.defs.getDefs().setIdentifiers(p.d.read<std::vector<std::string>>());
|
||||
state.game.getDefs().setIdentifiers(p.d.read<std::vector<std::string>>());
|
||||
|
||||
Packet resp(Packet::Type::BIOME_IDENTIFIER_LIST);
|
||||
resp.sendTo(connection.getPeer(), Packet::Channel::CONNECT);
|
||||
|
@ -97,7 +97,7 @@ void ConnectScene::update() {
|
|||
auto statusText = components.get<GuiText>("statusText");
|
||||
statusText->setText(statusText->getText() + "Received biome index-identifier table.\nDownloading mods...\n");
|
||||
|
||||
state.defs.getBiomes().setIdentifiers(p.d.read<std::vector<std::string>>());
|
||||
state.game.getBiomes().setIdentifiers(p.d.read<std::vector<std::string>>());
|
||||
|
||||
connectState = State::MODS;
|
||||
Packet resp(Packet::Type::MODS);
|
||||
|
@ -118,10 +118,10 @@ void ConnectScene::update() {
|
|||
if (p.type == Packet::Type::MODS) {
|
||||
auto luaMod = LuaMod::fromPacket(p);
|
||||
statusText->setText(statusText->getText() + "Received mod " + luaMod.config.name + ".\n");
|
||||
state.defs.getParser().getHandler().addLuaMod(std::move(luaMod));
|
||||
state.game.getParser().getHandler().addLuaMod(std::move(luaMod));
|
||||
}
|
||||
else if (p.type == Packet::Type::MOD_ORDER) {
|
||||
state.defs.getParser().getHandler().setModsOrder(p.d.read<std::vector<std::string>>());
|
||||
state.game.getParser().getHandler().setModsOrder(p.d.read<std::vector<std::string>>());
|
||||
|
||||
statusText->setText(statusText->getText() + "Done downloading mods.\nReceived the mods order.\nDownloading media...\n");
|
||||
|
||||
|
@ -156,7 +156,7 @@ void ConnectScene::update() {
|
|||
std::string data = p.d.read<std::string>();
|
||||
std::string uncompressed = gzip::decompress(data.data(), data.length());
|
||||
|
||||
state.defs.textures.addImage(
|
||||
state.game.textures.addImage(
|
||||
reinterpret_cast<unsigned char *>(const_cast<char *>(uncompressed.data())),
|
||||
assetName, true, width, height);
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ void ConnectScene::update() {
|
|||
std::string format = p.d.read<std::string>();
|
||||
std::string data = p.d.read<std::string>();
|
||||
|
||||
state.defs.models.models.insert({assetName, SerializedModel{assetName, data, format}});
|
||||
state.game.models.models.insert({assetName, SerializedModel{assetName, data, format}});
|
||||
}
|
||||
|
||||
t = static_cast<AssetType>(p.d.read<int>());
|
||||
|
@ -230,7 +230,7 @@ void ConnectScene::draw() {
|
|||
renderer.beginChunkDeferredCalls();
|
||||
renderer.endDeferredCalls();
|
||||
renderer.beginGUIDrawCalls();
|
||||
renderer.enableTexture(&state.defs.textures.atlasTexture);
|
||||
renderer.enableTexture(&state.game.textures.atlasTexture);
|
||||
|
||||
components.draw(renderer);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "../../net/PacketView.h"
|
||||
|
||||
GameScene::GameScene(ClientState& state) : Scene(state),
|
||||
game(std::make_shared<LocalSubgame>(state.defs)),
|
||||
game(std::make_shared<LocalSubgame>(state.game)),
|
||||
world(std::make_shared<LocalWorld>(game, state.connection, state.renderer)),
|
||||
debugGui(state.renderer.window.getSize(), game, world) {
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ LuaErrorScene::LuaErrorScene(ClientState &state, const std::string &err) : Scene
|
|||
state.renderer.setClearColor(0, 0, 0);
|
||||
state.renderer.window.input.lockMouse(false);
|
||||
|
||||
Font f(state.defs.textures, state.defs.textures["font"]);
|
||||
Font f(state.game.textures, state.game.textures["font"]);
|
||||
glm::ivec2 win = state.renderer.window.getSize();
|
||||
|
||||
auto container = std::make_shared<GuiRect>("container");
|
||||
|
@ -40,7 +40,7 @@ LuaErrorScene::LuaErrorScene(ClientState &state, const std::string &err) : Scene
|
|||
}
|
||||
|
||||
void LuaErrorScene::update() {
|
||||
state.defs.textures.update();
|
||||
state.game.textures.update();
|
||||
}
|
||||
|
||||
void LuaErrorScene::draw() {
|
||||
|
@ -49,7 +49,7 @@ void LuaErrorScene::draw() {
|
|||
renderer.beginChunkDeferredCalls();
|
||||
renderer.endDeferredCalls();
|
||||
renderer.beginGUIDrawCalls();
|
||||
renderer.enableTexture(&state.defs.textures.atlasTexture);
|
||||
renderer.enableTexture(&state.game.textures.atlasTexture);
|
||||
|
||||
components.draw(renderer);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ MainMenuScene::MainMenuScene(ClientState& state) :
|
|||
state.renderer.setClearColor(0, 0, 0);
|
||||
state.renderer.window.input.lockMouse(false);
|
||||
|
||||
Font f(state.defs.textures, state.defs.textures["font"]);
|
||||
Font f(state.game.textures, state.game.textures["font"]);
|
||||
win = state.renderer.window.getSize();
|
||||
sandboxArea = win - glm::ivec2(0, 18 * GS);
|
||||
|
||||
|
@ -55,28 +55,28 @@ MainMenuScene::MainMenuScene(ClientState& state) :
|
|||
{
|
||||
auto settingsButton = std::make_shared<GuiImageButton>("settingsButton");
|
||||
settingsButton->create({16 * GS, 16 * GS}, {},
|
||||
state.defs.textures["crop(0, 0, 16, 16, menu_flag_settings)"],
|
||||
state.defs.textures["crop(16, 0, 16, 16, menu_flag_settings)"]);
|
||||
state.game.textures["crop(0, 0, 16, 16, menu_flag_settings)"],
|
||||
state.game.textures["crop(16, 0, 16, 16, menu_flag_settings)"]);
|
||||
navigationBar->get<GuiContainer>("navigationBarIcons")->add(settingsButton);
|
||||
|
||||
auto closeButton = std::make_shared<GuiImageButton>("closeButton");
|
||||
closeButton->create({16 * GS, 16 * GS}, {},
|
||||
state.defs.textures["crop(0, 0, 16, 16, menu_flag_quit)"],
|
||||
state.defs.textures["crop(16, 0, 16, 16, menu_flag_quit)"]);
|
||||
state.game.textures["crop(0, 0, 16, 16, menu_flag_quit)"],
|
||||
state.game.textures["crop(16, 0, 16, 16, menu_flag_quit)"]);
|
||||
closeButton->setCallback(GuiComponent::CallbackType::PRIMARY, [](bool down, glm::ivec2) { if (down) exit(0); });
|
||||
navigationBar->get<GuiContainer>("navigationBarIcons")->add(closeButton);
|
||||
|
||||
auto serversButton = std::make_shared<GuiImageButton>("serversButton");
|
||||
serversButton->create({16 * GS, 16 * GS}, {},
|
||||
state.defs.textures["crop(0, 0, 16, 16, menu_flag_multiplayer)"],
|
||||
state.defs.textures["crop(16, 0, 16, 16, menu_flag_multiplayer)"]);
|
||||
state.game.textures["crop(0, 0, 16, 16, menu_flag_multiplayer)"],
|
||||
state.game.textures["crop(16, 0, 16, 16, menu_flag_multiplayer)"]);
|
||||
serversButton->setPos({GS, GS});
|
||||
navigationBarIcons->add(serversButton);
|
||||
|
||||
auto contentButton = std::make_shared<GuiImageButton>("contentButton");
|
||||
contentButton->create({16 * GS, 16 * GS}, {},
|
||||
state.defs.textures["crop(0, 0, 16, 16, menu_flag_content)"],
|
||||
state.defs.textures["crop(16, 0, 16, 16, menu_flag_content)"]);
|
||||
state.game.textures["crop(0, 0, 16, 16, menu_flag_content)"],
|
||||
state.game.textures["crop(16, 0, 16, 16, menu_flag_content)"]);
|
||||
contentButton->setPos({GS + GS * 18, GS});
|
||||
contentButton->setCallback(GuiComponent::CallbackType::PRIMARY, [&](bool down, glm::ivec2) { if (down) state.desiredState = "connect"; });
|
||||
navigationBarIcons->add(contentButton);
|
||||
|
@ -92,8 +92,8 @@ MainMenuScene::MainMenuScene(ClientState& state) :
|
|||
auto &subgame = subgames[i];
|
||||
auto button = std::make_shared<GuiImageButton>(subgame.config.name);
|
||||
button->create({16 * GS, 16 * GS}, {},
|
||||
state.defs.textures["crop(0, 0, 16, 16, " + subgame.iconRef->name + ")"],
|
||||
state.defs.textures["crop(16, 0, 16, 16, " + subgame.iconRef->name + ")"]);
|
||||
state.game.textures["crop(0, 0, 16, 16, " + subgame.iconRef->name + ")"],
|
||||
state.game.textures["crop(16, 0, 16, 16, " + subgame.iconRef->name + ")"]);
|
||||
button->setPos({GS * 7 + GS * 18 * (i + 2), GS});
|
||||
button->setCallback(GuiComponent::CallbackType::PRIMARY, [&, i](bool down, glm::ivec2) {
|
||||
if (down) {
|
||||
|
@ -165,8 +165,8 @@ void MainMenuScene::findSubgames() {
|
|||
std::string description = (j["description"].is_string() ? j["description"] : "");
|
||||
std::string version = j["version"];
|
||||
|
||||
std::shared_ptr<AtlasRef> icon = state.defs.textures["menu_flag_missing"];
|
||||
if (hasIcon) icon = state.defs.textures.loadImage(std::string(subgameFolder.path) + "/icon.png", name);
|
||||
std::shared_ptr<AtlasRef> icon = state.game.textures["menu_flag_missing"];
|
||||
if (hasIcon) icon = state.game.textures.loadImage(std::string(subgameFolder.path) + "/icon.png", name);
|
||||
|
||||
subgames.push_back({icon, {name, description, version}, subgameFolder.path});
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ void MainMenuScene::positionElements() {
|
|||
auto navigationBarBg = navigationBar->get<GuiContainer>("navigationBarBg");
|
||||
for (unsigned int i = 0; i < static_cast<float>(win.x) / 64.f / GS; i++) {
|
||||
auto segment = std::make_shared<GuiRect>("segment_" + std::to_string(i));
|
||||
segment->create({64 * GS, 18 * GS}, {}, state.defs.textures["menu_bar_bg"]);
|
||||
segment->create({64 * GS, 18 * GS}, {}, state.game.textures["menu_bar_bg"]);
|
||||
segment->setPos({i * 64 * GS, 0});
|
||||
navigationBarBg->add(segment);
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ void MainMenuScene::positionElements() {
|
|||
}
|
||||
|
||||
void MainMenuScene::update() {
|
||||
state.defs.textures.update();
|
||||
state.game.textures.update();
|
||||
sandbox.update(state.delta);
|
||||
|
||||
components.handleMouseInput(state.renderer.window);
|
||||
|
@ -213,7 +213,7 @@ void MainMenuScene::draw() {
|
|||
state.renderer.endDeferredCalls();
|
||||
|
||||
state.renderer.beginGUIDrawCalls();
|
||||
state.renderer.enableTexture(&state.defs.textures.atlasTexture);
|
||||
state.renderer.enableTexture(&state.game.textures.atlasTexture);
|
||||
components.draw(state.renderer);
|
||||
state.renderer.swapBuffers();
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
#include "../../../lua/modules/mSetGui.h"
|
||||
#include "../../../lua/modules/mStartGame.h"
|
||||
|
||||
MenuSandbox::MenuSandbox(glm::ivec2 &win, ClientState& state, std::shared_ptr<GuiContainer> container) : LuaParser(state.defs),
|
||||
MenuSandbox::MenuSandbox(glm::ivec2 &win, ClientState& state, std::shared_ptr<GuiContainer> container) : LuaParser(state.game),
|
||||
win(win),
|
||||
state(state),
|
||||
container(container),
|
||||
luaContainer(std::dynamic_pointer_cast<GuiContainer>(container->add(std::make_shared<GuiContainer>("__lua")))),
|
||||
builder(state.defs.textures, state.defs.models, luaContainer) {}
|
||||
builder(state.game.textures, state.game.models, luaContainer) {}
|
||||
|
||||
void MenuSandbox::reset() {
|
||||
container->remove("error");
|
||||
|
@ -149,7 +149,7 @@ void MenuSandbox::loadAndRunMod(const std::string &modPath) {
|
|||
|
||||
std::string texPath = modPath + "/textures";
|
||||
if (cf_file_exists(texPath.data())) {
|
||||
this->modAssets = state.defs.textures.loadDirectory(texPath, false, true);
|
||||
this->modAssets = state.game.textures.loadDirectory(texPath, false, true);
|
||||
}
|
||||
|
||||
this->mod = mod;
|
||||
|
@ -158,7 +158,7 @@ void MenuSandbox::loadAndRunMod(const std::string &modPath) {
|
|||
|
||||
void MenuSandbox::showError(const std::string& what, const std::string& subgame) {
|
||||
const std::string errPrefixText = "Encountered an error while loading the menu for " + subgame + " ;-;";
|
||||
Font f(state.defs.textures, state.defs.textures["font"]);
|
||||
Font f(state.game.textures, state.game.textures["font"]);
|
||||
|
||||
auto errWrap = std::make_shared<GuiContainer>("error");
|
||||
container->add(errWrap);
|
||||
|
|
|
@ -12,11 +12,12 @@
|
|||
#include "../../../def/item/BlockDef.h"
|
||||
#include "../../../world/chunk/Chunk.h"
|
||||
#include "../../../net/client/ClientNetworkInterpreter.h"
|
||||
#include "NetField.h"
|
||||
|
||||
LocalPlayer::LocalPlayer(SubgamePtr game, LocalWorld& world, DimensionPtr dim, Renderer &renderer) :
|
||||
Player(game, world, dim),
|
||||
Player(game, world, dim), DrawableEntity(game, dim), Entity(game, dim),
|
||||
renderer(renderer),
|
||||
wireframe({1, 1, 1}),
|
||||
wireframe(game, dim, {1, 1, 1}),
|
||||
gameGui(world.getRefs().l(), renderer.window.getSize(), game.l(), renderer) {
|
||||
|
||||
handItemModel.parent = &handModel;
|
||||
|
@ -49,12 +50,12 @@ void LocalPlayer::assertField(Packet packet) {
|
|||
void LocalPlayer::handleAssertion(Deserializer &d) {
|
||||
while (!d.atEnd()) {
|
||||
switch (d.readE<NetField>()) {
|
||||
case NetField::ID: id = d.read<unsigned int>(); break;
|
||||
case NetField::POS: setPos(d.read<glm::vec3>()); break;
|
||||
case NetField::VEL: setVel(d.read<glm::vec3>()); break;
|
||||
case NetField::YAW: setYaw(d.read<float>()); break;
|
||||
case NetField::PITCH: setPitch(d.read<float>()); break;
|
||||
case NetField::FLYING: setFlying(d.read<bool>()); break;
|
||||
case NetField::ID: setId(d.read<unsigned int>()); break;
|
||||
case NetField::POS: setPos(d.read<glm::vec3>()); break;
|
||||
case NetField::VEL: setVel(d.read<glm::vec3>()); break;
|
||||
case NetField::LOOK_YAW: setYaw(d.read<float>()); break;
|
||||
case NetField::LOOK_PITCH: setPitch(d.read<float>()); break;
|
||||
case NetField::FLYING: setFlying(d.read<bool>()); break;
|
||||
|
||||
case NetField::HAND_INV: setHandList(d.read<std::string>()); break;
|
||||
case NetField::WIELD_INV: setWieldList(d.read<std::string>()); break;
|
||||
|
@ -98,8 +99,8 @@ void LocalPlayer::setWieldIndex(unsigned short index, bool assert) {
|
|||
updateWieldAndHandItems();
|
||||
}
|
||||
|
||||
void LocalPlayer::setDimension(DimensionPtr dim) {
|
||||
Player::setDimension(dim);
|
||||
void LocalPlayer::setDim(DimensionPtr dim) {
|
||||
Player::setDim(dim);
|
||||
static_cast<LocalWorld&>(world).setActiveDimension(dim);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
virtual void setHandList(const std::string& list, bool assert = false) override;
|
||||
virtual void setWieldList(const std::string& list, bool assert = false) override;
|
||||
virtual void setWieldIndex(unsigned short index, bool assert = false) override;
|
||||
virtual void setDimension(DimensionPtr dim) override;
|
||||
virtual void setDim(DimensionPtr dim) override;
|
||||
|
||||
bool isInMenu();
|
||||
void showMenu(std::shared_ptr<LuaGuiElement> root);
|
||||
|
|
|
@ -24,7 +24,7 @@ void LocalWorld::connect() {
|
|||
|
||||
bool LocalWorld::updatePlayerDimension() {
|
||||
if (defaultDimension.empty()) return false;
|
||||
player->setDimension(getDefaultDimension());
|
||||
player->setDim(getDefaultDimension());
|
||||
activeDimension = getDefaultDimension().l();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-05.
|
||||
//
|
||||
|
||||
#include "NetField.h"
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-05.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <glm/vec3.hpp>
|
||||
#include "../../entity/Entity.h"
|
||||
#include "../../../util/CovariantPtr.h"
|
||||
#include "../../../def/DefinitionAtlas.h"
|
||||
|
||||
enum class NetField {
|
||||
// General
|
||||
ID,
|
||||
POS,
|
||||
VEL,
|
||||
ROT,
|
||||
SCALE,
|
||||
|
||||
// Entities
|
||||
DISPLAY,
|
||||
VISUAL_OFF,
|
||||
|
||||
// Players
|
||||
LOOK_OFF,
|
||||
LOOK_PITCH,
|
||||
LOOK_YAW,
|
||||
|
||||
FLYING,
|
||||
|
||||
HAND_INV,
|
||||
WIELD_INV,
|
||||
WIELD_INDEX,
|
||||
};
|
|
@ -6,14 +6,7 @@
|
|||
#include "Player.h"
|
||||
|
||||
#include "../../../net/Serializer.h"
|
||||
|
||||
unsigned int Player::getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void Player::setId(unsigned int id) {
|
||||
this->id = id;
|
||||
}
|
||||
#include "NetField.h"
|
||||
|
||||
void Player::setPos(glm::vec3 pos, bool assert) {
|
||||
Entity::setPos(pos);
|
||||
|
@ -31,7 +24,7 @@ float Player::getYaw() {
|
|||
|
||||
void Player::setYaw(float yaw, bool assert) {
|
||||
this->yaw = yaw;
|
||||
if (assert) assertField(Serializer().appendE(NetField::YAW).append(yaw).packet());
|
||||
if (assert) assertField(Serializer().appendE(NetField::LOOK_YAW).append(yaw).packet());
|
||||
}
|
||||
|
||||
float Player::getPitch() {
|
||||
|
@ -40,7 +33,7 @@ float Player::getPitch() {
|
|||
|
||||
void Player::setPitch(float pitch, bool assert) {
|
||||
this->pitch = pitch;
|
||||
if (assert) assertField(Serializer().appendE(NetField::PITCH).append(pitch).packet());
|
||||
if (assert) assertField(Serializer().appendE(NetField::LOOK_PITCH).append(pitch).packet());
|
||||
}
|
||||
|
||||
glm::vec3 Player::getLookOffset() {
|
||||
|
@ -87,13 +80,4 @@ unsigned short Player::getWieldIndex() {
|
|||
void Player::setWieldIndex(unsigned short index, bool assert) {
|
||||
wieldIndex = index;
|
||||
if (assert) assertField(Serializer().appendE(NetField::WIELD_INDEX).append(index).packet());
|
||||
}
|
||||
|
||||
void Player::setDimension(DimensionPtr dim) {
|
||||
this->dim = dim;
|
||||
}
|
||||
|
||||
|
||||
DimensionPtr Player::getDimension() {
|
||||
return dim;
|
||||
}
|
|
@ -21,18 +21,13 @@ class InventoryList;
|
|||
|
||||
class Player : public virtual Entity {
|
||||
public:
|
||||
enum class NetField {
|
||||
ID, POS, VEL, PITCH, YAW, LOOK_OFF, FLYING,
|
||||
HAND_INV, WIELD_INV, WIELD_INDEX };
|
||||
|
||||
Player(SubgamePtr game, World& world, DimensionPtr dim, unsigned int id = 0) :
|
||||
game(game), world(world), dim(dim), id(id), lookOffset(0, 1.65, 0) {
|
||||
Entity(game, dim),
|
||||
world(world), lookOffset(0, 1.65, 0) {
|
||||
collision = {{-0.3, 0, -0.3}, {0.3, 1.8, 0.3}};
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
virtual unsigned int getId();
|
||||
virtual void setId(unsigned int id);
|
||||
|
||||
virtual void setPos(glm::vec3 pos, bool assert = false);
|
||||
virtual void setVel(glm::vec3 vel, bool assert = false);
|
||||
|
||||
|
@ -57,20 +52,13 @@ public:
|
|||
virtual unsigned short getWieldIndex();
|
||||
virtual void setWieldIndex(unsigned short index, bool assert = false);
|
||||
|
||||
DimensionPtr getDimension();
|
||||
virtual void setDimension(DimensionPtr dim);
|
||||
|
||||
virtual InventoryPtr getInventory() = 0;
|
||||
|
||||
virtual void handleAssertion(Deserializer& d) = 0;
|
||||
protected:
|
||||
virtual void assertField(Packet packet) = 0;
|
||||
|
||||
unsigned int id = 0;
|
||||
|
||||
World& world;
|
||||
SubgamePtr game;
|
||||
DimensionPtr dim;
|
||||
|
||||
float yaw = 0;
|
||||
float pitch = 0;
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
// Usertypes
|
||||
#include "usertype/Target.h"
|
||||
#include "usertype/Player.h"
|
||||
#include "usertype/Entity.h"
|
||||
#include "usertype/Inventory.h"
|
||||
#include "usertype/Dimension.h"
|
||||
#include "usertype/ItemStack.h"
|
||||
#include "usertype/InventoryList.h"
|
||||
|
||||
#include "usertype/LuaGuiElement.h"
|
||||
#include "usertype/cLuaEntity.h"
|
||||
#include "usertype/cAnimationManager.h"
|
||||
|
||||
// Modules
|
||||
|
@ -63,11 +63,11 @@ void LocalLuaParser::loadApi(WorldPtr world, PlayerPtr player) {
|
|||
core["__builtin"] = lua.create_table();
|
||||
|
||||
// Types
|
||||
ClientApi::entity (lua);
|
||||
ClientApi::animation_manager (lua);
|
||||
ClientApi::gui_element (lua);
|
||||
|
||||
Api::Usertype::Target::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::Entity::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::Inventory::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::Dimension::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::ItemStack::bind(Api::State::CLIENT, lua, core);
|
||||
|
@ -79,8 +79,8 @@ void LocalLuaParser::loadApi(WorldPtr world, PlayerPtr player) {
|
|||
|
||||
// Modules
|
||||
modules.emplace_back(std::make_unique<Api::Module::Time>(Api::State::CLIENT, lua, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Register>(Api::State::CLIENT, core, game, *world.l()));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Dimension>(Api::State::CLIENT, core, game, *world.l()));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Register>(Api::State::CLIENT, core, game, **world));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Dimension>(Api::State::CLIENT, core, game, **world));
|
||||
|
||||
bindModules();
|
||||
|
||||
|
|
|
@ -18,13 +18,12 @@
|
|||
// Usertypes
|
||||
#include "usertype/Target.h"
|
||||
#include "usertype/Player.h"
|
||||
#include "usertype/Entity.h"
|
||||
#include "usertype/Inventory.h"
|
||||
#include "usertype/Dimension.h"
|
||||
#include "usertype/ItemStack.h"
|
||||
#include "usertype/InventoryList.h"
|
||||
|
||||
#include "usertype/sLuaEntity.h"
|
||||
|
||||
// Modules
|
||||
#include "modules/Time.h"
|
||||
#include "modules/Register.h"
|
||||
|
@ -95,9 +94,8 @@ void ServerLuaParser::loadApi(WorldPtr world) {
|
|||
core["__builtin"] = lua.create_table();
|
||||
|
||||
// Types
|
||||
ServerApi::entity (lua);
|
||||
|
||||
Api::Usertype::Target::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::Entity::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::Inventory::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::Dimension::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::ItemStack::bind(Api::State::SERVER, lua, core);
|
||||
|
|
|
@ -6,14 +6,13 @@
|
|||
|
||||
#include "../Lua.h"
|
||||
#include "../LuaParser.h"
|
||||
#include "LocalLuaEntity.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../world/LocalDimension.h"
|
||||
#include "../../net/server/world/ServerEntity.h"
|
||||
#include "../../def/ServerSubgame.h"
|
||||
#include "ServerLuaEntity.h"
|
||||
#include "../../world/LocalDimension.h"
|
||||
#include "../../world/ServerDimension.h"
|
||||
#include "../../game/entity/LocalLuaEntity.h"
|
||||
#include "../../net/server/world/ServerLuaEntity.h"
|
||||
|
||||
std::string Api::Usertype::Dimension::get_block(glm::ivec3 pos) {
|
||||
return dim->getGame()->getDefs().fromId(dim->getBlock(pos)).identifier;
|
||||
|
@ -68,13 +67,14 @@ sol::table Api::Usertype::Dimension::add_entity_c(sol::this_state s, glm::vec3 p
|
|||
auto displayTexture = luaEntity.get<sol::optional<std::string>>("display_texture");
|
||||
if (strncmp(displayType->data(), "model", 5) == 0 && !displayTexture) throw std::runtime_error("entity '" + identifier + "' is missing the display_texture property.");
|
||||
|
||||
auto entity = std::make_unique<::DrawableEntity>();
|
||||
auto entity = std::make_shared<::LocalLuaEntity>(dim->getGame(), dim);
|
||||
entity->setId(dim->nextEntityInd());
|
||||
entity->setPos(pos);
|
||||
auto ref = std::make_shared<LocalLuaEntity>(std::move(entity), dim->nextEntityInd(), dim->getGame().l());
|
||||
Entity ref(entity);
|
||||
|
||||
luaEntity["object"] = ref;
|
||||
ref->set_display_type(*displayType, *displayObject, displayTexture);
|
||||
core.get<sol::table>("entities")[ref->id] = luaEntity;
|
||||
ref.set_display_type(*displayType, *displayObject, displayTexture);
|
||||
core.get<sol::table>("entities")[entity->getId()] = luaEntity;
|
||||
|
||||
auto on_create = def.get<sol::optional<sol::protected_function>>("on_create");
|
||||
if (on_create) (*on_create)(luaEntity, staticData);
|
||||
|
@ -105,13 +105,14 @@ sol::table Api::Usertype::Dimension::add_entity_s(sol::this_state s, glm::vec3 p
|
|||
if (strncmp(displayType->data(), "model", 5) == 0 && !displayTexture) throw std::runtime_error("entity '" + identifier + "' is missing the display_texture property.");
|
||||
|
||||
unsigned int ind = dim->nextEntityInd();
|
||||
auto entity = std::make_unique<ServerEntity>(ind);
|
||||
auto entity = std::make_shared<ServerLuaEntity>(dim->getGame(), dim, ind);
|
||||
entity->setPos(pos);
|
||||
auto ref = std::make_shared<ServerLuaEntity>(std::move(entity), ind, dim->getGame());
|
||||
entity->setId(ind);
|
||||
Entity ref(entity);
|
||||
|
||||
luaEntity["object"] = ref;
|
||||
ref->set_display_type(*displayType, *displayObject, displayTexture);
|
||||
core.get<sol::table>("entities")[ref->id] = luaEntity;
|
||||
ref.set_display_type(*displayType, *displayObject, displayTexture);
|
||||
core.get<sol::table>("entities")[entity->getId()] = luaEntity;
|
||||
|
||||
auto on_create = def.get<sol::optional<sol::protected_function>>("on_create");
|
||||
if (on_create) (*on_create)(luaEntity, staticData);
|
||||
|
@ -124,16 +125,16 @@ void Api::Usertype::Dimension::remove_entity_c(sol::this_state s, sol::table ent
|
|||
sol::state_view lua = sol::state_view(s);
|
||||
sol::table core = lua.get<sol::table>("zepha");
|
||||
|
||||
auto object = entity.get<sol::optional<std::shared_ptr<LocalLuaEntity>>>("object");
|
||||
auto object = entity.get<sol::optional<Entity>>("object");
|
||||
if (!object) throw std::runtime_error("Attempting to remove an invalid entity.");
|
||||
|
||||
sol::optional<sol::table> entityTable = core["entities"][(*object)->id];
|
||||
sol::optional<sol::table> entityTable = core["entities"][object->get_id()];
|
||||
if (!entityTable) return;
|
||||
|
||||
sol::optional<sol::protected_function> onDestroy = (*entityTable)["on_destroy"];
|
||||
if (onDestroy) (*onDestroy)();
|
||||
|
||||
core["entities"][(*object)->id] = sol::nil;
|
||||
core["entities"][object->get_id()] = sol::nil;
|
||||
dim.l()->removeLocalEntity(*object);
|
||||
}
|
||||
|
||||
|
@ -141,16 +142,16 @@ void Api::Usertype::Dimension::remove_entity_s(sol::this_state s, sol::table ent
|
|||
sol::state_view lua = sol::state_view(s);
|
||||
sol::table core = lua.get<sol::table>("zepha");
|
||||
|
||||
auto object = entity.get<sol::optional<std::shared_ptr<ServerLuaEntity>>>("object");
|
||||
auto object = entity.get<sol::optional<Entity>>("object");
|
||||
if (!object) throw std::runtime_error("Attempting to rmeove an invalid entity.");
|
||||
|
||||
sol::optional<sol::table> entityTable = core["entities"][(*object)->id];
|
||||
sol::optional<sol::table> entityTable = core["entities"][object->get_id()];
|
||||
if (!entityTable) return;
|
||||
|
||||
sol::optional<sol::protected_function> onDestroy = (*entityTable)["on_destroy"];
|
||||
if (onDestroy) (*onDestroy)();
|
||||
|
||||
core["entities"][(*object)->id] = sol::nil;
|
||||
core["entities"][object->get_id()] = sol::nil;
|
||||
dim.s()->removeLuaEntity(*object);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-04.
|
||||
//
|
||||
|
||||
#include "Entity.h"
|
||||
|
||||
#include "../../world/Dimension.h"
|
||||
#include "../../def/LocalSubgame.h"
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../def/DefinitionAtlas.h"
|
||||
#include "../../def/item/CraftItemDef.h"
|
||||
#include "../../game/scene/world/World.h"
|
||||
#include "../../net/server/world/ServerLuaEntity.h"
|
||||
|
||||
unsigned int Api::Usertype::Entity::get_id() {
|
||||
return entity->getId();
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::snap_pos(glm::vec3 pos) {
|
||||
entity->setPos(pos);
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_pos(glm::vec3 pos) {
|
||||
entity->setPos(pos);
|
||||
}
|
||||
|
||||
glm::vec3 Api::Usertype::Entity::get_pos() {
|
||||
return entity->getPos();
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::snap_visual_offset(glm::vec3 vs) {
|
||||
entity->setVisualOffset(vs);
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_visual_offset(glm::vec3 vs) {
|
||||
entity->setVisualOffset(vs);
|
||||
}
|
||||
|
||||
glm::vec3 Api::Usertype::Entity::get_visual_offset() {
|
||||
return entity->getVisualOffset();
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::snap_pitch(float rot) {
|
||||
entity->setRotateX(rot);
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_pitch(float rot) {
|
||||
entity->setRotateX(rot);
|
||||
}
|
||||
|
||||
float Api::Usertype::Entity::get_pitch() {
|
||||
return entity->getRotateX();
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::snap_yaw(float rot) {
|
||||
entity->setRotateY(rot);
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_yaw(float rot) {
|
||||
entity->setRotateY(rot);
|
||||
}
|
||||
|
||||
float Api::Usertype::Entity::get_yaw() {
|
||||
return entity->getRotateY();
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::snap_roll(float rot) {
|
||||
entity->setRotateZ(rot);
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_roll(float rot) {
|
||||
entity->setRotateZ(rot);
|
||||
}
|
||||
|
||||
float Api::Usertype::Entity::get_roll() {
|
||||
return entity->getRotateZ();
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::snap_scale(float scale) {
|
||||
entity->setScale(scale);
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_scale(float scale) {
|
||||
entity->setScale(scale);
|
||||
}
|
||||
|
||||
float Api::Usertype::Entity::get_scale() {
|
||||
return entity->getScale().x;
|
||||
}
|
||||
|
||||
Api::Usertype::Dimension Api::Usertype::Entity::get_dimension() {
|
||||
return Dimension(entity->getDim());
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_dimension(const std::string& identifier) {
|
||||
entity->setDim(entity->getDim()->getWorld().getDimension(identifier));
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::set_display_type(const std::string &type, const std::string &arg, sol::optional<std::string> arg2) {
|
||||
if (strncmp(type.data(), "gameobject", 10) == 0) {
|
||||
ItemDef& def = entity->getGame()->getDefs().fromStr(arg);
|
||||
if (def.type == ItemDef::Type::BLOCK) entity->setAppearance("gameobject", "block", arg);
|
||||
else if (def.type == ItemDef::Type::CRAFTITEM) entity->setAppearance("gameobject", "craftitem", arg);
|
||||
}
|
||||
else if (strncmp(type.data(), "model", 5) == 0 && arg2 && !arg2->empty()) {
|
||||
entity->setAppearance("model", arg, *arg2);
|
||||
}
|
||||
else throw std::runtime_error("Invalid display type parameters.");
|
||||
}
|
||||
|
||||
void Api::Usertype::Entity::bind(State, sol::state &lua, sol::table &core) {
|
||||
lua.new_usertype<Entity>("Entity",
|
||||
"get_id", &Entity::get_id,
|
||||
"snap_pos", &Entity::snap_pos,
|
||||
"set_pos", &Entity::set_pos,
|
||||
"get_pos", &Entity::get_pos,
|
||||
"snap_visual_offset", &Entity::snap_visual_offset,
|
||||
"set_visual_offset", &Entity::set_visual_offset,
|
||||
"get_visual_offset", &Entity::get_visual_offset,
|
||||
"snap_pitch", &Entity::snap_pitch,
|
||||
"set_pitch", &Entity::set_pitch,
|
||||
"get_pitch", &Entity::get_pitch,
|
||||
"snap_yaw", &Entity::snap_yaw,
|
||||
"set_yaw", &Entity::set_yaw,
|
||||
"get_yaw", &Entity::get_yaw,
|
||||
"snap_roll", &Entity::snap_roll,
|
||||
"set_roll", &Entity::set_roll,
|
||||
"get_roll", &Entity::get_roll,
|
||||
"snap_scale", &Entity::snap_scale,
|
||||
"set_scale", &Entity::set_scale,
|
||||
"get_scale", &Entity::get_scale,
|
||||
|
||||
"set_display_type", &Entity::set_display_type,
|
||||
|
||||
"id", sol::property(&Entity::get_id),
|
||||
"pos", sol::property(&Entity::get_pos, &Entity::set_pos),
|
||||
"visual_offset", sol::property(&Entity::get_visual_offset, &Entity::set_visual_offset),
|
||||
"pitch", sol::property(&Entity::get_pitch, &Entity::set_pitch),
|
||||
"yaw", sol::property(&Entity::get_yaw, &Entity::set_yaw),
|
||||
"roll", sol::property(&Entity::get_roll, &Entity::set_roll),
|
||||
"scale", sol::property(&Entity::get_scale, &Entity::set_scale),
|
||||
"dim", sol::property(&Entity::get_dimension)
|
||||
|
||||
// "anims", sol::readonly(&Entity::manager)
|
||||
);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// Created by aurailus on 2020-08-04.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "SubgameUsertype.h"
|
||||
|
||||
#include "Dimension.h"
|
||||
#include "../../util/CovariantPtr.h"
|
||||
|
||||
namespace Api::Usertype {
|
||||
class Entity : public SubgameUsertype {
|
||||
public:
|
||||
Entity(EntityPtr entity) : entity(entity) {}
|
||||
|
||||
EntityPtr entity;
|
||||
|
||||
// LocalLuaAnimationManager manager;
|
||||
|
||||
unsigned int get_id();
|
||||
|
||||
void snap_pos(glm::vec3 pos);
|
||||
void set_pos(glm::vec3 pos);
|
||||
glm::vec3 get_pos();
|
||||
|
||||
void snap_visual_offset(glm::vec3 vs);
|
||||
void set_visual_offset(glm::vec3 vs);
|
||||
glm::vec3 get_visual_offset();
|
||||
|
||||
void snap_pitch(float rot);
|
||||
void set_pitch(float rot);
|
||||
float get_pitch();
|
||||
|
||||
void snap_yaw(float rot);
|
||||
void set_yaw(float rot);
|
||||
float get_yaw();
|
||||
|
||||
void snap_roll(float rot);
|
||||
void set_roll(float rot);
|
||||
float get_roll();
|
||||
|
||||
void snap_scale(float scale);
|
||||
void set_scale(float scale);
|
||||
float get_scale();
|
||||
|
||||
Dimension get_dimension();
|
||||
void set_dimension(const std::string& identifier);
|
||||
|
||||
void set_display_type(const std::string& type, const std::string& arg, sol::optional<std::string> arg2);
|
||||
|
||||
static void bind(State state, sol::state& lua, sol::table& core);
|
||||
};
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 03/10/19.
|
||||
//
|
||||
|
||||
#include "LocalLuaEntity.h"
|
||||
|
||||
#include "../Lua.h"
|
||||
#include "../LuaParser.h"
|
||||
#include "../../def/LocalSubgame.h"
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../def/item/CraftItemDef.h"
|
||||
#include "../../def/LocalDefinitionAtlas.h"
|
||||
|
||||
void LocalLuaEntity::snap_pos(glm::vec3 pos) {
|
||||
entity->setPos(pos);
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_pos(glm::vec3 pos) {
|
||||
entity->interpPos(pos);
|
||||
}
|
||||
|
||||
glm::vec3 LocalLuaEntity::get_pos() {
|
||||
return entity->getPos();
|
||||
}
|
||||
|
||||
void LocalLuaEntity::snap_visual_offset(glm::vec3 vs) {
|
||||
entity->setVisualOffset(vs);
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_visual_offset(glm::vec3 vs) {
|
||||
entity->interpVisualOffset(vs);
|
||||
}
|
||||
|
||||
glm::vec3 LocalLuaEntity::get_visual_offset() {
|
||||
return entity->getVisualOffset();
|
||||
}
|
||||
|
||||
void LocalLuaEntity::snap_pitch(float rot) {
|
||||
entity->setRotateX(rot);
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_pitch(float rot) {
|
||||
entity->interpRotateX(rot);
|
||||
}
|
||||
|
||||
float LocalLuaEntity::get_pitch() {
|
||||
return entity->getRotateX();
|
||||
}
|
||||
|
||||
void LocalLuaEntity::snap_yaw(float rot) {
|
||||
entity->setRotateY(rot);
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_yaw(float rot) {
|
||||
entity->interpRotateY(rot);
|
||||
}
|
||||
|
||||
float LocalLuaEntity::get_yaw() {
|
||||
return entity->getRotateY();
|
||||
}
|
||||
|
||||
void LocalLuaEntity::snap_roll(float rot) {
|
||||
entity->setRotateZ(rot);
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_roll(float rot) {
|
||||
entity->interpRotateZ(rot);
|
||||
}
|
||||
|
||||
float LocalLuaEntity::get_roll() {
|
||||
return entity->getRotateZ();
|
||||
}
|
||||
|
||||
void LocalLuaEntity::snap_scale(float scale) {
|
||||
entity->setScale(scale);
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_scale(float scale) {
|
||||
entity->interpScale(scale);
|
||||
}
|
||||
|
||||
float LocalLuaEntity::get_scale() {
|
||||
return entity->getScale().x;
|
||||
}
|
||||
|
||||
void LocalLuaEntity::set_display_type(const std::string &type, const std::string &arg, sol::optional<std::string> arg2) {
|
||||
if (strncmp(type.data(), "gameobject", 10) == 0) {
|
||||
ItemDef& def = game->getDefs().fromStr(arg);
|
||||
|
||||
if (def.type == ItemDef::Type::BLOCK)
|
||||
entity->setModel(static_cast<BlockDef&>(def).entityModel);
|
||||
else if (def.type == ItemDef::Type::CRAFTITEM)
|
||||
entity->setModel(static_cast<CraftItemDef&>(def).entityModel);
|
||||
}
|
||||
else if (strncmp(type.data(), "model", 5) == 0 && arg2 && !arg2->empty()) {
|
||||
auto model = std::make_shared<Model>();
|
||||
model->fromSerialized(game.l()->models.models[arg], {game.l()->textures[*arg2]});
|
||||
entity->setModel(model);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 03/10/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Lua.h"
|
||||
#include "../../util/CovariantPtr.h"
|
||||
#include "LocalLuaAnimationManager.h"
|
||||
#include "../../game/entity/DrawableEntity.h"
|
||||
|
||||
class LocalSubgame;
|
||||
|
||||
class LocalLuaEntity {
|
||||
public:
|
||||
LocalLuaEntity(std::unique_ptr<DrawableEntity> entity, unsigned int id, SubgamePtr game) :
|
||||
entity(std::move(entity)), id(id), game(game), manager(*this->entity) {}
|
||||
|
||||
std::unique_ptr<DrawableEntity> entity = nullptr;
|
||||
unsigned int id;
|
||||
SubgamePtr game;
|
||||
|
||||
LocalLuaAnimationManager manager;
|
||||
|
||||
void snap_pos(glm::vec3 pos);
|
||||
void set_pos(glm::vec3 pos);
|
||||
glm::vec3 get_pos();
|
||||
|
||||
void snap_visual_offset(glm::vec3 vs);
|
||||
void set_visual_offset(glm::vec3 vs);
|
||||
glm::vec3 get_visual_offset();
|
||||
|
||||
void snap_pitch(float rot);
|
||||
void set_pitch(float rot);
|
||||
float get_pitch();
|
||||
|
||||
void snap_yaw(float rot);
|
||||
void set_yaw(float rot);
|
||||
float get_yaw();
|
||||
|
||||
void snap_roll(float rot);
|
||||
void set_roll(float rot);
|
||||
float get_roll();
|
||||
|
||||
void snap_scale(float scale);
|
||||
void set_scale(float scale);
|
||||
float get_scale();
|
||||
|
||||
void set_display_type(const std::string& type, const std::string& arg, sol::optional<std::string> arg2);
|
||||
};
|
|
@ -57,11 +57,11 @@ Api::Usertype::Inventory Api::Usertype::ServerPlayer::get_inventory() {
|
|||
}
|
||||
|
||||
Api::Usertype::Dimension Api::Usertype::ServerPlayer::get_dimension() {
|
||||
return Dimension(player->getDimension());
|
||||
return Dimension(player->getDim());
|
||||
}
|
||||
|
||||
void Api::Usertype::ServerPlayer::set_dimension(const std::string& identifier) {
|
||||
player->setDimension(player->getDimension()->getWorld().getDimension(identifier));
|
||||
player->setDim(player->getDim()->getWorld().getDimension(identifier));
|
||||
}
|
||||
|
||||
sol::object Api::Usertype::ServerPlayer::get_hand_list(sol::this_state s) {
|
||||
|
@ -145,6 +145,7 @@ void Api::Usertype::ServerPlayer::bind(State, sol::state &lua, sol::table &core)
|
|||
"get_dimension", &ServerPlayer::get_dimension,
|
||||
"set_dimension", &ServerPlayer::set_dimension,
|
||||
|
||||
"id", sol::property(&ServerPlayer::get_id),
|
||||
"pos", sol::property(&ServerPlayer::get_pos, &ServerPlayer::set_pos),
|
||||
"block_pos", sol::property(&ServerPlayer::get_block_pos, &ServerPlayer::set_pos),
|
||||
"vel", sol::property(&ServerPlayer::get_vel, &ServerPlayer::set_vel),
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-07.
|
||||
//
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ServerLocalLuaEntity.h"
|
||||
|
||||
#include "../../def/ItemDef.h"
|
||||
#include "../../def/LocalSubgame.h"
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../def/item/CraftItemDef.h"
|
||||
#include "../../def/LocalDefinitionAtlas.h"
|
||||
|
||||
ServerLocalLuaEntity::ServerLocalLuaEntity(unsigned int id, SubgamePtr game, const std::string &appearance,
|
||||
const std::string &arg1, const std::string &arg2) :
|
||||
id(id),
|
||||
game(game) {
|
||||
|
||||
setDisplayType(appearance, arg1, arg2);
|
||||
}
|
||||
|
||||
void ServerLocalLuaEntity::setDisplayType(const std::string &type, const std::string &arg, const std::string &arg2) {
|
||||
if (strncmp(type.data(), "gameobject", 10) == 0 &&
|
||||
(strncmp(displayType.data(), "gameobject", 10) || arg2 != displayArg2)) {
|
||||
|
||||
ItemDef& def = game->getDefs().fromStr(arg2);
|
||||
|
||||
if (def.type == ItemDef::Type::BLOCK)
|
||||
entity->setModel(static_cast<BlockDef&>(def).entityModel);
|
||||
else if (def.type == ItemDef::Type::CRAFTITEM)
|
||||
entity->setModel(static_cast<CraftItemDef&>(def).entityModel);
|
||||
}
|
||||
else if (strncmp(type.data(), "model", 5) == 0 && !arg2.empty() &&
|
||||
(strncmp(displayType.data(), "model", 5) || arg != displayArg1 || arg != displayArg2)) {
|
||||
auto model = std::make_shared<Model>();
|
||||
model->fromSerialized(game.l()->models.models[arg], {game.l()->textures[arg2]});
|
||||
entity->setModel(model);
|
||||
}
|
||||
else return;
|
||||
|
||||
displayType = type;
|
||||
displayArg1 = arg;
|
||||
displayArg2 = arg2;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-07.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../../util/CovariantPtr.h"
|
||||
#include "../../game/entity/DrawableEntity.h"
|
||||
|
||||
class LocalSubgame;
|
||||
|
||||
class ServerLocalLuaEntity {
|
||||
public:
|
||||
ServerLocalLuaEntity(unsigned int id, SubgamePtr game, 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);
|
||||
|
||||
SubgamePtr game;
|
||||
std::unique_ptr<DrawableEntity> entity = std::make_unique<DrawableEntity>();
|
||||
unsigned int id;
|
||||
|
||||
std::string displayType {};
|
||||
std::string displayArg1 {};
|
||||
std::string displayArg2 {};
|
||||
};
|
|
@ -1,97 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-12-28.
|
||||
//
|
||||
|
||||
#include "ServerLuaEntity.h"
|
||||
|
||||
#include "../LuaParser.h"
|
||||
#include "../../def/ItemDef.h"
|
||||
#include "../../def/ServerSubgame.h"
|
||||
#include "../../def/ServerDefinitionAtlas.h"
|
||||
|
||||
void ServerLuaEntity::snap_pos(glm::vec3 pos) {
|
||||
entity->setPos(pos);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_pos(glm::vec3 pos) {
|
||||
entity->setPos(pos);
|
||||
}
|
||||
|
||||
glm::vec3 ServerLuaEntity::get_pos() {
|
||||
return entity->getPos();
|
||||
}
|
||||
|
||||
void ServerLuaEntity::snap_visual_offset(glm::vec3 vs) {
|
||||
entity->setVisualOffset(vs);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_visual_offset(glm::vec3 vs) {
|
||||
entity->setVisualOffset(vs);
|
||||
}
|
||||
|
||||
glm::vec3 ServerLuaEntity::get_visual_offset() {
|
||||
return entity->getVisualOffset();
|
||||
}
|
||||
|
||||
void ServerLuaEntity::snap_pitch(float rot) {
|
||||
entity->setRotateX(rot);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_pitch(float rot) {
|
||||
entity->setRotateX(rot);
|
||||
}
|
||||
|
||||
float ServerLuaEntity::get_pitch() {
|
||||
return entity->getRotateX();
|
||||
}
|
||||
|
||||
void ServerLuaEntity::snap_yaw(float rot) {
|
||||
entity->setRotateY(rot);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_yaw(float rot) {
|
||||
entity->setRotateY(rot);
|
||||
}
|
||||
|
||||
float ServerLuaEntity::get_yaw() {
|
||||
return entity->getRotateY();
|
||||
}
|
||||
|
||||
void ServerLuaEntity::snap_roll(float rot) {
|
||||
entity->setRotateZ(rot);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_roll(float rot) {
|
||||
entity->setRotateZ(rot);
|
||||
}
|
||||
|
||||
float ServerLuaEntity::get_roll() {
|
||||
return entity->getRotateZ();
|
||||
}
|
||||
|
||||
void ServerLuaEntity::snap_scale(float scale) {
|
||||
entity->setScale(scale);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_scale(float scale) {
|
||||
entity->setScale(scale);
|
||||
}
|
||||
|
||||
float ServerLuaEntity::get_scale() {
|
||||
return entity->getScale();
|
||||
}
|
||||
|
||||
void ServerLuaEntity::set_display_type(const std::string &type, const std::string &arg, sol::optional<std::string> arg2) {
|
||||
if (strncmp(type.data(), "gameobject", 10) == 0) {
|
||||
ItemDef& def = game->getDefs().fromStr(arg);
|
||||
// if (def.index == 0) throw "Invalid gameobject to display";
|
||||
|
||||
if (def.type == ItemDef::Type::BLOCK)
|
||||
entity->setAppearance("gameobject", "block", arg);
|
||||
else if (def.type == ItemDef::Type::CRAFTITEM)
|
||||
entity->setAppearance("gameobject", "craftitem", arg);
|
||||
}
|
||||
else if (strncmp(type.data(), "model", 5) == 0 && arg2 && !arg2->empty()) {
|
||||
entity->setAppearance("model", arg, *arg2);
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-12-28.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Lua.h"
|
||||
#include "../../util/CovariantPtr.h"
|
||||
#include "../../net/server/world/ServerEntity.h"
|
||||
|
||||
class ServerSubgame;
|
||||
|
||||
class ServerLuaEntity {
|
||||
public:
|
||||
ServerLuaEntity(std::unique_ptr<ServerEntity> entity, unsigned int id, SubgamePtr game) :
|
||||
entity(std::move(entity)), id(id), game(game) {}
|
||||
|
||||
std::unique_ptr<ServerEntity> entity = nullptr;
|
||||
unsigned int id;
|
||||
SubgamePtr game;
|
||||
|
||||
void snap_pos(glm::vec3 pos);
|
||||
void set_pos(glm::vec3 pos);
|
||||
glm::vec3 get_pos();
|
||||
|
||||
void snap_visual_offset(glm::vec3 vs);
|
||||
void set_visual_offset(glm::vec3 vs);
|
||||
glm::vec3 get_visual_offset();
|
||||
|
||||
void snap_pitch(float rot);
|
||||
void set_pitch(float rot);
|
||||
float get_pitch();
|
||||
|
||||
void snap_yaw(float rot);
|
||||
void set_yaw(float rot);
|
||||
float get_yaw();
|
||||
|
||||
void snap_roll(float rot);
|
||||
void set_roll(float rot);
|
||||
float get_roll();
|
||||
|
||||
void snap_scale(float scale);
|
||||
void set_scale(float scale);
|
||||
float get_scale();
|
||||
|
||||
void set_display_type(const std::string& type, const std::string& arg, sol::optional<std::string> arg2);
|
||||
};
|
|
@ -1,47 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 30/08/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Lua.h"
|
||||
#include "LocalLuaEntity.h"
|
||||
#include "../../game/scene/world/LocalWorld.h"
|
||||
|
||||
namespace ClientApi {
|
||||
void entity(sol::state& lua) {
|
||||
lua.new_usertype<LocalLuaEntity>("LuaEntity",
|
||||
"id", sol::readonly(&LocalLuaEntity::id),
|
||||
|
||||
"snap_pos", &LocalLuaEntity::snap_pos,
|
||||
"set_pos", &LocalLuaEntity::set_pos,
|
||||
"get_pos", &LocalLuaEntity::get_pos,
|
||||
"snap_visual_offset", &LocalLuaEntity::snap_visual_offset,
|
||||
"set_visual_offset", &LocalLuaEntity::set_visual_offset,
|
||||
"get_visual_offset", &LocalLuaEntity::get_visual_offset,
|
||||
"snap_pitch", &LocalLuaEntity::snap_pitch,
|
||||
"set_pitch", &LocalLuaEntity::set_pitch,
|
||||
"get_pitch", &LocalLuaEntity::get_pitch,
|
||||
"snap_yaw", &LocalLuaEntity::snap_yaw,
|
||||
"set_yaw", &LocalLuaEntity::set_yaw,
|
||||
"get_yaw", &LocalLuaEntity::get_yaw,
|
||||
"snap_roll", &LocalLuaEntity::snap_roll,
|
||||
"set_roll", &LocalLuaEntity::set_roll,
|
||||
"get_roll", &LocalLuaEntity::get_roll,
|
||||
"snap_scale", &LocalLuaEntity::snap_scale,
|
||||
"set_scale", &LocalLuaEntity::set_scale,
|
||||
"get_scale", &LocalLuaEntity::get_scale,
|
||||
|
||||
"set_display_type", &LocalLuaEntity::set_display_type,
|
||||
|
||||
"pos", sol::property(&LocalLuaEntity::get_pos, &LocalLuaEntity::set_pos),
|
||||
"visual_offset", sol::property(&LocalLuaEntity::get_visual_offset, &LocalLuaEntity::set_visual_offset),
|
||||
"pitch", sol::property(&LocalLuaEntity::get_pitch, &LocalLuaEntity::set_pitch),
|
||||
"yaw", sol::property(&LocalLuaEntity::get_yaw, &LocalLuaEntity::set_yaw),
|
||||
"roll", sol::property(&LocalLuaEntity::get_roll, &LocalLuaEntity::set_roll),
|
||||
"scale", sol::property(&LocalLuaEntity::get_scale, &LocalLuaEntity::set_scale),
|
||||
|
||||
"anims", sol::readonly(&LocalLuaEntity::manager)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2020-01-05.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Lua.h"
|
||||
#include "ServerLuaEntity.h"
|
||||
|
||||
namespace ServerApi {
|
||||
void entity(sol::state& lua) {
|
||||
lua.new_usertype<ServerLuaEntity>("LuaEntity",
|
||||
"id", sol::readonly(&ServerLuaEntity::id),
|
||||
|
||||
"snap_pos", &ServerLuaEntity::snap_pos,
|
||||
"set_pos", &ServerLuaEntity::set_pos,
|
||||
"get_pos", &ServerLuaEntity::get_pos,
|
||||
"snap_visual_offset", &ServerLuaEntity::snap_visual_offset,
|
||||
"set_visual_offset", &ServerLuaEntity::set_visual_offset,
|
||||
"get_visual_offset", &ServerLuaEntity::get_visual_offset,
|
||||
"snap_pitch", &ServerLuaEntity::snap_pitch,
|
||||
"set_pitch", &ServerLuaEntity::set_pitch,
|
||||
"get_pitch", &ServerLuaEntity::get_pitch,
|
||||
"snap_yaw", &ServerLuaEntity::snap_yaw,
|
||||
"set_yaw", &ServerLuaEntity::set_yaw,
|
||||
"get_yaw", &ServerLuaEntity::get_yaw,
|
||||
"snap_roll", &ServerLuaEntity::snap_roll,
|
||||
"set_roll", &ServerLuaEntity::set_roll,
|
||||
"get_roll", &ServerLuaEntity::get_roll,
|
||||
"snap_scale", &ServerLuaEntity::snap_scale,
|
||||
"set_scale", &ServerLuaEntity::set_scale,
|
||||
"get_scale", &ServerLuaEntity::get_scale,
|
||||
|
||||
"pos", sol::property(&ServerLuaEntity::get_pos, &ServerLuaEntity::set_pos),
|
||||
"visual_offset", sol::property(&ServerLuaEntity::get_visual_offset, &ServerLuaEntity::set_visual_offset),
|
||||
"pitch", sol::property(&ServerLuaEntity::get_pitch, &ServerLuaEntity::set_pitch),
|
||||
"yaw", sol::property(&ServerLuaEntity::get_yaw, &ServerLuaEntity::set_yaw),
|
||||
"roll", sol::property(&ServerLuaEntity::get_roll, &ServerLuaEntity::set_roll),
|
||||
"scale", sol::property(&ServerLuaEntity::get_scale, &ServerLuaEntity::set_scale),
|
||||
|
||||
"set_display_type", &ServerLuaEntity::set_display_type
|
||||
);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public:
|
|||
// World
|
||||
CHUNK, MAPBLOCK,
|
||||
// Block
|
||||
BLOCK_PLACE, BLOCK_INTERACT,
|
||||
BLOCK_HIT, BLOCK_PLACE, BLOCK_INTERACT,
|
||||
BLOCK_PLACE_OR_INTERACT, BLOCK_SET,
|
||||
// Entity
|
||||
ENTITY_INFO, ENTITY_REMOVED,
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "../Serializer.h"
|
||||
#include "../NetHandler.h"
|
||||
#include "../../util/Log.h"
|
||||
#include "../../game/scene/world/NetField.h"
|
||||
#include "../../game/scene/world/LocalWorld.h"
|
||||
#include "../../game/scene/world/LocalPlayer.h"
|
||||
|
||||
|
@ -50,10 +51,10 @@ void ClientNetworkInterpreter::update() {
|
|||
|
||||
auto player = world.getPlayer();
|
||||
if (player) Serializer()
|
||||
.appendE(Player::NetField::POS).append(player->getPos())
|
||||
.appendE(Player::NetField::VEL).append(player->getVel())
|
||||
.appendE(Player::NetField::PITCH).append(player->getPitch())
|
||||
.appendE(Player::NetField::YAW).append(player->getYaw())
|
||||
.appendE(NetField::POS).append(player->getPos())
|
||||
.appendE(NetField::VEL).append(player->getVel())
|
||||
.appendE(NetField::LOOK_PITCH).append(player->getPitch())
|
||||
.appendE(NetField::LOOK_YAW).append(player->getYaw())
|
||||
.packet(Packet::Type::THIS_PLAYER_INFO, false).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
|
||||
}
|
||||
|
||||
|
@ -83,10 +84,10 @@ void ClientNetworkInterpreter::receivedPacket(std::unique_ptr<PacketView> p) {
|
|||
break; }
|
||||
|
||||
case Packet::Type::ENTITY_INFO:
|
||||
world.getActiveDimension().l()->serverEntityInfo(*p); break;
|
||||
world.getActiveDimension().l()->serverEntitiesInfo(p->d); break;
|
||||
|
||||
case Packet::Type::ENTITY_REMOVED:
|
||||
world.getActiveDimension().l()->serverEntityRemoved(p->d.read<unsigned int>()); break;
|
||||
world.getActiveDimension().l()->serverEntitiesRemoved(p->d); break;
|
||||
|
||||
case Packet::Type::INV_DATA:
|
||||
onInvPacket(std::move(p)); break;
|
||||
|
@ -99,6 +100,11 @@ void ClientNetworkInterpreter::receivedPacket(std::unique_ptr<PacketView> p) {
|
|||
}
|
||||
}
|
||||
|
||||
void ClientNetworkInterpreter::blockHit(const Target &target) {
|
||||
Serializer().append<glm::ivec3>(target.pos).append(static_cast<unsigned short>(target.face))
|
||||
.packet(Packet::Type::BLOCK_HIT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
|
||||
}
|
||||
|
||||
void ClientNetworkInterpreter::blockPlace(const Target &target) {
|
||||
Serializer().append<glm::ivec3>(target.pos).append(static_cast<unsigned short>(target.face))
|
||||
.packet(Packet::Type::BLOCK_PLACE).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
void init(std::function<void(std::unique_ptr<PacketView>)> invCallback);
|
||||
void update();
|
||||
|
||||
void blockHit(const Target& target);
|
||||
void blockPlace(const Target& target);
|
||||
void blockInteract(const Target& target);
|
||||
void blockPlaceOrInteract(const Target& target);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "conn/ServerPlayer.h"
|
||||
#include "../../world/Target.h"
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../game/scene/world/NetField.h"
|
||||
|
||||
Server::Server(unsigned short port, const std::string& subgame) :
|
||||
seed(69),
|
||||
|
@ -61,10 +62,10 @@ void Server::update() {
|
|||
if (!player) continue;
|
||||
|
||||
Packet p = Serializer()
|
||||
.appendE(Player::NetField::ID).append(player->getId())
|
||||
.appendE(Player::NetField::POS).append(player->getPos())
|
||||
.appendE(Player::NetField::PITCH).append(player->getPitch())
|
||||
.appendE(Player::NetField::YAW).append(player->getYaw())
|
||||
.appendE(NetField::ID).append(player->getId())
|
||||
.appendE(NetField::POS).append(player->getPos())
|
||||
.appendE(NetField::LOOK_YAW).append(player->getYaw())
|
||||
.appendE(NetField::LOOK_PITCH).append(player->getPitch())
|
||||
.packet(Packet::Type::PLAYER_ENT_INFO, false);
|
||||
|
||||
for (auto& iter : clients.players)
|
||||
|
@ -144,17 +145,21 @@ void Server::playerPacketReceived(PacketView& p, PlayerPtr player) {
|
|||
// }
|
||||
// break; }
|
||||
|
||||
case Packet::Type::BLOCK_HIT:
|
||||
p.d.read(pos).readE(face);
|
||||
player->getDim()->blockHit(Target(player->getDim(), pos, face), player); break;
|
||||
|
||||
case Packet::Type::BLOCK_PLACE:
|
||||
p.d.read(pos).readE(face);
|
||||
player->getDimension()->blockPlace(Target(player->getDimension(), pos, face), player); break;
|
||||
player->getDim()->blockPlace(Target(player->getDim(), pos, face), player); break;
|
||||
|
||||
case Packet::Type::BLOCK_INTERACT:
|
||||
p.d.read(pos).readE(face);
|
||||
player->getDimension()->blockInteract(Target(player->getDimension(), pos, face), player); break;
|
||||
player->getDim()->blockInteract(Target(player->getDim(), pos, face), player); break;
|
||||
|
||||
case Packet::Type::BLOCK_PLACE_OR_INTERACT:
|
||||
p.d.read(pos).readE(face);
|
||||
player->getDimension()->blockPlaceOrInteract(Target(player->getDimension(), pos, face), player); break;
|
||||
player->getDim()->blockPlaceOrInteract(Target(player->getDim(), pos, face), player); break;
|
||||
|
||||
case Packet::Type::INV_WATCH:
|
||||
p.d.read<std::string>(source).read<std::string>(list);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "../../Serializer.h"
|
||||
#include "../../NetHandler.h"
|
||||
#include "../../../util/Log.h"
|
||||
#include "../../../game/scene/world/NetField.h"
|
||||
|
||||
ServerClients::ServerClients(SubgamePtr game) :
|
||||
game(game) {}
|
||||
|
@ -58,10 +59,10 @@ void ServerClients::createPlayer(std::shared_ptr<ServerClient> client, Dimension
|
|||
player->setPos({0, -37, 0}, true);
|
||||
|
||||
Serializer()
|
||||
.appendE(Player::NetField::ID).append(player->getId())
|
||||
.appendE(Player::NetField::POS).append(player->getPos())
|
||||
.appendE(Player::NetField::PITCH).append(player->getPitch())
|
||||
.appendE(Player::NetField::YAW).append(player->getYaw())
|
||||
.appendE(NetField::ID).append(player->getId())
|
||||
.appendE(NetField::POS).append(player->getPos())
|
||||
.appendE(NetField::LOOK_PITCH).append(player->getPitch())
|
||||
.appendE(NetField::LOOK_YAW).append(player->getYaw())
|
||||
.packet(Packet::Type::THIS_PLAYER_INFO).sendTo(player->getPeer(), Packet::Channel::INTERACT);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
#include "../../Serializer.h"
|
||||
#include "../../Deserializer.h"
|
||||
#include "../world/ServerWorld.h"
|
||||
#include "../../../game/scene/world/NetField.h"
|
||||
#include "../../../game/inventory/ServerInventoryRefs.h"
|
||||
|
||||
ServerPlayer::ServerPlayer(ServerClient& client, World& world, SubgamePtr game, DimensionPtr dim) :
|
||||
Player(game, world, dim, client.id), client(client),
|
||||
Player(game, world, dim, client.id), Entity(game, dim), client(client),
|
||||
inventory(world.getRefs()->createInventory("player:" + std::to_string(id))) {}
|
||||
|
||||
void ServerPlayer::assertField(Packet packet) {
|
||||
|
@ -22,14 +23,14 @@ void ServerPlayer::assertField(Packet packet) {
|
|||
void ServerPlayer::handleAssertion(Deserializer &d) {
|
||||
while (!d.atEnd()) {
|
||||
switch (d.readE<NetField>()) {
|
||||
case NetField::POS: setPos(d.read<glm::vec3>()); break;
|
||||
case NetField::VEL: setVel(d.read<glm::vec3>()); break;
|
||||
case NetField::PITCH: setPitch(d.read<float>()); break;
|
||||
case NetField::YAW: setYaw(d.read<float>()); break;
|
||||
case NetField::FLYING: setFlying(d.read<bool>()); break;
|
||||
case NetField::POS: setPos(d.read<glm::vec3>()); break;
|
||||
case NetField::VEL: setVel(d.read<glm::vec3>()); break;
|
||||
case NetField::LOOK_YAW: setPitch(d.read<float>()); break;
|
||||
case NetField::LOOK_PITCH: setYaw(d.read<float>()); break;
|
||||
case NetField::FLYING: setFlying(d.read<bool>()); break;
|
||||
|
||||
case NetField::HAND_INV: setHandList(d.read<std::string>()); break;
|
||||
case NetField::WIELD_INV: setWieldList(d.read<std::string>()); break;
|
||||
case NetField::HAND_INV: setHandList(d.read<std::string>()); break;
|
||||
case NetField::WIELD_INV: setWieldList(d.read<std::string>()); break;
|
||||
case NetField::WIELD_INDEX: setWieldIndex(d.read<unsigned short>()); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
class ServerClient;
|
||||
class Deserializer;
|
||||
class ServerSubgame;
|
||||
class ServerSubgame;
|
||||
class ServerInventoryRefs;
|
||||
enum class NetPlayerField;
|
||||
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-12-24.
|
||||
//
|
||||
|
||||
#include "ServerEntity.h"
|
||||
|
||||
#include "../../Serializer.h"
|
||||
|
||||
void ServerEntity::setPos(glm::vec3 position) {
|
||||
this->position = position;
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
glm::vec3 ServerEntity::getPos() {
|
||||
return position;
|
||||
}
|
||||
|
||||
void ServerEntity::setVisualOffset(glm::vec3 vs) {
|
||||
this->visualOffset = vs;
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
glm::vec3 ServerEntity::getVisualOffset(){
|
||||
return visualOffset;
|
||||
}
|
||||
|
||||
void ServerEntity::setRotateX(float rotation) {
|
||||
this->rotation.x = rotation;
|
||||
}
|
||||
|
||||
float ServerEntity::getRotateX() {
|
||||
return rotation.x;
|
||||
}
|
||||
|
||||
void ServerEntity::setRotateY(float rotation) {
|
||||
this->rotation.y = rotation;
|
||||
}
|
||||
|
||||
float ServerEntity::getRotateY() {
|
||||
return rotation.y;
|
||||
}
|
||||
|
||||
void ServerEntity::setRotateZ(float rotation) {
|
||||
this->rotation.z = rotation;
|
||||
}
|
||||
|
||||
float ServerEntity::getRotateZ() {
|
||||
return rotation.z;
|
||||
}
|
||||
|
||||
void ServerEntity::setScale(float scale) {
|
||||
this->scale = scale;
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
float ServerEntity::getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
void ServerEntity::setAppearance(const std::string& displayMode, const std::string& displayArgument1, const std::string& displayArgument2) {
|
||||
this->displayMode = displayMode;
|
||||
this->displayArgument1 = displayArgument1;
|
||||
this->displayArgument2 = displayArgument2;
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
bool ServerEntity::checkAndResetDirty() {
|
||||
bool dirty = this->dirty;
|
||||
this->dirty = false;
|
||||
return dirty;
|
||||
}
|
||||
|
||||
Packet ServerEntity::createPacket(bool reliable) {
|
||||
return std::move(Serializer()
|
||||
.append(id)
|
||||
.append(position)
|
||||
.append(visualOffset)
|
||||
.append(rotation)
|
||||
.append(scale)
|
||||
.append(displayMode)
|
||||
.append(displayArgument1)
|
||||
.append(displayArgument2)
|
||||
.packet(Packet::Type::ENTITY_INFO, reliable));
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-12-24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "../../Packet.h"
|
||||
|
||||
class ServerEntity {
|
||||
public:
|
||||
explicit ServerEntity(unsigned int id) : id(id) {};
|
||||
|
||||
void setPos(glm::vec3 position);
|
||||
glm::vec3 getPos();
|
||||
|
||||
void setVisualOffset(glm::vec3 vs);
|
||||
glm::vec3 getVisualOffset();
|
||||
|
||||
void setRotateX(float rotation);
|
||||
float getRotateX();
|
||||
|
||||
void setRotateY(float rotation);
|
||||
float getRotateY();
|
||||
|
||||
void setRotateZ(float rotation);
|
||||
float getRotateZ();
|
||||
|
||||
void setScale(float scale);
|
||||
float getScale();
|
||||
|
||||
void setAppearance(const std::string& displayMode, const std::string& displayArgument1, const std::string& displayArgument2);
|
||||
|
||||
bool checkAndResetDirty();
|
||||
Packet createPacket(bool reliable = true);
|
||||
protected:
|
||||
unsigned int id = 0;
|
||||
|
||||
glm::vec3 position {};
|
||||
glm::vec3 visualOffset {};
|
||||
glm::vec3 rotation {};
|
||||
float scale = 1;
|
||||
|
||||
std::string displayMode = "";
|
||||
std::string displayArgument1 = "";
|
||||
std::string displayArgument2 = "";
|
||||
|
||||
bool dirty = true;
|
||||
};
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
//
|
||||
// Created by aurailus on 2019-12-24.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "ServerLuaEntity.h"
|
||||
|
||||
#include "../../Serializer.h"
|
||||
|
||||
void ServerLuaEntity::setPos(glm::vec3 position) {
|
||||
Entity::setPos(position);
|
||||
dirtyFields.emplace(NetField::POS);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setVel(glm::vec3 vel) {
|
||||
Entity::setVel(rot);
|
||||
dirtyFields.emplace(NetField::VEL);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setRot(glm::vec3 rot) {
|
||||
Entity::setRot(rot);
|
||||
dirtyFields.emplace(NetField::ROT);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setScale(float scale) {
|
||||
Entity::setScale(scale);
|
||||
dirtyFields.emplace(NetField::SCALE);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setScale(glm::vec3 scale) {
|
||||
Entity::setScale(scale);
|
||||
dirtyFields.emplace(NetField::SCALE);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setRotateX(float rotation) {
|
||||
Entity::setRotateX(rotation);
|
||||
dirtyFields.emplace(NetField::ROT);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setRotateY(float rotation) {
|
||||
Entity::setRotateY(rotation);
|
||||
dirtyFields.emplace(NetField::ROT);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setRotateZ(float rotation) {
|
||||
Entity::setRotateZ(rotation);
|
||||
dirtyFields.emplace(NetField::ROT);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setVisualOffset(glm::vec3 vs) {
|
||||
Entity::setVisualOffset(vs);
|
||||
dirtyFields.emplace(NetField::VISUAL_OFF);
|
||||
}
|
||||
|
||||
void ServerLuaEntity::setAppearance(const std::string& dMode, const std::string& argA, const std::string& argB) {
|
||||
this->dMode = dMode;
|
||||
this->dArgA = argA;
|
||||
this->dArgB = argB;
|
||||
dirtyFields.emplace(NetField::DISPLAY);
|
||||
}
|
||||
|
||||
std::optional<std::string> ServerLuaEntity::serialize() {
|
||||
if (dirtyFields.empty() && !fullSend) return {};
|
||||
|
||||
Serializer s;
|
||||
s.append(id);
|
||||
|
||||
if (dirtyFields.count(NetField::POS) || fullSend) s.appendE(NetField::POS) .append(pos);
|
||||
if (dirtyFields.count(NetField::VEL) || fullSend) s.appendE(NetField::VEL) .append(vel);
|
||||
if (dirtyFields.count(NetField::SCALE) || fullSend) s.appendE(NetField::SCALE) .append(scale);
|
||||
if (dirtyFields.count(NetField::ROT) || fullSend) s.appendE(NetField::ROT) .append(rot);
|
||||
if (dirtyFields.count(NetField::VISUAL_OFF) || fullSend) s.appendE(NetField::VISUAL_OFF).append(visualOff);
|
||||
if (dirtyFields.count(NetField::DISPLAY) || fullSend) s.appendE(NetField::DISPLAY) .append(dMode).append(dArgA).append(dArgB);
|
||||
|
||||
dirtyFields.clear();
|
||||
fullSend = false;
|
||||
|
||||
return s.data;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// Created by aurailus on 2019-12-24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <set>
|
||||
|
||||
#include "../../../game/entity/LuaEntity.h"
|
||||
|
||||
#include "../../Packet.h"
|
||||
#include "../../../game/scene/world/NetField.h"
|
||||
|
||||
class ServerLuaEntity : public LuaEntity {
|
||||
public:
|
||||
explicit ServerLuaEntity(SubgamePtr game, DimensionPtr dim, unsigned int id) :
|
||||
LuaEntity(game, dim), Entity(game, dim) {
|
||||
setId(id);
|
||||
};
|
||||
|
||||
virtual void setPos(glm::vec3 position) override;
|
||||
virtual void setVel(glm::vec3 vel) override;
|
||||
virtual void setRot(glm::vec3 rot) override;
|
||||
virtual void setScale(float scale) override;
|
||||
virtual void setScale(glm::vec3 scale) override;
|
||||
virtual void setRotateX(float rotation) override;
|
||||
virtual void setRotateY(float rotation) override;
|
||||
virtual void setRotateZ(float rotation) override;
|
||||
virtual void setVisualOffset(glm::vec3 vs) override;
|
||||
|
||||
void setAppearance(const std::string& dMode, const std::string& argA, const std::string& argB) override;
|
||||
|
||||
std::optional<std::string> serialize();
|
||||
protected:
|
||||
std::string dMode = "";
|
||||
std::string dArgA = "";
|
||||
std::string dArgB = "";
|
||||
|
||||
std::set<NetField> dirtyFields;
|
||||
bool fullSend = true;
|
||||
};
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "ServerWorld.h"
|
||||
|
||||
#include "ServerLuaEntity.h"
|
||||
#include "ServerGenStream.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "ServerPacketStream.h"
|
||||
|
@ -17,7 +18,6 @@
|
|||
#include "../../../world/chunk/Chunk.h"
|
||||
#include "../../../lua/usertype/Target.h"
|
||||
#include "../../../world/chunk/MapBlock.h"
|
||||
#include "../../../lua/usertype/ServerLuaEntity.h"
|
||||
#include "../../../game/inventory/ServerInventoryRefs.h"
|
||||
|
||||
ServerWorld::ServerWorld(unsigned int seed, SubgamePtr game, ServerClients& clients) :
|
||||
|
@ -25,6 +25,7 @@ ServerWorld::ServerWorld(unsigned int seed, SubgamePtr game, ServerClients& clie
|
|||
seed(seed),
|
||||
clients(clients),
|
||||
refs(std::make_shared<ServerInventoryRefs>(game, clients)) {
|
||||
|
||||
clients.init(this);
|
||||
|
||||
generateOrder.reserve(mapBlockGenRange.x * 2 + 1 * mapBlockGenRange.x * 2 + 1 * mapBlockGenRange.y * 2 + 1);
|
||||
|
@ -68,6 +69,8 @@ void ServerWorld::init(const std::string& worldDir) {
|
|||
void ServerWorld::update(double delta) {
|
||||
World::update(delta);
|
||||
|
||||
refs->update();
|
||||
|
||||
std::unordered_set<glm::ivec4, Vec::ivec4> updatedChunks {};
|
||||
std::unordered_set<glm::ivec4, Vec::ivec4> generatedMapBlocks {};
|
||||
|
||||
|
@ -133,21 +136,39 @@ void ServerWorld::update(double delta) {
|
|||
|
||||
for (auto& d : dimensions) {
|
||||
auto dimension = std::static_pointer_cast<ServerDimension>(d);
|
||||
unsigned int ind = dimension->getInd();
|
||||
|
||||
// Update clients with new entity information.
|
||||
|
||||
Serializer inf;
|
||||
inf.append(ind);
|
||||
|
||||
for (auto& entity : dimension->getLuaEntities()) {
|
||||
if (entity->entity->checkAndResetDirty()) {
|
||||
Packet p = entity->entity->createPacket();
|
||||
|
||||
for (auto& client : clients.players)
|
||||
p.sendTo(client->getPeer(), Packet::Channel::ENTITY);
|
||||
}
|
||||
auto opt = entity.entity.s()->serialize();
|
||||
if (opt) inf.append(*opt);
|
||||
}
|
||||
|
||||
for (unsigned int entity : dimension->getRemovedEntities()) {
|
||||
Packet p = Serializer().append<unsigned int>(entity).packet(Packet::Type::ENTITY_REMOVED);
|
||||
if (inf.data.size() > 4) {
|
||||
auto p = inf.packet(Packet::Type::ENTITY_INFO);
|
||||
for (auto& player : clients.players)
|
||||
if (player->getDim()->getInd() == ind)
|
||||
p.sendTo(player->getPeer(), Packet::Channel::ENTITY);
|
||||
}
|
||||
|
||||
for (auto& client : clients.players)
|
||||
p.sendTo(client->getPeer(), Packet::Channel::ENTITY);
|
||||
// Update clients with removed entities.
|
||||
|
||||
Serializer rem;
|
||||
rem.append(ind);
|
||||
|
||||
for (unsigned int entity : dimension->getRemovedEntities()) {
|
||||
rem.append<unsigned int>(entity);
|
||||
}
|
||||
|
||||
if (rem.data.size() > 4) {
|
||||
Packet p = rem.packet(Packet::Type::ENTITY_REMOVED);
|
||||
for (auto& player : clients.players)
|
||||
if (player->getDim()->getInd() == ind)
|
||||
p.sendTo(player->getPeer(), Packet::Channel::ENTITY);
|
||||
}
|
||||
|
||||
dimension->clearRemovedEntities();
|
||||
|
@ -185,9 +206,9 @@ void ServerWorld::generateMapBlocks(ServerPlayer& player) {
|
|||
|
||||
for (const auto &c : generateOrder) {
|
||||
glm::ivec3 mapBlockPos = playerMapBlock + c;
|
||||
auto existing = player.getDimension()->getMapBlock(mapBlockPos);
|
||||
auto existing = player.getDim()->getMapBlock(mapBlockPos);
|
||||
if (existing && existing->generated) continue;
|
||||
else generating += generateMapBlock(player.getDimension()->getInd(), mapBlockPos);
|
||||
else generating += generateMapBlock(player.getDim()->getInd(), mapBlockPos);
|
||||
}
|
||||
|
||||
std::cout << "Player moved, generating " << generating << " MapBlocks." << std::endl;
|
||||
|
@ -215,7 +236,7 @@ void ServerWorld::sendChunksToPlayer(ServerPlayer& client) {
|
|||
for (int k = bounds.first.z; k < bounds.second.z; k++) {
|
||||
glm::ivec3 pos {i, j, k};
|
||||
if (isInBounds(pos, oldBounds)) continue;
|
||||
packetStream->queue(glm::ivec4(pos, client.getDimension()->getInd()));
|
||||
packetStream->queue(glm::ivec4(pos, client.getDim()->getInd()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@ class Player;
|
|||
class LocalPlayer;
|
||||
class ServerPlayer;
|
||||
|
||||
class LuaEntity;
|
||||
class LocalLuaEntity;
|
||||
class ServerLuaEntity;
|
||||
|
||||
class Subgame;
|
||||
class LocalSubgame;
|
||||
class ServerSubgame;
|
||||
|
@ -50,6 +54,10 @@ public:
|
|||
|
||||
std::shared_ptr<B> operator*() { return b; }
|
||||
std::shared_ptr<B> operator->() { return b; }
|
||||
|
||||
bool isL() const { return std::dynamic_pointer_cast<L>(b) != nullptr; }
|
||||
bool isS() const { return std::dynamic_pointer_cast<S>(b) != nullptr; }
|
||||
|
||||
std::shared_ptr<L> l() { auto ptr = std::dynamic_pointer_cast<L>(b); if (!ptr) throw std::bad_cast(); return ptr; }
|
||||
std::shared_ptr<S> s() { auto ptr = std::dynamic_pointer_cast<S>(b); if (!ptr) throw std::bad_cast(); return ptr; }
|
||||
};
|
||||
|
@ -57,6 +65,7 @@ public:
|
|||
typedef CovariantPtr<World, LocalWorld, ServerWorld> WorldPtr;
|
||||
typedef CovariantPtr<Player, LocalPlayer, ServerPlayer> PlayerPtr;
|
||||
typedef CovariantPtr<Subgame, LocalSubgame, ServerSubgame> SubgamePtr;
|
||||
typedef CovariantPtr<LuaEntity, LocalLuaEntity, ServerLuaEntity> EntityPtr;
|
||||
typedef CovariantPtr<Dimension, LocalDimension, ServerDimension> DimensionPtr;
|
||||
typedef CovariantPtr<Inventory, LocalInventory, ServerInventory> InventoryPtr;
|
||||
typedef CovariantPtr<InventoryList, LocalInventoryList, ServerInventoryList> InventoryListPtr;
|
||||
|
|
|
@ -26,10 +26,10 @@ public:
|
|||
// Override setBlock to update lighting.
|
||||
bool setBlock(glm::ivec3 pos, unsigned int block) override;
|
||||
|
||||
virtual double blockHit(const Target &target, PlayerPtr player) = 0;
|
||||
virtual void blockPlace(const Target &target, PlayerPtr player) = 0;
|
||||
virtual void blockPlaceOrInteract(const Target &target, PlayerPtr player) = 0;
|
||||
virtual void blockInteract(const Target &target, PlayerPtr player) = 0;
|
||||
virtual double blockHit(const Target &target, PlayerPtr player) = 0;
|
||||
|
||||
unsigned int nextEntityInd();
|
||||
|
||||
|
|
|
@ -11,15 +11,11 @@
|
|||
#include "../lua/usertype/Target.h"
|
||||
#include "../lua/usertype/Player.h"
|
||||
#include "../world/chunk/MapBlock.h"
|
||||
#include "../lua/usertype/ItemStack.h"
|
||||
#include "../game/scene/world/NetField.h"
|
||||
#include "../game/entity/LocalLuaEntity.h"
|
||||
#include "../game/scene/world/LocalWorld.h"
|
||||
#include "../lua/usertype/LocalLuaEntity.h"
|
||||
#include "../game/scene/world/LocalPlayer.h"
|
||||
#include "../game/scene/world/MeshGenStream.h"
|
||||
#include "../game/scene/world/graph/MeshChunk.h"
|
||||
#include "../game/scene/world/ChunkMeshDetails.h"
|
||||
#include "../lua/usertype/ServerLocalLuaEntity.h"
|
||||
//#include "../game/inventory/LocalInventoryList.h"
|
||||
|
||||
LocalDimension::LocalDimension(SubgamePtr game, LocalWorld& world, const std::string& identifier, unsigned int ind) :
|
||||
Dimension(game, static_cast<World&>(world), identifier, ind), meshGenStream(std::make_shared<MeshGenStream>(game, *this)) {}
|
||||
|
@ -29,8 +25,8 @@ void LocalDimension::update(double delta) {
|
|||
|
||||
finishMeshes();
|
||||
|
||||
for (auto& entity : localEntities ) entity->entity->update(delta);
|
||||
for (auto& entity : serverEntities) entity->entity->update(delta);
|
||||
for (auto& entity : localEntities ) entity.entity.l()->update(delta);
|
||||
for (auto& entity : serverEntities) entity.entity.l()->update(delta);
|
||||
for (auto& entity : playerEntities) entity.update(delta);
|
||||
|
||||
auto clientMapBlock = Space::MapBlock::world::fromBlock(static_cast<LocalWorld&>(world).getPlayer()->getPos());
|
||||
|
@ -131,7 +127,7 @@ double LocalDimension::blockHit(const Target &target, PlayerPtr player) {
|
|||
sol::tie(damage, timeout) = game->getParser().safe_function(game->getParser().core["block_hit"],
|
||||
Api::Usertype::LocalPlayer(player.l()), Api::Usertype::Target(target));
|
||||
|
||||
// net->blockHit(target);
|
||||
static_cast<LocalWorld&>(world).getNet().blockHit(target);
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
@ -152,61 +148,71 @@ void LocalDimension::removeMeshChunk(const glm::ivec3& pos) {
|
|||
}
|
||||
}
|
||||
|
||||
void LocalDimension::addLocalEntity(std::shared_ptr<LocalLuaEntity> &entity) {
|
||||
void LocalDimension::addLocalEntity(Api::Usertype::Entity entity) {
|
||||
unsigned int id = entity.get_id();
|
||||
localEntities.push_back(entity);
|
||||
localEntityRefs.emplace(entity->id, --localEntities.end());
|
||||
localEntityRefs.emplace(id, --localEntities.end());
|
||||
}
|
||||
|
||||
void LocalDimension::removeLocalEntity(std::shared_ptr<LocalLuaEntity> &entity) {
|
||||
if (!localEntityRefs.count(entity->id)) return;
|
||||
auto refIter = localEntityRefs.at(entity->id);
|
||||
void LocalDimension::removeLocalEntity(Api::Usertype::Entity entity) {
|
||||
unsigned int id = entity.get_id();
|
||||
|
||||
if (!localEntityRefs.count(id)) return;
|
||||
auto refIter = localEntityRefs.at(id);
|
||||
|
||||
localEntities.erase(refIter);
|
||||
localEntityRefs.erase(entity->id);
|
||||
localEntityRefs.erase(id);
|
||||
}
|
||||
|
||||
void LocalDimension::serverEntityInfo(PacketView& p) {
|
||||
auto id = p.d.read<unsigned int>();
|
||||
auto position = p.d.read<glm::vec3>();
|
||||
auto visualOffset = p.d.read<glm::vec3>();
|
||||
auto rotation = p.d.read<glm::vec3>();
|
||||
auto scale = p.d.read<float>();
|
||||
auto displayMode = p.d.read<std::string>();
|
||||
auto displayArg1 = p.d.read<std::string>();
|
||||
auto displayArg2 = p.d.read<std::string>();
|
||||
void LocalDimension::serverEntitiesInfo(Deserializer& d) {
|
||||
unsigned int dim = d.read<unsigned int>();
|
||||
|
||||
if (serverEntityRefs.count(id)) {
|
||||
auto& luaEntity = *serverEntityRefs.at(id)->get();
|
||||
auto& entity = *luaEntity.entity;
|
||||
std::shared_ptr<LocalLuaEntity> activeEntity = nullptr;
|
||||
|
||||
entity.interpPos(position);
|
||||
entity.interpVisualOffset(visualOffset);
|
||||
entity.interpRotateX(rotation.x);
|
||||
entity.interpRotateY(rotation.y);
|
||||
entity.interpRotateZ(rotation.z);
|
||||
entity.interpScale(scale);
|
||||
while (!d.atEnd()) {
|
||||
switch (d.readE<NetField>()) {
|
||||
case NetField::ID: {
|
||||
unsigned int id = d.read<unsigned int>();
|
||||
if (serverEntityRefs.count(id)) activeEntity = serverEntityRefs.at(id)->entity.l();
|
||||
else {
|
||||
std::cout << "new entity" << std::endl;
|
||||
//TODO BEFORE COMMIT: *oh my god, please don't do this*
|
||||
auto ent = std::make_shared<LocalLuaEntity>(game, DimensionPtr(std::shared_ptr<LocalDimension>(this, [](LocalDimension*){})));
|
||||
auto entity = Api::Usertype::Entity(ent);
|
||||
ent->setId(id);
|
||||
serverEntities.push_back(entity);
|
||||
serverEntityRefs.emplace(id, --serverEntities.end());
|
||||
activeEntity = ent;
|
||||
}
|
||||
break; }
|
||||
|
||||
luaEntity.setDisplayType(displayMode, displayArg1, displayArg2);
|
||||
}
|
||||
else {
|
||||
auto entity = std::make_shared<ServerLocalLuaEntity>(id, game, displayMode, displayArg1, displayArg2);
|
||||
entity->entity->setPos(position);
|
||||
entity->entity->setVisualOffset(visualOffset);
|
||||
entity->entity->setRotateX(rotation.x);
|
||||
entity->entity->setRotateY(rotation.y);
|
||||
entity->entity->setRotateZ(rotation.z);
|
||||
entity->entity->setScale(scale);
|
||||
serverEntities.push_back(entity);
|
||||
serverEntityRefs.emplace(id, --serverEntities.end());
|
||||
case NetField::POS: activeEntity->setPos(d.read<glm::vec3>()); break;
|
||||
case NetField::VEL: activeEntity->setVel(d.read<glm::vec3>()); break;
|
||||
case NetField::ROT: activeEntity->setRot(d.read<glm::vec3>()); break;
|
||||
case NetField::SCALE: activeEntity->setScale(d.read<glm::vec3>()); break;
|
||||
case NetField::VISUAL_OFF: activeEntity->setVisualOffset(d.read<glm::vec3>()); break;
|
||||
|
||||
case NetField::DISPLAY: {
|
||||
std::cout << "display update" << std::endl;
|
||||
std::string type, a, b;
|
||||
d.read(type).read(a).read(b);
|
||||
activeEntity->setAppearance(type, a, b);
|
||||
break; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocalDimension::serverEntityRemoved(unsigned int id) {
|
||||
if (!serverEntityRefs.count(id)) return;
|
||||
auto refIter = serverEntityRefs.at(id);
|
||||
void LocalDimension::serverEntitiesRemoved(Deserializer& d) {
|
||||
unsigned int dim = d.read<unsigned int>();
|
||||
|
||||
serverEntities.erase(refIter);
|
||||
serverEntityRefs.erase(id);
|
||||
while (!d.atEnd()) {
|
||||
unsigned int id = d.read<unsigned int>();
|
||||
if (!serverEntityRefs.count(id)) continue;
|
||||
auto refIter = serverEntityRefs.at(id);
|
||||
serverEntities.erase(refIter);
|
||||
serverEntityRefs.erase(id);
|
||||
}
|
||||
}
|
||||
|
||||
int LocalDimension::renderChunks(Renderer &renderer) {
|
||||
|
@ -222,8 +228,8 @@ int LocalDimension::renderChunks(Renderer &renderer) {
|
|||
}
|
||||
|
||||
void LocalDimension::renderEntities(Renderer &renderer) {
|
||||
for (auto& entity : localEntities) entity->entity->draw(renderer);
|
||||
for (auto& entity : serverEntities) entity->entity->draw(renderer);
|
||||
for (auto& entity : localEntities) entity.entity.l()->draw(renderer);
|
||||
for (auto& entity : serverEntities) entity.entity.l()->draw(renderer);
|
||||
for (auto& entity : playerEntities) entity.draw(renderer);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,15 +9,14 @@
|
|||
#include "Dimension.h"
|
||||
|
||||
#include "../def/LocalSubgame.h"
|
||||
#include "../lua/usertype/Entity.h"
|
||||
#include "../game/entity/engine/PlayerEntity.h"
|
||||
|
||||
class Renderer;
|
||||
class MeshChunk;
|
||||
class PacketView;
|
||||
class Deserializer;
|
||||
class MeshGenStream;
|
||||
class LocalLuaEntity;
|
||||
class ChunkRenderElem;
|
||||
class ServerLocalLuaEntity;
|
||||
|
||||
class LocalDimension : public Dimension {
|
||||
public:
|
||||
|
@ -39,11 +38,11 @@ public:
|
|||
void setMeshChunk(std::shared_ptr<MeshChunk> chunk);
|
||||
void removeMeshChunk(const glm::ivec3& pos);
|
||||
|
||||
void addLocalEntity(std::shared_ptr<LocalLuaEntity>& entity);
|
||||
void removeLocalEntity(std::shared_ptr<LocalLuaEntity>& entity);
|
||||
void addLocalEntity(Api::Usertype::Entity entity);
|
||||
void removeLocalEntity(Api::Usertype::Entity entity);
|
||||
|
||||
void serverEntityInfo(PacketView& p);
|
||||
void serverEntityRemoved(unsigned int id);
|
||||
void serverEntitiesInfo(Deserializer& d);
|
||||
void serverEntitiesRemoved(Deserializer& d);
|
||||
|
||||
int renderChunks(Renderer &renderer);
|
||||
void renderEntities(Renderer &renderer);
|
||||
|
@ -57,9 +56,8 @@ protected:
|
|||
std::unordered_set<glm::ivec3, Vec::ivec3> propogateRemoveNodes() override;
|
||||
|
||||
private:
|
||||
typedef std::list<Api::Usertype::Entity>::iterator ent_ref;
|
||||
typedef std::list<std::shared_ptr<ChunkRenderElem>>::iterator chunk_ref;
|
||||
typedef std::list<std::shared_ptr<LocalLuaEntity>>::iterator local_ent_ref;
|
||||
typedef std::list<std::shared_ptr<ServerLocalLuaEntity>>::iterator server_ent_ref;
|
||||
|
||||
void finishMeshes();
|
||||
|
||||
|
@ -68,11 +66,11 @@ private:
|
|||
|
||||
std::shared_ptr<MeshGenStream> meshGenStream;
|
||||
|
||||
std::unordered_map<unsigned int, local_ent_ref> localEntityRefs {};
|
||||
std::list<std::shared_ptr<LocalLuaEntity>> localEntities {};
|
||||
std::unordered_map<unsigned int, ent_ref> localEntityRefs {};
|
||||
std::list<Api::Usertype::Entity> localEntities {};
|
||||
|
||||
std::unordered_map<unsigned int, server_ent_ref> serverEntityRefs {};
|
||||
std::list<std::shared_ptr<ServerLocalLuaEntity>> serverEntities {};
|
||||
std::unordered_map<unsigned int, ent_ref> serverEntityRefs {};
|
||||
std::list<Api::Usertype::Entity> serverEntities {};
|
||||
|
||||
std::unordered_map<glm::vec3, chunk_ref, Vec::vec3> renderRefs {};
|
||||
std::list<std::shared_ptr<ChunkRenderElem>> renderElems {};
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "../lua/usertype/ItemStack.h"
|
||||
#include "../net/server/conn/ServerPlayer.h"
|
||||
#include "../net/server/world/ServerWorld.h"
|
||||
#include "../lua/usertype/ServerLuaEntity.h"
|
||||
|
||||
ServerDimension::ServerDimension(SubgamePtr game, ServerWorld& world, const std::string& identifier, unsigned int ind) :
|
||||
Dimension(game, static_cast<World&>(world), identifier, ind) {}
|
||||
|
@ -50,10 +49,17 @@ bool ServerDimension::setBlock(glm::ivec3 pos, unsigned int block) {
|
|||
bool manip = Dimension::setBlock(pos, block);
|
||||
if (!manip) return false;
|
||||
glm::vec3 mb = Space::MapBlock::world::fromBlock(pos);
|
||||
mapBlockIntegrity[mb] = mapBlockIntegrity[mb] + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
double ServerDimension::blockHit(const Target &target, PlayerPtr player) {
|
||||
double timeout = 0, damage = 0;
|
||||
sol::tie(damage, timeout) = game->getParser().safe_function(game->getParser().core["block_hit"],
|
||||
Api::Usertype::ServerPlayer(player), Api::Usertype::Target(target));
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
void ServerDimension::blockPlace(const Target &target, PlayerPtr player) {
|
||||
std::tuple<sol::optional<Api::Usertype::ItemStack>, sol::optional<glm::vec3>> res = game->getParser().safe_function(
|
||||
game->getParser().core["block_place"], Api::Usertype::ServerPlayer(player.s()), Api::Usertype::Target(target));
|
||||
|
@ -81,44 +87,32 @@ void ServerDimension::blockPlaceOrInteract(const Target &target, PlayerPtr playe
|
|||
if (inv->hasList(player->getWieldList())) inv->getList(player->getWieldList())->setStack(player->getWieldIndex(), ItemStack(*stack, game));
|
||||
}
|
||||
|
||||
double ServerDimension::blockHit(const Target &target, PlayerPtr player) {
|
||||
double timeout = 0, damage = 0;
|
||||
sol::tie(damage, timeout) = game->getParser().safe_function(game->getParser().core["block_hit"],
|
||||
Api::Usertype::ServerPlayer(player), Api::Usertype::Target(target));
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
void ServerDimension::setChunk(std::shared_ptr<Chunk> chunk) {
|
||||
std::shared_ptr<Chunk> existing = getChunk(chunk->pos);
|
||||
if (existing != nullptr) chunk = combinePartials(chunk, existing);
|
||||
|
||||
Dimension::setChunk(chunk);
|
||||
glm::vec3 mb = Space::MapBlock::world::fromChunk(chunk->pos);
|
||||
mapBlockIntegrity[mb] = mapBlockIntegrity[mb] + 1;
|
||||
}
|
||||
|
||||
void ServerDimension::addLuaEntity(std::shared_ptr<ServerLuaEntity> &entity) {
|
||||
luaEntities.push_back(entity);
|
||||
luaEntityRefs.emplace(entity->id, --luaEntities.end());
|
||||
void ServerDimension::addLuaEntity(Api::Usertype::Entity entity) {
|
||||
unsigned int id = entity.get_id();
|
||||
luaEntities.push_back(std::move(entity));
|
||||
luaEntityRefs.emplace(id, --luaEntities.end());
|
||||
}
|
||||
|
||||
void ServerDimension::removeLuaEntity(std::shared_ptr<ServerLuaEntity> &entity) {
|
||||
if (!luaEntityRefs.count(entity->id)) return;
|
||||
auto refIter = luaEntityRefs.at(entity->id);
|
||||
void ServerDimension::removeLuaEntity(Api::Usertype::Entity entity) {
|
||||
unsigned int id = entity.get_id();
|
||||
if (!luaEntityRefs.count(id)) return;
|
||||
|
||||
removedEntities.push_back(entity->id);
|
||||
auto refIter = luaEntityRefs.at(id);
|
||||
removedEntities.push_back(id);
|
||||
|
||||
luaEntities.erase(refIter);
|
||||
luaEntityRefs.erase(entity->id);
|
||||
luaEntityRefs.erase(id);
|
||||
}
|
||||
|
||||
unsigned long long ServerDimension::getMapBlockIntegrity(glm::ivec3 mapBlock) {
|
||||
if (mapBlockIntegrity.count(mapBlock)) return mapBlockIntegrity[mapBlock];
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<ServerLuaEntity>> &ServerDimension::getLuaEntities() {
|
||||
std::list<Api::Usertype::Entity> &ServerDimension::getLuaEntities() {
|
||||
return luaEntities;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "Dimension.h"
|
||||
|
||||
#include <list>
|
||||
#include "../lua/usertype/Entity.h"
|
||||
|
||||
class ServerWorld;
|
||||
class ServerPlayer;
|
||||
class ServerSubgame;
|
||||
class ServerLuaEntity;
|
||||
|
||||
class ServerDimension : public Dimension {
|
||||
public:
|
||||
|
@ -27,21 +28,22 @@ public:
|
|||
virtual void blockInteract(const Target &target, PlayerPtr player) override;
|
||||
virtual double blockHit(const Target &target, PlayerPtr player) override;
|
||||
|
||||
void addLuaEntity(std::shared_ptr<ServerLuaEntity>& entity);
|
||||
void removeLuaEntity(std::shared_ptr<ServerLuaEntity>& entity);
|
||||
void addLuaEntity(Api::Usertype::Entity entity);
|
||||
void removeLuaEntity(Api::Usertype::Entity entity);
|
||||
|
||||
unsigned long long getMapBlockIntegrity(glm::ivec3 mapBlock);
|
||||
std::list<std::shared_ptr<ServerLuaEntity>>& getLuaEntities();
|
||||
// unsigned long long getMapBlockIntegrity(glm::ivec3 mapBlock);
|
||||
|
||||
std::list<Api::Usertype::Entity>& getLuaEntities();
|
||||
const std::list<unsigned int>& getRemovedEntities() const;
|
||||
void clearRemovedEntities();
|
||||
|
||||
private:
|
||||
typedef std::list<std::shared_ptr<ServerLuaEntity>>::iterator luaent_ref;
|
||||
typedef std::list<Api::Usertype::Entity>::iterator luaent_ref;
|
||||
|
||||
std::unordered_map<unsigned int, luaent_ref> luaEntityRefs {};
|
||||
std::list<std::shared_ptr<ServerLuaEntity>> luaEntities {};
|
||||
std::list<Api::Usertype::Entity> luaEntities {};
|
||||
std::list<unsigned int> removedEntities {};
|
||||
|
||||
std::unordered_map<glm::ivec3, unsigned long long, Vec::ivec3> mapBlockIntegrity {};
|
||||
// std::unordered_map<glm::ivec3, unsigned long long, Vec::ivec3> mapBlockIntegrity {};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local function collides(entity)
|
||||
return zepha.get_block((entity.pos - V{0, 0.5, 0}):floor()) ~= "air"
|
||||
return entity.dim:get_block((entity.pos - V{0, 0.5, 0}):floor()) ~= "air"
|
||||
end
|
||||
|
||||
zepha.register_entity("@aurailus:item_collection:dropped_item", {
|
||||
|
@ -79,7 +79,7 @@ zepha.register_entity("@aurailus:item_collection:dropped_item", {
|
|||
|
||||
zepha.after(function()
|
||||
p:get_inventory():get_list("main"):add_stack({self.item, 1})
|
||||
zepha.remove_entity(self)
|
||||
self.object.dim:remove_entity(self)
|
||||
end, 2/20)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
return function(pos)
|
||||
local def = zepha.registered_blocks[zepha.get_block(pos)]
|
||||
return function(dim, pos)
|
||||
local def = zepha.registered_blocks[dim:get_block(pos)]
|
||||
if def == nil then return nil end
|
||||
local yields = def.yields
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local get_yield = runfile("@aurailus:item_collection/get_yield")
|
||||
|
||||
if zepha.server then
|
||||
zepha.bind("break", function(pos, player)
|
||||
zepha.bind("on_break", function(pos, player)
|
||||
local yields = get_yield(pos)
|
||||
if yields == nil then return end
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
local get_yield = runfile("@aurailus:item_collection/get_yield")
|
||||
|
||||
if zepha.server then
|
||||
zepha.bind("break", function(pos)
|
||||
local yields = get_yield(pos)
|
||||
zepha.bind("on_break", function(dim, pos)
|
||||
local yields = get_yield(dim, pos)
|
||||
if yields == nil then return end
|
||||
|
||||
zepha.add_entity(pos + 0.5, "@aurailus:item_collection:dropped_item", { item = yields });
|
||||
dim:add_entity(pos + 0.5, "@aurailus:item_collection:dropped_item", { item = yields });
|
||||
end)
|
||||
end
|
|
@ -11,10 +11,20 @@ zepha.register_entity("zeus:default:test", {
|
|||
self.object.scale = 1/4
|
||||
end,
|
||||
on_update = function(self, delta)
|
||||
-- self.object.pos = self.object.pos +
|
||||
-- V(0.6 * math.sin(math.rad(self.object.yaw)), 0, 0.6 * math.cos(math.rad(self.object.yaw))) * delta
|
||||
-- self.object.yaw += 50 * delta
|
||||
self.object.pos = self.object.pos +
|
||||
V(0.6 * math.sin(math.rad(self.object.yaw)), 0, 0.6 * math.cos(math.rad(self.object.yaw))) * delta
|
||||
self.object.yaw = self.object.yaw + 50 * delta
|
||||
end
|
||||
})
|
||||
|
||||
if zepha.client then zepha.after(function() zepha.get_default_dimension():add_entity(V(), "zeus:default:test") end, 0) end
|
||||
if zepha.client then
|
||||
zepha.after(function()
|
||||
zepha.player.dim:add_entity(V(0, -34, 0), "zeus:default:test")
|
||||
end, 0)
|
||||
end
|
||||
|
||||
if zepha.server then
|
||||
zepha.bind("player_join", function(player)
|
||||
player.dim:add_entity(V(0, -32, 0), "zeus:default:test")
|
||||
end)
|
||||
end
|
Loading…
Reference in New Issue