Skip to content

Commit

Permalink
Wrapper for version constants to lower impact on build speed in case …
Browse files Browse the repository at this point in the history
…of each-time rebuilding version.c
  • Loading branch information
T-Maxxx committed Jun 5, 2017
1 parent fb80fc6 commit c481dca
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 27 deletions.
15 changes: 11 additions & 4 deletions makefile2
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ tomcrypt:
# A rule to make bot library.
botlib:
@echo sh $@
# What is your OS, Appveyor? Fine, Windows_NT
# What is current build command?
@echo Current lib build command:
ifeq ($(OS),Windows_NT)
@cmd.exe /C "@cd $(SRC_DIR)/$@ && @comp.cmd"
else
Expand All @@ -143,11 +140,21 @@ endif

###############################
# A rule to link server binary.
$(TARGET): $(OS_OBJ) $(C_OBJ) $(ZLIB_OBJ) $(ASSETS_OBJ) $(ASM_OBJ)
$(TARGET): $(OS_OBJ) $(C_OBJ) $(ZLIB_OBJ) $(ASSETS_OBJ) $(ASM_OBJ) obj/version.o
@echo $(CC) $@
# CFLAGS for compiler, LFLAGS for linker.
@$(CC) $(LFLAGS) -o $@ $^ $(RESOURCE_FILE) $(LLIBS)

################################
# A rule to make version module.
obj/version.o: src/version/version.c FORCE
@echo $(CC) $@
@$(CC) -c -o $@ $<

############################################
# An empty rule to force rebuild other rule.
FORCE:

