1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-13 00:29:14 +00:00

Improve style: indentation, constness, names.

This commit is contained in:
Thomas Harte 2024-12-06 15:29:49 -05:00
parent ea4fe5e809
commit f43e594eca
8 changed files with 83 additions and 83 deletions

View File

@ -15,10 +15,9 @@ namespace MachineTypes {
/*!
An AudioProducer is any machine that **might** produce audio. This isn't always knowable statically.
*/
class AudioProducer {
public:
/// @returns The speaker that receives this machine's output, or @c nullptr if this machine is mute.
virtual Outputs::Speaker::Speaker *get_speaker() = 0;
struct AudioProducer {
/// @returns The speaker that receives this machine's output, or @c nullptr if this machine is mute.
virtual Outputs::Speaker::Speaker *get_speaker() = 0;
};
}

View File

@ -13,9 +13,8 @@
namespace MachineTypes {
class JoystickMachine {
public:
virtual const std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() = 0;
struct JoystickMachine {
virtual const std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() = 0;
};
}

View File

@ -41,70 +41,75 @@ struct KeyActions {
/*!
Describes an emulated machine which exposes a keyboard and accepts a typed string.
*/
class KeyboardMachine: public KeyActions {
public:
/*!
Causes the machine to attempt to type the supplied string.
struct KeyboardMachine: public KeyActions {
/*!
Causes the machine to attempt to type the supplied string.
This is best effort. Success or failure is permitted to be a function of machine and current state.
*/
virtual void type_string(const std::string &);
This is best effort. Success or failure is permitted to be a function of machine and current state.
*/
virtual void type_string(const std::string &);
/*!
@returns @c true if this machine can type the character @c c as part of a @c type_string; @c false otherwise.
*/
virtual bool can_type([[maybe_unused]] char c) const { return false; }
/*!
@returns @c true if this machine can type the character @c c as part of a @c type_string; @c false otherwise.
*/
virtual bool can_type([[maybe_unused]] char c) const { return false; }
/*!
Provides a destination for keyboard input.
*/
virtual Inputs::Keyboard &get_keyboard() = 0;
/*!
Provides a destination for keyboard input.
*/
virtual Inputs::Keyboard &get_keyboard() = 0;
/*!
Provides a standard bundle of logic for hosts that are able to correlate typed symbols
with keypresses. Specifically:
/*!
Provides a standard bundle of logic for hosts that are able to correlate typed symbols
with keypresses. Specifically:
If map_logically is false:
If map_logically is false:
(i) initially try to set @c key as @c is_pressed;
(ii) if this machine doesn't map @c key to anything but @c symbol is a printable ASCII character, attempt to @c type_string it.
(i) initially try to set @c key as @c is_pressed;
(ii) if this machine doesn't map @c key to anything but @c symbol is a printable ASCII character, attempt to @c type_string it.
If map_logically is true:
If map_logically is true:
(i) if @c symbol can be typed and this is a key down, @c type_string it;
(ii) if @c symbol cannot be typed, set @c key as @c is_pressed
*/
bool apply_key(Inputs::Keyboard::Key key, char symbol, bool is_pressed, bool is_repeat, bool map_logically) {
Inputs::Keyboard &keyboard = get_keyboard();
(i) if @c symbol can be typed and this is a key down, @c type_string it;
(ii) if @c symbol cannot be typed, set @c key as @c is_pressed
*/
bool apply_key(
const Inputs::Keyboard::Key key,
const char symbol,
const bool is_pressed,
const bool is_repeat,
const bool map_logically
) {
Inputs::Keyboard &keyboard = get_keyboard();
if(!map_logically) {
// Try a regular keypress first, and stop if that works.
if(keyboard.set_key_pressed(key, symbol, is_pressed, is_repeat)) {
return true;
}
// That having failed, if a symbol has been supplied then try typing it.
if(is_pressed && symbol && can_type(symbol)) {
char string[2] = { symbol, 0 };
type_string(string);
return true;
}
return false;
} else {
// Try to type first.
if(is_pressed && symbol && can_type(symbol)) {
char string[2] = { symbol, 0 };
type_string(string);
return true;
}
// That didn't work. Forward as a keypress. As, either:
// (i) this is a key down, but doesn't have a symbol, or is an untypeable symbol; or
// (ii) this is a key up, which it won't be an issue to miscommunicate.
return keyboard.set_key_pressed(key, symbol, is_pressed, is_repeat);
if(!map_logically) {
// Try a regular keypress first, and stop if that works.
if(keyboard.set_key_pressed(key, symbol, is_pressed, is_repeat)) {
return true;
}
// That having failed, if a symbol has been supplied then try typing it.
if(is_pressed && symbol && can_type(symbol)) {
char string[2] = { symbol, 0 };
type_string(string);
return true;
}
return false;
} else {
// Try to type first.
if(is_pressed && symbol && can_type(symbol)) {
char string[2] = { symbol, 0 };
type_string(string);
return true;
}
// That didn't work. Forward as a keypress. As, either:
// (i) this is a key down, but doesn't have a symbol, or is an untypeable symbol; or
// (ii) this is a key up, which it won't be an issue to miscommunicate.
return keyboard.set_key_pressed(key, symbol, is_pressed, is_repeat);
}
}
};
/*!
@ -119,9 +124,8 @@ public:
A keyboard mapper attempts to provide a physical mapping between host keys and emulated keys.
See the character mapper for logical mapping.
*/
class KeyboardMapper {
public:
virtual uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) const = 0;
struct KeyboardMapper {
virtual uint16_t mapped_key_for_key(Inputs::Keyboard::Key) const = 0;
};
/// Terminates a key sequence from the character mapper.
@ -146,8 +150,8 @@ public:
virtual Inputs::Keyboard &get_keyboard() override;
private:
bool keyboard_did_change_key(Inputs::Keyboard *keyboard, Inputs::Keyboard::Key key, bool is_pressed) override;
void reset_all_keys(Inputs::Keyboard *keyboard) override;
bool keyboard_did_change_key(Inputs::Keyboard *, Inputs::Keyboard::Key, bool is_pressed) override;
void reset_all_keys(Inputs::Keyboard *) override;
Inputs::Keyboard keyboard_;
};

View File

@ -18,14 +18,13 @@ namespace MachineTypes {
/*!
A MediaTarget::Machine is anything that can accept new media while running.
*/
class MediaTarget {
public:
/*!
Requests that the machine insert @c media as a modification to current state
struct MediaTarget {
/*!
Requests that the machine insert @c media as a modification to current state
@returns @c true if any media was inserted; @c false otherwise.
*/
virtual bool insert_media(const Analyser::Static::Media &media) = 0;
@returns @c true if any media was inserted; @c false otherwise.
*/
virtual bool insert_media(const Analyser::Static::Media &) = 0;
};
}

View File

@ -12,10 +12,9 @@
namespace MachineTypes {
class MouseMachine {
public:
// TODO: support multiple mice?
virtual Inputs::Mouse &get_mouse() = 0;
struct MouseMachine {
// TODO: support multiple mice?
virtual Inputs::Mouse &get_mouse() = 0;
};
}

View File

@ -27,10 +27,10 @@ namespace ROMMachine {
return a vector of unique_ptrs that either contain the contents of the ROM from @c names that corresponds by
index, or else are @c nullptr.
*/
typedef std::function<ROM::Map(const ROM::Request &request)> ROMFetcher;
typedef std::function<ROM::Map(const ROM::Request &)> ROMFetcher;
enum class Error {
MissingROMs
MissingROMs,
};
}

View File

@ -53,7 +53,7 @@ protected:
Maps from Configurable::Display to Outputs::Display::VideoSignal and calls
@c set_display_type with the result.
*/
void set_video_signal_configurable(Configurable::Display type) {
void set_video_signal_configurable(const Configurable::Display type) {
Outputs::Display::DisplayType display_type;
switch(type) {
default:

View File

@ -25,7 +25,7 @@ namespace MachineTypes {
class TimedMachine {
public:
/// Runs the machine for @c duration seconds.
virtual void run_for(Time::Seconds duration) {
virtual void run_for(const Time::Seconds duration) {
const double cycles = (duration * clock_rate_ * speed_multiplier_) + clock_conversion_error_;
clock_conversion_error_ = std::fmod(cycles, 1.0);
run_for(Cycles(int(cycles)));
@ -36,7 +36,7 @@ public:
emulated machine to run 50% faster than a real machine. This speed-up is an emulation
fiction: it will apply across the system, including to the CRT.
*/
virtual void set_speed_multiplier(double multiplier) {
virtual void set_speed_multiplier(const double multiplier) {
if(speed_multiplier_ == multiplier) {
return;
}
@ -75,10 +75,10 @@ public:
protected:
/// Runs the machine for @c cycles.
virtual void run_for(const Cycles cycles) = 0;
virtual void run_for(const Cycles) = 0;
/// Sets this machine's clock rate.
void set_clock_rate(double clock_rate) {
void set_clock_rate(const double clock_rate) {
clock_rate_ = clock_rate;
}