gosu 0.10.9.pre1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Audio.hpp +35 -66
  3. data/Gosu/AutoLink.hpp +14 -16
  4. data/Gosu/Bitmap.hpp +50 -37
  5. data/Gosu/Buttons.hpp +246 -265
  6. data/Gosu/Color.hpp +32 -76
  7. data/Gosu/Directories.hpp +14 -17
  8. data/Gosu/Font.hpp +28 -34
  9. data/Gosu/Fwd.hpp +27 -31
  10. data/Gosu/Gosu.hpp +2 -5
  11. data/Gosu/Graphics.hpp +31 -48
  12. data/Gosu/GraphicsBase.hpp +27 -58
  13. data/Gosu/IO.hpp +44 -56
  14. data/Gosu/Image.hpp +29 -73
  15. data/Gosu/ImageData.hpp +13 -17
  16. data/Gosu/Input.hpp +42 -57
  17. data/Gosu/Inspection.hpp +2 -6
  18. data/Gosu/Math.hpp +32 -38
  19. data/Gosu/Platform.hpp +10 -29
  20. data/Gosu/Text.hpp +30 -39
  21. data/Gosu/TextInput.hpp +29 -36
  22. data/Gosu/Timing.hpp +14 -16
  23. data/Gosu/Utility.hpp +10 -15
  24. data/Gosu/Version.hpp +13 -14
  25. data/Gosu/Window.hpp +53 -68
  26. data/README.md +23 -11
  27. data/ext/gosu/extconf.rb +31 -81
  28. data/lib/gosu/patches.rb +35 -19
  29. data/lib/gosu/run.rb +13 -4
  30. data/rdoc/gosu.rb +24 -20
  31. data/src/ALChannelManagement.hpp +119 -0
  32. data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
  33. data/src/AudioFile.hpp +57 -0
  34. data/src/AudioToolboxFile.hpp +214 -0
  35. data/src/Bitmap.cpp +159 -0
  36. data/src/BitmapIO.cpp +141 -0
  37. data/src/BlockAllocator.cpp +133 -0
  38. data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
  39. data/src/ClipRectStack.hpp +87 -0
  40. data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
  41. data/src/DirectoriesApple.cpp +68 -0
  42. data/src/DirectoriesUnix.cpp +20 -18
  43. data/src/DirectoriesWin.cpp +40 -41
  44. data/src/DrawOp.hpp +168 -0
  45. data/src/DrawOpQueue.hpp +190 -0
  46. data/src/FileUnix.cpp +40 -46
  47. data/src/FileWin.cpp +42 -38
  48. data/src/Font.cpp +165 -0
  49. data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
  50. data/src/GosuAppDelegate.cpp +30 -0
  51. data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
  52. data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
  53. data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
  54. data/src/GosuViewController.cpp +231 -0
  55. data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
  56. data/src/Graphics.cpp +464 -0
  57. data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
  58. data/src/IO.cpp +17 -16
  59. data/src/Iconv.hpp +13 -22
  60. data/src/Image.cpp +142 -0
  61. data/src/Input.cpp +459 -0
  62. data/src/InputUIKit.cpp +197 -0
  63. data/src/Inspection.cpp +4 -5
  64. data/src/LargeImageData.cpp +151 -0
  65. data/src/LargeImageData.hpp +43 -0
  66. data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
  67. data/src/Macro.hpp +30 -0
  68. data/src/Math.cpp +17 -29
  69. data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
  70. data/src/RenderState.hpp +205 -0
  71. data/src/Resolution.cpp +86 -0
  72. data/src/ResolutionApple.cpp +25 -0
  73. data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
  74. data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
  75. data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
  76. data/src/TexChunk.cpp +117 -0
  77. data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
  78. data/src/Text.cpp +371 -0
  79. data/src/TextApple.cpp +209 -0
  80. data/src/TextInput.cpp +278 -0
  81. data/src/TextTTFWin.cpp +251 -0
  82. data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
  83. data/src/TextWin.cpp +194 -0
  84. data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
  85. data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
  86. data/src/TimingApple.cpp +11 -7
  87. data/src/TimingUnix.cpp +13 -7
  88. data/src/TimingWin.cpp +6 -1
  89. data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
  90. data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
  91. data/src/Utility.cpp +29 -70
  92. data/src/UtilityApple.cpp +52 -0
  93. data/src/UtilityWin.cpp +7 -4
  94. data/src/Version.cpp +22 -0
  95. data/src/WinMain.cpp +30 -33
  96. data/src/WinUtility.cpp +24 -22
  97. data/src/WinUtility.hpp +11 -20
  98. data/src/Window.cpp +142 -112
  99. data/src/WindowUIKit.cpp +155 -0
  100. data/src/stb_image.h +384 -173
  101. data/src/stb_vorbis.c +20 -18
  102. metadata +60 -62
  103. data/Gosu/TR1.hpp +0 -56
  104. data/src/AppleUtility.hpp +0 -66
  105. data/src/Audio/ALChannelManagement.hpp +0 -114
  106. data/src/Audio/Audio.mm +0 -1
  107. data/src/Audio/AudioFile.hpp +0 -53
  108. data/src/Audio/AudioToolboxFile.hpp +0 -207
  109. data/src/Bitmap/Bitmap.cpp +0 -183
  110. data/src/Bitmap/BitmapIO.cpp +0 -176
  111. data/src/DirectoriesApple.mm +0 -71
  112. data/src/Graphics/BlockAllocator.cpp +0 -142
  113. data/src/Graphics/ClipRectStack.hpp +0 -93
  114. data/src/Graphics/DrawOp.hpp +0 -175
  115. data/src/Graphics/DrawOpQueue.hpp +0 -188
  116. data/src/Graphics/Graphics.cpp +0 -478
  117. data/src/Graphics/Image.cpp +0 -193
  118. data/src/Graphics/LargeImageData.cpp +0 -133
  119. data/src/Graphics/LargeImageData.hpp +0 -46
  120. data/src/Graphics/Macro.hpp +0 -36
  121. data/src/Graphics/RenderState.hpp +0 -211
  122. data/src/Graphics/Resolution.cpp +0 -91
  123. data/src/Graphics/ResolutionApple.mm +0 -19
  124. data/src/Graphics/TexChunk.cpp +0 -112
  125. data/src/Input/Input.cpp +0 -463
  126. data/src/Input/InputUIKit.mm +0 -190
  127. data/src/Input/TextInput.cpp +0 -261
  128. data/src/Text/Font.cpp +0 -175
  129. data/src/Text/Text.cpp +0 -391
  130. data/src/Text/TextApple.mm +0 -227
  131. data/src/Text/TextTTFWin.cpp +0 -249
  132. data/src/Text/TextWin.cpp +0 -186
  133. data/src/UIKit/GosuAppDelegate.mm +0 -24
  134. data/src/UIKit/GosuViewController.mm +0 -211
  135. data/src/UtilityApple.mm +0 -63
  136. data/src/WindowUIKit.mm +0 -139
