diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 70f2ffa..9622b05 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -281,7 +281,7 @@ void Chunk::updateClient() { imcUncompress(); #endif mut.lock(); - ContentRegistry &CR = *G->CR; + Content::Registry &CR = *G->CR; Vertex vertex[CX * CY * CZ * 6 /* faces */ * 4 /* vertices */ / 2 /* face removing (HSR) makes a lower vert max */]; GLushort idxOpaque[CX * CY * CZ * 6 /* faces */ * 6 /* indices */ / 2 /* HSR */], idxTransp[CX*CY*CZ*6*6/2]; diff --git a/src/Game.cpp b/src/Game.cpp index 86f8c65..6d1937e 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -19,7 +19,7 @@ Game::Game() : } void Game::init() { - CR = new ContentRegistry; + CR = new Content::Registry; LS = new Scripting::Lua::State(this); if (GlobalProperties::IsClient) { PM = new ProgramManager(*this); diff --git a/src/Game.hpp b/src/Game.hpp index b64bdc5..bb51aaa 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -11,6 +11,10 @@ using std::shared_ptr; namespace Diggler { +namespace Content { +class Registry; +} + namespace Render { class Renderer; } @@ -26,7 +30,6 @@ class Manager; } class Audio; -class ContentRegistry; class Config; class GameWindow; class KeyBinds; @@ -39,7 +42,7 @@ public: Net::Host H; Universe *U; PlayerList players; - ContentRegistry *CR; + Content::Registry *CR; Scripting::Lua::State *LS; // Server diff --git a/src/content/BlockDef.hpp b/src/content/BlockDef.hpp index c5fd089..401f951 100644 --- a/src/content/BlockDef.hpp +++ b/src/content/BlockDef.hpp @@ -1,5 +1,5 @@ -#ifndef DIGGLER_BLOCK_DEF_HPP -#define DIGGLER_BLOCK_DEF_HPP +#ifndef DIGGLER_CONTENT_BLOCK_DEF_HPP +#define DIGGLER_CONTENT_BLOCK_DEF_HPP #include @@ -9,6 +9,7 @@ //#include "../AABB.hpp" namespace Diggler { +namespace Content { class BlockDef : public ObjectDef { public: @@ -51,6 +52,7 @@ public: } phys; }; +} } -#endif /* DIGGLER_BLOCK_DEF_HPP */ +#endif /* DIGGLER_CONTENT_BLOCK_DEF_HPP */ diff --git a/src/content/Content.hpp b/src/content/Content.hpp index f46f712..ab5aac8 100644 --- a/src/content/Content.hpp +++ b/src/content/Content.hpp @@ -1,7 +1,7 @@ -#ifndef CONTENT_HPP -#define CONTENT_HPP +#ifndef DIGGLER_CONTENT_HPP +#define DIGGLER_CONTENT_HPP -#include "../Platform.hpp" +#include "../platform/Types.hpp" #include #include @@ -43,4 +43,4 @@ namespace Content { } } -#endif +#endif /* DIGGLER_CONTENT_HPP */ diff --git a/src/content/ObjectDef.hpp b/src/content/ObjectDef.hpp index aa937f7..c7b4b5d 100644 --- a/src/content/ObjectDef.hpp +++ b/src/content/ObjectDef.hpp @@ -1,8 +1,9 @@ -#ifndef OBJECT_DEF_HPP -#define OBJECT_DEF_HPP +#ifndef DIGGLER_CONTENT_OBJECT_DEF_HPP +#define DIGGLER_CONTENT_OBJECT_DEF_HPP #include "../Platform.hpp" namespace Diggler { +namespace Content { class ObjectDef { public: @@ -13,6 +14,7 @@ public: }; }; +} } -#endif +#endif /* DIGGLER_CONTENT_OBJECT_DEF_HPP */ diff --git a/src/content/Registry.cpp b/src/content/Registry.cpp index 8780829..ea0e8af 100644 --- a/src/content/Registry.cpp +++ b/src/content/Registry.cpp @@ -5,24 +5,23 @@ #define PRINT_BLOCK_REGISTRATIONS 1 namespace Diggler { +namespace Content { -using CR = ContentRegistry; - -CR::BlockRegistration::BlockRegistration(ContentRegistry ®istry, - const ContentRegistry::BlockNameMap::iterator &it) : +Registry::BlockRegistration::BlockRegistration(Registry ®istry, + const Registry::BlockNameMap::iterator &it) : registry(registry), it(it), state(Uncommitted), def(it->second->second) { } -CR::BlockRegistration::~BlockRegistration() { +Registry::BlockRegistration::~BlockRegistration() { if (state == Uncommitted) { registry.m_blocks.erase(it->second); } } -CR::BlockRegistration::BlockRegistration(CR::BlockRegistration &&o) : +Registry::BlockRegistration::BlockRegistration(Registry::BlockRegistration &&o) : registry(o.registry), it(o.it), state(o.state), @@ -30,7 +29,7 @@ CR::BlockRegistration::BlockRegistration(CR::BlockRegistration &&o) : o.state = Moved; } -BlockId CR::BlockRegistration::commit() { +BlockId Registry::BlockRegistration::commit() { state = Committed; #if PRINT_BLOCK_REGISTRATIONS getDebugStream() << "Registered block " << it->first << " with id " << @@ -76,14 +75,14 @@ static const DefBlocksInfo DefBlocksInfos[] = { {"diggler:transp_blue", "Force Field", 0, 0, 25, ANY, "translucent_blue.png"} }; -bool ContentRegistry::isTransparent(BlockId id) const { +bool Registry::isTransparent(BlockId id) const { if (id == Content::BlockAirId) return true; return false; // TODO return getBlockDef(id).isTransparent; } -bool ContentRegistry::isFaceVisible(BlockId id1, BlockId id2) const { +bool Registry::isFaceVisible(BlockId id1, BlockId id2) const { // TODO: node mesh/boxes -> not fullblock, faces may not be hidden if (isTransparent(id1)) { return (id1 != id2); @@ -92,7 +91,7 @@ bool ContentRegistry::isFaceVisible(BlockId id1, BlockId id2) const { } } -bool ContentRegistry::canEntityGoThrough(BlockId id/* , Entity& ent*/) const { +bool Registry::canEntityGoThrough(BlockId id/* , Entity& ent*/) const { if (id == Content::BlockAirId) return true; return false; @@ -103,15 +102,15 @@ bool ContentRegistry::canEntityGoThrough(BlockId id/* , Entity& ent*/) const { using Coord = TexturePacker::Coord; static Coord unk1, unk2, unk3, unk4, unk5, unk6, unk7, unk8; #define AddTex(b, t) Coord b = m_texturePacker->add(getAssetPath("blocks", t)); -ContentRegistry::ContentRegistry() : +Registry::Registry() : m_atlas(nullptr), m_nextMaxBlockId(Content::BlockUnknownId + 1) { - { ContentRegistry::BlockRegistration br(registerBlock(Content::BlockAirId, "air")); + { Registry::BlockRegistration br(registerBlock(Content::BlockAirId, "air")); br.def.appearance.look.type = BlockDef::Appearance::Look::Type::Hidden; br.def.phys.hasCollision = false; br.commit(); } - { ContentRegistry::BlockRegistration br(registerBlock(Content::BlockUnknownId, "unknown")); + { Registry::BlockRegistration br(registerBlock(Content::BlockUnknownId, "unknown")); br.def.appearance.look.type = BlockDef::Appearance::Look::Type::Hidden; br.def.phys.hasCollision = true; br.commit(); @@ -134,11 +133,11 @@ ContentRegistry::ContentRegistry() : m_atlas = m_texturePacker->getAtlas(); } -ContentRegistry::~ContentRegistry() { +Registry::~Registry() { delete m_texturePacker; } -TexturePacker::Coord ContentRegistry::addTexture(const std::string &texName, +TexturePacker::Coord Registry::addTexture(const std::string &texName, const std::string &path) { const TexturePacker::Coord coord = m_texturePacker->add(path); m_textureCoords.emplace(std::piecewise_construct, @@ -147,7 +146,7 @@ TexturePacker::Coord ContentRegistry::addTexture(const std::string &texName, return coord; } -const TexturePacker::Coord* ContentRegistry::blockTexCoord(BlockId t, FaceDirection d, +const TexturePacker::Coord* Registry::blockTexCoord(BlockId t, FaceDirection d, const glm::ivec3 &pos) const { if (t == Content::BlockUnknownId) { const Coord *unk[] = { @@ -199,11 +198,11 @@ const TexturePacker::Coord* ContentRegistry::blockTexCoord(BlockId t, FaceDirect return nullptr; } -const Texture* ContentRegistry::getAtlas() const { +const Texture* Registry::getAtlas() const { return m_atlas; } -ContentRegistry::BlockRegistration ContentRegistry::registerBlock(BlockId id, const char *name) { +Registry::BlockRegistration Registry::registerBlock(BlockId id, const char *name) { BlockIdMap::iterator bit = m_blocks.emplace(std::piecewise_construct, std::forward_as_tuple(id), std::forward_as_tuple()) @@ -214,7 +213,7 @@ ContentRegistry::BlockRegistration ContentRegistry::registerBlock(BlockId id, co .first); } -ContentRegistry::BlockRegistration ContentRegistry::registerBlock(const char *name) { +Registry::BlockRegistration Registry::registerBlock(const char *name) { BlockId id = Content::BlockUnknownId; if (m_freedBlockIds.empty()) { id = m_nextMaxBlockId; @@ -227,3 +226,4 @@ ContentRegistry::BlockRegistration ContentRegistry::registerBlock(const char *na } } +} diff --git a/src/content/Registry.hpp b/src/content/Registry.hpp index cc4f71d..d80a513 100644 --- a/src/content/Registry.hpp +++ b/src/content/Registry.hpp @@ -1,5 +1,5 @@ -#ifndef CONTENT_REGISTRY_HPP -#define CONTENT_REGISTRY_HPP +#ifndef DIGGLER_CONTENT_REGISTRY_HPP +#define DIGGLER_CONTENT_REGISTRY_HPP #include #include @@ -22,14 +22,16 @@ enum class FaceDirection : uint8_t { ZDec = 5 }; -class ContentRegistry { +namespace Content { + +class Registry { public: using BlockIdMap = std::unordered_map; using BlockNameMap = std::unordered_map; class BlockRegistration { protected: - ContentRegistry ®istry; + Registry ®istry; const BlockNameMap::iterator it; enum { Uncommitted, @@ -39,7 +41,7 @@ public: public: BlockDef &def; - BlockRegistration(ContentRegistry ®istry, const BlockNameMap::iterator &it); + BlockRegistration(Registry ®istry, const BlockNameMap::iterator &it); ~BlockRegistration(); BlockRegistration(const BlockRegistration&) = delete; @@ -66,14 +68,14 @@ private: std::vector m_freedBlockIds; // No copy - ContentRegistry(const ContentRegistry&) = delete; - ContentRegistry& operator=(const ContentRegistry&) = delete; + Registry(const Registry&) = delete; + Registry& operator=(const Registry&) = delete; BlockRegistration registerBlock(BlockId id, const char *name); public: - ContentRegistry(); - ~ContentRegistry(); + Registry(); + ~Registry(); bool isTransparent(BlockId id) const; bool isFaceVisible(BlockId id1, BlockId id2) const; @@ -89,6 +91,7 @@ public: const BlockDef& getBlockDef(BlockId); }; +} } -#endif +#endif /* DIGGLER_CONTENT_REGISTRY_HPP */ diff --git a/src/network/ClientMessageHandler.cpp b/src/network/ClientMessageHandler.cpp index 1888a3c..344e53b 100644 --- a/src/network/ClientMessageHandler.cpp +++ b/src/network/ClientMessageHandler.cpp @@ -66,7 +66,7 @@ bool ClientMessageHandler::handleMessage(InMessage &msg) { std::string playerName; if (cpt.player.display.type == msgpack::type::NIL) { const Player *blabbermouth = GS.G->players.getByGameId(cpt.player.id); - [[likely(true)]] if (blabbermouth != nullptr) { + if (blabbermouth != nullptr) { playerName = blabbermouth->name + "> "; } else { playerName = "?> "; diff --git a/src/scripting/lua/api/content/Registry.cpp b/src/scripting/lua/api/content/Registry.cpp index 118d9a3..51a58be 100644 --- a/src/scripting/lua/api/content/Registry.cpp +++ b/src/scripting/lua/api/content/Registry.cpp @@ -8,8 +8,9 @@ using namespace Diggler; void Diggler_Content_Registry_registerBlock(struct Diggler_Game *cG, const char *name, struct Diggler_Content_BlockDef *cBdef) { + using namespace Content; Game &G = *reinterpret_cast(cG); - ContentRegistry::BlockRegistration br(G.CR->registerBlock(name)); + Registry::BlockRegistration br(G.CR->registerBlock(name)); { decltype(cBdef->appearance) &cApp = cBdef->appearance; decltype(br.def.appearance) &app = br.def.appearance; std::vector textureIts; @@ -29,9 +30,6 @@ void Diggler_Content_Registry_registerBlock(struct Diggler_Game *cG, if (cTex.repeatXdiv > 1 || cTex.repeatYdiv > 1) { uint16 width = (tex.coord.u - tex.coord.x) / cTex.repeatXdiv, height = (tex.coord.v - tex.coord.y) / cTex.repeatYdiv; - getDebugStream() << "Split " << tex.coord.x << ' ' << tex.coord.y << ' ' << tex.coord.u << - ' ' << tex.coord.v << " into " << static_cast(tex.repeat.xdiv) << 'x' << - static_cast(tex.repeat.ydiv) << std::endl; for (int16 y = cTex.repeatYdiv - 1; y >= 0; --y) { for (int16 x = cTex.repeatXdiv - 1; x >= 0; --x) { tex.divCoords.emplace_back(TexturePacker::Coord { @@ -40,9 +38,6 @@ void Diggler_Content_Registry_registerBlock(struct Diggler_Game *cG, static_cast(tex.coord.x + width * (x + 1)), static_cast(tex.coord.y + height * (y + 1)) }); - const TexturePacker::Coord &coord = tex.divCoords.back(); - getDebugStream() << "> " << coord.x << ' ' << coord.y << ' ' << coord.u << - ' ' << coord.v << std::endl; } } }