move some files around
This commit is contained in:
parent
47c4f2045c
commit
cfe7501fe2
12 changed files with 78 additions and 49 deletions
|
|
@ -16,8 +16,8 @@
|
||||||
(var logo-sprite nil)
|
(var logo-sprite nil)
|
||||||
|
|
||||||
(global init (fn []
|
(global init (fn []
|
||||||
(pxl8.load_palette "sprites/pxl8_logo.ase")
|
(pxl8.load_palette "res/sprites/pxl8_logo.ase")
|
||||||
(set logo-sprite (pxl8.load_sprite "sprites/pxl8_logo.ase"))
|
(set logo-sprite (pxl8.load_sprite "res/sprites/pxl8_logo.ase"))
|
||||||
(set particles (pxl8.particles_new 1000))))
|
(set particles (pxl8.particles_new 1000))))
|
||||||
|
|
||||||
(global update (fn [dt]
|
(global update (fn [dt]
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
(set current-effect 8))
|
(set current-effect 8))
|
||||||
(when (pxl8.key_pressed "9")
|
(when (pxl8.key_pressed "9")
|
||||||
(set use-nes-palette (not use-nes-palette))
|
(set use-nes-palette (not use-nes-palette))
|
||||||
(local palette-path (if use-nes-palette "palettes/nes.ase" "sprites/pxl8_logo.ase"))
|
(local palette-path (if use-nes-palette "res/palettes/nes.ase" "res/sprites/pxl8_logo.ase"))
|
||||||
(pxl8.load_palette palette-path))
|
(pxl8.load_palette palette-path))
|
||||||
|
|
||||||
(case current-effect
|
(case current-effect
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
(fn init-texture []
|
(fn init-texture []
|
||||||
(when (not texture-initialized)
|
(when (not texture-initialized)
|
||||||
(pxl8.load_palette "sprites/pxl8_logo.ase")
|
(pxl8.load_palette "res/sprites/pxl8_logo.ase")
|
||||||
(set texture-id (pxl8.load_sprite "sprites/pxl8_logo.ase"))
|
(set texture-id (pxl8.load_sprite "res/sprites/pxl8_logo.ase"))
|
||||||
(pxl8.upload_atlas)
|
(pxl8.upload_atlas)
|
||||||
(set texture-initialized true)))
|
(set texture-initialized true)))
|
||||||
|
|
||||||
|
|
@ -71,37 +71,57 @@
|
||||||
(set fps-accumulator 0)
|
(set fps-accumulator 0)
|
||||||
(set fps-frame-count 0))
|
(set fps-frame-count 0))
|
||||||
|
|
||||||
(let [wheel-y (pxl8.mouse_wheel_y)
|
(let [wheel-y (pxl8.mouse_wheel_y)]
|
||||||
zoom-speed 0.5]
|
(when (and (not= wheel-y 0) (not (pxl8.ui_has_mouse_focus)))
|
||||||
(when (not= wheel-y 0)
|
(if orthographic
|
||||||
(let [forward-x (* (math.sin cam-yaw) wheel-y zoom-speed)
|
(set zoom (math.max 0.5 (math.min (- zoom (* wheel-y 0.2)) 10.0)))
|
||||||
forward-z (* (math.cos cam-yaw) wheel-y zoom-speed)]
|
(let [zoom-speed 0.5
|
||||||
(set cam-x (+ cam-x forward-x))
|
forward-x (* (math.sin cam-yaw) wheel-y zoom-speed)
|
||||||
(set cam-z (- cam-z forward-z)))))
|
forward-z (* (math.cos cam-yaw) wheel-y zoom-speed)]
|
||||||
|
(set cam-x (+ cam-x forward-x))
|
||||||
|
(set cam-z (- cam-z forward-z))))))
|
||||||
|
|
||||||
(let [move-speed 5.0
|
(let [move-speed 5.0
|
||||||
rot-speed 2.0
|
rot-speed 2.0
|
||||||
|
zoom-speed 2.0
|
||||||
forward-x (* (math.sin cam-yaw) move-speed dt)
|
forward-x (* (math.sin cam-yaw) move-speed dt)
|
||||||
forward-z (* (math.cos cam-yaw) move-speed dt)
|
forward-z (* (math.cos cam-yaw) move-speed dt)
|
||||||
right-x (* (math.cos cam-yaw) move-speed dt)
|
right-x (* (math.cos cam-yaw) move-speed dt)
|
||||||
right-z (* (- (math.sin cam-yaw)) move-speed dt)]
|
right-z (* (- (math.sin cam-yaw)) move-speed dt)]
|
||||||
|
|
||||||
(when (pxl8.key_down "w")
|
(if orthographic
|
||||||
(set cam-x (+ cam-x forward-x))
|
(do
|
||||||
(set cam-z (- cam-z forward-z)))
|
(when (pxl8.key_down "w")
|
||||||
(when (pxl8.key_down "s")
|
(set zoom (math.max 0.5 (- zoom (* zoom-speed dt)))))
|
||||||
(set cam-x (- cam-x forward-x))
|
(when (pxl8.key_down "s")
|
||||||
(set cam-z (+ cam-z forward-z)))
|
(set zoom (math.min 10.0 (+ zoom (* zoom-speed dt)))))
|
||||||
(when (pxl8.key_down "a")
|
(when (pxl8.key_down "a")
|
||||||
(set cam-x (- cam-x right-x))
|
(set cam-x (- cam-x right-x))
|
||||||
(set cam-z (- cam-z right-z)))
|
(set cam-z (- cam-z right-z)))
|
||||||
(when (pxl8.key_down "d")
|
(when (pxl8.key_down "d")
|
||||||
(set cam-x (+ cam-x right-x))
|
(set cam-x (+ cam-x right-x))
|
||||||
(set cam-z (+ cam-z right-z)))
|
(set cam-z (+ cam-z right-z)))
|
||||||
(when (pxl8.key_down "q")
|
(when (pxl8.key_down "q")
|
||||||
(set cam-y (- cam-y (* move-speed dt))))
|
(set cam-y (- cam-y (* move-speed dt))))
|
||||||
(when (pxl8.key_down "e")
|
(when (pxl8.key_down "e")
|
||||||
(set cam-y (+ cam-y (* move-speed dt))))
|
(set cam-y (+ cam-y (* move-speed dt)))))
|
||||||
|
(do
|
||||||
|
(when (pxl8.key_down "w")
|
||||||
|
(set cam-x (+ cam-x forward-x))
|
||||||
|
(set cam-z (- cam-z forward-z)))
|
||||||
|
(when (pxl8.key_down "s")
|
||||||
|
(set cam-x (- cam-x forward-x))
|
||||||
|
(set cam-z (+ cam-z forward-z)))
|
||||||
|
(when (pxl8.key_down "a")
|
||||||
|
(set cam-x (- cam-x right-x))
|
||||||
|
(set cam-z (- cam-z right-z)))
|
||||||
|
(when (pxl8.key_down "d")
|
||||||
|
(set cam-x (+ cam-x right-x))
|
||||||
|
(set cam-z (+ cam-z right-z)))
|
||||||
|
(when (pxl8.key_down "q")
|
||||||
|
(set cam-y (- cam-y (* move-speed dt))))
|
||||||
|
(when (pxl8.key_down "e")
|
||||||
|
(set cam-y (+ cam-y (* move-speed dt))))))
|
||||||
|
|
||||||
(when (pxl8.key_down "left")
|
(when (pxl8.key_down "left")
|
||||||
(set cam-yaw (- cam-yaw (* rot-speed dt))))
|
(set cam-yaw (- cam-yaw (* rot-speed dt))))
|
||||||
|
|
@ -144,7 +164,7 @@
|
||||||
(pxl8.set_wireframe wireframe)
|
(pxl8.set_wireframe wireframe)
|
||||||
|
|
||||||
(if orthographic
|
(if orthographic
|
||||||
(let [size 2.5
|
(let [size zoom
|
||||||
aspect (/ (pxl8.get_width) (pxl8.get_height))
|
aspect (/ (pxl8.get_width) (pxl8.get_height))
|
||||||
w (* size aspect)
|
w (* size aspect)
|
||||||
h size]
|
h size]
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
(fn render [state]
|
(fn render [state]
|
||||||
(var new-state {})
|
(var new-state {})
|
||||||
(when state.show-debug-ui
|
(when state.show-debug-ui
|
||||||
(let [window-h (if state.use-texture 210 180)
|
(let [window-open (pxl8.ui_window_begin "Debug Menu (F8)" 10 10 256 128)]
|
||||||
window-open (pxl8.ui_window_begin "Debug Menu (F8)" 10 10 250 window-h)]
|
|
||||||
(when window-open
|
(when window-open
|
||||||
(pxl8.ui_layout_row 1 0 0)
|
(pxl8.ui_layout_row 1 0 0)
|
||||||
(pxl8.ui_label (string.format "FPS: %.0f" (or state.fps 0)))
|
(pxl8.ui_label (string.format "FPS: %.0f" (or state.fps 0)))
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -2,6 +2,7 @@ local ffi = require("ffi")
|
||||||
local C = ffi.C
|
local C = ffi.C
|
||||||
local gfx = _pxl8_gfx
|
local gfx = _pxl8_gfx
|
||||||
local input = _pxl8_input
|
local input = _pxl8_input
|
||||||
|
local ui = _pxl8_ui
|
||||||
|
|
||||||
-- pxl8 lua api
|
-- pxl8 lua api
|
||||||
--
|
--
|
||||||
|
|
@ -369,30 +370,30 @@ function pxl8.mat4_lookat(eye, center, up)
|
||||||
return C.pxl8_mat4_lookat(eye_vec, center_vec, up_vec)
|
return C.pxl8_mat4_lookat(eye_vec, center_vec, up_vec)
|
||||||
end
|
end
|
||||||
|
|
||||||
pxl8.gfx = gfx
|
|
||||||
pxl8.input = input
|
|
||||||
pxl8.ui = _pxl8_ui
|
|
||||||
|
|
||||||
function pxl8.bounds(x, y, w, h)
|
function pxl8.bounds(x, y, w, h)
|
||||||
return ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
|
return ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_button(label)
|
function pxl8.ui_button(label)
|
||||||
return C.pxl8_ui_button(_pxl8_ui, label)
|
return C.pxl8_ui_button(ui, label)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_checkbox(label, state)
|
function pxl8.ui_checkbox(label, state)
|
||||||
local state_ptr = ffi.new("bool[1]", state)
|
local state_ptr = ffi.new("bool[1]", state)
|
||||||
local changed = C.pxl8_ui_checkbox(_pxl8_ui, label, state_ptr)
|
local changed = C.pxl8_ui_checkbox(ui, label, state_ptr)
|
||||||
return changed, state_ptr[0]
|
return changed, state_ptr[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function pxl8.ui_has_mouse_focus()
|
||||||
|
return C.pxl8_ui_has_mouse_focus(ui)
|
||||||
|
end
|
||||||
|
|
||||||
function pxl8.ui_indent(amount)
|
function pxl8.ui_indent(amount)
|
||||||
C.pxl8_ui_indent(_pxl8_ui, amount)
|
C.pxl8_ui_indent(ui, amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_label(text)
|
function pxl8.ui_label(text)
|
||||||
C.pxl8_ui_label(_pxl8_ui, text)
|
C.pxl8_ui_label(ui, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_layout_row(item_count, widths, height)
|
function pxl8.ui_layout_row(item_count, widths, height)
|
||||||
|
|
@ -402,20 +403,20 @@ function pxl8.ui_layout_row(item_count, widths, height)
|
||||||
elseif type(widths) == "number" then
|
elseif type(widths) == "number" then
|
||||||
widths_array = ffi.new("int[1]", widths)
|
widths_array = ffi.new("int[1]", widths)
|
||||||
end
|
end
|
||||||
C.pxl8_ui_layout_row(_pxl8_ui, item_count, widths_array, height)
|
C.pxl8_ui_layout_row(ui, item_count, widths_array, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_window_begin(title, x, y, w, h, options)
|
function pxl8.ui_window_begin(title, x, y, w, h, options)
|
||||||
local rect = ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
|
local rect = ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
|
||||||
return C.pxl8_ui_window_begin(_pxl8_ui, title, rect, options or 0)
|
return C.pxl8_ui_window_begin(ui, title, rect, options or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_window_end()
|
function pxl8.ui_window_end()
|
||||||
C.pxl8_ui_window_end(_pxl8_ui)
|
C.pxl8_ui_window_end(ui)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pxl8.ui_window_set_open(title, open)
|
function pxl8.ui_window_set_open(title, open)
|
||||||
C.pxl8_ui_window_set_open(_pxl8_ui, title, open)
|
C.pxl8_ui_window_set_open(ui, title, open)
|
||||||
end
|
end
|
||||||
|
|
||||||
return pxl8
|
return pxl8
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,9 @@ SDL_AppResult SDL_AppIterate(void* appstate) {
|
||||||
|
|
||||||
if (app->ui) {
|
if (app->ui) {
|
||||||
pxl8_ui_input_mousemove(app->ui, app->input.mouse_x, app->input.mouse_y);
|
pxl8_ui_input_mousemove(app->ui, app->input.mouse_x, app->input.mouse_y);
|
||||||
|
if (app->input.mouse_wheel_x != 0 || app->input.mouse_wheel_y != 0) {
|
||||||
|
pxl8_ui_input_scroll(app->ui, app->input.mouse_wheel_x * 10, -app->input.mouse_wheel_y * 10);
|
||||||
|
}
|
||||||
|
|
||||||
pxl8_ui_frame_begin(app->ui);
|
pxl8_ui_frame_begin(app->ui);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ static const char* pxl8_ffi_cdefs =
|
||||||
"void pxl8_ui_input_text(pxl8_ui* ui, const char* text);\n"
|
"void pxl8_ui_input_text(pxl8_ui* ui, const char* text);\n"
|
||||||
"bool pxl8_ui_button(pxl8_ui* ui, const char* label);\n"
|
"bool pxl8_ui_button(pxl8_ui* ui, const char* label);\n"
|
||||||
"bool pxl8_ui_checkbox(pxl8_ui* ui, const char* label, bool* state);\n"
|
"bool pxl8_ui_checkbox(pxl8_ui* ui, const char* label, bool* state);\n"
|
||||||
|
"bool pxl8_ui_has_mouse_focus(pxl8_ui* ui);\n"
|
||||||
"void pxl8_ui_indent(pxl8_ui* ui, int amount);\n"
|
"void pxl8_ui_indent(pxl8_ui* ui, int amount);\n"
|
||||||
"void pxl8_ui_label(pxl8_ui* ui, const char* text);\n"
|
"void pxl8_ui_label(pxl8_ui* ui, const char* text);\n"
|
||||||
"void pxl8_ui_layout_row(pxl8_ui* ui, int item_count, const int* widths, int height);\n"
|
"void pxl8_ui_layout_row(pxl8_ui* ui, int item_count, const int* widths, int height);\n"
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,8 @@ pxl8_ui* pxl8_ui_create(pxl8_gfx* gfx) {
|
||||||
ui->mu_ctx.style->colors[9] = (mu_Color){2, 0, 0, 255};
|
ui->mu_ctx.style->colors[9] = (mu_Color){2, 0, 0, 255};
|
||||||
ui->mu_ctx.style->colors[10] = (mu_Color){3, 0, 0, 255};
|
ui->mu_ctx.style->colors[10] = (mu_Color){3, 0, 0, 255};
|
||||||
ui->mu_ctx.style->colors[11] = (mu_Color){10, 0, 0, 255};
|
ui->mu_ctx.style->colors[11] = (mu_Color){10, 0, 0, 255};
|
||||||
ui->mu_ctx.style->colors[12] = (mu_Color){7, 0, 0, 255};
|
ui->mu_ctx.style->colors[12] = (mu_Color){1, 0, 0, 255};
|
||||||
ui->mu_ctx.style->colors[13] = (mu_Color){8, 0, 0, 255};
|
ui->mu_ctx.style->colors[13] = (mu_Color){3, 0, 0, 255};
|
||||||
|
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
@ -194,6 +194,11 @@ void pxl8_ui_input_text(pxl8_ui* ui, const char* text) {
|
||||||
mu_input_text(&ui->mu_ctx, text);
|
mu_input_text(&ui->mu_ctx, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pxl8_ui_has_mouse_focus(pxl8_ui* ui) {
|
||||||
|
if (!ui) return false;
|
||||||
|
return ui->mu_ctx.hover_root != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
bool pxl8_ui_button(pxl8_ui* ui, const char* label) {
|
bool pxl8_ui_button(pxl8_ui* ui, const char* label) {
|
||||||
if (!ui) return false;
|
if (!ui) return false;
|
||||||
return mu_button(&ui->mu_ctx, label) & MU_RES_SUBMIT;
|
return mu_button(&ui->mu_ctx, label) & MU_RES_SUBMIT;
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,10 @@ void pxl8_ui_destroy(pxl8_ui* ui);
|
||||||
void pxl8_ui_frame_begin(pxl8_ui* ui);
|
void pxl8_ui_frame_begin(pxl8_ui* ui);
|
||||||
void pxl8_ui_frame_end(pxl8_ui* ui);
|
void pxl8_ui_frame_end(pxl8_ui* ui);
|
||||||
|
|
||||||
|
bool pxl8_ui_button(pxl8_ui* ui, const char* label);
|
||||||
|
bool pxl8_ui_checkbox(pxl8_ui* ui, const char* label, bool* state);
|
||||||
|
bool pxl8_ui_has_mouse_focus(pxl8_ui* ui);
|
||||||
|
void pxl8_ui_indent(pxl8_ui* ui, i32 amount);
|
||||||
void pxl8_ui_input_keydown(pxl8_ui* ui, i32 key);
|
void pxl8_ui_input_keydown(pxl8_ui* ui, i32 key);
|
||||||
void pxl8_ui_input_keyup(pxl8_ui* ui, i32 key);
|
void pxl8_ui_input_keyup(pxl8_ui* ui, i32 key);
|
||||||
void pxl8_ui_input_mousedown(pxl8_ui* ui, i32 x, i32 y, i32 button);
|
void pxl8_ui_input_mousedown(pxl8_ui* ui, i32 x, i32 y, i32 button);
|
||||||
|
|
@ -59,10 +63,6 @@ void pxl8_ui_input_mousemove(pxl8_ui* ui, i32 x, i32 y);
|
||||||
void pxl8_ui_input_mouseup(pxl8_ui* ui, i32 x, i32 y, i32 button);
|
void pxl8_ui_input_mouseup(pxl8_ui* ui, i32 x, i32 y, i32 button);
|
||||||
void pxl8_ui_input_scroll(pxl8_ui* ui, i32 x, i32 y);
|
void pxl8_ui_input_scroll(pxl8_ui* ui, i32 x, i32 y);
|
||||||
void pxl8_ui_input_text(pxl8_ui* ui, const char* text);
|
void pxl8_ui_input_text(pxl8_ui* ui, const char* text);
|
||||||
|
|
||||||
bool pxl8_ui_button(pxl8_ui* ui, const char* label);
|
|
||||||
bool pxl8_ui_checkbox(pxl8_ui* ui, const char* label, bool* state);
|
|
||||||
void pxl8_ui_indent(pxl8_ui* ui, i32 amount);
|
|
||||||
void pxl8_ui_label(pxl8_ui* ui, const char* text);
|
void pxl8_ui_label(pxl8_ui* ui, const char* text);
|
||||||
void pxl8_ui_layout_row(pxl8_ui* ui, i32 item_count, const i32* widths, i32 height);
|
void pxl8_ui_layout_row(pxl8_ui* ui, i32 item_count, const i32* widths, i32 height);
|
||||||
i32 pxl8_ui_menu(pxl8_ui* ui, pxl8_menu_item* items, i32 item_count);
|
i32 pxl8_ui_menu(pxl8_ui* ui, pxl8_menu_item* items, i32 item_count);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue