Use range_for in hmp_open
This commit is contained in:
parent
3fc3cfecf1
commit
aabd01c9ad
|
@ -49,7 +49,7 @@ hmp_file::~hmp_file()
|
|||
}
|
||||
|
||||
std::unique_ptr<hmp_file> hmp_open(const char *filename) {
|
||||
int data, num_tracks, tempo;
|
||||
int data, tempo;
|
||||
auto fp = PHYSFSX_openReadBuffered(filename);
|
||||
|
||||
if (!fp)
|
||||
|
@ -67,6 +67,7 @@ std::unique_ptr<hmp_file> hmp_open(const char *filename) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
unsigned num_tracks;
|
||||
if (PHYSFS_read(fp, &num_tracks, 4, 1) != 1)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -93,22 +94,22 @@ std::unique_ptr<hmp_file> hmp_open(const char *filename) {
|
|||
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))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data -= 12;
|
||||
hmp->trks[i].len = data;
|
||||
|
||||
hmp->trks[i].data = make_unique<uint8_t[]>(data);
|
||||
i.len = data;
|
||||
i.data = make_unique<uint8_t[]>(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;
|
||||
}
|
||||
hmp->trks[i].loop_set = 0;
|
||||
i.loop_set = 0;
|
||||
}
|
||||
hmp->filesize = PHYSFS_fileLength(fp);
|
||||
return hmp;
|
||||
|
|
Loading…
Reference in a new issue