Remove zero special casing from named array
This commit is contained in:
parent
31ed419dfa
commit
b0c9ac7207
|
@ -136,6 +136,9 @@ static GLuint _glGetMipmapDataSize(TextureObject* obj) {
|
|||
GLubyte _glKosInitTextures() {
|
||||
named_array_init(&TEXTURE_OBJECTS, sizeof(TextureObject), MAX_TEXTURE_COUNT);
|
||||
|
||||
// Reserve zero so that it is never given to anyone as an ID!
|
||||
named_array_reserve(&TEXTURE_OBJECTS, 0);
|
||||
|
||||
SHARED_PALETTE = (TexturePalette*) malloc(sizeof(TexturePalette));
|
||||
return 1;
|
||||
}
|
||||
|
@ -191,6 +194,9 @@ void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
|
|||
while(n--) {
|
||||
GLuint id = 0;
|
||||
TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id);
|
||||
|
||||
assert(id); // Generated IDs must never be zero
|
||||
|
||||
_glInitializeTextureObject(txr, id);
|
||||
|
||||
*textures = id;
|
||||
|
|
|
@ -31,8 +31,6 @@ void named_array_init(NamedArray* array, unsigned int element_size, unsigned int
|
|||
}
|
||||
|
||||
char named_array_used(NamedArray* array, unsigned int id) {
|
||||
id--;
|
||||
|
||||
unsigned int i = id / 8;
|
||||
unsigned int j = id % 8;
|
||||
|
||||
|
@ -44,11 +42,11 @@ void* named_array_alloc(NamedArray* array, unsigned int* new_id) {
|
|||
unsigned int i = 0, j = 0;
|
||||
for(i = 0; i < array->marker_count; ++i) {
|
||||
for(j = 0; j < 8; ++j) {
|
||||
unsigned int id = (i * 8) + j + 1;
|
||||
unsigned int id = (i * 8) + j;
|
||||
if(!named_array_used(array, id)) {
|
||||
array->used_markers[i] |= (unsigned char) 1 << j;
|
||||
*new_id = id;
|
||||
unsigned char* ptr = &array->elements[(id - 1) * array->element_size];
|
||||
unsigned char* ptr = &array->elements[id * array->element_size];
|
||||
memset(ptr, 0, array->element_size);
|
||||
return ptr;
|
||||
}
|
||||
|
@ -60,14 +58,14 @@ void* named_array_alloc(NamedArray* array, unsigned int* new_id) {
|
|||
|
||||
void* named_array_reserve(NamedArray* array, unsigned int id) {
|
||||
if(!named_array_used(array, id)) {
|
||||
unsigned int j = (id % 8) - 1;
|
||||
unsigned int j = (id % 8);
|
||||
unsigned int i = id / 8;
|
||||
|
||||
assert(!named_array_used(array, id));
|
||||
array->used_markers[i] |= (unsigned char) 1 << j;
|
||||
assert(named_array_used(array, id));
|
||||
|
||||
unsigned char* ptr = &array->elements[(id - 1) * array->element_size];
|
||||
unsigned char* ptr = &array->elements[id * array->element_size];
|
||||
memset(ptr, 0, array->element_size);
|
||||
return ptr;
|
||||
}
|
||||
|
@ -76,8 +74,6 @@ void* named_array_reserve(NamedArray* array, unsigned int id) {
|
|||
}
|
||||
|
||||
void named_array_release(NamedArray* array, unsigned int new_id) {
|
||||
new_id--;
|
||||
|
||||
unsigned int i = new_id / 8;
|
||||
unsigned int j = new_id % 8;
|
||||
|
||||
|
@ -93,7 +89,7 @@ void* named_array_get(NamedArray* array, unsigned int id) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return &array->elements[(id - 1) * array->element_size];
|
||||
return &array->elements[id * array->element_size];
|
||||
}
|
||||
|
||||
void named_array_cleanup(NamedArray* array) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user