summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am4
-rw-r--r--src/emap/init.c10
-rw-r--r--src/emap/judyarray.c201
-rw-r--r--src/emap/judyarray.h29
-rw-r--r--src/emap/script_buildins.c109
-rw-r--r--src/emap/script_buildins.h7
-rwxr-xr-xtools/ci/jobs/clang39.sh2
-rwxr-xr-xtools/ci/jobs/clang6.sh2
-rwxr-xr-xtools/ci/jobs/clang7.sh2
-rwxr-xr-xtools/ci/jobs/gcc46.sh2
-rwxr-xr-xtools/ci/jobs/gcc48.sh2
-rwxr-xr-xtools/ci/jobs/gcc49.sh2
-rwxr-xr-xtools/ci/jobs/gcc5.sh2
-rwxr-xr-xtools/ci/jobs/gcc6.sh2
-rwxr-xr-xtools/ci/jobs/gcc7.sh2
-rwxr-xr-xtools/ci/jobs/gccsnapshot.sh2
16 files changed, 369 insertions, 11 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 68828fe..8bfb2f9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,8 @@ MAP_SRC = emap/atcommand.c \
emap/effects.h \
emap/hashtable.c \
emap/hashtable.h \
+ emap/judyarray.c \
+ emap/judyarray.h \
emap/homunculus.c \
emap/homunculus.h \
emap/horse.c \
@@ -140,7 +142,7 @@ SHARED_CFLAGS = ${CFLAGS} -O3 -pipe -ffast-math -std=c99 -Wall -Wextra -Wno-sign
-DPCRE_SUPPORT -I../../.. -I../../../../3rdparty \
-DPACKETVER=20150513 \
-DevolPacketOffset=0
-SHARED_LDFLAGS = -avoid-version -Wl,--no-undefined
+SHARED_LDFLAGS = -avoid-version -Wl,--no-undefined -lJudy
if ENABLE_STATIC_BUILD
SHARED_CFLAGS += "-static-libgcc"
diff --git a/src/emap/init.c b/src/emap/init.c
index fefbc6c..390800e 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -55,6 +55,7 @@
#include "emap/craft.h"
#include "emap/craftconf.h"
#include "emap/hashtable.h"
+#include "emap/judyarray.h"
#include "emap/homunculus.h"
#include "emap/itemdb.h"
#include "emap/lang.h"
@@ -95,6 +96,7 @@ HPExport void plugin_init (void)
isInit = false;
*global_npc_str = 0;
htreg_init();
+ judy_init();
skilld_init();
addAtcommand("setskill", setSkill);
@@ -196,6 +198,12 @@ HPExport void plugin_init (void)
addScriptCommand("getitemoptionparambyindex", "ii", getItemOptionParamByIndex);
addScriptCommand("setitemoptionbyindex", "iii*", setItemOptionByIndex);
addScriptCommand("isinstance", "i", isInstance);
+ addScriptCommand("judy_alloc", "", judyNew);
+ addScriptCommand("judy_free", "i", judyFree);
+ addScriptCommand("judy_exists", "i", judyExists);
+ addScriptCommand("judy_size", "i", judySize);
+ addScriptCommand("judy_put", "isv", judyPut);
+ addScriptCommand("judy_get", "is?", judyGet);
do_init_langs();
@@ -360,6 +368,7 @@ HPExport void server_preinit (void)
{
interfaces_init_common();
htreg_defaults();
+ judy_defaults();
setDefaultMap();
addMapInterConf("default_map", config_default_map);
@@ -387,5 +396,6 @@ HPExport void plugin_final (void)
do_final_craftconf();
commonClean();
htreg_final();
+ judy_final();
isInit = false;
}
diff --git a/src/emap/judyarray.c b/src/emap/judyarray.c
new file mode 100644
index 0000000..bb6dda9
--- /dev/null
+++ b/src/emap/judyarray.c
@@ -0,0 +1,201 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2018 Evol developers
+
+#include "common/hercules.h"
+
+#include <Judy.h>
+#include <string.h>
+
+#include "common/db.h"
+#include "common/memmgr.h"
+#include "emap/judyarray.h"
+
+struct judy_interface judy_s;
+struct judy_interface *judy;
+
+int64 judy_new_array(void)
+{
+ int64 id = judy->last_id++;
+ void **PJSLArray;
+ JLI(PJSLArray, judy->arrays, id);
+ *PJSLArray = (void *)NULL;
+ return id;
+}
+
+bool judy_destroy_array(int64 id)
+{
+ int ret = 0;
+ judy->clear_array(id);
+ JLD(ret, judy->arrays, id);
+ return true;
+}
+
+bool judy_array_exists(int64 id)
+{
+ void **PJSLArray;
+ JLG(PJSLArray, judy->arrays, id);
+ return PJSLArray != NULL;
+}
+
+int64 judy_array_size(int64 id)
+{
+ void **PJSLArray;
+ JLG(PJSLArray, judy->arrays, id);
+
+ if (!PJSLArray)
+ return 0;
+
+ unsigned long sz = 0;
+ JLC(sz, *PJSLArray, 0, -1);
+ return sz;
+}
+
+bool judy_clear_array(int64 id)
+{
+ void **PJSLArray;
+ JLG(PJSLArray, judy->arrays, id);
+
+ if (PJSLArray)
+ {
+ uint8_t key[1];
+ void **PValue;
+ key[0] = '\0';
+ JSLF(PValue, *PJSLArray, key);
+
+ while (PValue && *PValue)
+ {
+ const struct DBData *result = (struct DBData *)(*PValue);
+ if (result->type == DB_DATA_PTR)
+ aFree(result->u.ptr);
+ aFree(*PValue);
+
+ int ret = 0;
+ JSLD(ret, *PJSLArray, key);
+ JSLF(PValue, *PJSLArray, key);
+ }
+ return true;
+ }
+ return false;
+}
+
+const struct DBData* judy_getvalue(int64 id, const char *key, const struct DBData *defval)
+{
+ void **PJSLArray;
+ void **PValue;
+ JLG(PJSLArray, judy->arrays, id);
+
+ if (!PJSLArray)
+ return defval; // array not found
+
+ JSLG(PValue, *PJSLArray, (unsigned char *)key);
+ if (PValue && *PValue)
+ return (struct DBData *)(*PValue);
+ return defval;
+}
+
+bool judy_setvalue(int64 id, const char *key, struct DBData *value)
+{
+ void **PJSLArray;
+ JLG(PJSLArray, judy->arrays, id);
+
+ if (!PJSLArray)
+ {
+ if (value->type == DB_DATA_PTR)
+ aFree(value->u.ptr);
+ aFree(value);
+ return false; // array not found
+ }
+
+ bool keep = true;
+
+ switch(value->type)
+ {
+ case DB_DATA_INT:
+ case DB_DATA_UINT:
+ keep = value->u.i;
+ break;
+ case DB_DATA_PTR:
+ keep = value->u.ptr && *(char*)value->u.ptr;
+ break;
+ }
+
+ if (keep)
+ {
+ void **PValue;
+ JSLI(PValue, *PJSLArray, (unsigned char *)key);
+
+ if (PValue && *PValue)
+ {
+ const struct DBData *prev = (struct DBData *)(*PValue);
+ if (prev->type == DB_DATA_PTR)
+ aFree(prev->u.ptr);
+ aFree(*PValue); // free any previously-set struct
+ }
+
+ *PValue = value;
+ return true;
+ }
+ else
+ {
+ // check if it previously existed, and free it
+ {
+ void **PValue;
+ JSLG(PValue, *PJSLArray, (unsigned char *)key);
+ if (PValue && *PValue)
+ {
+ const struct DBData *prev = (struct DBData *)(*PValue);
+ if (prev->type == DB_DATA_PTR)
+ aFree(prev->u.ptr);
+ aFree(*PValue);
+ }
+ }
+
+ int ret = 0;
+ JSLD(ret, *PJSLArray, (unsigned char *)key);
+ }
+
+ if (value->type == DB_DATA_PTR)
+ aFree(value->u.ptr);
+ aFree(value);
+ return true;
+}
+
+
+/**
+ * Initializer.
+ */
+void judy_init(void)
+{
+ judy->arrays = (void *)NULL; // this is a judyL array of judySL arrays
+}
+
+/**
+ * Finalizer.
+ */
+void judy_final(void)
+{
+ for (int64 id = 1; id <= judy->last_id; id++)
+ judy->destroy_array(id);
+
+ unsigned long sz = 0;
+ JLFA(sz, judy->arrays);
+ judy->arrays = NULL;
+}
+
+/**
+ * Interface defaults initializer.
+ */
+void judy_defaults(void)
+{
+ judy = &judy_s;
+
+ judy->last_id = 1;
+ judy->arrays = NULL;
+ judy->new_array = judy_new_array;
+ judy->clear_array = judy_clear_array;
+ judy->destroy_array = judy_destroy_array;
+ judy->array_exists = judy_array_exists;
+ judy->array_size = judy_array_size;
+ judy->getvalue = judy_getvalue;
+ judy->setvalue = judy_setvalue;
+}
diff --git a/src/emap/judyarray.h b/src/emap/judyarray.h
new file mode 100644
index 0000000..ad9e1f0
--- /dev/null
+++ b/src/emap/judyarray.h
@@ -0,0 +1,29 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2018 Evol developers
+
+#ifndef EVOL_JUDY_ARRAY
+#define EVOL_JUDY_ARRAY
+
+#include "common/hercules.h"
+#include "common/db.h"
+
+struct judy_interface
+{
+ int64 last_id;
+ void *arrays;
+ int64 (*new_array) (void);
+ bool (*clear_array) (int64 id);
+ bool (*destroy_array) (int64 id);
+ bool (*array_exists) (int64 id);
+ int64 (*array_size) (int64 id);
+ const struct DBData* (*getvalue) (int64 id, const char *key, const struct DBData *defval);
+ bool (*setvalue) (int64 id, const char *key, struct DBData *value);
+};
+
+void judy_defaults(void);
+void judy_init(void);
+void judy_final(void);
+
+HPShared struct judy_interface *judy;
+
+#endif // EVOL_JUDY_ARRAY
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index 703307a..2b65f4a 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -24,6 +24,7 @@
#include "emap/lang.h"
#include "emap/map.h"
#include "emap/hashtable.h"
+#include "emap/judyarray.h"
#include "emap/scriptdefines.h"
#include "emap/send.h"
#include "emap/data/bgd.h"
@@ -42,6 +43,114 @@ uint32 MakeDWord(uint16 word0, uint16 word1)
return ((uint32)(word0)) | ((uint32)(word1 << 0x10));
}
+BUILDIN(judyNew)
+{
+ int64 id = judy->new_array();
+ script_pushint(st, id);
+ return true;
+}
+
+BUILDIN(judyPut)
+{
+ int64 id = script_getnum(st, 2);
+ const char *key = script_getstr(st, 3);
+ struct DBData *value;
+
+ CREATE(value, struct DBData, 1);
+
+ if (script_isstringtype(st, 4))
+ {
+ value->type = DB_DATA_PTR;
+ value->u.ptr = (void *)aStrdup(script_getstr(st, 4));
+ }
+ else if (script_isinttype(st, 4))
+ {
+ value->type = DB_DATA_INT;
+ value->u.i = script_getnum(st, 4);
+ }
+ else
+ {
+ aFree(value);
+ ShowError("judy_put: unhandled data type!\n");
+ script_pushint(st, 0);
+ return false;
+ }
+
+ judy->setvalue(id, key, value);
+ script_pushint(st, 1);
+ return true;
+}
+
+BUILDIN(judyGet)
+{
+ struct DBData defval_s;
+ struct DBData *defval = &defval_s;
+ int64 id = script_getnum(st, 2);
+ const char *key = script_getstr(st, 3);
+
+ if (script_hasdata(st, 4))
+ {
+ if (script_isstringtype(st, 4))
+ {
+ defval->type = DB_DATA_PTR;
+ defval->u.ptr = (void*)script_getstr(st, 4);
+ }
+ else if (script_isinttype(st, 4))
+ {
+ defval->type = DB_DATA_INT;
+ defval->u.i = script_getnum(st, 4);
+ }
+ else
+ {
+ ShowError("usage: judy_get(<id>, <strkey>[ ,<defval>])\n");
+ return false;
+ }
+ }
+ else
+ {
+ defval = NULL;
+ }
+
+ const struct DBData *result = judy->getvalue(id, key, defval);
+ if (result)
+ {
+ switch(result->type)
+ {
+ case DB_DATA_INT:
+ case DB_DATA_UINT:
+ script_pushint(st, result->u.i);
+ break;
+ case DB_DATA_PTR:
+ script_pushstrcopy(st, result->u.ptr);
+ break;
+ }
+ }
+ else
+ {
+ script_pushint(st, 0);
+ }
+
+ return true;
+}
+
+BUILDIN(judySize)
+{
+ script_pushint(st, judy->array_size(script_getnum(st, 2)));
+ return true;
+}
+
+BUILDIN(judyExists)
+{
+ script_pushint(st, judy->array_exists(script_getnum(st, 2)));
+ return true;
+}
+
+BUILDIN(judyFree)
+{
+ script_pushint(st, judy->destroy_array(script_getnum(st, 2)));
+ return true;
+}
+
BUILDIN(l)
{
format_sub(st, 1);
diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h
index 2066432..f84f30d 100644
--- a/src/emap/script_buildins.h
+++ b/src/emap/script_buildins.h
@@ -1,3 +1,4 @@
+
// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// Copyright (c) 2014 - 2015 Evol developers
@@ -95,5 +96,11 @@ BUILDIN(getItemOptionValueByIndex);
BUILDIN(getItemOptionParamByIndex);
BUILDIN(setItemOptionByIndex);
BUILDIN(isInstance);
+BUILDIN(judyPut);
+BUILDIN(judyGet);
+BUILDIN(judySize);
+BUILDIN(judyNew);
+BUILDIN(judyExists);
+BUILDIN(judyFree);
#endif // EVOL_MAP_SCRIPT_BUILDINS
diff --git a/tools/ci/jobs/clang39.sh b/tools/ci/jobs/clang39.sh
index 41e4e8a..a0a67d9 100755
--- a/tools/ci/jobs/clang39.sh
+++ b/tools/ci/jobs/clang39.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install clang-3.9 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/clang6.sh b/tools/ci/jobs/clang6.sh
index 8fdc908..94bbea1 100755
--- a/tools/ci/jobs/clang6.sh
+++ b/tools/ci/jobs/clang6.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install clang-6.0 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/clang7.sh b/tools/ci/jobs/clang7.sh
index c416f8d..9fdeed0 100755
--- a/tools/ci/jobs/clang7.sh
+++ b/tools/ci/jobs/clang7.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install clang-7 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gcc46.sh b/tools/ci/jobs/gcc46.sh
index f2cf542..7cf8400 100755
--- a/tools/ci/jobs/gcc46.sh
+++ b/tools/ci/jobs/gcc46.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-4.6 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gcc48.sh b/tools/ci/jobs/gcc48.sh
index 1867d5f..5300833 100755
--- a/tools/ci/jobs/gcc48.sh
+++ b/tools/ci/jobs/gcc48.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-4.8 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gcc49.sh b/tools/ci/jobs/gcc49.sh
index 800f970..98c7f21 100755
--- a/tools/ci/jobs/gcc49.sh
+++ b/tools/ci/jobs/gcc49.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-4.9 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gcc5.sh b/tools/ci/jobs/gcc5.sh
index cb959a1..388e3cd 100755
--- a/tools/ci/jobs/gcc5.sh
+++ b/tools/ci/jobs/gcc5.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-5 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gcc6.sh b/tools/ci/jobs/gcc6.sh
index 85f6748..927d5c4 100755
--- a/tools/ci/jobs/gcc6.sh
+++ b/tools/ci/jobs/gcc6.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-6 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gcc7.sh b/tools/ci/jobs/gcc7.sh
index 8d9fad6..65ab516 100755
--- a/tools/ci/jobs/gcc7.sh
+++ b/tools/ci/jobs/gcc7.sh
@@ -9,7 +9,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-7 \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init
diff --git a/tools/ci/jobs/gccsnapshot.sh b/tools/ci/jobs/gccsnapshot.sh
index 5e49d3e..7ac5fa4 100755
--- a/tools/ci/jobs/gccsnapshot.sh
+++ b/tools/ci/jobs/gccsnapshot.sh
@@ -10,7 +10,7 @@ source ./tools/ci/scripts/init.sh
aptget_install gcc-snapshot \
git-core \
make autoconf automake autopoint \
- libtool libmysqlclient-dev libz-dev libpcre3-dev
+ libtool libmysqlclient-dev libz-dev libpcre3-dev libjudy-dev
do_init
build_init