Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update version.h to support easy build flags #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static void set_window_title( void )
// this is now done in CreateWindow
#if !SDL_VERSION_ATLEAST(2,0,0)
// window title, icon title (taskbar and other places)
SDL_WM_SetCaption(PXVersion,"ProjectX");
SDL_WM_SetCaption(PX_VERSION_STR,"ProjectX");
#endif
}

Expand Down
5 changes: 3 additions & 2 deletions net_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ static void send_tracker_message( char* host, int port, char* message );
// 13 = hosting + white space + null byte
// +1 = comma for separating names
#define MAX_PORT 5
#define MAX_HOSTING_MSG (MAX_PORT + (MAXSHORTNAME+1) * MAX_PLAYERS + MAX_PXVersion + MAX_SHORT_LEVEL_NAME + 13)
#define MAX_PX_VERSION_STR 100
#define MAX_HOSTING_MSG (MAX_PORT + (MAXSHORTNAME+1) * MAX_PLAYERS + MAX_PX_VERSION_STR + MAX_SHORT_LEVEL_NAME + 13)

void send_tracker_update( char* host, int port )
{
int i;
char message[ MAX_HOSTING_MSG ];
sprintf(message,"hosting %d %s %s",my_local_port,PXVersion,my_player_name);
snprintf(message,MAX_HOSTING_MSG,"hosting %d %s %s",my_local_port,PX_VERSION_STR,my_player_name);
for(i=0; i<MAX_PLAYERS; i++)
{
if ( i != WhoIAm && STATUS_VALID_PLAYER(GameStatus[i]) )
Expand Down
8 changes: 4 additions & 4 deletions networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extern int GetPlayerNumCount;

extern bool PickupValid[ MAXPICKUPTYPES ];

#define YourVersion "YOUR VERSION: " PXVersion
#define YourVersion "YOUR VERSION: " PX_VERSION_STR

#define ONEOVER32767 (1.0F / 32767.0F)
#define ONEOVER256 (1.0F / 256.0F)
Expand Down Expand Up @@ -3278,7 +3278,7 @@ void EvaluateMessage( network_player_t * from, DWORD len , BYTE * MsgPnt )
// display my version number
AddColourMessageToQue(SystemMessageColour, "%s", YourVersion );
// send my version number back
strncpy( (char *)&QuickText.text, PXVersion , sizeof(PXVersion) );
strncpy( (char *)&QuickText.text, PX_VERSION_STR , sizeof(PX_VERSION_STR) );
SendGameMessage(MSG_TEXTMSG, 0, 0, TEXTMSGTYPE_QuickTaunt, 0);
QuickText.text[0] = 0; // clean message buffer
}
Expand Down Expand Up @@ -3526,7 +3526,7 @@ void SendGameMessage( BYTE msg, network_player_t * to, BYTE ShipNum, BYTE Type,
lpHereIAm = (LPHEREIAMMSG)&CommBuff[0];
lpHereIAm->MsgCode = msg;
lpHereIAm->WhoIAm = WhoIAm;
lpHereIAm->MPVersion = PXMPVINT;
lpHereIAm->MPVersion = PX_VERSION_NETWORK_COMPAT_INT;
nBytes = sizeof( HEREIAMMSG );
flags |= NETWORK_RELIABLE;
break;
Expand Down Expand Up @@ -3575,7 +3575,7 @@ void SendGameMessage( BYTE msg, network_player_t * to, BYTE ShipNum, BYTE Type,
// Check player has right version to join the game
//

if( PXMPVINT != mask )
if( PX_VERSION_NETWORK_COMPAT_INT != mask )
{
lpInit->YouAre = MAX_PLAYERS+3; // bad version
goto send;
Expand Down
87 changes: 58 additions & 29 deletions version.h
Original file line number Diff line number Diff line change
@@ -1,49 +1,78 @@
#ifndef VERSION_HEADER
#define VERSION_HEADER

// major version
#define PXV "1"
//
// These are some helpers that make us able to concat values as desired
//

// multiplayer version (increase if you break multiplayer compatibility)
#define PXMPV "18"
// you need 2 levels of indirection to make things work right
// https://stackoverflow.com/questions/1489932/how-can-i-concatenate-twice-with-the-c-preprocessor-and-expand-a-macro-as-in-ar

// multiplayer compatibility flag
// TODO: use this format in future for now hard coded to existing format
//#define PXMPVINT PXV.PXMPV
#define PXMPVINT 118
// combine two raw snippets into one
#define CONCAT2(a,b) a ## b
#define CONCAT(a,b) CONCAT2(a,b)

// revision (should be provided at build time for official builds)
// make PXRV=$(svn info | grep Revision | awk '{print $NF}')
#ifndef PXRV
#define PXRV "0"
// wraps a value as a string
#define STR2(x) #x
#define STR(x) STR2(x)



//
// Version information
//
//
// The basic versioning premis is:
//
// major.network.build-platform-arch
//
// major = major version
// network = network compatability (bump on breaking changes)
// build = incremental build version
// platform = windows/linux/mac/etc.
// arch = 32/64bit
//

#ifndef VERSION_MAJOR
#define VERSION_MAJOR 1
#endif

#ifndef VERSION_NETWORK
#define VERSION_NETWORK 18
#endif

#ifndef VERSION_BUILD
#define VERSION_BUILD 0
#endif

// tag name so we know what type of build this is
#ifndef PXBV
#ifdef WIN32
#ifdef D3D
#define PXBV "D3D9"
#else
#define PXBV "OPEN"
#endif
#ifndef VERSION_PLATFORM
#if defined(WIN32)
#define VERSION_PLATFORM "WINDOWS"
#elif defined(MACOSX)
#define PXBV "MACOSX"
#define VERSION_PLATFORM "MACOSX"
#else
#define PXBV "LINUX"
#define VERSION_PLATFORM "LINUX"
#endif
#endif

// architecture
#ifdef __i386__
#define ARCH "32"
#define ARCH "32"
#else
#define ARCH "64"
#define ARCH "64"
#endif

// the full version name (must contain no spaces for net_tracker)
#define PXVersion "ProjectX-" PXV "." PXMPV "." PXRV "-" PXBV "-" ARCH
// the full stringified version name
// must contain no spaces for net_tracker
#define PX_VERSION_STR \
"ProjectX-" \
STR(VERSION_MAJOR) "." \
STR(VERSION_NETWORK) "." \
STR(VERSION_BUILD) "-" \
VERSION_PLATFORM \
"-" \
ARCH

// this should be plenty if not please increase this
#define MAX_PXVersion 45
// the multiplayer version as an integer used for network packets
#define PX_VERSION_NETWORK_COMPAT_INT CONCAT(VERSION_MAJOR, VERSION_NETWORK)

#endif