1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Merge pull request #30 from TomHarte/PointerIdioms

Adds minor reference and pointer style improvements
This commit is contained in:
Thomas Harte 2016-06-23 21:10:45 -04:00 committed by GitHub
commit e9bf9034e3
13 changed files with 47 additions and 39 deletions

View File

@ -60,7 +60,7 @@ Machine::Machine() :
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(
"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())
{
_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));
}
}

View File

@ -39,7 +39,7 @@ class TypeRecipient: public Typer::Delegate {
public:
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:

View File

@ -98,7 +98,7 @@ void Machine::mos6522_did_change_interrupt_status(void *mos6522)
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)

View File

@ -11,8 +11,10 @@ import Cocoa
class Atari2600Document: MachineDocument {
private var atari2600 = CSAtari2600()
override func machine() -> CSMachine? {
return atari2600
override var machine: CSMachine! {
get {
return atari2600
}
}
// MARK: NSDocument overrides

View File

@ -12,8 +12,10 @@ import AudioToolbox
class ElectronDocument: MachineDocument {
private lazy var electron = CSElectron()
override func machine() -> CSMachine! {
return electron
override var machine: CSMachine! {
get {
return electron
}
}
override func aspectRatio() -> NSSize {

View File

@ -20,8 +20,10 @@ class MachineDocument:
{
lazy var actionLock = NSLock()
lazy var drawLock = NSLock()
func machine() -> CSMachine! {
return nil
var machine: CSMachine! {
get {
return nil
}
}
func aspectRatio() -> NSSize {
@ -54,11 +56,11 @@ class MachineDocument:
let displayAspectRatio = self.aspectRatio()
aController.window?.contentAspectRatio = displayAspectRatio
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()
self.machine().delegate = self
self.machine.delegate = self
}
func machineDidChangeClockRate(machine: CSMachine!) {
@ -68,15 +70,15 @@ class MachineDocument:
private func setupClockRate() {
// establish and provide the audio queue, taking advice as to an appropriate sampling rate
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 {
audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate))
audioQueue.delegate = self
self.machine().audioQueue = self.audioQueue
self.machine().setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.bufferSize / 2)
self.machine.audioQueue = self.audioQueue
self.machine.setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.bufferSize / 2)
}
self.bestEffortUpdater.clockRate = self.machine().clockRate
self.bestEffortUpdater.clockRate = self.machine.clockRate
}
override func close() {
@ -94,7 +96,7 @@ class MachineDocument:
func paste(sender: AnyObject!) {
let pasteboard = NSPasteboard.generalPasteboard()
if let string = pasteboard.stringForType(NSPasteboardTypeString) {
self.machine().paste(string)
self.machine.paste(string)
}
}
@ -106,7 +108,7 @@ class MachineDocument:
func runForNumberOfCycles(numberOfCycles: Int32) {
let cyclesToRunFor = min(numberOfCycles, Int32(bestEffortUpdater.clockRate / 10))
if actionLock.tryLock() {
self.machine().runForNumberOfCycles(cyclesToRunFor)
self.machine.runForNumberOfCycles(cyclesToRunFor)
actionLock.unlock()
}
}
@ -129,7 +131,7 @@ class MachineDocument:
final func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
bestEffortUpdater.update()
if drawLock.tryLock() {
self.machine().drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
self.machine.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
drawLock.unlock()
}
}
@ -141,7 +143,7 @@ class MachineDocument:
// MARK: Key forwarding
private func withKeyboardMachine(action: (CSKeyboardMachine) -> ()) {
if let keyboardMachine = self.machine() as? CSKeyboardMachine {
if let keyboardMachine = self.machine as? CSKeyboardMachine {
action(keyboardMachine)
}
}

View File

@ -11,8 +11,10 @@ import Foundation
class Vic20Document: MachineDocument {
private lazy var vic20 = CSVic20()
override func machine() -> CSMachine! {
return vic20
override var machine: CSMachine! {
get {
return vic20
}
}
// MARK: NSDocument overrides

View File

@ -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);
// create the two flywheels
_horizontal_flywheel = std::unique_ptr<Flywheel>(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));
_horizontal_flywheel.reset(new Flywheel(_cycles_per_line, (millisecondsHorizontalRetraceTime * _cycles_per_line) >> 6, _cycles_per_line >> 6));
_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
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)
{
_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);
}
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);
}

View File

@ -122,16 +122,16 @@ OpenGLOutputBuilder::OpenGLOutputBuilder(unsigned int buffer_depth) :
_last_output_height(0),
_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);
glBlendColor(0.6f, 0.6f, 0.6f, 1.0f);
// 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));
separatedTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, separated_texture_unit));
filteredYTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_y_texture_unit));
filteredTexture = std::unique_ptr<OpenGL::TextureTarget>(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_texture_unit));
compositeTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, composite_texture_unit));
separatedTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, separated_texture_unit));
filteredYTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_y_texture_unit));
filteredTexture.reset(new OpenGL::TextureTarget(IntermediateBufferWidth, IntermediateBufferHeight, filtered_texture_unit));
// create the surce texture
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
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)
{
new_framebuffer->bind_framebuffer();

View File

@ -86,7 +86,7 @@ std::unique_ptr<IntermediateShader> IntermediateShader::make_shader(const char *
"gl_Position = vec4(eyePosition, 0.0, 1.0);"
"}", 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);
return shader;

View File

@ -82,7 +82,7 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
"}",
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(fragment_shader);

View File

@ -89,7 +89,7 @@ void TextureTarget::draw(float aspect_ratio)
"{"
"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();
glGenVertexArrays(1, &_drawing_vertex_array);

View File

@ -41,7 +41,7 @@ class Speaker {
_output_cycles_per_second = cycles_per_second;
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;
}
set_needs_updated_filter_coefficients();
@ -189,10 +189,10 @@ template <class T> class Filter: public Speaker {
_coefficients_are_dirty = false;
_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));
_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));
_stepper.reset(new SignalProcessing::Stepper((uint64_t)_input_cycles_per_second, (uint64_t)_output_cycles_per_second));
_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;
}
};