Page MenuHomeWildfire Games

Make IGUIObject settings a template class
ClosedPublic

Authored by elexis on Sun, Aug 4, 3:33 AM.

Details

Summary

This transforms IGUIObject settings to a template class and IGUIObject::AddSetting to a template function.

This means the type information is available for all methods operating with the setting type, which is easier for the authors, allows for compile-time checks and optimizations.
Remove the enum that was used to indirectly obtain the setting type at runtime.
Revised SGUISetting and enum from rP290 (rP74), std::function from rP22574.

Move this to GUIUtil.cpp in anticipation of merging the other functions and since its a complex class that should be in a separate file concering only settings.

rP22596 removed one fringe use case of the enum.

Test Plan

Fight the compilers. Adore the vanished ugliness. Make sure the delete is in place and no leak snuck in.
Ways to reduce the number of GUItypes.h inclusions are to be considered, but will probably be easier to manage in an independent patch.

Brief mentioning on #0ad-dev on http://irclogs.wildfiregames.com/2019-07/2019-07-30-QuakeNet-%230ad-dev.log

21:48 < elexis> Vladislav: also would you agree that AddSetting<CStrW>("sound_released"); is better than AddSetting(GUIST_CStrW, "sound_released");?
21:49 < Vladislav> elexis: yes, the template one looks more strict.

I've compiled with gcc 9, clang 8.0.1, VS2015, Jenkins.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Sun, Aug 4, 3:33 AM
Vulcan added a comment.Sun, Aug 4, 3:45 AM

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

Linter detected issues:
Executing section Source...

source/gui/IGUIObject.h
| 169| »   ·*·example·a·CRect(10,10,20,20)·would·be·"10·10·20·20"
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classCClientArea{' is invalid C code. Use --std or --language to configure the language.

source/gui/GUIutil.h
|  45| template<typename·T>·class·GUI;
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'template<...' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/299/display/redirect

elexis edited the test plan for this revision. (Show Details)Sun, Aug 4, 4:13 AM
This revision was not accepted when it landed; it landed in state Needs Review.Sun, Aug 4, 4:20 AM
This revision was automatically updated to reflect the committed changes.
elexis edited the summary of this revision. (Show Details)Sun, Aug 4, 4:24 AM