Explorar el Código

Unload resources when not necessary anymore

Daniele Bartolini hace 12 años
padre
commit
a24f8fb368
Se han modificado 1 ficheros con 24 adiciones y 6 borrados
  1. 24 6
      samples/terrain/terrain.cpp

+ 24 - 6
samples/terrain/terrain.cpp

@@ -140,12 +140,12 @@ public:
 
 		terrain.CreateTerrain(64, 64, 1, 0.0f);
 
-		device()->resource_manager()->load("textures/red_north.tga");
-		device()->resource_manager()->load("textures/red_south.tga");
-		device()->resource_manager()->load("textures/red_east.tga");
-		device()->resource_manager()->load("textures/red_west.tga");
-		device()->resource_manager()->load("textures/red_up.tga");
-		device()->resource_manager()->load("textures/red_down.tga");
+		red_north = device()->resource_manager()->load("textures/red_north.tga");
+		red_south = device()->resource_manager()->load("textures/red_south.tga");
+		red_east  = device()->resource_manager()->load("textures/red_east.tga");
+		red_west  = device()->resource_manager()->load("textures/red_west.tga");
+		red_up    = device()->resource_manager()->load("textures/red_up.tga");
+		red_down  = device()->resource_manager()->load("textures/red_down.tga");
 
 		grass = device()->resource_manager()->load("textures/grass.tga");
 
@@ -155,6 +155,17 @@ public:
 		terrain.UpdateVertexBuffer(true);
 	}
 
+	void on_unload()
+	{
+		device()->resource_manager()->unload(grass);
+		device()->resource_manager()->unload(red_north);
+		device()->resource_manager()->unload(red_south);
+		device()->resource_manager()->unload(red_east);
+		device()->resource_manager()->unload(red_west);
+		device()->resource_manager()->unload(red_up);
+		device()->resource_manager()->unload(red_down);
+	}
+
 	void render(float dt)
 	{
 		Renderer* renderer = device()->renderer();
@@ -234,6 +245,12 @@ private:
 
 	// Resources
 	ResourceId grass;
+	ResourceId red_north;
+	ResourceId red_south;
+	ResourceId red_east;
+	ResourceId red_west;
+	ResourceId red_up;
+	ResourceId red_down;
 
 	bool optShowSkybox;
 	bool optShowCrate;
@@ -255,6 +272,7 @@ public:
 
 	void shutdown()
 	{
+		m_scene.on_unload();
 	}
 
 	void update(float dt)