GLBasic forum

Other languages => GLBasic - de => Topic started by: S. P. Gardebiter on 2008-Nov-15

Title: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-15
Mein Spiel hängt wie sau im Netzwerkmodus :o
Könnte mir bitte einer erklären wieso?
Danke! =D

Code (glbasic) Select
// --------------------------------- //
// Project: GTD
// Start: Sunday, November 09, 2008
// IDE Version: 6.034

SETSCREEN 640, 480, 0
LIMITFPS 60
SYSTEMPOINTER FALSE

LOADSPRITE "Ship01.png", 1
LOADSPRITE "Ship02.png", 2
LOADSPRITE "Light.png", 50
LOADSPRITE "Back01G.png", 100
LOADSPRITE "Brick01B.png", 400
DebugM = 0
Count = 0
CountX = 0
CountY = 0
CountZ = 0
FrameCounter = 0
Init = 0

PI = 3.1415926535

TotalPlayer = 0
CurPlayer = 0

DIM PlayerType[256] // 0 = Unused; 1 = Spectator; 2 = LPlayer1 (Team 0); 3 = LPlayer1 (Team 1)
DIM PlayerShip[256]
DIM PlayerX[256]
DIM PlayerY[256]
DIM PlayerXMove[256]
DIM PlayerYMove[256]
DIM PlayerDir[256]
DIM PlayerMaxHealth[256]
DIM PlayerHealth[256]
DIM PlayerMaxEnergy[256]
DIM PlayerEnergy[256]
DIM PlayerLight[256]
DIM PlayerLightSize[256]
DIM PlayerLightRange[256]
DIM PlayerMainWep[256]
DIM PlayerSubWep[256]
DIM PlayerSpeed[256]
DIM PlayerTurnSpeed[256]
DIM PlayerMisc[256] // 12345678; 1&5 = Stealth; 2&6 = Scanner; 3&7 = UltraStealth; 4&8 = Light
DIM PlayerID$[256]
DIM PlayerName$[256]

DIM PlayerMiscCounter1[256]
DIM PlayerMiscCounter2[256]
DIM PlayerDeathCounter[256]
DIM PlayerDeathCounterStep[256]

BackgroundType = 1
BackgroundNumber = 0

DIM Messages$[8]
DIM MessageAdd$[256]
MessageCounter = 0

DIM BulletType[8192]
DIM BulletSubType[8192]
DIM BulletX[8192]
DIM BulletY[8192]
DIM BulletXMove[8192]
DIM BulletYMove[8192]
DIM BulletAnim[8192]
DIM BulletSpeed[8192]
DIM BulletMove[8192]
DIM BulletDirection[8192]

DIM BlockType[8192]
DIM BlockX[8192]
DIM BlockY[8192]

FOR CountY = 0 TO 1
FOR CountX = 0 TO 8 + CountY * 4
BlockType[CountX*CountY+1] = 400
BlockX[CountX*CountY+1] = CountX*64
BlockY[CountX*CountY+1] = CountY*64
NEXT
NEXT

TotalBase = 1
DIM BaseTeam[32]
DIM BaseHealth[32]
DIM BaseX[32]
DIM BaseY[32]

MainBaseHealthInit = 5000
DIM MainBaseHealth[2]
DIM MainBaseX[2]
DIM MainBaseY[2]

DIM Sinus[360]
DIM CoSinus[360]

FOR Count = 0 TO 359
Sinus[Count] = SIN(Count)
CoSinus[Count] = COS(Count)
NEXT

GameMode = 0
ID$ = ""
IDNum = 0
IP$ = ""
Name$ = ""
NetCount = 250

PRINT "1: Local Game", 16, 16
PRINT "2: Join Game", 16, 32
PRINT "3: Host Game", 16, 48
SHOWSCREEN

WHILE TRUE

IF KEY(2) THEN GameMode = 1

IF KEY(3) THEN GameMode = 2

IF KEY(4) THEN GameMode = 3

IF GameMode > 0 THEN BREAK

WEND

IF GameMode = 2
PRINT "Enter IP Adress:", 16, 16
INPUT IP$, 16, 32
PRINT "Enter your name:", 16, 48
INPUT Name$, 16, 64
IF NETJOINGAME(0, "GTDGame", IP$, "26000")
ID$ = NETCREATEPLAYER$(Name$)
ELSE
PRINT "Error!", 64, 64
SHOWSCREEN
KEYWAIT
END
ENDIF
ENDIF

