aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libjin/audio/SDL/je_sdl_audio.cpp6
-rw-r--r--src/libjin/audio/SDL/je_sdl_audio.h6
-rw-r--r--src/libjin/audio/SDL/je_sdl_source.cpp32
-rw-r--r--src/libjin/audio/SDL/je_sdl_source.h6
-rw-r--r--src/libjin/audio/je_audio_manager.cpp6
-rw-r--r--src/libjin/audio/je_audio_manager.h46
-rw-r--r--src/libjin/audio/je_source.cpp30
-rw-r--r--src/libjin/audio/je_source.h54
-rw-r--r--src/libjin/common/je_subsystem.hpp8
-rw-r--r--src/libjin/filesystem/je_asset_database.cpp100
-rw-r--r--src/libjin/filesystem/je_asset_database.h32
-rw-r--r--src/libjin/filesystem/je_buffer.h74
-rw-r--r--src/libjin/game/je_application.cpp104
-rw-r--r--src/libjin/game/je_application.h58
-rw-r--r--src/libjin/graphics/fonts/je_decoder.cpp6
-rw-r--r--src/libjin/graphics/fonts/je_decoder.h6
-rw-r--r--src/libjin/graphics/fonts/je_font.h6
-rw-r--r--src/libjin/graphics/fonts/je_page.h6
-rw-r--r--src/libjin/graphics/fonts/je_text.cpp6
-rw-r--r--src/libjin/graphics/fonts/je_text.h6
-rw-r--r--src/libjin/graphics/fonts/je_texture_font.cpp12
-rw-r--r--src/libjin/graphics/fonts/je_texture_font.h6
-rw-r--r--src/libjin/graphics/fonts/je_ttf.cpp48
-rw-r--r--src/libjin/graphics/fonts/je_ttf.h6
-rw-r--r--src/libjin/graphics/je_bitmap.cpp200
-rw-r--r--src/libjin/graphics/je_bitmap.h44
-rw-r--r--src/libjin/graphics/je_canvas.cpp56
-rw-r--r--src/libjin/graphics/je_canvas.h22
-rw-r--r--src/libjin/graphics/je_color.cpp20
-rw-r--r--src/libjin/graphics/je_color.h116
-rw-r--r--src/libjin/graphics/je_gl.cpp8
-rw-r--r--src/libjin/graphics/je_gl.h16
-rw-r--r--src/libjin/graphics/je_graphic.h40
-rw-r--r--src/libjin/graphics/je_image.cpp16
-rw-r--r--src/libjin/graphics/je_image.h26
-rw-r--r--src/libjin/graphics/je_mesh.cpp6
-rw-r--r--src/libjin/graphics/je_mesh.h16
-rw-r--r--src/libjin/graphics/je_shapes.cpp188
-rw-r--r--src/libjin/graphics/je_shapes.h30
-rw-r--r--src/libjin/graphics/je_sprite.h4
-rw-r--r--src/libjin/graphics/je_texture.cpp30
-rw-r--r--src/libjin/graphics/je_texture.h18
-rw-r--r--src/libjin/graphics/je_window.cpp154
-rw-r--r--src/libjin/graphics/je_window.h56
-rw-r--r--src/libjin/graphics/shaders/je_base.shader.h19
-rw-r--r--src/libjin/graphics/shaders/je_shader.cpp10
-rw-r--r--src/libjin/graphics/shaders/je_shader.h6
-rw-r--r--src/libjin/input/je_keyboard.h12
-rw-r--r--src/libjin/input/je_mouse.cpp26
-rw-r--r--src/libjin/input/je_mouse.h18
-rw-r--r--src/libjin/math/je_math.h98
-rw-r--r--src/libjin/math/je_matrix.cpp372
-rw-r--r--src/libjin/math/je_matrix.h300
-rw-r--r--src/libjin/math/je_quad.h14
-rw-r--r--src/libjin/math/je_vector2.hpp54
-rw-r--r--src/libjin/math/je_vector3.hpp56
-rw-r--r--src/libjin/math/je_vector4.hpp64
-rw-r--r--src/libjin/net/je_net_manager.cpp30
-rw-r--r--src/libjin/net/je_net_manager.h22
-rw-r--r--src/libjin/net/je_socket.cpp366
-rw-r--r--src/libjin/net/je_socket.h86
-rw-r--r--src/libjin/threads/je_thread.cpp576
-rw-r--r--src/libjin/threads/je_thread.h268
-rw-r--r--src/libjin/time/je_timer.cpp132
-rw-r--r--src/libjin/time/je_timer.h68
-rw-r--r--src/lua/embed/scripts/boot.lua.h8
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp6
-rw-r--r--src/lua/modules/audio/je_lua_source.cpp16
-rw-r--r--src/lua/modules/bit/je_lua_bit.cpp1
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp10
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp256
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_text.cpp28
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp8
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp80
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp34
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp6
-rw-r--r--src/lua/modules/net/je_lua_buffer.cpp18
-rw-r--r--src/lua/modules/net/je_lua_net.cpp2
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp22
-rw-r--r--src/lua/modules/thread/je_lua_thread.cpp30
-rw-r--r--src/lua/modules/thread/je_lua_thread.h10
82 files changed, 2434 insertions, 2436 deletions
diff --git a/src/libjin/audio/SDL/je_sdl_audio.cpp b/src/libjin/audio/SDL/je_sdl_audio.cpp
index b89e8d3..f401502 100644
--- a/src/libjin/audio/SDL/je_sdl_audio.cpp
+++ b/src/libjin/audio/SDL/je_sdl_audio.cpp
@@ -13,8 +13,8 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
namespace SDL
{
@@ -140,7 +140,7 @@ namespace JinEngine
}
} // namespace SDL
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // (jin_audio) && (jin_audio == jin_audio_sdl) \ No newline at end of file
diff --git a/src/libjin/audio/SDL/je_sdl_audio.h b/src/libjin/audio/SDL/je_sdl_audio.h
index 4263767..5db1698 100644
--- a/src/libjin/audio/SDL/je_sdl_audio.h
+++ b/src/libjin/audio/SDL/je_sdl_audio.h
@@ -11,8 +11,8 @@
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
namespace SDL
{
@@ -128,7 +128,7 @@ namespace JinEngine
};
} // namespace SDL
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // (jin_audio) && (jin_audio == jin_audio_sdl)
diff --git a/src/libjin/audio/SDL/je_sdl_source.cpp b/src/libjin/audio/SDL/je_sdl_source.cpp
index 90f8daa..39472fd 100644
--- a/src/libjin/audio/SDL/je_sdl_source.cpp
+++ b/src/libjin/audio/SDL/je_sdl_source.cpp
@@ -19,8 +19,8 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
namespace SDL
{
@@ -162,21 +162,21 @@ namespace JinEngine
}
#define ActionNone(T)\
- do{\
- Command* cmd = Manager::get()->getCommand();\
- cmd->action = Action::T; \
- cmd->source = this; \
- Manager::get()->pushCommand(cmd); \
- } while (0)
+ do{\
+ Command* cmd = Manager::get()->getCommand();\
+ cmd->action = Action::T; \
+ cmd->source = this; \
+ Manager::get()->pushCommand(cmd); \
+ } while (0)
#define ActionArg(T, ARGT, ARG)\
- do{\
- Command* cmd = Manager::get()->getCommand();\
- cmd->action = Action::T; \
- cmd->parameter.ARGT = ARG; \
- cmd->source = this; \
- Manager::get()->pushCommand(cmd); \
- }while(0)
+ do{\
+ Command* cmd = Manager::get()->getCommand();\
+ cmd->action = Action::T; \
+ cmd->parameter.ARGT = ARG; \
+ cmd->source = this; \
+ Manager::get()->pushCommand(cmd); \
+ }while(0)
#define ActionInt(T, INT) ActionArg(T, _integer, INT)
#define ActionFloat(T, FLT) ActionArg(T, _float, FLT)
@@ -388,7 +388,7 @@ namespace JinEngine
}
} // namespace SDL
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // (jin_audio) && (jin_audio == jin_audio_sdl) \ No newline at end of file
diff --git a/src/libjin/audio/SDL/je_sdl_source.h b/src/libjin/audio/SDL/je_sdl_source.h
index 8a3309e..3f1c10f 100644
--- a/src/libjin/audio/SDL/je_sdl_source.h
+++ b/src/libjin/audio/SDL/je_sdl_source.h
@@ -12,8 +12,8 @@
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
namespace SDL
{
@@ -257,7 +257,7 @@ namespace JinEngine
};
} // namespace SDL
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // (jin_audio) && (jin_audio == jin_audio_sdl)
diff --git a/src/libjin/audio/je_audio_manager.cpp b/src/libjin/audio/je_audio_manager.cpp
index e451aa3..1fdc6ef 100644
--- a/src/libjin/audio/je_audio_manager.cpp
+++ b/src/libjin/audio/je_audio_manager.cpp
@@ -6,10 +6,10 @@
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // jin_audio
diff --git a/src/libjin/audio/je_audio_manager.h b/src/libjin/audio/je_audio_manager.h
index e0c7a4b..cc6d65b 100644
--- a/src/libjin/audio/je_audio_manager.h
+++ b/src/libjin/audio/je_audio_manager.h
@@ -11,27 +11,27 @@
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
- class Source;
+ class Source;
///
/// Audio manager.
///
- template<class SubAudio>
- class AudioManager : public Subsystem<SubAudio>
- {
- public:
+ template<class SubAudio>
+ class AudioManager : public Subsystem<SubAudio>
+ {
+ public:
///
/// Audio state.
///
- enum State
- {
- PLAY ,
- STOP ,
- PAUSE,
- };
+ enum State
+ {
+ PLAY ,
+ STOP ,
+ PAUSE,
+ };
///
/// AudioManager constructor.
@@ -49,35 +49,35 @@ namespace JinEngine
///
/// Play all sources whose state is playing.
///
- virtual void play() = 0;
+ virtual void play() = 0;
///
/// Stop and remove all sources from the queue.
///
- virtual void stop() = 0;
+ virtual void stop() = 0;
///
/// Pause audio.
///
- virtual void pause() = 0;
+ virtual void pause() = 0;
///
/// Resume audio.
///
- virtual void resume() = 0;
+ virtual void resume() = 0;
///
/// Set global audio volume.
///
- virtual void setVolume(float volume) = 0;
+ virtual void setVolume(float volume) = 0;
- protected:
- float volume;
- State state;
+ protected:
+ float volume;
+ State state;
- };
+ };
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // jin_audio
diff --git a/src/libjin/audio/je_source.cpp b/src/libjin/audio/je_source.cpp
index 6bc1f4f..382e820 100644
--- a/src/libjin/audio/je_source.cpp
+++ b/src/libjin/audio/je_source.cpp
@@ -7,24 +7,24 @@
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
- static int check_header(const void *data, int size, const char *str, int offset) {
- int len = strlen(str);
- return (size >= offset + len) && !memcmp((char*)data + offset, str, len);
- }
+ static int check_header(const void *data, int size, const char *str, int offset) {
+ int len = strlen(str);
+ return (size >= offset + len) && !memcmp((char*)data + offset, str, len);
+ }
- SourceType Source::getType(const void* mem, int size)
- {
- if(check_header(mem, size, "WAVE", 8))
- return SourceType::WAV;
- if(check_header(mem, size, "OggS", 0))
- return SourceType::OGG;
- return SourceType::INVALID;
- }
+ SourceType Source::getType(const void* mem, int size)
+ {
+ if(check_header(mem, size, "WAVE", 8))
+ return SourceType::WAV;
+ if(check_header(mem, size, "OggS", 0))
+ return SourceType::OGG;
+ return SourceType::INVALID;
+ }
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // jin_audio
diff --git a/src/libjin/audio/je_source.h b/src/libjin/audio/je_source.h
index 9b7bff0..fd78be5 100644
--- a/src/libjin/audio/je_source.h
+++ b/src/libjin/audio/je_source.h
@@ -9,34 +9,34 @@
namespace JinEngine
{
- namespace Audio
- {
+ namespace Audio
+ {
///
/// Audio source encoding type.
///
- enum SourceType
- {
- INVALID = 0,
- WAV,
- OGG,
- };
+ enum SourceType
+ {
+ INVALID = 0,
+ WAV,
+ OGG,
+ };
///
/// Audio source.
///
- class Source : public Object
- {
- public:
+ class Source : public Object
+ {
+ public:
///
/// Source constructor.
///
- Source() {};
+ Source() {};
///
/// Source destructor.
///
- virtual ~Source() {};
+ virtual ~Source() {};
///
/// Start playing source.
@@ -46,71 +46,71 @@ namespace JinEngine
///
/// Stop playing source.
///
- virtual void stop() = 0;
+ virtual void stop() = 0;
///
/// Pause source.
///
- virtual void pause() = 0;
+ virtual void pause() = 0;
///
/// Resume source.
///
- virtual void resume() = 0;
+ virtual void resume() = 0;
///
/// Rewind source.
///
- virtual void rewind() = 0;
+ virtual void rewind() = 0;
///
/// Whether the source is playing or not.
///
- virtual bool isStopped() const = 0;
+ virtual bool isStopped() const = 0;
///
/// Whether the source is paused or not.
///
- virtual bool isPaused() const = 0;
+ virtual bool isPaused() const = 0;
///
/// Set source pitch.
///
/// @param pitch Pitch of source.
///
- virtual void setPitch(float pitch) = 0;
+ virtual void setPitch(float pitch) = 0;
///
/// Set volume of source.
///
/// @param volume Volume of source.
///
- virtual void setVolume(float volume) = 0;
+ virtual void setVolume(float volume) = 0;
///
/// Set source loop.
///
/// @param loop Looping or not.
///
- virtual void setLoop(bool loop) = 0;
+ virtual void setLoop(bool loop) = 0;
///
/// Set source rate.
///
/// @param rate Rate of source.
///
- virtual void setRate(float rate) = 0;
+ virtual void setRate(float rate) = 0;
- protected:
+ protected:
///
/// Get type of source data.
///
- static SourceType getType(const void* mem, int size);
+ static SourceType getType(const void* mem, int size);
- };
+ };
- } // namespace Audio
+ } // namespace Audio
} // namespace JinEngine
#endif // jin_audio
diff --git a/src/libjin/common/je_subsystem.hpp b/src/libjin/common/je_subsystem.hpp
index 384d986..8f682ef 100644
--- a/src/libjin/common/je_subsystem.hpp
+++ b/src/libjin/common/je_subsystem.hpp
@@ -42,8 +42,8 @@ namespace JinEngine
void quit()
{
// Call only once.
- static char __dummy__ = (quitSystem(), 1);
- Singleton<System>::destroy();
+ static char __dummy__ = (quitSystem(), 1);
+ Singleton<System>::destroy();
}
///
@@ -60,12 +60,12 @@ namespace JinEngine
///
/// Initializer callback.
///
- virtual bool startSystem(const Setting* setting) = 0;
+ virtual bool startSystem(const Setting* setting) = 0;
///
/// Quit subsystem callback.
///
- virtual void quitSystem() = 0;
+ virtual void quitSystem() = 0;
};
diff --git a/src/libjin/filesystem/je_asset_database.cpp b/src/libjin/filesystem/je_asset_database.cpp
index a8524c5..1203643 100644
--- a/src/libjin/filesystem/je_asset_database.cpp
+++ b/src/libjin/filesystem/je_asset_database.cpp
@@ -11,75 +11,75 @@
namespace JinEngine
{
- namespace Filesystem
- {
+ namespace Filesystem
+ {
- AssetDatabase* AssetDatabase::mAssetDatabase = 0;
+ AssetDatabase* AssetDatabase::mAssetDatabase = 0;
- AssetDatabase::AssetDatabase()
- {
+ AssetDatabase::AssetDatabase()
+ {
mSmt = smtnewshared();
- }
-
- AssetDatabase* AssetDatabase::get()
- {
- return mAssetDatabase ? mAssetDatabase : (mAssetDatabase = new AssetDatabase());
- }
-
- void AssetDatabase::mount(const char * path)
- {
- int err = smtmount(mSmt, path);
- if (err)
- {
- printf("%s mounted path %s", smterrstr(err), path);
- exit(1);
- }
- }
-
- void AssetDatabase::read(const char* path, Buffer& buffer)
- {
+ }
+
+ AssetDatabase* AssetDatabase::get()
+ {
+ return mAssetDatabase ? mAssetDatabase : (mAssetDatabase = new AssetDatabase());
+ }
+
+ void AssetDatabase::mount(const char * path)
+ {
+ int err = smtmount(mSmt, path);
+ if (err)
+ {
+ printf("%s mounted path %s", smterrstr(err), path);
+ exit(1);
+ }
+ }
+
+ void AssetDatabase::read(const char* path, Buffer& buffer)
+ {
size_t size;
byte* data = (byte*)smtread(mSmt, path, &size);
if (data == nullptr)
throw Exception("Could not read file %s.", path);
buffer.bind(data, size);
- }
+ }
Buffer* read(const char* path)
{
return nullptr;
}
- void* AssetDatabase::read(const char* path, unsigned int* len)
- {
- return smtread(mSmt, path, len);
- }
-
- const char* AssetDatabase::getFull(const char* path)
- {
- return smtfullpath(mSmt, path);
- }
-
- bool AssetDatabase::isDir(const char* path)
- {
- return smtisdir(mSmt, path);
- }
-
- bool AssetDatabase::isFile(const char* path)
- {
- return smtisreg(mSmt, path);
- }
-
- bool AssetDatabase::exists(const char* path)
- {
- return smtexists(mSmt, path) == 0;
- }
+ void* AssetDatabase::read(const char* path, unsigned int* len)
+ {
+ return smtread(mSmt, path, len);
+ }
+
+ const char* AssetDatabase::getFull(const char* path)
+ {
+ return smtfullpath(mSmt, path);
+ }
+
+ bool AssetDatabase::isDir(const char* path)
+ {
+ return smtisdir(mSmt, path);
+ }
+
+ bool AssetDatabase::isFile(const char* path)
+ {
+ return smtisreg(mSmt, path);
+ }
+
+ bool AssetDatabase::exists(const char* path)
+ {
+ return smtexists(mSmt, path) == 0;
+ }
/*
std::vector<std::string> AssetDatabase::getFiles(const char* path, bool recursive)
{
}
*/
- } // namespace Filesystem
+ } // namespace Filesystem
} // namespace JinEngine
#endif // jin_filesystem \ No newline at end of file
diff --git a/src/libjin/filesystem/je_asset_database.h b/src/libjin/filesystem/je_asset_database.h
index 2e029ff..82d5ab4 100644
--- a/src/libjin/filesystem/je_asset_database.h
+++ b/src/libjin/filesystem/je_asset_database.h
@@ -12,21 +12,21 @@
namespace JinEngine
{
- namespace Filesystem
- {
+ namespace Filesystem
+ {
///
/// Assets managment.
///
class AssetDatabase : public Object
- {
- public:
+ {
+ public:
///
/// Get asset database singleton.
///
/// @param Singleton of asset database.
///
- static AssetDatabase* get();
+ static AssetDatabase* get();
///
/// Asset database constructor.
@@ -46,7 +46,7 @@ namespace JinEngine
/// @param path Path under asset folder.
/// @return True if the given path is directory, otherwise return false.
///
- bool isDir(const char* path);
+ bool isDir(const char* path);
///
/// Check if the path is file.
@@ -54,14 +54,14 @@ namespace JinEngine
/// @param path Path under asset folder.
/// @return True if the given path is file, otherwise return false.
///
- bool isFile(const char* path);
+ bool isFile(const char* path);
///
/// Check if the path exists.
/// @param path Given path.
/// @return True if path exists, otherwise return false.
///
- bool exists(const char* path);
+ bool exists(const char* path);
///
/// Read file into a buffer.
@@ -70,7 +70,7 @@ namespace JinEngine
/// @param buffer Buffer to fill.
/// @return True if read sucessful, otherwise return false.
///
- void read(const char* path, Buffer& buffer);
+ void read(const char* path, Buffer& buffer);
///
/// Read file and return data content.
@@ -79,7 +79,7 @@ namespace JinEngine
/// @param length Length of data.
/// @return Data if read sucessful, otherwise return null.
///
- void* read(const char* path, unsigned int* length);
+ void* read(const char* path, unsigned int* length);
///
/// Get files under given directory.
@@ -96,17 +96,17 @@ namespace JinEngine
/// @param path Path of asset.
/// @return Full path of asset.
///
- const char* getFull(const char* path);
+ const char* getFull(const char* path);
- private:
- static AssetDatabase* mAssetDatabase;
+ private:
+ static AssetDatabase* mAssetDatabase;
#if jin_filesystem == jin_filesystem_smount
- smtShared* mSmt;
+ smtShared* mSmt;
#endif
- };
+ };
- } // namespace Filesystem
+ } // namespace Filesystem
} // namespace JinEngine
#endif // jin_filesystem
diff --git a/src/libjin/filesystem/je_buffer.h b/src/libjin/filesystem/je_buffer.h
index 1111e49..b3c6612 100644
--- a/src/libjin/filesystem/je_buffer.h
+++ b/src/libjin/filesystem/je_buffer.h
@@ -12,19 +12,19 @@
namespace JinEngine
{
- namespace Filesystem
- {
+ namespace Filesystem
+ {
///
/// Data buffer allocated on heap.
///
- class Buffer : public Temporary
- {
- public:
+ class Buffer : public Temporary
+ {
+ public:
///
/// Buffer constructor.
///
- Buffer()
+ Buffer()
: mData(0)
, mSize(0)
{
@@ -35,13 +35,13 @@ namespace JinEngine
///
/// @param src Buffer source.
///
- Buffer(const Buffer& src)
- {
- delete[] mData;
- mSize = src.mSize;
- mData = new byte[mSize];
- memcpy(mData, src.mData, mSize);
- }
+ Buffer(const Buffer& src)
+ {
+ delete[] mData;
+ mSize = src.mSize;
+ mData = new byte[mSize];
+ memcpy(mData, src.mData, mSize);
+ }
///
/// Buffer constructor.
@@ -49,33 +49,33 @@ namespace JinEngine
/// @param data Buffer data.
/// @param size Size of buffer.
///
- Buffer(void* data, int size)
- {
+ Buffer(void* data, int size)
+ {
mSize = size;
mData = new byte[mSize];
- memcpy(mData, data, mSize);
- }
+ memcpy(mData, data, mSize);
+ }
///
/// Buffer constructor.
///
/// @param size Size of data.
///
- Buffer(size_t size)
- {
+ Buffer(size_t size)
+ {
mData = new byte[size];
- memset(mData, 0, size);
+ memset(mData, 0, size);
mSize = size;
- }
+ }
///
/// Buffer destructor.
///
- ~Buffer()
- {
- delete[] mData;
+ ~Buffer()
+ {
+ delete[] mData;
mSize = 0;
- }
+ }
///
/// Set buffer data.
@@ -115,13 +115,13 @@ namespace JinEngine
///
/// @param buffer Buffer to copy.
///
- void operator = (const Buffer& buffer)
- {
- delete[] mData;
+ void operator = (const Buffer& buffer)
+ {
+ delete[] mData;
mSize = buffer.mSize;
mData = new byte[mSize];
- memcpy(mData, buffer.mData, mSize);
- }
+ memcpy(mData, buffer.mData, mSize);
+ }
///
/// Get data addresss.
@@ -146,22 +146,22 @@ namespace JinEngine
///
/// Clear data.
///
- void clear()
- {
- if (mData == nullptr)
- return;
+ void clear()
+ {
+ if (mData == nullptr)
+ return;
delete mData;
mData = nullptr;
mSize = 0;
- }
+ }
private:
byte* mData;
size_t mSize;
- };
+ };
- } // namespace Filesystem
+ } // namespace Filesystem
} // namespace JinEngine
#endif // jin_filesystem
diff --git a/src/libjin/game/je_application.cpp b/src/libjin/game/je_application.cpp
index 1a3c5ed..19a74a0 100644
--- a/src/libjin/game/je_application.cpp
+++ b/src/libjin/game/je_application.cpp
@@ -18,64 +18,64 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Game
- {
+ namespace Game
+ {
- Application::Application() :_running(true) {};
+ Application::Application() :_running(true) {};
- /* default game loop */
- void Application::run()
- {
- if (_onLoad != nullptr)
- _onLoad();
- Window* wnd = Window::get();
- const int FPS = wnd ? wnd->getFPS() : 60;
- const int MS_PER_UPDATE = 1000.0f / FPS;
- _running = true;
- Event e;
- int current = getMilliSecond();
- int previous = current;
- int dt = 0;
- while (_running)
- {
- while (JinEngine::Input::pollEvent(&e))
- {
- if (_onEvent != nullptr)
- _onEvent(&e);
- if (!_running)
- goto quitloop;
- }
- previous = current;
- current = getMilliSecond();
- dt = current - previous;
- if (_onUpdate != nullptr)
- _onUpdate(dt);
+ /* default game loop */
+ void Application::run()
+ {
+ if (_onLoad != nullptr)
+ _onLoad();
+ Window* wnd = Window::get();
+ const int FPS = wnd ? wnd->getFPS() : 60;
+ const int MS_PER_UPDATE = 1000.0f / FPS;
+ _running = true;
+ Event e;
+ int current = getMilliSecond();
+ int previous = current;
+ int dt = 0;
+ while (_running)
+ {
+ while (JinEngine::Input::pollEvent(&e))
+ {
+ if (_onEvent != nullptr)
+ _onEvent(&e);
+ if (!_running)
+ goto quitloop;
+ }
+ previous = current;
+ current = getMilliSecond();
+ dt = current - previous;
+ if (_onUpdate != nullptr)
+ _onUpdate(dt);
glClear(GL_COLOR_BUFFER_BIT);
- if (_onDraw != nullptr)
- _onDraw();
- wnd->swapBuffers();
- sleep(16);
- }
- quitloop:;
- }
+ if (_onDraw != nullptr)
+ _onDraw();
+ wnd->swapBuffers();
+ sleep(16);
+ }
+ quitloop:;
+ }
- bool Application::startSystem(const SettingBase* setting)
- {
- if (setting == nullptr)
- return false;
- Application::Setting* s = (Application::Setting*) setting;
- _onEvent = s->eventHandler;
- _onUpdate = s->updater;
- _onDraw = s->drawer;
- _onLoad = s->loader;
- return true;
- }
+ bool Application::startSystem(const SettingBase* setting)
+ {
+ if (setting == nullptr)
+ return false;
+ Application::Setting* s = (Application::Setting*) setting;
+ _onEvent = s->eventHandler;
+ _onUpdate = s->updater;
+ _onDraw = s->drawer;
+ _onLoad = s->loader;
+ return true;
+ }
- void Application::quitSystem()
- {
- }
+ void Application::quitSystem()
+ {
+ }
- } // namespace Core
+ } // namespace Core
} // namespace JinEngine
#endif // jin_game \ No newline at end of file
diff --git a/src/libjin/game/je_application.h b/src/libjin/game/je_application.h
index 9de6e1c..6eb8af2 100644
--- a/src/libjin/game/je_application.h
+++ b/src/libjin/game/je_application.h
@@ -12,19 +12,19 @@
namespace JinEngine
{
- namespace Game
- {
+ namespace Game
+ {
///
/// Game class.
///
- class Application : public Subsystem<Application>
- {
- public:
- typedef void(*onLoad)();
- typedef void(*onEvent)(JinEngine::Input::Event* e);
- typedef void(*onUpdate)(int dt);
- typedef void(*onDraw)();
+ class Application : public Subsystem<Application>
+ {
+ public:
+ typedef void(*onLoad)();
+ typedef void(*onEvent)(JinEngine::Input::Event* e);
+ typedef void(*onUpdate)(int dt);
+ typedef void(*onDraw)();
Application();
~Application() {};
@@ -32,23 +32,23 @@ namespace JinEngine
///
/// Game setting.
///
- struct Setting : SettingBase
- {
- onEvent eventHandler;
- onUpdate updater;
- onDraw drawer;
- onLoad loader;
- };
+ struct Setting : SettingBase
+ {
+ onEvent eventHandler;
+ onUpdate updater;
+ onDraw drawer;
+ onLoad loader;
+ };
///
/// Main game loop.
///
- void run();
+ void run();
///
/// Stop game.
///
- inline void stop()
+ inline void stop()
{
_running = false;
};
@@ -58,25 +58,25 @@ namespace JinEngine
///
/// @return True if game is running, otherwise return false.
///
- inline bool running()
+ inline bool running()
{
return _running;
};
- private:
- onEvent _onEvent;
- onUpdate _onUpdate;
- onDraw _onDraw;
- onLoad _onLoad;
+ private:
+ onEvent _onEvent;
+ onUpdate _onUpdate;
+ onDraw _onDraw;
+ onLoad _onLoad;
- bool _running;
+ bool _running;
- bool startSystem(const SettingBase* setting);
- void quitSystem();
+ bool startSystem(const SettingBase* setting);
+ void quitSystem();
- };
+ };
- } // namespace Core
+ } // namespace Core
} // namespace JinEngine
#endif // jin_game
diff --git a/src/libjin/graphics/fonts/je_decoder.cpp b/src/libjin/graphics/fonts/je_decoder.cpp
index 02112a0..a7f4f32 100644
--- a/src/libjin/graphics/fonts/je_decoder.cpp
+++ b/src/libjin/graphics/fonts/je_decoder.cpp
@@ -4,8 +4,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -92,5 +92,5 @@ namespace JinEngine
}
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_decoder.h b/src/libjin/graphics/fonts/je_decoder.h
index 0c785af..43fa155 100644
--- a/src/libjin/graphics/fonts/je_decoder.h
+++ b/src/libjin/graphics/fonts/je_decoder.h
@@ -9,8 +9,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -93,7 +93,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_font.h b/src/libjin/graphics/fonts/je_font.h
index e8ce2c5..3af0b11 100644
--- a/src/libjin/graphics/fonts/je_font.h
+++ b/src/libjin/graphics/fonts/je_font.h
@@ -9,8 +9,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -106,7 +106,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // __JE_FONT_H__
diff --git a/src/libjin/graphics/fonts/je_page.h b/src/libjin/graphics/fonts/je_page.h
index b3c831c..d831691 100644
--- a/src/libjin/graphics/fonts/je_page.h
+++ b/src/libjin/graphics/fonts/je_page.h
@@ -7,8 +7,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -48,7 +48,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // __JE_PAGE_H__
diff --git a/src/libjin/graphics/fonts/je_text.cpp b/src/libjin/graphics/fonts/je_text.cpp
index 80aaa6a..f9909a6 100644
--- a/src/libjin/graphics/fonts/je_text.cpp
+++ b/src/libjin/graphics/fonts/je_text.cpp
@@ -5,8 +5,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -153,5 +153,5 @@ namespace JinEngine
}
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_text.h b/src/libjin/graphics/fonts/je_text.h
index 319ee4d..6837bfc 100644
--- a/src/libjin/graphics/fonts/je_text.h
+++ b/src/libjin/graphics/fonts/je_text.h
@@ -7,8 +7,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -168,7 +168,7 @@ namespace JinEngine
};
}
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_texture_font.cpp b/src/libjin/graphics/fonts/je_texture_font.cpp
index 9014509..4f2378b 100644
--- a/src/libjin/graphics/fonts/je_texture_font.cpp
+++ b/src/libjin/graphics/fonts/je_texture_font.cpp
@@ -12,8 +12,8 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -124,9 +124,9 @@ namespace JinEngine
int i = 0;
#define glyphvertices_push(_x, _y, _u, _v) \
- vertex.x = _x; vertex.y = _y;\
- vertex.u = _u; vertex.v = _v;\
- glyphvertices.push_back(vertex);\
+ vertex.x = _x; vertex.y = _y;\
+ vertex.u = _u; vertex.v = _v;\
+ glyphvertices.push_back(vertex);\
for (Codepoint c : text)
{
@@ -304,5 +304,5 @@ namespace JinEngine
}
}
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_texture_font.h b/src/libjin/graphics/fonts/je_texture_font.h
index 4875361..9192276 100644
--- a/src/libjin/graphics/fonts/je_texture_font.h
+++ b/src/libjin/graphics/fonts/je_texture_font.h
@@ -15,8 +15,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -125,7 +125,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_ttf.cpp b/src/libjin/graphics/fonts/je_ttf.cpp
index fec8cd4..40008d3 100644
--- a/src/libjin/graphics/fonts/je_ttf.cpp
+++ b/src/libjin/graphics/fonts/je_ttf.cpp
@@ -19,8 +19,8 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -234,29 +234,29 @@ namespace JinEngine
int i = 0;
#define glyphvertices_push(_x, _y, _u, _v) \
- vertex.x = _x; vertex.y = _y;\
- vertex.u = _u; vertex.v = _v;\
- glyphvertices.push_back(vertex);
+ vertex.x = _x; vertex.y = _y;\
+ vertex.u = _u; vertex.v = _v;\
+ glyphvertices.push_back(vertex);
#define glyphlize(c)\
- do{\
- glyph = &findGlyph(c); \
- if (texture != glyph->atlas) \
- { \
- GlyphArrayDrawInfo info; \
- info.start = i; \
- info.count = 0; \
- info.texture = glyph->atlas; \
- texture = glyph->atlas; \
- glyphinfolist.push_back(info); \
- } \
- glyphinfolist[glyphinfolist.size() - 1].count += 4; \
- TTFGlyph::Bbox& bbox = glyph->bbox; \
- glyphvertices_push(p.x, p.y, bbox.x, bbox.y); \
- glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); \
- glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); \
- glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \
- }while(0)
+ do{\
+ glyph = &findGlyph(c); \
+ if (texture != glyph->atlas) \
+ { \
+ GlyphArrayDrawInfo info; \
+ info.start = i; \
+ info.count = 0; \
+ info.texture = glyph->atlas; \
+ texture = glyph->atlas; \
+ glyphinfolist.push_back(info); \
+ } \
+ glyphinfolist[glyphinfolist.size() - 1].count += 4; \
+ TTFGlyph::Bbox& bbox = glyph->bbox; \
+ glyphvertices_push(p.x, p.y, bbox.x, bbox.y); \
+ glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); \
+ glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); \
+ glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \
+ }while(0)
for (Codepoint c : text)
{
@@ -448,7 +448,7 @@ namespace JinEngine
}
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/fonts/je_ttf.h b/src/libjin/graphics/fonts/je_ttf.h
index 198594a..feabf33 100644
--- a/src/libjin/graphics/fonts/je_ttf.h
+++ b/src/libjin/graphics/fonts/je_ttf.h
@@ -19,8 +19,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Fonts
{
@@ -278,7 +278,7 @@ namespace JinEngine
};
} // namespace Fonts
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics)
diff --git a/src/libjin/graphics/je_bitmap.cpp b/src/libjin/graphics/je_bitmap.cpp
index 18e15a8..eadd6d1 100644
--- a/src/libjin/graphics/je_bitmap.cpp
+++ b/src/libjin/graphics/je_bitmap.cpp
@@ -12,30 +12,30 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Graphics
- {
-
- Bitmap* Bitmap::clone()
- {
- Bitmap* b = new Bitmap(this);
- return b;
- }
-
- Bitmap::Bitmap()
- : width(0)
- , height(0)
- , pixels(nullptr)
- {
- }
-
- Bitmap::Bitmap(unsigned w, unsigned h)
- {
- width = w;
- height = h;
- pixels = new Color[w*h];
+ namespace Graphics
+ {
+
+ Bitmap* Bitmap::clone()
+ {
+ Bitmap* b = new Bitmap(this);
+ return b;
+ }
+
+ Bitmap::Bitmap()
+ : width(0)
+ , height(0)
+ , pixels(nullptr)
+ {
+ }
+
+ Bitmap::Bitmap(unsigned w, unsigned h)
+ {
+ width = w;
+ height = h;
+ pixels = new Color[w*h];
if (pixels == nullptr)
throw Exception("No enough memory.");
- }
+ }
Bitmap::Bitmap(const char* path)
{
@@ -96,94 +96,94 @@ namespace JinEngine
resetPixels(bitmap->getPixels(), 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];
+ 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];
if (pixels == nullptr)
throw Exception("Not enough memory.");
- 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)
- {
+ 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)
throw Exception("Bitmap don't have pixel space.");
- if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
- return;
+ if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
+ return;
if (x + y * width >= width * height)
throw Exception("Pixel <%d, %d> of bitmap is out of range.", x, y);
- 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];
+ 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];
if (pixels == nullptr)
throw Exception("Not enough memory.");
- 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, int count)
- {
+ 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, int count)
+ {
if (count > width * height)
throw Exception("Pixels are out of range.");
- 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];
- }
+ 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;
- }
+ const Color* Bitmap::getPixels() const
+ {
+ return pixels;
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_bitmap.h b/src/libjin/graphics/je_bitmap.h
index c392a32..644e56e 100644
--- a/src/libjin/graphics/je_bitmap.h
+++ b/src/libjin/graphics/je_bitmap.h
@@ -14,8 +14,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
/// A RGBA32 bitmap.
@@ -24,9 +24,9 @@ namespace JinEngine
/// texture is a renderable hard ware side structure which could be handled with GPU. For instance, opengl
/// create texture and store it in GPU memory for rendering them onto hdc.
///
- class Bitmap : public Object
- {
- public:
+ class Bitmap : public Object
+ {
+ public:
///
/// Constructor of bitmap.
///
@@ -55,7 +55,7 @@ namespace JinEngine
///
/// Destructor of bitmap
///
- virtual ~Bitmap();
+ virtual ~Bitmap();
///
/// Create bitmap with another one.
@@ -72,7 +72,7 @@ namespace JinEngine
/// @param width Width of bitmap
/// @param height Height of bitmap
///
- void bind(Color* pixels, int width, int height);
+ void bind(Color* pixels, int width, int height);
///
/// Reset pixel data with given pixels data.
@@ -81,7 +81,7 @@ namespace JinEngine
/// @param width Width of bitmap
/// @param height Height of bitmap
///
- void resetPixels(const Color* pixels, int width, int height);
+ void resetPixels(const Color* pixels, int width, int height);
///
/// Reset pixel data with given color.
@@ -90,7 +90,7 @@ namespace JinEngine
/// @param width Width of bitmap
/// @param height Height of bitmap
///
- void resetPixels(const Color& color, int width, int height);
+ void resetPixels(const Color& color, int width, int height);
///
/// Set pixel with given color.
@@ -99,14 +99,14 @@ namespace JinEngine
/// @param x X value of pixel.
/// @param y Y value of pixel.
///
- void setPixel(const Color& color, int x, int y);
+ void setPixel(const Color& color, int x, int y);
///
/// Set pixels with given color.
///
/// @param color Color to be set.
///
- void setPixels(Color color);
+ void setPixels(Color color);
///
/// Set pixels with given color data.
@@ -114,7 +114,7 @@ namespace JinEngine
/// @param colors New pixels' colors.
/// @param count Number of pixels.
///
- void setPixels(Color* colors, int count);
+ void setPixels(Color* colors, int count);
///
/// Get pixel in given position.
@@ -122,42 +122,42 @@ namespace JinEngine
/// @param x X value of position.
/// @param y Y value of position.
///
- Color getPixel(int x, int y);
+ Color getPixel(int x, int y);
///
/// Get pixels.
/// @return Colors of the bitmap.
///
- const Color* getPixels() const;
+ const Color* getPixels() const;
///
/// Get bitmap width.
///
/// @return Width of bitmap.
///
- inline int getWidth() const { return width; }
+ inline int getWidth() const { return width; }
///
/// Get bitmap height.
///
/// @return Height of bitmap.
///
- inline int getHeight() const { return height; }
+ inline int getHeight() const { return height; }
///
/// Get bitmap size.
///
/// @return Size of bitmap.
///
- inline Math::Vector2<int> getSize() const { return Math::Vector2<int>(width, height); }
+ inline Math::Vector2<int> getSize() const { return Math::Vector2<int>(width, height); }
- protected:
- Color * pixels;
- unsigned width, height;
+ protected:
+ Color * pixels;
+ unsigned width, height;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif
diff --git a/src/libjin/graphics/je_canvas.cpp b/src/libjin/graphics/je_canvas.cpp
index 564121e..0a3f6f4 100644
--- a/src/libjin/graphics/je_canvas.cpp
+++ b/src/libjin/graphics/je_canvas.cpp
@@ -7,48 +7,48 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
Canvas::Canvas(GLuint n)
: fbo(n)
{
}
- Canvas::Canvas(int w, int h)
- : Graphic(w, h)
- {
- GLint current_fbo;
- glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
+ Canvas::Canvas(int w, int h)
+ : Graphic(w, h)
+ {
+ GLint current_fbo;
+ glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
- // Generate a new render buffer object
- fbo = gl.genFrameBuffer();
- gl.bindFrameBuffer(fbo);
+ // Generate a new render buffer object
+ fbo = gl.genFrameBuffer();
+ gl.bindFrameBuffer(fbo);
GLuint texture = getGLTexture();
- gl.bindTexture(texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- gl.bindTexture(0);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+ gl.bindTexture(texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ gl.bindTexture(0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
- GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- // Unbind framebuffer
- gl.bindFrameBuffer(current_fbo);
- }
+ // Unbind framebuffer
+ gl.bindFrameBuffer(current_fbo);
+ }
- Canvas::~Canvas()
- {
- }
+ Canvas::~Canvas()
+ {
+ }
- bool Canvas::isBinded(const Canvas* cvs)
- {
- return gl.getCanvas() == cvs;
- }
+ bool Canvas::isBinded(const Canvas* cvs)
+ {
+ return gl.getCanvas() == cvs;
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_canvas.h b/src/libjin/graphics/je_canvas.h
index 277e39d..b65e598 100644
--- a/src/libjin/graphics/je_canvas.h
+++ b/src/libjin/graphics/je_canvas.h
@@ -7,20 +7,20 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
/// Renderable canvas.
///
/// A canvas is a rendering target.
///
- class Canvas : public Graphic
- {
- public:
+ class Canvas : public Graphic
+ {
+ public:
///
///
///
- static bool isBinded(const Canvas*);
+ static bool isBinded(const Canvas*);
///
///
@@ -35,17 +35,17 @@ namespace JinEngine
///
///
///
- ~Canvas();
+ ~Canvas();
inline GLuint getGLFrameBuffer() const { return fbo; };
- protected:
+ protected:
- GLuint fbo;
+ GLuint fbo;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics)
diff --git a/src/libjin/graphics/je_color.cpp b/src/libjin/graphics/je_color.cpp
index c939a1d..ea936fa 100644
--- a/src/libjin/graphics/je_color.cpp
+++ b/src/libjin/graphics/je_color.cpp
@@ -2,21 +2,21 @@
namespace JinEngine
{
- namespace Graphics
- {
+ 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);
+ 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);
const uint32 Color::RMASK = 0x000000ff;
const uint32 Color::GMASK = 0x0000ff00;
const uint32 Color::BMASK = 0x00ff0000;
const uint32 Color::AMASK = 0xff000000;
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin/graphics/je_color.h b/src/libjin/graphics/je_color.h
index 06b8f61..96120e3 100644
--- a/src/libjin/graphics/je_color.h
+++ b/src/libjin/graphics/je_color.h
@@ -13,22 +13,22 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- typedef uint8 Channel;
+ typedef uint8 Channel;
- class Color
- {
- public:
+ 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;
+ static const Color BLACK;
+ static const Color RED;
+ static const Color GREEN;
+ static const Color BLUE;
+ static const Color MAGENTA;
+ static const Color YELLOW;
static const uint32 RMASK;
static const uint32 GMASK;
@@ -57,61 +57,61 @@ namespace JinEngine
///
///
///
- Color() { r = g = b = a = 0; };
+ 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(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 set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
- {
- r = _r;
- g = _g;
- b = _b;
- a = _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;
- }
+ Color(const Color& c)
+ {
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+ }
+
+ void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
+ {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _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);
- }
+ bool operator != (const Color& c)
+ {
+ return !(r == c.r && g == c.g && b == c.b && a == c.a);
+ }
- Channel r, g, b, a;
+ Channel r, g, b, a;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/je_gl.cpp b/src/libjin/graphics/je_gl.cpp
index 453b4b4..41fdf76 100644
--- a/src/libjin/graphics/je_gl.cpp
+++ b/src/libjin/graphics/je_gl.cpp
@@ -13,10 +13,10 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- OpenGL gl;
+ OpenGL gl;
const Canvas* const OpenGL::DEFAULT_CANVAS = new Canvas(0);
@@ -359,5 +359,5 @@ namespace JinEngine
return mFont;
}
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_gl.h b/src/libjin/graphics/je_gl.h
index de381f4..37dc890 100644
--- a/src/libjin/graphics/je_gl.h
+++ b/src/libjin/graphics/je_gl.h
@@ -12,8 +12,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
// Wrap OpenGL API.
namespace Shaders { class Shader; };
@@ -23,9 +23,9 @@ namespace JinEngine
class Canvas;
- class OpenGL
- {
- public:
+ class OpenGL
+ {
+ public:
///
/// Blend mode.
/// https://www.andersriggelsen.dk/glblendfunc.php
@@ -229,12 +229,12 @@ namespace JinEngine
///
Fonts::Font* mFont;
- };
+ };
// Singleton.
- extern OpenGL gl;
+ extern OpenGL gl;
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // __JE_OPENGL_H__ \ No newline at end of file
diff --git a/src/libjin/graphics/je_graphic.h b/src/libjin/graphics/je_graphic.h
index 90b5522..f47adbf 100644
--- a/src/libjin/graphics/je_graphic.h
+++ b/src/libjin/graphics/je_graphic.h
@@ -17,43 +17,43 @@ namespace JinEngine
namespace Graphics
{
- ///
- /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. Very low
+ ///
+ /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties. Very low
/// level visualized resources.
///
class Graphic : public Object, public Renderable
{
public:
- ///
- ///
- ///
+ ///
+ ///
+ ///
Graphic(int w = 0, int h = 0);
- ///
- ///
- ///
+ ///
+ ///
+ ///
Graphic(const Bitmap* bitmap);
- ///
- ///
- ///
+ ///
+ ///
+ ///
virtual ~Graphic();
- ///
- ///
- ///
+ ///
+ ///
+ ///
inline int getWidth() const { return mSize.w; }
- ///
- ///
- ///
+ ///
+ ///
+ ///
inline int getHeight() const { return mSize.h; }
- ///
- /// Get opengl texture token.
+ ///
+ /// Get opengl texture token.
///
/// @return OpenGL texture token.
- ///
+ ///
inline GLuint getGLTexture() const { return mTexture; }
///
diff --git a/src/libjin/graphics/je_image.cpp b/src/libjin/graphics/je_image.cpp
index 285cef2..46ae34f 100644
--- a/src/libjin/graphics/je_image.cpp
+++ b/src/libjin/graphics/je_image.cpp
@@ -33,14 +33,14 @@ namespace JinEngine
height = h;
}
- Image::Image()
- : Bitmap()
- {
- }
-
- Image::~Image()
- {
- }
+ Image::Image()
+ : Bitmap()
+ {
+ }
+
+ Image::~Image()
+ {
+ }
} // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_image.h b/src/libjin/graphics/je_image.h
index 432b875..f23e8c6 100644
--- a/src/libjin/graphics/je_image.h
+++ b/src/libjin/graphics/je_image.h
@@ -13,9 +13,9 @@ namespace JinEngine
///
/// Just like bitmap but only from image file. The pixels data is readonly.
///
- class Image : public Bitmap
- {
- public:
+ class Image : public Bitmap
+ {
+ public:
///
/// Image constructor.
///
@@ -28,18 +28,18 @@ namespace JinEngine
///
/// Image destructor.
///
- ~Image();
+ ~Image();
- private:
+ private:
// Disable setters inherited from Bitmap.
- 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);
- void setPixel(const Color& pixel, int x, int y);
- void setPixels(Color pixels);
- void setPixels(Color* 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);
+ void setPixel(const Color& pixel, int x, int y);
+ void setPixels(Color pixels);
+ void setPixels(Color* pixels);
+
+ };
} // namespace Graphics
} // namespace JinEngine
diff --git a/src/libjin/graphics/je_mesh.cpp b/src/libjin/graphics/je_mesh.cpp
index dd2d61c..a88abbd 100644
--- a/src/libjin/graphics/je_mesh.cpp
+++ b/src/libjin/graphics/je_mesh.cpp
@@ -2,10 +2,10 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/graphics/je_mesh.h b/src/libjin/graphics/je_mesh.h
index 4327424..5bcca2e 100644
--- a/src/libjin/graphics/je_mesh.h
+++ b/src/libjin/graphics/je_mesh.h
@@ -5,24 +5,24 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
/// A 2D mesh.
///
- class Mesh
- {
- public:
+ class Mesh
+ {
+ public:
void setGraphic(const Graphic* graphic);
void pushVertex(float x, float y, float u, float v);
- private:
+ private:
const Graphic* mGraphic;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/graphics/je_shapes.cpp b/src/libjin/graphics/je_shapes.cpp
index ee5e9e5..02c007d 100644
--- a/src/libjin/graphics/je_shapes.cpp
+++ b/src/libjin/graphics/je_shapes.cpp
@@ -13,118 +13,118 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- using namespace Math;
+ using namespace Math;
- void point(int x, int y)
- {
- float verts[] = { x + 0.5f , y + 0.5f };
+ void point(int x, int y)
+ {
+ float verts[] = { x + 0.5f , y + 0.5f };
- Shader* shader = gl.getShader();
- shader->setVertexPointer(2, GL_FLOAT, 0, verts);
+ Shader* shader = gl.getShader();
+ shader->setVertexPointer(2, GL_FLOAT, 0, verts);
Matrix modelMatrix = gl.getModelViewMatrix();
- shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- glDrawArrays(GL_POINTS, 0, 1);
- }
+ glDrawArrays(GL_POINTS, 0, 1);
+ }
- void points(int n, GLshort* p)
- {
- Shader* shader = gl.getShader();
- shader->setVertexPointer(2, GL_SHORT, 0, p);
+ void points(int n, GLshort* p)
+ {
+ Shader* shader = gl.getShader();
+ shader->setVertexPointer(2, GL_SHORT, 0, p);
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+
+ glDrawArrays(GL_POINTS, 0, n);
+ }
+
+ void line(int x1, int y1, int x2, int y2)
+ {
+ float verts[] = {
+ x1 + 0.5f, y1 + 0.5f,
+ x2 + 0.5f, y2 + 0.5f
+ };
- glDrawArrays(GL_POINTS, 0, n);
- }
-
- void line(int x1, int y1, int x2, int y2)
- {
- float verts[] = {
- x1 + 0.5f, y1 + 0.5f,
- x2 + 0.5f, y2 + 0.5f
- };
-
- Shader* shader = gl.getShader();
- shader->setVertexPointer(2, GL_FLOAT, 0, verts);
+ Shader* shader = gl.getShader();
+ shader->setVertexPointer(2, GL_FLOAT, 0, verts);
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- glDrawArrays(GL_LINES, 0, 2);
- }
-
- void circle(RenderMode mode, int x, int y, int r)
- {
- r = r < 0 ? 0 : r;
-
- int points = 40;
- float two_pi = static_cast<float>(PI * 2);
- if (points <= 0) points = 1;
- float angle_shift = (two_pi / points);
- float phi = .0f;
-
- float *coords = new float[2 * (points + 1)];
- for (int i = 0; i < points; ++i, phi += angle_shift)
- {
- coords[2 * i] = x + r * cos(phi);
- coords[2 * i + 1] = y + r * sin(phi);
- }
-
- coords[2 * points] = coords[0];
- coords[2 * points + 1] = coords[1];
-
- polygon(mode, coords, points);
-
- delete[] coords;
- }
-
- void rect(RenderMode mode, int x, int y, int w, int h)
- {
- float coords[] = { x + 0.5f, y + 0.5f, x + w + 0.5f, y + 0.5f, x + w + 0.5f, y + h + 0.5f, x + 0.5f, y + h + 0.5f };
- polygon(mode, coords, 4);
- }
-
- void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3)
- {
- float coords[] = { x1 + 0.5f, y1 + 0.5f, x2 + 0.5f, y2 + 0.5f, x3 + 0.5f, y3 + 0.5f };
- polygon(mode, coords, 3);
- }
-
- void polygon_line(float* p, int count)
- {
- Shader* shader = gl.getShader();
+ glDrawArrays(GL_LINES, 0, 2);
+ }
+
+ void circle(RenderMode mode, int x, int y, int r)
+ {
+ r = r < 0 ? 0 : r;
+
+ int points = 40;
+ float two_pi = static_cast<float>(PI * 2);
+ if (points <= 0) points = 1;
+ float angle_shift = (two_pi / points);
+ float phi = .0f;
+
+ float *coords = new float[2 * (points + 1)];
+ for (int i = 0; i < points; ++i, phi += angle_shift)
+ {
+ coords[2 * i] = x + r * cos(phi);
+ coords[2 * i + 1] = y + r * sin(phi);
+ }
+
+ coords[2 * points] = coords[0];
+ coords[2 * points + 1] = coords[1];
+
+ polygon(mode, coords, points);
+
+ delete[] coords;
+ }
+
+ void rect(RenderMode mode, int x, int y, int w, int h)
+ {
+ float coords[] = { x + 0.5f, y + 0.5f, x + w + 0.5f, y + 0.5f, x + w + 0.5f, y + h + 0.5f, x + 0.5f, y + h + 0.5f };
+ polygon(mode, coords, 4);
+ }
+
+ void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3)
+ {
+ float coords[] = { x1 + 0.5f, y1 + 0.5f, x2 + 0.5f, y2 + 0.5f, x3 + 0.5f, y3 + 0.5f };
+ polygon(mode, coords, 3);
+ }
+
+ void polygon_line(float* p, int count)
+ {
+ Shader* shader = gl.getShader();
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- shader->setVertexPointer(2, GL_FLOAT, 0, p);
-
- glDrawArrays(GL_LINE_LOOP, 0, count);
- }
-
- void polygon(RenderMode mode, float* p, int count)
- {
- if (mode == LINE)
- {
- polygon_line(p, count);
- }
- else if (mode == FILL)
- {
- Shader* shader = gl.getShader();
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->setVertexPointer(2, GL_FLOAT, 0, p);
+
+ glDrawArrays(GL_LINE_LOOP, 0, count);
+ }
+
+ void polygon(RenderMode mode, float* p, int count)
+ {
+ if (mode == LINE)
+ {
+ polygon_line(p, count);
+ }
+ else if (mode == FILL)
+ {
+ Shader* shader = gl.getShader();
Matrix modelMatrix = gl.getModelViewMatrix();
shader->sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
- shader->setVertexPointer(2, GL_FLOAT, 0, p);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix());
+ shader->setVertexPointer(2, GL_FLOAT, 0, p);
- glDrawArrays(GL_POLYGON, 0, count);
- }
- }
+ glDrawArrays(GL_POLYGON, 0, count);
+ }
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_shapes.h b/src/libjin/graphics/je_shapes.h
index d62592b..dcc134d 100644
--- a/src/libjin/graphics/je_shapes.h
+++ b/src/libjin/graphics/je_shapes.h
@@ -9,24 +9,24 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- enum RenderMode {
- NONE = 0,
- FILL ,
- LINE
- };
+ enum RenderMode {
+ NONE = 0,
+ FILL ,
+ LINE
+ };
- extern void line(int x1, int y1, int x2, int y2);
- 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 line(int x1, int y1, int x2, int y2);
+ 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);
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/je_sprite.h b/src/libjin/graphics/je_sprite.h
index 70e8f7b..fe38a4a 100644
--- a/src/libjin/graphics/je_sprite.h
+++ b/src/libjin/graphics/je_sprite.h
@@ -17,7 +17,7 @@ namespace JinEngine
/// A sprite is unit of rendering. Animation is based on sprite, but not texture or other graphic stuff.
///
class Sprite : public Object, public Renderable
- {
+ {
public:
Sprite(const Graphic* graphic, const Math::Quad& quad, Origin origin);
@@ -47,7 +47,7 @@ namespace JinEngine
const Graphic* mGraphic;
- };
+ };
} // namespace Graphics
} // namespace JinEngine
diff --git a/src/libjin/graphics/je_texture.cpp b/src/libjin/graphics/je_texture.cpp
index 8d9bb0a..152e5d0 100644
--- a/src/libjin/graphics/je_texture.cpp
+++ b/src/libjin/graphics/je_texture.cpp
@@ -12,8 +12,8 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
/*
Texture* Texture::createTexture(const char* path)
{
@@ -23,11 +23,11 @@ namespace JinEngine
return texture;
}
- Texture* Texture::createTexture(Bitmap* bitmap)
- {
- Texture* tex = new Texture(bitmap);
- return tex;
- }
+ Texture* Texture::createTexture(Bitmap* bitmap)
+ {
+ Texture* tex = new Texture(bitmap);
+ return tex;
+ }
*/
Texture::Texture()
: Graphic()
@@ -41,16 +41,16 @@ namespace JinEngine
delete bitmap;
}
- Texture::Texture(const Bitmap* bitmap)
- : Graphic(bitmap)
- {
- }
+ Texture::Texture(const Bitmap* bitmap)
+ : Graphic(bitmap)
+ {
+ }
- Texture::~Texture()
- {
- }
+ Texture::~Texture()
+ {
+ }
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_texture.h b/src/libjin/graphics/je_texture.h
index 94e7a01..6e14111 100644
--- a/src/libjin/graphics/je_texture.h
+++ b/src/libjin/graphics/je_texture.h
@@ -11,20 +11,20 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
///
///
- class Texture : public Graphic
- {
- public:
+ class Texture : public Graphic
+ {
+ public:
/*
///
///
///
- static Texture* createTexture(const char* path);
+ static Texture* createTexture(const char* path);
///
///
@@ -55,11 +55,11 @@ namespace JinEngine
///
///
///
- ~Texture();
+ ~Texture();
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/je_window.cpp b/src/libjin/graphics/je_window.cpp
index 6572304..3260e14 100644
--- a/src/libjin/graphics/je_window.cpp
+++ b/src/libjin/graphics/je_window.cpp
@@ -17,57 +17,57 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
-
- bool Window::startSystem(const SettingBase* s)
- {
- jin_log_info("Initialize window system.");
-
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
- return false;
-
- const Setting* setting = (Setting*)s;
- mSize.w = setting->width;
+ namespace Graphics
+ {
+
+ bool Window::startSystem(const SettingBase* s)
+ {
+ jin_log_info("Initialize window system.");
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0)
+ return false;
+
+ const Setting* setting = (Setting*)s;
+ mSize.w = setting->width;
mSize.h = setting->height;
- mFps = setting->fps;
- bool vsync = setting->vsync;
- const char* title = setting->title;
+ mFps = setting->fps;
+ bool vsync = setting->vsync;
+ const char* title = setting->title;
const char* icon = setting->icon;
- if (mWnd)
- {
- SDL_DestroyWindow(mWnd);
- SDL_FlushEvent(SDL_WINDOWEVENT);
- }
-
- SDL_GLContext ctx = NULL;
-
- if (ctx)
- {
- SDL_GL_DeleteContext(ctx);
- }
-
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ if (mWnd)
+ {
+ SDL_DestroyWindow(mWnd);
+ SDL_FlushEvent(SDL_WINDOWEVENT);
+ }
+
+ SDL_GLContext ctx = NULL;
+
+ if (ctx)
+ {
+ SDL_GL_DeleteContext(ctx);
+ }
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
- int wx = SDL_WINDOWPOS_UNDEFINED,
- wy = SDL_WINDOWPOS_UNDEFINED;
+ int wx = SDL_WINDOWPOS_UNDEFINED,
+ wy = SDL_WINDOWPOS_UNDEFINED;
- int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
- if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
- if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
+ int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
+ if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
+ if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag);
- if (mWnd == NULL)
- return false;
+ if (mWnd == NULL)
+ return false;
// Set window icon.
try
@@ -82,49 +82,49 @@ namespace JinEngine
SDL_FreeSurface(surface);
} catch (...) {}
- ctx = SDL_GL_CreateContext(mWnd);
- if (ctx == NULL)
- return false;
- SDL_GL_SetSwapInterval(vsync ? 1 : 0);
- SDL_GL_MakeCurrent(mWnd, ctx);
- // Default configuration.
- gl.setClearColor(0, 0, 0, 0xff);
+ ctx = SDL_GL_CreateContext(mWnd);
+ if (ctx == NULL)
+ return false;
+ SDL_GL_SetSwapInterval(vsync ? 1 : 0);
+ SDL_GL_MakeCurrent(mWnd, ctx);
+ // Default configuration.
+ gl.setClearColor(0, 0, 0, 0xff);
glClear(GL_COLOR_BUFFER_BIT);
gl.setColor(0xff, 0xff, 0xff, 0xff);
- gl.enable(GL_BLEND);
- gl.enable(GL_TEXTURE_2D);
+ gl.enable(GL_BLEND);
+ gl.enable(GL_TEXTURE_2D);
// Default blend function.
gl.setBlendMode(OpenGL::BlendMode::ALPHA);
- // Bind to default canvas.
+ // Bind to default canvas.
gl.unbindCanvas();
gl.unuseShader();
- return true;
- }
+ return true;
+ }
- void Window::quitSystem()
- {
+ void Window::quitSystem()
+ {
jin_log_info("Quit window system.");
- // disable opengl
- gl.disable(GL_BLEND);
- gl.disable(GL_TEXTURE_2D);
- // close window
- SDL_DestroyWindow(mWnd);
- SDL_Quit();
- }
-
- void Window::swapBuffers()
- {
- if (mWnd)
- SDL_GL_SwapWindow(mWnd);
- }
-
- void Window::setTitle(const char* title)
- {
- SDL_SetWindowTitle(mWnd, title);
- };
-
- } // namespace Graphics
+ // disable opengl
+ gl.disable(GL_BLEND);
+ gl.disable(GL_TEXTURE_2D);
+ // close window
+ SDL_DestroyWindow(mWnd);
+ SDL_Quit();
+ }
+
+ void Window::swapBuffers()
+ {
+ if (mWnd)
+ SDL_GL_SwapWindow(mWnd);
+ }
+
+ void Window::setTitle(const char* title)
+ {
+ SDL_SetWindowTitle(mWnd, title);
+ };
+
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/graphics/je_window.h b/src/libjin/graphics/je_window.h
index 6e23445..902e873 100644
--- a/src/libjin/graphics/je_window.h
+++ b/src/libjin/graphics/je_window.h
@@ -11,29 +11,29 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
///
///
///
- class Window
+ class Window
: public Subsystem<Window>
- {
- public:
+ {
+ public:
///
///
///
- struct Setting : SettingBase
- {
- public:
- const char* title; ///< window title
+ struct Setting : SettingBase
+ {
+ public:
+ const char* title; ///< window title
const char* icon; ///< window icon
- bool fullscreen; ///< full screen
- int width, height; ///< window size
- bool vsync; ///< vsync
- int fps; ///< frame per second
- bool resizable; ///< resizable
- };
+ bool fullscreen; ///< full screen
+ int width, height; ///< window size
+ bool vsync; ///< vsync
+ int fps; ///< frame per second
+ bool resizable; ///< resizable
+ };
///
///
@@ -48,27 +48,27 @@ namespace JinEngine
///
///
///
- void setTitle(const char* title);
+ void setTitle(const char* title);
///
///
///
- inline int getW(){ return mSize.w; }
+ inline int getW(){ return mSize.w; }
///
///
///
- inline int getH(){ return mSize.h; }
+ inline int getH(){ return mSize.h; }
///
///
///
- inline int getFPS(){ return mFps; }
+ inline int getFPS(){ return mFps; }
///
///
///
- void swapBuffers();
+ void swapBuffers();
///
///
@@ -80,25 +80,25 @@ namespace JinEngine
///
void show() { SDL_ShowWindow(mWnd); };
- private:
+ private:
///
///
///
- bool startSystem(const SettingBase* setting) override;
+ bool startSystem(const SettingBase* setting) override;
///
///
///
- void quitSystem() override;
+ void quitSystem() override;
- SDL_Window* mWnd;
- JinEngine::Math::Vector2<unsigned int> mSize;
- int mFps;
+ SDL_Window* mWnd;
+ JinEngine::Math::Vector2<unsigned int> mSize;
+ int mFps;
- };
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // jin_graphics
diff --git a/src/libjin/graphics/shaders/je_base.shader.h b/src/libjin/graphics/shaders/je_base.shader.h
index 34996bc..1cecddf 100644
--- a/src/libjin/graphics/shaders/je_base.shader.h
+++ b/src/libjin/graphics/shaders/je_base.shader.h
@@ -2,13 +2,13 @@
#define __JE_BASE_SHADER_H__
static const char* base_shared = R"(
-#define Number float
+#define Number float
#define Texture sampler2D
#define Canvas sampler2D
#define Color vec4
-#define Vec2 vec2
-#define Vec3 vec3
-#define Vec4 vec4
+#define Vec2 vec2
+#define Vec3 vec3
+#define Vec4 vec4
#define texel texture2D
@@ -26,9 +26,8 @@ static const char* base_vertex = R"(
#version 130 core
%s
-// Projection matrix
+
uniform mat4 jin_ProjectionMatrix;
-// Model view matrix
uniform mat4 jin_ModelViewMatrix;
in vec2 jin_VertexCoords;
@@ -42,10 +41,10 @@ out vec2 jin_UV;
void main()
{
- vec4 v = jin_ModelViewMatrix * vec4(jin_VertexCoords, 0, 1.0);
+ vec4 v = jin_ModelViewMatrix * vec4(jin_VertexCoords, 0, 1.0);
Vertex _v = vert(Vertex(v.xy, jin_TextureCoords));
- gl_Position = jin_ProjectionMatrix * vec4(_v.xy, 0, 1.0f);
- jin_Color = gl_Color;
+ gl_Position = jin_ProjectionMatrix * vec4(_v.xy, 0, 1.0f);
+ jin_Color = gl_Color;
jin_XY = _v.xy;
jin_UV = _v.uv;
}
@@ -86,4 +85,4 @@ static const char* SHADER_MAIN_TEXTURE = "jin_MainTexture";
static const char* SHADER_VERTEX_COORDS = "jin_VertexCoords";
static const char* SHADER_TEXTURE_COORDS = "jin_TextureCoords";
-#endif // __JE_BASE_SHADER_H__
+#endif // __JE_BASE_SHADER_H__ \ No newline at end of file
diff --git a/src/libjin/graphics/shaders/je_shader.cpp b/src/libjin/graphics/shaders/je_shader.cpp
index 017231a..b7a4bba 100644
--- a/src/libjin/graphics/shaders/je_shader.cpp
+++ b/src/libjin/graphics/shaders/je_shader.cpp
@@ -16,8 +16,8 @@ using namespace JinEngine::Filesystem;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Shaders
{
@@ -145,8 +145,8 @@ if (success == GL_FALSE) \
}
#define checkJSL() \
- if (gl.getShader() != this) \
- return
+ if (gl.getShader() != this) \
+ return
void Shader::sendInt(const char* name, int value)
{
@@ -267,7 +267,7 @@ if (success == GL_FALSE) \
}
} // namespace Shaders
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/graphics/shaders/je_shader.h b/src/libjin/graphics/shaders/je_shader.h
index d8be118..2ccc537 100644
--- a/src/libjin/graphics/shaders/je_shader.h
+++ b/src/libjin/graphics/shaders/je_shader.h
@@ -17,8 +17,8 @@
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
namespace Shaders
{
@@ -175,7 +175,7 @@ namespace JinEngine
};
} // namespace Shaders
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine
#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
diff --git a/src/libjin/input/je_keyboard.h b/src/libjin/input/je_keyboard.h
index 25cfd5d..ffaad66 100644
--- a/src/libjin/input/je_keyboard.h
+++ b/src/libjin/input/je_keyboard.h
@@ -3,18 +3,18 @@
namespace JinEngine
{
- namespace Input
- {
+ namespace Input
+ {
///
///
///
- class Keyboard
- {
+ class Keyboard
+ {
- };
+ };
- } // namespace Input
+ } // namespace Input
} // namespace JinEngine
#endif // __JE_KEYBOARD_H__
diff --git a/src/libjin/input/je_mouse.cpp b/src/libjin/input/je_mouse.cpp
index 476b1a2..edd3cf5 100644
--- a/src/libjin/input/je_mouse.cpp
+++ b/src/libjin/input/je_mouse.cpp
@@ -7,22 +7,22 @@
namespace JinEngine
{
- namespace Input
- {
+ namespace Input
+ {
- void Mouse::getState(int* x, int* y)
- {
- #ifdef jin_input == jin_input_sdl
- SDL_GetMouseState(x, y);
- #endif
- }
+ void Mouse::getState(int* x, int* y)
+ {
+ #ifdef jin_input == jin_input_sdl
+ SDL_GetMouseState(x, y);
+ #endif
+ }
- void Mouse::setVisible(bool visible)
- {
- SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
- }
+ void Mouse::setVisible(bool visible)
+ {
+ SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
+ }
- } // namespace Input
+ } // namespace Input
} // namespace JinEngine
#endif // defined(jin_input) \ No newline at end of file
diff --git a/src/libjin/input/je_mouse.h b/src/libjin/input/je_mouse.h
index d129a07..f05f3bf 100644
--- a/src/libjin/input/je_mouse.h
+++ b/src/libjin/input/je_mouse.h
@@ -7,15 +7,15 @@
namespace JinEngine
{
- namespace Input
- {
+ namespace Input
+ {
///
///
///
- class Mouse : public Singleton<Mouse>
- {
- public:
+ class Mouse : public Singleton<Mouse>
+ {
+ public:
///
///
///
@@ -29,16 +29,16 @@ namespace JinEngine
///
///
///
- void getState(int* x, int* y);
+ void getState(int* x, int* y);
///
///
///
- void setVisible(bool visible);
+ void setVisible(bool visible);
- };
+ };
- } // namespace Input
+ } // namespace Input
} // namespace JinEngine
#endif // defined(jin_input)
diff --git a/src/libjin/math/je_math.h b/src/libjin/math/je_math.h
index ed46e58..f0a0a4c 100644
--- a/src/libjin/math/je_math.h
+++ b/src/libjin/math/je_math.h
@@ -7,63 +7,63 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- #ifdef min
- #undef min
- #endif // min
- #ifdef max
- #undef max
- #endif // max
+ #ifdef min
+ #undef min
+ #endif // min
+ #ifdef max
+ #undef max
+ #endif // max
- template<typename T>
- inline T min(T a, T b)
- {
- return a < b ? a : b;
- }
+ template<typename T>
+ inline T min(T a, T b)
+ {
+ return a < b ? a : b;
+ }
- template<typename T>
- inline T max(T a, T b)
- {
- return a > b ? a : b;
- }
+ template<typename T>
+ inline T max(T a, T b)
+ {
+ return a > b ? a : b;
+ }
- template<typename T>
- inline T clamp(T a, T mi, T ma)
- {
- return min<T>(max<T>(a, mi), ma);
- }
+ template<typename T>
+ inline T clamp(T a, T mi, T ma)
+ {
+ return min<T>(max<T>(a, mi), ma);
+ }
- template<typename T>
- inline bool within(T a, T mi, T ma)
- {
- return a >= mi && a <= ma;
- }
+ template<typename T>
+ inline bool within(T a, T mi, T ma)
+ {
+ return a >= mi && a <= ma;
+ }
- template<typename T>
- inline bool without(T a, T mi, T ma)
- {
- return a < mi || a > ma;
- }
+ template<typename T>
+ inline bool without(T a, T mi, T ma)
+ {
+ return a < mi || a > ma;
+ }
- template<typename T>
- inline T lowerBound(T a, T lower)
- {
- return a < lower ? lower : a;
- }
+ template<typename T>
+ inline T lowerBound(T a, T lower)
+ {
+ return a < lower ? lower : a;
+ }
- template<typename T>
- inline T upperBound(T a, T upper)
- {
- return a > upper ? upper : a;
- }
+ template<typename T>
+ inline T upperBound(T a, T upper)
+ {
+ return a > upper ? upper : a;
+ }
- template<typename T>
- inline T lerp(T a, T b, float t)
- {
- return a + t * (b - a);
- }
+ template<typename T>
+ inline T lerp(T a, T b, float t)
+ {
+ return a + t * (b - a);
+ }
inline float lerp(float a, float b, float f)
{
@@ -83,7 +83,7 @@ namespace JinEngine
return -a;
}
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_UTILS_MATH_H__ \ No newline at end of file
diff --git a/src/libjin/math/je_matrix.cpp b/src/libjin/math/je_matrix.cpp
index bc1fcea..f51ef5d 100644
--- a/src/libjin/math/je_matrix.cpp
+++ b/src/libjin/math/je_matrix.cpp
@@ -5,190 +5,190 @@
namespace JinEngine
{
- namespace Math
- {
-
- const Matrix Matrix::Identity;
-
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
-
- Matrix::Matrix()
- {
- setIdentity();
- }
-
- Matrix::~Matrix()
- {
- }
-
- void Matrix::setOrtho(float l, float r, float b, float t, float n, float f)
- {
- setIdentity();
- float w = r - l;
- float h = t - b;
- float z = f - n;
- e[0] = 2 / w;
- e[5] = 2 / h;
- e[10] = -2 / z;
- e[12] = -(r + l) / w;
- e[13] = -(t + b) / h;
- e[14] = -(f + n) / z;
- e[15] = 1;
- }
-
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
-
- Matrix Matrix::operator * (const Matrix & m) const
- {
- Matrix t;
-
- t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]);
- t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]);
- t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]);
- t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]);
-
- t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]);
- t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]);
- t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]);
- t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]);
-
- t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]);
- t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]);
- t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]);
- t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]);
-
- t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]);
- t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]);
- t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]);
- t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]);
-
- return t;
- }
-
- void Matrix::operator *= (const Matrix & m)
- {
- Matrix t = (*this) * m;
- memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16);
- }
-
- const float * Matrix::getElements() const
- {
- return e;
- }
-
- void Matrix::setIdentity()
- {
- memset(e, 0, sizeof(float) * 16);
- e[0] = e[5] = e[10] = e[15] = 1;
- }
-
- void Matrix::setTranslation(float x, float y)
- {
- setIdentity();
- e[12] = x;
- e[13] = y;
- }
-
- void Matrix::setRotation(float rad)
- {
- setIdentity();
- float c = cos(rad), s = sin(rad);
- e[0] = c; e[4] = -s;
- e[1] = s; e[5] = c;
- }
-
- void Matrix::setScale(float sx, float sy)
- {
- setIdentity();
- e[0] = sx;
- e[5] = sy;
- }
-
- void Matrix::setShear(float kx, float ky)
- {
- setIdentity();
- e[1] = ky;
- e[4] = kx;
- }
-
- void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy)
- {
- memset(e, 0, sizeof(float) * 16); // zero out matrix
- float c = cos(angle), s = sin(angle);
- // matrix multiplication carried out on paper:
- // |1 x| |c -s | |sx | |1 -ox|
- // | 1 y| |s c | | sy | | 1 -oy|
- // | 1 | | 1 | | 1 | | 1 |
- // | 1| | 1| | 1| | 1 |
- // move rotate scale origin
- e[10] = e[15] = 1.0f;
- e[0] = c * sx ; // = a
- e[1] = s * sx ; // = b
- e[4] = - s * sy; // = c
- e[5] = c * sy; // = d
- e[12] = x - ox * e[0] - oy * e[4];
- e[13] = y - ox * e[1] - oy * e[5];
- }
-
- void Matrix::translate(float x, float y)
- {
- Matrix t;
- t.setTranslation(x, y);
- this->operator *=(t);
- }
-
- void Matrix::rotate(float rad)
- {
- Matrix t;
- t.setRotation(rad);
- this->operator *=(t);
- }
-
- void Matrix::scale(float sx, float sy)
- {
- Matrix t;
- t.setScale(sx, sy);
- this->operator *=(t);
- }
-
- void Matrix::shear(float kx, float ky)
- {
- Matrix t;
- t.setShear(kx, ky);
- this->operator *=(t);
- }
-
- // | x |
- // | y |
- // | 0 |
- // | 1 |
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
-
- void Matrix::transform(vertex * dst, const vertex * src, int size) const
- {
- for (int i = 0; i<size; ++i)
- {
- // Store in temp variables in case src = dst
- float x = (e[0] * src[i].x) + (e[4] * src[i].y) + (0) + (e[12]);
- float y = (e[1] * src[i].x) + (e[5] * src[i].y) + (0) + (e[13]);
-
- dst[i].x = x;
- dst[i].y = y;
- }
- }
-
- } // namespace Math
+ namespace Math
+ {
+
+ const Matrix Matrix::Identity;
+
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ Matrix::Matrix()
+ {
+ setIdentity();
+ }
+
+ Matrix::~Matrix()
+ {
+ }
+
+ void Matrix::setOrtho(float l, float r, float b, float t, float n, float f)
+ {
+ setIdentity();
+ float w = r - l;
+ float h = t - b;
+ float z = f - n;
+ e[0] = 2 / w;
+ e[5] = 2 / h;
+ e[10] = -2 / z;
+ e[12] = -(r + l) / w;
+ e[13] = -(t + b) / h;
+ e[14] = -(f + n) / z;
+ e[15] = 1;
+ }
+
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ Matrix Matrix::operator * (const Matrix & m) const
+ {
+ Matrix t;
+
+ t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]);
+ t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]);
+ t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]);
+ t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]);
+
+ t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]);
+ t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]);
+ t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]);
+ t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]);
+
+ t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]);
+ t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]);
+ t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]);
+ t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]);
+
+ t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]);
+ t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]);
+ t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]);
+ t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]);
+
+ return t;
+ }
+
+ void Matrix::operator *= (const Matrix & m)
+ {
+ Matrix t = (*this) * m;
+ memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16);
+ }
+
+ const float * Matrix::getElements() const
+ {
+ return e;
+ }
+
+ void Matrix::setIdentity()
+ {
+ memset(e, 0, sizeof(float) * 16);
+ e[0] = e[5] = e[10] = e[15] = 1;
+ }
+
+ void Matrix::setTranslation(float x, float y)
+ {
+ setIdentity();
+ e[12] = x;
+ e[13] = y;
+ }
+
+ void Matrix::setRotation(float rad)
+ {
+ setIdentity();
+ float c = cos(rad), s = sin(rad);
+ e[0] = c; e[4] = -s;
+ e[1] = s; e[5] = c;
+ }
+
+ void Matrix::setScale(float sx, float sy)
+ {
+ setIdentity();
+ e[0] = sx;
+ e[5] = sy;
+ }
+
+ void Matrix::setShear(float kx, float ky)
+ {
+ setIdentity();
+ e[1] = ky;
+ e[4] = kx;
+ }
+
+ void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy)
+ {
+ memset(e, 0, sizeof(float) * 16); // zero out matrix
+ float c = cos(angle), s = sin(angle);
+ // matrix multiplication carried out on paper:
+ // |1 x| |c -s | |sx | |1 -ox|
+ // | 1 y| |s c | | sy | | 1 -oy|
+ // | 1 | | 1 | | 1 | | 1 |
+ // | 1| | 1| | 1| | 1 |
+ // move rotate scale origin
+ e[10] = e[15] = 1.0f;
+ e[0] = c * sx ; // = a
+ e[1] = s * sx ; // = b
+ e[4] = - s * sy; // = c
+ e[5] = c * sy; // = d
+ e[12] = x - ox * e[0] - oy * e[4];
+ e[13] = y - ox * e[1] - oy * e[5];
+ }
+
+ void Matrix::translate(float x, float y)
+ {
+ Matrix t;
+ t.setTranslation(x, y);
+ this->operator *=(t);
+ }
+
+ void Matrix::rotate(float rad)
+ {
+ Matrix t;
+ t.setRotation(rad);
+ this->operator *=(t);
+ }
+
+ void Matrix::scale(float sx, float sy)
+ {
+ Matrix t;
+ t.setScale(sx, sy);
+ this->operator *=(t);
+ }
+
+ void Matrix::shear(float kx, float ky)
+ {
+ Matrix t;
+ t.setShear(kx, ky);
+ this->operator *=(t);
+ }
+
+ // | x |
+ // | y |
+ // | 0 |
+ // | 1 |
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ void Matrix::transform(vertex * dst, const vertex * src, int size) const
+ {
+ for (int i = 0; i<size; ++i)
+ {
+ // Store in temp variables in case src = dst
+ float x = (e[0] * src[i].x) + (e[4] * src[i].y) + (0) + (e[12]);
+ float y = (e[1] * src[i].x) + (e[5] * src[i].y) + (0) + (e[13]);
+
+ dst[i].x = x;
+ dst[i].y = y;
+ }
+ }
+
+ } // namespace Math
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/math/je_matrix.h b/src/libjin/math/je_matrix.h
index bbc831d..f35b88b 100644
--- a/src/libjin/math/je_matrix.h
+++ b/src/libjin/math/je_matrix.h
@@ -3,157 +3,157 @@
namespace JinEngine
{
- namespace Math
- {
-
- struct vertex
- {
- unsigned char r, g, b, a;
- float x, y;
- float s, t;
- };
- ///
- /// This class is the basis for all transformations in LOVE. Althought not
- /// really needed for 2D, it contains 4x4 elements to be compatible with
- /// OpenGL without conversions.
- /// Ҫתõľ
- /// https://blog.csdn.net/candycat1992/article/details/8830894
- ///
- class Matrix
- {
- private:
-
- ///
- /// | e0 e4 e8 e12 |
- /// | e1 e5 e9 e13 |
- /// | e2 e6 e10 e14 |
- /// | e3 e7 e11 e15 |
- ///
- float e[16];
-
- public:
-
- static const Matrix Identity;
-
- ///
- /// Creates a new identity matrix.
- ///
- Matrix();
-
- ///
+ namespace Math
+ {
+
+ struct vertex
+ {
+ unsigned char r, g, b, a;
+ float x, y;
+ float s, t;
+ };
+ ///
+ /// This class is the basis for all transformations in LOVE. Althought not
+ /// really needed for 2D, it contains 4x4 elements to be compatible with
+ /// OpenGL without conversions.
+ /// Ҫתõľ
+ /// https://blog.csdn.net/candycat1992/article/details/8830894
+ ///
+ class Matrix
+ {
+ private:
+
+ ///
+ /// | e0 e4 e8 e12 |
+ /// | e1 e5 e9 e13 |
+ /// | e2 e6 e10 e14 |
+ /// | e3 e7 e11 e15 |
+ ///
+ float e[16];
+
+ public:
+
+ static const Matrix Identity;
+
+ ///
+ /// Creates a new identity matrix.
+ ///
+ Matrix();
+
+ ///
/// Destructor.
- ///
- ~Matrix();
-
- void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far);
-
- ///
- /// Multiplies this Matrix with another Matrix, changing neither.
- /// @param m The Matrix to multiply with this Matrix.
- /// @return The combined matrix.
- ///
- Matrix operator * (const Matrix & m) const;
-
- ///
- /// Multiplies a Matrix into this Matrix.
- /// @param m The Matrix to combine into this Matrix.
- ///
- void operator *= (const Matrix & m);
-
- ///
- /// Gets a pointer to the 16 array elements.
- /// @return The array elements.
- ///
- const float* getElements() const;
-
- ///
- /// Resets this Matrix to the identity matrix.
- ///
- void setIdentity();
-
- ///
- /// Resets this Matrix to a translation.
- /// @param x Translation along x-axis.
- /// @param y Translation along y-axis.
- ///
- void setTranslation(float x, float y);
-
- ///
- /// Resets this Matrix to a rotation.
- /// @param r The angle in radians.
- ///
- void setRotation(float r);
-
- ///
- /// Resets this Matrix to a scale transformation.
- /// @param sx Scale factor along the x-axis.
- /// @param sy Scale factor along the y-axis.
- ///
- void setScale(float sx, float sy);
-
- ///
- /// Resets this Matrix to a shear transformation.
- /// @param kx Shear along x-axis.
- /// @param ky Shear along y-axis.
- ///
- void setShear(float kx, float ky);
-
- ///
- /// Creates a transformation with a certain position, orientation, scale
- /// and offset. Perfect for Drawables -- what a coincidence!
- ///
- /// @param x The translation along the x-axis.
- /// @param y The translation along the y-axis.
- /// @param angle The rotation (rad) around the center with offset (ox,oy).
- /// @param sx Scale along x-axis.
- /// @param sy Scale along y-axis.
- /// @param ox The offset for rotation along the x-axis.
- /// @param oy The offset for rotation along the y-axis.
- /// @param kx Shear along x-axis
- /// @param ky Shear along y-axis
- ///
- void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy);
-
- ///
- /// Multiplies this Matrix with a translation.
- /// @param x Translation along x-axis.
- /// @param y Translation along y-axis.
- ///
- void translate(float x, float y);
-
- ///
- /// Multiplies this Matrix with a rotation.
- /// @param r Angle in radians.
- ///
- void rotate(float r);
-
- ///
- /// Multiplies this Matrix with a scale transformation.
- /// @param sx Scale factor along the x-axis.
- /// @param sy Scale factor along the y-axis.
- ///
- void scale(float sx, float sy);
-
- ///
- /// Multiplies this Matrix with a shear transformation.
- /// @param kx Shear along the x-axis.
- /// @param ky Shear along the y-axis.
- ///
- void shear(float kx, float ky);
-
- ///
- /// Transforms an array of vertices by this Matrix. The sources and
- /// destination arrays may be the same.
- ///
- /// @param dst Storage for the transformed vertices.
- /// @param src The source vertices.
- /// @param size The number of vertices.
- ///
- void transform(vertex * dst, const vertex * src, int size) const;
-
- };
-
- } // namespace Math
+ ///
+ ~Matrix();
+
+ void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far);
+
+ ///
+ /// Multiplies this Matrix with another Matrix, changing neither.
+ /// @param m The Matrix to multiply with this Matrix.
+ /// @return The combined matrix.
+ ///
+ Matrix operator * (const Matrix & m) const;
+
+ ///
+ /// Multiplies a Matrix into this Matrix.
+ /// @param m The Matrix to combine into this Matrix.
+ ///
+ void operator *= (const Matrix & m);
+
+ ///
+ /// Gets a pointer to the 16 array elements.
+ /// @return The array elements.
+ ///
+ const float* getElements() const;
+
+ ///
+ /// Resets this Matrix to the identity matrix.
+ ///
+ void setIdentity();
+
+ ///
+ /// Resets this Matrix to a translation.
+ /// @param x Translation along x-axis.
+ /// @param y Translation along y-axis.
+ ///
+ void setTranslation(float x, float y);
+
+ ///
+ /// Resets this Matrix to a rotation.
+ /// @param r The angle in radians.
+ ///
+ void setRotation(float r);
+
+ ///
+ /// Resets this Matrix to a scale transformation.
+ /// @param sx Scale factor along the x-axis.
+ /// @param sy Scale factor along the y-axis.
+ ///
+ void setScale(float sx, float sy);
+
+ ///
+ /// Resets this Matrix to a shear transformation.
+ /// @param kx Shear along x-axis.
+ /// @param ky Shear along y-axis.
+ ///
+ void setShear(float kx, float ky);
+
+ ///
+ /// Creates a transformation with a certain position, orientation, scale
+ /// and offset. Perfect for Drawables -- what a coincidence!
+ ///
+ /// @param x The translation along the x-axis.
+ /// @param y The translation along the y-axis.
+ /// @param angle The rotation (rad) around the center with offset (ox,oy).
+ /// @param sx Scale along x-axis.
+ /// @param sy Scale along y-axis.
+ /// @param ox The offset for rotation along the x-axis.
+ /// @param oy The offset for rotation along the y-axis.
+ /// @param kx Shear along x-axis
+ /// @param ky Shear along y-axis
+ ///
+ void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy);
+
+ ///
+ /// Multiplies this Matrix with a translation.
+ /// @param x Translation along x-axis.
+ /// @param y Translation along y-axis.
+ ///
+ void translate(float x, float y);
+
+ ///
+ /// Multiplies this Matrix with a rotation.
+ /// @param r Angle in radians.
+ ///
+ void rotate(float r);
+
+ ///
+ /// Multiplies this Matrix with a scale transformation.
+ /// @param sx Scale factor along the x-axis.
+ /// @param sy Scale factor along the y-axis.
+ ///
+ void scale(float sx, float sy);
+
+ ///
+ /// Multiplies this Matrix with a shear transformation.
+ /// @param kx Shear along the x-axis.
+ /// @param ky Shear along the y-axis.
+ ///
+ void shear(float kx, float ky);
+
+ ///
+ /// Transforms an array of vertices by this Matrix. The sources and
+ /// destination arrays may be the same.
+ ///
+ /// @param dst Storage for the transformed vertices.
+ /// @param src The source vertices.
+ /// @param size The number of vertices.
+ ///
+ void transform(vertex * dst, const vertex * src, int size) const;
+
+ };
+
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_MATRIX_H__
diff --git a/src/libjin/math/je_quad.h b/src/libjin/math/je_quad.h
index b07b5f6..e62f370 100644
--- a/src/libjin/math/je_quad.h
+++ b/src/libjin/math/je_quad.h
@@ -3,14 +3,14 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
///
///
///
- struct Quad
- {
+ struct Quad
+ {
Quad()
: x(0), y(0), w(0), h(0)
{
@@ -21,10 +21,10 @@ namespace JinEngine
{
}
- float x, y, w, h;
- };
+ float x, y, w, h;
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_QUAD_H__ \ No newline at end of file
diff --git a/src/libjin/math/je_vector2.hpp b/src/libjin/math/je_vector2.hpp
index 406b756..4d76987 100644
--- a/src/libjin/math/je_vector2.hpp
+++ b/src/libjin/math/je_vector2.hpp
@@ -3,27 +3,27 @@
namespace JinEngine
{
- namespace Math
- {
+ 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];
- }
+ 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];
+ }
void operator = (const Vector2<T>& v)
{
@@ -58,16 +58,16 @@ namespace JinEngine
return data[0] == 0 && data[1] == 0;
}
- T &x = data[0], &y = data[1]; // xy
- T &w = data[0], &h = data[1]; // wh
- T &colum = data[0], &row = data[1]; // colum row
+ T &x = data[0], &y = data[1]; // xy
+ T &w = data[0], &h = data[1]; // wh
+ T &colum = data[0], &row = data[1]; // colum row
- private:
- T data[2];
+ private:
+ T data[2];
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/math/je_vector3.hpp b/src/libjin/math/je_vector3.hpp
index fdab2d0..1e8f86d 100644
--- a/src/libjin/math/je_vector3.hpp
+++ b/src/libjin/math/je_vector3.hpp
@@ -3,39 +3,39 @@
namespace JinEngine
{
- namespace Math
- {
+ 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];
- }
+ 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
+ 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];
+ private:
+ T data[3];
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/math/je_vector4.hpp b/src/libjin/math/je_vector4.hpp
index 5cd5b35..02675dd 100644
--- a/src/libjin/math/je_vector4.hpp
+++ b/src/libjin/math/je_vector4.hpp
@@ -3,43 +3,43 @@
namespace JinEngine
{
- namespace Math
- {
+ 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];
- }
+ 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
- T &left = data[0], &right = data[1], &top = data[2], &bottom = data[3]; // lrtb
+ 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
+ T &left = data[0], &right = data[1], &top = data[2], &bottom = data[3]; // lrtb
- private:
- T data[4];
+ private:
+ T data[4];
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/net/je_net_manager.cpp b/src/libjin/net/je_net_manager.cpp
index 7990d99..553f9cb 100644
--- a/src/libjin/net/je_net_manager.cpp
+++ b/src/libjin/net/je_net_manager.cpp
@@ -2,23 +2,23 @@
namespace JinEngine
{
- namespace Net
- {
+ namespace Net
+ {
- bool NetManager::startSystem(const SettingBase* setting)
- {
- #ifdef _WIN32
- #if jin_net == jin_net_tekcos
- tk_init();
- #endif
- #endif
- return true;
- }
+ bool NetManager::startSystem(const SettingBase* setting)
+ {
+ #ifdef _WIN32
+ #if jin_net == jin_net_tekcos
+ tk_init();
+ #endif
+ #endif
+ return true;
+ }
- void NetManager::quitSystem()
- {
+ void NetManager::quitSystem()
+ {
- }
+ }
- } // namespace Net
+ } // namespace Net
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/net/je_net_manager.h b/src/libjin/net/je_net_manager.h
index 4efcd28..1271e37 100644
--- a/src/libjin/net/je_net_manager.h
+++ b/src/libjin/net/je_net_manager.h
@@ -9,38 +9,38 @@
namespace JinEngine
{
- namespace Net
- {
+ namespace Net
+ {
///
///
///
- class NetManager : public Subsystem<NetManager>
- {
- public:
+ class NetManager : public Subsystem<NetManager>
+ {
+ public:
///
///
///
- NetManager() {};
+ NetManager() {};
///
///
///
- ~NetManager() {};
+ ~NetManager() {};
///
///
///
- bool startSystem(const SettingBase* setting) override;
+ bool startSystem(const SettingBase* setting) override;
///
///
///
- void quitSystem() override;
+ void quitSystem() override;
- };
+ };
- } // namespace Net
+ } // namespace Net
} // namespace JinEngine
#endif // defined(jin_net)
diff --git a/src/libjin/net/je_socket.cpp b/src/libjin/net/je_socket.cpp
index 1810601..68f9aed 100644
--- a/src/libjin/net/je_socket.cpp
+++ b/src/libjin/net/je_socket.cpp
@@ -2,189 +2,189 @@
namespace JinEngine
{
- namespace Net
- {
- Socket::Socket(const Socket& socket)
- : mHandle(socket.mHandle)
- , mType(socket.mType)
- {
- }
-
- Socket::Socket(const SocketInformation& info)
- : mType(info.type)
- {
- if (mType == SocketType::TCP)
- {
- tk_IPaddress ip;
- ip.host = info.address;
- ip.port = info.port;
- mHandle.tcpHandle = tk_tcp_open(ip);
- }
- else if (mType == SocketType::UDP)
- {
- mHandle.udpHandle = tk_udp_open(info.port);
- }
- }
-
- Socket::Socket(SocketType type, const char* address, unsigned short port)
- {
- mType = type;
- if (mType == SocketType::TCP)
- {
- tk_IPaddress ip;
- #if jin_net == jin_net_tekcos
- ip.host = tk_strtohl(address);
- ip.port = port;
- mHandle.tcpHandle = tk_tcp_open(ip);
- #endif
- }
- else if (mType == SocketType::UDP)
- {
- mHandle.udpHandle = tk_udp_open(port);
- }
- }
-
- Socket::Socket(SocketType type, unsigned int address, unsigned short port)
- {
- mType = type;
- if (mType == SocketType::TCP)
- {
- tk_IPaddress ip;
- ip.host = address;
- ip.port = port;
- mHandle.tcpHandle = tk_tcp_open(ip);
- }
- else if (mType == SocketType::UDP)
- {
- mHandle.udpHandle = tk_udp_open(port);
- }
- }
-
- Socket::Socket(SocketType type, unsigned short port)
- {
- mType = type;
- if (mType == SocketType::TCP)
- {
- tk_IPaddress ip;
- ip.host = 0;
- ip.port = port;
- mHandle.tcpHandle = tk_tcp_open(ip);
- }
- else if (mType == SocketType::UDP)
- {
- mHandle.udpHandle = tk_udp_open(port);
- }
- }
-
- #if jin_net == jin_net_tekcos
-
- Socket::Socket(const tk_TCPsocket& tcphandle)
- {
- mHandle.tcpHandle = tcphandle;
- }
-
- Socket::Socket(const tk_UDPsocket& udphandle)
- {
- mHandle.udpHandle = udphandle;
- }
-
- #endif // jin_net == jin_net_tekcos
-
- Socket::~Socket()
- {
- }
-
- void Socket::configureBlocking(bool blocking)
- {
- if (mType != SocketType::TCP)
- return;
- #if jin_net == jin_net_tekcos
- if (blocking)
- tk_tcp_blocking(&mHandle.tcpHandle);
- else
- tk_tcp_nonblocking(&mHandle.tcpHandle);
- #endif
- }
-
- Socket* Socket::accept()
- {
- if (mType != SocketType::TCP)
- return nullptr;
- Socket* client;
- #if jin_net == jin_net_tekcos
- tk_TCPsocket socket = tk_tcp_accept(&mHandle.tcpHandle);
- client = new Socket(socket);
- #endif
- return client;
- }
-
- int Socket::receive(char* buffer, int size)
- {
- if (mType != SocketType::TCP)
- return 0;
- #if jin_net == jin_net_tekcos
- int len;
- tk_tcp_recv(&mHandle.tcpHandle, buffer, size, &len);
- return len;
- #endif
- }
+ namespace Net
+ {
+ Socket::Socket(const Socket& socket)
+ : mHandle(socket.mHandle)
+ , mType(socket.mType)
+ {
+ }
+
+ Socket::Socket(const SocketInformation& info)
+ : mType(info.type)
+ {
+ if (mType == SocketType::TCP)
+ {
+ tk_IPaddress ip;
+ ip.host = info.address;
+ ip.port = info.port;
+ mHandle.tcpHandle = tk_tcp_open(ip);
+ }
+ else if (mType == SocketType::UDP)
+ {
+ mHandle.udpHandle = tk_udp_open(info.port);
+ }
+ }
+
+ Socket::Socket(SocketType type, const char* address, unsigned short port)
+ {
+ mType = type;
+ if (mType == SocketType::TCP)
+ {
+ tk_IPaddress ip;
+ #if jin_net == jin_net_tekcos
+ ip.host = tk_strtohl(address);
+ ip.port = port;
+ mHandle.tcpHandle = tk_tcp_open(ip);
+ #endif
+ }
+ else if (mType == SocketType::UDP)
+ {
+ mHandle.udpHandle = tk_udp_open(port);
+ }
+ }
+
+ Socket::Socket(SocketType type, unsigned int address, unsigned short port)
+ {
+ mType = type;
+ if (mType == SocketType::TCP)
+ {
+ tk_IPaddress ip;
+ ip.host = address;
+ ip.port = port;
+ mHandle.tcpHandle = tk_tcp_open(ip);
+ }
+ else if (mType == SocketType::UDP)
+ {
+ mHandle.udpHandle = tk_udp_open(port);
+ }
+ }
+
+ Socket::Socket(SocketType type, unsigned short port)
+ {
+ mType = type;
+ if (mType == SocketType::TCP)
+ {
+ tk_IPaddress ip;
+ ip.host = 0;
+ ip.port = port;
+ mHandle.tcpHandle = tk_tcp_open(ip);
+ }
+ else if (mType == SocketType::UDP)
+ {
+ mHandle.udpHandle = tk_udp_open(port);
+ }
+ }
+
+ #if jin_net == jin_net_tekcos
+
+ Socket::Socket(const tk_TCPsocket& tcphandle)
+ {
+ mHandle.tcpHandle = tcphandle;
+ }
+
+ Socket::Socket(const tk_UDPsocket& udphandle)
+ {
+ mHandle.udpHandle = udphandle;
+ }
+
+ #endif // jin_net == jin_net_tekcos
+
+ Socket::~Socket()
+ {
+ }
+
+ void Socket::configureBlocking(bool blocking)
+ {
+ if (mType != SocketType::TCP)
+ return;
+ #if jin_net == jin_net_tekcos
+ if (blocking)
+ tk_tcp_blocking(&mHandle.tcpHandle);
+ else
+ tk_tcp_nonblocking(&mHandle.tcpHandle);
+ #endif
+ }
+
+ Socket* Socket::accept()
+ {
+ if (mType != SocketType::TCP)
+ return nullptr;
+ Socket* client;
+ #if jin_net == jin_net_tekcos
+ tk_TCPsocket socket = tk_tcp_accept(&mHandle.tcpHandle);
+ client = new Socket(socket);
+ #endif
+ return client;
+ }
+
+ int Socket::receive(char* buffer, int size)
+ {
+ if (mType != SocketType::TCP)
+ return 0;
+ #if jin_net == jin_net_tekcos
+ int len;
+ tk_tcp_recv(&mHandle.tcpHandle, buffer, size, &len);
+ return len;
+ #endif
+ }
- int Socket::send(char* buffer, int size)
- {
- if (mType != SocketType::TCP)
- return 0;
- #if jin_net == jin_net_tekcos
- int len;
- tk_tcp_send(&mHandle.tcpHandle, buffer, size, &len);
- return len;
- #endif
- }
-
- void Socket::sendTo(char* buffer, int size, unsigned int address, unsigned int port)
- {
- if (mType != SocketType::UDP)
- return;
- #if jin_net == jin_net_tekcos
- tk_UDPpack pack;
- pack.data = buffer;
- pack.len = size;
- pack.ip.host = address;
- pack.ip.port = port;
- tk_udp_sendto(&mHandle.udpHandle, &pack);
- #endif
- }
+ int Socket::send(char* buffer, int size)
+ {
+ if (mType != SocketType::TCP)
+ return 0;
+ #if jin_net == jin_net_tekcos
+ int len;
+ tk_tcp_send(&mHandle.tcpHandle, buffer, size, &len);
+ return len;
+ #endif
+ }
+
+ void Socket::sendTo(char* buffer, int size, unsigned int address, unsigned int port)
+ {
+ if (mType != SocketType::UDP)
+ return;
+ #if jin_net == jin_net_tekcos
+ tk_UDPpack pack;
+ pack.data = buffer;
+ pack.len = size;
+ pack.ip.host = address;
+ pack.ip.port = port;
+ tk_udp_sendto(&mHandle.udpHandle, &pack);
+ #endif
+ }
- int Socket::receiveFrom(char* buffer, int size, unsigned int address, unsigned int port)
- {
- if (mType != SocketType::UDP)
- return 0;
- int len;
- #if jin_net == jin_net_tekcos
- tk_UDPpack pack;
- pack.data = buffer;
- pack.len = size;
- pack.ip.host = address;
- pack.ip.port = port;
- tk_udp_recvfrom(&mHandle.udpHandle, &pack);
- return pack.len;
- #endif
- }
-
- void Socket::close()
- {
- if (mType == SocketType::TCP)
- {
- #if jin_net == jin_net_tekcos
- tk_tcp_close(&mHandle.tcpHandle);
- #endif
- }
- else if (mType == SocketType::UDP)
- {
- #if jin_net == jin_net_tekcos
- tk_udp_close(&mHandle.udpHandle);
- #endif
- }
- }
-
- } // namespace Net
+ int Socket::receiveFrom(char* buffer, int size, unsigned int address, unsigned int port)
+ {
+ if (mType != SocketType::UDP)
+ return 0;
+ int len;
+ #if jin_net == jin_net_tekcos
+ tk_UDPpack pack;
+ pack.data = buffer;
+ pack.len = size;
+ pack.ip.host = address;
+ pack.ip.port = port;
+ tk_udp_recvfrom(&mHandle.udpHandle, &pack);
+ return pack.len;
+ #endif
+ }
+
+ void Socket::close()
+ {
+ if (mType == SocketType::TCP)
+ {
+ #if jin_net == jin_net_tekcos
+ tk_tcp_close(&mHandle.tcpHandle);
+ #endif
+ }
+ else if (mType == SocketType::UDP)
+ {
+ #if jin_net == jin_net_tekcos
+ tk_udp_close(&mHandle.udpHandle);
+ #endif
+ }
+ }
+
+ } // namespace Net
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/net/je_socket.h b/src/libjin/net/je_socket.h
index 4e7faa8..00e91de 100644
--- a/src/libjin/net/je_socket.h
+++ b/src/libjin/net/je_socket.h
@@ -9,136 +9,136 @@
namespace JinEngine
{
- namespace Net
- {
+ namespace Net
+ {
///
///
///
- enum SocketType
- {
- TCP,
- UDP
- };
+ enum SocketType
+ {
+ TCP,
+ UDP
+ };
///
///
///
- struct SocketInformation
- {
- unsigned int address;
- unsigned short port;
- SocketType type;
- };
+ struct SocketInformation
+ {
+ unsigned int address;
+ unsigned short port;
+ SocketType type;
+ };
///
///
///
- class Socket : public Object
- {
- public:
+ class Socket : public Object
+ {
+ public:
///
///
///
- Socket() {};
+ Socket() {};
///
///
///
- Socket(const Socket& socket);
+ Socket(const Socket& socket);
///
///
///
- Socket(const SocketInformation& socketInformation);
+ Socket(const SocketInformation& socketInformation);
///
///
///
- Socket(SocketType type, unsigned short port);
+ Socket(SocketType type, unsigned short port);
///
///
///
- Socket(SocketType type, unsigned int address, unsigned short port);
+ Socket(SocketType type, unsigned int address, unsigned short port);
///
///
///
- Socket(SocketType type, const char* address, unsigned short port);
+ Socket(SocketType type, const char* address, unsigned short port);
///
///
///
- ~Socket();
+ ~Socket();
///
///
///
- void configureBlocking(bool bocking);
+ void configureBlocking(bool bocking);
///
///
///
- Socket* accept();
+ Socket* accept();
///
///
///
- int receive(char* buffer, int size);
+ int receive(char* buffer, int size);
///
///
///
- int send(char* buffer, int size);
+ int send(char* buffer, int size);
///
///
///
- void sendTo(char* buffer, int size, unsigned int address, unsigned int port);
+ void sendTo(char* buffer, int size, unsigned int address, unsigned int port);
///
///
///
- int receiveFrom(char* buffer, int size, unsigned int address, unsigned int port);
+ int receiveFrom(char* buffer, int size, unsigned int address, unsigned int port);
///
///
///
- void close();
+ void close();
- protected:
- #if jin_net == jin_net_tekcos
+ protected:
+ #if jin_net == jin_net_tekcos
///
///
///
- Socket(const tk_TCPsocket& tcpHandle);
+ Socket(const tk_TCPsocket& tcpHandle);
///
///
///
- Socket(const tk_UDPsocket& udpHandle);
+ Socket(const tk_UDPsocket& udpHandle);
///
///
///
- union
- {
- tk_TCPsocket tcpHandle;
- tk_UDPsocket udpHandle;
- } mHandle;
- #endif
+ union
+ {
+ tk_TCPsocket tcpHandle;
+ tk_UDPsocket udpHandle;
+ } mHandle;
+ #endif
///
///
///
- SocketType mType;
+ SocketType mType;
- };
+ };
- } // namespace Net
+ } // namespace Net
} // namespace JinEngine
#endif // defined(jin_net)
diff --git a/src/libjin/threads/je_thread.cpp b/src/libjin/threads/je_thread.cpp
index 0c34508..6a8a7eb 100644
--- a/src/libjin/threads/je_thread.cpp
+++ b/src/libjin/threads/je_thread.cpp
@@ -5,297 +5,297 @@
namespace JinEngine
{
- namespace Threads
- {
-
- class Mutex
- {
- public:
- Mutex();
- ~Mutex();
-
- void lock();
- void unlock();
- private:
- #if jin_thread == jin_thread_sdl
- SDL_mutex* mutex;
- #endif
- friend class Conditional;
- };
-
- // ̼߳signal wait
- class Conditional
- {
- public:
- Conditional();
- ~Conditional();
- void signal();
- void broadcast();
- bool wait(Mutex* mutex, int timeout = -1);
- private:
- #if jin_thread == jin_thread_sdl
- SDL_cond* cond;
- #endif
- };
-
- class Lock
- {
- public:
- Lock(Mutex* m) : mutex(m) {
- mutex->lock();
- }
-
- Lock(Mutex& m) : mutex(&m) {
- mutex->lock();
- }
-
- ~Lock() {
- mutex->unlock();
- }
- private:
- Mutex* mutex;
-
- Lock(Lock&) {}
-
- };
-
- //////////////////////////////////////////////////////////////////////
+ namespace Threads
+ {
+
+ class Mutex
+ {
+ public:
+ Mutex();
+ ~Mutex();
+
+ void lock();
+ void unlock();
+ private:
+ #if jin_thread == jin_thread_sdl
+ SDL_mutex* mutex;
+ #endif
+ friend class Conditional;
+ };
+
+ // ̼߳signal wait
+ class Conditional
+ {
+ public:
+ Conditional();
+ ~Conditional();
+ void signal();
+ void broadcast();
+ bool wait(Mutex* mutex, int timeout = -1);
+ private:
+ #if jin_thread == jin_thread_sdl
+ SDL_cond* cond;
+ #endif
+ };
+
+ class Lock
+ {
+ public:
+ Lock(Mutex* m) : mutex(m) {
+ mutex->lock();
+ }
+
+ Lock(Mutex& m) : mutex(&m) {
+ mutex->lock();
+ }
+
+ ~Lock() {
+ mutex->unlock();
+ }
+ private:
+ Mutex* mutex;
+
+ Lock(Lock&) {}
+
+ };
+
+ //////////////////////////////////////////////////////////////////////
- Mutex::Mutex()
- {
- #if jin_thread == jin_thread_sdl
- mutex = SDL_CreateMutex();
- #endif
- }
-
- Mutex::~Mutex()
- {
- #if jin_thread == jin_thread_sdl
- SDL_DestroyMutex(mutex);
- #endif
- }
-
- void Mutex::lock()
- {
- #if jin_thread == jin_thread_sdl
- SDL_LockMutex(mutex);
- #endif
- }
-
- void Mutex::unlock()
- {
- #if jin_thread == jin_thread_sdl
- SDL_UnlockMutex(mutex);
- #endif
- }
-
- //////////////////////////////////////////////////////////////////////
-
- Conditional::Conditional()
- {
- #if jin_thread == jin_thread_sdl
- cond = SDL_CreateCond();
- #endif
- }
-
- Conditional::~Conditional()
- {
- #if jin_thread == jin_thread_sdl
- SDL_DestroyCond(cond);
- #endif
- }
-
- void Conditional::signal()
- {
- #if jin_thread == jin_thread_sdl
- SDL_CondSignal(cond);
- #endif
- }
-
- void Conditional::broadcast()
- {
- #if jin_thread == jin_thread_sdl
- SDL_CondBroadcast(cond);
- #endif
- }
-
- bool Conditional::wait(Mutex* mutex, int timeout)
- {
- #if jin_thread == jin_thread_sdl
- if (timeout < 0)
- return !SDL_CondWait(cond, mutex->mutex);
- else
- return (SDL_CondWaitTimeout(cond, mutex->mutex, timeout) == 0);
- #endif
- }
+ Mutex::Mutex()
+ {
+ #if jin_thread == jin_thread_sdl
+ mutex = SDL_CreateMutex();
+ #endif
+ }
+
+ Mutex::~Mutex()
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_DestroyMutex(mutex);
+ #endif
+ }
+
+ void Mutex::lock()
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_LockMutex(mutex);
+ #endif
+ }
+
+ void Mutex::unlock()
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_UnlockMutex(mutex);
+ #endif
+ }
+
+ //////////////////////////////////////////////////////////////////////
+
+ Conditional::Conditional()
+ {
+ #if jin_thread == jin_thread_sdl
+ cond = SDL_CreateCond();
+ #endif
+ }
+
+ Conditional::~Conditional()
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_DestroyCond(cond);
+ #endif
+ }
+
+ void Conditional::signal()
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_CondSignal(cond);
+ #endif
+ }
+
+ void Conditional::broadcast()
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_CondBroadcast(cond);
+ #endif
+ }
+
+ bool Conditional::wait(Mutex* mutex, int timeout)
+ {
+ #if jin_thread == jin_thread_sdl
+ if (timeout < 0)
+ return !SDL_CondWait(cond, mutex->mutex);
+ else
+ return (SDL_CondWaitTimeout(cond, mutex->mutex, timeout) == 0);
+ #endif
+ }
- //////////////////////////////////////////////////////////////////////
-
- Thread::ThreadData::ThreadData(Mutex* m, Conditional* c)
- : mutex(m)
- , condition(c)
- , share()
- {
- }
-
- Thread::ThreadData::~ThreadData()
- {
- }
-
- void Thread::ThreadData::set(int slot, Variant value)
- {
- Lock l(mutex);
- share[slot] = value;
- }
-
- Thread::Variant Thread::ThreadData::get(int slot)
- {
- Lock l(mutex);
- return share[slot];
- }
-
- bool Thread::ThreadData::exist(int slot)
- {
- Lock l(mutex);
- return share.count(slot) == 1;
- }
-
- void Thread::ThreadData::remove(int slot)
- {
- Lock l(mutex);
- if (exist(slot))
- {
- share.erase(slot);
- }
- }
-
- //////////////////////////////////////////////////////////////////////
-
- Thread::Thread(const std::string tname, ThreadRunner runner)
- : name(tname)
- , running(false)
- , threadRunner(runner)
- {
- mutex = new Mutex();
- condition = new Conditional();
- common = new Thread::ThreadData(mutex, condition);
- }
-
- Thread::~Thread()
- {
- #if jin_thread == jin_thread_sdl
- #endif
- }
-
- const char* Thread::getName()
- {
- Lock l(mutex);
- return name.c_str();
- };
+ //////////////////////////////////////////////////////////////////////
+
+ Thread::ThreadData::ThreadData(Mutex* m, Conditional* c)
+ : mutex(m)
+ , condition(c)
+ , share()
+ {
+ }
+
+ Thread::ThreadData::~ThreadData()
+ {
+ }
+
+ void Thread::ThreadData::set(int slot, Variant value)
+ {
+ Lock l(mutex);
+ share[slot] = value;
+ }
+
+ Thread::Variant Thread::ThreadData::get(int slot)
+ {
+ Lock l(mutex);
+ return share[slot];
+ }
+
+ bool Thread::ThreadData::exist(int slot)
+ {
+ Lock l(mutex);
+ return share.count(slot) == 1;
+ }
+
+ void Thread::ThreadData::remove(int slot)
+ {
+ Lock l(mutex);
+ if (exist(slot))
+ {
+ share.erase(slot);
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////
+
+ Thread::Thread(const std::string tname, ThreadRunner runner)
+ : name(tname)
+ , running(false)
+ , threadRunner(runner)
+ {
+ mutex = new Mutex();
+ condition = new Conditional();
+ common = new Thread::ThreadData(mutex, condition);
+ }
+
+ Thread::~Thread()
+ {
+ #if jin_thread == jin_thread_sdl
+ #endif
+ }
+
+ const char* Thread::getName()
+ {
+ Lock l(mutex);
+ return name.c_str();
+ };
- bool Thread::isRunning()
- {
- Lock l(mutex);
- return running;
- };
-
- bool Thread::start(void* p)
- {
- Lock l(mutex);
- if (running)
- return false;
- if (handle)
- {
- #if jin_thread == jin_thread_sdl
- SDL_WaitThread(handle, nullptr);
- #endif
- }
- #if jin_thread == jin_thread_sdl
- handle = SDL_CreateThread(threadRunner, name.c_str(), p);
- #elif jin_thread == jin_thread_cpp
- handle = new std::thread();
- #endif
- return (running = (handle != nullptr));
- }
-
- void Thread::wait()
- {
- {
- Lock l(mutex);
- if (!handle)
- return;
- }
- #if jin_thread == jin_thread_sdl
- SDL_WaitThread(handle, nullptr);
- #endif
- Lock l(mutex);
- running = false;
- handle = nullptr;
- }
-
- void Thread::lock()
- {
- if (mutex != nullptr)
- mutex->lock();
- }
-
- void Thread::unlock()
- {
- if (mutex != nullptr)
- mutex->unlock();
- }
-
- void Thread::send(int slot, const Variant& value)
- {
- lock();
- common->set(slot, value);
- unlock();
- condition->broadcast();
- }
-
- bool Thread::receive(int slot)
- {
- return common->exist(slot);
- }
-
- Thread::Variant Thread::fetch(int slot)
- {
- Thread::Variant v = common->get(slot);
- return v;
- }
-
- Thread::Variant Thread::demand(int slot)
- {
- /**
- * pthread_mutex_lock(mtx);
- * while(pass == 0)
- * {
- * pthread_mutex_unlock(mtx);
- * pthread_cond_just_wait(cv);
- * pthread_mutex_lock(mtx);
- * }
- * pthread_mutex_unlock(mtx);
- */
- lock();
- while (!common->exist(slot))
- {
- if (common->exist(ThreadData::SLOT_ERROR))
- return 0;
- condition->wait(mutex);
- }
- Thread::Variant v = common->get(slot);
- unlock();
- return v;
- }
-
- void Thread::remove(int slot)
- {
- lock();
- common->remove(slot);
- unlock();
- }
-
- } // namespace Threads
+ bool Thread::isRunning()
+ {
+ Lock l(mutex);
+ return running;
+ };
+
+ bool Thread::start(void* p)
+ {
+ Lock l(mutex);
+ if (running)
+ return false;
+ if (handle)
+ {
+ #if jin_thread == jin_thread_sdl
+ SDL_WaitThread(handle, nullptr);
+ #endif
+ }
+ #if jin_thread == jin_thread_sdl
+ handle = SDL_CreateThread(threadRunner, name.c_str(), p);
+ #elif jin_thread == jin_thread_cpp
+ handle = new std::thread();
+ #endif
+ return (running = (handle != nullptr));
+ }
+
+ void Thread::wait()
+ {
+ {
+ Lock l(mutex);
+ if (!handle)
+ return;
+ }
+ #if jin_thread == jin_thread_sdl
+ SDL_WaitThread(handle, nullptr);
+ #endif
+ Lock l(mutex);
+ running = false;
+ handle = nullptr;
+ }
+
+ void Thread::lock()
+ {
+ if (mutex != nullptr)
+ mutex->lock();
+ }
+
+ void Thread::unlock()
+ {
+ if (mutex != nullptr)
+ mutex->unlock();
+ }
+
+ void Thread::send(int slot, const Variant& value)
+ {
+ lock();
+ common->set(slot, value);
+ unlock();
+ condition->broadcast();
+ }
+
+ bool Thread::receive(int slot)
+ {
+ return common->exist(slot);
+ }
+
+ Thread::Variant Thread::fetch(int slot)
+ {
+ Thread::Variant v = common->get(slot);
+ return v;
+ }
+
+ Thread::Variant Thread::demand(int slot)
+ {
+ /**
+ * pthread_mutex_lock(mtx);
+ * while(pass == 0)
+ * {
+ * pthread_mutex_unlock(mtx);
+ * pthread_cond_just_wait(cv);
+ * pthread_mutex_lock(mtx);
+ * }
+ * pthread_mutex_unlock(mtx);
+ */
+ lock();
+ while (!common->exist(slot))
+ {
+ if (common->exist(ThreadData::SLOT_ERROR))
+ return 0;
+ condition->wait(mutex);
+ }
+ Thread::Variant v = common->get(slot);
+ unlock();
+ return v;
+ }
+
+ void Thread::remove(int slot)
+ {
+ lock();
+ common->remove(slot);
+ unlock();
+ }
+
+ } // namespace Threads
} // namespace JinEngine
#endif // defined(jin_thread) \ No newline at end of file
diff --git a/src/libjin/threads/je_thread.h b/src/libjin/threads/je_thread.h
index 77f147d..ab13215 100644
--- a/src/libjin/threads/je_thread.h
+++ b/src/libjin/threads/je_thread.h
@@ -15,151 +15,151 @@
namespace JinEngine
{
- namespace Threads
- {
- /**
- * ӢӢMutual exclusionд Mutexһڶ̱߳Уֹ߳ͬʱͬһԴ
- * ȫֱждĻơĿͨƬһһٽcritical sectionɡٽ
- * ָһԹԴзʵĴ룬һֻƻ㷨һ򡢽̡߳̿ӵжٽ򣬵Dz
- * һӦûҪ˻ƵԴУꡢСжϴڶеĴ
- * ݡͬ״̬ȵԴάЩԴͬһºǺѵģΪһ߳̿κһʱ̱ͣ
- * ߣ߻ָѣ
- */
- class Mutex;
- class Conditional;
+ namespace Threads
+ {
+ /**
+ * ӢӢMutual exclusionд Mutexһڶ̱߳Уֹ߳ͬʱͬһԴ
+ * ȫֱждĻơĿͨƬһһٽcritical sectionɡٽ
+ * ָһԹԴзʵĴ룬һֻƻ㷨һ򡢽̡߳̿ӵжٽ򣬵Dz
+ * һӦûҪ˻ƵԴУꡢСжϴڶеĴ
+ * ݡͬ״̬ȵԴάЩԴͬһºǺѵģΪһ߳̿κһʱ̱ͣ
+ * ߣ߻ָѣ
+ */
+ class Mutex;
+ class Conditional;
- //
- // Thread::demand Receive a message from a thread. Wait for the message to exist before returning.
- // Thread::getName Get the name of a thread.
- // Thread::kill Forcefully terminate the thread.
- // Thread::peek Receive a message from a thread, but leave it in the message box.
- // Thread::receive Receive a message from a thread.
- // Thread::send Send a message.
- // Thread::set Set a value.
- // Thread::start Starts the thread.
- // Thread::wait Wait for a thread to finish.
- //
- class Thread
- {
- public:
- struct Variant
- {
- enum Type
- {
- NONE = 0,
- INTERGER,
- BOOLEAN,
- CHARACTER,
- CSTRING,
- POINTER,
- REAL,
- };
- Type type;
- union
- {
- int integer;
- bool boolean;
- char character;
- const char* cstring;
- void* pointer;
- float real;
- };
- Variant() :type(NONE) {};
- Variant(const Variant& v){ memcpy(this, &v, sizeof(v)); }
- Variant(int i) : integer(i), type(INTERGER) {};
- Variant(float f) : real(f), type(REAL) {};
- Variant(bool b) : boolean(b), type(BOOLEAN) {};
- Variant(char c) : character(c), type(CHARACTER) {};
- Variant(const char* s) : cstring(s), type(CSTRING) {};
- Variant(void* p) : pointer(p), type(POINTER) {};
- };
+ //
+ // Thread::demand Receive a message from a thread. Wait for the message to exist before returning.
+ // Thread::getName Get the name of a thread.
+ // Thread::kill Forcefully terminate the thread.
+ // Thread::peek Receive a message from a thread, but leave it in the message box.
+ // Thread::receive Receive a message from a thread.
+ // Thread::send Send a message.
+ // Thread::set Set a value.
+ // Thread::start Starts the thread.
+ // Thread::wait Wait for a thread to finish.
+ //
+ class Thread
+ {
+ public:
+ struct Variant
+ {
+ enum Type
+ {
+ NONE = 0,
+ INTERGER,
+ BOOLEAN,
+ CHARACTER,
+ CSTRING,
+ POINTER,
+ REAL,
+ };
+ Type type;
+ union
+ {
+ int integer;
+ bool boolean;
+ char character;
+ const char* cstring;
+ void* pointer;
+ float real;
+ };
+ Variant() :type(NONE) {};
+ Variant(const Variant& v){ memcpy(this, &v, sizeof(v)); }
+ Variant(int i) : integer(i), type(INTERGER) {};
+ Variant(float f) : real(f), type(REAL) {};
+ Variant(bool b) : boolean(b), type(BOOLEAN) {};
+ Variant(char c) : character(c), type(CHARACTER) {};
+ Variant(const char* s) : cstring(s), type(CSTRING) {};
+ Variant(void* p) : pointer(p), type(POINTER) {};
+ };
- private:
- 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;
+ private:
+ 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);
+ 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;
+ Conditional* condition;
+ Mutex* mutex;
- private:
- std::map<int, Variant> share; // threads shared value
+ private:
+ std::map<int, Variant> share; // threads shared value
- };
+ };
- public:
- typedef int(*ThreadRunner)(void* obj);
+ public:
+ typedef int(*ThreadRunner)(void* obj);
- Thread(const std::string name, ThreadRunner threadfuncs);
- ~Thread();
- bool start(void* p);
- void wait();
- void send(int slot, const Variant& value);
- bool receive(int slot);
- Variant fetch(int slot);
- Variant demand(int slot);
- void remove(int slot);
- const char* getName();
- bool isRunning();
- void lock();
- void unlock();
+ Thread(const std::string name, ThreadRunner threadfuncs);
+ ~Thread();
+ bool start(void* p);
+ void wait();
+ void send(int slot, const Variant& value);
+ bool receive(int slot);
+ Variant fetch(int slot);
+ Variant demand(int slot);
+ void remove(int slot);
+ const char* getName();
+ bool isRunning();
+ void lock();
+ void unlock();
- protected:
- #if jin_thread == jin_thread_sdl
- SDL_Thread* handle; // SDL thread
- #elif jin_thread == jin_thread_cpp
- std::thread* handle; // cpp thread
- #endif
- Mutex* mutex; // mutex variable
- Conditional* condition; // condition variable
- ThreadRunner threadRunner; // thread function
- ThreadData* common; // threads common data
- const std::string name; // thread name, for debugging purposes
- /**
- * https://stackoverflow.com/questions/149932/naming-conventions-for-threads
- *
- * Use short names because they don't make the lines in a log file too long.
- *
- * Create names where the important part is at the beginning. Log viewers in a
- * graphical user interface tend to have tables with columns, and the thread
- * column is usually small or will be made small by you to read everything else.
- *
- * Do not use the word "thread" in the thread name because it is obvious.
- *
- * Make the thread names easily grep-able. Avoid similar sounding thread names
- *
- * If you have several threads of the same nature, enumerate them with IDs that
- * are unique to one execution of the application or one log file, whichever fits
- * your logging habits.
- *
- * Avoid generalizations like "WorkerThread" (how do you name the next 5 worker
- * threads?), "GUIThread" (which GUI? is it for one window? for everything?) or
- * "Calculation" (what does it calculate?).
- *
- * If you have a test group that uses thread names to grep your application's log
- * files, do not rename your threads after some time. Your testers will hate you for
- * doing so. Thread names in well-tested applications should be there to stay.
- *
- * When you have threads that service a network connection, try to include the target
- * network address in the thread name (e.g. channel_123.212.123.3). Don't forget about
- * enumeration though if there are multiple connections to the same host.
- */
- bool running; // running
+ protected:
+ #if jin_thread == jin_thread_sdl
+ SDL_Thread* handle; // SDL thread
+ #elif jin_thread == jin_thread_cpp
+ std::thread* handle; // cpp thread
+ #endif
+ Mutex* mutex; // mutex variable
+ Conditional* condition; // condition variable
+ ThreadRunner threadRunner; // thread function
+ ThreadData* common; // threads common data
+ const std::string name; // thread name, for debugging purposes
+ /**
+ * https://stackoverflow.com/questions/149932/naming-conventions-for-threads
+ *
+ * Use short names because they don't make the lines in a log file too long.
+ *
+ * Create names where the important part is at the beginning. Log viewers in a
+ * graphical user interface tend to have tables with columns, and the thread
+ * column is usually small or will be made small by you to read everything else.
+ *
+ * Do not use the word "thread" in the thread name because it is obvious.
+ *
+ * Make the thread names easily grep-able. Avoid similar sounding thread names
+ *
+ * If you have several threads of the same nature, enumerate them with IDs that
+ * are unique to one execution of the application or one log file, whichever fits
+ * your logging habits.
+ *
+ * Avoid generalizations like "WorkerThread" (how do you name the next 5 worker
+ * threads?), "GUIThread" (which GUI? is it for one window? for everything?) or
+ * "Calculation" (what does it calculate?).
+ *
+ * If you have a test group that uses thread names to grep your application's log
+ * files, do not rename your threads after some time. Your testers will hate you for
+ * doing so. Thread names in well-tested applications should be there to stay.
+ *
+ * When you have threads that service a network connection, try to include the target
+ * network address in the thread name (e.g. channel_123.212.123.3). Don't forget about
+ * enumeration though if there are multiple connections to the same host.
+ */
+ bool running; // running
- };
+ };
- } // namespace Threads
+ } // namespace Threads
} // namespace JinEngine
#endif // defined(jin_thread)
diff --git a/src/libjin/time/je_timer.cpp b/src/libjin/time/je_timer.cpp
index 8dc5e86..5de3e26 100644
--- a/src/libjin/time/je_timer.cpp
+++ b/src/libjin/time/je_timer.cpp
@@ -5,26 +5,26 @@
namespace JinEngine
{
- namespace Time
- {
+ namespace Time
+ {
- Timer::Timer()
- : mHandlers()
- {
- }
+ Timer::Timer()
+ : mHandlers()
+ {
+ }
- Timer::~Timer()
- {
+ Timer::~Timer()
+ {
for (int i = 0; i < mHandlers.size(); ++i)
delete mHandlers[i];
- }
+ }
- void Timer::update(float dt)
- {
+ void Timer::update(float dt)
+ {
// Process handler.
- std::vector<Handler*>::iterator it = mHandlers.begin();
- for (; it != mHandlers.end(); ++it)
+ std::vector<Handler*>::iterator it = mHandlers.begin();
+ for (; it != mHandlers.end(); ++it)
(*it)->process(dt);
// Erase canceled handler.
for (it = mHandlers.begin(); it != mHandlers.end();)
@@ -38,7 +38,7 @@ namespace JinEngine
else
++it;
}
- }
+ }
void Timer::cancel(Handler* handler)
{
@@ -52,71 +52,71 @@ namespace JinEngine
cancel(h);
}
- Timer::Handler* Timer::every(float dt, TimerCallback callback, void* p, FinishCallback finish)
- {
- Handler* t = new Handler(Handler::EVERY, dt, 0, callback, p, finish);
- mHandlers.push_back(t);
+ Timer::Handler* Timer::every(float dt, TimerCallback callback, void* p, FinishCallback finish)
+ {
+ Handler* t = new Handler(Handler::EVERY, dt, 0, callback, p, finish);
+ mHandlers.push_back(t);
return t;
- }
+ }
- Timer::Handler* Timer::after(float dt, TimerCallback callback, void* p, FinishCallback finish)
- {
- Handler* t = new Handler(Handler::AFTER, dt, 0, callback, p, finish);
- mHandlers.push_back(t);
+ Timer::Handler* Timer::after(float dt, TimerCallback callback, void* p, FinishCallback finish)
+ {
+ Handler* t = new Handler(Handler::AFTER, dt, 0, callback, p, finish);
+ mHandlers.push_back(t);
return t;
- }
+ }
- Timer::Handler* Timer::repeat(float dt, int count, TimerCallback callback, void* p, FinishCallback finish)
- {
- Handler* t = new Handler(Handler::REPEAT, dt, count, callback, p, finish);
- mHandlers.push_back(t);
+ Timer::Handler* Timer::repeat(float dt, int count, TimerCallback callback, void* p, FinishCallback finish)
+ {
+ Handler* t = new Handler(Handler::REPEAT, dt, count, callback, p, finish);
+ mHandlers.push_back(t);
return t;
- }
-
- Timer::Handler::Handler(Type t, float d, int c, TimerCallback f, void* p, FinishCallback finishcallback)
- : type(t)
- , duration(d)
- , count(c)
- , tickdown(d)
- , countdown(c)
- , callback(f)
- , paramters(p)
+ }
+
+ Timer::Handler::Handler(Type t, float d, int c, TimerCallback f, void* p, FinishCallback finishcallback)
+ : type(t)
+ , duration(d)
+ , count(c)
+ , tickdown(d)
+ , countdown(c)
+ , callback(f)
+ , paramters(p)
, canceled(false)
, finishCallback(finishcallback)
- {
- }
+ {
+ }
- Timer::Handler::~Handler()
- {
+ Timer::Handler::~Handler()
+ {
if (finishCallback != nullptr)
finishCallback(paramters);
- }
-
- void Timer::Handler::process(float dt)
- {
- tickdown -= dt;
- if (tickdown <= 0)
- {
- tickdown += duration;
- if (!canceled && callback != nullptr)
- callback(paramters);
- if (type == EVERY)
- {
- }
- else if (type == AFTER)
- {
- canceled = true;
- }
- else if (type == REPEAT)
- {
- --countdown;
+ }
+
+ void Timer::Handler::process(float dt)
+ {
+ tickdown -= dt;
+ if (tickdown <= 0)
+ {
+ tickdown += duration;
+ if (!canceled && callback != nullptr)
+ callback(paramters);
+ if (type == EVERY)
+ {
+ }
+ else if (type == AFTER)
+ {
+ canceled = true;
+ }
+ else if (type == REPEAT)
+ {
+ --countdown;
if (countdown <= 0)
canceled = true;
- }
- }
- }
+ }
+ }
+ }
- } // namespace Time
+ } // namespace Time
} // namespace JinEngine
#endif // defined(jin_time) \ No newline at end of file
diff --git a/src/libjin/time/je_timer.h b/src/libjin/time/je_timer.h
index a918d63..1209827 100644
--- a/src/libjin/time/je_timer.h
+++ b/src/libjin/time/je_timer.h
@@ -12,15 +12,15 @@
namespace JinEngine
{
- namespace Time
- {
+ namespace Time
+ {
///
///
///
- class Timer : public Object
- {
- public:
+ class Timer : public Object
+ {
+ public:
typedef std::function<void(void*)> TimerCallback;
@@ -58,32 +58,32 @@ namespace JinEngine
///
///
///
- Timer();
+ Timer();
///
///
///
- ~Timer();
+ ~Timer();
///
///
///
- void update(float dt);
+ void update(float dt);
///
///
///
- Handler* every(float dt, TimerCallback callback, void* paramters = nullptr, FinishCallback finish = nullptr);
+ Handler* every(float dt, TimerCallback callback, void* paramters = nullptr, FinishCallback finish = nullptr);
///
///
///
- Handler* after(float dt, TimerCallback callback, void* paramters, FinishCallback finish);
+ Handler* after(float dt, TimerCallback callback, void* paramters, FinishCallback finish);
///
///
///
- Handler* repeat(float dt, int count, TimerCallback callback, void* paramters, FinishCallback finish);
+ Handler* repeat(float dt, int count, TimerCallback callback, void* paramters, FinishCallback finish);
///
///
@@ -95,43 +95,43 @@ namespace JinEngine
///
void cancelAll();
- private:
+ private:
- std::vector<Handler*> mHandlers;
+ std::vector<Handler*> mHandlers;
- };
+ };
///
///
///
- inline void sleep(int ms)
- {
- #if jin_time == jin_time_sdl
- SDL_Delay(ms);
- #endif
- }
+ inline void sleep(int ms)
+ {
+ #if jin_time == jin_time_sdl
+ SDL_Delay(ms);
+ #endif
+ }
///
///
///
- inline double getSecond()
- {
- #if jin_time == jin_time_sdl
- return SDL_GetTicks() / 1000.f;
- #endif
- }
+ inline double getSecond()
+ {
+ #if jin_time == jin_time_sdl
+ return SDL_GetTicks() / 1000.f;
+ #endif
+ }
///
///
///
- inline double getMilliSecond()
- {
- #if jin_time == jin_time_sdl
- return SDL_GetTicks();
- #endif
- }
-
- } // namespace Time
+ inline double getMilliSecond()
+ {
+ #if jin_time == jin_time_sdl
+ return SDL_GetTicks();
+ #endif
+ }
+
+ } // namespace Time
} // namespace JinEngine
#endif // defined(jin_time)
diff --git a/src/lua/embed/scripts/boot.lua.h b/src/lua/embed/scripts/boot.lua.h
index a42f7d4..4b97b69 100644
--- a/src/lua/embed/scripts/boot.lua.h
+++ b/src/lua/embed/scripts/boot.lua.h
@@ -18,7 +18,7 @@ jin.config.vsync = jin.config.vsync or true
jin.config.title = jin.config.title or ("jin v" .. jin.version)
jin.config.resizable = jin.config.resizable or false
jin.config.fullscreen = jin.config.fullscreen or false
-jin.config.fps = jin.config.fps or 60
+jin.config.fps = jin.config.fps or 60
jin.config.icon = jin.config.icon or ""
-------------------------------------------------------------------------
@@ -49,9 +49,9 @@ function jin.core.run()
end
step()
dt = jin.time.getDelta()
- call(jin.core.onUpdate, dt)
- jin.graphics.clear()
- call(jin.core.onDraw)
+ call(jin.core.onUpdate, dt)
+ jin.graphics.clear()
+ call(jin.core.onDraw)
jin.graphics.present()
jin.time.sleep(0.001)
end
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
index 7bfc206..f5ef31f 100644
--- a/src/lua/modules/audio/je_lua_audio.cpp
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -12,8 +12,8 @@ namespace JinEngine
namespace Lua
{
- typedef SDLAudio Audio;
- typedef SDLSource Source;
+ typedef SDLAudio Audio;
+ typedef SDLSource Source;
struct
{
@@ -28,7 +28,7 @@ namespace JinEngine
luax_pushboolean(L, true);
return 1;
}
- Audio::Setting setting;
+ Audio::Setting setting;
setting.samplerate = 44100;
setting.samples = 44100;
Audio* audio = Audio::get();
diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp
index 7bb28d9..8c9e247 100644
--- a/src/lua/modules/audio/je_lua_source.cpp
+++ b/src/lua/modules/audio/je_lua_source.cpp
@@ -48,14 +48,14 @@ namespace JinEngine
LUA_IMPLEMENT int l_resume(lua_State* L)
{
- Source* source = checkSource(L);
- source->resume();
+ Source* source = checkSource(L);
+ source->resume();
return 0;
}
LUA_IMPLEMENT int l_isStop(lua_State* L)
{
- Source* source = checkSource(L);
+ Source* source = checkSource(L);
bool isStop = source->isStopped();
luax_pushboolean(L, isStop);
return 1;
@@ -63,7 +63,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_isPaused(lua_State* L)
{
- Source* source = checkSource(L);
+ Source* source = checkSource(L);
bool isPaused = source->isPaused();
luax_pushboolean(L, isPaused);
return 1;
@@ -71,17 +71,17 @@ namespace JinEngine
LUA_IMPLEMENT int l_setVolume(lua_State* L)
{
- Source* source = checkSource(L);
+ Source* source = checkSource(L);
float volume = luax_checknumber(L, 2);
- source->setVolume(volume);
+ source->setVolume(volume);
return 0;
}
LUA_IMPLEMENT int l_setLoop(lua_State* L)
{
- Source* source = checkSource(L);
+ Source* source = checkSource(L);
bool loop = luax_checkbool(L, 2);
- source->setLoop(loop);
+ source->setLoop(loop);
return 0;
}
diff --git a/src/lua/modules/bit/je_lua_bit.cpp b/src/lua/modules/bit/je_lua_bit.cpp
index 6d5a8fd..9484743 100644
--- a/src/lua/modules/bit/je_lua_bit.cpp
+++ b/src/lua/modules/bit/je_lua_bit.cpp
@@ -63,7 +63,6 @@ namespace JinEngine
luax_pushboolean(L, (a & b) == b);
return 1;
}
-
LUA_EXPORT int luaopen_bit(lua_State* L)
{
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
index 0e884f8..97b3c96 100644
--- a/src/lua/modules/graphics/je_lua_canvas.cpp
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -15,26 +15,26 @@ namespace JinEngine
LUA_IMPLEMENT inline Canvas* checkCanvas(lua_State* L)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
- return luaObj->getObject<Canvas>();
- }
+ return luaObj->getObject<Canvas>();
+ }
LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
- Canvas* canvas = checkCanvas(L);
+ Canvas* canvas = checkCanvas(L);
luax_pushnumber(L, canvas->getWidth());
return 1;
}
LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
- Canvas* canvas = checkCanvas(L);
+ Canvas* canvas = checkCanvas(L);
luax_pushnumber(L, canvas->getHeight());
return 1;
}
LUA_IMPLEMENT int l_getSize(lua_State* L)
{
- Canvas* canvas = checkCanvas(L);
+ Canvas* canvas = checkCanvas(L);
luax_pushnumber(L, canvas->getWidth());
luax_pushnumber(L, canvas->getHeight());
return 2;
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 2eeb1d6..fba77d7 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -41,7 +41,7 @@ namespace JinEngine
static struct
{
Color curRenderColor;
- Color curClearColor;
+ Color curClearColor;
Font* defaultFont = nullptr;
bool initialized = false;
} context;
@@ -283,25 +283,25 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT int l_setClearColor(lua_State* L)
- {
- if (luax_gettop(L) == 0)
- {
- glClearColor(0, 0, 0, 1);
- return 0;
- }
+ LUA_IMPLEMENT int l_setClearColor(lua_State* L)
+ {
+ if (luax_gettop(L) == 0)
+ {
+ glClearColor(0, 0, 0, 1);
+ return 0;
+ }
- context.curClearColor.r = luax_checknumber(L, 1);
- context.curClearColor.g = luax_checknumber(L, 2);
- context.curClearColor.b = luax_checknumber(L, 3);
- context.curClearColor.a = luax_checknumber(L, 4);
+ context.curClearColor.r = luax_checknumber(L, 1);
+ context.curClearColor.g = luax_checknumber(L, 2);
+ context.curClearColor.b = luax_checknumber(L, 3);
+ context.curClearColor.a = luax_checknumber(L, 4);
gl.setClearColor(context.curClearColor.r,
- context.curClearColor.g,
- context.curClearColor.b,
- context.curClearColor.a);
- return 0;
- }
+ context.curClearColor.g,
+ context.curClearColor.b,
+ context.curClearColor.a);
+ return 0;
+ }
LUA_IMPLEMENT int l_present(lua_State* L)
{
@@ -309,80 +309,80 @@ namespace JinEngine
return 0;
}
- LUA_IMPLEMENT void l_draw_texture(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Texture))
- return;
- int x = luax_optnumber(L, 2, 0);
- int y = luax_optnumber(L, 3, 0);
- float sx = luax_optnumber(L, 4, 1);
- float sy = luax_optnumber(L, 5, 1);
- float r = luax_optnumber(L, 6, 0);
+ LUA_IMPLEMENT void l_draw_texture(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Texture))
+ return;
+ int x = luax_optnumber(L, 2, 0);
+ int y = luax_optnumber(L, 3, 0);
+ float sx = luax_optnumber(L, 4, 1);
+ float sy = luax_optnumber(L, 5, 1);
+ float r = luax_optnumber(L, 6, 0);
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
- LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
- Texture* tex = luaObj->getObject<Texture>();
- tex->render(x, y, sx, sy, r, ox, oy);
- }
-
- LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Canvas))
- return;
- int x = luax_optnumber(L, 2, 0);
- int y = luax_optnumber(L, 3, 0);
- float sx = luax_optnumber(L, 4, 1);
- float sy = luax_optnumber(L, 5, 1);
- float r = luax_optnumber(L, 6, 0);
+ LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
+ Texture* tex = luaObj->getObject<Texture>();
+ tex->render(x, y, sx, sy, r, ox, oy);
+ }
+
+ LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Canvas))
+ return;
+ int x = luax_optnumber(L, 2, 0);
+ int y = luax_optnumber(L, 3, 0);
+ float sx = luax_optnumber(L, 4, 1);
+ float sy = luax_optnumber(L, 5, 1);
+ float r = luax_optnumber(L, 6, 0);
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
- LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
- Canvas* canvas = luaObj->getObject<Canvas>();
+ LuaObject* luaObj = (LuaObject*)luax_toudata(L, 1);
+ Canvas* canvas = luaObj->getObject<Canvas>();
canvas->render(x, y, sx, sy, r, ox, oy);
- }
-
- /* jin.graphics.draw(text, font, x, y) */
- LUA_IMPLEMENT void l_draw_text(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Text))
- return;
- LuaObject* p = (LuaObject*)luax_toudata(L, 1);
- Text* text = p->getObject<Text>();
- int x = luax_optnumber(L, 3, 0);
- int y = luax_optnumber(L, 4, 0);
- int spacing = luax_optnumber(L, 6, 0);
+ }
+
+ /* jin.graphics.draw(text, font, x, y) */
+ LUA_IMPLEMENT void l_draw_text(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Text))
+ return;
+ LuaObject* p = (LuaObject*)luax_toudata(L, 1);
+ Text* text = p->getObject<Text>();
+ int x = luax_optnumber(L, 3, 0);
+ int y = luax_optnumber(L, 4, 0);
+ int spacing = luax_optnumber(L, 6, 0);
Font* font = nullptr;
LuaObject* p2 = (LuaObject*)luax_toudata(L, 2);
- if (luax_istype(L, 2, Jin_Lua_TextureFont))
- {
- TextureFont* tf = p2->getObject<TextureFont>();
+ if (luax_istype(L, 2, Jin_Lua_TextureFont))
+ {
+ TextureFont* tf = p2->getObject<TextureFont>();
font = tf;
- }
- else if (luax_istype(L, 2, Jin_Lua_TTF))
- {
- TTF* ttf = p2->getObject<TTF>();
+ }
+ else if (luax_istype(L, 2, Jin_Lua_TTF))
+ {
+ TTF* ttf = p2->getObject<TTF>();
font = ttf;
- }
+ }
else
{
font = context.defaultFont;
}
int lineheight = luax_optnumber(L, 5, font->getFontSize());
font->render(*text, x, y, lineheight, spacing);
- }
-
- /* jin.graphics.draw(page, x, y) */
- LUA_IMPLEMENT void l_draw_page(lua_State* L)
- {
- if (!luax_istype(L, 1, Jin_Lua_Page))
- return;
- int x = luax_optnumber(L, 2, 0);
- int y = luax_optnumber(L, 3, 0);
- LuaObject* p = (LuaObject*)luax_toudata(L, 1);
- Page* page = p->getObject<Page>();
- Font* font = page->font;
- font->render(page, x, y);
- }
+ }
+
+ /* jin.graphics.draw(page, x, y) */
+ LUA_IMPLEMENT void l_draw_page(lua_State* L)
+ {
+ if (!luax_istype(L, 1, Jin_Lua_Page))
+ return;
+ int x = luax_optnumber(L, 2, 0);
+ int y = luax_optnumber(L, 3, 0);
+ LuaObject* p = (LuaObject*)luax_toudata(L, 1);
+ Page* page = p->getObject<Page>();
+ Font* font = page->font;
+ font->render(page, x, y);
+ }
LUA_IMPLEMENT void l_draw_sprite(lua_State* L)
{
@@ -513,7 +513,7 @@ namespace JinEngine
return 0;
}
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Canvas);
- Canvas* canvas = luaObj->getObject<Canvas>();
+ Canvas* canvas = luaObj->getObject<Canvas>();
gl.bindCanvas(canvas);
return 0;
}
@@ -688,28 +688,28 @@ namespace JinEngine
return 1;
}
- /* newText(str[, encode]) */
- LUA_IMPLEMENT int l_newText(lua_State* L)
- {
- Encode encode = Encode::UTF8;
- if (luax_gettop(L) == 2)
- {
- const char* e = luax_checkstring(L, 2);
- if (strcmp(e, "UTF8") == 0) encode = Encode::UTF8;
- //else if (strcmp(e, "UTF16") == 0) encode = Encode::UTF16;
- else if (strcmp(e, "ASCII") == 0) encode = Encode::ASCII;
- else
- {
- luax_error(L, "wrong text encode %s", e);
- return 0;
- }
- }
- unsigned length;
- const char* data = luax_checklstring(L, 1, &length);
- Text* text = new Text(encode, data, length);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Text, new Shared(text));
- return 1;
- }
+ /* newText(str[, encode]) */
+ LUA_IMPLEMENT int l_newText(lua_State* L)
+ {
+ Encode encode = Encode::UTF8;
+ if (luax_gettop(L) == 2)
+ {
+ const char* e = luax_checkstring(L, 2);
+ if (strcmp(e, "UTF8") == 0) encode = Encode::UTF8;
+ //else if (strcmp(e, "UTF16") == 0) encode = Encode::UTF16;
+ else if (strcmp(e, "ASCII") == 0) encode = Encode::ASCII;
+ else
+ {
+ luax_error(L, "wrong text encode %s", e);
+ return 0;
+ }
+ }
+ unsigned length;
+ const char* data = luax_checklstring(L, 1, &length);
+ Text* text = new Text(encode, data, length);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Text, new Shared(text));
+ return 1;
+ }
// newSprite(Texture tex, Quad quad, Origin origin)
// newSprite(Texture tex, Quad quad, Number ox, Number oy)
@@ -843,11 +843,11 @@ namespace JinEngine
return 1;
}
- /* newTextureFont(bitmap, text, color | cellw, cellh) */
+ /* newTextureFont(bitmap, text, color | cellw, cellh) */
LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
- Bitmap* bitmap = p->getObject<Bitmap>();
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ Bitmap* bitmap = p->getObject<Bitmap>();
Text* text;
if (luax_istype(L, 2, Jin_Lua_Text))
{
@@ -865,21 +865,21 @@ namespace JinEngine
luax_typerror(L, 2, "Text or string");
return 1;
}
- float cellh = luax_checknumber(L, 4);
- TextureFont* textureFont = nullptr;
- if (luax_istable(L, 3))
- {
- unsigned int r = luax_rawgetnumber(L, 3, 1);
- unsigned int g = luax_rawgetnumber(L, 3, 2);
- unsigned int b = luax_rawgetnumber(L, 3, 3);
- unsigned int a = luax_rawgetnumber(L, 3, 4);
- textureFont = new TextureFont(bitmap, *text, Color(r, g, b, a), cellh);
- }
- else if (luax_isnumber(L, 3))
- {
- float cellw = luax_checknumber(L, 3);
- textureFont = new TextureFont(bitmap, *text, cellw, cellh);
- }
+ float cellh = luax_checknumber(L, 4);
+ TextureFont* textureFont = nullptr;
+ if (luax_istable(L, 3))
+ {
+ unsigned int r = luax_rawgetnumber(L, 3, 1);
+ unsigned int g = luax_rawgetnumber(L, 3, 2);
+ unsigned int b = luax_rawgetnumber(L, 3, 3);
+ unsigned int a = luax_rawgetnumber(L, 3, 4);
+ textureFont = new TextureFont(bitmap, *text, Color(r, g, b, a), cellh);
+ }
+ else if (luax_isnumber(L, 3))
+ {
+ float cellw = luax_checknumber(L, 3);
+ textureFont = new TextureFont(bitmap, *text, cellw, cellh);
+ }
else
{
luax_error(L, "bad arguments #3 to 'newTextureFont', need to be table or number");
@@ -890,9 +890,9 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_TextureFont, new Shared(textureFont));
- return 1;
- }
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_TextureFont, new Shared(textureFont));
+ return 1;
+ }
LUA_IMPLEMENT int l_newParticleSystem(lua_State* L)
{
@@ -901,8 +901,8 @@ namespace JinEngine
}
/* setFont(font) */
- LUA_IMPLEMENT int l_setFont(lua_State* L)
- {
+ LUA_IMPLEMENT int l_setFont(lua_State* L)
+ {
if (luax_istype(L, 1, Jin_Lua_TTF))
{
LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
@@ -915,8 +915,8 @@ namespace JinEngine
TextureFont* tf = p->getObject<TextureFont>();
gl.setFont(tf);
}
- return 0;
- }
+ return 0;
+ }
LUA_IMPLEMENT int l_unsetFont(lua_State* L)
{
@@ -971,9 +971,9 @@ namespace JinEngine
luaopen_Texture(L);
luaopen_Canvas(L);
luaopen_TTFData(L);
- luaopen_TTF(L);
- luaopen_Text(L);
- luaopen_TextureFont(L);
+ luaopen_TTF(L);
+ luaopen_Text(L);
+ luaopen_TextureFont(L);
luaopen_Page(L);
luaopen_Shader(L);
luaopen_Sprite(L);
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
index 6407256..5a312e2 100644
--- a/src/lua/modules/graphics/je_lua_page.cpp
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -24,7 +24,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_gc(lua_State* L)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Page);
- luaObj->release();
+ luaObj->release();
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp
index eb23879..0afbceb 100644
--- a/src/lua/modules/graphics/je_lua_text.cpp
+++ b/src/lua/modules/graphics/je_lua_text.cpp
@@ -11,21 +11,21 @@ namespace JinEngine
const char* Jin_Lua_Text = "Text";
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Text);
- p->release();
- return 0;
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* p = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Text);
+ p->release();
+ return 0;
+ }
- LUA_EXPORT void luaopen_Text(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_Text, methods);
- }
+ LUA_EXPORT void luaopen_Text(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Text, methods);
+ }
} // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
index 7bac237..b03b999 100644
--- a/src/lua/modules/graphics/je_lua_texture.cpp
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -15,26 +15,26 @@ namespace JinEngine
LUA_IMPLEMENT inline Texture* checkTexture(lua_State* L)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Texture);
- return luaObj->getObject<Texture>();
+ return luaObj->getObject<Texture>();
}
LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
- Texture* shared = checkTexture(L);
+ Texture* shared = checkTexture(L);
luax_pushnumber(L, shared->getWidth());
return 1;
}
LUA_IMPLEMENT int l_getHeight(lua_State *L)
{
- Texture* shared = checkTexture(L);
+ Texture* shared = checkTexture(L);
luax_pushnumber(L, shared->getHeight());
return 1;
}
LUA_IMPLEMENT int l_getSize(lua_State* L)
{
- Texture* shared = checkTexture(L);
+ Texture* shared = checkTexture(L);
luax_pushnumber(L, shared->getWidth());
luax_pushnumber(L, shared->getHeight());
return 2;
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index 9c9d52c..6cbf7ca 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -15,49 +15,49 @@ namespace JinEngine
const char* Jin_Lua_TextureFont = "TextureFont";
- LUA_IMPLEMENT int l_gc(lua_State* L)
- {
- LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
- luaObj->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- LUA_IMPLEMENT int l_typeset(lua_State* L)
- {
- LuaObject* luaTexFont = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
- TextureFont* tf = luaTexFont->getObject<TextureFont>();
- int lineheight = luax_checkinteger(L, 3);
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = tf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, Jin_Lua_Text))
- {
- LuaObject* p2 = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
- Text* text = p2->getObject<Text>();
- page = tf->typeset(*text, lineheight, spacing);
- }
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ luaObj->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ LuaObject* luaTexFont = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ TextureFont* tf = luaTexFont->getObject<TextureFont>();
+ int lineheight = luax_checkinteger(L, 3);
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = tf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ LuaObject* p2 = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = p2->getObject<Text>();
+ page = tf->typeset(*text, lineheight, spacing);
+ }
Shared* shrPage = new Shared(page);
LuaObject* luaPage = luax_newinstance(L, Jin_Lua_Page, shrPage);
luaPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, luaTexFont);
- return 1;
- }
-
- LUA_EXPORT void luaopen_TextureFont(lua_State* L)
- {
- luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
- luax_newtype(L, Jin_Lua_TextureFont, methods);
- }
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TextureFont(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TextureFont, methods);
+ }
} // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
index caa1e53..ead46de 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -22,28 +22,28 @@ namespace JinEngine
return 0;
}
- /* typeset(Text | string, lineheight, spacing) */
+ /* typeset(Text | string, lineheight, spacing) */
LUA_IMPLEMENT int l_typeset(lua_State* L)
{
LuaObject* luaTTF = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTF);
- TTF* ttf = luaTTF->getObject<TTF>();
+ TTF* ttf = luaTTF->getObject<TTF>();
int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = ttf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, Jin_Lua_Text))
- {
- LuaObject* luaText = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
- Text* text = luaText->getObject<Text>();
- page = ttf->typeset(*text, lineheight, spacing);
- }
- Shared* refPage = new Shared(page);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = ttf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ LuaObject* luaText = (LuaObject*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = luaText->getObject<Text>();
+ page = ttf->typeset(*text, lineheight, spacing);
+ }
+ Shared* refPage = new Shared(page);
LuaObject* luaPage = luax_newinstance(L, Jin_Lua_Page, refPage);
luaPage->setDependency((int)PageDependency::DEP_TTF, luaTTF);
return 1;
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
index 4a95ab2..e251ac8 100644
--- a/src/lua/modules/graphics/je_lua_ttf_data.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -19,9 +19,9 @@ namespace JinEngine
{
LuaObject* luaTTFData = (LuaObject*)luax_checktype(L, 1, Jin_Lua_TTFData);
int fontsize = luax_checkinteger(L, 2);
- TTFData* fontData = luaTTFData->getObject<TTFData>();
- TTF* font = fontData->createTTF(fontsize);
- Shared* shrTTF = new Shared(font);
+ TTFData* fontData = luaTTFData->getObject<TTFData>();
+ TTF* font = fontData->createTTF(fontsize);
+ Shared* shrTTF = new Shared(font);
LuaObject* luaTTF = luax_newinstance(L, Jin_Lua_TTF, shrTTF);
luaTTF->setDependency((int)TTFDependency::DEP_TTFDATA, luaTTFData);
return 1;
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp
index dcfdf01..10e7143 100644
--- a/src/lua/modules/net/je_lua_buffer.cpp
+++ b/src/lua/modules/net/je_lua_buffer.cpp
@@ -15,13 +15,13 @@ namespace JinEngine
static inline Net::Buffer* checkNetBuffer(lua_State* L)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Buffer);
- return luaObj->getObject<Net::Buffer>();
+ return luaObj->getObject<Net::Buffer>();
}
// net.Buffer:append(value) -> value_length
LUA_IMPLEMENT int l_append(lua_State* L)
{
- Buffer* buffer = checkNetBuffer(L);
+ Buffer* buffer = checkNetBuffer(L);
const int vp = 2;
if (luax_isintegerstrict(L, vp))
{
@@ -35,7 +35,7 @@ namespace JinEngine
{
float n = luax_checknumber(L, vp);
int size = sizeof(n);
- buffer->append(&n, size);
+ buffer->append(&n, size);
luax_pushinteger(L, size);
return 1;
}
@@ -43,7 +43,7 @@ namespace JinEngine
{
bool n = luax_checkbool(L, vp);
int size = sizeof(n);
- buffer->append(&n, size);
+ buffer->append(&n, size);
luax_pushinteger(L, size);
return 1;
}
@@ -51,7 +51,7 @@ namespace JinEngine
{
const char* str = luax_checkstring(L, vp);
int size = strlen(str) + 1;
- buffer->append(str, size);
+ buffer->append(str, size);
luax_pushinteger(L, size);
return 1;
}
@@ -65,7 +65,7 @@ namespace JinEngine
// net.Buffer:grabString(offset) -> string, length
LUA_IMPLEMENT int l_grabString(lua_State* L)
{
- Buffer* buffer = checkNetBuffer(L);
+ Buffer* buffer = checkNetBuffer(L);
int offset = luax_checkinteger(L, 2);
unsigned int len;
char* data = buffer->grabString(&len, offset);
@@ -79,7 +79,7 @@ namespace JinEngine
// net.Buffer:grabInteger(offset) -> integer, length
LUA_IMPLEMENT int l_grabInteger(lua_State* L)
{
- Buffer* buffer = checkNetBuffer(L);
+ Buffer* buffer = checkNetBuffer(L);
int offset = luax_checkinteger(L, 2);
int len;
int integer = buffer->grabInteger(&len, offset);
@@ -90,7 +90,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_grabFloat(lua_State* L)
{
- Buffer* buffer = checkNetBuffer(L);
+ Buffer* buffer = checkNetBuffer(L);
int offset = luax_checkinteger(L, 2);
int len;
float floatv = buffer->grabFloat(&len, offset);
@@ -101,7 +101,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
{
- Buffer* buffer = checkNetBuffer(L);
+ Buffer* buffer = checkNetBuffer(L);
int offset = luax_checkinteger(L, 2);
int len;
bool boolean = buffer->grabBoolean(&len, offset);
diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp
index 6ff5221..fad6fc5 100644
--- a/src/lua/modules/net/je_lua_net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -11,7 +11,7 @@ namespace JinEngine
{
using namespace JinEngine::Lua::Net;
- using namespace JinEngine::Net;
+ using namespace JinEngine::Net;
LUA_IMPLEMENT int l_initNetwork(lua_State* L)
{
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
index 1d87175..d6cfe91 100644
--- a/src/lua/modules/net/je_lua_socket.cpp
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -18,19 +18,19 @@ namespace JinEngine
LUA_IMPLEMENT inline Socket* checkSocket(lua_State* L, int pos = 1)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, pos, Jin_Lua_Socket);
- return luaObj->getObject<Socket>();
+ return luaObj->getObject<Socket>();
}
LUA_IMPLEMENT inline Buffer* checkNetBuffer(lua_State* L, int pos = 1)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, pos, Jin_Lua_Buffer);
- return luaObj->getObject<Buffer>();
+ return luaObj->getObject<Buffer>();
}
// return net.Socket
LUA_IMPLEMENT int l_accept(lua_State* L)
{
- Socket* socket = checkSocket(L);
+ Socket* socket = checkSocket(L);
Socket* client = socket->accept();
LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(client));
return 1;
@@ -39,7 +39,7 @@ namespace JinEngine
// return net.Buffer
LUA_IMPLEMENT int l_receive(lua_State* L)
{
- Socket* socket = checkSocket(L);
+ Socket* socket = checkSocket(L);
char buffer[BUFFER_SIZE] = {0};
int size = socket->receive(buffer, BUFFER_SIZE);
Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
@@ -50,7 +50,7 @@ namespace JinEngine
// Socket:receiveFrom(address, port)
LUA_IMPLEMENT int l_receiveFrom(lua_State* L)
{
- Socket* socket = checkSocket(L);
+ Socket* socket = checkSocket(L);
int address = luax_checkinteger(L, 2);
int port = luax_checkinteger(L, 3);
char buffer[BUFFER_SIZE];
@@ -63,8 +63,8 @@ namespace JinEngine
// Socket:send(net.Buffer) -> data_length
LUA_IMPLEMENT int l_send(lua_State* L)
{
- Socket* socket = checkSocket(L);
- Buffer* buffer = checkNetBuffer(L, 2);
+ Socket* socket = checkSocket(L);
+ Buffer* buffer = checkNetBuffer(L, 2);
int len = socket->send(buffer->buffer, buffer->size);
luax_pushinteger(L, len);
return 1;
@@ -73,24 +73,24 @@ namespace JinEngine
// Socket:sendTo(address, port, net.Buffer)
LUA_IMPLEMENT int l_sendTo(lua_State* L)
{
- Socket* socket = checkSocket(L);
+ Socket* socket = checkSocket(L);
int address = luax_checkinteger(L, 2);
int port = luax_checkinteger(L, 3);
- Buffer* buffer = checkNetBuffer(L, 4);
+ Buffer* buffer = checkNetBuffer(L, 4);
socket->sendTo(buffer->buffer, buffer->size, address, port);
return 0;
}
LUA_IMPLEMENT int l_close(lua_State* L)
{
- Socket* socket = checkSocket(L);
+ Socket* socket = checkSocket(L);
socket->close();
return 0;
}
LUA_IMPLEMENT int l_configBlocking(lua_State* L)
{
- Socket* socket = checkSocket(L);
+ Socket* socket = checkSocket(L);
bool blocking = luax_checkbool(L, 2);
socket->configureBlocking(blocking);
return 0;
diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp
index 9e785ff..a9d7f3b 100644
--- a/src/lua/modules/thread/je_lua_thread.cpp
+++ b/src/lua/modules/thread/je_lua_thread.cpp
@@ -17,12 +17,12 @@ namespace JinEngine
static inline Thread* checkThread(lua_State* L)
{
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Thread);
- return luaObj->getObject<Thread>();
+ return luaObj->getObject<Thread>();
}
LUA_IMPLEMENT int threadRunner(void* t)
{
- Shared* shared = (Shared*)t;
+ Shared* shared = (Shared*)t;
Thread* thread = shared->getObject<Thread>();
lua_State* L = lua_open();
luax_openlibs(L);
@@ -44,7 +44,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_start(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
bool result = shared->start(&shared);
luax_pushboolean(L, result);
return 1;
@@ -52,14 +52,14 @@ namespace JinEngine
LUA_IMPLEMENT int l_wait(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
shared->wait();
return 0;
}
LUA_IMPLEMENT int l_send(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
int slot = luax_checkinteger(L, 2);
const int vp = 3;
if (luax_isnumberstrict(L, vp))
@@ -70,29 +70,29 @@ namespace JinEngine
else if (luax_isbooleanstrict(L, vp))
{
bool bol = luax_checkbool(L, vp);
- shared->send(slot, bol);
+ shared->send(slot, bol);
}
else if (luax_isstringstrict(L, vp))
{
const char* str = luax_checkstring(L, vp);
- shared->send(slot, str);
+ shared->send(slot, str);
}
else if (luax_isuserdata(L, vp))
{
LuaObject* luaObj = (LuaObject*)luax_touserdata(L, vp);
- shared->send(slot, luaObj);
+ shared->send(slot, luaObj);
}/*
else if (luax_islightuserdata(L, vp))
{
void* p = luax_tolightuserdata(L, vp);
- shared->send(slot, p);
+ shared->send(slot, p);
}*/
return 0;
}
LUA_IMPLEMENT int l_receive(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
int slot = luax_checkinteger(L, 2);
bool result = shared->receive(slot);
luax_pushboolean(L, result);
@@ -101,7 +101,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_fetch(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
int slot = luax_checkinteger(L, 2);
Thread::Variant v = shared->fetch(slot);
switch (v.type)
@@ -134,7 +134,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_demand(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
int slot = luax_checkinteger(L, 2);
Thread::Variant v = shared->demand(slot);
switch (v.type)
@@ -167,7 +167,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_remove(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
int slot = luax_checkinteger(L, 2);
shared->remove(slot);
return 0;
@@ -175,7 +175,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_getName(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
const char* name = shared->getName();
luax_pushstring(L, name);
return 1;
@@ -183,7 +183,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_isRunning(lua_State* L)
{
- Thread* shared = checkThread(L);
+ Thread* shared = checkThread(L);
bool running = shared->isRunning();
luax_pushboolean(L, running);
return 1;
diff --git a/src/lua/modules/thread/je_lua_thread.h b/src/lua/modules/thread/je_lua_thread.h
index 9978d35..acb4c49 100644
--- a/src/lua/modules/thread/je_lua_thread.h
+++ b/src/lua/modules/thread/je_lua_thread.h
@@ -21,10 +21,10 @@ namespace JinEngine
thread = new JinEngine::Threads::Thread(_name, runner);
}
- ~Thread()
- {
- delete thread;
- }
+ ~Thread()
+ {
+ delete thread;
+ }
bool start(void* p)
{
@@ -84,7 +84,7 @@ namespace JinEngine
const std::string name;
const std::string code;
- private:
+ private:
JinEngine::Threads::Thread* thread;
};