# HG changeset patch # User Sam # Date 1684945492 -25200 # Node ID 9cbd9780ff6540a5cf14e76682e317892be83cd8 # Parent d6d48c7cc141e17bdba5524b1789810a6b6c59af fix: few issues with sound and resource loading diff -r d6d48c7cc141 -r 9cbd9780ff65 src/semicongine/audio.nim --- a/src/semicongine/audio.nim Wed May 24 23:00:21 2023 +0700 +++ b/src/semicongine/audio.nim Wed May 24 23:24:52 2023 +0700 @@ -9,6 +9,7 @@ import ./core import ./platform/audio +import ./resources export audiotypes @@ -35,9 +36,6 @@ buffers: seq[SoundData] currentBuffer: int -proc loadSoundResource(resourcePath: string): Sound = - assert false, "Not implemented yet" - proc initMixer*(): Mixer = result = Mixer( tracks: {"": Track(level: 1'f)}.toTable, @@ -56,7 +54,7 @@ proc loadSound*(mixer: var Mixer, name: string, resource: string) = assert not (name in mixer.sounds) - mixer.sounds[name] = loadSoundResource(resource) + mixer.sounds[name] = loadAudio(resource) proc addSound*(mixer: var Mixer, name: string, sound: Sound) = assert not (name in mixer.sounds) @@ -66,10 +64,10 @@ assert (name in mixer.sounds) mixer.sounds[name] = sound -proc addTrack*(mixer: var Mixer, name: string) = +proc addTrack*(mixer: var Mixer, name: string, level=1'f) = assert not (name in mixer.tracks) mixer.lock.withLock(): - mixer.tracks[name] = Track(level: 1'f) + mixer.tracks[name] = Track(level: level) proc play*(mixer: var Mixer, soundName: string, track="", stopOtherSounds=false, loop=false, levelLeft, levelRight: Level): uint64 = assert track in mixer.tracks diff -r d6d48c7cc141 -r 9cbd9780ff65 src/semicongine/resources.nim --- a/src/semicongine/resources.nim Wed May 24 23:00:21 2023 +0700 +++ b/src/semicongine/resources.nim Wed May 24 23:24:52 2023 +0700 @@ -1,5 +1,6 @@ import std/streams import std/strutils +import std/strformat import std/os import ./core @@ -32,6 +33,8 @@ joinPath(resourceRoot(), selectedMod) proc loadResource_intern(path: string): Stream = + if not path.fileExists(): + raise newException(Exception, &"Resource {path} not found") newFileStream(joinPath(modRoot(), path), fmRead) proc modList_intern(): seq[string] = @@ -53,6 +56,8 @@ joinPath(resourceRoot(), selectedMod) proc loadResource_intern(path: string): Stream = + if not path.fileExists(): + raise newException(Exception, &"Resource {path} not found") let archive = openZipArchive(modRoot() & ".zip") # read all here so we can close the stream result = newStringStream(archive.extractFile(path)) @@ -89,7 +94,8 @@ const bundledResources = loadResources() proc loadResource_intern(path: string): Stream = - # TODO: add Lempel–Ziv–Welch compression or something similar simple + if not (path in bundledResources[selectedMod]): + raise newException(Exception, &"Resource {path} not found") newStringStream(bundledResources[selectedMod][path]) proc modList_intern(): seq[string] =