gosu 0.7.10.1
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.
- data/COPYING.txt +29 -0
- data/Gosu/Async.hpp +48 -0
- data/Gosu/Audio.hpp +145 -0
- data/Gosu/AutoLink.hpp +16 -0
- data/Gosu/Bitmap.hpp +85 -0
- data/Gosu/ButtonsMac.hpp +114 -0
- data/Gosu/ButtonsWin.hpp +111 -0
- data/Gosu/ButtonsX.hpp +115 -0
- data/Gosu/Color.hpp +172 -0
- data/Gosu/Directories.hpp +36 -0
- data/Gosu/Font.hpp +59 -0
- data/Gosu/Fwd.hpp +31 -0
- data/Gosu/Gosu.hpp +26 -0
- data/Gosu/Graphics.hpp +86 -0
- data/Gosu/GraphicsBase.hpp +45 -0
- data/Gosu/IO.hpp +255 -0
- data/Gosu/Image.hpp +148 -0
- data/Gosu/ImageData.hpp +45 -0
- data/Gosu/Input.hpp +116 -0
- data/Gosu/Math.hpp +95 -0
- data/Gosu/Platform.hpp +61 -0
- data/Gosu/RotFlip.hpp +116 -0
- data/Gosu/Sockets.hpp +129 -0
- data/Gosu/Text.hpp +47 -0
- data/Gosu/TextInput.hpp +57 -0
- data/Gosu/Timing.hpp +16 -0
- data/Gosu/Utility.hpp +24 -0
- data/Gosu/WinUtility.hpp +76 -0
- data/Gosu/Window.hpp +84 -0
- data/GosuImpl/Async.cpp +37 -0
- data/GosuImpl/AudioFmod.cpp +417 -0
- data/GosuImpl/AudioSDL.cpp +255 -0
- data/GosuImpl/DirectoriesMac.mm +38 -0
- data/GosuImpl/DirectoriesUnix.cpp +48 -0
- data/GosuImpl/DirectoriesWin.cpp +42 -0
- data/GosuImpl/FileUnix.cpp +100 -0
- data/GosuImpl/FileWin.cpp +83 -0
- data/GosuImpl/Graphics/Bitmap.cpp +116 -0
- data/GosuImpl/Graphics/BitmapBMP.cpp +232 -0
- data/GosuImpl/Graphics/BitmapColorKey.cpp +39 -0
- data/GosuImpl/Graphics/BitmapPNG.cpp +276 -0
- data/GosuImpl/Graphics/BitmapUtils.cpp +67 -0
- data/GosuImpl/Graphics/BlockAllocator.cpp +127 -0
- data/GosuImpl/Graphics/BlockAllocator.hpp +34 -0
- data/GosuImpl/Graphics/Color.cpp +126 -0
- data/GosuImpl/Graphics/Common.hpp +21 -0
- data/GosuImpl/Graphics/DrawOp.hpp +154 -0
- data/GosuImpl/Graphics/Font.cpp +110 -0
- data/GosuImpl/Graphics/Graphics.cpp +295 -0
- data/GosuImpl/Graphics/Image.cpp +159 -0
- data/GosuImpl/Graphics/LargeImageData.cpp +115 -0
- data/GosuImpl/Graphics/LargeImageData.hpp +37 -0
- data/GosuImpl/Graphics/RotFlip.cpp +184 -0
- data/GosuImpl/Graphics/TexChunk.cpp +77 -0
- data/GosuImpl/Graphics/TexChunk.hpp +40 -0
- data/GosuImpl/Graphics/Text.cpp +223 -0
- data/GosuImpl/Graphics/TextMac.cpp +242 -0
- data/GosuImpl/Graphics/TextPangoFT.cpp +186 -0
- data/GosuImpl/Graphics/TextWin.cpp +172 -0
- data/GosuImpl/Graphics/Texture.cpp +104 -0
- data/GosuImpl/Graphics/Texture.hpp +34 -0
- data/GosuImpl/IO.cpp +48 -0
- data/GosuImpl/InputMac.mm +677 -0
- data/GosuImpl/InputWin.cpp +444 -0
- data/GosuImpl/InputX.cpp +158 -0
- data/GosuImpl/MacUtility.hpp +48 -0
- data/GosuImpl/Math.cpp +49 -0
- data/GosuImpl/RubyGosu.swg +474 -0
- data/GosuImpl/RubyGosuStub.mm +17 -0
- data/GosuImpl/RubyGosu_DllMain.cxx +30 -0
- data/GosuImpl/RubyGosu_wrap.cxx +8521 -0
- data/GosuImpl/RubyGosu_wrap.h +31 -0
- data/GosuImpl/Sockets/CommSocket.cpp +304 -0
- data/GosuImpl/Sockets/ListenerSocket.cpp +60 -0
- data/GosuImpl/Sockets/MessageSocket.cpp +136 -0
- data/GosuImpl/Sockets/Socket.cpp +145 -0
- data/GosuImpl/Sockets/Sockets.hpp +66 -0
- data/GosuImpl/TextInputMac.mm +207 -0
- data/GosuImpl/TextInputWin.cpp +197 -0
- data/GosuImpl/TextInputX.cpp +201 -0
- data/GosuImpl/TextTTFWin.cpp +247 -0
- data/GosuImpl/TimingUnix.cpp +17 -0
- data/GosuImpl/TimingWin.cpp +28 -0
- data/GosuImpl/Utility.cpp +140 -0
- data/GosuImpl/WinMain.cpp +69 -0
- data/GosuImpl/WinUtility.cpp +137 -0
- data/GosuImpl/WindowMac.mm +466 -0
- data/GosuImpl/WindowWin.cpp +447 -0
- data/GosuImpl/WindowX.cpp +392 -0
- data/GosuImpl/X11vroot.h +118 -0
- data/README.txt +13 -0
- data/Rakefile +178 -0
- data/examples/ChipmunkIntegration.rb +275 -0
- data/examples/CptnRuby.rb +231 -0
- data/examples/MoreChipmunkAndRMagick.rb +155 -0
- data/examples/OpenGLIntegration.rb +232 -0
- data/examples/RMagickIntegration.rb +449 -0
- data/examples/TextInput.cpp +170 -0
- data/examples/TextInput.rb +139 -0
- data/examples/Tutorial.cpp +215 -0
- data/examples/Tutorial.rb +137 -0
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +25 -0
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/CptnRuby.png +0 -0
- data/examples/media/Cursor.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Sky.jpg +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/linux/Makefile.in +98 -0
- data/linux/configure +5658 -0
- data/linux/configure.ac +126 -0
- data/linux/extconf.rb +11 -0
- data/mac/English.lproj/InfoPlist.strings +0 -0
- data/mac/Gosu-Info.plist +26 -0
- data/mac/Gosu.xcodeproj/project.pbxproj +1194 -0
- data/mac/RubyGosu Template-Info.plist +26 -0
- data/mac/libboost_thread_1_34_1_universal.a +0 -0
- data/mac/libboost_thread_d_1_34_1_universal.a +0 -0
- data/mac/libfmod_universal.a +0 -0
- data/mac/libpng_universal.a +0 -0
- data/mac/libz_universal.a +0 -0
- data/reference/Async_8hpp-source.html +70 -0
- data/reference/Audio_8hpp-source.html +114 -0
- data/reference/Audio_8hpp.html +50 -0
- data/reference/AutoLink_8hpp-source.html +38 -0
- data/reference/AutoLink_8hpp.html +34 -0
- data/reference/Bitmap_8hpp-source.html +85 -0
- data/reference/Bitmap_8hpp.html +58 -0
- data/reference/ButtonsMac_8hpp-source.html +133 -0
- data/reference/ButtonsWin_8hpp-source.html +133 -0
- data/reference/ButtonsX_8hpp-source.html +134 -0
- data/reference/Color_8hpp-source.html +169 -0
- data/reference/Color_8hpp.html +85 -0
- data/reference/Directories_8hpp-source.html +42 -0
- data/reference/Directories_8hpp.html +46 -0
- data/reference/Font_8hpp-source.html +65 -0
- data/reference/Font_8hpp.html +41 -0
- data/reference/Fwd_8hpp-source.html +52 -0
- data/reference/Fwd_8hpp.html +37 -0
- data/reference/Gosu_8hpp-source.html +48 -0
- data/reference/Gosu_8hpp.html +34 -0
- data/reference/GraphicsBase_8hpp-source.html +57 -0
- data/reference/GraphicsBase_8hpp.html +56 -0
- data/reference/Graphics_8hpp-source.html +96 -0
- data/reference/Graphics_8hpp.html +53 -0
- data/reference/IO_8hpp-source.html +255 -0
- data/reference/IO_8hpp.html +74 -0
- data/reference/ImageData_8hpp-source.html +62 -0
- data/reference/ImageData_8hpp.html +43 -0
- data/reference/Image_8hpp-source.html +126 -0
- data/reference/Image_8hpp.html +48 -0
- data/reference/Input_8hpp-source.html +118 -0
- data/reference/Input_8hpp.html +50 -0
- data/reference/Math_8hpp-source.html +92 -0
- data/reference/Math_8hpp.html +74 -0
- data/reference/Platform_8hpp-source.html +83 -0
- data/reference/Platform_8hpp.html +73 -0
- data/reference/RotFlip_8hpp-source.html +138 -0
- data/reference/RotFlip_8hpp.html +77 -0
- data/reference/Sockets_8hpp-source.html +130 -0
- data/reference/Sockets_8hpp.html +66 -0
- data/reference/TextInput_8hpp-source.html +64 -0
- data/reference/TextInput_8hpp.html +41 -0
- data/reference/Text_8hpp-source.html +51 -0
- data/reference/Text_8hpp.html +46 -0
- data/reference/Timing_8hpp-source.html +36 -0
- data/reference/Timing_8hpp.html +42 -0
- data/reference/Utility_8hpp-source.html +44 -0
- data/reference/Utility_8hpp.html +48 -0
- data/reference/WinUtility_8hpp-source.html +79 -0
- data/reference/WinUtility_8hpp.html +64 -0
- data/reference/Window_8hpp-source.html +91 -0
- data/reference/Window_8hpp.html +41 -0
- data/reference/annotated.html +51 -0
- data/reference/classGosu_1_1Audio-members.html +34 -0
- data/reference/classGosu_1_1Audio.html +46 -0
- data/reference/classGosu_1_1Bitmap-members.html +44 -0
- data/reference/classGosu_1_1Bitmap.html +263 -0
- data/reference/classGosu_1_1Buffer-members.html +44 -0
- data/reference/classGosu_1_1Buffer.html +78 -0
- data/reference/classGosu_1_1Buffer.png +0 -0
- data/reference/classGosu_1_1Button-members.html +36 -0
- data/reference/classGosu_1_1Button.html +143 -0
- data/reference/classGosu_1_1Color-members.html +56 -0
- data/reference/classGosu_1_1Color.html +387 -0
- data/reference/classGosu_1_1File-members.html +41 -0
- data/reference/classGosu_1_1File.html +69 -0
- data/reference/classGosu_1_1File.png +0 -0
- data/reference/classGosu_1_1Font-members.html +39 -0
- data/reference/classGosu_1_1Font.html +309 -0
- data/reference/classGosu_1_1Graphics-members.html +50 -0
- data/reference/classGosu_1_1Graphics.html +234 -0
- data/reference/classGosu_1_1Image-members.html +45 -0
- data/reference/classGosu_1_1Image.html +518 -0
- data/reference/classGosu_1_1ImageData-members.html +37 -0
- data/reference/classGosu_1_1ImageData.html +60 -0
- data/reference/classGosu_1_1Input-members.html +44 -0
- data/reference/classGosu_1_1Input.html +223 -0
- data/reference/classGosu_1_1MessageSocket-members.html +40 -0
- data/reference/classGosu_1_1MessageSocket.html +233 -0
- data/reference/classGosu_1_1Resource-members.html +39 -0
- data/reference/classGosu_1_1Resource.html +116 -0
- data/reference/classGosu_1_1Resource.png +0 -0
- data/reference/classGosu_1_1Sample-members.html +37 -0
- data/reference/classGosu_1_1Sample.html +200 -0
- data/reference/classGosu_1_1SampleInstance-members.html +38 -0
- data/reference/classGosu_1_1SampleInstance.html +169 -0
- data/reference/classGosu_1_1Song-members.html +43 -0
- data/reference/classGosu_1_1Song.html +260 -0
- data/reference/classGosu_1_1TextInput-members.html +38 -0
- data/reference/classGosu_1_1TextInput.html +121 -0
- data/reference/classGosu_1_1Window-members.html +50 -0
- data/reference/classGosu_1_1Window.html +271 -0
- data/reference/doxyfile +233 -0
- data/reference/doxygen.css +433 -0
- data/reference/doxygen.png +0 -0
- data/reference/files.html +54 -0
- data/reference/functions.html +236 -0
- data/reference/functions_enum.html +45 -0
- data/reference/functions_func.html +227 -0
- data/reference/functions_vars.html +47 -0
- data/reference/hierarchy.html +53 -0
- data/reference/index.html +26 -0
- data/reference/namespaceGosu.html +2890 -0
- data/reference/namespaceGosu_1_1Colors.html +70 -0
- data/reference/namespaceGosu_1_1Win.html +275 -0
- data/reference/namespacemembers.html +216 -0
- data/reference/namespacemembers_enum.html +52 -0
- data/reference/namespacemembers_eval.html +54 -0
- data/reference/namespacemembers_func.html +185 -0
- data/reference/namespacemembers_type.html +46 -0
- data/reference/namespacemembers_vars.html +46 -0
- data/reference/namespaces.html +35 -0
- data/reference/tab_b.gif +0 -0
- data/reference/tab_l.gif +0 -0
- data/reference/tab_r.gif +0 -0
- data/reference/tabs.css +102 -0
- data/windows/Gosu.sln +29 -0
- data/windows/Gosu.vcproj +553 -0
- data/windows/RubyGosu.vcproj +138 -0
- metadata +305 -0
data/Gosu/Input.hpp
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
//! \file Input.hpp
|
2
|
+
//! Interface of the Input class.
|
3
|
+
|
4
|
+
#ifndef GOSU_INPUT_HPP
|
5
|
+
#define GOSU_INPUT_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Platform.hpp>
|
9
|
+
|
10
|
+
#ifdef GOSU_IS_WIN
|
11
|
+
#include <Gosu/ButtonsWin.hpp>
|
12
|
+
#include <windows.h>
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#ifdef GOSU_IS_MAC
|
16
|
+
#include <Gosu/ButtonsMac.hpp>
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#ifdef GOSU_IS_X
|
20
|
+
#include <X11/Xlib.h>
|
21
|
+
#include <X11/Xutil.h>
|
22
|
+
#include <X11/keysym.h>
|
23
|
+
#include <Gosu/ButtonsX.hpp>
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#include <Gosu/Platform.hpp>
|
27
|
+
#include <Gosu/Fwd.hpp>
|
28
|
+
#include <boost/function.hpp>
|
29
|
+
#include <boost/scoped_ptr.hpp>
|
30
|
+
|
31
|
+
namespace Gosu
|
32
|
+
{
|
33
|
+
//! Very lightweight class that identifies a button (keyboard, mouse or other device).
|
34
|
+
class Button
|
35
|
+
{
|
36
|
+
unsigned id;
|
37
|
+
|
38
|
+
public:
|
39
|
+
//! For internal use.
|
40
|
+
explicit Button(unsigned id) : id(id) {}
|
41
|
+
//! For internal use.
|
42
|
+
unsigned getId() const { return id; }
|
43
|
+
|
44
|
+
//! Default constructor; == noButton.
|
45
|
+
Button() : id(noButton) {}
|
46
|
+
|
47
|
+
//! Conversion from ButtonName constants.
|
48
|
+
Button(ButtonName name) : id(name) {}
|
49
|
+
};
|
50
|
+
|
51
|
+
//! Tests whether two Buttons identify the same physical button.
|
52
|
+
inline bool operator==(Button lhs, Button rhs)
|
53
|
+
{
|
54
|
+
return lhs.getId() == rhs.getId();
|
55
|
+
}
|
56
|
+
inline bool operator!=(Button lhs, Button rhs)
|
57
|
+
{
|
58
|
+
return !(lhs == rhs);
|
59
|
+
}
|
60
|
+
|
61
|
+
//! Manages initialization and shutdown of the input system; only one Input
|
62
|
+
//! instance can live per application. (Should this limitation ever get into
|
63
|
+
//! anyone's way, I will happily remove it; until then, I practice YAGNI.)
|
64
|
+
class Input
|
65
|
+
{
|
66
|
+
struct Impl;
|
67
|
+
boost::scoped_ptr<Impl> pimpl;
|
68
|
+
|
69
|
+
public:
|
70
|
+
#ifdef GOSU_IS_WIN
|
71
|
+
Input(HWND window);
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#ifdef GOSU_IS_MAC
|
75
|
+
Input(void* nswindow);
|
76
|
+
bool feedNSEvent(void* event);
|
77
|
+
#endif
|
78
|
+
|
79
|
+
#ifdef GOSU_IS_X
|
80
|
+
Input(::Display* dpy);
|
81
|
+
bool feedXEvent(::XEvent& event, Window* window);
|
82
|
+
#endif
|
83
|
+
|
84
|
+
~Input();
|
85
|
+
|
86
|
+
//! Returns the character a button usually produces, or 0.
|
87
|
+
static wchar_t idToChar(Button btn);
|
88
|
+
//! Returns the button that has to be pressed to produce the
|
89
|
+
//! given character, or noButton.
|
90
|
+
static Button charToId(wchar_t ch);
|
91
|
+
|
92
|
+
//! Returns true if a button is currently pressed.
|
93
|
+
bool down(Button btn) const;
|
94
|
+
|
95
|
+
//! Returns the horizontal position of the mouse relative to the top
|
96
|
+
//! left corner of the window given to Input's constructor.
|
97
|
+
double mouseX() const;
|
98
|
+
//! See mouseX.
|
99
|
+
double mouseY() const;
|
100
|
+
// Undocumented for the moment.
|
101
|
+
void setMouseFactors(double factorX, double factorY);
|
102
|
+
|
103
|
+
//! Collects new information about which buttons are pressed, where the
|
104
|
+
//! mouse is and calls onButtonUp/onButtonDown, if assigned.
|
105
|
+
void update();
|
106
|
+
|
107
|
+
//! Assignable events that are called by update. You can bind these to your own functions.
|
108
|
+
//! If you use the Window class, it will assign forward these to its own methods.
|
109
|
+
boost::function<void (Button)> onButtonDown, onButtonUp;
|
110
|
+
|
111
|
+
TextInput* textInput() const;
|
112
|
+
void setTextInput(TextInput* input);
|
113
|
+
};
|
114
|
+
}
|
115
|
+
|
116
|
+
#endif
|
data/Gosu/Math.hpp
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
//! \file Math.hpp
|
2
|
+
//! Contains simple math functionality.
|
3
|
+
|
4
|
+
#ifndef GOSU_MATH_HPP
|
5
|
+
#define GOSU_MATH_HPP
|
6
|
+
|
7
|
+
namespace Gosu
|
8
|
+
{
|
9
|
+
//! Pi.
|
10
|
+
const double pi = 3.1415926536;
|
11
|
+
|
12
|
+
//! Truncates the fractional part of a real value. Equivalent to
|
13
|
+
//! static_cast<long>.
|
14
|
+
inline long trunc(double value)
|
15
|
+
{
|
16
|
+
return static_cast<long>(value);
|
17
|
+
}
|
18
|
+
|
19
|
+
//! Rounds a real value towards the next integer.
|
20
|
+
inline long round(double value)
|
21
|
+
{
|
22
|
+
if (value >= 0)
|
23
|
+
return static_cast<long>(value + 0.5);
|
24
|
+
else
|
25
|
+
return static_cast<long>(value - 0.5);
|
26
|
+
}
|
27
|
+
|
28
|
+
//! Returns a real value between min and max. Uses std::rand (so you have
|
29
|
+
//! to call std::srand before using it).
|
30
|
+
double random(double min, double max);
|
31
|
+
|
32
|
+
//! Returns the horizontal distance between the origin and the point to
|
33
|
+
//! which you would get if you moved radius pixels in the direction
|
34
|
+
//! specified by angle.
|
35
|
+
//! \param angle Angle in degrees where 0.0 means upwards.
|
36
|
+
double offsetX(double angle, double radius);
|
37
|
+
//! Returns the vertical distance between the origin and the point to
|
38
|
+
//! which you would get if you moved radius pixels in the direction
|
39
|
+
//! specified by angle.
|
40
|
+
//! \param angle Angle in degrees where 0.0 means upwards.
|
41
|
+
double offsetY(double angle, double radius);
|
42
|
+
//! Returns the angle between two points in degrees, where 0.0 means
|
43
|
+
//! upwards. Returns def if both points are equal.
|
44
|
+
double angle(double fromX, double fromY, double toX, double toY,
|
45
|
+
double def = 0);
|
46
|
+
//! Returns the smallest positive angle between two angles.
|
47
|
+
double angleDiff(double angle1, double angle2);
|
48
|
+
//! Normalizes an angle to fit into the range [0; 360[.
|
49
|
+
double normalizeAngle(double angle);
|
50
|
+
|
51
|
+
//! Returns value * value.
|
52
|
+
template<typename T>
|
53
|
+
T square(T value)
|
54
|
+
{
|
55
|
+
return value * value;
|
56
|
+
}
|
57
|
+
|
58
|
+
//! Returns min if value is smaller than min, max if value is larger than
|
59
|
+
//! max and value otherwise.
|
60
|
+
template<typename T>
|
61
|
+
T clamp(T value, T min, T max)
|
62
|
+
{
|
63
|
+
if (value < min)
|
64
|
+
return min;
|
65
|
+
if (value > max)
|
66
|
+
return max;
|
67
|
+
return value;
|
68
|
+
}
|
69
|
+
|
70
|
+
// Backward compatibility with 0.7.x
|
71
|
+
template<typename T>
|
72
|
+
T boundBy(T value, T min, T max)
|
73
|
+
{
|
74
|
+
return clamp(value, min, max);
|
75
|
+
}
|
76
|
+
|
77
|
+
//! Returns the square of the distance between two points.
|
78
|
+
inline double distanceSqr(double x1, double y1, double x2, double y2)
|
79
|
+
{
|
80
|
+
return square(x1 - x2) + square(y1 - y2);
|
81
|
+
}
|
82
|
+
|
83
|
+
//! Returns the distance between two points.
|
84
|
+
double distance(double x1, double y1, double x2, double y2);
|
85
|
+
|
86
|
+
//! Interpolates a value between a and b, weight being the bias towards the second value.
|
87
|
+
//! Examples: interpolate(0, 10, 0.5) == 5, interpolate(-10, 10, 0.25) == 5, interpolate(0, 10, -0.5) == -5.
|
88
|
+
template<typename T>
|
89
|
+
T interpolate(T a, T b, double weight = 0.5)
|
90
|
+
{
|
91
|
+
return a * (1.0 - weight) + b * weight;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
#endif
|
data/Gosu/Platform.hpp
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
//! \file Platform.hpp
|
2
|
+
//! Macros and utility functions to facilitate programming on all of Gosu's supported platforms.
|
3
|
+
|
4
|
+
#ifndef GOSU_PLATFORM_HPP
|
5
|
+
#define GOSU_PLATFORM_HPP
|
6
|
+
|
7
|
+
#ifdef __BIG_ENDIAN__
|
8
|
+
#define IDENTITY_FUN bigToNative
|
9
|
+
#define IDENTITY_FUN2 nativeToBig
|
10
|
+
#define CONV_FUN littleToNative
|
11
|
+
#define CONV_FUN2 nativeToLittle
|
12
|
+
#else
|
13
|
+
#define IDENTITY_FUN littleToNative
|
14
|
+
#define IDENTITY_FUN2 nativeToLittle
|
15
|
+
#define CONV_FUN bigToNative
|
16
|
+
#define CONV_FUN2 nativeToBig
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#include <algorithm>
|
20
|
+
|
21
|
+
namespace Gosu
|
22
|
+
{
|
23
|
+
template<typename T> T IDENTITY_FUN(T t) { return t; }
|
24
|
+
template<typename T> T IDENTITY_FUN2(T t) { return t; }
|
25
|
+
|
26
|
+
template<typename T>
|
27
|
+
T CONV_FUN(T t)
|
28
|
+
{
|
29
|
+
char* begin = reinterpret_cast<char*>(&t);
|
30
|
+
std::reverse(begin, begin + sizeof t);
|
31
|
+
return t;
|
32
|
+
}
|
33
|
+
|
34
|
+
template<typename T> T CONV_FUN2(T t) { return CONV_FUN(t); }
|
35
|
+
}
|
36
|
+
|
37
|
+
#undef IDENTITY_FUN
|
38
|
+
#undef IDENTITY_FUN2
|
39
|
+
#undef CONV_FUN
|
40
|
+
#undef CONV_FUN2
|
41
|
+
|
42
|
+
#ifdef _MSC_VER
|
43
|
+
#define GOSU_NORETURN __declspec(noreturn)
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#ifdef __GNUC__
|
47
|
+
#define GOSU_NORETURN __attribute__ ((noreturn))
|
48
|
+
#endif
|
49
|
+
|
50
|
+
#ifdef WIN32
|
51
|
+
# define GOSU_IS_WIN
|
52
|
+
#else
|
53
|
+
# define GOSU_IS_UNIX
|
54
|
+
# if defined(__linux) || defined(__FreeBSD__)
|
55
|
+
# define GOSU_IS_X
|
56
|
+
# else
|
57
|
+
# define GOSU_IS_MAC
|
58
|
+
# endif
|
59
|
+
#endif
|
60
|
+
|
61
|
+
#endif
|
data/Gosu/RotFlip.hpp
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
//! \file RotFlip.hpp
|
2
|
+
//! Interface of the undocumented RotFlip class.
|
3
|
+
|
4
|
+
#ifndef GOSU_ROTFLIP_HPP
|
5
|
+
#define GOSU_ROTFLIP_HPP
|
6
|
+
|
7
|
+
namespace Gosu
|
8
|
+
{
|
9
|
+
enum RotFlipName
|
10
|
+
{
|
11
|
+
rfDefault,
|
12
|
+
rfRotate90,
|
13
|
+
rfRotate180,
|
14
|
+
rfRotate270,
|
15
|
+
|
16
|
+
rfFlipX,
|
17
|
+
rfRotate90FlipX,
|
18
|
+
rfRotate180FlipX,
|
19
|
+
rfRotate270FlipX,
|
20
|
+
|
21
|
+
rfFlipY = rfRotate180FlipX,
|
22
|
+
rfRotate90FlipY = rfRotate270FlipX,
|
23
|
+
rfRotate180FlipY = rfFlipX,
|
24
|
+
rfRotate270FlipY = rfRotate90FlipX,
|
25
|
+
|
26
|
+
rfFlipXRotate90 = rfRotate270FlipX,
|
27
|
+
rfFlipXRotate180 = rfRotate180FlipX,
|
28
|
+
rfFlipXRotate270 = rfRotate90FlipX,
|
29
|
+
|
30
|
+
rfFlipYRotate90 = rfRotate90FlipX,
|
31
|
+
rfFlipYRotate180 = rfFlipX,
|
32
|
+
rfFlipYRotate270 = rfRotate270FlipX
|
33
|
+
};
|
34
|
+
|
35
|
+
class RotFlip
|
36
|
+
{
|
37
|
+
RotFlipName name_;
|
38
|
+
|
39
|
+
typedef RotFlipName TransTable[8];
|
40
|
+
static const TransTable flipXTable, flipYTable, rotate90Table,
|
41
|
+
rotate180Table, rotate270Table;
|
42
|
+
|
43
|
+
typedef unsigned CornerTable[8][4];
|
44
|
+
static const CornerTable mapCornerTable, realCornerTable;
|
45
|
+
|
46
|
+
public:
|
47
|
+
RotFlip(RotFlipName name = rfDefault)
|
48
|
+
: name_(name)
|
49
|
+
{
|
50
|
+
}
|
51
|
+
|
52
|
+
RotFlipName name() const
|
53
|
+
{
|
54
|
+
return name_;
|
55
|
+
}
|
56
|
+
|
57
|
+
void flipX()
|
58
|
+
{
|
59
|
+
name_ = flipXTable[name_];
|
60
|
+
}
|
61
|
+
|
62
|
+
void flipY()
|
63
|
+
{
|
64
|
+
name_ = flipYTable[name_];
|
65
|
+
}
|
66
|
+
|
67
|
+
void rotate90()
|
68
|
+
{
|
69
|
+
name_ = rotate90Table[name_];
|
70
|
+
}
|
71
|
+
|
72
|
+
void rotate180()
|
73
|
+
{
|
74
|
+
name_ = rotate180Table[name_];
|
75
|
+
}
|
76
|
+
|
77
|
+
void rotate270()
|
78
|
+
{
|
79
|
+
name_ = rotate270Table[name_];
|
80
|
+
}
|
81
|
+
|
82
|
+
bool flipped() const
|
83
|
+
{
|
84
|
+
return name_ >= rfFlipX;
|
85
|
+
}
|
86
|
+
|
87
|
+
bool rotated() const
|
88
|
+
{
|
89
|
+
return name_ % 2 == 1;
|
90
|
+
}
|
91
|
+
|
92
|
+
unsigned mapCorner(unsigned n) const
|
93
|
+
{
|
94
|
+
return mapCornerTable[name_][n];
|
95
|
+
}
|
96
|
+
|
97
|
+
unsigned realCorner(unsigned n) const
|
98
|
+
{
|
99
|
+
return realCornerTable[name_][n];
|
100
|
+
}
|
101
|
+
};
|
102
|
+
|
103
|
+
inline bool operator==(RotFlip a, RotFlip b)
|
104
|
+
{
|
105
|
+
return a.name() == b.name();
|
106
|
+
}
|
107
|
+
|
108
|
+
inline bool operator!=(RotFlip a, RotFlip b)
|
109
|
+
{
|
110
|
+
return a.name() != b.name();
|
111
|
+
}
|
112
|
+
|
113
|
+
void applyToPoint(RotFlip rotFlip, int& x, int& y, int max);
|
114
|
+
}
|
115
|
+
|
116
|
+
#endif
|
data/Gosu/Sockets.hpp
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
//! \file Sockets.hpp
|
2
|
+
//! Interface of the three socket classes, MessageSocket, CommSocket and ListenerSocket.
|
3
|
+
|
4
|
+
#ifndef GOSU_SOCKETS_HPP
|
5
|
+
#define GOSU_SOCKETS_HPP
|
6
|
+
|
7
|
+
#include <boost/cstdint.hpp>
|
8
|
+
#include <boost/function.hpp>
|
9
|
+
#include <boost/scoped_ptr.hpp>
|
10
|
+
#include <cstddef>
|
11
|
+
#include <string>
|
12
|
+
|
13
|
+
namespace Gosu
|
14
|
+
{
|
15
|
+
// Both addresses and ports are returned from and given to Gosu
|
16
|
+
// functions in host byte order.
|
17
|
+
typedef boost::uint32_t SocketAddress;
|
18
|
+
typedef boost::uint16_t SocketPort;
|
19
|
+
const SocketPort anyPort = 0;
|
20
|
+
|
21
|
+
//! Tries to convert a dotted IP4 string into an address suitable for
|
22
|
+
//! socket functions. If the string supplied is not such a string, it
|
23
|
+
//! tries to look up the host via DNS. If both methods fail, zero is
|
24
|
+
//! returned.
|
25
|
+
SocketAddress stringToAddress(const std::string& s);
|
26
|
+
//! Converts an address into a dotted IP4 string.
|
27
|
+
std::string addressToString(SocketAddress address);
|
28
|
+
|
29
|
+
//! Wraps an UDP socket. Message sockets can send data to and receive
|
30
|
+
//! data from arbitrary addresses. Also, message sockets send messages
|
31
|
+
//! (packets) which are limited in size and can arrive in any order, or
|
32
|
+
//! not at all.
|
33
|
+
class MessageSocket
|
34
|
+
{
|
35
|
+
struct Impl;
|
36
|
+
boost::scoped_ptr<Impl> pimpl;
|
37
|
+
|
38
|
+
public:
|
39
|
+
//! Opens a message socket for listening at the specified port.
|
40
|
+
//! Gosu::anyPort may be passed to have the message socket use
|
41
|
+
//! a random free port.
|
42
|
+
explicit MessageSocket(SocketPort port);
|
43
|
+
~MessageSocket();
|
44
|
+
|
45
|
+
//! Returns the local address of the socket.
|
46
|
+
SocketAddress address() const;
|
47
|
+
//! Returns the local port of the socket.
|
48
|
+
SocketPort port() const;
|
49
|
+
//! Returns the maximum size, in bytes, of a packet that can be sent
|
50
|
+
//! from this socket.
|
51
|
+
std::size_t maxMessageSize() const;
|
52
|
+
|
53
|
+
//! Collects all the packets that were sent to this socket and
|
54
|
+
//! calls onReceive for each of them.
|
55
|
+
void update();
|
56
|
+
|
57
|
+
//! Sends something to the given port of the computer identified
|
58
|
+
//! by the address.
|
59
|
+
void send(SocketAddress address, SocketPort port,
|
60
|
+
const void* buffer, std::size_t size);
|
61
|
+
/*void broadcast(SocketPort port, const void* buffer,
|
62
|
+
std::size_t size);*/
|
63
|
+
|
64
|
+
//! If assigned, will be called by update for every packet received.
|
65
|
+
boost::function<void (SocketAddress, SocketPort, const void*,
|
66
|
+
std::size_t)> onReceive;
|
67
|
+
};
|
68
|
+
|
69
|
+
enum CommMode
|
70
|
+
{
|
71
|
+
cmRaw,
|
72
|
+
//cmLines,
|
73
|
+
cmManaged
|
74
|
+
};
|
75
|
+
|
76
|
+
class Socket;
|
77
|
+
|
78
|
+
class CommSocket
|
79
|
+
{
|
80
|
+
struct Impl;
|
81
|
+
boost::scoped_ptr<Impl> pimpl;
|
82
|
+
|
83
|
+
public:
|
84
|
+
CommSocket(CommMode mode, SocketAddress targetAddress,
|
85
|
+
SocketPort targetPort);
|
86
|
+
CommSocket(CommMode mode, Socket& socket);
|
87
|
+
~CommSocket();
|
88
|
+
|
89
|
+
SocketAddress address() const;
|
90
|
+
SocketPort port() const;
|
91
|
+
SocketAddress remoteAddress() const;
|
92
|
+
SocketPort remotePort() const;
|
93
|
+
CommMode mode() const;
|
94
|
+
|
95
|
+
bool connected() const;
|
96
|
+
void disconnect();
|
97
|
+
bool keepAlive() const;
|
98
|
+
void setKeepAlive(bool value);
|
99
|
+
|
100
|
+
void update();
|
101
|
+
void send(const void* buffer, std::size_t size);
|
102
|
+
void sendPendingData();
|
103
|
+
std::size_t pendingBytes() const;
|
104
|
+
|
105
|
+
boost::function<void (const void*, std::size_t)> onReceive;
|
106
|
+
boost::function<void ()> onDisconnection;
|
107
|
+
};
|
108
|
+
|
109
|
+
class ListenerSocket
|
110
|
+
{
|
111
|
+
struct Impl;
|
112
|
+
boost::scoped_ptr<Impl> pimpl;
|
113
|
+
|
114
|
+
public:
|
115
|
+
ListenerSocket(SocketPort port);
|
116
|
+
~ListenerSocket();
|
117
|
+
|
118
|
+
SocketAddress address() const;
|
119
|
+
SocketPort port() const;
|
120
|
+
|
121
|
+
void update();
|
122
|
+
|
123
|
+
// This signal is fired by update() whenever someone connects
|
124
|
+
// to the port which is currently listened on.
|
125
|
+
boost::function<void (Socket&)> onConnection;
|
126
|
+
};
|
127
|
+
}
|
128
|
+
|
129
|
+
#endif
|