aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-12 21:04:39 +0800
committerchai <chaifix@163.com>2018-09-12 21:04:39 +0800
commit85dca918d254d2eaca6864d76b788a8023aad547 (patch)
tree10cae96f6d01ddc6c846318b24db26d75a63bb91
parent6c4ea0d2270630ca44e5e078d16df0aab684688f (diff)
*update
-rw-r--r--libjin/3rdparty/smount/smount.c31
-rw-r--r--libjin/3rdparty/smount/smount.h17
-rw-r--r--libjin/3rdparty/stb/stb_image.h2
-rw-r--r--libjin/3rdparty/stb/stb_truetype.h476
-rw-r--r--libjin/Audio/Audio.cpp8
-rw-r--r--libjin/Audio/Audio.h19
-rw-r--r--libjin/Audio/SDL/SDLAudio.cpp10
-rw-r--r--libjin/Audio/SDL/SDLAudio.h25
-rw-r--r--libjin/Audio/SDL/SDLSource.cpp8
-rw-r--r--libjin/Audio/SDL/SDLSource.h39
-rw-r--r--libjin/Audio/Source.cpp9
-rw-r--r--libjin/Audio/Source.h18
-rw-r--r--libjin/Common/Array.hpp83
-rw-r--r--libjin/Common/Object.h6
-rw-r--r--libjin/Common/Singleton.hpp9
-rw-r--r--libjin/Common/StringMap.hpp6
-rw-r--r--libjin/Common/Subsystem.hpp7
-rw-r--r--libjin/Common/common.h6
-rw-r--r--libjin/Common/utf8.cpp4
-rw-r--r--libjin/Common/utf8.h12
-rw-r--r--libjin/Core/Core.h4
-rw-r--r--libjin/Core/Game.h6
-rw-r--r--libjin/Debug/Debug.h6
-rw-r--r--libjin/Debug/Log.h14
-rw-r--r--libjin/Filesystem/Buffer.h49
-rw-r--r--libjin/Filesystem/Filesystem.cpp19
-rw-r--r--libjin/Filesystem/Filesystem.h35
-rw-r--r--libjin/Graphics/Bitmap.cpp141
-rw-r--r--libjin/Graphics/Bitmap.h49
-rw-r--r--libjin/Graphics/Canvas.cpp115
-rw-r--r--libjin/Graphics/Canvas.h30
-rw-r--r--libjin/Graphics/Color.cpp17
-rw-r--r--libjin/Graphics/Color.h78
-rw-r--r--libjin/Graphics/Drawable.cpp46
-rw-r--r--libjin/Graphics/Drawable.h57
-rw-r--r--libjin/Graphics/Font.cpp236
-rw-r--r--libjin/Graphics/Font.h109
-rw-r--r--libjin/Graphics/Graphics.h13
-rw-r--r--libjin/Graphics/JSL.cpp159
-rw-r--r--libjin/Graphics/Shader.cpp222
-rw-r--r--libjin/Graphics/Shader.h (renamed from libjin/Graphics/JSL.h)51
-rw-r--r--libjin/Graphics/Shapes.cpp37
-rw-r--r--libjin/Graphics/Shapes.h32
-rw-r--r--libjin/Graphics/Texture.cpp102
-rw-r--r--libjin/Graphics/Texture.h31
-rw-r--r--libjin/Graphics/Window.cpp34
-rw-r--r--libjin/Graphics/Window.h30
-rw-r--r--libjin/Graphics/base.shader.h34
-rw-r--r--libjin/Input/Event.cpp2
-rw-r--r--libjin/Input/Event.h38
-rw-r--r--libjin/Input/Input.h5
-rw-r--r--libjin/Input/Joypad.h44
-rw-r--r--libjin/Input/Keyboard.h12
-rw-r--r--libjin/Input/Mouse.cpp13
-rw-r--r--libjin/Input/Mouse.h22
-rw-r--r--libjin/Math/Math.h8
-rw-r--r--libjin/Math/Matrix.cpp4
-rw-r--r--libjin/Math/Matrix.h10
-rw-r--r--libjin/Math/Quad.h10
-rw-r--r--libjin/Math/Vector.cpp2
-rw-r--r--libjin/Math/Vector.h14
-rw-r--r--libjin/Math/Vector2.hpp39
-rw-r--r--libjin/Math/Vector3.hpp41
-rw-r--r--libjin/Math/Vector4.hpp44
-rw-r--r--libjin/Math/constant.h4
-rw-r--r--libjin/Net/Net.cpp6
-rw-r--r--libjin/Net/Net.h17
-rw-r--r--libjin/Net/Socket.cpp26
-rw-r--r--libjin/Net/Socket.h14
-rw-r--r--libjin/Thread/Thread.cpp36
-rw-r--r--libjin/Thread/Thread.h31
-rw-r--r--libjin/Time/Timer.cpp8
-rw-r--r--libjin/Time/Timer.h19
-rw-r--r--libjin/Utils/endian.h14
-rw-r--r--libjin/Utils/macros.h4
-rw-r--r--libjin/Utils/utils.h4
-rw-r--r--libjin/jin.h20
-rw-r--r--libjin/modules.h70
78 files changed, 1900 insertions, 1232 deletions
diff --git a/libjin/3rdparty/smount/smount.c b/libjin/3rdparty/smount/smount.c
index 2b4e9b9..6214800 100644
--- a/libjin/3rdparty/smount/smount.c
+++ b/libjin/3rdparty/smount/smount.c
@@ -44,7 +44,7 @@ smtShared* smtnewshared()
/**
* Concatenate strings together.
*/
-char *concat(const char *str, ...) {
+char* concat(const char *str, ...) {
va_list args;
const char *s;
// Get len
@@ -66,7 +66,7 @@ char *concat(const char *str, ...) {
return res;
}
-static int isdir(const char *path) {
+static int isdir(const char* path) {
struct stat s;
int res = stat(path, &s);
return S_ISDIR(s.st_mode);
@@ -75,12 +75,8 @@ static int isdir(const char *path) {
int smtmount(smtShared* S, const char *path)
{
if (!isdir(path))
- {
return SMT_INVALIDMOUNT;
- }
-
S->mount = smtnewpath(PATH_DIR, path, 0);
-
return SMT_SUCCESS;
}
@@ -132,33 +128,22 @@ const char* smterrstr(int e)
{
switch (e)
{
- case SMT_INVALIDMOUNT: return "invalid mount directory";
- default: return "unknown error";
+ case SMT_INVALIDMOUNT: return "invalid mount directory";
+ default: return "unknown error";
}
}
void *smtread(smtShared* S, const char *path, unsigned int *size)
{
- if (!smtisreg(S, path)) return 0;
- int fr = 0;
- if (size == 0)
- {
- fr = 1;
- size = (unsigned int*)malloc(sizeof(unsigned int));
- }
+ if (size == NULL) return NULL;
+ if (!smtisreg(S, path)) return NULL;
char *r = concat(S->mount->path, "/", path, NULL);
if (!r)
- {
- free(size);
return NULL;
- }
FILE *fp = fopen(r, "rb");
free(r);
if (!fp)
- {
- free(size);
return 0;
- }
/* Get file size */
fseek(fp, 0, SEEK_END);
*size = ftell(fp);
@@ -167,13 +152,13 @@ void *smtread(smtShared* S, const char *path, unsigned int *size)
char *res = (char*)malloc(*size + 1);
if (!res) return NULL;
res[*size] = '\0';
- if (fread(res, 1, *size, fp) != *size) {
+ if (fread(res, 1, *size, fp) != *size)
+ {
free(res);
fclose(fp);
return NULL;
}
fclose(fp);
- if (fr) free(size);
return res;
}
diff --git a/libjin/3rdparty/smount/smount.h b/libjin/3rdparty/smount/smount.h
index c0836a7..0f8f774 100644
--- a/libjin/3rdparty/smount/smount.h
+++ b/libjin/3rdparty/smount/smount.h
@@ -37,53 +37,38 @@ typedef struct smtShared
}smtShared;
smtShared* smtnewshared();
-
void smtcloseshared(smtShared* S);
-
/**
* Get error string with given error code.
*/
const char *smterrstr(int err);
-
/**
* Mount a sub file system.
*/
int smtmount(smtShared* S, const char *path);
-
/**
* Free mount
*/
void smtunmount(smtShared* S);
-
int smtexists(smtShared* S, const char *path);
-
/**
* Get size of a file.
*/
int smtsize(smtShared* S, const char *path);
-
/**
* Can only read files under root directory.
*/
-void *smtread(smtShared* S, const char *path, unsigned int *size);
-
+void* smtread(smtShared* S, const char *path, unsigned int *size);
int smtisdir(smtShared* S, const char *path);
-
int smtisreg(smtShared* S, const char *path);
-
/**
* List all folders and files inside current mount directory.
*/
smtPath *smtlist(smtShared*S, const char *path);
-
void smtfreelist(smtPath* S);
-
int smtwrite(smtShared* S, const char *path, const void *data, int size);
-
void smtdelete(smtShared* S, const char *path);
-
int smtmkdir(smtShared* S, const char *path);
-
char* smtfullpath(smtShared* S, const char* path);
#endif \ No newline at end of file
diff --git a/libjin/3rdparty/stb/stb_image.h b/libjin/3rdparty/stb/stb_image.h
index 72e0ae6..9624869 100644
--- a/libjin/3rdparty/stb/stb_image.h
+++ b/libjin/3rdparty/stb/stb_image.h
@@ -22,7 +22,7 @@
JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
PNG 1/2/4/8/16-bit-per-channel
-
+
TGA (not sure what subset, if a subset)
BMP non-1bpp, non-RLE
PSD (composited view only, no extra channels, 8/16 bit-per-channel)
diff --git a/libjin/3rdparty/stb/stb_truetype.h b/libjin/3rdparty/stb/stb_truetype.h
index cb8f4c2..927ee21 100644
--- a/libjin/3rdparty/stb/stb_truetype.h
+++ b/libjin/3rdparty/stb/stb_truetype.h
@@ -1,4 +1,4 @@
-// stb_truetype.h - v1.16 - public domain
+// stb_truetype.h - v1.19 - public domain
// authored from 2009-2016 by Sean Barrett / RAD Game Tools
//
// This library processes TrueType files:
@@ -22,39 +22,36 @@
// Mikko Mononen: compound shape support, more cmap formats
// Tor Andersson: kerning, subpixel rendering
// Dougall Johnson: OpenType / Type 2 font handling
+// Daniel Ribeiro Maciel: basic GPOS-based kerning
//
// Misc other:
// Ryan Gordon
// Simon Glass
// github:IntellectualKitty
+// Imanol Celaya
+// Daniel Ribeiro Maciel
//
// Bug/warning reports/fixes:
-// "Zer" on mollyrocket
-// Cass Everitt
-// stoiko (Haemimont Games)
-// Brian Hook
-// Walter van Niftrik
-// David Gow
-// David Given
-// Ivan-Assen Ivanov
-// Anthony Pesch
-// Johan Duparc
-// Hou Qiming
-// Fabian "ryg" Giesen
-// Martins Mozeiko
-// Cap Petschulat
-// Omar Cornut
-// github:aloucks
-// Peter LaValle
-// Sergey Popov
-// Giumo X. Clanjor
-// Higor Euripedes
-// Thomas Fields
-// Derek Vinyard
-// Cort Stratton
-//
+// "Zer" on mollyrocket Fabian "ryg" Giesen
+// Cass Everitt Martins Mozeiko
+// stoiko (Haemimont Games) Cap Petschulat
+// Brian Hook Omar Cornut
+// Walter van Niftrik github:aloucks
+// David Gow Peter LaValle
+// David Given Sergey Popov
+// Ivan-Assen Ivanov Giumo X. Clanjor
+// Anthony Pesch Higor Euripedes
+// Johan Duparc Thomas Fields
+// Hou Qiming Derek Vinyard
+// Rob Loach Cort Stratton
+// Kenney Phillis Jr. github:oyvindjam
+// Brian Costabile github:vassvik
+//
// VERSION HISTORY
//
+// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod
+// 1.18 (2018-01-29) add missing function
+// 1.17 (2017-07-23) make more arguments const; doc fix
// 1.16 (2017-07-12) SDF support
// 1.15 (2017-03-03) make more arguments const
// 1.14 (2017-01-16) num-fonts-in-TTC function
@@ -94,7 +91,7 @@
// Improved 3D API (more shippable):
// #include "stb_rect_pack.h" -- optional, but you really want it
// stbtt_PackBegin()
-// stbtt_PackSetOversample() -- for improved quality on small fonts
+// stbtt_PackSetOversampling() -- for improved quality on small fonts
// stbtt_PackFontRanges() -- pack and renders
// stbtt_PackEnd()
// stbtt_GetPackedQuad()
@@ -112,6 +109,7 @@
// Character advance/positioning
// stbtt_GetCodepointHMetrics()
// stbtt_GetFontVMetrics()
+// stbtt_GetFontVMetricsOS2()
// stbtt_GetCodepointKernAdvance()
//
// Starting with version 1.06, the rasterizer was replaced with a new,
@@ -167,7 +165,7 @@
// measurement for describing font size, defined as 72 points per inch.
// stb_truetype provides a point API for compatibility. However, true
// "per inch" conventions don't make much sense on computer displays
-// since they different monitors have different number of pixels per
+// since different monitors have different number of pixels per
// inch. For example, Windows traditionally uses a convention that
// there are 96 pixels per inch, thus making 'inch' measurements have
// nothing to do with inches, and thus effectively defining a point to
@@ -177,6 +175,39 @@
// for non-commercial fonts, thus making fonts scaled in points
// according to the TrueType spec incoherently sized in practice.
//
+// DETAILED USAGE:
+//
+// Scale:
+// Select how high you want the font to be, in points or pixels.
+// Call ScaleForPixelHeight or ScaleForMappingEmToPixels to compute
+// a scale factor SF that will be used by all other functions.
+//
+// Baseline:
+// You need to select a y-coordinate that is the baseline of where
+// your text will appear. Call GetFontBoundingBox to get the baseline-relative
+// bounding box for all characters. SF*-y0 will be the distance in pixels
+// that the worst-case character could extend above the baseline, so if
+// you want the top edge of characters to appear at the top of the
+// screen where y=0, then you would set the baseline to SF*-y0.
+//
+// Current point:
+// Set the current point where the first character will appear. The
+// first character could extend left of the current point; this is font
+// dependent. You can either choose a current point that is the leftmost
+// point and hope, or add some padding, or check the bounding box or
+// left-side-bearing of the first character to be displayed and set
+// the current point based on that.
+//
+// Displaying a character:
+// Compute the bounding box of the character. It will contain signed values
+// relative to <current_point, baseline>. I.e. if it returns x0,y0,x1,y1,
+// then the character should be displayed in the rectangle from
+// <current_point+SF*x0, baseline+SF*y0> to <current_point+SF*x1,baseline+SF*y1).
+//
+// Advancing for the next character:
+// Call GlyphHMetrics, and compute 'current_point += SF * advance'.
+//
+//
// ADVANCED USAGE
//
// Quality:
@@ -258,7 +289,7 @@ void my_stbtt_initfont(void)
glGenTextures(1, &ftex);
glBindTexture(GL_TEXTURE_2D, ftex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512, 512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap);
-
+ // can free temp_bitmap at this point
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
@@ -362,7 +393,7 @@ int main(int arg, char **argv)
// "alpha blend" that into the working buffer
xpos += (advance * scale);
if (text[ch + 1])
- xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch], text[ch + 1]);
+ xpos += scale * stbtt_GetCodepointKernAdvance(&font, text[ch], text[ch + 1]);
++ch;
}
@@ -383,7 +414,8 @@ int main(int arg, char **argv)
//// INTEGRATION WITH YOUR CODEBASE
////
//// The following sections allow you to supply alternate definitions
-//// of C library functions used by stb_truetype.
+//// of C library functions used by stb_truetype, e.g. if you don't
+//// link with the C runtime library.
#ifdef STB_TRUETYPE_IMPLEMENTATION
// #define your own (u)stbtt_int8/16/32 before including to override this
@@ -399,7 +431,7 @@ typedef signed int stbtt_int32;
typedef char stbtt__check_size32[sizeof(stbtt_int32) == 4 ? 1 : -1];
typedef char stbtt__check_size16[sizeof(stbtt_int16) == 2 ? 1 : -1];
-// #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h
+// e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h
#ifndef STBTT_ifloor
#include <math.h>
#define STBTT_ifloor(x) ((int) floor(x))
@@ -412,15 +444,15 @@ typedef char stbtt__check_size16[sizeof(stbtt_int16) == 2 ? 1 : -1];
#define STBTT_pow(x,y) pow(x,y)
#endif
-#ifndef STBTT_cos
+#ifndef STBTT_fmod
#include <math.h>
-#define STBTT_cos(x) cos(x)
-#define STBTT_acos(x) acos(x)
+#define STBTT_fmod(x,y) fmod(x,y)
#endif
-#ifndef STBTT_fabs
+#ifndef STBTT_cos
#include <math.h>
-#define STBTT_fabs(x) fabs(x)
+#define STBTT_cos(x) cos(x)
+#define STBTT_acos(x) acos(x)
#endif
#ifndef STBTT_fabs
@@ -562,7 +594,7 @@ extern "C" {
#define STBTT_POINT_SIZE(x) (-(x))
- STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
+ STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size,
int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range);
// Creates character bitmaps from the font_index'th font found in fontdata (use
// font_index=0 if you don't know what that is). It creates num_chars_in_range
@@ -587,7 +619,7 @@ extern "C" {
unsigned char h_oversample, v_oversample; // don't set these, they're used internally
} stbtt_pack_range;
- STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
+ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges);
// Creates character bitmaps from multiple ranges of characters stored in
// ranges. This will usually create a better-packed bitmap than multiple
// calls to stbtt_PackFontRange. Note that you can call this multiple
@@ -672,7 +704,7 @@ extern "C" {
int numGlyphs; // number of glyphs, needed for range checking
- int loca, head, glyf, hhea, hmtx, kern; // table locations as offset from start of .ttf
+ int loca, head, glyf, hhea, hmtx, kern, gpos; // table locations as offset from start of .ttf
int index_map; // a cmap mapping for our chosen character encoding
int indexToLocFormat; // format needed to map from glyph index to glyph
@@ -729,6 +761,12 @@ extern "C" {
// these are expressed in unscaled coordinates, so you must multiply by
// the scale factor for a given size
+ STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap);
+ // analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2
+ // table (specific to MS/Windows TTF files).
+ //
+ // Returns 1 on success (table present), 0 on failure.
+
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1);
// the bounding box around all possible characters
@@ -1310,6 +1348,7 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in
info->hhea = stbtt__find_table(data, fontstart, "hhea"); // required
info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); // required
info->kern = stbtt__find_table(data, fontstart, "kern"); // not required
+ info->gpos = stbtt__find_table(data, fontstart, "GPOS"); // not required
if (!cmap || !info->head || !info->hhea || !info->hmtx)
return 0;
@@ -2186,7 +2225,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st
// push immediate
if (b0 == 255) {
- f = (float)stbtt__buf_get32(&b) / 0x10000;
+ f = (float)(stbtt_int32)stbtt__buf_get32(&b) / 0x10000;
}
else {
stbtt__buf_skip(&b, -1);
@@ -2225,12 +2264,10 @@ static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, in
{
stbtt__csctx c = STBTT__CSCTX_INIT(1);
int r = stbtt__run_charstring(info, glyph_index, &c);
- if (x0) {
- *x0 = r ? c.min_x : 0;
- *y0 = r ? c.min_y : 0;
- *x1 = r ? c.max_x : 0;
- *y1 = r ? c.max_y : 0;
- }
+ if (x0) *x0 = r ? c.min_x : 0;
+ if (y0) *y0 = r ? c.min_y : 0;
+ if (x1) *x1 = r ? c.max_x : 0;
+ if (y1) *y1 = r ? c.max_y : 0;
return r ? c.num_vertices : 0;
}
@@ -2255,7 +2292,7 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde
}
}
-STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
+static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
{
stbtt_uint8 *data = info->data + info->kern;
stbtt_uint32 needle, straw;
@@ -2285,9 +2322,260 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1,
return 0;
}
+static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph)
+{
+ stbtt_uint16 coverageFormat = ttUSHORT(coverageTable);
+ switch (coverageFormat) {
+ case 1: {
+ stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2);
+
+ // Binary search.
+ stbtt_int32 l = 0, r = glyphCount - 1, m;
+ int straw, needle = glyph;
+ while (l <= r) {
+ stbtt_uint8 *glyphArray = coverageTable + 4;
+ stbtt_uint16 glyphID;
+ m = (l + r) >> 1;
+ glyphID = ttUSHORT(glyphArray + 2 * m);
+ straw = glyphID;
+ if (needle < straw)
+ r = m - 1;
+ else if (needle > straw)
+ l = m + 1;
+ else {
+ return m;
+ }
+ }
+ } break;
+
+ case 2: {
+ stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2);
+ stbtt_uint8 *rangeArray = coverageTable + 4;
+
+ // Binary search.
+ stbtt_int32 l = 0, r = rangeCount - 1, m;
+ int strawStart, strawEnd, needle = glyph;
+ while (l <= r) {
+ stbtt_uint8 *rangeRecord;
+ m = (l + r) >> 1;
+ rangeRecord = rangeArray + 6 * m;
+ strawStart = ttUSHORT(rangeRecord);
+ strawEnd = ttUSHORT(rangeRecord + 2);
+ if (needle < strawStart)
+ r = m - 1;
+ else if (needle > strawEnd)
+ l = m + 1;
+ else {
+ stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4);
+ return startCoverageIndex + glyph - strawStart;
+ }
+ }
+ } break;
+
+ default: {
+ // There are no other cases.
+ STBTT_assert(0);
+ } break;
+ }
+
+ return -1;
+}
+
+static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
+{
+ stbtt_uint16 classDefFormat = ttUSHORT(classDefTable);
+ switch (classDefFormat)
+ {
+ case 1: {
+ stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2);
+ stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4);
+ stbtt_uint8 *classDef1ValueArray = classDefTable + 6;
+
+ if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount)
+ return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID));
+
+ classDefTable = classDef1ValueArray + 2 * glyphCount;
+ } break;
+
+ case 2: {
+ stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2);
+ stbtt_uint8 *classRangeRecords = classDefTable + 4;
+
+ // Binary search.
+ stbtt_int32 l = 0, r = classRangeCount - 1, m;
+ int strawStart, strawEnd, needle = glyph;
+ while (l <= r) {
+ stbtt_uint8 *classRangeRecord;
+ m = (l + r) >> 1;
+ classRangeRecord = classRangeRecords + 6 * m;
+ strawStart = ttUSHORT(classRangeRecord);
+ strawEnd = ttUSHORT(classRangeRecord + 2);
+ if (needle < strawStart)
+ r = m - 1;
+ else if (needle > strawEnd)
+ l = m + 1;
+ else
+ return (stbtt_int32)ttUSHORT(classRangeRecord + 4);
+ }
+
+ classDefTable = classRangeRecords + 6 * classRangeCount;
+ } break;
+
+ default: {
+ // There are no other cases.
+ STBTT_assert(0);
+ } break;
+ }
+
+ return -1;
+}
+
+// Define to STBTT_assert(x) if you want to break on unimplemented formats.
+#define STBTT_GPOS_TODO_assert(x)
+
+static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
+{
+ stbtt_uint16 lookupListOffset;
+ stbtt_uint8 *lookupList;
+ stbtt_uint16 lookupCount;
+ stbtt_uint8 *data;
+ stbtt_int32 i;
+
+ if (!info->gpos) return 0;
+
+ data = info->data + info->gpos;
+
+ if (ttUSHORT(data + 0) != 1) return 0; // Major version 1
+ if (ttUSHORT(data + 2) != 0) return 0; // Minor version 0
+
+ lookupListOffset = ttUSHORT(data + 8);
+ lookupList = data + lookupListOffset;
+ lookupCount = ttUSHORT(lookupList);
+
+ for (i = 0; i<lookupCount; ++i) {
+ stbtt_uint16 lookupOffset = ttUSHORT(lookupList + 2 + 2 * i);
+ stbtt_uint8 *lookupTable = lookupList + lookupOffset;
+
+ stbtt_uint16 lookupType = ttUSHORT(lookupTable);
+ stbtt_uint16 subTableCount = ttUSHORT(lookupTable + 4);
+ stbtt_uint8 *subTableOffsets = lookupTable + 6;
+ switch (lookupType) {
+ case 2: { // Pair Adjustment Positioning Subtable
+ stbtt_int32 sti;
+ for (sti = 0; sti<subTableCount; sti++) {
+ stbtt_uint16 subtableOffset = ttUSHORT(subTableOffsets + 2 * sti);
+ stbtt_uint8 *table = lookupTable + subtableOffset;
+ stbtt_uint16 posFormat = ttUSHORT(table);
+ stbtt_uint16 coverageOffset = ttUSHORT(table + 2);
+ stbtt_int32 coverageIndex = stbtt__GetCoverageIndex(table + coverageOffset, glyph1);
+ if (coverageIndex == -1) continue;
+
+ switch (posFormat) {
+ case 1: {
+ stbtt_int32 l, r, m;
+ int straw, needle;
+ stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
+ stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
+ stbtt_int32 valueRecordPairSizeInBytes = 2;
+ stbtt_uint16 pairSetCount = ttUSHORT(table + 8);
+ stbtt_uint16 pairPosOffset = ttUSHORT(table + 10 + 2 * coverageIndex);
+ stbtt_uint8 *pairValueTable = table + pairPosOffset;
+ stbtt_uint16 pairValueCount = ttUSHORT(pairValueTable);
+ stbtt_uint8 *pairValueArray = pairValueTable + 2;
+ // TODO: Support more formats.
+ STBTT_GPOS_TODO_assert(valueFormat1 == 4);
+ if (valueFormat1 != 4) return 0;
+ STBTT_GPOS_TODO_assert(valueFormat2 == 0);
+ if (valueFormat2 != 0) return 0;
+
+ STBTT_assert(coverageIndex < pairSetCount);
+
+ needle = glyph2;
+ r = pairValueCount - 1;
+ l = 0;
+
+ // Binary search.
+ while (l <= r) {
+ stbtt_uint16 secondGlyph;
+ stbtt_uint8 *pairValue;
+ m = (l + r) >> 1;
+ pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m;
+ secondGlyph = ttUSHORT(pairValue);
+ straw = secondGlyph;
+ if (needle < straw)
+ r = m - 1;
+ else if (needle > straw)
+ l = m + 1;
+ else {
+ stbtt_int16 xAdvance = ttSHORT(pairValue + 2);
+ return xAdvance;
+ }
+ }
+ } break;
+
+ case 2: {
+ stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
+ stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
+
+ stbtt_uint16 classDef1Offset = ttUSHORT(table + 8);
+ stbtt_uint16 classDef2Offset = ttUSHORT(table + 10);
+ int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1);
+ int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2);
+
+ stbtt_uint16 class1Count = ttUSHORT(table + 12);
+ stbtt_uint16 class2Count = ttUSHORT(table + 14);
+ STBTT_assert(glyph1class < class1Count);
+ STBTT_assert(glyph2class < class2Count);
+
+ // TODO: Support more formats.
+ STBTT_GPOS_TODO_assert(valueFormat1 == 4);
+ if (valueFormat1 != 4) return 0;
+ STBTT_GPOS_TODO_assert(valueFormat2 == 0);
+ if (valueFormat2 != 0) return 0;
+
+ if (glyph1class >= 0 && glyph1class < class1Count && glyph2class >= 0 && glyph2class < class2Count) {
+ stbtt_uint8 *class1Records = table + 16;
+ stbtt_uint8 *class2Records = class1Records + 2 * (glyph1class * class2Count);
+ stbtt_int16 xAdvance = ttSHORT(class2Records + 2 * glyph2class);
+ return xAdvance;
+ }
+ } break;
+
+ default: {
+ // There are no other cases.
+ STBTT_assert(0);
+ break;
+ };
+ }
+ }
+ break;
+ };
+
+ default:
+ // TODO: Implement other stuff.
+ break;
+ }
+ }
+
+ return 0;
+}
+
+STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int g2)
+{
+ int xAdvance = 0;
+
+ if (info->gpos)
+ xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2);
+
+ if (info->kern)
+ xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2);
+
+ return xAdvance;
+}
+
STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2)
{
- if (!info->kern) // if no kerning table, don't waste time looking up both codepoint->glyphs
+ if (!info->kern && !info->gpos) // if no kerning table, don't waste time looking up both codepoint->glyphs
return 0;
return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info, ch1), stbtt_FindGlyphIndex(info, ch2));
}
@@ -2304,6 +2592,17 @@ STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, in
if (lineGap) *lineGap = ttSHORT(info->data + info->hhea + 8);
}
+STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap)
+{
+ int tab = stbtt__find_table(info->data, info->fontstart, "OS/2");
+ if (!tab)
+ return 0;
+ if (typoAscent) *typoAscent = ttSHORT(info->data + tab + 68);
+ if (typoDescent) *typoDescent = ttSHORT(info->data + tab + 70);
+ if (typoLineGap) *typoLineGap = ttSHORT(info->data + tab + 72);
+ return 1;
+}
+
STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1)
{
*x0 = ttSHORT(info->data + info->head + 36);
@@ -2402,7 +2701,7 @@ static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata)
hh->num_remaining_in_head_chunk = count;
}
--hh->num_remaining_in_head_chunk;
- return (char *)(hh->head) + size * hh->num_remaining_in_head_chunk;
+ return (char *)(hh->head) + sizeof(stbtt__hheap_chunk) + size * hh->num_remaining_in_head_chunk;
}
}
@@ -3122,7 +3421,7 @@ static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x
float dy = (y0 + y2) / 2 - my;
if (n > 16) // 65536 segments on one curve better be enough!
return 1;
- if (dx*dx + dy*dy > objspace_flatness_squared) { // half-pixel error allowed... need to be smaller if AA
+ if (dx*dx + dy * dy > objspace_flatness_squared) { // half-pixel error allowed... need to be smaller if AA
stbtt__tesselate_curve(points, num_points, x0, y0, (x0 + x1) / 2.0f, (y0 + y1) / 2.0f, mx, my, objspace_flatness_squared, n + 1);
stbtt__tesselate_curve(points, num_points, mx, my, (x1 + x2) / 2.0f, (y1 + y2) / 2.0f, x2, y2, objspace_flatness_squared, n + 1);
}
@@ -3144,9 +3443,9 @@ static void stbtt__tesselate_cubic(stbtt__point *points, int *num_points, float
float dy2 = y3 - y2;
float dx = x3 - x0;
float dy = y3 - y0;
- float longlen = (float)(STBTT_sqrt(dx0*dx0 + dy0*dy0) + STBTT_sqrt(dx1*dx1 + dy1*dy1) + STBTT_sqrt(dx2*dx2 + dy2*dy2));
- float shortlen = (float)STBTT_sqrt(dx*dx + dy*dy);
- float flatness_squared = longlen*longlen - shortlen*shortlen;
+ float longlen = (float)(STBTT_sqrt(dx0*dx0 + dy0 * dy0) + STBTT_sqrt(dx1*dx1 + dy1 * dy1) + STBTT_sqrt(dx2*dx2 + dy2 * dy2));
+ float shortlen = (float)STBTT_sqrt(dx*dx + dy * dy);
+ float flatness_squared = longlen * longlen - shortlen * shortlen;
if (n > 16) // 65536 segments on one curve better be enough!
return;
@@ -3257,7 +3556,8 @@ error:
STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata)
{
float scale = scale_x > scale_y ? scale_y : scale_x;
- int winding_count, *winding_lengths;
+ int winding_count = 0;
+ int *winding_lengths = NULL;
stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata);
if (windings) {
stbtt__rasterize(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata);
@@ -3345,6 +3645,11 @@ STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *
return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info, codepoint), width, height, xoff, yoff);
}
+STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint)
+{
+ stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, oversample_x, oversample_y, sub_x, sub_y, stbtt_FindGlyphIndex(info, codepoint));
+}
+
STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint)
{
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info, codepoint));
@@ -3397,7 +3702,7 @@ static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, // fo
return -i;
STBTT_assert(x + gw < pw);
STBTT_assert(y + gh < ph);
- stbtt_MakeGlyphBitmap(&f, pixels + x + y*pw, gw, gh, pw, scale, scale, g);
+ stbtt_MakeGlyphBitmap(&f, pixels + x + y * pw, gw, gh, pw, scale, scale, g);
chardata[i].x0 = (stbtt_int16)x;
chardata[i].y0 = (stbtt_int16)y;
chardata[i].x1 = (stbtt_int16)(x + gw);
@@ -3836,7 +4141,7 @@ STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect
stbrp_pack_rects((stbrp_context *)spc->pack_info, rects, num_rects);
}
-STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
+STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
{
stbtt_fontinfo info;
int i, j, n, return_value = 1;
@@ -3872,7 +4177,7 @@ STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, unsigned char *fontd
return return_value;
}
-STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size,
+STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size,
int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
{
stbtt_pack_range range;
@@ -3935,10 +4240,10 @@ static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2],
int num_s = 0;
if (a != 0.0) {
- float discr = b*b - a*c;
+ float discr = b * b - a * c;
if (discr > 0.0) {
float rcpna = -1 / a;
- float d = (float)sqrt(discr);
+ float d = (float)STBTT_sqrt(discr);
s0 = (b + d) * rcpna;
s1 = (b - d) * rcpna;
if (s0 >= 0.0 && s0 <= 1.0)
@@ -3972,12 +4277,12 @@ static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2],
float q20d = q2d - q0d;
float q0rd = q0d - rod;
- hits[0][0] = q0rd + s0*(2.0f - 2.0f*s0)*q10d + s0*s0*q20d;
- hits[0][1] = a*s0 + b;
+ hits[0][0] = q0rd + s0 * (2.0f - 2.0f*s0)*q10d + s0 * s0*q20d;
+ hits[0][1] = a * s0 + b;
if (num_s > 1) {
- hits[1][0] = q0rd + s1*(2.0f - 2.0f*s1)*q10d + s1*s1*q20d;
- hits[1][1] = a*s1 + b;
+ hits[1][0] = q0rd + s1 * (2.0f - 2.0f*s1)*q10d + s1 * s1*q20d;
+ hits[1][1] = a * s1 + b;
return 2;
}
else {
@@ -4002,7 +4307,7 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
orig[1] = y;
// make sure y never passes through a vertex of the shape
- y_frac = (float)fmod(y, 1.0f);
+ y_frac = (float)STBTT_fmod(y, 1.0f);
if (y_frac < 0.01f)
y += 0.01f;
else if (y_frac > 0.99f)
@@ -4073,10 +4378,10 @@ static float stbtt__cuberoot(float x)
static int stbtt__solve_cubic(float a, float b, float c, float* r)
{
float s = -a / 3;
- float p = b - a*a / 3;
+ float p = b - a * a / 3;
float q = a * (2 * a*a - 9 * b) / 27 + c;
- float p3 = p*p*p;
- float d = q*q + 4 * p3 / 27;
+ float p3 = p * p*p;
+ float d = q * q + 4 * p3 / 27;
if (d >= 0) {
float z = (float)STBTT_sqrt(d);
float u = (-q + z) / 2;
@@ -4158,9 +4463,9 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y;
float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y;
float bx = x0 - 2 * x1 + x2, by = y0 - 2 * y1 + y2;
- float len2 = bx*bx + by*by;
+ float len2 = bx * bx + by * by;
if (len2 != 0.0f)
- precompute[i] = 1.0f / (bx*bx + by*by);
+ precompute[i] = 1.0f / (bx*bx + by * by);
else
precompute[i] = 0.0f;
}
@@ -4203,7 +4508,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float px = x0 - sx, py = y0 - sy;
// minimize (px+t*dx)^2 + (py+t*dy)^2 = px*px + 2*px*dx*t + t^2*dx*dx + py*py + 2*py*dy*t + t^2*dy*dy
// derivative: 2*px*dx + 2*py*dy + (2*dx*dx+2*dy*dy)*t, set to 0 and solve
- float t = -(px*dx + py*dy) / (dx*dx + dy*dy);
+ float t = -(px*dx + py * dy) / (dx*dx + dy * dy);
if (t >= 0.0f && t <= 1.0f)
min_dist = dist;
}
@@ -4224,16 +4529,16 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float res[3], px, py, t, it;
float a_inv = precompute[i];
if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula
- float a = 3 * (ax*bx + ay*by);
- float b = 2 * (ax*ax + ay*ay) + (mx*bx + my*by);
- float c = mx*ax + my*ay;
+ float a = 3 * (ax*bx + ay * by);
+ float b = 2 * (ax*ax + ay * ay) + (mx*bx + my * by);
+ float c = mx * ax + my * ay;
if (a == 0.0) { // if a is 0, it's linear
if (b != 0.0) {
res[num++] = -c / b;
}
}
else {
- float discriminant = b*b - 4 * a*c;
+ float discriminant = b * b - 4 * a*c;
if (discriminant < 0)
num = 0;
else {
@@ -4245,31 +4550,31 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
}
}
else {
- float b = 3 * (ax*bx + ay*by) * a_inv; // could precompute this as it doesn't depend on sample point
- float c = (2 * (ax*ax + ay*ay) + (mx*bx + my*by)) * a_inv;
- float d = (mx*ax + my*ay) * a_inv;
+ float b = 3 * (ax*bx + ay * by) * a_inv; // could precompute this as it doesn't depend on sample point
+ float c = (2 * (ax*ax + ay * ay) + (mx*bx + my * by)) * a_inv;
+ float d = (mx*ax + my * ay) * a_inv;
num = stbtt__solve_cubic(b, c, d, res);
}
if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) {
t = res[0], it = 1.0f - t;
- px = it*it*x0 + 2 * t*it*x1 + t*t*x2;
- py = it*it*y0 + 2 * t*it*y1 + t*t*y2;
+ px = it * it*x0 + 2 * t*it*x1 + t * t*x2;
+ py = it * it*y0 + 2 * t*it*y1 + t * t*y2;
dist2 = (px - sx)*(px - sx) + (py - sy)*(py - sy);
if (dist2 < min_dist * min_dist)
min_dist = (float)STBTT_sqrt(dist2);
}
if (num >= 2 && res[1] >= 0.0f && res[1] <= 1.0f) {
t = res[1], it = 1.0f - t;
- px = it*it*x0 + 2 * t*it*x1 + t*t*x2;
- py = it*it*y0 + 2 * t*it*y1 + t*t*y2;
+ px = it * it*x0 + 2 * t*it*x1 + t * t*x2;
+ py = it * it*y0 + 2 * t*it*y1 + t * t*y2;
dist2 = (px - sx)*(px - sx) + (py - sy)*(py - sy);
if (dist2 < min_dist * min_dist)
min_dist = (float)STBTT_sqrt(dist2);
}
if (num >= 3 && res[2] >= 0.0f && res[2] <= 1.0f) {
t = res[2], it = 1.0f - t;
- px = it*it*x0 + 2 * t*it*x1 + t*t*x2;
- py = it*it*y0 + 2 * t*it*y1 + t*t*y2;
+ px = it * it*x0 + 2 * t*it*x1 + t * t*x2;
+ py = it * it*y0 + 2 * t*it*y1 + t * t*y2;
dist2 = (px - sx)*(px - sx) + (py - sy)*(py - sy);
if (dist2 < min_dist * min_dist)
min_dist = (float)STBTT_sqrt(dist2);
@@ -4516,6 +4821,9 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const
// FULL VERSION HISTORY
//
+// 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod
+// 1.18 (2018-01-29) add missing function
+// 1.17 (2017-07-23) make more arguments const; doc fix
// 1.16 (2017-07-12) SDF support
// 1.15 (2017-03-03) make more arguments const
// 1.14 (2017-01-16) num-fonts-in-TTC function
@@ -4608,4 +4916,4 @@ AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
-*/
+*/ \ No newline at end of file
diff --git a/libjin/Audio/Audio.cpp b/libjin/Audio/Audio.cpp
index 5fb10da..c9a3e40 100644
--- a/libjin/Audio/Audio.cpp
+++ b/libjin/Audio/Audio.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_AUDIO
+#if LIBJIN_MODULES_AUDIO
#include "SDL2/SDL.h"
#include "audio.h"
@@ -9,7 +9,7 @@ namespace jin
namespace audio
{
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO
diff --git a/libjin/Audio/Audio.h b/libjin/Audio/Audio.h
index 6c3468e..9faf0bc 100644
--- a/libjin/Audio/Audio.h
+++ b/libjin/Audio/Audio.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_AUDIO_H
-#define __JIN_AUDIO_H
+#ifndef __LIBJIN_AUDIO_H
+#define __LIBJIN_AUDIO_H
#include "../modules.h"
-#if JIN_MODULES_AUDIO
+#if LIBJIN_MODULES_AUDIO
#include "SDL2/SDL.h"
@@ -12,14 +12,13 @@ namespace jin
{
namespace audio
{
+
class Source;
template<class SubAudio>
class Audio : public Subsystem<SubAudio>
{
-
public:
-
enum State
{
PLAY ,
@@ -34,7 +33,6 @@ namespace audio
virtual void setVolume(float volume) = 0;
protected:
-
Audio()
: volume(1)
, state(State::PLAY)
@@ -44,10 +42,11 @@ namespace audio
float volume;
State state;
+
};
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO
-#endif // __JIN_AUDIO_H \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO
+#endif // __LIBJIN_AUDIO_H
diff --git a/libjin/Audio/SDL/SDLAudio.cpp b/libjin/Audio/SDL/SDLAudio.cpp
index 040ca96..d457dca 100644
--- a/libjin/Audio/SDL/SDLAudio.cpp
+++ b/libjin/Audio/SDL/SDLAudio.cpp
@@ -1,5 +1,5 @@
#include "../../modules.h"
-#if JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
+#if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
#include <iostream>
#include "SDLAudio.h"
@@ -29,7 +29,7 @@ namespace audio
/*call only once*/ bool SDLAudio::initSystem(const SettingBase* s)
{
-#if JIN_DEBUG
+#if LIBJIN_DEBUG
Loghelper::log(Loglevel::LV_INFO, "Init Audio System");
#endif
@@ -135,7 +135,7 @@ namespace audio
this->volume = clamp(volume, 0.0f, 1.0f);
}
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
diff --git a/libjin/Audio/SDL/SDLAudio.h b/libjin/Audio/SDL/SDLAudio.h
index f2a4fab..97ed664 100644
--- a/libjin/Audio/SDL/SDLAudio.h
+++ b/libjin/Audio/SDL/SDLAudio.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_AUDIO_SDL_H
-#define __JIN_AUDIO_SDL_H
+#ifndef __LIBJIN_AUDIO_SDL_H
+#define __LIBJIN_AUDIO_SDL_H
#include "../../modules.h"
-#if JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
+#if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
#include "SDLSource.h"
#include <vector>
@@ -18,9 +18,7 @@ namespace audio
class SDLAudio : public Audio<SDLAudio>
{
-
public:
-
struct Setting : SettingBase
{
public:
@@ -34,23 +32,20 @@ namespace audio
void pause() override;
void resume() override;
void setVolume(float volume) override;
-
/* process functions*/
void processCommands();
void processSources(void* buffer, size_t len);
void processBuffer(void* buffer, size_t len);
bool goOnProcess();
-
+ /* thread-safe */
void lock();
void unlock();
private:
-
+ SINGLETON(SDLAudio);
SDLAudio() {};
~SDLAudio() {};
-
- SINGLETON(SDLAudio);
-
+ /* subsystem interface */
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
@@ -58,8 +53,8 @@ namespace audio
};
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
-#endif // __JIN_AUDIO_SDL_H \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
+#endif // __LIBJIN_AUDIO_SDL_H
diff --git a/libjin/Audio/SDL/SDLSource.cpp b/libjin/Audio/SDL/SDLSource.cpp
index 5c6abb8..00193a4 100644
--- a/libjin/Audio/SDL/SDLSource.cpp
+++ b/libjin/Audio/SDL/SDLSource.cpp
@@ -1,5 +1,5 @@
#include "../../modules.h"
-#if JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
+#if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
#include <exception>
#include <fstream>
@@ -393,7 +393,7 @@ Manager::get()->pushCommand(cmd); \
}
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
diff --git a/libjin/Audio/SDL/SDLSource.h b/libjin/Audio/SDL/SDLSource.h
index dd792c7..7e407ee 100644
--- a/libjin/Audio/SDL/SDLSource.h
+++ b/libjin/Audio/SDL/SDLSource.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_SOURCE_SDL_H
-#define __JIN_SOURCE_SDL_H
+#ifndef __LIBJIN_SOURCE_SDL_H
+#define __LIBJIN_SOURCE_SDL_H
#include "../../modules.h"
-#if JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
+#if LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
#include <vector>
#include <queue>
@@ -20,14 +20,11 @@ namespace audio
class SDLSource : public Source
{
-
public:
-
- ~SDLSource();
-
static SDLSource* createSource(const char* file);
static SDLSource* createSource(void* mem, size_t size);
+ ~SDLSource();
/* ISource interface */
void play() override;
void stop() override;
@@ -37,25 +34,22 @@ namespace audio
bool isStopped() const override;
bool isPaused() const override;
void setPitch(float pitch) override;
- // Ͻ
void setVolume(float volume) override;
bool setLoop(bool loop) override;
void setRate(float rate) override;
-
+ /* handle and process anduio clip */
inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd);
inline void process(void* buffer, size_t size);
protected:
-
SDLSource();
-
+ /* decode raw audio data */
void decode_wav(void* mem, int size);
void decode_ogg(void* mem, int size);
-
+ /* check state */
inline bool is(int state) const { return (status.state & state) == state; }
- struct
- {
+ struct{
const void* data; // Ƶ
int length; // dataֽڳ
const void* end; // dataβ = (unsigned char*)data + size
@@ -64,10 +58,8 @@ namespace audio
int samples; // sample = size / (bitdepth / 8)
unsigned char channels; // channel1(mono)2(stereo)
} raw;
-
/* Procedure controller variable */
- struct
- {
+ struct{
int pos; // ǰŵsample
int pitch; // pitch
int state; // ǰ״̬
@@ -79,15 +71,13 @@ namespace audio
class SDLSourceManager
{
-
public:
-
static SDLSourceManager* get();
/* Process function */
void processCommands();
void processSources(void* buffer, size_t size);
-
+ /* control flow */
void removeAllSource();
void removeSource(SDLSource* source);
void pushSource(SDLSource* source);
@@ -95,7 +85,6 @@ namespace audio
void pushCommand(SDLSourceCommand* cmd);
private :
-
std::queue<SDLSourceCommand*> commands;
std::stack<SDLSourceCommand*> commandsPool;
std::vector<SDLSource*> sources; // processing sources
@@ -111,8 +100,8 @@ namespace audio
}
};
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
-#endif // __JIN_SOURCE_SDL_H \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
+#endif // __LIBJIN_SOURCE_SDL_H
diff --git a/libjin/Audio/Source.cpp b/libjin/Audio/Source.cpp
index 61f4055..7ac4e60 100644
--- a/libjin/Audio/Source.cpp
+++ b/libjin/Audio/Source.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_AUDIO
+#if LIBJIN_MODULES_AUDIO
#include <cstring>
#include "source.h"
@@ -23,6 +23,7 @@ namespace audio
return SourceType::INVALID;
}
-}
-}
-#endif // JIN_MODULES_AUDIO \ No newline at end of file
+} // audio
+} // jin
+
+#endif // LIBJIN_MODULES_AUDIO
diff --git a/libjin/Audio/Source.h b/libjin/Audio/Source.h
index 3abe7de..b227db2 100644
--- a/libjin/Audio/Source.h
+++ b/libjin/Audio/Source.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_AUDIO_SOURCE_H
-#define __JIN_AUDIO_SOURCE_H
+#ifndef __LIBJIN_AUDIO_SOURCE_H
+#define __LIBJIN_AUDIO_SOURCE_H
#include "../modules.h"
-#if JIN_MODULES_AUDIO
+#if LIBJIN_MODULES_AUDIO
#include "SDL2/SDL.h"
@@ -19,12 +19,9 @@ namespace audio
class Source
{
-
public:
-
Source() {};
virtual ~Source() {};
-
/* interface */
virtual void play() = 0;
virtual void stop() = 0;
@@ -39,13 +36,12 @@ namespace audio
virtual void setRate(float rate) = 0;
protected:
-
static SourceType getType(const void* mem, int size);
};
-}
-}
+} // audio
+} // jin
-#endif // JIN_MODULES_AUDIO
-#endif // __JIN_AUDIO_SOURCE_H \ No newline at end of file
+#endif // LIBJIN_MODULES_AUDIO
+#endif // __LIBJIN_AUDIO_SOURCE_H
diff --git a/libjin/Common/Array.hpp b/libjin/Common/Array.hpp
new file mode 100644
index 0000000..7c0f058
--- /dev/null
+++ b/libjin/Common/Array.hpp
@@ -0,0 +1,83 @@
+#ifndef __LIBJIN_COMMON_ARRAY_H
+#define __LIBJIN_COMMON_ARRAY_H
+
+namespace jin
+{
+
+ /* ԶͷŶڴջϴĶ̬ */
+ template<typename T>
+ class Array
+ {
+ public:
+ Array() : length(0), data(nullptr) {}
+
+ Array(int l)
+ {
+ length = l;
+ data = new T[l];
+ }
+
+ ~Array()
+ {
+ delete[] data;
+ length = 0;
+ }
+
+ T* operator &()
+ {
+ return data;
+ }
+
+ T operator[](int index)
+ {
+ return data[index];
+ }
+
+ /* ڴ */
+ void bind(T* d, int len)
+ {
+ if (data != nullptr)
+ delete data;
+ data = d;
+ length = len;
+ }
+
+ void add(T v)
+ {
+ int len = length + 1;
+ T* d = new T[len];
+ memcpy(d, data, size());
+ d[length] = v;
+ bind(d, len);
+ }
+
+ int size()
+ {
+ return sizeof(T) * length;
+ }
+
+ int count()
+ {
+ return length;
+ }
+
+ private:
+ /**
+ * http://blog.jobbole.com/106923/
+ * new ڴ洴
+ * 1. new ڴ
+ * 2. ù캯
+ *
+ * new, deleteڷͷڴ棬
+ */
+ void* operator new(size_t t);
+ void operator delete(void* ptr);
+
+ T * data;
+ unsigned int length;
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/libjin/Common/Object.h b/libjin/Common/Object.h
index 9ac1b5a..f7f3b43 100644
--- a/libjin/Common/Object.h
+++ b/libjin/Common/Object.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_COMMON_OBJECT_H
-#define __JIN_COMMON_OBJECT_H
+#ifndef __LIBJIN_COMMON_OBJECT_H
+#define __LIBJIN_COMMON_OBJECT_H
namespace jin
{
@@ -44,6 +44,6 @@ namespace jin
}; // Object
-}
+} // jin
#endif \ No newline at end of file
diff --git a/libjin/Common/Singleton.hpp b/libjin/Common/Singleton.hpp
index 48cd5bc..600813a 100644
--- a/libjin/Common/Singleton.hpp
+++ b/libjin/Common/Singleton.hpp
@@ -1,5 +1,5 @@
-#ifndef __JIN_SINGLETON_H
-#define __JIN_SINGLETON_H
+#ifndef __LIBJIN_SINGLETON_H
+#define __LIBJIN_SINGLETON_H
namespace jin
{
@@ -30,9 +30,8 @@ namespace jin
template<class T> T* Singleton<T>::_instance = nullptr;
-#define SINGLETON(T) \
- friend Singleton<T>
+#define SINGLETON(T) friend Singleton<T>
} // jin
-#endif // __JIN_SINGLETON_H \ No newline at end of file
+#endif // __LIBJIN_SINGLETON_H \ No newline at end of file
diff --git a/libjin/Common/StringMap.hpp b/libjin/Common/StringMap.hpp
index bebd94d..9e4b0f5 100644
--- a/libjin/Common/StringMap.hpp
+++ b/libjin/Common/StringMap.hpp
@@ -1,5 +1,5 @@
-#ifndef __JIN_COMMON_SREINGMAP_H
-#define __JIN_COMMON_SREINGMAP_H
+#ifndef __LIBJIN_COMMON_SREINGMAP_H
+#define __LIBJIN_COMMON_SREINGMAP_H
namespace jin
{
@@ -138,6 +138,6 @@ namespace jin
}; // StringMap
-}
+} // jin
#endif \ No newline at end of file
diff --git a/libjin/Common/Subsystem.hpp b/libjin/Common/Subsystem.hpp
index 59013c6..78f4e01 100644
--- a/libjin/Common/Subsystem.hpp
+++ b/libjin/Common/Subsystem.hpp
@@ -1,5 +1,5 @@
-#ifndef __JIN_COMMON_SUBSYSTEM_H
-#define __JIN_COMMON_SUBSYSTEM_H
+#ifndef __LIBJIN_COMMON_SUBSYSTEM_H
+#define __LIBJIN_COMMON_SUBSYSTEM_H
#include "singleton.hpp"
#include "../utils/macros.h"
@@ -28,12 +28,11 @@ namespace jin
}
protected:
+ SINGLETON(System);
Subsystem() {};
virtual ~Subsystem() {};
- SINGLETON(System);
-
/*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0;
/*onlyonce*/ virtual void quitSystem() = 0;
diff --git a/libjin/Common/common.h b/libjin/Common/common.h
new file mode 100644
index 0000000..9586c82
--- /dev/null
+++ b/libjin/Common/common.h
@@ -0,0 +1,6 @@
+#ifndef __LIBJIN_COMMON_H
+#define __LIBJIN_COMMON_H
+
+#include "Array.hpp"
+
+#endif \ No newline at end of file
diff --git a/libjin/Common/utf8.cpp b/libjin/Common/utf8.cpp
index bef6c85..8c05da8 100644
--- a/libjin/Common/utf8.cpp
+++ b/libjin/Common/utf8.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_OS == JIN_WINDOWS
+#if LIBJIN_OS == LIBJIN_WINDOWS
#include "utf8.h"
@@ -39,4 +39,4 @@ namespace jin
} // jin
-#endif // JIN_OS == JIN_WINDOWS \ No newline at end of file
+#endif // LIBJIN_OS == LIBJIN_WINDOWS
diff --git a/libjin/Common/utf8.h b/libjin/Common/utf8.h
index 7f26841..5985684 100644
--- a/libjin/Common/utf8.h
+++ b/libjin/Common/utf8.h
@@ -1,8 +1,8 @@
-#ifndef __JIN_COMMON_UTF8_H
-#define __JIN_COMMON_UTF8_H
+#ifndef __LIBJIN_COMMON_UTF8_H
+#define __LIBJIN_COMMON_UTF8_H
#include "../modules.h"
-#if JIN_OS == JIN_WINDOWS
+#if LIBJIN_OS == LIBJIN_WINDOWS
#include <string>
#include <windows.h>
@@ -25,7 +25,7 @@ namespace jin
**/
void replace_char(std::string & str, char find, char replace);
-}
+} // jin
-#endif // JIN_OS == JIN_WINDOWS
-#endif // __JIN_COMMON_UTF8_H \ No newline at end of file
+#endif // LIBJIN_OS == LIBJIN_WINDOWS
+#endif // __LIBJIN_COMMON_UTF8_H
diff --git a/libjin/Core/Core.h b/libjin/Core/Core.h
index dd902b4..4b4df8f 100644
--- a/libjin/Core/Core.h
+++ b/libjin/Core/Core.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_CORE_H
-#define __JIN_CORE_H
+#ifndef __LIBJIN_CORE_H
+#define __LIBJIN_CORE_H
#include "game.h"
diff --git a/libjin/Core/Game.h b/libjin/Core/Game.h
index 31f32d8..725c62c 100644
--- a/libjin/Core/Game.h
+++ b/libjin/Core/Game.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_CORE_GAME_H
-#define __JIN_CORE_GAME_H
+#ifndef __LIBJIN_CORE_GAME_H
+#define __LIBJIN_CORE_GAME_H
#include "SDL2/SDL.h"
@@ -55,4 +55,4 @@ namespace core
} // core
} // jin
-#endif // __JIN_CORE_GAME_H \ No newline at end of file
+#endif // __LIBJIN_CORE_GAME_H
diff --git a/libjin/Debug/Debug.h b/libjin/Debug/Debug.h
deleted file mode 100644
index 9fa9fe1..0000000
--- a/libjin/Debug/Debug.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __JIN_DEBUG_H
-#define __JIN_DEBUG_H
-
-
-
-#endif \ No newline at end of file
diff --git a/libjin/Debug/Log.h b/libjin/Debug/Log.h
deleted file mode 100644
index e1624f5..0000000
--- a/libjin/Debug/Log.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __JIN_LOG_H
-#define __JIN_LOG_H
-
-namespace jin
-{
-namespace debug
-{
-
- const char* err;
-
-}
-}
-
-#endif \ No newline at end of file
diff --git a/libjin/Filesystem/Buffer.h b/libjin/Filesystem/Buffer.h
index 1d72083..15ea665 100644
--- a/libjin/Filesystem/Buffer.h
+++ b/libjin/Filesystem/Buffer.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_BUFFER_H
-#define __JIN_BUFFER_H
+#ifndef __LIBJIN_BUFFER_H
+#define __LIBJIN_BUFFER_H
#include <string.h>
@@ -8,46 +8,51 @@ namespace jin
namespace filesystem
{
+ /**
+ * ڶϷָռbuffer
+ */
class Buffer
{
public:
-
- inline Buffer(): data(0), size(0)
+ Buffer() : data(0), size(0) {}
+ Buffer(const Buffer& src)
{
- }
-
- inline Buffer(const Buffer& src)
- {
- delete data;
+ delete[] data;
size = src.size;
data = new char[size];
memcpy(data, src.data, size);
}
-
- inline Buffer(void* d, int s)
+ Buffer(void* d, int s)
{
- data = new char(size);
+ data = new char[size];
memcpy(data, d, size);
size = s;
}
-
- inline ~Buffer()
+ Buffer(size_t s)
{
+ data = new char[s];
+ memset(data, 0, s);
+ size = s;
+ }
+ ~Buffer()
+ {
+ delete[] data;
size = 0;
- delete[] data;
+ }
+ void operator = (const Buffer& buffer)
+ {
+ delete[] data;
+ size = buffer.size;
+ data = new char[size];
+ memcpy(data, buffer.data, size);
}
- public:
-
- // data position in memory
void* data;
-
- // data buffer size
unsigned int size;
};
-}
-}
+} // filesystem
+} // jin
#endif \ No newline at end of file
diff --git a/libjin/Filesystem/Filesystem.cpp b/libjin/Filesystem/Filesystem.cpp
index e9b05e3..3f91274 100644
--- a/libjin/Filesystem/Filesystem.cpp
+++ b/libjin/Filesystem/Filesystem.cpp
@@ -20,9 +20,6 @@ namespace filesystem
return fs ? fs : (fs = new Filesystem());
}
- /**
- * r is relative path
- */
void Filesystem::mount(const char * path)
{
int err = smtmount(S, path);
@@ -33,15 +30,17 @@ namespace filesystem
}
}
- /**
- *
- */
int Filesystem::read(const char* path, Buffer* buffer)
{
buffer->data = smtread(S, path, &buffer->size);
if (buffer->data == 0)
- return 0;
- return 1;
+ return 0;
+ return 1;
+ }
+
+ void* Filesystem::read(const char* path, unsigned int* len)
+ {
+ return smtread(S, path, len);
}
const char* Filesystem::getFull(const char* path)
@@ -64,5 +63,5 @@ namespace filesystem
return smtexists(S, path) == 0;
}
-}
-} \ No newline at end of file
+} // filesystem
+} // jin \ No newline at end of file
diff --git a/libjin/Filesystem/Filesystem.h b/libjin/Filesystem/Filesystem.h
index ba0fdc5..ffc0c52 100644
--- a/libjin/Filesystem/Filesystem.h
+++ b/libjin/Filesystem/Filesystem.h
@@ -9,48 +9,23 @@ namespace filesystem
class Filesystem
{
public:
-
- Filesystem();
-
static Filesystem* get();
- /**
- * is a path a directroy or a single file
- */
- bool isDir(const char* path);
+ Filesystem();
- /**
- * is a path a directroy or a single file
- */
+ bool isDir(const char* path);
bool isFile(const char* path);
-
- /**
- * is path a valid path
- */
bool exists(const char* path);
-
- /**
- * read a file and return data buffer
- */
int read(const char* path, Buffer* buffer);
-
- /**
- * set root directory, can only mount once.
- */
+ void* read(const char* path, unsigned int* len);
void mount(const char* root);
-
- /**
- * convret relative path to absolute path
- */
const char* getFull(const char* path);
private:
-
static Filesystem* fs;
-
smtShared* S;
};
-}
-} \ No newline at end of file
+} // filesystem
+} // jin \ No newline at end of file
diff --git a/libjin/Graphics/Bitmap.cpp b/libjin/Graphics/Bitmap.cpp
new file mode 100644
index 0000000..acfde58
--- /dev/null
+++ b/libjin/Graphics/Bitmap.cpp
@@ -0,0 +1,141 @@
+#include "Bitmap.h"
+#include "../3rdparty/stb/stb_image.h"
+#include "../Math/math.h"
+
+using namespace jin::math;
+
+namespace jin
+{
+namespace graphics
+{
+
+ /*static*/ Bitmap* Bitmap::createBitmap(const void* imgData, size_t size)
+ {
+ if (imgData == nullptr)
+ return nullptr;
+ int w, h;
+ void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
+ if (data == nullptr)
+ return nullptr;
+ Bitmap* bitmap = new Bitmap();
+ bitmap->pixels = (Color*)data;
+ bitmap->width = w;
+ bitmap->height = h;
+ return bitmap;
+ }
+
+ /*static*/ Bitmap* Bitmap::createBitmap(int w, int h, Color color)
+ {
+ Bitmap* bitmap = new Bitmap(w, h);
+ if (color != Color::BLACK)
+ bitmap->setPixels(color);
+ return bitmap;
+ }
+
+ /*static */ Bitmap* Bitmap::clone(const Bitmap* bitmap)
+ {
+ Bitmap* b = new Bitmap();
+ int w = bitmap->getWidth();
+ int h = bitmap->getHeight();
+ b->resetPixels(bitmap->getPixels(), w, h);
+ return b;
+ }
+
+ Bitmap::Bitmap()
+ : width(0)
+ , height(0)
+ , pixels(nullptr)
+ {
+ }
+
+ Bitmap::Bitmap(int w, int h)
+ {
+ width = w;
+ height = h;
+ pixels = new Color[w*h];
+ }
+
+ Bitmap::~Bitmap()
+ {
+ stbi_image_free(pixels);
+ }
+
+ void Bitmap::bind(Color* p, int w, int h)
+ {
+ if (pixels != nullptr)
+ delete[] pixels;
+ pixels = p;
+ width = w;
+ height = h;
+ }
+
+ void Bitmap::resetPixels(const Color* p, int w, int h)
+ {
+ if (pixels != nullptr)
+ delete[] pixels;
+ pixels = new Color[w*h];
+ size_t s = w * h * sizeof(Color);
+ memcpy(pixels, p, s);
+ width = w;
+ height = h;
+ }
+
+ void Bitmap::setPixel(const Color& c, int x, int y)
+ {
+ if (pixels == nullptr)
+ return;
+ if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
+ return;
+ pixels[x + y * width] = c;
+ }
+
+ void Bitmap::resetPixels(const Color& c, int w, int h)
+ {
+ if (pixels != nullptr)
+ delete[] pixels;
+ pixels = new Color[w*h];
+ size_t s = w * h * sizeof(Color);
+ width = w;
+ height = h;
+ for (int x = 0; x < w; ++x)
+ {
+ for (int y = 0; y < h; ++y)
+ {
+ pixels[x + y * w] = c;
+ }
+ }
+ }
+
+ void Bitmap::setPixels(Color* p)
+ {
+ size_t s = width * height * sizeof(Color);
+ memcpy(pixels, p, s);
+ }
+
+ void Bitmap::setPixels(Color c)
+ {
+ for (int x = 0; x < width; ++x)
+ {
+ for (int y = 0; y < height; ++y)
+ {
+ pixels[x + y * width] = c;
+ }
+ }
+ }
+
+ Color Bitmap::getPixel(int x, int y)
+ {
+ if (pixels == nullptr)
+ return Color::BLACK;
+ if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
+ return Color::BLACK;
+ return pixels[x + y * width];
+ }
+
+ const Color* Bitmap::getPixels() const
+ {
+ return pixels;
+ }
+
+}
+} \ No newline at end of file
diff --git a/libjin/Graphics/Bitmap.h b/libjin/Graphics/Bitmap.h
new file mode 100644
index 0000000..ab84388
--- /dev/null
+++ b/libjin/Graphics/Bitmap.h
@@ -0,0 +1,49 @@
+#ifndef __LIBJIN_BITMAP_H
+#define __LIBJIN_BITMAP_H
+#include "../modules.h"
+#if LIBJIN_MODULES_RENDER
+
+#include "../Math/Vector2.hpp"
+#include "../3rdparty/GLee/GLee.h"
+#include "Color.h"
+namespace jin
+{
+namespace graphics
+{
+
+ class Bitmap
+ {
+ public:
+ static Bitmap* createBitmap(const void* imgData, size_t size);
+ static Bitmap* createBitmap(int w, int h, Color color = Color::BLACK);
+ static Bitmap* clone(const Bitmap* bitmap);
+
+ ~Bitmap();
+ /* init pixels */
+ void bind(Color* pixels, int w, int h);
+ void resetPixels(const Color* pixels, int w, int h);
+ void resetPixels(const Color& pixels, int w, int h);
+ /* modify pixels */
+ void setPixel(const Color& pixel, int x, int y);
+ void setPixels(Color pixels);
+ void setPixels(Color* pixels);
+ Color getPixel(int x, int y);
+ const Color* getPixels() const;
+ /* get width and height */
+ inline int getWidth() const { return width; }
+ inline int getHeight() const { return height; }
+
+ private:
+ Bitmap();
+ Bitmap(int w, int h);
+
+ Color * pixels;
+ int width, height;
+
+ };
+
+}
+}
+
+#endif
+#endif \ No newline at end of file
diff --git a/libjin/Graphics/Canvas.cpp b/libjin/Graphics/Canvas.cpp
index 99f022d..efcd12d 100644
--- a/libjin/Graphics/Canvas.cpp
+++ b/libjin/Graphics/Canvas.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "../utils/macros.h"
#include "canvas.h"
@@ -10,126 +10,125 @@ namespace jin
namespace graphics
{
+ /*class member*/ const Canvas* Canvas::current = nullptr;
+ /*class member*/ const Canvas* const Canvas::DEFAULT_CANVAS = new Canvas(0);
+
/*class member*/ Canvas* Canvas::createCanvas(int w, int h)
{
return new Canvas(w, h);
}
- Canvas::Canvas(int w, int h)
- : Drawable(w, h)
+ Canvas::Canvas(GLuint n)
+ : fbo(n)
{
- init();
}
- Canvas::~Canvas()
+ Canvas::Canvas(int w, int h)
+ : Drawable(w, h)
{
- }
+ vertCoord[0] = 0; vertCoord[1] = 0;
+ vertCoord[2] = 0; vertCoord[3] = h;
+ vertCoord[4] = w; vertCoord[5] = h;
+ vertCoord[6] = w; vertCoord[7] = 0;
- /*class member*/ GLint Canvas::cur = -1;
-
- bool Canvas::init()
- {
- setVertices(
- new float [DRAWABLE_V_SIZE] {
- 0, 0,
- 0, (float)height,
- (float)width, (float)height,
- (float)width, 0,
- },
- new float [DRAWABLE_V_SIZE] {
- 0, 1,
- 0, 0,
- 1, 0,
- 1, 1
- }
- );
+ textCoord[0] = 0; textCoord[1] = 1;
+ textCoord[2] = 0; textCoord[3] = 0;
+ textCoord[4] = 1; textCoord[5] = 0;
+ textCoord[6] = 1; textCoord[7] = 1;
GLint current_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
- // generate a new render buffer object
+ /* generate a new render buffer object */
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- // generate texture save target
+ /* generate texture save target */
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-
- // unbind framebuffer
+
+ /* unbind framebuffer */
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
-
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
- return false;
- return true;
}
- bool Canvas::hasbind(GLint fbo)
+ Canvas::~Canvas()
{
- return cur == fbo;
+ }
+
+ /*class member*/ bool Canvas::isBinded(const Canvas* cvs)
+ {
+ return current == cvs;
}
/**
* bind to canvas
*/
- void Canvas::bind()
+ /*class member*/ void Canvas::bind(Canvas* canvas)
{
- if (hasbind(fbo)) return;
-
- cur = fbo;
+ if (isBinded(canvas)) return;
+ current = canvas;
+ glBindFramebuffer(GL_FRAMEBUFFER, canvas->fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ int w = canvas->size.w;
+ int h = canvas->size.h;
+ /* set view port to canvas */
+ glViewport(0, 0, w, h);
+ /* set projection matrix */
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
+ glOrtho(0, w, h, 0, -1, 1);
- glViewport(0, 0, width, height);
- glOrtho(0, width, height, 0, -1, 1);
-
- // Switch back to modelview matrix
+ /* set (model*view) matrix */
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
+
+ /* ready to draw */
}
/**
* bind to default screen render buffer.
+ * do some coordinates transform work
+ * https://blog.csdn.net/liji_digital/article/details/79370841
+ * https://blog.csdn.net/lyx2007825/article/details/8792475
*/
/*class member*/ void Canvas::unbind()
{
- if (hasbind(0)) return;
-
- cur = 0;
-
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ if (isBinded(DEFAULT_CANVAS)) return;
+ current = DEFAULT_CANVAS;
+ /* get window size as viewport */
Window* wnd = Window::get();
- int ww = wnd->getW(),
- wh = wnd->getH();
+ int ww = wnd->getW();
+ int wh = wnd->getH();
- glViewport(0, 0, ww, wh);
+ glBindFramebuffer(GL_FRAMEBUFFER, DEFAULT_CANVAS->fbo);
- // load back to normal
+ glViewport(0, 0, ww, wh);
+
+ /* set projection matrix */
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
-
- // set viewport matrix
glOrtho(0, ww, wh, 0, -1, 1);
-
- // switch to model matrix
+
+ /* set (model*view) matrix */
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
+
+ /* ready to draw */
}
} // render
} // jin
-#endif // JIN_MODULES_RENDER \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Canvas.h b/libjin/Graphics/Canvas.h
index 0d5635e..a6a52ea 100644
--- a/libjin/Graphics/Canvas.h
+++ b/libjin/Graphics/Canvas.h
@@ -1,40 +1,38 @@
-#ifndef __JIN_CANVAS_H
-#define __JIN_CANVAS_H
+#ifndef __LIBJIN_CANVAS_H
+#define __LIBJIN_CANVAS_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "drawable.h"
namespace jin
{
namespace graphics
{
+
class Canvas: public Drawable
{
public:
-
static Canvas* createCanvas(int w, int h);
-
- ~Canvas();
-
- void bind();
+ static void bind(Canvas*);
static void unbind();
+ static bool isBinded(const Canvas*);
- static bool hasbind(GLint fbo);
-
+ ~Canvas();
+
protected:
+ static const Canvas* const DEFAULT_CANVAS;
+ static const Canvas* current;
Canvas(int w, int h);
+ Canvas(GLuint n);
GLuint fbo;
- // current binded fbo
- static GLint cur;
-
- bool init();
};
+
} // render
} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_CANVAS_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_CANVAS_H \ No newline at end of file
diff --git a/libjin/Graphics/Color.cpp b/libjin/Graphics/Color.cpp
new file mode 100644
index 0000000..414b248
--- /dev/null
+++ b/libjin/Graphics/Color.cpp
@@ -0,0 +1,17 @@
+#include "Color.h"
+
+namespace jin
+{
+namespace graphics
+{
+
+ const Color Color::WHITE = Color(255, 255, 255);
+ const Color Color::BLACK = Color(0, 0, 0);
+ const Color Color::RED = Color(255, 0, 0);
+ const Color Color::GREEN = Color(0, 255, 0);
+ const Color Color::BLUE = Color(0, 0, 255);
+ const Color Color::MAGENTA = Color(255, 0, 255);
+ const Color Color::YELLOW = Color(255, 255, 0);
+
+}
+} \ No newline at end of file
diff --git a/libjin/Graphics/Color.h b/libjin/Graphics/Color.h
index a78234e..a5bc5d0 100644
--- a/libjin/Graphics/Color.h
+++ b/libjin/Graphics/Color.h
@@ -1,10 +1,10 @@
/**
* Some color operating here.
*/
-#ifndef __JIN_COLOR_H
-#define __JIN_COLOR_H
+#ifndef __LIBJIN_COLOR_H
+#define __LIBJIN_COLOR_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "../utils/endian.h"
@@ -13,19 +13,69 @@ namespace jin
namespace graphics
{
- union color {
- struct {
-#if JIN_BYTEORDER == JIN_BIG_ENDIAN
- unsigned char r, g, b, a;
-#else
- unsigned char a, b, g, r;
-#endif
- }rgba;
- int word;
+ class Color
+ {
+ public:
+ /* Built-in Colors */
+ static const Color WHITE;
+ static const Color BLACK;
+ static const Color RED;
+ static const Color GREEN;
+ static const Color BLUE;
+ static const Color MAGENTA;
+ static const Color YELLOW;
+
+ Color() { r = g = b = a = 0; };
+
+ Color(unsigned char _r
+ , unsigned char _g
+ , unsigned char _b
+ , unsigned char _a = 255)
+ {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+
+ Color(const Color& c)
+ {
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+ }
+
+ void operator = (const Color& c)
+ {
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+ }
+
+ bool operator == (const Color& c)
+ {
+ return r == c.r && g == c.g && b == c.b && a == c.a;
+ }
+
+ bool operator != (const Color& c)
+ {
+ return !(r == c.r && g == c.g && b == c.b && a == c.a);
+ }
+
+ unsigned char r, g, b, a;
+
+ //#if LIBJIN_BYTEORDER == LIBJIN_BIG_ENDIAN
+ // unsigned char r, g, b, a;
+ //#else
+ // unsigned char a, b, g, r;
+ //#endif
+
};
} // render
} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_COLOR_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_COLOR_H \ No newline at end of file
diff --git a/libjin/Graphics/Drawable.cpp b/libjin/Graphics/Drawable.cpp
index cab6c50..675c54d 100644
--- a/libjin/Graphics/Drawable.cpp
+++ b/libjin/Graphics/Drawable.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "drawable.h"
#include "../math/matrix.h"
@@ -9,49 +9,36 @@ namespace jin
{
namespace graphics
{
- Drawable::Drawable(int w, int h):texture(0), width(w), height(h), ancx(0), ancy(0), textCoord(0), vertCoord(0)
+
+ Drawable::Drawable(int w, int h)
+ : texture(0)
+ , size(w, h)
+ , anchor(0, 0)
{
}
Drawable::~Drawable()
{
glDeleteTextures(1, &texture);
- delete[] vertCoord;
- delete[] textCoord;
- }
-
- void Drawable::setVertices(float* v, float* t)
- {
- // render area
- if (vertCoord)
- delete[] vertCoord;
- vertCoord = v;
-
- // textrue
- if (textCoord)
- delete[] textCoord;
- textCoord = t;
}
void Drawable::setAnchor(int x, int y)
{
- ancx = x;
- ancy = y;
+ anchor.x = x;
+ anchor.y = y;
}
void Drawable::draw(int x, int y, float sx, float sy, float r)
{
- // Must set textCoord and vertCoord before renderring
+ /* Must set textCoord and vertCoord before renderring */
if (! textCoord||! vertCoord) return;
static jin::math::Matrix t;
- t.setTransformation(x, y, r, sx, sy, ancx, ancy);
-
- glEnable(GL_TEXTURE_2D);
+ t.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y);
glBindTexture(GL_TEXTURE_2D, texture);
- // push modle matrix
+ /* push modle matrix */
glPushMatrix();
glMultMatrixf((const GLfloat*)t.getElements());
@@ -60,18 +47,17 @@ namespace graphics
glTexCoordPointer(2, GL_FLOAT, 0, textCoord);
glVertexPointer(2, GL_FLOAT, 0, vertCoord);
glDrawArrays(GL_QUADS, 0, 4);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- // pop the model matrix
+ /* pop the model matrix */
glPopMatrix();
- // bind texture to default screen
+ /* bind texture to default screen */
glBindTexture(GL_TEXTURE_2D, 0);
-
- glDisable(GL_TEXTURE_2D);
}
+
} // render
} // jin
-#endif // JIN_MODULES_RENDER \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Drawable.h b/libjin/Graphics/Drawable.h
index e04ac6b..ff82365 100644
--- a/libjin/Graphics/Drawable.h
+++ b/libjin/Graphics/Drawable.h
@@ -1,9 +1,11 @@
-#ifndef __JIN_DRAWABLE
-#define __JIN_DRAWABLE
+#ifndef __LIBJIN_DRAWABLE
+#define __LIBJIN_DRAWABLE
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
+#include "../math/Vector2.hpp"
#include "../3rdparty/GLee/GLee.h"
+
namespace jin
{
namespace graphics
@@ -16,45 +18,26 @@ namespace graphics
virtual ~Drawable();
void setAnchor(int x, int y);
-
void draw(int x, int y, float sx, float sy, float r);
-
- inline int getWidth() const
- {
- return width;
- }
-
- inline int getHeight() const
- {
- return height;
- }
-
- inline GLuint getTexture() const
- {
- return texture;
- };
+ inline int getWidth() const { return size.w; }
+ inline int getHeight() const { return size.h; }
+ inline GLuint getTexture() const { return texture; }
protected:
-
- const int DRAWABLE_V_SIZE = 8;
-
- void setVertices(float* v, float* t);
-
- GLuint texture;
-
- int width, height;
+ static const int DRAWABLE_V_SIZE = 8;
+
+ GLuint texture;
+ /* TODO: vertex buffer object */
+ /* GLuint vbo; */
+ jin::math::Vector2<unsigned int> size;
+ jin::math::Vector2<int> anchor;
+ float vertCoord[DRAWABLE_V_SIZE];
+ float textCoord[DRAWABLE_V_SIZE];
- /* anchor point */
- int ancx, ancy;
-
- // render coords
- float* textCoord;
- float* vertCoord;
-
};
-
+
} // render
} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_DRAWABLE \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_DRAWABLE \ No newline at end of file
diff --git a/libjin/Graphics/Font.cpp b/libjin/Graphics/Font.cpp
index a107613..17653f0 100644
--- a/libjin/Graphics/Font.cpp
+++ b/libjin/Graphics/Font.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "font.h"
#include <stdio.h>
@@ -12,183 +12,117 @@ namespace jin
namespace graphics
{
+ using namespace std;
using namespace jin::math;
- const int BITMAP_WIDTH = 512;
- const int BITMAP_HEIGHT = 512;
- const int PIXEL_HEIGHT = 32;
+ const int Font::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
+ const int Font::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
+ /* https://www.zhihu.com/question/23374078 */
+ /* https://blog.csdn.net/carrie0728/article/details/17286043 */
+ /* https://wenku.baidu.com/view/a6fddd07bed5b9f3f90f1ceb.html */
+ /* https://stackoverflow.com/questions/27331819/whats-the-difference-between-a-character-a-code-point-a-glyph-and-a-grapheme */
+ /* utf8 to unicode */
+ static const char *ttf_utf8toCodepoint(const char *p, unsigned *res) {
+ unsigned x, mask, shift;
+ switch (*p & 0xf0) { // 1111 0000
+ case 0xf0 /*1111 0000*/ : mask = 0x07 /*0111*/; shift = 18; break;
+ case 0xe0 /*1110 0000*/: mask = 0x0f /*1111*/; shift = 12; break;
+ case 0xc0 /*1100 0000*/:
+ case 0xd0 /*1101 0000*/: mask = 0x1f /*0001 1111*/; shift = 6; break;
+ default:
+ *res = *p;
+ return p + 1;
+ }
+ x = (*p & mask) << shift;
+ do {
+ /* Return early if we reach an unexpected NULL */
+ if (*(++p) == '\0') {
+ *res = x;
+ return p;
+ }
+ shift -= 6;
+ x |= (*p & 0x3f) << shift;
+ } while (shift);
+ *res = x;
+ return p + 1;
+ }
- Font::Font():Drawable()
+ /*static*/ Font* Font::createFont(const char* font, size_t size)
{
+
}
- // ttf file read buffer
- static unsigned char ttf_buffer[1 << 20];
+ /*static*/ Font* Font::createFont(const char* file)
+ {
- // bitmap for saving font data
- static unsigned char temp_bitmap[BITMAP_WIDTH * BITMAP_HEIGHT];
+ }
- void Font::loadf(const char* path)
+ Font::Font()
+ : textureLevel(TEXTURE_SIZE_LEVEL_MAX)
{
- fread(ttf_buffer, 1, 1 << 20, fopen(path, "rb"));
- loadb(ttf_buffer);
}
- /**
- * load from memory
- */
- void Font::loadb(const unsigned char* data)
+ bool Font::createTexture()
{
- stbtt_BakeFontBitmap(data, 0, PIXEL_HEIGHT, temp_bitmap, BITMAP_WIDTH, BITMAP_HEIGHT, 32, 96, cdata);
-
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, BITMAP_WIDTH,
- BITMAP_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
+ GLuint t;
+ glGenTextures(1, &t);
+ glBindTexture(GL_TEXTURE_2D, t);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ /*Initialize the texture, attempting smaller sizes if initialization fails.*/
+ bool initialized = false;
+ while (textureLevel >= 0)
+ {
+ /*clear errors before initializing*/
+ while (glGetError() != GL_NO_ERROR);
+ textureWidth = TEXTURE_WIDTHS[textureLevel];
+ textureHeight = TEXTURE_HEIGHTS[textureLevel];
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ initialized = (glGetError() == GL_NO_ERROR);
+ if (initialized || textureLevel <= 0)
+ break;
+ --textureLevel;
+ }
+ if (!initialized)
+ {
+ glDeleteTextures(1, &t);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ return false;
+ }
+ textures.push_back(t);
glBindTexture(GL_TEXTURE_2D, 0);
+ return true;
}
- /**
- * get texture quad
- */
- static Quad getCharQuad(const stbtt_bakedchar* chardata, int pw, int ph, int char_index)
+ void Font::print(const char* text, int x, int y)
{
- float ipw = 1.0f / pw, iph = 1.0f / ph;
- const stbtt_bakedchar *b = chardata + char_index;
- Quad q;
- q.x = b->x0 * ipw;
- q.y = b->y0 * iph;
- q.w = b->x1 * ipw - b->x0 * ipw;
- q.h = b->y1 * iph - b->y0 * iph;
- return q;
+ int len = strlen(text);
+ /* xy and uv list */
+ vector<GlyphVertex> glyphvertices(len*4);
+ /* texture binded along with glyphvertices */
+ vector<GlyphArrayDrawInfo> glyphinfolist;
+ float dx = 0;
+ float dy = 0;
+ //float lineheihgt = ;
}
/**
- * render function draw mutiple times
- * in loop
+ * unicodeȾļtextureϣglyphs
*/
- void Font::render(
- const char* text, // rendered text
- float x, float y, // render position
- int fheight, // font height
- int spacing, // font spacing
- int lheight) // line height
+ Glyph* Font::addGlyph(unsigned int character)
{
- float _x = x,
- _y = y;
-
- int len = strlen(text);
-
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, texture);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- // for saving clip quad
- stbtt_aligned_quad q;
-
- // render every given character
- int xc = x;
- int yc = y;
-
- float factor = fheight / (float)PIXEL_HEIGHT;
- for (int i = 0; i < len; ++i)
- {
- char c = text[i];
- if (c == '\n')
- {
- xc = x;
- yc += lheight;
- continue;
- }
-
- // only support ASCII
- Quad q = getCharQuad(cdata, 512, 512, c - 32);
- float s0 = q.x,
- s1 = q.x + q.w,
- t0 = q.y,
- t1 = q.y + q.h;
-
- // texture quad
- float tc[] = {
- s0, t1,
- s1, t1,
- s1, t0,
- s0, t0
- };
-
- // character bound box
- stbtt_bakedchar box = cdata[c - 32];
-
- float width = factor * (box.x1 - box.x0);
- float height = factor * (box.y1 - box.y0);
- float xoffset = factor * box.xoff;
- // I don't know why add PIXEL_HEIGHT to box.yoff, but
- // it works.
- float yoffset = factor * (box.yoff + PIXEL_HEIGHT);
- float xadvance = factor * box.xadvance;
-
- // render quad
- float vc[] = {
- xc + xoffset, yc + height + yoffset,
- xc + width + xoffset, yc + height + yoffset,
- xc + width + xoffset, yc + yoffset,
- xc + xoffset, yc + yoffset
- };
-
- // forward to next character
- xc += xadvance + spacing;
-
- glTexCoordPointer(2, GL_FLOAT, 0, tc);
- glVertexPointer(2, GL_FLOAT, 0, vc);
- glDrawArrays(GL_QUADS, 0, 4);
- }
-
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
}
- void Font::box(const char* str, int fheight, int spacing, int lheight, int* w, int * h)
+ Glyph* Font::findGlyph(unsigned int character)
{
- int len = strlen(str);
-
- float xc = 0;
- int yc = len ? lheight: 0;
- int maxX = 0;
-
- float factor = fheight / (float)PIXEL_HEIGHT;
-
- for (int i = 0; i < len; ++i)
- {
- char c = str[i];
- if (c == '\n')
- {
- yc += lheight;
- xc = 0;
- continue;
- }
- stbtt_bakedchar box = cdata[c - 32];
-
- xc += factor * box.xadvance + spacing;
- if (xc > maxX) maxX = xc;
- }
- *w = maxX;
- *h = yc;
}
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Font.h b/libjin/Graphics/Font.h
index 7fc96e2..10fd242 100644
--- a/libjin/Graphics/Font.h
+++ b/libjin/Graphics/Font.h
@@ -1,8 +1,10 @@
-#ifndef __JIN_FONT_H
-#define __JIN_FONT_H
+#ifndef __LIBJIN_FONT_H
+#define __LIBJIN_FONT_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
+#include <vector>
+#include <map>
#include "drawable.h"
#include "../3rdparty/stb/stb_truetype.h"
#include "../math/quad.h"
@@ -12,50 +14,71 @@ namespace jin
namespace graphics
{
/**
- * Usage of stb_truetype.h here might be a little
- * bit dummy. Implementation of Font is referring
- * to stb_truetype.h L243~284. I basicly copy it:)
+ * original from love2d font and graphics modules
+ * the basic idea is storing glyphs in several mipmap
+ * http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html
*/
- class Font: public Drawable
+
+ struct GlyphVertex
+ {
+ float x, y; // screen coordinates
+ float u, v; // texture coordinates
+ };
+
+ /* track when to change texutre binded in render array */
+ /* casue switch texture is expensive */
+ /* std::vector<GlyphVertex> list */
+ struct GlyphArrayDrawInfo
+ {
+ GLuint texture;
+ int startvertex;
+ int vertexcount;
+ };
+
+ /* glyph texture */
+ struct Glyph
+ {
+ GLuint texture; // texture where this glyph rendered
+ int spacing; // spacing of glyph
+ GlyphVertex vertices[4]; // quad of glyph render region
+ };
+
+ class Font
{
public:
+ static Font* createFont(const char* file);
+ static Font* createFont(const char* data, size_t size);
+
+ void print(const char* text, int x, int y);
+
+ private:
+ /* font atlas levels */
+ static const int TEXTURE_SIZE_LEVELS_COUNT = 7;
+ static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1;
+ static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT];
+ static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT];
+ static const int SPACES_PER_TAB = 4;
+
+ /* create a new mipmap to render glyph and push it on textures */
+ bool createTexture();
+ /* create a glyph for a unicode and return it */
+ Glyph* addGlyph(unsigned int character);
+ /* find glyph by unicode */
+ Glyph* findGlyph(unsigned int character);
+
+ /* list of textures where glyphs rendered, always operate the last one */
+ /* map character to its render area */
+ std::vector<GLuint> textures;
+ std::map<unsigned int, Glyph*> glyphs;
+ /* mipmap size level */
+ int textureLevel;
+ int textureWidth;
+ int textureHeight;
- Font();
-
- /**
- * load ttf font data from .ttf
- */
- void loadf(const char* file);
-
- /**
- * load ttf font data from memory
- */
- void loadb(const unsigned char* data);
-
- /**
- * render text to screen
- */
- void render(
- const char* str, // rendered text
- float x, float y, // render position
- int fheight, // font size
- int spacing, // font spacing
- int lheight // line height
- );
-
- void box(const char* str, int fheight, int spacing, int lheight, int* w, int * h);
-
- private:
-
- /**
- * ASCII 32(space)..126(~) is 95 glyphs
- */
- stbtt_bakedchar cdata[96];
-
};
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_FONT_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_FONT_H \ No newline at end of file
diff --git a/libjin/Graphics/Graphics.h b/libjin/Graphics/Graphics.h
index 210dadf..dfd6048 100644
--- a/libjin/Graphics/Graphics.h
+++ b/libjin/Graphics/Graphics.h
@@ -1,15 +1,16 @@
-#ifndef __JIN_GRAPHICS_H
-#define __JIN_GRAPHICS_H
+#ifndef __LIBJIN_GRAPHICS_H
+#define __LIBJIN_GRAPHICS_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "canvas.h"
#include "color.h"
#include "font.h"
#include "Shapes.h"
#include "texture.h"
-#include "jsl.h"
+#include "Shader.h"
#include "window.h"
+#include "Bitmap.h"
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_GRAPHICS_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_GRAPHICS_H \ No newline at end of file
diff --git a/libjin/Graphics/JSL.cpp b/libjin/Graphics/JSL.cpp
deleted file mode 100644
index 2ab7ceb..0000000
--- a/libjin/Graphics/JSL.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-#include "../modules.h"
-#if JIN_MODULES_RENDER
-
-#include "../utils/macros.h"
-#include "jsl.h"
-namespace jin
-{
-namespace graphics
-{
- //vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
- static const char* base_f = " "
- //"#version 120 \n"
- "#define number float \n"
- "#define Image sampler2D \n"
- "#define Canvas sampler2D \n"
- "#define Color vec4 \n"
- "#define Texel texture2D \n"
- "#define extern uniform \n"
- "uniform Image _tex0_; \n"
- "%s \n"
- "void main(){ \n"
- " gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);\n"
- "}\0";
-
- /*static*/ JSLProgram* JSLProgram::currentJSLProgram = nullptr;
-
- JSLProgram* JSLProgram::createJSLProgram(const char* program)
- {
- return new JSLProgram(program);
- }
-
- JSLProgram::JSLProgram(const char* program)
- : currentTextureUnit(0)
- {
- initialize(program);
- }
-
- JSLProgram::~JSLProgram()
- {
- destroy();
- }
-
- inline void JSLProgram::destroy()
- {
- if (currentJSLProgram == this)
- unuse();
- }
-
- inline void JSLProgram::initialize(const char* program)
- {
- char* fs = (char*)alloca(strlen(program) + strlen(base_f));
- sprintf(fs, base_f, program);
- GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragmentShader, 1, (const GLchar**)&fs, NULL);
- glCompileShader(fragmentShader);
-
- pid = glCreateProgram();
- glAttachShader(pid, fragmentShader);
- glLinkProgram(pid);
- }
-
- static inline GLint getMaxTextureUnits()
- {
- GLint maxTextureUnits = 0;
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
- return maxTextureUnits;
- }
-
- GLint JSLProgram::getTextureUnit(const std::string& name)
- {
- std::map<std::string, GLint>::iterator texture_unit = texturePool.find(name);
- if (texture_unit != texturePool.end())
- return texture_unit->second;
- static GLint maxTextureUnits = getMaxTextureUnits();
- if (++currentTextureUnit >= maxTextureUnits)
- return 0;
- texturePool[name] = currentTextureUnit;
- return currentTextureUnit;
- }
-
-#define checkJSL() if (currentJSLProgram != this) return
-
- void JSLProgram::sendFloat(const char* variable, float number)
- {
- checkJSL();
-
- int loc = glGetUniformLocation(pid, variable);
- glUniform1f(loc, number);
- }
-
- void JSLProgram::sendTexture(const char* variable, const Texture* tex)
- {
- checkJSL();
-
- GLint location = glGetUniformLocation(pid, variable);
- if (location == -1)
- return;
- GLint texture_unit = getTextureUnit(variable);
- glUniform1i(location, texture_unit);
- glActiveTexture(GL_TEXTURE0 + texture_unit);
- glBindTexture(GL_TEXTURE_2D, tex->getTexture());
- glActiveTexture(GL_TEXTURE0);
- }
-
- void JSLProgram::sendCanvas(const char* variable, const Canvas* canvas)
- {
- checkJSL();
-
- GLint location = glGetUniformLocation(pid, variable);
- if (location == -1)
- return;
- GLint texture_unit = getTextureUnit(variable);
- glUniform1i(location, texture_unit);
- glActiveTexture(GL_TEXTURE0 + texture_unit);
- glBindTexture(GL_TEXTURE_2D, canvas->getTexture());
- glActiveTexture(GL_TEXTURE0);
- }
-
- void JSLProgram::sendVec2(const char* name, float x, float y)
- {
- checkJSL();
-
- int loc = glGetUniformLocation(pid, name);
- glUniform2f(loc, x, y);
- }
-
- void JSLProgram::sendVec3(const char* name, float x, float y, float z)
- {
- checkJSL();
-
- int loc = glGetUniformLocation(pid, name);
- glUniform3f(loc, x, y, z);
- }
-
- void JSLProgram::sendVec4(const char* name, float x, float y, float z, float w)
- {
- checkJSL();
-
- int loc = glGetUniformLocation(pid, name);
- glUniform4f(loc, x, y, z, w);
- }
-
- void JSLProgram::sendColor(const char* name, const color* col)
- {
- checkJSL();
-
- int loc = glGetUniformLocation(pid, name);
- glUniform4f(loc,
- col->rgba.r / 255.f,
- col->rgba.g / 255.f,
- col->rgba.b / 255.f,
- col->rgba.a / 255.f
- );
- }
-
-}
-}
-
-#endif // JIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Shader.cpp b/libjin/Graphics/Shader.cpp
new file mode 100644
index 0000000..e882d35
--- /dev/null
+++ b/libjin/Graphics/Shader.cpp
@@ -0,0 +1,222 @@
+#include "../modules.h"
+#if LIBJIN_MODULES_RENDER
+
+#include "../utils/macros.h"
+#include "Shader.h"
+#include "../Filesystem/Buffer.h"
+namespace jin
+{
+namespace graphics
+{
+
+ using namespace jin::filesystem;
+
+ /**
+ * default_texture
+ * base_shader
+ * SHADER_FORMAT_SIZE
+ * formatShader
+ */
+ #include "base.shader.h"
+
+ /**
+ * https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value
+ * The default value of a sampler variable is 0. From the GLSL 3.30 spec,
+ * section "4.3.5 Uniforms":
+ *
+ * The link time initial value is either the value of the variable's
+ * initializer, if present, or 0 if no initializer is present.Sampler
+ * types cannot have initializers.
+ *
+ * Since a value of 0 means that it's sampling from texture unit 0, it will
+ * work without ever setting the value as long as you bind your textures to
+ * unit 0. This is well defined behavior.
+ *
+ * Since texture unit 0 is also the default until you call glActiveTexture()
+ * with a value other than GL_TEXTURE0, it's very common to always use unit
+ * 0 as long as shaders do not need more than one texture.Which means that
+ * often times, setting the sampler uniforms is redundant for simple
+ * applications.
+ *
+ * I would still prefer to always set the values.If nothing else, it makes
+ * it clear to anybody reading your code that you really mean to sample from
+ * texture unit 0, and did not just forget to set the value.
+ */
+ const int DEFAULT_TEXTURE_UNIT = 0;
+
+ /*static*/ JSLProgram* JSLProgram::currentJSLProgram = nullptr;
+
+ JSLProgram* JSLProgram::createJSLProgram(const char* program)
+ {
+ JSLProgram* jsl = nullptr;
+ try
+ {
+ jsl = new JSLProgram(program);
+ }
+ catch(...)
+ {
+ return nullptr;
+ }
+ return jsl;
+ }
+
+ JSLProgram::JSLProgram(const char* program)
+ : currentTextureUnit(DEFAULT_TEXTURE_UNIT)
+ {
+ Buffer b = Buffer(strlen(program) + SHADER_FORMAT_SIZE);
+ formatShader((char*)b.data, program);
+ GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(shader, 1, (const GLchar**)&b.data, NULL);
+ glCompileShader(shader);
+ GLint success;
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
+ if (success == GL_FALSE)
+ throw 0;
+ pid = glCreateProgram();
+ glAttachShader(pid, shader);
+ glLinkProgram(pid);
+ glGetProgramiv(pid, GL_LINK_STATUS, &success);
+ if (success == GL_FALSE)
+ throw 0;
+ }
+
+ JSLProgram::~JSLProgram()
+ {
+ if (currentJSLProgram == this)
+ unuse();
+ }
+
+ static inline GLint getMaxTextureUnits()
+ {
+ GLint maxTextureUnits = 0;
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
+ return maxTextureUnits;
+ }
+
+ void JSLProgram::use()
+ {
+ glUseProgram(pid);
+ currentJSLProgram = this;
+ /* bind default texture */
+ int loc = glGetUniformLocation(pid, default_texture);
+ glUniform1i(loc, DEFAULT_TEXTURE_UNIT);
+ }
+
+ /*static*/ void JSLProgram::unuse()
+ {
+ glUseProgram(0);
+ currentJSLProgram = nullptr;
+ }
+
+ GLint JSLProgram::claimTextureUnit(const std::string& name)
+ {
+ std::map<std::string, GLint>::iterator unit = textureUnits.find(name);
+ if (unit != textureUnits.end())
+ return unit->second;
+ static GLint MAX_TEXTURE_UNITS = getMaxTextureUnits();
+ if (++currentTextureUnit >= MAX_TEXTURE_UNITS)
+ return 0;
+ textureUnits[name] = currentTextureUnit;
+ return currentTextureUnit;
+ }
+
+#define checkJSL() \
+ if (currentJSLProgram != this) \
+ return
+
+ void JSLProgram::sendFloat(const char* variable, float number)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(pid, variable);
+ glUniform1f(loc, number);
+ }
+
+ /**
+ * https://www.douban.com/note/627332677/
+ * struct TextureUnit
+ * {
+ * GLuint targetTexture1D;
+ * GLuint targetTexture2D;
+ * GLuint targetTexture3D;
+ * GLuint targetTextureCube;
+ * ...
+ * };
+ *
+ * TextureUnit textureUnits[GL_MAX_TEXTURE_IMAGE_UNITS]
+ * GLuint currentTextureUnit = 0;
+ */
+ void JSLProgram::sendTexture(const char* variable, const Texture* tex)
+ {
+ checkJSL();
+ GLint location = glGetUniformLocation(pid, variable);
+ if (location == -1)
+ return;
+ GLint unit = claimTextureUnit(variable);
+ if (unit == 0)
+ {
+ // TODO: 쳣󶨵
+ return;
+ }
+ glUniform1i(location, unit);
+ glActiveTexture(GL_TEXTURE0 + unit);
+ glBindTexture(GL_TEXTURE_2D, tex->getTexture());
+
+ glActiveTexture(GL_TEXTURE0);
+ }
+
+ void JSLProgram::sendCanvas(const char* variable, const Canvas* canvas)
+ {
+ checkJSL();
+ GLint location = glGetUniformLocation(pid, variable);
+ if (location == -1)
+ return;
+ GLint unit = claimTextureUnit(variable);
+ if (unit == 0)
+ {
+ // TODO: 쳣󶨵
+ return;
+ }
+ glUniform1i(location, unit);
+ glActiveTexture(GL_TEXTURE0 + unit);
+ glBindTexture(GL_TEXTURE_2D, canvas->getTexture());
+
+ glActiveTexture(GL_TEXTURE0);
+ }
+
+ void JSLProgram::sendVec2(const char* name, float x, float y)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(pid, name);
+ glUniform2f(loc, x, y);
+ }
+
+ void JSLProgram::sendVec3(const char* name, float x, float y, float z)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(pid, name);
+ glUniform3f(loc, x, y, z);
+ }
+
+ void JSLProgram::sendVec4(const char* name, float x, float y, float z, float w)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(pid, name);
+ glUniform4f(loc, x, y, z, w);
+ }
+
+ void JSLProgram::sendColor(const char* name, const Color* col)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(pid, name);
+ glUniform4f(loc,
+ col->r / 255.f,
+ col->g / 255.f,
+ col->b / 255.f,
+ col->a / 255.f
+ );
+ }
+
+} // graphics
+} // jin
+
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/JSL.h b/libjin/Graphics/Shader.h
index 8d4712b..83a2831 100644
--- a/libjin/Graphics/JSL.h
+++ b/libjin/Graphics/Shader.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_JSL_H
-#define __JIN_JSL_H
+#ifndef __LIBJIN_JSL_H
+#define __LIBJIN_JSL_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include <string>
#include <map>
@@ -15,60 +15,39 @@ namespace jin
namespace graphics
{
+ /* Jin Shader Language Program*/
class JSLProgram
{
-
public:
-
static JSLProgram* createJSLProgram(const char* program);
+ static inline JSLProgram* getCurrentJSL() { return currentJSLProgram; }
+ static void unuse();
virtual ~JSLProgram();
- inline void use()
- {
- glUseProgram(pid);
- currentJSLProgram = this;
- }
-
- static inline void unuse()
- {
- glUseProgram(0);
- currentJSLProgram = nullptr;
- }
-
+ void use();
void sendFloat(const char* name, float number);
void sendTexture(const char* name, const Texture* image);
void sendVec2(const char* name, float x, float y);
void sendVec3(const char* name, float x, float y, float z);
void sendVec4(const char* name, float x, float y, float z, float w);
void sendCanvas(const char* name, const Canvas* canvas);
- void sendColor(const char* name, const color* col);
-
- static inline JSLProgram* getCurrentJSL()
- {
- return currentJSLProgram;
- }
+ void sendColor(const char* name, const Color* col);
protected:
+ static JSLProgram* currentJSLProgram;
+ GLint claimTextureUnit(const std::string& name);
JSLProgram(const char* program);
- static JSLProgram* currentJSLProgram;
-
GLuint pid;
-
- std::map<std::string, GLint> texturePool;
-
GLint currentTextureUnit;
- GLint getTextureUnit(const std::string& name);
-
- inline void initialize(const char* program);
- inline void destroy();
+ std::map<std::string, GLint> textureUnits;
};
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_JSL_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_JSL_H \ No newline at end of file
diff --git a/libjin/Graphics/Shapes.cpp b/libjin/Graphics/Shapes.cpp
index 4b136a1..2cb33a2 100644
--- a/libjin/Graphics/Shapes.cpp
+++ b/libjin/Graphics/Shapes.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "Shapes.h"
#include "../math/matrix.h"
@@ -23,28 +23,25 @@ namespace graphics
void points(int n, GLshort* p)
{
glEnableClientState(GL_VERTEX_ARRAY);
-
glVertexPointer(2, GL_SHORT, 0, (GLvoid*)p);
glDrawArrays(GL_POINTS, 0, n);
-
glDisableClientState(GL_VERTEX_ARRAY);
}
void line(int x1, int y1, int x2, int y2)
{
- glDisable(GL_TEXTURE_2D);
float verts[] = {
x1, y1,
x2, y2
};
glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts);
+ glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)verts);
glDrawArrays(GL_LINES, 0, 2);
glDisableClientState(GL_VERTEX_ARRAY);
}
- void circle(RENDER_MODE mode, int x, int y, int r)
+ void circle(RenderMode mode, int x, int y, int r)
{
r = r < 0 ? 0 : r;
@@ -69,13 +66,13 @@ namespace graphics
delete[] coords;
}
- void rect(RENDER_MODE mode, int x, int y, int w, int h)
+ void rect(RenderMode mode, int x, int y, int w, int h)
{
float coords[] = { x, y, x + w, y, x + w, y + h, x, y + h };
polygon(mode, coords, 4);
}
- void triangle(RENDER_MODE mode, int x1, int y1, int x2, int y2, int x3, int y3)
+ void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3)
{
float coords[] = { x1, y1, x2, y2, x3, y3 };
polygon(mode, coords, 3);
@@ -83,25 +80,13 @@ namespace graphics
void polygon_line(float* p, int count)
{
- float* verts = new float[count * 4];
- for (int i = 0; i < count; ++i)
- {
- // each line has two point n,n+1
- verts[i * 4] = p[i * 2];
- verts[i * 4 + 1] = p[i * 2 + 1];
- verts[i * 4 + 2] = p[(i + 1) % count * 2];
- verts[i * 4 + 3] = p[(i + 1) % count * 2 + 1];
- }
-
glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts);
- glDrawArrays(GL_LINES, 0, count * 2);
+ glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p);
+ glDrawArrays(GL_LINE_LOOP, 0, count);
glDisableClientState(GL_VERTEX_ARRAY);
-
- delete[] verts;
}
- void polygon(RENDER_MODE mode, float* p, int count)
+ void polygon(RenderMode mode, float* p, int count)
{
if (mode == LINE)
{
@@ -116,7 +101,7 @@ namespace graphics
}
}
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Shapes.h b/libjin/Graphics/Shapes.h
index afd4f7a..dc9f272 100644
--- a/libjin/Graphics/Shapes.h
+++ b/libjin/Graphics/Shapes.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_GEOMETRY_H
-#define __JIN_GEOMETRY_H
+#ifndef __LIBJIN_GEOMETRY_H
+#define __LIBJIN_GEOMETRY_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "color.h"
#include "canvas.h"
@@ -16,28 +16,22 @@ namespace graphics
NONE = 0,
FILL ,
LINE
- }RENDER_MODE;
+ }RenderMode;
/**
* TODO:
- * drawPixels(int n, points)
+ * drawPixels(int n, points)
*/
extern void line(int x1, int y1, int x2, int y2);
-
- extern void rect(RENDER_MODE mode, int x, int y, int w, int h);
-
- extern void triangle(RENDER_MODE mode, int x1, int y1, int x2, int y2, int x3, int y3);
-
- extern void circle(RENDER_MODE mode, int x, int y, int r);
-
+ extern void rect(RenderMode mode, int x, int y, int w, int h);
+ extern void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3);
+ extern void circle(RenderMode mode, int x, int y, int r);
extern void point(int x, int y);
-
extern void points(int n, GLshort* p, GLubyte* c);
+ extern void polygon(RenderMode mode, float* p, int count);
- extern void polygon(RENDER_MODE mode, float* p, int count);
-
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_GEOMETRY_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_GEOMETRY_H \ No newline at end of file
diff --git a/libjin/Graphics/Texture.cpp b/libjin/Graphics/Texture.cpp
index 4c6707d..9ffe946 100644
--- a/libjin/Graphics/Texture.cpp
+++ b/libjin/Graphics/Texture.cpp
@@ -1,9 +1,8 @@
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include <fstream>
#include "texture.h"
-#include "../3rdparty/stb/stb_image.h"
#include "../utils/utils.h"
#include "../Math/Math.h"
@@ -14,89 +13,44 @@ namespace graphics
using namespace jin::math;
- Texture* Texture::createTexture(const char* file)
+ /*static*/ Texture* Texture::createTexture(Bitmap* bitmap)
{
- std::ifstream fs;
- fs.open(file, std::ios::binary);
- Texture* tex = nullptr;
- if (fs.is_open())
- {
- fs.seekg(0, std::ios::end);
- int size = fs.tellg();
- fs.seekg(0, std::ios::beg);
- char* buffer = (char*)malloc(size);
- memset(buffer, 0, size);
- fs.read(buffer, size);
- tex = createTexture(buffer, size);
- free(buffer);
- }
- fs.close();
- return tex;
- }
+ Texture* tex = new Texture();
+ const Color* pixels = bitmap->getPixels();
+ tex->size.w = bitmap->getWidth();
+ tex->size.h = bitmap->getHeight();
+ unsigned int w = tex->size.w;
+ unsigned int h = tex->size.h;
+
+ glGenTextures(1, &tex->texture);
+ glBindTexture(GL_TEXTURE_2D, tex->texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+ tex->vertCoord[0] = 0; tex->vertCoord[1] = 1;
+ tex->vertCoord[2] = 0; tex->vertCoord[3] = h;
+ tex->vertCoord[4] = w; tex->vertCoord[5] = h;
+ tex->vertCoord[6] = w; tex->vertCoord[7] = 1;
+
+ tex->textCoord[0] = 0; tex->textCoord[1] = 0;
+ tex->textCoord[2] = 0; tex->textCoord[3] = 1;
+ tex->textCoord[4] = 1; tex->textCoord[5] = 1;
+ tex->textCoord[6] = 1; tex->textCoord[7] = 0;
- Texture* Texture::createTexture(const void* mem, size_t size)
- {
- Texture* tex = new Texture();
- if(!tex->loadb(mem, size))
- {
- delete tex;
- tex = nullptr;
- }
return tex;
}
Texture::Texture()
- : Drawable(), pixels(0)
+ : Drawable()
{
}
Texture::~Texture()
{
- stbi_image_free(pixels);
}
- color Texture::getPixel(int x, int y)
- {
- if (without(x, 0, width) || without(y, 0, height))
- {
- return { 0 };
- }
- return pixels[x + y * width];
- }
-
- bool Texture::loadb(const void* b, size_t size)
- {
- // ʹstbi_load_from_memory
- unsigned char* textureData = stbi_load_from_memory((unsigned char *)b, size, &width, &height, NULL, STBI_rgb_alpha);
- if (textureData == 0) return false;
- pixels = (color*)textureData;
-
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width,
- height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
-
- // set render vertices
- Drawable::setVertices(
- new float [DRAWABLE_V_SIZE] {
- 0, 0,
- 0, (float)height,
- (float)width, (float)height,
- (float)width, 0,
- },
- new float [DRAWABLE_V_SIZE] {
- 0, 0,
- 0, 1,
- 1, 1,
- 1, 0
- }
- );
-
- return true;
- }
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Texture.h b/libjin/Graphics/Texture.h
index 47f8d53..f2e45f0 100644
--- a/libjin/Graphics/Texture.h
+++ b/libjin/Graphics/Texture.h
@@ -1,11 +1,12 @@
-#ifndef __JIN_IMAGE_H
-#define __JIN_IMAGE_H
+#ifndef __LIBJIN_IMAGE_H
+#define __LIBJIN_IMAGE_H
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "../3rdparty/GLee/GLee.h"
-#include "color.h"
-#include "drawable.h"
+#include "Color.h"
+#include "Drawable.h"
+#include "Bitmap.h"
namespace jin
{
namespace graphics
@@ -13,28 +14,18 @@ namespace graphics
class Texture: public Drawable
{
-
public:
-
- static Texture* createTexture(const char* file);
- static Texture* createTexture(const void* mem, size_t size);
+ static Texture* createTexture(Bitmap* bitmap);
~Texture();
- color getPixel(int x, int y);
-
private:
-
Texture();
- bool loadb(const void* buffer, size_t size);
-
- color* pixels;
-
};
-}
-}
+} // graphics
+} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_IMAGE_H \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_IMAGE_H \ No newline at end of file
diff --git a/libjin/Graphics/Window.cpp b/libjin/Graphics/Window.cpp
index 708a30f..1fb60cc 100644
--- a/libjin/Graphics/Window.cpp
+++ b/libjin/Graphics/Window.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include <iostream>
#include "window.h"
@@ -16,16 +16,16 @@ namespace graphics
bool Window::initSystem(const SettingBase* s)
{
-#if JIN_DEBUG
+#if LIBJIN_DEBUG
Loghelper::log(Loglevel::LV_INFO, "Init window system");
-#endif // JIN_DEBUG
+#endif
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return false;
const Setting* setting = (Setting*)s;
- width = setting->width;
- height = setting->height;
+ size.w = setting->width;
+ size.h = setting->height;
fps = setting->fps;
bool vsync = setting->vsync;
const char* title = setting->title;
@@ -59,7 +59,7 @@ namespace graphics
if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
- wnd = SDL_CreateWindow(title, wx, wy, width, height, flag);
+ wnd = SDL_CreateWindow(title, wx, wy, size.w, size.h, flag);
if (wnd == NULL)
return false;
ctx = SDL_GL_CreateContext(wnd);
@@ -67,31 +67,41 @@ namespace graphics
return false;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
SDL_GL_MakeCurrent(wnd, ctx);
+ /* default configuration */
glClearColor(0.f, 0.f, 0.f, 1.f);
- glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glColor4f(1, 1, 1, 1);
-
glEnable(GL_BLEND);
+ glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- Canvas::unbind();
+ /* avoid white screen blink on windows */
swapBuffers();
+ /* bind to default canvas */
+ Canvas::unbind();
return true;
}
void Window::quitSystem()
{
+ /* disable opengl */
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+ /* close window */
SDL_DestroyWindow(wnd);
SDL_Quit();
}
- inline void Window::swapBuffers()
+ void Window::swapBuffers()
{
if (wnd)
SDL_GL_SwapWindow(wnd);
}
+ void Window::setTitle(const char* title)
+ {
+ SDL_SetWindowTitle(wnd, title);
+ };
+
} // graphics
} // jin
-#endif // JIN_MODULES_RENDER \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER \ No newline at end of file
diff --git a/libjin/Graphics/Window.h b/libjin/Graphics/Window.h
index e4939f6..6b247a6 100644
--- a/libjin/Graphics/Window.h
+++ b/libjin/Graphics/Window.h
@@ -1,10 +1,11 @@
-#ifndef __JIN_RENDER_WINDOW
-#define __JIN_RENDER_WINDOW
+#ifndef __LIBJIN_RENDER_WINDOW
+#define __LIBJIN_RENDER_WINDOW
#include "../modules.h"
-#if JIN_MODULES_RENDER
+#if LIBJIN_MODULES_RENDER
#include "SDL2/SDL.h"
#include "../utils/utils.h"
+#include "../math/Vector2.hpp"
#include "../common/Subsystem.hpp"
namespace jin
@@ -15,7 +16,6 @@ namespace graphics
class Window : public Subsystem<Window>
{
public:
-
struct Setting : SettingBase
{
public:
@@ -27,29 +27,29 @@ namespace graphics
bool resizable; // resize
};
- inline int getW(){ return width; }
- inline int getH(){ return height; }
+ void setTitle(const char* title);
+ inline int getW(){ return size.w; }
+ inline int getH(){ return size.h; }
inline int getFPS(){ return fps; }
- inline void swapBuffers();
+ void swapBuffers();
private:
+ SINGLETON(Window);
Window() {};
- virtual ~Window() {};
- SINGLETON(Window);
+ virtual ~Window() {};
+ bool initSystem(const SettingBase* setting) override;
+ void quitSystem() override;
SDL_Window* wnd;
-
- int width, height;
+ jin::math::Vector2<unsigned int> size;
int fps;
- /*call only once*/ bool initSystem(const SettingBase* setting) override;
- /*call only once*/ void quitSystem() override;
};
} // render
} // jin
-#endif // JIN_MODULES_RENDER
-#endif // __JIN_RENDER_WINDOW \ No newline at end of file
+#endif // LIBJIN_MODULES_RENDER
+#endif // __LIBJIN_RENDER_WINDOW \ No newline at end of file
diff --git a/libjin/Graphics/base.shader.h b/libjin/Graphics/base.shader.h
new file mode 100644
index 0000000..080e27e
--- /dev/null
+++ b/libjin/Graphics/base.shader.h
@@ -0,0 +1,34 @@
+/*
+ * https://stackoverflow.com/questions/10868958/what-does-sampler2d-store
+ * The sampler2D is bound to a texture unit. The glUniform call binds it to texture
+ * unit zero. The glActiveTexture call is only needed if you are going to use multiple
+ * texture units (because GL_TEXTURE0 is the default anyway).
+*/
+
+static const char* default_texture = "_tex0_";
+
+static const char* base_shader = R"(
+#define number float
+#define Texture sampler2D
+#define Canvas sampler2D
+#define Color vec4
+#define Texel texture2D
+#define extern uniform
+#define Vec2 vec2
+#define Vec3 vec3
+#define Vec4 vec4
+#define Number number
+#define Image Texture
+
+extern Texture %s;
+%s
+void main()
+{
+ gl_FragColor = effect(gl_Color, %s, gl_TexCoord[0].xy, gl_FragCoord.xy);
+}
+)";
+
+static const int SHADER_FORMAT_SIZE = strlen(base_shader) + strlen(default_texture) * 2;
+
+#define formatShader(buf, program)\
+ sprintf(buf, base_shader, default_texture, program, default_texture)
diff --git a/libjin/Input/Event.cpp b/libjin/Input/Event.cpp
index 8eb45e6..3edff01 100644
--- a/libjin/Input/Event.cpp
+++ b/libjin/Input/Event.cpp
@@ -4,4 +4,4 @@
namespace jin
{
-} \ No newline at end of file
+} // jin \ No newline at end of file
diff --git a/libjin/Input/Event.h b/libjin/Input/Event.h
index 9feb3a5..cef6b88 100644
--- a/libjin/Input/Event.h
+++ b/libjin/Input/Event.h
@@ -1,13 +1,13 @@
-#ifndef __JIN_EVENT_H
-#define __JIN_EVENT_H
+#ifndef __LIBJIN_EVENT_H
+#define __LIBJIN_EVENT_H
#include "../modules.h"
-#if JIN_MODULES_INPUT
+#if LIBJIN_MODULES_INPUT
namespace jin
{
namespace input
{
-#if JIN_INPUT_SDL
+#if LIBJIN_INPUT_SDL
#include "SDL.h"
typedef SDL_Event Event;
@@ -16,13 +16,27 @@ namespace input
enum EventType {
QUIT = SDL_QUIT,
+ /* keyboard events */
KEY_DOWN = SDL_KEYDOWN,
KEY_UP = SDL_KEYUP,
+ /* mouse events */
MOUSE_MOTION = SDL_MOUSEMOTION,
MOUSE_BUTTON_DOWN = SDL_MOUSEBUTTONDOWN,
MOUSE_BUTTON_UP = SDL_MOUSEBUTTONUP,
MOUSE_WHEEL = SDL_MOUSEWHEEL,
- WINDOW_EVENT = SDL_WINDOWEVENT,
+ /* joypad events */
+ JOYBUTTONDOWN = SDL_JOYBUTTONDOWN,
+ JOYBUTTONUP = SDL_JOYBUTTONUP,
+ JOYAXISMOTION = SDL_JOYAXISMOTION,
+ JOYBALLMOTION = SDL_JOYBALLMOTION,
+ JOYHATMOTION = SDL_JOYHATMOTION,
+ JOYDEVICEADDED = SDL_JOYDEVICEADDED,
+ JOYDEVICEREMOVED = SDL_JOYDEVICEREMOVED,
+ CONTROLLERBUTTONDOWN = SDL_CONTROLLERBUTTONDOWN,
+ CONTROLLERBUTTONUP = SDL_CONTROLLERBUTTONUP,
+ CONTROLLERAXISMOTION = SDL_CONTROLLERAXISMOTION,
+ /* window evnets */
+ WINDOW_EVENT = SDL_WINDOWEVENT,
};
enum WindowEvent {
@@ -58,11 +72,11 @@ namespace input
{
switch (button)
{
- case 1: return "left";
- case 2: return "middle";
- case 3: return "right";
- case 4: return "wheelup";
- case 5: return "wheeldown";
+ case 1: return "Left";
+ case 2: return "Middle";
+ case 3: return "Right";
+ case 4: return "WheelUp";
+ case 5: return "WheelDown";
default: return "?";
}
}
@@ -83,9 +97,9 @@ namespace input
}
*/
-#endif // JIN_INPUT_SDL
+#endif // LIBJIN_INPUT_SDL
} // input
} // jin
-#endif // JIN_MODULES_INPUT
+#endif // LIBJIN_MODULES_INPUT
#endif \ No newline at end of file
diff --git a/libjin/Input/Input.h b/libjin/Input/Input.h
index 217edd2..a828ac7 100644
--- a/libjin/Input/Input.h
+++ b/libjin/Input/Input.h
@@ -1,8 +1,9 @@
-#ifndef __JIN_INPUT_H
-#define __JIN_INPUT_H
+#ifndef __LIBJIN_INPUT_H
+#define __LIBJIN_INPUT_H
#include "event.h"
#include "keyboard.h"
#include "mouse.h"
+#include "joypad.h"
#endif \ No newline at end of file
diff --git a/libjin/Input/Joypad.h b/libjin/Input/Joypad.h
index e8d309b..b630aa5 100644
--- a/libjin/Input/Joypad.h
+++ b/libjin/Input/Joypad.h
@@ -1,14 +1,50 @@
-#ifndef __JIN_JOYPAD_H
-#define __JIN_JOYPAD_H
+#ifndef __LIBJIN_JOYPAD_H
+#define __LIBJIN_JOYPAD_H
+
+#include <SDL2/SDL.h>
namespace jin
{
namespace input
{
+ inline const char* getJoyButtonName(int button)
+ {
+ switch (button)
+ {
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_A: return "A"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_B : return "B"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_X : return "X"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_Y: return "Y"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_BACK: return "Back"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_GUIDE: return "Guide"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_START: return "Start"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_LEFTSTICK: return "LeftStick"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_RIGHTSTICK: return "RightStick"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_LEFTSHOULDER: return "LeftShoulder"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: return "RightShoulder"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_DPAD_UP: return "DpadUp"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_DPAD_DOWN: return "DpadDown"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_DPAD_LEFT: return "DpadLeft"; break;
+ case SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_DPAD_RIGHT: return "DpadRight"; break;
+ default: return NULL;
+ }
+ }
+ inline const char* getJoyAxisName(int axis)
+ {
+ switch (axis)
+ {
+ case SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_LEFTX: return "LeftX"; break;
+ case SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_LEFTY: return "LeftY"; break;
+ case SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_RIGHTX: return "RightX"; break;
+ case SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_RIGHTY: return "RightY"; break;
+ case SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_TRIGGERLEFT: return "TriggerLeft"; break;
+ case SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_TRIGGERRIGHT: return "TriggerRight"; break;
+ }
+ }
-}
-}
+} // input
+} // jin
#endif \ No newline at end of file
diff --git a/libjin/Input/Keyboard.h b/libjin/Input/Keyboard.h
index 3e78ab1..250e8f0 100644
--- a/libjin/Input/Keyboard.h
+++ b/libjin/Input/Keyboard.h
@@ -1,15 +1,17 @@
-#ifndef __JIN_KEYBOARD_H
-#define __JIN_KEYBOARD_H
+#ifndef __LIBJIN_KEYBOARD_H
+#define __LIBJIN_KEYBOARD_H
namespace jin
{
namespace input
{
+
class Keyboard
{
};
-}
-}
-#endif // __JIN_KEYBOARD_H \ No newline at end of file
+} // input
+} // jin
+
+#endif // __LIBJIN_KEYBOARD_H \ No newline at end of file
diff --git a/libjin/Input/Mouse.cpp b/libjin/Input/Mouse.cpp
index 98c4a39..892d140 100644
--- a/libjin/Input/Mouse.cpp
+++ b/libjin/Input/Mouse.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#ifdef JIN_MODULES_INPUT
+#ifdef LIBJIN_MODULES_INPUT
#include "SDL.h"
#include "Mouse.h"
@@ -11,12 +11,17 @@ namespace input
void Mouse::getState(int* x, int* y)
{
-#ifdef JIN_INPUT_SDL
+ #ifdef LIBJIN_INPUT_SDL
SDL_GetMouseState(x, y);
-#endif // JIN_INPUT_SDL
+ #endif // LIBJIN_INPUT_SDL
+ }
+
+ void Mouse::setVisible(bool visible)
+ {
+ SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
}
} // input
} // jin
-#endif // JIN_MODULES_INPUT \ No newline at end of file
+#endif // LIBJIN_MODULES_INPUT \ No newline at end of file
diff --git a/libjin/Input/Mouse.h b/libjin/Input/Mouse.h
index 5fc6b47..25dd4c3 100644
--- a/libjin/Input/Mouse.h
+++ b/libjin/Input/Mouse.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_MOUSE_H
-#define __JIN_MOUSE_H
+#ifndef __LIBJIN_MOUSE_H
+#define __LIBJIN_MOUSE_H
#include "../modules.h"
-#ifdef JIN_MODULES_INPUT
+#ifdef LIBJIN_MODULES_INPUT
#include "../Common/Singleton.hpp"
@@ -9,21 +9,23 @@ namespace jin
{
namespace input
{
+
class Mouse : public Singleton<Mouse>
{
public:
-
- //
void getState(int* x, int* y);
+ void setVisible(bool visible);
private:
+ SINGLETON(Mouse);
+
Mouse() {};
~Mouse() {};
- SINGLETON(Mouse);
};
-}
-}
-#endif // JIN_MODULES_INPUT
-#endif // __JIN_MOUSE_H \ No newline at end of file
+} // input
+} // jin
+
+#endif // LIBJIN_MODULES_INPUT
+#endif // __LIBJIN_MOUSE_H \ No newline at end of file
diff --git a/libjin/Math/Math.h b/libjin/Math/Math.h
index 2bc8ed9..6eb4367 100644
--- a/libjin/Math/Math.h
+++ b/libjin/Math/Math.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_UTILS_MATH_H
-#define __JIN_UTILS_MATH_H
+#ifndef __LIBJIN_UTILS_MATH_H
+#define __LIBJIN_UTILS_MATH_H
#include "constant.h"
#include "matrix.h"
@@ -71,7 +71,7 @@ namespace math
return a + t * (b - a);
}
-}
-}
+} // math
+} // jin
#endif \ No newline at end of file
diff --git a/libjin/Math/Matrix.cpp b/libjin/Math/Matrix.cpp
index 97e9178..39042f0 100644
--- a/libjin/Math/Matrix.cpp
+++ b/libjin/Math/Matrix.cpp
@@ -173,5 +173,5 @@ namespace math
}
}
-}
-} \ No newline at end of file
+} // math
+} // jin \ No newline at end of file
diff --git a/libjin/Math/Matrix.h b/libjin/Math/Matrix.h
index ff4a51a..b9a55d4 100644
--- a/libjin/Math/Matrix.h
+++ b/libjin/Math/Matrix.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_MATRIX_H
-#define __JIN_MATRIX_H
+#ifndef __LIBJIN_MATRIX_H
+#define __LIBJIN_MATRIX_H
namespace jin
{
@@ -147,7 +147,7 @@ namespace math
};
-}
-}
+} // math
+} // jin
-#endif
+#endif \ No newline at end of file
diff --git a/libjin/Math/Quad.h b/libjin/Math/Quad.h
index a50cc9e..ed41270 100644
--- a/libjin/Math/Quad.h
+++ b/libjin/Math/Quad.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_QUAD_H
-#define __JIN_QUAD_H
+#ifndef __LIBJIN_QUAD_H
+#define __LIBJIN_QUAD_H
namespace jin
{
@@ -11,7 +11,7 @@ namespace math
float x, y, w, h;
};
-}
-}
+} // math
+} // jin
-#endif
+#endif \ No newline at end of file
diff --git a/libjin/Math/Vector.cpp b/libjin/Math/Vector.cpp
deleted file mode 100644
index f26d0c4..0000000
--- a/libjin/Math/Vector.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "vector.h"
-
diff --git a/libjin/Math/Vector.h b/libjin/Math/Vector.h
deleted file mode 100644
index 43e249e..0000000
--- a/libjin/Math/Vector.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __JIN_VECTOR_H
-#define __JIN_VECTOR_H
-
-namespace jin
-{
-namespace math
-{
-
-
-
-}
-}
-
-#endif \ No newline at end of file
diff --git a/libjin/Math/Vector2.hpp b/libjin/Math/Vector2.hpp
new file mode 100644
index 0000000..bee22f3
--- /dev/null
+++ b/libjin/Math/Vector2.hpp
@@ -0,0 +1,39 @@
+#ifndef __LIBJIN_VECTOR_H
+#define __LIBJIN_VECTOR_H
+
+namespace jin
+{
+namespace math
+{
+
+ template<typename T>
+ class Vector2
+ {
+ public:
+ Vector2()
+ {
+ data[0] = data[1] = 0;
+ }
+ Vector2(T _x, T _y)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ }
+ Vector2(const Vector2<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ }
+
+ T &x = data[0], &y = data[1]; // xy
+ T &w = data[0], &h = data[1]; // wh
+
+ private:
+ T data[2];
+
+ };
+
+} // math
+} // jin
+
+#endif \ No newline at end of file
diff --git a/libjin/Math/Vector3.hpp b/libjin/Math/Vector3.hpp
new file mode 100644
index 0000000..77fa006
--- /dev/null
+++ b/libjin/Math/Vector3.hpp
@@ -0,0 +1,41 @@
+#ifndef __LIBJIN_VECTOR3_H
+#define __LIBJIN_VECTOR3_H
+
+namespace jin
+{
+namespace math
+{
+
+ template<typename T>
+ class Vector3
+ {
+ public:
+ Vector3()
+ {
+ data[0] = data[1] = data[2] = 0;
+ }
+ Vector3(T _x, T _y, T _z)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ data[2] = _z;
+ }
+ Vector3(const Vector3<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ data[2] = v.data[2];
+ }
+
+ T &x = data[0], &y = data[1], &z = data[2]; // xyz
+ T &r = data[0], &g = data[1], &b = data[2]; // rgb
+
+ private:
+ T data[3];
+
+ };
+
+} // math
+} // jin
+
+#endif \ No newline at end of file
diff --git a/libjin/Math/Vector4.hpp b/libjin/Math/Vector4.hpp
new file mode 100644
index 0000000..c7dfaa8
--- /dev/null
+++ b/libjin/Math/Vector4.hpp
@@ -0,0 +1,44 @@
+#ifndef __LIBJIN_VECTOR4_H
+#define __LIBJIN_VECTOR4_H
+
+namespace jin
+{
+namespace math
+{
+
+ template<typename T>
+ class Vector4
+ {
+ public:
+ Vector4()
+ {
+ data[0] = data[1] = data[2] = data[3] = 0;
+ }
+ Vector4(T _x, T _y, T _z, T _t)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ data[2] = _z;
+ data[3] = _t;
+ }
+ Vector4(const Vector4<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ data[2] = v.data[2];
+ data[3] = v.data[3];
+ }
+
+ T &x = data[0], &y = data[1], &z = data[2], &t = data[3]; // xyzt
+ T &w = data[2], &h = data[3]; // xywh
+ T &r = data[0], &g = data[1], &b = data[2], &a = data[3]; // rgb
+
+ private:
+ T data[4];
+
+ };
+
+} // math
+} // jin
+
+#endif \ No newline at end of file
diff --git a/libjin/Math/constant.h b/libjin/Math/constant.h
index f2f740f..f8e0f5a 100644
--- a/libjin/Math/constant.h
+++ b/libjin/Math/constant.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_MATH_CONSTANT_H
-#define __JIN_MATH_CONSTANT_H
+#ifndef __LIBJIN_MATH_CONSTANT_H
+#define __LIBJIN_MATH_CONSTANT_H
#define PI 3.1415926f
diff --git a/libjin/Net/Net.cpp b/libjin/Net/Net.cpp
index db39be7..e6c3d98 100644
--- a/libjin/Net/Net.cpp
+++ b/libjin/Net/Net.cpp
@@ -8,7 +8,7 @@ namespace net
bool Net::initSystem(const SettingBase* setting)
{
#ifdef _WIN32
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
tk_init();
#endif
#endif
@@ -20,5 +20,5 @@ namespace net
}
-}
-}
+} // net
+} // jin \ No newline at end of file
diff --git a/libjin/Net/Net.h b/libjin/Net/Net.h
index 54ffede..4727667 100644
--- a/libjin/Net/Net.h
+++ b/libjin/Net/Net.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_NET_H
-#define __JIN_NET_H
+#ifndef __LIBJIN_NET_H
+#define __LIBJIN_NET_H
#include "../modules.h"
-#if JIN_MODULES_NET
+#if LIBJIN_MODULES_NET
#include "../Common/Subsystem.hpp"
#include "Socket.h"
@@ -16,15 +16,16 @@ namespace net
public:
protected:
+ SINGLETON(Net);
Net() {};
~Net() {};
- SINGLETON(Net);
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
+
};
-}
-}
+} // net
+} // jin
-#endif // JIN_MODULES_NET
-#endif // __JIN_NET_H \ No newline at end of file
+#endif // LIBJIN_MODULES_NET
+#endif // __LIBJIN_NET_H
diff --git a/libjin/Net/Socket.cpp b/libjin/Net/Socket.cpp
index cfc593a..32d160c 100644
--- a/libjin/Net/Socket.cpp
+++ b/libjin/Net/Socket.cpp
@@ -32,7 +32,7 @@ namespace net
if (type == SocketType::TCP)
{
tk_IPaddress ip;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
ip.host = tk_strtohl(address);
ip.port = port;
handle.tcpHandle = tk_tcp_open(ip);
@@ -76,7 +76,7 @@ namespace net
}
}
-#if JIN_NET_TEKCOS
+#if LIBJIN_NET_TEKCOS
Socket::Socket(const tk_TCPsocket& tcphandle)
{
@@ -88,7 +88,7 @@ namespace net
handle.udpHandle = udphandle;
}
-#endif // JIN_NET_TEKCOS
+#endif // LIBJIN_NET_TEKCOS
Socket::~Socket()
{
@@ -98,7 +98,7 @@ namespace net
{
if (type != SocketType::TCP)
return;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
if (blocking)
tk_tcp_blocking(&handle.tcpHandle);
else
@@ -111,7 +111,7 @@ namespace net
if (type != SocketType::TCP)
return nullptr;
Socket* client;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
tk_TCPsocket socket = tk_tcp_accept(&handle.tcpHandle);
client = new Socket(socket);
#endif
@@ -122,7 +122,7 @@ namespace net
{
if (type != SocketType::TCP)
return 0;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
int len;
tk_tcp_recv(&handle.tcpHandle, buffer, size, &len);
return len;
@@ -133,7 +133,7 @@ namespace net
{
if (type != SocketType::TCP)
return 0;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
int len;
tk_tcp_send(&handle.tcpHandle, buffer, size, &len);
return len;
@@ -144,7 +144,7 @@ namespace net
{
if (type != SocketType::UDP)
return;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
tk_UDPpack pack;
pack.data = buffer;
pack.len = size;
@@ -159,7 +159,7 @@ namespace net
if (type != SocketType::UDP)
return 0;
int len;
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
tk_UDPpack pack;
pack.data = buffer;
pack.len = size;
@@ -174,17 +174,17 @@ namespace net
{
if (type == SocketType::TCP)
{
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
tk_tcp_close(&handle.tcpHandle);
#endif
}
else if (type == SocketType::UDP)
{
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
tk_udp_close(&handle.udpHandle);
#endif
}
}
-}
-} \ No newline at end of file
+} // net
+} // jin \ No newline at end of file
diff --git a/libjin/Net/Socket.h b/libjin/Net/Socket.h
index 6d9e09b..1a2256c 100644
--- a/libjin/Net/Socket.h
+++ b/libjin/Net/Socket.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_NET_SOCKET_H
-#define __JIN_NET_SOCKET_H
+#ifndef __LIBJIN_NET_SOCKET_H
+#define __LIBJIN_NET_SOCKET_H
#include "../modules.h"
-#if JIN_MODULES_NET
+#if LIBJIN_MODULES_NET
#include "../3rdparty/tekcos/tekcos.h"
@@ -33,7 +33,6 @@ namespace net
Socket(SocketType type, unsigned int address, unsigned short port);
Socket(SocketType type, const char* address, unsigned short port);
~Socket();
-
void configureBlocking(bool bocking);
Socket* accept();
int receive(char* buffer, int size);
@@ -43,7 +42,7 @@ namespace net
void close();
protected:
- #if JIN_NET_TEKCOS
+ #if LIBJIN_NET_TEKCOS
Socket(const tk_TCPsocket& tcpHandle);
Socket(const tk_UDPsocket& udpHandle);
union
@@ -53,10 +52,11 @@ namespace net
} handle;
#endif
SocketType type;
+
};
} // net
} // jin
-#endif // JIN_MODULES_NET
-#endif // __JIN_NET_SOCKET_H \ No newline at end of file
+#endif // LIBJIN_MODULES_NET
+#endif // __LIBJIN_NET_SOCKET_H
diff --git a/libjin/Thread/Thread.cpp b/libjin/Thread/Thread.cpp
index 13e691a..c2b7b91 100644
--- a/libjin/Thread/Thread.cpp
+++ b/libjin/Thread/Thread.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_THREAD
+#if LIBJIN_MODULES_THREAD
#include "Thread.h"
@@ -17,7 +17,7 @@ namespace thread
void lock();
void unlock();
private:
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_mutex* mutex;
#endif
friend class Conditional;
@@ -33,7 +33,7 @@ namespace thread
void broadcast();
bool wait(Mutex* mutex, int timeout = -1);
private:
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_cond* cond;
#endif
};
@@ -63,28 +63,28 @@ namespace thread
Mutex::Mutex()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
mutex = SDL_CreateMutex();
#endif
}
Mutex::~Mutex()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_DestroyMutex(mutex);
#endif
}
void Mutex::lock()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_LockMutex(mutex);
#endif
}
void Mutex::unlock()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_UnlockMutex(mutex);
#endif
}
@@ -93,35 +93,35 @@ namespace thread
Conditional::Conditional()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
cond = SDL_CreateCond();
#endif
}
Conditional::~Conditional()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_DestroyCond(cond);
#endif
}
void Conditional::signal()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_CondSignal(cond);
#endif
}
void Conditional::broadcast()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_CondBroadcast(cond);
#endif
}
bool Conditional::wait(Mutex* mutex, int timeout)
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
if (timeout < 0)
return !SDL_CondWait(cond, mutex->mutex);
else
@@ -183,7 +183,7 @@ namespace thread
Thread::~Thread()
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
#endif
}
@@ -206,13 +206,13 @@ namespace thread
return false;
if (handle)
{
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_WaitThread(handle, nullptr);
#endif
}
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
handle = SDL_CreateThread(threadRunner, name.c_str(), p);
- #elif JIN_THREAD_CPP
+ #elif LIBJIN_THREAD_CPP
handle = new std::thread();
#endif
return (running = (handle != nullptr));
@@ -225,7 +225,7 @@ namespace thread
if (!handle)
return;
}
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_WaitThread(handle, nullptr);
#endif
Lock l(mutex);
@@ -298,4 +298,4 @@ namespace thread
} // thread
} // jin
-#endif // JIN_MODULES_THREAD \ No newline at end of file
+#endif // LIBJIN_MODULES_THREAD \ No newline at end of file
diff --git a/libjin/Thread/Thread.h b/libjin/Thread/Thread.h
index 046c8f6..3c41949 100644
--- a/libjin/Thread/Thread.h
+++ b/libjin/Thread/Thread.h
@@ -1,13 +1,13 @@
-#ifndef __JIN_THREAD_H
-#define __JIN_THREAD_H
+#ifndef __LIBJIN_THREAD_H
+#define __LIBJIN_THREAD_H
#include "../modules.h"
-#if JIN_MODULES_THREAD
+#if LIBJIN_MODULES_THREAD
#include <string>
#include <map>
-#if JIN_THREAD_SDL
+#if LIBJIN_THREAD_SDL
# include "SDL2/SDL_thread.h"
-#elif JIN_THREAD_CPP
+#elif LIBJIN_THREAD_CPP
# include <thread>
# include <mutex>
# include <condition_variable>
@@ -78,26 +78,29 @@ namespace thread
class ThreadData
{
public:
+ static const int SLOT_ERROR = -1;
+ static const int SLOT_WARN = -2;
+ static const int SLOT_INFO = -3;
+ static const int SLOT_DEBUG = -4;
+
ThreadData(Mutex*, Conditional*);
~ThreadData();
bool exist(int slot);
void set(int slot, Variant value);
Variant get(int slot);
void remove(int slot);
+
Conditional* condition;
Mutex* mutex;
- static const int SLOT_ERROR = -1;
- static const int SLOT_WARN = -2;
- static const int SLOT_INFO = -3;
- static const int SLOT_DEBUG = -4;
-
private:
std::map<int, Variant> share; // threads shared value
+
};
public:
typedef int(*ThreadRunner)(void* obj);
+
Thread(const std::string name, ThreadRunner threadfuncs);
~Thread();
bool start(void* p);
@@ -113,9 +116,9 @@ namespace thread
void unlock();
protected:
- #if JIN_THREAD_SDL
+ #if LIBJIN_THREAD_SDL
SDL_Thread* handle; // SDL thread
- #elif JIN_THREAD_CPP
+ #elif LIBJIN_THREAD_CPP
std::thread* handle; // cpp thread
#endif
Mutex* mutex; // mutex variable
@@ -159,5 +162,5 @@ namespace thread
} // thread
} // jin
-#endif // JIN_MODULES_THREAD
-#endif // __JIN_THREAD_H \ No newline at end of file
+#endif // LIBJIN_MODULES_THREAD
+#endif // __LIBJIN_THREAD_H \ No newline at end of file
diff --git a/libjin/Time/Timer.cpp b/libjin/Time/Timer.cpp
index cfdb4bd..e5d0799 100644
--- a/libjin/Time/Timer.cpp
+++ b/libjin/Time/Timer.cpp
@@ -1,5 +1,5 @@
#include "../modules.h"
-#if JIN_MODULES_TIME
+#if LIBJIN_MODULES_TIME
#include "Timer.h"
@@ -94,7 +94,7 @@ namespace time
return true;
}
-}
-}
+} // time
+} // jin
-#endif // JIN_MODULES_TIME \ No newline at end of file
+#endif // LIBJIN_MODULES_TIME
diff --git a/libjin/Time/Timer.h b/libjin/Time/Timer.h
index 173cd95..aff2f70 100644
--- a/libjin/Time/Timer.h
+++ b/libjin/Time/Timer.h
@@ -1,7 +1,7 @@
-#ifndef __JIN_TIMER_H
-#define __JIN_TIMER_H
+#ifndef __LIBJIN_TIMER_H
+#define __LIBJIN_TIMER_H
#include "../modules.h"
-#if JIN_MODULES_TIME
+#if LIBJIN_MODULES_TIME
#include "SDL2/SDL.h"
#include <vector>
@@ -18,9 +18,7 @@ namespace time
Timers();
~Timers();
-
void update(int ms);
-
void every(int ms, timer_callback callback, void* paramters);
void after(int ms, timer_callback callback, void* paramters);
void repeat(int ms, int count, timer_callback callback, void* paramters);
@@ -48,25 +46,26 @@ namespace time
void* paramters;
};
std::vector<Timer*> timers;
+
};
inline void sleep(int ms)
{
- #if JIN_TIME_SDL
+ #if LIBJIN_TIME_SDL
SDL_Delay(ms);
#endif
}
inline double getSecond()
{
- #if JIN_TIME_SDL
+ #if LIBJIN_TIME_SDL
return SDL_GetTicks() / 1000.f;
#endif
}
inline double getMilliSecond()
{
- #if JIN_TIME_SDL
+ #if LIBJIN_TIME_SDL
return SDL_GetTicks();
#endif
}
@@ -74,5 +73,5 @@ namespace time
} // time
} // jin
-#endif // JIN_MODULES_TIME
-#endif // __JIN_TIMER_H \ No newline at end of file
+#endif // LIBJIN_MODULES_TIME
+#endif // __LIBJIN_TIMER_H
diff --git a/libjin/Utils/endian.h b/libjin/Utils/endian.h
index d4c441a..01def88 100644
--- a/libjin/Utils/endian.h
+++ b/libjin/Utils/endian.h
@@ -1,23 +1,23 @@
-#ifndef JIN_LIL_ENDIAN && JIN_BIG_ENDIAN
+#ifndef LIBJIN_LIL_ENDIAN && LIBJIN_BIG_ENDIAN
-#define JIN_LIL_ENDIAN 2
-#define JIN_BIG_ENDIAN 4
+#define LIBJIN_LIL_ENDIAN 2
+#define LIBJIN_BIG_ENDIAN 4
#endif
-#ifndef JIN_BYTEORDER
+#ifndef LIBJIN_BYTEORDER
#ifdef __linux__
#include <endian.h>
-#define JIN_BYTEORDER __BYTE_ORDER
+#define LIBJIN_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
+#define LIBJIN_BYTEORDER LIBJIN_BIG_ENDIAN
#else
-#define JIN_BYTEORDER JIN_LIL_ENDIAN
+#define LIBJIN_BYTEORDER LIBJIN_LIL_ENDIAN
#endif
#endif /* __linux__ */
#endif /* !SDL_BYTEORDER */ \ No newline at end of file
diff --git a/libjin/Utils/macros.h b/libjin/Utils/macros.h
index 290bcf7..e19193c 100644
--- a/libjin/Utils/macros.h
+++ b/libjin/Utils/macros.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_MACROS_H
-#define __JIN_MACROS_H
+#ifndef __LIBJIN_MACROS_H
+#define __LIBJIN_MACROS_H
#include <cstring>
//#define implement // ʵֽӿ
diff --git a/libjin/Utils/utils.h b/libjin/Utils/utils.h
index cf0920e..1654a8f 100644
--- a/libjin/Utils/utils.h
+++ b/libjin/Utils/utils.h
@@ -1,5 +1,5 @@
-#ifndef __JIN_UTILS_H
-#define __JIN_UTILS_H
+#ifndef __LIBJIN_UTILS_H
+#define __LIBJIN_UTILS_H
#include "macros.h"
#include "endian.h"
diff --git a/libjin/jin.h b/libjin/jin.h
index 239fddd..a4bb37f 100644
--- a/libjin/jin.h
+++ b/libjin/jin.h
@@ -1,23 +1,25 @@
-#ifndef __JIN_H
-#define __JIN_H
+#ifndef __LIBJIN_H
+#define __LIBJIN_H
#include "modules.h"
#include "Utils/utils.h"
-#ifdef JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
+#ifdef LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
#include "Audio/SDL/SDLAudio.h"
-#endif // JIN_MODULES_AUDIO && JIN_AUDIO_SDLAUDIO
+#endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO
#include "Core/Core.h"
#include "Filesystem/Filesystem.h"
+#include "Filesystem/Buffer.h"
#include "Input/Input.h"
#include "Net/Net.h"
#include "Graphics/Graphics.h"
#include "Time/Timer.h"
#include "Thread/Thread.h"
+#include "Common/common.h"
-#define JIN_VERSION "Jin 0.1";
-#define JIN_AUTHOR "Chai";
-#define JIN_RELEASE "Jin 0.1.1";
-#define JIN_VERSION_NUM 101;
+#define LIBJIN_VERSION "Jin 0.1";
+#define LIBJIN_AUTHOR "Chai";
+#define LIBJIN_RELEASE "Jin 0.1.1";
+#define LIBJIN_VERSION_NUM 101;
-#endif // __JIN_H \ No newline at end of file
+#endif // __LIBJIN_H \ No newline at end of file
diff --git a/libjin/modules.h b/libjin/modules.h
index 5992f0c..83eb90b 100644
--- a/libjin/modules.h
+++ b/libjin/modules.h
@@ -1,64 +1,64 @@
-#ifndef __JIN_COMMON_MODULES_H
-#define __JIN_COMMON_MODULES_H
+#ifndef __LIBJIN_COMMON_MODULES_H
+#define __LIBJIN_COMMON_MODULES_H
/*
* ģģı룬Ҫģرղ
*/
-#define JIN_MODULES_AUDIO 1
-#define JIN_AUDIO_SDLAUDIO 1
-#define JIN_AUDIO_OPENAL 1
+#define LIBJIN_MODULES_AUDIO 1
+#define LIBJIN_AUDIO_SDLAUDIO 1
+#define LIBJIN_AUDIO_OPENAL 1
-#define JIN_MODULES_RENDER 1
+#define LIBJIN_MODULES_RENDER 1
-#define JIN_MODULES_DEBUG 1
+#define LIBJIN_MODULES_DEBUG 1
-#define JIN_MODULES_FILESYSTEM 1
+#define LIBJIN_MODULES_FILESYSTEM 1
-#define JIN_MODULES_INPUT 1
-#define JIN_INPUT_SDL 1
+#define LIBJIN_MODULES_INPUT 1
+#define LIBJIN_INPUT_SDL 1
-#define JIN_MODULES_MATH 1
+#define LIBJIN_MODULES_MATH 1
-#define JIN_MODULES_NET 1
-#define JIN_NET_TEKCOS 1
+#define LIBJIN_MODULES_NET 1
+#define LIBJIN_NET_TEKCOS 1
-#define JIN_MODULES_PHYSICS 0
-#define JIN_PHYSICS_BOX2D 1
-#define JIN_PHYSICS_NEWTON 1
+#define LIBJIN_MODULES_PHYSICS 0
+#define LIBJIN_PHYSICS_BOX2D 1
+#define LIBJIN_PHYSICS_NEWTON 1
-#define JIN_MODULES_TILEMAP 1
+#define LIBJIN_MODULES_TILEMAP 1
-#define JIN_MODULES_UI 1
+#define LIBJIN_MODULES_UI 1
-#define JIN_MODULES_TOOLS 0
-#define JIN_TOOLS_COMPONENT 1
-#define JIN_TOOLS_EVENTMSGCENTER 1
-#define JIN_TOOLS_XML 1
-#define JIN_TOOLS_CSV 1
-#define JIN_TOOLS_JSON 1
+#define LIBJIN_MODULES_TOOLS 0
+#define LIBJIN_TOOLS_COMPONENT 1
+#define LIBJIN_TOOLS_EVENTMSGCENTER 1
+#define LIBJIN_TOOLS_XML 1
+#define LIBJIN_TOOLS_CSV 1
+#define LIBJIN_TOOLS_JSON 1
-#define JIN_MODULES_THREAD 1
-#define JIN_THREAD_SDL 1
-#define JIN_THREAD_CPP 0
-#define JIN_THREAD_PTHREAD 0
+#define LIBJIN_MODULES_THREAD 1
+#define LIBJIN_THREAD_SDL 1
+#define LIBJIN_THREAD_CPP 0
+#define LIBJIN_THREAD_PTHREAD 0
-#define JIN_MODULES_TIME 1
-#define JIN_TIME_SDL 1
+#define LIBJIN_MODULES_TIME 1
+#define LIBJIN_TIME_SDL 1
/*
* Open libjin debug
*/
-#define JIN_DEBUG 0
+#define LIBJIN_DEBUG 0
/*
* Operating system
*/
-#define JIN_WINDOWS 1
-#define JIN_MACOS 2
-#define JIN_LINUX 3
+#define LIBJIN_WINDOWS 1
+#define LIBJIN_MACOS 2
+#define LIBJIN_LINUX 3
-#define JIN_OS JIN_WINDOWS
+#define LIBJIN_OS LIBJIN_WINDOWS
#endif \ No newline at end of file