Issue 952: Unloading/freeing all tilesets prior to shutdown
[supertux.git] / src / supertux / resources.cpp
1 //  SuperTux
2 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
5 //  This program is free software: you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation, either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 #include "supertux/resources.hpp"
19
20 #include "gui/mousecursor.hpp"
21 #include "sprite/sprite_manager.hpp"
22 #include "supertux/player_status.hpp"
23 #include "supertux/tile_manager.hpp"
24 #include "video/font.hpp"
25
26 MouseCursor* Resources::mouse_cursor = NULL;
27
28 FontPtr Resources::fixed_font;
29 FontPtr Resources::normal_font;
30 FontPtr Resources::small_font;
31 FontPtr Resources::big_font;
32
33 SurfacePtr Resources::checkbox;
34 SurfacePtr Resources::checkbox_checked;
35 SurfacePtr Resources::back;
36 SurfacePtr Resources::arrow_left;
37 SurfacePtr Resources::arrow_right;
38
39 TileSet* Resources::general_tiles;
40 TileSet* Resources::worldmap_tiles;
41 TileSet* Resources::iceworld_tiles;
42
43 /* Load graphics/sounds shared between all levels: */
44 void
45 Resources::load_shared()
46 {
47   /* Load the mouse-cursor */
48   mouse_cursor = new MouseCursor("images/engine/menu/mousecursor.png");
49   MouseCursor::set_current(mouse_cursor);
50
51   /* Load global images: */
52   fixed_font.reset(new Font(Font::FIXED, "fonts/white.stf"));
53   normal_font.reset(new Font(Font::VARIABLE, "fonts/white.stf"));
54   small_font.reset(new Font(Font::VARIABLE, "fonts/white-small.stf", 1));
55   big_font.reset(new Font(Font::VARIABLE, "fonts/white-big.stf", 3));
56
57   /* Load menu images */
58   checkbox = Surface::create("images/engine/menu/checkbox-unchecked.png");
59   checkbox_checked = Surface::create("images/engine/menu/checkbox-checked.png");
60   back = Surface::create("images/engine/menu/arrow-back.png");
61   arrow_left = Surface::create("images/engine/menu/arrow-left.png");
62   arrow_right = Surface::create("images/engine/menu/arrow-right.png");
63
64   tile_manager   = new TileManager();
65   sprite_manager = new SpriteManager();
66   
67   /* Create a reference to tilesets */
68   general_tiles = tile_manager->get_tileset("images/tiles.strf");
69   worldmap_tiles = tile_manager->get_tileset("images/worldmap.strf");
70   iceworld_tiles = tile_manager->get_tileset("images/ice_world.strf");
71 }
72
73 /* Free shared data: */
74 void
75 Resources::unload_shared()
76 {
77   /* Free menu images */
78   checkbox.reset();
79   checkbox_checked.reset();
80   back.reset();
81   arrow_left.reset();
82   arrow_right.reset();
83
84   /* Free global images: */
85   fixed_font.reset();
86   normal_font.reset();
87   small_font.reset();
88   big_font.reset();
89   
90   /* Free tilesets */
91   delete worldmap_tiles;
92   worldmap_tiles = NULL;
93   delete general_tiles;
94   general_tiles = NULL;
95   delete iceworld_tiles;
96   iceworld_tiles = NULL;
97
98   delete sprite_manager;
99   sprite_manager = NULL;
100
101   /* Free mouse-cursor */
102   mouse_cursor->cursor.reset();
103   delete mouse_cursor;
104 }
105
106 /* EOF */