System GameCache Extension

chobibo

Level 1 Crypt Lord
Reaction score
48
JASS:
//======================================================
//= GameCache Extension - by Chobibo
//=     Makes use of a string array for use as string 
//= keys when storing and retrieving data from the ga
//= mecache. Can be used for an estimated 66,044,033 
//= handle ids.
//= Reuirements: JassNewGen WE
//= Special thanks: To the people who made Jass
//=                 NewGen pack
//=                 To Blizzard for making gamecache
//======================================================

//*********************
//*** Function List ***
//*********************
//=== (Data Types: Integer, Real, Boolean)
//--> STORE FUNCTION
//--- Cache<Data Type>( handle h, <DataTypeAllowed> data ) Example: CacheReal( caster, 10.5 )
//---       *Saves data ( can be integer, real or boolean ) to the gamecache
//--> RETRIEVE FUNCTION
//--- Get<DataType>( handle h ) Example: GetBoolean(caster)
//---       *Retrieves the saved data by using the handle id of an object.
//*********************

//*** PROS
//--> uses 8191 string keys to store data onto gamecache
//--> can handle 66,044,033 data elements
//--> flushes the gamecache by itself
//--> you don't need to null local variables
//--> you don't need to worry about handleId leaks

//*** CONS
//--> uses gamecache, which is slow
//--> can only store integers, reals and booleans
//--> limited working capacity
//--> I made it( I'm noob )
//****************************

library GCX initializer Init

globals
    public string array Key
    public gamecache Cache = null
    private constant integer MaxValue = 8191
endglobals

public function H2I takes handle h returns integer
    return h
    return 0
endfunction

// === Initializes the string keys and the gamecache
public function Init takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i == MaxValue
        set Key<i> = I2S(i)
        set i=i+1
    endloop
    set i = 0
    if Cache == null then
        call FlushGameCache(InitGameCache(&quot;GCX&quot;))
        set Cache = InitGameCache(&quot;GCX&quot;)
    endif
endfunction

// === INTEGER
function CacheInteger takes handle h, integer i returns nothing
    local integer id = H2I(h)
    local integer x = id / MaxValue
    local integer y = id - x * MaxValue
    debug call BJDebugMsg(&quot;string key: &quot; + Key[x] + &quot;  :: mission key: &quot; + Key[y] + &quot;  :: Data: &quot; + Key<i>)
    call StoreInteger(Cache, Key[x], Key[y], i)
endfunction

function GetInteger takes handle h returns integer
    local integer id = H2I(h)
    local integer x = id / MaxValue
    local integer y = id - x * MaxValue
    local integer data = GetStoredInteger(Cache, Key[x], Key[y])
    debug call BJDebugMsg(&quot;string key: &quot; + Key[x] + &quot;  :: mission key: &quot; + Key[y] + &quot;  :: Return Data: &quot; + Key[data])
    call FlushStoredInteger(Cache, Key[x], Key[y])
    return data
endfunction

//=== REAL
function CacheReal takes handle h, real r returns nothing
    local integer id = H2I(h)
    local integer x = id / MaxValue
    local integer y = id - x * MaxValue
    debug call BJDebugMsg(&quot;string key: &quot; + Key[x] + &quot;  :: mission key: &quot; + Key[y] + &quot;  :: Data: &quot; + Key[R2I(r)])
    call StoreReal(Cache, Key[x], Key[y], r)
endfunction

function GetReal takes handle h returns real
    local integer id = H2I(h)
    local integer x = id / MaxValue
    local integer y = id - x * MaxValue
    local real data = GetStoredReal(Cache, Key[x], Key[y])
    debug call BJDebugMsg(&quot;string key: &quot; + Key[x] + &quot;  :: mission key: &quot; + Key[y] + &quot;  :: Return Data: &quot; + Key[R2I(data)])
    call FlushStoredReal(Cache, Key[x], Key[y])
    return data
endfunction

//=== BOOLEAN
function CacheBoolean takes handle h, boolean b returns nothing
    local integer id = H2I(h)
    local integer x = id / MaxValue
    local integer y = id - x * MaxValue
    debug local string s 
    debug if b==true then
        debug set s = &quot;true&quot;
    debug elseif b==false then
        debug set s = &quot;false&quot;
    debug endif
    debug call BJDebugMsg(&quot;string key: &quot; + Key[x] + &quot;  :: mission key: &quot; + Key[y] + &quot;  :: Data: &quot; + s)
    call StoreBoolean(Cache, Key[x], Key[y], b)
endfunction

function GetBoolean takes handle h returns boolean
    local integer id = H2I(h)
    local integer x = id / MaxValue
    local integer y = id - x * MaxValue
    local boolean data = GetStoredBoolean(Cache, Key[x], Key[y])
    debug local string s 
    debug if data==true then
        debug set s = &quot;true&quot;
    debug elseif data==false then
        debug set s = &quot;false&quot;
    debug else
        debug set s = &quot;Invalid data!&quot;
    debug endif
    debug call BJDebugMsg(&quot;string key: &quot; + Key[x] + &quot;  :: mission key: &quot; + Key[y] + &quot;  :: Return Data: &quot; + s)
    call FlushStoredBoolean(Cache, Key[x], Key[y])
    return data
endfunction

endlibrary



//=== Forced By WE ===
function InitTrig_GCX takes nothing returns nothing
endfunction</i></i>


A gamecache extension which is easy to use but can only store real, integer and boolean data types.

Uses an array of 8191 strings as missionkey and key for storing data so you wouldn't need to worry about handles not being recycled.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top