Isle
Loading...
Searching...
No Matches
mxpresenter.cpp
Go to the documentation of this file.
1#include "mxpresenter.h"
2
3#include "decomp.h"
4#include "define.h"
6#include "mxautolock.h"
8#include "mxdsanim.h"
9#include "mxdssound.h"
10#include "mxentity.h"
11#include "mxeventpresenter.h"
12#include "mxflcpresenter.h"
16#include "mxmidipresenter.h"
17#include "mxmisc.h"
19#include "mxobjectfactory.h"
20#include "mxomni.h"
21#include "mxparam.h"
22#include "mxsmkpresenter.h"
23#include "mxstillpresenter.h"
24#include "mxstreamer.h"
25#include "mxutilities.h"
26#include "mxwavepresenter.h"
27
28#include <string.h>
29
31
32// FUNCTION: LEGO1 0x100b4d50
34{
36 m_action = NULL;
37 m_location = MxPoint32(0, 0);
38 m_displayZ = 0;
41}
42
43// FUNCTION: LEGO1 0x100b4d80
44// FUNCTION: BETA10 0x1012e120
46{
48
49 m_action = p_action;
52
54
55 return SUCCESS;
56}
57
58// FUNCTION: LEGO1 0x100b4e40
60{
61 if (m_action == NULL) {
62 return;
63 }
64
66
70 );
71 }
72
73 m_action = NULL;
74 MxS32 previousTickleState = 1 << m_currentTickleState;
75 m_previousTickleStates |= previousTickleState;
77}
78
79// FUNCTION: LEGO1 0x100b4fc0
81{
83
84 MxU16 extraLength;
85 char* extraData;
86 m_action->GetExtra(extraLength, extraData);
87
88 if (extraLength) {
89 char extraCopy[512];
90 memcpy(extraCopy, extraData, extraLength);
91 extraCopy[extraLength] = '\0';
92
93 char worldValue[512];
94 if (KeyValueStringParse(worldValue, g_strWORLD, extraCopy)) {
95 char* token = strtok(worldValue, g_parseExtraTokens);
96 char buf[256];
97 strcpy(buf, token);
98
99 token = strtok(NULL, g_parseExtraTokens);
100 MxS32 val = token ? atoi(token) : 0;
101 MxEntity* result = MxOmni::GetInstance()->AddToWorld(buf, val, this);
102
104
105 if (result) {
107 }
108 }
109 }
110}
111
112// FUNCTION: LEGO1 0x100b5120
113// FUNCTION: BETA10 0x1012e5d8
115{
118
120 m_action->SetOrigin(p_omni ? p_omni : MxOmni::GetInstance());
122 }
123}
124
125// FUNCTION: LEGO1 0x100b5200
127{
129
130 switch (m_currentTickleState) {
131 case e_ready:
132 ReadyTickle();
133
135 break;
136 }
137 case e_starting:
139
141 break;
142 }
143 case e_streaming:
145
147 break;
148 }
149 case e_repeating:
151
153 break;
154 }
155 case e_freezing:
157
159 break;
160 }
161 case e_done:
162 DoneTickle();
163 default:
164 break;
165 }
166
167 return SUCCESS;
168}
169
170// FUNCTION: LEGO1 0x100b52d0
172{
173 if (m_action && IsEnabled() != p_enable) {
174 MxU32 flags = m_action->GetFlags();
175
176 if (p_enable) {
178 }
179 else {
181 }
182 }
183}
184
185// FUNCTION: LEGO1 0x100b5310
186// FUNCTION: BETA10 0x1012e8bd
187const char* PresenterNameDispatch(const MxDSAction& p_action)
188{
189 const char* name = p_action.GetSourceName();
190 MxS32 format;
191
192 if (!name || strlen(name) == 0) {
193 switch (p_action.GetType()) {
195 format = ((MxDSAnim&) p_action).GetMediaFormat();
196 switch (format) {
197 case FOURCC(' ', 'F', 'L', 'C'):
198 name = !p_action.IsLooping() ? MxFlcPresenter::HandlerClassName()
200 break;
201 case FOURCC(' ', 'S', 'M', 'K'):
202 name = !p_action.IsLooping() ? MxSmkPresenter::HandlerClassName()
204 break;
205 }
206 break;
207
209 format = ((MxDSSound&) p_action).GetMediaFormat();
210 switch (format) {
211 case FOURCC(' ', 'M', 'I', 'D'):
212 name = !p_action.IsLooping() ? MxMIDIPresenter::HandlerClassName()
214 break;
215 case FOURCC(' ', 'W', 'A', 'V'):
217 break;
218 }
219 break;
220
225 break;
226
229 break;
230
233 break;
234 }
235 }
236
237 return name;
238}
239
240// FUNCTION: LEGO1 0x100b5410
241MxEntity* MxPresenter::CreateEntity(const char* p_defaultName)
242{
243 // create an object from LegoObjectFactory based on OBJECT: value in extra data.
244 // If that is missing, p_defaultName is used
245
246 char objectName[512];
247 strcpy(objectName, p_defaultName);
248
249 MxU16 extraLength;
250 char* extraData;
251 m_action->GetExtra(extraLength, extraData);
252
253 if (extraLength) {
254 char extraCopy[512];
255 memcpy(extraCopy, extraData, extraLength);
256 extraCopy[extraLength] = '\0';
257 KeyValueStringParse(objectName, g_strOBJECT, extraCopy);
258 }
259
260 return (MxEntity*) ObjectFactory()->Create(objectName);
261}
262
263// FUNCTION: LEGO1 0x100b54c0
264// FUNCTION: BETA10 0x1012ebaf
266{
268}
static const char * HandlerClassName()
[AI] Returns the handler class name ("MxCompositePresenter").
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
Definition: mxdsaction.h:17
MxU32 GetFlags()
[AI] Returns the flag field for this action (bitmask).
Definition: mxdsaction.h:177
MxBool IsLooping() const
[AI] Whether this action is set to loop based on current flags.
Definition: mxdsaction.h:270
void GetExtra(MxU16 &p_extraLength, char *&p_extraData)
[AI] Retrieves the extra data and its length for this action.
Definition: mxdsaction.h:168
void SetOrigin(MxCore *p_origin)
[AI] Sets the origin core pointer for this action, if spatially transforming/localizing this action.
Definition: mxdsaction.h:265
const Vector3 & GetLocation()
[AI] Gets the location vector for this action (world or local space).
Definition: mxdsaction.h:215
void SetFlags(MxU32 p_flags)
[AI] Sets the flag bitmask controlling action logic (enabled, looping, etc).
Definition: mxdsaction.h:183
@ c_world
[AI] Action is described in world-space coordinates [AI]
Definition: mxdsaction.h:27
@ c_enabled
[AI] Action is currently enabled [AI]
Definition: mxdsaction.h:25
Derived class representing an animation action extracted from SI files.
Definition: mxdsanim.h:14
@ e_serialAction
[AI] Series of actions to play in order. [AI]
Definition: mxdsobject.h:55
@ e_still
[AI] Still image resource. [AI]
Definition: mxdsobject.h:59
@ e_parallelAction
[AI] Parallel (simultaneous) action list. [AI]
Definition: mxdsobject.h:56
@ e_sound
[AI] Sound resource reference or cue. [AI]
Definition: mxdsobject.h:53
@ e_selectAction
[AI] Selects an action from several (with rules/random). [AI]
Definition: mxdsobject.h:58
@ e_anim
[AI] Animation sequence or reference. [AI]
Definition: mxdsobject.h:52
@ e_event
[AI] Scripted event type. [AI]
Definition: mxdsobject.h:57
Type GetType() const
[AI] Returns the object's type enum as stored in m_type.
Definition: mxdsobject.h:121
const char * GetSourceName() const
[AI] Returns the source name string (typically the originating SI file).
Definition: mxdsobject.h:124
[AI] Represents a sound action extracted from an SI script and used in the data-driven action system.
Definition: mxdssound.h:14
[AI] Notification parameter marking the end of an action, specialization of MxActionNotificationParam...
MxEntity is a base class for game entities which are uniquely identified by an integer ID and an Atom...
Definition: mxentity.h:22
static const char * HandlerClassName()
[AI] Returns the static class identifier for this presenter ("MxEventPresenter").
static const char * HandlerClassName()
[AI] Provides the class handler string for presenter registration/dispatch.
static const char * HandlerClassName()
[AI] Gets the handler class name string for dynamic presenter dispatch.
static const char * HandlerClassName()
[AI] Returns the concrete handler class name string for dynamic type identification and lookup,...
static const char * HandlerClassName()
[AI] Returns the handler class name used in presenter dispatching: "MxLoopingSmkPresenter".
static const char * HandlerClassName()
Returns the handler class name for this presenter.
MxResult Send(MxCore *p_listener, const MxNotificationParam &p_param)
[AI] Queues a notification to be sent to a specific registered listener.
[AI] Parameter object representing a single notification or event, carrying an identifier and sender ...
virtual MxCore * Create(const char *p_name)
[AI] Creates a new instance of the class matching the provided string name.
[AI] Central subsystem coordinator and singleton of the LEGO Island engine.
Definition: mxomni.h:32
static MxOmni * GetInstance()
[AI] Returns the singleton instance of the MxOmni subsystem coordinator.
Definition: mxomni.cpp:289
virtual MxEntity * AddToWorld(const char *, MxS32, MxPresenter *)
[AI] [VIRTUAL BASE] Placeholder virtual for derived engines to instantiate an entity and add to the 3...
Definition: mxomni.cpp:40
virtual void NotifyCurrentEntity(const MxNotificationParam &p_param)
[AI] [VIRTUAL BASE] Placeholder for derived implementations—sends a notification to the currently act...
Definition: mxomni.cpp:46
[AI] 2D point with 32-bit signed integer coordinates.
Definition: mxgeometry.h:487
[AI] Abstract base class for all presenter types in the LEGO Island engine, responsible for managing ...
Definition: mxpresenter.h:20
virtual void ParseExtra()
[AI] Parses additional data from the associated action for configuration or world interaction.
Definition: mxpresenter.cpp:80
MxS32 m_displayZ
[AI] Z-order value for display stacking.
Definition: mxpresenter.h:208
virtual void EndAction()
[AI] Terminates the current action, notifies listeners and resets state.
Definition: mxpresenter.cpp:59
void ProgressTickleState(TickleState p_tickleState)
[AI] Helper for advancing the presenter's tickle state and updating transition history.
Definition: mxpresenter.h:72
virtual void RepeatingTickle()
[AI] Handles updates when in a repeating (looping) stage. Advances to freezing state.
Definition: mxpresenter.h:58
virtual void Enable(MxBool p_enable)
[AI] Enables or disables this presenter (controls action flags accordingly).
MxBool IsEnabled()
[AI] Returns whether this presenter is logically enabled (based on the associated action's flags).
virtual MxResult StartAction(MxStreamController *, MxDSAction *)
[AI] Initiates presenter for a new action, setting up context and state.
Definition: mxpresenter.cpp:45
MxU32 m_previousTickleStates
[AI] Bitfield representing all tickle states that have already occurred during this lifetime.
Definition: mxpresenter.h:202
MxDSAction * m_action
[AI] The associated action currently being presented by this presenter.
Definition: mxpresenter.h:211
TickleState m_currentTickleState
[AI] Current state in the tickle lifecycle.
Definition: mxpresenter.h:199
virtual void StartingTickle()
[AI] Handles actions required when first starting presentation. Advances to streaming state.
Definition: mxpresenter.h:52
void Init()
[AI] Initializes object state to post-construction defaults.
Definition: mxpresenter.cpp:33
virtual void FreezingTickle()
[AI] Handles updates during the freezing/suspended state. Advances to done state.
Definition: mxpresenter.h:61
MxResult Tickle() override
[AI] Main tickle handler, called periodically to progress presenter's internal state.
MxEntity * CreateEntity(const char *p_defaultName)
[AI] Creates an entity based on action 'extra' data, or uses the provided default name.
@ e_repeating
[AI] Presentation is repeating (e.g., looping media).
Definition: mxpresenter.h:28
@ e_done
[AI] Completed processing the current action.
Definition: mxpresenter.h:30
@ e_idle
[AI] Not processing an action.
Definition: mxpresenter.h:24
@ e_ready
[AI] Prepared to start processing an action.
Definition: mxpresenter.h:25
@ e_freezing
[AI] Temporarily suspending updates or playback.
Definition: mxpresenter.h:29
@ e_starting
[AI] In the process of starting playback/presentation.
Definition: mxpresenter.h:26
@ e_streaming
[AI] Streaming or rendering actively.
Definition: mxpresenter.h:27
MxCriticalSection m_criticalSection
[AI] Thread synchronization for presenter state and data.
Definition: mxpresenter.h:214
virtual void StreamingTickle()
[AI] Handles periodic updates during the streaming/presentation stage. Advances to repeating state.
Definition: mxpresenter.h:55
MxCompositePresenter * m_compositePresenter
[AI] Owner composite presenter, if any.
Definition: mxpresenter.h:217
void SendToCompositePresenter(MxOmni *p_omni)
[AI] Notifies a composite presenter (if one exists) that this presenter wishes to join a group.
MxPoint32 m_location
[AI] 2D display location for the presenter.
Definition: mxpresenter.h:205
virtual void ReadyTickle()
[AI] Handles the transition and setup for the Ready state. Parses extra action data and advances stat...
Definition: mxpresenter.h:45
virtual void DoneTickle()
[AI] Handles any post-completion logic, resetting to idle state.
Definition: mxpresenter.h:65
static const char * HandlerClassName()
[AI] Returns the human-readable handler class name for this presenter type.
static const char * HandlerClassName()
[AI] Returns the handler class name string for this Presenter type ("MxStillPresenter").
[AI] Controller for streaming and managing multimedia resources and actions during gameplay.
static const char * HandlerClassName()
[AI] Returns the name identifying this presenter class.
#define TRUE
Definition: d3drmdef.h:28
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
const char * g_parseExtraTokens
[AI] Delimiter tokens for parsing extra parameters in scripts or command strings.
Definition: define.cpp:141
const char * g_strOBJECT
[AI] Used when referencing or distinguishing object instances in script actions or variable assignmen...
Definition: define.cpp:73
const char * g_strWORLD
[AI] Symbolic name used to reference a "WORLD" entity or property in scripts and object definitions.
Definition: define.cpp:125
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
#define AUTOLOCK(CS)
[AI] Macro for automatic locking using the MxAutoLock class. This macro instantiates an MxAutoLock ob...
Definition: mxautolock.h:5
MxObjectFactory * ObjectFactory()
[AI] Returns the factory for creating core engine objects from atom/type ids.
Definition: mxmisc.cpp:9
MxNotificationManager * NotificationManager()
[AI] Returns the notification manager for system-wide state/update notifications.
Definition: mxmisc.cpp:17
@ c_notificationPresenter
[AI] Update or event from a Presenter [AI]
@ c_notificationEndAction
[AI] Indicates the end of an action [AI]
const char * PresenterNameDispatch(const MxDSAction &p_action)
[AI] Provides a mapping from action object/type to the correct presenter handler class name based on ...
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
#define FOURCC(a, b, c, d)
[AI] Macro to compose a 32-bit code from four 8-bit characters (e.g., for resource and chunk IDs).
Definition: mxtypes.h:162
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned short MxU16
[AI]
Definition: mxtypes.h:20
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
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