Allow compilation with threads off.
This commit is contained in:
parent
c77187fa9f
commit
5b588fddf1
4 changed files with 108 additions and 95 deletions
|
@ -75,6 +75,7 @@ proc newLoadableResource*[T: LoadableResource](
|
||||||
result.str = proc(): string = ""
|
result.str = proc(): string = ""
|
||||||
result.use_threads = use_threads
|
result.use_threads = use_threads
|
||||||
|
|
||||||
|
when compileOption("threads"):
|
||||||
# main -> thread channels
|
# main -> thread channels
|
||||||
var to_start: Channel[LoadableResource]
|
var to_start: Channel[LoadableResource]
|
||||||
# main <- thread channels
|
# main <- thread channels
|
||||||
|
@ -83,7 +84,7 @@ var to_return: Channel[(LoadableResource, bool, string, SliceMem[byte])]
|
||||||
proc start*[T: LoadableResource](self: T) =
|
proc start*[T: LoadableResource](self: T) =
|
||||||
self.status = Started
|
self.status = Started
|
||||||
if self.use_threads:
|
if self.use_threads:
|
||||||
to_start.send self
|
when compileOption("threads"): to_start.send self
|
||||||
else:
|
else:
|
||||||
self.start_func(self)
|
self.start_func(self)
|
||||||
|
|
||||||
|
@ -97,6 +98,7 @@ proc onload*[T: LoadableResource](self: T, ok: bool, err: string, data = SliceMe
|
||||||
# self.result[] = (ok, err, data)
|
# self.result[] = (ok, err, data)
|
||||||
if self.onload_func != nil:
|
if self.onload_func != nil:
|
||||||
if self.use_threads:
|
if self.use_threads:
|
||||||
|
when compileOption("threads"):
|
||||||
to_return.send((self.LoadableResource, ok, err, data))
|
to_return.send((self.LoadableResource, ok, err, data))
|
||||||
else:
|
else:
|
||||||
self.onload_func(ok, err, data)
|
self.onload_func(ok, err, data)
|
||||||
|
@ -124,6 +126,7 @@ proc cancel*[T: LoadableResource](self: T) =
|
||||||
# results.add res.result[]
|
# results.add res.result[]
|
||||||
# res.result = nil
|
# res.result = nil
|
||||||
|
|
||||||
|
when compileOption("threads"):
|
||||||
var worker: Thread[void]
|
var worker: Thread[void]
|
||||||
proc workerThreadProc() {.thread.} =
|
proc workerThreadProc() {.thread.} =
|
||||||
while true:
|
while true:
|
||||||
|
@ -246,7 +249,10 @@ proc loadUri*(
|
||||||
var start_func: proc(self: LoadableResource)
|
var start_func: proc(self: LoadableResource)
|
||||||
var self: Fetch
|
var self: Fetch
|
||||||
var uri = uri
|
var uri = uri
|
||||||
|
when compileOption("threads"):
|
||||||
var use_threads = use_threads
|
var use_threads = use_threads
|
||||||
|
else:
|
||||||
|
var use_threads = false
|
||||||
when not defined(onlyLocalFiles):
|
when not defined(onlyLocalFiles):
|
||||||
when defined(emscripten):
|
when defined(emscripten):
|
||||||
const is_remote = true
|
const is_remote = true
|
||||||
|
|
|
@ -367,6 +367,7 @@ proc loadOptimized*(tex: Texture, slices: seq[SliceMem[byte]],
|
||||||
, flip = flip, min_channels = min_channels)
|
, flip = flip, min_channels = min_channels)
|
||||||
|
|
||||||
|
|
||||||
|
when compileOption("threads"):
|
||||||
# main -> thread channels
|
# main -> thread channels
|
||||||
type DecodeChanMsg = tuple[
|
type DecodeChanMsg = tuple[
|
||||||
tex: Texture, slices: seq[SliceMem[byte]],
|
tex: Texture, slices: seq[SliceMem[byte]],
|
||||||
|
@ -392,7 +393,7 @@ proc loadOptimizedThreaded*(tex: Texture, slices: seq[SliceMem[byte]],
|
||||||
callback_compressed: CallbackCompressed = nil,
|
callback_compressed: CallbackCompressed = nil,
|
||||||
flip = true, min_channels = 0) =
|
flip = true, min_channels = 0) =
|
||||||
|
|
||||||
when false:
|
when not compileOption("threads"):
|
||||||
loadOptimized(tex, slices, callback_uncompressed, callback_compressed, flip, min_channels)
|
loadOptimized(tex, slices, callback_uncompressed, callback_compressed, flip, min_channels)
|
||||||
else:
|
else:
|
||||||
decode_chan.send((tex: tex, slices: slices,
|
decode_chan.send((tex: tex, slices: slices,
|
||||||
|
@ -400,6 +401,7 @@ proc loadOptimizedThreaded*(tex: Texture, slices: seq[SliceMem[byte]],
|
||||||
callback_compressed: callback_compressed,
|
callback_compressed: callback_compressed,
|
||||||
flip: flip, min_channels: min_channels))
|
flip: flip, min_channels: min_channels))
|
||||||
|
|
||||||
|
when compileOption("threads"):
|
||||||
var workers = newSeq[Thread[void]](myouEngineNumTextureThreads)
|
var workers = newSeq[Thread[void]](myouEngineNumTextureThreads)
|
||||||
proc workerThreadProc() {.thread.} =
|
proc workerThreadProc() {.thread.} =
|
||||||
# TODO: handle errors
|
# TODO: handle errors
|
||||||
|
|
|
@ -77,6 +77,7 @@ import ./screen
|
||||||
import ./platform/platform
|
import ./platform/platform
|
||||||
import ./loaders/blend
|
import ./loaders/blend
|
||||||
import ./util
|
import ./util
|
||||||
|
when compileOption("threads"):
|
||||||
from loadable import updateLoadableWorkerThreads
|
from loadable import updateLoadableWorkerThreads
|
||||||
from ./gpu_formats/texture_optimize import updateTextureWorkerThreads
|
from ./gpu_formats/texture_optimize import updateTextureWorkerThreads
|
||||||
import arr_ref
|
import arr_ref
|
||||||
|
@ -167,6 +168,8 @@ proc myou_main_loop*(self: MyouEngine) =
|
||||||
##
|
##
|
||||||
## You usually don't need to call this. Use `run <#run,MyouEngine>`_
|
## You usually don't need to call this. Use `run <#run,MyouEngine>`_
|
||||||
## instead.
|
## instead.
|
||||||
|
self.renderer.unbind_all_ubos()
|
||||||
|
when compileOption("threads"):
|
||||||
updateTextureWorkerThreads()
|
updateTextureWorkerThreads()
|
||||||
updateLoadableWorkerThreads()
|
updateLoadableWorkerThreads()
|
||||||
# TODO: make a table object that can be iterated while changing, e.g. with a
|
# TODO: make a table object that can be iterated while changing, e.g. with a
|
||||||
|
|
|
@ -46,6 +46,7 @@ import ../screen
|
||||||
import ../util
|
import ../util
|
||||||
import ../graphics/render
|
import ../graphics/render
|
||||||
import ../input
|
import ../input
|
||||||
|
when compileOption("threads"):
|
||||||
from loadable import terminateLoadableWorkerThreads
|
from loadable import terminateLoadableWorkerThreads
|
||||||
from ../gpu_formats/texture_optimize import terminateTextureWorkerThreads
|
from ../gpu_formats/texture_optimize import terminateTextureWorkerThreads
|
||||||
|
|
||||||
|
@ -234,6 +235,7 @@ proc start_platform_main_loop*(engine: MyouEngine, main_loop: proc(self: MyouEng
|
||||||
for i in 0 ..< window.screen.frame_interval:
|
for i in 0 ..< window.screen.frame_interval:
|
||||||
window.swapBuffers()
|
window.swapBuffers()
|
||||||
glfw.pollEvents()
|
glfw.pollEvents()
|
||||||
|
when compileOption("threads"):
|
||||||
terminateLoadableWorkerThreads()
|
terminateLoadableWorkerThreads()
|
||||||
terminateTextureWorkerThreads()
|
terminateTextureWorkerThreads()
|
||||||
glfw.terminate()
|
glfw.terminate()
|
||||||
|
|
Loading…
Reference in a new issue