Commits

Anonymous committed 3511887

Fixed various gcc warnings.
Removed OpenGL tests.
Changed structure fields and variables to be PyObjects, not specific
types.

Comments (0)

Files changed (11)

include/glTestSuite.h

-#ifndef _PG_TEST_SUITE_H
-#define _PG_TEST_SUITE_H
-
-#include <GL/glut.h>
-
-void watch_start();
-double watch_stop();
-void draw_text(int x, int y, char *str);
-void glprintf(int x, int y, const char* fmt, ...);
-
-#endif

include/pgWorldObject.h

 {
 	PyObject_HEAD
 
-	PyListObject*	bodyList;
-	PyListObject*	jointList;
-	PyListObject*	contactList;
+	PyObject*	bodyList;
+	PyObject*	jointList;
+	PyObject*	contactList;
 
 	Py_complex		vecGravity;
 	double			fDamping;
 if __name__ == "__main__":
 
     extphysics = Extension ("physics", sources = get_c_files (),
-                            include_dirs = [ "include" ])
+                            include_dirs = [ "include" ],
+                            extra_compile_args=["-g", "-W", "-Wall"])
 
     setupdata = {
         "name" : "physics",

src/glTestSuite.c

-#include "glTestSuite.h"
-#include <time.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#ifdef WIN32
-#pragma warning(disable:4996)
-#endif
-
-#define MAX_STR_LEN 1000
-
-//�ܱ�
-static double s_time;
-
-void watch_start()
-{
-	s_time = (double)clock();
-}
-
-//������ܱ�򿪵�ֹͣ�������˶�����
-double watch_stop()
-{
-	return ((double)clock() - s_time)/CLOCKS_PER_SEC;
-}
-
-//��Ⱦ����, ����Ӣ�ģ�(x, y)�����־������Ͻ�����
-//ÿ���ַ��ַ���9���أ���15����
-void draw_text(int x, int y, char *str)
-{
-	int len, i, w, h;
-
-	glMatrixMode(GL_PROJECTION);
-	glPushMatrix();
-	glLoadIdentity();
-	w = glutGet(GLUT_WINDOW_WIDTH);
-	h = glutGet(GLUT_WINDOW_HEIGHT);
-	gluOrtho2D(0, w, h, 0);
-	glMatrixMode(GL_MODELVIEW);
-	glPushMatrix();
-	glLoadIdentity();
-
-	glColor3f(0.6f, 0.8f, 0.6f);
-	glRasterPos2i(x, y + 15);
-	len = (int) strlen(str);
-	for (i = 0; i < len; i++)
-		glutBitmapCharacter(GLUT_BITMAP_9_BY_15, str[i]);
-
-	glPopMatrix();
-	glMatrixMode(GL_PROJECTION);
-	glPopMatrix();
-	glMatrixMode(GL_MODELVIEW);
-}
-
-//��ӡ���ֵ���Ļ������printf���Ƽ�
-void glprintf(int x, int y, const char* fmt, ...)
-{
-	static char buf[MAX_STR_LEN];
-	va_list p;
-	va_start(p, fmt);
-	memset(buf, 0, sizeof(buf));
-	vsprintf(buf, fmt, p);
-	draw_text(x, y, buf);
-}
 {
 	pgBodyObject* body = (pgBodyObject*)self;
 	int i;
-	PyListObject* list;
+	PyObject* list;
 
 	/*if (!PyArg_ParseTuple(args,"O",&body))
 	{
 			PyErr_SetString(PyExc_ValueError,"Shape is NULL");
 			return NULL;
 		}
-		list = (PyListObject*)PyList_New(4);
+		list = PyList_New(4);
 		for (i = 0;i < 4;i++)
 		{
 			pgVector2* pVertex = &(((pgRectShape*)(body->shape))->point[i]);
 			pgVector2 golVertex = PG_GetGlobalPos(body,pVertex);
-			PyTupleObject* tuple = (PyTupleObject*)PyTuple_New(2);
+			PyObject* tuple = PyTuple_New(2);
 
 			long ix = golVertex.real * FLOAT_TO_INT_MUL;
 			long iy = golVertex.imag * FLOAT_TO_INT_MUL;
-			PyIntObject* xnum = PyInt_FromLong(ix);
-			PyIntObject* ynum = PyInt_FromLong(iy);
-			PyTuple_SetItem((PyObject*)tuple,0,xnum);
-			PyTuple_SetItem((PyObject*)tuple,1,ynum);
-			PyList_SetItem((PyObject*)list,i,(PyObject*)tuple);
+			PyObject* xnum = PyInt_FromLong(ix);
+			PyObject* ynum = PyInt_FromLong(iy);
+			PyTuple_SetItem(tuple,0,xnum);
+			PyTuple_SetItem(tuple,1,ynum);
+			PyList_SetItem(list,i,tuple);
 		}
 		return (PyObject*)list;
 	}
 	{"torque",T_DOUBLE,offsetof(pgBodyObject,fTorque),0,""},
 	{"restitution",T_DOUBLE,offsetof(pgBodyObject,fRestitution),0,""},
 	{"friction",T_DOUBLE,offsetof(pgBodyObject,fFriction),0,""},
-    {NULL}  /* Sentinel */
+        {NULL, 0, 0, 0, NULL}  /* Sentinel */
 };
 
 static PyMethodDef _pgBody_methods[] = {
 	{"velocity",(getter)_pgBody_getVelocity,(setter)_pgBody_setVelocity,"velocity",NULL},
 	{"position",(getter)_pgBody_getPosition,(setter)_pgBody_setPosition,"position",NULL},
 	{"force",(getter)_pgBody_getForce,(setter)_pgBody_setForce,"force",NULL},
-	{ NULL}
+	{ NULL, NULL, NULL, NULL, NULL}
 };
 
 PyTypeObject pgBodyType =
 #include "pgAABBBox.h"
 #include "pgShapeObject.h"
 #include "pgBodyObject.h"
-#include "glTestSuite.h"
 #include <assert.h>
-#include <GL/glut.h>
 
 extern PyTypeObject pgContactType;
 
 	incidR = c_diff(contact->pos, incidBody->vecPosition);
 
 	if(c_dot(contact->dv, contact->normal) > 0) return;
-	glPointSize(6.f);
-	glColor3f(1.f, 0.f, 0.f);
-	glBegin(GL_POINTS);
-	glVertex2d(contact->pos.real, contact->pos.imag);
-	glEnd();
-	glPointSize(1.f);
 
 	if(!refBody->bStatic)
 	{

src/pgHelpFunctions.c

 PyMethodDef pgHelpMethods[] = {
 	//{"get_point_list",_pg_getPointListFromBody,METH_VARARGS,""	},
 	{NULL, NULL, 0, NULL} 
-};
+};
 		"body2",(getter)_pgJoint_getBody2,(setter)_pgJoint_setBody2,"",NULL,
 	},
 	{
-		NULL
+            NULL, NULL, NULL, NULL, NULL
 	}
 };
 
 
 static PyMemberDef _pgDistanceJoint_members[] = 
 {
-	{	NULL }
+    {	NULL, 0, 0, 0, NULL}
 }; 
 
 static PyGetSetDef _pgDistanceJoint_getseters[] = {
 		"anchor2",(getter)_pgDistanceJoint_getAnchor2,(setter)_pgDistanceJoint_setAnchor2,"",NULL,
 	},
 	{
-		NULL
+            NULL, NULL, NULL, NULL, NULL
 	}
 };
 
 	int face_id;
 	pgVector2 gp[4];
 	pgVector2 contacts[MAX_CONTACTS];