IF GameMode = 3
PRINT "Enter your name:", 16, 48
INPUT Name$, 16, 64
IF NETHOSTGAME(0, "GTDGame", "", "26000")
ID$ = NETCREATEPLAYER$(Name$)
ELSE
PRINT "Error!", 64, 64
SHOWSCREEN
KEYWAIT
END
ENDIF
ENDIF

WHILE TRUE

IF KEY(1) THEN BREAK

IF NetCount = 250
IF GameMode > 1
IF TotalPlayer <> NETNUMPLAYERS()
TotalPlayer = NETNUMPLAYERS()
FOR Count = 0 TO TotalPlayer-1
PlayerID$[Count] = NETGETPLAYERID$(Count)
PlayerName$[Count] = NETPLAYERNAME$(PlayerID$[Count])
NEXT
IDNum = ID$
NetCount = 0
ENDIF
ELSE
TotalPlayer = 1
ID$ = "0"
IDNum = 0
ENDIF
ELSE
INC NetCount, 1
ENDIF

GOSUB Gameflow

GOSUB Background

GOSUB Map

GOSUB Player

GOSUB Collision

GOSUB Light

IF GameMode > 1
GOSUB Network
ENDIF

GOSUB Messages

INC FrameCounter, 1

SHOWSCREEN

WEND

SUB Gameflow:

IF Init = 0
FOR Count = 0 TO 1
MainBaseHealth[Count] = MainBaseHealthInit
IF MainBaseX[Count] = 0
MainBaseX[Count] = 640/2
ENDIF
IF MainBaseY[Count] = 0
MainBaseY[Count] = 480/2
ENDIF
NEXT
ENDIF

ENDSUB

SUB Background:

ALPHAMODE 0.6

IF BackgroundType = 1
FOR CountY = 0 TO 7
FOR CountX = 0 TO 9
DRAWSPRITE 100+BackgroundNumber, CountX*64, CountY*64
NEXT
NEXT
ENDIF

ENDSUB

SUB Map:

ALPHAMODE 0

FOR Count = 0 TO 8191
IF BlockType[Count] > 0
DRAWSPRITE BlockType[Count], BlockX[Count], BlockY[Count]
ENDIF
NEXT

ENDSUB

SUB Player:

IF KEY(14)
INPUT MessageAdd$[IDNum], 16, 464
MessageAdd$[IDNum] = "S. P. Gardebiter: " + MessageAdd$[IDNum]
ENDIF

IF TotalPlayer > CurPlayer
IF PlayerType[IDNum] = 0
PlayerType[IDNum] = 2
PlayerShip[IDNum] = 1
IF PlayerShip[IDNum] = 1
PlayerLight[IDNum] = 1
PlayerLightSize[IDNum] = 25
PlayerLightRange[IDNum] = 150
PlayerSpeed[IDNum] = 0.1
PlayerTurnSpeed[IDNum] = 4
ENDIF
IF PlayerShip[IDNum] = 2
PlayerLight[IDNum] = 2
PlayerLightSize[IDNum] = 35
PlayerLightRange[IDNum] = 400
PlayerSpeed[IDNum] = 0.02
PlayerTurnSpeed[IDNum] = 2
ENDIF
PlayerMisc[IDNum] = bOR(PlayerMisc[IDNum], 0x01)
INC CurPlayer, 1
ENDIF
ENDIF

FOR Count = 0 TO 255
IF PlayerType[Count] = 2 OR PlayerType[Count] = 3
IF PlayerHealth[Count] > 0

IF KEY(203)
INC PlayerDir[Count], PlayerTurnSpeed[Count]
IF PlayerDir[Count] > 359 THEN DEC PlayerDir[Count], 360
ENDIF

IF KEY(205)
DEC PlayerDir[Count], PlayerTurnSpeed[Count]
IF PlayerDir[Count] < 0 THEN INC PlayerDir[Count], 360
ENDIF

IF KEY(16)
IF bAND(PlayerMisc[Count], 0x01) = 0x01
PlayerMisc[Count] = bAND(PlayerMisc[Count], 0xFE)
ELSE
PlayerMisc[Count] = bOR(PlayerMisc[Count], 0x01)
ENDIF
ENDIF

IF KEY(200)
DEC PlayerXMove[Count], Sinus[PlayerDir[Count]] * PlayerSpeed[Count]
DEC PlayerYMove[Count], CoSinus[PlayerDir[Count]] * PlayerSpeed[Count]
ENDIF

