Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] Re: (PR#14243) [PATCH] Scenario descriptions
Home

[Freeciv-Dev] Re: (PR#14243) [PATCH] Scenario descriptions

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: vasc@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#14243) [PATCH] Scenario descriptions
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 9 Oct 2005 15:50:56 -0700
Reply-to: bugs@xxxxxxxxxxx

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

But section_file_load is very expensive: probably well over half the 
work of fully loading the savegame.  Doing this for every scenario isn't 
good (even though right now all our scenarios are tiny).

This patch is, I think, much better.  The real solution would probably 
be a section_file_load_part where you could pass it "scenario" and it 
would only load the [scenario] section.

One thing this patch doesn't do is sorting.  Scenarios should be sorted 
by name I think.

-jason


? defend.diff
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.45
diff -p -u -r1.45 pages.c
--- client/gui-gtk-2.0/pages.c  9 Oct 2005 21:25:30 -0000       1.45
+++ client/gui-gtk-2.0/pages.c  9 Oct 2005 22:49:06 -0000
@@ -1543,26 +1543,32 @@ static void scenario_browse_callback(Gtk
 static void update_scenario_page(void)
 {
   struct datafile_list *files;
+  const char *scenario = "scenario";
 
   gtk_list_store_clear(scenario_store);
 
   /* search for scenario files. */
-  files = datafilelist_infix("scenario", ".sav", TRUE);
+  files = datafilelist_infix(scenario, ".sav", TRUE);
   datafile_list_iterate(files, pfile) {
     GtkTreeIter it;
     struct section_file sf;
-    char *description;
+    char *description = "", *name = pfile->name;
+    char desc_file[strlen(pfile->name) + 100], *desc_file_fullname;
 
-    if (section_file_load(&sf, pfile->fullname)) {
-      description = secfile_lookup_str_default(&sf, "", "game.description");
-    } else {
-      description = "";
+    my_snprintf(desc_file, sizeof(desc_file),
+               "%s/%s.sce", scenario, pfile->name);
+    desc_file_fullname = datafilename(desc_file);
+    if (desc_file_fullname) {
+      if (section_file_load(&sf, desc_file_fullname)) {
+       name = secfile_lookup_str(&sf, "scenario.name");
+       description = secfile_lookup_str(&sf, "scenario.description");
+       section_file_free(&sf);
+      }
     }
-    section_file_free(&sf);
 
     gtk_list_store_append(scenario_store, &it);
     gtk_list_store_set(scenario_store, &it,
-       0, pfile->name, 1, pfile->fullname, 2, description, -1);
+       0, name, 1, pfile->fullname, 2, description, -1);
 
     free(pfile->name);
     free(pfile->fullname);
Index: data/scenario/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/scenario/Makefile.am,v
retrieving revision 1.7
diff -p -u -r1.7 Makefile.am
--- data/scenario/Makefile.am   10 May 2005 02:25:27 -0000      1.7
+++ data/scenario/Makefile.am   9 Oct 2005 22:49:06 -0000
@@ -18,10 +18,19 @@ unzipped_files =                            \
        iberian-peninsula-136x100-v1.0.sav      \
        tutorial.sav
 
+sce_files =                                    \
+       british-isles-85x80-v2.80.sce           \
+       earth-160x90-v2.sce                     \
+       earth-80x50-v2.sce                      \
+       europe-200x100-v2.sce                   \
+       hagworld-120x60-v1.2.sce                \
+       iberian-peninsula-136x100-v1.0.sce      \
+       tutorial.sce
+
 
 ## Override automake so that "make install" puts these in proper place:
 pkgdatadir = $(datadir)/@PACKAGE@/scenario
-pkgdata_DATA = $(zipped_files)
+pkgdata_DATA = $(zipped_files) $(sce_files)
 
 $(zipped_files): %.sav.gz: %.sav
        $(GZIP) --best -c $< > $@
Index: data/scenario/british-isles-85x80-v2.80.sce
===================================================================
RCS file: data/scenario/british-isles-85x80-v2.80.sce
diff -N data/scenario/british-isles-85x80-v2.80.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/british-isles-85x80-v2.80.sce 9 Oct 2005 22:49:06 -0000
@@ -0,0 +1,3 @@
+[scenario]
+name="British Isles (medium/classic)"
+description="Classic-style 85x80 map of the British Isles."
Index: data/scenario/earth-160x90-v2.sce
===================================================================
RCS file: data/scenario/earth-160x90-v2.sce
diff -N data/scenario/earth-160x90-v2.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/earth-160x90-v2.sce   9 Oct 2005 22:49:06 -0000
@@ -0,0 +1,3 @@
+[scenario]
+name="Earth (classic, large)"
+description="Classic-style 160x90 Earth scenario."
Index: data/scenario/earth-80x50-v2.sce
===================================================================
RCS file: data/scenario/earth-80x50-v2.sce
diff -N data/scenario/earth-80x50-v2.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/earth-80x50-v2.sce    9 Oct 2005 22:49:06 -0000
@@ -0,0 +1,3 @@
+[scenario]
+name="Earth (classic, small)"
+description="Classic-style 80x50 Earth scenario."
Index: data/scenario/europe-200x100-v2.sce
===================================================================
RCS file: data/scenario/europe-200x100-v2.sce
diff -N data/scenario/europe-200x100-v2.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/europe-200x100-v2.sce 9 Oct 2005 22:49:06 -0000
@@ -0,0 +1,3 @@
+[scenario]
+name="Europe (giant/classic)"
+description="Very large classic-style map of Europe."
Index: data/scenario/hagworld-120x60-v1.2.sce
===================================================================
RCS file: data/scenario/hagworld-120x60-v1.2.sce
diff -N data/scenario/hagworld-120x60-v1.2.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/hagworld-120x60-v1.2.sce      9 Oct 2005 22:49:06 -0000
@@ -0,0 +1,3 @@
+[scenario]
+name="Earth (classic, medium)"
+description="Classic-style 120x60 Earth scenario."
Index: data/scenario/iberian-peninsula-136x100-v1.0.sce
===================================================================
RCS file: data/scenario/iberian-peninsula-136x100-v1.0.sce
diff -N data/scenario/iberian-peninsula-136x100-v1.0.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/iberian-peninsula-136x100-v1.0.sce    9 Oct 2005 22:49:06 
-0000
@@ -0,0 +1,3 @@
+[scenario]
+name="Iberian Peninsula (classic/large)"
+description="Large classic-style map of the Iberian Peninsula (modern-day 
Spain and Portugal)."
Index: data/scenario/tutorial.sav
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/scenario/tutorial.sav,v
retrieving revision 1.5
diff -p -u -r1.5 tutorial.sav
--- data/scenario/tutorial.sav  9 Oct 2005 21:25:31 -0000       1.5
+++ data/scenario/tutorial.sav  9 Oct 2005 22:49:07 -0000
@@ -450,7 +450,6 @@ dispersion=0
 randseed=0
 save_random=0
 rulesetdir="default"
-description="Tutorial Scenario."
 
 [savefile]
 options="startoptions spacerace2 rulesets diplchance_percent worklists2 
map_editor known32fix turn attributes watchtower rulesetdir client_worklists 
orders startunits turn_last_built improvement_order technology_order embassies"
Index: data/scenario/tutorial.sce
===================================================================
RCS file: data/scenario/tutorial.sce
diff -N data/scenario/tutorial.sce
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/scenario/tutorial.sce  9 Oct 2005 22:49:07 -0000
@@ -0,0 +1,3 @@
+[scenario]
+name="Tutorial"
+description="Tutorial Scenario."

[Prev in Thread] Current Thread [Next in Thread]