forgottenserver icon indicating copy to clipboard operation
forgottenserver copied to clipboard

Rework Class Creature, Cylinder and Item from Raw Pointer to Smart Pointer

Open alysonjacomin opened this issue 2 months ago • 6 comments

  • Change from Raw Pointer to Smart Pointer (Shared Pointer in this cases);
  • Use enable_shared_from_this for compatibility with Shared Pointer;
  • Use "weak_ptr" when necessary;
  • Create using "Class_ptr" for each Class;
  • Keep the object alive and send only the reference to subsequent functions with "Class_ptr&" to get the best performance + good naming semantics;
  • Create virtual function on Class Thing "getClass()" for each Class and Sub-Class, this way we avoid using dynamic_cast which is more expensive.

alysonjacomin avatar Oct 28 '25 02:10 alysonjacomin

We're (me and @ramon-bernardo) are halfway there in https://github.com/ranisalt/forgottenserver/pull/9 but there are a few issues still. I'm going to open a PR here when it's done

ranisalt avatar Oct 30 '25 01:10 ranisalt

I hadn't seen that branch!

Very good, I'll take a look and try to contribute some details as well

alysonjacomin avatar Oct 30 '25 10:10 alysonjacomin

Not directly related to shared_ptr, but we intend to remove Cylinder class 😃 (https://github.com/otland/forgottenserver/pull/5058)

ramon-bernardo avatar Nov 17 '25 14:11 ramon-bernardo

@ramon-bernardo In this case, are you continuing what was started in PR #5022 ?

alysonjacomin avatar Nov 17 '25 20:11 alysonjacomin

@alysonjacomin something that is present in the shared PR and we reviewed it for another

ramon-bernardo avatar Nov 18 '25 13:11 ramon-bernardo

The smart pointer PR is just getting split so it's easier to track issues and review

ranisalt avatar Nov 19 '25 10:11 ranisalt