Skip to content

Commit

Permalink
* Fix Info_RemoveKey() deleting only first key
Browse files Browse the repository at this point in the history
* Made rsqrt hint really work
* Cleanup makefile
* Re-enable sound-mixing asm in MSVC solutions
  • Loading branch information
ec- committed Aug 14, 2023
1 parent 76585ce commit 1b06509
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 72 deletions.
17 changes: 6 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ ifdef MINGW
ifeq ($(ARCH),x86_64)
ARCHEXT = .x64
BASE_CFLAGS += -m64
OPTIMIZE = -O2 -ffast-math -fstrength-reduce
OPTIMIZE = -O2 -ffast-math
endif
ifeq ($(ARCH),x86)
BASE_CFLAGS += -m32
OPTIMIZE = -O2 -march=i586 -mtune=i686 -ffast-math -fstrength-reduce
OPTIMIZE = -O2 -march=i586 -mtune=i686 -ffast-math
endif

SHLIBEXT = dll
Expand Down Expand Up @@ -619,12 +619,12 @@ endif

define DO_CC
$(echo_cmd) "CC $<"
$(Q)$(CC) $(NOTSHLIBCFLAGS) $(CFLAGS) -o $@ -c $<
$(Q)$(CC) $(CFLAGS) -o $@ -c $<
endef

define DO_REND_CC
$(echo_cmd) "REND_CC $<"
$(Q)$(CC) $(RENDCFLAGS) $(CFLAGS) -o $@ -c $<
$(Q)$(CC) $(CFLAGS) $(RENDCFLAGS) -o $@ -c $<
endef

define DO_REF_STR
Expand All @@ -635,12 +635,7 @@ endef

define DO_BOT_CC
$(echo_cmd) "BOT_CC $<"
$(Q)$(CC) $(NOTSHLIBCFLAGS) $(CFLAGS) $(BOTCFLAGS) -DBOTLIB -o $@ -c $<
endef

define DO_SHLIB_CC
$(echo_cmd) "SHLIB_CC $<"
$(Q)$(CC) $(CFLAGS) $(SHLIBCFLAGS) -o $@ -c $<
$(Q)$(CC) $(CFLAGS) $(BOTCFLAGS) -DBOTLIB -o $@ -c $<
endef

define DO_AS
Expand All @@ -650,7 +645,7 @@ endef

define DO_DED_CC
$(echo_cmd) "DED_CC $<"
$(Q)$(CC) $(NOTSHLIBCFLAGS) -DDEDICATED $(CFLAGS) -o $@ -c $<
$(Q)$(CC) $(CFLAGS) -DDEDICATED -o $@ -c $<
endef

define DO_WINDRES
Expand Down
7 changes: 5 additions & 2 deletions code/qcommon/q_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,17 @@ void VectorRotate( const vec3_t in, const vec3_t matrix[3], vec3_t out )
#endif

