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/Text/TextWin.cpp
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
#define _WIN32_WINNT 0x0500
|
2
|
-
#include <windows.h>
|
3
|
-
|
4
|
-
#include <Gosu/Bitmap.hpp>
|
5
|
-
#include <Gosu/Text.hpp>
|
6
|
-
#include <Gosu/Utility.hpp>
|
7
|
-
#include "../WinUtility.hpp"
|
8
|
-
#include <cstdlib>
|
9
|
-
#include <cwchar>
|
10
|
-
#include <algorithm>
|
11
|
-
#include <stdexcept>
|
12
|
-
#include <map>
|
13
|
-
#include <set>
|
14
|
-
|
15
|
-
std::wstring Gosu::defaultFontName()
|
16
|
-
{
|
17
|
-
return L"Arial";
|
18
|
-
}
|
19
|
-
|
20
|
-
namespace Gosu
|
21
|
-
{
|
22
|
-
std::wstring getNameFromTTFFile(const std::wstring& filename);
|
23
|
-
|
24
|
-
namespace
|
25
|
-
{
|
26
|
-
class WinBitmap
|
27
|
-
{
|
28
|
-
WinBitmap(const WinBitmap&);
|
29
|
-
WinBitmap& operator=(const WinBitmap&);
|
30
|
-
|
31
|
-
HDC dc;
|
32
|
-
HBITMAP bitmap;
|
33
|
-
char* pixels;
|
34
|
-
|
35
|
-
public:
|
36
|
-
WinBitmap(unsigned width, unsigned height)
|
37
|
-
{
|
38
|
-
dc = Win::check(::CreateCompatibleDC(0),
|
39
|
-
"creating a device context");
|
40
|
-
|
41
|
-
BITMAPCOREHEADER coreHeader;
|
42
|
-
coreHeader.bcSize = sizeof coreHeader;
|
43
|
-
coreHeader.bcWidth = width;
|
44
|
-
coreHeader.bcHeight = height;
|
45
|
-
coreHeader.bcPlanes = 1;
|
46
|
-
coreHeader.bcBitCount = 24;
|
47
|
-
|
48
|
-
bitmap = ::CreateDIBSection(dc,
|
49
|
-
reinterpret_cast<BITMAPINFO*>(&coreHeader), DIB_RGB_COLORS,
|
50
|
-
reinterpret_cast<VOID**>(&pixels), 0, 0);
|
51
|
-
if (bitmap == 0)
|
52
|
-
{
|
53
|
-
::DeleteDC(dc);
|
54
|
-
Win::throwLastError("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 selectFont(std::wstring fontName, unsigned fontHeight,
|
83
|
-
unsigned fontFlags) const
|
84
|
-
{
|
85
|
-
// TODO for ASYNC support:
|
86
|
-
// Use a lock on both maps.
|
87
|
-
|
88
|
-
// Note:
|
89
|
-
// The caching of opened fonts didn't really show improved text rendering
|
90
|
-
// performance on my test system.
|
91
|
-
// In case of trouble, it can be taken out without worrying too much.
|
92
|
-
|
93
|
-
static std::map<std::wstring, std::wstring> customFonts;
|
94
|
-
|
95
|
-
if (fontName.find(L"/") != std::wstring::npos)
|
96
|
-
{
|
97
|
-
if (customFonts.count(fontName) == 0)
|
98
|
-
{
|
99
|
-
AddFontResourceEx(fontName.c_str(), FR_PRIVATE, 0);
|
100
|
-
fontName = customFonts[fontName] = getNameFromTTFFile(fontName);
|
101
|
-
}
|
102
|
-
else
|
103
|
-
fontName = customFonts[fontName];
|
104
|
-
}
|
105
|
-
|
106
|
-
static std::map<std::pair<std::wstring, unsigned>, HFONT> loadedFonts;
|
107
|
-
|
108
|
-
HFONT font;
|
109
|
-
std::pair<std::wstring, unsigned> key =
|
110
|
-
std::make_pair(fontName, fontHeight | fontFlags << 16);
|
111
|
-
if (loadedFonts.count(key) == 0)
|
112
|
-
{
|
113
|
-
LOGFONT logfont = { fontHeight, 0, 0, 0,
|
114
|
-
fontFlags & ffBold ? FW_BOLD : FW_NORMAL,
|
115
|
-
fontFlags & ffItalic ? TRUE : FALSE,
|
116
|
-
fontFlags & ffUnderline ? TRUE : FALSE,
|
117
|
-
FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
|
118
|
-
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
|
119
|
-
DEFAULT_PITCH | FF_DONTCARE };
|
120
|
-
|
121
|
-
// Don't rely on wcsncpy being in std::...
|
122
|
-
using namespace std;
|
123
|
-
wcsncpy(logfont.lfFaceName, fontName.c_str(), LF_FACESIZE);
|
124
|
-
logfont.lfFaceName[LF_FACESIZE - 1] = 0;
|
125
|
-
|
126
|
-
font = loadedFonts[key] = Win::check(::CreateFontIndirect(&logfont),
|
127
|
-
"creating font object for " + narrow(fontName));
|
128
|
-
}
|
129
|
-
else
|
130
|
-
font = loadedFonts[key];
|
131
|
-
|
132
|
-
::SelectObject(dc, font);
|
133
|
-
}
|
134
|
-
};
|
135
|
-
}
|
136
|
-
};
|
137
|
-
|
138
|
-
unsigned Gosu::textWidth(const std::wstring& text,
|
139
|
-
const std::wstring& fontName, unsigned fontHeight, unsigned fontFlags)
|
140
|
-
{
|
141
|
-
if (text.find_first_of(L"\r\n") != std::wstring::npos)
|
142
|
-
throw std::invalid_argument("the argument to textWidth cannot contain line breaks");
|
143
|
-
|
144
|
-
WinBitmap helper(1, 1);
|
145
|
-
helper.selectFont(fontName, fontHeight, fontFlags);
|
146
|
-
|
147
|
-
SIZE size;
|
148
|
-
if (!::GetTextExtentPoint32(helper.context(), text.c_str(), text.length(), &size))
|
149
|
-
Win::throwLastError("calculating the width of a text");
|
150
|
-
|
151
|
-
return size.cx;
|
152
|
-
}
|
153
|
-
|
154
|
-
void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
|
155
|
-
Color c, const std::wstring& fontName, unsigned fontHeight,
|
156
|
-
unsigned fontFlags)
|
157
|
-
{
|
158
|
-
if (text.find_first_of(L"\r\n") != std::wstring::npos)
|
159
|
-
throw std::invalid_argument("the argument to drawText cannot contain line breaks");
|
160
|
-
|
161
|
-
unsigned width = textWidth(text, fontName, fontHeight, fontFlags);
|
162
|
-
|
163
|
-
WinBitmap helper(width, fontHeight);
|
164
|
-
helper.selectFont(fontName, fontHeight, fontFlags);
|
165
|
-
|
166
|
-
if (::SetTextColor(helper.context(), 0xffffff) == CLR_INVALID)
|
167
|
-
Win::throwLastError("setting the text color");
|
168
|
-
|
169
|
-
Win::check(::SetBkMode(helper.context(), TRANSPARENT),
|
170
|
-
"setting a bitmap's background mode to TRANSPARENT");
|
171
|
-
|
172
|
-
::ExtTextOut(helper.context(), 0, 0, 0, 0, text.c_str(), text.length(), 0);
|
173
|
-
|
174
|
-
for (unsigned relY = 0; relY < fontHeight; ++relY)
|
175
|
-
for (unsigned relX = 0; relX < width; ++relX)
|
176
|
-
{
|
177
|
-
Color pixel = c;
|
178
|
-
Color::Channel srcAlpha = GetPixel(helper.context(), relX, relY) & 0xff;
|
179
|
-
if (srcAlpha == 0)
|
180
|
-
continue;
|
181
|
-
pixel = multiply(c, Color(srcAlpha, 255, 255, 255));
|
182
|
-
if (pixel != 0 && x + relX >= 0 && x + relX < bitmap.width() &&
|
183
|
-
y + relY >= 0 && y + relY < bitmap.height())
|
184
|
-
bitmap.setPixel(x + relX, y + relY, pixel);
|
185
|
-
}
|
186
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
#import "GosuAppDelegate.h"
|
2
|
-
#import <Gosu/Gosu.hpp>
|
3
|
-
|
4
|
-
|
5
|
-
@implementation GosuAppDelegate
|
6
|
-
|
7
|
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
8
|
-
{
|
9
|
-
self.window = (__bridge UIWindow *)windowInstance().UIWindow();
|
10
|
-
[self.window makeKeyAndVisible];
|
11
|
-
|
12
|
-
return YES;
|
13
|
-
}
|
14
|
-
|
15
|
-
@end
|
16
|
-
|
17
|
-
|
18
|
-
int main(int argc, char *argv[])
|
19
|
-
{
|
20
|
-
@autoreleasepool {
|
21
|
-
Gosu::useResourceDirectory();
|
22
|
-
return UIApplicationMain(argc, argv, nil, NSStringFromClass([GosuAppDelegate class]));
|
23
|
-
}
|
24
|
-
}
|
@@ -1,211 +0,0 @@
|
|
1
|
-
#import "GosuViewController.h"
|
2
|
-
#import "GosuGLView.h"
|
3
|
-
#import "../Graphics/Common.hpp"
|
4
|
-
#import <Gosu/Gosu.hpp>
|
5
|
-
|
6
|
-
#import <OpenAL/alc.h>
|
7
|
-
#import <AudioToolbox/AudioSession.h>
|
8
|
-
|
9
|
-
|
10
|
-
namespace Gosu
|
11
|
-
{
|
12
|
-
namespace FPS
|
13
|
-
{
|
14
|
-
void registerFrame();
|
15
|
-
}
|
16
|
-
|
17
|
-
ALCcontext *sharedContext();
|
18
|
-
}
|
19
|
-
|
20
|
-
|
21
|
-
// TODO: This has been written on iOS 3.x.
|
22
|
-
// Is this still the best way to handle interruptions?
|
23
|
-
static void handleAudioInterruption(void *unused, UInt32 inInterruptionState)
|
24
|
-
{
|
25
|
-
if (inInterruptionState == kAudioSessionBeginInterruption) {
|
26
|
-
alcMakeContextCurrent(NULL);
|
27
|
-
}
|
28
|
-
else if (inInterruptionState == kAudioSessionEndInterruption) {
|
29
|
-
alcMakeContextCurrent(Gosu::sharedContext());
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
@implementation GosuViewController
|
35
|
-
{
|
36
|
-
BOOL _paused;
|
37
|
-
BOOL _musicPaused;
|
38
|
-
id _timerOrDisplayLink;
|
39
|
-
}
|
40
|
-
|
41
|
-
#pragma mark - UIViewController
|
42
|
-
|
43
|
-
- (void)loadView
|
44
|
-
{
|
45
|
-
self.view = [[GosuGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
46
|
-
}
|
47
|
-
|
48
|
-
- (BOOL)prefersStatusBarHidden
|
49
|
-
{
|
50
|
-
return YES;
|
51
|
-
}
|
52
|
-
|
53
|
-
- (BOOL)shouldAutorotate
|
54
|
-
{
|
55
|
-
return YES;
|
56
|
-
}
|
57
|
-
|
58
|
-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
59
|
-
{
|
60
|
-
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
|
61
|
-
}
|
62
|
-
|
63
|
-
- (NSUInteger)supportedInterfaceOrientations
|
64
|
-
{
|
65
|
-
return UIInterfaceOrientationMaskLandscape;
|
66
|
-
}
|
67
|
-
|
68
|
-
- (GosuGLView *)GLView
|
69
|
-
{
|
70
|
-
return (GosuGLView *)self.view;
|
71
|
-
}
|
72
|
-
|
73
|
-
- (Gosu::Window &)gosuWindowReference
|
74
|
-
{
|
75
|
-
NSAssert(self.gosuWindow,
|
76
|
-
@"gosuWindow needs to be set before showing GosuViewController");
|
77
|
-
|
78
|
-
return *(Gosu::Window *)self.gosuWindow;
|
79
|
-
}
|
80
|
-
|
81
|
-
#pragma mark - Notifications (handle pausing)
|
82
|
-
|
83
|
-
- (void)viewDidLoad
|
84
|
-
{
|
85
|
-
[super viewDidLoad];
|
86
|
-
|
87
|
-
AudioSessionInitialize(NULL, NULL, handleAudioInterruption, NULL);
|
88
|
-
|
89
|
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
|
90
|
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
|
91
|
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
|
92
|
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
93
|
-
}
|
94
|
-
|
95
|
-
- (void)dealloc
|
96
|
-
{
|
97
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
98
|
-
}
|
99
|
-
|
100
|
-
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
101
|
-
{
|
102
|
-
if (_musicPaused) {
|
103
|
-
if (Gosu::Song::currentSong())
|
104
|
-
Gosu::Song::currentSong()->play();
|
105
|
-
_musicPaused = NO;
|
106
|
-
}
|
107
|
-
_paused = NO;
|
108
|
-
}
|
109
|
-
|
110
|
-
- (void)applicationWillResignActive:(NSNotification *)notification
|
111
|
-
{
|
112
|
-
if (Gosu::Song::currentSong()) {
|
113
|
-
Gosu::Song::currentSong()->pause();
|
114
|
-
_musicPaused = YES;
|
115
|
-
}
|
116
|
-
_paused = YES;
|
117
|
-
|
118
|
-
self.gosuWindowReference.loseFocus();
|
119
|
-
}
|
120
|
-
|
121
|
-
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
122
|
-
{
|
123
|
-
[self setupTimerOrDisplayLink];
|
124
|
-
}
|
125
|
-
|
126
|
-
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
127
|
-
{
|
128
|
-
[_timerOrDisplayLink invalidate];
|
129
|
-
_timerOrDisplayLink = nil;
|
130
|
-
}
|
131
|
-
|
132
|
-
#pragma mark - Redraw & update "loop"
|
133
|
-
|
134
|
-
- (void)viewWillAppear:(BOOL)animated
|
135
|
-
{
|
136
|
-
[super viewWillAppear:animated];
|
137
|
-
|
138
|
-
[self setupTimerOrDisplayLink];
|
139
|
-
|
140
|
-
[UIApplication sharedApplication].statusBarHidden = YES;
|
141
|
-
}
|
142
|
-
|
143
|
-
- (void)setupTimerOrDisplayLink
|
144
|
-
{
|
145
|
-
if (_timerOrDisplayLink)
|
146
|
-
return;
|
147
|
-
|
148
|
-
NSInteger targetFPS = round(1000.0 / self.gosuWindowReference.updateInterval());
|
149
|
-
|
150
|
-
if (60 % targetFPS != 0) {
|
151
|
-
NSTimeInterval interval = self.gosuWindowReference.updateInterval() / 1000.0;
|
152
|
-
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(updateAndDraw:) userInfo:nil repeats:YES];
|
153
|
-
|
154
|
-
_timerOrDisplayLink = timer;
|
155
|
-
}
|
156
|
-
else {
|
157
|
-
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateAndDraw:)];
|
158
|
-
displayLink.frameInterval = 60 / targetFPS;
|
159
|
-
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
160
|
-
|
161
|
-
_timerOrDisplayLink = displayLink;
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
- (void)updateAndDraw:(id)sender
|
166
|
-
{
|
167
|
-
Gosu::Window& window = self.gosuWindowReference;
|
168
|
-
|
169
|
-
window.input().update();
|
170
|
-
|
171
|
-
if (!_paused) {
|
172
|
-
window.update();
|
173
|
-
}
|
174
|
-
|
175
|
-
if (window.needsRedraw()) {
|
176
|
-
[self.GLView redrawGL:^{
|
177
|
-
if (window.graphics().begin()) {
|
178
|
-
window.draw();
|
179
|
-
window.graphics().end();
|
180
|
-
|
181
|
-
Gosu::FPS::registerFrame();
|
182
|
-
}
|
183
|
-
}];
|
184
|
-
}
|
185
|
-
|
186
|
-
Gosu::Song::update();
|
187
|
-
}
|
188
|
-
|
189
|
-
#pragma mark - Touch forwarding
|
190
|
-
|
191
|
-
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
192
|
-
{
|
193
|
-
self.gosuWindowReference.input().feedTouchEvent(0, (__bridge void *)touches);
|
194
|
-
}
|
195
|
-
|
196
|
-
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
197
|
-
{
|
198
|
-
self.gosuWindowReference.input().feedTouchEvent(1, (__bridge void *)touches);
|
199
|
-
}
|
200
|
-
|
201
|
-
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
202
|
-
{
|
203
|
-
self.gosuWindowReference.input().feedTouchEvent(2, (__bridge void *)touches);
|
204
|
-
}
|
205
|
-
|
206
|
-
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
207
|
-
{
|
208
|
-
self.gosuWindowReference.input().feedTouchEvent(3, (__bridge void *)touches);
|
209
|
-
}
|
210
|
-
|
211
|
-
@end
|
data/src/UtilityApple.mm
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
#include <Gosu/Utility.hpp>
|
2
|
-
#include <Gosu/Platform.hpp>
|
3
|
-
#include "AppleUtility.hpp"
|
4
|
-
#import <Foundation/Foundation.h>
|
5
|
-
#include <stdexcept>
|
6
|
-
#include <vector>
|
7
|
-
using namespace std;
|
8
|
-
|
9
|
-
#ifdef GOSU_IS_IPHONE // (but could also be used for OS X)
|
10
|
-
wstring Gosu::utf8ToWstring(const string& s)
|
11
|
-
{
|
12
|
-
if (s.empty()) {
|
13
|
-
return wstring();
|
14
|
-
}
|
15
|
-
|
16
|
-
NSString *str = [NSString stringWithUTF8String:s.c_str()];
|
17
|
-
vector<wchar_t> buffer(s.size());
|
18
|
-
NSUInteger usedBufferCount;
|
19
|
-
if (![str getBytes:&buffer[0]
|
20
|
-
maxLength:buffer.size() * sizeof(wchar_t)
|
21
|
-
usedLength:&usedBufferCount
|
22
|
-
encoding:NSUTF32LittleEndianStringEncoding
|
23
|
-
options:0
|
24
|
-
range:NSMakeRange(0, str.length)
|
25
|
-
remainingRange:NULL]) {
|
26
|
-
throw std::runtime_error("String " + s + " could not be converted to Unicode");
|
27
|
-
}
|
28
|
-
return wstring(&buffer[0], &buffer[0] + usedBufferCount / sizeof(wchar_t));
|
29
|
-
}
|
30
|
-
|
31
|
-
string Gosu::wstringToUTF8(const std::wstring& ws)
|
32
|
-
{
|
33
|
-
if (ws.empty()) {
|
34
|
-
return string();
|
35
|
-
}
|
36
|
-
|
37
|
-
@autoreleasepool {
|
38
|
-
NSString *str = [[NSString alloc] initWithBytes:ws.data()
|
39
|
-
length:ws.size() * sizeof(wchar_t)
|
40
|
-
encoding:NSUTF32LittleEndianStringEncoding];
|
41
|
-
return str.UTF8String ?: string();
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
wstring Gosu::widen(const string& s)
|
46
|
-
{
|
47
|
-
return utf8ToWstring(s);
|
48
|
-
}
|
49
|
-
|
50
|
-
string Gosu::narrow(const std::wstring& ws)
|
51
|
-
{
|
52
|
-
return wstringToUTF8(ws);
|
53
|
-
}
|
54
|
-
#endif
|
55
|
-
|
56
|
-
string Gosu::language()
|
57
|
-
{
|
58
|
-
@autoreleasepool {
|
59
|
-
// Cannot use accessor syntax here without breaking compilation with OS X 10.7/Xcode 4.6.3.
|
60
|
-
NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
|
61
|
-
return language.UTF8String ?: "en";
|
62
|
-
}
|
63
|
-
}
|