Browse Source

use self.wakeTime instead of cTask object

David Rose 21 years ago
parent
commit
735c45d8b4

+ 1 - 1
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 \

+ 0 - 3
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
 

+ 26 - 19
direct/src/heapq/heapq.cxx

@@ -10,7 +10,6 @@
 */
 
 #include <Python.h>
-#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;
             }
         }

+ 0 - 17
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

+ 10 - 14
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 "<ERROR WHILE PRINTING VALUE>"
 
-# 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:

+ 0 - 38
direct/src/task/cTask.I

@@ -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
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////////////
-//     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;
-}

+ 0 - 31
direct/src/task/cTask.cxx

@@ -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
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-
-#include "cTask.h"
-
-TypeHandle CTask::_type_handle;
-
-CTask::
-CTask() {
-  _wake_time = 0.0;
-}
-
-CTask::
-~CTask() {
-}

+ 0 - 59
direct/src/task/cTask.h

@@ -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
-// [email protected] .
-//
-////////////////////////////////////////////////////////////////////
-
-
-#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