summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c2
-rw-r--r--src/map/instance.c7
-rw-r--r--src/map/instance.h2
-rw-r--r--src/map/npc.c4
-rw-r--r--src/map/pc_groups.c2
-rw-r--r--src/map/pc_groups.h2
-rw-r--r--src/map/script.c135
-rw-r--r--src/map/script.h10
8 files changed, 72 insertions, 92 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 6ad69e5e3..6d5190d6e 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -8993,4 +8993,4 @@ void do_init_atcommand(void)
void do_final_atcommand(void)
{
atcommand_db_clear();
-} \ No newline at end of file
+}
diff --git a/src/map/instance.c b/src/map/instance.c
index c4e151d79..b105a09fa 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -343,13 +343,10 @@ void instance_destroy(int instance_id)
}
if( instance[instance_id].ivar )
- linkdb_final( &instance[instance_id].ivar ); // Remove numeric vars
+ db_destroy(instance[instance_id].ivar);
if( instance[instance_id].svar )
- { // Remove string vars
- linkdb_foreach( &instance[instance_id].svar, instance_destroy_freesvar );
- linkdb_final( &instance[instance_id].svar );
- }
+ db_destroy(instance[instance_id].svar);
if( instance[instance_id].progress_timer != INVALID_TIMER )
delete_timer( instance[instance_id].progress_timer, instance_destroy_timer);
diff --git a/src/map/instance.h b/src/map/instance.h
index e2b0354f9..e918aa516 100644
--- a/src/map/instance.h
+++ b/src/map/instance.h
@@ -21,7 +21,7 @@ struct s_instance {
int num_map;
int users;
- struct linkdb_node *ivar, *svar; // Instance Variable for scripts
+ struct DBMap *ivar, *svar; // Instance Variable for scripts
int progress_timer;
time_t progress_timeout;
diff --git a/src/map/npc.c b/src/map/npc.c
index 0309d6556..66635543a 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2767,9 +2767,9 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
func_db = script_get_userfunc_db();
if (func_db->put(func_db, db_str2key(w3), db_ptr2data(script), &old_data))
{
- struct script_code *oldscript = db_data2ptr(&old_data);
+ struct script_code *oldscript = (struct script_code*)db_data2ptr(&old_data);
ShowInfo("npc_parse_function: Overwriting user function [%s] (%s:%d)\n", w3, filepath, strline(buffer,start-buffer));
- script_free_vars(&oldscript->script_vars);
+ script_free_vars(oldscript->script_vars);
aFree(oldscript->script_buf);
aFree(oldscript);
}
diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c
index 74215eab9..c6fb6a7b1 100644
--- a/src/map/pc_groups.c
+++ b/src/map/pc_groups.c
@@ -443,4 +443,4 @@ void pc_groups_reload(void)
{
do_final_pc_groups();
do_init_pc_groups();
-} \ No newline at end of file
+}
diff --git a/src/map/pc_groups.h b/src/map/pc_groups.h
index 1134bc01a..353bbebfa 100644
--- a/src/map/pc_groups.h
+++ b/src/map/pc_groups.h
@@ -17,4 +17,4 @@ void do_init_pc_groups(void);
void do_final_pc_groups(void);
void pc_groups_reload(void);
-#endif // _PC_GROUPS_H_ \ No newline at end of file
+#endif // _PC_GROUPS_H_
diff --git a/src/map/script.c b/src/map/script.c
index ead524e77..0428d7a26 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2533,22 +2533,22 @@ void get_val(struct script_state* st, struct script_data* data)
break;
case '.':
{
- struct linkdb_node** n =
- data->ref ? data->ref:
- name[1] == '@' ? st->stack->var_function:// instance/scope variable
- &st->script->script_vars;// npc variable
- data->u.str = (char*)linkdb_search(n, (void*)__64BPRTSIZE(reference_getuid(data)));
+ struct DBMap* n =
+ data->ref ? *data->ref:
+ name[1] == '@' ? st->stack->var_function:// instance/scope variable
+ st->script->script_vars;// npc variable
+ data->u.str = (char*)idb_get(n,reference_getuid(data));
}
break;
case '\'':
{
- struct linkdb_node** n = NULL;
+ struct DBMap* n = NULL;
if (st->instance_id) {
- n = &instance[st->instance_id].svar;
+ n = instance[st->instance_id].svar;
} else {
ShowWarning("script:get_val: cannot access instance variable '%s', defaulting to 0\n", name);
}
- data->u.str = (char*)linkdb_search(n, (void*)__64BPRTSIZE(reference_getuid(data)));
+ data->u.str = (char*)idb_get(n,reference_getuid(data));
}
break;
default:
@@ -2598,19 +2598,19 @@ void get_val(struct script_state* st, struct script_data* data)
break;
case '.':
{
- struct linkdb_node** n =
- data->ref ? data->ref:
- name[1] == '@' ? st->stack->var_function:// instance/scope variable
- &st->script->script_vars;// npc variable
- data->u.num = (int)__64BPRTSIZE(linkdb_search(n, (void*)__64BPRTSIZE(reference_getuid(data))));
+ struct DBMap* n =
+ data->ref ? *data->ref:
+ name[1] == '@' ? st->stack->var_function:// instance/scope variable
+ st->script->script_vars;// npc variable
+ data->u.num = (int)idb_iget(n,reference_getuid(data));
}
break;
case '\'':
{
- struct linkdb_node** n = NULL;
+ struct DBMap* n = NULL;
if( st->instance_id )
- n = &instance[st->instance_id].ivar;
- data->u.num = (int)__64BPRTSIZE(linkdb_search(n, (void*)__64BPRTSIZE(reference_getuid(data))));
+ n = instance[st->instance_id].ivar;
+ data->u.num = (int)idb_iget(n,reference_getuid(data));
}
break;
default:
@@ -2623,11 +2623,11 @@ void get_val(struct script_state* st, struct script_data* data)
return;
}
-struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct linkdb_node** ref);
+struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref);
/// Retrieves the value of a reference identified by uid (variable, constant, param)
/// The value is left in the top of the stack and needs to be removed manually.
-void* get_val2(struct script_state* st, int uid, struct linkdb_node** ref)
+void* get_val2(struct script_state* st, int uid, struct DBMap** ref)
{
struct script_data* data;
push_val2(st->stack, C_NAME, uid, ref);
@@ -2640,7 +2640,7 @@ void* get_val2(struct script_state* st, int uid, struct linkdb_node** ref)
* Stores the value of a script variable
* Return value is 0 on fail, 1 on success.
*------------------------------------------*/
-static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* name, const void* value, struct linkdb_node** ref)
+static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* name, const void* value, struct DBMap** ref)
{
char prefix = name[0];
@@ -2656,24 +2656,20 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
return (name[1] == '#') ?
pc_setaccountreg2str(sd, name, str) :
pc_setaccountregstr(sd, name, str);
- case '.': {
- char* p;
- struct linkdb_node** n;
- n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars;
- p = (char*)linkdb_erase(n, (void*)__64BPRTSIZE(num));
- if (p) aFree(p);
- if (str[0]) linkdb_insert(n, (void*)__64BPRTSIZE(num), aStrdup(str));
+ case '.':
+ {
+ struct DBMap* n;
+ n = (ref) ? *ref : (name[1] == '@') ? st->stack->var_function : st->script->script_vars;
+ if( n ) {
+ idb_remove(n, num);
+ if (str[0]) idb_put(n, num, aStrdup(str));
+ }
}
return 1;
- case '\'': {
- char *p;
- struct linkdb_node** n = NULL;
- if( st->instance_id )
- n = &instance[st->instance_id].svar;
-
- p = (char*)linkdb_erase(n, (void*)__64BPRTSIZE(num));
- if (p) aFree(p);
- if( str[0] ) linkdb_insert(n, (void*)__64BPRTSIZE(num), aStrdup(str));
+ case '\'':
+ if( st->instance_id ) {
+ idb_remove(instance[st->instance_id].svar, num);
+ if( str[0] ) idb_put(instance[st->instance_id].svar, num, aStrdup(str));
}
return 1;
default:
@@ -2707,27 +2703,24 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
return (name[1] == '#') ?
pc_setaccountreg2(sd, name, val) :
pc_setaccountreg(sd, name, val);
- case '.': {
- struct linkdb_node** n;
- n = (ref) ? ref : (name[1] == '@') ? st->stack->var_function : &st->script->script_vars;
- if (val == 0)
- linkdb_erase(n, (void*)__64BPRTSIZE(num));
- else
- linkdb_replace(n, (void*)__64BPRTSIZE(num), (void*)__64BPRTSIZE(val));
+ case '.':
+ {
+ struct DBMap* n;
+ n = (ref) ? *ref : (name[1] == '@') ? st->stack->var_function : st->script->script_vars;
+ if( n ) {
+ idb_remove(n, num);
+ if( val != 0 )
+ idb_iput(n, num, val);
+ }
}
return 1;
case '\'':
- {
- struct linkdb_node** n = NULL;
- if( st->instance_id )
- n = &instance[st->instance_id].ivar;
-
- if( val == 0 )
- linkdb_erase(n, (void*)__64BPRTSIZE(num));
- else
- linkdb_replace(n, (void*)__64BPRTSIZE(num), (void*)__64BPRTSIZE(val));
- return 1;
+ if( st->instance_id ) {
+ idb_remove(instance[st->instance_id].ivar, num);
+ if( val != 0 )
+ idb_iput(instance[st->instance_id].ivar, num, val);
}
+ return 1;
default:
return pc_setglobalreg(sd, name, val);
}
@@ -2739,7 +2732,7 @@ int set_var(TBL_PC* sd, char* name, void* val)
return set_reg(NULL, sd, reference_uid(add_str(name),0), name, val, NULL);
}
-void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct linkdb_node **ref)
+void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct DBMap **ref)
{
set_reg(st, sd, reference_uid(add_str(varname),elem), varname, value, ref);
}
@@ -2852,7 +2845,7 @@ void stack_expand(struct script_stack* stack)
#define push_val(stack,type,val) push_val2(stack, type, val, NULL)
/// Pushes a value into the stack (with reference)
-struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct linkdb_node** ref)
+struct script_data* push_val2(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref)
{
if( stack->sp >= stack->sp_max )
stack_expand(stack);
@@ -2937,10 +2930,7 @@ void pop_stack(struct script_state* st, int start, int end)
{
struct script_retinfo* ri = data->u.ri;
if( ri->var_function )
- {
script_free_vars(ri->var_function);
- aFree(ri->var_function);
- }
aFree(ri);
}
data->type = C_NOP;
@@ -2969,22 +2959,17 @@ void pop_stack(struct script_state* st, int start, int end)
/*==========================================
* スクリプト依存変数、関数依存変数の解放
*------------------------------------------*/
-void script_free_vars(struct linkdb_node **node)
+void script_free_vars(struct DBMap* storage)
{
- struct linkdb_node* n = *node;
- while( n != NULL)
- {
- const char* name = get_str((int)__64BPRTSIZE((n->key)&0x00ffffff));
- if( is_string_variable(name) )
- aFree(n->data); // 文字型変数なので、データ削除
- n = n->next;
+ if( storage )
+ {// destroy the storage construct containing the variables
+ db_destroy(storage);
}
- linkdb_final( node );
}
void script_free_code(struct script_code* code)
{
- script_free_vars( &code->script_vars );
+ script_free_vars( code->script_vars );
aFree( code->script_buf );
aFree( code );
}
@@ -3005,7 +2990,7 @@ struct script_state* script_alloc_state(struct script_code* script, int pos, int
st->stack->sp_max = 64;
CREATE(st->stack->stack_data, struct script_data, st->stack->sp_max);
st->stack->defsp = st->stack->sp;
- CREATE(st->stack->var_function, struct linkdb_node*, 1);
+ st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA);
st->state = RUN;
st->script = script;
//st->scriptroot = script;
@@ -3028,7 +3013,6 @@ void script_free_state(struct script_state* st)
if( st->sleep.timer != INVALID_TIMER )
delete_timer(st->sleep.timer, run_script_timer);
script_free_vars(st->stack->var_function);
- aFree(st->stack->var_function);
pop_stack(st, 0, st->stack->sp);
aFree(st->stack->stack_data);
aFree(st->stack);
@@ -3465,7 +3449,6 @@ int run_func(struct script_state *st)
return 1;
}
script_free_vars( st->stack->var_function );
- aFree(st->stack->var_function);
ri = st->stack->stack_data[st->stack->defsp-1].u.ri;
nargs = ri->nargs;
@@ -4481,7 +4464,7 @@ BUILDIN_FUNC(callfunc)
{
const char* name = reference_getname(data);
if( name[0] == '.' && name[1] == '@' )
- data->ref = st->stack->var_function;
+ data->ref = &st->stack->var_function;
else if( name[0] == '.' )
data->ref = &st->script->script_vars;
}
@@ -4499,7 +4482,7 @@ BUILDIN_FUNC(callfunc)
st->script = scr;
st->stack->defsp = st->stack->sp;
st->state = GOTO;
- st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
+ st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA);
return 0;
}
@@ -4527,7 +4510,7 @@ BUILDIN_FUNC(callsub)
{
const char* name = reference_getname(data);
if( name[0] == '.' && name[1] == '@' )
- data->ref = st->stack->var_function;
+ data->ref = &st->stack->var_function;
}
}
@@ -4542,7 +4525,7 @@ BUILDIN_FUNC(callsub)
st->pos = pos;
st->stack->defsp = st->stack->sp;
st->state = GOTO;
- st->stack->var_function = (struct linkdb_node**)aCalloc(1, sizeof(struct linkdb_node*));
+ st->stack->var_function = idb_alloc(DB_OPT_RELEASE_DATA);
return 0;
}
@@ -4597,7 +4580,7 @@ BUILDIN_FUNC(return)
const char* name = reference_getname(data);
if( name[0] == '.' && name[1] == '@' )
{// scope variable
- if( !data->ref || data->ref == st->stack->var_function )
+ if( !data->ref || data->ref == (DBMap**)&st->stack->var_function )
get_val(st, data);// current scope, convert to value
}
else if( name[0] == '.' && !data->ref )
@@ -5178,7 +5161,7 @@ BUILDIN_FUNC(set)
///
/// Returns the size of the specified array
-static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct linkdb_node** ref)
+static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct DBMap** ref)
{
int32 ret = idx;
diff --git a/src/map/script.h b/src/map/script.h
index 9f8752aff..4d7754241 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -76,7 +76,7 @@ typedef enum c_op {
} c_op;
struct script_retinfo {
- struct linkdb_node** var_function;// scope variables
+ struct DBMap* var_function;// scope variables
struct script_code* script;// script code
int pos;// script location
int nargs;// argument count
@@ -90,7 +90,7 @@ struct script_data {
char *str;
struct script_retinfo* ri;
} u;
- struct linkdb_node** ref;
+ struct DBMap** ref;
};
// Moved defsp from script_state to script_stack since
@@ -98,7 +98,7 @@ struct script_data {
struct script_code {
int script_size;
unsigned char* script_buf;
- struct linkdb_node* script_vars;
+ struct DBMap* script_vars;
};
struct script_stack {
@@ -106,7 +106,7 @@ struct script_stack {
int sp_max;// capacity of the stack
int defsp;
struct script_data *stack_data;// stack
- struct linkdb_node** var_function;// scope variables
+ struct DBMap* var_function;// scope variables
};
@@ -164,7 +164,7 @@ void run_script_main(struct script_state *st);
void script_stop_sleeptimers(int id);
struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n);
void script_free_code(struct script_code* code);
-void script_free_vars(struct linkdb_node **node);
+void script_free_vars(struct DBMap *storage);
struct script_state* script_alloc_state(struct script_code* script, int pos, int rid, int oid);
void script_free_state(struct script_state* st);