mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-09 21:29:53 +00:00
Merge pull request #30 from TomHarte/PointerIdioms
Adds minor reference and pointer style improvements
This commit is contained in:
commit
e9bf9034e3
@ -60,7 +60,7 @@ Machine::Machine() :
|
|||||||
|
|
||||||
void Machine::setup_output(float aspect_ratio)
|
void Machine::setup_output(float aspect_ratio)
|
||||||
{
|
{
|
||||||
_crt = std::unique_ptr<Outputs::CRT::CRT>(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1));
|
_crt.reset(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1));
|
||||||
_crt->set_rgb_sampling_function(
|
_crt->set_rgb_sampling_function(
|
||||||
"vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)"
|
"vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)"
|
||||||
"{"
|
"{"
|
||||||
@ -927,7 +927,7 @@ inline void Tape::get_next_tape_pulse()
|
|||||||
}
|
}
|
||||||
if(_input.pulse_stepper == nullptr || _input.current_pulse.length.clock_rate != _input.pulse_stepper->get_output_rate())
|
if(_input.pulse_stepper == nullptr || _input.current_pulse.length.clock_rate != _input.pulse_stepper->get_output_rate())
|
||||||
{
|
{
|
||||||
_input.pulse_stepper = std::unique_ptr<SignalProcessing::Stepper>(new SignalProcessing::Stepper(_input.current_pulse.length.clock_rate, 2000000));
|
_input.pulse_stepper.reset(new SignalProcessing::Stepper(_input.current_pulse.length.clock_rate, 2000000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class TypeRecipient: public Typer::Delegate {
|
|||||||
public:
|
public:
|
||||||
void set_typer_for_string(const char *string)
|
void set_typer_for_string(const char *string)
|
||||||
{
|
{
|
||||||
_typer = std::unique_ptr<Typer>(new Typer(string, get_typer_delay(), get_typer_frequency(), this));
|
_typer.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -98,7 +98,7 @@ void Machine::mos6522_did_change_interrupt_status(void *mos6522)
|
|||||||
|
|
||||||
void Machine::setup_output(float aspect_ratio)
|
void Machine::setup_output(float aspect_ratio)
|
||||||
{
|
{
|
||||||
_mos6560 = std::unique_ptr<MOS::MOS6560>(new MOS::MOS6560());
|
_mos6560.reset(new MOS::MOS6560());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data)
|
void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data)
|
||||||
|
@ -11,8 +11,10 @@ import Cocoa
|
|||||||
class Atari2600Document: MachineDocument {
|
class Atari2600Document: MachineDocument {
|
||||||
|
|
||||||
private var atari2600 = CSAtari2600()
|
private var atari2600 = CSAtari2600()
|
||||||
override func machine() -> CSMachine? {
|
override var machine: CSMachine! {
|
||||||
return atari2600
|
get {
|
||||||
|
return atari2600
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: NSDocument overrides
|
// MARK: NSDocument overrides
|
||||||
|
@ -12,8 +12,10 @@ import AudioToolbox
|
|||||||
class ElectronDocument: MachineDocument {
|
class ElectronDocument: MachineDocument {
|
||||||
|
|
||||||
private lazy var electron = CSElectron()
|
private lazy var electron = CSElectron()
|
||||||
override func machine() -> CSMachine! {
|
override var machine: CSMachine! {
|
||||||
return electron
|
get {
|
||||||
|
return electron
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func aspectRatio() -> NSSize {
|
override func aspectRatio() -> NSSize {
|
||||||
|
@ -20,8 +20,10 @@ class MachineDocument:
|
|||||||
{
|
{
|
||||||
lazy var actionLock = NSLock()
|
lazy var actionLock = NSLock()
|
||||||
lazy var drawLock = NSLock()
|
lazy var drawLock = NSLock()
|
||||||
func machine() -> CSMachine! {
|
var machine: CSMachine! {
|
||||||
return nil
|
get {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func aspectRatio() -> NSSize {
|
func aspectRatio() -> NSSize {
|
||||||
@ -54,11 +56,11 @@ class MachineDocument:
|
|||||||
let displayAspectRatio = self.aspectRatio()
|
let displayAspectRatio = self.aspectRatio()
|
||||||
aController.window?.contentAspectRatio = displayAspectRatio
|
aController.window?.contentAspectRatio = displayAspectRatio
|
||||||
openGLView.performWithGLContext({
|
openGLView.performWithGLContext({
|
||||||
self.machine().setView(self.openGLView, aspectRatio: Float(displayAspectRatio.width / displayAspectRatio.height))
|
self.machine.setView(self.openGLView, aspectRatio: Float(displayAspectRatio.width / displayAspectRatio.height))
|
||||||
})
|
})
|
||||||
|
|
||||||
setupClockRate()
|
setupClockRate()
|
||||||
self.machine().delegate = self
|
self.machine.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
func machineDidChangeClockRate(machine: CSMachine!) {
|
func machineDidChangeClockRate(machine: CSMachine!) {
|
||||||
@ -68,15 +70,15 @@ class MachineDocument:
|
|||||||
private func setupClockRate() {
|
private func setupClockRate() {
|
||||||
// establish and provide the audio queue, taking advice as to an appropriate sampling rate
|
// establish and provide the audio queue, taking advice as to an appropriate sampling rate
|
||||||
let maximumSamplingRate = CSAudioQueue.preferredSamplingRate()
|
let maximumSamplingRate = CSAudioQueue.preferredSamplingRate()
|
||||||
let selectedSamplingRate = self.machine().idealSamplingRateFromRange(NSRange(location: 0, length: NSInteger(maximumSamplingRate)))
|
let selectedSamplingRate = self.machine.idealSamplingRateFromRange(NSRange(location: 0, length: NSInteger(maximumSamplingRate)))
|
||||||
if selectedSamplingRate > 0 {
|
if selectedSamplingRate > 0 {
|
||||||
audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate))
|
audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate))
|
||||||
audioQueue.delegate = self
|
audioQueue.delegate = self
|
||||||
self.machine().audioQueue = self.audioQueue
|
self.machine.audioQueue = self.audioQueue
|
||||||
self.machine().setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.bufferSize / 2)
|
self.machine.setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.bufferSize / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.bestEffortUpdater.clockRate = self.machine().clockRate
|
self.bestEffortUpdater.clockRate = self.machine.clockRate
|
||||||
}
|
}
|
||||||
|
|
||||||
override func close() {
|
override func close() {
|
||||||
@ -94,7 +96,7 @@ class MachineDocument:
|
|||||||
func paste(sender: AnyObject!) {
|
func paste(sender: AnyObject!) {
|
||||||
let pasteboard = NSPasteboard.generalPasteboard()
|
let pasteboard = NSPasteboard.generalPasteboard()
|
||||||
if let string = pasteboard.stringForType(NSPasteboardTypeString) {
|
if let string = pasteboard.stringForType(NSPasteboardTypeString) {
|
||||||
self.machine().paste(string)
|
self.machine.paste(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +108,7 @@ class MachineDocument:
|
|||||||
func runForNumberOfCycles(numberOfCycles: Int32) {
|
func runForNumberOfCycles(numberOfCycles: Int32) {
|
||||||
let cyclesToRunFor = min(numberOfCycles, Int32(bestEffortUpdater.clockRate / 10))
|
let cyclesToRunFor = min(numberOfCycles, Int32(bestEffortUpdater.clockRate / 10))
|
||||||
if actionLock.tryLock() {
|
if actionLock.tryLock() {
|
||||||
self.machine().runForNumberOfCycles(cyclesToRunFor)
|
self.machine.runForNumberOfCycles(cyclesToRunFor)
|
||||||
actionLock.unlock()
|
actionLock.unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +131,7 @@ class MachineDocument:
|
|||||||
final func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
|
final func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
|
||||||
bestEffortUpdater.update()
|
bestEffortUpdater.update()
|
||||||
if drawLock.tryLock() {
|
if drawLock.tryLock() {
|
||||||
self.machine().drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
|
self.machine.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
|
||||||
drawLock.unlock()
|
drawLock.unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +143,7 @@ class MachineDocument:
|
|||||||
|
|
||||||
// MARK: Key forwarding
|
// MARK: Key forwarding
|
||||||
private func withKeyboardMachine(action: (CSKeyboardMachine) -> ()) {
|
private func withKeyboardMachine(action: (CSKeyboardMachine) -> ()) {
|
||||||
if let keyboardMachine = self.machine() as? CSKeyboardMachine {
|
if let keyboardMachine = self.machine as? CSKeyboardMachine {
|
||||||
action(keyboardMachine)
|
action(keyboardMachine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,10 @@ import Foundation
|
|||||||
class Vic20Document: MachineDocument {
|
class Vic20Document: MachineDocument {
|
||||||
|
|
||||||
private lazy var vic20 = CSVic20()
|
private lazy var vic20 = CSVic20()
|
||||||
override func machine() -> CSMachine! {
|
override var machine: CSMachine! {
|
||||||
return vic20
|
get {
|
||||||
|
return vic20
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: NSDocument overrides
|
// MARK: NSDocument overrides
|
||||||
|
@ -38,8 +38,8 @@ void CRT::set_new_timing(unsigned int cycles_per_line, unsigned int height_of_di
|
|||||||
_sync_capacitor_charge_threshold = (int)(syncCapacityLineChargeThreshold * _cycles_per_line);
|
_sync_capacitor_charge_threshold = (int)(syncCapacityLineChargeThreshold * _cycles_per_line);
|
||||||
|
|
||||||
// create the two flywheels
|
// create the two flywheels
|
||||||
_horizontal_flywheel = std::unique_ptr<Flywheel>(new Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6, _cycles_per_line >> 6));
|
_horizontal_flywheel.reset(new Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6, _cycles_per_line >> 6));
|
||||||
_vertical_flywheel = std::unique_ptr<Flywheel>(new Flywheel(_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * _cycles_per_line, (_cycles_per_line * height_of_display) >> 3));
|
_vertical_flywheel.reset(new Flywheel(_cycles_per_line * height_of_display, scanlinesVerticalRetraceTime * _cycles_per_line, (_cycles_per_line * height_of_display) >> 3));
|
||||||
|
|
||||||
// figure out the divisor necessary to get the horizontal flywheel into a 16-bit range
|
// figure out the divisor necessary to get the horizontal flywheel into a 16-bit range
|
||||||
unsigned int real_clock_scan_period = (_cycles_per_line * height_of_display) / (_time_multiplier * _common_output_divisor);
|
unsigned int real_clock_scan_period = (_cycles_per_line * height_of_display) / (_time_multiplier * _common_output_divisor);
|
||||||
@ -73,13 +73,13 @@ CRT::CRT(unsigned int common_output_divisor) :
|
|||||||
|
|
||||||
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int buffer_depth) : CRT(common_output_divisor)
|
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, unsigned int height_of_display, ColourSpace colour_space, unsigned int colour_cycle_numerator, unsigned int colour_cycle_denominator, unsigned int buffer_depth) : CRT(common_output_divisor)
|
||||||
{
|
{
|
||||||
_openGL_output_builder = std::unique_ptr<OpenGLOutputBuilder>(new OpenGLOutputBuilder(buffer_depth));
|
_openGL_output_builder.reset(new OpenGLOutputBuilder(buffer_depth));
|
||||||
set_new_timing(cycles_per_line, height_of_display, colour_space, colour_cycle_numerator, colour_cycle_denominator);
|
set_new_timing(cycles_per_line, height_of_display, colour_space, colour_cycle_numerator, colour_cycle_denominator);
|
||||||
}
|
}
|
||||||
|
|
||||||
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, DisplayType displayType, unsigned int buffer_depth) : CRT(common_output_divisor)
|
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, DisplayType displayType, unsigned int buffer_depth) : CRT(common_output_divisor)
|
||||||
{
|
{
|
||||||
_openGL_output_builder = std::unique_ptr<OpenGLOutputBuilder>(new OpenGLOutputBuilder(buffer_depth));
|
_openGL_output_builder.reset(new OpenGLOutputBuilder(buffer_depth));
|
||||||
set_new_display_type(cycles_per_line, displayType);
|
set_new_display_type(cycles_per_line, displayType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,16 +122,16 @@ OpenGLOutputBuilder::OpenGLOutputBuilder(unsigned int buffer_depth) :
|
|||||||
_last_output_height(0),
|
_last_output_height(0),
|
||||||
_fence(nullptr)
|
_fence(nullptr)
|
||||||
{
|
{
|
||||||
_buffer_builder = std::unique_ptr<CRTInputBufferBuilder>(new CRTInputBufferBuilder(buffer_depth));
|
_buffer_builder.reset(new CRTInputBufferBuilder(buffer_depth));
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_CONSTANT_COLOR);
|
glBlendFunc(GL_SRC_ALPHA, GL_CONSTANT_COLOR);
|
||||||
glBlendColor(0.6f, 0.6f, 0.6f, 1.0f);
|
glBlendColor(0.6f, 0.6f, 0.6f, 1.0f);
|
||||||
|
|
||||||
// Create intermediate textures and bind to slots 0, 1 and 2
|
// Create intermediate textures and bind to slots 0, 1 and 2
|
||||||
compositeTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, composite_texture_unit));
|
compositeTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, composite_texture_unit));
|
||||||
separatedTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, separated_texture_unit));
|
separatedTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, separated_texture_unit));
|
||||||
filteredYTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_y_texture_unit));
|
filteredYTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_y_texture_unit));
|
||||||
filteredTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_texture_unit));
|
filteredTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_texture_unit));
|
||||||
|
|
||||||
// create the surce texture
|
// create the surce texture
|
||||||
glGenTextures(1, &textureName);
|
glGenTextures(1, &textureName);
|
||||||
@ -199,7 +199,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
|||||||
// make sure there's a target to draw to
|
// make sure there's a target to draw to
|
||||||
if(!framebuffer || framebuffer->get_height() != output_height || framebuffer->get_width() != output_width)
|
if(!framebuffer || framebuffer->get_height() != output_height || framebuffer->get_width() != output_width)
|
||||||
{
|
{
|
||||||
std::unique_ptr<OpenGL::TextureTarget> new_framebuffer = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget((GLsizei)output_width, (GLsizei)output_height, pixel_accumulation_texture_unit));
|
std::unique_ptr<OpenGL::TextureTarget> new_framebuffer(new OpenGL::TextureTarget((GLsizei)output_width, (GLsizei)output_height, pixel_accumulation_texture_unit));
|
||||||
if(framebuffer)
|
if(framebuffer)
|
||||||
{
|
{
|
||||||
new_framebuffer->bind_framebuffer();
|
new_framebuffer->bind_framebuffer();
|
||||||
|
@ -86,7 +86,7 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_shader(const char *
|
|||||||
"gl_Position = vec4(eyePosition, 0.0, 1.0);"
|
"gl_Position = vec4(eyePosition, 0.0, 1.0);"
|
||||||
"}", sampler_type, input_variable);
|
"}", sampler_type, input_variable);
|
||||||
|
|
||||||
std::unique_ptr<IntermediateShader> shader = std::unique_ptr<IntermediateShader>(new IntermediateShader(vertex_shader, fragment_shader, bindings));
|
std::unique_ptr<IntermediateShader> shader(new IntermediateShader(vertex_shader, fragment_shader, bindings));
|
||||||
free(vertex_shader);
|
free(vertex_shader);
|
||||||
|
|
||||||
return shader;
|
return shader;
|
||||||
|
@ -82,7 +82,7 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
|
|||||||
"}",
|
"}",
|
||||||
sampler_type, fragment_methods, colour_expression);
|
sampler_type, fragment_methods, colour_expression);
|
||||||
|
|
||||||
std::unique_ptr<OutputShader> result = std::unique_ptr<OutputShader>(new OutputShader(vertex_shader, fragment_shader, bindings));
|
std::unique_ptr<OutputShader> result(new OutputShader(vertex_shader, fragment_shader, bindings));
|
||||||
free(vertex_shader);
|
free(vertex_shader);
|
||||||
free(fragment_shader);
|
free(fragment_shader);
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void TextureTarget::draw(float aspect_ratio)
|
|||||||
"{"
|
"{"
|
||||||
"fragColour = texture(texID, texCoordVarying);"
|
"fragColour = texture(texID, texCoordVarying);"
|
||||||
"}";
|
"}";
|
||||||
_pixel_shader = std::unique_ptr<Shader>(new Shader(vertex_shader, fragment_shader, nullptr));
|
_pixel_shader.reset(new Shader(vertex_shader, fragment_shader, nullptr));
|
||||||
_pixel_shader->bind();
|
_pixel_shader->bind();
|
||||||
|
|
||||||
glGenVertexArrays(1, &_drawing_vertex_array);
|
glGenVertexArrays(1, &_drawing_vertex_array);
|
||||||
|
@ -41,7 +41,7 @@ class Speaker {
|
|||||||
_output_cycles_per_second = cycles_per_second;
|
_output_cycles_per_second = cycles_per_second;
|
||||||
if(_buffer_size != buffer_size)
|
if(_buffer_size != buffer_size)
|
||||||
{
|
{
|
||||||
_buffer_in_progress = std::unique_ptr<int16_t>(new int16_t[buffer_size]);
|
_buffer_in_progress.reset(new int16_t[buffer_size]);
|
||||||
_buffer_size = buffer_size;
|
_buffer_size = buffer_size;
|
||||||
}
|
}
|
||||||
set_needs_updated_filter_coefficients();
|
set_needs_updated_filter_coefficients();
|
||||||
@ -189,10 +189,10 @@ template <class T> class Filter: public Speaker {
|
|||||||
_coefficients_are_dirty = false;
|
_coefficients_are_dirty = false;
|
||||||
_buffer_in_progress_pointer = 0;
|
_buffer_in_progress_pointer = 0;
|
||||||
|
|
||||||
_stepper = std::unique_ptr<SignalProcessing::Stepper>(new SignalProcessing::Stepper((uint64_t)_input_cycles_per_second, (uint64_t)_output_cycles_per_second));
|
_stepper.reset(new SignalProcessing::Stepper((uint64_t)_input_cycles_per_second, (uint64_t)_output_cycles_per_second));
|
||||||
_filter = std::unique_ptr<SignalProcessing::FIRFilter>(new SignalProcessing::FIRFilter((unsigned int)_number_of_taps, (float)_input_cycles_per_second, 0.0, (float)_output_cycles_per_second / 2.0f, SignalProcessing::FIRFilter::DefaultAttenuation));
|
_filter.reset(new SignalProcessing::FIRFilter((unsigned int)_number_of_taps, (float)_input_cycles_per_second, 0.0, (float)_output_cycles_per_second / 2.0f, SignalProcessing::FIRFilter::DefaultAttenuation));
|
||||||
|
|
||||||
_input_buffer = std::unique_ptr<int16_t>(new int16_t[_number_of_taps]);
|
_input_buffer.reset(new int16_t[_number_of_taps]);
|
||||||
_input_buffer_depth = 0;
|
_input_buffer_depth = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user