From: Daniel Karbach Date: Mon, 12 Oct 2015 12:15:06 +0000 (+0200) Subject: composite model is the canonical model X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=eba29c8ad489194cd1e3cd64b5f23424ad4384ef;p=blank.git composite model is the canonical model --- diff --git a/src/ai/Spawner.cpp b/src/ai/Spawner.cpp index 4f28cfb..b14271f 100644 --- a/src/ai/Spawner.cpp +++ b/src/ai/Spawner.cpp @@ -2,7 +2,7 @@ #include "Chaser.hpp" #include "RandomWalk.hpp" -#include "../model/CompositeModel.hpp" +#include "../model/Model.hpp" #include "../model/Skeletons.hpp" #include "../rand/GaloisLFSR.hpp" #include "../world/BlockLookup.hpp" @@ -147,7 +147,7 @@ void Spawner::Spawn(Entity &reference, const glm::ivec3 &chunk, const glm::vec3 controllers.emplace_back(ctrl); } -CompositeModel &Spawner::RandomSkeleton() noexcept { +Model &Spawner::RandomSkeleton() noexcept { std::size_t offset = (random.Next() % skeletons_length) + skeletons_offset; return skeletons[offset]; } diff --git a/src/ai/Spawner.hpp b/src/ai/Spawner.hpp index e460bbc..4b20dd4 100644 --- a/src/ai/Spawner.hpp +++ b/src/ai/Spawner.hpp @@ -9,10 +9,10 @@ namespace blank { -class CompositeModel; class Controller; class Entity; class GaloisLFSR; +class Model; class Skeletons; class World; @@ -31,7 +31,7 @@ private: void TrySpawn(); void Spawn(Entity &reference, const glm::ivec3 &, const glm::vec3 &); - CompositeModel &RandomSkeleton() noexcept; + Model &RandomSkeleton() noexcept; private: World &world; diff --git a/src/client/client.cpp b/src/client/client.cpp index 1978f39..7e8c04e 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -5,7 +5,7 @@ #include "../app/Environment.hpp" #include "../app/init.hpp" #include "../app/TextureIndex.hpp" -#include "../model/CompositeModel.hpp" +#include "../model/Model.hpp" #include "../io/WorldSave.hpp" #include "../world/ChunkIndex.hpp" #include "../world/ChunkStore.hpp" @@ -327,7 +327,7 @@ void MasterState::On(const Packet::SpawnEntity &pack) { pack.ReadEntity(entity); uint32_t skel_id; pack.ReadSkeletonID(skel_id); - CompositeModel *skel = state->GetSkeletons().ByID(skel_id); + Model *skel = state->GetSkeletons().ByID(skel_id); if (skel) { skel->Instantiate(entity.GetModel()); } diff --git a/src/model/CompositeInstance.hpp b/src/model/CompositeInstance.hpp deleted file mode 100644 index 4b6cfb5..0000000 --- a/src/model/CompositeInstance.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef BLANK_MODEL_COMPOSITEINSTANCE_HPP_ -#define BLANK_MODEL_COMPOSITEINSTANCE_HPP_ - -#include -#include -#include - - -namespace blank { - -class CompositeModel; -class DirectionalLighting; - -// TODO: this doesn't have to be a tree, actually -// linearizing might be a good opportunity to optimize -class CompositeInstance { - - friend class CompositeModel; - -public: - CompositeInstance(); - - operator bool() const noexcept { return part_model; } - const CompositeModel &GetModel() const noexcept { return *part_model; } - - const glm::vec3 &Position() const noexcept { return position; } - void Position(const glm::vec3 &p) noexcept { position = p; } - - const glm::quat &Orientation() const noexcept { return orientation; } - void Orientation(const glm::quat &o) noexcept { orientation = o; } - - glm::mat4 LocalTransform() const noexcept; - glm::mat4 GlobalTransform() const noexcept; - - void Render(const glm::mat4 &, DirectionalLighting &) const; - -private: - CompositeInstance &AddPart(); - bool HasParent() const noexcept { return parent; } - CompositeInstance &Parent() const noexcept { return *parent; } - bool IsRoot() const noexcept { return !HasParent(); } - -private: - const CompositeModel *part_model; - CompositeInstance *parent; - - glm::vec3 position; - glm::quat orientation; - - std::vector parts; - -}; - -} - -#endif diff --git a/src/model/CompositeModel.hpp b/src/model/CompositeModel.hpp deleted file mode 100644 index 4b3d2a9..0000000 --- a/src/model/CompositeModel.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef BLANK_MODEL_COMPOSITEMODEL_HPP_ -#define BLANK_MODEL_COMPOSITEMODEL_HPP_ - -#include "geometry.hpp" - -#include -#include -#include -#include - - -namespace blank { - -class CompositeInstance; -class EntityMesh; - -class CompositeModel { - -public: - CompositeModel(); - - CompositeModel(const CompositeModel &) = delete; - CompositeModel &operator =(const CompositeModel &) = delete; - - std::uint32_t ID() const noexcept { return id; } - void ID(std::uint32_t i) noexcept { id = i; } - - const AABB &Bounds() const noexcept { return bounds; } - void Bounds(const AABB &b) noexcept { bounds = b; } - - const glm::vec3 &Position() const noexcept { return position; } - void Position(const glm::vec3 &p) noexcept { position = p; } - - const glm::quat &Orientation() const noexcept { return orientation; } - void Orientation(const glm::quat &o) noexcept { orientation = o; } - - bool HasNodeMesh() const noexcept { return node_mesh; } - void SetNodeMesh(const EntityMesh *m) noexcept { node_mesh = m; } - - const EntityMesh &NodeMesh() const noexcept { return *node_mesh; } - - CompositeModel &AddPart(); - bool HasParent() const noexcept { return parent; } - CompositeModel &Parent() const noexcept { return *parent; } - bool IsRoot() const noexcept { return !HasParent(); } - - glm::mat4 LocalTransform() const noexcept; - glm::mat4 GlobalTransform() const noexcept; - - void Instantiate(CompositeInstance &) const; - -private: - CompositeModel *parent; - const EntityMesh *node_mesh; - - std::uint32_t id; - - AABB bounds; - - glm::vec3 position; - glm::quat orientation; - - std::list parts; - -}; - -} - -#endif diff --git a/src/model/Instance.hpp b/src/model/Instance.hpp new file mode 100644 index 0000000..6c073b8 --- /dev/null +++ b/src/model/Instance.hpp @@ -0,0 +1,56 @@ +#ifndef BLANK_MODEL_INSTANCE_HPP_ +#define BLANK_MODEL_INSTANCE_HPP_ + +#include +#include +#include + + +namespace blank { + +class Model; +class DirectionalLighting; + +// TODO: this doesn't have to be a tree, actually +// linearizing might be a good opportunity to optimize +class Instance { + + friend class Model; + +public: + Instance(); + + operator bool() const noexcept { return part_model; } + const Model &GetModel() const noexcept { return *part_model; } + + const glm::vec3 &Position() const noexcept { return position; } + void Position(const glm::vec3 &p) noexcept { position = p; } + + const glm::quat &Orientation() const noexcept { return orientation; } + void Orientation(const glm::quat &o) noexcept { orientation = o; } + + glm::mat4 LocalTransform() const noexcept; + glm::mat4 GlobalTransform() const noexcept; + + void Render(const glm::mat4 &, DirectionalLighting &) const; + +private: + Instance &AddPart(); + bool HasParent() const noexcept { return parent; } + Instance &Parent() const noexcept { return *parent; } + bool IsRoot() const noexcept { return !HasParent(); } + +private: + const Model *part_model; + Instance *parent; + + glm::vec3 position; + glm::quat orientation; + + std::vector parts; + +}; + +} + +#endif diff --git a/src/model/Model.hpp b/src/model/Model.hpp new file mode 100644 index 0000000..118ac2e --- /dev/null +++ b/src/model/Model.hpp @@ -0,0 +1,69 @@ +#ifndef BLANK_MODEL_MODEL_HPP_ +#define BLANK_MODEL_MODEL_HPP_ + +#include "geometry.hpp" + +#include +#include +#include +#include + + +namespace blank { + +class Instance; +class EntityMesh; + +class Model { + +public: + Model(); + + Model(const Model &) = delete; + Model &operator =(const Model &) = delete; + + std::uint32_t ID() const noexcept { return id; } + void ID(std::uint32_t i) noexcept { id = i; } + + const AABB &Bounds() const noexcept { return bounds; } + void Bounds(const AABB &b) noexcept { bounds = b; } + + const glm::vec3 &Position() const noexcept { return position; } + void Position(const glm::vec3 &p) noexcept { position = p; } + + const glm::quat &Orientation() const noexcept { return orientation; } + void Orientation(const glm::quat &o) noexcept { orientation = o; } + + bool HasNodeMesh() const noexcept { return node_mesh; } + void SetNodeMesh(const EntityMesh *m) noexcept { node_mesh = m; } + + const EntityMesh &NodeMesh() const noexcept { return *node_mesh; } + + Model &AddPart(); + bool HasParent() const noexcept { return parent; } + Model &Parent() const noexcept { return *parent; } + bool IsRoot() const noexcept { return !HasParent(); } + + glm::mat4 LocalTransform() const noexcept; + glm::mat4 GlobalTransform() const noexcept; + + void Instantiate(Instance &) const; + +private: + Model *parent; + const EntityMesh *node_mesh; + + std::uint32_t id; + + AABB bounds; + + glm::vec3 position; + glm::quat orientation; + + std::list parts; + +}; + +} + +#endif diff --git a/src/model/Skeletons.hpp b/src/model/Skeletons.hpp index 250ebce..8d106d9 100644 --- a/src/model/Skeletons.hpp +++ b/src/model/Skeletons.hpp @@ -8,15 +8,15 @@ namespace blank { -class CompositeModel; +class Model; class EntityMesh; class Skeletons { public: using size_type = std::size_t; - using reference = CompositeModel &; - using const_reference = const CompositeModel &; + using reference = Model &; + using const_reference = const Model &; public: Skeletons(); @@ -30,11 +30,11 @@ public: reference operator[](size_type i) noexcept { return *skeletons[i]; } const_reference operator[](size_type i) const noexcept { return *skeletons[i]; } - CompositeModel *ByID(std::uint16_t) noexcept; - const CompositeModel *ByID(std::uint16_t) const noexcept; + Model *ByID(std::uint16_t) noexcept; + const Model *ByID(std::uint16_t) const noexcept; private: - std::vector> skeletons; + std::vector> skeletons; std::vector meshes; }; diff --git a/src/model/composite.cpp b/src/model/composite.cpp deleted file mode 100644 index 8507770..0000000 --- a/src/model/composite.cpp +++ /dev/null @@ -1,204 +0,0 @@ -#include "CompositeModel.hpp" -#include "CompositeInstance.hpp" -#include "Skeletons.hpp" - -#include "shapes.hpp" -#include "../graphics/DirectionalLighting.hpp" -#include "../graphics/EntityMesh.hpp" - -#include - - -namespace blank { - -CompositeModel::CompositeModel() -: parent(nullptr) -, node_mesh(nullptr) -, id(0) -, bounds{{ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }} -, position(0.0f) -, orientation(1.0f, 0.0f, 0.0f, 0.0f) -, parts() { - -} - - -CompositeModel &CompositeModel::AddPart() { - parts.emplace_back(); - parts.back().parent = this; - return parts.back(); -} - - -glm::mat4 CompositeModel::LocalTransform() const noexcept { - glm::mat4 transform(toMat4(orientation)); - transform[3].x = position.x; - transform[3].y = position.y; - transform[3].z = position.z; - return transform; -} - -glm::mat4 CompositeModel::GlobalTransform() const noexcept { - if (HasParent()) { - return Parent().GlobalTransform() * LocalTransform(); - } else { - return LocalTransform(); - } -} - - -void CompositeModel::Instantiate(CompositeInstance &inst) const { - inst.part_model = this; - inst.position = position; - inst.orientation = orientation; - inst.parts.clear(); - inst.parts.reserve(parts.size()); - for (const CompositeModel &part : parts) { - part.Instantiate(inst.AddPart()); - } -} - - -CompositeInstance::CompositeInstance() -: part_model(nullptr) -, parent(nullptr) -, position(0.0f) -, orientation(1.0f, 0.0f, 0.0f, 0.0f) -, parts() { - -} - - -CompositeInstance &CompositeInstance::AddPart() { - parts.emplace_back(); - parts.back().parent = this; - return parts.back(); -} - - -glm::mat4 CompositeInstance::LocalTransform() const noexcept { - glm::mat4 transform(toMat4(orientation)); - transform[3].x = position.x; - transform[3].y = position.y; - transform[3].z = position.z; - return transform; -} - -glm::mat4 CompositeInstance::GlobalTransform() const noexcept { - if (HasParent()) { - return Parent().GlobalTransform() * LocalTransform(); - } else { - return LocalTransform(); - } -} - - -void CompositeInstance::Render(const glm::mat4 &M, DirectionalLighting &prog) const { - glm::mat4 transform(M * LocalTransform()); - if (part_model->HasNodeMesh()) { - prog.SetM(transform); - part_model->NodeMesh().Draw(); - } - for (const CompositeInstance &part : parts) { - part.Render(transform, prog); - } -} - - -Skeletons::Skeletons() -: skeletons() -, meshes() { - -} - -Skeletons::~Skeletons() { - -} - -void Skeletons::LoadHeadless() { - skeletons.clear(); - skeletons.reserve(4); - { - AABB bounds{{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}; - skeletons.emplace_back(new CompositeModel); - skeletons[0]->ID(1); - skeletons[0]->Bounds(bounds); - } - { - AABB bounds{{ -0.5f, -0.25f, -0.5f }, { 0.5f, 0.25f, 0.5f }}; - skeletons.emplace_back(new CompositeModel); - skeletons[1]->ID(2); - skeletons[1]->Bounds(bounds); - } - { - AABB bounds{{ -0.25f, -0.5f, -0.25f }, { 0.25f, 0.5f, 0.25f }}; - skeletons.emplace_back(new CompositeModel); - skeletons[2]->ID(3); - skeletons[2]->Bounds(bounds); - } - { - AABB bounds{{ -0.25f, -0.5f, -0.35f }, { 0.25f, 0.5f, 0.35f }}; - skeletons.emplace_back(new CompositeModel); - skeletons[3]->ID(4); - skeletons[3]->Bounds(bounds); - } -} - -void Skeletons::Load() { - LoadHeadless(); - meshes.resize(4); - EntityMesh::Buffer buf; - { - CuboidShape shape(skeletons[0]->Bounds()); - shape.Vertices(buf, 3.0f); - buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); - buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f }); - meshes[0].Update(buf); - skeletons[0]->SetNodeMesh(&meshes[0]); - } - { - CuboidShape shape(skeletons[1]->Bounds()); - buf.Clear(); - shape.Vertices(buf, 0.0f); - buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); - buf.rgb_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); - meshes[1].Update(buf); - skeletons[1]->SetNodeMesh(&meshes[1]); - } - { - StairShape shape(skeletons[2]->Bounds(), { 0.4f, 0.4f }); - buf.Clear(); - shape.Vertices(buf, 1.0f); - buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); - buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.0f, 1.0f }); - meshes[2].Update(buf); - skeletons[2]->SetNodeMesh(&meshes[2]); - } - { - CuboidShape shape(skeletons[3]->Bounds()); - buf.Clear(); - shape.Vertices(buf, 2.0f); - buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); - buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.25f, 0.5f }); - meshes[3].Update(buf); - skeletons[3]->SetNodeMesh(&meshes[3]); - } -} - -CompositeModel *Skeletons::ByID(std::uint16_t id) noexcept { - if (id == 0 || id > skeletons.size()) { - return nullptr; - } else { - return skeletons[id - 1].get(); - } -} - -const CompositeModel *Skeletons::ByID(std::uint16_t id) const noexcept { - if (id == 0 || id > skeletons.size()) { - return nullptr; - } else { - return skeletons[id - 1].get(); - } -} - -} diff --git a/src/model/model.cpp b/src/model/model.cpp new file mode 100644 index 0000000..987d86c --- /dev/null +++ b/src/model/model.cpp @@ -0,0 +1,204 @@ +#include "Model.hpp" +#include "Instance.hpp" +#include "Skeletons.hpp" + +#include "shapes.hpp" +#include "../graphics/DirectionalLighting.hpp" +#include "../graphics/EntityMesh.hpp" + +#include + + +namespace blank { + +Model::Model() +: parent(nullptr) +, node_mesh(nullptr) +, id(0) +, bounds{{ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }} +, position(0.0f) +, orientation(1.0f, 0.0f, 0.0f, 0.0f) +, parts() { + +} + + +Model &Model::AddPart() { + parts.emplace_back(); + parts.back().parent = this; + return parts.back(); +} + + +glm::mat4 Model::LocalTransform() const noexcept { + glm::mat4 transform(toMat4(orientation)); + transform[3].x = position.x; + transform[3].y = position.y; + transform[3].z = position.z; + return transform; +} + +glm::mat4 Model::GlobalTransform() const noexcept { + if (HasParent()) { + return Parent().GlobalTransform() * LocalTransform(); + } else { + return LocalTransform(); + } +} + + +void Model::Instantiate(Instance &inst) const { + inst.part_model = this; + inst.position = position; + inst.orientation = orientation; + inst.parts.clear(); + inst.parts.reserve(parts.size()); + for (const Model &part : parts) { + part.Instantiate(inst.AddPart()); + } +} + + +Instance::Instance() +: part_model(nullptr) +, parent(nullptr) +, position(0.0f) +, orientation(1.0f, 0.0f, 0.0f, 0.0f) +, parts() { + +} + + +Instance &Instance::AddPart() { + parts.emplace_back(); + parts.back().parent = this; + return parts.back(); +} + + +glm::mat4 Instance::LocalTransform() const noexcept { + glm::mat4 transform(toMat4(orientation)); + transform[3].x = position.x; + transform[3].y = position.y; + transform[3].z = position.z; + return transform; +} + +glm::mat4 Instance::GlobalTransform() const noexcept { + if (HasParent()) { + return Parent().GlobalTransform() * LocalTransform(); + } else { + return LocalTransform(); + } +} + + +void Instance::Render(const glm::mat4 &M, DirectionalLighting &prog) const { + glm::mat4 transform(M * LocalTransform()); + if (part_model->HasNodeMesh()) { + prog.SetM(transform); + part_model->NodeMesh().Draw(); + } + for (const Instance &part : parts) { + part.Render(transform, prog); + } +} + + +Skeletons::Skeletons() +: skeletons() +, meshes() { + +} + +Skeletons::~Skeletons() { + +} + +void Skeletons::LoadHeadless() { + skeletons.clear(); + skeletons.reserve(4); + { + AABB bounds{{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}; + skeletons.emplace_back(new Model); + skeletons[0]->ID(1); + skeletons[0]->Bounds(bounds); + } + { + AABB bounds{{ -0.5f, -0.25f, -0.5f }, { 0.5f, 0.25f, 0.5f }}; + skeletons.emplace_back(new Model); + skeletons[1]->ID(2); + skeletons[1]->Bounds(bounds); + } + { + AABB bounds{{ -0.25f, -0.5f, -0.25f }, { 0.25f, 0.5f, 0.25f }}; + skeletons.emplace_back(new Model); + skeletons[2]->ID(3); + skeletons[2]->Bounds(bounds); + } + { + AABB bounds{{ -0.25f, -0.5f, -0.35f }, { 0.25f, 0.5f, 0.35f }}; + skeletons.emplace_back(new Model); + skeletons[3]->ID(4); + skeletons[3]->Bounds(bounds); + } +} + +void Skeletons::Load() { + LoadHeadless(); + meshes.resize(4); + EntityMesh::Buffer buf; + { + CuboidShape shape(skeletons[0]->Bounds()); + shape.Vertices(buf, 3.0f); + buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); + buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f }); + meshes[0].Update(buf); + skeletons[0]->SetNodeMesh(&meshes[0]); + } + { + CuboidShape shape(skeletons[1]->Bounds()); + buf.Clear(); + shape.Vertices(buf, 0.0f); + buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); + buf.rgb_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); + meshes[1].Update(buf); + skeletons[1]->SetNodeMesh(&meshes[1]); + } + { + StairShape shape(skeletons[2]->Bounds(), { 0.4f, 0.4f }); + buf.Clear(); + shape.Vertices(buf, 1.0f); + buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); + buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.0f, 1.0f }); + meshes[2].Update(buf); + skeletons[2]->SetNodeMesh(&meshes[2]); + } + { + CuboidShape shape(skeletons[3]->Bounds()); + buf.Clear(); + shape.Vertices(buf, 2.0f); + buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f }); + buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 0.25f, 0.5f }); + meshes[3].Update(buf); + skeletons[3]->SetNodeMesh(&meshes[3]); + } +} + +Model *Skeletons::ByID(std::uint16_t id) noexcept { + if (id == 0 || id > skeletons.size()) { + return nullptr; + } else { + return skeletons[id - 1].get(); + } +} + +const Model *Skeletons::ByID(std::uint16_t id) const noexcept { + if (id == 0 || id > skeletons.size()) { + return nullptr; + } else { + return skeletons[id - 1].get(); + } +} + +} diff --git a/src/net/net.cpp b/src/net/net.cpp index 58875e7..115cb4e 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -4,7 +4,7 @@ #include "Packet.hpp" #include "../app/init.hpp" -#include "../model/CompositeModel.hpp" +#include "../model/Model.hpp" #include "../world/Entity.hpp" #include "../world/EntityState.hpp" diff --git a/src/server/ClientConnection.hpp b/src/server/ClientConnection.hpp index 9aaae12..11670bc 100644 --- a/src/server/ClientConnection.hpp +++ b/src/server/ClientConnection.hpp @@ -19,7 +19,7 @@ namespace blank { -class CompositeModel; +class Model; namespace server { @@ -57,9 +57,9 @@ public: ChunkIndex &PlayerChunks() noexcept { return input->GetPlayer().GetChunks(); } const ChunkIndex &PlayerChunks() const noexcept { return input->GetPlayer().GetChunks(); } - void SetPlayerModel(const CompositeModel &) noexcept; + void SetPlayerModel(const Model &) noexcept; bool HasPlayerModel() const noexcept; - const CompositeModel &GetPlayerModel() const noexcept; + const Model &GetPlayerModel() const noexcept; bool ChunkInRange(const glm::ivec3 &) const noexcept; @@ -100,7 +100,7 @@ private: Server &server; Connection conn; std::unique_ptr input; - const CompositeModel *player_model; + const Model *player_model; std::list spawns; unsigned int confirm_wait; diff --git a/src/server/Server.hpp b/src/server/Server.hpp index c12b86a..cef98be 100644 --- a/src/server/Server.hpp +++ b/src/server/Server.hpp @@ -12,7 +12,7 @@ namespace blank { class ChunkIndex; -class CompositeModel; +class Model; class Player; class WorldSave; @@ -37,9 +37,9 @@ public: World &GetWorld() noexcept { return world; } const WorldSave &GetWorldSave() noexcept { return save; } - void SetPlayerModel(const CompositeModel &) noexcept; + void SetPlayerModel(const Model &) noexcept; bool HasPlayerModel() const noexcept; - const CompositeModel &GetPlayerModel() const noexcept; + const Model &GetPlayerModel() const noexcept; Player *JoinPlayer(const std::string &name); @@ -58,7 +58,7 @@ private: World &world; ChunkIndex &spawn_index; const WorldSave &save; - const CompositeModel *player_model; + const Model *player_model; }; diff --git a/src/server/net.cpp b/src/server/net.cpp index 27643ee..bb42979 100644 --- a/src/server/net.cpp +++ b/src/server/net.cpp @@ -4,7 +4,7 @@ #include "../app/init.hpp" #include "../io/WorldSave.hpp" -#include "../model/CompositeModel.hpp" +#include "../model/Model.hpp" #include "../world/ChunkIndex.hpp" #include "../world/Entity.hpp" #include "../world/World.hpp" @@ -446,7 +446,7 @@ void ClientConnection::DetachPlayer() { old_actions = 0; } -void ClientConnection::SetPlayerModel(const CompositeModel &m) noexcept { +void ClientConnection::SetPlayerModel(const Model &m) noexcept { player_model = &m; if (HasPlayer()) { m.Instantiate(PlayerEntity().GetModel()); @@ -457,7 +457,7 @@ bool ClientConnection::HasPlayerModel() const noexcept { return player_model; } -const CompositeModel &ClientConnection::GetPlayerModel() const noexcept { +const Model &ClientConnection::GetPlayerModel() const noexcept { return *player_model; } @@ -662,7 +662,7 @@ void Server::Update(int dt) { } } -void Server::SetPlayerModel(const CompositeModel &m) noexcept { +void Server::SetPlayerModel(const Model &m) noexcept { player_model = &m; for (ClientConnection &client : clients) { client.SetPlayerModel(m); @@ -673,7 +673,7 @@ bool Server::HasPlayerModel() const noexcept { return player_model; } -const CompositeModel &Server::GetPlayerModel() const noexcept { +const Model &Server::GetPlayerModel() const noexcept { return *player_model; } diff --git a/src/world/Entity.hpp b/src/world/Entity.hpp index dcfb418..eb312ee 100644 --- a/src/world/Entity.hpp +++ b/src/world/Entity.hpp @@ -3,7 +3,7 @@ #include "Chunk.hpp" #include "EntityState.hpp" -#include "../model/CompositeInstance.hpp" +#include "../model/Instance.hpp" #include "../model/geometry.hpp" #include @@ -22,8 +22,8 @@ class Entity { public: Entity() noexcept; - CompositeInstance &GetModel() noexcept { return model; } - const CompositeInstance &GetModel() const noexcept { return model; } + Instance &GetModel() noexcept { return model; } + const Instance &GetModel() const noexcept { return model; } std::uint32_t ID() const noexcept { return id; } void ID(std::uint32_t i) noexcept { id = i; } @@ -83,7 +83,7 @@ public: } private: - CompositeInstance model; + Instance model; std::uint32_t id; std::string name; diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index b5f9eed..464c9d6 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -1,6 +1,6 @@ #include "PacketTest.hpp" -#include "model/CompositeModel.hpp" +#include "model/Model.hpp" #include "world/Entity.hpp" CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::PacketTest); @@ -229,7 +229,7 @@ void PacketTest::testSpawnEntity() { Entity write_entity; write_entity.ID(534574); - CompositeModel model; + Model model; model.ID(23); model.Instantiate(write_entity.GetModel()); write_entity.GetState().chunk_pos = { 7, 2, -3 };