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

2102: Support for model scale #3889

Merged
merged 34 commits into from Oct 30, 2021
Merged

2102: Support for model scale #3889

merged 34 commits into from Oct 30, 2021

Conversation

kduske
Copy link
Collaborator

@kduske kduske commented Oct 9, 2021

Closes #2102.

This PR adds support for configuring an entities' model scale. Currently, the scale is only applied to the model. The model scale can be configured in the game configuration as a default to be applied to all entity models, or it can be configured per entity definition in the entity definition file using TB's model syntax.

Regardless of where it is configured, the actual expression that yields a models' scale is evaluated at runtime, against the properties of the entity that has the model. This requires a couple of changes to the EL infrastructure so that we can efficiently store an expression in a value.

The first couple of commits just clean up the existing code and add some missing infrastructure such as comparison and stream insertion operators. Then we refactor the EL to support storing the expression that generated a value along with that value. Finally we add support for configuring model scale in the game configuration and the entity definition files.

@kduske kduske marked this pull request as draft October 9, 2021 09:57
We remove the constructors and use these types as simple structs. On top
of that we enable move semantics in more places.
Previously we used an enum to differentiate the different cases. With
variant, we can save one alternative and make the code safer and less
awkward to use.
@kduske kduske force-pushed the feature/2102-2 branch 4 times, most recently from 1043f07 to 1812201 Compare October 14, 2021 08:57
This refactoring contains a number of cleanups and simplifications. The
main takeaway is that we now store the expression that generated a value
as a member of that value. To that end, we make both Value and
Expression trivial to copy by storing their actual data using
shared_ptr. To achieve this, we must make values and expressions
immutable.

We also extract all of the concrete expression types into a separate
compilation unit to improve source code organization.
This iterator is useful when working with collections of pointers. It
wraps another iterator and just dereferences that iterator twice when
it is itself dereferenced.
We add support for setting a scale expression in the game configuration.
This expression is evaluated at runtime against an entities' properties.
The scale expression configured in the game configuration is used only
if the model definition doesn't have its own scale expression.
The test cases we remove in the parser tests are redundant because they
test the functionality of the ModelDefinition class, not the parser
itself. We only leave one test each to ensure that parsing EL model
expressions works at all.
This is necessary to make scale expressions work as expected, i.e., if a
model definition has a scale expression that accesses an entity property
that an entity doesn't have, then the global scale should be returned.
All other related types have the prefix "Entity", so we adapt these
names to be more consistent.
In the following commits, we will add the model transformation to the
cached entity properties. Once we start to consider the model scale in
the model transformation, we need to access the default model scale
expression from the game config, which we cannot access lazily.
Therefore, we change the updating to the cached entity properties to be
done eagerly here.
EntityPropertyConfig encapsulates any information that controls how
entity properties behave. Currently, it only contains a global scale
expression that is used if a model definition doesn't have a scale
expression itself, but in the future, it may also contain info about
the semantics of special entity property keys such as target or
targetname. This would then allow us to move away from hard coding
property keys.

EntityPropertyConfig must be passed to any member of Entity that
modifies entity properties in some way. Nodes can access a global config
object by calling Node::entityPropertyConfig, since the world node
stores that global config.
@kduske kduske marked this pull request as ready for review October 14, 2021 19:09
@kduske kduske requested a review from ericwa October 14, 2021 19:09
@kduske kduske removed the request for review from ericwa October 30, 2021 20:54
@kduske kduske merged commit 10a8025 into master Oct 30, 2021
@kduske kduske deleted the feature/2102-2 branch October 30, 2021 20:54
@kduske kduske mentioned this pull request Oct 31, 2021
@kduske kduske added this to the 2022.2 milestone May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add entity scale key.
1 participant