use log instead of console
This commit is contained in:
@@ -126,7 +126,7 @@ meson test -C build_dbg
|
|||||||
### Debugging
|
### Debugging
|
||||||
- Use debug build: `make debug`
|
- Use debug build: `make debug`
|
||||||
- Tracy profiler support when enabled
|
- Tracy profiler support when enabled
|
||||||
- Console logging available via `console.log()`, `console.error()`, etc.
|
- Console logging available via `log.console()`, `log.error()`, etc.
|
||||||
- Log files written to `.prosperon/log.txt`
|
- Log files written to `.prosperon/log.txt`
|
||||||
|
|
||||||
# Project Structure Notes
|
# Project Structure Notes
|
||||||
@@ -234,7 +234,7 @@ When sending a message with a callback, respond by sending to the message itself
|
|||||||
```javascript
|
```javascript
|
||||||
// Sender side:
|
// Sender side:
|
||||||
send(actor, {type: 'status'}, response => {
|
send(actor, {type: 'status'}, response => {
|
||||||
console.log(response); // Handle the response
|
log.console(response); // Handle the response
|
||||||
});
|
});
|
||||||
|
|
||||||
// Receiver side:
|
// Receiver side:
|
||||||
|
|||||||
@@ -49,28 +49,28 @@ function getStats(arr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pretty print results
|
// Pretty print results
|
||||||
console.log("\n=== Performance Test Results (100 iterations) ===");
|
log.console("\n=== Performance Test Results (100 iterations) ===");
|
||||||
console.log("\nJSON Decoding (ms):");
|
log.console("\nJSON Decoding (ms):");
|
||||||
const jsonDecStats = getStats(jsonDecodeTimes);
|
const jsonDecStats = getStats(jsonDecodeTimes);
|
||||||
console.log(`Average: ${jsonDecStats.avg.toFixed(2)} ms`);
|
log.console(`Average: ${jsonDecStats.avg.toFixed(2)} ms`);
|
||||||
console.log(`Min: ${jsonDecStats.min.toFixed(2)} ms`);
|
log.console(`Min: ${jsonDecStats.min.toFixed(2)} ms`);
|
||||||
console.log(`Max: ${jsonDecStats.max.toFixed(2)} ms`);
|
log.console(`Max: ${jsonDecStats.max.toFixed(2)} ms`);
|
||||||
|
|
||||||
console.log("\nJSON Encoding (ms):");
|
log.console("\nJSON Encoding (ms):");
|
||||||
const jsonEncStats = getStats(jsonEncodeTimes);
|
const jsonEncStats = getStats(jsonEncodeTimes);
|
||||||
console.log(`Average: ${jsonEncStats.avg.toFixed(2)} ms`);
|
log.console(`Average: ${jsonEncStats.avg.toFixed(2)} ms`);
|
||||||
console.log(`Min: ${jsonEncStats.min.toFixed(2)} ms`);
|
log.console(`Min: ${jsonEncStats.min.toFixed(2)} ms`);
|
||||||
console.log(`Max: ${jsonEncStats.max.toFixed(2)} ms`);
|
log.console(`Max: ${jsonEncStats.max.toFixed(2)} ms`);
|
||||||
|
|
||||||
console.log("\nNOTA Encoding (ms):");
|
log.console("\nNOTA Encoding (ms):");
|
||||||
const notaEncStats = getStats(notaEncodeTimes);
|
const notaEncStats = getStats(notaEncodeTimes);
|
||||||
console.log(`Average: ${notaEncStats.avg.toFixed(2)} ms`);
|
log.console(`Average: ${notaEncStats.avg.toFixed(2)} ms`);
|
||||||
console.log(`Min: ${notaEncStats.min.toFixed(2)} ms`);
|
log.console(`Min: ${notaEncStats.min.toFixed(2)} ms`);
|
||||||
console.log(`Max: ${notaEncStats.max.toFixed(2)} ms`);
|
log.console(`Max: ${notaEncStats.max.toFixed(2)} ms`);
|
||||||
|
|
||||||
console.log("\nNOTA Decoding (ms):");
|
log.console("\nNOTA Decoding (ms):");
|
||||||
const notaDecStats = getStats(notaDecodeTimes);
|
const notaDecStats = getStats(notaDecodeTimes);
|
||||||
console.log(`Average: ${notaDecStats.avg.toFixed(2)} ms`);
|
log.console(`Average: ${notaDecStats.avg.toFixed(2)} ms`);
|
||||||
console.log(`Min: ${notaDecStats.min.toFixed(2)} ms`);
|
log.console(`Min: ${notaDecStats.min.toFixed(2)} ms`);
|
||||||
console.log(`Max: ${notaDecStats.max.toFixed(2)} ms`);
|
log.console(`Max: ${notaDecStats.max.toFixed(2)} ms`);
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ const benchmarks = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Print a header
|
// Print a header
|
||||||
console.log("Wota Encode/Decode Benchmark");
|
log.console("Wota Encode/Decode Benchmark");
|
||||||
console.log("============================\n");
|
log.console("============================\n");
|
||||||
|
|
||||||
// We'll run each benchmark scenario in turn.
|
// We'll run each benchmark scenario in turn.
|
||||||
for (let bench of benchmarks) {
|
for (let bench of benchmarks) {
|
||||||
@@ -96,11 +96,11 @@ for (let bench of benchmarks) {
|
|||||||
let elapsedSec = measureTime(runAllData, bench.iterations);
|
let elapsedSec = measureTime(runAllData, bench.iterations);
|
||||||
let opsPerSec = (totalIterations / elapsedSec).toFixed(1);
|
let opsPerSec = (totalIterations / elapsedSec).toFixed(1);
|
||||||
|
|
||||||
console.log(`${bench.name}:`);
|
log.console(`${bench.name}:`);
|
||||||
console.log(` Iterations: ${bench.iterations} × ${bench.data.length} data items = ${totalIterations}`);
|
log.console(` Iterations: ${bench.iterations} × ${bench.data.length} data items = ${totalIterations}`);
|
||||||
console.log(` Elapsed: ${elapsedSec.toFixed(3)} s`);
|
log.console(` Elapsed: ${elapsedSec.toFixed(3)} s`);
|
||||||
console.log(` Throughput: ${opsPerSec} encode+decode ops/sec\n`);
|
log.console(` Throughput: ${opsPerSec} encode+decode ops/sec\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All done
|
// All done
|
||||||
console.log("Benchmark completed.\n");
|
log.console("Benchmark completed.\n");
|
||||||
|
|||||||
@@ -160,12 +160,12 @@ function runBenchmarkForLibrary(lib, bench) {
|
|||||||
// 5. Main driver: run across all benchmarks, for each library.
|
// 5. Main driver: run across all benchmarks, for each library.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
console.log("Benchmark: Wota vs Nota vs JSON");
|
log.console("Benchmark: Wota vs Nota vs JSON");
|
||||||
console.log("================================\n");
|
log.console("================================\n");
|
||||||
|
|
||||||
for (let bench of benchmarks) {
|
for (let bench of benchmarks) {
|
||||||
console.log(`SCENARIO: ${bench.name}`);
|
log.console(`SCENARIO: ${bench.name}`);
|
||||||
console.log(` Data length: ${bench.data.length} | Iterations: ${bench.iterations}\n`);
|
log.console(` Data length: ${bench.data.length} | Iterations: ${bench.iterations}\n`);
|
||||||
|
|
||||||
for (let lib of libraries) {
|
for (let lib of libraries) {
|
||||||
let { encodeTime, decodeTime, totalSize } = runBenchmarkForLibrary(lib, bench);
|
let { encodeTime, decodeTime, totalSize } = runBenchmarkForLibrary(lib, bench);
|
||||||
@@ -175,15 +175,15 @@ for (let bench of benchmarks) {
|
|||||||
let encOpsPerSec = (totalOps / encodeTime).toFixed(1);
|
let encOpsPerSec = (totalOps / encodeTime).toFixed(1);
|
||||||
let decOpsPerSec = (totalOps / decodeTime).toFixed(1);
|
let decOpsPerSec = (totalOps / decodeTime).toFixed(1);
|
||||||
|
|
||||||
console.log(` ${lib.name}:`);
|
log.console(` ${lib.name}:`);
|
||||||
console.log(` Encode time: ${encodeTime.toFixed(3)}s => ${encOpsPerSec} encodes/sec [${(encodeTime/bench.iterations)*1000000000} ns/try]`);
|
log.console(` Encode time: ${encodeTime.toFixed(3)}s => ${encOpsPerSec} encodes/sec [${(encodeTime/bench.iterations)*1000000000} ns/try]`);
|
||||||
console.log(` Decode time: ${decodeTime.toFixed(3)}s => ${decOpsPerSec} decodes/sec [${(decodeTime/bench.iterations)*1000000000}/try]`);
|
log.console(` Decode time: ${decodeTime.toFixed(3)}s => ${decOpsPerSec} decodes/sec [${(decodeTime/bench.iterations)*1000000000}/try]`);
|
||||||
console.log(` Total size: ${totalSize} bytes (or code units for JSON)`);
|
log.console(` Total size: ${totalSize} bytes (or code units for JSON)`);
|
||||||
console.log("");
|
log.console("");
|
||||||
}
|
}
|
||||||
console.log("---------------------------------------------------------\n");
|
log.console("---------------------------------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Benchmark complete.\n");
|
log.console("Benchmark complete.\n");
|
||||||
|
|
||||||
os.exit()
|
os.exit()
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ Certain functions are intrinsic to the program and cannot be overridden. They’
|
|||||||
- **Example**:
|
- **Example**:
|
||||||
```js
|
```js
|
||||||
this.delay(_ => {
|
this.delay(_ => {
|
||||||
console.log("3 seconds later!")
|
log.console("3 seconds later!")
|
||||||
}, 3)
|
}, 3)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Docstrings are set to the symbol `prosperon.DOC`
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// Suppose we have a module that returns a function
|
// Suppose we have a module that returns a function
|
||||||
function greet(name) { console.log("Hello, " + name) }
|
function greet(name) { log.console("Hello, " + name) }
|
||||||
|
|
||||||
// We can attach a docstring
|
// We can attach a docstring
|
||||||
greet.doc = `
|
greet.doc = `
|
||||||
@@ -21,7 +21,7 @@ return greet
|
|||||||
```js
|
```js
|
||||||
// Another way is to add a docstring object to an object
|
// Another way is to add a docstring object to an object
|
||||||
var greet = {
|
var greet = {
|
||||||
hello() { console.log('hello!') }
|
hello() { log.console('hello!') }
|
||||||
}
|
}
|
||||||
|
|
||||||
greet[prosperon.DOC] = {}
|
greet[prosperon.DOC] = {}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ return {
|
|||||||
This will cause prosperon to launch a 500x500 window with the title 'Hello World'. In your ```main.js```, write the following:
|
This will cause prosperon to launch a 500x500 window with the title 'Hello World'. In your ```main.js```, write the following:
|
||||||
|
|
||||||
```
|
```
|
||||||
console.log("Hello world")
|
log.console("Hello world")
|
||||||
|
|
||||||
this.delay(_ => {
|
this.delay(_ => {
|
||||||
this.kill();
|
this.kill();
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ myblob.write_bit(0)
|
|||||||
myblob.__proto__.toString = function() {
|
myblob.__proto__.toString = function() {
|
||||||
return `[${this.length} bit blob]`
|
return `[${this.length} bit blob]`
|
||||||
}
|
}
|
||||||
console.log(myblob.toString())
|
log.console(myblob.toString(), myblob, myblob.length)
|
||||||
console.log(myblob)
|
|
||||||
console.log(myblob.length)
|
|
||||||
|
|
||||||
var input = use('input')
|
var input = use('input')
|
||||||
|
|
||||||
@@ -63,7 +61,7 @@ function updateTitle() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(title)
|
log.console(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize title
|
// Initialize title
|
||||||
@@ -125,16 +123,16 @@ function handleMouseButtonUp(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mover.tryMove(grid.at(selectPos)[0], c)) {
|
if (mover.tryMove(grid.at(selectPos)[0], c)) {
|
||||||
console.log("Made move from", selectPos, "to", c);
|
log.console("Made move from", selectPos, "to", c);
|
||||||
// Send move to opponent
|
// Send move to opponent
|
||||||
console.log("Sending move to opponent:", opponent);
|
log.console("Sending move to opponent:", opponent);
|
||||||
send(opponent, {
|
send(opponent, {
|
||||||
type: 'move',
|
type: 'move',
|
||||||
from: selectPos,
|
from: selectPos,
|
||||||
to: c
|
to: c
|
||||||
});
|
});
|
||||||
isMyTurn = false; // It's now opponent's turn
|
isMyTurn = false; // It's now opponent's turn
|
||||||
console.log("Move sent, now opponent's turn");
|
log.console("Move sent, now opponent's turn");
|
||||||
selectPos = null;
|
selectPos = null;
|
||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
@@ -305,11 +303,11 @@ function startServer() {
|
|||||||
updateTitle();
|
updateTitle();
|
||||||
|
|
||||||
$_.portal(e => {
|
$_.portal(e => {
|
||||||
console.log("Portal received contact message");
|
log.console("Portal received contact message");
|
||||||
// Reply with this actor to establish connection
|
// Reply with this actor to establish connection
|
||||||
console.log (json.encode($_))
|
log.console (json.encode($_))
|
||||||
send(e, $_);
|
send(e, $_);
|
||||||
console.log("Portal replied with server actor");
|
log.console("Portal replied with server actor");
|
||||||
}, 5678);
|
}, 5678);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,10 +316,10 @@ function joinServer() {
|
|||||||
updateTitle();
|
updateTitle();
|
||||||
|
|
||||||
function contact_fn(actor, reason) {
|
function contact_fn(actor, reason) {
|
||||||
console.log("CONTACTED!", actor ? "SUCCESS" : "FAILED", reason);
|
log.console("CONTACTED!", actor ? "SUCCESS" : "FAILED", reason);
|
||||||
if (actor) {
|
if (actor) {
|
||||||
opponent = actor;
|
opponent = actor;
|
||||||
console.log("Connection established with server, sending join request");
|
log.console("Connection established with server, sending join request");
|
||||||
|
|
||||||
// Send a greet message with our actor object
|
// Send a greet message with our actor object
|
||||||
send(opponent, {
|
send(opponent, {
|
||||||
@@ -329,7 +327,7 @@ function joinServer() {
|
|||||||
client_actor: $_
|
client_actor: $_
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(`Failed to connect: ${json.encode(reason)}`);
|
log.console(`Failed to connect: ${json.encode(reason)}`);
|
||||||
gameState = 'waiting';
|
gameState = 'waiting';
|
||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
@@ -349,33 +347,33 @@ $_.receiver(e => {
|
|||||||
else if (e.kind == 'draw')
|
else if (e.kind == 'draw')
|
||||||
send(e, draw())
|
send(e, draw())
|
||||||
else if (e.type === 'game_start' || e.type === 'move' || e.type === 'greet')
|
else if (e.type === 'game_start' || e.type === 'move' || e.type === 'greet')
|
||||||
console.log("Receiver got message:", e.type, e);
|
log.console("Receiver got message:", e.type, e);
|
||||||
if (e.type === 'quit') os.exit()
|
if (e.type === 'quit') os.exit()
|
||||||
|
|
||||||
if (e.type === 'greet') {
|
if (e.type === 'greet') {
|
||||||
console.log("Server received greet from client");
|
log.console("Server received greet from client");
|
||||||
// Store the client's actor object for ongoing communication
|
// Store the client's actor object for ongoing communication
|
||||||
opponent = e.client_actor;
|
opponent = e.client_actor;
|
||||||
console.log("Stored client actor:", json.encode(opponent));
|
log.console("Stored client actor:", json.encode(opponent));
|
||||||
gameState = 'connected';
|
gameState = 'connected';
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
|
||||||
// Send game_start to the client
|
// Send game_start to the client
|
||||||
console.log("Sending game_start to client");
|
log.console("Sending game_start to client");
|
||||||
send(opponent, {
|
send(opponent, {
|
||||||
type: 'game_start',
|
type: 'game_start',
|
||||||
your_color: 'black'
|
your_color: 'black'
|
||||||
});
|
});
|
||||||
console.log("game_start message sent to client");
|
log.console("game_start message sent to client");
|
||||||
}
|
}
|
||||||
else if (e.type === 'game_start') {
|
else if (e.type === 'game_start') {
|
||||||
console.log("Game starting, I am:", e.your_color);
|
log.console("Game starting, I am:", e.your_color);
|
||||||
myColor = e.your_color;
|
myColor = e.your_color;
|
||||||
isMyTurn = (myColor === 'white');
|
isMyTurn = (myColor === 'white');
|
||||||
gameState = 'connected';
|
gameState = 'connected';
|
||||||
updateTitle();
|
updateTitle();
|
||||||
} else if (e.type === 'move') {
|
} else if (e.type === 'move') {
|
||||||
console.log("Received move from opponent:", e.from, "to", e.to);
|
log.console("Received move from opponent:", e.from, "to", e.to);
|
||||||
// Apply opponent's move
|
// Apply opponent's move
|
||||||
var fromCell = grid.at(e.from);
|
var fromCell = grid.at(e.from);
|
||||||
if (fromCell.length) {
|
if (fromCell.length) {
|
||||||
@@ -383,12 +381,12 @@ $_.receiver(e => {
|
|||||||
if (mover.tryMove(piece, e.to)) {
|
if (mover.tryMove(piece, e.to)) {
|
||||||
isMyTurn = true; // It's now our turn
|
isMyTurn = true; // It's now our turn
|
||||||
updateTitle();
|
updateTitle();
|
||||||
console.log("Applied opponent move, now my turn");
|
log.console("Applied opponent move, now my turn");
|
||||||
} else {
|
} else {
|
||||||
console.log("Failed to apply opponent move");
|
log.console("Failed to apply opponent move");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("No piece found at from position");
|
log.console("No piece found at from position");
|
||||||
}
|
}
|
||||||
} else if (e.type === 'mouse_move') {
|
} else if (e.type === 'mouse_move') {
|
||||||
// Update opponent's mouse position
|
// Update opponent's mouse position
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ $_.receiver(function(msg) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'status':
|
case 'status':
|
||||||
console.log(`got status request. current is ${json.encode(get_status())}`)
|
log.console(`got status request. current is ${json.encode(get_status())}`)
|
||||||
send(msg, {
|
send(msg, {
|
||||||
type: 'status_response',
|
type: 'status_response',
|
||||||
...get_status()
|
...get_status()
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ var waiting_client = null;
|
|||||||
var match_id = 0;
|
var match_id = 0;
|
||||||
|
|
||||||
$_.portal(e => {
|
$_.portal(e => {
|
||||||
console.log("NAT server: received connection request");
|
log.console("NAT server: received connection request");
|
||||||
|
|
||||||
if (!is_actor(e.actor))
|
if (!is_actor(e.actor))
|
||||||
send(e, {reason: "Must provide the actor you want to connect."});
|
send(e, {reason: "Must provide the actor you want to connect."});
|
||||||
|
|
||||||
if (waiting_client) {
|
if (waiting_client) {
|
||||||
console.log(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`)
|
log.console(`sending out messages! to ${json.encode(e.actor)} and ${json.encode(waiting_client.actor)}`)
|
||||||
send(waiting_client, e.actor)
|
send(waiting_client, e.actor)
|
||||||
send(e, waiting_client.actor)
|
send(e, waiting_client.actor)
|
||||||
|
|
||||||
@@ -25,5 +25,5 @@ $_.portal(e => {
|
|||||||
|
|
||||||
waiting_client = e
|
waiting_client = e
|
||||||
|
|
||||||
console.log(`actor ${json.encode(e.actor)} is waiting ...`)
|
log.console(`actor ${json.encode(e.actor)} is waiting ...`)
|
||||||
}, 4000);
|
}, 4000);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
console.log(`nat client starting`)
|
log.console(`nat client starting`)
|
||||||
|
|
||||||
$_.contact((actor, reason) => {
|
$_.contact((actor, reason) => {
|
||||||
if (actor) {
|
if (actor) {
|
||||||
console.log(`trying to message ${json.encode(actor)}`)
|
log.console(`trying to message ${json.encode(actor)}`)
|
||||||
send(actor, {type:"greet"})
|
send(actor, {type:"greet"})
|
||||||
} else {
|
} else {
|
||||||
console.log(json.encode(reason))
|
log.console(json.encode(reason))
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
address: "108.210.60.32", // NAT server's public IP
|
address: "108.210.60.32", // NAT server's public IP
|
||||||
@@ -16,7 +16,7 @@ $_.contact((actor, reason) => {
|
|||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
switch(e.type) {
|
switch(e.type) {
|
||||||
case 'greet':
|
case 'greet':
|
||||||
console.log(`hello!`)
|
log.console(`hello!`)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -23,23 +23,23 @@ var stats_loaded = false;
|
|||||||
// Initialize Steam
|
// Initialize Steam
|
||||||
function init_steam() {
|
function init_steam() {
|
||||||
if (!steam) {
|
if (!steam) {
|
||||||
console.log("Steam module not available");
|
log.console("Steam module not available");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Initializing Steam...");
|
log.console("Initializing Steam...");
|
||||||
steam_available = steam.steam_init();
|
steam_available = steam.steam_init();
|
||||||
|
|
||||||
if (steam_available) {
|
if (steam_available) {
|
||||||
console.log("Steam initialized successfully");
|
log.console("Steam initialized successfully");
|
||||||
|
|
||||||
// Request current stats/achievements
|
// Request current stats/achievements
|
||||||
if (steam.stats.stats_request()) {
|
if (steam.stats.stats_request()) {
|
||||||
console.log("Stats requested");
|
log.console("Stats requested");
|
||||||
stats_loaded = true;
|
stats_loaded = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Failed to initialize Steam");
|
log.console("Failed to initialize Steam");
|
||||||
}
|
}
|
||||||
|
|
||||||
return steam_available;
|
return steam_available;
|
||||||
@@ -59,13 +59,13 @@ function unlock_achievement(achievement_name) {
|
|||||||
// Check if already unlocked
|
// Check if already unlocked
|
||||||
var unlocked = steam.achievement.achievement_get(achievement_name);
|
var unlocked = steam.achievement.achievement_get(achievement_name);
|
||||||
if (unlocked) {
|
if (unlocked) {
|
||||||
console.log("Achievement already unlocked:", achievement_name);
|
log.console("Achievement already unlocked:", achievement_name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock it
|
// Unlock it
|
||||||
if (steam.achievement.achievement_set(achievement_name)) {
|
if (steam.achievement.achievement_set(achievement_name)) {
|
||||||
console.log("Achievement unlocked:", achievement_name);
|
log.console("Achievement unlocked:", achievement_name);
|
||||||
|
|
||||||
// Store stats to make it permanent
|
// Store stats to make it permanent
|
||||||
steam.stats.stats_store();
|
steam.stats.stats_store();
|
||||||
@@ -87,7 +87,7 @@ function update_stat(stat_name, value, is_float) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
console.log("Stat updated:", stat_name, "=", value);
|
log.console("Stat updated:", stat_name, "=", value);
|
||||||
steam.stats.stats_store();
|
steam.stats.stats_store();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ function start_game() {
|
|||||||
total_score = get_stat(STATS.TOTAL_SCORE, false);
|
total_score = get_stat(STATS.TOTAL_SCORE, false);
|
||||||
current_score = 0;
|
current_score = 0;
|
||||||
|
|
||||||
console.log("Starting game #" + (games_played + 1));
|
log.console("Starting game #" + (games_played + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
function end_game(score) {
|
function end_game(score) {
|
||||||
@@ -167,7 +167,7 @@ function load_from_cloud() {
|
|||||||
function cleanup_steam() {
|
function cleanup_steam() {
|
||||||
if (steam_available) {
|
if (steam_available) {
|
||||||
steam.steam_shutdown();
|
steam.steam_shutdown();
|
||||||
console.log("Steam shut down");
|
log.console("Steam shut down");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ $_.receiver(function(msg) {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
response = {error: e.toString()};
|
response = {error: e.toString()};
|
||||||
console.error(e)
|
log.error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
send(msg, response);
|
send(msg, response);
|
||||||
@@ -436,11 +436,11 @@ function handle_renderer(msg) {
|
|||||||
|
|
||||||
var tex;
|
var tex;
|
||||||
// Direct surface data
|
// Direct surface data
|
||||||
console.log(json.encode(msg.data))
|
log.console(json.encode(msg.data))
|
||||||
var surf = new surface(msg.data)
|
var surf = new surface(msg.data)
|
||||||
|
|
||||||
console.log("GOT DATA")
|
log.console("GOT DATA")
|
||||||
console.log(json.encode(msg.data))
|
log.console(json.encode(msg.data))
|
||||||
|
|
||||||
if (!surf)
|
if (!surf)
|
||||||
throw new Error("Must provide surface_id or surface data")
|
throw new Error("Must provide surface_id or surface data")
|
||||||
@@ -528,7 +528,7 @@ function handle_texture(msg) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(json.encode(msg.data))
|
log.console(json.encode(msg.data))
|
||||||
return {error: "Must provide either surface_id or width/height"};
|
return {error: "Must provide either surface_id or width/height"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,70 @@
|
|||||||
(function engine() {
|
(function engine() {
|
||||||
prosperon.DOC = Symbol('+documentation+') // Symbol for documentation references
|
prosperon.DOC = Symbol('+documentation+') // Symbol for documentation references
|
||||||
|
|
||||||
globalThis.log = new Proxy({}, {
|
function caller_data(depth = 0)
|
||||||
|
{
|
||||||
|
var file = "nofile"
|
||||||
|
var line = 0
|
||||||
|
|
||||||
|
var caller = new Error().stack.split("\n")[1+depth]
|
||||||
|
if (caller) {
|
||||||
|
var md = caller.match(/\((.*)\:/)
|
||||||
|
var m = md ? md[1] : "SCRIPT"
|
||||||
|
if (m) file = m
|
||||||
|
md = caller.match(/\:(\d*)\)/)
|
||||||
|
m = md ? md[1] : 0
|
||||||
|
if (m) line = m
|
||||||
|
}
|
||||||
|
|
||||||
|
return {file,line}
|
||||||
|
}
|
||||||
|
|
||||||
|
function console_rec(line, file, msg) {
|
||||||
|
return `[${prosperon.id.slice(0,5)}] [${file}:${line}]: ${msg}\n`
|
||||||
|
|
||||||
|
var now = time.now()
|
||||||
|
|
||||||
|
var id = prosperon.name ? prosperon.name : prosperon.id
|
||||||
|
id = id.substring(0,6)
|
||||||
|
|
||||||
|
return `[${id}] [${time.text(now, "mb d yyyy h:nn:ss")}] ${file}:${line}: ${msg}\n`
|
||||||
|
}
|
||||||
|
|
||||||
|
var console_mod = prosperon.hidden.console
|
||||||
|
|
||||||
|
var logs = {}
|
||||||
|
logs.console = function(msg)
|
||||||
|
{
|
||||||
|
var caller = caller_data(4)
|
||||||
|
console_mod.print(console_rec(caller.line, caller.file, msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
logs.error = function(e)
|
||||||
|
{
|
||||||
|
if (!e)
|
||||||
|
e = new Error()
|
||||||
|
|
||||||
|
if (e instanceof Error)
|
||||||
|
pprint(`${e.name} : ${e.message}
|
||||||
|
${e.stack}`, 4)
|
||||||
|
else {
|
||||||
|
var stack = new Error()
|
||||||
|
pprint(`${e}
|
||||||
|
${stack.stack}`,4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logs.panic = function(msg)
|
||||||
|
{
|
||||||
|
pprint(e, 5)
|
||||||
|
os.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
|
globalThis.log = new Proxy(logs, {
|
||||||
get(target,prop,receiver) {
|
get(target,prop,receiver) {
|
||||||
return function() {}
|
if (target[prop])
|
||||||
|
return (...args) => args.forEach(arg => target[prop](arg))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -11,7 +72,7 @@ globalThis.log = new Proxy({}, {
|
|||||||
var hidden = prosperon.hidden
|
var hidden = prosperon.hidden
|
||||||
var actor_mod = hidden.actor
|
var actor_mod = hidden.actor
|
||||||
var wota = hidden.wota
|
var wota = hidden.wota
|
||||||
var console_mod = hidden.console
|
|
||||||
var use_embed = hidden.use_embed
|
var use_embed = hidden.use_embed
|
||||||
var use_dyn = hidden.use_dyn
|
var use_dyn = hidden.use_dyn
|
||||||
var enet = hidden.enet
|
var enet = hidden.enet
|
||||||
@@ -25,8 +86,6 @@ var js = use_embed('js')
|
|||||||
|
|
||||||
var io = use_embed('io')
|
var io = use_embed('io')
|
||||||
|
|
||||||
globalThis.console = console_mod
|
|
||||||
|
|
||||||
var RESPATH = 'scripts/modules/resources.js'
|
var RESPATH = 'scripts/modules/resources.js'
|
||||||
var canonical = io.realdir(RESPATH) + 'resources.js'
|
var canonical = io.realdir(RESPATH) + 'resources.js'
|
||||||
var content = io.slurp(RESPATH)
|
var content = io.slurp(RESPATH)
|
||||||
@@ -40,10 +99,10 @@ function print_api(obj) {
|
|||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
if (!obj.hasOwnProperty(prop)) continue
|
if (!obj.hasOwnProperty(prop)) continue
|
||||||
var val = obj[prop]
|
var val = obj[prop]
|
||||||
console.log(prop)
|
log.console(prop)
|
||||||
if (typeof val === 'function') {
|
if (typeof val === 'function') {
|
||||||
var m = val.toString().match(/\(([^)]*)\)/)
|
var m = val.toString().match(/\(([^)]*)\)/)
|
||||||
if (m) console.log(' function: ' + prop + '(' + m[1].trim() + ')')
|
if (m) log.console(' function: ' + prop + '(' + m[1].trim() + ')')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,84 +114,6 @@ prosperon.PATH = [
|
|||||||
|
|
||||||
var res_cache = {}
|
var res_cache = {}
|
||||||
|
|
||||||
function console_rec(category, priority, line, file, msg) {
|
|
||||||
return `[${prosperon.id.slice(0,5)}] [${file}:${line}: [${category} ${priority}]: ${msg}\n`
|
|
||||||
|
|
||||||
var now = time.now()
|
|
||||||
|
|
||||||
var id = prosperon.name ? prosperon.name : prosperon.id
|
|
||||||
id = id.substring(0,6)
|
|
||||||
|
|
||||||
return `[${id}] [${time.text(now, "mb d yyyy h:nn:ss")}] ${file}:${line}: [${category} ${priority}]: ${msg}\n`
|
|
||||||
}
|
|
||||||
|
|
||||||
function pprint(msg, lvl = 0) {
|
|
||||||
var file = "nofile"
|
|
||||||
var line = 0
|
|
||||||
|
|
||||||
var caller = new Error().stack.split("\n")[2]
|
|
||||||
if (caller) {
|
|
||||||
var md = caller.match(/\((.*)\:/)
|
|
||||||
var m = md ? md[1] : "SCRIPT"
|
|
||||||
if (m) file = m
|
|
||||||
md = caller.match(/\:(\d*)\)/)
|
|
||||||
m = md ? md[1] : 0
|
|
||||||
if (m) line = m
|
|
||||||
}
|
|
||||||
var fmt = console_rec("script", lvl, line, file, msg)
|
|
||||||
console.print(fmt)
|
|
||||||
}
|
|
||||||
|
|
||||||
function format_args(...args) {
|
|
||||||
return args.map(arg => {
|
|
||||||
if (typeof arg === 'object' && arg !== null) {
|
|
||||||
try {
|
|
||||||
return json.encode(arg)
|
|
||||||
} catch (e) {
|
|
||||||
return String(arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return String(arg)
|
|
||||||
}).join(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
console.spam = function spam(...args) {
|
|
||||||
pprint(format_args(...args), 0)
|
|
||||||
}
|
|
||||||
console.debug = function debug(...args) {
|
|
||||||
pprint(format_args(...args), 1)
|
|
||||||
}
|
|
||||||
console.info = function info(...args) {
|
|
||||||
pprint(format_args(...args), 2)
|
|
||||||
}
|
|
||||||
console.warn = function warn(...args) {
|
|
||||||
pprint(format_args(...args), 3)
|
|
||||||
}
|
|
||||||
console.log = function log(...args) {
|
|
||||||
pprint(format_args(...args), 2)
|
|
||||||
}
|
|
||||||
console.error = function error(e) {
|
|
||||||
if (!e)
|
|
||||||
e = new Error()
|
|
||||||
|
|
||||||
if (e instanceof Error)
|
|
||||||
pprint(`${e.name} : ${e.message}
|
|
||||||
${e.stack}`, 4)
|
|
||||||
else {
|
|
||||||
var stack = new Error()
|
|
||||||
pprint(`${e}
|
|
||||||
${stack.stack}`,4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.panic = function panic(e) {
|
|
||||||
pprint(e, 5)
|
|
||||||
os.quit()
|
|
||||||
}
|
|
||||||
|
|
||||||
console.assert = function assert(op, str = `assertion failed [value '${op}']`) {
|
|
||||||
if (!op) console.panic(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
var BASEPATH = 'scripts/core/base.js'
|
var BASEPATH = 'scripts/core/base.js'
|
||||||
var script = io.slurp(BASEPATH)
|
var script = io.slurp(BASEPATH)
|
||||||
var fnname = "base"
|
var fnname = "base"
|
||||||
@@ -350,7 +331,7 @@ var service_delay = 0.01
|
|||||||
$_.portal = function(fn, port) {
|
$_.portal = function(fn, port) {
|
||||||
if (portal) throw new Error(`Already started a portal listening on ${portal.port}`)
|
if (portal) throw new Error(`Already started a portal listening on ${portal.port}`)
|
||||||
if (!port) throw new Error("Requires a valid port.")
|
if (!port) throw new Error("Requires a valid port.")
|
||||||
console.log(`starting a portal on port ${port}`)
|
log.console(`starting a portal on port ${port}`)
|
||||||
portal = enet.create_host({address: "any", port})
|
portal = enet.create_host({address: "any", port})
|
||||||
portal_fn = fn
|
portal_fn = fn
|
||||||
}
|
}
|
||||||
@@ -359,23 +340,23 @@ $_.portal[prosperon.DOC] = "A portal is a special actor with a public address th
|
|||||||
function handle_host(e) {
|
function handle_host(e) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case "connect":
|
case "connect":
|
||||||
console.log(`connected a new peer: ${e.peer.address}:${e.peer.port}`)
|
log.console(`connected a new peer: ${e.peer.address}:${e.peer.port}`)
|
||||||
peers[`${e.peer.address}:${e.peer.port}`] = e.peer
|
peers[`${e.peer.address}:${e.peer.port}`] = e.peer
|
||||||
var queue = peer_queue.get(e.peer)
|
var queue = peer_queue.get(e.peer)
|
||||||
if (queue) {
|
if (queue) {
|
||||||
for (var msg of queue) e.peer.send(nota.encode(msg))
|
for (var msg of queue) e.peer.send(nota.encode(msg))
|
||||||
console.log(`sent ${json.encode(msg)} out of queue`)
|
log.console(`sent ${json.encode(msg)} out of queue`)
|
||||||
peer_queue.delete(e.peer)
|
peer_queue.delete(e.peer)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "disconnect":
|
case "disconnect":
|
||||||
peer_queue.delete(e.peer)
|
peer_queue.delete(e.peer)
|
||||||
for (var id in peers) if (peers[id] === e.peer) delete peers[id]
|
for (var id in peers) if (peers[id] === e.peer) delete peers[id]
|
||||||
console.log('portal got disconnect from ' + e.peer.address + ":" + e.peer.port)
|
log.console('portal got disconnect from ' + e.peer.address + ":" + e.peer.port)
|
||||||
break
|
break
|
||||||
case "receive":
|
case "receive":
|
||||||
var data = nota.decode(e.data)
|
var data = nota.decode(e.data)
|
||||||
// console.log(`got message ${json.encode(data)} over the wire`)
|
// log.console(`got message ${json.encode(data)} over the wire`)
|
||||||
if (data.replycc && !data.replycc.address) {
|
if (data.replycc && !data.replycc.address) {
|
||||||
data.replycc.__ACTORDATA__.address = e.peer.address
|
data.replycc.__ACTORDATA__.address = e.peer.address
|
||||||
data.replycc.__ACTORDATA__.port = e.peer.port
|
data.replycc.__ACTORDATA__.port = e.peer.port
|
||||||
@@ -394,7 +375,7 @@ function handle_host(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.data) populate_actor_addresses(data.data)
|
if (data.data) populate_actor_addresses(data.data)
|
||||||
// console.log(`turned it into ${json.encode(data)} over the wire`)
|
// log.console(`turned it into ${json.encode(data)} over the wire`)
|
||||||
handle_message(data)
|
handle_message(data)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -414,7 +395,7 @@ $_.receiver[prosperon.DOC] = "registers a function that will receive all message
|
|||||||
|
|
||||||
$_.start = function start(cb, prg, arg) {
|
$_.start = function start(cb, prg, arg) {
|
||||||
if (dying) {
|
if (dying) {
|
||||||
console.warn(`Cannot start an underling in the same turn as we're stopping`)
|
log.warn(`Cannot start an underling in the same turn as we're stopping`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var id = util.guid()
|
var id = util.guid()
|
||||||
@@ -458,7 +439,7 @@ $_.delay[prosperon.DOC] = "used to schedule the invocation of a function..."
|
|||||||
|
|
||||||
var couplings = new Set()
|
var couplings = new Set()
|
||||||
$_.couple = function couple(actor) {
|
$_.couple = function couple(actor) {
|
||||||
console.log(`coupled to ${actor.__ACTORDATA__.id}`)
|
log.console(`coupled to ${actor.__ACTORDATA__.id}`)
|
||||||
couplings.add(actor.__ACTORDATA__.id)
|
couplings.add(actor.__ACTORDATA__.id)
|
||||||
}
|
}
|
||||||
$_.couple[prosperon.DOC] = "causes this actor to stop when another actor stops."
|
$_.couple[prosperon.DOC] = "causes this actor to stop when another actor stops."
|
||||||
@@ -496,11 +477,11 @@ function actor_send(actor, message) {
|
|||||||
var peer = peers[actor.__ACTORDATA__.address + ":" + actor.__ACTORDATA__.port]
|
var peer = peers[actor.__ACTORDATA__.address + ":" + actor.__ACTORDATA__.port]
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
if (!portal) {
|
if (!portal) {
|
||||||
console.log(`creating a contactor ...`)
|
log.console(`creating a contactor ...`)
|
||||||
portal = enet.create_host({address:"any"})
|
portal = enet.create_host({address:"any"})
|
||||||
console.log(`allowing contact to port ${portal.port}`)
|
log.console(`allowing contact to port ${portal.port}`)
|
||||||
}
|
}
|
||||||
console.log(`no peer! connecting to ${actor.__ACTORDATA__.address}:${actor.__ACTORDATA__.port}`)
|
log.console(`no peer! connecting to ${actor.__ACTORDATA__.address}:${actor.__ACTORDATA__.port}`)
|
||||||
peer = portal.connect(actor.__ACTORDATA__.address, actor.__ACTORDATA__.port)
|
peer = portal.connect(actor.__ACTORDATA__.address, actor.__ACTORDATA__.port)
|
||||||
peer_queue.set(peer, [message])
|
peer_queue.set(peer, [message])
|
||||||
} else {
|
} else {
|
||||||
@@ -528,8 +509,8 @@ function send_messages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
console.error("Some messages failed to send:", errors)
|
log.error("Some messages failed to send:", errors)
|
||||||
for (var i of errors) console.error(i)
|
for (var i of errors) log.error(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,7 +588,7 @@ if (typeof prosperon.args.program !== 'string')
|
|||||||
actor_mod.setname(prosperon.args.program)
|
actor_mod.setname(prosperon.args.program)
|
||||||
|
|
||||||
function destroyself() {
|
function destroyself() {
|
||||||
console.log(`Got the message to destroy self.`)
|
log.console(`Got the message to destroy self.`)
|
||||||
dying = true
|
dying = true
|
||||||
for (var i of underlings)
|
for (var i of underlings)
|
||||||
$_.stop(create_actor({id:i}))
|
$_.stop(create_actor({id:i}))
|
||||||
@@ -621,7 +602,7 @@ function handle_actor_disconnect(id) {
|
|||||||
greeter({type: "stopped", id})
|
greeter({type: "stopped", id})
|
||||||
delete greeters[id]
|
delete greeters[id]
|
||||||
}
|
}
|
||||||
console.log(`actor ${id} disconnected`)
|
log.console(`actor ${id} disconnected`)
|
||||||
if (couplings.has(id)) $_.stop()
|
if (couplings.has(id)) $_.stop()
|
||||||
delete peers[id]
|
delete peers[id]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,13 +83,13 @@ Cmdline.register_order(
|
|||||||
"about",
|
"about",
|
||||||
function (argv) {
|
function (argv) {
|
||||||
if (!argv[0]) {
|
if (!argv[0]) {
|
||||||
console.print("About your game");
|
log.print("About your game");
|
||||||
console.print(`Prosperon version ${prosperon.version}`);
|
log.print(`Prosperon version ${prosperon.version}`);
|
||||||
console.print(`Total entities ${ur._list.length}`);
|
log.print(`Total entities ${ur._list.length}`);
|
||||||
}
|
}
|
||||||
switch (argv[0]) {
|
switch (argv[0]) {
|
||||||
case "entities":
|
case "entities":
|
||||||
for (var i of ur._list) console.print(i);
|
for (var i of ur._list) log.print(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -111,8 +111,8 @@ Cmdline.register_order(
|
|||||||
"input",
|
"input",
|
||||||
function (pawn) {
|
function (pawn) {
|
||||||
use("editor.js");
|
use("editor.js");
|
||||||
console.print(`## Input for ${pawn}`);
|
log.print(`## Input for ${pawn}`);
|
||||||
eval(`console.print(input.print_md_kbm(${pawn}));`);
|
eval(`log.print(input.print_md_kbm(${pawn}));`);
|
||||||
},
|
},
|
||||||
"Print input documentation for a given object as markdown. Give it a file to save the output to",
|
"Print input documentation for a given object as markdown. Give it a file to save the output to",
|
||||||
"OBJECT ?FILE?",
|
"OBJECT ?FILE?",
|
||||||
@@ -122,8 +122,8 @@ Cmdline.print_order = function (fn) {
|
|||||||
if (typeof fn === "string") fn = Cmdline.orders[fn];
|
if (typeof fn === "string") fn = Cmdline.orders[fn];
|
||||||
|
|
||||||
if (!fn) return;
|
if (!fn) return;
|
||||||
console.print(`Usage: prosperon ${fn.usage}` + "\n");
|
log.print(`Usage: prosperon ${fn.usage}` + "\n");
|
||||||
console.print(fn.doc + "\n");
|
log.print(fn.doc + "\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
function parse_args(argv)
|
function parse_args(argv)
|
||||||
@@ -198,7 +198,7 @@ Cmdline.register_order(
|
|||||||
var orfn = Cmdline.orders[order];
|
var orfn = Cmdline.orders[order];
|
||||||
|
|
||||||
if (!orfn) {
|
if (!orfn) {
|
||||||
console.warn(`No command named ${order}.`);
|
log.warn(`No command named ${order}.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ Cmdline.register_order(
|
|||||||
|
|
||||||
Cmdline.print_order("help");
|
Cmdline.print_order("help");
|
||||||
|
|
||||||
for (var cmd of Object.keys(Cmdline.orders).sort()) console.print(cmd + "\n");
|
for (var cmd of Object.keys(Cmdline.orders).sort()) log.print(cmd + "\n");
|
||||||
|
|
||||||
Cmdline.orders.version();
|
Cmdline.orders.version();
|
||||||
},
|
},
|
||||||
@@ -219,7 +219,7 @@ Cmdline.register_order(
|
|||||||
Cmdline.register_order(
|
Cmdline.register_order(
|
||||||
"version",
|
"version",
|
||||||
function () {
|
function () {
|
||||||
console.print(`Prosperon version ${prosperon.version} [${prosperon.revision}]` + "\n");
|
log.print(`Prosperon version ${prosperon.version} [${prosperon.revision}]` + "\n");
|
||||||
},
|
},
|
||||||
"Display Prosperon info.",
|
"Display Prosperon info.",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ Docstrings are set to the symbol \`prosperon.DOC\`
|
|||||||
|
|
||||||
\`\`\`js
|
\`\`\`js
|
||||||
// Suppose we have a module that returns a function
|
// Suppose we have a module that returns a function
|
||||||
function greet(name) { console.log("Hello, " + name) }
|
function greet(name) { log.console("Hello, " + name) }
|
||||||
|
|
||||||
// We can attach a docstring
|
// We can attach a docstring
|
||||||
greet.doc = \`
|
greet.doc = \`
|
||||||
@@ -299,7 +299,7 @@ return greet
|
|||||||
\`\`\`js
|
\`\`\`js
|
||||||
// Another way is to add a docstring object to an object
|
// Another way is to add a docstring object to an object
|
||||||
var greet = {
|
var greet = {
|
||||||
hello() { console.log('hello!') }
|
hello() { log.console('hello!') }
|
||||||
}
|
}
|
||||||
|
|
||||||
greet[prosperon.DOC] = {}
|
greet[prosperon.DOC] = {}
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ var Player = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
print_pawns() {
|
print_pawns() {
|
||||||
[...this.pawns].reverse().forEach(x => console.log(x))
|
[...this.pawns].reverse().forEach(x => log.console(x))
|
||||||
},
|
},
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ ex.garbage = function()
|
|||||||
ex.update = function(dt)
|
ex.update = function(dt)
|
||||||
{
|
{
|
||||||
for (var e of ex.emitters)
|
for (var e of ex.emitters)
|
||||||
try { e.step(dt) } catch(e) { console.error(e) }
|
try { e.step(dt) } catch(e) { log.error(e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
ex.step_hook = function(p)
|
ex.step_hook = function(p)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ var sprite = {
|
|||||||
set path(p) {
|
set path(p) {
|
||||||
var image = graphics.texture(p);
|
var image = graphics.texture(p);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
console.warn(`Could not find image ${p}.`);
|
log.warn(`Could not find image ${p}.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ var sprite = {
|
|||||||
t.parent = undefined
|
t.parent = undefined
|
||||||
delete this.transform.sprite
|
delete this.transform.sprite
|
||||||
delete this._sprite
|
delete this._sprite
|
||||||
// console.log("CLEARED SPRITE")
|
// log.console("CLEARED SPRITE")
|
||||||
},
|
},
|
||||||
anchor: [0, 0],
|
anchor: [0, 0],
|
||||||
set layer(v) { this._sprite.layer = v; },
|
set layer(v) { this._sprite.layer = v; },
|
||||||
|
|||||||
@@ -41,17 +41,17 @@ Object.defineProperties(graphics.Image.prototype, {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Send message to load texture
|
// Send message to load texture
|
||||||
console.log("LOADING")
|
log.console("LOADING")
|
||||||
send(renderer_actor, {
|
send(renderer_actor, {
|
||||||
kind: "renderer",
|
kind: "renderer",
|
||||||
id: renderer_id,
|
id: renderer_id,
|
||||||
op: "loadTexture",
|
op: "loadTexture",
|
||||||
data: this[CPU]
|
data: this[CPU]
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
console.log("GOT MSG")
|
log.console("GOT MSG")
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to load texture:")
|
log.error("Failed to load texture:")
|
||||||
console.error(response.error)
|
log.error(response.error)
|
||||||
self[LOADING] = false;
|
self[LOADING] = false;
|
||||||
} else {
|
} else {
|
||||||
self[GPU] = response;
|
self[GPU] = response;
|
||||||
@@ -190,7 +190,7 @@ function create_image(path){
|
|||||||
throw new Error('Unsupported image structure from decoder');
|
throw new Error('Unsupported image structure from decoder');
|
||||||
|
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.error(`Error loading image ${path}: ${e.message}`);
|
log.error(`Error loading image ${path}: ${e.message}`);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,14 +296,14 @@ graphics.texture.total_vram[prosperon.DOC] = `
|
|||||||
`
|
`
|
||||||
|
|
||||||
graphics.tex_hotreload = function tex_hotreload(file) {
|
graphics.tex_hotreload = function tex_hotreload(file) {
|
||||||
console.log(`hot reloading ${file}`)
|
log.console(`hot reloading ${file}`)
|
||||||
if (!(file in graphics.texture.cache)) return
|
if (!(file in graphics.texture.cache)) return
|
||||||
console.log('really doing it')
|
log.console('really doing it')
|
||||||
|
|
||||||
var img = create_image(file)
|
var img = create_image(file)
|
||||||
var oldimg = graphics.texture.cache[file]
|
var oldimg = graphics.texture.cache[file]
|
||||||
console.log(`new image:${json.encode(img)}`)
|
log.console(`new image:${json.encode(img)}`)
|
||||||
console.log(`old image: ${json.encode(oldimg)}`)
|
log.console(`old image: ${json.encode(oldimg)}`)
|
||||||
|
|
||||||
merge_objects(oldimg, img, ['surface', 'texture', 'loop', 'time'])
|
merge_objects(oldimg, img, ['surface', 'texture', 'loop', 'time'])
|
||||||
}
|
}
|
||||||
@@ -356,7 +356,7 @@ graphics.get_font = function get_font(path, size) {
|
|||||||
data: font.surface
|
data: font.surface
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to load font texture:", response.error);
|
log.error("Failed to load font texture:", response.error);
|
||||||
} else {
|
} else {
|
||||||
font.texture = response;
|
font.texture = response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ imgui.prosperon_menu = function prosperon_menu() {
|
|||||||
if (render_menu) {
|
if (render_menu) {
|
||||||
if (debug.console)
|
if (debug.console)
|
||||||
debug.console = imgui.window("console", _ => {
|
debug.console = imgui.window("console", _ => {
|
||||||
imgui.text(console.transcript);
|
imgui.text(log.transcript);
|
||||||
replstr = imgui.textinput(undefined, replstr);
|
replstr = imgui.textinput(undefined, replstr);
|
||||||
imgui.button("submit", _ => {
|
imgui.button("submit", _ => {
|
||||||
eval(replstr);
|
eval(replstr);
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ function eachobj(obj, fn) {
|
|||||||
var val = fn(obj)
|
var val = fn(obj)
|
||||||
if (val) return val
|
if (val) return val
|
||||||
for (var o in obj.objects) {
|
for (var o in obj.objects) {
|
||||||
if (obj.objects[o] === obj) console.error(`Object ${obj.toString()} is referenced by itself.`)
|
if (obj.objects[o] === obj) log.error(`Object ${obj.toString()} is referenced by itself.`)
|
||||||
val = eachobj(obj.objects[o], fn)
|
val = eachobj(obj.objects[o], fn)
|
||||||
if (val) return val
|
if (val) return val
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ var dir = args[0]
|
|||||||
if (!io.exists(args[0] + '/main.js'))
|
if (!io.exists(args[0] + '/main.js'))
|
||||||
throw Error(`No main.js found in ${args[0]}`)
|
throw Error(`No main.js found in ${args[0]}`)
|
||||||
|
|
||||||
console.log('starting game in ' + dir)
|
log.console('starting game in ' + dir)
|
||||||
|
|
||||||
io.mount(dir)
|
io.mount(dir)
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ send(video_actor, {
|
|||||||
}
|
}
|
||||||
}, e => {
|
}, e => {
|
||||||
if (e.error) {
|
if (e.error) {
|
||||||
console.error(e.error)
|
log.error(e.error)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,14 +100,14 @@ send(video_actor, {
|
|||||||
id:window
|
id:window
|
||||||
}, e => {
|
}, e => {
|
||||||
if (e.error) {
|
if (e.error) {
|
||||||
console.error(e.error)
|
log.error(e.error)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
render = e.id
|
render = e.id
|
||||||
graphics = use('graphics', video_actor, e.id)
|
graphics = use('graphics', video_actor, e.id)
|
||||||
|
|
||||||
console.log(`Created window and renderer id ${render}`)
|
log.console(`Created window and renderer id ${render}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var Blob = use('blob')
|
|||||||
|
|
||||||
var pp = new Blob()
|
var pp = new Blob()
|
||||||
|
|
||||||
console.log(pp.length)
|
log.console(pp.length)
|
||||||
|
|
||||||
// If you're testing in an environment without a 'use' loader, you might do
|
// If you're testing in an environment without a 'use' loader, you might do
|
||||||
// something like importing the compiled C module or linking it differently.
|
// something like importing the compiled C module or linking it differently.
|
||||||
@@ -150,7 +150,7 @@ let tests = [
|
|||||||
let b = new Blob();
|
let b = new Blob();
|
||||||
let length = b.length;
|
let length = b.length;
|
||||||
let passed = (b instanceof Blob && length === 0);
|
let passed = (b instanceof Blob && length === 0);
|
||||||
console.log(`blob len: ${b.length}, is blob? ${b instanceof Blob}`)
|
log.console(`blob len: ${b.length}, is blob? ${b instanceof Blob}`)
|
||||||
let messages = [];
|
let messages = [];
|
||||||
if (!(b instanceof Blob)) messages.push("Returned object is not recognized as a blob");
|
if (!(b instanceof Blob)) messages.push("Returned object is not recognized as a blob");
|
||||||
if (length !== 0) messages.push(`Expected length 0, got ${length}`);
|
if (length !== 0) messages.push(`Expected length 0, got ${length}`);
|
||||||
@@ -618,18 +618,18 @@ for (let i = 0; i < tests.length; i++) {
|
|||||||
let passedCount = 0;
|
let passedCount = 0;
|
||||||
for (let r of results) {
|
for (let r of results) {
|
||||||
let status = r.passed ? "Passed" : "Failed";
|
let status = r.passed ? "Passed" : "Failed";
|
||||||
console.log(`${r.testName} - ${status}`);
|
log.console(`${r.testName} - ${status}`);
|
||||||
if (!r.passed && r.messages.length > 0) {
|
if (!r.passed && r.messages.length > 0) {
|
||||||
console.log(" " + r.messages.join("\n "));
|
log.console(" " + r.messages.join("\n "));
|
||||||
}
|
}
|
||||||
if (r.passed) passedCount++;
|
if (r.passed) passedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\nResult: ${passedCount}/${results.length} tests passed`);
|
log.console(`\nResult: ${passedCount}/${results.length} tests passed`);
|
||||||
if (passedCount < results.length) {
|
if (passedCount < results.length) {
|
||||||
console.log("Overall: FAILED");
|
log.console("Overall: FAILED");
|
||||||
if (os && os.exit) os.exit(1);
|
if (os && os.exit) os.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.log("Overall: PASSED");
|
log.console("Overall: PASSED");
|
||||||
if (os && os.exit) os.exit(0);
|
if (os && os.exit) os.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ function loop()
|
|||||||
sprite.forEach(x => x.move(x.dir.scale(dt)))
|
sprite.forEach(x => x.move(x.dir.scale(dt)))
|
||||||
var queue = sprite.queue()
|
var queue = sprite.queue()
|
||||||
|
|
||||||
//console.log(json.encode(queue))
|
//log.console(json.encode(queue))
|
||||||
|
|
||||||
for (var q of queue) {
|
for (var q of queue) {
|
||||||
if (!q.image) continue
|
if (!q.image) continue
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ var json = use('json');
|
|||||||
// Get list of cameras
|
// Get list of cameras
|
||||||
var cameras = camera.list();
|
var cameras = camera.list();
|
||||||
if (cameras.length === 0) {
|
if (cameras.length === 0) {
|
||||||
console.log("No cameras found!");
|
log.console("No cameras found!");
|
||||||
$_. stop();
|
$_. stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cam_id = cameras[0];
|
var cam_id = cameras[0];
|
||||||
console.log("Testing camera:", camera.name(cam_id));
|
log.console("Testing camera:", camera.name(cam_id));
|
||||||
|
|
||||||
// Get supported formats
|
// Get supported formats
|
||||||
var formats = camera.supported_formats(cam_id);
|
var formats = camera.supported_formats(cam_id);
|
||||||
console.log("\nLooking for different colorspaces in supported formats...");
|
log.console("\nLooking for different colorspaces in supported formats...");
|
||||||
|
|
||||||
// Group formats by colorspace
|
// Group formats by colorspace
|
||||||
var colorspaces = {};
|
var colorspaces = {};
|
||||||
@@ -26,21 +26,21 @@ for (var i = 0; i < formats.length; i++) {
|
|||||||
colorspaces[fmt.colorspace].push(fmt);
|
colorspaces[fmt.colorspace].push(fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nFound colorspaces:");
|
log.console("\nFound colorspaces:");
|
||||||
for (var cs in colorspaces) {
|
for (var cs in colorspaces) {
|
||||||
console.log(" " + cs + ": " + colorspaces[cs].length + " formats");
|
log.console(" " + cs + ": " + colorspaces[cs].length + " formats");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try opening camera with different colorspaces
|
// Try opening camera with different colorspaces
|
||||||
console.log("\nTrying to open camera with different colorspaces...");
|
log.console("\nTrying to open camera with different colorspaces...");
|
||||||
|
|
||||||
for (var cs in colorspaces) {
|
for (var cs in colorspaces) {
|
||||||
// Get first format for this colorspace
|
// Get first format for this colorspace
|
||||||
var format = colorspaces[cs][0];
|
var format = colorspaces[cs][0];
|
||||||
|
|
||||||
console.log("\nTrying colorspace '" + cs + "' with format:");
|
log.console("\nTrying colorspace '" + cs + "' with format:");
|
||||||
console.log(" Resolution: " + format.width + "x" + format.height);
|
log.console(" Resolution: " + format.width + "x" + format.height);
|
||||||
console.log(" Pixel format: " + format.format);
|
log.console(" Pixel format: " + format.format);
|
||||||
|
|
||||||
// You can also create a custom format with a specific colorspace
|
// You can also create a custom format with a specific colorspace
|
||||||
var custom_format = {
|
var custom_format = {
|
||||||
@@ -55,18 +55,18 @@ for (var cs in colorspaces) {
|
|||||||
var cam = camera.open(cam_id, custom_format);
|
var cam = camera.open(cam_id, custom_format);
|
||||||
if (cam) {
|
if (cam) {
|
||||||
var actual = cam.get_format();
|
var actual = cam.get_format();
|
||||||
console.log(" Opened successfully!");
|
log.console(" Opened successfully!");
|
||||||
console.log(" Actual colorspace: " + actual.colorspace);
|
log.console(" Actual colorspace: " + actual.colorspace);
|
||||||
|
|
||||||
// Camera will be closed when object is freed
|
// Camera will be closed when object is freed
|
||||||
cam = null;
|
cam = null;
|
||||||
} else {
|
} else {
|
||||||
console.log(" Failed to open with this colorspace");
|
log.console(" Failed to open with this colorspace");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just test first 3 colorspaces
|
// Just test first 3 colorspaces
|
||||||
if (Object.keys(colorspaces).indexOf(cs) >= 2) break;
|
if (Object.keys(colorspaces).indexOf(cs) >= 2) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nColorspace test complete!");
|
log.console("\nColorspace test complete!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
@@ -6,35 +6,35 @@ var json = use('json');
|
|||||||
// Get first camera
|
// Get first camera
|
||||||
var cameras = camera.list();
|
var cameras = camera.list();
|
||||||
if (cameras.length === 0) {
|
if (cameras.length === 0) {
|
||||||
console.log("No cameras found!");
|
log.console("No cameras found!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cam_id = cameras[0];
|
var cam_id = cameras[0];
|
||||||
console.log("Using camera:", camera.name(cam_id));
|
log.console("Using camera:", camera.name(cam_id));
|
||||||
|
|
||||||
// Open camera with default settings
|
// Open camera with default settings
|
||||||
var cam = camera.open(cam_id);
|
var cam = camera.open(cam_id);
|
||||||
if (!cam) {
|
if (!cam) {
|
||||||
console.log("Failed to open camera!");
|
log.console("Failed to open camera!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the format being used
|
// Get the format being used
|
||||||
var format = cam.get_format();
|
var format = cam.get_format();
|
||||||
console.log("\nCamera format:");
|
log.console("\nCamera format:");
|
||||||
console.log(" Resolution:", format.width + "x" + format.height);
|
log.console(" Resolution:", format.width + "x" + format.height);
|
||||||
console.log(" Pixel format:", format.format);
|
log.console(" Pixel format:", format.format);
|
||||||
console.log(" Colorspace:", format.colorspace);
|
log.console(" Colorspace:", format.colorspace);
|
||||||
|
|
||||||
// Handle camera approval
|
// Handle camera approval
|
||||||
var approved = false;
|
var approved = false;
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
if (e.type === 'camera_device_approved') {
|
if (e.type === 'camera_device_approved') {
|
||||||
console.log("\nCamera approved!");
|
log.console("\nCamera approved!");
|
||||||
approved = true;
|
approved = true;
|
||||||
} else if (e.type === 'camera_device_denied') {
|
} else if (e.type === 'camera_device_denied') {
|
||||||
console.error("Camera access denied!");
|
log.error("Camera access denied!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -46,59 +46,59 @@ function capture_test() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nCapturing frame...");
|
log.console("\nCapturing frame...");
|
||||||
var surf = cam.capture();
|
var surf = cam.capture();
|
||||||
|
|
||||||
if (!surf) {
|
if (!surf) {
|
||||||
console.log("No frame captured yet, retrying...");
|
log.console("No frame captured yet, retrying...");
|
||||||
$_.delay(capture_test, 0.1);
|
$_.delay(capture_test, 0.1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nCaptured surface:");
|
log.console("\nCaptured surface:");
|
||||||
console.log(" Size:", surf.width + "x" + surf.height);
|
log.console(" Size:", surf.width + "x" + surf.height);
|
||||||
console.log(" Format:", surf.format);
|
log.console(" Format:", surf.format);
|
||||||
|
|
||||||
// Test various colorspace conversions
|
// Test various colorspace conversions
|
||||||
console.log("\nTesting colorspace conversions:");
|
log.console("\nTesting colorspace conversions:");
|
||||||
|
|
||||||
// Convert to sRGB if not already
|
// Convert to sRGB if not already
|
||||||
if (format.colorspace !== "srgb") {
|
if (format.colorspace !== "srgb") {
|
||||||
try {
|
try {
|
||||||
var srgb_surf = surf.convert(surf.format, "srgb");
|
var srgb_surf = surf.convert(surf.format, "srgb");
|
||||||
console.log(" Converted to sRGB colorspace");
|
log.console(" Converted to sRGB colorspace");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(" sRGB conversion failed:", e.message);
|
log.console(" sRGB conversion failed:", e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to linear sRGB for processing
|
// Convert to linear sRGB for processing
|
||||||
try {
|
try {
|
||||||
var linear_surf = surf.convert("rgba8888", "srgb_linear");
|
var linear_surf = surf.convert("rgba8888", "srgb_linear");
|
||||||
console.log(" Converted to linear sRGB (RGBA8888) for processing");
|
log.console(" Converted to linear sRGB (RGBA8888) for processing");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(" Linear sRGB conversion failed:", e.message);
|
log.console(" Linear sRGB conversion failed:", e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to JPEG colorspace (common for compression)
|
// Convert to JPEG colorspace (common for compression)
|
||||||
try {
|
try {
|
||||||
var jpeg_surf = surf.convert("rgb888", "jpeg");
|
var jpeg_surf = surf.convert("rgb888", "jpeg");
|
||||||
console.log(" Converted to JPEG colorspace (RGB888) for compression");
|
log.console(" Converted to JPEG colorspace (RGB888) for compression");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(" JPEG colorspace conversion failed:", e.message);
|
log.console(" JPEG colorspace conversion failed:", e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If YUV format, try BT.709 (HD video standard)
|
// If YUV format, try BT.709 (HD video standard)
|
||||||
if (surf.format.indexOf("yuv") !== -1 || surf.format.indexOf("yuy") !== -1) {
|
if (surf.format.indexOf("yuv") !== -1 || surf.format.indexOf("yuy") !== -1) {
|
||||||
try {
|
try {
|
||||||
var hd_surf = surf.convert(surf.format, "bt709_limited");
|
var hd_surf = surf.convert(surf.format, "bt709_limited");
|
||||||
console.log(" Converted to BT.709 limited (HD video standard)");
|
log.console(" Converted to BT.709 limited (HD video standard)");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(" BT.709 conversion failed:", e.message);
|
log.console(" BT.709 conversion failed:", e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nTest complete!");
|
log.console("\nTest complete!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,38 +3,38 @@ var camera = use('camera');
|
|||||||
|
|
||||||
// Get camera drivers
|
// Get camera drivers
|
||||||
var drivers = camera.drivers();
|
var drivers = camera.drivers();
|
||||||
console.log("Available camera drivers:", drivers);
|
log.console("Available camera drivers:", drivers);
|
||||||
|
|
||||||
// Get list of cameras
|
// Get list of cameras
|
||||||
var cameras = camera.list();
|
var cameras = camera.list();
|
||||||
console.log("Found", cameras.length, "cameras");
|
log.console("Found", cameras.length, "cameras");
|
||||||
|
|
||||||
// Get info about each camera
|
// Get info about each camera
|
||||||
for (var i = 0; i < cameras.length; i++) {
|
for (var i = 0; i < cameras.length; i++) {
|
||||||
var cam_id = cameras[i];
|
var cam_id = cameras[i];
|
||||||
console.log("\nCamera", i + 1, "ID:", cam_id);
|
log.console("\nCamera", i + 1, "ID:", cam_id);
|
||||||
console.log(" Name:", camera.name(cam_id));
|
log.console(" Name:", camera.name(cam_id));
|
||||||
console.log(" Position:", camera.position(cam_id));
|
log.console(" Position:", camera.position(cam_id));
|
||||||
|
|
||||||
// Get supported formats
|
// Get supported formats
|
||||||
var formats = camera.supported_formats(cam_id);
|
var formats = camera.supported_formats(cam_id);
|
||||||
console.log(" Supported formats:", formats.length);
|
log.console(" Supported formats:", formats.length);
|
||||||
|
|
||||||
// Show first few formats
|
// Show first few formats
|
||||||
for (var j = 0; j < formats.length; j++) {
|
for (var j = 0; j < formats.length; j++) {
|
||||||
var fmt = formats[j];
|
var fmt = formats[j];
|
||||||
console.log(" Format", j + 1 + ":");
|
log.console(" Format", j + 1 + ":");
|
||||||
console.log(" Pixel format:", fmt.format);
|
log.console(" Pixel format:", fmt.format);
|
||||||
console.log(" Resolution:", fmt.width + "x" + fmt.height);
|
log.console(" Resolution:", fmt.width + "x" + fmt.height);
|
||||||
console.log(" FPS:", fmt.framerate_numerator + "/" + fmt.framerate_denominator,
|
log.console(" FPS:", fmt.framerate_numerator + "/" + fmt.framerate_denominator,
|
||||||
"(" + (fmt.framerate_numerator / fmt.framerate_denominator) + ")");
|
"(" + (fmt.framerate_numerator / fmt.framerate_denominator) + ")");
|
||||||
console.log(" Colorspace:", fmt.colorspace);
|
log.console(" Colorspace:", fmt.colorspace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the first camera with a specific format if available
|
// Open the first camera with a specific format if available
|
||||||
if (cameras.length > 0) {
|
if (cameras.length > 0) {
|
||||||
console.log("\nOpening first camera...");
|
log.console("\nOpening first camera...");
|
||||||
var cam_id = cameras[0];
|
var cam_id = cameras[0];
|
||||||
var formats = camera.supported_formats(cam_id);
|
var formats = camera.supported_formats(cam_id);
|
||||||
|
|
||||||
@@ -49,25 +49,25 @@ if (cameras.length > 0) {
|
|||||||
|
|
||||||
var cam;
|
var cam;
|
||||||
if (preferred_format) {
|
if (preferred_format) {
|
||||||
console.log("Opening with 640x480 format...");
|
log.console("Opening with 640x480 format...");
|
||||||
cam = camera.open(cam_id, preferred_format);
|
cam = camera.open(cam_id, preferred_format);
|
||||||
} else {
|
} else {
|
||||||
console.log("Opening with default format...");
|
log.console("Opening with default format...");
|
||||||
cam = camera.open(cam_id);
|
cam = camera.open(cam_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cam) {
|
if (cam) {
|
||||||
console.log("Camera opened successfully!");
|
log.console("Camera opened successfully!");
|
||||||
console.log("Driver being used:", cam.get_driver());
|
log.console("Driver being used:", cam.get_driver());
|
||||||
|
|
||||||
// Get the actual format being used
|
// Get the actual format being used
|
||||||
var actual_format = cam.get_format();
|
var actual_format = cam.get_format();
|
||||||
console.log("Actual format being used:");
|
log.console("Actual format being used:");
|
||||||
console.log(" Pixel format:", actual_format.format);
|
log.console(" Pixel format:", actual_format.format);
|
||||||
console.log(" Resolution:", actual_format.width + "x" + actual_format.height);
|
log.console(" Resolution:", actual_format.width + "x" + actual_format.height);
|
||||||
console.log(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator,
|
log.console(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator,
|
||||||
"(" + (actual_format.framerate_numerator / actual_format.framerate_denominator) + ")");
|
"(" + (actual_format.framerate_numerator / actual_format.framerate_denominator) + ")");
|
||||||
console.log(" Colorspace:", actual_format.colorspace);
|
log.console(" Colorspace:", actual_format.colorspace);
|
||||||
|
|
||||||
// Clean up - camera will be closed when object is freed
|
// Clean up - camera will be closed when object is freed
|
||||||
cam = null;
|
cam = null;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ var parseq = use('parseq')
|
|||||||
|
|
||||||
function load_comment_from_api(id)
|
function load_comment_from_api(id)
|
||||||
{
|
{
|
||||||
console.log(`Loading comment #${id}`)
|
log.console(`Loading comment #${id}`)
|
||||||
return {
|
return {
|
||||||
id: id,
|
id: id,
|
||||||
title: `Comment #${id}`
|
title: `Comment #${id}`
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
function contact_fn(actor,reason) {
|
function contact_fn(actor,reason) {
|
||||||
if (actor) {
|
if (actor) {
|
||||||
console.log(`Got an actor: ${json.encode(actor)}`)
|
log.console(`Got an actor: ${json.encode(actor)}`)
|
||||||
|
|
||||||
send(actor, {greet: "Hello!"}, e => {
|
send(actor, {greet: "Hello!"}, e => {
|
||||||
console.log(`Got the response ${json.encode(e)}. Goodbye!`);
|
log.console(`Got the response ${json.encode(e)}. Goodbye!`);
|
||||||
$_.stop()
|
$_.stop()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
console.log(`Did not get an actor: ${json.encode(reason)}`)
|
log.console(`Did not get an actor: ${json.encode(reason)}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
$_.contact(contact_fn,
|
$_.contact(contact_fn,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ var count = 0
|
|||||||
function loop()
|
function loop()
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
console.log(`loop ${count}`);
|
log.console(`loop ${count}`);
|
||||||
if (count < 60)
|
if (count < 60)
|
||||||
$_.delay(loop, 0.01);
|
$_.delay(loop, 0.01);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var window_id = null;
|
|||||||
var renderer_id = null;
|
var renderer_id = null;
|
||||||
|
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
console.log(json.encode(e))
|
log.console(json.encode(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
@@ -26,12 +26,12 @@ send(video_actor, {
|
|||||||
}
|
}
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to create window:", response.error);
|
log.error("Failed to create window:", response.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window_id = response.id;
|
window_id = response.id;
|
||||||
console.log("Created window with id:", window_id);
|
log.console("Created window with id:", window_id);
|
||||||
|
|
||||||
// Create renderer
|
// Create renderer
|
||||||
send(video_actor, {
|
send(video_actor, {
|
||||||
@@ -40,12 +40,12 @@ send(video_actor, {
|
|||||||
id: window_id
|
id: window_id
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to create renderer:", response.error);
|
log.error("Failed to create renderer:", response.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer_id = response.id;
|
renderer_id = response.id;
|
||||||
console.log("Created renderer with id:", renderer_id);
|
log.console("Created renderer with id:", renderer_id);
|
||||||
|
|
||||||
// Configure draw2d and graphics
|
// Configure draw2d and graphics
|
||||||
draw2d = use('draw2d', video_actor, renderer_id)
|
draw2d = use('draw2d', video_actor, renderer_id)
|
||||||
@@ -220,7 +220,7 @@ function start_drawing() {
|
|||||||
if (frame < 600) { // Run for 10 seconds
|
if (frame < 600) { // Run for 10 seconds
|
||||||
$_.delay(draw_frame, 1/60);
|
$_.delay(draw_frame, 1/60);
|
||||||
} else {
|
} else {
|
||||||
console.log("Test completed - drew", frame, "frames");
|
log.console("Test completed - drew", frame, "frames");
|
||||||
$_.delay($_.stop, 0.5);
|
$_.delay($_.stop, 0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var render = use('render')
|
var render = use('render')
|
||||||
|
|
||||||
for (var i in render) console.log(i)
|
for (var i in render) log.console(i)
|
||||||
|
|
||||||
function loop()
|
function loop()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ var got = false
|
|||||||
var count = 0
|
var count = 0
|
||||||
http.fetch("https://dictionary.ink/find?word=theological", {
|
http.fetch("https://dictionary.ink/find?word=theological", {
|
||||||
on_data: e => {
|
on_data: e => {
|
||||||
console.log(e.length)
|
log.console(e.length)
|
||||||
count++
|
count++
|
||||||
},
|
},
|
||||||
callback: e => {
|
callback: e => {
|
||||||
for (var i in e) console.log(i)
|
for (var i in e) log.console(i)
|
||||||
console.log(e.data)
|
log.console(e.data)
|
||||||
got = true
|
got = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -23,7 +23,7 @@ while (!got) {
|
|||||||
http.poll()
|
http.poll()
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`got hit ${count} times`)
|
log.console(`got hit ${count} times`)
|
||||||
|
|
||||||
os.exit()
|
os.exit()
|
||||||
|
|
||||||
@@ -214,30 +214,30 @@ function processResults() {
|
|||||||
results.push({ testName, passed, messages });
|
results.push({ testName, passed, messages });
|
||||||
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
console.log(`\nDetailed Failure Report for ${testName}:`);
|
log.console(`\nDetailed Failure Report for ${testName}:`);
|
||||||
console.log(`URL: ${test.url}`);
|
log.console(`URL: ${test.url}`);
|
||||||
console.log(messages.join("\n"));
|
log.console(messages.join("\n"));
|
||||||
console.log("");
|
log.console("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log("\nTest Summary:");
|
log.console("\nTest Summary:");
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
console.log(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`);
|
log.console(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`);
|
||||||
if (!result.passed) {
|
if (!result.passed) {
|
||||||
console.log(result.messages.join("\n"));
|
log.console(result.messages.join("\n"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let passedCount = results.filter(r => r.passed).length;
|
let passedCount = results.filter(r => r.passed).length;
|
||||||
console.log(`\nResult: ${passedCount}/${testCount} tests passed`);
|
log.console(`\nResult: ${passedCount}/${testCount} tests passed`);
|
||||||
|
|
||||||
if (passedCount < testCount) {
|
if (passedCount < testCount) {
|
||||||
console.log("Overall: FAILED");
|
log.console("Overall: FAILED");
|
||||||
os.exit(1);
|
os.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.log("Overall: PASSED");
|
log.console("Overall: PASSED");
|
||||||
os.exit(0);
|
os.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function checkin()
|
|||||||
if (download_complete) return
|
if (download_complete) return
|
||||||
|
|
||||||
send(downloader, {type:'status'}, e => {
|
send(downloader, {type:'status'}, e => {
|
||||||
console.log("Status:", json.encode(e))
|
log.console("Status:", json.encode(e))
|
||||||
|
|
||||||
// Check if download is complete or error
|
// Check if download is complete or error
|
||||||
if (e.type === 'error' || (e.type === 'status_response' && e.status === 'idle')) {
|
if (e.type === 'error' || (e.type === 'status_response' && e.status === 'idle')) {
|
||||||
@@ -23,7 +23,7 @@ function checkin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
$_.start(e => {
|
$_.start(e => {
|
||||||
console.log(json.encode(e))
|
log.console(json.encode(e))
|
||||||
if (e.type === 'greet') {
|
if (e.type === 'greet') {
|
||||||
downloader = e.actor
|
downloader = e.actor
|
||||||
|
|
||||||
@@ -32,13 +32,13 @@ $_.start(e => {
|
|||||||
type:'download',
|
type:'download',
|
||||||
url: 'https://dictionary.ink/find?word=palm'
|
url: 'https://dictionary.ink/find?word=palm'
|
||||||
}, e => {
|
}, e => {
|
||||||
console.log("Download response:", json.encode(e))
|
log.console("Download response:", json.encode(e))
|
||||||
download_complete = true
|
download_complete = true
|
||||||
|
|
||||||
if (e.type === 'complete') {
|
if (e.type === 'complete') {
|
||||||
console.log("Download complete! Size:", e.size, "bytes")
|
log.console("Download complete! Size:", e.size, "bytes")
|
||||||
} else if (e.type === 'error') {
|
} else if (e.type === 'error') {
|
||||||
console.log("Download failed:", e.error)
|
log.console("Download failed:", e.error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -243,30 +243,30 @@ for (let test of testCases) {
|
|||||||
results.push({ testName, passed, messages });
|
results.push({ testName, passed, messages });
|
||||||
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
console.log(`\nDetailed Failure Report for ${testName}:`);
|
log.console(`\nDetailed Failure Report for ${testName}:`);
|
||||||
console.log(`Input: ${JSON.stringify(test.input)}`);
|
log.console(`Input: ${JSON.stringify(test.input)}`);
|
||||||
if (test.replacer) console.log(`Replacer: ${test.replacer.toString()}`);
|
if (test.replacer) log.console(`Replacer: ${test.replacer.toString()}`);
|
||||||
if (test.reviver) console.log(`Reviver: ${test.reviver.toString()}`);
|
if (test.reviver) log.console(`Reviver: ${test.reviver.toString()}`);
|
||||||
console.log(messages.join("\n"));
|
log.console(messages.join("\n"));
|
||||||
console.log("");
|
log.console("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log("\nTest Summary:");
|
log.console("\nTest Summary:");
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
console.log(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`);
|
log.console(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`);
|
||||||
if (!result.passed)
|
if (!result.passed)
|
||||||
console.log(result.messages)
|
log.console(result.messages)
|
||||||
});
|
});
|
||||||
|
|
||||||
let passedCount = results.filter(r => r.passed).length;
|
let passedCount = results.filter(r => r.passed).length;
|
||||||
console.log(`\nResult: ${passedCount}/${testCount} tests passed`);
|
log.console(`\nResult: ${passedCount}/${testCount} tests passed`);
|
||||||
|
|
||||||
if (passedCount < testCount) {
|
if (passedCount < testCount) {
|
||||||
console.log("Overall: FAILED");
|
log.console("Overall: FAILED");
|
||||||
// os.exit(1);
|
// os.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.log("Overall: PASSED");
|
log.console("Overall: PASSED");
|
||||||
// os.exit(0);
|
// os.exit(0);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
$_.start(e => {
|
$_.start(e => {
|
||||||
switch(e.type) {
|
switch(e.type) {
|
||||||
case "actor_started":
|
case "actor_started":
|
||||||
console.log(json.encode(e))
|
log.console(json.encode(e))
|
||||||
$_.connection(e => console.log(json.encode(e)), e.actor) // get connection info
|
$_.connection(e => log.console(json.encode(e)), e.actor) // get connection info
|
||||||
|
|
||||||
send(e.actor, {message: "Hello!"})
|
send(e.actor, {message: "Hello!"})
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var actor = $_.start(undefined, "tests/comments.js")
|
|||||||
|
|
||||||
send(actor, tree, (result, reason) => {
|
send(actor, tree, (result, reason) => {
|
||||||
if (reason)
|
if (reason)
|
||||||
console.log(reason)
|
log.console(reason)
|
||||||
else
|
else
|
||||||
console.log(json.encode(result))
|
log.console(json.encode(result))
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ $_.portal(e => {
|
|||||||
}, 5678);
|
}, 5678);
|
||||||
|
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
console.log(`Got message: ${json.encode(e)}`)
|
log.console(`Got message: ${json.encode(e)}`)
|
||||||
send(e, {greet: "Hello back!"})
|
send(e, {greet: "Hello back!"})
|
||||||
$_.delay(_ => $_.stop(), 0.2)
|
$_.delay(_ => $_.stop(), 0.2)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ var myqr = qr.encode("HELLO WORLD", {
|
|||||||
casesensitive: false
|
casesensitive: false
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log("test finished success.")
|
log.console("test finished success.")
|
||||||
os.exit()
|
os.exit()
|
||||||
|
|||||||
@@ -46,26 +46,26 @@ var qr = use('qr')
|
|||||||
|
|
||||||
var lvl = io.slurp('tests/level.json')
|
var lvl = io.slurp('tests/level.json')
|
||||||
var lvl_json = lvl
|
var lvl_json = lvl
|
||||||
console.log(`json size is ${lvl.length}`)
|
log.console(`json size is ${lvl.length}`)
|
||||||
lvl = json.decode(lvl)
|
lvl = json.decode(lvl)
|
||||||
lvl = nota.encode(lvl)
|
lvl = nota.encode(lvl)
|
||||||
console.log(`nota size is ${lvl.byteLength}`)
|
log.console(`nota size is ${lvl.byteLength}`)
|
||||||
var lvl_cmp = miniz.compress(lvl)
|
var lvl_cmp = miniz.compress(lvl)
|
||||||
var lvl_json_cmp = miniz.compress(lvl_json)
|
var lvl_json_cmp = miniz.compress(lvl_json)
|
||||||
|
|
||||||
console.log(`compressed json is ${lvl_json_cmp.byteLength}`)
|
log.console(`compressed json is ${lvl_json_cmp.byteLength}`)
|
||||||
console.log(`compressed nota is ${lvl_cmp.byteLength}`)
|
log.console(`compressed nota is ${lvl_cmp.byteLength}`)
|
||||||
|
|
||||||
var uncmp = miniz.decompress(lvl_cmp, false)
|
var uncmp = miniz.decompress(lvl_cmp, false)
|
||||||
console.log(uncmp.byteLength)
|
log.console(uncmp.byteLength)
|
||||||
|
|
||||||
console.log(`json cmp width: ${qr.encode(lvl_json_cmp).width}`)
|
log.console(`json cmp width: ${qr.encode(lvl_json_cmp).width}`)
|
||||||
var qr_lvl = qr.encode(lvl_cmp)
|
var qr_lvl = qr.encode(lvl_cmp)
|
||||||
console.log(`nota cmp width: ${qr_lvl.width}`)
|
log.console(`nota cmp width: ${qr_lvl.width}`)
|
||||||
var lvl_bytes = qr.rgba(qr_lvl)
|
var lvl_bytes = qr.rgba(qr_lvl)
|
||||||
|
|
||||||
console.log(lvl_bytes.buffer.byteLength)
|
log.console(lvl_bytes.buffer.byteLength)
|
||||||
console.log(json.encode(lvl_bytes))
|
log.console(json.encode(lvl_bytes))
|
||||||
|
|
||||||
var bsurf = graphics.surface_from_pixels(lvl_bytes)
|
var bsurf = graphics.surface_from_pixels(lvl_bytes)
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ var frame_img = graphics.texture("alcinaqr")
|
|||||||
var blit_img = graphics.from_surface("frame", frame_img.cpu.dup())
|
var blit_img = graphics.from_surface("frame", frame_img.cpu.dup())
|
||||||
|
|
||||||
var qr_size = lvl_bytes.width*4
|
var qr_size = lvl_bytes.width*4
|
||||||
console.log(`blowing it up to ${qr_size}`)
|
log.console(`blowing it up to ${qr_size}`)
|
||||||
var qr_rect = {x:300, y:500, width:qr_size, height:qr_size}
|
var qr_rect = {x:300, y:500, width:qr_size, height:qr_size}
|
||||||
var gutter = 25 // pixels per side
|
var gutter = 25 // pixels per side
|
||||||
var qr_rect_gutter = {
|
var qr_rect_gutter = {
|
||||||
@@ -135,7 +135,7 @@ $_.receiver(e => {
|
|||||||
|
|
||||||
switch(e.type) {
|
switch(e.type) {
|
||||||
case "drop_file":
|
case "drop_file":
|
||||||
console.log(`got ${e.data} dropped`)
|
log.console(`got ${e.data} dropped`)
|
||||||
var data = io.slurpbytes(e.data)
|
var data = io.slurpbytes(e.data)
|
||||||
img = graphics.make_texture(data)
|
img = graphics.make_texture(data)
|
||||||
var qr_surf = img;//extract_qr_surface(img)
|
var qr_surf = img;//extract_qr_surface(img)
|
||||||
@@ -143,23 +143,23 @@ $_.receiver(e => {
|
|||||||
var image = {surface:qr_surf_scaled}
|
var image = {surface:qr_surf_scaled}
|
||||||
display = graphics.from_surface("aaa", qr_surf_scaled)
|
display = graphics.from_surface("aaa", qr_surf_scaled)
|
||||||
var data = qr.decode(image.surface.pixels(), image.surface.width, image.surface.height, image.surface.pitch)
|
var data = qr.decode(image.surface.pixels(), image.surface.width, image.surface.height, image.surface.pitch)
|
||||||
console.log(`found ${data.length} qr codes`)
|
log.console(`found ${data.length} qr codes`)
|
||||||
if (data.length == 0) break
|
if (data.length == 0) break
|
||||||
data = data[0]
|
data = data[0]
|
||||||
console.log(data.byteLength)
|
log.console(data.byteLength)
|
||||||
var ddata = miniz.decompress(data, false)
|
var ddata = miniz.decompress(data, false)
|
||||||
console.log(ddata.byteLength)
|
log.console(ddata.byteLength)
|
||||||
console.log(`qr data size was ${data.byteLength}, uncompressed ${ddata.byteLength}`)
|
log.console(`qr data size was ${data.byteLength}, uncompressed ${ddata.byteLength}`)
|
||||||
|
|
||||||
var nn = nota.decode(ddata)
|
var nn = nota.decode(ddata)
|
||||||
console.log(json.encode(nn))
|
log.console(json.encode(nn))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "drop_text":
|
case "drop_text":
|
||||||
console.log(`text ${e.data} dropped`)
|
log.console(`text ${e.data} dropped`)
|
||||||
// if e.data is a url, fetch it
|
// if e.data is a url, fetch it
|
||||||
if (is_url(e.data)) {
|
if (is_url(e.data)) {
|
||||||
console.log('fetching!')
|
log.console('fetching!')
|
||||||
http.fetch(e.data, parse_data)
|
http.fetch(e.data, parse_data)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var os = use('os')
|
var os = use('os')
|
||||||
|
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
console.log(`Got a message: ${json.encode(e)}`)
|
log.console(`Got a message: ${json.encode(e)}`)
|
||||||
|
|
||||||
send(e, {
|
send(e, {
|
||||||
message: "Good to go."
|
message: "Good to go."
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
var os = use('os')
|
var os = use('os')
|
||||||
|
|
||||||
$_.start(e => {
|
$_.start(e => {
|
||||||
console.log(json.encode(e.actor))
|
log.console(json.encode(e.actor))
|
||||||
send(e.actor, { message: "Hello! Good to go?" }, msg => {
|
send(e.actor, { message: "Hello! Good to go?" }, msg => {
|
||||||
console.log(`Original sender got message back: ${json.encode(msg)}. Stopping!`)
|
log.console(`Original sender got message back: ${json.encode(msg)}. Stopping!`)
|
||||||
$_.stop()
|
$_.stop()
|
||||||
})
|
})
|
||||||
}, "tests/reply.js")
|
}, "tests/reply.js")
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
this.spawn()
|
this.spawn()
|
||||||
console.log("SPAWNED")
|
log.console("SPAWNED")
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
console.log("im alive")
|
log.console("im alive")
|
||||||
@@ -6,7 +6,7 @@ function spawnem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
with ([1,2,3]) {
|
with ([1,2,3]) {
|
||||||
console.log(toString())
|
log.console(toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
$_.delay(spawnem, 3)
|
$_.delay(spawnem, 3)
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
var steam = use("steam");
|
var steam = use("steam");
|
||||||
|
|
||||||
console.log("Steam module loaded:", steam);
|
log.console("Steam module loaded:", steam);
|
||||||
|
|
||||||
if (steam) {
|
if (steam) {
|
||||||
console.log("Steam functions available:");
|
log.console("Steam functions available:");
|
||||||
console.log("- steam_init:", typeof steam.steam_init);
|
log.console("- steam_init:", typeof steam.steam_init);
|
||||||
console.log("- steam_shutdown:", typeof steam.steam_shutdown);
|
log.console("- steam_shutdown:", typeof steam.steam_shutdown);
|
||||||
console.log("- steam_run_callbacks:", typeof steam.steam_run_callbacks);
|
log.console("- steam_run_callbacks:", typeof steam.steam_run_callbacks);
|
||||||
|
|
||||||
console.log("\nSteam sub-modules:");
|
log.console("\nSteam sub-modules:");
|
||||||
console.log("- stats:", steam.stats);
|
log.console("- stats:", steam.stats);
|
||||||
console.log("- achievement:", steam.achievement);
|
log.console("- achievement:", steam.achievement);
|
||||||
console.log("- app:", steam.app);
|
log.console("- app:", steam.app);
|
||||||
console.log("- user:", steam.user);
|
log.console("- user:", steam.user);
|
||||||
console.log("- friends:", steam.friends);
|
log.console("- friends:", steam.friends);
|
||||||
console.log("- cloud:", steam.cloud);
|
log.console("- cloud:", steam.cloud);
|
||||||
|
|
||||||
// Try to initialize Steam
|
// Try to initialize Steam
|
||||||
console.log("\nAttempting to initialize Steam...");
|
log.console("\nAttempting to initialize Steam...");
|
||||||
var init_result = steam.steam_init();
|
var init_result = steam.steam_init();
|
||||||
console.log("Initialization result:", init_result);
|
log.console("Initialization result:", init_result);
|
||||||
|
|
||||||
if (init_result) {
|
if (init_result) {
|
||||||
// Get some basic info
|
// Get some basic info
|
||||||
console.log("\nApp ID:", steam.app.app_id());
|
log.console("\nApp ID:", steam.app.app_id());
|
||||||
console.log("User logged on:", steam.user.user_logged_on());
|
log.console("User logged on:", steam.user.user_logged_on());
|
||||||
|
|
||||||
if (steam.user.user_logged_on()) {
|
if (steam.user.user_logged_on()) {
|
||||||
console.log("User name:", steam.friends.friends_name());
|
log.console("User name:", steam.friends.friends_name());
|
||||||
console.log("User state:", steam.friends.friends_state());
|
log.console("User state:", steam.friends.friends_state());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown when done
|
// Shutdown when done
|
||||||
steam.steam_shutdown();
|
steam.steam_shutdown();
|
||||||
console.log("Steam shut down");
|
log.console("Steam shut down");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Steam module not available (compiled without Steam support)");
|
log.console("Steam module not available (compiled without Steam support)");
|
||||||
}
|
}
|
||||||
@@ -3,35 +3,35 @@ var Surface = use('surface');
|
|||||||
|
|
||||||
// Test creating a surface
|
// Test creating a surface
|
||||||
var surf = new Surface({width: 100, height: 100});
|
var surf = new Surface({width: 100, height: 100});
|
||||||
console.log("Created surface:", surf.width, "x", surf.height);
|
log.console("Created surface:", surf.width, "x", surf.height);
|
||||||
|
|
||||||
console.log(json.encode(surf))
|
log.console(json.encode(surf))
|
||||||
|
|
||||||
// Test fill
|
// Test fill
|
||||||
surf.fill([1, 0, 0, 1]); // Red
|
surf.fill([1, 0, 0, 1]); // Red
|
||||||
|
|
||||||
// Test dup
|
// Test dup
|
||||||
var surf2 = surf.dup();
|
var surf2 = surf.dup();
|
||||||
console.log("Duplicated surface:", surf2.width, "x", surf2.height);
|
log.console("Duplicated surface:", surf2.width, "x", surf2.height);
|
||||||
|
|
||||||
// Test scale
|
// Test scale
|
||||||
var surf3 = surf.scale([50, 50], "linear");
|
var surf3 = surf.scale([50, 50], "linear");
|
||||||
console.log("Scaled surface:", surf3.width, "x", surf3.height);
|
log.console("Scaled surface:", surf3.width, "x", surf3.height);
|
||||||
|
|
||||||
// Test format
|
// Test format
|
||||||
console.log("Surface format:", surf.format);
|
log.console("Surface format:", surf.format);
|
||||||
|
|
||||||
// Test pixels
|
// Test pixels
|
||||||
var pixels = surf.pixels();
|
var pixels = surf.pixels();
|
||||||
console.log("Got pixels array buffer, length:", pixels.byteLength);
|
log.console("Got pixels array buffer, length:", pixels.byteLength);
|
||||||
|
|
||||||
// Test creating surface with custom format
|
// Test creating surface with custom format
|
||||||
var surf4 = new Surface({width: 64, height: 64, format: "rgb24"});
|
var surf4 = new Surface({width: 64, height: 64, format: "rgb24"});
|
||||||
console.log("Created RGB24 surface:", surf4.width, "x", surf4.height, "format:", surf4.format);
|
log.console("Created RGB24 surface:", surf4.width, "x", surf4.height, "format:", surf4.format);
|
||||||
|
|
||||||
// Test creating surface from pixels
|
// Test creating surface from pixels
|
||||||
var pixelData = new ArrayBuffer(32 * 32 * 4); // 32x32 RGBA
|
var pixelData = new ArrayBuffer(32 * 32 * 4); // 32x32 RGBA
|
||||||
var surf5 = new Surface({width: 32, height: 32, pixels: pixelData});
|
var surf5 = new Surface({width: 32, height: 32, pixels: pixelData});
|
||||||
console.log("Created surface from pixels:", surf5.width, "x", surf5.height);
|
log.console("Created surface from pixels:", surf5.width, "x", surf5.height);
|
||||||
|
|
||||||
console.log("Surface module test passed!");
|
log.console("Surface module test passed!");
|
||||||
@@ -9,39 +9,39 @@ var surf = surface({
|
|||||||
format: "rgb888"
|
format: "rgb888"
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Created surface:");
|
log.console("Created surface:");
|
||||||
console.log(" Size:", surf.width + "x" + surf.height);
|
log.console(" Size:", surf.width + "x" + surf.height);
|
||||||
console.log(" Format:", surf.format);
|
log.console(" Format:", surf.format);
|
||||||
|
|
||||||
// Fill with a test color
|
// Fill with a test color
|
||||||
surf.fill([1, 0.5, 0.25, 1]); // Orange color
|
surf.fill([1, 0.5, 0.25, 1]); // Orange color
|
||||||
|
|
||||||
// Test 1: Convert format only (no colorspace change)
|
// Test 1: Convert format only (no colorspace change)
|
||||||
console.log("\nTest 1: Convert to RGBA8888 format only");
|
log.console("\nTest 1: Convert to RGBA8888 format only");
|
||||||
var converted1 = surf.convert("rgba8888");
|
var converted1 = surf.convert("rgba8888");
|
||||||
console.log(" New format:", converted1.format);
|
log.console(" New format:", converted1.format);
|
||||||
|
|
||||||
// Test 2: Convert format and colorspace
|
// Test 2: Convert format and colorspace
|
||||||
console.log("\nTest 2: Convert to YUY2 format with JPEG colorspace");
|
log.console("\nTest 2: Convert to YUY2 format with JPEG colorspace");
|
||||||
var converted2 = surf.convert("yuy2", "jpeg");
|
var converted2 = surf.convert("yuy2", "jpeg");
|
||||||
console.log(" New format:", converted2.format);
|
log.console(" New format:", converted2.format);
|
||||||
|
|
||||||
// Test 3: Try different colorspaces
|
// Test 3: Try different colorspaces
|
||||||
var colorspaces = ["srgb", "srgb_linear", "jpeg", "bt601_limited", "bt709_limited"];
|
var colorspaces = ["srgb", "srgb_linear", "jpeg", "bt601_limited", "bt709_limited"];
|
||||||
var test_format = "rgba8888";
|
var test_format = "rgba8888";
|
||||||
|
|
||||||
console.log("\nTest 3: Converting to", test_format, "with different colorspaces:");
|
log.console("\nTest 3: Converting to", test_format, "with different colorspaces:");
|
||||||
for (var i = 0; i < colorspaces.length; i++) {
|
for (var i = 0; i < colorspaces.length; i++) {
|
||||||
try {
|
try {
|
||||||
var conv = surf.convert(test_format, colorspaces[i]);
|
var conv = surf.convert(test_format, colorspaces[i]);
|
||||||
console.log(" " + colorspaces[i] + ": Success");
|
log.console(" " + colorspaces[i] + ": Success");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(" " + colorspaces[i] + ": Failed -", e.message);
|
log.console(" " + colorspaces[i] + ": Failed -", e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test 4: YUV formats with appropriate colorspaces
|
// Test 4: YUV formats with appropriate colorspaces
|
||||||
console.log("\nTest 4: YUV format conversions:");
|
log.console("\nTest 4: YUV format conversions:");
|
||||||
var yuv_tests = [
|
var yuv_tests = [
|
||||||
{format: "yuy2", colorspace: "jpeg"},
|
{format: "yuy2", colorspace: "jpeg"},
|
||||||
{format: "nv12", colorspace: "bt601_limited"},
|
{format: "nv12", colorspace: "bt601_limited"},
|
||||||
@@ -53,11 +53,11 @@ for (var i = 0; i < yuv_tests.length; i++) {
|
|||||||
var test = yuv_tests[i];
|
var test = yuv_tests[i];
|
||||||
try {
|
try {
|
||||||
var conv = surf.convert(test.format, test.colorspace);
|
var conv = surf.convert(test.format, test.colorspace);
|
||||||
console.log(" " + test.format + " with " + test.colorspace + ": Success");
|
log.console(" " + test.format + " with " + test.colorspace + ": Success");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(" " + test.format + " with " + test.colorspace + ": Failed -", e.message);
|
log.console(" " + test.format + " with " + test.colorspace + ": Failed -", e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nColorspace conversion test complete!");
|
log.console("\nColorspace conversion test complete!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
// Test that actors have access to $_
|
// Test that actors have access to $_
|
||||||
console.log("Testing actor access to $_:");
|
log.console("Testing actor access to $_:");
|
||||||
|
|
||||||
// In an actor script, $_ should be available
|
// In an actor script, $_ should be available
|
||||||
if (typeof $_ !== 'undefined') {
|
if (typeof $_ !== 'undefined') {
|
||||||
console.log("✓ Actor has access to $_");
|
log.console("✓ Actor has access to $_");
|
||||||
console.log(" $_.random is a", typeof $_.random);
|
log.console(" $_.random is a", typeof $_.random);
|
||||||
console.log(" $_.clock is a", typeof $_.clock);
|
log.console(" $_.clock is a", typeof $_.clock);
|
||||||
|
|
||||||
// Test spawning another actor
|
// Test spawning another actor
|
||||||
var child = this.spawn('test_child_actor.js');
|
var child = this.spawn('test_child_actor.js');
|
||||||
|
|
||||||
// Test using a module
|
// Test using a module
|
||||||
var testModule = use('test_module');
|
var testModule = use('test_module');
|
||||||
console.log("✓ Module loaded, result:", testModule.test());
|
log.console("✓ Module loaded, result:", testModule.test());
|
||||||
} else {
|
} else {
|
||||||
console.error("✗ Actor does NOT have access to $_");
|
log.error("✗ Actor does NOT have access to $_");
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
// Test module to verify argument passing
|
// Test module to verify argument passing
|
||||||
|
|
||||||
console.log("Test args module loaded");
|
log.console("Test args module loaded");
|
||||||
console.log("Number of arguments:", arg.length);
|
log.console("Number of arguments:", arg.length);
|
||||||
console.log("Arguments received:", arg);
|
log.console("Arguments received:", arg);
|
||||||
|
|
||||||
function createMessage(prefix) {
|
function createMessage(prefix) {
|
||||||
prefix = prefix || "default";
|
prefix = prefix || "default";
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Child actor test
|
// Child actor test
|
||||||
console.log("Child actor spawned");
|
log.console("Child actor spawned");
|
||||||
|
|
||||||
if (typeof $_ !== 'undefined') {
|
if (typeof $_ !== 'undefined') {
|
||||||
console.log("✓ Child actor has access to $_");
|
log.console("✓ Child actor has access to $_");
|
||||||
} else {
|
} else {
|
||||||
console.error("✗ Child actor does NOT have access to $_");
|
log.error("✗ Child actor does NOT have access to $_");
|
||||||
}
|
}
|
||||||
@@ -6,20 +6,20 @@ input.watch($_);
|
|||||||
|
|
||||||
$_.receiver(msg => {
|
$_.receiver(msg => {
|
||||||
if (msg.type) {
|
if (msg.type) {
|
||||||
console.log("Received event:", msg.type);
|
log.console("Received event:", msg.type);
|
||||||
|
|
||||||
// Log specific event details
|
// Log specific event details
|
||||||
switch(msg.type) {
|
switch(msg.type) {
|
||||||
case "key_down":
|
case "key_down":
|
||||||
case "key_up":
|
case "key_up":
|
||||||
console.log(" Key:", msg.key, "Scancode:", msg.scancode, "Down:", msg.down);
|
log.console(" Key:", msg.key, "Scancode:", msg.scancode, "Down:", msg.down);
|
||||||
break;
|
break;
|
||||||
case "mouse_motion":
|
case "mouse_motion":
|
||||||
console.log(" Mouse position:", msg.pos, "Delta:", msg.d_pos);
|
log.console(" Mouse position:", msg.pos, "Delta:", msg.d_pos);
|
||||||
break;
|
break;
|
||||||
case "mouse_button_down":
|
case "mouse_button_down":
|
||||||
case "mouse_button_up":
|
case "mouse_button_up":
|
||||||
console.log(" Button:", msg.button, "Position:", msg.mouse, "Down:", msg.down);
|
log.console(" Button:", msg.button, "Position:", msg.mouse, "Down:", msg.down);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,11 +28,11 @@ $_.receiver(msg => {
|
|||||||
$_.event_count++;
|
$_.event_count++;
|
||||||
|
|
||||||
if ($_.event_count >= 10) {
|
if ($_.event_count >= 10) {
|
||||||
console.log("Received 10 events, stopping watch");
|
log.console("Received 10 events, stopping watch");
|
||||||
input.unwatch($_);
|
input.unwatch($_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Event watcher started. Press keys or move mouse to generate events.");
|
log.console("Event watcher started. Press keys or move mouse to generate events.");
|
||||||
console.log("Will stop after 10 events.");
|
log.console("Will stop after 10 events.");
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
if (typeof $_ !== 'undefined') {
|
if (typeof $_ !== 'undefined') {
|
||||||
console.error("✗ Module incorrectly has access to $_!");
|
log.error("✗ Module incorrectly has access to $_!");
|
||||||
return "ERROR: Module has $_ access";
|
return "ERROR: Module has $_ access";
|
||||||
} else {
|
} else {
|
||||||
console.log("✓ Module correctly does NOT have access to $_");
|
log.console("✓ Module correctly does NOT have access to $_");
|
||||||
return "Module loaded without $_ access";
|
return "Module loaded without $_ access";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
// Test script to verify use() with arguments
|
// Test script to verify use() with arguments
|
||||||
|
|
||||||
console.log("Testing use() with arguments:");
|
log.console("Testing use() with arguments:");
|
||||||
|
|
||||||
// Test 1: Load module without arguments
|
// Test 1: Load module without arguments
|
||||||
var module1 = use('test_args');
|
var module1 = use('test_args');
|
||||||
console.log("Module 1 message:", module1.message);
|
log.console("Module 1 message:", module1.message);
|
||||||
console.log("Module 1 args:", module1.args);
|
log.console("Module 1 args:", module1.args);
|
||||||
|
|
||||||
// Test 2: Load module with arguments
|
// Test 2: Load module with arguments
|
||||||
var module2 = use('test_args', 'hello', 'world', 123);
|
var module2 = use('test_args', 'hello', 'world', 123);
|
||||||
console.log("Module 2 message:", module2.message);
|
log.console("Module 2 message:", module2.message);
|
||||||
console.log("Module 2 all args:", module2.allArgs());
|
log.console("Module 2 all args:", module2.allArgs());
|
||||||
|
|
||||||
// Test 3: Verify modules are cached (should return same as module1)
|
// Test 3: Verify modules are cached (should return same as module1)
|
||||||
var module3 = use('test_args');
|
var module3 = use('test_args');
|
||||||
console.log("Module 3 (cached) message:", module3.message);
|
log.console("Module 3 (cached) message:", module3.message);
|
||||||
console.log("Are module1 and module3 the same?", module1 === module3);
|
log.console("Are module1 and module3 the same?", module1 === module3);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
var os = use('os')
|
var os = use('os')
|
||||||
|
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
console.log(`got message: ${json.encode(e)}`)
|
log.console(`got message: ${json.encode(e)}`)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
$_.unneeded(_ => {
|
$_.unneeded(_ => {
|
||||||
console.log("Unneded function fired.");
|
log.console("Unneded function fired.");
|
||||||
$_.unneeded($_.stop, 1);
|
$_.unneeded($_.stop, 1);
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ var webcam_texture = null;
|
|||||||
// Handle camera events
|
// Handle camera events
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
if (e.type === 'camera_device_approved' && e.which === cam_id) {
|
if (e.type === 'camera_device_approved' && e.which === cam_id) {
|
||||||
console.log("Camera approved!");
|
log.console("Camera approved!");
|
||||||
cam_approved = true;
|
cam_approved = true;
|
||||||
} else if (e.type === 'camera_device_denied' && e.which === cam_id) {
|
} else if (e.type === 'camera_device_denied' && e.which === cam_id) {
|
||||||
console.error("Camera access denied!");
|
log.error("Camera access denied!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -40,12 +40,12 @@ send(video_actor, {
|
|||||||
}
|
}
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to create window:", response.error);
|
log.error("Failed to create window:", response.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window_id = response.id;
|
window_id = response.id;
|
||||||
console.log("Created window with id:", window_id);
|
log.console("Created window with id:", window_id);
|
||||||
|
|
||||||
// Create renderer
|
// Create renderer
|
||||||
send(video_actor, {
|
send(video_actor, {
|
||||||
@@ -54,12 +54,12 @@ send(video_actor, {
|
|||||||
id: window_id
|
id: window_id
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to create renderer:", response.error);
|
log.error("Failed to create renderer:", response.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer_id = response.id;
|
renderer_id = response.id;
|
||||||
console.log("Created renderer with id:", renderer_id);
|
log.console("Created renderer with id:", renderer_id);
|
||||||
|
|
||||||
// Configure draw2d and graphics
|
// Configure draw2d and graphics
|
||||||
draw2d = use('draw2d', video_actor, renderer_id)
|
draw2d = use('draw2d', video_actor, renderer_id)
|
||||||
@@ -68,23 +68,23 @@ send(video_actor, {
|
|||||||
// List available cameras
|
// List available cameras
|
||||||
var cameras = camera.list();
|
var cameras = camera.list();
|
||||||
if (cameras.length === 0) {
|
if (cameras.length === 0) {
|
||||||
console.error("No cameras found!");
|
log.error("No cameras found!");
|
||||||
console.log(json.encode(cameras))
|
log.console(json.encode(cameras))
|
||||||
$_.stop();
|
$_.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Found", cameras.length, "camera(s)");
|
log.console("Found", cameras.length, "camera(s)");
|
||||||
|
|
||||||
// Open the first camera
|
// Open the first camera
|
||||||
cam_id = cameras[0];
|
cam_id = cameras[0];
|
||||||
var cam_name = camera.name(cam_id);
|
var cam_name = camera.name(cam_id);
|
||||||
var cam_position = camera.position(cam_id);
|
var cam_position = camera.position(cam_id);
|
||||||
console.log("Opening camera:", cam_name, "Position:", cam_position);
|
log.console("Opening camera:", cam_name, "Position:", cam_position);
|
||||||
|
|
||||||
// Get supported formats and try to find a good one
|
// Get supported formats and try to find a good one
|
||||||
var formats = camera.supported_formats(cam_id);
|
var formats = camera.supported_formats(cam_id);
|
||||||
console.log("Camera supports", formats.length, "formats");
|
log.console("Camera supports", formats.length, "formats");
|
||||||
|
|
||||||
// Look for a 640x480 format with preferred colorspace
|
// Look for a 640x480 format with preferred colorspace
|
||||||
var preferred_format = null;
|
var preferred_format = null;
|
||||||
@@ -106,7 +106,7 @@ send(video_actor, {
|
|||||||
preferred_format.framerate_numerator = 30
|
preferred_format.framerate_numerator = 30
|
||||||
|
|
||||||
if (preferred_format) {
|
if (preferred_format) {
|
||||||
console.log("Using format:", preferred_format.width + "x" + preferred_format.height,
|
log.console("Using format:", preferred_format.width + "x" + preferred_format.height,
|
||||||
"FPS:", preferred_format.framerate_numerator + "/" + preferred_format.framerate_denominator,
|
"FPS:", preferred_format.framerate_numerator + "/" + preferred_format.framerate_denominator,
|
||||||
"Format:", preferred_format.format,
|
"Format:", preferred_format.format,
|
||||||
"Colorspace:", preferred_format.colorspace);
|
"Colorspace:", preferred_format.colorspace);
|
||||||
@@ -116,20 +116,20 @@ send(video_actor, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cam_obj) {
|
if (!cam_obj) {
|
||||||
console.error("Failed to open camera!");
|
log.error("Failed to open camera!");
|
||||||
$_.stop();
|
$_.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Camera driver:", cam_obj.get_driver());
|
log.console("Camera driver:", cam_obj.get_driver());
|
||||||
|
|
||||||
// Get and display the actual format being used
|
// Get and display the actual format being used
|
||||||
var actual_format = cam_obj.get_format();
|
var actual_format = cam_obj.get_format();
|
||||||
console.log("Actual camera format:");
|
log.console("Actual camera format:");
|
||||||
console.log(" Resolution:", actual_format.width + "x" + actual_format.height);
|
log.console(" Resolution:", actual_format.width + "x" + actual_format.height);
|
||||||
console.log(" Format:", actual_format.format);
|
log.console(" Format:", actual_format.format);
|
||||||
console.log(" Colorspace:", actual_format.colorspace);
|
log.console(" Colorspace:", actual_format.colorspace);
|
||||||
console.log(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator);
|
log.console(" FPS:", actual_format.framerate_numerator + "/" + actual_format.framerate_denominator);
|
||||||
|
|
||||||
// Start capturing after a short delay to wait for approval
|
// Start capturing after a short delay to wait for approval
|
||||||
$_.delay(start_capturing, 0.5);
|
$_.delay(start_capturing, 0.5);
|
||||||
@@ -140,7 +140,7 @@ var captured = false
|
|||||||
|
|
||||||
function start_capturing() {
|
function start_capturing() {
|
||||||
if (!cam_approved) {
|
if (!cam_approved) {
|
||||||
console.log("Waiting for camera approval...");
|
log.console("Waiting for camera approval...");
|
||||||
$_.delay(start_capturing, 0.1);
|
$_.delay(start_capturing, 0.1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ function start_capturing() {
|
|||||||
if (frame < 300) { // Run for 10 seconds
|
if (frame < 300) { // Run for 10 seconds
|
||||||
$_.delay(capture_and_draw, 1/30);
|
$_.delay(capture_and_draw, 1/30);
|
||||||
} else {
|
} else {
|
||||||
console.log("Test completed - captured", frame, "frames");
|
log.console("Test completed - captured", frame, "frames");
|
||||||
|
|
||||||
// Clean up resources
|
// Clean up resources
|
||||||
if (webcam_texture) {
|
if (webcam_texture) {
|
||||||
@@ -255,7 +255,7 @@ function start_capturing() {
|
|||||||
$_.delay(_ => {
|
$_.delay(_ => {
|
||||||
// Capture frame from camera
|
// Capture frame from camera
|
||||||
var surface = cam_obj.capture().convert("rgba8888", "srgb")
|
var surface = cam_obj.capture().convert("rgba8888", "srgb")
|
||||||
console.log('capturing!')
|
log.console('capturing!')
|
||||||
graphics.save_png("test.png", surface.width, surface.height, surface.pixels(),surface.pitch)
|
graphics.save_png("test.png", surface.width, surface.height, surface.pixels(),surface.pitch)
|
||||||
}, 3)
|
}, 3)
|
||||||
|
|
||||||
|
|||||||
@@ -53,5 +53,5 @@ $_.receiver(e => {
|
|||||||
if (e.type === 'quit')
|
if (e.type === 'quit')
|
||||||
os.exit()
|
os.exit()
|
||||||
else
|
else
|
||||||
console.log(json.encode(e))
|
log.console(json.encode(e))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -231,30 +231,30 @@ for (let test of testCases) {
|
|||||||
results.push({ testName, passed, messages });
|
results.push({ testName, passed, messages });
|
||||||
|
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
console.log(`\nDetailed Failure Report for ${testName}:`);
|
log.console(`\nDetailed Failure Report for ${testName}:`);
|
||||||
console.log(`Input: ${JSON.stringify(test.input)}`);
|
log.console(`Input: ${JSON.stringify(test.input)}`);
|
||||||
if (test.replacer) console.log(`Replacer: ${test.replacer.toString()}`);
|
if (test.replacer) log.console(`Replacer: ${test.replacer.toString()}`);
|
||||||
if (test.reviver) console.log(`Reviver: ${test.reviver.toString()}`);
|
if (test.reviver) log.console(`Reviver: ${test.reviver.toString()}`);
|
||||||
console.log(messages.join("\n"));
|
log.console(messages.join("\n"));
|
||||||
console.log("");
|
log.console("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log("\nTest Summary:");
|
log.console("\nTest Summary:");
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
console.log(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`);
|
log.console(`${result.testName} - ${result.passed ? "Passed" : "Failed"}`);
|
||||||
if (!result.passed)
|
if (!result.passed)
|
||||||
console.log(result.messages);
|
log.console(result.messages);
|
||||||
});
|
});
|
||||||
|
|
||||||
let passedCount = results.filter(r => r.passed).length;
|
let passedCount = results.filter(r => r.passed).length;
|
||||||
console.log(`\nResult: ${passedCount}/${testCount} tests passed`);
|
log.console(`\nResult: ${passedCount}/${testCount} tests passed`);
|
||||||
|
|
||||||
if (passedCount < testCount) {
|
if (passedCount < testCount) {
|
||||||
console.log("Overall: FAILED");
|
log.console("Overall: FAILED");
|
||||||
os.exit(1);
|
os.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.log("Overall: PASSED");
|
log.console("Overall: PASSED");
|
||||||
os.exit(0);
|
os.exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user