From 55b88f9a9160963932176bf4fa0ee7f84bce83b5 Mon Sep 17 00:00:00 2001 From: Rene Kjellerup Date: Mon, 3 Jul 2023 11:05:19 -0700 Subject: [PATCH 1/2] audio sources cleanup and reduced some whitespace code noise --- .../client/src/sys/win/winclientde_impl.cpp | 147 +++++++------- runtime/sound/src/sys/openal/openal.cpp | 192 ++++++++++++++---- 2 files changed, 227 insertions(+), 112 deletions(-) diff --git a/runtime/client/src/sys/win/winclientde_impl.cpp b/runtime/client/src/sys/win/winclientde_impl.cpp index 9dc2e90a..dabaf475 100644 --- a/runtime/client/src/sys/win/winclientde_impl.cpp +++ b/runtime/client/src/sys/win/winclientde_impl.cpp @@ -3,6 +3,7 @@ #include "clientmgr.h" #include "iltclient.h" #include "console.h" +#include "ltinteger.h" #include "winclientde_impl.h" #include "interface_helpers.h" #ifndef USE_DXVK @@ -72,17 +73,17 @@ static PFormat g_PrevScreenFormat; static uint32 g_nPrevScreenPixelBytes; -static LTRESULT cis_WarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_WarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords); -static LTRESULT cis_WarpSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_WarpSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords, HLTCOLOR hColor); -static LTRESULT cis_WarpSurfaceToSurfaceSolidColor(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_WarpSurfaceToSurfaceSolidColor(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords, HLTCOLOR hTransColor, HLTCOLOR hFillColor); static LTRESULT cis_End3D(uint flags); -typedef LTRESULT (*DrawPixelsFn)(bool bSameSurface, uint8 *pSrcData, uint8 *pDestData, +typedef LTRESULT (*DrawPixelsFn)(bool bSameSurface, uint8 *pSrcData, uint8 *pDestData, long srcPitch, long destPitch, LTRect *pSrcRect, LTRect *pDestRect); @@ -102,7 +103,7 @@ inline void cis_SetSolidColor(uint32 inColor) static LTRESULT cis_OpaqueDraw(bool bSameSurface, - uint8 *pSrcLine, uint8 *pDestLine, + uint8 *pSrcLine, uint8 *pDestLine, long srcPitch, long destPitch, LTRect *pSrcRect, LTRect *pDestRect) { uint32 y, rectWidth, rectHeight, bytesPerLine; @@ -113,7 +114,7 @@ static LTRESULT cis_OpaqueDraw(bool bSameSurface, pSrcLine += pSrcRect->top*srcPitch + pSrcRect->left*g_nScreenPixelBytes; pDestLine += pDestRect->top*destPitch + pDestRect->left*g_nScreenPixelBytes; - + for(y=0; y < rectHeight; y++) { if(bSameSurface) @@ -142,7 +143,7 @@ inline void cis_SolidColorDrawLine(uint8 *pSrcLine, uint8 *pDestLine, uint32 wid while(width) { width--; - + if(src != g_TransparentColor) dest = g_SolidColor; @@ -152,7 +153,7 @@ inline void cis_SolidColorDrawLine(uint8 *pSrcLine, uint8 *pDestLine, uint32 wid } static LTRESULT cis_SolidColorDraw(bool bSameSurface, - uint8 *pSrcLine, uint8 *pDestLine, + uint8 *pSrcLine, uint8 *pDestLine, long srcPitch, long destPitch, LTRect *pSrcRect, LTRect *pDestRect) { uint32 y, rectWidth, rectHeight; @@ -173,7 +174,7 @@ static LTRESULT cis_SolidColorDraw(bool bSameSurface, { cis_SolidColorDrawLine(pSrcLine, pDestLine, rectWidth, (Pixel32*)LTNULL); } - + pSrcLine += srcPitch; pDestLine += destPitch; } @@ -202,12 +203,12 @@ inline void cis_TransparentDrawLine(uint8 *pSrcLine, uint8 *pDestLine, uint32 wi } static LTRESULT cis_TransparentDraw(bool bSameSurface, - uint8 *pSrcData, uint8 *pDestData, + uint8 *pSrcData, uint8 *pDestData, long srcPitch, long destPitch, LTRect *pSrcRect, LTRect *pDestRect) { uint32 y, rectWidth, rectHeight; uint8 *pSrcLine, *pDestLine; - + rectWidth = (uint32)(pSrcRect->right - pSrcRect->left); rectHeight = (uint32)(pSrcRect->bottom - pSrcRect->top); @@ -224,7 +225,7 @@ static LTRESULT cis_TransparentDraw(bool bSameSurface, { cis_TransparentDrawLine(pSrcLine, pDestLine, rectWidth, (Pixel32*)LTNULL); } - + pSrcLine += srcPitch; pDestLine += destPitch; } @@ -327,7 +328,7 @@ static void cis_OptimizeDirty(CisSurface *pSurface) { if(!pSurface) return; - + if((pSurface->m_Flags & SURFFLAG_OPTIMIZED) && (pSurface->m_Flags & SURFFLAG_OPTIMIZEDIRTY)) { g_pCisRenderStruct->OptimizeSurface(pSurface->m_hBuffer, pSurface->m_OptimizedTransparentColor); @@ -345,7 +346,7 @@ static LTRESULT cis_MaskedDraw(bool bSameSurface, uint32 y, maskMaskX, maskMaskY; long maskPitch; uint32 rectWidth, rectHeight; - + CHECK_PARAMS2(g_pMask && g_pMask->m_Width <= 256 && g_pMask->m_Height <= 256); maskMaskX = g_MaskLookup[g_pMask->m_Width]; @@ -368,11 +369,11 @@ static LTRESULT cis_MaskedDraw(bool bSameSurface, { if(g_ScreenFormat.GetType() == BPP_16) { - + cis_MaskedDrawLine16(pSrcLine, pDestLine, rectWidth, &pMaskData[((pSrcRect->top+y)&maskMaskY)*maskPitch], maskMaskX, pSrcRect->left); - + } else if(g_ScreenFormat.GetType() == BPP_32) { @@ -380,7 +381,7 @@ static LTRESULT cis_MaskedDraw(bool bSameSurface, &pMaskData[((pSrcRect->top+y)&maskMaskY)*maskPitch], maskMaskX, pSrcRect->left); } - + pSrcLine += srcPitch; pDestLine += destPitch; } @@ -390,7 +391,7 @@ static LTRESULT cis_MaskedDraw(bool bSameSurface, } -static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, LTRect *pSrcRect, int destX, int destY, DrawPixelsFn fn) { FN_NAME(cis_DoDrawSurfaceToSurface); @@ -409,7 +410,7 @@ static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, if(pSrcRect) { bIsInside = cis_ClipRectsNonScaled( - pSrc->m_Width, pSrc->m_Height, pSrcRect->left, pSrcRect->top, pSrcRect->right, pSrcRect->bottom, + pSrc->m_Width, pSrc->m_Height, pSrcRect->left, pSrcRect->top, pSrcRect->right, pSrcRect->bottom, pDest->m_Width, pDest->m_Height, destX, destY, &srcRect, &destRect); } else @@ -421,9 +422,9 @@ static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, if(!bIsInside) return LT_OK; - + // Try to translate the command to let the RenderStruct do it. - if(fn == cis_OpaqueDraw || + if(fn == cis_OpaqueDraw || fn == cis_TransparentDraw) { if(pDest == &g_ScreenSurface) @@ -438,13 +439,13 @@ static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, blitRequest.m_pDestRect = &destRect; blitRequest.m_BlitOptions = (fn == cis_TransparentDraw) ? BLIT_TRANSPARENT : 0; blitRequest.m_Alpha = pSrc->m_Alpha; - + r_GetRenderStruct()->BlitToScreen(&blitRequest); cis_SetDirty(pDest); return LT_OK; } - } + } else if (pSrc==&g_ScreenSurface) { // do a screen read... @@ -455,7 +456,7 @@ static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, blitRequest.m_pSrcRect = &srcRect; blitRequest.m_pDestRect = &destRect; blitRequest.m_BlitOptions = (fn == cis_TransparentDraw) ? BLIT_TRANSPARENT : 0; - + r_GetRenderStruct()->BlitFromScreen(&blitRequest); return LT_OK; } @@ -505,7 +506,7 @@ static void cis_InternalBitmapToSurface(CisSurface *pDest, LoadedBitmap *pSrc, if(pSrcRect) { bIsInside = cis_ClipRectsNonScaled( - pSrc->m_Width, pSrc->m_Height, pSrcRect->left, pSrcRect->top, pSrcRect->right, pSrcRect->bottom, + pSrc->m_Width, pSrc->m_Height, pSrcRect->left, pSrcRect->top, pSrcRect->right, pSrcRect->bottom, pDest->m_Width, pDest->m_Height, destX, destY, &srcRect, &destRect); } else @@ -528,7 +529,7 @@ static void cis_InternalBitmapToSurface(CisSurface *pDest, LoadedBitmap *pSrc, request.m_pSrc += srcRect.top*pSrc->m_Pitch + srcRect.left; request.m_pSrcPalette = pSrc->m_Palette; request.m_SrcPitch = pSrc->m_Pitch; - + request.m_Width = (uint32)(srcRect.right - srcRect.left); request.m_Height = (uint32)(srcRect.bottom - srcRect.top); @@ -536,7 +537,7 @@ static void cis_InternalBitmapToSurface(CisSurface *pDest, LoadedBitmap *pSrc, cis_UnlockSurface(pDest); } -static LTRESULT cis_InternalWarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_InternalWarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords, DrawWarpFn fn) { CisSurface *pSrc, *pDest; @@ -545,12 +546,12 @@ static LTRESULT cis_InternalWarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, WarpCoords leftCoords[1024], rightCoords[1024]; uint32 minY, maxY; - + pSrc = (CisSurface*)hSrc; pDest = (CisSurface*)hDest; if(!pSrc || !pDest) RETURN_ERROR(1, InternalWarpSurfaceToSurface, LT_INVALIDPARAMS); - + // Make sure they specified the coordinates correctly. if(nCoords > MAX_WARP_POINTS) nCoords = MAX_WARP_POINTS; @@ -566,7 +567,7 @@ static LTRESULT cis_InternalWarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, } // Clip the dest coordinates.. - bIsVisible = cis_Clip2dPoly(pCoords, nCoords, 0.0f, 0.0f, + bIsVisible = cis_Clip2dPoly(pCoords, nCoords, 0.0f, 0.0f, (float)(pDest->m_Width-1), (float)(pDest->m_Height-1)); if(!bIsVisible) return LT_OK; @@ -589,7 +590,7 @@ static LTRESULT cis_InternalTransformSurfaceToSurface(HSURFACE hDest, HSURFACE h LTFloatPt points[4], translate, shiftBack; BlitRequest blitRequest; int i; - + pSrc = (CisSurface*)hSrc; pDest = (CisSurface*)hDest; if(!pSrc || !pDest) @@ -607,7 +608,7 @@ static LTRESULT cis_InternalTransformSurfaceToSurface(HSURFACE hDest, HSURFACE h rotOrigin.y = (float)destY + halfSrcHeight; } - + // Setup the points at the rotation origin. translate.x = (float)destX - rotOrigin.x; translate.y = (float)destY - rotOrigin.y; @@ -626,7 +627,7 @@ static LTRESULT cis_InternalTransformSurfaceToSurface(HSURFACE hDest, HSURFACE h shiftBack.x = -translate.x + (float)destX; shiftBack.y = -translate.y + (float)destY; - + for(i=0; i < 4; i++) { points[i].x *= scaleX; @@ -744,10 +745,10 @@ static LTRESULT cis_InternalScaleSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, if(pDest == &g_ScreenSurface) { bIsInside = cis_ClipRectsScaled( - pSrc->m_Width, pSrc->m_Height, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, + pSrc->m_Width, pSrc->m_Height, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, pDest->m_Width, pDest->m_Height, destRect.left, destRect.top, destRect.right, destRect.bottom, &srcRect, &destRect); - + if(bIsInside) { if(r_GetRenderStruct()->BlitToScreen) @@ -761,7 +762,7 @@ static LTRESULT cis_InternalScaleSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, blitRequest.m_BlitOptions = (tType == 0) ? BLIT_TRANSPARENT : 0; blitRequest.m_Alpha = pSrc->m_Alpha; blitRequest.m_bUseOld = true; - + r_GetRenderStruct()->BlitToScreen(&blitRequest); cis_SetDirty(pDest); @@ -804,7 +805,7 @@ static void cis_DeleteSurfaceBuffer(CisSurface *pSurface) if(pSurface->m_hBuffer) { ASSERT(g_pCisRenderStruct); - + g_pCisRenderStruct->DeleteSurface(pSurface->m_hBuffer); pSurface->m_hBuffer = LTNULL; } @@ -880,7 +881,7 @@ static bool cis_RestoreSurface(CisSurface *pSurface) return false; request.m_DestPitch = iPitch; - + request.m_pSrcFormat = &g_PrevScreenFormat; request.m_pSrc = pSurface->m_pBackupBuffer; request.m_SrcPitch = pSurface->m_Width * g_nPrevScreenPixelBytes; @@ -889,7 +890,7 @@ static bool cis_RestoreSurface(CisSurface *pSurface) request.m_Height = pSurface->m_Height; dResult = format_mgr->Mgr()->ConvertPixels(&request); - g_pCisRenderStruct->UnlockSurface(pSurface->m_hBuffer); + g_pCisRenderStruct->UnlockSurface(pSurface->m_hBuffer); if(dResult != LT_OK) { @@ -953,7 +954,7 @@ static void cis_DeleteSurfaces() cis_DeleteSurfaceBackupBuffer(pSurface); cis_DeleteSurfaceBuffer(pSurface); - + sb_Free(&g_SurfaceBank, pSurface); } @@ -989,7 +990,7 @@ CisSurface* cis_InternalCreateSurface(uint32 width, uint32 height) pSurface->m_pUserData = LTNULL; pSurface->m_Alpha = 1.0f; - g_Surfaces.AddHead(pSurface); + g_Surfaces.AddHead(pSurface); return pSurface; } @@ -1031,7 +1032,7 @@ static bool IsVertSpanSolidColor(uint8 *pBuf, GenericColor color, uint32 height, { if(*((uint16*)pBuf) != color.wVal) return false; - + pBuf += pitch; --height; } @@ -1042,7 +1043,7 @@ static bool IsVertSpanSolidColor(uint8 *pBuf, GenericColor color, uint32 height, { if(*((uint32*)pBuf) != color.dwVal) return false; - + pBuf += pitch; --height; } @@ -1059,7 +1060,7 @@ static bool IsHorzSpanSolidColor(uint8 *pBuf, GenericColor color, uint32 width) { if(*((uint16*)pBuf) != color.wVal) return false; - + --width; pBuf += sizeof(uint16); } @@ -1070,7 +1071,7 @@ static bool IsHorzSpanSolidColor(uint8 *pBuf, GenericColor color, uint32 width) { if(*((uint32*)pBuf) != color.dwVal) return false; - + --width; pBuf += sizeof(uint32); } @@ -1110,8 +1111,8 @@ static LTRESULT cis_GetBorderSize(HSURFACE hSurface, HLTCOLOR hColor, LTRect *pR while(pRect->bottom < (int)pSurface->m_Height && IsHorzSpanSolidColor(&pBuf[(pSurface->m_Height-pRect->bottom-1)*iPitch], theColor, pSurface->m_Width)) { ++pRect->bottom; } - - g_pCisRenderStruct->UnlockSurface(pSurface->m_hBuffer); + + g_pCisRenderStruct->UnlockSurface(pSurface->m_hBuffer); return LT_OK; } @@ -1125,8 +1126,8 @@ static LTRESULT cis_OptimizeSurface(HSURFACE hSurface, HLTCOLOR hTransparentColo pSurface = (CisSurface*)hSurface; pSurface->m_OptimizedTransparentColor = (uint32)hTransparentColor; - // The render driver wants a uint32 color so either get rid of the - // COLOR_TRANSPARENCY_MASK or set it to OPTIMIZE_NO_TRANSPARENCY. + // The render driver wants a uint32 color so either get rid of the + // COLOR_TRANSPARENCY_MASK or set it to OPTIMIZE_NO_TRANSPARENCY. if(pSurface->m_OptimizedTransparentColor & COLOR_TRANSPARENCY_MASK) pSurface->m_OptimizedTransparentColor &= ~COLOR_TRANSPARENCY_MASK; else @@ -1231,7 +1232,7 @@ static LTRESULT cis_CreateHeightmapFromBitmap(const char* pBitmap, uint32* pWidt return LT_INVALIDPARAMS; //load up the bitmap - LoadedBitmap Bitmap; + LoadedBitmap Bitmap; if(!cis_LoadPcx((char*)pBitmap, &Bitmap)) return LT_ERROR; @@ -1251,8 +1252,8 @@ static LTRESULT cis_CreateHeightmapFromBitmap(const char* pBitmap, uint32* pWidt for(uint32 nCurrColor = 0; nCurrColor < 256; nCurrColor++) { - nPalette[nCurrColor] = (uint8)(((uint32)Bitmap.m_Palette[nCurrColor].rgb.r + - (uint32)Bitmap.m_Palette[nCurrColor].rgb.g + + nPalette[nCurrColor] = (uint8)(((uint32)Bitmap.m_Palette[nCurrColor].rgb.r + + (uint32)Bitmap.m_Palette[nCurrColor].rgb.g + (uint32)Bitmap.m_Palette[nCurrColor].rgb.b) / 3); } @@ -1291,7 +1292,7 @@ static HSURFACE cis_CreateSurfaceFromBitmap(const char *pBitmapName) LoadedBitmap bitmap; HSURFACE hRet; - + if(!cis_LoadPcx(pBitmapName, &bitmap)) return LTNULL; @@ -1398,7 +1399,7 @@ static void cis_GetSurfaceDims(HSURFACE hSurf, uint32 *pWidth, uint32 *pHeight) { if(pWidth) *pWidth = pSurface->m_Width; - + if(pHeight) *pHeight = pSurface->m_Height; } @@ -1408,7 +1409,7 @@ static void cis_GetSurfaceDims(HSURFACE hSurf, uint32 *pWidth, uint32 *pHeight) } } -static bool cis_DrawBitmapToSurface(HSURFACE hDest, const char *pSourceBitmapName, +static bool cis_DrawBitmapToSurface(HSURFACE hDest, const char *pSourceBitmapName, const LTRect *pSrcRect, int destX, int destY) { LoadedBitmap bitmap; @@ -1448,7 +1449,7 @@ static LTRESULT cis_DrawSurfaceMasked(HSURFACE hDest, HSURFACE hSrc, HSURFACE hM return cis_DoDrawSurfaceToSurface(hDest, hSrc, pSrcRect, destX, destY, cis_MaskedDraw); } -LTRESULT cis_DrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, +LTRESULT cis_DrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, LTRect *pSrcRect, int destX, int destY) { if(!g_pCisRenderStruct) @@ -1457,7 +1458,7 @@ LTRESULT cis_DrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, return cis_DoDrawSurfaceToSurface(hDest, hSrc, pSrcRect, destX, destY, cis_OpaqueDraw); } -static LTRESULT cis_DrawSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_DrawSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSrc, LTRect *pSrcRect, int destX, int destY, HLTCOLOR hColor) { if(!g_pCisRenderStruct) @@ -1498,7 +1499,7 @@ static LTRESULT cis_ScaleSurfaceToSurfaceSolidColor(HSURFACE hDest, HSURFACE hSr return cis_InternalScaleSurfaceToSurface(hDest, hSrc, pDestRect, pSrcRect, 2, hTransColor, hFillColor); } -static LTRESULT cis_WarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_WarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords) { if(!g_pCisRenderStruct) @@ -1508,7 +1509,7 @@ static LTRESULT cis_WarpSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, } -static LTRESULT cis_WarpSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_WarpSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords, HLTCOLOR hColor) { if(!g_pCisRenderStruct) @@ -1519,7 +1520,7 @@ static LTRESULT cis_WarpSurfaceToSurfaceTransparent(HSURFACE hDest, HSURFACE hSr } -static LTRESULT cis_WarpSurfaceToSurfaceSolidColor(HSURFACE hDest, HSURFACE hSrc, +static LTRESULT cis_WarpSurfaceToSurfaceSolidColor(HSURFACE hDest, HSURFACE hSrc, LTWarpPt *pCoords, int nCoords, HLTCOLOR hTransColor, HLTCOLOR hFillColor) { if(!g_pCisRenderStruct) @@ -1608,7 +1609,7 @@ static LTRESULT cis_GetSurfaceAlpha(HSURFACE hSurface, float &alpha) CisSurface *pSurface; CHECK_PARAMS2(hSurface); - + pSurface = (CisSurface*)hSurface; alpha = pSurface->m_Alpha; return LT_OK; @@ -1621,7 +1622,7 @@ static LTRESULT cis_SetSurfaceAlpha(HSURFACE hSurface, float alpha) CisSurface *pSurface; CHECK_PARAMS2(hSurface); - + pSurface = (CisSurface*)hSurface; pSurface->m_Alpha = LTCLAMP(alpha, 0.0f, 1.0f); return LT_OK; @@ -1662,7 +1663,7 @@ static LTRESULT cis_GetEngineHook(const char *pName, void **pData) *pData = (void*)r_GetRenderStruct()->GetD3DDevice(); return LT_OK; } - + return LT_ERROR; } @@ -1688,7 +1689,7 @@ static LTRESULT cis_QueryGraphicDevice(LTGraphicsCaps* pCaps) pCaps->PixelShaderVersion = (uint32)caps.PixelShaderVersion; pCaps->VertexShaderVersion = (uint32)caps.VertexShaderVersion; - + return LT_OK; } @@ -1705,7 +1706,7 @@ static LTRESULT cis_FlipScreen(uint32 flags) cis_End3D(END3D_CANDRAWCONSOLE); } - g_pClientMgr->ShowDrawSurface(flags); + g_pClientMgr->ShowDrawSurface(flags); return LT_OK; } @@ -1834,7 +1835,7 @@ static LTRESULT cis_StartOptimized2D() if(!pStruct->IsIn3D()) RETURN_ERROR(1, StartOptimized2D, LT_NOTIN3D); - + ++(pStruct->m_nInOptimized2D); if (pStruct->m_nInOptimized2D == 1) @@ -1854,10 +1855,10 @@ static LTRESULT cis_EndOptimized2D() if(!pStruct->IsIn3D()) RETURN_ERROR(1, EndOptimized2D, LT_NOTIN3D); - + if(!pStruct->IsInOptimized2D()) RETURN_ERROR(1, EndOptimized2D, LT_NOTIN3D); - + --(pStruct->m_nInOptimized2D); if (pStruct->m_nInOptimized2D == 0) @@ -1877,7 +1878,7 @@ static LTRESULT cis_SetOptimized2DBlend(LTSurfaceBlend blend) if(!pStruct->IsIn3D()) RETURN_ERROR(1, SetOptimized2DBlend, LT_NOTIN3D); - + // This shouldn't ever fail unless an invalid blend mode is specified bool bResult = pStruct->SetOptimized2DBlend(blend); ASSERT(bResult); @@ -1909,7 +1910,7 @@ static LTRESULT cis_SetOptimized2DColor(HLTCOLOR hColor) if(!pStruct->IsIn3D()) RETURN_ERROR(1, SetOptimized2DColor, LT_NOTIN3D); - + // This shouldn't ever fail unless an invalid blend mode is specified bool bResult = pStruct->SetOptimized2DColor(hColor); ASSERT(bResult); @@ -2018,7 +2019,7 @@ void cis_Init() ilt_client->GetSurfaceDims = cis_GetSurfaceDims; ilt_client->GetScreenSurface = cis_GetScreenSurface; ilt_client->DrawSurfaceToSurfaceTransparent = cis_DrawSurfaceToSurfaceTransparent; - + ilt_client->CreateHeightmapFromBitmap = cis_CreateHeightmapFromBitmap; ilt_client->FreeHeightmap = cis_FreeHeightmap; ilt_client->CreateSurfaceFromBitmap = cis_CreateSurfaceFromBitmap; @@ -2055,7 +2056,7 @@ void cis_Init() void cis_Term() { cis_DeleteSurfaces(); - + // Shutdown the allocators. sb_Term(&g_SurfaceBank); #ifndef USE_DXVK @@ -2097,7 +2098,7 @@ unsigned long GetInterfaceSurfaceMemory() for(pos=g_Surfaces; pos; ) { pSurface = g_Surfaces.GetNext(pos); - + total += pSurface->m_Width * pSurface->m_Height * 2; if(pSurface->m_Flags & SURFFLAG_OPTIMIZED) { diff --git a/runtime/sound/src/sys/openal/openal.cpp b/runtime/sound/src/sys/openal/openal.cpp index dca53139..5779bc02 100644 --- a/runtime/sound/src/sys/openal/openal.cpp +++ b/runtime/sound/src/sys/openal/openal.cpp @@ -11,6 +11,7 @@ #endif #include #include +#include typedef sint16 S16; typedef uint16 U16; @@ -46,6 +47,88 @@ enum #endif #define C3D_REFERENCE_DISTANCE 2000.0f +class OpenALSources +{ + ALuint sources[256]{0}; + bool in_use[256]{false}; +public: + void init(); + void term(); + ALuint GetNextSource(); + void ReleaseSource(ALuint src); + void reset(); +}; + +static OpenALSources oalSource; + +void +OpenALSources::init() +{ + alGenSources(256, sources); + std::cout << "init all 256 OpenAL sources\n"; +} + +void +OpenALSources::term() +{ + { + auto beg = std::begin(in_use); + auto end = std::end(in_use); + std::cout << std::count(beg, end, true) << '\n'; + std::fill(beg, end, false); + } + std::cout << "release all 256 OpenAL sources\n"; + + alDeleteSources(256, sources); + alGetError(); + for(auto &&s: sources) + s = 0; +} + +ALuint +OpenALSources::GetNextSource() +{ + auto beg = std::begin(in_use); + auto end = std::end(in_use); + auto next = std::find(beg, end, false); + + if (next == end) + return 0; + auto idx = next - beg; + // if (in_use[next - beg]) return GetNextSource(); + std::cout << idx << ',' << std::count(beg, end, true) << '\n'; + in_use[idx] = true; + return sources[idx]; +} + +void +OpenALSources::ReleaseSource(ALuint src) +{ + auto beg = std::begin(sources); + auto end = std::end(sources); + auto next = std::find(beg, end, src); + + if (next == end) return; + + auto idx = next - beg; + + alSourcei(src, AL_BYTE_OFFSET, 0); + alSourcei(src, AL_LOOPING, AL_FALSE); + alSourcei(src, AL_BUFFER, 0); + alGetError(); + + in_use[idx] = false; + // std::cout << "releaseing '" << src << "' back to source pool\n"; +} + +void +OpenALSources::reset() +{ + alDeleteSources(256, sources); + alGenSources(256, sources); + for(auto &&u: in_use) + u = false; +} //ADPCM decoding from https://github.com/dbry/adpcm-xq/ //see adpcm_license.txt for details. @@ -319,6 +402,7 @@ class CSample // =========================================================================== // Incorporation of DSMStrm* required functionality public: + void assignBuffer(); bool IsPlaying( ); virtual void SetLooping( COpenALSoundSys* pSoundSys, bool bLoop ); bool IsLooping( ) { return m_bLooping; } @@ -391,27 +475,29 @@ void CSample::DisplayError() switch (error) { case AL_NO_ERROR: break; case AL_INVALID_NAME: - std::cout << "OpenAL invalid name\n"; + std::cout << "OpenAL invalid name (" << source << ", " << buffer << ")\n"; + throw std::string{"OpenAL Invalid Name"}; break; case AL_INVALID_ENUM: - std::cout << "OpenAL invalid Enum\n"; + std::cout << "OpenAL invalid Enum (" << source << ", " << buffer << ")\n"; break; case AL_INVALID_VALUE: - std::cout << "OpenAL invalid Value\n"; + std::cout << "OpenAL invalid Value (" << source << ", " << buffer << ")\n"; break; case AL_INVALID_OPERATION: - std::cout << "OpenAL invalid Operation\n"; + std::cout << "OpenAL invalid Operation (" << source << ", " << buffer << ")\n"; break; case AL_OUT_OF_MEMORY: - std::cout << "OpenAL Out of Memory\n"; + std::cout << "OpenAL Out of Memory (" << source << ", " << buffer << ")\n"; break; } } void CSample::Term( ) { - alDeleteSources(1, &source); - alDeleteBuffers(1, &buffer); + //alDeleteSources(1, &source); + //alDeleteBuffers(1, &buffer); + oalSource.ReleaseSource(source); if( m_bAllocatedSoundData && m_pSoundData != NULL ) delete[] m_pSoundData; @@ -467,21 +553,23 @@ bool CSample::IsPlaying( ) void CSample::SetLooping( COpenALSoundSys* pSoundSys, bool bLoop ) { - if( bLoop != m_bLooping ) + bool playing = IsPlaying(); + if (m_bLooping != bLoop && playing) { - if( IsPlaying( )) - { - Stop( false ); - Play( ); - } + Stop(false); } - m_bLooping = bLoop; - alSourcei(source, AL_LOOPING, m_bLooping ? AL_TRUE : AL_FALSE); + alSourcei(source, AL_LOOPING, bLoop? AL_TRUE: AL_FALSE); + + if (m_bLooping != bLoop && playing) + { + Play(); + } } bool CSample::GetCurrentPosition( unsigned int* pdwPlayPos, unsigned int* pdwWritePos ) { + if( source == 0 ) return false; @@ -489,11 +577,29 @@ bool CSample::GetCurrentPosition( unsigned int* pdwPlayPos, unsigned int* pdwWri return true; } +void CSample::assignBuffer() +{ + if ( buffer == 0 ) + return; + + if ( source == 0 ) + source = oalSource.GetNextSource(); + alGetError(); + alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BYTE_OFFSET, m_nLastPlayPos); + alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE); + error = alGetError(); + DisplayError(); +} + bool CSample::SetCurrentPosition( unsigned int dwStartOffset ) { - if( source == 0 ) + if (buffer == 0) return false; + if( source == 0 ) + assignBuffer(); + alSourcei(source, AL_BYTE_OFFSET, dwStartOffset); // Set the last play pos to zero, because doing this on a playing sound @@ -511,13 +617,8 @@ bool CSample::Play( ) if (source == 0) { alGetError(); // clear errors, prior to create a new source - alGenSources(1, &source); - error = alGetError(); - if (error != AL_NO_ERROR) { - std::cout << "CSample::Play genSources: "; - DisplayError(); - return false; - } + assignBuffer(); + std::cout << "CSample::Play assigned source (" << source << ", " << buffer << ")\n"; } alSourcei(source, AL_BUFFER, buffer); @@ -525,6 +626,7 @@ bool CSample::Play( ) alSource3i(source, AL_POSITION, 0, 0, 0); alSourcei(source, AL_LOOPING, m_bLooping ? AL_TRUE : AL_FALSE); alSourcef(source, AL_GAIN, m_fVolume); + alGetError(); alSourcePlay(source); error = alGetError(); if (error != AL_NO_ERROR){ @@ -545,11 +647,10 @@ bool CSample::Stop( bool bReset ) if( bReset ) { m_nLastPlayPos = 0; - } if (! m_bLooping ) { - alDeleteSources(1, &source); + oalSource.ReleaseSource(source); source = 0; } return true; @@ -750,22 +851,16 @@ void C3DSample::Term( ) void C3DSample::SetPosition( LTVector& pos ) { - LTVector vPosInner; -// float fRatioInnerToDist, fDistSquared; - I3DObject::SetPosition( pos ); if(m_sample.source == 0) - return; - - alSource3f(m_sample.source, AL_POSITION, pos.x, pos.y, pos.z); + m_sample.assignBuffer(); alSourcef(m_sample.source, AL_REFERENCE_DISTANCE, C3D_REFERENCE_DISTANCE); -/* // we want the relative position of the object to the inner // radius of the object - fDistSquared = pos.MagSqr(); - fRatioInnerToDist = sqrtf(m_innerRadiusSquared)/sqrtf(fDistSquared); + auto fDistSquared = pos.MagSqr(); + auto fRatioInnerToDist = sqrtf(m_innerRadiusSquared)/sqrtf(fDistSquared); // if it's inside the inner radius if ( fRatioInnerToDist > 1.0f ) @@ -778,11 +873,11 @@ void C3DSample::SetPosition( LTVector& pos ) // otherwise build a vector that is at the appropriate distance // get a vector to the inner radius in the appropriate direction - vPosInner = pos * fRatioInnerToDist; + auto vPosInner = pos * fRatioInnerToDist; // get the relative position of the object outside the inner radius pos = pos - vPosInner; } -*/ + alSource3f(m_sample.source, AL_POSITION, pos.x, pos.y, pos.z); PRINTSTUB; } @@ -790,7 +885,7 @@ void C3DSample::SetVelocity( LTVector& vel ) { I3DObject::SetVelocity( vel ); if(m_sample.source == 0) - return; + m_sample.assignBuffer(); alSource3f(m_sample.source, AL_VELOCITY, vel.x, vel.y, vel.z); PRINTSTUB; @@ -807,6 +902,7 @@ void C3DSample::SetRadiusData( float& fInnerRadius, float& fOuterRadius ) m_innerRadius = fInnerRadius; m_outerRadius = fOuterRadius; m_innerRadiusSquared = fInnerRadius * fInnerRadius; + } void C3DSample::GetRadiusData( float* fInnerRadius, float* fInnerRadiusSquared ) @@ -1105,14 +1201,28 @@ uint32 CStream::FillBuffer( COpenALSoundSys* pSoundSys ) void CStream::SetLooping( COpenALSoundSys* pSoundSys, bool bLoop ) { + bool playing = IsPlaying(); + if (m_bLooping != bLoop && playing) + { + Stop(false); + } + alSourcei(source, AL_LOOPING, bLoop? AL_TRUE: AL_FALSE); + if (m_bLooping != bLoop && playing) + { + Play(); + } m_bLooping = bLoop; + } bool CStream::SetCurrentPosition( unsigned int dwStartOffset ) { - if( source == 0 ) + if( buffer == 0 ) return false; + if (source == 0) + assignBuffer(); + alSourcef(source, AL_BYTE_OFFSET, dwStartOffset); // Set the last play pos to zero, because doing this on a playing sound @@ -1300,6 +1410,7 @@ class COpenALSoundSys : public ILTSoundSys bool COpenALSoundSys::Init( ) { LT_MEM_TRACK_ALLOC(m_pStreams = new CStream( NULL, NULL ),LT_MEM_TYPE_SOUND); + oalSource.init(); return true; } @@ -1333,6 +1444,8 @@ S32 COpenALSoundSys::Startup( void ) alcontext = alcCreateContext(aldevice, 0); alcMakeContextCurrent(alcontext); + oalSource.init(); + mpg_error = mpg123_init(); if (mpg_error != MPG123_OK) @@ -1345,6 +1458,7 @@ S32 COpenALSoundSys::Startup( void ) void COpenALSoundSys::Shutdown( void ) { + oalSource.term(); alcMakeContextCurrent(0); if (alcontext) { @@ -1546,7 +1660,7 @@ void COpenALSoundSys::Set3DVelocityVector( LH3DPOBJECT hObj, float fDX_per_ms, f C3DSample *p3dSample = (C3DSample*)hObj; LTVector vel{fDX_per_ms,fDY_per_ms,fDZ_per_ms}; - p3dSample->SetVelocity(vel); + p3dSample->SetVelocity(vel); } void COpenALSoundSys::Set3DOrientation( LH3DPOBJECT hObj, float fX_face, float fY_face, float fZ_face, float fX_up, float fY_up, float fZ_up ) From 4c45d078fb0ceeffb0f6aba7bc20181a0cc77049 Mon Sep 17 00:00:00 2001 From: Rene Kjellerup Date: Mon, 3 Jul 2023 11:06:33 -0700 Subject: [PATCH 2/2] cleared an assigment + test reading ambiguity --- runtime/client/src/sys/win/winclientde_impl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/client/src/sys/win/winclientde_impl.cpp b/runtime/client/src/sys/win/winclientde_impl.cpp index dabaf475..3fdccdbd 100644 --- a/runtime/client/src/sys/win/winclientde_impl.cpp +++ b/runtime/client/src/sys/win/winclientde_impl.cpp @@ -464,7 +464,8 @@ static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, } bOk = false; - if(pSrcData = (uint8*)cis_LockSurface(pSrc, srcPitch)) + pSrcData = static_cast(cis_LockSurface(pSrc, srcPitch)); + if(pSrcData != nullptr) { if(pSrc == pDest) { @@ -473,15 +474,16 @@ static LTRESULT cis_DoDrawSurfaceToSurface(HSURFACE hDest, HSURFACE hSrc, } else { - if(pDestData = (uint8*)cis_LockSurface(pDest, destPitch, true)) + pDestData = static_cast(cis_LockSurface(pDest, destPitch)); + if(pDestData != nullptr) { if(fn(false, pSrcData, pDestData, srcPitch, destPitch, &srcRect, &destRect) == LT_OK) bOk = true; - + cis_UnlockSurface(pDest); } } - + cis_UnlockSurface(pSrc); }