diff --git a/include/audio/library.h b/include/audio/library.h index 70f1e78..1c4179b 100644 --- a/include/audio/library.h +++ b/include/audio/library.h @@ -44,7 +44,7 @@ struct SDL_AudioSpec; * \enddot * * \todo - * This module should be moved to oshu::library::skin. + * This module should be moved to oshu::skin in the library module. * * \todo * The audio module should not depend on the beatmap module. diff --git a/include/core/log.h b/include/core/log.h index c94bb3a..2283077 100644 --- a/include/core/log.h +++ b/include/core/log.h @@ -31,7 +31,7 @@ * It is a bit more verbose but it is also easier to extend, and also * type-safe. * - * See #oshu::core::log. + * See #oshu::log. * * \{ */ @@ -80,10 +80,6 @@ /** \} */ namespace oshu { -inline namespace core { - -/** \ingroup core_log */ -namespace log { /** * \ingroup core_log @@ -100,7 +96,7 @@ namespace log { * to SDL for that. In the mid-term, the enum will be unrelated to SDL's, even * though they're likely to remain equal. */ -enum class level : int { +enum class log_level : int { verbose = SDL_LOG_PRIORITY_VERBOSE, debug = SDL_LOG_PRIORITY_DEBUG, info = SDL_LOG_PRIORITY_INFO, @@ -109,8 +105,8 @@ enum class level : int { critical = SDL_LOG_PRIORITY_CRITICAL, }; -level& operator++(level&); -level& operator--(level&); +log_level& operator++(log_level&); +log_level& operator--(log_level&); /** * Current log level. @@ -118,7 +114,7 @@ level& operator--(level&); * Only messages with a level higher or equal to this level are logged. The * other messages are silently discarded. */ -extern level priority; +extern log_level log_priority; /** * Return the output stream for the wanted verbosity. @@ -136,15 +132,15 @@ extern level priority; * Support redirecting to a standard file, probably by redirecting std::clog. * However, it won't work with the legacy facility. */ -std::ostream& logger(level priority); +std::ostream& logger(log_level priority); -std::ostream& verbose(); -std::ostream& debug(); -std::ostream& info(); -std::ostream& warning(); -std::ostream& error(); -std::ostream& critical(); +std::ostream& verbose_log(); +std::ostream& debug_log(); +std::ostream& info_log(); +std::ostream& warning_log(); +std::ostream& error_log(); +std::ostream& critical_log(); /** \} */ -}}} +} diff --git a/include/game/base.h b/include/game/base.h index d1fac63..e2b26b5 100644 --- a/include/game/base.h +++ b/include/game/base.h @@ -15,7 +15,6 @@ #include "game/mode.h" namespace oshu { -namespace game { /** * \ingroup game @@ -23,7 +22,7 @@ namespace game { * The full game state, from the beatmap state to the audio and graphical * context. */ -class base : public mode { +class game_base : public game_mode { public: /** * Create the game context for a beatmap, and load all the associated assets. @@ -38,8 +37,8 @@ class base : public mode { * the beatmap is a taiko beatmap, then the taiko game should be instanciated, * not the base module. Instead, take a beatmap by reference. */ - base(const char *beatmap_path); - ~base(); + game_base(const char *beatmap_path); + ~game_base(); /** * Resume the game. * @@ -95,7 +94,7 @@ class base : public mode { struct oshu_hit *hit_cursor {}; }; -}} +} /** * \defgroup game_helpers Helpers @@ -110,21 +109,21 @@ class base : public mode { /** * Find the first hit object after *now - offset*. * - * It bases the search on the #oshu::game::base::hit_cursor for performance, but its + * It bases the search on the #oshu::game_base::hit_cursor for performance, but its * position won't affect the results. * * For long notes like sliders, the end time is used, not the start time. * * \sa oshu_look_hit_up */ -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); /** * Find the last hit object before *now + offset*. * * 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* oshu_look_hit_up(struct oshu::game_base *game, double offset); /** * Return the next relevant hit. @@ -134,11 +133,11 @@ 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* oshu_next_hit(struct oshu::game_base *game); /** * Like #oshu_next_hit, but in the other direction. */ -struct oshu_hit* oshu_previous_hit(struct oshu::game::base *game); +struct oshu_hit* oshu_previous_hit(struct oshu::game_base *game); /** \} */ diff --git a/include/game/clock.h b/include/game/clock.h index f4620a8..f9bb078 100644 --- a/include/game/clock.h +++ b/include/game/clock.h @@ -6,9 +6,8 @@ #pragma once namespace oshu { -namespace game { -class base; -}} +class game_base; +} /** * \defgroup game_clock Clock @@ -63,7 +62,7 @@ struct oshu_clock { double system; }; -void oshu_initialize_clock(struct oshu::game::base *game); +void oshu_initialize_clock(struct oshu::game_base *game); /** * Update the game clock. @@ -82,6 +81,6 @@ 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 oshu_update_clock(struct oshu::game_base *game); /** \} */ diff --git a/include/game/controls.h b/include/game/controls.h index dfa59c1..075c5d8 100644 --- a/include/game/controls.h +++ b/include/game/controls.h @@ -78,7 +78,7 @@ enum oshu_finger { * which makes it look like it's for the left hand. * * Anyway, this key is only meant as a temporary value, and it is never - * passed to the #oshu::game::base::press. No need to make special + * passed to the #oshu::game_base::press. No need to make special * cases for it. However, because new keys might be added in the future * (who knows?) you should have a sane default case for keys your * module doesn't handle, if relevant. @@ -113,7 +113,6 @@ enum oshu_control_key { /** \} */ namespace oshu { -namespace game { /** * \ingroup game_controls @@ -127,4 +126,4 @@ struct mouse { /** \} */ -}} +} diff --git a/include/game/mode.h b/include/game/mode.h index 6fbb266..9bf8c74 100644 --- a/include/game/mode.h +++ b/include/game/mode.h @@ -8,7 +8,6 @@ #include "game/controls.h" namespace oshu { -namespace game { /** * Define the contract for a game mode. @@ -20,9 +19,9 @@ namespace game { * * \ingroup game */ -struct mode { +struct game_mode { - virtual ~mode() = default; + virtual ~game_mode() = default; /** * Called at every game iteration, unless the game is paused. @@ -72,4 +71,4 @@ struct mode { }; -}} +} diff --git a/include/game/osu.h b/include/game/osu.h index c7f61ce..553bf49 100644 --- a/include/game/osu.h +++ b/include/game/osu.h @@ -19,7 +19,7 @@ * \{ */ -struct osu_game : public oshu::game::base { +struct osu_game : public oshu::game_base { osu_game(const char *beatmap_path); /** @@ -35,7 +35,7 @@ struct osu_game : public oshu::game::base { * irrelevant. */ enum oshu_finger held_key {}; - std::shared_ptr mouse {}; + std::shared_ptr mouse {}; int check() override; int check_autoplay() override; diff --git a/include/game/tty.h b/include/game/tty.h index b54a949..c80cc21 100644 --- a/include/game/tty.h +++ b/include/game/tty.h @@ -6,9 +6,8 @@ #pragma once namespace oshu { -namespace game { -class base; -}} +class game_base; +} /** * \defgroup game_tty TTY @@ -38,7 +37,7 @@ class base; * * Show the beatmap's metadata and difficulty information. */ -void oshu_welcome(struct oshu::game::base *game); +void oshu_welcome(struct oshu::game_base *game); /** * Show the state of the game (paused/playing) and the current song position. @@ -50,13 +49,13 @@ 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 oshu_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 oshu_congratulate(struct oshu::game_base *game); /** \} */ diff --git a/include/library/beatmaps.h b/include/library/beatmaps.h index 2742631..99dc27c 100644 --- a/include/library/beatmaps.h +++ b/include/library/beatmaps.h @@ -12,7 +12,6 @@ #include namespace oshu { -namespace library { /** * \defgroup library_beatmaps Beatmaps @@ -106,4 +105,4 @@ std::vector find_beatmap_sets(const std::string &path); /** } */ -}} +} diff --git a/include/library/html.h b/include/library/html.h index fd22487..df8fd76 100644 --- a/include/library/html.h +++ b/include/library/html.h @@ -19,10 +19,6 @@ #include namespace oshu { -namespace library { - -/** \ingroup library_html */ -namespace html { /** * \ingroup library_html @@ -41,11 +37,11 @@ namespace html { * The string object is taken by reference, so it must not be modified or * deleted as long as the #escape object is still alive. */ -class escape { +class html_escape { public: - explicit escape(const char*); - explicit escape(const std::string&); - friend std::ostream& operator<<(std::ostream&, const escape&); + explicit html_escape(const char*); + explicit html_escape(const std::string&); + friend std::ostream& operator<<(std::ostream&, const html_escape&); private: const char *data; }; @@ -53,8 +49,8 @@ class escape { /** * Generate an HTML listing of a list of beatmap sets. */ -void generate_beatmap_set_listing(const std::vector&, std::ostream&); +void generate_html_beatmap_set_listing(const std::vector&, std::ostream&); /** } */ -}}} +} diff --git a/include/ui/osu.h b/include/ui/osu.h index f01dbcf..8c8c404 100644 --- a/include/ui/osu.h +++ b/include/ui/osu.h @@ -15,11 +15,10 @@ struct osu_game; namespace oshu { -namespace ui { -struct osu; +struct osu_ui; -struct osu_mouse : public oshu::game::mouse { +struct osu_mouse : public oshu::mouse { osu_mouse(oshu_display *display); oshu_display *display; oshu_point position() override; @@ -30,9 +29,9 @@ struct osu_mouse : public oshu::game::mouse { * \{ */ -struct osu : public widget { - osu(oshu_display *display, osu_game &game); - ~osu(); +struct osu_ui : public widget { + osu_ui(oshu_display *display, osu_game &game); + ~osu_ui(); oshu_display *display; osu_game &game; @@ -99,7 +98,7 @@ struct osu : public widget { /** \} */ -}} +} /** * Paint all the required textures for the beatmap. @@ -108,7 +107,7 @@ struct osu : public widget { * * Sliders are not painted. Instead, you must call #osu_paint_slider. */ -int osu_paint_resources(oshu::ui::osu&); +int osu_paint_resources(oshu::osu_ui&); /** * Paint a slider. @@ -121,12 +120,12 @@ int osu_paint_resources(oshu::ui::osu&); * * Slider textures are freed with #osu_free_resources. */ -int osu_paint_slider(oshu::ui::osu&, struct oshu_hit *hit); +int osu_paint_slider(oshu::osu_ui&, struct oshu_hit *hit); /** * Free the dynamic resources of the game mode. */ -void osu_free_resources(oshu::ui::osu&); +void osu_free_resources(oshu::osu_ui&); /** * Set-up the coordinate system for the osu!standard mode. diff --git a/include/ui/shell.h b/include/ui/shell.h index cd05a9a..e0ac2dd 100644 --- a/include/ui/shell.h +++ b/include/ui/shell.h @@ -13,14 +13,12 @@ #include namespace oshu { -namespace game { -class base; -}} +class game_base; +} struct oshu_game_screen; namespace oshu { -namespace ui { struct widget; @@ -46,7 +44,7 @@ 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. @@ -54,7 +52,7 @@ struct shell { * A display should not be associated to more than one shell. */ oshu_display &display; - oshu::game::base &game; + oshu::game_base &game; /** * The widget responsible for drawing the main game objects, specific * to the mode. @@ -84,4 +82,4 @@ struct shell { /** \} */ -}} +} diff --git a/include/ui/widget.h b/include/ui/widget.h index 34dab11..2dc41cf 100644 --- a/include/ui/widget.h +++ b/include/ui/widget.h @@ -6,7 +6,6 @@ #pragma once namespace oshu { -namespace ui { /** * \ingroup ui @@ -20,4 +19,4 @@ struct widget { /** \} */ -}} +} diff --git a/lib/beatmap/parser.cc b/lib/beatmap/parser.cc index cbb9ce9..ce81733 100644 --- a/lib/beatmap/parser.cc +++ b/lib/beatmap/parser.cc @@ -71,7 +71,7 @@ static const struct oshu_beatmap default_beatmap = { ##__VA_ARGS__ \ ) -using namespace oshu::beatmap::parser; +using namespace oshu; /* Primitives ****************************************************************/ @@ -1305,7 +1305,7 @@ static int parse_file(FILE *input, const char *name, struct oshu_beatmap *beatma try { process_input(&parser); } catch (invalid_header& e) { - oshu::log::error() << e.what() << std::endl; + oshu::error_log() << e.what() << std::endl; rc = -1; break; } diff --git a/lib/beatmap/parser.h b/lib/beatmap/parser.h index 50974e2..a64c816 100644 --- a/lib/beatmap/parser.h +++ b/lib/beatmap/parser.h @@ -263,11 +263,9 @@ static int process_input(P*); static int parse_additions(P*, struct oshu_hit*); namespace oshu { -namespace beatmap { -namespace parser { struct invalid_header: public std::exception { const char* what() const throw() { return "invalid osu beatmap header"; } }; -}}} +} diff --git a/lib/core/index.dox b/lib/core/index.dox index 2fabc38..7311d4d 100644 --- a/lib/core/index.dox +++ b/lib/core/index.dox @@ -7,8 +7,3 @@ * This group gathers all the small modules that perform generic tasks. * It is standalone, and doesn't have any special link with the game in itself. */ - -/** - * \namespace oshu::core - * \ingroup core - */ diff --git a/lib/core/log.cc b/lib/core/log.cc index f607b0c..51db075 100644 --- a/lib/core/log.cc +++ b/lib/core/log.cc @@ -8,26 +8,24 @@ #include namespace oshu { -inline namespace core { -namespace log { -level priority = level::warning; +log_level log_priority = log_level::warning; -level& operator++(level &l) +log_level& operator++(log_level &l) { - if (l == level::critical) + if (l == log_level::critical) return l; int raw = static_cast(l); - l = static_cast(raw + 1); + l = static_cast(raw + 1); return l; } -level& operator--(level &l) +log_level& operator--(log_level &l) { - if (l == level::verbose) + if (l == log_level::verbose) return l; int raw = static_cast(l); - l = static_cast(raw - 1); + l = static_cast(raw - 1); return l; } @@ -36,19 +34,19 @@ level& operator--(level &l) */ static std::ostream devnull {nullptr}; -std::ostream& logger(level priority) +std::ostream& logger(log_level priority) { - if (priority >= oshu::core::log::priority) + if (log_priority >= oshu::log_priority) return std::clog; else return devnull; } -std::ostream& verbose() { return logger(level::verbose) << "VERBOSE: "; } -std::ostream& debug() { return logger(level::debug) << "DEBUG: "; } -std::ostream& info() { return logger(level::info) << "INFO: "; } -std::ostream& warning() { return logger(level::warning) << "WARNING: "; } -std::ostream& error() { return logger(level::error) << "ERROR: "; } -std::ostream& critical() { return logger(level::critical) << "CRITICAL: "; } +std::ostream& verbose_log() { return logger(log_level::verbose) << "VERBOSE: "; } +std::ostream& debug_log() { return logger(log_level::debug) << "DEBUG: "; } +std::ostream& info_log() { return logger(log_level::info) << "INFO: "; } +std::ostream& warning_log() { return logger(log_level::warning) << "WARNING: "; } +std::ostream& error_log() { return logger(log_level::error) << "ERROR: "; } +std::ostream& critical_log() { return logger(log_level::critical) << "CRITICAL: "; } -}}} +} diff --git a/lib/game/base.cc b/lib/game/base.cc index 59530a1..9257276 100644 --- a/lib/game/base.cc +++ b/lib/game/base.cc @@ -16,7 +16,7 @@ #include -static int open_beatmap(const char *beatmap_path, struct oshu::game::base *game) +static int open_beatmap(const char *beatmap_path, struct oshu::game_base *game) { if (oshu_load_beatmap(beatmap_path, &game->beatmap) < 0) { oshu_log_error("no beatmap, aborting"); @@ -31,7 +31,7 @@ static int open_beatmap(const char *beatmap_path, struct oshu::game::base *game) return 0; } -static int open_audio(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) { @@ -44,9 +44,8 @@ static int open_audio(struct oshu::game::base *game) } namespace oshu { -namespace game { -base::base(const char *beatmap_path) +game_base::game_base(const char *beatmap_path) { if (open_beatmap(beatmap_path, this) < 0) throw std::runtime_error("could not load the beatmap"); @@ -54,14 +53,14 @@ base::base(const char *beatmap_path) throw std::runtime_error("could not open the audio device"); } -base::~base() +game_base::~game_base() { oshu_destroy_beatmap(&beatmap); oshu_close_audio(&audio); oshu_close_sound_library(&library); } -void base::rewind(double offset) +void game_base::rewind(double offset) { oshu_seek_music(&this->audio, this->audio.music.current_timestamp - offset); this->clock.now = this->audio.music.current_timestamp; @@ -75,7 +74,7 @@ void base::rewind(double offset) } } -void base::forward(double offset) +void game_base::forward(double offset) { oshu_seek_music(&this->audio, this->audio.music.current_timestamp + offset); this->clock.now = this->audio.music.current_timestamp; @@ -90,14 +89,14 @@ void base::forward(double offset) } } -void base::pause() +void game_base::pause() { oshu_pause_audio(&this->audio); this->paused = true; oshu_print_state(this); } -void base::unpause() +void game_base::unpause() { if (this->clock.now >= 0) oshu_play_audio(&this->audio); @@ -105,4 +104,4 @@ void base::unpause() oshu_print_state(this); } -}} +} diff --git a/lib/game/clock.cc b/lib/game/clock.cc index 4efd446..f307289 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,7 +25,7 @@ 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; double system = SDL_GetTicks() / 1000.; diff --git a/lib/game/helpers.cc b/lib/game/helpers.cc index e0c2081..79dc356 100644 --- a/lib/game/helpers.cc +++ b/lib/game/helpers.cc @@ -5,7 +5,7 @@ #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; double target = game->clock.now - offset; @@ -19,7 +19,7 @@ struct oshu_hit* oshu_look_hit_back(struct oshu::game::base *game, double offset 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; double target = game->clock.now + offset; @@ -33,7 +33,7 @@ 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; for (; hit->next; hit = hit->next) { @@ -43,7 +43,7 @@ struct oshu_hit* oshu_next_hit(struct oshu::game::base *game) 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; if (!hit->previous) diff --git a/lib/game/index.dox b/lib/game/index.dox index f1aec9e..2f60e8d 100644 --- a/lib/game/index.dox +++ b/lib/game/index.dox @@ -1,8 +1,3 @@ /** * \defgroup game Game */ - -/** - * \namespace oshu::game - * \ingroup game - */ diff --git a/lib/game/osu.cc b/lib/game/osu.cc index b2905bb..6148c31 100644 --- a/lib/game/osu.cc +++ b/lib/game/osu.cc @@ -13,7 +13,7 @@ #include osu_game::osu_game(const char *beatmap_path) -: oshu::game::base(beatmap_path) +: oshu::game_base(beatmap_path) { } diff --git a/lib/game/tty.cc b/lib/game/tty.cc index ad7ec7c..da7bc89 100644 --- a/lib/game/tty.cc +++ b/lib/game/tty.cc @@ -21,7 +21,7 @@ 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; @@ -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,7 +70,7 @@ 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"); diff --git a/lib/library/beatmaps.cc b/lib/library/beatmaps.cc index f121c07..7abfed1 100644 --- a/lib/library/beatmaps.cc +++ b/lib/library/beatmaps.cc @@ -15,7 +15,6 @@ #include namespace oshu { -namespace library { beatmap_entry::beatmap_entry(const std::string &path) : path(path) @@ -64,12 +63,12 @@ static void find_entries(const std::string &path, beatmap_set &set) os << path << "/" << entry->d_name; beatmap_entry entry (os.str()); if (entry.mode != OSHU_OSU_MODE) - oshu::log::debug() << "skipping " << path << ": unsupported mode" << std::endl; + oshu::debug_log() << "skipping " << path << ": unsupported mode" << std::endl; else set.entries.push_back(std::move(entry)); } catch(std::runtime_error &e) { - oshu::log::warning() << e.what() << std::endl; - oshu::log::warning() << "ignoring invalid beatmap " << path << std::endl; + oshu::warning_log() << e.what() << std::endl; + oshu::warning_log() << "ignoring invalid beatmap " << path << std::endl; } } } @@ -133,7 +132,7 @@ std::vector find_beatmap_sets(const std::string &path) if (!set.empty()) sets.push_back(std::move(set)); } catch (std::system_error& e) { - oshu::log::debug() << e.what() << std::endl; + oshu::debug_log() << e.what() << std::endl; } } } @@ -142,4 +141,4 @@ std::vector find_beatmap_sets(const std::string &path) return sets; } -}} +} diff --git a/lib/library/html.cc b/lib/library/html.cc index d5cec7b..25c76e3 100644 --- a/lib/library/html.cc +++ b/lib/library/html.cc @@ -11,15 +11,13 @@ #include namespace oshu { -namespace library { -namespace html { -escape::escape(const char *str) +html_escape::html_escape(const char *str) : data(str) { } -escape::escape(const std::string &str) +html_escape::html_escape(const std::string &str) : data(str.c_str()) { } @@ -31,7 +29,7 @@ static std::unordered_map escape_sequences = { {'"', """}, // for attributes }; -std::ostream& operator<<(std::ostream &os, const escape &e) +std::ostream& operator<<(std::ostream &os, const html_escape &e) { for (const char *c = e.data; *c; ++c) { auto i = escape_sequences.find(*c); @@ -52,7 +50,7 @@ static const char *head = R"html( static void generate_entry(const beatmap_entry &entry, std::ostream &os) { - os << "
  • " << escape{entry.version} << "
  • "; + os << "
  • " << html_escape{entry.version} << "
  • "; } /** @@ -66,18 +64,18 @@ static void generate_entry(const beatmap_entry &entry, std::ostream &os) static void generate_set(const beatmap_set &set, std::ostream &os) { os << "
    "; - os << "

    " << escape{set.artist} << " - " << escape{set.title} << "

      "; + os << "

      " << html_escape{set.artist} << " - " << html_escape{set.title} << "

        "; for (const beatmap_entry &entry : set.entries) generate_entry(entry, os); os << "
    "; } -void generate_beatmap_set_listing(const std::vector &sets, std::ostream &os) +void generate_html_beatmap_set_listing(const std::vector &sets, std::ostream &os) { os << head; - os << ""; + os << ""; for (const beatmap_set &set : sets) generate_set(set, os); } -}}} +} diff --git a/lib/library/index.dox b/lib/library/index.dox index 7481623..54bccc6 100644 --- a/lib/library/index.dox +++ b/lib/library/index.dox @@ -4,8 +4,3 @@ * \brief * Discover resources. */ - -/** - * \namespace oshu::library - * \ingroup library - */ diff --git a/lib/ui/index.dox b/lib/ui/index.dox index 680ed21..c41e268 100644 --- a/lib/ui/index.dox +++ b/lib/ui/index.dox @@ -20,8 +20,3 @@ * take the widget object, but may receive additional parameters. * */ - -/** - * \namespace oshu::ui - * \ingroup ui - */ diff --git a/lib/ui/osu.cc b/lib/ui/osu.cc index f75d2ca..e26842f 100644 --- a/lib/ui/osu.cc +++ b/lib/ui/osu.cc @@ -14,9 +14,9 @@ #include -static void draw_hint(oshu::ui::osu &view, struct oshu_hit *hit) +static void draw_hint(oshu::osu_ui &view, struct oshu_hit *hit) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; double now = game->clock.now; if (hit->time > now && hit->state == OSHU_INITIAL_HIT) { SDL_SetRenderDrawColor(view.display->renderer, 255, 128, 64, 255); @@ -30,9 +30,9 @@ static void draw_hint(oshu::ui::osu &view, struct oshu_hit *hit) } } -static void draw_hit_mark(oshu::ui::osu &view, struct oshu_hit *hit) +static void draw_hit_mark(oshu::osu_ui &view, struct oshu_hit *hit) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; if (hit->state == OSHU_GOOD_HIT) { double leniency = game->beatmap.difficulty.leniency; struct oshu_texture *mark = &view.good_mark; @@ -48,9 +48,9 @@ static void draw_hit_mark(oshu::ui::osu &view, struct oshu_hit *hit) } } -static void draw_hit_circle(oshu::ui::osu &view, struct oshu_hit *hit) +static void draw_hit_circle(oshu::osu_ui &view, struct oshu_hit *hit) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; struct oshu_display *display = view.display; if (hit->state == OSHU_INITIAL_HIT) { assert (hit->color != NULL); @@ -61,9 +61,9 @@ static void draw_hit_circle(oshu::ui::osu &view, struct oshu_hit *hit) } } -static void draw_slider(oshu::ui::osu &view, struct oshu_hit *hit) +static void draw_slider(oshu::osu_ui &view, struct oshu_hit *hit) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; struct oshu_display *display = view.display; double now = game->clock.now; if (hit->state == OSHU_INITIAL_HIT || hit->state == OSHU_SLIDING_HIT) { @@ -84,9 +84,9 @@ static void draw_slider(oshu::ui::osu &view, struct oshu_hit *hit) } } -static void draw_hit(oshu::ui::osu &view, struct oshu_hit *hit) +static void draw_hit(oshu::osu_ui &view, struct oshu_hit *hit) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; if (hit->type & OSHU_SLIDER_HIT) draw_slider(view, hit); else if (hit->type & OSHU_CIRCLE_HIT) @@ -118,9 +118,9 @@ static void draw_hit(oshu::ui::osu &view, struct oshu_hit *hit) * Voilà! * */ -static void connect_hits(oshu::ui::osu &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; + oshu::game_base *game = &view.game; if (a->state != OSHU_INITIAL_HIT && a->state != OSHU_SLIDING_HIT) return; oshu_point a_end = oshu_end_point(a); @@ -141,13 +141,12 @@ static void connect_hits(oshu::ui::osu &view, struct oshu_hit *a, struct oshu_hi } namespace oshu { -namespace ui { /** * \todo * Handle errors. */ -osu::osu(oshu_display *display, osu_game &game) +osu_ui::osu_ui(oshu_display *display, osu_game &game) : display(display), game(game) { assert (display != nullptr); @@ -160,7 +159,7 @@ osu::osu(oshu_display *display, osu_game &game) game.mouse = mouse; } -osu::~osu() +osu_ui::~osu_ui() { SDL_ShowCursor(SDL_ENABLE); osu_free_resources(*this); @@ -171,7 +170,7 @@ osu::~osu() * Draw all the visible nodes from the beatmap, according to the current * position in the song. */ -void osu::draw() +void osu_ui::draw() { osu_view(display); struct oshu_hit *cursor = oshu_look_hit_up(&game, game.beatmap.difficulty.approach_time); @@ -204,7 +203,7 @@ oshu_point osu_mouse::position() return mouse; } -}} +} void osu_view(struct oshu_display *display) { diff --git a/lib/ui/osu_paint.cc b/lib/ui/osu_paint.cc index 6728f3f..57726ee 100644 --- a/lib/ui/osu_paint.cc +++ b/lib/ui/osu_paint.cc @@ -18,9 +18,9 @@ static double brighter(double v) return v < 1. ? v : 1.; } -static int paint_approach_circle(oshu::ui::osu &view) +static int paint_approach_circle(oshu::osu_ui &view) { - oshu::game::base *game = &view.game; + 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.); @@ -39,9 +39,9 @@ static int paint_approach_circle(oshu::ui::osu &view) return rc; } -static int paint_circle(oshu::ui::osu &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; + oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.circle_radius; oshu_size size = oshu_size(radius * 2., radius * 2.); @@ -108,9 +108,9 @@ 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::ui::osu &view, struct oshu_hit *hit) +int osu_paint_slider(oshu::osu_ui &view, struct oshu_hit *hit) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; int start = SDL_GetTicks(); assert (hit->type & OSHU_SLIDER_HIT); double radius = game->beatmap.difficulty.circle_radius; @@ -189,8 +189,8 @@ int osu_paint_slider(oshu::ui::osu &view, struct oshu_hit *hit) * It looks like cairo_fill with a pattern triggers jumps depending on * uninitialised values, which propagates. */ -static int paint_slider_ball(oshu::ui::osu &view) { - oshu::game::base *game = &view.game; +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.; @@ -225,9 +225,9 @@ static int paint_slider_ball(oshu::ui::osu &view) { return rc; } -static int paint_good_mark(oshu::ui::osu &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; + oshu::game_base *game = &view.game; double radius = game->beatmap.difficulty.circle_radius / 3.5; oshu_size size = oshu_size{1, 1} * radius * 2.; @@ -256,9 +256,9 @@ static int paint_good_mark(oshu::ui::osu &view, int offset, struct oshu_texture return rc; } -static int paint_bad_mark(oshu::ui::osu &view) +static int paint_bad_mark(oshu::osu_ui &view) { - oshu::game::base *game = &view.game; + 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.; @@ -283,9 +283,9 @@ static int paint_bad_mark(oshu::ui::osu &view) return rc; } -static int paint_skip_mark(oshu::ui::osu &view) +static int paint_skip_mark(oshu::osu_ui &view) { - oshu::game::base *game = &view.game; + 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.; @@ -312,9 +312,9 @@ static int paint_skip_mark(oshu::ui::osu &view) return rc; } -static int paint_connector(oshu::ui::osu &view) +static int paint_connector(oshu::osu_ui &view) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; double radius = 3; oshu_size size = oshu_size{1, 1} * radius * 2.; @@ -336,9 +336,9 @@ static int paint_connector(oshu::ui::osu &view) * \todo * Handle errors. */ -int osu_paint_resources(oshu::ui::osu &view) +int osu_paint_resources(oshu::osu_ui &view) { - oshu::game::base *game = &view.game; + oshu::game_base *game = &view.game; int start = SDL_GetTicks(); oshu_log_debug("painting the textures"); @@ -369,9 +369,9 @@ int osu_paint_resources(oshu::ui::osu &view) return 0; } -void osu_free_resources(oshu::ui::osu &view) +void osu_free_resources(oshu::osu_ui &view) { - oshu::game::base *game = &view.game; + 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]); diff --git a/lib/ui/screens/pause.cc b/lib/ui/screens/pause.cc index c8a8be2..c7b7d40 100644 --- a/lib/ui/screens/pause.cc +++ b/lib/ui/screens/pause.cc @@ -14,9 +14,9 @@ #include -static int on_event(oshu::ui::shell &w, union SDL_Event *event) +static int on_event(oshu::shell &w, union SDL_Event *event) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; switch (event->type) { case SDL_KEYDOWN: if (event->key.repeat) @@ -50,9 +50,9 @@ static int on_event(oshu::ui::shell &w, union SDL_Event *event) return 0; } -static int update(oshu::ui::shell &w) +static int update(oshu::shell &w) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; if (!game->paused) w.screen = &oshu_play_screen; return 0; @@ -76,9 +76,9 @@ static void draw_pause(struct oshu_display *display) SDL_RenderFillRect(display->renderer, &bar); } -static int draw(oshu::ui::shell &w) +static int draw(oshu::shell &w) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; SDL_ShowCursor(SDL_ENABLE); oshu_show_background(&w.background, 0); oshu_show_metadata_frame(&w.metadata, 1); diff --git a/lib/ui/screens/play.cc b/lib/ui/screens/play.cc index 1f2b821..367617d 100644 --- a/lib/ui/screens/play.cc +++ b/lib/ui/screens/play.cc @@ -17,9 +17,9 @@ #include -static int on_event(oshu::ui::shell &w, union SDL_Event *event) +static int on_event(oshu::shell &w, union SDL_Event *event) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; switch (event->type) { case SDL_KEYDOWN: if (event->key.repeat) @@ -83,9 +83,9 @@ static int on_event(oshu::ui::shell &w, union SDL_Event *event) * * The game switches to the score screen, from which the only exit is *death*. */ -static void check_end(oshu::ui::shell &w) +static void check_end(oshu::shell &w) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; if (game->hit_cursor->next) return; const double delay = game->beatmap.difficulty.leniency + game->beatmap.difficulty.approach_time; @@ -97,9 +97,9 @@ static void check_end(oshu::ui::shell &w) } } -static int update(oshu::ui::shell &w) +static int update(oshu::shell &w) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; if (game->paused) { w.screen = &oshu_pause_screen; return 0; @@ -140,9 +140,9 @@ static int update(oshu::ui::shell &w) * seconds. * */ -static void draw_background(oshu::ui::shell &w) +static void draw_background(oshu::shell &w) { - oshu::game::base *game = &w.game; + 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 now = game->clock.now; @@ -152,9 +152,9 @@ static void draw_background(oshu::ui::shell &w) oshu_show_background(&w.background, ratio); } -static int draw(oshu::ui::shell &w) +static int draw(oshu::shell &w) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; if (w.display.features & OSHU_FANCY_CURSOR) SDL_ShowCursor(SDL_DISABLE); draw_background(w); diff --git a/lib/ui/screens/score.cc b/lib/ui/screens/score.cc index 2d9d1f2..2a2f622 100644 --- a/lib/ui/screens/score.cc +++ b/lib/ui/screens/score.cc @@ -14,9 +14,9 @@ #include -static int on_event(oshu::ui::shell &w, union SDL_Event *event) +static int on_event(oshu::shell &w, union SDL_Event *event) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; switch (event->type) { case SDL_KEYDOWN: if (event->key.repeat) @@ -38,14 +38,14 @@ static int on_event(oshu::ui::shell &w, union SDL_Event *event) return 0; } -static int update(oshu::ui::shell &w) +static int update(oshu::shell &w) { return 0; } -static int draw(oshu::ui::shell &w) +static int draw(oshu::shell &w) { - oshu::game::base *game = &w.game; + 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); diff --git a/lib/ui/screens/screens.h b/lib/ui/screens/screens.h index 6ec0c93..1eefa14 100644 --- a/lib/ui/screens/screens.h +++ b/lib/ui/screens/screens.h @@ -8,9 +8,8 @@ union SDL_Event; namespace oshu { -namespace ui { struct shell; -}} +} /** * \defgroup ui_screens Screens @@ -69,11 +68,11 @@ struct oshu_game_screen { * The main game module may preprocess the event, or even filter it. * For instance, when the shell is closed. */ - int (*on_event)(oshu::ui::shell&, union SDL_Event *event); + int (*on_event)(oshu::shell&, union SDL_Event *event); /** * The update function is run at every iteration of the main loop. */ - int (*update)(oshu::ui::shell&); + int (*update)(oshu::shell&); /** * Draw the screen. * @@ -82,7 +81,7 @@ struct oshu_game_screen { * * Beside that, no implicit drawing is done for you. */ - int (*draw)(oshu::ui::shell&); + int (*draw)(oshu::shell&); }; /* Defined in play.c */ diff --git a/lib/ui/shell.cc b/lib/ui/shell.cc index 235c190..518b2ee 100644 --- a/lib/ui/shell.cc +++ b/lib/ui/shell.cc @@ -13,7 +13,7 @@ #include "./screens/screens.h" -static void set_title(oshu::ui::shell &w) +static void set_title(oshu::shell &w) { struct oshu_metadata *meta = &w.game.beatmap.metadata; std::ostringstream title; @@ -23,9 +23,8 @@ static void set_title(oshu::ui::shell &w) } namespace oshu { -namespace ui { -shell::shell(oshu_display &display, oshu::game::base &game) +shell::shell(oshu_display &display, oshu::game_base &game) : display(display), game(game), screen(&oshu_play_screen) { set_title(*this); @@ -46,7 +45,7 @@ shell::~shell() static void draw(shell &w) { - oshu::game::base *game = &w.game; + oshu::game_base *game = &w.game; SDL_SetRenderDrawColor(w.display.renderer, 0, 0, 0, 255); SDL_RenderClear(w.display.renderer); w.screen->draw(w); @@ -99,4 +98,4 @@ void shell::close() stop = true; } -}} +} diff --git a/lib/video/index.dox b/lib/video/index.dox index eba8f5d..a4ec27a 100644 --- a/lib/video/index.dox +++ b/lib/video/index.dox @@ -45,8 +45,3 @@ * \enddot * */ - - /** - * \namespace oshu::video - * \ingroup video - */ diff --git a/src/oshu-library/build_index.cc b/src/oshu-library/build_index.cc index f9a235c..9189da5 100644 --- a/src/oshu-library/build_index.cc +++ b/src/oshu-library/build_index.cc @@ -35,7 +35,7 @@ static void ensure_directory(const std::string &path) return; throw std::system_error(errno, std::system_category(), "could not create directory " + path); } else { - oshu::log::debug() << "created directory " << path << std::endl; + oshu::debug_log() << "created directory " << path << std::endl; } } @@ -44,7 +44,7 @@ static void change_directory(const std::string &path) if (chdir(path.c_str()) < 0) throw std::system_error(errno, std::system_category(), "could not chdir to " + path); else - oshu::log::debug() << "moving to " << path << std::endl; + oshu::debug_log() << "moving to " << path << std::endl; } /** @@ -71,13 +71,13 @@ static std::string get_oshu_home() static void do_build_index() { std::string home = get_oshu_home(); - oshu::log::info() << "oshu! home directory: " << home << std::endl; + oshu::info_log() << "oshu! home directory: " << home << std::endl; ensure_directory(home); ensure_directory(home + "/web"); change_directory(home + "/web"); - auto sets = oshu::library::find_beatmap_sets("../beatmaps"); + auto sets = oshu::find_beatmap_sets("../beatmaps"); std::ofstream index("index.html"); - oshu::library::html::generate_beatmap_set_listing(sets, index); + oshu::generate_html_beatmap_set_listing(sets, index); std::cout << home << "/web/index.html" << std::endl; } @@ -89,7 +89,7 @@ static int run(int argc, char **argv) break; switch (c) { case OPT_VERBOSE: - --oshu::log::priority; + --oshu::log_priority; break; } } @@ -99,7 +99,7 @@ static int run(int argc, char **argv) return 2; } SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN); - SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, static_cast(oshu::log::priority)); + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, static_cast(oshu::log_priority)); do_build_index(); return 0; } diff --git a/src/oshu/main.cc b/src/oshu/main.cc index 652f07a..660e064 100644 --- a/src/oshu/main.cc +++ b/src/oshu/main.cc @@ -71,7 +71,7 @@ static const char *version = "There is NO WARRANTY, to the extent permitted by law.\n" ; -static std::weak_ptr current_shell; +static std::weak_ptr current_shell; static void signal_handler(int signum) { @@ -95,12 +95,12 @@ int run(const char *beatmap_path, int autoplay, int pause) game.pause(); oshu_display display; - std::shared_ptr shell = std::make_shared(display, game); - shell->game_view = std::make_unique(&display, game); + std::shared_ptr shell = std::make_shared(display, game); + shell->game_view = std::make_unique(&display, game); current_shell = shell; shell->open(); } catch (std::exception &e) { - oshu::log::critical() << e.what() << std::endl; + oshu::critical_log() << e.what() << std::endl; rc = -1; } @@ -119,7 +119,7 @@ int main(int argc, char **argv) break; switch (c) { case OPT_VERBOSE: - --oshu::log::priority; + --oshu::log_priority; break; case OPT_HELP: puts(usage); @@ -146,8 +146,8 @@ int main(int argc, char **argv) } SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN); - SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, static_cast(oshu::log::priority)); - av_log_set_level(oshu::log::priority <= oshu::log::level::debug ? AV_LOG_INFO : AV_LOG_ERROR); + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, static_cast(oshu::log_priority)); + av_log_set_level(oshu::log_priority <= oshu::log_level::debug ? AV_LOG_INFO : AV_LOG_ERROR); char *beatmap_path = realpath(argv[optind], NULL); if (beatmap_path == NULL) {