Skip to content

Move Events methods to namespace#4692

Closed
ramon-bernardo wants to merge 54 commits intootland:masterfrom
ramon-bernardo:events-namespace
Closed

Move Events methods to namespace#4692
ramon-bernardo wants to merge 54 commits intootland:masterfrom
ramon-bernardo:events-namespace

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

@ramon-bernardo ramon-bernardo May 19, 2024

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();

}

return g_events->eventCreatureOnAreaCombat(caster, tile, aggressive);
return tfs::events::creature::onAreaCombat(caster, tile, aggressive);
Copy link
Contributor Author

@ramon-bernardo ramon-bernardo May 19, 2024

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


namespace tfs::events {

bool load()

Check warning

Code scanning / CodeQL

Poorly documented large function

Poorly documented function: fewer than 2% comments for a function of 136 lines.
ranisalt and others added 2 commits May 21, 2024 16:02
* doubling the vartrack size

Increasing the max-vartrack-size because luascript.cpp has a function which exceeded the limit and thus the build failed
@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.

ranisalt and others added 10 commits May 22, 2024 01:42
* Refactor Docker image workflow with docker actions
* Don't install libiconv outside OSX, install Lua by default
* Use Guild shared_ptr

* Member rank level default to constexpr

* Use const when possible

* @ramon-bernardo
Use const when possible

* Use shared_ptr alias

* Fix

* Fix

* Fix

* Fix

* Fix delete

* Fix

* No need to reuse the variable

* Use const shared ptr

* Use const& ptr

* Inline rank check
@ramon-bernardo ramon-bernardo requested a review from ranisalt May 26, 2024 13:11
@ramon-bernardo ramon-bernardo marked this pull request as ready for review May 26, 2024 13:12
* Split game core into different files

* eof
@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.

ranisalt and others added 28 commits June 2, 2024 23:41
thrown an error when it didn't find a single number included in the message
… by 1 (#4733)

Co-authored-by: EvilHero90 <Shadow280690@hotmail.de>
The first leak in #4288 is related to handle leaking, I couldn't really reproduce how mysql_init is called without mysql_close not being called on the line before, but using a unique_ptr with a custom deleter fixes the leak.

Using unique_ptr for MYSQL_RES also fixes eventual leaks that happen on queries.
* Compilation problem issue template update

I've added
- Buildtype
- Compiler flags
for more information

Co-authored-by: Ranieri Althoff <1993083+ranisalt@users.noreply.github.com>
- npc now correctly clears all npc id data when he is removed
- farewell and greet messages can be individually set per talk state if not they fall back to default
- fixed a bug if the npc disappeared while the player was talking to him, then the npc would not respond to the player again once he was spawned
- better warning/error messages which show which npc it occured and which file it originates from
- added shop callback function callback(npc, player, handler, items, afterDiscount) order:
- discount (if there is any) -> callback
- added NpcsHandler:player() this is basicly the equivalent to requirements but instead of requireing you can add/set stuff to the player (modules.lua)
- implemented modules they're load after callbacks order:
    requirements (if returns true) -> callback (if returns true) -> modules
- moved teleport/addItems/setStorageValue to modules
- added new requirements
- changed the requirements functions
- I've included the error message directly inside the functions
- removed :failureRespond & :getFailureRespond as they're redundant with requirement re work
- changed modules outfit function it requires to insert 2 different outfits now because of 2 different player sexes
    ex: :outfit(id1, id2, addon)
- a few linter/annotation fixes
- if the player changed the talk state but still had the shop open and then tried to purchase something it thrown errors, this is now fixed
Release of The Forgotten Server 1.6
The start of `The Forgotten Server 1.7` Development cycle
* Fix some warnings and improve type annotations

* Fix `item:transform` type annotation

* Remove `dump` function from compat.lua

* Fix `configKeys` type annotations

* Refactor all enums/constants of `cpplinter.lua` and fix ident style to tabs

Some were missing and others were wrong, I got them all directly from the source.

* Refactor the PlayerFlag constants in cpplinter.lua to use bitwise shift operators instead of exponentiation
* Moved everything to NpcScriptInterface

There was an issue with the Revisioned Npc System.
Because it was included in 2 different lua environments it would not correctly work on any of the cmake builds only the msvc builds worked fine (they somehow have shared lua envs)
Now the npcs should correctly work as it's expected
Moved all std::vector out of the pointer class itself and put them into their singleton classes (Actions/MoveEvents)
They're now stored in a std::map map by their pointer as a std::vector and once it is registered it clears the std::map with the pointer index.
- checking first if the pointer has a map (is valid) before trying to get it's content
this sets NULL default for session tokens, just for safety
Add monster icons correctly when creature appears on the screen
- Added `onSight` event, this has to be enabled with `NpcType:sight(x, y)` unless that is not set the event wont fire. This event triggers whenever a creature (monsters/npcs/players) steps into the sight range, will only re trigger once you walk out of idle range and back in again.
- fixed event callbacks, they're now moved into `NpcCallbacks` they can be set like: `NpcType:callbacks().onSay/onSight/etc.`
- fixed a crash which could occur if you had a npc disabled then enabled him and /reload npcs, this is now fixed
- fixed a crash that if a xml npc is invalid on server startup that it throws an error instead of crashing
- made all the functions in the lib overloadable, only the table data is protected, you can now change functions and they will be correctly changed on /reload npcs
- changed everything related to focus from seconds into ms
- changed focus so it works for all creatures not only players
- changed NpcTalkQueue it now works for creatures not only for players
- changed the onCreatureSay event, it now triggers for all creatures not only for players
- selfSay has a new parameter now called talkType which is optional and falls back to TALKTYPE_SAY
- added `onSpeechBubble` event, with this we can set the speech bubble for each player individual.
example:
Npc has a quest for the player he only shows for this player the quest speech bubble, once the quest is finished the npc wont have a quest speech bubble anymore

---------

Co-authored-by: Evil Puncker <EPuncker@users.noreply.github.com>
Co-authored-by: KrecikOnDexin <krecikondexin@gmail.com>
* Remove Account class and account.h file

* Update theforgottenserver.vcxproj
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: Done

Development

Successfully merging this pull request may close these issues.