Skip to content

Instantly share code, notes, and snippets.

@tomprince
Created March 5, 2011 17:04
Show Gist options
  • Save tomprince/856507 to your computer and use it in GitHub Desktop.
Save tomprince/856507 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..8cc2f6b 100644
--- a/gemrb/core/EffectQueue.cpp
+++ b/gemrb/core/EffectQueue.cpp
@@ -30,6 +30,8 @@
#include "Spell.h" //needs for the source flags bitfield
#include <cstdio>
+#include <vector>
+#include <algorithm>
static struct {
const char* Name;
@@ -39,8 +41,7 @@ static struct {
} Opcodes[MAX_EFFECTS];
static int initialized = 0;
-static EffectDesc *effectnames = NULL;
-static int effectnames_count = 0;
+static std::vector<EffectDesc> effectnames;
static int pstflags = false;
bool EffectQueue::match_ids(Actor *target, int table, ieDword value)
@@ -163,27 +164,27 @@ 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)
{
- if( !effectname || !effectnames) {
+ if( !effectname) {
return NULL;
}
- void *tmp = bsearch(effectname, effectnames, effectnames_count, sizeof(EffectDesc), find_effect);
- if( !tmp) {
+ std::vector<EffectDesc>::iterator tmp = std::lower_bound(effectnames.begin(), effectnames.end(), effectname, find_effect);
+ if (tmp == effectnames.end() || 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 };
@@ -264,28 +265,16 @@ bool Init_EffectQueue()
void EffectQueue_ReleaseMemory()
{
- if( effectnames) {
- free (effectnames);
- }
- effectnames_count = 0;
- effectnames = NULL;
+ effectnames.clear();
}
void EffectQueue_RegisterOpcodes(int count, const EffectDesc* opcodes)
{
- if( ! effectnames) {
- effectnames = (EffectDesc*) malloc( (count+1) * sizeof( EffectDesc ) );
- } else {
- effectnames = (EffectDesc*) realloc( effectnames, (effectnames_count + count + 1) * sizeof( EffectDesc ) );
- }
-
- memcpy( effectnames + effectnames_count, opcodes, count * sizeof( EffectDesc ));
- effectnames_count += count;
- effectnames[effectnames_count].Name = NULL;
+ effectnames.insert(effectnames.end(), opcodes, opcodes + count);
//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.begin(), effectnames.end(), compare_effects);
}
EffectQueue::EffectQueue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment