aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-03-13 04:57:25 +0100
committerEinar Johan Trøan Sømåen2012-06-02 12:12:36 +0200
commitafee4aeacccf66f52fefacbb0904049f0ce45227 (patch)
treebc55768384380e3d9bcbc477f6ae10e30bc92149 /engines
parentf33e2d1824738ebe76d26a89498627ca13814e7f (diff)
downloadscummvm-rg350-afee4aeacccf66f52fefacbb0904049f0ce45227.tar.gz
scummvm-rg350-afee4aeacccf66f52fefacbb0904049f0ce45227.tar.bz2
scummvm-rg350-afee4aeacccf66f52fefacbb0904049f0ce45227.zip
WINTERMUTE: One big and ugly commit that resolves most of the forbidden-symbols.
The StringUtils aren't complete or tested, and the SysClasses are a hack, and there are a few "FORBIDDEN_SYMBOL_EXCEPTIONS". Expect this commit to need a bunch of cleanup going forwards.
Diffstat (limited to 'engines')
-rw-r--r--engines/wintermute/AdObject.cpp43
-rw-r--r--engines/wintermute/BBase.cpp10
-rw-r--r--engines/wintermute/BBase.h13
-rw-r--r--engines/wintermute/BFader.cpp3
-rw-r--r--engines/wintermute/BFileEntry.h2
-rw-r--r--engines/wintermute/BFileManager.cpp20
-rw-r--r--engines/wintermute/BFileManager.h4
-rw-r--r--engines/wintermute/BFontBitmap.cpp6
-rw-r--r--engines/wintermute/BFontTT.cpp23
-rw-r--r--engines/wintermute/BFontTT.h6
-rw-r--r--engines/wintermute/BGame.cpp15
-rw-r--r--engines/wintermute/BGame.h2
-rw-r--r--engines/wintermute/BObject.h4
-rw-r--r--engines/wintermute/BParser.cpp3
-rw-r--r--engines/wintermute/BPkgFile.cpp9
-rw-r--r--engines/wintermute/BRegistry.cpp21
-rw-r--r--engines/wintermute/BRegistry.h4
-rw-r--r--engines/wintermute/BStringTable.cpp12
-rw-r--r--engines/wintermute/BStringTable.h6
-rw-r--r--engines/wintermute/BTransitionMgr.cpp4
-rw-r--r--engines/wintermute/BViewport.cpp8
-rw-r--r--engines/wintermute/FontGlyphCache.cpp6
-rw-r--r--engines/wintermute/FontGlyphCache.h3
-rw-r--r--engines/wintermute/PathUtil.cpp40
-rw-r--r--engines/wintermute/StringUtil.cpp154
-rw-r--r--engines/wintermute/StringUtil.h6
-rw-r--r--engines/wintermute/SysClass.cpp70
-rw-r--r--engines/wintermute/SysClass.h23
-rw-r--r--engines/wintermute/SysClassRegistry.cpp35
-rw-r--r--engines/wintermute/SysClassRegistry.h34
-rw-r--r--engines/wintermute/SysInstance.cpp1
-rw-r--r--engines/wintermute/UIEdit.cpp17
-rw-r--r--engines/wintermute/dctypes.h29
-rw-r--r--engines/wintermute/scriptables/ScEngine.h2
-rw-r--r--engines/wintermute/scriptables/ScValue.cpp2
-rw-r--r--engines/wintermute/tinystr.cpp111
-rw-r--r--engines/wintermute/tinystr.h305
-rw-r--r--engines/wintermute/tinyxml.h2
-rw-r--r--engines/wintermute/utils.cpp12
-rw-r--r--engines/wintermute/wintermute.cpp4
-rw-r--r--engines/wintermute/wintypes.h4
41 files changed, 826 insertions, 252 deletions
diff --git a/engines/wintermute/AdObject.cpp b/engines/wintermute/AdObject.cpp
index 11552b1488..0e2a351ed4 100644
--- a/engines/wintermute/AdObject.cpp
+++ b/engines/wintermute/AdObject.cpp
@@ -27,29 +27,30 @@
*/
#include "dcgf.h"
-#include "AdObject.h"
-#include "AdScene.h"
-#include "BGame.h"
-#include "BFrame.h"
-#include "BSound.h"
-#include "BSurfaceStorage.h"
-#include "engines/wintermute/scriptables/ScValue.h"
-#include "AdGame.h"
-#include "AdLayer.h"
-#include "AdSceneNode.h"
-#include "AdInventory.h"
-#include "AdWaypointGroup.h"
-#include "AdItem.h"
-#include "BSubFrame.h"
-#include "BFont.h"
-#include "BFontStorage.h"
+#include "engines/wintermute/AdGame.h"
+#include "engines/wintermute/AdItem.h"
+#include "engines/wintermute/AdObject.h"
+#include "engines/wintermute/AdInventory.h"
+#include "engines/wintermute/AdLayer.h"
+#include "engines/wintermute/AdScene.h"
+#include "engines/wintermute/AdSceneNode.h"
+#include "engines/wintermute/AdSentence.h"
+#include "engines/wintermute/AdWaypointGroup.h"
+#include "engines/wintermute/BGame.h"
+#include "engines/wintermute/BFrame.h"
+#include "engines/wintermute/BSound.h"
+#include "engines/wintermute/BSurfaceStorage.h"
+#include "engines/wintermute/BSubFrame.h"
+#include "engines/wintermute/BFont.h"
+#include "engines/wintermute/BFontStorage.h"
+#include "engines/wintermute/BSprite.h"
+#include "engines/wintermute/BStringTable.h"
#include "engines/wintermute/scriptables/ScEngine.h"
-#include "BStringTable.h"
-#include "AdSentence.h"
#include "engines/wintermute/scriptables/ScScript.h"
-#include "BSprite.h"
#include "engines/wintermute/scriptables/ScStack.h"
+#include "engines/wintermute/scriptables/ScValue.h"
#include "common/str.h"
+#include "common/util.h"
namespace WinterMute {
@@ -860,8 +861,8 @@ void CAdObject::Talk(char *Text, char *Sound, uint32 Duration, char *Stances, TT
}
// set duration by text length
- if (m_Sentence->m_Duration <= 0) {
- m_Sentence->m_Duration = MAX(1000, Game->m_SubtitlesSpeed * strlen(m_Sentence->m_Text));
+ if (m_Sentence->m_Duration <= 0) {// TODO: Avoid longs.
+ m_Sentence->m_Duration = MAX((unsigned long)1000, Game->m_SubtitlesSpeed * strlen(m_Sentence->m_Text));
}
diff --git a/engines/wintermute/BBase.cpp b/engines/wintermute/BBase.cpp
index 845543c351..536decb5f9 100644
--- a/engines/wintermute/BBase.cpp
+++ b/engines/wintermute/BBase.cpp
@@ -57,7 +57,9 @@ CBBase::~CBBase() {
//////////////////////////////////////////////////////////////////////////
const char *CBBase::GetEditorProp(const char *PropName, const char *InitVal) {
m_EditorPropsIter = m_EditorProps.find(PropName);
- if (m_EditorPropsIter != m_EditorProps.end()) return m_EditorPropsIter->second.c_str();
+ if (m_EditorPropsIter != m_EditorProps.end())
+ return m_EditorPropsIter->_value.c_str();
+ //return m_EditorPropsIter->second.c_str(); // <- TODO Clean
else return InitVal;
}
@@ -161,8 +163,10 @@ HRESULT CBBase::SaveAsText(CBDynBuffer *Buffer, int Indent) {
while (m_EditorPropsIter != m_EditorProps.end()) {
Buffer->PutTextIndent(Indent, "EDITOR_PROPERTY\n");
Buffer->PutTextIndent(Indent, "{\n");
- Buffer->PutTextIndent(Indent + 2, "NAME=\"%s\"\n", (char *)m_EditorPropsIter->first.c_str());
- Buffer->PutTextIndent(Indent + 2, "VALUE=\"%s\"\n", m_EditorPropsIter->second.c_str());
+ Buffer->PutTextIndent(Indent + 2, "NAME=\"%s\"\n", (char *)m_EditorPropsIter->_key.c_str());
+ Buffer->PutTextIndent(Indent + 2, "VALUE=\"%s\"\n", m_EditorPropsIter->_value.c_str());
+ //Buffer->PutTextIndent(Indent + 2, "NAME=\"%s\"\n", (char *)m_EditorPropsIter->first.c_str()); // <- TODO, remove
+ //Buffer->PutTextIndent(Indent + 2, "VALUE=\"%s\"\n", m_EditorPropsIter->second.c_str()); // <- TODO, remove
Buffer->PutTextIndent(Indent, "}\n\n");
m_EditorPropsIter++;
diff --git a/engines/wintermute/BBase.h b/engines/wintermute/BBase.h
index ba228bc572..c72d687eca 100644
--- a/engines/wintermute/BBase.h
+++ b/engines/wintermute/BBase.h
@@ -31,8 +31,11 @@
#include "wintypes.h"
#include "dctypes.h"
-#include <map>
-#include <string>
+#include "common/str.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+//#include <map>
+//#include <string>
namespace WinterMute {
@@ -52,8 +55,10 @@ public:
CBBase(CBGame *GameOwner);
virtual ~CBBase();
- std::map<std::string, std::string> m_EditorProps;
- std::map<std::string, std::string>::iterator m_EditorPropsIter;
+ Common::HashMap<Common::String, Common::String> m_EditorProps;
+ Common::HashMap<Common::String, Common::String>::iterator m_EditorPropsIter;
+/* std::map<std::string, std::string> m_EditorProps;
+ std::map<std::string, std::string>::iterator m_EditorPropsIter;*/
};
} // end of namespace WinterMute
diff --git a/engines/wintermute/BFader.cpp b/engines/wintermute/BFader.cpp
index f64023a08d..955f0252f5 100644
--- a/engines/wintermute/BFader.cpp
+++ b/engines/wintermute/BFader.cpp
@@ -30,6 +30,7 @@
#include "BFader.h"
#include "BGame.h"
#include "PlatformSDL.h"
+#include "common/util.h"
namespace WinterMute {
@@ -73,7 +74,7 @@ HRESULT CBFader::Update() {
else {
m_CurrentAlpha = m_SourceAlpha + (float)time / (float)m_Duration * AlphaDelta;
}
- m_CurrentAlpha = MIN(255, std::max(m_CurrentAlpha, (byte )0));
+ m_CurrentAlpha = MIN((unsigned char)255, MAX(m_CurrentAlpha, (byte )0)); // TODO: clean
m_Ready = time >= m_Duration;
if (m_Ready && m_CurrentAlpha == 0x00) m_Active = false;
diff --git a/engines/wintermute/BFileEntry.h b/engines/wintermute/BFileEntry.h
index cfad80926c..2c555c8bfe 100644
--- a/engines/wintermute/BFileEntry.h
+++ b/engines/wintermute/BFileEntry.h
@@ -42,7 +42,7 @@ public:
uint32 m_TimeDate1;
uint32 m_Flags;
uint32 m_JournalTime;
- std::string m_Filename;
+ Common::String m_Filename;
uint32 m_CompressedLength;
uint32 m_Length;
uint32 m_Offset;
diff --git a/engines/wintermute/BFileManager.cpp b/engines/wintermute/BFileManager.cpp
index ce0de04596..8763506e99 100644
--- a/engines/wintermute/BFileManager.cpp
+++ b/engines/wintermute/BFileManager.cpp
@@ -43,6 +43,7 @@
#include "PlatformSDL.h"
#include "common/str.h"
#include "common/textconsole.h"
+#include "common/util.h"
//#include <boost/filesystem.hpp>
#ifdef __WIN32__
@@ -106,7 +107,7 @@ HRESULT CBFileManager::Cleanup() {
// delete file entries
m_FilesIter = m_Files.begin();
while (m_FilesIter != m_Files.end()) {
- delete m_FilesIter->second;
+ delete m_FilesIter->_value;
m_FilesIter++;
}
m_Files.clear();
@@ -491,7 +492,6 @@ HRESULT CBFileManager::RegisterPackage(const char *Path, const char *Name, bool
fread(&TimeDate1, sizeof(uint32), 1, f);
fread(&TimeDate2, sizeof(uint32), 1, f);
}
-
m_FilesIter = m_Files.find(Name);
if (m_FilesIter == m_Files.end()) {
CBFileEntry *file = new CBFileEntry(Game);
@@ -504,12 +504,12 @@ HRESULT CBFileManager::RegisterPackage(const char *Path, const char *Name, bool
m_Files[Name] = file;
} else {
// current package has lower CD number or higher priority, than the registered
- if (pkg->m_CD < m_FilesIter->second->m_Package->m_CD || pkg->m_Priority > m_FilesIter->second->m_Package->m_Priority) {
- m_FilesIter->second->m_Package = pkg;
- m_FilesIter->second->m_Offset = Offset;
- m_FilesIter->second->m_Length = Length;
- m_FilesIter->second->m_CompressedLength = CompLength;
- m_FilesIter->second->m_Flags = Flags;
+ if (pkg->m_CD < m_FilesIter->_value->m_Package->m_CD || pkg->m_Priority > m_FilesIter->_value->m_Package->m_Priority) {
+ m_FilesIter->_value->m_Package = pkg;
+ m_FilesIter->_value->m_Offset = Offset;
+ m_FilesIter->_value->m_Length = Length;
+ m_FilesIter->_value->m_CompressedLength = CompLength;
+ m_FilesIter->_value->m_Flags = Flags;
}
}
delete [] Name;
@@ -605,7 +605,7 @@ CBFileEntry *CBFileManager::GetPackageEntry(const char *Filename) {
CBFileEntry *ret = NULL;
m_FilesIter = m_Files.find(upc_name);
- if (m_FilesIter != m_Files.end()) ret = m_FilesIter->second;
+ if (m_FilesIter != m_Files.end()) ret = m_FilesIter->_value;
delete [] upc_name;
@@ -721,7 +721,7 @@ bool CBFileManager::FindPackageSignature(FILE *f, uint32 *Offset) {
int BytesRead = StartPos;
while (BytesRead < FileSize - 16) {
- int ToRead = MIN(32768, FileSize - BytesRead);
+ int ToRead = MIN((unsigned int)32768, FileSize - BytesRead);
fseek(f, StartPos, SEEK_SET);
int ActuallyRead = fread(buf, 1, ToRead, f);
if (ActuallyRead != ToRead) return false;
diff --git a/engines/wintermute/BFileManager.h b/engines/wintermute/BFileManager.h
index e585841a4a..849a30bf8e 100644
--- a/engines/wintermute/BFileManager.h
+++ b/engines/wintermute/BFileManager.h
@@ -68,10 +68,10 @@ public:
CBArray<CBPackage *, CBPackage *> m_Packages;
CBArray<CBFile *, CBFile *> m_OpenFiles;
- std::map<std::string, CBFileEntry *> m_Files;
+ Common::HashMap<Common::String, CBFileEntry *> m_Files;
private:
HRESULT RegisterPackage(const char *Path, const char *Name, bool SearchSignature = false);
- std::map<std::string, CBFileEntry *>::iterator m_FilesIter;
+ Common::HashMap<Common::String, CBFileEntry *>::iterator m_FilesIter;
bool IsValidPackage(const AnsiString &fileName) const;
};
diff --git a/engines/wintermute/BFontBitmap.cpp b/engines/wintermute/BFontBitmap.cpp
index 4b5b0c6199..9b49a84079 100644
--- a/engines/wintermute/BFontBitmap.cpp
+++ b/engines/wintermute/BFontBitmap.cpp
@@ -92,10 +92,12 @@ int CBFontBitmap::GetTextWidth(byte *text, int MaxLength) {
str = AnsiString((char *)text);
}
- if (MaxLength >= 0 && str.length() > MaxLength) str = str.substr(0, MaxLength);
+ if (MaxLength >= 0 && str.size() > MaxLength)
+ str = Common::String(str.c_str(), MaxLength);
+ //str.substr(0, MaxLength); // TODO: Remove
int TextWidth = 0;
- for (size_t i = 0; i < str.length(); i++) {
+ for (size_t i = 0; i < str.size(); i++) {
TextWidth += GetCharWidth(str[i]);
}
diff --git a/engines/wintermute/BFontTT.cpp b/engines/wintermute/BFontTT.cpp
index a1ca6577fa..398d3bb1d9 100644
--- a/engines/wintermute/BFontTT.cpp
+++ b/engines/wintermute/BFontTT.cpp
@@ -124,7 +124,9 @@ int CBFontTT::GetTextWidth(byte *Text, int MaxLength) {
if (Game->m_TextEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
else text = StringUtil::AnsiToWide((char *)Text);
- if (MaxLength >= 0 && text.length() > MaxLength) text = text.substr(0, MaxLength);
+ if (MaxLength >= 0 && text.size() > MaxLength)
+ text = Common::String(text.c_str(), MaxLength);
+ //text = text.substr(0, MaxLength); // TODO: Remove
int textWidth, textHeight;
MeasureText(text, -1, -1, textWidth, textHeight);
@@ -156,7 +158,9 @@ void CBFontTT::DrawText(byte *Text, int X, int Y, int Width, TTextAlign Align,
if (Game->m_TextEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text);
else text = StringUtil::AnsiToWide((char *)Text);
- if (MaxLength >= 0 && text.length() > MaxLength) text = text.substr(0, MaxLength);
+ if (MaxLength >= 0 && text.size() > MaxLength)
+ text = Common::String(text.c_str(), MaxLength);
+ //text = text.substr(0, MaxLength); // TODO: Remove
CBRenderSDL *m_Renderer = (CBRenderSDL *)Game->m_Renderer;
@@ -258,7 +262,7 @@ CBSurface *CBFontTT::RenderTextToTexture(const WideString &text, int width, TTex
textOffset = 0;
- for (size_t i = 0; i < line->GetText().length(); i++) {
+ for (size_t i = 0; i < line->GetText().size(); i++) {
wchar_t ch = line->GetText()[i];
GlyphInfo *glyph = m_GlyphCache->GetGlyph(ch);
@@ -271,7 +275,7 @@ CBSurface *CBFontTT::RenderTextToTexture(const WideString &text, int width, TTex
int origPosX = posX;
wchar_t prevChar = L'\0';
- for (size_t i = 0; i < line->GetText().length(); i++) {
+ for (size_t i = 0; i < line->GetText().size(); i++) {
wchar_t ch = line->GetText()[i];
GlyphInfo *glyph = m_GlyphCache->GetGlyph(ch);
@@ -700,7 +704,7 @@ void CBFontTT::WrapText(const WideString &text, int maxWidth, int maxHeight, Tex
PrepareGlyphs(text);
- for (size_t i = 0; i < text.length(); i++) {
+ for (size_t i = 0; i < text.size(); i++) {
wchar_t ch = text[i];
if (ch == L' ') {
@@ -728,7 +732,7 @@ void CBFontTT::WrapText(const WideString &text, int maxWidth, int maxHeight, Tex
if (lineTooLong && currWidth == 0) break;
- if (ch == L'\n' || i == text.length() - 1 || lineTooLong) {
+ if (ch == L'\n' || i == text.size() - 1 || lineTooLong) {
int breakPoint, breakWidth;
if (prevSpaceIndex >= 0 && lineTooLong) {
@@ -742,7 +746,7 @@ void CBFontTT::WrapText(const WideString &text, int maxWidth, int maxHeight, Tex
breakOnSpace = (ch == L'\n');
// we're at the end
- if (i == text.length() - 1) {
+ if (i == text.size() - 1) {
breakPoint++;
breakWidth += charWidth;
}
@@ -750,7 +754,8 @@ void CBFontTT::WrapText(const WideString &text, int maxWidth, int maxHeight, Tex
if (maxHeight >= 0 && (lines.size() + 1) * GetLineHeight() > maxHeight) break;
- WideString line = text.substr(lineStartIndex, breakPoint - lineStartIndex);
+ //WideString line = text.substr(lineStartIndex, breakPoint - lineStartIndex); // TODO: Remove
+ WideString line = Common::String(text.c_str() + lineStartIndex, breakPoint - lineStartIndex);
lines.push_back(new TextLine(line, breakWidth));
currWidth = 0;
@@ -805,7 +810,7 @@ float CBFontTT::GetKerning(wchar_t leftChar, wchar_t rightChar) {
//////////////////////////////////////////////////////////////////////////
void CBFontTT::PrepareGlyphs(const WideString &text) {
// make sure we have all the glyphs we need
- for (size_t i = 0; i < text.length(); i++) {
+ for (size_t i = 0; i < text.size(); i++) {
wchar_t ch = text[i];
if (!m_GlyphCache->HasGlyph(ch)) CacheGlyph(ch);
}
diff --git a/engines/wintermute/BFontTT.h b/engines/wintermute/BFontTT.h
index 6fbb019a27..5675cca5de 100644
--- a/engines/wintermute/BFontTT.h
+++ b/engines/wintermute/BFontTT.h
@@ -35,6 +35,7 @@
#define NUM_CACHED_TEXTS 30
class SDL_Surface;
+class SDL_Rect;
namespace WinterMute {
class FontGlyphCache;
@@ -55,7 +56,8 @@ private:
bool m_Marked;
CBCachedTTFontText() {
- m_Text = L"";
+ //m_Text = L"";
+ m_Text = "";
m_Width = m_MaxHeight = m_MaxLength = -1;
m_Align = TAL_LEFT;
m_Surface = NULL;
@@ -108,7 +110,7 @@ public:
WideString m_Text;
int m_Width;
};
- typedef std::list<TextLine *> TextLineList;
+ typedef Common::List<TextLine *> TextLineList;
public:
diff --git a/engines/wintermute/BGame.cpp b/engines/wintermute/BGame.cpp
index a4329fc5df..5cc048b48d 100644
--- a/engines/wintermute/BGame.cpp
+++ b/engines/wintermute/BGame.cpp
@@ -68,6 +68,7 @@
#include "engines/wintermute/scriptables/SXStore.h"
#include "engines/wintermute/scriptables/SXString.h"
#include "common/textconsole.h"
+#include "common/util.h"
#ifdef __IPHONEOS__
# include "ios_utils.h"
@@ -514,7 +515,7 @@ void CBGame::DEBUG_DebugEnable(const char *Filename) {
m_DEBUG_LogFile = fopen(safeLogFileName.c_str(), "a+");
}
- if (m_DEBUG_LogFile != NULL) fprintf(m_DEBUG_LogFile, "\n");
+ if (m_DEBUG_LogFile != NULL) fprintf((FILE*)m_DEBUG_LogFile, "\n");
#endif
time_t timeNow;
@@ -540,7 +541,7 @@ void CBGame::DEBUG_DebugEnable(const char *Filename) {
void CBGame::DEBUG_DebugDisable() {
if (m_DEBUG_LogFile != NULL) {
LOG(0, "********** DEBUG LOG CLOSED ********************************************");
- fclose(m_DEBUG_LogFile);
+ fclose((FILE*)m_DEBUG_LogFile);
m_DEBUG_LogFile = NULL;
}
m_DEBUG_DebugMode = false;
@@ -576,8 +577,8 @@ void CBGame::LOG(HRESULT res, LPCSTR fmt, ...) {
if (m_DebugMgr) m_DebugMgr->OnLog(res, buff);
warning("%02d:%02d: %s\n", tm->tm_hour, tm->tm_min, buff);
- fprintf(m_DEBUG_LogFile, "%02d:%02d: %s\n", tm->tm_hour, tm->tm_min, buff);
- fflush(m_DEBUG_LogFile);
+ fprintf((FILE*)m_DEBUG_LogFile, "%02d:%02d: %s\n", tm->tm_hour, tm->tm_min, buff);
+ fflush((FILE*)m_DEBUG_LogFile);
#endif
//QuickMessage(buff);
@@ -615,12 +616,12 @@ HRESULT CBGame::InitLoop() {
m_LiveTimerDelta = m_LiveTimer - m_LiveTimerLast;
m_LiveTimerLast = m_LiveTimer;
- m_LiveTimer += MIN(1000, m_DeltaTime);
+ m_LiveTimer += MIN((uint32)1000, m_DeltaTime);
if (m_State != GAME_FROZEN) {
m_TimerDelta = m_Timer - m_TimerLast;
m_TimerLast = m_Timer;
- m_Timer += MIN(1000, m_DeltaTime);
+ m_Timer += MIN((uint32)1000, m_DeltaTime);
} else m_TimerDelta = 0;
m_FramesRendered++;
@@ -2015,7 +2016,7 @@ HRESULT CBGame::ScCallMethod(CScScript *Script, CScStack *Stack, CScStack *ThisS
int BytesRead = 0;
while (BytesRead < File->GetSize()) {
- int BufSize = MIN(1024, File->GetSize() - BytesRead);
+ int BufSize = MIN((uint32)1024, File->GetSize() - BytesRead);
BytesRead += BufSize;
File->Read(Buf, BufSize);
diff --git a/engines/wintermute/BGame.h b/engines/wintermute/BGame.h
index 610915d154..5de2beacc3 100644
--- a/engines/wintermute/BGame.h
+++ b/engines/wintermute/BGame.h
@@ -191,7 +191,7 @@ public:
bool m_DEBUG_DebugMode;
bool m_DEBUG_AbsolutePathWarning;
- FILE *m_DEBUG_LogFile;
+ void *m_DEBUG_LogFile;
int m_Sequence;
virtual HRESULT LoadFile(const char *Filename);
virtual HRESULT LoadBuffer(byte *Buffer, bool Complete = true);
diff --git a/engines/wintermute/BObject.h b/engines/wintermute/BObject.h
index 064cc78fc4..3fd22fafcd 100644
--- a/engines/wintermute/BObject.h
+++ b/engines/wintermute/BObject.h
@@ -30,10 +30,12 @@
#define WINTERMUTE_BOBJECT_H
-#include "SDL.h"
+//#include "SDL.h"
#include "BScriptHolder.h"
#include "persistent.h"
+union SDL_Event;
+
namespace WinterMute {
class CBSprite;
diff --git a/engines/wintermute/BParser.cpp b/engines/wintermute/BParser.cpp
index de8dd140d2..94de0771f9 100644
--- a/engines/wintermute/BParser.cpp
+++ b/engines/wintermute/BParser.cpp
@@ -31,6 +31,7 @@
#include "BGame.h"
#include "PlatformSDL.h"
#include "common/str.h"
+#include "common/util.h"
#define WHITESPACE " \t\n\r"
@@ -88,7 +89,7 @@ long CBParser::GetObject(char **buf, TokenDesc *tokens, char **name, char **data
if (tokens->id == 0) {
char *p = strchr(*buf, '\n');
if (p && p > *buf) {
- strncpy(m_LastOffender, *buf, MIN(255, p - *buf));
+ strncpy(m_LastOffender, *buf, MIN((long int)255, p - *buf)); // TODO, clean
} else strcpy(m_LastOffender, "");
return PARSERR_TOKENNOTFOUND;
diff --git a/engines/wintermute/BPkgFile.cpp b/engines/wintermute/BPkgFile.cpp
index 1210d90e24..deac1c8817 100644
--- a/engines/wintermute/BPkgFile.cpp
+++ b/engines/wintermute/BPkgFile.cpp
@@ -31,6 +31,7 @@
#include "BPkgFile.h"
#include "BGame.h"
#include "BFileManager.h"
+#include "common/util.h"
#if _DEBUG
#pragma comment(lib, "zlib_d.lib")
@@ -131,7 +132,7 @@ HRESULT CBPkgFile::Read(void *Buffer, uint32 Size) {
while (m_Stream.total_out - InitOut < Size && m_Stream.total_in < m_FileEntry->m_CompressedLength) {
// needs to read more data?
if (m_Stream.avail_in == 0) {
- m_Stream.avail_in = MIN(COMPRESSED_BUFFER_SIZE, m_FileEntry->m_CompressedLength - m_Stream.total_in);
+ m_Stream.avail_in = MIN((long unsigned int)COMPRESSED_BUFFER_SIZE, m_FileEntry->m_CompressedLength - m_Stream.total_in); // TODO: long unsigned int????
m_FileEntry->m_Package->Read(m_File, m_FileEntry->m_Offset + m_Stream.total_in, m_CompBuffer, m_Stream.avail_in);
m_Stream.next_in = m_CompBuffer;
}
@@ -192,7 +193,7 @@ HRESULT CBPkgFile::SeekToPos(uint32 NewPos) {
m_Stream.avail_in = 0;
m_Stream.next_in = m_CompBuffer;
- m_Stream.avail_out = MIN(STREAM_BUFFER_SIZE, NewPos);
+ m_Stream.avail_out = MIN((uint32)STREAM_BUFFER_SIZE, NewPos); //TODO: remove cast.
m_Stream.next_out = StreamBuffer;
inflateInit(&m_Stream);
m_InflateInit = true;
@@ -200,7 +201,7 @@ HRESULT CBPkgFile::SeekToPos(uint32 NewPos) {
while (m_Stream.total_out < NewPos && m_Stream.total_in < m_FileEntry->m_CompressedLength) {
// needs to read more data?
if (m_Stream.avail_in == 0) {
- m_Stream.avail_in = MIN(COMPRESSED_BUFFER_SIZE, m_FileEntry->m_CompressedLength - m_Stream.total_in);
+ m_Stream.avail_in = MIN((long unsigned int)COMPRESSED_BUFFER_SIZE, m_FileEntry->m_CompressedLength - m_Stream.total_in); // TODO: long unsigned int???
m_FileEntry->m_Package->Read(m_File, m_FileEntry->m_Offset + m_Stream.total_in, m_CompBuffer, m_Stream.avail_in);
m_Stream.next_in = m_CompBuffer;
}
@@ -208,7 +209,7 @@ HRESULT CBPkgFile::SeekToPos(uint32 NewPos) {
// needs more space?
if (m_Stream.avail_out == 0) {
m_Stream.next_out = StreamBuffer;
- m_Stream.avail_out = MIN(STREAM_BUFFER_SIZE, NewPos - m_Stream.total_out);
+ m_Stream.avail_out = MIN((long unsigned int)STREAM_BUFFER_SIZE, NewPos - m_Stream.total_out); // TODO: long unsigned int???.
}
// stream on!
diff --git a/engines/wintermute/BRegistry.cpp b/engines/wintermute/BRegistry.cpp
index 4d7b1b6d37..75b621d90f 100644
--- a/engines/wintermute/BRegistry.cpp
+++ b/engines/wintermute/BRegistry.cpp
@@ -159,26 +159,27 @@ AnsiString CBRegistry::GetValue(PathValueMap &values, const AnsiString path, con
PathValueMap::iterator it = values.find(path);
if (it == values.end()) return "";
- KeyValuePair pairs = (*it).second;
+ KeyValuePair pairs = (*it)._value;
KeyValuePair::iterator keyIt = pairs.find(key);
if (keyIt == pairs.end()) return "";
else {
found = true;
- return (*keyIt).second;
+ return (*keyIt)._value;
}
}
//////////////////////////////////////////////////////////////////////////
void CBRegistry::LoadXml(const AnsiString fileName, PathValueMap &values) {
- TiXmlDocument doc(fileName);
+ TiXmlDocument doc(fileName.c_str());
if (!doc.LoadFile()) return;
TiXmlElement *rootElem = doc.RootElement();
- if (!rootElem || rootElem->ValueStr() != "Settings") return;
+ if (!rootElem || Common::String(rootElem->Value()) != "Settings") // TODO: Avoid this strcmp-use. (Hack for now, since we might drop TinyXML all together)
+ return;
for (TiXmlElement *pathElem = rootElem->FirstChildElement(); pathElem != NULL; pathElem = pathElem->NextSiblingElement()) {
for (TiXmlElement *keyElem = pathElem->FirstChildElement(); keyElem != NULL; keyElem = keyElem->NextSiblingElement()) {
- values[pathElem->ValueStr()][keyElem->ValueStr()] = keyElem->GetText();
+ values[Common::String(pathElem->Value())][Common::String(keyElem->Value())] = keyElem->GetText();
}
}
}
@@ -196,17 +197,17 @@ void CBRegistry::SaveXml(const AnsiString fileName, PathValueMap &values) {
PathValueMap::iterator pathIt;
for (pathIt = m_Values.begin(); pathIt != m_Values.end(); ++pathIt) {
- TiXmlElement *pathElem = new TiXmlElement((*pathIt).first);
+ TiXmlElement *pathElem = new TiXmlElement((*pathIt)._key.c_str());
root->LinkEndChild(pathElem);
- KeyValuePair pairs = (*pathIt).second;
+ KeyValuePair pairs = (*pathIt)._value;
KeyValuePair::iterator keyIt;
for (keyIt = pairs.begin(); keyIt != pairs.end(); ++keyIt) {
- TiXmlElement *keyElem = new TiXmlElement((*keyIt).first);
+ TiXmlElement *keyElem = new TiXmlElement((*keyIt)._key.c_str());
pathElem->LinkEndChild(keyElem);
- keyElem->LinkEndChild(new TiXmlText((*keyIt).second));
+ keyElem->LinkEndChild(new TiXmlText((*keyIt)._value.c_str()));
}
}
@@ -219,7 +220,7 @@ void CBRegistry::SaveXml(const AnsiString fileName, PathValueMap &values) {
if (!stream.is_open()) return;
else {
- stream << printer.Str();
+ stream << printer.CStr();
stream.close();
}
}
diff --git a/engines/wintermute/BRegistry.h b/engines/wintermute/BRegistry.h
index 48b88fd663..2838d3794f 100644
--- a/engines/wintermute/BRegistry.h
+++ b/engines/wintermute/BRegistry.h
@@ -57,8 +57,8 @@ public:
private:
char *m_IniName;
- typedef std::map<AnsiString, AnsiString> KeyValuePair;
- typedef std::map<AnsiString, KeyValuePair> PathValueMap;
+ typedef Common::HashMap<AnsiString, AnsiString> KeyValuePair;
+ typedef Common::HashMap<AnsiString, KeyValuePair> PathValueMap;
PathValueMap m_LocalValues;
PathValueMap m_Values;
diff --git a/engines/wintermute/BStringTable.cpp b/engines/wintermute/BStringTable.cpp
index e3bf2fd89b..fda4853115 100644
--- a/engines/wintermute/BStringTable.cpp
+++ b/engines/wintermute/BStringTable.cpp
@@ -58,7 +58,7 @@ HRESULT CBStringTable::AddString(const char *Key, const char *Val, bool ReportDu
return S_OK;
}
- std::string final_key = Key;
+ Common::String final_key = Key;
StringUtil::ToLowerCase(final_key);
m_StringsIter = m_Strings.find(final_key);
@@ -85,8 +85,8 @@ char *CBStringTable::GetKey(const char *Str) {
m_StringsIter = m_Strings.find(key);
if (m_StringsIter != m_Strings.end()) {
- new_str = new char[m_StringsIter->second.length() + 1];
- strcpy(new_str, m_StringsIter->second.c_str());
+ new_str = new char[m_StringsIter->_value.size() + 1];
+ strcpy(new_str, m_StringsIter->_value.c_str());
if (strlen(new_str) > 0 && new_str[0] == '/' && strchr(new_str + 1, '/')) {
delete [] key;
char *Ret = GetKey(new_str);
@@ -121,8 +121,8 @@ void CBStringTable::Expand(char **Str, bool ForceExpand) {
m_StringsIter = m_Strings.find(key);
if (m_StringsIter != m_Strings.end()) {
- new_str = new char[m_StringsIter->second.length() + 1];
- strcpy(new_str, m_StringsIter->second.c_str());
+ new_str = new char[m_StringsIter->_value.size() + 1];
+ strcpy(new_str, m_StringsIter->_value.c_str());
} else {
new_str = new char[strlen(value) + 1];
strcpy(new_str, value);
@@ -156,7 +156,7 @@ const char *CBStringTable::ExpandStatic(const char *String, bool ForceExpand) {
m_StringsIter = m_Strings.find(key);
if (m_StringsIter != m_Strings.end()) {
- new_str = m_StringsIter->second.c_str();
+ new_str = m_StringsIter->_value.c_str();
} else {
new_str = value;
}
diff --git a/engines/wintermute/BStringTable.h b/engines/wintermute/BStringTable.h
index 6b28f5307d..28617c8593 100644
--- a/engines/wintermute/BStringTable.h
+++ b/engines/wintermute/BStringTable.h
@@ -30,7 +30,7 @@
#define WINTERMUTE_BSTRINGTABLE_H
-#include <map>
+#include "common/hashmap.h"
#include "BBase.h"
namespace WinterMute {
@@ -43,10 +43,10 @@ public:
HRESULT AddString(const char *Key, const char *Val, bool ReportDuplicities = true);
CBStringTable(CBGame *inGame);
virtual ~CBStringTable();
- std::map<std::string, std::string> m_Strings;
+ Common::HashMap<Common::String, Common::String> m_Strings;
char *GetKey(const char *Str);
private:
- std::map<std::string, std::string>::iterator m_StringsIter;
+ Common::HashMap<Common::String, Common::String>::iterator m_StringsIter;
};
diff --git a/engines/wintermute/BTransitionMgr.cpp b/engines/wintermute/BTransitionMgr.cpp
index 56703b3336..78fd43c545 100644
--- a/engines/wintermute/BTransitionMgr.cpp
+++ b/engines/wintermute/BTransitionMgr.cpp
@@ -98,7 +98,7 @@ HRESULT CBTransitionMgr::Update() {
case TRANSITION_FADE_OUT: {
uint32 time = CBPlatform::GetTime() - m_LastTime;
int Alpha = 255 - (float)time / (float)FADE_DURATION * 255;
- Alpha = std::min(255, std::max(Alpha, 0));
+ Alpha = MIN(255, MAX(Alpha, 0));
Game->m_Renderer->Fade((WORD)Alpha);
if (time > FADE_DURATION) m_State = TRANS_MGR_READY;
@@ -108,7 +108,7 @@ HRESULT CBTransitionMgr::Update() {
case TRANSITION_FADE_IN: {
uint32 time = CBPlatform::GetTime() - m_LastTime;
int Alpha = (float)time / (float)FADE_DURATION * 255;
- Alpha = std::min(255, std::max(Alpha, 0));
+ Alpha = MIN(255, MAX(Alpha, 0));
Game->m_Renderer->Fade((WORD)Alpha);
if (time > FADE_DURATION) m_State = TRANS_MGR_READY;
diff --git a/engines/wintermute/BViewport.cpp b/engines/wintermute/BViewport.cpp
index bb2f5b6b29..57cb1bc02f 100644
--- a/engines/wintermute/BViewport.cpp
+++ b/engines/wintermute/BViewport.cpp
@@ -65,10 +65,10 @@ HRESULT CBViewport::Persist(CBPersistMgr *PersistMgr) {
//////////////////////////////////////////////////////////////////////////
HRESULT CBViewport::SetRect(int left, int top, int right, int bottom, bool NoCheck) {
if (!NoCheck) {
- left = std::max(left, 0);
- top = std::max(top, 0);
- right = std::min(right, Game->m_Renderer->m_Width);
- bottom = std::min(bottom, Game->m_Renderer->m_Height);
+ left = MAX(left, 0);
+ top = MAX(top, 0);
+ right = MIN(right, Game->m_Renderer->m_Width);
+ bottom = MIN(bottom, Game->m_Renderer->m_Height);
}
CBPlatform::SetRect(&m_Rect, left, top, right, bottom);
diff --git a/engines/wintermute/FontGlyphCache.cpp b/engines/wintermute/FontGlyphCache.cpp
index 6181fb2704..04c7095dd1 100644
--- a/engines/wintermute/FontGlyphCache.cpp
+++ b/engines/wintermute/FontGlyphCache.cpp
@@ -36,8 +36,8 @@ FontGlyphCache::~FontGlyphCache() {
GlyphInfoMap::iterator it;
for (it = m_Glyphs.begin(); it != m_Glyphs.end(); ++it) {
- delete it->second;
- it->second = NULL;
+ delete it->_value;
+ it->_value = NULL;
}
}
@@ -56,7 +56,7 @@ GlyphInfo *FontGlyphCache::GetGlyph(wchar_t ch) {
it = m_Glyphs.find(ch);
if (it == m_Glyphs.end()) return NULL;
- return it->second;
+ return it->_value;
}
//////////////////////////////////////////////////////////////////////////
diff --git a/engines/wintermute/FontGlyphCache.h b/engines/wintermute/FontGlyphCache.h
index 50db962771..c30e0f92b8 100644
--- a/engines/wintermute/FontGlyphCache.h
+++ b/engines/wintermute/FontGlyphCache.h
@@ -111,7 +111,8 @@ public:
void AddGlyph(wchar_t ch, int glyphIndex, FT_GlyphSlot glyphSlot, size_t width, size_t height, byte *pixels, size_t stride = 0);
private:
- typedef std::map<wchar_t, GlyphInfo *> GlyphInfoMap;
+ //typedef Common::HashMap<wchar_t, GlyphInfo *> GlyphInfoMap;
+ typedef Common::HashMap<char, GlyphInfo *> GlyphInfoMap; // TODO
GlyphInfoMap m_Glyphs;
};
diff --git a/engines/wintermute/PathUtil.cpp b/engines/wintermute/PathUtil.cpp
index d7d632f398..aea35e395f 100644
--- a/engines/wintermute/PathUtil.cpp
+++ b/engines/wintermute/PathUtil.cpp
@@ -77,40 +77,48 @@ AnsiString PathUtil::Combine(const AnsiString &path1, const AnsiString &path2) {
AnsiString PathUtil::GetDirectoryName(const AnsiString &path) {
AnsiString newPath = UnifySeparators(path);
- size_t pos = newPath.find_last_of(L'/');
-
- if (pos == AnsiString::npos) return "";
- else return newPath.substr(0, pos + 1);
+ //size_t pos = newPath.find_last_of(L'/');
+ Common::String filename = GetFileName(path);
+ return Common::String(path.c_str(), path.size() - filename.size());
+ //if (pos == AnsiString::npos) return "";
+ //else return newPath.substr(0, pos + 1);
}
//////////////////////////////////////////////////////////////////////////
AnsiString PathUtil::GetFileName(const AnsiString &path) {
AnsiString newPath = UnifySeparators(path);
- size_t pos = newPath.find_last_of(L'/');
-
- if (pos == AnsiString::npos) return path;
- else return newPath.substr(pos + 1);
+ //size_t pos = newPath.find_last_of(L'/'); TODO REMOVE.
+ Common::String lastPart = Common::lastPathComponent(path,'/');
+ if (lastPart[lastPart.size() - 1 ] != '/')
+ return lastPart;
+ else
+ return path;
+ //if (pos == AnsiString::npos) return path;
+ //else return newPath.substr(pos + 1);
}
//////////////////////////////////////////////////////////////////////////
AnsiString PathUtil::GetFileNameWithoutExtension(const AnsiString &path) {
AnsiString fileName = GetFileName(path);
- size_t pos = fileName.find_last_of('.');
-
- if (pos == AnsiString::npos) return fileName;
- else return fileName.substr(0, pos);
+ //size_t pos = fileName.find_last_of('.'); //TODO REMOVE!
+ // TODO: Prettify this.
+ Common::String extension = Common::lastPathComponent(path, '.');
+ Common::String filename = Common::String(path.c_str(), path.size() - extension.size());
+ return filename;
+ //if (pos == AnsiString::npos) return fileName;
+ //else return fileName.substr(0, pos);
}
//////////////////////////////////////////////////////////////////////////
AnsiString PathUtil::GetExtension(const AnsiString &path) {
AnsiString fileName = GetFileName(path);
- size_t pos = fileName.find_last_of('.');
-
- if (pos == AnsiString::npos) return "";
- else return fileName.substr(pos);
+ //size_t pos = fileName.find_last_of('.');
+ return Common::lastPathComponent(path, '.');
+ //if (pos == AnsiString::npos) return "";
+ //else return fileName.substr(pos);
}
diff --git a/engines/wintermute/StringUtil.cpp b/engines/wintermute/StringUtil.cpp
index f3b4e0c0db..a8af7f25ec 100644
--- a/engines/wintermute/StringUtil.cpp
+++ b/engines/wintermute/StringUtil.cpp
@@ -42,9 +42,9 @@ void StringUtil::ToLowerCase(AnsiString &str) {
}
//////////////////////////////////////////////////////////////////////////
-void StringUtil::ToLowerCase(WideString &str) {
+/*void StringUtil::ToLowerCase(WideString &str) {
std::transform(str.begin(), str.end(), str.begin(), ::towlower);
-}
+}*/
//////////////////////////////////////////////////////////////////////////
void StringUtil::ToUpperCase(AnsiString &str) {
@@ -52,9 +52,9 @@ void StringUtil::ToUpperCase(AnsiString &str) {
}
//////////////////////////////////////////////////////////////////////////
-void StringUtil::ToUpperCase(WideString &str) {
+/*void StringUtil::ToUpperCase(WideString &str) {
std::transform(str.begin(), str.end(), str.begin(), ::towupper);
-}
+}*/
//////////////////////////////////////////////////////////////////////////
bool StringUtil::CompareNoCase(const AnsiString &str1, const AnsiString &str2) {
@@ -68,7 +68,7 @@ bool StringUtil::CompareNoCase(const AnsiString &str1, const AnsiString &str2) {
}
//////////////////////////////////////////////////////////////////////////
-bool StringUtil::CompareNoCase(const WideString &str1, const WideString &str2) {
+/*bool StringUtil::CompareNoCase(const WideString &str1, const WideString &str2) {
WideString str1lc = str1;
WideString str2lc = str2;
@@ -76,11 +76,12 @@ bool StringUtil::CompareNoCase(const WideString &str1, const WideString &str2) {
ToLowerCase(str2lc);
return (str1lc == str2lc);
-}
+}*/
//////////////////////////////////////////////////////////////////////////
WideString StringUtil::Utf8ToWide(const Utf8String &Utf8Str) {
- size_t WideSize = Utf8Str.length();
+ error("WideString not supported yet");
+/* size_t WideSize = Utf8Str.size();
if (sizeof(wchar_t) == 2) {
wchar_t *WideStringNative = new wchar_t[WideSize + 1];
@@ -122,12 +123,14 @@ WideString StringUtil::Utf8ToWide(const Utf8String &Utf8Str) {
return ResultString;
} else {
return L"";
- }
+ }*/
+ return "";
}
//////////////////////////////////////////////////////////////////////////
Utf8String StringUtil::WideToUtf8(const WideString &WideStr) {
- size_t WideSize = WideStr.length();
+ error("Widestring not supported yet");
+/* size_t WideSize = WideStr.length();
if (sizeof(wchar_t) == 2) {
size_t Utf8Size = 3 * WideSize + 1;
@@ -169,37 +172,42 @@ Utf8String StringUtil::WideToUtf8(const WideString &WideStr) {
return ResultString;
} else {
return (Utf8String)"";
- }
+ }*/
+ return "";
}
//////////////////////////////////////////////////////////////////////////
WideString StringUtil::AnsiToWide(const AnsiString &str) {
// using default os locale!
- setlocale(LC_CTYPE, "");
+ error("WideString not supported yet");
+/* setlocale(LC_CTYPE, "");
size_t WideSize = mbstowcs(NULL, str.c_str(), 0) + 1;
wchar_t *wstr = new wchar_t[WideSize];
mbstowcs(wstr, str.c_str(), WideSize);
WideString ResultString(wstr);
delete [] wstr;
- return ResultString;
+ return ResultString;*/
+ return "";
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::WideToAnsi(const WideString &wstr) {
// using default os locale!
- setlocale(LC_CTYPE, "");
+ error("WideString not supported yet");
+/* setlocale(LC_CTYPE, "");
size_t WideSize = wcstombs(NULL, wstr.c_str(), 0) + 1;
char *str = new char[WideSize];
wcstombs(str, wstr.c_str(), WideSize);
AnsiString ResultString(str);
delete [] str;
- return ResultString;
+ return ResultString;*/
+ return "";
}
//////////////////////////////////////////////////////////////////////////
bool StringUtil::StartsWith(const AnsiString &str, const AnsiString &pattern, bool ignoreCase) {
- size_t strLength = str.length();
- size_t patternLength = pattern.length();
+/* size_t strLength = str.size();
+ size_t patternLength = pattern.size();
if (strLength < patternLength || patternLength == 0)
return false;
@@ -207,13 +215,26 @@ bool StringUtil::StartsWith(const AnsiString &str, const AnsiString &pattern, bo
AnsiString startPart = str.substr(0, patternLength);
if (ignoreCase) return CompareNoCase(startPart, pattern);
- else return (startPart == pattern);
+ else return (startPart == pattern);*/
+ if (!ignoreCase)
+ return str.hasPrefix(pattern);
+ else {
+ size_t strLength = str.size();
+ size_t patternLength = pattern.size();
+
+ if (strLength < patternLength || patternLength == 0)
+ return false;
+
+ AnsiString startPart(str.c_str(), patternLength);
+ uint32 likeness = str.compareToIgnoreCase(pattern.c_str());
+ return (likeness == 0);
+ }
}
//////////////////////////////////////////////////////////////////////////
bool StringUtil::EndsWith(const AnsiString &str, const AnsiString &pattern, bool ignoreCase) {
- size_t strLength = str.length();
- size_t patternLength = pattern.length();
+/* size_t strLength = str.size(); // TODO: Remove
+ size_t patternLength = pattern.size();
if (strLength < patternLength || patternLength == 0)
return false;
@@ -221,7 +242,20 @@ bool StringUtil::EndsWith(const AnsiString &str, const AnsiString &pattern, bool
AnsiString endPart = str.substr(strLength - patternLength, patternLength);
if (ignoreCase) return CompareNoCase(endPart, pattern);
- else return (endPart == pattern);
+ else return (endPart == pattern);*/
+ if (!ignoreCase) {
+ return str.hasSuffix(pattern);
+ } else {
+ size_t strLength = str.size();
+ size_t patternLength = pattern.size();
+
+ if (strLength < patternLength || patternLength == 0)
+ return false;
+
+ Common::String endPart(str.c_str(), strLength - patternLength);
+ uint32 likeness = str.compareToIgnoreCase(pattern.c_str());
+ return (likeness == 0);
+ }
}
//////////////////////////////////////////////////////////////////////////
@@ -237,12 +271,20 @@ AnsiString StringUtil::Replace(const AnsiString &str, const AnsiString &from, co
AnsiString result = str;
size_t pos = 0;
- while (true) {
- pos = result.find(from, pos);
+ while (result.contains(from)) {
+ const char* startPtr = strstr(result.c_str(), from.c_str());
+ uint32 index = startPtr - result.c_str();
+
+ Common::String tail(result.c_str() + index + to.size());
+ result = Common::String(result.c_str(), index);
+ result += to;
+ result += tail;
+
+/* pos = result.find(from, pos);
if (pos == result.npos) break;
result.replace(pos, from.size(), to);
- pos += to.size();
+ pos += to.size();*/
}
return result;
@@ -252,55 +294,83 @@ AnsiString StringUtil::Replace(const AnsiString &str, const AnsiString &from, co
AnsiString StringUtil::Trim(const AnsiString &str, bool fromLeft, bool fromRight, const AnsiString &chars) {
AnsiString trimmedStr = str;
- if (fromRight)
- trimmedStr.erase(trimmedStr.find_last_not_of(chars) + 1);
- if (fromLeft)
- trimmedStr.erase(0, trimmedStr.find_first_not_of(chars));
-
+ if (fromRight) {
+ //trimmedStr.erase(trimmedStr.find_last_not_of(chars) + 1); // TODO
+ warning("fromRight-trim not implemented yet, %s", chars.c_str());
+ }
+ if (fromLeft) {
+ uint32 lastOf = LastIndexOf(str, chars, 0);
+ trimmedStr = Common::String(trimmedStr.c_str() + lastOf);
+ //trimmedStr.erase(0, trimmedStr.find_first_not_of(chars));
+ }
return trimmedStr;
}
//////////////////////////////////////////////////////////////////////////
int StringUtil::IndexOf(const WideString &str, const WideString &toFind, size_t startFrom) {
- size_t pos = str.find(toFind, startFrom);
+ /*size_t pos = str.find(toFind, startFrom);
if (pos == str.npos) return -1;
- else return pos;
+ else return pos;*/
+ const char* index = strstr(str.c_str(), toFind.c_str());
+ if (index == NULL)
+ return -1;
+ else
+ return str.c_str() - index;
}
//////////////////////////////////////////////////////////////////////////
int StringUtil::LastIndexOf(const WideString &str, const WideString &toFind, size_t startFrom) {
- size_t pos = str.rfind(toFind, startFrom);
+ /*size_t pos = str.rfind(toFind, startFrom);
if (pos == str.npos) return -1;
- else return pos;
+ else return pos;*/
+ uint32 lastIndex = -1;
+ bool found = false;
+ for (int i = startFrom; i < str.size(); i++) {
+ found = false;
+ for (int j = 0; j < toFind.size(); j++) {
+ if (str[i+j] != toFind[j]) {
+ found = false;
+ break;
+ } else {
+ found = true;
+ }
+ }
+ if (found)
+ lastIndex = i;
+ }
+ return lastIndex;
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::ToString(size_t val) {
- std::ostringstream str;
+/* std::ostringstream str;
str << val;
- return str.str();
+ return str.str();*/
+ return Common::String::format("%u", val);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::ToString(int val) {
- std::ostringstream str;
+/* std::ostringstream str;
str << val;
- return str.str();
-
+ return str.str();*/
+ return Common::String::format("%d", val);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::ToString(float val) {
- std::ostringstream str;
+/* std::ostringstream str;
str << val;
- return str.str();
+ return str.str();*/
+ return Common::String::format("%f", val);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::ToString(double val) {
- std::ostringstream str;
+/* std::ostringstream str;
str << val;
- return str.str();
+ return str.str();*/
+ return Common::String::format("%f", val);
}
@@ -315,7 +385,7 @@ void StringUtil::Split(const AnsiString &list, const AnsiString &delimiters, Ans
//separator_t del(delimiters.c_str(), "", keepEmptyItems ? boost::keep_empty_tokens : boost::drop_empty_tokens);
//tokenizer_t tokens(list, del);
while (!tokenizer.empty()) {
- std::string copy(tokenizer.nextToken().c_str());
+ Common::String copy(tokenizer.nextToken().c_str());
result.push_back(copy);
}
}
diff --git a/engines/wintermute/StringUtil.h b/engines/wintermute/StringUtil.h
index 80c95ced03..f62f82db9a 100644
--- a/engines/wintermute/StringUtil.h
+++ b/engines/wintermute/StringUtil.h
@@ -36,11 +36,11 @@ namespace WinterMute {
class StringUtil {
public:
static void ToLowerCase(AnsiString &str);
- static void ToLowerCase(WideString &str);
+ //static void ToLowerCase(WideString &str);
static void ToUpperCase(AnsiString &str);
- static void ToUpperCase(WideString &str);
+ //static void ToUpperCase(WideString &str);
static bool CompareNoCase(const AnsiString &str1, const AnsiString &str2);
- static bool CompareNoCase(const WideString &str1, const WideString &str2);
+ //static bool CompareNoCase(const WideString &str1, const WideString &str2);
static WideString Utf8ToWide(const Utf8String &Utf8Str);
static Utf8String WideToUtf8(const WideString &WideStr);
static WideString AnsiToWide(const AnsiString &str);
diff --git a/engines/wintermute/SysClass.cpp b/engines/wintermute/SysClass.cpp
index a673943b57..ebde28cdb1 100644
--- a/engines/wintermute/SysClass.cpp
+++ b/engines/wintermute/SysClass.cpp
@@ -35,6 +35,8 @@
namespace WinterMute {
+// TODO: Note that the set was removed, this might have bizarre side-effects.
+
//////////////////////////////////////////////////////////////////////////
CSysClass::CSysClass(const AnsiString &name, PERSISTBUILD build, PERSISTLOAD load, bool persistent_class) {
m_Name = name;
@@ -58,11 +60,11 @@ CSysClass::~CSysClass() {
//////////////////////////////////////////////////////////////////////////
bool CSysClass::RemoveAllInstances() {
- Instances::iterator it;
- for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
- delete(*it);
+ InstanceMap::iterator it;
+ for (it = m_InstanceMap.begin(); it != m_InstanceMap.end(); ++it) {
+ delete(it->_value);
}
- m_Instances.clear();
+ //m_Instances.clear();
m_InstanceMap.clear();
return true;
@@ -72,7 +74,7 @@ bool CSysClass::RemoveAllInstances() {
CSysInstance *CSysClass::AddInstance(void *instance, int id, int savedId) {
CSysInstance *inst = new CSysInstance(instance, id, this);
inst->SetSavedID(savedId);
- m_Instances.insert(inst);
+ //m_Instances.insert(inst);
m_InstanceMap[instance] = inst;
@@ -86,13 +88,14 @@ CSysInstance *CSysClass::AddInstance(void *instance, int id, int savedId) {
bool CSysClass::RemoveInstance(void *instance) {
InstanceMap::iterator mapIt = m_InstanceMap.find(instance);
if (mapIt == m_InstanceMap.end()) return false;
-
+/*
Instances::iterator it = m_Instances.find((*mapIt).second);
if (it != m_Instances.end()) {
delete(*it);
m_Instances.erase(it);
- }
+ }*/
+ delete mapIt->_value;
m_InstanceMap.erase(mapIt);
return false;
@@ -102,39 +105,49 @@ bool CSysClass::RemoveInstance(void *instance) {
int CSysClass::GetInstanceID(void *pointer) {
InstanceMap::iterator mapIt = m_InstanceMap.find(pointer);
if (mapIt == m_InstanceMap.end()) return -1;
- else return (*mapIt).second->GetID();
+ else return (*mapIt)._value->GetID();
}
//////////////////////////////////////////////////////////////////////////
void *CSysClass::IDToPointer(int savedID) {
//slow
- Instances::iterator it;
+ /*Instances::iterator it;
for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
if ((*it)->GetSavedID() == savedID) return (*it)->GetInstance();
+ }*/
+ InstanceMap::iterator it;
+ for (it = m_InstanceMap.begin(); it != m_InstanceMap.end(); ++it) {
+ if ((it->_value)->GetSavedID() == savedID) return (it->_value)->GetInstance();
}
return NULL;
}
//////////////////////////////////////////////////////////////////////////
int CSysClass::GetNumInstances() {
- return m_Instances.size();
+ //return m_Instances.size();
+ return m_InstanceMap.size(); // TODO: This might break, if we have multiple keys per value.
}
//////////////////////////////////////////////////////////////////////////
-void CSysClass::Dump(FILE *stream) {
- fprintf(stream, "%03d %c %-20s instances: %d\n", m_ID, m_Persistent ? 'p' : ' ', m_Name.c_str(), GetNumInstances());
+void CSysClass::Dump(void *stream) {
+ fprintf((FILE*)stream, "%03d %c %-20s instances: %d\n", m_ID, m_Persistent ? 'p' : ' ', m_Name.c_str(), GetNumInstances());
}
//////////////////////////////////////////////////////////////////////////
void CSysClass::SaveTable(CBGame *Game, CBPersistMgr *PersistMgr) {
PersistMgr->PutString(m_Name.c_str());
PersistMgr->PutDWORD(m_ID);
- PersistMgr->PutDWORD(m_Instances.size());
+ PersistMgr->PutDWORD(m_InstanceMap.size());
+ InstanceMap::iterator it;
+ for (it = m_InstanceMap.begin(); it != m_InstanceMap.end(); ++it) {
+ PersistMgr->PutDWORD((it->_value)->GetID());
+ }
+ /*
Instances::iterator it;
for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
PersistMgr->PutDWORD((*it)->GetID());
- }
+ }*/
}
//////////////////////////////////////////////////////////////////////////
@@ -151,10 +164,11 @@ void CSysClass::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
continue;
}
- Instances::iterator it = m_Instances.begin();
- if (it != m_Instances.end()) {
- (*it)->SetSavedID(instId);
- CSysClassRegistry::GetInstance()->AddInstanceToTable((*it), (*it)->GetInstance());
+ InstanceMap::iterator it = m_InstanceMap.begin();
+/* Instances::iterator it = m_Instances.begin();*/
+ if (it != m_InstanceMap.end()) {
+ (it->_value)->SetSavedID(instId);
+ CSysClassRegistry::GetInstance()->AddInstanceToTable((it->_value), (it->_value)->GetInstance());
} else Game->LOG(0, "Warning: instance %d of persistent class %s not found", i, m_Name.c_str());
}
// normal instances, create empty objects
@@ -168,13 +182,13 @@ void CSysClass::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
//////////////////////////////////////////////////////////////////////////
void CSysClass::SaveInstances(CBGame *Game, CBPersistMgr *PersistMgr) {
- Instances::iterator it;
- for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
+ InstanceMap::iterator it;
+ for (it = m_InstanceMap.begin(); it != m_InstanceMap.end(); ++it) {
// write instace header
PersistMgr->PutDWORD(m_ID);
- PersistMgr->PutDWORD((*it)->GetID());
+ PersistMgr->PutDWORD((it->_value)->GetID());
- m_Load((*it)->GetInstance(), PersistMgr);
+ m_Load((it->_value)->GetInstance(), PersistMgr);
}
}
@@ -186,17 +200,17 @@ void CSysClass::LoadInstance(void *instance, CBPersistMgr *PersistMgr) {
//////////////////////////////////////////////////////////////////////////
void CSysClass::ResetSavedIDs() {
- Instances::iterator it;
- for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
- (*it)->SetSavedID(-1);
+ InstanceMap::iterator it;
+ for (it = m_InstanceMap.begin(); it != m_InstanceMap.end(); ++it) {
+ (it->_value)->SetSavedID(-1);
}
}
//////////////////////////////////////////////////////////////////////////
void CSysClass::InstanceCallback(SYS_INSTANCE_CALLBACK lpCallback, void *lpData) {
- Instances::iterator it;
- for (it = m_Instances.begin(); it != m_Instances.end(); ++it) {
- lpCallback((*it)->GetInstance(), lpData);
+ InstanceMap::iterator it;
+ for (it = m_InstanceMap.begin(); it != m_InstanceMap.end(); ++it) {
+ lpCallback((it->_value)->GetInstance(), lpData);
}
}
diff --git a/engines/wintermute/SysClass.h b/engines/wintermute/SysClass.h
index 48d7a2626e..bcd63cc5e4 100644
--- a/engines/wintermute/SysClass.h
+++ b/engines/wintermute/SysClass.h
@@ -30,10 +30,21 @@
#define WINTERMUTE_SYSCLASS_H
#include "persistent.h"
-#include <set>
-#include <map>
#include "dctypes.h"
+//#include <set>
+//#include <map>
+#include "common/hashmap.h"
+#include "common/func.h"
+namespace Common {
+template<typename T> struct Hash;
+
+template<> struct Hash<void*> : public UnaryFunction<void*, uint> {
+ uint operator()(void* val) const { return (uint)((size_t)val); }
+};
+
+}
+
namespace WinterMute {
class CSysInstance;
class CBGame;
@@ -80,7 +91,7 @@ public:
void ResetSavedIDs();
- void Dump(FILE *stream);
+ void Dump(void *stream);
private:
int m_NumInst;
@@ -92,10 +103,10 @@ private:
PERSISTBUILD m_Build;
PERSISTLOAD m_Load;
- typedef std::set<CSysInstance *> Instances;
- Instances m_Instances;
+ //typedef std::set<CSysInstance *> Instances;
+ //Instances m_Instances;
- typedef std::map<void *, CSysInstance *> InstanceMap;
+ typedef Common::HashMap<void *, CSysInstance *> InstanceMap;
InstanceMap m_InstanceMap;
};
diff --git a/engines/wintermute/SysClassRegistry.cpp b/engines/wintermute/SysClassRegistry.cpp
index 72740a79cf..1170921768 100644
--- a/engines/wintermute/SysClassRegistry.cpp
+++ b/engines/wintermute/SysClassRegistry.cpp
@@ -53,7 +53,8 @@ CSysClassRegistry *CSysClassRegistry::GetInstance() {
//////////////////////////////////////////////////////////////////////////
bool CSysClassRegistry::RegisterClass(CSysClass *classObj) {
classObj->SetID(m_Count++);
- m_Classes.insert(classObj);
+ //m_Classes.insert(classObj);
+ m_Classes[classObj] = classObj;
m_NameMap[classObj->GetName()] = classObj;
m_IdMap[classObj->GetID()] = classObj;
@@ -93,7 +94,7 @@ bool CSysClassRegistry::RegisterInstance(const char *className, void *instance)
NameMap::iterator mapIt = m_NameMap.find(className);
if (mapIt == m_NameMap.end()) return false;
- CSysInstance *inst = (*mapIt).second->AddInstance(instance, m_Count++);
+ CSysInstance *inst = (*mapIt)._value->AddInstance(instance, m_Count++);
return (inst != NULL);
}
@@ -114,7 +115,7 @@ int CSysClassRegistry::GetNextID() {
bool CSysClassRegistry::UnregisterInstance(const char *className, void *instance) {
NameMap::iterator mapIt = m_NameMap.find(className);
if (mapIt == m_NameMap.end()) return false;
- (*mapIt).second->RemoveInstance(instance);
+ (*mapIt)._value->RemoveInstance(instance);
InstanceMap::iterator instIt = m_InstanceMap.find(instance);
if (instIt != m_InstanceMap.end()) {
@@ -132,7 +133,7 @@ bool CSysClassRegistry::GetPointerID(void *pointer, int *classID, int *instanceI
if (it == m_InstanceMap.end()) return false;
- CSysInstance *inst = (*it).second;
+ CSysInstance *inst = (*it)._value;
*instanceID = inst->GetID();
*classID = inst->GetClass()->GetID();
@@ -143,7 +144,7 @@ bool CSysClassRegistry::GetPointerID(void *pointer, int *classID, int *instanceI
void *CSysClassRegistry::IDToPointer(int classID, int instanceID) {
SavedInstanceMap::iterator it = m_SavedInstanceMap.find(instanceID);
if (it == m_SavedInstanceMap.end()) return NULL;
- else return (*it).second->GetInstance();
+ else return (*it)._value->GetInstance();
}
@@ -163,7 +164,7 @@ HRESULT CSysClassRegistry::SaveTable(CBGame *Game, CBPersistMgr *PersistMgr, boo
Game->m_Renderer->Flip();
}
- (*it)->SaveTable(Game, PersistMgr);
+ (it->_value)->SaveTable(Game, PersistMgr);
}
return S_OK;
@@ -176,12 +177,12 @@ HRESULT CSysClassRegistry::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
// reset SavedID of current instances
for (it = m_Classes.begin(); it != m_Classes.end(); ++it) {
- (*it)->ResetSavedIDs();
+ (it->_value)->ResetSavedIDs();
}
for (it = m_Classes.begin(); it != m_Classes.end(); ++it) {
- if ((*it)->IsPersistent()) continue;
- (*it)->RemoveAllInstances();
+ if ((it->_value)->IsPersistent()) continue;
+ (it->_value)->RemoveAllInstances();
}
m_InstanceMap.clear();
@@ -196,7 +197,7 @@ HRESULT CSysClassRegistry::LoadTable(CBGame *Game, CBPersistMgr *PersistMgr) {
char *className = PersistMgr->GetString();
NameMap::iterator mapIt = m_NameMap.find(className);
- if (mapIt != m_NameMap.end())(*mapIt).second->LoadTable(Game, PersistMgr);
+ if (mapIt != m_NameMap.end())(*mapIt)._value->LoadTable(Game, PersistMgr);
}
return S_OK;
@@ -211,7 +212,7 @@ HRESULT CSysClassRegistry::SaveInstances(CBGame *Game, CBPersistMgr *PersistMgr,
// count total instances
int numInstances = 0;
for (it = m_Classes.begin(); it != m_Classes.end(); ++it) {
- numInstances += (*it)->GetNumInstances();
+ numInstances += (it->_value)->GetNumInstances();
}
PersistMgr->PutDWORD(numInstances);
@@ -229,7 +230,7 @@ HRESULT CSysClassRegistry::SaveInstances(CBGame *Game, CBPersistMgr *PersistMgr,
}
Game->MiniUpdate();
- (*it)->SaveInstances(Game, PersistMgr);
+ (it->_value)->SaveInstances(Game, PersistMgr);
}
return S_OK;
@@ -255,8 +256,8 @@ HRESULT CSysClassRegistry::LoadInstances(CBGame *Game, CBPersistMgr *PersistMgr)
Classes::iterator it;
for (it = m_Classes.begin(); it != m_Classes.end(); ++it) {
- if ((*it)->GetSavedID() == classID) {
- (*it)->LoadInstance(instance, PersistMgr);
+ if ((it->_value)->GetSavedID() == classID) {
+ (it->_value)->LoadInstance(instance, PersistMgr);
}
}
}
@@ -272,16 +273,16 @@ HRESULT CSysClassRegistry::EnumInstances(SYS_INSTANCE_CALLBACK lpCallback, const
NameMap::iterator mapIt = m_NameMap.find(className);
if (mapIt == m_NameMap.end()) return E_FAIL;
- (*mapIt).second->InstanceCallback(lpCallback, lpData);
+ (*mapIt)._value->InstanceCallback(lpCallback, lpData);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
-void CSysClassRegistry::DumpClasses(FILE *stream) {
+void CSysClassRegistry::DumpClasses(void *stream) {
Classes::iterator it;
for (it = m_Classes.begin(); it != m_Classes.end(); ++it)
- (*it)->Dump(stream);
+ (it->_value)->Dump(stream);
}
} // end of namespace WinterMute
diff --git a/engines/wintermute/SysClassRegistry.h b/engines/wintermute/SysClassRegistry.h
index 1a73f28010..6d3367fc30 100644
--- a/engines/wintermute/SysClassRegistry.h
+++ b/engines/wintermute/SysClassRegistry.h
@@ -32,14 +32,30 @@
#include "wintypes.h"
#include "dctypes.h"
#include "persistent.h"
-#include <set>
-#include <map>
+//#include <set>
+//#include <map>
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+#include "common/func.h"
+
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+
+namespace WinterMute {
+class CSysClass;
+}
+
+namespace Common {
+template<typename T> struct Hash;
+template<> struct Hash<WinterMute::CSysClass*> : public UnaryFunction<WinterMute::CSysClass*, uint> {
+ uint operator()(WinterMute::CSysClass* val) const { return (uint)((size_t)val); }
+};
+
+}
namespace WinterMute {
class CBGame;
class CBPersistMgr;
-class CSysClass;
class CSysInstance;
class CSysClassRegistry {
@@ -57,7 +73,7 @@ public:
bool UnregisterClass(CSysClass *classObj);
bool RegisterInstance(const char *className, void *instance);
bool UnregisterInstance(const char *className, void *instance);
- void DumpClasses(FILE *stream);
+ void DumpClasses(void *stream);
int GetNextID();
void AddInstanceToTable(CSysInstance *instance, void *pointer);
@@ -67,19 +83,19 @@ public:
bool m_Disabled;
int m_Count;
- typedef std::set<CSysClass *> Classes;
+ typedef Common::HashMap<CSysClass *, CSysClass *> Classes;
Classes m_Classes;
- typedef std::map<AnsiString, CSysClass *> NameMap;
+ typedef Common::HashMap<AnsiString, CSysClass *> NameMap;
NameMap m_NameMap;
- typedef std::map<int, CSysClass *> IdMap;
+ typedef Common::HashMap<int, CSysClass *> IdMap;
IdMap m_IdMap;
- typedef std::map<void *, CSysInstance *> InstanceMap;
+ typedef Common::HashMap<void *, CSysInstance *> InstanceMap;
InstanceMap m_InstanceMap;
- typedef std::map<int, CSysInstance *> SavedInstanceMap;
+ typedef Common::HashMap<int, CSysInstance *> SavedInstanceMap;
SavedInstanceMap m_SavedInstanceMap;
};
diff --git a/engines/wintermute/SysInstance.cpp b/engines/wintermute/SysInstance.cpp
index b937136706..857a857a45 100644
--- a/engines/wintermute/SysInstance.cpp
+++ b/engines/wintermute/SysInstance.cpp
@@ -27,6 +27,7 @@
*/
#include "SysInstance.h"
+#include "SysClassRegistry.h"
#include "SysClass.h"
namespace WinterMute {
diff --git a/engines/wintermute/UIEdit.cpp b/engines/wintermute/UIEdit.cpp
index 58ac8ff13b..6d1018ec0a 100644
--- a/engines/wintermute/UIEdit.cpp
+++ b/engines/wintermute/UIEdit.cpp
@@ -45,6 +45,7 @@
#include "engines/wintermute/scriptables/ScStack.h"
#include "engines/wintermute/scriptables/ScScript.h"
#include "engines/wintermute/utils.h"
+#include "common/util.h"
namespace WinterMute {
@@ -462,7 +463,7 @@ HRESULT CUIEdit::ScSetProperty(char *Name, CScValue *Value) {
if (strcmp(Name, "SelStart") == 0) {
m_SelStart = Value->GetInt();
m_SelStart = MAX(m_SelStart, 0);
- m_SelStart = MIN(m_SelStart, strlen(m_Text));
+ m_SelStart = MIN((size_t)m_SelStart, strlen(m_Text));
return S_OK;
}
@@ -472,7 +473,7 @@ HRESULT CUIEdit::ScSetProperty(char *Name, CScValue *Value) {
else if (strcmp(Name, "SelEnd") == 0) {
m_SelEnd = Value->GetInt();
m_SelEnd = MAX(m_SelEnd, 0);
- m_SelEnd = MIN(m_SelEnd, strlen(m_Text));
+ m_SelEnd = MIN((size_t)m_SelEnd, strlen(m_Text));
return S_OK;
}
@@ -567,8 +568,8 @@ HRESULT CUIEdit::Display(int OffsetX, int OffsetY) {
m_SelStart = MAX(m_SelStart, 0);
m_SelEnd = MAX(m_SelEnd, 0);
- m_SelStart = MIN(m_SelStart, strlen(m_Text));
- m_SelEnd = MIN(m_SelEnd, strlen(m_Text));
+ m_SelStart = MIN((size_t)m_SelStart, strlen(m_Text));
+ m_SelEnd = MIN((size_t)m_SelEnd, strlen(m_Text));
//int CursorWidth = font->GetCharWidth(m_CursorChar[0]);
int CursorWidth = font->GetTextWidth((byte *)m_CursorChar);
@@ -788,8 +789,8 @@ bool CUIEdit::HandleKeypress(SDL_Event *event) {
int CUIEdit::DeleteChars(int Start, int End) {
if (Start > End) CBUtils::Swap(&Start, &End);
- Start = MAX(Start, 0);
- End = MIN(End, strlen(m_Text));
+ Start = MAX(Start, (int)0);
+ End = MIN((size_t)End, strlen(m_Text));
char *str = new char[strlen(m_Text) - (End - Start) + 1];
if (str) {
@@ -811,8 +812,8 @@ int CUIEdit::InsertChars(int Pos, byte *Chars, int Num) {
Num -= (strlen(m_Text) + Num - m_MaxLength);
}
- Pos = MAX(Pos, 0);
- Pos = MIN(Pos, strlen(m_Text));
+ Pos = MAX(Pos, (int)0);
+ Pos = MIN((size_t)Pos, strlen(m_Text));
char *str = new char[strlen(m_Text) + Num + 1];
if (str) {
diff --git a/engines/wintermute/dctypes.h b/engines/wintermute/dctypes.h
index 0ee5a6bf54..bd5ec3b6e5 100644
--- a/engines/wintermute/dctypes.h
+++ b/engines/wintermute/dctypes.h
@@ -29,22 +29,29 @@
#ifndef WINTERMUTE_DCTYPES_H
#define WINTERMUTE_DCTYPES_H
-#include <string>
-#include <list>
-#include <vector>
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
-namespace WinterMute {
+#include "common/str.h"
+#include "common/list.h"
+#include "common/array.h"
+//#include <string>
+//#include <list>
+//#include <vector>
-typedef std::string AnsiString;
-typedef std::string Utf8String;
-typedef std::wstring WideString;
+namespace WinterMute {
+//typedef std::string AnsiString;
+//typedef std::string Utf8String;
+//typedef std::wstring WideString;
+typedef Common::String AnsiString;
+typedef Common::String Utf8String;
+typedef Common::String WideString; // NB: Not actually true I presume.
-typedef std::list<WideString> WideStringList;
-typedef std::list<AnsiString> AnsiStringList;
+typedef Common::List<WideString> WideStringList;
+typedef Common::List<AnsiString> AnsiStringList;
-typedef std::vector<WideString> WideStringArray;
-typedef std::vector<AnsiString> AnsiStringArray;
+typedef Common::Array<WideString> WideStringArray;
+typedef Common::Array<AnsiString> AnsiStringArray;
enum TGameState {
diff --git a/engines/wintermute/scriptables/ScEngine.h b/engines/wintermute/scriptables/ScEngine.h
index 54e590bdfe..13103f6d3c 100644
--- a/engines/wintermute/scriptables/ScEngine.h
+++ b/engines/wintermute/scriptables/ScEngine.h
@@ -168,7 +168,7 @@ private:
bool m_IsProfiling;
uint32 m_ProfilingStartTime;
- typedef std::map<std::string, uint32> ScriptTimes;
+ typedef Common::HashMap<Common::String, uint32> ScriptTimes;
ScriptTimes m_ScriptTimes;
};
diff --git a/engines/wintermute/scriptables/ScValue.cpp b/engines/wintermute/scriptables/ScValue.cpp
index 387bf45b46..186f4ff9d2 100644
--- a/engines/wintermute/scriptables/ScValue.cpp
+++ b/engines/wintermute/scriptables/ScValue.cpp
@@ -170,7 +170,7 @@ CScValue *CScValue::GetProp(char *Name) {
Game->m_ScValue->SetInt(strlen(m_ValString));
} else {
WideString wstr = StringUtil::Utf8ToWide(m_ValString);
- Game->m_ScValue->SetInt(wstr.length());
+ Game->m_ScValue->SetInt(wstr.size());
}
return Game->m_ScValue;
diff --git a/engines/wintermute/tinystr.cpp b/engines/wintermute/tinystr.cpp
new file mode 100644
index 0000000000..0665768205
--- /dev/null
+++ b/engines/wintermute/tinystr.cpp
@@ -0,0 +1,111 @@
+/*
+www.sourceforge.net/projects/tinyxml
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+*/
+
+
+#ifndef TIXML_USE_STL
+
+#include "tinystr.h"
+
+// Error value for find primitive
+const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
+
+
+// Null rep.
+TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
+
+
+void TiXmlString::reserve (size_type cap)
+{
+ if (cap > capacity())
+ {
+ TiXmlString tmp;
+ tmp.init(length(), cap);
+ memcpy(tmp.start(), data(), length());
+ swap(tmp);
+ }
+}
+
+
+TiXmlString& TiXmlString::assign(const char* str, size_type len)
+{
+ size_type cap = capacity();
+ if (len > cap || cap > 3*(len + 8))
+ {
+ TiXmlString tmp;
+ tmp.init(len);
+ memcpy(tmp.start(), str, len);
+ swap(tmp);
+ }
+ else
+ {
+ memmove(start(), str, len);
+ set_size(len);
+ }
+ return *this;
+}
+
+
+TiXmlString& TiXmlString::append(const char* str, size_type len)
+{
+ size_type newsize = length() + len;
+ if (newsize > capacity())
+ {
+ reserve (newsize + capacity());
+ }
+ memmove(finish(), str, len);
+ set_size(newsize);
+ return *this;
+}
+
+
+TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
+{
+ TiXmlString tmp;
+ tmp.reserve(a.length() + b.length());
+ tmp += a;
+ tmp += b;
+ return tmp;
+}
+
+TiXmlString operator + (const TiXmlString & a, const char* b)
+{
+ TiXmlString tmp;
+ TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
+ tmp.reserve(a.length() + b_len);
+ tmp += a;
+ tmp.append(b, b_len);
+ return tmp;
+}
+
+TiXmlString operator + (const char* a, const TiXmlString & b)
+{
+ TiXmlString tmp;
+ TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
+ tmp.reserve(a_len + b.length());
+ tmp.append(a, a_len);
+ tmp += b;
+ return tmp;
+}
+
+
+#endif // TIXML_USE_STL
diff --git a/engines/wintermute/tinystr.h b/engines/wintermute/tinystr.h
new file mode 100644
index 0000000000..89cca33415
--- /dev/null
+++ b/engines/wintermute/tinystr.h
@@ -0,0 +1,305 @@
+/*
+www.sourceforge.net/projects/tinyxml
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+*/
+
+
+#ifndef TIXML_USE_STL
+
+#ifndef TIXML_STRING_INCLUDED
+#define TIXML_STRING_INCLUDED
+
+#include <assert.h>
+#include <string.h>
+
+/* The support for explicit isn't that universal, and it isn't really
+ required - it is used to check that the TiXmlString class isn't incorrectly
+ used. Be nice to old compilers and macro it here:
+*/
+#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
+ // Microsoft visual studio, version 6 and higher.
+ #define TIXML_EXPLICIT explicit
+#elif defined(__GNUC__) && (__GNUC__ >= 3 )
+ // GCC version 3 and higher.s
+ #define TIXML_EXPLICIT explicit
+#else
+ #define TIXML_EXPLICIT
+#endif
+
+
+/*
+ TiXmlString is an emulation of a subset of the std::string template.
+ Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
+ Only the member functions relevant to the TinyXML project have been implemented.
+ The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
+ a string and there's no more room, we allocate a buffer twice as big as we need.
+*/
+class TiXmlString
+{
+ public :
+ // The size type used
+ typedef size_t size_type;
+
+ // Error value for find primitive
+ static const size_type npos; // = -1;
+
+
+ // TiXmlString empty constructor
+ TiXmlString () : rep_(&nullrep_)
+ {
+ }
+
+ // TiXmlString copy constructor
+ TiXmlString ( const TiXmlString & copy) : rep_(0)
+ {
+ init(copy.length());
+ memcpy(start(), copy.data(), length());
+ }
+
+ // TiXmlString constructor, based on a string
+ TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
+ {
+ init( static_cast<size_type>( strlen(copy) ));
+ memcpy(start(), copy, length());
+ }
+
+ // TiXmlString constructor, based on a string
+ TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
+ {
+ init(len);
+ memcpy(start(), str, len);
+ }
+
+ // TiXmlString destructor
+ ~TiXmlString ()
+ {
+ quit();
+ }
+
+ TiXmlString& operator = (const char * copy)
+ {
+ return assign( copy, (size_type)strlen(copy));
+ }
+
+ TiXmlString& operator = (const TiXmlString & copy)
+ {
+ return assign(copy.start(), copy.length());
+ }
+
+
+ // += operator. Maps to append
+ TiXmlString& operator += (const char * suffix)
+ {
+ return append(suffix, static_cast<size_type>( strlen(suffix) ));
+ }
+
+ // += operator. Maps to append
+ TiXmlString& operator += (char single)
+ {
+ return append(&single, 1);
+ }
+
+ // += operator. Maps to append
+ TiXmlString& operator += (const TiXmlString & suffix)
+ {
+ return append(suffix.data(), suffix.length());
+ }
+
+
+ // Convert a TiXmlString into a null-terminated char *
+ const char * c_str () const { return rep_->str; }
+
+ // Convert a TiXmlString into a char * (need not be null terminated).
+ const char * data () const { return rep_->str; }
+
+ // Return the length of a TiXmlString
+ size_type length () const { return rep_->size; }
+
+ // Alias for length()
+ size_type size () const { return rep_->size; }
+
+ // Checks if a TiXmlString is empty
+ bool empty () const { return rep_->size == 0; }
+
+ // Return capacity of string
+ size_type capacity () const { return rep_->capacity; }
+
+
+ // single char extraction
+ const char& at (size_type index) const
+ {
+ assert( index < length() );
+ return rep_->str[ index ];
+ }
+
+ // [] operator
+ char& operator [] (size_type index) const
+ {
+ assert( index < length() );
+ return rep_->str[ index ];
+ }
+
+ // find a char in a string. Return TiXmlString::npos if not found
+ size_type find (char lookup) const
+ {
+ return find(lookup, 0);
+ }
+
+ // find a char in a string from an offset. Return TiXmlString::npos if not found
+ size_type find (char tofind, size_type offset) const
+ {
+ if (offset >= length()) return npos;
+
+ for (const char* p = c_str() + offset; *p != '\0'; ++p)
+ {
+ if (*p == tofind) return static_cast< size_type >( p - c_str() );
+ }
+ return npos;
+ }
+
+ void clear ()
+ {
+ //Lee:
+ //The original was just too strange, though correct:
+ // TiXmlString().swap(*this);
+ //Instead use the quit & re-init:
+ quit();
+ init(0,0);
+ }
+
+ /* Function to reserve a big amount of data when we know we'll need it. Be aware that this
+ function DOES NOT clear the content of the TiXmlString if any exists.
+ */
+ void reserve (size_type cap);
+
+ TiXmlString& assign (const char* str, size_type len);
+
+ TiXmlString& append (const char* str, size_type len);
+
+ void swap (TiXmlString& other)
+ {
+ Rep* r = rep_;
+ rep_ = other.rep_;
+ other.rep_ = r;
+ }
+
+ private:
+
+ void init(size_type sz) { init(sz, sz); }
+ void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
+ char* start() const { return rep_->str; }
+ char* finish() const { return rep_->str + rep_->size; }
+
+ struct Rep
+ {
+ size_type size, capacity;
+ char str[1];
+ };
+
+ void init(size_type sz, size_type cap)
+ {
+ if (cap)
+ {
+ // Lee: the original form:
+ // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
+ // doesn't work in some cases of new being overloaded. Switching
+ // to the normal allocation, although use an 'int' for systems
+ // that are overly picky about structure alignment.
+ const size_type bytesNeeded = sizeof(Rep) + cap;
+ const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
+ rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
+
+ rep_->str[ rep_->size = sz ] = '\0';
+ rep_->capacity = cap;
+ }
+ else
+ {
+ rep_ = &nullrep_;
+ }
+ }
+
+ void quit()
+ {
+ if (rep_ != &nullrep_)
+ {
+ // The rep_ is really an array of ints. (see the allocator, above).
+ // Cast it back before delete, so the compiler won't incorrectly call destructors.
+ delete [] ( reinterpret_cast<int*>( rep_ ) );
+ }
+ }
+
+ Rep * rep_;
+ static Rep nullrep_;
+
+} ;
+
+
+inline bool operator == (const TiXmlString & a, const TiXmlString & b)
+{
+ return ( a.length() == b.length() ) // optimization on some platforms
+ && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
+}
+inline bool operator < (const TiXmlString & a, const TiXmlString & b)
+{
+ return strcmp(a.c_str(), b.c_str()) < 0;
+}
+
+inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
+inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
+inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
+inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
+
+inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
+inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
+inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
+inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
+
+TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
+TiXmlString operator + (const TiXmlString & a, const char* b);
+TiXmlString operator + (const char* a, const TiXmlString & b);
+
+
+/*
+ TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
+ Only the operators that we need for TinyXML have been developped.
+*/
+class TiXmlOutStream : public TiXmlString
+{
+public :
+
+ // TiXmlOutStream << operator.
+ TiXmlOutStream & operator << (const TiXmlString & in)
+ {
+ *this += in;
+ return *this;
+ }
+
+ // TiXmlOutStream << operator.
+ TiXmlOutStream & operator << (const char * in)
+ {
+ *this += in;
+ return *this;
+ }
+
+} ;
+
+#endif // TIXML_STRING_INCLUDED
+#endif // TIXML_USE_STL
diff --git a/engines/wintermute/tinyxml.h b/engines/wintermute/tinyxml.h
index ee73173932..a78e981deb 100644
--- a/engines/wintermute/tinyxml.h
+++ b/engines/wintermute/tinyxml.h
@@ -22,7 +22,7 @@ must not be misrepresented as being the original software.
distribution.
*/
-#define TIXML_USE_STL
+//#define TIXML_USE_STL
#ifndef TINYXML_INCLUDED
#define TINYXML_INCLUDED
diff --git a/engines/wintermute/utils.cpp b/engines/wintermute/utils.cpp
index c69a0068b6..6c5ddb5d40 100644
--- a/engines/wintermute/utils.cpp
+++ b/engines/wintermute/utils.cpp
@@ -238,7 +238,7 @@ char *CBUtils::GetPath(char *Filename) {
//path = boost::filesystem::system_complete(path).string();
warning("CBUtils::GetPath: (%s), not implemented", Filename);
return Filename;
- char *ret = new char[path.length() + 1];
+ char *ret = new char[path.size() + 1];
strcpy(ret, path.c_str());
return ret;
@@ -247,7 +247,7 @@ char *CBUtils::GetPath(char *Filename) {
//////////////////////////////////////////////////////////////////////////
char *CBUtils::GetFilename(char *Filename) {
AnsiString path = PathUtil::GetFileName(Filename);
- char *ret = new char[path.length() + 1];
+ char *ret = new char[path.size() + 1];
strcpy(ret, path.c_str());
return ret;
}
@@ -259,12 +259,12 @@ void CBUtils::RGBtoHSL(uint32 RGBColor, byte *OutH, byte *OutS, byte *OutL) {
float var_B = (D3DCOLGetB(RGBColor) / 255.0f);
//Min. value of RGB
- float var_Min = std::min(var_R, var_G);
- var_Min = std::min(var_Min, var_B);
+ float var_Min = MIN(var_R, var_G);
+ var_Min = MIN(var_Min, var_B);
//Max. value of RGB
- float var_Max = std::max(var_R, var_G);
- var_Max = std::max(var_Max, var_B);
+ float var_Max = MAX(var_R, var_G);
+ var_Max = MAX(var_Max, var_B);
//Delta RGB value
float del_Max = var_Max - var_Min;
diff --git a/engines/wintermute/wintermute.cpp b/engines/wintermute/wintermute.cpp
index c831baf19b..4f791cabd1 100644
--- a/engines/wintermute/wintermute.cpp
+++ b/engines/wintermute/wintermute.cpp
@@ -31,7 +31,7 @@
#include "common/fs.h"
#include "engines/util.h"
-
+#include "engines/wintermute/BGame.h"
#include "engines/wintermute/wintermute.h"
namespace WinterMute {
@@ -103,6 +103,8 @@ namespace WinterMute {
debugC(3, kWinterMuteDebugExample | kWinterMuteDebugExample2, "Example debug call two");
return Common::kNoError;
+
+ CBGame game;
}
} // End of namespace WinterMute \ No newline at end of file
diff --git a/engines/wintermute/wintypes.h b/engines/wintermute/wintypes.h
index 50d6dd16be..c722b92c51 100644
--- a/engines/wintermute/wintypes.h
+++ b/engines/wintermute/wintypes.h
@@ -33,8 +33,8 @@
#include "common/scummsys.h"
//namespace WinterMute {
-#include <cstdio>
-#include <stdio.h>
+//#include <cstdio>
+//#include <stdio.h>
#ifndef __WIN32__
#define WINAPI