summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-06-07 22:10:29 +0200
committerAki <nthirtyone@gmail.com>2016-06-07 22:10:29 +0200
commit33b5a2969a0de51f4241f170cafb386efa31cc99 (patch)
tree925c904ff4b1a10cf0ee7bdc2bac439adbc1995f
parent5d9addae1483c5ccfd75b39b50fb950315f9c55e (diff)
downloadroflnauts-33b5a2969a0de51f4241f170cafb386efa31cc99.zip
roflnauts-33b5a2969a0de51f4241f170cafb386efa31cc99.tar.gz
roflnauts-33b5a2969a0de51f4241f170cafb386efa31cc99.tar.bz2
Dest
Destructors to make memory managment a little bit more efficient in long terms.
-rw-r--r--ground.lua6
-rw-r--r--main.lua1
-rw-r--r--menu.lua4
-rw-r--r--player.lua6
-rw-r--r--world.lua12
5 files changed, 29 insertions, 0 deletions
diff --git a/ground.lua b/ground.lua
index fa84506..6800944 100644
--- a/ground.lua
+++ b/ground.lua
@@ -28,6 +28,12 @@ function Ground:new (game, world, x, y, shape, sprite)
return o
end
+-- Destructor of `Ground`
+function Ground:delete ()
+ -- body deletion is handled by world deletion
+ self.sprite = nil
+end
+
-- Draw of `Ground`
function Ground:draw (offset_x, offset_y, scale, debug)
-- defaults
diff --git a/main.lua b/main.lua
index 198e8b5..2fbec32 100644
--- a/main.lua
+++ b/main.lua
@@ -86,6 +86,7 @@ function love.keypressed (key)
end
if key == "f5" and debug then
local new = World:new("default", {"leon", Controllers[1]}, {"lonestar", Controllers[2]})
+ Scene:delete()
changeScene(new)
end
end
diff --git a/menu.lua b/menu.lua
index d18e149..f704a1c 100644
--- a/menu.lua
+++ b/menu.lua
@@ -33,6 +33,10 @@ function Menu:new ()
return o
end
+-- Destructor
+function Menu:delete()
+end
+
-- Naut selector
function Menu:newSelector()
local selector = Selector:new(self)
diff --git a/player.lua b/player.lua
index 7a6a035..f7595a1 100644
--- a/player.lua
+++ b/player.lua
@@ -74,6 +74,12 @@ function Player:new (game, world, x, y, name)
return o
end
+-- Destructor of `Player`
+function Player:delete()
+ -- body deletion is handled by world deletion
+ self.sprite = nil
+end
+
function Player:assignController(controller)
self.controller = controller or nil
controller:setParent(self)
diff --git a/world.lua b/world.lua
index 81d69bc..db0526c 100644
--- a/world.lua
+++ b/world.lua
@@ -65,6 +65,18 @@ function World:new(map, ...)
return o
end
+-- The end of the world
+function World:delete()
+ self.world:destroy()
+ for _,platform in pairs(self.Platforms) do
+ platform:delete()
+ end
+ for _,naut in pairs(self.Nauts) do
+ naut:delete()
+ end
+ self = nil
+end
+
-- Load map from file
function World:loadMap(name)
local name = name or "default"