generated from rpuzonas/raylib-cpp-template
Compare commits
2 Commits
cc0a7dfc9e
...
97396e87f6
Author | SHA1 | Date | |
---|---|---|---|
97396e87f6 | |||
842db1db65 |
@ -102,15 +102,8 @@ void UpdateDrawFrame() {
|
|||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
|
|
||||||
RPROF_START("Update");
|
RPROF_START("Update");
|
||||||
#ifdef PLATFORM_WEB
|
// TODO: Account for large 'dt' whenever a user switches to another tab and comes back in 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
|
|
||||||
world_update(&g_app.world, dt);
|
world_update(&g_app.world, dt);
|
||||||
#endif
|
|
||||||
visuals_update(&g_app.world, &g_app.visuals);
|
visuals_update(&g_app.world, &g_app.visuals);
|
||||||
RPROF_STOP();
|
RPROF_STOP();
|
||||||
|
|
||||||
|
@ -38,26 +38,6 @@
|
|||||||
background-color: black;
|
background-color: black;
|
||||||
}
|
}
|
||||||
</style>
|
</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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
|
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
|
||||||
|
33
src/ui.cpp
33
src/ui.cpp
@ -34,14 +34,9 @@ static Rectangle next_in_layout(VerticalLayout *layout, float width, float heigh
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ui_draw(World *world, Visuals *visuals, UI *ui) {
|
static void ui_draw_control_panel(World *world, Visuals *visuals, UI *ui, Rectangle rect) {
|
||||||
if (!ui->show_panel) {
|
float panel_height = rect.height;
|
||||||
ui->show_panel = GuiButton({ 20, 20, 30, 30 }, GuiIconText(ICON_PENCIL_BIG, ""));
|
ui->show_panel = !GuiWindowBox(rect, "Control panel");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float panel_height = 315;
|
|
||||||
ui->show_panel = !GuiWindowBox({ 20, 20, 660, panel_height }, "Control panel");
|
|
||||||
|
|
||||||
float group_height = panel_height - 45;
|
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);
|
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");
|
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
|
// 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), "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);
|
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_width = GetScreenWidth();
|
||||||
float window_height = GetScreenHeight();
|
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());
|
snprintf(boid_label, sizeof(boid_label), "%lu boids", world->boids.size());
|
||||||
DrawText(boid_label, window_width - 125, 35, 20, GREEN);
|
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);
|
DrawText("May crash sometimes", 20, window_height - 30, 20, RED);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user