@@ -0,0 +1,194 @@
1
+ #include <Gosu/Platform.hpp>
2
+ #if defined(GOSU_IS_WIN)
3
+
4
+ #define _WIN32_WINNT 0x0500
5
+ #include <windows.h>
6
+
7
+ #include "WinUtility.hpp"
8
+ #include <Gosu/Bitmap.hpp>
9
+ #include <Gosu/Text.hpp>
10
+ #include <Gosu/Utility.hpp>
11
+ #include <cstdlib>
12
+ #include <cwchar>
13
+ #include <algorithm>
14
+ #include <map>
15
+ #include <set>
16
+ #include <stdexcept>
17
+
18
+ std::string Gosu::default_font_name()
19
+ {
20
+ return "Arial";
21
+ }
22
+
23
+ namespace Gosu
24
+ {
25
+ std::string get_name_from_ttf_file(const std::wstring& filename);
26
+
27
+ namespace
28
+ {
29
+ class WinBitmap
30
+ {
31
+ WinBitmap(const WinBitmap&);
32
+ WinBitmap& operator=(const WinBitmap&);
33
+
34
+ HDC dc;
35
+ HBITMAP bitmap;
36
+ char* pixels;
37
+
38
+ public:
39
+ WinBitmap(unsigned width, unsigned height)
40
+ {
41
+ dc = winapi_check(CreateCompatibleDC(0), "creating a device context");
42
+
43
+ BITMAPCOREHEADER core_header;
44
+ core_header.bcSize = sizeof core_header;
45
+ core_header.bcWidth = width;
46
+ core_header.bcHeight = height;
47
+ core_header.bcPlanes = 1;
48
+ core_header.bcBitCount = 24;
49
+
50
+ bitmap = CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&core_header),
51
+ DIB_RGB_COLORS, reinterpret_cast<VOID**>(&pixels), 0, 0);
52
+ if (bitmap == 0) {
53
+ DeleteDC(dc);
54
+ throw_last_winapi_error("creating a bitmap");
55
+ }
56
+
57
+ SelectObject(dc, bitmap);
58
+
59
+ HBRUSH brush = CreateSolidBrush(0x000000);
60
+ RECT rc = { 0, 0, width, height };
61
+ FillRect(dc, &rc, brush);
62
+ DeleteObject(brush);
63
+ }
64
+
65
+ ~WinBitmap()
66
+ {
67
+ DeleteObject(bitmap);
68
+ SelectObject(dc, GetStockObject(SYSTEM_FONT));
69
+ DeleteDC(dc);
70
+ }
71
+
72
+ HDC context() const
73
+ {
74
+ return dc;
75
+ }
76
+
77
+ HBITMAP handle() const
78
+ {
79
+ return bitmap;
80
+ }
81
+
82
+ void select_font(std::string font_name, unsigned font_height, unsigned font_flags) const
83
+ {
84
+ // TODO for ASYNC support:
85
+ // Use a lock on both maps.
86
+
87
+ // Note:
88
+ // The caching of opened fonts didn't really show improved text rendering
89
+ // performance on my test system.
90
+ // In case of trouble, it can be taken out without worrying too much.
91
+
92
+ static std::map<std::string, std::string> custom_fonts;
93
+
94
+ if (font_name.find("/") != font_name.npos) {
95
+ if (custom_fonts.count(font_name) == 0) {
96
+ std::wstring wfont_name = utf8_to_wstring(font_name);
97
+ AddFontResourceExW(wfont_name.c_str(), FR_PRIVATE, 0);
98
+ font_name = custom_fonts[font_name] = get_name_from_ttf_file(wfont_name);
99
+ }
100
+ else {
101
+ font_name = custom_fonts[font_name];
102
+ }
103
+ }
104
+
105
+ static std::map<std::pair<std::string, unsigned>, HFONT> loaded_fonts;
106
+
107
+ HFONT font;
108
+ std::pair<std::string, unsigned> key =
109
+ std::make_pair(font_name, font_height | font_flags << 16);
110
+
111
+ if (loaded_fonts.count(key) == 0) {
112
+ LOGFONT logfont = {
113
+ font_height, 0, 0, 0,
114
+ font_flags & FF_BOLD ? FW_BOLD : FW_NORMAL,
115
+ font_flags & FF_ITALIC ? TRUE : FALSE,
116
+ font_flags & FF_UNDERLINE ? TRUE : FALSE, FALSE, DEFAULT_CHARSET,
117
+ OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
118
+ DEFAULT_PITCH | FF_DONTCARE
119
+ };
120
+
121
+ std::wstring wfont_name = utf8_to_wstring(font_name);
122
+ // Don't rely on wcsncpy being in std::...
123
+ using namespace std;
124
+ wcsncpy(logfont.lfFaceName, wfont_name.c_str(), LF_FACESIZE);
125
+ logfont.lfFaceName[LF_FACESIZE - 1] = 0;
126
+
127
+ font = loaded_fonts[key] = winapi_check(CreateFontIndirect(&logfont),
128
+ "CreateFontIndirect for " + font_name);
129
+ }
130
+ else {
131
+ font = loaded_fonts[key];
132
+ }
133
+
134
+ SelectObject(dc, font);
135
+ }
136
+ };
137
+ }
138
+ };
139
+
140
+ unsigned Gosu::text_width(const std::string& text, const std::string& font_name,
141
+ unsigned font_height, unsigned font_flags)
142
+ {
143
+ if (text.find_first_of("\r\n") != text.npos) {
144
+ throw std::invalid_argument("the argument to text_width cannot contain line breaks");
145
+ }
146
+
147
+ WinBitmap helper(1, 1);
148
+ helper.select_font(font_name, font_height, font_flags);
149
+
150
+ std::wstring wtext = utf8_to_wstring(text);
151
+ SIZE size;
152
+ winapi_check(GetTextExtentPoint32W(helper.context(), wtext.c_str(), text.length(), &size),
153
+ "calculating the width of a text");
154
+
155
+ return size.cx;
156
+ }
157
+
158
+ void Gosu::draw_text(Bitmap& bitmap, const std::string& text, int x, int y, Color c,
159
+ const std::string& font_name, unsigned font_height, unsigned font_flags)
160
+ {
161
+ if (text.find_first_of("\r\n") != text.npos) {
162
+ throw std::invalid_argument("the argument to draw_text cannot contain line breaks");
163
+ }
164
+
165
+ unsigned width = text_width(text, font_name, font_height, font_flags);
166
+
167
+ WinBitmap helper(width, font_height);
168
+ helper.select_font(font_name, font_height, font_flags);
169
+
170
+ winapi_check(SetTextColor(helper.context(), 0xffffff) != CLR_INVALID,
171
+ "setting the text color");
172
+
173
+ winapi_check(SetBkMode(helper.context(), TRANSPARENT),
174
+ "setting a bitmap's background mode to TRANSPARENT");
175
+
176
+ std::wstring wtext = utf8_to_wstring(text);
177
+ ExtTextOutW(helper.context(), 0, 0, 0, 0, wtext.c_str(), text.length(), 0);
178
+
179
+ for (unsigned rel_y = 0; rel_y < font_height; ++rel_y)
180
+ for (unsigned rel_x = 0; rel_x < width; ++rel_x) {
181
+ Color pixel = c;
182
+ Color::Channel src_alpha = GetPixel(helper.context(), rel_x, rel_y) & 0xff;
183
+
184
+ if (src_alpha == 0) continue;
185
+
186
+ pixel = multiply(c, Color(src_alpha, 255, 255, 255));
187
+ if (pixel != 0 && x + rel_x >= 0 && x + rel_x < bitmap.width() &&
188
+ y + rel_y >= 0 && y + rel_y < bitmap.height()) {
189
+ bitmap.set_pixel(x + rel_x, y + rel_y, pixel);
190
+ }
191
+ }
192
+ }
193
+
194
+ #endif
@@ -1,42 +1,41 @@
1
- #include <Gosu/Graphics.hpp>
2
1
  #include "Texture.hpp"
3
2
  #include "TexChunk.hpp"
4
3
  #include <Gosu/Bitmap.hpp>
4
+ #include <Gosu/Graphics.hpp>
5
5
  #include <Gosu/Platform.hpp>
6
6
  #include <stdexcept>
7
7
 
8
8
  namespace Gosu
9
9
  {
10
- bool undocumentedRetrofication = false;
10
+ bool undocumented_retrofication = false;
11
11
  }
12
12
 
13
13
  Gosu::Texture::Texture(unsigned size, bool retro)
14
14
  : allocator_(size, size), retro_(retro)
15
15
  {
16
- ensureCurrentContext();
16
+ ensure_current_context();
17
17
 
18
18
  // Create texture name.
19
- glGenTextures(1, &texName_);
20
- if (texName_ == static_cast<GLuint>(-1))
19
+ glGenTextures(1, &tex_name_);
20
+ if (tex_name_ == static_cast<GLuint>(-1)) {
21
21
  throw std::runtime_error("Couldn't create OpenGL texture");
22
-
22
+ }
23
+
23
24
  // Create empty texture.
24
- glBindTexture(GL_TEXTURE_2D, texName_);
25
+ glBindTexture(GL_TEXTURE_2D, tex_name_);
25
26
  #ifdef GOSU_IS_OPENGLES
26
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocator_.width(), allocator_.height(), 0,
27
- GL_RGBA, GL_UNSIGNED_BYTE, 0);
27
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, allocator_.width(), allocator_.height(), 0, GL_RGBA,
28
+ GL_UNSIGNED_BYTE, nullptr);
28
29
  #else
29
- glTexImage2D(GL_TEXTURE_2D, 0, 4, allocator_.width(), allocator_.height(), 0,
30
- GL_RGBA, GL_UNSIGNED_BYTE, 0);
30
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, allocator_.width(), allocator_.height(), 0, GL_RGBA,
31
+ GL_UNSIGNED_BYTE, nullptr);
31
32
  #endif
32
33
 
33
- if (retro || undocumentedRetrofication)
34
- {
34
+ if (retro || undocumented_retrofication) {
35
35
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
36
36
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
37
37
  }
38
- else
39
- {
38
+ else {
40
39
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
41
40
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
42
41
  }
@@ -52,9 +51,9 @@ Gosu::Texture::Texture(unsigned size, bool retro)
52
51
 
53
52
  Gosu::Texture::~Texture()
54
53
  {
55
- ensureCurrentContext();
54
+ ensure_current_context();
56
55
 
57
- glDeleteTextures(1, &texName_);
56
+ glDeleteTextures(1, &tex_name_);
58
57
  }
59
58
 
60
59
  unsigned Gosu::Texture::size() const
@@ -62,9 +61,9 @@ unsigned Gosu::Texture::size() const
62
61
  return allocator_.width(); // == height
63
62
  }
64
63
 
65
- GLuint Gosu::Texture::texName() const
64
+ GLuint Gosu::Texture::tex_name() const
66
65
  {
67
- return texName_;
66
+ return tex_name_;
68
67
  }
69
68
 
70
69
  bool Gosu::Texture::retro() const
@@ -72,25 +71,23 @@ bool Gosu::Texture::retro() const
72
71
  return retro_;
73
72
  }
