7 Commits

Author SHA1 Message Date
Ville Lindholm
9238ce61c6
Add global leaderboard client (dormant by default)
End-of-game scores are POSTed to a configurable backend URL; the main menu
gains a "Global Leaderboard" entry that fetches and renders the top N for
the current board. Default `global_leaderboard=0` ships the code dormant
until the backend at leaderboard_url is live.

Architecture:
- httpclient.h: thin async interface. http_post_json / http_get fire and
  forget; the user callback runs from http_pump() (native) or the
  Emscripten runtime (web). No blocking calls.
- httpclient_native.cpp: libcurl-multi, polled per frame.
- httpclient_web.cpp: emscripten_fetch (-sFETCH=1 link option).
- leaderboard.{h,cpp}: portable game-side module. Hand-rolled JSON
  build/parse for the tiny fixed-shape wire format; no JSON dep.

Identity: player name + a player-typed "board name" (shared room code).
A per-install RFC-4122-v4 UUID `client_id` is auto-generated on first run
via SDL_rand_bits and stored in the config — server uses it for rate
limiting / dedup, not as a public identity.

Wire format (informational, server is out-of-tree):
  POST /api/scores  body: {board, name, client_id, score, skill,
                           gametype, end_scene, end_lives, end_health,
                           playtime, start_date, end_date}
                    resp: {rank, total}
  GET  /api/scores?board=&limit=50
                    resp: {board, total, scores:[{name,score,end_scene}]}

Hook points:
- manage.cpp game_start: populate hi.start_date; reset_submission().
- manage.cpp game_stop: populate hi.end_date and the profile name on hi,
  then leaderboard::submit_score after scorefile.record.
- kobo.cpp main: http_init/http_shutdown around the run; generate
  client_id on first run when empty.
- kobo.cpp kobo_gfxengine_t::frame: http_pump() before gsm.frame().
- states.cpp st_game_over post_render: renders "Submitting…" / "Rank #N of M"
  / "(offline)" under "GAME OVER".
- states.cpp main_menu: "Global Leaderboard" button (only when enabled
  + board name set).
- states.cpp st_global_leaderboard_t: new browser state listing top 16.
- options.cpp game_options: onoff toggle.

Out of scope for this commit (left as follow-ups):
- In-game text editor for board name / URL (form toolkit has no free-text
  widget; users edit via config file or CLI flags for now).
- Retry queue across sessions.
- Server implementation. tools/mock-leaderboard.py is a 100-line Python
  scratch server for local testing only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-05 11:10:20 +03:00
Ville Lindholm
0263be65d4
Add deterministic bench harness (KOBO_BENCH=1)
When KOBO_BENCH=1 is set in the environment, the game becomes a
hands-off benchmark:

  * Skips the intro/menu sequence and pushes st_game directly with
    scene=0, skill=CLASSIC, invulnerable ship, always_fire = constant
    auto-fire, countdown = 0 so "GET READY" auto-pops in 700ms.
  * Seeds pubrand and gamerand from KOBO_BENCH_SEED (default 12345)
    so the map, stress spawn pattern, and enemy AI are identical
    run-to-run.
  * Defaults KOBO_STRESS=1500 unless overridden, so the move pass has
    a steady workload, and KOBO_PROF=1 so the profiler is on.
  * Counts frames in run_game; after KOBO_BENCH_FRAMES (default 1800)
    it dumps prof to stderr and exits cleanly.

Usage from repo root (the cwd matters — relative GFX paths only
resolve from here):
    KOBO_BENCH=1 ./build/kobodl 2>bench-logs/phaseN.log

A single command produces a comparable profiler dump at every phase
of the DOD refactor — no menus to navigate, no keyboard input,
identical workload.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-04 15:37:44 +03:00
Ville Lindholm
869056c5d2
Phase 0: profiling scaffolding for DOD refactor
Adds a tiny zone-based profiler (prof.{h,cpp}) enabled via KOBO_PROF=1.
Instruments run_game with zones for myship.move, enemies.move (split into
realize and move_pass), hit_structure, and hit_bolt. Adds KOBO_STRESS=N
to keep the enemy pool topped up with rocks for stable per-frame timing.

Why: the entity/render pipeline refactor in BENCH.md needs a comparable
baseline before any layout changes. Without a stress workload the natural
gameplay enemy count is too noisy to compare across commits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-29 13:31:31 +03:00
Ville Lindholm
8d57d63da2
Phase 9 cleanup: rip out SDL 1.2 video knobs no SDL 3 path uses
After the SDL 3 renderer migration, the engine has exactly one back
buffer (a CPU-side ARGB8888 SDL_Surface) and one presentation path
(upload to streaming SDL_Texture, RenderPresent). All the SDL 1.2
hardware-surface / page-flipping / depth / driver knobs were dead.

Removed from gfxengine_t:
- _doublebuf, doublebuffer() setter+getter
- _pages, pages() setter
- _shadow, shadow() setter+getter
- _depth + the depth argument processing in mode()
- _driver, driver() setter, gfx_drivers_t enum, GFX_DRIVER_SDL2D
- xflags + the extraflags parameter to open()
- broken_rgba8 (the OpenGL RGBA→RGBA4 workaround field)
- MAX_PAGES + backpage/frontpage + the per-page dirtyrects[]/
  dirtytable[]/dirtywtable[] arrays. Collapsed to 1-D dirtytable.
- __invalidate(int page, ...) → __invalidate(rect, window).
- The per-page invalidate() switch on _pages.
- vsync() now hot-applies via SDL_SetRenderVSync (no hide/show cycle).
- mode() keeps the int-bits arg for API compat but ignores it.

Removed from prefs_t:
- videodriver, depth, doublebuf, shadow, pages, broken_rgba8.
  Their config-file keys are now read as obsolete fields (silently
  consumed, never re-written) so existing config files load cleanly
  without breaking on unknown keys.

Removed from the options menu:
- Display Depth, Display Buffering Mode, Software Shadow Buffer,
  Display Buffer Pages, Broken RGBA8.

Removed from the escape-hammering safe-video-mode reset path the
fields that no longer exist (doublebuf, pages, shadow, depth,
videodriver).

dashboard.cpp: dropped the doublebuffer()-guarded second pass of the
loading-animation nibble draw; SDL 3's single back buffer doesn't
need it.

Build clean, binary still runs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-28 22:12:40 +03:00
Ville Lindholm
0e6865c4da
WIP: port deferred input/audio stubs to real SDL 3 APIs
Phase 7-8 of the migration. Replaces the per-subsystem stubs added in
the earlier "builds clean" commit with proper SDL 3 implementations.

- gfxengine: add SDL_Window* accessor window_handle() so callers that
  need to talk to SDL 3's window APIs (grab, text input) can reach it.
- states.cpp mouse grab: SDL_WM_GrabInput → SDL_SetWindowMouseGrab.
  Drops the local SDL_GRAB_* / SDL_WM_GrabInput stub macros.
- states.cpp text input: SDL_EnableUNICODE → SDL_StartTextInput /
  SDL_StopTextInput. kobo.cpp event loop now handles
  SDL_EVENT_TEXT_INPUT (in both quit_requested() and the main game
  loop) and forwards each byte of the UTF-8 string as a unicode value
  to gsm.press(-1, ch) so the high-score name-entry path keeps
  working without any state-side changes.
- kobo.cpp joystick: full re-port of init_js / close_js using
  SDL_GetJoysticks (returns SDL_JoystickID array), SDL_OpenJoystick,
  SDL_CloseJoystick. options.cpp joystick enumeration already used
  the new API from the previous commit.
- sound/audio.c: replace the silent stub with a real SDL 3 backend
  built on SDL_OpenAudioDeviceStream + an SDL_AudioStreamCallback.
  The engine's existing _audio_callback (Sint16 stereo fill-buffer)
  is kept; a small adapter (sdl3_stream_callback) runs it on a
  scratch buffer and pushes the result via SDL_PutAudioStreamData.
  audio_lock/unlock now call SDL_LockAudioStream / SDL_UnlockAudioStream.

After this commit the binary opens an audio device successfully and
the joystick path resolves real SDL 3 calls. Renderer + audio +
input are now all on SDL 3 with no compat shims.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-28 22:02:38 +03:00
Ville Lindholm
f11b6516da
WIP: port renderer + supporting layers to SDL 3 (builds clean)
Completes phases 3-6 of the migration plan. After this commit, the
codebase compiles and links against pure SDL 3 (no compat shim). The
binary is unverified at runtime but the build is clean.

