diff --git a/game/client/touch.cpp b/game/client/touch.cpp index c80550bb..86b55d37 100644 --- a/game/client/touch.cpp +++ b/game/client/touch.cpp @@ -448,7 +448,12 @@ void CTouchControls::CreateAtlasTexture() FileHandle_t fp; fp = ::filesystem->Open( fullFileName, "rb" ); - if( !fp ) return; + if( !fp ) + { + t->textureID = vgui::surface()->CreateNewTextureID(); + vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false ); + continue; + } ::filesystem->Seek( fp, 0, FILESYSTEM_SEEK_TAIL ); int srcVTFLength = ::filesystem->Tell( fp ); @@ -467,19 +472,27 @@ void CTouchControls::CreateAtlasTexture() { if( t->vtf->Format() != IMAGE_FORMAT_RGBA8888 && t->vtf->Format() != IMAGE_FORMAT_BGRA8888 ) { - Msg("Format=%d\n", t->vtf->Format()); - Error("Use RGBA8888/BGRA88888 for touch buttons!\n"); + t->textureID = vgui::surface()->CreateNewTextureID(); + vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false); + DestroyVTFTexture(t->vtf); + continue; } if( t->vtf->Height() != t->vtf->Width() || (t->vtf->Height() & (t->vtf->Height() - 1)) != 0 ) - Error("Touch texture is wrong! Don't use npot textures for touch."); + Error("%s texture is wrong! Don't use npot textures for touch."); t->height = t->vtf->Height(); t->width = t->vtf->Width(); + t->isInAtlas = true; atlasSize += t->width*t->height; } - - buf.Clear(); + else + { + DestroyVTFTexture(t->vtf); + t->textureID = vgui::surface()->CreateNewTextureID(); + vgui::surface()->DrawSetTextureFile( t->textureID, t->szName, true, false); + continue; + } rects[i].h = t->height; rects[i].w = t->width; @@ -504,6 +517,9 @@ void CTouchControls::CreateAtlasTexture() for( int i = 0; i < textureList.Count(); i++ ) { CTouchTexture *t = textureList[i]; + if( t->textureID ) + continue; + t->X0 = rects[i].x / (float)atlasHeight; t->Y0 = rects[i].y / (float)atlasHeight; t->X1 = t->X0 + t->width / (float)atlasHeight; @@ -519,13 +535,11 @@ void CTouchControls::CreateAtlasTexture() } DestroyVTFTexture(t->vtf); - t->isInAtlas = true; } touchTextureID = vgui::surface()->CreateNewTextureID( true ); vgui::surface()->DrawSetTextureRGBA( touchTextureID, dest, atlasHeight, atlasHeight, 1, true ); - free(nodes); free(rects); delete[] dest; @@ -603,7 +617,6 @@ void CTouchControls::Paint( ) return; CUtlLinkedList::iterator it; - CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); if( state == state_edit ) @@ -638,7 +651,6 @@ void CTouchControls::Paint( ) } } - pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(touchTextureID) ); m_pMesh = pRenderContext->GetDynamicMesh(); int meshCount = 0; @@ -648,20 +660,53 @@ void CTouchControls::Paint( ) if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) ) { - if( !btn->texture->isInAtlas ) + CTouchTexture *t = btn->texture; + + if( t->textureID ) + { + pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(t->textureID) ); + meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount ); + + rgba_t color(btn->color.r, btn->color.g, btn->color.b, btn->color.a); + meshBuilder.Position3f( btn->x1*screen_w, btn->y1*screen_h, 0 ); + meshBuilder.Color4ubv( color ); + meshBuilder.TexCoord2f( 0, 0, 0 ); + meshBuilder.AdvanceVertexF(); + + meshBuilder.Position3f( btn->x2*screen_w, btn->y1*screen_h, 0 ); + meshBuilder.Color4ubv( color ); + meshBuilder.TexCoord2f( 0, 1, 0 ); + meshBuilder.AdvanceVertexF(); + + meshBuilder.Position3f( btn->x2*screen_w, btn->y2*screen_h, 0 ); + meshBuilder.Color4ubv( color ); + meshBuilder.TexCoord2f( 0, 1, 1 ); + meshBuilder.AdvanceVertexF(); + + meshBuilder.Position3f( btn->x1*screen_w, btn->y2*screen_h, 0 ); + meshBuilder.Color4ubv( color ); + meshBuilder.TexCoord2f( 0, 0, 1 ); + meshBuilder.AdvanceVertexF(); + + meshBuilder.End(); + m_pMesh->Draw(); + } + else if( !btn->texture->isInAtlas ) CreateAtlasTexture(); - meshCount++; + if( !t->textureID ) + meshCount++; } } + pRenderContext->Bind( g_pMatSystemSurface->DrawGetTextureMaterial(touchTextureID) ); meshBuilder.Begin( m_pMesh, MATERIAL_QUADS, meshCount ); for( it = btns.begin(); it != btns.end(); it++ ) { CTouchButton *btn = *it; - if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) ) + if( btn->texture != NULL && !(btn->flags & TOUCH_FL_HIDE) && !btn->texture->textureID ) { CTouchTexture *t = btn->texture; @@ -744,6 +789,7 @@ void CTouchControls::AddButton( const char *name, const char *texturefile, const CTouchTexture *texture = new CTouchTexture; btn->texture = texture; texture->isInAtlas = false; + texture->textureID = 0; texture->X0 = 0; texture->X1 = 0; texture->Y0 = 0; texture->Y1 = 0; Q_strncpy( texture->szName, btn->texturefile, sizeof(btn->texturefile) ); textureList.AddToTail(texture); diff --git a/game/client/touch.h b/game/client/touch.h index ad555368..7d37f162 100644 --- a/game/client/touch.h +++ b/game/client/touch.h @@ -83,6 +83,7 @@ struct CTouchTexture float X0, Y0, X1, Y1; // position in atlas texture int height, width; + int textureID; bool isInAtlas; char szName[1024]; }; @@ -164,7 +165,7 @@ public: void Paint( ); void Frame( ); - + void AddButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, rgba_t color = rgba_t(255, 255, 255, 255), int round = 2, float aspect = 1.f, int flags = 0 ); void RemoveButton( const char *name ); void ResetToDefaults(); @@ -172,7 +173,7 @@ public: void ShowButton( const char *name ); void ListButtons(); void RemoveButtons(); - + CTouchButton *FindButton( const char *name ); // bool FindNextButton( const char *name, CTouchButton &button ); void SetTexture( const char *name, const char *file ); diff --git a/mathlib/polyhedron.cpp b/mathlib/polyhedron.cpp index 5981ebca..51af4ca6 100644 --- a/mathlib/polyhedron.cpp +++ b/mathlib/polyhedron.cpp @@ -15,7 +15,6 @@ #include #endif - struct GeneratePolyhedronFromPlanes_Point; struct GeneratePolyhedronFromPlanes_PointLL; struct GeneratePolyhedronFromPlanes_Line; @@ -73,18 +72,18 @@ void CreateDumpDirectory( const char *szDirectoryName ) void CPolyhedron_AllocByNew::Release( void ) { - free(this); + delete this; } CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation { - void *pMemory = malloc(sizeof( CPolyhedron_AllocByNew ) + + void *pMemory = new unsigned char [ sizeof( CPolyhedron_AllocByNew ) + (iVertices * sizeof(Vector)) + (iLines * sizeof(Polyhedron_IndexedLine_t)) + (iIndices * sizeof( Polyhedron_IndexedLineReference_t )) + - (iPolygons * sizeof( Polyhedron_IndexedPolygon_t ))); + (iPolygons * sizeof( Polyhedron_IndexedPolygon_t ))]; -#include "tier0/memdbgoff.h" +#include "tier0/memdbgoff.h" //the following placement new doesn't compile with memory debugging CPolyhedron_AllocByNew *pAllocated = new ( pMemory ) CPolyhedron_AllocByNew; #include "tier0/memdbgon.h" @@ -108,7 +107,7 @@ public: int iReferenceCount; #endif - void Release( void ) override + virtual void Release( void ) { #ifdef DBGFLAG_ASSERT --iReferenceCount;