Page MenuHomeWildfire Games

Add "mul_round" op to template parsing to support multiplying with integer types.
ClosedPublic

Authored by wraitii on Mar 27 2017, 5:23 PM.

Details

Reviewers
leper
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Restricted Owners Package(Owns No Changed Paths)
Commits
rP22003: Add "mul_round" op to template parsing to support multiplying-then-rounding.
Trac Tickets
#3818
Summary

Sometimes when using "mul", the values come out decimal. This may happen in situation where the validation expects an integer result (as it was for cost before for example), leading us to change that to Decimal.

This is a poor solution to the problem.

I think it is preferable that the paramNode code is not aware of the validation, so I think the simplest solution is to allow rounding following an attribute. See code.

Test Plan

Check out the code, test it, approve/disapprove the idea

Diff Detail

Repository
rP 0 A.D. Public Repository
Branch
/ps/trunk
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 1518
Build 2397: Vulcan BuildJenkins
Build 2396: arc lint + arc unit

Event Timeline

wraitii created this revision.Mar 27 2017, 5:23 PM
wraitii updated this revision to Diff 973.Mar 27 2017, 5:28 PM

Because of course it's not a data type it's a ref name…

Vulcan added a subscriber: Vulcan.Mar 27 2017, 7:06 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (305 tests).................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (305 tests).................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/619/ for more details.

leper requested changes to this revision.Mar 27 2017, 7:39 PM
leper added a subscriber: leper.

No, go fix that one TODO in the relative template code if you need it for that. Also non-int costs are stupid.

This revision now requires changes to proceed.Mar 27 2017, 7:39 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (305 tests).................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (305 tests).................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/620/ for more details.

2 things:
-non int costs aren't stupid. Time could very legitimately be under 1 second, I don't see why we would not allow that. It's more doubtful for resources, admittedly, but even then I conceptualise a reason to.
-this isn't exactly "technical debt".

In D268#10313, @wraitii wrote:

2 things:
-non int costs aren't stupid. Time could very legitimately be under 1 second, I don't see why we would not allow that. It's more doubtful for resources, admittedly, but even then I conceptualise a reason to.

They are. You're not changing only time here, and sure something costing half a wood totally makes sense.

-this isn't exactly "technical debt".

If you don't consider that whole component to be just that.

Going to rephrase this revision to address #3818.

@leper: I thought about this a bit and I don't think validation schemas should have an influence on templates. I would rather go with a user specified parameter, something like:

<Cost op="mul" round="true">2.5</Cost>
<Cost op="mul" ceil="true">2.5</Cost>

Would need minimal code change, would lead validation to still fail if you forget to round, meaning the template code has more control, and so on.

wraitii updated this revision to Diff 1718.May 7 2017, 3:06 PM
wraitii edited edge metadata.
wraitii retitled this revision from Upgrade component cost and time should be NonNegativeDecimal to Allow rounding template values (for use with op="mul").
wraitii edited the summary of this revision. (Show Details)
wraitii edited the test plan for this revision. (Show Details)
wraitii added a reviewer: Restricted Owners Package.

Allow rounding/flooring/ceiling the value.

Owners added a subscriber: Restricted Owners Package.May 7 2017, 3:06 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1058/ for more details.

leper requested changes to this revision.May 8 2017, 4:06 AM

@leper: I thought about this a bit and I don't think validation schemas should have an influence on templates. I would rather go with a user specified parameter, something like:

