Debian Codegraph @

src/game/track.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2011 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef TRACK_HPP
17 #define TRACK_HPP
18
19 #include "tracktile.hpp"
20 #include "updateableif.hpp"
21
22 #include <MCBBox>
23 #include <MCGLShaderProgram>
24
25 #include <memory>
26
27 class TrackData;
28 class MCCamera;
29 class MCSurface;
30
31 //! A renderable race track object constructed from
32 //! the given track data.
33 class Track
34 {
35 public:
36 /*! Constructor.
37 * \param trackData The data that represents the track. */
38 explicit Track(std::unique_ptr<TrackData> trackData);
39
40 //! Render as seen through the given camera window.
41 void render(MCCamera & camera);
42
43 //! Return width in length units.
44 size_t width() const;
45
46 //! Return height in length units.
47 size_t height() const;
48
49 //! Return the track data.
50 TrackData & trackData() const;
51
52 //! Return pointer to the tile at the given location.
53 //! It is assumed that x >= 0 and y >= 0.
54 TrackTileS trackTileAtLocation(float x, float y) const;
55
56 //! Return pointer to the finish line tile.
57 TrackTileS finishLine() const;
58
59 //! Set the next track.
60 void setNext(std::weak_ptr<Track> next);
61
62 //! Return the next track or nullptr.
63 std::weak_ptr<Track> next() const;
64
65 //! Set the prev track.
66 void setPrev(std::weak_ptr<Track> prev);
67
68 //! Return the prev track or nullptr.
69 std::weak_ptr<Track> prev() const;
70
71 private:
72 void calculateVisibleIndices(const MCBBox<int> & r, size_t & i0, size_t & i2, size_t & j0, size_t & j2);
73
74 void renderAsphalt(MCCamera & camera, MCGLShaderProgramPtr prog, size_t i0, size_t i2, size_t j0, size_t j2);
75
76 void renderTiles(MCCamera & camera, MCGLShaderProgramPtr prog, size_t i0, size_t i2, size_t j0, size_t j2);
77
78 std::unique_ptr<TrackData> m_trackData;
79
80 size_t m_rows, m_cols, m_width, m_height;
81
82 std::shared_ptr<MCSurface> m_asphalt;
83
84 std::weak_ptr<Track> m_next;
85
86 std::weak_ptr<Track> m_prev;
87 };
88
89 #endif // TRACK_HPP