Skip to content

Commit a76b22d

Browse files
committed
Reworked fixes to make temporary timers fire in the submitted sequence
1 parent d5ff964 commit a76b22d

18 files changed

+185
-213
lines changed

OtherTypes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,7 @@ class CTimer : public CObject
703703

704704
};
705705

706-
typedef map <string, CTimer*> CTimerMap;
707-
typedef CTimerMap::iterator CTimerMapIterator;
706+
typedef CTypedPtrMap <CMapStringToPtr, CString, CTimer*> CTimerMap;
708707

709708
// map for lookup name from pointer
710709
typedef map <CTimer*, string> CTimerRevMap;

dialogs/plugins/PluginWizard.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,13 @@ BOOL CPluginWizardPage5::OnInitDialog()
586586
m_ctlList.InsertColumn(3, TranslateHeading ("Group"), LVCFMT_LEFT, 50);
587587

588588
int iItem = 0;
589+
POSITION pos;
590+
CString strName;
589591

590-
for (CTimerMapIterator timerIt = m_doc->m_TimerMap.begin ();
591-
timerIt != m_doc->m_TimerMap.end ();
592-
timerIt++)
592+
for (pos = m_doc->m_TimerMap.GetStartPosition(); pos; )
593593
{
594-
CTimer * t = timerIt->second;
594+
CTimer * t;
595+
m_doc->m_TimerMap.GetNextAssoc (pos, strName, t);
595596

596597
if (t->bTemporary)
597598
continue; // ignore temporary ones
@@ -642,13 +643,14 @@ void CPluginWizardPage5::OnSelectNone()
642643

643644
void CPluginWizardPage5::OnOK()
644645
{
646+
POSITION pos;
647+
CString strName;
645648

646649
// first deselect everything
647-
for (CTimerMapIterator timerIt = m_doc->m_TimerMap.begin ();
648-
timerIt != m_doc->m_TimerMap.end ();
649-
timerIt++)
650+
for (pos = m_doc->m_TimerMap.GetStartPosition(); pos; )
650651
{
651-
CTimer * t = timerIt->second;
652+
CTimer * t;
653+
m_doc->m_TimerMap.GetNextAssoc (pos, strName, t);
652654
t->bSelected = false;
653655
}
654656

@@ -657,16 +659,15 @@ void CPluginWizardPage5::OnOK()
657659
{
658660
CTimer * t = (CTimer *) m_ctlList.GetItemData (nItem);
659661
// find in Timer array (in case it doesn't exist any more) and select it
660-
for (CTimerMapIterator timerIt = m_doc->m_TimerMap.begin ();
661-
timerIt != m_doc->m_TimerMap.end ();
662-
timerIt++)
662+
for (pos = m_doc->m_TimerMap.GetStartPosition(); pos; )
663663
{
664-
CTimer * t2 = timerIt->second;
665-
if (t == t2)
666-
{
667-
t->bSelected = true;
668-
break;
669-
}
664+
CTimer * t2;
665+
m_doc->m_TimerMap.GetNextAssoc (pos, strName, t2);
666+
if (t == t2)
667+
{
668+
t->bSelected = true;
669+
break;
670+
}
670671
}
671672
} // end of each list item
672673

dialogs/world_prefs/TimerDlg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ void CTimerDlg::DoDataExchange(CDataExchange* pDX)
142142
} // end of doing a periodical timer
143143

144144

145+
CString strTimerName;
145146
CTimer * timer_item;
147+
POSITION pos;
146148

147-
for (CTimerMapIterator timerIt = m_pTimerMap->begin ();
148-
timerIt != m_pTimerMap->end ();
149-
timerIt++)
149+
for (pos = m_pTimerMap->GetStartPosition (); pos; )
150150
{
151-
timer_item = timerIt->second;
151+
m_pTimerMap->GetNextAssoc (pos, strTimerName, timer_item);
152152

153153
// don't compare against itself
154154

dialogs/world_prefs/aliasdlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void CAliasDlg::DoDataExchange(CDataExchange* pDX)
171171
if (m_bRegexp)
172172
{
173173
if (!CheckRegularExpression (m_name, (m_bIgnoreCase ? 0 : PCRE_CASELESS)
174-
| (m_pDoc->m_bUTF_8 ? PCRE_UTF8 : 0)
174+
| (m_pDoc->m_bUTF_8 ? PCRE_UTF8 : 0)
175175
))
176176
{ // failed check
177177
DDX_Text(pDX, IDC_ALIAS_NAME, m_name);

dialogs/world_prefs/configuration.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ void CMUSHclientDoc:: LoadPrefsP15 (CPrefsP15 &page15)
441441

442442
CTrigger * pTrigger;
443443
CAlias * pAlias;
444+
CTimer * pTimer;
444445
CString strName;
445446
POSITION pos;
446447
LONGLONG iTimeTaken = 0;
@@ -465,11 +466,10 @@ void CMUSHclientDoc:: LoadPrefsP15 (CPrefsP15 &page15)
465466
}
466467

467468
// count number of timers fired
468-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
469-
timerIt != m_TimerMap.end ();
470-
timerIt++)
469+
for (pos = m_TimerMap.GetStartPosition(); pos; )
471470
{
472-
nTotalTimers += timerIt->second->nMatched;
471+
m_TimerMap.GetNextAssoc (pos, strName, pTimer);
472+
nTotalTimers += pTimer->nMatched;
473473
}
474474

475475
page15.m_strBufferLines.Format ("%i / %ld",
@@ -500,7 +500,7 @@ void CMUSHclientDoc:: LoadPrefsP15 (CPrefsP15 &page15)
500500
m_AliasMap.GetCount (),
501501
nTotalAliases);
502502
page15.m_strTimers.Format ("%i (%I64d fired)",
503-
m_TimerMap.size (),
503+
m_TimerMap.GetCount (),
504504
nTotalTimers);
505505

506506
if (m_sockAddr.sin_addr.s_addr == INADDR_NONE)

dialogs/world_prefs/prefspropertypages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,10 +6203,10 @@ void CPrefsP16::DoDataExchange(CDataExchange* pDX)
62036203
if (pDX->m_bSaveAndValidate)
62046204
if (m_ctlUseDefaultTimers.GetCheck ())
62056205
if (m_ctlUseDefaultTimers.GetCheck () != m_bUseDefaultTimers)
6206-
if (m_doc->m_TimerMap.size () > 0)
6206+
if (m_doc->m_TimerMap.GetCount () > 0)
62076207
if (::UMessageBox (TFormat ("By checking the option \"Override with default timers\" "
62086208
" your existing %i timer%s will be PERMANENTLY discarded next time you open this world.\n\n"
6209-
"Are you SURE you want to do this?", PLURAL (m_doc->m_TimerMap.size ())),
6209+
"Are you SURE you want to do this?", PLURAL (m_doc->m_TimerMap.GetCount ())),
62106210
MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2 ) != IDYES)
62116211
pDX->Fail ();
62126212

doc_construct.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int i;
3939
m_VariableMap.InitHashTable (997); // allow for 1000 variables (at least)
4040
m_AliasMap.InitHashTable (293); // probably won't have many more than 300 aliases
4141
m_TriggerMap.InitHashTable (293); // probably won't have many more than 300 triggers
42+
m_TimerMap.InitHashTable (293); // probably won't have many more than 300 timers
4243

4344
SetDefaults (false); // set up numeric/boolean defaults
4445
SetAlphaDefaults (false); // set up alpha defaults
@@ -560,14 +561,8 @@ int i;
560561

561562
// delete timer map
562563

563-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
564-
timerIt != m_TimerMap.end ();
565-
timerIt++)
566-
delete timerIt->second;
567-
m_TimerMap.clear ();
568-
m_TimerRevMap.clear ();
569-
570-
564+
DELETE_MAP (m_TimerMap, CTimer);
565+
571566
// delete variables map
572567

