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
@ -120,7 +121,8 @@ class ClockDelta(DirectObject.DirectObject):
""" """
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

@ -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,7 +548,8 @@ 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(
entry,
level_state.get_parent_bound(c), level_state.get_parent_bound(c),
level_state.get_local_bound(c), level_state.get_local_bound(c),
node_gbv); node_gbv);
@ -588,7 +590,8 @@ 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(
entry,
level_state.get_parent_bound(c), level_state.get_parent_bound(c),
level_state.get_local_bound(c), level_state.get_local_bound(c),
node_gbv); 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);
} }

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