From 39060e79000126ffb088db6b2ed437412bfc97e2 Mon Sep 17 00:00:00 2001 From: janwas Date: Wed, 19 Oct 2005 20:26:53 +0000 Subject: [PATCH] cinput, ogl_shader, h_mgr, vfs: stomp on warnings ia32, sysdep: add rint() minimap: saw TODO on GetMapSpaceCoords and sped it up by 15% using rintf and precalculating scaleX timer: add indication of how often something was billed (helps measure stuff called an indeterminate number of times) This was SVN commit r2973. --- source/gui/CInput.cpp | 1 + source/gui/MiniMap.cpp | 27 +++++++++++++------------- source/gui/MiniMap.h | 3 --- source/lib/res/file/vfs.cpp | 1 + source/lib/res/graphics/ogl_shader.cpp | 6 +++--- source/lib/res/h_mgr.cpp | 2 ++ source/lib/sysdep/ia32.cpp | 25 +++++++++++++++++++++++- source/lib/sysdep/ia32.h | 5 +++++ source/lib/sysdep/sysdep.cpp | 15 ++++++++++++++ source/lib/sysdep/sysdep.h | 14 +++++++++++++ source/lib/timer.cpp | 3 ++- source/lib/timer.h | 4 ++++ 12 files changed, 84 insertions(+), 22 deletions(-) diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index 850a1bb224..9178d6011b 100755 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -1428,6 +1428,7 @@ int CInput::GetMouseHoveringTextPosition() // Pointer to caption, will come in handy CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting; + UNUSED2(pCaption); // Now get the height of the font. // TODO: Get the real font diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp index 92f117939b..1b98ff21fd 100755 --- a/source/gui/MiniMap.cpp +++ b/source/gui/MiniMap.cpp @@ -22,6 +22,13 @@ bool g_TerrainModified = false; +// used by GetMapSpaceCoords (precalculated as an optimization). +// this was formerly access via inline asm, which required it to be +// static data instead of a class member. that is no longer the case, +// but we leave it because this is slightly more efficient. +static float m_scaleX, m_scaleY; + + static unsigned int ScaleColor(unsigned int color, float x) { unsigned int r = uint(float(color & 0xff) * x); @@ -168,6 +175,9 @@ void CMiniMap::Draw() m_MapSize = m_Terrain->GetVerticesPerSide(); m_TextureSize = round_up_to_pow2(m_MapSize); + m_scaleX = float(m_Width) / float(m_MapSize - 1); + m_scaleY = float(m_Height) / float(m_MapSize - 1); + if(!m_TerrainTexture) CreateTextures(); @@ -422,23 +432,12 @@ void CMiniMap::Destroy() } } -TIMER_ADD_CLIENT(tc_minimap_getmapspacecoords); - -/* -* Calefaction -* TODO: Speed this up. There has to be some mathematical way to make -* this more efficient. This works for now. -*/ CVector2D CMiniMap::GetMapSpaceCoords(CVector3D worldPos) { - TIMER_ACCRUE(tc_minimap_getmapspacecoords); - - u32 x = (u32)(worldPos.X / CELL_SIZE); + float x = rintf(worldPos.X / CELL_SIZE); + float y = rintf(worldPos.Z / CELL_SIZE); // Entity's Z coordinate is really its longitudinal coordinate on the terrain - u32 y = (u32)(worldPos.Z / CELL_SIZE); // Calculate map space scale - float scaleX = float(m_Width) / float(m_MapSize - 1); - float scaleY = float(m_Height) / float(m_MapSize - 1); - return CVector2D(float(x) * scaleX, float(y) * scaleY); + return CVector2D(x * m_scaleX, y * m_scaleY); } diff --git a/source/gui/MiniMap.h b/source/gui/MiniMap.h index 43ddae672f..86355f0562 100755 --- a/source/gui/MiniMap.h +++ b/source/gui/MiniMap.h @@ -58,9 +58,6 @@ protected: // map size u32 m_MapSize; - // used by GetMapSpaceCoords (precalculated as an optimization) - float m_scaleX, m_scaleY; - // texture size u32 m_TextureSize; diff --git a/source/lib/res/file/vfs.cpp b/source/lib/res/file/vfs.cpp index 38e50d9120..279d93a0ba 100755 --- a/source/lib/res/file/vfs.cpp +++ b/source/lib/res/file/vfs.cpp @@ -142,6 +142,7 @@ static int VDir_validate(const VDir* vd) if(vd->filter && !isprint(vd->filter[0])) return -2; #endif + UNUSED2(vd); return 0; } diff --git a/source/lib/res/graphics/ogl_shader.cpp b/source/lib/res/graphics/ogl_shader.cpp index 5c99f528fe..543c46fd27 100644 --- a/source/lib/res/graphics/ogl_shader.cpp +++ b/source/lib/res/graphics/ogl_shader.cpp @@ -162,7 +162,7 @@ static void Ogl_Shader_dtor(Ogl_Shader* shdr) } } -static int Ogl_Shader_validate(const Ogl_Shader* shdr) +static int Ogl_Shader_validate(const Ogl_Shader* UNUSED(shdr)) { // TODO return 0; @@ -225,7 +225,7 @@ static void Ogl_Program_init(Ogl_Program* UNUSED(p), va_list UNUSED(args)) // Load the shader associated with one Shader element, // and attach it to our program object. static int do_load_shader( - Ogl_Program* p, const char* filename, Handle h, + Ogl_Program* p, const char* filename, Handle UNUSED(h), const CXeromyces& XeroFile, const XMBElement& Shader) { #define AT(x) int at_##x = XeroFile.getAttributeID(#x) @@ -379,7 +379,7 @@ static void Ogl_Program_dtor(Ogl_Program* p) } } -static int Ogl_Program_validate(const Ogl_Program* p) +static int Ogl_Program_validate(const Ogl_Program* UNUSED(p)) { // TODO return 0; diff --git a/source/lib/res/h_mgr.cpp b/source/lib/res/h_mgr.cpp index 1403f158b8..4d46930237 100755 --- a/source/lib/res/h_mgr.cpp +++ b/source/lib/res/h_mgr.cpp @@ -481,6 +481,8 @@ static void warn_if_invalid(HDATA* hd) if(*p != 0) debug_warn("handle user data was overrun!"); } +#else + UNUSED2(hd); #endif } diff --git a/source/lib/sysdep/ia32.cpp b/source/lib/sysdep/ia32.cpp index f5ee3e21b7..11609dd444 100755 --- a/source/lib/sysdep/ia32.cpp +++ b/source/lib/sysdep/ia32.cpp @@ -40,9 +40,10 @@ #error ia32.cpp needs inline assembly support! #endif +#if HAVE_MS_ASM + // replace pathetic MS libc implementation. // not needed on non-Win32, so don't bother converting from MS inline asm. -#if HAVE_MS_ASM double _ceil(double f) { UNUSED2(f); // avoid bogus warning @@ -57,6 +58,28 @@ __asm } return r; } + + +// note: declspec naked is significantly faster: it avoids redundant +// store/load, even though it prevents inlining. + +// if on 64-bit systems, [esp+4] will have to change +cassert(sizeof(int)*CHAR_BIT == 32); + +__declspec(naked) float ia32_rintf(float) +{ + __asm fld [esp+4] + __asm frndint + __asm ret +} + +inline double ia32_rint(double) +{ + __asm fld [esp+4] + __asm frndint + __asm ret +} + #endif diff --git a/source/lib/sysdep/ia32.h b/source/lib/sysdep/ia32.h index 1daacb1da6..b2a32b9563 100755 --- a/source/lib/sysdep/ia32.h +++ b/source/lib/sysdep/ia32.h @@ -34,8 +34,13 @@ extern "C" { // call before any of the following functions extern void ia32_init(); + extern double _ceil(double); +extern float ia32_rintf(float f); +extern double ia32_rint(double f); + + extern u64 rdtsc(void); diff --git a/source/lib/sysdep/sysdep.cpp b/source/lib/sysdep/sysdep.cpp index d8c533210e..091b0970b8 100755 --- a/source/lib/sysdep/sysdep.cpp +++ b/source/lib/sysdep/sysdep.cpp @@ -35,8 +35,23 @@ float fmaxf(float a, float b) return (a > b)? a : b; } + +#ifndef rint + +inline float rintf(float f) +{ + return (float)(int)f; +} + +inline double rint(double d) +{ + return (double)(int)d; +} + #endif +#endif // !HAVE_C99 + void memcpy2(void* dst, const void* src, size_t nbytes) { diff --git a/source/lib/sysdep/sysdep.h b/source/lib/sysdep/sysdep.h index b1b860e932..4aee823ef9 100755 --- a/source/lib/sysdep/sysdep.h +++ b/source/lib/sysdep/sysdep.h @@ -39,6 +39,19 @@ extern int vsnprintf2(char* buffer, size_t count, const char* format, va_list ar extern void* alloca(size_t size); #endif +// rint: round float to nearest integer. +// provided by C99, otherwise: +#if !HAVE_C99 +// .. implemented on IA-32; define as macro to avoid jmp overhead +# if CPU_IA32 +# define rintf ia32_rintf +# define rint ia32_rint +# endif +// .. forward-declare either the IA-32 version or portable C emulation. +extern float rintf(float f); +extern double rint(double d); +#endif + // finite: return 0 iff the given double is infinite or NaN. #if OS_WIN # define finite _finite @@ -71,6 +84,7 @@ extern void* alloca(size_t size); #endif + // // output // diff --git a/source/lib/timer.cpp b/source/lib/timer.cpp index bde3d5931b..8f89d032a4 100755 --- a/source/lib/timer.cpp +++ b/source/lib/timer.cpp @@ -278,6 +278,7 @@ TimerClient* timer_add_client(TimerClient* tc, const char* description) void timer_bill_client(TimerClient* tc, double dt) { tc->sum += dt; + tc->num_calls++; } @@ -305,7 +306,7 @@ void timer_display_client_totals() else if(sum > 1e-3) scale = 1e3, unit = "ms"; - debug_printf(" %s: %g %s\n", tc->description, sum*scale, unit); + debug_printf(" %s: %g %s (%dx)\n", tc->description, sum*scale, unit, tc->num_calls); } debug_printf("-----------------------------------------------------\n"); diff --git a/source/lib/timer.h b/source/lib/timer.h index 093a75e504..72f6f7f1a8 100755 --- a/source/lib/timer.h +++ b/source/lib/timer.h @@ -62,6 +62,10 @@ struct TimerClient const char* description; TimerClient* next; + + // how often timer_bill_client was called (helps measure relative + // performance of something that is done indeterminately often). + uint num_calls; };