1 /* Copyright (c) 2007 Scott Lembcke
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19  * SOFTWARE.
20  */
21 
22 #include "ChipmunkDebugDraw.h"
23 
24 typedef struct ChipmunkDemo ChipmunkDemo;
25 
26 typedef cpSpace *(*ChipmunkDemoInitFunc)(void);
27 typedef void (*ChipmunkDemoUpdateFunc)(cpSpace *space, double dt);
28 typedef void (*ChipmunkDemoDrawFunc)(cpSpace *space);
29 typedef void (*ChipmunkDemoDestroyFunc)(cpSpace *space);
30 
31 struct ChipmunkDemo {
32 	const char *name;
33 	double timestep;
34 
35 	ChipmunkDemoInitFunc initFunc;
36 	ChipmunkDemoUpdateFunc updateFunc;
37 	ChipmunkDemoDrawFunc drawFunc;
38 
39 	ChipmunkDemoDestroyFunc destroyFunc;
40 };
41 
42 static inline cpFloat
frand(void)43 frand(void)
44 {
45 	return (cpFloat)rand()/(cpFloat)RAND_MAX;
46 }
47 
48 static inline cpVect
frand_unit_circle()49 frand_unit_circle(){
50 	cpVect v = cpv(frand()*2.0f - 1.0f, frand()*2.0f - 1.0f);
51 	return (cpvlengthsq(v) < 1.0f ? v : frand_unit_circle());
52 }
53 
54 extern int ChipmunkDemoTicks;
55 extern double ChipmunkDemoTime;
56 extern cpVect ChipmunkDemoKeyboard;
57 extern cpVect ChipmunkDemoMouse;
58 extern cpBool ChipmunkDemoRightClick;
59 extern cpBool ChipmunkDemoRightDown;
60 
61 extern char const *ChipmunkDemoMessageString;
62 void ChipmunkDemoPrintString(char const *fmt, ...);
63 
64 extern cpShapeFilter GRAB_FILTER;
65 extern cpShapeFilter NOT_GRABBABLE_FILTER;
66 
67 void ChipmunkDemoDefaultDrawImpl(cpSpace *space);
68 void ChipmunkDemoFreeSpaceChildren(cpSpace *space);
69