/*
** float q_rsqrt( float number )
** float Q_rsqrt( float number )
*/
float Q_rsqrt( float number )
{
#ifdef _MSC_SSE2
#if defined(_MSC_SSE2)
float ret;
_mm_store_ss( &ret, _mm_rsqrt_ss( _mm_load_ss( &number ) ) );
return ret;
#elif defined(_GCC_SSE2)
/* writing it this way allows gcc to recognize that rsqrt can be used with -ffast-math */
return 1.0f / sqrtf( number );
#else
floatint_t t;
float x2, y;
Expand Down
4 changes: 3 additions & 1 deletion code/qcommon/q_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if idx64
#ifdef _MSC_VER
#define _MSC_SSE2
#endif // _MSC_VER
#else
#define _GCC_SSE2
#endif
#endif // idx64

#endif // __Q_PLATFORM_H
88 changes: 47 additions & 41 deletions code/qcommon/q_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -1956,46 +1956,52 @@ const char *Info_NextPair( const char *s, char *key, char *value ) {
/*
===================
Info_RemoveKey
return removed character count
===================
*/
int Info_RemoveKey( char *s, const char *key )
{
char *start;
const char *pkey;
int key_len, len;

key_len = (int) strlen( key );

while (1)
{
start = s;
if ( *s == '\\' )
s++;
pkey = s;
while ( *s != '\\' )
{
if ( *s == '\0' )
return 0;
++s;
}
len = (int)(s - pkey);
++s; // skip '\\'

while ( *s != '\\' && *s != '\0' )
++s;

if ( len == key_len && Q_strkey( pkey, key, key_len ) )
{
memmove( start, s, strlen( s ) + 1 ); // remove this part
return (int)(s - start);
}

if ( *s == '\0' )
break;
}

return 0;
}
int Info_RemoveKey( char *s, const char *key )
{
char *start;
const char *pkey;
int key_len, len, ret;

key_len = (int)strlen( key );
ret = 0;

while ( 1 ) {
start = s;
if ( *s == '\\' ) {
++s;
}
pkey = s;
while ( *s != '\\' ) {
if ( *s == '\0' ) {
return ret;
}
++s;
}
len = (int)(s - pkey);
++s; // skip '\\'

while ( *s != '\\' && *s != '\0' ) {
++s;
}

if ( len == key_len && Q_strkey( pkey, key, key_len ) ) {
memmove( start, s, strlen( s ) + 1 ); // remove this part
ret += (int)(s - start);
s = start;
}

if ( *s == '\0' ) {
break;
}

}

return ret;
}


/*
Expand Down Expand Up @@ -2080,13 +2086,13 @@ qboolean Info_SetValueForKey_s( char *s, int slen, const char *key, const char *
}

len1 -= Info_RemoveKey( s, key );
if ( !value || !*value )
if ( value == NULL || *value == '\0' ) {
return qtrue;
}

len2 = Com_sprintf( newi, sizeof( newi ), "\\%s\\%s", key, value );

if ( len1 + len2 >= slen )
{
if ( len1 + len2 >= slen ) {
Com_Printf( S_COLOR_YELLOW "Info string length exceeded for key '%s'\n", key );
return qfalse;
}
Expand Down
8 changes: 5 additions & 3 deletions code/renderer/tr_model_iqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ static void QuatSlerp(const quat_t from, const quat_t _to, float fraction, quat_
out[2] = from[2] * backlerp + to[2] * lerp;
out[3] = from[3] * backlerp + to[3] * lerp;
}


static vec_t QuatNormalize2( const quat_t v, quat_t out) {
float length, ilength;
float length;

length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3];

if (length) {
/* writing it this way allows gcc to recognize that rsqrt can be used */
ilength = 1/(float)sqrt (length);
/* writing it this way allows gcc to recognize that rsqrt can be used with -ffast-math */
const float ilength = 1.0f / sqrtf( length );
/* sqrt(length) = length * (1 / sqrt(length)) */
length *= ilength;
out[0] = v[0]*ilength;
Expand Down
8 changes: 5 additions & 3 deletions code/renderer2/tr_model_iqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ static void QuatSlerp(const quat_t from, const quat_t _to, float fraction, quat_
out[2] = from[2] * backlerp + to[2] * lerp;
out[3] = from[3] * backlerp + to[3] * lerp;
}


static vec_t QuatNormalize2( const quat_t v, quat_t out) {
float length, ilength;
float length;

length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3];

if (length) {
/* writing it this way allows gcc to recognize that rsqrt can be used */
ilength = 1/(float)sqrt (length);
/* writing it this way allows gcc to recognize that rsqrt can be used with -ffast-math */
const float ilength = 1.0f / sqrtf( length );
/* sqrt(length) = length * (1 / sqrt(length)) */
length *= ilength;
out[0] = v[0]*ilength;
Expand Down
8 changes: 5 additions & 3 deletions code/renderervk/tr_model_iqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ static void QuatSlerp(const quat_t from, const quat_t _to, float fraction, quat_
out[2] = from[2] * backlerp + to[2] * lerp;
out[3] = from[3] * backlerp + to[3] * lerp;
}


static vec_t QuatNormalize2( const quat_t v, quat_t out) {
float length, ilength;
float length;

length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3];

if (length) {
/* writing it this way allows gcc to recognize that rsqrt can be used */
ilength = 1/(float)sqrt (length);
/* writing it this way allows gcc to recognize that rsqrt can be used with -ffast-math */
const float ilength = 1.0f / sqrtf( length );
/* sqrt(length) = length * (1 / sqrt(length)) */
length *= ilength;
out[0] = v[0]*ilength;
Expand Down
8 changes: 4 additions & 4 deletions code/win32/msvc2005/quake3e.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\libogg\include;..\..\libvorbis\include;..\..\libcurl\windows\include;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
AssemblerListingLocation="$(IntDir)\"
Expand Down Expand Up @@ -131,7 +131,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\libogg\include;..\..\libvorbis\include;..\..\libcurl\windows\include;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
AssemblerListingLocation="$(IntDir)\"
Expand Down Expand Up @@ -218,7 +218,7 @@
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\libogg\include;..\..\libvorbis\include;..\..\libcurl\windows\include;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_WIN32;NDEBUG;_WINDOWS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_WIN32;NDEBUG;_WINDOWS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
AssemblerListingLocation="$(IntDir)\"
/>
<Tool
Expand Down Expand Up @@ -298,7 +298,7 @@
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\libogg\include;..\..\libvorbis\include;..\..\libcurl\windows\include;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_WIN32;NDEBUG;_WINDOWS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;_WIN32;NDEBUG;_WINDOWS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;_CRT_SECURE_NO_DEPRECATE;$(NOINHERIT)"
AssemblerListingLocation="$(IntDir)\"
/>
<Tool
Expand Down
8 changes: 4 additions & 4 deletions code/win32/msvc2017/quake3e.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\libcurl\windows\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<BrowseInformation>true</BrowseInformation>
Expand All @@ -145,7 +145,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\libcurl\windows\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<BrowseInformation>true</BrowseInformation>
Expand Down Expand Up @@ -190,7 +190,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\libcurl\windows\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level4</WarningLevel>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
Expand All @@ -215,7 +215,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\libcurl\windows\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_WINSOCK_DEPRECATED_NO_WARNINGS;USE_SKIPIDLOGO;USE_CURL;CURL_STATICLIB;USE_OPENGL_API;USE_VULKAN_API;USE_OGG_VORBIS;USE_WIN32_ASM;$(UseWASAPI);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level4</WarningLevel>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput>
Expand Down

0 comments on commit 1b06509

Please sign in to comment.