gosu 0.8.6-x86-mingw32 → 0.8.7-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Audio.hpp +171 -171
  3. data/Gosu/Bitmap.hpp +96 -96
  4. data/Gosu/Color.hpp +204 -204
  5. data/Gosu/Directories.hpp +36 -36
  6. data/Gosu/Font.hpp +83 -83
  7. data/Gosu/Gosu.hpp +34 -34
  8. data/Gosu/Graphics.hpp +115 -115
  9. data/Gosu/GraphicsBase.hpp +110 -110
  10. data/Gosu/IO.hpp +269 -269
  11. data/Gosu/Image.hpp +122 -122
  12. data/Gosu/ImageData.hpp +61 -61
  13. data/Gosu/Input.hpp +149 -149
  14. data/Gosu/Inspection.hpp +14 -14
  15. data/Gosu/Math.hpp +135 -135
  16. data/Gosu/Platform.hpp +93 -93
  17. data/Gosu/Sockets.hpp +156 -156
  18. data/Gosu/TR1.hpp +56 -56
  19. data/Gosu/Text.hpp +71 -71
  20. data/Gosu/TextInput.hpp +70 -70
  21. data/Gosu/Utility.hpp +28 -28
  22. data/Gosu/Version.hpp +19 -19
  23. data/Gosu/Window.hpp +145 -145
  24. data/examples/ChipmunkIntegration.rb +275 -275
  25. data/examples/CptnRuby.rb +223 -223
  26. data/examples/GosuZen.rb +68 -68
  27. data/examples/MoreChipmunkAndRMagick.rb +155 -155
  28. data/examples/OpenGLIntegration.rb +225 -225
  29. data/examples/RMagickIntegration.rb +417 -417
  30. data/examples/TextInput.rb +154 -154
  31. data/examples/Tutorial.rb +130 -130
  32. data/examples/media/Beep.wav +0 -0
  33. data/examples/media/CptnRuby Map.txt b/data/examples/media/CptnRuby → Map.txt +0 -0
  34. data/examples/media/Explosion.wav +0 -0
  35. data/examples/media/Landscape.svg +9 -9
  36. data/examples/media/Space.png +0 -0
  37. data/examples/media/Star.png +0 -0
  38. data/examples/media/Starfighter.bmp +0 -0
  39. data/lib/1.8/gosu.so +0 -0
  40. data/lib/1.9/gosu.so +0 -0
  41. data/lib/2.0/gosu.so +0 -0
  42. data/lib/2.1/gosu.so +0 -0
  43. data/lib/FreeImage.dll +0 -0
  44. data/lib/OpenAL32.dll +0 -0
  45. data/lib/gosu.rb +19 -16
  46. data/lib/gosu/patches.rb +81 -81
  47. data/lib/gosu/preview.rb +143 -139
  48. data/lib/gosu/run.rb +11 -11
  49. data/lib/gosu/swig_patches.rb +60 -60
  50. data/lib/gosu/zen.rb +89 -89
  51. metadata +5 -5
