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
@@ -0,0 +1,156 @@
|
|
1
|
+
#include <Gosu/Bitmap.hpp>
|
2
|
+
#include <Gosu/Platform.hpp>
|
3
|
+
#include <Gosu/IO.hpp>
|
4
|
+
#include <Gosu/Utility.hpp>
|
5
|
+
|
6
|
+
#define STB_IMAGE_IMPLEMENTATION
|
7
|
+
#define STBI_NO_STDIO
|
8
|
+
#define STBI_NO_LINEAR
|
9
|
+
#include "../stb_image.h"
|
10
|
+
|
11
|
+
namespace
|
12
|
+
{
|
13
|
+
int readCallback(void* user, char* data, int size)
|
14
|
+
{
|
15
|
+
Gosu::Reader* reader = static_cast<Gosu::Reader*>(user);
|
16
|
+
std::size_t remaining = reader->resource().size() - reader->position();
|
17
|
+
std::size_t actualSize = (size < remaining ? size : remaining);
|
18
|
+
reader->read(data, actualSize);
|
19
|
+
return actualSize;
|
20
|
+
}
|
21
|
+
|
22
|
+
void skipCallback(void* user, int n)
|
23
|
+
{
|
24
|
+
Gosu::Reader* reader = static_cast<Gosu::Reader*>(user);
|
25
|
+
reader->setPosition(reader->position() + n);
|
26
|
+
}
|
27
|
+
|
28
|
+
int eofCallback(void* user)
|
29
|
+
{
|
30
|
+
Gosu::Reader* reader = static_cast<Gosu::Reader*>(user);
|
31
|
+
return reader->position() == reader->resource().size();
|
32
|
+
}
|
33
|
+
|
34
|
+
bool isBMP(Gosu::Reader reader)
|
35
|
+
{
|
36
|
+
std::size_t remaining = reader.resource().size() - reader.position();
|
37
|
+
if (remaining < 2)
|
38
|
+
return false;
|
39
|
+
char magicBytes[2];
|
40
|
+
reader.read(magicBytes, sizeof magicBytes);
|
41
|
+
reader.seek(sizeof magicBytes);
|
42
|
+
return magicBytes[0] == 'B' && magicBytes[1] == 'M';
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
void Gosu::loadImageFile(Gosu::Bitmap& bitmap, const std::wstring& filename)
|
47
|
+
{
|
48
|
+
Buffer buffer;
|
49
|
+
loadFile(buffer, filename);
|
50
|
+
loadImageFile(bitmap, buffer.frontReader());
|
51
|
+
}
|
52
|
+
|
53
|
+
void Gosu::loadImageFile(Gosu::Bitmap& bitmap, Reader input)
|
54
|
+
{
|
55
|
+
bool needsColorKey = isBMP(input);
|
56
|
+
|
57
|
+
stbi_io_callbacks callbacks;
|
58
|
+
callbacks.read = readCallback;
|
59
|
+
callbacks.skip = skipCallback;
|
60
|
+
callbacks.eof = eofCallback;
|
61
|
+
int x, y, n;
|
62
|
+
stbi_uc* bytes = stbi_load_from_callbacks(&callbacks, &input, &x, &y, &n, STBI_rgb_alpha);
|
63
|
+
|
64
|
+
if (bytes == 0) {
|
65
|
+
// TODO - stbi_failure_reason is not thread safe. Everything here should be wrapped in a mutex.
|
66
|
+
throw std::runtime_error("Cannot load image: " + std::string(stbi_failure_reason()));
|
67
|
+
}
|
68
|
+
|
69
|
+
bitmap.resize(x, y);
|
70
|
+
std::memcpy(bitmap.data(), bytes, x * y * sizeof(Gosu::Color));
|
71
|
+
|
72
|
+
stbi_image_free(bytes);
|
73
|
+
|
74
|
+
if (needsColorKey)
|
75
|
+
applyColorKey(bitmap, Gosu::Color::FUCHSIA);
|
76
|
+
}
|
77
|
+
|
78
|
+
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
79
|
+
#include "../stb_image_write.h"
|
80
|
+
|
81
|
+
// TODO: Move into proper internal header
|
82
|
+
namespace Gosu { bool isExtension(const wchar_t* str, const wchar_t* ext); }
|
83
|
+
|
84
|
+
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, const std::wstring& filename)
|
85
|
+
{
|
86
|
+
int ok;
|
87
|
+
std::string utf8 = Gosu::wstringToUTF8(filename);
|
88
|
+
|
89
|
+
if (isExtension(filename.c_str(), L"bmp"))
|
90
|
+
{
|
91
|
+
ok = stbi_write_bmp(utf8.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data());
|
92
|
+
}
|
93
|
+
else if (isExtension(filename.c_str(), L"tga"))
|
94
|
+
{
|
95
|
+
ok = stbi_write_tga(utf8.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data());
|
96
|
+
}
|
97
|
+
else
|
98
|
+
{
|
99
|
+
ok = stbi_write_png(utf8.c_str(), bitmap.width(), bitmap.height(), 4, bitmap.data(), 0);
|
100
|
+
}
|
101
|
+
|
102
|
+
if (ok == 0)
|
103
|
+
throw std::runtime_error("Could not save image data to file: " + utf8);
|
104
|
+
}
|
105
|
+
|
106
|
+
void Gosu::saveImageFile(const Gosu::Bitmap& bitmap, Gosu::Writer writer,
|
107
|
+
const std::wstring& formatHint)
|
108
|
+
{
|
109
|
+
unsigned char* rgba =
|
110
|
+
const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bitmap.data()));
|
111
|
+
|
112
|
+
int length;
|
113
|
+
unsigned char* png =
|
114
|
+
stbi_write_png_to_mem(rgba, 0, bitmap.width(), bitmap.height(), 4, &length);
|
115
|
+
|
116
|
+
if (png == 0)
|
117
|
+
throw std::runtime_error("Could not save image data to memory");
|
118
|
+
|
119
|
+
try
|
120
|
+
{
|
121
|
+
writer.write(png, length);
|
122
|
+
}
|
123
|
+
catch (...)
|
124
|
+
{
|
125
|
+
STBIW_FREE(png);
|
126
|
+
throw;
|
127
|
+
}
|
128
|
+
|
129
|
+
STBIW_FREE(png);
|
130
|
+
}
|
131
|
+
|
132
|
+
// Deprecated methods.
|
133
|
+
|
134
|
+
Gosu::Reader Gosu::loadFromPNG(Bitmap& bitmap, Reader reader)
|
135
|
+
{
|
136
|
+
loadImageFile(bitmap, reader);
|
137
|
+
reader.setPosition(reader.resource().size());
|
138
|
+
return reader;
|
139
|
+
}
|
140
|
+
|
141
|
+
Gosu::Reader Gosu::loadFromBMP(Bitmap& bitmap, Reader reader)
|
142
|
+
{
|
143
|
+
return loadFromPNG(bitmap, reader);
|
144
|
+
}
|
145
|
+
|
146
|
+
Gosu::Writer Gosu::saveToPNG(const Bitmap& bitmap, Writer writer)
|
147
|
+
{
|
148
|
+
saveImageFile(bitmap, writer, L".png");
|
149
|
+
return writer.resource().backWriter();
|
150
|
+
}
|
151
|
+
|
152
|
+
Gosu::Writer Gosu::saveToBMP(const Bitmap& bitmap, Writer writer)
|
153
|
+
{
|
154
|
+
saveImageFile(bitmap, writer, L".bmp");
|
155
|
+
return writer.resource().backWriter();
|
156
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#import <Gosu/Directories.hpp>
|
2
|
+
#import <Gosu/Utility.hpp>
|
3
|
+
#import "AppleUtility.hpp"
|
4
|
+
#import <Foundation/Foundation.h>
|
5
|
+
#import <unistd.h>
|
6
|
+
|
7
|
+
|
8
|
+
static std::wstring stringFromNSString(NSString* string, const std::wstring& def)
|
9
|
+
{
|
10
|
+
return string ? Gosu::utf8ToWstring([string UTF8String]) : def;
|
11
|
+
}
|
12
|
+
|
13
|
+
void Gosu::useResourceDirectory()
|
14
|
+
{
|
15
|
+
chdir(Gosu::wstringToUTF8(resourcePrefix()).c_str());
|
16
|
+
}
|
17
|
+
|
18
|
+
std::wstring Gosu::userSettingsPrefix()
|
19
|
+
{
|
20
|
+
static std::wstring result;
|
21
|
+
if (result.empty())
|
22
|
+
{
|
23
|
+
ObjCRef<NSAutoreleasePool> pool([NSAutoreleasePool new]);
|
24
|
+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
|
25
|
+
NSString *libraryDirectory = [paths objectAtIndex:0];
|
26
|
+
NSString *preferencesDirectory = [libraryDirectory stringByAppendingPathComponent:@"Preferences"];
|
27
|
+
|
28
|
+
result = stringFromNSString(preferencesDirectory, L".") + L"/";
|
29
|
+
}
|
30
|
+
return result;
|
31
|
+
}
|
32
|
+
|
33
|
+
std::wstring Gosu::userDocsPrefix()
|
34
|
+
{
|
35
|
+
static std::wstring result;
|
36
|
+
if (result.empty())
|
37
|
+
{
|
38
|
+
ObjCRef<NSAutoreleasePool> pool([NSAutoreleasePool new]);
|
39
|
+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
40
|
+
NSString *documentsDirectory = [paths objectAtIndex:0];
|
41
|
+
|
42
|
+
result = stringFromNSString(documentsDirectory, L".") + L"/";
|
43
|
+
}
|
44
|
+
return result;
|
45
|
+
}
|
46
|
+
|
47
|
+
std::wstring Gosu::resourcePrefix()
|
48
|
+
{
|
49
|
+
static std::wstring result;
|
50
|
+
if (result.empty())
|
51
|
+
{
|
52
|
+
ObjCRef<NSAutoreleasePool> pool([NSAutoreleasePool new]);
|
53
|
+
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
|
54
|
+
|
55
|
+
result = stringFromNSString(resourcePath, L".") + L"/";
|
56
|
+
}
|
57
|
+
return result;
|
58
|
+
}
|
59
|
+
|
60
|
+
std::wstring Gosu::sharedResourcePrefix()
|
61
|
+
{
|
62
|
+
#ifdef GOSU_IS_IPHONE
|
63
|
+
return resourcePrefix();
|
64
|
+
#else
|
65
|
+
static std::wstring result;
|
66
|
+
if (result.empty())
|
67
|
+
{
|
68
|
+
ObjCRef<NSAutoreleasePool> pool([NSAutoreleasePool new]);
|
69
|
+
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
|
70
|
+
NSString *containingPath = [bundlePath stringByDeletingLastPathComponent];
|
71
|
+
|
72
|
+
result = stringFromNSString(containingPath, L".");
|
73
|
+
}
|
74
|
+
return result;
|
75
|
+
#endif
|
76
|
+
}
|
data/src/DirectoriesUnix.cpp
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
#include <Gosu/Directories.hpp>
|
2
|
-
#include <Gosu/Platform.hpp>
|
3
2
|
#include <Gosu/Utility.hpp>
|
4
3
|
#include <cassert>
|
5
|
-
#include <vector>
|
6
4
|
#include <sys/types.h>
|
7
5
|
#include <unistd.h>
|
8
6
|
#include <pwd.h>
|
@@ -17,7 +15,11 @@ namespace
|
|
17
15
|
}
|
18
16
|
}
|
19
17
|
|
20
|
-
|
18
|
+
void Gosu::useResourceDirectory()
|
19
|
+
{
|
20
|
+
// Do nothing - the current directory HAS to be correct on Linux.
|
21
|
+
}
|
22
|
+
|
21
23
|
std::wstring Gosu::resourcePrefix()
|
22
24
|
{
|
23
25
|
return std::wstring();
|
@@ -27,22 +29,13 @@ std::wstring Gosu::sharedResourcePrefix()
|
|
27
29
|
{
|
28
30
|
return std::wstring();
|
29
31
|
}
|
30
|
-
#endif
|
31
32
|
|
32
33
|
std::wstring Gosu::userSettingsPrefix()
|
33
34
|
{
|
34
|
-
#ifdef GOSU_IS_MAC
|
35
|
-
return homeDir() + L"/Library/Preferences/";
|
36
|
-
#else
|
37
35
|
return homeDir() + L"/.";
|
38
|
-
#endif
|
39
36
|
}
|
40
37
|
|
41
38
|
std::wstring Gosu::userDocsPrefix()
|
42
39
|
{
|
43
|
-
#ifdef GOSU_IS_MAC
|
44
|
-
return homeDir() + L"/Documents/";
|
45
|
-
#else
|
46
40
|
return homeDir() + L"/";
|
47
|
-
#endif
|
48
41
|
}
|
data/src/DirectoriesWin.cpp
CHANGED
data/src/Graphics/Common.hpp
CHANGED
data/src/Graphics/DrawOp.hpp
CHANGED
data/src/Graphics/Graphics.cpp
CHANGED
@@ -392,6 +392,8 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
392
392
|
if (flags == 1)
|
393
393
|
flags = ifTileable;
|
394
394
|
|
395
|
+
bool wantsRetro = (flags & ifRetro);
|
396
|
+
|
395
397
|
// Special case: If the texture is supposed to have hard borders, is
|
396
398
|
// quadratic, has a size that is at least 64 pixels but no more than maxSize
|
397
399
|
// pixels and a power of two, create a single texture just for this image.
|
@@ -400,7 +402,7 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
400
402
|
(srcWidth & (srcWidth - 1)) == 0 &&
|
401
403
|
srcWidth >= 64 && srcWidth <= maxSize)
|
402
404
|
{
|
403
|
-
std::tr1::shared_ptr<Texture> texture(new Texture(srcWidth));
|
405
|
+
std::tr1::shared_ptr<Texture> texture(new Texture(srcWidth, wantsRetro));
|
404
406
|
GOSU_UNIQUE_PTR<ImageData> data;
|
405
407
|
|
406
408
|
// Use the source bitmap directly if the source area completely covers
|
@@ -440,6 +442,9 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
440
442
|
{
|
441
443
|
std::tr1::shared_ptr<Texture> texture(*i);
|
442
444
|
|
445
|
+
if (texture->retro() != wantsRetro)
|
446
|
+
continue;
|
447
|
+
|
443
448
|
GOSU_UNIQUE_PTR<ImageData> data;
|
444
449
|
data = texture->tryAlloc(texture, bmp, 1);
|
445
450
|
if (data.get())
|
@@ -449,7 +454,7 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
449
454
|
// All textures are full: Create a new one.
|
450
455
|
|
451
456
|
std::tr1::shared_ptr<Texture> texture;
|
452
|
-
texture.reset(new Texture(maxSize));
|
457
|
+
texture.reset(new Texture(maxSize, wantsRetro));
|
453
458
|
textures.push_back(texture);
|
454
459
|
|
455
460
|
GOSU_UNIQUE_PTR<ImageData> data;
|
@@ -7,7 +7,7 @@
|
|
7
7
|
using namespace std;
|
8
8
|
|
9
9
|
Gosu::LargeImageData::LargeImageData(const Bitmap& source,
|
10
|
-
unsigned partWidth, unsigned partHeight, unsigned
|
10
|
+
unsigned partWidth, unsigned partHeight, unsigned imageFlags)
|
11
11
|
{
|
12
12
|
fullWidth = source.width();
|
13
13
|
fullHeight = source.height();
|
@@ -31,15 +31,15 @@ Gosu::LargeImageData::LargeImageData(const Bitmap& source,
|
|
31
31
|
if (y == partsY - 1 && source.height() % partHeight != 0)
|
32
32
|
srcHeight = source.height() % partHeight;
|
33
33
|
|
34
|
-
unsigned localFlags = ifTileable;
|
34
|
+
unsigned localFlags = ifTileable | imageFlags;
|
35
35
|
if (x == 0)
|
36
|
-
localFlags = (localFlags & ~ifTileableLeft) | (
|
36
|
+
localFlags = (localFlags & ~ifTileableLeft) | (imageFlags & ifTileableLeft);
|
37
37
|
if (x == partsX - 1)
|
38
|
-
localFlags = (localFlags & ~ifTileableRight) | (
|
38
|
+
localFlags = (localFlags & ~ifTileableRight) | (imageFlags & ifTileableRight);
|
39
39
|
if (y == 0)
|
40
|
-
localFlags = (localFlags & ~ifTileableTop) | (
|
40
|
+
localFlags = (localFlags & ~ifTileableTop) | (imageFlags & ifTileableTop);
|
41
41
|
if (y == partsY - 1)
|
42
|
-
localFlags = (localFlags & ~ifTileableBottom) | (
|
42
|
+
localFlags = (localFlags & ~ifTileableBottom) | (imageFlags & ifTileableBottom);
|
43
43
|
|
44
44
|
parts[y * partsX + x].reset(Graphics::createImage(source,
|
45
45
|
x * partWidth, y * partHeight, srcWidth, srcHeight,
|
@@ -1,5 +1,5 @@
|
|
1
|
-
#ifndef
|
2
|
-
#define
|
1
|
+
#ifndef GOSU_SRC_LARGEIMAGEDATA_HPP
|
2
|
+
#define GOSU_SRC_LARGEIMAGEDATA_HPP
|
3
3
|
|
4
4
|
#include <Gosu/Fwd.hpp>
|
5
5
|
#include <Gosu/ImageData.hpp>
|
@@ -17,7 +17,7 @@ namespace Gosu
|
|
17
17
|
|
18
18
|
public:
|
19
19
|
LargeImageData(const Bitmap& source,
|
20
|
-
unsigned partWidth, unsigned partHeight, unsigned
|
20
|
+
unsigned partWidth, unsigned partHeight, unsigned imageFlags);
|
21
21
|
|
22
22
|
int width() const;
|
23
23
|
int height() const;
|
data/src/Graphics/Macro.hpp
CHANGED
data/src/Graphics/Resolution.cpp
CHANGED
data/src/Graphics/TexChunk.hpp
CHANGED