aboutsummaryrefslogtreecommitdiff
path: root/src/libjin
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin')
-rw-r--r--src/libjin/Common/Singleton.hpp3
-rw-r--r--src/libjin/Core/game.cpp74
-rw-r--r--src/libjin/Debug/Debug.h6
-rw-r--r--src/libjin/Debug/Log.h14
-rw-r--r--src/libjin/Graphics/Drawable.h1
-rw-r--r--src/libjin/Graphics/JSL.cpp29
-rw-r--r--src/libjin/Graphics/Texture.h4
-rw-r--r--src/libjin/debug/debug.h6
-rw-r--r--src/libjin/debug/log.h14
9 files changed, 93 insertions, 58 deletions
diff --git a/src/libjin/Common/Singleton.hpp b/src/libjin/Common/Singleton.hpp
index 48cd5bc..b817901 100644
--- a/src/libjin/Common/Singleton.hpp
+++ b/src/libjin/Common/Singleton.hpp
@@ -30,8 +30,7 @@ namespace jin
template<class T> T* Singleton<T>::_instance = nullptr;
-#define SINGLETON(T) \
- friend Singleton<T>
+#define SINGLETON(T) friend Singleton<T>
} // jin
diff --git a/src/libjin/Core/game.cpp b/src/libjin/Core/game.cpp
new file mode 100644
index 0000000..3f905f2
--- /dev/null
+++ b/src/libjin/Core/game.cpp
@@ -0,0 +1,74 @@
+#include "game.h"
+#include "../Time/Timer.h"
+#include "../input/Event.h"
+#include "../Graphics/Window.h"
+#include "../Math/Math.h"
+#include <iostream>
+
+namespace jin
+{
+namespace core
+{
+
+ using namespace jin::graphics;
+ using namespace jin::input;
+ using namespace jin::time;
+ using namespace jin::math;
+
+ Game::Game() :_running(true) {};
+
+ void Game::run()
+ {
+ if (_onLoad != nullptr)
+ _onLoad();
+ Window* wnd = Window::get();
+ const int FPS = wnd ? wnd->getFPS() : 60;
+ const int MS_PER_UPDATE = 1000.0f / FPS;
+ _running = true;
+ Event e;
+ int previous = getMilliSecond();
+ int dt = MS_PER_UPDATE;
+ while (_running)
+ {
+ while (jin::input::pollEvent(&e))
+ {
+ if (_onEvent != nullptr)
+ _onEvent(&e);
+ if (!_running) goto quitloop;
+ }
+ if (_onUpdate != nullptr) _onUpdate(dt);
+ if (_onDraw != nullptr) _onDraw();
+ wnd->swapBuffers();
+ const int current = getMilliSecond();
+ dt = current - previous;
+ const int wait = MS_PER_UPDATE - (current - previous);
+ previous += MS_PER_UPDATE;
+ if (wait > 0)
+ {
+ sleep(wait);
+ dt = MS_PER_UPDATE;
+ }
+ else
+ previous = current;
+ }
+ quitloop:;
+ }
+
+ bool Game::initSystem(const SettingBase* setting)
+ {
+ if (setting == nullptr)
+ return false;
+ Game::Setting* s = (Game::Setting*) setting;
+ _onEvent = s->eventHandler;
+ _onUpdate = s->updater;
+ _onDraw = s->drawer;
+ _onLoad = s->loader;
+ return true;
+ }
+
+ void Game::quitSystem()
+ {
+ }
+
+} // core
+} // jin \ No newline at end of file
diff --git a/src/libjin/Debug/Debug.h b/src/libjin/Debug/Debug.h
deleted file mode 100644
index 9fa9fe1..0000000
--- a/src/libjin/Debug/Debug.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __JIN_DEBUG_H
-#define __JIN_DEBUG_H
-
-
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Debug/Log.h b/src/libjin/Debug/Log.h
deleted file mode 100644
index e1624f5..0000000
--- a/src/libjin/Debug/Log.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __JIN_LOG_H
-#define __JIN_LOG_H
-
-namespace jin
-{
-namespace debug
-{
-
- const char* err;
-
-}
-}
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Drawable.h b/src/libjin/Graphics/Drawable.h
index e04ac6b..4e91adb 100644
--- a/src/libjin/Graphics/Drawable.h
+++ b/src/libjin/Graphics/Drawable.h
@@ -41,6 +41,7 @@ namespace graphics
void setVertices(float* v, float* t);
GLuint texture;
+ GLuint vbo;
int width, height;
diff --git a/src/libjin/Graphics/JSL.cpp b/src/libjin/Graphics/JSL.cpp
index 2ab7ceb..fb6279a 100644
--- a/src/libjin/Graphics/JSL.cpp
+++ b/src/libjin/Graphics/JSL.cpp
@@ -7,20 +7,21 @@ namespace jin
{
namespace graphics
{
- //vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
- static const char* base_f = " "
- //"#version 120 \n"
- "#define number float \n"
- "#define Image sampler2D \n"
- "#define Canvas sampler2D \n"
- "#define Color vec4 \n"
- "#define Texel texture2D \n"
- "#define extern uniform \n"
- "uniform Image _tex0_; \n"
- "%s \n"
- "void main(){ \n"
- " gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);\n"
- "}\0";
+
+ static const char* base_f = R"base_f(
+#define number float
+#define Texture sampler2D
+#define Canvas sampler2D
+#define Color vec4
+#define Texel texture2D
+#define extern uniform
+uniform Texture _tex0_;
+%s
+void main()
+{
+ gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);
+}
+ )base_f";
/*static*/ JSLProgram* JSLProgram::currentJSLProgram = nullptr;
diff --git a/src/libjin/Graphics/Texture.h b/src/libjin/Graphics/Texture.h
index 47f8d53..1e7a2f5 100644
--- a/src/libjin/Graphics/Texture.h
+++ b/src/libjin/Graphics/Texture.h
@@ -33,8 +33,8 @@ namespace graphics
};
-}
-}
+} // graphics
+} // jin
#endif // JIN_MODULES_RENDER
#endif // __JIN_IMAGE_H \ No newline at end of file
diff --git a/src/libjin/debug/debug.h b/src/libjin/debug/debug.h
deleted file mode 100644
index 9fa9fe1..0000000
--- a/src/libjin/debug/debug.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __JIN_DEBUG_H
-#define __JIN_DEBUG_H
-
-
-
-#endif \ No newline at end of file
diff --git a/src/libjin/debug/log.h b/src/libjin/debug/log.h
deleted file mode 100644
index e1624f5..0000000
--- a/src/libjin/debug/log.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __JIN_LOG_H
-#define __JIN_LOG_H
-
-namespace jin
-{
-namespace debug
-{
-
- const char* err;
-
-}
-}
-
-#endif \ No newline at end of file