Permalink
Browse files

Added Pong sample

Added window_options
Modified glm to be available in xd namespace
  • Loading branch information...
1 parent 02e4235 commit adcd0532cddea59667dc2c463e5430803b950318 Reko Tiira committed Feb 29, 2012
View
@@ -13,4 +13,9 @@
/win/vc10/lua/Debug
/win/vc10/test/Debug
/win/vc10/common/Debug
-/win/vc10/system/Debug
+/win/vc10/system/Debug
+/win/vc10/samples/pong/Debug
+/win/vc10/samples/pong/Release
+/win/vc10/samples/Release
+/win/vc10/samples/Debug
+/win/vc10/samples/ipch
@@ -0,0 +1,21 @@
+#if !BOOST_PP_IS_ITERATING
+# error "do not include this file directly"
+#endif
+
+#include <utility>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+#define XD_N BOOST_PP_ITERATION()
+#define XD_FORWARD(Z, N, D) std::forward<BOOST_PP_CAT(T, N)>(BOOST_PP_CAT(p, N))
+
+template <BOOST_PP_ENUM_PARAMS(XD_N, typename T)>
+entity(BOOST_PP_ENUM_BINARY_PARAMS(XD_N, T, && p))
+ : Base(BOOST_PP_ENUM(XD_N, XD_FORWARD, _))
+{
+}
+
+#undef XD_FORWARD
+#undef XD_N
View
@@ -3,15 +3,20 @@
#include <xd/detail/entity.hpp>
+#include <xd/ref_counted.hpp>
+#include <xd/event_bus.hpp>
+#include <boost/config.hpp>
#include <boost/any.hpp>
#include <unordered_map>
#include <functional>
#include <memory>
#include <list>
#include <map>
#include <type_traits>
-#include <xd/ref_counted.hpp>
-#include <xd/event_bus.hpp>
+
+#ifdef BOOST_NO_VARIADIC_TEMPLATES
+#include <boost/preprocessor/iteration/iterate.hpp>
+#endif
namespace xd
{
@@ -51,6 +56,19 @@ namespace xd
{
}
+#ifndef BOOST_NO_VARIADIC_TEMPLATES
+ // constructor that delegates parameters to the entity_base
+ template <typename... Args>
+ entity(Args&&... args)
+ : Base(std::forward<Args>(args)...)
+ {
+ }
+#else
+ // generate xd::entity::entity overloads with file iteration (up to XD_MAX_ARITY parameters)
+ #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, XD_MAX_ARITY, <xd/detail/iterate_entity_constructor.hpp>))
+ #include BOOST_PP_ITERATE()
+#endif
+
entity(const Base& base)
: Base(base)
{
View
@@ -0,0 +1,12 @@
+#ifndef H_XD_GLM
+#define H_XD_GLM
+
+#include <xd/vendor/glm/glm.hpp>
+#include <xd/vendor/glm/gtc/type_ptr.hpp>
+
+namespace xd
+{
+ using namespace glm;
+}
+
+#endif
View
@@ -1,10 +1,10 @@
#ifndef H_XD_GRAPHICS
#define H_XD_GRAPHICS
+#include <xd/glm.hpp>
#include <xd/vendor/glew/glew.h>
-#include <xd/vendor/glm/glm.hpp>
-#include <xd/vendor/glm/gtc/type_ptr.hpp>
+#include <xd/factory.hpp>
#include <xd/graphics/exceptions.hpp>
#include <xd/graphics/font.hpp>
#include <xd/graphics/image.hpp>
@@ -2,7 +2,7 @@
#define H_XD_GRAPHICS_DETAIL_VERTEX_TRAITS
#include <xd/vendor/glew/glew.h>
-#include <xd/vendor/glm/glm.hpp>
+#include <xd/glm.hpp>
#include <type_traits>
namespace xd
@@ -4,18 +4,18 @@
#include <xd/graphics/detail/font.hpp>
#include <xd/vendor/glew/glew.h>
-#include <xd/vendor/glm/glm.hpp>
-#include <boost/noncopyable.hpp>
-#include <boost/optional.hpp>
-#include <boost/unordered_map.hpp>
-#include <memory>
-#include <unordered_map>
+#include <xd/glm.hpp>
+
#include <xd/ref_counted.hpp>
#include <xd/graphics/types.hpp>
#include <xd/graphics/vertex_batch.hpp>
#include <xd/graphics/shader_program.hpp>
#include <xd/graphics/transform_geometry.hpp>
#include <xd/vendor/utf8.h>
+#include <boost/noncopyable.hpp>
+#include <boost/optional.hpp>
+#include <memory>
+#include <unordered_map>
#ifndef XD_STATIC
// disable warning about boost::noncopyable not being dll-exportable
@@ -3,7 +3,7 @@
#include <stdexcept>
#include <stack>
-#include <xd/vendor/glm/glm.hpp>
+#include <xd/glm.hpp>
#include <xd/vendor/glm/gtc/matrix_transform.hpp>
namespace xd
@@ -81,6 +81,7 @@ namespace xd
{
scale(glm::vec3(s, s, s));
}
+
void rotate(float a, const glm::vec3& vec)
{
m_stack.top() = glm::rotate(m_stack.top(), a, vec);
@@ -2,18 +2,22 @@
#define H_XD_GRAPHICS_SHADER_PROGRAM
#include <xd/config.hpp>
+#include <xd/ref_counted.hpp>
#include <xd/vendor/glew/glew.h>
-#include <xd/vendor/glm/glm.hpp>
+#include <xd/glm.hpp>
#include <boost/noncopyable.hpp>
+#include <boost/intrusive_ptr.hpp>
#include <string>
#pragma warning(disable: 4275)
namespace xd
{
- class XD_API shader_program : boost::noncopyable
+ class XD_API shader_program : public ref_counted, public boost::noncopyable
{
public:
+ typedef boost::intrusive_ptr<shader_program> ptr;
+
// constructors & destructors
shader_program();
virtual ~shader_program();
@@ -6,44 +6,43 @@
#include <xd/graphics/transform_geometry.hpp>
#include <xd/graphics/texture.hpp>
#include <xd/graphics/types.hpp>
-#include <xd/vendor/glm/glm.hpp>
+#include <xd/glm.hpp>
#include <boost/noncopyable.hpp>
#pragma warning(disable: 4275)
namespace xd
{
// sprite batch
- class XD_API sprite_batch : public xd::ref_counted, public boost::noncopyable
+ class XD_API sprite_batch : public ref_counted, public boost::noncopyable
{
public:
typedef boost::intrusive_ptr<sprite_batch> ptr;
- sprite_batch(xd::transform_geometry& geometry_pipeline);
+ sprite_batch();
virtual ~sprite_batch();
void clear();
- void draw();
+ void draw(const mat4& matrix);
void set_scale(float scale);
float get_scale() const;
- void add(const xd::texture::ptr texture, float x, float y,
- const glm::vec4& color = glm::vec4(1, 1, 1, 1), const glm::vec2& anchor = glm::vec2(0, 0));
- void add(const xd::texture::ptr texture, float x, float y, float rotation, float scale,
- const glm::vec4& color = glm::vec4(1, 1, 1, 1), const glm::vec2& anchor = glm::vec2(0, 0));
- void add(const xd::texture::ptr texture, float x, float y, float rotation, const glm::vec2& scale,
- const glm::vec4& color = glm::vec4(1, 1, 1, 1), const glm::vec2& anchor = glm::vec2(0, 0));
+ void add(const texture::ptr texture, float x, float y,
+ const vec4& color = vec4(1, 1, 1, 1), const vec2& origin = vec2(0, 0));
+ void add(const texture::ptr texture, float x, float y, float rotation, float scale,
+ const vec4& color = vec4(1, 1, 1, 1), const vec2& origin = vec2(0, 0));
+ void add(const texture::ptr texture, float x, float y, float rotation, const vec2& scale,
+ const vec4& color = vec4(1, 1, 1, 1), const vec2& origin = vec2(0, 0));
- void add(const xd::texture::ptr texture, const xd::rect& src, float x, float y,
- const glm::vec4& color = glm::vec4(1, 1, 1, 1), const glm::vec2& anchor = glm::vec2(0, 0));
- void add(const xd::texture::ptr texture, const xd::rect& src, float x, float y, float rotation, float scale,
- const glm::vec4& color = glm::vec4(1, 1, 1, 1), const glm::vec2& anchor = glm::vec2(0, 0));
- void add(const xd::texture::ptr texture, const xd::rect& src, float x, float y, float rotation, const glm::vec2& scale,
- const glm::vec4& color = glm::vec4(1, 1, 1, 1), const glm::vec2& anchor = glm::vec2(0, 0));
+ void add(const texture::ptr texture, const rect& src, float x, float y,
+ const vec4& color = vec4(1, 1, 1, 1), const vec2& origin = vec2(0, 0));
+ void add(const texture::ptr texture, const rect& src, float x, float y, float rotation, float scale,
+ const vec4& color = vec4(1, 1, 1, 1), const vec2& origin = vec2(0, 0));
+ void add(const texture::ptr texture, const rect& src, float x, float y, float rotation, const vec2& scale,
+ const vec4& color = vec4(1, 1, 1, 1), const vec2& origin = vec2(0, 0));
private:
- transform_geometry& m_geometry_pipeline;
detail::sprite_batch_data *m_data;
float m_scale;
};
@@ -1,7 +1,7 @@
#ifndef H_XD_GRAPHICS_STOCK_TEXT_FORMATTER
#define H_XD_GRAPHICS_STOCK_TEXT_FORMATTER
-#include <xd/vendor/glm/glm.hpp>
+#include <xd/glm.hpp>
#include <string>
#include <ctime>
#include <unordered_map>
@@ -3,6 +3,11 @@
#include <xd/graphics/detail/text_formatter.hpp>
+#include <xd/glm.hpp>
+#include <xd/graphics/exceptions.hpp>
+#include <xd/graphics/font.hpp>
+#include <xd/graphics/shader_program.hpp>
+#include <xd/vendor/utf8.h>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <boost/noncopyable.hpp>
@@ -12,11 +17,6 @@
#include <string>
#include <functional>
#include <unordered_map>
-#include <xd/vendor/glm/glm.hpp>
-#include <xd/graphics/exceptions.hpp>
-#include <xd/graphics/font.hpp>
-#include <xd/graphics/shader_program.hpp>
-#include <xd/vendor/utf8.h>
#ifndef XD_STATIC
// disable warnings about nonstandard extension
@@ -1,7 +1,7 @@
#ifndef H_XD_GRAPHICS_TYPES
#define H_XD_GRAPHICS_TYPES
-#include <xd/vendor/glm/glm.hpp>
+#include <xd/glm.hpp>
namespace xd
{
@@ -15,11 +15,15 @@ namespace xd
: x(x), y(y), w(w), h(h)
{}
- explicit rect(glm::vec2 xy, glm::vec2 wh)
+ explicit rect(const glm::vec2& xy, const glm::vec2& wh)
: x(xy.x), y(xy.y), w(wh.x), h(wh.y)
{}
- explicit rect(glm::vec4 rect)
+ explicit rect(const glm::vec2& xy, float w, float h)
+ : x(xy.x), y(xy.y), w(w), h(h)
+ {}
+
+ explicit rect(const glm::vec4& rect)
: x(rect[0]), y(rect[1]), w(rect[2]), h(rect[3])
{}
@@ -32,6 +36,17 @@ namespace xd
, h(static_cast<float>(h))
{}
+ // check if two rects intersect
+ bool intersects(const rect& other)
+ {
+ return (
+ x < (other.x+other.w) &&
+ (x+w) > other.x &&
+ y < (other.y+other.h) &&
+ (y+h) > other.y
+ );
+ }
+
float x, y, w, h;
};
}
View
@@ -1,6 +1,8 @@
#ifndef H_XD_LUA
#define H_XD_LUA
+#include <xd/config.hpp>
+#include <xd/factory.hpp>
#include <xd/lua/config.hpp>
#include <xd/lua/types.hpp>
#include <xd/lua/exceptions.hpp>
@@ -15,7 +15,6 @@
// classes/functions from the library
#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef XD_LUA_EXPORT
- #define LUABIND_BUILDING
#ifdef XD_STATIC
#define XD_LUA_API extern
#else
View
@@ -2,6 +2,7 @@
#define H_XD_SYSTEM
#include <xd/config.hpp>
+#include <xd/factory.hpp>
#include <xd/system/input.hpp>
#include <xd/system/exceptions.hpp>
#include <xd/system/window.hpp>
@@ -1,15 +1,18 @@
#ifndef H_XD_SYSTEM_WINDOW
#define H_XD_SYSTEM_WINDOW
-#include <string>
+#include <xd/ref_counted.hpp>
+#include <xd/system/window_options.hpp>
#include <xd/system/input.hpp>
#include <xd/graphics/transform_geometry.hpp>
#include <xd/event_bus.hpp>
#include <boost/noncopyable.hpp>
+#include <boost/intrusive_ptr.hpp>
#include <boost/cstdint.hpp>
#include <unordered_map>
#include <unordered_set>
#include <functional>
+#include <string>
#if defined(_MSC_VER) && !defined(XD_STATIC)
// disable warning about boost::noncopyable not being dll-exportable
@@ -19,15 +22,16 @@
namespace xd
{
- class XD_API window : public boost::noncopyable
+ class XD_API window : public xd::ref_counted, public boost::noncopyable
{
public:
// typedefs
+ typedef boost::intrusive_ptr<window> ptr;
typedef event_bus<input_args>::callback_t input_event_callback_t;
typedef std::function<void ()> tick_callback_t;
// public interface
- window(const std::string& title, int width, int height);
+ window(const std::string& title, int width, int height, const window_options& options = window_options());
virtual ~window();
void update();
Oops, something went wrong.

0 comments on commit adcd053

Please sign in to comment.