Events - morcSkyrim/SkyrimSE GitHub Wiki
Documentation on the creation of events, the different types of events, how to set handles etc. Existing examples include Ryan's Skywind, which has handles for UIEvents, and QuickLoot's main function has an pretty simple example of a keyListener.
From a quick search of the commonlib files we have
-
InputEvent
- Pretty self explanatory, pertains to user input, things like keyboard, mouse commands etc. Children:
-
IDEvent
Children:ButtonEvent
KineticEvent
MouseMoveEvent
ThumbstickEvent
An event sink is essentially a function which is used to handle an event. In the case of skyrim, this involves an object of type BSTEventSink, where EventType specifies the type of Event. The BSTEventSink is extremely simple,
template <class Event>
class BSTEventSink
{
public:
virtual ~BSTEventSink() = default; // 00
virtual BSEventNotifyControl ProcessEvent(const Event* a_event, BSTEventSource<Event>* a_eventSource) = 0; // 01
};
static_assert(sizeof(BSTEventSink<void>) == 0x8);
with its only member functions being its destructor, and the ProcessEvent, which will specify the function that gets called during the event. The only job that our custom event sink must provide is the ProcessEvent function.
Every event sink must be registered with the associated event source, such that it can be called when an event occurs. To the best of my knowledge this occurs exclusively through the BSTEventSource
virtual class interface, which has the following functions
void AddEventSink(Sink* a_eventSink) {
....
}
void RemoveEventSink(Sink* a_eventSink) {
....
}
void SendEvent(const Event* a_event) {
....
}
This allows us to easily identify all the different header files defining event sources in CommonLib,
- BeamProjectile.h
- BGSFootstepManager.h
- BGSMoviePlayer.h
- BGSSaveLoadManager.h
- BGSStoryTeller.h
- bhkCharacterController.h
- BSAnimationGraphManager.h
- BSGamepadDevice.h
- BShkbAnimationGraph.h
- BSInputDeviceManager.h
- BSSaveDataSystemUtility.h
- ControlMap.h
- ErrorLogger.h
- PlayerCharacter.h: 3 event declarations
- ScriptEventSourceHolder.h: 53 events source declarations
- SkyrimVM.h
- UI : 3 sub declarations
- VirtualMachine.h
According to my search through commonlib, there are apparently a total of 74 unique event holders.
The procedure for setting up a new event listener goes something like
- Locate the appropriate event.
- Locate the appropriate event source.
- Program a class that inherits from the EventSink with your appropriate event type.
- Program the ProcessEvent function to handle the associated event.
- Register your new class with the appropriate event source using the AddEventSink function.
- Test
- Profit
We would like to listen for key presses when in the inventory to provide some additional functionality to items. This leaves us with a few options for event types, InputEvent, ButtonEvent, and possibly MenuControls. Considering ButtonEvent derives from InputEvent, it's presumably an event that is specific to buttonpresses. Either should be appropriate in this case, though ButtonEvent must be used if the information in its members is required.