From 7f4cda6622990b7aa26e433ecdc8f17b8a3b237d Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 29 Oct 2005 21:24:54 +0000 Subject: Applied my own patch #1341495, in an attempt to fix alignment issues reported by Crilith. To elaborate a bit, the engine no longer accesses resource data through packed structs. Instead it uses memory streams and the READ/WRITE functions. If data is mainly read, not written, I have replaced the old struct with a new one with a read() function to read the whole thing from memory into the struct's variables, and a write() function to dump the struct's variables to memory. In fact, most of these write() functions remain unused. If data is both read and written, I have replaced the struct with a class with individual get/set functions to replace the old variables. This manipulates memory directly. Since I'm fairly sure that these structs are frequently stored as local variables for a script, all script variables (both local and global) are stored as little-endian and accessed through the READ/WRITE functions, rather than being treated as arrays of 32-bit integers. On a positive note, the functions for doing endian conversion of resources and save games have been removed, and some general cleanups have been made to assist in the rewrite. Initial reports indicate that this patch indeed fixes alignment issues, and that I have not - surprisingly - broken the game on big-endian platforms. At least not in any immediately obvious way. And there's still plenty of time to fix regressions before 0.9.0, too. svn-id: r19366 --- sword2/driver/d_sound.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sword2/driver/d_sound.cpp') diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index ed12eaaaf9..8f3426c220 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -177,7 +177,7 @@ CLUInputStream::~CLUInputStream() { int CLUInputStream::readBuffer(int16 *buffer, const int numSamples) { int samples = 0; while (samples < numSamples && !eosIntern()) { - const int len = MIN(numSamples - samples, (int) (_bufferEnd - _pos)); + const int len = MIN(numSamples - samples, (int)(_bufferEnd - _pos)); memcpy(buffer, _pos, len * 2); buffer += len; _pos += len; @@ -195,7 +195,7 @@ void CLUInputStream::refill() { _file->seek(_file_pos, SEEK_SET); - uint len_left = _file->read(in, MIN((uint32) BUFFER_SIZE, _end_pos - _file->pos())); + uint len_left = _file->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _file->pos())); _file_pos = _file->pos(); @@ -270,7 +270,7 @@ int MusicInputStream::readBuffer(int16 *buffer, const int numSamples) { int samples = 0; while (samples < numSamples && !eosIntern()) { - const int len = MIN(numSamples - samples, (int) (_bufferEnd - _pos)); + const int len = MIN(numSamples - samples, (int)(_bufferEnd - _pos)); memcpy(buffer, _pos, len * 2); buffer += len; _pos += len; @@ -290,7 +290,7 @@ void MusicInputStream::refill() { len_left = BUFFER_SIZE; - if (_fading > 0 && (uint32) _fading < len_left) + if (_fading > 0 && (uint32)_fading < len_left) len_left = _fading; if (_samplesLeft < len_left) -- cgit v1.2.3