IF KEY(208)
INC PlayerXMove[Count], Sinus[PlayerDir[Count]] * PlayerSpeed[Count]
INC PlayerYMove[Count], CoSinus[PlayerDir[Count]] * PlayerSpeed[Count]
ENDIF

INC PlayerX[Count], PlayerXMove[Count]
INC PlayerY[Count], PlayerYMove[Count]

ALPHAMODE 0

ROTOSPRITE PlayerShip[Count], PlayerX[Count], PlayerY[Count], PlayerDir[Count]
ELSE
IF PlayerDeathCounter[Count] > 4.8
PlayerHealth[Count] = 100
IF PlayerShip[Count] = 1
PlayerX[Count] = MainBaseX[PlayerType[Count]-2]+16
PlayerY[Count] = MainBaseY[PlayerType[Count]-2]+16
ELSEIF PlayerShip[Count] = 2
PlayerX[Count] = MainBaseX[PlayerType[Count]-2]+24
PlayerY[Count] = MainBaseY[PlayerType[Count]-2]+24
ENDIF
ELSE
IF PlayerDeathCounterStep[Count] <= 5
INC PlayerDeathCounterStep[Count], 1
ELSE
INC PlayerDeathCounter[Count], 0.1
ENDIF
PRINT PlayerDeathCounter[Count], 320, 240
ENDIF
ENDIF
ENDIF
NEXT

ENDSUB

SUB Collision:

ENDSUB

SUB Light:

ALPHAMODE 0.5

// STARTPOLY 50
// POLYVECTOR MainBaseX[0]-256, MainBaseX[0]+256, 0, 0, RGB(50, 50, 50)
// POLYVECTOR MainBaseX[0]+256, MainBaseX[0]+256, 31, 0, RGB(50, 50, 50)
// POLYVECTOR MainBaseX[0]+256, MainBaseX[0]-256, 31, 31, RGB(50, 50, 50)
// POLYVECTOR MainBaseX[0]-256, MainBaseX[0]-256, 0, 31, RGB(50, 50, 50)
// ENDPOLY


FOR Count = 0 TO 255
IF PlayerHealth[Count] > 0
ALPHAMODE 0.5
IF PlayerShip[Count] = 1
STARTPOLY 50
POLYVECTOR PlayerX[Count]-32, PlayerY[Count]+64, 0, 0, RGB(100, 100, 100)
POLYVECTOR PlayerX[Count]+64, PlayerY[Count]+64, 31, 0, RGB(100, 100, 100)
POLYVECTOR PlayerX[Count]+64, PlayerY[Count]-32, 31, 31, RGB(100, 100, 100)
POLYVECTOR PlayerX[Count]-32, PlayerY[Count]-32, 0, 31, RGB(100, 100, 100)
ENDPOLY
ELSEIF PlayerShip[Count] = 2
STARTPOLY 50
POLYVECTOR PlayerX[Count]-32, PlayerY[Count]+80, 0, 0, RGB(100, 100, 100)
POLYVECTOR PlayerX[Count]+80, PlayerY[Count]+80, 31, 0, RGB(100, 100, 100)
POLYVECTOR PlayerX[Count]+80, PlayerY[Count]-32, 31, 31, RGB(100, 100, 100)
POLYVECTOR PlayerX[Count]-32, PlayerY[Count]-32, 0, 31, RGB(100, 100, 100)
ENDPOLY
ENDIF
IF PlayerLight[Count] > 0
IF bAND(PlayerMisc[Count], 0x01) = 0x01
IF PlayerLight[Count] = 1
ALPHAMODE 0.75
STARTPOLY -1
POLYVECTOR PlayerX[Count]+16, PlayerY[Count]+16, 0, 0, RGB(100, 100, 100)
POLYVECTOR INTEGER(PlayerLightRange[Count] * COS((PlayerDir[Count]/-1)+PlayerLightSize[Count]-90)) + PlayerX[Count]+16, INTEGER(PlayerLightRange[Count] * SIN((PlayerDir[Count]/-1)+PlayerLightSize[Count]-90)) + PlayerY[Count]+16, 0, 0, RGB(0, 0, 0)
POLYVECTOR INTEGER(PlayerLightRange[Count] * COS((PlayerDir[Count]/-1)-PlayerLightSize[Count]-90)) + PlayerX[Count]+16, INTEGER(PlayerLightRange[Count] * SIN((PlayerDir[Count]/-1)-PlayerLightSize[Count]-90)) + PlayerY[Count]+16, 0, 0, RGB(0, 0, 0)
ENDPOLY
ENDIF
IF PlayerLight[Count] = 2
ALPHAMODE 0.5
STARTPOLY -1
POLYVECTOR PlayerX[Count]+24, PlayerY[Count]+24, 0, 0, RGB(150, 150, 200)
POLYVECTOR INTEGER(PlayerLightRange[Count] * COS((PlayerDir[Count]/-1)+PlayerLightSize[Count]-90)) + PlayerX[Count]+24, INTEGER(PlayerLightRange[Count] * SIN((PlayerDir[Count]/-1)+PlayerLightSize[Count]-90)) + PlayerY[Count]+24, 0, 0, RGB(0, 0, 0)
POLYVECTOR INTEGER(PlayerLightRange[Count] * COS((PlayerDir[Count]/-1)-PlayerLightSize[Count]-90)) + PlayerX[Count]+24, INTEGER(PlayerLightRange[Count] * SIN((PlayerDir[Count]/-1)-PlayerLightSize[Count]-90)) + PlayerY[Count]+24, 0, 0, RGB(0, 0, 0)
ENDPOLY
ENDIF
ENDIF
ENDIF
ENDIF
NEXT

