Created
March 5, 2011 16:32
-
-
Save tomprince/856486 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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..3566d71 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 <map> | |
| static struct { | |
| const char* Name; | |
| @@ -39,8 +40,8 @@ static struct { | |
| } Opcodes[MAX_EFFECTS]; | |
| static int initialized = 0; | |
| -static EffectDesc *effectnames = NULL; | |
| -static int effectnames_count = 0; | |
| +typedef std::map<const char*,EffectDesc,iless> effect_map; | |
| +static effect_map effectnames; | |
| static int pstflags = false; | |
| bool EffectQueue::match_ids(Actor *target, int table, ieDword value) | |
| @@ -175,15 +176,16 @@ int find_effect(const void *a, const void *b) | |
| 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) { | |
| + effect_map::iterator it = effectnames.find(effectname); | |
| + if (it == effectnames.end()) { | |
| printMessage( "EffectQueue", "", YELLOW); | |
| printf("Couldn't assign effect: %s\n", effectname ); | |
| + return NULL; | |
| } | |
| - return (EffectDesc *) tmp; | |
| + return &it->second; | |
| } | |
| static EffectRef fx_protection_from_display_string_ref = { "Protection:String", -1 }; | |
| @@ -264,28 +266,14 @@ 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 ) ); | |
| + for (int i = 0; i < count; ++i) { | |
| + effectnames[opcodes[i].Name] = opcodes[i]; | |
| } | |
| - | |
| - memcpy( effectnames + effectnames_count, opcodes, count * sizeof( EffectDesc )); | |
| - 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); | |
| } | |
| EffectQueue::EffectQueue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment