kobodl/prefs.h
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

145 lines
4.5 KiB
C++

/*(GPL)
------------------------------------------------------------
Kobo Deluxe - An enhanced SDL port of XKobo
------------------------------------------------------------
* Copyright (C) 2001-2003, 2007 David Olofson
* Copyright (C) 2005 Erik Auerswald
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _KOBO_PREFS_H_
#define _KOBO_PREFS_H_
#include "aconfig.h"
#include "cfgparse.h"
class prefs_t : public config_parser_t
{
public:
//System options
int logfile; //Log messages to log.txt/html
int logformat; //0: text, 1: ANSI, 2: HTML
int logverbosity;
//Input options
int use_joystick;
int joystick_no; //which joystick to use
int use_mouse;
int mousemode;
int broken_numdia;
int dia_emphasis;
int always_fire;
int mousecapture;
//Game options
int filter; //Use motion filtering
int timefilter; //Delta time filter
int scrollradar; //Radar display mode
int countdown; //"Get Ready" countdown
int starfield; //None/Old/parallax
int stars; //Number of parallax stars
int overheatloud; //Overheat warning loudness
int cannonloud; //Cannon loudness
//Sound: System
int use_sound; //Enable sound
int use_music; //Enable "real" music
int cached_sounds; //Use prerendered waveforms
int use_oss; //Use OSS audio driver
int samplerate;
int latency; //Audio latency in ms
int mixquality; //Mixer quality control
int volume; //Digital master volume
//Sound: Mixer
int intro_vol; //Intro music volume
int sfx_vol; //Sound effects volume
int music_vol; //In-game music volume
//Sound: Master Effects
int reverb; //Master reverb level
int vol_boost; //Master volume boost
//Video settings
int fullscreen; //Use fullscreen mode
int width; //Screen/window width
int height; //Screen/window height
int aspect; //Pixel aspect ratio * 1000
int max_fps; //Maximum fps
int max_fps_strict; //Strictly regulated fps limiter
int videomode; //Selected entry from the vidmodes table
int vsync; //Vertical (retrace) sync
//Graphics settings
int scalemode; //Scaling filter mode
int use_dither;
int dither_type;
int alpha; //Alpha blending
int brightness; //Graphics brightness
int contrast; //Graphics contrast
//File paths
cfg_string_t dir; //Path to kobo-deluxe/
cfg_string_t gfxdir; //Path to gfx/
cfg_string_t sfxdir; //Path to sfx/
cfg_string_t scoredir; //Path to scores/
//Global leaderboard
int global_leaderboard; //Submit scores to the server
cfg_string_t leaderboard_board; //Shared "room code"
cfg_string_t leaderboard_url; //Server endpoint base URL
cfg_string_t client_id; //Per-install UUID (auto-gen)
//Obsolete stuff (compatibility)
int o_size; //Screen scale
int o_wait_msec; //ms per control system frame
cfg_string_t o_bgm_indexfile; //Ext playlist path
int o_threshold; //Limiter threshold
int o_release; //Limiter release rate
int o_internalres; //Internal resolution for OpenGL
// SDL 1.2 video settings, read for back-compat but unused under SDL 3
int o_videodriver;
int o_depth;
int o_doublebuf;
int o_shadow;
int o_pages;
int o_broken_rgba8;
//"Hidden" stuff ("to remember until next startup")
int last_profile; //Last used player profile
int number_of_joysticks; //no of connected joysticks
void init();
void postload();
/* "Commands" - never written to config files */
int cmd_showcfg;
int cmd_hiscores;
int cmd_override;
int cmd_debug;
int cmd_fps;
int cmd_noframe;
int cmd_midi;
int cmd_cheat; //Unlimited lives; select any starting stage
int cmd_indicator; //Enable collision testing mode
int cmd_pushmove; //Stop when not holding any direction down
int cmd_noparachute; //Disable SDL parachute
int cmd_pollaudio; //Use polling based audio instead of thread
int cmd_autoshot; //Take ingame screenshots
int cmd_help; //Show help and exit
int cmd_options_man; //Output OPTIONS doc in Un*x man source format
};
#endif //_KOBO_PREFS_H_