- Joined
- Jan 2, 2020
- Messages
- 1,414
This is a simple example on how to put both x & y inside one int
It also shows you how to create an efficient stack, without security checks.
This way we can shove away many coordinates with great speed and less memory.
It also shows you how to create an efficient stack, without security checks.
This way we can shove away many coordinates with great speed and less memory.
Cerberus:
' -------------------------------------------------------------
' Say that we want to push a lot of positions efficiently
' x & y can each be 0-16383 in this example
' -------------------------------------------------------------
Strict
Global data:Int[65535] ' Create a stack
Global sp:Int = 32768 ' Create a stack pointer, prepared for a circular datastack
Function Main:Int()
Local x:Int = 10 ' Set coordinates
Local y:Int = 100
' PUSH X,Y -------------------------------
sp = sp - 1 ; data[sp] = ( (x Shl 14) + y)
' ------------------------------------------
x = 435833 ' destroy coordinates
y = 34894
' POP X,Y ---------------------------------------------------------------------
Local m:Int = data[sp] ; sp = sp + 1 ; x = (m Shr 14) & 16383 ; y = m & 16383
' ------------------------------------------------------------------------------
Print x ' Proove that we have restored the coordinates
Print y
Return 0
End
Last edited: