diff --git a/source/graphics/LightEnv.cpp b/source/graphics/LightEnv.cpp index 0eeec93dfb..abf942a467 100644 --- a/source/graphics/LightEnv.cpp +++ b/source/graphics/LightEnv.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : CLightEnv implementation * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h index 18325b7915..858d476ca7 100644 --- a/source/graphics/LightEnv.h +++ b/source/graphics/LightEnv.h @@ -5,7 +5,7 @@ * Description : CLightEnv, a class describing the current lights * * @author Rich Cross - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/graphics/scripting/JSInterface_LightEnv.cpp b/source/graphics/scripting/JSInterface_LightEnv.cpp index f2e8721079..517d002a6f 100644 --- a/source/graphics/scripting/JSInterface_LightEnv.cpp +++ b/source/graphics/scripting/JSInterface_LightEnv.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Provide the LightEnv object type for JavaScript * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/graphics/scripting/JSInterface_LightEnv.h b/source/graphics/scripting/JSInterface_LightEnv.h index 55b088f3b8..61d13c70be 100644 --- a/source/graphics/scripting/JSInterface_LightEnv.h +++ b/source/graphics/scripting/JSInterface_LightEnv.h @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Provide the LightEnv object type for JavaScript * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/lib/allocators.cpp b/source/lib/allocators.cpp index ede24fa397..96107f0986 100644 --- a/source/lib/allocators.cpp +++ b/source/lib/allocators.cpp @@ -62,6 +62,14 @@ static inline LibError LibError_from_mmap(void* ret, bool warn_if_failed = true) return LibError_from_errno(warn_if_failed); } +// "anonymous" effectively means mapping /dev/zero, but is more efficient. +// MAP_ANONYMOUS is not in SUSv3, but is a very common extension. +// unfortunately, MacOS X only defines MAP_ANON, which Solaris says is +// deprecated. workaround there: define MAP_ANONYMOUS in terms of MAP_ANON. +#ifndef MAP_ANONYMOUS +# define MAP_ANONYMOUS MAP_ANON +#endif + static const int mmap_flags = MAP_PRIVATE|MAP_ANONYMOUS; static LibError mem_reserve(size_t size, u8** pp) diff --git a/source/lib/config.h b/source/lib/config.h index 644d3e28d5..ad2ac0d404 100644 --- a/source/lib/config.h +++ b/source/lib/config.h @@ -48,6 +48,13 @@ # endif #endif +// (only applicable if CPU_IA32) 64-bit values will be returned in EDX:EAX. +// this chiefly affects ia32_rdtsc. if not set, a safer but slower fallback +// will be used that doesn't assume anything about return convention. +#ifndef CONFIG_RETURN64_EDX_EAX +# define CONFIG_RETURN64_EDX_EAX 1 +#endif + // this enables/disables the actual checking done by OverrunProtector-s // (quite slow, entailing mprotect() before/after each access). // define to 1 here or in the relevant module if you suspect mem corruption. diff --git a/source/lib/ogl.cpp b/source/lib/ogl.cpp index 282f9cc3dc..37df6e5710 100644 --- a/source/lib/ogl.cpp +++ b/source/lib/ogl.cpp @@ -332,8 +332,8 @@ void oglSquelchError(GLenum err_to_ignore) // feature and limit detect //---------------------------------------------------------------------------- -int ogl_max_tex_size = -1; // [pixels] -int ogl_max_tex_units = -1; // limit on GL_TEXTUREn +GLint ogl_max_tex_size = -1; // [pixels] +GLint ogl_max_tex_units = -1; // limit on GL_TEXTUREn // set sysdep/gfx.h gfx_card and gfx_drv_ver. called by gfx_detect. diff --git a/source/lib/ogl.h b/source/lib/ogl.h index 4954969f56..0f819a941d 100644 --- a/source/lib/ogl.h +++ b/source/lib/ogl.h @@ -136,8 +136,8 @@ extern const char* oglExtList(void); // implementation limits / feature detect // -extern int ogl_max_tex_size; /// [pixels] -extern int ogl_max_tex_units; /// limit on GL_TEXTUREn +extern GLint ogl_max_tex_size; /// [pixels] +extern GLint ogl_max_tex_units; /// limit on GL_TEXTUREn /** * set sysdep/gfx.h gfx_card and gfx_drv_ver. called by gfx_detect. diff --git a/source/lib/posix.h b/source/lib/posix.h index 37be0a127a..77322c5543 100644 --- a/source/lib/posix.h +++ b/source/lib/posix.h @@ -82,6 +82,8 @@ need only be renamed (e.g. _open, _stat). #include #include +#include + #include #include #include diff --git a/source/lib/sysdep/ia32.cpp b/source/lib/sysdep/ia32.cpp index feafd539d3..668df0ab43 100644 --- a/source/lib/sysdep/ia32.cpp +++ b/source/lib/sysdep/ia32.cpp @@ -175,13 +175,12 @@ __asm{ //----------------------------------------------------------------------------- -// rationale: this function should return its output (instead of setting -// out params) to simplify its callers. it is written in inline asm -// (instead of moving to ia32.asm) to insulate from changing compiler -// calling conventions. -// MSC, ICC and GCC currently return 64 bits in edx:eax, which even -// matches rdtsc output, but we play it safe and return a temporary. -u64 ia32_rdtsc() +// this RDTSC implementation writes edx:eax to a temporary and returns that. +// rationale: this insulates against changing compiler calling conventions, +// at the cost of some efficiency. +// use ia32_rdtsc_edx_eax instead if the return convention is known to be +// edx:eax (should be the case on all 32-bit x86). +u64 ia32_rdtsc_safe() { u64 c; #if HAVE_MS_ASM @@ -193,11 +192,13 @@ __asm mov dword ptr [c+4], edx } #elif HAVE_GNU_ASM + // note: we save+restore EBX to avoid xcode complaining about a + // "PIC register" being clobbered, whatever that means. __asm__ __volatile__ ( - "cpuid; rdtsc" + "pushl %%ebx; cpuid; popl %%ebx; rdtsc" : "=A" (c) : /* no input */ - : "ebx", "ecx" /* cpuid clobbers ebx and ecx */); + : "ecx" /* cpuid clobbers eax..edx, but the rest are covered */); #endif return c; } diff --git a/source/lib/sysdep/ia32.h b/source/lib/sysdep/ia32.h index f5f292cf55..2abe43e6a3 100644 --- a/source/lib/sysdep/ia32.h +++ b/source/lib/sysdep/ia32.h @@ -89,7 +89,13 @@ extern void* ia32_memcpy(void* dst, const void* src, size_t nbytes); // asm extern uint ia32_control87(uint new_val, uint mask); // asm -extern u64 ia32_rdtsc(void); +extern u64 ia32_rdtsc_edx_eax(void); +extern u64 ia32_rdtsc_safe(void); +#if CONFIG_RETURN64_EDX_EAX +# define ia32_rdtsc ia32_rdtsc_edx_eax +#else +# define ia32_rdtsc ia32_rdtsc_safe +#endif extern void ia32_debug_break(void); diff --git a/source/lib/sysdep/ia32_asm.asm b/source/lib/sysdep/ia32_asm.asm index 5fda89e443..4ad8cc001b 100644 --- a/source/lib/sysdep/ia32_asm.asm +++ b/source/lib/sysdep/ia32_asm.asm @@ -178,6 +178,25 @@ sym(ia32_fpclassifyf): ; misc ;------------------------------------------------------------------------------- +; rationale: the common return convention for 64-bit values is in edx:eax. +; with inline asm, we'd have to MOV data to a temporary and return that; +; this is less efficient (-> important for low-overhead profiling) than +; making use of the convention. +; +; however, speed is not the main reason for providing this routine. +; xcode complains about CPUID clobbering ebx, so we use external asm +; where possible (IA-32 CPUs). +; +; extern "C" u64 ia32_rdtsc_edx_eax() +global sym(ia32_rdtsc_edx_eax) +sym(ia32_rdtsc_edx_eax): + push ebx + cpuid + pop ebx + rdtsc + ret + + ; write the current execution state (e.g. all register values) into ; (Win32::CONTEXT*)pcontext (defined as void* to avoid dependency). ; optimized for size; this must be straight asm because __declspec(naked) diff --git a/source/lib/sysdep/sysdep.h b/source/lib/sysdep/sysdep.h index 8bbe6c086b..20f989c0c3 100644 --- a/source/lib/sysdep/sysdep.h +++ b/source/lib/sysdep/sysdep.h @@ -127,14 +127,12 @@ extern void* alloca(size_t size); # endif # define isnan(d) (fpclassify(d) == FP_NAN) +# define isfinite(d) ((fpclassify(d) & (FP_NORMAL|FP_ZERO)) != 0) +# define isinf(d) (fpclassify(d) == FP_NAN|FP_NORMAL) +# define isnormal(d) (fpclassify(d) == FP_NORMAL) +//# define signbit #endif -// finite: return 0 iff the given double is infinite or NaN. -#if OS_WIN -# define finite _finite -#else -# define finite __finite -#endif // C99 restrict // .. for some reason, g++-3.3 claims to support C99 (according to diff --git a/source/lib/timer.cpp b/source/lib/timer.cpp index 175f3721aa..bd464f940e 100644 --- a/source/lib/timer.cpp +++ b/source/lib/timer.cpp @@ -62,7 +62,7 @@ double get_time() gettimeofday(&cur, 0); t = (cur.tv_sec - start.tv_sec) + (cur.tv_usec - start.tv_usec)*1e-6; #else -#error "get_time: add timer implementation for this platform!" +# error "get_time: add timer implementation for this platform!" #endif // make sure time is monotonic (never goes backwards) diff --git a/source/maths/Brush.cpp b/source/maths/Brush.cpp index ce2ee84d9f..01db0d0420 100644 --- a/source/maths/Brush.cpp +++ b/source/maths/Brush.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Implementation of CBrush, a class representing a convex object * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/maths/Brush.h b/source/maths/Brush.h index d853311682..522b1f05d0 100644 --- a/source/maths/Brush.h +++ b/source/maths/Brush.h @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : CBrush, a class representing a convex object * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/FixedFunctionModelRenderer.cpp b/source/renderer/FixedFunctionModelRenderer.cpp index 2c69baaae2..fc259c2704 100644 --- a/source/renderer/FixedFunctionModelRenderer.cpp +++ b/source/renderer/FixedFunctionModelRenderer.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Implementation of FixedFunctionModelRenderer * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/FixedFunctionModelRenderer.h b/source/renderer/FixedFunctionModelRenderer.h index 5745633c62..baaa236c3b 100644 --- a/source/renderer/FixedFunctionModelRenderer.h +++ b/source/renderer/FixedFunctionModelRenderer.h @@ -5,7 +5,7 @@ * Description : ModelVertexRenderer that uses only fixed function pipeline * : to render animated models. * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/HWLightingModelRenderer.cpp b/source/renderer/HWLightingModelRenderer.cpp index 9bfb3e435c..f01fed3d89 100644 --- a/source/renderer/HWLightingModelRenderer.cpp +++ b/source/renderer/HWLightingModelRenderer.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Implementation of HWLightingModelRenderer * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/HWLightingModelRenderer.h b/source/renderer/HWLightingModelRenderer.h index f188a907c5..dbe4548d6b 100644 --- a/source/renderer/HWLightingModelRenderer.h +++ b/source/renderer/HWLightingModelRenderer.h @@ -5,7 +5,7 @@ * Description : ModelVertexRenderer that transforms models on the CPU * : but performs lighting in a vertex shader. * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/InstancingModelRenderer.cpp b/source/renderer/InstancingModelRenderer.cpp index 9456134966..46d1bd39da 100644 --- a/source/renderer/InstancingModelRenderer.cpp +++ b/source/renderer/InstancingModelRenderer.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Implementation of InstancingModelRenderer * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/InstancingModelRenderer.h b/source/renderer/InstancingModelRenderer.h index 352dde075a..c02d5c1f33 100644 --- a/source/renderer/InstancingModelRenderer.h +++ b/source/renderer/InstancingModelRenderer.h @@ -5,7 +5,7 @@ * Description : Special ModelVertexRender that only works for non-animated * : models, but is very fast for instanced models. * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/ModelRenderer.cpp b/source/renderer/ModelRenderer.cpp index 8ab617a462..c4edf63494 100644 --- a/source/renderer/ModelRenderer.cpp +++ b/source/renderer/ModelRenderer.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Implementation of ModelRenderer and BatchModelRenderer * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/ModelRenderer.h b/source/renderer/ModelRenderer.h index 59e61678e2..58a00596dc 100644 --- a/source/renderer/ModelRenderer.h +++ b/source/renderer/ModelRenderer.h @@ -6,7 +6,7 @@ * : that manages a per-frame list of submitted models, * : as well as simple helper classes. * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/ModelVertexRenderer.h b/source/renderer/ModelVertexRenderer.h index 9b48caf8c6..0951843197 100644 --- a/source/renderer/ModelVertexRenderer.h +++ b/source/renderer/ModelVertexRenderer.h @@ -5,7 +5,7 @@ * Description : Definition of ModelVertexRenderer, the abstract base class * : for model vertex transformation implementations. * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/PlayerRenderer.cpp b/source/renderer/PlayerRenderer.cpp index ff43c29be3..91d319b2c5 100644 --- a/source/renderer/PlayerRenderer.cpp +++ b/source/renderer/PlayerRenderer.cpp @@ -5,7 +5,7 @@ * Description : Implementation of player colour RenderModifiers. * * @author John M. Mena - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/PlayerRenderer.h b/source/renderer/PlayerRenderer.h index 7a23b27772..63bc37b6fb 100644 --- a/source/renderer/PlayerRenderer.h +++ b/source/renderer/PlayerRenderer.h @@ -6,7 +6,7 @@ * : with e.g. FixedFunctionModelRenderer * * @author John M. Mena - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/RenderModifiers.cpp b/source/renderer/RenderModifiers.cpp index 03c6acc21e..5b96e227b0 100644 --- a/source/renderer/RenderModifiers.cpp +++ b/source/renderer/RenderModifiers.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Implementation of common RenderModifiers * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/RenderModifiers.h b/source/renderer/RenderModifiers.h index ce7e60b30b..f878ea362b 100644 --- a/source/renderer/RenderModifiers.h +++ b/source/renderer/RenderModifiers.h @@ -6,7 +6,7 @@ * : of some ModelRenderers. This file defines some common * : RenderModifiers in addition to the base class. * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index 8315fdbe6b..8651ccc271 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Shadow mapping related texture and matrix management * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/ShadowMap.h b/source/renderer/ShadowMap.h index a87ca51162..ad0d72a5f8 100644 --- a/source/renderer/ShadowMap.h +++ b/source/renderer/ShadowMap.h @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Shadow mapping related texture and matrix management * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 3a88b41336..80f83aa5fb 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -5,7 +5,7 @@ * Description : Terrain rendering (everything related to patches and * : water) is encapsulated in TerrainRenderer * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/TerrainRenderer.h b/source/renderer/TerrainRenderer.h index e29c7d4701..ec8508409b 100644 --- a/source/renderer/TerrainRenderer.h +++ b/source/renderer/TerrainRenderer.h @@ -5,7 +5,7 @@ * Description : Terrain rendering (everything related to patches and * : water) is encapsulated in TerrainRenderer * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/TransparencyRenderer.cpp b/source/renderer/TransparencyRenderer.cpp index 165bc28ca7..849dd9766f 100644 --- a/source/renderer/TransparencyRenderer.cpp +++ b/source/renderer/TransparencyRenderer.cpp @@ -7,7 +7,7 @@ * : rendering. * * @author Rich Cross - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/TransparencyRenderer.h b/source/renderer/TransparencyRenderer.h index 3b163f411e..ef7cd86598 100644 --- a/source/renderer/TransparencyRenderer.h +++ b/source/renderer/TransparencyRenderer.h @@ -7,7 +7,7 @@ * : rendering. * * @author Rich Cross - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/WaterManager.cpp b/source/renderer/WaterManager.cpp index 3d8e176391..e315938f31 100644 --- a/source/renderer/WaterManager.cpp +++ b/source/renderer/WaterManager.cpp @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Water settings (speed, height) and texture management * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/renderer/WaterManager.h b/source/renderer/WaterManager.h index 4158b4218e..9881822f2a 100644 --- a/source/renderer/WaterManager.h +++ b/source/renderer/WaterManager.h @@ -4,7 +4,7 @@ * Project : Pyrogenesis * Description : Water settings (speed, height) and texture management * - * @author Nicolai Hähnle + * @author Nicolai Haehnle * ========================================================================= */ diff --git a/source/scripting/JSConversions.cpp b/source/scripting/JSConversions.cpp index 47458b621d..5b215de125 100644 --- a/source/scripting/JSConversions.cpp +++ b/source/scripting/JSConversions.cpp @@ -6,7 +6,7 @@ #include "ps/Parser.h" #include "ps/Player.h" #include "simulation/EntityTemplate.h" -#include "lib/sysdep/sysdep.h" // finite +#include "lib/sysdep/sysdep.h" // isfinite #include @@ -151,7 +151,7 @@ template<> jsval ToJSVal( double& Native ) template<> bool ToPrimitive( JSContext* cx, jsval v, double& Storage ) { JSBool ok = JS_ValueToNumber(cx, v, &Storage); - if (ok == JS_FALSE || !finite( Storage ) ) + if (ok == JS_FALSE || !isfinite( Storage ) ) return false; return true; } diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index 94dec2936f..bd5024f216 100644 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -340,7 +340,7 @@ double ScriptingHost::ValueToDouble(const jsval value) JSBool ok = JS_ValueToNumber(m_Context, value, &d); - if (ok == JS_FALSE || !finite(d)) + if (ok == JS_FALSE || !isfinite(d)) throw PSERROR_Scripting_ConversionFailed(); return d; diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 403c9458ff..bf54b3f283 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -60,7 +60,7 @@ float CEntity::processChooseMovement( float distance ) // TODO: the animation code requires unicode for now. will be changed to // 8bit later (for consistency; note that filenames etc. need not be // unicode), so remove this then. - const CStrW u_anim_name = anim_name; + const CStrW u_anim_name(anim_name); if ( m_actor ) {