aboutsummaryrefslogtreecommitdiff
path: root/src/libjin
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin')
-rw-r--r--src/libjin/core/core.h6
-rw-r--r--src/libjin/fs/buffer.h12
-rw-r--r--src/libjin/fs/fs.h7
-rw-r--r--src/libjin/input/input.h8
-rw-r--r--src/libjin/jin.h12
-rw-r--r--src/libjin/render/canvas.cpp2
-rw-r--r--src/libjin/render/color.h2
-rw-r--r--src/libjin/render/drawable.cpp3
-rw-r--r--src/libjin/render/graphics.cpp2
-rw-r--r--src/libjin/render/image.cpp2
-rw-r--r--src/libjin/render/jsl.cpp2
-rw-r--r--src/libjin/render/render.h14
-rw-r--r--src/libjin/render/window.cpp2
-rw-r--r--src/libjin/utils/endian.h26
-rw-r--r--src/libjin/utils/macros.h6
-rw-r--r--src/libjin/utils/math.h8
-rw-r--r--src/libjin/utils/matrix.cpp177
-rw-r--r--src/libjin/utils/matrix.h153
-rw-r--r--src/libjin/utils/utils.h16
19 files changed, 448 insertions, 12 deletions
diff --git a/src/libjin/core/core.h b/src/libjin/core/core.h
new file mode 100644
index 0000000..dd902b4
--- /dev/null
+++ b/src/libjin/core/core.h
@@ -0,0 +1,6 @@
+#ifndef __JIN_CORE_H
+#define __JIN_CORE_H
+
+#include "game.h"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/fs/buffer.h b/src/libjin/fs/buffer.h
index d727d84..dfdea21 100644
--- a/src/libjin/fs/buffer.h
+++ b/src/libjin/fs/buffer.h
@@ -1,3 +1,6 @@
+#ifndef __JIN_BUFFER_H
+#define __JIN_BUFFER_H
+
#include <string.h>
namespace jin
@@ -5,9 +8,6 @@ namespace jin
namespace fs
{
- /**
- * A file data buffer.
- */
class Buffer
{
public:
@@ -30,7 +30,7 @@ namespace fs
public:
- // data position in memory
+ // data position in memory
void* data;
// data buffer size
@@ -39,4 +39,6 @@ namespace fs
};
}
-} \ No newline at end of file
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/fs/fs.h b/src/libjin/fs/fs.h
new file mode 100644
index 0000000..6fbf33f
--- /dev/null
+++ b/src/libjin/fs/fs.h
@@ -0,0 +1,7 @@
+#ifndef __JIN_FS_H
+#define __JIN_FS_H
+
+#include "buffer.h"
+#include "filesystem.h"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/input/input.h b/src/libjin/input/input.h
new file mode 100644
index 0000000..217edd2
--- /dev/null
+++ b/src/libjin/input/input.h
@@ -0,0 +1,8 @@
+#ifndef __JIN_INPUT_H
+#define __JIN_INPUT_H
+
+#include "event.h"
+#include "keyboard.h"
+#include "mouse.h"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/jin.h b/src/libjin/jin.h
new file mode 100644
index 0000000..95895f7
--- /dev/null
+++ b/src/libjin/jin.h
@@ -0,0 +1,12 @@
+#ifndef __JIN_H
+#define __JIN_H
+
+#include "utils/utils.h"
+#include "audio/audio.h"
+#include "core/core.h"
+#include "fs/fs.h"
+#include "input/input.h"
+#include "net/net.h"
+#include "render/render.h"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/render/canvas.cpp b/src/libjin/render/canvas.cpp
index 494b0fa..376c076 100644
--- a/src/libjin/render/canvas.cpp
+++ b/src/libjin/render/canvas.cpp
@@ -1,4 +1,4 @@
-#include "utils/macros.h"
+#include "../utils/macros.h"
#include "canvas.h"
#include "window.h"
diff --git a/src/libjin/render/color.h b/src/libjin/render/color.h
index dfb02e1..6f34b4a 100644
--- a/src/libjin/render/color.h
+++ b/src/libjin/render/color.h
@@ -3,7 +3,7 @@
*/
#ifndef __JIN_COLOR_H
#define __JIN_COLOR_H
-#include "utils/endian.h"
+#include "../utils/endian.h"
namespace jin
{
diff --git a/src/libjin/render/drawable.cpp b/src/libjin/render/drawable.cpp
index 45d6044..7acd3bf 100644
--- a/src/libjin/render/drawable.cpp
+++ b/src/libjin/render/drawable.cpp
@@ -1,6 +1,7 @@
#include "drawable.h"
-#include "utils/matrix.h"
+#include "../utils/matrix.h"
#include <stdlib.h>
+
namespace jin
{
namespace render
diff --git a/src/libjin/render/graphics.cpp b/src/libjin/render/graphics.cpp
index 15d8a9c..254b6a4 100644
--- a/src/libjin/render/graphics.cpp
+++ b/src/libjin/render/graphics.cpp
@@ -1,5 +1,5 @@
#include "graphics.h"
-#include "utils/math.h"
+#include "../utils/math.h"
#include <string>
namespace jin
{
diff --git a/src/libjin/render/image.cpp b/src/libjin/render/image.cpp
index ac5947a..b27b9a6 100644
--- a/src/libjin/render/image.cpp
+++ b/src/libjin/render/image.cpp
@@ -1,6 +1,6 @@
#include "image.h"
#include "3rdparty/stb/stb_image.h"
-#include "utils/utils.h"
+#include "../utils/utils.h"
namespace jin
{
namespace render
diff --git a/src/libjin/render/jsl.cpp b/src/libjin/render/jsl.cpp
index 6fcee53..1fb4482 100644
--- a/src/libjin/render/jsl.cpp
+++ b/src/libjin/render/jsl.cpp
@@ -1,4 +1,4 @@
-#include "utils/macros.h"
+#include "../utils/macros.h"
#include "jsl.h"
namespace jin
{
diff --git a/src/libjin/render/render.h b/src/libjin/render/render.h
new file mode 100644
index 0000000..8939480
--- /dev/null
+++ b/src/libjin/render/render.h
@@ -0,0 +1,14 @@
+#ifndef __JIN_RENDER_H
+#define __JIN_RENDER_H
+
+#include "canvas.h"
+#include "color.h"
+#include "font.h"
+#include "graphics.h"
+#include "image.h"
+#include "jsl.h"
+#include "quad.h"
+#include "rect.h"
+#include "window.h"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/render/window.cpp b/src/libjin/render/window.cpp
index 20a6adc..e5d26a7 100644
--- a/src/libjin/render/window.cpp
+++ b/src/libjin/render/window.cpp
@@ -1,7 +1,7 @@
#include "window.h"
#include "3rdparty/GLee/GLee.h"
#include "canvas.h"
-#include "utils/macros.h"
+#include "../utils/macros.h"
namespace jin
{
namespace render
diff --git a/src/libjin/utils/endian.h b/src/libjin/utils/endian.h
new file mode 100644
index 0000000..df28ddb
--- /dev/null
+++ b/src/libjin/utils/endian.h
@@ -0,0 +1,26 @@
+/**
+*
+*/
+#ifndef JIN_LIL_ENDIAN && JIN_BIG_ENDIAN
+
+#define JIN_LIL_ENDIAN 2
+#define JIN_BIG_ENDIAN 4
+
+#endif
+
+#ifndef JIN_BYTEORDER
+#ifdef __linux__
+#include <endian.h>
+#define JIN_BYTEORDER __BYTE_ORDER
+#else /* __linux__ */
+#if defined(__hppa__) || \
+ defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
+ (defined(__MIPS__) && defined(__MISPEB__)) || \
+ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
+ defined(__sparc__)
+#define JIN_BYTEORDER JIN_BIG_ENDIAN
+#else
+#define JIN_BYTEORDER JIN_LIL_ENDIAN
+#endif
+#endif /* __linux__ */
+#endif /* !SDL_BYTEORDER */ \ No newline at end of file
diff --git a/src/libjin/utils/macros.h b/src/libjin/utils/macros.h
new file mode 100644
index 0000000..4f739a9
--- /dev/null
+++ b/src/libjin/utils/macros.h
@@ -0,0 +1,6 @@
+#ifndef __JIN_MACROS_H
+#define __JIN_MACROS_H
+
+#define shared
+
+#endif \ No newline at end of file
diff --git a/src/libjin/utils/math.h b/src/libjin/utils/math.h
new file mode 100644
index 0000000..5e44ce7
--- /dev/null
+++ b/src/libjin/utils/math.h
@@ -0,0 +1,8 @@
+#ifndef __JIN_UTILS_MATH_H
+#define __JIN_UTILS_MATH_H
+
+#include <math.h>
+
+#define PI 3.1415926f
+
+#endif \ No newline at end of file
diff --git a/src/libjin/utils/matrix.cpp b/src/libjin/utils/matrix.cpp
new file mode 100644
index 0000000..b970ec0
--- /dev/null
+++ b/src/libjin/utils/matrix.cpp
@@ -0,0 +1,177 @@
+#include "Matrix.h"
+
+#include <cstring> // memcpy
+#include <cmath>
+
+namespace jin
+{
+namespace util
+{
+
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ Matrix::Matrix()
+ {
+ setIdentity();
+ }
+
+ Matrix::~Matrix()
+ {
+ }
+
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ Matrix Matrix::operator * (const Matrix & m) const
+ {
+ Matrix t;
+
+ t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]);
+ t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]);
+ t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]);
+ t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]);
+
+ t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]);
+ t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]);
+ t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]);
+ t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]);
+
+ t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]);
+ t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]);
+ t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]);
+ t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]);
+
+ t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]);
+ t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]);
+ t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]);
+ t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]);
+
+ return t;
+ }
+
+ void Matrix::operator *= (const Matrix & m)
+ {
+ Matrix t = (*this) * m;
+ memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16);
+ }
+
+ const float * Matrix::getElements() const
+ {
+ return e;
+ }
+
+ void Matrix::setIdentity()
+ {
+ memset(e, 0, sizeof(float) * 16);
+ e[0] = e[5] = e[10] = e[15] = 1;
+ }
+
+ void Matrix::setTranslation(float x, float y)
+ {
+ setIdentity();
+ e[12] = x;
+ e[13] = y;
+ }
+
+ void Matrix::setRotation(float rad)
+ {
+ setIdentity();
+ float c = cos(rad), s = sin(rad);
+ e[0] = c; e[4] = -s;
+ e[1] = s; e[5] = c;
+ }
+
+ void Matrix::setScale(float sx, float sy)
+ {
+ setIdentity();
+ e[0] = sx;
+ e[5] = sy;
+ }
+
+ void Matrix::setShear(float kx, float ky)
+ {
+ setIdentity();
+ e[1] = ky;
+ e[4] = kx;
+ }
+
+ void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy)
+ {
+ memset(e, 0, sizeof(float) * 16); // zero out matrix
+ float c = cos(angle), s = sin(angle);
+ // matrix multiplication carried out on paper:
+ // |1 x| |c -s | |sx | |1 -ox|
+ // | 1 y| |s c | | sy | | 1 -oy|
+ // | 1 | | 1 | | 1 | | 1 |
+ // | 1| | 1| | 1| | 1 |
+ // move rotate scale origin
+ e[10] = e[15] = 1.0f;
+ e[0] = c * sx ; // = a
+ e[1] = s * sx ; // = b
+ e[4] = - s * sy; // = c
+ e[5] = c * sy; // = d
+ e[12] = x - ox * e[0] - oy * e[4];
+ e[13] = y - ox * e[1] - oy * e[5];
+ }
+
+ void Matrix::translate(float x, float y)
+ {
+ Matrix t;
+ t.setTranslation(x, y);
+ this->operator *=(t);
+ }
+
+ void Matrix::rotate(float rad)
+ {
+ Matrix t;
+ t.setRotation(rad);
+ this->operator *=(t);
+ }
+
+ void Matrix::scale(float sx, float sy)
+ {
+ Matrix t;
+ t.setScale(sx, sy);
+ this->operator *=(t);
+ }
+
+ void Matrix::shear(float kx, float ky)
+ {
+ Matrix t;
+ t.setShear(kx, ky);
+ this->operator *=(t);
+ }
+
+ // | x |
+ // | y |
+ // | 0 |
+ // | 1 |
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ void Matrix::transform(vertex * dst, const vertex * src, int size) const
+ {
+ for (int i = 0; i<size; ++i)
+ {
+ // Store in temp variables in case src = dst
+ float x = (e[0] * src[i].x) + (e[4] * src[i].y) + (0) + (e[12]);
+ float y = (e[1] * src[i].x) + (e[5] * src[i].y) + (0) + (e[13]);
+
+ dst[i].x = x;
+ dst[i].y = y;
+ }
+ }
+
+}
+} \ No newline at end of file
diff --git a/src/libjin/utils/matrix.h b/src/libjin/utils/matrix.h
new file mode 100644
index 0000000..51d7980
--- /dev/null
+++ b/src/libjin/utils/matrix.h
@@ -0,0 +1,153 @@
+#ifndef __JIN_MATRIX_H
+#define __JIN_MATRIX_H
+#include <math.h>
+namespace jin
+{
+namespace util
+{
+
+ struct vertex
+ {
+ unsigned char r, g, b, a;
+ float x, y;
+ float s, t;
+ };
+ /**
+ * This class is the basis for all transformations in LOVE. Althought not
+ * really needed for 2D, it contains 4x4 elements to be compatible with
+ * OpenGL without conversions.
+ **/
+ class Matrix
+ {
+ private:
+
+ /**
+ * | e0 e4 e8 e12 |
+ * | e1 e5 e9 e13 |
+ * | e2 e6 e10 e14 |
+ * | e3 e7 e11 e15 |
+ **/
+ float e[16];
+
+ public:
+
+ /**
+ * Creates a new identity matrix.
+ **/
+ Matrix();
+
+ /**
+ * Destructor.
+ **/
+ ~Matrix();
+
+ /**
+ * Multiplies this Matrix with another Matrix, changing neither.
+ * @param m The Matrix to multiply with this Matrix.
+ * @return The combined matrix.
+ **/
+ Matrix operator * (const Matrix & m) const;
+
+ /**
+ * Multiplies a Matrix into this Matrix.
+ * @param m The Matrix to combine into this Matrix.
+ **/
+ void operator *= (const Matrix & m);
+
+ /**
+ * Gets a pointer to the 16 array elements.
+ * @return The array elements.
+ **/
+ const float * getElements() const;
+
+ /**
+ * Resets this Matrix to the identity matrix.
+ **/
+ void setIdentity();
+
+ /**
+ * Resets this Matrix to a translation.
+ * @param x Translation along x-axis.
+ * @param y Translation along y-axis.
+ **/
+ void setTranslation(float x, float y);
+
+ /**
+ * Resets this Matrix to a rotation.
+ * @param r The angle in radians.
+ **/
+ void setRotation(float r);
+
+ /**
+ * Resets this Matrix to a scale transformation.
+ * @param sx Scale factor along the x-axis.
+ * @param sy Scale factor along the y-axis.
+ **/
+ void setScale(float sx, float sy);
+
+ /**
+ * Resets this Matrix to a shear transformation.
+ * @param kx Shear along x-axis.
+ * @param ky Shear along y-axis.
+ **/
+ void setShear(float kx, float ky);
+
+ /**
+ * Creates a transformation with a certain position, orientation, scale
+ * and offset. Perfect for Drawables -- what a coincidence!
+ *
+ * @param x The translation along the x-axis.
+ * @param y The translation along the y-axis.
+ * @param angle The rotation (rad) around the center with offset (ox,oy).
+ * @param sx Scale along x-axis.
+ * @param sy Scale along y-axis.
+ * @param ox The offset for rotation along the x-axis.
+ * @param oy The offset for rotation along the y-axis.
+ * @param kx Shear along x-axis
+ * @param ky Shear along y-axis
+ **/
+ void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy);
+
+ /**
+ * Multiplies this Matrix with a translation.
+ * @param x Translation along x-axis.
+ * @param y Translation along y-axis.
+ **/
+ void translate(float x, float y);
+
+ /**
+ * Multiplies this Matrix with a rotation.
+ * @param r Angle in radians.
+ **/
+ void rotate(float r);
+
+ /**
+ * Multiplies this Matrix with a scale transformation.
+ * @param sx Scale factor along the x-axis.
+ * @param sy Scale factor along the y-axis.
+ **/
+ void scale(float sx, float sy);
+
+ /**
+ * Multiplies this Matrix with a shear transformation.
+ * @param kx Shear along the x-axis.
+ * @param ky Shear along the y-axis.
+ **/
+ void shear(float kx, float ky);
+
+ /**
+ * Transforms an array of vertices by this Matrix. The sources and
+ * destination arrays may be the same.
+ *
+ * @param dst Storage for the transformed vertices.
+ * @param src The source vertices.
+ * @param size The number of vertices.
+ **/
+ void transform(vertex * dst, const vertex * src, int size) const;
+
+ };
+
+}
+}
+
+#endif
diff --git a/src/libjin/utils/utils.h b/src/libjin/utils/utils.h
new file mode 100644
index 0000000..45c8ff9
--- /dev/null
+++ b/src/libjin/utils/utils.h
@@ -0,0 +1,16 @@
+#ifndef __JIN_UTILS_H
+#define __JIN_UTILS_H
+
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#define clamp(a, mi,ma) min(max(a,mi),ma)
+
+#define within(a,min,max) (a >= min && a <= max)
+#define without(a,min,max) (a < min || a > max)
+
+#include "macros.h"
+#include "endian.h"
+#include "math.h"
+#include "matrix.h"
+
+#endif \ No newline at end of file