-
Notifications
You must be signed in to change notification settings - Fork 293
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
Feat/refactor flags #6475
base: master
Are you sure you want to change the base?
Feat/refactor flags #6475
Conversation
…to enum flags, and adds a bitset on Equipment
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6475 +/- ##
============================================
+ Coverage 28.56% 28.65% +0.09%
- Complexity 14373 14392 +19
============================================
Files 2798 2803 +5
Lines 275101 275456 +355
Branches 48669 48669
============================================
+ Hits 78576 78940 +364
+ Misses 191890 191881 -9
Partials 4635 4635 ☔ View full report in Codecov by Sentry. |
38b7e6d
to
b122841
Compare
AmmoTypeFlag and WeaponTypeFlags reordered by family of weapon and alphabetized in each family. |
|
||
// Limit which type of unit can install the equipment | ||
F_BA_EQUIPMENT, | ||
F_MEK_EQUIPMENT, | ||
F_TANK_EQUIPMENT, | ||
F_FIGHTER_EQUIPMENT, | ||
F_SUPPORT_TANK_EQUIPMENT, | ||
F_PROTOMEK_EQUIPMENT, | ||
|
||
F_JUMP_JET, | ||
F_JUMP_BOOSTER, | ||
F_MECHANICAL_JUMP_BOOSTER, | ||
|
||
F_CASE, | ||
F_CASEII, | ||
F_CASEP, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request: Add comments for each section of values for new people to know what kind of enums go into each section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting for this comment XD
I'm not finished with it yet, too many equipment to figure out what each one of them is or means, so I am going slowly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one requested change about the comments for the enum groupings.
6a22cd3
to
77450ac
Compare
Once done with the comments for the types within the enums, this should be good to go. |
What this PR does?
Changes every single BigInteger in MegaMek for an Enum, uses a specialized BitSet to substitute the BigInteger and emulates its API to make it possible to substitute with minimal changes in code all around the application.
This change reduces the amount of time it takes to go through the function
EquipmentType::hasFlag
which today is quite slow and is queried extremelly frequently.How to use this PR?
This PR is standalone but probably MML and MHQ need to be updated, this is literally to get an "ok" on the change.
Improvements
I have tested using EnumSet for the flags, and a mix of Enum + BitSet, where the enum is a flag position in the bitSet and the bitset holds the flags itself. This was the result when running a Megamek game with 5 Princesses, no human players, for around 3 minutes. The same scenario was run the 3 times.
The BitInteger, the original implementation, spent 31 seconds of the total 210 seconds of the test duration. With EnumSet the time spent querying
hasFlag
reduced to 2 secons, and with the Enum + BitSet the time was further reduced to 72ms.With a few extra repetitions the result varied around 300ms and 50ms, depending on how many units were alive after the first couple of minutes.