| 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 | /* |
| 23 | IMPORTANT - READ ME! |
| 24 | |
| 25 | This file sets up a simple interface that the individual demos can use to get |
| 26 | a Chipmunk space running and draw what's in it. In order to keep the Chipmunk |
| 27 | examples clean and simple, they contain no graphics code. All drawing is done |
| 28 | by accessing the Chipmunk structures at a very low level. It is NOT |
| 29 | recommended to write a game or application this way as it does not scale |
| 30 | beyond simple shape drawing and is very dependent on implementation details |
| 31 | about Chipmunk which may change with little to no warning. |
| 32 | */ |
| 33 | |
| 34 | #include <stdbool.h> |
| 35 | #include <stdio.h> |
| 36 | #include <string.h> |
| 37 | #include <limits.h> |
| 38 | #include <stdarg.h> |
| 39 | |
| 40 | #include "chipmunk/chipmunk_private.h"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/ |
| 41 | #include "ChipmunkDemo.h"cxx . . $ `<file>/demo/ChipmunkDemo.h`/ |
| 42 | #include "ChipmunkDemoTextSupport.h"cxx . . $ `<file>/demo/ChipmunkDemoTextSupport.h`/ |
| 43 | |
| 44 | #include "sokol/sokol.h"cxx . . $ `<file>/demo/sokol/sokol.h`/ |
| 45 | |
| 46 | #undef Convex |
| 47 | |
| 48 | static ChipmunkDemocxx . . $ ChipmunkDemo# demoscxx . . $ demos.[32]; |
| 49 | static int demo_countcxx . . $ demo_count.; |
| 50 | static int demo_indexcxx . . $ demo_index.; |
| 51 | |
| 52 | static cpBoolcxx . . $ cpBool# pausedcxx . . $ paused. = cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 53 | static cpBoolcxx . . $ cpBool# stepcxx . . $ step. = cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 54 | |
| 55 | static cpSpacecxx . . $ cpSpace# *spacecxx . . $ space.; |
| 56 | |
| 57 | static double Accumulatorcxx . . $ Accumulator.; |
| 58 | static double LastTimecxx . . $ LastTime.; |
| 59 | int ChipmunkDemoTickscxx . . $ ChipmunkDemoTicks.; |
| 60 | double ChipmunkDemoTimecxx . . $ ChipmunkDemoTime.; |
| 61 | |
| 62 | cpVectcxx . . $ cpVect# ChipmunkDemoMousecxx . . $ ChipmunkDemoMouse.; |
| 63 | cpBoolcxx . . $ cpBool# ChipmunkDemoRightClickcxx . . $ ChipmunkDemoRightClick.; |
| 64 | cpBoolcxx . . $ cpBool# ChipmunkDemoRightDowncxx . . $ ChipmunkDemoRightDown.; |
| 65 | cpVectcxx . . $ cpVect# ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard.; |
| 66 | |
| 67 | static cpBodycxx . . $ cpBody# *mouse_bodycxx . . $ mouse_body. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 68 | static cpConstraintcxx . . $ cpConstraint# *mouse_jointcxx . . $ mouse_joint. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 69 | |
| 70 | char const *ChipmunkDemoMessageStringcxx . . $ ChipmunkDemoMessageString. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 71 | |
| 72 | #define GRABBABLE_MASK_BITcxx . . $ `demo/ChipmunkDemo.c:72:9`! (1<<31) |
| 73 | cpShapeFiltercxx . . $ cpShapeFilter# GRAB_FILTERcxx . . $ GRAB_FILTER. = {CP_NO_GROUPcxx . . $ `include/chipmunk/chipmunk_types.h:228:10`!, GRABBABLE_MASK_BITcxx . . $ `demo/ChipmunkDemo.c:72:9`!, GRABBABLE_MASK_BITcxx . . $ `demo/ChipmunkDemo.c:72:9`!}; |
| 74 | cpShapeFiltercxx . . $ cpShapeFilter# NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER. = {CP_NO_GROUPcxx . . $ `include/chipmunk/chipmunk_types.h:228:10`!, ~GRABBABLE_MASK_BITcxx . . $ `demo/ChipmunkDemo.c:72:9`!, ~GRABBABLE_MASK_BITcxx . . $ `demo/ChipmunkDemo.c:72:9`!}; |
| 75 | |
| 76 | cpVectcxx . . $ cpVect# view_translatecxx . . $ view_translate. = {0, 0}; |
| 77 | cpFloatcxx . . $ cpFloat# view_scalecxx . . $ view_scale. = 1.0; |
| 78 | |
| 79 | static void ShapeFreeWrapcxx . . $ ShapeFreeWrap(2fd42d343383d20).(cpSpacecxx . . $ cpSpace# *space, cpShapecxx . . $ cpShape# *shape, void *unused){ |
| 80 | cpSpaceRemoveShapecxx . . $ cpSpaceRemoveShape(b4590e6760e37cb0).(space, shape); |
| 81 | cpShapeFreecxx . . $ cpShapeFree(49d28a84d341894).(shape); |
| 82 | } |
| 83 | |
| 84 | static void PostShapeFreecxx . . $ PostShapeFree(c2422c69a9cceb8).(cpShapecxx . . $ cpShape# *shape, cpSpacecxx . . $ cpSpace# *space){ |
| 85 | cpSpaceAddPostStepCallbackcxx . . $ cpSpaceAddPostStepCallback(1ff9997ad0bee464).(space, (cpPostStepFunccxx . . $ cpPostStepFunc#)ShapeFreeWrapcxx . . $ ShapeFreeWrap(2fd42d343383d20)., shape, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!); |
| 86 | } |
| 87 | |
| 88 | static void ConstraintFreeWrapcxx . . $ ConstraintFreeWrap(78322303cc2cca01).(cpSpacecxx . . $ cpSpace# *space, cpConstraintcxx . . $ cpConstraint# *constraint, void *unused){ |
| 89 | cpSpaceRemoveConstraintcxx . . $ cpSpaceRemoveConstraint(ab426c857162788d).(space, constraint); |
| 90 | cpConstraintFreecxx . . $ cpConstraintFree(ce362f6e378064c6).(constraint); |
| 91 | } |
| 92 | |
| 93 | static void PostConstraintFreecxx . . $ PostConstraintFree(e6d8226ee831afeb).(cpConstraintcxx . . $ cpConstraint# *constraint, cpSpacecxx . . $ cpSpace# *space){ |
| 94 | cpSpaceAddPostStepCallbackcxx . . $ cpSpaceAddPostStepCallback(1ff9997ad0bee464).(space, (cpPostStepFunccxx . . $ cpPostStepFunc#)ConstraintFreeWrapcxx . . $ ConstraintFreeWrap(78322303cc2cca01)., constraint, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!); |
| 95 | } |
| 96 | |
| 97 | static void BodyFreeWrapcxx . . $ BodyFreeWrap(98cdd5ff45ae5c75).(cpSpacecxx . . $ cpSpace# *space, cpBodycxx . . $ cpBody# *body, void *unused){ |
| 98 | cpSpaceRemoveBodycxx . . $ cpSpaceRemoveBody(f865e61ac2c3a7c6).(space, body); |
| 99 | cpBodyFreecxx . . $ cpBodyFree(92943d3541b63e72).(body); |
| 100 | } |
| 101 | |
| 102 | static void PostBodyFreecxx . . $ PostBodyFree(fb36fbc70fe12e70).(cpBodycxx . . $ cpBody# *body, cpSpacecxx . . $ cpSpace# *space){ |
| 103 | cpSpaceAddPostStepCallbackcxx . . $ cpSpaceAddPostStepCallback(1ff9997ad0bee464).(space, (cpPostStepFunccxx . . $ cpPostStepFunc#)BodyFreeWrapcxx . . $ BodyFreeWrap(98cdd5ff45ae5c75)., body, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!); |
| 104 | } |
| 105 | |
| 106 | // Safe and future proof way to remove and free all objects that have been added to the space. |
| 107 | void |
| 108 | ChipmunkDemoFreeSpaceChildrencxx . . $ ChipmunkDemoFreeSpaceChildren(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 109 | { |
| 110 | // Must remove these BEFORE freeing the body or you will access dangling pointers. |
| 111 | cpSpaceEachShapecxx . . $ cpSpaceEachShape(c89de79254242337).(space, (cpSpaceShapeIteratorFunccxx . . $ cpSpaceShapeIteratorFunc#)PostShapeFreecxx . . $ PostShapeFree(c2422c69a9cceb8)., space); |
| 112 | cpSpaceEachConstraintcxx . . $ cpSpaceEachConstraint(b1831c7c46e49bbc).(space, (cpSpaceConstraintIteratorFunccxx . . $ cpSpaceConstraintIteratorFunc#)PostConstraintFreecxx . . $ PostConstraintFree(e6d8226ee831afeb)., space); |
| 113 | |
| 114 | cpSpaceEachBodycxx . . $ cpSpaceEachBody(ac08ffee037ef35).(space, (cpSpaceBodyIteratorFunccxx . . $ cpSpaceBodyIteratorFunc#)PostBodyFreecxx . . $ PostBodyFree(fb36fbc70fe12e70)., space); |
| 115 | } |
| 116 | |
| 117 | static void |
| 118 | DrawCirclecxx . . $ DrawCircle(fb46142f67a53d74).(cpVectcxx . . $ cpVect# p, cpFloatcxx . . $ cpFloat# a, cpFloatcxx . . $ cpFloat# r, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# outline, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# fill, cpDataPointercxx . . $ cpDataPointer# data) |
| 119 | {ChipmunkDebugDrawCirclecxx . . $ ChipmunkDebugDrawCircle(14e7ba4e04136dff).(p, a, r, outline, fill);} |
| 120 | |
| 121 | static void |
| 122 | DrawSegmentcxx . . $ DrawSegment(15bc27535c85589b).(cpVectcxx . . $ cpVect# a, cpVectcxx . . $ cpVect# b, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# color, cpDataPointercxx . . $ cpDataPointer# data) |
| 123 | {ChipmunkDebugDrawSegmentcxx . . $ ChipmunkDebugDrawSegment(307cf2b0f0a496c2).(a, b, color);} |
| 124 | |
| 125 | static void |
| 126 | DrawFatSegmentcxx . . $ DrawFatSegment(102b85d595d732d1).(cpVectcxx . . $ cpVect# a, cpVectcxx . . $ cpVect# b, cpFloatcxx . . $ cpFloat# r, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# outline, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# fill, cpDataPointercxx . . $ cpDataPointer# data) |
| 127 | {ChipmunkDebugDrawFatSegmentcxx . . $ ChipmunkDebugDrawFatSegment(972494e4e0a31225).(a, b, r, outline, fill);} |
| 128 | |
| 129 | static void |
| 130 | DrawPolygoncxx . . $ DrawPolygon(918ed4529e41d9b6).(int count, const cpVectcxx . . $ cpVect# *verts, cpFloatcxx . . $ cpFloat# r, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# outline, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# fill, cpDataPointercxx . . $ cpDataPointer# data) |
| 131 | {ChipmunkDebugDrawPolygoncxx . . $ ChipmunkDebugDrawPolygon(6db671fc658f3d5c).(count, verts, r, outline, fill);} |
| 132 | |
| 133 | static void |
| 134 | DrawDotcxx . . $ DrawDot(3a420d72503c4d82).(cpFloatcxx . . $ cpFloat# size, cpVectcxx . . $ cpVect# pos, cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# color, cpDataPointercxx . . $ cpDataPointer# data) |
| 135 | {ChipmunkDebugDrawDotcxx . . $ ChipmunkDebugDrawDot(227e9b49eafe2913).(size, pos, color);} |
| 136 | |
| 137 | |
| 138 | static cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# Colorscxx . . $ Colors.[] = { |
| 139 | {0xb5/255.0f, 0x89/255.0f, 0x00/255.0f, 1.0f}, |
| 140 | {0xcb/255.0f, 0x4b/255.0f, 0x16/255.0f, 1.0f}, |
| 141 | {0xdc/255.0f, 0x32/255.0f, 0x2f/255.0f, 1.0f}, |
| 142 | {0xd3/255.0f, 0x36/255.0f, 0x82/255.0f, 1.0f}, |
| 143 | {0x6c/255.0f, 0x71/255.0f, 0xc4/255.0f, 1.0f}, |
| 144 | {0x26/255.0f, 0x8b/255.0f, 0xd2/255.0f, 1.0f}, |
| 145 | {0x2a/255.0f, 0xa1/255.0f, 0x98/255.0f, 1.0f}, |
| 146 | {0x85/255.0f, 0x99/255.0f, 0x00/255.0f, 1.0f}, |
| 147 | }; |
| 148 | |
| 149 | static cpSpaceDebugColorcxx . . $ cpSpaceDebugColor# |
| 150 | ColorForShapecxx . . $ ColorForShape(8ab49622c00263ed).(cpShapecxx . . $ cpShape# *shape, cpDataPointercxx . . $ cpDataPointer# data) |
| 151 | { |
| 152 | if(cpShapeGetSensorcxx . . $ cpShapeGetSensor(1e47cac20e9f9f40).(shape)){ |
| 153 | return LAColorcxx . . $ LAColor(197b9b65f197505a).(1.0f, 0.1f); |
| 154 | } else { |
| 155 | cpBodycxx . . $ cpBody# *body = cpShapeGetBodycxx . . $ cpShapeGetBody(abc772114277478f).(shape); |
| 156 | |
| 157 | if(cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(body)){ |
| 158 | return RGBAColorcxx . . $ RGBAColor(54765961e0537a31).(0x58/255.0f, 0x6e/255.0f, 0x75/255.0f, 1.0f); |
| 159 | } else if(body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. > shape->spacecxx . . $ cpShape#space.->sleepTimeThresholdcxx . . $ cpSpace#sleepTimeThreshold.) { |
| 160 | return RGBAColorcxx . . $ RGBAColor(54765961e0537a31).(0x93/255.0f, 0xa1/255.0f, 0xa1/255.0f, 1.0f); |
| 161 | } else { |
| 162 | uint32_tcxx . . $ uint32_t# val = (uint32_tcxx . . $ uint32_t#)shape->hashidcxx . . $ cpShape#hashid.; |
| 163 | |
| 164 | // scramble the bits up using Robert Jenkins' 32 bit integer hash function |
| 165 | val = (val+0x7ed55d16) + (val<<12); |
| 166 | val = (val^0xc761c23c) ^ (val>>19); |
| 167 | val = (val+0x165667b1) + (val<<5); |
| 168 | val = (val+0xd3a2646c) ^ (val<<9); |
| 169 | val = (val+0xfd7046c5) + (val<<3); |
| 170 | val = (val^0xb55a4f09) ^ (val>>16); |
| 171 | return Colorscxx . . $ Colors.[val & 0x7]; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | void |
| 177 | ChipmunkDemoDefaultDrawImplcxx . . $ ChipmunkDemoDefaultDrawImpl(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 178 | { |
| 179 | cpSpaceDebugDrawOptionscxx . . $ cpSpaceDebugDrawOptions# drawOptions = { |
| 180 | DrawCirclecxx . . $ DrawCircle(fb46142f67a53d74)., |
| 181 | DrawSegmentcxx . . $ DrawSegment(15bc27535c85589b)., |
| 182 | DrawFatSegmentcxx . . $ DrawFatSegment(102b85d595d732d1)., |
| 183 | DrawPolygoncxx . . $ DrawPolygon(918ed4529e41d9b6)., |
| 184 | DrawDotcxx . . $ DrawDot(3a420d72503c4d82)., |
| 185 | |
| 186 | (cpSpaceDebugDrawFlagscxx . . $ cpSpaceDebugDrawFlags#)(CP_SPACE_DEBUG_DRAW_SHAPEScxx . . $ CP_SPACE_DEBUG_DRAW_SHAPES. | CP_SPACE_DEBUG_DRAW_CONSTRAINTScxx . . $ CP_SPACE_DEBUG_DRAW_CONSTRAINTS. | CP_SPACE_DEBUG_DRAW_COLLISION_POINTScxx . . $ CP_SPACE_DEBUG_DRAW_COLLISION_POINTS.), |
| 187 | |
| 188 | {0xEE/255.0f, 0xE8/255.0f, 0xD5/255.0f, 1.0f}, // Outline color |
| 189 | ColorForShapecxx . . $ ColorForShape(8ab49622c00263ed)., |
| 190 | {0.0f, 0.75f, 0.0f, 1.0f}, // Constraint color |
| 191 | {1.0f, 0.0f, 0.0f, 1.0f}, // Collision point color |
| 192 | NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, |
| 193 | }; |
| 194 | |
| 195 | cpSpaceDebugDrawcxx . . $ cpSpaceDebugDraw(65c744a1b54fb2ad).(space, &drawOptions); |
| 196 | } |
| 197 | |
| 198 | static void |
| 199 | DrawInstructionscxx . . $ DrawInstructions(d878ad36e69247c7).() |
| 200 | { |
| 201 | static char title[1024]; |
| 202 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(title, "Demo(%c): %s", 'A' + demo_indexcxx . . $ demo_index., demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].namecxx . . $ ChipmunkDemo#name.); |
| 203 | ChipmunkDemoTextDrawStringcxx . . $ ChipmunkDemoTextDrawString(ba6331894cb75a04).(cpvcxx . . $ cpv(3142d57d978b2176).(-300, 220), title); |
| 204 | |
| 205 | ChipmunkDemoTextDrawStringcxx . . $ ChipmunkDemoTextDrawString(ba6331894cb75a04).(cpvcxx . . $ cpv(3142d57d978b2176).(-300, 200), |
| 206 | "Controls:\n" |
| 207 | "A - Z Switch demos. (return restarts)\n" |
| 208 | "Use the mouse to grab objects.\n" |
| 209 | ); |
| 210 | } |
| 211 | |
| 212 | static int max_arbiterscxx . . $ max_arbiters. = 0; |
| 213 | static int max_pointscxx . . $ max_points. = 0; |
| 214 | static int max_constraintscxx . . $ max_constraints. = 0; |
| 215 | |
| 216 | static void |
| 217 | DrawInfocxx . . $ DrawInfo(d878ad36e69247c7).() |
| 218 | { |
| 219 | int arbiters = spacecxx . . $ space.->arbiterscxx . . $ cpSpace#arbiters.->numcxx . . $ cpArray#num.; |
| 220 | int points = 0; |
| 221 | |
| 222 | for(int i=0; i<arbiters; i++) |
| 223 | points += ((cpArbitercxx . . $ cpArbiter# *)(spacecxx . . $ space.->arbiterscxx . . $ cpSpace#arbiters.->arrcxx . . $ cpArray#arr.[i]))->countcxx . . $ cpArbiter#count.; |
| 224 | |
| 225 | int constraints = (spacecxx . . $ space.->constraintscxx . . $ cpSpace#constraints.->numcxx . . $ cpArray#num. + points)*spacecxx . . $ space.->iterationscxx . . $ cpSpace#iterations.; |
| 226 | |
| 227 | max_arbiterscxx . . $ max_arbiters. = arbiters > max_arbiterscxx . . $ max_arbiters. ? arbiters : max_arbiterscxx . . $ max_arbiters.; |
| 228 | max_pointscxx . . $ max_points. = points > max_pointscxx . . $ max_points. ? points : max_pointscxx . . $ max_points.; |
| 229 | max_constraintscxx . . $ max_constraints. = constraints > max_constraintscxx . . $ max_constraints. ? constraints : max_constraintscxx . . $ max_constraints.; |
| 230 | |
| 231 | char buffer[1024]; |
| 232 | const char *format = |
| 233 | "Arbiters: %d (%d) - " |
| 234 | "Contact Points: %d (%d)\n" |
| 235 | "Other Constraints: %d, Iterations: %d\n" |
| 236 | "Constraints x Iterations: %d (%d)\n" |
| 237 | "Time:% 5.2fs, KE:% 5.2e"; |
| 238 | |
| 239 | cpArraycxx . . $ cpArray# *bodies = spacecxx . . $ space.->dynamicBodiescxx . . $ cpSpace#dynamicBodies.; |
| 240 | cpFloatcxx . . $ cpFloat# ke = 0.0f; |
| 241 | for(int i=0; i<bodies->numcxx . . $ cpArray#num.; i++){ |
| 242 | cpBodycxx . . $ cpBody# *body = (cpBodycxx . . $ cpBody# *)bodies->arrcxx . . $ cpArray#arr.[i]; |
| 243 | if(body->mcxx . . $ cpBody#m. == INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`! || body->icxx . . $ cpBody#i. == INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!) continue; |
| 244 | |
| 245 | ke += body->mcxx . . $ cpBody#m.*cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(body->vcxx . . $ cpBody#v., body->vcxx . . $ cpBody#v.) + body->icxx . . $ cpBody#i.*body->wcxx . . $ cpBody#w.*body->wcxx . . $ cpBody#w.; |
| 246 | } |
| 247 | |
| 248 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(buffer, format, |
| 249 | arbiters, max_arbiterscxx . . $ max_arbiters., |
| 250 | points, max_pointscxx . . $ max_points., |
| 251 | spacecxx . . $ space.->constraintscxx . . $ cpSpace#constraints.->numcxx . . $ cpArray#num., spacecxx . . $ space.->iterationscxx . . $ cpSpace#iterations., |
| 252 | constraints, max_constraintscxx . . $ max_constraints., |
| 253 | ChipmunkDemoTimecxx . . $ ChipmunkDemoTime., (ke < 1e-10f ? 0.0f : ke) |
| 254 | ); |
| 255 | |
| 256 | ChipmunkDemoTextDrawStringcxx . . $ ChipmunkDemoTextDrawString(ba6331894cb75a04).(cpvcxx . . $ cpv(3142d57d978b2176).(0, 220), buffer); |
| 257 | } |
| 258 | |
| 259 | static char PrintStringBuffercxx . . $ PrintStringBuffer.[1024*8]; |
| 260 | static char *PrintStringCursorcxx . . $ PrintStringCursor.; |
| 261 | |
| 262 | void |
| 263 | ChipmunkDemoPrintStringcxx . . $ ChipmunkDemoPrintString(326aeb464d16410c).(char const *fmt, ...) |
| 264 | { |
| 265 | if (PrintStringCursorcxx . . $ PrintStringCursor. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) { |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | ChipmunkDemoMessageStringcxx . . $ ChipmunkDemoMessageString. = PrintStringBuffercxx . . $ PrintStringBuffer.; |
| 270 | |
| 271 | va_listcxx . . $ va_list# args; |
| 272 | va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stdarg.h:51:9`!(args, fmt); |
| 273 | int remaining = sizeof(PrintStringBuffercxx . . $ PrintStringBuffer.) - (PrintStringCursorcxx . . $ PrintStringCursor. - PrintStringBuffercxx . . $ PrintStringBuffer.); |
| 274 | int would_write = vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(PrintStringCursorcxx . . $ PrintStringCursor., remaining, fmt, args); |
| 275 | if (would_write > 0 && would_write < remaining) { |
| 276 | PrintStringCursorcxx . . $ PrintStringCursor. += would_write; |
| 277 | } else { |
| 278 | // encoding error or overflow, prevent further use until reinitialized |
| 279 | PrintStringCursorcxx . . $ PrintStringCursor. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 280 | } |
| 281 | va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stdarg.h:53:9`!(args); |
| 282 | } |
| 283 | |
| 284 | static void |
| 285 | Tickcxx . . $ Tick(ba8836b59fb42830).(double dt) |
| 286 | { |
| 287 | if(!pausedcxx . . $ paused. || stepcxx . . $ step.){ |
| 288 | PrintStringBuffercxx . . $ PrintStringBuffer.[0] = 0; |
| 289 | PrintStringCursorcxx . . $ PrintStringCursor. = PrintStringBuffercxx . . $ PrintStringBuffer.; |
| 290 | |
| 291 | // Completely reset the renderer only at the beginning of a tick. |
| 292 | // That way it can always display at least the last ticks' debug drawing. |
| 293 | ChipmunkDebugDrawClearRenderercxx . . $ ChipmunkDebugDrawClearRenderer(49f6e7a06ebc5aa8).(); |
| 294 | ChipmunkDemoTextClearRenderercxx . . $ ChipmunkDemoTextClearRenderer(49f6e7a06ebc5aa8).(); |
| 295 | |
| 296 | cpVectcxx . . $ cpVect# new_point = cpvlerpcxx . . $ cpvlerp(12b05c0b9acd6d4b).(mouse_bodycxx . . $ mouse_body.->pcxx . . $ cpBody#p., ChipmunkDemoMousecxx . . $ ChipmunkDemoMouse., 0.25f); |
| 297 | mouse_bodycxx . . $ mouse_body.->vcxx . . $ cpBody#v. = cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(new_point, mouse_bodycxx . . $ mouse_body.->pcxx . . $ cpBody#p.), 60.0f); |
| 298 | mouse_bodycxx . . $ mouse_body.->pcxx . . $ cpBody#p. = new_point; |
| 299 | |
| 300 | demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].updateFunccxx . . $ ChipmunkDemo#updateFunc.(spacecxx . . $ space., dt); |
| 301 | |
| 302 | ChipmunkDemoTickscxx . . $ ChipmunkDemoTicks.++; |
| 303 | ChipmunkDemoTimecxx . . $ ChipmunkDemoTime. += dt; |
| 304 | |
| 305 | stepcxx . . $ step. = cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 306 | ChipmunkDemoRightDowncxx . . $ ChipmunkDemoRightDown. = cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 307 | |
| 308 | ChipmunkDemoTextDrawStringcxx . . $ ChipmunkDemoTextDrawString(ba6331894cb75a04).(cpvcxx . . $ cpv(3142d57d978b2176).(-300, -200), ChipmunkDemoMessageStringcxx . . $ ChipmunkDemoMessageString.); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | static void |
| 313 | Updatecxx . . $ Update(49f6e7a06ebc5aa8).(void) |
| 314 | { |
| 315 | double time = stm_seccxx . . $ stm_sec(78051de35c49feff).(stm_nowcxx . . $ stm_now(f708dce9a8856c70).()); |
| 316 | double dt = time - LastTimecxx . . $ LastTime.; |
| 317 | if(dt > 0.2) dt = 0.2; |
| 318 | |
| 319 | double fixed_dt = demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].timestepcxx . . $ ChipmunkDemo#timestep.; |
| 320 | |
| 321 | for(Accumulatorcxx . . $ Accumulator. += dt; Accumulatorcxx . . $ Accumulator. > fixed_dt; Accumulatorcxx . . $ Accumulator. -= fixed_dt){ |
| 322 | Tickcxx . . $ Tick(ba8836b59fb42830).(fixed_dt); |
| 323 | } |
| 324 | |
| 325 | LastTimecxx . . $ LastTime. = time; |
| 326 | } |
| 327 | |
| 328 | static void |
| 329 | Displaycxx . . $ Display(49f6e7a06ebc5aa8).(void) |
| 330 | { |
| 331 | cpVectcxx . . $ cpVect# screen_size = {sapp_widthcxx . . $ sapp_width(b126dc7c1de90089).(), sapp_heightcxx . . $ sapp_height(b126dc7c1de90089).()}; |
| 332 | cpTransformcxx . . $ cpTransform# view_matrix = cpTransformMultcxx . . $ cpTransformMult(6ca748ec370be7bf).(cpTransformScalecxx . . $ cpTransformScale(bb22bad472590b26).(view_scalecxx . . $ view_scale., view_scalecxx . . $ view_scale.), cpTransformTranslatecxx . . $ cpTransformTranslate(9ddf098b65af1f2f).(view_translatecxx . . $ view_translate.)); |
| 333 | |
| 334 | float screen_scale = (float)cpfmincxx . . $ cpfmin(d8e7e0733fa41c87).(screen_size.xcxx . . $ cpVect#x./640.0, screen_size.ycxx . . $ cpVect#y./480.0); |
| 335 | float hw = (float)screen_size.xcxx . . $ cpVect#x.*(0.5f/screen_scale); |
| 336 | float hh = (float)screen_size.ycxx . . $ cpVect#y.*(0.5f/screen_scale); |
| 337 | cpTransformcxx . . $ cpTransform# projection_matrix = cpTransformOrthocxx . . $ cpTransformOrtho(33751de6f6f25f9d).(cpBBNewcxx . . $ cpBBNew(f05aa3203068e6d3).(-hw, -hh, hw, hh)); |
| 338 | |
| 339 | ChipmunkDebugDrawPointLineScalecxx . . $ ChipmunkDebugDrawPointLineScale. = 1.0f/(float)view_scalecxx . . $ view_scale.; |
| 340 | ChipmunkDebugDrawVPMatrixcxx . . $ ChipmunkDebugDrawVPMatrix. = cpTransformMultcxx . . $ cpTransformMult(6ca748ec370be7bf).(projection_matrix, view_matrix); |
| 341 | |
| 342 | Updatecxx . . $ Update(49f6e7a06ebc5aa8).(); |
| 343 | |
| 344 | // Save the drawing commands from the most recent tick. |
| 345 | ChipmunkDebugDrawPushRenderercxx . . $ ChipmunkDebugDrawPushRenderer(49f6e7a06ebc5aa8).(); |
| 346 | ChipmunkDemoTextPushRenderercxx . . $ ChipmunkDemoTextPushRenderer(49f6e7a06ebc5aa8).(); |
| 347 | demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].drawFunccxx . . $ ChipmunkDemo#drawFunc.(spacecxx . . $ space.); |
| 348 | |
| 349 | // // Highlight the shape under the mouse because it looks neat. |
| 350 | // cpShape *nearest = cpSpacePointQueryNearest(space, ChipmunkDemoMouse, 0.0f, CP_ALL_LAYERS, CP_NO_GROUP, NULL); |
| 351 | // if(nearest) ChipmunkDebugDrawShape(nearest, RGBAColor(1.0f, 0.0f, 0.0f, 1.0f), LAColor(0.0f, 0.0f)); |
| 352 | |
| 353 | sg_pass_actioncxx . . $ sg_pass_action# action = { |
| 354 | .colors[0] = {.action = SG_ACTION_CLEARcxx . . $ SG_ACTION_CLEAR., .val = {0x07/255.0f, 0x36/255.0f, 0x42/255.0f}}, |
| 355 | }; |
| 356 | sg_begin_default_passcxx . . $ sg_begin_default_pass(2956e7fd84f328a).(&action, (int)screen_size.xcxx . . $ cpVect#x., (int)screen_size.ycxx . . $ cpVect#y.); |
| 357 | |
| 358 | // Draw the renderer contents and reset it back to the last tick's state. |
| 359 | ChipmunkDebugDrawFlushRenderercxx . . $ ChipmunkDebugDrawFlushRenderer(49f6e7a06ebc5aa8).(); |
| 360 | |
| 361 | // // Now render all the UI text. |
| 362 | DrawInstructionscxx . . $ DrawInstructions(d878ad36e69247c7).(); |
| 363 | DrawInfocxx . . $ DrawInfo(d878ad36e69247c7).(); |
| 364 | |
| 365 | ChipmunkDemoTextMatrixcxx . . $ ChipmunkDemoTextMatrix. = projection_matrix; |
| 366 | ChipmunkDemoTextFlushRenderercxx . . $ ChipmunkDemoTextFlushRenderer(49f6e7a06ebc5aa8).(); |
| 367 | |
| 368 | ChipmunkDebugDrawPopRenderercxx . . $ ChipmunkDebugDrawPopRenderer(49f6e7a06ebc5aa8).(); |
| 369 | ChipmunkDemoTextPopRenderercxx . . $ ChipmunkDemoTextPopRenderer(49f6e7a06ebc5aa8).(); |
| 370 | |
| 371 | sg_end_passcxx . . $ sg_end_pass(49f6e7a06ebc5aa8).(); |
| 372 | sg_commitcxx . . $ sg_commit(49f6e7a06ebc5aa8).(); |
| 373 | } |
| 374 | |
| 375 | static void |
| 376 | RunDemocxx . . $ RunDemo(d4f767463ce0a6b3).(int index) |
| 377 | { |
| 378 | srandcxx . . $ srand(cb2f890c2fdad230).(45073); |
| 379 | |
| 380 | demo_indexcxx . . $ demo_index. = index; |
| 381 | |
| 382 | ChipmunkDemoTickscxx . . $ ChipmunkDemoTicks. = 0; |
| 383 | ChipmunkDemoTimecxx . . $ ChipmunkDemoTime. = 0.0; |
| 384 | Accumulatorcxx . . $ Accumulator. = 0.0; |
| 385 | LastTimecxx . . $ LastTime. = stm_seccxx . . $ stm_sec(78051de35c49feff).(stm_nowcxx . . $ stm_now(f708dce9a8856c70).()); |
| 386 | |
| 387 | mouse_jointcxx . . $ mouse_joint. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 388 | ChipmunkDemoMessageStringcxx . . $ ChipmunkDemoMessageString. = ""; |
| 389 | max_arbiterscxx . . $ max_arbiters. = 0; |
| 390 | max_pointscxx . . $ max_points. = 0; |
| 391 | max_constraintscxx . . $ max_constraints. = 0; |
| 392 | spacecxx . . $ space. = demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].initFunccxx . . $ ChipmunkDemo#initFunc.(); |
| 393 | |
| 394 | // Not supported by Sokol yet. |
| 395 | // static char title[1024]; |
| 396 | // sprintf(title, "Demo(%c): %s", 'a' + demo_index, demos[demo_index].name); |
| 397 | } |
| 398 | |
| 399 | static void |
| 400 | Keyboardcxx . . $ Keyboard(241e5018601f13a4).(const sapp_eventcxx . . $ sapp_event# *event) |
| 401 | { |
| 402 | float translate_increment = 50.0f/(float)view_scalecxx . . $ view_scale.; |
| 403 | float scale_increment = 1.2f; |
| 404 | |
| 405 | if(event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_CHARcxx . . $ SAPP_EVENTTYPE_CHAR. && !event->key_repeatcxx . . $ sapp_event#key_repeat.){ |
| 406 | int index = event->char_codecxx . . $ sapp_event#char_code. - 'a'; |
| 407 | if(0 <= index && index < demo_countcxx . . $ demo_count.){ |
| 408 | demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].destroyFunccxx . . $ ChipmunkDemo#destroyFunc.(spacecxx . . $ space.); |
| 409 | RunDemocxx . . $ RunDemo(d4f767463ce0a6b3).(index); |
| 410 | } |
| 411 | } else if(event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_KEY_DOWNcxx . . $ SAPP_EVENTTYPE_KEY_DOWN.){ |
| 412 | switch(event->key_codecxx . . $ sapp_event#key_code.){ |
| 413 | case SAPP_KEYCODE_SPACEcxx . . $ SAPP_KEYCODE_SPACE.:{ |
| 414 | if(!event->key_repeatcxx . . $ sapp_event#key_repeat.){ |
| 415 | demoscxx . . $ demos.[demo_indexcxx . . $ demo_index.].destroyFunccxx . . $ ChipmunkDemo#destroyFunc.(spacecxx . . $ space.); |
| 416 | RunDemocxx . . $ RunDemo(d4f767463ce0a6b3).(demo_indexcxx . . $ demo_index.); |
| 417 | } |
| 418 | } break; |
| 419 | case SAPP_KEYCODE_GRAVE_ACCENTcxx . . $ SAPP_KEYCODE_GRAVE_ACCENT. : { |
| 420 | if(!event->key_repeatcxx . . $ sapp_event#key_repeat.) pausedcxx . . $ paused. = !pausedcxx . . $ paused.; |
| 421 | } break; |
| 422 | case SAPP_KEYCODE_1cxx . . $ SAPP_KEYCODE_1.: { |
| 423 | stepcxx . . $ step. = cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 424 | } break; |
| 425 | |
| 426 | case SAPP_KEYCODE_KP_4cxx . . $ SAPP_KEYCODE_KP_4.: view_translatecxx . . $ view_translate..xcxx . . $ cpVect#x. += translate_increment; break; |
| 427 | case SAPP_KEYCODE_KP_6cxx . . $ SAPP_KEYCODE_KP_6.: view_translatecxx . . $ view_translate..xcxx . . $ cpVect#x. -= translate_increment; break; |
| 428 | case SAPP_KEYCODE_KP_2cxx . . $ SAPP_KEYCODE_KP_2.: view_translatecxx . . $ view_translate..ycxx . . $ cpVect#y. += translate_increment; break; |
| 429 | case SAPP_KEYCODE_KP_8cxx . . $ SAPP_KEYCODE_KP_8.: view_translatecxx . . $ view_translate..ycxx . . $ cpVect#y. -= translate_increment; break; |
| 430 | case SAPP_KEYCODE_KP_7cxx . . $ SAPP_KEYCODE_KP_7.: view_scalecxx . . $ view_scale. /= scale_increment; break; |
| 431 | case SAPP_KEYCODE_KP_9cxx . . $ SAPP_KEYCODE_KP_9.: view_scalecxx . . $ view_scale. *= scale_increment; break; |
| 432 | case SAPP_KEYCODE_KP_5cxx . . $ SAPP_KEYCODE_KP_5.: { |
| 433 | view_translatecxx . . $ view_translate..xcxx . . $ cpVect#x. = 0.0f; |
| 434 | view_translatecxx . . $ view_translate..ycxx . . $ cpVect#y. = 0.0f; |
| 435 | view_scalecxx . . $ view_scale. = 1.0f; |
| 436 | } break; |
| 437 | |
| 438 | default: break; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | if(!event->key_repeatcxx . . $ sapp_event#key_repeat.){ |
| 443 | switch(event->key_codecxx . . $ sapp_event#key_code.){ |
| 444 | case SAPP_KEYCODE_UPcxx . . $ SAPP_KEYCODE_UP. : ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard..ycxx . . $ cpVect#y. += (event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_KEY_DOWNcxx . . $ SAPP_EVENTTYPE_KEY_DOWN. ? 1.0 : -1.0); break; |
| 445 | case SAPP_KEYCODE_DOWNcxx . . $ SAPP_KEYCODE_DOWN. : ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard..ycxx . . $ cpVect#y. += (event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_KEY_DOWNcxx . . $ SAPP_EVENTTYPE_KEY_DOWN. ? -1.0 : 1.0); break; |
| 446 | case SAPP_KEYCODE_LEFTcxx . . $ SAPP_KEYCODE_LEFT. : ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard..xcxx . . $ cpVect#x. += (event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_KEY_DOWNcxx . . $ SAPP_EVENTTYPE_KEY_DOWN. ? -1.0 : 1.0); break; |
| 447 | case SAPP_KEYCODE_RIGHTcxx . . $ SAPP_KEYCODE_RIGHT. : ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard..xcxx . . $ cpVect#x. += (event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_KEY_DOWNcxx . . $ SAPP_EVENTTYPE_KEY_DOWN. ? 1.0 : -1.0); break; |
| 448 | default: break; |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | static cpVectcxx . . $ cpVect# |
| 454 | MouseToSpacecxx . . $ MouseToSpace(84d60b906bf81a4a).(const sapp_eventcxx . . $ sapp_event# *event) |
| 455 | { |
| 456 | // Calculate clip coord for mouse. |
| 457 | cpVectcxx . . $ cpVect# screen_size = cpvcxx . . $ cpv(3142d57d978b2176).(sapp_widthcxx . . $ sapp_width(b126dc7c1de90089).(), sapp_heightcxx . . $ sapp_height(b126dc7c1de90089).()); |
| 458 | cpVectcxx . . $ cpVect# clip_coord = cpvcxx . . $ cpv(3142d57d978b2176).(2*event->mouse_xcxx . . $ sapp_event#mouse_x./screen_size.xcxx . . $ cpVect#x. - 1, 1 - 2*event->mouse_ycxx . . $ sapp_event#mouse_y./screen_size.ycxx . . $ cpVect#y.); |
| 459 | |
| 460 | // Use the VP matrix to transform to world space. |
| 461 | cpTransformcxx . . $ cpTransform# vp_inverse = cpTransformInversecxx . . $ cpTransformInverse(3d60147e912b055a).(ChipmunkDebugDrawVPMatrixcxx . . $ ChipmunkDebugDrawVPMatrix.); |
| 462 | return cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(vp_inverse, clip_coord); |
| 463 | } |
| 464 | |
| 465 | static void |
| 466 | Clickcxx . . $ Click(241e5018601f13a4).(const sapp_eventcxx . . $ sapp_event# *event) |
| 467 | { |
| 468 | cpVectcxx . . $ cpVect# mouse_pos = MouseToSpacecxx . . $ MouseToSpace(84d60b906bf81a4a).(event); |
| 469 | |
| 470 | if(event->mouse_buttoncxx . . $ sapp_event#mouse_button. == SAPP_MOUSEBUTTON_LEFTcxx . . $ SAPP_MOUSEBUTTON_LEFT.){ |
| 471 | if(event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_MOUSE_DOWNcxx . . $ SAPP_EVENTTYPE_MOUSE_DOWN.){ |
| 472 | // give the mouse click a little radius to make it easier to click small shapes. |
| 473 | cpFloatcxx . . $ cpFloat# radius = 5.0; |
| 474 | |
| 475 | cpPointQueryInfocxx . . $ cpPointQueryInfo# info = {0}; |
| 476 | cpShapecxx . . $ cpShape# *shape = cpSpacePointQueryNearestcxx . . $ cpSpacePointQueryNearest(b0e549d484789d).(spacecxx . . $ space., mouse_pos, radius, GRAB_FILTERcxx . . $ GRAB_FILTER., &info); |
| 477 | |
| 478 | if(shape && cpBodyGetMasscxx . . $ cpBodyGetMass(2880d7999e0b34c3).(cpShapeGetBodycxx . . $ cpShapeGetBody(abc772114277478f).(shape)) < INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!){ |
| 479 | // Use the closest point on the surface if the click is outside of the shape. |
| 480 | cpVectcxx . . $ cpVect# nearest = (info.distancecxx . . $ cpPointQueryInfo#distance. > 0.0f ? info.pointcxx . . $ cpPointQueryInfo#point. : mouse_pos); |
| 481 | |
| 482 | cpBodycxx . . $ cpBody# *body = cpShapeGetBodycxx . . $ cpShapeGetBody(abc772114277478f).(shape); |
| 483 | mouse_jointcxx . . $ mouse_joint. = cpPivotJointNew2cxx . . $ cpPivotJointNew2(74f6d8fa0e302020).(mouse_bodycxx . . $ mouse_body., body, cpvzerocxx . . $ cpvzero., cpBodyWorldToLocalcxx . . $ cpBodyWorldToLocal(4ff4900d49a97e73).(body, nearest)); |
| 484 | mouse_jointcxx . . $ mouse_joint.->maxForcecxx . . $ cpConstraint#maxForce. = 50000.0f; |
| 485 | mouse_jointcxx . . $ mouse_joint.->errorBiascxx . . $ cpConstraint#errorBias. = cpfpowcxx . . $ `include/chipmunk/chipmunk_types.h:75:10`!(1.0f - 0.15f, 60.0f); |
| 486 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(spacecxx . . $ space., mouse_jointcxx . . $ mouse_joint.); |
| 487 | } |
| 488 | } else if(mouse_jointcxx . . $ mouse_joint.){ |
| 489 | cpSpaceRemoveConstraintcxx . . $ cpSpaceRemoveConstraint(ab426c857162788d).(spacecxx . . $ space., mouse_jointcxx . . $ mouse_joint.); |
| 490 | cpConstraintFreecxx . . $ cpConstraintFree(ce362f6e378064c6).(mouse_jointcxx . . $ mouse_joint.); |
| 491 | mouse_jointcxx . . $ mouse_joint. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 492 | } |
| 493 | } else if(event->mouse_buttoncxx . . $ sapp_event#mouse_button. == SAPP_MOUSEBUTTON_RIGHTcxx . . $ SAPP_MOUSEBUTTON_RIGHT.){ |
| 494 | ChipmunkDemoRightDowncxx . . $ ChipmunkDemoRightDown. = ChipmunkDemoRightClickcxx . . $ ChipmunkDemoRightClick. = (event->typecxx . . $ sapp_event#type. == SAPP_EVENTTYPE_MOUSE_DOWNcxx . . $ SAPP_EVENTTYPE_MOUSE_DOWN.); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | static void |
| 499 | Eventcxx . . $ Event(241e5018601f13a4).(const sapp_eventcxx . . $ sapp_event# *event) |
| 500 | { |
| 501 | switch(event->typecxx . . $ sapp_event#type.){ |
| 502 | case SAPP_EVENTTYPE_CHARcxx . . $ SAPP_EVENTTYPE_CHAR.: |
| 503 | case SAPP_EVENTTYPE_KEY_UPcxx . . $ SAPP_EVENTTYPE_KEY_UP.: |
| 504 | case SAPP_EVENTTYPE_KEY_DOWNcxx . . $ SAPP_EVENTTYPE_KEY_DOWN.: { |
| 505 | Keyboardcxx . . $ Keyboard(241e5018601f13a4).(event); |
| 506 | } break; |
| 507 | |
| 508 | case SAPP_EVENTTYPE_MOUSE_MOVEcxx . . $ SAPP_EVENTTYPE_MOUSE_MOVE.: { |
| 509 | ChipmunkDemoMousecxx . . $ ChipmunkDemoMouse. = MouseToSpacecxx . . $ MouseToSpace(84d60b906bf81a4a).(event); |
| 510 | }; break; |
| 511 | |
| 512 | case SAPP_EVENTTYPE_MOUSE_UPcxx . . $ SAPP_EVENTTYPE_MOUSE_UP.: |
| 513 | case SAPP_EVENTTYPE_MOUSE_DOWNcxx . . $ SAPP_EVENTTYPE_MOUSE_DOWN.: { |
| 514 | Clickcxx . . $ Click(241e5018601f13a4).(event); |
| 515 | } break; |
| 516 | |
| 517 | default: break; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | static void |
| 522 | TimeTrialcxx . . $ TimeTrial(3e454b8ccf442868).(int index, int count) |
| 523 | { |
| 524 | spacecxx . . $ space. = demoscxx . . $ demos.[index].initFunccxx . . $ ChipmunkDemo#initFunc.(); |
| 525 | |
| 526 | double start_time = stm_seccxx . . $ stm_sec(78051de35c49feff).(stm_nowcxx . . $ stm_now(f708dce9a8856c70).()); |
| 527 | double dt = demoscxx . . $ demos.[index].timestepcxx . . $ ChipmunkDemo#timestep.; |
| 528 | |
| 529 | for(int i=0; i<count; i++) |
| 530 | demoscxx . . $ demos.[index].updateFunccxx . . $ ChipmunkDemo#updateFunc.(spacecxx . . $ space., dt); |
| 531 | |
| 532 | double end_time = stm_seccxx . . $ stm_sec(78051de35c49feff).(stm_nowcxx . . $ stm_now(f708dce9a8856c70).()); |
| 533 | |
| 534 | demoscxx . . $ demos.[index].destroyFunccxx . . $ ChipmunkDemo#destroyFunc.(spacecxx . . $ space.); |
| 535 | |
| 536 | printfcxx . . $ printf(581fddd72a8db8fc).("Time(%c) = %8.2f ms (%s)\n", index + 'a', (end_time - start_time)*1e3f, demoscxx . . $ demos.[index].namecxx . . $ ChipmunkDemo#name.); |
| 537 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!); |
| 538 | } |
| 539 | |
| 540 | extern ChipmunkDemocxx . . $ ChipmunkDemo# LogoSmashcxx . . $ LogoSmash.; |
| 541 | extern ChipmunkDemocxx . . $ ChipmunkDemo# PyramidStackcxx . . $ PyramidStack.; |
| 542 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Plinkcxx . . $ Plink.; |
| 543 | extern ChipmunkDemocxx . . $ ChipmunkDemo# BouncyHexagonscxx . . $ BouncyHexagons.; |
| 544 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Tumblecxx . . $ Tumble.; |
| 545 | extern ChipmunkDemocxx . . $ ChipmunkDemo# PyramidTopplecxx . . $ PyramidTopple.; |
| 546 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Planetcxx . . $ Planet.; |
| 547 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Springiescxx . . $ Springies.; |
| 548 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Pumpcxx . . $ Pump.; |
| 549 | extern ChipmunkDemocxx . . $ ChipmunkDemo# TheoJansencxx . . $ TheoJansen.; |
| 550 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Querycxx . . $ Query.; |
| 551 | extern ChipmunkDemocxx . . $ ChipmunkDemo# OneWaycxx . . $ OneWay.; |
| 552 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Playercxx . . $ Player.; |
| 553 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Jointscxx . . $ Joints.; |
| 554 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Tankcxx . . $ Tank.; |
| 555 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Chainscxx . . $ Chains.; |
| 556 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Cranecxx . . $ Crane.; |
| 557 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Buoyancycxx . . $ Buoyancy.; |
| 558 | extern ChipmunkDemocxx . . $ ChipmunkDemo# ContactGraphcxx . . $ ContactGraph.; |
| 559 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Slicecxx . . $ Slice.; |
| 560 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Convexcxx . . $ Convex.; |
| 561 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Unicyclecxx . . $ Unicycle.; |
| 562 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Stickycxx . . $ Sticky.; |
| 563 | extern ChipmunkDemocxx . . $ ChipmunkDemo# Shattercxx . . $ Shatter.; |
| 564 | extern ChipmunkDemocxx . . $ ChipmunkDemo# GJKcxx . . $ GJK.; |
| 565 | |
| 566 | extern ChipmunkDemocxx . . $ ChipmunkDemo# bench_listcxx . . $ bench_list.[]; |
| 567 | extern int bench_countcxx . . $ bench_count.; |
| 568 | |
| 569 | static void |
| 570 | Initcxx . . $ Init(49f6e7a06ebc5aa8).(void) |
| 571 | { |
| 572 | sg_desccxx . . $ sg_desc# desc = {0}; |
| 573 | sg_setupcxx . . $ sg_setup(14daf3ac2a73e58e).(&desc); |
| 574 | cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(sg_isvalid(), "Could not init Sokol GFX."); |
| 575 | |
| 576 | ChipmunkDebugDrawInitcxx . . $ ChipmunkDebugDrawInit(49f6e7a06ebc5aa8).(); |
| 577 | ChipmunkDemoTextInitcxx . . $ ChipmunkDemoTextInit(49f6e7a06ebc5aa8).(); |
| 578 | |
| 579 | mouse_bodycxx . . $ mouse_body. = cpBodyNewKinematiccxx . . $ cpBodyNewKinematic(af6db6e743345a49).(); |
| 580 | RunDemocxx . . $ RunDemo(d4f767463ce0a6b3).(demo_indexcxx . . $ demo_index.); |
| 581 | } |
| 582 | |
| 583 | void Cleanupcxx . . $ Cleanup(49f6e7a06ebc5aa8).(void) { |
| 584 | sg_shutdowncxx . . $ sg_shutdown(49f6e7a06ebc5aa8).(); |
| 585 | } |
| 586 | |
| 587 | sapp_desccxx . . $ sapp_desc# sokol_maincxx . . $ sokol_main(de724fcec28caf22).(int argc, char* argv[]) { |
| 588 | demoscxx . . $ demos.[ 0] = LogoSmashcxx . . $ LogoSmash.; //A |
| 589 | demoscxx . . $ demos.[ 1] = PyramidStackcxx . . $ PyramidStack.; //B |
| 590 | demoscxx . . $ demos.[ 2] = Plinkcxx . . $ Plink.; //C |
| 591 | demoscxx . . $ demos.[ 3] = BouncyHexagonscxx . . $ BouncyHexagons.; //D |
| 592 | demoscxx . . $ demos.[ 4] = Tumblecxx . . $ Tumble.; //E |
| 593 | demoscxx . . $ demos.[ 5] = PyramidTopplecxx . . $ PyramidTopple.; //F |
| 594 | demoscxx . . $ demos.[ 6] = Planetcxx . . $ Planet.; //G |
| 595 | demoscxx . . $ demos.[ 7] = Springiescxx . . $ Springies.; //H |
| 596 | demoscxx . . $ demos.[ 8] = Pumpcxx . . $ Pump.; //I |
| 597 | demoscxx . . $ demos.[ 9] = TheoJansencxx . . $ TheoJansen.; //J |
| 598 | demoscxx . . $ demos.[10] = Querycxx . . $ Query.; //K |
| 599 | demoscxx . . $ demos.[11] = OneWaycxx . . $ OneWay.; //L |
| 600 | demoscxx . . $ demos.[12] = Jointscxx . . $ Joints.; //M |
| 601 | demoscxx . . $ demos.[13] = Tankcxx . . $ Tank.; //N |
| 602 | demoscxx . . $ demos.[14] = Chainscxx . . $ Chains.; //O |
| 603 | demoscxx . . $ demos.[15] = Cranecxx . . $ Crane.; //P |
| 604 | demoscxx . . $ demos.[16] = ContactGraphcxx . . $ ContactGraph.; //Q |
| 605 | demoscxx . . $ demos.[17] = Buoyancycxx . . $ Buoyancy.; //R |
| 606 | demoscxx . . $ demos.[18] = Playercxx . . $ Player.; //S |
| 607 | demoscxx . . $ demos.[19] = Slicecxx . . $ Slice.; //T |
| 608 | demoscxx . . $ demos.[20] = Convexcxx . . $ Convex.; //U |
| 609 | demoscxx . . $ demos.[21] = Unicyclecxx . . $ Unicycle.; //V |
| 610 | demoscxx . . $ demos.[22] = Stickycxx . . $ Sticky.; //W |
| 611 | demoscxx . . $ demos.[23] = Shattercxx . . $ Shatter.; //X |
| 612 | demo_countcxx . . $ demo_count. = 24; |
| 613 | |
| 614 | int trial = 0; |
| 615 | for(int i=0; i<argc; i++){ |
| 616 | if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[i], "-bench") == 0){ |
| 617 | memcpycxx . . $ memcpy(cc817cb175f282d).(demoscxx . . $ demos., bench_listcxx . . $ bench_list., bench_countcxx . . $ bench_count.*sizeof(ChipmunkDemocxx . . $ ChipmunkDemo#)); |
| 618 | demo_countcxx . . $ demo_count. = bench_countcxx . . $ bench_count.; |
| 619 | } else if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[i], "-trial") == 0){ |
| 620 | trial = 1; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | stm_setupcxx . . $ stm_setup(49f6e7a06ebc5aa8).(); |
| 625 | if(trial){ |
| 626 | for(int i=0; i<demo_countcxx . . $ demo_count.; i++) TimeTrialcxx . . $ TimeTrial(3e454b8ccf442868).(i, 1000); |
| 627 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 628 | } else { |
| 629 | return (sapp_desccxx . . $ sapp_desc#){ |
| 630 | .init_cb = Initcxx . . $ Init(49f6e7a06ebc5aa8)., |
| 631 | .frame_cb = Displaycxx . . $ Display(49f6e7a06ebc5aa8)., |
| 632 | .event_cb = Eventcxx . . $ Event(241e5018601f13a4)., |
| 633 | .cleanup_cb = Cleanupcxx . . $ Cleanup(49f6e7a06ebc5aa8)., |
| 634 | .width = 1024, |
| 635 | .height = 768, |
| 636 | .high_dpi = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!, |
| 637 | .window_title = "Chipmunk2D", |
| 638 | }; |
| 639 | } |
| 640 | } |