From 38c229a35084ffcaeea38cb9025dca6bcfe84c7d Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sun, 7 Nov 2010 05:51:54 +0000 Subject: [PATCH] GregMiscellaneous: zzogl-pg: Use some of the routines in the Utilities library instead of the copies in ZZOgl. (Which were basically older versions of the same code.) git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@4006 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/zzogl-pg/opengl/GS.h | 10 ++-- plugins/zzogl-pg/opengl/GSmain.cpp | 2 +- plugins/zzogl-pg/opengl/GifTransfer.h | 2 +- .../opengl/Linux/zzogl-pg/zzogl-pg.cbp | 1 + plugins/zzogl-pg/opengl/Profile.cpp | 2 +- plugins/zzogl-pg/opengl/Util.h | 58 ++----------------- plugins/zzogl-pg/opengl/ZZHacks.cpp | 1 + plugins/zzogl-pg/opengl/ZZoglCRTC.cpp | 7 ++- plugins/zzogl-pg/opengl/ZZoglCreate.cpp | 10 ++-- plugins/zzogl-pg/opengl/ZZoglFlush.cpp | 11 +--- plugins/zzogl-pg/opengl/ZZoglMath.h | 17 ++++++ plugins/zzogl-pg/opengl/ZZoglSave.cpp | 1 + plugins/zzogl-pg/opengl/ZZoglShaders.cpp | 9 +-- plugins/zzogl-pg/opengl/ZZoglShoots.cpp | 1 + plugins/zzogl-pg/opengl/ZZoglVB.cpp | 1 + plugins/zzogl-pg/opengl/targets.cpp | 1 + plugins/zzogl-pg/opengl/zerogs.cpp | 1 + 17 files changed, 52 insertions(+), 83 deletions(-) diff --git a/plugins/zzogl-pg/opengl/GS.h b/plugins/zzogl-pg/opengl/GS.h index 3bd2378cf4..4c932d7eb8 100644 --- a/plugins/zzogl-pg/opengl/GS.h +++ b/plugins/zzogl-pg/opengl/GS.h @@ -546,15 +546,15 @@ typedef struct GSClut clut_buffer; int primNext(int inc = 1) { - // Note: ARRAY_SIZE(gsvertex) == 2^n => modulo is replaced by an and instruction - return ((primIndex + inc) % ARRAY_SIZE(gsvertex)); + // Note: ArraySize(gsvertex) == 2^n => modulo is replaced by an and instruction + return ((primIndex + inc) % ArraySize(gsvertex)); } int primPrev(int dec = 1) { - // Note: assert( dec <= ARRAY_SIZE(gsvertex) ); - // Note: ARRAY_SIZE(gsvertex) == 2^n => modulo is replaced by an and instruction - return ((primIndex + (ARRAY_SIZE(gsvertex) - dec)) % ARRAY_SIZE(gsvertex)); + // Note: assert( dec <= ArraySize(gsvertex) ); + // Note: ArraySize(gsvertex) == 2^n => modulo is replaced by an and instruction + return ((primIndex + (ArraySize(gsvertex) - dec)) % ArraySize(gsvertex)); } void setRGBA(u32 r, u32 g, u32 b, u32 a) diff --git a/plugins/zzogl-pg/opengl/GSmain.cpp b/plugins/zzogl-pg/opengl/GSmain.cpp index 539adec6ab..b6bd326cea 100644 --- a/plugins/zzogl-pg/opengl/GSmain.cpp +++ b/plugins/zzogl-pg/opengl/GSmain.cpp @@ -536,7 +536,7 @@ void CALLBACK GSvsync(int interlace) if (--nToNextUpdate <= 0) { u32 d = timeGetTime(); - fFPS = UPDATE_FRAMES * 1000.0f / (float)max(d - dwTime, 1); + fFPS = UPDATE_FRAMES * 1000.0f / (float)max(d - dwTime, (u32)1); dwTime = d; g_nFrame += UPDATE_FRAMES; SetGSTitle(); diff --git a/plugins/zzogl-pg/opengl/GifTransfer.h b/plugins/zzogl-pg/opengl/GifTransfer.h index 4326da4693..533733ed07 100644 --- a/plugins/zzogl-pg/opengl/GifTransfer.h +++ b/plugins/zzogl-pg/opengl/GifTransfer.h @@ -20,9 +20,9 @@ #ifndef GIFTRANSFER_H_INCLUDED #define GIFTRANSFER_H_INCLUDED +#include "Util.h" #include "GS.h" #include "Regs.h" -#include "Util.h" enum GIF_FLG { diff --git a/plugins/zzogl-pg/opengl/Linux/zzogl-pg/zzogl-pg.cbp b/plugins/zzogl-pg/opengl/Linux/zzogl-pg/zzogl-pg.cbp index 814aff372b..db06433750 100644 --- a/plugins/zzogl-pg/opengl/Linux/zzogl-pg/zzogl-pg.cbp +++ b/plugins/zzogl-pg/opengl/Linux/zzogl-pg/zzogl-pg.cbp @@ -62,6 +62,7 @@ + diff --git a/plugins/zzogl-pg/opengl/Profile.cpp b/plugins/zzogl-pg/opengl/Profile.cpp index 20c9c3712f..9e1bd81c34 100644 --- a/plugins/zzogl-pg/opengl/Profile.cpp +++ b/plugins/zzogl-pg/opengl/Profile.cpp @@ -60,7 +60,7 @@ struct DVPROFSTRUCT while (it != listpChild.end()) { - SAFE_DELETE(*it); + safe_delete(*it); ++it; } } diff --git a/plugins/zzogl-pg/opengl/Util.h b/plugins/zzogl-pg/opengl/Util.h index 5fe2871da9..99141b65d3 100644 --- a/plugins/zzogl-pg/opengl/Util.h +++ b/plugins/zzogl-pg/opengl/Util.h @@ -43,7 +43,10 @@ extern HWND GShwnd; #define GSdefs -#include "PS2Edefs.h" + +//Pcsx2Defs is included in Dependencies.h. +#include "Utilities/Dependencies.h" + #include "CRC.h" #include "ZZLog.h" @@ -55,47 +58,10 @@ extern "C" char* CALLBACK PS2EgetLibName(void); #include "ZZoglMath.h" #include "Profile.h" -#include -#include -#include - -extern std::string s_strIniPath; // Air's new (r2361) new constant for ini file path - -#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC) -#include - -// declare linux equivalents -static __forceinline void* pcsx2_aligned_malloc(size_t size, size_t align) -{ - assert(align < 0x10000); - char* p = (char*)malloc(size + align); - int off = 2 + align - ((int)(uptr)(p + 2) % align); - - p += off; - *(u16*)(p - 2) = off; - - return p; -} - -static __forceinline void pcsx2_aligned_free(void* pmem) -{ - if (pmem != NULL) - { - char* p = (char*)pmem; - free(p - (int)*(u16*)(p - 2)); - } -} - -#define _aligned_malloc pcsx2_aligned_malloc -#define _aligned_free pcsx2_aligned_free - -#endif - #include "Utilities/MemcpyFast.h" #define memcpy_amd memcpy_fast -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define min(a,b) (((a) < (b)) ? (a) : (b)) +extern std::string s_strIniPath; // Air's new (r2361) new constant for ini file path typedef struct { @@ -273,21 +239,7 @@ union name \ #define REG_SET_END }; -#ifndef SAFE_DELETE -# define SAFE_DELETE(x) if( (x) != NULL ) { delete (x); (x) = NULL; } -#endif -#ifndef SAFE_DELETE_ARRAY -# define SAFE_DELETE_ARRAY(x) if( (x) != NULL ) { delete[] (x); (x) = NULL; } -#endif -#ifndef SAFE_RELEASE -# define SAFE_RELEASE(x) if( (x) != NULL ) { (x)->Release(); (x) = NULL; } -#endif - #define FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it)) - -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif extern void LoadConfig(); extern void SaveConfig(); diff --git a/plugins/zzogl-pg/opengl/ZZHacks.cpp b/plugins/zzogl-pg/opengl/ZZHacks.cpp index 716e687da4..183f0fa894 100644 --- a/plugins/zzogl-pg/opengl/ZZHacks.cpp +++ b/plugins/zzogl-pg/opengl/ZZHacks.cpp @@ -17,6 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ + #include "Util.h" #include "ZZHacks.h" #include "ZZLog.h" diff --git a/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp b/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp index fdc1c06387..08def2cd7f 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp @@ -21,6 +21,7 @@ // It draw picture direct on screen, so here we have interlacing and frame skipping. //------------------ Includes + #include "Util.h" #include "ZZoglCRTC.h" #include "GLWin.h" #include "ZZoglShaders.h" @@ -814,13 +815,13 @@ inline void AfterRendererAutoresetTargets() if (conf.settings().auto_reset) { s_nResolveCounts[s_nCurResolveIndex] = s_nResolved; - s_nCurResolveIndex = (s_nCurResolveIndex + 1) % ARRAY_SIZE(s_nResolveCounts); + s_nCurResolveIndex = (s_nCurResolveIndex + 1) % ArraySize(s_nResolveCounts); int total = 0; - for (int i = 0; i < ARRAY_SIZE(s_nResolveCounts); ++i) total += s_nResolveCounts[i]; + for (int i = 0; i < ArraySize(s_nResolveCounts); ++i) total += s_nResolveCounts[i]; - if (total / ARRAY_SIZE(s_nResolveCounts) > 3) + if (total / ArraySize(s_nResolveCounts) > 3) { if (s_nLastResolveReset > (int)(fFPS * 8)) { diff --git a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp index 3c1580a9d9..c07c2c26a8 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp @@ -329,7 +329,7 @@ inline bool CreateOpenShadersFile() // test if ps2hw.fx exists char tempstr[255]; char curwd[255]; - getcwd(curwd, ARRAY_SIZE(curwd)); + getcwd(curwd, ArraySize(curwd)); strcpy(tempstr, "/plugins/"); sprintf(EFFECT_NAME, "%sps2hw.fx", tempstr); @@ -798,7 +798,7 @@ void ZZDestroy() if (pvs != NULL) { - for (int i = 0; i < ARRAY_SIZE(pvs); ++i) + for (int i = 0; i < ArraySize(pvs); ++i) { SAFE_RELEASE_PROG(pvs[i]); } @@ -806,7 +806,7 @@ void ZZDestroy() if (ppsRegular != NULL) { - for (int i = 0; i < ARRAY_SIZE(ppsRegular); ++i) + for (int i = 0; i < ArraySize(ppsRegular); ++i) { SAFE_RELEASE_PROG(ppsRegular[i].prog); } @@ -814,7 +814,7 @@ void ZZDestroy() if (ppsTexture != NULL) { - for (int i = 0; i < ARRAY_SIZE(ppsTexture); ++i) + for (int i = 0; i < ArraySize(ppsTexture); ++i) { SAFE_RELEASE_PROG(ppsTexture[i].prog); } @@ -833,7 +833,7 @@ void ZZDestroy() SAFE_RELEASE_PROG(ppsCRTC24[1].prog); SAFE_RELEASE_PROG(ppsOne.prog); - SAFE_DELETE(font_p); + safe_delete(font_p); GLWin.ReleaseContext(); diff --git a/plugins/zzogl-pg/opengl/ZZoglFlush.cpp b/plugins/zzogl-pg/opengl/ZZoglFlush.cpp index 1c573a1ad6..60b2d35c46 100644 --- a/plugins/zzogl-pg/opengl/ZZoglFlush.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglFlush.cpp @@ -304,7 +304,7 @@ void ReloadEffects() { #ifdef ZEROGS_DEVBUILD - for (int i = 0; i < ARRAY_SIZE(ppsTexture); ++i) + for (int i = 0; i < ArraySize(ppsTexture); ++i) { SAFE_RELEASE_PROG(ppsTexture[i].prog); } @@ -2015,15 +2015,6 @@ void SetTexClamping(int context, FRAGMENTSHADER* pfragment) } -// Fixme should be in float4 lib -inline bool equal_vectors(float4 a, float4 b) -{ - if (abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z) + abs(a.w - b.w) < 0.01) - return true; - else - return false; -} - int CheckTexArray[4][2][2][2] = {{{{0, }}}}; void SetTexVariables(int context, FRAGMENTSHADER* pfragment) { diff --git a/plugins/zzogl-pg/opengl/ZZoglMath.h b/plugins/zzogl-pg/opengl/ZZoglMath.h index 2a3fbca45d..2e31aebb90 100644 --- a/plugins/zzogl-pg/opengl/ZZoglMath.h +++ b/plugins/zzogl-pg/opengl/ZZoglMath.h @@ -195,6 +195,15 @@ class Vector4 y = ((color >> 8) & 0xff) / 255.0f; z = ((color >> 16) & 0xff) / 255.0f; } + + bool equal_vectors(const Vector4& v) + { + if (abs(x - v.x) + abs(y - v.y) + abs(z - v.z) + abs(w - v.w) < 0.01) + return true; + else + return false; + } + }; typedef Vector4 float4; @@ -444,6 +453,14 @@ class float4 return float4(_mm_cmple_ps(v1.m, v2.m)); } + bool equal_vectors(const float4& v) + { + if (abs(x - v.x) + abs(y - v.y) + abs(z - v.z) + abs(w - v.w) < 0.01) + return true; + else + return false; + } + // This looked interesting, so I thought I'd include it... template float4 shuffle() const diff --git a/plugins/zzogl-pg/opengl/ZZoglSave.cpp b/plugins/zzogl-pg/opengl/ZZoglSave.cpp index e0b52e232a..b0e2ebc002 100644 --- a/plugins/zzogl-pg/opengl/ZZoglSave.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglSave.cpp @@ -20,6 +20,7 @@ // Save and Load. //------------------ Includes + #include "Util.h" #include "ZZoglVB.h" extern void ZZGSStateReset(); diff --git a/plugins/zzogl-pg/opengl/ZZoglShaders.cpp b/plugins/zzogl-pg/opengl/ZZoglShaders.cpp index d0cc11c815..dfe69c44e6 100644 --- a/plugins/zzogl-pg/opengl/ZZoglShaders.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglShaders.cpp @@ -21,6 +21,7 @@ // ZZogl Shader manipulation functions. //------------------- Includes +#include "Util.h" #include "ZZoglShaders.h" #include "zpipe.h" #include @@ -227,7 +228,7 @@ bool ZZshCreateOpenShadersFile() { // test if ps2hw.fx exists char tempstr[255]; char curwd[255]; - getcwd(curwd, ARRAY_SIZE(curwd)); + getcwd(curwd, ArraySize(curwd)); strcpy(tempstr, "/plugins/"); sprintf(EFFECT_NAME, "%sps2hw.fx", tempstr); @@ -538,7 +539,7 @@ inline bool LoadEffects() } // clear the textures - for(u16 i = 0; i < ARRAY_SIZE(ppsTexture); ++i) { + for(u16 i = 0; i < ArraySize(ppsTexture); ++i) { SAFE_RELEASE_PROG(ppsTexture[i].prog); ppsTexture[i].prog = NULL; } @@ -645,7 +646,7 @@ FRAGMENTSHADER* ZZshLoadShadeEffect(int type, int texfilter, int fog, int testae int index = GET_SHADER_INDEX(type, texfilter, texwrap, fog, s_bWriteDepth, testaem, exactcolor, context, 0); - assert( index < ARRAY_SIZE(ppsTexture) ); + assert( index < ArraySize(ppsTexture) ); FRAGMENTSHADER* pf = ppsTexture+index; if( pbFailed != NULL ) *pbFailed = false; @@ -722,7 +723,7 @@ FRAGMENTSHADER* ZZshLoadShadeEffect(int type, int texfilter, int fog, int testae inline bool LoadEffects() { // clear the textures - for(int i = 0; i < ARRAY_SIZE(ppsTexture); ++i) { + for(int i = 0; i < ArraySize(ppsTexture); ++i) { SAFE_RELEASE_PROG(ppsTexture[i].prog); } diff --git a/plugins/zzogl-pg/opengl/ZZoglShoots.cpp b/plugins/zzogl-pg/opengl/ZZoglShoots.cpp index 09eef0ca9e..af96b974eb 100644 --- a/plugins/zzogl-pg/opengl/ZZoglShoots.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglShoots.cpp @@ -20,6 +20,7 @@ // Texture and avi saving to file functions //------------------ Includes + #include "Util.h" #if defined(_WIN32) # include # include diff --git a/plugins/zzogl-pg/opengl/ZZoglVB.cpp b/plugins/zzogl-pg/opengl/ZZoglVB.cpp index 5545d8f7a7..a1604b2be2 100644 --- a/plugins/zzogl-pg/opengl/ZZoglVB.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglVB.cpp @@ -21,6 +21,7 @@ // VB stands for Visual Buffer, as I think //------------------- Includes + #include "Util.h" #include "targets.h" #include "ZZoglVB.h" #include "GS.h" diff --git a/plugins/zzogl-pg/opengl/targets.cpp b/plugins/zzogl-pg/opengl/targets.cpp index 07a1dbd38a..6ebd8a73ae 100644 --- a/plugins/zzogl-pg/opengl/targets.cpp +++ b/plugins/zzogl-pg/opengl/targets.cpp @@ -1992,6 +1992,7 @@ CMemoryTarget* CMemoryTargetMngr::GetMemoryTarget(const tex0Info& tex0, int forc else { // In case it could occured // realloc would be better but you need to get it from libutilies first + // _aligned_realloc is brought in from ScopedAlloc.h now. --arcum42 _aligned_free(targ->clut); targ->clut = (u8*)_aligned_malloc(clutsize, 16); } diff --git a/plugins/zzogl-pg/opengl/zerogs.cpp b/plugins/zzogl-pg/opengl/zerogs.cpp index f6adfe2a36..26be604e8c 100644 --- a/plugins/zzogl-pg/opengl/zerogs.cpp +++ b/plugins/zzogl-pg/opengl/zerogs.cpp @@ -18,6 +18,7 @@ */ //-------------------------- Includes +#include "Util.h" #include "zerogs.h" #include "ZZoglVB.h"