74
73
 
75
- GOSU_UNIQUE_PTR<Gosu::TexChunk>
76
- Gosu::Texture::tryAlloc(std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding)
74
+ std::unique_ptr<Gosu::TexChunk>
75
+ Gosu::Texture::try_alloc(std::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding)
77
76
  {
78
- GOSU_UNIQUE_PTR<Gosu::TexChunk> result;
79
-
80
77
  BlockAllocator::Block block;
81
- if (!allocator_.alloc(bmp.width(), bmp.height(), block))
82
- return result;
83
78
 
84
- result.reset(new TexChunk(ptr, block.left + padding, block.top + padding,
85
- block.width - 2 * padding, block.height - 2 * padding, padding));
79
+ if (!allocator_.alloc(bmp.width(), bmp.height(), block)) return nullptr;
80
+
81
+ std::unique_ptr<Gosu::TexChunk> result(new TexChunk(ptr, block.left + padding,
82
+ block.top + padding, block.width - 2 * padding, block.height - 2 * padding, padding));
86
83
 
87
- ensureCurrentContext();
84
+ ensure_current_context();
88
85
 
89
- glBindTexture(GL_TEXTURE_2D, texName_);
86
+ glBindTexture(GL_TEXTURE_2D, tex_name_);
90
87
  glTexSubImage2D(GL_TEXTURE_2D, 0, block.left, block.top, block.width, block.height,
91
- Color::GL_FORMAT, GL_UNSIGNED_BYTE, bmp.data());
88
+ Color::GL_FORMAT, GL_UNSIGNED_BYTE, bmp.data());
92
89
 
93
- return GOSU_MOVE_UNIQUE_PTR(result);
90
+ return std::move(result);
94
91
  }
95
92
 
96
93
  void Gosu::Texture::block(unsigned x, unsigned y, unsigned width, unsigned height)
@@ -103,18 +100,18 @@ void Gosu::Texture::free(unsigned x, unsigned y, unsigned width, unsigned height
103
100
  allocator_.free(x, y, width, height);
104
101
  }
105
102
 
106
- Gosu::Bitmap Gosu::Texture::toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const
103
+ Gosu::Bitmap Gosu::Texture::to_bitmap(unsigned x, unsigned y, unsigned width, unsigned height) const
107
104
  {
108
105
  #ifdef GOSU_IS_OPENGLES
109
- throw std::logic_error("Texture::toBitmap not supported on iOS");
106
+ throw std::logic_error("Texture::to_bitmap not supported on iOS");
110
107
  #else
111
- ensureCurrentContext();
108
+ ensure_current_context();
112
109
 
113
- Gosu::Bitmap fullTexture(size(), size());
114
- glBindTexture(GL_TEXTURE_2D, texName());
115
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, fullTexture.data());
110
+ Gosu::Bitmap full_texture(size(), size());
111
+ glBindTexture(GL_TEXTURE_2D, tex_name());
112
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, full_texture.data());
116
113
  Gosu::Bitmap bitmap(width, height);
117
- bitmap.insert(fullTexture, -int(x), -int(y));
114
+ bitmap.insert(full_texture, -int(x), -int(y));
118
115
 
119
116
  return bitmap;
120
117
  #endif
@@ -1,12 +1,10 @@
1
- #ifndef GOSU_SRC_GRAPHICS_TEXTURE_HPP
2
- #define GOSU_SRC_GRAPHICS_TEXTURE_HPP
1
+ #pragma once
3
2
 
3
+ #include "BlockAllocator.hpp"
4
+ #include "GraphicsImpl.hpp"
5
+ #include "TexChunk.hpp"
4
6
  #include <Gosu/Fwd.hpp>
5
7
  #include <Gosu/Bitmap.hpp>
