aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libjin/3rdparty/smount/smount.c31
-rw-r--r--src/libjin/3rdparty/smount/smount.h17
-rw-r--r--src/libjin/Filesystem/Buffer.h18
-rw-r--r--src/libjin/Filesystem/Filesystem.cpp10
-rw-r--r--src/libjin/Filesystem/Filesystem.h34
-rw-r--r--src/libjin/Graphics/JSL.cpp24
-rw-r--r--src/libjin/Graphics/JSL.h19
-rw-r--r--src/lua/modules/embed/boot.lua.h8
-rw-r--r--src/lua/modules/graphics/graphics.cpp1
9 files changed, 32 insertions, 130 deletions
diff --git a/src/libjin/3rdparty/smount/smount.c b/src/libjin/3rdparty/smount/smount.c
index 2b4e9b9..6214800 100644
--- a/src/libjin/3rdparty/smount/smount.c
+++ b/src/libjin/3rdparty/smount/smount.c
@@ -44,7 +44,7 @@ smtShared* smtnewshared()
/**
* Concatenate strings together.
*/
-char *concat(const char *str, ...) {
+char* concat(const char *str, ...) {
va_list args;
const char *s;
// Get len
@@ -66,7 +66,7 @@ char *concat(const char *str, ...) {
return res;
}
-static int isdir(const char *path) {
+static int isdir(const char* path) {
struct stat s;
int res = stat(path, &s);
return S_ISDIR(s.st_mode);
@@ -75,12 +75,8 @@ static int isdir(const char *path) {
int smtmount(smtShared* S, const char *path)
{
if (!isdir(path))
- {
return SMT_INVALIDMOUNT;
- }
-
S->mount = smtnewpath(PATH_DIR, path, 0);
-
return SMT_SUCCESS;
}
@@ -132,33 +128,22 @@ const char* smterrstr(int e)
{
switch (e)
{
- case SMT_INVALIDMOUNT: return "invalid mount directory";
- default: return "unknown error";
+ case SMT_INVALIDMOUNT: return "invalid mount directory";
+ default: return "unknown error";
}
}
void *smtread(smtShared* S, const char *path, unsigned int *size)
{
- if (!smtisreg(S, path)) return 0;
- int fr = 0;
- if (size == 0)
- {
- fr = 1;
- size = (unsigned int*)malloc(sizeof(unsigned int));
- }
+ if (size == NULL) return NULL;
+ if (!smtisreg(S, path)) return NULL;
char *r = concat(S->mount->path, "/", path, NULL);
if (!r)
- {
- free(size);
return NULL;
- }
FILE *fp = fopen(r, "rb");
free(r);
if (!fp)
- {
- free(size);
return 0;
- }
/* Get file size */
fseek(fp, 0, SEEK_END);
*size = ftell(fp);
@@ -167,13 +152,13 @@ void *smtread(smtShared* S, const char *path, unsigned int *size)
char *res = (char*)malloc(*size + 1);
if (!res) return NULL;
res[*size] = '\0';
- if (fread(res, 1, *size, fp) != *size) {
+ if (fread(res, 1, *size, fp) != *size)
+ {
free(res);
fclose(fp);
return NULL;
}
fclose(fp);
- if (fr) free(size);
return res;
}
diff --git a/src/libjin/3rdparty/smount/smount.h b/src/libjin/3rdparty/smount/smount.h
index c0836a7..0f8f774 100644
--- a/src/libjin/3rdparty/smount/smount.h
+++ b/src/libjin/3rdparty/smount/smount.h
@@ -37,53 +37,38 @@ typedef struct smtShared
}smtShared;
smtShared* smtnewshared();
-
void smtcloseshared(smtShared* S);
-
/**
* Get error string with given error code.
*/
const char *smterrstr(int err);
-
/**
* Mount a sub file system.
*/
int smtmount(smtShared* S, const char *path);
-
/**
* Free mount
*/
void smtunmount(smtShared* S);
-
int smtexists(smtShared* S, const char *path);
-
/**
* Get size of a file.
*/
int smtsize(smtShared* S, const char *path);
-
/**
* Can only read files under root directory.
*/
-void *smtread(smtShared* S, const char *path, unsigned int *size);
-
+void* smtread(smtShared* S, const char *path, unsigned int *size);
int smtisdir(smtShared* S, const char *path);
-
int smtisreg(smtShared* S, const char *path);
-
/**
* List all folders and files inside current mount directory.
*/
smtPath *smtlist(smtShared*S, const char *path);
-
void smtfreelist(smtPath* S);
-
int smtwrite(smtShared* S, const char *path, const void *data, int size);
-
void smtdelete(smtShared* S, const char *path);
-
int smtmkdir(smtShared* S, const char *path);
-
char* smtfullpath(smtShared* S, const char* path);
#endif \ No newline at end of file
diff --git a/src/libjin/Filesystem/Buffer.h b/src/libjin/Filesystem/Buffer.h
index 1d72083..ad16c12 100644
--- a/src/libjin/Filesystem/Buffer.h
+++ b/src/libjin/Filesystem/Buffer.h
@@ -11,26 +11,20 @@ namespace filesystem
class Buffer
{
public:
-
- inline Buffer(): data(0), size(0)
- {
- }
-
- inline Buffer(const Buffer& src)
+ Buffer() : data(0), size(0) {}
+ Buffer(const Buffer& src)
{
delete data;
size = src.size;
data = new char[size];
memcpy(data, src.data, size);
}
-
inline Buffer(void* d, int s)
{
data = new char(size);
memcpy(data, d, size);
size = s;
}
-
inline ~Buffer()
{
size = 0;
@@ -38,16 +32,12 @@ namespace filesystem
}
public:
-
- // data position in memory
void* data;
-
- // data buffer size
unsigned int size;
};
-}
-}
+} // filesystem
+} // jin
#endif \ No newline at end of file
diff --git a/src/libjin/Filesystem/Filesystem.cpp b/src/libjin/Filesystem/Filesystem.cpp
index e9b05e3..8089c9d 100644
--- a/src/libjin/Filesystem/Filesystem.cpp
+++ b/src/libjin/Filesystem/Filesystem.cpp
@@ -20,9 +20,6 @@ namespace filesystem
return fs ? fs : (fs = new Filesystem());
}
- /**
- * r is relative path
- */
void Filesystem::mount(const char * path)
{
int err = smtmount(S, path);
@@ -33,9 +30,6 @@ namespace filesystem
}
}
- /**
- *
- */
int Filesystem::read(const char* path, Buffer* buffer)
{
buffer->data = smtread(S, path, &buffer->size);
@@ -64,5 +58,5 @@ namespace filesystem
return smtexists(S, path) == 0;
}
-}
-} \ No newline at end of file
+} // filesystem
+} // jin \ No newline at end of file
diff --git a/src/libjin/Filesystem/Filesystem.h b/src/libjin/Filesystem/Filesystem.h
index ba0fdc5..f2e39af 100644
--- a/src/libjin/Filesystem/Filesystem.h
+++ b/src/libjin/Filesystem/Filesystem.h
@@ -9,48 +9,22 @@ namespace filesystem
class Filesystem
{
public:
-
- Filesystem();
-
static Filesystem* get();
- /**
- * is a path a directroy or a single file
- */
- bool isDir(const char* path);
+ Filesystem();
- /**
- * is a path a directroy or a single file
- */
+ bool isDir(const char* path);
bool isFile(const char* path);
-
- /**
- * is path a valid path
- */
bool exists(const char* path);
-
- /**
- * read a file and return data buffer
- */
int read(const char* path, Buffer* buffer);
-
- /**
- * set root directory, can only mount once.
- */
void mount(const char* root);
-
- /**
- * convret relative path to absolute path
- */
const char* getFull(const char* path);
private:
-
static Filesystem* fs;
-
smtShared* S;
};
-}
-} \ No newline at end of file
+} // filesystem
+} // jin \ No newline at end of file
diff --git a/src/libjin/Graphics/JSL.cpp b/src/libjin/Graphics/JSL.cpp
index e22e872..1eb1357 100644
--- a/src/libjin/Graphics/JSL.cpp
+++ b/src/libjin/Graphics/JSL.cpp
@@ -33,22 +33,6 @@ void main()
JSLProgram::JSLProgram(const char* program)
: currentTextureUnit(0)
{
- initialize(program);
- }
-
- JSLProgram::~JSLProgram()
- {
- destroy();
- }
-
- inline void JSLProgram::destroy()
- {
- if (currentJSLProgram == this)
- unuse();
- }
-
- inline void JSLProgram::initialize(const char* program)
- {
char* fs = (char*)alloca(strlen(program) + strlen(base_f));
sprintf(fs, base_f, program);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
@@ -58,7 +42,13 @@ void main()
glAttachShader(pid, fragmentShader);
glLinkProgram(pid);
}
-
+
+ JSLProgram::~JSLProgram()
+ {
+ if (currentJSLProgram == this)
+ unuse();
+ }
+
static inline GLint getMaxTextureUnits()
{
GLint maxTextureUnits = 0;
diff --git a/src/libjin/Graphics/JSL.h b/src/libjin/Graphics/JSL.h
index b9198fb..a99a4c7 100644
--- a/src/libjin/Graphics/JSL.h
+++ b/src/libjin/Graphics/JSL.h
@@ -17,11 +17,9 @@ namespace graphics
class JSLProgram
{
-
public:
-
static JSLProgram* createJSLProgram(const char* program);
-
+ static inline JSLProgram* getCurrentJSL() { return currentJSLProgram; }
virtual ~JSLProgram();
inline void use()
@@ -29,7 +27,6 @@ namespace graphics
glUseProgram(pid);
currentJSLProgram = this;
}
-
static inline void unuse()
{
glUseProgram(0);
@@ -44,27 +41,15 @@ namespace graphics
void sendCanvas(const char* name, const Canvas* canvas);
void sendColor(const char* name, const color* col);
- static inline JSLProgram* getCurrentJSL()
- {
- return currentJSLProgram;
- }
-
protected:
-
- JSLProgram(const char* program);
-
static JSLProgram* currentJSLProgram;
+ JSLProgram(const char* program);
GLuint pid;
-
std::map<std::string, GLint> texturePool;
-
GLint currentTextureUnit;
GLint getTextureUnit(const std::string& name);
- inline void initialize(const char* program);
- inline void destroy();
-
};
} // graphics
diff --git a/src/lua/modules/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h
index cc71102..1638cbd 100644
--- a/src/lua/modules/embed/boot.lua.h
+++ b/src/lua/modules/embed/boot.lua.h
@@ -42,7 +42,6 @@ function jin.core.run()
local dt = 0
local previous = jin.time.second()
local current = previous
- local SECOND_PER_FRAME = 1/jin.config.fps
while jin.core.running() do
for _, e in pairs(jin.event.poll()) do
if e.type == "keydown" then
@@ -56,10 +55,11 @@ function jin.core.run()
current = jin.time.second()
dt = current - previous
call(jin.core.onUpdate, dt)
- call(jin.graphics.clear)
+ jin.graphics.clear()
call(jin.core.onDraw)
- call(jin.graphics.present)
- call(jin.time.sleep, 0.001)
+ jin.graphics.present()
+ -- sleep 1 ms
+ jin.time.sleep(0.001)
end
end
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index 92168ad..cd79211 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -173,7 +173,6 @@ namespace lua
}
else
{
- /* wrong type */
luax_typerror(L, 1, "texture or canvas");
}
return 0;