Compare commits

...

2 Commits

Author SHA1 Message Date
97396e87f6 remove unnecessary code 2023-08-15 00:08:59 +03:00
842db1db65 add controls panel 2023-08-14 23:29:49 +03:00
3 changed files with 24 additions and 38 deletions

View File

@ -102,15 +102,8 @@ void UpdateDrawFrame() {
float dt = GetFrameTime();
RPROF_START("Update");
#ifdef PLATFORM_WEB
// If user goes to another tab and comes back, the time that the user was gone needs to be ignored.
// So boids wouldn't tunnel through walls and do other shenanigans.
if (dt <= 5*TIME_PER_FRAME) {
world_update(&g_app.world, dt);
}
#else
// TODO: Account for large 'dt' whenever a user switches to another tab and comes back in web
world_update(&g_app.world, dt);
#endif
visuals_update(&g_app.world, &g_app.visuals);
RPROF_STOP();

View File

@ -38,26 +38,6 @@
background-color: black;
}
</style>
<script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js">
</script>
<script type='text/javascript'>
function saveFileFromMEMFSToDisk(memoryFSname, localFSname) // This can be called by C/C++ code
{
var isSafari = false; // Not supported, navigator.userAgent access is being restricted
//var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
var data = FS.readFile(memoryFSname);
var blob;
if (isSafari) blob = new Blob([data.buffer], { type: "application/octet-stream" });
else blob = new Blob([data.buffer], { type: "application/octet-binary" });
// NOTE: SaveAsDialog is a browser setting. For example, in Google Chrome,
// in Settings/Advanced/Downloads section you have a setting:
// 'Ask where to save each file before downloading' - which you can set true/false.
// If you enable this setting it would always ask you and bring the SaveAsDialog
saveAs(blob, localFSname);
}
</script>
</head>
<body>
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>

View File

@ -34,14 +34,9 @@ static Rectangle next_in_layout(VerticalLayout *layout, float width, float heigh
return rect;
}
static void ui_draw(World *world, Visuals *visuals, UI *ui) {
if (!ui->show_panel) {
ui->show_panel = GuiButton({ 20, 20, 30, 30 }, GuiIconText(ICON_PENCIL_BIG, ""));
return;
}
float panel_height = 315;
ui->show_panel = !GuiWindowBox({ 20, 20, 660, panel_height }, "Control panel");
static void ui_draw_control_panel(World *world, Visuals *visuals, UI *ui, Rectangle rect) {
float panel_height = rect.height;
ui->show_panel = !GuiWindowBox(rect, "Control panel");
float group_height = panel_height - 45;
@ -66,7 +61,6 @@ static void ui_draw(World *world, Visuals *visuals, UI *ui) {
GuiColorPicker(bg_color_rect, NULL, &visuals->bg_color);
GuiLabel(rect_with_offset({ 80, 10, 80, 16 }, bg_color_rect.x, bg_color_rect.y), "BG color");
// TODO: Add show FPS
// TODO: Add showing out of bounds boids
}
@ -100,6 +94,25 @@ static void ui_draw(World *world, Visuals *visuals, UI *ui) {
gui_valuebox_float(next_in_layout(&layout, 50, 15), "Separation strength", &world->separation_strength, 0, 100, &ui->separation_strength_edit);
gui_valuebox_float(next_in_layout(&layout, 50, 15), "Collision avoidance strength", &world->collision_avoidance_strength, 0, 100, &ui->collision_avoidance_strength_edit);
}
}
static void ui_draw_controls_guide(Rectangle rect) {
GuiPanel(rect, "Controls");
VerticalLayout layout = { .x = rect.x + 10, .y = rect.y + 30, .gap = 6 };
GuiLabel(next_in_layout(&layout, 250, 12), "R - reset camera view");
GuiLabel(next_in_layout(&layout, 250, 12), "Scroll middle mouse - zoom camera");
GuiLabel(next_in_layout(&layout, 250, 12), "Hold middle mouse & move - move camera");
}
static void ui_draw(World *world, Visuals *visuals, UI *ui) {
if (!ui->show_panel) {
ui->show_panel = GuiButton({ 20, 20, 30, 30 }, GuiIconText(ICON_PENCIL_BIG, ""));
return;
}
ui_draw_control_panel(world, visuals, ui, { 20, 20, 660, 315 });
ui_draw_controls_guide({ 20, 340, 275, 120 });
float window_width = GetScreenWidth();
float window_height = GetScreenHeight();
@ -109,6 +122,6 @@ static void ui_draw(World *world, Visuals *visuals, UI *ui) {
snprintf(boid_label, sizeof(boid_label), "%lu boids", world->boids.size());
DrawText(boid_label, window_width - 125, 35, 20, GREEN);
DrawText("W.I.P.", 20, window_height - 50, 20, RED);
DrawText("Beware!", 20, window_height - 50, 20, RED);
DrawText("May crash sometimes", 20, window_height - 30, 20, RED);
}