HoverRace  2.0
Res.h
Go to the documentation of this file.
1 
2 // Res.h
3 //
4 // Copyright (c) 2014 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 "../Util/MR_Types.h"
25 #include "../Exception.h"
26 
27 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
28 # ifdef MR_ENGINE
29 # define MR_DllDeclare __declspec( dllexport )
30 # else
31 # define MR_DllDeclare __declspec( dllimport )
32 # endif
33 #else
34 # define MR_DllDeclare
35 #endif
36 
37 namespace HoverRace {
38  namespace Display {
39  class Texture;
40  }
41 }
42 
43 
44 namespace HoverRace {
45 namespace Display {
46 
47 class ResLoadExn;
48 
49 class BaseRes
50 {
51 public:
52  virtual ~BaseRes() { }
53 
54 public:
68  virtual std::string GetId() const = 0;
69 
75  virtual std::unique_ptr<std::istream> Open() const = 0;
76 };
77 
82 template<class T>
83 class Res : public BaseRes
84 {
85 public:
86  virtual ~Res() { }
87 };
88 
93 template<>
94 class Res<Texture> : public BaseRes
95 {
96 public:
97  virtual ~Res() { }
98 
99 public:
100  struct ImageData
101  {
102  ImageData() : pixels(),
103  width(0), height(0), depth(32), pitch(0),
104  rMask(0), gMask(0), bMask(0), aMask(0) { }
105  ImageData(const ImageData &o) = delete;
106  ImageData(ImageData &&o) = default;
107 
108  ImageData &operator=(const ImageData &o) = delete;
109  ImageData &operator=(ImageData &&o) = default;
110 
111  std::unique_ptr<MR_UInt8[]> pixels;
112  int width;
113  int height;
114  int depth;
115  int pitch;
120  };
121 
122 public:
132  virtual bool IsGenerated() const
133  {
134  return false;
135  }
136 
142  virtual const ImageData *GetImageData()
143  {
144  return nullptr;
145  }
146 };
147 
152 class ResLoadExn : public Exception
153 {
154  typedef Exception SUPER;
155 
156 public:
157  ResLoadExn() : SUPER() { }
158  ResLoadExn(const std::string &msg) : SUPER(msg) { }
159  ResLoadExn(const char *msg) : SUPER(msg) { }
160  virtual ~ResLoadExn() noexcept { }
161 };
162 
163 } // namespace Display
164 } // namespace HoverRace
165 
166 #undef MR_DllDeclare
ResLoadExn(const char *msg)
Definition: Res.h:159
A resource failed to load.
Definition: Res.h:152
virtual const ImageData * GetImageData()
If IsGenerated() is true, returns the image data necessary to create the texture. ...
Definition: Res.h:142
virtual ~BaseRes()
Definition: Res.h:52
MR_UInt32 aMask
Definition: Res.h:119
virtual ~Res()
Definition: Res.h:86
A hardware texture.
Definition: Texture.h:41
virtual ~Res()
Definition: Res.h:97
Definition: Res.h:49
virtual ~ResLoadExn() noexcept
Definition: Res.h:160
ResLoadExn()
Definition: Res.h:157
MR_UInt32 bMask
Definition: Res.h:118
virtual bool IsGenerated() const
Check if this texture is generated from memory rather than an input stream.
Definition: Res.h:132
std::unique_ptr< MR_UInt8[]> pixels
Definition: Res.h:111
ResLoadExn(const std::string &msg)
Definition: Res.h:158
Base class for loadable resources.
Definition: Res.h:83
MR_UInt32 rMask
Definition: Res.h:116
Definition: Announcement.h:24
uint32_t MR_UInt32
Definition: MR_Types.h:44
Exception SUPER
Definition: Res.h:154
Base exception, providing constructors for setting the message.
Definition: Exception.h:42
MR_UInt32 gMask
Definition: Res.h:117