Browse Source

Using the new pushGetIndex and pushConstructGetIndex List methods.

David Piuva 2 years ago
parent
commit
97c4990e36

+ 1 - 2
Source/DFPSR/gui/VisualTheme.cpp

@@ -298,8 +298,7 @@ public:
 	List<ClassSettings> settings;
 	int32_t getClassIndex(const ReadableString& className) {
 		for (int64_t i = 0; i < this->settings.length(); i++) { if (string_caseInsensitiveMatch(this->settings[i].className, className)) { return i; } }
-		settings.pushConstruct(className);
-		return settings.length() - 1;
+		return settings.pushConstructGetIndex(className);
 	}
 	VisualThemeImpl(const MediaMachine &machine, const ReadableString &styleSettings, const ReadableString &fromPath) : machine(machine) {
 		this->settings.pushConstruct(U"default");

+ 3 - 6
Source/DFPSR/render/model/Model.cpp

@@ -223,8 +223,7 @@ ModelImpl::ModelImpl(const ModelImpl &old) :
   positionBuffer(old.positionBuffer),
   partBuffer(old.partBuffer) {}
 int ModelImpl::addEmptyPart(const String& name) {
-	this->partBuffer.pushConstruct(name);
-	return this->partBuffer.length() - 1;
+	return this->partBuffer.pushConstructGetIndex(name);
 }
 int ModelImpl::getNumberOfParts() const {
 	return this->partBuffer.length();
@@ -277,8 +276,7 @@ void ModelImpl::setLightMapByName(ResourcePool &pool, const String &filename, in
 }
 int ModelImpl::addPolygon(Polygon polygon, int partIndex) {
 	CHECK_PART_INDEX(partIndex, return -1);
-	this->partBuffer[partIndex].polygonBuffer.push(polygon);
-	return this->partBuffer[partIndex].polygonBuffer.length() - 1;
+	return this->partBuffer[partIndex].polygonBuffer.pushGetIndex(polygon);
 }
 int ModelImpl::getNumberOfPolygons(int partIndex) const {
 	CHECK_PART_INDEX(partIndex, return -1);
@@ -321,9 +319,8 @@ void ModelImpl::setPoint(int pointIndex, const FVector3D& position) {
 	this->positionBuffer[pointIndex] = position;
 }
 int ModelImpl::addPoint(const FVector3D &position) {
-	this->positionBuffer.push(position);
 	this->expandBound(position);
-	return this->positionBuffer.length() - 1;
+	return this->positionBuffer.pushGetIndex(position);
 }
 int ModelImpl::addPointIfNeeded(const FVector3D &position, float threshold) {
 	int existingIndex = this->findPoint(position, threshold);

+ 1 - 2
Source/SDK/SpriteEngine/importer.cpp

@@ -242,8 +242,7 @@ static void loadPlyModel(Model& targetModel, int targetPart, const ReadableStrin
 					}
 				} else if (tokens.length() >= 3) {
 					if (string_caseInsensitiveMatch(tokens[0], U"ELEMENT")) {
-						elements.push(PlyElement(tokens[1], string_toInteger(tokens[2])));
-						elementIndex = elements.length() - 1;
+						elementIndex = elements.pushGetIndex(PlyElement(tokens[1], string_toInteger(tokens[2])));
 					} else if (string_caseInsensitiveMatch(tokens[0], U"PROPERTY")) {
 						if (elementIndex < 0) {
 							printText("loadPlyModel: Cannot declare a property without an element!\n");

+ 2 - 4
Source/SDK/SpriteEngine/spriteAPI.cpp

@@ -283,8 +283,7 @@ public:
 // Global list of all sprite types ever loaded
 List<SpriteType> spriteTypes;
 int spriteWorld_loadSpriteTypeFromFile(const String& folderPath, const String& spriteName) {
-	spriteTypes.pushConstruct(folderPath, spriteName);
-	return spriteTypes.length() - 1;
+	return spriteTypes.pushConstructGetIndex(folderPath, spriteName);
 }
 int spriteWorld_getSpriteTypeCount() {
 	return spriteTypes.length();
@@ -296,8 +295,7 @@ String spriteWorld_getSpriteTypeName(int index) {
 // Global list of all model types ever loaded
 List<ModelType> modelTypes;
 int spriteWorld_loadModelTypeFromFile(const String& folderPath, const String& visibleModelName, const String& shadowModelName) {
-	modelTypes.pushConstruct(folderPath, visibleModelName, shadowModelName);
-	return modelTypes.length() - 1;
+	return modelTypes.pushConstructGetIndex(folderPath, visibleModelName, shadowModelName);
 }
 int spriteWorld_getModelTypeCount() {
 	return modelTypes.length();

+ 1 - 2
Source/tools/wizard/sound.cpp

@@ -108,8 +108,7 @@ static int createEmptySoundBuffer(const ReadableString &name, bool fromFile, int
 	if (sampleCount < 1) { throwError("Cannot create sound buffer without and length!\n");}
 	if (channelCount < 1) { throwError("Cannot create sound buffer without any channels!\n");}
 	if (sampleRate < 1) { throwError("Cannot create sound buffer without any sample rate!\n");}
-	sounds.pushConstruct(name, fromFile, sampleCount, sampleRate, channelCount, soundFormat);
-	return sounds.length() - 1;
+	return sounds.pushConstructGetIndex(name, fromFile, sampleCount, sampleRate, channelCount, soundFormat);
 }
 int generateMonoSoundBuffer(const ReadableString &name, int sampleCount, int sampleRate, int soundFormat, std::function<double(double time)> generator) {
 	int result = createEmptySoundBuffer(name, false, sampleCount, sampleRate, 1, soundFormat);