Jump to content

[in dev] Updating the scriptlib


Recommended Posts

Posted

currently the scriptlib ('universal') has some bad things in the code.

i'm on it to update this library, please do not commit any of those changes yet to the repo, it would break sd2 (i'll write a patch for sd2 before it will be ready for the repo).

here is the branch for it: http://github.com/DasBlub/mangos/commits/scriptlib_universal (actually only a clone from the master branch, i'll create a scriptlib_universal_0.12 when i'm done with the changes)

changes done:

* change the array m_scripts to a dynamic std::map, so we can have whatever amount of scripts we wanna have:


  • * change the array to std::map:
http://github.com/DasBlub/mangos/commit/3a6d2e275ecd0657270b3d077a3a4172c64c735b
* fix crash (sorry, didn't test the previous commit, so i haven't seen the NULL-pointer :/): http://github.com/DasBlub/mangos/commit/10d8ad5d865ff29cb66f8d27960d1eda0c7c58f5

changes to be done:

  • * code cleanup (if i've missed something^^)
    * move the functions into a class, this could help with implementing multithreading
    * move the GetAI_xyz() into the CreatureAI class
    * create a patchfile for sd2 before submitting this here

comments and ideas are welcome :)

if someone who knows the ACE lib will and knows how to implement multithreading could say here, what changes would be needed to implement a better multithreading, would that be nice :)

i had the idea, that we could multithread all instances in the script library (for every instance an own thread)... but i'm unsure if that isn't already the case when using the mtmaps patch?

Posted
change the array m_scripts to a dynamic std::map, so we can have whatever amount of scripts we wanna have
You don't need std::map to allow it to resize dynamically. std::vector is far more efficient for integer keys without holes.
Posted
You don't need std::map to allow it to resize dynamically. std::vector is far more efficient for integer keys without holes.
how would you make this association with an std::vector ?

i need a map, because i need the association scriptid (uint32) <-> script instance (Script*)

(the scriptid comes from the core and is not automatically calculated by the script library, else i would have used std::vector)

Posted
updating coding style
Adding i and ui for integer and unsigned integer is inconsistent with the rest of the code. These things were invented for a language where there were no integer types so they had to be marked, but in today's typesafe languages it's useless. In fact because of the need for camelcase, they are just irritating to read in my opinion. Adding the p for pointers generally doesn't improve readability either. If consistency is needed I'd rather remove all p's than add them everywhere. The compiler will definitely tell you if you tried to use a pointer as a normal reference.
Posted
(the scriptid comes from the core and is not automatically calculated by the script library, else i would have used std::vector)
The core can and does ensure that all IDs are generated in the order 1...N (where N is the number of scripts) so you can use the position of the element in the vector as the key of the association. In fact, scripts are never added without reloading the library, so it would be enough, and most efficient, to use a simple array but allocated dynamically at load.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use