My life is finally complete. (Fixed entities, server-side entity anims!)
parent
2a952955bf
commit
aafe67ce11
|
@ -1,7 +1,7 @@
|
|||
zepha.delayed_functions = {}
|
||||
|
||||
function zepha.after(fn, timeout)
|
||||
table.insert(zepha.delayed_functions, {fn = fn, timeout = timeout, at = zepha.time.s()})
|
||||
table.insert(zepha.delayed_functions, {fn = fn, timeout = timeout, at = zepha.time.s() + timeout})
|
||||
end
|
||||
|
||||
function zepha.__builtin.update_delayed_functions()
|
||||
|
|
|
@ -35,6 +35,10 @@ void AnimationState::update(double delta) {
|
|||
}
|
||||
}
|
||||
|
||||
bool AnimationState::isLooping() {
|
||||
return loop;
|
||||
}
|
||||
|
||||
void AnimationState::setAnim(const std::string& name, double interp, bool loop) {
|
||||
auto& anim = animations[name];
|
||||
setAnim(anim.range, interp, loop);
|
||||
|
@ -46,6 +50,10 @@ void AnimationState::setAnim(glm::ivec2 range, double interp, bool loop) {
|
|||
currentFrame = range.x;
|
||||
}
|
||||
|
||||
bool AnimationState::isPlaying() {
|
||||
return playing;
|
||||
}
|
||||
|
||||
void AnimationState::setPlaying(bool playing) {
|
||||
this->playing = playing;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,11 @@ public:
|
|||
void setAnimations(const std::vector<AnimationSegment>& anims);
|
||||
void defineAnimation(const std::string& name, glm::ivec2 range);
|
||||
|
||||
bool isLooping();
|
||||
void setAnim(const std::string& name, double interp, bool loop);
|
||||
void setAnim(glm::ivec2 range, double interp, bool loop);
|
||||
|
||||
bool isPlaying();
|
||||
void setPlaying(bool playing);
|
||||
|
||||
double getFrame();
|
||||
|
|
|
@ -27,7 +27,7 @@ void DrawableEntity::setModel(std::shared_ptr<Model> model) {
|
|||
}
|
||||
|
||||
void DrawableEntity::update(double delta) {
|
||||
animation.update(delta);
|
||||
Entity::update(delta);
|
||||
|
||||
float factor = static_cast<float>(fmin(delta * 8, 1));
|
||||
|
||||
|
|
|
@ -91,3 +91,7 @@ void Entity::setDim(DimensionPtr dim) {
|
|||
SubgamePtr Entity::getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
void Entity::update(double delta) {
|
||||
animation.update(delta);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ public:
|
|||
Entity() = default;
|
||||
Entity(SubgamePtr game, DimensionPtr dim) : game(game), dim(dim) {};
|
||||
|
||||
virtual void update(double delta);
|
||||
|
||||
virtual glm::vec3 getPos();
|
||||
virtual void setPos(glm::vec3 position);
|
||||
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
#include "LuaEntity.h"
|
||||
|
||||
LuaEntity::LuaEntity(SubgamePtr game, DimensionPtr dim) : Entity(game, dim) {}
|
||||
LuaEntity::LuaEntity(SubgamePtr game, DimensionPtr dim) : Entity(game, dim) {}
|
|
@ -84,7 +84,7 @@ void DebugGui::update(std::shared_ptr<LocalPlayer> player, double fps, int /*chu
|
|||
auto& onBiomeDef = game->getBiomes().biomeFromId(world.l()->getActiveDimension()->getBiome(glm::floor(player->getPos())));
|
||||
auto& targetedBlockDef = game->getDefs().blockFromId(world.l()->getActiveDimension()->getBlock(target.pos));
|
||||
|
||||
{ // Top Right Graphs
|
||||
/* Top-right Graphs */ {
|
||||
get<GuiLabelledGraph>("fpsGraph")->pushValue(static_cast<float>(fps));
|
||||
get<GuiLabelledGraph>("drawsGraph")->pushValue(drawCalls);
|
||||
|
||||
|
@ -97,20 +97,19 @@ void DebugGui::update(std::shared_ptr<LocalPlayer> player, double fps, int /*chu
|
|||
(videoMemTotal - videoMemAvail) / static_cast<float>(videoMemTotal) * 100.0)) / 100.0f);
|
||||
}
|
||||
|
||||
{ // Bottom Right Graphs
|
||||
/* Bottom-right Graphs */ {
|
||||
get<GuiLabelledGraph>("meshGraph")->pushValue(world.l()->lastMeshUpdates);
|
||||
get<GuiLabelledGraph>("interpGraph")->pushValue(world.l()->mapBlocksInterpolated);
|
||||
get<GuiLabelledGraph>("genGraph")->pushValue(static_cast<float>(ssGen));
|
||||
get<GuiLabelledGraph>("packetGraph")->pushValue(static_cast<float>(ssPack));
|
||||
}
|
||||
|
||||
{ // Top-left Data
|
||||
/* Top-left Data */ {
|
||||
glm::vec3 playerPos = glm::floor(player->getPos());
|
||||
glm::vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos);
|
||||
glm::vec3 mapBlockPos = Space::MapBlock::world::fromChunk(chunkPos);
|
||||
glm::vec3 regionPos = Space::Region::world::fromChunk(chunkPos);
|
||||
|
||||
// Block Coordinates offset from respective container
|
||||
glm::vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos);
|
||||
glm::vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos);
|
||||
glm::vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos);
|
||||
|
@ -119,31 +118,32 @@ void DebugGui::update(std::shared_ptr<LocalPlayer> player, double fps, int /*chu
|
|||
|
||||
using namespace Util;
|
||||
|
||||
str << "Player: " << vecToString(playerPos);
|
||||
str << " (" << floatVecToString(player->getPos()) << ")" << std::endl << std::endl;
|
||||
|
||||
str << "Chunk: " << vecToString(posOffsetFromChunk) << " [" << vecToString(chunkPos) << "]" << std::endl;
|
||||
str << "MapBlock: " << vecToString(posOffsetFromBlock) << " [" << vecToString(mapBlockPos) << "]" << std::endl;
|
||||
str << "Region: " << vecToString(posOffsetFromRegion) << " [" << vecToString(regionPos) << "]" << std::endl << std::endl;
|
||||
str << "Dimension: " << world.l()->getActiveDimension()->getIdentifier()
|
||||
<< " [" << world.l()->getActiveDimension()->getInd() << "]" << std::endl << std::endl;
|
||||
|
||||
str << "Pos: " << vecToString(playerPos) << " (" << floatVecToString(player->getPos()) << ")" << std::endl;
|
||||
str << "Vel: " << floatVecToString(player->getVel()) << std::endl;
|
||||
str << "Yaw: " << floatToString(player->getYaw()) << ", ";
|
||||
str << "Pitch: " << floatToString(player->getPitch()) << std::endl << std::endl;
|
||||
|
||||
str << "Biome: " << onBiomeDef.identifier << " [" << onBiomeDef.index << "]" << std::endl << std::endl;
|
||||
str << "C: " << vecToString(posOffsetFromChunk) << " [" << vecToString(chunkPos) << "]" << std::endl;
|
||||
str << "M: " << vecToString(posOffsetFromBlock) << " [" << vecToString(mapBlockPos) << "]" << std::endl;
|
||||
str << "R: " << vecToString(posOffsetFromRegion) << " [" << vecToString(regionPos) << "]" << std::endl << std::endl;
|
||||
|
||||
str << "Texture Slots: " << game.l()->textures.textureSlotsUsed << " / " << game.l()->textures.maxTextureSlots
|
||||
<< " (" << round(game.l()->textures.textureSlotsUsed / static_cast<float>(game.l()->textures.maxTextureSlots) * 100) << "%)" << std::endl << std::endl;
|
||||
|
||||
str << "Biome: " << onBiomeDef.identifier << " [" << onBiomeDef.index << "]" << std::endl << std::endl;
|
||||
|
||||
if (target.type == Target::Type::BLOCK) {
|
||||
std::string face =
|
||||
target.face == EVec::TOP ? "TOP" :
|
||||
target.face == EVec::BOTTOM ? "BOTTOM" :
|
||||
target.face == EVec::LEFT ? "LEFT" :
|
||||
target.face == EVec::RIGHT ? "RIGHT" :
|
||||
target.face == EVec::FRONT ? "FRONT" :
|
||||
target.face == EVec::BACK ? "BACK" :
|
||||
"NONE" ;
|
||||
target.face == EVec::TOP ? "TOP" :
|
||||
target.face == EVec::BOTTOM ? "BOTTOM" :
|
||||
target.face == EVec::LEFT ? "LEFT" :
|
||||
target.face == EVec::RIGHT ? "RIGHT" :
|
||||
target.face == EVec::FRONT ? "FRONT" :
|
||||
target.face == EVec::BACK ? "BACK" :
|
||||
"NONE" ;
|
||||
|
||||
str << "Pointing At: " << targetedBlockDef.identifier << " [" << targetedBlockDef.index << "]" << std::endl;
|
||||
str << "Pointed Position: " << vecToString(target.pos) << std::endl;
|
||||
|
@ -156,7 +156,7 @@ void DebugGui::update(std::shared_ptr<LocalPlayer> player, double fps, int /*chu
|
|||
get<GuiText>("dataText")->setText(str.str());
|
||||
}
|
||||
|
||||
{ // Crosshair Text
|
||||
/* Crosshair Text */ {
|
||||
if (target.type == Target::Type::BLOCK) get<GuiText>("crosshairText")->setText(targetedBlockDef.name + " (" +
|
||||
targetedBlockDef.identifier + ") [" + std::to_string(targetedBlockDef.index) + "]");
|
||||
else get<GuiText>("crosshairText")->setText("");
|
||||
|
|
|
@ -21,6 +21,8 @@ enum class NetField {
|
|||
// Entities
|
||||
DISPLAY,
|
||||
VISUAL_OFF,
|
||||
ANIM_RANGE,
|
||||
ANIM_STATE,
|
||||
|
||||
// Players
|
||||
LOOK_OFF,
|
||||
|
|
|
@ -72,7 +72,7 @@ void LocalLuaParser::loadApi(WorldPtr world, PlayerPtr player) {
|
|||
Api::Usertype::ItemStack::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::LocalPlayer::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::InventoryList::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::AnimationManager::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::LocalAnimationManager::bind(Api::State::CLIENT, lua, core);
|
||||
|
||||
core["client"] = true;
|
||||
core["player"] = Api::Usertype::LocalPlayer(player);
|
||||
|
|
|
@ -96,13 +96,13 @@ void ServerLuaParser::loadApi(WorldPtr world) {
|
|||
|
||||
// Types
|
||||
Api::Usertype::Target::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::Entity::bind(Api::State::CLIENT, lua, core);
|
||||
Api::Usertype::Entity::bind(Api::State::SERVER, 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);
|
||||
Api::Usertype::ServerPlayer::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::InventoryList::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::AnimationManager::bind(Api::State::SERVER, lua, core);
|
||||
Api::Usertype::ServerAnimationManager::bind(Api::State::SERVER, lua, core);
|
||||
|
||||
core["server"] = true;
|
||||
core["players"] = lua.create_table();
|
||||
|
|
|
@ -16,8 +16,8 @@ void Api::Module::Dimension::bind() {
|
|||
core.set_function("set_default_dimension", Util::bind_this(this, &Dimension::setDefaultDimension));
|
||||
}
|
||||
|
||||
void Api::Module::Dimension::createDimension(const std::string& identifier) {
|
||||
world.createDimension(identifier);
|
||||
Api::Usertype::Dimension Api::Module::Dimension::createDimension(const std::string& identifier) {
|
||||
return Api::Usertype::Dimension(world.createDimension(identifier));
|
||||
}
|
||||
|
||||
void Api::Module::Dimension::setDefaultDimension(const std::string& identifier) {
|
||||
|
@ -25,9 +25,13 @@ void Api::Module::Dimension::setDefaultDimension(const std::string& identifier)
|
|||
}
|
||||
|
||||
sol::object Api::Module::Dimension::getDefaultDimension(const sol::this_state s) {
|
||||
return sol::make_object(s, Api::Usertype::Dimension(world.getDefaultDimension()));
|
||||
auto dim = world.getDefaultDimension();
|
||||
if (!dim) return sol::nil;
|
||||
return sol::make_object(s, Api::Usertype::Dimension(dim));
|
||||
}
|
||||
|
||||
sol::object Api::Module::Dimension::getDimension(sol::this_state s, const std::string& identifier) {
|
||||
return sol::make_object(s, Api::Usertype::Dimension(world.getDimension(identifier)));
|
||||
auto dim = world.getDimension(identifier);
|
||||
if (!dim) return sol::nil;
|
||||
return sol::make_object(s, Api::Usertype::Dimension(dim));
|
||||
}
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "SubgameModule.h"
|
||||
|
||||
#include "../usertype/Dimension.h"
|
||||
|
||||
namespace Api::Module {
|
||||
class Dimension : public Api::Module::SubgameModule {
|
||||
public:
|
||||
|
@ -13,7 +15,7 @@ namespace Api::Module {
|
|||
void bind() override;
|
||||
|
||||
protected:
|
||||
void createDimension(const std::string& identifier);
|
||||
Api::Usertype::Dimension createDimension(const std::string& identifier);
|
||||
sol::object getDimension(sol::this_state s, const std::string& identifier);
|
||||
|
||||
sol::object getDefaultDimension(const sol::this_state s);
|
||||
|
|
|
@ -8,49 +8,72 @@
|
|||
#include "../../game/entity/LuaEntity.h"
|
||||
#include "../../game/entity/DrawableEntity.h"
|
||||
#include "../../game/entity/AnimationSegment.h"
|
||||
#include "../../net/server/world/ServerLuaEntity.h"
|
||||
|
||||
Api::Usertype::AnimationManager::AnimationManager(EntityPtr entity) :
|
||||
entity(entity) {}
|
||||
Api::Usertype::AnimationManager::AnimationManager(EntityPtr entity) : entity(entity) {}
|
||||
|
||||
Api::Usertype::AnimationManager& Api::Usertype::AnimationManager::define(sol::table anims) {
|
||||
Api::Usertype::AnimationManager Api::Usertype::AnimationManager::define(sol::table anims) {
|
||||
std::vector<AnimationSegment> animations;
|
||||
|
||||
for (auto& ref : anims) {
|
||||
std::string n = ref.first.as<std::string>();
|
||||
sol::table t = ref.second.as<sol::table>();
|
||||
animations.push_back({n, {static_cast<unsigned int>(t.get<float>(1)), static_cast<unsigned int>(t.get<float>(2))}});
|
||||
}
|
||||
|
||||
entity->animation.setAnimations(animations);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Api::Usertype::AnimationManager& Api::Usertype::AnimationManager::set_anim(sol::object anim, sol::optional<bool> loop) {
|
||||
Api::Usertype::AnimationManager Api::Usertype::AnimationManager::set_anim(sol::object anim, sol::optional<bool> loop) {
|
||||
if (anim.is<std::string>()) entity->animation.setAnim(anim.as<std::string>(), 0, loop.value_or(true));
|
||||
else if (anim.is<sol::table>()) entity->animation.setAnim(
|
||||
glm::ivec2 {anim.as<sol::table>().get<unsigned int>(1), anim.as<sol::table>().get<unsigned int>(2)}, 0, loop.value_or(true));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Api::Usertype::AnimationManager& Api::Usertype::AnimationManager::play(sol::optional<unsigned int> offset) {
|
||||
Api::Usertype::AnimationManager Api::Usertype::AnimationManager::play(sol::optional<unsigned int> offset) {
|
||||
entity->animation.setPlaying(true);
|
||||
if (offset) entity->animation.setFrame(entity->animation.getFrame() + *offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Api::Usertype::AnimationManager& Api::Usertype::AnimationManager::pause(sol::optional<unsigned int> offset) {
|
||||
Api::Usertype::AnimationManager Api::Usertype::AnimationManager::pause(sol::optional<unsigned int> offset) {
|
||||
entity->animation.setPlaying(false);
|
||||
if (offset) entity->animation.setFrame(entity->animation.getFrame() + *offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Api::Usertype::AnimationManager::bind(State, sol::state &lua, sol::table &core) {
|
||||
lua.new_usertype<AnimationManager>("AnimationManager",
|
||||
"define", &AnimationManager::define,
|
||||
"set_anim", &AnimationManager::set_anim,
|
||||
"play", &AnimationManager::play,
|
||||
"pause", &AnimationManager::pause
|
||||
void Api::Usertype::LocalAnimationManager::bind(State, sol::state &lua, sol::table &core) {
|
||||
lua.new_usertype<LocalAnimationManager>("AnimationManager",
|
||||
"define", &LocalAnimationManager::define,
|
||||
"set_anim", &LocalAnimationManager::set_anim,
|
||||
"play", &LocalAnimationManager::play,
|
||||
"pause", &LocalAnimationManager::pause
|
||||
);
|
||||
}
|
||||
|
||||
Api::Usertype::AnimationManager Api::Usertype::ServerAnimationManager::set_anim(sol::object anim, sol::optional<bool> loop) {
|
||||
AnimationManager::set_anim(anim, loop);
|
||||
entity.s()->dirtyField(NetField::ANIM_RANGE);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Api::Usertype::AnimationManager Api::Usertype::ServerAnimationManager::play(sol::optional<unsigned int> offset) {
|
||||
AnimationManager::play(offset);
|
||||
entity.s()->dirtyField(NetField::ANIM_STATE);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Api::Usertype::AnimationManager Api::Usertype::ServerAnimationManager::pause(sol::optional<unsigned int> offset) {
|
||||
AnimationManager::pause(offset);
|
||||
entity.s()->dirtyField(NetField::ANIM_STATE);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Api::Usertype::ServerAnimationManager::bind(State, sol::state &lua, sol::table &core) {
|
||||
lua.new_usertype<ServerAnimationManager>("AnimationManager",
|
||||
"define", &ServerAnimationManager::define,
|
||||
"set_anim", &ServerAnimationManager::set_anim,
|
||||
"play", &ServerAnimationManager::play,
|
||||
"pause", &ServerAnimationManager::pause
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,16 +10,32 @@
|
|||
#include "SubgameUsertype.h"
|
||||
|
||||
namespace Api::Usertype {
|
||||
class AnimationManager : public SubgameUsertype {
|
||||
class AnimationManager : public SubgameUsertype {
|
||||
public:
|
||||
AnimationManager(EntityPtr entity);
|
||||
|
||||
EntityPtr entity;
|
||||
|
||||
AnimationManager& define(sol::table anims);
|
||||
AnimationManager& set_anim(sol::object anim, sol::optional<bool> loop);
|
||||
AnimationManager& play(sol::optional<unsigned int> offset);
|
||||
AnimationManager& pause(sol::optional<unsigned int> offset);
|
||||
virtual AnimationManager define(sol::table anims);
|
||||
virtual AnimationManager set_anim(sol::object anim, sol::optional<bool> loop);
|
||||
virtual AnimationManager play(sol::optional<unsigned int> offset);
|
||||
virtual AnimationManager pause(sol::optional<unsigned int> offset);
|
||||
};
|
||||
|
||||
class LocalAnimationManager : public AnimationManager {
|
||||
public:
|
||||
using AnimationManager::AnimationManager;
|
||||
|
||||
static void bind(State state, sol::state& lua, sol::table& core);
|
||||
};
|
||||
|
||||
class ServerAnimationManager : public AnimationManager {
|
||||
public:
|
||||
using AnimationManager::AnimationManager;
|
||||
|
||||
virtual AnimationManager set_anim(sol::object anim, sol::optional<bool> loop) override;
|
||||
virtual AnimationManager play(sol::optional<unsigned int> offset) override;
|
||||
virtual AnimationManager pause(sol::optional<unsigned int> offset) override;
|
||||
|
||||
static void bind(State state, sol::state& lua, sol::table& core);
|
||||
};
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "Dimension.h"
|
||||
|
||||
#include "../Lua.h"
|
||||
#include "../LuaParser.h"
|
||||
#include "../../def/gen/BiomeDef.h"
|
||||
#include "../../def/item/BlockDef.h"
|
||||
#include "../../def/ServerSubgame.h"
|
||||
|
@ -14,6 +13,10 @@
|
|||
#include "../../game/entity/LocalLuaEntity.h"
|
||||
#include "../../net/server/world/ServerLuaEntity.h"
|
||||
|
||||
std::string Api::Usertype::Dimension::get_identifier() {
|
||||
return dim->getIdentifier();
|
||||
}
|
||||
|
||||
std::string Api::Usertype::Dimension::get_block(glm::ivec3 pos) {
|
||||
return dim->getGame()->getDefs().fromId(dim->getBlock(pos)).identifier;
|
||||
}
|
||||
|
@ -157,6 +160,9 @@ void Api::Usertype::Dimension::remove_entity_s(sol::this_state s, sol::table ent
|
|||
|
||||
void Api::Usertype::Dimension::bind(State state, sol::state &lua, sol::table &core) {
|
||||
lua.new_usertype<Dimension>("LocalDimension",
|
||||
"identifier", sol::property(&Dimension::get_identifier),
|
||||
"get_identifier", &Dimension::get_identifier,
|
||||
|
||||
"get_block", &Dimension::get_block,
|
||||
"set_block", &Dimension::set_block,
|
||||
"remove_block", &Dimension::remove_block,
|
||||
|
@ -171,4 +177,4 @@ void Api::Usertype::Dimension::bind(State state, sol::state &lua, sol::table &co
|
|||
"add_entity", (state == State::CLIENT ? &Dimension::add_entity_c : &Dimension::add_entity_s),
|
||||
"remove_entity", (state == State::CLIENT ? &Dimension::remove_entity_c : &Dimension::remove_entity_s)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -19,6 +19,8 @@ namespace Api::Usertype {
|
|||
|
||||
DimensionPtr dim;
|
||||
|
||||
std::string get_identifier();
|
||||
|
||||
std::string get_block(glm::ivec3 pos);
|
||||
void set_block(glm::ivec3 pos, const std::string& block);
|
||||
void remove_block(glm::ivec3 pos);
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
#include "../../game/scene/world/World.h"
|
||||
#include "../../net/server/world/ServerLuaEntity.h"
|
||||
|
||||
sol::object Api::Usertype::Entity::get_animation_manager(sol::this_state s) {
|
||||
if (entity.isL()) return sol::make_object(s, std::static_pointer_cast<LocalAnimationManager>(animation));
|
||||
else return sol::make_object(s, std::static_pointer_cast<ServerAnimationManager>(animation));
|
||||
}
|
||||
|
||||
unsigned int Api::Usertype::Entity::get_id() {
|
||||
return entity->getId();
|
||||
}
|
||||
|
@ -141,6 +146,6 @@ void Api::Usertype::Entity::bind(State, sol::state &lua, sol::table &core) {
|
|||
"scale", sol::property(&Entity::get_scale, &Entity::set_scale),
|
||||
"dim", sol::property(&Entity::get_dimension),
|
||||
|
||||
"anims", sol::readonly(&Entity::animation)
|
||||
"anims", sol::property(&Entity::get_animation_manager)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -11,14 +11,19 @@
|
|||
#include "Dimension.h"
|
||||
#include "AnimationManager.h"
|
||||
#include "../../util/CovariantPtr.h"
|
||||
#include "../../game/entity/LocalLuaEntity.h"
|
||||
|
||||
namespace Api::Usertype {
|
||||
class Entity : public SubgameUsertype {
|
||||
public:
|
||||
Entity(EntityPtr entity) : entity(entity), animation(entity) {}
|
||||
Entity(EntityPtr entity) : entity(entity), animation(entity.isL() ?
|
||||
std::static_pointer_cast<AnimationManager>(std::make_shared<LocalAnimationManager>(entity)) :
|
||||
std::static_pointer_cast<AnimationManager>(std::make_shared<ServerAnimationManager>(entity))) {}
|
||||
|
||||
EntityPtr entity;
|
||||
AnimationManager animation;
|
||||
std::shared_ptr<AnimationManager> animation;
|
||||
|
||||
sol::object get_animation_manager(sol::this_state s);
|
||||
|
||||
unsigned int get_id();
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ std::unique_ptr<std::vector<ServerGenStream::FinishedJob>> ServerGenStream::upda
|
|||
j.pos = glm::ivec3(pos);
|
||||
j.dim = pos.w;
|
||||
j.locked = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "ServerLuaEntity.h"
|
||||
|
||||
#include "../../Serializer.h"
|
||||
#include "../../../util/Util.h"
|
||||
|
||||
void ServerLuaEntity::setPos(glm::vec3 position) {
|
||||
Entity::setPos(position);
|
||||
|
@ -60,18 +61,25 @@ void ServerLuaEntity::setAppearance(const std::string& dMode, const std::string&
|
|||
dirtyFields.emplace(NetField::DISPLAY);
|
||||
}
|
||||
|
||||
std::optional<std::string> ServerLuaEntity::serialize() {
|
||||
void ServerLuaEntity::dirtyField(NetField field) {
|
||||
dirtyFields.emplace(field);
|
||||
}
|
||||
|
||||
std::string ServerLuaEntity::serialize() {
|
||||
if (dirtyFields.empty() && !fullSend) return {};
|
||||
|
||||
Serializer s;
|
||||
s.append(id);
|
||||
s.append<unsigned int>(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::ANIM_STATE) || fullSend) s.appendE(NetField::ANIM_STATE).append<bool>(animation.isPlaying());
|
||||
if (dirtyFields.count(NetField::DISPLAY) || fullSend) s.appendE(NetField::DISPLAY) .append(dMode).append(dArgA).append(dArgB);
|
||||
if (dirtyFields.count(NetField::ANIM_RANGE) || fullSend) s.appendE(NetField::ANIM_RANGE)
|
||||
.append<unsigned int>(animation.getBounds().x).append<unsigned int>(animation.getBounds().y).append<bool>(animation.isLooping());
|
||||
|
||||
dirtyFields.clear();
|
||||
fullSend = false;
|
||||
|
|
|
@ -17,8 +17,7 @@ class ServerLuaEntity : public LuaEntity {
|
|||
public:
|
||||
explicit ServerLuaEntity(SubgamePtr game, DimensionPtr dim, unsigned int id) :
|
||||
LuaEntity(game, dim), Entity(game, dim) {
|
||||
setId(id);
|
||||
};
|
||||
setId(id); };
|
||||
|
||||
virtual void setPos(glm::vec3 position) override;
|
||||
virtual void setVel(glm::vec3 vel) override;
|
||||
|
@ -31,8 +30,9 @@ public:
|
|||
virtual void setVisualOffset(glm::vec3 vs) override;
|
||||
|
||||
void setAppearance(const std::string& dMode, const std::string& argA, const std::string& argB) override;
|
||||
void dirtyField(NetField field);
|
||||
|
||||
std::optional<std::string> serialize();
|
||||
std::string serialize();
|
||||
protected:
|
||||
std::string dMode = "";
|
||||
std::string dArgA = "";
|
||||
|
|
|
@ -136,8 +136,8 @@ void ServerWorld::update(double delta) {
|
|||
inf.append(ind);
|
||||
|
||||
for (auto& entity : dimension->getLuaEntities()) {
|
||||
auto opt = entity.entity.s()->serialize();
|
||||
if (opt) inf.append(*opt);
|
||||
auto str = entity.entity.s()->serialize();
|
||||
if (!str.empty()) inf.append(str);
|
||||
}
|
||||
|
||||
if (inf.data.size() > 4) {
|
||||
|
@ -186,6 +186,10 @@ InventoryRefsPtr ServerWorld::getRefs() {
|
|||
return InventoryRefsPtr(refs);
|
||||
}
|
||||
|
||||
ServerClients& ServerWorld::getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
void ServerWorld::changedMapBlocks(ServerPlayer& player) {
|
||||
generateMapBlocks(player);
|
||||
sendChunksToPlayer(player);
|
||||
|
@ -238,4 +242,4 @@ bool ServerWorld::isInBounds(glm::ivec3 cPos, std::pair<glm::ivec3, glm::ivec3>
|
|||
return (cPos.x >= bounds.first.x && cPos.x <= bounds.second.x
|
||||
&& cPos.y >= bounds.first.y && cPos.y <= bounds.second.y
|
||||
&& cPos.z >= bounds.first.z && cPos.z <= bounds.second.z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
virtual DimensionPtr getDimension(const std::string& identifier) override;
|
||||
|
||||
virtual InventoryRefsPtr getRefs() override;
|
||||
virtual ServerClients& getClients();
|
||||
private:
|
||||
void changedMapBlocks(ServerPlayer& player);
|
||||
static bool isInBounds(glm::ivec3 pos, std::pair<glm::ivec3, glm::ivec3>& bounds);
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "../lua/usertype/Player.h"
|
||||
#include "../world/chunk/MapBlock.h"
|
||||
#include "../game/scene/world/NetField.h"
|
||||
#include "../game/entity/LocalLuaEntity.h"
|
||||
#include "../game/scene/world/LocalWorld.h"
|
||||
#include "../game/scene/world/MeshGenStream.h"
|
||||
#include "../game/scene/world/graph/MeshChunk.h"
|
||||
|
@ -164,33 +163,40 @@ void LocalDimension::removeLocalEntity(Api::Usertype::Entity entity) {
|
|||
localEntityRefs.erase(id);
|
||||
}
|
||||
|
||||
void LocalDimension::serverEntitiesInfo(Deserializer& d) {
|
||||
void LocalDimension::serverEntitiesInfo(Deserializer& e) {
|
||||
bool boolean;
|
||||
unsigned int x, y;
|
||||
std::string type, a, b;
|
||||
d.read<unsigned int>();
|
||||
|
||||
std::shared_ptr<LocalLuaEntity> activeEntity = nullptr;
|
||||
e.read<unsigned int>();
|
||||
|
||||
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 {
|
||||
auto ent = std::make_shared<LocalLuaEntity>(game, world.getDimension(getInd()));
|
||||
auto entity = Api::Usertype::Entity(ent);
|
||||
ent->setId(id);
|
||||
serverEntities.push_back(entity);
|
||||
serverEntityRefs.emplace(id, --serverEntities.end());
|
||||
activeEntity = ent;
|
||||
}
|
||||
break; }
|
||||
while (!e.atEnd()) {
|
||||
std::string dat = e.read<std::string>();
|
||||
Deserializer d(dat);
|
||||
|
||||
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: d.read(type).read(a).read(b); activeEntity->setAppearance(type, a, b); break;
|
||||
unsigned int id = d.read<unsigned int>();
|
||||
std::shared_ptr<LocalLuaEntity> activeEntity;
|
||||
if (serverEntityRefs.count(id)) activeEntity = serverEntityRefs.at(id)->entity.l();
|
||||
else {
|
||||
auto ent = std::make_shared<LocalLuaEntity>(game, world.getDimension(getInd()));
|
||||
auto entity = Api::Usertype::Entity(ent);
|
||||
ent->setId(id);
|
||||
serverEntities.push_back(entity);
|
||||
serverEntityRefs.emplace(id, --serverEntities.end());
|
||||
activeEntity = ent;
|
||||
}
|
||||
|
||||
while (!d.atEnd()) {
|
||||
switch (d.readE<NetField>()) {
|
||||
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::ANIM_STATE: d.read(boolean); activeEntity->animation.setPlaying(boolean); break;
|
||||
case NetField::DISPLAY: d.read(type).read(a).read(b); activeEntity->setAppearance(type, a, b); break;
|
||||
case NetField::ANIM_RANGE: d.read(x).read(y).read(boolean); activeEntity->animation.setAnim(glm::ivec2 {x, y}, 10, boolean); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,36 +11,38 @@
|
|||
#include "../def/ServerSubgame.h"
|
||||
#include "../lua/usertype/Player.h"
|
||||
#include "../lua/usertype/Target.h"
|
||||
#include "../lua/usertype/ItemStack.h"
|
||||
#include "../net/server/conn/ServerPlayer.h"
|
||||
#include "../net/server/world/ServerWorld.h"
|
||||
#include "../net/server/conn/ServerClients.h"
|
||||
#include "../net/server/world/ServerLuaEntity.h"
|
||||
|
||||
ServerDimension::ServerDimension(SubgamePtr game, ServerWorld& world, const std::string& identifier, unsigned int ind) :
|
||||
Dimension(game, static_cast<World&>(world), identifier, ind) {}
|
||||
|
||||
void ServerDimension::update(double delta) {
|
||||
//TODO: Thiss
|
||||
// for (const auto& region : regions) {
|
||||
// for (unsigned short i = 0; i < 64; i++) {
|
||||
// if (region.second->operator[](i) == nullptr) continue;
|
||||
// const auto& mapBlockPos = region.second->operator[](i)->pos;
|
||||
//
|
||||
// bool clientNearby = false;
|
||||
// for (auto& player : players) {
|
||||
// if (player->getDimension().getInd() == ind) {
|
||||
// auto clientPos = Space::MapBlock::world::fromBlock(player->getPos());
|
||||
// if (abs(clientPos.x - mapBlockPos.x) <= discardRange.x + 1
|
||||
// && abs(clientPos.y - mapBlockPos.y) <= discardRange.y + 1
|
||||
// && abs(clientPos.z - mapBlockPos.z) <= discardRange.x + 1) {
|
||||
// clientNearby = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!clientNearby) region.second->remove(i);
|
||||
// }
|
||||
// }
|
||||
for (auto& entity : luaEntities) entity.entity.s()->update(delta);
|
||||
|
||||
for (const auto& region : regions) {
|
||||
for (unsigned short i = 0; i < 64; i++) {
|
||||
auto mb = region.second->get(i);
|
||||
if (!mb) continue;
|
||||
|
||||
bool clientNearby = false;
|
||||
for (auto& player : static_cast<ServerWorld&>(world).getClients().players) {
|
||||
if (player->getDim()->getInd() == ind) {
|
||||
auto clientPos = Space::MapBlock::world::fromBlock(player->getPos());
|
||||
if (abs(clientPos.x - mb->pos.x) <= discardRange.x + 1
|
||||
&& abs(clientPos.y - mb->pos.y) <= discardRange.y + 1
|
||||
&& abs(clientPos.z - mb->pos.z) <= discardRange.x + 1) {
|
||||
clientNearby = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!clientNearby) region.second->remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double ServerDimension::blockHit(const Target &target, PlayerPtr player) {
|
||||
|
|
|
@ -30,12 +30,9 @@ public:
|
|||
void addLuaEntity(Api::Usertype::Entity entity);
|
||||
void removeLuaEntity(Api::Usertype::Entity entity);
|
||||
|
||||
// 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<Api::Usertype::Entity>::iterator luaent_ref;
|
||||
|
||||
|
@ -43,6 +40,6 @@ private:
|
|||
std::list<Api::Usertype::Entity> luaEntities {};
|
||||
std::list<unsigned int> removedEntities {};
|
||||
|
||||
// std::unordered_map<glm::ivec3, unsigned long long, Vec::ivec3> mapBlockIntegrity {};
|
||||
const glm::ivec2 discardRange = {20, 20};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ zepha.register_entity("zeus:default:test", {
|
|||
self.object.anims:define({
|
||||
walk = {0, 300}
|
||||
})
|
||||
self.object.anims:set_anim("walk"):play()
|
||||
-- self.object.scale = 1/4
|
||||
self.object.anims:set_anim("walk")
|
||||
self.object.anims:play()
|
||||
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 = 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
|
||||
})
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local identifier = "zeus:world:desert"
|
||||
|
||||
local noise = {
|
||||
heightmap = {
|
||||
module = "add",
|
||||
|
@ -28,7 +30,7 @@ local noise = {
|
|||
}
|
||||
}
|
||||
|
||||
zepha.register_biome("zeus:world:desert", {
|
||||
zepha.register_biome(identifier, {
|
||||
environment = {
|
||||
temperature = 40/100,
|
||||
humidity = 20/100,
|
||||
|
@ -41,4 +43,6 @@ zepha.register_biome("zeus:world:desert", {
|
|||
},
|
||||
biome_tint = "#e6fa61",
|
||||
noise = noise
|
||||
})
|
||||
})
|
||||
|
||||
return identifier;
|
|
@ -1,3 +1,5 @@
|
|||
local identifier = "zeus:world:forest"
|
||||
|
||||
local noise = {
|
||||
heightmap = {
|
||||
module = "add",
|
||||
|
@ -108,7 +110,7 @@ local tree = zepha.create_structure({
|
|||
}
|
||||
})
|
||||
|
||||
zepha.register_biome("zeus:world:forest", {
|
||||
zepha.register_biome(identifier, {
|
||||
environment = {
|
||||
temperature = 15/100,
|
||||
humidity = 80/100,
|
||||
|
@ -124,4 +126,6 @@ zepha.register_biome("zeus:world:forest", {
|
|||
structures = {
|
||||
tree
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return identifier
|
|
@ -1,3 +1,5 @@
|
|||
local identifier = "zeus:world:highlands"
|
||||
|
||||
-- local woo = "zeus:default:wood"
|
||||
-- local lea = "zeus:default:leaves"
|
||||
-- local inv = "invalid"
|
||||
|
@ -75,7 +77,7 @@ local noise = {
|
|||
}
|
||||
}
|
||||
|
||||
zepha.register_biome("zeus:world:highlands", {
|
||||
zepha.register_biome(identifier, {
|
||||
environment = {
|
||||
temperature = 0/100,
|
||||
humidity = 0/100,
|
||||
|
@ -91,4 +93,6 @@ zepha.register_biome("zeus:world:highlands", {
|
|||
structures = {
|
||||
shrub
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return identifier
|
|
@ -1,4 +0,0 @@
|
|||
runfile(_PATH .. "plains")
|
||||
runfile(_PATH .. "highlands")
|
||||
runfile(_PATH .. "desert")
|
||||
runfile(_PATH .. "forest")
|
|
@ -1,3 +1,5 @@
|
|||
local identifier = "zeus:world:plains"
|
||||
|
||||
local noise = {
|
||||
heightmap = {
|
||||
module = "add",
|
||||
|
@ -31,7 +33,7 @@ local noise = {
|
|||
}
|
||||
}
|
||||
|
||||
zepha.register_biome("zeus:world:plains", {
|
||||
zepha.register_biome(identifier, {
|
||||
environment = {
|
||||
temperature = 15/100,
|
||||
humidity = 60/100,
|
||||
|
@ -42,9 +44,12 @@ zepha.register_biome("zeus:world:plains", {
|
|||
soil = "zeus:default:dirt",
|
||||
rock = "zeus:default:stone"
|
||||
},
|
||||
groups = { natural = 1 },
|
||||
biome_tint = "#aaed45",
|
||||
noise = noise,
|
||||
structures = {
|
||||
tree
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return identifier
|
|
@ -1,20 +0,0 @@
|
|||
zepha.create_dimension("zeus:default")
|
||||
zepha.set_default_dimension("zeus:default")
|
||||
|
||||
zepha.create_dimension("zeus:second")
|
||||
|
||||
local v = false
|
||||
zepha.register_keybind("zeus:world:go_to_hell", {
|
||||
default = zepha.keys.enter,
|
||||
on_press = function()
|
||||
print("Here we go again")
|
||||
|
||||
if not v then
|
||||
zepha.player:set_dimension("zeus:second")
|
||||
v = true
|
||||
else
|
||||
zepha.player:set_dimension("zeus:default")
|
||||
v = false
|
||||
end
|
||||
end
|
||||
})
|
|
@ -1,2 +1,7 @@
|
|||
runfile(_PATH .. "dimension/init")
|
||||
runfile(_PATH .. "biomes/init")
|
||||
runfile(_PATH.."register_biomes")
|
||||
|
||||
local dim = zepha.create_dimension("zeus:world:default", { biomes = { "#natural" } })
|
||||
-- zepha.set_default_dimension(dim.identifier)
|
||||
|
||||
zepha.create_dimension("zeus:world:endless_desert", { biomes = { "zeus:world:desert" } })
|
||||
zepha.set_default_dimension("zeus:world:endless_desert")
|
|
@ -0,0 +1,6 @@
|
|||
return {
|
||||
runfile(_PATH.."biomes/plains"),
|
||||
runfile(_PATH.."biomes/highlands"),
|
||||
runfile(_PATH.."biomes/desert"),
|
||||
runfile(_PATH.."biomes/forest")
|
||||
}
|
Loading…
Reference in New Issue