gosu 0.7.40 → 0.7.41

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.
@@ -5,9 +5,11 @@
5
5
  #define GOSU_IMAGE_HPP
6
6
 
7
7
  #include <Gosu/Fwd.hpp>
8
- #include <Gosu/Bitmap.hpp>
8
+ #include <Gosu/Color.hpp>
9
+ #include <Gosu/GraphicsBase.hpp>
9
10
  #include <Gosu/TR1.hpp>
10
11
  #include <memory>
12
+ #include <vector>
11
13
 
12
14
  namespace Gosu
13
15
  {
@@ -79,7 +81,10 @@ namespace Gosu
79
81
  //! Provides access to the underlying image data object.
80
82
  ImageData& getData() const;
81
83
  };
82
-
84
+
85
+ std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
86
+ std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
87
+
83
88
  //! Convenience function that splits a BMP or PNG file into an array
84
89
  //! of small rectangles and creates images from them.
85
90
  //! \param tileWidth If positive, specifies the width of one tile in
@@ -89,14 +94,13 @@ namespace Gosu
89
94
  //! Must provide a push_back member function; vector<tr1::shared_ptr<Image>>
90
95
  //! or boost::ptr_vector<Image> are good choices.
91
96
  template<typename Container>
92
- void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename,
93
- int tileWidth, int tileHeight, bool tileable, Container& appendTo)
97
+ void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
94
98
  {
95
- Bitmap bmp;
96
- loadImageFile(bmp, filename);
97
- imagesFromTiledBitmap(graphics, bmp, tileWidth, tileHeight, tileable, appendTo);
99
+ std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
100
+ for (int i = 0, num = tiles.size(); i < num; ++i)
101
+ appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
98
102
  }
99
-
103
+
100
104
  //! Convenience function that splits a bitmap into an area of array
101
105
  //! rectangles and creates images from them.
102
106
  //! \param tileWidth If positive, specifies the width of one tile in
@@ -109,29 +113,9 @@ namespace Gosu
109
113
  void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
110
114
  int tileWidth, int tileHeight, bool tileable, Container& appendTo)
111
115
  {
112
- int tilesX, tilesY;
113
-
114
- if (tileWidth > 0)
115
- tilesX = bmp.width() / tileWidth;
116
- else
117
- {
118
- tilesX = -tileWidth;
119
- tileWidth = bmp.width() / tilesX;
120
- }
121
-
122
- if (tileHeight > 0)
123
- tilesY = bmp.height() / tileHeight;
124
- else
125
- {
126
- tilesY = -tileHeight;
127
- tileHeight = bmp.height() / tilesY;
128
- }
129
-
130
- for (int y = 0; y < tilesY; ++y)
131
- for (int x = 0; x < tilesX; ++x)
132
- appendTo.push_back(typename Container::value_type(new Image(graphics, bmp,
133
- x * tileWidth, y * tileHeight, tileWidth, tileHeight,
134
- tileable)));
116
+ std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, tileWidth, tileHeight, tileable);
117
+ for (int i = 0, num = tiles.size(); i < num; ++i)
118
+ appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
135
119
  }
136
120
  }
137
121
 
@@ -1,26 +1,34 @@
1
1
  //! \file TR1.hpp
2
- //! Includes all parts of C++03 (TR1) that are relevant for Gosu.
2
+ //! Includes all parts of C++03 (TR1) that are relevant for Gosu. It makes available the following members of the std::tr1 namespace: array, bind, function, shared_ptr, uint*_t and int*_t.
3
3
 
4
4
  #ifndef GOSU_TR1_HPP
5
5
  #define GOSU_TR1_HPP
6
6
 
7
- #ifdef _MSC_VER
7
+ #include <memory>
8
+
9
+ #if defined(_MSC_VER) || defined(_LIBCPP_MEMORY)
8
10
  #include <array>
9
- #include <memory>
10
11
  #include <functional>
11
12
  namespace std
12
13
  {
13
14
  namespace tr1
14
15
  {
15
- typedef unsigned char uint8_t;
16
- typedef unsigned short uint16_t;
17
- typedef unsigned int uint32_t;
18
- typedef unsigned long long uint64_t;
19
- typedef signed char int8_t;
20
- typedef signed short int16_t;
21
- typedef signed int int32_t;
22
- typedef signed long long int64_t;
23
- }
16
+ typedef unsigned char uint8_t;
17
+ typedef unsigned short uint16_t;
18
+ typedef unsigned int uint32_t;
19
+ typedef unsigned long long uint64_t;
20
+ typedef signed char int8_t;
21
+ typedef signed short int16_t;
22
+ typedef signed int int32_t;
23
+ typedef signed long long int64_t;
24
+
25
+ #ifdef _LIBCPP_MEMORY
26
+ using std::array;
27
+ using std::bind;
28
+ using std::function;
29
+ using std::shared_ptr;
30
+ #endif
31
+ }
24
32
  }
25
33
  #else
26
34
  #include <tr1/array>
