Use range_for in hmp_open

This commit is contained in:
Kp 2016-10-29 23:16:17 +00:00
parent 3fc3cfecf1
commit aabd01c9ad

View file

@ -49,7 +49,7 @@ hmp_file::~hmp_file()
} }
std::unique_ptr<hmp_file> hmp_open(const char *filename) { std::unique_ptr<hmp_file> hmp_open(const char *filename) {
int data, num_tracks, tempo; int data, tempo;
auto fp = PHYSFSX_openReadBuffered(filename); auto fp = PHYSFSX_openReadBuffered(filename);
if (!fp) if (!fp)
@ -67,6 +67,7 @@ std::unique_ptr<hmp_file> hmp_open(const char *filename) {
return NULL; return NULL;
} }
unsigned num_tracks;
if (PHYSFS_read(fp, &num_tracks, 4, 1) != 1) if (PHYSFS_read(fp, &num_tracks, 4, 1) != 1)
{ {
return NULL; return NULL;
@ -93,22 +94,22 @@ std::unique_ptr<hmp_file> hmp_open(const char *filename) {
return NULL; return NULL;
} }
for (int i = 0; i < num_tracks; i++) { range_for (auto &i, partial_range(hmp->trks, num_tracks))
{
if ((PHYSFSX_fseek(fp, 4, SEEK_CUR)) || (PHYSFS_read(fp, &data, 4, 1) != 1)) if ((PHYSFSX_fseek(fp, 4, SEEK_CUR)) || (PHYSFS_read(fp, &data, 4, 1) != 1))
{ {
return NULL; return NULL;
} }
data -= 12; data -= 12;
hmp->trks[i].len = data; i.len = data;
i.data = make_unique<uint8_t[]>(data);
hmp->trks[i].data = make_unique<uint8_t[]>(data);
/* finally, read track data */ /* finally, read track data */
if ((PHYSFSX_fseek(fp, 4, SEEK_CUR)) || (PHYSFS_read(fp, hmp->trks[i].data.get(), data, 1) != 1)) if ((PHYSFSX_fseek(fp, 4, SEEK_CUR)) || (PHYSFS_read(fp, i.data.get(), data, 1) != 1))
{ {
return NULL; return NULL;
} }
hmp->trks[i].loop_set = 0; i.loop_set = 0;
} }
hmp->filesize = PHYSFS_fileLength(fp); hmp->filesize = PHYSFS_fileLength(fp);
return hmp; return hmp;