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

Move Events methods to namespace #4692

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ramon-bernardo
Copy link
Contributor

Pull Request Prelude

Changes Proposed

  • Move Events methods to namespace.

Copy link
Contributor Author

@ramon-bernardo ramon-bernardo left a comment

Choose a reason for hiding this comment

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

I need assistance with these points. What decision should I make?

};
namespace tfs::events {

bool load();
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 prefer to change this for each events::x, as it gives us better control over each type. However, this approach will result in repeated code and reading the same file multiple times. I suggest this because I plan to add global events and move events to the namespace.

like

tfs::events::global::startup();
tfs::events::global::shutdown();
tfs::events::global::save();

src/events.cpp Outdated Show resolved Hide resolved
@@ -260,8 +259,7 @@ ReturnValue Combat::canDoCombat(Creature* caster, Tile* tile, bool aggressive)
if (aggressive && tile->hasFlag(TILESTATE_PROTECTIONZONE)) {
return RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE;
}

return g_events->eventCreatureOnAreaCombat(caster, tile, aggressive);
return tfs::events::creature::onAreaCombat(caster, tile, aggressive);
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'm still unsure whether to use tfs::events or tfs::game::events. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

tfs::events

src/events.cpp Fixed Show fixed Hide fixed
src/events.cpp Outdated Show resolved Hide resolved

namespace tfs::events {

bool load()

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 136 lines.
@MillhioreBT
Copy link
Contributor

@ranisalt to what extent is it good to use namespace to handle all singletons?
I personally like namespaces, but is it in its main function? Anyway, I can't think of any other idea.

@ramon-bernardo ramon-bernardo marked this pull request as ready for review May 26, 2024 13:12
@ranisalt
Copy link
Member

to what extent is it good to use namespace to handle all singletons?

Singletons are almost always a bad idea. Namespaces are an enhanced private section in a class, since you hide the implementation details and the compiler can assume it's not visible and perform more aggressive optimizations.

I like this post on how singletons are an awful idea in general. Namespaces don't solve it, but they make it less bad.

@EvilHero90 EvilHero90 added this to the 1.8 milestone Jun 2, 2024
@EvilHero90 EvilHero90 added the enhancement Increase or improvement in quality, value, or extent label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Increase or improvement in quality, value, or extent
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

4 participants