@@ -32,7 +40,7 @@
32
40
  {
33
41
  namespace tr1
34
42
  {
35
- using ::int8_t; using ::int16_t; using ::int32_t; using ::int64_t;
43
+ using ::int8_t; using ::int16_t; using ::int32_t; using ::int64_t;
36
44
  using ::uint8_t; using ::uint16_t; using ::uint32_t; using ::uint64_t;
37
45
  }
38
46
  }
@@ -3,8 +3,8 @@
3
3
 
4
4
  #define GOSU_MAJOR_VERSION 0
5
5
  #define GOSU_MINOR_VERSION 7
6
- #define GOSU_POINT_VERSION 40
7
- #define GOSU_VERSION "0.7.40"
6
+ #define GOSU_POINT_VERSION 41
7
+ #define GOSU_VERSION "0.7.41"
8
8
 
9
9
  #define GOSU_COPYRIGHT_NOTICE \
10
10
  " " \
@@ -105,6 +105,7 @@ namespace Gosu
105
105
  #endif
106
106
 
107
107
  #ifdef GOSU_IS_IPHONE
108
+ void* rootViewController() const;
108
109
  // iPhone-only callbacks for touch events.
109
110
  // Note that it does not hurt to override them even if you compile
110
111
  // for another platform; if you don't specify "virtual" the code
@@ -121,4 +122,8 @@ namespace Gosu
121
122
  };
122
123
  }
123
124
 
125
+ #ifdef GOSU_IS_IPHONE
126
+ Gosu::Window& windowInstance();
127
+ #endif
128
+
124
129
  #endif
@@ -32,10 +32,23 @@ namespace
32
32
  for (int i = bitmap.width() * bitmap.height(); i > 0; --i, ++p)
33
33
  *p = (*p & 0xff00ff00) | ((*p << 16) & 0x00ff0000) | ((*p >> 16) & 0x000000ff);
34
34
  }
35
+
36
+ FIBITMAP* ensure32bits(FIBITMAP* fib)
37
+ {
38
+ int bpp = FreeImage_GetBPP(fib);
39
+ FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(fib);
40
+ if (bpp != 32 && (image_type == FIT_BITMAP || image_type == FIT_RGBA16)) {
41
+ FIBITMAP* fib32 = FreeImage_ConvertTo32Bits(fib);
42
+ FreeImage_Unload(fib);
43
+ fib = fib32;
44
+ }
45
+ return fib;
46
+ }
35
47
 
36
48
  void fibToBitmap(Gosu::Bitmap& bitmap, FIBITMAP* fib, FREE_IMAGE_FORMAT fif)
37
49
  {
38
50
  bitmap.resize(FreeImage_GetWidth(fib), FreeImage_GetHeight(fib));
51
+ fib = ensure32bits(fib);
39
52
  FreeImage_ConvertToRawBits(reinterpret_cast<BYTE*>(bitmap.data()),
40
53
  fib, bitmap.width() * 4, 32,
41
54
  FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE);
@@ -76,13 +76,6 @@ public:
76
76
  updateEffectiveRect();
77
77
  }
78
78
 
79
- void swap(ClipRectStack& other)
80
- {
81
- stack.swap(other.stack); // don't trust ADL :/
82
- std::swap(hasEffectiveRect, other.hasEffectiveRect);
83
- std::swap(effectiveRect, other.effectiveRect);
84
- }
85
-
86
79
  const ClipRect* maybeEffectiveRect() const
87
80
  {
88
81
  return hasEffectiveRect ? &effectiveRect : 0;
@@ -58,7 +58,7 @@ namespace Gosu
58
58
  struct DrawOp;
59
59
  class DrawOpQueue;
60
60
  typedef std::list<Transform> Transforms;
61
- typedef std::vector<DrawOpQueue> DrawOpQueueStack;
61
+ typedef std::list<DrawOpQueue> DrawOpQueueStack;
62
62
  class Macro;
63
63
  struct ArrayVertex
64
64
  {
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include <Gosu/TR1.hpp>
5
5
  #include <GosuImpl/Graphics/Common.hpp>
6
+ #include <GosuImpl/Graphics/TransformStack.hpp>
6
7
  #include <GosuImpl/Graphics/ClipRectStack.hpp>
7
8
  #include <GosuImpl/Graphics/DrawOp.hpp>
8
9
  #include <cassert>
@@ -12,8 +13,7 @@
12
13
 
13
14
  class Gosu::DrawOpQueue
14
15
  {
15
- Transforms individualTransforms;
16
- Transforms absoluteTransforms;
16
+ TransformStack transformStack;
17
17
  ClipRectStack clipRectStack;
18
18
 
19
19
  typedef std::vector<DrawOp> DrawOps;
@@ -21,31 +21,7 @@ class Gosu::DrawOpQueue
21
21
  typedef std::vector<std::tr1::function<void()> > GLBlocks;
22
22
  GLBlocks glBlocks;
23
23
 
24
- void makeCurrentTransform(const Transform& transform)
25
- {
26
- Transforms::iterator oldPosition =
27
- std::find(absoluteTransforms.begin(), absoluteTransforms.end(), transform);
28
- if (oldPosition == absoluteTransforms.end())
29
- absoluteTransforms.push_back(transform);
30
- else
31
- absoluteTransforms.splice(absoluteTransforms.end(), absoluteTransforms, oldPosition);
32
- }
33
-
34
- Transform& currentTransform()
35
- {
36
- return absoluteTransforms.back();
37
- }
38
-
39
24
  public:
40
- DrawOpQueue()
41
- {
42
- // Every queue has a base transform that is always the current transform.
43
- // This keeps the code a bit more uniform, and allows the window to
44
- // set a base transform in the main rendering queue.
45
- individualTransforms.push_back(scale(1));
46
- absoluteTransforms.push_back(scale(1));
47
- }
48
-
49
25
  void scheduleDrawOp(DrawOp op)
50
26
  {
51
27
  if (clipRectStack.clippedWorldAway())
@@ -56,7 +32,7 @@ public:
56
32
  assert (op.verticesOrBlockIndex == 4);
57
33
  #endif
58
34
 
59
- op.renderState.transform = &currentTransform();
35
+ op.renderState.transform = &transformStack.current();
60
36
  if (const ClipRect* cr = clipRectStack.maybeEffectiveRect())
61
37
  op.renderState.clipRect = *cr;
62
38
  ops.push_back(op);
@@ -73,7 +49,7 @@ public:
73
49
 
74
50
  DrawOp op;
75
51
  op.verticesOrBlockIndex = complementOfBlockIndex;
76
- op.renderState.transform = &currentTransform();
52
+ op.renderState.transform = &transformStack.current();
77
53
  if (const ClipRect* cr = clipRectStack.maybeEffectiveRect())
78
54
  op.renderState.clipRect = *cr;
79
55
  op.z = z;
@@ -87,8 +63,8 @@ public:
87
63
  double left = x, right = x + width;
88
64
  double top = y, bottom = y + height;
89
65
 
90
- applyTransform(currentTransform(), left, top);
91
- applyTransform(currentTransform(), right, bottom);
66
+ applyTransform(transformStack.current(), left, top);
67
+ applyTransform(transformStack.current(), right, bottom);
92
68
 
93
69
  int physX = std::min(left, right);
94
70
  int physY = std::min(top, bottom);
@@ -110,31 +86,17 @@ public:
110
86
 
111
87
  void setBaseTransform(const Transform& baseTransform)
112
88
  {
113
- assert (individualTransforms.size() == 1);
114
- assert (absoluteTransforms.size() == 1);
115
-
116
- individualTransforms.front() = absoluteTransforms.front() = baseTransform;
89
+ transformStack.setBaseTransform(baseTransform);
117
90
  }
118
91
 
119
92
  void pushTransform(const Transform& transform)
120
93
  {
121
- individualTransforms.push_back(transform);
122
- Transform result = multiply(transform, currentTransform());
123
- makeCurrentTransform(result);
94
+ transformStack.push(transform);
124
95
  }
125
96
 
126
97
  void popTransform()
127
98
  {
128
- assert (individualTransforms.size() > 1);
129
-
130
- individualTransforms.pop_back();
131
- // TODO: If currentTransform() wouldn't have to be .back(), then I think
132
- // this could be optimized away and just be pop_back too. Or not?
133
- Transform result = scale(1);
134
- for (Transforms::reverse_iterator it = individualTransforms.rbegin(),
135
- end = individualTransforms.rend(); it != end; ++it)
136
- result = multiply(result, *it);
137
- makeCurrentTransform(result);
99
+ transformStack.pop();
138
100
  }
139
101
 
140
102
  void performDrawOpsAndCode()
@@ -185,17 +147,21 @@ public:
185
147
  op->compileTo(vas);
186
148
  }
187
149
 
188
- void clear()
150
+ // This retains the current stack of transforms and clippings.
151
+ void clearQueue()
189
152
  {
190
- absoluteTransforms.resize(1);
191
- // Important!! Due to all the swapping, the first entry in the list is not necessarily
192
- // the base matrix. We need to restore it.
193
- absoluteTransforms.front() = scale(1);
194
- individualTransforms.resize(1);
195
- clipRectStack.clear();
196
153
  glBlocks.clear();
197
154
  ops.clear();
198
155
  }
156
+
157
+ // This clears the queue and starts with new stacks. This must not be called
158
+ // when endClipping/popTransform calls might still be pending.
159
+ void reset()
160
+ {
161
+ transformStack.reset();
162
+ clipRectStack.clear();
163
+ clearQueue();
164
+ }
199
165
  };
200
166
 
201
167
  #endif
@@ -36,7 +36,7 @@ int Gosu::clipRectBaseFactor()
36
36
  }
37
37
 
38
38
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
39
- return NO;//UIInterfaceOrientationIsLandscape(interfaceOrientation);
39
+ return NO;
40
40
  }
41
41
 
42
42
  - (void)didReceiveMemoryWarning {
@@ -52,20 +52,9 @@ struct Gosu::Graphics::Impl
52
52
  }
53
53
  }
54
54
 
55
- Orientation orientation;
56
-
57
- Impl()
58
- : orientation(currentOrientation())
59
- {
60
- }
61
-
62
55
  void updateBaseTransform()
63
56
  {
64
- if (orientation != currentOrientation())
65
- {
66
- orientation = currentOrientation();
67
- queues.front().setBaseTransform(transformForOrientation(orientation));
68
- }
57
+ queues.front().setBaseTransform(transformForOrientation(currentOrientation()));
69
58
  }
70
59
  #endif
71
60
  };
@@ -127,9 +116,8 @@ void Gosu::Graphics::setResolution(unsigned virtualWidth, unsigned virtualHeight
127
116
  throw std::invalid_argument("Invalid virtual resolution.");
128
117
 
129
118
  pimpl->virtWidth = virtualWidth, pimpl->virtHeight = virtualHeight;
130
- #ifdef GOSU_IS_IPHONE
131
- pimpl->orientation = static_cast<Orientation>(-1);
132
- #else
119
+ #ifndef GOSU_IS_IPHONE
120
+ // on the iPhone, updateCurrentTransform will handle this (yuck)
133
121
  Transform baseTransform;
134
122
  baseTransform = scale(1.0 / virtualWidth * pimpl->physWidth,
135
123
  1.0 / virtualHeight * pimpl->physHeight);
@@ -142,8 +130,8 @@ bool Gosu::Graphics::begin(Gosu::Color clearWithColor)
142
130
  // If recording is in process, cancel it.
143
131
  assert (pimpl->queues.size() == 1);
144
132
  pimpl->queues.resize(1);
145
- // Clear leftover clippings.
146
- pimpl->queues.front().clear();
133
+ // Clear leftover transforms, clip rects etc.
134
+ pimpl->queues.front().reset();
147
135
 
148
136
  #ifdef GOSU_IS_IPHONE
149
137
  pimpl->updateBaseTransform();
@@ -172,7 +160,7 @@ void Gosu::Graphics::flush()
172
160
  throw std::logic_error("Flushing to screen is not allowed while creating a macro");
173
161
 
174
162
  pimpl->queues.front().performDrawOpsAndCode();
175
- pimpl->queues.front().clear();
163
+ pimpl->queues.front().clearQueue();
176
164
  }
177
165
 
178
166
  void Gosu::Graphics::beginGL()
@@ -111,3 +111,38 @@ Gosu::ImageData& Gosu::Image::getData() const
111
111
  {
112
112
  return *data;
113
113
  }
114
+
115
+ std::vector<Gosu::Image> Gosu::loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable)
116
+ {
117
+ int tilesX, tilesY;
118
+ std::vector<Image> images;
119
+
120
+ if (tileWidth > 0)
121
+ tilesX = bmp.width() / tileWidth;
122
+ else
123
+ {
124
+ tilesX = -tileWidth;
125
+ tileWidth = bmp.width() / tilesX;
126
+ }
127
+
128
+ if (tileHeight > 0)
129
+ tilesY = bmp.height() / tileHeight;
130
+ else
131
+ {
132
+ tilesY = -tileHeight;
133
+ tileHeight = bmp.height() / tilesY;
134
+ }
135
+
136
+ for (int y = 0; y < tilesY; ++y)
137
+ for (int x = 0; x < tilesX; ++x)
138
+ images.push_back(Image(graphics, bmp, x * tileWidth, y * tileHeight, tileWidth, tileHeight, tileable));
139
+
140
+ return images;
141
+ }
142
+
143
+ std::vector<Gosu::Image> Gosu::loadTiles(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable)
144
+ {
145
+ Bitmap bmp;
146
+ loadImageFile(bmp, filename);
147
+ return loadTiles(graphics, bmp, tileWidth, tileHeight, tileable);
148
+ }
@@ -8,7 +8,7 @@
8
8
  struct Gosu::RenderState
9
9
  {
10
10
  GLuint texName;
11
- Transform* transform;
11
+ const Transform* transform;
12
12
  ClipRect clipRect;
13
13
  AlphaMode mode;
14
14
 
@@ -126,16 +126,19 @@ public:
126
126
 
127
127
  if (newTexName != NO_TEXTURE)
128
128
  {
129
+ // New texture *is* really a texture - change to it.
130
+
129
131
  if (texName == NO_TEXTURE)
130
132
  glEnable(GL_TEXTURE_2D);
131
133
  glBindTexture(GL_TEXTURE_2D, newTexName);
132
134
  }
133
- else if (texName != NO_TEXTURE)
135
+ else
136
+ // New texture is NO_TEXTURE, disable texturing.
134
137
  glDisable(GL_TEXTURE_2D);
135
138
  texName = newTexName;
136
139
  }
137
140
 
138
- void setTransform(Transform* newTransform)
141
+ void setTransform(const Transform* newTransform)
139
142
  {
140
143
  if (newTransform == transform)
141
144
  return;
@@ -0,0 +1,100 @@
1
+ #ifndef GOSUIMPL_GRAPHICS_TRANSFORMSTACK_HPP
2
+ #define GOSUIMPL_GRAPHICS_TRANSFORMSTACK_HPP
3
+
4
+ #include <GosuImpl/Graphics/Common.hpp>
5
+ #include <cassert>
6
+ #include <algorithm>
7
+
8
+ namespace Gosu
9
+ {
10
+ class TransformStack
11
+ {
12
+ // All the matrices that are pushed right now.
13
+ Transforms individual;
14
+ // All the absolute matrices that have been created since last reset.
15
+ Transforms absolute;
16
+ // Points to one absolute transform.
17
+ Transforms::const_iterator currentIterator;
18
+
19
+ void makeCurrent(const Transform& transform)
20
+ {
21
+ currentIterator =
22
+ std::find(absolute.begin(), absolute.end(), transform);
23
+ if (currentIterator == absolute.end())
24
+ currentIterator = absolute.insert(absolute.end(), transform);
25
+ }
26
+
27
+ public:
28
+ TransformStack()
29
+ {
30
+ reset();
31
+ individual.front() = absolute.front() = scale(1);
32
+ }
33
+
34
+ void reset()
35
+ {
36
+ // Every queue has a base transform that is always the current transform.
37
+ // This keeps the code a bit more uniform, and allows the window to
38
+ // set a base transform in the main rendering queue.
39
+ individual.resize(1);
40
+ absolute.resize(1);
41
+ currentIterator = absolute.begin();
42
+ }
43
+
44
+ TransformStack(const TransformStack& other)
45
+ {
46
+ *this = other;
47
+ }
48
+
49
+ // Custom assignment to ensure valid currentIterator
50
+ TransformStack& operator=(const TransformStack &other)
51
+ {
52
+ individual = other.individual;
53
+ absolute = other.absolute;
54
+
55
+ // Reset our currentIterator to point to the respective element
56
+ // in our own 'absolute' transforms by iterating both lists up to
57
+ // the other lists' current iterator
58
+ currentIterator = absolute.begin();
59
+ Transforms::const_iterator otherIterator = other.absolute.begin();
60
+ while (otherIterator != other.currentIterator)
61
+ ++currentIterator, ++otherIterator;
62
+
63
+ return *this;
64
+ }
65
+
66
+ void setBaseTransform(const Transform& baseTransform)
67
+ {
68
+ assert (individual.size() == 1);
69
+ assert (absolute.size() == 1);
70
+
71
+ individual.front() = absolute.front() = baseTransform;
72
+ }
73
+
74
+ const Transform& current()
75
+ {
76
+ return *currentIterator;
77
+ }
78
+
79
+ void push(const Transform& transform)
80
+ {
81
+ individual.push_back(transform);
82
+ Transform result = multiply(transform, current());
83
+ makeCurrent(result);
84
+ }
85
+
86
+ void pop()
87
+ {
88
+ assert (individual.size() > 1);
89
+
90
+ individual.pop_back();
91
+ Transform result = scale(1);
92
+ for (Transforms::reverse_iterator it = individual.rbegin(),
93
+ end = individual.rend(); it != end; ++it)
94
+ result = multiply(result, *it);
95
+ makeCurrent(result);
96
+ }
97
+ };
98
+ }
99
+
100
+ #endif
@@ -1,10 +1,10 @@
1
1
  #include <Gosu/Input.hpp>
2
2
  #include <Gosu/TextInput.hpp>
3
3
 
4
- #import <GosuImpl/MacUtility.hpp>
5
- #import <GosuImpl/Orientation.hpp>
6
- #import <GosuImpl/Graphics/GosuView.hpp>
7
- #import <GosuImpl/Input/AccelerometerReader.hpp>
4
+ #include <GosuImpl/MacUtility.hpp>
5
+ #include <GosuImpl/Orientation.hpp>
6
+ #include <GosuImpl/Input/AccelerometerReader.hpp>
7
+ #import <UIKit/UIKit.h>
8
8
 
9
9
  struct Gosu::TextInput::Impl {};
10
10
  Gosu::TextInput::TextInput() {}
@@ -14,8 +14,10 @@ void Gosu::TextInput::setText(const std::wstring& text) {}
14
14
  unsigned Gosu::TextInput::caretPos() const { return 0; }
15
15
  unsigned Gosu::TextInput::selectionStart() const { return 0; }
16
16
 
17
- struct Gosu::Input::Impl {
18
- GosuView* view;
17
+ struct Gosu::Input::Impl
18
+ {
19
+ UIView* view;
20
+ float mouseX, mouseY;
19
21
  float factorX, factorY;
20
22
  float updateInterval;
21
23
 
@@ -52,13 +54,15 @@ struct Gosu::Input::Impl {
52
54
  Gosu::Input::Input(void* view, float updateInterval)
53
55
  : pimpl(new Impl)
54
56
  {
55
- pimpl->view = (GosuView*)view;
57
+ pimpl->view = (UIView*)view;
56
58
  pimpl->updateInterval = updateInterval;
57
59
  pimpl->currentTouchesSet.reset([[NSMutableSet alloc] init]);
60
+ pimpl->mouseX = pimpl->mouseY = -1000;
58
61
  setMouseFactors(1, 1);
59
62
  }
60
63
 
61
- Gosu::Input::~Input() {
64
+ Gosu::Input::~Input()
65
+ {
62
66
  }
63
67
 
64
68
  void Gosu::Input::feedTouchEvent(int type, void* touches)
@@ -76,27 +80,34 @@ void Gosu::Input::feedTouchEvent(int type, void* touches)
76
80
  (*f)(pimpl->translateTouch(uiTouch));
77
81
  }
78
82
 
79
- wchar_t Gosu::Input::idToChar(Button btn) {
83
+ wchar_t Gosu::Input::idToChar(Button btn)
84
+ {
80
85
  return 0;
81
86
  }
82
87
 
83
- Gosu::Button Gosu::Input::charToId(wchar_t ch) {
88
+ Gosu::Button Gosu::Input::charToId(wchar_t ch)
89
+ {
84
90
  return noButton;
85
91
  }
86
92
 
87
- bool Gosu::Input::down(Button btn) const {
93
+ bool Gosu::Input::down(Button btn) const
94
+ {
88
95
  return false;
89
96
  }
90
97
 
91
- double Gosu::Input::mouseX() const {
92
- return -1000;
98
+ double Gosu::Input::mouseX() const
99
+ {
100
+ return pimpl->mouseX;
93
101
  }
94
102
 
95
- double Gosu::Input::mouseY() const {
96
- return -1000;
103
+ double Gosu::Input::mouseY() const
104
+ {
105
+ return pimpl->mouseY;
97
106
  }
98
107
 
99
108
  void Gosu::Input::setMousePosition(double x, double y) {
109
+ pimpl->mouseX = x;
110
+ pimpl->mouseY = y;
100
111
  }
101
112
 
102
113
  void Gosu::Input::setMouseFactors(double factorX, double factorY) {
@@ -115,19 +126,23 @@ const Gosu::Touches& Gosu::Input::currentTouches() const
115
126
  return *pimpl->currentTouchesVector;
116
127
  }
117
128
 
118
- double Gosu::Input::accelerometerX() const {
129
+ double Gosu::Input::accelerometerX() const
130
+ {
119
131
  return pimpl->acceleration(0);
120
132
  }
121
133
 
122
- double Gosu::Input::accelerometerY() const {
134
+ double Gosu::Input::accelerometerY() const
135
+ {
123
136
  return pimpl->acceleration(1);
124
137
  }
125
138
 
126
- double Gosu::Input::accelerometerZ() const {
139
+ double Gosu::Input::accelerometerZ() const
140
+ {
127
141
  return pimpl->acceleration(2);
128
142
  }
129
143
 
130
- void Gosu::Input::update() {
144
+ void Gosu::Input::update()
145
+ {
131
146
  // Check for dead touches and remove from vector if
132
147
  // necessary
133
148
 
@@ -140,7 +155,7 @@ void Gosu::Input::update() {
140
155
  phase == UITouchPhaseMoved ||
141
156
  phase == UITouchPhaseStationary)
142
157
  continue;
143
-
158
+
144
159
  // Something was deleted, we will need the set.
145
160
  if (!deadTouches.get())
146
161
  deadTouches.reset([[NSMutableSet alloc] init]);
@@ -158,10 +173,12 @@ void Gosu::Input::update() {
158
173
  }
159
174
  }
160
175
 
161
- Gosu::TextInput* Gosu::Input::textInput() const {
176
+ Gosu::TextInput* Gosu::Input::textInput() const
177
+ {
162
178
  return 0;
163
179
  }
164
180
 
165
- void Gosu::Input::setTextInput(TextInput* input) {
181
+ void Gosu::Input::setTextInput(TextInput* input)
182
+ {
166
183
  throw "NYI";
167
184
  }
@@ -19,8 +19,8 @@ Gosu::Orientation Gosu::currentOrientation()
19
19
 
20
20
  static Orientation orientation = Gosu::Orientation(-1);
21
21
  static unsigned waitingForChangeSince = now;
22
-
23
- if (!UIDeviceOrientationIsLandscape(newOrientation) || orientationToGosu(newOrientation) == orientation)
22
+
23
+ if (not UIDeviceOrientationIsLandscape(newOrientation) or orientationToGosu(newOrientation) == orientation)
24
24
  waitingForChangeSince = now;
25
25
 
26
26
  if (now - waitingForChangeSince >= CHANGE_AFTER_MS or orientation == Gosu::Orientation(-1))
@@ -158,6 +158,7 @@
158
158
  #undef close
159
159
  #undef read
160
160
  #undef bind
161
+ #undef send
161
162
  #undef sleep
162
163
  #undef Sleep
163
164
  #undef int8_t
@@ -173,23 +174,7 @@
173
174
  //#include <Gosu/Async.hpp>
174
175
  //#endif
175
176
 
176
- #include <Gosu/Audio.hpp>
177
- #include <Gosu/Color.hpp>
178
- #include <Gosu/Font.hpp>
179
- #include <Gosu/GraphicsBase.hpp>
180
- #include <Gosu/Graphics.hpp>
181
- #include <Gosu/Image.hpp>
182
- #include <Gosu/ImageData.hpp>
183
- #include <Gosu/Inspection.hpp>
184
- #include <Gosu/Input.hpp>
185
- #include <Gosu/IO.hpp>
186
- #include <Gosu/Math.hpp>
187
- #include <Gosu/Text.hpp>
188
- #include <Gosu/TextInput.hpp>
189
- #include <Gosu/Timing.hpp>
190
- #include <Gosu/Utility.hpp>
191
- #include <Gosu/Version.hpp>
192
- #include <Gosu/Window.hpp>
177
+ #include <Gosu/Gosu.hpp>
193
178
  #ifdef GOSU_IS_WIN
194
179
  #include <FreeImage.h>
195
180
  #endif
@@ -521,6 +506,7 @@ namespace Gosu {
521
506
  %ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, bool tileable = false);
522
507
  %ignore Gosu::Image::Image(Graphics& graphics, const Bitmap& source, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, bool tileable = false);
523
508
  %ignore Gosu::Image::Image(std::auto_ptr<ImageData> data);
509
+ %ignore Gosu::loadTiles;
524
510
  %include "../Gosu/Image.hpp"
525
511
  %extend Gosu::Image {
526
512
  Image(Gosu::Window& window, VALUE source, bool tileable = false) {
@@ -2208,6 +2208,7 @@ static VALUE mGosu;
2208
2208
  #undef close
2209
2209
  #undef read
2210
2210
  #undef bind
2211
+ #undef send
2211
2212
  #undef sleep
2212
2213
  #undef Sleep
2213
2214
  #undef int8_t
@@ -2223,23 +2224,7 @@ static VALUE mGosu;
2223
2224
  //#include <Gosu/Async.hpp>
2224
2225
  //#endif
2225
2226
 
2226
- #include <Gosu/Audio.hpp>
2227
- #include <Gosu/Color.hpp>
2228
- #include <Gosu/Font.hpp>
2229
- #include <Gosu/GraphicsBase.hpp>
2230
- #include <Gosu/Graphics.hpp>
2231
- #include <Gosu/Image.hpp>
2232
- #include <Gosu/ImageData.hpp>
2233
- #include <Gosu/Inspection.hpp>
2234
- #include <Gosu/Input.hpp>
2235
- #include <Gosu/IO.hpp>
2236
- #include <Gosu/Math.hpp>
2237
- #include <Gosu/Text.hpp>
2238
- #include <Gosu/TextInput.hpp>
2239
- #include <Gosu/Timing.hpp>
2240
- #include <Gosu/Utility.hpp>
2241
- #include <Gosu/Version.hpp>
2242
- #include <Gosu/Window.hpp>
2227
+ #include <Gosu/Gosu.hpp>
2243
2228
  #ifdef GOSU_IS_WIN
2244
2229
  #include <FreeImage.h>
2245
2230
  #endif
@@ -11243,8 +11228,8 @@ SWIGEXPORT void Init_gosu(void) {
11243
11228
  SWIG_RubyInitializeTrackings();
11244
11229
  rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
11245
11230
  rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(7)));
11246
- rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(40)));
11247
- rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.40"));
11231
+ rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(41)));
11232
+ rb_define_const(mGosu, "VERSION", SWIG_FromCharPtr("0.7.41"));
11248
11233
  rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
11249
11234
  rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
11250
11235
  rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
@@ -13,27 +13,41 @@ using namespace std::tr1::placeholders;
13
13
 
14
14
  namespace Gosu
15
15
  {
16
- CGRect screenRect = [[UIScreen mainScreen] bounds];
16
+ static CGRect &screenRect()
17
+ {
18
+ static CGRect screenRect = [[UIScreen mainScreen] bounds];
19
+ return screenRect;
20
+ }
17
21
 
18
22
  unsigned screenWidth()
19
23
  {
20
- return screenRect.size.width;
24
+ return screenRect().size.width;
21
25
  }
22
26
 
23
27
  unsigned screenHeight()
24
28
  {
25
- return screenRect.size.height;
29
+ return screenRect().size.height;
26
30
  }
27
31
  }
28
32
 
29
- int main(int argc, char *argv[]) {
30
- [[NSAutoreleasePool alloc] init];
31
- return UIApplicationMain(argc, argv, nil, @"GosuAppDelegate");
33
+ int main(int argc, char *argv[])
34
+ {
35
+ try
36
+ {
37
+ [[NSAutoreleasePool alloc] init];
38
+ return UIApplicationMain(argc, argv, nil, @"GosuAppDelegate");
39
+ }
40
+ catch (const std::exception& e)
41
+ {
42
+ NSLog(@"Terminating due to C++ exception: %s", e.what());
43
+ throw;
44
+ }
32
45
  }
33
46
 
34
47
  class Gosu::Audio {};
35
48
 
36
- struct Gosu::Window::Impl {
49
+ struct Gosu::Window::Impl
50
+ {
37
51
  ObjRef<UIWindow> window;
38
52
  ObjRef<GosuViewController> controller;
39
53
  std::auto_ptr<Graphics> graphics;
@@ -57,27 +71,22 @@ namespace
57
71
 
58
72
  @implementation GosuAppDelegate
59
73
  // Required according to docs...
60
- - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application
61
- {
74
+ - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application {
62
75
  }
63
76
 
64
77
  // Required according to docs...
65
- - (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application
66
- {
78
+ - (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application {
67
79
  }
68
80
 
69
81
  // Required according to docs...
70
- - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
71
- {
82
+ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
72
83
  }
73
84
 
74
85
  - (void)applicationDidFinishLaunching:(UIApplication *)application {
75
86
  [UIDevice.currentDevice beginGeneratingDeviceOrientationNotifications];
76
- UIApplication.sharedApplication.idleTimerDisabled = YES;
87
+ //UIApplication.sharedApplication.idleTimerDisabled = YES;
77
88
  UIApplication.sharedApplication.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
78
-
79
- windowInstance();
80
-
89
+
81
90
  [[NSTimer scheduledTimerWithTimeInterval: windowInstance().updateInterval() / 1000.0
82
91
  target: self
83
92
  selector: @selector(doTick:)
@@ -139,11 +148,13 @@ Gosu::Window::~Window()
139
148
  {
140
149
  }
141
150
 
142
- std::wstring Gosu::Window::caption() const {
151
+ std::wstring Gosu::Window::caption() const
152
+ {
143
153
  return L"";
144
154
  }
145
155
 
146
- void Gosu::Window::setCaption(const std::wstring& caption) {
156
+ void Gosu::Window::setCaption(const std::wstring& caption)
157
+ {
147
158
  }
148
159
 
149
160
  double Gosu::Window::updateInterval() const
@@ -151,27 +162,33 @@ double Gosu::Window::updateInterval() const
151
162
  return pimpl->interval;
152
163
  }
153
164
 
154
- const Gosu::Graphics& Gosu::Window::graphics() const {
165
+ const Gosu::Graphics& Gosu::Window::graphics() const
166
+ {
155
167
  return *pimpl->graphics;
156
168
  }
157
169
 
158
- Gosu::Graphics& Gosu::Window::graphics() {
170
+ Gosu::Graphics& Gosu::Window::graphics()
171
+ {
159
172
  return *pimpl->graphics;
160
173
  }
161
174
 
162
- const Gosu::Audio& Gosu::Window::audio() const {
175
+ const Gosu::Audio& Gosu::Window::audio() const
176
+ {
163
177
  return *pimpl->audio;
164
178
  }
165
179
 
166
- Gosu::Audio& Gosu::Window::audio() {
180
+ Gosu::Audio& Gosu::Window::audio()
181
+ {
167
182
  return *pimpl->audio;
168
183
  }
169
184
 
170
- const Gosu::Input& Gosu::Window::input() const {
185
+ const Gosu::Input& Gosu::Window::input() const
186
+ {
171
187
  return *pimpl->input;
172
188
  }
173
189
 
174
- Gosu::Input& Gosu::Window::input() {
190
+ Gosu::Input& Gosu::Window::input()
191
+ {
175
192
  return *pimpl->input;
176
193
  }
177
194
 
@@ -183,3 +200,8 @@ void Gosu::Window::close()
183
200
  {
184
201
  throw std::logic_error("Cannot close windows manually on iOS");
185
202
  }
203
+
204
+ void* Gosu::Window::rootViewController() const
205
+ {
206
+ return pimpl->controller.get();
207
+ }
@@ -68,7 +68,7 @@ if `uname`.chomp == 'Darwin' then
68
68
  # Apple curiously distributes libpng only inside X11
69
69
  $INCFLAGS << " -I/usr/X11/include"
70
70
  # To make everything work with the Objective C runtime
71
- $CFLAGS << " -x objective-c++ -fobjc-gc"
71
+ $CFLAGS << " -x objective-c++ -fobjc-gc -DNDEBUG"
72
72
  $LDFLAGS << " -L/usr/X11/lib -logg -lvorbis -lvorbisfile -liconv"
73
73
  %w(AudioToolbox IOKit OpenAL OpenGL AppKit ApplicationServices Foundation Carbon).each do |f|
74
74
  #$INCFLAGS << " -framework #{f}" <- not necessary? I only get lots of warnings
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 83
4
+ hash: 81
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 40
10
- version: 0.7.40
9
+ - 41
10
+ version: 0.7.41
11
11
  platform: ruby
12
12
  authors:
13
13
  - Julian Raschke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-19 00:00:00 Z
18
+ date: 2011-12-17 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: " 2D game development library.\n\n Gosu features easy to use and game-friendly interfaces to 2D graphics\n and text (accelerated by 3D hardware), sound samples and music as well as\n keyboard, mouse and gamepad/joystick input.\n\n Also includes demos for integration with RMagick, Chipmunk and OpenGL.\n"
@@ -138,6 +138,7 @@ files:
138
138
  - GosuImpl/Graphics/Texture.hpp
139
139
  - GosuImpl/Graphics/TextWin.cpp
140
140
  - GosuImpl/Graphics/Transform.cpp
141
+ - GosuImpl/Graphics/TransformStack.hpp
141
142
  - GosuImpl/Iconv.hpp
142
143
  - GosuImpl/Input/AccelerometerReader.hpp
143
144
  - GosuImpl/Input/AccelerometerReader.mm