# HG changeset patch # User Sam # Date 1684945492 -25200 # Node ID f52bac7a1c7323879aa4c813299c85a7603fc28a # Parent 76af5ffc0cb58f6d105f50d22f65d429409996fa fix: few issues with sound and resource loading diff -r 76af5ffc0cb5 -r f52bac7a1c73 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 76af5ffc0cb5 -r f52bac7a1c73 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] =