Browse Source

Merge with master commit

Ivan Safrin 12 years ago
parent
commit
ddd80c87db

+ 15 - 10
Core/Contents/Source/PolyPeer.cpp

@@ -27,11 +27,14 @@ THE SOFTWARE.
 
 
 using namespace Polycode;
 using namespace Polycode;
 
 
-void PeerConnection::ackPackets(unsigned int ack) {
-	for(int i=0; i < reliablePacketQueue.size(); i++) {
-		if(reliablePacketQueue[i].packet->header.sequence == ack) {
-			delete reliablePacketQueue[i].packet;
-			reliablePacketQueue.erase(reliablePacketQueue.begin()+i);
+void PeerConnection::ackPackets(unsigned int ack) {	
+	std::vector<SentPacketEntry>::iterator it;	
+	for(it = reliablePacketQueue.begin(); it != reliablePacketQueue.end();) {
+		if((*it).packet->header.sequence == ack) {
+			delete (*it).packet;
+			it = reliablePacketQueue.erase(it);
+		} else {
+			++it;
 		}
 		}
 	}
 	}
 }
 }
@@ -108,12 +111,16 @@ void Peer::sendReliableData(const Address &target, char *data, unsigned int size
 	Packet *packet = createPacket(target, data, size, type);
 	Packet *packet = createPacket(target, data, size, type);
 	packet->header.reliableID = connection->reliableID;
 	packet->header.reliableID = connection->reliableID;
 	connection->reliableID++;
 	connection->reliableID++;
+	
+	if(connection->reliableID == 0)
+		connection->reliableID = 1;
+
 	sendPacket(target, packet);	
 	sendPacket(target, packet);	
 	
 	
 	SentPacketEntry entry;
 	SentPacketEntry entry;
 	entry.packet = packet;
 	entry.packet = packet;
 	entry.timestamp = CoreServices::getInstance()->getCore()->getTicks();
 	entry.timestamp = CoreServices::getInstance()->getCore()->getTicks();
-//	connection->reliablePacketQueue.push_back(entry);
+	connection->reliablePacketQueue.push_back(entry);
 
 
 }
 }
 
 
@@ -163,9 +170,7 @@ bool Peer::checkPacketAcks(PeerConnection *connection, Packet *packet) {
 		}		
 		}		
 	}
 	}
 	
 	
-	for(int i=0; i < peerConnections.size(); i++) {
-		peerConnections[i]->ackPackets(packet->header.ack);
-	}
+	connection->ackPackets(packet->header.ack);
 	
 	
 	return retVal;
 	return retVal;
 }
 }
@@ -189,7 +194,7 @@ void Peer::handleEvent(Event *event) {
 
 
 void Peer::updateReliableDataQueue() {
 void Peer::updateReliableDataQueue() {
 	for(int i=0; i < peerConnections.size(); i++) {
 	for(int i=0; i < peerConnections.size(); i++) {
-		for(int j=0; j < peerConnections[i]->reliablePacketQueue.size(); j++) {
+		for(int j=0; j < peerConnections[i]->reliablePacketQueue.size(); j++) {		
 			if(peerConnections[i]->reliablePacketQueue[j].timestamp < CoreServices::getInstance()->getCore()->getTicks() - 1000) {
 			if(peerConnections[i]->reliablePacketQueue[j].timestamp < CoreServices::getInstance()->getCore()->getTicks() - 1000) {
 				peerConnections[i]->reliablePacketQueue[j].timestamp = CoreServices::getInstance()->getCore()->getTicks(); 
 				peerConnections[i]->reliablePacketQueue[j].timestamp = CoreServices::getInstance()->getCore()->getTicks(); 
 				sendPacket(peerConnections[i]->address, peerConnections[i]->reliablePacketQueue[j].packet);
 				sendPacket(peerConnections[i]->address, peerConnections[i]->reliablePacketQueue[j].packet);

+ 6 - 0
Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h

@@ -22,6 +22,7 @@ THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyGlobals.h"
+#include "PolyQuaternion.h"
 #include "PolyCollisionSceneEntity.h"
 #include "PolyCollisionSceneEntity.h"
 #include "btBulletCollisionCommon.h"
 #include "btBulletCollisionCommon.h"
 #include "btBulletDynamicsCommon.h"
 #include "btBulletDynamicsCommon.h"
@@ -55,6 +56,11 @@ namespace Polycode {
 		
 		
 		void setMass(Number mass);
 		void setMass(Number mass);
 		
 		
+		Vector3 getVelocity();
+		Vector3 getSpin();
+		
+			void setRotation(Quaternion quat);
+			
 			void setVelocity(Vector3 velocity);
 			void setVelocity(Vector3 velocity);
 			void warpTo(Vector3 position, bool resetRotation);
 			void warpTo(Vector3 position, bool resetRotation);
 			
 			

+ 23 - 14
Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp

@@ -229,31 +229,40 @@ void PhysicsEntity::setMass(Number mass) {
 }
 }
 
 
 void PhysicsEntity::Update() {		
 void PhysicsEntity::Update() {		
-	Matrix4 m;
-		
-	btScalar* mat = (btScalar*) malloc(sizeof(btScalar) * 16);				
-		
-	rigidBody->getWorldTransform().getOpenGLMatrix(mat);
-	for(int i=0; i < 16; i++) {
-		m.ml[i] = mat[i];
-	}
-	
-	free(mat);
-	
-	entity->setTransformByMatrixPure(m);
-//	collisionObject->getWorldTransform().setFromOpenGLMatrix(mat);
+	btVector3 t = rigidBody->getWorldTransform().getOrigin();
+	btQuaternion q = rigidBody->getOrientation();
+	entity->setRotationQuat(q.getW(), q.getX(), q.getY(), q.getZ());
+	entity->setPosition(t.getX(), t.getY(), t.getZ());
+}
+
+void PhysicsEntity::setRotation(Quaternion quat) {
+	btTransform t = rigidBody->getWorldTransform();
+	btQuaternion q;
+	q.setValue(quat.x, quat.y, quat.z, quat.w);
+	t.setRotation(q);
+	rigidBody->setWorldTransform(t);
 }
 }
 
 
 void PhysicsEntity::setVelocity(Vector3 velocity) {
 void PhysicsEntity::setVelocity(Vector3 velocity) {
 	rigidBody->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
 	rigidBody->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
-//	rigidBody->applyForce(btVector3(velocity.x, velocity.y, velocity.z), btVector3(0,0,0));
 }
 }
 
 
+
 void PhysicsEntity::setSpin(Vector3 spin) {
 void PhysicsEntity::setSpin(Vector3 spin) {
 	btVector3 angularVel = btVector3(spin.x, spin.y, spin.z);	
 	btVector3 angularVel = btVector3(spin.x, spin.y, spin.z);	
 	rigidBody->setAngularVelocity(angularVel);
 	rigidBody->setAngularVelocity(angularVel);
 }
 }
 
 
+Vector3 PhysicsEntity::getVelocity() {
+	btVector3 retVec = rigidBody->getLinearVelocity();
+	return Vector3(retVec.getX(), retVec.getY(), retVec.getZ());
+}
+
+Vector3 PhysicsEntity::getSpin() {
+	btVector3 retVec = rigidBody->getAngularVelocity();
+	return Vector3(retVec.getX(), retVec.getY(), retVec.getZ());
+}
+
 void PhysicsEntity::applyImpulse(Vector3 direction, Vector3 point) {
 void PhysicsEntity::applyImpulse(Vector3 direction, Vector3 point) {
 	btVector3 imp = btVector3(direction.x, direction.y, direction.z);
 	btVector3 imp = btVector3(direction.x, direction.y, direction.z);
 	btVector3 pos = btVector3(point.x, point.y, point.z);
 	btVector3 pos = btVector3(point.x, point.y, point.z);