@Preben, here is your code working in AGK2 so I have tried it and saw it running on Android now
To be honest it didn't need much changing and was just a couple of Syntax things which must have been since AGK1.
Works quite well with the lines etc, will have to see if I can take out just the drawing commands and see what that is like
Cheers.
rem
rem The Wall: Preben Eriksen 31-01-2012 using AGK.
rem
global maxclients = 16
global maxdrawers = 5
global maxlines = 1500
global clientnumber = 0
global firstconnect = 1
global lmsg$
global nettimestart
global mintimer
global iNetID = 0
global joindelay = 5 // try reconnect every 5 sec.
dim connections[maxclients]
dim connectionss[maxclients]
dim spritelines[ maxlines * maxclients]
dim spritexya[ maxlines * maxclients,2 ]
dim spritexyb[ maxlines * maxclients,2 ]
dim spritecolor[ maxlines * maxclients,3 ]
dim download[16384] as integer
global maxbuf = 17 // avoid max packetsize of (34) 1400b AGK limit.
global curbuf = 1
dim netbuffer[maxbuf,10]
global flushtimer
flushtimer = Timer()
global selections = 0
global selection = 1
global curroom = 0
global viewrooms = 0
global viewroom = 1
selections = createSprite ( 0 )
setSpriteSize ( selections , 18 , 26 )
SetSpriteColor ( selections , 255 , 255 , 255 , 64 )
SetSpriteDepth( selections , 0)
viewrooms = createSprite ( 0 )
setSpriteSize ( viewrooms , 18 , 18 )
SetSpriteColor ( viewrooms , 255 , 255 , 255 , 64 )
SetSpriteDepth( viewrooms , 0)
for a = 1 to maxclients
connectionss[a] = createSprite ( 0 )
setSpriteSize ( connectionss[a] , 10 , 10 )
SetSpriteColor ( connectionss[a] , 128 , 128 , 128 , 128 )
SetSpriteDepth( connectionss[a] , 0)
next a
clientstr$ = str(random(1,9999))
if GetAccelerometerExists() = 1
//delay a bit.
for a = 1 to 30
sync()
next a
endif
iNetID = JoinNetwork("66.23.226.207", 4800 , "PLEMGameServer")
SetNetworkLatency( iNetID, 10 )
nettimestart = Timer()
mintimer = Timer()
recordspeed# = 0.08
/*
global oldx# as float
global oldy# as float
global x# as float
global y# as float
*/
oldx# = -1
oldy# = -1
x# = -1
y# = -1
screengrid# = 2
global pensize = 3
global recordindex = 1
global oldrecordindex = 1
global downs = 0
global users = 0
SetVirtualResolution ( 320 , 480 )
SetOrientationAllowed ( 1, 1, 1, 1 )
SetSyncRate( 60, 0 )
SetClearColor( 24 , 47 , 80 )
setuplines()
global screenwidth = 0
global screenheight = 0
global orintation = 0
global packets = 0
global reconnect = 0
getorintation()
rem A Wizard Did It!
lastFrame# = Timer ( )
do
if IsNetworkActive(iNetID)=0 and ( timer() - nettimestart) > joindelay
nettimestart = Timer()
CloseNetwork( iNetID )
iNetID = JoinNetwork("66.23.226.207", 4800 , "PLEMGameMobile") // + clientstr$)
reconnect = reconnect + 1
lmsg$ = "reconnecting..."
else
if GetNetworkNumClients(iNetID) > 1
SetNetworkLatency( iNetID, 10 )
if firstconnect = 1
// get client number.
cnum$ = getclientnumber()
//lmsg$ = "CN: " + cnum$
clientnumber = Val( cnum$ ) - 1
curroom = clientnumber
viewroom = curroom
if viewroom >= maxdrawers
viewroom = maxdrawers-1
endif
if clientnumber < 0
// failed ?
lmsg$ = "Cant get client number, are you on the internet ?"
else
lmsg$ = ""
connections[clientnumber+1] = 1
// download media.
checkfiles("p1")
checkfiles("u1")
// setup toolbar image.
downi = loadImage ( "p1.png" )
downs = createSprite ( downi )
useri = loadImage ( "u1.png" )
users = createSprite ( useri )
sentline((curroom*maxlines)+1,0 , 0 , 0 , 0 , -1, -1, -1 , 2)
firstconnect = 0
endif
endif
msg = GetNetworkMessage(iNetID)
while msg > 0
ClientID = GetNetworkMessageFromClient(msg)
packets = packets + 1
//lmsg$ = "packets: " + str(packets) + " rec: " + str(reconnect)
if ClientID > 0
bufpackets = GetNetworkMessageInteger(msg)
for packloop = 1 to bufpackets
// get draw data from other client.
// client number.,size
cnumber = GetNetworkMessageInteger(msg)
if cnumber >= 0 and cnumber <= maxclients
connections[cnumber+1] = Timer()
endif
// later move to rooms. (cnumber)
a = GetNetworkMessageInteger(msg) // line number
if a > 0 and a < (maxlines*maxdrawers) and spritexya[a,1] < 800 and spritexya[a,2] < 800 and spritecolor[a,2] < 256
spritexya[a,1] = GetNetworkMessageInteger(msg)
spritexya[a,2] = GetNetworkMessageInteger(msg)
spritexyb[a,1] = GetNetworkMessageInteger(msg)
spritexyb[a,2] = GetNetworkMessageInteger(msg)
spritecolor[a,1] = GetNetworkMessageInteger(msg)
spritecolor[a,2] = GetNetworkMessageInteger(msg)
spritecolor[a,3] = GetNetworkMessageInteger(msg)
//spritecolor[a+1,1] = -1
// loop for all data.
clearstart = 0
clearend = 0
if a = 1 and spritecolor[a,1] = -1
clearstart = 1
clearend = maxlines
elseif a = maxlines+1 and spritecolor[a,1] = -1
clearstart = maxlines+1
clearend = maxlines*2
elseif a = 2*maxlines+1 and spritecolor[a,1] = -1
clearstart = maxlines*2+1
clearend = maxlines*3
elseif a = 3*maxlines+1 and spritecolor[a,1] = -1
clearstart = maxlines*3+1
clearend = maxlines*4
elseif a = 4*maxlines+1 and spritecolor[a,1] = -1
clearstart = maxlines*4+1
clearend = maxlines*5
endif
if clearstart > 0 or clearend > 0
for b = clearstart to clearend
spritecolor[b,1] = -1
SetSpritePosition( spritelines[b] , 1000 , 1000 )
spritexya[ b, 1 ] = -1
spritexya[ b, 2 ] = -1
spritexyb[ b, 1 ] = -1
spritexyb[ b, 2 ] = -1
next b
endif
endif
next packloop
endif
DeleteNetworkMessage(msg)
msg = GetNetworkMessage(iNetID)
endwhile
endif
endif
getorintation()
if downs <> 0
SetSpritePosition( downs , screenwidth/2-160 , screenheight-30 )
endif
if users <> 0
SetSpritePosition( users , screenwidth/2-160 , 0 )
endif
xsel = selection * 20 + 2
SetSpritePosition( selections , screenwidth/2-160+xsel , screenheight-28 )
xsel = viewroom * 20 + 2
SetSpritePosition( viewrooms , screenwidth/2-160+xsel , 2 )
for a = 1 to maxclients
// viewroom
xsel = (a-1) * 20
if connections[a] = 0
SetSpriteColor ( connectionss[a] , 255 , 255 , 255 , 128 )
SetSpritePosition( connectionss[a] , screenwidth/2-160+xsel+5 , 5 )
elseif a = clientnumber+1
SetSpriteColor ( connectionss[a] , 0 , 255 , 0 , 128 )
SetSpritePosition( connectionss[a] , screenwidth/2-160+xsel+5 , 5 )
elseif connections[a] > 0
SetSpriteColor ( connectionss[a] , 255 , 255 , 0 , 128 )
SetSpritePosition( connectionss[a] , screenwidth/2-160+xsel+5 , 5 )
else
//
SetSpriteColor ( connectionss[a] , 255 , 255 ,255 ,128 )
SetSpritePosition( connectionss[a] , screenwidth/2-160+xsel+5 , 5 )
endif
next a
thisFrame# = Timer ( )
difference# = thisFrame# - lastFrame#
if ( GetPointerReleased ( ) = 1 )
//oldx# = GetPointerX ( )
//oldy# = GetPointerY ( )
mx# = GetPointerX ( )
my# = GetPointerY ( )
if my# > screenheight-30
st = mx# - (screenwidth/2-160)
if st / 20 = 14
//ignore.
else
selection = st / 20
if selection = 15
// clear everything
for a = 1 to maxlines
spritecolor[a+ (curroom*maxlines),1] = -1
spritexya[a+ (curroom*maxlines), 1 ] = -1
spritexya[a+ (curroom*maxlines), 2 ] = -1
spritexyb[a+ (curroom*maxlines), 1 ] = -1
spritexyb[a+ (curroom*maxlines), 2 ] = -1
SetSpritePosition( spritelines[a+ (curroom*maxlines)] , 1000 , 1000 )
next a
recordindex = 1
oldx# = -1
oldy# = -1
x# = -1
y# = -1
selection = 1
flushtimer = 0
sentline((curroom*maxlines)+1,0 , 0 , 0 , 0 , -1, -1, -1 , 2)
endif
endif
elseif my# < 20
st = mx# - (screenwidth/2-160)
if st / 20 = 14
//ignore.
else
viewroom = st / 20
if viewroom >= maxdrawers
viewroom = maxdrawers-1
endif
endif
endif
endif
if difference# > recordspeed#
lastFrame# = thisFrame#
if ( curroom < maxdrawers and GetPointerState ( ) = 1 and GetPointerY ( ) < screenheight-28 and GetPointerY ( ) > 18 )
oldx# = x#
oldy# = y#
x# = GetPointerX ( ) / screengrid#
y# = GetPointerY ( ) / screengrid#
x# = Trunc(x#)
y# = Trunc(y#)
if oldx# = x# and oldy# = y#
// no need to record.
else
if oldx# > 0 and oldy# > 0
spritexya[ recordindex + (curroom*maxlines), 1 ] = x# * screengrid#
spritexya[ recordindex + (curroom*maxlines) , 2 ] = y# * screengrid#
spritexyb[ recordindex + (curroom*maxlines) , 1 ] = oldx# * screengrid#
spritexyb[ recordindex + (curroom*maxlines), 2 ] = oldy# * screengrid#
if selection = 0
spritecolor[recordindex+ (curroom*maxlines),1] = 255
spritecolor[recordindex+ (curroom*maxlines),2] = 0
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 1
spritecolor[recordindex+ (curroom*maxlines),1] = 0
spritecolor[recordindex+ (curroom*maxlines),2] = 0
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 2
spritecolor[recordindex+ (curroom*maxlines),1] = 255
spritecolor[recordindex+ (curroom*maxlines),2] = 255
spritecolor[recordindex+ (curroom*maxlines),3] = 255
elseif selection = 3
spritecolor[recordindex+ (curroom*maxlines),1] = 0
spritecolor[recordindex+ (curroom*maxlines),2] = 255
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 4
spritecolor[recordindex+ (curroom*maxlines),1] = 0
spritecolor[recordindex+ (curroom*maxlines),2] = 0
spritecolor[recordindex+ (curroom*maxlines),3] = 255
elseif selection = 5
spritecolor[recordindex+ (curroom*maxlines),1] = 128
spritecolor[recordindex+ (curroom*maxlines),2] = 0
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 6
spritecolor[recordindex+ (curroom*maxlines),1] = 64
spritecolor[recordindex+ (curroom*maxlines),2] = 64
spritecolor[recordindex+ (curroom*maxlines),3] = 64
elseif selection = 7
spritecolor[recordindex+ (curroom*maxlines),1] = 128
spritecolor[recordindex+ (curroom*maxlines),2] = 128
spritecolor[recordindex+ (curroom*maxlines),3] = 128
elseif selection = 8
spritecolor[recordindex+ (curroom*maxlines),1] = 0
spritecolor[recordindex+ (curroom*maxlines),2] = 128
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 9
spritecolor[recordindex+ (curroom*maxlines),1] = 0
spritecolor[recordindex+ (curroom*maxlines),2] = 0
spritecolor[recordindex+ (curroom*maxlines),3] = 128
elseif selection = 10
spritecolor[recordindex+ (curroom*maxlines),1] = 255
spritecolor[recordindex+ (curroom*maxlines),2] = 255
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 11
spritecolor[recordindex+ (curroom*maxlines),1] = 128
spritecolor[recordindex+ (curroom*maxlines),2] = 128
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 12
spritecolor[recordindex+ (curroom*maxlines),1] = 120
spritecolor[recordindex+ (curroom*maxlines),2] = 56
spritecolor[recordindex+ (curroom*maxlines),3] = 0
elseif selection = 13
spritecolor[recordindex+ (curroom*maxlines),1] = 198
spritecolor[recordindex+ (curroom*maxlines),2] = 88
spritecolor[recordindex+ (curroom*maxlines),3] = 0
else
spritecolor[recordindex+ (curroom*maxlines),1] = 0
spritecolor[recordindex+ (curroom*maxlines),2] = 0
spritecolor[recordindex+ (curroom*maxlines),3] = 0
endif
//sentline
line(recordindex+ (curroom*maxlines),spritexya[recordindex+ (curroom*maxlines),1] , spritexya[recordindex+ (curroom*maxlines),2] , spritexyb[recordindex+ (curroom*maxlines),1] , spritexyb[recordindex+ (curroom*maxlines),2] , spritecolor[recordindex+ (curroom*maxlines),1], spritecolor[recordindex+ (curroom*maxlines),2], spritecolor[recordindex+ (curroom*maxlines),3] , pensize)
sentline(recordindex+ (curroom*maxlines),spritexya[recordindex+ (curroom*maxlines),1] , spritexya[recordindex+ (curroom*maxlines),2] , spritexyb[recordindex+ (curroom*maxlines),1] , spritexyb[recordindex+ (curroom*maxlines),2] , spritecolor[recordindex+ (curroom*maxlines),1], spritecolor[recordindex+ (curroom*maxlines),2], spritecolor[recordindex+ (curroom*maxlines),3] , pensize)
recordindex = recordindex + 1
if recordindex >= maxlines
recordindex = 1
endif
endif
endif // oldx = x
else
// released set new start.
oldx# = -1
oldy# = -1
x# = -1
y# = -1
endif
endif
//print( Str(clientnumber) )
//print ( ScreenFPS() )
//print(str(viewroom))
//print ( recordindex )
// Print("INetID:" + Str(INetID))
// print( "GetNetworkNumClients(iNetID) : " + str(GetNetworkNumClients(iNetID)) )
// print ("GetNetworkMyClientID( iNetID ) :" +str(GetNetworkMyClientID( iNetID )) )
print("")
print("")
print( " " + lmsg$ )
drawlines()
drawlines_otherrooms()
flushsentbuffer() // check if we need net flush.
Sync( )
loop
// buffer sentline to avoid, packets get added to each other.
// slow upload, fast server sending ( packets dont flush but is added. )
function flushsentbuffer()
if curbuf = 1
// nothing todo (yet)
else
if curbuf >= maxbuf or ( Timer() - flushtimer ) > 1
// sent every 2 sec. To make sure packets are not appended on TCP.
flushtimer = Timer()
ServerID = GetNetworkServerID(iNetID)
newMsg = CreateNetworkMessage()
AddNetworkMessageInteger(newMsg, curbuf ) // set number of buffered entrys.
for a = 1 to curbuf
AddNetworkMessageInteger(newMsg, netbuffer[a,1] ) // client.
AddNetworkMessageInteger(newMsg, netbuffer[a,2] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,3] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,4] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,5] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,6] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,7] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,8] ) // line
AddNetworkMessageInteger(newMsg, netbuffer[a,9] ) // line
next a
SendNetworkMessage(iNetID, ServerID, newMsg)
DeleteNetworkMessage(newMsg)
curbuf = 1
endif
endif
endfunction
function sentline( l, x, y, xx, yy , r , g , b , s)
flushsentbuffer()
if curbuf < maxbuf and x >= 0 and y >= 0 and xx >= 0 and yy >= 0
netbuffer[curbuf,1] = clientnumber
netbuffer[curbuf,2] = l
netbuffer[curbuf,3] = x
netbuffer[curbuf,4] = y
netbuffer[curbuf,5] = xx
netbuffer[curbuf,6] = yy
netbuffer[curbuf,7] = r
netbuffer[curbuf,8] = g
netbuffer[curbuf,9] = b
curbuf = curbuf + 1
endif
endfunction l
function sentconnected(l)
ServerID = GetNetworkServerID(iNetID)
newMsg = CreateNetworkMessage()
AddNetworkMessageInteger(newMsg, 99) // client.
AddNetworkMessageInteger(newMsg, clientnumber+1) // line
SendNetworkMessage(iNetID, ServerID, newMsg)
//DeleteNetworkMessage(newMsg)
endfunction l
function setuplines()
for room = 0 to maxdrawers-1
for a = 1 to maxlines
spritelines[a+(room*maxlines)] = createSprite ( 0 )
setSpriteSize ( spritelines[a+(room*maxlines)] , pensize, pensize )
SetSpriteColor ( spritelines[a+(room*maxlines)] , 255 , 255 , 255 , 255 )
SetSpritePosition( spritelines[a+(room*maxlines)] , 1000 , 1000 )
setSpriteAngle ( spritelines[a+(room*maxlines)] , 0 )
spritecolor[a+(room*maxlines),1] = -1
SetSpritePhysicsOff ( spritelines[a+(room*maxlines)] )
next a
next room
endfunction
function drawlines()
for a = 1 to maxlines-1
if spritecolor[a+(viewroom*maxlines),1] >= 0
line(a+(viewroom*maxlines),spritexya[a+(viewroom*maxlines),1] , spritexya[a+(viewroom*maxlines),2] , spritexyb[a+(viewroom*maxlines),1] , spritexyb[a+(viewroom*maxlines),2] , spritecolor[a+(viewroom*maxlines),1], spritecolor[a+(viewroom*maxlines),2], spritecolor[a+(viewroom*maxlines),3] , pensize)
else
SetSpritePosition( spritelines[a+(viewroom*maxlines)] , 1000 , 1000 )
endif
next a
endfunction
function drawlines_otherrooms()
for room = 0 to maxdrawers-1
if room <> viewroom
ktherest = 0
for a = 1 to maxlines-1
if spritecolor[a+(room*maxlines),1] >= 0
rline(a+(room*maxlines),spritexya[a+(room*maxlines),1] , spritexya[a+(room*maxlines),2] , spritexyb[a+(room*maxlines),1] , spritexyb[a+(room*maxlines),2] , spritecolor[a+(room*maxlines),1], spritecolor[a+(room*maxlines),2], spritecolor[a+(room*maxlines),3] , pensize)
else
SetSpritePosition( spritelines[a+(room*maxlines)] , 1000 , 1000 )
endif
next a
endif
next room
endfunction
function line( l, x, y, xx, yy , r , g , b , s)
SetSpriteColor ( spritelines[l] , r , g , b , 255 )
SetSpritePosition( spritelines[l] , x , y )
dx = x-xx
dy = y-yy
di = sqrt( (dx)^2 + (dy)^2 ) // calc dist
setSpriteSize ( spritelines[l] , s, di )
SetSpriteOffset( spritelines[l] , 1 , 1 )
sngAngle = aTanFull( dx , dy )
setSpriteAngle ( spritelines[l] , sngAngle )
endfunction l
function rline( l, x, y, xx, yy , r , g , b , s)
SetSpriteColor ( spritelines[l] , r , g , b , 30 )
SetSpritePosition( spritelines[l] , x , y )
dx = x-xx
dy = y-yy
di = sqrt( (dx)^2 + (dy)^2 ) // calc dist
setSpriteSize ( spritelines[l] , s, di )
SetSpriteOffset( spritelines[l] , 1 , 1 )
sngAngle = aTanFull( dx , dy )
setSpriteAngle ( spritelines[l] , sngAngle )
setSpriteDepth( spritelines[l], 10000)
endfunction l
function getclientnumber()
ServerID = GetNetworkServerID(iNetID)
msg = CreateNetworkMessage()
AddNetworkMessageString(msg, "CN:") // 11 = get a image from the internet.
SendNetworkMessage(iNetID, ServerID, msg)
for a = 1 to 4
sync()
next a
//DeleteNetworkMessage(msg)
reply$ = getreply()
endfunction reply$
function checkfiles(filename$)
ServerID = GetNetworkServerID(iNetID)
msg = CreateNetworkMessage()
AddNetworkMessageString(msg, "FT:"+filename$+" ") // 11 = get a image from the internet.
SendNetworkMessage(iNetID, ServerID, msg)
for a = 1 to 4
sync()
next a
//DeleteNetworkMessage(msg)
tmp$ = getreply()
if Val(tmp$) > 0
// recieve file.
flength = Val(tmp$)
tmp$ = getdata(Val(tmp$))
if tmp$ = "ok"
//lmsg$ = "filok:"
//save file.
fileid = OpenToWrite ( filename$+".png", 0 )
for a = 1 to flength/4+1
WriteInteger( fileid, download[a] )
next a
CloseFile ( fileid )
else
//file failed.
lmsg$ = "file failed. found 0 length:"
endif
else
lmsg$ = "file not found 0 length:"
endif
endfunction
function getdata(length)
gotb = 1
rest = length/4
current = 0
delayer = 0
for a = 0 to 2000
delayer = 0
msg = GetNetworkMessage(iNetID)
if msg > 0
mClientID = GetNetworkMessageFromClient(msg)
delayer = 1
if mClientID > 0
current = 1
while current < 64 and gotb-1 <= rest
download[gotb] = GetNetworkMessageInteger(msg)
gotb = gotb + 1
current = current + 1
endwhile
endif
DeleteNetworkMessage(msg)
endif
if gotb >= rest
reply$ = "ok"
exit
endif
if delayer = 0
sync()
endif
next a
if a >= 2000
reply$ = ""
else
reply$ = "ok"
endif
endfunction reply$
function getreply()
for a = 0 to 500
msg = GetNetworkMessage(iNetID)
if msg > 0
mClientID = GetNetworkMessageFromClient(msg)
if mClientID > 0
reply$ = GetNetworkMessageString(msg)
DeleteNetworkMessage(msg)
exit
endif
DeleteNetworkMessage(msg)
endif
sync()
next a
endfunction reply$
function getorintation()
if ( orientation <> GetOrientation ( ) )
orientation = GetOrientation ( )
if ( orientation = 1 or orientation = 2 )
SetVirtualResolution ( 320, 480 ) // 320,480
screenwidth = 320
screenheight = 480
else
SetVirtualResolution ( 480, 320 ) // 320,480
screenwidth = 480
screenheight = 320
endif
endif
endfunction