Permalink
Browse files

Merge remote-tracking branch 'origin/pending-merge/linux'

  • Loading branch information...
1 parent 498d538 commit 10fae519dc724ccaf03d11ee4e89f89c751ca89d @epreston epreston committed Nov 16, 2013
View
@@ -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.
@@ -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.
@@ -309,4 +309,4 @@ namespace cyclone {
} // namespace cyclone
-#endif // CYCLONE_COLLISION_FINE_H
+#endif // CYCLONE_COLLISION_FINE_H
@@ -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:
/**
@@ -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:
@@ -194,4 +194,4 @@ namespace cyclone {
} // namespace cyclone
-#endif // CYCLONE_CONTACTS_H
+#endif // CYCLONE_CONTACTS_H
@@ -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
@@ -122,4 +131,4 @@ namespace cyclone {
} // namespace cyclone
-#endif // CYCLONE_BODY_H
+#endif // CYCLONE_BODY_H
@@ -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.
@@ -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,
@@ -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;
-}
+}
View
@@ -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);
@@ -324,4 +324,4 @@ void RigidBodyApplication::key(unsigned char key)
}
Application::key(key);
-}
+}
@@ -17,7 +17,7 @@
#include <stdio.h>
-static cyclone::Random random;
+static cyclone::Random crandom;
/**
* Fireworks are particles, with additional data for rendering and
@@ -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) {
@@ -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
@@ -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);
@@ -481,4 +481,4 @@ void FireworksDemo::key(unsigned char key)
Application* getApplication()
{
return new FireworksDemo();
-}
+}
View
@@ -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);
@@ -126,4 +126,4 @@ void main(int argc, char** argv)
app->deinit();
delete app;
TimingData::deinit();
-}
+}
View
@@ -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;
@@ -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
}
@@ -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;
@@ -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;
@@ -145,4 +185,4 @@ void TimingData::deinit()
{
delete timingData;
timingData = NULL;
-}
+}
View
@@ -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;
@@ -169,4 +181,4 @@ Vector3 Random::randomVector(const Vector3 &min, const Vector3 &max)
randomReal(min.y, max.y),
randomReal(min.z, max.z)
);
-}
+}
View
@@ -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];
@@ -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.