[Freeciv-Dev] (PR#13015) [PATCH] Remove misfeature of script signals
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#13015) [PATCH] Remove misfeature of script signals |
From: |
"Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx> |
Date: |
Mon, 9 May 2005 14:26:44 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13015 >
> [vasc - Mon May 09 21:24:01 2005]:
>
> Signal enabled/disabled state caused havok on scenarios. A bug in script
> loading from savedgames was also fixed.
>
> Bug reported by Jason Dorje Short.
Ooops, I sent the wrong patch. Here it is.
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.245
diff -u -u -r1.245 savegame.c
--- server/savegame.c 7 May 2005 15:38:31 -0000 1.245
+++ server/savegame.c 9 May 2005 21:20:23 -0000
@@ -3472,6 +3472,8 @@
load_rulesets();
}
+ script_state_load(file);
+
{
if (game.version >= 10300) {
{
@@ -3741,8 +3743,6 @@
players_iterate(pplayer) {
calc_civ_score(pplayer);
} players_iterate_end;
-
- script_state_load(file);
}
/***************************************************************
Index: server/scripting/script.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script.c,v
retrieving revision 1.1
diff -u -u -r1.1 script.c
--- server/scripting/script.c 1 May 2005 12:01:16 -0000 1.1
+++ server/scripting/script.c 9 May 2005 21:20:24 -0000
@@ -62,16 +62,12 @@
/**************************************************************************
Invoke the 'callback_name' Lua function.
**************************************************************************/
-void script_callback_invoke(const char *callback_name,
- bool *stop_emission, bool *remove_callback,
+bool script_callback_invoke(const char *callback_name,
int nargs, va_list args)
{
int i, nres;
bool res;
- *stop_emission = FALSE;
- *remove_callback = FALSE;
-
/* The function name */
lua_getglobal(state, callback_name);
@@ -142,39 +138,25 @@
/* Call the function with nargs arguments, return 2 results */
if (lua_pcall(state, nargs, 2, 0) != 0) {
- return;
+ return FALSE;
}
nres = lua_gettop(state);
- switch (nres) {
- case 2:
- if (lua_isboolean(state, -1)) {
- res = lua_toboolean(state, -1);
- lua_pop(state, 1);
-
- /* Shall we remove this callback? */
- if (res) {
- *remove_callback = TRUE;
- }
- }
- case 1:
- if (lua_isboolean(state, -1)) {
- res = lua_toboolean(state, -1);
- lua_pop(state, 1);
-
- /* Shall we stop the emission of this signal? */
- if (res) {
- *stop_emission = TRUE;
- }
+ if (nres == 1) {
+ if (lua_isboolean(state, -1)) {
+ res = lua_toboolean(state, -1);
+ lua_pop(state, 1);
+
+ /* Shall we stop the emission of this signal? */
+ if (res) {
+ return TRUE;
}
- break;
- case 0:
- break;
- default:
- lua_pop(state, nres);
- break;
+ }
}
+
+ lua_pop(state, nres);
+ return FALSE;
}
/**************************************************************************
@@ -333,10 +315,6 @@
/* Variables must be loaded after code is loaded and executed,
* so we restore their saved state properly */
script_vars_load(file);
-
- /* Signals must be loaded last,
- * so we restore their state properly */
- script_signals_load(file);
}
/**************************************************************************
@@ -346,7 +324,5 @@
{
script_code_save(file);
script_vars_save(file);
-
- script_signals_save(file);
}
Index: server/scripting/script.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script.h,v
retrieving revision 1.1
diff -u -u -r1.1 script.h
--- server/scripting/script.h 1 May 2005 12:01:16 -0000 1.1
+++ server/scripting/script.h 9 May 2005 21:20:24 -0000
@@ -22,8 +22,7 @@
int script_error(const char *fmt, ...);
/* callback invocation function. */
-void script_callback_invoke(const char *callback_name,
- bool *stop_emission, bool *remove_callback,
+bool script_callback_invoke(const char *callback_name,
int nargs, va_list args);
/* script functions. */
Index: server/scripting/script_signal.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script_signal.c,v
retrieving revision 1.1
diff -u -u -r1.1 script_signal.c
--- server/scripting/script_signal.c 1 May 2005 12:01:16 -0000 1.1
+++ server/scripting/script_signal.c 9 May 2005 21:20:24 -0000
@@ -67,8 +67,6 @@
**************************************************************************/
struct signal {
int nargs; /* number of arguments to pass */
-
- bool enabled; /* reserved for future use */
struct signal_callback_list *callbacks; /* connected callbacks */
};
@@ -77,8 +75,6 @@
**************************************************************************/
struct signal_callback {
char *name; /* callback function name */
-
- bool enabled; /* reserved for future use */
};
/**************************************************************************
@@ -104,7 +100,6 @@
callback = fc_malloc(sizeof(*callback));
callback->name = mystrdup(callback_name);
- callback->enabled = TRUE;
signal_callback_list_append(list, callback);
return callback;
@@ -138,7 +133,6 @@
signal = fc_malloc(sizeof(*signal));
signal->nargs = nargs;
- signal->enabled = TRUE;
signal->callbacks = signal_callback_list_new();
hash_insert(signals, name, signal);
@@ -190,16 +184,8 @@
"Signal \"%s\" requires %d args, was passed %d on invoke.",
signal_name, signal->nargs, nargs);
} else {
- bool stop_emission, remove_callback;
-
signal_callback_list_iterate(signal->callbacks, pcallback) {
- script_callback_invoke(pcallback->name,
- &stop_emission, &remove_callback,
- nargs, args);
- if (remove_callback) {
- internal_signal_callback_remove(signal->callbacks, pcallback);
- }
- if (stop_emission) {
+ if (script_callback_invoke(pcallback->name, nargs, args)) {
break;
}
} signal_callback_list_iterate_end;
@@ -318,78 +304,6 @@
}
/**************************************************************************
- Load script signal callbacks state from file.
-**************************************************************************/
-void script_signals_load(struct section_file *file)
-{
- unsigned int n1, i;
-
- /* free existent data, load new data. */
- script_signals_free();
- script_signals_init();
-
- n1 = secfile_lookup_int_default(file, 0, "script.nsignals");
-
- for (i = 0; i < n1; i++) {
- unsigned int n2, j;
- char *signal_name, *callback_name;
- bool signal_enabled, callback_enabled;
-
- signal_name = secfile_lookup_str(file, "script_signal%d.name", i);
- signal_enabled = secfile_lookup_bool(file, "script_signal%d.enabled", i);
- n2 = secfile_lookup_int(file, "script_signal%d.ncallbacks", i);
-
- signal_name = mystrdup(signal_name);
-
- for (j = 0; j < n2; j++) {
- callback_name = secfile_lookup_str(file,
- "script_signal%d.callback%d.name", i, j);
- callback_enabled = secfile_lookup_bool(file,
- "script_signal%d.callback%d.enabled", i, j);
-
- script_signal_connect(signal_name, callback_name);
- }
-
- free(signal_name);
- }
-}
-
-/**************************************************************************
- Save script signal callbacks state to file.
-**************************************************************************/
-void script_signals_save(struct section_file *file)
-{
- if (signals) {
- unsigned int n1 = hash_num_entries(signals), n2, i, j;
-
- secfile_insert_int(file, n1, "script.nsignals");
-
- for (i = 0; i < n1; i++) {
- const char *name;
- const struct signal *signal;
-
- name = hash_key_by_number(signals, i);
- signal = hash_value_by_number(signals, i);
-
- n2 = signal_callback_list_size(signal->callbacks);
-
- secfile_insert_str(file, name, "script_signal%d.name", i);
- secfile_insert_bool(file, signal->enabled, "script_signal%d.enabled", i);
- secfile_insert_int(file, n2, "script_signal%d.ncallbacks", i);
-
- j = 0;
- signal_callback_list_iterate(signal->callbacks, pcallback) {
- secfile_insert_str(file, pcallback->name,
- "script_signal%d.callback%d.name", i, j);
- secfile_insert_bool(file, pcallback->enabled,
- "script_signal%d.callback%d.enabled", i, j);
- j++;
- } signal_callback_list_iterate_end;
- }
- }
-}
-
-/**************************************************************************
Declare any new signal types you need here.
**************************************************************************/
static void signals_create(void)
Index: server/scripting/script_signal.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script_signal.h,v
retrieving revision 1.1
diff -u -u -r1.1 script_signal.h
--- server/scripting/script_signal.h 1 May 2005 12:01:16 -0000 1.1
+++ server/scripting/script_signal.h 9 May 2005 21:20:24 -0000
@@ -42,8 +42,5 @@
void script_signals_init(void);
void script_signals_free(void);
-void script_signals_load(struct section_file *file);
-void script_signals_save(struct section_file *file);
-
#endif
|
|