Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pending-merge/linux'
Browse files Browse the repository at this point in the history
  • Loading branch information
epreston committed Nov 16, 2013
1 parent 498d538 commit 10fae51
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 33 deletions.
38 changes: 38 additions & 0 deletions Makefile
@@ -0,0 +1,38 @@
# CYCLONEPHYSICS LIB
CXXFLAGS=-O2 -I./include -fPIC
CYCLONEOBJS=src/body.o src/collide_coarse.o src/collide_fine.o src/contacts.o src/core.o src/fgen.o src/joints.o src/particle.o src/pcontacts.o src/pfgen.o src/plinks.o src/pworld.o src/random.o src/world.o


# DEMO FILES
SOURCES=body
LDFLAGS=-lGL -lglut -lGLU -L./Debug
DEMO_CPP=./src/demos/app.cpp ./src/demos/timing.cpp ./src/demos/main.cpp
CYCLONELIB=./lib/libcyclone.so

DEMOS=ballistic bigballistic blob bridge explosion fireworks flightsim fracture platform ragdoll sailboat



all: libcyclone.so $(DEMOS)

libcyclone.so: $(CYCLONEOBJS)
$(CXX) $(CYCLONEOBJS) -shared -dynamiclib -o lib/libcyclone.so

$(DEMOS):
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o ./bin/$@ $(DEMO_CPP) $(CYCLONELIB) ./src/demos/$@/$@.cpp


clean:
rm -f src/*.o lib/libcyclone.so
rm -f \
./bin/fireworks \
./bin/fracture \
./bin/flightsim \
./bin/bridge \
./bin/sailboat \
./bin/explosion \
./bin/ballistic \
./bin/platform \
./bin/bigballistic \
./bin/blob \
./bin/ragdoll
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions include/cyclone/collide_fine.h
Expand Up @@ -44,8 +44,8 @@ namespace cyclone {
* and intersection routines, so they should have
* access to its data.
*/
friend IntersectionTests;
friend CollisionDetector;
friend class IntersectionTests;
friend class CollisionDetector;

/**
* The rigid body that is represented by this primitive.
Expand Down Expand Up @@ -309,4 +309,4 @@ namespace cyclone {

} // namespace cyclone

#endif // CYCLONE_COLLISION_FINE_H
#endif // CYCLONE_COLLISION_FINE_H
2 changes: 1 addition & 1 deletion include/cyclone/contacts.h
Expand Up @@ -64,7 +64,7 @@ namespace cyclone {
* The contact resolver object needs access into the contacts to
* set and effect the contact.
*/
friend ContactResolver;
friend class ContactResolver;

public:
/**
Expand Down
4 changes: 2 additions & 2 deletions include/cyclone/pcontacts.h
Expand Up @@ -53,7 +53,7 @@ namespace cyclone {
* The contact resolver object needs access into the contacts to
* set and effect the contact.
*/
friend ParticleContactResolver;
friend class ParticleContactResolver;


public:
Expand Down Expand Up @@ -194,4 +194,4 @@ namespace cyclone {

} // namespace cyclone

