gosu 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gosu/Bitmap.hpp +3 -3
- data/Gosu/Directories.hpp +6 -3
- data/Gosu/Gosu.hpp +0 -1
- data/Gosu/GraphicsBase.hpp +12 -8
- data/Gosu/Input.hpp +5 -16
- data/Gosu/Platform.hpp +1 -0
- data/Gosu/Version.hpp +3 -5
- data/Gosu/Window.hpp +7 -8
- data/README.txt +3 -3
- data/ext/gosu/extconf.rb +17 -16
- data/ext/gosu/gosu_wrap.cxx +59 -58
- data/ext/gosu/gosu_wrap.h +1 -1
- data/rdoc/gosu.rb +285 -283
- data/src/{MacUtility.hpp → AppleUtility.hpp} +24 -42
- data/src/Audio/ALChannelManagement.hpp +1 -1
- data/src/Audio/{AudioOpenAL.cpp → Audio.cpp} +6 -7
- data/src/Audio/Audio.mm +1 -0
- data/src/Audio/AudioFile.hpp +2 -2
- data/src/Audio/AudioToolboxFile.hpp +5 -20
- data/src/Audio/OggFile.hpp +44 -56
- data/src/Audio/SndFile.hpp +2 -2
- data/src/Bitmap/Bitmap.cpp +98 -2
- data/src/Bitmap/BitmapIO.cpp +156 -0
- data/src/DirectoriesApple.mm +76 -0
- data/src/DirectoriesUnix.cpp +5 -12
- data/src/DirectoriesWin.cpp +5 -0
- data/src/Graphics/BlockAllocator.hpp +2 -2
- data/src/Graphics/ClipRectStack.hpp +2 -2
- data/src/Graphics/Common.hpp +2 -2
- data/src/Graphics/DrawOp.hpp +2 -2
- data/src/Graphics/DrawOpQueue.hpp +2 -2
- data/src/Graphics/Graphics.cpp +7 -2
- data/src/Graphics/LargeImageData.cpp +6 -6
- data/src/Graphics/LargeImageData.hpp +3 -3
- data/src/Graphics/Macro.hpp +2 -2
- data/src/Graphics/RenderState.hpp +2 -2
- data/src/Graphics/Resolution.cpp +1 -1
- data/src/Graphics/TexChunk.hpp +2 -2
- data/src/Graphics/Texture.cpp +21 -16
- data/src/Graphics/Texture.hpp +7 -5
- data/src/Graphics/TransformStack.hpp +2 -2
- data/src/Iconv.hpp +2 -2
- data/src/Input/Input.cpp +3 -1
- data/src/Input/{InputTouch.mm → InputUIKit.mm} +32 -26
- data/src/Input/TextInput.cpp +1 -1
- data/src/Text/FormattedString.hpp +2 -2
- data/src/Text/TextApple.mm +8 -8
- data/src/Text/TextMac.cpp +1 -1
- data/src/Text/TextUnix.cpp +1 -1
- data/src/UIKit/GosuAppDelegate.h +8 -0
- data/src/UIKit/GosuAppDelegate.mm +24 -0
- data/src/UIKit/GosuGLView.h +8 -0
- data/src/UIKit/GosuGLView.mm +130 -0
- data/src/UIKit/GosuViewController.h +13 -0
- data/src/UIKit/GosuViewController.mm +214 -0
- data/src/UtilityApple.mm +5 -18
- data/src/Window.cpp +1 -3
- data/src/WindowUIKit.mm +124 -0
- data/src/stb_image.h +6437 -0
- data/src/stb_image_write.h +730 -0
- data/src/stb_vorbis.c +5459 -0
- metadata +18 -26
- data/Gosu/Sockets.hpp +0 -156
- data/src/Audio/AudioOpenAL.mm +0 -1
- data/src/Bitmap/BitmapApple.mm +0 -226
- data/src/Bitmap/BitmapBMP.cpp +0 -79
- data/src/Bitmap/BitmapColorKey.cpp +0 -50
- data/src/Bitmap/BitmapFreeImage.cpp +0 -174
- data/src/Bitmap/BitmapGDIplus.cpp +0 -212
- data/src/Bitmap/BitmapUtils.cpp +0 -76
- data/src/DirectoriesMac.mm +0 -38
- data/src/DirectoriesTouch.mm +0 -38
- data/src/GosuView.hpp +0 -15
- data/src/GosuView.mm +0 -208
- data/src/Input/AccelerometerReader.hpp +0 -10
- data/src/Input/AccelerometerReader.mm +0 -31
- data/src/Sockets/CommSocket.cpp +0 -305
- data/src/Sockets/ListenerSocket.cpp +0 -59
- data/src/Sockets/MessageSocket.cpp +0 -128
- data/src/Sockets/Socket.cpp +0 -145
- data/src/Sockets/Socket.hpp +0 -66
- data/src/WindowTouch.mm +0 -243
- data/src/X11vroot.h +0 -118
@@ -1,59 +0,0 @@
|
|
1
|
-
#include <Gosu/Sockets.hpp>
|
2
|
-
#include "Socket.hpp"
|
3
|
-
#include <cassert>
|
4
|
-
#include <cstring>
|
5
|
-
|
6
|
-
struct Gosu::ListenerSocket::Impl
|
7
|
-
{
|
8
|
-
Socket socket;
|
9
|
-
};
|
10
|
-
|
11
|
-
Gosu::ListenerSocket::ListenerSocket(SocketPort port)
|
12
|
-
: pimpl(new Impl)
|
13
|
-
{
|
14
|
-
pimpl->socket.setHandle(socketCheck(::socket(AF_INET, SOCK_STREAM, 0)));
|
15
|
-
pimpl->socket.setBlocking(false);
|
16
|
-
|
17
|
-
int enable = 1;
|
18
|
-
socketCheck(::setsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_REUSEADDR,
|
19
|
-
reinterpret_cast<char*>(&enable), sizeof enable));
|
20
|
-
|
21
|
-
sockaddr_in addr;
|
22
|
-
std::memset(&addr, 0, sizeof addr);
|
23
|
-
addr.sin_family = AF_INET;
|
24
|
-
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
25
|
-
addr.sin_port = htons(port);
|
26
|
-
socketCheck(::bind(pimpl->socket.handle(),
|
27
|
-
reinterpret_cast<sockaddr*>(&addr), sizeof addr));
|
28
|
-
socketCheck(::listen(pimpl->socket.handle(), 10));
|
29
|
-
}
|
30
|
-
|
31
|
-
Gosu::ListenerSocket::~ListenerSocket()
|
32
|
-
{
|
33
|
-
}
|
34
|
-
|
35
|
-
Gosu::SocketAddress Gosu::ListenerSocket::address() const
|
36
|
-
{
|
37
|
-
return pimpl->socket.address();
|
38
|
-
}
|
39
|
-
|
40
|
-
Gosu::SocketPort Gosu::ListenerSocket::port() const
|
41
|
-
{
|
42
|
-
return pimpl->socket.port();
|
43
|
-
}
|
44
|
-
|
45
|
-
void Gosu::ListenerSocket::update()
|
46
|
-
{
|
47
|
-
while (onConnection)
|
48
|
-
{
|
49
|
-
SocketHandle newHandle =
|
50
|
-
socketCheck(::accept(pimpl->socket.handle(), 0, 0));
|
51
|
-
|
52
|
-
if (newHandle == INVALID_SOCKET)
|
53
|
-
break;
|
54
|
-
|
55
|
-
Socket newSocket;
|
56
|
-
newSocket.setHandle(newHandle);
|
57
|
-
onConnection(newSocket);
|
58
|
-
}
|
59
|
-
}
|
@@ -1,128 +0,0 @@
|
|
1
|
-
#include <Gosu/Sockets.hpp>
|
2
|
-
#include "Socket.hpp"
|
3
|
-
#include <cassert>
|
4
|
-
#include <cstring>
|
5
|
-
#include <vector>
|
6
|
-
|
7
|
-
struct Gosu::MessageSocket::Impl
|
8
|
-
{
|
9
|
-
Socket socket;
|
10
|
-
std::size_t maxMessageSize;
|
11
|
-
};
|
12
|
-
|
13
|
-
Gosu::MessageSocket::MessageSocket(SocketPort port)
|
14
|
-
: pimpl(new Impl)
|
15
|
-
{
|
16
|
-
pimpl->socket.setHandle(socketCheck(::socket(AF_INET, SOCK_DGRAM, 0)));
|
17
|
-
pimpl->socket.setBlocking(false);
|
18
|
-
sockaddr_in addr;
|
19
|
-
std::memset(&addr, 0, sizeof addr);
|
20
|
-
addr.sin_family = AF_INET;
|
21
|
-
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
22
|
-
addr.sin_port = htons(port);
|
23
|
-
socketCheck(::bind(pimpl->socket.handle(),
|
24
|
-
reinterpret_cast<sockaddr*>(&addr), sizeof addr));
|
25
|
-
|
26
|
-
unsigned maxMessageSize;
|
27
|
-
socklen_t size = sizeof maxMessageSize;
|
28
|
-
#ifdef GOSU_IS_WIN
|
29
|
-
socketCheck(::getsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_MAX_MSG_SIZE,
|
30
|
-
reinterpret_cast<char*>(&maxMessageSize), &size));
|
31
|
-
#else
|
32
|
-
socketCheck(::getsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_SNDBUF,
|
33
|
-
reinterpret_cast<char*>(&maxMessageSize), &size));
|
34
|
-
#endif
|
35
|
-
pimpl->maxMessageSize = maxMessageSize;
|
36
|
-
}
|
37
|
-
|
38
|
-
Gosu::MessageSocket::~MessageSocket()
|
39
|
-
{
|
40
|
-
}
|
41
|
-
|
42
|
-
Gosu::SocketAddress Gosu::MessageSocket::address() const
|
43
|
-
{
|
44
|
-
return pimpl->socket.address();
|
45
|
-
}
|
46
|
-
|
47
|
-
Gosu::SocketPort Gosu::MessageSocket::port() const
|
48
|
-
{
|
49
|
-
return pimpl->socket.port();
|
50
|
-
}
|
51
|
-
|
52
|
-
std::size_t Gosu::MessageSocket::maxMessageSize() const
|
53
|
-
{
|
54
|
-
return pimpl->maxMessageSize;
|
55
|
-
}
|
56
|
-
|
57
|
-
void Gosu::MessageSocket::update()
|
58
|
-
{
|
59
|
-
std::vector<char> buffer(maxMessageSize());
|
60
|
-
|
61
|
-
sockaddr_in addr;
|
62
|
-
socklen_t size = sizeof addr;
|
63
|
-
|
64
|
-
for (;;)
|
65
|
-
{
|
66
|
-
int received = ::recvfrom(pimpl->socket.handle(), &buffer.front(),
|
67
|
-
buffer.size(), 0, reinterpret_cast<sockaddr*>(&addr),
|
68
|
-
&size);
|
69
|
-
|
70
|
-
if (received != SOCKET_ERROR && onReceive)
|
71
|
-
{
|
72
|
-
onReceive(ntohl(addr.sin_addr.s_addr),
|
73
|
-
ntohs(addr.sin_port), &buffer.front(), received);
|
74
|
-
}
|
75
|
-
else switch (lastSocketError())
|
76
|
-
{
|
77
|
-
// Ignore some of the errors.
|
78
|
-
case GOSU_SOCK_ERR(EWOULDBLOCK):
|
79
|
-
case GOSU_SOCK_ERR(ENETDOWN):
|
80
|
-
case GOSU_SOCK_ERR(ENETRESET):
|
81
|
-
case GOSU_SOCK_ERR(ETIMEDOUT):
|
82
|
-
case GOSU_SOCK_ERR(ECONNRESET):
|
83
|
-
return;
|
84
|
-
|
85
|
-
// Everything else is unexpected.
|
86
|
-
default:
|
87
|
-
throwLastSocketError();
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
void Gosu::MessageSocket::send(SocketAddress address, SocketPort port,
|
93
|
-
const void* buffer, std::size_t size)
|
94
|
-
{
|
95
|
-
sockaddr_in addr;
|
96
|
-
std::memset(&addr, 0, sizeof addr);
|
97
|
-
addr.sin_family = AF_INET;
|
98
|
-
addr.sin_addr.s_addr = htonl(address);
|
99
|
-
addr.sin_port = htons(port);
|
100
|
-
|
101
|
-
int sent = ::sendto(pimpl->socket.handle(),
|
102
|
-
reinterpret_cast<const char*>(buffer), size, 0,
|
103
|
-
reinterpret_cast<sockaddr*>(&addr), sizeof addr);
|
104
|
-
|
105
|
-
if (sent == static_cast<int>(size))
|
106
|
-
return; // Yay, did it!
|
107
|
-
|
108
|
-
assert(sent == SOCKET_ERROR); // Don't expect partial sends.
|
109
|
-
|
110
|
-
switch (lastSocketError())
|
111
|
-
{
|
112
|
-
// Just ignore a lot of errors... this is UDP, right?
|
113
|
-
case GOSU_SOCK_ERR(ENETDOWN):
|
114
|
-
case GOSU_SOCK_ERR(ENETRESET):
|
115
|
-
case GOSU_SOCK_ERR(ENOBUFS):
|
116
|
-
case GOSU_SOCK_ERR(EWOULDBLOCK):
|
117
|
-
case GOSU_SOCK_ERR(EHOSTUNREACH):
|
118
|
-
case GOSU_SOCK_ERR(ECONNABORTED):
|
119
|
-
case GOSU_SOCK_ERR(ECONNRESET):
|
120
|
-
case GOSU_SOCK_ERR(ENETUNREACH):
|
121
|
-
case GOSU_SOCK_ERR(ETIMEDOUT):
|
122
|
-
break;
|
123
|
-
|
124
|
-
// Everything else means more than just another lost packet, though.
|
125
|
-
default:
|
126
|
-
throwLastSocketError();
|
127
|
-
}
|
128
|
-
}
|
data/src/Sockets/Socket.cpp
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
#include <Gosu/Sockets.hpp>
|
2
|
-
#include "Socket.hpp"
|
3
|
-
#ifdef GOSU_IS_WIN
|
4
|
-
#include <Gosu/WinUtility.hpp>
|
5
|
-
#endif
|
6
|
-
#include <cstdlib>
|
7
|
-
#include <cstring>
|
8
|
-
#include <algorithm>
|
9
|
-
#include <stdexcept>
|
10
|
-
|
11
|
-
namespace Gosu
|
12
|
-
{
|
13
|
-
namespace
|
14
|
-
{
|
15
|
-
void cleanup()
|
16
|
-
{
|
17
|
-
#ifdef GOSU_IS_WIN
|
18
|
-
::WSACleanup();
|
19
|
-
#endif
|
20
|
-
}
|
21
|
-
|
22
|
-
void needsSockLib()
|
23
|
-
{
|
24
|
-
#ifdef GOSU_IS_WIN
|
25
|
-
static bool initialized = false;
|
26
|
-
if (!initialized)
|
27
|
-
{
|
28
|
-
WSADATA data;
|
29
|
-
if (::WSAStartup(0x0202, &data) != 0)
|
30
|
-
throw std::runtime_error("Could not initialize "
|
31
|
-
"Windows sockets");
|
32
|
-
|
33
|
-
initialized = true;
|
34
|
-
std::atexit(cleanup);
|
35
|
-
}
|
36
|
-
#endif
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
int Gosu::lastSocketError()
|
42
|
-
{
|
43
|
-
#ifdef GOSU_IS_WIN
|
44
|
-
needsSockLib();
|
45
|
-
return ::WSAGetLastError();
|
46
|
-
#else
|
47
|
-
return errno;
|
48
|
-
#endif
|
49
|
-
}
|
50
|
-
|
51
|
-
GOSU_NORETURN void Gosu::throwLastSocketError()
|
52
|
-
{
|
53
|
-
#ifdef GOSU_IS_WIN
|
54
|
-
Win::throwLastError();
|
55
|
-
#else
|
56
|
-
throw std::runtime_error(strerror(errno));
|
57
|
-
#endif
|
58
|
-
}
|
59
|
-
|
60
|
-
Gosu::SocketAddress Gosu::stringToAddress(const std::string& s)
|
61
|
-
{
|
62
|
-
needsSockLib();
|
63
|
-
|
64
|
-
SocketAddress address;
|
65
|
-
|
66
|
-
// Try to interpret name as an IP number string.
|
67
|
-
address = ntohl(::inet_addr(s.c_str()));
|
68
|
-
if (address != INADDR_NONE)
|
69
|
-
return address;
|
70
|
-
|
71
|
-
// This didn't work: Resolve host name via DNS.
|
72
|
-
hostent* host = ::gethostbyname(s.c_str());
|
73
|
-
if (!host)
|
74
|
-
return 0;
|
75
|
-
in_addr addr = *reinterpret_cast<in_addr*>(host->h_addr_list[0]);
|
76
|
-
return ntohl(addr.s_addr);
|
77
|
-
}
|
78
|
-
|
79
|
-
std::string Gosu::addressToString(SocketAddress address)
|
80
|
-
{
|
81
|
-
needsSockLib();
|
82
|
-
|
83
|
-
in_addr addr;
|
84
|
-
addr.s_addr = htonl(address);
|
85
|
-
return ::inet_ntoa(addr);
|
86
|
-
}
|
87
|
-
|
88
|
-
Gosu::Socket::Socket()
|
89
|
-
: handle_(INVALID_SOCKET)
|
90
|
-
{
|
91
|
-
needsSockLib();
|
92
|
-
}
|
93
|
-
|
94
|
-
Gosu::Socket::~Socket()
|
95
|
-
{
|
96
|
-
setHandle(INVALID_SOCKET);
|
97
|
-
}
|
98
|
-
|
99
|
-
Gosu::SocketHandle Gosu::Socket::handle() const
|
100
|
-
{
|
101
|
-
return handle_;
|
102
|
-
}
|
103
|
-
|
104
|
-
void Gosu::Socket::setHandle(SocketHandle value)
|
105
|
-
{
|
106
|
-
if (handle() != INVALID_SOCKET)
|
107
|
-
{
|
108
|
-
::closesocket(handle());
|
109
|
-
}
|
110
|
-
|
111
|
-
handle_ = value;
|
112
|
-
}
|
113
|
-
|
114
|
-
void Gosu::Socket::setBlocking(bool value)
|
115
|
-
{
|
116
|
-
unsigned long enable = !value;
|
117
|
-
socketCheck(::ioctlsocket(handle(), FIONBIO, &enable));
|
118
|
-
}
|
119
|
-
|
120
|
-
Gosu::SocketAddress Gosu::Socket::address() const
|
121
|
-
{
|
122
|
-
sockaddr_in addr;
|
123
|
-
int size = sizeof addr;
|
124
|
-
socketCheck(::getsockname(handle(),
|
125
|
-
reinterpret_cast<sockaddr*>(&addr),
|
126
|
-
reinterpret_cast<socklen_t*>(&size)));
|
127
|
-
|
128
|
-
return ntohl(addr.sin_addr.s_addr);
|
129
|
-
}
|
130
|
-
|
131
|
-
Gosu::SocketPort Gosu::Socket::port() const
|
132
|
-
{
|
133
|
-
sockaddr_in addr;
|
134
|
-
int size = sizeof addr;
|
135
|
-
socketCheck(::getsockname(handle(),
|
136
|
-
reinterpret_cast<sockaddr*>(&addr),
|
137
|
-
reinterpret_cast<socklen_t*>(&size)));
|
138
|
-
|
139
|
-
return ntohs(addr.sin_port);
|
140
|
-
}
|
141
|
-
|
142
|
-
void Gosu::Socket::swap(Socket& other)
|
143
|
-
{
|
144
|
-
std::swap(handle_, other.handle_);
|
145
|
-
}
|
data/src/Sockets/Socket.hpp
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
#ifndef GOSUIMPL_SOCKETS_HPP
|
2
|
-
#define GOSUIMPL_SOCKETS_HPP
|
3
|
-
|
4
|
-
#include <Gosu/Platform.hpp>
|
5
|
-
|
6
|
-
#ifdef GOSU_IS_WIN
|
7
|
-
#include "winsock2.h"
|
8
|
-
#define GOSU_SOCK_ERR(code) WSA##code
|
9
|
-
namespace Gosu { typedef SOCKET SocketHandle; }
|
10
|
-
typedef int socklen_t;
|
11
|
-
#else
|
12
|
-
#include <unistd.h>
|
13
|
-
#include <sys/errno.h>
|
14
|
-
#include <sys/socket.h>
|
15
|
-
#include <netinet/in.h>
|
16
|
-
#include <arpa/inet.h>
|
17
|
-
#include <netdb.h>
|
18
|
-
#include <sys/ioctl.h>
|
19
|
-
#define GOSU_SOCK_ERR(code) code
|
20
|
-
#define INVALID_SOCKET -1
|
21
|
-
#define SOCKET_ERROR -1
|
22
|
-
#define closesocket close
|
23
|
-
#define ioctlsocket ioctl
|
24
|
-
namespace Gosu { typedef int SocketHandle; }
|
25
|
-
#endif
|
26
|
-
|
27
|
-
namespace Gosu
|
28
|
-
{
|
29
|
-
// Owns a socket and manages library initialization.
|
30
|
-
class Socket {
|
31
|
-
Socket(const Socket&);
|
32
|
-
Socket& operator=(const Socket&);
|
33
|
-
|
34
|
-
SocketHandle handle_;
|
35
|
-
public:
|
36
|
-
Socket();
|
37
|
-
~Socket();
|
38
|
-
|
39
|
-
SocketHandle handle() const;
|
40
|
-
void setHandle(SocketHandle value);
|
41
|
-
void setBlocking(bool value);
|
42
|
-
|
43
|
-
SocketAddress address() const;
|
44
|
-
SocketPort port() const;
|
45
|
-
|
46
|
-
void swap(Socket& other);
|
47
|
-
};
|
48
|
-
|
49
|
-
int lastSocketError();
|
50
|
-
|
51
|
-
GOSU_NORETURN void throwLastSocketError();
|
52
|
-
|
53
|
-
template<typename T>
|
54
|
-
T socketCheck(T retVal)
|
55
|
-
{
|
56
|
-
if (retVal == SOCKET_ERROR &&
|
57
|
-
lastSocketError() != GOSU_SOCK_ERR(EWOULDBLOCK))
|
58
|
-
{
|
59
|
-
throwLastSocketError();
|
60
|
-
}
|
61
|
-
|
62
|
-
return retVal;
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
#endif
|
data/src/WindowTouch.mm
DELETED
@@ -1,243 +0,0 @@
|
|
1
|
-
#include <Gosu/Window.hpp>
|
2
|
-
#include <Gosu/Graphics.hpp>
|
3
|
-
#include <Gosu/Audio.hpp>
|
4
|
-
#include <Gosu/Input.hpp>
|
5
|
-
#include "MacUtility.hpp"
|
6
|
-
#include "GosuView.hpp"
|
7
|
-
|
8
|
-
#import <CoreGraphics/CoreGraphics.h>
|
9
|
-
#import <UIKit/UIKit.h>
|
10
|
-
#import <OpenGLES/EAGL.h>
|
11
|
-
#import <QuartzCore/QuartzCore.h>
|
12
|
-
|
13
|
-
#include <OpenAL/alc.h>
|
14
|
-
#include <AudioToolbox/AudioSession.h>
|
15
|
-
|
16
|
-
using namespace std::tr1::placeholders;
|
17
|
-
|
18
|
-
namespace Gosu
|
19
|
-
{
|
20
|
-
static CGRect &screenRect()
|
21
|
-
{
|
22
|
-
static CGRect screenRect = [[UIScreen mainScreen] nativeBounds];
|
23
|
-
return screenRect;
|
24
|
-
}
|
25
|
-
|
26
|
-
unsigned screenWidth()
|
27
|
-
{
|
28
|
-
return screenRect().size.width;
|
29
|
-
}
|
30
|
-
|
31
|
-
unsigned screenHeight()
|
32
|
-
{
|
33
|
-
return screenRect().size.height;
|
34
|
-
}
|
35
|
-
|
36
|
-
ALCcontext *sharedContext();
|
37
|
-
}
|
38
|
-
|
39
|
-
static void handleAudioInterruption(void *unused, UInt32 inInterruptionState)
|
40
|
-
{
|
41
|
-
if (inInterruptionState == kAudioSessionBeginInterruption) {
|
42
|
-
alcMakeContextCurrent(NULL);
|
43
|
-
} else if (inInterruptionState == kAudioSessionEndInterruption) {
|
44
|
-
alcMakeContextCurrent(Gosu::sharedContext());
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
int main(int argc, char *argv[])
|
49
|
-
{
|
50
|
-
try
|
51
|
-
{
|
52
|
-
[[NSAutoreleasePool alloc] init];
|
53
|
-
return UIApplicationMain(argc, argv, nil, @"GosuAppDelegate");
|
54
|
-
}
|
55
|
-
catch (const std::exception& e)
|
56
|
-
{
|
57
|
-
NSLog(@"Terminating due to C++ exception: %s", e.what());
|
58
|
-
throw;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
class Gosu::Audio {};
|
63
|
-
|
64
|
-
struct Gosu::Window::Impl
|
65
|
-
{
|
66
|
-
ObjRef<UIWindow> window;
|
67
|
-
ObjRef<GosuViewController> controller;
|
68
|
-
std::auto_ptr<Graphics> graphics;
|
69
|
-
std::auto_ptr<Input> input;
|
70
|
-
double interval;
|
71
|
-
};
|
72
|
-
|
73
|
-
Gosu::Window& windowInstance();
|
74
|
-
|
75
|
-
@interface GosuAppDelegate : NSObject <UIApplicationDelegate>
|
76
|
-
@end
|
77
|
-
|
78
|
-
namespace
|
79
|
-
{
|
80
|
-
// Ugly patching to bridge the C++ and ObjC sides.
|
81
|
-
GosuView* gosuView = nil;
|
82
|
-
bool pausedSong = false;
|
83
|
-
bool paused = false;
|
84
|
-
|
85
|
-
id timerOrDisplayLink = nil;
|
86
|
-
}
|
87
|
-
|
88
|
-
@implementation GosuAppDelegate
|
89
|
-
- (void)setupTimerOrDisplayLink
|
90
|
-
{
|
91
|
-
if (timerOrDisplayLink)
|
92
|
-
return;
|
93
|
-
|
94
|
-
NSInteger targetFPS = round(1000.0 / windowInstance().updateInterval());
|
95
|
-
|
96
|
-
if (60 % targetFPS != 0) {
|
97
|
-
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:windowInstance().updateInterval() / 1000.0 target:self selector:@selector(doTick:) userInfo:nil repeats:YES];
|
98
|
-
|
99
|
-
timerOrDisplayLink = [timer retain];
|
100
|
-
}
|
101
|
-
else {
|
102
|
-
CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doTick:)];
|
103
|
-
displayLink.frameInterval = 60 / targetFPS;
|
104
|
-
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
105
|
-
|
106
|
-
timerOrDisplayLink = [displayLink retain];
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
111
|
-
{
|
112
|
-
[UIApplication sharedApplication].statusBarHidden = YES;
|
113
|
-
[self setupTimerOrDisplayLink];
|
114
|
-
|
115
|
-
AudioSessionInitialize(NULL, NULL, handleAudioInterruption, NULL);
|
116
|
-
}
|
117
|
-
|
118
|
-
- (void)applicationWillResignActive:(UIApplication *)application
|
119
|
-
{
|
120
|
-
if (Gosu::Song::currentSong()) {
|
121
|
-
Gosu::Song::currentSong()->pause();
|
122
|
-
pausedSong = true;
|
123
|
-
}
|
124
|
-
paused = true;
|
125
|
-
windowInstance().loseFocus();
|
126
|
-
}
|
127
|
-
|
128
|
-
- (void)applicationDidBecomeActive:(UIApplication *)application
|
129
|
-
{
|
130
|
-
if (pausedSong) {
|
131
|
-
if (Gosu::Song::currentSong())
|
132
|
-
Gosu::Song::currentSong()->play();
|
133
|
-
pausedSong = false;
|
134
|
-
}
|
135
|
-
paused = false;
|
136
|
-
}
|
137
|
-
|
138
|
-
- (void)applicationDidEnterBackground:(UIApplication *)application
|
139
|
-
{
|
140
|
-
[timerOrDisplayLink invalidate];
|
141
|
-
[timerOrDisplayLink release];
|
142
|
-
timerOrDisplayLink = nil;
|
143
|
-
}
|
144
|
-
|
145
|
-
- (void)applicationWillEnterForeground:(UIApplication *)application
|
146
|
-
{
|
147
|
-
[self setupTimerOrDisplayLink];
|
148
|
-
}
|
149
|
-
|
150
|
-
- (void)doTick:(id)sender
|
151
|
-
{
|
152
|
-
if (!paused)
|
153
|
-
windowInstance().update();
|
154
|
-
[gosuView drawView];
|
155
|
-
Gosu::Song::update();
|
156
|
-
windowInstance().input().update();
|
157
|
-
}
|
158
|
-
@end
|
159
|
-
|
160
|
-
Gosu::Window::Window(unsigned width, unsigned height,
|
161
|
-
bool fullscreen, double updateInterval)
|
162
|
-
: pimpl(new Impl)
|
163
|
-
{
|
164
|
-
pimpl->window.reset([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
|
165
|
-
pimpl->controller.reset([[GosuViewController alloc] init]);
|
166
|
-
gosuView = (GosuView*)pimpl->controller.obj().view;
|
167
|
-
pimpl->window.obj().rootViewController = pimpl->controller.obj();
|
168
|
-
|
169
|
-
pimpl->graphics.reset(new Graphics(screenHeight(), screenWidth(), false));
|
170
|
-
pimpl->graphics->setResolution(width, height);
|
171
|
-
pimpl->input.reset(new Input(gosuView, updateInterval));
|
172
|
-
pimpl->input->onTouchBegan = std::tr1::bind(&Window::touchBegan, this, _1);
|
173
|
-
pimpl->input->onTouchMoved = std::tr1::bind(&Window::touchMoved, this, _1);
|
174
|
-
pimpl->input->onTouchEnded = std::tr1::bind(&Window::touchEnded, this, _1);
|
175
|
-
pimpl->interval = updateInterval;
|
176
|
-
|
177
|
-
// TODO: Get rid of performSelector:withObject:afterDelay:, without causing a C++ static initialization error
|
178
|
-
[pimpl->window.obj() performSelector:@selector(makeKeyAndVisible) withObject:nil afterDelay:0];
|
179
|
-
}
|
180
|
-
|
181
|
-
Gosu::Window::~Window()
|
182
|
-
{
|
183
|
-
}
|
184
|
-
|
185
|
-
std::wstring Gosu::Window::caption() const
|
186
|
-
{
|
187
|
-
return L"";
|
188
|
-
}
|
189
|
-
|
190
|
-
void Gosu::Window::setCaption(const std::wstring& caption)
|
191
|
-
{
|
192
|
-
}
|
193
|
-
|
194
|
-
double Gosu::Window::updateInterval() const
|
195
|
-
{
|
196
|
-
return pimpl->interval;
|
197
|
-
}
|
198
|
-
|
199
|
-
const Gosu::Graphics& Gosu::Window::graphics() const
|
200
|
-
{
|
201
|
-
return *pimpl->graphics;
|
202
|
-
}
|
203
|
-
|
204
|
-
Gosu::Graphics& Gosu::Window::graphics()
|
205
|
-
{
|
206
|
-
return *pimpl->graphics;
|
207
|
-
}
|
208
|
-
|
209
|
-
const Gosu::Audio& Gosu::Window::audio() const
|
210
|
-
{
|
211
|
-
static Gosu::Audio audio;
|
212
|
-
return audio;
|
213
|
-
}
|
214
|
-
|
215
|
-
Gosu::Audio& Gosu::Window::audio()
|
216
|
-
{
|
217
|
-
static Gosu::Audio audio;
|
218
|
-
return audio;
|
219
|
-
}
|
220
|
-
|
221
|
-
const Gosu::Input& Gosu::Window::input() const
|
222
|
-
{
|
223
|
-
return *pimpl->input;
|
224
|
-
}
|
225
|
-
|
226
|
-
Gosu::Input& Gosu::Window::input()
|
227
|
-
{
|
228
|
-
return *pimpl->input;
|
229
|
-
}
|
230
|
-
|
231
|
-
void Gosu::Window::show()
|
232
|
-
{
|
233
|
-
}
|
234
|
-
|
235
|
-
void Gosu::Window::close()
|
236
|
-
{
|
237
|
-
throw std::logic_error("Cannot close windows manually on iOS");
|
238
|
-
}
|
239
|
-
|
240
|
-
void* Gosu::Window::rootViewController() const
|
241
|
-
{
|
242
|
-
return pimpl->controller.get();
|
243
|
-
}
|