Renderer (graphics/gfxengine.{cpp,h}):
- Replace SDL_SetVideoMode + SDL_Flip + page-flip machinery with
  SDL_CreateWindow + SDL_CreateRenderer + a streaming SDL_Texture.
  The CPU-side back buffer (softbuf) is now always ARGB8888; legacy
  HW/double-buffer/page flags are dead.
- flip() does a single full-frame SDL_UpdateTexture + SDL_RenderClear
  + SDL_RenderTexture + SDL_RenderPresent each frame. The dirtyrect
  iteration is retained only to drive widget phys_refresh() callbacks.
- SDL_SetRenderLogicalPresentation gives us letterbox scaling for free.
- SDL_SetRenderVSync replaces glSDL_VSync.
- title()/cursor() ported to SDL 3 window/cursor APIs.

Surface API (graphics/sprite.c, filters.c, window.cpp, sofont.cpp,
region.c):
- SDL_FreeSurface → SDL_DestroySurface
- SDL_FillRect → SDL_FillSurfaceRect
- SDL_SetClipRect → SDL_SetSurfaceClipRect
- SDL_SetColorKey(s, flags, key) → SDL_SetSurfaceColorKey(s, bool, key)
- SDL_SetAlpha(s, flags, a) → SDL_SetSurfaceAlphaMod + BlendMode
- SDL_SetColors → SDL_SetSurfacePalette
- SDL_CreateRGBSurface(...) → SDL_CreateSurface(w, h, format_enum)
- SDL_DisplayFormat[Alpha] → SDL_ConvertSurface(s, ARGB8888)
- SDL_MapRGB(surf->format, ...) → SDL_MapSurfaceRGB(surf, ...)
- surface->format->Field → SDL_GetPixelFormatDetails(surf->format)->field
- surface->format->Amask test → SDL_ISPIXELFORMAT_ALPHA
- surface->clip_rect → SDL_GetSurfaceClipRect

Events (kobo.cpp):
- SDL_{KEYDOWN,KEYUP,QUIT,VIDEOEXPOSE,MOUSE*,JOY*} → SDL_EVENT_*
- SDL_ACTIVEEVENT (with gain check) → SDL_EVENT_WINDOW_FOCUS_LOST
- ev.key.keysym.sym → ev.key.key (.unicode → text input, deferred)
- SDLK_PRINT/SYSREQ → SDLK_PRINTSCREEN; lowercase SDLK_p/y/n → uppercase
- ev.motion.x/y for button events → ev.button.x/y (struct layout differs)
- KMOD_META → SDL_KMOD_GUI
- SDL_INIT_NOPARACHUTE → SDL_Init(0) (no parachute by default in SDL 3)

Keymap (gamectl.{cpp,h}):
- SDLKey → SDL_Keycode
- SDLK_KP{1..9} → SDLK_KP_{1..9}

Stubs deferred for later phases (binary will run but with degraded
behavior):
- sound/audio.c: _start_SDL_output returns -1 immediately; SDL 1.2
  audio callback model needs full rewrite onto SDL_AudioStream.
- kobo.cpp init_js/close_js: SDL 3 joystick API uses instance IDs;
  re-port deferred.
- states.cpp SDL_WM_GrabInput/SDL_EnableUNICODE: need window pointer
  exposed from gfxengine; stubbed.
- gamectl.cpp SDL_EnableKeyRepeat: removed; relies on ev.key.repeat.

Other adjustments:
- options.cpp: GFX_DRIVER_GLSDL menu paths removed; show vsync option
  always (renderer handles it).
- sound/a_wave.c: AUDIO_S8/AUDIO_S16SYS → SDL_AUDIO_S8/S16, SDL_FreeWAV
  → SDL_free.
- gfxengine.cpp: SDL_putenv("SDL_VIDEO_CENTERED=1") obsolete (handled
  by SDL_CreateWindow defaults).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-28 21:54:55 +03:00
Ville Lindholm
dbc223eb84
Initial commit
Import existing source tree; original VCS history is no longer available.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-28 16:35:31 +03:00