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.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +35 -66
- data/Gosu/AutoLink.hpp +14 -16
- data/Gosu/Bitmap.hpp +50 -37
- data/Gosu/Buttons.hpp +246 -265
- data/Gosu/Color.hpp +32 -76
- data/Gosu/Directories.hpp +14 -17
- data/Gosu/Font.hpp +28 -34
- data/Gosu/Fwd.hpp +27 -31
- data/Gosu/Gosu.hpp +2 -5
- data/Gosu/Graphics.hpp +31 -48
- data/Gosu/GraphicsBase.hpp +27 -58
- data/Gosu/IO.hpp +44 -56
- data/Gosu/Image.hpp +29 -73
- data/Gosu/ImageData.hpp +13 -17
- data/Gosu/Input.hpp +42 -57
- data/Gosu/Inspection.hpp +2 -6
- data/Gosu/Math.hpp +32 -38
- data/Gosu/Platform.hpp +10 -29
- data/Gosu/Text.hpp +30 -39
- data/Gosu/TextInput.hpp +29 -36
- data/Gosu/Timing.hpp +14 -16
- data/Gosu/Utility.hpp +10 -15
- data/Gosu/Version.hpp +13 -14
- data/Gosu/Window.hpp +53 -68
- data/README.md +23 -11
- data/ext/gosu/extconf.rb +31 -81
- data/lib/gosu/patches.rb +35 -19
- data/lib/gosu/run.rb +13 -4
- data/rdoc/gosu.rb +24 -20
- data/src/ALChannelManagement.hpp +119 -0
- data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
- data/src/AudioFile.hpp +57 -0
- data/src/AudioToolboxFile.hpp +214 -0
- data/src/Bitmap.cpp +159 -0
- data/src/BitmapIO.cpp +141 -0
- data/src/BlockAllocator.cpp +133 -0
- data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
- data/src/ClipRectStack.hpp +87 -0
- data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
- data/src/DirectoriesApple.cpp +68 -0
- data/src/DirectoriesUnix.cpp +20 -18
- data/src/DirectoriesWin.cpp +40 -41
- data/src/DrawOp.hpp +168 -0
- data/src/DrawOpQueue.hpp +190 -0
- data/src/FileUnix.cpp +40 -46
- data/src/FileWin.cpp +42 -38
- data/src/Font.cpp +165 -0
- data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
- data/src/GosuAppDelegate.cpp +30 -0
- data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
- data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
- data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
- data/src/GosuViewController.cpp +231 -0
- data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
- data/src/Graphics.cpp +464 -0
- data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
- data/src/IO.cpp +17 -16
- data/src/Iconv.hpp +13 -22
- data/src/Image.cpp +142 -0
- data/src/Input.cpp +459 -0
- data/src/InputUIKit.cpp +197 -0
- data/src/Inspection.cpp +4 -5
- data/src/LargeImageData.cpp +151 -0
- data/src/LargeImageData.hpp +43 -0
- data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
- data/src/Macro.hpp +30 -0
- data/src/Math.cpp +17 -29
- data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
- data/src/RenderState.hpp +205 -0
- data/src/Resolution.cpp +86 -0
- data/src/ResolutionApple.cpp +25 -0
- data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
- data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
- data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
- data/src/TexChunk.cpp +117 -0
- data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
- data/src/Text.cpp +371 -0
- data/src/TextApple.cpp +209 -0
- data/src/TextInput.cpp +278 -0
- data/src/TextTTFWin.cpp +251 -0
- data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
- data/src/TextWin.cpp +194 -0
- data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
- data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
- data/src/TimingApple.cpp +11 -7
- data/src/TimingUnix.cpp +13 -7
- data/src/TimingWin.cpp +6 -1
- data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
- data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
- data/src/Utility.cpp +29 -70
- data/src/UtilityApple.cpp +52 -0
- data/src/UtilityWin.cpp +7 -4
- data/src/Version.cpp +22 -0
- data/src/WinMain.cpp +30 -33
- data/src/WinUtility.cpp +24 -22
- data/src/WinUtility.hpp +11 -20
- data/src/Window.cpp +142 -112
- data/src/WindowUIKit.cpp +155 -0
- data/src/stb_image.h +384 -173
- data/src/stb_vorbis.c +20 -18
- metadata +60 -62
- data/Gosu/TR1.hpp +0 -56
- data/src/AppleUtility.hpp +0 -66
- data/src/Audio/ALChannelManagement.hpp +0 -114
- data/src/Audio/Audio.mm +0 -1
- data/src/Audio/AudioFile.hpp +0 -53
- data/src/Audio/AudioToolboxFile.hpp +0 -207
- data/src/Bitmap/Bitmap.cpp +0 -183
- data/src/Bitmap/BitmapIO.cpp +0 -176
- data/src/DirectoriesApple.mm +0 -71
- data/src/Graphics/BlockAllocator.cpp +0 -142
- data/src/Graphics/ClipRectStack.hpp +0 -93
- data/src/Graphics/DrawOp.hpp +0 -175
- data/src/Graphics/DrawOpQueue.hpp +0 -188
- data/src/Graphics/Graphics.cpp +0 -478
- data/src/Graphics/Image.cpp +0 -193
- data/src/Graphics/LargeImageData.cpp +0 -133
- data/src/Graphics/LargeImageData.hpp +0 -46
- data/src/Graphics/Macro.hpp +0 -36
- data/src/Graphics/RenderState.hpp +0 -211
- data/src/Graphics/Resolution.cpp +0 -91
- data/src/Graphics/ResolutionApple.mm +0 -19
- data/src/Graphics/TexChunk.cpp +0 -112
- data/src/Input/Input.cpp +0 -463
- data/src/Input/InputUIKit.mm +0 -190
- data/src/Input/TextInput.cpp +0 -261
- data/src/Text/Font.cpp +0 -175
- data/src/Text/Text.cpp +0 -391
- data/src/Text/TextApple.mm +0 -227
- data/src/Text/TextTTFWin.cpp +0 -249
- data/src/Text/TextWin.cpp +0 -186
- data/src/UIKit/GosuAppDelegate.mm +0 -24
- data/src/UIKit/GosuViewController.mm +0 -211
- data/src/UtilityApple.mm +0 -63
- data/src/WindowUIKit.mm +0 -139
data/src/WinUtility.cpp
CHANGED
@@ -1,39 +1,41 @@
|
|
1
|
-
#include <Gosu/
|
1
|
+
#include <Gosu/Platform.hpp>
|
2
|
+
#if defined(GOSU_IS_WIN)
|
3
|
+
|
2
4
|
#include "WinUtility.hpp"
|
5
|
+
#include <Gosu/Utility.hpp>
|
3
6
|
#include <stdexcept>
|
4
7
|
#include <windows.h>
|
5
8
|
|
6
|
-
void Gosu::
|
9
|
+
void Gosu::throw_last_winapi_error(const std::string& action)
|
7
10
|
{
|
8
11
|
// Obtain error message from Windows.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
wchar_t* buffer;
|
13
|
+
|
14
|
+
if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
15
|
+
FORMAT_MESSAGE_FROM_SYSTEM |
|
16
|
+
FORMAT_MESSAGE_IGNORE_INSERTS, 0, GetLastError(),
|
17
|
+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR) &buffer, 0, 0)
|
18
|
+
|| buffer == nullptr) {
|
16
19
|
throw std::runtime_error("Unknown error");
|
17
20
|
}
|
18
21
|
|
19
|
-
//
|
22
|
+
// Safely move the message into a std::string.
|
20
23
|
std::string message;
|
21
|
-
try
|
22
|
-
|
23
|
-
message = buffer;
|
24
|
+
try {
|
25
|
+
message = wstring_to_utf8(buffer);
|
24
26
|
}
|
25
|
-
catch (...)
|
26
|
-
|
27
|
-
::LocalFree(buffer);
|
27
|
+
catch (...) {
|
28
|
+
LocalFree(buffer);
|
28
29
|
throw;
|
29
30
|
}
|
30
|
-
|
31
|
+
LocalFree(buffer);
|
31
32
|
|
32
33
|
// Optionally prepend the action.
|
33
|
-
if (!action.empty())
|
34
|
-
message = "While " + action + ", the following error occured: " +
|
35
|
-
|
34
|
+
if (!action.empty()) {
|
35
|
+
message = "While " + action + ", the following error occured: " + message;
|
36
|
+
}
|
36
37
|
|
37
|
-
// Now throw it.
|
38
38
|
throw std::runtime_error(message);
|
39
|
-
|
39
|
+
}
|
40
|
+
|
41
|
+
#endif
|
data/src/WinUtility.hpp
CHANGED
@@ -1,30 +1,21 @@
|
|
1
|
-
#
|
2
|
-
#define GOSU_WINUTILITY_HPP
|
1
|
+
#pragma once
|
3
2
|
|
4
3
|
#include <Gosu/Platform.hpp>
|
5
4
|
#include <string>
|
6
5
|
|
7
6
|
namespace Gosu
|
8
7
|
{
|
9
|
-
//!
|
10
|
-
|
11
|
-
|
12
|
-
//! Throws an exception according to the error which GetLastError()
|
13
|
-
//! returns, optionally prefixed with "While (action), the following
|
14
|
-
//! error occured: ".
|
15
|
-
GOSU_NORETURN void throwLastError(const std::string& action = "");
|
8
|
+
//! Throws an exception according to the error returned by GetLastError(), optionally prefixed
|
9
|
+
//! with "While (action), the following error occured: ".
|
10
|
+
GOSU_NORETURN void throw_last_winapi_error(const std::string& action = "");
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if (!valToCheck)
|
24
|
-
throwLastError(action);
|
25
|
-
return valToCheck;
|
12
|
+
//! Small helper function that throws the last Windows error when val_to_check is false.
|
13
|
+
template<typename T>
|
14
|
+
inline T winapi_check(T val_to_check, const std::string& action = "")
|
15
|
+
{
|
16
|
+
if (!val_to_check) {
|
17
|
+
throw_last_winapi_error(action);
|
26
18
|
}
|
19
|
+
return val_to_check;
|
27
20
|
}
|
28
21
|
}
|
29
|
-
|
30
|
-
#endif
|
data/src/Window.cpp
CHANGED
@@ -1,204 +1,247 @@
|
|
1
|
+
#include <Gosu/Platform.hpp>
|
2
|
+
#if !defined(GOSU_IS_IPHONE)
|
3
|
+
|
1
4
|
#include <Gosu/Gosu.hpp>
|
2
|
-
#include "Graphics/Common.hpp"
|
3
5
|
#include <SDL.h>
|
4
6
|
#include <cstdlib>
|
5
7
|
#include <memory>
|
6
8
|
#include <stdexcept>
|
7
9
|
|
8
|
-
using namespace std::tr1::placeholders;
|
9
|
-
|
10
10
|
namespace Gosu
|
11
11
|
{
|
12
12
|
namespace FPS
|
13
13
|
{
|
14
|
-
void
|
14
|
+
void register_frame();
|
15
15
|
}
|
16
16
|
|
17
|
-
void
|
17
|
+
void throw_sdl_error(const std::string& operation)
|
18
18
|
{
|
19
|
-
const char
|
19
|
+
const char* error = SDL_GetError();
|
20
20
|
throw std::runtime_error(operation + ": " + (error ? error : "(unknown error)"));
|
21
21
|
}
|
22
22
|
|
23
23
|
void cleanup();
|
24
24
|
|
25
|
-
SDL_Window*
|
25
|
+
SDL_Window* shared_window()
|
26
26
|
{
|
27
|
-
static SDL_Window
|
28
|
-
if (window ==
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
static SDL_Window* window = nullptr;
|
28
|
+
if (window == nullptr) {
|
29
|
+
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
30
|
+
throw_sdl_error("Could not initialize SDL Video");
|
31
|
+
}
|
32
32
|
|
33
33
|
std::atexit(cleanup);
|
34
34
|
|
35
35
|
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
|
36
36
|
|
37
|
-
|
37
|
+
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
38
38
|
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
39
|
-
|
39
|
+
#endif
|
40
40
|
|
41
|
-
window =
|
42
|
-
|
43
|
-
|
41
|
+
window =
|
42
|
+
SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
|
43
|
+
if (window == nullptr) {
|
44
|
+
throw_sdl_error("Could not create window");
|
45
|
+
}
|
44
46
|
}
|
45
47
|
return window;
|
46
48
|
}
|
47
49
|
|
48
|
-
SDL_GLContext
|
50
|
+
SDL_GLContext shared_gl_context()
|
49
51
|
{
|
50
|
-
static SDL_GLContext context =
|
51
|
-
if (context ==
|
52
|
-
|
53
|
-
#ifdef GOSU_IS_OPENGLES
|
52
|
+
static SDL_GLContext context = nullptr;
|
53
|
+
if (context == nullptr) {
|
54
|
+
#ifdef GOSU_IS_OPENGLES
|
54
55
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
55
56
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
56
|
-
|
57
|
+
#endif
|
57
58
|
|
58
|
-
context = SDL_GL_CreateContext(
|
59
|
+
context = SDL_GL_CreateContext(shared_window());
|
59
60
|
|
60
|
-
if (context ==
|
61
|
-
|
61
|
+
if (context == nullptr) {
|
62
|
+
throw_sdl_error("Could not create OpenGL context");
|
63
|
+
}
|
62
64
|
}
|
63
65
|
return context;
|
64
66
|
}
|
65
67
|
|
66
|
-
void
|
68
|
+
void ensure_current_context()
|
67
69
|
{
|
68
|
-
SDL_GL_MakeCurrent(
|
70
|
+
SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
|
69
71
|
}
|
70
72
|
|
71
73
|
void cleanup()
|
72
74
|
{
|
73
|
-
SDL_GL_DeleteContext(
|
74
|
-
SDL_DestroyWindow(
|
75
|
+
SDL_GL_DeleteContext(shared_gl_context());
|
76
|
+
SDL_DestroyWindow(shared_window());
|
75
77
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
76
78
|
}
|
77
79
|
}
|
78
80
|
|
79
81
|
struct Gosu::Window::Impl
|
80
82
|
{
|
81
|
-
|
83
|
+
bool fullscreen;
|
84
|
+
double update_interval;
|
82
85
|
|
83
|
-
std::
|
84
|
-
std::
|
86
|
+
std::unique_ptr<Graphics> graphics;
|
87
|
+
std::unique_ptr<Input> input;
|
85
88
|
};
|
86
89
|
|
87
|
-
Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double
|
90
|
+
Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double update_interval)
|
88
91
|
: pimpl(new Impl)
|
89
92
|
{
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
// This will implicitly create graphics() and input(), and make the OpenGL context current.
|
94
|
+
resize(width, height, fullscreen);
|
95
|
+
|
96
|
+
SDL_GL_SetSwapInterval(1);
|
97
|
+
|
98
|
+
pimpl->update_interval = update_interval;
|
99
|
+
|
100
|
+
if (!fullscreen) {
|
101
|
+
SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
102
|
+
}
|
103
|
+
|
104
|
+
input().on_button_down = [this](Gosu::Button button) { button_down(button); };
|
105
|
+
input().on_button_up = [this](Gosu::Button button) { button_up(button); };
|
106
|
+
}
|
107
|
+
|
108
|
+
Gosu::Window::~Window()
|
109
|
+
{
|
110
|
+
SDL_HideWindow(shared_window());
|
111
|
+
}
|
112
|
+
|
113
|
+
unsigned Gosu::Window::width() const
|
114
|
+
{
|
115
|
+
return graphics().width();
|
116
|
+
}
|
117
|
+
|
118
|
+
unsigned Gosu::Window::height() const
|
119
|
+
{
|
120
|
+
return graphics().height();
|
121
|
+
}
|
122
|
+
|
123
|
+
bool Gosu::Window::fullscreen() const
|
124
|
+
{
|
125
|
+
return pimpl->fullscreen;
|
126
|
+
}
|
127
|
+
|
128
|
+
void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
129
|
+
{
|
130
|
+
pimpl->fullscreen = fullscreen;
|
131
|
+
|
132
|
+
int actual_width = width;
|
133
|
+
int actual_height = height;
|
134
|
+
double scale_factor = 1.0;
|
135
|
+
double black_bar_width = 0;
|
136
|
+
double black_bar_height = 0;
|
95
137
|
|
96
138
|
if (fullscreen) {
|
97
|
-
|
98
|
-
|
139
|
+
actual_width = Gosu::screen_width();
|
140
|
+
actual_height = Gosu::screen_height();
|
99
141
|
|
100
|
-
double
|
101
|
-
double
|
102
|
-
|
142
|
+
double scale_x = 1.0 * actual_width / width;
|
143
|
+
double scale_y = 1.0 * actual_height / height;
|
144
|
+
scale_factor = std::min(scale_x, scale_y);
|
103
145
|
|
104
|
-
if (
|
105
|
-
|
146
|
+
if (scale_x < scale_y) {
|
147
|
+
black_bar_height = (actual_height / scale_x - height) / 2;
|
106
148
|
}
|
107
|
-
else if (
|
108
|
-
|
149
|
+
else if (scale_y < scale_x) {
|
150
|
+
black_bar_width = (actual_width / scale_y - width) / 2;
|
109
151
|
}
|
110
152
|
}
|
111
153
|
else {
|
112
|
-
double
|
113
|
-
double
|
154
|
+
double max_width = Gosu::available_width();
|
155
|
+
double max_height = Gosu::available_height();
|
114
156
|
|
115
|
-
if (width >
|
116
|
-
|
117
|
-
|
118
|
-
|
157
|
+
if (width > max_width || height > max_height) {
|
158
|
+
scale_factor = std::min(max_width / width, max_height / height);
|
159
|
+
actual_width = width * scale_factor;
|
160
|
+
actual_height = height * scale_factor;
|
119
161
|
}
|
120
162
|
}
|
121
163
|
|
122
|
-
|
123
|
-
SDL_SetWindowSize(
|
124
|
-
SDL_SetWindowPosition(sharedWindow(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
125
|
-
if (fullscreen)
|
126
|
-
{
|
127
|
-
SDL_SetWindowFullscreen(sharedWindow(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
128
|
-
}
|
164
|
+
SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
165
|
+
SDL_SetWindowSize(shared_window(), actual_width, actual_height);
|
129
166
|
|
130
|
-
|
131
|
-
SDL_GL_GetDrawableSize(
|
132
|
-
|
167
|
+
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
168
|
+
SDL_GL_GetDrawableSize(shared_window(), &actual_width, &actual_height);
|
169
|
+
#endif
|
133
170
|
|
134
|
-
|
135
|
-
|
171
|
+
ensure_current_context();
|
172
|
+
|
173
|
+
if (pimpl->graphics.get() == nullptr) {
|
174
|
+
pimpl->graphics.reset(new Graphics(actual_width, actual_height));
|
175
|
+
}
|
176
|
+
else {
|
177
|
+
pimpl->graphics->set_physical_resolution(actual_width, actual_height);
|
178
|
+
}
|
179
|
+
pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
|
136
180
|
|
137
|
-
pimpl->
|
138
|
-
|
139
|
-
|
140
|
-
pimpl->input->
|
141
|
-
|
142
|
-
input().onButtonUp = std::tr1::bind(&Window::buttonUp, this, _1);
|
143
|
-
pimpl->updateInterval = updateInterval;
|
181
|
+
if (pimpl->input.get() == nullptr) {
|
182
|
+
pimpl->input.reset(new Input(shared_window()));
|
183
|
+
}
|
184
|
+
pimpl->input->set_mouse_factors(1 / scale_factor, 1 / scale_factor,
|
185
|
+
black_bar_width, black_bar_height);
|
144
186
|
}
|
145
187
|
|
146
|
-
Gosu::Window
|
188
|
+
double Gosu::Window::update_interval() const
|
147
189
|
{
|
148
|
-
|
190
|
+
return pimpl->update_interval;
|
149
191
|
}
|
150
192
|
|
151
|
-
|
193
|
+
void Gosu::Window::set_update_interval(double update_interval)
|
152
194
|
{
|
153
|
-
|
195
|
+
pimpl->update_interval = update_interval;
|
154
196
|
}
|
155
197
|
|
156
|
-
|
198
|
+
std::string Gosu::Window::caption() const
|
157
199
|
{
|
158
|
-
|
159
|
-
|
200
|
+
const char* title = SDL_GetWindowTitle(shared_window());
|
201
|
+
return title ? title : "";
|
160
202
|
}
|
161
203
|
|
162
|
-
|
204
|
+
void Gosu::Window::set_caption(const std::string& caption)
|
163
205
|
{
|
164
|
-
|
206
|
+
SDL_SetWindowTitle(shared_window(), caption.c_str());
|
165
207
|
}
|
166
208
|
|
167
209
|
void Gosu::Window::show()
|
168
210
|
{
|
169
|
-
unsigned long
|
211
|
+
unsigned long time_before_tick = milliseconds();
|
170
212
|
|
171
213
|
while (tick()) {
|
172
214
|
// Sleep to keep this loop from eating 100% CPU.
|
173
|
-
unsigned long
|
174
|
-
if (
|
175
|
-
sleep(
|
215
|
+
unsigned long tick_time = milliseconds() - time_before_tick;
|
216
|
+
if (tick_time < update_interval()) {
|
217
|
+
sleep(update_interval() - tick_time);
|
218
|
+
}
|
176
219
|
|
177
|
-
|
220
|
+
time_before_tick = milliseconds();
|
178
221
|
}
|
179
222
|
}
|
180
223
|
|
181
224
|
bool Gosu::Window::tick()
|
182
225
|
{
|
183
|
-
if (SDL_GetWindowFlags(
|
184
|
-
SDL_ShowWindow(
|
226
|
+
if (SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_HIDDEN) {
|
227
|
+
SDL_ShowWindow(shared_window());
|
185
228
|
|
186
229
|
// SDL_GL_GetDrawableSize returns different values before and after showing the window.
|
187
230
|
// -> When first showing the window, update the physical size of Graphics (=glViewport).
|
188
231
|
// Fixes https://github.com/gosu/gosu/issues/318
|
189
232
|
int width, height;
|
190
|
-
SDL_GL_GetDrawableSize(
|
191
|
-
graphics().
|
233
|
+
SDL_GL_GetDrawableSize(shared_window(), &width, &height);
|
234
|
+
graphics().set_physical_resolution(width, height);
|
192
235
|
}
|
193
236
|
|
194
237
|
SDL_Event e;
|
195
238
|
while (SDL_PollEvent(&e)) {
|
196
239
|
if (e.type == SDL_QUIT) {
|
197
|
-
SDL_HideWindow(
|
240
|
+
SDL_HideWindow(shared_window());
|
198
241
|
return false;
|
199
242
|
}
|
200
243
|
else {
|
201
|
-
input().
|
244
|
+
input().feed_sdl_event(&e);
|
202
245
|
}
|
203
246
|
}
|
204
247
|
|
@@ -208,17 +251,17 @@ bool Gosu::Window::tick()
|
|
208
251
|
|
209
252
|
update();
|
210
253
|
|
211
|
-
SDL_ShowCursor(
|
254
|
+
SDL_ShowCursor(needs_cursor());
|
212
255
|
|
213
|
-
if (
|
214
|
-
|
256
|
+
if (needs_redraw()) {
|
257
|
+
ensure_current_context();
|
215
258
|
if (graphics().begin()) {
|
216
259
|
draw();
|
217
260
|
graphics().end();
|
218
|
-
FPS::
|
261
|
+
FPS::register_frame();
|
219
262
|
}
|
220
263
|
|
221
|
-
SDL_GL_SwapWindow(
|
264
|
+
SDL_GL_SwapWindow(shared_window());
|
222
265
|
}
|
223
266
|
|
224
267
|
return true;
|
@@ -251,17 +294,4 @@ Gosu::Input& Gosu::Window::input()
|
|
251
294
|
return *pimpl->input;
|
252
295
|
}
|
253
296
|
|
254
|
-
|
255
|
-
|
256
|
-
class Gosu::Audio {};
|
257
|
-
namespace { Gosu::Audio dummyAudio; }
|
258
|
-
|
259
|
-
const Gosu::Audio& Gosu::Window::audio() const
|
260
|
-
{
|
261
|
-
return dummyAudio;
|
262
|
-
}
|
263
|
-
|
264
|
-
Gosu::Audio& Gosu::Window::audio()
|
265
|
-
{
|
266
|
-
return dummyAudio;
|
267
|
-
}
|
297
|
+
#endif
|