From 2831e232b886c5e3b0791ea5192f9e5194e6abf3 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 9 Mar 2018 23:55:49 -0500 Subject: Added IGUIImages Added the ability to display itextures on the gui --- src/test/test_phys.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++ src/test/test_streams.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/test/test_phys.cpp create mode 100644 src/test/test_streams.cpp (limited to 'src/test') diff --git a/src/test/test_phys.cpp b/src/test/test_phys.cpp new file mode 100644 index 0000000..d56b031 --- /dev/null +++ b/src/test/test_phys.cpp @@ -0,0 +1,72 @@ +#include + +#include + +int main (void) +{ + + btBroadphaseInterface* broadphase = new btDbvtBroadphase(); + + btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); + btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); + + btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; + + btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); + + dynamicsWorld->setGravity(btVector3(0, -10, 0)); + + + btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1); + + btCollisionShape* fallShape = new btSphereShape(1); + + + btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0))); + btRigidBody::btRigidBodyConstructionInfo + groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0)); + btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); + dynamicsWorld->addRigidBody(groundRigidBody); + + + btDefaultMotionState* fallMotionState = + new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 50, 0))); + btScalar mass = 1; + btVector3 fallInertia(0, 0, 0); + fallShape->calculateLocalInertia(mass, fallInertia); + btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, fallShape, fallInertia); + btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI); + dynamicsWorld->addRigidBody(fallRigidBody); + + + for (int i = 0; i < 300; i++) { + dynamicsWorld->stepSimulation(1 / 60.f, 10); + + btTransform trans; + fallRigidBody->getMotionState()->getWorldTransform(trans); + + std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl; + } + + dynamicsWorld->removeRigidBody(fallRigidBody); + delete fallRigidBody->getMotionState(); + delete fallRigidBody; + + dynamicsWorld->removeRigidBody(groundRigidBody); + delete groundRigidBody->getMotionState(); + delete groundRigidBody; + + + delete fallShape; + + delete groundShape; + + + delete dynamicsWorld; + delete solver; + delete collisionConfiguration; + delete dispatcher; + delete broadphase; + + return 0; +} \ No newline at end of file diff --git a/src/test/test_streams.cpp b/src/test/test_streams.cpp new file mode 100644 index 0000000..cbcbcac --- /dev/null +++ b/src/test/test_streams.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +#include "../shared/lua_api/stream.hpp" + +int main(){ + //Simple + struct stream* s = stream_create(); + stream_writeInt(s,5); + assert(stream_readInt(s) == 5); + stream_free(s); + + //Little more complex + s = stream_create(); + stream_writeInt(s,1); + stream_writeInt(s,2); + stream_writeInt(s,3); + stream_writeInt(s,4); + assert(stream_readInt(s) == 1); + assert(stream_readInt(s) == 2); + assert(stream_readInt(s) == 3); + assert(stream_readInt(s) == 4); + stream_free(s); + + //Make sure we're not leaking memory + //Uncomment this section, and check htop or windows task manager + /* + time_t t; + time(&t); + srand((unsigned) t); + int i,j; + for(i = 0; i < 100000; i++){ + s = stream_create(); + for(j = 0; j < 10000; j++){ + stream_writeInt(s,rand()); + } + stream_free(s); + } + */ + + //Read/write data + s = stream_create(); + char* str = (char*)"One two three four!\n"; + int slen = strlen(str); + stream_writeData(s,str,slen); + char out[slen+1]; + stream_readData(s,slen,out); + out[slen] = '\0'; + assert(strcmp(out,str) == 0); + stream_free(s); + + //Read/write string + s = stream_create(); + stream_writeString(s,str,slen); + char* rstr = stream_readString(s); + assert(strcmp(rstr,str) == 0); + stream_free(s); + + //Make sure the string reads it's null character + s = stream_create(); + stream_writeString(s,str,slen); + stream_writeInt(s,5); + stream_print(s); + stream_readString(s); + stream_print(s); + int i = stream_readInt(s); + assert(i == 5); + stream_free(s); + + printf("OK!\n"); + return 0; +} -- cgit v1.2.3-70-g09d2