diff options
| author | Steven Fuller <relnev@icculus.org> | 2017-05-05 12:00:00 +0200 |
|---|---|---|
| committer | Patryk Obara <dreamer.tan@gmail.com> | 2019-08-20 03:51:51 +0200 |
| commit | 5673c1665a2c6d7fdaf1a20d554bb135a20c7bc8 (patch) | |
| tree | ccf08c484f14d7c5e95fa7f645db2014d61ebb78 /src/win95 | |
| parent | 0de664d0a886bcda45a0cd05551b6896c5c46ed0 (diff) | |
Import icculus.org release (2017-05-05)
Diffstat (limited to 'src/win95')
| -rw-r--r-- | src/win95/aw.h | 3 | ||||
| -rw-r--r-- | src/win95/awtexld.cpp | 16 | ||||
| -rw-r--r-- | src/win95/db.c | 5 | ||||
| -rw-r--r-- | src/win95/iff.hpp | 22 | ||||
| -rw-r--r-- | src/win95/media.hpp | 172 | ||||
| -rw-r--r-- | src/win95/shpchunk.cpp | 6 |
6 files changed, 129 insertions, 95 deletions
diff --git a/src/win95/aw.h b/src/win95/aw.h index 8b9985c..4a4ecec 100644 --- a/src/win95/aw.h +++ b/src/win95/aw.h @@ -19,6 +19,9 @@ typedef struct DIRECTDRAWSURFACE float RecipW; float RecipH; + int hasAlpha; + int hasChroma; + int filter; } DIRECTDRAWSURFACE; diff --git a/src/win95/awtexld.cpp b/src/win95/awtexld.cpp index 64afca7..ac9d857 100644 --- a/src/win95/awtexld.cpp +++ b/src/win95/awtexld.cpp @@ -145,8 +145,7 @@ namespace AwTl DWORD memFlag; void * ddP; - } - driverDesc; + } driverDesc; /*************************************************************************/ /* Class used to hold all the parameters for the CreateTexture functions */ @@ -496,6 +495,9 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR #endif /* Just convert the texture to 32bpp */ + // may want to support paletted textures + // at some point; at which point, should + // push texture conversion into the opengl layer pixelFormat.palettizedB = 0; pixelFormat.alphaB = 1; @@ -540,7 +542,15 @@ AwTl::SurfUnion AwBackupTexture::CreateTexture(AwTl::CreateTextureParms const & fprintf(stderr, "AwBackupTexture::CreateTexture - chroma\n"); } + if (pixelFormat.texB && m_bTranspMask) { + //fprintf(stderr, "AwBackupTexture::CreateTexture - transparency\n"); + } + // convert asset to 32-bit rgba + // may want to support paletted textures + // at some point; at which point, should + // push texture conversion into the opengl layer + unsigned char *buf = (unsigned char *)malloc(m_nWidth * m_nHeight * 4); Colour * paletteP = m_nPaletteSize ? GetPalette() : NULL; @@ -591,6 +601,8 @@ AwTl::SurfUnion AwBackupTexture::CreateTexture(AwTl::CreateTextureParms const & Tex->w = m_nWidth; Tex->h = m_nHeight; + Tex->hasAlpha = m_bTranspMask; + Tex->hasChroma = m_fFlags & AW_TLF_CHROMAKEY; if (pixelFormat.texB) { CreateOGLTexture(Tex, buf); diff --git a/src/win95/db.c b/src/win95/db.c index ed3cd57..61b2155 100644 --- a/src/win95/db.c +++ b/src/win95/db.c @@ -387,6 +387,10 @@ void db_print_fired(int x, int y, const char *strP) */ void db_log_fired(const char *strP) { +#if EMSCRIPTEN + printf("%s\n", strP); + return; +#else /* Have we intialised the file? */ if(!InitialisedLog) db_log_init(); { @@ -398,6 +402,7 @@ void db_log_fired(const char *strP) fprintf(fP, "%s\n", strP); fclose(fP); } +#endif } void db_log_init(void) diff --git a/src/win95/iff.hpp b/src/win95/iff.hpp index c8060e6..f2dbd9c 100644 --- a/src/win95/iff.hpp +++ b/src/win95/iff.hpp @@ -158,16 +158,19 @@ namespace IFF UBYTE b; }; - union ID + struct ID { UINT32 m_nID; - char m_sID[4]; - inline ID(){} - inline ID(char const * pszID) { m_nID = *reinterpret_cast<UINT32 const *>(pszID); } + inline ID() : m_nID(0) {} + inline ID(char const * pszID) { + m_nID = (pszID[0] << 0) + | (pszID[1] << 8) + | (pszID[2] << 16) + | (pszID[3] << 24); + } inline ID(UINT32 nID) : m_nID(nID) {} inline operator UINT32 () const { return m_nID; } - inline operator char const * () const { return &m_sID[0]; } inline bool operator == (ID const & rId) const { return !m_nID || !rId.m_nID || m_nID == rId.m_nID; } inline bool operator != (ID const & rId) const { return ! operator == (rId); } inline bool operator ! () const { return !m_nID; } @@ -717,8 +720,13 @@ namespace IFF m_nBytesRemaining -= 4; if (m_nBytesRemaining >= 0) { - // cast pointer to pointer to 4 byte data type to force 4 byte 'fast' read - ::MediaRead(m_pMedium, reinterpret_cast<UINT32 *>(&n.m_sID[0])); + + UBYTE b0, b1, b2, b3; + ::MediaRead(m_pMedium, &b0); + ::MediaRead(m_pMedium, &b1); + ::MediaRead(m_pMedium, &b2); + ::MediaRead(m_pMedium, &b3); + n.m_nID = b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); if (m_pMedium->m_fError) m_bError = true; } else m_bError = true; diff --git a/src/win95/media.hpp b/src/win95/media.hpp index 916e5e6..83035b3 100644 --- a/src/win95/media.hpp +++ b/src/win95/media.hpp @@ -4,24 +4,14 @@ #include <stdio.h> #include <limits.h> #include <string.h> - -class MediaMedium; - -// use this to read in simple data types -// note especially that if the size of TYPE is greater than the -// default buffer size, then the operation will fail -// and the virtual end of file error flag will be set -// - use ReadBlock instead -template <class TYPE> -void MediaRead(MediaMedium * pThis, TYPE * p); -// use this to write simple data types -// note especially that if the size of TYPE is greater than the -// default buffer size, then the operation will fail -// and the virtual end of file error flag will be set -// - use WriteBlock instead -template <class TYPE> -void MediaWrite(MediaMedium * pThis, TYPE d); +// type names that do not conflcit with anything else +typedef signed char S8; +typedef unsigned char U8; +typedef signed short int S16; +typedef unsigned short int U16; +typedef signed int S32; +typedef unsigned int U32; class MediaMedium { @@ -270,62 +260,13 @@ class MediaMedium virtual void DoSetPos(unsigned nPos) = 0; friend class MediaSection; - - friend class _Media_CompilerHack; -}; -class _Media_CompilerHack -{ - public: - template <class TYPE> - static inline void MediaRead(MediaMedium * pThis, TYPE * p) - { - if (pThis->m_nReadBufPos + sizeof(TYPE) <= pThis->m_nBufSize) - { - *p = *reinterpret_cast<TYPE const *>(static_cast<char const *>(pThis->m_pReadBuffer) + pThis->m_nReadBufPos/sizeof(char)); - - pThis->m_nReadBufPos += sizeof(TYPE); - } - else - { - pThis->Flush(); - pThis->m_pReadBuffer = pThis->GetReadBuffer(&pThis->m_nBufSize,pThis->m_nDefBufSize); - if (sizeof(TYPE) <= pThis->m_nBufSize) - { - *p = *static_cast<TYPE const *>(pThis->m_pReadBuffer); - pThis->m_nReadBufPos = sizeof(TYPE); - } - else - { - pThis->m_fError |= MediaMedium::MME_VEOFMET; - } - } - } - - template <class TYPE> - static inline void MediaWrite(MediaMedium * pThis, TYPE d) - { - if (pThis->m_nWriteBufPos + sizeof(TYPE) <= pThis->m_nBufSize) - { - *reinterpret_cast<TYPE *>(static_cast<char *>(pThis->m_pWriteBuffer) + pThis->m_nWriteBufPos/sizeof(char)) = d; - - pThis->m_nWriteBufPos += sizeof(TYPE); - } - else - { - pThis->Flush(); - pThis->m_pWriteBuffer = pThis->GetWriteBuffer(&pThis->m_nBufSize,pThis->m_nDefBufSize); - if (sizeof(TYPE) <= pThis->m_nBufSize) - { - *static_cast<TYPE *>(pThis->m_pWriteBuffer) = d; - pThis->m_nWriteBufPos = sizeof(TYPE); - } - else - { - pThis->m_fError |= MediaMedium::MME_VEOFMET; - } - } - } + friend void MediaRead(MediaMedium * pThis, S8 * p); + friend void MediaRead(MediaMedium * pThis, U8 * p); + friend void MediaRead(MediaMedium * pThis, S16 * p); + friend void MediaRead(MediaMedium * pThis, U16 * p); + friend void MediaRead(MediaMedium * pThis, S32 * p); + friend void MediaRead(MediaMedium * pThis, U32 * p); }; // use this to read in simple data types @@ -333,21 +274,86 @@ class _Media_CompilerHack // default buffer size, then the operation will fail // and the virtual end of file error flag will be set // - use ReadBlock instead -template <class TYPE> -inline void MediaRead(MediaMedium * pThis, TYPE * p) +inline void MediaRead(MediaMedium * pThis, S8 * p) { - _Media_CompilerHack::MediaRead(pThis,p); + if (pThis->m_nReadBufPos + sizeof(S8) <= pThis->m_nBufSize) + { + *p = static_cast<S8 const *>(pThis->m_pReadBuffer)[pThis->m_nReadBufPos]; + pThis->m_nReadBufPos += sizeof(S8); + } + else + { + pThis->Flush(); + pThis->m_pReadBuffer = pThis->GetReadBuffer(&pThis->m_nBufSize,pThis->m_nDefBufSize); + if (sizeof(S8) <= pThis->m_nBufSize) + { + *p = *static_cast<S8 const *>(pThis->m_pReadBuffer); + pThis->m_nReadBufPos = sizeof(S8); + } + else + { + pThis->m_fError |= MediaMedium::MME_VEOFMET; + } + } } -// use this to write simple data types -// note especially that if the size of TYPE is greater than the -// default buffer size, then the operation will fail -// and the virtual end of file error flag will be set -// - use WriteBlock instead -template <class TYPE> -inline void MediaWrite(MediaMedium * pThis, TYPE d) +inline void MediaRead(MediaMedium * pThis, U8 * p) +{ + if (pThis->m_nReadBufPos + sizeof(U8) <= pThis->m_nBufSize) + { + *p = static_cast<U8 const *>(pThis->m_pReadBuffer)[pThis->m_nReadBufPos]; + pThis->m_nReadBufPos += sizeof(U8); + } + else + { + pThis->Flush(); + pThis->m_pReadBuffer = pThis->GetReadBuffer(&pThis->m_nBufSize,pThis->m_nDefBufSize); + if (sizeof(U8) <= pThis->m_nBufSize) + { + *p = *static_cast<U8 const *>(pThis->m_pReadBuffer); + pThis->m_nReadBufPos = sizeof(U8); + } + else + { + pThis->m_fError |= MediaMedium::MME_VEOFMET; + } + } +} + +inline void MediaRead(MediaMedium * pThis, S16 * p) +{ + S8 b0, b1; + ::MediaRead(pThis, &b0); + ::MediaRead(pThis, &b1); + *p = (b0 << 0) | (b1 << 8); +} + +inline void MediaRead(MediaMedium * pThis, U16 * p) +{ + U8 b0, b1; + ::MediaRead(pThis, &b0); + ::MediaRead(pThis, &b1); + *p = (b0 << 0) | (b1 << 8); +} + +inline void MediaRead(MediaMedium * pThis, S32 * p) +{ + S8 b0, b1, b2, b3; + ::MediaRead(pThis, &b0); + ::MediaRead(pThis, &b1); + ::MediaRead(pThis, &b2); + ::MediaRead(pThis, &b3); + *p = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24); +} + +inline void MediaRead(MediaMedium * pThis, U32 * p) { - _Media_CompilerHack::MediaWrite(pThis,d); + U8 b0, b1, b2, b3; + ::MediaRead(pThis, &b0); + ::MediaRead(pThis, &b1); + ::MediaRead(pThis, &b2); + ::MediaRead(pThis, &b3); + *p = (b0 << 0) | (b1 << 8) | (b2 << 16) | (b3 << 24); } #ifdef _MEDIA_WIN_TARGET diff --git a/src/win95/shpchunk.cpp b/src/win95/shpchunk.cpp index 779045b..341e5e7 100644 --- a/src/win95/shpchunk.cpp +++ b/src/win95/shpchunk.cpp @@ -1,5 +1,5 @@ #include <math.h> - +#include "unaligned.h" #include "chunk.hpp" #include "chnktype.hpp" #include "shpchunk.hpp" @@ -1610,9 +1610,9 @@ Shape_External_Filename_Chunk::Shape_External_Filename_Chunk(Chunk_With_Children Shape_External_Filename_Chunk::Shape_External_Filename_Chunk (Chunk_With_Children * parent, const char *fdata, size_t /*fsize*/) : Chunk (parent, "SHPEXTFN") { - rescale = *((double *) fdata); + rescale = *((unaligned_f64 *) fdata); fdata += 8; - version_no = *((int *) fdata); + version_no = *((unaligned_s32 *) fdata); fdata += 4; file_name = new char [strlen(fdata)+1]; strcpy (file_name, fdata); |
