diff --git a/src/dict.cpp b/src/dict.cpp deleted file mode 100644 index 27c3c93f..00000000 --- a/src/dict.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2018 Sam Hocevar -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#include - -#include -#include - -#if defined _WIN32 -# define strcasecmp _stricmp -#endif - -namespace lol -{ - -/* - * Dict implementation class - */ - -class DictData -{ - friend class Dict; - -public: - DictData() : - nentities(0) - { - /* Nothing to do */ - } - - ~DictData() - { -#if !LOL_BUILD_RELEASE - if (nentities) - msg::error("still %i entities in dict\n", nentities); -#endif - } - -private: - array m_entities; - int nentities; -}; - -/* - * Public Dict class - */ - -Dict::Dict() - : data(new DictData()) -{ -} - -Dict::~Dict() -{ - delete data; -} - -int Dict::MakeSlot(std::string const &name) -{ - int slotid, empty = -1; - - /* If the entry is already registered, remember its ID. Look for an - * empty slot at the same time. */ - for (slotid = 0; slotid < data->m_entities.count(); slotid++) - { - Entity *e = data->m_entities[slotid]; - if (!e) - { - empty = slotid; - break; - } - else - { - auto oldname = e->GetName(); - if (oldname[0] == '<') - oldname = std::regex_replace(oldname, std::regex("<[^>]*> *"), ""); - - if (oldname == name) - break; - } - } - - /* If this is a new entry, create a new slot for it. */ - if (slotid == data->m_entities.count() || !data->m_entities[slotid]) - { - if (slotid == data->m_entities.count()) - { - empty = (int)data->m_entities.count(); - data->m_entities.push(nullptr); - } - - data->m_entities[empty] = nullptr; - slotid = empty; - data->nentities++; - } - else - { - Ticker::Ref(data->m_entities[slotid]); - } - - return slotid; -} - -void Dict::RemoveSlot(int slotid) -{ - if (Ticker::Unref(data->m_entities[slotid]) == 0) - { - data->m_entities[slotid] = nullptr; - data->nentities--; - } -} - -void Dict::RemoveSlot(Entity *entity) -{ - for (int slotid = 0; slotid < data->m_entities.count(); slotid++) - if (data->m_entities[slotid] == entity) - { - RemoveSlot(slotid); - return; - } - -#if !LOL_BUILD_RELEASE - msg::error("removing unregistered entity %p (%s)\n", - entity, entity->GetName().c_str()); -#endif -} - -void Dict::SetEntity(int slotid, Entity *entity) -{ - Ticker::Ref(entity); - data->m_entities[slotid] = entity; -} - -Entity *Dict::GetEntity(int slotid) -{ - return data->m_entities[slotid]; -} - -} /* namespace lol */ - diff --git a/src/dict.h b/src/dict.h deleted file mode 100644 index 0a6a8b3d..00000000 --- a/src/dict.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2018 Sam Hocevar -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -// -// The Dict class -// -------------- -// - -#include "engine/entity.h" - -namespace lol -{ - -class DictData; - -class Dict -{ -public: - Dict(); - ~Dict(); - - int MakeSlot(std::string const &name); - void RemoveSlot(int slotid); - void RemoveSlot(Entity *entity); - - void SetEntity(int slotid, Entity *entity); - Entity *GetEntity(int slotid); - -private: - DictData *data; -}; - -} /* namespace lol */ -