aboutsummaryrefslogtreecommitdiff
path: root/src/libjin
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin')
-rw-r--r--src/libjin/Common/je_exception.h22
-rw-r--r--src/libjin/Common/je_noncopyable.h24
-rw-r--r--src/libjin/Common/je_object.h16
-rw-r--r--src/libjin/Common/je_pool.hpp11
-rw-r--r--src/libjin/Common/je_temporary.h31
-rw-r--r--src/libjin/Filesystem/je_asset_database.cpp7
-rw-r--r--src/libjin/Filesystem/je_asset_database.h21
-rw-r--r--src/libjin/Filesystem/je_buffer.h7
-rw-r--r--src/libjin/Game/je_entity.cpp11
-rw-r--r--src/libjin/Game/je_entity.h31
-rw-r--r--src/libjin/Game/je_scene.cpp0
-rw-r--r--src/libjin/Game/je_scene.h4
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.cpp4
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.h4
-rw-r--r--src/libjin/Graphics/Font/je_ttf.h2
-rw-r--r--src/libjin/Graphics/Shader/je_default.shader.h2
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.cpp40
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.h12
-rw-r--r--src/libjin/Graphics/Shader/je_shader.cpp73
-rw-r--r--src/libjin/Graphics/animation/je_animation.h3
-rw-r--r--src/libjin/Graphics/animation/je_clip.h3
-rw-r--r--src/libjin/Graphics/je_bitmap.h4
-rw-r--r--src/libjin/Graphics/je_canvas.cpp10
-rw-r--r--src/libjin/Graphics/je_canvas.h4
-rw-r--r--src/libjin/Graphics/je_color.h3
-rw-r--r--src/libjin/Graphics/je_graphic.cpp (renamed from src/libjin/Graphics/je_drawable.cpp)24
-rw-r--r--src/libjin/Graphics/je_graphic.h (renamed from src/libjin/Graphics/je_drawable.h)35
-rw-r--r--src/libjin/Graphics/je_sprite.h9
-rw-r--r--src/libjin/Graphics/je_texture.cpp2
-rw-r--r--src/libjin/Graphics/je_texture.h4
-rw-r--r--src/libjin/Graphics/je_window.cpp26
-rw-r--r--src/libjin/Graphics/je_window.h12
-rw-r--r--src/libjin/Graphics/particle/je_particle.h1
-rw-r--r--src/libjin/Graphics/particle/je_particle_batch.h20
-rw-r--r--src/libjin/Graphics/particle/je_particle_emitter.cpp11
-rw-r--r--src/libjin/Graphics/particle/je_particle_emitter.h23
-rw-r--r--src/libjin/core/je_configuration.h7
37 files changed, 388 insertions, 135 deletions
diff --git a/src/libjin/Common/je_exception.h b/src/libjin/Common/je_exception.h
index e69de29..7c66af8 100644
--- a/src/libjin/Common/je_exception.h
+++ b/src/libjin/Common/je_exception.h
@@ -0,0 +1,22 @@
+#ifndef __JE_EXCEPTION_H
+#define __JE_EXCEPTION_H
+
+#include <exception>
+
+namespace JinEngine
+{
+
+ ///
+ /// Built-in exception class.
+ ///
+ class JinException : public std::exception
+ {
+ public:
+ JinException();
+ const char* what() const throw();
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_noncopyable.h b/src/libjin/Common/je_noncopyable.h
new file mode 100644
index 0000000..89a3e68
--- /dev/null
+++ b/src/libjin/Common/je_noncopyable.h
@@ -0,0 +1,24 @@
+#ifndef __JE_NONCOPYABLE_H
+#define __JE_NONCOPYABLE_H
+
+namespace JinEngine
+{
+
+ ///
+ /// Class inherites this could not be copied.
+ ///
+ class Noncopyable
+ {
+ public:
+ Noncopyable(void) { }
+ virtual ~Noncopyable(void) { }
+
+ private:
+ Noncopyable(const Noncopyable& other);
+ Noncopyable& operator=(const Noncopyable& other);
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h
new file mode 100644
index 0000000..c256879
--- /dev/null
+++ b/src/libjin/Common/je_object.h
@@ -0,0 +1,16 @@
+#ifndef __JE_OBJECT_H
+#define __JE_OBJECT_H
+
+namespace JinEngine
+{
+
+ ///
+ /// Base class of all objects in Jin.
+ ///
+ class Object
+ {
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_pool.hpp b/src/libjin/Common/je_pool.hpp
new file mode 100644
index 0000000..1107fd5
--- /dev/null
+++ b/src/libjin/Common/je_pool.hpp
@@ -0,0 +1,11 @@
+#ifndef __JE_POOL_H
+#define __JE_POOL_H
+
+namespace JinEngine
+{
+
+
+
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_temporary.h b/src/libjin/Common/je_temporary.h
new file mode 100644
index 0000000..5af8704
--- /dev/null
+++ b/src/libjin/Common/je_temporary.h
@@ -0,0 +1,31 @@
+#ifndef __JE_ON_STACK_H
+#define __JE_ON_STACK_H
+
+namespace JinEngine
+{
+
+ ///
+ /// Class inherites this clound only be created on stack or static zone.
+ ///
+ class Temporary
+ {
+ public:
+ Temporary() {};
+ virtual ~Temporary() {};
+/*
+ protected:
+ void operator delete(void* t)
+ {
+ if(t != nullptr)
+ free(t);
+ }
+*/
+ private:
+ // Disable new operands.
+ void* operator new(size_t);
+
+ };
+
+} // namespace JinEngine
+
+#endif \ 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 738b18f..ac547f0 100644
--- a/src/libjin/Filesystem/je_asset_database.cpp
+++ b/src/libjin/Filesystem/je_asset_database.cpp
@@ -46,7 +46,7 @@ namespace JinEngine
Buffer* read(const char* path)
{
-
+ return nullptr;
}
void* AssetDatabase::read(const char* path, unsigned int* len)
@@ -74,6 +74,11 @@ namespace JinEngine
return smtexists(mSmt, path) == 0;
}
+ std::vector<std::string> AssetDatabase::getFiles(const char* path, bool recursive)
+ {
+
+ }
+
} // namespace Filesystem
} // namespace JinEngine
diff --git a/src/libjin/Filesystem/je_asset_database.h b/src/libjin/Filesystem/je_asset_database.h
index 3d47f15..8c30fc1 100644
--- a/src/libjin/Filesystem/je_asset_database.h
+++ b/src/libjin/Filesystem/je_asset_database.h
@@ -4,6 +4,8 @@
#include "../core/je_configuration.h"
#if defined(jin_filesystem)
+#include <vector>
+
#include "../3rdparty/smount/smount.h"
#include "je_buffer.h"
@@ -32,6 +34,13 @@ namespace JinEngine
AssetDatabase();
///
+ /// Set asset root folder.
+ ///
+ /// @param root Root folder of assets.
+ ///
+ void mount(const char* root);
+
+ ///
/// Check if the path is directory.
///
/// @param path Path under asset folder.
@@ -73,11 +82,13 @@ namespace JinEngine
void* read(const char* path, unsigned int* length);
///
- /// Set asset root folder.
- ///
- /// @param root Root folder of assets.
+ /// Get files under given directory.
+ ///
+ /// @param path Path of directory.
+ /// @param recursive Recursivily search folder.
+ /// @return File list under given directory.
///
- void mount(const char* root);
+ std::vector<std::string> getFiles(const char* path, bool recursive);
///
/// Get full path of asset.
@@ -89,7 +100,9 @@ namespace JinEngine
private:
static AssetDatabase* mAssetDatabase;
+#if jin_filesystem == jin_filesystem_smount
smtShared* mSmt;
+#endif
};
diff --git a/src/libjin/Filesystem/je_buffer.h b/src/libjin/Filesystem/je_buffer.h
index a2f4deb..0726e1d 100644
--- a/src/libjin/Filesystem/je_buffer.h
+++ b/src/libjin/Filesystem/je_buffer.h
@@ -7,6 +7,7 @@
#include <string.h>
#include <stdlib.h>
+#include "../common/je_temporary.h"
#include "../common/je_types.h"
namespace JinEngine
@@ -17,7 +18,7 @@ namespace JinEngine
///
/// Data buffer allocated on heap.
///
- class Buffer
+ class Buffer : public Temporary
{
public:
///
@@ -158,10 +159,6 @@ namespace JinEngine
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.cpp b/src/libjin/Game/je_entity.cpp
new file mode 100644
index 0000000..1396518
--- /dev/null
+++ b/src/libjin/Game/je_entity.cpp
@@ -0,0 +1,11 @@
+#include "je_entity.h"
+
+namespace JinEngine
+{
+ namespace Game
+ {
+
+
+
+ } // namespace Game
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Game/je_entity.h b/src/libjin/Game/je_entity.h
index 41a3c10..4a252da 100644
--- a/src/libjin/Game/je_entity.h
+++ b/src/libjin/Game/je_entity.h
@@ -4,9 +4,11 @@
#include "../core/je_configuration.h"
#if defined(jin_game)
+#include <list>
#include <map>
#include <set>
+#include "../common/je_object.h"
#include "../common/je_types.h"
namespace JinEngine
@@ -17,24 +19,41 @@ namespace JinEngine
///
/// Game object base class.
///
- class Entity
+ class Entity : public Object
{
public:
+
+ ///
+ ///
+ ///
virtual ~Entity();
+ ///
+ ///
+ ///
void lifecycle();
+ ///
+ ///
+ ///
+ void setVisible(bool isVisible);
+
+ ///
+ ///
+ ///
+ void setActive(bool isActive);
+
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;
+ uint32 layer; // layer where entity belongs
+ uint32 index; // render index in layer
+ uint64 tag; // tag of entity, 64 now
+ bool mIsVisible; // if the entity is visible or not
+ bool mIsActive; // if the entity is joined into the logic
};
diff --git a/src/libjin/Game/je_scene.cpp b/src/libjin/Game/je_scene.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Game/je_scene.cpp
diff --git a/src/libjin/Game/je_scene.h b/src/libjin/Game/je_scene.h
index 34d4569..f510a1f 100644
--- a/src/libjin/Game/je_scene.h
+++ b/src/libjin/Game/je_scene.h
@@ -65,8 +65,8 @@ namespace JinEngine
};
- }
-}
+ } // namespace Game
+} // namespace JinEngine
#endif // jin_game
diff --git a/src/libjin/Graphics/Font/je_texture_font.cpp b/src/libjin/Graphics/Font/je_texture_font.cpp
index f85a8ce..2c04815 100644
--- a/src/libjin/Graphics/Font/je_texture_font.cpp
+++ b/src/libjin/Graphics/Font/je_texture_font.cpp
@@ -245,7 +245,7 @@ namespace JinEngine
}
TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
- : Drawable(bitmap)
+ : Graphic(bitmap)
, Font(cellh)
{
TextureGlyph glyph;
@@ -266,7 +266,7 @@ namespace JinEngine
}
TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
- : Drawable(bitmap)
+ : Graphic(bitmap)
, Font(cellh)
{
TextureGlyph glyph;
diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h
index 43d92c8..6276350 100644
--- a/src/libjin/Graphics/Font/je_texture_font.h
+++ b/src/libjin/Graphics/Font/je_texture_font.h
@@ -6,7 +6,7 @@
#include "../../math/je_vector4.hpp"
-#include "../je_drawable.h"
+#include "../je_graphic.h"
#include "../je_bitmap.h"
#include "je_page.h"
@@ -22,7 +22,7 @@ namespace JinEngine
///
///
class TextureFont : public Font
- , public Drawable
+ , public Graphic
{
public:
diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h
index 7bc6934..e3d63b2 100644
--- a/src/libjin/Graphics/Font/je_ttf.h
+++ b/src/libjin/Graphics/Font/je_ttf.h
@@ -10,7 +10,7 @@
#include "../../math/je_quad.h"
#include "../je_color.h"
-#include "../je_drawable.h"
+#include "../je_graphic.h"
#include "je_page.h"
#include "je_font.h"
diff --git a/src/libjin/Graphics/Shader/je_default.shader.h b/src/libjin/Graphics/Shader/je_default.shader.h
index f0175d7..3f57c44 100644
--- a/src/libjin/Graphics/Shader/je_default.shader.h
+++ b/src/libjin/Graphics/Shader/je_default.shader.h
@@ -14,7 +14,7 @@ Vertex vert(Vertex v)
Color frag(Color col, Texture tex, Vertex v)
{
- return col;
+ return col * texel(tex, v.uv);
}
#END_FRAGMENT_SHADER
diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
index 2683969..81b14e8 100644
--- a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
+++ b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
@@ -1,16 +1,54 @@
#include "../../core/je_configuration.h"
#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+#include "../../Filesystem/je_buffer.h"
+
#include "je_jsl_compiler.h"
+using namespace std;
+using namespace JinEngine::Filesystem;
+
namespace JinEngine
{
namespace Graphics
{
+#include "je_base.shader.h"
+ bool JSLCompiler::compile(const string& jsl, string* vertex_shader, string* fragment_shader)
+ {
+ // parse shader source, need some optimizations
+ int loc_VERTEX_SHADER = jsl.find("#VERTEX_SHADER");
+ int loc_END_VERTEX_SHADER = jsl.find("#END_VERTEX_SHADER");
+ int loc_FRAGMENT_SHADER = jsl.find("#FRAGMENT_SHADER");
+ int loc_END_FRAGMENT_SHADER = jsl.find("#END_FRAGMENT_SHADER");
+ if (loc_VERTEX_SHADER == string::npos
+ || loc_END_VERTEX_SHADER == string::npos
+ || loc_FRAGMENT_SHADER == string::npos
+ || loc_END_FRAGMENT_SHADER == string::npos
+ )
+ return false;
+ // Load vertex and fragment shader source into buffers.
+ {
+ // Compile JSL vertex program.
+ int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER");
+ *vertex_shader = jsl.substr(start, loc_END_VERTEX_SHADER - start);
+ Buffer vbuffer = Buffer(vertex_shader->length() + BASE_VERTEX_SHADER_SIZE);
+ formatVertexShader((char*)&vbuffer, vertex_shader->c_str());
+ vertex_shader->assign((char*)&vbuffer);
+ }
+ {
+ // Compile JSL fragment program.
+ int start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER");
+ *fragment_shader = jsl.substr(start, loc_END_FRAGMENT_SHADER - start);
+ Buffer fbuffer = Buffer(fragment_shader->length() + BASE_FRAGMENT_SHADER_SIZE);
+ formatFragmentShader((char*)&fbuffer, fragment_shader->c_str());
+ fragment_shader->assign((char*)&fbuffer);
+ }
+ return true;
+ }
} // namespace Graphics
-} // namespace JinEngine
+} // namespace JinEngine
#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ 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
index 1817a7b..29129e1 100644
--- a/src/libjin/Graphics/Shader/je_jsl_compiler.h
+++ b/src/libjin/Graphics/Shader/je_jsl_compiler.h
@@ -4,6 +4,8 @@
#include "../../core/je_configuration.h"
#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+#include <string>
+
#include "../../common/je_singleton.hpp"
namespace JinEngine
@@ -17,7 +19,15 @@ namespace JinEngine
class JSLCompiler : public Singleton<JSLCompiler>
{
public:
-
+ ///
+ /// Compile JSL shader source into GLSL.
+ ///
+ /// @param jsl JSL shader source.
+ /// @param glsl_vertex Output of vertex glsl shader source.
+ /// @param glsl_fragment Output of fragment glsl shader source.
+ /// @return True if compile successful, otherwise return false.
+ ///
+ bool compile(const std::string& jsl, std::string* glsl_vertex, std::string* glsl_fragment);
private:
singleton(JSLCompiler);
diff --git a/src/libjin/Graphics/Shader/je_shader.cpp b/src/libjin/Graphics/Shader/je_shader.cpp
index 6c8076a..b0e7506 100644
--- a/src/libjin/Graphics/Shader/je_shader.cpp
+++ b/src/libjin/Graphics/Shader/je_shader.cpp
@@ -6,6 +6,7 @@
#include "../../filesystem/je_buffer.h"
#include "../../utils/je_macros.h"
+#include "je_jsl_compiler.h"
#include "je_shader.h"
namespace JinEngine
@@ -13,8 +14,8 @@ namespace JinEngine
namespace Graphics
{
+ using namespace std;
using namespace JinEngine::Filesystem;
- using namespace std;
//
// default_texture
@@ -82,49 +83,39 @@ namespace JinEngine
bool Shader::compile(const string& program)
{
- // parse shader source, need some optimizations
- int loc_VERTEX_SHADER = program.find("#VERTEX_SHADER");
- int loc_END_VERTEX_SHADER = program.find("#END_VERTEX_SHADER");
- int loc_FRAGMENT_SHADER = program.find("#FRAGMENT_SHADER");
- int loc_END_FRAGMENT_SHADER = program.find("#END_FRAGMENT_SHADER");
- if (loc_VERTEX_SHADER == string::npos
- || loc_END_VERTEX_SHADER == string::npos
- || loc_FRAGMENT_SHADER == string::npos
- || loc_END_FRAGMENT_SHADER == string::npos
- )
- return false;
- // load vertex and fragment shader source into buffers
- 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, 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, fragment_shader.c_str());
- // compile
- GLint success;
- GLuint vshader = glCreateShader(GL_VERTEX_SHADER);
- 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);
- _data = &fbuffer;
- glShaderSource(fshader, 1, (const GLchar**)&_data, NULL);
- glCompileShader(fshader);
- glGetShaderiv(fshader, GL_COMPILE_STATUS, &success);
- if (success == GL_FALSE)
- return false;
+ string vertex_shader, fragment_shader;
+ // Compile JSL shader source into GLSL shader source.
+ JSLCompiler* compiler = JSLCompiler::get();
+ if (!compiler->compile(program, &vertex_shader, &fragment_shader))
+ {
+ return false;
+ }
+#define glsl(SHADER_MODE, SHADER, SRC) \
+do{ \
+const GLchar* src = SRC.c_str(); \
+glShaderSource(SHADER, 1, &src, NULL); \
+glCompileShader(SHADER); \
+GLint success; \
+glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \
+if (success == GL_FALSE) \
+ return false; \
+}while(0)
+ // Compile vertex shader.
+ GLuint vid = glCreateShader(GL_VERTEX_SHADER);
+ glsl(GL_VERTEX_SHADER, vid, vertex_shader);
+ // Compile fragment shader.
+ GLuint fid = glCreateShader(GL_FRAGMENT_SHADER);
+ glsl(GL_FRAGMENT_SHADER, fid, fragment_shader);
+#undef glsl
+ // Create OpenGL shader program.
mPID = glCreateProgram();
- glAttachShader(mPID, vshader);
- glAttachShader(mPID, fshader);
+ glAttachShader(mPID, vid);
+ glAttachShader(mPID, fid);
glLinkProgram(mPID);
+ GLint success;
glGetProgramiv(mPID, GL_LINK_STATUS, &success);
if (success == GL_FALSE)
- throw false;
+ return false;
}
static inline GLint getMaxTextureUnits()
@@ -133,7 +124,7 @@ namespace JinEngine
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
return maxTextureUnits;
}
-
+
void Shader::use()
{
glUseProgram(mPID);
diff --git a/src/libjin/Graphics/animation/je_animation.h b/src/libjin/Graphics/animation/je_animation.h
index c006f83..f330a0c 100644
--- a/src/libjin/Graphics/animation/je_animation.h
+++ b/src/libjin/Graphics/animation/je_animation.h
@@ -6,6 +6,9 @@ namespace JinEngine
namespace Graphics
{
+ ///
+ ///
+ ///
class Animation
{
diff --git a/src/libjin/Graphics/animation/je_clip.h b/src/libjin/Graphics/animation/je_clip.h
index 35a35b3..d6709dc 100644
--- a/src/libjin/Graphics/animation/je_clip.h
+++ b/src/libjin/Graphics/animation/je_clip.h
@@ -6,6 +6,9 @@ namespace JinEngine
namespace Graphics
{
+ ///
+ /// Animation clip with key.
+ ///
class Clip
{
diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h
index 445bf91..ae97d0d 100644
--- a/src/libjin/Graphics/je_bitmap.h
+++ b/src/libjin/Graphics/je_bitmap.h
@@ -13,11 +13,11 @@ namespace JinEngine
{
namespace Graphics
{
+
///
/// A RGBA32 bitmap.
///
- /// A bitmap keeps pixels and can't render directly onto screen. To render bitmap,
- /// a texture is required. A texture is create from specific bitmap.
+ /// A bitmap keeps pixels and can't draw directly onto screen. To render bitmap, a texture is required.
///
class Bitmap
{
diff --git a/src/libjin/Graphics/je_canvas.cpp b/src/libjin/Graphics/je_canvas.cpp
index 6406e5f..3841206 100644
--- a/src/libjin/Graphics/je_canvas.cpp
+++ b/src/libjin/Graphics/je_canvas.cpp
@@ -24,16 +24,16 @@ namespace JinEngine
}
Canvas::Canvas(int w, int h)
- : Drawable(w, h)
+ : Graphic(w, h)
{
GLint current_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
- // generate a new render buffer object
+ // Generate a new render buffer object
fbo = gl.genFrameBuffer();
gl.bindFrameBuffer(fbo);
- // generate texture save target
+ // Generate texture save target
mTexture = gl.genTexture();
gl.bindTexture(mTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -44,7 +44,7 @@ namespace JinEngine
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
- /* unbind framebuffer */
+ // Unbind framebuffer
gl.bindFrameBuffer(current_fbo);
}
@@ -67,7 +67,7 @@ namespace JinEngine
gl.bindFrameBuffer(canvas->fbo);
int w = canvas->mSize.w;
int h = canvas->mSize.h;
- /* set view port to canvas */
+ // Set view port to canvas.
glViewport(0, 0, w, h);
gl.ProjectionMatrix.setOrtho(0, w, 0, h, -1, 1);
}
diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h
index a4c0330..f39b0de 100644
--- a/src/libjin/Graphics/je_canvas.h
+++ b/src/libjin/Graphics/je_canvas.h
@@ -3,7 +3,7 @@
#include "../core/je_configuration.h"
#if defined(jin_graphics)
-#include "je_drawable.h"
+#include "je_graphic.h"
namespace JinEngine
{
@@ -14,7 +14,7 @@ namespace JinEngine
///
/// A canvas is a rendering target.
///
- class Canvas: public Drawable
+ class Canvas: public Graphic
{
public:
///
diff --git a/src/libjin/Graphics/je_color.h b/src/libjin/Graphics/je_color.h
index 80c1e4d..8fe7691 100644
--- a/src/libjin/Graphics/je_color.h
+++ b/src/libjin/Graphics/je_color.h
@@ -6,6 +6,7 @@
#include "../core/je_configuration.h"
#if defined(jin_graphics)
+#include "../common/je_types.h"
#include "../utils/je_endian.h"
namespace JinEngine
@@ -13,7 +14,7 @@ namespace JinEngine
namespace Graphics
{
- typedef unsigned char Channel;
+ typedef uint8 Channel;
class Color
{
diff --git a/src/libjin/Graphics/je_drawable.cpp b/src/libjin/Graphics/je_graphic.cpp
index 7480a32..831e409 100644
--- a/src/libjin/Graphics/je_drawable.cpp
+++ b/src/libjin/Graphics/je_graphic.cpp
@@ -6,17 +6,16 @@
#include "../math/je_matrix.h"
#include "shader/je_shader.h"
-#include "je_drawable.h"
+#include "je_graphic.h"
namespace JinEngine
{
namespace Graphics
{
- Drawable::Drawable(int w, int h)
+ Graphic::Graphic(int w, int h)
: mTexture(0)
, mSize(w, h)
- , mOrigin(0, 0)
{
mVertexCoords[0] = 0; mVertexCoords[1] = 0;
mVertexCoords[2] = 0; mVertexCoords[3] = h;
@@ -29,9 +28,8 @@ namespace JinEngine
mTextureCoords[6] = 1; mTextureCoords[7] = 0;
}
- Drawable::Drawable(const Bitmap* bitmap)
+ Graphic::Graphic(const Bitmap* bitmap)
: mTexture(0)
- , mOrigin(0, 0)
{
uint32 w = mSize.w = bitmap->getWidth();
uint32 h = mSize.h = bitmap->getHeight();
@@ -56,20 +54,14 @@ namespace JinEngine
gl.bindTexture(0);
}
- Drawable::~Drawable()
+ Graphic::~Graphic()
{
glDeleteTextures(1, &mTexture);
}
- void Drawable::setOrigin(int x, int y)
+ void Graphic::draw(int x, int y, float sx, float sy, float r, float ox, float oy)
{
- 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, mOrigin.x, mOrigin.y);
+ gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy);
Shader* shader = Shader::getCurrentShader();
shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
@@ -82,7 +74,7 @@ namespace JinEngine
gl.bindTexture(0);
}
- void Drawable::draw(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
+ void Graphic::draw(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
{
float vertCoords[8] = {
0, 0,
@@ -114,7 +106,7 @@ namespace JinEngine
gl.bindTexture(0);
}
- //void Drawable::setFilter(GLint min, GLint max)
+ //void Graphic::setFilter(GLint min, GLint max)
//{
// glTexParameteri(GL_)
//}
diff --git a/src/libjin/Graphics/je_drawable.h b/src/libjin/Graphics/je_graphic.h
index fdf9ea2..d7e3254 100644
--- a/src/libjin/Graphics/je_drawable.h
+++ b/src/libjin/Graphics/je_graphic.h
@@ -13,36 +13,39 @@ namespace JinEngine
{
namespace Graphics
{
+
+ //
+ // Graphic
+ // |-Texture
+ // |-Canvas
+ //
+
///
- ///
- ///
- class Drawable
+ /// Class inherites Graphic doesn't keep any state such as origin, scale and other
+ /// properties.
+ ///
+ class Graphic
{
public:
///
///
///
- Drawable(int w = 0, int h = 0);
+ Graphic(int w = 0, int h = 0);
///
///
///
- Drawable(const Bitmap* bitmap);
+ Graphic(const Bitmap* bitmap);
///
///
///
- virtual ~Drawable();
-
- ///
- ///
- ///
- void setOrigin(int x, int y);
+ virtual ~Graphic();
///
///
///
- void draw(int x, int y, float sx = 1, float sy = 1, float r = 0);
+ void draw(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
///
///
@@ -73,9 +76,11 @@ namespace JinEngine
static const int DRAWABLE_V_SIZE = 8;
GLuint mTexture;
- GLuint mVBO;
- JinEngine::Math::Vector2<unsigned int> mSize;
- JinEngine::Math::Vector2<int> mOrigin;
+
+ // Size of drawable thing.
+ JinEngine::Math::Vector2<uint> mSize;
+
+ // Screen coordinates and uv coordinates.
float mVertexCoords[DRAWABLE_V_SIZE];
float mTextureCoords[DRAWABLE_V_SIZE];
diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h
index 4273240..3b96162 100644
--- a/src/libjin/Graphics/je_sprite.h
+++ b/src/libjin/Graphics/je_sprite.h
@@ -17,11 +17,16 @@ namespace JinEngine
class Sprite
{
public:
+ void setOrigin(float x, float y);
+ void setPosition(int x, int y);
+ void setScale(float x, float y);
+ void setColor(Color color);
+ void setShader(const Shader* shader);
private:
Math::Vector2<int> mPosition;
- Math::Vector2<int> mOrigin;
- Math::Vector2<int> mScale;
+ Math::Vector2<float> mOrigin;
+ Math::Vector2<float> mScale;
Color mColor;
const Shader* mShader;
diff --git a/src/libjin/Graphics/je_texture.cpp b/src/libjin/Graphics/je_texture.cpp
index d191c8b..8aa3f9a 100644
--- a/src/libjin/Graphics/je_texture.cpp
+++ b/src/libjin/Graphics/je_texture.cpp
@@ -30,7 +30,7 @@ namespace JinEngine
}
Texture::Texture(const Bitmap* bitmap)
- : Drawable(bitmap)
+ : Graphic(bitmap)
{
}
diff --git a/src/libjin/Graphics/je_texture.h b/src/libjin/Graphics/je_texture.h
index 5238aa1..ddc8cfc 100644
--- a/src/libjin/Graphics/je_texture.h
+++ b/src/libjin/Graphics/je_texture.h
@@ -6,7 +6,7 @@
#include "../3rdparty/GLee/GLee.h"
#include "je_color.h"
-#include "je_drawable.h"
+#include "je_graphic.h"
#include "je_bitmap.h"
namespace JinEngine
@@ -17,7 +17,7 @@ namespace JinEngine
///
///
///
- class Texture: public Drawable
+ class Texture: public Graphic
{
public:
///
diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp
index 8c36c85..f0b789e 100644
--- a/src/libjin/Graphics/je_window.cpp
+++ b/src/libjin/Graphics/je_window.cpp
@@ -27,15 +27,15 @@ namespace JinEngine
return false;
const Setting* setting = (Setting*)s;
- size.w = setting->width;
- size.h = setting->height;
- fps = setting->fps;
+ mSize.w = setting->width;
+ mSize.h = setting->height;
+ mFps = setting->fps;
bool vsync = setting->vsync;
const char* title = setting->title;
- if (wnd)
+ if (mWnd)
{
- SDL_DestroyWindow(wnd);
+ SDL_DestroyWindow(mWnd);
SDL_FlushEvent(SDL_WINDOWEVENT);
}
@@ -62,14 +62,14 @@ namespace JinEngine
if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
- wnd = SDL_CreateWindow(title, wx, wy, size.w, size.h, flag);
- if (wnd == NULL)
+ mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag);
+ if (mWnd == NULL)
return false;
- ctx = SDL_GL_CreateContext(wnd);
+ ctx = SDL_GL_CreateContext(mWnd);
if (ctx == NULL)
return false;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
- SDL_GL_MakeCurrent(wnd, ctx);
+ SDL_GL_MakeCurrent(mWnd, ctx);
// default configuration
gl.setClearColor(0, 0, 0, 0xff);
gl.pushColor(0xff, 0xff, 0xff, 0xff);
@@ -90,19 +90,19 @@ namespace JinEngine
gl.disable(GL_BLEND);
gl.disable(GL_TEXTURE_2D);
// close window
- SDL_DestroyWindow(wnd);
+ SDL_DestroyWindow(mWnd);
SDL_Quit();
}
void Window::swapBuffers()
{
- if (wnd)
- SDL_GL_SwapWindow(wnd);
+ if (mWnd)
+ SDL_GL_SwapWindow(mWnd);
}
void Window::setTitle(const char* title)
{
- SDL_SetWindowTitle(wnd, title);
+ SDL_SetWindowTitle(mWnd, title);
};
} // namespace Graphics
diff --git a/src/libjin/Graphics/je_window.h b/src/libjin/Graphics/je_window.h
index 0969a36..7ca1e5e 100644
--- a/src/libjin/Graphics/je_window.h
+++ b/src/libjin/Graphics/je_window.h
@@ -41,17 +41,17 @@ namespace JinEngine
///
///
///
- inline int getW(){ return size.w; }
+ inline int getW(){ return mSize.w; }
///
///
///
- inline int getH(){ return size.h; }
+ inline int getH(){ return mSize.h; }
///
///
///
- inline int getFPS(){ return fps; }
+ inline int getFPS(){ return mFps; }
///
///
@@ -83,9 +83,9 @@ namespace JinEngine
///
void quitSystem() override;
- SDL_Window* wnd;
- JinEngine::Math::Vector2<unsigned int> size;
- int fps;
+ SDL_Window* mWnd;
+ JinEngine::Math::Vector2<unsigned int> mSize;
+ int mFps;
};
diff --git a/src/libjin/Graphics/particle/je_particle.h b/src/libjin/Graphics/particle/je_particle.h
index ba4dd18..2a5c54f 100644
--- a/src/libjin/Graphics/particle/je_particle.h
+++ b/src/libjin/Graphics/particle/je_particle.h
@@ -11,6 +11,7 @@ namespace JinEngine
///
class Particle
{
+
};
diff --git a/src/libjin/Graphics/particle/je_particle_batch.h b/src/libjin/Graphics/particle/je_particle_batch.h
index e69de29..19f4ded 100644
--- a/src/libjin/Graphics/particle/je_particle_batch.h
+++ b/src/libjin/Graphics/particle/je_particle_batch.h
@@ -0,0 +1,20 @@
+#ifndef __JE_PARTICLE_BATCH_H
+#define __JE_PARTICLE_BATCH_H
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ ///
+ ///
+ class ParticleBatch
+ {
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_emitter.cpp b/src/libjin/Graphics/particle/je_particle_emitter.cpp
index e69de29..d57d5ed 100644
--- a/src/libjin/Graphics/particle/je_particle_emitter.cpp
+++ b/src/libjin/Graphics/particle/je_particle_emitter.cpp
@@ -0,0 +1,11 @@
+#include "je_particle_emitter.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+
+
+ }
+}
diff --git a/src/libjin/Graphics/particle/je_particle_emitter.h b/src/libjin/Graphics/particle/je_particle_emitter.h
index e69de29..e191e36 100644
--- a/src/libjin/Graphics/particle/je_particle_emitter.h
+++ b/src/libjin/Graphics/particle/je_particle_emitter.h
@@ -0,0 +1,23 @@
+#ifndef __JE_PARTICLE_EMMITTER_H
+#define __JE_PARTICLE_EMMITTER_H
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// Particle emitter
+ ///
+ class ParticleEmitter
+ {
+ public:
+
+ private:
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/core/je_configuration.h b/src/libjin/core/je_configuration.h
index 167ffd0..34c3a74 100644
--- a/src/libjin/core/je_configuration.h
+++ b/src/libjin/core/je_configuration.h
@@ -1,6 +1,8 @@
#ifndef __JE_COMMON_MODULES_H
#define __JE_COMMON_MODULES_H
+#define jin_undefined 0x00
+
#define jin_debug
#define jin_os_windows 0x01
@@ -18,14 +20,13 @@
#define jin_audio_openal 0x02
#define jin_audio jin_audio_sdl
-#define jin_filesystem
+#define jin_filesystem_smount 0x01
+#define jin_filesystem jin_filesystem_smount
#define jin_game
#define jin_core
-#define jin_filesystem
-
#define jin_input_sdl 0x01
#define jin_input jin_input_sdl