- Reaction score
- 456
DS - Data Store
by: Uberplayer
by: Uberplayer
So this is just another struct attaching system. I've been testing this many many times, and no problems thus far. This has some kind of a extended arrays system (written by me also) inside the library, but I made them private, because this system uses them.. so they shouldn't be used anywhere else.
Hopefully this does not look like a copy of another already made system.
Code:
JASS:
//= = = = = = = = = = = = = = = =
// DS - DATA STORE
//= = = = = = = = = = = = = = = =
// Author: Uberplayer @thehelper
// Version: 2.0
// Date: 02/25/2008 - 03/03/2008
//= = = = = = = = = = = = = = = =
// Implementing
// ¯¯¯¯¯¯¯¯¯¯¯¯
// Just copy this trigger to your map. Only system DS
// requires is Extended Arrays, which can be found from
// this library.
//
// How To Use?
// ¯¯¯¯¯¯¯¯¯¯¯
// You can store one integer per one trigger or
// timer.
//
// Use these functions to store integer to a handle:
// call SetTriggerData(trigger whichTrigger, integer data)
// call SetTimerData(timer whichTimer, integer data)
//
// Use these functions to get an integer from a handle:
// call GetTriggerData(trigger whichTrigger)
// call GetTimerData(timer whichTimer)
library DataStore
public function H2I takes handle h returns integer
return h
return 0
endfunction
//=-=-=
// I. EXTENDED ARRAYS
//=-=-=
//! textmacro ExtendedArrays takes TYPE, TYPENAME, REMOVE
globals
private $TYPE$ array $TYPE$ArrayA // 0 - 8192
private $TYPE$ array $TYPE$ArrayB // 8193 - 16385
private $TYPE$ array $TYPE$ArrayC // 16386 - 24578
private $TYPE$ array $TYPE$ArrayD // 24579 - 32771
private $TYPE$ array $TYPE$ArrayE // 32772 - 40964
private $TYPE$ array $TYPE$ArrayF // 40965 - 49157
private $TYPE$ array $TYPE$ArrayG // 49158 - 57350
private $TYPE$ array $TYPE$ArrayH // 57351 - 65543
endglobals
private function Get$TYPENAME$Array takes integer index returns $TYPE$
local integer loopA = index
if index < 8193 then
return $TYPE$ArrayA[index]
elseif index < 16386 then
return $TYPE$ArrayB[index - 8193]
elseif index < 24579 then
return $TYPE$ArrayC[index - 16386]
elseif index < 32772 then
return $TYPE$ArrayD[index - 24579]
elseif index < 40965 then
return $TYPE$ArrayE[index - 32772]
elseif index < 49158 then
return $TYPE$ArrayF[index - 40965]
elseif index < 57351 then
return $TYPE$ArrayG[index - 49158]
elseif index < 65544 then
return $TYPE$ArrayH[index - 57351]
endif
return $REMOVE$
endfunction
private function Set$TYPENAME$Array takes $TYPE$ value, integer index returns nothing
local integer loopA = index
if index < 8193 then
set $TYPE$ArrayA[index] = value
elseif index < 16386 then
set $TYPE$ArrayB[index - 8193] = value
elseif index < 24579 then
set $TYPE$ArrayC[index - 16386] = value
elseif index < 32772 then
set $TYPE$ArrayD[index - 24579] = value
elseif index < 40965 then
set $TYPE$ArrayE[index - 32772] = value
elseif index < 49158 then
set $TYPE$ArrayF[index - 40965] = value
elseif index < 57351 then
set $TYPE$ArrayG[index - 49158] = value
elseif index < 65544 then
set $TYPE$ArrayH[index - 57351] = value
endif
endfunction
//! endtextmacro
//! runtextmacro ExtendedArrays("integer", "Integer", "-1")
//! runtextmacro ExtendedArrays("trigger", "Trigger", "null")
//! runtextmacro ExtendedArrays("timer", "Timer", "null")
//! runtextmacro ExtendedArrays("unit", "Unit", "null")
//=-=-=
// II. DATA STORE
//=-=-=
//! textmacro DataStore takes TYPE, TYPENAME
function Get$TYPENAME$Data takes $TYPE$ which$TYPENAME$ returns integer
local integer loopA = 0
local integer id = H2I(which$TYPENAME$) - 23104 * 45
if Get$TYPENAME$Array(id) != which$TYPENAME$ then
debug call BJDebugMsg("|CFFED1C24DS Error (get): Unknown handle.")
return -1
endif
return GetIntegerArray(id)
endfunction
function Set$TYPENAME$Data takes $TYPE$ which$TYPENAME$, integer data returns nothing
local integer loopA = 0
local integer id = H2I(which$TYPENAME$) - 23104 * 45
if which$TYPENAME$ == null then
debug call BJDebugMsg("|CFFED1C24DS Error (set): Null handles not allowed.")
return
endif
call SetIntegerArray(data, id)
call Set$TYPENAME$Array(which$TYPENAME$, id)
endfunction
//! endtextmacro
//! runtextmacro DataStore("trigger", "Trigger")
//! runtextmacro DataStore("timer", "Timer")
//! runtextmacro DataStore("unit", "Unit")
endlibrary