Compare commits

...

3 Commits

Author SHA1 Message Date
9991b991ab hud: draw title and controls 2026-03-23 03:38:57 -05:00
1b0fd6dc04 test: keyboard camera controls 2026-03-23 03:22:21 -05:00
a994e54639 main.lua: joystick hotplug 2026-03-23 03:15:07 -05:00
5 changed files with 96 additions and 31 deletions

View File

@ -14,6 +14,7 @@ CFLAGS += -fpic
CFLAGS += -I./include
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -Wno-error=unused-but-set-variable
CFLAGS += -Wno-error=unknown-pragmas -Wno-unknown-pragmas
CFLAGS += -Wno-error=unused-function
CFLAGS += -fno-strict-aliasing
ifdef READ_PACK_FILE
CFLAGS += -DREAD_PACK_FILE

View File

@ -13,7 +13,8 @@ extern "C" {
EXPORT void DECL update_keyboard(int up, int down, int left, int right,
int w, int s, int a, int d,
int t, int g, int f, int h,
int i, int k, int j, int l);
int i, int k, int j, int l,
int q, int e);
EXPORT void DECL update_mouse(int x, int y);
EXPORT void DECL update_joystick(int joystick_index,
float lx, float ly, float rx, float ry, float tl, float tr,

View File

@ -1,11 +1,17 @@
local ffi = require 'ffi'
local joysticks
function init()
joysticks = love.joystick.getJoysticks()
for i, joystick in ipairs(joysticks) do
print(i, joystick:getName())
function init_joysticks()
joysticks = {}
for i, joystick in ipairs(love.joystick.getJoysticks()) do
if joystick:isGamepad() then
table.insert(joysticks, joystick)
print(#joysticks, joystick:getName())
end
end
end
function init()
ffi.cdef[[
void load(const char * source_path);
@ -14,7 +20,8 @@ void draw();
void update_keyboard(int up, int down, int left, int right,
int w, int s, int a, int d,
int t, int g, int f, int h,
int i, int k, int j, int l);
int i, int k, int j, int l,
int q, int e);
void update_mouse(int x, int y);
void update_joystick(int joystick_index,
float lx, float ly, float rx, float ry, float tl, float tr,
@ -123,10 +130,13 @@ local update = function(time)
local k = love.keyboard.isDown("k")
local j = love.keyboard.isDown("j")
local l = love.keyboard.isDown("l")
local q = love.keyboard.isDown("q")
local e = love.keyboard.isDown("e")
test.update_keyboard(up, down, left, right,
w, s, a, d,
t, g, f, h,
i, k, j, l);
i, k, j, l,
q, e)
test.update(time)
end
@ -229,6 +239,9 @@ function love.run()
return function()
love.event.pump()
for name, a,b,c,d,e,f,g,h in love.event.poll() do
if name == "joystickadded" or name == "joystickremoved" then
init_joysticks()
end
if name == "quit" then
if c or not love.quit or not love.quit() then
return a or 0, b

View File

@ -2,11 +2,15 @@
#include <string.h>
#include "directxmath/directxmath.h"
#include "glad/gl.h"
#include "font/bitmap.h"
#include "font/outline.h"
#include "view.h"
#include "window.h"
extern font::bitmap::font * terminus_fonts;
extern font::outline::font * uncial_antiqua_fonts;
extern unsigned int empty_vertex_array_object;
extern unsigned int quad_index_buffer;
@ -80,6 +84,8 @@ namespace hud {
return y + font.desc->glyph_height;
}
static int frame = 0;
void draw()
{
static char buf[512];
@ -90,14 +96,41 @@ namespace hud {
font::bitmap::font const& ter_best = terminus_fonts[font_ix];
font::bitmap::draw_start(ter_best, empty_vertex_array_object, quad_index_buffer);
y = draw_label<float>(ter_best, buf, 10, y, "fov: ", "%.3f", view::state.fov);
y = draw_label<int>(ter_best, buf, 10, y, "font_height: ", "%d", ter_best.desc->glyph_height);
//y = draw_label<float>(ter_best, buf, 10, y, "fov: ", "%.3f", view::state.fov);
//y = draw_label<int>(ter_best, buf, 10, y, "font_height: ", "%d", ter_best.desc->glyph_height);
font::bitmap::draw_string(ter_best, "keyboard:", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, " move: w/a/s/d", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, " look: up/down/left/right", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, " elevate: q/e", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, "gamepad:", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, " move: right stick", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, " look: left stick", 10, y); y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, " elevate: trigger left/right", 10, y); y += ter_best.desc->glyph_height;
if (frame++ > 60 * 10)
return;
font::outline::draw_start(uncial_antiqua_fonts[0], empty_vertex_array_object, quad_index_buffer);
char const * title = "Technical demo: Bibliotheca";
int const title_length = strlen(title);
int title_width = 563;
int title_height = 31;
int title_x = (window::width - title_width) / 2.0;
int title_y = (window::height - title_height) / 2.0;
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
font::outline::draw_string(uncial_antiqua_fonts[0], title, title_x + 3, title_y + 3);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
font::outline::draw_string(uncial_antiqua_fonts[0], title, title_x + 0, title_y + 0);
/*
y = draw_label<float>(ter_best, buf, 10, y, "lighting.quadratic: ", "%.2f", lighting.quadratic);
y = draw_label<float>(ter_best, buf, 10, y, "lighting.linear: ", "%.2f", lighting.linear);
*/
/*
y = draw_vector(ter_best, buf, y, "eye", XMVectorSetW(view::state.eye, 0));
y = draw_vector(ter_best, buf, y, "at", XMVectorSetW(view::state.at, 0));
y = draw_vector(ter_best, buf, y, "forward", XMVectorSetW(view::state.forward, 0));
@ -105,10 +138,10 @@ namespace hud {
y = draw_label<float>(ter_best, buf, 10, y, "pitch: ", "%.4f", view::state.pitch);
y = draw_label<float>(ter_best, buf, 10, y, "frame_rate_avg: ", "%.2f", 1.0f / update_average(current_time - last_frame_time));
font::bitmap::draw_string(ter_best, "mouse:", 10, y);
y += ter_best.desc->glyph_height;
font::bitmap::draw_string(ter_best, "mouse:", 10, y); y += ter_best.desc->glyph_height;
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat4((XMFLOAT4*)mouse_position));
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat4((XMFLOAT4*)mouse_block));
*/
}
}

View File

@ -215,26 +215,6 @@ void load(const char * source_path)
flame::load_texture();
}
void update_keyboard(int up, int down, int left, int right,
int w, int s, int a, int d,
int t, int g, int f, int h,
int i, int k, int j, int l)
{
//float forward = (0.1f * up + -0.1f * down);
//float strafe = (-0.1f * left + 0.1f * right);
//view::third_person::apply_translation(forward, strafe, 0);
/*
collision_scene::update(up, down, left, right,
w, s, a, d,
t, g, f, h,
i, k, j, l);
*/
boids_scene::update(up, down, left, right,
w, s, a, d,
t, g, f, h,
i, k, j, l);
}
void check_collisions(collision::Sphere const & sphere, XMVECTOR const & direction,
collision::state & state)
{
@ -312,6 +292,43 @@ void minecraft_view_update(XMVECTOR direction)
view::state.eye = view::state.at - view::state.direction * view::at_distance;
}
void update_keyboard(int up, int down, int left, int right,
int w, int s, int a, int d,
int t, int g, int f, int h,
int i, int k, int j, int l,
int q, int e)
{
//float forward = (0.1f * up + -0.1f * down);
//float strafe = (-0.1f * left + 0.1f * right);
//view::third_person::apply_translation(forward, strafe, 0);
/*
collision_scene::update(up, down, left, right,
w, s, a, d,
t, g, f, h,
i, k, j, l);
*/
/*
boids_scene::update(up, down, left, right,
w, s, a, d,
t, g, f, h,
i, k, j, l);
*/
float forward = (w - s) * 0.5;
float strafe = (d - a) * 0.5;
float elevation = (q - e) * 0.5;
float delta_yaw = (left - right) * -0.035;
float delta_pitch = (down - up) * -0.035;
XMVECTOR direction = view::third_person::apply_transform(forward, strafe, elevation,
delta_yaw, delta_pitch);
view::apply_fov(0.01 * up + -0.01 * down);
if (true) {
minecraft_view_update(direction);
}
}
void update_joystick(int joystick_index,
float lx, float ly, float rx, float ry, float tl, float tr,
int up, int down, int left, int right,