#####################################
# A rule to build common server code.
# -march=nocona
Expand Down
6 changes: 3 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,12 @@ static void Com_InitCvars( void ){
com_fixedtime = Cvar_RegisterInt("fixedtime", 0, 0, 1000, 0x80, "Use a fixed time rate for each frame");
com_maxFrameTime = Cvar_RegisterInt("com_maxFrameTime", 100, 50, 1000, 0, "Time slows down if a frame takes longer than this many milliseconds");
com_animCheck = Cvar_RegisterBool("com_animCheck", qfalse, 0, "Check anim tree");
s = va("%s %s %s build %i %s", GAME_STRING,Q3_VERSION,PLATFORM_STRING, BUILD_NUMBER, __DATE__);
s = va("%s %s %s build %i %s", GAME_STRING,Q3_VERSION,PLATFORM_STRING, Sys_GetBuild(), __DATE__);

com_version = Cvar_RegisterString ("version", s, CVAR_ROM | CVAR_SERVERINFO , "Game version");
com_shortversion = Cvar_RegisterString ("shortversion", Q3_VERSION, CVAR_ROM | CVAR_SERVERINFO , "Short game version");

Cvar_RegisterString ("build", va("%i", BUILD_NUMBER), CVAR_ROM | CVAR_SERVERINFO , "");
Cvar_RegisterString ("build", va("%i", Sys_GetBuild()), CVAR_ROM | CVAR_SERVERINFO , "");
com_useFastfiles = Cvar_RegisterBool ("useFastFiles", qtrue, 16, "Enables loading data from fast files");
//MasterServer
//AuthServer
Expand Down Expand Up @@ -792,7 +792,7 @@ void Com_Init(char* commandLine){
if(setjmp(*abortframe)){
Sys_Error(va("Error during Initialization:\n%s\n", com_errorMessage));
}
Com_Printf("%s %s %s build %i %s\n", GAME_STRING,Q3_VERSION,PLATFORM_STRING, BUILD_NUMBER, __DATE__);
Com_Printf("%s %s %s build %i %s\n", GAME_STRING,Q3_VERSION,PLATFORM_STRING, Sys_GetBuild(), __DATE__);


Cbuf_Init();
Expand Down
4 changes: 1 addition & 3 deletions src/net_game_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@

#define PORT_SERVER 28960

#define PROTOCOL_VERSION (unsigned int)(SYS_COMMONVERSION + 0.00001)

#define COD4X_SUBVERSION STRINGIFY(SYS_COMMONVERSION)
#define PROTOCOL_VERSION (unsigned int)(Sys_GetCommonVersion() + 0.00001)

#define LEGACY_PROTOCOL_VERSION 6

Expand Down
8 changes: 4 additions & 4 deletions src/sec_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,13 @@ void Sec_Update( qboolean getbasefiles ){
Com_Printf("\n-----------------------------\n");
Com_Printf(" CoD4X Auto Update\n");
Com_Printf(" Current version: %g\n", SEC_VERSION);
Com_Printf(" Current subversion: %g\n", SYS_COMMONVERSION);
Com_Printf(" Current build: %d\n", BUILD_NUMBER);
Com_Printf(" Current subversion: %g\n", Sys_GetCommonVersion());
Com_Printf(" Current build: %d\n", Sys_GetBuild());
Com_Printf("-----------------------------\n\n");

Sec_SetupPaths();

Com_sprintf(buff, sizeof(buff), UPDATE_SERVER_NAME "?mode=11&os=" OS_STRING "&ver=%g", SYS_COMMONVERSION);
Com_sprintf(buff, sizeof(buff), UPDATE_SERVER_NAME "?mode=11&os=" OS_STRING "&ver=%g", Sys_GetCommonVersion());

filetransferobj = FileDownloadRequest( buff );

Expand Down Expand Up @@ -742,7 +742,7 @@ void Sec_Update( qboolean getbasefiles ){
}
Q_strncpyz(version, ptr +9, sizeof(version));

int l1 = sscanf(STRINGIFY(SYS_COMMONVERSION), "%d.%d", &currentversion.major, &currentversion.minor);
int l1 = sscanf(Sys_GetCommonVersionString(), "%d.%d", &currentversion.major, &currentversion.minor);
int l2 = sscanf(version, "%d.%d", &newversion.major, &newversion.minor);

if(l1 != 2 || l2 != 2)
Expand Down
2 changes: 1 addition & 1 deletion src/sec_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct sec_file_s{


#define SEC_UPDATE_DOWNLOAD(baseurl, qpath) "%s%s", baseurl, qpath
#define SEC_UPDATE_GETVERSION "/?ver=%g&os=%s&build=%d&type=%c", SEC_VERSION, OS_STRING, BUILD_NUMBER, SEC_TYPE
#define SEC_UPDATE_GETVERSION "/?ver=%g&os=%s&build=%d&type=%c", SEC_VERSION, OS_STRING, Sys_GetBuild(), SEC_TYPE

#define UPDATE_SERVER_NAME "http://cod4update.cod4x.me/svupdate/"

Expand Down
4 changes: 2 additions & 2 deletions src/sv_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ __optimize3 __regparm1 void SV_DirectConnect( netadr_t *from ) {
char* xversion;

xversion = Info_ValueForKey( userinfo, "xver");
if(Q_stricmp(xversion, COD4X_SUBVERSION) && version > 6)
if(Q_stricmp(xversion, Sys_GetCommonVersionString()) && version > 6)
{
NET_OutOfBandPrint( NS_SERVER, from, "error\nBad subversion. Server expects subversion %s but client is %s\n", COD4X_SUBVERSION, xversion );
NET_OutOfBandPrint( NS_SERVER, from, "error\nBad subversion. Server expects subversion %s but client is %s\n", Sys_GetCommonVersionString(), xversion );
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ __optimize3 __regparm1 void SVC_Info( netadr_t *from ) {
Info_SetValueForKey( infostring, "sv_maxclients", va("%i", sv_maxclients->integer - sv_privateClients->integer ) );
Info_SetValueForKey( infostring, "gametype", sv_g_gametype->string );
Info_SetValueForKey( infostring, "pure", va("%i", sv_pure->boolean ) );
Info_SetValueForKey( infostring, "build", va("%i", BUILD_NUMBER));
Info_SetValueForKey( infostring, "build", va("%i", Sys_GetBuild()));
Info_SetValueForKey( infostring, "shortversion", Q3_VERSION );

if(*sv_password->string)
Expand Down Expand Up @@ -1210,7 +1210,7 @@ void SVC_SourceEngineQuery_WriteInfo( msg_t* msg, const char* challengeStr, qboo
if(masterserver)
{
MSG_WriteLong( msg, psvs.masterServer_id);
MSG_WriteLong( msg, BUILD_NUMBER);
MSG_WriteLong( msg, Sys_GetBuild());
MSG_WriteString( msg, masterServerSecret);

}
Expand Down
5 changes: 1 addition & 4 deletions src/sys_cod4defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@

#define GAME_STRING "CoD4 X"

#include "version.h"
#ifndef BUILD_NUMBER
#define BUILD_NUMBER -1
#endif
#include "version/version.h"

#define MAX_CLIENTS 64
#define MAX_CONFIGSTRINGS 2442
Expand Down
2 changes: 1 addition & 1 deletion src/sys_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void Sys_PrintBinVersion( const char* name ) {
char* sep = "==============================================================";
fprintf( stdout, "\n\n%s\n", sep );

fprintf( stdout, "%s %s %s build %i %s\n", GAME_STRING,Q3_VERSION,PLATFORM_STRING, BUILD_NUMBER, __DATE__);
fprintf( stdout, "%s %s %s build %i %s\n", GAME_STRING,Q3_VERSION,PLATFORM_STRING, Sys_GetBuild(), __DATE__);

fprintf( stdout, " local install: %s\n", name );
fprintf( stdout, "%s\n\n", sep );
Expand Down
2 changes: 1 addition & 1 deletion src/unix/sys_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Sys_DumpCrash(int signal,struct sigcontext *ctx)
long unsigned size = sizeof(hash);

Com_Printf("This program has crashed with signal: %s\n", strsignal(signal));
Com_Printf("The current Gameversion is: %s %s %s type '%c' build %i %s\n", GAME_STRING,Q3_VERSION,PLATFORM_STRING, SEC_TYPE,BUILD_NUMBER, __DATE__);
Com_Printf("The current Gameversion is: %s %s %s type '%c' build %i %s\n", GAME_STRING,Q3_VERSION,PLATFORM_STRING, SEC_TYPE,Sys_GetBuild(), __DATE__);
Sec_HashFile(SEC_HASH_SHA256, Sys_ExeFile(), hash, &size, qfalse);
//Q_strncpyz(hash, "File Hashing has not been implemented yet", sizeof(hash));
hash[64] = '\0';
Expand Down
2 changes: 0 additions & 2 deletions src/version.h

This file was deleted.

21 changes: 21 additions & 0 deletions src/version/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "version.h"
#include "version_build.h"

#define SYS_COMMONVERSION 17.5
#define _STRINGIFY(s) #s
#define STRINGIFY(s) _STRINGIFY(s)

float Sys_GetCommonVersion()
{
return SYS_COMMONVERSION;
}

const char* Sys_GetCommonVersionString()
{
return STRINGIFY(SYS_COMMONVERSION);
}

int Sys_GetBuild()
{
return BUILD_NUMBER;
}
6 changes: 6 additions & 0 deletions src/version/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
// Wrap constants in functions in order to faster rebuild
// module "version.c" each time.
float Sys_GetCommonVersion();
const char* Sys_GetCommonVersionString();
int Sys_GetBuild();
File renamed without changes.

0 comments on commit c481dca

Please sign in to comment.