mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
use self.wakeTime instead of cTask object
This commit is contained in:
parent
44aa13cb4c
commit
735c45d8b4
@ -8,7 +8,7 @@
|
|||||||
#define BUILDING_DLL BUILDING_DIRECT
|
#define BUILDING_DLL BUILDING_DIRECT
|
||||||
|
|
||||||
#define COMPONENT_LIBS \
|
#define COMPONENT_LIBS \
|
||||||
directbase dcparser showbase deadrec directd interval distributed task
|
directbase dcparser showbase deadrec directd interval distributed
|
||||||
|
|
||||||
#define OTHER_LIBS \
|
#define OTHER_LIBS \
|
||||||
panda:m \
|
panda:m \
|
||||||
|
@ -14,9 +14,6 @@
|
|||||||
#begin metalib_target
|
#begin metalib_target
|
||||||
#define TARGET heapq
|
#define TARGET heapq
|
||||||
|
|
||||||
#define LOCAL_LIBS \
|
|
||||||
task
|
|
||||||
|
|
||||||
#define SOURCES heapq.cxx
|
#define SOURCES heapq.cxx
|
||||||
#end metalib_target
|
#end metalib_target
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "cTask.h"
|
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
static PyObject * heappush(PyObject *self, PyObject *args);
|
static PyObject * heappush(PyObject *self, PyObject *args);
|
||||||
@ -129,10 +128,12 @@ _siftdown(PyObject *list, int startpos, int pos) {
|
|||||||
|
|
||||||
newitem = PySequence_GetItem(list,pos);
|
newitem = PySequence_GetItem(list,pos);
|
||||||
|
|
||||||
PyObject *newitemCTask_this = PyObject_GetAttrString(newitem, "this");
|
PyObject *newitem_wakeTime_obj = PyObject_GetAttrString(newitem, "wakeTime");
|
||||||
nassertr(newitemCTask_this != NULL, false);
|
double newitem_wakeTime = 0.0;
|
||||||
CTask *newitemCTask = (CTask *)PyInt_AsLong(newitemCTask_this);
|
if (newitem_wakeTime_obj != NULL) {
|
||||||
Py_DECREF(newitemCTask_this);
|
newitem_wakeTime = PyFloat_AS_DOUBLE(newitem_wakeTime_obj);
|
||||||
|
Py_DECREF(newitem_wakeTime_obj);
|
||||||
|
}
|
||||||
|
|
||||||
while (pos > startpos) {
|
while (pos > startpos) {
|
||||||
parentpos = (pos - 1) >> 1;
|
parentpos = (pos - 1) >> 1;
|
||||||
@ -146,12 +147,14 @@ _siftdown(PyObject *list, int startpos, int pos) {
|
|||||||
return -1;
|
return -1;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PyObject *parentCTask_this = PyObject_GetAttrString(parent, "this");
|
PyObject *parent_wakeTime_obj = PyObject_GetAttrString(parent, "wakeTime");
|
||||||
nassertr(parentCTask_this != NULL, false);
|
double parent_wakeTime = 0.0;
|
||||||
CTask *parentCTask = (CTask *)PyInt_AsLong(parentCTask_this);
|
if (parent_wakeTime_obj != NULL) {
|
||||||
Py_DECREF(parentCTask_this);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,19 +180,23 @@ _siftup(PyObject *list, int pos) {
|
|||||||
rightpos = childpos + 1;
|
rightpos = childpos + 1;
|
||||||
child = PySequence_Fast_GET_ITEM(list,childpos);
|
child = PySequence_Fast_GET_ITEM(list,childpos);
|
||||||
|
|
||||||
PyObject *childCTask_this = PyObject_GetAttrString(child, "this");
|
PyObject *child_wakeTime_obj = PyObject_GetAttrString(child, "wakeTime");
|
||||||
nassertr(childCTask_this != NULL, false);
|
double child_wakeTime = 0.0;
|
||||||
CTask *childCTask = (CTask *)PyInt_AsLong(childCTask_this);
|
if (child_wakeTime_obj != NULL) {
|
||||||
Py_DECREF(childCTask_this);
|
child_wakeTime = PyFloat_AS_DOUBLE(child_wakeTime_obj);
|
||||||
|
Py_DECREF(child_wakeTime_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (rightpos < endpos) {
|
if (rightpos < endpos) {
|
||||||
right = PySequence_Fast_GET_ITEM(list,rightpos);
|
right = PySequence_Fast_GET_ITEM(list,rightpos);
|
||||||
|
|
||||||
PyObject *rightCTask_this = PyObject_GetAttrString(right, "this");
|
PyObject *right_wakeTime_obj = PyObject_GetAttrString(right, "wakeTime");
|
||||||
nassertr(rightCTask_this != NULL, false);
|
double right_wakeTime = 0.0;
|
||||||
CTask *rightCTask = (CTask *)PyInt_AsLong(rightCTask_this);
|
if (right_wakeTime_obj != NULL) {
|
||||||
Py_DECREF(rightCTask_this);
|
right_wakeTime = PyFloat_AS_DOUBLE(right_wakeTime_obj);
|
||||||
|
Py_DECREF(right_wakeTime_obj);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
cmp = PyObject_RichCompareBool(right,child,Py_LE);
|
cmp = PyObject_RichCompareBool(right,child,Py_LE);
|
||||||
@ -199,7 +206,7 @@ _siftup(PyObject *list, int pos) {
|
|||||||
return -1;
|
return -1;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (rightCTask->get_wake_time() <= childCTask->get_wake_time()) {
|
if (right_wakeTime <= child_wakeTime) {
|
||||||
childpos = rightpos;
|
childpos = rightpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
@ -5,8 +5,7 @@
|
|||||||
# subset of PandaModules that we know is available immediately.
|
# subset of PandaModules that we know is available immediately.
|
||||||
# Methods that require more advanced C++ methods may import the
|
# Methods that require more advanced C++ methods may import the
|
||||||
# appropriate files within their own scope.
|
# appropriate files within their own scope.
|
||||||
# from pandac.libpandaexpressModules import *
|
from pandac.libpandaexpressModules import *
|
||||||
from pandac.libdirectModules import *
|
|
||||||
|
|
||||||
from direct.directnotify.DirectNotifyGlobal import *
|
from direct.directnotify.DirectNotifyGlobal import *
|
||||||
from direct.showbase.PythonUtil import *
|
from direct.showbase.PythonUtil import *
|
||||||
@ -64,14 +63,9 @@ def print_exc_plus():
|
|||||||
except:
|
except:
|
||||||
print "<ERROR WHILE PRINTING VALUE>"
|
print "<ERROR WHILE PRINTING VALUE>"
|
||||||
|
|
||||||
# Here we inherit from CTask so that we can drop the expensive work
|
class Task:
|
||||||
# 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):
|
|
||||||
count = 0
|
count = 0
|
||||||
def __init__(self, callback, priority = 0):
|
def __init__(self, callback, priority = 0):
|
||||||
CTask.__init__(self)
|
|
||||||
# Unique ID for each task
|
# Unique ID for each task
|
||||||
self.id = Task.count
|
self.id = Task.count
|
||||||
Task.count += 1
|
Task.count += 1
|
||||||
@ -85,14 +79,16 @@ class Task(CTask):
|
|||||||
self.runningTotal = 0.0
|
self.runningTotal = 0.0
|
||||||
self.pstats = None
|
self.pstats = None
|
||||||
self.extraArgs = None
|
self.extraArgs = None
|
||||||
|
# Used for doLaters
|
||||||
|
self.wakeTime = 0.0
|
||||||
|
|
||||||
# # Used for putting into the doLaterList
|
# # Used for putting into the doLaterList
|
||||||
# # the heapq calls __cmp__ via the rich compare function
|
# # the heapq calls __cmp__ via the rich compare function
|
||||||
# def __cmp__(self, other):
|
# def __cmp__(self, other):
|
||||||
# if isinstance(other, Task):
|
# if isinstance(other, Task):
|
||||||
# if self.getWakeTime() < other.getWakeTime():
|
# if self.wakeTime < other.wakeTime:
|
||||||
# return -1
|
# return -1
|
||||||
# elif self.getWakeTime() > other.getWakeTime():
|
# elif self.wakeTime > other.wakeTime:
|
||||||
# return 1
|
# return 1
|
||||||
# # If the wakeTimes happen to be the same, just
|
# # If the wakeTimes happen to be the same, just
|
||||||
# # sort them based on id
|
# # sort them based on id
|
||||||
@ -390,7 +386,7 @@ class TaskManager:
|
|||||||
continue
|
continue
|
||||||
# If the time now is less than the start of the doLater + delay
|
# If the time now is less than the start of the doLater + delay
|
||||||
# then we are not ready yet, continue to next one
|
# 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
|
# Since the list is sorted, the first one we get to, that
|
||||||
# is not ready to go, we can return
|
# is not ready to go, we can return
|
||||||
break
|
break
|
||||||
@ -427,7 +423,7 @@ class TaskManager:
|
|||||||
# have been synced since the start of this frame
|
# have been synced since the start of this frame
|
||||||
currentTime = globalClock.getFrameTime()
|
currentTime = globalClock.getFrameTime()
|
||||||
# Cache the time we should wake up for easier sorting
|
# 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.
|
# Push this onto the doLaterList. The heap maintains the sorting.
|
||||||
heappush(self.__doLaterList, task)
|
heappush(self.__doLaterList, task)
|
||||||
if self.fVerbose:
|
if self.fVerbose:
|
||||||
@ -854,10 +850,10 @@ class TaskManager:
|
|||||||
# The priority heap is not actually in order - it is a tree
|
# The priority heap is not actually in order - it is a tree
|
||||||
# Make a shallow copy so we can sort it
|
# Make a shallow copy so we can sort it
|
||||||
sortedDoLaterList = self.__doLaterList[:]
|
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()
|
sortedDoLaterList.reverse()
|
||||||
for task in sortedDoLaterList:
|
for task in sortedDoLaterList:
|
||||||
remainingTime = ((task.getWakeTime()) - self.currentTime)
|
remainingTime = ((task.wakeTime) - self.currentTime)
|
||||||
if task.isRemoved():
|
if task.isRemoved():
|
||||||
taskName = '(R)' + task.name
|
taskName = '(R)' + task.name
|
||||||
else:
|
else:
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -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() {
|
|
||||||
}
|
|
@ -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
|
|
Loading…
x
Reference in New Issue
Block a user