diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2RequestArrayList.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to 'src/T2DLL/T2RequestArrayList.cpp')
-rw-r--r-- | src/T2DLL/T2RequestArrayList.cpp | 97 |
1 files changed, 89 insertions, 8 deletions
diff --git a/src/T2DLL/T2RequestArrayList.cpp b/src/T2DLL/T2RequestArrayList.cpp index 1bc4a9b..0b5acbb 100644 --- a/src/T2DLL/T2RequestArrayList.cpp +++ b/src/T2DLL/T2RequestArrayList.cpp @@ -1,34 +1,115 @@ +#include "T2Archive.h" +#include "T2RequestArray.h" #include "T2RequestArrayList.h" -T2RequestArrayList::T2RequestArrayList() { +T2RequestArrayList::T2RequestArrayList() + : LArray(sizeof(T2RequestArray *)) +{ + T2RequestArray *requestArray = new T2RequestArray(1000); + Add(requestArray); } /*virtual*/ T2RequestArrayList::~T2RequestArrayList() { + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + delete requestArray; } -void T2RequestArrayList::Add(T2RequestArray*) { +void T2RequestArrayList::Add(T2RequestArray* requestArray) { + InsertItemsAt(1, mItemCount + 1, &requestArray); } unsigned int T2RequestArrayList::GetItemCount() { + return GetCount(); } -T2RequestArray* T2RequestArrayList::GetItemAt(int) { +T2RequestArray* T2RequestArrayList::GetItemAt(int index) { + T2RequestArray *requestArray; + if (FetchItemAt(index, &requestArray)) + return requestArray; + else + return NULL; } -T2Request* T2RequestArrayList::GetRequestByID(unsigned int) { +T2Request* T2RequestArrayList::GetRequestByID(unsigned int requestID) { + if (requestID == 0) + return NULL; + if (requestID < 1000) + return NULL; + + int group = (requestID - 1000) / 64; + int indexInGroup = (requestID - 1000) % 64; + T2RequestArray *requestArray = GetItemAt(group + 1); + if (requestArray) + return requestArray->GetIndexRequest(indexInGroup); + else + return NULL; } T2Request* T2RequestArrayList::FindUnusedRequest() { + T2Request *result = NULL; + LArrayIterator iterator(*this); + T2RequestArray *requestArray = NULL; + + while (!result && iterator.Next(&requestArray)) { + result = requestArray->FindUnusedRequest(); + } + + if (!result) { + unsigned int newStartID = 1000; + if (requestArray) + newStartID = requestArray->GetStartID() + 64; + + requestArray = new T2RequestArray(newStartID); + if (requestArray) { + Add(requestArray); + result = requestArray->FindUnusedRequest(); + } + } + + return result; } -void T2RequestArrayList::BreakoutEmergency(T2TowerDoc*) { +void T2RequestArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + requestArray->BreakoutEmergency(towerDoc); } -void T2RequestArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2RequestArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + int count; + archive >> count; + + RemoveItemsAt(GetCount(), 1); + unsigned int startID = 1000; + + for (int i = 0; i < count; i++) { + T2RequestArray *requestArray = new T2RequestArray(startID); + requestArray->Read(archive, towerDoc); + Add(requestArray); + startID += 64; + } } -void T2RequestArrayList::Write(T2Archive&) { +void T2RequestArrayList::Write(T2Archive& archive) { + int count = GetItemCount(); + archive << count; + + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + requestArray->Write(archive); } -void T2RequestArrayList::DispatchIdle(T2TowerDoc*) { +void T2RequestArrayList::DispatchIdle(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + requestArray->DispatchIdle(towerDoc, 0); } |