summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorerorcun <erayorcunus@gmail.com>2019-11-09 16:06:20 +0100
committerGitHub <noreply@github.com>2019-11-09 16:06:20 +0100
commit0df15bb73dbdf352f92bc522c7b5c102f1e33ba5 (patch)
tree73c9bf00f83b91d7862f28296640860fa16291ab /src/core
parentFix link to config.h in readme (diff)
parentImplemented faststrcmp, faststricmp, strcasecmp (diff)
downloadre3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.tar
re3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.tar.gz
re3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.tar.bz2
re3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.tar.lz
re3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.tar.xz
re3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.tar.zst
re3-0df15bb73dbdf352f92bc522c7b5c102f1e33ba5.zip
Diffstat (limited to '')
-rw-r--r--src/core/CutsceneMgr.cpp15
-rw-r--r--src/core/Directory.cpp3
-rw-r--r--src/core/General.h23
-rw-r--r--src/core/PlayerSkin.cpp4
-rw-r--r--src/core/Streaming.cpp27
-rw-r--r--src/core/TxdStore.cpp3
-rw-r--r--src/core/common.h4
7 files changed, 55 insertions, 24 deletions
diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp
index fa322242..2fbc5186 100644
--- a/src/core/CutsceneMgr.cpp
+++ b/src/core/CutsceneMgr.cpp
@@ -1,5 +1,6 @@
#include "common.h"
#include "patcher.h"
+#include "General.h"
#include "CutsceneMgr.h"
#include "Directory.h"
#include "Camera.h"
@@ -107,7 +108,7 @@ int
FindCutsceneAudioTrackId(const char *szCutsceneName)
{
for (int i = 0; musicNameIdAssoc[i].szTrackName; i++) {
- if (!strcmpi(musicNameIdAssoc[i].szTrackName, szCutsceneName))
+ if (!CGeneral::faststricmp(musicNameIdAssoc[i].szTrackName, szCutsceneName))
return musicNameIdAssoc[i].iTrackId;
}
return -1;
@@ -171,7 +172,7 @@ CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName)
CPlayerPed *pPlayerPed;
ms_cutsceneProcessing = true;
- if (!strcmpi(szCutsceneName, "jb"))
+ if (!strcasecmp(szCutsceneName, "jb"))
ms_useLodMultiplier = true;
CTimer::Stop();
@@ -207,7 +208,7 @@ CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName)
CFileMgr::CloseFile(file);
- if (strcmpi(ms_cutsceneName, "end")) {
+ if (CGeneral::faststricmp(ms_cutsceneName, "end")) {
DMAudio.ChangeMusicMode(MUSICMODE_CUTSCENE);
int trackId = FindCutsceneAudioTrackId(szCutsceneName);
if (trackId != -1) {
@@ -364,9 +365,9 @@ CCutsceneMgr::DeleteCutsceneData(void)
CPad::GetPad(0)->DisablePlayerControls &= ~PLAYERCONTROL_DISABLED_80;
CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false);
- if (strcmpi(ms_cutsceneName, "end")) {
+ if (CGeneral::faststricmp(ms_cutsceneName, "end")) {
DMAudio.StopCutSceneMusic();
- if (strcmpi(ms_cutsceneName, "bet"))
+ if (CGeneral::faststricmp(ms_cutsceneName, "bet"))
DMAudio.ChangeMusicMode(MUSICMODE_GAME);
}
CTimer::Stop();
@@ -389,7 +390,7 @@ CCutsceneMgr::Update(void)
switch (ms_cutsceneLoadStatus) {
case CUTSCENE_LOADING_AUDIO:
SetupCutsceneToStart();
- if (strcmpi(ms_cutsceneName, "end"))
+ if (CGeneral::faststricmp(ms_cutsceneName, "end"))
DMAudio.PlayPreloadedCutSceneMusic();
ms_cutsceneLoadStatus++;
break;
@@ -407,7 +408,7 @@ CCutsceneMgr::Update(void)
if (!ms_running) return;
ms_cutsceneTimer += CTimer::GetTimeStepNonClipped() * 0.02f;
- if (strcmpi(ms_cutsceneName, "end") && TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FLYBY && ms_cutsceneLoadStatus == CUTSCENE_LOADING_0) {
+ if (CGeneral::faststricmp(ms_cutsceneName, "end") && TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FLYBY && ms_cutsceneLoadStatus == CUTSCENE_LOADING_0) {
if (CPad::GetPad(0)->GetCrossJustDown()
|| (CGame::playingIntro && CPad::GetPad(0)->GetStartJustDown())
|| CPad::GetPad(0)->GetLeftMouseJustDown()
diff --git a/src/core/Directory.cpp b/src/core/Directory.cpp
index 3e0d5382..d4b4279d 100644
--- a/src/core/Directory.cpp
+++ b/src/core/Directory.cpp
@@ -1,5 +1,6 @@
#include "common.h"
#include "patcher.h"
+#include "General.h"
#include "FileMgr.h"
#include "Directory.h"
@@ -49,7 +50,7 @@ CDirectory::FindItem(const char *name, uint32 &offset, uint32 &size)
int i;
for(i = 0; i < numEntries; i++)
- if(strcmpi(entries[i].name, name) == 0){
+ if(!CGeneral::faststricmp(entries[i].name, name)){
offset = entries[i].offset;
size = entries[i].size;
return true;
diff --git a/src/core/General.h b/src/core/General.h
index d73cf36f..a7b240c2 100644
--- a/src/core/General.h
+++ b/src/core/General.h
@@ -104,6 +104,29 @@ public:
return (int)floorf(angle / DEGTORAD(45.0f));
}
+ // Unlike usual string comparison functions, these don't care about greater or lesser
+ static bool faststrcmp(const char *str1, const char *str2)
+ {
+ for (; *str1; str1++, str2++) {
+ if (*str1 != *str2)
+ return true;
+ }
+ return *str2 != '\0';
+ }
+
+ static bool faststricmp(const char *str1, const char *str2)
+ {
+ for (; *str1; str1++, str2++) {
+#if MUCH_SLOWER
+ if (toupper(*str1) != toupper(*str2))
+#else
+ if (__ascii_toupper(*str1) != __ascii_toupper(*str2))
+#endif
+ return true;
+ }
+ return *str2 != '\0';
+ }
+
// not too sure about all these...
static uint16 GetRandomNumber(void)
{ return myrand() & MYRAND_MAX; }
diff --git a/src/core/PlayerSkin.cpp b/src/core/PlayerSkin.cpp
index 82427491..4d2c31df 100644
--- a/src/core/PlayerSkin.cpp
+++ b/src/core/PlayerSkin.cpp
@@ -28,7 +28,7 @@ FindPlayerDff(uint32 &offset, uint32 &size)
do {
if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo)))
return;
- } while (strcmpi("player.dff", info.name));
+ } while (strcasecmp("player.dff", info.name) != 0);
offset = info.offset;
size = info.size;
@@ -94,7 +94,7 @@ CPlayerSkin::GetSkinTexture(const char *texName)
CTxdStore::PopCurrentTxd();
if (tex) return tex;
- if (!strcmp(DEFAULT_SKIN_NAME, texName))
+ if (strcmp(DEFAULT_SKIN_NAME, texName) == 0)
sprintf(gString, "models\\generic\\player.bmp");
else
sprintf(gString, "skins\\%s.bmp", texName);
diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp
index 69e14869..b0933063 100644
--- a/src/core/Streaming.cpp
+++ b/src/core/Streaming.cpp
@@ -1,5 +1,6 @@
#include "common.h"
#include "patcher.h"
+#include "General.h"
#include "Pad.h"
#include "Hud.h"
#include "Text.h"
@@ -347,7 +348,7 @@ CStreaming::LoadCdDirectory(const char *dirname, int n)
if(direntry.size > (uint32)ms_streamingBufferSize)
ms_streamingBufferSize = direntry.size;
- if(strcmp(dot+1, "DFF") == 0 || strcmp(dot+1, "dff") == 0){
+ if(!CGeneral::faststrcmp(dot+1, "DFF") || !CGeneral::faststrcmp(dot+1, "dff")){
if(CModelInfo::GetModelInfo(direntry.name, &modelId)){
if(ms_aInfoForModel[modelId].GetCdPosnAndSize(posn, size)){
debug("%s appears more than once in %s\n", direntry.name, dirname);
@@ -364,20 +365,20 @@ CStreaming::LoadCdDirectory(const char *dirname, int n)
ms_pExtraObjectsDir->AddItem(direntry);
lastID = -1;
}
- }else if(strcmp(dot+1, "TXD") == 0 || strcmp(dot+1, "txd") == 0){
+ }else if(!CGeneral::faststrcmp(dot+1, "TXD") || !CGeneral::faststrcmp(dot+1, "txd")){
txdId = CTxdStore::FindTxdSlot(direntry.name);
if(txdId == -1)
txdId = CTxdStore::AddTxdSlot(direntry.name);
- if(ms_aInfoForModel[txdId + STREAM_OFFSET_TXD].GetCdPosnAndSize(posn, size)){
- debug("%s appears more than once in %s\n", direntry.name, dirname);
- lastID = -1;
- }else{
- direntry.offset |= imgSelector;
- ms_aInfoForModel[txdId + STREAM_OFFSET_TXD].SetCdPosnAndSize(direntry.offset, direntry.size);
- if(lastID != -1)
- ms_aInfoForModel[lastID].m_nextID = txdId + STREAM_OFFSET_TXD;
- lastID = txdId + STREAM_OFFSET_TXD;
- }
+ if(ms_aInfoForModel[txdId + STREAM_OFFSET_TXD].GetCdPosnAndSize(posn, size)){
+ debug("%s appears more than once in %s\n", direntry.name, dirname);
+ lastID = -1;
+ }else{
+ direntry.offset |= imgSelector;
+ ms_aInfoForModel[txdId + STREAM_OFFSET_TXD].SetCdPosnAndSize(direntry.offset, direntry.size);
+ if(lastID != -1)
+ ms_aInfoForModel[lastID].m_nextID = txdId + STREAM_OFFSET_TXD;
+ lastID = txdId + STREAM_OFFSET_TXD;
+ }
}else
lastID = -1;
}
@@ -720,7 +721,7 @@ CStreaming::RequestSpecialModel(int32 modelId, const char *modelName, int32 flag
uint32 pos, size;
mi = CModelInfo::GetModelInfo(modelId);
- if(strcmp(mi->GetName(), modelName) == 0){
+ if(!CGeneral::faststrcmp(mi->GetName(), modelName)){
// Already have the correct name, just request it
RequestModel(modelId, flags);
return;
diff --git a/src/core/TxdStore.cpp b/src/core/TxdStore.cpp
index 5085c7e4..ab970b99 100644
--- a/src/core/TxdStore.cpp
+++ b/src/core/TxdStore.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include "patcher.h"
#include "templates.h"
+#include "General.h"
#include "Streaming.h"
#include "RwHelper.h"
#include "TxdStore.h"
@@ -61,7 +62,7 @@ CTxdStore::FindTxdSlot(const char *name)
int size = ms_pTxdPool->GetSize();
for(int i = 0; i < size; i++){
defname = GetTxdName(i);
- if(defname && _strcmpi(defname, name) == 0)
+ if(defname && !CGeneral::faststricmp(defname, name))
return i;
}
return -1;
diff --git a/src/core/common.h b/src/core/common.h
index fd5f35b0..cadcac1d 100644
--- a/src/core/common.h
+++ b/src/core/common.h
@@ -153,6 +153,10 @@ public:
#endif
};
+#if (defined(_MSC_VER))
+extern int strcasecmp(const char *str1, const char *str2);
+#endif
+
#define clamp(v, low, high) ((v)<(low) ? (low) : (v)>(high) ? (high) : (v))
inline float sq(float x) { return x*x; }