From ce26e0bb9d17a48eb43020f7b2f4d8cc57e12ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sat, 28 Mar 2020 13:31:50 -0400 Subject: [PATCH] move all the oshu_* symbols under oshu:: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It bothered me to leave oshu after a half-assed C++ migrations. Some things were inside the namespace and other had the oshu_ C prefix. Now the naming scheme is at least consistent. This refactoring was mostly automated, which is why oshu:: is explicit in most instances. It doesn’t have to be that way in the future. --- include/audio/audio.h | 96 ++++++++------- include/audio/library.h | 68 ++++++----- include/audio/sample.h | 26 ++-- include/audio/stream.h | 47 ++++---- include/audio/track.h | 26 ++-- include/beatmap/beatmap.h | 234 ++++++++++++++++++------------------ include/beatmap/path.h | 76 ++++++------ include/core/geometry.h | 18 ++- include/game/base.h | 32 ++--- include/game/clock.h | 12 +- include/game/controls.h | 57 ++++----- include/game/mode.h | 6 +- include/game/osu.h | 12 +- include/game/tty.h | 10 +- include/library/beatmaps.h | 4 +- include/ui/audio.h | 26 ++-- include/ui/background.h | 34 +++--- include/ui/cursor.h | 24 ++-- include/ui/metadata.h | 37 +++--- include/ui/osu.h | 58 ++++----- include/ui/score.h | 22 ++-- include/ui/shell.h | 22 ++-- include/video/display.h | 60 ++++----- include/video/paint.h | 43 ++++--- include/video/texture.h | 35 +++--- include/video/transitions.h | 15 ++- include/video/view.h | 38 +++--- lib/audio/audio.cc | 54 ++++----- lib/audio/library.cc | 164 ++++++++++++------------- lib/audio/sample.cc | 8 +- lib/audio/stream.cc | 34 +++--- lib/audio/track.cc | 6 +- lib/beatmap/helpers.cc | 10 +- lib/beatmap/parser.cc | 206 +++++++++++++++---------------- lib/beatmap/parser.h | 40 +++--- lib/beatmap/path.cc | 98 +++++++-------- lib/core/geometry.cc | 2 +- lib/game/base.cc | 38 +++--- lib/game/clock.cc | 6 +- lib/game/controls.cc | 30 ++--- lib/game/helpers.cc | 24 ++-- lib/game/osu.cc | 102 ++++++++-------- lib/game/tty.cc | 16 +-- lib/library/beatmaps.cc | 8 +- lib/ui/audio.cc | 6 +- lib/ui/background.cc | 30 ++--- lib/ui/cursor.cc | 30 ++--- lib/ui/index.dox | 2 +- lib/ui/metadata.cc | 52 ++++---- lib/ui/osu.cc | 112 ++++++++--------- lib/ui/osu_paint.cc | 134 ++++++++++----------- lib/ui/score.cc | 12 +- lib/ui/screens/pause.cc | 28 +++-- lib/ui/screens/play.cc | 56 +++++---- lib/ui/screens/score.cc | 20 +-- lib/ui/screens/screens.h | 12 +- lib/ui/shell.cc | 38 +++--- lib/video/display.cc | 38 +++--- lib/video/paint.cc | 6 +- lib/video/texture.cc | 16 +-- lib/video/transitions.cc | 6 +- lib/video/view.cc | 24 ++-- src/oshu/main.cc | 4 +- test/zerotokei.cc | 6 +- 64 files changed, 1354 insertions(+), 1262 deletions(-) diff --git a/include/audio/audio.h b/include/audio/audio.h index 0c5eba8..bfb170d 100644 --- a/include/audio/audio.h +++ b/include/audio/audio.h @@ -6,7 +6,7 @@ * Definition of the highest-level audio module. * * \todo - * Rename this file to engine.h after renaming #oshu_audio. + * Rename this file to engine.h after renaming #oshu::audio. */ #pragma once @@ -17,6 +17,8 @@ #include +namespace oshu { + /** \defgroup audio Audio * * \brief @@ -84,45 +86,45 @@ * rankdir=LR * node [shape=rect] * - * track1 [label="oshu_track"] - * track2 [label="oshu_track"] - * track3 [label="oshu_track"] - * sample1 [label="oshu_sample"] - * sample2 [label="oshu_sample"] + * track1 [label="oshu::track"] + * track2 [label="oshu::track"] + * track3 [label="oshu::track"] + * sample1 [label="oshu::sample"] + * sample2 [label="oshu::sample"] * "float*" [shape=none] * "music.mp3" [shape=none] * "hit.wav" [shape=none] * "clap.wav" [shape=none] * - * "music.mp3" -> "oshu_stream" [label="oshu_open_stream"] - * "oshu_stream" -> "float*" [label="oshu_read_stream"] - * "hit.wav" -> sample1 [label="oshu_load_sample"] - * "clap.wav" -> sample2 [label="oshu_load_sample"] - * sample1 -> track1 [label="oshu_start_track"] - * sample1 -> track2 [label="oshu_start_track"] - * sample2 -> track3 [label="oshu_start_track"] - * track1 -> "float*" [label="oshu_mix_track"] - * track2 -> "float*" [label="oshu_mix_track"] - * track3 -> "float*" [label="oshu_mix_track"] + * "music.mp3" -> "oshu::stream" [label="oshu::open_stream"] + * "oshu::stream" -> "float*" [label="oshu::read_stream"] + * "hit.wav" -> sample1 [label="oshu::load_sample"] + * "clap.wav" -> sample2 [label="oshu::load_sample"] + * sample1 -> track1 [label="oshu::start_track"] + * sample1 -> track2 [label="oshu::start_track"] + * sample2 -> track3 [label="oshu::start_track"] + * track1 -> "float*" [label="oshu::mix_track"] + * track2 -> "float*" [label="oshu::mix_track"] + * track3 -> "float*" [label="oshu::mix_track"] * "float*" -> "SDL" * } * \enddot * * ## Use * - * To use this module, open streams using #oshu_open_audio, and play them using - * #oshu_play_audio. When you're done, close your streams with - * #oshu_pause_audio. Also make sure you initialized SDL with the audio + * To use this module, open streams using #oshu::open_audio, and play them using + * #oshu::play_audio. When you're done, close your streams with + * #oshu::pause_audio. Also make sure you initialized SDL with the audio * sub-module. * * ```c * SDL_Init(SDL_AUDIO|...); - * struct oshu_audio audio; + * struct oshu::audio audio; * memset(&audio, 0, sizeof(audio)); - * oshu_open_audio("file.ogg", &audio); - * oshu_play_audio(&audio); + * oshu::open_audio("file.ogg", &audio); + * oshu::play_audio(&audio); * do_things(); - * oshu_close_audio(&audio); + * oshu::close_audio(&audio); * ``` * * ## Limitations @@ -156,11 +158,11 @@ * \todo * Rename this to oshu::audio::engine. */ -struct oshu_audio { +struct audio { /** * The background music. */ - struct oshu_stream music; + struct oshu::stream music; /** * Tracks for playing sound effects on top of the music. * @@ -169,17 +171,17 @@ struct oshu_audio { * When the need for looping samples arise, it would be smart to * dedicate a track for them. * - * \sa oshu_play_sample + * \sa oshu::play_sample */ - struct oshu_track effects[16]; + struct oshu::track effects[16]; /** * Special track for the looping sample. * * As you can see, only one loop is supported. * - * \sa oshu_play_loop + * \sa oshu::play_loop */ - struct oshu_track looping; + struct oshu::track looping; /** * A device ID returned by SDL, and required by most SDL audio * functions. @@ -189,7 +191,7 @@ struct oshu_audio { * Contains the sample rate, format, and channel layout of the audio * output device. * - * This is useful for loading samples with #oshu_load_sample. + * This is useful for loading samples with #oshu::load_sample. */ SDL_AudioSpec device_spec; }; @@ -198,13 +200,13 @@ struct oshu_audio { * Open a file and initialize everything needed to play it. * * \param url Path or URL to the audio file to play. - * \param audio Null-initialized #oshu_audio object. + * \param audio Null-initialized #oshu::audio object. * * \return 0 on success. On error, -1 is returned and everything is freed. * * \sa oshu_audio_close */ -int oshu_open_audio(const char *url, struct oshu_audio *audio); +int open_audio(const char *url, struct oshu::audio *audio); /** * Start playing! @@ -212,17 +214,17 @@ int oshu_open_audio(const char *url, struct oshu_audio *audio); * The SDL plays audio in a separate thread, so you need not worry about * calling this function regularily or anything. Don't bother, it's magic! * - * \sa oshu_pause_audio + * \sa oshu::pause_audio */ -void oshu_play_audio(struct oshu_audio *audio); +void play_audio(struct oshu::audio *audio); /** * Pause the stream. * - * Calling #oshu_play_audio will resume the audio playback where it was + * Calling #oshu::play_audio will resume the audio playback where it was * left playing. */ -void oshu_pause_audio(struct oshu_audio *audio); +void pause_audio(struct oshu::audio *audio); /** * Play a sample on top of the background music. @@ -232,7 +234,7 @@ void oshu_pause_audio(struct oshu_audio *audio); * reached because all the effects tracks are used, the playback of one of * the samples is stopped to play the new sample. */ -void oshu_play_sample(struct oshu_audio *audio, struct oshu_sample *sample, float volume); +void play_sample(struct oshu::audio *audio, struct oshu::sample *sample, float volume); /** * Play a looping sample. @@ -240,21 +242,21 @@ void oshu_play_sample(struct oshu_audio *audio, struct oshu_sample *sample, floa * Currently, only one looping sample may be played at a time. Calling this * function cancels any other looping sample. * - * \sa oshu_play_sample - * \sa oshu_stop_loop + * \sa oshu::play_sample + * \sa oshu::stop_loop */ -void oshu_play_loop(struct oshu_audio *audio, struct oshu_sample *sample, float volume); +void play_loop(struct oshu::audio *audio, struct oshu::sample *sample, float volume); /** * Seek the music stream to the specifed target position in seconds. * - * See #oshu_seek_stream for details. + * See #oshu::seek_stream for details. * - * It is similar to #oshu_seek_stream, with the different that this function + * It is similar to #oshu::seek_stream, with the different that this function * locks the audio thread, and stops all the currently playing sound effects, * which is definitely what you want. */ -int oshu_seek_music(struct oshu_audio *audio, double target); +int seek_music(struct oshu::audio *audio, double target); /** * Stop the looping sample. @@ -263,13 +265,15 @@ int oshu_seek_music(struct oshu_audio *audio, double target); * future, if more looping samples are supported, this function's prototype * would change. * - * \sa oshu_play_loop + * \sa oshu::play_loop */ -void oshu_stop_loop(struct oshu_audio *audio); +void stop_loop(struct oshu::audio *audio); /** * Close the audio stream and free everything associated to it. */ -void oshu_close_audio(struct oshu_audio *audio); +void close_audio(struct oshu::audio *audio); /** \} */ + +} diff --git a/include/audio/library.h b/include/audio/library.h index 1c4179b..947bf81 100644 --- a/include/audio/library.h +++ b/include/audio/library.h @@ -9,11 +9,13 @@ #include -struct oshu_audio; -struct oshu_sample; - struct SDL_AudioSpec; +namespace oshu { + +struct audio; +struct sample; + /** * \defgroup audio_library Library * \ingroup audio @@ -56,7 +58,7 @@ struct SDL_AudioSpec; * \{ */ -enum oshu_sound_shelf_index { +enum sound_shelf_index { /** * Fallback shelf when a sample is missing from a custom shelf. * @@ -64,7 +66,7 @@ enum oshu_sound_shelf_index { * the skin. It is different from shelf 1 which uses the sample files * in the beatmap directory. */ - OSHU_DEFAULT_SHELF = 0, + DEFAULT_SHELF = 0, }; /** @@ -72,13 +74,13 @@ enum oshu_sound_shelf_index { * * These pointers are NULL when no sample is available. */ -struct oshu_sound_shelf { - struct oshu_sample *hit_normal; - struct oshu_sample *hit_whistle; - struct oshu_sample *hit_finish; - struct oshu_sample *hit_clap; - struct oshu_sample *slider_slide; - struct oshu_sample *slider_whistle; +struct sound_shelf { + struct oshu::sample *hit_normal; + struct oshu::sample *hit_whistle; + struct oshu::sample *hit_finish; + struct oshu::sample *hit_clap; + struct oshu::sample *slider_slide; + struct oshu::sample *slider_whistle; }; /** @@ -89,7 +91,7 @@ struct oshu_sound_shelf { * * More concretely, a room is a dynamically-sized array of shelves. */ -struct oshu_sound_room { +struct sound_room { /** * Location of the shelves. * @@ -98,7 +100,7 @@ struct oshu_sound_room { * * \sa size */ - struct oshu_sound_shelf *shelves; + struct oshu::sound_shelf *shelves; /** * Indices of the shelves. * @@ -133,9 +135,9 @@ struct oshu_sound_room { * * The library is composed of 3 rooms, one per sample set family. * - * \sa oshu_sample_set_family + * \sa oshu::sample_set_family */ -struct oshu_sound_library { +struct sound_library { /** * Path to the skin directory, containing the samples. * @@ -155,9 +157,9 @@ struct oshu_sound_library { * Format of the samples in the library. */ struct SDL_AudioSpec *format; - struct oshu_sound_room normal; - struct oshu_sound_room soft; - struct oshu_sound_room drum; + struct oshu::sound_room normal; + struct oshu::sound_room soft; + struct oshu::sound_room drum; }; /** @@ -169,48 +171,50 @@ struct oshu_sound_library { * * The library object must be zero-initalized. * - * \sa oshu_close_sound_library + * \sa oshu::close_sound_library */ -void oshu_open_sound_library(struct oshu_sound_library *library, struct SDL_AudioSpec *format); +void open_sound_library(struct oshu::sound_library *library, struct SDL_AudioSpec *format); /** * Delete all the loaded samples from the library. */ -void oshu_close_sound_library(struct oshu_sound_library *library); +void close_sound_library(struct oshu::sound_library *library); /** * Locate a sample on the filesystem and insert it into the library. * - * *type* is an OR'd combination of #oshu_sound_type. + * *type* is an OR'd combination of #oshu::sound_type. * - * \sa oshu_register_sounds + * \sa oshu::register_sound */ -int oshu_register_sample(struct oshu_sound_library *library, enum oshu_sample_set_family set, int index, int type); +int register_sample(struct oshu::sound_library *library, enum oshu::sample_set_family set, int index, int type); /** * Load every sample required to play a hit sound effect. * - * \sa oshu_register_sample - * \sa oshu_populate_library + * \sa oshu::register_sample + * \sa oshu::populate_library */ -void oshu_register_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound); +void register_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound); /** * Find every sample reference into a beatmap and load them into the library. * - * \sa oshu_register_sounds + * \sa oshu::register_sound */ -void oshu_populate_library(struct oshu_sound_library *library, struct oshu_beatmap *beatmap); +void populate_library(struct oshu::sound_library *library, struct oshu::beatmap *beatmap); /** * Play all the samples associated to the hit sound. * * If one of the required samples wasn't found, it is ignored. * - * If the sound is for a slider, its sample is looped until you call #oshu_stop_loop. + * If the sound is for a slider, its sample is looped until you call #oshu::stop_loop. * * \sa oshu_find_sample */ -void oshu_play_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound, struct oshu_audio *audio); +void play_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound, struct oshu::audio *audio); /** \} */ + +} diff --git a/include/audio/sample.h b/include/audio/sample.h index 3f7775a..1370efe 100644 --- a/include/audio/sample.h +++ b/include/audio/sample.h @@ -9,6 +9,8 @@ struct SDL_AudioSpec; +namespace oshu { + /** * \defgroup audio_sample Sample * \ingroup audio @@ -21,11 +23,11 @@ struct SDL_AudioSpec; * with a PCM sample. * * If need be, samples could be loaded using the audio stream module and - * slurped into memory through #oshu_read_stream. However, since samples are + * slurped into memory through #oshu::read_stream. However, since samples are * always WAV anyway, let's start with a naive implementation using SDL's * procedures. * - * To play samples, you must use tracks. See #oshu_track. + * To play samples, you must use tracks. See #oshu::track. * * \{ */ @@ -36,12 +38,12 @@ struct SDL_AudioSpec; * For consistency accross the audio modules, samples are always stored as * packed 32-bit floats. The sample rate is defined when loading the sample. * - * \sa oshu_load_sample - * \sa oshu_destroy_sample + * \sa oshu::load_sample + * \sa oshu::destroy_sample */ -struct oshu_sample { +struct sample { /** - * The PCM samples, as described in #oshu_sample. + * The PCM samples, as described in #oshu::sample. * * The array should contain exactly #size bytes. */ @@ -66,22 +68,24 @@ struct oshu_sample { * required. Note that this means the sample will be specific to that stream * only. * - * On failure, you may, but are not required to, call #oshu_destroy_sample. + * On failure, you may, but are not required to, call #oshu::destroy_sample. * * \param path Path to the WAV file to load. * \param spec Target format of the sample. Must be stereo float samples. - * \param sample An allocated #oshu_sample, initialized or not. + * \param sample An allocated #oshu::sample, initialized or not. * - * \sa oshu_destroy_sample + * \sa oshu::destroy_sample */ -int oshu_load_sample(const char *path, struct SDL_AudioSpec *spec, struct oshu_sample *sample); +int load_sample(const char *path, struct SDL_AudioSpec *spec, struct oshu::sample *sample); /** * Free the sample's PCM samples buffer. * * The sample object is left in an unspecified state. */ -void oshu_destroy_sample(struct oshu_sample *sample); +void destroy_sample(struct oshu::sample *sample); /** \} */ + +} diff --git a/include/audio/stream.h b/include/audio/stream.h index f947dbb..3450ec4 100644 --- a/include/audio/stream.h +++ b/include/audio/stream.h @@ -5,6 +5,18 @@ #pragma once +/* + * Forward declaration of the ffmpeg structures to avoid including big headers. + */ +struct AVFormatContext; +struct AVCodec; +struct AVStream; +struct AVCodecContext; +struct AVFrame; +struct SwrContext; + +namespace oshu { + /** * \defgroup audio_stream Stream * \ingroup audio @@ -41,15 +53,6 @@ * \{ */ -/* - * Forward declaration of the ffmpeg structures to avoid including big headers. - */ -struct AVFormatContext; -struct AVCodec; -struct AVStream; -struct AVCodecContext; -struct AVFrame; - /** * An audio stream, from its demuxer and decoder to its output device. * @@ -57,7 +60,7 @@ struct AVFrame; * #sample_rate when setting up the audio output device, and the * #current_timestamp to know the current stream position. */ -struct oshu_stream { +struct stream { /** * The libavformat demuxer, handling the I/O aspects. */ @@ -106,7 +109,7 @@ struct oshu_stream { struct SwrContext *converter; /** * The sample rate of the output stream when read with - * #oshu_read_stream. + * #oshu::read_stream. * * It is set by the #converter, and in practice will always be the same * as the sample rate of the #decoder. @@ -143,14 +146,14 @@ struct oshu_stream { double current_timestamp; /** * How many samples per channel of the current #frame we've read using - * #oshu_read_stream. When this number is bigger than the number of + * #oshu::read_stream. When this number is bigger than the number of * samples per channel in the frame, we must request a new frame. */ int sample_index; /** * True when the end of the stream is reached. * - * Set to 1 by #oshu_read_stream when we receive an AVERROR_EOF code + * Set to 1 by #oshu::read_stream when we receive an AVERROR_EOF code * while trying to read a frame. */ int finished; @@ -162,9 +165,9 @@ struct oshu_stream { * \param url Path or URL to the media you want to play. * \param stream A null-initialized stream object. * - * \sa oshu_close_stream + * \sa oshu::close_stream */ -int oshu_open_stream(const char *url, struct oshu_stream *stream); +int open_stream(const char *url, struct oshu::stream *stream); /** * Read *nb_samples* float samples from an audio stream. @@ -181,9 +184,9 @@ int oshu_open_stream(const char *url, struct oshu_stream *stream); * means the end of the stream was reached, and further calls to this function * will return 0. On error, return -1. * - * \sa oshu_stream::finished + * \sa oshu::stream::finished */ -int oshu_read_stream(struct oshu_stream *stream, float *samples, int nb_samples); +int read_stream(struct oshu::stream *stream, float *samples, int nb_samples); /** * Seek the stream to the specifed target position in seconds. @@ -191,19 +194,21 @@ int oshu_read_stream(struct oshu_stream *stream, float *samples, int nb_samples) * If the target is negative, the stream is rewinded to its beginning. * * To determine the new position of the stream after seeking, use - * #oshu_stream::current_timestamp. + * #oshu::stream::current_timestamp. * - * You should probably use #oshu_seek_music instead. + * You should probably use #oshu::seek_music instead. * * \todo * There's often some kind of audio distortion glitch right after seeking. * */ -int oshu_seek_stream(struct oshu_stream *stream, double target); +int seek_stream(struct oshu::stream *stream, double target); /** * Close an audio stream, and free everything we can. */ -void oshu_close_stream(struct oshu_stream *stream); +void close_stream(struct oshu::stream *stream); /** \} */ + +} diff --git a/include/audio/track.h b/include/audio/track.h index 931014e..fe36a31 100644 --- a/include/audio/track.h +++ b/include/audio/track.h @@ -5,7 +5,9 @@ #pragma once -struct oshu_sample; +namespace oshu { + +struct sample; /** * \defgroup audio_track Track @@ -28,10 +30,10 @@ struct oshu_sample; * * Tracks may only play packed stereo float samples. * - * \sa oshu_start_track - * \sa oshu_stop_track + * \sa oshu::start_track + * \sa oshu::stop_track */ -struct oshu_track { +struct track { /** * The sample object the track is going to play. * @@ -40,11 +42,11 @@ struct oshu_track { * This pointer is automatically reset to NULL when the sample is done * playing. */ - struct oshu_sample *sample; + struct oshu::sample *sample; /** * The position in the #sample buffer, in samples per channel. * - * It is comprised between 0 and #oshu_sample::nb_samples, inclusive. + * It is comprised between 0 and #oshu::sample::nb_samples, inclusive. */ int cursor; /** @@ -55,7 +57,7 @@ struct oshu_track { float volume; /** * If true, the sample is looped over and over until - * #oshu_stop_track is called. + * #oshu::stop_track is called. */ int loop; }; @@ -67,9 +69,9 @@ struct oshu_track { * that is already playing something. Note that any previously playing sample * will stop playing. * - * \sa oshu_track + * \sa oshu::track */ -void oshu_start_track(struct oshu_track *track, struct oshu_sample *sample, float volume, int loop); +void start_track(struct oshu::track *track, struct oshu::sample *sample, float volume, int loop); /** * Stop the playback on a track. @@ -77,7 +79,7 @@ void oshu_start_track(struct oshu_track *track, struct oshu_sample *sample, floa * It gets useful when a sample is looping, as it wouldn't stop by itself * otherwise. */ -void oshu_stop_track(struct oshu_track *track); +void stop_track(struct oshu::track *track); /** * Mix a track on top of an audio stream. @@ -97,6 +99,8 @@ void oshu_stop_track(struct oshu_track *track); * when the stream is inactive, or less than *nb_samples* when the sample has * reached an end. */ -int oshu_mix_track(struct oshu_track *track, float *samples, int nb_samples); +int mix_track(struct oshu::track *track, float *samples, int nb_samples); /** \} */ + +} diff --git a/include/beatmap/beatmap.h b/include/beatmap/beatmap.h index addd9b5..36f80d6 100644 --- a/include/beatmap/beatmap.h +++ b/include/beatmap/beatmap.h @@ -7,7 +7,9 @@ #include "beatmap/path.h" -struct oshu_texture; +namespace oshu { + +struct texture; /** \defgroup beatmap Beatmap * @@ -40,11 +42,11 @@ struct oshu_texture; * The value of the constants match the way they're written as integers in the * beatmap. */ -enum oshu_mode { - OSHU_OSU_MODE = 0, - OSHU_TAIKO_MODE = 1, - OSHU_CATCH_THE_BEAT_MODE = 2, - OSHU_MANIA_MODE = 3, +enum mode { + OSU_MODE = 0, + TAIKO_MODE = 1, + CATCH_THE_BEAT_MODE = 2, + MANIA_MODE = 3, }; /** @@ -57,7 +59,7 @@ enum oshu_mode { * shiro rightfully said, you'd prefer families because families are good while * banks are evil. */ -enum oshu_sample_set_family { +enum sample_set_family { /** * The beatmap's hit objects often specifiy 0 as the sample set, * meaning we should use the inherited one. @@ -65,11 +67,11 @@ enum oshu_sample_set_family { * However, the parser should in these case replace 0 with the actual * value, so it should be used in an external module. */ - OSHU_NO_SAMPLE_SET = -1, - OSHU_AUTO_SAMPLE_SET = 0, - OSHU_NORMAL_SAMPLE_SET = 1, - OSHU_SOFT_SAMPLE_SET = 2, - OSHU_DRUM_SAMPLE_SET = 3, + NO_SAMPLE_SET = -1, + AUTO_SAMPLE_SET = 0, + NORMAL_SAMPLE_SET = 1, + SOFT_SAMPLE_SET = 2, + DRUM_SAMPLE_SET = 3, }; /** @@ -81,28 +83,28 @@ enum oshu_sample_set_family { * * They can be OR'd, so you should store them in an *int*. */ -enum oshu_sound_type { +enum sound_type { /** * The first bit is undocumented, but it stands for Normal according to * the source code of osu. * * 0 means None, so I guess it's a silent note. */ - OSHU_NORMAL_SOUND = 1, - OSHU_WHISTLE_SOUND = 2, - OSHU_FINISH_SOUND = 4, - OSHU_CLAP_SOUND = 8, + NORMAL_SOUND = 1, + WHISTLE_SOUND = 2, + FINISH_SOUND = 4, + CLAP_SOUND = 8, /** * OR this with your sound type to make it a hit sound. * * Note that it's set to 0, and therefore is theoritically optional. */ - OSHU_HIT_SOUND = 0, + HIT_SOUND = 0, /** * OR this with your sound type and you'll make it a sliding slider * sound. * - * Looks like only OSHU_NORMAL_SOUND and OSHU_WHISTLE_SOUND may be + * Looks like only oshu::NORMAL_SOUND and oshu::WHISTLE_SOUND may be * combined with these. * * Slider sounds are meant to be looped, unlike hit sounds. @@ -112,18 +114,18 @@ enum oshu_sound_type { * used by some beatmaps. It can't be a looping clap, right? Besides, * there's no such file as `sliderclap.wav`. */ - OSHU_SLIDER_SOUND = 0x80, + SLIDER_SOUND = 0x80, /** * AND this with your combined sound type to retrieve the sound type: - * #OSHU_NORMAL_SOUND, #OSHU_WHISTLE_SOUND, #OSHU_FINISH_SOUND, - * #OSHU_CLAP_SOUND. + * #oshu::NORMAL_SOUND, #oshu::WHISTLE_SOUND, #oshu::FINISH_SOUND, + * #oshu::CLAP_SOUND. */ - OSHU_SOUND_MASK = 0x7F, + SOUND_MASK = 0x7F, /** * AND this with your combined sound type to retrieve the target hit: - * #OSHU_HIT_SOUND, #OSHU_SLIDER_SOUND. + * #oshu::HIT_SOUND, #oshu::SLIDER_SOUND. */ - OSHU_SOUND_TARGET = 0x80, + SOUND_TARGET = 0x80, }; /** @@ -135,7 +137,7 @@ enum oshu_sound_type { * element's next element is the first element. Keep that in mind when looping * over it. */ -struct oshu_color { +struct color { /** * The identifier of the combo. * @@ -146,7 +148,7 @@ struct oshu_color { double red; double green; double blue; - struct oshu_color *next; + struct oshu::color *next; }; /** @@ -168,7 +170,7 @@ struct oshu_color { * The structure provides a #next field to make a linked list *in chronological * order* with respect to #offset. */ -struct oshu_timing_point { +struct timing_point { /** * \brief When the timing point starts, in seconds. * @@ -193,7 +195,7 @@ struct oshu_timing_point { /** * Default sample set to use in that timing section. */ - enum oshu_sample_set_family sample_set; + enum oshu::sample_set_family sample_set; /** * Index of the sample set. * @@ -228,24 +230,24 @@ struct oshu_timing_point { * * NULL for the last item. */ - struct oshu_timing_point *next; + struct oshu::timing_point *next; }; /** * Flags defining the type of a hit object. * - * To check if it's a circle, you should use `type & OSHU_CIRCLE_HIT` rather + * To check if it's a circle, you should use `type & oshu::CIRCLE_HIT` rather * than check for equality, because it will often be combined with - * #OSHU_NEW_HIT_COMBO. + * #oshu::NEW_HIT_COMBO. */ -enum oshu_hit_type { - OSHU_CIRCLE_HIT = 0b1, - OSHU_SLIDER_HIT = 0b10, - OSHU_NEW_HIT_COMBO = 0b100, - OSHU_SPINNER_HIT = 0b1000, - OSHU_COMBO_HIT_MASK = 0b1110000, /**< How many combos to skip. */ - OSHU_COMBO_HIT_OFFSET = 4, /**< How many bits to shift. */ - OSHU_HOLD_HIT = 0b10000000, /**< Mania mode only. */ +enum hit_type { + CIRCLE_HIT = 0b1, + SLIDER_HIT = 0b10, + NEW_HIT_COMBO = 0b100, + SPINNER_HIT = 0b1000, + COMBO_HIT_MASK = 0b1110000, /**< How many combos to skip. */ + COMBO_HIT_OFFSET = 4, /**< How many bits to shift. */ + HOLD_HIT = 0b10000000, /**< Mania mode only. */ }; /** @@ -255,33 +257,33 @@ enum oshu_hit_type { * want to maintain a parallel linked list to keep track of the state of every * hit. */ -enum oshu_hit_state { +enum hit_state { /** * The default state. * * The hit has never been clicked not skipped nor anything. This also * means the user can interact with the hit object. */ - OSHU_INITIAL_HIT = 0, + INITIAL_HIT = 0, /** * The slider is currently being held. * * Only meaningful for spinners and mania hold notes. */ - OSHU_SLIDING_HIT, + SLIDING_HIT, /** * The hit was clicked on time. */ - OSHU_GOOD_HIT, + GOOD_HIT, /** * The hit was missed, either because it wasn't clicked at the right * time, or because it wasn't clicked at all. */ - OSHU_MISSED_HIT, + MISSED_HIT, /** * A hit obejct may be skipped when the user seeks forward. */ - OSHU_SKIPPED_HIT, + SKIPPED_HIT, /** * Hit objects are marked unknown when the current game mode cannot * interpret it. @@ -290,7 +292,7 @@ enum oshu_hit_state { * other mode than osu. Also spinners in osu mode because they're not * supported yet. */ - OSHU_UNKNOWN_HIT, + UNKNOWN_HIT, }; /** @@ -306,11 +308,11 @@ enum oshu_hit_state { * simple type. It would be easier to have a structure for 1 sound, and * associate a list of sounds to hit objects. The downside is that it would * cause a memory indirection, and require more memory. The upside is that the - * #oshu_hit_sound to filename conversion is easier. As a compromise, if + * #oshu::hit_sound to filename conversion is easier. As a compromise, if * performance matters, the list can be a structure like the current one, with * an iterator to convert the compacted multi-sound pack to simple sounds. */ -struct oshu_hit_sound { +struct hit_sound { /** * Sample set to use when playing the hit sound. * @@ -318,13 +320,13 @@ struct oshu_hit_sound { * replace that value by the sample set to use, computed from the * context. * - * \sa oshu_timing_point::sample_set + * \sa oshu::timing_point::sample_set */ - enum oshu_sample_set_family sample_set; + enum oshu::sample_set_family sample_set; /** - * Combination of flags from #oshu_sound_type. + * Combination of flags from #oshu::sound_type. * - * To play the normal sound, #OSHU_NORMAL_SOUND must be enabled. + * To play the normal sound, #oshu::NORMAL_SOUND must be enabled. * * The sample set to use for these additions is defined by the * #additions_set field, while the normal sound's sample set is defined @@ -336,7 +338,7 @@ struct oshu_hit_sound { * * It's similar to #sample_set. */ - enum oshu_sample_set_family additions_set; + enum oshu::sample_set_family additions_set; /** * For a given #sample_set family, alternative samples may be used. * @@ -350,22 +352,22 @@ struct oshu_hit_sound { /** * Volume of the sample, from 0 to 100%. * - * \sa #oshu_timing_point::volume + * \sa #oshu::timing_point::volume */ double volume; }; /** - * Parts of a #oshu_hit specific to slider objects. + * Parts of a #oshu::hit specific to slider objects. * * The most complex part of the slider is its path. The way it should be parsed - * and represented is explained in #oshu_path. + * and represented is explained in #oshu::path. */ -struct oshu_slider { +struct slider { /** * Path the slider follows. */ - struct oshu_path path; + struct oshu::path path; /** * > repeat (Integer) is the number of times a player will go over the * > slider. A value of 1 will not repeat, 2 will repeat once, 3 twice, @@ -383,43 +385,43 @@ struct oshu_slider { * #duration. * * It is computed from the pixel length in the beatmap file, - * #oshu_difficulty::slider_multiplier, and - * #oshu_timing_point::beat_duration. + * #oshu::difficulty::slider_multiplier, and + * #oshu::timing_point::beat_duration. */ double duration; /** * Array of sounds to play over each circle. * - * #oshu_hit::sound contains the sample for the body of the slider, not + * #oshu::hit::sound contains the sample for the body of the slider, not * the edges of the slider. * * The size of the array is #repeat + 1. A non-repeating slider will * have 2 sounds. For a repeating slider, it implies the sound for the * same circle will change every time it is repeated. */ - struct oshu_hit_sound *sounds; + struct oshu::hit_sound *sounds; }; /** - * Parts of a #oshu_hit specific to spinner objects. + * Parts of a #oshu::hit specific to spinner objects. */ -struct oshu_spinner { +struct spinner { /** * Time in seconds when the spinner ends. * - * Relative to the song's position, like #oshu_hit::time. + * Relative to the song's position, like #oshu::hit::time. */ double end_time; }; /** - * Parts of a #oshu_hit specific to osu!mania hold note objects. + * Parts of a #oshu::hit specific to osu!mania hold note objects. */ -struct oshu_hold_note { +struct hold_note { /** * Time in seconds when the hold note ends. * - * Relative to the song's position, like #oshu_hit::time. + * Relative to the song's position, like #oshu::hit::time. */ double end_time; }; @@ -437,14 +439,14 @@ struct oshu_hold_note { * * The structure for a slider is * `x,y,time,type,hitSound,sliderType|curvePoints,repeat,pixelLength,edgeHitsounds,edgeAdditions,addition`. - * See #oshu_slider. + * See #oshu::slider. * * The structure for a spinner is `x,y,time,type,hitSound,endTime,addition`. - * See #oshu_spinner. + * See #oshu::spinner. * * The structure for a osu!mania hold note is * `x,y,time,type,hitSound,endTime:addition`. - * See #oshu_hold_note. + * See #oshu::hold_note. * * For every type, the addition is structured like * `sampleSet:additions:customIndex:sampleVolume:filename`. @@ -452,13 +454,13 @@ struct oshu_hold_note { * * For details, look at the corresponding field in this structure. */ -struct oshu_hit { +struct hit { /** * Coordinates of the hit object in game coordinates. * * From (0, 0) for top-left to (512, 384) for bottom-right. */ - oshu_point p; + oshu::point p; /** * \brief When the hit object should be clicked, in seconds. * @@ -475,7 +477,7 @@ struct oshu_hit { * Type of the hit object, like circle, slider, spinner, and a few * extra information. * - * Combination of flags from #oshu_hit_type. + * Combination of flags from #oshu::hit_type. */ int type; /** @@ -483,28 +485,28 @@ struct oshu_hit { * * Sliders have some more sounds on the edges, don't forget them. */ - struct oshu_hit_sound sound; + struct oshu::hit_sound sound; /** * Type-specific properties. */ union { - struct oshu_slider slider; - struct oshu_spinner spinner; - struct oshu_hold_note hold_note; + struct oshu::slider slider; + struct oshu::spinner spinner; + struct oshu::hold_note hold_note; }; /** * \brief Timing point in effect when the hit object should be clicked. * * It is used by the parser to compute the duration of sliders, and may * also be needed by the game or graphics module to handle the slider - * ticks, using the #oshu_timing_point::beat_duration property. + * ticks, using the #oshu::timing_point::beat_duration property. */ - struct oshu_timing_point *timing_point; + struct oshu::timing_point *timing_point; /** * \brief Combo identifier. * * Starts at 0 at the beginning of the beatmap, and increases at every - * hit object with #OSHU_NEW_HIT_COMBO. Its value may increase by more + * hit object with #oshu::NEW_HIT_COMBO. Its value may increase by more * than 1 if the hit object specifies a non-zero combo skip. * * Two hit objects belong in the same combo if and only if they have @@ -515,7 +517,7 @@ struct oshu_hit { * \brief Sequence number of the hit inside its combo. * * The first hit object will have the sequence number 1, the next one - * 2, and so on until a hit object's type includes #OSHU_NEW_HIT_COMBO, + * 2, and so on until a hit object's type includes #oshu::NEW_HIT_COMBO, * which resets the sequence number to 1. */ int combo_seq; @@ -526,13 +528,13 @@ struct oshu_hit { * It's closely linked to #combo, and increases in the same way, taking * into account combo skips. */ - struct oshu_color *color; + struct oshu::color *color; /** * Dynamic state of the hit. Whether it was clicked or not. * - * It should be left to 0 (#OSHU_INITIAL_HIT) by the parser. + * It should be left to 0 (#oshu::INITIAL_HIT) by the parser. */ - enum oshu_hit_state state; + enum oshu::hit_state state; /** * Graphical texture for the hit object. * @@ -542,28 +544,28 @@ struct oshu_hit { * \todo * The GUI module should manage its own texture cache. */ - struct oshu_texture *texture; + struct oshu::texture *texture; /** * Pointer to the previous element of the linked list. * * NULL if it's the first element. */ - struct oshu_hit *previous; + struct oshu::hit *previous; /** * Pointer to the next element of the linked list. * * NULL if it's the last element. */ - struct oshu_hit *next; + struct oshu::hit *next; }; /** * Tell the time offset, in seconds, when the hit object ends. * - * For a circle, that's the same as #oshu_hit::time, but for a slider, spinner + * For a circle, that's the same as #oshu::hit::time, but for a slider, spinner * or hold note, it's that offset plus the duration of the hit. */ -double oshu_hit_end_time(struct oshu_hit *hit); +double hit_end_time(struct oshu::hit *hit); /** * Compute the last point of a hit object. @@ -572,7 +574,7 @@ double oshu_hit_end_time(struct oshu_hit *hit); * the position at the end of the slide. If the slider repeats, it may be the * same as the starting point though. */ -oshu_point oshu_end_point(struct oshu_hit *hit); +oshu::point end_point(struct oshu::hit *hit); /** * \brief Complete definition of the [Metadata] section. @@ -585,7 +587,7 @@ oshu_point oshu_end_point(struct oshu_hit *hit); * * All the strings are encoded in UTF-8. */ -struct oshu_metadata { +struct metadata { /** * \brief ASCII representation of the title. * @@ -654,7 +656,7 @@ struct oshu_metadata { * Looks like 5 in the beatmap file usually means average. Higher than 5 is * harder, and lower than 5 is easier. */ -struct oshu_difficulty { +struct difficulty { /** * \brief Radius of the hit object's circles, in pixels. * @@ -786,9 +788,9 @@ struct oshu_difficulty { * * Most string values are dynamically allocated inside this structure. Some * linked structures are allocated on the heap too. Make sure you free - * everything with #oshu_destroy_beatmap. + * everything with #oshu::destroy_beatmap. */ -struct oshu_beatmap { +struct beatmap { /** * The version written in the header of every osu beatmap file. * Today it's something around 14. @@ -848,24 +850,24 @@ struct oshu_beatmap { * sample set, so you must check the hit object first before resorting * to this variable. * - * Let's default to #OSHU_SOFT_SAMPLE_SET. + * Let's default to #oshu::SOFT_SAMPLE_SET. */ - enum oshu_sample_set_family sample_set; + enum oshu::sample_set_family sample_set; /** * The game mode. Today, only the standard osu! game is supported. * * It is written as a number between 0 and 3, and matches the values in - * #oshu_mode. + * #oshu::mode. */ - enum oshu_mode mode; + enum oshu::mode mode; /** * \brief [Metadata] section. */ - struct oshu_metadata metadata; + struct oshu::metadata metadata; /** * \brief [Difficulty] section. */ - struct oshu_difficulty difficulty; + struct oshu::difficulty difficulty; /** * \brief Path to the background picture. * @@ -883,15 +885,15 @@ struct oshu_beatmap { * * It's a linked list, in chronological order. */ - struct oshu_timing_point *timing_points; + struct oshu::timing_point *timing_points; /** * \brief [Colours] section. * - * It's a circular linked list, as described in #oshu_color. + * It's a circular linked list, as described in #oshu::color. * * \sa color_count */ - struct oshu_color *colors; + struct oshu::color *colors; /** * Number of colors in the #colors list. */ @@ -907,7 +909,7 @@ struct oshu_beatmap { * *next* and *previous* pointers. This lets you ensure your hit cursor * is never null. */ - struct oshu_hit *hits; + struct oshu::hit *hits; }; /** @@ -916,7 +918,7 @@ struct oshu_beatmap { * On failure, the content of *beatmap* is undefined, but any dynamically * allocated internal memory is freed. */ -int oshu_load_beatmap(const char *path, struct oshu_beatmap *beatmap); +int load_beatmap(const char *path, struct oshu::beatmap *beatmap); /** * Parse the first sections of a beatmap to get the metadata and difficulty @@ -924,24 +926,26 @@ int oshu_load_beatmap(const char *path, struct oshu_beatmap *beatmap); * * This function should load the following fields: * - * - #oshu_beatmap::audio_filename, - * - #oshu_beatmap::background_filename, - * - #oshu_beatmap::mode, - * - #oshu_beatmap::metadata, - * - #oshu_beatmap::difficulty. + * - #oshu::beatmap::audio_filename, + * - #oshu::beatmap::background_filename, + * - #oshu::beatmap::mode, + * - #oshu::beatmap::metadata, + * - #oshu::beatmap::difficulty. * * However, because most fields may be missing from the beatmap, you cannot * assume they all have non-NULL values. * - * The aim of this function, compared to #oshu_load_beatmap, is not to load the + * The aim of this function, compared to #oshu::load_beatmap, is not to load the * timing points, colors, and hit objects, which contain most of the beatmap's * data. */ -int oshu_load_beatmap_headers(const char *path, struct oshu_beatmap *beatmap); +int load_beatmap_headers(const char *path, struct oshu::beatmap *beatmap); /** * Free any object dynamically allocated inside the beatmap. */ -void oshu_destroy_beatmap(struct oshu_beatmap *beatmap); +void destroy_beatmap(struct oshu::beatmap *beatmap); /** \} */ + +} diff --git a/include/beatmap/path.h b/include/beatmap/path.h index 254dcea..fe45956 100644 --- a/include/beatmap/path.h +++ b/include/beatmap/path.h @@ -7,6 +7,8 @@ #include "core/geometry.h" +namespace oshu { + /** * \defgroup beatmap_path Path * \ingroup beatmap @@ -20,7 +22,7 @@ /** * A simple line, with a start point and end point. * - * Used by #OSHU_LINEAR_PATH segments. + * Used by #oshu::LINEAR_PATH segments. * * It's formally the same as a degree 1 Bézier curve, but we'll keep that type * to make experiments. @@ -28,15 +30,15 @@ * \todo * Support polyline paths. */ -struct oshu_line { - oshu_point start; - oshu_point end; +struct line { + oshu::point start; + oshu::point end; }; /** * An arc, defined as a section of a circle. * - * Used by #OSHU_PERFECT_PATH segments. + * Used by #oshu::PERFECT_PATH segments. * * In the beatmaps, these arc are called *perfect* and are defined with 3 * points. The first point beging the start of the arc, the second one (called @@ -49,10 +51,10 @@ struct oshu_line { * radius, and a pair of angles in radian where 0 is the the rightmost point, * like we do in common trigonometry. * - * \sa oshu_build_arc + * \sa oshu::build_arc */ -struct oshu_arc { - oshu_point center; +struct arc { + oshu::point center; double radius; double start_angle; double end_angle; @@ -61,7 +63,7 @@ struct oshu_arc { /** * \brief Compute an arc of circle from 3 points. * - * See #oshu_arc to see how arcs are defined in oshu!. + * See #oshu::arc to see how arcs are defined in oshu!. * * In beatmaps, the arcs are defined in a hard to manipulate way, so this * function in the geometry module is meant to help the parser generate arcs. @@ -93,7 +95,7 @@ struct oshu_arc { * * \return 0 on success, -1 if the arc computation failed. */ -int oshu_build_arc(oshu_point a, oshu_point b, oshu_point c, struct oshu_arc *arc); +int build_arc(oshu::point a, oshu::point b, oshu::point c, struct oshu::arc *arc); /** * A Bézier path, made up of one or many Bézier segments. @@ -101,7 +103,7 @@ int oshu_build_arc(oshu_point a, oshu_point b, oshu_point c, struct oshu_arc *ar * A Bézier segment is defined by its degree, and a number of control points * equal to its degree plus one. * - * Used by #OSHU_BEZIER_PATH segments. + * Used by #oshu::BEZIER_PATH segments. * * For example, a degree 2 Bézier segment (called *quadratic*) has 3 control * points. @@ -133,9 +135,9 @@ int oshu_build_arc(oshu_point a, oshu_point b, oshu_point c, struct oshu_arc *ar * and 1, and represents how far the point is from the start. For example, * l=1/2 means that the point is at the middle of the curve, as opposed to * t=1/2 which means, for quadratic curves, that the point is closest to the - * middle control point. See #oshu_normalize_path. + * middle control point. See #oshu::normalize_path. */ -struct oshu_bezier { +struct bezier { /** * How many segments the Bézier path contains. */ @@ -150,7 +152,7 @@ struct oshu_bezier { * This implies the *n*th segment has `indexes[n+1] - indexes[n]` * points, and that its degree is `indexes[n+1] - indexes[n] - 1`. * - * To reuse the example in #oshu_bezier, since all the segments are + * To reuse the example in #oshu::bezier, since all the segments are * quadratic, the indices are [0, 3, 6, 9]. * * The size of the indices array must be *segment_count + 1*. @@ -180,7 +182,7 @@ struct oshu_bezier { * * For the normalization process, it must be dynamically allocated. */ - oshu_point *control_points; + oshu::point *control_points; /** * Translation map from l-coordinates to t-coordinates. * @@ -190,7 +192,7 @@ struct oshu_bezier { * For any point such that i / n ≤ l ≤ (i + 1) / n, compute a weighted * average between anchors[i] and anchors[i+1]. * - * \sa oshu_normalize_path + * \sa oshu::normalize_path */ double anchors[64]; }; @@ -200,37 +202,37 @@ struct oshu_bezier { * * Their value is the letter that appears in the beatmaps to identify the type. */ -enum oshu_path_type { - OSHU_LINEAR_PATH = 'L', - OSHU_PERFECT_PATH = 'P', - OSHU_BEZIER_PATH = 'B', - OSHU_CATMULL_PATH = 'C', +enum path_type { + LINEAR_PATH = 'L', + PERFECT_PATH = 'P', + BEZIER_PATH = 'B', + CATMULL_PATH = 'C', }; /** - * The linear paths (#OSHU_LINEAR_PATH) are the simplest and only have 2 - * points. See #oshu_line. + * The linear paths (#oshu::LINEAR_PATH) are the simplest and only have 2 + * points. See #oshu::line. * - * Perfect paths (#OSHU_PERFECT_PATH) are bits of circle and have 3 points. + * Perfect paths (#oshu::PERFECT_PATH) are bits of circle and have 3 points. * The 3 non-aligned points define a circle in a unique way. The perfect path * is the part of that circle that starts with the first point, passes through - * the second point, and ends at the third point. See #oshu_arc. + * the second point, and ends at the third point. See #oshu::arc. * - * Bézier paths (#OSHU_BEZIER_PATH) have 2 to an arbitrary large number of + * Bézier paths (#oshu::BEZIER_PATH) have 2 to an arbitrary large number of * control points. A 2-point Bézier path is nothing but a linear path. A * 3-point Bézier path is a quadratic curve, also called a parabola. Things get * interesting with the 4-point cubic Bézier curve, which is the one you see in - * most painting tools. See #oshu_bezier. + * most painting tools. See #oshu::bezier. * - * Catmull paths (#OSHU_CATMULL_PATH) are officially deprecated, but we should + * Catmull paths (#oshu::CATMULL_PATH) are officially deprecated, but we should * support them someday in order to support old beatmaps. */ -struct oshu_path { - enum oshu_path_type type; +struct path { + enum oshu::path_type type; union { - struct oshu_line line; /**< For #OSHU_LINEAR_PATH. */ - struct oshu_arc arc; /**< For #OSHU_PERFECT_PATH. */ - struct oshu_bezier bezier; /**< For #OSHU_BEZIER_PATH. */ + struct oshu::line line; /**< For #oshu::LINEAR_PATH. */ + struct oshu::arc arc; /**< For #oshu::PERFECT_PATH. */ + struct oshu::bezier bezier; /**< For #oshu::BEZIER_PATH. */ }; }; @@ -244,7 +246,7 @@ struct oshu_path { * In most case, this function will shrink the path, because the actual length * is greater than the one specified in the beatmap. */ -void oshu_normalize_path(struct oshu_path *path, double length); +void normalize_path(struct oshu::path *path, double length); /** * Express the path in floating t-coordinates. @@ -284,7 +286,7 @@ void oshu_normalize_path(struct oshu_path *path, double length); * defined in the C standard library, by 2. * */ -oshu_point oshu_path_at(struct oshu_path *path, double t); +oshu::point path_at(struct oshu::path *path, double t); /** * Compute the smallest box such that the path fits in. @@ -298,6 +300,8 @@ oshu_point oshu_path_at(struct oshu_path *path, double t); * 2. ∀t imag(top_left) ≤ imag(at(t)) ≤ imag(bottom_right) * */ -void oshu_path_bounding_box(struct oshu_path *path, oshu_point *top_left, oshu_point *bottom_right); +void path_bounding_box(struct oshu::path *path, oshu::point *top_left, oshu::point *bottom_right); /** \} */ + +} diff --git a/include/core/geometry.h b/include/core/geometry.h index 705e2bf..db3037f 100644 --- a/include/core/geometry.h +++ b/include/core/geometry.h @@ -7,12 +7,16 @@ #include +namespace oshu { + /** * \defgroup core_geometry Geometry * \ingroup core * * \brief * Common 2D types. + * + * \{ */ /** @@ -20,21 +24,25 @@ * * The coordinate system is arbitrary. */ -using oshu_point = std::complex; +using point = std::complex; /** * A 2D vector. * - * This is distinct from #oshu_point for readability. + * This is distinct from #oshu::point for readability. */ -using oshu_vector = std::complex; +using vector = std::complex; /** * A 2D size. */ -using oshu_size = std::complex; +using size = std::complex; /** * Return the width / height ratio of a size. */ -double oshu_ratio(oshu_size size); +double ratio(oshu::size size); + +/* } */ + +} diff --git a/include/game/base.h b/include/game/base.h index e54b1e0..1314b0c 100644 --- a/include/game/base.h +++ b/include/game/base.h @@ -64,17 +64,17 @@ class game_base : public game_mode { * \todo * Take the beatmap by reference when the game state is constructed. */ - struct oshu_beatmap beatmap {}; - struct oshu_audio audio {}; - struct oshu_sound_library library {}; - struct oshu_clock clock {}; + struct oshu::beatmap beatmap {}; + struct oshu::audio audio {}; + struct oshu::sound_library library {}; + struct oshu::clock clock {}; int autoplay {}; bool paused {}; /** * Pointer to the next clickable hit. * * Any hit before this cursor has already been dealt with, and its - * state should be anything but #OSHU_INITIAL_HIT. + * state should be anything but #oshu::INITIAL_HIT. * * On the contrary, any hit past this cursor is *usually* in its * initial state, but that's not an absolute necessity. The user might @@ -84,16 +84,14 @@ class game_base : public game_mode { * This cursor is mostly here to speed things up. It is technically * okay for it to always point to the first hit, but the performance * will suffer. It's ideal position is right at the first *fresh* - * (= #OSHU_INITIAL_HIT) hit object. + * (= #oshu::INITIAL_HIT) hit object. * * With the two sentinels in the beatmap's hits linked list, this * cursor is never null, even after the last hit was played. */ - struct oshu_hit *hit_cursor {}; + struct oshu::hit *hit_cursor {}; }; -} - /** * \defgroup game_helpers Helpers * \ingroup game @@ -112,16 +110,16 @@ class game_base : public game_mode { * * For long notes like sliders, the end time is used, not the start time. * - * \sa oshu_look_hit_up + * \sa oshu::look_hit_up */ -struct oshu_hit* oshu_look_hit_back(struct oshu::game_base *game, double offset); +struct oshu::hit* look_hit_back(struct oshu::game_base *game, double offset); /** * Find the last hit object before *now + offset*. * - * This is analogous to #oshu_look_hit_back. + * This is analogous to #oshu::look_hit_back. */ -struct oshu_hit* oshu_look_hit_up(struct oshu::game_base *game, double offset); +struct oshu::hit* look_hit_up(struct oshu::game_base *game, double offset); /** * Return the next relevant hit. @@ -131,11 +129,13 @@ struct oshu_hit* oshu_look_hit_up(struct oshu::game_base *game, double offset); * The final null hit is considered relevant in order to ensure this function * always return something. */ -struct oshu_hit* oshu_next_hit(struct oshu::game_base *game); +struct oshu::hit* next_hit(struct oshu::game_base *game); /** - * Like #oshu_next_hit, but in the other direction. + * Like #oshu::next_hit, but in the other direction. */ -struct oshu_hit* oshu_previous_hit(struct oshu::game_base *game); +struct oshu::hit* previous_hit(struct oshu::game_base *game); /** \} */ + +} diff --git a/include/game/clock.h b/include/game/clock.h index f9bb078..3acc8bc 100644 --- a/include/game/clock.h +++ b/include/game/clock.h @@ -1,4 +1,6 @@ /** + * + * } * \file game/clock.h * \ingroup game_clock */ @@ -6,8 +8,8 @@ #pragma once namespace oshu { + class game_base; -} /** * \defgroup game_clock Clock @@ -22,7 +24,7 @@ class game_base; /** * Keep track of various aspects of the elapsing time. */ -struct oshu_clock { +struct clock { /** * The current time in seconds. * @@ -62,7 +64,7 @@ struct oshu_clock { double system; }; -void oshu_initialize_clock(struct oshu::game_base *game); +void initialize_clock(struct oshu::game_base *game); /** * Update the game clock. @@ -81,6 +83,8 @@ void oshu_initialize_clock(struct oshu::game_base *game); * lead-in phase, because the audio starts when the *now* clock becomes * positive, while the audio clock will be null at that moment. */ -void oshu_update_clock(struct oshu::game_base *game); +void update_clock(struct oshu::game_base *game); /** \} */ + +} diff --git a/include/game/controls.h b/include/game/controls.h index 075c5d8..b039e40 100644 --- a/include/game/controls.h +++ b/include/game/controls.h @@ -11,6 +11,8 @@ struct SDL_Keysym; +namespace oshu { + /** * \defgroup game_controls Controls * \ingroup game @@ -46,16 +48,16 @@ struct SDL_Keysym; * Keys on the left hand are negative, while keys on the right hand are * positive, making it easy to test which hand a constant belongs to. */ -enum oshu_finger { - OSHU_LEFT_PINKY = -4, - OSHU_LEFT_RING = -3, - OSHU_LEFT_MIDDLE = -2, - OSHU_LEFT_INDEX = -1, - OSHU_THUMBS = 0, - OSHU_RIGHT_INDEX = 1, - OSHU_RIGHT_MIDDLE = 2, - OSHU_RIGHT_RING = 3, - OSHU_RIGHT_PINKY = 4, +enum finger { + LEFT_PINKY = -4, + LEFT_RING = -3, + LEFT_MIDDLE = -2, + LEFT_INDEX = -1, + THUMBS = 0, + RIGHT_INDEX = 1, + RIGHT_MIDDLE = 2, + RIGHT_RING = 3, + RIGHT_PINKY = 4, /** * Playing with the mouse is discouraged, but if you really wanna be * able to catch the clicks, this is for you. In particular, it is nice @@ -66,11 +68,11 @@ enum oshu_finger { * modes, however, have no business knowing that, and should handle * clicks like keys. */ - OSHU_LEFT_BUTTON = -5, + LEFT_BUTTON = -5, /** - * See #OSHU_LEFT_BUTTON. + * See #oshu::LEFT_BUTTON. */ - OSHU_RIGHT_BUTTON = 5, + RIGHT_BUTTON = 5, /** * Special value when a key couldn't be translated. * @@ -83,17 +85,17 @@ enum oshu_finger { * (who knows?) you should have a sane default case for keys your * module doesn't handle, if relevant. */ - OSHU_UNKNOWN_KEY = -100, + UNKNOWN_KEY = -100, }; /** - * Translate an SDL keysym to its finger in #oshu_finger. + * Translate an SDL keysym to its finger in #oshu::finger. * * The physical key code is used for the translation, to guarantee layout agnosticity. * - * If the key doesn't match a finger, return #OSHU_UNKNOWN_KEY. + * If the key doesn't match a finger, return #oshu::UNKNOWN_KEY. */ -enum oshu_finger oshu_translate_key(struct SDL_Keysym *keysym); +enum oshu::finger translate_key(struct SDL_Keysym *keysym); /** * Map functions to SDL keycodes. @@ -103,25 +105,16 @@ enum oshu_finger oshu_translate_key(struct SDL_Keysym *keysym); * * Compare the keys with `SDL_Event.key.keysym.sym`. */ -enum oshu_control_key { - OSHU_QUIT_KEY = SDLK_q, - OSHU_PAUSE_KEY = SDLK_ESCAPE, - OSHU_REWIND_KEY = SDLK_PAGEUP, - OSHU_FORWARD_KEY = SDLK_PAGEDOWN, +enum control_key { + QUIT_KEY = SDLK_q, + PAUSE_KEY = SDLK_ESCAPE, + REWIND_KEY = SDLK_PAGEUP, + FORWARD_KEY = SDLK_PAGEDOWN, }; -/** \} */ - -namespace oshu { - -/** - * \ingroup game_controls - * \{ - */ - struct mouse { virtual ~mouse() = default; - virtual oshu_point position() = 0; + virtual oshu::point position() = 0; }; /** \} */ diff --git a/include/game/mode.h b/include/game/mode.h index e67be5e..ca1b920 100644 --- a/include/game/mode.h +++ b/include/game/mode.h @@ -47,19 +47,19 @@ struct game_mode { * key used by the game module itself, like escape or space to pause, q * to quit, &c. Same goes for mouse buttons. * - * If you need the mouse position, use #oshu_get_mouse to have it in + * If you need the mouse position, use #oshu::get_mouse to have it in * game coordinates. * * This callback isn't called when the game is paused or on autoplay. * * \sa release */ - virtual int press(enum oshu_finger key) = 0; + virtual int press(enum oshu::finger key) = 0; /** * See #press. */ - virtual int release(enum oshu_finger key) = 0; + virtual int release(enum oshu::finger key) = 0; /** * Release any held object, like sliders or hold notes. diff --git a/include/game/osu.h b/include/game/osu.h index a68cdde..5d8abe8 100644 --- a/include/game/osu.h +++ b/include/game/osu.h @@ -9,6 +9,8 @@ #include +namespace oshu { + /** * \defgroup game_osu Osu * \ingroup game @@ -27,21 +29,23 @@ struct osu_game : public oshu::game_base { * * NULL most of the time. */ - struct oshu_hit *current_slider {}; + struct oshu::hit *current_slider {}; /** * Keyboard key or mouse button associated to the #current_slider. * * When the #current_slider is NULL, the value of this field is * irrelevant. */ - enum oshu_finger held_key = {}; + enum oshu::finger held_key = {}; std::shared_ptr mouse {}; int check() override; int check_autoplay() override; - int press(enum oshu_finger key) override; - int release(enum oshu_finger key) override; + int press(enum oshu::finger key) override; + int release(enum oshu::finger key) override; int relinquish() override; }; /** \} */ + +} diff --git a/include/game/tty.h b/include/game/tty.h index c80cc21..fd095e8 100644 --- a/include/game/tty.h +++ b/include/game/tty.h @@ -6,8 +6,8 @@ #pragma once namespace oshu { + class game_base; -} /** * \defgroup game_tty TTY @@ -37,7 +37,7 @@ class game_base; * * Show the beatmap's metadata and difficulty information. */ -void oshu_welcome(struct oshu::game_base *game); +void welcome(struct oshu::game_base *game); /** * Show the state of the game (paused/playing) and the current song position. @@ -49,13 +49,15 @@ void oshu_welcome(struct oshu::game_base *game); * glitches. If you write `foo\rx`, you get `xoo`. This is the reason the * Paused string literal has an extra space. */ -void oshu_print_state(struct oshu::game_base *game); +void print_state(struct oshu::game_base *game); /** * Congratulate the user when the beatmap is over. * * Show the number of good hits and bad hits. */ -void oshu_congratulate(struct oshu::game_base *game); +void congratulate(struct oshu::game_base *game); /** \} */ + +} diff --git a/include/library/beatmaps.h b/include/library/beatmaps.h index 99dc27c..e4906ae 100644 --- a/include/library/beatmaps.h +++ b/include/library/beatmaps.h @@ -44,14 +44,14 @@ namespace oshu { /** * Gather the key information of a beatmap. * - * To save resources, it uses #oshu_load_beatmap_headers. + * To save resources, it uses #oshu::load_beatmap_headers. * * \todo * Reuse the beatmap structure? */ struct beatmap_entry { explicit beatmap_entry(const std::string &path); - oshu_mode mode; + oshu::mode mode; /** * Difficulty indicator. * diff --git a/include/ui/audio.h b/include/ui/audio.h index 3487d87..30cc566 100644 --- a/include/ui/audio.h +++ b/include/ui/audio.h @@ -5,8 +5,10 @@ #pragma once -struct oshu_display; -struct oshu_stream; +namespace oshu { + +struct display; +struct stream; /** * \defgroup ui_audio Audio @@ -23,13 +25,13 @@ struct oshu_stream; * * It appears as a full-width transparent bar that fills as the song is played. * - * \sa oshu_create_audio_progress_bar - * \sa oshu_destroy_audio_progress_bar - * \sa oshu_show_audio_progress_bar + * \sa oshu::create_audio_progress_bar + * \sa oshu::destroy_audio_progress_bar + * \sa oshu::show_audio_progress_bar */ -struct oshu_audio_progress_bar { - struct oshu_display *display; - struct oshu_stream *stream; +struct audio_progress_bar { + struct oshu::display *display; + struct oshu::stream *stream; }; /** @@ -39,12 +41,12 @@ struct oshu_audio_progress_bar { * * The stream must have a non-zero duration. */ -int oshu_create_audio_progress_bar(struct oshu_display *display, struct oshu_stream *stream, struct oshu_audio_progress_bar *bar); +int create_audio_progress_bar(struct oshu::display *display, struct oshu::stream *stream, struct oshu::audio_progress_bar *bar); /** * Display the progress bar at the bottom of the screen. */ -void oshu_show_audio_progress_bar(struct oshu_audio_progress_bar *bar); +void show_audio_progress_bar(struct oshu::audio_progress_bar *bar); /** * Destroy an audio progress bar. @@ -52,6 +54,8 @@ void oshu_show_audio_progress_bar(struct oshu_audio_progress_bar *bar); * Today, this is a no-op. It is still provided for interface consistency with * the other widgets. */ -void oshu_destroy_audio_progress_bar(struct oshu_audio_progress_bar *bar); +void destroy_audio_progress_bar(struct oshu::audio_progress_bar *bar); /** \} */ + +} diff --git a/include/ui/background.h b/include/ui/background.h index 19b0e6c..99c55d6 100644 --- a/include/ui/background.h +++ b/include/ui/background.h @@ -7,7 +7,9 @@ #include "video/texture.h" -struct oshu_display; +namespace oshu { + +struct display; /** * \defgroup ui_background Background @@ -16,7 +18,7 @@ struct oshu_display; * \brief * Picture background. * - * To enable this module, the #OSHU_SHOW_BACKGROUND flag must be enabled for + * To enable this module, the #oshu::SHOW_BACKGROUND flag must be enabled for * the display. Otherwise, this module behaves like a stub and does nothing. * * \{ @@ -32,7 +34,7 @@ struct oshu_display; * Depending on the game state, the background can be darkened to make the game * objects more visible. */ -struct oshu_background { +struct background { /** * The display to which the background is attached. * @@ -40,9 +42,9 @@ struct oshu_background { * scaling. * * \todo - * Implement the #OSHU_SHOW_BACKGROUND flag. + * Implement the #oshu::SHOW_BACKGROUND flag. */ - struct oshu_display *display; + struct oshu::display *display; /** * The background picture. * @@ -52,19 +54,19 @@ struct oshu_background { * * When the ratio doesn't match, the picture is cropped. * - * When no texture is loaded, #oshu_show_background is a no-op, so you + * When no texture is loaded, #oshu::show_background is a no-op, so you * can safely assume the background is a valid object. */ - struct oshu_texture picture; + struct oshu::texture picture; }; /** * Load a background picture with SDL2_image. * - * You must free the background with #oshu_destroy_background. + * You must free the background with #oshu::destroy_background. * - * On error, returns -1, but the #oshu_background object remains safe to use - * with #oshu_show_background and #oshu_destroy_background. It is therefore + * On error, returns -1, but the #oshu::background object remains safe to use + * with #oshu::show_background and #oshu::destroy_background. It is therefore * safe to ignore errors here. * * The background is pre-scaled to avoid keeping a huge texture in video @@ -74,13 +76,13 @@ struct oshu_background { * because the pre-scale algorithm is fancier than that, thanks to cairo. * */ -int oshu_load_background(struct oshu_display *display, const char *filename, struct oshu_background *background); +int load_background(struct oshu::display *display, const char *filename, struct oshu::background *background); /** * Display the background such that it fills the whole screen. * * The size of the screen is determined from the display's current view, so you - * should always call #oshu_reset_view before this function. Otherwise, expect + * should always call #oshu::reset_view before this function. Otherwise, expect * black bars or overflows. * * You should also fill the screen with a solid color in case the background @@ -92,14 +94,16 @@ int oshu_load_background(struct oshu_display *display, const char *filename, str * subjective “anything below that and the background might as well not be * there” point. * - * You may use #oshu_trapezium for the brightness to implement a fading-in + * You may use #oshu::trapezium for the brightness to implement a fading-in * fading-out effect. */ -void oshu_show_background(struct oshu_background *background, double brightness); +void show_background(struct oshu::background *background, double brightness); /** * Free the background picture. */ -void oshu_destroy_background(struct oshu_background *background); +void destroy_background(struct oshu::background *background); /** \} */ + +} diff --git a/include/ui/cursor.h b/include/ui/cursor.h index 92d6927..856b268 100644 --- a/include/ui/cursor.h +++ b/include/ui/cursor.h @@ -8,7 +8,9 @@ #include "core/geometry.h" #include "video/texture.h" -struct oshu_display; +namespace oshu { + +struct display; /** * \defgroup ui_cursor Cursor @@ -17,20 +19,20 @@ struct oshu_display; * \brief * Fancy software mouse cursor. * - * To enable this module, the #OSHU_FANCY_CURSOR flag must be enabled for the + * To enable this module, the #oshu::FANCY_CURSOR flag must be enabled for the * display. Otherwise, this module behaves like a stub and do nothing. * * \{ */ -struct oshu_cursor_widget { +struct cursor_widget { /** * The display associated to the cursor. * * It is used both to retrieve the mouse position, and to render the * cursor. */ - struct oshu_display *display; + struct oshu::display *display; /** * Keep track of the previous positions of the mouse to display a * fancier cursor, with a trail. @@ -38,7 +40,7 @@ struct oshu_cursor_widget { * This is a circular array, starting at #offset. The previous is at * #offset - 1, and so on. When you reach the maximum index, wrap at 0. */ - oshu_point history[4]; + oshu::point history[4]; /** * Index of the most recent point in #history. */ @@ -49,15 +51,15 @@ struct oshu_cursor_widget { * It's a white disc, which is scaled and whose opacity is adjusted for * the main cursor and all the trailing particles. */ - struct oshu_texture mouse; + struct oshu::texture mouse; }; /** * Create a cursor for the display, and paint its texture with cairo. * - * You must free the cursor with #oshu_destroy_cursor. + * You must free the cursor with #oshu::destroy_cursor. */ -int oshu_create_cursor(struct oshu_display *display, struct oshu_cursor_widget *cursor); +int create_cursor(struct oshu::display *display, struct oshu::cursor_widget *cursor); /** * Render the cursor on the display it was created on. @@ -69,7 +71,7 @@ int oshu_create_cursor(struct oshu_display *display, struct oshu_cursor_widget * * Every call to this function update the mouse position history, affecting the * cursor trail. */ -void oshu_show_cursor(struct oshu_cursor_widget *cursor); +void show_cursor(struct oshu::cursor_widget *cursor); /** * Free the cursor's texture. @@ -77,6 +79,8 @@ void oshu_show_cursor(struct oshu_cursor_widget *cursor); * It is safe to call this function on a destroyed cursor, or on a * zero-initialized cursor. */ -void oshu_destroy_cursor(struct oshu_cursor_widget *cursor); +void destroy_cursor(struct oshu::cursor_widget *cursor); /** \} */ + +} diff --git a/include/ui/metadata.h b/include/ui/metadata.h index c72532d..7a97619 100644 --- a/include/ui/metadata.h +++ b/include/ui/metadata.h @@ -7,8 +7,11 @@ #include "video/texture.h" -struct oshu_display; -struct oshu_metadata; +namespace oshu { + +struct beatmap; +struct display; +struct metadata; /** * \defgroup ui_metadata Metadata @@ -27,18 +30,18 @@ struct oshu_metadata; * When both ASCII and Unicode metadata are available, the display switches * between each variant with a fading transition. */ -struct oshu_metadata_frame { +struct metadata_frame { /** * The display storing the textures. */ - struct oshu_display *display; + struct oshu::display *display; /** * The metadata source. */ - struct oshu_beatmap *beatmap; + struct oshu::beatmap *beatmap; /** * The clock points to an ever-increasing continuous time value, in - * seconds. The game clock's #oshu_clock::system is a good fit for this + * seconds. The game clock's #oshu::clock::system is a good fit for this * value. * * This clock determines which of #ascii and #unicode is displayed. @@ -52,38 +55,38 @@ struct oshu_metadata_frame { * 2 lines of text: the first with the title, the second with the * artist name. */ - struct oshu_texture ascii; + struct oshu::texture ascii; /** * Unicode variant of #ascii. * * When the Unicode metadata is missing, or identical to the ASCII * ones, this texture is left null. */ - struct oshu_texture unicode; + struct oshu::texture unicode; /** * Show difficulty information. * - * The first line is the #oshu_metadata::version, and the second the + * The first line is the #oshu::metadata::version, and the second the * difficulty value in stars. */ - struct oshu_texture stars; + struct oshu::texture stars; }; /** * Create a metadata frame. * - * Refer to #oshu_metadata_frame for documentation on the parameters. + * Refer to #oshu::metadata_frame for documentation on the parameters. * * `frame` needs not be initialized. * - * When done, please destroy the frame with #oshu_destroy_metadata_frame. + * When done, please destroy the frame with #oshu::destroy_metadata_frame. */ -int oshu_create_metadata_frame(struct oshu_display *display, struct oshu_beatmap *beatmap, double *clock, struct oshu_metadata_frame *frame); +int create_metadata_frame(struct oshu::display *display, struct oshu::beatmap *beatmap, double *clock, struct oshu::metadata_frame *frame); /** * Display the metadata frame on the configured display with the given opacity. * - * *opacity* is a number between 0 and 1. You may want to use #oshu_fade_out to + * *opacity* is a number between 0 and 1. You may want to use #oshu::fade_out to * compute that value. * * Metadata are drawn in white text and a translucent black background for @@ -92,11 +95,13 @@ int oshu_create_metadata_frame(struct oshu_display *display, struct oshu_beatmap * Every 3.5 second, the display is switched between Unicode and ASCII, with a * 0.2-second fade transititon. */ -void oshu_show_metadata_frame(struct oshu_metadata_frame *frame, double opacity); +void show_metadata_frame(struct oshu::metadata_frame *frame, double opacity); /** * Free the allocated textures. */ -void oshu_destroy_metadata_frame(struct oshu_metadata_frame *frame); +void destroy_metadata_frame(struct oshu::metadata_frame *frame); /** \} */ + +} diff --git a/include/ui/osu.h b/include/ui/osu.h index 8c8c404..6b03fe6 100644 --- a/include/ui/osu.h +++ b/include/ui/osu.h @@ -12,16 +12,16 @@ #include -struct osu_game; - namespace oshu { +struct hit; struct osu_ui; +struct osu_game; struct osu_mouse : public oshu::mouse { - osu_mouse(oshu_display *display); - oshu_display *display; - oshu_point position() override; + osu_mouse(oshu::display *display); + oshu::display *display; + oshu::point position() override; }; /** @@ -30,11 +30,11 @@ struct osu_mouse : public oshu::mouse { */ struct osu_ui : public widget { - osu_ui(oshu_display *display, osu_game &game); + osu_ui(oshu::display *display, oshu::osu_game &game); ~osu_ui(); - oshu_display *display; - osu_game &game; + oshu::display *display; + oshu::osu_game &game; std::shared_ptr mouse; void draw() override; @@ -44,83 +44,79 @@ struct osu_ui : public widget { * * There are as many textures as there are colors in the beatmap. */ - struct oshu_texture *circles {}; + struct oshu::texture *circles {}; /** * Full-size approach circle. * * Its size is the `radius + approach_size` from the beatmap. */ - struct oshu_texture approach_circle {}; + struct oshu::texture approach_circle {}; /** * The slider ball and its tolerance circle. */ - struct oshu_texture slider_ball {}; + struct oshu::texture slider_ball {}; /** * Symbol to indicate a note was successfully hit. * * A green circle. */ - struct oshu_texture good_mark {}; + struct oshu::texture good_mark {}; /** * Symbol for early hits. * * A yellow half-circle, on the left. */ - struct oshu_texture early_mark {}; + struct oshu::texture early_mark {}; /** * Symbol for early hits. * * A yellow half-circle, on the right. */ - struct oshu_texture late_mark {}; + struct oshu::texture late_mark {}; /** * Symbol to indicate a note was missed. * * A red X. */ - struct oshu_texture bad_mark {}; + struct oshu::texture bad_mark {}; /** * Symbol to indicate a note was skipped. * * A blue triangle pointing right. */ - struct oshu_texture skip_mark {}; + struct oshu::texture skip_mark {}; /** * Little tick mark for the dotted line between two consecutive hits. */ - struct oshu_texture connector {}; + struct oshu::texture connector {}; /** * Use a fancy software cursor for the osu!standard mode, because the * mouse is a central part of the gameplay. */ - struct oshu_cursor_widget cursor {}; + struct oshu::cursor_widget cursor {}; }; -/** \} */ - -} - /** * Paint all the required textures for the beatmap. * - * Free everything with #osu_free_resources. + * Free everything with #oshu::osu_free_resources. * - * Sliders are not painted. Instead, you must call #osu_paint_slider. + * Sliders are not painted. Instead, you must call #oshu::osu_paint_slider. */ int osu_paint_resources(oshu::osu_ui&); /** * Paint a slider. * - * This is externalized from #osu_paint_slider to let you paint them lazily, + * This is externalized from #oshu::osu_paint_slider to let you paint them lazily, * because painting all the sliders at once would increase the startup time by * up to a few long seconds. * * The texture is stored in `hit->texture`. * - * Slider textures are freed with #osu_free_resources. + * Slider textures are freed with #oshu::osu_free_resources. */ -int osu_paint_slider(oshu::osu_ui&, struct oshu_hit *hit); +int osu_paint_slider(oshu::osu_ui&, struct oshu::hit *hit); /** * Free the dynamic resources of the game mode. @@ -134,6 +130,10 @@ void osu_free_resources(oshu::osu_ui&); * 512×384 logical screen. * * It is the caller's responsibility to reset the view, preferably such that - * the #osu_view/#oshu_reset_view pairing looks obvious. + * the #oshu::osu_view/#oshu::reset_view pairing looks obvious. */ -void osu_view(struct oshu_display *display); +void osu_view(struct oshu::display *display); + +/** \} */ + +} diff --git a/include/ui/score.h b/include/ui/score.h index 986e850..c9ec247 100644 --- a/include/ui/score.h +++ b/include/ui/score.h @@ -5,8 +5,10 @@ #pragma once -struct oshu_beatmap; -struct oshu_display; +namespace oshu { + +struct beatmap; +struct display; /** * \defgroup ui_score Score @@ -21,9 +23,9 @@ struct oshu_display; * \{ */ -struct oshu_score_frame { - struct oshu_display *display; - struct oshu_beatmap *beatmap; +struct score_frame { + struct oshu::display *display; + struct oshu::beatmap *beatmap; int good; int bad; }; @@ -36,22 +38,24 @@ struct oshu_score_frame { * Maybe in a future version, this widget could be permanently shown and * updated on every action. */ -int oshu_create_score_frame(struct oshu_display *display, struct oshu_beatmap *beatmap, struct oshu_score_frame *frame); +int create_score_frame(struct oshu::display *display, struct oshu::beatmap *beatmap, struct oshu::score_frame *frame); /** * Show the score frame. * * It's a simple bar, centered in the bottom of the screen. * - * The opacity argument lets you fade in the bar with #oshu_fade_in. + * The opacity argument lets you fade in the bar with #oshu::fade_in. */ -void oshu_show_score_frame(struct oshu_score_frame *frame, double opacity); +void show_score_frame(struct oshu::score_frame *frame, double opacity); /** * Destroy a score frame. * * In fact, it does nothing, but is there for consistency. */ -void oshu_destroy_score_frame(struct oshu_score_frame *frame); +void destroy_score_frame(struct oshu::score_frame *frame); /** \} */ + +} diff --git a/include/ui/shell.h b/include/ui/shell.h index e0ac2dd..fcacd46 100644 --- a/include/ui/shell.h +++ b/include/ui/shell.h @@ -12,14 +12,10 @@ #include -namespace oshu { -class game_base; -} - -struct oshu_game_screen; - namespace oshu { +class game_base; +struct game_screen; struct widget; /** @@ -44,25 +40,25 @@ struct shell { * * Both the display and the game must outlive the shell. */ - shell(oshu_display&, oshu::game_base&); + shell(oshu::display&, oshu::game_base&); ~shell(); /** * The window that the shell managed. * * A display should not be associated to more than one shell. */ - oshu_display &display; + oshu::display &display; oshu::game_base &game; /** * The widget responsible for drawing the main game objects, specific * to the mode. */ std::unique_ptr game_view; - oshu_game_screen *screen; - oshu_background background {}; - oshu_metadata_frame metadata {}; - oshu_score_frame score {}; - oshu_audio_progress_bar audio_progress_bar {}; + oshu::game_screen *screen; + oshu::background background {}; + oshu::metadata_frame metadata {}; + oshu::score_frame score {}; + oshu::audio_progress_bar audio_progress_bar {}; /** * Start the main loop. */ diff --git a/include/video/display.h b/include/video/display.h index ae2607c..d94a546 100644 --- a/include/video/display.h +++ b/include/video/display.h @@ -11,6 +11,8 @@ struct SDL_Renderer; struct SDL_Window; +namespace oshu { + /** * \defgroup video_display Display * \ingroup video @@ -22,11 +24,11 @@ struct SDL_Window; * functions for initializing the window and its renderer together, with the * appropriate settings. * - * The main drawing operation on a display is #oshu_draw_texture. The other + * The main drawing operation on a display is #oshu::draw_texture. The other * drawing primitives must be called straight from SDL using the display's * underlying renderer. Note that while wrapped operations transform the * coordinates using the display's view, you would need to project the - * coordinates yourself with #oshu_project to get a consistent behavior with + * coordinates yourself with #oshu::project to get a consistent behavior with * the equivalent SDL routines. * * \{ @@ -41,7 +43,7 @@ struct SDL_Window; * \todo * Make a higher level object instead of exposing the raw flags. */ -enum oshu_visual_feature { +enum visual_feature { /** * Control the `SDL_HINT_RENDER_SCALE_QUALITY`. * @@ -49,24 +51,24 @@ enum oshu_visual_feature { * antialising when textures are scaled. *linear* gives much nicer * results, but is much more expensive. */ - OSHU_LINEAR_SCALING = 0x1, + LINEAR_SCALING = 0x1, /** * Display a background picture rather than a pitch black screen. * * Implemented by the \ref ui_background module. */ - OSHU_SHOW_BACKGROUND = 0x2, + SHOW_BACKGROUND = 0x2, /** * Show a fancy software mouse cursor instead of the default one. * * This flag is implemented by the \ref ui_cursor module. */ - OSHU_FANCY_CURSOR = 0x4, + FANCY_CURSOR = 0x4, /** * Prefer hardware rendering over software rendering. * * Since the graphics are quite simple, unless fancy scaling is enabled - * with #OSHU_LINEAR_SCALING, hardware video provide little + * with #LINEAR_SCALING, hardware video provide little * advantage, and may even worsen the performance. * * One notable example is the Raspberry Pi which runs much smoother @@ -75,14 +77,14 @@ enum oshu_visual_feature { * Note that enabling this flag doesn't force it on the SDL display, * but disabling it forces software rendering. */ - OSHU_HARDWARE_ACCELERATION = 0x8, + HARDWARE_ACCELERATION = 0x8, /** * Increase the frame rate to 60 FPS. * * On low-end hardware, 30 FPS is a good compromise, but most of the * time 60 is much smoother. */ - OSHU_60FPS = 0x10, + SIXTY_FPS = 0x10, }; /** @@ -90,19 +92,19 @@ enum oshu_visual_feature { * * This is controllable through the `OSHU_QUALITY` environment variable: * - * - `low` for #OSHU_LOW_QUALITY, - * - `medium` for #OSHU_MEDIUM_QUALITY, - * - `high` for #OSHU_HIGH_QUALITY. + * - `low` for #LOW_QUALITY, + * - `medium` for #MEDIUM_QUALITY, + * - `high` for #HIGH_QUALITY. * * A quality level is actually a combination of visual features from - * #oshu_visual_feature. + * #oshu::visual_feature. * * In the future, the OSHU_QUALITY variable may be expanded to support finer * settings and allow enabling individual features instead of picking a level * from a limited set of values. For example, you could imagine * `medium-background`, or `low+acceleration`. */ -enum oshu_quality_level { +enum quality_level { /** * Lowest quality for the poorest computers. * @@ -111,27 +113,27 @@ enum oshu_quality_level { * * No background picture. */ - OSHU_LOW_QUALITY = 0, + LOW_QUALITY = 0, /** * Quality for pretty bad computers. * * The scaling algorithm is set to *nearest*. Get ready for aliasing * and staircases. */ - OSHU_MEDIUM_QUALITY = OSHU_LOW_QUALITY|OSHU_SHOW_BACKGROUND|OSHU_FANCY_CURSOR|OSHU_60FPS, + MEDIUM_QUALITY = LOW_QUALITY|SHOW_BACKGROUND|FANCY_CURSOR|SIXTY_FPS, /** * Best quality. * * Use linear scaling, and make textures fit the window size exactly, * whatever the window size is. */ - OSHU_HIGH_QUALITY = OSHU_MEDIUM_QUALITY|OSHU_LINEAR_SCALING|OSHU_HARDWARE_ACCELERATION, + HIGH_QUALITY = MEDIUM_QUALITY|LINEAR_SCALING|HARDWARE_ACCELERATION, /** * Default quality level. * * Used when the user didn't specify anything. */ - OSHU_DEFAULT_QUALITY = OSHU_HIGH_QUALITY, + DEFAULT_QUALITY = HIGH_QUALITY, }; /** @@ -145,12 +147,12 @@ enum oshu_quality_level { * \sa oshu_open_display * \sa oshu_close_display */ -struct oshu_display { +struct display { /** * Create a display structure, open the SDL window and create the renderer. */ - oshu_display(); - ~oshu_display(); + display(); + ~display(); /** * The one and only SDL game window. */ @@ -165,14 +167,14 @@ struct oshu_display { * The current view, used to project coordinates when drawing. * * When the window is resized, make sure you reset it with - * #oshu_reset_view and recreate your view from it. + * #oshu::reset_view and recreate your view from it. */ - struct oshu_view view; + struct oshu::view view; /** - * Bitmap of visual features, defined in #oshu_visual_feature. + * Bitmap of visual features, defined in #oshu::visual_feature. * * It is by default loaded from the `OSHU_QUALITY` environment - * variable, using the values defined by #oshu_quality_level. + * variable, using the values defined by #oshu::quality_level. */ int features; /** @@ -180,7 +182,7 @@ struct oshu_display { * * 0.01666… is 60 FPS. * - * Its value depends on whether the #OSHU_60FPS is enabled or not. If + * Its value depends on whether the #SIXTY_FPS is enabled or not. If * it isn't, then the game runs at 30 FPS. */ double frame_duration; @@ -193,8 +195,10 @@ struct oshu_display { * SDL provides it in window coordinates, which are unprojected into the * current coordinate system for the display. * - * \sa oshu_unproject + * \sa oshu::unproject */ -oshu_point oshu_get_mouse(struct oshu_display *display); +oshu::point get_mouse(struct display *display); /** \} */ + +} diff --git a/include/video/paint.h b/include/video/paint.h index a83ad9c..e773c1a 100644 --- a/include/video/paint.h +++ b/include/video/paint.h @@ -10,8 +10,11 @@ #include struct SDL_Surface; -struct oshu_display; -struct oshu_texture; + +namespace oshu { + +struct display; +struct texture; /** * \defgroup video_paint Paint @@ -26,15 +29,15 @@ struct oshu_texture; * Unlike a naive Cairo/SDL integration, this module provides full alpha * support by un-premultiplying the alpha channel when generating the texture. * - * You can create a cairo context with #oshu_start_painting, and finalize it to - * upload the texture with #oshu_finish_painting. + * You can create a cairo context with #oshu::start_painting, and finalize it to + * upload the texture with #oshu::finish_painting. * * ```c - * struct oshu_texture t; - * struct oshu_painter p; - * oshu_start_painting(128 + 128 * I, 64 + 64 * I, &p); + * struct oshu::texture t; + * struct oshu::painter p; + * oshu::start_painting(128 + 128 * I, 64 + 64 * I, &p); * // call cairo with p->cr - * oshu_finish_painting(&p, display, &t); + * oshu::finish_painting(&p, display, &t); * ``` * * The \ref video/paint.h header imports cairo.h for convenience. @@ -42,9 +45,9 @@ struct oshu_texture; * \{ */ -struct oshu_painter { - struct oshu_display *display; - oshu_size size; +struct painter { + struct oshu::display *display; + oshu::size size; struct SDL_Surface *destination; cairo_surface_t *surface; cairo_t *cr; @@ -53,9 +56,9 @@ struct oshu_painter { /** * Create an SDL surface and bind a Cairo context. * - * When you're done drawing, call #oshu_finish_painting. + * When you're done drawing, call #oshu::finish_painting. * - * The *size* argument defines the logical size for #oshu_texture::size, which + * The *size* argument defines the logical size for #oshu::texture::size, which * is the one used when drawing the finalized texture. * * The actual physical size of the texture depends on the display's current @@ -65,24 +68,26 @@ struct oshu_painter { * * Note that the texture quality will depend on the display's current view when * this function is called. You should make sure the view set when calling - * #oshu_start_painting is the same view that will be used with - * #oshu_draw_texture. + * #oshu::start_painting is the same view that will be used with + * #oshu::draw_texture. * * The painter object needs not be initialized before calling this function. */ -int oshu_start_painting(struct oshu_display *display, oshu_size size, struct oshu_painter *painter); +int start_painting(struct oshu::display *display, oshu::size size, struct oshu::painter *painter); /** * Load the drawn texture onto the GPU as a texture, and free everything else. * * The *painter* object is left in an undefined state, but you may reuse it - * with #oshu_start_painting. Note that you won't get any performance + * with #oshu::start_painting. Note that you won't get any performance * improvement by reusing painters per se. * * You must not finish painting on the same painter twice. * - * You must destroy the texture later with #oshu_destroy_texture. + * You must destroy the texture later with #oshu::destroy_texture. */ -int oshu_finish_painting(struct oshu_painter *painter, struct oshu_texture *texture); +int finish_painting(struct oshu::painter *painter, struct oshu::texture *texture); /** \} */ + +} diff --git a/include/video/texture.h b/include/video/texture.h index 5df549e..a340efa 100644 --- a/include/video/texture.h +++ b/include/video/texture.h @@ -7,9 +7,12 @@ #include "core/geometry.h" -struct oshu_display; struct SDL_Texture; +namespace oshu { + +struct display; + /** * \defgroup video_texture Texture * \ingroup video @@ -18,7 +21,7 @@ struct SDL_Texture; * Load and draw accelerated textures. * * This module provides a wrapper over SDL's texture rendering. Its main - * benefit is that it integrates with an #oshu_display's view. + * benefit is that it integrates with an #oshu::display's view. * * Assume you need to draw a circle hit object at a given position in game * coordinates, this module will let you draw it by specifying only the center @@ -26,9 +29,9 @@ struct SDL_Texture; * * Coordinate transformation takes 3 metadata into account: * - * - The #oshu_display's view. - * - The logical #oshu_texture::size of the texture. - * - The texture's oshu_texture::origin. + * - The #oshu::display's view. + * - The logical #oshu::texture::size of the texture. + * - The texture's oshu::texture::origin. * * While the view may change every time the texture is drawn, the latter two * properties are well defined at the texture's creation, and thus need not be @@ -40,10 +43,10 @@ struct SDL_Texture; /** * Define a texture loaded on the GPU. * - * Load it from a file with #oshu_load_texture or create it using the - * \ref video_paint module, then destroy it with #oshu_destroy_texture. + * Load it from a file with #oshu::load_texture or create it using the + * \ref video_paint module, then destroy it with #oshu::destroy_texture. */ -struct oshu_texture { +struct texture { /** * The final size of the texture, specified in logical units. * @@ -63,7 +66,7 @@ struct oshu_texture { * You are free to change this property at will, but nothing will * prevent you from breaking the aspect ratio of the texture. */ - oshu_size size; + oshu::size size; /** * The origin defines the anchor of the texture when drawing, rather * than always using the top-left corner. @@ -74,7 +77,7 @@ struct oshu_texture { * When drawing a texture at (x, y), it will be drawn such that the * #origin is at (x, y). */ - oshu_point origin; + oshu::point origin; /** * The underlying SDL texture. */ @@ -89,7 +92,7 @@ struct oshu_texture { * * Log an error and return -1 on failure. */ -int oshu_load_texture(struct oshu_display *display, const char *filename, struct oshu_texture *texture); +int load_texture(struct oshu::display *display, const char *filename, struct oshu::texture *texture); /** * Destroy an SDL texture with `SDL_DestroyTexture`. @@ -100,18 +103,18 @@ int oshu_load_texture(struct oshu_display *display, const char *filename, struct * It is safe to destroy a texture more than once, or destroy a * null-initialized texture object. */ -void oshu_destroy_texture(struct oshu_texture *texture); +void destroy_texture(struct oshu::texture *texture); /** * Draw a texture at the specified position. * * *p* points at the position of the *origin* of the texture, not at the - * top-left corner. See #oshu_texture::origin. + * top-left corner. See #oshu::texture::origin. * * The logical size of the texture is preserved, according to the display's * current view. */ -void oshu_draw_texture(struct oshu_display *display, struct oshu_texture *texture, oshu_point p); +void draw_texture(struct oshu::display *display, struct oshu::texture *texture, oshu::point p); /** * Draw a texture with a customizable scale factor. @@ -123,6 +126,8 @@ void oshu_draw_texture(struct oshu_display *display, struct oshu_texture *textur * The texture is scaled relative to its origin, preserving the property that * *p* always represents the same texture pixel (the origin), for any ratio. */ -void oshu_draw_scaled_texture(struct oshu_display *display, struct oshu_texture *texture, oshu_point p, double ratio); +void draw_scaled_texture(struct oshu::display *display, struct oshu::texture *texture, oshu::point p, double ratio); /** \} */ + +} diff --git a/include/video/transitions.h b/include/video/transitions.h index 496d3d1..73352da 100644 --- a/include/video/transitions.h +++ b/include/video/transitions.h @@ -5,6 +5,8 @@ #pragma once +namespace oshu { + /** * \defgroup video_transitions Transitions * \ingroup video @@ -41,14 +43,14 @@ * S E * ``` * - * \sa oshu_fade_in + * \sa oshu::fade_in */ -double oshu_fade_out(double start, double end, double t); +double fade_out(double start, double end, double t); /** * Fading in function. * - * It's pretty much the same as #oshu_fade_out, with the property that + * It's pretty much the same as #oshu::fade_out, with the property that * `fade_in(s, e, t) = 1 - fade_out(s, e, t)`. * * Assumes *start < end*. @@ -63,7 +65,7 @@ double oshu_fade_out(double start, double end, double t); * S E * ``` */ -double oshu_fade_in(double start, double end, double t); +double fade_in(double start, double end, double t); /** * Convex isosceles trapezoid function. @@ -104,7 +106,8 @@ double oshu_fade_in(double start, double end, double t); * `transition = (end - start) / 2`, because that won't reflect your intention. * */ -double oshu_trapezium(double start, double end, double transition, double t); - +double trapezium(double start, double end, double transition, double t); /** \} */ + +} diff --git a/include/video/view.h b/include/video/view.h index 611d211..f3449f8 100644 --- a/include/video/view.h +++ b/include/video/view.h @@ -7,7 +7,9 @@ #include "core/geometry.h" -struct oshu_display; +namespace oshu { + +struct display; /** * \defgroup video_view View @@ -72,7 +74,7 @@ struct oshu_display; * 640px * ``` * - * The above transformation is performed by #oshu_resize_view. + * The above transformation is performed by #oshu::resize_view. * * When the window grows, this whole viewport is scaled, and not just the game * area. The viewport will be zoomed to fit the available space, while @@ -97,7 +99,7 @@ struct oshu_display; * window width = 640 × zoom * ``` * - * This is done by #oshu_fit_view. + * This is done by #oshu::fit_view. * * \{ */ @@ -108,8 +110,8 @@ struct oshu_display; * More concretely, this is an affine transformation system, where zoom is the * factor and (x, y) the constant. `v(p) = z p + o` * - * Transformation operations on the view like #oshu_resize_view, - * #oshu_scale_view and #oshu_fit_view are composed on the right: + * Transformation operations on the view like #oshu::resize_view, + * #oshu::scale_view and #oshu::fit_view are composed on the right: * `v(v'(p)) = z (z' p + o') + o = z z' p + z o' + o` * * For ease of understanding, transformation of views are explained in terms of @@ -117,10 +119,10 @@ struct oshu_display; * coordinates into physical coordinates, so the logical one is the input, and * physical one the output. */ -struct oshu_view { +struct view { double zoom; - oshu_point origin; - oshu_size size; + oshu::point origin; + oshu::size size; }; /** @@ -142,7 +144,7 @@ struct oshu_view { * - `v(logical width / 2) = physical width / 2` * */ -void oshu_resize_view(struct oshu_view *view, oshu_size size); +void resize_view(struct oshu::view *view, oshu::size size); /** * Scale the coordinate system. @@ -162,7 +164,7 @@ void oshu_resize_view(struct oshu_view *view, oshu_size size); * - `v(logical width) = physical width` * */ -void oshu_scale_view(struct oshu_view *view, double factor); +void scale_view(struct oshu::view *view, double factor); /** * Scale and resize the view while preserving the aspect ratio. @@ -176,34 +178,36 @@ void oshu_scale_view(struct oshu_view *view, double factor); * - The view is not cut: * `0 ≤ v(0) ≤ v(logical width) ≤ physical width` */ -void oshu_fit_view(struct oshu_view *view, oshu_size size); +void fit_view(struct oshu::view *view, oshu::size size); /** * Reset the display's view to the identity view. * * The size of the window is automatically retrieved from the SDL window. * - * The resulting view is stored in the display's #oshu_display::view attribute. + * The resulting view is stored in the display's #oshu::display::view attribute. */ -void oshu_reset_view(struct oshu_display *display); +void reset_view(struct oshu::display *display); /** * Project a point from logical coordinates to physical coordinates. * * Applies the affine transformation: `v(p) = z p + o`. * - * \sa oshu_unproject + * \sa oshu::unproject */ -oshu_point oshu_project(struct oshu_view *view, oshu_point p); +oshu::point project(struct oshu::view *view, oshu::point p); /** * Unproject a point from physical coordinates to logical coordinates. * - * This is the opposite operation of #oshu_project. + * This is the opposite operation of #oshu::project. * * From the definition of the view, `v(p) = z p + o`, * we deduce `p = (v(p) - o) / z`. */ -oshu_point oshu_unproject(struct oshu_view *view, oshu_point p); +oshu::point unproject(struct oshu::view *view, oshu::point p); /** \} */ + +} diff --git a/lib/audio/audio.cc b/lib/audio/audio.cc index bcaaaf8..aa1bf5e 100644 --- a/lib/audio/audio.cc +++ b/lib/audio/audio.cc @@ -52,14 +52,14 @@ static void clip(float *samples, int nb_samples, int channels) */ static void audio_callback(void *userdata, Uint8 *buffer, int len) { - struct oshu_audio *audio; - audio = (struct oshu_audio*) userdata; + struct oshu::audio *audio; + audio = (struct oshu::audio*) userdata; int unit = audio->device_spec.channels * sizeof(float); assert (len % unit == 0); int nb_samples = len / unit; float *samples = (float*) buffer; - int rc = oshu_read_stream(&audio->music, samples, nb_samples); + int rc = oshu::read_stream(&audio->music, samples, nb_samples); if (rc < 0) { oshu_log_debug("failed reading samples from the audio stream"); return; @@ -70,8 +70,8 @@ static void audio_callback(void *userdata, Uint8 *buffer, int len) int tracks = sizeof(audio->effects) / sizeof(*audio->effects); for (int i = 0; i < tracks; i++) - oshu_mix_track(&audio->effects[i], samples, nb_samples); - oshu_mix_track(&audio->looping, samples, nb_samples); + oshu::mix_track(&audio->effects[i], samples, nb_samples); + oshu::mix_track(&audio->looping, samples, nb_samples); clip(samples, nb_samples, audio->device_spec.channels); } @@ -80,7 +80,7 @@ static void audio_callback(void *userdata, Uint8 *buffer, int len) * Initialize the SDL audio device. * \return 0 on success, -1 on error. */ -static int open_device(struct oshu_audio *audio) +static int open_device(struct oshu::audio *audio) { SDL_AudioSpec want; SDL_zero(want); @@ -101,34 +101,34 @@ static int open_device(struct oshu_audio *audio) return 0; } -int oshu_open_audio(const char *url, struct oshu_audio *audio) +int oshu::open_audio(const char *url, struct oshu::audio *audio) { assert (sizeof(float) == 4); - if (oshu_open_stream(url, &audio->music) < 0) + if (oshu::open_stream(url, &audio->music) < 0) goto fail; if (open_device(audio) < 0) goto fail; return 0; fail: - oshu_close_audio(audio); + oshu::close_audio(audio); return -1; } -void oshu_play_audio(struct oshu_audio *audio) +void oshu::play_audio(struct oshu::audio *audio) { SDL_PauseAudioDevice(audio->device_id, 0); } -void oshu_pause_audio(struct oshu_audio *audio) +void oshu::pause_audio(struct oshu::audio *audio) { SDL_PauseAudioDevice(audio->device_id, 1); } -void oshu_close_audio(struct oshu_audio *audio) +void oshu::close_audio(struct oshu::audio *audio) { if (audio->device_id) SDL_CloseAudioDevice(audio->device_id); - oshu_close_stream(&audio->music); + oshu::close_stream(&audio->music); } /** @@ -141,13 +141,13 @@ void oshu_close_audio(struct oshu_audio *audio) * Make sure you lock the audio device when calling this function, in order to * ensure predictable results. */ -static struct oshu_track *select_track(struct oshu_audio *audio) +static struct oshu::track *select_track(struct oshu::audio *audio) { int max_cursor = 0; - struct oshu_track *best_track = &audio->effects[0]; + struct oshu::track *best_track = &audio->effects[0]; int tracks = sizeof(audio->effects) / sizeof(*audio->effects); for (int i = 0; i < tracks; ++i) { - struct oshu_track *c = &audio->effects[i]; + struct oshu::track *c = &audio->effects[i]; if (c->sample == NULL) { return c; } else if (c->cursor > max_cursor) { @@ -158,38 +158,38 @@ static struct oshu_track *select_track(struct oshu_audio *audio) return best_track; } -void oshu_play_sample(struct oshu_audio *audio, struct oshu_sample *sample, float volume) +void oshu::play_sample(struct oshu::audio *audio, struct oshu::sample *sample, float volume) { SDL_LockAudioDevice(audio->device_id); - struct oshu_track *track = select_track(audio); + struct oshu::track *track = select_track(audio); if (track->sample != NULL) oshu_log_debug("all the effect tracks are taken, stealing one"); - oshu_start_track(track, sample, volume, 0); + oshu::start_track(track, sample, volume, 0); SDL_UnlockAudioDevice(audio->device_id); } -void oshu_play_loop(struct oshu_audio *audio, struct oshu_sample *sample, float volume) +void oshu::play_loop(struct oshu::audio *audio, struct oshu::sample *sample, float volume) { SDL_LockAudioDevice(audio->device_id); - oshu_start_track(&audio->looping, sample, volume, 1); + oshu::start_track(&audio->looping, sample, volume, 1); SDL_UnlockAudioDevice(audio->device_id); } -void oshu_stop_loop(struct oshu_audio *audio) +void oshu::stop_loop(struct oshu::audio *audio) { SDL_LockAudioDevice(audio->device_id); - oshu_stop_track(&audio->looping); + oshu::stop_track(&audio->looping); SDL_UnlockAudioDevice(audio->device_id); } -int oshu_seek_music(struct oshu_audio *audio, double target) +int oshu::seek_music(struct oshu::audio *audio, double target) { SDL_LockAudioDevice(audio->device_id); - int rc = oshu_seek_stream(&audio->music, target); - oshu_stop_track(&audio->looping); + int rc = oshu::seek_stream(&audio->music, target); + oshu::stop_track(&audio->looping); int tracks = sizeof(audio->effects) / sizeof(*audio->effects); for (int i = 0; i < tracks; ++i) - oshu_stop_track(&audio->effects[i]); + oshu::stop_track(&audio->effects[i]); SDL_UnlockAudioDevice(audio->device_id); return rc; } diff --git a/lib/audio/library.cc b/lib/audio/library.cc index 1b42d36..23db7aa 100644 --- a/lib/audio/library.cc +++ b/lib/audio/library.cc @@ -21,7 +21,7 @@ /** * Determine the directory of the skin to use. * - * See #oshu_sound_library::skin_directory for details. + * See #oshu::sound_library::skin_directory for details. */ static std::string skin_directory() { @@ -46,23 +46,23 @@ static std::string skin_directory() return OSHU_SKINS_DIRECTORY "/" OSHU_DEFAULT_SKIN; } -void oshu_open_sound_library(struct oshu_sound_library *library, struct SDL_AudioSpec *format) +void oshu::open_sound_library(struct oshu::sound_library *library, struct SDL_AudioSpec *format) { library->skin_directory = skin_directory(); oshu_log_debug("using skin directory %s", library->skin_directory.c_str()); library->format = format; } -static void free_sample(struct oshu_sample **sample) +static void free_sample(struct oshu::sample **sample) { if (*sample) { - oshu_destroy_sample(*sample); + oshu::destroy_sample(*sample); free(*sample); *sample = NULL; } } -static void free_shelf(struct oshu_sound_shelf *shelf) +static void free_shelf(struct oshu::sound_shelf *shelf) { free_sample(&shelf->hit_normal); free_sample(&shelf->hit_whistle); @@ -72,7 +72,7 @@ static void free_shelf(struct oshu_sound_shelf *shelf) free_sample(&shelf->slider_whistle); } -static void free_room(struct oshu_sound_room *room) +static void free_room(struct oshu::sound_room *room) { if (room->shelves) { for (int i = 0; i < room->size; ++i) @@ -84,7 +84,7 @@ static void free_room(struct oshu_sound_room *room) room->indices = NULL; } -void oshu_close_sound_library(struct oshu_sound_library *library) +void oshu::close_sound_library(struct oshu::sound_library *library) { free_room(&library->normal); free_room(&library->soft); @@ -96,7 +96,7 @@ void oshu_close_sound_library(struct oshu_sound_library *library) * * Return NULL if the shelf wasn't found. */ -static struct oshu_sound_shelf* find_shelf(struct oshu_sound_room *room, int index) +static struct oshu::sound_shelf* find_shelf(struct oshu::sound_room *room, int index) { for (int i = 0; i < room->size; ++i) { if (room->indices[i] == index) @@ -114,13 +114,13 @@ static struct oshu_sound_shelf* find_shelf(struct oshu_sound_room *room, int ind * After calling this function, you are guaranteed that there is the capacity * for at least one new shelf (i.e. `room->size < room->capacity`). */ -static void grow_room(struct oshu_sound_room *room) +static void grow_room(struct oshu::sound_room *room) { assert (room->size <= room->capacity); if (room->size < room->capacity) return; room->capacity += 8; - room->shelves = (oshu_sound_shelf*) realloc(room->shelves, room->capacity * sizeof(*room->shelves)); + room->shelves = (oshu::sound_shelf*) realloc(room->shelves, room->capacity * sizeof(*room->shelves)); assert (room->shelves != NULL); room->indices = (int*) realloc(room->indices, room->capacity * sizeof(*room->indices)); assert (room->indices != NULL); @@ -131,7 +131,7 @@ static void grow_room(struct oshu_sound_room *room) * * Return the pointer to the new shelf. */ -static struct oshu_sound_shelf* new_shelf(struct oshu_sound_room *room, int index) +static struct oshu::sound_shelf* new_shelf(struct oshu::sound_room *room, int index) { grow_room(room); int position = room->size++; @@ -145,12 +145,12 @@ static struct oshu_sound_shelf* new_shelf(struct oshu_sound_room *room, int inde * * If the room wasnn't found, return NULL. */ -static struct oshu_sound_room* get_room(struct oshu_sound_library *library, enum oshu_sample_set_family set) +static struct oshu::sound_room* get_room(struct oshu::sound_library *library, enum oshu::sample_set_family set) { switch (set) { - case OSHU_NORMAL_SAMPLE_SET: return &library->normal; - case OSHU_SOFT_SAMPLE_SET: return &library->soft; - case OSHU_DRUM_SAMPLE_SET: return &library->drum; + case oshu::NORMAL_SAMPLE_SET: return &library->normal; + case oshu::SOFT_SAMPLE_SET: return &library->soft; + case oshu::DRUM_SAMPLE_SET: return &library->drum; default: oshu_log_debug("unknown sample set %d", (int) set); return NULL; @@ -162,15 +162,15 @@ static struct oshu_sound_room* get_room(struct oshu_sound_library *library, enum * * If the sample wasnn't found because its type doesn't exist, return NULL. */ -static struct oshu_sample** get_sample(struct oshu_sound_shelf *shelf, int type) +static struct oshu::sample** get_sample(struct oshu::sound_shelf *shelf, int type) { switch (type) { - case OSHU_HIT_SOUND|OSHU_NORMAL_SOUND: return &shelf->hit_normal; - case OSHU_HIT_SOUND|OSHU_WHISTLE_SOUND: return &shelf->hit_whistle; - case OSHU_HIT_SOUND|OSHU_FINISH_SOUND: return &shelf->hit_finish; - case OSHU_HIT_SOUND|OSHU_CLAP_SOUND: return &shelf->hit_clap; - case OSHU_SLIDER_SOUND|OSHU_NORMAL_SOUND: return &shelf->slider_slide; - case OSHU_SLIDER_SOUND|OSHU_WHISTLE_SOUND: return &shelf->slider_whistle; + case oshu::HIT_SOUND|oshu::NORMAL_SOUND: return &shelf->hit_normal; + case oshu::HIT_SOUND|oshu::WHISTLE_SOUND: return &shelf->hit_whistle; + case oshu::HIT_SOUND|oshu::FINISH_SOUND: return &shelf->hit_finish; + case oshu::HIT_SOUND|oshu::CLAP_SOUND: return &shelf->hit_clap; + case oshu::SLIDER_SOUND|oshu::NORMAL_SOUND: return &shelf->slider_slide; + case oshu::SLIDER_SOUND|oshu::WHISTLE_SOUND: return &shelf->slider_whistle; default: oshu_log_debug("unknown sample type %d", (int) type); return NULL; @@ -186,14 +186,14 @@ static struct oshu_sample** get_sample(struct oshu_sound_shelf *shelf, int type) * * If the set or type is invalid, return an empty string. */ -static std::string make_sample_file_name(enum oshu_sample_set_family set, int index, int type) +static std::string make_sample_file_name(enum oshu::sample_set_family set, int index, int type) { /* Set name. */ const char *set_name; switch (set) { - case OSHU_NORMAL_SAMPLE_SET: set_name = "normal"; break; - case OSHU_SOFT_SAMPLE_SET: set_name = "soft"; break; - case OSHU_DRUM_SAMPLE_SET: set_name = "drum"; break; + case oshu::NORMAL_SAMPLE_SET: set_name = "normal"; break; + case oshu::SOFT_SAMPLE_SET: set_name = "soft"; break; + case oshu::DRUM_SAMPLE_SET: set_name = "drum"; break; default: oshu_log_debug("unknown sample set %d", (int) set); return {}; @@ -201,12 +201,12 @@ static std::string make_sample_file_name(enum oshu_sample_set_family set, int in /* Type name. */ const char *type_name; switch (type) { - case OSHU_HIT_SOUND|OSHU_NORMAL_SOUND: type_name = "hitnormal"; break; - case OSHU_HIT_SOUND|OSHU_WHISTLE_SOUND: type_name = "hitwhistle"; break; - case OSHU_HIT_SOUND|OSHU_FINISH_SOUND: type_name = "hitfinish"; break; - case OSHU_HIT_SOUND|OSHU_CLAP_SOUND: type_name = "hitclap"; break; - case OSHU_SLIDER_SOUND|OSHU_NORMAL_SOUND: type_name = "sliderslide"; break; - case OSHU_SLIDER_SOUND|OSHU_WHISTLE_SOUND: type_name = "sliderwhistle"; break; + case oshu::HIT_SOUND|oshu::NORMAL_SOUND: type_name = "hitnormal"; break; + case oshu::HIT_SOUND|oshu::WHISTLE_SOUND: type_name = "hitwhistle"; break; + case oshu::HIT_SOUND|oshu::FINISH_SOUND: type_name = "hitfinish"; break; + case oshu::HIT_SOUND|oshu::CLAP_SOUND: type_name = "hitclap"; break; + case oshu::SLIDER_SOUND|oshu::NORMAL_SOUND: type_name = "sliderslide"; break; + case oshu::SLIDER_SOUND|oshu::WHISTLE_SOUND: type_name = "sliderwhistle"; break; default: oshu_log_debug("unknown sample type %d", (int) set); return {}; @@ -229,7 +229,7 @@ static std::string make_sample_file_name(enum oshu_sample_set_family set, int in * * If no suitable sample file was found, an empty string is returned. */ -static std::string locate_sample(oshu_sound_library *library, enum oshu_sample_set_family set, int index, int type) +static std::string locate_sample(oshu::sound_library *library, enum oshu::sample_set_family set, int index, int type) { std::string filename = make_sample_file_name(set, index, type); if (filename.empty()) @@ -247,17 +247,17 @@ static std::string locate_sample(oshu_sound_library *library, enum oshu_sample_s return {}; } -int oshu_register_sample(struct oshu_sound_library *library, enum oshu_sample_set_family set, int index, int type) +int oshu::register_sample(struct oshu::sound_library *library, enum oshu::sample_set_family set, int index, int type) { - struct oshu_sound_room *room = get_room(library, set); + struct oshu::sound_room *room = get_room(library, set); if (!room) return -1; - struct oshu_sound_shelf *shelf = find_shelf(room, index); + struct oshu::sound_shelf *shelf = find_shelf(room, index); if (!shelf) shelf = new_shelf(room, index); if (!shelf) return -1; - struct oshu_sample **sample = get_sample(shelf, type); + struct oshu::sample **sample = get_sample(shelf, type); if (!sample) return -1; if (*sample) /* already loaded */ @@ -266,51 +266,51 @@ int oshu_register_sample(struct oshu_sound_library *library, enum oshu_sample_se if (path.empty()) return -1; oshu_log_debug("registering %s", path.c_str()); - *sample = (oshu_sample*) calloc(1, sizeof(**sample)); + *sample = (oshu::sample*) calloc(1, sizeof(**sample)); assert (*sample != NULL); assert (library->format != NULL); - int rc = oshu_load_sample(path.c_str(), library->format, *sample); + int rc = oshu::load_sample(path.c_str(), library->format, *sample); if (rc < 0) oshu_log_debug("continuing the process with an empty sample"); return 0; } -void oshu_register_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound) +void oshu::register_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound) { - int target = sound->additions & OSHU_SOUND_TARGET; - if (sound->additions & OSHU_NORMAL_SOUND) - oshu_register_sample(library, sound->sample_set, sound->index, target | OSHU_NORMAL_SOUND); - if (sound->additions & OSHU_WHISTLE_SOUND) - oshu_register_sample(library, sound->additions_set, sound->index, target | OSHU_WHISTLE_SOUND); - if (sound->additions & OSHU_FINISH_SOUND) - oshu_register_sample(library, sound->additions_set, sound->index, target | OSHU_FINISH_SOUND); - if (sound->additions & OSHU_CLAP_SOUND) - oshu_register_sample(library, sound->additions_set, sound->index, target | OSHU_CLAP_SOUND); + int target = sound->additions & oshu::SOUND_TARGET; + if (sound->additions & oshu::NORMAL_SOUND) + oshu::register_sample(library, sound->sample_set, sound->index, target | oshu::NORMAL_SOUND); + if (sound->additions & oshu::WHISTLE_SOUND) + oshu::register_sample(library, sound->additions_set, sound->index, target | oshu::WHISTLE_SOUND); + if (sound->additions & oshu::FINISH_SOUND) + oshu::register_sample(library, sound->additions_set, sound->index, target | oshu::FINISH_SOUND); + if (sound->additions & oshu::CLAP_SOUND) + oshu::register_sample(library, sound->additions_set, sound->index, target | oshu::CLAP_SOUND); } -static void populate_default(struct oshu_sound_library *library, enum oshu_sample_set_family set) +static void populate_default(struct oshu::sound_library *library, enum oshu::sample_set_family set) { - oshu_register_sample(library, set, OSHU_DEFAULT_SHELF, OSHU_HIT_SOUND|OSHU_NORMAL_SOUND); - oshu_register_sample(library, set, OSHU_DEFAULT_SHELF, OSHU_HIT_SOUND|OSHU_WHISTLE_SOUND); - oshu_register_sample(library, set, OSHU_DEFAULT_SHELF, OSHU_HIT_SOUND|OSHU_FINISH_SOUND); - oshu_register_sample(library, set, OSHU_DEFAULT_SHELF, OSHU_HIT_SOUND|OSHU_CLAP_SOUND); - oshu_register_sample(library, set, OSHU_DEFAULT_SHELF, OSHU_SLIDER_SOUND|OSHU_NORMAL_SOUND); - oshu_register_sample(library, set, OSHU_DEFAULT_SHELF, OSHU_SLIDER_SOUND|OSHU_WHISTLE_SOUND); + oshu::register_sample(library, set, oshu::DEFAULT_SHELF, oshu::HIT_SOUND|oshu::NORMAL_SOUND); + oshu::register_sample(library, set, oshu::DEFAULT_SHELF, oshu::HIT_SOUND|oshu::WHISTLE_SOUND); + oshu::register_sample(library, set, oshu::DEFAULT_SHELF, oshu::HIT_SOUND|oshu::FINISH_SOUND); + oshu::register_sample(library, set, oshu::DEFAULT_SHELF, oshu::HIT_SOUND|oshu::CLAP_SOUND); + oshu::register_sample(library, set, oshu::DEFAULT_SHELF, oshu::SLIDER_SOUND|oshu::NORMAL_SOUND); + oshu::register_sample(library, set, oshu::DEFAULT_SHELF, oshu::SLIDER_SOUND|oshu::WHISTLE_SOUND); } -void oshu_populate_library(struct oshu_sound_library *library, struct oshu_beatmap *beatmap) +void oshu::populate_library(struct oshu::sound_library *library, struct oshu::beatmap *beatmap) { int start = SDL_GetTicks(); oshu_log_debug("loading the sample library"); - populate_default(library, OSHU_NORMAL_SAMPLE_SET); - populate_default(library, OSHU_SOFT_SAMPLE_SET); - populate_default(library, OSHU_DRUM_SAMPLE_SET); - for (struct oshu_hit *hit = beatmap->hits; hit; hit = hit->next) { - if (hit->type & OSHU_SLIDER_HIT) { + populate_default(library, oshu::NORMAL_SAMPLE_SET); + populate_default(library, oshu::SOFT_SAMPLE_SET); + populate_default(library, oshu::DRUM_SAMPLE_SET); + for (struct oshu::hit *hit = beatmap->hits; hit; hit = hit->next) { + if (hit->type & oshu::SLIDER_HIT) { for (int i = 0; i <= hit->slider.repeat; ++i) - oshu_register_sound(library, &hit->slider.sounds[i]); + oshu::register_sound(library, &hit->slider.sounds[i]); } - oshu_register_sound(library, &hit->sound); + oshu::register_sound(library, &hit->sound); } int end = SDL_GetTicks(); oshu_log_debug("done loading the library in %.3f seconds", (end - start) / 1000.); @@ -322,22 +322,22 @@ void oshu_populate_library(struct oshu_sound_library *library, struct oshu_beatm * If the wanted sample couldn't be found, return a sane replacement or, in the * worst case scenario, NULL. * - * \sa oshu_play_sound + * \sa oshu::play_sound */ -struct oshu_sample* find_sample(struct oshu_sound_library *library, enum oshu_sample_set_family set, int index, int type) +struct oshu::sample* find_sample(struct oshu::sound_library *library, enum oshu::sample_set_family set, int index, int type) { - struct oshu_sample **sample {nullptr}; - struct oshu_sound_room *room = get_room(library, set); + struct oshu::sample **sample {nullptr}; + struct oshu::sound_room *room = get_room(library, set); if (!room) return NULL; - struct oshu_sound_shelf *shelf = find_shelf(room, index); + struct oshu::sound_shelf *shelf = find_shelf(room, index); if (!shelf) goto round2; sample = get_sample(shelf, type); if (sample && *sample) return *sample; round2: - shelf = find_shelf(room, OSHU_DEFAULT_SHELF); + shelf = find_shelf(room, oshu::DEFAULT_SHELF); if (!shelf) return NULL; sample = get_sample(shelf, type); @@ -346,25 +346,25 @@ struct oshu_sample* find_sample(struct oshu_sound_library *library, enum oshu_sa return *sample; } -static void try_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound, struct oshu_audio *audio, enum oshu_sound_type flag) +static void try_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound, struct oshu::audio *audio, enum oshu::sound_type flag) { if (sound->additions & flag) { - int target = sound->additions & OSHU_SOUND_TARGET; - oshu_sample_set_family set = (flag == OSHU_NORMAL_SOUND) ? sound->sample_set : sound->additions_set; - struct oshu_sample *sample = find_sample(library, set, sound->index, target | flag); + int target = sound->additions & oshu::SOUND_TARGET; + oshu::sample_set_family set = (flag == oshu::NORMAL_SOUND) ? sound->sample_set : sound->additions_set; + struct oshu::sample *sample = find_sample(library, set, sound->index, target | flag); if (!sample) return; - else if (sound->additions & OSHU_SLIDER_SOUND) - oshu_play_loop(audio, sample, sound->volume); + else if (sound->additions & oshu::SLIDER_SOUND) + oshu::play_loop(audio, sample, sound->volume); else - oshu_play_sample(audio, sample, sound->volume); + oshu::play_sample(audio, sample, sound->volume); } } -void oshu_play_sound(struct oshu_sound_library *library, struct oshu_hit_sound *sound, struct oshu_audio *audio) +void oshu::play_sound(struct oshu::sound_library *library, struct oshu::hit_sound *sound, struct oshu::audio *audio) { - try_sound(library, sound, audio, OSHU_NORMAL_SOUND); - try_sound(library, sound, audio, OSHU_WHISTLE_SOUND); - try_sound(library, sound, audio, OSHU_FINISH_SOUND); - try_sound(library, sound, audio, OSHU_CLAP_SOUND); + try_sound(library, sound, audio, oshu::NORMAL_SOUND); + try_sound(library, sound, audio, oshu::WHISTLE_SOUND); + try_sound(library, sound, audio, oshu::FINISH_SOUND); + try_sound(library, sound, audio, oshu::CLAP_SOUND); } diff --git a/lib/audio/sample.cc b/lib/audio/sample.cc index fd65fe0d..c2615a1 100644 --- a/lib/audio/sample.cc +++ b/lib/audio/sample.cc @@ -19,7 +19,7 @@ static const int channels = 2; * * Trust me, your ears don't want you to overlap two incompatible streams. */ -static int convert_audio(SDL_AudioSpec *device_spec, SDL_AudioSpec *wav_spec, struct oshu_sample *sample) +static int convert_audio(SDL_AudioSpec *device_spec, SDL_AudioSpec *wav_spec, struct oshu::sample *sample) { SDL_AudioCVT converter; int rc = SDL_BuildAudioCVT(&converter, @@ -51,7 +51,7 @@ static int convert_audio(SDL_AudioSpec *device_spec, SDL_AudioSpec *wav_spec, st return 0; } -int oshu_load_sample(const char *path, SDL_AudioSpec *spec, struct oshu_sample *sample) +int oshu::load_sample(const char *path, SDL_AudioSpec *spec, struct oshu::sample *sample) { assert (spec->format == AUDIO_F32); assert (spec->channels == channels); @@ -66,11 +66,11 @@ int oshu_load_sample(const char *path, SDL_AudioSpec *spec, struct oshu_sample * sample->nb_samples = sample->size / (channels * sizeof(*sample->samples)); return 0; fail: - oshu_destroy_sample(sample); + oshu::destroy_sample(sample); return -1; } -void oshu_destroy_sample(struct oshu_sample *sample) +void oshu::destroy_sample(struct oshu::sample *sample) { if (sample->samples) { SDL_FreeWAV((Uint8*) sample->samples); diff --git a/lib/audio/stream.cc b/lib/audio/stream.cc index 17f26b1..10c7c0a 100644 --- a/lib/audio/stream.cc +++ b/lib/audio/stream.cc @@ -41,7 +41,7 @@ static void log_av_error(int rc) * * \return 0 on success, -1 on error. */ -static int next_page(struct oshu_stream *stream) +static int next_page(struct oshu::stream *stream) { int rc; AVPacket packet; @@ -69,12 +69,12 @@ static int next_page(struct oshu_stream *stream) } /** - * Read the next frame from the stream into #oshu_stream::frame. + * Read the next frame from the stream into #oshu::stream::frame. * * When the end of file is reached, or when an error occurs, set - * #oshu_stream::finished to true. + * #oshu::stream::finished to true. */ -static int next_frame(struct oshu_stream *stream) +static int next_frame(struct oshu::stream *stream) { for (;;) { int rc = avcodec_receive_frame(stream->decoder, stream->frame); @@ -134,7 +134,7 @@ static int convert_frame(struct SwrContext *converter, AVFrame *frame, int index return rc; } -int oshu_read_stream(struct oshu_stream *stream, float *samples, int nb_samples) +int oshu::read_stream(struct oshu::stream *stream, float *samples, int nb_samples) { int left = nb_samples; while (left > 0 && !stream->finished) { @@ -158,7 +158,7 @@ int oshu_read_stream(struct oshu_stream *stream, float *samples, int nb_samples) * Log some helpful information about the decoded audio stream. * Meant for debugging more than anything else. */ -static void dump_stream_info(struct oshu_stream *stream) +static void dump_stream_info(struct oshu::stream *stream) { oshu_log_info("============ Audio information ============"); oshu_log_info(" Codec: %s.", stream->codec->long_name); @@ -171,12 +171,12 @@ static void dump_stream_info(struct oshu_stream *stream) /** * Open the libavformat demuxer, and find the best stream stream. * - * Fill #oshu_stream::demuxer, #oshu_stream::codec, #oshu_stream::stream and - * #oshu_stream::time_base. + * Fill #oshu::stream::demuxer, #oshu::stream::codec, #oshu::stream::stream and + * #oshu::stream::time_base. * * \return 0 on success, -1 on error. */ -static int open_demuxer(const char *url, struct oshu_stream *stream) +static int open_demuxer(const char *url, struct oshu::stream *stream) { int rc = avformat_open_input(&stream->demuxer, url, NULL, NULL); if (rc < 0) { @@ -215,7 +215,7 @@ static int open_demuxer(const char *url, struct oshu_stream *stream) * * \return 0 on success, and a negative ffmpeg error code on failure. */ -static int open_decoder(struct oshu_stream *stream) +static int open_decoder(struct oshu::stream *stream) { stream->decoder = avcodec_alloc_context3(stream->codec); int rc = avcodec_parameters_to_context( @@ -246,11 +246,11 @@ static int open_decoder(struct oshu_stream *stream) /** * Initialize the libswresample converter to resample data from - * #oshu_stream::decoder into a definied output format. + * #oshu::stream::decoder into a definied output format. * - * The output sample rate must be defined in #oshu_stream::sample_rate. + * The output sample rate must be defined in #oshu::stream::sample_rate. */ -static int open_converter(struct oshu_stream *stream) +static int open_converter(struct oshu::stream *stream) { assert (channels == 2); stream->converter = swr_alloc_set_opts( @@ -278,7 +278,7 @@ static int open_converter(struct oshu_stream *stream) return 0; } -int oshu_open_stream(const char *url, struct oshu_stream *stream) +int oshu::open_stream(const char *url, struct oshu::stream *stream) { /* * av_register_all() got deprecated in lavf 58.9.100 @@ -301,11 +301,11 @@ int oshu_open_stream(const char *url, struct oshu_stream *stream) goto fail; return 0; fail: - oshu_close_stream(stream); + oshu::close_stream(stream); return -1; } -void oshu_close_stream(struct oshu_stream *stream) +void oshu::close_stream(struct oshu::stream *stream) { /* the av routines set the pointers to NULL */ if (stream->frame) @@ -318,7 +318,7 @@ void oshu_close_stream(struct oshu_stream *stream) swr_free(&stream->converter); } -int oshu_seek_stream(struct oshu_stream *stream, double target) +int oshu::seek_stream(struct oshu::stream *stream, double target) { if (target < 0.) { target = 0.; diff --git a/lib/audio/track.cc b/lib/audio/track.cc index 6881d88..bba9e70 100644 --- a/lib/audio/track.cc +++ b/lib/audio/track.cc @@ -13,7 +13,7 @@ /** Work in stereo. */ static const int channels = 2; -void oshu_start_track(struct oshu_track *track, struct oshu_sample *sample, float volume, int loop) +void oshu::start_track(struct oshu::track *track, struct oshu::sample *sample, float volume, int loop) { if (sample && sample->nb_samples == 0) sample = NULL; @@ -23,12 +23,12 @@ void oshu_start_track(struct oshu_track *track, struct oshu_sample *sample, floa track->loop = loop; } -void oshu_stop_track(struct oshu_track *track) +void oshu::stop_track(struct oshu::track *track) { track->sample = NULL; } -int oshu_mix_track(struct oshu_track *track, float *samples, int nb_samples) +int oshu::mix_track(struct oshu::track *track, float *samples, int nb_samples) { int wanted = nb_samples; while (wanted > 0 && track->sample) { diff --git a/lib/beatmap/helpers.cc b/lib/beatmap/helpers.cc index 236873c..0b39dac 100644 --- a/lib/beatmap/helpers.cc +++ b/lib/beatmap/helpers.cc @@ -8,18 +8,18 @@ #include "beatmap/beatmap.h" -double oshu_hit_end_time(struct oshu_hit *hit) +double oshu::hit_end_time(struct oshu::hit *hit) { - if (hit->type & OSHU_SLIDER_HIT) + if (hit->type & oshu::SLIDER_HIT) return hit->time + hit->slider.duration * hit->slider.repeat; else return hit->time; } -oshu_point oshu_end_point(struct oshu_hit *hit) +oshu::point oshu::end_point(struct oshu::hit *hit) { - if (hit->type & OSHU_SLIDER_HIT) - return oshu_path_at(&hit->slider.path, hit->slider.repeat); + if (hit->type & oshu::SLIDER_HIT) + return oshu::path_at(&hit->slider.path, hit->slider.repeat); else return hit->p; } diff --git a/lib/beatmap/parser.cc b/lib/beatmap/parser.cc index ce81733..7867dfb 100644 --- a/lib/beatmap/parser.cc +++ b/lib/beatmap/parser.cc @@ -27,14 +27,14 @@ static const char *osu_file_header = "osu file format v"; * This is especially handy for the difficulty section where many values are * not 0 by default. */ -static const struct oshu_beatmap default_beatmap = { +static const struct oshu::beatmap default_beatmap = { .version = 0, .audio_filename = nullptr, .audio_lead_in = 0, .preview_time = 0, .countdown = 0, - .sample_set = OSHU_SOFT_SAMPLE_SET, - .mode = OSHU_OSU_MODE, + .sample_set = oshu::SOFT_SAMPLE_SET, + .mode = oshu::OSU_MODE, .metadata = {}, .difficulty = { .circle_radius = 32., @@ -404,7 +404,7 @@ static int process_section(struct parser_state *parser) static int process_general(struct parser_state *parser) { - struct oshu_beatmap *beatmap = parser->beatmap; + struct oshu::beatmap *beatmap = parser->beatmap; int rc; enum token key; int i; @@ -437,7 +437,7 @@ static int process_general(struct parser_state *parser) break; case Mode: if ((rc = parse_int(parser, &i)) == 0) - beatmap->mode = (oshu_mode) i; + beatmap->mode = (oshu::mode) i; break; case SampleSet: rc = parse_sample_set(parser, &beatmap->sample_set); @@ -476,23 +476,23 @@ static int process_general(struct parser_state *parser) return rc; } -static int parse_sample_set(struct parser_state *parser, enum oshu_sample_set_family *set) +static int parse_sample_set(struct parser_state *parser, enum oshu::sample_set_family *set) { enum token token; if (parse_token(parser, &token) < 0) return -1; switch (token) { case Drum: - *set = OSHU_DRUM_SAMPLE_SET; + *set = oshu::DRUM_SAMPLE_SET; break; case Normal: - *set = OSHU_NORMAL_SAMPLE_SET; + *set = oshu::NORMAL_SAMPLE_SET; break; case Soft: - *set = OSHU_SOFT_SAMPLE_SET; + *set = oshu::SOFT_SAMPLE_SET; break; case None: - *set = OSHU_NO_SAMPLE_SET; + *set = oshu::NO_SAMPLE_SET; break; default: parser_error(parser, "invalid sample set"); @@ -503,7 +503,7 @@ static int parse_sample_set(struct parser_state *parser, enum oshu_sample_set_fa static int process_metadata(struct parser_state *parser) { - struct oshu_metadata *meta = &parser->beatmap->metadata; + struct oshu::metadata *meta = &parser->beatmap->metadata; enum token key; if (parse_key(parser, &key) < 0) return -1; @@ -528,7 +528,7 @@ static int process_metadata(struct parser_state *parser) static int process_difficulty(struct parser_state *parser) { - struct oshu_difficulty *difficulty = &parser->beatmap->difficulty; + struct oshu::difficulty *difficulty = &parser->beatmap->difficulty; enum token key; double value; if (parse_key(parser, &key) < 0) @@ -604,7 +604,7 @@ static int process_event(struct parser_state *parser) */ static int process_timing_point(struct parser_state *parser) { - struct oshu_timing_point *timing; + struct oshu::timing_point *timing; if (parse_timing_point(parser, &timing) < 0) return -1; if (parser->last_timing_point && timing->offset < parser->last_timing_point->offset) { @@ -621,10 +621,10 @@ static int process_timing_point(struct parser_state *parser) return 0; } -static int parse_timing_point(struct parser_state *parser, struct oshu_timing_point **timing) +static int parse_timing_point(struct parser_state *parser, struct oshu::timing_point **timing) { int value; - *timing = (oshu_timing_point*) calloc(1, sizeof(**timing)); + *timing = (oshu::timing_point*) calloc(1, sizeof(**timing)); assert (timing != NULL); /* 1. Timing offset. */ if (parse_double_sep(parser, &(*timing)->offset, ',') < 0) @@ -656,7 +656,7 @@ static int parse_timing_point(struct parser_state *parser, struct oshu_timing_po /* 4. Sample set. */ if (parse_int_sep(parser, &value, ',') < 0) goto fail; - (*timing)->sample_set = value ? (oshu_sample_set_family) value : parser->beatmap->sample_set; + (*timing)->sample_set = value ? (oshu::sample_set_family) value : parser->beatmap->sample_set; /* 5. Looks like this is the sample set index. */ if (parse_int_sep(parser, &value, ',') < 0) goto fail; @@ -723,7 +723,7 @@ static int process_color_combo(struct parser_state *parser) } /* Parse everything else. */ - struct oshu_color *color; + struct oshu::color *color; consume_spaces(parser); if (consume_char(parser, ':') < 0) return -1; @@ -743,9 +743,9 @@ static int process_color_combo(struct parser_state *parser) return 0; } -static int parse_color(struct parser_state *parser, struct oshu_color **color) +static int parse_color(struct parser_state *parser, struct oshu::color **color) { - *color = (oshu_color*) calloc(1, sizeof(**color)); + *color = (oshu::color*) calloc(1, sizeof(**color)); assert (color != NULL); if (parse_color_channel(parser, &(*color)->red) < 0) goto fail; @@ -782,7 +782,7 @@ static void validate_colors(struct parser_state *parser) if (parser->beatmap->colors) return; oshu_log_debug("no colors; generating a default color scheme"); - oshu_color *color = (oshu_color*) calloc(1, sizeof(*color)); + oshu::color *color = (oshu::color*) calloc(1, sizeof(*color)); color->red = color->green = color->blue = 128; color->next = color; parser->beatmap->colors = color; @@ -802,12 +802,12 @@ static void validate_colors(struct parser_state *parser) * results on further calls, assuming you'd never seek to a point before the * last seek. */ -static struct oshu_timing_point* seek_timing_point(double offset, struct parser_state *parser) +static struct oshu::timing_point* seek_timing_point(double offset, struct parser_state *parser) { if (parser->current_timing_point == NULL) parser->current_timing_point = parser->beatmap->timing_points; /* update the parser state as we loop */ - struct oshu_timing_point **tp = &parser->current_timing_point; + struct oshu::timing_point **tp = &parser->current_timing_point; for (; *tp && (*tp)->next; *tp = (*tp)->next) { if ((*tp)->next->offset > offset) break; @@ -816,11 +816,11 @@ static struct oshu_timing_point* seek_timing_point(double offset, struct parser_ } /** - * Compute #oshu_hit::combo and #oshu_hit::combo_seq of a single #oshu_hit. + * Compute #oshu::hit::combo and #oshu::hit::combo_seq of a single #oshu::hit. * - * Also the update the #oshu_hit::color. + * Also the update the #oshu::hit::color. * - * The common case for a new combo is to have the #OSHU_NEW_HIT_COMBO flag set + * The common case for a new combo is to have the #oshu::NEW_HIT_COMBO flag set * and the combo skip at 0. * * \todo @@ -829,15 +829,15 @@ static struct oshu_timing_point* seek_timing_point(double offset, struct parser_ * - What if the initial hit has a combo skip? * - What if the combo skip is non-zero but the new combo flag is unset? */ -static void compute_hit_combo(struct parser_state *parser, struct oshu_hit *hit) +static void compute_hit_combo(struct parser_state *parser, struct oshu::hit *hit) { assert (parser->last_hit != NULL); if (parser->last_hit->time < 0.) { hit->combo = 0; hit->combo_seq = 1; hit->color = parser->beatmap->colors; - } else if (hit->type & OSHU_NEW_HIT_COMBO) { - int skip_combo = (hit->type & OSHU_COMBO_HIT_MASK) >> OSHU_COMBO_HIT_OFFSET; + } else if (hit->type & oshu::NEW_HIT_COMBO) { + int skip_combo = (hit->type & oshu::COMBO_HIT_MASK) >> oshu::COMBO_HIT_OFFSET; hit->combo = parser->last_hit->combo + 1 + skip_combo; hit->combo_seq = 1; hit->color = parser->last_hit->color; @@ -858,12 +858,12 @@ static void compute_hit_combo(struct parser_state *parser, struct oshu_hit *hit) * Therefore, we need to re-process the slider's sounds after the hit is * completely parser. */ -static void fill_slider_additions(struct oshu_hit *hit) +static void fill_slider_additions(struct oshu::hit *hit) { - assert (hit->type & OSHU_SLIDER_HIT); + assert (hit->type & oshu::SLIDER_HIT); for (int i = 0; i <= hit->slider.repeat; ++i) { - struct oshu_hit_sound *s = &hit->slider.sounds[i]; - s->additions |= OSHU_NORMAL_SOUND; + struct oshu::hit_sound *s = &hit->slider.sounds[i]; + s->additions |= oshu::NORMAL_SOUND; if (!s->sample_set) s->sample_set = hit->sound.sample_set; if (!s->additions_set) @@ -875,7 +875,7 @@ static void fill_slider_additions(struct oshu_hit *hit) static int process_hit_object(struct parser_state *parser) { - struct oshu_hit *hit; + struct oshu::hit *hit; if (parse_hit_object(parser, &hit) < 0) return -1; compute_hit_combo(parser, hit); @@ -900,9 +900,9 @@ static int process_hit_object(struct parser_state *parser) * Consumes: * `288,256,8538,2,0,P|254:261|219:255,1,70,8|0,0:0|0:0,0:0:0:0:` */ -static int parse_hit_object(struct parser_state *parser, struct oshu_hit **hit) +static int parse_hit_object(struct parser_state *parser, struct oshu::hit **hit) { - *hit = (oshu_hit*) calloc(1, sizeof(**hit)); + *hit = (oshu::hit*) calloc(1, sizeof(**hit)); assert (*hit != NULL); if (parse_common_hit(parser, *hit) < 0) goto fail; @@ -911,16 +911,16 @@ static int parse_hit_object(struct parser_state *parser, struct oshu_hit **hit) parser_error(parser, "could not find the timing point for this hit"); goto fail; } - if (!((*hit)->type & OSHU_CIRCLE_HIT) && consume_char(parser, ',') < 0) + if (!((*hit)->type & oshu::CIRCLE_HIT) && consume_char(parser, ',') < 0) goto fail; int rc; - if ((*hit)->type & OSHU_CIRCLE_HIT) { + if ((*hit)->type & oshu::CIRCLE_HIT) { rc = 0; - } else if ((*hit)->type & OSHU_SLIDER_HIT) { + } else if ((*hit)->type & oshu::SLIDER_HIT) { rc = parse_slider(parser, *hit); - } else if ((*hit)->type & OSHU_SPINNER_HIT) { + } else if ((*hit)->type & oshu::SPINNER_HIT) { rc = parse_spinner(parser, *hit); - } else if ((*hit)->type & OSHU_HOLD_HIT) { + } else if ((*hit)->type & oshu::HOLD_HIT) { rc = parse_hold_note(parser, *hit); } else { parser_error(parser, "unknown type"); @@ -930,7 +930,7 @@ static int parse_hit_object(struct parser_state *parser, struct oshu_hit **hit) goto fail; if (parse_additions(parser, *hit) < 0) goto fail; - if ((*hit)->type & OSHU_SLIDER_HIT) + if ((*hit)->type & oshu::SLIDER_HIT) fill_slider_additions(*hit); return 0; fail: @@ -945,14 +945,14 @@ static int parse_hit_object(struct parser_state *parser, struct oshu_hit **hit) * Consumes: * `288,256,8538,2,0` */ -static int parse_common_hit(struct parser_state *parser, struct oshu_hit *hit) +static int parse_common_hit(struct parser_state *parser, struct oshu::hit *hit) { double x, y; if (parse_double_sep(parser, &x, ',') < 0) return -1; if (parse_double_sep(parser, &y, ',') < 0) return -1; - hit->p = oshu_point{x, y}; + hit->p = oshu::point{x, y}; if (parse_double_sep(parser, &hit->time, ',') < 0) return -1; hit->time /= 1000.; @@ -960,9 +960,9 @@ static int parse_common_hit(struct parser_state *parser, struct oshu_hit *hit) return -1; if (parse_int(parser, &hit->sound.additions) < 0) return -1; - hit->sound.additions |= OSHU_NORMAL_SOUND; - if (hit->type & OSHU_SLIDER_HIT) - hit->sound.additions |= OSHU_SLIDER_SOUND; + hit->sound.additions |= oshu::NORMAL_SOUND; + if (hit->type & oshu::SLIDER_HIT) + hit->sound.additions |= oshu::SLIDER_SOUND; return 0; } @@ -977,7 +977,7 @@ static int parse_common_hit(struct parser_state *parser, struct oshu_hit *hit) * Some sliders are shorter and omit the slider additions, like that: * `160,76,142685,6,0,B|156:120|116:152,1,70,8|0` */ -static int parse_slider(struct parser_state *parser, struct oshu_hit *hit) +static int parse_slider(struct parser_state *parser, struct oshu::hit *hit) { char type; if (parse_char(parser, &type) < 0) @@ -986,9 +986,9 @@ static int parse_slider(struct parser_state *parser, struct oshu_hit *hit) return -1; int rc; switch (type) { - case OSHU_LINEAR_PATH: rc = parse_linear_slider(parser, hit); break; - case OSHU_PERFECT_PATH: rc = parse_perfect_slider(parser, hit); break; - case OSHU_BEZIER_PATH: rc = parse_bezier_slider(parser, hit); break; + case oshu::LINEAR_PATH: rc = parse_linear_slider(parser, hit); break; + case oshu::PERFECT_PATH: rc = parse_perfect_slider(parser, hit); break; + case oshu::BEZIER_PATH: rc = parse_bezier_slider(parser, hit); break; default: parser_error(parser, "unknown slider type"); return -1; @@ -1002,7 +1002,7 @@ static int parse_slider(struct parser_state *parser, struct oshu_hit *hit) if (parse_double(parser, &hit->slider.length) < 0) return -1; hit->slider.duration = hit->slider.length / (100. * parser->beatmap->difficulty.slider_multiplier) * hit->timing_point->beat_duration; - oshu_normalize_path(&hit->slider.path, hit->slider.length); + oshu::normalize_path(&hit->slider.path, hit->slider.length); if (parse_slider_additions(parser, hit) < 0) return -1; return 0; @@ -1012,14 +1012,14 @@ static int parse_slider(struct parser_state *parser, struct oshu_hit *hit) * Consumes: * `168:88` */ -static int parse_point(struct parser_state *parser, oshu_point *p) +static int parse_point(struct parser_state *parser, oshu::point *p) { double x, y; if (parse_double_sep(parser, &x, ':') < 0) return -1; if (parse_double(parser, &y) < 0) return -1; - *p = oshu_point{x, y}; + *p = oshu::point{x, y}; return 0; } @@ -1032,10 +1032,10 @@ static int parse_point(struct parser_state *parser, oshu_point *p) * \todo * Parse polyline paths, like `L|X:Y|X:Y`. */ -static int parse_linear_slider(struct parser_state *parser, struct oshu_hit *hit) +static int parse_linear_slider(struct parser_state *parser, struct oshu::hit *hit) { - struct oshu_path *path = &hit->slider.path; - path->type = OSHU_LINEAR_PATH; + struct oshu::path *path = &hit->slider.path; + path->type = oshu::LINEAR_PATH; path->line.start = hit->p; if (parse_point(parser, &path->line.end) < 0) return -1; @@ -1051,9 +1051,9 @@ static int parse_linear_slider(struct parser_state *parser, struct oshu_hit *hit * Consumes: * `396:140|448:80' */ -static int parse_perfect_slider(struct parser_state *parser, struct oshu_hit *hit) +static int parse_perfect_slider(struct parser_state *parser, struct oshu::hit *hit) { - oshu_point a, b, c; + oshu::point a, b, c; a = hit->p; if (parse_point(parser, &b) < 0) return -1; @@ -1062,10 +1062,10 @@ static int parse_perfect_slider(struct parser_state *parser, struct oshu_hit *hi if (parse_point(parser, &c) < 0) return -1; - hit->slider.path.type = OSHU_PERFECT_PATH; - if (oshu_build_arc(a, b, c, &hit->slider.path.arc) < 0) { + hit->slider.path.type = oshu::PERFECT_PATH; + if (oshu::build_arc(a, b, c, &hit->slider.path.arc) < 0) { oshu_log_debug("degenerate perfect arc slider, turning it into a line"); - hit->slider.path.type = OSHU_LINEAR_PATH; + hit->slider.path.type = oshu::LINEAR_PATH; hit->slider.path.line.start = a; hit->slider.path.line.end = c; } @@ -1092,7 +1092,7 @@ static int parse_perfect_slider(struct parser_state *parser, struct oshu_hit *hi * \todo * Reclaim the unused memory in the indices aray. */ -static int parse_bezier_slider(struct parser_state *parser, struct oshu_hit *hit) +static int parse_bezier_slider(struct parser_state *parser, struct oshu::hit *hit) { int count = 2; for (char *c = parser->input; *c != '\0' && *c != ','; ++c) { @@ -1100,9 +1100,9 @@ static int parse_bezier_slider(struct parser_state *parser, struct oshu_hit *hit count++; } - hit->slider.path.type = OSHU_BEZIER_PATH; - struct oshu_bezier *bezier = &hit->slider.path.bezier; - bezier->control_points = (oshu_point*) calloc(count, sizeof(*bezier->control_points)); + hit->slider.path.type = oshu::BEZIER_PATH; + struct oshu::bezier *bezier = &hit->slider.path.bezier; + bezier->control_points = (oshu::point*) calloc(count, sizeof(*bezier->control_points)); assert (bezier->control_points != NULL); bezier->control_points[0] = hit->p; @@ -1111,11 +1111,11 @@ static int parse_bezier_slider(struct parser_state *parser, struct oshu_hit *hit assert (bezier->indices != NULL); bezier->indices[index] = 0; - oshu_point prev = bezier->control_points[0]; + oshu::point prev = bezier->control_points[0]; for (int i = 1; i < count; i++) { if (i > 1 && consume_char(parser, '|') < 0) goto fail; - oshu_point p; + oshu::point p; if (parse_point(parser, &p) < 0) goto fail; bezier->control_points[i] = p; @@ -1141,9 +1141,9 @@ static int parse_bezier_slider(struct parser_state *parser, struct oshu_hit *hit * Consumes: * `4|2,1:2|0:3 */ -static int parse_slider_additions(struct parser_state *parser, struct oshu_hit *hit) +static int parse_slider_additions(struct parser_state *parser, struct oshu::hit *hit) { - hit->slider.sounds = (oshu_hit_sound*) calloc(hit->slider.repeat + 1, sizeof(*hit->slider.sounds)); + hit->slider.sounds = (oshu::hit_sound*) calloc(hit->slider.repeat + 1, sizeof(*hit->slider.sounds)); assert (hit->slider.sounds != NULL); /* Degenerate case. */ if (*parser->input == '\0') @@ -1169,10 +1169,10 @@ static int parse_slider_additions(struct parser_state *parser, struct oshu_hit * goto fail; if (parse_int_sep(parser, &value, ':') < 0) goto fail; - hit->slider.sounds[i].sample_set = (oshu_sample_set_family) value; + hit->slider.sounds[i].sample_set = (oshu::sample_set_family) value; if (parse_int(parser, &value) < 0) goto fail; - hit->slider.sounds[i].additions_set = (oshu_sample_set_family) value; + hit->slider.sounds[i].additions_set = (oshu::sample_set_family) value; } return 0; fail: @@ -1187,7 +1187,7 @@ static int parse_slider_additions(struct parser_state *parser, struct oshu_hit * * Consumes: * - `16620` */ -static int parse_spinner(struct parser_state *parser, struct oshu_hit *hit) +static int parse_spinner(struct parser_state *parser, struct oshu::hit *hit) { if (parse_double(parser, &hit->spinner.end_time) < 0) return -1; @@ -1201,7 +1201,7 @@ static int parse_spinner(struct parser_state *parser, struct oshu_hit *hit) * Consumes: * `16620` */ -static int parse_hold_note(struct parser_state *parser, struct oshu_hit *hit) +static int parse_hold_note(struct parser_state *parser, struct oshu::hit *hit) { if (parse_double(parser, &hit->hold_note.end_time) < 0) return -1; @@ -1222,7 +1222,7 @@ static int parse_hold_note(struct parser_state *parser, struct oshu_hit *hit) * \todo * Store the optional filename at the end when present. */ -static int parse_additions(struct parser_state *parser, struct oshu_hit *hit) +static int parse_additions(struct parser_state *parser, struct oshu::hit *hit) { /* 0. Fill defaults. */ hit->sound.sample_set = hit->timing_point->sample_set; @@ -1237,14 +1237,14 @@ static int parse_additions(struct parser_state *parser, struct oshu_hit *hit) /* 1. Sample set. */ if (parse_int(parser, &value) < 0) return -1; - hit->sound.sample_set = value ? (oshu_sample_set_family) value : hit->timing_point->sample_set; + hit->sound.sample_set = value ? (oshu::sample_set_family) value : hit->timing_point->sample_set; if (*parser->input != ':') return 0; consume_char(parser, ':'); /* 2. Additions set. */ if (parse_int(parser, &value) < 0) return -1; - hit->sound.additions_set = value ? (oshu_sample_set_family) value : hit->timing_point->sample_set; + hit->sound.additions_set = value ? (oshu::sample_set_family) value : hit->timing_point->sample_set; if (*parser->input != ':') return 0; consume_char(parser, ':'); @@ -1284,7 +1284,7 @@ static int parse_additions(struct parser_state *parser, struct oshu_hit *hit) * Stop reading the file if the header is incorrect. It's no use printing a * mega list of warnings if the file clearly looks nothing like text. */ -static int parse_file(FILE *input, const char *name, struct oshu_beatmap *beatmap, bool headers_only) +static int parse_file(FILE *input, const char *name, struct oshu::beatmap *beatmap, bool headers_only) { struct parser_state parser; memset(&parser, 0, sizeof(parser)); @@ -1315,8 +1315,8 @@ static int parse_file(FILE *input, const char *name, struct oshu_beatmap *beatma } free(line); /* Finalize the hits sequence. */ - struct oshu_hit *end; - end = (oshu_hit*) calloc(1, sizeof(*end)); + struct oshu::hit *end; + end = (oshu::hit*) calloc(1, sizeof(*end)); assert (end != NULL); end->time = INFINITY; parser.last_hit->next = end; @@ -1328,15 +1328,15 @@ static int parse_file(FILE *input, const char *name, struct oshu_beatmap *beatma * Initialize the beatmap to its defaults, and add the first unreachable hit * object. */ -void initialize(struct oshu_beatmap *beatmap) +void initialize(struct oshu::beatmap *beatmap) { memcpy(beatmap, &default_beatmap, sizeof(*beatmap)); - beatmap->hits = (oshu_hit*) calloc(1, sizeof(*beatmap->hits)); + beatmap->hits = (oshu::hit*) calloc(1, sizeof(*beatmap->hits)); assert (beatmap->hits != NULL); beatmap->hits->time = -INFINITY; } -static int validate_metadata(struct oshu_metadata *meta) +static int validate_metadata(struct oshu::metadata *meta) { if (!meta->title) return -1; @@ -1351,7 +1351,7 @@ static int validate_metadata(struct oshu_metadata *meta) * Perform a variety of checks on a beatmap file to ensure it was parsed well * enough to be played. */ -static int validate(struct oshu_beatmap *beatmap) +static int validate(struct oshu::beatmap *beatmap) { if (!beatmap->audio_filename) { oshu_log_error("no audio file mentionned"); @@ -1364,7 +1364,7 @@ static int validate(struct oshu_beatmap *beatmap) return 0; } -static int load_beatmap(const char *path, struct oshu_beatmap *beatmap, bool headers_only) +static int load_beatmap(const char *path, struct oshu::beatmap *beatmap, bool headers_only) { oshu_log_debug("loading beatmap %s", path); @@ -1392,21 +1392,21 @@ static int load_beatmap(const char *path, struct oshu_beatmap *beatmap, bool hea return 0; fail: oshu_log_error("error loading the beatmap file"); - oshu_destroy_beatmap(beatmap); + oshu::destroy_beatmap(beatmap); return -1; } -int oshu_load_beatmap(const char *path, struct oshu_beatmap *beatmap) +int oshu::load_beatmap(const char *path, struct oshu::beatmap *beatmap) { - return load_beatmap(path, beatmap, false); + return ::load_beatmap(path, beatmap, false); } -int oshu_load_beatmap_headers(const char *path, struct oshu_beatmap *beatmap) +int oshu::load_beatmap_headers(const char *path, struct oshu::beatmap *beatmap) { - return load_beatmap(path, beatmap, true); + return ::load_beatmap(path, beatmap, true); } -static void free_metadata(struct oshu_metadata *meta) +static void free_metadata(struct oshu::metadata *meta) { free(meta->title); free(meta->title_unicode); @@ -1417,20 +1417,20 @@ static void free_metadata(struct oshu_metadata *meta) free(meta->source); } -static void free_path(struct oshu_path *path) +static void free_path(struct oshu::path *path) { - if (path->type == OSHU_BEZIER_PATH) { + if (path->type == oshu::BEZIER_PATH) { free(path->bezier.control_points); free(path->bezier.indices); } } -static void free_hits(struct oshu_hit *hits) +static void free_hits(struct oshu::hit *hits) { - struct oshu_hit *current = hits; + struct oshu::hit *current = hits; while (current != NULL) { - struct oshu_hit *next = current->next; - if (current->type & OSHU_SLIDER_HIT) { + struct oshu::hit *next = current->next; + if (current->type & oshu::SLIDER_HIT) { free_path(¤t->slider.path); free(current->slider.sounds); } @@ -1439,29 +1439,29 @@ static void free_hits(struct oshu_hit *hits) } } -static void free_timing_points(struct oshu_timing_point *t) +static void free_timing_points(struct oshu::timing_point *t) { - struct oshu_timing_point *current = t; + struct oshu::timing_point *current = t; while (current != NULL) { - struct oshu_timing_point *next = current->next; + struct oshu::timing_point *next = current->next; free(current); current = next; } } -static void free_colors(struct oshu_color *colors) +static void free_colors(struct oshu::color *colors) { if (!colors) return; - struct oshu_color *current = colors; + struct oshu::color *current = colors; do { - struct oshu_color *next = current->next; + struct oshu::color *next = current->next; free(current); current = next; } while (current != colors); } -void oshu_destroy_beatmap(struct oshu_beatmap *beatmap) +void oshu::destroy_beatmap(struct oshu::beatmap *beatmap) { free(beatmap->audio_filename); free(beatmap->background_filename); diff --git a/lib/beatmap/parser.h b/lib/beatmap/parser.h index a64c816..8e37f9a 100644 --- a/lib/beatmap/parser.h +++ b/lib/beatmap/parser.h @@ -161,7 +161,7 @@ struct parser_state { * * Its memory isn't handled by us. */ - struct oshu_beatmap *beatmap; + struct oshu::beatmap *beatmap; /** * The current section. * @@ -177,11 +177,11 @@ struct parser_state { /** * Keep track of the last timing point to build the linked list. */ - struct oshu_timing_point *last_timing_point; + struct oshu::timing_point *last_timing_point; /** * Keep track of the last color to build the circular linked list. */ - struct oshu_color *last_color; + struct oshu::color *last_color; /** * When parsing hit objects, we need to figure out what its timing * point is, notably to compute slider durations. @@ -190,16 +190,16 @@ struct parser_state { * It must not become NULL at the end of the chain, because otherwise * we're back to the first case and will trigger an infinite loop. */ - struct oshu_timing_point *current_timing_point; + struct oshu::timing_point *current_timing_point; /** - * This is the #oshu_timing_point::beat_duration of the last + * This is the #oshu::timing_point::beat_duration of the last * non-inherited timing point. */ double timing_base; /** * Keep track of the last hit object to build the linked list. */ - struct oshu_hit *last_hit; + struct oshu::hit *last_hit; }; /** @@ -238,29 +238,29 @@ static int process_input(P*); static int process_header(P*); static int process_section(P*); static int process_general(P*); - static int parse_sample_set(P*, enum oshu_sample_set_family*); + static int parse_sample_set(P*, enum oshu::sample_set_family*); static int process_metadata(P*); static int process_difficulty(P*); static int process_event(P*); static int process_timing_point(P*); - static int parse_timing_point(P*, struct oshu_timing_point**); + static int parse_timing_point(P*, struct oshu::timing_point**); static int process_color(P*); static int process_color_combo(P*); - static int parse_color(P*, struct oshu_color**); + static int parse_color(P*, struct oshu::color**); static int parse_color_channel(P*, double*); static void validate_colors(P*); static int process_hit_object(P*); - static int parse_hit_object(P*, struct oshu_hit**); - static int parse_common_hit(P*, struct oshu_hit*); - static int parse_slider(P*, struct oshu_hit*); - static int parse_point(P*, oshu_point*); - static int parse_linear_slider(P*, struct oshu_hit*); - static int parse_perfect_slider(P*, struct oshu_hit*); - static int parse_bezier_slider(P*, struct oshu_hit*); - static int parse_slider_additions(P*, struct oshu_hit*); - static int parse_spinner(P*, struct oshu_hit*); - static int parse_hold_note(P*, struct oshu_hit*); - static int parse_additions(P*, struct oshu_hit*); + static int parse_hit_object(P*, struct oshu::hit**); + static int parse_common_hit(P*, struct oshu::hit*); + static int parse_slider(P*, struct oshu::hit*); + static int parse_point(P*, oshu::point*); + static int parse_linear_slider(P*, struct oshu::hit*); + static int parse_perfect_slider(P*, struct oshu::hit*); + static int parse_bezier_slider(P*, struct oshu::hit*); + static int parse_slider_additions(P*, struct oshu::hit*); + static int parse_spinner(P*, struct oshu::hit*); + static int parse_hold_note(P*, struct oshu::hit*); + static int parse_additions(P*, struct oshu::hit*); namespace oshu { diff --git a/lib/beatmap/path.cc b/lib/beatmap/path.cc index 0c247ad..7526667 100644 --- a/lib/beatmap/path.cc +++ b/lib/beatmap/path.cc @@ -18,16 +18,16 @@ static double epsilon = 0.001; /** * Extend a box so that the point *p* fits in. */ -static void extend_box(oshu_point p, oshu_point *top_left, oshu_point *bottom_right) +static void extend_box(oshu::point p, oshu::point *top_left, oshu::point *bottom_right) { if (std::real(p) < std::real(*top_left)) - *top_left = oshu_point(std::real(p), std::imag(*top_left)); + *top_left = oshu::point(std::real(p), std::imag(*top_left)); if (std::imag(p) < std::imag(*top_left)) - *top_left = oshu_point(std::real(*top_left), std::imag(p)); + *top_left = oshu::point(std::real(*top_left), std::imag(p)); if (std::real(p) > std::real(*bottom_right)) - *bottom_right = oshu_point(std::real(p), std::imag(*bottom_right)); + *bottom_right = oshu::point(std::real(p), std::imag(*bottom_right)); if (std::imag(p) > std::imag(*bottom_right)) - *bottom_right = oshu_point(std::real(*bottom_right), std::imag(p)); + *bottom_right = oshu::point(std::real(*bottom_right), std::imag(p)); } /* Bézier *********************************************************************/ @@ -102,7 +102,7 @@ static int focus(double *t, int n) * * \sa focus */ -static void bezier_map(struct oshu_bezier *path, double *t, int *degree, oshu_point **control_points) +static void bezier_map(struct oshu::bezier *path, double *t, int *degree, oshu::point **control_points) { int segment = focus(t, path->segment_count); *degree = path->indices[segment+1] - path->indices[segment] - 1; @@ -119,12 +119,12 @@ static void bezier_map(struct oshu_bezier *path, double *t, int *degree, oshu_po * super high-degree Bézier curves on some beatmaps, and the factorial was at * its limits. */ -static oshu_point bezier_at(struct oshu_bezier *path, double t) +static oshu::point bezier_at(struct oshu::bezier *path, double t) { int degree; - oshu_point *points; + oshu::point *points; bezier_map(path, &t, °ree, &points); - oshu_point pp[degree + 1]; + oshu::point pp[degree + 1]; memcpy(pp, points, (degree + 1) * sizeof(*pp)); /* l is the logical length of pp. @@ -153,18 +153,18 @@ static oshu_point bezier_at(struct oshu_bezier *path, double t) * The memory reallocation implies the memory must have been dynamically * allocated. You won't be able to grow a static path. */ -static int grow_bezier(struct oshu_bezier *bezier, double extension) +static int grow_bezier(struct oshu::bezier *bezier, double extension) { assert (bezier->segment_count >= 1); assert (bezier->indices != NULL); assert (bezier->control_points != NULL); size_t n = bezier->indices[bezier->segment_count]; assert (n >= 2); - oshu_point end = bezier->control_points[n - 1]; - oshu_point before_end = bezier->control_points[n - 2]; + oshu::point end = bezier->control_points[n - 1]; + oshu::point before_end = bezier->control_points[n - 2]; oshu_log_debug("expanding the bezier path by %f pixels", extension); - oshu_vector direction = end - before_end; + oshu::vector direction = end - before_end; if (std::abs(direction) < epsilon) { oshu_log_warning("cannot grow a bezier path whose end is stationary"); return -1; @@ -174,7 +174,7 @@ static int grow_bezier(struct oshu_bezier *bezier, double extension) bezier->indices = (int*) realloc(bezier->indices, (bezier->segment_count + 1) * sizeof(*bezier->indices)); bezier->indices[bezier->segment_count] = n + 2; - bezier->control_points = (oshu_point*) realloc(bezier->control_points, (n + 2) * sizeof(*bezier->control_points)); + bezier->control_points = (oshu::point*) realloc(bezier->control_points, (n + 2) * sizeof(*bezier->control_points)); bezier->control_points[n] = end; bezier->control_points[n + 1] = end + direction / std::abs(direction) * extension; return 0; @@ -183,9 +183,9 @@ static int grow_bezier(struct oshu_bezier *bezier, double extension) /** * Approximate the length of the segment and set-up the l-coordinate system. * - * Receives a Bézier path whose #oshu_bezier::segment_count, - * #oshu_bezier::indices and #oshu_bezier::control_points are filled, and use - * these data to compute the #oshu_bezier::anchors field. + * Receives a Bézier path whose #oshu::bezier::segment_count, + * #oshu::bezier::indices and #oshu::bezier::control_points are filled, and use + * these data to compute the #oshu::bezier::anchors field. * * Here are the steps of the normalization process: * @@ -203,7 +203,7 @@ static int grow_bezier(struct oshu_bezier *bezier, double extension) * `l_n ≥ 1`, which in turns implies that the final curve is cut, the * desired effect. * - * 4. Now, let's compute #oshu_bezier::anchors. + * 4. Now, let's compute #oshu::bezier::anchors. * For every anchor index `j`, let `l = j / (# of anchors - 1)`, and find * `i` such that `l_i ≤ l ≤ l_(i+1)`. * Compute `k` such that `l = (1-k) * l_i + k * l_(i+1)`. @@ -211,7 +211,7 @@ static int grow_bezier(struct oshu_bezier *bezier, double extension) * Finally, let `anchors[j] = (1-k) * t_i + k * t_(i+1)`. * */ -void normalize_bezier(struct oshu_bezier *bezier, double target_length) +void normalize_bezier(struct oshu::bezier *bezier, double target_length) { /* 1. Prepare the field. */ int n = 64; /* arbitrary */ @@ -221,10 +221,10 @@ void normalize_bezier(struct oshu_bezier *bezier, double target_length) begin: /* 2. Compute the length of the path. */ length = 0; - oshu_point prev = bezier->control_points[0]; + oshu::point prev = bezier->control_points[0]; for (int i = 0; i <= n; i++) { double t = (double) i / n; - oshu_point current = bezier_at(bezier, t); + oshu::point current = bezier_at(bezier, t); length += std::abs(prev - current); l[i] = length; prev = current; @@ -266,7 +266,7 @@ void normalize_bezier(struct oshu_bezier *bezier, double target_length) * * \sa normalize_bezier */ -static double l_to_t(struct oshu_bezier *bezier, double l) +static double l_to_t(struct oshu::bezier *bezier, double l) { int n = sizeof(bezier->anchors) / sizeof(*bezier->anchors) - 1; int i = focus(&l, n); @@ -277,7 +277,7 @@ static double l_to_t(struct oshu_bezier *bezier, double l) * Every point on a Bézier line is an average of all the control points, so * it's safe to compute the bounding box of the polyline defined by them. */ -void bezier_bounding_box(struct oshu_bezier *bezier, oshu_point *top_left, oshu_point *bottom_right) +void bezier_bounding_box(struct oshu::bezier *bezier, oshu::point *top_left, oshu::point *bottom_right) { assert (bezier->segment_count > 0); *top_left = *bottom_right = bezier->control_points[0]; @@ -291,12 +291,12 @@ void bezier_bounding_box(struct oshu_bezier *bezier, oshu_point *top_left, oshu_ /** * Simple weighted average of the starting point and end point. */ -static oshu_point line_at(struct oshu_line *line, double t) +static oshu::point line_at(struct oshu::line *line, double t) { return (1 - t) * line->start + t * line->end; } -static void normalize_line(struct oshu_line *line, double target_length) +static void normalize_line(struct oshu::line *line, double target_length) { double actual_length = std::abs(line->start - line->end); assert (target_length > 0); @@ -305,7 +305,7 @@ static void normalize_line(struct oshu_line *line, double target_length) line->end = line->start + (line->end - line->start) * factor; } -void line_bounding_box(struct oshu_line *line, oshu_point *top_left, oshu_point *bottom_right) +void line_bounding_box(struct oshu::line *line, oshu::point *top_left, oshu::point *bottom_right) { *top_left = *bottom_right = line->start; extend_box(line->start, top_left, bottom_right); @@ -314,7 +314,7 @@ void line_bounding_box(struct oshu_line *line, oshu_point *top_left, oshu_point /* Perfect circle arcs ********************************************************/ -static oshu_point arc_at(struct oshu_arc *arc, double t) +static oshu::point arc_at(struct oshu::arc *arc, double t) { double angle = (1 - t) * arc->start_angle + t * arc->end_angle; return arc->center + std::polar(arc->radius, angle); @@ -325,7 +325,7 @@ static oshu_point arc_at(struct oshu_arc *arc, double t) * * This code is inspired by the official osu! client's source code. */ -int arc_center(oshu_point a, oshu_point b, oshu_point c, oshu_point *center) +int arc_center(oshu::point a, oshu::point b, oshu::point c, oshu::point *center) { double a2 = std::norm(b - c); double b2 = std::norm(a - c); @@ -344,7 +344,7 @@ int arc_center(oshu_point a, oshu_point b, oshu_point c, oshu_point *center) return 0; } -int oshu_build_arc(oshu_point a, oshu_point b, oshu_point c, struct oshu_arc *arc) +int oshu::build_arc(oshu::point a, oshu::point b, oshu::point c, struct oshu::arc *arc) { if (arc_center(a, b, c, &arc->center) < 0) return -1; @@ -361,7 +361,7 @@ int oshu_build_arc(oshu_point a, oshu_point b, oshu_point c, struct oshu_arc *ar return 0; } -static void normalize_arc(struct oshu_arc *arc, double target_length) +static void normalize_arc(struct oshu::arc *arc, double target_length) { double target_angle = target_length / arc->radius; double diff = copysign(target_angle, arc->end_angle - arc->start_angle); @@ -377,7 +377,7 @@ static void normalize_arc(struct oshu_arc *arc, double target_length) * Then, add the two extremities of the arc, and, for any side of the circle * reached, extend the box. */ -void arc_bounding_box(struct oshu_arc *arc, oshu_point *top_left, oshu_point *bottom_right) +void arc_bounding_box(struct oshu::arc *arc, oshu::point *top_left, oshu::point *bottom_right) { double min = arc->start_angle < arc->end_angle ? arc->start_angle : arc->end_angle; double max = arc->start_angle > arc->end_angle ? arc->start_angle : arc->end_angle; @@ -397,10 +397,10 @@ void arc_bounding_box(struct oshu_arc *arc, oshu_point *top_left, oshu_point *bo extend_box(arc_at(arc, 1.), top_left, bottom_right); double angle = 0; - oshu_vector radius = arc->radius; + oshu::vector radius = arc->radius; for (int i = 1; i < 8; ++i) { angle += M_PI / 2.; - radius *= oshu_vector(0, 1); + radius *= oshu::vector(0, 1); if (min < angle && angle < max) extend_box(arc->center + radius, top_left, bottom_right); } @@ -408,55 +408,55 @@ void arc_bounding_box(struct oshu_arc *arc, oshu_point *top_left, oshu_point *bo /* Generic interface **********************************************************/ -void oshu_normalize_path(struct oshu_path *path, double length) +void oshu::normalize_path(struct oshu::path *path, double length) { switch (path->type) { - case OSHU_LINEAR_PATH: + case oshu::LINEAR_PATH: return normalize_line(&path->line, length); - case OSHU_PERFECT_PATH: + case oshu::PERFECT_PATH: return normalize_arc(&path->arc, length); - case OSHU_BEZIER_PATH: + case oshu::BEZIER_PATH: return normalize_bezier(&path->bezier, length); default: return; } } -oshu_point oshu_path_at(struct oshu_path *path, double t) +oshu::point oshu::path_at(struct oshu::path *path, double t) { /* map t from ℝ to [0,1] */ t = fabs(remainder(t, 2.)); assert (-epsilon <= t && t <= 1 + epsilon); switch (path->type) { - case OSHU_LINEAR_PATH: + case oshu::LINEAR_PATH: return line_at(&path->line, t); - case OSHU_BEZIER_PATH: + case oshu::BEZIER_PATH: t = l_to_t(&path->bezier, t); return bezier_at(&path->bezier, t); - case OSHU_PERFECT_PATH: + case oshu::PERFECT_PATH: return arc_at(&path->arc, t); - case OSHU_CATMULL_PATH: - assert (path->type != OSHU_CATMULL_PATH); + case oshu::CATMULL_PATH: + assert (path->type != oshu::CATMULL_PATH); default: assert (path->type != path->type); } return 0; } -void oshu_path_bounding_box(struct oshu_path *path, oshu_point *top_left, oshu_point *bottom_right) +void oshu::path_bounding_box(struct oshu::path *path, oshu::point *top_left, oshu::point *bottom_right) { switch (path->type) { - case OSHU_LINEAR_PATH: + case oshu::LINEAR_PATH: line_bounding_box(&path->line, top_left, bottom_right); break; - case OSHU_BEZIER_PATH: + case oshu::BEZIER_PATH: bezier_bounding_box(&path->bezier, top_left, bottom_right); break; - case OSHU_PERFECT_PATH: + case oshu::PERFECT_PATH: arc_bounding_box(&path->arc, top_left, bottom_right); break; - case OSHU_CATMULL_PATH: - assert (path->type != OSHU_CATMULL_PATH); + case oshu::CATMULL_PATH: + assert (path->type != oshu::CATMULL_PATH); default: assert (path->type != path->type); } diff --git a/lib/core/geometry.cc b/lib/core/geometry.cc index d671710..f52b04c 100644 --- a/lib/core/geometry.cc +++ b/lib/core/geometry.cc @@ -5,7 +5,7 @@ #include "core/geometry.h" -double oshu_ratio(oshu_size size) +double oshu::ratio(oshu::size size) { return std::real(size) / std::imag(size); } diff --git a/lib/game/base.cc b/lib/game/base.cc index 582cc81..deeaf21 100644 --- a/lib/game/base.cc +++ b/lib/game/base.cc @@ -18,11 +18,11 @@ static int open_beatmap(const char *beatmap_path, struct oshu::game_base *game) { - if (oshu_load_beatmap(beatmap_path, &game->beatmap) < 0) { + if (oshu::load_beatmap(beatmap_path, &game->beatmap) < 0) { oshu_log_error("no beatmap, aborting"); return -1; } - if (game->beatmap.mode != OSHU_OSU_MODE) { + if (game->beatmap.mode != oshu::OSU_MODE) { oshu_log_error("unsupported game mode"); return -1; } @@ -34,12 +34,12 @@ static int open_beatmap(const char *beatmap_path, struct oshu::game_base *game) static int open_audio(struct oshu::game_base *game) { assert (game->beatmap.audio_filename != NULL); - if (oshu_open_audio(game->beatmap.audio_filename, &game->audio) < 0) { + if (oshu::open_audio(game->beatmap.audio_filename, &game->audio) < 0) { oshu_log_error("no audio, aborting"); return -1; } - oshu_open_sound_library(&game->library, &game->audio.device_spec); - oshu_populate_library(&game->library, &game->beatmap); + oshu::open_sound_library(&game->library, &game->audio.device_spec); + oshu::populate_library(&game->library, &game->beatmap); return 0; } @@ -49,59 +49,59 @@ game_base::game_base(const char *beatmap_path) { if (open_beatmap(beatmap_path, this) < 0) throw std::runtime_error("could not load the beatmap"); - if (open_audio(this) < 0) + if (::open_audio(this) < 0) throw std::runtime_error("could not open the audio device"); } game_base::~game_base() { - oshu_destroy_beatmap(&beatmap); - oshu_close_audio(&audio); - oshu_close_sound_library(&library); + oshu::destroy_beatmap(&beatmap); + oshu::close_audio(&audio); + oshu::close_sound_library(&library); } void game_base::rewind(double offset) { - oshu_seek_music(&this->audio, this->audio.music.current_timestamp - offset); + oshu::seek_music(&this->audio, this->audio.music.current_timestamp - offset); this->clock.now = this->audio.music.current_timestamp; this->relinquish(); - oshu_print_state(this); + oshu::print_state(this); assert (this->hit_cursor != NULL); while (this->hit_cursor->time > this->clock.now + 1.) { - this->hit_cursor->state = OSHU_INITIAL_HIT; + this->hit_cursor->state = oshu::INITIAL_HIT; this->hit_cursor = this->hit_cursor->previous; } } void game_base::forward(double offset) { - oshu_seek_music(&this->audio, this->audio.music.current_timestamp + offset); + oshu::seek_music(&this->audio, this->audio.music.current_timestamp + offset); this->clock.now = this->audio.music.current_timestamp; this->relinquish(); - oshu_print_state(this); + oshu::print_state(this); assert (this->hit_cursor != NULL); while (this->hit_cursor->time < this->clock.now + 1.) { - this->hit_cursor->state = OSHU_SKIPPED_HIT; + this->hit_cursor->state = oshu::SKIPPED_HIT; this->hit_cursor = this->hit_cursor->next; } } void game_base::pause() { - oshu_pause_audio(&this->audio); + oshu::pause_audio(&this->audio); this->paused = true; - oshu_print_state(this); + oshu::print_state(this); } void game_base::unpause() { if (this->clock.now >= 0) - oshu_play_audio(&this->audio); + oshu::play_audio(&this->audio); this->paused = false; - oshu_print_state(this); + oshu::print_state(this); } } diff --git a/lib/game/clock.cc b/lib/game/clock.cc index f307289..387d5ba 100644 --- a/lib/game/clock.cc +++ b/lib/game/clock.cc @@ -8,7 +8,7 @@ #include "core/log.h" #include "game/base.h" -void oshu_initialize_clock(struct oshu::game_base *game) +void oshu::initialize_clock(struct oshu::game_base *game) { if (game->beatmap.audio_lead_in > 0.) { game->clock.now = - game->beatmap.audio_lead_in; @@ -25,9 +25,9 @@ void oshu_initialize_clock(struct oshu::game_base *game) * Find a better way to determine if the music is playing. The clock shouldn't * take the game screen into consideration. */ -void oshu_update_clock(struct oshu::game_base *game) +void oshu::update_clock(struct oshu::game_base *game) { - struct oshu_clock *clock = &game->clock; + struct oshu::clock *clock = &game->clock; double system = SDL_GetTicks() / 1000.; double diff = system - clock->system; double prev_audio = clock->audio; diff --git a/lib/game/controls.cc b/lib/game/controls.cc index 1db2f2a..38941da 100644 --- a/lib/game/controls.cc +++ b/lib/game/controls.cc @@ -7,24 +7,24 @@ #include -enum oshu_finger oshu_translate_key(SDL_Keysym *keysym) +enum oshu::finger oshu::translate_key(SDL_Keysym *keysym) { switch (keysym->scancode) { /* Bottom row, for standard and taiko modes. */ - case SDL_SCANCODE_Z: return OSHU_LEFT_MIDDLE; - case SDL_SCANCODE_X: return OSHU_LEFT_INDEX; - case SDL_SCANCODE_C: return OSHU_RIGHT_INDEX; - case SDL_SCANCODE_V: return OSHU_RIGHT_MIDDLE; + case SDL_SCANCODE_Z: return oshu::LEFT_MIDDLE; + case SDL_SCANCODE_X: return oshu::LEFT_INDEX; + case SDL_SCANCODE_C: return oshu::RIGHT_INDEX; + case SDL_SCANCODE_V: return oshu::RIGHT_MIDDLE; /* Middle row, for mania. */ - case SDL_SCANCODE_A: return OSHU_LEFT_PINKY; - case SDL_SCANCODE_S: return OSHU_LEFT_RING; - case SDL_SCANCODE_D: return OSHU_LEFT_MIDDLE; - case SDL_SCANCODE_F: return OSHU_LEFT_INDEX; - case SDL_SCANCODE_SPACE: return OSHU_THUMBS; - case SDL_SCANCODE_J: return OSHU_RIGHT_INDEX; - case SDL_SCANCODE_K: return OSHU_RIGHT_MIDDLE; - case SDL_SCANCODE_L: return OSHU_RIGHT_RING; - case SDL_SCANCODE_SEMICOLON: return OSHU_RIGHT_PINKY; - default: return OSHU_UNKNOWN_KEY; + case SDL_SCANCODE_A: return oshu::LEFT_PINKY; + case SDL_SCANCODE_S: return oshu::LEFT_RING; + case SDL_SCANCODE_D: return oshu::LEFT_MIDDLE; + case SDL_SCANCODE_F: return oshu::LEFT_INDEX; + case SDL_SCANCODE_SPACE: return oshu::THUMBS; + case SDL_SCANCODE_J: return oshu::RIGHT_INDEX; + case SDL_SCANCODE_K: return oshu::RIGHT_MIDDLE; + case SDL_SCANCODE_L: return oshu::RIGHT_RING; + case SDL_SCANCODE_SEMICOLON: return oshu::RIGHT_PINKY; + default: return oshu::UNKNOWN_KEY; } } diff --git a/lib/game/helpers.cc b/lib/game/helpers.cc index 79dc356..6a7b738 100644 --- a/lib/game/helpers.cc +++ b/lib/game/helpers.cc @@ -5,23 +5,23 @@ #include "game/base.h" -struct oshu_hit* oshu_look_hit_back(struct oshu::game_base *game, double offset) +struct oshu::hit* oshu::look_hit_back(struct oshu::game_base *game, double offset) { - struct oshu_hit *hit = game->hit_cursor; + struct oshu::hit *hit = game->hit_cursor; double target = game->clock.now - offset; /* seek backward */ - while (oshu_hit_end_time(hit) > target) + while (oshu::hit_end_time(hit) > target) hit = hit->previous; /* seek forward */ - while (oshu_hit_end_time(hit) < target) + while (oshu::hit_end_time(hit) < target) hit = hit->next; /* here we have the guarantee that hit->time >= target */ return hit; } -struct oshu_hit* oshu_look_hit_up(struct oshu::game_base *game, double offset) +struct oshu::hit* oshu::look_hit_up(struct oshu::game_base *game, double offset) { - struct oshu_hit *hit = game->hit_cursor; + struct oshu::hit *hit = game->hit_cursor; double target = game->clock.now + offset; /* seek forward */ while (hit->time < target) @@ -33,23 +33,23 @@ struct oshu_hit* oshu_look_hit_up(struct oshu::game_base *game, double offset) return hit; } -struct oshu_hit* oshu_next_hit(struct oshu::game_base *game) +struct oshu::hit* oshu::next_hit(struct oshu::game_base *game) { - struct oshu_hit *hit = game->hit_cursor; + struct oshu::hit *hit = game->hit_cursor; for (; hit->next; hit = hit->next) { - if (hit->type & (OSHU_CIRCLE_HIT | OSHU_SLIDER_HIT)) + if (hit->type & (oshu::CIRCLE_HIT | oshu::SLIDER_HIT)) break; } return hit; } -struct oshu_hit* oshu_previous_hit(struct oshu::game_base *game) +struct oshu::hit* oshu::previous_hit(struct oshu::game_base *game) { - struct oshu_hit *hit = game->hit_cursor; + struct oshu::hit *hit = game->hit_cursor; if (!hit->previous) return hit; for (hit = hit->previous; hit->previous; hit = hit->previous) { - if (hit->type & (OSHU_CIRCLE_HIT | OSHU_SLIDER_HIT)) + if (hit->type & (oshu::CIRCLE_HIT | oshu::SLIDER_HIT)) break; } return hit; diff --git a/lib/game/osu.cc b/lib/game/osu.cc index 6148c31..f2e99c1 100644 --- a/lib/game/osu.cc +++ b/lib/game/osu.cc @@ -12,7 +12,7 @@ #include -osu_game::osu_game(const char *beatmap_path) +oshu::osu_game::osu_game(const char *beatmap_path) : oshu::game_base(beatmap_path) { } @@ -25,14 +25,14 @@ osu_game::osu_game(const char *beatmap_path) * * If two hit objects overlap, yield the oldest unclicked one. */ -static struct oshu_hit* find_hit(struct osu_game *game, oshu_point p) +static struct oshu::hit* find_hit(struct oshu::osu_game *game, oshu::point p) { - struct oshu_hit *start = oshu_look_hit_back(game, game->beatmap.difficulty.approach_time); + struct oshu::hit *start = oshu::look_hit_back(game, game->beatmap.difficulty.approach_time); double max_time = game->clock.now + game->beatmap.difficulty.approach_time; - for (struct oshu_hit *hit = start; hit->time <= max_time; hit = hit->next) { - if (!(hit->type & (OSHU_CIRCLE_HIT | OSHU_SLIDER_HIT))) + for (struct oshu::hit *hit = start; hit->time <= max_time; hit = hit->next) { + if (!(hit->type & (oshu::CIRCLE_HIT | oshu::SLIDER_HIT))) continue; - if (hit->state != OSHU_INITIAL_HIT) + if (hit->state != oshu::INITIAL_HIT) continue; if (std::abs(p - hit->p) <= game->beatmap.difficulty.circle_radius) return hit; @@ -46,10 +46,10 @@ static struct oshu_hit* find_hit(struct osu_game *game, oshu_point p) * It is unlikely that once a slider is marked as good or missed, it will ever * be shown once again. The main exception is when the user seeks. */ -static void jettison_hit(struct oshu_hit *hit) +static void jettison_hit(struct oshu::hit *hit) { if (hit->texture) { - oshu_destroy_texture(hit->texture); + oshu::destroy_texture(hit->texture); free(hit->texture); hit->texture = NULL; } @@ -59,20 +59,20 @@ static void jettison_hit(struct oshu_hit *hit) * Release the held slider, either because the held key is released, or because * a new slider is activated (somehow). */ -static void release_slider(struct osu_game *game) +static void release_slider(struct oshu::osu_game *game) { - struct oshu_hit *hit = game->current_slider; + struct oshu::hit *hit = game->current_slider; if (!hit) return; - assert (hit->type & OSHU_SLIDER_HIT); - if (game->clock.now < oshu_hit_end_time(hit) - game->beatmap.difficulty.leniency) { - hit->state = OSHU_MISSED_HIT; + assert (hit->type & oshu::SLIDER_HIT); + if (game->clock.now < oshu::hit_end_time(hit) - game->beatmap.difficulty.leniency) { + hit->state = oshu::MISSED_HIT; } else { - hit->state = OSHU_GOOD_HIT; - oshu_play_sound(&game->library, &hit->slider.sounds[hit->slider.repeat], &game->audio); + hit->state = oshu::GOOD_HIT; + oshu::play_sound(&game->library, &hit->slider.sounds[hit->slider.repeat], &game->audio); } jettison_hit(hit); - oshu_stop_loop(&game->audio); + oshu::stop_loop(&game->audio); game->current_slider = NULL; } @@ -81,19 +81,19 @@ static void release_slider(struct osu_game *game) * * When the last one is reached, release the slider. */ -static void sonorize_slider(struct osu_game *game) +static void sonorize_slider(struct oshu::osu_game *game) { - struct oshu_hit *hit = game->current_slider; + struct oshu::hit *hit = game->current_slider; if (!hit) return; - assert (hit->type & OSHU_SLIDER_HIT); + assert (hit->type & oshu::SLIDER_HIT); int t = (game->clock.now - hit->time) / hit->slider.duration; int prev_t = (game->clock.before - hit->time) / hit->slider.duration; - if (game->clock.now > oshu_hit_end_time(hit)) { + if (game->clock.now > oshu::hit_end_time(hit)) { release_slider(game); } else if (t > prev_t && prev_t >= 0) { assert (t <= hit->slider.repeat); - oshu_play_sound(&game->library, &hit->slider.sounds[t], &game->audio); + oshu::play_sound(&game->library, &hit->slider.sounds[t], &game->audio); } } @@ -106,30 +106,30 @@ static void sonorize_slider(struct osu_game *game) * Also mark sliders as missed if the mouse is too far from where it's supposed * to be. */ -int osu_game::check() +int oshu::osu_game::check() { /* Ensure the mouse follows the slider. */ sonorize_slider(this); /* < may release the slider! */ if (this->current_slider && mouse) { - struct oshu_hit *hit = this->current_slider; + struct oshu::hit *hit = this->current_slider; double t = (this->clock.now - hit->time) / hit->slider.duration; - oshu_point ball = oshu_path_at(&hit->slider.path, t); - oshu_point m = mouse->position(); + oshu::point ball = oshu::path_at(&hit->slider.path, t); + oshu::point m = mouse->position(); if (std::abs(ball - m) > this->beatmap.difficulty.slider_tolerance) { - oshu_stop_loop(&this->audio); + oshu::stop_loop(&this->audio); this->current_slider = NULL; - hit->state = OSHU_MISSED_HIT; + hit->state = oshu::MISSED_HIT; jettison_hit(hit); } } /* Mark dead notes as missed. */ double left_wall = this->clock.now - this->beatmap.difficulty.leniency; while (this->hit_cursor->time < left_wall) { - struct oshu_hit *hit = this->hit_cursor; - if (!(hit->type & (OSHU_CIRCLE_HIT | OSHU_SLIDER_HIT))) { - hit->state = OSHU_UNKNOWN_HIT; - } else if (hit->state == OSHU_INITIAL_HIT) { - hit->state = OSHU_MISSED_HIT; + struct oshu::hit *hit = this->hit_cursor; + if (!(hit->type & (oshu::CIRCLE_HIT | oshu::SLIDER_HIT))) { + hit->state = oshu::UNKNOWN_HIT; + } else if (hit->state == oshu::INITIAL_HIT) { + hit->state = oshu::MISSED_HIT; jettison_hit(hit); } this->hit_cursor = hit->next; @@ -146,31 +146,31 @@ int osu_game::check() * The key is the held key, relevant only for sliders. In autoplay mode, it's * value doesn't matter. */ -static void activate_hit(struct osu_game *game, struct oshu_hit *hit, enum oshu_finger key) +static void activate_hit(struct oshu::osu_game *game, struct oshu::hit *hit, enum oshu::finger key) { - if (hit->type & OSHU_SLIDER_HIT) { + if (hit->type & oshu::SLIDER_HIT) { release_slider(game); - hit->state = OSHU_SLIDING_HIT; + hit->state = oshu::SLIDING_HIT; game->current_slider = hit; game->held_key = key; - oshu_play_sound(&game->library, &hit->sound, &game->audio); - oshu_play_sound(&game->library, &hit->slider.sounds[0], &game->audio); - } else if (hit->type & OSHU_CIRCLE_HIT) { - hit->state = OSHU_GOOD_HIT; - oshu_play_sound(&game->library, &hit->sound, &game->audio); + oshu::play_sound(&game->library, &hit->sound, &game->audio); + oshu::play_sound(&game->library, &hit->slider.sounds[0], &game->audio); + } else if (hit->type & oshu::CIRCLE_HIT) { + hit->state = oshu::GOOD_HIT; + oshu::play_sound(&game->library, &hit->sound, &game->audio); } else { - hit->state = OSHU_UNKNOWN_HIT; + hit->state = oshu::UNKNOWN_HIT; } } /** * Automatically activate the sliders on time. */ -int osu_game::check_autoplay() +int oshu::osu_game::check_autoplay() { sonorize_slider(this); while (this->hit_cursor->time < this->clock.now) { - activate_hit(this, this->hit_cursor, OSHU_UNKNOWN_KEY); + activate_hit(this, this->hit_cursor, oshu::UNKNOWN_KEY); this->hit_cursor = this->hit_cursor->next; } return 0; @@ -181,19 +181,19 @@ int osu_game::check_autoplay() * * Play a sample depending on what was clicked, and when. */ -int osu_game::press(enum oshu_finger key) +int oshu::osu_game::press(enum oshu::finger key) { if (!mouse) return 0; - oshu_point m = mouse->position(); - struct oshu_hit *hit = find_hit(this, m); + oshu::point m = mouse->position(); + struct oshu::hit *hit = find_hit(this, m); if (!hit) return 0; if (fabs(hit->time - this->clock.now) < this->beatmap.difficulty.leniency) { activate_hit(this, hit, key); hit->offset = this->clock.now - hit->time; } else { - hit->state = OSHU_MISSED_HIT; + hit->state = oshu::MISSED_HIT; jettison_hit(hit); } return 0; @@ -203,18 +203,18 @@ int osu_game::press(enum oshu_finger key) * When the user is holding a slider or a hold note in mania mode, release the * thing. */ -int osu_game::release(enum oshu_finger key) +int oshu::osu_game::release(enum oshu::finger key) { if (this->held_key == key) release_slider(this); return 0; } -int osu_game::relinquish() +int oshu::osu_game::relinquish() { if (this->current_slider) { - this->current_slider->state = OSHU_INITIAL_HIT; - oshu_stop_loop(&this->audio); + this->current_slider->state = oshu::INITIAL_HIT; + oshu::stop_loop(&this->audio); this->current_slider = NULL; } return 0; diff --git a/lib/game/tty.cc b/lib/game/tty.cc index da7bc89..1d22c7b 100644 --- a/lib/game/tty.cc +++ b/lib/game/tty.cc @@ -21,10 +21,10 @@ void print_dual(const char *ascii, const char *unicode) printf(" Unknown\n"); } -void oshu_welcome(struct oshu::game_base *game) +void oshu::welcome(struct oshu::game_base *game) { - struct oshu_beatmap *beatmap = &game->beatmap; - struct oshu_metadata *meta = &beatmap->metadata; + struct oshu::beatmap *beatmap = &game->beatmap; + struct oshu::metadata *meta = &beatmap->metadata; printf("\n"); print_dual(meta->title, meta->title_unicode); print_dual(meta->artist, meta->artist_unicode); @@ -53,7 +53,7 @@ void oshu_welcome(struct oshu::game_base *game) * \todo * This function should be deleted once the window can display the time. */ -void oshu_print_state(struct oshu::game_base *game) +void oshu::print_state(struct oshu::game_base *game) { if (!isatty(fileno(stdout))) return; @@ -70,17 +70,17 @@ void oshu_print_state(struct oshu::game_base *game) fflush(stdout); } -void oshu_congratulate(struct oshu::game_base *game) +void oshu::congratulate(struct oshu::game_base *game) { /* Clear the status line. */ printf("\r \r"); /* Compute the score. */ int good = 0; int missed = 0; - for (struct oshu_hit *hit = game->beatmap.hits; hit; hit = hit->next) { - if (hit->state == OSHU_MISSED_HIT) + for (struct oshu::hit *hit = game->beatmap.hits; hit; hit = hit->next) { + if (hit->state == oshu::MISSED_HIT) missed++; - else if (hit->state == OSHU_GOOD_HIT) + else if (hit->state == oshu::GOOD_HIT) good++; } double rate = (double) good / (good + missed); diff --git a/lib/library/beatmaps.cc b/lib/library/beatmaps.cc index 7abfed1..54b76dd 100644 --- a/lib/library/beatmaps.cc +++ b/lib/library/beatmaps.cc @@ -19,8 +19,8 @@ namespace oshu { beatmap_entry::beatmap_entry(const std::string &path) : path(path) { - oshu_beatmap beatmap; - int rc = oshu_load_beatmap_headers(path.c_str(), &beatmap); + oshu::beatmap beatmap; + int rc = oshu::load_beatmap_headers(path.c_str(), &beatmap); if (rc < 0) throw std::runtime_error("could not load beatmap " + path); mode = beatmap.mode; @@ -28,7 +28,7 @@ beatmap_entry::beatmap_entry(const std::string &path) title = beatmap.metadata.title; artist = beatmap.metadata.artist; version = beatmap.metadata.version; - oshu_destroy_beatmap(&beatmap); + oshu::destroy_beatmap(&beatmap); } static bool osu_file(const char *filename) @@ -62,7 +62,7 @@ static void find_entries(const std::string &path, beatmap_set &set) std::ostringstream os; os << path << "/" << entry->d_name; beatmap_entry entry (os.str()); - if (entry.mode != OSHU_OSU_MODE) + if (entry.mode != oshu::OSU_MODE) oshu::debug_log() << "skipping " << path << ": unsupported mode" << std::endl; else set.entries.push_back(std::move(entry)); diff --git a/lib/ui/audio.cc b/lib/ui/audio.cc index 7810e6e..8f4edb9 100644 --- a/lib/ui/audio.cc +++ b/lib/ui/audio.cc @@ -11,14 +11,14 @@ #include #include -int oshu_create_audio_progress_bar(struct oshu_display *display, struct oshu_stream *stream, struct oshu_audio_progress_bar *bar) +int oshu::create_audio_progress_bar(struct oshu::display *display, struct oshu::stream *stream, struct oshu::audio_progress_bar *bar) { bar->display = display; bar->stream = stream; return 0; } -void oshu_show_audio_progress_bar(struct oshu_audio_progress_bar *bar) +void oshu::show_audio_progress_bar(struct oshu::audio_progress_bar *bar) { assert (bar->stream->duration != 0); double progression = bar->stream->current_timestamp / bar->stream->duration; @@ -39,6 +39,6 @@ void oshu_show_audio_progress_bar(struct oshu_audio_progress_bar *bar) SDL_RenderFillRect(bar->display->renderer, &shape); } -void oshu_destroy_audio_progress_bar(struct oshu_audio_progress_bar *bar) +void oshu::destroy_audio_progress_bar(struct oshu::audio_progress_bar *bar) { } diff --git a/lib/ui/background.cc b/lib/ui/background.cc index 7ce5242..9c0d8bc 100644 --- a/lib/ui/background.cc +++ b/lib/ui/background.cc @@ -25,11 +25,11 @@ * The result is written in *dest*, such that the rectangle covers the whole * window while possibly being cropped. */ -static void fit(struct oshu_display *display, oshu_size size, SDL_Rect *dest) +static void fit(struct oshu::display *display, oshu::size size, SDL_Rect *dest) { - oshu_size vsize = display->view.size; - double window_ratio = oshu_ratio(vsize);; - double pic_ratio = oshu_ratio(size); + oshu::size vsize = display->view.size; + double window_ratio = oshu::ratio(vsize);; + double pic_ratio = oshu::ratio(size); if (window_ratio > pic_ratio) { /* the window is too wide */ @@ -53,7 +53,7 @@ static void fit(struct oshu_display *display, oshu_size size, SDL_Rect *dest) * point to the new scaled surface. * * First, the resulting image size is computing using the same function as - * #oshu_show_background. If the resulting size is smaller than the original + * #oshu::show_background. If the resulting size is smaller than the original * size, do nothing. * * Then, the image is converted to unpacked RGB: each pixel is made of 4-bytes, @@ -76,10 +76,10 @@ static void fit(struct oshu_display *display, oshu_size size, SDL_Rect *dest) * \todo * Handle cairo errors. */ -static int scale_background(struct oshu_display *display, SDL_Surface **pic) +static int scale_background(struct oshu::display *display, SDL_Surface **pic) { SDL_Rect target_rect; - fit(display, oshu_size((*pic)->w, (*pic)->h), &target_rect); + fit(display, oshu::size((*pic)->w, (*pic)->h), &target_rect); if (target_rect.w >= (*pic)->w) return 0; /* don't upscale */ double zoom = (double) target_rect.w / (*pic)->w; @@ -120,11 +120,11 @@ static int scale_background(struct oshu_display *display, SDL_Surface **pic) return 0; } -int oshu_load_background(struct oshu_display *display, const char *filename, struct oshu_background *background) +int oshu::load_background(struct oshu::display *display, const char *filename, struct oshu::background *background) { memset(background, 0, sizeof(*background)); background->display = display; - if (!(display->features & OSHU_SHOW_BACKGROUND)) + if (!(display->features & oshu::SHOW_BACKGROUND)) return 0; SDL_Surface *pic = IMG_Load(filename); @@ -135,7 +135,7 @@ int oshu_load_background(struct oshu_display *display, const char *filename, str if (scale_background(display, &pic) < 0) return -1; - background->picture.size = oshu_size(pic->w, pic->h); + background->picture.size = oshu::size(pic->w, pic->h); background->picture.origin = 0; background->picture.texture = SDL_CreateTextureFromSurface(display->renderer, pic); SDL_FreeSurface(pic); @@ -155,14 +155,14 @@ int oshu_load_background(struct oshu_display *display, const char *filename, str * When the aspects don't match, crop the picture to ensure the window is * filled. */ -static void fill_screen(struct oshu_display *display, struct oshu_texture *pic) +static void fill_screen(struct oshu::display *display, struct oshu::texture *pic) { SDL_Rect dest; fit(display, pic->size, &dest); SDL_RenderCopy(display->renderer, pic->texture, NULL, &dest); } -void oshu_show_background(struct oshu_background *background, double brightness) +void oshu::show_background(struct oshu::background *background, double brightness) { if (!background->picture.texture) return; @@ -175,11 +175,11 @@ void oshu_show_background(struct oshu_background *background, double brightness) fill_screen(background->display, &background->picture); } -void oshu_destroy_background(struct oshu_background *background) +void oshu::destroy_background(struct oshu::background *background) { if (!background->display) /* uninitialized background */ return; - if (!(background->display->features & OSHU_SHOW_BACKGROUND)) + if (!(background->display->features & oshu::SHOW_BACKGROUND)) return; - oshu_destroy_texture(&background->picture); + oshu::destroy_texture(&background->picture); } diff --git a/lib/ui/cursor.cc b/lib/ui/cursor.cc index 21a42c1..b76b962 100644 --- a/lib/ui/cursor.cc +++ b/lib/ui/cursor.cc @@ -11,13 +11,13 @@ #include #include -static int paint_cursor(struct oshu_cursor_widget *cursor) +static int paint_cursor(struct oshu::cursor_widget *cursor) { double radius = 14; - oshu_size size = oshu_size{1, 1} * radius * 2.; + oshu::size size = oshu::size{1, 1} * radius * 2.; - struct oshu_painter p; - oshu_start_painting(cursor->display, size, &p); + struct oshu::painter p; + oshu::start_painting(cursor->display, size, &p); cairo_translate(p.cr, radius, radius); cairo_pattern_t *pattern = cairo_pattern_create_radial( @@ -33,41 +33,41 @@ static int paint_cursor(struct oshu_cursor_widget *cursor) cairo_fill(p.cr); cairo_pattern_destroy(pattern); - int rc = oshu_finish_painting(&p, &cursor->mouse); + int rc = oshu::finish_painting(&p, &cursor->mouse); cursor->mouse.origin = size / 2.; return rc; } -int oshu_create_cursor(struct oshu_display *display, struct oshu_cursor_widget *cursor) +int oshu::create_cursor(struct oshu::display *display, struct oshu::cursor_widget *cursor) { memset(cursor, 0, sizeof(*cursor)); cursor->display = display; - if (!(display->features & OSHU_FANCY_CURSOR)) + if (!(display->features & oshu::FANCY_CURSOR)) return 0; int fireflies = sizeof(cursor->history) / sizeof(*cursor->history); - oshu_point mouse = oshu_get_mouse(display); + oshu::point mouse = oshu::get_mouse(display); for (int i = 0; i < fireflies; ++i) cursor->history[i] = mouse; return paint_cursor(cursor); } -void oshu_show_cursor(struct oshu_cursor_widget *cursor) +void oshu::show_cursor(struct oshu::cursor_widget *cursor) { - if (!(cursor->display->features & OSHU_FANCY_CURSOR)) + if (!(cursor->display->features & oshu::FANCY_CURSOR)) return; int fireflies = sizeof(cursor->history) / sizeof(*cursor->history); cursor->offset = (cursor->offset + 1) % fireflies; - cursor->history[cursor->offset] = oshu_get_mouse(cursor->display); + cursor->history[cursor->offset] = oshu::get_mouse(cursor->display); for (int i = 1; i <= fireflies; ++i) { int offset = (cursor->offset + i) % fireflies; double ratio = (double) (i + 1) / (fireflies + 1); SDL_SetTextureAlphaMod(cursor->mouse.texture, ratio * 255); - oshu_draw_scaled_texture( + oshu::draw_scaled_texture( cursor->display, &cursor->mouse, cursor->history[offset], ratio @@ -75,12 +75,12 @@ void oshu_show_cursor(struct oshu_cursor_widget *cursor) } } -void oshu_destroy_cursor(struct oshu_cursor_widget *cursor) +void oshu::destroy_cursor(struct oshu::cursor_widget *cursor) { if (!cursor->display) return; - if (!(cursor->display->features & OSHU_FANCY_CURSOR)) + if (!(cursor->display->features & oshu::FANCY_CURSOR)) return; - oshu_destroy_texture(&cursor->mouse); + oshu::destroy_texture(&cursor->mouse); } diff --git a/lib/ui/index.dox b/lib/ui/index.dox index c41e268..23978d5 100644 --- a/lib/ui/index.dox +++ b/lib/ui/index.dox @@ -9,7 +9,7 @@ * - The widget's state is defined with a structure. * * - The widget is initialized and configured with a `create` function, - * returning an int. The first argument is an #oshu_display, and the last one + * returning an int. The first argument is an #oshu::display, and the last one * a *widget*. All the other parameters are widget-specific. * * - The widget is destroyed with the symmetrical void `destroy` function. Note diff --git a/lib/ui/metadata.cc b/lib/ui/metadata.cc index 06f8356..00abb3c 100644 --- a/lib/ui/metadata.cc +++ b/lib/ui/metadata.cc @@ -20,7 +20,7 @@ static const double padding = 10; -static PangoLayout* setup_layout(struct oshu_painter *p) +static PangoLayout* setup_layout(struct oshu::painter *p) { cairo_set_operator(p->cr, CAIRO_OPERATOR_SOURCE); @@ -41,11 +41,11 @@ static PangoLayout* setup_layout(struct oshu_painter *p) * \todo * Handle errors. */ -static int paint_stars(struct oshu_metadata_frame *frame) +static int paint_stars(struct oshu::metadata_frame *frame) { - oshu_size size {360, 60}; - struct oshu_painter p; - oshu_start_painting(frame->display, size, &p); + oshu::size size {360, 60}; + struct oshu::painter p; + oshu::start_painting(frame->display, size, &p); const char *sky = " ★ ★ ★ ★ ★ ★ ★ ★ ★ ★"; int stars = frame->beatmap->difficulty.overall_difficulty; @@ -54,7 +54,7 @@ static int paint_stars(struct oshu_metadata_frame *frame) int star_length = strlen(sky) / 10; std::string difficulty (sky, star_length * stars); - struct oshu_metadata *meta = &frame->beatmap->metadata; + struct oshu::metadata *meta = &frame->beatmap->metadata; const char *version = meta->version; assert (version != NULL); std::ostringstream os; @@ -70,8 +70,8 @@ static int paint_stars(struct oshu_metadata_frame *frame) pango_cairo_show_layout(p.cr, layout); g_object_unref(layout); - struct oshu_texture *texture = &frame->stars; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = &frame->stars; + int rc = oshu::finish_painting(&p, texture); texture->origin = std::real(size); return rc; } @@ -80,13 +80,13 @@ static int paint_stars(struct oshu_metadata_frame *frame) * \todo * Handle errors. */ -static int paint_metadata(struct oshu_metadata_frame *frame, int unicode) +static int paint_metadata(struct oshu::metadata_frame *frame, int unicode) { - oshu_size size {640, 60}; - struct oshu_painter p; - oshu_start_painting(frame->display, size, &p); + oshu::size size {640, 60}; + struct oshu::painter p; + oshu::start_painting(frame->display, size, &p); - struct oshu_metadata *meta = &frame->beatmap->metadata; + struct oshu::metadata *meta = &frame->beatmap->metadata; const char *title = unicode ? meta->title_unicode : meta->title; const char *artist = unicode ? meta->artist_unicode : meta->artist; std::ostringstream os; @@ -101,8 +101,8 @@ static int paint_metadata(struct oshu_metadata_frame *frame, int unicode) pango_cairo_show_layout(p.cr, layout); g_object_unref(layout); - struct oshu_texture *texture = unicode ? &frame->unicode : &frame->ascii; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = unicode ? &frame->unicode : &frame->ascii; + int rc = oshu::finish_painting(&p, texture); texture->origin = 0; return rc; } @@ -111,9 +111,9 @@ static int paint_metadata(struct oshu_metadata_frame *frame, int unicode) * \todo * Handle errors. */ -static int paint(struct oshu_metadata_frame *frame) +static int paint(struct oshu::metadata_frame *frame) { - struct oshu_metadata *meta = &frame->beatmap->metadata; + struct oshu::metadata *meta = &frame->beatmap->metadata; int title_difference = meta->title && meta->title_unicode && strcmp(meta->title, meta->title_unicode); int artist_difference = meta->artist && meta->artist_unicode && strcmp(meta->artist, meta->artist_unicode); @@ -125,7 +125,7 @@ static int paint(struct oshu_metadata_frame *frame) return 0; } -int oshu_create_metadata_frame(struct oshu_display *display, struct oshu_beatmap *beatmap, double *clock, struct oshu_metadata_frame *frame) +int oshu::create_metadata_frame(struct oshu::display *display, struct oshu::beatmap *beatmap, double *clock, struct oshu::metadata_frame *frame) { memset(frame, 0, sizeof(*frame)); frame->display = display; @@ -134,7 +134,7 @@ int oshu_create_metadata_frame(struct oshu_display *display, struct oshu_beatmap return paint(frame); } -void oshu_show_metadata_frame(struct oshu_metadata_frame *frame, double opacity) +void oshu::show_metadata_frame(struct oshu::metadata_frame *frame, double opacity) { SDL_Rect back = { .x = 0, @@ -154,17 +154,17 @@ void oshu_show_metadata_frame(struct oshu_metadata_frame *frame, double opacity) if (progression > .9 && has_unicode) transition = 1. - (progression - .9) * 10.; - struct oshu_texture *meta = unicode ? &frame->unicode : &frame->ascii; + struct oshu::texture *meta = unicode ? &frame->unicode : &frame->ascii; SDL_SetTextureAlphaMod(meta->texture, opacity * transition * 255); - oshu_draw_texture(frame->display, meta, 0); + oshu::draw_texture(frame->display, meta, 0); SDL_SetTextureAlphaMod(frame->stars.texture, opacity * 255); - oshu_draw_texture(frame->display, &frame->stars, std::real(frame->display->view.size)); + oshu::draw_texture(frame->display, &frame->stars, std::real(frame->display->view.size)); } -void oshu_destroy_metadata_frame(struct oshu_metadata_frame *frame) +void oshu::destroy_metadata_frame(struct oshu::metadata_frame *frame) { - oshu_destroy_texture(&frame->ascii); - oshu_destroy_texture(&frame->unicode); - oshu_destroy_texture(&frame->stars); + oshu::destroy_texture(&frame->ascii); + oshu::destroy_texture(&frame->unicode); + oshu::destroy_texture(&frame->stars); } diff --git a/lib/ui/osu.cc b/lib/ui/osu.cc index e26842f..5f3ff29 100644 --- a/lib/ui/osu.cc +++ b/lib/ui/osu.cc @@ -14,82 +14,82 @@ #include -static void draw_hint(oshu::osu_ui &view, struct oshu_hit *hit) +static void draw_hint(oshu::osu_ui &view, struct oshu::hit *hit) { oshu::game_base *game = &view.game; double now = game->clock.now; - if (hit->time > now && hit->state == OSHU_INITIAL_HIT) { + if (hit->time > now && hit->state == oshu::INITIAL_HIT) { SDL_SetRenderDrawColor(view.display->renderer, 255, 128, 64, 255); double ratio = (double) (hit->time - now) / game->beatmap.difficulty.approach_time; double base_radius = game->beatmap.difficulty.circle_radius; double radius = base_radius + ratio * game->beatmap.difficulty.approach_size; - oshu_draw_scaled_texture( + oshu::draw_scaled_texture( view.display, &view.approach_circle, hit->p, 2. * radius / std::real(view.approach_circle.size) ); } } -static void draw_hit_mark(oshu::osu_ui &view, struct oshu_hit *hit) +static void draw_hit_mark(oshu::osu_ui &view, struct oshu::hit *hit) { oshu::game_base *game = &view.game; - if (hit->state == OSHU_GOOD_HIT) { + if (hit->state == oshu::GOOD_HIT) { double leniency = game->beatmap.difficulty.leniency; - struct oshu_texture *mark = &view.good_mark; + struct oshu::texture *mark = &view.good_mark; if (hit->offset < - leniency / 2) mark = &view.early_mark; else if (hit->offset > leniency / 2) mark = &view.late_mark; - oshu_draw_texture(view.display, mark, oshu_end_point(hit)); - } else if (hit->state == OSHU_MISSED_HIT) { - oshu_draw_texture(view.display, &view.bad_mark, oshu_end_point(hit)); - } else if (hit->state == OSHU_SKIPPED_HIT) { - oshu_draw_texture(view.display, &view.skip_mark, oshu_end_point(hit)); + oshu::draw_texture(view.display, mark, oshu::end_point(hit)); + } else if (hit->state == oshu::MISSED_HIT) { + oshu::draw_texture(view.display, &view.bad_mark, oshu::end_point(hit)); + } else if (hit->state == oshu::SKIPPED_HIT) { + oshu::draw_texture(view.display, &view.skip_mark, oshu::end_point(hit)); } } -static void draw_hit_circle(oshu::osu_ui &view, struct oshu_hit *hit) +static void draw_hit_circle(oshu::osu_ui &view, struct oshu::hit *hit) { oshu::game_base *game = &view.game; - struct oshu_display *display = view.display; - if (hit->state == OSHU_INITIAL_HIT) { + struct oshu::display *display = view.display; + if (hit->state == oshu::INITIAL_HIT) { assert (hit->color != NULL); - oshu_draw_texture(display, &view.circles[hit->color->index], hit->p); + oshu::draw_texture(display, &view.circles[hit->color->index], hit->p); draw_hint(view, hit); } else { draw_hit_mark(view, hit); } } -static void draw_slider(oshu::osu_ui &view, struct oshu_hit *hit) +static void draw_slider(oshu::osu_ui &view, struct oshu::hit *hit) { oshu::game_base *game = &view.game; - struct oshu_display *display = view.display; + struct oshu::display *display = view.display; double now = game->clock.now; - if (hit->state == OSHU_INITIAL_HIT || hit->state == OSHU_SLIDING_HIT) { + if (hit->state == oshu::INITIAL_HIT || hit->state == oshu::SLIDING_HIT) { if (!hit->texture) { - osu_paint_slider(view, hit); + oshu::osu_paint_slider(view, hit); assert (hit->texture != NULL); } - oshu_draw_texture(view.display, hit->texture, hit->p); + oshu::draw_texture(view.display, hit->texture, hit->p); draw_hint(view, hit); /* ball */ double t = (now - hit->time) / hit->slider.duration; - if (hit->state == OSHU_SLIDING_HIT) { - oshu_point ball = oshu_path_at(&hit->slider.path, t < 0 ? 0 : t); - oshu_draw_texture(display, &view.slider_ball, ball); + if (hit->state == oshu::SLIDING_HIT) { + oshu::point ball = oshu::path_at(&hit->slider.path, t < 0 ? 0 : t); + oshu::draw_texture(display, &view.slider_ball, ball); } } else { draw_hit_mark(view, hit); } } -static void draw_hit(oshu::osu_ui &view, struct oshu_hit *hit) +static void draw_hit(oshu::osu_ui &view, struct oshu::hit *hit) { oshu::game_base *game = &view.game; - if (hit->type & OSHU_SLIDER_HIT) + if (hit->type & oshu::SLIDER_HIT) draw_slider(view, hit); - else if (hit->type & OSHU_CIRCLE_HIT) + else if (hit->type & oshu::CIRCLE_HIT) draw_hit_circle(view, hit); } @@ -118,12 +118,12 @@ static void draw_hit(oshu::osu_ui &view, struct oshu_hit *hit) * Voilà! * */ -static void connect_hits(oshu::osu_ui &view, struct oshu_hit *a, struct oshu_hit *b) +static void connect_hits(oshu::osu_ui &view, struct oshu::hit *a, struct oshu::hit *b) { oshu::game_base *game = &view.game; - if (a->state != OSHU_INITIAL_HIT && a->state != OSHU_SLIDING_HIT) + if (a->state != oshu::INITIAL_HIT && a->state != oshu::SLIDING_HIT) return; - oshu_point a_end = oshu_end_point(a); + oshu::point a_end = oshu::end_point(a); double radius = game->beatmap.difficulty.circle_radius; double interval = 15; double center_distance = std::abs(b->p - a_end); @@ -133,11 +133,11 @@ static void connect_hits(oshu::osu_ui &view, struct oshu_hit *a, struct oshu_hit int steps = edge_distance / interval; assert (steps >= 1); interval = edge_distance / steps; /* recalibrate */ - oshu_vector direction = (b->p - a_end) / center_distance; - oshu_point start = a_end + direction * radius; - oshu_vector step = direction * interval; + oshu::vector direction = (b->p - a_end) / center_distance; + oshu::point start = a_end + direction * radius; + oshu::vector step = direction * interval; for (int i = 0; i < steps; ++i) - oshu_draw_texture(view.display, &view.connector, start + (i + .5) * step); + oshu::draw_texture(view.display, &view.connector, start + (i + .5) * step); } namespace oshu { @@ -146,15 +146,15 @@ namespace oshu { * \todo * Handle errors. */ -osu_ui::osu_ui(oshu_display *display, osu_game &game) +osu_ui::osu_ui(oshu::display *display, oshu::osu_game &game) : display(display), game(game) { assert (display != nullptr); - osu_view(display); - int rc = osu_paint_resources(*this); - if (oshu_create_cursor(display, &cursor) < 0) + oshu::osu_view(display); + int rc = oshu::osu_paint_resources(*this); + if (oshu::create_cursor(display, &cursor) < 0) rc = -1; - oshu_reset_view(display); + oshu::reset_view(display); mouse = std::make_shared(display); game.mouse = mouse; } @@ -162,8 +162,8 @@ osu_ui::osu_ui(oshu_display *display, osu_game &game) osu_ui::~osu_ui() { SDL_ShowCursor(SDL_ENABLE); - osu_free_resources(*this); - oshu_destroy_cursor(&cursor); + oshu::osu_free_resources(*this); + oshu::destroy_cursor(&cursor); } /** @@ -172,41 +172,41 @@ osu_ui::~osu_ui() */ void osu_ui::draw() { - osu_view(display); - struct oshu_hit *cursor = oshu_look_hit_up(&game, game.beatmap.difficulty.approach_time); - struct oshu_hit *next = NULL; + oshu::osu_view(display); + struct oshu::hit *cursor = oshu::look_hit_up(&game, game.beatmap.difficulty.approach_time); + struct oshu::hit *next = NULL; double now = game.clock.now; - for (struct oshu_hit *hit = cursor; hit; hit = hit->previous) { - if (!(hit->type & (OSHU_CIRCLE_HIT | OSHU_SLIDER_HIT))) + for (struct oshu::hit *hit = cursor; hit; hit = hit->previous) { + if (!(hit->type & (oshu::CIRCLE_HIT | oshu::SLIDER_HIT))) continue; - if (oshu_hit_end_time(hit) < now - game.beatmap.difficulty.approach_time) + if (oshu::hit_end_time(hit) < now - game.beatmap.difficulty.approach_time) break; if (next && next->combo == hit->combo) connect_hits(*this, hit, next); draw_hit(*this, hit); next = hit; } - oshu_show_cursor(&this->cursor); - oshu_reset_view(display); + oshu::show_cursor(&this->cursor); + oshu::reset_view(display); } -osu_mouse::osu_mouse(oshu_display *display) +osu_mouse::osu_mouse(oshu::display *display) : display(display) { } -oshu_point osu_mouse::position() +oshu::point osu_mouse::position() { - osu_view(display); - oshu_point mouse = oshu_get_mouse(display); - oshu_reset_view(display); + oshu::osu_view(display); + oshu::point mouse = oshu::get_mouse(display); + oshu::reset_view(display); return mouse; } } -void osu_view(struct oshu_display *display) +void oshu::osu_view(struct oshu::display *display) { - oshu_fit_view(&display->view, oshu_size{640, 480}); - oshu_resize_view(&display->view, oshu_size{512, 384}); + oshu::fit_view(&display->view, oshu::size{640, 480}); + oshu::resize_view(&display->view, oshu::size{512, 384}); } diff --git a/lib/ui/osu_paint.cc b/lib/ui/osu_paint.cc index 57726ee..b8cf305 100644 --- a/lib/ui/osu_paint.cc +++ b/lib/ui/osu_paint.cc @@ -22,10 +22,10 @@ static int paint_approach_circle(oshu::osu_ui &view) { oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.circle_radius + game->beatmap.difficulty.approach_size; - oshu_size size = oshu_size(radius * 2., radius * 2.); + oshu::size size = oshu::size(radius * 2., radius * 2.); - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, radius, radius); cairo_arc(p.cr, 0, 0, radius - 3, 0, 2. * M_PI); @@ -33,20 +33,20 @@ static int paint_approach_circle(oshu::osu_ui &view) cairo_set_line_width(p.cr, 4); cairo_stroke(p.cr); - struct oshu_texture *texture = &view.approach_circle; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = &view.approach_circle; + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } -static int paint_circle(oshu::osu_ui &view, struct oshu_color *color, struct oshu_texture *texture) +static int paint_circle(oshu::osu_ui &view, struct oshu::color *color, struct oshu::texture *texture) { oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.circle_radius; - oshu_size size = oshu_size(radius * 2., radius * 2.); + oshu::size size = oshu::size(radius * 2., radius * 2.); - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, radius, radius); cairo_set_operator(p.cr, CAIRO_OPERATOR_SOURCE); double opacity = 0.7; @@ -71,28 +71,28 @@ static int paint_circle(oshu::osu_ui &view, struct oshu_color *color, struct osh cairo_set_line_width(p.cr, 3); cairo_stroke(p.cr); - int rc = oshu_finish_painting(&p, texture); + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } -static void build_path(cairo_t *cr, struct oshu_slider *slider) +static void build_path(cairo_t *cr, struct oshu::slider *slider) { - if (slider->path.type == OSHU_LINEAR_PATH) { + if (slider->path.type == oshu::LINEAR_PATH) { cairo_move_to(cr, std::real(slider->path.line.start), std::imag(slider->path.line.start)); cairo_line_to(cr, std::real(slider->path.line.end), std::imag(slider->path.line.end)); - } else if (slider->path.type == OSHU_PERFECT_PATH) { - struct oshu_arc *arc = &slider->path.arc; + } else if (slider->path.type == oshu::PERFECT_PATH) { + struct oshu::arc *arc = &slider->path.arc; if (arc->start_angle < arc->end_angle) cairo_arc(cr, std::real(arc->center), std::imag(arc->center), arc->radius, arc->start_angle, arc->end_angle); else cairo_arc_negative(cr, std::real(arc->center), std::imag(arc->center), arc->radius, arc->start_angle, arc->end_angle); } else { - oshu_point start = oshu_path_at(&slider->path, 0); + oshu::point start = oshu::path_at(&slider->path, 0); cairo_move_to(cr, std::real(start), std::imag(start)); int resolution = slider->length / 5. + 5; for (int i = 1; i <= resolution; ++i) { - oshu_point pt = oshu_path_at(&slider->path, (double) i / resolution); + oshu::point pt = oshu::path_at(&slider->path, (double) i / resolution); cairo_line_to(cr, std::real(pt), std::imag(pt)); } } @@ -108,18 +108,18 @@ static void build_path(cairo_t *cr, struct oshu_slider *slider) * Paint the slider ticks. Preferably updating the ticks every time the slider * repeats. Also, clear the ticks as the slider rolls over them. */ -int osu_paint_slider(oshu::osu_ui &view, struct oshu_hit *hit) +int oshu::osu_paint_slider(oshu::osu_ui &view, struct oshu::hit *hit) { oshu::game_base *game = &view.game; int start = SDL_GetTicks(); - assert (hit->type & OSHU_SLIDER_HIT); + assert (hit->type & oshu::SLIDER_HIT); double radius = game->beatmap.difficulty.circle_radius; - oshu_point top_left, bottom_right; - oshu_path_bounding_box(&hit->slider.path, &top_left, &bottom_right); - oshu_size size = bottom_right - top_left + oshu_vector{2, 2} * radius; + oshu::point top_left, bottom_right; + oshu::path_bounding_box(&hit->slider.path, &top_left, &bottom_right); + oshu::size size = bottom_right - top_left + oshu::vector{2, 2} * radius; - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, - std::real(top_left) + radius, - std::imag(top_left) + radius); cairo_set_operator(p.cr, CAIRO_OPERATOR_SOURCE); @@ -151,7 +151,7 @@ int osu_paint_slider(oshu::osu_ui &view, struct oshu_hit *hit) cairo_stroke(p.cr); /* End point. */ - oshu_point end = oshu_path_at(&hit->slider.path, 1.); + oshu::point end = oshu::path_at(&hit->slider.path, 1.); cairo_set_source_rgba(p.cr, 0., 0., 0., opacity); cairo_set_line_width(p.cr, 1); for (int i = 1; i <= hit->slider.repeat; ++i) { @@ -171,15 +171,15 @@ int osu_paint_slider(oshu::osu_ui &view, struct oshu_hit *hit) cairo_pattern_destroy(pattern); - hit->texture = (oshu_texture*) calloc(1, sizeof(*hit->texture)); + hit->texture = (oshu::texture*) calloc(1, sizeof(*hit->texture)); assert (hit->texture != NULL); - if (oshu_finish_painting(&p, hit->texture) < 0) { + if (oshu::finish_painting(&p, hit->texture) < 0) { free(hit->texture); hit->texture = NULL; return -1; } - hit->texture->origin = hit->p - top_left + oshu_vector{1, 1} * radius; + hit->texture->origin = hit->p - top_left + oshu::vector{1, 1} * radius; oshu_log_verbose("slider drawn in %.3f seconds", (SDL_GetTicks() - start) / 1000.); return 0; } @@ -192,10 +192,10 @@ int osu_paint_slider(oshu::osu_ui &view, struct oshu_hit *hit) static int paint_slider_ball(oshu::osu_ui &view) { oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.slider_tolerance; - oshu_size size = oshu_size{1, 1} * radius * 2.; + oshu::size size = oshu::size{1, 1} * radius * 2.; - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, radius, radius); /* tolerance */ @@ -219,20 +219,20 @@ static int paint_slider_ball(oshu::osu_ui &view) { cairo_fill(p.cr); cairo_pattern_destroy(pattern); - struct oshu_texture *texture = &view.slider_ball; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = &view.slider_ball; + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } -static int paint_good_mark(oshu::osu_ui &view, int offset, struct oshu_texture *texture) +static int paint_good_mark(oshu::osu_ui &view, int offset, struct oshu::texture *texture) { oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.circle_radius / 3.5; - oshu_size size = oshu_size{1, 1} * radius * 2.; + oshu::size size = oshu::size{1, 1} * radius * 2.; - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, radius, radius); if (offset == 0) { @@ -251,7 +251,7 @@ static int paint_good_mark(oshu::osu_ui &view, int offset, struct oshu_texture * cairo_set_line_width(p.cr, 2); cairo_stroke(p.cr); - int rc = oshu_finish_painting(&p, texture); + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } @@ -260,10 +260,10 @@ static int paint_bad_mark(oshu::osu_ui &view) { oshu::game_base *game = &view.game; double half = game->beatmap.difficulty.circle_radius / 4.7; - oshu_size size = oshu_size{1, 1} * (half + 2) * 2.; + oshu::size size = oshu::size{1, 1} * (half + 2) * 2.; - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, half + 2, half + 2); cairo_set_source_rgba(p.cr, .9, 0, 0, .4); @@ -277,8 +277,8 @@ static int paint_bad_mark(oshu::osu_ui &view) cairo_stroke(p.cr); - struct oshu_texture *texture = &view.bad_mark; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = &view.bad_mark; + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } @@ -287,10 +287,10 @@ static int paint_skip_mark(oshu::osu_ui &view) { oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.circle_radius / 4.7; - oshu_size size = oshu_size{1, 1} * (radius + 2) * 2.; + oshu::size size = oshu::size{1, 1} * (radius + 2) * 2.; - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, radius + 2, radius + 2); cairo_set_source_rgba(p.cr, .3, .3, 1, .6); @@ -306,8 +306,8 @@ static int paint_skip_mark(oshu::osu_ui &view) cairo_stroke(p.cr); - struct oshu_texture *texture = &view.skip_mark; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = &view.skip_mark; + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } @@ -316,18 +316,18 @@ static int paint_connector(oshu::osu_ui &view) { oshu::game_base *game = &view.game; double radius = 3; - oshu_size size = oshu_size{1, 1} * radius * 2.; + oshu::size size = oshu::size{1, 1} * radius * 2.; - struct oshu_painter p; - oshu_start_painting(view.display, size, &p); + struct oshu::painter p; + oshu::start_painting(view.display, size, &p); cairo_translate(p.cr, radius, radius); cairo_set_source_rgba(p.cr, 1, 1, 1, .5); cairo_arc(p.cr, 0, 0, radius - 1, 0, 2. * M_PI); cairo_fill(p.cr); - struct oshu_texture *texture = &view.connector; - int rc = oshu_finish_painting(&p, texture); + struct oshu::texture *texture = &view.connector; + int rc = oshu::finish_painting(&p, texture); texture->origin = size / 2.; return rc; } @@ -336,7 +336,7 @@ static int paint_connector(oshu::osu_ui &view) * \todo * Handle errors. */ -int osu_paint_resources(oshu::osu_ui &view) +int oshu::osu_paint_resources(oshu::osu_ui &view) { oshu::game_base *game = &view.game; int start = SDL_GetTicks(); @@ -345,9 +345,9 @@ int osu_paint_resources(oshu::osu_ui &view) /* Circle hits. */ assert (game->beatmap.color_count > 0); assert (game->beatmap.colors != NULL); - view.circles = (oshu_texture*) calloc(game->beatmap.color_count, sizeof(*view.circles)); + view.circles = (oshu::texture*) calloc(game->beatmap.color_count, sizeof(*view.circles)); assert (view.circles != NULL); - struct oshu_color *color = game->beatmap.colors; + struct oshu::color *color = game->beatmap.colors; for (int i = 0; i < game->beatmap.color_count; ++i) { oshu_log_verbose("painting circle for combo color #%d", i); assert (color->index == i); @@ -369,27 +369,27 @@ int osu_paint_resources(oshu::osu_ui &view) return 0; } -void osu_free_resources(oshu::osu_ui &view) +void oshu::osu_free_resources(oshu::osu_ui &view) { oshu::game_base *game = &view.game; if (view.circles) { for (int i = 0; i < game->beatmap.color_count; ++i) - oshu_destroy_texture(&view.circles[i]); + oshu::destroy_texture(&view.circles[i]); free(view.circles); } - for (struct oshu_hit *hit = game->beatmap.hits; hit; hit = hit->next) { + for (struct oshu::hit *hit = game->beatmap.hits; hit; hit = hit->next) { if (hit->texture) { - oshu_destroy_texture(hit->texture); + oshu::destroy_texture(hit->texture); free(hit->texture); hit->texture = NULL; } } - oshu_destroy_texture(&view.approach_circle); - oshu_destroy_texture(&view.slider_ball); - oshu_destroy_texture(&view.good_mark); - oshu_destroy_texture(&view.early_mark); - oshu_destroy_texture(&view.late_mark); - oshu_destroy_texture(&view.bad_mark); - oshu_destroy_texture(&view.skip_mark); - oshu_destroy_texture(&view.connector); + oshu::destroy_texture(&view.approach_circle); + oshu::destroy_texture(&view.slider_ball); + oshu::destroy_texture(&view.good_mark); + oshu::destroy_texture(&view.early_mark); + oshu::destroy_texture(&view.late_mark); + oshu::destroy_texture(&view.bad_mark); + oshu::destroy_texture(&view.skip_mark); + oshu::destroy_texture(&view.connector); } diff --git a/lib/ui/score.cc b/lib/ui/score.cc index 76e6ee9..05844f5 100644 --- a/lib/ui/score.cc +++ b/lib/ui/score.cc @@ -12,23 +12,23 @@ #include -int oshu_create_score_frame(struct oshu_display *display, struct oshu_beatmap *beatmap, struct oshu_score_frame *frame) +int oshu::create_score_frame(struct oshu::display *display, struct oshu::beatmap *beatmap, struct oshu::score_frame *frame) { memset(frame, 0, sizeof(*frame)); frame->display = display; frame->beatmap = beatmap; - for (struct oshu_hit *hit = beatmap->hits; hit; hit = hit->next) { - if (hit->state == OSHU_MISSED_HIT) + for (struct oshu::hit *hit = beatmap->hits; hit; hit = hit->next) { + if (hit->state == oshu::MISSED_HIT) ++frame->bad; - else if (hit->state == OSHU_GOOD_HIT) + else if (hit->state == oshu::GOOD_HIT) ++frame->good; } return 0; } -void oshu_show_score_frame(struct oshu_score_frame *frame, double opacity) +void oshu::show_score_frame(struct oshu::score_frame *frame, double opacity) { int notes = frame->good + frame->bad; if (notes == 0) @@ -62,6 +62,6 @@ void oshu_show_score_frame(struct oshu_score_frame *frame, double opacity) SDL_RenderFillRect(frame->display->renderer, &bad); } -void oshu_destroy_score_frame(struct oshu_score_frame *frame) +void oshu::destroy_score_frame(struct oshu::score_frame *frame) { } diff --git a/lib/ui/screens/pause.cc b/lib/ui/screens/pause.cc index c7b7d40..46ed167 100644 --- a/lib/ui/screens/pause.cc +++ b/lib/ui/screens/pause.cc @@ -22,19 +22,19 @@ static int on_event(oshu::shell &w, union SDL_Event *event) if (event->key.repeat) break; switch (event->key.keysym.sym) { - case OSHU_QUIT_KEY: + case oshu::QUIT_KEY: w.close(); break; - case OSHU_PAUSE_KEY: + case oshu::PAUSE_KEY: if (game->clock.now > 0 && !game->autoplay) game->rewind(1.); game->unpause(); - w.screen = &oshu_play_screen; + w.screen = &oshu::play_screen; break; - case OSHU_REWIND_KEY: + case oshu::REWIND_KEY: game->rewind(10.); break; - case OSHU_FORWARD_KEY: + case oshu::FORWARD_KEY: game->forward(20.); break; } @@ -54,15 +54,15 @@ static int update(oshu::shell &w) { oshu::game_base *game = &w.game; if (!game->paused) - w.screen = &oshu_play_screen; + w.screen = &oshu::play_screen; return 0; } -static void draw_pause(struct oshu_display *display) +static void draw_pause(struct oshu::display *display) { const double size = 100; const double thickness = 40; - const oshu_size screen = display->view.size; + const oshu::size screen = display->view.size; SDL_SetRenderDrawColor(display->renderer, 255, 255, 255, 128); SDL_SetRenderDrawBlendMode(display->renderer, SDL_BLENDMODE_BLEND); SDL_Rect bar = { @@ -80,13 +80,15 @@ static int draw(oshu::shell &w) { oshu::game_base *game = &w.game; SDL_ShowCursor(SDL_ENABLE); - oshu_show_background(&w.background, 0); - oshu_show_metadata_frame(&w.metadata, 1); - oshu_show_audio_progress_bar(&w.audio_progress_bar); + oshu::show_background(&w.background, 0); + oshu::show_metadata_frame(&w.metadata, 1); + oshu::show_audio_progress_bar(&w.audio_progress_bar); draw_pause(&w.display); return 0; } +namespace oshu { + /** * Pause screen: the music stops. * @@ -100,9 +102,11 @@ static int draw(oshu::shell &w) * to re-focus. * */ -struct oshu_game_screen oshu_pause_screen = { +struct oshu::game_screen pause_screen = { .name = "Paused", .on_event = on_event, .update = update, .draw = draw, }; + +} diff --git a/lib/ui/screens/play.cc b/lib/ui/screens/play.cc index 367617d..197d578 100644 --- a/lib/ui/screens/play.cc +++ b/lib/ui/screens/play.cc @@ -25,38 +25,38 @@ static int on_event(oshu::shell &w, union SDL_Event *event) if (event->key.repeat) break; switch (event->key.keysym.sym) { - case OSHU_PAUSE_KEY: + case oshu::PAUSE_KEY: game->pause(); - w.screen = &oshu_pause_screen; + w.screen = &oshu::pause_screen; break; - case OSHU_REWIND_KEY: + case oshu::REWIND_KEY: game->rewind(10.); break; - case OSHU_FORWARD_KEY: + case oshu::FORWARD_KEY: game->forward(20.); break; default: if (!game->autoplay) { - enum oshu_finger key = oshu_translate_key(&event->key.keysym); - if (key != OSHU_UNKNOWN_KEY) + enum oshu::finger key = oshu::translate_key(&event->key.keysym); + if (key != oshu::UNKNOWN_KEY) game->press(key); } } break; case SDL_KEYUP: if (!game->autoplay) { - enum oshu_finger key = oshu_translate_key(&event->key.keysym); - if (key != OSHU_UNKNOWN_KEY) + enum oshu::finger key = oshu::translate_key(&event->key.keysym); + if (key != oshu::UNKNOWN_KEY) game->release(key); } break; case SDL_MOUSEBUTTONDOWN: if (!game->autoplay) - game->press(OSHU_LEFT_BUTTON); + game->press(oshu::LEFT_BUTTON); break; case SDL_MOUSEBUTTONUP: if (!game->autoplay) - game->release(OSHU_LEFT_BUTTON); + game->release(oshu::LEFT_BUTTON); break; case SDL_WINDOWEVENT: switch (event->window.event) { @@ -64,7 +64,7 @@ static int on_event(oshu::shell &w, union SDL_Event *event) case SDL_WINDOWEVENT_FOCUS_LOST: if (!game->autoplay && game->hit_cursor->next) { game->pause(); - w.screen = &oshu_pause_screen; + w.screen = &oshu::pause_screen; } break; case SDL_WINDOWEVENT_CLOSE: @@ -89,11 +89,11 @@ static void check_end(oshu::shell &w) if (game->hit_cursor->next) return; const double delay = game->beatmap.difficulty.leniency + game->beatmap.difficulty.approach_time; - if (game->clock.now > oshu_hit_end_time(game->hit_cursor->previous) + delay) { - oshu_reset_view(&w.display); - oshu_create_score_frame(&w.display, &game->beatmap, &w.score); - oshu_congratulate(game); - w.screen = &oshu_score_screen; + if (game->clock.now > oshu::hit_end_time(game->hit_cursor->previous) + delay) { + oshu::reset_view(&w.display); + oshu::create_score_frame(&w.display, &game->beatmap, &w.score); + oshu::congratulate(game); + w.screen = &oshu::score_screen; } } @@ -101,11 +101,11 @@ static int update(oshu::shell &w) { oshu::game_base *game = &w.game; if (game->paused) { - w.screen = &oshu_pause_screen; + w.screen = &oshu::pause_screen; return 0; } if (game->clock.now >= 0) - oshu_play_audio(&game->audio); + oshu::play_audio(&game->audio); if (game->autoplay) game->check_autoplay(); else @@ -143,28 +143,30 @@ static int update(oshu::shell &w) static void draw_background(oshu::shell &w) { oshu::game_base *game = &w.game; - double break_start = oshu_hit_end_time(oshu_previous_hit(game)); - double break_end = oshu_next_hit(game)->time; + double break_start = oshu::hit_end_time(oshu::previous_hit(game)); + double break_end = oshu::next_hit(game)->time; double now = game->clock.now; double ratio = 0.; if (break_end - break_start > 6.) - ratio = oshu_trapezium(break_start + 1, break_end - 1, 1, now); - oshu_show_background(&w.background, ratio); + ratio = oshu::trapezium(break_start + 1, break_end - 1, 1, now); + oshu::show_background(&w.background, ratio); } static int draw(oshu::shell &w) { oshu::game_base *game = &w.game; - if (w.display.features & OSHU_FANCY_CURSOR) + if (w.display.features & oshu::FANCY_CURSOR) SDL_ShowCursor(SDL_DISABLE); draw_background(w); - oshu_show_metadata_frame(&w.metadata, oshu_fade_out(5, 6, game->clock.system)); - oshu_show_audio_progress_bar(&w.audio_progress_bar); + oshu::show_metadata_frame(&w.metadata, oshu::fade_out(5, 6, game->clock.system)); + oshu::show_audio_progress_bar(&w.audio_progress_bar); if (w.game_view) w.game_view->draw(); return 0; } +namespace oshu { + /** * The standard in-play game screen. * @@ -174,9 +176,11 @@ static int draw(oshu::shell &w) * This screen relies heavily on the game mode. * */ -struct oshu_game_screen oshu_play_screen = { +struct oshu::game_screen play_screen = { .name = "Playing", .on_event = on_event, .update = update, .draw = draw, }; + +} diff --git a/lib/ui/screens/score.cc b/lib/ui/screens/score.cc index 2a2f622..fa96785 100644 --- a/lib/ui/screens/score.cc +++ b/lib/ui/screens/score.cc @@ -22,7 +22,7 @@ static int on_event(oshu::shell &w, union SDL_Event *event) if (event->key.repeat) break; switch (event->key.keysym.sym) { - case OSHU_QUIT_KEY: + case oshu::QUIT_KEY: w.close(); break; } @@ -47,24 +47,28 @@ static int draw(oshu::shell &w) { oshu::game_base *game = &w.game; SDL_ShowCursor(SDL_ENABLE); - double end = oshu_hit_end_time(oshu_previous_hit(game)); - double r = oshu_fade_in(end + 1, end + 2, game->clock.now); - oshu_show_background(&w.background, r); - oshu_show_audio_progress_bar(&w.audio_progress_bar); - oshu_show_metadata_frame(&w.metadata, r); - oshu_show_score_frame(&w.score, r); + double end = oshu::hit_end_time(oshu::previous_hit(game)); + double r = oshu::fade_in(end + 1, end + 2, game->clock.now); + oshu::show_background(&w.background, r); + oshu::show_audio_progress_bar(&w.audio_progress_bar); + oshu::show_metadata_frame(&w.metadata, r); + oshu::show_score_frame(&w.score, r); return 0; } +namespace oshu { + /** * Game complete screen. * * Once this screen is reached, the only command left is *exit*. * */ -struct oshu_game_screen oshu_score_screen = { +struct oshu::game_screen score_screen = { .name = "Finished", .on_event = on_event, .update = update, .draw = draw, }; + +} diff --git a/lib/ui/screens/screens.h b/lib/ui/screens/screens.h index 1eefa14..667c14b 100644 --- a/lib/ui/screens/screens.h +++ b/lib/ui/screens/screens.h @@ -8,8 +8,8 @@ union SDL_Event; namespace oshu { + struct shell; -} /** * \defgroup ui_screens Screens @@ -56,7 +56,7 @@ struct shell; /** * Define a game screen by its behavior. */ -struct oshu_game_screen { +struct game_screen { /** * \todo * Drop it if it's not used. @@ -85,12 +85,14 @@ struct oshu_game_screen { }; /* Defined in play.c */ -extern struct oshu_game_screen oshu_play_screen; +extern struct oshu::game_screen play_screen; /* Defined in pause.c */ -extern struct oshu_game_screen oshu_pause_screen; +extern struct oshu::game_screen pause_screen; /* Defined in score.c */ -extern struct oshu_game_screen oshu_score_screen; +extern struct oshu::game_screen score_screen; /** \} */ + +} diff --git a/lib/ui/shell.cc b/lib/ui/shell.cc index 518b2ee..dfbaf12 100644 --- a/lib/ui/shell.cc +++ b/lib/ui/shell.cc @@ -15,32 +15,32 @@ static void set_title(oshu::shell &w) { - struct oshu_metadata *meta = &w.game.beatmap.metadata; + struct oshu::metadata *meta = &w.game.beatmap.metadata; std::ostringstream title; title << meta->artist << " - " << meta->title << " ♯ " << meta->version << " 𝄞 oshu!"; SDL_SetWindowTitle(w.display.window, title.str().c_str()); - oshu_reset_view(&w.display); + oshu::reset_view(&w.display); } namespace oshu { -shell::shell(oshu_display &display, oshu::game_base &game) -: display(display), game(game), screen(&oshu_play_screen) +shell::shell(oshu::display &display, oshu::game_base &game) +: display(display), game(game), screen(&oshu::play_screen) { set_title(*this); if (game.beatmap.background_filename) - oshu_load_background(&display, game.beatmap.background_filename, &background); - oshu_create_metadata_frame(&display, &game.beatmap, &game.clock.system, &metadata); - oshu_create_audio_progress_bar(&display, &game.audio.music, &audio_progress_bar); + oshu::load_background(&display, game.beatmap.background_filename, &background); + oshu::create_metadata_frame(&display, &game.beatmap, &game.clock.system, &metadata); + oshu::create_audio_progress_bar(&display, &game.audio.music, &audio_progress_bar); } shell::~shell() { game_view.release(); - oshu_destroy_background(&background); - oshu_destroy_metadata_frame(&metadata); - oshu_destroy_score_frame(&score); - oshu_destroy_audio_progress_bar(&audio_progress_bar); + oshu::destroy_background(&background); + oshu::destroy_metadata_frame(&metadata); + oshu::destroy_score_frame(&score); + oshu::destroy_audio_progress_bar(&audio_progress_bar); } static void draw(shell &w) @@ -54,24 +54,24 @@ static void draw(shell &w) void shell::open() { - oshu_welcome(&game); - oshu_initialize_clock(&game); + oshu::welcome(&game); + oshu::initialize_clock(&game); SDL_Event event; int missed_frames = 0; while (!stop) { - oshu_update_clock(&game); - oshu_reset_view(&display); + oshu::update_clock(&game); + oshu::reset_view(&display); while (SDL_PollEvent(&event)) screen->on_event(*this, &event); screen->update(*this); draw(*this); - /* Calling oshu_print_state before draw causes some flickering + /* Calling oshu::print_state before draw causes some flickering * on the tty, for some reason. */ - if (screen == &oshu_play_screen) - oshu_print_state(&game); + if (screen == &oshu::play_screen) + oshu::print_state(&game); double advance = display.frame_duration - (SDL_GetTicks() / 1000. - game.clock.system); if (advance > 0) { @@ -86,7 +86,7 @@ void shell::open() } } - if (screen != &oshu_score_screen) + if (screen != &oshu::score_screen) puts(""); /* write a new line to avoid conflict between the status line * and the shell prompt */ diff --git a/lib/video/display.cc b/lib/video/display.cc index 8aea2c8..966da99 100644 --- a/lib/video/display.cc +++ b/lib/video/display.cc @@ -20,7 +20,7 @@ * to have a wider window. It's just that the extra width will be nothing but * margin. It may fit the background better though. */ -static oshu_size get_default_window_size() +static oshu::size get_default_window_size() { int width, height; char *value = getenv("OSHU_WINDOW_SIZE"); @@ -44,12 +44,12 @@ static oshu_size get_default_window_size() oshu_log_warning("it's unlikely you have a screen bigger than 4K"); goto invalid; } else { - return oshu_size(width, height); + return oshu::size(width, height); } invalid: oshu_log_warning("rejected OSHU_WINDOW_SIZE value %s, defaulting to 960x720", value); def: - return oshu_size{960, 720}; + return oshu::size{960, 720}; } /** @@ -60,17 +60,17 @@ int get_features() { char *value = getenv("OSHU_QUALITY"); if (!value || !*value) { /* null or empty */ - return OSHU_DEFAULT_QUALITY; + return oshu::DEFAULT_QUALITY; } else if (!strcmp(value, "high")) { - return OSHU_HIGH_QUALITY; + return oshu::HIGH_QUALITY; } else if (!strcmp(value, "medium")) { - return OSHU_MEDIUM_QUALITY; + return oshu::MEDIUM_QUALITY; } else if (!strcmp(value, "low")) { - return OSHU_LOW_QUALITY; + return oshu::LOW_QUALITY; } else { oshu_log_warning("invalid OSHU_QUALITY value: %s", value); oshu_log_warning("supported quality levels are: low, medium, high"); - return OSHU_DEFAULT_QUALITY; + return oshu::DEFAULT_QUALITY; } } @@ -80,14 +80,14 @@ int get_features() * The default window size, 960x720 is arbitrary but proportional the the game * area. It's just a saner default for most screens. */ -int create_window(struct oshu_display *display) +int create_window(struct oshu::display *display) { memset(display, 0, sizeof(*display)); display->features = get_features(); - oshu_size window_size = get_default_window_size(); - if (display->features & OSHU_LINEAR_SCALING) + oshu::size window_size = get_default_window_size(); + if (display->features & oshu::LINEAR_SCALING) SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); - display->frame_duration = 1. / ((display->features|OSHU_60FPS) ? 60. : 30.); + display->frame_duration = 1. / ((display->features|oshu::SIXTY_FPS) ? 60. : 30.); display->window = SDL_CreateWindow( "oshu!", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, @@ -98,7 +98,7 @@ int create_window(struct oshu_display *display) goto fail; display->renderer = SDL_CreateRenderer( display->window, -1, - (display->features & OSHU_HARDWARE_ACCELERATION) ? 0 : SDL_RENDERER_SOFTWARE + (display->features & oshu::HARDWARE_ACCELERATION) ? 0 : SDL_RENDERER_SOFTWARE ); if (display->renderer == NULL) goto fail; @@ -108,7 +108,7 @@ int create_window(struct oshu_display *display) return -1; } -static void close_display(oshu_display *display) +static void close_display(oshu::display *display) { if (display->renderer) { SDL_DestroyRenderer(display->renderer); @@ -124,23 +124,23 @@ static void close_display(oshu_display *display) * The default window size is read from the OSHU_WINDOW_SIZE environment * variable. More details at #get_default_window_size. */ -oshu_display::oshu_display() +oshu::display::display() { if (create_window(this) < 0) { close_display(this); throw std::runtime_error("could not open display"); } - oshu_reset_view(this); + oshu::reset_view(this); } -oshu_display::~oshu_display() +oshu::display::~display() { close_display(this); } -oshu_point oshu_get_mouse(struct oshu_display *display) +oshu::point oshu::get_mouse(struct oshu::display *display) { int x, y; SDL_GetMouseState(&x, &y); - return oshu_unproject(&display->view, oshu_point(x, y)); + return oshu::unproject(&display->view, oshu::point(x, y)); } diff --git a/lib/video/paint.cc b/lib/video/paint.cc index ab93a86..ce034fa 100644 --- a/lib/video/paint.cc +++ b/lib/video/paint.cc @@ -12,7 +12,7 @@ #include #include -static void destroy_painter(struct oshu_painter *painter) +static void destroy_painter(struct oshu::painter *painter) { if (painter->cr) { cairo_destroy(painter->cr); @@ -28,7 +28,7 @@ static void destroy_painter(struct oshu_painter *painter) } } -int oshu_start_painting(struct oshu_display *display, oshu_size size, struct oshu_painter *painter) +int oshu::start_painting(struct oshu::display *display, oshu::size size, struct oshu::painter *painter) { cairo_status_t s; memset(painter, 0, sizeof(*painter)); @@ -101,7 +101,7 @@ static void unpremultiply(SDL_Surface *surface) } } -int oshu_finish_painting(struct oshu_painter *painter, struct oshu_texture *texture) +int oshu::finish_painting(struct oshu::painter *painter, struct oshu::texture *texture) { int rc = 0; unpremultiply(painter->destination); diff --git a/lib/video/texture.cc b/lib/video/texture.cc index cf17d02..5738651 100644 --- a/lib/video/texture.cc +++ b/lib/video/texture.cc @@ -10,7 +10,7 @@ #include -int oshu_load_texture(struct oshu_display *display, const char *filename, struct oshu_texture *texture) +int oshu::load_texture(struct oshu::display *display, const char *filename, struct oshu::texture *texture) { texture->texture = IMG_LoadTexture(display->renderer, filename); if (!texture->texture) { @@ -20,11 +20,11 @@ int oshu_load_texture(struct oshu_display *display, const char *filename, struct texture->origin = 0; int tw, th; SDL_QueryTexture(texture->texture, NULL, NULL, &tw, &th); - texture->size = oshu_size(tw, th); + texture->size = oshu::size(tw, th); return 0; } -void oshu_destroy_texture(struct oshu_texture *texture) +void oshu::destroy_texture(struct oshu::texture *texture) { if (texture->texture) { SDL_DestroyTexture(texture->texture); @@ -32,10 +32,10 @@ void oshu_destroy_texture(struct oshu_texture *texture) } } -void oshu_draw_scaled_texture(struct oshu_display *display, struct oshu_texture *texture, oshu_point p, double ratio) +void oshu::draw_scaled_texture(struct oshu::display *display, struct oshu::texture *texture, oshu::point p, double ratio) { - oshu_point top_left = oshu_project(&display->view, p - texture->origin * ratio); - oshu_size size = texture->size * ratio * display->view.zoom; + oshu::point top_left = oshu::project(&display->view, p - texture->origin * ratio); + oshu::size size = texture->size * ratio * display->view.zoom; SDL_Rect dest = { .x = (int) std::real(top_left), .y = (int) std::imag(top_left), .w = (int) std::real(size), .h = (int) std::imag(size), @@ -43,7 +43,7 @@ void oshu_draw_scaled_texture(struct oshu_display *display, struct oshu_texture SDL_RenderCopy(display->renderer, texture->texture, NULL, &dest); } -void oshu_draw_texture(struct oshu_display *display, struct oshu_texture *texture, oshu_point p) +void oshu::draw_texture(struct oshu::display *display, struct oshu::texture *texture, oshu::point p) { - oshu_draw_scaled_texture(display, texture, p, 1.); + oshu::draw_scaled_texture(display, texture, p, 1.); } diff --git a/lib/video/transitions.cc b/lib/video/transitions.cc index 13f26a6..30bf18f 100644 --- a/lib/video/transitions.cc +++ b/lib/video/transitions.cc @@ -7,7 +7,7 @@ #include -double oshu_fade_out(double start, double end, double t) +double oshu::fade_out(double start, double end, double t) { assert (end > start); if (t < start) @@ -18,7 +18,7 @@ double oshu_fade_out(double start, double end, double t) return 0; } -double oshu_fade_in(double start, double end, double t) +double oshu::fade_in(double start, double end, double t) { assert (end > start); if (t < start) @@ -29,7 +29,7 @@ double oshu_fade_in(double start, double end, double t) return 1; } -double oshu_trapezium(double start, double end, double transition, double t) +double oshu::trapezium(double start, double end, double transition, double t) { double ratio = 0.; if (t <= start) diff --git a/lib/video/view.cc b/lib/video/view.cc index 150286b..597cb17 100644 --- a/lib/video/view.cc +++ b/lib/video/view.cc @@ -9,47 +9,47 @@ #include -void oshu_scale_view(struct oshu_view *view, double factor) +void oshu::scale_view(struct oshu::view *view, double factor) { view->zoom *= factor; view->size /= factor; } -void oshu_resize_view(struct oshu_view *view, oshu_size size) +void oshu::resize_view(struct oshu::view *view, oshu::size size) { view->origin += view->zoom * (view->size - size) / 2.; view->size = size; } -void oshu_fit_view(struct oshu_view *view, oshu_size size) +void oshu::fit_view(struct oshu::view *view, oshu::size size) { - double wanted_ratio = oshu_ratio(size); - double current_ratio = oshu_ratio(view->size); + double wanted_ratio = oshu::ratio(size); + double current_ratio = oshu::ratio(view->size); if (current_ratio > wanted_ratio) { /* the window is too wide */ - oshu_scale_view(view, std::imag(view->size) / std::imag(size)); + oshu::scale_view(view, std::imag(view->size) / std::imag(size)); } else { /* the window is too high */ - oshu_scale_view(view, std::real(view->size) / std::real(size)); + oshu::scale_view(view, std::real(view->size) / std::real(size)); } - oshu_resize_view(view, size); + oshu::resize_view(view, size); } -oshu_point oshu_project(struct oshu_view *view, oshu_point p) +oshu::point oshu::project(struct oshu::view *view, oshu::point p) { return p * view->zoom + view->origin; } -oshu_point oshu_unproject(struct oshu_view *view, oshu_point p) +oshu::point oshu::unproject(struct oshu::view *view, oshu::point p) { return (p - view->origin) / view->zoom; } -void oshu_reset_view(struct oshu_display *display) +void oshu::reset_view(struct oshu::display *display) { int w, h; SDL_GetWindowSize(display->window, &w, &h); display->view.zoom = 1.; display->view.origin = 0; - display->view.size = oshu_size(w, h); + display->view.size = oshu::size(w, h); } diff --git a/src/oshu/main.cc b/src/oshu/main.cc index 660e064..6f3aa25 100644 --- a/src/oshu/main.cc +++ b/src/oshu/main.cc @@ -89,12 +89,12 @@ int run(const char *beatmap_path, int autoplay, int pause) } try { - osu_game game(beatmap_path); + oshu::osu_game game(beatmap_path); game.autoplay = autoplay; if (pause) game.pause(); - oshu_display display; + oshu::display display; std::shared_ptr shell = std::make_shared(display, game); shell->game_view = std::make_unique(&display, game); current_shell = shell; diff --git a/test/zerotokei.cc b/test/zerotokei.cc index 6219dc1..5dd846c 100644 --- a/test/zerotokei.cc +++ b/test/zerotokei.cc @@ -8,8 +8,8 @@ int main() { int failures = 0; int rc; - oshu_beatmap b; - rc = oshu_load_beatmap("Kaori Oda - Zero Tokei (Short ver.) (ShogunMoon) [Shining].osu", &b); + oshu::beatmap b; + rc = oshu::load_beatmap("Kaori Oda - Zero Tokei (Short ver.) (ShogunMoon) [Shining].osu", &b); if (rc < 0) { ++failures; goto abort; @@ -21,6 +21,6 @@ int main() if (failures > 0) std::cerr << "Total: " << failures << " failed tests." << std::endl; abort: - oshu_destroy_beatmap(&b); + oshu::destroy_beatmap(&b); return failures; }