Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for resetting a lookup at runtime back to its original data #592

Closed
chrispcampbell opened this issue Dec 17, 2024 · 1 comment · Fixed by #593 · May be fixed by #594
Closed

Allow for resetting a lookup at runtime back to its original data #592

chrispcampbell opened this issue Dec 17, 2024 · 1 comment · Fixed by #593 · May be fixed by #594

Comments

@chrispcampbell
Copy link
Contributor

In #472 we added support for overriding the data for lookups and data variables at runtime. This was implemented primarily to support the use case of supplying game inputs at runtime.

For the EPS model, @ToddFincannonEI has been maintaining a fork of SDE for a similar use case where they need to be able to override lookups at runtime. In their case however, they need to be able to reset a lookup back to its original data (i.e., the data in the generated model that was used to initialize the native Lookup instance). Additionally they would like to avoid malloc/free where possible for performance reasons.

When I implemented #472, I didn't include support for the "reset to original" use case (since it wasn't needed for the gaming mode use case), but with a few incremental changes we should be able to refactor the existing implementation to make that reset behavior work.

@chrispcampbell
Copy link
Contributor Author

In my implementation of #472, I made the "override lookups" case work by disposing the existing Lookup instance and creating a new one (for both the C and JS runtimes).

Since we now want to be able to preserve the original lookup data, the new approach will be to add a __set_lookup function (for the C runtime) and a JsModelLookup.setData method (for the JS runtime). The implementation is largely the same for both C and JS. We now allow the data/points parameter to be NULL/undefined. In the instance state, we now keep separate references for the original data and the dynamic (set at runtime) data. Calling __set_lookup with a non-NULL data buffer will copy that data into an internally managed buffer, and will make the dynamic data buffer the "active" one. Calling __set_lookup again with a NULL data buffer will switch the internal state back so that the original data buffer is the "active" one.

In the compile package, I am changing code gen for the setLookup function so that it calls __set_lookup or lookup.setData instead of doing the replace (dispose+create) like before.

In the runtime package, I am making the following changes:

  • Changed LookupDef and createLookupDef so that points is allowed to be undefined
  • Changed encoding/decoding of LookupDef to handle the case where points is undefined
  • Added JsModelLookup.setData and reworked the implementation of JsModelLookup to behave like its C counterpart

I updated the unit tests to cover these changes, and also updated the existing override-lookups integration test to verify the case of resetting a lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment