correct pixelformat bug
This commit is contained in:
@@ -159,8 +159,11 @@ function create_image(path){
|
|||||||
let raw = decode_image(bytes, path.ext());
|
let raw = decode_image(bytes, path.ext());
|
||||||
|
|
||||||
/* ── Case A: static image ─────────────────────────────────── */
|
/* ── Case A: static image ─────────────────────────────────── */
|
||||||
if(raw.surface)
|
if(raw.surface) {
|
||||||
|
console.log("STATIC!")
|
||||||
|
console.log(json.encode(raw.surface))
|
||||||
return make_handle(raw.surface);
|
return make_handle(raw.surface);
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Case B: GIF helpers returned array [surf, …] ─────────── */
|
/* ── Case B: GIF helpers returned array [surf, …] ─────────── */
|
||||||
if(Array.isArray(raw))
|
if(Array.isArray(raw))
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
var input = this
|
|
||||||
|
|
||||||
input.mouse_show[prosperon.DOC] = `Show or hide the mouse cursor. Pass true to show, false to hide.
|
|
||||||
|
|
||||||
:param show: Boolean. True to show, false to hide.
|
|
||||||
:return: None
|
|
||||||
`
|
|
||||||
|
|
||||||
input.mouse_lock[prosperon.DOC] = `Capture or release the mouse, confining it within the window if locked.
|
|
||||||
|
|
||||||
:param lock: Boolean. True to lock, false to unlock.
|
|
||||||
:return: None
|
|
||||||
`
|
|
||||||
|
|
||||||
input.keyname[prosperon.DOC] = `Given a numeric keycode, return the corresponding key name (e.g., from SDL).
|
|
||||||
|
|
||||||
:param keycode: A numeric SDL keycode.
|
|
||||||
:return: A string with the key name.
|
|
||||||
`
|
|
||||||
|
|
||||||
input.keymod[prosperon.DOC] = `Return an object describing the current modifier keys, e.g. {shift:true, ctrl:true}.
|
|
||||||
|
|
||||||
:return: An object with boolean fields for each modifier key.
|
|
||||||
`
|
|
||||||
|
|
||||||
input.mousestate[prosperon.DOC] = `Return an object describing the current mouse state, including x,y coordinates
|
|
||||||
and booleans for pressed buttons (left, middle, right, x1, x2).
|
|
||||||
|
|
||||||
:return: Object { x, y, left, middle, right, x1, x2 }
|
|
||||||
`
|
|
||||||
|
|
||||||
return input
|
|
||||||
@@ -16,53 +16,81 @@ if (!delay.name || (delay.name !== 'delay' && !delay.name.includes('delay'))) {
|
|||||||
|
|
||||||
var os = use('os');
|
var os = use('os');
|
||||||
var io = use('io');
|
var io = use('io');
|
||||||
var render = use('render');
|
|
||||||
var transform = use('transform');
|
var transform = use('transform');
|
||||||
|
|
||||||
var gameConfig = {};
|
var draw2d
|
||||||
var gameDir = "";
|
var graphics
|
||||||
|
|
||||||
// Framework initialization
|
var video_actor = use('sdl_video')
|
||||||
function initialize() {
|
|
||||||
var configPath = `config.js`;
|
|
||||||
if (io.exists(configPath))
|
|
||||||
gameConfig = use(configPath);
|
|
||||||
|
|
||||||
// Set up default config values
|
var window
|
||||||
gameConfig.resolution = gameConfig.resolution || { width: 640, height: 480 };
|
var render
|
||||||
gameConfig.internal_resolution = gameConfig.internal_resolution || gameConfig.resolution;
|
|
||||||
gameConfig.title = gameConfig.title || "Moth Game";
|
|
||||||
gameConfig.fps = gameConfig.fps || 60;
|
|
||||||
gameConfig.clearColor = gameConfig.clearColor || [0, 0, 0, 1];
|
|
||||||
|
|
||||||
// Initialize render system
|
var gameConfig = arg[1] || {};
|
||||||
render.initialize({
|
|
||||||
width: gameConfig.resolution.width,
|
|
||||||
height: gameConfig.resolution.height,
|
|
||||||
resolution_x: gameConfig.internal_resolution.width,
|
|
||||||
resolution_y: gameConfig.internal_resolution.height,
|
|
||||||
mode: gameConfig.mode || 'letterbox'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up default camera
|
send(video_actor, {
|
||||||
gameConfig.camera = gameConfig.camera || {
|
kind: "window",
|
||||||
size: [gameConfig.internal_resolution.width, gameConfig.internal_resolution.height],
|
op:"create",
|
||||||
transform: new transform,
|
data: gameConfig
|
||||||
fov: 50,
|
}, e => {
|
||||||
near_z: 0,
|
if (e.error) {
|
||||||
far_z: 1000,
|
console.error(e.error)
|
||||||
surface: undefined,
|
os.exit(1)
|
||||||
viewport: {x: 0, y: 0, width: 1, height: 1},
|
}
|
||||||
ortho: true,
|
|
||||||
anchor: [0, 0]
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set window title
|
window = e.id
|
||||||
prosperon.window.title = gameConfig.title;
|
|
||||||
|
send(video_actor,{
|
||||||
|
kind:"window",
|
||||||
|
op:"makeRenderer",
|
||||||
|
id:window
|
||||||
|
}, e => {
|
||||||
|
if (e.error) {
|
||||||
|
console.error(e.error)
|
||||||
|
os.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
render = e.id
|
||||||
|
draw2d = use('draw2d', video_actor, render)
|
||||||
|
graphics = use('graphics', video_actor, render)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function loop()
|
||||||
|
{
|
||||||
|
|
||||||
startGameLoop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$_.delay(loop, 1/60)
|
||||||
|
|
||||||
|
|
||||||
|
// Initialize render system
|
||||||
|
render.initialize({
|
||||||
|
width: gameConfig.resolution.width,
|
||||||
|
height: gameConfig.resolution.height,
|
||||||
|
resolution_x: gameConfig.internal_resolution.width,
|
||||||
|
resolution_y: gameConfig.internal_resolution.height,
|
||||||
|
mode: gameConfig.mode || 'letterbox'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set up default camera
|
||||||
|
gameConfig.camera = gameConfig.camera || {
|
||||||
|
size: [gameConfig.internal_resolution.width, gameConfig.internal_resolution.height],
|
||||||
|
transform: new transform,
|
||||||
|
fov: 50,
|
||||||
|
near_z: 0,
|
||||||
|
far_z: 1000,
|
||||||
|
surface: undefined,
|
||||||
|
viewport: {x: 0, y: 0, width: 1, height: 1},
|
||||||
|
ortho: true,
|
||||||
|
anchor: [0, 0]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set window title
|
||||||
|
prosperon.window.title = gameConfig.title;
|
||||||
|
|
||||||
|
startGameLoop();
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
function startGameLoop() {
|
function startGameLoop() {
|
||||||
var last = os.now();
|
var last = os.now();
|
||||||
@@ -107,7 +135,4 @@ function startGameLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Public API
|
// Public API
|
||||||
return {
|
return {}
|
||||||
initialize: initialize,
|
|
||||||
config: gameConfig
|
|
||||||
};
|
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
#include "qjs_js.h"
|
#include "qjs_js.h"
|
||||||
#include "qjs_debug.h"
|
#include "qjs_debug.h"
|
||||||
#include "qjs_sdl_surface.h"
|
#include "qjs_sdl_surface.h"
|
||||||
|
#include "qjs_sdl.h"
|
||||||
#ifndef NSTEAM
|
#ifndef NSTEAM
|
||||||
#include "qjs_steam.h"
|
#include "qjs_steam.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -937,53 +938,6 @@ static const JSCFunctionListEntry js_number_funcs[] = {
|
|||||||
PROTO_FUNC_DEF(number, lerp, 2),
|
PROTO_FUNC_DEF(number, lerp, 2),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct { const char *name; SDL_PixelFormat fmt; } fmt_entry;
|
|
||||||
|
|
||||||
static const fmt_entry k_fmt_table[] = {
|
|
||||||
{ "rgba32", SDL_PIXELFORMAT_RGBA32 },
|
|
||||||
{ "argb32", SDL_PIXELFORMAT_ARGB32 },
|
|
||||||
{ "bgra32", SDL_PIXELFORMAT_BGRA32 },
|
|
||||||
{ "abgr32", SDL_PIXELFORMAT_ABGR32 },
|
|
||||||
{ "rgb565", SDL_PIXELFORMAT_RGB565 },
|
|
||||||
{ "bgr565", SDL_PIXELFORMAT_BGR565 },
|
|
||||||
{ "rgb24", SDL_PIXELFORMAT_RGB24 },
|
|
||||||
{ "bgr24", SDL_PIXELFORMAT_BGR24 },
|
|
||||||
{ "rgb332", SDL_PIXELFORMAT_RGB332 },
|
|
||||||
{ "rgba64", SDL_PIXELFORMAT_RGBA64 },
|
|
||||||
{ "rgb48", SDL_PIXELFORMAT_RGB48 },
|
|
||||||
{ NULL, SDL_PIXELFORMAT_UNKNOWN }
|
|
||||||
};
|
|
||||||
|
|
||||||
static JSValue pixelformat2js(JSContext *js, SDL_PixelFormat fmt)
|
|
||||||
{
|
|
||||||
fmt_entry *it;
|
|
||||||
for (it = k_fmt_table; it->name; it++)
|
|
||||||
if (it->fmt == fmt)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (it->name)
|
|
||||||
return JS_NewString(js, it->name);
|
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
|
|
||||||
{
|
|
||||||
if (JS_IsUndefined(v)) return SDL_PIXELFORMAT_UNKNOWN;
|
|
||||||
const char *s = JS_ToCString(js, v);
|
|
||||||
if (!s) return SDL_PIXELFORMAT_UNKNOWN;
|
|
||||||
|
|
||||||
fmt_entry *it;
|
|
||||||
for (it = k_fmt_table; it->name; it++)
|
|
||||||
if (!strcmp(it->name, s))
|
|
||||||
break;
|
|
||||||
|
|
||||||
JS_FreeCString(js,s);
|
|
||||||
return it->fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSC_CCALL(os_guid,
|
JSC_CCALL(os_guid,
|
||||||
SDL_GUID guid;
|
SDL_GUID guid;
|
||||||
randombytes(guid.data, 16);
|
randombytes(guid.data, 16);
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
#include "qjs_actor.h"
|
#include "qjs_actor.h"
|
||||||
#include "qjs_sdl_surface.h"
|
#include "qjs_sdl_surface.h"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
|
|
||||||
// SDL Free functions
|
// SDL Free functions
|
||||||
void SDL_Camera_free(JSRuntime *rt, SDL_Camera *cam)
|
void SDL_Camera_free(JSRuntime *rt, SDL_Camera *cam)
|
||||||
{
|
{
|
||||||
@@ -263,6 +261,7 @@ SDL_PixelFormat str2pixelformat(const char *str) {
|
|||||||
if (!strcmp(str, "nv12")) return SDL_PIXELFORMAT_NV12;
|
if (!strcmp(str, "nv12")) return SDL_PIXELFORMAT_NV12;
|
||||||
if (!strcmp(str, "nv21")) return SDL_PIXELFORMAT_NV21;
|
if (!strcmp(str, "nv21")) return SDL_PIXELFORMAT_NV21;
|
||||||
if (!strcmp(str, "p010")) return SDL_PIXELFORMAT_P010;
|
if (!strcmp(str, "p010")) return SDL_PIXELFORMAT_P010;
|
||||||
|
if (!strcmp(str, "rgba32")) return SDL_PIXELFORMAT_RGBA32;
|
||||||
return SDL_PIXELFORMAT_UNKNOWN;
|
return SDL_PIXELFORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef QJS_SDL_H
|
#ifndef QJS_SDL_H
|
||||||
#define QJS_SDL_H
|
#define QJS_SDL_H
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
#include "quickjs.h"
|
#include "quickjs.h"
|
||||||
|
|
||||||
JSValue js_input_use(JSContext *ctx);
|
JSValue js_input_use(JSContext *ctx);
|
||||||
@@ -8,4 +9,13 @@ JSValue js_camera_use(JSContext *ctx);
|
|||||||
JSValue js_sdl_audio_use(JSContext *ctx);
|
JSValue js_sdl_audio_use(JSContext *ctx);
|
||||||
JSValue js_sdl_use(JSContext *js);
|
JSValue js_sdl_use(JSContext *js);
|
||||||
|
|
||||||
|
SDL_PixelFormat str2pixelformat(const char *str);
|
||||||
|
SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v);
|
||||||
|
JSValue pixelformat2js(JSContext *js, SDL_PixelFormat format);
|
||||||
|
const char *pixelformat2str(SDL_PixelFormat format);
|
||||||
|
SDL_Colorspace str2colorspace(const char *str);
|
||||||
|
SDL_Colorspace js2colorspace(JSContext *js, JSValue v);
|
||||||
|
JSValue colorspace2js(JSContext *js, SDL_Colorspace colorspace);
|
||||||
|
const char *colorspace2str(SDL_Colorspace colorspace);
|
||||||
|
|
||||||
#endif /* QJS_SDL_H */
|
#endif /* QJS_SDL_H */
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ extern const char *pixelformat2str(SDL_PixelFormat fmt);
|
|||||||
extern SDL_Colorspace str2colorspace(const char *str);
|
extern SDL_Colorspace str2colorspace(const char *str);
|
||||||
extern const char *colorspace2str(SDL_Colorspace colorspace);
|
extern const char *colorspace2str(SDL_Colorspace colorspace);
|
||||||
|
|
||||||
static JSValue pixelformat2js(JSContext *js, SDL_PixelFormat fmt)
|
JSValue pixelformat2js(JSContext *js, SDL_PixelFormat fmt)
|
||||||
{
|
{
|
||||||
const char *str = pixelformat2str(fmt);
|
const char *str = pixelformat2str(fmt);
|
||||||
return JS_NewString(js, str);
|
return JS_NewString(js, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
|
SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
|
||||||
{
|
{
|
||||||
if (JS_IsUndefined(v)) return SDL_PIXELFORMAT_UNKNOWN;
|
if (JS_IsUndefined(v)) return SDL_PIXELFORMAT_UNKNOWN;
|
||||||
const char *s = JS_ToCString(js, v);
|
const char *s = JS_ToCString(js, v);
|
||||||
@@ -35,7 +35,7 @@ static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
|
|||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Colorspace js2colorspace(JSContext *js, JSValue v)
|
SDL_Colorspace js2colorspace(JSContext *js, JSValue v)
|
||||||
{
|
{
|
||||||
if (JS_IsUndefined(v)) return SDL_COLORSPACE_UNKNOWN;
|
if (JS_IsUndefined(v)) return SDL_COLORSPACE_UNKNOWN;
|
||||||
const char *s = JS_ToCString(js, v);
|
const char *s = JS_ToCString(js, v);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "jsffi.h"
|
#include "jsffi.h"
|
||||||
#include "qjs_macros.h"
|
#include "qjs_macros.h"
|
||||||
#include "qjs_sdl_surface.h"
|
#include "qjs_sdl_surface.h"
|
||||||
|
#include "qjs_sdl.h"
|
||||||
#include "qjs_actor.h"
|
#include "qjs_actor.h"
|
||||||
#include "prosperon.h"
|
#include "prosperon.h"
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
@@ -1455,26 +1456,6 @@ static SDL_BlendMode js2blendmode(JSContext *js, JSValue v) {
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert pixel format string to SDL_PixelFormat
|
|
||||||
static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v) {
|
|
||||||
if (JS_IsNumber(v)) {
|
|
||||||
return js2number(js, v);
|
|
||||||
}
|
|
||||||
const char *str = JS_ToCString(js, v);
|
|
||||||
SDL_PixelFormat fmt = SDL_PIXELFORMAT_RGBA8888;
|
|
||||||
if (str) {
|
|
||||||
if (strcmp(str, "rgba8888") == 0) fmt = SDL_PIXELFORMAT_RGBA8888;
|
|
||||||
else if (strcmp(str, "bgra8888") == 0) fmt = SDL_PIXELFORMAT_BGRA8888;
|
|
||||||
else if (strcmp(str, "argb8888") == 0) fmt = SDL_PIXELFORMAT_ARGB8888;
|
|
||||||
else if (strcmp(str, "abgr8888") == 0) fmt = SDL_PIXELFORMAT_ABGR8888;
|
|
||||||
else if (strcmp(str, "rgba32") == 0) fmt = SDL_PIXELFORMAT_RGBA32;
|
|
||||||
else if (strcmp(str, "bgra32") == 0) fmt = SDL_PIXELFORMAT_BGRA32;
|
|
||||||
else if (strcmp(str, "argb32") == 0) fmt = SDL_PIXELFORMAT_ARGB32;
|
|
||||||
else if (strcmp(str, "abgr32") == 0) fmt = SDL_PIXELFORMAT_ABGR32;
|
|
||||||
JS_FreeCString(js, str);
|
|
||||||
}
|
|
||||||
return fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Texture constructor
|
// Texture constructor
|
||||||
static JSValue js_texture_constructor(JSContext *js, JSValueConst new_target, int argc, JSValueConst *argv)
|
static JSValue js_texture_constructor(JSContext *js, JSValueConst new_target, int argc, JSValueConst *argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user