Sfoglia il codice sorgente

Do not use non-portable stuff

Daniele Bartolini 8 anni fa
parent
commit
9ec85a02d3
2 ha cambiato i file con 13 aggiunte e 24 eliminazioni
  1. 2 8
      tools/core/json/sjson.vala
  2. 11 16
      tools/level_editor/level_editor.vala

+ 2 - 8
tools/core/json/sjson.vala

@@ -10,7 +10,6 @@
 
 using Gee;
 using GLib;
-using Posix;
 
 namespace Crown
 {
@@ -86,15 +85,10 @@ namespace Crown
 		   write_object_fields(t, builder, 0);
 		}
 
-		static int cmpfn_key(ref string a, ref string b)
-		{
-			return Posix.strcmp(a, b);
-		}
-
 		static void write_object_fields(Hashtable t, StringBuilder builder, int indentation)
 		{
-			string[] keys = t.keys.to_array();
-			Posix.qsort(keys, keys.length, sizeof(string), (Posix.compar_fn_t)cmpfn_key);
+			ArrayList<string> keys = new ArrayList<string>.wrap(t.keys.to_array());
+			keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
 			foreach (string key in keys) {
 				write_new_line(builder, indentation);
 				builder.append(key);

+ 11 - 16
tools/level_editor/level_editor.vala

@@ -424,11 +424,6 @@ namespace Crown
 			_project.delete_level_editor_test_level();
 		}
 
-		private static int stringcmp(ref string a, ref string b)
-		{
-			return Posix.strcmp(a, b);
-		}
-
 		private void on_message_received(ConsoleClient client, uint8[] json)
 		{
 			try
@@ -508,15 +503,15 @@ namespace Crown
 					Hashtable new_rotations = (Hashtable)msg["new_rotations"];
 					Hashtable new_scales    = (Hashtable)msg["new_scales"];
 
-					string[] keys = ids.keys.to_array();
-					Posix.qsort(keys, keys.length, sizeof(string), (Posix.compar_fn_t)stringcmp);
+					ArrayList<string> keys = new ArrayList<string>.wrap(ids.keys.to_array());
+					keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
 
-					Guid[] n_ids             = new Guid[keys.length];
-					Vector3[] n_positions    = new Vector3[keys.length];
-					Quaternion[] n_rotations = new Quaternion[keys.length];
-					Vector3[] n_scales       = new Vector3[keys.length];
+					Guid[] n_ids             = new Guid[keys.size];
+					Vector3[] n_positions    = new Vector3[keys.size];
+					Quaternion[] n_rotations = new Quaternion[keys.size];
+					Vector3[] n_scales       = new Vector3[keys.size];
 
-					for (int i = 0; i < keys.length; ++i)
+					for (int i = 0; i < keys.size; ++i)
 					{
 						string k = keys[i];
 
@@ -532,12 +527,12 @@ namespace Crown
 				{
 					Hashtable objects = (Hashtable)msg["objects"];
 
-					string[] keys = objects.keys.to_array();
-					Posix.qsort(keys, keys.length, sizeof(string), (Posix.compar_fn_t)stringcmp);
+					ArrayList<string> keys = new ArrayList<string>.wrap(objects.keys.to_array());
+					keys.sort(Gee.Functions.get_compare_func_for(typeof(string)));
 
-					Guid[] ids = new Guid[keys.length];
+					Guid[] ids = new Guid[keys.size];
 
-					for (int i = 0; i < keys.length; ++i)
+					for (int i = 0; i < keys.size; ++i)
 					{
 						string k = keys[i];
 						ids[i] = Guid.parse((string)objects[k]);