[Freeciv-Dev] Re: (PR#6411) genlist cleanup
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Jason Short wrote:
> [per - Fri Oct 24 11:33:49 2003]:
>
>
>>On Wed, 22 Oct 2003, Jason Short wrote:
>>
>>>>>But gui-gtk at least doesn't compile with this; citydlg.c still uses
>>>>>genlist_iterator.
>>
>>See attached patch. This approach is faster than the gtk2 solution, but
>>perhaps not as pretty (gtk2 does a unit_list_get() on each unit, which is
>>a genlist search function).
>>
>>If this approach is fine, I'll do the same for the other clients that
>>have this code.
>
>
> This patch doesn't work.
>
> In isotrident view, it won't show more than 3 units total for either the
> supported or active units, in either the overview or units tab. I don't
> know why.
Looks like it was just a typo.
The attached patch is better, though I'm not sure it is completely working.
jason
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.172
diff -u -r1.172 citydlg.c
--- client/gui-gtk/citydlg.c 2003/08/06 07:22:44 1.172
+++ client/gui-gtk/citydlg.c 2003/10/27 20:18:41
@@ -2002,10 +2002,8 @@
*****************************************************************/
static void city_dialog_update_supported_units(struct city_dialog *pdialog)
{
- int i;
+ int i, j;
struct unit_list *plist;
- struct genlist_iterator myiter;
- struct unit *punit;
int size, mini_size;
char buf[30];
@@ -2040,13 +2038,15 @@
/* mini */
- genlist_iterator_init(&myiter, &(plist->list),
- pdialog->overview.supported_unit_pos *
- MINI_NUM_UNITS);
-
- for (i = 0; i < MINI_NUM_UNITS && ITERATOR_PTR(myiter);
- ITERATOR_NEXT(myiter), i++) {
- punit = (struct unit *) ITERATOR_PTR(myiter);
+ i = 0; /* number of displayed units */
+ j = 0; /* index into list */
+ unit_list_iterate(*plist, punit) {
+ if (j++ < pdialog->overview.supported_unit_pos * MINI_NUM_UNITS) {
+ continue;
+ }
+ if (i >= MINI_NUM_UNITS) {
+ break;
+ }
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->
overview.supported_unit_pixmaps[i]),
@@ -2080,8 +2080,10 @@
GINT_TO_POINTER(punit->id));
gtk_widget_set_sensitive(pdialog->overview.supported_unit_boxes[i],
TRUE);
- }
+ i++;
+ } unit_list_iterate_end;
+ /* Disable any empty slots */
for (; i < MINI_NUM_UNITS; i++) {
gtk_pixcomm_clear(GTK_PIXCOMM
(pdialog->overview.supported_unit_pixmaps[i]), TRUE);
@@ -2092,13 +2094,15 @@
/* normal */
- genlist_iterator_init(&myiter, &(plist->list),
- pdialog->unit.supported_unit_pos *
- NUM_UNITS_SHOWN);
-
- for (i = 0; i < NUM_UNITS_SHOWN && ITERATOR_PTR(myiter);
- ITERATOR_NEXT(myiter), i++) {
- punit = (struct unit *) ITERATOR_PTR(myiter);
+ i = 0; /* number of displayed units */
+ j = 0; /* index into list */
+ unit_list_iterate(*plist, punit) {
+ if (j++ < pdialog->overview.supported_unit_pos * MINI_NUM_UNITS) {
+ continue;
+ }
+ if (i >= MINI_NUM_UNITS) {
+ break;
+ }
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->unit.supported_unit_pixmaps[i]),
FALSE);
@@ -2126,7 +2130,8 @@
GTK_SIGNAL_FUNC(supported_unit_middle_callback),
GINT_TO_POINTER(punit->id));
gtk_widget_set_sensitive(pdialog->unit.supported_unit_boxes[i], TRUE);
- }
+ i++;
+ } unit_list_iterate_end;
for (; i < NUM_UNITS_SHOWN; i++) {
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->unit.supported_unit_pixmaps[i]),
@@ -2147,10 +2152,8 @@
*****************************************************************/
static void city_dialog_update_present_units(struct city_dialog *pdialog)
{
- int i;
+ int i, j;
struct unit_list *plist;
- struct genlist_iterator myiter;
- struct unit *punit;
int size, mini_size;
char buf[30];
@@ -2184,13 +2187,15 @@
/* mini */
- genlist_iterator_init(&myiter, &(plist->list),
- pdialog->overview.present_unit_pos *
- MINI_NUM_UNITS);
-
- for (i = 0; i < MINI_NUM_UNITS && ITERATOR_PTR(myiter);
- ITERATOR_NEXT(myiter), i++) {
- punit = (struct unit *) ITERATOR_PTR(myiter);
+ i = 0; /* number of displayed units */
+ j = 0; /* index into list */
+ unit_list_iterate(*plist, punit) {
+ if (j++ < pdialog->overview.present_unit_pos * MINI_NUM_UNITS) {
+ continue;
+ }
+ if (i >= MINI_NUM_UNITS) {
+ break;
+ }
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->overview.present_unit_pixmaps[i]),
FALSE);
@@ -2218,7 +2223,9 @@
GINT_TO_POINTER(punit->id));
gtk_widget_set_sensitive(pdialog->overview.present_unit_boxes[i],
TRUE);
- }
+ i++;
+ } unit_list_iterate_end;
+
for (; i < MINI_NUM_UNITS; i++) {
gtk_pixcomm_clear(GTK_PIXCOMM
(pdialog->overview.present_unit_pixmaps[i]), TRUE);
@@ -2229,14 +2236,16 @@
/* normal */
+ i = 0; /* number of displayed units */
+ j = 0; /* index into list */
+ unit_list_iterate(*plist, punit) {
+ if (j++ < pdialog->overview.present_unit_pos * MINI_NUM_UNITS) {
+ continue;
+ }
+ if (i >= MINI_NUM_UNITS) {
+ break;
+ }
- genlist_iterator_init(&myiter, &(plist->list),
- pdialog->unit.present_unit_pos * NUM_UNITS_SHOWN);
-
- for (i = 0; i < NUM_UNITS_SHOWN && ITERATOR_PTR(myiter);
- ITERATOR_NEXT(myiter), i++) {
- punit = (struct unit *) ITERATOR_PTR(myiter);
-
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->unit.present_unit_pixmaps[i]),
FALSE);
@@ -2259,7 +2268,9 @@
GTK_SIGNAL_FUNC(present_unit_middle_callback),
GINT_TO_POINTER(punit->id));
gtk_widget_set_sensitive(pdialog->unit.present_unit_boxes[i], TRUE);
- }
+ i++;
+ } unit_list_iterate_end;
+
for (; i < NUM_UNITS_SHOWN; i++) {
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->unit.present_unit_pixmaps[i]),
TRUE);
[Freeciv-Dev] (PR#6411) genlist cleanup, Jason Short, 2003/10/19
[Freeciv-Dev] (PR#6411) genlist cleanup, Jason Short, 2003/10/27
- Message not available
- [Freeciv-Dev] Re: (PR#6411) genlist cleanup,
Jason Short <=
|
|