//Fills the buffer with the bitmap data. // Used by new mouse cursor draw routines. void StaticInfo::getData(unsigned char * buffer) { if ((vHeight > 32) || (uWidth > 32)) { memset(buffer,0,sizeof(DWORD) * 32 * 32); return; } unsigned long gosID = mcTextureManager->get_gosTextureHandle( textureHandle ); if (gosID) { TEXTUREPTR textureData; gos_LockTexture( gosID, 0, 0, &textureData ); DWORD *bufMem = (DWORD *)buffer; DWORD localU = location[0].u * textureData.Width; DWORD localV = location[0].v * textureData.Width; //Make sure we don't fall off of the texture! if ((localU > textureData.Width) || ((localU + uWidth) > textureData.Width) || (localV > textureData.Width) || ((localV + vHeight) > textureData.Width)) { memset(buffer,0,sizeof(DWORD) * 32 * 32); gos_UnLockTexture( gosID ); return; } for (long y=0;y<vHeight;y++) { DWORD *textureMemory = textureData.pTexture + (localU + ((localV+y) * textureData.Width)); for (long x=0;x<uWidth;x++) { *bufMem = *textureMemory; bufMem++; textureMemory++; } } gos_UnLockTexture( gosID ); } }
void aObject::setTexture(uint32_t newHandle) { // Gotta check handle. If its the same as the new one, // We don't gotta delete the old one. The texture manager already did!! if (textureHandle && textureHandle != newHandle) { int32_t gosID = mcTextureManager->get_gosTextureHandle(textureHandle); if (gosID > 0) mcTextureManager->removeTexture(gosID); } textureHandle = newHandle; if (newHandle) { int32_t gosID = mcTextureManager->get_gosTextureHandle(newHandle); TEXTUREPTR textureData; gos_LockTexture(gosID, 0, 0, &textureData); fileWidth = textureData.Width; gos_UnLockTexture(gosID); } }
void aObject::setTexture(PCSTR fileName) { if (textureHandle) { int32_t gosID = mcTextureManager->get_gosTextureHandle(textureHandle); if (gosID > 0) mcTextureManager->removeTexture(gosID); } textureHandle = mcTextureManager->loadTexture(fileName, gos_Texture_Keyed, 0, 0, 0x2); int32_t gosID = mcTextureManager->get_gosTextureHandle(textureHandle); if (gosID) { TEXTUREPTR textureData; gos_LockTexture(gosID, 0, 0, &textureData); fileWidth = textureData.Width; gos_UnLockTexture(gosID); } else fileWidth = 256; // guess }
void StaticInfo::init( FitIniFile& file, char* blockName, long hiResOffsetX, long hiResOffsetY, DWORD neverFlush ) { memset( location, 0, sizeof( location ) ); char fileName[256]; textureHandle = 0; textureWidth = 0; if ( NO_ERR != file.seekBlock( blockName ) ) { char errBuffer[256]; sprintf( errBuffer, "couldn't find static block %s", blockName ); Assert( 0, 0, errBuffer ); return; } long x, y, width, height; file.readIdLong( "XLocation", x ); file.readIdLong( "YLocation", y ); x += hiResOffsetX; y += hiResOffsetY; file.readIdLong( "Width", width ); file.readIdLong( "Height", height ); file.readIdString( "FileName", fileName, 32 ); if ( !textureHandle ) { FullPathFileName fullPath; _strlwr( fileName ); fullPath.init( artPath, fileName, ".tga" ); int ID = mcTextureManager->loadTexture( fullPath, gos_Texture_Alpha, 0, 0, 0x2 ); textureHandle = ID; unsigned long gosID = mcTextureManager->get_gosTextureHandle( ID ); TEXTUREPTR textureData; gos_LockTexture( gosID, 0, 0, &textureData ); textureWidth = textureData.Width; gos_UnLockTexture( gosID ); } bool bRotated = 0; file.readIdLong( "UNormal", u ); file.readIdLong( "VNormal", v ); file.readIdLong( "UWidth", uWidth ); file.readIdLong( "VHeight", vHeight ); file.readIdBoolean( "texturesRotated", bRotated ); for ( int k = 0; k < 4; k++ ) { location[k].argb = 0xffffffff; location[k].frgb = 0; location[k].x = x; location[k].y = y; location[k].z = 0.f; location[k].rhw = .5; location[k].u = (float)u/(float)textureWidth + (.1f / (float)textureWidth); location[k].v = (float)v/(float)textureWidth + (.1f / (float)textureWidth); } location[3].x = location[2].x = x + width; location[2].y = location[1].y = y + height; location[2].u = location[3].u = ((float)(u + uWidth))/((float)textureWidth) + (.1f / (float)textureWidth); location[1].v = location[2].v = ((float)(v + vHeight))/((float)textureWidth) + (.1f / (float)textureWidth); if ( bRotated ) { location[0].u = (u + uWidth)/(float)textureWidth + (.1f / (float)textureWidth);; location[1].u = u/(float)textureWidth + (.1f / (float)textureWidth);; location[2].u = u/(float)textureWidth + (.1f / (float)textureWidth); location[3].u = (u + uWidth)/(float)textureWidth + (.1f / (float)textureWidth); location[0].v = v/(float)textureWidth + (.1f / (float)textureWidth);; location[1].v = v/(float)textureWidth + (.1f / (float)textureWidth);; location[2].v = (v + vHeight)/(float)textureWidth + (.1f / (float)textureWidth);; location[3].v = (v + vHeight)/(float)textureWidth + (.1f / (float)textureWidth);; } }
void aObject::init(FitIniFile* file, PCSTR blockName, uint32_t neverFlush) { memset(location, 0, sizeof(location)); char fileName[256]; textureHandle = 0; fileWidth = 256.; if (NO_ERROR != file->seekBlock(blockName)) { char errBuffer[256]; sprintf(errBuffer, "couldn't find static block %s", blockName); Assert(0, 0, errBuffer); return; } int32_t x, y, width, height; file->readIdLong("XLocation", x); file->readIdLong("YLocation", y); file->readIdLong("Width", width); file->readIdLong("Height", height); file->readIdLong("HelpCaption", helpHeader); file->readIdLong("HelpDesc", helpID); if (NO_ERROR == file->readIdString("fileName", fileName, 32)) { bool bAlpha = 0; file->readIdBoolean("Alpha", bAlpha); if (!textureHandle) { char buffer[256]; strcpy(buffer, artPath); strcat(buffer, fileName); _strlwr(buffer); if (!strstr(buffer, ".tga")) strcat(buffer, ".tga"); int32_t ID = mcTextureManager->loadTexture( buffer, bAlpha ? gos_Texture_Alpha : gos_Texture_Keyed, 0, 0, 0x2); textureHandle = ID; uint32_t gosID = mcTextureManager->get_gosTextureHandle(ID); TEXTUREPTR textureData; gos_LockTexture(gosID, 0, 0, &textureData); fileWidth = textureData.Width; gos_UnLockTexture(gosID); } } int32_t u, v, uWidth, vHeight; bool bRotated = 0; file->readIdLong("UNormal", u); file->readIdLong("VNormal", v); file->readIdLong("UWidth", uWidth); file->readIdLong("VHeight", vHeight); file->readIdBoolean("texturesRotated", bRotated); for (size_t k = 0; k < 4; k++) { location[k].argb = 0xffffffff; location[k].frgb = 0; location[k].x = x; location[k].y = y; location[k].z = 0.f; location[k].rhw = .5; if (fileWidth) location[k].u = (float)u / (float)fileWidth + (.1f / (float)fileWidth); if (fileWidth) location[k].v = (float)v / (float)fileWidth + (.1f / (float)fileWidth); } location[3].x = location[2].x = x + width; location[2].y = location[1].y = y + height; if (fileWidth) location[2].u = location[3].u = ((float)(u + uWidth)) / ((float)fileWidth) + (.1f / (float)fileWidth); if (fileWidth) location[1].v = location[2].v = ((float)(v + vHeight)) / ((float)fileWidth) + (.1f / (float)fileWidth); if (bRotated) { location[0].u = (u + uWidth) / (float)fileWidth + (.1f / (float)fileWidth); ; location[1].u = u / (float)fileWidth + (.1f / (float)fileWidth); ; location[2].u = u / (float)fileWidth + (.1f / (float)fileWidth); location[3].u = (u + uWidth) / (float)fileWidth + (.1f / (float)fileWidth); location[0].v = v / (float)fileWidth + (.1f / (float)fileWidth); ; location[1].v = v / (float)fileWidth + (.1f / (float)fileWidth); ; location[2].v = (v + vHeight) / (float)fileWidth + (.1f / (float)fileWidth); ; location[3].v = (v + vHeight) / (float)fileWidth + (.1f / (float)fileWidth); ; } }
//---------------------------------------------------------------------- // MC_TextureNode DWORD MC_TextureNode::get_gosTextureHandle (void) //If texture is not in VidRAM, cache a texture out and cache this one in. { if (gosTextureHandle == 0xffffffff) { //Somehow this texture is bad. Probably we are using a handle which got purged between missions. // Just send back, NO TEXTURE and we should be able to debug from there because the tri will have no texture!! return 0x0; } if (gosTextureHandle != CACHED_OUT_HANDLE) { lastUsed = turn; return gosTextureHandle; } else { if ((mcTextureManager->currentUsedTextures >= MAX_MC2_GOS_TEXTURES) && !mcTextureManager->flushCache()) return 0x0; //No texture! if (width == 0) return 0; //These faces have no texture!! if (!textureData) return 0x0; //No Texture. Cache is out of RAM!! if (width > 0xf0000000) { //------------------------------------------ // Cache this badboy IN. // Badboys are now LZ Compressed in texture cache. // Uncompress, then memcpy. long origSize = LZDecomp(MC_TextureManager::lzBuffer2,(MemoryPtr)textureData,lzCompSize); if (origSize != (long)(width & 0x0fffffff)) STOP(("Decompressed to different size from original! Txm:%s Width:%d DecompSize:%d",nodeName,(width & 0x0fffffff),origSize)); if (origSize >= MAX_LZ_BUFFER_SIZE) STOP(("Texture TOO large: %s",nodeName)); gosTextureHandle = gos_NewTextureFromMemory(key,nodeName,MC_TextureManager::lzBuffer2,(width & 0x0fffffff),hints); mcTextureManager->currentUsedTextures++; lastUsed = turn; return gosTextureHandle; } else { gosTextureHandle = gos_NewEmptyTexture(key,nodeName,width,hints); mcTextureManager->currentUsedTextures++; //------------------------------------------ // Cache this badboy IN. TEXTUREPTR pTextureData; gos_LockTexture(gosTextureHandle, 0, 0, &pTextureData); //------------------------------------------------------- // Create a block of cache memory to hold this texture. DWORD txmSize = pTextureData.Height * pTextureData.Height * sizeof(DWORD); gosASSERT(textureData); LZDecomp(MC_TextureManager::lzBuffer2,(MemoryPtr)textureData,lzCompSize); memcpy(pTextureData.pTexture,MC_TextureManager::lzBuffer2,txmSize); //------------------------ // Unlock the texture gos_UnLockTexture(gosTextureHandle); lastUsed = turn; return gosTextureHandle; } } }
void aButton::init( FitIniFile& buttonFile, const char* str, HGOSFONT3D font ) { textureHandle = 0; long result = buttonFile.seekBlock( str ); if ( result != NO_ERR ) { char errorStr[256]; sprintf( errorStr, "couldn't find button %s", str ); Assert( 0, 0, errorStr ); return; } buttonFile.readIdLong( "ID", data.ID ); buttonFile.readIdString("FileName", data.fileName, 32 ); buttonFile.readIdLong( "HelpCaption", helpHeader ); buttonFile.readIdLong( "HelpDesc", helpID ); buttonFile.readIdLong( "TextID", data.textID ); buttonFile.readIdLong( "TextNormal", data.textColors[0] ); buttonFile.readIdLong( "TextPressed", data.textColors[1] ); buttonFile.readIdLong( "TextDisabled", data.textColors[2] ); buttonFile.readIdBoolean( "Toggle", toggleButton ); buttonFile.readIdBoolean( "outline", data.outline ); long fontID; buttonFile.readIdLong( "Font", fontID ); if ( fontID ) data.textFont = aFont::loadFont( fontID, data.textSize ); else data.textFont = 0; long x, y, width, height; buttonFile.readIdLong( "XLocation", x ); buttonFile.readIdLong( "YLocation", y ); buttonFile.readIdLong( "Width", width ); buttonFile.readIdLong( "Height", height ); buttonFile.readIdLong( "HelpCaption", helpHeader ); buttonFile.readIdLong( "HelpDesc", helpID ); buttonFile.readIdBoolean( "texturesRotated", data.textureRotated ); if ( NO_ERR != buttonFile.readIdLong( "Alignment", data.textAlign ) ) data.textAlign = 2; location[0].x = location[1].x = x; location[0].y = location[3].y = y; location[2].x = location[3].x = x + width; location[1].y = location[2].y = y + height; for ( int j = 0; j < 4; j++ ) { location[j].argb = 0xffffffff; location[j].frgb = 0; location[j].rhw = .5; location[j].u = 0.f; location[j].v = 0.f; location[j].z = 0.f; } if ( 0 == textureHandle && data.fileName && strlen( data.fileName ) ) { char file[256]; strcpy( file, artPath ); strcat( file, data.fileName ); _strlwr( file ); if ( !strstr( data.fileName, ".tga" ) ) strcat( file, ".tga" ); int ID = mcTextureManager->loadTexture( file, gos_Texture_Alpha, 0, 0, 0x2 ); int gosID = mcTextureManager->get_gosTextureHandle( ID ); TEXTUREPTR textureData; gos_LockTexture( gosID, 0, 0, &textureData ); gos_UnLockTexture( gosID ); textureHandle = ID; data.fileWidth = textureData.Width; data.fileHeight = data.fileWidth; } if ( NO_ERR != buttonFile.readIdLong( "UNormal", data.stateCoords[0][0] ) ) data.stateCoords[0][0] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "VNormal", data.stateCoords[0][1] ) ) data.stateCoords[0][1] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "UPressed", data.stateCoords[1][0] ) ) data.stateCoords[1][0] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "VPressed", data.stateCoords[1][1] ) ) data.stateCoords[1][1] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "UDisabled", data.stateCoords[2][0] ) ) data.stateCoords[2][0] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "VDisabled", data.stateCoords[2][1] ) ) data.stateCoords[2][1] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "UAmbiguous", data.stateCoords[3][0] ) ) data.stateCoords[3][0] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "VAmbiguous", data.stateCoords[3][1] ) ) data.stateCoords[3][1] = -1.f; if ( NO_ERR != buttonFile.readIdLong( "UHighlight", data.stateCoords[4][0] ) ) { data.stateCoords[4][0] = data.stateCoords[0][0]; } if ( NO_ERR != buttonFile.readIdLong( "VHighlight", data.stateCoords[4][1] ) ) { data.stateCoords[4][1] = data.stateCoords[0][1]; } buttonFile.readIdLong( "UWidth", data.textureWidth ); buttonFile.readIdLong( "VHeight", data.textureHeight ); if ( data.textID ) buttonFile.readIdBoolean( "TextOutline", data.outlineText ); if ( NO_ERR == buttonFile.readIdLong( "XTextLocation", data.textRect.left ) ) { buttonFile.readIdLong( "YTextLocation", data.textRect.top ); buttonFile.readIdLong( "TextWidth", width ); buttonFile.readIdLong( "TextHeight", height ); data.textRect.right = data.textRect.left + width; data.textRect.bottom = data.textRect.top + height; buttonFile.readIdBoolean( "TextOutline", data.outlineText ); } else { data.textRect.left = x; data.textRect.right = x + width; data.textRect.top = y; data.textRect.bottom = y + height; } char bmpName[256]; strcpy( bmpName, str ); strcat( bmpName, "Bmp" ); char finalName[256]; int counter = 0; while(true) { sprintf( finalName, "%s%ld", bmpName, counter ); if ( NO_ERR != buttonFile.seekBlock( finalName) ) break; aObject* pObject = new aObject; pObject->init( &buttonFile, finalName ); // Dorje is doing this in global coords pObject->move( -globalX(), -globalY() ); addChild( pObject ); counter++; } buttonFile.seekBlock( str ); disable( 0 ); press( 0 ); }