6
- #include <Gosu/TR1.hpp>
7
- #include "Common.hpp"
8
- #include "TexChunk.hpp"
9
- #include "BlockAllocator.hpp"
10
8
  #include <vector>
11
9
 
12
10
  namespace Gosu
@@ -14,21 +12,19 @@ namespace Gosu
14
12
  class Texture
15
13
  {
16
14
  BlockAllocator allocator_;
17
- GLuint texName_;
15
+ GLuint tex_name_;
18
16
  bool retro_;
19
17
 
20
18
  public:
21
19
  Texture(unsigned size, bool retro);
22
20
  ~Texture();
23
21
  unsigned size() const;
24
- GLuint texName() const;
22
+ GLuint tex_name() const;
25
23
  bool retro() const;
26
- GOSU_UNIQUE_PTR<TexChunk>
27
- tryAlloc(std::tr1::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding);
24
+ std::unique_ptr<TexChunk>
25
+ try_alloc(std::shared_ptr<Texture> ptr, const Bitmap& bmp, unsigned padding);
28
26
  void block(unsigned x, unsigned y, unsigned width, unsigned height);
29
27
  void free(unsigned x, unsigned y, unsigned width, unsigned height);
30
- Gosu::Bitmap toBitmap(unsigned x, unsigned y, unsigned width, unsigned height) const;
28
+ Gosu::Bitmap to_bitmap(unsigned x, unsigned y, unsigned width, unsigned height) const;
31
29
  };
32
30
  }
33
-
34
- #endif
@@ -1,9 +1,12 @@
1
+ #include <Gosu/Platform.hpp>
2
+ #if defined(GOSU_IS_MAC)
3
+
1
4
  #include <Gosu/Timing.hpp>
2
5
  #include <unistd.h>
3
6
 
4
7
  void Gosu::sleep(unsigned milliseconds)
5
8
  {
6
- usleep(milliseconds * 1000);
9
+ usleep(milliseconds * 1000);
7
10
  }
8
11
 
9
12
  // Thanks to this blog for the unconvoluted code example:
@@ -13,15 +16,16 @@ void Gosu::sleep(unsigned milliseconds)
13
16
 
14
17
  unsigned long Gosu::milliseconds()
15
18
  {
16
- static uint64_t firstTick = 0;
19
+ static uint64_t first_tick = 0;
17
20
  static mach_timebase_info_data_t info;
18
21
 
19
- if (firstTick == 0)
20
- {
22
+ if (first_tick == 0) {
21
23
  mach_timebase_info(&info);
22
- firstTick = mach_absolute_time();
24
+ first_tick = mach_absolute_time();
23
25
  }
24
26
 
25
- uint64_t runtime = mach_absolute_time() - firstTick;
26
- return runtime * info.numer / info.denom / 1000000.0;
27
+ uint64_t runtime = mach_absolute_time() - first_tick;
28
+ return runtime * info.numer / info.denom / 1000000.0;
27
29
  }
30
+
31
+ #endif
@@ -1,24 +1,30 @@
1
+ #include <Gosu/Platform.hpp>
2
+ #if defined(GOSU_IS_X)
3
+
1
4
  #include <Gosu/Timing.hpp>
2
- #include <unistd.h>
3
5
  #include <sys/time.h>
6
+ #include <unistd.h>
4
7
 
5
8
  void Gosu::sleep(unsigned milliseconds)
6
9
  {
7
- usleep(milliseconds * 1000);
10
+ usleep(milliseconds * 1000);
8
11
  }
9
12
 
10
13
  unsigned long Gosu::milliseconds()
11
14
  {
12
- static unsigned long start = 0;
15
+ static unsigned long start = 0;
13
16
 
14
17
  timeval tp;
15
- gettimeofday(&tp, NULL);
18
+ gettimeofday(&tp, nullptr);
19
+
20
+ if (!start) {
21
+ start = tp.tv_usec / 1000UL + tp.tv_sec * 1000UL;
22
+ }
16
23
 
17
- if (!start)
18
- start = tp.tv_usec / 1000UL + tp.tv_sec * 1000UL;
19
-
20
24
  // Truncate to 2^30, C++ users shouldn't mind and Ruby users will
21
25
  // have a happy GC on 32-bit systems.
22
26
  // No, don't ask why this is an unsigned long then :)
23
27
  return (tp.tv_usec / 1000UL + tp.tv_sec * 1000UL - start) & 0x1fffffff;
24
28
  }
29
+
30
+ #endif