Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions code/vqa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ long VQAClass::CacheHandler(long action, void * buffer, long nbytes)
break;

case VQACMD_SEEK:
switch ((int)(intptr_t)buffer) {
case 1:
switch (VQA_DecodeSeekOrigin(buffer)) {
case SEEK_CUR:
Cache.file_buffer_pos += nbytes;
rc = 0;
break;
case 0:
case SEEK_SET:
Cache.file_buffer_pos = nbytes;
rc = 0;
break;
case 2:
case SEEK_END:
Cache.file_buffer_pos = Cache.file_size - nbytes - 1;
rc = 0;
break;
Expand Down Expand Up @@ -846,26 +846,25 @@ long VQAClass::CCFileHandler(long action, void * buffer, long nbytes)
break;

/*
** VQACMD_SEEK asks that you perform a seek relative to the current
** position. NBytes is a signed number, indicating seek direction
** (positive for forward, negative for backward). Buffer has no meaning
** here.
** VQACMD_SEEK asks that you perform a seek from the origin Buffer
** names, which is a SEEK_SET, SEEK_CUR or SEEK_END value cast to a
** pointer. NBytes is the signed offset from that origin.
**
** Any error code returned will be remapped by VQA library into
** VQAERR_SEEK.
*/
case VQACMD_SEEK:
error = (FileHandle.Seek(nbytes, (int)(intptr_t)buffer) == 0);
error = (FileHandle.Seek(nbytes, VQA_DecodeSeekOrigin(buffer)) == 0);
break;

case VQACMD_SEEKPEEK:
if (nbytes > 0) {
error = FileHandle.Seek(nbytes - sizeof(tmp), (int)(intptr_t)buffer) == 0;
error = FileHandle.Seek(nbytes - sizeof(tmp), VQA_DecodeSeekOrigin(buffer)) == 0;
if (error == 0) {
error = FileHandle.Read(&tmp, sizeof(tmp)) != sizeof(tmp);
}
} else {
error = FileHandle.Seek(nbytes, (int)(intptr_t)buffer) == 0;
error = FileHandle.Seek(nbytes, VQA_DecodeSeekOrigin(buffer)) == 0;
if (error == 0) {
error = FileHandle.Read(&tmp, sizeof(tmp)) != sizeof(tmp);
if (error == 0) {
Expand Down Expand Up @@ -973,26 +972,25 @@ long VQAClass::MixFileHandler(long action, void * buffer, long nbytes)
break;

/*
** VQACMD_SEEK asks that you perform a seek relative to the current
** position. NBytes is a signed number, indicating seek direction
** (positive for forward, negative for backward). Buffer has no meaning
** here.
** VQACMD_SEEK asks that you perform a seek from the origin Buffer
** names, which is a SEEK_SET, SEEK_CUR or SEEK_END value cast to a
** pointer. NBytes is the signed offset from that origin.
**
** Any error code returned will be remapped by VQA library into
** VQAERR_SEEK.
*/
case VQACMD_SEEK:
error = (FileHandle.Seek(nbytes, (int)(intptr_t)buffer) == 0);
error = (FileHandle.Seek(nbytes, VQA_DecodeSeekOrigin(buffer)) == 0);
break;

case VQACMD_SEEKPEEK:
if (nbytes > 0) {
error = FileHandle.Seek(nbytes - sizeof(tmp), (int)(intptr_t)buffer) == 0;
error = FileHandle.Seek(nbytes - sizeof(tmp), VQA_DecodeSeekOrigin(buffer)) == 0;
if (error == 0) {
error = FileHandle.Read(&tmp, sizeof(tmp)) != sizeof(tmp);
}
} else {
error = FileHandle.Seek(nbytes, (int)(intptr_t)buffer) == 0;
error = FileHandle.Seek(nbytes, VQA_DecodeSeekOrigin(buffer)) == 0;
if (error == 0) {
error = FileHandle.Read(&tmp, sizeof(tmp)) != sizeof(tmp);
if (error == 0) {
Expand Down
28 changes: 13 additions & 15 deletions code/vqalib/dstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,30 @@ intptr_t __cdecl Disk_VQA_Stream_Handler(VQAHandle *vqa, long action, void *buff
error = 1;
break;

/* VQACMD_SEEK asks that you perform a seek relative to the current
* position. NBytes is a signed number, indicating seek direction
* (positive for forward, negative for backward). Buffer has no meaning
* here.
/* VQACMD_SEEK asks that you perform a seek from the origin Buffer
* names, which is a SEEK_SET, SEEK_CUR or SEEK_END value cast to a
* pointer. NBytes is the signed offset from that origin.
*
* Any error code returned will be remapped by VQA library into
* VQAERR_SEEK.
*/
case VQACMD_SEEK:
error = (lseek(fh, nbytes, (int)(intptr_t)buffer) == -1);
error = (lseek(fh, nbytes, VQA_DecodeSeekOrigin(buffer)) == -1);
break;

case VQACMD_SEEKPEEK:
if (nbytes > 0) {
error = lseek(fh, nbytes - 1, (int)(intptr_t)buffer) == -1;
error = lseek(fh, nbytes - 1, VQA_DecodeSeekOrigin(buffer)) == -1;
if (error == 0) {
error = read(fh, &temp, 1) != 1;
}
} else {
error = lseek(fh, nbytes, (int)(intptr_t)buffer) == -1;
error = lseek(fh, nbytes, VQA_DecodeSeekOrigin(buffer)) == -1;
if (error == 0) {
error = read(fh, &temp, 1) != 1;
}
if (error == 0) {
error = lseek(fh, -1, 1) == -1;
error = lseek(fh, -1, SEEK_CUR) == -1;
}
}
break;
Expand Down Expand Up @@ -186,24 +185,23 @@ intptr_t __cdecl Memory_VQA_Stream_Handler(VQAHandle *vqa, long action, void *bu
error = 1;
break;

/* VQACMD_SEEK asks that you perform a seek relative to the current
* position. NBytes is a signed number, indicating seek direction
* (positive for forward, negative for backward). Buffer has no meaning
* here.
/* VQACMD_SEEK asks that you perform a seek from the origin Buffer
* names, which is a SEEK_SET, SEEK_CUR or SEEK_END value cast to a
* pointer. NBytes is the signed offset from that origin.
*
* Any error code returned will be remapped by VQA library into
* VQAERR_SEEK.
*/
case VQACMD_SEEK:
case VQACMD_SEEKPEEK:
switch ((intptr_t)buffer) {
switch (VQA_DecodeSeekOrigin(buffer)) {

case 1:
case SEEK_CUR:
cache->Offset += nbytes;
error = 0;
break;

case 0:
case SEEK_SET:
p = cache->FileOffset;
if (nbytes >= p) {
cache->Offset = nbytes - p;
Expand Down
8 changes: 4 additions & 4 deletions code/vqalib/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ long VQA_LoadFrame(VQAHandleP *vqap, long flags)

if (tocache > 0) {
if (config->StreamHandler != Memory_VQA_Stream_Handler) {
config->StreamHandler((VQAHandle *)vqap, VQACMD_SEEK, NULL, foffset);
config->StreamHandler((VQAHandle *)vqap, VQACMD_SEEK, (void *)SEEK_SET, foffset);
}
if (config->StreamHandler((VQAHandle *)vqap, VQACMD_READ, &cache->Ptr[cache->Offset], tocache)) {
return -4;
Expand Down Expand Up @@ -1074,7 +1074,7 @@ long VQA_SeekLoop(VQAHandleP *vqap, long framenum, long flags)
needs_seek = true;
}
cache->Offset = 0;
} else if (vqap->Config.StreamHandler((VQAHandle *)vqap, VQACMD_SEEK, 0, VQAFRAME_OFFSET(foff[framenum])) != 0) {
} else if (vqap->Config.StreamHandler((VQAHandle *)vqap, VQACMD_SEEK, (void *)SEEK_SET, VQAFRAME_OFFSET(foff[framenum])) != 0) {
return(VQAERR_SEEK);
}

Expand All @@ -1083,7 +1083,7 @@ long VQA_SeekLoop(VQAHandleP *vqap, long framenum, long flags)
}

if (rc == VQAERR_NONE) {
if (needs_seek && vqap->Config.StreamHandler((VQAHandle *)vqap, VQACMD_SEEKPEEK, 0, cache->FileOffset + cache->Bytes) != 0) {
if (needs_seek && vqap->Config.StreamHandler((VQAHandle *)vqap, VQACMD_SEEKPEEK, (void *)SEEK_SET, cache->FileOffset + cache->Bytes) != 0) {
return(VQAERR_SEEK);
}
}
Expand Down Expand Up @@ -1826,7 +1826,7 @@ long Load_VQF(VQAHandleP *vqap, unsigned long frame_iffsize, char flags)

/* Skip any unknown chunks. */
if (skip == true) {
if (vqap->Config.StreamHandler((VQAHandle *)vqap, VQACMD_SEEK, (void *)1, PADSIZE(iffsize))) {
if (vqap->Config.StreamHandler((VQAHandle *)vqap, VQACMD_SEEK, (void *)SEEK_CUR, PADSIZE(iffsize))) {
return(VQAERR_SEEK);
}
}
Expand Down
9 changes: 9 additions & 0 deletions code/vqalib/vqaplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ typedef struct _VQAHandle {
#define VQACMD_SEEKPEEK 8
#define VQACMD_SIZE 9

/* VQACMD_SEEK and VQACMD_SEEKPEEK carry the seek origin in Buffer rather
* than a pointer. It comes back at pointer width before narrowing to the
* int origin that lseek and FileClass::Seek take.
*/
inline int VQA_DecodeSeekOrigin(void *buffer)
{
return (int)(std::intptr_t)buffer;
}

#define VQAMEM_0 0
#define VQAMEM_1 1
#define VQAMEM_ALLOC 2
Expand Down