Isle
Loading...
Searching...
No Matches
mxstreamer.cpp
Go to the documentation of this file.
1#include "mxstreamer.h"
2
3#include "mxdebug.h"
5#include "mxdsaction.h"
6#include "mxmisc.h"
9
10#include <algorithm>
11#include <assert.h>
12
18
19// FUNCTION: LEGO1 0x100b8f00
20// FUNCTION: BETA10 0x10145150
22{
24}
25
26// FUNCTION: LEGO1 0x100b9190
27// FUNCTION: BETA10 0x10145220
29{
30 if (m_pool64.Allocate() || m_pool128.Allocate()) {
31 return FAILURE;
32 }
33
34 return SUCCESS;
35}
36
37// FUNCTION: LEGO1 0x100b91d0
38// FUNCTION: BETA10 0x10145268
40{
41 while (!m_controllers.empty()) {
42 MxStreamController* controller = m_controllers.front();
43
44#ifdef COMPAT_MODE
45 {
46 MxDSAction action;
47 assert(controller->IsStoped(&action));
48 }
49#else
50 assert(controller->IsStoped(&MxDSAction()));
51#endif
52
53 m_controllers.pop_front();
54 delete controller;
55 }
56
58}
59
60// FUNCTION: LEGO1 0x100b92c0
61// FUNCTION: BETA10 0x1014542d
62MxStreamController* MxStreamer::Open(const char* p_name, MxU16 p_lookupType)
63{
64 MxTrace("Open %s as %s controller\n", p_name, !p_lookupType ? "disk" : "RAM");
65 MxTrace("Heap before: %d\n", DebugHeapState());
66
67 MxStreamController* stream = NULL;
68
69 if (GetOpenStream(p_name)) {
70 goto done;
71 }
72
73 switch (p_lookupType) {
74 case e_diskStream:
75 stream = new MxDiskStreamController();
76 break;
77 case e_RAMStream:
78 stream = new MxRAMStreamController();
79 break;
80 }
81
82 if (stream == NULL) {
83 goto done;
84 }
85
86 if (stream->Open(p_name) != SUCCESS || AddStreamControllerToOpenList(stream) != SUCCESS) {
87 delete stream;
88 stream = NULL;
89 }
90
91done:
92 MxTrace("Heap after: %d\n", DebugHeapState());
93 return stream;
94}
95
96// FUNCTION: LEGO1 0x100b9570
97// FUNCTION: BETA10 0x10145638
98MxLong MxStreamer::Close(const char* p_name)
99{
100 MxDSAction ds;
101 ds.SetUnknown24(-2);
102
103 for (list<MxStreamController*>::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) {
104 MxStreamController* c = *it;
105
106 if (!p_name || c->GetAtom() == p_name) {
107 m_controllers.erase(it);
108
109 if (c->IsStoped(&ds)) {
110 delete c;
111 }
112 else {
114 }
115
116 return SUCCESS;
117 }
118 }
119
120 return FAILURE;
121}
122
123// FUNCTION: LEGO1 0x100b9700
124// FUNCTION: BETA10 0x10146ed0
126{
127 return new MxStreamerNotification(m_type, m_sender, m_controller);
128}
129
130// FUNCTION: LEGO1 0x100b9870
131// FUNCTION: BETA10 0x1014584b
133{
134 for (list<MxStreamController*>::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) {
135 if ((*it)->GetAtom() == p_name) {
136 return *it;
137 }
138 }
139
140 return NULL;
141}
142
143// FUNCTION: LEGO1 0x100b98f0
145{
146 MxStreamController* controller = GetOpenStream(p_action->GetAtomId().GetInternal());
147 if (controller && controller->IsA("MxDiskStreamController")) {
148 ((MxDiskStreamController*) controller)->FUN_100c8120(p_action);
149 }
150}
151
152// FUNCTION: LEGO1 0x100b9930
153// FUNCTION: BETA10 0x101458e5
155{
156 list<MxStreamController*>::iterator i = find(m_controllers.begin(), m_controllers.end(), p_stream);
157
158 assert(i == m_controllers.end());
159
160 // DECOMP: Retail is missing the optimization that skips this check if find() reaches the end.
161 if (i == m_controllers.end()) {
162 m_controllers.push_back(p_stream);
163 return SUCCESS;
164 }
165
166 return FAILURE;
167}
168
169// FUNCTION: LEGO1 0x100b99b0
170// FUNCTION: BETA10 0x101459ad
172{
173 // TODO: MxAtomId operator== used here for NULL test. BETA10 0x1007dc20
174 if (p_action == NULL || p_action->GetAtomId().GetInternal() == NULL || p_action->GetObjectId() == -1) {
175 return FAILURE;
176 }
177
178 MxStreamController* controller = GetOpenStream(p_action->GetAtomId().GetInternal());
179 if (controller == NULL) {
180 return FAILURE;
181 }
182
183 return controller->VTable0x20(p_action);
184}
185
186// FUNCTION: LEGO1 0x100b99f0
187// FUNCTION: BETA10 0x10145a54
189{
190 MxDSAction tempAction;
191
192 if (p_dsAction) {
193 tempAction.SetObjectId(p_dsAction->GetObjectId());
194 tempAction.SetAtomId(p_dsAction->GetAtomId());
195 tempAction.SetUnknown24(p_dsAction->GetUnknown24());
196 }
197 else {
198 tempAction.SetUnknown24(-2);
199 }
200
201 MxResult result = FAILURE;
202 for (list<MxStreamController*>::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) {
203 // TODO: MxAtomId operator== used here for NULL test. BETA10 0x1007dc20
204 if (p_dsAction->GetAtomId().GetInternal() == NULL || p_dsAction->GetAtomId() == (*it)->GetAtom()) {
205 tempAction.SetAtomId((*it)->GetAtom());
206 result = (*it)->VTable0x24(&tempAction);
207 }
208 }
209
210 return result;
211}
212
213// FUNCTION: LEGO1 0x100b9b30
214// FUNCTION: BETA10 0x10145d01
216{
217 MxStreamController* controller = GetOpenStream(p_dsObject.GetAtomId().GetInternal());
218 if (controller) {
219 return controller->IsStoped(&p_dsObject);
220 }
221 return TRUE;
222}
223
224// FUNCTION: LEGO1 0x100b9b60
225// FUNCTION: BETA10 0x10145d51
227{
228 MxStreamerNotification& s = static_cast<MxStreamerNotification&>(p_param);
229
230 switch (s.GetNotification()) {
232 // DECOMP: Beta does not use a variable, but this matches retail better.
234
235 MxDSAction ds;
236 ds.SetUnknown24(-2);
237
238 if (c->IsStoped(&ds)) {
239 delete c;
240 }
241 else {
243 }
244
245 break;
246 }
247 default:
248 assert(0);
249 break;
250 }
251
252 return 0;
253}
const char * GetInternal() const
[AI] Returns a pointer to the internal string, or nullptr if not set.
Definition: mxatom.h:194
Templated fixed-size bitset for bit manipulation.
Definition: mxbitset.h:18
[AI] Represents an action deserialized from SI chunks, holding key animation or script parameters suc...
Definition: mxdsaction.h:17
[AI] Base class for any object deserialized from an SI (script/data) file in the LEGO Island engine.
Definition: mxdsobject.h:44
const MxAtomId & GetAtomId()
[AI] Returns a const-reference to the object's atom identifier.
Definition: mxdsobject.h:133
virtual void SetAtomId(MxAtomId p_atomId)
[AI] Sets the atom id for this object instance, used for indexing or lookup.
Definition: mxdsobject.h:118
void SetUnknown24(MxS16 p_unk0x24)
[AI] Sets the unknown field at 0x24 (possibly version/state).
Definition: mxdsobject.h:151
MxS16 GetUnknown24()
[AI] Returns the unknown 0x24 value (may be data version or usage state). [AI]
Definition: mxdsobject.h:136
void SetObjectId(MxU32 p_objectId)
[AI] Sets the object id (for serialization or lookup).
Definition: mxdsobject.h:147
MxU32 GetObjectId()
[AI] Returns the object id numeric value.
Definition: mxdsobject.h:130
[AI] Controller for streaming from disk-based SI resources, manages buffers and streaming actions.
MxResult Allocate()
[AI] Allocates the memory pool according to template parameters.
Definition: mxmemorypool.h:71
void Unregister(MxCore *p_listener)
[AI] Removes a previously registered listener and flushes any pending notifications for it.
void Register(MxCore *p_listener)
[AI] Registers a listener object to receive notifications.
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 ...
NotificationId GetNotification() const
[AI] Retrieves the current notification type of this parameter.
MxCore * m_sender
[AI] Pointer to the MxCore instance that sent or originated this notification.
NotificationId m_type
[AI] Type of notification/event carried by this object (see NotificationId).
[AI] MxParam serves as a polymorphic base class for parameter passing in event and notification syste...
Definition: mxparam.h:7
Derived stream controller that manages media streaming from memory buffers as opposed to disk.
[AI] Controller for streaming and managing multimedia resources and actions during gameplay.
virtual MxResult VTable0x20(MxDSAction *p_action)
[AI] Streams data for the provided action by determining data offset and reading required chunk.
MxBool IsStoped(MxDSObject *p_obj)
[AI] Checks if the streaming operation for a given object/action has fully stopped and no longer has ...
virtual MxResult Open(const char *p_filename)
[AI] Opens a data stream with the specified resource filename.
MxBool IsA(const char *p_name) const override
[AI] Performs runtime type checking, matching the given name with this or any parent class.
MxAtomId & GetAtom()
[AI] Retrieves the atom ID (unique logical identifier) for this stream controller.
Streamer notification param for streaming events in MxStreamer [AI].
Definition: mxstreamer.h:27
MxStreamController * GetController()
[AI] Retrieve the stream controller associated with this notification.
Definition: mxstreamer.h:51
MxNotificationParam * Clone() const override
[AI] Clone this notification param.
Definition: mxstreamer.cpp:125
Streams and manages media data, handles memory pools for RAM/disk streaming [AI].
Definition: mxstreamer.h:65
MxStreamController * Open(const char *p_name, MxU16 p_openMode)
Open a stream, returning a controller for further access [AI].
Definition: mxstreamer.cpp:62
MxResult DeleteObject(MxDSAction *p_dsAction)
Ask all controllers to remove a DS Action's object.
Definition: mxstreamer.cpp:188
MxBool FUN_100b9b30(MxDSObject &p_dsObject)
Check stream state for a dsObject's Atom ID.
Definition: mxstreamer.cpp:215
MxResult AddStreamControllerToOpenList(MxStreamController *p_stream)
Add a controller to the open list, asserting if already present.
Definition: mxstreamer.cpp:154
MxStreamController * GetOpenStream(const char *p_name)
Search for and return an open stream controller with a matching name.
Definition: mxstreamer.cpp:132
~MxStreamer() override
Destructor—Stops all stream controllers and unregisters from notification manager.
Definition: mxstreamer.cpp:39
MxLong Notify(MxParam &p_param) override
Handle notifications, including deferred controller deletion [AI].
Definition: mxstreamer.cpp:226
MxLong Close(const char *p_name)
Close a named stream and remove its controller from the open list [AI].
Definition: mxstreamer.cpp:98
MxResult FUN_100b99b0(MxDSAction *p_action)
Internal: Calls stream controller's specific command for action execution.
Definition: mxstreamer.cpp:171
MxStreamer()
Construct a streamer and register it for notifications.
Definition: mxstreamer.cpp:21
@ e_diskStream
Load streaming resource from disk [AI].
Definition: mxstreamer.h:71
@ e_RAMStream
Load streaming resource fully to RAM [AI].
Definition: mxstreamer.h:72
virtual MxResult Create()
Allocate memory pools needed for streaming operation.
Definition: mxstreamer.cpp:28
void FUN_100b98f0(MxDSAction *p_action)
Internal: Delegate stream operation on MxDSAction to a DiskStreamController if present.
Definition: mxstreamer.cpp:144
#define TRUE
Definition: d3drmdef.h:28
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#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
#define MxTrace(args)
[AI] Macro for trace logging (non-variadic version, MSVC compatibility), expands to nothing.
Definition: mxdebug.h:55
MxNotificationManager * NotificationManager()
[AI] Returns the notification manager for system-wide state/update notifications.
Definition: mxmisc.cpp:17
@ c_notificationStreamer
[AI] Event related to a Streamer [AI]
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
int MxLong
[AI]
Definition: mxtypes.h:83
unsigned short MxU16
[AI]
Definition: mxtypes.h:20