34 : datapath(
""), video(0), use_file_system(true), enable_media(true)
50 def_loader =
new(__FILE__,__LINE__)
DataLoader;
78 use_file_system = use;
84 enable_media = enable;
95 fopen_s(&f, name,
"rb");
107 while (++iter && !found) {
109 if (!strcmp(archive->
Name(), name)) {
118 Print(
" WARNING: invalid data file '%s'\n", name);
127 Print(
" WARNING: could not open datafile '%s'\n", name);
140 if (!strcmp(a->
Name(), name)) {
167 strcpy_s(filename, datapath);
168 strcat_s(filename, name);
171 if (use_file_system) {
173 ::fopen_s(&f, filename,
"rb");
182 int narchives = archives.
size();
183 for (
int i = 0; i < narchives; i++) {
200 ListFileSystem(filter, list, datapath, recurse);
203 int narchives = archives.
size();
204 for (
int i = 0; i < narchives; i++) {
215 int pathlen = datapath.
length();
219 int narchives = archives.
size();
220 for (
int i = 0; i < narchives && !a; i++) {
221 a = archives[narchives-1-i];
223 if (_stricmp(a->
Name(), archive_name))
229 ListFileSystem(filter, list, datapath,
true);
233 if (!strcmp(filter,
"*.*")) {
235 for (
int n = 0; n < count; n++) {
240 if (entry_name.
contains(datapath)) {
241 Text fname = entry_name(pathlen, 1000);
249 char data_filter[256];
250 ZeroMemory(data_filter, 256);
252 const char* pf = filter;
253 char* pdf = data_filter;
262 for (
int n = 0; n < count; n++) {
268 Text fname = entry_name(pathlen, 1000);
282 DataLoader::ListFileSystem(
const char* filter,
List<Text>& list,
Text base_path,
bool recurse)
284 if (use_file_system) {
285 char data_filter[256];
286 ZeroMemory(data_filter, 256);
288 const char* pf = filter;
289 char* pdf = data_filter;
297 int pathlen = base_path.
length();
300 char win32_filter[1024];
301 strcpy_s(win32_filter, datapath);
304 strcat_s(win32_filter,
"*.*");
306 strcat_s(win32_filter, filter);
309 WIN32_FIND_DATA data;
310 HANDLE hFind = FindFirstFile(win32_filter, &data);
312 if (hFind != INVALID_HANDLE_VALUE) {
314 if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
315 if (recurse && data.cFileName[0] !=
'.') {
316 Text old_datapath = datapath;
318 Text newpath = datapath;
319 newpath += data.cFileName;
323 ListFileSystem(filter, list, base_path, recurse);
325 datapath = old_datapath;
329 if (!strcmp(filter,
"*.*") || strstr(data.cFileName, data_filter)) {
330 Text full_name = datapath;
331 full_name += data.cFileName;
333 list.
append(
new Text(full_name(pathlen, 1000)));
337 while (FindNextFile(hFind, &data));
351 strcpy_s(filename, datapath);
352 strcat_s(filename, name);
354 if (use_file_system) {
357 ::fopen_s(&f, filename,
"rb");
360 ::fseek(f, 0, SEEK_END);
362 ::fseek(f, 0, SEEK_SET);
364 if (null_terminate) {
365 buf =
new(__FILE__,__LINE__) BYTE[len+1];
371 buf =
new(__FILE__,__LINE__) BYTE[len];
384 int narchives = archives.
size();
388 if (narchives > 1 && strstr(filename,
"Vox")) {
389 for (
int i = 0; i < narchives; i++) {
391 if (strstr(a->
Name(),
"vox")) {
399 for (
int i = 0; i < narchives; i++) {
407 Print(
"WARNING - DataLoader could not load buffer '%s'\n", filename);
414 DataLoader::LoadPartialFile(
const char* name, BYTE*& buf,
int max_load,
bool optional)
420 strcpy_s(filename, datapath);
421 strcat_s(filename, name);
425 ::fopen_s(&f, filename,
"rb");
428 ::fseek(f, 0, SEEK_END);
430 ::fseek(f, 0, SEEK_SET);
432 if (len > max_load) {
436 buf =
new(__FILE__,__LINE__) BYTE[len];
447 Print(
"WARNING - DataLoader could not load partial file '%s'\n", filename);
454 CopyMemory(buffer, stream, size*count);
455 stream += size*count;
478 if (bitmap)
return 1;
481 bitmap =
new(__FILE__,__LINE__)
Bitmap;
484 result =
LoadBitmap(name, *bitmap, type, optional);
486 if (result && bitmap)
500 int result = LoadIndexed(name, bitmap, type);
504 int hi_result = LoadHiColor(name, bitmap, type);
512 if (!result && !optional)
513 Print(
"WARNING - DataLoader could not load bitmap '%s%s'\n", datapath.
data(), name);
530 strcpy_s(filename, datapath);
531 strcat_s(filename, name);
535 if (bitmap)
return 1;
538 bitmap =
new(__FILE__,__LINE__)
Bitmap;
541 result = LoadHiColor(name, *bitmap, type);
544 result = LoadIndexed(name, *bitmap, type);
558 Print(
"WARNING - DataLoader could not load texture '%s%s'\n", datapath.
data(), name);
561 else if (!optional) {
562 Print(
"WARNING - DataLoader could not allocate texture '%s%s'\n", datapath.
data(), name);
571 DataLoader::LoadIndexed(
const char* name,
Bitmap& bitmap,
int type)
579 bool pcx_file = strstr(name,
".pcx") || strstr(name,
".PCX");
583 strcpy_s(filename, datapath);
584 strcat_s(filename, name);
589 if (use_file_system) {
594 loaded = d3dx.
Load(filename);
602 int narchives = archives.
size();
603 for (
int i = 0; i < narchives; i++) {
628 else if (pcx.
himap) {
634 LoadAlpha(name, bitmap, type);
644 LoadAlpha(name, bitmap, type);
652 DataLoader::LoadHiColor(
const char* name,
Bitmap& bitmap,
int type)
660 bool pcx_file = strstr(name,
".pcx") || strstr(name,
".PCX");
661 bool bmp_file = strstr(name,
".bmp") || strstr(name,
".BMP");
662 bool png_file = strstr(name,
".png") || strstr(name,
".PNG");
667 strcpy_s(name2, name);
669 char* dot = strrchr(name2,
'.');
671 strcpy(dot,
"+.pcx");
672 else if (dot && bmp_file)
673 strcpy(dot,
"+.bmp");
674 else if (dot && png_file)
675 strcpy(dot,
"+.png");
679 strcpy_s(filename, datapath);
680 strcat_s(filename, name2);
685 if (use_file_system) {
690 loaded = d3dx.
Load(filename);
698 int narchives = archives.
size();
699 for (
int i = 0; i < narchives; i++) {
717 if (pcx_file && pcx.
himap) {
722 else if (d3dx.
image) {
728 LoadAlpha(name, bitmap, type);
734 DataLoader::LoadAlpha(
const char* name,
Bitmap& bitmap,
int type)
741 bool pcx_file = strstr(name,
".pcx") || strstr(name,
".PCX");
742 bool bmp_file = strstr(name,
".bmp") || strstr(name,
".BMP");
743 bool png_file = strstr(name,
".png") || strstr(name,
".PNG");
744 bool tga_file = strstr(name,
".tga") || strstr(name,
".TGA");
749 strcpy_s(name2, name);
750 char* dot = strrchr(name2,
'.');
752 strcpy(dot,
"@.pcx");
753 else if (dot && bmp_file)
754 strcpy(dot,
"@.bmp");
755 else if (dot && png_file)
756 strcpy(dot,
"@.png");
757 else if (dot && tga_file)
758 strcpy(dot,
"@.tga");
762 strcpy_s(filename, datapath);
763 strcat_s(filename, name2);
768 if (use_file_system) {
773 loaded = d3dx.
Load(filename);
781 int narchives = archives.
size();
782 for (
int i = 0; i < narchives; i++) {
800 if (pcx_file && pcx.
bitmap) {
803 else if (pcx_file && pcx.
himap) {
806 else if (d3dx.
image) {
821 if (strstr(name,
".ogg"))
837 ZeroMemory(&head,
sizeof(head));
838 ZeroMemory(&fmt,
sizeof(fmt));
839 ZeroMemory(&fact,
sizeof(fact));
840 ZeroMemory(&data,
sizeof(data));
844 if (len >
sizeof(head)) {
845 CopyMemory(&head, buf,
sizeof(head));
847 if (head.
RIFF == MAKEFOURCC(
'R',
'I',
'F',
'F') &&
848 head.
WAVE == MAKEFOURCC(
'W',
'A',
'V',
'E')) {
853 DWORD chunk_id = *((LPDWORD) p);
856 case MAKEFOURCC(
'f',
'm',
't',
' '):
857 CopyMemory(&fmt, p,
sizeof(fmt));
861 case MAKEFOURCC(
'f',
'a',
'c',
't'):
862 CopyMemory(&fact, p,
sizeof(fact));
866 case MAKEFOURCC(
's',
'm',
'p',
'l'):
867 CopyMemory(&fact, p,
sizeof(fact));
871 case MAKEFOURCC(
'd',
'a',
't',
'a'):
872 CopyMemory(&data, p,
sizeof(data));
912 int namelen = strlen(name);
917 if ((name[namelen-3] ==
'o' || name[namelen-3] ==
'O') &&
918 (name[namelen-2] ==
'g' || name[namelen-2] ==
'G') &&
919 (name[namelen-1] ==
'g' || name[namelen-1] ==
'G')) {
921 return LoadOggStream(name, snd);
936 ZeroMemory(&head,
sizeof(head));
937 ZeroMemory(&fmt,
sizeof(fmt));
938 ZeroMemory(&fact,
sizeof(fact));
939 ZeroMemory(&data,
sizeof(data));
941 len = LoadPartialFile(name, buf, 4096, optional);
943 if (len >
sizeof(head)) {
944 CopyMemory(&head, buf,
sizeof(head));
946 if (head.
RIFF == MAKEFOURCC(
'R',
'I',
'F',
'F') &&
947 head.
WAVE == MAKEFOURCC(
'W',
'A',
'V',
'E')) {
952 DWORD chunk_id = *((LPDWORD) p);
955 case MAKEFOURCC(
'f',
'm',
't',
' '):
956 CopyMemory(&fmt, p,
sizeof(fmt));
960 case MAKEFOURCC(
'f',
'a',
'c',
't'):
961 CopyMemory(&fact, p,
sizeof(fact));
965 case MAKEFOURCC(
's',
'm',
'p',
'l'):
966 CopyMemory(&fact, p,
sizeof(fact));
970 case MAKEFOURCC(
'd',
'a',
't',
'a'):
971 CopyMemory(&data, p,
sizeof(data));
995 strcpy_s(filename, datapath);
996 strcat_s(filename, name);
1010 DataLoader::LoadOggStream(
const char* name,
Sound*& snd)