1DOLLY 72APPLICATION bhop3REQUIRES HOST runtime@04REQUIRES HOST display@05REQUIRES HOST input@06REQUIRES HOST download@07REQUIRES HOST http@08REQUIRES HOST snapshot@09REQUIRES HOST threads@010REQUIRES HOST upload@01112FROM /v0.1.2/demos/slopyard/Dollyfile-gamedev-sdk 7154125de83d4f1dcfc8e0bdfbe70c1a4636a450985bb9d63f4ca87ec1e61ec913INSTALL /v0.1.2/demos/javascript/Dollyfile-javascript fb348fa05cd708e79fe9f6b3f7603b99441fc17fe01de2253505ad9df7c239e314INSTALL /v0.1.2/demos/pi/Dollyfile-pi-coding-agent a18f9957bdb2224dbbca1ad138141ea89a4dc298fbbc2b17a7e3c4cfb6f3c30115INSTALL /v0.1.2/demos/sdl2/Dollyfile-sdl2 a6b39d45ce2763ebe31f99bb42c1784769fb9ec66752f7148cb0900d339422e116REQUIRES TOOL cc17REQUIRES TOOL make18REQUIRES TOOL c++19REQUIRES TOOL pi20REQUIRES TOOL download21REQUIRES TOOL tar22REQUIRES TOOL rm23REQUIRES HEADER cpp24REQUIRES HEADER quickjs-runner25REQUIRES HEADER sdl226REQUIRES LIB dolly-js27REQUIRES LIB SDL22829SOURCE /v0.1.2/dist/static/bhop/source.tar 545e1598c5b30df2c6c27988e2b28938d511a335be491d1a8d037d8066cdf94b /tmp/bhop-source.tar30SOURCE /v0.1.2/dist/static/default/stb_truetype.h ecd30b05e0dd4fea3a13c26810dd9e1992dc379049482c393d5a19e6b5090aab /tmp/bhop-stb/stb_truetype.h31SLOP tar -xf /tmp/bhop-source.tar -C /3233FILE /usr/src/dolly/bhop/bhop-movement.h34    #ifndef DOLLY_BHOP_MOVEMENT_H35    #define DOLLY_BHOP_MOVEMENT_H36    #include <math.h>37    #include <string.h>38    39    #define BH_STEP 0.01f40    #define BH_RADIUS 16.0f41    #define BH_HEIGHT 72.0f42    #define BH_GRAVITY 800.0f43    #define BH_RUN_SPEED 250.0f44    45    typedef struct { float low[3], high[3]; } bh_box;46    typedef struct {47      float position[3], velocity[3];48      int ground, jump_queue, jumps;49    } bh_player;50    typedef struct { float fraction, normal[3]; int box; } bh_trace;51    52    static float bh_speed(const bh_player *player) {53      return hypotf(player->velocity[0], player->velocity[2]);54    }55    56    // Original implementation of GoldSrc's projection-limited acceleration rule.57    // Only the air projection is capped at 30; the acceleration uses full wishspeed.58    static void bh_accelerate(bh_player *player, float yaw, float forward, float side, int air) {59      float length = hypotf(forward, side);60      if (length == 0) return;61      float direction[3] = {62        (sinf(yaw) * forward + cosf(yaw) * side) / length, 0,63        (-cosf(yaw) * forward + sinf(yaw) * side) / length64      };65      float projection = player->velocity[0] * direction[0] + player->velocity[2] * direction[2];66      float available = (air ? 30.0f : BH_RUN_SPEED) - projection;67      float acceleration = fminf(available, (air ? 10.0f : 5.0f) * BH_RUN_SPEED * BH_STEP);68      if (acceleration <= 0) return;69      player->velocity[0] += direction[0] * acceleration;70      player->velocity[2] += direction[2] * acceleration;71    }72    73    static bh_trace bh_sweep(const float position[3], const float delta[3],74                             const bh_box *boxes, int count) {75      bh_trace best = {.fraction = 1, .box = -1};76      for (int box = 0; box < count; ++box) {77        if (boxes[box].low[0] >= boxes[box].high[0] || boxes[box].low[1] >= boxes[box].high[1] ||78            boxes[box].low[2] >= boxes[box].high[2]) continue;79        float enter = -INFINITY, leave = INFINITY, normal[3] = {0};80        int intersects = 1;81        for (int axis = 0; axis < 3; ++axis) {82          float low = boxes[box].low[axis] - (axis == 1 ? BH_HEIGHT : BH_RADIUS);83          float high = boxes[box].high[axis] + (axis == 1 ? 0 : BH_RADIUS);84          if (fabsf(delta[axis]) < 1e-8f) {85            if (position[axis] <= low || position[axis] >= high) { intersects = 0; break; }86            continue;87          }88          float first = (low - position[axis]) / delta[axis];89          float last = (high - position[axis]) / delta[axis];90          float sign = -1;91          if (first > last) { float swap = first; first = last; last = swap; sign = 1; }92          if (first > enter) {93            enter = first;94            memset(normal, 0, sizeof(normal));95            normal[axis] = sign;96          }97          leave = fminf(leave, last);98          if (enter > leave) { intersects = 0; break; }99        }100        if (intersects && enter >= 0 && enter < best.fraction && leave >= 0) {101          best.fraction = enter;102          best.box = box;103          memcpy(best.normal, normal, sizeof(normal));104        }105      }106      return best;107    }108    109    static void bh_slide(bh_player *player, const bh_box *boxes, int count) {110      float remaining = BH_STEP;111      for (int bump = 0; bump < 4 && remaining > 0; ++bump) {112        float delta[3];113        for (int axis = 0; axis < 3; ++axis) delta[axis] = player->velocity[axis] * remaining;114        bh_trace hit = bh_sweep(player->position, delta, boxes, count);115        for (int axis = 0; axis < 3; ++axis)116          player->position[axis] += delta[axis] * hit.fraction + hit.normal[axis] * 0.01f;117        if (hit.box < 0) break;118        remaining *= 1 - hit.fraction;119        float inward = 0;120        for (int axis = 0; axis < 3; ++axis) inward += player->velocity[axis] * hit.normal[axis];121        if (inward < 0) for (int axis = 0; axis < 3; ++axis)122          player->velocity[axis] -= inward * hit.normal[axis];123      }124    }125    126    static void bh_ground(bh_player *player, const bh_box *boxes, int count) {127      player->ground = -1;128      if (player->velocity[1] > 0) return;129      const float down[3] = {0, -2, 0};130      bh_trace floor = bh_sweep(player->position, down, boxes, count);131      if (floor.box >= 0 && floor.normal[1] > 0.7f) {132        player->position[1] -= 2 * floor.fraction - 0.01f;133        player->velocity[1] = 0;134        player->ground = floor.box;135      }136    }137    138    static void bh_tick(bh_player *player, float yaw, float forward, float side,139                        const bh_box *boxes, int count) {140      bh_ground(player, boxes, count);141      if (player->jump_queue > 0 && player->ground >= 0) {142        player->velocity[1] = sqrtf(2 * BH_GRAVITY * 45);143        player->ground = -1;144        player->jump_queue = 0;145        ++player->jumps;146      }147      if (player->jump_queue > 0) --player->jump_queue;148      if (player->ground >= 0) {149        float speed = bh_speed(player);150        if (speed > 0) {151          float retained = fmaxf(0, speed - fmaxf(75, speed) * 4 * BH_STEP) / speed;152          player->velocity[0] *= retained;153          player->velocity[2] *= retained;154        }155      }156      bh_accelerate(player, yaw, forward, side, player->ground < 0);157      if (player->ground >= 0 && bh_speed(player) > BH_RUN_SPEED) {158        float scale = BH_RUN_SPEED / bh_speed(player);159        player->velocity[0] *= scale;160        player->velocity[2] *= scale;161      }162      player->velocity[1] -= BH_GRAVITY * BH_STEP / 2;163      bh_slide(player, boxes, count);164      player->velocity[1] -= BH_GRAVITY * BH_STEP / 2;165      bh_ground(player, boxes, count);166    }167    #endif168169FILE /usr/src/dolly/bhop/bhop-course.h170    #ifndef DOLLY_BHOP_COURSE_H171    #define DOLLY_BHOP_COURSE_H172    #include "bhop-movement.h"173    174    enum { BH_PADS = 33, BH_PAD_DELAY = 10, BH_PAD_RETURN = 200 };175    typedef struct {176      bh_box pads[BH_PADS];177      int cooldown[BH_PADS], collapses;178    } bh_course;179    180    static int bh_checkpoint(int pad) { return pad >= 0 && pad < BH_PADS && pad % 8 == 0; }181    static void bh_course_init(bh_course *course) {182      const float x[BH_PADS] = {0, 0, 48, 110, 160, 180, 140, 70, 0,183        -60, -130, -180, -160, -100, -20, 60, 120,184        180, 220, 190, 120, 40, -40, -120, -180,185        -200, -150, -80, 0, 80, 150, 190, 180};186      const float top[BH_PADS] = {0, 0, 0, 16, 16, 32, 32, 48, 48,187        32, 16, 0, -16, -16, 0, 0, 0,188        0, 16, 16, 32, 32, 48, 48, 64,189        64, 80, 80, 96, 96, 112, 112, 128};190      memset(course, 0, sizeof(*course));191      float z = 0;192      for (int i = 0; i < BH_PADS; ++i) {193        int section = i ? (i - 1) / 8 : 0;194        if (i) z -= i == 1 ? 400 : 220 + section * 10;195        float width = i == 0 ? 512 : bh_checkpoint(i) ? 224 : 88 - section * 8;196        float depth = bh_checkpoint(i) ? (i == 0 ? 512 : 256) : width;197        course->pads[i] = (bh_box){{x[i] - width / 2, top[i] - 32, z - depth / 2},198          {x[i] + width / 2, top[i], z + depth / 2}};199      }200    }201    static void bh_course_tick(bh_course *course, bh_player *player, float yaw, float forward, float side) {202      bh_box solid[BH_PADS];203      memcpy(solid, course->pads, sizeof(solid));204      for (int i = 0; i < BH_PADS; ++i) {205        if (course->cooldown[i] && --course->cooldown[i] == BH_PAD_RETURN) ++course->collapses;206        if (course->cooldown[i] > 0 && course->cooldown[i] <= BH_PAD_RETURN)207          solid[i].high[1] = solid[i].low[1];208      }209      bh_tick(player, yaw, forward, side, solid, BH_PADS);210      int pad = player->ground;211      if (pad >= 0 && !bh_checkpoint(pad) && !course->cooldown[pad])212        course->cooldown[pad] = BH_PAD_DELAY + BH_PAD_RETURN;213    }214    #endif215216FILE /usr/src/dolly/bhop/bhop-check.c217    #include "bhop-course.h"218    #include <stdio.h>219    220    #define CHECK(condition) do { if (!(condition)) { \221      fprintf(stderr, "bhop movement check failed at line %d: %s\n", __LINE__, #condition); return 1; \222    } } while (0)223    224    int main(void) {225      bh_player player = {.velocity = {0, 0, -300}};226      bh_accelerate(&player, 0, 1, 0, 1);227      CHECK(player.velocity[2] == -300);228      bh_accelerate(&player, 0, 0, 1, 1);229      CHECK(player.velocity[0] == 25 && player.velocity[2] == -300);230      bh_accelerate(&player, 0, 0, 1, 1);231      CHECK(player.velocity[0] == 30 && bh_speed(&player) > 300);232      player = (bh_player){0};233      bh_accelerate(&player, 0, 1, 1, 1);234      CHECK(fabsf(bh_speed(&player) - 25) < 0.001f);235    236      bh_player strafe = {.velocity = {0, 0, -300}}, held = strafe;237      for (int tick = 0; tick < 100; ++tick) {238        float yaw = atan2f(strafe.velocity[2], strafe.velocity[0]) + acosf(5 / bh_speed(&strafe));239        bh_accelerate(&strafe, yaw, 0, 1, 1);240        bh_accelerate(&held, 0, 0, 1, 1);241      }242      CHECK(bh_speed(&strafe) > 420 && bh_speed(&held) < 302);243      printf("bhop: synchronized strafe %.3f u/s; fixed-direction strafe %.3f u/s\n",244        bh_speed(&strafe), bh_speed(&held));245    246      const bh_box floor = {{-10000, -100, -10000}, {10000, 0, 10000}};247      player = (bh_player){.position = {0, 0.01f, 0}, .velocity = {100, 0, 0}};248      bh_tick(&player, 0, 0, 0, &floor, 1);249      CHECK(fabsf(player.velocity[0] - 96) < 0.001f && player.ground == 0);250      player = (bh_player){.position = {0, 0.01f, 0}, .velocity = {600, 0, 0}, .jump_queue = 2};251      float peak = 0;252      for (int tick = 0; tick < 65; ++tick) {253        bh_tick(&player, 0, 0, 0, &floor, 1);254        peak = fmaxf(peak, player.position[1]);255        CHECK(fabsf(player.velocity[0] - 600) < 0.001f);256      }257      CHECK(peak > 44.9f && peak < 45.1f && player.jumps == 1);258      while (player.ground < 0) bh_tick(&player, 0, 0, 0, &floor, 1);259      player.jump_queue = 2;260      bh_tick(&player, 0, 0, 0, &floor, 1);261      CHECK(player.jumps == 2 && player.ground == -1 && player.velocity[0] == 600);262      for (int tick = 0; tick < 100; ++tick) bh_tick(&player, 0, 0, 0, &floor, 1);263      CHECK(player.jumps == 2 && player.ground == 0 && bh_speed(&player) < 250);264    265      const bh_box wall = {{100, -100, -100}, {110, 200, 100}};266      player = (bh_player){.position = {60, 10, 0}, .velocity = {5000, 0, -100}};267      bh_slide(&player, &wall, 1);268      CHECK(player.position[0] < 84 && player.position[0] > 83.9f);269      CHECK(player.velocity[0] == 0 && player.velocity[2] == -100);270      CHECK(fabsf(player.position[2] + 1) < 0.001f);271      puts("bhop: projection cap, full-wish acceleration, diagonal input, friction, 45-unit jump, landing momentum and swept wall sliding passed");272    273      bh_course course;274      bh_course_init(&course);275      bh_box pad = course.pads[1];276      player = (bh_player){.position = {(pad.low[0] + pad.high[0]) / 2, pad.high[1] + 0.01f,277        (pad.low[2] + pad.high[2]) / 2}};278      bh_course_tick(&course, &player, 0, 0, 0);279      CHECK(course.cooldown[1] == BH_PAD_DELAY + BH_PAD_RETURN && player.ground == 1);280      for (int i = 1; i < BH_PAD_DELAY; ++i) {281        bh_course_tick(&course, &player, 0, 0, 0);282        CHECK(player.ground == 1);283      }284      bh_course_tick(&course, &player, 0, 0, 0);285      CHECK(player.ground == -1 && course.collapses == 1);286      for (int i = 0; i < BH_PAD_RETURN; ++i) bh_course_tick(&course, &player, 0, 0, 0);287      CHECK(course.cooldown[1] == 0 && player.position[1] < pad.low[1]);288      player = (bh_player){.position = {0, 0.01f, 0}};289      for (int i = 0; i < 250; ++i) bh_course_tick(&course, &player, 0, 0, 0);290      CHECK(player.ground == 0 && course.cooldown[0] == 0);291      bh_course_init(&course);292      player = (bh_player){.position = {0, 0.01f, -400}};293      bh_course_tick(&course, &player, 0, 0, 0);294      player.jump_queue = 2;295      for (int i = 0; i < BH_PAD_DELAY + 1; ++i) bh_course_tick(&course, &player, 0, 0, 0);296      CHECK(player.jumps == 1 && player.position[1] > 20 && course.collapses == 1);297      puts("bhop: 100ms collapse, 2s return, safe checkpoints and immediate jumping passed");298    299      float fastest = 0;300      for (int next = 1; next < BH_PADS; ++next) {301        bh_course_init(&course);302        bh_box start = course.pads[next - 1], end = course.pads[next];303        float sx = (start.low[0] + start.high[0]) / 2, sz = (start.low[2] + start.high[2]) / 2;304        float ex = (end.low[0] + end.high[0]) / 2, ez = (end.low[2] + end.high[2]) / 2;305        // Check each gap independently with real swept physics, not just the ballistic formula.306        // Checkpoints provide a run-up; ordinary pads must be crossed without stopping.307        if (bh_checkpoint(next - 1)) sz = start.low[2] + 8;308        float rise = end.high[1] - start.high[1];309        float flight = (sqrtf(2 * BH_GRAVITY * 45) + sqrtf(2 * BH_GRAVITY * (45 - rise))) / BH_GRAVITY;310        float vx = (ex - sx) / flight, vz = (ez - sz) / flight;311        float speed = hypotf(vx, vz);312        fastest = fmaxf(fastest, speed);313        CHECK(speed < 440 && (!bh_checkpoint(next - 1) || speed < BH_RUN_SPEED));314        player = (bh_player){.position = {sx, start.high[1] + 0.01f, sz},315          .velocity = {vx, 0, vz}, .jump_queue = 2};316        int landed = -1;317        for (int tick = 0; tick < 100 && landed < 0; ++tick) {318          bh_course_tick(&course, &player, 0, 0, 0);319          if (player.ground >= 0) landed = player.ground;320        }321        CHECK(landed == next);322      }323      printf("bhop: all 32 individual gaps reachable, maximum center-landing speed %.1f u/s\n", fastest);324      return 0;325    }326327FILE /usr/src/dolly/bhop/bhop.c328    #define _POSIX_C_SOURCE 200809L329    #include "bhop-course.h"330    #include "agent/input.h"331    #include <dolly/raylib.h>332    #include <raymath.h>333    #include <rlgl.h>334    #include <errno.h>335    #include <stdio.h>336    #include <stdlib.h>337    #include <time.h>338    339    enum { PLATFORM_COUNT = BH_PADS };340    static const Color SKY = {20, 28, 38, 255}, INK = {231, 235, 234, 255};341    static const Color ACCENT = {255, 185, 82, 255}, CYAN = {84, 218, 205, 255};342    static const Color MUTED = {145, 159, 172, 255};343    static const char *record_path = "/workspace/bhop-foundry-record.txt";344    345    typedef struct {346      bh_player player;347      bh_course course;348      int forward, backward, left, right, turn_left, turn_right, looking, quit;349      int checkpoint, furthest, deaths, finished, practice, ticks, jumps, air_ticks, gain_ticks;350      float yaw, pitch, elapsed, best, peak_speed, landing_speed;351    } game;352    353    static double seconds(void) {354      struct timespec now;355      return clock_gettime(CLOCK_MONOTONIC, &now) == 0356        ? now.tv_sec + now.tv_nsec / 1e9 : 0;357    }358    static Color blend(Color from, Color to, float amount) {359      amount = Clamp(amount, 0, 1);360      return (Color){from.r + (to.r - from.r) * amount, from.g + (to.g - from.g) * amount,361        from.b + (to.b - from.b) * amount, 255};362    }363    static Vector3 center(bh_box box) {364      return (Vector3){(box.low[0] + box.high[0]) / 2, (box.low[1] + box.high[1]) / 2,365        (box.low[2] + box.high[2]) / 2};366    }367    static int is_checkpoint(int index) { return bh_checkpoint(index); }368    static void clear_keys(game *state) {369      state->forward = state->backward = state->left = state->right = 0;370      state->turn_left = state->turn_right = 0;371      state->player.jump_queue = 0;372    }373    static void respawn(game *state, int restart) {374      if (restart) {375        state->checkpoint = state->furthest = state->deaths = state->finished = 0;376        state->practice = 0;377        state->ticks = state->jumps = state->air_ticks = state->gain_ticks = 0;378        state->elapsed = state->peak_speed = state->landing_speed = 0;379      }380      memset(state->course.cooldown, 0, sizeof(state->course.cooldown));381      if (restart) state->course.collapses = 0;382      bh_box pad = state->course.pads[state->checkpoint];383      state->player = (bh_player){.position = {(pad.low[0] + pad.high[0]) / 2,384        pad.high[1] + 0.01f, (pad.low[2] + pad.high[2]) / 2 + (state->checkpoint == 0 ? 115 : 40)},385        .ground = state->checkpoint};386      Vector3 here = center(pad), next = center(state->course.pads[state->checkpoint + (state->checkpoint < BH_PADS - 1)]);387      state->yaw = atan2f(next.x - here.x, here.z - next.z);388      state->pitch = -0.06f;389      clear_keys(state);390    }391    static void tick(game *state) {392      if (!state->looking || state->finished) return;393      state->yaw += (state->turn_right - state->turn_left) * BH_STEP * 1.6f;394      int grounded = state->player.ground >= 0;395      int jumps = state->player.jumps;396      float before = bh_speed(&state->player);397      bh_course_tick(&state->course, &state->player, state->yaw, state->forward - state->backward,398        state->right - state->left);399      state->jumps += state->player.jumps - jumps;400      ++state->ticks;401      float speed = bh_speed(&state->player);402      state->peak_speed = fmaxf(state->peak_speed, speed);403      if (!grounded && (state->left || state->right || state->forward || state->backward)) {404        ++state->air_ticks;405        if (speed > before + 0.001f) ++state->gain_ticks;406      }407      if (state->player.position[2] < -180 || state->elapsed > 0) state->elapsed += BH_STEP;408      int pad = state->player.ground;409      if (!grounded && pad >= 0) state->landing_speed = speed;410      if (pad > state->furthest) state->furthest = pad;411      if (pad > state->checkpoint && is_checkpoint(pad)) state->checkpoint = pad;412      if (pad == PLATFORM_COUNT - 1 && !state->finished) {413        state->finished = 1;414        if (!state->practice && (!state->best || state->elapsed < state->best)) {415          state->best = state->elapsed;416          FILE *record = fopen(record_path, "w");417          if (record) { fprintf(record, "%.3f\n", state->best); fclose(record); }418        }419      }420      if (state->player.position[1] < -200) { ++state->deaths; respawn(state, 0); }421    }422    static void input(game *state, const dolly_input_event *event) {423      if (event->type == DOLLY_INPUT_EVENT_POINTER_CAPTURE) {424        state->looking = event->action != 0;425        clear_keys(state);426      } else if (event->type == DOLLY_INPUT_EVENT_POINTER_MOTION && state->looking) {427        state->yaw += event->x * 0.0000011f;428        state->pitch = Clamp(state->pitch - event->y * 0.0000011f, -1.48f, 1.48f);429      } else if (event->type == DOLLY_INPUT_EVENT_FOCUS && !event->action) {430        state->looking = 0;431        clear_keys(state);432      } else if (event->type == DOLLY_INPUT_EVENT_DROPPED) {433        clear_keys(state);434      } else if (event->type == DOLLY_INPUT_EVENT_SCROLL && state->looking && event->y != 0) {435        state->player.jump_queue = 2;436      } else if (event->type == DOLLY_INPUT_EVENT_KEY) {437        int down = event->action != DOLLY_KEY_ACTION_RELEASE;438        if (dolly_raylib_code_is(event, "KeyW")) state->forward = down;439        if (dolly_raylib_code_is(event, "KeyS")) state->backward = down;440        if (dolly_raylib_code_is(event, "KeyA")) state->left = down;441        if (dolly_raylib_code_is(event, "KeyD")) state->right = down;442        if (dolly_raylib_code_is(event, "ArrowLeft")) state->turn_left = down;443        if (dolly_raylib_code_is(event, "ArrowRight")) state->turn_right = down;444        if (event->action == DOLLY_KEY_ACTION_PRESS) {445          if (dolly_raylib_code_is(event, "Space") && state->looking) state->player.jump_queue = 2;446          if (dolly_raylib_code_is(event, "KeyR")) respawn(state, 1);447          if (dolly_raylib_code_is(event, "KeyF")) { ++state->deaths; respawn(state, 0); }448          if (dolly_raylib_code_is(event, "KeyQ")) state->quit = 1;449          const char *sections[] = {"Digit1", "Digit2", "Digit3", "Digit4"};450          for (int i = 0; i < 4; ++i) if (dolly_raylib_code_is(event, sections[i])) {451            state->checkpoint = state->furthest = i * 8;452            state->finished = 0;453            state->practice = 1;454            state->elapsed = 0;455            respawn(state, 0);456          }457        }458      }459    }460    static void label(Font font, const char *message, float x, float y, float size, Color color) {461      DrawTextEx(font, message, (Vector2){x, y}, size, 0, color);462    }463    static void shaded_cube(Vector3 middle, Vector3 size, Color color, float fog) {464      static const int faces[6][4] = {{0, 4, 6, 2}, {1, 3, 7, 5}, {0, 1, 5, 4},465        {2, 6, 7, 3}, {0, 2, 3, 1}, {4, 5, 7, 6}};466      static const float light[] = {0.68f, 0.85f, 0.5f, 1, 0.72f, 0.9f};467      Vector3 corner[8];468      for (int i = 0; i < 8; ++i) corner[i] = (Vector3){middle.x + (i & 1 ? 0.5f : -0.5f) * size.x,469        middle.y + (i & 2 ? 0.5f : -0.5f) * size.y, middle.z + (i & 4 ? 0.5f : -0.5f) * size.z};470      for (int i = 0; i < 6; ++i) {471        Color shade = blend((Color){color.r * light[i], color.g * light[i], color.b * light[i], 255}, SKY, fog);472        DrawTriangle3D(corner[faces[i][0]], corner[faces[i][1]], corner[faces[i][2]], shade);473        DrawTriangle3D(corner[faces[i][0]], corner[faces[i][2]], corner[faces[i][3]], shade);474      }475    }476    static void platform(bh_box box, int index, int cooldown, float fade) {477      int hidden = cooldown > 0 && cooldown <= BH_PAD_RETURN;478      if (hidden) {479        int falling = BH_PAD_RETURN - cooldown;480        if (falling > 24) return;481        float drop = falling * falling * 0.65f;482        box.low[1] -= drop;483        box.high[1] -= drop;484        fade = fmaxf(fade, falling / 26.0f);485      }486      Vector3 middle = center(box);487      Color rim = blend(is_checkpoint(index) ? CYAN : cooldown ? (Color){255, 89, 58, 255} : ACCENT, SKY, fade);488      shaded_cube(middle, (Vector3){box.high[0] - box.low[0], box.high[1] - box.low[1], box.high[2] - box.low[2]},489        (Color){132, 144, 153, 255}, fade);490      DrawCube((Vector3){middle.x, box.high[1] - 3, middle.z},491        box.high[0] - box.low[0] + 1, 6, box.high[2] - box.low[2] + 1, rim);492      float y = box.high[1] + 0.07f;493      int columns = (int)ceilf((box.high[0] - box.low[0]) / 32);494      int rows = (int)ceilf((box.high[2] - box.low[2]) / 32);495      for (int row = 0; row < rows; ++row) for (int column = 0; column < columns; ++column) {496        float left = box.low[0] + column * 32, right = fminf(left + 32, box.high[0]);497        float back = box.low[2] + row * 32, front = fminf(back + 32, box.high[2]);498        Color tile = blend((row + column) & 1 ? (Color){190, 198, 201, 255} : (Color){215, 221, 220, 255}, SKY, fade);499        DrawTriangle3D((Vector3){left, y, back}, (Vector3){left, y, front}, (Vector3){right, y, front}, tile);500        DrawTriangle3D((Vector3){left, y, back}, (Vector3){right, y, front}, (Vector3){right, y, back}, tile);501      }502      if (is_checkpoint(index)) {503        DrawCube((Vector3){middle.x, box.low[1] - 116, middle.z}, 60, 232, 60,504          blend((Color){43, 59, 73, 255}, SKY, fade));505        for (int side = -1; side <= 1; side += 2) {506          float x = side < 0 ? box.low[0] - 8 : box.high[0] + 8;507          DrawCube((Vector3){x, box.high[1] + 24, middle.z + 30}, 5, 5, 130, rim);508          for (int end = -1; end <= 1; end += 2)509            DrawCube((Vector3){x, box.high[1] + 12, middle.z + 30 + end * 62}, 5, 24, 5, rim);510        }511      }512    }513    static void structure(Vector3 eye, Vector3 middle, Vector3 size, Color color) {514      float distance = Vector3Distance(eye, middle);515      if (distance < 1900) shaded_cube(middle, size, color, Clamp((distance - 550) / 1450, 0, 0.95f));516    }517    static void industrial_yard(const game *state, Vector3 eye) {518      const Color steel = {65, 82, 92, 255}, concrete = {101, 115, 120, 255};519      const Color rust = {128, 73, 46, 255}, blue = {40, 89, 117, 255};520      for (int i = 0; i < BH_PADS; i += 2) {521        Vector3 pad = center(state->course.pads[i]);522        if (fabsf(pad.z - eye.z) > 1800) continue;523        int section = i / 8;524        float floor = -250;525        structure(eye, (Vector3){0, floor, pad.z}, (Vector3){1280, 12, 480}, (Color){31, 46, 55, 255});526        for (int side = -1; side <= 1; side += 2) {527          float x = side * 520;528          structure(eye, (Vector3){x, 100, pad.z}, (Vector3){24, 700, 32}, steel);529          structure(eye, (Vector3){x - side * 12, 85, pad.z + 17}, (Vector3){5, 95, 2}, ACCENT);530          structure(eye, (Vector3){side * 625, -135, pad.z}, (Vector3){245, 210, 465}, section == 0 ? blue : concrete);531          if (section == 0) {532            // Stacked ribbed shipping containers and open sky at the loading yard.533            structure(eye, (Vector3){side * 660, 50, pad.z - 75}, (Vector3){270, 165, 300}, i % 4 ? rust : blue);534            for (int rib = 0; rib < 6; ++rib)535              structure(eye, (Vector3){side * 519, 50, pad.z - 200 + rib * 50}, (Vector3){8, 150, 7}, steel);536          } else if (section == 1) {537            // Tall windowed turbine hall, suspended ducts and overhead beams.538            structure(eye, (Vector3){side * 550, 260, pad.z}, (Vector3){32, 340, 460}, concrete);539            for (int window = 0; window < 3; ++window)540              structure(eye, (Vector3){side * 530, 285, pad.z - 150 + window * 150},541                (Vector3){3, 92, 105}, (Color){74, 136, 154, 255});542            structure(eye, (Vector3){side * 345, 330, pad.z}, (Vector3){68, 62, 475}, steel);543          } else {544            // Original reactor/silo shapes; low polygon counts suit the software renderer.545            float distance = Vector3Distance(eye, (Vector3){side * 710, 0, pad.z});546            if (distance < 1700) {547              Color tank = blend(section == 2 ? blue : concrete, SKY, Clamp((distance - 450) / 1450, 0, 0.94f));548              DrawCylinder((Vector3){side * 710, -220, pad.z}, 125, 145, section == 2 ? 590 : 790, 12, tank);549              DrawCylinder((Vector3){side * 710, section == 2 ? 220 : 400, pad.z}, 149, 149, 18, 12,550                blend(section == 2 ? CYAN : ACCENT, SKY, Clamp(distance / 2000, 0, 0.9f)));551            }552            structure(eye, (Vector3){side * 460, -170, pad.z}, (Vector3){14, 20, 470}, section == 2 ? CYAN : ACCENT);553          }554        }555        if (section == 1 || i % 4 == 0) {556          structure(eye, (Vector3){0, 425, pad.z}, (Vector3){1080, 24, 32}, steel);557          structure(eye, (Vector3){0, 409, pad.z}, (Vector3){240, 4, 18}, (Color){233, 219, 168, 255});558        }559        if (is_checkpoint(i)) {560          structure(eye, (Vector3){pad.x, pad.y + 194, pad.z - 100}, (Vector3){310, 46, 24}, blue);561          for (int side = -1; side <= 1; side += 2)562            structure(eye, (Vector3){pad.x + side * 152, pad.y + 90, pad.z - 100}, (Vector3){8, 220, 8}, CYAN);563        }564      }565    }566    static void draw(game *state, Font font, int width, int height) {567      BeginDrawing();568      ClearBackground(SKY);569      DrawRectangleGradientV(0, 0, width, height, (Color){12, 18, 27, 255}, SKY);570      Vector3 eye = {state->player.position[0], state->player.position[1] + 64, state->player.position[2]};571      Camera3D camera = {.position = eye, .target = {eye.x + sinf(state->yaw) * cosf(state->pitch),572        eye.y + sinf(state->pitch), eye.z - cosf(state->yaw) * cosf(state->pitch)},573        .up = {0, 1, 0}, .fovy = 74, .projection = CAMERA_PERSPECTIVE};574      BeginMode3D(camera);575      industrial_yard(state, eye);576      for (int i = 0; i < PLATFORM_COUNT; ++i) {577        float distance = Vector3Distance(eye, center(state->course.pads[i]));578        if (distance < 1900) platform(state->course.pads[i], i, state->course.cooldown[i],579          Clamp((distance - 450) / 1500, 0, 0.92f));580      }581      EndMode3D();582    583      DrawRectangle(0, 0, width, 62, (Color){12, 18, 25, 255});584      label(font, "A I R T I M E", 18, 10, 25, INK);585      label(font, "FOUNDRY / STRAFE TRIALS", 20, 39, 11, ACCENT);586      const char *sections[] = {"01 / LOADING YARD", "02 / TURBINE HALL", "03 / REACTOR", "04 / SILO RUN", "FINISH"};587      label(font, sections[state->checkpoint / 8], width / 2 - 95, 14, 14, CYAN);588      for (int i = 0; i < BH_PADS; ++i) {589        Color color = i <= state->furthest ? CYAN : is_checkpoint(i) ? INK : MUTED;590        DrawRectangle(width / 2 - 96 + i * 6, 43, 3, is_checkpoint(i) ? 8 : 4, color);591      }592      char text[160];593      if (state->practice) snprintf(text, sizeof(text), "%05.2f  /  PRACTICE", state->elapsed);594      else snprintf(text, sizeof(text), "%05.2f  /  BEST %s", state->elapsed, state->best > 0 ? TextFormat("%.2f", state->best) : "--");595      label(font, text, width - 230, 17, 18, INK);596      snprintf(text, sizeof(text), "PAD %02d/%02d    FALLS %d", state->furthest, PLATFORM_COUNT - 1, state->deaths);597      label(font, text, width - 230, 41, 11, MUTED);598    599      DrawRectangle(0, height - 96, width, 96, (Color){12, 18, 25, 255});600      float speed = bh_speed(&state->player);601      snprintf(text, sizeof(text), "%03.0f", speed);602      Color speed_color = speed > 300 ? CYAN : ACCENT;603      label(font, text, width / 2 - 50, height - 86, 40, speed_color);604      label(font, "UNITS / SECOND", width / 2 - 47, height - 43, 11, MUTED);605      DrawRectangle(20, height - 16, width - 40, 3, (Color){45, 58, 69, 255});606      DrawRectangle(20, height - 16, (width - 40) * fminf(speed / 800, 1), 3, speed_color);607      snprintf(text, sizeof(text), "%s  |  SYNC %.0f%%", state->player.ground < 0 ? "AIR" : "GROUND",608        state->air_ticks ? 100.0f * state->gain_ticks / state->air_ticks : 0);609      label(font, text, 20, height - 77, 13, INK);610      snprintf(text, sizeof(text), "LAND %.0f   PEAK %.0f", state->landing_speed, state->peak_speed);611      label(font, text, 20, height - 53, 11, MUTED);612      label(font, "WASD   SPACE / WHEEL JUMP", width - 222, height - 77, 11, INK);613      label(font, "R RESTART   F CHECKPOINT   Q EXIT", width - 222, height - 53, 10, MUTED);614      label(font, "1-4 PRACTICE A SECTION", width - 222, height - 33, 10, MUTED);615    616      DrawLine(width / 2 - 5, height / 2, width / 2 + 5, height / 2, INK);617      DrawLine(width / 2, height / 2 - 5, width / 2, height / 2 + 5, INK);618      int ground = state->player.ground;619      if (ground >= 0 && !is_checkpoint(ground)) {620        label(font, "JUMP!", width / 2 - 25, height / 2 + 25, 16, ACCENT);621        DrawRectangle(width / 2 - 32, height / 2 + 47,622          64 * (state->course.cooldown[ground] - BH_PAD_RETURN) / BH_PAD_DELAY, 3, ACCENT);623      }624      if (!state->looking || state->finished) {625        int panel_width = width > 540 ? 500 : width - 30, x = (width - panel_width) / 2;626        DrawRectangle(x, height / 2 - 74, panel_width, 178, (Color){12, 18, 25, 255});627        DrawRectangle(x, height / 2 - 74, panel_width, 2, ACCENT);628        label(font, state->finished ? "COURSE COMPLETE" : "CLICK TO TAKE THE MOUSE", x + 22, height / 2 - 54, 23, INK);629        label(font, "W to launch. In air, release W and strafe A / D", x + 22, height / 2 - 17, 12, MUTED);630        label(font, "while turning the mouse in the same direction.", x + 22, height / 2 + 3, 12, MUTED);631        label(font, "Yellow pads drop on touch. Cyan decks are safe.", x + 22, height / 2 + 26, 12, INK);632        label(font, state->finished ? "R to race again. Q returns to Slop." :633          "Space or either wheel direction jumps. Esc releases.", x + 22, height / 2 + 65, 12, ACCENT);634      }635    }636    static int usage(const char *name, int status) {637      fprintf(status ? stderr : stdout, "usage: %s [--frames COUNT]\n"638        "Click once for mouse look; Escape releases. WASD moves; Space and wheel up/down jump.\n"639        "Foundry: 32 jumps through the yard, turbine hall, reactor and silos.\n"640        "Yellow pads collapse 100ms after landing and return after 2s; cyan checkpoints stay solid.\n"641        "1-4 practices a section without recording a best time; R begins a full run.\n"642        "R restarts; F returns to a checkpoint; Q exits. Release W in air and match A/D with mouse turn.\n", name);643      return status;644    }645    static void agent_input(void *context, const dolly_input_event *event) { input(context, event); }646    static int agent_frame(game *state, Font font) {647      static unsigned char pixels[960 * 540 * 4];648      draw(state, font, 960, 540);649      EndDrawing();650      rlCopyFramebuffer(0, 0, 960, 540, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, pixels);651      return bh_agent_frame(pixels);652    }653    int main(int argc, char **argv) {654      unsigned long limit = 0;655      if (argc == 2 && strcmp(argv[1], "--help") == 0) return usage(argv[0], 0);656      if (argc == 3 && strcmp(argv[1], "--frames") == 0) {657        char *end;658        errno = 0;659        limit = strtoul(argv[2], &end, 10);660        if (errno || argv[2][0] < '0' || argv[2][0] > '9' || *end || !limit) return usage(argv[0], 2);661      } else if (argc != 1) return usage(argv[0], 2);662      game state = {0};663      const int agent = bh_agent_open(agent_input, &state);664      dolly_raylib graphics = {0};665      if (agent) {666        graphics.surface.width = 960; graphics.surface.height = 540;667        InitWindow(960, 540, "Dolly Airtime");668        if (!IsWindowReady()) return 1;669        SetTraceLogLevel(LOG_WARNING);670      } else if (dolly_raylib_open_sized(&graphics, "Dolly Airtime", 960, 540) != 0) return 1;671      // A crosshair asks for the click that lets the page capture the pointer.672      if (!agent && (dolly_input_set_pointer_relative(graphics.input, 1) != 0 ||673                     dolly_raylib_set_cursor(&graphics, DOLLY_DISPLAY_CURSOR_CROSSHAIR) != 0)) {674        dolly_raylib_close(&graphics);675        fputs("bhop: this runtime does not support captured mouse input\n", stderr);676        return 1;677      }678      Font font = LoadFontEx("/usr/share/fonts/IosevkaTerm-SemiBold.ttf", 32, NULL, 0);679      if (!IsFontValid(font)) { if (agent) CloseWindow(); else dolly_raylib_close(&graphics); return 1; }680      SetTextureFilter(font.texture, TEXTURE_FILTER_BILINEAR);681      rlSetClipPlanes(1, 2400);682      bh_course_init(&state.course);683      respawn(&state, 1);684      FILE *record = fopen(record_path, "r");685      if (record) { if (fscanf(record, "%f", &state.best) != 1 || !isfinite(state.best) || state.best < 0) state.best = 0; fclose(record); }686      double previous = seconds(), accumulator = 0;687      unsigned long frames = 0;688      int result = 0;689      while (!state.quit && (!limit || frames < limit)) {690        if (agent) {691          const struct timespec interval = {0, 8000000}; nanosleep(&interval, NULL);692          if (bh_agent_poll()) break;693        } else if (frames && dolly_raylib_wait_frame(&graphics, 1000) < 0) { result = 1; break; }694        dolly_input_event event;695        for (int i = 0; !agent && i < 256; ++i) {696          int status = dolly_raylib_next_event(&graphics, &event, 0);697          if (status < 0) { result = 1; state.quit = 1; break; }698          if (!status) break;699          input(&state, &event);700        }701        if (state.quit) break;702        double now = seconds();703        accumulator += now >= previous ? fmin(now - previous, 0.1) : 0;704        previous = now;705        int drawn = 0;706        for (int i = 0; accumulator >= BH_STEP && i < 10; ++i, accumulator -= BH_STEP) {707          if (agent) bh_agent_tick();708          tick(&state); drawn = 0;709          if (agent && bh_agent_capture_due()) {710            if (!agent_frame(&state, font)) { result = 1; break; }711            drawn = 1;712          }713        }714        if (result) break;715        if (agent) {716          if (!drawn && !agent_frame(&state, font)) { result = 1; break; }717        } else {718          draw(&state, font, graphics.surface.width, graphics.surface.height);719          if (dolly_raylib_end_frame(&graphics) != 0) { result = 1; break; }720        }721        ++frames;722      }723      UnloadFont(font);724      if (agent) { bh_agent_close(); CloseWindow(); } else dolly_raylib_close(&graphics);725      printf("bhop: ticks=%d jumps=%d falls=%d pad=%d peak=%.3f speed=%.3f collapses=%d\n",726        state.ticks, state.jumps, state.deaths, state.furthest, state.peak_speed, bh_speed(&state.player), state.course.collapses);727      return result;728    }729730FILE /usr/src/dolly/bhop/bhop.mk731    .PHONY: all check732    all: /usr/bin/bhop733    /usr/bin/bhop: /usr/src/dolly/bhop/bhop.c /usr/src/dolly/bhop/bhop-movement.h /usr/src/dolly/bhop/bhop-course.h /usr/src/dolly/bhop/agent/input.c /usr/src/dolly/bhop/agent/input.h /usr/src/dolly/bhop/agent/timeline.h /usr/src/dolly/game-agent/control.h /usr/lib/libdolly-raylib.a /usr/lib/libraylib.a /usr/lib/libm.a734    	cc -std=c17 -O2 -fno-builtin $< /usr/src/dolly/bhop/agent/input.c -o $@ -ldolly-raylib -lraylib -lm735    check:736    	@output=/tmp/bhop-check.$$$$; status=0; cc -std=c17 -O2 -fno-builtin /usr/src/dolly/bhop/bhop-check.c -o "$$output" -lm && "$$output" || status=$$?; rm -f "$$output"; exit "$$status"737738SLOP make -f /usr/src/dolly/bhop/bhop.mk all check739740SLOP c++ -O1 -std=c++11 -I/usr/include/SDL2 -I/tmp/bhop-stb /usr/src/dolly/game-agent/viewer.cpp -o /usr/bin/bhop-viewer -lSDL2 -lm741SLOP cc -std=gnu11 -I/usr/include/dolly -DEMSCRIPTEN=1 -D_GNU_SOURCE -DQUICKJS_NG_BUILD -DNDEBUG -funsigned-char /usr/src/dolly/bhop/agent/launch.c -ldolly-js -o /usr/bin/bhop-agent742SLOP rm -rf /tmp/bhop-source.tar /tmp/bhop-stb743744EXPORTS TOOL bhop745EXPORTS TOOL bhop-agent746EXPORTS TOOL bhop-viewer747EXPORTS FOLDER bhop-agent-source /usr/src/dolly/bhop/agent748EXPORTS FOLDER game-agent-source /usr/src/dolly/game-agent749EXPORTS FOLDER game-input-source /usr/src/dolly/rts750751FILE /etc/dolly/init.slop752    if test -f "$HOME/.dollyrc"; then753      /bin/foreground /bin/slop -e "$HOME/.dollyrc"754    fi755    /bin/foreground -i /usr/bin/bhop-agent756    printf '\nDolly: image entry exited; entering the recovery Slop shell.\n'757    /bin/foreground -i /bin/slop758759FILE /home/dolly/.dollyrc760    printf '\033[33mDOLLY / AIRTIME: FOUNDRY\033[0m\n'761    printf 'Tab hides the agent UI; backtick toggles human/agent controls; Enter opens a prompt.\n'762    printf 'Settings connects OpenRouter or local Codex. Review attempts exports captured frames.\n'763    printf 'WASD moves. Space and scroll up/down jump. R restarts; F returns to a checkpoint.\n'764    printf 'Release W in air, then strafe A/D while turning the mouse in the same direction.\n'765    printf '32 jumps: yard, turbine hall, reactor, silos. Yellow pads collapse; cyan checkpoints are safe.\n'766    printf '1-4 practices a section without saving a best time; R starts a full run.\n'767    printf 'Edit /usr/src/dolly/bhop/bhop.c; make -f /usr/src/dolly/bhop/bhop.mk all check.\n\n'768769ENTRY /bin/foreground -i /bin/slop /etc/dolly/init.slop770