Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11116) remove dealloc_id from the client
Home

[Freeciv-Dev] (PR#11116) remove dealloc_id from the client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11116) remove dealloc_id from the client
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 20 Nov 2004 17:15:08 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11116 >

There is a server function dealloc_id called in the common code.  To 
facilitate this is_server is checked and the client has a dummy function.

This patch replaces that hack with a different hack.  Instead a callback 
function pointer is stored in the game structure.  This isn't 
particularly prettier or less bug-prone but it is more flexible.  It 
doesn't rely on the is_server variable which doesn't extend well to (for 
instance) civworld.

In the long term there should be a whole module of functions registered 
for unit allocation and deallocation.  That way at least we would have 
balance.  Or maybe there is a better way...

jason

Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.204
diff -u -r1.204 civclient.c
--- client/civclient.c  19 Nov 2004 01:31:48 -0000      1.204
+++ client/civclient.c  21 Nov 2004 01:11:21 -0000
@@ -558,9 +558,6 @@
   }
 }
 
-void dealloc_id(int id); /* double kludge (suppress a possible warning) */
-void dealloc_id(int id) { }/* kludge */
-
 /**************************************************************************
 ..
 **************************************************************************/
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.190
diff -u -r1.190 game.c
--- common/game.c       13 Nov 2004 08:34:17 -0000      1.190
+++ common/game.c       21 Nov 2004 01:11:22 -0000
@@ -38,7 +38,6 @@
 
 #include "game.h"
 
-void dealloc_id(int id);
 struct civ_game game;
 
 /*
@@ -158,8 +157,8 @@
 
   idex_unregister_unit(punit);
 
-  if (is_server) {
-    dealloc_id(punit->id);
+  if (game.callbacks.unit_deallocate) {
+    (game.callbacks.unit_deallocate)(punit->id);
   }
   destroy_unit_virtual(punit);
 }
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.156
diff -u -r1.156 game.h
--- common/game.h       20 Nov 2004 18:08:42 -0000      1.156
+++ common/game.h       21 Nov 2004 01:11:22 -0000
@@ -245,6 +245,11 @@
   int work_veteran_chance[MAX_VET_LEVELS];
   int veteran_chance[MAX_VET_LEVELS];
   int revolution_length; /* 0=> random length, else the fixated length */
+
+  struct {
+    /* Function to be called in game_remove_unit when a unit is deleted. */
+    void (*unit_deallocate)(int unit_id);
+  } callbacks;
 };
 
 /* Unused? */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.209
diff -u -r1.209 srv_main.c
--- server/srv_main.c   16 Nov 2004 18:09:47 -0000      1.209
+++ server/srv_main.c   21 Nov 2004 01:11:22 -0000
@@ -204,6 +204,9 @@
   /* init character encodings. */
   init_character_encodings(FC_DEFAULT_DATA_ENCODING);
 
+  /* Initialize callbacks. */
+  game.callbacks.unit_deallocate = dealloc_id;
+
   /* done */
   return;
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11116) remove dealloc_id from the client, Jason Short <=