Skip to content

Commit

Permalink
Renamings in Engine/Events
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Feb 9, 2025
1 parent 7f35f86 commit ac35f96
Show file tree
Hide file tree
Showing 36 changed files with 157 additions and 154 deletions.
2 changes: 1 addition & 1 deletion src/Application/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Engine/EngineGlobals.h"
#include "Engine/Data/AwardEnums.h"
#include "Engine/Data/HouseEnumFunctions.h"
#include "Engine/Events/Processor.h"
#include "Engine/Evt/Processor.h"
#include "Engine/Graphics/DecalBuilder.h"
#include "Engine/Graphics/ParticleEngine.h"
#include "Engine/Graphics/LightsStack.h"
Expand Down
8 changes: 4 additions & 4 deletions src/Bin/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "Engine/Components/Random/EngineRandomComponent.h"
#include "Engine/Tables/ItemTable.h"
#include "Engine/Tables/HouseTable.h"
#include "Engine/Events/EventMap.h"
#include "Engine/Evt/EvtProgram.h"
#include "Engine/Random/Random.h"
#include "Engine/Objects/DecorationEnums.h"
#include "Engine/Objects/DecorationList.h"
Expand Down Expand Up @@ -209,17 +209,17 @@ int runHouseIdCodeGen(const CodeGenOptions &options, GameResourceManager *resour
continue; // Not a level file.

std::string mapName = mapIdEnumName(mapInfoByFileName(mapStats, fileName));
EventMap eventMap = EventMap::load(resourceManager->getEventsFile(fileName.substr(0, fileName.size() - 4) + ".evt"));
EvtProgram eventMap = EvtProgram::load(resourceManager->getEventsFile(fileName.substr(0, fileName.size() - 4) + ".evt"));

for (const EventTrigger &trigger : eventMap.enumerateTriggers(EVENT_SpeakInHouse)) {
HouseId houseId = eventMap.event(trigger.eventId, trigger.eventStep).data.house_id;
HouseId houseId = eventMap.instruction(trigger.eventId, trigger.eventStep).data.house_id;
if (houseId == HOUSE_INVALID)
throw Exception("Invalid house id encountered in house event");
mapNamesByHouseId[houseId].insert(mapName);
}

for (const EventTrigger &trigger : eventMap.enumerateTriggers(EVENT_MoveToMap)) {
HouseId houseId = eventMap.event(trigger.eventId, trigger.eventStep).data.move_map_descr.house_id;
HouseId houseId = eventMap.instruction(trigger.eventId, trigger.eventStep).data.move_map_descr.house_id;
if (houseId != HOUSE_INVALID)
mapNamesByHouseId[houseId].insert(mapName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ target_compile_definitions(engine PRIVATE

add_subdirectory(Data)
add_subdirectory(Components)
add_subdirectory(Events)
add_subdirectory(Evt)
add_subdirectory(Graphics)
add_subdirectory(Objects)
add_subdirectory(Random)
Expand Down
6 changes: 3 additions & 3 deletions src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Engine/EngineGlobals.h"
#include "Engine/AssetsManager.h"

#include "Engine/Events/Processor.h"
#include "Engine/Evt/Processor.h"
#include "Engine/Graphics/Camera.h"
#include "Engine/Graphics/DecalBuilder.h"
#include "Engine/Objects/DecorationList.h"
Expand Down Expand Up @@ -762,7 +762,7 @@ void Engine::SecondaryInitialization() {
initializeMerchants(engine->_gameResourceManager->getEventsFile("merchant.txt"));
initializeMessageScrolls(engine->_gameResourceManager->getEventsFile("scroll.txt"));

engine->_globalEventMap = EventMap::load(engine->_gameResourceManager->getEventsFile("global.evt"));
engine->_globalEventMap = EvtProgram::load(engine->_gameResourceManager->getEventsFile("global.evt"));

pBitmaps_LOD->reserveLoadedTextures();
pSprites_LOD->reserveLoadedSprites();
Expand Down Expand Up @@ -1485,7 +1485,7 @@ void loadMapEventsAndStrings(MapId mapid) {

initLevelStrings(engine->_gameResourceManager->getEventsFile(fmt::format("{}.str", mapNameWithoutExt)));

engine->_localEventMap = EventMap::load(engine->_gameResourceManager->getEventsFile(fmt::format("{}.evt", mapNameWithoutExt)));
engine->_localEventMap = EvtProgram::load(engine->_gameResourceManager->getEventsFile(fmt::format("{}.evt", mapNameWithoutExt)));
}

bool _44100D_should_alter_right_panel() {
Expand Down
6 changes: 3 additions & 3 deletions src/Engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "Application/GameConfig.h"

#include "Engine/Events/EventMap.h"
#include "Engine/Evt/EvtProgram.h"
#include "Engine/MapEnums.h"
#include "Engine/TeleportPoint.h"
#include "Engine/mm7_data.h"
Expand Down Expand Up @@ -122,8 +122,8 @@ class Engine {
Vis *vis = nullptr;
std::shared_ptr<Io::KeyboardInputHandler> keyboardInputHandler;
std::shared_ptr<Io::KeyboardActionMapping> keyboardActionMapping;
EventMap _globalEventMap;
EventMap _localEventMap;
EvtProgram _globalEventMap;
EvtProgram _localEventMap;
std::vector<std::string> _levelStrings;
PersistentVariables _persistentVariables;
MapId _currentLoadedMapId = MAP_INVALID;
Expand Down
5 changes: 0 additions & 5 deletions src/Engine/Events/EventEnums.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)

set(ENGINE_EVENTS_SOURCES
EventEnums.cpp
EventIR.cpp
EventMap.cpp
EventInterpreter.cpp
EvtEnums.cpp
EvtInstruction.cpp
EvtProgram.cpp
EvtInterpreter.cpp
Processor.cpp)

set(ENGINE_EVENTS_HEADERS
EventIR.h
EventMap.h
EventInterpreter.h
EventEnums.h
EvtInstruction.h
EvtProgram.h
EvtInterpreter.h
EvtEnums.h
Processor.h
EventEnumFunctions.h)
EvtEnumFunctions.h)

add_library(engine_events STATIC ${ENGINE_EVENTS_SOURCES} ${ENGINE_EVENTS_HEADERS})
target_link_libraries(engine_events PUBLIC engine tl::generator)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "EventEnums.h"
#include "EvtEnums.h"

#include <cassert>
#include <utility>

inline int historyIndex(VariableType variable) {
inline int historyIndex(EvtVariable variable) {
assert(variable >= VAR_History_0 && variable <= VAR_History_28);
return std::to_underlying(variable) - std::to_underlying(VAR_History_0);
}
5 changes: 5 additions & 0 deletions src/Engine/Evt/EvtEnums.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "EvtEnums.h"

#include "Library/Serialization/EnumSerialization.h"

MM_DEFINE_ENUM_MAGIC_SERIALIZATION_FUNCTIONS(EvtOpcode)
16 changes: 9 additions & 7 deletions src/Engine/Events/EventEnums.h → src/Engine/Evt/EvtEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "Library/Serialization/SerializationFwd.h"

enum class EventType : uint8_t {
// TODO(captainurist): rename the enum values properly

enum class EvtOpcode : uint8_t {
EVENT_Invalid = 0,
EVENT_Exit = 1,
EVENT_SpeakInHouse = 2,
Expand Down Expand Up @@ -74,10 +76,10 @@ enum class EventType : uint8_t {
EVENT_IsTotalBountyHuntingAwardInRange = 67,
EVENT_IsNPCInParty = 68,
};
using enum EventType;
MM_DECLARE_SERIALIZATION_FUNCTIONS(EventType)
using enum EvtOpcode;
MM_DECLARE_SERIALIZATION_FUNCTIONS(EvtOpcode)

enum class VariableType {
enum class EvtVariable {
VAR_Sex = 0x1,
VAR_Class = 0x2,
VAR_CurrentHP = 0x3,
Expand Down Expand Up @@ -245,7 +247,7 @@ enum class VariableType {
VAR_Invisible = 0x13A,
VAR_ItemEquipped = 0x13B,
};
using enum VariableType;
using enum EvtVariable;

enum class Season {
SEASON_SPRING = 0,
Expand All @@ -256,7 +258,7 @@ enum class Season {
using enum Season;

// TODO(Nik-RE-dev): currently exclusive for MM7, need to be independent from players number
enum class CharacterChoosePolicy {
enum class EvtTargetCharacter {
CHOOSE_PLAYER1 = 0,
CHOOSE_PLAYER2 = 1,
CHOOSE_PLAYER3 = 2,
Expand All @@ -266,5 +268,5 @@ enum class CharacterChoosePolicy {
CHOOSE_PARTY = 5,
CHOOSE_RANDOM = 6
};
using enum CharacterChoosePolicy;
using enum EvtTargetCharacter;

44 changes: 22 additions & 22 deletions src/Engine/Events/EventIR.cpp → src/Engine/Evt/EvtInstruction.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "EventIR.h"
#include "EvtInstruction.h"

#include <span>
#include <string>

#include "Engine/Events/EventEnums.h"
#include "Engine/Evt/EvtEnums.h"
#include "Engine/Objects/Decoration.h"
#include "Engine/Tables/HouseTable.h"
#include "Engine/Tables/NPCTable.h"
Expand All @@ -15,9 +15,9 @@
#include "Utility/Exception.h"
#include "Utility/Unaligned.h"

#include "EventEnumFunctions.h"
#include "EvtEnumFunctions.h"

static std::string getVariableSetStr(VariableType type, int value) {
static std::string getVariableSetStr(EvtVariable type, int value) {
if (type >= VAR_MapPersistentVariable_0 && type <= VAR_MapPersistentVariable_74) {
return fmt::format("MapVars[{}], {}", std::to_underlying(type) - std::to_underlying(VAR_MapPersistentVariable_0), value);
}
Expand Down Expand Up @@ -340,7 +340,7 @@ static std::string getVariableSetStr(VariableType type, int value) {
}
}

static std::string getVariableCompareStr(VariableType type, int value) {
static std::string getVariableCompareStr(EvtVariable type, int value) {
if (type >= VAR_MapPersistentVariable_0 && type <= VAR_MapPersistentVariable_74) {
return fmt::format("MapVars[{}] >= {}", std::to_underlying(type) - std::to_underlying(VAR_MapPersistentVariable_0), value);
}
Expand Down Expand Up @@ -663,8 +663,8 @@ static std::string getVariableCompareStr(VariableType type, int value) {
}
}

std::string EventIR::toString() const {
switch (type) {
std::string EvtInstruction::toString() const {
switch (opcode) {
case EVENT_Exit:
return fmt::format("{}: Exit", step);
case EVENT_SpeakInHouse:
Expand Down Expand Up @@ -835,30 +835,30 @@ std::string EventIR::toString() const {
break;
}

return fmt::format("{}: UNPROCESSED/{}", step, ::toString(type));
return fmt::format("{}: UNPROCESSED/{}", step, ::toString(opcode));
}

EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
EvtInstruction EvtInstruction::parse(SequentialBlobReader &sbr, const size_t size) {
// TODO(yoctozepto): zeroing-out the struct to prevent values from previous events from lingering;
// this makes it slightly easier to spot uninitialised members but, since the 0s may have a proper meaning, not always;
EventIR ir = {};
EvtInstruction ir = {};

ir.step = sbr.read<uint8_t>();
ir.type = EventType(sbr.read<uint8_t>());
ir.opcode = EvtOpcode(sbr.read<uint8_t>());

bool requireSizeCalled = false;

const auto requireSize = [&](size_t minSize) {
requireSizeCalled = true;
if (size < minSize)
throw Exception("Invalid evt record size for event '{}': expected at least {} bytes, got {} bytes", ::toString(ir.type), minSize, size);
throw Exception("Invalid evt record size for event '{}': expected at least {} bytes, got {} bytes", ::toString(ir.opcode), minSize, size);
};

// TODO(captainurist): verify enum ranges here.
// TODO(yoctozepto): which are present in global events and which in local?
// TODO(yoctozepto): some types (marked with further TODOs) are not present in used MM7 data - their parsing might thus be wrong

switch (ir.type) {
switch (ir.opcode) {
case EVENT_Exit:
requireSize(6);
sbr.read<uint8_t>(); // TODO(yoctozepto): always 0 in MM7 data, check MM6&8
Expand Down Expand Up @@ -899,12 +899,12 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
break;
case EVENT_ShowFace: // TODO(yoctozepto): not present in used MM7 data
requireSize(7);
ir.who = static_cast<CharacterChoosePolicy>(sbr.read<uint8_t>());
ir.who = static_cast<EvtTargetCharacter>(sbr.read<uint8_t>());
ir.data.portrait_id = static_cast<CharacterPortrait>(sbr.read<uint8_t>());
break;
case EVENT_ReceiveDamage:
requireSize(11);
ir.who = static_cast<CharacterChoosePolicy>(sbr.read<uint8_t>());
ir.who = static_cast<EvtTargetCharacter>(sbr.read<uint8_t>());
ir.data.damage_descr.damage_type = static_cast<DamageType>(sbr.read<uint8_t>());
ir.data.damage_descr.damage = sbr.read<uint32_t>();
break;
Expand Down Expand Up @@ -932,7 +932,7 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
break;
case EVENT_Compare:
requireSize(11);
ir.data.variable_descr.type = static_cast<VariableType>(sbr.read<uint16_t>());
ir.data.variable_descr.type = static_cast<EvtVariable>(sbr.read<uint16_t>());
ir.data.variable_descr.value = sbr.read<uint32_t>();
ir.target_step = sbr.read<uint8_t>();
break;
Expand All @@ -945,7 +945,7 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
case EVENT_Substract:
case EVENT_Set:
requireSize(8);
ir.data.variable_descr.type = static_cast<VariableType>(sbr.read<uint16_t>());
ir.data.variable_descr.type = static_cast<EvtVariable>(sbr.read<uint16_t>());
ir.data.variable_descr.value = sbr.read<uint32_t>();
break;
case EVENT_SummonMonsters:
Expand Down Expand Up @@ -1047,7 +1047,7 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
break;
case EVENT_ForPartyMember:
requireSize(6);
ir.who = static_cast<CharacterChoosePolicy>(sbr.read<uint8_t>());
ir.who = static_cast<EvtTargetCharacter>(sbr.read<uint8_t>());
break;
case EVENT_Jmp:
requireSize(6);
Expand Down Expand Up @@ -1087,7 +1087,7 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
break;
case EVENT_OnCanShowDialogItemCmp:
requireSize(12);
ir.data.variable_descr.type = static_cast<VariableType>(sbr.read<uint16_t>());
ir.data.variable_descr.type = static_cast<EvtVariable>(sbr.read<uint16_t>());
ir.data.variable_descr.value = sbr.read<uint32_t>();
ir.target_step = sbr.read<uint8_t>();
break;
Expand Down Expand Up @@ -1162,7 +1162,7 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
break;
case EVENT_CharacterAnimation:
requireSize(7);
ir.who = static_cast<CharacterChoosePolicy>(sbr.read<uint8_t>());
ir.who = static_cast<EvtTargetCharacter>(sbr.read<uint8_t>());
ir.data.speech_id = static_cast<CharacterSpeech>(sbr.read<uint8_t>());
break;
case EVENT_OnDateTimer: // TODO(yoctozepto): not present in used MM7 data
Expand Down Expand Up @@ -1190,14 +1190,14 @@ EventIR EventIR::parse(SequentialBlobReader &sbr, const size_t size) {
// TODO
break;
default:
throw Exception("Unknown evt type: {}", static_cast<uint8_t>(ir.type));
throw Exception("Unknown evt type: {}", static_cast<uint8_t>(ir.opcode));
break;
}

assert(requireSizeCalled && "please report");

if (sbr.readable()) {
throw Exception("Some evt data has not been parsed for evt type: {}", ::toString(ir.type));
throw Exception("Some evt data has not been parsed for evt type: {}", ::toString(ir.opcode));
}

return ir;
Expand Down
12 changes: 6 additions & 6 deletions src/Engine/Events/EventIR.h → src/Engine/Evt/EvtInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>

#include "Engine/Data/HouseEnums.h"
#include "Engine/Events/EventEnums.h"
#include "Engine/Evt/EvtEnums.h"
#include "Engine/Objects/CharacterEnums.h"
#include "Engine/Objects/ItemEnums.h"
#include "Engine/Objects/ChestEnums.h"
Expand All @@ -16,15 +16,15 @@

#include "Utility/SequentialBlobReader.h"

class EventIR {
class EvtInstruction {
public:
std::string toString() const;
static EventIR parse(SequentialBlobReader &sbr, const size_t size);
static EvtInstruction parse(SequentialBlobReader &sbr, const size_t size);

EventType type;
EvtOpcode opcode;
int step;
int target_step;
CharacterChoosePolicy who;
EvtTargetCharacter who;
std::string str;
union {
HouseId house_id;
Expand All @@ -50,7 +50,7 @@ class EventIR {
bool is_give;
} npc_item_descr;
struct {
VariableType type;
EvtVariable type;
int value;
} variable_descr;
struct {
Expand Down
Loading

0 comments on commit ac35f96

Please sign in to comment.