Jass Vault WC3Jass.com
"The Jass Vault"
 
 FAQ   Search   Memberlist   Usergroups   Register 
 Profile   Log in to check your private messages   Log in  
 Forum   Scripts   Files   Chat   Pastebin   Function finder  
Affiliates
The HIVE Workshop Games Modding
The Hubb Wc3Campaigns
WC3-Mapping.net

Handle Lists

 
Post new topic   Reply to topic    Jass Vault -> Systems
View previous script :: View next script  

Script code
// Variables
// -> real array udg_ListValues
// -> location array udg_ListArray


// Conversions


function R2L takes real r returns location
	return r
	return null
endfunction

function I2L takes integer i returns location
	return i
	return null
endfunction

function ItoR takes integer i returns real
	return i
	return 0.
endfunction

function RtoI takes real r returns integer
	return r
	return 0
endfunction

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

function H2R takes handle h returns real
	return h
	return 0.
endfunction


// List Functions


function NewList takes integer index,real value returns location
	// Generates a new list and adds a first item to it
	return Location(0,H2R(Location(ItoR(index),value)))
endfunction

function ListAdd takes location list,integer index,real value returns nothing
	// Adds a new element behind the first element of the list
	call MoveLocation(list,H2R(Location(GetLocationX(list),H2R(Location(ItoR(index),value)))),GetLocationY(list))
endfunction

function ListGetRem takes location list,integer index returns real
	// Returns the value from a specific index saved in a list
	// and removes the item
	local location data
	local location lastreferrer=list
	local location referrer=list
	local integer i
	local real r
	loop
		exitwhen referrer==null
		set data=R2L(GetLocationY(referrer))
		set i=RtoI(GetLocationX(data))
		if i==index then
			set r=GetLocationY(data)
			if referrer==list then
				set referrer=R2L(GetLocationX(referrer))
				if referrer==null then
					set referrer=list
				else
					call MoveLocation(list,GetLocationX(referrer),GetLocationY(referrer))
				endif
			else
				call MoveLocation(lastreferrer,GetLocationX(referrer),GetLocationY(lastreferrer))
			endif
			call RemoveLocation(data)
			call RemoveLocation(referrer)
			set referrer=null
			set lastreferrer=null
			set data=null
			return r
		endif
		set lastreferrer=referrer
		set referrer=R2L(GetLocationX(referrer))
	endloop
	set lastreferrer=null
	set data=null
	return 0.
endfunction

function ListGet takes location list,integer index returns real
	// Returns the value from a specific index saved in a list
	local location data
	local location referrer=list
	local integer i
	local real r
	loop
		exitwhen referrer==null
		set data=R2L(GetLocationY(referrer))
		set i=RtoI(GetLocationX(data))
		if i==index then
			set r=GetLocationY(data)
			set data=null
			set referrer=null
			return r
		endif
		set referrer=R2L(GetLocationX(referrer))
	endloop
	set data=null
	return 0.
endfunction


function ListSet takes location list,integer index,real value returns nothing
	// Changes an existing item with the given index
	local location data
	local location referrer=list
	local integer i
	loop
		exitwhen referrer==null
		set data=R2L(GetLocationY(referrer))
		set i=RtoI(GetLocationX(data))
		if i==index then
			call MoveLocation(data,GetLocationX(data),value)
			set referrer=null
			set data=null
			return
		endif
		set referrer=R2L(GetLocationX(referrer))
	endloop
	set data=null
	call ListAdd(list,index,value)
endfunction


function ReadListRem takes location list returns nothing
	// Saves the values of a list into a global array
	// This cannot save values with an index higher than 8192
	// Afterwards destroys the list
	local location data
	local location referrer=R2L(GetLocationX(list))
	local integer i
	local real r
	loop
		exitwhen referrer==null
		set data=R2L(GetLocationY(referrer))
		set i=RtoI(GetLocationX(data))
		set udg_ListValues[i]=GetLocationY(data)
		set r = GetLocationX(referrer)
		call RemoveLocation(data)
		call RemoveLocation(referrer)
		set referrer=R2L(r)
	endloop
	set data=null
endfunction

function ReadList takes location list returns nothing
	// Saves the values of a list into a global array
	// This cannot save values with an index higher than 8192
	local location data
	local location referrer=R2L(GetLocationX(list))
	local integer i
	loop
		exitwhen referrer==null
		set data=R2L(GetLocationY(referrer))
		set i=RtoI(GetLocationX(data))
		set udg_ListValues[i]=GetLocationY(data)
		set referrer=R2L(GetLocationX(referrer))
	endloop
	set data=null
endfunction


function DestroyList takes location list returns nothing
	// Removes all items and the list
	local location referrer=list
	local location data
	local real r
	loop
		exitwhen referrer==null
		set data=R2L(GetLocationY(referrer))
		set r = GetLocationX(referrer)
		call RemoveLocation(data)
		call RemoveLocation(referrer)
		set referrer=R2L(r)
	endloop
	set data=null
