aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-07 00:27:46 +0800
committerchai <chaifix@163.com>2018-09-07 00:27:46 +0800
commit5e4a2c8fa58f30a93506c1db21aa7a9921c0affc (patch)
tree644837c30568296c311eb68b199048ad5f3b8a83 /src
parentd395ac00770e1dad6f9a2ba98ef23b8b719d0d16 (diff)
*format source code
Diffstat (limited to 'src')
-rw-r--r--src/libjin/Audio/Audio.h4
-rw-r--r--src/libjin/Audio/SDL/SDLAudio.h11
-rw-r--r--src/libjin/Audio/SDL/SDLSource.h25
-rw-r--r--src/libjin/Audio/Source.h4
-rw-r--r--src/libjin/Graphics/Bitmap.h1
-rw-r--r--src/libjin/Graphics/Canvas.h8
-rw-r--r--src/libjin/Graphics/Drawable.h3
-rw-r--r--src/libjin/Graphics/Font.h2
-rw-r--r--src/libjin/Graphics/Shader.cpp2
-rw-r--r--src/libjin/Graphics/Shader.h4
-rw-r--r--src/libjin/Graphics/Window.h1
-rw-r--r--src/libjin/Graphics/base.shader.h17
-rw-r--r--src/libjin/Net/Net.h3
-rw-r--r--src/libjin/Net/Socket.h2
-rw-r--r--src/libjin/Net/net.h3
-rw-r--r--src/libjin/Thread/Thread.h13
-rw-r--r--src/libjin/Thread/thread.h13
-rw-r--r--src/libjin/Time/Timer.h3
-rw-r--r--src/libjin/audio/audio.h4
-rw-r--r--src/libjin/audio/source.h4
-rw-r--r--src/libjin/net/net.h3
-rw-r--r--src/libjin/thread/thread.h13
22 files changed, 61 insertions, 82 deletions
diff --git a/src/libjin/Audio/Audio.h b/src/libjin/Audio/Audio.h
index 255f88b..674020e 100644
--- a/src/libjin/Audio/Audio.h
+++ b/src/libjin/Audio/Audio.h
@@ -18,9 +18,7 @@ namespace audio
template<class SubAudio>
class Audio : public Subsystem<SubAudio>
{
-
public:
-
enum State
{
PLAY ,
@@ -35,7 +33,6 @@ namespace audio
virtual void setVolume(float volume) = 0;
protected:
-
Audio()
: volume(1)
, state(State::PLAY)
@@ -45,6 +42,7 @@ namespace audio
float volume;
State state;
+
};
} // audio
diff --git a/src/libjin/Audio/SDL/SDLAudio.h b/src/libjin/Audio/SDL/SDLAudio.h
index a8067ba..b43dcfe 100644
--- a/src/libjin/Audio/SDL/SDLAudio.h
+++ b/src/libjin/Audio/SDL/SDLAudio.h
@@ -18,9 +18,7 @@ namespace audio
class SDLAudio : public Audio<SDLAudio>
{
-
public:
-
struct Setting : SettingBase
{
public:
@@ -34,23 +32,20 @@ namespace audio
void pause() override;
void resume() override;
void setVolume(float volume) override;
-
/* process functions*/
void processCommands();
void processSources(void* buffer, size_t len);
void processBuffer(void* buffer, size_t len);
bool goOnProcess();
-
+ /* thread-safe */
void lock();
void unlock();
private:
-
+ SINGLETON(SDLAudio);
SDLAudio() {};
~SDLAudio() {};
-
- SINGLETON(SDLAudio);
-
+ /* subsystem interface */
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
diff --git a/src/libjin/Audio/SDL/SDLSource.h b/src/libjin/Audio/SDL/SDLSource.h
index c45d7e5..a99f65e 100644
--- a/src/libjin/Audio/SDL/SDLSource.h
+++ b/src/libjin/Audio/SDL/SDLSource.h
@@ -20,14 +20,11 @@ namespace audio
class SDLSource : public Source
{
-
public:
-
- ~SDLSource();
-
static SDLSource* createSource(const char* file);
static SDLSource* createSource(void* mem, size_t size);
+ ~SDLSource();
/* ISource interface */
void play() override;
void stop() override;
@@ -37,25 +34,22 @@ namespace audio
bool isStopped() const override;
bool isPaused() const override;
void setPitch(float pitch) override;
- // Ͻ
void setVolume(float volume) override;
bool setLoop(bool loop) override;
void setRate(float rate) override;
-
+ /* handle and process anduio clip */
inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd);
inline void process(void* buffer, size_t size);
protected:
-
SDLSource();
-
+ /* decode raw audio data */
void decode_wav(void* mem, int size);
void decode_ogg(void* mem, int size);
-
+ /* check state */
inline bool is(int state) const { return (status.state & state) == state; }
- struct
- {
+ struct{
const void* data; // Ƶ
int length; // dataֽڳ
const void* end; // dataβ = (unsigned char*)data + size
@@ -64,10 +58,8 @@ namespace audio
int samples; // sample = size / (bitdepth / 8)
unsigned char channels; // channel1(mono)2(stereo)
} raw;
-
/* Procedure controller variable */
- struct
- {
+ struct{
int pos; // ǰŵsample
int pitch; // pitch
int state; // ǰ״̬
@@ -79,15 +71,13 @@ namespace audio
class SDLSourceManager
{
-
public:
-
static SDLSourceManager* get();
/* Process function */
void processCommands();
void processSources(void* buffer, size_t size);
-
+ /* control flow */
void removeAllSource();
void removeSource(SDLSource* source);
void pushSource(SDLSource* source);
@@ -95,7 +85,6 @@ namespace audio
void pushCommand(SDLSourceCommand* cmd);
private :
-
std::queue<SDLSourceCommand*> commands;
std::stack<SDLSourceCommand*> commandsPool;
std::vector<SDLSource*> sources; // processing sources
diff --git a/src/libjin/Audio/Source.h b/src/libjin/Audio/Source.h
index 70d6fae..b8cfb83 100644
--- a/src/libjin/Audio/Source.h
+++ b/src/libjin/Audio/Source.h
@@ -19,12 +19,9 @@ namespace audio
class Source
{
-
public:
-
Source() {};
virtual ~Source() {};
-
/* interface */
virtual void play() = 0;
virtual void stop() = 0;
@@ -39,7 +36,6 @@ namespace audio
virtual void setRate(float rate) = 0;
protected:
-
static SourceType getType(const void* mem, int size);
};
diff --git a/src/libjin/Graphics/Bitmap.h b/src/libjin/Graphics/Bitmap.h
index d050c43..464ca7f 100644
--- a/src/libjin/Graphics/Bitmap.h
+++ b/src/libjin/Graphics/Bitmap.h
@@ -18,7 +18,6 @@ namespace graphics
static Bitmap* createBitmap(int w, int h);
~Bitmap();
-
void bindPixels(Color* pixels, int w, int h);
void setPixels(Color* pixels, int w, int h);
void setPixel(const Color& pixel, int x, int y);
diff --git a/src/libjin/Graphics/Canvas.h b/src/libjin/Graphics/Canvas.h
index b5cf8a2..3b0a40a 100644
--- a/src/libjin/Graphics/Canvas.h
+++ b/src/libjin/Graphics/Canvas.h
@@ -13,12 +13,12 @@ namespace graphics
{
public:
static Canvas* createCanvas(int w, int h);
- ~Canvas();
-
- void bind();
static void unbind();
- static bool hasbind(GLint fbo);
+ static bool hasbind(GLint fbo);
+ ~Canvas();
+ void bind();
+
protected:
Canvas(int w, int h);
diff --git a/src/libjin/Graphics/Drawable.h b/src/libjin/Graphics/Drawable.h
index b3fc565..bdec5b4 100644
--- a/src/libjin/Graphics/Drawable.h
+++ b/src/libjin/Graphics/Drawable.h
@@ -16,7 +16,6 @@ namespace graphics
public:
Drawable(int w = 0, int h = 0);
virtual ~Drawable();
-
void setAnchor(int x, int y);
void draw(int x, int y, float sx, float sy, float r);
inline int getWidth() const { return size.x; }
@@ -28,7 +27,7 @@ namespace graphics
GLuint texture;
/* TODO: vertex buffer object */
- GLuint vbo;
+ /* GLuint vbo; */
jin::math::Vector2<unsigned int> size;
jin::math::Vector2<int> anchor;
float vertCoord[DRAWABLE_V_SIZE];
diff --git a/src/libjin/Graphics/Font.h b/src/libjin/Graphics/Font.h
index 5311c96..d805d1c 100644
--- a/src/libjin/Graphics/Font.h
+++ b/src/libjin/Graphics/Font.h
@@ -16,10 +16,8 @@ namespace graphics
{
public:
Font();
-
void loadFile(const char* file);
void loadMemory(const unsigned char* data);
-
void render(
const char* text, // rendered text
float x, float y, // render position
diff --git a/src/libjin/Graphics/Shader.cpp b/src/libjin/Graphics/Shader.cpp
index 1af861f..13e259d 100644
--- a/src/libjin/Graphics/Shader.cpp
+++ b/src/libjin/Graphics/Shader.cpp
@@ -45,7 +45,7 @@ namespace graphics
JSLProgram::JSLProgram(const char* program)
: currentTextureUnit(DEFAULT_TEX_UNIT)
{
- char* fs = (char*)calloc(1, strlen(program) + base_size);
+ char* fs = (char*)calloc(1, strlen(program) + SHADER_FORMAT_SIZE);
formatShader(fs, program);
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shader, 1, (const GLchar**)&fs, NULL);
diff --git a/src/libjin/Graphics/Shader.h b/src/libjin/Graphics/Shader.h
index 0356dd5..ad484db 100644
--- a/src/libjin/Graphics/Shader.h
+++ b/src/libjin/Graphics/Shader.h
@@ -35,12 +35,12 @@ namespace graphics
void sendColor(const char* name, const Color* col);
protected:
+ static JSLProgram* currentJSLProgram;
+
GLint claimTextureUnit(const std::string& name);
JSLProgram(const char* program);
void bindDefaultTexture();
- static JSLProgram* currentJSLProgram;
-
GLuint pid;
GLint currentTextureUnit;
std::map<std::string, GLint> textureUnits;
diff --git a/src/libjin/Graphics/Window.h b/src/libjin/Graphics/Window.h
index 09ec6dd..22033ee 100644
--- a/src/libjin/Graphics/Window.h
+++ b/src/libjin/Graphics/Window.h
@@ -37,7 +37,6 @@ namespace graphics
SINGLETON(Window);
Window() {};
virtual ~Window() {};
-
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
diff --git a/src/libjin/Graphics/base.shader.h b/src/libjin/Graphics/base.shader.h
index 0b8eca9..067a60b 100644
--- a/src/libjin/Graphics/base.shader.h
+++ b/src/libjin/Graphics/base.shader.h
@@ -1,3 +1,9 @@
+/*
+ * https://stackoverflow.com/questions/10868958/what-does-sampler2d-store
+ * The sampler2D is bound to a texture unit. The glUniform call binds it to texture
+ * unit zero. The glActiveTexture call is only needed if you are going to use multiple
+ * texture units (because GL_TEXTURE0 is the default anyway).
+*/
static const char* default_tex = "_tex0_";
@@ -21,13 +27,8 @@ void main()
gl_FragColor = effect(gl_Color, %s, gl_TexCoord[0].xy, gl_FragCoord.xy);
}
)";
+
+static const int SHADER_FORMAT_SIZE = strlen(base_shader) + strlen(default_tex) * 2;
+
#define formatShader(buf, program)\
sprintf(buf, base_shader, default_tex, program, default_tex)
-
-#define base_size (strlen(base_shader) + strlen(default_tex)*2)
-/*
- * https://stackoverflow.com/questions/10868958/what-does-sampler2d-store
- * The sampler2D is bound to a texture unit. The glUniform call binds it to texture
- * unit zero. The glActiveTexture call is only needed if you are going to use multiple
- * texture units (because GL_TEXTURE0 is the default anyway).
-*/ \ No newline at end of file
diff --git a/src/libjin/Net/Net.h b/src/libjin/Net/Net.h
index b10f5f2..5ca658b 100644
--- a/src/libjin/Net/Net.h
+++ b/src/libjin/Net/Net.h
@@ -16,11 +16,12 @@ namespace net
public:
protected:
+ SINGLETON(Net);
Net() {};
~Net() {};
- SINGLETON(Net);
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
+
};
} // net
diff --git a/src/libjin/Net/Socket.h b/src/libjin/Net/Socket.h
index 6d9e09b..5329974 100644
--- a/src/libjin/Net/Socket.h
+++ b/src/libjin/Net/Socket.h
@@ -33,7 +33,6 @@ namespace net
Socket(SocketType type, unsigned int address, unsigned short port);
Socket(SocketType type, const char* address, unsigned short port);
~Socket();
-
void configureBlocking(bool bocking);
Socket* accept();
int receive(char* buffer, int size);
@@ -53,6 +52,7 @@ namespace net
} handle;
#endif
SocketType type;
+
};
} // net
diff --git a/src/libjin/Net/net.h b/src/libjin/Net/net.h
index b10f5f2..5ca658b 100644
--- a/src/libjin/Net/net.h
+++ b/src/libjin/Net/net.h
@@ -16,11 +16,12 @@ namespace net
public:
protected:
+ SINGLETON(Net);
Net() {};
~Net() {};
- SINGLETON(Net);
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
+
};
} // net
diff --git a/src/libjin/Thread/Thread.h b/src/libjin/Thread/Thread.h
index 046c8f6..3300b4f 100644
--- a/src/libjin/Thread/Thread.h
+++ b/src/libjin/Thread/Thread.h
@@ -78,26 +78,29 @@ namespace thread
class ThreadData
{
public:
+ static const int SLOT_ERROR = -1;
+ static const int SLOT_WARN = -2;
+ static const int SLOT_INFO = -3;
+ static const int SLOT_DEBUG = -4;
+
ThreadData(Mutex*, Conditional*);
~ThreadData();
bool exist(int slot);
void set(int slot, Variant value);
Variant get(int slot);
void remove(int slot);
+
Conditional* condition;
Mutex* mutex;
- static const int SLOT_ERROR = -1;
- static const int SLOT_WARN = -2;
- static const int SLOT_INFO = -3;
- static const int SLOT_DEBUG = -4;
-
private:
std::map<int, Variant> share; // threads shared value
+
};
public:
typedef int(*ThreadRunner)(void* obj);
+
Thread(const std::string name, ThreadRunner threadfuncs);
~Thread();
bool start(void* p);
diff --git a/src/libjin/Thread/thread.h b/src/libjin/Thread/thread.h
index 046c8f6..3300b4f 100644
--- a/src/libjin/Thread/thread.h
+++ b/src/libjin/Thread/thread.h
@@ -78,26 +78,29 @@ namespace thread
class ThreadData
{
public:
+ static const int SLOT_ERROR = -1;
+ static const int SLOT_WARN = -2;
+ static const int SLOT_INFO = -3;
+ static const int SLOT_DEBUG = -4;
+
ThreadData(Mutex*, Conditional*);
~ThreadData();
bool exist(int slot);
void set(int slot, Variant value);
Variant get(int slot);
void remove(int slot);
+
Conditional* condition;
Mutex* mutex;
- static const int SLOT_ERROR = -1;
- static const int SLOT_WARN = -2;
- static const int SLOT_INFO = -3;
- static const int SLOT_DEBUG = -4;
-
private:
std::map<int, Variant> share; // threads shared value
+
};
public:
typedef int(*ThreadRunner)(void* obj);
+
Thread(const std::string name, ThreadRunner threadfuncs);
~Thread();
bool start(void* p);
diff --git a/src/libjin/Time/Timer.h b/src/libjin/Time/Timer.h
index 173cd95..401e3c5 100644
--- a/src/libjin/Time/Timer.h
+++ b/src/libjin/Time/Timer.h
@@ -18,9 +18,7 @@ namespace time
Timers();
~Timers();
-
void update(int ms);
-
void every(int ms, timer_callback callback, void* paramters);
void after(int ms, timer_callback callback, void* paramters);
void repeat(int ms, int count, timer_callback callback, void* paramters);
@@ -48,6 +46,7 @@ namespace time
void* paramters;
};
std::vector<Timer*> timers;
+
};
inline void sleep(int ms)
diff --git a/src/libjin/audio/audio.h b/src/libjin/audio/audio.h
index 255f88b..674020e 100644
--- a/src/libjin/audio/audio.h
+++ b/src/libjin/audio/audio.h
@@ -18,9 +18,7 @@ namespace audio
template<class SubAudio>
class Audio : public Subsystem<SubAudio>
{
-
public:
-
enum State
{
PLAY ,
@@ -35,7 +33,6 @@ namespace audio
virtual void setVolume(float volume) = 0;
protected:
-
Audio()
: volume(1)
, state(State::PLAY)
@@ -45,6 +42,7 @@ namespace audio
float volume;
State state;
+
};
} // audio
diff --git a/src/libjin/audio/source.h b/src/libjin/audio/source.h
index 70d6fae..b8cfb83 100644
--- a/src/libjin/audio/source.h
+++ b/src/libjin/audio/source.h
@@ -19,12 +19,9 @@ namespace audio
class Source
{
-
public:
-
Source() {};
virtual ~Source() {};
-
/* interface */
virtual void play() = 0;
virtual void stop() = 0;
@@ -39,7 +36,6 @@ namespace audio
virtual void setRate(float rate) = 0;
protected:
-
static SourceType getType(const void* mem, int size);
};
diff --git a/src/libjin/net/net.h b/src/libjin/net/net.h
index b10f5f2..5ca658b 100644
--- a/src/libjin/net/net.h
+++ b/src/libjin/net/net.h
@@ -16,11 +16,12 @@ namespace net
public:
protected:
+ SINGLETON(Net);
Net() {};
~Net() {};
- SINGLETON(Net);
bool initSystem(const SettingBase* setting) override;
void quitSystem() override;
+
};
} // net
diff --git a/src/libjin/thread/thread.h b/src/libjin/thread/thread.h
index 046c8f6..3300b4f 100644
--- a/src/libjin/thread/thread.h
+++ b/src/libjin/thread/thread.h
@@ -78,26 +78,29 @@ namespace thread
class ThreadData
{
public:
+ static const int SLOT_ERROR = -1;
+ static const int SLOT_WARN = -2;
+ static const int SLOT_INFO = -3;
+ static const int SLOT_DEBUG = -4;
+
ThreadData(Mutex*, Conditional*);
~ThreadData();
bool exist(int slot);
void set(int slot, Variant value);
Variant get(int slot);
void remove(int slot);
+
Conditional* condition;
Mutex* mutex;
- static const int SLOT_ERROR = -1;
- static const int SLOT_WARN = -2;
- static const int SLOT_INFO = -3;
- static const int SLOT_DEBUG = -4;
-
private:
std::map<int, Variant> share; // threads shared value
+
};
public:
typedef int(*ThreadRunner)(void* obj);
+
Thread(const std::string name, ThreadRunner threadfuncs);
~Thread();
bool start(void* p);