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("GCX"))
set Cache = InitGameCache("GCX")
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("string key: " + Key[x] + " :: mission key: " + Key[y] + " :: Data: " + 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("string key: " + Key[x] + " :: mission key: " + Key[y] + " :: Return Data: " + 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("string key: " + Key[x] + " :: mission key: " + Key[y] + " :: Data: " + 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("string key: " + Key[x] + " :: mission key: " + Key[y] + " :: Return Data: " + 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 = "true"
debug elseif b==false then
debug set s = "false"
debug endif
debug call BJDebugMsg("string key: " + Key[x] + " :: mission key: " + Key[y] + " :: Data: " + 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 = "true"
debug elseif data==false then
debug set s = "false"
debug else
debug set s = "Invalid data!"
debug endif
debug call BJDebugMsg("string key: " + Key[x] + " :: mission key: " + Key[y] + " :: Return Data: " + 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.