Raised This Month: $51 Target: $400
 12% 

Being version independent


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 11-16-2005 , 19:06   Being version independent
Reply With Quote #1

Code:
CreateInterfaceFn* findValidInterface(CreateInterfaceFn fac,const char * inter,unsigned int offset) {
	if (fac==NULL || inter==NULL || offset ==0) return NULL;
	CreateInterfaceFn *temp;

	temp = (CreateInterfaceFn*)fac(inter,NULL);
	if (!temp) {
		int sLenName=strlen(inter);
		char intName[256], newVer[256];
		memcpy(intName,inter,(sLenName>256?256:sLenName));
		unsigned int cVersion;
		cVersion = intName[sLenName-1]+(intName[sLenName-2]*10)+(intName[sLenName-3]*100);
		cVersion = atoi(&intName[sLenName-3]);
		intName[sLenName-3] = 0;
		for (cVersion=cVersion+offset;(cVersion>cVersion-offset && cVersion>0);cVersion--) {
			_snprintf(newVer,256,"%s%03d",intName,cVersion);
			temp = (CreateInterfaceFn *)fac(newVer,NULL);
			if (temp) break;
		}
	}
	return temp;
}
You use this as so.
To replace
Code:
m_ServerDll = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMEDLL, NULL));
You would use
Code:
m_ServerDll = (IServerGameDLL *)findValidInterface(ismm->serverFactory(),INTERFACEVERSION_SERVERGAMEDLL,2);
In that way, as long as the interface available is either 2 above or below the one it was compiled against, you will get a valid interface pointer. It's still possible to get null's, if for example the interface was totally removed.
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
BAILOPAN
Join Date: Jan 2004
Old 11-17-2005 , 01:48  
Reply With Quote #2

Perhaps it would be best to have some sort of table of version compatibilities so you knew what was available or not.

I know it sounds like work but it'd be neat to have like interfaces.xml which you could parse and the user could modify, to adapt to a game.
__________________
egg
BAILOPAN is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 11-17-2005 , 14:45  
Reply With Quote #3

It would be but, its a lot more code
This is the simplest thing to do at the moment, requiring no user action.
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode