Raknet using all the processor?

BlitzMax Forums/BlitzMax Programming/Raknet using all the processor?

Sanctus(Posted 2009) [#1]
Hey
I've been trying to use RakNet for a few days. It works fine but howcome once I start my app it imediatly takes one core?. I have a client and a server so that takes 2 processors and thus my dual core is used at 100%.
I've used repeatuntil's version but I'm now thinking of making my own. However I have no ideea how to get the functions from the dll since the dll functions are OOP.


Brucey(Posted 2009) [#2]
Can't say I've noticed that problem myself, although maybe it depends what you are actually doing with it. Can't you profile your code?

<EDIT> Well, I should say, I've not had this problem with mine...


Sanctus(Posted 2009) [#3]
Type TServerApp
	Global Peer:Int
	Global ClientList:TList = New TList
	Global GUpdateTime:Int = MilliSecs()
	Global TextList:TList = New TList
	Function StartServer()
		Peer = RN_Getrakpeerinterface()
		RN_startup(Peer, 32, 0, 6123)
		Graphics(1024, 768)
		RunServer()
	End Function
	
	Function RunServer()
		While Not KeyHit(KEY_ESCAPE)
			Local packet:Int = RN_Receive(peer)
			If(packet)
				Local MSG:String = RN_PacketGetData(packet)
				Local msgType:Int = Asc(MSG[0..1])
				Select msgType
					Case ID_REMOTE_DISCONNECTION_NOTIFICATION
	
					Case ID_REMOTE_CONNECTION_LOST
					
					Case ID_REMOTE_NEW_INCOMING_CONNECTION
						TextList.AddLast(CreateText("A client has connected"))
				End Select
			EndIf
			Delay 5
			UpdateGraphics()
		Wend
	End Function
	
	Function UpdateGraphics()
		If MilliSecs() - GUpdateTime > 100
			Local y:Int = 768 - 10
			For Local t:TText = EachIn TextList
				SetColor(t.r, t.g, t.b)
				DrawText(t.Text, 10, y)
				y = y - 10
			Next
			Flip
			Cls
			GUpdateTime = MilliSecs()
		End If
	End Function
	
End Type

I'd say this code is pretty easy... it just waits for packets and doesn't do anything.
Even the samples run like this so maybe it's a bug.

Anyway could you maybe post your version of raknet wrapper? I've noticed you have it on your modules page but can't find the dowload link like with the others.
Oh btw nice work on the database modules. They really help out


Zeke(Posted 2009) [#4]
try RN_startup(Peer, 32, 20, 6123)

20 is threadSleepTimer

This is from Raknet Manual:
The thread sleep timer controls how long RakNet will sleep between each internal update in its thread. A value of 0 will cause it to yield thread access after running once, then run again once its thread is scheduled again. This is suitable for file transfers over very low ping networks. It can also be used for games to save off a small amount of ping. However, Windows will report substantially more CPU usage. Many users are alarmed by this: However, keep in mind that the thread will yield, so if your game is doing other things, it won't slow down your game. If you don't want to use a value of 0, a value of 30 greatly reduces idle CPU usage.


Sanctus(Posted 2009) [#5]
Well that seems to have reduced the processor usage to 0 :)
Thanks man!
Then I guess when using the server for a lot of players I should reduce that to a smaller number like 2 or 1 or even 0 right?
The game I'm working on (till now with tcp sockets) is really fast paces so it was a pain to keep everything really synchronized