Jump to content

  • Log In with Google      Sign In   
  • Create Account


Fezziiwig

Member Since 03 Oct 2012
Offline Last Active Apr 03 2013 06:55 AM

Topics I've Started

Velocity Verlet Integration

09 March 2013 - 05:21 AM

In a platformer game I'm making I'm going to use Verlet Integration, so in the player calculate function. At the moment I have it set up like this:

//// Velocity Verlet integration
lastAcceleration = avgAcceleration;
nextPosition.x += velocity.x * delta + ( 0.5 * lastAcceleration.x * delta * delta);
nextPosition.y += velocity.y * delta + ( 0.5 * lastAcceleration.y * delta * delta);


// Collision Detection - I wont put this in the sample code

// Move to new coords
position = nextPosition;

// Initialise Acceleration
newAcceleration.x = 0.0;
newAcceleration.y = 0.0;

// Gravity
if (!yCollision)
{
	double force = mass * -0.0001;
	newAcceleration.y = force * delta / mass;
}

// Air Resistance
velocity.x -= velocity.x * 0.01 * delta;

// Controls
if (key['W'] && yCollision)
{
	double force = mass * 0.05;
	newAcceleration.y = force / mass;
}

if (key['A'])
{
	double force = mass * -0.003;
	newAcceleration.x += force / mass;
	facingLeft = true;
}

if (key['D'])
{
	double force = mass * 0.003;
	newAcceleration.x += force / mass;
	facingLeft = false;
}

avgAcceleration.x = (lastAcceleration.x + newAcceleration.x) / 2.0;
avgAcceleration.y = (lastAcceleration.y + newAcceleration.y) / 2.0;
velocity.x += avgAcceleration.x * delta;
velocity.y += avgAcceleration.y * delta;
//// Velocity Verlet integration

 

However, The jumping still seems to be majorly affected by the frame rate. Have I set up the integration properly?


Using boost serialization to send a vector.

02 November 2012 - 05:56 PM

I've run into a real problem with regards to sending serialized vectors over a socket. A simplified example of what I'm doing:

Server:
#include <boost/serialization/vector.hpp>


struct someObject
{
	 int i;
	 template <class Archive>
	 void serialize(Archive & ar, const unsigned int version)
    {
	    ar & i;
    }
}

struct OutStream
{
	 std::vector <someObject> someVector;

	 template <class Archive>
	 void serialize(Archive & ar, const unsigned int version)
	 {
		  ar & someVector;
	 }
}outStream;

// Another part of the code
outStream.someVector.swap(someOtherVector);

// Serialise
std::stringstream archive_stream;
boost::archive::text_oarchive archive(archive_stream);
archive << outStream;


// Send
 sendto(ServerSocket, archive_stream.str().c_str(), strlen(archive_stream.str().c_str())...

Client:
#include <boost/serialization/vector.hpp>

struct someObject
{
     int i;
	 template <class Archive>
	 void serialize(Archive & ar, const unsigned int version)
    {
	    ar & i;
    }
}

struct InStream
{
	 std::vector <someObject> someVector;

	 template <class Archive>
	 void serialize(Archive & ar, const unsigned int version)
	 {
		  ar & someVector;
	 }
}inStream;

// Another part of the code
// Deserialize
archive_stream << temp;
boost::archive::text_iarchive archive(archive_stream);
ZeroMemory(&inStream, sizeof(inStream));
archive >> inStream;

someOtherVector.swap(inStream.someVector);

However when I run this, on the server side, either it doesn't send proberly(lots of blank variables) or it says

Expression:vector iterator not dereferencable


If it would help I can upload the whole source code (it's not that large). Any help is much appreciated!

Thanks,
Rowan.

Feedback wanted

21 October 2012 - 10:01 AM

Just stated prototyping a game under the working title COSMOS. Just want some feedback. Note; I am very much a beginner and I realise it is very under developed. Also any suggestions or ideas would be really cool. More information from the link

Link

Thanks,
Rowan.

Serialization

20 October 2012 - 04:14 AM

Can anyone recommend a fast method to serialize a class or struct so it can be send over a socket, and a short example would be nice.

How often should a server update

03 October 2012 - 11:07 AM

In most professional games how often do servers update (not as in patches but other player positions and stuff) their clients or do they use a different method to sending out an update every so often? At the moment my server sends out sixty times a second and when the client receives an update it sends an update to the server. It works, but is this the traditional way of doing things?

PARTNERS