ENDSUB

SUB Network:

FOR Count = 0 TO TotalPlayer-1
PRINT PlayerID$[Count], 16, 256+Count*16
PRINT PlayerName$[Count], 64, 256+Count*16
NEXT

ENDSUB

SUB Messages:

ALPHAMODE 0.75

FOR CountX = 0 TO 255
IF MessageAdd$[CountX] <> ""
FOR Count = 0 TO 7
IF Messages$[Count] = ""
Messages$[Count] = MessageAdd$[CountX]
MessageAdd$[CountX] = ""
MessageCounter = 350
BREAK
ENDIF
NEXT
IF MessageAdd$[CountX] <> ""
FOR Count = 0 TO 6
Messages$[Count] = Messages$[Count+1]
Messages$[7] = MessageAdd$[CountX]
MessageAdd$[CountX] = ""
MessageCounter = 350
NEXT
ENDIF
ENDIF
NEXT

FOR Count = 0 TO 7
IF Messages$[Count] <> ""
PRINT Messages$[Count], 16, 16*Count+16
IF MessageCounter = 0
MessageCounter = 350
ENDIF
ENDIF
NEXT

IF MessageCounter > 1
DEC MessageCounter, 1
ELSE
FOR Count = 0 TO 6
Messages$[Count] = Messages$[Count+1]
NEXT
MessageCounter = 0
ENDIF

ENDSUB
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Schranz0r on 2008-Nov-17
Boah, massig Array die Riesengroß sind  :|
Tippe mal schwer darauf, deshalb der Lagg?!
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-17
Only call NETNUMPLAYERS() as the server, when you call that as a client it will take up to 400 ms which makes your game lag
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-17
Quote from: Schranz0r on 2008-Nov-17
Boah, massig Array die Riesengroß sind  :|
Tippe mal schwer darauf, deshalb der Lagg?!

Kann nicht sein, hier wird nichts gesendet.

Quote from: Moru on 2008-Nov-17
Only call NETNUMPLAYERS() as the server, when you call that as a client it will take up to 400 ms which makes your game lag

Thank you :D

Edit: Es laggt immernoch. Ich will aber auch keine Lobby haben, ich will das die Spieler in Echtzeit joinen können. :(

It is still lagging. I don't want to have a lobby I want to let the players join whenever they decide to join the game. :(
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-17
One more thing, only call it now and then, every 2-5 seconds mabe. If you call it more often it will start to lag a little bit too :-)
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-17
Quote from: Moru on 2008-Nov-17
One more thing, only call it now and then, every 2-5 seconds mabe. If you call it more often it will start to lag a little bit too :-)

I test it every 5 secounds. I still wonder why it laggs... Is it just me?
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-17
Are you testing it both on client and server? When the server tests, it has all the data already so it goes quite fast. If you test it on client it seems to ask the server which takes a bit longer.

You need to remake the server to send the data to the clients.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-17
Quote from: Moru on 2008-Nov-17
Are you testing it both on client and server? When the server tests, it has all the data already so it goes quite fast. If you test it on client it seems to ask the server which takes a bit longer.

