summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-23 14:51:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-01-23 14:51:57 +0000
commitd7388ee954d9ea7acea346aad4af57764e20dd04 (patch)
tree64bad9cdd4572bd2434c2c23c05c759e27d414c0 /game
parentAdd a basic cache template (diff)
downloadilt-d7388ee954d9ea7acea346aad4af57764e20dd04.tar.bz2
ilt-d7388ee954d9ea7acea346aad4af57764e20dd04.tar.xz
ilt-d7388ee954d9ea7acea346aad4af57764e20dd04.zip
Allow physical objects to share meshes and textures
Diffstat (limited to 'game')
-rw-r--r--game/physical.cpp12
-rw-r--r--game/physical.h15
2 files changed, 20 insertions, 7 deletions
diff --git a/game/physical.cpp b/game/physical.cpp
index f4c17d4..5263268 100644
--- a/game/physical.cpp
+++ b/game/physical.cpp
@@ -1,8 +1,14 @@
#include "physical.h"
+#include "gfx/models/mesh.h"
+#include "gfx/models/texture.h"
+#include <cache.h>
#include <gfx/gl/shader.h>
+Cache<Mesh> Physical::cachedMesh;
+Cache<Texture> Physical::cachedTexture;
+
Physical::Physical(glm::vec3 where, const std::string & m, const std::string & t) :
- location {where}, mesh {m}, texture {t}
+ location {where}, mesh {cachedMesh.get(m)}, texture {cachedTexture.get(t)}
{
}
@@ -10,6 +16,6 @@ void
Physical::render(const Shader & shader, const Camera & camera) const
{
shader.Update(location, camera);
- texture.Bind();
- mesh.Draw();
+ texture->Bind();
+ mesh->Draw();
}
diff --git a/game/physical.h b/game/physical.h
index ff9d316..ad2207d 100644
--- a/game/physical.h
+++ b/game/physical.h
@@ -1,14 +1,16 @@
#ifndef PHYSICAL_H
#define PHYSICAL_H
-#include "gfx/models/mesh.h"
-#include "gfx/models/texture.h"
#include <gfx/gl/transform.h>
#include <glm/glm.hpp>
+#include <memory>
#include <string>
class Camera;
class Shader;
+class Mesh;
+class Texture;
+template<typename Obj> class Cache;
class Physical {
public:
@@ -24,8 +26,13 @@ public:
protected:
Transform location;
- Mesh mesh;
- Texture texture;
+
+ std::shared_ptr<Mesh> mesh;
+ std::shared_ptr<Texture> texture;
+
+private:
+ static Cache<Mesh> cachedMesh;
+ static Cache<Texture> cachedTexture;
};
#endif