Показать сообщение отдельно
Старый 04.04.2009, 15:50   #1
ratttx
AnyKey`щик
 
Регистрация: 04.04.2009
Сообщений: 4
Написано 0 полезных сообщений
(для 0 пользователей)
Не могу понять, как оптимизировать, то, что написал....

Добрые люди! Хелп! Столкнулся с такой проблемой.....
Я пишу игрушку шутер сетевую - пока что разрабатываю сетевой коннект через UDP. При смене координат игрока - их пересылают на другой компьютер... (игрок 1 шагнул на шаг "мувЕНТИТИ ххх,0,0,1" - отсылается УДП пакет с новыми координатами игрока) НО!!!! Когда у нас добавляются боты, игроки начинают бегать - то СИНХРОНИЗАЦИЯ Между компьютерами теряется (Целая орда сетевых пакетов - во всяком случае я на это грешу...) Может кто подскажет, способ, или ошибку, почему 2 2-х ядерных компа, не могут осилить 2-х игроков и 10 ботов(запуск 1 бота русская буква "х").... Где моя логика не верна? П.С. - при запуске - может потребовать текстуры - их можно просто отключить. П.С. - игра должна получиться интересной )
Const in_port=53424
Const out_port=53425
Global Stream_1=CreateUDPStream(out_port)
Global Stream_2=CreateUDPStream(in_port)
Type PL
Field IP
Field X
Field Y
Field NAPR
Field LIVE
Field ARMOR
Field mesh
End Type

Type BOT
Field botID
Field botHOST$
Field X$
Field Y$
Field NAPR$
Field LIVE
Field ARMOR
Field mesh
End Type


Global IN1$, IN2$, IN3$, IN4$, IN5$, IN6$, IN7$, IN8$, IN9$,IN10$
Global OUT1$, OUT2$, OUT3$, OUT4$, OUT5$, OUT6$, OUT7$, OUT8$, OUT9$,OUT10$
Global op_ip$
Global bike,izm
Graphics3D 800,600,32,2
SetBuffer BackBuffer()
;iip$=Input$("1) ya. 2) mom ")
op_ip$=Input$("Konnect IP ")
myIP$=Input$("MY IP ")

;If iip= 2 Then op_ip$ ="192.168.0.2"
;If iip= 1 Then op_ip$ ="192.168.0.3"
;-----------------myIP
;If iip=1 Then myIP$ ="192.168.0.2"
;If iip=2 Then myIP$ ="192.168.0.3"
myIP$=Int_IP(myIP$)
op_ip$=Int_IP(op_ip$)
SeedRnd (MilliSecs())
;================================================= ============================
bike=CreateSphere()
ScaleMesh bike,2,2,2
PositionEntity bike,0,1,0
camera=CreateCamera(bike)
TurnEntity camera,45,0,0
PositionEntity camera,0,20,-30
PointEntity camera,bike
light=CreateLight()
TurnEntity light,45,45,0

P.PL = New PL
P\IP$ = myIP$
P\X =EntityX#(bike)
P\Y =EntityY#(bike)
P\NAPR =EntityYaw#(bike)
P\LIVE =100
P\ARMOR =0

;================================================= ============================
grid_tex=LoadTexture( "towerz.bmp" )

ScaleTexture grid_tex,10,10
grid_plane=CreatePlane()
EntityTexture grid_plane,grid_tex









;opovewau -o vxode
WriteLine Stream_1,"VXOD" ;PLAYER \ bot
WriteLine Stream_1,name$ ;PLAYER NAME \bot ID
WriteLine Stream_1,myIP$ ;PLAYER IP
WriteLine Stream_1,"OTKLIK" ;KOMANDA
WriteLine Stream_1,EntityX#(bike) ;X
WriteLine Stream_1,EntityY#(bike);Y
WriteLine Stream_1,EntityYaw#(bike) ;NAPR
WriteLine Stream_1,""
WriteLine Stream_1,""
WriteLine Stream_1,""
SendUDPMsg Stream_1,op_ip$,in_port
;============








While Not KeyHit(1)
izm=False
FPS=FPS+1
If FPStime<MilliSecs() Then
FPSsave=FPS
FPS=0
FPStime=MilliSecs()+1000
End If






Gosub BOT
Gosub OBRABin

Gosub UPR ;Ypravlenie - otsilka novix koordinat



RenderWorld
Text 1,1, "x1= "+IN1$
Text 10,10, "x2 "+IN2$
Text 10,20, "x3= "+IN3$
Text 10,30, "x4= "+IN4$
Text 10,40, "x5= "+IN5$
Text 10,50, "x6= "+IN6$
Text 10,60, "x7= "+IN7$
Text 10,70, "x8= "+IN8$
Text 10,80, "x9= "+IN9$
Text 10,90, "x10= "+IN10$
Text 10,100, "fps= "+ FPSsave
Text 10,110, "myIP= "+ myIP$
Text 10,120, "B\x= "+tttt
Text 10,130, "b\y= "+tttt2
Text 10,140, "b\yaw= "+tttt3
Text 10,150, "bot max= "+BOTmax


Flip
Wend
;----------------------------------------------
.UPR
izm=False
If KeyDown(30) Then
TurnEntity bike,0,1,0 ;levo
izm =True
End If
If KeyDown(32) Then
TurnEntity bike,0,-1,0 ;pravo
izm =True
End If
If KeyDown(17) Then
MoveEntity bike,0,0,1 ;pered
izm =True
End If
If KeyDown(31) Then
MoveEntity bike,0,0,-1 ;zad
izm =True
End If
If KeyHit(26)And BOTmax<400 Then BOTmax=BOTmax+1


If izm=True
WriteLine Stream_1,"PLAYER" ;PLAYER \ bot
WriteLine Stream_1," " ;PLAYER NAME \bot ID
WriteLine Stream_1,myIP$ ;PLAYER IP
WriteLine Stream_1,"KOORDINATI" ;KOMANDA
WriteLine Stream_1,EntityX#(bike) ;X
WriteLine Stream_1,EntityZ#(bike) ;Y
WriteLine Stream_1,EntityYaw#(bike) ;NAPR
WriteLine Stream_1," "
WriteLine Stream_1," "
WriteLine Stream_1," "
For P.PL = Each PL
If P\IP$ <>myIP$ Then SendUDPMsg Stream_1,P\IP$,in_port
Next
End If

Return

;---------------------------------------------
.OBRABin
IN1$="" IN2$="" IN3$="" IN4$="" IN5$="" IN6$="" IN7$="" IN8$="" IN9$="" IN10$=""
If RecvUDPMsg(Stream_2) Then
IN1$=ReadLine$(Stream_2) ;PLAYER \ bot
IN2$=ReadLine$(Stream_2) ;PLAYER NAME \bot ID
IN3$=ReadLine$(Stream_2) ;PLAYER IP
IN4$=ReadLine$(Stream_2) ;KOMANDA
IN5$=ReadLine$(Stream_2) ;X
IN6$=ReadLine$(Stream_2) ;Y
IN7$=ReadLine$(Stream_2) ;NAPR
IN8$=ReadLine$(Stream_2)
IN9$=ReadLine$(Stream_2)
IN10$=ReadLine$(Stream_2)
EndIf

If IN1$="VXOD" Then
;proverka na est' li takou' pleer?
For P.PL = Each PL
If P\IP$ =IN3$ Then Return
Next

P.PL = New PL
P\IP$ = IN3$
P\X =Float(IN5$)
P\Y =Float(IN6$)
P\NAPR =Float(IN7$)
P\LIVE =100
P\ARMOR =0
P\mesh=CreateCube()
ScaleMesh P\mesh,2,2,2
PositionEntity P\mesh,Float(IN5$),Float(IN6$),0


;-
WriteLine Stream_1,"VXOD" ;PLAYER \ bot
WriteLine Stream_1,name$ ;PLAYER NAME \bot ID
WriteLine Stream_1,myIP$ ;PLAYER IP
WriteLine Stream_1,"OTKLIK" ;KOMANDA
WriteLine Stream_1,EntityX#(bike) ;X
WriteLine Stream_1,EntityY#(bike) ;Y
WriteLine Stream_1,EntityYaw#(bike) ;NAPR
WriteLine Stream_1,""
WriteLine Stream_1,""
WriteLine Stream_1,""
SendUDPMsg Stream_1,IN3$,in_port
;-
WriteLine Stream_1,IN1$ ;PLAYER \ bot
WriteLine Stream_1,IN2$ ;PLAYER NAME \bot ID
WriteLine Stream_1,IN3$ ;PLAYER IP
WriteLine Stream_1,IN4$ ;KOMANDA
WriteLine Stream_1,IN5$ ;X
WriteLine Stream_1,IN6$ ;Y
WriteLine Stream_1,IN7$ ;NAPR
WriteLine Stream_1,IN8$
WriteLine Stream_1,IN9$
WriteLine Stream_1,IN10$
For P.PL = Each PL
If (P\IP$ <>myIP$) And (P\IP$<>IN3$) Then SendUDPMsg Stream_1,P\IP$,in_port
Next


End If

If (IN1$="PLAYER") And (IN4$="KOORDINATI") Then
For P.PL = Each PL
If IN3$=P\IP$ Then
P\X=Float(IN5$)
P\Y= Float(IN6$)
P\NAPR=Float(IN7$)
PositionEntity P\mesh,Float(IN5$),0,Float(IN6$),0
RotateEntity P\mesh,0,Float(IN7$),0
EndIf

Next
End If


If (IN1$="BOT") And (IN4$="BOT KOORD") Then
flag=False
For B.BOT = Each BOT ;esli bot suw'estvyet - prinimaem novie koordinati
If IN2$=B\botID$ Then
B\X=Float(IN5$)
B\Y= Float(IN6$)
B\NAPR=Float(IN7$)
PositionEntity B\mesh,B\X,0,B\Y,0
RotateEntity B\mesh,0,B\NAPR,0
flag=True
EndIf
Next

If flag=False Then ;esli takogo imeni bota net - sozdaem ego
B.BOT = New BOT
B\botID$ = IN2$
B\botHOST=IN3$
B\mesh =CreateCube()
;grid_tex=LoadTexture( "heightmap.BMP" )
;ScaleTexture grid_tex,10,10
;EntityTexture B\mesh,grid_tex
EntityColor B\mesh,Rnd(250),Rnd(250),Rnd(250)
B\X =Float(IN5$)
B\Y =Float(IN6$)
B\NAPR =Float(IN7$)
B\LIVE =100
B\ARMOR =0
botNUM=botNUM+1
PositionEntity B\mesh,Float(IN5$),Float(IN6$),0,0
RotateEntity B\mesh,0,Float(IN7$),0
End If



End If




Return
;------------------------------------------------------------
.BOT
;sizdau bota
If botNUM<BOTmax Then
B.BOT = New BOT
B\botID$ = Rnd(30000)
B\botHOST$="MY"
B\mesh =CreateCube()
grid_tex=LoadTexture( "heightmap.BMP" )
ScaleTexture grid_tex,10,10
EntityTexture B\mesh,grid_tex
B\X =EntityX#(B\mesh)
B\Y =EntityY#(B\mesh)
B\NAPR =EntityYaw#(B\mesh)
B\LIVE =100
B\ARMOR =0
botNUM=botNUM+1
End If

If botNUM>0 Then
For B.BOT = Each BOT


If B\botHOST="MY" Then

MoveEntity B\mesh,0,0,0.5
TurnEntity B\mesh,0,Rnd(-40,40),0
B\X$ =EntityX(B\mesh)
B\Y$ =EntityY(B\mesh)
B\NAPR$ =EntityYaw(B\mesh)
tttt=EntityX(B\mesh)
tttt2 =EntityZ(B\mesh)
tttt3 =EntityYaw(B\mesh)

WriteLine Stream_1,"BOT" ;PLAYER \ bot
WriteLine Stream_1,B\botID$ ;PLAYER NAME \bot ID
WriteLine Stream_1,myIP$ ;PLAYER IP
WriteLine Stream_1,"BOT KOORD" ;KOMANDA
WriteLine Stream_1,EntityX(B\mesh) ;X
WriteLine Stream_1,EntityZ(B\mesh) ;Y
WriteLine Stream_1,EntityYaw(B\mesh) ;NAPR
WriteLine Stream_1," "
WriteLine Stream_1," "
WriteLine Stream_1," "
For P.PL = Each PL
If (P\IP$ <>myIP$) Then SendUDPMsg Stream_1,P\IP$,in_port
Next
End If
Next

End If

Return
;---------------------------
;.OBRABout
;If izm=True
; WriteLine Stream_1,OUT1$ ;PLAYER \ bot
; WriteLine Stream_1,OUT2$ ;PLAYER NAME \bot ID
; WriteLine Stream_1,OUT3$ ;PLAYER IP
; WriteLine Stream_1,OUT4$ ;KOMANDA
; WriteLine Stream_1,OUT5$ ;X
; WriteLine Stream_1,OUT6$ ;Y
; WriteLine Stream_1,OUT7$ ;NAPR
; WriteLine Stream_1,OUT8$
; WriteLine Stream_1,OUT9$
; WriteLine Stream_1,OUT10$
; SendUDPMsg Stream_1,op_ip$,in_port
; End If

Return



Function Int_IP(IP$)
d1%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d2%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d3%=Left(IP$,Instr(IP$,".")-1):IP$=Right(IP$,Len(IP$)-Instr(IP$,"."))
d4%=IP$
Return (d1 Shl 24) + (d2 Shl 16) + (d3 Shl 8 ) +d4
End Function


End
(Offline)
 
Ответить с цитированием