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,
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
self.delta += timeDelta
@ -120,7 +121,8 @@ class ClockDelta(DirectObject.DirectObject):
"""
newDelta = (float(localTime) -
(float(networkTime) / NetworkTimePrecision))
self.newDelta(localTime, newDelta, newUncertainty, trustNew = trustNew)
self.newDelta(
localTime, newDelta, newUncertainty, trustNew = trustNew)
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
# been resynced since then: ergo, the timestamp in this
# 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
# 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,
# it must be very old indeed, or someone is playing tricks
# 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:
# Now the other client has told us his delta and uncertainty
# information, which was generated somewhere in the range
# [-elapsed, 0] seconds ago. That means our complete window
# 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
uncertainty += elapsed / 2.0
@ -184,8 +191,12 @@ class ClockDelta(DirectObject.DirectObject):
"""
oldUncertainty = self.getUncertainty()
if oldUncertainty != None:
self.notify.info('previous delta at %.3f s, +/- %.3f s.' % (self.delta, oldUncertainty))
self.notify.info('new delta at %.3f s, +/- %.3f s.' % (newDelta, newUncertainty))
self.notify.info(
'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 new measurement is newDelta +/- newUncertainty. Take
# the intersection of both.
@ -209,7 +220,9 @@ class ClockDelta(DirectObject.DirectObject):
else:
newDelta = (low + high) / 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.uncertainty = newUncertainty
@ -261,7 +274,6 @@ class ClockDelta(DirectObject.DirectObject):
ntime = int(math.floor(((localTime - self.delta) * ticksPerSec) + 0.5))
if bits == 16:
return self.__signExtend(ntime)
else:
# 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

View File

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

View File

@ -40,7 +40,9 @@ PUBLISHED:
protected:
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);
private:

View File

@ -54,9 +54,9 @@ CollisionTraverser(const string &name) :
_this_pcollector(_collisions_pcollector, name)
{
_respect_prev_transform = respect_prev_transform;
#ifdef DO_COLLISION_RECORDING
#ifdef DO_COLLISION_RECORDING
_recorder = (CollisionRecorder *)NULL;
#endif
#endif
}
////////////////////////////////////////////////////////////////////
@ -66,9 +66,9 @@ CollisionTraverser(const string &name) :
////////////////////////////////////////////////////////////////////
CollisionTraverser::
~CollisionTraverser() {
#ifdef DO_COLLISION_RECORDING
#ifdef DO_COLLISION_RECORDING
clear_recorder();
#endif
#endif
}
////////////////////////////////////////////////////////////////////
@ -256,11 +256,11 @@ void CollisionTraverser::
traverse(const NodePath &root) {
PStatTimer timer(_this_pcollector);
#ifdef DO_COLLISION_RECORDING
#ifdef DO_COLLISION_RECORDING
if (has_recorder()) {
get_recorder()->begin_traversal();
}
#endif // DO_COLLISION_RECORDING
#endif // DO_COLLISION_RECORDING
LevelStates level_states;
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
// whatever number of bits we have available in CurrentMask).
for (size_t pass = 0; pass < level_states.size(); ++pass) {
#ifdef DO_PSTATS
#ifdef DO_PSTATS
PStatTimer pass_timer(get_pass_collector(pass));
#endif
#endif
r_traverse(level_states[pass]);
}
@ -289,11 +289,11 @@ traverse(const NodePath &root) {
}
}
#ifdef DO_COLLISION_RECORDING
#ifdef DO_COLLISION_RECORDING
if (has_recorder()) {
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";
}
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());
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 = level_state.get_collider(c);
compare_collider_to_node(entry,
compare_collider_to_node(
entry,
level_state.get_parent_bound(c),
level_state.get_local_bound(c),
node_gbv);
@ -556,12 +558,12 @@ r_traverse(CollisionLevelState &level_state) {
}
} else if (node->is_geom_node()) {
#ifndef NDEBUG
#ifndef NDEBUG
if (collide_cat.is_spam()) {
collide_cat.spam()
<< "Reached " << *node << "\n";
}
#endif
#endif
GeomNode *gnode;
DCAST_INTO_V(gnode, node);
@ -588,7 +590,8 @@ r_traverse(CollisionLevelState &level_state) {
entry._from_node_path = level_state.get_collider_node_path(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_local_bound(c),
node_gbv);
@ -618,7 +621,8 @@ r_traverse(CollisionLevelState &level_state) {
for (int i = 0; i < num_children; ++i) {
CollisionLevelState next_state(level_state, node->get_child(i));
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);
}
@ -731,9 +735,9 @@ compare_collider_to_solid(CollisionEntry &entry,
if (from_node_gbv != (GeometricBoundingVolume *)NULL &&
solid_gbv != (GeometricBoundingVolume *)NULL) {
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);
#endif // DO_PSTATS
#endif // DO_PSTATS
}
if (within_solid_bounds) {
Colliders::const_iterator ci;
@ -793,9 +797,9 @@ compare_collider_to_geom(CollisionEntry &entry, const Geom *geom,
PT(BoundingSphere) sphere = new BoundingSphere;
sphere->around(v, v + 3);
within_solid_bounds = (sphere->contains(from_node_gbv) != 0);
#ifdef DO_PSTATS
#ifdef DO_PSTATS
CollisionGeom::_volume_pcollector.add_level(1);
#endif // DO_PSTATS
#endif // DO_PSTATS
}
if (within_solid_bounds) {
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::
apply_linear_force(ColliderDef &def, const LVector3f &force) {
}
////////////////////////////////////////////////////////////////////
// Function: PhysicsCollisionHandler::apply_net_shove
// Access: Protected, Virtual
@ -122,18 +123,22 @@ apply_net_shove(ColliderDef &def, const LVector3f& net_shove,
// Copy the force vector while translating it
// into the physics object coordinate system:
LVector3f adjustment=force;
physics_debug(" adjustment set "<<adjustment<<" len "<<adjustment.length());
physics_debug(
" adjustment set "<<adjustment<<" len "<<adjustment.length());
//NodePath np(def._node);
//CPT(TransformState) trans = np.get_net_transform();
//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();
physics_debug(" adjustment lcs "<<adjustment<<" len "<<adjustment.length());
physics_debug(
" adjustment lcs "<<adjustment<<" len "<<adjustment.length());
adjustment.normalize();
physics_debug(" adjustment nrm "<<adjustment<<" len "<<adjustment.length());
physics_debug(
" adjustment nrm "<<adjustment<<" len "<<adjustment.length());
float adjustmentLength=-(adjustment.dot(vel));
physics_debug(" adjustmentLength "<<adjustmentLength);
@ -145,11 +150,12 @@ apply_net_shove(ColliderDef &def, const LVector3f& net_shove,
#if 0
cerr<<"vel "<<vel<<endl;
cerr<<"net_shove "<<net_shove<<endl;
cerr<<"-force "<<-force<<endl;
actor->get_physics_object()->add_impact(-force, -vel);
cerr<<"force "<<force<<endl;
actor->get_physics_object()->add_impact(force, -vel);
#else
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,
// 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 //[
if (IS_THRESHOLD_EQUAL(vel.length(), old_vel.length(), 0.0001f)) {
// 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()) {
// 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 {
// 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) {
// This is a check to see if the velocity is higher than I expect it