Author: richard
Date: Mon Jan 12 06:50:06 2009
New Revision: 3771
URL: http://svn.slimdevices.com?rev=3771&root=Jive&view=rev
Log:
Bug: N/A
Description:
Re-implement jive.ui.Timer in pure lua, and not using SDL_Timer. There is
clearly an underlying
timer bug that is causing many problems, and this will hopefully fix it once
and for all.
Removed:
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_timer.c
Modified:
7.4/trunk/squeezeplay/src/squeezeplay/Makefile.am
7.4/trunk/squeezeplay/src/squeezeplay/Makefile.in
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/Makefile.am
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/Makefile.am?rev=3771&root=Jive&r1=3770&r2=3771&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/Makefile.am (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/Makefile.am Mon Jan 12 06:50:06 2009
@@ -164,7 +164,6 @@
src/ui/jive_textarea.c \
src/ui/jive_textinput.c \
src/ui/jive_tile.c \
- src/ui/jive_timer.c \
src/ui/jive_utils.c \
src/ui/jive_widget.c \
src/ui/jive_window.c \
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/Makefile.in
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/Makefile.in?rev=3771&root=Jive&r1=3770&r2=3771&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/Makefile.in (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/Makefile.in Mon Jan 12 06:50:06 2009
@@ -78,8 +78,8 @@
jive_group.lo jive_icon.lo jive_label.lo jive_menu.lo \
platform_osx.lo platform_linux.lo jive_slider.lo jive_style.lo \
jive_surface.lo system.lo jive_textarea.lo jive_textinput.lo \
- jive_tile.lo jive_timer.lo jive_utils.lo jive_widget.lo \
- jive_window.lo lua_jiveui.lo
+ jive_tile.lo jive_utils.lo jive_widget.lo jive_window.lo \
+ lua_jiveui.lo
libjiveui_la_OBJECTS = $(am_libjiveui_la_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(testdir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
@@ -287,7 +287,6 @@
src/ui/jive_textarea.c \
src/ui/jive_textinput.c \
src/ui/jive_tile.c \
- src/ui/jive_timer.c \
src/ui/jive_utils.c \
src/ui/jive_widget.c \
src/ui/jive_window.c \
@@ -496,7 +495,6 @@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_textarea....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_textinput....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_tile....@am__quote@
-...@amdep_true@@am__include@ @am__qu...@./$(DEPDIR)/jive_timer....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_utils....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_widget....@am__quote@
@AMDEP_TRUE@@am__include@ @am__qu...@./$(DEPDIR)/jive_window....@am__quote@
@@ -745,13 +743,6 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/ui/jive_tile.c'
object='jive_tile.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE)
$(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS)
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -c -o jive_tile.lo `test -f 'src/ui/jive_tile.c' || echo
'$(srcdir)/'`src/ui/jive_tile.c
-
-jive_timer.lo: src/ui/jive_timer.c
-...@am__fastdepcc_true@ if $(LIBTOOL) --tag=CC --mode=compile $(CC)
$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -MT jive_timer.lo -MD -MP -MF "$(DEPDIR)/jive_timer.Tpo" -c -o
jive_timer.lo `test -f 'src/ui/jive_timer.c' || echo
'$(srcdir)/'`src/ui/jive_timer.c; \
-...@am__fastdepcc_true@ then mv -f "$(DEPDIR)/jive_timer.Tpo"
"$(DEPDIR)/jive_timer.Plo"; else rm -f "$(DEPDIR)/jive_timer.Tpo"; exit 1; fi
-...@amdep_true@@am__fastdepCC_FALSE@ source='src/ui/jive_timer.c'
object='jive_timer.lo' libtool=yes @AMDEPBACKSLASH@
-...@amdep_true@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE)
$(depcomp) @AMDEPBACKSLASH@
-...@am__fastdepcc_false@ $(LIBTOOL) --tag=CC --mode=compile $(CC)
$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -c -o jive_timer.lo `test -f 'src/ui/jive_timer.c' || echo
'$(srcdir)/'`src/ui/jive_timer.c
jive_utils.lo: src/ui/jive_utils.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS)
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS)
$(CFLAGS) -MT jive_utils.lo -MD -MP -MF "$(DEPDIR)/jive_utils.Tpo" -c -o
jive_utils.lo `test -f 'src/ui/jive_utils.c' || echo
'$(srcdir)/'`src/ui/jive_utils.c; \
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua?rev=3771&root=Jive&r1=3770&r2=3771&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua Mon Jan
12 06:50:06 2009
@@ -294,6 +294,7 @@
collectgarbage("step")
-- process ui event once per frame
+ Timer:_runTimer(now)
running = eventTask:resume()
-- when is the next frame due?
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua?rev=3771&root=Jive&r1=3770&r2=3771&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/share/jive/ui/Timer.lua Mon Jan 12
06:50:06 2009
@@ -26,15 +26,23 @@
-- stuff we use
-local _assert, string, tostring, type = _assert, string, tostring, type
+local _assert, ipairs, pcall, string, tostring, type = _assert, ipairs, pcall,
string, tostring, type
local oo = require("loop.base")
+local table = require("jive.utils.table")
+
+local Framework = require("jive.ui.Framework")
+
local debug = require("jive.utils.debug")
+local log = require("jive.utils.log").logger("ui")
-- our class
module(..., oo.class)
+
+-- sorted list of running timers
+local timers = {}
--[[
@@ -68,7 +76,12 @@
=cut
--]]
--- C implementation
+function start(self)
+ local now = Framework:getTicks()
+
+ self.expires = now + self.interval
+ self:_insertTimer()
+end
--[[
@@ -80,7 +93,10 @@
=cut
--]]
--- C implementation
+function stop(self)
+ table.delete(timers, self)
+ self.expires = nil
+end
--[[
@@ -115,9 +131,10 @@
function setInterval(self, interval)
_assert(type(interval) == "number")
- self.interval = interval
- if self._timerData then
- self:restart()
+ if self.expires then
+ self:restart(interval)
+ else
+ self.interval = interval
end
end
@@ -131,9 +148,39 @@
=cut
--]]
function isRunning(self)
- return self._timerData ~= nil
+ return self.expires ~= nil
end
+
+-- insert the timer into timer queue
+function _insertTimer(self)
+ for i, timer in ipairs(timers) do
+ if self.expires < timer.expires then
+ table.insert(timers, i, self)
+ return
+ end
+ end
+ table.insert(timers, self)
+end
+
+
+-- process timer queue
+function _runTimer(self, now)
+ while timers[1] and timers[1].expires <= now do
+ local timer = table.remove(timers, 1)
+
+ -- call back may modify the timer so update it first
+ if not timer.once then
+ timer.expires = timer.expires + timer.interval
+ timer:_insertTimer()
+ end
+
+ local status, err = pcall(timer.callback)
+ if not status then
+ log:warn("timer error: ", err)
+ end
+ end
+end
--[[
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h?rev=3771&root=Jive&r1=3770&r2=3771&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h Mon Jan 12 06:50:06 2009
@@ -140,7 +140,7 @@
enum {
- JIVE_USER_EVENT_TIMER = 0x00000001,
+ /* reserved: 0x00000001 */
JIVE_USER_EVENT_KEY_HOLD = 0x00000002,
JIVE_USER_EVENT_MOUSE_HOLD = 0x00000003,
JIVE_USER_EVENT_EVENT = 0x00000004,
@@ -390,8 +390,6 @@
JiveFont *jive_style_array_font(lua_State *L, int index, const char *array,
int n, const char *key);
Uint32 jive_style_array_color(lua_State *L, int index, const char *array, int
n, const char *key, Uint32 def, bool *is_set);
-void jive_timer_dispatch_event(lua_State *L, void *param);
-
/* lua functions */
int jiveL_get_background(lua_State *L);
@@ -484,9 +482,6 @@
int jiveL_style_color(lua_State *L);
int jiveL_style_font(lua_State *L);
-int jiveL_timer_add_timer(lua_State *L);
-int jiveL_timer_remove_timer(lua_State *L);
-
#define JIVEL_STACK_CHECK_BEGIN(L) { int _sc = lua_gettop((L));
#define JIVEL_STACK_CHECK_ASSERT(L) assert(_sc == lua_gettop((L)));
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c?rev=3771&root=Jive&r1=3770&r2=3771&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c Mon Jan 12
06:50:06 2009
@@ -1108,12 +1108,6 @@
case SDL_USEREVENT:
switch ( (int) event->user.code) {
- case JIVE_USER_EVENT_TIMER:
- JIVEL_STACK_CHECK_BEGIN(L);
- jive_timer_dispatch_event(L, event->user.data1);
- JIVEL_STACK_CHECK_END(L);
- return 0;
-
case JIVE_USER_EVENT_KEY_HOLD:
jevent.type = JIVE_EVENT_KEY_HOLD;
jevent.u.key.code = (JiveKey) event->user.data1;
@@ -1294,12 +1288,6 @@
{ NULL, NULL }
};
-static const struct luaL_Reg timer_methods[] = {
- { "start", jiveL_timer_add_timer },
- { "stop", jiveL_timer_remove_timer },
- { NULL, NULL }
-};
-
static const struct luaL_Reg event_methods[] = {
{ "new", jiveL_event_new },
{ "getType", jiveL_event_get_type },
@@ -1386,10 +1374,6 @@
luaL_register(L, NULL, slider_methods);
lua_pop(L, 1);
- lua_getfield(L, 2, "Timer");
- luaL_register(L, NULL, timer_methods);
- lua_pop(L, 1);
-
lua_getfield(L, 2, "Event");
luaL_register(L, NULL, event_methods);
lua_pop(L, 1);
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins