I am working on converting my hand-coded int arrays for levels to putting them in a .txt file and loading them by resource. So this function will also handle looping through the file and then setting the ints in the global level array.
Everythings working so far, but I have a few questions.
On the char array, how can I use a variable size? or should I just set it to the maximum?
Then, what function would I use to loop through the char array and extract ints?
The text file will be setup, and formatted with some extra spacing such as:
Code:
0, 0, 1, 2, 10, 0, 5
1, 0, 0, 11, 0, 0, 0
0, 0, 0, 0, 0, 0, 0
I have checked the char array, and it is loading the text file correctly.
Code:
void loadResourceLevel(int resid) {
// variables
DWORD dwFileSize;
LPVOID lpTxtData;
LPVOID pvData;
LPSTREAM pstm;
HRSRC hrlp;
HGLOBAL hGlobal;
HINSTANCE hInst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
char data[100];
// find resource
hrlp = FindResource(hInst, MAKEINTRESOURCE(resid), RT_RCDATA);
// make sure it found something
if (hrlp != NULL) {
dwFileSize = SizeofResource(hInst, hrlp);
hGlobal = LoadResource(hInst, hrlp);
// something was loaded
if (hGlobal != 0) {
lpTxtData = LockResource(hGlobal);
pvData = NULL;
hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
pvData = GlobalLock(hGlobal);
CopyMemory(pvData, lpTxtData, dwFileSize);
GlobalUnlock(hGlobal);
memcpy(data, lpTxtData, dwFileSize);
return;
}
}
MessageBox(hwnd, "Failed", NULL, MB_OK);
}
I was thinking of something like sscanf() to read the ints. That won't work though because each line will contain 100's of ints, so I need a function to iterate through each int.