Hi. Because of the lack of java support on my GP2X, I'm now attempting to learn C++.
But it isn't going so great. C++'s complicated syntax is spanking me with compiler errors. :lol: I can see why there's courses for this language. It's not something you just start typing, and it works.
Anyway, I'm a noob when it comes to compiled languages. I have no idea what needs to be fixed. I figured since in C there's no garbage collector, it'd be a good idea to have a big list of all the surfaces loaded into memory, so I can keep track of them, and delete them through that object. Good concept anyway, right?
So I figured....arr[16] of pointers that points to arr[64] of pointers to surfaces. That combo allows up to 1024 surfaces, which is more than I could possibly use, while also keeping memory usage to ~(16*4 + n*64*4 + overhead) bytes.
Unfortunately, that concept maps very poorly into actual code, since my brain and fingers don't know how to get it working.
So anyways...Java:
CODE
public class imageCache
{
public int MaxChunks = 16;
public int ChunkSize = 64;
public int maxSize = MaxChunks*ChunkSize;
public int Count = 0;
public Chunk[] Chunks = new Chunk[MaxChunks];
final public boolean outOfBounds(int iNum)
{
return (iNum < 0 || iNum >= maxSize);
}
final public SDL_Surface get(int iOffset)
{
if(outOfBounds(iOffset)) return null;
int iChunk = iOffset >> 6;
int iIndex = iOffset & 63;
if(Chunks[iChunk] == null) return null;
return Chunks[iChunk].Arr[iIndex]; // May be null
}
final public int add(SDL_Surface mySurf)
{
if(Count >= maxSize) return -1;
int iChunk = Count >> 6;
int iIndex = Count & 63;
if(Chunks[iChunk] == null) Chunks[iChunk] = new Chunk(ChunkSize);
Chunks[iChunk].Arr[iIndex] = mySurf;
iIndex = Count;
Count++;
return iIndex; // Return Index/Offset
}
private class Chunk
{
public SDL_Surface Arr[];
Chunk(int iSize)
{
Arr = new SDL_Surface[iSize];
}
}
}
If anyone has the time to convert that, I'd be grateful.
-Kramy
But it isn't going so great. C++'s complicated syntax is spanking me with compiler errors. :lol: I can see why there's courses for this language. It's not something you just start typing, and it works.
Anyway, I'm a noob when it comes to compiled languages. I have no idea what needs to be fixed. I figured since in C there's no garbage collector, it'd be a good idea to have a big list of all the surfaces loaded into memory, so I can keep track of them, and delete them through that object. Good concept anyway, right?
So I figured....arr[16] of pointers that points to arr[64] of pointers to surfaces. That combo allows up to 1024 surfaces, which is more than I could possibly use, while also keeping memory usage to ~(16*4 + n*64*4 + overhead) bytes.
Unfortunately, that concept maps very poorly into actual code, since my brain and fingers don't know how to get it working.
So anyways...Java:
CODE
public class imageCache
{
public int MaxChunks = 16;
public int ChunkSize = 64;
public int maxSize = MaxChunks*ChunkSize;
public int Count = 0;
public Chunk[] Chunks = new Chunk[MaxChunks];
final public boolean outOfBounds(int iNum)
{
return (iNum < 0 || iNum >= maxSize);
}
final public SDL_Surface get(int iOffset)
{
if(outOfBounds(iOffset)) return null;
int iChunk = iOffset >> 6;
int iIndex = iOffset & 63;
if(Chunks[iChunk] == null) return null;
return Chunks[iChunk].Arr[iIndex]; // May be null
}
final public int add(SDL_Surface mySurf)
{
if(Count >= maxSize) return -1;
int iChunk = Count >> 6;
int iIndex = Count & 63;
if(Chunks[iChunk] == null) Chunks[iChunk] = new Chunk(ChunkSize);
Chunks[iChunk].Arr[iIndex] = mySurf;
iIndex = Count;
Count++;
return iIndex; // Return Index/Offset
}
private class Chunk
{
public SDL_Surface Arr[];
Chunk(int iSize)
{
Arr = new SDL_Surface[iSize];
}
}
}
If anyone has the time to convert that, I'd be grateful.
-Kramy