Isle
Loading...
Searching...
No Matches
legoactioncontrolpresenter.cpp
Go to the documentation of this file.
2
3#include "define.h"
4#include "extra.h"
5#include "legomain.h"
6#include "legoutils.h"
8#include "mxdssubscriber.h"
9#include "mxmediapresenter.h"
10#include "mxmisc.h"
11#include "mxstreamchunk.h"
12#include "mxticklemanager.h"
13#include "mxutilities.h"
14
16
17// FUNCTION: LEGO1 0x10043ce0
18void LegoActionControlPresenter::ReadyTickle()
19{
20 MxStreamChunk* chunk = NextChunk();
21
22 if (chunk) {
23 ParseExtra();
24 ProgressTickleState(e_starting);
25
26 m_subscriber->FreeDataChunk(chunk);
27 if (m_compositePresenter) {
28 if (m_action->GetDuration() == -1 || m_action->GetFlags() & 1) {
29 m_compositePresenter->VTable0x60(this);
30 }
31 }
32 }
33}
34
35// FUNCTION: LEGO1 0x10043d40
37{
38 if (IsEnabled()) {
39 if (m_unk0x50 == 0) {
40 ParseExtra();
41 }
42
43 InvokeAction(m_unk0x50, MxAtomId(m_unk0x54.GetData(), e_lowerCase2), m_unk0x64, NULL);
45 }
46}
47
48// FUNCTION: LEGO1 0x10043df0
50{
51 MxResult result = FAILURE;
52
53 if (TickleManager()) {
54 result = SUCCESS;
55 TickleManager()->RegisterClient(this, 100);
56 }
57
58 return result;
59}
60
61// FUNCTION: LEGO1 0x10043e20
63{
64 if (TickleManager()) {
66 }
67
68 if (!p_fromDestructor) {
70 }
71}
72
73// FUNCTION: LEGO1 0x10043e50
75{
76 MxU16 extraLength;
77 char* extraData;
78 m_action->GetExtra(extraLength, extraData);
79
80 if (extraLength) {
81 char extraCopy[1024];
82 memcpy(extraCopy, extraData, extraLength);
83 extraCopy[extraLength] = '\0';
84
85 char output[1024];
86 if (KeyValueStringParse(output, g_strACTION, extraCopy)) {
87 m_unk0x50 = MatchActionString(strtok(output, g_parseExtraTokens));
88
89 if (m_unk0x50 != Extra::ActionType::e_exit) {
90 MakeSourceName(extraCopy, strtok(NULL, g_parseExtraTokens));
91
92 m_unk0x54 = extraCopy;
93 m_unk0x54.ToLowerCase();
94 if (m_unk0x50 != Extra::ActionType::e_run) {
95 m_unk0x64 = atoi(strtok(NULL, g_parseExtraTokens));
96 }
97 }
98 }
99 }
100}
[AI] Presenter for controlling action logic (e.g., invoking named actions such as "RUN",...
void RepeatingTickle() override
[AI] Handles tickle at the 'repeating' state to invoke parsed actions.
MxResult AddToManager() override
[AI] Registers this presenter as a tickle client with the TickleManager.
void ParseExtra() override
[AI] Parses the Extra field (from SI) for action commands and parameters.
[AI] Atomized (unique) string identifier, managed by reference counting.
Definition: mxatom.h:124
void GetExtra(MxU16 &p_extraLength, char *&p_extraData)
[AI] Retrieves the extra data and its length for this action.
Definition: mxdsaction.h:168
void Destroy() override
[AI] Cleans up internal resources and resets the presenter to an uninitialized state.
void ProgressTickleState(TickleState p_tickleState)
[AI] Helper for advancing the presenter's tickle state and updating transition history.
Definition: mxpresenter.h:72
MxBool IsEnabled()
[AI] Returns whether this presenter is logically enabled (based on the associated action's flags).
MxDSAction * m_action
[AI] The associated action currently being presented by this presenter.
Definition: mxpresenter.h:211
@ e_done
[AI] Completed processing the current action.
Definition: mxpresenter.h:30
[AI] Represents a streamable chunk of data, typically sourced from a media buffer and designed for no...
Definition: mxstreamchunk.h:19
char * GetData() const
Returns a pointer to the internal character buffer.
Definition: mxstring.h:110
void ToLowerCase()
Converts the string contents to lowercase in-place.
Definition: mxstring.cpp:97
virtual void UnregisterClient(MxCore *p_client)
[AI] Unregisters (marks for destruction) a previously registered client.
virtual void RegisterClient(MxCore *p_client, MxTime p_interval)
[AI] Registers an MxCore object to receive periodic tickles.
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
const char * g_strACTION
[AI] Used as the key for defining an action or command block in game scripts.
Definition: define.cpp:5
const char * g_parseExtraTokens
[AI] Delimiter tokens for parsing extra parameters in scripts or command strings.
Definition: define.cpp:141
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
void InvokeAction(Extra::ActionType p_actionId, const MxAtomId &p_pAtom, MxS32 p_streamId, LegoEntity *p_sender)
[AI] Dispatches and triggers a game action on the given script or object.
Definition: legoutils.cpp:271
Extra::ActionType MatchActionString(const char *)
[AI] Parses an action string to determine the corresponding action type.
Definition: legoutils.cpp:228
@ e_lowerCase2
[AI] Alternative or legacy lower case mode, functionally equivalent to e_lowerCase.
Definition: mxatom.h:109
MxTickleManager * TickleManager()
[AI] Provides access to the global tickle manager.
Definition: mxmisc.cpp:25
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
MxBool KeyValueStringParse(char *, const char *, const char *)
Searches p_string for a key command and copies its associated value to p_output.
Definition: mxutilities.cpp:85
void MakeSourceName(char *, const char *)
Parses an SI source filename and normalizes it for use in the engine.
Definition: mxutilities.cpp:66
@ e_exit
[AI] Exit an activity, context or resource [AI]
Definition: extra.h:33
@ e_run
[AI] Run (execute) an operation [AI]
Definition: extra.h:32