Well, I am back to work on my game.
Xterria is probably shouting in his seat, "FINALLY! GET TO WORK!"
anyways, I have encountered something that I could fix...but the only way I know how to fix it would be significantly slow...and I know there must be a faster way to do this...
Here is my problem:
Take blitting for example. I am using SDL by the way. Using blitting we can easily do a quick copy of one surface or even just a part of one surface to another surface or the screen. For example we could outline a rectangle using SDL_Rect and blit that specific part of a surface to another surface or the screen. Blitting is incredibly fast, and as far as I know I think it is just a quick memcpy(), right?
Well, my problem isnt with blitting, but it is similar to blitting.
I have 2 matrixes. Both matrixes only contain boolean values. Also, one is larger than the other.
The first matrix is a "bit matrix" of the entire map in my game. A 1 represents an obstacle, a 0 represents a clear path. For collision detection purposes, I only need a very small piece of this map's bit matrix at any one point in time.
I copy the part I need from the map's bit matrix into a smaller bit matrix which is then used for collision detection.
The problem I am having is when I copy part of the larger matrix to the smaller matrix being used for collision detection. I am using a slow nested loop (with a Big-O value of N^2) to move through every element in the section of the matrix that I need and copy it to the second matrix. That is slow.
Is there any way you can outline a specific rectangle of a matrix (or array even), almost like in blitting, and do a fast memcpy to another matrix (or array). It is like blitting. I dont want to "blit" the entire matrix to the other matrix. I just want to outline a rectangle of the matrix that I want to "blit", and then "blit" it to the other matrix, per se.
If this can be done with surfaces, surely it can be done with matrixes or arrays?
I do see possible obstacles in doing this with matrixes, but it should be able to be done with at least arrays, right?
Anybody have ideas?