moth now filters events to the correct space
This commit is contained in:
@@ -1,23 +1,10 @@
|
||||
/* main.js – runs the demo with your prototype-based grid */
|
||||
|
||||
var json = use('json')
|
||||
var os = use('os')
|
||||
var draw2d = use('draw2d')
|
||||
|
||||
var blob = use('blob')
|
||||
|
||||
var myblob = new blob
|
||||
myblob.write_bit(1)
|
||||
myblob.write_bit(0)
|
||||
myblob.__proto__.toString = function() {
|
||||
return `[${this.length} bit blob]`
|
||||
}
|
||||
log.console(myblob.toString(), myblob, myblob.length)
|
||||
|
||||
var input = use('input')
|
||||
|
||||
input.watch($_)
|
||||
|
||||
/*──── import our pieces + systems ───────────────────────────────────*/
|
||||
var Grid = use('examples/chess/grid'); // your new ctor
|
||||
var MovementSystem = use('examples/chess/movement').MovementSystem;
|
||||
@@ -339,8 +326,6 @@ function joinServer() {
|
||||
});
|
||||
}
|
||||
|
||||
var os = use('os')
|
||||
|
||||
$_.receiver(e => {
|
||||
if (e.kind == 'update')
|
||||
send(e, update(e.dt))
|
||||
@@ -348,7 +333,6 @@ $_.receiver(e => {
|
||||
send(e, draw())
|
||||
else if (e.type === 'game_start' || e.type === 'move' || e.type === 'greet')
|
||||
log.console("Receiver got message:", e.type, e);
|
||||
if (e.type === 'quit') os.exit()
|
||||
|
||||
if (e.type === 'greet') {
|
||||
log.console("Server received greet from client");
|
||||
@@ -411,3 +395,5 @@ $_.receiver(e => {
|
||||
handleKeyDown(e)
|
||||
}
|
||||
})
|
||||
|
||||
var parseq = use('parseq', $_.delay)
|
||||
|
||||
@@ -436,12 +436,8 @@ function handle_renderer(msg) {
|
||||
|
||||
var tex;
|
||||
// Direct surface data
|
||||
log.console(json.encode(msg.data))
|
||||
var surf = new surface(msg.data)
|
||||
|
||||
log.console("GOT DATA")
|
||||
log.console(json.encode(msg.data))
|
||||
|
||||
if (!surf)
|
||||
throw new Error("Must provide surface_id or surface data")
|
||||
|
||||
|
||||
@@ -39,19 +39,21 @@ logs.console = function(msg)
|
||||
console_mod.print(console_rec(caller.line, caller.file, msg))
|
||||
}
|
||||
|
||||
logs.error = function(e)
|
||||
logs.error = function(msg)
|
||||
{
|
||||
if (!e)
|
||||
e = new Error()
|
||||
var caller = caller_data(4)
|
||||
|
||||
if (e instanceof Error)
|
||||
pprint(`${e.name} : ${e.message}
|
||||
${e.stack}`, 4)
|
||||
var err
|
||||
|
||||
if (!msg || !(msg instanceof Error))
|
||||
err = new Error()
|
||||
else {
|
||||
var stack = new Error()
|
||||
pprint(`${e}
|
||||
${stack.stack}`,4)
|
||||
err = msg
|
||||
msg = undefined
|
||||
}
|
||||
|
||||
console_mod.print(console_rec(caller.line,caller.file,`${msg}
|
||||
${err.stack}`))
|
||||
}
|
||||
|
||||
logs.panic = function(msg)
|
||||
@@ -65,6 +67,8 @@ globalThis.log = new Proxy(logs, {
|
||||
get(target,prop,receiver) {
|
||||
if (target[prop])
|
||||
return (...args) => args.forEach(arg => target[prop](arg))
|
||||
|
||||
return noop
|
||||
}
|
||||
})
|
||||
|
||||
@@ -588,7 +592,7 @@ if (typeof prosperon.args.program !== 'string')
|
||||
actor_mod.setname(prosperon.args.program)
|
||||
|
||||
function destroyself() {
|
||||
log.console(`Got the message to destroy self.`)
|
||||
log.spam(`Got the message to destroy self.`)
|
||||
dying = true
|
||||
for (var i of underlings)
|
||||
$_.stop(create_actor({id:i}))
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
the "dull" game engine
|
||||
|
||||
This sets up a lot of different modules to be used altogether
|
||||
*/
|
||||
|
||||
var render = use('render')
|
||||
var layout = use('clay')
|
||||
var input = use('input')
|
||||
var emitter = use('emitter')
|
||||
var os = use('os')
|
||||
var imgui = use('imgui')
|
||||
var tracy = use('tracy')
|
||||
|
||||
var last_frame_time = 0
|
||||
var timescale = 1
|
||||
|
||||
last_frame_time = os.now()
|
||||
|
||||
function step() {
|
||||
var now = os.now()
|
||||
var dt = now - last_frame_time
|
||||
last_frame_time = now
|
||||
|
||||
layout.newframe()
|
||||
|
||||
prosperon.appupdate(dt)
|
||||
input.procdown()
|
||||
emitter.update(dt * timescale)
|
||||
prosperon.update(dt * timescale)
|
||||
|
||||
render.setup_draw()
|
||||
render.setup_hud()
|
||||
|
||||
if (imgui) imgui.prosperon_menu();
|
||||
|
||||
// Now do the GPU present (calls gpupresent in render.js)
|
||||
render.present()
|
||||
|
||||
tracy.end_frame()
|
||||
}
|
||||
|
||||
function start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Return or export them so you can call from a main script
|
||||
return {
|
||||
start,
|
||||
step
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
var cam = {}
|
||||
|
||||
var os = use('os')
|
||||
var transform = use('transform')
|
||||
|
||||
var basecam = {}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var color = use('color')
|
||||
var os = use('os')
|
||||
var graphics = use('graphics')
|
||||
var transform = use('transform')
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ var renderer_actor = arg[0]
|
||||
var renderer_id = arg[1]
|
||||
|
||||
var io = use('io')
|
||||
var os = use('os')
|
||||
var time = use('time')
|
||||
var res = use('resources')
|
||||
var json = use('json')
|
||||
|
||||
@@ -27,7 +27,7 @@ graphics.Image = function(surfaceData) {
|
||||
this[CPU] = surfaceData || undefined;
|
||||
this[GPU] = undefined;
|
||||
this[LOADING] = false;
|
||||
this[LASTUSE] = os.now();
|
||||
this[LASTUSE] = time.now();
|
||||
this.rect = {x:0, y:0, width:1, height:1};
|
||||
}
|
||||
|
||||
@@ -35,20 +35,18 @@ graphics.Image = function(surfaceData) {
|
||||
Object.defineProperties(graphics.Image.prototype, {
|
||||
gpu: {
|
||||
get: function() {
|
||||
this[LASTUSE] = os.now();
|
||||
this[LASTUSE] = time.now();
|
||||
if (!this[GPU] && !this[LOADING]) {
|
||||
this[LOADING] = true;
|
||||
var self = this;
|
||||
|
||||
// Send message to load texture
|
||||
log.console("LOADING")
|
||||
send(renderer_actor, {
|
||||
kind: "renderer",
|
||||
id: renderer_id,
|
||||
op: "loadTexture",
|
||||
data: this[CPU]
|
||||
}, function(response) {
|
||||
log.console("GOT MSG")
|
||||
if (response.error) {
|
||||
log.error("Failed to load texture:")
|
||||
log.error(response.error)
|
||||
@@ -71,7 +69,7 @@ Object.defineProperties(graphics.Image.prototype, {
|
||||
|
||||
cpu: {
|
||||
get: function() {
|
||||
this[LASTUSE] = os.now();
|
||||
this[LASTUSE] = time.now();
|
||||
// Note: Reading texture back from GPU requires async operation
|
||||
// For now, return the CPU data if available
|
||||
return this[CPU]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
var render = {}
|
||||
|
||||
var io = use('io')
|
||||
var os = use('os')
|
||||
var controller = use('controller')
|
||||
var tracy = use('tracy')
|
||||
var graphics = use('graphics')
|
||||
|
||||
@@ -8,6 +8,9 @@ var io = use('io');
|
||||
var transform = use('transform');
|
||||
var rasterize = use('rasterize');
|
||||
var video_actor = use('sdl_video')
|
||||
var input = use('input')
|
||||
|
||||
input.watch($_)
|
||||
|
||||
var geometry = use('geometry')
|
||||
|
||||
@@ -41,6 +44,26 @@ function worldToScreenPoint([wx, wy], camera, winW, winH) {
|
||||
return [ px, py ];
|
||||
}
|
||||
|
||||
function screenToWorldPoint([px, py], camera, winW, winH) {
|
||||
// 1) undo pixel→NDC within the camera’s viewport
|
||||
const ndcX = (px - camera.viewport.x * winW)
|
||||
/ (camera.viewport.width * winW)
|
||||
const ndcY = 1 - (py - camera.viewport.y * winH)
|
||||
/ (camera.viewport.height * winH)
|
||||
|
||||
// 2) compute the world‐window origin (bottom‐left)
|
||||
const worldX0 = camera.pos[0]
|
||||
- camera.size[0] * camera.anchor[0]
|
||||
const worldY0 = camera.pos[1]
|
||||
- camera.size[1] * camera.anchor[1]
|
||||
|
||||
// 3) map NDC back to world coords
|
||||
return [
|
||||
ndcX * camera.size[0] + worldX0,
|
||||
ndcY * camera.size[1] + worldY0
|
||||
]
|
||||
}
|
||||
|
||||
var camera = {
|
||||
size: [500,500],//{width:500,height:500}, // pixel size the camera "sees", like its resolution
|
||||
pos: [250,250],//{x:0,y:0}, // where it is
|
||||
@@ -68,7 +91,7 @@ var dir = args[0]
|
||||
if (!io.exists(args[0] + '/main.js'))
|
||||
throw Error(`No main.js found in ${args[0]}`)
|
||||
|
||||
log.console('starting game in ' + dir)
|
||||
log.spam('Starting game in ' + dir)
|
||||
|
||||
io.mount(dir)
|
||||
|
||||
@@ -106,8 +129,6 @@ send(video_actor, {
|
||||
|
||||
render = e.id
|
||||
graphics = use('graphics', video_actor, e.id)
|
||||
|
||||
log.console(`Created window and renderer id ${render}`)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -316,3 +337,18 @@ function loop()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
$_.receiver(e => {
|
||||
if (e.type === 'quit')
|
||||
$_.stop()
|
||||
|
||||
if (e.type.includes('mouse')) {
|
||||
if (e.pos)
|
||||
e.pos = screenToWorldPoint(e.pos, camera, 500, 500)
|
||||
|
||||
if (e.d_pos)
|
||||
e.d_pos.y *= -1
|
||||
}
|
||||
|
||||
send(gameactor, e)
|
||||
})
|
||||
@@ -1019,8 +1019,6 @@ JSC_CCALL(os_make_texture,
|
||||
int pitch = width*4;
|
||||
size_t pixels_size = pitch * height;
|
||||
|
||||
printf("making surface from blob %p of %u bytes\n", raw, len);
|
||||
|
||||
// Create JS object with surface data
|
||||
JSValue obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, width));
|
||||
@@ -1576,9 +1574,6 @@ void ffi_load(JSContext *js)
|
||||
arrput(rt->module_registry, MISTLINE(sprite));
|
||||
arrput(rt->module_registry, MISTLINE(transform));
|
||||
|
||||
// arrput(rt->module_registry, MISTLINE(wota));
|
||||
// arrput(rt->module_registry, MISTLINE(nota));
|
||||
|
||||
#ifndef NSTEAM
|
||||
arrput(rt->module_registry, MISTLINE(steam));
|
||||
#endif
|
||||
|
||||
@@ -1202,7 +1202,7 @@ static void event2wota_write(WotaBuffer *wb, const SDL_Event *e, int c) {
|
||||
wota_write_number(wb, (double)e->wheel.which);
|
||||
wota_write_text(wb, "scroll");
|
||||
wota_write_vec2(wb, (double)e->wheel.x, (double)e->wheel.y);
|
||||
wota_write_text(wb, "mouse");
|
||||
wota_write_text(wb, "pos");
|
||||
wota_write_vec2(wb, (double)e->wheel.mouse_x, (double)e->wheel.mouse_y);
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||
@@ -1217,7 +1217,7 @@ static void event2wota_write(WotaBuffer *wb, const SDL_Event *e, int c) {
|
||||
wota_write_text(wb, mouse_button_to_string(e->button.button));
|
||||
wota_write_text(wb, "clicks");
|
||||
wota_write_number(wb, (double)e->button.clicks);
|
||||
wota_write_text(wb, "mouse");
|
||||
wota_write_text(wb, "pos");
|
||||
wota_write_vec2(wb, (double)e->button.x, (double)e->button.y);
|
||||
break;
|
||||
case SDL_EVENT_SENSOR_UPDATE:
|
||||
@@ -1536,8 +1536,6 @@ int main(int argc, char **argv)
|
||||
actor_argv[0] = argv[0]; // Keep the program name
|
||||
create_actor(actor_argc, actor_argv, NULL);
|
||||
|
||||
cores = 1;
|
||||
|
||||
/* Start the thread that pumps ready actors, one per logical core. */
|
||||
for (int i = 0; i < cores; i++) {
|
||||
char threadname[128];
|
||||
|
||||
@@ -602,7 +602,6 @@ JSValue js_blob_use(JSContext *js) {
|
||||
|
||||
JSValue js_new_blob_stoned_copy(JSContext *js, void *data, size_t bytes)
|
||||
{
|
||||
printf("Making blob from %p with %u bytes\n", data, bytes);
|
||||
blob *b = blob_new(bytes*8);
|
||||
memcpy(b->data, data, bytes);
|
||||
b->bit_length = bytes * 8; // Set the actual length in bits
|
||||
|
||||
Reference in New Issue
Block a user