00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Root.h"
00023 #include "Groups.h"
00024 #include "ASN1Codes.h"
00025 #include "ParseNode.h"
00026 #include "Ingredients.h"
00027 #include "Programs.h"
00028 #include "Variables.h"
00029 #include "Presentable.h"
00030 #include "Visible.h"
00031 #include "Engine.h"
00032 #include "Text.h"
00033 #include "Bitmap.h"
00034 #include "Stream.h"
00035 #include "DynamicLineArt.h"
00036 #include "Link.h"
00037 #include "TokenGroup.h"
00038 #include "Logging.h"
00039
00040 MHGroup::MHGroup()
00041 {
00042 m_nOrigGCPriority = 127;
00043 m_Timers.setAutoDelete(true);
00044 m_nLastId = 0;
00045 }
00046
00047 void MHGroup::Initialise(MHParseNode *p, MHEngine *engine)
00048 {
00049 engine->GetGroupId().Copy("");
00050 MHRoot::Initialise(p, engine);
00051
00052 if (m_ObjectReference.m_nObjectNo != 0 || m_ObjectReference.m_GroupId.Size() == 0)
00053 MHERROR("Object reference for a group object must be zero and external");
00054
00055 engine->GetGroupId().Copy(m_ObjectReference.m_GroupId);
00056
00057
00058
00059
00060
00061 MHParseNode *pOnStartUp = p->GetNamedArg(C_ON_START_UP);
00062 if (pOnStartUp) m_StartUp.Initialise(pOnStartUp, engine);
00063 MHParseNode *pOnCloseDown = p->GetNamedArg(C_ON_CLOSE_DOWN);
00064 if (pOnCloseDown) m_CloseDown.Initialise(pOnCloseDown, engine);
00065 MHParseNode *pOriginalGCPrio = p->GetNamedArg(C_ORIGINAL_GC_PRIORITY);
00066 if (pOriginalGCPrio) m_nOrigGCPriority = pOriginalGCPrio->GetArgN(0)->GetIntValue();
00067
00068
00069 MHParseNode *pItems = p->GetNamedArg(C_ITEMS);
00070 if (pItems == NULL) p->Failure("Missing :Items block");
00071 for (int i = 0; i < pItems->GetArgCount(); i++) {
00072 MHParseNode *pItem = pItems->GetArgN(i);
00073 MHIngredient *pIngredient = NULL;
00074 try {
00075
00076 switch (pItem->GetTagNo()) {
00077 case C_RESIDENT_PROGRAM: pIngredient = new MHResidentProgram; break;
00078 case C_REMOTE_PROGRAM: pIngredient = new MHRemoteProgram; break;
00079 case C_INTERCHANGED_PROGRAM: pIngredient = new MHInterChgProgram; break;
00080 case C_PALETTE: pIngredient = new MHPalette; break;
00081 case C_FONT: pIngredient = new MHFont; break;
00082 case C_CURSOR_SHAPE: pIngredient = new MHCursorShape; break;
00083 case C_BOOLEAN_VARIABLE: pIngredient = new MHBooleanVar; break;
00084 case C_INTEGER_VARIABLE: pIngredient = new MHIntegerVar; break;
00085 case C_OCTET_STRING_VARIABLE: pIngredient = new MHOctetStrVar; break;
00086 case C_OBJECT_REF_VARIABLE: pIngredient = new MHObjectRefVar; break;
00087 case C_CONTENT_REF_VARIABLE: pIngredient = new MHContentRefVar; break;
00088 case C_LINK: pIngredient = new MHLink; break;
00089 case C_STREAM: pIngredient = new MHStream; break;
00090 case C_BITMAP: pIngredient = new MHBitmap; break;
00091 case C_LINE_ART: pIngredient = new MHLineArt; break;
00092 case C_DYNAMIC_LINE_ART: pIngredient = new MHDynamicLineArt; break;
00093 case C_RECTANGLE: pIngredient = new MHRectangle; break;
00094 case C_HOTSPOT: pIngredient = new MHHotSpot; break;
00095 case C_SWITCH_BUTTON: pIngredient = new MHSwitchButton; break;
00096 case C_PUSH_BUTTON: pIngredient = new MHPushButton; break;
00097 case C_TEXT: pIngredient = new MHText; break;
00098 case C_ENTRY_FIELD: pIngredient = new MHEntryField; break;
00099 case C_HYPER_TEXT: pIngredient = new MHHyperText; break;
00100 case C_SLIDER: pIngredient = new MHSlider; break;
00101 case C_TOKEN_GROUP: pIngredient = new MHTokenGroup; break;
00102 case C_LIST_GROUP: pIngredient = new MHListGroup; break;
00103 default:
00104 MHLOG(MHLogWarning, QString("Unknown ingredient %1").arg(pItem->GetTagNo()));
00105
00106
00107 }
00108 if (pIngredient) {
00109
00110 pIngredient->Initialise(pItem, engine);
00111
00112 if (pIngredient->m_ObjectReference.m_nObjectNo > m_nLastId)
00113 m_nLastId = pIngredient->m_ObjectReference.m_nObjectNo;
00114
00115 m_Items.Append(pIngredient);
00116 }
00117 }
00118 catch (...) {
00119 delete(pIngredient);
00120 throw;
00121 }
00122 }
00123 }
00124
00125 void MHGroup::PrintMe(FILE *fd, int nTabs) const
00126 {
00127 MHRoot::PrintMe(fd, nTabs);
00128 if (m_StartUp.Size() != 0) {
00129 PrintTabs(fd, nTabs+1); fprintf(fd, ":OnStartUp (\n");
00130 m_StartUp.PrintMe(fd, nTabs+2);
00131 PrintTabs(fd, nTabs+2); fprintf(fd, ")\n");
00132 }
00133 if (m_CloseDown.Size() != 0) {
00134 PrintTabs(fd, nTabs+1); fprintf(fd, ":OnCloseDown (\n");
00135 m_CloseDown.PrintMe(fd, nTabs+2);
00136 PrintTabs(fd, nTabs+2); fprintf(fd, ")\n");
00137 }
00138 if (m_nOrigGCPriority != 127) { PrintTabs(fd, nTabs+1); fprintf(fd, ":OrigGCPriority %d\n", m_nOrigGCPriority); }
00139 PrintTabs(fd, nTabs+1); fprintf(fd, ":Items ( \n");
00140 for (int i = 0; i < m_Items.Size(); i++) m_Items.GetAt(i)->PrintMe(fd, nTabs+2);
00141 PrintTabs(fd, nTabs+1); fprintf(fd, ")\n");
00142 }
00143
00144
00145 void MHGroup::Preparation(MHEngine *engine)
00146 {
00147
00148 for (int i = 0; i < m_Items.Size(); i++) {
00149 MHIngredient *pIngredient = m_Items.GetAt(i);
00150 if (pIngredient->InitiallyActive() || pIngredient->InitiallyAvailable()) {
00151 pIngredient->Preparation(engine);
00152 }
00153 }
00154 MHRoot::Preparation(engine);
00155 }
00156
00157
00158 void MHGroup::Activation(MHEngine *engine)
00159 {
00160 if (m_fRunning) return;
00161 MHRoot::Activation(engine);
00162
00163 engine->AddActions(m_StartUp);
00164 engine->RunActions();
00165
00166 for (int i = 0; i < m_Items.Size(); i++) {
00167 MHIngredient *pIngredient = m_Items.GetAt(i);
00168 if (pIngredient->InitiallyActive()) pIngredient->Activation(engine);
00169 }
00170 m_fRunning = true;
00171
00172 m_StartTime.start();
00173
00174 }
00175
00176
00177 void MHGroup::Deactivation(MHEngine *engine)
00178 {
00179 if (! m_fRunning) return;
00180
00181 engine->AddActions(m_CloseDown);
00182 engine->RunActions();
00183 MHRoot::Deactivation(engine);
00184 }
00185
00186
00187 void MHGroup::Destruction(MHEngine *engine)
00188 {
00189 for (int i = m_Items.Size(); i > 0; i--) m_Items.GetAt(i-1)->Destruction(engine);
00190 MHRoot::Destruction(engine);
00191 }
00192
00193
00194 MHRoot *MHGroup::FindByObjectNo(int n)
00195 {
00196 if (n == m_ObjectReference.m_nObjectNo) return this;
00197 for (int i = m_Items.Size(); i > 0; i--) {
00198 MHRoot *pResult = m_Items.GetAt(i-1)->FindByObjectNo(n);
00199 if (pResult) return pResult;
00200 }
00201 return NULL;
00202 }
00203
00204
00205 void MHGroup::SetTimer(int nTimerId, bool fAbsolute, int nMilliSecs, MHEngine *)
00206 {
00207
00208 for (int i = 0; i < (int)m_Timers.count(); i++) {
00209 MHTimer *pTimer = m_Timers.at(i);
00210 if (pTimer->m_nTimerId == nTimerId) {
00211 m_Timers.remove(i);
00212 break;
00213 }
00214 }
00215
00216 QTime currentTime;
00217 currentTime.start();
00218 if (nMilliSecs < 0 || (fAbsolute && m_StartTime.addMSecs(nMilliSecs) < currentTime)) return;
00219 MHTimer *pTimer = new MHTimer;
00220 m_Timers.append(pTimer);
00221 pTimer->m_nTimerId = nTimerId;
00222 if (fAbsolute) pTimer->m_Time = m_StartTime.addMSecs(nMilliSecs);
00223 else pTimer->m_Time = currentTime.addMSecs(nMilliSecs);
00224 }
00225
00226
00227 int MHGroup::CheckTimers(MHEngine *engine)
00228 {
00229 QTime currentTime = QTime::currentTime();
00230 MHTimer *pTimer = m_Timers.first();
00231 int nMSecs = 0;
00232 while (pTimer != 0) {
00233 if (pTimer->m_Time <= currentTime) {
00234
00235 engine->EventTriggered(this, EventTimerFired, pTimer->m_nTimerId);
00236 m_Timers.remove();
00237 pTimer = m_Timers.current();
00238 }
00239 else {
00240
00241 int nMSecsToGo = currentTime.msecsTo(pTimer->m_Time);
00242 if (nMSecs == 0 || nMSecsToGo < nMSecs) nMSecs = nMSecsToGo;
00243 pTimer = m_Timers.next();
00244 }
00245 }
00246 return nMSecs;
00247 }
00248
00249
00250 void MHGroup::MakeClone(MHRoot *pTarget, MHRoot *pRef, MHEngine *engine)
00251 {
00252 MHIngredient *pClone = pTarget->Clone(engine);
00253 pClone->m_ObjectReference.m_GroupId.Copy(m_ObjectReference.m_GroupId);
00254 pClone->m_ObjectReference.m_nObjectNo = ++m_nLastId;
00255 m_Items.Append(pClone);
00256
00257 pRef->SetVariableValue(pClone->m_ObjectReference);
00258 pClone->Preparation(engine);
00259 }
00260
00261 MHApplication::MHApplication()
00262 {
00263 m_fIsApp = true;
00264 m_nCharSet = 0;
00265 m_nTextCHook = 0;
00266 m_nIPCHook = 0;
00267 m_nStrCHook = 0;
00268 m_nBitmapCHook = 0;
00269 m_nLineArtCHook = 0;
00270
00271 m_pCurrentScene = NULL;
00272 m_nLockCount = 0;
00273 m_fRestarting = false;
00274 }
00275
00276 MHApplication::~MHApplication()
00277 {
00278 delete(m_pCurrentScene);
00279 }
00280
00281 void MHApplication::Initialise(MHParseNode *p, MHEngine *engine)
00282 {
00283 MHGroup::Initialise(p, engine);
00284
00285 MHParseNode *pOnSpawn = p->GetNamedArg(C_ON_SPAWN_CLOSE_DOWN);
00286 if (pOnSpawn) m_OnSpawnCloseDown.Initialise(pOnSpawn, engine);
00287
00288 MHParseNode *pOnRestart = p->GetNamedArg(C_ON_RESTART);
00289 if (pOnRestart) m_OnRestart.Initialise(pOnRestart, engine);
00290
00291 MHParseNode *pDefattrs = p->GetNamedArg(C_DEFAULT_ATTRIBUTES);
00292
00293 if (pDefattrs == NULL) pDefattrs = p;
00294 MHParseNode *pCharSet = pDefattrs->GetNamedArg(C_CHARACTER_SET);
00295 if (pCharSet) m_nCharSet = pCharSet->GetArgN(0)->GetIntValue();
00296
00297 MHParseNode *pBGColour = pDefattrs->GetNamedArg(C_BACKGROUND_COLOUR);
00298 if (pBGColour) m_BGColour.Initialise(pBGColour->GetArgN(0), engine);
00299 MHParseNode *pTextColour = pDefattrs->GetNamedArg(C_TEXT_COLOUR);
00300 if (pTextColour) m_TextColour.Initialise(pTextColour->GetArgN(0), engine);
00301 MHParseNode *pButtonRefColour = pDefattrs->GetNamedArg(C_BUTTON_REF_COLOUR);
00302 if (pButtonRefColour) m_ButtonRefColour.Initialise(pButtonRefColour->GetArgN(0), engine);
00303 MHParseNode *pHighlightRefColour = pDefattrs->GetNamedArg(C_HIGHLIGHT_REF_COLOUR);
00304 if (pHighlightRefColour) m_HighlightRefColour.Initialise(pHighlightRefColour->GetArgN(0), engine);
00305 MHParseNode *pSliderRefColour = pDefattrs->GetNamedArg(C_SLIDER_REF_COLOUR);
00306 if (pSliderRefColour) m_SliderRefColour.Initialise(pSliderRefColour->GetArgN(0), engine);
00307
00308 MHParseNode *pTextCHook = pDefattrs->GetNamedArg(C_TEXT_CONTENT_HOOK);
00309 if (pTextCHook) m_nTextCHook = pTextCHook->GetArgN(0)->GetIntValue();
00310 MHParseNode *pIPCHook = pDefattrs->GetNamedArg(C_IP_CONTENT_HOOK);
00311 if (pIPCHook) m_nIPCHook = pIPCHook->GetArgN(0)->GetIntValue();
00312 MHParseNode *pStrCHook = pDefattrs->GetNamedArg(C_STREAM_CONTENT_HOOK);
00313 if (pStrCHook) m_nStrCHook = pStrCHook->GetArgN(0)->GetIntValue();
00314 MHParseNode *pBitmapCHook = pDefattrs->GetNamedArg(C_BITMAP_CONTENT_HOOK);
00315 if (pBitmapCHook) m_nBitmapCHook = pBitmapCHook->GetArgN(0)->GetIntValue();
00316 MHParseNode *pLineArtCHook = pDefattrs->GetNamedArg(C_LINE_ART_CONTENT_HOOK);
00317 if (pLineArtCHook) m_nLineArtCHook = pLineArtCHook->GetArgN(0)->GetIntValue();
00318
00319
00320
00321 MHParseNode *pFont = pDefattrs->GetNamedArg(C_FONT2);
00322 if (pFont == NULL) pFont = pDefattrs->GetNamedArg(C_FONT);
00323 if (pFont) m_Font.Initialise(pFont->GetArgN(0), engine);
00324
00325 MHParseNode *pFontAttrs = pDefattrs->GetNamedArg(C_FONT_ATTRIBUTES);
00326 if (pFontAttrs) pFontAttrs->GetArgN(0)->GetStringValue(m_FontAttrs);
00327 }
00328
00329 void MHApplication::PrintMe(FILE *fd, int nTabs) const
00330 {
00331 PrintTabs(fd, nTabs);
00332 fprintf(fd, "{:Application ");
00333 MHGroup::PrintMe(fd, nTabs);
00334 if (m_OnSpawnCloseDown.Size() != 0) {
00335 PrintTabs(fd, nTabs+1); fprintf(fd, ":OnSpawnCloseDown");
00336 m_OnSpawnCloseDown.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
00337 }
00338 if (m_OnRestart.Size() != 0) {
00339 PrintTabs(fd, nTabs+1); fprintf(fd, ":OnRestart");
00340 m_OnRestart.PrintMe(fd, nTabs+1); fprintf(fd, "\n");
00341 }
00342 if (m_nCharSet > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":CharacterSet %d\n", m_nCharSet); }
00343 if (m_BGColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":BackgroundColour "); m_BGColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00344 if (m_nTextCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":TextCHook %d\n", m_nTextCHook); }
00345 if (m_TextColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":TextColour"); m_TextColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00346 if (m_Font.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":Font "); m_Font.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00347 if (m_FontAttrs.Size() > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":FontAttributes "); m_FontAttrs.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00348 if (m_nIPCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":InterchgPrgCHook %d\n", m_nIPCHook); }
00349 if (m_nStrCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":StreamCHook %d\n", m_nStrCHook); }
00350 if (m_nBitmapCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":BitmapCHook %d\n", m_nBitmapCHook); }
00351 if (m_nLineArtCHook > 0) { PrintTabs(fd, nTabs+1); fprintf(fd, ":LineArtCHook %d\n", m_nLineArtCHook); }
00352 if (m_ButtonRefColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":ButtonRefColour "); m_ButtonRefColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00353 if (m_HighlightRefColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":HighlightRefColour "); m_HighlightRefColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00354 if (m_SliderRefColour.IsSet()) { PrintTabs(fd, nTabs+1); fprintf(fd, ":SliderRefColour "); m_SliderRefColour.PrintMe(fd, nTabs+1); fprintf(fd, "\n"); }
00355 fprintf(fd, "}\n");
00356 }
00357
00358
00359
00360
00361 void MHApplication::Activation(MHEngine *engine)
00362 {
00363 if (m_fRunning) return;
00364 MHGroup::Activation(engine);
00365 if (m_fRestarting) {
00366 engine->AddActions(m_OnRestart);
00367 engine->RunActions();
00368 }
00369 engine->EventTriggered(this, EventIsRunning);
00370 }
00371
00372 int MHApplication::FindOnStack(const MHRoot *pVis)
00373 {
00374 for (int i = 0; i < m_DisplayStack.Size(); i++) {
00375 if (m_DisplayStack.GetAt(i) == pVis) return i;
00376 }
00377 return -1;
00378 }
00379
00380 MHScene::MHScene()
00381 {
00382 m_fIsApp = false;
00383
00384
00385 m_nAspectRatioW = 4; m_nAspectRatioH = 3;
00386 m_fMovingCursor = false;
00387 }
00388
00389 void MHScene::Initialise(MHParseNode *p, MHEngine *engine)
00390 {
00391 MHGroup::Initialise(p, engine);
00392
00393 MHParseNode *pInputEventReg = p->GetNamedArg(C_INPUT_EVENT_REGISTER);
00394 m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue();
00395
00396 MHParseNode *pSceneCoords = p->GetNamedArg(C_SCENE_COORDINATE_SYSTEM);
00397 m_nSceneCoordX = pSceneCoords->GetArgN(0)->GetIntValue();
00398 m_nSceneCoordY = pSceneCoords->GetArgN(1)->GetIntValue();
00399
00400 MHParseNode *pAspectRatio = p->GetNamedArg(C_ASPECT_RATIO);
00401 if (pAspectRatio) {
00402
00403 m_nAspectRatioW = pAspectRatio->GetArgN(0)->GetIntValue();
00404 m_nAspectRatioH = pAspectRatio->GetArgN(1)->GetIntValue();
00405 }
00406
00407 MHParseNode *pMovingCursor = p->GetNamedArg(C_MOVING_CURSOR);
00408 if (pMovingCursor) pMovingCursor->GetArgN(0)->GetBoolValue();
00409
00410 }
00411
00412 void MHScene::PrintMe(FILE *fd, int nTabs) const
00413 {
00414 PrintTabs(fd, nTabs);
00415 fprintf(fd, "{:Scene ");
00416 MHGroup::PrintMe(fd, nTabs);
00417 PrintTabs(fd, nTabs+1); fprintf(fd, ":InputEventReg %d\n", m_nEventReg);
00418 PrintTabs(fd, nTabs+1); fprintf(fd, ":SceneCS %d %d\n", m_nSceneCoordX, m_nSceneCoordY);
00419 if (m_nAspectRatioW != 4 || m_nAspectRatioH != 3) { PrintTabs(fd, nTabs+1); fprintf(fd, ":AspectRatio %d %d\n", m_nAspectRatioW, m_nAspectRatioH); }
00420 if (m_fMovingCursor) { PrintTabs(fd, nTabs+1); fprintf(fd, ":MovingCursor true\n"); }
00421 fprintf(fd, "}\n");
00422 }
00423
00424 void MHScene::Activation(MHEngine *engine)
00425 {
00426 if (m_fRunning) return;
00427 MHGroup::Activation(engine);
00428 engine->EventTriggered(this, EventIsRunning);
00429 }
00430
00431
00432 void MHScene::SetInputRegister(int nReg, MHEngine *engine)
00433 {
00434 m_nEventReg = nReg;
00435 engine->SetInputRegister(nReg);
00436 }
00437
00438
00439 void MHSendEvent::Initialise(MHParseNode *p, MHEngine *engine)
00440 {
00441 MHElemAction::Initialise(p, engine);
00442 m_EventSource.Initialise(p->GetArgN(1), engine);
00443 m_EventType = (enum EventType)p->GetArgN(2)->GetEnumValue();
00444 if (p->GetArgCount() >= 4) {
00445
00446 m_EventData.Initialise(p->GetArgN(3), engine);
00447 }
00448 }
00449
00450 void MHSendEvent::PrintArgs(FILE *fd, int) const
00451 {
00452 m_EventSource.PrintMe(fd, 0);
00453 fprintf(fd, MHLink::EventTypeToString(m_EventType).ascii());
00454 fprintf(fd, " ");
00455 if (m_EventData.m_Type != MHParameter::P_Null) m_EventData.PrintMe(fd, 0);
00456 }
00457
00458 void MHSendEvent::Perform(MHEngine *engine)
00459 {
00460
00461 MHObjectRef target, source;
00462 m_Target.GetValue(target, engine);
00463 m_EventSource.GetValue(source, engine);
00464
00465 if (m_EventData.m_Type == MHParameter::P_Null)
00466 engine->EventTriggered(engine->FindObject(source), m_EventType);
00467 else {
00468 MHUnion data;
00469 data.GetValueFrom(m_EventData, engine);
00470 engine->EventTriggered(engine->FindObject(source), m_EventType, data);
00471 }
00472 }
00473
00474 void MHSetTimer::Initialise(MHParseNode *p, MHEngine *engine)
00475 {
00476 MHElemAction::Initialise(p, engine);
00477 m_TimerId.Initialise(p->GetArgN(1), engine);
00478 if (p->GetArgCount() > 2) {
00479 MHParseNode *pNewTimer = p->GetArgN(2);
00480 m_TimerValue.Initialise(pNewTimer->GetSeqN(0), engine);
00481 if (pNewTimer->GetSeqCount() > 1) {
00482 m_TimerType = ST_TimerAbsolute;
00483 m_AbsFlag.Initialise(pNewTimer->GetSeqN(1), engine);
00484 }
00485 else m_TimerType = ST_TimerRelative;
00486 }
00487 }
00488
00489 void MHSetTimer::PrintArgs(FILE *fd, int ) const
00490 {
00491 m_TimerId.PrintMe(fd, 0);
00492 if (m_TimerType != ST_NoNewTimer) {
00493 fprintf(fd, "( ");
00494 m_TimerValue.PrintMe(fd, 0);
00495 if (m_TimerType == ST_TimerAbsolute) m_AbsFlag.PrintMe(fd, 0);
00496 fprintf(fd, ") ");
00497 }
00498 }
00499
00500 void MHSetTimer::Perform(MHEngine *engine)
00501 {
00502 int nTimerId = m_TimerId.GetValue(engine);
00503 bool fAbsolute = false;
00504 int newTime = -1;
00505 switch (m_TimerType) {
00506 case ST_NoNewTimer: fAbsolute = true; newTime = -1; break;
00507 case ST_TimerAbsolute: fAbsolute = m_AbsFlag.GetValue(engine);
00508 case ST_TimerRelative: newTime = m_TimerValue.GetValue(engine);
00509 }
00510 Target(engine)->SetTimer(nTimerId, fAbsolute, newTime, engine);
00511 }
00512
00513 void MHPersistent::Initialise(MHParseNode *p, MHEngine *engine)
00514 {
00515 MHElemAction::Initialise(p, engine);
00516 m_Succeeded.Initialise(p->GetArgN(1), engine);
00517 MHParseNode *pVarSeq = p->GetArgN(2);
00518 for (int i = 0; i < pVarSeq->GetSeqCount(); i++) {
00519 MHObjectRef *pVar = new MHObjectRef;
00520 m_Variables.Append(pVar);
00521 pVar->Initialise(pVarSeq->GetSeqN(i), engine);
00522 }
00523 m_FileName.Initialise(p->GetArgN(3), engine);
00524 }
00525
00526 void MHPersistent::PrintArgs(FILE *fd, int nTabs) const
00527 {
00528 m_Succeeded.PrintMe(fd, nTabs);
00529 fprintf(fd, " ( ");
00530 for (int i = 0; i < m_Variables.Size(); i++) m_Variables.GetAt(i)->PrintMe(fd, 0);
00531 fprintf(fd, " ) ");
00532 m_FileName.PrintMe(fd, nTabs);
00533 }
00534
00535 void MHPersistent::Perform(MHEngine *engine)
00536 {
00537 MHObjectRef target;
00538 m_Target.GetValue(target, engine);
00539 MHOctetString fileName;
00540 m_FileName.GetValue(fileName, engine);
00541 bool fResult = engine->LoadStorePersistent(m_fIsLoad, fileName, m_Variables);
00542 engine->FindObject(m_Succeeded)->SetVariableValue(fResult);
00543 }
00544
00545 MHTransitionTo::MHTransitionTo(): MHElemAction(":TransitionTo")
00546 {
00547 m_fIsTagged = false;
00548 m_nConnectionTag = 0;
00549 m_nTransitionEffect = -1;
00550 }
00551
00552 void MHTransitionTo::Initialise(MHParseNode *p, MHEngine *engine)
00553 {
00554 MHElemAction::Initialise(p, engine);
00555
00556 if (p->GetArgCount() > 1) {
00557 MHParseNode *pCtag = p->GetArgN(1);
00558 if (pCtag->m_nNodeType == MHParseNode::PNInt) {
00559 m_fIsTagged = TRUE;
00560 m_nConnectionTag = pCtag->GetIntValue();
00561 }
00562 }
00563 if (p->GetArgCount() > 2) {
00564 MHParseNode *pTrEff = p->GetArgN(2);
00565 m_nTransitionEffect = pTrEff->GetIntValue();
00566 }
00567 }
00568
00569 void MHTransitionTo::PrintArgs(FILE *fd, int ) const
00570 {
00571 if (m_fIsTagged) fprintf(fd, " %d ", m_nConnectionTag);
00572 else if (m_nTransitionEffect >= 0) fprintf(fd, " NULL ");
00573 if (m_nTransitionEffect >= 0) fprintf(fd, " %d", m_nTransitionEffect);
00574 }
00575
00576
00577 void MHTransitionTo::Perform(MHEngine *engine)
00578 {
00579 MHObjectRef target;
00580 m_Target.GetValue(target, engine);
00581 engine->TransitionToScene(target);
00582 }
00583
00584 void MHLaunch::Perform(MHEngine *engine) { MHObjectRef target; m_Target.GetValue(target, engine); engine->Launch(target); }
00585 void MHQuit::Perform(MHEngine *engine) { engine->Quit(); }
00586 void MHSpawn::Perform(MHEngine *engine) { MHObjectRef target; m_Target.GetValue(target, engine); engine->Spawn(target); }
00587 void MHLockScreen::Perform(MHEngine *engine) { engine->LockScreen(); }
00588 void MHUnlockScreen::Perform(MHEngine *engine) { engine->UnlockScreen(); }
00589
00590 void MHGetEngineSupport::Initialise(MHParseNode *p, MHEngine *engine)
00591 {
00592 MHElemAction::Initialise(p, engine);
00593 m_Feature.Initialise(p->GetArgN(1), engine);
00594 m_Answer.Initialise(p->GetArgN(2), engine);
00595 }
00596
00597 void MHGetEngineSupport::Perform(MHEngine *engine)
00598 {
00599
00600 MHOctetString feature;
00601 m_Feature.GetValue(feature, engine);
00602 engine->FindObject(m_Answer)->SetVariableValue(engine->GetEngineSupport(feature));
00603 }