-	int csize;
-	pgVector2 normal;
+	int csize = 0;
+	pgVector2 normal = { 0, 0 };
 	pgAABBBox clipBox;
 	int overlap;
 	pgVector2* pAcc, * pSplitAcc;
 	Py_ssize_t size = PyList_Size((PyObject*)(world->bodyList));
 	for (i = 0; i < size; ++i)
 	{
-		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), i));		
+		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem(world->bodyList, i));		
 		PG_FreeUpdateBodyVel(world, body, stepTime);
 	}
 }
 	pgBodyObject* refBody, *incBody;
 	pgJointObject* contact;
 	
-	body_cnt = PyList_Size((PyObject*)(world->bodyList));
+	body_cnt = PyList_Size(world->bodyList);
 	//clear contactList first
-	contact_cnt = PyList_Size((PyObject*)(world->contactList));
-	if(PyList_SetSlice((PyObject*)(world->contactList), 0, contact_cnt, NULL) < 0) return;
-	assert(PyList_Size((PyObject*)(world->contactList))==0);
+	contact_cnt = PyList_Size(world->contactList);
+	if(PyList_SetSlice(world->contactList, 0, contact_cnt, NULL) < 0) return;
+	assert(PyList_Size(world->contactList)==0);
 	
 	//for all pair of objects, do collision test	
 	//update AABB
 	for(i = 0; i < body_cnt; ++i)
 	{
-		refBody = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), i));
+		refBody = (pgBodyObject*)(PyList_GetItem(world->bodyList, i));
 		refBody->shape->UpdateAABB(refBody);
 	}
 	
 	//collision test
 	for(i = 0; i < body_cnt-1; ++i)
 	{
-		refBody = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), i));
+		refBody = (pgBodyObject*)(PyList_GetItem(world->bodyList, i));
 		for(j = i+1; j < body_cnt; ++j)
 		{
-			incBody = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), j));
+			incBody = (pgBodyObject*)(PyList_GetItem(world->bodyList, j));
 			if(refBody->bStatic && incBody->bStatic) continue;
 			if(PG_IsOverlap(&(refBody->shape->box), &(incBody->shape->box), 1e-8))
 			{
-				PG_AppendContact(refBody, incBody, (PyObject*)world->contactList);
+				PG_AppendContact(refBody, incBody, world->contactList);
 			}
 		}
 	}
 
