static FModel * FindModel(const char * path, const char * modelfile) { FModel * model; FString fullname; fullname.Format("%s%s", path, modelfile); int lump = Wads.CheckNumForFullName(fullname); if (lump<0) { Printf("FindModel: '%s' not found\n", fullname.GetChars()); return NULL; } for(int i = 0; i< (int)Models.Size(); i++) { if (!stricmp(fullname, Models[i]->filename)) return Models[i]; } int len = Wads.LumpLength(lump); FMemLump lumpd = Wads.ReadLump(lump); char * buffer = (char*)lumpd.GetMem(); if (!memcmp(buffer, "DMDM", 4)) { model = new FDMDModel; } else if (!memcmp(buffer, "IDP2", 4)) { model = new FMD2Model; } else if (!memcmp(buffer, "IDP3", 4)) { model = new FMD3Model; } else { Printf("LoadModel: Unknown model format in '%s'\n", fullname.GetChars()); delete buffer; return NULL; } if (!model->Load(path, buffer, len)) { delete model; delete buffer; return NULL; } model->filename = copystring(fullname); Models.Push(model); return model; }
static unsigned FindModel(const char * path, const char * modelfile) { FModel * model = nullptr; FString fullname; fullname.Format("%s%s", path, modelfile); int lump = Wads.CheckNumForFullName(fullname); if (lump<0) { Printf("FindModel: '%s' not found\n", fullname.GetChars()); return -1; } for(unsigned i = 0; i< Models.Size(); i++) { if (!Models[i]->mFileName.CompareNoCase(fullname)) return i; } int len = Wads.LumpLength(lump); FMemLump lumpd = Wads.ReadLump(lump); char * buffer = (char*)lumpd.GetMem(); if (!memcmp(buffer, "DMDM", 4)) { model = new FDMDModel; } else if (!memcmp(buffer, "IDP2", 4)) { model = new FMD2Model; } else if (!memcmp(buffer, "IDP3", 4)) { model = new FMD3Model; } if (model != nullptr) { if (!model->Load(path, lump, buffer, len)) { delete model; return -1; } } else { // try loading as a voxel FVoxel *voxel = R_LoadKVX(lump); if (voxel != nullptr) { model = new FVoxelModel(voxel, true); } else { Printf("LoadModel: Unknown model format in '%s'\n", fullname.GetChars()); return -1; } } // The vertex buffer cannot be initialized here because this gets called before OpenGL is initialized model->mFileName = fullname; return Models.Push(model); }