gosu 0.7.14 → 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +1 -2
- data/Gosu/Graphics.hpp +6 -0
- data/Gosu/Image.hpp +4 -0
- data/Gosu/Version.hpp +2 -2
- data/GosuImpl/Audio/ALChannelManagement.hpp +3 -3
- data/GosuImpl/Audio/AudioOpenAL.mm +11 -19
- data/GosuImpl/Audio/AudioToolboxFile.hpp +2 -1
- data/GosuImpl/Graphics/Common.hpp +3 -0
- data/GosuImpl/Graphics/DrawOp.hpp +105 -29
- data/GosuImpl/Graphics/GosuView.hpp +6 -0
- data/GosuImpl/Graphics/GosuView.mm +34 -1
- data/GosuImpl/Graphics/Graphics.cpp +57 -17
- data/GosuImpl/Graphics/Image.cpp +5 -0
- data/GosuImpl/Graphics/LargeImageData.cpp +1 -1
- data/GosuImpl/Graphics/Macro.hpp +79 -0
- data/GosuImpl/Graphics/TexChunk.cpp +3 -3
- data/GosuImpl/Graphics/TexChunk.hpp +2 -2
- data/GosuImpl/Graphics/TextMac.cpp +6 -0
- data/GosuImpl/Graphics/TextTouch.mm +49 -14
- data/GosuImpl/Graphics/Texture.cpp +2 -2
- data/GosuImpl/Graphics/Texture.hpp +3 -2
- data/GosuImpl/InputMac.mm +2 -0
- data/GosuImpl/RubyGosu.swg +15 -4
- data/GosuImpl/RubyGosu_wrap.cxx +85 -6
- data/GosuImpl/Sockets/CommSocket.cpp +304 -304
- data/GosuImpl/Sockets/Socket.cpp +1 -1
- data/GosuImpl/WindowMac.mm +3 -0
- data/GosuImpl/WindowTouch.mm +1 -0
- data/Rakefile +13 -5
- data/mac/Gosu.xcodeproj/jlnr.pbxuser +292 -280
- data/mac/Gosu.xcodeproj/jlnr.perspectivev3 +46 -48
- data/mac/Gosu.xcodeproj/project.pbxproj +58 -18
- data/reference/cpp/_audio_8hpp-source.html +2 -1
- data/reference/cpp/_audio_8hpp.html +11 -4
- data/reference/cpp/_audio_8hpp_source.html +178 -0
- data/reference/cpp/_auto_link_8hpp-source.html +1 -0
- data/reference/cpp/_auto_link_8hpp.html +5 -4
- data/reference/cpp/_auto_link_8hpp_source.html +85 -0
- data/reference/cpp/_bitmap_8hpp-source.html +9 -8
- data/reference/cpp/_bitmap_8hpp.html +11 -4
- data/reference/cpp/_bitmap_8hpp_source.html +131 -0
- data/reference/cpp/_buttons_mac_8hpp-source.html +124 -123
- data/reference/cpp/_buttons_mac_8hpp.html +10 -3
- data/reference/cpp/_buttons_mac_8hpp_source.html +206 -0
- data/reference/cpp/_color_8hpp-source.html +18 -17
- data/reference/cpp/_color_8hpp.html +16 -4
- data/reference/cpp/_color_8hpp_source.html +216 -0
- data/reference/cpp/_directories_8hpp-source.html +5 -4
- data/reference/cpp/_directories_8hpp.html +11 -4
- data/reference/cpp/_directories_8hpp_source.html +89 -0
- data/reference/cpp/_font_8hpp-source.html +8 -7
- data/reference/cpp/_font_8hpp.html +11 -4
- data/reference/cpp/_font_8hpp_source.html +116 -0
- data/reference/cpp/_fwd_8hpp-source.html +1 -0
- data/reference/cpp/_fwd_8hpp.html +11 -4
- data/reference/cpp/_fwd_8hpp_source.html +99 -0
- data/reference/cpp/_gosu_8hpp-source.html +1 -0
- data/reference/cpp/_gosu_8hpp.html +5 -4
- data/reference/cpp/_gosu_8hpp_source.html +97 -0
- data/reference/cpp/_graphics_8hpp-source.html +7 -6
- data/reference/cpp/_graphics_8hpp.html +11 -4
- data/reference/cpp/_graphics_8hpp_source.html +138 -0
- data/reference/cpp/_graphics_base_8hpp-source.html +22 -21
- data/reference/cpp/_graphics_base_8hpp.html +15 -8
- data/reference/cpp/_graphics_base_8hpp_source.html +116 -0
- data/reference/cpp/_i_o_8hpp-source.html +16 -15
- data/reference/cpp/_i_o_8hpp.html +13 -6
- data/reference/cpp/_i_o_8hpp_source.html +302 -0
- data/reference/cpp/_image_8hpp-source.html +23 -22
- data/reference/cpp/_image_8hpp.html +11 -4
- data/reference/cpp/_image_8hpp_source.html +176 -0
- data/reference/cpp/_image_data_8hpp-source.html +2 -1
- data/reference/cpp/_image_data_8hpp.html +11 -4
- data/reference/cpp/_image_data_8hpp_source.html +109 -0
- data/reference/cpp/_input_8hpp-source.html +6 -5
- data/reference/cpp/_input_8hpp.html +11 -4
- data/reference/cpp/_input_8hpp_source.html +183 -0
- data/reference/cpp/_math_8hpp-source.html +26 -25
- data/reference/cpp/_math_8hpp.html +11 -4
- data/reference/cpp/_math_8hpp_source.html +157 -0
- data/reference/cpp/_platform_8hpp-source.html +5 -4
- data/reference/cpp/_platform_8hpp.html +14 -7
- data/reference/cpp/_platform_8hpp_source.html +134 -0
- data/reference/cpp/_rot_flip_8hpp-source.html +30 -29
- data/reference/cpp/_rot_flip_8hpp.html +12 -5
- data/reference/cpp/_rot_flip_8hpp_source.html +185 -0
- data/reference/cpp/_sockets_8hpp-source.html +25 -24
- data/reference/cpp/_sockets_8hpp.html +14 -7
- data/reference/cpp/_sockets_8hpp_source.html +175 -0
- data/reference/cpp/_text_8hpp-source.html +7 -6
- data/reference/cpp/_text_8hpp.html +11 -4
- data/reference/cpp/_text_8hpp_source.html +103 -0
- data/reference/cpp/_text_input_8hpp-source.html +1 -0
- data/reference/cpp/_text_input_8hpp.html +11 -4
- data/reference/cpp/_text_input_8hpp_source.html +111 -0
- data/reference/cpp/_timing_8hpp-source.html +3 -2
- data/reference/cpp/_timing_8hpp.html +11 -4
- data/reference/cpp/_timing_8hpp_source.html +83 -0
- data/reference/cpp/_utility_8hpp-source.html +5 -4
- data/reference/cpp/_utility_8hpp.html +11 -4
- data/reference/cpp/_utility_8hpp_source.html +90 -0
- data/reference/cpp/_version_8hpp-source.html +1 -0
- data/reference/cpp/_version_8hpp.html +7 -6
- data/reference/cpp/_version_8hpp_source.html +78 -0
- data/reference/cpp/_win_utility_8hpp-source.html +13 -12
- data/reference/cpp/_win_utility_8hpp.html +18 -6
- data/reference/cpp/_win_utility_8hpp_source.html +126 -0
- data/reference/cpp/_window_8hpp-source.html +6 -5
- data/reference/cpp/_window_8hpp.html +12 -5
- data/reference/cpp/_window_8hpp_source.html +158 -0
- data/reference/cpp/annotated.html +3 -2
- data/reference/cpp/class_gosu_1_1_audio-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_audio.html +5 -4
- data/reference/cpp/class_gosu_1_1_bitmap-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_bitmap.html +17 -12
- data/reference/cpp/class_gosu_1_1_buffer-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_buffer.html +12 -13
- data/reference/cpp/class_gosu_1_1_button-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_button.html +13 -10
- data/reference/cpp/class_gosu_1_1_color-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_color.html +29 -26
- data/reference/cpp/class_gosu_1_1_comm_socket-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_comm_socket.html +23 -22
- data/reference/cpp/class_gosu_1_1_file-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_file.html +7 -6
- data/reference/cpp/class_gosu_1_1_font-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_font.html +17 -16
- data/reference/cpp/class_gosu_1_1_graphics-members.html +4 -1
- data/reference/cpp/class_gosu_1_1_graphics.html +68 -19
- data/reference/cpp/class_gosu_1_1_image-members.html +3 -1
- data/reference/cpp/class_gosu_1_1_image.html +49 -23
- data/reference/cpp/class_gosu_1_1_image_data-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_image_data.html +9 -8
- data/reference/cpp/class_gosu_1_1_input-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_input.html +7 -6
- data/reference/cpp/class_gosu_1_1_listener_socket-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_listener_socket.html +12 -11
- data/reference/cpp/class_gosu_1_1_message_socket-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_message_socket.html +19 -18
- data/reference/cpp/class_gosu_1_1_reader-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_reader.html +18 -17
- data/reference/cpp/class_gosu_1_1_resource-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_resource.html +10 -9
- data/reference/cpp/class_gosu_1_1_rot_flip-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_rot_flip.html +24 -19
- data/reference/cpp/class_gosu_1_1_sample-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_sample.html +5 -4
- data/reference/cpp/class_gosu_1_1_sample_instance-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_sample_instance.html +5 -4
- data/reference/cpp/class_gosu_1_1_song-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_song.html +6 -5
- data/reference/cpp/class_gosu_1_1_text_input-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_text_input.html +6 -5
- data/reference/cpp/class_gosu_1_1_window-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_window.html +12 -11
- data/reference/cpp/class_gosu_1_1_writer-members.html +2 -1
- data/reference/cpp/class_gosu_1_1_writer.html +15 -14
- data/reference/cpp/classes.html +11 -10
- data/reference/cpp/files.html +28 -27
- data/reference/cpp/functions.html +2 -1
- data/reference/cpp/functions_0x62.html +5 -2
- data/reference/cpp/functions_0x63.html +2 -1
- data/reference/cpp/functions_0x64.html +2 -1
- data/reference/cpp/functions_0x65.html +4 -1
- data/reference/cpp/functions_0x66.html +2 -1
- data/reference/cpp/functions_0x67.html +5 -2
- data/reference/cpp/functions_0x68.html +2 -1
- data/reference/cpp/functions_0x69.html +2 -1
- data/reference/cpp/functions_0x6b.html +2 -1
- data/reference/cpp/functions_0x6c.html +2 -1
- data/reference/cpp/functions_0x6d.html +2 -1
- data/reference/cpp/functions_0x6e.html +2 -1
- data/reference/cpp/functions_0x6f.html +2 -1
- data/reference/cpp/functions_0x70.html +2 -1
- data/reference/cpp/functions_0x72.html +2 -1
- data/reference/cpp/functions_0x73.html +2 -1
- data/reference/cpp/functions_0x74.html +4 -3
- data/reference/cpp/functions_0x75.html +2 -1
- data/reference/cpp/functions_0x76.html +2 -1
- data/reference/cpp/functions_0x77.html +2 -1
- data/reference/cpp/functions_0x78.html +2 -1
- data/reference/cpp/functions_0x79.html +2 -1
- data/reference/cpp/functions_0x7e.html +2 -1
- data/reference/cpp/functions_enum.html +2 -1
- data/reference/cpp/functions_eval.html +2 -1
- data/reference/cpp/functions_func.html +2 -1
- data/reference/cpp/functions_func_0x62.html +5 -2
- data/reference/cpp/functions_func_0x63.html +2 -1
- data/reference/cpp/functions_func_0x64.html +2 -1
- data/reference/cpp/functions_func_0x65.html +4 -1
- data/reference/cpp/functions_func_0x66.html +2 -1
- data/reference/cpp/functions_func_0x67.html +5 -2
- data/reference/cpp/functions_func_0x68.html +2 -1
- data/reference/cpp/functions_func_0x69.html +2 -1
- data/reference/cpp/functions_func_0x6b.html +2 -1
- data/reference/cpp/functions_func_0x6c.html +2 -1
- data/reference/cpp/functions_func_0x6d.html +2 -1
- data/reference/cpp/functions_func_0x6e.html +2 -1
- data/reference/cpp/functions_func_0x6f.html +2 -1
- data/reference/cpp/functions_func_0x70.html +2 -1
- data/reference/cpp/functions_func_0x72.html +2 -1
- data/reference/cpp/functions_func_0x73.html +2 -1
- data/reference/cpp/functions_func_0x74.html +4 -3
- data/reference/cpp/functions_func_0x75.html +2 -1
- data/reference/cpp/functions_func_0x76.html +2 -1
- data/reference/cpp/functions_func_0x77.html +2 -1
- data/reference/cpp/functions_func_0x7e.html +2 -1
- data/reference/cpp/functions_type.html +2 -1
- data/reference/cpp/functions_vars.html +2 -1
- data/reference/cpp/globals.html +2 -1
- data/reference/cpp/globals_defs.html +2 -1
- data/reference/cpp/hierarchy.html +2 -1
- data/reference/cpp/index.html +3 -2
- data/reference/cpp/namespace_gosu.html +3314 -0
- data/reference/cpp/namespace_gosu_1_1_colors.html +274 -0
- data/reference/cpp/namespace_gosu_1_1_win.html +354 -0
- data/reference/cpp/namespacemembers.html +135 -0
- data/reference/cpp/namespacemembers_0x62.html +143 -0
- data/reference/cpp/namespacemembers_0x63.html +125 -0
- data/reference/cpp/namespacemembers_0x64.html +119 -0
- data/reference/cpp/namespacemembers_0x66.html +129 -0
- data/reference/cpp/namespacemembers_0x67.html +165 -0
- data/reference/cpp/namespacemembers_0x68.html +113 -0
- data/reference/cpp/namespacemembers_0x69.html +117 -0
- data/reference/cpp/namespacemembers_0x6b.html +289 -0
- data/reference/cpp/namespacemembers_0x6c.html +119 -0
- data/reference/cpp/namespacemembers_0x6d.html +131 -0
- data/reference/cpp/namespacemembers_0x6e.html +127 -0
- data/reference/cpp/namespacemembers_0x6f.html +121 -0
- data/reference/cpp/namespacemembers_0x70.html +115 -0
- data/reference/cpp/namespacemembers_0x71.html +113 -0
- data/reference/cpp/namespacemembers_0x72.html +165 -0
- data/reference/cpp/namespacemembers_0x73.html +135 -0
- data/reference/cpp/namespacemembers_0x74.html +129 -0
- data/reference/cpp/namespacemembers_0x75.html +117 -0
- data/reference/cpp/namespacemembers_0x77.html +117 -0
- data/reference/cpp/namespacemembers_0x79.html +113 -0
- data/reference/cpp/namespacemembers_0x7a.html +115 -0
- data/reference/cpp/namespacemembers_enum.html +103 -0
- data/reference/cpp/namespacemembers_eval.html +443 -0
- data/reference/cpp/namespacemembers_func.html +269 -0
- data/reference/cpp/namespacemembers_type.html +93 -0
- data/reference/cpp/namespacemembers_vars.html +115 -0
- data/reference/cpp/namespaces.html +76 -0
- data/reference/cpp/struct_gosu_1_1_g_l_tex_info-members.html +2 -1
- data/reference/cpp/struct_gosu_1_1_g_l_tex_info.html +10 -9
- data/reference/cpp/struct_gosu_1_1_touch-members.html +2 -1
- data/reference/cpp/struct_gosu_1_1_touch.html +8 -7
- data/reference/rdoc/classes/Gosu.html +16 -29
- data/reference/rdoc/classes/Gosu.src/M000003.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000004.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000005.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000006.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000007.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000008.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000009.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000010.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000011.html +0 -0
- data/reference/rdoc/classes/Gosu.src/M000012.html +0 -0
- data/reference/rdoc/classes/Gosu/Color.html +16 -17
- data/reference/rdoc/classes/Gosu/Color.src/M000016.html +0 -0
- data/reference/rdoc/classes/Gosu/Color.src/M000017.html +0 -0
- data/reference/rdoc/classes/Gosu/Color.src/M000018.html +0 -0
- data/reference/rdoc/classes/Gosu/Color.src/M000019.html +0 -0
- data/reference/rdoc/classes/Gosu/Font.html +16 -19
- data/reference/rdoc/classes/Gosu/Font.src/M000029.html +0 -0
- data/reference/rdoc/classes/Gosu/Font.src/M000030.html +0 -0
- data/reference/rdoc/classes/Gosu/Font.src/M000031.html +0 -0
- data/reference/rdoc/classes/Gosu/Font.src/M000032.html +0 -0
- data/reference/rdoc/classes/Gosu/Font.src/M000033.html +0 -0
- data/reference/rdoc/classes/Gosu/GLTexInfo.html +24 -16
- data/reference/rdoc/classes/Gosu/Image.html +16 -27
- data/reference/rdoc/classes/Gosu/Image.src/M000020.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000021.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000022.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000023.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000024.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000025.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000026.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000027.html +0 -0
- data/reference/rdoc/classes/Gosu/Image.src/M000028.html +0 -0
- data/reference/rdoc/classes/Gosu/Sample.html +16 -15
- data/reference/rdoc/classes/Gosu/Sample.src/M000013.html +0 -0
- data/reference/rdoc/classes/Gosu/Sample.src/M000014.html +0 -0
- data/reference/rdoc/classes/Gosu/Sample.src/M000015.html +0 -0
- data/reference/rdoc/classes/Gosu/SampleInstance.html +16 -19
- data/reference/rdoc/classes/Gosu/SampleInstance.src/M000051.html +0 -0
- data/reference/rdoc/classes/Gosu/SampleInstance.src/M000052.html +0 -0
- data/reference/rdoc/classes/Gosu/SampleInstance.src/M000053.html +0 -0
- data/reference/rdoc/classes/Gosu/SampleInstance.src/M000054.html +0 -0
- data/reference/rdoc/classes/Gosu/SampleInstance.src/M000055.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.html +16 -23
- data/reference/rdoc/classes/Gosu/Song.src/M000056.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.src/M000057.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.src/M000058.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.src/M000059.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.src/M000060.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.src/M000061.html +0 -0
- data/reference/rdoc/classes/Gosu/Song.src/M000062.html +0 -0
- data/reference/rdoc/classes/Gosu/TextInput.html +16 -9
- data/reference/rdoc/classes/Gosu/Window.html +16 -51
- data/reference/rdoc/classes/Gosu/Window.src/M000034.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000035.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000036.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000037.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000038.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000039.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000040.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000041.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000042.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000043.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000044.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000045.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000046.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000047.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000048.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000049.html +0 -0
- data/reference/rdoc/classes/Gosu/Window.src/M000050.html +0 -0
- data/reference/rdoc/classes/Numeric.html +16 -13
- data/reference/rdoc/classes/Numeric.src/M000001.html +0 -0
- data/reference/rdoc/classes/Numeric.src/M000002.html +0 -0
- data/reference/rdoc/created.rid +1 -1
- data/reference/rdoc/files/COPYING_txt.html +17 -12
- data/reference/rdoc/files/README_txt.html +16 -10
- data/reference/rdoc/files/reference/{DeploymentOnOSX_rdoc.html → Deployment on OS X_rdoc.html } +17 -11
- data/reference/rdoc/files/reference/{DeploymentOnWindows_rdoc.html → Deployment on Windows_rdoc.html } +17 -11
- data/reference/rdoc/files/reference/{DrawingWithColors_rdoc.html → Drawing with Colors_rdoc.html } +23 -17
- data/reference/rdoc/files/reference/{OrderOfCorners_rdoc.html → Order of Corners_rdoc.html } +18 -12
- data/reference/rdoc/files/reference/Tileability_rdoc.html +16 -10
- data/reference/rdoc/files/reference/{ZOrdering_rdoc.html → Z Ordering_rdoc.html } +18 -12
- data/reference/rdoc/files/reference/gosu_rb.html +16 -10
- data/reference/rdoc/fr_file_index.html +5 -5
- data/reference/rdoc/index.html +1 -1
- data/reference/rdoc/rdoc-style.css +4 -0
- metadata +129 -9
@@ -78,7 +78,7 @@ GLuint Gosu::Texture::texName() const
|
|
78
78
|
|
79
79
|
std::auto_ptr<Gosu::TexChunk>
|
80
80
|
Gosu::Texture::tryAlloc(Graphics& graphics,
|
81
|
-
|
81
|
+
DrawOpQueueStack& queues, boost::shared_ptr<Texture> ptr,
|
82
82
|
const Bitmap& bmp, unsigned srcX,
|
83
83
|
unsigned srcY, unsigned srcWidth,
|
84
84
|
unsigned srcHeight, unsigned padding)
|
@@ -89,7 +89,7 @@ std::auto_ptr<Gosu::TexChunk>
|
|
89
89
|
if (!block)
|
90
90
|
return result;
|
91
91
|
|
92
|
-
result.reset(new TexChunk(graphics,
|
92
|
+
result.reset(new TexChunk(graphics, queues, ptr, block->left + padding, block->top + padding,
|
93
93
|
block->width - 2 * padding, block->height - 2 * padding, padding));
|
94
94
|
|
95
95
|
#if defined(__BIG_ENDIAN__)
|
@@ -25,8 +25,9 @@ namespace Gosu
|
|
25
25
|
unsigned size() const;
|
26
26
|
GLuint texName() const;
|
27
27
|
std::auto_ptr<TexChunk>
|
28
|
-
tryAlloc(Graphics& graphics,
|
29
|
-
unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
28
|
+
tryAlloc(Graphics& graphics, DrawOpQueueStack& queues, boost::shared_ptr<Texture> ptr,
|
29
|
+
const Bitmap& bmp, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
30
|
+
unsigned padding);
|
30
31
|
void free(unsigned x, unsigned y);
|
31
32
|
};
|
32
33
|
}
|
data/GosuImpl/InputMac.mm
CHANGED
@@ -435,6 +435,7 @@ namespace {
|
|
435
435
|
|
436
436
|
idChars.assign(0);
|
437
437
|
|
438
|
+
#ifndef __LP64__
|
438
439
|
const void* KCHR = reinterpret_cast<const void*>(GetScriptManagerVariable(smKCHRCache));
|
439
440
|
if (!KCHR)
|
440
441
|
return;
|
@@ -467,6 +468,7 @@ namespace {
|
|
467
468
|
idChars[code] = ch;
|
468
469
|
charIds[ch] = code;
|
469
470
|
}
|
471
|
+
#endif
|
470
472
|
}
|
471
473
|
|
472
474
|
boost::array<bool, Gosu::numButtons> buttonStates;
|
data/GosuImpl/RubyGosu.swg
CHANGED
@@ -269,12 +269,16 @@ namespace Gosu
|
|
269
269
|
%include "std_string.i"
|
270
270
|
%include "../Gosu/Color.hpp"
|
271
271
|
%extend Gosu::Color {
|
272
|
+
Gosu::Color dup() const {
|
273
|
+
return *$self;
|
274
|
+
}
|
275
|
+
|
272
276
|
std::string toS() const {
|
273
277
|
std::ostringstream stream;
|
274
|
-
stream << "(" << static_cast<int>($self->alpha())
|
275
|
-
<< "
|
276
|
-
<< "
|
277
|
-
<< "
|
278
|
+
stream << "(ARGB: " << static_cast<int>($self->alpha())
|
279
|
+
<< "/" << static_cast<int>($self->red())
|
280
|
+
<< "/" << static_cast<int>($self->green())
|
281
|
+
<< "/" << static_cast<int>($self->blue()) << ")";
|
278
282
|
return stream.str();
|
279
283
|
}
|
280
284
|
}
|
@@ -327,6 +331,7 @@ namespace Gosu
|
|
327
331
|
%ignore Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool tileable = false);
|
328
332
|
%ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, bool tileable = false);
|
329
333
|
%ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool tileable = false);
|
334
|
+
%ignore Gosu::Image::Image(std::auto_ptr<ImageData> data);
|
330
335
|
%include "../Gosu/Image.hpp"
|
331
336
|
%extend Gosu::Image {
|
332
337
|
Image(Gosu::Window& window, VALUE source, bool tileable = false) {
|
@@ -546,4 +551,10 @@ namespace Gosu
|
|
546
551
|
rb_yield(Qnil);
|
547
552
|
$self->graphics().endClipping();
|
548
553
|
}
|
554
|
+
%newobject record;
|
555
|
+
Gosu::Image* record() {
|
556
|
+
$self->graphics().beginRecording();
|
557
|
+
rb_yield(Qnil);
|
558
|
+
return new Gosu::Image($self->graphics().endRecording());
|
559
|
+
}
|
549
560
|
};
|
data/GosuImpl/RubyGosu_wrap.cxx
CHANGED
@@ -2459,12 +2459,15 @@ SWIG_From_unsigned_SS_char (unsigned char value)
|
|
2459
2459
|
return SWIG_From_unsigned_SS_long (value);
|
2460
2460
|
}
|
2461
2461
|
|
2462
|
+
SWIGINTERN Gosu::Color Gosu_Color_dup(Gosu::Color const *self){
|
2463
|
+
return *self;
|
2464
|
+
}
|
2462
2465
|
SWIGINTERN std::string Gosu_Color_toS(Gosu::Color const *self){
|
2463
2466
|
std::ostringstream stream;
|
2464
|
-
stream << "(" << static_cast<int>(self->alpha())
|
2465
|
-
<< "
|
2466
|
-
<< "
|
2467
|
-
<< "
|
2467
|
+
stream << "(ARGB: " << static_cast<int>(self->alpha())
|
2468
|
+
<< "/" << static_cast<int>(self->red())
|
2469
|
+
<< "/" << static_cast<int>(self->green())
|
2470
|
+
<< "/" << static_cast<int>(self->blue()) << ")";
|
2468
2471
|
return stream.str();
|
2469
2472
|
}
|
2470
2473
|
|
@@ -2741,6 +2744,11 @@ SWIGINTERN void Gosu_Window_clipTo(Gosu::Window *self,int x,int y,unsigned int w
|
|
2741
2744
|
rb_yield(Qnil);
|
2742
2745
|
self->graphics().endClipping();
|
2743
2746
|
}
|
2747
|
+
SWIGINTERN Gosu::Image *Gosu_Window_record(Gosu::Window *self){
|
2748
|
+
self->graphics().beginRecording();
|
2749
|
+
rb_yield(Qnil);
|
2750
|
+
return new Gosu::Image(self->graphics().endRecording());
|
2751
|
+
}
|
2744
2752
|
|
2745
2753
|
static void markWindow(void* window) {
|
2746
2754
|
Gosu::TextInput* ti = static_cast<Gosu::Window*>(window)->input().textInput();
|
@@ -4179,6 +4187,45 @@ fail:
|
|
4179
4187
|
}
|
4180
4188
|
|
4181
4189
|
|
4190
|
+
|
4191
|
+
/*
|
4192
|
+
Document-method: Gosu::Color.dup
|
4193
|
+
|
4194
|
+
call-seq:
|
4195
|
+
dup -> Color
|
4196
|
+
|
4197
|
+
Create a duplicate of the class and unfreeze it if needed.
|
4198
|
+
*/
|
4199
|
+
SWIGINTERN VALUE
|
4200
|
+
_wrap_Color_dup(int argc, VALUE *argv, VALUE self) {
|
4201
|
+
Gosu::Color *arg1 = (Gosu::Color *) 0 ;
|
4202
|
+
void *argp1 = 0 ;
|
4203
|
+
int res1 = 0 ;
|
4204
|
+
Gosu::Color result;
|
4205
|
+
VALUE vresult = Qnil;
|
4206
|
+
|
4207
|
+
if ((argc < 0) || (argc > 0)) {
|
4208
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
4209
|
+
}
|
4210
|
+
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Gosu__Color, 0 | 0 );
|
4211
|
+
if (!SWIG_IsOK(res1)) {
|
4212
|
+
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Color const *","dup", 1, self ));
|
4213
|
+
}
|
4214
|
+
arg1 = reinterpret_cast< Gosu::Color * >(argp1);
|
4215
|
+
{
|
4216
|
+
try {
|
4217
|
+
result = Gosu_Color_dup((Gosu::Color const *)arg1);
|
4218
|
+
} catch(const std::runtime_error& e) {
|
4219
|
+
SWIG_exception(SWIG_RuntimeError, e.what());
|
4220
|
+
}
|
4221
|
+
}
|
4222
|
+
vresult = SWIG_NewPointerObj((new Gosu::Color(static_cast< const Gosu::Color& >(result))), SWIGTYPE_p_Gosu__Color, SWIG_POINTER_OWN | 0 );
|
4223
|
+
return vresult;
|
4224
|
+
fail:
|
4225
|
+
return Qnil;
|
4226
|
+
}
|
4227
|
+
|
4228
|
+
|
4182
4229
|
SWIGINTERN VALUE
|
4183
4230
|
_wrap_Color_to_s(int argc, VALUE *argv, VALUE self) {
|
4184
4231
|
Gosu::Color *arg1 = (Gosu::Color *) 0 ;
|
@@ -8643,6 +8690,36 @@ fail:
|
|
8643
8690
|
}
|
8644
8691
|
|
8645
8692
|
|
8693
|
+
SWIGINTERN VALUE
|
8694
|
+
_wrap_Window_record(int argc, VALUE *argv, VALUE self) {
|
8695
|
+
Gosu::Window *arg1 = (Gosu::Window *) 0 ;
|
8696
|
+
void *argp1 = 0 ;
|
8697
|
+
int res1 = 0 ;
|
8698
|
+
Gosu::Image *result = 0 ;
|
8699
|
+
VALUE vresult = Qnil;
|
8700
|
+
|
8701
|
+
if ((argc < 0) || (argc > 0)) {
|
8702
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
8703
|
+
}
|
8704
|
+
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Gosu__Window, 0 | 0 );
|
8705
|
+
if (!SWIG_IsOK(res1)) {
|
8706
|
+
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "Gosu::Window *","record", 1, self ));
|
8707
|
+
}
|
8708
|
+
arg1 = reinterpret_cast< Gosu::Window * >(argp1);
|
8709
|
+
{
|
8710
|
+
try {
|
8711
|
+
result = (Gosu::Image *)Gosu_Window_record(arg1);
|
8712
|
+
} catch(const std::runtime_error& e) {
|
8713
|
+
SWIG_exception(SWIG_RuntimeError, e.what());
|
8714
|
+
}
|
8715
|
+
}
|
8716
|
+
vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Gosu__Image, SWIG_POINTER_OWN | 0 );
|
8717
|
+
return vresult;
|
8718
|
+
fail:
|
8719
|
+
return Qnil;
|
8720
|
+
}
|
8721
|
+
|
8722
|
+
|
8646
8723
|
SWIGINTERN VALUE
|
8647
8724
|
_wrap_disown_Window(int argc, VALUE *argv, VALUE self) {
|
8648
8725
|
Gosu::Window *arg1 = (Gosu::Window *) 0 ;
|
@@ -8995,8 +9072,8 @@ SWIGEXPORT void Init_gosu(void) {
|
|
8995
9072
|
SWIG_RubyInitializeTrackings();
|
8996
9073
|
rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
|
8997
9074
|
rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(7)));
|
8998
|
-
rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(
|
8999
|
-
rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.
|
9075
|
+
rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(15)));
|
9076
|
+
rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.15"));
|
9000
9077
|
rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
|
9001
9078
|
rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
|
9002
9079
|
rb_define_module_function(mGosu, "gosu_to_radian_scale", VALUEFUNC(_wrap_gosu_to_radian_scale), -1);
|
@@ -9034,6 +9111,7 @@ SWIGEXPORT void Init_gosu(void) {
|
|
9034
9111
|
rb_define_method(SwigClassColor.klass, "argb", VALUEFUNC(_wrap_Color_argb), -1);
|
9035
9112
|
rb_define_method(SwigClassColor.klass, "bgr", VALUEFUNC(_wrap_Color_bgr), -1);
|
9036
9113
|
rb_define_method(SwigClassColor.klass, "abgr", VALUEFUNC(_wrap_Color_abgr), -1);
|
9114
|
+
rb_define_method(SwigClassColor.klass, "dup", VALUEFUNC(_wrap_Color_dup), -1);
|
9037
9115
|
rb_define_method(SwigClassColor.klass, "to_s", VALUEFUNC(_wrap_Color_to_s), -1);
|
9038
9116
|
SwigClassColor.mark = 0;
|
9039
9117
|
SwigClassColor.destroy = (void (*)(void *)) free_Gosu_Color;
|
@@ -9332,6 +9410,7 @@ SWIGEXPORT void Init_gosu(void) {
|
|
9332
9410
|
rb_define_method(SwigClassWindow.klass, "height", VALUEFUNC(_wrap_Window_height), -1);
|
9333
9411
|
rb_define_method(SwigClassWindow.klass, "gl", VALUEFUNC(_wrap_Window_gl), -1);
|
9334
9412
|
rb_define_method(SwigClassWindow.klass, "clip_to", VALUEFUNC(_wrap_Window_clip_to), -1);
|
9413
|
+
rb_define_method(SwigClassWindow.klass, "record", VALUEFUNC(_wrap_Window_record), -1);
|
9335
9414
|
SwigClassWindow.mark = (void (*)(void *)) markWindow;
|
9336
9415
|
SwigClassWindow.destroy = (void (*)(void *)) free_Gosu_Window;
|
9337
9416
|
SwigClassWindow.trackObjects = 1;
|
@@ -1,304 +1,304 @@
|
|
1
|
-
#include <Gosu/Sockets.hpp>
|
2
|
-
#include <GosuImpl/Sockets/Sockets.hpp>
|
3
|
-
#include <cassert>
|
4
|
-
#include <cstring>
|
5
|
-
#include <stdexcept>
|
6
|
-
#include <vector>
|
7
|
-
|
8
|
-
struct Gosu::CommSocket::Impl
|
9
|
-
{
|
10
|
-
Socket socket;
|
11
|
-
CommMode mode;
|
12
|
-
|
13
|
-
typedef std::vector<char> Buffer;
|
14
|
-
Buffer inbox, outbox;
|
15
|
-
|
16
|
-
void appendBuffer(const char* buffer, std::size_t size,
|
17
|
-
boost::function<void (const void*, std::size_t)>& event)
|
18
|
-
{
|
19
|
-
switch (mode)
|
20
|
-
{
|
21
|
-
case cmRaw:
|
22
|
-
{
|
23
|
-
// Raw = simple! Yay.
|
24
|
-
if (event)
|
25
|
-
event(buffer, size);
|
26
|
-
|
27
|
-
break;
|
28
|
-
}
|
29
|
-
|
30
|
-
case cmManaged:
|
31
|
-
{
|
32
|
-
// Append new data to inbox.
|
33
|
-
inbox.insert(inbox.end(), buffer, buffer + size);
|
34
|
-
|
35
|
-
for (;;) // IMPR.
|
36
|
-
{
|
37
|
-
const size_t sizeSize = sizeof(
|
38
|
-
|
39
|
-
// Not even enough bytes there to determine the size of the
|
40
|
-
// incoming message.
|
41
|
-
if (inbox.size() < sizeSize)
|
42
|
-
break;
|
43
|
-
|
44
|
-
// Message size is already here, convert it.
|
45
|
-
|
46
|
-
msgSize = ntohl(msgSize);
|
47
|
-
|
48
|
-
// Can't really handle zero-size messages. IMPR?!
|
49
|
-
if (msgSize == 0)
|
50
|
-
throw std::logic_error("Cannot handle empty messages");
|
51
|
-
|
52
|
-
// Has the current message arrived completely?
|
53
|
-
if (inbox.size() < sizeSize + msgSize)
|
54
|
-
break;
|
55
|
-
|
56
|
-
// Current message is here: Call event...
|
57
|
-
if (event)
|
58
|
-
event(&inbox[sizeSize], msgSize);
|
59
|
-
|
60
|
-
// ...and delete it from the inbox.
|
61
|
-
inbox.erase(inbox.begin(),
|
62
|
-
inbox.begin() + sizeSize + msgSize);
|
63
|
-
}
|
64
|
-
|
65
|
-
break;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
}
|
69
|
-
};
|
70
|
-
|
71
|
-
Gosu::CommSocket::CommSocket(CommMode mode, SocketAddress targetAddress,
|
72
|
-
SocketPort targetPort)
|
73
|
-
: pimpl(new Impl)
|
74
|
-
{
|
75
|
-
pimpl->mode = mode;
|
76
|
-
|
77
|
-
sockaddr_in addr;
|
78
|
-
std::memset(&addr, 0, sizeof addr);
|
79
|
-
addr.sin_family = AF_INET;
|
80
|
-
addr.sin_addr.s_addr = htonl(targetAddress);
|
81
|
-
addr.sin_port = htons(targetPort);
|
82
|
-
|
83
|
-
pimpl->socket.setHandle(socketCheck(::socket(AF_INET, SOCK_STREAM, 0)));
|
84
|
-
pimpl->socket.setBlocking(true);
|
85
|
-
socketCheck(::connect(pimpl->socket.handle(), reinterpret_cast<sockaddr*>(&addr),
|
86
|
-
sizeof addr));
|
87
|
-
pimpl->socket.setBlocking(false);
|
88
|
-
}
|
89
|
-
|
90
|
-
Gosu::CommSocket::CommSocket(CommMode mode, Socket& socket)
|
91
|
-
: pimpl(new Impl)
|
92
|
-
{
|
93
|
-
pimpl->mode = mode;
|
94
|
-
|
95
|
-
pimpl->socket.swap(socket);
|
96
|
-
pimpl->socket.setBlocking(false);
|
97
|
-
}
|
98
|
-
|
99
|
-
Gosu::CommSocket::~CommSocket()
|
100
|
-
{
|
101
|
-
}
|
102
|
-
|
103
|
-
Gosu::SocketAddress Gosu::CommSocket::address() const
|
104
|
-
{
|
105
|
-
return pimpl->socket.address();
|
106
|
-
}
|
107
|
-
|
108
|
-
Gosu::SocketPort Gosu::CommSocket::port() const
|
109
|
-
{
|
110
|
-
return pimpl->socket.port();
|
111
|
-
}
|
112
|
-
|
113
|
-
Gosu::SocketAddress Gosu::CommSocket::remoteAddress() const
|
114
|
-
{
|
115
|
-
assert(connected());
|
116
|
-
|
117
|
-
sockaddr_in addr;
|
118
|
-
int size = sizeof addr;
|
119
|
-
socketCheck(::getpeername(pimpl->socket.handle(),
|
120
|
-
reinterpret_cast<sockaddr*>(&addr),
|
121
|
-
reinterpret_cast<socklen_t*>(&size)));
|
122
|
-
|
123
|
-
return ntohl(addr.sin_addr.s_addr);
|
124
|
-
}
|
125
|
-
|
126
|
-
Gosu::SocketPort Gosu::CommSocket::remotePort() const
|
127
|
-
{
|
128
|
-
assert(connected());
|
129
|
-
|
130
|
-
sockaddr_in addr;
|
131
|
-
int size = sizeof addr;
|
132
|
-
socketCheck(::getpeername(pimpl->socket.handle(),
|
133
|
-
reinterpret_cast<sockaddr*>(&addr),
|
134
|
-
reinterpret_cast<socklen_t*>(&size)));
|
135
|
-
return ntohs(addr.sin_port);
|
136
|
-
}
|
137
|
-
|
138
|
-
Gosu::CommMode Gosu::CommSocket::mode() const
|
139
|
-
{
|
140
|
-
return pimpl->mode;
|
141
|
-
}
|
142
|
-
|
143
|
-
bool Gosu::CommSocket::connected() const
|
144
|
-
{
|
145
|
-
return pimpl->socket.handle() != INVALID_SOCKET;
|
146
|
-
}
|
147
|
-
|
148
|
-
void Gosu::CommSocket::disconnect()
|
149
|
-
{
|
150
|
-
pimpl->socket.setHandle(INVALID_SOCKET);
|
151
|
-
// IMPR: Mmmmh. A full-blown sockets library should probably try to send
|
152
|
-
// the remaining contents of the outbox. This is annoying to implement,
|
153
|
-
// though...
|
154
|
-
pimpl->outbox.clear();
|
155
|
-
if (onDisconnection)
|
156
|
-
onDisconnection();
|
157
|
-
}
|
158
|
-
|
159
|
-
bool Gosu::CommSocket::keepAlive() const
|
160
|
-
{
|
161
|
-
int buf;
|
162
|
-
int size = sizeof buf;
|
163
|
-
socketCheck(::getsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_KEEPALIVE,
|
164
|
-
reinterpret_cast<char*>(&buf),
|
165
|
-
reinterpret_cast<socklen_t*>(&size)));
|
166
|
-
return buf != 0;
|
167
|
-
}
|
168
|
-
|
169
|
-
void Gosu::CommSocket::setKeepAlive(bool value)
|
170
|
-
{
|
171
|
-
int buf = value;
|
172
|
-
socketCheck(::setsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_KEEPALIVE,
|
173
|
-
reinterpret_cast<char*>(&buf), sizeof buf));
|
174
|
-
}
|
175
|
-
|
176
|
-
void Gosu::CommSocket::update()
|
177
|
-
{
|
178
|
-
sendPendingData();
|
179
|
-
|
180
|
-
if (!connected())
|
181
|
-
return;
|
182
|
-
|
183
|
-
for (;;)
|
184
|
-
{
|
185
|
-
char buffer[1024];
|
186
|
-
int received = ::recv(pimpl->socket.handle(), buffer, sizeof buffer, 0);
|
187
|
-
|
188
|
-
if (received > 0 && received <= static_cast<int>(sizeof buffer))
|
189
|
-
{
|
190
|
-
// Data arrived and fit into the buffer.
|
191
|
-
pimpl->appendBuffer(buffer, received, onReceive);
|
192
|
-
}
|
193
|
-
else if (received == 0)
|
194
|
-
{
|
195
|
-
// The other side has gracefully closed the connection.
|
196
|
-
disconnect();
|
197
|
-
return;
|
198
|
-
}
|
199
|
-
else if (received == SOCKET_ERROR)
|
200
|
-
{
|
201
|
-
switch (lastSocketError())
|
202
|
-
{
|
203
|
-
// Arriving data didn't fit into the buffer.
|
204
|
-
case GOSU_SOCK_ERR(EMSGSIZE):
|
205
|
-
pimpl->appendBuffer(buffer, sizeof buffer, onReceive);
|
206
|
-
break;
|
207
|
-
|
208
|
-
// There simply was no data.
|
209
|
-
case GOSU_SOCK_ERR(EWOULDBLOCK):
|
210
|
-
return;
|
211
|
-
|
212
|
-
// Connection was reset or is invalid.
|
213
|
-
case GOSU_SOCK_ERR(ENETDOWN):
|
214
|
-
case GOSU_SOCK_ERR(ENOTCONN):
|
215
|
-
case GOSU_SOCK_ERR(ENETRESET):
|
216
|
-
case GOSU_SOCK_ERR(ECONNABORTED):
|
217
|
-
case GOSU_SOCK_ERR(ETIMEDOUT):
|
218
|
-
case GOSU_SOCK_ERR(ECONNRESET):
|
219
|
-
#ifndef GOSU_IS_WIN
|
220
|
-
// UNIX specific, rare error
|
221
|
-
case GOSU_SOCK_ERR(EPIPE):
|
222
|
-
#endif
|
223
|
-
disconnect();
|
224
|
-
return;
|
225
|
-
|
226
|
-
// Everything else is unexpected.
|
227
|
-
default:
|
228
|
-
throwLastSocketError();
|
229
|
-
}
|
230
|
-
}
|
231
|
-
else assert(false);
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
|
-
void Gosu::CommSocket::send(const void* buffer, std::size_t size)
|
236
|
-
{
|
237
|
-
if (!connected())
|
238
|
-
return;
|
239
|
-
|
240
|
-
// In managed mode, also send the length of the buffer.
|
241
|
-
if (mode() == cmManaged)
|
242
|
-
{
|
243
|
-
|
244
|
-
const char* charBuf = reinterpret_cast<const char*>(&netSize);
|
245
|
-
pimpl->outbox.insert(pimpl->outbox.end(), charBuf,
|
246
|
-
charBuf + sizeof netSize);
|
247
|
-
}
|
248
|
-
|
249
|
-
const char* charBuf = reinterpret_cast<const char*>(buffer);
|
250
|
-
pimpl->outbox.insert(pimpl->outbox.end(), charBuf, charBuf + size);
|
251
|
-
}
|
252
|
-
|
253
|
-
void Gosu::CommSocket::sendPendingData()
|
254
|
-
{
|
255
|
-
if (pendingBytes() == 0 || !connected())
|
256
|
-
return;
|
257
|
-
|
258
|
-
int sent = ::send(pimpl->socket.handle(), &pimpl->outbox.front(),
|
259
|
-
pendingBytes(), 0);
|
260
|
-
|
261
|
-
if (sent >= 0)
|
262
|
-
{
|
263
|
-
// Remove sent data from the outbox.
|
264
|
-
if (sent >= static_cast<int>(pendingBytes()))
|
265
|
-
pimpl->outbox.clear();
|
266
|
-
else
|
267
|
-
pimpl->outbox.erase(pimpl->outbox.begin(),
|
268
|
-
pimpl->outbox.begin() + sent);
|
269
|
-
}
|
270
|
-
else
|
271
|
-
{
|
272
|
-
switch (lastSocketError())
|
273
|
-
{
|
274
|
-
// These error codes basically mean "try again later".
|
275
|
-
case GOSU_SOCK_ERR(ENOBUFS):
|
276
|
-
case GOSU_SOCK_ERR(EWOULDBLOCK):
|
277
|
-
case GOSU_SOCK_ERR(EHOSTUNREACH):
|
278
|
-
break;
|
279
|
-
|
280
|
-
// And these tell us we're disconnected.
|
281
|
-
case GOSU_SOCK_ERR(ENETDOWN):
|
282
|
-
case GOSU_SOCK_ERR(ENETRESET):
|
283
|
-
case GOSU_SOCK_ERR(ENOTCONN):
|
284
|
-
case GOSU_SOCK_ERR(ECONNABORTED):
|
285
|
-
case GOSU_SOCK_ERR(ECONNRESET):
|
286
|
-
case GOSU_SOCK_ERR(ETIMEDOUT):
|
287
|
-
#ifndef GOSU_IS_WIN
|
288
|
-
// UNIX-specific, rare error
|
289
|
-
case GOSU_SOCK_ERR(EPIPE):
|
290
|
-
#endif
|
291
|
-
disconnect();
|
292
|
-
break;
|
293
|
-
|
294
|
-
// Everything else is unexpected.
|
295
|
-
default:
|
296
|
-
throwLastSocketError();
|
297
|
-
}
|
298
|
-
}
|
299
|
-
}
|
300
|
-
|
301
|
-
std::size_t Gosu::CommSocket::pendingBytes() const
|
302
|
-
{
|
303
|
-
return pimpl->outbox.size();
|
304
|
-
}
|
1
|
+
#include <Gosu/Sockets.hpp>
|
2
|
+
#include <GosuImpl/Sockets/Sockets.hpp>
|
3
|
+
#include <cassert>
|
4
|
+
#include <cstring>
|
5
|
+
#include <stdexcept>
|
6
|
+
#include <vector>
|
7
|
+
|
8
|
+
struct Gosu::CommSocket::Impl
|
9
|
+
{
|
10
|
+
Socket socket;
|
11
|
+
CommMode mode;
|
12
|
+
|
13
|
+
typedef std::vector<char> Buffer;
|
14
|
+
Buffer inbox, outbox;
|
15
|
+
|
16
|
+
void appendBuffer(const char* buffer, std::size_t size,
|
17
|
+
boost::function<void (const void*, std::size_t)>& event)
|
18
|
+
{
|
19
|
+
switch (mode)
|
20
|
+
{
|
21
|
+
case cmRaw:
|
22
|
+
{
|
23
|
+
// Raw = simple! Yay.
|
24
|
+
if (event)
|
25
|
+
event(buffer, size);
|
26
|
+
|
27
|
+
break;
|
28
|
+
}
|
29
|
+
|
30
|
+
case cmManaged:
|
31
|
+
{
|
32
|
+
// Append new data to inbox.
|
33
|
+
inbox.insert(inbox.end(), buffer, buffer + size);
|
34
|
+
|
35
|
+
for (;;) // IMPR.
|
36
|
+
{
|
37
|
+
const size_t sizeSize = sizeof(unsigned long);
|
38
|
+
|
39
|
+
// Not even enough bytes there to determine the size of the
|
40
|
+
// incoming message.
|
41
|
+
if (inbox.size() < sizeSize)
|
42
|
+
break;
|
43
|
+
|
44
|
+
// Message size is already here, convert it.
|
45
|
+
unsigned long msgSize = *reinterpret_cast<unsigned long*>(&inbox[0]);
|
46
|
+
msgSize = ntohl(msgSize);
|
47
|
+
|
48
|
+
// Can't really handle zero-size messages. IMPR?!
|
49
|
+
if (msgSize == 0)
|
50
|
+
throw std::logic_error("Cannot handle empty messages");
|
51
|
+
|
52
|
+
// Has the current message arrived completely?
|
53
|
+
if (inbox.size() < sizeSize + msgSize)
|
54
|
+
break;
|
55
|
+
|
56
|
+
// Current message is here: Call event...
|
57
|
+
if (event)
|
58
|
+
event(&inbox[sizeSize], msgSize);
|
59
|
+
|
60
|
+
// ...and delete it from the inbox.
|
61
|
+
inbox.erase(inbox.begin(),
|
62
|
+
inbox.begin() + sizeSize + msgSize);
|
63
|
+
}
|
64
|
+
|
65
|
+
break;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
Gosu::CommSocket::CommSocket(CommMode mode, SocketAddress targetAddress,
|
72
|
+
SocketPort targetPort)
|
73
|
+
: pimpl(new Impl)
|
74
|
+
{
|
75
|
+
pimpl->mode = mode;
|
76
|
+
|
77
|
+
sockaddr_in addr;
|
78
|
+
std::memset(&addr, 0, sizeof addr);
|
79
|
+
addr.sin_family = AF_INET;
|
80
|
+
addr.sin_addr.s_addr = htonl(targetAddress);
|
81
|
+
addr.sin_port = htons(targetPort);
|
82
|
+
|
83
|
+
pimpl->socket.setHandle(socketCheck(::socket(AF_INET, SOCK_STREAM, 0)));
|
84
|
+
pimpl->socket.setBlocking(true);
|
85
|
+
socketCheck(::connect(pimpl->socket.handle(), reinterpret_cast<sockaddr*>(&addr),
|
86
|
+
sizeof addr));
|
87
|
+
pimpl->socket.setBlocking(false);
|
88
|
+
}
|
89
|
+
|
90
|
+
Gosu::CommSocket::CommSocket(CommMode mode, Socket& socket)
|
91
|
+
: pimpl(new Impl)
|
92
|
+
{
|
93
|
+
pimpl->mode = mode;
|
94
|
+
|
95
|
+
pimpl->socket.swap(socket);
|
96
|
+
pimpl->socket.setBlocking(false);
|
97
|
+
}
|
98
|
+
|
99
|
+
Gosu::CommSocket::~CommSocket()
|
100
|
+
{
|
101
|
+
}
|
102
|
+
|
103
|
+
Gosu::SocketAddress Gosu::CommSocket::address() const
|
104
|
+
{
|
105
|
+
return pimpl->socket.address();
|
106
|
+
}
|
107
|
+
|
108
|
+
Gosu::SocketPort Gosu::CommSocket::port() const
|
109
|
+
{
|
110
|
+
return pimpl->socket.port();
|
111
|
+
}
|
112
|
+
|
113
|
+
Gosu::SocketAddress Gosu::CommSocket::remoteAddress() const
|
114
|
+
{
|
115
|
+
assert(connected());
|
116
|
+
|
117
|
+
sockaddr_in addr;
|
118
|
+
int size = sizeof addr;
|
119
|
+
socketCheck(::getpeername(pimpl->socket.handle(),
|
120
|
+
reinterpret_cast<sockaddr*>(&addr),
|
121
|
+
reinterpret_cast<socklen_t*>(&size)));
|
122
|
+
|
123
|
+
return ntohl(addr.sin_addr.s_addr);
|
124
|
+
}
|
125
|
+
|
126
|
+
Gosu::SocketPort Gosu::CommSocket::remotePort() const
|
127
|
+
{
|
128
|
+
assert(connected());
|
129
|
+
|
130
|
+
sockaddr_in addr;
|
131
|
+
int size = sizeof addr;
|
132
|
+
socketCheck(::getpeername(pimpl->socket.handle(),
|
133
|
+
reinterpret_cast<sockaddr*>(&addr),
|
134
|
+
reinterpret_cast<socklen_t*>(&size)));
|
135
|
+
return ntohs(addr.sin_port);
|
136
|
+
}
|
137
|
+
|
138
|
+
Gosu::CommMode Gosu::CommSocket::mode() const
|
139
|
+
{
|
140
|
+
return pimpl->mode;
|
141
|
+
}
|
142
|
+
|
143
|
+
bool Gosu::CommSocket::connected() const
|
144
|
+
{
|
145
|
+
return pimpl->socket.handle() != INVALID_SOCKET;
|
146
|
+
}
|
147
|
+
|
148
|
+
void Gosu::CommSocket::disconnect()
|
149
|
+
{
|
150
|
+
pimpl->socket.setHandle(INVALID_SOCKET);
|
151
|
+
// IMPR: Mmmmh. A full-blown sockets library should probably try to send
|
152
|
+
// the remaining contents of the outbox. This is annoying to implement,
|
153
|
+
// though...
|
154
|
+
pimpl->outbox.clear();
|
155
|
+
if (onDisconnection)
|
156
|
+
onDisconnection();
|
157
|
+
}
|
158
|
+
|
159
|
+
bool Gosu::CommSocket::keepAlive() const
|
160
|
+
{
|
161
|
+
int buf;
|
162
|
+
int size = sizeof buf;
|
163
|
+
socketCheck(::getsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_KEEPALIVE,
|
164
|
+
reinterpret_cast<char*>(&buf),
|
165
|
+
reinterpret_cast<socklen_t*>(&size)));
|
166
|
+
return buf != 0;
|
167
|
+
}
|
168
|
+
|
169
|
+
void Gosu::CommSocket::setKeepAlive(bool value)
|
170
|
+
{
|
171
|
+
int buf = value;
|
172
|
+
socketCheck(::setsockopt(pimpl->socket.handle(), SOL_SOCKET, SO_KEEPALIVE,
|
173
|
+
reinterpret_cast<char*>(&buf), sizeof buf));
|
174
|
+
}
|
175
|
+
|
176
|
+
void Gosu::CommSocket::update()
|
177
|
+
{
|
178
|
+
sendPendingData();
|
179
|
+
|
180
|
+
if (!connected())
|
181
|
+
return;
|
182
|
+
|
183
|
+
for (;;)
|
184
|
+
{
|
185
|
+
char buffer[1024];
|
186
|
+
int received = ::recv(pimpl->socket.handle(), buffer, sizeof buffer, 0);
|
187
|
+
|
188
|
+
if (received > 0 && received <= static_cast<int>(sizeof buffer))
|
189
|
+
{
|
190
|
+
// Data arrived and fit into the buffer.
|
191
|
+
pimpl->appendBuffer(buffer, received, onReceive);
|
192
|
+
}
|
193
|
+
else if (received == 0)
|
194
|
+
{
|
195
|
+
// The other side has gracefully closed the connection.
|
196
|
+
disconnect();
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
else if (received == SOCKET_ERROR)
|
200
|
+
{
|
201
|
+
switch (lastSocketError())
|
202
|
+
{
|
203
|
+
// Arriving data didn't fit into the buffer.
|
204
|
+
case GOSU_SOCK_ERR(EMSGSIZE):
|
205
|
+
pimpl->appendBuffer(buffer, sizeof buffer, onReceive);
|
206
|
+
break;
|
207
|
+
|
208
|
+
// There simply was no data.
|
209
|
+
case GOSU_SOCK_ERR(EWOULDBLOCK):
|
210
|
+
return;
|
211
|
+
|
212
|
+
// Connection was reset or is invalid.
|
213
|
+
case GOSU_SOCK_ERR(ENETDOWN):
|
214
|
+
case GOSU_SOCK_ERR(ENOTCONN):
|
215
|
+
case GOSU_SOCK_ERR(ENETRESET):
|
216
|
+
case GOSU_SOCK_ERR(ECONNABORTED):
|
217
|
+
case GOSU_SOCK_ERR(ETIMEDOUT):
|
218
|
+
case GOSU_SOCK_ERR(ECONNRESET):
|
219
|
+
#ifndef GOSU_IS_WIN
|
220
|
+
// UNIX specific, rare error
|
221
|
+
case GOSU_SOCK_ERR(EPIPE):
|
222
|
+
#endif
|
223
|
+
disconnect();
|
224
|
+
return;
|
225
|
+
|
226
|
+
// Everything else is unexpected.
|
227
|
+
default:
|
228
|
+
throwLastSocketError();
|
229
|
+
}
|
230
|
+
}
|
231
|
+
else assert(false);
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
void Gosu::CommSocket::send(const void* buffer, std::size_t size)
|
236
|
+
{
|
237
|
+
if (!connected())
|
238
|
+
return;
|
239
|
+
|
240
|
+
// In managed mode, also send the length of the buffer.
|
241
|
+
if (mode() == cmManaged)
|
242
|
+
{
|
243
|
+
unsigned long netSize = htonl(size);
|
244
|
+
const char* charBuf = reinterpret_cast<const char*>(&netSize);
|
245
|
+
pimpl->outbox.insert(pimpl->outbox.end(), charBuf,
|
246
|
+
charBuf + sizeof netSize);
|
247
|
+
}
|
248
|
+
|
249
|
+
const char* charBuf = reinterpret_cast<const char*>(buffer);
|
250
|
+
pimpl->outbox.insert(pimpl->outbox.end(), charBuf, charBuf + size);
|
251
|
+
}
|
252
|
+
|
253
|
+
void Gosu::CommSocket::sendPendingData()
|
254
|
+
{
|
255
|
+
if (pendingBytes() == 0 || !connected())
|
256
|
+
return;
|
257
|
+
|
258
|
+
int sent = ::send(pimpl->socket.handle(), &pimpl->outbox.front(),
|
259
|
+
pendingBytes(), 0);
|
260
|
+
|
261
|
+
if (sent >= 0)
|
262
|
+
{
|
263
|
+
// Remove sent data from the outbox.
|
264
|
+
if (sent >= static_cast<int>(pendingBytes()))
|
265
|
+
pimpl->outbox.clear();
|
266
|
+
else
|
267
|
+
pimpl->outbox.erase(pimpl->outbox.begin(),
|
268
|
+
pimpl->outbox.begin() + sent);
|
269
|
+
}
|
270
|
+
else
|
271
|
+
{
|
272
|
+
switch (lastSocketError())
|
273
|
+
{
|
274
|
+
// These error codes basically mean "try again later".
|
275
|
+
case GOSU_SOCK_ERR(ENOBUFS):
|
276
|
+
case GOSU_SOCK_ERR(EWOULDBLOCK):
|
277
|
+
case GOSU_SOCK_ERR(EHOSTUNREACH):
|
278
|
+
break;
|
279
|
+
|
280
|
+
// And these tell us we're disconnected.
|
281
|
+
case GOSU_SOCK_ERR(ENETDOWN):
|
282
|
+
case GOSU_SOCK_ERR(ENETRESET):
|
283
|
+
case GOSU_SOCK_ERR(ENOTCONN):
|
284
|
+
case GOSU_SOCK_ERR(ECONNABORTED):
|
285
|
+
case GOSU_SOCK_ERR(ECONNRESET):
|
286
|
+
case GOSU_SOCK_ERR(ETIMEDOUT):
|
287
|
+
#ifndef GOSU_IS_WIN
|
288
|
+
// UNIX-specific, rare error
|
289
|
+
case GOSU_SOCK_ERR(EPIPE):
|
290
|
+
#endif
|
291
|
+
disconnect();
|
292
|
+
break;
|
293
|
+
|
294
|
+
// Everything else is unexpected.
|
295
|
+
default:
|
296
|
+
throwLastSocketError();
|
297
|
+
}
|
298
|
+
}
|
299
|
+
}
|
300
|
+
|
301
|
+
std::size_t Gosu::CommSocket::pendingBytes() const
|
302
|
+
{
|
303
|
+
return pimpl->outbox.size();
|
304
|
+
}
|