add window message handling for sdl actor
This commit is contained in:
@@ -52,10 +52,169 @@ var default_window = {
|
||||
textInput: true, // Enable text input on creation
|
||||
};
|
||||
|
||||
var winwin
|
||||
// Resource tracking
|
||||
var resources = {
|
||||
window: {},
|
||||
renderer: {},
|
||||
texture: {},
|
||||
surface: {}
|
||||
};
|
||||
|
||||
// Export the video functions for other actors to call
|
||||
// ID counter for resource allocation
|
||||
var next_id = 1;
|
||||
|
||||
// Helper to allocate new ID
|
||||
function allocate_id() {
|
||||
return next_id++;
|
||||
}
|
||||
|
||||
// Message handler
|
||||
$_.receiver(function(msg) {
|
||||
console.log("Video actor received message:", msg);
|
||||
winwin = new prosperon.endowments.window(default_window)
|
||||
if (!msg.kind || !msg.op) {
|
||||
send(msg, {error: "Message must have 'kind' and 'op' fields"});
|
||||
return;
|
||||
}
|
||||
|
||||
var response = {};
|
||||
|
||||
try {
|
||||
switch (msg.kind) {
|
||||
case 'window':
|
||||
response = handle_window(msg);
|
||||
break;
|
||||
case 'renderer':
|
||||
response = handle_renderer(msg);
|
||||
break;
|
||||
case 'texture':
|
||||
response = handle_texture(msg);
|
||||
break;
|
||||
default:
|
||||
response = {error: "Unknown kind: " + msg.kind};
|
||||
}
|
||||
} catch (e) {
|
||||
response = {error: e.toString()};
|
||||
}
|
||||
|
||||
// Send response back
|
||||
send(msg, response);
|
||||
});
|
||||
|
||||
// Window operations
|
||||
function handle_window(msg) {
|
||||
switch (msg.op) {
|
||||
case 'create':
|
||||
var config = Object.assign({}, default_window, msg.data || {});
|
||||
var id = allocate_id();
|
||||
var window = new prosperon.endowments.window(config);
|
||||
resources.window[id] = window;
|
||||
return {id: id, data: {width: window.width, height: window.height}};
|
||||
|
||||
case 'destroy':
|
||||
if (!msg.id || !resources.window[msg.id]) {
|
||||
return {error: "Invalid window id: " + msg.id};
|
||||
}
|
||||
resources.window[msg.id].destroy();
|
||||
delete resources.window[msg.id];
|
||||
return {success: true};
|
||||
|
||||
case 'show':
|
||||
if (!msg.id || !resources.window[msg.id]) {
|
||||
return {error: "Invalid window id: " + msg.id};
|
||||
}
|
||||
resources.window[msg.id].show();
|
||||
return {success: true};
|
||||
|
||||
case 'hide':
|
||||
if (!msg.id || !resources.window[msg.id]) {
|
||||
return {error: "Invalid window id: " + msg.id};
|
||||
}
|
||||
resources.window[msg.id].hide();
|
||||
return {success: true};
|
||||
|
||||
case 'set_title':
|
||||
if (!msg.id || !resources.window[msg.id]) {
|
||||
return {error: "Invalid window id: " + msg.id};
|
||||
}
|
||||
if (!msg.data || !msg.data.title) {
|
||||
return {error: "Missing title in data"};
|
||||
}
|
||||
resources.window[msg.id].title = msg.data.title;
|
||||
return {success: true};
|
||||
|
||||
case 'get_size':
|
||||
if (!msg.id || !resources.window[msg.id]) {
|
||||
return {error: "Invalid window id: " + msg.id};
|
||||
}
|
||||
var win = resources.window[msg.id];
|
||||
return {data: {width: win.width, height: win.height}};
|
||||
|
||||
case 'set_size':
|
||||
if (!msg.id || !resources.window[msg.id]) {
|
||||
return {error: "Invalid window id: " + msg.id};
|
||||
}
|
||||
if (!msg.data || typeof msg.data.width !== 'number' || typeof msg.data.height !== 'number') {
|
||||
return {error: "Missing or invalid width/height in data"};
|
||||
}
|
||||
var win = resources.window[msg.id];
|
||||
win.width = msg.data.width;
|
||||
win.height = msg.data.height;
|
||||
return {success: true};
|
||||
|
||||
default:
|
||||
return {error: "Unknown window operation: " + msg.op};
|
||||
}
|
||||
}
|
||||
|
||||
// Renderer operations
|
||||
function handle_renderer(msg) {
|
||||
switch (msg.op) {
|
||||
case 'create':
|
||||
if (!msg.data || !msg.data.window_id) {
|
||||
return {error: "Missing window_id in data"};
|
||||
}
|
||||
if (!resources.window[msg.data.window_id]) {
|
||||
return {error: "Invalid window id: " + msg.data.window_id};
|
||||
}
|
||||
var id = allocate_id();
|
||||
var renderer = prosperon.endowments.renderer.create(resources.window[msg.data.window_id]);
|
||||
resources.renderer[id] = renderer;
|
||||
return {id: id};
|
||||
|
||||
case 'destroy':
|
||||
if (!msg.id || !resources.renderer[msg.id]) {
|
||||
return {error: "Invalid renderer id: " + msg.id};
|
||||
}
|
||||
resources.renderer[msg.id].destroy();
|
||||
delete resources.renderer[msg.id];
|
||||
return {success: true};
|
||||
|
||||
case 'clear':
|
||||
if (!msg.id || !resources.renderer[msg.id]) {
|
||||
return {error: "Invalid renderer id: " + msg.id};
|
||||
}
|
||||
resources.renderer[msg.id].clear();
|
||||
return {success: true};
|
||||
|
||||
case 'present':
|
||||
if (!msg.id || !resources.renderer[msg.id]) {
|
||||
return {error: "Invalid renderer id: " + msg.id};
|
||||
}
|
||||
resources.renderer[msg.id].present();
|
||||
return {success: true};
|
||||
|
||||
default:
|
||||
return {error: "Unknown renderer operation: " + msg.op};
|
||||
}
|
||||
}
|
||||
|
||||
// Texture operations
|
||||
function handle_texture(msg) {
|
||||
switch (msg.op) {
|
||||
case 'create':
|
||||
// TODO: Implement texture creation
|
||||
return {error: "Texture operations not yet implemented"};
|
||||
|
||||
default:
|
||||
return {error: "Unknown texture operation: " + msg.op};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
var video = use('sdl_video')
|
||||
|
||||
console.log(video)
|
||||
var myid
|
||||
var myrender
|
||||
|
||||
send({__ACTORDATA__:{id:video}}, {kind:"HELLO!"})
|
||||
send({__ACTORDATA__:{id:video}}, {kind:"window", op: "create"}, ({id}) => {
|
||||
myid = id
|
||||
console.log(`made window id ${id}`)
|
||||
})
|
||||
|
||||
$_.delay($_.stop, 2)
|
||||
Reference in New Issue
Block a user