fix html5 build + add a new HTML5 demo
parent
2d56c302b8
commit
d93c8febbe
|
@ -1,4 +1,4 @@
|
||||||
if "%1"=="" MAKE.bat demo_collide.c
|
if "%1"=="" MAKE.bat demo_ddraw.c
|
||||||
|
|
||||||
del index.html 2>NUL >NUL
|
del index.html 2>NUL >NUL
|
||||||
del index.worker.js 2>NUL >NUL
|
del index.worker.js 2>NUL >NUL
|
||||||
|
@ -19,5 +19,5 @@ rem cook art
|
||||||
|
|
||||||
rem host webserver, compile and launch
|
rem host webserver, compile and launch
|
||||||
rem start python -m http.server --bind 127.0.0.1 8000
|
rem start python -m http.server --bind 127.0.0.1 8000
|
||||||
call emcc %* -g ..\..\engine\v4k.c -I..\..\engine -o index.html -pthread -s FULL_ES3 -s USE_PTHREADS -s USE_GLFW=3 -s SINGLE_FILE=1 -s PRECISE_F32=1 -s TOTAL_MEMORY=256mb -s ENVIRONMENT=worker,web --shell-file template.html -Wfatal-errors --preload-file .art[00].zip@index.zip -lidbfs.js
|
call emcc %* -g ..\..\engine\v4k.c -I..\..\engine -o index.html -pthread -s FULL_ES3 -s USE_PTHREADS -s USE_GLFW=3 -s SINGLE_FILE=1 -s PRECISE_F32=1 -s TOTAL_MEMORY=256mb -s ALLOW_MEMORY_GROWTH=1 -s ENVIRONMENT=worker,web --shell-file template.html -Wfatal-errors --preload-file .art[00].zip@index.zip -lidbfs.js
|
||||||
rem emrun index.html
|
rem emrun index.html
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
#include "v4k.h"
|
||||||
|
|
||||||
|
// -- demo
|
||||||
|
|
||||||
|
int paused;
|
||||||
|
camera_t cam;
|
||||||
|
skybox_t sky;
|
||||||
|
bool do_boids_demo = 1;
|
||||||
|
bool do_colliders_demo = 1;
|
||||||
|
bool do_debugdraw_demo = 1;
|
||||||
|
|
||||||
|
void game_loop(void *userdata) {
|
||||||
|
// fps camera
|
||||||
|
profile("FPS camera") {
|
||||||
|
if( input(GAMEPAD_CONNECTED) ) {
|
||||||
|
vec2 filtered_lpad = input_filter_deadzone(input2(GAMEPAD_LPAD), 0.15f/*do_gamepad_deadzone*/ + 1e-3 );
|
||||||
|
vec2 filtered_rpad = input_filter_deadzone(input2(GAMEPAD_RPAD), 0.15f/*do_gamepad_deadzone*/ + 1e-3 );
|
||||||
|
vec2 mouse = scale2(vec2(filtered_rpad.x, filtered_rpad.y), 1.0f);
|
||||||
|
vec3 wasdec = scale3(vec3(filtered_lpad.x, input(GAMEPAD_LT) - input(GAMEPAD_RT), filtered_lpad.y), 1.0f);
|
||||||
|
camera_move(&cam, wasdec.x,wasdec.y,wasdec.z);
|
||||||
|
camera_fps(&cam, mouse.x,mouse.y);
|
||||||
|
window_cursor( true );
|
||||||
|
} else {
|
||||||
|
bool active = ui_active() || ui_hover() || gizmo_active() ? false : input(MOUSE_L) || input(MOUSE_M) || input(MOUSE_R);
|
||||||
|
if( active ) cam.speed = clampf(cam.speed + input_diff(MOUSE_W) / 10, 0.05f, 5.0f);
|
||||||
|
vec2 mouse = scale2(vec2(input_diff(MOUSE_X), -input_diff(MOUSE_Y)), 0.2f * active);
|
||||||
|
vec3 wasdecq = scale3(vec3(input(KEY_D)-input(KEY_A),input(KEY_E)-(input(KEY_C)||input(KEY_Q)),input(KEY_W)-input(KEY_S)), cam.speed);
|
||||||
|
camera_move(&cam, wasdecq.x,wasdecq.y,wasdecq.z);
|
||||||
|
camera_fps(&cam, mouse.x,mouse.y);
|
||||||
|
window_cursor( !active );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw skybox
|
||||||
|
skybox_render(&sky, cam.proj, cam.view);
|
||||||
|
|
||||||
|
// world
|
||||||
|
ddraw_grid(0);
|
||||||
|
|
||||||
|
// boids
|
||||||
|
static swarm_t sw;
|
||||||
|
if( do_boids_demo ) profile("boids") {
|
||||||
|
do_once sw = swarm();
|
||||||
|
do_once array_push(sw.steering_targets, vec3(0,0,0));
|
||||||
|
do_once for(int i = 0; i < 100; ++i)
|
||||||
|
array_push(sw.boids, boid(scale3(rnd3(),10), rnd3())); // pos,vel
|
||||||
|
|
||||||
|
// move
|
||||||
|
sw.steering_targets[0] = cam.position;
|
||||||
|
swarm_update(&sw, window_delta());
|
||||||
|
|
||||||
|
// draw
|
||||||
|
for (int j = 0, end = array_count(sw.boids); j < end; ++j) {
|
||||||
|
vec3 dir = norm3(sub3(sw.boids[j].position, sw.boids[j].prev_position));
|
||||||
|
ddraw_boid(sw.boids[j].position, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// showcase many debugdraw shapes
|
||||||
|
if( do_debugdraw_demo ) {
|
||||||
|
ddraw_demo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// showcase many colliding tests
|
||||||
|
if( do_colliders_demo ) {
|
||||||
|
collide_demo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ui
|
||||||
|
if( ui_panel("App", 0) ) {
|
||||||
|
ui_bool("Boids demo", &do_boids_demo);
|
||||||
|
ui_bool("Collide demo", &do_colliders_demo);
|
||||||
|
ui_bool("DebugDraw demo", &do_debugdraw_demo);
|
||||||
|
ui_panel_end();
|
||||||
|
}
|
||||||
|
if( ui_panel("Swarm", 0) ) {
|
||||||
|
ui_swarm(&sw);
|
||||||
|
ui_panel_end();
|
||||||
|
}
|
||||||
|
if( ui_panel("Camera", 0)) {
|
||||||
|
if( ui_float("Speed", &cam.speed) ) {}
|
||||||
|
if( ui_float3("Position", cam.position.v3) ) {}
|
||||||
|
ui_panel_end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// 75% sized, msaa x4 enabled
|
||||||
|
window_create(1, 0);
|
||||||
|
window_title( "V4K - SPACE pauses simulation" );
|
||||||
|
|
||||||
|
// fx_load("fx**.fs");
|
||||||
|
|
||||||
|
// camera that points to origin
|
||||||
|
cam = camera();
|
||||||
|
|
||||||
|
// load up skybox
|
||||||
|
sky = skybox(0, 0);
|
||||||
|
|
||||||
|
// main loop
|
||||||
|
window_loop(game_loop, NULL);
|
||||||
|
}
|
|
@ -350331,7 +350331,7 @@ int window_frame_begin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @transparent
|
// @transparent
|
||||||
static bool has_transparent_attrib = 0; do_once has_transparent_attrib = glfwGetWindowAttrib(window_handle(), GLFW_TRANSPARENT_FRAMEBUFFER) == GLFW_TRUE;
|
static bool has_transparent_attrib = 0; do_once ifdef(ems, false, has_transparent_attrib = glfwGetWindowAttrib(window_handle(), GLFW_TRANSPARENT_FRAMEBUFFER) == GLFW_TRUE);
|
||||||
if( has_transparent_attrib ) may_render_stats = 0;
|
if( has_transparent_attrib ) may_render_stats = 0;
|
||||||
// @transparent
|
// @transparent
|
||||||
|
|
||||||
|
|
|
@ -523,7 +523,7 @@ int window_frame_begin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @transparent
|
// @transparent
|
||||||
static bool has_transparent_attrib = 0; do_once has_transparent_attrib = glfwGetWindowAttrib(window_handle(), GLFW_TRANSPARENT_FRAMEBUFFER) == GLFW_TRUE;
|
static bool has_transparent_attrib = 0; do_once ifdef(ems, false, has_transparent_attrib = glfwGetWindowAttrib(window_handle(), GLFW_TRANSPARENT_FRAMEBUFFER) == GLFW_TRUE);
|
||||||
if( has_transparent_attrib ) may_render_stats = 0;
|
if( has_transparent_attrib ) may_render_stats = 0;
|
||||||
// @transparent
|
// @transparent
|
||||||
|
|
||||||
|
|
|
@ -20935,7 +20935,7 @@ int window_frame_begin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @transparent
|
// @transparent
|
||||||
static bool has_transparent_attrib = 0; do_once has_transparent_attrib = glfwGetWindowAttrib(window_handle(), GLFW_TRANSPARENT_FRAMEBUFFER) == GLFW_TRUE;
|
static bool has_transparent_attrib = 0; do_once ifdef(ems, false, has_transparent_attrib = glfwGetWindowAttrib(window_handle(), GLFW_TRANSPARENT_FRAMEBUFFER) == GLFW_TRUE);
|
||||||
if( has_transparent_attrib ) may_render_stats = 0;
|
if( has_transparent_attrib ) may_render_stats = 0;
|
||||||
// @transparent
|
// @transparent
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue