fix various graphics and sound issues

This commit is contained in:
2025-02-27 16:51:48 -06:00
parent 1a76081fec
commit 30c5da879b
6 changed files with 1258 additions and 1228 deletions

View File

@@ -117,10 +117,7 @@ quickjs_opts += 'default_library=static'
deps += dependency('quickjs', static:true, default_options:quickjs_opts)
storefront = get_option('storefront')
if storefront == 'steam'
deps += dependency('qjs-steam',static:false)
endif
#deps += dependency('qjs-steam', static:false)
deps += dependency('qjs-layout',static:true)
deps += dependency('qjs-miniz',static:true)
@@ -135,8 +132,6 @@ deps += dependency('chipmunk', static:true)
deps += dependency('enet', static:true)
deps += dependency('soloud', static:true)
#deps += dependency('qjs-chipmunk', static:false)
sources = []
src += ['anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c','render.c','script.c','simplex.c','spline.c', 'timer.c', 'transform.c','prosperon.c', 'wildmatch.c', 'sprite.c', 'rtree.c', 'qjs_dmon.c', 'qjs_nota.c', 'qjs_enet.c', 'qjs_soloud.c']

1166
scripts/core/doc.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -18,40 +18,60 @@ Internally loads image data from disk and prepares a GPU texture. Used by graphi
Not intended for direct user calls.
*/
function create_image(path) {
var data = io.slurpbytes(path)
var newimg
switch (path.ext()) {
case 'gif':
newimg = graphics.make_gif(data)
if (newimg.surface)
newimg.texture = prosperon.gpu.load_texture(newimg.surface)
else
for (var frame of newimg.frames)
frame.texture = prosperon.gpu.load_texture(frame.surface)
break
case 'ase':
case 'aseprite':
newimg = graphics.make_aseprite(data)
if (newimg.surface)
newimg.texture = prosperon.gpu.load_texture(newimg.surface)
else {
for (var anim in newimg) {
var a = newimg[anim]
for (var frame of a.frames)
frame.texture = prosperon.gpu.load_texture(frame.surface)
try {
var data = io.slurpbytes(path);
var newimg;
switch (path.ext()) {
case 'gif':
newimg = graphics.make_gif(data);
if (newimg.surface) {
newimg.texture = prosperon.gpu.load_texture(newimg.surface);
} else {
for (var frame of newimg.frames) {
frame.texture = prosperon.gpu.load_texture(frame.surface);
}
}
}
break
default:
newimg = {
surface: graphics.make_texture(data)
}
newimg.texture = prosperon.gpu.load_texture(newimg.surface)
break
break;
case 'ase':
case 'aseprite':
newimg = graphics.make_aseprite(data);
if (newimg.surface) {
newimg.texture = prosperon.gpu.load_texture(newimg.surface);
} else {
for (var anim in newimg) {
var a = newimg[anim];
for (var frame of a.frames) {
frame.texture = prosperon.gpu.load_texture(frame.surface);
}
}
}
break;
default:
newimg = {
surface: graphics.make_texture(data)
};
newimg.texture = prosperon.gpu.load_texture(newimg.surface);
break;
}
return newimg;
} catch (e) {
// Add the path to the error message for better debugging
console.error(`Error loading image from path: ${path}`);
console.error(e.message);
if (e.stack) {
console.error(e.stack);
}
// Optionally, you can throw the error again to let it propagate
throw e;
}
return newimg
}
var image = {}
image.dimensions = function() {
return [this.texture.width, this.texture.height].scale([this.rect[2], this.rect[3]])

View File

@@ -41,8 +41,6 @@ function isRecognizedExtension(ext) {
return false
}
// Attempt to find file with or without extension from the current PATH
// (From the original resources.js, unchanged except for code style)
function find_in_path(filename, exts = []) {
if (filename.includes('.')) {
for (var dir of prosperon.PATH) {
@@ -53,10 +51,15 @@ function find_in_path(filename, exts = []) {
}
for (var dir of prosperon.PATH) {
var candidate = dir + filename
if (io.exists(candidate) && !io.is_directory(candidate)) return candidate
for (var ext of exts) {
candidate = dir + filename + '.' + ext
// Only check extensions if exts is provided and not empty
if (exts.length > 0) {
for (var ext of exts) {
var candidate = dir + filename + '.' + ext
if (io.exists(candidate) && !io.is_directory(candidate)) return candidate
}
} else {
// Fallback to extensionless file only if no extensions are specified
var candidate = dir + filename
if (io.exists(candidate) && !io.is_directory(candidate)) return candidate
}
}

View File

@@ -62,8 +62,14 @@ typedef unsigned int voice;
static Soloud *soloud;
void voice_free(unsigned int *voice)
{
Soloud_stop(soloud, *voice);
free(voice);
}
JSCLASS(Wav, Wav_destroy)
JSCLASS(voice, free)
JSCLASS(voice, voice_free)
JSCLASS(Bus, Bus_destroy)
static JSValue js_soloud_make(JSContext *js, JSValue self, int argc, JSValue *argv)