/* =========================================================================== * Free the window and hash table */ void lm_free(void) { #ifdef DYN_ALLOC if (window != NULL) { fcfree(window); window = NULL; } if (prev != NULL) { fcfree(prev); fcfree(head); prev = head = NULL; } #endif /* DYN_ALLOC */ }
void killtexture(void) { if (!OEMtexture) return; // OEMtexture not defined ... we haven't yet been initialized deletealltextures(); // killbucket(Texture, flags, texture_memstruct); { Texture *tmpTexture, *nextTexture; while (usedTexture) { tmpTexture = usedTexture; deletebucket(Texture, tmpTexture) } tmpTexture = freeTexture; while (tmpTexture) { nextTexture = tmpTexture->next; if (tmpTexture->flags & Generic_MemoryFlag32) { tmpTexture->next = usedTexture; usedTexture = tmpTexture; } tmpTexture = nextTexture; } tmpTexture = usedTexture; while (tmpTexture) { nextTexture = tmpTexture->next; fcfree(tmpTexture); tmpTexture = nextTexture; } } texturelog->log("Estimated Texture memory used = %i Megs",estimatedtexmemused / (1024*1024)); delete texturelog; delete OEMtexture; }
netclient::~netclient(void) { if ((connectionerror & 0x80000000) == 0) { netclientoem *oem = (netclientoem *)oemdata; closesocket(oem->conn_socket); } fcfree(oemdata); }
Texture *newNormalizeCubeMap(int size, float intensity, const char *name) { // Create a new Normalizing Cube Map (commonly used in Normal Mapping) // Size = Number of pixels in width, height, and depth // Intensity = Intensity of lighting. Ranges from 0 (very little lighting) to 1 (heavy specular effect) // Name = the name you want to call this texture (optional) Texture *tex = newTexture("Unnamed Cubemap", size, texture_cubemap | texture_manualmip); if (name) txtcpy(tex->name,maxtexnamesize,name); float vector[3] = {0,0,0}; intf side, x, y, mip; byte *pixels; intensity *= 127; bitmap *bm = newbitmap("Normalize CubeMap", size, size,bitmap_RGB_32bit); pixels = (byte *)bm->pixel; mip = 0; while (size>0) { float oofsize = 1.0f / (float)size; bm->width = size; bm->height = size; for (side = 0; side < 6; side++) { for (y = 0; y < size; y++) { for (x = 0; x < size; x++) { float s, t, sc, tc, mag; s = ((float)x + 0.5f) * oofsize; // / (float)size; t = ((float)y + 0.5f) * oofsize; // / (float)size; sc = s*2.0f - 1.0f; tc = t*2.0f - 1.0f; switch (side) { case 0: vector[0] = 1.0; vector[1] = -tc; vector[2] = -sc; break; case 1: vector[0] = -1.0; vector[1] = -tc; vector[2] = sc; break; case 2: vector[0] = sc; vector[1] = 1.0; vector[2] = tc; break; case 3: vector[0] = sc; vector[1] = -1.0; vector[2] = -tc; break; case 4: vector[0] = sc; vector[1] = -tc; vector[2] = 1.0; break; case 5: vector[0] = -sc; vector[1] = -tc; vector[2] = -1.0; break; } // switch size mag = 1.0f/(float)sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]); vector[0] *= mag; vector[1] *= mag; vector[2] *= mag; float alpha = intensity * vector[2] * 2; if (alpha<0) alpha = 0; pixels[4*(y*size+x) + 0] = (byte)alpha;//(128 + (byte)(intensity*vector[2])); // A (A taken from Z) pixels[4*(y*size+x) + 1] = (128 + (byte)(intensity*vector[0])); // R pixels[4*(y*size+x) + 2] = (128 + (byte)(intensity*vector[1])); // G pixels[4*(y*size+x) + 3] = (128 + (byte)(intensity*vector[2])); // B } // for X } // for Y downloadcubemapface(tex, side, bm, mip); } // for side size >>= 1; mip++; } tex->mapping = texmapping_default | texmapping_clampUV; fcfree(bm); return tex; }
cMatrixStack::~cMatrixStack(void) { if (flags) fcfree(level); }