diff options
Diffstat (limited to 'src')
88 files changed, 1888 insertions, 465 deletions
diff --git a/src/libjin/Audio/SDL/je_sdl_audio.h b/src/libjin/Audio/SDL/je_sdl_audio.h index 01da7b3..b13dc10 100644 --- a/src/libjin/Audio/SDL/je_sdl_audio.h +++ b/src/libjin/Audio/SDL/je_sdl_audio.h @@ -18,9 +18,15 @@ namespace JinEngine #define SDLAUDIO_BYTEDEPTH (SDLAUDIO_BITDEPTH >> 3) #define SDLAUDIO_CHANNELS 2 + /// + /// Audio system SDL implementation. + /// class SDLAudio : public AudioManager<SDLAudio> { public: + /// + /// SDL audio setting. + /// struct Setting : SettingBase { public: @@ -28,29 +34,95 @@ namespace JinEngine int samples; // sample<=samplerate }; - /* IAudio interface */ + /// + /// Play all sources whose state is playing. + /// void play() override; + + /// + /// Stop and remove all sources from the queue. + /// void stop() override; + + /// + /// Pause audio. + /// void pause() override; + + /// + /// Resume audio. + /// void resume() override; + + /// + /// Set global audio volume. + /// void setVolume(float volume) override; - /* process functions*/ + + /// + /// Process all commands in the queue. + /// void processCommands(); + + /// + /// Process all sources. + /// + /// @param buffer Source buffer. + /// @param len Source length. + /// void processSources(void* buffer, size_t len); + + /// + /// Process audio buffer. + /// + /// @param buffer Audio stream buffer. + /// @param len Length of stream buffer. + /// void processBuffer(void* buffer, size_t len); + + /// + /// Goon process. + /// + /// @return True if sucessful, otherwise return false. + /// bool goOnProcess(); - /* thread-safe */ + + /// + /// Lock audio device. + /// void lock(); + + /// + /// Unlock audio device. + /// void unlock(); private: singleton(SDLAudio); + + /// + /// SDL audio constructor. + /// SDLAudio() {}; + + /// + /// SDL audio destructor. + /// ~SDLAudio() {}; - /* subsystem interface */ + + /// + /// Initialize audio system. + /// + /// @param setting Audio setting. + /// bool initSystem(const SettingBase* setting) override; + + /// + /// Quit audio system. + /// void quitSystem() override; + // Audio device id. unsigned int audioDevice; }; @@ -59,4 +131,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO -#endif // __JE_AUDIO_SDL_H + +#endif // __JE_AUDIO_SDL_H
\ No newline at end of file diff --git a/src/libjin/Audio/SDL/je_sdl_source.cpp b/src/libjin/Audio/SDL/je_sdl_source.cpp index 210d058..8f4a2dc 100644 --- a/src/libjin/Audio/SDL/je_sdl_source.cpp +++ b/src/libjin/Audio/SDL/je_sdl_source.cpp @@ -233,10 +233,9 @@ namespace JinEngine ActionFloat(SetVolume, clamp(volume, 0.0f, 1.0f)); } - bool SDLSource::setLoop(bool loop) + void SDLSource::setLoop(bool loop) { ActionBool(SetLoop, loop); - return false; } void SDLSource::setRate(float rate) diff --git a/src/libjin/Audio/SDL/je_sdl_source.h b/src/libjin/Audio/SDL/je_sdl_source.h index b32ecce..fe6abc3 100644 --- a/src/libjin/Audio/SDL/je_sdl_source.h +++ b/src/libjin/Audio/SDL/je_sdl_source.h @@ -16,39 +16,154 @@ namespace JinEngine { typedef struct SDLSourceCommand; + class SDLSourceManager; + /// + /// Audio source SDL implementation. + /// class SDLSource : public Source { public: + /// + /// Create source from raw source data file. + /// + /// @param file Audio source file. + /// @return Return source if create successful, otherwise return null. + /// static SDLSource* createSource(const char* file); + + /// + /// Create source from raw source data. + /// + /// @param mem Source data. + /// @param size Source data size. + /// @return Return source if create successful, otherwise return null. + /// static SDLSource* createSource(void* mem, size_t size); + /// + /// Source destructor. + /// ~SDLSource(); - /* ISource interface */ + + /// + /// Play source. + /// void play() override; + + /// + /// Stop source. + /// void stop() override; + + /// + /// Pause source. + /// void pause() override; + + /// + /// Resume source. + /// void resume() override; + + /// + /// Rewind source. + /// void rewind() override; + + /// + /// Return if the source is stopped. + /// + /// @return True if the source is stopped, otherwise return false. + /// bool isStopped() const override; + + /// + /// Return if the source is paused. + /// + /// @return True if the source is paused(, otherwise return false. + /// bool isPaused() const override; + + /// + /// Set pitch. + /// + /// @param pitch Pitch of source. + /// void setPitch(float pitch) override; + + /// + /// Set volume. + /// + /// @param volume Volume of source. + /// void setVolume(float volume) override; - bool setLoop(bool loop) override; + + /// + /// Set source loop. + /// + /// @param loop Looping or not. + /// + void setLoop(bool loop) override; + + /// + /// Set source rate. + /// + /// @param rate Rate of source. + /// void setRate(float rate) override; - /* handle and process anduio clip */ + + /// + /// Handle a specific command. + /// + /// @param manager Audio manager. + /// @param cmd Source commad. + /// inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd); + + /// + /// Process decoded source data. + /// + /// @param buffer Source data. + /// @param size Data size. + /// inline void process(void* buffer, size_t size); protected: + /// + /// Source constructor. + /// SDLSource(); - /* decode raw audio data */ + + /// + /// Decode wav file. + /// + /// @param mem Wav file data. + /// @param size Wav data size. + /// void decode_wav(void* mem, int size); + + /// + /// Decode ogg file. + /// + /// @param mem ogg file data. + /// @param size ogg data size. + /// void decode_ogg(void* mem, int size); - /* check state */ - inline bool is(int state) const { return (status.state & state) == state; } + /// + /// Check source state. + /// + /// @param state State to be checked. + /// @return True if state is given state, otherwise return false. + /// + inline bool is(int state) const + { + return (status.state & state) == state; + } + + // Source data. struct{ const void* data; // Ƶ int length; // dataֽڳ @@ -58,7 +173,7 @@ namespace JinEngine int samples; // sample = size / (bitdepth / 8) unsigned char channels; // channel1(mono)2(stereo) } raw; - /* Procedure controller variable */ + // Procedure controller variable. struct{ int pos; // ǰŵsample int pitch; // pitch @@ -69,22 +184,68 @@ namespace JinEngine }; + /// + /// Source manager. + /// class SDLSourceManager { public: + /// + /// Get manager singleton. + /// + /// @return Singleton of SDL source manager. + /// static SDLSourceManager* get(); - /* Process function */ + /// + /// Process commands. + /// void processCommands(); + + /// + /// Process sources. + /// + /// @param buffer Source data. + /// @param size Size of source data. + /// void processSources(void* buffer, size_t size); - /* control flow */ + + /// + /// Clear source queue. + /// + /// This function will stop all sources. + /// void removeAllSource(); + + /// + /// Remove specific source. + /// + /// @param source SDL audio source. + /// void removeSource(SDLSource* source); + + /// + /// Push specific source into queue. + /// + /// @param source SDL audio source. + /// void pushSource(SDLSource* source); + + /// + /// Get command from queue. + /// + /// @return Command at first place. + /// SDLSourceCommand* getCommand(); + + /// + /// Push command. + /// + /// @param cmd Spcific command. + /// void pushCommand(SDLSourceCommand* cmd); - private : + private: std::queue<SDLSourceCommand*> commands; std::stack<SDLSourceCommand*> commandsPool; std::vector<SDLSource*> sources; // processing sources @@ -94,7 +255,7 @@ namespace JinEngine class SourceException : public std::exception { - const char * what() const throw () + const char* what() const throw () { return "Load Source Exception"; } @@ -104,4 +265,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_AUDIO && LIBJIN_AUDIO_SDLAUDIO -#endif // __JE_SOURCE_SDL_H + +#endif // __JE_SOURCE_SDL_H
\ No newline at end of file diff --git a/src/libjin/Audio/je_audio_manager.h b/src/libjin/Audio/je_audio_manager.h index 86716ef..10df08c 100644 --- a/src/libjin/Audio/je_audio_manager.h +++ b/src/libjin/Audio/je_audio_manager.h @@ -16,10 +16,16 @@ namespace JinEngine class Source; + /// + /// Audio manager. + /// template<class SubAudio> class AudioManager : public Subsystem<SubAudio> { public: + /// + /// Audio state. + /// enum State { PLAY , @@ -27,19 +33,45 @@ namespace JinEngine PAUSE, }; + /// + /// Play all sources whose state is playing. + /// virtual void play() = 0; + + /// + /// Stop and remove all sources from the queue. + /// virtual void stop() = 0; + + /// + /// Pause audio. + /// virtual void pause() = 0; + + /// + /// Resume audio. + /// virtual void resume() = 0; + + /// + /// Set global audio volume. + /// virtual void setVolume(float volume) = 0; protected: singleton(AudioManager); + /// + /// AudioManager constructor. + /// AudioManager() : volume(1) , state(State::PLAY) {}; + + /// + /// AudioManager destructor. + /// virtual ~AudioManager() {}; float volume; @@ -52,4 +84,4 @@ namespace JinEngine #endif // LIBJIN_MODULES_AUDIO -#endif // __JE_AUDIO_H +#endif // __JE_AUDIO_H
\ No newline at end of file diff --git a/src/libjin/Audio/je_source.h b/src/libjin/Audio/je_source.h index 9ef0b46..ac87c07 100644 --- a/src/libjin/Audio/je_source.h +++ b/src/libjin/Audio/je_source.h @@ -10,6 +10,9 @@ namespace JinEngine namespace Audio { + /// + /// Audio source encoding type. + /// enum SourceType { INVALID = 0, @@ -17,25 +20,90 @@ namespace JinEngine OGG, }; + /// + /// Audio source. + /// class Source { public: + /// + /// Source constructor. + /// Source() {}; + + /// + /// Source destructor. + /// virtual ~Source() {}; - /* interface */ - virtual void play() = 0; + + /// + /// Start playing source. + /// + virtual void play() = 0; + + /// + /// Stop playing source. + /// virtual void stop() = 0; + + /// + /// Pause source. + /// virtual void pause() = 0; + + /// + /// Resume source. + /// virtual void resume() = 0; + + /// + /// Rewind source. + /// virtual void rewind() = 0; + + /// + /// Whether the source is playing or not. + /// virtual bool isStopped() const = 0; + + /// + /// Whether the source is paused or not. + /// virtual bool isPaused() const = 0; + + /// + /// Set source pitch. + /// + /// @param pitch Pitch of source. + /// virtual void setPitch(float pitch) = 0; + + /// + /// Set volume of source. + /// + /// @param volume Volume of source. + /// virtual void setVolume(float volume) = 0; - virtual bool setLoop(bool loop) = 0; + + /// + /// Set source loop. + /// + /// @param loop Looping or not. + /// + virtual void setLoop(bool loop) = 0; + + /// + /// Set source rate. + /// + /// @param rate Rate of source. + /// virtual void setRate(float rate) = 0; protected: + + /// + /// Get type of source data. + /// static SourceType getType(const void* mem, int size); }; @@ -44,4 +112,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_AUDIO -#endif // __JE_AUDIO_SOURCE_H + +#endif // __JE_AUDIO_SOURCE_H
\ No newline at end of file diff --git a/src/libjin/Common/je_array.hpp b/src/libjin/Common/je_array.hpp index 473bae8..361f1f0 100644 --- a/src/libjin/Common/je_array.hpp +++ b/src/libjin/Common/je_array.hpp @@ -3,77 +3,114 @@ namespace JinEngine { - /* ԶͷŶڴջϴĶ̬ */ + + /// + /// A array created on heap. + /// template<typename T> class Array { public: - Array() : length(0), data(nullptr) {} + /// + /// Array constructor. + /// + Array() + : length(0) + , data(nullptr) + { + } + /// + /// Array constructor. + /// + /// @param l Length of array. + /// Array(int l) { length = l; data = new T[l]; } + /// + /// Array destructor. + /// ~Array() { delete[] data; length = 0; } + /// + /// Get address of data. + /// + /// @return Address of data. + /// T* operator &() { return data; } + /// + /// Get specific element of array. + /// + /// @return Element of array. + /// T& operator[](int index) { return data[index]; } - /* ڴ */ - void bind(T* d, int len) + /// + /// Bind data with given data. + /// + /// @param data Data pointer. + /// @param length Length of data. + /// + void bind(T* data, int length) { if (data != nullptr) delete data; - data = d; - length = len; + this->data = data; + this->length = length; } - void add(T v) + /// + /// Add an element. + /// + /// @param v Value of element. + /// + void add(T value) { int len = length + 1; T* d = new T[len]; memcpy(d, data, size()); - d[length] = v; + d[length] = value; bind(d, len); } + /// + /// Get size of data in byte. + /// + /// @return Size of data in byte. + /// int size() { return sizeof(T) * length; } + /// + /// Get length of data. + /// + /// @return Count of data. + /// int count() { return length; } private: - /// - /// http://blog.jobbole.com/106923/ - /// new ڴ洴 - /// 1. new ڴ - /// 2. ù캯 - /// - /// new, deleteڷͷڴ棬 - /// + // Disable new and delete. void* operator new(size_t t); - - /// - /// Disable delete. - /// void operator delete(void* ptr); T * data; diff --git a/src/libjin/Common/je_object.cpp b/src/libjin/Common/je_object.cpp deleted file mode 100644 index 69e4a56..0000000 --- a/src/libjin/Common/je_object.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// LOVE -#include "je_object.h" - -namespace JinEngine -{ - - Object::Object() - : count(1) - { - } - - Object::~Object() - { - } - - int Object::getReferenceCount() const - { - return count; - } - - void Object::retain() - { - ++count; - } - - void Object::release() - { - if (--count <= 0) - delete this; - } - -} // love diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h deleted file mode 100644 index ca17586..0000000 --- a/src/libjin/Common/je_object.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __JE_COMMON_OBJECT_H -#define __JE_COMMON_OBJECT_H - -namespace JinEngine -{ - - class Object - { - private: - - // The reference count. - int count; - - public: - - /** - * Constructor. Sets reference count to one. - **/ - Object(); - - /** - * Destructor. - **/ - virtual ~Object() = 0; - - /** - * Gets the reference count of this Object. - * @returns The reference count. - **/ - int getReferenceCount() const; - - /** - * Retains the Object, i.e. increases the - * reference count by one. - **/ - void retain(); - - /** - * Releases one reference to the Object, i.e. decrements the - * reference count by one, and potentially deletes the Object - * if there are no more references. - **/ - void release(); - - }; // Object - -} // namespace JinEngine - -#endif
\ No newline at end of file diff --git a/src/libjin/Common/je_singleton.hpp b/src/libjin/Common/je_singleton.hpp index f37f3af..e981e7a 100644 --- a/src/libjin/Common/je_singleton.hpp +++ b/src/libjin/Common/je_singleton.hpp @@ -4,33 +4,76 @@ namespace JinEngine { + /// + /// Singleton base class. + /// template<class T> class Singleton { public: + /// + /// Get singleton. + /// + /// @param Singleton instance of class. + /// static T* get() { if (_instance == nullptr) _instance = new T; return _instance; } + + /// + /// Destroy instance of singleton. + /// static void destroy() { delete _instance; _instance = nullptr; } + protected: + /// + /// Singleton constructor. + /// Singleton() {}; + + /// + /// Singleton destructor. + /// virtual ~Singleton() {}; + + /// + /// Singleton instance. + /// static T* _instance; + private: - Singleton(const Singleton&); - Singleton& operator = (const Singleton&); + /// + /// Singleton copy constructor. + /// + /// @param singleton Singleton of class. + /// + Singleton(const Singleton& singleton); + + /// + /// Singleton assignment. + /// + /// @param singleton Singleton of class. + /// + Singleton& operator = (const Singleton& singleton); + }; + /// + /// Singleton instance. + /// template<class T> T* Singleton<T>::_instance = nullptr; -#define singleton(T) friend Singleton<T> + /// + /// Singleton notation. + /// + #define singleton(T) friend Singleton<T> } // namespace JinEngine diff --git a/src/libjin/Common/je_subsystem.hpp b/src/libjin/Common/je_subsystem.hpp index 4966a9d..d8e106d 100644 --- a/src/libjin/Common/je_subsystem.hpp +++ b/src/libjin/Common/je_subsystem.hpp @@ -8,22 +8,40 @@ namespace JinEngine { + /// + /// Subsystem class. + /// template<class System> class Subsystem : public Singleton<System> { public: - struct Setting {}; + /// + /// Subsystem setting. + /// + struct Setting + { + }; + typedef Setting SettingBase; + /// + /// Initialize subsystem. + /// + /// @param setting Subsystem setting. + /// @return True if initialize sucessful, otherwise return false. + /// bool init(const SettingBase* setting = nullptr) { static bool success = initSystem(setting); return success; } + /// + /// Quit subsystem. + /// void quit() { - /*call only once*/ + // Call only once. static char __dummy__ = (quitSystem(), 1); Singleton<System>::destroy(); } @@ -31,11 +49,27 @@ namespace JinEngine protected: singleton(System); + /// + /// Subsystem constructor. + /// Subsystem() {}; - virtual ~Subsystem() {}; - /*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0; - /*onlyonce*/ virtual void quitSystem() = 0; + /// + /// Subsystem destructor. + /// + virtual ~Subsystem() + { + }; + + /// + /// Initializer callback. + /// + virtual bool initSystem(const Setting* setting) = 0; + + /// + /// Quit subsystem callback. + /// + virtual void quitSystem() = 0; }; diff --git a/src/libjin/Common/je_types.h b/src/libjin/Common/je_types.h index 7e7ad21..446c413 100644 --- a/src/libjin/Common/je_types.h +++ b/src/libjin/Common/je_types.h @@ -4,20 +4,20 @@ namespace JinEngine { - namespace common - { - typedef int8_t int8; - typedef uint8_t uint8; - typedef uint8 byte; - typedef int16_t int16; - typedef uint16_t uint16; - typedef int32_t int32; - typedef uint32_t uint32; - typedef int64_t int64; - typedef uint64_t uint64; + typedef int8_t int8; ///< Signed integer with a size of 8 bits. Supports values from -128 to 127 + typedef uint8_t uint8; ///< Unsigned integer with a size of 8 bits. Supports values from 0 to 255. + typedef uint8 byte; ///< Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255. + typedef int16_t int16; ///< Signed integer with a size of 16 bits. Supports values from -32768 to 32767 + typedef uint16_t uint16; ///< Unsigned integer with a size of 16 bits. Supports values from 0 to 65535. + typedef int32_t int32; ///< Signed integer with a size of 32 bits. Supports values from -2147483648 to 2147483647. + typedef uint32_t uint32; ///< Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1). + typedef int64_t int64; ///< Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1). + typedef uint64_t uint64; ///< Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1). + + typedef uint32_t uint; + typedef int32_t sint; - } } #endif
\ No newline at end of file diff --git a/src/libjin/Common/je_utf8.cpp b/src/libjin/Common/je_utf8.cpp index b2c1d31..012bf5e 100644 --- a/src/libjin/Common/je_utf8.cpp +++ b/src/libjin/Common/je_utf8.cpp @@ -39,4 +39,4 @@ namespace JinEngine } // namespace JinEngine -#endif // LIBJIN_OS == LIBJIN_WINDOWS +#endif // LIBJIN_OS == LIBJIN_WINDOWS
\ No newline at end of file diff --git a/src/libjin/Common/je_utf8.h b/src/libjin/Common/je_utf8.h index 9fdff10..72a11af 100644 --- a/src/libjin/Common/je_utf8.h +++ b/src/libjin/Common/je_utf8.h @@ -10,22 +10,25 @@ namespace JinEngine { - /** - * Convert the wide string to a UTF-8 encoded string. - * @param wstr The wide-char string. - * @return A UTF-8 string. - **/ + /// + /// Convert the wide string to a UTF-8 encoded string. + /// + /// @param wstr The wide-char string. + /// @return A UTF-8 string. + /// std::string to_utf8(LPCWSTR wstr); - /** - * Replace all occurences of 'find' with 'replace' in a string. - * @param str The string to modify. - * @param find The character to match. - * @param replace The character to replace matches. - **/ + /// + /// Replace all occurences of 'find' with 'replace' in a string. + /// + /// @param str The string to modify. + /// @param find The character to match. + /// @param replace The character to replace matches. + /// void replace_char(std::string & str, char find, char replace); } // namespace JinEngine #endif // LIBJIN_OS == LIBJIN_WINDOWS -#endif // __JE_COMMON_UTF8_H + +#endif // __JE_COMMON_UTF8_H
\ No newline at end of file diff --git a/src/libjin/Filesystem/je_asset_database.cpp b/src/libjin/Filesystem/je_asset_database.cpp index c945d6a..edc3661 100644 --- a/src/libjin/Filesystem/je_asset_database.cpp +++ b/src/libjin/Filesystem/je_asset_database.cpp @@ -9,21 +9,21 @@ namespace JinEngine namespace Filesystem { - AssetDatabase* AssetDatabase::fs = 0; + AssetDatabase* AssetDatabase::mAssetDatabase = 0; AssetDatabase::AssetDatabase() { - S = smtnewshared(); + mSmt = smtnewshared(); } AssetDatabase* AssetDatabase::get() { - return fs ? fs : (fs = new AssetDatabase()); + return mAssetDatabase ? mAssetDatabase : (mAssetDatabase = new AssetDatabase()); } void AssetDatabase::mount(const char * path) { - int err = smtmount(S, path); + int err = smtmount(mSmt, path); if (err) { printf("%s mounted path %s", smterrstr(err), path); @@ -31,37 +31,44 @@ namespace JinEngine } } - int AssetDatabase::read(const char* path, Buffer* buffer) + bool AssetDatabase::read(const char* path, Buffer& buffer) { - buffer->data = smtread(S, path, &buffer->size); - if (buffer->data == 0) - return 0; - return 1; + size_t size; + byte* data = (byte*)smtread(mSmt, path, &size); + if (data == nullptr) + return false; + buffer.bind(data, size); + return true; } + Buffer* read(const char* path) + { + + } + void* AssetDatabase::read(const char* path, unsigned int* len) { - return smtread(S, path, len); + return smtread(mSmt, path, len); } const char* AssetDatabase::getFull(const char* path) { - return smtfullpath(S, path); + return smtfullpath(mSmt, path); } bool AssetDatabase::isDir(const char* path) { - return smtisdir(S, path); + return smtisdir(mSmt, path); } bool AssetDatabase::isFile(const char* path) { - return smtisreg(S, path); + return smtisreg(mSmt, path); } bool AssetDatabase::exists(const char* path) { - return smtexists(S, path) == 0; + return smtexists(mSmt, path) == 0; } } // namespace Filesystem diff --git a/src/libjin/Filesystem/je_asset_database.h b/src/libjin/Filesystem/je_asset_database.h index b8f96f6..81cce64 100644 --- a/src/libjin/Filesystem/je_asset_database.h +++ b/src/libjin/Filesystem/je_asset_database.h @@ -8,25 +8,84 @@ namespace JinEngine { namespace Filesystem { - /* Դ */ - class AssetDatabase + + /// + /// Assets managment. + /// + class AssetDatabase { public: + /// + /// Get asset database singleton. + /// + /// @param Singleton of asset database. + /// static AssetDatabase* get(); + /// + /// Asset database constructor. + /// AssetDatabase(); + /// + /// Check if the path is directory. + /// + /// @param path Path under asset folder. + /// @return True if the given path is directory, otherwise return false. + /// bool isDir(const char* path); + + /// + /// Check if the path is file. + /// + /// @param path Path under asset folder. + /// @return True if the given path is file, otherwise return false. + /// 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); - int read(const char* path, Buffer* buffer); - void* read(const char* path, unsigned int* len); + + /// + /// Read file into a buffer. + /// + /// @param path Path of file. + /// @param buffer Buffer to fill. + /// @return True if read sucessful, otherwise return false. + /// + bool read(const char* path, Buffer& buffer); + + /// + /// Read file and return data content. + /// + /// @param path Path of file. + /// @param length Length of data. + /// @return Data if read sucessful, otherwise return null. + /// + void* read(const char* path, unsigned int* length); + + /// + /// Set asset root folder. + /// + /// @param root Root folder of assets. + /// void mount(const char* root); + + /// + /// Get full path of asset. + /// + /// @param path Path of asset. + /// @return Full path of asset. + /// const char* getFull(const char* path); private: - static AssetDatabase* fs; - smtShared* S; + static AssetDatabase* mAssetDatabase; + smtShared* mSmt; }; diff --git a/src/libjin/Filesystem/je_buffer.h b/src/libjin/Filesystem/je_buffer.h index 11faf79..18a381d 100644 --- a/src/libjin/Filesystem/je_buffer.h +++ b/src/libjin/Filesystem/je_buffer.h @@ -4,61 +4,161 @@ #include <string.h> #include <stdlib.h> +#include "../common/je_types.h" + namespace JinEngine { namespace Filesystem { - /** - * ڶϷָռbuffer - */ + /// + /// Data buffer allocated on heap. + /// class Buffer { public: - Buffer() : data(0), size(0) {} + /// + /// Buffer constructor. + /// + Buffer() + : mData(0) + , mSize(0) + { + } + + /// + /// Copy constructor. + /// + /// @param src Buffer source. + /// Buffer(const Buffer& src) { - delete[] data; - size = src.size; - data = new char[size]; - memcpy(data, src.data, size); + delete[] mData; + mSize = src.mSize; + mData = new byte[mSize]; + memcpy(mData, src.mData, mSize); } - Buffer(void* d, int s) + + /// + /// Buffer constructor. + /// + /// @param data Buffer data. + /// @param size Size of buffer. + /// + Buffer(void* data, int size) { - data = new char[size]; - memcpy(data, d, size); - size = s; + mSize = size; + mData = new byte[mSize]; + memcpy(mData, data, mSize); } - Buffer(size_t s) + + /// + /// Buffer constructor. + /// + /// @param size Size of data. + /// + Buffer(size_t size) { - data = new char[s]; - memset(data, 0, s); - size = s; + mData = new byte[size]; + memset(mData, 0, size); + mSize = size; } + + /// + /// Buffer destructor. + /// ~Buffer() { - delete[] data; - size = 0; + delete[] mData; + mSize = 0; } + + /// + /// Set buffer data. + /// + /// @param data Buffer data. + /// @param size Size of data. + /// + void set(byte* data, size_t size) + { + if (data == nullptr) + return; + if (mSize != size) + { + delete mData; + mData = new byte[size]; + } + mSize = size; + memcpy(mData, data, size); + } + + /// + /// Bind buffer data. + /// + /// @param data Buffer data. + /// @param size Size of buffer. + /// + void bind(byte* data, size_t size) + { + if (mData != nullptr) + delete mData; + mSize = size; + mData = data; + } + + /// + /// Buffer assignment. + /// + /// @param buffer Buffer to copy. + /// void operator = (const Buffer& buffer) { - delete[] data; - size = buffer.size; - data = new char[size]; - memcpy(data, buffer.data, size); + delete[] mData; + mSize = buffer.mSize; + mData = new byte[mSize]; + memcpy(mData, buffer.mData, mSize); } + /// + /// Get data addresss. + /// + /// @return Data address. + /// + const byte* operator &() + { + return mData; + } + + /// + /// Get data size. + /// + /// @return Size of data. + /// + const inline size_t size() + { + return mSize; + } + + /// + /// Clear data. + /// void clear() { - if (data == nullptr) + if (mData == nullptr) return; - free(data); - data = nullptr; + delete mData; + mData = nullptr; + mSize = 0; } - void* data; - unsigned int size; - + private: + byte* mData; + size_t mSize; + + // diasble new and delete + void* operator new(size_t t); + void operator delete(void*); + }; } // namespace Filesystem diff --git a/src/libjin/Game/je_entity.h b/src/libjin/Game/je_entity.h new file mode 100644 index 0000000..29fe8be --- /dev/null +++ b/src/libjin/Game/je_entity.h @@ -0,0 +1,51 @@ +#ifndef __JE_GAME_OBJECT_H +#define __JE_GAME_OBJECT_H + +#include <map> +#include <set> + +#include "../common/je_types.h" + +namespace JinEngine +{ + namespace Game + { + + /// + /// Game object base class. + /// + class Entity + { + public: + virtual ~Entity(); + + void lifecycle(); + + protected: + virtual void onAlive(); + virtual void onUpdate(float dt); + virtual void onDraw(); + virtual void onDie(); + + uint32 layer; // layer where entity belongs + uint32 index; // render index in layer + uint64 tag; // tag of entity + bool mIsVisible; + bool mIsActive; + + }; + + /// + /// Entity list. For quickly adding and removing entities. + /// + typedef std::list<Entity*> EntityList; + + /// + /// Entity set. For searching and keeps entities unique and sorted. + /// + typedef std::set<Entity*> EntitySet; + + } // namespace Game +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/Game/je_game.h b/src/libjin/Game/je_game.h index 8fe4b51..6f7ad6d 100644 --- a/src/libjin/Game/je_game.h +++ b/src/libjin/Game/je_game.h @@ -12,6 +12,9 @@ namespace JinEngine namespace Core { + /// + /// Game class. + /// class Game : public Subsystem<Game> { public: @@ -21,6 +24,9 @@ namespace JinEngine typedef void(*onUpdate)(int dt); typedef void(*onDraw)(); + /// + /// Game setting. + /// struct Setting : SettingBase { onEvent eventHandler; @@ -29,12 +35,31 @@ namespace JinEngine onLoad loader; }; + /// + /// Main game loop. + /// void run(); - inline void stop() { _running = false; }; - inline bool running() { return _running; }; + + /// + /// Stop game. + /// + inline void stop() + { + _running = false; + }; + + /// + /// Return if game is running. + /// + /// @return True if game is running, otherwise return false. + /// + inline bool running() + { + return _running; + }; private: - + Game(); ~Game() {}; @@ -55,4 +80,4 @@ namespace JinEngine } // namespace Core } // namespace JinEngine -#endif // __JE_CORE_GAME_H +#endif // __JE_CORE_GAME_H
\ No newline at end of file diff --git a/src/libjin/Game/je_scene.h b/src/libjin/Game/je_scene.h new file mode 100644 index 0000000..388b047 --- /dev/null +++ b/src/libjin/Game/je_scene.h @@ -0,0 +1,68 @@ +#ifndef __JE_GAME_SCENE_H +#define __JE_GAME_SCENE_H + +#include <map> +#include <list> + +#include "je_entity.h" + +namespace JinEngine +{ + namespace Game + { + + /// + /// Handle all entities. + /// + class Scene + { + public: + /// + /// + /// + void addEntity(Entity* entity); + + /// + /// + /// + EntityList& getEntitiesByTag(uint64 tag); + + /// + /// + /// + EntityList& getEntitiesByLayer(uint32 layer); + + /// + /// + /// + void setEntitiesActiveByTag(uint64 tag); + + /// + /// + /// + void setEntitiesActiveByLayer(uint32 layer); + + /// + /// + /// + void removeEntitiesByLayer(uint32 layer); + + /// + /// + /// + void removeEntitiesByTag(uint64 tag); + + protected: + // all entities + EntitySet entities; + // all entities grouped by layer, render order + std::map<uint32, EntityList> layers; + // all entities grouped by tag + std::map<uint64, EntityList> tags; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/Font/je_decoder.h b/src/libjin/Graphics/Font/je_decoder.h index 162f22e..36cbda7 100644 --- a/src/libjin/Graphics/Font/je_decoder.h +++ b/src/libjin/Graphics/Font/je_decoder.h @@ -16,6 +16,7 @@ namespace JinEngine class Decoder { public: + /// /// Decode a code unit. /// @@ -32,6 +33,7 @@ namespace JinEngine /// @return Next code unit location. /// virtual const void* next(const void* data) const = 0; + }; /// @@ -40,6 +42,7 @@ namespace JinEngine class Utf8 : public Decoder { public: + /// /// Decode a code unit. /// @@ -56,6 +59,7 @@ namespace JinEngine /// @return Next code unit location. /// const void* next(const void* data) const override; + }; /// @@ -64,6 +68,7 @@ namespace JinEngine class Ascii : public Decoder { public: + /// /// Decode a code unit. /// @@ -80,6 +85,7 @@ namespace JinEngine /// @return Next code unit location. /// const void* next(const void* data) const override; + }; } // namespace Graphics diff --git a/src/libjin/Graphics/Font/je_font.h b/src/libjin/Graphics/Font/je_font.h index ec60c21..75dd4c5 100644 --- a/src/libjin/Graphics/Font/je_font.h +++ b/src/libjin/Graphics/Font/je_font.h @@ -89,6 +89,7 @@ namespace JinEngine inline unsigned getFontSize() { return mFontSize; }; protected: + unsigned mFontSize; }; diff --git a/src/libjin/Graphics/Font/je_text.cpp b/src/libjin/Graphics/Font/je_text.cpp index 70a1c36..75dfc7b 100644 --- a/src/libjin/Graphics/Font/je_text.cpp +++ b/src/libjin/Graphics/Font/je_text.cpp @@ -20,8 +20,8 @@ namespace JinEngine { switch (encode) { - case Encode::UTF8: decoder = new Utf8(); break; - case Encode::ASCII: decoder = new Ascii(); break; + case Encode::UTF8: decoder = new Utf8(); break; + case Encode::ASCII: decoder = new Ascii(); break; } } @@ -33,8 +33,8 @@ namespace JinEngine { switch (encode) { - case Encode::UTF8: decoder = new Utf8(); break; - case Encode::ASCII: decoder = new Ascii(); break; + case Encode::UTF8: decoder = new Utf8(); break; + case Encode::ASCII: decoder = new Ascii(); break; } } diff --git a/src/libjin/Graphics/Font/je_text.h b/src/libjin/Graphics/Font/je_text.h index af40993..7436875 100644 --- a/src/libjin/Graphics/Font/je_text.h +++ b/src/libjin/Graphics/Font/je_text.h @@ -31,44 +31,134 @@ namespace JinEngine class Text { public: + /// + /// + /// Text(Encode encode, const void* data); + + /// + /// + /// Text(Encode encode, const void* data, unsigned int length); + + /// + /// + /// ~Text(); + /// + /// + /// const Content& getContent() const; + + /// + /// + /// const Content& operator*() const; private: + /// + /// + /// class Iterator { public: + + /// + /// + /// Iterator(const Iterator& itor); + + /// + /// + /// Iterator(const Encode& encode, const void* data, unsigned int length); + + /// + /// + /// ~Iterator(); + /// + /// + /// Codepoint get(); + //Iterator begin(); //Iterator end(); + + /// + /// + /// void toBegin(); + + /// + /// + /// void toEnd(); + + /// + /// + /// Codepoint operator *(); - /* prefix ++ */ + + /// + /// + /// Iterator& operator ++(); - /* postfix ++ */ + + /// + /// + /// Iterator operator ++(int); + + /// + /// + /// bool operator !=(const Iterator& itor); + + /// + /// + /// bool operator ==(const Iterator& itor); private: + + /// + /// + /// void operator = (const Iterator&); + /// + /// + /// const Encode encode; + + /// + /// + /// const Decoder* decoder; + + /// + /// + /// const void* p; + + /// + /// + /// const void* const data; + + /// + /// + /// unsigned int length; + }; + /// + /// + /// Content content; }; diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h index 9805cda..43d92c8 100644 --- a/src/libjin/Graphics/Font/je_texture_font.h +++ b/src/libjin/Graphics/Font/je_texture_font.h @@ -25,36 +25,111 @@ namespace JinEngine , public Drawable { public: + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh); + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); + + /// + /// + /// static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh); - + + /// + /// + /// ~TextureFont(); + /// + /// + /// Page* typeset(const Text& text, int lineheight, int spacing = 0) override; + + /// + /// + /// Page* typeset(const Content& text, int lineheight, int spacing = 0) override ; + /// + /// + /// void print(const Page* page, int x, int y) override; + + /// + /// + /// void print(const Content& text, int x, int y, int linehgiht, int spacing = 0) override; + + /// + /// + /// void print(const Text& text, int x, int y, int lineheight, int spacing = 0)override; private: + + /// + /// + /// struct TextureGlyph { float x, y, w, h; }; + /// + /// + /// TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh); + + /// + /// + /// TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh); + /// + /// + /// int getCharWidth(int c); + + /// + /// + /// int getCharHeight(int c); + + /// + /// + /// int getTextWidth(const Content& text, int spacing = 0); + + /// + /// + /// int getTextHeight(const Content& text, int lineheight); + + /// + /// + /// void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0); + + /// + /// + /// const TextureGlyph* findGlyph(Codepoint codepoint) const; + + /// + /// + /// std::map<Codepoint, TextureGlyph> glyphs; }; diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h index e4314fe..9acb07e 100644 --- a/src/libjin/Graphics/Font/je_ttf.h +++ b/src/libjin/Graphics/Font/je_ttf.h @@ -34,32 +34,81 @@ namespace JinEngine class TTFData { public: + + /// + /// + /// static TTFData* createTTFData(const unsigned char* data, unsigned int size); + /// + /// + /// ~TTFData(); + /// + /// + /// TTF* createTTF(unsigned ttfsize); + /// + /// + /// void pushTTFsize(unsigned ttfsize); + + /// + /// + /// void popTTFsize(); + /// + /// + /// Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const; + + /// + /// + /// Color* getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const; + /// + /// + /// void getVMetrics(int* baseline, int* descent); + + /// + /// + /// void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing); private: + + /// + /// + /// static const unsigned int FONT_SIZE = 12; + /// + /// + /// TTFData(const unsigned char* data, unsigned int size); + /// + /// + /// stbtt_fontinfo info; + + /// + /// + /// struct { unsigned char* data; unsigned int size; } raw; + + /// + /// + /// std::vector<float> scales; }; @@ -69,18 +118,43 @@ namespace JinEngine public: //static TTF* createTTF(TTFData* ttfData, unsigned ttfSzie); + /// + /// + /// Page* typeset(const Text& text, int lineheight, int spacing = 0) override; + + /// + /// + /// Page* typeset(const Content& text, int lineheight, int spacing = 0) override; + /// + /// + /// void print(const Text& text, int x, int y, int lineheight, int spacing = 0) override; + + /// + /// + /// void print(const Content& text, int x, int y, int lineheight, int spacing = 0) override; + + /// + /// + /// void print(const Page* page, int x, int y) override; + /// + /// + /// ~TTF(); private: + friend class TTFData; + /// + /// + /// struct TTFGlyph { GLuint atlas; @@ -94,34 +168,114 @@ namespace JinEngine unsigned int width, height; }; + /// + /// + /// static const int TEXTURE_SIZE_LEVELS_COUNT = 7; + + /// + /// + /// static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1; + + /// + /// + /// static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT]; + + /// + /// + /// static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT]; + /// + /// + /// TTF(TTFData* ttf, Codepoint ttfSize); + /// + /// + /// void estimateSize(); + + /// + /// + /// GLuint createAtlas(); + + /// + /// + /// TTFGlyph& bakeGlyph(Codepoint character); + + /// + /// + /// TTFGlyph& findGlyph(Codepoint character); + /// + /// + /// int getCharWidth(int c); + + /// + /// + /// int getCharHeight(int c); + /// + /// + /// int getTextWidth(const Content& text, int spacing = 0); + + /// + /// + /// int getTextHeight(const Content& text, int lineheight); + + /// + /// + /// void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0); + /// + /// + /// int textureWidth; + + /// + /// + /// int textureHeight; + + /// + /// + /// std::vector<GLuint> atlases; + + /// + /// + /// std::map<Codepoint, TTFGlyph> glyphs; + + /// + /// + /// TTFData* ttf; + + /// + /// + /// int baseline; + + /// + /// + /// int descent; - /* cursor helped render to texture */ + /// + /// + /// Math::Vector2<float> cursor; }; diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp new file mode 100644 index 0000000..490caea --- /dev/null +++ b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp @@ -0,0 +1,11 @@ +#include "je_jsl_compiler.h" + +namespace JinEngine +{ + namespace Graphics + { + + + + } // namespace Graphics +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.h b/src/libjin/Graphics/Shader/je_jsl_compiler.h new file mode 100644 index 0000000..b530466 --- /dev/null +++ b/src/libjin/Graphics/Shader/je_jsl_compiler.h @@ -0,0 +1,27 @@ +#ifndef __JE_JSL_COMPILER_H +#define __JE_JSL_COMPILER_H + +#include "../../common/je_singleton.hpp" + +namespace JinEngine +{ + namespace Graphics + { + + /// + /// Compile JSL into GLSL. + /// + class JSLCompiler : public Singleton<JSLCompiler> + { + public: + + + private: + singleton(JSLCompiler); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/Shader/je_shader.cpp b/src/libjin/Graphics/Shader/je_shader.cpp index 19485b9..6066864 100644 --- a/src/libjin/Graphics/Shader/je_shader.cpp +++ b/src/libjin/Graphics/Shader/je_shader.cpp @@ -77,6 +77,8 @@ namespace JinEngine { if (CurrentShader == this) unuse(); + // delete shader program + glDeleteShader(mPID); } bool Shader::compile(const string& program) @@ -96,21 +98,23 @@ namespace JinEngine int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER"); string vertex_shader = program.substr(start, loc_END_VERTEX_SHADER - start); Buffer vbuffer = Buffer(vertex_shader.length() + BASE_VERTEX_SHADER_SIZE); - formatVertexShader((char*)vbuffer.data, vertex_shader.c_str()); + formatVertexShader((char*)&vbuffer, vertex_shader.c_str()); start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER"); string fragment_shader = program.substr(start, loc_END_FRAGMENT_SHADER - start); Buffer fbuffer = Buffer(fragment_shader.length() + BASE_FRAGMENT_SHADER_SIZE); - formatFragmentShader((char*)fbuffer.data, fragment_shader.c_str()); + formatFragmentShader((char*)&fbuffer, fragment_shader.c_str()); // compile GLint success; GLuint vshader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vshader, 1, (const GLchar**)&vbuffer.data, NULL); + const byte* _data = &vbuffer; + glShaderSource(vshader, 1, (const GLchar**)&_data, NULL); glCompileShader(vshader); glGetShaderiv(vshader, GL_COMPILE_STATUS, &success); if (success == GL_FALSE) return false; GLuint fshader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fshader, 1, (const GLchar**)&fbuffer.data, NULL); + _data = &fbuffer; + glShaderSource(fshader, 1, (const GLchar**)&_data, NULL); glCompileShader(fshader); glGetShaderiv(fshader, GL_COMPILE_STATUS, &success); if (success == GL_FALSE) diff --git a/src/libjin/Graphics/animation/je_animation.cpp b/src/libjin/Graphics/animation/je_animation.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/animation/je_animation.cpp diff --git a/src/libjin/Graphics/animation/je_animation.h b/src/libjin/Graphics/animation/je_animation.h new file mode 100644 index 0000000..c006f83 --- /dev/null +++ b/src/libjin/Graphics/animation/je_animation.h @@ -0,0 +1,17 @@ +#ifndef __JE_ANIMATION_H +#define __JE_ANIMATION_H + +namespace JinEngine +{ + namespace Graphics + { + + class Animation + { + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/animation/je_clip.cpp b/src/libjin/Graphics/animation/je_clip.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/animation/je_clip.cpp diff --git a/src/libjin/Graphics/animation/je_clip.h b/src/libjin/Graphics/animation/je_clip.h new file mode 100644 index 0000000..35a35b3 --- /dev/null +++ b/src/libjin/Graphics/animation/je_clip.h @@ -0,0 +1,17 @@ +#ifndef __JE_CLIP_H +#define __JE_CLIP_H + +namespace JinEngine +{ + namespace Graphics + { + + class Clip + { + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h index 8adc326..d9d0981 100644 --- a/src/libjin/Graphics/je_bitmap.h +++ b/src/libjin/Graphics/je_bitmap.h @@ -4,7 +4,9 @@ #if LIBJIN_MODULES_RENDER #include "../3rdparty/GLee/GLee.h" +#include "../common/je_types.h" #include "../math/je_vector2.hpp" + #include "je_color.h" namespace JinEngine diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h index 321cd32..9839899 100644 --- a/src/libjin/Graphics/je_canvas.h +++ b/src/libjin/Graphics/je_canvas.h @@ -64,4 +64,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_RENDER + #endif // __JE_CANVAS_H
\ No newline at end of file diff --git a/src/libjin/Graphics/je_color.h b/src/libjin/Graphics/je_color.h index a3c7582..80c1e4d 100644 --- a/src/libjin/Graphics/je_color.h +++ b/src/libjin/Graphics/je_color.h @@ -27,8 +27,14 @@ namespace JinEngine static const Color MAGENTA; static const Color YELLOW; + /// + /// + /// Color() { r = g = b = a = 0; }; - + + /// + /// + /// Color(unsigned char _r , unsigned char _g , unsigned char _b diff --git a/src/libjin/Graphics/je_drawable.cpp b/src/libjin/Graphics/je_drawable.cpp index 00ff739..af9e4d8 100644 --- a/src/libjin/Graphics/je_drawable.cpp +++ b/src/libjin/Graphics/je_drawable.cpp @@ -14,42 +14,42 @@ namespace JinEngine { Drawable::Drawable(int w, int h) - : texture(0) - , size(w, h) - , anchor(0, 0) + : mTexture(0) + , mSize(w, h) + , mOrigin(0, 0) { - vertex_coords[0] = 0; vertex_coords[1] = 0; - vertex_coords[2] = 0; vertex_coords[3] = h; - vertex_coords[4] = w; vertex_coords[5] = h; - vertex_coords[6] = w; vertex_coords[7] = 0; - - texture_coords[0] = 0; texture_coords[1] = 0; - texture_coords[2] = 0; texture_coords[3] = 1; - texture_coords[4] = 1; texture_coords[5] = 1; - texture_coords[6] = 1; texture_coords[7] = 0; + mVertexCoords[0] = 0; mVertexCoords[1] = 0; + mVertexCoords[2] = 0; mVertexCoords[3] = h; + mVertexCoords[4] = w; mVertexCoords[5] = h; + mVertexCoords[6] = w; mVertexCoords[7] = 0; + + mTextureCoords[0] = 0; mTextureCoords[1] = 0; + mTextureCoords[2] = 0; mTextureCoords[3] = 1; + mTextureCoords[4] = 1; mTextureCoords[5] = 1; + mTextureCoords[6] = 1; mTextureCoords[7] = 0; } Drawable::Drawable(const Bitmap* bitmap) - : texture(0) - , anchor(0, 0) + : mTexture(0) + , mOrigin(0, 0) { - unsigned int w = size.w = bitmap->getWidth(); - unsigned int h = size.h = bitmap->getHeight(); + uint32 w = mSize.w = bitmap->getWidth(); + uint32 h = mSize.h = bitmap->getHeight(); - vertex_coords[0] = 0; vertex_coords[1] = 0; - vertex_coords[2] = 0; vertex_coords[3] = h; - vertex_coords[4] = w; vertex_coords[5] = h; - vertex_coords[6] = w; vertex_coords[7] = 0; + mVertexCoords[0] = 0; mVertexCoords[1] = 0; + mVertexCoords[2] = 0; mVertexCoords[3] = h; + mVertexCoords[4] = w; mVertexCoords[5] = h; + mVertexCoords[6] = w; mVertexCoords[7] = 0; - texture_coords[0] = 0; texture_coords[1] = 0; - texture_coords[2] = 0; texture_coords[3] = 1; - texture_coords[4] = 1; texture_coords[5] = 1; - texture_coords[6] = 1; texture_coords[7] = 0; + mTextureCoords[0] = 0; mTextureCoords[1] = 0; + mTextureCoords[2] = 0; mTextureCoords[3] = 1; + mTextureCoords[4] = 1; mTextureCoords[5] = 1; + mTextureCoords[6] = 1; mTextureCoords[7] = 0; const Color* pixels = bitmap->getPixels(); - texture = gl.genTexture(); - gl.bindTexture(texture); + mTexture = gl.genTexture(); + gl.bindTexture(mTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); @@ -58,26 +58,26 @@ namespace JinEngine Drawable::~Drawable() { - glDeleteTextures(1, &texture); + glDeleteTextures(1, &mTexture); } - void Drawable::setAnchor(int x, int y) + void Drawable::setOrigin(int x, int y) { - anchor.x = x; - anchor.y = y; + mOrigin.x = x; + mOrigin.y = y; } void Drawable::draw(int x, int y, float sx, float sy, float r) { - gl.ModelMatrix.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y); + gl.ModelMatrix.setTransformation(x, y, r, sx, sy, mOrigin.x, mOrigin.y); Shader* shader = Shader::getCurrentShader(); shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - shader->bindVertexPointer(2, GL_FLOAT, 0, vertex_coords); - shader->bindUVPointer(2, GL_FLOAT, 0, texture_coords); + shader->bindVertexPointer(2, GL_FLOAT, 0, mVertexCoords); + shader->bindUVPointer(2, GL_FLOAT, 0, mTextureCoords); - gl.bindTexture(texture); + gl.bindTexture(mTexture); gl.drawArrays(GL_QUADS, 0, 4); gl.bindTexture(0); } @@ -90,10 +90,10 @@ namespace JinEngine slice.w, slice.h, slice.w, 0 }; - float slx = slice.x / size.w; - float sly = slice.y / size.h; - float slw = slice.w / size.w; - float slh = slice.h / size.h; + float slx = slice.x / mSize.w; + float sly = slice.y / mSize.h; + float slw = slice.w / mSize.w; + float slh = slice.h / mSize.h; float texCoords[8] = { slx, sly, slx, sly + slh, @@ -109,7 +109,7 @@ namespace JinEngine shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords); shader->bindUVPointer(2, GL_FLOAT, 0, texCoords); - gl.bindTexture(texture); + gl.bindTexture(mTexture); gl.drawArrays(GL_QUADS, 0, 4); gl.bindTexture(0); } diff --git a/src/libjin/Graphics/je_drawable.h b/src/libjin/Graphics/je_drawable.h index 2547373..1b739cb 100644 --- a/src/libjin/Graphics/je_drawable.h +++ b/src/libjin/Graphics/je_drawable.h @@ -37,7 +37,7 @@ namespace JinEngine /// /// /// - void setAnchor(int x, int y); + void setOrigin(int x, int y); /// /// @@ -52,17 +52,17 @@ namespace JinEngine /// /// /// - inline int getWidth() const { return size.w; } + inline int getWidth() const { return mSize.w; } /// /// /// - inline int getHeight() const { return size.h; } + inline int getHeight() const { return mSize.h; } /// /// /// - inline GLuint getTexture() const { return texture; } + inline GLuint getTexture() const { return mTexture; } /// /// @@ -72,14 +72,12 @@ namespace JinEngine protected: static const int DRAWABLE_V_SIZE = 8; - GLuint texture; - GLuint vbo; - /* TODO: vertex buffer object */ - /* GLuint vbo; */ - JinEngine::Math::Vector2<unsigned int> size; - JinEngine::Math::Vector2<int> anchor; - float vertex_coords[DRAWABLE_V_SIZE]; - float texture_coords[DRAWABLE_V_SIZE]; + GLuint mTexture; + GLuint mVBO; + JinEngine::Math::Vector2<unsigned int> mSize; + JinEngine::Math::Vector2<int> mOrigin; + float mVertexCoords[DRAWABLE_V_SIZE]; + float mTextureCoords[DRAWABLE_V_SIZE]; }; @@ -87,4 +85,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_RENDER + #endif // __JE_DRAWABLE
\ No newline at end of file diff --git a/src/libjin/Graphics/je_gl.h b/src/libjin/Graphics/je_gl.h index 703fdc7..846b90a 100644 --- a/src/libjin/Graphics/je_gl.h +++ b/src/libjin/Graphics/je_gl.h @@ -13,9 +13,19 @@ namespace JinEngine class OpenGL : public ogl2d::OpenGL { public: + /// + /// + /// Math::Matrix ProjectionMatrix; + + /// + /// + /// Math::Matrix ModelMatrix; + /// + /// + /// OpenGL() : ogl2d::OpenGL() { } diff --git a/src/libjin/Graphics/je_image.cpp b/src/libjin/Graphics/je_image.cpp index a905943..f800423 100644 --- a/src/libjin/Graphics/je_image.cpp +++ b/src/libjin/Graphics/je_image.cpp @@ -15,7 +15,7 @@ namespace JinEngine if (imgData == nullptr) return nullptr; int w, h; - void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha); + void* data = stbi_load_from_memory((uint8*)imgData, size, &w, &h, NULL, STBI_rgb_alpha); if (data == nullptr) return nullptr; Image* image = new Image(); @@ -29,8 +29,8 @@ namespace JinEngine { AssetDatabase* fs = AssetDatabase::get(); Buffer buffer; - fs->read(path, &buffer); - return createImage(buffer.data, buffer.size); + fs->read(path, buffer); + return createImage(&buffer, buffer.size()); } Image::Image() @@ -43,4 +43,4 @@ namespace JinEngine } } // namespace Graphics -} // namespace JinEngine
\ No newline at end of file +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Graphics/je_mesh.cpp b/src/libjin/Graphics/je_mesh.cpp index 4ef5a6e..dd2d61c 100644 --- a/src/libjin/Graphics/je_mesh.cpp +++ b/src/libjin/Graphics/je_mesh.cpp @@ -5,7 +5,7 @@ namespace JinEngine 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 854b701..ed22d91 100644 --- a/src/libjin/Graphics/je_mesh.h +++ b/src/libjin/Graphics/je_mesh.h @@ -6,6 +6,9 @@ namespace JinEngine namespace Graphics { + /// + /// + /// class Mesh { public: diff --git a/src/libjin/Graphics/je_shapes.h b/src/libjin/Graphics/je_shapes.h index ea010be..2221526 100644 --- a/src/libjin/Graphics/je_shapes.h +++ b/src/libjin/Graphics/je_shapes.h @@ -1,7 +1,7 @@ #ifndef __JE_GEOMETRY_H #define __JE_GEOMETRY_H #include "../core/je_configuration.h" -#if LIBJIN_MODULES_RENDER +#if defined(jin_graphics) #include "je_color.h" #include "je_canvas.h" @@ -18,10 +18,6 @@ namespace JinEngine LINE }RenderMode; - /** - * TODO: - * drawPixels(int n, points) - */ 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); @@ -33,5 +29,6 @@ namespace JinEngine } // namespace Graphics } // namespace JinEngine -#endif // LIBJIN_MODULES_RENDER +#endif // jin_graphics + #endif // __JE_GEOMETRY_H
\ No newline at end of file diff --git a/src/libjin/Graphics/je_sprite.cpp b/src/libjin/Graphics/je_sprite.cpp index e69de29..3ac976a 100644 --- a/src/libjin/Graphics/je_sprite.cpp +++ b/src/libjin/Graphics/je_sprite.cpp @@ -0,0 +1,11 @@ +#include "je_sprite.h" + +namespace JinEngine +{ + namespace Graphics + { + + + + } // namespace Graphics +} // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index 9c3f7a2..23824a7 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -1,6 +1,10 @@ #ifndef __JE_SPRITE_H #define __JE_SPRITE_H +#include "je_color.h" +#include "../common/je_types.h" +#include "../math/je_vector2.hpp" + namespace JinEngine { namespace Graphics @@ -11,10 +15,16 @@ namespace JinEngine class Sprite { public: - + + private: + Math::Vector2<int> mPosition; + Math::Vector2<int> mOrigin; + Math::Vector2<int> mScale; + Color mColor; + }; - } -} + } // namespace Graphics +} // namespace JinEngine #endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_sprite_batch.cpp b/src/libjin/Graphics/je_sprite_batch.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/je_sprite_batch.cpp diff --git a/src/libjin/Graphics/je_sprite_batch.h b/src/libjin/Graphics/je_sprite_batch.h new file mode 100644 index 0000000..85a7951 --- /dev/null +++ b/src/libjin/Graphics/je_sprite_batch.h @@ -0,0 +1,17 @@ +#ifndef __JE_SPRITE_BATCH_H +#define __JE_SPRITE_BATCH_H + +namespace JinEngine +{ + namespace Graphics + { + + class SpriteBatch + { + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp index bdcb00a..163aa36 100644 --- a/src/libjin/Graphics/je_window.cpp +++ b/src/libjin/Graphics/je_window.cpp @@ -70,15 +70,15 @@ namespace JinEngine return false; SDL_GL_SetSwapInterval(vsync ? 1 : 0); SDL_GL_MakeCurrent(wnd, ctx); - /* default configuration */ + // default configuration gl.setClearColor(0, 0, 0, 0xff); gl.pushColor(0xff, 0xff, 0xff, 0xff); gl.enable(GL_BLEND); gl.enable(GL_TEXTURE_2D); gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* avoid white screen blink on windows */ + // avoid white screen blink on windows swapBuffers(); - /* bind to default canvas */ + // bind to default canvas Canvas::unbind(); Shader::unuse(); return true; @@ -86,10 +86,10 @@ namespace JinEngine void Window::quitSystem() { - /* disable opengl */ + // disable opengl gl.disable(GL_BLEND); gl.disable(GL_TEXTURE_2D); - /* close window */ + // close window SDL_DestroyWindow(wnd); SDL_Quit(); } diff --git a/src/libjin/Graphics/je_window.h b/src/libjin/Graphics/je_window.h index f7d265f..0969a36 100644 --- a/src/libjin/Graphics/je_window.h +++ b/src/libjin/Graphics/je_window.h @@ -59,6 +59,7 @@ namespace JinEngine void swapBuffers(); private: + // declare a singleton singleton(Window); diff --git a/src/libjin/Graphics/particle/je_particle.cpp b/src/libjin/Graphics/particle/je_particle.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle.cpp diff --git a/src/libjin/Graphics/particle/je_particle.h b/src/libjin/Graphics/particle/je_particle.h new file mode 100644 index 0000000..ba4dd18 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle.h @@ -0,0 +1,20 @@ +#ifndef __JE_PARTICLE_H +#define __JE_PARTICLE_H + +namespace JinEngine +{ + namespace Graphics + { + + /// + /// Single particle. + /// + class Particle + { + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/Graphics/particle/je_particle_batch.cpp b/src/libjin/Graphics/particle/je_particle_batch.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle_batch.cpp diff --git a/src/libjin/Graphics/particle/je_particle_batch.h b/src/libjin/Graphics/particle/je_particle_batch.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle_batch.h diff --git a/src/libjin/Graphics/particle/je_particle_emitter.cpp b/src/libjin/Graphics/particle/je_particle_emitter.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle_emitter.cpp diff --git a/src/libjin/Graphics/particle/je_particle_emitter.h b/src/libjin/Graphics/particle/je_particle_emitter.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle_emitter.h diff --git a/src/libjin/Graphics/particle/je_particle_system.cpp b/src/libjin/Graphics/particle/je_particle_system.cpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle_system.cpp @@ -0,0 +1 @@ +#pragma once diff --git a/src/libjin/Graphics/particle/je_particle_system.h b/src/libjin/Graphics/particle/je_particle_system.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/Graphics/particle/je_particle_system.h diff --git a/src/libjin/Input/je_event.h b/src/libjin/Input/je_event.h index ca5dab7..2e87dc9 100644 --- a/src/libjin/Input/je_event.h +++ b/src/libjin/Input/je_event.h @@ -14,6 +14,9 @@ namespace JinEngine typedef SDL_Keycode Key; typedef SDL_MouseWheelEvent Wheel; + /// + /// + /// enum EventType { QUIT = SDL_QUIT, /* keyboard events */ @@ -39,6 +42,9 @@ namespace JinEngine WINDOW_EVENT = SDL_WINDOWEVENT, }; + /// + /// + /// enum WindowEvent { WINDOW_SHOWN = SDL_WINDOWEVENT_SHOWN , WINDOW_HIDDEN = SDL_WINDOWEVENT_HIDDEN , @@ -58,16 +64,25 @@ namespace JinEngine WINDOW_HIT_TEST = SDL_WINDOWEVENT_HIT_TEST , }; + /// + /// + /// inline int pollEvent(Event* e) { return SDL_PollEvent(e); } + /// + /// + /// inline const char* getKeyName(Key key) { return SDL_GetKeyName(key); } + /// + /// + /// inline const char* getButtonName(int button) { switch (button) @@ -102,4 +117,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_INPUT -#endif
\ No newline at end of file + +#endif // __JE_EVENT_H
\ No newline at end of file diff --git a/src/libjin/Input/je_joypad.h b/src/libjin/Input/je_joypad.h index 49cd2d8..74173af 100644 --- a/src/libjin/Input/je_joypad.h +++ b/src/libjin/Input/je_joypad.h @@ -8,6 +8,9 @@ namespace JinEngine namespace Input { + /// + /// + /// inline const char* getJoyButtonName(int button) { switch (button) @@ -31,6 +34,9 @@ namespace JinEngine } } + /// + /// + /// inline const char* getJoyAxisName(int axis) { switch (axis) @@ -47,4 +53,4 @@ namespace JinEngine } // namespace Input } // namespace JinEngine -#endif
\ No newline at end of file +#endif // __JE_JOYPAD_H
\ No newline at end of file diff --git a/src/libjin/Input/je_keyboard.h b/src/libjin/Input/je_keyboard.h index 85b6267..61da361 100644 --- a/src/libjin/Input/je_keyboard.h +++ b/src/libjin/Input/je_keyboard.h @@ -6,6 +6,9 @@ namespace JinEngine namespace Input { + /// + /// + /// class Keyboard { diff --git a/src/libjin/Input/je_mouse.h b/src/libjin/Input/je_mouse.h index 6f01993..bd25e9c 100644 --- a/src/libjin/Input/je_mouse.h +++ b/src/libjin/Input/je_mouse.h @@ -10,16 +10,33 @@ namespace JinEngine namespace Input { + /// + /// + /// class Mouse : public Singleton<Mouse> { public: + /// + /// + /// void getState(int* x, int* y); + + /// + /// + /// void setVisible(bool visible); private: singleton(Mouse); + /// + /// + /// Mouse() {}; + + /// + /// + /// ~Mouse() {}; }; @@ -28,4 +45,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_INPUT + #endif // __JE_MOUSE_H
\ No newline at end of file diff --git a/src/libjin/Math/README.md b/src/libjin/Math/README.md new file mode 100644 index 0000000..a096332 --- /dev/null +++ b/src/libjin/Math/README.md @@ -0,0 +1 @@ +ļռΪJinEngineڴģ乲õ
\ No newline at end of file diff --git a/src/libjin/Math/je_math.h b/src/libjin/Math/je_math.h index adbe2f4..1f8e0b3 100644 --- a/src/libjin/Math/je_math.h +++ b/src/libjin/Math/je_math.h @@ -11,10 +11,10 @@ namespace JinEngine { #ifdef min - # undef min + #undef min #endif // min #ifdef max - # undef max + #undef max #endif // max template<typename T> @@ -74,4 +74,4 @@ namespace JinEngine } // namespace Math } // namespace JinEngine -#endif
\ No newline at end of file +#endif // __JE_UTILS_MATH_H
\ No newline at end of file diff --git a/src/libjin/Math/je_matrix.h b/src/libjin/Math/je_matrix.h index 1ab9371..3592d18 100644 --- a/src/libjin/Math/je_matrix.h +++ b/src/libjin/Math/je_matrix.h @@ -12,143 +12,143 @@ namespace JinEngine 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 - **/ + /// + /// 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 | - **/ + /// + /// | 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. - **/ + /// + /// Creates a new identity matrix. + /// Matrix(); - /** - * Destructor. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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; + /// + /// Gets a pointer to the 16 array elements. + /// @return The array elements. + /// + const float* getElements() const; - /** - * Resets this Matrix to the identity matrix. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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 - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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. - **/ + /// + /// 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; }; @@ -156,4 +156,4 @@ namespace JinEngine } // namespace Math } // namespace JinEngine -#endif
\ No newline at end of file +#endif // __JE_MATRIX_H
\ No newline at end of file diff --git a/src/libjin/Math/je_quad.h b/src/libjin/Math/je_quad.h index 4121eab..2a66fa1 100644 --- a/src/libjin/Math/je_quad.h +++ b/src/libjin/Math/je_quad.h @@ -6,12 +6,18 @@ namespace JinEngine namespace Math { + /// + /// + /// struct Quad { + /// + /// + /// float x, y, w, h; }; } // namespace Math } // namespace JinEngine -#endif
\ No newline at end of file +#endif // __JE_QUAD_H
\ No newline at end of file diff --git a/src/libjin/Math/je_random.h b/src/libjin/Math/je_random.h new file mode 100644 index 0000000..eb59341 --- /dev/null +++ b/src/libjin/Math/je_random.h @@ -0,0 +1,14 @@ +#ifndef __JE_RANDOM_H +#define __JE_RANDOM_H + +namespace JinEngine +{ + namespace Math + { + + + + } +} + +#endif
\ 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 31c4d04..05c3fe3 100644 --- a/src/libjin/Net/je_net_manager.h +++ b/src/libjin/Net/je_net_manager.h @@ -12,15 +12,32 @@ namespace JinEngine namespace Net { + /// + /// + /// class NetManager : public Subsystem<NetManager> { - public: - protected: - singleton(NetManager); + singleton(NetManager); + + /// + /// + /// NetManager() {}; + + /// + /// + /// ~NetManager() {}; + + /// + /// + /// bool initSystem(const SettingBase* setting) override; + + /// + /// + /// void quitSystem() override; }; @@ -29,4 +46,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_NET -#endif // __JE_NET_H + +#endif // __JE_NET_H
\ No newline at end of file diff --git a/src/libjin/Net/je_socket.h b/src/libjin/Net/je_socket.h index 5a31683..cfe904f 100644 --- a/src/libjin/Net/je_socket.h +++ b/src/libjin/Net/je_socket.h @@ -10,12 +10,18 @@ namespace JinEngine namespace Net { + /// + /// + /// enum SocketType { TCP, UDP }; + /// + /// + /// struct SocketInformation { unsigned int address; @@ -23,34 +29,109 @@ namespace JinEngine SocketType type; }; + /// + /// + /// class Socket { public: + + /// + /// + /// Socket() {}; + + /// + /// + /// Socket(const Socket& socket); + + /// + /// + /// Socket(const SocketInformation& socketInformation); + + /// + /// + /// Socket(SocketType type, unsigned short port); + + /// + /// + /// Socket(SocketType type, unsigned int address, unsigned short port); + + /// + /// + /// Socket(SocketType type, const char* address, unsigned short port); + + /// + /// + /// ~Socket(); + + /// + /// + /// void configureBlocking(bool bocking); + + /// + /// + /// Socket* accept(); + + /// + /// + /// int receive(char* buffer, int size); + + /// + /// + /// int send(char* buffer, int size); + + /// + /// + /// void sendTo(char* buffer, int size, unsigned int address, unsigned int port); + + /// + /// + /// int receiveFrom(char* buffer, int size, unsigned int address, unsigned int port); + + /// + /// + /// void close(); protected: #if LIBJIN_NET_TEKCOS + + /// + /// + /// Socket(const tk_TCPsocket& tcpHandle); + + /// + /// + /// Socket(const tk_UDPsocket& udpHandle); + + /// + /// + /// union { tk_TCPsocket tcpHandle; tk_UDPsocket udpHandle; } handle; #endif + + /// + /// + /// SocketType type; }; @@ -59,4 +140,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_NET -#endif // __JE_NET_SOCKET_H + +#endif // __JE_NET_SOCKET_H
\ No newline at end of file diff --git a/src/libjin/Time/je_timer.h b/src/libjin/Time/je_timer.h index e5488cc..82b4b52 100644 --- a/src/libjin/Time/je_timer.h +++ b/src/libjin/Time/je_timer.h @@ -11,19 +11,49 @@ namespace JinEngine namespace Time { + /// + /// + /// class Timers { public: typedef void(*timer_callback)(void* prameters); + /// + /// + /// Timers(); + + /// + /// + /// ~Timers(); + + /// + /// + /// void update(int ms); + + /// + /// + /// void every(int ms, timer_callback callback, void* paramters); + + /// + /// + /// void after(int ms, timer_callback callback, void* paramters); + + /// + /// + /// void repeat(int ms, int count, timer_callback callback, void* paramters); private: + + /// + /// + /// class Timer { public: @@ -48,7 +78,10 @@ namespace JinEngine std::vector<Timer*> timers; }; - + + /// + /// + /// inline void sleep(int ms) { #if LIBJIN_TIME_SDL @@ -56,6 +89,9 @@ namespace JinEngine #endif } + /// + /// + /// inline double getSecond() { #if LIBJIN_TIME_SDL @@ -63,6 +99,9 @@ namespace JinEngine #endif } + /// + /// + /// inline double getMilliSecond() { #if LIBJIN_TIME_SDL @@ -74,4 +113,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_TIME -#endif // __JE_TIMER_H + +#endif // __JE_TIMER_H
\ No newline at end of file diff --git a/src/libjin/Utils/je_log.h b/src/libjin/Utils/je_log.h index 9b3fe2c..8e4bf61 100644 --- a/src/libjin/Utils/je_log.h +++ b/src/libjin/Utils/je_log.h @@ -132,4 +132,4 @@ void Loghelper::close() #endif -#endif +#endif
\ No newline at end of file diff --git a/src/libjin/ai/je_behavior_tree.cpp b/src/libjin/ai/je_behavior_tree.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/ai/je_behavior_tree.cpp diff --git a/src/libjin/ai/je_behavior_tree.h b/src/libjin/ai/je_behavior_tree.h new file mode 100644 index 0000000..0654849 --- /dev/null +++ b/src/libjin/ai/je_behavior_tree.h @@ -0,0 +1,20 @@ +#ifndef __JE_BEHAVIOR_TREE_H +#define __JE_BEHAVIOR_TREE_H + +namespace JinEngine +{ + namespace AI + { + + /// + /// + /// + class BehaviorTree + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/src/libjin/ai/je_state_machine.cpp b/src/libjin/ai/je_state_machine.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/libjin/ai/je_state_machine.cpp diff --git a/src/libjin/ai/je_state_machine.h b/src/libjin/ai/je_state_machine.h new file mode 100644 index 0000000..4e80da3 --- /dev/null +++ b/src/libjin/ai/je_state_machine.h @@ -0,0 +1,20 @@ +#ifndef __JE_STATEMACHINE_TREE_H +#define __JE_STATEMACHINE_TREE_H + +namespace JinEngine +{ + namespace AI + { + + /// + /// + /// + class StateMachine + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/src/libjin/core/README.md b/src/libjin/core/README.md new file mode 100644 index 0000000..b393007 --- /dev/null +++ b/src/libjin/core/README.md @@ -0,0 +1 @@ +ļµļƱṩһЩ汾Ϣ
\ No newline at end of file diff --git a/src/libjin/core/je_configuration.h b/src/libjin/core/je_configuration.h index 819b34d..f70ae5a 100644 --- a/src/libjin/core/je_configuration.h +++ b/src/libjin/core/je_configuration.h @@ -66,4 +66,12 @@ #define jin_graphics_font #define jin_graphics_shader +#define jin_audio + +#define jin_filesystem + +#define jin_game + +#define jin_core + #endif
\ No newline at end of file diff --git a/src/libjin/core/je_types.h b/src/libjin/core/je_types.h deleted file mode 100644 index 5fd6c12..0000000 --- a/src/libjin/core/je_types.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __JE_CORE_TYPES_H -#define __JE_CORE_TYPES_H - -#include <stdint.h> - -namespace JinEngine -{ - namespace Core - { - - typedef int8_t int8; ///< Signed integer with a size of 8 bits. Supports values from -128 to 127 - typedef uint8_t uint8; ///< Unsigned integer with a size of 8 bits. Supports values from 0 to 255. - typedef uint8 byte; ///< Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255. - typedef int16_t int16; ///< Signed integer with a size of 16 bits. Supports values from -32768 to 32767 - typedef uint16_t uint16; ///< Unsigned integer with a size of 16 bits. Supports values from 0 to 65535. - typedef int32_t int32; ///< Signed integer with a size of 32 bits. Supports values from -2147483648 to 2147483647. - typedef uint32_t uint32; ///< Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1). - typedef int64_t int64; ///< Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1). - typedef uint64_t uint64; ///< Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1). - - } -} - -#endif // __JE_CORE_TYPES_H
\ No newline at end of file diff --git a/src/libjin/core/je_version.h b/src/libjin/core/je_version.h new file mode 100644 index 0000000..6a91797 --- /dev/null +++ b/src/libjin/core/je_version.h @@ -0,0 +1,26 @@ +#ifndef __JE_CORE_VERSION_H +#define __JE_CORE_VERSION_H + +namespace JinEngine +{ + namespace Core + { + + /// + /// Get version of Jin. + /// + /// @return Version of Jin. + /// + int getVersion(); + + /// + /// Get author of Jin. + /// + /// @return Author of Jin. + /// + int getAuthor(); + + } // namespace Core +} // namespace JinEngine + +#endif
\ No newline at end of file diff --git a/src/libjin/jin.h b/src/libjin/jin.h index 443fbed..53b61fb 100644 --- a/src/libjin/jin.h +++ b/src/libjin/jin.h @@ -14,7 +14,7 @@ #include "net/je_net_manager.h" #include "graphics/je_graphics.h" #include "time/je_timer.h" -#include "thread/je_thread.h" +#include "multithread/je_thread.h" #include "common/je_common.h" #define LIBJIN_VERSION "Jin 0.1"; diff --git a/src/libjin/Thread/je_thread.cpp b/src/libjin/multithread/je_thread.cpp index 3c18657..3c18657 100644 --- a/src/libjin/Thread/je_thread.cpp +++ b/src/libjin/multithread/je_thread.cpp diff --git a/src/libjin/Thread/je_thread.h b/src/libjin/multithread/je_thread.h index b39e4e2..b3a3e2e 100644 --- a/src/libjin/Thread/je_thread.h +++ b/src/libjin/multithread/je_thread.h @@ -28,17 +28,17 @@ namespace JinEngine 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. - */ + // + // 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: @@ -163,4 +163,5 @@ namespace JinEngine } // namespace JinEngine #endif // LIBJIN_MODULES_THREAD + #endif // __JE_THREAD_H
\ No newline at end of file diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp index 4d8837a..faae9b2 100644 --- a/src/lua/jin.cpp +++ b/src/lua/jin.cpp @@ -78,6 +78,7 @@ namespace JinEngine { "math", luaopen_math }, { "thread", luaopen_thread }, { "bit", luaopen_bit }, + //{"ai", luaopen_ai }, { 0, 0 } }; diff --git a/src/lua/main.cpp b/src/lua/main.cpp index a17ed1c..495ca6f 100644 --- a/src/lua/main.cpp +++ b/src/lua/main.cpp @@ -28,16 +28,17 @@ int main(int argc, char* argv[]) /* absolute directory */ Buffer cwd = Buffer(1024); #ifdef _WIN32 - _getcwd((char*)cwd.data, cwd.size); + _getcwd((char*)&cwd, cwd.size()); #elif defined __unix__ #elif defined __APPLE__ #endif - luax_setfieldstring(L, "cwd", (char*)cwd.data); + luax_setfieldstring(L, "cwd", (char*)&cwd); luax_clear(L); /* boot jin and run it */ boot(L); luax_close(L); + return 0; }
\ No newline at end of file diff --git a/src/lua/modules/audio/audio.cpp b/src/lua/modules/audio/audio.cpp index 0aa4a29..198323d 100644 --- a/src/lua/modules/audio/audio.cpp +++ b/src/lua/modules/audio/audio.cpp @@ -70,12 +70,12 @@ namespace JinEngine error(L, "No such image %s", f); goto fail; } - if (!fs->read(f, &b)) + if (!fs->read(f, b)) { error(L, "Failed to read source file %s", f); goto fail; } - Source* src = Source::createSource(b.data, b.size); + Source* src = Source::createSource((void*)&b, b.size()); if (src == nullptr) { error(L, "Failed to decode source file %s", f); diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp index f46f8d9..7466ce8 100644 --- a/src/lua/modules/filesystem/filesystem.cpp +++ b/src/lua/modules/filesystem/filesystem.cpp @@ -55,8 +55,8 @@ namespace JinEngine { const char* filename = lua_tostring(L, -1); Buffer bf; - context.fs->read(filename, &bf); - luax_loadbuffer(L, (const char*)bf.data, bf.size, filename); + context.fs->read(filename, bf); + luax_loadbuffer(L, (const char*)&bf, bf.size(), filename); return 1; } @@ -113,9 +113,9 @@ namespace JinEngine const char* file = luax_checkstring(L, 1); unsigned int len; Buffer buffer; - buffer.data = (char*)fs->read(file, &buffer.size); - luax_pushstring(L, (char*)buffer.data); - luax_pushinteger(L, buffer.size); + fs->read(file, buffer); + luax_pushstring(L, (char*)&buffer); + luax_pushinteger(L, buffer.size()); return 2; } diff --git a/src/lua/modules/graphics/canvas.cpp b/src/lua/modules/graphics/canvas.cpp index 79e7282..b64dc16 100644 --- a/src/lua/modules/graphics/canvas.cpp +++ b/src/lua/modules/graphics/canvas.cpp @@ -40,12 +40,12 @@ namespace JinEngine return 2; } - static int l_setAnchor(lua_State* L) + static int l_setOrigin(lua_State* L) { CanvasRef ref = checkCanvas(L); int x = luax_checknumber(L, 1); int y = luax_checknumber(L, 2); - ref->setAnchor(x, y); + ref->setOrigin(x, y); return 0; } @@ -61,7 +61,7 @@ namespace JinEngine { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, { "getSize", l_getSize }, - { "setAnchor", l_setAnchor }, + { "setOrigin", l_setOrigin }, { 0, 0 } }; diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index 573f319..4ff0dfc 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -10,6 +10,7 @@ namespace JinEngine { namespace Lua { + using namespace std; using namespace JinEngine; using namespace JinEngine::Graphics; @@ -125,12 +126,12 @@ namespace JinEngine goto fail; } Buffer b = {}; - if (!fs->read(f, &b)) + if (!fs->read(f, b)) { error(L, "Failed to read image %s", f); goto fail; } - bitmap = Bitmap::createBitmap(b.data, b.size); + bitmap = Bitmap::createBitmap(&b, b.size()); //const Color* col = bitmap->getPixels(); //ofstream o = ofstream("img.txt", ios_base::app); //for (int i = 0; i < bitmap->getWidth() * bitmap->getHeight(); ++i) @@ -195,8 +196,8 @@ namespace JinEngine return 1; } Buffer b; - fs->read(path, &b); - Shader* jsl = Shader::createShader((char*)b.data); + fs->read(path, b); + Shader* jsl = Shader::createShader((char*)&b); if (jsl == nullptr) { error(L, "Failed to compile shader"); @@ -618,8 +619,8 @@ namespace JinEngine return 1; } Buffer b; - fs->read(path, &b); - fd = TTFData::createTTFData((unsigned char*)b.data, b.size); + fs->read(path, b); + fd = TTFData::createTTFData(&b, b.size()); } proxy->bind(new Ref<TTFData>(fd, JIN_GRAPHICS_TTFDATA)); return 1; diff --git a/src/lua/modules/graphics/texture.cpp b/src/lua/modules/graphics/texture.cpp index 63ab5f2..15e258c 100644 --- a/src/lua/modules/graphics/texture.cpp +++ b/src/lua/modules/graphics/texture.cpp @@ -32,12 +32,12 @@ namespace JinEngine return 1; } - static int l_setAnchor(lua_State* L) + static int l_setOrigin(lua_State* L) { TextureRef ref = checkTexture(L); int x = luax_checknumber(L, 2); int y = luax_checknumber(L, 3); - ref->setAnchor(x, y); + ref->setOrigin(x, y); return 0; } @@ -61,7 +61,7 @@ namespace JinEngine { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, { "getSize", l_getSize }, - { "setAnchor", l_setAnchor }, + { "setOrigin", l_setOrigin }, { 0, 0 } }; diff --git a/src/lua/resources/font.ttf.h b/src/lua/resources/font.ttf.h index 419adc5..d2c6bf1 100644 --- a/src/lua/resources/font.ttf.h +++ b/src/lua/resources/font.ttf.h @@ -1,5 +1,6 @@ -static const char default_font_bitmap[] = -{ 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,106,0,0,0,13,8,6,0,0,0, +static const char +default_font_bitmap[] = { +137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,106,0,0,0,13,8,6,0,0,0, 216,50,157,116,0,0,0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0,0,9,112,72,89, 115,0,0,14,194,0,0,14,194,1,21,40,74,128,0,0,0,25,116,69,88,116,83,111,102, 116,119,97,114,101,0,112,97,105,110,116,46,110,101,116,32,52,46,48,46,50,49, @@ -322,9 +323,11 @@ static const char default_font_bitmap[] = 83,181,165,129,61,165,34,198,166,11,125,27,121,156,150,195,96,159,235,175,173, 240,221,188,94,243,174,123,186,222,113,245,132,198,156,239,58,47,16,111,48,78, 129,254,4,62,41,102,5,254,227,227,255,0,188,211,66,64,172,137,134,157,0,0,0,0, -73, 69, 78, 68, 174, 66, 96, 130 }; +73, 69, 78, 68, 174, 66, 96, 130 +}; -static const char* default_charset = R"( abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.!?;:-_/|\!'"+=*()[]{}&%$#@)"; +static const char* +default_charset = R"( abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.!?;:-_/|\!'"+=*()[]{}&%$#@)"; #include "libjin/jin.h" |