You need to remake the server to send the data to the clients.

I did that and it is still lagging for the server.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-18
How much is it lagging? Have you tried connecting two computers or are you running it on the same computer? Are you using AUTOPAUSE FALSE?
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-18
I tested it and it still does lag for the server (even without clients joined), there is nothing else than a test every 5 secounds. In the local game though it doesn't lag.

Ich hab es getestet und es laggt immernoch für den Server (selbst wenn noch nichtmal clients gejoint sind), es führt nichts anderes aus als einen test jede 5 Sekunden. Im Lokalen Spiel laggt es aber nicht.

Local: FPS - 60; CPU: 3%
Server/Host: FPS - 45; CPU: 0%

Seems to be something wrong with GLBasic.
Es scheint etwas nicht in Ordnung mit GLBasic zu sein.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-18
Try my Scribble download on my homepage and see if you get the same lag
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-18
Quote from: Moru on 2008-Nov-18
Try my Scribble download on my homepage and see if you get the same lag

I use V6. Is Scribble OpenSource?
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Kosta on 2008-Nov-18
Quote from: S. P. Gardebiter on 2008-Nov-18
Quote from: Moru on 2008-Nov-18
Try my Scribble download on my homepage and see if you get the same lag

I use V6. Is Scribble OpenSource?

Sourcecode liegt bei

siehe Webseite:
Download Scribble (876.17 KiB, 2008-11-03 14:19:12.) (Includes source)
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-18
404 D:
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-18
You can't download it?
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Kosta on 2008-Nov-18
Quote from: Moru on 2008-Nov-18
You can't download it?

hmm... from my side ... it's downloadable (from home and work downloaded)

but it isn't extractable (tested with winrar,winzip,7-zip)
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-18
I just uploaded latest version and have tested to download and extract with 7-zip and it works.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Kosta on 2008-Nov-18
Quote from: Moru on 2008-Nov-18
I just uploaded latest version and have tested to download and extract with 7-zip and it works.

Looks better (and have a bigger size now)

it's now extractable.  :good:
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-18
I added the source of the linked files too so should be bigger.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-18
Syntax Error.
I guess it would take no effect anyway, since it's not a game and you don't even have a build in FPS counter so I can't tell if it's lagging. :o
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-19
Eh, what does FPS have to do with lag? Lag you see if you run the two programs on the same screen and paint in one window and see that it takes 5 seconds to show up in the other window.

What line are you getting syntax error on and what version of GLBasic do you have? I'm running latest beta just fine.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Kosta on 2008-Nov-19
I think   S.P.Gardebiter means with his "Lag" -> a short (or long) time of freezing on the source (or both) clients (rather server/client) or a SlowerDown on both.
Not the time lag between both.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-19
Correct.

Like I showed you:

Quote from: S. P. Gardebiter on 2008-Nov-18Local: FPS - 60; CPU: 3%
Server/Host: FPS - 45; CPU: 0%

The FPS decrease allthough the CPU doesn't do as much as it would do in a local game.
Notice the bug?
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-19
To run network means that it uses more processor power too. I don't know how much but NETNUMPLAYERS() needs a few milliseconds at least. Not sure about the rest commands.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-19
Quote from: Moru on 2008-Nov-19
To run network means that it uses more processor power too. I don't know how much but NETNUMPLAYERS() needs a few milliseconds at least. Not sure about the rest commands.

I think you don't understand what I mean :o
It doesn't use more processor power, instead it uses less processor power allthough that's totally uneeded.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-19
I think I know what you mean. The program is running at 45 FPS while running only the netcode without grafics, the client with grafics is running at 60 FPS.

But the netcode is not using processorpower as much as it is waiting for answers and this wait also takes a few milliseconds from your code wich ends up with less FPS.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: S. P. Gardebiter on 2008-Nov-19
The server has graphics too, there is no difference to the client. But still there some to be some bugs in GLBasic's Network code.
Title: Re: Spiel laggt sehr wegen Netzwerkmodus
Post by: Moru on 2008-Nov-20
I have tried scribble with FPS-counter now and I do get a lower FPS when I run two clients on the same computer connected to eachother. But only if I set limitfps to -1. Before connecting to the server they both have 500 FPS, when connected the FPS drops to 150. without any other change.

I don't know if this is because I could only test it on the same computer. Do you have the same problem when you test it on two computers?