gosu 1.4.6 → 2.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL_atomic.h +2 -3
  4. data/dependencies/SDL/include/SDL_audio.h +7 -7
  5. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  6. data/dependencies/SDL/include/SDL_endian.h +3 -3
  7. data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
  8. data/dependencies/SDL/include/SDL_hints.h +72 -28
  9. data/dependencies/SDL/include/SDL_joystick.h +8 -5
  10. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  11. data/dependencies/SDL/include/SDL_main.h +7 -0
  12. data/dependencies/SDL/include/SDL_mouse.h +6 -7
  13. data/dependencies/SDL/include/SDL_mutex.h +79 -5
  14. data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
  15. data/dependencies/SDL/include/SDL_power.h +7 -8
  16. data/dependencies/SDL/include/SDL_render.h +5 -0
  17. data/dependencies/SDL/include/SDL_revision.h +2 -2
  18. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  19. data/dependencies/SDL/include/SDL_stdinc.h +19 -11
  20. data/dependencies/SDL/include/SDL_thread.h +2 -2
  21. data/dependencies/SDL/include/SDL_version.h +2 -2
  22. data/dependencies/SDL/include/SDL_video.h +30 -2
  23. data/dependencies/SDL/include/begin_code.h +7 -7
  24. data/dependencies/SDL/include/close_code.h +2 -2
  25. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  26. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  27. data/dependencies/SDL_sound/SDL_sound.h +1 -1
  28. data/dependencies/SDL_sound/dr_flac.h +48 -23
  29. data/dependencies/SDL_sound/dr_mp3.h +34 -14
  30. data/dependencies/SDL_sound/stb_vorbis.h +3 -2
  31. data/dependencies/mojoAL/mojoal.c +1 -1
  32. data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
  33. data/ext/gosu-ffi/gosu-ffi.def +464 -0
  34. data/ffi/Gosu.cpp +307 -0
  35. data/ffi/Gosu.h +84 -0
  36. data/ffi/Gosu_Channel.cpp +62 -0
  37. data/ffi/Gosu_Channel.h +17 -0
  38. data/ffi/Gosu_Color.cpp +132 -0
  39. data/ffi/Gosu_Color.h +31 -0
  40. data/ffi/Gosu_Constants.cpp +334 -0
  41. data/ffi/Gosu_FFI.h +34 -0
  42. data/ffi/Gosu_FFI_internal.h +161 -0
  43. data/ffi/Gosu_Font.cpp +92 -0
  44. data/ffi/Gosu_Font.h +32 -0
  45. data/ffi/Gosu_Image.cpp +206 -0
  46. data/ffi/Gosu_Image.h +60 -0
  47. data/ffi/Gosu_Sample.cpp +29 -0
  48. data/ffi/Gosu_Sample.h +14 -0
  49. data/ffi/Gosu_Song.cpp +69 -0
  50. data/ffi/Gosu_Song.h +18 -0
  51. data/ffi/Gosu_TextInput.cpp +94 -0
  52. data/ffi/Gosu_TextInput.h +25 -0
  53. data/ffi/Gosu_Window.cpp +314 -0
  54. data/ffi/Gosu_Window.h +78 -0
  55. data/include/Gosu/Audio.hpp +6 -11
  56. data/include/Gosu/Bitmap.hpp +38 -53
  57. data/include/Gosu/Buffer.hpp +54 -0
  58. data/include/Gosu/Color.hpp +27 -35
  59. data/include/Gosu/Directories.hpp +25 -28
  60. data/include/Gosu/Drawable.hpp +58 -0
  61. data/include/Gosu/Font.hpp +6 -5
  62. data/include/Gosu/Fwd.hpp +4 -6
  63. data/include/Gosu/Gosu.hpp +5 -5
  64. data/include/Gosu/Graphics.hpp +51 -61
  65. data/include/Gosu/GraphicsBase.hpp +1 -11
  66. data/include/Gosu/Image.hpp +11 -14
  67. data/include/Gosu/Math.hpp +50 -72
  68. data/include/Gosu/Transform.hpp +32 -0
  69. data/include/Gosu/Utility.hpp +51 -1
  70. data/include/Gosu/Version.hpp +3 -3
  71. data/include/Gosu/Window.hpp +15 -9
  72. data/lib/SDL2.dll +0 -0
  73. data/lib/gosu/channel.rb +49 -0
  74. data/lib/gosu/color.rb +150 -0
  75. data/lib/gosu/compat.rb +29 -8
  76. data/lib/gosu/constants.rb +386 -0
  77. data/lib/gosu/ffi.rb +258 -0
  78. data/lib/gosu/font.rb +56 -0
  79. data/lib/gosu/gl_tex_info.rb +33 -0
  80. data/lib/gosu/gosu.rb +210 -0
  81. data/lib/gosu/image.rb +141 -0
  82. data/lib/gosu/numeric.rb +17 -0
  83. data/lib/gosu/preview.rb +6 -6
  84. data/lib/gosu/sample.rb +24 -0
  85. data/lib/gosu/song.rb +56 -0
  86. data/lib/gosu/text_input.rb +69 -0
  87. data/lib/gosu/window.rb +228 -0
  88. data/lib/gosu.rb +29 -8
  89. data/lib64/SDL2.dll +0 -0
  90. data/rdoc/gosu.rb +0 -2
  91. data/src/Audio.cpp +12 -12
  92. data/src/AudioFile.hpp +5 -4
  93. data/src/AudioFileAudioToolbox.cpp +8 -8
  94. data/src/AudioFileSDLSound.cpp +7 -10
  95. data/src/BinPacker.cpp +187 -0
  96. data/src/BinPacker.hpp +55 -0
  97. data/src/Bitmap.cpp +166 -144
  98. data/src/BitmapIO.cpp +60 -86
  99. data/src/Buffer.cpp +159 -0
  100. data/src/Color.cpp +75 -80
  101. data/src/Directories.cpp +47 -0
  102. data/src/DirectoriesUIKit.cpp +50 -0
  103. data/src/DrawOp.hpp +9 -4
  104. data/src/DrawOpQueue.hpp +2 -2
  105. data/src/Drawable.cpp +95 -0
  106. data/src/EmptyDrawable.hpp +38 -0
  107. data/src/FPS.cpp +31 -0
  108. data/src/Font.cpp +104 -74
  109. data/src/GosuGLView.cpp +14 -6
  110. data/src/GosuViewController.cpp +2 -10
  111. data/src/Graphics.cpp +60 -126
  112. data/src/GraphicsImpl.hpp +17 -47
  113. data/src/Image.cpp +41 -35
  114. data/src/Input.cpp +7 -8
  115. data/src/Macro.cpp +6 -6
  116. data/src/Macro.hpp +4 -4
  117. data/src/MarkupParser.cpp +5 -5
  118. data/src/Math.cpp +35 -22
  119. data/src/OffScreenTarget.cpp +53 -49
  120. data/src/OffScreenTarget.hpp +13 -11
  121. data/src/OpenGLContext.cpp +117 -0
  122. data/src/OpenGLContext.hpp +41 -0
  123. data/src/RenderState.hpp +21 -19
  124. data/src/Resolution.cpp +23 -21
  125. data/src/TexChunk.cpp +35 -80
  126. data/src/TexChunk.hpp +44 -35
  127. data/src/Text.cpp +1 -1
  128. data/src/TextBuilder.cpp +35 -21
  129. data/src/TextBuilder.hpp +6 -9
  130. data/src/Texture.cpp +62 -80
  131. data/src/Texture.hpp +25 -23
  132. data/src/TiledDrawable.cpp +150 -0
  133. data/src/TiledDrawable.hpp +47 -0
  134. data/src/TimingApple.cpp +1 -1
  135. data/src/Transform.cpp +45 -50
  136. data/src/TransformStack.hpp +16 -16
  137. data/src/TrueTypeFont.cpp +59 -51
  138. data/src/TrueTypeFont.hpp +6 -7
  139. data/src/TrueTypeFontApple.cpp +28 -19
  140. data/src/TrueTypeFontUnix.cpp +27 -23
  141. data/src/TrueTypeFontWin.cpp +30 -30
  142. data/src/Utility.cpp +84 -21
  143. data/src/UtilityWin.cpp +45 -0
  144. data/src/Window.cpp +92 -142
  145. data/src/WindowUIKit.cpp +14 -14
  146. metadata +72 -31
  147. data/include/Gosu/IO.hpp +0 -254
  148. data/include/Gosu/ImageData.hpp +0 -53
  149. data/include/Gosu/Inspection.hpp +0 -7
  150. data/lib/gosu/patches.rb +0 -66
  151. data/lib/gosu/run.rb +0 -20
  152. data/lib/gosu/swig_patches.rb +0 -110
  153. data/src/BlockAllocator.cpp +0 -131
  154. data/src/BlockAllocator.hpp +0 -32
  155. data/src/DirectoriesApple.cpp +0 -69
  156. data/src/DirectoriesUnix.cpp +0 -46
  157. data/src/DirectoriesWin.cpp +0 -65
  158. data/src/EmptyImageData.hpp +0 -52
  159. data/src/FileUnix.cpp +0 -99
  160. data/src/FileWin.cpp +0 -88
  161. data/src/IO.cpp +0 -60
  162. data/src/Iconv.hpp +0 -51
  163. data/src/Inspection.cpp +0 -27
  164. data/src/LargeImageData.cpp +0 -215
  165. data/src/LargeImageData.hpp +0 -39
  166. data/src/Log.hpp +0 -19
  167. data/src/RubyGosu.cxx +0 -13100
  168. data/src/RubyGosu.h +0 -49
  169. data/src/WinUtility.cpp +0 -61
  170. data/src/WinUtility.hpp +0 -27
@@ -1,110 +0,0 @@
1
- # Exceptions in Window callbacks often get lost, this is especially annoying in draw/update.
2
- # It is not clear whether this is a SWIG issue or if some stack frame is not exception
3
- # compatible, but I just call protected_update etc. in the Ruby wrapper so I can add this
4
- # custom debugging help:
5
- class Gosu::Window
6
- alias_method :initialize_with_bitmask, :initialize
7
-
8
- def initialize(width, height, *args)
9
- $gosu_gl_blocks = nil
10
-
11
- if args.first.is_a? Hash
12
- flags = 0
13
- flags |= 1 if args.first[:fullscreen]
14
- flags |= 2 if args.first[:resizable]
15
- flags |= 4 if args.first[:borderless]
16
- initialize_with_bitmask(width, height, flags, args.first[:update_interval] || 16.666666)
17
- else
18
- initialize_with_bitmask(width, height, args[0] ? 1 : 0, args[1] || 16.666666)
19
- end
20
- end
21
-
22
- %w(update draw needs_redraw? needs_cursor?
23
- gain_focus lose_focus button_down button_up
24
- gamepad_connected gamepad_disconnected drop).each do |callback|
25
- define_method "protected_#{callback}" do |*args|
26
- begin
27
- # If there has been an exception, don't do anything as to not make matters worse.
28
- # Conveniently turn the return value into a boolean result (for needs_cursor? etc).
29
- defined?(@_exception) ? false : !!send(callback, *args)
30
- rescue Exception => e
31
- # Exit the message loop naturally, then re-throw during the next tick.
32
- @_exception = e
33
- close!
34
- false
35
- end
36
- end
37
- end
38
-
39
- def protected_draw_2
40
- protected_draw
41
- $gosu_gl_blocks_2 = $gosu_gl_blocks
42
- $gosu_gl_blocks = nil
43
- end
44
-
45
- alias_method :show_internal, :show
46
- def show
47
- show_internal
48
- # Try to format the message nicely, without any useless patching that we are
49
- # doing here.
50
- if defined? @_exception
51
- if @_exception.backtrace.is_a? Array and not @_exception.backtrace.frozen?
52
- @_exception.backtrace.reject! { |line| line.include? "lib/gosu/swig_patches.rb" }
53
- end
54
- raise @_exception
55
- end
56
- end
57
-
58
- alias_method :tick_internal, :tick
59
- def tick
60
- value = tick_internal
61
- # Try to format the message nicely, without any useless patching that we are
62
- # doing here.
63
- if defined? @_exception
64
- if @_exception.backtrace.is_a? Array and not @_exception.backtrace.frozen?
65
- @_exception.backtrace.reject! { |line| line.include? "lib/gosu/swig_patches.rb" }
66
- end
67
- raise @_exception
68
- end
69
-
70
- value
71
- end
72
- end
73
-
74
- module Gosu
75
- # Keep a reference to these blocks that is only cleared after Window#draw.
76
- # Otherwise, the GC might free these blocks while Gosu is still rendering.
77
- def self.gl(z = nil, &block)
78
- $gosu_gl_blocks ||= []
79
- $gosu_gl_blocks << block
80
- if z.nil?
81
- unsafe_gl(&block)
82
- else
83
- unsafe_gl(z, &block)
84
- end
85
- end
86
- end
87
-
88
- # SWIG somehow maps the instance method "argb" as an overload of the class
89
- # method of the same name.
90
- class Gosu::Color
91
- alias_method :initialize_without_argb, :initialize
92
-
93
- # The (a,r,g,b) constructor overload was dropped in C++ to reduce ambiguity,
94
- # adding it via %extend in gosu.i does not work, so patch it here.
95
- def initialize(*args)
96
- if args.size == 4
97
- initialize_without_argb(args[1], args[2], args[3])
98
- self.alpha = args[0]
99
- else
100
- initialize_without_argb(*args)
101
- end
102
- end
103
-
104
- alias_method :argb, :to_i
105
- end
106
-
107
- # SWIG will not let me rename my method to '[]=', so use alias_method here.
108
- class Gosu::Font
109
- alias_method :[]=, :set_image
110
- end
@@ -1,131 +0,0 @@
1
- #include <Gosu/Utility.hpp>
2
- #include "BlockAllocator.hpp"
3
- #include <stdexcept>
4
- #include <vector>
5
- using namespace std;
6
-
7
- struct Gosu::BlockAllocator::Impl : private Gosu::Noncopyable
8
- {
9
- unsigned width, height;
10
-
11
- vector<Block> blocks;
12
- unsigned first_x, first_y;
13
- unsigned max_w, max_h;
14
-
15
- void mark_block_used(const Block& block, unsigned a_width, unsigned a_height)
16
- {
17
- first_x += a_width;
18
- if (first_x + a_width >= width) {
19
- first_x = 0;
20
- first_y += a_height;
21
- }
22
- blocks.push_back(block);
23
- }
24
-
25
- bool is_block_free(const Block& block) const
26
- {
27
- // right and bottom are exclusive (not part of the block).
28
- unsigned right = block.left + block.width;
29
- unsigned bottom = block.top + block.height;
30
-
31
- // Block isn't valid.
32
- if (right > width || bottom > height) return false;
33
-
34
- // Test if the block collides with any existing rects.
35
- for (auto b : blocks) {
36
- if (b.left < right && block.left < b.left + b.width &&
37
- b.top < bottom && block.top < b.top + b.height) {
38
- return false;
39
- }
40
- }
41
-
42
- return true;
43
- }
44
- };
45
-
46
- Gosu::BlockAllocator::BlockAllocator(unsigned width, unsigned height)
47
- : pimpl(new Impl)
48
- {
49
- pimpl->width = width;
50
- pimpl->height = height;
51
-
52
- pimpl->first_x = 0;
53
- pimpl->first_y = 0;
54
-
55
- pimpl->max_w = width;
56
- pimpl->max_h = height;
57
- }
58
-
59
- Gosu::BlockAllocator::~BlockAllocator()
60
- {
61
- }
62
-
63
- unsigned Gosu::BlockAllocator::width() const
64
- {
65
- return pimpl->width;
66
- }
67
-
68
- unsigned Gosu::BlockAllocator::height() const
69
- {
70
- return pimpl->height;
71
- }
72
-
73
- bool Gosu::BlockAllocator::alloc(unsigned a_width, unsigned a_height, Block& b)
74
- {
75
- // The rect wouldn't even fit onto the texture!
76
- if (a_width > width() || a_height > height()) return false;
77
-
78
- // We know there's no space left.
79
- if (a_width > pimpl->max_w && a_height > pimpl->max_h) return false;
80
-
81
- // Start to look for a place next to the last returned rect. Chances are
82
- // good we'll find a place there.
83
- b = Block(pimpl->first_x, pimpl->first_y, a_width, a_height);
84
- if (pimpl->is_block_free(b)) {
85
- pimpl->mark_block_used(b, a_width, a_height);
86
- return true;
87
- }
88
-
89
- // Brute force: Look for a free place on this texture.
90
- unsigned& x = b.left;
91
- unsigned& y = b.top;
92
- for (y = 0; y <= height() - a_height; y += 16) {
93
- for (x = 0; x <= width() - a_width; x += 8) {
94
- if (!pimpl->is_block_free(b)) continue;
95
-
96
- // Found a nice place!
97
-
98
- // Try to make up for the large for ()-stepping.
99
- while (y > 0 && pimpl->is_block_free(Block(x, y - 1, a_width, a_height))) --y;
100
- while (x > 0 && pimpl->is_block_free(Block(x - 1, y, a_width, a_height))) --x;
101
-
102
- pimpl->mark_block_used(b, a_width, a_height);
103
- return true;
104
- }
105
- }
106
-
107
- // So there was no space for the bitmap. Remember this for later.
108
- pimpl->max_w = a_width - 1;
109
- pimpl->max_h = a_height - 1;
110
- return false;
111
- }
112
-
113
- void Gosu::BlockAllocator::block(unsigned left, unsigned top, unsigned width, unsigned height)
114
- {
115
- pimpl->blocks.emplace_back(left, top, width, height);
116
- }
117
-
118
- void Gosu::BlockAllocator::free(unsigned left, unsigned top, unsigned width, unsigned height)
119
- {
120
- for (auto it = pimpl->blocks.begin(), end = pimpl->blocks.end(); it != end; ++it) {
121
- if (it->left == left && it->top == top && it->width == width && it->height == height) {
122
- pimpl->blocks.erase(it);
123
- // Be optimistic again, since we might have deleted the largest/only block.
124
- pimpl->max_w = pimpl->width - 1;
125
- pimpl->max_h = pimpl->height - 1;
126
- return;
127
- }
128
- }
129
-
130
- throw logic_error("Tried to free an invalid block");
131
- }
@@ -1,32 +0,0 @@
1
- #pragma once
2
-
3
- #include <Gosu/Platform.hpp>
4
- #include <memory>
5
-
6
- namespace Gosu
7
- {
8
- class BlockAllocator
9
- {
10
- struct Impl;
11
- const std::unique_ptr<Impl> pimpl;
12
-
13
- public:
14
- struct Block
15
- {
16
- unsigned left, top, width, height;
17
- Block() {}
18
- Block(unsigned left, unsigned top, unsigned width, unsigned height)
19
- : left(left), top(top), width(width), height(height) {}
20
- };
21
-
22
- BlockAllocator(unsigned width, unsigned height);
23
- ~BlockAllocator();
24
-
25
- unsigned width() const;
26
- unsigned height() const;
27
-
28
- bool alloc(unsigned width, unsigned height, Block& block);
29
- void block(unsigned left, unsigned top, unsigned width, unsigned height);
30
- void free(unsigned left, unsigned top, unsigned width, unsigned height);
31
- };
32
- }
@@ -1,69 +0,0 @@
1
- #include <Gosu/Platform.hpp>
2
- #if defined(GOSU_IS_MAC)
3
-
4
- #import <Gosu/Directories.hpp>
5
- #import <Foundation/Foundation.h>
6
- #import <unistd.h>
7
-
8
- void Gosu::use_resource_directory()
9
- {
10
- chdir(resource_prefix().c_str());
11
- }
12
-
13
- const std::string& Gosu::user_settings_prefix()
14
- {
15
- static const std::string user_settings_prefix = [] {
16
- @autoreleasepool {
17
- NSString* library =
18
- NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)
19
- .firstObject;
20
- NSString* preferences = [library stringByAppendingPathComponent:@"Preferences"];
21
-
22
- return std::string{preferences.UTF8String ?: "."} + "/";
23
- }
24
- }();
25
- return user_settings_prefix;
26
- }
27
-
28
- const std::string& Gosu::user_documents_prefix()
29
- {
30
- static const std::string user_documents_prefix = [] {
31
- @autoreleasepool {
32
- NSString* documents =
33
- NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
34
- .firstObject;
35
-
36
- return std::string{documents.UTF8String ?: "."} + "/";
37
- }
38
- }();
39
- return user_documents_prefix;
40
- }
41
-
42
- const std::string& Gosu::resource_prefix()
43
- {
44
- static const std::string resource_prefix = [] {
45
- @autoreleasepool {
46
- NSString* resources = [NSBundle mainBundle].resourcePath;
47
- return std::string{resources.UTF8String ?: "."} + "/";
48
- }
49
- }();
50
- return resource_prefix;
51
- }
52
-
53
- const std::string& Gosu::shared_resource_prefix()
54
- {
55
- #ifdef GOSU_IS_IPHONE
56
- return resource_prefix();
57
- #else
58
- static const std::string shared_resource_prefix = [] {
59
- @autoreleasepool {
60
- NSString* bundle_path = [NSBundle mainBundle].bundlePath;
61
- NSString* containing_path = [bundle_path stringByDeletingLastPathComponent];
62
- return std::string{containing_path.UTF8String ?: "."};
63
- }
64
- }();
65
- return shared_resource_prefix;
66
- #endif
67
- }
68
-
69
- #endif
@@ -1,46 +0,0 @@
1
- #include <Gosu/Platform.hpp>
2
- #if defined(GOSU_IS_X)
3
-
4
- #include <Gosu/Directories.hpp>
5
- #include <Gosu/Utility.hpp>
6
- #include <cassert>
7
- #include <pwd.h>
8
- #include <sys/types.h>
9
- #include <unistd.h>
10
-
11
- static std::string home_dir()
12
- {
13
- passwd* pwd = getpwuid(geteuid());
14
- return pwd && pwd->pw_dir ? pwd->pw_dir : ".";
15
- }
16
-
17
- void Gosu::use_resource_directory()
18
- {
19
- // Do nothing, we expect the user to have the correct cwd on Linux.
20
- }
21
-
22
- const std::string& Gosu::resource_prefix()
23
- {
24
- static const std::string empty;
25
- return empty;
26
- }
27
-
28
- const std::string& Gosu::shared_resource_prefix()
29
- {
30
- static const std::string empty;
31
- return empty;
32
- }
33
-
34
- const std::string& Gosu::user_settings_prefix()
35
- {
36
- static const std::string user_settings_prefix = home_dir() + "/.";
37
- return user_settings_prefix;
38
- }
39
-
40
- const std::string& Gosu::user_documents_prefix()
41
- {
42
- static const std::string user_documents_prefix = home_dir() + "/";
43
- return user_documents_prefix;
44
- }
45
-
46
- #endif
@@ -1,65 +0,0 @@
1
- #include <Gosu/Platform.hpp>
2
- #if defined(GOSU_IS_WIN)
3
-
4
- #include <Gosu/Directories.hpp>
5
- #include <Gosu/Utility.hpp>
6
- #include "WinUtility.hpp"
7
- #include <cwchar>
8
- #include <shlobj.h>
9
- #include <stdexcept>
10
-
11
- static std::string special_folder_path(int csidl)
12
- {
13
- WCHAR buf[MAX_PATH + 2];
14
- if (FAILED(SHGetFolderPathW(nullptr, csidl | CSIDL_FLAG_CREATE, nullptr, 0, buf)))
15
- throw std::runtime_error{"Error getting special folder path"};
16
- size_t len = std::wcslen(buf);
17
- if (buf[len - 1] != L'\\') {
18
- buf[len] = L'\\';
19
- buf[len + 1] = 0;
20
- }
21
- return Gosu::utf16_to_utf8(buf);
22
- }
23
-
24
- std::string exe_filename()
25
- {
26
- WCHAR buffer[MAX_PATH * 2];
27
- Gosu::winapi_check(GetModuleFileNameW(nullptr, buffer, MAX_PATH * 2),
28
- "getting the module filename");
29
- return Gosu::utf16_to_utf8(buffer);
30
- }
31
-
32
- void Gosu::use_resource_directory()
33
- {
34
- SetCurrentDirectory(utf8_to_utf16(resource_prefix()).c_str());
35
- }
36
-
37
- const std::string& Gosu::resource_prefix()
38
- {
39
- static const std::string resource_prefix = [] {
40
- std::string result = exe_filename();
41
- const auto last_delim = result.find_last_of("\\/");
42
- result.resize(last_delim == std::string::npos ? 0 : last_delim + 1);
43
- return result;
44
- }();
45
- return resource_prefix;
46
- }
47
-
48
- const std::string& Gosu::shared_resource_prefix()
49
- {
50
- return resource_prefix();
51
- }
52
-
53
- const std::string& Gosu::user_settings_prefix()
54
- {
55
- static const std::string user_settings_prefix = special_folder_path(CSIDL_APPDATA);
56
- return user_settings_prefix;
57
- }
58
-
59
- const std::string& Gosu::user_documents_prefix()
60
- {
61
- static const std::string user_documents_prefix = special_folder_path(CSIDL_PERSONAL);
62
- return user_documents_prefix;
63
- }
64
-
65
- #endif
@@ -1,52 +0,0 @@
1
- #pragma once
2
-
3
- #include <Gosu/ImageData.hpp>
4
- #include <memory>
5
-
6
- namespace Gosu
7
- {
8
- class EmptyImageData : public ImageData
9
- {
10
- public:
11
- int width() const override //
12
- {
13
- return 0;
14
- }
15
-
16
- int height() const override //
17
- {
18
- return 0;
19
- }
20
-
21
- void draw(double, double, Color, double, double, Color, //
22
- double, double, Color, double, double, Color, //
23
- ZPos, BlendMode) const override
24
- {
25
- }
26
-
27
- GLTexInfo* gl_tex_info() const override //
28
- {
29
- return nullptr;
30
- }
31
-
32
- Bitmap to_bitmap() const override //
33
- {
34
- return Bitmap();
35
- }
36
-
37
- std::unique_ptr<ImageData> subimage(int, int, int, int) const override //
38
- {
39
- return nullptr;
40
- }
41
-
42
- void insert(const Bitmap&, int x, int y) override //
43
- {
44
- }
45
-
46
- static const std::shared_ptr<EmptyImageData>& instance_ptr()
47
- {
48
- static std::shared_ptr<EmptyImageData> instance = std::make_shared<EmptyImageData>();
49
- return instance;
50
- }
51
- };
52
- }
data/src/FileUnix.cpp DELETED
@@ -1,99 +0,0 @@
1
- #include <Gosu/Platform.hpp>
2
- #if !defined(GOSU_IS_WIN)
3
-
4
- #include <Gosu/IO.hpp>
5
- #include <Gosu/Utility.hpp>
6
- #include <cstring>
7
- #include <fcntl.h>
8
- #include <stdexcept>
9
- #include <sys/mman.h>
10
- #include <sys/types.h>
11
- #include <unistd.h>
12
-
13
- #ifdef HAVE_SYS_STAT_H
14
- #include <sys/stat.h>
15
- #endif
16
-
17
- using namespace std;
18
-
19
- struct Gosu::File::Impl : private Gosu::Noncopyable
20
- {
21
- int fd = -1;
22
- void* mapping = MAP_FAILED;
23
-
24
- ~Impl()
25
- {
26
- if (fd >= 0) {
27
- close(fd);
28
- }
29
- }
30
- };
31
-
32
- Gosu::File::File(const string& filename, FileMode mode)
33
- : pimpl(new Impl)
34
- {
35
- int flags;
36
-
37
- switch (mode) {
38
- case FM_READ:
39
- flags = O_RDONLY;
40
- break;
41
- case FM_REPLACE:
42
- flags = O_RDWR | O_TRUNC | O_CREAT;
43
- break;
44
- case FM_ALTER:
45
- flags = O_RDWR | O_CREAT;
46
- break;
47
- default:
48
- throw invalid_argument("Unknown file mode: " + to_string(mode));
49
- }
50
-
51
- // TODO: Locking flags?
52
-
53
- pimpl->fd = open(filename.c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
54
- if (pimpl->fd < 0) throw runtime_error("Cannot open file " + filename);
55
-
56
- if (mode == FM_READ && size() > 0) {
57
- pimpl->mapping = mmap(nullptr, size(), PROT_READ, 0, pimpl->fd, 0);
58
- }
59
- }
60
-
61
- Gosu::File::~File()
62
- {
63
- if (pimpl->mapping != MAP_FAILED) {
64
- munmap(pimpl->mapping, size());
65
- }
66
- }
67
-
68
- size_t Gosu::File::size() const
69
- {
70
- // TODO: Error checking?
71
- return static_cast<size_t>(lseek(pimpl->fd, 0, SEEK_END));
72
- }
73
-
74
- void Gosu::File::resize(size_t new_size)
75
- {
76
- ftruncate(pimpl->fd, new_size);
77
- }
78
-
79
- void Gosu::File::read(size_t offset, size_t length, void* dest_buffer) const
80
- {
81
- // TODO: Bounds checks?
82
- if (pimpl->mapping != MAP_FAILED) {
83
- memcpy(dest_buffer, static_cast<const char*>(pimpl->mapping) + offset, length);
84
- }
85
- else {
86
- // TODO: Error checking?
87
- lseek(pimpl->fd, offset, SEEK_SET);
88
- ::read(pimpl->fd, dest_buffer, length);
89
- }
90
- }
91
-
92
- void Gosu::File::write(size_t offset, size_t length, const void* source_buffer)
93
- {
94
- // TODO: Error checking?
95
- lseek(pimpl->fd, offset, SEEK_SET);
96
- ::write(pimpl->fd, source_buffer, length);
97
- }
98
-
99
- #endif
data/src/FileWin.cpp DELETED
@@ -1,88 +0,0 @@
1
- #include <Gosu/Platform.hpp>
2
- #if defined(GOSU_IS_WIN)
3
-
4
- #include "WinUtility.hpp"
5
- #include <Gosu/IO.hpp>
6
- #include <Gosu/Utility.hpp>
7
- #include <windows.h>
8
- using namespace std;
9
-
10
- // TODO: Error checking
11
-
12
- struct Gosu::File::Impl : private Gosu::Noncopyable
13
- {
14
- HANDLE handle = INVALID_HANDLE_VALUE;
15
-
16
- ~Impl()
17
- {
18
- if (handle != INVALID_HANDLE_VALUE) {
19
- CloseHandle(handle);
20
- }
21
- }
22
- };
23
-
24
- Gosu::File::File(const string& filename, FileMode mode)
25
- : pimpl(new Impl)
26
- {
27
- DWORD access;
28
- switch (mode) {
29
- case FM_READ:
30
- access = GENERIC_READ;
31
- break;
32
- case FM_REPLACE:
33
- access = GENERIC_WRITE;
34
- break;
35
- case FM_ALTER:
36
- access = GENERIC_READ | GENERIC_WRITE;
37
- break;
38
- }
39
- DWORD share_mode = FILE_SHARE_READ;
40
- DWORD creation_disp = (mode == FM_READ) ? OPEN_EXISTING : OPEN_ALWAYS;
41
-
42
- wstring wfilename = utf8_to_utf16(filename);
43
- pimpl->handle = CreateFileW(wfilename.c_str(), access, share_mode, 0, creation_disp,
44
- FILE_ATTRIBUTE_NORMAL, 0);
45
- if (pimpl->handle == INVALID_HANDLE_VALUE) {
46
- throw_last_winapi_error("opening " + filename);
47
- }
48
- if (mode == FM_REPLACE) {
49
- resize(0);
50
- }
51
- }
52
-
53
- Gosu::File::~File()
54
- {
55
- }
56
-
57
- size_t Gosu::File::size() const
58
- {
59
- return GetFileSize(pimpl->handle, 0);
60
- }
61
-
62
- void Gosu::File::resize(size_t new_size)
63
- {
64
- if (SetFilePointer(pimpl->handle, new_size, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
65
- throw_last_winapi_error("setting the file pointer");
66
- }
67
- winapi_check(SetEndOfFile(pimpl->handle), "resizing a file");
68
- }
69
-
70
- void Gosu::File::read(size_t offset, size_t length, void* dest_buffer) const
71
- {
72
- if (SetFilePointer(pimpl->handle, offset, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
73
- throw_last_winapi_error("setting the file pointer");
74
- }
75
- DWORD dummy;
76
- winapi_check(ReadFile(pimpl->handle, dest_buffer, length, &dummy, 0));
77
- }
78
-
79
- void Gosu::File::write(size_t offset, size_t length, const void* source_buffer)
80
- {
81
- if (SetFilePointer(pimpl->handle, offset, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
82
- throw_last_winapi_error("setting the file pointer");
83
- }
84
- DWORD dummy;
85
- winapi_check(WriteFile(pimpl->handle, source_buffer, length, &dummy, 0));
86
- }
87
-
88
- #endif