indexing description: "[ If you need performance information use an EM_FRAME_COUNTER. A EM_FRAME_COUNTER draws the current frame rate to a surface. ]" date: "$Date$" revision: "$Revision$" class EM_FRAME_COUNTER inherit EM_TIME_SINGLETON undefine default_create end EM_DRAWABLE redefine draw_part end EM_SHARED_STANDARD_FONTS export {NONE} all end create make feature {NONE} -- Initialization make is -- Initialise default values. local font: EM_FONT do default_create font := standard_bmp_fonts.small_font create str.make("??.? fps",font) set_visible (True) ensure is_visible: is_visible end feature -- Commands draw (a_surface: EM_SURFACE) is -- Draws `current' to `a_surface' do if is_visible then update_fps str.set_x (x) str.set_y (y) str.draw (a_surface) end end draw_part (rect: EM_BLITTING_RECTANGLE; a_surface: EM_SURFACE) is -- Draws rectangular part of `current' defined by `rect' to `a_surface' do if is_visible then update_fps str.set_x (x) str.set_y (y) str.draw_part (rect, a_surface) end end feature -- Status report width: INTEGER is -- Width of `Current' do result := str.width end height: INTEGER is -- Height of `Current' do result := str.height end feature {NONE} -- Implementation str: EM_STRING -- The string containing the correctly formatted frame per second information count: INTEGER -- The number of calls to draw last_call: INTEGER -- The last call of draw in millisecond update_fps is -- Recalculates actual frame rate and saves it in `str'. local fps: STRING do count := count + 1 if count\\10 = 0 then fps := (10000 / ( time.ticks - last_call )).out fps.keep_head (4) fps := fps + " fps" last_call := time.ticks str.set_value(fps) end end end