You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Director using deprecated pyglet class clock.ClockDisplayĀ #255
The "set_show_FPS" function of cocos.director is currently using pyglet.clock.ClockDisplay to show the FPS.
According to pyglet documentation:
"Deprecated. This class presents values that are often misleading, as they reflect the rate of clock ticks, not displayed framerate. Use pyglet.window.FPSDisplay instead." (http://pyglet.readthedocs.org/en/latest/api/pyglet/clock/pyglet.clock.ClockDisplay.html)
I've made a few tests, running default samples and tests from cocos, after commenting on director.py:
self.fps_display = clock.ClockDisplay()
and adding:
self.fps_display = pyglet.window.FPSDisplay(self.window)
One or two scripts stopped working, but they had no fps display by default, so I can't really tell if they crashed after inserting a fps display or because I've changed it from ClockDisplay to FPSDisplay.
The majority of them ran without any issues and the new fps display gave me supposedly more stable fps numbers.
Any reason not to use the pyglet.window.FPSDisplay? If not that should probably become the new cocos.director.fps_display.
I reviewed the code and here are some suggestions.
fps.pyget_default_fpsdisplay(): I don't understand why with Python version <3.3 on platforms other than Windows you want to use time.time instead of time.clock. The documentation says:
time.clock()
On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of āprocessor timeā, depends on that of the C function of the same name, but in any case, this instead the function to use for benchmarking Python or timing algorithms. [...]
(Emphasis is mine)
FpsStatsABC: why not enforce that methods are abstract methods using the decorator @abstractmethod ?
I read many times that it's bad practice to use import inside code. I see import used inside FpsDisplayDeprecatedPygletOldStyle and InfoLabel. I understand that if one of those classes is not used, the import won't execute and we won't pull unecessary code. But this could create confusion later on, when trying to figure out what are the dependencies of the module. Maybe there is a reason I don't see why we can't just place the imports at the top of the code.
As it is, the FPS only displays when I press a key, and the number is extremely low. If I uncomment the schedule call, then it works normally. I roughly understand that pyglet tries to be efficient in its mainloop, and if there is nothing scheduled, then the loop stays idle. But at the very least, we should make sure the Label displays when CTRL-X is pressed.
That's all I could think of at the moment. Otherwise it's obviously very well written and well thought of.
fps.py get_default_fpsdisplay(): I don't understand why with Python
version <3.3 on platforms other than Windows you want to use time.time
instead of time.clock. The documentation says:
time.clock() On Unix, return the current processor time as a floating
point number expressed in seconds. The precision, and in fact the very
definition of the meaning of āprocessor timeā, depends on that of the C
function of the same name, but in any case, this instead the function to
use for benchmarking Python or timing algorithms. [...]
(Emphasis is mine)
To measure we count how many frames got drawn along a time interval
measured in the real world, also known as wall time.
In (some?all?) unix-like systems time.clock seems to be more akin to
process time, 'how many cpu time was used by our process', that is, when
the cpu runs other processes that time does not count for time.clock.
So, along 1 sec of wall time, time.clock usually will show less than 1 sec,
because the cpu / core is shared with other processes.
Anecdote: I was bitten by this difference in a pyweek because used
time.clock and it worked as intended in windows, but linuxy people
complained game movements were too slow. And it was that, the dt were much
smaller than wall time dt.
The python 3.5 docs for time.clock changed a lot, telling:
"""
On Unix, return the current processor time as a floating point number
expressed in seconds. The precision, and in fact the very definition of the
meaning of āprocessor timeā, depends on that of the C function of the same
name.
On Windows, this function returns wall-clock seconds elapsed since the
first call to this function, as a floating point number, based on the Win32
function QueryPerformanceCounter(). The resolution is typically better than
one microsecond.
Deprecated since version 3.3: The behaviour of this function depends on the
platform: use perf_counter() or process_time() instead, depending on your
requirements, to have a well defined behaviour.
"""
FpsStatsABC: why not enforce that methods are abstract methods using the
decorator @AbstractMethod ?
ok, doing that with an additional help from six for this to work py2-3
I read many times that it's bad practice to use import inside code. I see
import used inside FpsDisplayDeprecatedPygletOldStyle and InfoLabel. I
understand that if one of those classes is not used, the import won't
execute and we won't pull unecessary code. But this could create confusion
later on, when trying to figure out what are the dependencies of the
module. Maybe there is a reason I don't see why we can't just place the
imports at the top of the code.
Ok, done
I tried also this minimal code:
[sniped code]
As it is, the FPS only displays when I press a key, and the number is
extremely low. If I uncomment the schedule call, then it works normally. I
roughly understand that pyglet tries to be efficient in its mainloop, and
if there is nothing scheduled, then the loop stays idle. But at the very
least, we should make sure the Label displays when CTRL-X is pressed.
It used to be that if nothing scheduled the on_draw method got called at
low fps; current pyglet stops calling at all. This also produces the effect
that (if nothing scheduled) covering and uncovering a pyglet Window leaves
the window dirty.
A workaround for cocos is to do a
pyglet.clock.schedule_interval(lambda dt: None, 0.1)
in director.run.
This is a low frequency refresh, if fixes your case and the one I mentioned.
I will add as a separate commit after the fps one.
From the next email: format string
Done.
I will take a final look, squash and commit to master.
edit: there is some issue with the markup that hides parts of this post (I answered from the gmail web client) and I don't see how to fix with an edit on github. so:
use /@abc.abstractmethod -> done
move imports to top: -> done
Activity
ccanepa commentedon Nov 8, 2015
No reason, simply it was out of the radar.
I will look at this, but can you mention the tests that stopped ?
Thanks for the warning and testing.
LukeMS commentedon Nov 10, 2015
I've tried it again and everything worked fine this time.
new interface for easy customize fps stats, #255
ccanepa commentedon Apr 16, 2016
Looked at the new implementation in pyglet. While it provides equivalent functionality that old pyglet, I disliked
Not a big deal, but it is not hard to write fps support in cocos which
The common usage does not change: use ctrl + X to toggle show fps interactively, use
director.show_FPS = Trueto show it programaticallyI created the branch https://github.com/los-cocos/cocos/commits/fps to implement this.
Comments are welcomed. @dangillet ?
dangillet commentedon Apr 17, 2016
Hello Claudio,
Very nice job! Well done!
I reviewed the code and here are some suggestions.
fps.py
get_default_fpsdisplay(): I don't understand why with Python version <3.3 on platforms other than Windows you want to usetime.timeinstead oftime.clock. The documentation says:time.clock()
On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of āprocessor timeā, depends on that of the C function of the same name, but in any case, this instead the function to use for benchmarking Python or timing algorithms. [...]
(Emphasis is mine)
FpsStatsABC: why not enforce that methods are abstract methods using the decorator@abstractmethod?I read many times that it's bad practice to use import inside code. I see import used inside
FpsDisplayDeprecatedPygletOldStyleandInfoLabel. I understand that if one of those classes is not used, the import won't execute and we won't pull unecessary code. But this could create confusion later on, when trying to figure out what are the dependencies of the module. Maybe there is a reason I don't see why we can't just place the imports at the top of the code.I tried also this minimal code:
As it is, the FPS only displays when I press a key, and the number is extremely low. If I uncomment the
schedulecall, then it works normally. I roughly understand that pyglet tries to be efficient in its mainloop, and if there is nothing scheduled, then the loop stays idle. But at the very least, we should make sure the Label displays when CTRL-X is pressed.That's all I could think of at the moment. Otherwise it's obviously very well written and well thought of.
Regards,
Daniel.
dangillet commentedon Apr 17, 2016
One more remark I forgot to make. Maybe use
formatfor strings instead of%. :)ccanepa commentedon Apr 18, 2016
On Sun, Apr 17, 2016 at 4:18 AM, Daniel Gillet notifications@github.com
wrote:
To measure we count how many frames got drawn along a time interval
measured in the real world, also known as wall time.
In (some?all?) unix-like systems time.clock seems to be more akin to
process time, 'how many cpu time was used by our process', that is, when
the cpu runs other processes that time does not count for time.clock.
So, along 1 sec of wall time, time.clock usually will show less than 1 sec,
because the cpu / core is shared with other processes.
Anecdote: I was bitten by this difference in a pyweek because used
time.clock and it worked as intended in windows, but linuxy people
complained game movements were too slow. And it was that, the dt were much
smaller than wall time dt.
The python 3.5 docs for time.clock changed a lot, telling:
"""
On Unix, return the current processor time as a floating point number
expressed in seconds. The precision, and in fact the very definition of the
meaning of āprocessor timeā, depends on that of the C function of the same
name.
On Windows, this function returns wall-clock seconds elapsed since the
first call to this function, as a floating point number, based on the Win32
function QueryPerformanceCounter(). The resolution is typically better than
one microsecond.
Deprecated since version 3.3: The behaviour of this function depends on the
platform: use perf_counter() or process_time() instead, depending on your
requirements, to have a well defined behaviour.
"""
[sniped code]
It used to be that if nothing scheduled the on_draw method got called at
low fps; current pyglet stops calling at all. This also produces the effect
that (if nothing scheduled) covering and uncovering a pyglet Window leaves
the window dirty.
A workaround for cocos is to do a
pyglet.clock.schedule_interval(lambda dt: None, 0.1)
in director.run.
This is a low frequency refresh, if fixes your case and the one I mentioned.
I will add as a separate commit after the fps one.
Done.
I will take a final look, squash and commit to master.
edit: there is some issue with the markup that hides parts of this post (I answered from the gmail web client) and I don't see how to fix with an edit on github. so:
use /@abc.abstractmethod -> done
move imports to top: -> done
new interface for easy customize fps stats, #255
ccanepa commentedon Apr 18, 2016
Merged to master; and committed also the on_draw workaround in next commit.
Thanks for the review, @dangillet .