tests: Trim .nim files trailing whitespace

via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
Adam Strzelecki 2015-09-04 23:04:32 +02:00
commit e80465dacf
372 changed files with 4486 additions and 4486 deletions

View file

@ -1,15 +1,15 @@
# Copyright (c) 2007 Scott Lembcke
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -17,7 +17,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#
const Lib = "libchipmunk.so.6.1.1"
@ -30,12 +30,12 @@ when defined(CpUseFloat):
type CpFloat* = cfloat
else:
type CpFloat* = cdouble
const
CP_BUFFER_BYTES* = (32 * 1024)
const
CP_BUFFER_BYTES* = (32 * 1024)
CP_MAX_CONTACTS_PER_ARBITER* = 4
CpInfinity*: CpFloat = 1.0/0
{.pragma: pf, pure, final.}
type
type
Bool32* = cint #replace one day with cint-compatible bool
CpDataPointer* = pointer
TVector* {.final, pure.} = object
@ -44,12 +44,12 @@ type
TBodyVelocityFunc* = proc(body: PBody, gravity: TVector,
damping: CpFloat; dt: CpFloat){.cdecl.}
TBodyPositionFunc* = proc(body: PBody; dt: CpFloat){.cdecl.}
TComponentNode*{.pf.} = object
TComponentNode*{.pf.} = object
root*: PBody
next*: PBody
idleTime*: CpFloat
THashValue = cuint # uintptr_t
THashValue = cuint # uintptr_t
TCollisionType* = cuint #uintptr_t
TGroup * = cuint #uintptr_t
TLayers* = cuint
@ -60,9 +60,9 @@ type
PContact* = ptr TContact
TContact*{.pure,final.} = object
PArbiter* = ptr TArbiter
TArbiter*{.pf.} = object
TArbiter*{.pf.} = object
e*: CpFloat
u*: CpFloat
u*: CpFloat
surface_vr*: TVector
a*: PShape
b*: PShape
@ -77,7 +77,7 @@ type
swappedColl*: Bool32
state*: TArbiterState
PCollisionHandler* = ptr TCollisionHandler
TCollisionHandler*{.pf.} = object
TCollisionHandler*{.pf.} = object
a*: TCollisionType
b*: TCollisionType
begin*: TCollisionBeginFunc
@ -85,26 +85,26 @@ type
postSolve*: TCollisionPostSolveFunc
separate*: TCollisionSeparateFunc
data*: pointer
TArbiterState*{.size: sizeof(cint).} = enum
TArbiterState*{.size: sizeof(cint).} = enum
ArbiterStateFirstColl, # Arbiter is active and its not the first collision.
ArbiterStateNormal, # Collision has been explicitly ignored.
# Either by returning false from a begin collision handler or calling cpArbiterIgnore().
ArbiterStateIgnore, # Collison is no longer active. A space will cache an arbiter for up to cpSpace.collisionPersistence more steps.
ArbiterStateCached
TArbiterThread*{.pf.} = object
TArbiterThread*{.pf.} = object
next*: PArbiter # Links to next and previous arbiters in the contact graph.
prev*: PArbiter
TContactPoint*{.pf.} = object
TContactPoint*{.pf.} = object
point*: TVector #/ The position of the contact point.
normal*: TVector #/ The normal of the contact point.
dist*: CpFloat #/ The depth of the contact point.
#/ A struct that wraps up the important collision data for an arbiter.
PContactPointSet* = ptr TContactPointSet
TContactPointSet*{.pf.} = object
TContactPointSet*{.pf.} = object
count*: cint #/ The number of contact points in the set.
points*: array[0..CP_MAX_CONTACTS_PER_ARBITER - 1, TContactPoint] #/ The array of contact points.
#/ Collision begin event function callback type.
#/ Returning false from a begin callback causes the collision to be ignored until
#/ the the separate callback is called when the objects stop colliding.
@ -112,35 +112,35 @@ type
cdecl.}
#/ Collision pre-solve event function callback type.
#/ Returning false from a pre-step callback causes the collision to be ignored until the next step.
TCollisionPreSolveFunc* = proc (arb: PArbiter; space: PSpace;
TCollisionPreSolveFunc* = proc (arb: PArbiter; space: PSpace;
data: pointer): bool {.cdecl.}
#/ Collision post-solve event function callback type.
TCollisionPostSolveFunc* = proc (arb: PArbiter; space: PSpace;
TCollisionPostSolveFunc* = proc (arb: PArbiter; space: PSpace;
data: pointer){.cdecl.}
#/ Collision separate event function callback type.
TCollisionSeparateFunc* = proc (arb: PArbiter; space: PSpace;
TCollisionSeparateFunc* = proc (arb: PArbiter; space: PSpace;
data: pointer){.cdecl.}
#/ Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
PBB* = ptr TBB
TBB* {.pf.} = object
TBB* {.pf.} = object
l*, b*, r*, t*: CpFloat
#/ Spatial index bounding box callback function type.
#/ The spatial index calls this function and passes you a pointer to an object you added
#/ when it needs to get the bounding box associated with that object.
TSpatialIndexBBFunc* = proc (obj: pointer): TBB{.cdecl.}
#/ Spatial index/object iterator callback function type.
TSpatialIndexIteratorFunc* = proc (obj: pointer; data: pointer){.cdecl.}
#/ Spatial query callback function type.
#/ Spatial query callback function type.
TSpatialIndexQueryFunc* = proc (obj1: pointer; obj2: pointer; data: pointer){.
cdecl.}
#/ Spatial segment query callback function type.
TSpatialIndexSegmentQueryFunc* = proc (obj1: pointer; obj2: pointer;
TSpatialIndexSegmentQueryFunc* = proc (obj1: pointer; obj2: pointer;
data: pointer): CpFloat {.cdecl.}
#/ private
PSpatialIndex = ptr TSpatialIndex
TSpatialIndex{.pf.} = object
TSpatialIndex{.pf.} = object
klass: PSpatialIndexClass
bbfun: TSpatialIndexBBFunc
staticIndex: PSpatialIndex
@ -148,31 +148,31 @@ type
TSpatialIndexDestroyImpl* = proc (index: PSpatialIndex){.cdecl.}
TSpatialIndexCountImpl* = proc (index: PSpatialIndex): cint{.cdecl.}
TSpatialIndexEachImpl* = proc (index: PSpatialIndex;
TSpatialIndexEachImpl* = proc (index: PSpatialIndex;
fun: TSpatialIndexIteratorFunc; data: pointer){.
cdecl.}
TSpatialIndexContainsImpl* = proc (index: PSpatialIndex; obj: pointer;
TSpatialIndexContainsImpl* = proc (index: PSpatialIndex; obj: pointer;
hashid: THashValue): Bool32 {.cdecl.}
TSpatialIndexInsertImpl* = proc (index: PSpatialIndex; obj: pointer;
TSpatialIndexInsertImpl* = proc (index: PSpatialIndex; obj: pointer;
hashid: THashValue){.cdecl.}
TSpatialIndexRemoveImpl* = proc (index: PSpatialIndex; obj: pointer;
TSpatialIndexRemoveImpl* = proc (index: PSpatialIndex; obj: pointer;
hashid: THashValue){.cdecl.}
TSpatialIndexReindexImpl* = proc (index: PSpatialIndex){.cdecl.}
TSpatialIndexReindexObjectImpl* = proc (index: PSpatialIndex;
TSpatialIndexReindexObjectImpl* = proc (index: PSpatialIndex;
obj: pointer; hashid: THashValue){.cdecl.}
TSpatialIndexReindexQueryImpl* = proc (index: PSpatialIndex;
TSpatialIndexReindexQueryImpl* = proc (index: PSpatialIndex;
fun: TSpatialIndexQueryFunc; data: pointer){.cdecl.}
TSpatialIndexPointQueryImpl* = proc (index: PSpatialIndex; point: TVector;
fun: TSpatialIndexQueryFunc;
TSpatialIndexPointQueryImpl* = proc (index: PSpatialIndex; point: TVector;
fun: TSpatialIndexQueryFunc;
data: pointer){.cdecl.}
TSpatialIndexSegmentQueryImpl* = proc (index: PSpatialIndex; obj: pointer;
a: TVector; b: TVector; t_exit: CpFloat; fun: TSpatialIndexSegmentQueryFunc;
TSpatialIndexSegmentQueryImpl* = proc (index: PSpatialIndex; obj: pointer;
a: TVector; b: TVector; t_exit: CpFloat; fun: TSpatialIndexSegmentQueryFunc;
data: pointer){.cdecl.}
TSpatialIndexQueryImpl* = proc (index: PSpatialIndex; obj: pointer;
bb: TBB; fun: TSpatialIndexQueryFunc;
TSpatialIndexQueryImpl* = proc (index: PSpatialIndex; obj: pointer;
bb: TBB; fun: TSpatialIndexQueryFunc;
data: pointer){.cdecl.}
PSpatialIndexClass* = ptr TSpatialIndexClass
TSpatialIndexClass*{.pf.} = object
TSpatialIndexClass*{.pf.} = object
destroy*: TSpatialIndexDestroyImpl
count*: TSpatialIndexCountImpl
each*: TSpatialIndexEachImpl
@ -185,32 +185,32 @@ type
pointQuery*: TSpatialIndexPointQueryImpl
segmentQuery*: TSpatialIndexSegmentQueryImpl
query*: TSpatialIndexQueryImpl
PSpaceHash* = ptr TSpaceHash
TSpaceHash* {.pf.} = object
PBBTree* = ptr TBBTree
TBBTree* {.pf.} = object
PSweep1D* = ptr TSweep1D
TSweep1D* {.pf.} = object
#/ Bounding box tree velocity callback function.
#/ This function should return an estimate for the object's velocity.
TBBTreeVelocityFunc* = proc (obj: pointer): TVector {.cdecl.}
PContactBufferHeader* = ptr TContentBufferHeader
TContentBufferHeader* {.pf.} = object
TSpaceArbiterApplyImpulseFunc* = proc (arb: PArbiter){.cdecl.}
PSpace* = ptr TSpace
TSpace* {.pf.} = object
iterations*: cint
iterations*: cint
gravity*: TVector
damping*: CpFloat
idleSpeedThreshold*: CpFloat
sleepTimeThreshold*: CpFloat
collisionSlop*: CpFloat
idleSpeedThreshold*: CpFloat
sleepTimeThreshold*: CpFloat
collisionSlop*: CpFloat
collisionBias*: CpFloat
collisionPersistence*: TTimestamp
collisionPersistence*: TTimestamp
enableContactGraph*: cint ##BOOL
data*: pointer
staticBody*: PBody
@ -232,24 +232,24 @@ type
defaultHandler: TCollisionHandler
postStepCallbacks: PHashSet
arbiterApplyImpulse: TSpaceArbiterApplyImpulseFunc
staticBody2: TBody #_staticBody
staticBody2: TBody #_staticBody
PBody* = ptr TBody
TBody*{.pf.} = object
velocityFunc*: TBodyVelocityFunc
positionFunc*: TBodyPositionFunc
m*: CpFloat
mInv*: CpFloat
i*: CpFloat
iInv*: CpFloat
p*: TVector
v*: TVector
f*: TVector
a*: CpFloat
w*: CpFloat
t*: CpFloat
rot*: TVector
TBody*{.pf.} = object
velocityFunc*: TBodyVelocityFunc
positionFunc*: TBodyPositionFunc
m*: CpFloat
mInv*: CpFloat
i*: CpFloat
iInv*: CpFloat
p*: TVector
v*: TVector
f*: TVector
a*: CpFloat
w*: CpFloat
t*: CpFloat
rot*: TVector
data*: pointer
vLimit*: CpFloat
vLimit*: CpFloat
wLimit*: CpFloat
vBias*: TVector
wBias*: CpFloat
@ -258,51 +258,51 @@ type
arbiterList*: PArbiter
constraintList*: PConstraint
node*: TComponentNode
#/ Body/shape iterator callback function type.
TBodyShapeIteratorFunc* = proc (body: PBody; shape: PShape;
#/ Body/shape iterator callback function type.
TBodyShapeIteratorFunc* = proc (body: PBody; shape: PShape;
data: pointer) {.cdecl.}
#/ Body/constraint iterator callback function type.
TBodyConstraintIteratorFunc* = proc (body: PBody;
constraint: PConstraint;
#/ Body/constraint iterator callback function type.
TBodyConstraintIteratorFunc* = proc (body: PBody;
constraint: PConstraint;
data: pointer) {.cdecl.}
#/ Body/arbiter iterator callback function type.
TBodyArbiterIteratorFunc* = proc (body: PBody; arbiter: PArbiter;
#/ Body/arbiter iterator callback function type.
TBodyArbiterIteratorFunc* = proc (body: PBody; arbiter: PArbiter;
data: pointer) {.cdecl.}
PNearestPointQueryInfo* = ptr TNearestPointQueryInfo
#/ Nearest point query info struct.
TNearestPointQueryInfo*{.pf.} = object
shape: PShape #/ The nearest shape, NULL if no shape was within range.
p: TVector #/ The closest point on the shape's surface. (in world space coordinates)
d: CpFloat #/ The distance to the point. The distance is negative if the point is inside the shape.
PSegmentQueryInfo* = ptr TSegmentQueryInfo
#/ Segment query info struct.
TSegmentQueryInfo*{.pf.} = object
TSegmentQueryInfo*{.pf.} = object
shape*: PShape #/ The shape that was hit, NULL if no collision occurred.
t*: CpFloat #/ The normalized distance along the query segment in the range [0, 1].
n*: TVector #/ The normal of the surface hit.
TShapeType*{.size: sizeof(cint).} = enum
TShapeType*{.size: sizeof(cint).} = enum
CP_CIRCLE_SHAPE, CP_SEGMENT_SHAPE, CP_POLY_SHAPE, CP_NUM_SHAPES
TShapeCacheDataImpl* = proc (shape: PShape; p: TVector; rot: TVector): TBB{.cdecl.}
TShapeDestroyImpl* = proc (shape: PShape){.cdecl.}
TShapePointQueryImpl* = proc (shape: PShape; p: TVector): Bool32 {.cdecl.}
TShapeSegmentQueryImpl* = proc (shape: PShape; a: TVector; b: TVector;
TShapeSegmentQueryImpl* = proc (shape: PShape; a: TVector; b: TVector;
info: PSegmentQueryInfo){.cdecl.}
PShapeClass* = ptr TShapeClass
TShapeClass*{.pf.} = object
TShapeClass*{.pf.} = object
kind*: TShapeType
cacheData*: TShapeCacheDataImpl
destroy*: TShapeDestroyImpl
pointQuery*: TShapePointQueryImpl
segmentQuery*: TShapeSegmentQueryImpl
PShape* = ptr TShape
TShape*{.pf.} = object
TShape*{.pf.} = object
klass: PShapeClass #/ PRIVATE
body*: PBody #/ The rigid body this collision shape is attached to.
bb*: TBB #/ The current bounding box of the shape.
bb*: TBB #/ The current bounding box of the shape.
sensor*: Bool32 #/ Sensor flag.
#/ Sensor shapes call collision callbacks but don't produce collisions.
#/ Sensor shapes call collision callbacks but don't produce collisions.
e*: CpFloat #/ Coefficient of restitution. (elasticity)
u*: CpFloat #/ Coefficient of friction.
surface_v*: TVector #/ Surface velocity used when solving for friction.
@ -336,29 +336,29 @@ type
TSplittingPlane*{.pf.} = object
n: TVector
d: CpFloat
#/ Post Step callback function type.
TPostStepFunc* = proc (space: PSpace; obj: pointer; data: pointer){.cdecl.}
#/ Point query callback function type.
TSpacePointQueryFunc* = proc (shape: PShape; data: pointer){.cdecl.}
#/ Segment query callback function type.
TSpaceSegmentQueryFunc* = proc (shape: PShape; t: CpFloat; n: TVector;
TSpaceSegmentQueryFunc* = proc (shape: PShape; t: CpFloat; n: TVector;
data: pointer){.cdecl.}
#/ Rectangle Query callback function type.
TSpaceBBQueryFunc* = proc (shape: PShape; data: pointer){.cdecl.}
#/ Shape query callback function type.
TSpaceShapeQueryFunc* = proc (shape: PShape; points: PContactPointSet;
TSpaceShapeQueryFunc* = proc (shape: PShape; points: PContactPointSet;
data: pointer){.cdecl.}
#/ Space/body iterator callback function type.
TSpaceBodyIteratorFunc* = proc (body: PBody; data: pointer){.cdecl.}
#/ Space/body iterator callback function type.
TSpaceShapeIteratorFunc* = proc (shape: PShape; data: pointer){.cdecl.}
#/ Space/constraint iterator callback function type.
TSpaceConstraintIteratorFunc* = proc (constraint: PConstraint;
TSpaceConstraintIteratorFunc* = proc (constraint: PConstraint;
data: pointer){.cdecl.}
#/ Opaque cpConstraint struct.
PConstraint* = ptr TConstraint
TConstraint*{.pf.} = object
TConstraint*{.pf.} = object
klass: PConstraintClass #/PRIVATE
a*: PBody #/ The first body connected to this constraint.
b*: PBody #/ The second body connected to this constraint.
@ -367,7 +367,7 @@ type
next_b: PConstraint #/PRIVATE
maxForce*: CpFloat #/ The maximum force that this constraint is allowed to use. Defaults to infinity.
errorBias*: CpFloat #/ The rate at which joint error is corrected. Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.
maxBias*: CpFloat #/ The maximum rate at which joint error is corrected. Defaults to infinity.
maxBias*: CpFloat #/ The maximum rate at which joint error is corrected. Defaults to infinity.
preSolve*: TConstraintPreSolveFunc #/ Function called before the solver runs. Animate your joint anchors, update your motor torque, etc.
postSolve*: TConstraintPostSolveFunc #/ Function called after the solver runs. Use the applied impulse to perform effects like breakable joints.
data*: CpDataPointer # User definable data pointer. Generally this points to your the game object class so you can access it when given a cpConstraint reference in a callback.
@ -376,7 +376,7 @@ type
TConstraintApplyImpulseImpl = proc (constraint: PConstraint){.cdecl.}
TConstraintGetImpulseImpl = proc (constraint: PConstraint): CpFloat{.cdecl.}
PConstraintClass = ptr TConstraintClass
TConstraintClass{.pf.} = object
TConstraintClass{.pf.} = object
preStep*: TConstraintPreStepImpl
applyCachedImpulse*: TConstraintApplyCachedImpulseImpl
applyImpulse*: TConstraintApplyImpulseImpl
@ -427,29 +427,29 @@ defGetter(PSpace, CpFloat, currDt, CurrentTimeStep)
#/ returns true from inside a callback and objects cannot be added/removed.
proc isLocked*(space: PSpace): bool{.inline.} =
proc isLocked*(space: PSpace): bool{.inline.} =
result = space.locked.bool
#/ Set a default collision handler for this space.
#/ The default collision handler is invoked for each colliding pair of shapes
#/ that isn't explicitly handled by a specific collision handler.
#/ You can pass NULL for any function you don't want to implement.
proc setDefaultCollisionHandler*(space: PSpace; begin: TCollisionBeginFunc;
preSolve: TCollisionPreSolveFunc;
postSolve: TCollisionPostSolveFunc;
separate: TCollisionSeparateFunc;
proc setDefaultCollisionHandler*(space: PSpace; begin: TCollisionBeginFunc;
preSolve: TCollisionPreSolveFunc;
postSolve: TCollisionPostSolveFunc;
separate: TCollisionSeparateFunc;
data: pointer){.
cdecl, importc: "cpSpaceSetDefaultCollisionHandler", dynlib: Lib.}
#/ Set a collision handler to be used whenever the two shapes with the given collision types collide.
#/ You can pass NULL for any function you don't want to implement.
proc addCollisionHandler*(space: PSpace; a, b: TCollisionType;
begin: TCollisionBeginFunc;
preSolve: TCollisionPreSolveFunc;
postSolve: TCollisionPostSolveFunc;
proc addCollisionHandler*(space: PSpace; a, b: TCollisionType;
begin: TCollisionBeginFunc;
preSolve: TCollisionPreSolveFunc;
postSolve: TCollisionPostSolveFunc;
separate: TCollisionSeparateFunc; data: pointer){.
cdecl, importc: "cpSpaceAddCollisionHandler", dynlib: Lib.}
#/ Unset a collision handler.
proc removeCollisionHandler*(space: PSpace; a: TCollisionType;
proc removeCollisionHandler*(space: PSpace; a: TCollisionType;
b: TCollisionType){.
cdecl, importc: "cpSpaceRemoveCollisionHandler", dynlib: Lib.}
#/ Add a collision shape to the simulation.
@ -489,34 +489,34 @@ proc containsConstraint*(space: PSpace; constraint: PConstraint): bool{.
cdecl, importc: "cpSpaceContainsConstraint", dynlib: Lib.}
#/ Schedule a post-step callback to be called when cpSpaceStep() finishes.
#/ @c obj is used a key, you can only register one callback per unique value for @c obj
proc addPostStepCallback*(space: PSpace; fun: TPostStepFunc;
proc addPostStepCallback*(space: PSpace; fun: TPostStepFunc;
obj: pointer; data: pointer){.
cdecl, importc: "cpSpaceAddPostStepCallback", dynlib: Lib.}
#/ Query the space at a point and call @c func for each shape found.
proc pointQuery*(space: PSpace; point: TVector; layers: TLayers;
proc pointQuery*(space: PSpace; point: TVector; layers: TLayers;
group: TGroup; fun: TSpacePointQueryFunc; data: pointer){.
cdecl, importc: "cpSpacePointQuery", dynlib: Lib.}
#/ Query the space at a point and return the first shape found. Returns NULL if no shapes were found.
proc pointQueryFirst*(space: PSpace; point: TVector; layers: TLayers;
proc pointQueryFirst*(space: PSpace; point: TVector; layers: TLayers;
group: TGroup): PShape{.
cdecl, importc: "cpSpacePointQueryFirst", dynlib: Lib.}
#/ Perform a directed line segment query (like a raycast) against the space calling @c func for each shape intersected.
proc segmentQuery*(space: PSpace; start: TVector; to: TVector;
layers: TLayers; group: TGroup;
proc segmentQuery*(space: PSpace; start: TVector; to: TVector;
layers: TLayers; group: TGroup;
fun: TSpaceSegmentQueryFunc; data: pointer){.
cdecl, importc: "cpSpaceSegmentQuery", dynlib: Lib.}
#/ Perform a directed line segment query (like a raycast) against the space and return the first shape hit. Returns NULL if no shapes were hit.
proc segmentQueryFirst*(space: PSpace; start: TVector; to: TVector;
layers: TLayers; group: TGroup;
proc segmentQueryFirst*(space: PSpace; start: TVector; to: TVector;
layers: TLayers; group: TGroup;
res: PSegmentQueryInfo): PShape{.
cdecl, importc: "cpSpaceSegmentQueryFirst", dynlib: Lib.}
#/ Perform a fast rectangle query on the space calling @c func for each shape found.
#/ Only the shape's bounding boxes are checked for overlap, not their full shape.
proc BBQuery*(space: PSpace; bb: TBB; layers: TLayers; group: TGroup;
proc BBQuery*(space: PSpace; bb: TBB; layers: TLayers; group: TGroup;
fun: TSpaceBBQueryFunc; data: pointer){.
cdecl, importc: "cpSpaceBBQuery", dynlib: Lib.}
@ -532,11 +532,11 @@ proc eachBody*(space: PSpace; fun: TSpaceBodyIteratorFunc; data: pointer){.
cdecl, importc: "cpSpaceEachBody", dynlib: Lib.}
#/ Call @c func for each shape in the space.
proc eachShape*(space: PSpace; fun: TSpaceShapeIteratorFunc;
proc eachShape*(space: PSpace; fun: TSpaceShapeIteratorFunc;
data: pointer){.
cdecl, importc: "cpSpaceEachShape", dynlib: Lib.}
#/ Call @c func for each shape in the space.
proc eachConstraint*(space: PSpace; fun: TSpaceConstraintIteratorFunc;
proc eachConstraint*(space: PSpace; fun: TSpaceConstraintIteratorFunc;
data: pointer){.
cdecl, importc: "cpSpaceEachConstraint", dynlib: Lib.}
#/ Update the collision detection info for the static shapes in the space.
@ -566,7 +566,7 @@ proc newVector*(x, y: CpFloat): TVector {.inline.} =
var VectorZero* = newVector(0.0, 0.0)
#/ Vector dot product.
proc dot*(v1, v2: TVector): CpFloat {.inline.} =
proc dot*(v1, v2: TVector): CpFloat {.inline.} =
result = v1.x * v2.x + v1.y * v2.y
#/ Returns the length of v.
@ -613,7 +613,7 @@ proc `-=`*(v1: var TVector; v2: TVector) =
v1.y = v1.y - v2.y
#/ Negate a vector.
proc `-`*(v: TVector): TVector {.inline.} =
proc `-`*(v: TVector): TVector {.inline.} =
result = newVector(- v.x, - v.y)
#/ Scalar multiplication.
@ -627,54 +627,54 @@ proc `*=`*(v: var TVector; s: CpFloat) =
#/ 2D vector cross product analog.
#/ The cross product of 2D vectors results in a 3D vector with only a z component.
#/ This function returns the magnitude of the z value.
proc cross*(v1, v2: TVector): CpFloat {.inline.} =
proc cross*(v1, v2: TVector): CpFloat {.inline.} =
result = v1.x * v2.y - v1.y * v2.x
#/ Returns a perpendicular vector. (90 degree rotation)
proc perp*(v: TVector): TVector {.inline.} =
proc perp*(v: TVector): TVector {.inline.} =
result = newVector(- v.y, v.x)
#/ Returns a perpendicular vector. (-90 degree rotation)
proc rperp*(v: TVector): TVector {.inline.} =
proc rperp*(v: TVector): TVector {.inline.} =
result = newVector(v.y, - v.x)
#/ Returns the vector projection of v1 onto v2.
proc project*(v1,v2: TVector): TVector {.inline.} =
proc project*(v1,v2: TVector): TVector {.inline.} =
result = v2 * (v1.dot(v2) / v2.dot(v2))
#/ Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector.
proc rotate*(v1, v2: TVector): TVector {.inline.} =
proc rotate*(v1, v2: TVector): TVector {.inline.} =
result = newVector(v1.x * v2.x - v1.y * v2.y, v1.x * v2.y + v1.y * v2.x)
#/ Inverse of cpvrotate().
proc unrotate*(v1, v2: TVector): TVector {.inline.} =
proc unrotate*(v1, v2: TVector): TVector {.inline.} =
result = newVector(v1.x * v2.x + v1.y * v2.y, v1.y * v2.x - v1.x * v2.y)
#/ Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths.
proc lenSq*(v: TVector): CpFloat {.inline.} =
proc lenSq*(v: TVector): CpFloat {.inline.} =
result = v.dot(v)
#/ Linearly interpolate between v1 and v2.
proc lerp*(v1, v2: TVector; t: CpFloat): TVector {.inline.} =
proc lerp*(v1, v2: TVector; t: CpFloat): TVector {.inline.} =
result = (v1 * (1.0 - t)) + (v2 * t)
#/ Returns a normalized copy of v.
proc normalize*(v: TVector): TVector {.inline.} =
proc normalize*(v: TVector): TVector {.inline.} =
result = v * (1.0 / v.len)
#/ Returns a normalized copy of v or cpvzero if v was already cpvzero. Protects against divide by zero errors.
proc normalizeSafe*(v: TVector): TVector {.inline.} =
proc normalizeSafe*(v: TVector): TVector {.inline.} =
result = if v.x == 0.0 and v.y == 0.0: VectorZero else: v.normalize
#/ Clamp v to length len.
proc clamp*(v: TVector; len: CpFloat): TVector {.inline.} =
proc clamp*(v: TVector; len: CpFloat): TVector {.inline.} =
result = if v.dot(v) > len * len: v.normalize * len else: v
#/ Linearly interpolate between v1 towards v2 by distance d.
proc lerpconst*(v1, v2: TVector; d: CpFloat): TVector {.inline.} =
proc lerpconst*(v1, v2: TVector; d: CpFloat): TVector {.inline.} =
result = v1 + clamp(v2 - v1, d) #vadd(v1 + vclamp(vsub(v2, v1), d))
#/ Returns the distance between v1 and v2.
proc dist*(v1, v2: TVector): CpFloat {.inline.} =
proc dist*(v1, v2: TVector): CpFloat {.inline.} =
result = (v1 - v2).len #vlength(vsub(v1, v2))
#/ Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare distances.
proc distsq*(v1, v2: TVector): CpFloat {.inline.} =
proc distsq*(v1, v2: TVector): CpFloat {.inline.} =
result = (v1 - v2).lenSq #vlengthsq(vsub(v1, v2))
#/ Returns true if the distance between v1 and v2 is less than dist.
proc near*(v1, v2: TVector; dist: CpFloat): bool{.inline.} =
proc near*(v1, v2: TVector; dist: CpFloat): bool{.inline.} =
result = v1.distSq(v2) < dist * dist
@ -706,13 +706,13 @@ proc Sleep*(body: PBody){.importc: "cpBodySleep", dynlib: Lib.}
proc SleepWithGroup*(body: PBody; group: PBody){.
importc: "cpBodySleepWithGroup", dynlib: Lib.}
#/ Returns true if the body is sleeping.
proc isSleeping*(body: PBody): bool {.inline.} =
proc isSleeping*(body: PBody): bool {.inline.} =
return body.node.root != nil
#/ Returns true if the body is static.
proc isStatic*(body: PBody): bool {.inline.} =
proc isStatic*(body: PBody): bool {.inline.} =
return body.node.idleTime == CpInfinity
#/ Returns true if the body has not been added to a space.
proc isRogue*(body: PBody): bool {.inline.} =
proc isRogue*(body: PBody): bool {.inline.} =
return body.space == nil
# #define CP_DefineBodyStructGetter(type, member, name) \
@ -740,7 +740,7 @@ defGetter(PBody, CpFloat, i, Moment)
#/ Set the moment of a body.
when defined(MoreNim):
defSetter(PBody, CpFloat, i, Moment)
else:
else:
proc SetMoment*(body: PBody; i: CpFloat) {.
cdecl, importc: "cpBodySetMoment", dynlib: Lib.}
@ -775,10 +775,10 @@ proc UpdateVelocity*(body: PBody; gravity: TVector; damping: CpFloat; dt: CpFloa
proc UpdatePosition*(body: PBody; dt: CpFloat){.
cdecl, importc: "cpBodyUpdatePosition", dynlib: Lib.}
#/ Convert body relative/local coordinates to absolute/world coordinates.
proc Local2World*(body: PBody; v: TVector): TVector{.inline.} =
proc Local2World*(body: PBody; v: TVector): TVector{.inline.} =
result = body.p + v.rotate(body.rot) ##return cpvadd(body.p, cpvrotate(v, body.rot))
#/ Convert body absolute/world coordinates to relative/local coordinates.
proc world2Local*(body: PBody; v: TVector): TVector{.inline.} =
proc world2Local*(body: PBody; v: TVector): TVector{.inline.} =
result = (v - body.p).unrotate(body.rot)
#/ Set the forces and torque or a body to zero.
proc resetForces*(body: PBody){.
@ -808,26 +808,26 @@ proc kineticEnergy*(body: PBOdy): CpFloat =
result = (body.v.dot(body.v) * body.m) + (body.w * body.w * body.i)
#/ Call @c func once for each shape attached to @c body and added to the space.
proc eachShape*(body: PBody; fun: TBodyShapeIteratorFunc;
proc eachShape*(body: PBody; fun: TBodyShapeIteratorFunc;
data: pointer){.
cdecl, importc: "cpBodyEachShape", dynlib: Lib.}
#/ Call @c func once for each constraint attached to @c body and added to the space.
proc eachConstraint*(body: PBody; fun: TBodyConstraintIteratorFunc;
proc eachConstraint*(body: PBody; fun: TBodyConstraintIteratorFunc;
data: pointer) {.
cdecl, importc: "cpBodyEachConstraint", dynlib: Lib.}
#/ Call @c func once for each arbiter that is currently active on the body.
proc eachArbiter*(body: PBody; fun: TBodyArbiterIteratorFunc;
proc eachArbiter*(body: PBody; fun: TBodyArbiterIteratorFunc;
data: pointer){.
cdecl, importc: "cpBodyEachArbiter", dynlib: Lib.}
#/ Allocate a spatial hash.
proc SpaceHashAlloc*(): PSpaceHash{.
cdecl, importc: "cpSpaceHashAlloc", dynlib: Lib.}
#/ Initialize a spatial hash.
proc SpaceHashInit*(hash: PSpaceHash; celldim: CpFloat; numcells: cint;
#/ Initialize a spatial hash.
proc SpaceHashInit*(hash: PSpaceHash; celldim: CpFloat; numcells: cint;
bbfun: TSpatialIndexBBFunc; staticIndex: PSpatialIndex): PSpatialIndex{.
cdecl, importc: "cpSpaceHashInit", dynlib: Lib.}
#/ Allocate and initialize a spatial hash.
proc SpaceHashNew*(celldim: CpFloat; cells: cint; bbfun: TSpatialIndexBBFunc;
proc SpaceHashNew*(celldim: CpFloat; cells: cint; bbfun: TSpatialIndexBBFunc;
staticIndex: PSpatialIndex): PSpatialIndex{.
cdecl, importc: "cpSpaceHashNew", dynlib: Lib.}
#/ Change the cell dimensions and table size of the spatial hash to tune it.
@ -842,8 +842,8 @@ proc SpaceHashResize*(hash: PSpaceHash; celldim: CpFloat; numcells: cint){.
#/ Allocate a bounding box tree.
proc BBTreeAlloc*(): PBBTree{.cdecl, importc: "cpBBTreeAlloc", dynlib: Lib.}
#/ Initialize a bounding box tree.
proc BBTreeInit*(tree: PBBTree; bbfun: TSpatialIndexBBFunc;
staticIndex: ptr TSpatialIndex): ptr TSpatialIndex{.cdecl,
proc BBTreeInit*(tree: PBBTree; bbfun: TSpatialIndexBBFunc;
staticIndex: ptr TSpatialIndex): ptr TSpatialIndex{.cdecl,
importc: "cpBBTreeInit", dynlib: Lib.}
#/ Allocate and initialize a bounding box tree.
proc BBTreeNew*(bbfun: TSpatialIndexBBFunc; staticIndex: PSpatialIndex): PSpatialIndex{.
@ -860,12 +860,12 @@ proc BBTreeSetVelocityFunc*(index: PSpatialIndex; fun: TBBTreeVelocityFunc){.
#/ Allocate a 1D sort and sweep broadphase.
proc Sweep1DAlloc*(): ptr TSweep1D{.cdecl, importc: "cpSweep1DAlloc",
proc Sweep1DAlloc*(): ptr TSweep1D{.cdecl, importc: "cpSweep1DAlloc",
dynlib: Lib.}
#/ Initialize a 1D sort and sweep broadphase.
proc Sweep1DInit*(sweep: ptr TSweep1D; bbfun: TSpatialIndexBBFunc;
staticIndex: ptr TSpatialIndex): ptr TSpatialIndex{.cdecl,
proc Sweep1DInit*(sweep: ptr TSweep1D; bbfun: TSpatialIndexBBFunc;
staticIndex: ptr TSpatialIndex): ptr TSpatialIndex{.cdecl,
importc: "cpSweep1DInit", dynlib: Lib.}
#/ Allocate and initialize a 1D sort and sweep broadphase.
@ -878,7 +878,7 @@ defProp(PArbiter, CpFloat, e, Elasticity)
defProp(PArbiter, CpFloat, u, Friction)
defProp(PArbiter, TVector, surface_vr, SurfaceVelocity)
#/ Calculate the total impulse that was applied by this
#/ Calculate the total impulse that was applied by this
#/ This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
proc totalImpulse*(obj: PArbiter): TVector {.cdecl, importc: "cpArbiterTotalImpulse", dynlib: Lib.}
@ -917,7 +917,7 @@ template getShapes*(arb: PArbiter, name1, name2: expr): stmt {.immediate.} =
#/ Return the colliding bodies involved for this arbiter.
#/ The order of the cpSpace.collision_type the bodies are associated with values will match
#/ the order set when the collision handler was registered.
#proc getBodies*(arb: PArbiter, a, b: var PBody) {.inline.} =
#proc getBodies*(arb: PArbiter, a, b: var PBody) {.inline.} =
# getShapes(arb, shape1, shape2)
# a = shape1.body
# b = shape2.body
@ -981,7 +981,7 @@ proc segmentQuery*(shape: PShape, a, b: TVector, info: PSegmentQueryInfo): bool
cdecl, importc: "cpShapeSegmentQuery", dynlib: Lib.}
#/ Get the hit point for a segment query.
## Possibly change; info to PSegmentQueryInfo
## Possibly change; info to PSegmentQueryInfo
proc queryHitPoint*(start, to: TVector, info: TSegmentQueryInfo): TVector {.inline.} =
result = start.lerp(to, info.t)
@ -1035,7 +1035,7 @@ proc init*(poly: PPolyShape; body: PBody, numVerts: cint;
cdecl, importc: "cpPolyShapeInit", dynlib: Lib.}
#/ Allocate and initialize a polygon shape.
#/ A convex hull will be created from the vertexes.
proc newPolyShape*(body: PBody; numVerts: cint; verts: ptr TVector;
proc newPolyShape*(body: PBody; numVerts: cint; verts: ptr TVector;
offset: TVector): PShape {.
cdecl, importc: "cpPolyShapeNew", dynlib: Lib.}
#/ Initialize a box shaped polygon shape.
@ -1129,11 +1129,11 @@ proc MomentForBox2*(m: CpFloat; box: TBB): CpFloat {.
##constraints
type
type
#TODO: all these are private
#TODO: defConstraintProp()
PPinJoint = ptr TPinJoint
TPinJoint{.pf.} = object
TPinJoint{.pf.} = object
constraint: PConstraint
anchr1: TVector
anchr2: TVector
@ -1146,7 +1146,7 @@ type
jnMax: CpFloat
bias: CpFloat
PSlideJoint = ptr TSlideJoint
TSlideJoint{.pf.} = object
TSlideJoint{.pf.} = object
constraint: PConstraint
anchr1: TVector
anchr2: TVector
@ -1160,7 +1160,7 @@ type
jnMax: CpFloat
bias: CpFloat
PPivotJoint = ptr TPivotJoint
TPivotJoint{.pf.} = object
TPivotJoint{.pf.} = object
constraint: PConstraint
anchr1: TVector
anchr2: TVector
@ -1172,7 +1172,7 @@ type
jMaxLen: CpFloat
bias: TVector
PGrooveJoint = ptr TGrooveJoint
TGrooveJoint{.pf.} = object
TGrooveJoint{.pf.} = object
constraint: PConstraint
grv_n: TVector
grv_a: TVector
@ -1188,7 +1188,7 @@ type
jMaxLen: CpFloat
bias: TVector
PDampedSpring = ptr TDampedSpring
TDampedSpring{.pf.} = object
TDampedSpring{.pf.} = object
constraint: PConstraint
anchr1: TVector
anchr2: TVector
@ -1203,7 +1203,7 @@ type
nMass: CpFloat
n: TVector
PDampedRotarySpring = ptr TDampedRotarySpring
TDampedRotarySpring{.pf.} = object
TDampedRotarySpring{.pf.} = object
constraint: PConstraint
restAngle: CpFloat
stiffness: CpFloat
@ -1213,7 +1213,7 @@ type
w_coef: CpFloat
iSum: CpFloat
PRotaryLimitJoint = ptr TRotaryLimitJoint
TRotaryLimitJoint{.pf.} = object
TRotaryLimitJoint{.pf.} = object
constraint: PConstraint
min: CpFloat
max: CpFloat
@ -1222,7 +1222,7 @@ type
jAcc: CpFloat
jMax: CpFloat
PRatchetJoint = ptr TRatchetJoint
TRatchetJoint{.pf.} = object
TRatchetJoint{.pf.} = object
constraint: PConstraint
angle: CpFloat
phase: CpFloat
@ -1232,7 +1232,7 @@ type
jAcc: CpFloat
jMax: CpFloat
PGearJoint = ptr TGearJoint
TGearJoint{.pf.} = object
TGearJoint{.pf.} = object
constraint: PConstraint
phase: CpFloat
ratio: CpFloat
@ -1242,7 +1242,7 @@ type
jAcc: CpFloat
jMax: CpFloat
PSimpleMotor = ptr TSimpleMotor
TSimpleMotor{.pf.} = object
TSimpleMotor{.pf.} = object
constraint: PConstraint
rate: CpFloat
iSum: CpFloat
@ -1250,7 +1250,7 @@ type
jMax: CpFloat
TDampedSpringForceFunc* = proc (spring: PConstraint; dist: CpFloat): CpFloat{.
cdecl.}
TDampedRotarySpringTorqueFunc* = proc (spring: PConstraint;
TDampedRotarySpringTorqueFunc* = proc (spring: PConstraint;
relativeAngle: CpFloat): CpFloat {.cdecl.}
#/ Destroy a constraint.
proc destroy*(constraint: PConstraint){.
@ -1260,7 +1260,7 @@ proc free*(constraint: PConstraint){.
cdecl, importc: "cpConstraintFree", dynlib: Lib.}
#/ @private
proc activateBodies(constraint: PConstraint) {.inline.} =
proc activateBodies(constraint: PConstraint) {.inline.} =
if not constraint.a.isNil: constraint.a.activate()
if not constraint.b.isNil: constraint.b.activate()
@ -1291,7 +1291,7 @@ defGetter(PConstraint, TConstraintPreSolveFunc, preSolve, PreSolveFunc)
defGetter(PConstraint, TConstraintPostSolveFunc, postSolve, PostSolveFunc)
defGetter(PConstraint, CpDataPointer, data, UserData)
# Get the last impulse applied by this constraint.
proc getImpulse*(constraint: PConstraint): CpFloat {.inline.} =
proc getImpulse*(constraint: PConstraint): CpFloat {.inline.} =
return constraint.klass.getImpulse(constraint)
# #define cpConstraintCheckCast(constraint, struct) \
@ -1309,7 +1309,7 @@ proc getImpulse*(constraint: PConstraint): CpFloat {.inline.} =
# }
template constraintCheckCast(constraint: PConstraint, ctype: expr): stmt {.immediate.} =
assert(constraint.klass == `ctype getClass`(), "Constraint is the wrong class")
template defCGetter(ctype: expr, memberType: typedesc, member: expr, name: expr): stmt {.immediate.} =
template defCGetter(ctype: expr, memberType: typedesc, member: expr, name: expr): stmt {.immediate.} =
proc `get ctype name`*(constraint: PConstraint): memberType {.cdecl.} =
constraintCheckCast(constraint, ctype)
result = cast[`P ctype`](constraint).member
@ -1330,7 +1330,7 @@ proc PinJointGetClass*(): PConstraintClass{.
proc AllocPinJoint*(): PPinJoint{.
cdecl, importc: "cpPinJointAlloc", dynlib: Lib.}
#/ Initialize a pin joint.
proc PinJointInit*(joint: PPinJoint; a: PBody; b: PBody; anchr1: TVector;
proc PinJointInit*(joint: PPinJoint; a: PBody; b: PBody; anchr1: TVector;
anchr2: TVector): PPinJoint{.
cdecl, importc: "cpPinJointInit", dynlib: Lib.}
#/ Allocate and initialize a pin joint.
@ -1411,7 +1411,7 @@ proc init*(joint: PDampedSpring; a, b: PBody; anchr1, anchr2: TVector;
restLength, stiffness, damping: CpFloat): PDampedSpring{.
cdecl, importc: "cpDampedSpringInit", dynlib: Lib.}
#/ Allocate and initialize a damped spring.
proc newDampedSpring*(a, b: PBody; anchr1, anchr2: TVector;
proc newDampedSpring*(a, b: PBody; anchr1, anchr2: TVector;
restLength, stiffness, damping: CpFloat): PConstraint{.
cdecl, importc: "cpDampedSpringNew", dynlib: Lib.}
@ -1431,7 +1431,7 @@ proc DampedRotarySpringGetClass*(): PConstraintClass{.
proc DampedRotarySpringAlloc*(): PDampedRotarySpring{.
cdecl, importc: "cpDampedRotarySpringAlloc", dynlib: Lib.}
#/ Initialize a damped rotary spring.
proc init*(joint: PDampedRotarySpring; a, b: PBody;
proc init*(joint: PDampedRotarySpring; a, b: PBody;
restAngle, stiffness, damping: CpFloat): PDampedRotarySpring{.
cdecl, importc: "cpDampedRotarySpringInit", dynlib: Lib.}
#/ Allocate and initialize a damped rotary spring.
@ -1477,7 +1477,7 @@ defCProp(RatchetJoint, CpFloat, phase, Phase)
defCProp(RatchetJoint, CpFloat, ratchet, Ratchet)
proc GearJointGetClass*(): PConstraintClass{.cdecl,
proc GearJointGetClass*(): PConstraintClass{.cdecl,
importc: "cpGearJointGetClass", dynlib: Lib.}
#/ Allocate a gear joint.
proc AllocGearJoint*(): PGearJoint{.
@ -1502,7 +1502,7 @@ proc SimpleMotorGetClass*(): PConstraintClass{.
proc AllocSimpleMotor*(): PSimpleMotor{.
cdecl, importc: "cpSimpleMotorAlloc", dynlib: Lib.}
#/ initialize a simple motor.
proc init*(joint: PSimpleMotor; a, b: PBody;
proc init*(joint: PSimpleMotor; a, b: PBody;
rate: CpFloat): PSimpleMotor{.
cdecl, importc: "cpSimpleMotorInit", dynlib: Lib.}
#/ Allocate and initialize a simple motor.

View file

@ -1,52 +1,52 @@
discard """Copyright (c) 2002-2012 Lee Salzman
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
const Lib = "libenet.so.1(|.0.3)"
{.deadCodeElim: on.}
const
const
ENET_VERSION_MAJOR* = 1
ENET_VERSION_MINOR* = 3
ENET_VERSION_PATCH* = 3
template ENET_VERSION_CREATE(major, minor, patch: expr): expr =
template ENET_VERSION_CREATE(major, minor, patch: expr): expr =
(((major) shl 16) or ((minor) shl 8) or (patch))
const
ENET_VERSION* = ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR,
const
ENET_VERSION* = ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR,
ENET_VERSION_PATCH)
type
type
TVersion* = cuint
TSocketType*{.size: sizeof(cint).} = enum
TSocketType*{.size: sizeof(cint).} = enum
ENET_SOCKET_TYPE_STREAM = 1, ENET_SOCKET_TYPE_DATAGRAM = 2
TSocketWait*{.size: sizeof(cint).} = enum
ENET_SOCKET_WAIT_NONE = 0, ENET_SOCKET_WAIT_SEND = (1 shl 0),
TSocketWait*{.size: sizeof(cint).} = enum
ENET_SOCKET_WAIT_NONE = 0, ENET_SOCKET_WAIT_SEND = (1 shl 0),
ENET_SOCKET_WAIT_RECEIVE = (1 shl 1)
TSocketOption*{.size: sizeof(cint).} = enum
ENET_SOCKOPT_NONBLOCK = 1, ENET_SOCKOPT_BROADCAST = 2,
ENET_SOCKOPT_RCVBUF = 3, ENET_SOCKOPT_SNDBUF = 4,
TSocketOption*{.size: sizeof(cint).} = enum
ENET_SOCKOPT_NONBLOCK = 1, ENET_SOCKOPT_BROADCAST = 2,
ENET_SOCKOPT_RCVBUF = 3, ENET_SOCKOPT_SNDBUF = 4,
ENET_SOCKOPT_REUSEADDR = 5
const
const
ENET_HOST_ANY* = 0
ENET_HOST_BROADCAST* = 0xFFFFFFFF
ENET_PORT_ANY* = 0
ENET_PROTOCOL_MINIMUM_MTU* = 576
ENET_PROTOCOL_MAXIMUM_MTU* = 4096
ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS* = 32
@ -57,29 +57,29 @@ const
ENET_PROTOCOL_MAXIMUM_PEER_ID* = 0x00000FFF
type
PAddress* = ptr TAddress
TAddress*{.pure, final.} = object
TAddress*{.pure, final.} = object
host*: cuint
port*: cushort
TPacketFlag*{.size: sizeof(cint).} = enum
FlagReliable = (1 shl 0),
FlagUnsequenced = (1 shl 1),
NoAllocate = (1 shl 2),
TPacketFlag*{.size: sizeof(cint).} = enum
FlagReliable = (1 shl 0),
FlagUnsequenced = (1 shl 1),
NoAllocate = (1 shl 2),
UnreliableFragment = (1 shl 3)
TENetListNode*{.pure, final.} = object
TENetListNode*{.pure, final.} = object
next*: ptr T_ENetListNode
previous*: ptr T_ENetListNode
PENetListIterator* = ptr TENetListNode
TENetList*{.pure, final.} = object
TENetList*{.pure, final.} = object
sentinel*: TENetListNode
T_ENetPacket*{.pure, final.} = object
T_ENetPacket*{.pure, final.} = object
TPacketFreeCallback* = proc (a2: ptr T_ENetPacket){.cdecl.}
PPacket* = ptr TPacket
TPacket*{.pure, final.} = object
TPacket*{.pure, final.} = object
referenceCount: csize
flags*: cint
data*: cstring#ptr cuchar
@ -87,13 +87,13 @@ type
freeCallback*: TPacketFreeCallback
PAcknowledgement* = ptr TAcknowledgement
TAcknowledgement*{.pure, final.} = object
TAcknowledgement*{.pure, final.} = object
acknowledgementList*: TEnetListNode
sentTime*: cuint
command*: TEnetProtocol
POutgoingCommand* = ptr TOutgoingCommand
TOutgoingCommand*{.pure, final.} = object
TOutgoingCommand*{.pure, final.} = object
outgoingCommandList*: TEnetListNode
reliableSequenceNumber*: cushort
unreliableSequenceNumber*: cushort
@ -107,7 +107,7 @@ type
packet*: PPacket
PIncomingCommand* = ptr TIncomingCommand
TIncomingCommand*{.pure, final.} = object
TIncomingCommand*{.pure, final.} = object
incomingCommandList*: TEnetListNode
reliableSequenceNumber*: cushort
unreliableSequenceNumber*: cushort
@ -117,52 +117,52 @@ type
fragments*: ptr cuint
packet*: ptr TPacket
TPeerState*{.size: sizeof(cint).} = enum
ENET_PEER_STATE_DISCONNECTED = 0, ENET_PEER_STATE_CONNECTING = 1,
ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
ENET_PEER_STATE_CONNECTION_PENDING = 3,
ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4, ENET_PEER_STATE_CONNECTED = 5,
ENET_PEER_STATE_DISCONNECT_LATER = 6, ENET_PEER_STATE_DISCONNECTING = 7,
TPeerState*{.size: sizeof(cint).} = enum
ENET_PEER_STATE_DISCONNECTED = 0, ENET_PEER_STATE_CONNECTING = 1,
ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
ENET_PEER_STATE_CONNECTION_PENDING = 3,
ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4, ENET_PEER_STATE_CONNECTED = 5,
ENET_PEER_STATE_DISCONNECT_LATER = 6, ENET_PEER_STATE_DISCONNECTING = 7,
ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8, ENET_PEER_STATE_ZOMBIE = 9
TENetProtocolCommand*{.size: sizeof(cint).} = enum
ENET_PROTOCOL_COMMAND_NONE = 0, ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
ENET_PROTOCOL_COMMAND_CONNECT = 2,
ENET_PROTOCOL_COMMAND_VERIFY_CONNECT = 3,
ENET_PROTOCOL_COMMAND_DISCONNECT = 4, ENET_PROTOCOL_COMMAND_PING = 5,
ENET_PROTOCOL_COMMAND_SEND_RELIABLE = 6,
ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE = 7,
ENET_PROTOCOL_COMMAND_SEND_FRAGMENT = 8,
ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED = 9,
ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT = 10,
ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE = 11,
ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT = 12,
TENetProtocolCommand*{.size: sizeof(cint).} = enum
ENET_PROTOCOL_COMMAND_NONE = 0, ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
ENET_PROTOCOL_COMMAND_CONNECT = 2,
ENET_PROTOCOL_COMMAND_VERIFY_CONNECT = 3,
ENET_PROTOCOL_COMMAND_DISCONNECT = 4, ENET_PROTOCOL_COMMAND_PING = 5,
ENET_PROTOCOL_COMMAND_SEND_RELIABLE = 6,
ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE = 7,
ENET_PROTOCOL_COMMAND_SEND_FRAGMENT = 8,
ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED = 9,
ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT = 10,
ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE = 11,
ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT = 12,
ENET_PROTOCOL_COMMAND_COUNT = 13, ENET_PROTOCOL_COMMAND_MASK = 0x0000000F
TENetProtocolFlag*{.size: sizeof(cint).} = enum
TENetProtocolFlag*{.size: sizeof(cint).} = enum
ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12,
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 shl 6),
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 shl 7),
ENET_PROTOCOL_HEADER_SESSION_MASK = (3 shl 12),
ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 shl 14),
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 shl 6),
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 shl 7),
ENET_PROTOCOL_HEADER_SESSION_MASK = (3 shl 12),
ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 shl 14),
ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 shl 15),
ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED.cint or
ENET_PROTOCOL_HEADER_FLAG_SENT_TIME.cint
TENetProtocolHeader*{.pure, final.} = object
TENetProtocolHeader*{.pure, final.} = object
peerID*: cushort
sentTime*: cushort
TENetProtocolCommandHeader*{.pure, final.} = object
TENetProtocolCommandHeader*{.pure, final.} = object
command*: cuchar
channelID*: cuchar
reliableSequenceNumber*: cushort
TENetProtocolAcknowledge*{.pure, final.} = object
TENetProtocolAcknowledge*{.pure, final.} = object
header*: TENetProtocolCommandHeader
receivedReliableSequenceNumber*: cushort
receivedSentTime*: cushort
TENetProtocolConnect*{.pure, final.} = object
TENetProtocolConnect*{.pure, final.} = object
header*: TENetProtocolCommandHeader
outgoingPeerID*: cushort
incomingSessionID*: cuchar
@ -178,7 +178,7 @@ type
connectID*: cuint
data*: cuint
TENetProtocolVerifyConnect*{.pure, final.} = object
TENetProtocolVerifyConnect*{.pure, final.} = object
header*: TENetProtocolCommandHeader
outgoingPeerID*: cushort
incomingSessionID*: cuchar
@ -193,39 +193,39 @@ type
packetThrottleDeceleration*: cuint
connectID*: cuint
TENetProtocolBandwidthLimit*{.pure, final.} = object
TENetProtocolBandwidthLimit*{.pure, final.} = object
header*: TENetProtocolCommandHeader
incomingBandwidth*: cuint
outgoingBandwidth*: cuint
TENetProtocolThrottleConfigure*{.pure, final.} = object
TENetProtocolThrottleConfigure*{.pure, final.} = object
header*: TENetProtocolCommandHeader
packetThrottleInterval*: cuint
packetThrottleAcceleration*: cuint
packetThrottleDeceleration*: cuint
TENetProtocolDisconnect*{.pure, final.} = object
TENetProtocolDisconnect*{.pure, final.} = object
header*: TENetProtocolCommandHeader
data*: cuint
TENetProtocolPing*{.pure, final.} = object
TENetProtocolPing*{.pure, final.} = object
header*: TENetProtocolCommandHeader
TENetProtocolSendReliable*{.pure, final.} = object
TENetProtocolSendReliable*{.pure, final.} = object
header*: TENetProtocolCommandHeader
dataLength*: cushort
TENetProtocolSendUnreliable*{.pure, final.} = object
TENetProtocolSendUnreliable*{.pure, final.} = object
header*: TENetProtocolCommandHeader
unreliableSequenceNumber*: cushort
dataLength*: cushort
TENetProtocolSendUnsequenced*{.pure, final.} = object
TENetProtocolSendUnsequenced*{.pure, final.} = object
header*: TENetProtocolCommandHeader
unsequencedGroup*: cushort
dataLength*: cushort
TENetProtocolSendFragment*{.pure, final.} = object
TENetProtocolSendFragment*{.pure, final.} = object
header*: TENetProtocolCommandHeader
startSequenceNumber*: cushort
dataLength*: cushort
@ -233,12 +233,12 @@ type
fragmentNumber*: cuint
totalLength*: cuint
fragmentOffset*: cuint
## this is incomplete; need helper templates or something
## ENetProtocol
TENetProtocol*{.pure, final.} = object
TENetProtocol*{.pure, final.} = object
header*: TENetProtocolCommandHeader
const
const
ENET_BUFFER_MAXIMUM* = (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)
ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024
ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024
@ -270,39 +270,39 @@ when defined(Linux) or true:
import posix
const
ENET_SOCKET_NULL*: cint = -1
type
type
TENetSocket* = cint
PEnetBuffer* = ptr object
TENetBuffer*{.pure, final.} = object
TENetBuffer*{.pure, final.} = object
data*: pointer
dataLength*: csize
TENetSocketSet* = Tfd_set
## see if these are different on win32, if not then get rid of these
template ENET_HOST_TO_NET_16*(value: expr): expr =
template ENET_HOST_TO_NET_16*(value: expr): expr =
(htons(value))
template ENET_HOST_TO_NET_32*(value: expr): expr =
template ENET_HOST_TO_NET_32*(value: expr): expr =
(htonl(value))
template ENET_NET_TO_HOST_16*(value: expr): expr =
template ENET_NET_TO_HOST_16*(value: expr): expr =
(ntohs(value))
template ENET_NET_TO_HOST_32*(value: expr): expr =
template ENET_NET_TO_HOST_32*(value: expr): expr =
(ntohl(value))
template ENET_SOCKETSET_EMPTY*(sockset: expr): expr =
template ENET_SOCKETSET_EMPTY*(sockset: expr): expr =
FD_ZERO(addr((sockset)))
template ENET_SOCKETSET_ADD*(sockset, socket: expr): expr =
template ENET_SOCKETSET_ADD*(sockset, socket: expr): expr =
FD_SET(socket, addr((sockset)))
template ENET_SOCKETSET_REMOVE*(sockset, socket: expr): expr =
template ENET_SOCKETSET_REMOVE*(sockset, socket: expr): expr =
FD_CLEAR(socket, addr((sockset)))
template ENET_SOCKETSET_CHECK*(sockset, socket: expr): expr =
template ENET_SOCKETSET_CHECK*(sockset, socket: expr): expr =
FD_ISSET(socket, addr((sockset)))
when defined(Windows):
## put the content of win32.h in here
type
type
PChannel* = ptr TChannel
TChannel*{.pure, final.} = object
TChannel*{.pure, final.} = object
outgoingReliableSequenceNumber*: cushort
outgoingUnreliableSequenceNumber*: cushort
usedReliableWindows*: cushort
@ -313,7 +313,7 @@ type
incomingUnreliableCommands*: TENetList
PPeer* = ptr TPeer
TPeer*{.pure, final.} = object
TPeer*{.pure, final.} = object
dispatchList*: TEnetListNode
host*: ptr THost
outgoingPeerID*: cushort
@ -367,25 +367,25 @@ type
needsDispatch*: cint
incomingUnsequencedGroup*: cushort
outgoingUnsequencedGroup*: cushort
unsequencedWindow*: array[0..ENET_PEER_UNSEQUENCED_WINDOW_SIZE div 32 - 1,
unsequencedWindow*: array[0..ENET_PEER_UNSEQUENCED_WINDOW_SIZE div 32 - 1,
cuint]
eventData*: cuint
PCompressor* = ptr TCompressor
TCompressor*{.pure, final.} = object
TCompressor*{.pure, final.} = object
context*: pointer
compress*: proc (context: pointer; inBuffers: ptr TEnetBuffer;
inBufferCount: csize; inLimit: csize;
compress*: proc (context: pointer; inBuffers: ptr TEnetBuffer;
inBufferCount: csize; inLimit: csize;
outData: ptr cuchar; outLimit: csize): csize{.cdecl.}
decompress*: proc (context: pointer; inData: ptr cuchar; inLimit: csize;
decompress*: proc (context: pointer; inData: ptr cuchar; inLimit: csize;
outData: ptr cuchar; outLimit: csize): csize{.cdecl.}
destroy*: proc (context: pointer){.cdecl.}
TChecksumCallback* = proc (buffers: ptr TEnetBuffer; bufferCount: csize): cuint{.
cdecl.}
PHost* = ptr THost
THost*{.pure, final.} = object
THost*{.pure, final.} = object
socket*: TEnetSocket
address*: TAddress
incomingBandwidth*: cuint
@ -402,14 +402,14 @@ type
continueSending*: cint
packetSize*: csize
headerFlags*: cushort
commands*: array[0..ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS - 1,
commands*: array[0..ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS - 1,
TEnetProtocol]
commandCount*: csize
buffers*: array[0..ENET_BUFFER_MAXIMUM - 1, TEnetBuffer]
bufferCount*: csize
checksum*: TChecksumCallback
compressor*: TCompressor
packetData*: array[0..ENET_PROTOCOL_MAXIMUM_MTU - 1,
packetData*: array[0..ENET_PROTOCOL_MAXIMUM_MTU - 1,
array[0..2 - 1, cuchar]]
receivedAddress*: TAddress
receivedData*: ptr cuchar
@ -418,19 +418,19 @@ type
totalSentPackets*: cuint
totalReceivedData*: cuint
totalReceivedPackets*: cuint
TEventType*{.size: sizeof(cint).} = enum
EvtNone = 0, EvtConnect = 1,
TEventType*{.size: sizeof(cint).} = enum
EvtNone = 0, EvtConnect = 1,
EvtDisconnect = 2, EvtReceive = 3
PEvent* = ptr TEvent
TEvent*{.pure, final.} = object
TEvent*{.pure, final.} = object
kind*: TEventType
peer*: ptr TPeer
channelID*: cuchar
data*: cuint
packet*: ptr TPacket
TENetCallbacks*{.pure, final.} = object
TENetCallbacks*{.pure, final.} = object
malloc*: proc (size: csize): pointer{.cdecl.}
free*: proc (memory: pointer){.cdecl.}
no_memory*: proc (){.cdecl.}
@ -473,10 +473,10 @@ proc send*(socket: TEnetSocket; address: var TAddress; buffer: ptr TEnetBuffer;
importc: "enet_socket_send", dynlib: Lib.}
proc send*(socket: TEnetSocket; address: ptr TAddress; buffer: ptr TEnetBuffer; size: csize): cint{.
importc: "enet_socket_send", dynlib: Lib.}
proc receive*(socket: TEnetSocket; address: var TAddress;
proc receive*(socket: TEnetSocket; address: var TAddress;
buffer: ptr TEnetBuffer; size: csize): cint{.
importc: "enet_socket_receive", dynlib: Lib.}
proc receive*(socket: TEnetSocket; address: ptr TAddress;
proc receive*(socket: TEnetSocket; address: ptr TAddress;
buffer: ptr TEnetBuffer; size: csize): cint{.
importc: "enet_socket_receive", dynlib: Lib.}
proc wait*(socket: TEnetSocket; a3: ptr cuint; a4: cuint): cint{.
@ -485,7 +485,7 @@ proc setOption*(socket: TEnetSocket; a3: TSocketOption; a4: cint): cint{.
importc: "enet_socket_set_option", dynlib: Lib.}
proc destroy*(socket: TEnetSocket){.
importc: "enet_socket_destroy", dynlib: Lib.}
proc select*(socket: TEnetSocket; a3: ptr TENetSocketSet;
proc select*(socket: TEnetSocket; a3: ptr TENetSocketSet;
a4: ptr TENetSocketSet; a5: cuint): cint{.
importc: "enet_socketset_select", dynlib: Lib.}
@ -578,13 +578,13 @@ proc resetQueues*(peer: PPeer){.
proc setupOutgoingCommand*(peer: PPeer; outgoingCommand: POutgoingCommand){.
importc: "enet_peer_setup_outgoing_command", dynlib: Lib.}
proc queueOutgoingCommand*(peer: PPeer; command: ptr TEnetProtocol;
proc queueOutgoingCommand*(peer: PPeer; command: ptr TEnetProtocol;
packet: PPacket; offset: cuint; length: cushort): POutgoingCommand{.
importc: "enet_peer_queue_outgoing_command", dynlib: Lib.}
proc queueIncomingCommand*(peer: PPeer; command: ptr TEnetProtocol;
proc queueIncomingCommand*(peer: PPeer; command: ptr TEnetProtocol;
packet: PPacket; fragmentCount: cuint): PIncomingCommand{.
importc: "enet_peer_queue_incoming_command", dynlib: Lib.}
proc queueAcknowledgement*(peer: PPeer; command: ptr TEnetProtocol;
proc queueAcknowledgement*(peer: PPeer; command: ptr TEnetProtocol;
sentTime: cushort): PAcknowledgement{.
importc: "enet_peer_queue_acknowledgement", dynlib: Lib.}
proc dispatchIncomingUnreliableCommands*(peer: PPeer; channel: PChannel){.
@ -596,10 +596,10 @@ proc createRangeCoder*(): pointer{.
importc: "enet_range_coder_create", dynlib: Lib.}
proc rangeCoderDestroy*(context: pointer){.
importc: "enet_range_coder_destroy", dynlib: Lib.}
proc rangeCoderCompress*(context: pointer; inBuffers: PEnetBuffer; inLimit,
proc rangeCoderCompress*(context: pointer; inBuffers: PEnetBuffer; inLimit,
bufferCount: csize; outData: cstring; outLimit: csize): csize{.
importc: "enet_range_coder_compress", dynlib: Lib.}
proc rangeCoderDecompress*(context: pointer; inData: cstring; inLimit: csize;
proc rangeCoderDecompress*(context: pointer; inData: cstring; inLimit: csize;
outData: cstring; outLimit: csize): csize{.
importc: "enet_range_coder_decompress", dynlib: Lib.}
proc protocolCommandSize*(commandNumber: cuchar): csize{.

View file

@ -19,11 +19,11 @@ while server.hostService(addr event, 2500) >= 0:
case event.kind
of EvtConnect:
echo "New client from $1:$2".format(event.peer.address.host, event.peer.address.port)
var
msg = "hello"
msg = "hello"
resp = createPacket(cstring(msg), msg.len + 1, FlagReliable)
if event.peer.send(0.cuchar, resp) < 0:
echo "FAILED"
else:
@ -32,9 +32,9 @@ while server.hostService(addr event, 2500) >= 0:
echo "Recvd ($1) $2 ".format(
event.packet.dataLength,
event.packet.data)
destroy(event.packet)
of EvtDisconnect:
echo "Disconnected"
event.peer.data = nil
@ -42,4 +42,4 @@ while server.hostService(addr event, 2500) >= 0:
discard
server.destroy()
enetDeinit()
enetDeinit()

View file

@ -1,7 +1,7 @@
import streams
from strutils import repeat
proc readPaddedStr*(s: PStream, length: int, padChar = '\0'): TaintedString =
proc readPaddedStr*(s: PStream, length: int, padChar = '\0'): TaintedString =
var lastChr = length
result = s.readStr(length)
while lastChr >= 0 and result[lastChr - 1] == padChar: dec(lastChr)
@ -26,22 +26,22 @@ proc writeLEStr*(s: PStream, str: string) =
when isMainModule:
var testStream = newStringStream()
testStream.writeLEStr("Hello")
doAssert testStream.data == "\5\0Hello"
testStream.setPosition 0
var res = testStream.readLEStr()
doAssert res == "Hello"
testStream.setPosition 0
testStream.writePaddedStr("Sup", 10)
echo(repr(testStream), testStream.data.len)
doAssert testStream.data == "Sup"&repeat('\0', 7)
testStream.setPosition 0
res = testStream.readPaddedStr(10)
doAssert res == "Sup"
testStream.close()

View file

@ -3,7 +3,7 @@ DO AS THOU WILST PUBLIC LICENSE
Whoever should stumble upon this document is henceforth and forever
entitled to DO AS THOU WILST with aforementioned document and the
contents thereof.
contents thereof.
As said in the Olde Country, `Keepe it Gangster'."""
@ -14,7 +14,7 @@ type
desc*: string
action*: TTaskFunction
TTaskFunction* = proc() {.closure.}
var
var
tasks* = initTable[string, PTask](16)
proc newTask*(desc: string; action: TTaskFunction): PTask
@ -61,7 +61,7 @@ when isMainModule:
quit(shell("nim", "c", "-r", "nakefile.nim", args))
else:
addQuitProc(proc() {.noconv.} =
var
var
task: string
printTaskList: bool
for kind, key, val in getOpt():
@ -70,7 +70,7 @@ else:
case key.tolower
of "tasks", "t":
printTaskList = true
else:
else:
echo "Unknown option: ", key, ": ", val
of cmdArgument:
task = key

View file

@ -1,4 +1,4 @@
import
import
strutils, math
when defined(linux):
const
@ -27,7 +27,7 @@ type
x*, y*, z*: cfloat
PInputStream* = ptr TInputStream
TInputStream* {.pf.} = object
TInputStream* {.pf.} = object
read*: TInputStreamReadFunc
seek*: TInputStreamSeekFunc
tell*: TInputStreamTellFunc
@ -52,14 +52,14 @@ type
width*: cint
height*: cint
bitsPerPixel*: cint
TEventType*{.size: sizeof(cint).} = enum
EvtClosed, EvtResized, EvtLostFocus, EvtGainedFocus,
EvtTextEntered, EvtKeyPressed, EvtKeyReleased, EvtMouseWheelMoved,
EvtMouseButtonPressed, EvtMouseButtonReleased, EvtMouseMoved,
EvtMouseEntered, EvtMouseLeft, EvtJoystickButtonPressed,
EvtJoystickButtonReleased, EvtJoystickMoved, EvtJoystickConnected,
TEventType*{.size: sizeof(cint).} = enum
EvtClosed, EvtResized, EvtLostFocus, EvtGainedFocus,
EvtTextEntered, EvtKeyPressed, EvtKeyReleased, EvtMouseWheelMoved,
EvtMouseButtonPressed, EvtMouseButtonReleased, EvtMouseMoved,
EvtMouseEntered, EvtMouseLeft, EvtJoystickButtonPressed,
EvtJoystickButtonReleased, EvtJoystickMoved, EvtJoystickConnected,
EvtJoystickDisconnected
TKeyEvent*{.pf.} = object
TKeyEvent*{.pf.} = object
code*: TKeyCode
alt* : bool
control*: bool
@ -74,7 +74,7 @@ type
joystickId*: cint
axis*: TJoystickAxis
position*: cfloat
TMouseWheelEvent*{.pf.} = object
TMouseWheelEvent*{.pf.} = object
delta*: cint
x*: cint
y*: cint
@ -90,7 +90,7 @@ type
PEvent* = ptr TEvent
TEvent*{.pf.} = object
case kind*: TEventType
of EvtKeyPressed, EvtKeyReleased:
of EvtKeyPressed, EvtKeyReleased:
key*: TKeyEvent
of EvtMouseButtonPressed, EvtMouseButtonReleased:
mouseButton*: TMouseButtonEvent
@ -109,16 +109,16 @@ type
of EvtMouseWheelMoved:
mouseWheel*: TMouseWheelEvent
else: nil
TJoystickAxis*{.size: sizeof(cint).} = enum
JoystickX, JoystickY, JoystickZ, JoystickR,
TJoystickAxis*{.size: sizeof(cint).} = enum
JoystickX, JoystickY, JoystickZ, JoystickR,
JoystickU, JoystickV, JoystickPovX, JoystickPovY
TSizeEvent*{.pf.} = object
width*: cint
height*: cint
TMouseButton*{.size: sizeof(cint).} = enum
MouseLeft, MouseRight, MouseMiddle,
TMouseButton*{.size: sizeof(cint).} = enum
MouseLeft, MouseRight, MouseMiddle,
MouseXButton1, MouseXButton2, MouseButtonCount
TKeyCode*{.size: sizeof(cint).} = enum
TKeyCode*{.size: sizeof(cint).} = enum
KeyUnknown = - 1, KeyA, KeyB, KeyC, KeyD, KeyE,
KeyF, KeyG, KeyH, KeyI, KeyJ, KeyK, KeyL, KeyM, #/< The M key
KeyN, KeyO, KeyP, KeyQ, KeyR, KeyS, KeyT, KeyU, #/< The U key
@ -204,11 +204,11 @@ type
PConvexShape* = ptr TConvexShape
TConvexShape* {.pf.} = object
TTextStyle*{.size: sizeof(cint).} = enum
TextRegular = 0, TextBold = 1 shl 0, TextItalic = 1 shl 1,
TTextStyle*{.size: sizeof(cint).} = enum
TextRegular = 0, TextBold = 1 shl 0, TextItalic = 1 shl 1,
TextUnderlined = 1 shl 2
TBlendMode*{.size: sizeof(cint).} = enum
TBlendMode*{.size: sizeof(cint).} = enum
BlendAlpha, BlendAdd, BlendMultiply, BlendNone
PRenderStates* = ptr TRenderStates
TRenderStates* {.pf.} = object
@ -220,19 +220,19 @@ type
PTransform* = ptr TTransform
TTransform* {.pf.} = object
matrix*: array[0..8, cfloat]
TColor* {.pf.} = object
TColor* {.pf.} = object
r*: uint8
g*: uint8
b*: uint8
a*: uint8
PFloatRect* = ptr TFloatRect
TFloatRect*{.pf.} = object
TFloatRect*{.pf.} = object
left*: cfloat
top*: cfloat
width*: cfloat
height*: cfloat
PIntRect* = ptr TIntRect
TIntRect*{.pf.} = object
TIntRect*{.pf.} = object
left*: cint
top*: cint
width*: cint
@ -246,7 +246,7 @@ type
position*: TVector2f
color*: TColor
texCoords*: TVector2f
TPrimitiveType*{.size: sizeof(cint).} = enum
TPrimitiveType*{.size: sizeof(cint).} = enum
Points, #/< List of individual points
Lines, #/< List of individual lines
LinesStrip, #/< List of connected lines, a point uses the previous point to form a line
@ -381,7 +381,7 @@ proc draw*(window: PRenderWindow, shape: PConvexShape, states: PRenderStates = n
cdecl, importc: "sfRenderWindow_drawConvexShape", dynlib: LibG.}
proc draw*(window: PRenderWindow, shape: PVertexArray, states: PRenderStates = nil) {.
cdecl, importc: "sfRenderWindow_drawVertexArray", dynlib: LibG.}
proc draw*(window: PRenderWindow, vertices: PVertex, vertexCount: cint,
proc draw*(window: PRenderWindow, vertices: PVertex, vertexCount: cint,
vertexType: TPrimitiveType, states: PRenderStates = nil) {.
cdecl, importc: "sfRenderWindow_drawPrimitives", dynlib: LibG.}
@ -434,20 +434,20 @@ proc draw*(renderTexture: PRenderTexture; text: PText; states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawText", dynlib: LibG.}
proc draw*(renderTexture: PRenderTexture; shape: PShape; states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawShape", dynlib: LibG.}
proc draw*(renderTexture: PRenderTexture; shape: PCircleShape;
proc draw*(renderTexture: PRenderTexture; shape: PCircleShape;
states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawCircleShape", dynlib: LibG.}
proc draw*(renderTexture: PRenderTexture; shape: PConvexShape;
proc draw*(renderTexture: PRenderTexture; shape: PConvexShape;
states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawConvexShape", dynlib: LibG.}
proc draw*(renderTexture: PRenderTexture; shape: PRectangleShape;
proc draw*(renderTexture: PRenderTexture; shape: PRectangleShape;
states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawRectangleShape", dynlib: LibG.}
proc draw*(renderTexture: PRenderTexture; va: PVertexArray;
proc draw*(renderTexture: PRenderTexture; va: PVertexArray;
states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawVertexArray", dynlib: LibG.}
#Draw primitives defined by an array of vertices to a render texture
proc draw*(renderTexture: PRenderTexture; vertices: PVertex; vertexCount: cint;
proc draw*(renderTexture: PRenderTexture; vertices: PVertex; vertexCount: cint;
primitiveType: TPrimitiveType; states: PRenderStates){.
cdecl, importc: "sfRenderTexture_drawPrimitives", dynlib: LibG.}
#Save the current OpenGL render states and matrices
@ -500,12 +500,12 @@ proc intRect*(left, top, width, height: cint): TIntRect =
result.height = height
proc floatRect*(left, top, width, height: cfloat): TFloatRect =
result.left = left
result.top = top
result.top = top
result.width = width
result.height = height
proc contains*(rect: PFloatRect, x, y: cfloat): bool {.
cdecl, importc: "sfFloatRect_contains", dynlib: LibG.}
proc contains*(rect: PIntRect, x: cint, y: cint): bool{.cdecl,
proc contains*(rect: PIntRect, x: cint, y: cint): bool{.cdecl,
importc: "sfIntRect_contains", dynlib: LibG.}
proc intersects*(rect1, rect2, intersection: PFloatRect): bool {.
cdecl, importc: "sfFloatRect_intersects", dynlib: LibG.}
@ -894,7 +894,7 @@ proc setColor*(text: PText, color: TColor) {.
cdecl, importc: "sfText_setColor", dynlib: LibG.}
proc getString*(text: PText): cstring {.
cdecl, importc: "sfText_getString", dynlib: LibG.}
proc getUnicodeString*(text: PText): ptr uint32 {.cdecl,
proc getUnicodeString*(text: PText): ptr uint32 {.cdecl,
importc: "sfText_getUnicodeString", dynlib: LibG.}
proc getFont*(text: PText): PFont {.
cdecl, importc: "sfText_getFont", dynlib: LibG.}
@ -985,7 +985,7 @@ proc `*`*(color1, color2: TColor): TColor {.
cdecl, importc: "sfColor_modulate", dynlib: LibG.}
proc newColor*(r,g,b: int): TColor {.inline.} =
return color(r,g,b)
proc newColor*(r,g,b,a: int): TColor {.inline.} =
proc newColor*(r,g,b,a: int): TColor {.inline.} =
return color(r,g,b,a)
proc newClock*(): PClock {.
@ -1022,7 +1022,7 @@ proc newContextSettings*(depthBits: cint = 0,
result.majorVersion = majorVersion
result.minorVersion = minorVersion
proc newCircleShape*(radius: cfloat; pointCount: cint = 30): PCircleShape =
proc newCircleShape*(radius: cfloat; pointCount: cint = 30): PCircleShape =
result = newCircleShape()
result.setRadius radius
result.setPointCount pointCount
@ -1047,13 +1047,13 @@ proc `[]`*(a: PVertexArray, index: int): PVertex =
proc `$` *(a: TContextSettings): string =
return "<TContextSettings stencil=$1 aa=$2 major=$3 minor=$4 depth=$5>" % [
$a.stencilBits, $a.antialiasingLevel, $a.majorVersion, $a.minorVersion, $a.depthBits]
proc `$` *(a: TVideoMode): string =
proc `$` *(a: TVideoMode): string =
return "<TVideoMode $1x$2 $3bpp>" % [$a.width, $a.height, $a.bitsPerPixel]
proc `$` *(a: TFloatRect): string =
proc `$` *(a: TFloatRect): string =
return "<TFloatRect $1,$2 $3x$4>" % [$a.left, $a.top, $a.width, $a.height]
proc `$` *(a: PView): string =
proc `$` *(a: PView): string =
return $a.getViewport()
proc `$` *(a: TVector2f): string =
proc `$` *(a: TVector2f): string =
return "<TVector2f $1,$2>" % [$a.x, $a.y]
proc vec2i*(x, y: int): TVector2i =

View file

@ -294,7 +294,7 @@ proc newSoundBuffer*(stream: PInputStream): PSoundBuffer{.
#/ \return A new sfSoundBuffer object (NULL if failed)
#/
#//////////////////////////////////////////////////////////
proc createFromSamples*(samples: ptr int16; sampleCount: cuint;
proc createFromSamples*(samples: ptr int16; sampleCount: cuint;
channelCount: cuint; sampleRate: cuint): PSoundBuffer{.
cdecl, importc: "sfSoundBuffer_createFromSamples", dynlib: Lib.}
#//////////////////////////////////////////////////////////
@ -437,10 +437,10 @@ proc listenerSetDirection*(orientation: TVector3f){.
proc listenerGetDirection*(): TVector3f{.
cdecl, importc: "sfListener_getDirection", dynlib: Lib.}
type
type
TSoundRecorderStartCallback* = proc (a2: pointer): bool {.cdecl.}
#/< Type of the callback used when starting a capture
TSoundRecorderProcessCallback* = proc(a2: ptr int16; a3: cuint;
#/< Type of the callback used when starting a capture
TSoundRecorderProcessCallback* = proc(a2: ptr int16; a3: cuint;
a4: pointer): bool {.cdecl.}
#/< Type of the callback used to process audio data
TSoundRecorderStopCallback* = proc (a2: pointer){.cdecl.}
@ -456,9 +456,9 @@ type
#/ \return A new sfSoundRecorder object (NULL if failed)
#/
#//////////////////////////////////////////////////////////
proc newSoundRecorder*(onStart: TSoundRecorderStartCallback;
onProcess: TSoundRecorderProcessCallback;
onStop: TSoundRecorderStopCallback;
proc newSoundRecorder*(onStart: TSoundRecorderStartCallback;
onProcess: TSoundRecorderProcessCallback;
onStop: TSoundRecorderStopCallback;
userData: pointer = nil): PSoundRecorder{.
cdecl, importc: "sfSoundRecorder_create", dynlib: Lib.}
#//////////////////////////////////////////////////////////
@ -595,13 +595,13 @@ proc getBuffer*(soundBufferRecorder: PSoundBufferRecorder): PSoundBuffer{.
#/ \brief defines the data to fill by the OnGetData callback
#/
#//////////////////////////////////////////////////////////
type
type
PSoundStreamChunk* = ptr TSoundStreamChunk
TSoundStreamChunk*{.pure, final.} = object
TSoundStreamChunk*{.pure, final.} = object
samples*: ptr int16 #/< Pointer to the audio samples
sampleCount*: cuint #/< Number of samples pointed by Samples
TSoundStreamGetDataCallback* = proc (a2: PSoundStreamChunk;
TSoundStreamGetDataCallback* = proc (a2: PSoundStreamChunk;
a3: pointer): bool{.cdecl.}
#/< Type of the callback used to get a sound stream data
TSoundStreamSeekCallback* = proc (a2: TTime; a3: pointer){.cdecl.}
@ -618,7 +618,7 @@ type
#/ \return A new sfSoundStream object
#/
#//////////////////////////////////////////////////////////
proc create*(onGetData: TSoundStreamGetDataCallback; onSeek: TSoundStreamSeekCallback;
proc create*(onGetData: TSoundStreamGetDataCallback; onSeek: TSoundStreamSeekCallback;
channelCount: cuint; sampleRate: cuint; userData: pointer): PSoundStream{.
cdecl, importc: "sfSoundStream_create", dynlib: Lib.}
#//////////////////////////////////////////////////////////

View file

@ -12,4 +12,4 @@ let
Transparent*: TColor = color(0, 0, 0, 0)
Gray* = color(84, 84, 84)
RoyalBlue* = color(65, 105, 225)
##todo: define more colors lul
##todo: define more colors lul