-	contact_cnt = PyList_Size((PyObject*)(world->contactList));
+	contact_cnt = PyList_Size(world->contactList);
 	for(j = 0; j < MAX_ITERATION; ++j)
 	{
 		//clear bias
 		for(i = 0; i < body_cnt; ++i)
 		{
-			refBody = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList), i));
+			refBody = (pgBodyObject*)(PyList_GetItem(world->bodyList, i));
 			PG_Set_Vector2(refBody->cBiasLV, 0.f, 0.f);
 			refBody->cBiasW = 0.f;
 		}
 		//clear impulse
 		for(i = 0; i < contact_cnt; ++i)
 		{
-			contact = (pgJointObject*)(PyList_GetItem((PyObject*)(world->contactList), i));
+			contact = (pgJointObject*)(PyList_GetItem(world->contactList, i));
 			PG_Set_Vector2(**(((pgContact*)contact)->ppAccMoment), 0, 0);
 			PG_Set_Vector2(**(((pgContact*)contact)->ppSplitAccMoment), 0, 0);
 		}
 
 		//collision reaction
-		contact_cnt = PyList_Size((PyObject*)(world->contactList));
+		contact_cnt = PyList_Size(world->contactList);
 		for(i = 0; i < contact_cnt; ++i)
 		{
-			contact = (pgJointObject*)(PyList_GetItem((PyObject*)(world->contactList), i));
+			contact = (pgJointObject*)(PyList_GetItem(world->contactList, i));
 			PG_ApplyContact((PyObject*)contact, step);
 		}
 		//update V	
 		for(i = 0; i < contact_cnt; ++i)
 		{
-			contact = (pgJointObject*)(PyList_GetItem((PyObject*)(world->contactList), i));
+			contact = (pgJointObject*)(PyList_GetItem(world->contactList, i));
 			contact->SolveConstraintVelocity(contact, step);
 		}
 	}
 	Py_ssize_t i;
 	for (i = 0; i < size; ++i)
 	{
-		pgJointObject* joint = (pgJointObject*)(PyList_GetItem((PyObject*)(world->jointList),i));
+		pgJointObject* joint = (pgJointObject*)(PyList_GetItem(world->jointList,i));
 		//what happened here?
 		if (joint->SolveConstraintVelocity)
 		{
 
 void _PG_BodyPositionUpdate(pgWorldObject* world,double stepTime)
 {
-	Py_ssize_t size = PyList_Size((PyObject*)(world->bodyList));
+	Py_ssize_t size = PyList_Size(world->bodyList);
 	Py_ssize_t i;
 	for (i = 0; i < size; ++i)
 	{
-		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList),i));
+		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem(world->bodyList,i));
 		PG_FreeUpdateBodyPos(world,body,stepTime);	
 	}
 }
 
 int PG_AddBodyToWorld(pgWorldObject* world,pgBodyObject* body)
 {
-	return PyList_Append((PyObject*)world->bodyList,(PyObject*)body);
+	return PyList_Append(world->bodyList,(PyObject*)body);
 }
 
 
 
 int PG_AddJointToWorld(pgWorldObject* world,pgJointObject* joint)
 {
-	return PyList_Append((PyObject*)world->jointList,(PyObject*)joint);
+	return PyList_Append(world->jointList,(PyObject*)joint);
 }
 
 int PG_RemoveJointFromWorld(pgWorldObject* world,pgJointObject* joint)
 
 void PG_WorldInit(pgWorldObject* world)
 {
-	world->bodyList = (PyListObject*)PyList_New(0);
-	world->jointList = (PyListObject*)PyList_New(0);
-	world->contactList = (PyListObject*)PyList_New(0);
+	world->bodyList = PyList_New(0);
+	world->jointList = PyList_New(0);
+	world->contactList = PyList_New(0);
 	world->fDamping = 0.0;
 	world->fStepTime = 0.1;
 	PG_Set_Vector2(world->vecGravity,0.0,-50);
 
 static PyObject* _pgWorld_getBodyList(pgWorldObject* world,void* closure)
 {
-	Py_INCREF ((PyObject*)world->bodyList);
-	return (PyObject*)world->bodyList;
+	Py_INCREF (world->bodyList);
+	return world->bodyList;
 }
 
 static PyObject* _pgWorld_getJointList(pgWorldObject* world,void* closure)
 {
-	Py_INCREF ((PyObject*)world->jointList);
-	return (PyObject*)world->jointList;
+	Py_INCREF (world->jointList);
+	return world->jointList;
 }
 
 
 		"gravity",(getter)_pgWorld_getGravity,(setter)_pgWorld_setGravity,"gravity",NULL,
 	},
 	{
-		"body_list",(getter)_pgWorld_getBodyList,NULL,NULL
+            "body_list",(getter)_pgWorld_getBodyList,NULL,NULL,NULL
 	},
 	{
-		"joint_list",(getter)_pgWorld_getJointList,NULL,NULL
+            "joint_list",(getter)_pgWorld_getJointList,NULL,NULL,NULL
 	},
 	{
-		NULL
+            NULL, NULL, NULL, NULL, NULL
 	}
 };
 
 {
 	{"damping",T_DOUBLE,offsetof(pgWorldObject,fDamping),0,""},
 	{
-		NULL
+            NULL, 0, 0, 0, NULL
 	}
 }; 
 
 
 
 def render_body(body,surface,color):
-    l = physics.get_point_list(body)
+    l = body.get_point_list()
     pygame.draw.polygon(surface,color,l)