Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] (PR#15574) move worklists out of player structure
Home

[Freeciv-Dev] (PR#15574) move worklists out of player structure

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#15574) move worklists out of player structure
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 Feb 2006 14:23:54 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15574 >

This patch moves the global worklists out of the player structure.  This 
client-only variable is now simply held in a worklists[] array in 
civclient.h.

Since this breaks some GUIs this is best for only the development version.

We could also consider having a client structure that could hold lots of 
global variables.  This would be safest in the long run.  Probably just 
a struct civ_client {...} in civclient.h.

-jason

Index: common/player.h
===================================================================
--- common/player.h     (revision 11592)
+++ common/player.h     (working copy)
@@ -191,7 +191,6 @@
   bool is_connected;
   struct connection *current_conn;     /* non-null while handling packet */
   struct conn_list *connections;       /* will replace conn */
-  struct worklist worklists[MAX_NUM_WORKLISTS];
   struct player_tile *private_map;
   unsigned int gives_shared_vision; /* bitvector those that give you shared 
vision */
   unsigned int really_gives_vision; /* takes into account that p3 may see what 
p1 has via p2 */
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
--- client/gui-gtk-2.0/wldlg.c  (revision 11592)
+++ client/gui-gtk-2.0/wldlg.c  (working copy)
@@ -106,7 +106,6 @@
 *****************************************************************/
 void update_worklist_report_dialog(void)
 {
-  struct player *plr;
   int i;
   GtkTreeIter it;
 
@@ -114,20 +113,14 @@
     return;
   }
 
-  plr = game.player_ptr;
-
   gtk_list_store_clear(worklists_store);
 
-  if (!game.player_ptr) {
-    return;
-  }
-
   for (i = 0; i < MAX_NUM_WORKLISTS; i++) {
-    if (plr->worklists[i].is_valid) {
+    if (worklists[i].is_valid) {
       gtk_list_store_append(worklists_store, &it);
       
        gtk_list_store_set(worklists_store, &it,
-                         0, plr->worklists[i].name,
+                         0, worklists[i].name,
                          1, i,
                          -1); 
     }
@@ -139,20 +132,13 @@
 *****************************************************************/
 static void worklists_response(GtkWidget *w, gint response)
 {
-  struct player *plr;
   int i, pos;
   GtkTreeSelection *selection;
   GtkTreeModel *model;
   GtkTreeIter it;
 
-  plr = game.player_ptr;
-
-  if (!game.player_ptr) {
-    return;
-  }
-
   for (i = 0; i < MAX_NUM_WORKLISTS; i++) {
-    if (!plr->worklists[i].is_valid) {
+    if (!worklists[i].is_valid) {
       break;
     }
   }
@@ -173,9 +159,9 @@
       }
 
       /* Validate this slot. */
-      init_worklist(&plr->worklists[i]);
-      plr->worklists[i].is_valid = TRUE;
-      strcpy(plr->worklists[i].name, _("new"));
+      init_worklist(&worklists[i]);
+      worklists[i].is_valid = TRUE;
+      strcpy(worklists[i].name, _("new"));
 
       update_worklist_report_dialog();
       return;
@@ -185,10 +171,10 @@
        return;
       }
 
-      popdown_worklist(&plr->worklists[pos]);
+      popdown_worklist(&worklists[pos]);
 
-      plr->worklists[pos].is_valid = FALSE;
-      plr->worklists[pos].name[0] = '\0';
+      worklists[pos].is_valid = FALSE;
+      worklists[pos].name[0] = '\0';
 
       update_worklist_report_dialog();
       return;
@@ -198,7 +184,7 @@
        return;
       }
 
-      popup_worklist(&plr->worklists[pos]);
+      popup_worklist(&worklists[pos]);
       return;
 
     default:
@@ -217,14 +203,13 @@
   GtkTreePath *path;
   GtkTreeIter it;
   int pos;
-  struct player *plr = game.player_ptr;
 
   path = gtk_tree_path_new_from_string(spath);
   gtk_tree_model_get_iter(GTK_TREE_MODEL(worklists_store), &it, path);
   
   gtk_tree_model_get(GTK_TREE_MODEL(worklists_store), &it, 1, &pos, -1);
 
-  sz_strlcpy(plr->worklists[pos].name, text);
+  sz_strlcpy(worklists[pos].name, text);
   gtk_list_store_set(worklists_store, &it, 0, text, -1);
 
   gtk_tree_path_free(path);
@@ -476,7 +461,6 @@
 *****************************************************************/
 static void menu_item_callback(GtkMenuItem *item, struct worklist_data *ptr)
 {
-  struct player *plr;
   gint pos;
   struct worklist *pwl;
 
@@ -484,10 +468,9 @@
     return;
   }
 
-  plr = game.player_ptr;
   pos = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item), "pos"));
 