573568
DELETE_MAP (m_VariableMap, CVariable);

evaluate.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ if (strFileName.IsEmpty ())
613613
replace = FALSE;
614614
}
615615
else
616-
if (set_type == TIMER && !m_TimerMap.empty ())
616+
if (set_type == TIMER && !m_TimerMap.IsEmpty ())
617617
{
618618
if (::TMessageBox ("Replace existing timers?\n"
619619
"If you reply \"No\", then timers from the file"
@@ -661,14 +661,7 @@ CArchive * ar = NULL;
661661

662662
case TIMER:
663663
if (replace)
664-
{
665-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
666-
timerIt != m_TimerMap.end ();
667-
timerIt++)
668-
delete timerIt->second;
669-
m_TimerMap.clear ();
670-
m_TimerRevMap.clear ();
671-
}
664+
DELETE_MAP (m_TimerMap, CTimer);
672665
Load_World_XML (*ar, XML_TIMERS | XML_NO_PLUGINS | XML_IMPORT_MAIN_FILE_ONLY);
673666
break;
674667

plugins.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ CPlugin::CPlugin (CMUSHclientDoc * pDoc)
159159
m_VariableMap.InitHashTable (293); // allow for 300 variables in this plugin
160160
m_AliasMap.InitHashTable (293); // ditto for aliases
161161
m_TriggerMap.InitHashTable (293); // ditto for triggers
162+
m_TimerMap.InitHashTable (293); // ditto for timers
162163
m_tDateInstalled = CTime::GetCurrentTime(); // when plugin loaded
163164

164165
m_dRequiredVersion = 0.0;
@@ -185,12 +186,7 @@ CPlugin::~CPlugin ()
185186
SaveState ();
186187
DELETE_MAP (m_TriggerMap, CTrigger);
187188
DELETE_MAP (m_AliasMap, CAlias);
188-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
189-
timerIt != m_TimerMap.end ();
190-
timerIt++)
191-
delete timerIt->second;
192-
m_TimerMap.clear ();
193-
m_TimerRevMap.clear ();
189+
DELETE_MAP (m_TimerMap, CTimer);
194190
DELETE_MAP (m_VariableMap, CVariable);
195191
delete m_ScriptEngine;
196192

@@ -911,11 +907,11 @@ void CMUSHclientDoc::OnFilePluginwizard()
911907
a->bSelected = true;
912908
}
913909
// timers
914-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
915-
timerIt != m_TimerMap.end ();
916-
timerIt++)
910+
for (pos = m_TimerMap.GetStartPosition(); pos; )
917911
{
918-
timerIt->second->bSelected = true;
912+
CTimer * t;
913+
m_TimerMap.GetNextAssoc (pos, strName, t);
914+
t->bSelected = true;
919915
}
920916
// variables
921917
for (pos = m_VariableMap.GetStartPosition(); pos; iCount++)
@@ -1126,24 +1122,24 @@ void CMUSHclientDoc::OnFilePluginwizard()
11261122
// ---------- timers ----------
11271123

11281124
iCount = 0;
1129-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
1130-
timerIt != m_TimerMap.end ();
1131-
timerIt++)
1125+
for (pos = m_TimerMap.GetStartPosition(); pos; )
11321126
{
1133-
if (timerIt->second->bSelected)
1127+
CTimer * t;
1128+
m_TimerMap.GetNextAssoc (pos, strName, t);
1129+
if (t->bSelected)
11341130
iCount++;
11351131
}
11361132

11371133
if (iCount)
11381134
{
11391135
ar.WriteString (NL "<!-- Timers -->" NL NL);
11401136
Save_Header_XML (ar, "timers", false);
1141-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
1142-
timerIt != m_TimerMap.end ();
1143-
timerIt++)
1137+
for (pos = m_TimerMap.GetStartPosition(); pos; )
11441138
{
1145-
if (timerIt->second->bSelected)
1146-
Save_One_Timer_XML (ar, timerIt->second);
1139+
CTimer * t;
1140+
m_TimerMap.GetNextAssoc (pos, strName, t);
1141+
if (t->bSelected)
1142+
Save_One_Timer_XML (ar, t);
11471143
}
11481144
Save_Footer_XML (ar, "timers");
11491145
} // end of having some
@@ -1338,19 +1334,17 @@ void CMUSHclientDoc::OnFilePluginwizard()
13381334
// ---------- timers ----------
13391335

13401336
iCount = 0;
1341-
for (CTimerMapIterator timerIt = m_TimerMap.begin ();
1342-
timerIt != m_TimerMap.end ();
1343-
)
1337+
for (pos = m_TimerMap.GetStartPosition(); pos; )
13441338
{
1345-
CTimer * t = timerIt->second;
1339+
CTimer * t;
1340+
m_TimerMap.GetNextAssoc (pos, strName, t);
13461341
if (t->bSelected)
13471342
{
1348-
CTimerMapIterator it = timerIt++; // make copy before deleting
13491343
iCount++;
13501344
// delete its pointer
13511345
delete t;
13521346
// now delete its entry
1353-
m_TimerMap.erase (it);
1347+
m_TimerMap.RemoveKey (strName);
13541348
} // end of selected Timer
13551349

13561350
// show document modified

scripting/methods/methods_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ VARIANT CMUSHclientDoc::GetInfo(long InfoType)
602602
case 217: SetUpVariantLong (vaResult, (long) m_nBytesOut); break;
603603
case 218: SetUpVariantLong (vaResult, GetVariableMap ().GetCount ()); break;
604604
case 219: SetUpVariantLong (vaResult, GetTriggerMap ().GetCount ()); break;
605-
case 220: SetUpVariantLong (vaResult, GetTimerMap ().size ()); break;
605+
case 220: SetUpVariantLong (vaResult, GetTimerMap ().GetCount ()); break;
606606
case 221: SetUpVariantLong (vaResult, GetAliasMap ().GetCount ()); break;
607607
case 222: SetUpVariantLong (vaResult, m_QueuedCommandsList.GetCount ()); break;
608608
case 223: SetUpVariantLong (vaResult, m_strMapList.GetCount ()); break;

scripting/methods/methods_plugins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ VARIANT CMUSHclientDoc::GetPluginInfo(LPCTSTR PluginID, short InfoType)
115115
case 8: SetUpVariantString (vaResult, pPlugin->m_strPurpose); break;
116116
case 9: SetUpVariantLong (vaResult, pPlugin->m_TriggerMap.GetCount ()); break;
117117
case 10: SetUpVariantLong (vaResult, pPlugin->m_AliasMap.GetCount ()); break;
118-
case 11: SetUpVariantLong (vaResult, pPlugin->m_TimerMap.size ()); break;
118+
case 11: SetUpVariantLong (vaResult, pPlugin->m_TimerMap.GetCount ()); break;
119119
case 12: SetUpVariantLong (vaResult, pPlugin->m_VariableMap.GetCount ()); break;
120120
case 13:
121121
if (pPlugin->m_tDateWritten.GetTime ()) // only if non-zero, otherwise return empty

0 commit comments

Comments
 (0)