From b02b3ebb217473f670570860d0914aee59b1e656 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 2 Jun 2012 02:31:59 +0200 Subject: WINTERMUTE: Add folders for utils and video --- engines/wintermute/utils/utils.cpp | 342 +++++++++++++++++++++++++++++++++++++ 1 file changed, 342 insertions(+) create mode 100644 engines/wintermute/utils/utils.cpp (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp new file mode 100644 index 0000000000..d1ce280639 --- /dev/null +++ b/engines/wintermute/utils/utils.cpp @@ -0,0 +1,342 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#include "engines/wintermute/dcgf.h" +#include "utils.h" +#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/wintypes.h" +#include "PathUtil.h" +#include "engines/wintermute/Base/BGame.h" +#include "common/str.h" +#include "common/textconsole.h" + +namespace WinterMute { + +////////////////////////////////////////////////////////////////////// +static inline unsigned Sqr(int x) { + return (x * x); +} + + +////////////////////////////////////////////////////////////////////////////////// +void CBUtils::Clip(int *DestX, int *DestY, RECT *SrcRect, RECT *DestRect) { + // If it's partly off the right side of the screen + if (*DestX + (SrcRect->right - SrcRect->left) > DestRect->right) + SrcRect->right -= *DestX + (SrcRect->right - SrcRect->left) - DestRect->right; + + if (SrcRect->right < 0) SrcRect->right = 0; + + // Partly off the left side of the screen + if (*DestX < DestRect->left) { + SrcRect->left += DestRect->left - *DestX; + *DestX = DestRect->left; + } + + // Partly off the top of the screen + if (*DestY < DestRect->top) { + SrcRect->top += DestRect->top - *DestY; + *DestY = DestRect->top; + } + + // If it's partly off the bottom side of the screen + if (*DestY + (SrcRect->bottom - SrcRect->top) > DestRect->bottom) + SrcRect->bottom -= ((SrcRect->bottom - SrcRect->top) + *DestY) - DestRect->bottom; + + if (SrcRect->bottom < 0) SrcRect->bottom = 0; + + return; +} + +////////////////////////////////////////////////////////////////////////////////// +// Swap - swaps two integers +////////////////////////////////////////////////////////////////////////////////// +void CBUtils::Swap(int *a, int *b) { + int Temp = *a; + *a = *b; + *b = Temp; +} + +////////////////////////////////////////////////////////////////////////// +bool CBUtils::StrBeginsI(const char *String, const char *Fragment) { + return (scumm_strnicmp(String, Fragment, strlen(Fragment)) == 0); +} + + +////////////////////////////////////////////////////////////////////////// +float CBUtils::NormalizeAngle(float Angle) { + while (Angle > 360) Angle -= 360; + while (Angle < 0) Angle += 360; + + return Angle; +} + + +//////////////////////////////////////////////////////////////////////////////// +void CBUtils::CreatePath(const char *Path, bool PathOnly) { + AnsiString path; + + if (!PathOnly) path = PathUtil::GetDirectoryName(Path); + else path = Path; + +// try { + warning("CBUtils::CreatePath - not implemented: %s", Path); +// boost::filesystem::create_directories(path); +// } catch (...) { + return; +// } +} + + +////////////////////////////////////////////////////////////////////////// +void CBUtils::DebugMessage(HWND hWnd, const char *Text) { + //MessageBox(hWnd, Text, "WME", MB_OK|MB_ICONINFORMATION); +} + + +////////////////////////////////////////////////////////////////////////// +char *CBUtils::SetString(char **String, const char *Value) { + delete[] *String; + *String = new char[strlen(Value) + 1]; + if (*String) strcpy(*String, Value); + return *String; +} + +////////////////////////////////////////////////////////////////////////// +int CBUtils::StrNumEntries(const char *Str, const char Delim) { + int NumEntries = 1; + for (uint32 i = 0; i < strlen(Str); i++) { + if (Str[i] == Delim) NumEntries++; + } + return NumEntries; +} + + +////////////////////////////////////////////////////////////////////////// +char *CBUtils::StrEntry(int Entry, const char *Str, const char Delim) { + int NumEntries = 0; + + const char *Start = NULL; + int Len = 0; + + for (uint32 i = 0; i <= strlen(Str); i++) { + if (NumEntries == Entry) { + if (!Start) Start = Str + i; + else Len++; + } + if (Str[i] == Delim || Str[i] == '\0') { + NumEntries++; + if (Start) { + char *Ret = new char[Len + 1]; + memset(Ret, 0, Len + 1); + strncpy(Ret, Start, Len); + return Ret; + } + } + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +int CBUtils::RandomInt(int From, int To) { + if (To < From) { + int i = To; + To = From; + From = i; + } + return (rand() % (To - From + 1)) + From; +} + +////////////////////////////////////////////////////////////////////////// +float CBUtils::RandomFloat(float From, float To) { + float RandNum = (float)rand() / (float)RAND_MAX; + return From + (To - From) * RandNum; +} + +////////////////////////////////////////////////////////////////////////// +float CBUtils::RandomAngle(float From, float To) { + while (To < From) { + To += 360; + } + return NormalizeAngle(RandomFloat(From, To)); +} + +////////////////////////////////////////////////////////////////////////// +bool CBUtils::MatchesPattern(const char *Pattern, const char *String) { + char stringc, patternc; + + for (;; ++String) { + stringc = toupper(*String); + patternc = toupper(*Pattern++); + + switch (patternc) { + case 0: + return (stringc == 0); + + case '?': + if (stringc == 0) return false; + break; + + case '*': + if (!*Pattern) return true; + + if (*Pattern == '.') { + char *dot; + if (Pattern[1] == '*' && Pattern[2] == 0) return true; + dot = (char *)strchr(String, '.'); + if (Pattern[1] == 0) return (dot == NULL || dot[1] == 0); + if (dot != NULL) { + String = dot; + if (strpbrk(Pattern, "*?[") == NULL && strchr(String + 1, '.') == NULL) + return(scumm_stricmp(Pattern + 1, String + 1) == 0); + } + } + + while (*String) + if (CBUtils::MatchesPattern(Pattern, String++)) + return true; + return false; + + default: + if (patternc != stringc) + if (patternc == '.' && stringc == 0) + return(CBUtils::MatchesPattern(Pattern, String)); + else + return false; + break; + } + } +} + +////////////////////////////////////////////////////////////////////////// +char *CBUtils::GetPath(const char *Filename) { + AnsiString path = PathUtil::GetDirectoryName(Filename); + //path = boost::filesystem::syste_complete(path).string(); + warning("CBUtils::GetPath: (%s), not implemented", Filename); + char *ret = new char[path.size() + 1]; + strcpy(ret, path.c_str()); + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +char *CBUtils::GetFilename(const char *Filename) { + AnsiString path = PathUtil::GetFileName(Filename); + char *ret = new char[path.size() + 1]; + strcpy(ret, path.c_str()); + return ret; +} + +////////////////////////////////////////////////////////////////////////// +void CBUtils::RGBtoHSL(uint32 RGBColor, byte *OutH, byte *OutS, byte *OutL) { + float var_R = (D3DCOLGetR(RGBColor) / 255.0f); + float var_G = (D3DCOLGetG(RGBColor) / 255.0f); + float var_B = (D3DCOLGetB(RGBColor) / 255.0f); + + //Min. value of RGB + float var_Min = MIN(var_R, var_G); + var_Min = MIN(var_Min, var_B); + + //Max. value of RGB + 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; + + float H, S, L; + + L = (var_Max + var_Min) / 2.0f; + + //This is a gray, no chroma... + if (del_Max == 0) { + H = 0; + S = 0; + } + //Chromatic data... + else { + if (L < 0.5f) S = del_Max / (var_Max + var_Min); + else S = del_Max / (2.0f - var_Max - var_Min); + + float del_R = (((var_Max - var_R) / 6.0f) + (del_Max / 2.0f)) / del_Max; + float del_G = (((var_Max - var_G) / 6.0f) + (del_Max / 2.0f)) / del_Max; + float del_B = (((var_Max - var_B) / 6.0f) + (del_Max / 2.0f)) / del_Max; + + if (var_R == var_Max) H = del_B - del_G; + else if (var_G == var_Max) H = (1.0f / 3.0f) + del_R - del_B; + else if (var_B == var_Max) H = (2.0f / 3.0f) + del_G - del_R; + + if (H < 0) H += 1; + if (H > 1) H -= 1; + } + + *OutH = (byte)(H * 255); + *OutS = (byte)(S * 255); + *OutL = (byte)(L * 255); +} + + +////////////////////////////////////////////////////////////////////////// +uint32 CBUtils::HSLtoRGB(byte InH, byte InS, byte InL) { + float H = InH / 255.0f; + float S = InS / 255.0f; + float L = InL / 255.0f; + + byte R, G, B; + + + if (S == 0) { + R = (byte)(L * 255); + G = (byte)(L * 255); + B = (byte)(L * 255); + } else { + float var_1, var_2; + + if (L < 0.5) var_2 = L * (1.0 + S); + else var_2 = (L + S) - (S * L); + + var_1 = 2.0f * L - var_2; + + R = (byte)(255 * Hue2RGB(var_1, var_2, H + (1.0f / 3.0f))); + G = (byte)(255 * Hue2RGB(var_1, var_2, H)); + B = (byte)(255 * Hue2RGB(var_1, var_2, H - (1.0f / 3.0f))); + } + return DRGBA(255, R, G, B); +} + + +////////////////////////////////////////////////////////////////////////// +float CBUtils::Hue2RGB(float v1, float v2, float vH) { + if (vH < 0.0f) vH += 1.0f; + if (vH > 1.0f) vH -= 1.0f; + if ((6.0f * vH) < 1.0f) return (v1 + (v2 - v1) * 6.0f * vH); + if ((2.0f * vH) < 1.0f) return (v2); + if ((3.0f * vH) < 2.0f) return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + return (v1); +} + +} // end of namespace WinterMute -- cgit v1.2.3 From 1d5e59766fc1e6083921741a1ad270dd8d9363d1 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 8 Jun 2012 18:24:41 +0200 Subject: WINTERMUTE: Move FORBIDDEN_SYMBOL_EXCEPTION out of the headers and into the CPP-files that still need it. --- engines/wintermute/utils/utils.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index d1ce280639..c9131608be 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -26,6 +26,8 @@ * Copyright (c) 2011 Jan Nedoma */ +#define FORBIDDEN_SYMBOL_EXCEPTION_rand + #include "engines/wintermute/dcgf.h" #include "utils.h" #include "engines/wintermute/PlatformSDL.h" -- cgit v1.2.3 From 850e237d318a3299648a07fd142667b966e316c3 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 15 Jun 2012 19:19:09 +0200 Subject: WINTERMUTE: Get rid of rand/srand. --- engines/wintermute/utils/utils.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index c9131608be..4e4678ffae 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -26,8 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#define FORBIDDEN_SYMBOL_EXCEPTION_rand - #include "engines/wintermute/dcgf.h" #include "utils.h" #include "engines/wintermute/PlatformSDL.h" @@ -36,6 +34,7 @@ #include "engines/wintermute/Base/BGame.h" #include "common/str.h" #include "common/textconsole.h" +#include "wintermute.h" namespace WinterMute { @@ -164,19 +163,21 @@ char *CBUtils::StrEntry(int Entry, const char *Str, const char Delim) { } ////////////////////////////////////////////////////////////////////////// -int CBUtils::RandomInt(int From, int To) { - if (To < From) { - int i = To; - To = From; - From = i; +int CBUtils::RandomInt(int from, int to) { + if (to < from) { + int i = to; + to = from; + from = i; } - return (rand() % (To - From + 1)) + From; + return g_wintermute->randInt(from, to); +// return (rand() % (to - from + 1)) + from; } ////////////////////////////////////////////////////////////////////////// -float CBUtils::RandomFloat(float From, float To) { - float RandNum = (float)rand() / (float)RAND_MAX; - return From + (To - From) * RandNum; +float CBUtils::RandomFloat(float from, float to) { + const uint32 randMax = RAND_MAX; + float randNum = (float)g_wintermute->randInt(0, randMax) / (float)randMax; + return from + (to - from) * randNum; } ////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 9ce1685bf51a1f4f02e3a9760fc84c53ebc328c9 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 22 Jun 2012 10:34:50 +0200 Subject: WINTERMUTE: Remove AdActorDir and fix build --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 4e4678ffae..29c992f1ac 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -34,7 +34,7 @@ #include "engines/wintermute/Base/BGame.h" #include "common/str.h" #include "common/textconsole.h" -#include "wintermute.h" +#include "engines/wintermute/wintermute.h" namespace WinterMute { -- cgit v1.2.3 From 88a3d91cbd60a4e31194750cf367f8b50620604b Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 26 Jun 2012 20:46:39 +0200 Subject: WINTERMUTE: Fix a few warnings pointed out by [md5] --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 29c992f1ac..845c2e21c6 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -271,7 +271,7 @@ void CBUtils::RGBtoHSL(uint32 RGBColor, byte *OutH, byte *OutS, byte *OutL) { //Delta RGB value float del_Max = var_Max - var_Min; - float H, S, L; + float H = 0.0f, S = 0.0f, L = 0.0f; L = (var_Max + var_Min) / 2.0f; -- cgit v1.2.3 From 6c6c0bb0167cbf004cf300a81dda71a952d93626 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 3 Jul 2012 05:00:57 +0200 Subject: WINTERMUTE: Mass-rename "Value"->"value" --- engines/wintermute/utils/utils.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 845c2e21c6..2f66313bb0 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -120,11 +120,11 @@ void CBUtils::DebugMessage(HWND hWnd, const char *Text) { ////////////////////////////////////////////////////////////////////////// -char *CBUtils::SetString(char **String, const char *Value) { - delete[] *String; - *String = new char[strlen(Value) + 1]; - if (*String) strcpy(*String, Value); - return *String; +char *CBUtils::SetString(char **string, const char *value) { + delete[] *string; + *string = new char[strlen(value) + 1]; + if (*string) strcpy(*string, value); + return *string; } ////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 2457d3860470a757ccf7f008c5638c6a7b5af1de Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 3 Jul 2012 06:20:09 +0200 Subject: WINTERMUTE: Rename FuncName->funcName in PathUtil and StringUtil --- engines/wintermute/utils/utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 2f66313bb0..ae456b25e7 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -101,7 +101,7 @@ float CBUtils::NormalizeAngle(float Angle) { void CBUtils::CreatePath(const char *Path, bool PathOnly) { AnsiString path; - if (!PathOnly) path = PathUtil::GetDirectoryName(Path); + if (!PathOnly) path = PathUtil::getDirectoryName(Path); else path = Path; // try { @@ -237,7 +237,7 @@ bool CBUtils::MatchesPattern(const char *Pattern, const char *String) { ////////////////////////////////////////////////////////////////////////// char *CBUtils::GetPath(const char *Filename) { - AnsiString path = PathUtil::GetDirectoryName(Filename); + AnsiString path = PathUtil::getDirectoryName(Filename); //path = boost::filesystem::syste_complete(path).string(); warning("CBUtils::GetPath: (%s), not implemented", Filename); char *ret = new char[path.size() + 1]; @@ -248,7 +248,7 @@ char *CBUtils::GetPath(const char *Filename) { ////////////////////////////////////////////////////////////////////////// char *CBUtils::GetFilename(const char *Filename) { - AnsiString path = PathUtil::GetFileName(Filename); + AnsiString path = PathUtil::getFileName(Filename); char *ret = new char[path.size() + 1]; strcpy(ret, path.c_str()); return ret; -- cgit v1.2.3 From 370355f85ec1ac55b7a1467899ecfbff788ec1c7 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 3 Jul 2012 06:32:19 +0200 Subject: WINTERMUTE: Rename FuncName->funcName in utils --- engines/wintermute/utils/utils.cpp | 142 ++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 71 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index ae456b25e7..ab7ebac565 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -45,30 +45,30 @@ static inline unsigned Sqr(int x) { ////////////////////////////////////////////////////////////////////////////////// -void CBUtils::Clip(int *DestX, int *DestY, RECT *SrcRect, RECT *DestRect) { +void CBUtils::clip(int *destX, int *destY, RECT *srcRect, RECT *destRect) { // If it's partly off the right side of the screen - if (*DestX + (SrcRect->right - SrcRect->left) > DestRect->right) - SrcRect->right -= *DestX + (SrcRect->right - SrcRect->left) - DestRect->right; + if (*destX + (srcRect->right - srcRect->left) > destRect->right) + srcRect->right -= *destX + (srcRect->right - srcRect->left) - destRect->right; - if (SrcRect->right < 0) SrcRect->right = 0; + if (srcRect->right < 0) srcRect->right = 0; // Partly off the left side of the screen - if (*DestX < DestRect->left) { - SrcRect->left += DestRect->left - *DestX; - *DestX = DestRect->left; + if (*destX < destRect->left) { + srcRect->left += destRect->left - *destX; + *destX = destRect->left; } // Partly off the top of the screen - if (*DestY < DestRect->top) { - SrcRect->top += DestRect->top - *DestY; - *DestY = DestRect->top; + if (*destY < destRect->top) { + srcRect->top += destRect->top - *destY; + *destY = destRect->top; } // If it's partly off the bottom side of the screen - if (*DestY + (SrcRect->bottom - SrcRect->top) > DestRect->bottom) - SrcRect->bottom -= ((SrcRect->bottom - SrcRect->top) + *DestY) - DestRect->bottom; + if (*destY + (srcRect->bottom - srcRect->top) > destRect->bottom) + srcRect->bottom -= ((srcRect->bottom - srcRect->top) + *destY) - destRect->bottom; - if (SrcRect->bottom < 0) SrcRect->bottom = 0; + if (srcRect->bottom < 0) srcRect->bottom = 0; return; } @@ -76,36 +76,36 @@ void CBUtils::Clip(int *DestX, int *DestY, RECT *SrcRect, RECT *DestRect) { ////////////////////////////////////////////////////////////////////////////////// // Swap - swaps two integers ////////////////////////////////////////////////////////////////////////////////// -void CBUtils::Swap(int *a, int *b) { +void CBUtils::swap(int *a, int *b) { int Temp = *a; *a = *b; *b = Temp; } ////////////////////////////////////////////////////////////////////////// -bool CBUtils::StrBeginsI(const char *String, const char *Fragment) { - return (scumm_strnicmp(String, Fragment, strlen(Fragment)) == 0); +bool CBUtils::strBeginsI(const char *string, const char *fragment) { + return (scumm_strnicmp(string, fragment, strlen(fragment)) == 0); } ////////////////////////////////////////////////////////////////////////// -float CBUtils::NormalizeAngle(float Angle) { - while (Angle > 360) Angle -= 360; - while (Angle < 0) Angle += 360; +float CBUtils::normalizeAngle(float angle) { + while (angle > 360) angle -= 360; + while (angle < 0) angle += 360; - return Angle; + return angle; } //////////////////////////////////////////////////////////////////////////////// -void CBUtils::CreatePath(const char *Path, bool PathOnly) { - AnsiString path; +void CBUtils::createPath(const char *path, bool pathOnly) { + AnsiString pathStr; - if (!PathOnly) path = PathUtil::getDirectoryName(Path); - else path = Path; + if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); + else pathStr = path; // try { - warning("CBUtils::CreatePath - not implemented: %s", Path); + warning("CBUtils::CreatePath - not implemented: %s", path); // boost::filesystem::create_directories(path); // } catch (...) { return; @@ -114,13 +114,13 @@ void CBUtils::CreatePath(const char *Path, bool PathOnly) { ////////////////////////////////////////////////////////////////////////// -void CBUtils::DebugMessage(HWND hWnd, const char *Text) { +void CBUtils::debugMessage(HWND hWnd, const char *text) { //MessageBox(hWnd, Text, "WME", MB_OK|MB_ICONINFORMATION); } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::SetString(char **string, const char *value) { +char *CBUtils::setString(char **string, const char *value) { delete[] *string; *string = new char[strlen(value) + 1]; if (*string) strcpy(*string, value); @@ -128,34 +128,34 @@ char *CBUtils::SetString(char **string, const char *value) { } ////////////////////////////////////////////////////////////////////////// -int CBUtils::StrNumEntries(const char *Str, const char Delim) { - int NumEntries = 1; - for (uint32 i = 0; i < strlen(Str); i++) { - if (Str[i] == Delim) NumEntries++; +int CBUtils::strNumEntries(const char *str, const char delim) { + int numEntries = 1; + for (uint32 i = 0; i < strlen(str); i++) { + if (str[i] == delim) numEntries++; } - return NumEntries; + return numEntries; } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::StrEntry(int Entry, const char *Str, const char Delim) { - int NumEntries = 0; +char *CBUtils::strEntry(int entry, const char *str, const char delim) { + int numEntries = 0; - const char *Start = NULL; - int Len = 0; + const char *start = NULL; + int len = 0; - for (uint32 i = 0; i <= strlen(Str); i++) { - if (NumEntries == Entry) { - if (!Start) Start = Str + i; - else Len++; + for (uint32 i = 0; i <= strlen(str); i++) { + if (numEntries == entry) { + if (!start) start = str + i; + else len++; } - if (Str[i] == Delim || Str[i] == '\0') { - NumEntries++; - if (Start) { - char *Ret = new char[Len + 1]; - memset(Ret, 0, Len + 1); - strncpy(Ret, Start, Len); - return Ret; + if (str[i] == delim || str[i] == '\0') { + numEntries++; + if (start) { + char *ret = new char[len + 1]; + memset(ret, 0, len + 1); + strncpy(ret, start, len); + return ret; } } } @@ -163,7 +163,7 @@ char *CBUtils::StrEntry(int Entry, const char *Str, const char Delim) { } ////////////////////////////////////////////////////////////////////////// -int CBUtils::RandomInt(int from, int to) { +int CBUtils::randomInt(int from, int to) { if (to < from) { int i = to; to = from; @@ -174,27 +174,27 @@ int CBUtils::RandomInt(int from, int to) { } ////////////////////////////////////////////////////////////////////////// -float CBUtils::RandomFloat(float from, float to) { +float CBUtils::randomFloat(float from, float to) { const uint32 randMax = RAND_MAX; float randNum = (float)g_wintermute->randInt(0, randMax) / (float)randMax; return from + (to - from) * randNum; } ////////////////////////////////////////////////////////////////////////// -float CBUtils::RandomAngle(float From, float To) { +float CBUtils::randomAngle(float From, float To) { while (To < From) { To += 360; } - return NormalizeAngle(RandomFloat(From, To)); + return normalizeAngle(randomFloat(From, To)); } ////////////////////////////////////////////////////////////////////////// -bool CBUtils::MatchesPattern(const char *Pattern, const char *String) { +bool CBUtils::matchesPattern(const char *pattern, const char *string) { char stringc, patternc; - for (;; ++String) { - stringc = toupper(*String); - patternc = toupper(*Pattern++); + for (;; ++string) { + stringc = toupper(*string); + patternc = toupper(*pattern++); switch (patternc) { case 0: @@ -205,29 +205,29 @@ bool CBUtils::MatchesPattern(const char *Pattern, const char *String) { break; case '*': - if (!*Pattern) return true; + if (!*pattern) return true; - if (*Pattern == '.') { + if (*pattern == '.') { char *dot; - if (Pattern[1] == '*' && Pattern[2] == 0) return true; - dot = (char *)strchr(String, '.'); - if (Pattern[1] == 0) return (dot == NULL || dot[1] == 0); + if (pattern[1] == '*' && pattern[2] == 0) return true; + dot = (char *)strchr(string, '.'); + if (pattern[1] == 0) return (dot == NULL || dot[1] == 0); if (dot != NULL) { - String = dot; - if (strpbrk(Pattern, "*?[") == NULL && strchr(String + 1, '.') == NULL) - return(scumm_stricmp(Pattern + 1, String + 1) == 0); + string = dot; + if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) + return(scumm_stricmp(pattern + 1, string + 1) == 0); } } - while (*String) - if (CBUtils::MatchesPattern(Pattern, String++)) + while (*string) + if (CBUtils::matchesPattern(pattern, string++)) return true; return false; default: if (patternc != stringc) if (patternc == '.' && stringc == 0) - return(CBUtils::MatchesPattern(Pattern, String)); + return(CBUtils::matchesPattern(pattern, string)); else return false; break; @@ -236,10 +236,10 @@ bool CBUtils::MatchesPattern(const char *Pattern, const char *String) { } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::GetPath(const char *Filename) { - AnsiString path = PathUtil::getDirectoryName(Filename); +char *CBUtils::getPath(const char *filename) { + AnsiString path = PathUtil::getDirectoryName(filename); //path = boost::filesystem::syste_complete(path).string(); - warning("CBUtils::GetPath: (%s), not implemented", Filename); + warning("CBUtils::GetPath: (%s), not implemented", filename); char *ret = new char[path.size() + 1]; strcpy(ret, path.c_str()); @@ -247,8 +247,8 @@ char *CBUtils::GetPath(const char *Filename) { } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::GetFilename(const char *Filename) { - AnsiString path = PathUtil::getFileName(Filename); +char *CBUtils::getFilename(const char *filename) { + AnsiString path = PathUtil::getFileName(filename); char *ret = new char[path.size() + 1]; strcpy(ret, path.c_str()); return ret; -- cgit v1.2.3 From 7f1296e9dc5060fd49286b6a916483c200611983 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 9 Jul 2012 03:07:30 +0200 Subject: WINTERMUTE: Remove references to HWND --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index ab7ebac565..46e5a8da36 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -114,7 +114,7 @@ void CBUtils::createPath(const char *path, bool pathOnly) { ////////////////////////////////////////////////////////////////////////// -void CBUtils::debugMessage(HWND hWnd, const char *text) { +void CBUtils::debugMessage(const char *text) { //MessageBox(hWnd, Text, "WME", MB_OK|MB_ICONINFORMATION); } -- cgit v1.2.3 From 1eea9ad1a3ae577195363abe475cfbbee33d153b Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 9 Jul 2012 03:27:21 +0200 Subject: WINTERMUTE: Remove most of the wintype-definitions. --- engines/wintermute/utils/utils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 46e5a8da36..ca68b3c691 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -256,9 +256,9 @@ char *CBUtils::getFilename(const char *filename) { ////////////////////////////////////////////////////////////////////////// void CBUtils::RGBtoHSL(uint32 RGBColor, byte *OutH, byte *OutS, byte *OutL) { - float var_R = (D3DCOLGetR(RGBColor) / 255.0f); - float var_G = (D3DCOLGetG(RGBColor) / 255.0f); - float var_B = (D3DCOLGetB(RGBColor) / 255.0f); + float var_R = (RGBCOLGetR(RGBColor) / 255.0f); + float var_G = (RGBCOLGetG(RGBColor) / 255.0f); + float var_B = (RGBCOLGetB(RGBColor) / 255.0f); //Min. value of RGB float var_Min = MIN(var_R, var_G); @@ -328,7 +328,7 @@ uint32 CBUtils::HSLtoRGB(byte InH, byte InS, byte InL) { G = (byte)(255 * Hue2RGB(var_1, var_2, H)); B = (byte)(255 * Hue2RGB(var_1, var_2, H - (1.0f / 3.0f))); } - return DRGBA(255, R, G, B); + return BYTETORGBA(255, R, G, B); } -- cgit v1.2.3 From 7c984d24a8cd2ebe5a7860e21cda392edada34b3 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 9 Jul 2012 04:09:15 +0200 Subject: WINTERMUTE: Change RECT -> Common::Rect and POINT-> Common::Point, completing the removal of Windows-specifics in wintypes.h --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index ca68b3c691..d672656973 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -45,7 +45,7 @@ static inline unsigned Sqr(int x) { ////////////////////////////////////////////////////////////////////////////////// -void CBUtils::clip(int *destX, int *destY, RECT *srcRect, RECT *destRect) { +void CBUtils::clip(int *destX, int *destY, Common::Rect *srcRect, Common::Rect *destRect) { // If it's partly off the right side of the screen if (*destX + (srcRect->right - srcRect->left) > destRect->right) srcRect->right -= *destX + (srcRect->right - srcRect->left) - destRect->right; -- cgit v1.2.3 From 0ef77c57b6f6889471c7c5d902999fcf34c47a89 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 9 Jul 2012 04:36:25 +0200 Subject: WINTERMUTE: Rename VarName->varName in WinterMute::Utils --- engines/wintermute/utils/utils.cpp | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index d672656973..ae64cd0686 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -255,51 +255,51 @@ char *CBUtils::getFilename(const char *filename) { } ////////////////////////////////////////////////////////////////////////// -void CBUtils::RGBtoHSL(uint32 RGBColor, byte *OutH, byte *OutS, byte *OutL) { - float var_R = (RGBCOLGetR(RGBColor) / 255.0f); - float var_G = (RGBCOLGetG(RGBColor) / 255.0f); - float var_B = (RGBCOLGetB(RGBColor) / 255.0f); +void CBUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { + float varR = (RGBCOLGetR(RGBColor) / 255.0f); + float varG = (RGBCOLGetG(RGBColor) / 255.0f); + float varB = (RGBCOLGetB(RGBColor) / 255.0f); //Min. value of RGB - float var_Min = MIN(var_R, var_G); - var_Min = MIN(var_Min, var_B); + float varMin = MIN(varR, varG); + varMin = MIN(varMin, varB); //Max. value of RGB - float var_Max = MAX(var_R, var_G); - var_Max = MAX(var_Max, var_B); + float varMax = MAX(varR, varG); + varMax = MAX(varMax, varB); //Delta RGB value - float del_Max = var_Max - var_Min; + float delMax = varMax - varMin; float H = 0.0f, S = 0.0f, L = 0.0f; - L = (var_Max + var_Min) / 2.0f; + L = (varMax + varMin) / 2.0f; //This is a gray, no chroma... - if (del_Max == 0) { + if (delMax == 0) { H = 0; S = 0; } //Chromatic data... else { - if (L < 0.5f) S = del_Max / (var_Max + var_Min); - else S = del_Max / (2.0f - var_Max - var_Min); + if (L < 0.5f) S = delMax / (varMax + varMin); + else S = delMax / (2.0f - varMax - varMin); - float del_R = (((var_Max - var_R) / 6.0f) + (del_Max / 2.0f)) / del_Max; - float del_G = (((var_Max - var_G) / 6.0f) + (del_Max / 2.0f)) / del_Max; - float del_B = (((var_Max - var_B) / 6.0f) + (del_Max / 2.0f)) / del_Max; + float delR = (((varMax - varR) / 6.0f) + (delMax / 2.0f)) / delMax; + float delG = (((varMax - varG) / 6.0f) + (delMax / 2.0f)) / delMax; + float delB = (((varMax - varB) / 6.0f) + (delMax / 2.0f)) / delMax; - if (var_R == var_Max) H = del_B - del_G; - else if (var_G == var_Max) H = (1.0f / 3.0f) + del_R - del_B; - else if (var_B == var_Max) H = (2.0f / 3.0f) + del_G - del_R; + if (varR == varMax) H = delB - delG; + else if (varG == varMax) H = (1.0f / 3.0f) + delR - delB; + else if (varB == varMax) H = (2.0f / 3.0f) + delG - delR; if (H < 0) H += 1; if (H > 1) H -= 1; } - *OutH = (byte)(H * 255); - *OutS = (byte)(S * 255); - *OutL = (byte)(L * 255); + *outH = (byte)(H * 255); + *outS = (byte)(S * 255); + *outL = (byte)(L * 255); } -- cgit v1.2.3 From 07cebdbf2b70e02b12d32880d23dbe293ab12358 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 9 Jul 2012 12:27:06 +0200 Subject: WINTERMUTE: Change usage of Common::Rect to our own 32-bit variant. --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index ae64cd0686..9efc7b8935 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -45,7 +45,7 @@ static inline unsigned Sqr(int x) { ////////////////////////////////////////////////////////////////////////////////// -void CBUtils::clip(int *destX, int *destY, Common::Rect *srcRect, Common::Rect *destRect) { +void CBUtils::clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect) { // If it's partly off the right side of the screen if (*destX + (srcRect->right - srcRect->left) > destRect->right) srcRect->right -= *destX + (srcRect->right - srcRect->left) - destRect->right; -- cgit v1.2.3 From 113961fd2a2203434b03766d722a0f8c0854bfd0 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 19 Jul 2012 19:29:15 +0200 Subject: WINTERMUTE: Change all folder-names to lowercase. --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 9efc7b8935..641b2d20ac 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -31,7 +31,7 @@ #include "engines/wintermute/PlatformSDL.h" #include "engines/wintermute/wintypes.h" #include "PathUtil.h" -#include "engines/wintermute/Base/BGame.h" +#include "engines/wintermute/base/BGame.h" #include "common/str.h" #include "common/textconsole.h" #include "engines/wintermute/wintermute.h" -- cgit v1.2.3 From 3ad839b32c5e432e93058218db9139dfbe8b8c84 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 20 Jul 2012 00:45:20 +0200 Subject: WINTERMUTE: Rename PlatformSDL->platform_osystem --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 641b2d20ac..1735732185 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -28,7 +28,7 @@ #include "engines/wintermute/dcgf.h" #include "utils.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/wintypes.h" #include "PathUtil.h" #include "engines/wintermute/base/BGame.h" -- cgit v1.2.3 From 5683f076331d2831eb4720b65bb53e8d01ca33ee Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 21 Jul 2012 18:19:07 +0200 Subject: WINTERMUTE: Rename CamelCased filenames to prefixed_under_score-filenames This is mostly a lead-up to namespacing the Ad/Base folders, and then possibly removing the prefixes from the files, it also has the added benefit of getting rid of the odd case-typos that makes for issues on platforms that don't ignore case. --- engines/wintermute/utils/utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 1735732185..e77f35a0e8 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -27,11 +27,11 @@ */ #include "engines/wintermute/dcgf.h" -#include "utils.h" +#include "engines/wintermute/utils/utils.h" #include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/wintypes.h" -#include "PathUtil.h" -#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/utils/path_util.h" +#include "engines/wintermute/base/base_game.h" #include "common/str.h" #include "common/textconsole.h" #include "engines/wintermute/wintermute.h" -- cgit v1.2.3 From b5a07fef8ebf29f7f44b15d9b34799c7e115fdad Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 21 Jul 2012 21:01:47 +0200 Subject: WINTERMUTE: Get rid of the C-prefix for class-definitions. --- engines/wintermute/utils/utils.cpp | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index e77f35a0e8..038095c8ae 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -45,7 +45,7 @@ static inline unsigned Sqr(int x) { ////////////////////////////////////////////////////////////////////////////////// -void CBUtils::clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect) { +void BaseUtils::clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect) { // If it's partly off the right side of the screen if (*destX + (srcRect->right - srcRect->left) > destRect->right) srcRect->right -= *destX + (srcRect->right - srcRect->left) - destRect->right; @@ -76,20 +76,20 @@ void CBUtils::clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect) { ////////////////////////////////////////////////////////////////////////////////// // Swap - swaps two integers ////////////////////////////////////////////////////////////////////////////////// -void CBUtils::swap(int *a, int *b) { +void BaseUtils::swap(int *a, int *b) { int Temp = *a; *a = *b; *b = Temp; } ////////////////////////////////////////////////////////////////////////// -bool CBUtils::strBeginsI(const char *string, const char *fragment) { +bool BaseUtils::strBeginsI(const char *string, const char *fragment) { return (scumm_strnicmp(string, fragment, strlen(fragment)) == 0); } ////////////////////////////////////////////////////////////////////////// -float CBUtils::normalizeAngle(float angle) { +float BaseUtils::normalizeAngle(float angle) { while (angle > 360) angle -= 360; while (angle < 0) angle += 360; @@ -98,14 +98,14 @@ float CBUtils::normalizeAngle(float angle) { //////////////////////////////////////////////////////////////////////////////// -void CBUtils::createPath(const char *path, bool pathOnly) { +void BaseUtils::createPath(const char *path, bool pathOnly) { AnsiString pathStr; if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); else pathStr = path; // try { - warning("CBUtils::CreatePath - not implemented: %s", path); + warning("BaseUtils::CreatePath - not implemented: %s", path); // boost::filesystem::create_directories(path); // } catch (...) { return; @@ -114,13 +114,13 @@ void CBUtils::createPath(const char *path, bool pathOnly) { ////////////////////////////////////////////////////////////////////////// -void CBUtils::debugMessage(const char *text) { +void BaseUtils::debugMessage(const char *text) { //MessageBox(hWnd, Text, "WME", MB_OK|MB_ICONINFORMATION); } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::setString(char **string, const char *value) { +char *BaseUtils::setString(char **string, const char *value) { delete[] *string; *string = new char[strlen(value) + 1]; if (*string) strcpy(*string, value); @@ -128,7 +128,7 @@ char *CBUtils::setString(char **string, const char *value) { } ////////////////////////////////////////////////////////////////////////// -int CBUtils::strNumEntries(const char *str, const char delim) { +int BaseUtils::strNumEntries(const char *str, const char delim) { int numEntries = 1; for (uint32 i = 0; i < strlen(str); i++) { if (str[i] == delim) numEntries++; @@ -138,7 +138,7 @@ int CBUtils::strNumEntries(const char *str, const char delim) { ////////////////////////////////////////////////////////////////////////// -char *CBUtils::strEntry(int entry, const char *str, const char delim) { +char *BaseUtils::strEntry(int entry, const char *str, const char delim) { int numEntries = 0; const char *start = NULL; @@ -163,7 +163,7 @@ char *CBUtils::strEntry(int entry, const char *str, const char delim) { } ////////////////////////////////////////////////////////////////////////// -int CBUtils::randomInt(int from, int to) { +int BaseUtils::randomInt(int from, int to) { if (to < from) { int i = to; to = from; @@ -174,14 +174,14 @@ int CBUtils::randomInt(int from, int to) { } ////////////////////////////////////////////////////////////////////////// -float CBUtils::randomFloat(float from, float to) { +float BaseUtils::randomFloat(float from, float to) { const uint32 randMax = RAND_MAX; float randNum = (float)g_wintermute->randInt(0, randMax) / (float)randMax; return from + (to - from) * randNum; } ////////////////////////////////////////////////////////////////////////// -float CBUtils::randomAngle(float From, float To) { +float BaseUtils::randomAngle(float From, float To) { while (To < From) { To += 360; } @@ -189,7 +189,7 @@ float CBUtils::randomAngle(float From, float To) { } ////////////////////////////////////////////////////////////////////////// -bool CBUtils::matchesPattern(const char *pattern, const char *string) { +bool BaseUtils::matchesPattern(const char *pattern, const char *string) { char stringc, patternc; for (;; ++string) { @@ -220,14 +220,14 @@ bool CBUtils::matchesPattern(const char *pattern, const char *string) { } while (*string) - if (CBUtils::matchesPattern(pattern, string++)) + if (BaseUtils::matchesPattern(pattern, string++)) return true; return false; default: if (patternc != stringc) if (patternc == '.' && stringc == 0) - return(CBUtils::matchesPattern(pattern, string)); + return(BaseUtils::matchesPattern(pattern, string)); else return false; break; @@ -236,10 +236,10 @@ bool CBUtils::matchesPattern(const char *pattern, const char *string) { } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::getPath(const char *filename) { +char *BaseUtils::getPath(const char *filename) { AnsiString path = PathUtil::getDirectoryName(filename); //path = boost::filesystem::syste_complete(path).string(); - warning("CBUtils::GetPath: (%s), not implemented", filename); + warning("BaseUtils::GetPath: (%s), not implemented", filename); char *ret = new char[path.size() + 1]; strcpy(ret, path.c_str()); @@ -247,7 +247,7 @@ char *CBUtils::getPath(const char *filename) { } ////////////////////////////////////////////////////////////////////////// -char *CBUtils::getFilename(const char *filename) { +char *BaseUtils::getFilename(const char *filename) { AnsiString path = PathUtil::getFileName(filename); char *ret = new char[path.size() + 1]; strcpy(ret, path.c_str()); @@ -255,7 +255,7 @@ char *CBUtils::getFilename(const char *filename) { } ////////////////////////////////////////////////////////////////////////// -void CBUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { +void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { float varR = (RGBCOLGetR(RGBColor) / 255.0f); float varG = (RGBCOLGetG(RGBColor) / 255.0f); float varB = (RGBCOLGetB(RGBColor) / 255.0f); @@ -304,7 +304,7 @@ void CBUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { ////////////////////////////////////////////////////////////////////////// -uint32 CBUtils::HSLtoRGB(byte InH, byte InS, byte InL) { +uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { float H = InH / 255.0f; float S = InS / 255.0f; float L = InL / 255.0f; @@ -333,7 +333,7 @@ uint32 CBUtils::HSLtoRGB(byte InH, byte InS, byte InL) { ////////////////////////////////////////////////////////////////////////// -float CBUtils::Hue2RGB(float v1, float v2, float vH) { +float BaseUtils::Hue2RGB(float v1, float v2, float vH) { if (vH < 0.0f) vH += 1.0f; if (vH > 1.0f) vH -= 1.0f; if ((6.0f * vH) < 1.0f) return (v1 + (v2 - v1) * 6.0f * vH); -- cgit v1.2.3 From 7a818009b4c20df1811c0b158b0f8acfe0e3d208 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 23 Jul 2012 02:23:14 +0200 Subject: WINTERMUTE: Clean out unused utils. --- engines/wintermute/utils/utils.cpp | 64 ++------------------------------------ 1 file changed, 2 insertions(+), 62 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 038095c8ae..ee723cf80a 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -26,14 +26,7 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/wintypes.h" -#include "engines/wintermute/utils/path_util.h" -#include "engines/wintermute/base/base_game.h" -#include "common/str.h" -#include "common/textconsole.h" #include "engines/wintermute/wintermute.h" namespace WinterMute { @@ -43,36 +36,6 @@ static inline unsigned Sqr(int x) { return (x * x); } - -////////////////////////////////////////////////////////////////////////////////// -void BaseUtils::clip(int *destX, int *destY, Rect32 *srcRect, Rect32 *destRect) { - // If it's partly off the right side of the screen - if (*destX + (srcRect->right - srcRect->left) > destRect->right) - srcRect->right -= *destX + (srcRect->right - srcRect->left) - destRect->right; - - if (srcRect->right < 0) srcRect->right = 0; - - // Partly off the left side of the screen - if (*destX < destRect->left) { - srcRect->left += destRect->left - *destX; - *destX = destRect->left; - } - - // Partly off the top of the screen - if (*destY < destRect->top) { - srcRect->top += destRect->top - *destY; - *destY = destRect->top; - } - - // If it's partly off the bottom side of the screen - if (*destY + (srcRect->bottom - srcRect->top) > destRect->bottom) - srcRect->bottom -= ((srcRect->bottom - srcRect->top) + *destY) - destRect->bottom; - - if (srcRect->bottom < 0) srcRect->bottom = 0; - - return; -} - ////////////////////////////////////////////////////////////////////////////////// // Swap - swaps two integers ////////////////////////////////////////////////////////////////////////////////// @@ -82,11 +45,6 @@ void BaseUtils::swap(int *a, int *b) { *b = Temp; } -////////////////////////////////////////////////////////////////////////// -bool BaseUtils::strBeginsI(const char *string, const char *fragment) { - return (scumm_strnicmp(string, fragment, strlen(fragment)) == 0); -} - ////////////////////////////////////////////////////////////////////////// float BaseUtils::normalizeAngle(float angle) { @@ -99,11 +57,11 @@ float BaseUtils::normalizeAngle(float angle) { //////////////////////////////////////////////////////////////////////////////// void BaseUtils::createPath(const char *path, bool pathOnly) { - AnsiString pathStr; +/* AnsiString pathStr; if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); else pathStr = path; - +*/ // try { warning("BaseUtils::CreatePath - not implemented: %s", path); // boost::filesystem::create_directories(path); @@ -235,24 +193,6 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { } } -////////////////////////////////////////////////////////////////////////// -char *BaseUtils::getPath(const char *filename) { - AnsiString path = PathUtil::getDirectoryName(filename); - //path = boost::filesystem::syste_complete(path).string(); - warning("BaseUtils::GetPath: (%s), not implemented", filename); - char *ret = new char[path.size() + 1]; - strcpy(ret, path.c_str()); - - return ret; -} - -////////////////////////////////////////////////////////////////////////// -char *BaseUtils::getFilename(const char *filename) { - AnsiString path = PathUtil::getFileName(filename); - char *ret = new char[path.size() + 1]; - strcpy(ret, path.c_str()); - return ret; -} ////////////////////////////////////////////////////////////////////////// void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { -- cgit v1.2.3 From 38507fa9895620639d8733dbb4e085dfb2282a33 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 04:12:58 +0200 Subject: WINTERMUTE: AStyle-formatting. --- engines/wintermute/utils/utils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index ee723cf80a..a4751ef11b 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -57,11 +57,11 @@ float BaseUtils::normalizeAngle(float angle) { //////////////////////////////////////////////////////////////////////////////// void BaseUtils::createPath(const char *path, bool pathOnly) { -/* AnsiString pathStr; + /* AnsiString pathStr; - if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); - else pathStr = path; -*/ + if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); + else pathStr = path; + */ // try { warning("BaseUtils::CreatePath - not implemented: %s", path); // boost::filesystem::create_directories(path); -- cgit v1.2.3 From ef11f9d0c53cbdd9d88a99143de6f43f34d7e24d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 15:59:26 +0200 Subject: WINTERMUTE: Run Astyle with add-braces to break one-line statements into easier-to-read-code. --- engines/wintermute/utils/utils.cpp | 102 +++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 28 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index a4751ef11b..39bb1d7137 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -48,8 +48,12 @@ void BaseUtils::swap(int *a, int *b) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::normalizeAngle(float angle) { - while (angle > 360) angle -= 360; - while (angle < 0) angle += 360; + while (angle > 360) { + angle -= 360; + } + while (angle < 0) { + angle += 360; + } return angle; } @@ -81,7 +85,9 @@ void BaseUtils::debugMessage(const char *text) { char *BaseUtils::setString(char **string, const char *value) { delete[] *string; *string = new char[strlen(value) + 1]; - if (*string) strcpy(*string, value); + if (*string) { + strcpy(*string, value); + } return *string; } @@ -89,7 +95,9 @@ char *BaseUtils::setString(char **string, const char *value) { int BaseUtils::strNumEntries(const char *str, const char delim) { int numEntries = 1; for (uint32 i = 0; i < strlen(str); i++) { - if (str[i] == delim) numEntries++; + if (str[i] == delim) { + numEntries++; + } } return numEntries; } @@ -104,8 +112,11 @@ char *BaseUtils::strEntry(int entry, const char *str, const char delim) { for (uint32 i = 0; i <= strlen(str); i++) { if (numEntries == entry) { - if (!start) start = str + i; - else len++; + if (!start) { + start = str + i; + } else { + len++; + } } if (str[i] == delim || str[i] == '\0') { numEntries++; @@ -159,35 +170,46 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { return (stringc == 0); case '?': - if (stringc == 0) return false; + if (stringc == 0) { + return false; + } break; case '*': - if (!*pattern) return true; + if (!*pattern) { + return true; + } if (*pattern == '.') { char *dot; - if (pattern[1] == '*' && pattern[2] == 0) return true; + if (pattern[1] == '*' && pattern[2] == 0) { + return true; + } dot = (char *)strchr(string, '.'); - if (pattern[1] == 0) return (dot == NULL || dot[1] == 0); + if (pattern[1] == 0) { + return (dot == NULL || dot[1] == 0); + } if (dot != NULL) { string = dot; - if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) + if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) { return(scumm_stricmp(pattern + 1, string + 1) == 0); + } } } while (*string) - if (BaseUtils::matchesPattern(pattern, string++)) + if (BaseUtils::matchesPattern(pattern, string++)) { return true; + } return false; default: if (patternc != stringc) - if (patternc == '.' && stringc == 0) + if (patternc == '.' && stringc == 0) { return(BaseUtils::matchesPattern(pattern, string)); - else + } else { return false; + } break; } } @@ -222,19 +244,30 @@ void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { } //Chromatic data... else { - if (L < 0.5f) S = delMax / (varMax + varMin); - else S = delMax / (2.0f - varMax - varMin); + if (L < 0.5f) { + S = delMax / (varMax + varMin); + } else { + S = delMax / (2.0f - varMax - varMin); + } float delR = (((varMax - varR) / 6.0f) + (delMax / 2.0f)) / delMax; float delG = (((varMax - varG) / 6.0f) + (delMax / 2.0f)) / delMax; float delB = (((varMax - varB) / 6.0f) + (delMax / 2.0f)) / delMax; - if (varR == varMax) H = delB - delG; - else if (varG == varMax) H = (1.0f / 3.0f) + delR - delB; - else if (varB == varMax) H = (2.0f / 3.0f) + delG - delR; + if (varR == varMax) { + H = delB - delG; + } else if (varG == varMax) { + H = (1.0f / 3.0f) + delR - delB; + } else if (varB == varMax) { + H = (2.0f / 3.0f) + delG - delR; + } - if (H < 0) H += 1; - if (H > 1) H -= 1; + if (H < 0) { + H += 1; + } + if (H > 1) { + H -= 1; + } } *outH = (byte)(H * 255); @@ -259,8 +292,11 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { } else { float var_1, var_2; - if (L < 0.5) var_2 = L * (1.0 + S); - else var_2 = (L + S) - (S * L); + if (L < 0.5) { + var_2 = L * (1.0 + S); + } else { + var_2 = (L + S) - (S * L); + } var_1 = 2.0f * L - var_2; @@ -274,11 +310,21 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::Hue2RGB(float v1, float v2, float vH) { - if (vH < 0.0f) vH += 1.0f; - if (vH > 1.0f) vH -= 1.0f; - if ((6.0f * vH) < 1.0f) return (v1 + (v2 - v1) * 6.0f * vH); - if ((2.0f * vH) < 1.0f) return (v2); - if ((3.0f * vH) < 2.0f) return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + if (vH < 0.0f) { + vH += 1.0f; + } + if (vH > 1.0f) { + vH -= 1.0f; + } + if ((6.0f * vH) < 1.0f) { + return (v1 + (v2 - v1) * 6.0f * vH); + } + if ((2.0f * vH) < 1.0f) { + return (v2); + } + if ((3.0f * vH) < 2.0f) { + return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + } return (v1); } -- cgit v1.2.3 From 2c530bc6edc9ffd95fa86488a663e67d2735041f Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 20:49:59 +0200 Subject: WINTERMUTE: var_name -> varName --- engines/wintermute/utils/utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 39bb1d7137..3336cf63e2 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -290,19 +290,19 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { G = (byte)(L * 255); B = (byte)(L * 255); } else { - float var_1, var_2; + float var1, var2; if (L < 0.5) { - var_2 = L * (1.0 + S); + var2 = L * (1.0 + S); } else { - var_2 = (L + S) - (S * L); + var2 = (L + S) - (S * L); } - var_1 = 2.0f * L - var_2; + var1 = 2.0f * L - var2; - R = (byte)(255 * Hue2RGB(var_1, var_2, H + (1.0f / 3.0f))); - G = (byte)(255 * Hue2RGB(var_1, var_2, H)); - B = (byte)(255 * Hue2RGB(var_1, var_2, H - (1.0f / 3.0f))); + R = (byte)(255 * Hue2RGB(var1, var2, H + (1.0f / 3.0f))); + G = (byte)(255 * Hue2RGB(var1, var2, H)); + B = (byte)(255 * Hue2RGB(var1, var2, H - (1.0f / 3.0f))); } return BYTETORGBA(255, R, G, B); } -- cgit v1.2.3 From 3a49f2bad407787ef65d04c5f9ae423485629b41 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 22:20:55 +0200 Subject: WINTERMUTE: More variable/function renaming VarName->varName --- engines/wintermute/utils/utils.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 3336cf63e2..3050a36263 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -40,9 +40,9 @@ static inline unsigned Sqr(int x) { // Swap - swaps two integers ////////////////////////////////////////////////////////////////////////////////// void BaseUtils::swap(int *a, int *b) { - int Temp = *a; + int temp = *a; *a = *b; - *b = Temp; + *b = temp; } @@ -150,11 +150,11 @@ float BaseUtils::randomFloat(float from, float to) { } ////////////////////////////////////////////////////////////////////////// -float BaseUtils::randomAngle(float From, float To) { - while (To < From) { - To += 360; +float BaseUtils::randomAngle(float from, float to) { + while (to < from) { + to += 360; } - return normalizeAngle(randomFloat(From, To)); + return normalizeAngle(randomFloat(from, to)); } ////////////////////////////////////////////////////////////////////////// @@ -217,10 +217,10 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { ////////////////////////////////////////////////////////////////////////// -void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { - float varR = (RGBCOLGetR(RGBColor) / 255.0f); - float varG = (RGBCOLGetG(RGBColor) / 255.0f); - float varB = (RGBCOLGetB(RGBColor) / 255.0f); +void BaseUtils::RGBtoHSL(uint32 rgbColor, byte *outH, byte *outS, byte *outL) { + float varR = (RGBCOLGetR(rgbColor) / 255.0f); + float varG = (RGBCOLGetG(rgbColor) / 255.0f); + float varB = (RGBCOLGetB(rgbColor) / 255.0f); //Min. value of RGB float varMin = MIN(varR, varG); -- cgit v1.2.3 From fbc19f3f0b4345d5e2db3416ed3de79593bcef36 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 27 Jul 2012 18:24:00 +0200 Subject: WINTERMUTE: Fix a Clang-warning --- engines/wintermute/utils/utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 3050a36263..05aa34f95f 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -204,12 +204,13 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { return false; default: - if (patternc != stringc) + if (patternc != stringc) { if (patternc == '.' && stringc == 0) { return(BaseUtils::matchesPattern(pattern, string)); } else { return false; } + } break; } } -- cgit v1.2.3 From da0ba41903bf50c3a6cb2923ca943386cd984f8c Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 29 Jul 2012 14:56:39 +0200 Subject: WINTERMUTE: Remove more unused utils. --- engines/wintermute/utils/utils.cpp | 72 -------------------------------------- 1 file changed, 72 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 05aa34f95f..6571147a80 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -91,18 +91,6 @@ char *BaseUtils::setString(char **string, const char *value) { return *string; } -////////////////////////////////////////////////////////////////////////// -int BaseUtils::strNumEntries(const char *str, const char delim) { - int numEntries = 1; - for (uint32 i = 0; i < strlen(str); i++) { - if (str[i] == delim) { - numEntries++; - } - } - return numEntries; -} - - ////////////////////////////////////////////////////////////////////////// char *BaseUtils::strEntry(int entry, const char *str, const char delim) { int numEntries = 0; @@ -157,66 +145,6 @@ float BaseUtils::randomAngle(float from, float to) { return normalizeAngle(randomFloat(from, to)); } -////////////////////////////////////////////////////////////////////////// -bool BaseUtils::matchesPattern(const char *pattern, const char *string) { - char stringc, patternc; - - for (;; ++string) { - stringc = toupper(*string); - patternc = toupper(*pattern++); - - switch (patternc) { - case 0: - return (stringc == 0); - - case '?': - if (stringc == 0) { - return false; - } - break; - - case '*': - if (!*pattern) { - return true; - } - - if (*pattern == '.') { - char *dot; - if (pattern[1] == '*' && pattern[2] == 0) { - return true; - } - dot = (char *)strchr(string, '.'); - if (pattern[1] == 0) { - return (dot == NULL || dot[1] == 0); - } - if (dot != NULL) { - string = dot; - if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) { - return(scumm_stricmp(pattern + 1, string + 1) == 0); - } - } - } - - while (*string) - if (BaseUtils::matchesPattern(pattern, string++)) { - return true; - } - return false; - - default: - if (patternc != stringc) { - if (patternc == '.' && stringc == 0) { - return(BaseUtils::matchesPattern(pattern, string)); - } else { - return false; - } - } - break; - } - } -} - - ////////////////////////////////////////////////////////////////////////// void BaseUtils::RGBtoHSL(uint32 rgbColor, byte *outH, byte *outS, byte *outL) { float varR = (RGBCOLGetR(rgbColor) / 255.0f); -- cgit v1.2.3 From e32b79bff1260f8d2853404f750acc22209a323b Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 7 Aug 2012 13:32:26 +0200 Subject: WINTERMUTE: Save the random-seed as well. --- engines/wintermute/utils/utils.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 6571147a80..f8a7b0e547 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -28,6 +28,7 @@ #include "engines/wintermute/utils/utils.h" #include "engines/wintermute/wintermute.h" +#include "engines/wintermute/base/base_engine.h" namespace WinterMute { @@ -126,14 +127,14 @@ int BaseUtils::randomInt(int from, int to) { to = from; from = i; } - return g_wintermute->randInt(from, to); + return BaseEngine::instance().randInt(from, to); // return (rand() % (to - from + 1)) + from; } ////////////////////////////////////////////////////////////////////////// float BaseUtils::randomFloat(float from, float to) { const uint32 randMax = RAND_MAX; - float randNum = (float)g_wintermute->randInt(0, randMax) / (float)randMax; + float randNum = (float)BaseEngine::instance().randInt(0, randMax) / (float)randMax; return from + (to - from) * randNum; } -- cgit v1.2.3 From c422ae9d8a90aeb63da3e3fdf521323fe6769828 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 11 Aug 2012 02:30:07 +0200 Subject: WINTERMUTE: Get rid of strncpy+manual termination. --- engines/wintermute/utils/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index f8a7b0e547..4546750c61 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -112,7 +112,7 @@ char *BaseUtils::strEntry(int entry, const char *str, const char delim) { if (start) { char *ret = new char[len + 1]; memset(ret, 0, len + 1); - strncpy(ret, start, len); + Common::strlcpy(ret, start, len + 1); return ret; } } -- cgit v1.2.3 From fed19cb66ae5b56dd7dc81b90edd5a0d15986678 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 13 Aug 2012 03:42:30 +0200 Subject: WINTERMUTE: WinterMute -> Wintermute --- engines/wintermute/utils/utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 4546750c61..f26d60b7cf 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -30,7 +30,7 @@ #include "engines/wintermute/wintermute.h" #include "engines/wintermute/base/base_engine.h" -namespace WinterMute { +namespace Wintermute { ////////////////////////////////////////////////////////////////////// static inline unsigned Sqr(int x) { @@ -258,4 +258,4 @@ float BaseUtils::Hue2RGB(float v1, float v2, float vH) { return (v1); } -} // end of namespace WinterMute +} // end of namespace Wintermute -- cgit v1.2.3 From b4090ead4d4334e08725323ff72fd355c93b63d5 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 4 Sep 2012 22:17:23 +0200 Subject: WINTERMUTE: Convert CRLF to LF --- engines/wintermute/utils/utils.cpp | 522 ++++++++++++++++++------------------- 1 file changed, 261 insertions(+), 261 deletions(-) (limited to 'engines/wintermute/utils/utils.cpp') diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index f26d60b7cf..824b16ccdb 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -1,261 +1,261 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -/* - * This file is based on WME Lite. - * http://dead-code.org/redir.php?target=wmelite - * Copyright (c) 2011 Jan Nedoma - */ - -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/wintermute.h" -#include "engines/wintermute/base/base_engine.h" - -namespace Wintermute { - -////////////////////////////////////////////////////////////////////// -static inline unsigned Sqr(int x) { - return (x * x); -} - -////////////////////////////////////////////////////////////////////////////////// -// Swap - swaps two integers -////////////////////////////////////////////////////////////////////////////////// -void BaseUtils::swap(int *a, int *b) { - int temp = *a; - *a = *b; - *b = temp; -} - - -////////////////////////////////////////////////////////////////////////// -float BaseUtils::normalizeAngle(float angle) { - while (angle > 360) { - angle -= 360; - } - while (angle < 0) { - angle += 360; - } - - return angle; -} - - -//////////////////////////////////////////////////////////////////////////////// -void BaseUtils::createPath(const char *path, bool pathOnly) { - /* AnsiString pathStr; - - if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); - else pathStr = path; - */ -// try { - warning("BaseUtils::CreatePath - not implemented: %s", path); -// boost::filesystem::create_directories(path); -// } catch (...) { - return; -// } -} - - -////////////////////////////////////////////////////////////////////////// -void BaseUtils::debugMessage(const char *text) { - //MessageBox(hWnd, Text, "WME", MB_OK|MB_ICONINFORMATION); -} - - -////////////////////////////////////////////////////////////////////////// -char *BaseUtils::setString(char **string, const char *value) { - delete[] *string; - *string = new char[strlen(value) + 1]; - if (*string) { - strcpy(*string, value); - } - return *string; -} - -////////////////////////////////////////////////////////////////////////// -char *BaseUtils::strEntry(int entry, const char *str, const char delim) { - int numEntries = 0; - - const char *start = NULL; - int len = 0; - - for (uint32 i = 0; i <= strlen(str); i++) { - if (numEntries == entry) { - if (!start) { - start = str + i; - } else { - len++; - } - } - if (str[i] == delim || str[i] == '\0') { - numEntries++; - if (start) { - char *ret = new char[len + 1]; - memset(ret, 0, len + 1); - Common::strlcpy(ret, start, len + 1); - return ret; - } - } - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -int BaseUtils::randomInt(int from, int to) { - if (to < from) { - int i = to; - to = from; - from = i; - } - return BaseEngine::instance().randInt(from, to); -// return (rand() % (to - from + 1)) + from; -} - -////////////////////////////////////////////////////////////////////////// -float BaseUtils::randomFloat(float from, float to) { - const uint32 randMax = RAND_MAX; - float randNum = (float)BaseEngine::instance().randInt(0, randMax) / (float)randMax; - return from + (to - from) * randNum; -} - -////////////////////////////////////////////////////////////////////////// -float BaseUtils::randomAngle(float from, float to) { - while (to < from) { - to += 360; - } - return normalizeAngle(randomFloat(from, to)); -} - -////////////////////////////////////////////////////////////////////////// -void BaseUtils::RGBtoHSL(uint32 rgbColor, byte *outH, byte *outS, byte *outL) { - float varR = (RGBCOLGetR(rgbColor) / 255.0f); - float varG = (RGBCOLGetG(rgbColor) / 255.0f); - float varB = (RGBCOLGetB(rgbColor) / 255.0f); - - //Min. value of RGB - float varMin = MIN(varR, varG); - varMin = MIN(varMin, varB); - - //Max. value of RGB - float varMax = MAX(varR, varG); - varMax = MAX(varMax, varB); - - //Delta RGB value - float delMax = varMax - varMin; - - float H = 0.0f, S = 0.0f, L = 0.0f; - - L = (varMax + varMin) / 2.0f; - - //This is a gray, no chroma... - if (delMax == 0) { - H = 0; - S = 0; - } - //Chromatic data... - else { - if (L < 0.5f) { - S = delMax / (varMax + varMin); - } else { - S = delMax / (2.0f - varMax - varMin); - } - - float delR = (((varMax - varR) / 6.0f) + (delMax / 2.0f)) / delMax; - float delG = (((varMax - varG) / 6.0f) + (delMax / 2.0f)) / delMax; - float delB = (((varMax - varB) / 6.0f) + (delMax / 2.0f)) / delMax; - - if (varR == varMax) { - H = delB - delG; - } else if (varG == varMax) { - H = (1.0f / 3.0f) + delR - delB; - } else if (varB == varMax) { - H = (2.0f / 3.0f) + delG - delR; - } - - if (H < 0) { - H += 1; - } - if (H > 1) { - H -= 1; - } - } - - *outH = (byte)(H * 255); - *outS = (byte)(S * 255); - *outL = (byte)(L * 255); -} - - -////////////////////////////////////////////////////////////////////////// -uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { - float H = InH / 255.0f; - float S = InS / 255.0f; - float L = InL / 255.0f; - - byte R, G, B; - - - if (S == 0) { - R = (byte)(L * 255); - G = (byte)(L * 255); - B = (byte)(L * 255); - } else { - float var1, var2; - - if (L < 0.5) { - var2 = L * (1.0 + S); - } else { - var2 = (L + S) - (S * L); - } - - var1 = 2.0f * L - var2; - - R = (byte)(255 * Hue2RGB(var1, var2, H + (1.0f / 3.0f))); - G = (byte)(255 * Hue2RGB(var1, var2, H)); - B = (byte)(255 * Hue2RGB(var1, var2, H - (1.0f / 3.0f))); - } - return BYTETORGBA(255, R, G, B); -} - - -////////////////////////////////////////////////////////////////////////// -float BaseUtils::Hue2RGB(float v1, float v2, float vH) { - if (vH < 0.0f) { - vH += 1.0f; - } - if (vH > 1.0f) { - vH -= 1.0f; - } - if ((6.0f * vH) < 1.0f) { - return (v1 + (v2 - v1) * 6.0f * vH); - } - if ((2.0f * vH) < 1.0f) { - return (v2); - } - if ((3.0f * vH) < 2.0f) { - return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); - } - return (v1); -} - -} // end of namespace Wintermute +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/wintermute.h" +#include "engines/wintermute/base/base_engine.h" + +namespace Wintermute { + +////////////////////////////////////////////////////////////////////// +static inline unsigned Sqr(int x) { + return (x * x); +} + +////////////////////////////////////////////////////////////////////////////////// +// Swap - swaps two integers +////////////////////////////////////////////////////////////////////////////////// +void BaseUtils::swap(int *a, int *b) { + int temp = *a; + *a = *b; + *b = temp; +} + + +////////////////////////////////////////////////////////////////////////// +float BaseUtils::normalizeAngle(float angle) { + while (angle > 360) { + angle -= 360; + } + while (angle < 0) { + angle += 360; + } + + return angle; +} + + +//////////////////////////////////////////////////////////////////////////////// +void BaseUtils::createPath(const char *path, bool pathOnly) { + /* AnsiString pathStr; + + if (!pathOnly) pathStr = PathUtil::getDirectoryName(path); + else pathStr = path; + */ +// try { + warning("BaseUtils::CreatePath - not implemented: %s", path); +// boost::filesystem::create_directories(path); +// } catch (...) { + return; +// } +} + + +////////////////////////////////////////////////////////////////////////// +void BaseUtils::debugMessage(const char *text) { + //MessageBox(hWnd, Text, "WME", MB_OK|MB_ICONINFORMATION); +} + + +////////////////////////////////////////////////////////////////////////// +char *BaseUtils::setString(char **string, const char *value) { + delete[] *string; + *string = new char[strlen(value) + 1]; + if (*string) { + strcpy(*string, value); + } + return *string; +} + +////////////////////////////////////////////////////////////////////////// +char *BaseUtils::strEntry(int entry, const char *str, const char delim) { + int numEntries = 0; + + const char *start = NULL; + int len = 0; + + for (uint32 i = 0; i <= strlen(str); i++) { + if (numEntries == entry) { + if (!start) { + start = str + i; + } else { + len++; + } + } + if (str[i] == delim || str[i] == '\0') { + numEntries++; + if (start) { + char *ret = new char[len + 1]; + memset(ret, 0, len + 1); + Common::strlcpy(ret, start, len + 1); + return ret; + } + } + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +int BaseUtils::randomInt(int from, int to) { + if (to < from) { + int i = to; + to = from; + from = i; + } + return BaseEngine::instance().randInt(from, to); +// return (rand() % (to - from + 1)) + from; +} + +////////////////////////////////////////////////////////////////////////// +float BaseUtils::randomFloat(float from, float to) { + const uint32 randMax = RAND_MAX; + float randNum = (float)BaseEngine::instance().randInt(0, randMax) / (float)randMax; + return from + (to - from) * randNum; +} + +////////////////////////////////////////////////////////////////////////// +float BaseUtils::randomAngle(float from, float to) { + while (to < from) { + to += 360; + } + return normalizeAngle(randomFloat(from, to)); +} + +////////////////////////////////////////////////////////////////////////// +void BaseUtils::RGBtoHSL(uint32 rgbColor, byte *outH, byte *outS, byte *outL) { + float varR = (RGBCOLGetR(rgbColor) / 255.0f); + float varG = (RGBCOLGetG(rgbColor) / 255.0f); + float varB = (RGBCOLGetB(rgbColor) / 255.0f); + + //Min. value of RGB + float varMin = MIN(varR, varG); + varMin = MIN(varMin, varB); + + //Max. value of RGB + float varMax = MAX(varR, varG); + varMax = MAX(varMax, varB); + + //Delta RGB value + float delMax = varMax - varMin; + + float H = 0.0f, S = 0.0f, L = 0.0f; + + L = (varMax + varMin) / 2.0f; + + //This is a gray, no chroma... + if (delMax == 0) { + H = 0; + S = 0; + } + //Chromatic data... + else { + if (L < 0.5f) { + S = delMax / (varMax + varMin); + } else { + S = delMax / (2.0f - varMax - varMin); + } + + float delR = (((varMax - varR) / 6.0f) + (delMax / 2.0f)) / delMax; + float delG = (((varMax - varG) / 6.0f) + (delMax / 2.0f)) / delMax; + float delB = (((varMax - varB) / 6.0f) + (delMax / 2.0f)) / delMax; + + if (varR == varMax) { + H = delB - delG; + } else if (varG == varMax) { + H = (1.0f / 3.0f) + delR - delB; + } else if (varB == varMax) { + H = (2.0f / 3.0f) + delG - delR; + } + + if (H < 0) { + H += 1; + } + if (H > 1) { + H -= 1; + } + } + + *outH = (byte)(H * 255); + *outS = (byte)(S * 255); + *outL = (byte)(L * 255); +} + + +////////////////////////////////////////////////////////////////////////// +uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { + float H = InH / 255.0f; + float S = InS / 255.0f; + float L = InL / 255.0f; + + byte R, G, B; + + + if (S == 0) { + R = (byte)(L * 255); + G = (byte)(L * 255); + B = (byte)(L * 255); + } else { + float var1, var2; + + if (L < 0.5) { + var2 = L * (1.0 + S); + } else { + var2 = (L + S) - (S * L); + } + + var1 = 2.0f * L - var2; + + R = (byte)(255 * Hue2RGB(var1, var2, H + (1.0f / 3.0f))); + G = (byte)(255 * Hue2RGB(var1, var2, H)); + B = (byte)(255 * Hue2RGB(var1, var2, H - (1.0f / 3.0f))); + } + return BYTETORGBA(255, R, G, B); +} + + +////////////////////////////////////////////////////////////////////////// +float BaseUtils::Hue2RGB(float v1, float v2, float vH) { + if (vH < 0.0f) { + vH += 1.0f; + } + if (vH > 1.0f) { + vH -= 1.0f; + } + if ((6.0f * vH) < 1.0f) { + return (v1 + (v2 - v1) * 6.0f * vH); + } + if ((2.0f * vH) < 1.0f) { + return (v2); + } + if ((3.0f * vH) < 2.0f) { + return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + } + return (v1); +} + +} // end of namespace Wintermute -- cgit v1.2.3