@@ -1,110 +1,110 @@
1
- //! \file GraphicsBase.hpp
2
- //! Contains general typedefs and enums related to graphics.
3
-
4
- #ifndef GOSU_GRAPHICSBASE_HPP
5
- #define GOSU_GRAPHICSBASE_HPP
6
-
7
- #include <Gosu/Platform.hpp>
8
- #include <Gosu/TR1.hpp>
9
- #include <limits>
10
-
11
- namespace Gosu
12
- {
13
- //! Represents the Z position of something drawn with Gosu's graphics
14
- //! system. Draw calls with higher ZPos values will cover those with a
15
- //! lower ZPos value, that is, they are performed last.
16
- typedef double ZPos;
17
-
18
- //! Determines the way colors are combined when one is drawn onto
19
- //! another.
20
- #if defined(GOSU_CPP11_ENABLED)
21
- enum class AlphaMode
22
- {
23
- //! The color's channels will be interpolated. The alpha channel
24
- //! specifies the opacity of the new color, 255 is full opacity.
25
- DEFAULT,
26
- INTERPOLATE = DEFAULT,
27
- //! The colors' channels will be added. The alpha channel specifies
28
- //! the percentage of the new color's channels that will be added
29
- //! to the old color's channels.
30
- ADD,
31
- //! The color's channels will be multiplied with each other.
32
- MULTIPLY
33
- };
34
- GOSU_DEPRECATED constexpr AlphaMode amDefault = AlphaMode::DEFAULT;
35
- GOSU_DEPRECATED constexpr AlphaMode amInterpolate = AlphaMode::INTERPOLATE;
36
- GOSU_DEPRECATED constexpr AlphaMode amAdd = AlphaMode::ADD;
37
- GOSU_DEPRECATED constexpr AlphaMode amAdditive = AlphaMode::ADD;
38
- GOSU_DEPRECATED constexpr AlphaMode amMultiply = AlphaMode::MULTIPLY;
39
- #else
40
- enum AlphaMode
41
- {
42
- //! The color's channels will be interpolated. The alpha channel
43
- //! specifies the opacity of the new color, 255 is full opacity.
44
- amDefault,
45
- //! The colors' channels will be added. The alpha channel specifies
46
- //! the percentage of the new color's channels that will be added
47
- //! to the old color's channels.
48
- amAdd,
49
- amAdditive = amAdd,
50
- //! The color's channels will be multiplied with each other.
51
- amMultiply
52
- };
53
- #endif
54
-
55
- enum FontFlags
56
- {
57
- ffBold = 1,
58
- ffItalic = 2,
59
- ffUnderline = 4,
60
- ffCombinations = 8
61
- };
62
-
63
- enum TextAlign
64
- {
65
- taLeft,
66
- taRight,
67
- taCenter,
68
- taJustify
69
- };
70
-
71
- //! Flags that affect the tileability of an image.
72
- enum BorderFlags
73
- {
74
- bfSmooth = 0,
75
- bfTileableLeft = 1,
76
- bfTileableTop = 2,
77
- bfTileableRight = 4,
78
- bfTileableBottom = 8,
79
- bfTileable = bfTileableLeft | bfTileableTop | bfTileableRight | bfTileableBottom
80
- };
81
-
82
- #ifdef GOSU_IS_MAC
83
- // TODO: Without this gigantic hack, Gosu crashes in the "scale" function,
84
- // but _only_ when used from Ruby 1.9. It is unclear what might cause this -
85
- // maybe a compiler bug that tries to use SSE functions with the wrong
86
- // alignment. Adding __attribute__((aligned(16))) does not help, though.
87
- struct Transform
88
- {
89
- double value[16];
90
- bool operator==(const Transform &other) { for (int i = 0; i < 16; ++i) if ((*this)[i] != other[i]) return false; return true; }
91
- const double &operator[](std::size_t idx) const { return value[idx]; }
92
- double &operator[](std::size_t idx) { return value[idx]; }
93
- };
94
- #else
95
- typedef std::tr1::array<double, 16> Transform;
96
- #endif
97
- Transform translate(double x, double y);
98
- Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
99
- Transform scale(double factor);
100
- Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
101
- Transform concat(const Transform& lhs, const Transform& rhs);
102
-
103
- #ifndef SWIG
104
- // A not so useful optimization - this was supposed to bypass the Z queue for immediate rendering.
105
- // In retrospect, the only useful optimization would be to work down the Z queue on a second thread.
106
- GOSU_DEPRECATED const double zImmediate = -std::numeric_limits<double>::infinity();
107
- #endif
108
- }
109
-
110
- #endif
1
+ //! \file GraphicsBase.hpp
2
+ //! Contains general typedefs and enums related to graphics.
3
+
4
+ #ifndef GOSU_GRAPHICSBASE_HPP
5
+ #define GOSU_GRAPHICSBASE_HPP
6
+
7
+ #include <Gosu/Platform.hpp>
8
+ #include <Gosu/TR1.hpp>
9
+ #include <limits>
10
+
11
+ namespace Gosu
12
+ {
13
+ //! Represents the Z position of something drawn with Gosu's graphics
14
+ //! system. Draw calls with higher ZPos values will cover those with a
15
+ //! lower ZPos value, that is, they are performed last.
16
+ typedef double ZPos;
17
+
18
+ //! Determines the way colors are combined when one is drawn onto
19
+ //! another.
20
+ #if defined(GOSU_CPP11_ENABLED)
21
+ enum class AlphaMode
22
+ {
23
+ //! The color's channels will be interpolated. The alpha channel
24
+ //! specifies the opacity of the new color, 255 is full opacity.
25
+ DEFAULT,
26
+ INTERPOLATE = DEFAULT,
27
+ //! The colors' channels will be added. The alpha channel specifies
28
+ //! the percentage of the new color's channels that will be added
29
+ //! to the old color's channels.
30
+ ADD,
31
+ //! The color's channels will be multiplied with each other.
32
+ MULTIPLY
33
+ };
34
+ GOSU_DEPRECATED constexpr AlphaMode amDefault = AlphaMode::DEFAULT;
35
+ GOSU_DEPRECATED constexpr AlphaMode amInterpolate = AlphaMode::INTERPOLATE;
36
+ GOSU_DEPRECATED constexpr AlphaMode amAdd = AlphaMode::ADD;
37
+ GOSU_DEPRECATED constexpr AlphaMode amAdditive = AlphaMode::ADD;
38
+ GOSU_DEPRECATED constexpr AlphaMode amMultiply = AlphaMode::MULTIPLY;
39
+ #else
40
+ enum AlphaMode
41
+ {
42
+ //! The color's channels will be interpolated. The alpha channel
43
+ //! specifies the opacity of the new color, 255 is full opacity.
44
+ amDefault,
45
+ //! The colors' channels will be added. The alpha channel specifies
46
+ //! the percentage of the new color's channels that will be added
47
+ //! to the old color's channels.
48
+ amAdd,
49
+ amAdditive = amAdd,
50
+ //! The color's channels will be multiplied with each other.
51
+ amMultiply
52
+ };
53
+ #endif
54
+
55
+ enum FontFlags
56
+ {
57
+ ffBold = 1,
58
+ ffItalic = 2,
59
+ ffUnderline = 4,
60
+ ffCombinations = 8
61
+ };
62
+
63
+ enum TextAlign
64
+ {
65
+ taLeft,
66
+ taRight,
67
+ taCenter,
68
+ taJustify
69
+ };
70
+
71
+ //! Flags that affect the tileability of an image.
72
+ enum BorderFlags
73
+ {
74
+ bfSmooth = 0,
75
+ bfTileableLeft = 1,
76
+ bfTileableTop = 2,
77
+ bfTileableRight = 4,
78
+ bfTileableBottom = 8,
79
+ bfTileable = bfTileableLeft | bfTileableTop | bfTileableRight | bfTileableBottom
80
+ };
81
+
82
+ #ifdef GOSU_IS_MAC
83
+ // TODO: Without this gigantic hack, Gosu crashes in the "scale" function,
84
+ // but _only_ when used from Ruby 1.9. It is unclear what might cause this -
85
+ // maybe a compiler bug that tries to use SSE functions with the wrong
86
+ // alignment. Adding __attribute__((aligned(16))) does not help, though.
87
+ struct Transform
88
+ {
89
+ double value[16];
90
+ bool operator==(const Transform &other) { for (int i = 0; i < 16; ++i) if ((*this)[i] != other[i]) return false; return true; }
91
+ const double &operator[](std::size_t idx) const { return value[idx]; }
92
+ double &operator[](std::size_t idx) { return value[idx]; }
93
+ };
94
+ #else
95
+ typedef std::tr1::array<double, 16> Transform;
96
+ #endif
97
+ Transform translate(double x, double y);
98
+ Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
99
+ Transform scale(double factor);
100
+ Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
101
+ Transform concat(const Transform& lhs, const Transform& rhs);
102
+
103
+ #ifndef SWIG
104
+ // A not so useful optimization - this was supposed to bypass the Z queue for immediate rendering.
105
+ // In retrospect, the only useful optimization would be to work down the Z queue on a second thread.
106
+ GOSU_DEPRECATED const double zImmediate = -std::numeric_limits<double>::infinity();
107
+ #endif
108
+ }
109
+
110
+ #endif
@@ -1,269 +1,269 @@
1
- //! \file IO.hpp
2
- //! Contains everything related to input and output.
3
-
4
- #ifndef GOSU_IO_HPP
5
- #define GOSU_IO_HPP
6
-
7
- #include <cstddef>
8
- #include <algorithm>
9
- #include <memory>
10
- #include <string>
11
- #include <vector>
12
- #include <Gosu/Platform.hpp>
13
-
14
- namespace Gosu
15
- {
16
- class Resource;
17
-
18
- enum ByteOrder { boLittle, boBig, boDontCare };
19
- #ifdef __BIG_ENDIAN__
20
- const ByteOrder nativeByteOrder = boBig, otherByteOrder = boLittle;
21
- #else
22
- const ByteOrder nativeByteOrder = boLittle, otherByteOrder = boBig;
23
- #endif
24
-
25
- //! Utility class that points to a specific position in a resource
26
- //! and offers an interface for sequential reading.
27
- class Reader
28
- {
29
- const Resource* res;
30
- std::size_t pos;
31
-
32
- public:
33
- Reader(const Resource& resource, std::size_t position)
34
- : res(&resource), pos(position)
35
- {
36
- }
37
-
38
- const Resource& resource() const
39
- {
40
- return *res;
41
- }
42
-
43
- std::size_t position() const
44
- {
45
- return pos;
46
- }
47
-
48
- void setPosition(std::size_t value)
49
- {
50
- // TODO: Check?
51
- pos = value;
52
- }
53
-
54
- void seek(std::ptrdiff_t offset)
55
- {
56
- // TODO: Check?
57
- pos += offset;
58
- }
59
-
60
- void read(void* destBuffer, std::size_t length);
61
-
62
- //! Convenience function; equivalent to read(&t, sizeof t).
63
- template<typename T>
64
- void readPod(T& t, ByteOrder bo = boDontCare)
65
- {
66
- read(&t, sizeof t);
67
- if (bo == otherByteOrder)
68
- {
69
- char* begin = reinterpret_cast<char*>(&t);
70
- std::reverse(begin, begin + sizeof t);
71
- }
72
- }
73
-
74
- //! Similar to readPod(T&), but returns the read value instead.
75
- template<typename T>
76
- T getPod(ByteOrder bo = boDontCare)
77
- {
78
- T t;
79
- readPod<T>(t, bo);
80
- return t;
81
- }
82
- };
83
-
84
- //! Utility class that points to a specific position in a resource
85
- //! and offers an interface for sequential writing.
86
- class Writer
87
- {
88
- Resource* res;
89
- std::size_t pos;
90
-
91
- public:
92
- Writer(Resource& resource, std::size_t position)
93
- : res(&resource), pos(position)
94
- {
95
- }
96
-
97
- Resource& resource() const
98
- {
99
- return *res;
100
- }
101
-
102
- std::size_t position() const
103
- {
104
- return pos;
105
- }
106
-
107
- void setPosition(std::size_t value)
108
- {
109
- // TODO: Check?
110
- pos = value;
111
- }
112
-
113
- void seek(std::ptrdiff_t offset)
114
- {
115
- // TODO: Check?
116
- pos += offset;
117
- }
118
-
119
- void write(const void* sourceBuffer, std::size_t length);
120
-
121
- //! Convenience function; equivalent to write(&t, sizeof t).
122
- template<typename T>
123
- void writePod(const T& t, ByteOrder bo = boDontCare)
124
- {
125
- if (bo == otherByteOrder)
126
- {
127
- char buf[sizeof t];
128
- const char* begin = reinterpret_cast<const char*>(&t);
129
- std::reverse_copy(begin, begin + sizeof t, buf);
130
- write(buf, sizeof buf);
131
- }
132
- else
133
- write(&t, sizeof t);
134
- }
135
- };
136
-
137
- //! Base class for resources. A resource in Gosu is nothing more but a
138
- //! piece of binary data that can be read or written, for example files
139
- //! or simply areas of allocated memory.
140
- //! A resource always knows its size and can resize itself, thereby either
141
- //! truncating its content or allocating room for more data.
142
- class Resource
143
- {
144
- // Non-copyable
145
- #if defined(GOSU_CPP11_ENABLED)
146
- Resource(const Resource&) = delete;
147
- Resource& operator=(const Resource&) = delete;
148
- // and non-movable
149
- Resource(Resource&&) = delete;
150
- Resource& operator=(Resource&&) = delete;
151
- #else
152
- Resource(const Resource&);
153
- Resource& operator=(const Resource&);
154
- #endif
155
-
156
- public:
157
- Resource()
158
- {
159
- }
160
-
161
- virtual ~Resource()
162
- {
163
- }
164
-
165
- //! Convenience: Creates a new Reader that reads from the start of
166
- //! the resource.
167
- Reader frontReader() const
168
- {
169
- return Reader(*this, 0);
170
- }
171
-
172
- //! Convenience: Creates a new Writer that appends data at the
173
- //! end of the resource.
174
- Writer backWriter()
175
- {
176
- return Writer(*this, size());
177
- }
178
-
179
- virtual std::size_t size() const = 0;
180
-
181
- virtual void resize(std::size_t newSize) = 0;
182
-
183
- virtual void read(std::size_t offset, std::size_t length,
184
- void* destBuffer) const = 0;
185
-
186
- virtual void write(std::size_t offset, std::size_t length,
187
- const void* sourceBuffer) = 0;
188
- };
189
-
190
- //! Piece of memory with the Resource interface.
191
- class Buffer : public Resource
192
- {
193
- std::vector<char> buf;
194
-
195
- public:
196
- Buffer()
197
- {
198
- }
199
-
200
- Buffer(const Buffer& other)
201
- : Resource()
202
- , buf(other.buf)
203
- {
204
- }
205
-
206
- Buffer& operator=(const Buffer& other)
207
- {
208
- buf = other.buf;
209
- return *this;
210
- }
211
-
212
- std::size_t size() const;
213
- void resize(std::size_t newSize);
214
-
215
- void read(std::size_t offset, std::size_t length,
216
- void* destBuffer) const;
217
-
218
- void write(std::size_t offset, std::size_t length,
219
- const void* sourceBuffer);
220
-
221
- const void* data() const
222
- {
223
- return &buf[0];
224
- }
225
-
226
- void* data()
227
- {
228
- return &buf[0];
229
- }
230
- };
231
-
232
- enum FileMode
233
- {
234
- //! Opens an existing file for reading; throws an exception if the file
235
- //! cannot be found.
236
- fmRead,
237
- //! Writes data to a file. If the file already exists, is emptied on
238
- //! opening. If the file does not exist, it is created.
239
- fmReplace,
240
- //! Opens or creates a file with writing access, but does not clear
241
- //! existing contents.
242
- fmAlter
243
- };
244
-
245
- //! File with the Resource interface.
246
- class File : public Resource
247
- {
248
- struct Impl;
249
- const GOSU_UNIQUE_PTR<Impl> pimpl;
250
-
251
- public:
252
- explicit File(const std::wstring& filename, FileMode mode = fmRead);
253
- ~File();
254
-
255
- std::size_t size() const;
256
- void resize(std::size_t newSize);
257
- void read(std::size_t offset, std::size_t length,
258
- void* destBuffer) const;
259
- void write(std::size_t offset, std::size_t length,
260
- const void* sourceBuffer);
261
- };
262
-
263
- //! Loads a whole file into a buffer.
264
- void loadFile(Buffer& buffer, const std::wstring& filename);
265
- //! Creates or overwrites a file with the contents of a buffer.
266
- void saveFile(const Buffer& buffer, const std::wstring& filename);
267
- }
268
-
269
- #endif
1
+ //! \file IO.hpp
2
+ //! Contains everything related to input and output.
3
+
4
+ #ifndef GOSU_IO_HPP
5
+ #define GOSU_IO_HPP
6
+
7
+ #include <cstddef>
8
+ #include <algorithm>
9
+ #include <memory>
10
+ #include <string>
11
+ #include <vector>
12
+ #include <Gosu/Platform.hpp>
13
+
14
+ namespace Gosu
15
+ {
16
+ class Resource;
17
+
18
+ enum ByteOrder { boLittle, boBig, boDontCare };
19
+ #ifdef __BIG_ENDIAN__
20
+ const ByteOrder nativeByteOrder = boBig, otherByteOrder = boLittle;
21
+ #else
22
+ const ByteOrder nativeByteOrder = boLittle, otherByteOrder = boBig;
23
+ #endif
24
+
25
+ //! Utility class that points to a specific position in a resource
26
+ //! and offers an interface for sequential reading.
27
+ class Reader
28
+ {
29
+ const Resource* res;
30
+ std::size_t pos;
31
+
32
+ public:
33
+ Reader(const Resource& resource, std::size_t position)
34
+ : res(&resource), pos(position)
35
+ {
36
+ }
37
+
38
+ const Resource& resource() const
39
+ {
40
+ return *res;
41
+ }
42
+
43
+ std::size_t position() const
44
+ {
45
+ return pos;
46
+ }
47
+
48
+ void setPosition(std::size_t value)
49
+ {
50
+ // TODO: Check?
51
+ pos = value;
52
+ }
53
+
54
+ void seek(std::ptrdiff_t offset)
55
+ {
56
+ // TODO: Check?
57
+ pos += offset;
58
+ }
59
+
60
+ void read(void* destBuffer, std::size_t length);
61
+
62
+ //! Convenience function; equivalent to read(&t, sizeof t).
63
+ template<typename T>
64
+ void readPod(T& t, ByteOrder bo = boDontCare)
65
+ {
66
+ read(&t, sizeof t);
67
+ if (bo == otherByteOrder)
68
+ {
69
+ char* begin = reinterpret_cast<char*>(&t);
70
+ std::reverse(begin, begin + sizeof t);
71
+ }
72
+ }
73
+
74
+ //! Similar to readPod(T&), but returns the read value instead.
75
+ template<typename T>
76
+ T getPod(ByteOrder bo = boDontCare)
77
+ {
78
+ T t;
79
+ readPod<T>(t, bo);
80
+ return t;
81
+ }
82
+ };
83
+
84
+ //! Utility class that points to a specific position in a resource
85
+ //! and offers an interface for sequential writing.
86
+ class Writer
87
+ {
88
+ Resource* res;
89
+ std::size_t pos;
90
+
91
+ public:
92
+ Writer(Resource& resource, std::size_t position)
93
+ : res(&resource), pos(position)
94
+ {
95
+ }
96
+
97
+ Resource& resource() const
98
+ {
99
+ return *res;
100
+ }
101
+
102
+ std::size_t position() const
103
+ {
104
+ return pos;
105
+ }
106
+
107
+ void setPosition(std::size_t value)
108
+ {
109
+ // TODO: Check?
110
+ pos = value;
111
+ }
112
+
113
+ void seek(std::ptrdiff_t offset)
114
+ {
115
+ // TODO: Check?
116
+ pos += offset;
117
+ }
118
+
119
+ void write(const void* sourceBuffer, std::size_t length);
120
+
121
+ //! Convenience function; equivalent to write(&t, sizeof t).
122
+ template<typename T>
123
+ void writePod(const T& t, ByteOrder bo = boDontCare)
124
+ {
125
+ if (bo == otherByteOrder)
126
+ {
127
+ char buf[sizeof t];
128
+ const char* begin = reinterpret_cast<const char*>(&t);
129
+ std::reverse_copy(begin, begin + sizeof t, buf);
130
+ write(buf, sizeof buf);
131
+ }
132
+ else
133
+ write(&t, sizeof t);
134
+ }
135
+ };
136
+
137
+ //! Base class for resources. A resource in Gosu is nothing more but a
138
+ //! piece of binary data that can be read or written, for example files
139
+ //! or simply areas of allocated memory.
140
+ //! A resource always knows its size and can resize itself, thereby either
141
+ //! truncating its content or allocating room for more data.
142
+ class Resource
143
+ {
144
+ // Non-copyable
145
+ #if defined(GOSU_CPP11_ENABLED)
146
+ Resource(const Resource&) = delete;
147
+ Resource& operator=(const Resource&) = delete;
148
+ // and non-movable
149
+ Resource(Resource&&) = delete;
150
+ Resource& operator=(Resource&&) = delete;
151
+ #else
152
+ Resource(const Resource&);
153
+ Resource& operator=(const Resource&);
154
+ #endif
155
+
156
+ public:
157
+ Resource()
158
+ {
159
+ }
160
+
161
+ virtual ~Resource()
162
+ {
163
+ }
164
+
165
+ //! Convenience: Creates a new Reader that reads from the start of
166
+ //! the resource.
167
+ Reader frontReader() const
168
+ {
169
+ return Reader(*this, 0);
170
+ }
171
+
172
+ //! Convenience: Creates a new Writer that appends data at the
173
+ //! end of the resource.
174
+ Writer backWriter()
175
+ {
176
+ return Writer(*this, size());
177
+ }
178
+
179
+ virtual std::size_t size() const = 0;
180
+
181
+ virtual void resize(std::size_t newSize) = 0;
182
+
183
+ virtual void read(std::size_t offset, std::size_t length,
184
+ void* destBuffer) const = 0;
185
+
186
+ virtual void write(std::size_t offset, std::size_t length,
187
+ const void* sourceBuffer) = 0;
188
+ };
189
+
190
+ //! Piece of memory with the Resource interface.
191
+ class Buffer : public Resource
192
+ {
193
+ std::vector<char> buf;
194
+
195
+ public:
196
+ Buffer()
197
+ {
198
+ }
199
+
200
+ Buffer(const Buffer& other)
201
+ : Resource()
202
+ , buf(other.buf)
203
+ {
204
+ }
205
+
206
+ Buffer& operator=(const Buffer& other)
207
+ {
208
+ buf = other.buf;
209
+ return *this;
210
+ }
211
+
212
+ std::size_t size() const;
213
+ void resize(std::size_t newSize);
214
+
215
+ void read(std::size_t offset, std::size_t length,
216
+ void* destBuffer) const;
217
+
218
+ void write(std::size_t offset, std::size_t length,
219
+ const void* sourceBuffer);
220
+
221
+ const void* data() const
222
+ {
223
+ return &buf[0];
224
+ }
225
+
226
+ void* data()
227
+ {
228
+ return &buf[0];
229
+ }
230
+ };
231
+
232
+ enum FileMode
233
+ {
234
+ //! Opens an existing file for reading; throws an exception if the file
235
+ //! cannot be found.
236
+ fmRead,
237
+ //! Writes data to a file. If the file already exists, is emptied on
238
+ //! opening. If the file does not exist, it is created.
239
+ fmReplace,
240
+ //! Opens or creates a file with writing access, but does not clear
241
+ //! existing contents.
242
+ fmAlter
243
+ };
244
+
245
+ //! File with the Resource interface.
246
+ class File : public Resource
247
+ {
248
+ struct Impl;
249
+ const GOSU_UNIQUE_PTR<Impl> pimpl;
250
+
251
+ public:
252
+ explicit File(const std::wstring& filename, FileMode mode = fmRead);
253
+ ~File();
254
+
255
+ std::size_t size() const;
256
+ void resize(std::size_t newSize);
257
+ void read(std::size_t offset, std::size_t length,
258
+ void* destBuffer) const;
259
+ void write(std::size_t offset, std::size_t length,
260
+ const void* sourceBuffer);
261
+ };
262
+
263
+ //! Loads a whole file into a buffer.
264
+ void loadFile(Buffer& buffer, const std::wstring& filename);
265
+ //! Creates or overwrites a file with the contents of a buffer.
266
+ void saveFile(const Buffer& buffer, const std::wstring& filename);
267
+ }
268
+
269
+ #endif