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

Refactor item templates [RDY] #15908

Merged
merged 6 commits into from
Mar 26, 2016
Merged

Refactor item templates [RDY] #15908

merged 6 commits into from
Mar 26, 2016

Conversation

mugling
Copy link
Contributor

@mugling mugling commented Mar 25, 2016

There were only two instances where itype templates were modified after loading. The first was the charge rifle (dropped in #15713) and the second in defense mode where for some reason 2x4 is set to have zero weight and volume (dropped in 6b7a8dd).

This PR refactors Item_factory::find_template to return const itype * and changes the storage of template to be backed by std::unique_ptr. Item templates are now effectively immutable after loading although new templates can still be added. Nothing prevents the later addition of an explicit mutate_template method if such a need arises.

Incidentally noted during refactoring the parsing of magazine is insufficiently strict and I suspect nullptr references are possible dependent upon the JSON data. This is fixed in c057f35 which adds an additional test to Item_factory::check_definitions()

Item_factory::get_all_itypes() questionably breaks encapsulation so a future PR could consider deprecating that also.

Trivial merge conflict with #15901 should be easily resolvable when merge testing.

@mugling mugling changed the title Refactor item templates Refactor item templates [RDY] Mar 25, 2016
@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

Rebased against master

@Coolthulhu Coolthulhu self-assigned this Mar 26, 2016
@@ -589,6 +588,10 @@ void Item_factory::check_definitions() const
if( type->item_tags.count( "BIO_WEAPON" ) ) {
msg << "BIO_WEAPON must not be specified with an ammo type" << "\n";
}

if( !type->magazines.empty() && !type->magazine_default.count( type->gun->ammo ) ) {
msg << "specified magazine but none provided for default ammo type" << "\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Causes errors with mods, specifically Generic Guns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look now

@Coolthulhu
Copy link
Contributor

Worse: it seems to cause a segfault with the no magazines mod.

@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

Worse: it seems to cause a segfault with the no magazines mod.

I have debug symbols for that build so I'll take a look.

@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

Almost certainly 90db4e1 but I'm struggling to see why

@Coolthulhu
Copy link
Contributor

Maybe you're checking the magazine field of a gun that no longer has one?

@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

I think I have it, the conditional for magazines.empty() looks to have been inverted

@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

be84b8c fixes the segfault but the generic guns mod is still unhappy

@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

Have candidate fix for generic guns, waiting on --check-mods

@mugling
Copy link
Contributor Author

mugling commented Mar 26, 2016

Fixed in 387bf07

@Coolthulhu Coolthulhu merged commit a379bee into CleverRaven:master Mar 26, 2016
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.

None yet

2 participants