summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2OutObjArrayList.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
commitc0c336500955a23e344651e5412c9d9d441ef4ee (patch)
tree790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2OutObjArrayList.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to 'src/T2DLL/T2OutObjArrayList.cpp')
-rw-r--r--src/T2DLL/T2OutObjArrayList.cpp98
1 files changed, 89 insertions, 9 deletions
diff --git a/src/T2DLL/T2OutObjArrayList.cpp b/src/T2DLL/T2OutObjArrayList.cpp
index 3948561..bf1b3fd 100644
--- a/src/T2DLL/T2OutObjArrayList.cpp
+++ b/src/T2DLL/T2OutObjArrayList.cpp
@@ -1,34 +1,114 @@
+#include "T2Archive.h"
+#include "T2OutObjArray.h"
#include "T2OutObjArrayList.h"
-T2OutObjArrayList::T2OutObjArrayList() {
+T2OutObjArrayList::T2OutObjArrayList()
+ : LArray(sizeof(T2OutObjArray *))
+{
+ T2OutObjArray *theArray = new T2OutObjArray;
+ Add(theArray);
}
/*virtual*/ T2OutObjArrayList::~T2OutObjArrayList() {
+ LArrayIterator iterator(*this);
+ T2OutObjArray *theArray;
+
+ while (iterator.Next(&theArray))
+ delete theArray;
}
-void T2OutObjArrayList::Add(T2OutObjArray*) {
+void T2OutObjArrayList::Add(T2OutObjArray* inArray) {
+ InsertItemsAt(1, mItemCount + 1, &inArray);
}
-T2OutObjArray* T2OutObjArrayList::GetItemAt(int) {
+T2OutObjArray* T2OutObjArrayList::GetItemAt(int inIndex) {
+ T2OutObjArray *theArray;
+ if (FetchItemAt(inIndex, &theArray))
+ return theArray;
+ return NULL;
}
T2OutObj* T2OutObjArrayList::FindUnusedOutObj() {
+ LArrayIterator iterator(*this);
+ unsigned int lastStartID = 1;
+ T2OutObjArray *theArray;
+
+ while (iterator.Next(&theArray)) {
+ T2OutObj *theOutObj = theArray->FindUnusedOutObj();
+ if (theOutObj)
+ return theOutObj;
+
+ lastStartID = theArray->mStartID;
+ }
+
+ theArray = new T2OutObjArray(lastStartID + T2OutObjArray::kGroupSize);
+ if (theArray) {
+ Add(theArray);
+ return theArray->FindUnusedOutObj();
+ }
+
+ return NULL;
}
-void T2OutObjArrayList::DispatchIdle(T2TowerDoc*) {
+void T2OutObjArrayList::DispatchIdle(T2TowerDoc* inDoc) {
+ LArrayIterator iterator(*this);
+ T2OutObjArray *theArray;
+
+ while (iterator.Next(&theArray))
+ theArray->DispatchIdle(inDoc, 0);
}
-T2OutObj* T2OutObjArrayList::GetIndOutObj(unsigned int) {
+T2OutObj* T2OutObjArrayList::GetIndOutObj(unsigned int inIndex) {
+ int groupNum = inIndex / T2OutObjArray::kGroupSize;
+ int indexInGroup = inIndex % T2OutObjArray::kGroupSize;
+
+ T2OutObjArray *theArray = GetItemAt(groupNum + 1);
+ if (theArray)
+ return theArray->GetIndexOutObj(indexInGroup);
+ else
+ return NULL;
}
-T2OutObj* T2OutObjArrayList::GetOutObjByID(unsigned int) {
+T2OutObj* T2OutObjArrayList::GetOutObjByID(unsigned int inOutObjID) {
+ if (inOutObjID == 0)
+ return NULL;
+ else
+ return GetIndOutObj(inOutObjID - 1000);
}
-int T2OutObjArrayList::CalcMentenanceCost(T2TowerDoc*) const {
+int T2OutObjArrayList::CalcMentenanceCost(T2TowerDoc* inDoc) const {
+ int totalCost = 0;
+ LArrayIterator iterator(*this);
+ T2OutObjArray *theArray;
+
+ while (iterator.Next(&theArray))
+ totalCost += theArray->CalcMentenanceCost(inDoc);
+
+ return totalCost;
}
-void T2OutObjArrayList::Read(T2Archive&, T2TowerDoc*) {
+void T2OutObjArrayList::Read(T2Archive& inArchive, T2TowerDoc* inDoc) {
+ unsigned int groupCount;
+ inArchive >> groupCount;
+
+ RemoveItemsAt(GetCount(), 1);
+
+ unsigned int startID = 1000;
+ for (unsigned int i = 0; i < groupCount; i++) {
+ T2OutObjArray *theArray = new T2OutObjArray(startID);
+ theArray->Read(inArchive, inDoc);
+ Add(theArray);
+ startID += T2OutObjArray::kGroupSize;
+ }
}
-void T2OutObjArrayList::Write(T2Archive&) {
+void T2OutObjArrayList::Write(T2Archive& inArchive) {
+ unsigned int groupCount = GetCount();
+ inArchive << groupCount;
+
+ LArrayIterator iterator(*this);
+ T2OutObjArray *theArray;
+
+ while (iterator.Next(&theArray))
+ theArray->Write(inArchive);
}