wc3edit.net

United Warcraft 3 map hacking!
It is currently May 28th, 2020, 2:00 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 6th, 2020, 7:01 pm 
Offline
Super Moderator
User avatar

Joined: February 24th, 2009, 1:31 pm
Posts: 3805
Location: JEW LAND
Unryze wrote:
owner123 wrote:
Very nice! Looks much cleaner even with just a quick glance over it. No more dynamic triggers and WaitForString calls.
Small efficiency comment: I'd make these commands use elseif rather than "endif/then" like this:
Code:
            if command == "debuff" then
               call UnitRemoveBuffs( jjUnit, true, true )
            endif
            if command == "heal" then
               call UnitRestoreLife( jjUnit, UnitMaxLife( jjUnit ) )
            endif

That way we can save computation on evaluating these ifs

Well, WC3 has a limit of about 50 elseifs or maybe a bit higher, I have actually run into a limit, when I was rewriting VIP system for NRPG, so I would actually suggest avoid using it, instead it's better to add return in the if statement to exit from the thread upon completion, or just leave it as is. Aka in WC3 elseif is still read as a separate if, and the lower you go the more "paths" it generates.

haxorico wrote:
Not talking about leaks, more about general coding.
For example, if I have a program with many different functions and loops (as many big projects have).

That is not really correct, every time a CreateGroup or DestroyGroup is called, WC3 is re-allocating memory, aka trying to free whatever was occupied and shifts it, to the changes. That also includes the shifting of arrays and so on, which is not really ideal.
Don't forget JASS only stores pointers, not the "objects" themselves. A Group is simply a dynamic array, that doesn't accept repeating entries, so there is no real point in destroying it, if it is used as a temporary group, which we can see in:

https://www.hiveworkshop.com/threads/ja ... st-2458284

The point is, you don't need to destroy a group that will be used frequently, but you should destroy a group that probably will never be used again, if it is used in something like MUI spells. The same reasoning applies even to C++, you generally want to avoid re-creating variables if they don't really serve any purpose (although C++ has a much better garbage collector than what Warcraft 3 has, but oh well).

And now for the natives, I am using 1.26a offsets, CreateGroup ( GameDll + 0x3D2900 ) and DestroyGroup ( GameDll + 0x3C3FA0 ):
Spoiler for CreateGroup:
Attachment:
CreateGroup.png


Spoiler for DestroyGroup:
Attachment:
DestroyGroup_2.png

Attachment:
DestroyGroup.png


haxorico wrote:
I will not use a single global integer called "i" or "index" that will be set to a starting value (like 0) at the beginning of each loop. As while no loop is using it, it is just some data that is sitting waiting and taking space.
When I need to use some data, I create it and when it is finished, destroy it.


You are comparing completely different types of variables, however, yes, with this example it is indeed better to get rid of unused variables, which I have stated above

haxorico wrote:
Example for a cheatpack, is aslong as the game is running, even if I am not using the cheat-pack (as I am a user who is unaware), there is data taking space (the group is still being created, an empty group is still taking some space).

Well, same goes for any of the code, right? User will never be aware of what is happening "under the hood" until he takes a peek.



Thank you for the great answer and explenation.
I haven't touched JASS for quite a while so was just curious on the aspect of recycling a variable and not destroying it after use.


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 7th, 2020, 12:11 am 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2331
Great in-depth analysis, Unryze!


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 17th, 2020, 2:04 am 
Offline
Newcomer

Joined: April 25th, 2020, 2:46 pm
Posts: 3
Hi there I got Q why -copy work only on heroes?


Top
 Profile  
 
 Post subject: Re: [JASS] JJCP: NewGen
PostPosted: May 18th, 2020, 10:33 pm 
Offline
Super Moderator

Joined: February 3rd, 2009, 11:28 pm
Posts: 2331
Because copying units was never programmed:
Code:
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
   if uid == 0 then
      set uid = GetUnitTypeId( source )
   endif
   if IsUnitType( source, UNIT_TYPE_HERO ) then
      set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
      call CopyStats( source, bj_lastCreatedUnit )
      call CopyItems( source, bj_lastCreatedUnit )
      call CopyState( source, bj_lastCreatedUnit )
   endif
endfunction

I think it can be updated like this:
Code:
function CopyHero takes unit source, integer uid, real locX, real locY returns nothing
local integer pid = GetPlayerId( GetOwningPlayer( source ) )
local real facing = GetUnitFacing( source )
   if uid == 0 then
      set uid = GetUnitTypeId( source )
   endif
   if IsUnitType( source, UNIT_TYPE_HERO ) then
      set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
      call CopyStats( source, bj_lastCreatedUnit )
      call CopyItems( source, bj_lastCreatedUnit )
      call CopyState( source, bj_lastCreatedUnit )
   else
      set bj_lastCreatedUnit = CreateUnit( Player( pid ), uid, locX, locY, facing )
   endif
endfunction


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

phpBB SEO


Privacy Policy Statement
Impressum (German)