Sfoglia il codice sorgente

A minor memory improvement, and some curly brace love.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@16008 54d463be-8e91-2dee-dedb-b68131a5f0ec
shennetsind 13 anni fa
parent
commit
2f177fa207
3 ha cambiato i file con 18 aggiunte e 18 eliminazioni
  1. 12 9
      src/map/map.c
  2. 1 0
      src/map/map.h
  3. 5 9
      src/map/npc.c

+ 12 - 9
src/map/map.c

@@ -1302,19 +1302,17 @@ int map_get_new_object_id(void)
 
 	// find a free id
 	i = last_object_id + 1;
-	while( i != last_object_id )
-	{
+	while( i != last_object_id ) {
 		if( i == MAX_FLOORITEM )
 			i = MIN_FLOORITEM;
 
-		if( idb_get(id_db, i) == NULL )
+		if( !idb_exists(id_db, i) )
 			break;
 
 		++i;
 	}
 
-	if( i == last_object_id )
-	{
+	if( i == last_object_id ) {
 		ShowError("map_addobject: no free object id!\n");
 		return 0;
 	}
@@ -1892,14 +1890,19 @@ struct map_session_data * map_nick2sd(const char *nick)
 }
 
 /*==========================================
- * id番?の物を探す
- * 一三bjectの場合は配列を引くのみ
+ * Looksup id_db DBMap and returns BL pointer of 'id' or NULL if not found
  *------------------------------------------*/
-struct block_list * map_id2bl(int id)
-{
+struct block_list * map_id2bl(int id) {
 	return (struct block_list*)idb_get(id_db,id);
 }
 
+/**
+ * Same as map_id2bl except it only checks for its existence
+ **/
+bool map_blid_exists( int id ) {
+	return (idb_exists(id_db,id));
+}
+
 /*==========================================
  * Convext Mirror
  *------------------------------------------*/

+ 1 - 0
src/map/map.h

@@ -660,6 +660,7 @@ struct homun_data* map_id2hd(int id);
 struct mercenary_data* map_id2mc(int id);
 struct chat_data* map_id2cd(int id);
 struct block_list * map_id2bl(int id);
+bool map_blid_exists( int id );
 
 #define map_id2index(id) map[(id)].index
 int map_mapindex2mapid(unsigned short mapindex);

+ 5 - 9
src/map/npc.c

@@ -55,17 +55,15 @@ static int npc_cache_mob=0;
 
 /// Returns a new npc id that isn't being used in id_db.
 /// Fatal error if nothing is available.
-int npc_get_new_npc_id(void)
-{
-	if( npc_id >= START_NPC_NUM && map_id2bl(npc_id) == NULL )
+int npc_get_new_npc_id(void) {
+	if( npc_id >= START_NPC_NUM && !map_blid_exists(npc_id) )
 		return npc_id++;// available
-	{// find next id
+	else {// find next id
 		int base_id = npc_id;
-		while( base_id != ++npc_id )
-		{
+		while( base_id != ++npc_id ) {
 			if( npc_id < START_NPC_NUM )
 				npc_id = START_NPC_NUM;
-			if( map_id2bl(npc_id) == NULL )
+			if( !map_blid_exists(npc_id) )
 				return npc_id++;// available
 		}
 		// full loop, nothing available
@@ -3578,7 +3576,6 @@ int do_init_npc(void)
 	npcname_db = strdb_alloc(DB_OPT_BASE,NAME_LENGTH);
 
 	timer_event_ers = ers_new(sizeof(struct timer_event_data));
-
 	// process all npc files
 	ShowStatus("Loading NPCs...\r");
 	for( file = npc_src_files; file != NULL; file = file->next )
@@ -3586,7 +3583,6 @@ int do_init_npc(void)
 		ShowStatus("Loading NPC file: %s"CL_CLL"\r", file->name);
 		npc_parsesrcfile(file->name);
 	}
-
 	ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n"
 		"\t-'"CL_WHITE"%d"CL_RESET"' Warps\n"
 		"\t-'"CL_WHITE"%d"CL_RESET"' Shops\n"