Skip to content

Commit

Permalink
Precompute the RGBA palette colors
Browse files Browse the repository at this point in the history
  • Loading branch information
robb committed Jun 10, 2018
1 parent 2da18d8 commit 8b3db5b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions NES/PPU+IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extension PPU: IO {
let mirrored = mirrorPalette(wrappedAddress)

palette[mirrored] = value
precomputedPalette[mirrored] = RGBA.from(paletteColor: value)
default:
fatalError("Attempt to wirte illegal PPU memory address \(format(address)).")
}
Expand Down
6 changes: 1 addition & 5 deletions NES/PPU+Step.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ internal extension PPU {

let mirrored = mirrorPalette(backgroundPixel)

let color = palette[mirrored]

let rgba = RGBA.from(paletteColor: color)

backBuffer[x, y] = rgba
backBuffer[x, y] = precomputedPalette[mirrored]
}

var backgroundPixel: UInt8 {
Expand Down
4 changes: 4 additions & 0 deletions NES/PPU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ internal final class PPU {
0x08, 0x3A, 0x00, 0x02, 0x00, 0x20, 0x2C, 0x08
]

var precomputedPalette: UnsafeMutableBufferPointer<RGBA>

init(mapper: Mapper, vram: Data = Data(repeating: 0x00, count: 0x800)) {
self.mapper = mapper
self.precomputedPalette = .from(source: palette.map(RGBA.from))
self.vram = .from(source: vram)
}

Expand All @@ -139,6 +142,7 @@ internal final class PPU {
frontBuffer.deallocate()
oam.deallocate()
palette.deallocate()
precomputedPalette.deallocate()
vram.deallocate()
}
}
Expand Down

0 comments on commit 8b3db5b

Please sign in to comment.