add proper fnl modules to demo
This commit is contained in:
parent
9bb9fa5f5b
commit
47c4f2045c
14 changed files with 510 additions and 240 deletions
63
src/pxl8.c
63
src/pxl8.c
|
|
@ -44,8 +44,6 @@ typedef struct pxl8_state {
|
|||
pxl8_script* script;
|
||||
pxl8_ui* ui;
|
||||
|
||||
f32 current_fps;
|
||||
f32 fps_timer;
|
||||
i32 frame_count;
|
||||
u64 last_time;
|
||||
f32 time;
|
||||
|
|
@ -53,7 +51,6 @@ typedef struct pxl8_state {
|
|||
bool repl_mode;
|
||||
bool running;
|
||||
bool script_loaded;
|
||||
bool show_fps;
|
||||
char script_path[256];
|
||||
|
||||
pxl8_input_state input;
|
||||
|
|
@ -319,16 +316,8 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
|||
u64 current_time = SDL_GetTicksNS();
|
||||
f32 dt = (f32)(current_time - app->last_time) / 1000000000.0f;
|
||||
|
||||
app->frame_count++;
|
||||
app->fps_timer += dt;
|
||||
app->last_time = current_time;
|
||||
app->time += dt;
|
||||
|
||||
if (app->fps_timer >= 1.0f) {
|
||||
app->current_fps = app->frame_count / app->fps_timer;
|
||||
app->frame_count = 0;
|
||||
app->fps_timer = 0.0f;
|
||||
}
|
||||
|
||||
pxl8_script_check_reload(app->script);
|
||||
|
||||
|
|
@ -344,23 +333,24 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
|||
}
|
||||
|
||||
if (app->ui) {
|
||||
pxl8_ui_input_mousemove(app->ui, app->input.mouse_x, app->input.mouse_y);
|
||||
|
||||
pxl8_ui_frame_begin(app->ui);
|
||||
|
||||
for (i32 i = 0; i < 3; i++) {
|
||||
if (app->input.mouse_buttons[i] && app->input.mouse_buttons_pressed[i]) {
|
||||
if (app->input.mouse_buttons_pressed[i]) {
|
||||
pxl8_ui_input_mousedown(app->ui, app->input.mouse_x, app->input.mouse_y, i + 1);
|
||||
}
|
||||
if (!app->input.mouse_buttons[i]) {
|
||||
if (app->input.mouse_buttons_released[i]) {
|
||||
pxl8_ui_input_mouseup(app->ui, app->input.mouse_x, app->input.mouse_y, i + 1);
|
||||
}
|
||||
}
|
||||
pxl8_ui_input_mousemove(app->ui, app->input.mouse_x, app->input.mouse_y);
|
||||
|
||||
for (i32 key = 0; key < 256; key++) {
|
||||
if (app->input.keys_pressed[key]) {
|
||||
pxl8_ui_input_keydown(app->ui, key);
|
||||
}
|
||||
if (!app->input.keys[key] && app->input.keys_pressed[key]) {
|
||||
if (!app->input.keys_down[key] && app->input.keys_pressed[key]) {
|
||||
pxl8_ui_input_keyup(app->ui, key);
|
||||
}
|
||||
}
|
||||
|
|
@ -390,12 +380,6 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
|||
i32 render_width, render_height;
|
||||
pxl8_gfx_get_resolution_dimensions(app->resolution, &render_width, &render_height);
|
||||
|
||||
if (app->show_fps && app->current_fps > 0.0f) {
|
||||
char fps_text[32];
|
||||
SDL_snprintf(fps_text, sizeof(fps_text), "FPS: %d", (i32)(app->current_fps + 0.5f));
|
||||
pxl8_text(app->gfx, fps_text, render_width - 80, 10, 15);
|
||||
}
|
||||
|
||||
if (app->ui) {
|
||||
pxl8_ui_frame_end(app->ui);
|
||||
}
|
||||
|
|
@ -406,7 +390,9 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
|||
pxl8_gfx_present(app->gfx);
|
||||
|
||||
SDL_memset(app->input.keys_pressed, 0, sizeof(app->input.keys_pressed));
|
||||
SDL_memset(app->input.keys_released, 0, sizeof(app->input.keys_released));
|
||||
SDL_memset(app->input.mouse_buttons_pressed, 0, sizeof(app->input.mouse_buttons_pressed));
|
||||
SDL_memset(app->input.mouse_buttons_released, 0, sizeof(app->input.mouse_buttons_released));
|
||||
app->input.mouse_wheel_x = 0;
|
||||
app->input.mouse_wheel_y = 0;
|
||||
|
||||
|
|
@ -427,25 +413,23 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
|||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
|
||||
if (event->key.key == SDLK_F3) {
|
||||
app->show_fps = !app->show_fps;
|
||||
}
|
||||
|
||||
SDL_Keycode key = event->key.key;
|
||||
if (key < 256) {
|
||||
if (!app->input.keys[key]) {
|
||||
app->input.keys_pressed[key] = true;
|
||||
SDL_Scancode scancode = event->key.scancode;
|
||||
if (scancode < 256) {
|
||||
if (!app->input.keys_down[scancode]) {
|
||||
app->input.keys_pressed[scancode] = true;
|
||||
}
|
||||
app->input.keys[key] = true;
|
||||
app->input.keys_down[scancode] = true;
|
||||
app->input.keys_released[scancode] = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case SDL_EVENT_KEY_UP: {
|
||||
SDL_Keycode key = event->key.key;
|
||||
if (key < 256) {
|
||||
app->input.keys[key] = false;
|
||||
app->input.keys_pressed[key] = false;
|
||||
SDL_Scancode scancode = event->key.scancode;
|
||||
if (scancode < 256) {
|
||||
app->input.keys_down[scancode] = false;
|
||||
app->input.keys_pressed[scancode] = false;
|
||||
app->input.keys_released[scancode] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -453,10 +437,11 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
|||
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
||||
u8 button = event->button.button - 1;
|
||||
if (button < 3) {
|
||||
if (!app->input.mouse_buttons[button]) {
|
||||
if (!app->input.mouse_buttons_down[button]) {
|
||||
app->input.mouse_buttons_pressed[button] = true;
|
||||
}
|
||||
app->input.mouse_buttons[button] = true;
|
||||
app->input.mouse_buttons_down[button] = true;
|
||||
app->input.mouse_buttons_released[button] = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -464,7 +449,9 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
|||
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
||||
u8 button = event->button.button - 1;
|
||||
if (button < 3) {
|
||||
app->input.mouse_buttons[button] = false;
|
||||
app->input.mouse_buttons_down[button] = false;
|
||||
app->input.mouse_buttons_pressed[button] = false;
|
||||
app->input.mouse_buttons_released[button] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue