From eba29c8ad489194cd1e3cd64b5f23424ad4384ef Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 12 Oct 2015 14:15:06 +0200 Subject: [PATCH] composite model is the canonical model --- src/ai/Spawner.cpp | 4 +- src/ai/Spawner.hpp | 4 +- src/client/client.cpp | 4 +- .../{CompositeInstance.hpp => Instance.hpp} | 24 +++++------ src/model/{CompositeModel.hpp => Model.hpp} | 24 +++++------ src/model/Skeletons.hpp | 12 +++--- src/model/{composite.cpp => model.cpp} | 40 +++++++++---------- src/net/net.cpp | 2 +- src/server/ClientConnection.hpp | 8 ++-- src/server/Server.hpp | 8 ++-- src/server/net.cpp | 10 ++--- src/world/Entity.hpp | 8 ++-- tst/net/PacketTest.cpp | 4 +- 13 files changed, 76 insertions(+), 76 deletions(-) rename src/model/{CompositeInstance.hpp => Instance.hpp} (66%) rename src/model/{CompositeModel.hpp => Model.hpp} (72%) rename src/model/{composite.cpp => model.cpp} (78%) 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/Instance.hpp similarity index 66% rename from src/model/CompositeInstance.hpp rename to src/model/Instance.hpp index 4b6cfb5..6c073b8 100644 --- a/src/model/CompositeInstance.hpp +++ b/src/model/Instance.hpp @@ -1,5 +1,5 @@ -#ifndef BLANK_MODEL_COMPOSITEINSTANCE_HPP_ -#define BLANK_MODEL_COMPOSITEINSTANCE_HPP_ +#ifndef BLANK_MODEL_INSTANCE_HPP_ +#define BLANK_MODEL_INSTANCE_HPP_ #include #include @@ -8,20 +8,20 @@ namespace blank { -class CompositeModel; +class Model; class DirectionalLighting; // TODO: this doesn't have to be a tree, actually // linearizing might be a good opportunity to optimize -class CompositeInstance { +class Instance { - friend class CompositeModel; + friend class Model; public: - CompositeInstance(); + Instance(); operator bool() const noexcept { return part_model; } - const CompositeModel &GetModel() 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; } @@ -35,19 +35,19 @@ public: void Render(const glm::mat4 &, DirectionalLighting &) const; private: - CompositeInstance &AddPart(); + Instance &AddPart(); bool HasParent() const noexcept { return parent; } - CompositeInstance &Parent() const noexcept { return *parent; } + Instance &Parent() const noexcept { return *parent; } bool IsRoot() const noexcept { return !HasParent(); } private: - const CompositeModel *part_model; - CompositeInstance *parent; + const Model *part_model; + Instance *parent; glm::vec3 position; glm::quat orientation; - std::vector parts; + std::vector parts; }; diff --git a/src/model/CompositeModel.hpp b/src/model/Model.hpp similarity index 72% rename from src/model/CompositeModel.hpp rename to src/model/Model.hpp index 4b3d2a9..118ac2e 100644 --- a/src/model/CompositeModel.hpp +++ b/src/model/Model.hpp @@ -1,5 +1,5 @@ -#ifndef BLANK_MODEL_COMPOSITEMODEL_HPP_ -#define BLANK_MODEL_COMPOSITEMODEL_HPP_ +#ifndef BLANK_MODEL_MODEL_HPP_ +#define BLANK_MODEL_MODEL_HPP_ #include "geometry.hpp" @@ -11,16 +11,16 @@ namespace blank { -class CompositeInstance; +class Instance; class EntityMesh; -class CompositeModel { +class Model { public: - CompositeModel(); + Model(); - CompositeModel(const CompositeModel &) = delete; - CompositeModel &operator =(const CompositeModel &) = delete; + 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; } @@ -39,18 +39,18 @@ public: const EntityMesh &NodeMesh() const noexcept { return *node_mesh; } - CompositeModel &AddPart(); + Model &AddPart(); bool HasParent() const noexcept { return parent; } - CompositeModel &Parent() 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(CompositeInstance &) const; + void Instantiate(Instance &) const; private: - CompositeModel *parent; + Model *parent; const EntityMesh *node_mesh; std::uint32_t id; @@ -60,7 +60,7 @@ private: glm::vec3 position; glm::quat orientation; - std::list parts; + std::list parts; }; 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/model.cpp similarity index 78% rename from src/model/composite.cpp rename to src/model/model.cpp index 8507770..987d86c 100644 --- a/src/model/composite.cpp +++ b/src/model/model.cpp @@ -1,5 +1,5 @@ -#include "CompositeModel.hpp" -#include "CompositeInstance.hpp" +#include "Model.hpp" +#include "Instance.hpp" #include "Skeletons.hpp" #include "shapes.hpp" @@ -11,7 +11,7 @@ namespace blank { -CompositeModel::CompositeModel() +Model::Model() : parent(nullptr) , node_mesh(nullptr) , id(0) @@ -23,14 +23,14 @@ CompositeModel::CompositeModel() } -CompositeModel &CompositeModel::AddPart() { +Model &Model::AddPart() { parts.emplace_back(); parts.back().parent = this; return parts.back(); } -glm::mat4 CompositeModel::LocalTransform() const noexcept { +glm::mat4 Model::LocalTransform() const noexcept { glm::mat4 transform(toMat4(orientation)); transform[3].x = position.x; transform[3].y = position.y; @@ -38,7 +38,7 @@ glm::mat4 CompositeModel::LocalTransform() const noexcept { return transform; } -glm::mat4 CompositeModel::GlobalTransform() const noexcept { +glm::mat4 Model::GlobalTransform() const noexcept { if (HasParent()) { return Parent().GlobalTransform() * LocalTransform(); } else { @@ -47,19 +47,19 @@ glm::mat4 CompositeModel::GlobalTransform() const noexcept { } -void CompositeModel::Instantiate(CompositeInstance &inst) const { +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 CompositeModel &part : parts) { + for (const Model &part : parts) { part.Instantiate(inst.AddPart()); } } -CompositeInstance::CompositeInstance() +Instance::Instance() : part_model(nullptr) , parent(nullptr) , position(0.0f) @@ -69,14 +69,14 @@ CompositeInstance::CompositeInstance() } -CompositeInstance &CompositeInstance::AddPart() { +Instance &Instance::AddPart() { parts.emplace_back(); parts.back().parent = this; return parts.back(); } -glm::mat4 CompositeInstance::LocalTransform() const noexcept { +glm::mat4 Instance::LocalTransform() const noexcept { glm::mat4 transform(toMat4(orientation)); transform[3].x = position.x; transform[3].y = position.y; @@ -84,7 +84,7 @@ glm::mat4 CompositeInstance::LocalTransform() const noexcept { return transform; } -glm::mat4 CompositeInstance::GlobalTransform() const noexcept { +glm::mat4 Instance::GlobalTransform() const noexcept { if (HasParent()) { return Parent().GlobalTransform() * LocalTransform(); } else { @@ -93,13 +93,13 @@ glm::mat4 CompositeInstance::GlobalTransform() const noexcept { } -void CompositeInstance::Render(const glm::mat4 &M, DirectionalLighting &prog) const { +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 CompositeInstance &part : parts) { + for (const Instance &part : parts) { part.Render(transform, prog); } } @@ -120,25 +120,25 @@ void Skeletons::LoadHeadless() { skeletons.reserve(4); { AABB bounds{{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}; - skeletons.emplace_back(new CompositeModel); + 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 CompositeModel); + 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 CompositeModel); + 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 CompositeModel); + skeletons.emplace_back(new Model); skeletons[3]->ID(4); skeletons[3]->Bounds(bounds); } @@ -185,7 +185,7 @@ void Skeletons::Load() { } } -CompositeModel *Skeletons::ByID(std::uint16_t id) noexcept { +Model *Skeletons::ByID(std::uint16_t id) noexcept { if (id == 0 || id > skeletons.size()) { return nullptr; } else { @@ -193,7 +193,7 @@ CompositeModel *Skeletons::ByID(std::uint16_t id) noexcept { } } -const CompositeModel *Skeletons::ByID(std::uint16_t id) const noexcept { +const Model *Skeletons::ByID(std::uint16_t id) const noexcept { if (id == 0 || id > skeletons.size()) { return nullptr; } else { 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 }; -- 2.39.2