formatting

This commit is contained in:
Dave Schuyler 2006-03-24 00:36:55 +00:00
parent 6e9bab7195
commit 19de130ffd
5 changed files with 75 additions and 48 deletions

View File

@ -96,7 +96,8 @@ class ClockDelta(DirectObject.DirectObject):
timeDelta is equal to the amount of time, in seconds, timeDelta is equal to the amount of time, in seconds,
that has been added to the global clock that has been added to the global clock
""" """
assert self.notify.debug("adjusting timebase by %f seconds" % timeDelta) assert self.notify.debug(
"adjusting timebase by %f seconds" % timeDelta)
# adjust our timebase by the same amount # adjust our timebase by the same amount
self.delta += timeDelta self.delta += timeDelta
@ -119,8 +120,9 @@ class ClockDelta(DirectObject.DirectObject):
delta accordingly. delta accordingly.
""" """
newDelta = (float(localTime) - newDelta = (float(localTime) -
(float(networkTime) / NetworkTimePrecision)) (float(networkTime) / NetworkTimePrecision))
self.newDelta(localTime, newDelta, newUncertainty, trustNew = trustNew) self.newDelta(
localTime, newDelta, newUncertainty, trustNew = trustNew)
def peerToPeerResync(self, avId, timestamp, serverTime, uncertainty): def peerToPeerResync(self, avId, timestamp, serverTime, uncertainty):
""" """
@ -142,7 +144,9 @@ class ClockDelta(DirectObject.DirectObject):
# of some other request, and our local timestamp may have # of some other request, and our local timestamp may have
# been resynced since then: ergo, the timestamp in this # been resynced since then: ergo, the timestamp in this
# request is meaningless. # request is meaningless.
assert self.notify.debug("Ignoring request for resync from %s within %.3f s." % (avId, now - self.lastResync)) assert self.notify.debug(
"Ignoring request for resync from %s within %.3f s." %
(avId, now - self.lastResync))
return -1 return -1
# The timestamp value will be a timestamp that we sent out # The timestamp value will be a timestamp that we sent out
@ -160,13 +164,16 @@ class ClockDelta(DirectObject.DirectObject):
# P2PResyncDelay. If it does not meet these requirements, # P2PResyncDelay. If it does not meet these requirements,
# it must be very old indeed, or someone is playing tricks # it must be very old indeed, or someone is playing tricks
# on us. # on us.
self.notify.info("Ignoring old request for resync from %s." % (avId)) self.notify.info(
"Ignoring old request for resync from %s." % (avId))
else: else:
# Now the other client has told us his delta and uncertainty # Now the other client has told us his delta and uncertainty
# information, which was generated somewhere in the range # information, which was generated somewhere in the range
# [-elapsed, 0] seconds ago. That means our complete window # [-elapsed, 0] seconds ago. That means our complete window
# is wider by that amount. # is wider by that amount.
self.notify.info("Got sync +/- %.3f s, elapsed %.3f s, from %s." % (uncertainty, elapsed, avId)) self.notify.info(
"Got sync +/- %.3f s, elapsed %.3f s, from %s." %
(uncertainty, elapsed, avId))
delta -= elapsed / 2.0 delta -= elapsed / 2.0
uncertainty += elapsed / 2.0 uncertainty += elapsed / 2.0
@ -184,8 +191,12 @@ class ClockDelta(DirectObject.DirectObject):
""" """
oldUncertainty = self.getUncertainty() oldUncertainty = self.getUncertainty()
if oldUncertainty != None: if oldUncertainty != None:
self.notify.info('previous delta at %.3f s, +/- %.3f s.' % (self.delta, oldUncertainty)) self.notify.info(
self.notify.info('new delta at %.3f s, +/- %.3f s.' % (newDelta, newUncertainty)) 'previous delta at %.3f s, +/- %.3f s.' %
(self.delta, oldUncertainty))
self.notify.info(
'new delta at %.3f s, +/- %.3f s.' %
(newDelta, newUncertainty))
# Our previous measurement was self.delta +/- oldUncertainty; # Our previous measurement was self.delta +/- oldUncertainty;
# our new measurement is newDelta +/- newUncertainty. Take # our new measurement is newDelta +/- newUncertainty. Take
# the intersection of both. # the intersection of both.
@ -209,7 +220,9 @@ class ClockDelta(DirectObject.DirectObject):
else: else:
newDelta = (low + high) / 2.0 newDelta = (low + high) / 2.0
newUncertainty = (high - low) / 2.0 newUncertainty = (high - low) / 2.0
self.notify.info('intersection at %.3f s, +/- %.3f s.' % (newDelta, newUncertainty)) self.notify.info(
'intersection at %.3f s, +/- %.3f s.' %
(newDelta, newUncertainty))
self.delta = newDelta self.delta = newDelta
self.uncertainty = newUncertainty self.uncertainty = newUncertainty
@ -261,7 +274,6 @@ class ClockDelta(DirectObject.DirectObject):
ntime = int(math.floor(((localTime - self.delta) * ticksPerSec) + 0.5)) ntime = int(math.floor(((localTime - self.delta) * ticksPerSec) + 0.5))
if bits == 16: if bits == 16:
return self.__signExtend(ntime) return self.__signExtend(ntime)
else: else:
# Assume the bits is either 16 or 32. If it's 32, no need # Assume the bits is either 16 or 32. If it's 32, no need
# to sign-extend. 32 bits gives us about 227 days of # to sign-extend. 32 bits gives us about 227 days of

