From 735c45d8b4c8a4541cef94a89be11802ae41b44e Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 8 Sep 2004 17:38:07 +0000 Subject: [PATCH] use self.wakeTime instead of cTask object --- direct/metalibs/direct/Sources.pp | 2 +- direct/src/heapq/Sources.pp | 3 -- direct/src/heapq/heapq.cxx | 45 +++++++++++++---------- direct/src/task/Sources.pp | 17 --------- direct/src/task/Task.py | 24 ++++++------- direct/src/task/cTask.I | 38 -------------------- direct/src/task/cTask.cxx | 31 ---------------- direct/src/task/cTask.h | 59 ------------------------------- 8 files changed, 37 insertions(+), 182 deletions(-) delete mode 100755 direct/src/task/cTask.I delete mode 100755 direct/src/task/cTask.cxx delete mode 100755 direct/src/task/cTask.h diff --git a/direct/metalibs/direct/Sources.pp b/direct/metalibs/direct/Sources.pp index 8debb4e3d2..eecbe14258 100644 --- a/direct/metalibs/direct/Sources.pp +++ b/direct/metalibs/direct/Sources.pp @@ -8,7 +8,7 @@ #define BUILDING_DLL BUILDING_DIRECT #define COMPONENT_LIBS \ - directbase dcparser showbase deadrec directd interval distributed task + directbase dcparser showbase deadrec directd interval distributed #define OTHER_LIBS \ panda:m \ diff --git a/direct/src/heapq/Sources.pp b/direct/src/heapq/Sources.pp index 8710a0d160..f0aa8fe922 100755 --- a/direct/src/heapq/Sources.pp +++ b/direct/src/heapq/Sources.pp @@ -14,9 +14,6 @@ #begin metalib_target #define TARGET heapq - #define LOCAL_LIBS \ - task - #define SOURCES heapq.cxx #end metalib_target diff --git a/direct/src/heapq/heapq.cxx b/direct/src/heapq/heapq.cxx index b25f0593d4..c09620161c 100755 --- a/direct/src/heapq/heapq.cxx +++ b/direct/src/heapq/heapq.cxx @@ -10,7 +10,6 @@ */ #include -#include "cTask.h" /* Prototypes */ static PyObject * heappush(PyObject *self, PyObject *args); @@ -129,10 +128,12 @@ _siftdown(PyObject *list, int startpos, int pos) { newitem = PySequence_GetItem(list,pos); - PyObject *newitemCTask_this = PyObject_GetAttrString(newitem, "this"); - nassertr(newitemCTask_this != NULL, false); - CTask *newitemCTask = (CTask *)PyInt_AsLong(newitemCTask_this); - Py_DECREF(newitemCTask_this); + PyObject *newitem_wakeTime_obj = PyObject_GetAttrString(newitem, "wakeTime"); + double newitem_wakeTime = 0.0; + if (newitem_wakeTime_obj != NULL) { + newitem_wakeTime = PyFloat_AS_DOUBLE(newitem_wakeTime_obj); + Py_DECREF(newitem_wakeTime_obj); + } while (pos > startpos) { parentpos = (pos - 1) >> 1; @@ -146,12 +147,14 @@ _siftdown(PyObject *list, int startpos, int pos) { return -1; */ - PyObject *parentCTask_this = PyObject_GetAttrString(parent, "this"); - nassertr(parentCTask_this != NULL, false); - CTask *parentCTask = (CTask *)PyInt_AsLong(parentCTask_this); - Py_DECREF(parentCTask_this); + PyObject *parent_wakeTime_obj = PyObject_GetAttrString(parent, "wakeTime"); + double parent_wakeTime = 0.0; + if (parent_wakeTime_obj != NULL) { + parent_wakeTime = PyFloat_AS_DOUBLE(parent_wakeTime_obj); + Py_DECREF(parent_wakeTime_obj); + } - if (parentCTask->get_wake_time() <= newitemCTask->get_wake_time()) { + if (parent_wakeTime <= newitem_wakeTime) { break; } @@ -177,19 +180,23 @@ _siftup(PyObject *list, int pos) { rightpos = childpos + 1; child = PySequence_Fast_GET_ITEM(list,childpos); - PyObject *childCTask_this = PyObject_GetAttrString(child, "this"); - nassertr(childCTask_this != NULL, false); - CTask *childCTask = (CTask *)PyInt_AsLong(childCTask_this); - Py_DECREF(childCTask_this); + PyObject *child_wakeTime_obj = PyObject_GetAttrString(child, "wakeTime"); + double child_wakeTime = 0.0; + if (child_wakeTime_obj != NULL) { + child_wakeTime = PyFloat_AS_DOUBLE(child_wakeTime_obj); + Py_DECREF(child_wakeTime_obj); + } if (rightpos < endpos) { right = PySequence_Fast_GET_ITEM(list,rightpos); - PyObject *rightCTask_this = PyObject_GetAttrString(right, "this"); - nassertr(rightCTask_this != NULL, false); - CTask *rightCTask = (CTask *)PyInt_AsLong(rightCTask_this); - Py_DECREF(rightCTask_this); + PyObject *right_wakeTime_obj = PyObject_GetAttrString(right, "wakeTime"); + double right_wakeTime = 0.0; + if (right_wakeTime_obj != NULL) { + right_wakeTime = PyFloat_AS_DOUBLE(right_wakeTime_obj); + Py_DECREF(right_wakeTime_obj); + } /* cmp = PyObject_RichCompareBool(right,child,Py_LE); @@ -199,7 +206,7 @@ _siftup(PyObject *list, int pos) { return -1; */ - if (rightCTask->get_wake_time() <= childCTask->get_wake_time()) { + if (right_wakeTime <= child_wakeTime) { childpos = rightpos; } } diff --git a/direct/src/task/Sources.pp b/direct/src/task/Sources.pp index 208c7edca9..e69de29bb2 100644 --- a/direct/src/task/Sources.pp +++ b/direct/src/task/Sources.pp @@ -1,17 +0,0 @@ -#begin lib_target - #define TARGET task - #define LOCAL_LIBS \ - directbase - #define OTHER_LIBS \ - panda - - #define SOURCES \ - config_task.cxx config_task.h \ - cTask.h cTask.I cTask.cxx - - #define INSTALL_HEADERS \ - config_task.h \ - cTask.h cTask.I - - #define IGATESCAN all -#end lib_target diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 8aaf8877ff..f8a35331ef 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -5,8 +5,7 @@ # subset of PandaModules that we know is available immediately. # Methods that require more advanced C++ methods may import the # appropriate files within their own scope. -# from pandac.libpandaexpressModules import * -from pandac.libdirectModules import * +from pandac.libpandaexpressModules import * from direct.directnotify.DirectNotifyGlobal import * from direct.showbase.PythonUtil import * @@ -64,14 +63,9 @@ def print_exc_plus(): except: print "" -# Here we inherit from CTask so that we can drop the expensive work -# that the task does down into C++. The main reason to do this is -# to move the compare operator for the heapq data structure. - -class Task(CTask): +class Task: count = 0 def __init__(self, callback, priority = 0): - CTask.__init__(self) # Unique ID for each task self.id = Task.count Task.count += 1 @@ -85,14 +79,16 @@ class Task(CTask): self.runningTotal = 0.0 self.pstats = None self.extraArgs = None + # Used for doLaters + self.wakeTime = 0.0 # # Used for putting into the doLaterList # # the heapq calls __cmp__ via the rich compare function # def __cmp__(self, other): # if isinstance(other, Task): -# if self.getWakeTime() < other.getWakeTime(): +# if self.wakeTime < other.wakeTime: # return -1 -# elif self.getWakeTime() > other.getWakeTime(): +# elif self.wakeTime > other.wakeTime: # return 1 # # If the wakeTimes happen to be the same, just # # sort them based on id @@ -390,7 +386,7 @@ class TaskManager: continue # If the time now is less than the start of the doLater + delay # then we are not ready yet, continue to next one - elif task.time < dl.getWakeTime(): + elif task.time < dl.wakeTime: # Since the list is sorted, the first one we get to, that # is not ready to go, we can return break @@ -427,7 +423,7 @@ class TaskManager: # have been synced since the start of this frame currentTime = globalClock.getFrameTime() # Cache the time we should wake up for easier sorting - task.setWakeTime(currentTime + delayTime) + task.wakeTime = currentTime + delayTime # Push this onto the doLaterList. The heap maintains the sorting. heappush(self.__doLaterList, task) if self.fVerbose: @@ -854,10 +850,10 @@ class TaskManager: # The priority heap is not actually in order - it is a tree # Make a shallow copy so we can sort it sortedDoLaterList = self.__doLaterList[:] - sortedDoLaterList.sort(lambda a,b: cmp(a.getWakeTime(), b.getWakeTime())) + sortedDoLaterList.sort(lambda a,b: cmp(a.wakeTime, b.wakeTime)) sortedDoLaterList.reverse() for task in sortedDoLaterList: - remainingTime = ((task.getWakeTime()) - self.currentTime) + remainingTime = ((task.wakeTime) - self.currentTime) if task.isRemoved(): taskName = '(R)' + task.name else: diff --git a/direct/src/task/cTask.I b/direct/src/task/cTask.I deleted file mode 100755 index 134b0ec8bf..0000000000 --- a/direct/src/task/cTask.I +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: cTask.I -// Created by: Administrator (03Sep04) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: CTask::set_wake_time -// Access: Published -// Description: Sets the wake time of this task (for doLaters) -//////////////////////////////////////////////////////////////////// -INLINE void CTask:: -set_wake_time(float wake_time) { - _wake_time = wake_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: CTask::get_wake_time -// Access: Published -// Description: Returns wake time of this task (for doLaters) -//////////////////////////////////////////////////////////////////// -INLINE float CTask:: -get_wake_time() const { - return _wake_time; -} diff --git a/direct/src/task/cTask.cxx b/direct/src/task/cTask.cxx deleted file mode 100755 index 5908f52fbc..0000000000 --- a/direct/src/task/cTask.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Filename: cTask.cxx -// Created by: Administrator (03Sep04) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - - -#include "cTask.h" - -TypeHandle CTask::_type_handle; - -CTask:: -CTask() { - _wake_time = 0.0; -} - -CTask:: -~CTask() { -} diff --git a/direct/src/task/cTask.h b/direct/src/task/cTask.h deleted file mode 100755 index d72f532cff..0000000000 --- a/direct/src/task/cTask.h +++ /dev/null @@ -1,59 +0,0 @@ -// Filename: cTask.h -// Created by: Shochet (03Sep04) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://etc.cmu.edu/panda3d/docs/license/ . -// -// To contact the maintainers of this program write to -// panda3d-general@lists.sourceforge.net . -// -//////////////////////////////////////////////////////////////////// - - -#ifndef CTASK_H -#define CTASK_H - -#include "directbase.h" -#include "typedReferenceCount.h" -#include "config_task.h" - - -class EXPCL_DIRECT CTask : public TypedReferenceCount { -PUBLISHED: - CTask(); - ~CTask(); - - INLINE void set_wake_time(float wake_time); - INLINE float get_wake_time() const; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "CTask", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - - float _wake_time; - - static TypeHandle _type_handle; -}; - -#include "cTask.I" - -#endif