#endif // CYCLONE_CONTACTS_H
#endif // CYCLONE_CONTACTS_H
11 changes: 10 additions & 1 deletion include/cyclone/random.h
Expand Up @@ -32,6 +32,15 @@ namespace cyclone {
class Random
{
public:
/**
* left bitwise rotation
*/

unsigned rotl(unsigned n, unsigned r);
/**
* right bitwise rotation
*/
unsigned rotr(unsigned n, unsigned r);

/**
* Creates a new random number stream with a seed based on
Expand Down Expand Up @@ -122,4 +131,4 @@ namespace cyclone {

} // namespace cyclone

#endif // CYCLONE_BODY_H
#endif // CYCLONE_BODY_H
2 changes: 1 addition & 1 deletion include/cyclone/world.h
Expand Up @@ -116,4 +116,4 @@ namespace cyclone {

} // namespace cyclone

#endif // CYCLONE_PWORLD_H
#endif // CYCLONE_PWORLD_H
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/collide_fine.cpp
Expand Up @@ -286,7 +286,7 @@ static inline real penetrationOnAxis(
static inline bool tryAxis(
const CollisionBox &one,
const CollisionBox &two,
Vector3& axis,
Vector3 axis,
const Vector3& toCentre,
unsigned index,

Expand Down Expand Up @@ -695,10 +695,10 @@ unsigned CollisionDetector::boxAndHalfSpace(
// Move onto the next contact
contact++;
contactsUsed++;
if (contactsUsed == data->contactsLeft) return contactsUsed;
if (contactsUsed == (unsigned)data->contactsLeft) return contactsUsed;
}
}

data->addContacts(contactsUsed);
return contactsUsed;
}
}
4 changes: 2 additions & 2 deletions src/demos/app.cpp
Expand Up @@ -166,7 +166,7 @@ void MassAggregateApplication::display()
p++)
{
cyclone::Particle *particle = *p;
cyclone::Vector3 &pos = particle->getPosition();
const cyclone::Vector3 &pos = particle->getPosition();
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
glutSolidSphere(0.1f, 20, 10);
Expand Down Expand Up @@ -324,4 +324,4 @@ void RigidBodyApplication::key(unsigned char key)
}

Application::key(key);
}
}
12 changes: 6 additions & 6 deletions src/demos/fireworks/fireworks.cpp
Expand Up @@ -17,7 +17,7 @@

#include <stdio.h>

static cyclone::Random random;
static cyclone::Random crandom;

/**
* Fireworks are particles, with additional data for rendering and
Expand Down Expand Up @@ -143,7 +143,7 @@ struct FireworkRule
void create(Firework *firework, const Firework *parent = NULL) const
{
firework->type = type;
firework->age = random.randomReal(minAge, maxAge);
firework->age = crandom.randomReal(minAge, maxAge);

cyclone::Vector3 vel;
if (parent) {
Expand All @@ -154,12 +154,12 @@ struct FireworkRule
else
{
cyclone::Vector3 start;
int x = (int)random.randomInt(3) - 1;
int x = (int)crandom.randomInt(3) - 1;
start.x = 5.0f * cyclone::real(x);
firework->setPosition(start);
}

vel += random.randomVector(minVelocity, maxVelocity);
vel += crandom.randomVector(minVelocity, maxVelocity);
firework->setVelocity(vel);

// We use a mass of one in all cases (no point having fireworks
Expand Down Expand Up @@ -442,7 +442,7 @@ void FireworksDemo::display()
case 9: glColor3f(1,0.5f,0.5f); break;
};

cyclone::Vector3 &pos = firework->getPosition();
const cyclone::Vector3 &pos = firework->getPosition();
glVertex3f(pos.x-size, pos.y-size, pos.z);
glVertex3f(pos.x+size, pos.y-size, pos.z);
glVertex3f(pos.x+size, pos.y+size, pos.z);
Expand Down Expand Up @@ -481,4 +481,4 @@ void FireworksDemo::key(unsigned char key)
Application* getApplication()
{
return new FireworksDemo();
}
}
4 changes: 2 additions & 2 deletions src/demos/main.cpp
Expand Up @@ -100,7 +100,7 @@ void motion(int x, int y)
/**
* The main entry point. We pass arguments onto GLUT.
*/
void main(int argc, char** argv)
int main(int argc, char** argv)
{
// Set up GLUT and the timers
glutInit(&argc, argv);
Expand All @@ -126,4 +126,4 @@ void main(int argc, char** argv)
app->deinit();
delete app;
TimingData::deinit();
}
}
56 changes: 48 additions & 8 deletions src/demos/timing.cpp
Expand Up @@ -12,17 +12,41 @@

#include "timing.h"

// Import the high performance timer (c. 4ms).
#include <windows.h>
#include <mmsystem.h>

// Hold internal timing data for the performance counter.
static bool qpcFlag;
static double qpcFrequency;

#if (__APPLE__ || __unix)
#define TIMING_UNIX 1

#include <stdlib.h>
#include <sys/time.h>

// assume unix based OS
typedef unsigned long long LONGLONG;
#else
#define TIMING_WINDOWS 1
// assume windows

// Import the high performance timer (c. 4ms).
#include <windows.h>
#include <mmsystem.h>

static double qpcFrequency;
#endif



// Internal time and clock access functions
unsigned systemTime()
{
#if TIMING_UNIX
struct timeval tv;
gettimeofday(&tv, 0);

return tv.tv_sec * 1000 + tv.tv_usec/1000;

#else
if(qpcFlag)
{
static LONGLONG qpcMillisPerTick;
Expand All @@ -33,35 +57,51 @@ unsigned systemTime()
{
return unsigned(timeGetTime());
}
#endif

}

unsigned TimingData::getTime()
{
return systemTime();
}

#if TIMING_WINDOWS
unsigned long systemClock()
{
__asm {
rdtsc;
rdtsc;
}
}
#endif

unsigned long TimingData::getClock()
{

#if TIMING_UNIX
struct timeval tv;
gettimeofday(&tv, 0);

return tv.tv_sec * 1000 + tv.tv_usec/1000;
#else
return systemClock();
#endif
}

// Sets up the timing system and registers the performance timer.
void initTime()
{
#if TIMING_UNIX
qpcFlag = false;
#else
LONGLONG time;

qpcFlag = (QueryPerformanceFrequency((LARGE_INTEGER*)&time) > 0);

// Check if we have access to the performance counter at this
// resolution.
if (qpcFlag) qpcFrequency = 1000.0 / time;
#endif
}


Expand Down Expand Up @@ -92,7 +132,7 @@ void TimingData::update()
timingData->lastFrameTimestamp = thisTime;

// Update the tick information.
unsigned long thisClock = systemClock();
unsigned long thisClock = getClock();
timingData->lastFrameClockTicks =
thisClock - timingData->lastFrameClockstamp;
timingData->lastFrameClockstamp = thisClock;
Expand Down Expand Up @@ -132,7 +172,7 @@ void TimingData::init()
timingData->lastFrameTimestamp = systemTime();
timingData->lastFrameDuration = 0;

timingData->lastFrameClockstamp = systemClock();
timingData->lastFrameClockstamp = getClock();
timingData->lastFrameClockTicks = 0;

timingData->isPaused = false;
Expand All @@ -145,4 +185,4 @@ void TimingData::deinit()
{
delete timingData;
timingData = NULL;
}
}
16 changes: 14 additions & 2 deletions src/random.cpp
Expand Up @@ -44,12 +44,24 @@ void Random::seed(unsigned s)
p1 = 0; p2 = 10;
}

unsigned Random::rotl(unsigned n, unsigned r)
{
return (n << r) |
(n >> (32 - r));
}

unsigned Random::rotr(unsigned n, unsigned r)
{
return (n >> r) |
(n << (32 - r));
}

unsigned Random::randomBits()
{
unsigned result;

// Rotate the buffer and store it back to itself
result = buffer[p1] = _lrotl(buffer[p2], 13) + _lrotl(buffer[p1], 9);
result = buffer[p1] = rotl(buffer[p2], 13) + rotl(buffer[p1], 9);

// Rotate pointers
if (--p1 < 0) p1 = 16;
Expand Down Expand Up @@ -169,4 +181,4 @@ Vector3 Random::randomVector(const Vector3 &min, const Vector3 &max)
randomReal(min.y, max.y),
randomReal(min.z, max.z)
);
}
}
4 changes: 2 additions & 2 deletions src/world.cpp
Expand Up @@ -18,8 +18,8 @@ using namespace cyclone;
World::World(unsigned maxContacts, unsigned iterations)
:
firstBody(NULL),
firstContactGen(NULL),
resolver(iterations),
firstContactGen(NULL),
maxContacts(maxContacts)
{
contacts = new Contact[maxContacts];
Expand Down Expand Up @@ -90,4 +90,4 @@ void World::runPhysics(real duration)
// And process them
if (calculateIterations) resolver.setIterations(usedContacts * 4);
resolver.resolveContacts(contacts, usedContacts, duration);
}
}

0 comments on commit 10fae51

Please sign in to comment.