Merge remote-tracking branch 'trombonecot/comparestring'

This commit is contained in:
Marc Zinnschlag 2012-12-30 20:11:18 +01:00
commit 8b2785400b
8 changed files with 28 additions and 85 deletions

View file

@ -42,35 +42,11 @@
namespace namespace
{ {
std::string toLower (const std::string& name)
{
std::string lowerCase;
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
(int(*)(int)) std::tolower);
return lowerCase;
}
bool stringCompareNoCase (std::string first, std::string second)
{
unsigned int i=0;
while ( (i<first.length()) && (i<second.length()) )
{
if (tolower(first[i])<tolower(second[i])) return true;
else if (tolower(first[i])>tolower(second[i])) return false;
++i;
}
if (first.length()<second.length())
return true;
else
return false;
}
//helper function //helper function
std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos)
{ {
return toLower(str).find(toLower(substr),pos); return Misc::StringUtils::toLower(const_cast<std::string &>(str)).find(Misc::StringUtils::toLower(const_cast<std::string &>(substr)).c_str(),pos);
} }
} }
@ -94,13 +70,13 @@ namespace MWDialogue
MWWorld::Store<ESM::Dialogue>::iterator it = dialogs.begin(); MWWorld::Store<ESM::Dialogue>::iterator it = dialogs.begin();
for (; it != dialogs.end(); ++it) for (; it != dialogs.end(); ++it)
{ {
mDialogueMap[toLower(it->mId)] = *it; mDialogueMap[Misc::StringUtils::toLower(const_cast<std::string &>(it->mId))] = *it;
} }
} }
void DialogueManager::addTopic (const std::string& topic) void DialogueManager::addTopic (const std::string& topic)
{ {
mKnownTopics[toLower(topic)] = true; mKnownTopics[Misc::StringUtils::toLower(const_cast<std::string &>(topic))] = true;
} }
void DialogueManager::parseText (const std::string& text) void DialogueManager::parseText (const std::string& text)
@ -298,10 +274,10 @@ namespace MWDialogue
{ {
if (filter.search (*iter)) if (filter.search (*iter))
{ {
mActorKnownTopics.push_back (toLower (iter->mId)); mActorKnownTopics.push_back ( Misc::StringUtils::toLower(const_cast<std::string &>(iter->mId)));
//does the player know the topic? //does the player know the topic?
if (mKnownTopics.find (toLower (iter->mId)) != mKnownTopics.end()) if (mKnownTopics.find ( Misc::StringUtils::toLower(const_cast<std::string &>(iter->mId))) != mKnownTopics.end())
{ {
keywordList.push_back (iter->mId); keywordList.push_back (iter->mId);
} }
@ -359,7 +335,7 @@ namespace MWDialogue
win->setServices (windowServices); win->setServices (windowServices);
// sort again, because the previous sort was case-sensitive // sort again, because the previous sort was case-sensitive
keywordList.sort(stringCompareNoCase); keywordList.sort(Misc::StringUtils::ciEqual);
win->setKeywords(keywordList); win->setKeywords(keywordList);
mChoice = choice; mChoice = choice;
@ -439,7 +415,7 @@ namespace MWDialogue
{ {
MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow(); MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow();
win->askQuestion(question); win->askQuestion(question);
mChoiceMap[toLower(question)] = choice; mChoiceMap[Misc::StringUtils::toLower(const_cast<std::string &>(question))] = choice;
mIsInChoice = true; mIsInChoice = true;
} }

View file

@ -71,6 +71,7 @@ namespace MWDialogue
virtual void persuade (int type); virtual void persuade (int type);
virtual int getTemporaryDispositionChange () const; virtual int getTemporaryDispositionChange () const;
virtual void applyTemporaryDispositionChange (int delta); virtual void applyTemporaryDispositionChange (int delta);
void toLower(std::string question);
}; };
} }

View file

