<commit_before>
#include "stdafx.h"
#include "objlist.h"

static struct ObjListAddresses : AddressTable {
	void(__cdecl *ObjListTile)(locXY loc, int flags, ObjListResult &result);
	void(__cdecl *ObjListVicinity)(locXY loc, int flags, ObjListResult &result);
	void(__cdecl *ObjListRadius)(LocAndOffsets loc, float radius, float unk1, float unk2, int flags, ObjListResult &result);
	void(__cdecl *ObjListFollowers)(objHndl critter, ObjListResult &result);
	void(__cdecl *ObjListFree)(ObjListResult &result);

	ObjListAddresses() {
		rebase(ObjListTile, 0x1001E970);
		rebase(ObjListVicinity, 0x1001F1C0);
		rebase(ObjListRadius, 0x10022E50);
		rebase(ObjListFollowers, 0x1001F450);
		rebase(ObjListFree, 0x1001F2C0);
	}
} addresses;

ObjList::ObjList() {
	FreeResult();
}

ObjList::~ObjList() {
	FreeResult();
}

void ObjList::ListTile(locXY loc, int flags) {
	FreeResult();
	addresses.ObjListTile(loc, flags, mResult);
}

void ObjList::ListVicinity(locXY loc, int flags) {
	FreeResult();
	addresses.ObjListVicinity(loc, flags, mResult);
}

void ObjList::ListRadius(LocAndOffsets loc, float radius, int flags) {
	FreeResult();
	addresses.ObjListRadius(loc, radius, 0.0f, (float)(M_PI * 2), flags, mResult);
}

void ObjList::ListCone(LocAndOffsets loc, float radius, float coneStartAngleRad, float coneArcRad, int flags) {
	FreeResult();
	addresses.ObjListRadius(loc, radius, coneStartAngleRad, coneArcRad, flags, mResult);
}

void ObjList::ListFollowers(objHndl critter) {
	FreeResult();
	addresses.ObjListFollowers(critter, mResult);
}

int ObjList::size() {
	if (mSizeValid) {
		return mSize;
	}
	mSize = CountObjects();
	mSizeValid = true;
	return mSize;
}

int ObjList::CountObjects() const {
	if (!mResult.objects) {
		return 0;
	}
	auto item = mResult.objects;
	auto result = 0;
	while (item) {
		result++;
		item = item->next;
	}
	return result;
}

void ObjList::FreeResult() {
	if (mHasToFree) {
		addresses.ObjListFree(mResult);
	}
	mSizeValid = false;
	mSize = 0;
	mHasToFree = false;
}
<commit_msg>Fixes #98. We weren't freeing object lists after using them which apparently caused destroyed objects to not be permanently destroyed in the savegame for whatever reason.<commit_after>
#include "stdafx.h"
#include "objlist.h"

static struct ObjListAddresses : AddressTable {
	void(__cdecl *ObjListTile)(locXY loc, int flags, ObjListResult &result);
	void(__cdecl *ObjListVicinity)(locXY loc, int flags, ObjListResult &result);
	void(__cdecl *ObjListRadius)(LocAndOffsets loc, float radius, float unk1, float unk2, int flags, ObjListResult &result);
	void(__cdecl *ObjListFollowers)(objHndl critter, ObjListResult &result);
	void(__cdecl *ObjListFree)(ObjListResult &result);

	ObjListAddresses() {
		rebase(ObjListTile, 0x1001E970);
		rebase(ObjListVicinity, 0x1001F1C0);
		rebase(ObjListRadius, 0x10022E50);
		rebase(ObjListFollowers, 0x1001F450);
		rebase(ObjListFree, 0x1001F2C0);
	}
} addresses;

ObjList::ObjList() {
	FreeResult();
}

ObjList::~ObjList() {
	FreeResult();
}

void ObjList::ListTile(locXY loc, int flags) {
	FreeResult();
	addresses.ObjListTile(loc, flags, mResult);
	mHasToFree = true;
}

void ObjList::ListVicinity(locXY loc, int flags) {
	FreeResult();
	addresses.ObjListVicinity(loc, flags, mResult);
	mHasToFree = true;
}

void ObjList::ListRadius(LocAndOffsets loc, float radius, int flags) {
	FreeResult();
	addresses.ObjListRadius(loc, radius, 0.0f, (float)(M_PI * 2), flags, mResult);
	mHasToFree = true;
}

void ObjList::ListCone(LocAndOffsets loc, float radius, float coneStartAngleRad, float coneArcRad, int flags) {
	FreeResult();
	addresses.ObjListRadius(loc, radius, coneStartAngleRad, coneArcRad, flags, mResult);
	mHasToFree = true;
}

void ObjList::ListFollowers(objHndl critter) {
	FreeResult();
	addresses.ObjListFollowers(critter, mResult);
	mHasToFree = true;
}

int ObjList::size() {
	if (mSizeValid) {
		return mSize;
	}
	mSize = CountObjects();
	mSizeValid = true;
	return mSize;
}

int ObjList::CountObjects() const {
	if (!mResult.objects) {
		return 0;
	}
	auto item = mResult.objects;
	auto result = 0;
	while (item) {
		result++;
		item = item->next;
	}
	return result;
}

void ObjList::FreeResult() {
	if (mHasToFree) {
		addresses.ObjListFree(mResult);
	}
	mSizeValid = false;
	mSize = 0;
	mHasToFree = false;
}

{'fraction_non_alphanumeric': 0.127370639194568, 'fraction_numerical': 0.022008897213767267, 'mean_word_length': 5.980392156862745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5745646', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1588, 'n_words': 355}