EXAPUNKS

EXAPUNKS

View Stats:
[Virtual Network] setRegisterReadCallback called every frame
According to the documentation, setRegisterReadCallback does the following:
"Set the specified function as the read callback for the specified hardware register. When an EXA attempts to read from the register the read callback will be called and whatever value it returns will be read by the EXA. A read callback should return either an integer or a string."
However, it seems this function is called every frame instead of only when an EXA reads from it.
I think this is an ambiguity in the documention.
However, it raises the following question:
Is there a way I can emulate addTableInput updating of register value after an EXA has read from it?
Attempting something like
setRegisterReadCallback( reg, function() { regval = (regval+1)%1000; return regval; } );
creates a register rapidly increasing in value.
< >
Showing 1-3 of 3 comments
I second this. Maybe add a parameter that tells you whether it's read for displaying or because an EXA read from it.
I found a way to work around this. I set up an inaccessible hardware register which serves the purpose of detecting when the "frame reads" happen. Then I added a global flag for each other functional register which are set by the auxiliary registers callback to false every frame. Then in the functional registers' callbacks I can use this flag to detect the "frame call" which happens first by checking if the flag is false. Immediately after the flag is set to true. Then every subsequent call, where the flag is set to true is treated as a "real read".

Here is a snippet of how the auxiliary register is implemented. Every read callback which needs to distinguish between "frame reads" and "actual reads" must be created with "createReadCallback" and given a unique name:
function createReadCallback(name, callback) { readCallbackFrameReads[name] = false return function () { const result = callback(readCallbackFrameReads[name]) readCallbackFrameReads[name] = true return result } } const readCallbackFrameReads = {} function createAuxiliaryRegister() { const auxHost = createHost('zzz', 2, -3, 1, 1) const auxRegister = createRegister(auxHost, 2, -3, 'zign') setRegisterReadCallback(auxRegister, function () { for (let callbackName in readCallbackFrameReads) readCallbackFrameReads[callbackName] = false return 'ignr' }) }
Actually it required some more tweaking to also work in the fastest simulation speed. You can see a working solution here https://steamcommunity.com/sharedfiles/filedetails/?id=3502863561&searchtext=
< >
Showing 1-3 of 3 comments
Per page: 1530 50