Ok, I want to share game data between the PC and PPC. Should I store it as just a char and convert it before passing it to GapiDraw, taking cpu power; or should I store it as a unicode TCHAR and take up twice as much space for game data and memory?
ASCII and Unicode
I would have to say either way is negligible. Using TCHARs would probably make more sense though I often use chars out of habbit and convert them with the TEXT() macro.
In the case of Warlords, all data is in the form of CHAR and SHORT, so I load it in those formats and do _T conversions as necessary so I handle all text in UNICODE.
So to pass a path to GapiDraw on the PPC, could I pass it as _T(char) or something like that? Would it work the same way for PC?
Do your path names as unicode so it will be portable between platforms. Here's an example:
- Code:
#ifndef _WIN32_WCE
FILE *fp = fopen(getFullPath(_T("data\\data.dat")), _T("rb")); if(!fp) return E_FAIL;
#else
FILE *fp = _wfopen(getFullPath(_T("data\\data.dat")), _T("rb")); if(!fp) return E_FAIL;
#endif
.......
LPCTSTR getFullPath(const TCHAR *pFilename)
{
static TCHAR lpFilename[257];
INT nStrLen;
TCHAR *pDest;
INT result;
INT ch = '\\';
for(INT i = 0; i < 257; i++) lpFilename[i] = '\0';
nStrLen = GetModuleFileName(NULL, lpFilename, 1024);
pDest = _tcsrchr(lpFilename, ch);
if (pDest != NULL) {
result = pDest - lpFilename + 1;
lpFilename[result] = '\0';
if (pFilename != NULL) _tcscat(lpFilename, pFilename);
return lpFilename;
} else return NULL;
}
Ok, but what about storing paths in the data.dat file that points to other files? Just use unicode to?
Oh, I see what you're asking. If you read everything in as a CHAR, you can store it as a CHAR data too. There is an api function for converting from unicode to CHAR data as well, so you can work text in unicode internally and store it as CHAR data externally.
Now looking back at the code example, couldn't you have the following:
And then use open multiple times in a program? Wouldn't that be a little more efficient?
- Code:
#ifndef _WIN32_WCE
#define open fopen
#else
#define open _wfopen
#endif
FILE *fp = open(getFullPath(_T("data\\data.dat")), _T("rb")); if(!fp) return E_FAIL;
And then use open multiple times in a program? Wouldn't that be a little more efficient?