Yes, but the templates should conform to the schemas, else why even have schemas (I mean NoSQL dbs also work just fine (or at least nobody can tell if they don't)?

<Cost op="mul" round="true">2.5</Cost>
<Cost op="mul" ceil="true">2.5</Cost>

This allows specifying both round and ceil which seems like a bad idea from a usability perspective.

Also why not just have eg imul in case we don't want to rely on the schema when parsing. (Would also make the CParamNode code nicer IMO.)

binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
40

I assume this is just to exemplify the code.

source/simulation2/system/ComponentManager.cpp
1113

So how does removing this not break loading things? (Unless I'm just not seeing why this cannot be done before this diff.)

source/simulation2/system/ParamNode.cpp
123

So now I go and specify round="" ceil="" floor="" round="" and the only thing someone would notice is that round is specified twice.

213

broken indentation here and below

220

pointless comment

This revision now requires changes to proceed.May 8 2017, 4:06 AM

I'm ok with using imul but it doesn't allow choosing between flooring, rounding and ceiling which would be convenient imo.

I would also like a

round="round/ceil/foor"

argument instead but I'd like a better name than round and couldn't think of one.

source/simulation2/system/ComponentManager.cpp
1113

From what I've seen, the "op" are removed during parsing(cf l255 of paramnode) so this is actually useless. We could keep it, I suppose, for indicative purposes.

In D268#18417, @wraitii wrote:

I'm ok with using imul but it doesn't allow choosing between flooring, rounding and ceiling which would be convenient imo.

I'm not sure if it is really worth bothering with providing all of those, since if someone cared enough about the specific value they would provide it in the template, instead of making balancing that much easier.

I would also like a

round="round/ceil/foor"

argument instead but I'd like a better name than round and couldn't think of one.

rounding_mode, but that also sounds bad.

source/simulation2/system/ComponentManager.cpp
1113

Ah, that does indeed make sense. Guess they didn't at some early point in that wip diff I handed scythetwirler.

wraitii updated this revision to Diff 1785.May 9 2017, 10:09 AM
wraitii edited edge metadata.
wraitii retitled this revision from Allow rounding template values (for use with op="mul") to Add "mul_round" op to template parsing to support multiplying with integer types..

Use mul_round instead of 3 different attributes.

The woman template is still just to show the code works.

Vulcan added a comment.May 9 2017, 1:44 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1100/ for more details.

leper added inline comments.May 12 2017, 1:18 AM
binaries/data/mods/public/simulation/components/Cost.js
23

Time was actually the only thing in here where decimals make some sense. If you want to change that back fine by me I guess.

source/simulation2/system/ParamNode.cpp
205

Keeping it consistent with the other two cases would be nice. Especially so nobody wonders why there are two different ways of doing this.

elexis added a subscriber: elexis.May 17 2017, 1:10 PM

What about Health? If we don't have fractional health, then attack damage should be rounded too. But if attack damage is rounded, the tooltips display a misleading value. Perhaps that could be solved with a ssmall GUI page that displays the actual damage dealt to some templates (basically that templatesanalyzer ingame).

In D268#20615, @elexis wrote:

What about Health? If we don't have fractional health, then attack damage should be rounded too. But if attack damage is rounded, the tooltips display a misleading value. Perhaps that could be solved with a ssmall GUI page that displays the actual damage dealt to some templates (basically that templatesanalyzer ingame).

Possible values in templates and whatever components do with that are different things.

leper requested changes to this revision.May 17 2017, 6:42 PM

See last inline comments.

This revision now requires changes to proceed.May 17 2017, 6:42 PM

You're right about time, I'll update when I get the time.

wraitii updated this revision to Diff 4016.Oct 29 2017, 3:05 PM
wraitii marked an inline comment as done.

Address comments.

wraitii added inline comments.Oct 29 2017, 3:06 PM
source/simulation2/system/ParamNode.cpp
205

Annoyingly, can't use std::to_wstring in the above cases as that always has a "." in the result when called with a double or a float. So instead I'm doing the odd casting here.

Build is green

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...

http://jenkins-master:8080/job/phabricator/2189/ for more details.

Executing section Default...
Executing section Source...
Executing section JS...

http://jenkins-master:8080/job/phabricator_lint/645/ for more details.

wraitii added a reviewer: Restricted Owners Package.Nov 1 2017, 5:07 PM

(imul sounds better than mul_round.)
/me won the useless comment award.

The other approach seems really hard. @leper had you some vague ideas when writing the TODO?

(imul sounds better than mul_round.)

I'd agree, but mul_round is clearer and I don't believe all of our modders would instantly understand imul.

The other approach seems really hard. @leper had you some vague ideas when writing the TODO?

Probably, else I wouldn't have written the TODO. Then again it has been 2 years, so dunno.

Any other comments? Would like to commit this, and it's imo sufficiently reviewed.

@elexis any chance you'd look at this?

wraitii updated this revision to Diff 7153.Dec 30 2018, 6:44 PM

Rebasing to run the tests before committing.

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/differential/863/

This revision was not accepted when it landed; it landed in state Needs Review.Jan 2 2019, 3:46 PM
This revision was automatically updated to reflect the committed changes.
elexis updated the Trac tickets for this revision.Jun 15 2019, 7:08 PM