Make PlayerEntities use the Player model.
parent
be60f1ed4d
commit
098e5ff86d
|
@ -1,29 +0,0 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" fileNamingConvention="NONE" />
|
||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
</code_scheme>
|
||||
</component>
|
|
@ -1,6 +1,9 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="false">
|
||||
<option name="clangTidyChecks" value="*,-android-*,-bugprone-bool-pointer-implicit-conversion,-cert-env33-c,-cert-dcl50-cpp,-cert-dcl59-cpp,-cppcoreguidelines-no-malloc,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-special-member-functions,-fuchsia-*,-google-*,google-default-arguments,google-explicit-constructor,google-runtime-member-string-references,google-runtime-operator,-hicpp-braces-around-statements,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-no-malloc,-hicpp-function-size,-hicpp-special-member-functions,-hicpp-vararg,-llvm-*,-objc-*,-readability-else-after-return,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-simplify-boolean-expr,-readability-braces-around-statements,-readability-identifier-naming,-readability-function-size,-readability-redundant-member-init,-misc-bool-pointer-implicit-conversion,-misc-definitions-in-headers,-misc-unused-alias-decls,-misc-unused-parameters,-misc-unused-using-decls,-modernize-use-using,-modernize-use-default-member-init,-clang-diagnostic-*,-clang-analyzer-*,-cert-msc30-c,-cert-msc50-cpp,-bugprone-integer-division,-modernize-use-auto,-hicpp-uppercase-literal-suffix" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ClangTidyInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="clangTidyChecks" value="*,-android-*,-bugprone-bool-pointer-implicit-conversion,-cert-env33-c,-cert-dcl50-cpp,-cert-dcl59-cpp,-cppcoreguidelines-no-malloc,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-special-member-functions,-fuchsia-*,-google-*,google-default-arguments,google-explicit-constructor,google-runtime-member-string-references,google-runtime-operator,-hicpp-braces-around-statements,-hicpp-named-parameter,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-no-malloc,-hicpp-function-size,-hicpp-special-member-functions,-hicpp-vararg,-llvm-*,-objc-*,-readability-else-after-return,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-simplify-boolean-expr,-readability-braces-around-statements,-readability-identifier-naming,-readability-function-size,-readability-redundant-member-init,-misc-bool-pointer-implicit-conversion,-misc-definitions-in-headers,-misc-unused-alias-decls,-misc-unused-parameters,-misc-unused-using-decls,-modernize-use-using,-modernize-use-default-member-init,-clang-diagnostic-*,-clang-analyzer-*,-cert-msc30-c,-cert-msc50-cpp,-bugprone-integer-division,-modernize-use-auto" />
|
||||
</inspection_tool>
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
})
|
|
@ -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
|
||||
})
|
||||
})
|
||||
|
|
|
@ -21,7 +21,7 @@ void Entity::setModel(std::shared_ptr<Model> 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<float>(fmin(delta * 8, 1));
|
||||
|
||||
|
|
|
@ -4,48 +4,9 @@
|
|||
|
||||
#include "PlayerEntity.h"
|
||||
|
||||
PlayerEntity::PlayerEntity(glm::vec3 pos, int peer_id, std::shared_ptr<AtlasRef> playerFrontTex, std::shared_ptr<AtlasRef> playerBackTex, std::shared_ptr<AtlasRef> 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<Model>& playerModel) :
|
||||
peer_id(peer_id) {
|
||||
|
||||
this->model = std::make_shared<Model>();
|
||||
|
||||
auto fUV = this->playerFrontTex->uv;
|
||||
auto bUV = this->playerBackTex->uv;
|
||||
auto sUV = this->shadowTex->uv;
|
||||
|
||||
std::vector<EntityVertex> 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<unsigned int> 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<EntityMesh> mesh = std::make_unique<EntityMesh>();
|
||||
mesh->create(vertices, indices);
|
||||
this->model->fromMesh(std::move(mesh));
|
||||
this->setPos(pos);
|
||||
setModel(playerModel);
|
||||
setPos(pos);
|
||||
}
|
|
@ -10,9 +10,6 @@
|
|||
|
||||
class PlayerEntity : public Entity {
|
||||
public:
|
||||
PlayerEntity(glm::vec3 pos, int peer_id, std::shared_ptr<AtlasRef> playerFrontTex, std::shared_ptr<AtlasRef> playerBackTex, std::shared_ptr<AtlasRef> shadowTex);
|
||||
|
||||
PlayerEntity(glm::vec3 pos, int peer_id, const std::shared_ptr<Model>& playerModel);
|
||||
int peer_id;
|
||||
private:
|
||||
std::shared_ptr<AtlasRef> playerFrontTex, playerBackTex, shadowTex;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,23 +6,18 @@
|
|||
|
||||
ClientNetworkInterpreter::ClientNetworkInterpreter(ServerConnection &connection, LocalDefs &defs) :
|
||||
connection(connection),
|
||||
entities(new DrawableGroup()),
|
||||
world(nullptr),
|
||||
playerModel(std::make_shared<Model>()){
|
||||
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<Drawable *> &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<PlayerEntity*>(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<uint>(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);
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
ClientNetworkInterpreter(ServerConnection& connection, LocalDefs& defs);
|
||||
ClientNetworkInterpreter(const ClientNetworkInterpreter& other) = default;
|
||||
|
||||
void init(std::vector<Drawable*> &entities, LocalWorld* world);
|
||||
void init(LocalWorld* world);
|
||||
void update(Player &player);
|
||||
void cleanup();
|
||||
|
||||
|
@ -38,8 +38,8 @@ private:
|
|||
std::shared_ptr<AtlasRef> playerFrontTex, playerBackTex, shadowTex;
|
||||
int id = 0;
|
||||
|
||||
DrawableGroup* entities = nullptr;
|
||||
LocalWorld* world = nullptr;
|
||||
ServerConnection& connection;
|
||||
sptr<Model> playerModel;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<BlockCrackEntity*> crackedBlocks;
|
||||
|
|
|
@ -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<BlockChunk> chunk) {
|
||||
|
|
|
@ -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<BlockChunk> getChunk(glm::vec3 pos);
|
||||
|
||||
int lastMeshUpdates = 0;
|
||||
std::vector<PlayerEntity> playerEntities;
|
||||
private:
|
||||
typedef std::unordered_map<glm::vec3, std::shared_ptr<BlockChunk>, VecUtils::compareFunc> block_chunk_map;
|
||||
typedef std::list<sptr<ChunkRenderElem>>::iterator chunk_ref;
|
||||
|
|
Loading…
Reference in New Issue