Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
boomAlex
Visitor

roScreen on Roku 3 locked to 20 fps

I am writing a game for Roku using the roScreen and for some reason it seems that the Roku 3 I am testing on is locked to 20 fps. The thing that is really confusing is that the same game runs at more then 60fps on a Roku 2. What could be going on here that is making my frame rate so low on the Roku 3 when it should be a higher preforming device then the Roku 2?
0 Kudos
10 REPLIES 10
RokuJoel
Binge Watcher

Re: roScreen on Roku 3 locked to 20 fps

You probably would have to share some source. If you don't want to do that in the public forum, please email developer@roku.com with a sample app (in .zip format, not a .pkg) that shows the issue, so we can investigate.

- Joel
0 Kudos
Komag
Roku Guru

Re: roScreen on Roku 3 locked to 20 fps

Depends on which Roku 3 and Roku 2 you are talking about as well - they might be the same!
0 Kudos
boomAlex
Visitor

Re: roScreen on Roku 3 locked to 20 fps

Alright here is some code, still not sure why this should matter as it is the exact same code running on both the Roku 2 and the Roku 3, yet the Roku 2 has 5x the frame rate.

Main while loop
calls to other objects, one of them is an implementation of dnode for socket events could that be causing it?
in this case m.mode = "game"
    
while m.running
if m.mode = "game"
m.gameModeObject.gameLoop()
m.timerManager.handleTimers()
delay = 1
else
delay = m.timerManager.handleTimers()
end if
msg = wait(delay, m.port)
if msg <> invalid
if type(msg) = "roSocketEvent"
m.dnode.update(msg)
else if type(msg) = "roChannelStoreEvent"
storeSvc.update(msg)
else
m.sManager.update(msg)
End If
end if
end while


The implementation of the "gameModeObject" from the above code

function gameScreen(msgPort as object) as object
this = {
s: CreateObject("roScreen")
time: CreateObject("roTimespan")
fr: CreateObject("roFontRegistry")

elapsed: 0
lastTime: 0
current: 0
start: 0
}

this.init = function()
m.s.SetMessagePort(m.port)
m.s.clear(&hff954aFF)
m.s.setAlphaEnable(true)

'draw a simple rectangle on the screen once and nothing else
m.s.drawRect(0, 0, 264, 720, &hff95ffFF)
end function

this.drawLoop = function(dt as dynamic)
if dt <= 0 then stop

'fps counter
m.s.DrawRect(1115, 0, 200, 50, &hff954aFF)
m.s.DrawText("fps: " + toString(1000 / dt), 1120, 0, &hFFFFFF, m.fr.GetDefaultFont())
m.s.finish()
end function

this.gameLoop = function()
m.lastTime = m.current
'm.time.mark()
m.current = m.time.totalmilliseconds() - m.start
m.elapsed = (m.time.totalmilliseconds() - m.start) - m.lastTime

m.drawLoop(m.elapsed)
end function

this.init()

return this
end function
0 Kudos
RokuMarkn
Visitor

Re: roScreen on Roku 3 locked to 20 fps

This first thing I'm suspicious about is your use of a timed wait. Generally this isn't a safe thing to do for animation, and the behavior could be different on different Roku models. You should probably use GetMessage() instead. See the discussion under "Game scripts" in https://sdkdocs.roku.com/display/sdkdoc/Event+Loops

--Mark
0 Kudos
RokuJoel
Binge Watcher

Re: roScreen on Roku 3 locked to 20 fps

Yes, as Mark points out best not to use wait if you need a high framerate. On the Roku 2 XS and related chipsets there is actually a bug that makes wait take an inconsistent amount of time to complete. Not sure why that would give you higher performance, usually it is the opposite effect.

I would suggest using message=port.getmessage() and if you want to execute on a timeframe, then use roTimeSpan to trigger action at the millisecond count you want:


if mytimer.totalmilliseconds() >=m.timerManager.handleTimers() then 
msg=port.getmessage()
doStuff()
timer.mark()
end if
0 Kudos
boomAlex
Visitor

Re: roScreen on Roku 3 locked to 20 fps

So I just switched from using wait() to using roMessagePort.getMessage() but it seems that getMessage() never returns roSocket events.

I though that doing getMessage() was the same thing as wait(1, port) but faster, is this not the case?
0 Kudos
malort
Visitor

Re: roScreen on Roku 3 locked to 20 fps

"boomAlex" wrote:
So I just switched from using wait() to using roMessagePort.getMessage() but it seems that getMessage() never returns roSocket events.

I though that doing getMessage() was the same thing as wait(1, port) but faster, is this not the case?


We noticed that too for events for `roStreamSocket`, but not for `roDatagramSocket`. We ended up using `wait(1, port)` for the roSocketPorts and `GetMessage()` for the others. This required using multiple ports, but processing them in a global loop.

At first we used `wait(1, port)` due to the missing events, but we noticed the Roku would intermittently wait 5000ms on every Roku model we tested, and only seemed to affect the message events for `roDatagramSocket`. Maybe this is what RokuMarkn was referring to.
0 Kudos
RokuJoel
Binge Watcher

Re: roScreen on Roku 3 locked to 20 fps

"malort" wrote:
but we noticed the Roku would intermittently wait 5000ms on every Roku model we tested


Hmm not seeing this. What devices are you testing?

sub main()
screen=createobject("roScreen")
port=createobject("roMessagePort")
screen.setmessageport(port)
timer=createobject("roTimeSpan")
timer.mark()
while true
timer.mark()
msg=wait(1,port)
?timer.totalmilliseconds()
end while
end sub
0 Kudos
RokuJoel
Binge Watcher

Re: roScreen on Roku 3 locked to 20 fps

Also, for things like roStreamSockets, probably best not to share a port (not saying you are doing this) with any other components like the screen - give it its own port.

- Joel
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.