|
@@ -0,0 +1,42 @@
|
|
|
+/*
|
|
|
+ * 2D Game Engine
|
|
|
+ * Pool.h:
|
|
|
+ * Based on pikuma.com 2D game engine in C++ and Lua course
|
|
|
+ * Copyright (c) 2021 986-Studio. All rights reserved.
|
|
|
+ *
|
|
|
+ * Created by Manoël Trapier on 11/02/2021.
|
|
|
+ */
|
|
|
+
|
|
|
+#ifndef GAMEENGINE_POOL_H
|
|
|
+#define GAMEENGINE_POOL_H
|
|
|
+
|
|
|
+#include <vector>
|
|
|
+
|
|
|
+class IPool
|
|
|
+{
|
|
|
+public:
|
|
|
+ virtual ~IPool() = default;
|
|
|
+};
|
|
|
+
|
|
|
+template <typename T> class Pool:public IPool
|
|
|
+{
|
|
|
+private:
|
|
|
+ std::vector<T> data;
|
|
|
+
|
|
|
+public:
|
|
|
+ Pool(int size = 100) { this->resize(size); }
|
|
|
+ virtual ~Pool() = default;
|
|
|
+
|
|
|
+ bool isEmpty() const { return this->data.empty(); }
|
|
|
+ void resize(int size) { this->data.reserve(size); }
|
|
|
+ void clear() { this->data.clear(); }
|
|
|
+
|
|
|
+ void add(T object) { this->data.push_back(object); }
|
|
|
+
|
|
|
+ void set(uint32_t index, T object) { this->data[index] = object; }
|
|
|
+ T& get(uint32_t index) { return this->data[index]; }
|
|
|
+
|
|
|
+ T& operator[](uint32_t index) { return this->data[index]; }
|
|
|
+};
|
|
|
+
|
|
|
+#endif /* GAMEENGINE_POOL_H */
|