The objects in my game are put inside of an NSMutableArray called "gameObjectArray." Each time it renders, it cycles through each object in the array, pulls out each vertex information, and inserts it into an array called vertexArray of type HOSpriteVertex (which is just a structure holding vertex and color structures).
So to add to the array, simply add objects into the mutable array and this will insert their vertex information to OpenGL ES to render.
Problem is, I'm not getting the performance I was hoping for, and I believe it has to do with how I'm using calloc() and free() each rendering method. Is this correct at all? How SHOULD it look? Any thing you see here I should avoid?
Yeah, calloc zero initialises the memory (ick), no need to be using that. You shouldn't be re-allocated memory like that every frame, either. Much better to alloc all you need and be done, but I doubt that's your time sink either way.
What's all that HOSpriteVertexMake stuff doing? Why are you calling that colour making function so often?
__________________
Visit Mr Jack Games for my blog and more about my games
Oh, alright. I'll try to malloc a large array at the beginning and just feed into that one. Butttttttt the HOSpriteVertex is a structure containing vertex and color structures. These are assigned to each vertex of the HOGameObject, and take on the properties of the HOGameObject.
So each object has 4 vertexes, that's why I'm creating them each run-through and feeding them into the array. I'm making the color each time and creating a structure to put into the interleaved array. Would it be less expensive to create the structures in the UPDATE method and reference to them during the DRAW method? Is creating structures too taxing for that?
So each object has 4 vertexes, that's why I'm creating them each run-through and feeding them into the array. I'm making the color each time and creating a structure to put into the interleaved array. Would it be less expensive to create the structures in the UPDATE method and reference to them during the DRAW method? Is creating structures too taxing for that?
Could you post the code for HOSpriteVertexMake, HOVertexMake and HOColorMake, please? And the definition for any structures they're using?
It looks like you're needlessly recreating an HOColor structure for each vertex when they're all the same then copying that structure into an HOSpriteVertex, and copying an HOVertex structure into the same. Then copying all that into the HOSpriteVertex afterwards. That's a load of unneeded copying.
__________________
Visit Mr Jack Games for my blog and more about my games
I'll show ya what I got, but I changed it first. I think it's better now. Basically the demo is this: You touch the screen, and a colored box appears. You can do this 100 times.
This is the init for the game object being created.
Code:
-(id)init{
if (self = [super init])
{
x = touchX;
y = touchY;
width = 32;
height = 32;
red = arc4random() %255;
green = arc4random() %255;
blue = arc4random() %255;
v1 = HOSpriteVertexMake(HOVertexMake(x, y), HOColorMake(red, green, blue, 255));
v2 = HOSpriteVertexMake(HOVertexMake(x + width, y), HOColorMake(red, green, blue, 255));
v3 = HOSpriteVertexMake(HOVertexMake(x, y + height), HOColorMake(red, green, blue, 255));
v4 = HOSpriteVertexMake(HOVertexMake(x + width, y + height), HOColorMake(red, green, blue, 255));
}
It is then passed into an NSMutableArray, which cycles through each object's draw method.