Skip to content

Instantly share code, notes, and snippets.

@tomprince
Created March 5, 2011 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomprince/856503 to your computer and use it in GitHub Desktop.
Save tomprince/856503 to your computer and use it in GitHub Desktop.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb0f7f3..80c4c37 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,18 +6,6 @@ endif(COMMAND cmake_policy)
# allow empty else and endif constructs (available by default since 2.6.0)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
-# prevent in-source builds
-IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
- MESSAGE(FATAL_ERROR "
- CMake generation for this project is not allowed within the source directory!
- Remove the CMakeCache.txt file and try again from another folder, e.g.:
- rm CMakeCache.txt
- mkdir build
- cd build
- cmake .."
- )
-ENDIF()
-
# If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition
# and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE
# to Release prior to calling PROJECT()
diff --git a/gemrb/core/EffectQueue.cpp b/gemrb/core/EffectQueue.cpp
index 85f4b44..3069c16 100644
--- a/gemrb/core/EffectQueue.cpp
+++ b/gemrb/core/EffectQueue.cpp
@@ -30,6 +30,7 @@
#include "Spell.h" //needs for the source flags bitfield
#include <cstdio>
+#include <algorithm>
static struct {
const char* Name;
@@ -163,14 +164,14 @@ inline ieByte TriggeredEffect(ieByte timingmode)
return fx_triggered[timingmode];
}
-int compare_effects(const void *a, const void *b)
+int compare_effects(const EffectDesc &a, const EffectDesc &b)
{
- return stricmp(((EffectRef *) a)->Name,((EffectRef *) b)->Name);
+ return stricmp(a.Name,b.Name) < 0;
}
-int find_effect(const void *a, const void *b)
+int find_effect(const EffectDesc &b, const char *a)
{
- return stricmp((const char *) a,((const EffectRef *) b)->Name);
+ return stricmp(b.Name, a) < 0;
}
static EffectDesc* FindEffect(const char* effectname)
@@ -178,12 +179,12 @@ static EffectDesc* FindEffect(const char* effectname)
if( !effectname || !effectnames) {
return NULL;
}
- void *tmp = bsearch(effectname, effectnames, effectnames_count, sizeof(EffectDesc), find_effect);
- if( !tmp) {
+ EffectDesc *tmp = std::lower_bound(effectnames, effectnames + effectnames_count, effectname, find_effect);
+ if (tmp == effectnames + effectnames_count || stricmp(effectname, tmp->Name) != 0) {
printMessage( "EffectQueue", "", YELLOW);
printf("Couldn't assign effect: %s\n", effectname );
}
- return (EffectDesc *) tmp;
+ return tmp;
}
static EffectRef fx_protection_from_display_string_ref = { "Protection:String", -1 };
@@ -279,13 +280,13 @@ void EffectQueue_RegisterOpcodes(int count, const EffectDesc* opcodes)
effectnames = (EffectDesc*) realloc( effectnames, (effectnames_count + count + 1) * sizeof( EffectDesc ) );
}
- memcpy( effectnames + effectnames_count, opcodes, count * sizeof( EffectDesc ));
+ std::copy(opcodes, opcodes + count, effectnames + effectnames_count);
effectnames_count += count;
effectnames[effectnames_count].Name = NULL;
//if we merge two effect lists, then we need to sort their effect tables
//actually, we might always want to sort this list, so there is no
- //need to do it manually (sorted table is needed if we use bsearch)
- qsort(effectnames, effectnames_count, sizeof(EffectDesc), compare_effects);
+ //need to do it manually (sorted table is needed if we use search)
+ std::sort(effectnames, effectnames + effectnames_count, compare_effects);
}
EffectQueue::EffectQueue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment