Esempio n. 1
0
static BOOL _invariant(Drawable* self)
{
    smug_assert(self != NULL);
    smug_assert(self->mShape != NULL);
    smug_assert(Shape_getType(self->mShape) == SHAPE_RECTANGLE);
    return (self != NULL && self->mShape != NULL && Shape_getType(self->mShape) == SHAPE_RECTANGLE);
}
Esempio n. 2
0
void RenderBatch_addTexturedRect(RenderBatch* self,
                                 float x1, float y1, float x2, float y2,
                                 float z,
                                 float s1, float t1, float s2, float t2)
{
    smug_assert(_usesTexture(self));
    _expandArraysIfNeeded(self, 4);
    int start = self->addedElements * PRIMITIVES_PER_VERTEX;
    self->vertexArray[start++] = x1;
    self->vertexArray[start++] = y1;
    self->vertexArray[start++] = z;
    self->vertexArray[start++] = x1;
    self->vertexArray[start++] = y2;
    self->vertexArray[start++] = z;
    self->vertexArray[start++] = x2;
    self->vertexArray[start++] = y2;
    self->vertexArray[start++] = z;
    self->vertexArray[start++] = x2;
    self->vertexArray[start++] = y1;
    self->vertexArray[start++] = z;
    smug_assert(start == (self->addedElements + 4) * PRIMITIVES_PER_VERTEX);

    start = self->addedElements * PRIMITIVES_PER_TEXTURE_COORDINATE;
    self->textureArray[start++] = s1;
    self->textureArray[start++] = t1;
    self->textureArray[start++] = s1;
    self->textureArray[start++] = t2;
    self->textureArray[start++] = s2;
    self->textureArray[start++] = t2;
    self->textureArray[start++] = s2;
    self->textureArray[start++] = t1;
    smug_assert(start == (self->addedElements + 4) * PRIMITIVES_PER_TEXTURE_COORDINATE);
    self->addedElements += 4;
}
Esempio n. 3
0
void RenderBatch_addColoredRect(RenderBatch* self,
                                float x1, float y1, float x2, float y2,
                                float z,
                                float r, float g, float b, float a)
{
    smug_assert(!_usesTexture(self));
    _expandArraysIfNeeded(self, 4);
    int start = self->addedElements * PRIMITIVES_PER_VERTEX;
    self->vertexArray[start++] = x1;
    self->vertexArray[start++] = y1;
    self->vertexArray[start++] = z;
    self->vertexArray[start++] = x1;
    self->vertexArray[start++] = y2;
    self->vertexArray[start++] = z;
    self->vertexArray[start++] = x2;
    self->vertexArray[start++] = y2;
    self->vertexArray[start++] = z;
    self->vertexArray[start++] = x2;
    self->vertexArray[start++] = y1;
    self->vertexArray[start++] = z;
    smug_assert(start == (self->addedElements + 4) * PRIMITIVES_PER_VERTEX);

    start = self->addedElements * PRIMITIVES_PER_COLOR;
    int offset;
    for (offset = start; offset < start + 4 * PRIMITIVES_PER_COLOR;)
    {
        self->colorArray[offset++] = r;
        self->colorArray[offset++] = g;
        self->colorArray[offset++] = b;
        self->colorArray[offset++] = a;
    }
    smug_assert(offset == (self->addedElements + 4) * PRIMITIVES_PER_COLOR);
    self->addedElements += 4;
}
Esempio n. 4
0
unsigned int Drawable_getTextureID(Drawable* self)
{
    smug_assert(self != NULL);
    if (self->mSprite == NULL)
    {
        return 0;
    }
    smug_assert(self->mSprite != NULL);
    return Sprite_getTextureId(self->mSprite);
}
Esempio n. 5
0
void BinaryTree_removeAll(BinaryTree* self)
{
    smug_assert(_invariant(self));
    if (!BinaryTree_isEmpty(self))
    {
        _deleteWithChildren(self->root);
        self->root = NULL;
        smug_assert(_invariant(self));
    }
}
Esempio n. 6
0
void BinaryTree_deleteAll(BinaryTree* self, void (*deleter)(void* item))
{
    smug_assert(_invariant(self));
    if (!BinaryTree_isEmpty(self))
    {
        _deleteContentsWithChildren(self->root, deleter);
        self->root = NULL;
        smug_assert(_invariant(self));
    }
}
Esempio n. 7
0
void RenderBatch_addDrawable(RenderBatch* batch, Drawable* drawable)
{
    smug_assert(NULL != batch);
    smug_assert(NULL != drawable);
    smug_assert(Drawable_getTexture(drawable) == batch->texture);
    smug_assert(Drawable_getDataSize(drawable) == batch->objectSize);

    // Add drawable to list
    LinkedList_addLast(batch->drawables, drawable);
}
Esempio n. 8
0
Texture* Drawable_getTexture(Drawable* self)
{
    smug_assert(self != NULL);
    if (self->mSprite == NULL)
    {
        return NULL;
    }
    smug_assert(self->mSprite != NULL);
    return Sprite_getTexture(self->mSprite);
}
Esempio n. 9
0
BinaryTree* BinaryTree_new(int (*compare)(void*, void*))
{
    smug_assert(compare != NULL);
    BinaryTree* newTree = allocate(BinaryTree);
    newTree->root = NULL;
    newTree->compare = compare;
    newTree->comparePredicated = NULL;
    newTree->predicateData = NULL;
    smug_assert(_invariant(newTree));
    return newTree;
}
Esempio n. 10
0
BinaryTree* BinaryTree_newPredicated(int (*comparePredicated)(void*, void*, void*), void* predicateData)
{
    smug_assert(comparePredicated != NULL);
    BinaryTree* newTree = allocate(BinaryTree);
    newTree->root = NULL;
    newTree->compare = NULL;
    newTree->comparePredicated = comparePredicated;
    newTree->predicateData = predicateData;
    smug_assert(_invariant(newTree));
    return newTree;
}
Esempio n. 11
0
void RenderQueue_addDrawable(RenderQueue* self, Drawable* drawable, float positionX, float positionY)
{
    smug_assert(_invariant(self));
    Sprite* sprite = Drawable_getSprite(drawable);
    smug_assert(sprite != NULL);
    int id = Sprite_getTextureId(sprite);
    RenderBatch* renderBatch = (RenderBatch*)Map_get(self->renderBatches, &id);
    if (renderBatch == NULL)
    {
        renderBatch = RenderBatch_new(RENDERBATCH_INITIAL_SIZE, TRUE);
        Map_set(self->renderBatches, _allocInt(id), renderBatch);
    }
    Drawable_addRenderData(drawable, renderBatch, positionX, positionY);
}
Esempio n. 12
0
RenderQueue* RenderQueue_new()
{
    RenderQueue* newRenderQueue = allocate(RenderQueue);
    newRenderQueue->renderBatches = Map_new(Map_compareInts);
    smug_assert(_invariant(newRenderQueue));
    return newRenderQueue;
}
Esempio n. 13
0
int File_fseek(File* self, long int offset, int origin)
{
    smug_assert(self != NULL);
    switch (origin)
    {
        case SMUG_SEEK_SET:
            return fseek(self->mFile, offset, SEEK_SET);
        case SMUG_SEEK_CUR:
            return fseek(self->mFile, offset, SEEK_CUR);
        case SMUG_SEEK_END:
            return fseek(self->mFile, offset, SEEK_END);
        default:
            smug_assert(!"Invalid offset parameter to File_fseek!");
            return 1;
    }
}
Esempio n. 14
0
void RenderQueue_delete(RenderQueue* self)
{
    smug_assert(_invariant(self));
    Map_doForEach(self->renderBatches, _deleteRenderBatchInMap);
    Map_delete(self->renderBatches);
    free(self);
}
Esempio n. 15
0
void* BinaryTree_find(BinaryTree* self, void* item)
{
    smug_assert(_invariant(self));
    BinaryTreeNode* node;
    _findNode(self, item, &node);
    return node == NULL ? NULL : node->item;
}
Esempio n. 16
0
void Drawable_scaleY(Drawable* self, float scale)
{
    smug_assert(_invariant(self));
    if (self->mShape != NULL)
    {
        Shape_scaleY(self->mShape, scale);
    }
}
Esempio n. 17
0
void Drawable_scaleXY(Drawable* self, Vector scales)
{
    smug_assert(_invariant(self));
    if (self->mShape != NULL)
    {
        Shape_scaleXY(self->mShape, scales);
    }
}
Esempio n. 18
0
long int File_getLength(File* self)
{
    smug_assert(self != NULL);
    long int oldPos = File_ftell(self);
	File_fseek(self, 0, SMUG_SEEK_END);
	long int len = File_ftell(self);
	File_fseek(self, oldPos, SMUG_SEEK_SET);
    return len;
}
Esempio n. 19
0
void* LinkedListIterator_getSame(LinkedListIterator* self)
{
    smug_assert(self != NULL);
    if (self->mCurrent != NULL)
    {
        return self->mCurrent->item;
    }
    return NULL;
}
Esempio n. 20
0
BOOL PositionedObject_getPosForDrawing(GameObject* self, Point* p)
{
    if (GameObject_isType(self, SMUG_TYPE_POSITIONED))
    {
        Point myPos = Interpoint_getInterpolated(((PositionedObject*)self)->mPosition);
        if (GameObject_isRootObject(self) || ((PositionedObject*)self)->mPositionInheritance == SMUG_POSITION_KEEP)
        {
            *p = myPos;
            return TRUE;
        }
        else
        {
            Point pp = Point_createFromXY(0, 0);
            PositionedObject_getPosForDrawing(GameObject_getParent(self), &pp);
            if (((PositionedObject*)self)->mPositionInheritance == SMUG_POSITION_INHERIT)
            {
                *p = pp;
                return TRUE;
            }
            else
            {
                smug_assert(((PositionedObject*)self)->mPositionInheritance == SMUG_POSITION_RELATIVE);
                *p = Point_add(myPos, pp);
                return TRUE;
            }
        }
    }
    else
    {
        if (GameObject_isRootObject(self))
        {
            return FALSE;
        }
        else
        {
            return PositionedObject_getPosForDrawing(GameObject_getParent(self), p);
        }
    }
/*     if (self->mPositionInheritance == SMUG_POSITION_RELATIVE
        && !GameObject_isRootObject((GameObject*)self)
        && GameObject_isType(GameObject_getParent((GameObject*)self), SMUG_TYPE_POSITIONED))
    {
        Point pp;
        PositionedObject_getPosForDrawing((PositionedObject*)GameObject_getParent((GameObject*)self), &pp);
        Point p1 = Interpoint_getInterpolated(self->mPosition);
        // smug_printf("Object %i has pos (%i) %f, %f relative to %f, %f", self, data->mPosition, Point_getX(p1), Point_getY(p1), Point_getX(pp), Point_getY(pp));
        *p = Point_add(p1, pp);
    }
    else
    {
        *p = Interpoint_getInterpolated(self->mPosition);
        // smug_printf("Object %i has pos %f, %f", self, Point_getX(*p), Point_getY(*p));
    }
    return TRUE; */
}
Esempio n. 21
0
void BinaryTree_insert(BinaryTree* self, void* item)
{
    smug_assert(_invariant(self));
    if (BinaryTree_isEmpty(self))
    {
        self->root = BinaryTreeNode_new(item);
        smug_assert(_invariant(self));
        return;
    }
    BinaryTreeNode* current = self->root;
    int comp;
    while (TRUE)
    {
        comp = _compare(self, item, current->item);
        if (comp == 0)
        {
            return;
        }
        if (comp < 0)
        {
            if (current->left == NULL)
            {
                current->left = BinaryTreeNode_new(item);
                current->left->parent = current;
                smug_assert(_invariant(self));
                return;
            }
            current = current->left;
        }
        if (comp > 0)
        {
            if (current->right == NULL)
            {
                current->right = BinaryTreeNode_new(item);
                current->right->parent = current;
                smug_assert(_invariant(self));
                return;
            }
            current = current->right;
        }
    }
}
Esempio n. 22
0
void PathName_addBase(PathName* self, PathName* base)
{
    smug_assert(_invariant(self));
    smug_assert(_invariant(base));
    smug_assert(PathName_isRelative(self));

    smug_assert(_invariant(self));
    smug_assert(_invariant(base));

    LinkedList* basePath;

    if (base->root)
    {
        self->root = String_newCopy(base->root);
    }

    basePath = LinkedList_deepCopy(base->path, String_newCopyVoid);
    LinkedList_concat(basePath, self->path);
    self->path = basePath;
}
Esempio n. 23
0
/** Requires OpenGL to be initialized, and GL_VERTEX_ARRAY and
 *  GL_TEXTURE_COORD_ARRAY to be enabled.
 */
void RenderQueue_render(RenderQueue* self)
{
    smug_assert(_invariant(self));
    MapIterator* iter = Map_getIterator(self->renderBatches);
    MapPair* pair = MapIterator_getNextPair(iter);
    while (pair != NULL)
    {
        glBindTexture(GL_TEXTURE_2D, *(int*)pair->key);
        RenderBatch_render((RenderBatch*)pair->value);
        pair = MapIterator_getNextPair(iter);
    }
    MapIterator_delete(iter);
}
Esempio n. 24
0
unsigned char* File_getBuffer(File* self)
{
    smug_assert(self != NULL);
    long int length = File_getLength(self);
	unsigned char* buffer = (unsigned char*)malloc(length);
	if (File_fread(self, buffer, 1, length) != length)
	{
		ERROR("Did not read correct amount of bytes.");
		free(buffer);
        return NULL;
	}
    return buffer;
}
Esempio n. 25
0
Drawable* Drawable_newBoxFromSize(Vector size)
{
    Drawable* newObj = (Drawable*)malloc(sizeof(_Drawable));
    Drawable_init(newObj);
    newObj->_writeBatchDataFunc = writeBatchData;
    newObj->_getDataSizeFunc = getDataSize;
    newObj->mShape = Shape_newFromRectangle(Rectangle_createFromXYWH(0, 0, Vector_getX(&size), Vector_getY(&size)));
    smug_assert(_invariant(newObj));
    return newObj;
/*    smug_assert(GameObject_isExactType(newObj, SMUG_TYPE_SHAPE));
    smug_assert(GameObject_isType(newObj, SMUG_TYPE_SHAPE));
    smug_assert(GameObject_isType(newObj, SMUG_TYPE_DRAWABLE));
    smug_assert(GameObject_isType(newObj, SMUG_TYPE_POSITION));
    smug_assert(GameObject_isType(newObj, SMUG_TYPE_OBJECT)); */
}
Esempio n. 26
0
PathName* PathName_newCopy(PathName* self)
{
    PathName* newPn;

    smug_assert(_invariant(self));

    newPn = (PathName*)malloc(sizeof(PathName));
    if (self->root)
    {
        newPn->root = String_newCopy(self->root);
    }
    if (self->bareName)
    {
        newPn->bareName = String_newCopy(self->bareName);
        if (self->extension)
        {
            newPn->extension = String_newCopy(self->extension);
        }
    }
    newPn->path = LinkedList_deepCopy(self->path, String_newCopyVoid);

    smug_assert(_invariant(newPn));
    return newPn;
}
Esempio n. 27
0
BinaryTreeIterator* BinaryTree_getIterator(BinaryTree* self)
{
    smug_assert(_invariant(self));
    BinaryTreeIterator* newIter = allocate(BinaryTreeIterator);
    newIter->current = self->root;
    if (self->root == NULL)
    {
        return newIter;
    }
    while (newIter->current->left != NULL)
    {
        newIter->current = newIter->current->left;
    }
    return newIter;
}
Esempio n. 28
0
void RenderBatch_delete(void* batch)
{
    smug_assert(NULL != batch);

    RenderBatch* thebatch = (RenderBatch*)batch;
    BatchData_delete(thebatch->data);

    freeBuffer(&thebatch->vertexBufferIndex);
    freeBuffer(&thebatch->colorBufferIndex);
    freeBuffer(&thebatch->textureBufferIndex);

    // Delete only list, don't touch drawables
    LinkedList_delete(thebatch->drawables);

    free(thebatch);
}
Esempio n. 29
0
static int _isLeftOrRightChild(BinaryTreeNode* node)
{
    if (node->parent == NULL)
    {
        return 0;
    }
    if (node->parent->left == node)
    {
        return -1;
    }
    if (node->parent->right == node)
    {
        return 1;
    }
    smug_assert(FALSE);
    return 0;
}
Esempio n. 30
0
String* PathName_getAsString(PathName* self)
{
    smug_assert(_invariant(self));
    String* path;
    String* fullPath;

    path = String_newJoin(self->path, _getSeparator());
    if (self->root != NULL)
    {
        fullPath = String_newConcat(self->root, path);
        String_delete(path);
    }
    else
    {
        fullPath = path;
    }
    return fullPath;
}