View File

@ -39,7 +39,6 @@ public:
virtual void add_entry(CollisionEntry *entry); virtual void add_entry(CollisionEntry *entry);
virtual bool end_group(); virtual bool end_group();
PUBLISHED: PUBLISHED:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {
return _type_handle; return _type_handle;

View File

@ -40,7 +40,9 @@ PUBLISHED:
protected: protected:
virtual bool handle_entries(); virtual bool handle_entries();
virtual void apply_net_shove(ColliderDef &def, const LVector3f &net_shove, const LVector3f &force_normal); virtual void apply_net_shove(
ColliderDef &def, const LVector3f &net_shove,
const LVector3f &force_normal);
virtual void apply_linear_force(ColliderDef &def, const LVector3f &force); virtual void apply_linear_force(ColliderDef &def, const LVector3f &force);
private: private:

View File

@ -54,9 +54,9 @@ CollisionTraverser(const string &name) :
_this_pcollector(_collisions_pcollector, name) _this_pcollector(_collisions_pcollector, name)
{ {
_respect_prev_transform = respect_prev_transform; _respect_prev_transform = respect_prev_transform;
#ifdef DO_COLLISION_RECORDING #ifdef DO_COLLISION_RECORDING
_recorder = (CollisionRecorder *)NULL; _recorder = (CollisionRecorder *)NULL;
#endif #endif
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -66,9 +66,9 @@ CollisionTraverser(const string &name) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
CollisionTraverser:: CollisionTraverser::
~CollisionTraverser() { ~CollisionTraverser() {
#ifdef DO_COLLISION_RECORDING #ifdef DO_COLLISION_RECORDING
clear_recorder(); clear_recorder();
#endif #endif
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -256,11 +256,11 @@ void CollisionTraverser::
traverse(const NodePath &root) { traverse(const NodePath &root) {
PStatTimer timer(_this_pcollector); PStatTimer timer(_this_pcollector);
#ifdef DO_COLLISION_RECORDING #ifdef DO_COLLISION_RECORDING
if (has_recorder()) { if (has_recorder()) {
get_recorder()->begin_traversal(); get_recorder()->begin_traversal();
} }
#endif // DO_COLLISION_RECORDING #endif // DO_COLLISION_RECORDING
LevelStates level_states; LevelStates level_states;
prepare_colliders(level_states, root); prepare_colliders(level_states, root);
@ -273,9 +273,9 @@ traverse(const NodePath &root) {
// Make a number of passes, one for each group of 32 Colliders (or // Make a number of passes, one for each group of 32 Colliders (or
// whatever number of bits we have available in CurrentMask). // whatever number of bits we have available in CurrentMask).
for (size_t pass = 0; pass < level_states.size(); ++pass) { for (size_t pass = 0; pass < level_states.size(); ++pass) {
#ifdef DO_PSTATS #ifdef DO_PSTATS
PStatTimer pass_timer(get_pass_collector(pass)); PStatTimer pass_timer(get_pass_collector(pass));
#endif #endif
r_traverse(level_states[pass]); r_traverse(level_states[pass]);
} }
@ -289,11 +289,11 @@ traverse(const NodePath &root) {
} }
} }
#ifdef DO_COLLISION_RECORDING #ifdef DO_COLLISION_RECORDING
if (has_recorder()) { if (has_recorder()) {
get_recorder()->end_traversal(); get_recorder()->end_traversal();
} }
#endif // DO_COLLISION_RECORDING #endif // DO_COLLISION_RECORDING
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -436,7 +436,8 @@ write(ostream &out, int indent_level) const {
out << " ignored\n"; out << " ignored\n";
} }
if (!cnode_path.is_empty() && cnode_path.node()->is_of_type(CollisionNode::get_class_type())) { if (!cnode_path.is_empty() && cnode_path.node()->is_of_type(
CollisionNode::get_class_type())) {
CollisionNode *cnode = DCAST(CollisionNode, cnode_path.node()); CollisionNode *cnode = DCAST(CollisionNode, cnode_path.node());
int num_solids = cnode->get_num_solids(); int num_solids = cnode->get_num_solids();
@ -547,21 +548,22 @@ r_traverse(CollisionLevelState &level_state) {
entry._from_node_path = level_state.get_collider_node_path(c); entry._from_node_path = level_state.get_collider_node_path(c);
entry._from = level_state.get_collider(c); entry._from = level_state.get_collider(c);
compare_collider_to_node(entry, compare_collider_to_node(
level_state.get_parent_bound(c), entry,
level_state.get_local_bound(c), level_state.get_parent_bound(c),
node_gbv); level_state.get_local_bound(c),
node_gbv);
} }
} }
} }
} else if (node->is_geom_node()) { } else if (node->is_geom_node()) {
#ifndef NDEBUG #ifndef NDEBUG
if (collide_cat.is_spam()) { if (collide_cat.is_spam()) {
collide_cat.spam() collide_cat.spam()
<< "Reached " << *node << "\n"; << "Reached " << *node << "\n";
} }
#endif #endif
GeomNode *gnode; GeomNode *gnode;
DCAST_INTO_V(gnode, node); DCAST_INTO_V(gnode, node);
@ -588,10 +590,11 @@ r_traverse(CollisionLevelState &level_state) {
entry._from_node_path = level_state.get_collider_node_path(c); entry._from_node_path = level_state.get_collider_node_path(c);
entry._from = level_state.get_collider(c); entry._from = level_state.get_collider(c);
compare_collider_to_geom_node(entry, compare_collider_to_geom_node(
level_state.get_parent_bound(c), entry,
level_state.get_local_bound(c), level_state.get_parent_bound(c),
node_gbv); level_state.get_local_bound(c),
node_gbv);
} }
} }
} }
@ -618,7 +621,8 @@ r_traverse(CollisionLevelState &level_state) {
for (int i = 0; i < num_children; ++i) { for (int i = 0; i < num_children; ++i) {
CollisionLevelState next_state(level_state, node->get_child(i)); CollisionLevelState next_state(level_state, node->get_child(i));
if (i != index) { if (i != index) {
next_state.set_include_mask(next_state.get_include_mask() & ~GeomNode::get_default_collide_mask()); next_state.set_include_mask(next_state.get_include_mask() &
~GeomNode::get_default_collide_mask());
} }
r_traverse(next_state); r_traverse(next_state);
} }
@ -731,9 +735,9 @@ compare_collider_to_solid(CollisionEntry &entry,
if (from_node_gbv != (GeometricBoundingVolume *)NULL && if (from_node_gbv != (GeometricBoundingVolume *)NULL &&
solid_gbv != (GeometricBoundingVolume *)NULL) { solid_gbv != (GeometricBoundingVolume *)NULL) {
within_solid_bounds = (solid_gbv->contains(from_node_gbv) != 0); within_solid_bounds = (solid_gbv->contains(from_node_gbv) != 0);
#ifdef DO_PSTATS #ifdef DO_PSTATS
((CollisionSolid *)entry.get_into())->get_volume_pcollector().add_level(1); ((CollisionSolid *)entry.get_into())->get_volume_pcollector().add_level(1);
#endif // DO_PSTATS #endif // DO_PSTATS
} }
if (within_solid_bounds) { if (within_solid_bounds) {
Colliders::const_iterator ci; Colliders::const_iterator ci;
@ -793,9 +797,9 @@ compare_collider_to_geom(CollisionEntry &entry, const Geom *geom,
PT(BoundingSphere) sphere = new BoundingSphere; PT(BoundingSphere) sphere = new BoundingSphere;
sphere->around(v, v + 3); sphere->around(v, v + 3);
within_solid_bounds = (sphere->contains(from_node_gbv) != 0); within_solid_bounds = (sphere->contains(from_node_gbv) != 0);
#ifdef DO_PSTATS #ifdef DO_PSTATS
CollisionGeom::_volume_pcollector.add_level(1); CollisionGeom::_volume_pcollector.add_level(1);
#endif // DO_PSTATS #endif // DO_PSTATS
} }
if (within_solid_bounds) { if (within_solid_bounds) {
PT(CollisionGeom) cgeom = new CollisionGeom(v[0], v[1], v[2]); PT(CollisionGeom) cgeom = new CollisionGeom(v[0], v[1], v[2]);

View File

@ -92,6 +92,7 @@ apply_friction(ColliderDef &def, LVector3f& vel, const LVector3f& force,
void PhysicsCollisionHandler:: void PhysicsCollisionHandler::
apply_linear_force(ColliderDef &def, const LVector3f &force) { apply_linear_force(ColliderDef &def, const LVector3f &force) {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PhysicsCollisionHandler::apply_net_shove // Function: PhysicsCollisionHandler::apply_net_shove
// Access: Protected, Virtual // Access: Protected, Virtual
@ -122,18 +123,22 @@ apply_net_shove(ColliderDef &def, const LVector3f& net_shove,
// Copy the force vector while translating it // Copy the force vector while translating it
// into the physics object coordinate system: // into the physics object coordinate system:
LVector3f adjustment=force; LVector3f adjustment=force;
physics_debug(" adjustment set "<<adjustment<<" len "<<adjustment.length()); physics_debug(
" adjustment set "<<adjustment<<" len "<<adjustment.length());
//NodePath np(def._node); //NodePath np(def._node);
//CPT(TransformState) trans = np.get_net_transform(); //CPT(TransformState) trans = np.get_net_transform();
//adjustment=adjustment*trans->get_mat(); //adjustment=adjustment*trans->get_mat();
//physics_debug(" adjustment trn "<<adjustment<<" len "<<adjustment.length()); //physics_debug(
// " adjustment trn "<<adjustment<<" len "<<adjustment.length());
adjustment=adjustment*actor->get_physics_object()->get_lcs(); adjustment=adjustment*actor->get_physics_object()->get_lcs();
physics_debug(" adjustment lcs "<<adjustment<<" len "<<adjustment.length()); physics_debug(
" adjustment lcs "<<adjustment<<" len "<<adjustment.length());
adjustment.normalize(); adjustment.normalize();
physics_debug(" adjustment nrm "<<adjustment<<" len "<<adjustment.length()); physics_debug(
" adjustment nrm "<<adjustment<<" len "<<adjustment.length());
float adjustmentLength=-(adjustment.dot(vel)); float adjustmentLength=-(adjustment.dot(vel));
physics_debug(" adjustmentLength "<<adjustmentLength); physics_debug(" adjustmentLength "<<adjustmentLength);
@ -145,11 +150,12 @@ apply_net_shove(ColliderDef &def, const LVector3f& net_shove,
#if 0 #if 0
cerr<<"vel "<<vel<<endl; cerr<<"vel "<<vel<<endl;
cerr<<"net_shove "<<net_shove<<endl; cerr<<"net_shove "<<net_shove<<endl;
cerr<<"-force "<<-force<<endl; cerr<<"force "<<force<<endl;
actor->get_physics_object()->add_impact(-force, -vel); actor->get_physics_object()->add_impact(force, -vel);
#else #else
adjustment*=adjustmentLength; adjustment*=adjustmentLength;
physics_debug(" adjustment mul "<<adjustment<<" len "<<adjustment.length()); physics_debug(
" adjustment mul "<<adjustment<<" len "<<adjustment.length());
// This adjustment to our velocity will not reflect us off the surface, // This adjustment to our velocity will not reflect us off the surface,
// but will deflect us parallel (or tangent) to the surface: // but will deflect us parallel (or tangent) to the surface:
@ -167,13 +173,17 @@ apply_net_shove(ColliderDef &def, const LVector3f& net_shove,
#ifndef NDEBUG //[ #ifndef NDEBUG //[
if (IS_THRESHOLD_EQUAL(vel.length(), old_vel.length(), 0.0001f)) { if (IS_THRESHOLD_EQUAL(vel.length(), old_vel.length(), 0.0001f)) {
// This is a check to see if vel is staying the same: // This is a check to see if vel is staying the same:
physics_debug(" vel is about the same length: "<<vel.length()<<" ~ "<<old_vel.length()); physics_debug(
" vel is about the same length: "
<<vel.length()<<" ~ "<<old_vel.length());
} else if (vel.length() > old_vel.length()) { } else if (vel.length() > old_vel.length()) {
// This is a check to avoid adding engergy: // This is a check to avoid adding engergy:
physics_debug(" vel got larger "<<vel.length()<<" > "<<old_vel.length()); physics_debug(
" vel got larger "<<vel.length()<<" > "<<old_vel.length());
} else { } else {
// This is a check to avoid losing engergy: // This is a check to avoid losing engergy:
physics_debug(" vel got smaller "<<vel.length()<<" < "<<old_vel.length()); physics_debug(
" vel got smaller "<<vel.length()<<" < "<<old_vel.length());
} }
if (vel.length() > 10.0f) { if (vel.length() > 10.0f) {
// This is a check to see if the velocity is higher than I expect it // This is a check to see if the velocity is higher than I expect it