From 098e5ff86d3ee7819063606236508a5574b892ec Mon Sep 17 00:00:00 2001
From: Nicole Collings <100Toby1@gmail.com>
Date: Sat, 19 Oct 2019 14:03:07 -0700
Subject: [PATCH] Make PlayerEntities use the Player model.
---
.idea/codeStyles/Project.xml | 29 ------------
.idea/inspectionProfiles/Project_Default.xml | 3 ++
mods/default/script/blocks/_index.lua | 1 -
mods/default/script/blocks/open_formspec.lua | 33 -------------
mods/default/script/main.lua | 44 ++++++++++++++++-
src/game/entity/Entity.cpp | 2 +-
src/game/entity/world/PlayerEntity.cpp | 47 ++-----------------
src/game/entity/world/PlayerEntity.h | 5 +-
src/game/scene/GameScene.cpp | 4 +-
.../scene/net/ClientNetworkInterpreter.cpp | 34 +++++---------
src/game/scene/net/ClientNetworkInterpreter.h | 4 +-
src/game/scene/world/LocalWorld.h | 2 +-
src/world/LocalDimension.cpp | 10 ++--
src/world/LocalDimension.h | 2 +
14 files changed, 72 insertions(+), 148 deletions(-)
delete mode 100644 .idea/codeStyles/Project.xml
delete mode 100644 mods/default/script/blocks/open_formspec.lua
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 30aa626c..00000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 34efcd8c..d77dc4f0 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -1,6 +1,9 @@
+
+
+
diff --git a/mods/default/script/blocks/_index.lua b/mods/default/script/blocks/_index.lua
index 56470327..53daa3a5 100644
--- a/mods/default/script/blocks/_index.lua
+++ b/mods/default/script/blocks/_index.lua
@@ -3,7 +3,6 @@ runfile(_PATH .. "cobblestone")
runfile(_PATH .. "dirt")
runfile(_PATH .. "grass")
runfile(_PATH .. "leaves")
-runfile(_PATH .. "open_formspec")
runfile(_PATH .. "sand")
runfile(_PATH .. "sandstone")
runfile(_PATH .. "stone")
diff --git a/mods/default/script/blocks/open_formspec.lua b/mods/default/script/blocks/open_formspec.lua
deleted file mode 100644
index d405d434..00000000
--- a/mods/default/script/blocks/open_formspec.lua
+++ /dev/null
@@ -1,33 +0,0 @@
-zepha.register_block("default:open_formspec", {
- name = "Open Formspec Block",
- model = "default:block",
- textures = {"zeus:default:brick"},
- on_place_client = function()
- zepha.show_menu({
- key = "form_root",
- type = "rect",
-
- size = "1920px, 1080px",
- background = "#0004",
-
- children = {
- {
- key = "inv_root",
- type = "rect",
-
- position = "202px, 138px",
- size = "236px, 118px",
- padding = "20px, 10px, 8px, 10px",
- background = "inventory"
- }, {
- key = "hotwheel_root",
- type = "rect",
-
- position = "296px, 268px",
- size = "52px, 52px",
- background = "inventory_wheel"
- }
- }
- });
- end
-})
\ No newline at end of file
diff --git a/mods/default/script/main.lua b/mods/default/script/main.lua
index d7cad2f0..0de3dcd9 100644
--- a/mods/default/script/main.lua
+++ b/mods/default/script/main.lua
@@ -8,7 +8,47 @@ zepha.register_keybind("open_inventory", {
description = "Open Inventory",
default = zepha.keys.e,
on_press = function()
- print("Inventory Toggle")
+ zepha.show_menu({
+ key = "form_root",
+ type = "rect",
+
+ size = "1920px, 1080px",
+ background = "#0004",
+
+ children = {{
+ key = "inv_root",
+ type = "rect",
+
+ position = "202px, 138px",
+ size = "236px, 118px",
+ padding = "20px, 10px, 8px, 10px",
+ background = "inventory"
+ }, {
+ key = "hotwheel_root",
+ type = "rect",
+
+ position = "296px, 268px",
+ size = "52px, 52px",
+ background = "inventory_wheel"
+ } }
+ });
+
+ zepha.show_menu([[
+ rect[form_root]
+ size=1920px 1080px
+ background=#0004
+
+ rect[inv_root]
+ position=202px 138px
+ size=236px 138px
+ padding=20px 10px 8px 10px
+ background=img("inventory")
+
+ rect[hotwheel_root]
+ position=296px 268px
+ size=52px 52px
+ background=img("inventory_wheel")
+ ]]);
end
})
@@ -18,4 +58,4 @@ zepha.register_keybind("open_chat", {
on_press = function()
print("Chat Toggle")
end
-})
\ No newline at end of file
+})
diff --git a/src/game/entity/Entity.cpp b/src/game/entity/Entity.cpp
index 8453894b..e16e1cf5 100644
--- a/src/game/entity/Entity.cpp
+++ b/src/game/entity/Entity.cpp
@@ -21,7 +21,7 @@ void Entity::setModel(std::shared_ptr model) {
void Entity::update(double delta) {
animState.update(delta);
- if (animState.getFrame() > 394) animState.setFrame(302);
+ if (animState.getFrame() > 390) animState.setFrame(302);
float factor = static_cast(fmin(delta * 8, 1));
diff --git a/src/game/entity/world/PlayerEntity.cpp b/src/game/entity/world/PlayerEntity.cpp
index 3c16169e..8c95e255 100644
--- a/src/game/entity/world/PlayerEntity.cpp
+++ b/src/game/entity/world/PlayerEntity.cpp
@@ -4,48 +4,9 @@
#include "PlayerEntity.h"
-PlayerEntity::PlayerEntity(glm::vec3 pos, int peer_id, std::shared_ptr playerFrontTex, std::shared_ptr playerBackTex, std::shared_ptr shadowTex) :
- peer_id(peer_id),
- playerFrontTex(std::move(playerFrontTex)),
- playerBackTex(std::move(playerBackTex)),
- shadowTex(std::move(shadowTex)) {
+PlayerEntity::PlayerEntity(glm::vec3 pos, int peer_id, const std::shared_ptr& playerModel) :
+ peer_id(peer_id) {
- this->model = std::make_shared();
-
- auto fUV = this->playerFrontTex->uv;
- auto bUV = this->playerBackTex->uv;
- auto sUV = this->shadowTex->uv;
-
- std::vector vertices {
- //Front
- {{0.001, 2, -0.5}, {fUV.x, fUV.y, 0, 0}, {1, 1, 1}, true, {1, 0, 0}},
- {{0.001, 0, -0.5}, {fUV.x, fUV.w, 0, 0}, {1, 1, 1}, true, {1, 0, 0}},
- {{0.001, 0, 0.5}, {fUV.z, fUV.w, 0, 0}, {1, 1, 1}, true, {1, 0, 0}},
- {{0.001, 2, 0.5}, {fUV.z, fUV.y, 0, 0}, {1, 1, 1}, true, {1, 0, 0}},
- //Back
- {{-0.001, 2, -0.5}, {bUV.x, bUV.y, 0, 0}, {1, 1, 1}, true, {-1, 0, 0}},
- {{-0.001, 0, -0.5}, {bUV.x, bUV.w, 0, 0}, {1, 1, 1}, true, {-1, 0, 0}},
- {{-0.001, 0, 0.5}, {bUV.z, bUV.w, 0, 0}, {1, 1, 1}, true, {-1, 0, 0}},
- {{-0.001, 2, 0.5}, {bUV.z, bUV.y, 0, 0}, {1, 1, 1}, true, {-1, 0, 0}},
- //Shadow
- {{-0.5, 0, -0.5}, {sUV.x, sUV.y, 0, 0}, {1, 1, 1}, true, {0, 1, 0}},
- {{-0.5, 0, 0.5}, {sUV.x, sUV.w, 0, 0}, {1, 1, 1}, true, {0, 1, 0}},
- {{ 0.5, 0, 0.5}, {sUV.z, sUV.w, 0, 0}, {1, 1, 1}, true, {0, 1, 0}},
- {{ 0.5, 0, -0.5}, {sUV.z, sUV.y, 0, 0}, {1, 1, 1}, true, {0, 1, 0}},
- };
- std::vector indices {
- 0, 1, 2, 2, 3, 0,
- 0, 2, 1, 2, 0, 3,
-
- 4, 5, 6, 6, 7, 4,
- 4, 6, 5, 6, 4, 7,
-
- 8, 9, 10, 10, 11, 8,
- 8, 10, 9, 10, 8, 11,
- };
-
- uptr mesh = std::make_unique();
- mesh->create(vertices, indices);
- this->model->fromMesh(std::move(mesh));
- this->setPos(pos);
+ setModel(playerModel);
+ setPos(pos);
}
\ No newline at end of file
diff --git a/src/game/entity/world/PlayerEntity.h b/src/game/entity/world/PlayerEntity.h
index 0b8ae224..9e936128 100644
--- a/src/game/entity/world/PlayerEntity.h
+++ b/src/game/entity/world/PlayerEntity.h
@@ -10,9 +10,6 @@
class PlayerEntity : public Entity {
public:
- PlayerEntity(glm::vec3 pos, int peer_id, std::shared_ptr playerFrontTex, std::shared_ptr playerBackTex, std::shared_ptr shadowTex);
-
+ PlayerEntity(glm::vec3 pos, int peer_id, const std::shared_ptr& playerModel);
int peer_id;
-private:
- std::shared_ptr playerFrontTex, playerBackTex, shadowTex;
};
diff --git a/src/game/scene/GameScene.cpp b/src/game/scene/GameScene.cpp
index 82babdcc..abc99322 100644
--- a/src/game/scene/GameScene.cpp
+++ b/src/game/scene/GameScene.cpp
@@ -25,10 +25,8 @@ GameScene::GameScene(ClientState& state) : Scene(state),
gui.push_back(&debugGui);
debugGui.initItemDisplays(defs);
-
entities.push_back(&player);
-
- server.init(entities, &world);
+ server.init(&world);
Packet r(PacketType::CONNECT_DATA_RECVD);
r.sendTo(state.connection.getPeer(), PacketChannel::CONNECT);
diff --git a/src/game/scene/net/ClientNetworkInterpreter.cpp b/src/game/scene/net/ClientNetworkInterpreter.cpp
index 59034c0d..dc60d2ce 100644
--- a/src/game/scene/net/ClientNetworkInterpreter.cpp
+++ b/src/game/scene/net/ClientNetworkInterpreter.cpp
@@ -6,23 +6,18 @@
ClientNetworkInterpreter::ClientNetworkInterpreter(ServerConnection &connection, LocalDefs &defs) :
connection(connection),
- entities(new DrawableGroup()),
world(nullptr),
+ playerModel(std::make_shared()){
+ playerModel->fromSerialized(defs.models().models["zeus:default:player"], {defs.textures().getTextureRef("zeus:default:player")});
+}
- playerFrontTex(defs.textures().getTextureRef("player_front")),
- playerBackTex(defs.textures().getTextureRef("player_back")),
- shadowTex(defs.textures().getTextureRef("player_shadow")) {}
-
-void ClientNetworkInterpreter::init(std::vector &entities, LocalWorld *world) {
- entities.push_back(this->entities);
+void ClientNetworkInterpreter::init(LocalWorld *world) {
this->world = world;
}
void ClientNetworkInterpreter::update(Player &player) {
recvPackets = 0;
-// enet_peer_ping(connection.getPeer());
-
ENetEvent event;
while (connection.pollEvents(&event)) {
recvPackets++;
@@ -52,27 +47,20 @@ void ClientNetworkInterpreter::update(Player &player) {
auto playerAngle = Serializer::decodeFloat(&p.data[16]);
bool found = false;
- for (auto ent : entities->getChildren()) {
- auto playerEntity = static_cast(ent);
-
- if (playerEntity->peer_id == peer_id) {
-
- playerEntity->setPos(playerPos);
- playerEntity->setAngle(-playerAngle);
-
+ for (auto& ent : world->dimension.playerEntities) {
+ if (ent.peer_id == peer_id) {
+ ent.interpPos(playerPos);
+ ent.interpAngle(-playerAngle + 90);
found = true;
break;
}
}
-
- if (!found) {
- entities->addDrawable(new PlayerEntity(playerPos, peer_id, playerFrontTex, playerBackTex, shadowTex));
- }
+ if (!found) world->dimension.playerEntities.emplace_back(playerPos, peer_id, playerModel);
break;
}
case PacketType::BLOCK_SET: {
auto pos = Serializer::decodeIntVec3(&p.data[0]);
- auto block = Serializer::decodeInt(&p.data[12]);
+ uint block = static_cast(Serializer::decodeInt(&p.data[12]));
world->setBlock(pos, block);
break;
}
@@ -105,7 +93,7 @@ void ClientNetworkInterpreter::update(Player &player) {
//Send Player Position
Packet p(PacketType::PLAYER);
Serializer::encodeFloat(p.data, player.getPos().x);
- Serializer::encodeFloat(p.data, player.getPos().y - Player::EYE_HEIGHT);
+ Serializer::encodeFloat(p.data, player.getPos().y);
Serializer::encodeFloat(p.data, player.getPos().z);
Serializer::encodeFloat(p.data, player.getYaw());
p.sendTo(connection.getPeer(), PacketChannel::PLAYER);
diff --git a/src/game/scene/net/ClientNetworkInterpreter.h b/src/game/scene/net/ClientNetworkInterpreter.h
index 849e11c8..514ca3de 100644
--- a/src/game/scene/net/ClientNetworkInterpreter.h
+++ b/src/game/scene/net/ClientNetworkInterpreter.h
@@ -23,7 +23,7 @@ public:
ClientNetworkInterpreter(ServerConnection& connection, LocalDefs& defs);
ClientNetworkInterpreter(const ClientNetworkInterpreter& other) = default;
- void init(std::vector &entities, LocalWorld* world);
+ void init(LocalWorld* world);
void update(Player &player);
void cleanup();
@@ -38,8 +38,8 @@ private:
std::shared_ptr playerFrontTex, playerBackTex, shadowTex;
int id = 0;
- DrawableGroup* entities = nullptr;
LocalWorld* world = nullptr;
ServerConnection& connection;
+ sptr playerModel;
};
diff --git a/src/game/scene/world/LocalWorld.h b/src/game/scene/world/LocalWorld.h
index 77d657cf..d1a16d32 100644
--- a/src/game/scene/world/LocalWorld.h
+++ b/src/game/scene/world/LocalWorld.h
@@ -60,11 +60,11 @@ public:
int lastMeshUpdates = 0;
LocalDimension dimension;
+ LocalDefs& defs;
private:
void finishChunks();
void updateBlockDamages(double delta);
- LocalDefs& defs;
glm::vec3* playerPos;
std::vector crackedBlocks;
diff --git a/src/world/LocalDimension.cpp b/src/world/LocalDimension.cpp
index 080e7bd4..db58f6ef 100644
--- a/src/world/LocalDimension.cpp
+++ b/src/world/LocalDimension.cpp
@@ -10,9 +10,8 @@ void LocalDimension::update(double delta, glm::vec3 playerPos) {
finishMeshes();
queueMeshes();
- for (auto& entities : luaEntities) {
- entities->entity->update(delta);
- }
+ for (auto& entities : luaEntities) entities->entity->update(delta);
+ for (auto& playerEnt : playerEntities) playerEnt.update(delta);
auto chunkPosOfPlayer = TransPos::chunkFromVec(playerPos);
@@ -90,9 +89,8 @@ int LocalDimension::renderChunks(Renderer &renderer) {
}
void LocalDimension::renderEntities(Renderer &renderer) {
- for (auto& entity : luaEntities) {
- entity->entity->draw(renderer);
- }
+ for (auto& entity : luaEntities) entity->entity->draw(renderer);
+ for (auto& entity : playerEntities) entity.draw(renderer);
}
void LocalDimension::setChunk(sptr chunk) {
diff --git a/src/world/LocalDimension.h b/src/world/LocalDimension.h
index b9d5c275..3d276cf1 100644
--- a/src/world/LocalDimension.h
+++ b/src/world/LocalDimension.h
@@ -11,6 +11,7 @@
#include "../game/scene/world/graph/MeshChunk.h"
#include "../game/scene/world/MeshGenStream.h"
#include "../game/entity/world/LuaEntity.h"
+#include "../game/entity/world/PlayerEntity.h"
class LocalDimension {
public:
@@ -34,6 +35,7 @@ public:
std::shared_ptr getChunk(glm::vec3 pos);
int lastMeshUpdates = 0;
+ std::vector playerEntities;
private:
typedef std::unordered_map, VecUtils::compareFunc> block_chunk_map;
typedef std::list>::iterator chunk_ref;