Spiel laggt sehr wegen Netzwerkmodus

Previous topic - Next topic

S. P. Gardebiter

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
~ Cave Story rules! ~

Schranz0r

Boah, massig Array die Riesengroß sind  :|
Tippe mal schwer darauf, deshalb der Lagg?!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Moru

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

S. P. Gardebiter

#3
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. :(
~ Cave Story rules! ~

Moru

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 :-)

S. P. Gardebiter

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?
~ Cave Story rules! ~

Moru

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.

S. P. Gardebiter

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.
~ Cave Story rules! ~

Moru

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?

S. P. Gardebiter

#9
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.
~ Cave Story rules! ~

Moru

Try my Scribble download on my homepage and see if you get the same lag

S. P. Gardebiter

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?
~ Cave Story rules! ~

Kosta

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)
Intel QuadCore, Geforce8600GT,512MB,4GB Ram, 26" TFT
HP nw8440 Schläppy
GP2X Mk2 (Firmware 3.0)

GLBASIC Blog:
http://www.glbasic.com/forum/index.php?blog=51.0

S. P. Gardebiter

~ Cave Story rules! ~

Moru