Example #1
0
World_t *world_create(void)
{
    World_t *out = obj_create_autoreleased(&Class_World);
    out->cpSpace = cpSpaceNew();
    out->cpSpace->data = out;
    cpSpaceAddCollisionHandler(out->cpSpace, 0, 0,
                               collisionWillBegin,
                               NULL,
                               collisionDidBegin,
                               collisionDidEnd, NULL);
    out->entities = obj_retain(llist_create((InsertionCallback_t)&obj_retain, &obj_release));

    // Create the static entity
    out->staticEntity = obj_create(&Class_WorldEntity);
    out->staticEntity->world = out;
    out->staticEntity->owner = out;
    out->staticEntity->cpBody = out->cpSpace->staticBody;
    out->staticEntity->luaUpdateHandler = -1;
    out->staticEntity->luaPreCollisionHandler = -1;
    out->staticEntity->luaCollisionHandler = -1;
    out->staticEntity->luaPostCollisionHandler = -1;
    out->cpSpace->staticBody->data = out->staticEntity;
    out->staticEntity->shapes = obj_retain(llist_create((InsertionCallback_t)&obj_retain, &obj_release));

    return out;
}
Example #2
0
InputManager_t *input_createManager()
{
    InputManager_t *out = obj_create_autoreleased(&Class_InputManager);
    out->observers = obj_retain(llist_create((InsertionCallback_t)&obj_retain, (RemovalCallback_t)&obj_release));
    out->activeEvents = obj_retain(llist_create(NULL, NULL));

    return out;
}
Example #3
0
WorldConstraint_t *worldConstr_createSimpleMotorJoint(WorldEntity_t *a, WorldEntity_t *b, GLMFloat aRate)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_SimpleMotor;
    ret->cpConstraint = cpSimpleMotorNew(a->cpBody, b->cpBody, aRate);
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #4
0
WorldConstraint_t *worldConstr_createRotaryLimitJoint(WorldEntity_t *a, WorldEntity_t *b, GLMFloat aMinAngle, GLMFloat aMaxAngle)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_RotaryLimit;
    ret->cpConstraint = cpRotaryLimitJointNew(a->cpBody, b->cpBody, aMinAngle, aMaxAngle);
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #5
0
WorldConstraint_t *worldConstr_createPivotJoint(WorldEntity_t *a, WorldEntity_t *b, vec2_t aPivot)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_Pivot;
    ret->cpConstraint = cpPivotJointNew(a->cpBody, b->cpBody, VEC2_TO_CPV(aPivot));
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #6
0
WorldConstraint_t *worldConstr_createDampedRotarySpringJoint(WorldEntity_t *a, WorldEntity_t *b,
        GLMFloat aRestAngle, GLMFloat aStiffness, GLMFloat aDamping)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_DampedRotarySpring;
    ret->cpConstraint = cpDampedRotarySpringNew(a->cpBody, b->cpBody, aRestAngle, aStiffness, aDamping);
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #7
0
WorldConstraint_t *worldConstr_createDampedSpringJoint(WorldEntity_t *a, WorldEntity_t *b, vec2_t aAnchorA, vec2_t aAnchorB,
        GLMFloat aRestLength, GLMFloat aStiffness, GLMFloat aDamping)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_DampedSpring;
    ret->cpConstraint = cpDampedSpringNew(a->cpBody, b->cpBody, VEC2_TO_CPV(aAnchorA), VEC2_TO_CPV(aAnchorB), aRestLength, aStiffness, aDamping);
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #8
0
WorldConstraint_t *worldConstr_createSlideJoint(WorldEntity_t *a, WorldEntity_t *b, vec2_t aAnchorA, vec2_t aAnchorB,
        GLMFloat aMinDist, GLMFloat aMaxDist)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_Slide;
    ret->cpConstraint = cpSlideJointNew(a->cpBody, b->cpBody, VEC2_TO_CPV(aAnchorA), VEC2_TO_CPV(aAnchorB), aMinDist, aMaxDist);
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #9
0
WorldConstraint_t *worldConstr_createGrooveJoint(WorldEntity_t *a, WorldEntity_t *b, vec2_t aGrooveStart, vec2_t aGrooveEnd,
        vec2_t aAnchorB)
{
    dynamo_assert(a->world == b->world, "Entities are not in the same world");
    WorldConstraint_t *ret = obj_create_autoreleased(&Class_WorldConstraint);
    ret->world = a->world;
    ret->a = obj_retain(a);
    ret->b = obj_retain(b);
    ret->type = kWorldJointType_Groove;
    ret->cpConstraint = cpGrooveJointNew(a->cpBody, b->cpBody, VEC2_TO_CPV(aGrooveStart), VEC2_TO_CPV(aGrooveEnd),
                                         VEC2_TO_CPV(aAnchorB));
    cpSpaceAddConstraint(ret->world->cpSpace, ret->cpConstraint);
    return ret;
}
Example #10
0
LuaContext_t *luaCtx_createContext()
{
    LuaContext_t *out = obj_create_autoreleased(&Class_LuaContext);
    
    if(!GlobalLuaContext)
        GlobalLuaContext = obj_retain(out);
    
    out->luaState = lua_open();
    luaL_openlibs(out->luaState);
    
    lua_pushcfunction(out->luaState, &luaApi_dynamo_registerCallback);
    lua_setglobal(out->luaState, "dynamo_registerCallback");
    lua_pushcfunction(out->luaState, &luaApi_dynamo_unregisterCallback);
    lua_setglobal(out->luaState, "dynamo_unregisterCallback");
    
    char buf[1024];
    dynamo_assert(util_pathForResource(NULL, NULL, "DynamoScripts", buf, 1024), "Couldn't find dynamo scripts");
    luaCtx_addSearchPath(out, buf);
    
    dynamo_assert(util_pathForResource("glmath", "lua", "DynamoScripts", buf, 1024), "Couldn't find glmath init script");
    dynamo_assert(luaCtx_executeFile(out, buf), "Error initializing GLMath");
    dynamo_assert(util_pathForResource("dynamo", "lua", "DynamoScripts", buf, 1024), "Couldn't find dynamo init script");
    dynamo_assert(luaCtx_executeFile(out, buf), "Error initializing dynamo");
    
    return out;
}
Example #11
0
SpriteBatch_t *spriteBatch_create(TextureAtlas_t *aAtlas)
{
    SpriteBatch_t *out = obj_create_autoreleased(&Class_SpriteBatch);
    out->spriteCount = 0;
    out->sprites = obj_retain(llist_create((InsertionCallback_t)&obj_retain, (RemovalCallback_t)&obj_release));
    out->displayCallback = (RenderableDisplayCallback_t)&_spriteBatch_draw;
	return out;
}
Example #12
0
Obj_t *obj_create(Class_t *aClass)
{
    dynamo_assert(aClass != NULL, "Invalid class");

    _Obj_guts *self = calloc(1, aClass->instanceSize);
    self->isa = aClass;
    return obj_retain(self);
}
Example #13
0
extern bool texture_loadPackingInfo(Texture_t *aTexture, const char *aPath)
{
    char *jsonInput;
    util_readFile(aPath, NULL, &jsonInput);
    dynamo_assert(jsonInput != NULL, "No file at %s", aPath);
    Dictionary_t *info = parseJSON(jsonInput);
    free(jsonInput);
    dynamo_assert(info != NULL && dict_get(info, "frames") != NULL, "Could not load texture packing info from %s", aPath);
    
    aTexture->subtextures = obj_retain(dict_get(info, "frames"));
    
    return true;
}
Example #14
0
Sprite_t *sprite_create(vec3_t aLocation, vec2_t aSize, TextureAtlas_t *aAtlas, int aAnimationCapacity)
{
	Sprite_t *out = (Sprite_t*)obj_create_autoreleased(&Class_Sprite);
	out->displayCallback = (RenderableDisplayCallback_t)&_sprite_draw;
	out->location = aLocation;
	out->size = aSize;
	out->scale = 1.0f;
	out->angle = 0.0f;
	out->atlas = obj_retain(aAtlas);
	out->flippedHorizontally = false;
	out->flippedVertically = false;
	out->activeAnimation = 0;
	out->animations = calloc(aAnimationCapacity, sizeof(SpriteAnimation_t));

	return out;
}
Example #15
0
WorldEntity_t *worldEnt_create(World_t *aWorld, Obj_t *aOwner, GLMFloat aMass, GLMFloat amoment)
{
    WorldEntity_t *out = obj_create_autoreleased(&Class_WorldEntity);
    out->world  = aWorld;
    out->owner  = aOwner;
    out->cpBody = cpBodyNew(aMass, amoment);
    out->cpBody->data = out;

    out->shapes = obj_retain(llist_create((InsertionCallback_t)&obj_retain, &obj_release));

    out->luaUpdateHandler = -1;
    out->luaPreCollisionHandler = -1;
    out->luaCollisionHandler = -1;
    out->luaPostCollisionHandler = -1;

    return out;
}
Example #16
0
void _obj_retain(Obj_t *aObj, void *ignored) { obj_retain(aObj); }