- fixed 'When you jump into the roof or a bonus and fall back down you collide with...
[supertux.git] / src / display_manager.h
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef __DISPLAY_MANAGER_H__
20 #define __DISPLAY_MANAGER_H__
21
22 #include <vector>
23
24 #include "drawable.h"
25 #include "camera.h"
26
27 // some constants for predefined layer values
28 enum {
29   LAYER_BACKGROUND0 = -300,
30   LAYER_BACKGROUND1 = -200,
31   LAYER_BACKGROUNDTILES = -100,
32   LAYER_TILES = 0,
33   LAYER_OBJECTS = 100,
34   LAYER_FOREGROUNDTILES = 200,
35   LAYER_FOREGROUND0 = 300,
36   LAYER_FOREGROUND1 = 400
37 };
38
39 /** This class holds a list of all things that should be drawn to screen
40  */
41 class DisplayManager
42 {
43 public:
44   DisplayManager();
45   ~DisplayManager();
46   
47   /** adds an object to the list of stuff that should be drawn each frame.
48    * The layer argument specifies how early an object is drawn.
49    */
50   void add_drawable(Drawable* object, int layer);
51
52   void remove_drawable(Drawable* object);
53
54   void draw(Camera& camera);
55
56 private:
57   class DrawingQueueEntry {
58   public:
59     DrawingQueueEntry(Drawable* newobject, int newlayer)
60       : object(newobject), layer(newlayer)
61     { }
62
63     bool operator <(int olayer) const
64     {
65       return layer < olayer;
66     }
67
68     Drawable* object;
69     int layer;
70   };
71
72   typedef std::vector<DrawingQueueEntry> DisplayList;
73   DisplayList displaylist;
74 };
75
76 #endif
77