project_files/frontlib/model/weapon.c
changeset 7497 7e1d72fc03c7
parent 7320 e704706008d4
child 8132 f68b43cf510f
child 10017 de822cd3df3a
--- a/project_files/frontlib/model/weapon.c	Sun Aug 12 23:51:36 2012 +0200
+++ b/project_files/frontlib/model/weapon.c	Wed Aug 15 23:40:10 2012 +0200
@@ -22,20 +22,12 @@
 #include "../util/inihelper.h"
 #include "../util/logging.h"
 #include "../util/util.h"
-#include "../util/refcounter.h"
 #include "../util/list.h"
 
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 
-static void flib_weaponset_destroy(flib_weaponset *cfg) {
-	if(cfg) {
-		free(cfg->name);
-		free(cfg);
-	}
-}
-
 static void setField(char field[WEAPONS_COUNT+1], const char *line, int lineLen, bool no9) {
 	if(lineLen>WEAPONS_COUNT) {
 		lineLen = WEAPONS_COUNT;
@@ -60,7 +52,7 @@
 flib_weaponset *flib_weaponset_create(const char *name) {
 	flib_weaponset *result = NULL;
 	if(!log_badargs_if(name==NULL)) {
-		flib_weaponset *newSet = flib_weaponset_retain(flib_calloc(1, sizeof(flib_weaponset)));
+		flib_weaponset *newSet = flib_calloc(1, sizeof(flib_weaponset));
 		if(newSet) {
 			newSet->name = flib_strdupnull(name);
 			if(newSet->name) {
@@ -68,24 +60,19 @@
 				setField(newSet->crateprob, "", 0, false);
 				setField(newSet->crateammo, "", 0, false);
 				setField(newSet->delay, "", 0, false);
-				result = flib_weaponset_retain(newSet);
+				result = newSet;
+				newSet = NULL;
 			}
 		}
-		flib_weaponset_release(newSet);
+		flib_weaponset_destroy(newSet);
 	}
 	return result;
 }
 
-flib_weaponset *flib_weaponset_retain(flib_weaponset *weaponset) {
-	if(weaponset) {
-		flib_retain(&weaponset->_referenceCount, "flib_weaponset");
-	}
-	return weaponset;
-}
-
-void flib_weaponset_release(flib_weaponset *weaponset) {
-	if(weaponset && flib_release(&weaponset->_referenceCount, "flib_weaponset")) {
-		flib_weaponset_destroy(weaponset);
+void flib_weaponset_destroy(flib_weaponset *cfg) {
+	if(cfg) {
+		free(cfg->name);
+		free(cfg);
 	}
 }
 
@@ -108,7 +95,7 @@
 void flib_weaponsetlist_destroy(flib_weaponsetlist *list) {
 	if(list) {
 		for(int i=0; i<list->weaponsetCount; i++) {
-			flib_weaponset_release(list->weaponsets[i]);
+			flib_weaponset_destroy(list->weaponsets[i]);
 		}
 		free(list->weaponsets);
 		free(list);
@@ -139,8 +126,10 @@
 		flib_weaponset *set = flib_weaponset_from_ammostring(decodedKeyname, ammostring);
 		if(set) {
 			result = flib_weaponsetlist_insert(list, set, list->weaponsetCount);
+			if(result) {
+				flib_weaponset_destroy(set);
+			}
 		}
-		flib_weaponset_release(set);
 	}
 	free(ammostring);
 	free(decodedKeyname);
@@ -228,7 +217,6 @@
 int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *set, int pos) {
 	if(!log_badargs_if2(list==NULL, set==NULL)
 			&& !insertWeaponset(&list->weaponsets, &list->weaponsetCount, set, pos)) {
-		flib_weaponset_retain(set);
 		return 0;
 	}
 	return -1;
@@ -238,7 +226,7 @@
 	if(!log_badargs_if(list==NULL)) {
 		flib_weaponset *elem = list->weaponsets[pos];
 		if(!deleteWeaponset(&list->weaponsets, &list->weaponsetCount, pos)) {
-			flib_weaponset_release(elem);
+			flib_weaponset_destroy(elem);
 			return 0;
 		}
 	}