endfunction


// Handle Functions


function GetHandleList takes handle h returns location
	// Returns the list attached to the given handle
	local integer handleid=H2I(h)
	return ListGet(udg_ListArray[ModuloInteger(handleid,8192)],handleid/8192)
	return null
endfunction


function UnsetHandleList takes handle h returns nothing
	// Removes the list from the handle
	// This does not destroy the list itself
	local integer handleid=H2I(h)
	call ListGetRem(udg_ListArray[ModuloInteger(handleid,8192)],handleid/8192)
endfunction


function SetHandleList takes handle h,location list returns nothing
	// Attachs a list to the given handle
	local integer handleid=H2I(h)
	local integer i = ModuloInteger(handleid,8192)
	if udg_ListArray[i]==null then
		set udg_ListArray[i] = Location(0,H2R(Location(ItoR(handleid/8192),H2R(list))))
	else
		call ListAdd(udg_ListArray[i],handleid/8192,H2R(list))
	endif
endfunction


function NewHandleList takes handle h,integer index,real value returns location
	// Creates a list with a first item and instantly attachs it to the given handle
	local integer handleid=H2I(h)
	local integer i = ModuloInteger(handleid,8192)
	local real r=H2R(Location(0,H2R(Location(ItoR(index),value))))
	if udg_ListArray[i]==null then
		set udg_ListArray[i] = Location(0,H2R(Location(ItoR(handleid/8192),r)))
	else
		call ListAdd(udg_ListArray[i],handleid/8192,r)
	endif
	return r
	return null
endfunction


// Execution Helpers


function ListGetLocationRem takes location list,integer index returns location
	return ListGetRem(list,index)
	return null
endfunction

function ListGetLocation takes location list,integer index returns location
	return ListGet(list,index)
	return null
endfunction


function ListGetUnitRem takes location list,integer index returns unit
	return ListGetRem(list,index)
	return null
endfunction

function ListGetUnit takes location list,integer index returns unit
	return ListGet(list,index)
	return null
endfunction


function ListGetGroupRem takes location list,integer index returns group
	return ListGetRem(list,index)
	return null
endfunction

function ListGetGroup takes location list,integer index returns group
	return ListGet(list,index)
	return null
endfunction


function ListGetEffectRem takes location list,integer index returns effect
	return ListGetRem(list,index)
	return null
endfunction

function ListGetEffect takes location list,integer index returns effect
	return ListGet(list,index)
	return null
endfunction


function ListSetHandle takes location list, integer index,handle value returns nothing
	call ListSet(list,index,H2R(value))
endfunction


function NewHandleListHandle takes handle h,integer index,handle value returns location
	return NewHandleList(h,index,H2R(value))
endfunction
Script info
Description
I made this system because i dont trust gamecaches...
it combines linked list with an infinite array system to store information attached to handles

it just works fine, but still needs some performance improvements i think

if you find any bugs, leaks etc, tell me!

EDIT: perhaps i should mention, that empty lists do not exist in this system, so if you remove the last element of the list, it automatically destroys the list

Author
Mapz_Maker


Joined: 25 Nov 2006
Comments: 178
Back to top
Message
CommentPosted: Mon Aug 06, 2007 3:15 pm    Post subject: Reply with quote

Interesting...
tell me if my first impression is correct: This is storing the handle to complex object inside of the y-value of a location? Have not looked at it very long but your description is very uninformative. I learned just about nothing from the description except that "it is a linked list infinite array system".
Would you elaborate more on what you mean by infinite array system? I am not sure I understand how you made an infinite array system.
View user's profile Send private message

Author
Bob666


Joined: 29 Jun 2007
Comments: 192
Back to top
Message
CommentPosted: Mon Aug 06, 2007 4:47 pm    Post subject: Reply with quote

ive an array with location, and then, if a array index is set, it adds a linked list to one of that locations (modulo 8192)... if there are more, it adds more... in this case i am using handle ids as indexes, and in the y-value a new list can be created to be attached to that index
_________________
Projects:
SupCom | WC3 FlightSim | JASS Benchmark
View user's profile Send private message Visit poster's website

Author
lbebusiness
Guest



Back to top
Message
CommentPosted: Tue Feb 03, 2009 3:47 am    Post subject: thehelper.net Reply with quote

Add lasers and you could go holographic with this!

Display posts from previous:   
Post new topic   Reply to topic    Jass Vault -> Systems All times are GMT
Page 1 of 1

 
Jump to:  
You can submit new scripts in this section
You can comment on scripts in this section
You cannot edit your scripts in this section
You cannot delete your scripts in this forum



FSDark by SkaidonDesigns
Powered by phpBB © 2001, 2002 phpBB Group