fix distributed treasure, donald's boat

This commit is contained in:
David Rose 2002-08-29 22:36:54 +00:00
parent 045688d305
commit e735658356
3 changed files with 161 additions and 11 deletions

View File

@ -169,16 +169,7 @@ class MetaInterval(CMetaInterval):
def addInterval(self, ival, relTime, relTo):
# Adds the given interval to the MetaInterval.
if isinstance(ival, MetaInterval):
# It's another MetaInterval, so copy in its intervals
# directly to this object. We could just store the
# MetaInterval itself, which would work, but we get a
# performance advantage by flattening out the deeply
# nested hierarchy into a linear list within the root
# CMetaInterval object.
ival.applyIvals(self, relTime, relTo)
elif isinstance(ival, CInterval):
if isinstance(ival, CInterval):
# It's a C++-style Interval, so add it directly.
if getattr(ival, "inPython", 0):
# Actually, it's been flagged to run in Python, even
@ -190,10 +181,20 @@ class MetaInterval(CMetaInterval):
self.pythonIvals.append(ival)
self.addExtIndex(index, ival.getName(), ival.getDuration(),
ival.getOpenEnded(), relTime, relTo)
elif isinstance(ival, MetaInterval):
# It's another MetaInterval, so copy in its intervals
# directly to this object. We could just store the
# MetaInterval itself, which would work, but we get a
# performance advantage by flattening out the deeply
# nested hierarchy into a linear list within the root
# CMetaInterval object.
ival.applyIvals(self, relTime, relTo)
else:
# Nope, a perfectly ordinary C++ interval. Hooray!
self.addCInterval(ival, relTime, relTo)
elif isinstance(ival, Interval.Interval):
# It's a Python-style Interval, so add it as an external.
index = len(self.pythonIvals)
@ -315,6 +316,26 @@ class MetaInterval(CMetaInterval):
CMetaInterval.setFinalT(self)
self.__doPythonCallbacks()
def setIntervalStartTime(self, *args, **kw):
# This function overrides from the parent level to force it to
# update the interval list first, if necessary.
self.__updateIvals()
# Once we have monkeyed with the interval timings, we'd better
# run the whole thing as a monolithic Python interval, since
# we can't extract the ivals list back out and append them
# into a parent MetaInterval.
self.inPython = 1
return CMetaInterval.setIntervalStartTime(self, *args, **kw)
def getIntervalStartTime(self, *args, **kw):
# This function overrides from the parent level to force it to
# update the interval list first, if necessary.
self.__updateIvals()
return CMetaInterval.getIntervalStartTime(self, *args, **kw)
def getDuration(self):
# This function overrides from the parent level to force it to
# update the interval list first, if necessary.

View File

@ -196,6 +196,130 @@ pop_level() {
return (int)_defs.size() - 1;
}
////////////////////////////////////////////////////////////////////
// Function: CMetaInterval::set_interval_start_time
// Access: Published
// Description: Adjusts the start time of the child interval with the
// given name, if found. This may be either a C++
// interval added via add_c_interval(), or an external
// interval added via add_ext_index(); the name must
// match exactly.
//
// If the interval is found, its start time is adjusted,
// and all subsequent intervals are adjusting
// accordingly, and true is returned. If a matching
// interval is not found, nothing is changed and false
// is returned.
////////////////////////////////////////////////////////////////////
bool CMetaInterval::
set_interval_start_time(const string &name, double rel_time,
CMetaInterval::RelativeStart rel_to) {
Defs::iterator di;
for (di = _defs.begin(); di != _defs.end(); ++di) {
IntervalDef &def = (*di);
bool match = false;
switch (def._type) {
case DT_c_interval:
match = (def._c_interval->get_name() == name);
break;
case DT_ext_index:
match = (def._ext_name == name);
break;
default:
break;
}
if (match) {
// Here's the interval.
def._rel_time = rel_time;
def._rel_to = rel_to;
mark_dirty();
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: CMetaInterval::get_interval_start_time
// Access: Published
// Description: Returns the actual start time, relative to the
// beginning of the interval, of the child interval with
// the given name, if found, or -1 if the interval is
// not found.
////////////////////////////////////////////////////////////////////
double CMetaInterval::
get_interval_start_time(const string &name) const {
recompute();
Defs::const_iterator di;
for (di = _defs.begin(); di != _defs.end(); ++di) {
const IntervalDef &def = (*di);
bool match = false;
switch (def._type) {
case DT_c_interval:
match = (def._c_interval->get_name() == name);
break;
case DT_ext_index:
match = (def._ext_name == name);
break;
default:
break;
}
if (match) {
// Here's the interval.
return int_to_double_time(def._actual_begin_time);
}
}
return -1.0;
}
////////////////////////////////////////////////////////////////////
// Function: CMetaInterval::get_interval_end_time
// Access: Published
// Description: Returns the actual end time, relative to the
// beginning of the interval, of the child interval with
// the given name, if found, or -1 if the interval is
// not found.
////////////////////////////////////////////////////////////////////
double CMetaInterval::
get_interval_end_time(const string &name) const {
recompute();
Defs::const_iterator di;
for (di = _defs.begin(); di != _defs.end(); ++di) {
const IntervalDef &def = (*di);
bool match = false;
double duration = 0.0;
switch (def._type) {
case DT_c_interval:
duration = def._c_interval->get_duration();
match = (def._c_interval->get_name() == name);
break;
case DT_ext_index:
duration = def._ext_duration;
match = (def._ext_name == name);
break;
default:
break;
}
if (match) {
// Here's the interval.
return int_to_double_time(def._actual_begin_time) + duration;
}
}
return -1.0;
}
////////////////////////////////////////////////////////////////////
// Function: CMetaInterval::initialize
// Access: Published, Virtual

View File

@ -57,6 +57,11 @@ PUBLISHED:
double rel_time, RelativeStart rel_to);
int pop_level();
bool set_interval_start_time(const string &name, double rel_time,
RelativeStart rel_to = RS_level_begin);
double get_interval_start_time(const string &name) const;
double get_interval_end_time(const string &name) const;
enum DefType {
DT_c_interval,
DT_ext_index,