mirror of
https://git.shylie.info/shylie/glerminal.git
synced 2024-12-22 14:40:05 +00:00
Compare commits
No commits in common. "e5b017ad97f380abbbbbdcb9965bc2532cd37883" and "4b740e3eddf05d51f9a60380a90be2fcd37a6ba3" have entirely different histories.
e5b017ad97
...
4b740e3edd
@ -17,7 +17,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: prev
|
||||
fetch-depth: 0
|
||||
fetch-depth: 2
|
||||
submodules: recursive
|
||||
lfs: true
|
||||
- run: cd prev && git checkout 10a90a5f6a
|
||||
|
@ -71,7 +71,7 @@ target_link_libraries(glerminal
|
||||
PRIVATE
|
||||
glerminallib
|
||||
lua_static
|
||||
)
|
||||
)
|
||||
|
||||
if (PROJECT_IS_TOP_LEVEL)
|
||||
add_subdirectory(examples examples)
|
||||
|
@ -42,5 +42,5 @@ namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glerminal_run(init, mainloop, nullptr, nullptr);
|
||||
glerminal_run(init, mainloop);
|
||||
}
|
@ -39,5 +39,5 @@ namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glerminal_run(init, mainloop, nullptr, nullptr);
|
||||
glerminal_run(init, mainloop);
|
||||
}
|
@ -83,5 +83,5 @@ namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glerminal_run(init, mainloop, nullptr, nullptr);
|
||||
glerminal_run(init, mainloop);
|
||||
}
|
@ -63,5 +63,5 @@ namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glerminal_run(init, mainloop, nullptr, nullptr);
|
||||
glerminal_run(init, mainloop);
|
||||
}
|
@ -10,16 +10,13 @@ extern "C"
|
||||
|
||||
typedef void (*glerminal_init_cb)();
|
||||
typedef void (*glerminal_main_cb)(float dt);
|
||||
typedef void (*glerminal_keys_cb)(int key);
|
||||
|
||||
/**
|
||||
* @brief Call init once, then run the application's mainloop
|
||||
* @param init initialization callback
|
||||
* @param main main calllback
|
||||
* @param pressed key pressed callback (can be null)
|
||||
* @param released key released callback (can be null)
|
||||
*/
|
||||
void glerminal_run(glerminal_init_cb init, glerminal_main_cb main, glerminal_keys_cb pressed, glerminal_keys_cb released);
|
||||
void glerminal_run(glerminal_init_cb init, glerminal_main_cb main);
|
||||
|
||||
void glerminal_quit();
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
#include <glerminal.h>
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -133,40 +131,6 @@ namespace
|
||||
lua_remove(L, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void pressed(int key)
|
||||
{
|
||||
const char* const name = glfwGetKeyName(key, 0);
|
||||
if (name)
|
||||
{
|
||||
lua_getglobal(L, "glerminal");
|
||||
lua_getfield(L, -1, "pressed");
|
||||
lua_remove(L, -2);
|
||||
lua_pushstring(L, name);
|
||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK)
|
||||
{
|
||||
// ignore error for now
|
||||
lua_remove(L, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void released(int key)
|
||||
{
|
||||
const char* const name = glfwGetKeyName(key, 0);
|
||||
if (name)
|
||||
{
|
||||
lua_getglobal(L, "glerminal");
|
||||
lua_getfield(L, -1, "released");
|
||||
lua_remove(L, -2);
|
||||
lua_pushstring(L, name);
|
||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK)
|
||||
{
|
||||
// ignore error for now
|
||||
lua_remove(L, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@ -191,7 +155,7 @@ int main(int argc, char** argv)
|
||||
|
||||
luaL_dofile(L, "main.lua");
|
||||
|
||||
glerminal_run(init, mainloop, pressed, released);
|
||||
glerminal_run(init, mainloop);
|
||||
|
||||
lua_close(L);
|
||||
|
||||
|
@ -25,7 +25,7 @@ namespace glerminal
|
||||
class glerminal
|
||||
{
|
||||
public:
|
||||
glerminal(glerminal_init_cb init, glerminal_main_cb main, glerminal_keys_cb pressed, glerminal_keys_cb released);
|
||||
glerminal(glerminal_init_cb init, glerminal_main_cb main);
|
||||
~glerminal();
|
||||
|
||||
glerminal(const glerminal&) = delete;
|
||||
@ -84,7 +84,6 @@ namespace glerminal
|
||||
|
||||
unsigned int m_sprites[CELL_SIZE * CELL_SIZE * (1 << (8 * sizeof(*m_cells)))];
|
||||
glerminal_main_cb m_main;
|
||||
glerminal_keys_cb m_pressed, m_released;
|
||||
|
||||
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
|
||||
mutable std::ofstream m_log;
|
||||
@ -100,8 +99,6 @@ namespace glerminal
|
||||
void update_sprites();
|
||||
void update_layer_colors();
|
||||
void update_layer_scales();
|
||||
|
||||
static void glfw_key_handler(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -198,10 +198,8 @@ namespace
|
||||
|
||||
namespace glerminal
|
||||
{
|
||||
glerminal::glerminal(glerminal_init_cb init, glerminal_main_cb main, glerminal_keys_cb pressed, glerminal_keys_cb released) :
|
||||
glerminal::glerminal(glerminal_init_cb init, glerminal_main_cb main) :
|
||||
m_main(main),
|
||||
m_pressed(pressed),
|
||||
m_released(released),
|
||||
m_cells{ },
|
||||
m_offsets{ },
|
||||
m_sprites{ },
|
||||
@ -239,6 +237,8 @@ namespace glerminal
|
||||
GLERMINAL_G = this;
|
||||
|
||||
init();
|
||||
|
||||
glerminal_flush();
|
||||
}
|
||||
|
||||
glerminal::~glerminal()
|
||||
@ -261,8 +261,6 @@ namespace glerminal
|
||||
m_main(current - last);
|
||||
|
||||
last = current;
|
||||
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,8 +292,6 @@ namespace glerminal
|
||||
glBlitNamedFramebuffer(m_screen_framebuffer, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
glfwSwapBuffers(m_window);
|
||||
|
||||
glBlitNamedFramebuffer(m_screen_framebuffer, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
|
||||
void glerminal::set(unsigned char x, unsigned char y, unsigned char layer, unsigned char sprite)
|
||||
@ -366,7 +362,6 @@ namespace glerminal
|
||||
{
|
||||
glfwInit();
|
||||
|
||||
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
@ -386,9 +381,6 @@ namespace glerminal
|
||||
{
|
||||
throw std::runtime_error("Failed to create glerminal window.");
|
||||
}
|
||||
|
||||
glfwSetWindowUserPointer(m_window, this);
|
||||
glfwSetKeyCallback(m_window, glerminal::glfw_key_handler);
|
||||
}
|
||||
|
||||
void glerminal::log(GLenum type, GLuint id, GLenum severity, const char* message) const
|
||||
@ -775,28 +767,13 @@ namespace glerminal
|
||||
{
|
||||
glNamedBufferData(m_layer_scales_buffer, sizeof(m_layer_scales), m_layer_scales, GL_DYNAMIC_READ);
|
||||
}
|
||||
|
||||
void glerminal::glfw_key_handler(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
glerminal* const self = static_cast<glerminal*>(glfwGetWindowUserPointer(window));
|
||||
|
||||
if (self->m_pressed && action == GLFW_PRESS)
|
||||
{
|
||||
self->m_pressed(key);
|
||||
}
|
||||
|
||||
if (self->m_released && action == GLFW_RELEASE)
|
||||
{
|
||||
self->m_released(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void glerminal_run(glerminal_init_cb init, glerminal_main_cb main, glerminal_keys_cb pressed, glerminal_keys_cb released)
|
||||
void glerminal_run(glerminal_init_cb init, glerminal_main_cb main)
|
||||
{
|
||||
try
|
||||
{
|
||||
glerminal::glerminal* g = new glerminal::glerminal(init, main, pressed, released);
|
||||
glerminal::glerminal* g = new glerminal::glerminal(init, main);
|
||||
g->run();
|
||||
delete g;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
glerminal_run(init, mainloop, nullptr, nullptr);
|
||||
glerminal_run(init, mainloop);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user