Skip to content

Commit

Permalink
remove all the sub-namespaces
Browse files Browse the repository at this point in the history
The root namespace is cool because we don’t have to prefix everything
with oshu_ anymore. However, using a dedicated namespace has several
cons:

- when they are used for context, they get confusing when implied, like
  html::escape which becomes only “escape”,

- otherwise, they are redondant at best, conflicting at worst, like
  library::beatmap_set whose module doesn’t matter, or the oshu::beatmap
  namespace which would have conflicted with the beatmap class.

When looking for a definition, Doxygen and ctags are good enough. No
need to explicitly qualify the namespace everytime in the code.
  • Loading branch information
fmang committed Mar 27, 2020
1 parent ae4118b commit b4becdf
Show file tree
Hide file tree
Showing 37 changed files with 191 additions and 245 deletions.
2 changes: 1 addition & 1 deletion include/audio/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 13 additions & 17 deletions include/core/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* \{
*/
Expand Down Expand Up @@ -80,10 +80,6 @@
/** \} */

namespace oshu {
inline namespace core {

/** \ingroup core_log */
namespace log {

/**
* \ingroup core_log
Expand All @@ -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,
Expand All @@ -109,16 +105,16 @@ 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.
*
* 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.
Expand All @@ -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();

/** \} */

}}}
}
19 changes: 9 additions & 10 deletions include/game/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
#include "game/mode.h"

namespace oshu {
namespace game {

/**
* \ingroup 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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -95,7 +94,7 @@ class base : public mode {
struct oshu_hit *hit_cursor {};
};

}}
}

/**
* \defgroup game_helpers Helpers
Expand All @@ -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.
Expand All @@ -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);

/** \} */
9 changes: 4 additions & 5 deletions include/game/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#pragma once

namespace oshu {
namespace game {
class base;
}}
class game_base;
}

/**
* \defgroup game_clock Clock
Expand Down Expand Up @@ -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.
Expand All @@ -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);

/** \} */
5 changes: 2 additions & 3 deletions include/game/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -113,7 +113,6 @@ enum oshu_control_key {
/** \} */

namespace oshu {
namespace game {

/**
* \ingroup game_controls
Expand All @@ -127,4 +126,4 @@ struct mouse {

/** \} */

}}
}
7 changes: 3 additions & 4 deletions include/game/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "game/controls.h"

namespace oshu {
namespace game {

/**
* Define the contract for a game mode.
Expand All @@ -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.
Expand Down Expand Up @@ -72,4 +71,4 @@ struct mode {

};

}}
}
4 changes: 2 additions & 2 deletions include/game/osu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* \{
*/

struct osu_game : public oshu::game::base {
struct osu_game : public oshu::game_base {
osu_game(const char *beatmap_path);

/**
Expand All @@ -35,7 +35,7 @@ struct osu_game : public oshu::game::base {
* irrelevant.
*/
enum oshu_finger held_key {};
std::shared_ptr<oshu::game::mouse> mouse {};
std::shared_ptr<oshu::mouse> mouse {};

int check() override;
int check_autoplay() override;
Expand Down
11 changes: 5 additions & 6 deletions include/game/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#pragma once

namespace oshu {
namespace game {
class base;
}}
class game_base;
}

/**
* \defgroup game_tty TTY
Expand Down Expand Up @@ -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.
Expand All @@ -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);

/** \} */
3 changes: 1 addition & 2 deletions include/library/beatmaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <vector>

namespace oshu {
namespace library {

/**
* \defgroup library_beatmaps Beatmaps
Expand Down Expand Up @@ -106,4 +105,4 @@ std::vector<beatmap_set> find_beatmap_sets(const std::string &path);

/** } */

}}
}
16 changes: 6 additions & 10 deletions include/library/html.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include <vector>

namespace oshu {
namespace library {

/** \ingroup library_html */
namespace html {

/**
* \ingroup library_html
Expand All @@ -41,20 +37,20 @@ 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;
};

/**
* Generate an HTML listing of a list of beatmap sets.
*/
void generate_beatmap_set_listing(const std::vector<oshu::library::beatmap_set>&, std::ostream&);
void generate_html_beatmap_set_listing(const std::vector<oshu::beatmap_set>&, std::ostream&);

/** } */

}}}
}
Loading

0 comments on commit b4becdf

Please sign in to comment.