diff --git a/src/Chain.cpp b/src/Chain.cpp index 084fba3f..b3d50a56 100644 --- a/src/Chain.cpp +++ b/src/Chain.cpp @@ -7,12 +7,6 @@ namespace th06 { DIFFABLE_STATIC(Chain, g_Chain) -Chain::Chain() -{ - midiOutputDeviceCount = midiOutGetNumDevs(); - unk = 0; -} - Chain::~Chain() { } @@ -44,157 +38,118 @@ ChainElem::~ChainElem() deletedCallback = NULL; } -ChainElem *Chain::CreateElem(ChainCallback callback) +Chain::Chain() { - ChainElem *elem; - - elem = new ChainElem(); - - elem->callback = callback; - elem->addedCallback = NULL; - elem->deletedCallback = NULL; - - elem->isHeapAllocated = true; - - return elem; + midiOutputDeviceCount = midiOutGetNumDevs(); + unk = 0; } -void Chain::ReleaseSingleChain(ChainElem *root) +int Chain::AddToCalcChain(ChainElem *elem, int priority) { - // NOTE: Those names are like this to get perfect stack frame matching - // TODO: Give meaningfull names that still match. - ChainElem a0; - ChainElem *current; - ChainElem *tmp; - ChainElem *wasNext; + ChainElem *cur; - tmp = new ChainElem(); - a0.next = tmp; + cur = &this->calcChain; + utils::DebugPrint2("add calc chain (pri = %d)\n", priority); + elem->priority = priority; - current = root; - while (current != NULL) + while (cur->next != NULL) { - tmp->unkPtr = current; - tmp->next = new ChainElem(); - tmp = tmp->next; - current = current->next; + if (cur->priority > priority) + { + break; + } + + cur = cur->next; } - current = &a0; - while (current != NULL) + if (cur->priority > priority) { - Cut(current->unkPtr); - current = current->next; - } + elem->next = cur; + elem->prev = cur->prev; - tmp = a0.next; + if (elem->prev != NULL) + { + elem->prev->next = elem; + } - while (tmp != NULL) + cur->prev = elem; + } + else { - wasNext = tmp->next; + elem->next = NULL; + elem->prev = cur; + cur->next = elem; + } - delete tmp; + if (elem->addedCallback != NULL) + { + int res = elem->addedCallback(elem->arg); + elem->addedCallback = NULL; - tmp = NULL; - tmp = wasNext; + return res; + } + else + { + return 0; } } -void Chain::Release(void) -{ - ReleaseSingleChain(&this->calcChain); - ReleaseSingleChain(&this->drawChain); -} - -void Chain::Cut(ChainElem *to_remove) +int Chain::AddToDrawChain(ChainElem *elem, int priority) { - int isDrawChain; - ChainElem *tmp; - - isDrawChain = 0; - - if (to_remove == NULL) - { - return; - } + ChainElem *cur; - tmp = &this->calcChain; + cur = &this->drawChain; + utils::DebugPrint2("add draw chain (pri = %d)\n", priority); + elem->priority = priority; - while (tmp != NULL) + while (cur->next != NULL) { - if (tmp == to_remove) + if (cur->priority > priority) { - goto destroy_elem; + break; } - tmp = tmp->next; + cur = cur->next; } + if (cur->priority > priority) { - isDrawChain = 1; + elem->next = cur; + elem->prev = cur->prev; - tmp = &this->drawChain; - while (tmp != NULL) + if (elem->prev != NULL) { - if (tmp == to_remove) - { - goto destroy_elem; - } - - tmp = tmp->next; + elem->prev->next = elem; } - } - return; - -destroy_elem: - if (!isDrawChain) - { - utils::DebugPrint2("calc cut Chain (Pri = %d)\n", to_remove->priority); + cur->prev = elem; } else { - utils::DebugPrint2("draw cut Chain (Pri = %d)\n", to_remove->priority); + elem->next = NULL; + elem->prev = cur; + cur->next = elem; } - if (to_remove->prev != NULL) + if (elem->addedCallback != NULL) { - to_remove->callback = NULL; - to_remove->prev->next = to_remove->next; - - if (to_remove->next != NULL) - { - to_remove->next->prev = to_remove->prev; - } - - to_remove->prev = NULL; - to_remove->next = NULL; - - if (to_remove->isHeapAllocated) - { - delete to_remove; - to_remove = NULL; - } - else - { - if (to_remove->deletedCallback != NULL) - { - ChainDeletedCallback callback = to_remove->deletedCallback; - to_remove->deletedCallback = NULL; - callback(to_remove->arg); - } - } + return elem->addedCallback(elem->arg); + } + else + { + return 0; } } -int Chain::RunDrawChain(void) +int Chain::RunCalcChain(void) { ChainElem *tmp1; ChainElem *current; int updatedCount; +restart_from_first_job: updatedCount = 0; - current = &this->drawChain; + current = &this->calcChain; while (current != NULL) { @@ -223,6 +178,9 @@ int Chain::RunDrawChain(void) case CHAIN_CALLBACK_RESULT_EXIT_GAME_ERROR: return -1; + case CHAIN_CALLBACK_RESULT_RESTART_FROM_FIRST_JOB: + goto restart_from_first_job; + default: break; } @@ -236,15 +194,14 @@ int Chain::RunDrawChain(void) return updatedCount; } -int Chain::RunCalcChain(void) +int Chain::RunDrawChain(void) { ChainElem *tmp1; ChainElem *current; int updatedCount; -restart_from_first_job: updatedCount = 0; - current = &this->calcChain; + current = &this->drawChain; while (current != NULL) { @@ -273,9 +230,6 @@ int Chain::RunCalcChain(void) case CHAIN_CALLBACK_RESULT_EXIT_GAME_ERROR: return -1; - case CHAIN_CALLBACK_RESULT_RESTART_FROM_FIRST_JOB: - goto restart_from_first_job; - default: break; } @@ -289,100 +243,146 @@ int Chain::RunCalcChain(void) return updatedCount; } -int Chain::AddToCalcChain(ChainElem *elem, int priority) +void Chain::ReleaseSingleChain(ChainElem *root) { - ChainElem *cur; + // NOTE: Those names are like this to get perfect stack frame matching + // TODO: Give meaningfull names that still match. + ChainElem a0; + ChainElem *current; + ChainElem *tmp; + ChainElem *wasNext; - cur = &this->calcChain; - utils::DebugPrint2("add calc chain (pri = %d)\n", priority); - elem->priority = priority; + tmp = new ChainElem(); + a0.next = tmp; - while (cur->next != NULL) + current = root; + while (current != NULL) { - if (cur->priority > priority) - { - break; - } - - cur = cur->next; + tmp->unkPtr = current; + tmp->next = new ChainElem(); + tmp = tmp->next; + current = current->next; } - if (cur->priority > priority) + current = &a0; + while (current != NULL) { - elem->next = cur; - elem->prev = cur->prev; + Cut(current->unkPtr); + current = current->next; + } - if (elem->prev != NULL) - { - elem->prev->next = elem; - } + tmp = a0.next; - cur->prev = elem; - } - else + while (tmp != NULL) { - elem->next = NULL; - elem->prev = cur; - cur->next = elem; - } + wasNext = tmp->next; - if (elem->addedCallback != NULL) - { - int res = elem->addedCallback(elem->arg); - elem->addedCallback = NULL; + delete tmp; - return res; - } - else - { - return 0; + tmp = NULL; + tmp = wasNext; } } -int Chain::AddToDrawChain(ChainElem *elem, int priority) +void Chain::Release(void) { - ChainElem *cur; + ReleaseSingleChain(&this->calcChain); + ReleaseSingleChain(&this->drawChain); +} - cur = &this->drawChain; - utils::DebugPrint2("add draw chain (pri = %d)\n", priority); - elem->priority = priority; +ChainElem *Chain::CreateElem(ChainCallback callback) +{ + ChainElem *elem; - while (cur->next != NULL) + elem = new ChainElem(); + + elem->callback = callback; + elem->addedCallback = NULL; + elem->deletedCallback = NULL; + + elem->isHeapAllocated = true; + + return elem; +} + +void Chain::Cut(ChainElem *to_remove) +{ + int isDrawChain; + ChainElem *tmp; + + isDrawChain = 0; + + if (to_remove == NULL) { - if (cur->priority > priority) + return; + } + + tmp = &this->calcChain; + + while (tmp != NULL) + { + if (tmp == to_remove) { - break; + goto destroy_elem; } - cur = cur->next; + tmp = tmp->next; } - if (cur->priority > priority) { - elem->next = cur; - elem->prev = cur->prev; + isDrawChain = 1; - if (elem->prev != NULL) + tmp = &this->drawChain; + while (tmp != NULL) { - elem->prev->next = elem; + if (tmp == to_remove) + { + goto destroy_elem; + } + + tmp = tmp->next; } + } - cur->prev = elem; + return; + +destroy_elem: + if (!isDrawChain) + { + utils::DebugPrint2("calc cut Chain (Pri = %d)\n", to_remove->priority); } else { - elem->next = NULL; - elem->prev = cur; - cur->next = elem; + utils::DebugPrint2("draw cut Chain (Pri = %d)\n", to_remove->priority); } - if (elem->addedCallback != NULL) - { - return elem->addedCallback(elem->arg); - } - else + if (to_remove->prev != NULL) { - return 0; + to_remove->callback = NULL; + to_remove->prev->next = to_remove->next; + + if (to_remove->next != NULL) + { + to_remove->next->prev = to_remove->prev; + } + + to_remove->prev = NULL; + to_remove->next = NULL; + + if (to_remove->isHeapAllocated) + { + delete to_remove; + to_remove = NULL; + } + else + { + if (to_remove->deletedCallback != NULL) + { + ChainDeletedCallback callback = to_remove->deletedCallback; + to_remove->deletedCallback = NULL; + callback(to_remove->arg); + } + } } } }; // namespace th06 diff --git a/src/GuiImpl.cpp b/src/GuiImpl.cpp index 6a4f665b..f9d453a5 100644 --- a/src/GuiImpl.cpp +++ b/src/GuiImpl.cpp @@ -11,9 +11,8 @@ namespace th06 #pragma optimize("s", on) GuiImpl::GuiImpl() { - -}; +}; ZunResult GuiImpl::RunMsg() {