HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

System: GC vs Array?

01-04-2009, 07:20 PM#1
Thunder_Eye
I'm working on updating an old system of mine, but I need some answers on how to design/structure the code aswell as performance.

You can find the old submission-thread here: http://www.wc3campaigns.net/showthread.php?t=83177

I'm scripting it in normal JASS as I want it to be open for all.
Currently it heavily uses gamecache to store all the info, this only requires users to copy the gamecache variable and follow instructions on how to implent the rest of the system.

I'm thinking about using arrays, which would clutter up the Variable Editor abit, but overall increase the performance. Problem is I'm not sure if arrays are needed, the system isn't very cpu-heavy and it's easier to store data logically with the gamecache imo.

How the data is stored doesn't really matter for the end-user, the only difference is that they'd need to copy over more variables to their map if I decide to go for arrays.
So it's mostly a "Structure vs Performance" battle.

I'm also wondering which is better performance wise;
1. Looping through an array with ~200 values
2. Getting data from a gamecache ~15-20 times


I'm hoping to get some feedback and opinions on what you would use and why.
01-04-2009, 07:36 PM#2
Ammorth
I would use GC in this case, personally speaking.
01-04-2009, 07:39 PM#3
Themerion
Equipment system, it says... doesn't sound like you need extreme performance for that. I'd stick with gc or switch to vJASS.
01-04-2009, 07:47 PM#4
Thunder_Eye
Yes, the only problem I'm thinking of is when you equip an item. Currently the system loops through all the possible items (this can get quite high) to find the correct one.
I'm thinking about instead of storing them by id's I'd store them by their item-name to prevent this heavy gamecache-loop.
So instead of:
Code:
loop
  exitwhen RetrieveItemFromGC(i) == itemImSearchingFor
  code..
endloop
I'd have something like:
Code:
set itemImSearchingFor = GetFromGC(udg_gc, "", GetNameOfItem(i))
01-04-2009, 08:00 PM#5
Ammorth
I wouldn't use the name, but the id of the item ( 'I000' ). Use GetItemTypeId() to get the id of each item (same as the rawcode) and then use that as one of the keys for the gc.
01-04-2009, 08:01 PM#6
Themerion
Name's no good. Multiple items can have the same name. Use I2S(GetItemTypeId(itm)) instead.
01-04-2009, 08:15 PM#7
Thunder_Eye
Hmm yes that would be better indeed.
Thanks for the help! If I can remove that loop with this I think I'm staying with GC.
01-05-2009, 03:33 AM#8
chobibo
I think warcraft's internal string table could help you, I just don't know if it's safe to use, since gamecache already uses strings, caching string wouldn't bother the system.

Collapse JASS:
globals
    integer udg_ItemOffset = 0
    
    integer array udg_Items
endglobals

function GetStringId takes string s returns integer
    return s
    return 0
endfunction

function InitItemTable takes nothing returns nothing

    set udg_Items[0]='Iswd'
    set udg_Items[1]='Igun'
    set udg_Items[2]='Ipot'
    set udg_Items[3]='Ipen'
    set udg_Items[4]='Id98'
    set udg_Items[5]='Iund'
    set udg_Items[6]='Iflr'
    set udg_Items[7]='I019'  
    
    set udg_ItemOffset=0
    
    loop
        exitwhen udg_Items[udg_ItemOffset]==null
        call I2S(udg_Items[udg_ItemOffset])
        set udg_ItemOffset=udg_ItemOffset+1
    endloop
    
    set udg_ItemOffset=GetStringId(I2S(udg_Items[0]))
endfunction

// Example

function sample takes nothing returns nothing
    local integer item_id=GetItemTypeId(GetManipulatedItem())
    
    set item_id=GetStringId(I2S(item_id))
    
    if (item_id > 0 and item_id < 8) then
        // item is on the item table
    else
        // item not found on the item table
    endif
endfunction