Access resources from mission model in procedures #1715
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR lets goals and constraints query resources by referencing them through the mission model. Meaning you can write
simResults.resource(model.fruit)
instead ofsimResults.resource("/fruit", Real.deserializer())
, wheremission
is a valid instance of the mission model.WithModel<M>
interface, which has a mutable static fieldmodelSingleton
. The scheduler or constraint action creates an instance of the model with the default sim config and sets the sim config at the beginning of the action. Goals/constraints that inherit fromWithModel<M>
can then get that instance withthis.model()
.NameableResource
interface andNamedResource
abstract implementor of that interface for convenience. Concrete resource types can inherit fromNamedResource
, which just lets theRegistrar
callNameableResource.setName(string)
. This happens during the model constructor, so it happens both during simulation (which is useless) and during scheduling/constraint actions. The timeline librarySimulationResults
then provides a fewresource(...)
overloads that look for things likeNameableResource<RealDynamics>
,NameableResource<Boolean>
, etc. It callsNameableResource.getName()
and associates the payload type with a timeline type likeReal
,Booleans
, etc.This required some fiddling with ClassLoaders to make sure that the mission model was not loaded twice by different loaders (which isn't just a waste, it also causes a class cast exception).
Verification
I've made two integration tests, one for scheduling and one for constraints. I've also manually verified that the constraint/goal jars don't include the mission model. (
unzip -l <jar> | grep banana
)Documentation
I swear I'll update the guide docs this time.
Future work
Because Vile Hack No. 1 creates the model with the default sim config, this could cause some issues when we support other configs during scheduling. I'm assuming that the default config corresponds to the full model with no resources left out.