Skip to content

Commit b2daaa7

Browse files
authored
refactor(metaevent): Move meta event type asserts from key event update to engine initialization (TheSuperHackers#2590)
1 parent 9379a32 commit b2daaa7

6 files changed

Lines changed: 74 additions & 46 deletions

File tree

Generals/Code/GameEngine/Include/GameClient/MetaEvent.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ class MetaMap : public SubsystemInterface
391391

392392
static void parseMetaMap(INI* ini);
393393

394-
// TheSuperHackers @info Function to generate default key mappings
394+
// TheSuperHackers @feature Function to generate default key mappings
395395
// for actions that were not found in a CommandMap.ini
396-
static void generateMetaMap();
396+
void generateMetaMap();
397+
398+
void verifyMetaMap();
397399

398400
const MetaMapRec *getFirstMetaMapRec() const { return m_metaMaps; }
399401
};

Generals/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,13 @@ void GameEngine::init()
486486
fname.format("Data\\%s\\CommandMap", GetRegistryLanguage().str());
487487
initSubsystem(TheMetaMap,"TheMetaMap", MSGNEW("GameEngineSubsystem") MetaMap(), nullptr, fname.str(), "Data\\INI\\CommandMap");
488488

489-
TheMetaMap->generateMetaMap();
490-
491489
#if defined(RTS_DEBUG)
492490
ini.loadFileDirectory("Data\\INI\\CommandMapDebug", INI_LOAD_MULTIFILE, nullptr);
493491
#endif
494492

493+
TheMetaMap->generateMetaMap();
494+
TheMetaMap->verifyMetaMap();
495+
495496
initSubsystem(TheActionManager,"TheActionManager", MSGNEW("GameEngineSubsystem") ActionManager(), nullptr);
496497
//initSubsystem((CComObject<WebBrowser> *)TheWebBrowser,"(CComObject<WebBrowser> *)TheWebBrowser", (CComObject<WebBrowser> *)createWebBrowser(), nullptr);
497498
initSubsystem(TheGameStateMap,"TheGameStateMap", MSGNEW("GameEngineSubsystem") GameStateMap, nullptr );

Generals/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,6 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessa
429429

430430
for (const MetaMapRec *map = TheMetaMap->getFirstMetaMapRec(); map; map = map->m_next)
431431
{
432-
DEBUG_ASSERTCRASH(map->m_meta > GameMessage::MSG_BEGIN_META_MESSAGES &&
433-
map->m_meta < GameMessage::MSG_END_META_MESSAGES, ("hmm, expected only meta-msgs here"));
434-
435432
if (!isMessageUsable(map->m_usableIn))
436433
continue;
437434

@@ -669,14 +666,14 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
669666
}
670667

671668
//-------------------------------------------------------------------------------------------------
672-
/*static */ void MetaMap::generateMetaMap()
669+
void MetaMap::generateMetaMap()
673670
{
674671
// TheSuperHackers @info A default mapping for MSG_META_SELECT_ALL_AIRCRAFT would be useful for Generals
675672
// but is not recommended, because it will cause key mapping conflicts with original game languages.
676673

677674
{
678675
// Is useful for Generals and Zero Hour.
679-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_INCREASE_MAX_RENDER_FPS);
676+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_INCREASE_MAX_RENDER_FPS);
680677
if (map->m_key == MK_NONE)
681678
{
682679
map->m_key = MK_KPPLUS;
@@ -687,7 +684,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
687684
}
688685
{
689686
// Is useful for Generals and Zero Hour.
690-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_DECREASE_MAX_RENDER_FPS);
687+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_DECREASE_MAX_RENDER_FPS);
691688
if (map->m_key == MK_NONE)
692689
{
693690
map->m_key = MK_KPMINUS;
@@ -698,7 +695,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
698695
}
699696
{
700697
// Is useful for Generals and Zero Hour.
701-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_INCREASE_LOGIC_TIME_SCALE);
698+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_INCREASE_LOGIC_TIME_SCALE);
702699
if (map->m_key == MK_NONE)
703700
{
704701
map->m_key = MK_KPPLUS;
@@ -709,7 +706,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
709706
}
710707
{
711708
// Is useful for Generals and Zero Hour.
712-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_DECREASE_LOGIC_TIME_SCALE);
709+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_DECREASE_LOGIC_TIME_SCALE);
713710
if (map->m_key == MK_NONE)
714711
{
715712
map->m_key = MK_KPMINUS;
@@ -720,7 +717,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
720717
}
721718
{
722719
// Is useful for Generals and Zero Hour.
723-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_TOGGLE_PLAYER_OBSERVER);
720+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_TOGGLE_PLAYER_OBSERVER);
724721
if (map->m_key == MK_NONE)
725722
{
726723
map->m_key = MK_M;
@@ -731,7 +728,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
731728
}
732729
{
733730
// Is mostly useful for Generals.
734-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY);
731+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY);
735732
if (map->m_key == MK_NONE)
736733
{
737734
map->m_key = MK_F;
@@ -742,7 +739,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
742739
}
743740
{
744741
// Is useful for Generals and Zero Hour.
745-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_TOGGLE_PAUSE);
742+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_TOGGLE_PAUSE);
746743
if (map->m_key == MK_NONE)
747744
{
748745
map->m_key = MK_P;
@@ -753,7 +750,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
753750
}
754751
{
755752
// Is useful for Generals and Zero Hour.
756-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_TOGGLE_PAUSE_ALT);
753+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_TOGGLE_PAUSE_ALT);
757754
if (map->m_key == MK_NONE)
758755
{
759756
map->m_key = MK_P;
@@ -764,7 +761,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
764761
}
765762
{
766763
// Is useful for Generals and Zero Hour.
767-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_STEP_FRAME);
764+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_STEP_FRAME);
768765
if (map->m_key == MK_NONE)
769766
{
770767
map->m_key = MK_O;
@@ -775,7 +772,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
775772
}
776773
{
777774
// Is useful for Generals and Zero Hour.
778-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_STEP_FRAME_ALT);
775+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_STEP_FRAME_ALT);
779776
if (map->m_key == MK_NONE)
780777
{
781778
map->m_key = MK_O;
@@ -786,7 +783,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
786783
}
787784
{
788785
// Is useful for Generals and Zero Hour.
789-
MetaMapRec* map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_SELECT_NEXT_IDLE_WORKER);
786+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_SELECT_NEXT_IDLE_WORKER);
790787
if (map->m_key == MK_NONE) {
791788
map->m_key = MK_I;
792789
map->m_transition = DOWN;
@@ -798,7 +795,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
798795
}
799796
}
800797
{
801-
MetaMapRec* map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_ALT_CAMERA_ROTATE_LEFT);
798+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_ALT_CAMERA_ROTATE_LEFT);
802799
if (map->m_key == MK_NONE) {
803800
map->m_key = MK_KP4;
804801
map->m_transition = DOWN;
@@ -807,7 +804,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
807804
}
808805
}
809806
{
810-
MetaMapRec* map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_ALT_CAMERA_ROTATE_RIGHT);
807+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_ALT_CAMERA_ROTATE_RIGHT);
811808
if (map->m_key == MK_NONE) {
812809
map->m_key = MK_KP6;
813810
map->m_transition = DOWN;
@@ -819,7 +816,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
819816
#if defined(RTS_DEBUG)
820817
{
821818
// Is useful for Generals and Zero Hour.
822-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_DEMO_REMOVE_PREREQ);
819+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_DEMO_REMOVE_PREREQ);
823820
if (map->m_key == MK_NONE)
824821
{
825822
map->m_key = MK_P;
@@ -830,7 +827,7 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
830827
}
831828
{
832829
// Is useful for Generals and Zero Hour.
833-
MetaMapRec *map = TheMetaMap->getMetaMapRec(GameMessage::MSG_META_DEMO_FREE_BUILD);
830+
MetaMapRec *map = getMetaMapRec(GameMessage::MSG_META_DEMO_FREE_BUILD);
834831
if (map->m_key == MK_NONE)
835832
{
836833
map->m_key = MK_B;
@@ -864,6 +861,20 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
864861
#endif // defined(RTS_DEBUG)
865862
}
866863

864+
//-------------------------------------------------------------------------------------------------
865+
void MetaMap::verifyMetaMap()
866+
{
867+
#ifdef DEBUG_CRASHING
868+
for (const MetaMapRec *map = getFirstMetaMapRec(); map; map = map->m_next)
869+
{
870+
DEBUG_ASSERTCRASH(
871+
map->m_meta > GameMessage::MSG_BEGIN_META_MESSAGES &&
872+
map->m_meta < GameMessage::MSG_END_META_MESSAGES,
873+
("hmm, expected only meta-msgs here"));
874+
}
875+
#endif
876+
}
877+
867878
//-------------------------------------------------------------------------------------------------
868879
/*static*/ void INI::parseMetaMapDefinition( INI* ini )
869880
{

GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ class MetaMap : public SubsystemInterface
391391

392392
static void parseMetaMap(INI* ini);
393393

394-
// TheSuperHackers @info Function to generate default key mappings
394+
// TheSuperHackers @feature Function to generate default key mappings
395395
// for actions that were not found in a CommandMap.ini
396-
static void generateMetaMap();
396+
void generateMetaMap();
397+
398+
void verifyMetaMap();
397399

398400
const MetaMapRec *getFirstMetaMapRec() const { return m_metaMaps; }
399401
};

GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,6 @@ void GameEngine::init()
627627
fname.format("Data\\%s\\CommandMap", GetRegistryLanguage().str());
628628
initSubsystem(TheMetaMap,"TheMetaMap", MSGNEW("GameEngineSubsystem") MetaMap(), nullptr, fname.str(), "Data\\INI\\CommandMap");
629629

630-
TheMetaMap->generateMetaMap();
631-
632630
#if defined(RTS_DEBUG)
633631
ini.loadFileDirectory("Data\\INI\\CommandMapDebug", INI_LOAD_MULTIFILE, nullptr);
634632
#endif
@@ -637,6 +635,9 @@ void GameEngine::init()
637635
ini.loadFileDirectory("Data\\INI\\CommandMapDemo", INI_LOAD_MULTIFILE, nullptr);
638636
#endif
639637

638+
TheMetaMap->generateMetaMap();
639+
TheMetaMap->verifyMetaMap();
640+
640641

641642
initSubsystem(TheActionManager,"TheActionManager", MSGNEW("GameEngineSubsystem") ActionManager(), nullptr);
642643
//initSubsystem((CComObject<WebBrowser> *)TheWebBrowser,"(CComObject<WebBrowser> *)TheWebBrowser", (CComObject<WebBrowser> *)createWebBrowser(), nullptr);

0 commit comments

Comments
 (0)