@ -24,19 +24,6 @@
#include "scrollwindow.hpp" #include "scrollwindow.hpp"
#include "spellwindow.hpp" #include "spellwindow.hpp"
namespace
{
std::string toLower (const std::string& name)
{
std::string lowerCase;
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
(int(*)(int)) std::tolower);
return lowerCase;
}
}
namespace MWGui namespace MWGui
{ {
@ -284,7 +271,7 @@ namespace MWGui
for (MWWorld::ContainerStoreIterator it = invStore.begin(); for (MWWorld::ContainerStoreIterator it = invStore.begin();
it != invStore.end(); ++it) it != invStore.end(); ++it)
{ {
if (toLower(it->getCellRef().mRefID) == "gold_001") if (Misc::StringUtils::toLower(it->getCellRef().mRefID) == "gold_001")
return it->getRefData().getCount(); return it->getRefData().getCount();
} }
return 0; return 0;

View file

@ -25,19 +25,6 @@
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp" #include "ref.hpp"
namespace
{
std::string toLower (const std::string& name)
{
std::string lowerCase;
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
(int(*)(int)) std::tolower);
return lowerCase;
}
}
namespace MWScript namespace MWScript
{ {
namespace Container namespace Container
@ -85,7 +72,7 @@ namespace MWScript
Interpreter::Type_Integer sum = 0; Interpreter::Type_Integer sum = 0;
for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter) for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end(); ++iter)
if (toLower(iter->getCellRef().mRefID) == toLower(item)) if (Misc::StringUtils::toLower(iter->getCellRef().mRefID) == Misc::StringUtils::toLower(item))
sum += iter->getRefData().getCount(); sum += iter->getRefData().getCount();
runtime.push (sum); runtime.push (sum);
@ -118,7 +105,7 @@ namespace MWScript
for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end() && count; for (MWWorld::ContainerStoreIterator iter (store.begin()); iter!=store.end() && count;
++iter) ++iter)
{ {
if (toLower(iter->getCellRef().mRefID) == toLower(item)) if (Misc::StringUtils::toLower(iter->getCellRef().mRefID) == Misc::StringUtils::toLower(item))
{ {
itemName = MWWorld::Class::get(*iter).getName(*iter); itemName = MWWorld::Class::get(*iter).getName(*iter);
@ -176,7 +163,7 @@ namespace MWScript
MWWorld::ContainerStoreIterator it = invStore.begin(); MWWorld::ContainerStoreIterator it = invStore.begin();
for (; it != invStore.end(); ++it) for (; it != invStore.end(); ++it)
{ {
if (toLower(it->getCellRef().mRefID) == toLower(item)) if (Misc::StringUtils::toLower(it->getCellRef().mRefID) == Misc::StringUtils::toLower(item))
break; break;
} }
if (it == invStore.end()) if (it == invStore.end())
@ -276,7 +263,7 @@ namespace MWScript
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
{ {
MWWorld::ContainerStoreIterator it = invStore.getSlot (slot); MWWorld::ContainerStoreIterator it = invStore.getSlot (slot);
if (it != invStore.end() && toLower(it->getCellRef().mRefID) == toLower(item)) if (it != invStore.end() && Misc::StringUtils::toLower(it->getCellRef().mRefID) == Misc::StringUtils::toLower(item))
{ {
runtime.push(1); runtime.push(1);
return; return;
@ -294,8 +281,9 @@ namespace MWScript
virtual void execute(Interpreter::Runtime &runtime) virtual void execute(Interpreter::Runtime &runtime)
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string creatureName = toLower (runtime.getStringLiteral (runtime[0].mInteger)); const std::string &name = runtime.getStringLiteral (runtime[0].mInteger);
std::string creatureName = Misc::StringUtils::toLower (const_cast<std::string &>(name));
runtime.pop(); runtime.pop();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr); MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore (ptr);
@ -303,7 +291,7 @@ namespace MWScript
it != invStore.end(); ++it) it != invStore.end(); ++it)
{ {
if (toLower(it->getCellRef().mSoul) == toLower(creatureName)) if (Misc::StringUtils::toLower(it->getCellRef().mSoul) == Misc::StringUtils::toLower(creatureName))
{ {
runtime.push(1); runtime.push(1);
return; return;

View file

@ -607,16 +607,6 @@ namespace MWWorld
} }
} }
std::string toLower (const std::string& name)
{
std::string lowerCase;
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
(int(*)(int)) std::tolower);
return lowerCase;
}
void World::moveObject(const Ptr &ptr, CellStore &newCell, float x, float y, float z) void World::moveObject(const Ptr &ptr, CellStore &newCell, float x, float y, float z)
{ {
ESM::Position &pos = ptr.getRefData().getPosition(); ESM::Position &pos = ptr.getRefData().getPosition();
@ -631,7 +621,7 @@ namespace MWWorld
{ {
if (isPlayer) if (isPlayer)
if (!newCell.isExterior()) if (!newCell.isExterior())
changeToInteriorCell(toLower(newCell.mCell->mName), pos); changeToInteriorCell(Misc::StringUtils::toLower(const_cast<std::string &> (newCell.mCell->mName)), pos);
else else
{ {
int cellX = newCell.mCell->getGridX(); int cellX = newCell.mCell->getGridX();

View file

@ -1,8 +1,14 @@
#include "stringops.hpp" #include "stringops.hpp"
#include <cctype>
#include <algorithm>
#include <iterator>
#include <string.h> #include <string.h>
#include <libs/platform/strings.h> #include <libs/platform/strings.h>
namespace Misc namespace Misc
{ {

View file

@ -70,6 +70,3 @@ endif()
link_directories(${CMAKE_CURRENT_BINARY_DIR}) link_directories(${CMAKE_CURRENT_BINARY_DIR})
set(SHINY_LIBRARY ${SHINY_LIBRARY} PARENT_SCOPE)
set(SHINY_OGREPLATFORM_LIBRARY ${SHINY_OGREPLATFORM_LIBRARY} PARENT_SCOPE)

View file

@ -72,8 +72,6 @@ namespace sh
allowFixedFunction = retrieveValue<BooleanValue>(getProperty("allow_fixed_function"), NULL).get(); allowFixedFunction = retrieveValue<BooleanValue>(getProperty("allow_fixed_function"), NULL).get();
} }
bool useShaders = mShadersEnabled || !allowFixedFunction;
// get passes of the top-most parent // get passes of the top-most parent
PassVector passes = getPasses(); PassVector passes = getPasses();
if (passes.size() == 0) if (passes.size() == 0)
@ -93,7 +91,7 @@ namespace sh
// create or retrieve shaders // create or retrieve shaders
bool hasVertex = it->hasProperty("vertex_program"); bool hasVertex = it->hasProperty("vertex_program");
bool hasFragment = it->hasProperty("fragment_program"); bool hasFragment = it->hasProperty("fragment_program");
if (useShaders) if (mShadersEnabled || !allowFixedFunction)
{ {
it->setContext(context); it->setContext(context);
it->mShaderProperties.setContext(context); it->mShaderProperties.setContext(context);
@ -146,7 +144,7 @@ namespace sh
bool foundVertex = std::find(usedTextureSamplersVertex.begin(), usedTextureSamplersVertex.end(), texIt->getName()) != usedTextureSamplersVertex.end(); bool foundVertex = std::find(usedTextureSamplersVertex.begin(), usedTextureSamplersVertex.end(), texIt->getName()) != usedTextureSamplersVertex.end();
bool foundFragment = std::find(usedTextureSamplersFragment.begin(), usedTextureSamplersFragment.end(), texIt->getName()) != usedTextureSamplersFragment.end(); bool foundFragment = std::find(usedTextureSamplersFragment.begin(), usedTextureSamplersFragment.end(), texIt->getName()) != usedTextureSamplersFragment.end();
if ( (foundVertex || foundFragment) if ( (foundVertex || foundFragment)
|| (((!useShaders || (!hasVertex || !hasFragment)) && allowFixedFunction) && texIt->hasProperty("create_in_ffp") && retrieveValue<BooleanValue>(texIt->getProperty("create_in_ffp"), this).get())) || (((!mShadersEnabled || (!hasVertex || !hasFragment)) && allowFixedFunction) && texIt->hasProperty("create_in_ffp") && retrieveValue<BooleanValue>(texIt->getProperty("create_in_ffp"), this).get()))
{ {
boost::shared_ptr<TextureUnitState> texUnit = pass->createTextureUnitState (); boost::shared_ptr<TextureUnitState> texUnit = pass->createTextureUnitState ();
texIt->copyAll (texUnit.get(), context); texIt->copyAll (texUnit.get(), context);
@ -154,7 +152,7 @@ namespace sh
mTexUnits.push_back(texUnit); mTexUnits.push_back(texUnit);
// set texture unit indices (required by GLSL) // set texture unit indices (required by GLSL)
if (useShaders && ((hasVertex && foundVertex) || (hasFragment && foundFragment)) && mFactory->getCurrentLanguage () == Language_GLSL) if (mShadersEnabled && ((hasVertex && foundVertex) || (hasFragment && foundFragment)) && mFactory->getCurrentLanguage () == Language_GLSL)
{ {
pass->setTextureUnitIndex (foundVertex ? GPT_Vertex : GPT_Fragment, texIt->getName(), i); pass->setTextureUnitIndex (foundVertex ? GPT_Vertex : GPT_Fragment, texIt->getName(), i);