cleanup (add supportive function getSub() )

svn-id: r8013
This commit is contained in:
Oliver Kiehl 2003-05-26 19:25:24 +00:00
parent d95832d732
commit d08a06ea88
3 changed files with 42 additions and 30 deletions

View file

@ -50,6 +50,29 @@
namespace SkyCompact { namespace SkyCompact {
uint16 *getSub(Compact *cpt, uint16 mode) {
switch (mode) {
case 0:
return &(cpt->baseSub);
case 2:
return &(cpt->baseSub_off);
case 4:
return &(cpt->extCompact->actionSub);
case 6:
return &(cpt->extCompact->actionSub_off);
case 8:
return &(cpt->extCompact->getToSub);
case 10:
return &(cpt->extCompact->getToSub_off);
case 12:
return &(cpt->extCompact->extraSub);
case 14:
return &(cpt->extCompact->extraSub_off);
default:
error("Invalid Mode (%d)", mode);
}
}
static const uint32 compactOffsets[] = { static const uint32 compactOffsets[] = {
MK16(Compact, logic), MK16(Compact, logic),
MK16(Compact, status), MK16(Compact, status),

View file

@ -27,6 +27,7 @@
#include "sky/skydefs.h" #include "sky/skydefs.h"
namespace SkyCompact { namespace SkyCompact {
uint16 *getSub(Compact *cpt, uint16 mode);
void *getCompactElem(Compact *cpt, uint32 off); void *getCompactElem(Compact *cpt, uint32 off);
extern uint16 slide2_seq[]; extern uint16 slide2_seq[];

View file

@ -109,8 +109,8 @@ void SkyLogic::logicScript() {
for (;;) { for (;;) {
uint16 mode = _compact->mode; // get pointer to current script uint16 mode = _compact->mode; // get pointer to current script
printf("compact mode: %d\n", mode); printf("compact mode: %d\n", mode);
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + mode); uint16 *scriptNo = SkyCompact::getSub(_compact, mode);
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + mode + 2); uint16 *offset = SkyCompact::getSub(_compact, mode + 2);
uint32 scr = script(*scriptNo, *offset); uint32 scr = script(*scriptNo, *offset);
*scriptNo = (uint16)(scr & 0xffff); *scriptNo = (uint16)(scr & 0xffff);
@ -224,7 +224,7 @@ void SkyLogic::arAnim() {
// tell it it is waiting for us // tell it it is waiting for us
cpt->extCompact->waitingFor = (uint16)(_scriptVariables[CUR_ID] & 0xffff); cpt->extCompact->waitingFor = (uint16)(_scriptVariables[CUR_ID] & 0xffff);
// restart current script // restart current script
*(uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2) = 0; *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
_compact->logic = L_SCRIPT; _compact->logic = L_SCRIPT;
logicScript(); logicScript();
return; return;
@ -267,7 +267,7 @@ void SkyLogic::arAnim() {
// changed so restart the current script // changed so restart the current script
// *not suitable for base initiated ARing // *not suitable for base initiated ARing
*(uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2) = 0; *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
_compact->logic = L_SCRIPT; _compact->logic = L_SCRIPT;
logicScript(); logicScript();
@ -340,13 +340,9 @@ void SkyLogic::arTurn() {
void SkyLogic::alt() { void SkyLogic::alt() {
// change the current script // change the current script
_compact->logic = L_SCRIPT; _compact->logic = L_SCRIPT;
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode); *SkyCompact::getSub(_compact, _compact->mode) = _compact->extCompact->alt;
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2); *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
*scriptNo = _compact->extCompact->alt;
*offset = 0;
logicScript(); logicScript();
} }
@ -432,7 +428,7 @@ void SkyLogic::stopped() {
// we are free, continue processing the script // we are free, continue processing the script
// restart script one level below // restart script one level below
*(uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode - 2) = 0; *SkyCompact::getSub(_compact, _compact->mode - 2) = 0;
_compact->extCompact->waitingFor = 0xffff; _compact->extCompact->waitingFor = 0xffff;
_compact->logic = L_SCRIPT; _compact->logic = L_SCRIPT;
@ -614,8 +610,8 @@ void SkyLogic::runGetOff() {
void SkyLogic::stopAndWait() { void SkyLogic::stopAndWait() {
_compact->mode += 4; _compact->mode += 4;
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode); uint16 *scriptNo = SkyCompact::getSub(_compact, _compact->mode);
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2); uint16 *offset = SkyCompact::getSub(_compact, _compact->mode + 2);
*scriptNo = (uint16)(_compact->extCompact->stopScript & 0xffff); *scriptNo = (uint16)(_compact->extCompact->stopScript & 0xffff);
*offset = (uint16)(_compact->extCompact->stopScript >> 16); *offset = (uint16)(_compact->extCompact->stopScript >> 16);
@ -1152,31 +1148,24 @@ uint32 SkyLogic::fnInteract(uint32 targetId, uint32 b, uint32 c) {
_compact->logic = L_SCRIPT; _compact->logic = L_SCRIPT;
Compact *cpt = SkyState::fetchCompact(targetId); Compact *cpt = SkyState::fetchCompact(targetId);
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode); *SkyCompact::getSub(_compact, _compact->mode) = cpt->actionScript;
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2); *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
*scriptNo = cpt->actionScript;
*offset = 0;
return 0; return 0;
} }
uint32 SkyLogic::fnStartSub(uint32 scr, uint32 b, uint32 c) { uint32 SkyLogic::fnStartSub(uint32 scr, uint32 b, uint32 c) {
_compact->mode += 4; _compact->mode += 4;
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode); *SkyCompact::getSub(_compact, _compact->mode) = (uint16)(scr & 0xffff);
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2); *SkyCompact::getSub(_compact, _compact->mode + 2) = (uint16)(scr >> 16);
*scriptNo = (uint16)(scr & 0xffff);
*offset = (uint16)(scr >> 16);
return 0; return 0;
} }
uint32 SkyLogic::fnTheyStartSub(uint32 mega, uint32 scr, uint32 c) { uint32 SkyLogic::fnTheyStartSub(uint32 mega, uint32 scr, uint32 c) {
Compact *cpt = SkyState::fetchCompact(mega); Compact *cpt = SkyState::fetchCompact(mega);
cpt->mode += 4; cpt->mode += 4;
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(cpt, C_BASE_SUB + _compact->mode); *SkyCompact::getSub(cpt, _compact->mode) = (uint16)(scr & 0xffff);
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(cpt, C_BASE_SUB + _compact->mode + 2); *SkyCompact::getSub(cpt, _compact->mode + 2) = (uint16)(scr >> 16);
*scriptNo = (uint16)(scr & 0xffff);
*offset = (uint16)(scr >> 16);
return 1; return 1;
} }
@ -1235,10 +1224,9 @@ uint32 SkyLogic::fnGetTo(uint32 targetPlaceId, uint32 mode, uint32 c) {
while (*getToTable != targetPlaceId) while (*getToTable != targetPlaceId)
getToTable += 2; getToTable += 2;
uint16 *scriptNo = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode); // get new script
uint16 *offset = (uint16 *)SkyCompact::getCompactElem(_compact, C_BASE_SUB + _compact->mode + 2); *SkyCompact::getSub(_compact, _compact->mode) = *(getToTable + 1);
*scriptNo = *(getToTable + 1); // get new script *SkyCompact::getSub(_compact, _compact->mode + 2) = 0;
*offset = 0;
return 0; // drop out of script return 0; // drop out of script
} }