BlitzPlay help - 3d conversion
Blitz3D Forums/Blitz3D Programming/BlitzPlay help - 3d conversion
| ||
I've been trying to convert the demo that comes with BP-LE to a 3d format, and I need to know if anyone could catch what mistake I'm making here that isn't updating the models for players that join (not even showing models when they join) But the log it makes says we're connecting and it also says we're sending data to each other ... so I can't figure it ... any help would be great! Thanks! Include "BPliteV1.13.bb" Global send_freq% = 8 Global sendupdates% = True Global logging% = False Type pdata Field x#,y#,z#,r#,name$,net_id% Field xvel#,yvel#,zvel#,rvel# Field model End Type Type Info Field txt$ End Type Graphics3D 800, 600, 16, 2 SetBuffer BackBuffer() Global gameFPS = 60 ; Third Person Camera crap Global TPerson = CreateCamera () ; Creating camera for First Person Global FPerson=CreateCamera() CameraRange FPerson, 0.2, 2000 ; Collision Constants Const BUILDING_COL = 1 Const PLAYER_COL = 2 Const MONSTER_COL = 3 Const STAIRS_COL = 4 Const STAIRS_COL_X = 5 ;--------------------------------------------| ;LINKED FILES - Load resources files ;--------------------------------------------| Include "resources.bb" ; Consider collisions in these manners Collisions PLAYER_COL, MONSTER_COL, 2, 2 Collisions PLAYER_COL, BUILDING_COL, 2, 2 Collisions PLAYER_COL, STAIRS_COL_X, 2, 3 Collisions MONSTER_COL, BUILDING_COL, 2, 2 framePeriod = 1000 / gameFPS frameTime = MilliSecs () - framePeriod fps=0 framecount=0 oldfps=0 TAB_HELD = 0 Global health# = 100 ; Move mouse to center of screen MoveMouse 400, 300 ;--------------------------------------------| ;LINKED FILES - Camera control and Monster AI ;--------------------------------------------| Include "camera.bb" ;Include "monster.bb" Include "GUI.bb" Include "controls.bb" Cls Color 100,150,100 Text 0,0,"Would you like to:" Text 20,FontHeight()*2,"[H]ost a game" Text 10,FontHeight()*3,"or" Text 20,FontHeight()*4,"[J]oin one in progress?" FlushKeys() Repeat If KeyHit(35) Then Host = True Exit End If If KeyHit(36) Then Host = False Exit End If Forever Cls FlushKeys myname$ = Input$ ("Your name? ") FlushKeys If Host Then My_Port = 2222 If Not BP_HostSession (myname,10,1,2222,10) Then Cls Locate 0,0 Print "Host port was unavailable..Push a key to exit.." WaitKey End End If p.pdata = New pdata p\name = myname p\x = 0 p\y = 50 p\z = 0 p\r = 90 p\model = player ShowEntity p\model p\net_id = BP_My_ID Else Print "Host port = 2222" Print "(Blank for Local IP)" IP$ = Input$("Please enter the host's IP? ") Select IP Case "" IP$ = "127.0.0.1" My_Port = Rand(3000,4000) Default My_Port = Input$ ("What port would you like to use? ") If Not My_Port Then My_Port = Rand (3000,4000) End Select Cls Text 200,50,"Connecting! (Hit [esc] to cancel)",True,True Select BP_JoinSession (myname,My_Port,IP,2222) ;Handle any of the reasons if we couldn't join. Case BP_NOREPLY Cls Text 0,0,"No reply in specified timeout period.. exiting" WaitKey End Case BP_IAMBANNED Cls Text 0,0,"You have been banned from joining this game.. exiting" WaitKey End Case BP_GAMEISFULL Cls Text 0,0,"The game is full.. exiting" WaitKey End Case BP_PORTNOTAVAILABLE Cls Text 0,0,"Port: " + My_Port + " was not available.. exiting" WaitKey End Case BP_USERABORT Cls Text 0,0,"Connection attempt aborted!" WaitKey End End Select ;Oh, we're allowed in? here we go! p.pdata = New pdata p\name = myname p\x = 0 p\y = 50 p\z = 0 p\r = 0 p\model = player ShowEntity p\model p\net_id = BP_My_ID End If ;----------------------------------------------------------------------------- Repeat ; Frame limiting Repeat frameElapsed = MilliSecs () - frameTime Until frameElapsed frameTicks = frameElapsed / framePeriod frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod) ; Update game and world state For frameLimit = 1 To frameTicks If frameLimit = frameTicks Then CaptureWorld frameTime = frameTime + framePeriod BP_UpdateNetwork() HandleMessages() UpdateGame() send_count = send_count - 1 If send_count <= 0 Then send_count = send_freq p.pdata = First pdata msgtosend$ = BP_IntToStr(Int(p\x),2) + BP_IntToStr(Int(p\y),2) + BP_IntToStr(Int(p\r),2) + BP_IntToStr(Int(p\z),2 ) If sendupdates Then BP_UDPMessage (0,1,msgtosend$) End If fps = fps + 1 UpdateWorld Next RenderWorld frameTween If ent Then Text 0,0, EntityName$(ent) Color 255, 255, 255 If health < 0 Then health = 0 Text 10, 10, "Health: " + health If MilliSecs()-framecount > 1000 Then framecount=MilliSecs():oldfps=fps:fps=0 Flip Until KeyHit (1) BP_EndSession () End Function UpdateGame() CameraModeSwitcher() CameraModeHandler() UpdatePlayers() UserInput() If KeyHit(59) Then logging = 1 - logging If logging Then BP_StartLogFile (myname + ".txt") Else BP_StopLogFile () End If End If End Function Function HandleMessages () For msg.MsgInfo = Each MsgInfo Select msg\msgType Case 255 ;A new player has joined! p.pdata = New pdata p\name = msg\msgData p\x = 0 p\y = 50 p\z = 0 p\r = 90 p\model = LoadAnimMesh("media\sammarktou2.x") p\net_id = msg\msgFrom nInfo.NetInfo = BP_FindID(p\net_id) Info ("**" + p\Name + " has joined!") Case 254 ;A player has left p.pdata = Find_pdata(msg\msgFrom) If p<>Null Then If msg\msgData = True Then Info ("**" + p\Name + " has left!") Else Info ("**" + p\Name + " lagged out!") Delete p End If Case 253 ;The host has disconnected For p.pdata = Each pdata If p\net_id <> BP_My_ID Then Delete p Next If msg\msgData = True Then Info ("**The host ended the game!") Else Info ("**No reply from host in " + (BP_TimeoutPeriod / 1000) + " seconds. Exiting game..") Case 252 ;Someone got kicked/banned p.pdata = Find_pdata(msg\msgFrom) If p\net_id = BP_My_ID Then ;It was -me-?? If msg\msgData = False Then Info ("**You have been kicked!") Else Info ("**You have been banned!") For p.pdata = Each pdata If p\net_id <> BP_My_ID Then Delete p End If Next Else ;It wasn't? Ok then. If msg\msgData = False Then Info ("**" + p\Name + " has been kicked!") Else Info ("**" + p\Name + " has been banned!") Delete p End If Case 1 ;a position update packet newx% = BP_StrToInt (Mid$(msg\msgData,1,2)) newy% = BP_StrToInt (Mid$(msg\msgData,3,2)) newr% = BP_StrToInt (Mid$(msg\msgData,5,2)) newz% = BP_StrToInt (Mid$(msg\msgData,7,2)) p.pdata = Find_pdata(msg\msgFrom) ;This demo handles movement by calculating an average speed to bring the player to the point indicated ;in the packet by the time we think the next update should arrive. ;This is fairly accurate in describing where the player moved, at one point, but unfortunately is not very ;accurate for predicting where the player is "now" so to speak. p\xvel = (newx - p\x) / send_freq p\yvel = (newy - p\y) / send_freq p\zvel = (newz - p\z) / send_freq p\rvel = rotarydir(p\r,newr,send_freq) Case 2 ;a chat packet p.pdata = Find_pdata(msg\msgFrom) Info (p\Name + ":" + msg\msgData) End Select Delete msg Next End Function Function UpdatePlayers () For p.pdata = Each pdata If p\net_id = BP_My_ID Then p\x = EntityX(player) p\y = EntityY(player) p\z = EntityZ(player) p\r = EntityYaw(player) End If Next For p.pdata = Each pdata PositionEntity p\model, p\x, p\y, p\z RotateEntity p\model, 0, p\r, 0 Next End Function Function Find_pdata.pdata (ID) For p.pdata = Each pdata If p\net_id = ID Then Return p Next End Function Function rotarydir#(Asource#,Adest#,smooth#) ;Taken from the Code Archives on blitzbasic.com, If Asource#>Adest# ;Thanks Skully! Diff1#=Asource-Adest diff2#=(360.0-Asource)+Adest If diff2<diff1 dir#=diff2/smooth Else dir#=diff1/smooth*-1 EndIf Else If Asource#<Adest# diff1=Adest-Asource diff2=(360.0-Adest)+Asource If diff2<diff1 dir#=diff2/smooth*-1 Else dir#=diff1/smooth EndIf Else dir=0 EndIf EndIf Return dir End Function Function Info (t$) i.Info=New Info i\txt$=t$ Insert i Before First Info End Function |