-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04ab7ac
commit 0502a4c
Showing
7 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// ConcurrentRenderer.swift | ||
// Rampage | ||
// | ||
// Created by Nick Lockwood on 09/08/2019. | ||
// Copyright © 2019 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Engine | ||
import Renderer | ||
|
||
public extension Bitmap { | ||
init(width: Int, height: Int, world: World, textures: Textures) { | ||
let cpuCores = ProcessInfo.processInfo.activeProcessorCount | ||
var buffers = Array(repeating: [Color](), count: cpuCores) | ||
let step = 1.0 / Double(cpuCores) | ||
DispatchQueue.concurrentPerform(iterations: cpuCores) { i in | ||
let offset = Double(i) * step | ||
let range = offset ..< offset + step | ||
var renderer = Renderer( | ||
width: width, | ||
height: height, | ||
range: range, | ||
textures: textures | ||
) | ||
renderer.draw(world) | ||
buffers[i] = renderer.bitmap.pixels | ||
} | ||
let pixels = Array(buffers.joined()) | ||
self.init(height: height, pixels: pixels) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters