12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #pragma once
- #include <iostream>
- template<typename T> class StaticRegistry
- {
- public:
- static StaticRegistry<T> INSTANCE;
- private:
- T** registry;
- int count;
- StaticRegistry()
- {
- count = 0;
- registry = new T*[count];
- memset(registry, 0, sizeof(T*) * count);
- }
- ~StaticRegistry()
- {
- for (int index = 0; index < count; index++)
- {
- if (registry[index])
- {
- registry[index]->release();
- registry[index] = 0;
- }
- }
- delete[] registry;
- }
- public:
- void registerT(T* type, int id)
- {
- if (id >= count)
- {
- T** temp = new T*[id + 1];
- memcpy(temp, registry, sizeof(T*) * count);
- memset(temp + count, 0, sizeof(T*) * (id + 1 - count));
- delete[] registry;
- registry = temp;
- count = id + 1;
- }
- registry[id] = type;
- }
- T* zElement(int id)
- {
- if (id < 0 || id >= count) return 0;
- return registry[id];
- }
- int getCount() const
- {
- return count;
- }
- bool info(int id)
- {
- std::cout << typeid(*registry[id]).name() << " was registered as "
- << typeid(T).name() << " with id " << id << std::endl;
- return 1;
- }
- friend T;
- };
- template<typename T> StaticRegistry<T> StaticRegistry<T>::INSTANCE;
- void initializeBlockTypes();
- void initializeItemTypes();
- void initializeEntityTypes();
- void initializeDimensions();
- void initializeMultiblockTypes();
|