This code runs very slow on my network. It has fine frames per second on both computers, but it takes about two minutes to register what happened on one computer on the other.
Does anybody know why it is so slow?
How can I make it faster?
StartNetGame()
name=Input("Name:")
id=CreateNetPlayer(name)
Graphics3D 640,480
SetBuffer BackBuffer()
target=LoadImage("target.bmp")
light=CreateLight()
ground=LoadTerrain("ground.bmp")
ScaleEntity ground,2,50,2
PositionEntity ground,-256,-75,-256
groundtex=LoadTexture("groundtex.bmp")
ScaleTexture groundtex,10,10
EntityTexture ground,groundtex
EntityType ground,2
guy=CreateCube()
PositionEntity guy,100,0,100
ScaleEntity guy,1,2,1
EntityRadius guy,1,4
EntityType guy,1
camera=CreateCamera(guy)
PositionEntity camera,EntityX(guy),EntityY(guy)+.5,EntityZ(guy)-1,1
PointEntity camera,guy
CameraClsColor camera,0,100,255
gravity#=0
health=100
otherguy=CreateCube()
Type youbullet
Field mesh
Field time
End Type
Collisions 1,2,2,2
Collisions 3,2,2,1
Collisions 3,6,1,1
Collisions 5,1,1,1
MoveMouse 200,200
While Not KeyDown(1)
mxs#=MouseXSpeed()
mys#=MouseYSpeed()
MoveMouse 200,200
TurnEntity guy,0,-mxs,0
TurnEntity camera,mys,0,0
If EntityCollided(guy,2)
gravity=-.2
If KeyDown(17) Then MoveEntity guy,0,0,.5
If KeyDown(31) Then MoveEntity guy,0,0,-.5
If KeyDown(32) Then MoveEntity guy,.5,0,0
If KeyDown(30) Then MoveEntity guy,-.5,0,0
TranslateEntity guy,0,gravity,0
Else
gravity=gravity+(-1-gravity)/50
TranslateEntity guy,0,gravity,0
EndIf
If MouseHit(1)
b.youbullet=New youbullet
b\mesh=CreateSphere()
ScaleMesh b\mesh,.1,.1,.1
b\time=300
PositionEntity b\mesh,EntityX(camera,1),EntityY(camera,1),EntityZ(camera,1),1
RotateEntity b\mesh,EntityPitch(camera,1),EntityYaw(camera,1),EntityRoll(camera,1),1
EntityType b\mesh,3
EntityRadius b\mesh,.1
EndIf
For b.youbullet=Each youbullet
MoveEntity b\mesh,0,0,1
TranslateEntity b\mesh,0,-.01,0
If EntityCollided(b\mesh,2) Then b\time=0
b\time=b\time-1
If b\time<0
FreeEntity b\mesh
Delete b
EndIf
Next
sendx$=LSet(EntityX(guy),10)
sendy$=LSet(EntityY(guy),10)
sendz$=LSet(EntityZ(guy),10)
sendpi$=LSet(EntityPitch(guy),10)
sendya$=LSet(EntityYaw(guy),10)
sendro$=LSet(EntityRoll(guy),10)
SendNetMsg(1,sendx+sendy+sendz+sendpi+sendya+sendro,id,0,0)
If RecvNetMsg()
msg$=NetMsgData()
PositionEntity otherguy,Left(msg,10),Mid(msg,11,20),Mid(msg,21,40)
RotateEntity otherguy,Mid(msg,31,10),Mid(msg,41,10),Right(msg,10)
EndIf
If health<0 Then CameraClsColor camera,255,0,0
UpdateWorld
RenderWorld
Text 0,0,health
DrawImage target,(GraphicsWidth()/2)-32,(GraphicsHeight()/2)-32
Flip
Wend
End