-  pwl = &plr->worklists[pos];
+  pwl = &worklists[pos];
 
   if (pwl->is_valid) {
     int i;
@@ -511,21 +494,15 @@
 *****************************************************************/
 static void popup_add_menu(GtkMenuShell *menu, gpointer data)
 {
-  struct player *plr;
   int i;
   GtkWidget *item;
 
   gtk_container_foreach(GTK_CONTAINER(menu),
                        (GtkCallback) gtk_widget_destroy, NULL);
-  plr = game.player_ptr;
 
-  if (!game.player_ptr) {
-    return;
-  }
-
   for (i = 0; i < MAX_NUM_WORKLISTS; i++) {
-    if (plr->worklists[i].is_valid) {
-      item = gtk_menu_item_new_with_label(plr->worklists[i].name);
+    if (worklists[i].is_valid) {
+      item = gtk_menu_item_new_with_label(worklists[i].name);
       g_object_set_data(G_OBJECT(item), "pos", GINT_TO_POINTER(i));
       gtk_widget_show(item);
 
@@ -994,7 +971,6 @@
     }
   } else {
     struct city **pcity = data;
-    struct player *plr;
     gint column;
     char *row[4];
     char  buf[4][64];
@@ -1010,8 +986,7 @@
     g_object_set(rend, "text", row[column], NULL);
 
     if (!target.is_unit && *pcity) {
-      plr = city_owner(*pcity);
-      useless = improvement_obsolete(plr, target.value)
+      useless = improvement_obsolete(city_owner(*pcity), target.value)
        || is_building_replaced(*pcity, target.value);
       g_object_set(rend, "strikethrough", useless, NULL);
     } else {
Index: client/civclient.c
===================================================================
--- client/civclient.c  (revision 11592)
+++ client/civclient.c  (working copy)
@@ -94,6 +94,8 @@
 bool auto_connect = FALSE; /* TRUE = skip "Connect to Freeciv Server" dialog */
 bool in_ggz = FALSE;
 
+struct worklist worklists[MAX_NUM_WORKLISTS];
+
 static enum client_states client_state = CLIENT_BOOT_STATE;
 
 /* TRUE if an end turn request is blocked by busy agents */
Index: client/civclient.h
===================================================================
--- client/civclient.h  (revision 11592)
+++ client/civclient.h  (working copy)
@@ -13,9 +13,11 @@
 #ifndef FC__CIVCLIENT_H
 #define FC__CIVCLIENT_H
 
+#include "shared.h"            /* MAX_LEN_NAME */
+
 #include "game.h"              /* enum client_states */
 #include "packets.h"           /* enum report_type */
-#include "shared.h"            /* MAX_LEN_NAME */
+#include "worklist.h"
 
 /*
  * Every TIMER_INTERVAL milliseconds real_timer_callback is
@@ -52,6 +54,8 @@
 extern bool turn_done_sent;
 extern bool in_ggz;
 
+extern struct worklist worklists[MAX_NUM_WORKLISTS];
+
 void wait_till_request_got_processed(int request_id);
 bool client_is_observer(void);
 void set_seconds_to_turndone(double seconds);
Index: client/options.c
===================================================================
--- client/options.c    (revision 11592)
+++ client/options.c    (working copy)
@@ -547,7 +547,7 @@
   if (game.player_ptr) {
     /* load global worklists */
     for (i = 0; i < MAX_NUM_WORKLISTS; i++) {
-      worklist_load(&sf, &(game.player_ptr->worklists[i]),
+      worklist_load(&sf, &worklists[i],
                    "worklists.worklist%d", i);
     }
   }
@@ -623,8 +623,8 @@
   /* insert global worklists */
   if (game.player_ptr) {
     for(i = 0; i < MAX_NUM_WORKLISTS; i++){
-      if (game.player_ptr->worklists[i].is_valid) {
-       worklist_save(&sf, &(game.player_ptr->worklists[i]),
+      if (worklists[i].is_valid) {
+       worklist_save(&sf, &worklists[i],
                      "worklists.worklist%d", i);
       }
     }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#15574) move worklists out of player structure, Jason Short <=