UDP für Netzwerkspiele?
Übersicht

![]() |
NoobodyBetreff: UDP für Netzwerkspiele? |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo, ich bins wieder mit ner Netzwerkfrage.
Ich habe ein kleines Beat 'em up-Spiel erstellt im Stil von Little Fighter (kennt ihr vielleicht). Nur bin ich jetzt auf ein Problem gestossen, als ich es netzwerkfähig machen wollte. Für ein Actionspiel nimmt man ja normalerweise UDP, weil das schneller ist - mit dem Risiko, dass Nachrichten verlorengehen. Also Hostet einer am Anfang ein Game, gibt seine IP an seine Freunde weiter und die joinen dann. Soweit sogut. Nur hab ich jetzt ein Problem für den Spielablauf. Ich hab mir das so gedacht, dass das Programm alle 5 frames eine Nachricht an die anderen sendet (bei 10 fps) mit x,y, Geschwindigkeit und das Frame der Spieleranimation, und das nur, wenn sich was ändert. Aber ich hab einfach keine Idee, wie ich die Nachrichtenabfrage gestalten will. Zum ersten, wenn einige PCs schneller sind als die anderen, dann sendet er mehr Nachrichten, was bei den anderen zum Stau führt. Zum zweiten, wie ich feststellen will, von wem welche Nachricht kommt. Ich habe jetzt schon zwei Wochen über dem Problem gebrütet und wollte jetzt mal die Pros hier fragen, wie man das lösen könnte^^ Greetz Noobody |
||
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun |
![]() |
Tankbuster |
![]() Antworten mit Zitat ![]() |
---|---|---|
Zitat: Zum ersten, wenn einige PCs schneller sind als die anderen, dann sendet er mehr Nachrichten, was bei den anderen zum Stau führt.
Du könntest das ganze Frameunabhängig machen ![]() Zitat: Zum zweiten, wie ich feststellen will, von wem welche Nachricht kommt.
Sobald die Leutz deinem Spiel beitreten, gibts du (der host) ihnen eine Nummer! Dann schicken die in ihrer Nachricht immer ihre Nummer mit, und du weißt, von wem die Nachricht kommt ![]() PS: Little Fighter rockt!! würd das game gern mal testen |
||
Twitter
Download Jewel Snake! Windows|Android |
![]() |
Noobody |
![]() Antworten mit Zitat ![]() |
---|---|---|
Zitat: Du könntest das ganze Frameunabhängig machen
Also z.B. all halbe Sekunde eine Nachricht schicken (indem es die absolute Zeit des PCs misst)? Das wäre tatsächlich eine gute Idee. thx ![]() Zitat: Sobald die Leutz deinem Spiel beitreten, gibts du (der host) ihnen eine Nummer! Dann schicken die in ihrer Nachricht immer ihre Nummer mit, und du weißt, von wem die Nachricht kommt
Na klar! Wieso bin ich nicht selbst drauf gekommen ![]() Zitat: PS: Little Fighter rockt!!
würd das game gern mal testen Also es ist noch weit von der Fertigstellung entfernt^^. Ich hab einfach die Grafiken vom Template genommen und mit dem gearbeitet. Bis jetzt gibt es nur ne billige Strasse, auf der er Laufen, Rennen, Schlagen und in alle Richtungen springen kann. D.h. keine KI, keine Spezialattacken und keine Lebensanzeige (aber arbeite auch erst seit nem Monat dran)^^. Ich hab mir überlegt, dass es viel gescheiter wäre, für jeden Charakter eine eigene externe Datei zu schreiben mit den ganzen Animationsangaben, aber soviel ich weiss, liest BB nur C++ bei externen Dateien, oder irre ich mich? Andere Möglichkeit wäre natürlich einfach TXT-Dateien zu schreiben und dann mit Read... das Zeugs auszulesen, was bei LF glaub ich auch so gemacht wurde. |
||
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun |
- Zuletzt bearbeitet von Noobody am So, Mai 13, 2007 15:13, insgesamt einmal bearbeitet
![]() |
ZaP |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich habe vor geraumer zeit ein Netzwerk Testprogramm erstellt, vielleicht hilft dir das weiter...
hier der Code: [AUSKLAPPEN] Graphics 640,480,32,2 hosting = 0 ;host status; 0=Spiel läuft nicht; 1=Host 2=Client ;------------------------------- Global stream = 0 Global client_port = 29071 ;Ihr solltet 29070 und 29071 öffnen, ichb in mir aber nicht sicher ob das notwendig ist. Global host_port = 29070 Global serverIP$ = 0 Global curY = 0 Global maxlines = 32 ;------------------------------- Text 0,0,"Press H to Host or J to Join a game." Repeat ;menü If KeyHit(36) ;J gedrückt (join) hosting = 2 serverIP$ = Input("Server IP: ") stream = CreateUDPStream(client_port) WriteByte(stream,1) ;Im Here! an Host senden SendUDPMsg(stream, intIP(serverIP$), host_port) EndIf If KeyHit(35) ;H gedrückt (Host) stream = CreateUDPStream(host_port) hosting = 1 EndIf If Not hosting = 0 Goto ingame EndIf Until KeyHit(1) .ingame Graphics3D 640,480,32,2 SetBuffer BackBuffer() groundtexture = LoadTexture("tex/1.jpg") ground = CreatePlane() EntityTexture ground, groundtexture Type players Field x#,y#,z#,yaw#,pitch# Field mesh Field ip End Type Type infotext Field y Field txt$ Field deleted End Type Global Host If hosting = 1 Host = CreateCube() EntityColor Host,255,0,0 EntityBox Host,0,0,0,1,1,1 PositionEntity Host,0,0,10 drawinfo("you are the host.") EndIf Global camera = CreateCamera() PositionEntity camera,0,5,0 Global me If hosting = 2 me = CreateCube() EntityColor me,0,255,0 PositionEntity me,0,0,10 drawinfo("you are a client.") EndIf If Not stream = 0 drawinfo("ingame.") drawinfo("hosting: "+hosting) Else Text 0,0,"stream could not be created." EndIf ;================================= Repeat UpdateWorld RenderWorld If hosting = 1 PointEntity camera, Host updatehost() Else PointEntity camera, me updateme() EndIf updateqbes() For t.infotext = Each infotext If t\deleted = 0 Text 0,t\y,t\txt$ EndIf Next For p.players = Each players Text 0, Rnd(480), p\ip Next If KeyHit(36) drawinfo("text...") EndIf Flip Until KeyHit(1) ;================================= CloseUDPStream(stream) End Function updatehost() If KeyDown(200) PositionEntity Host,EntityX(Host),0,EntityZ(Host)+0.1 EndIf If KeyDown(208) PositionEntity Host,EntityX(Host),0,EntityZ(Host)-0.1 EndIf If KeyDown(203) PositionEntity Host,EntityX(Host)+0.1,0,EntityZ(Host) EndIf If KeyDown(205) PositionEntity Host,EntityX(Host)-0.1,0,EntityZ(Host) EndIf If RecvUDPMsg(stream) msgtype = ReadByte(stream) msgFrom = UDPMsgIP(stream) Select(msgtype) Case 1 p.players = New players p\mesh = CopyEntity(Host) EntityColor p\mesh,0,255,0 p\ip = msgFrom drawinfo("New player.") WriteByte(stream,3) SendUDPMsg(stream, msgFrom, client_port) For p.players = Each players WriteByte(stream,1) WriteInt(stream,msgFrom) SendUDPMsg(stream,p\ip,client_port) Next Case 2 For p.players = Each players If p\ip = msgFrom p\x# = ReadFloat(stream) p\y# = ReadFloat(stream) p\z# = ReadFloat(stream) p\yaw# = ReadFloat(stream) p\pitch# = ReadFloat(stream) EndIf Next End Select EndIf ;----data to clients---- For p.players = Each players WriteByte(stream,2) WriteFloat(stream, EntityX(Host)) WriteFloat(stream, EntityY(Host)) WriteFloat(stream, EntityZ(Host)) WriteFloat(stream, EntityYaw(Host)) WriteFloat(stream, EntityPitch(Host)) SendUDPMsg(stream, p\ip, client_port) Next ;----------------------- End Function Function updateme() If KeyDown(200) PositionEntity me,EntityX(me),0,EntityZ(me)+0.1 EndIf If KeyDown(208) PositionEntity me,EntityX(me),0,EntityZ(me)-0.1 EndIf If KeyDown(203) PositionEntity me,EntityX(me)+0.1,0,EntityZ(me) EndIf If KeyDown(205) PositionEntity me,EntityX(me)-0.1,0,EntityZ(me) EndIf If RecvUDPMsg(stream) msgtype = ReadByte(stream) msgFrom = UDPMsgIP(stream) Select(msgtype) Case 1 If Not DottedIP(msgFrom) = serverIP$ p.players = New players p\mesh = CopyEntity(me) EntityColor p\mesh,0,255,0 p\ip = ReadInt(stream) drawinfo("New player [" + DottedIP(p\ip) + "]") WriteByte(stream,3) SendUDPMsg(stream, msgFrom, client_port) EndIf Case 2 For p.players = Each players If p\ip = msgFrom p\x# = ReadFloat(stream) p\y# = ReadFloat(stream) p\z# = ReadFloat(stream) p\yaw# = ReadFloat(stream) p\pitch# = ReadFloat(stream) EndIf Next Case 3 p.players = New players p\mesh = CopyEntity(me) EntityColor p\mesh,0,255,0 p\ip = msgFrom End Select EndIf ;----data to host---- WriteByte(stream,2) WriteFloat(stream, EntityX(me)) WriteFloat(stream, EntityY(me)) WriteFloat(stream, EntityZ(me)) WriteFloat(stream, EntityYaw(me)) WriteFloat(stream, EntityPitch(me)) SendUDPMsg(stream, intIP(serverIP$), host_port) ;-------------------- ;---data to client--- For p.players = Each players WriteByte(stream,2) WriteFloat(stream, EntityX(me)) WriteFloat(stream, EntityY(me)) WriteFloat(stream, EntityZ(me)) WriteFloat(stream, EntityYaw(me)) WriteFloat(stream, EntityPitch(me)) SendUDPMsg(stream, p\ip, client_port) Next ;-------------------- End Function Function updateqbes() For p.players = Each players PositionEntity p\mesh,p\x#,p\y#,p\z# Next End Function Function drawinfo(inftxt$) t.infotext = New infotext t\y = curY t\txt$ = inftxt$ t\deleted = 0 curY = curY+12 If curY > 12*maxlines For t.infotext = Each infotext t\deleted = 1 Next EndIf End Function Function intIP(IP$) CountHostIPs(IP$) Return HostIP(1) End Function |
||
Starfare: Worklog, Website (download) |
![]() |
Noobody |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ist lieb gemeint, aber der Code hilft mir weniger weiter^^
Hab erstens keine Ahnung von 3D-Programmierung (trotz B3D^^) und für meinen Geschmack ist mit Kommentaren ein wenig zu spärlich umgegangen worden. Hat jemand ne Ahnung wie ich das mit den externen Dateien für die Charas machen könnte? |
||
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun |
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
www.robsite.de
Die Anfänger-RPG tutorials mal machen. |
||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group