HoverRace  2.0
Track.h
Go to the documentation of this file.
1 
2 // Track.h
3 //
4 // Copyright (c) 2010, 2014-2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "../Display/Res.h"
25 #include "../Vec.h"
26 
27 #include "TrackEntry.h"
28 
29 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
30 # ifdef MR_ENGINE
31 # define MR_DllDeclare __declspec( dllexport )
32 # else
33 # define MR_DllDeclare __declspec( dllimport )
34 # endif
35 #else
36 # define MR_DllDeclare
37 #endif
38 
39 namespace HoverRace {
40  namespace Model {
41  class FreeElementBase;
42  class GameOptions;
43  class Level;
44  }
45  namespace Parcel {
46  class RecordFile;
47  }
48 }
49 
50 namespace HoverRace {
51 namespace Model {
52 
58 {
60 
61 private:
62  Track() = delete;
63 public:
64  Track(const std::string &name,
65  std::shared_ptr<Parcel::RecordFile> recFile = {});
66  virtual ~Track();
67 
68  Parcel::RecordFile *GetRecordFile() const { return recFile.get(); }
69  std::shared_ptr<Parcel::RecordFile> ShareRecordFile() const { return recFile; }
70  const TrackEntry &GetHeader() const { return header; }
71  Level *GetLevel() const { return level.get(); }
72 
77  const Vec2 &GetOffset() const { return offset; }
78 
83  const Vec2 &GetSize() const { return size; }
84 
85  std::shared_ptr<Display::Res<Display::Texture>> GetMap() const { return map; }
86 
91  double GetGravity() const { return physics.gravity; }
92 
97  void SetGravity(double gravity) { this->physics.gravity = gravity; }
98 
103  void AddFreeElement(std::shared_ptr<Model::FreeElementBase> elem)
104  {
105  freeElements.emplace_back(std::move(elem));
106  }
107 
108 public:
109  void Inspect(Util::InspectMapNode &node) const override;
110 
111 private:
112  void LoadHeader();
113  void LoadLevel(bool allowRendering, const GameOptions &gameOpts);
114  void LoadMap();
115 
116 public:
117  void Load(bool allowRendering, const GameOptions &gameOpts);
118 
119 private:
120  std::shared_ptr<Parcel::RecordFile> recFile;
122  std::unique_ptr<Level> level;
125  std::shared_ptr<Display::Res<Display::Texture>> map;
126  std::list<std::shared_ptr<Model::FreeElementBase>> freeElements;
127 
128  struct Physics
129  {
130  Physics();
131 
132  double gravity;
133  } physics;
134 };
135 
136 } // namespace Model
137 } // namespace HoverRace
138 
139 #undef MR_DllDeclare
double gravity
Definition: Track.h:132
Level
Definition: Log.h:62
An inspection node which maps field names to values (either strings or inspectable subobjects)...
Definition: InspectMapNode.h:88
Definition: Inspectable.h:41
Base class for parcel implementations.
Definition: RecordFile.h:46
TrackEntry header
Definition: Track.h:121
Definition: Vec.h:38
const Vec2 & GetSize() const
Retrieve the size of the track.
Definition: Track.h:83
#define MR_DllDeclare
Definition: Track.h:36
std::shared_ptr< Parcel::RecordFile > recFile
Definition: Track.h:120
The metadata for a track.
Definition: TrackEntry.h:54
Vec2 offset
Definition: Track.h:123
A track level.
Definition: Track.h:57
const TrackEntry & GetHeader() const
Definition: Track.h:70
std::shared_ptr< Display::Res< Display::Texture > > GetMap() const
Definition: Track.h:85
Definition: GameOptions.h:41
std::shared_ptr< Parcel::RecordFile > ShareRecordFile() const
Definition: Track.h:69
Definition: Track.h:128
std::unordered_map< std::string, std::string > map
Definition: SdlDisplay.cpp:115
const Vec2 & GetOffset() const
Retrieve the coordinates of the north-west corner of the track.
Definition: Track.h:77
std::unique_ptr< Level > level
Definition: Track.h:122
Definition: Level.h:74
Definition: Announcement.h:24
Level * GetLevel() const
Definition: Track.h:71
void AddFreeElement(std::shared_ptr< Model::FreeElementBase > elem)
Add a FreeElement to be managed by this Track.
Definition: Track.h:103
double GetGravity() const
Gets the gravity multiplier.
Definition: Track.h:91
Parcel::RecordFile * GetRecordFile() const
Definition: Track.h:68
std::shared_ptr< Display::Res< Display::Texture > > map
Definition: Track.h:125
std::list< std::shared_ptr< Model::FreeElementBase > > freeElements
Definition: Track.h:126
void SetGravity(double gravity)
Set the current gravity multiplier.
Definition: Track.h:97
Vec2 size
Definition: Track.h:124
std::string header
Definition: Observer.cpp:60