Isle
Loading...
Searching...
No Matches
mxvideomanager.cpp
Go to the documentation of this file.
1#include "mxvideomanager.h"
2
3#include "mxautolock.h"
4#include "mxdisplaysurface.h"
5#include "mxmisc.h"
6#include "mxomni.h"
7#include "mxpalette.h"
8#include "mxpresenter.h"
9#include "mxregion.h"
10#include "mxticklemanager.h"
11#include "mxticklethread.h"
12
14
15// FUNCTION: LEGO1 0x100be1f0
17{
18 Init();
19}
20
21// FUNCTION: LEGO1 0x100be270
22void MxVideoManager::UpdateView(MxU32 p_x, MxU32 p_y, MxU32 p_width, MxU32 p_height)
23{
24}
25
26// FUNCTION: LEGO1 0x100be2a0
28{
30}
31
32// FUNCTION: LEGO1 0x100be320
34{
38 m_region = NULL;
41 return SUCCESS;
42}
43
44// FUNCTION: LEGO1 0x100be340
45void MxVideoManager::Destroy(MxBool p_fromDestructor)
46{
47 if (m_thread) {
49 delete m_thread;
50 }
51 else {
53 }
54
56
57 if (m_displaySurface) {
58 delete m_displaySurface;
59 }
60
61 if (m_region) {
62 delete m_region;
63 }
64
66 delete m_videoParam.GetPalette();
67 }
68
69 if (m_unk0x60) {
70 if (m_pDirectDraw) {
71 m_pDirectDraw->Release();
72 }
73 if (m_pDirect3D) {
74 m_pDirect3D->Release();
75 }
76 }
77
78 Init();
80
81 if (!p_fromDestructor) {
83 }
84}
85
86// FUNCTION: LEGO1 0x100be3e0
87// FUNCTION: BETA10 0x1012cdaa
89{
90 if (m_region->IsEmpty() == FALSE) {
92 rect &= m_videoParam.GetRect();
93
95 ->Display(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
96 }
97}
98
99// FUNCTION: LEGO1 0x100be440
100// FUNCTION: BETA10 0x1012ce5e
102{
103 if (m_presenters->GetNumElements() <= 1) {
104 return;
105 }
106
109 MxU32 count = m_presenters->GetNumElements() - 1;
110 MxBool finished;
111
112 if (count != 0) {
113 do {
114 a.Reset();
115 b.Head();
116
117 finished = TRUE;
118 for (MxU32 i = count; i != 0; i--) {
119 MxPresenter *presenterA, *presenterB;
120
121 a.Next(presenterA);
122 b.Next(presenterB);
123
124 if (presenterA->GetDisplayZ() < presenterB->GetDisplayZ()) {
125 a.SetValue(presenterB);
126 b.SetValue(presenterA);
127 finished = FALSE;
128 }
129 }
130 } while (!finished && --count != 0);
131 }
132}
133
134// FUNCTION: LEGO1 0x100be600
136 MxVideoParam& p_videoParam,
137 LPDIRECTDRAW p_pDirectDraw,
138 LPDIRECT3D2 p_pDirect3D,
139 LPDIRECTDRAWSURFACE p_ddSurface1,
140 LPDIRECTDRAWSURFACE p_ddSurface2,
141 LPDIRECTDRAWCLIPPER p_ddClipper,
142 MxU32 p_frequencyMS,
143 MxBool p_createThread
144)
145{
146 MxBool locked = FALSE;
147 MxResult status = FAILURE;
148
150
152 goto done;
153 }
154
156 locked = TRUE;
157
158 m_videoParam = p_videoParam;
159 m_region = new MxRegion();
160
161 if (!m_region) {
162 goto done;
163 }
164
165 m_pDirectDraw = p_pDirectDraw;
166 m_pDirect3D = p_pDirect3D;
167
168 MxPalette* palette;
169 if (p_videoParam.GetPalette() == NULL) {
170 palette = new MxPalette();
171 m_videoParam.SetPalette(palette);
172
173 if (!palette) {
174 goto done;
175 }
176 }
177 else {
178 palette = p_videoParam.GetPalette()->Clone();
179 m_videoParam.SetPalette(palette);
180
181 if (!palette) {
182 goto done;
183 }
184 }
185
187 if (m_displaySurface && m_displaySurface->Init(m_videoParam, p_ddSurface1, p_ddSurface2, p_ddClipper) == SUCCESS) {
189
190 if (p_createThread) {
191 m_thread = new MxTickleThread(this, p_frequencyMS);
192
193 if (!m_thread || m_thread->Start(0, 0) != SUCCESS) {
194 goto done;
195 }
196 }
197 else {
198 TickleManager()->RegisterClient(this, p_frequencyMS);
199 }
200
201 status = SUCCESS;
202 }
203
204done:
205 if (status != SUCCESS) {
206 Destroy();
207 }
208
209 if (locked) {
211 }
212
213 return status;
214}
215
216// FUNCTION: LEGO1 0x100be820
217MxResult MxVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyMS, MxBool p_createThread)
218{
219 MxBool locked = FALSE;
220 MxResult status = FAILURE;
221
222 m_unk0x60 = TRUE;
223
225 goto done;
226 }
227
229 locked = TRUE;
230
231 m_videoParam = p_videoParam;
232 m_region = new MxRegion();
233
234 if (!m_region) {
235 goto done;
236 }
237
238 if (DirectDrawCreate(NULL, &m_pDirectDraw, NULL) != DD_OK) {
239 goto done;
240 }
241
242 if (m_pDirectDraw->SetCooperativeLevel(MxOmni::GetInstance()->GetWindowHandle(), DDSCL_NORMAL) != DD_OK) {
243 goto done;
244 }
245
246 MxPalette* palette;
247 if (p_videoParam.GetPalette() == NULL) {
248 palette = new MxPalette();
249 m_videoParam.SetPalette(palette);
250
251 if (!palette) {
252 goto done;
253 }
254 }
255 else {
256 palette = p_videoParam.GetPalette()->Clone();
257 m_videoParam.SetPalette(palette);
258
259 if (!palette) {
260 goto done;
261 }
262 }
263
267
268 if (p_createThread) {
269 m_thread = new MxTickleThread(this, p_frequencyMS);
270
271 if (!m_thread || m_thread->Start(0, 0) != SUCCESS) {
272 goto done;
273 }
274 }
275 else {
276 TickleManager()->RegisterClient(this, p_frequencyMS);
277 }
278
279 status = SUCCESS;
280 }
281
282done:
283 if (status != SUCCESS) {
284 Destroy();
285 }
286
287 if (locked) {
289 }
290
291 return status;
292}
293
294// FUNCTION: LEGO1 0x100bea50
296{
297 Destroy(FALSE);
298}
299
300// FUNCTION: LEGO1 0x100bea60
302{
304
305 if (m_region) {
306 m_region->AddRect(p_rect);
307 }
308
310}
311
312// FUNCTION: LEGO1 0x100bea90
314{
316
318
319 MxPresenter* presenter;
321
322 while (cursor.Next(presenter)) {
323 presenter->Tickle();
324 }
325
326 cursor.Reset();
327
328 while (cursor.Next(presenter)) {
329 presenter->PutData();
330 }
331
332 UpdateRegion();
333 m_region->Reset();
334
335 return SUCCESS;
336}
337
338// FUNCTION: LEGO1 0x100bebe0
340{
341 PALETTEENTRY paletteEntries[256];
342
344
345 if (p_palette && m_videoParam.GetPalette()) {
346 p_palette->GetEntries(paletteEntries);
347 m_videoParam.GetPalette()->SetEntries(paletteEntries);
349 }
350
352 return SUCCESS;
353}
void Enter()
[AI] Acquires/gains entry to the critical section or mutex, blocking if not available.
void Leave()
[AI] Releases/leaves the critical section or mutex.
Provides a DirectDraw-based drawing surface for blitting bitmaps, managing palette,...
virtual MxResult Create(MxVideoParam &p_videoParam)
[AI] Creates DirectDraw surfaces and initializes based on the desired video mode.
virtual void SetPalette(MxPalette *p_palette)
[AI] Sets the palette used for the primary and secondary DirectDraw surfaces.
virtual MxResult Init(MxVideoParam &p_videoParam, LPDIRECTDRAWSURFACE p_ddSurface1, LPDIRECTDRAWSURFACE p_ddSurface2, LPDIRECTDRAWCLIPPER p_ddClipper)
[AI] Initializes the surface object with given video parameters, DirectDraw surfaces,...
virtual void Display(MxS32 p_left, MxS32 p_top, MxS32 p_left2, MxS32 p_top2, MxS32 p_width, MxS32 p_height)
[AI] Presents the back buffer contents to the front buffer or window.
MxBool Next()
[AI]
MxBool Head()
[AI]
Definition: mxlist.h:252
void Reset()
[AI]
Definition: mxlist.h:269
void SetValue(T p_obj)
[AI]
MxU32 GetNumElements()
[AI]
Definition: mxlist.h:118
MxPresenterList * m_presenters
[AI] Pointer to list of currently registered (active) presenters.
MxCriticalSection m_criticalSection
[AI] Critical section object used for guarding access to the presenter list and internal members for ...
MxThread * m_thread
[AI] Optional pointer to a worker thread used for media dispatch/IO (if multi-threaded operation is u...
virtual void Destroy()
[AI] Destroys all registered presenters and resets the internal state, ensuring safe resource disposa...
virtual MxResult Create()
[AI] Allocates and initializes the internal presenter list for this manager, ensuring thread safety.
static MxOmni * GetInstance()
[AI] Returns the singleton instance of the MxOmni subsystem coordinator.
Definition: mxomni.cpp:289
HWND GetWindowHandle() const
[AI] Gets the window handle (HWND) associated with the engine (ownership not transferred).
Definition: mxomni.h:192
[AI] Encapsulates a DirectDraw 8-bit (256 color) palette for use with DirectX rendering.
Definition: mxpalette.h:17
MxResult SetEntries(LPPALETTEENTRY p_palette)
[AI] Sets the palette's RGB entries from an external array and updates the DirectDraw palette if atta...
Definition: mxpalette.cpp:178
MxPalette * Clone()
[AI] Creates a duplicate of this palette object with the same palette data and override flag.
Definition: mxpalette.cpp:160
MxResult GetEntries(LPPALETTEENTRY p_entries)
[AI] Copies all palette entries to external buffer.
Definition: mxpalette.cpp:170
[AI] Cursor/iterator for traversing an MxPresenterList.
[AI] Abstract base class for all presenter types in the LEGO Island engine, responsible for managing ...
Definition: mxpresenter.h:20
virtual MxResult PutData()
[AI] Allows the presenter to submit pending results or output to the engine.
Definition: mxpresenter.h:112
MxResult Tickle() override
[AI] Main tickle handler, called periodically to progress presenter's internal state.
MxS32 GetDisplayZ() const
[AI] Returns the display Z (depth) order.
Definition: mxpresenter.h:172
[AI] Rectangle using 32-bit signed integer coordinates.
Definition: mxgeometry.h:706
T GetTop() const
[AI] Get the top edge.
Definition: mxgeometry.h:231
T GetWidth() const
[AI] Get the rectangle's width.
Definition: mxgeometry.h:262
T GetHeight() const
[AI] Get the rectangle's height.
Definition: mxgeometry.h:268
T GetLeft() const
[AI] Get the left edge.
Definition: mxgeometry.h:221
[AI] Represents a 2D region as a set of vertical spans each containing one or more horizontal segment...
Definition: mxregion.h:327
virtual void Reset()
[AI] Removes all spans and resets the bounding rectangle to an empty state.
Definition: mxregion.cpp:27
MxRect32 & GetBoundingRect()
[AI] Returns a reference to the current bounding rectangle for the region.
Definition: mxregion.h:346
virtual void AddRect(MxRect32 &p_rect)
[AI] Adds a rectangle to this region, merging or splitting spans and segments as necessary.
Definition: mxregion.cpp:35
virtual MxBool IsEmpty()
[AI] Returns TRUE if the region contains zero spans (i.e., is empty).
Definition: mxregion.h:369
void Terminate()
[AI] Signals the thread to terminate.
Definition: mxthread.cpp:50
MxResult Start(MxS32 p_stackSize, MxS32 p_flag)
[AI] Starts the thread with a given stack size and creation flags.
Definition: mxthread.cpp:28
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.
MxTickleThread periodically calls Tickle() on a target MxCore object in a separate thread.
[AI] Video subsystem manager for DirectDraw/Direct3D video rendering and presenter control.
MxResult Tickle() override
[AI] Runs the per-frame tick/update including presenter tickle, surface update, and region display.
virtual MxResult VTable0x28(MxVideoParam &p_videoParam, LPDIRECTDRAW p_pDirectDraw, LPDIRECT3D2 p_pDirect3D, LPDIRECTDRAWSURFACE p_ddSurface1, LPDIRECTDRAWSURFACE p_ddSurface2, LPDIRECTDRAWCLIPPER p_ddClipper, MxU32 p_frequencyMS, MxBool p_createThread)
[AI] Main DirectDraw/Direct3D allocator and presenter chain creation.
LPDIRECT3D2 m_pDirect3D
[AI] Direct3D2 interface pointer, for 3D presentation and device context. [0x54]
MxResult Init()
[AI] Initializes video resources and zeros pointers for this manager.
virtual MxResult RealizePalette(MxPalette *p_palette)
[AI] Applies (realizes) the palette to both MxVideoParam and hardware palette, and updates the displa...
virtual void UpdateView(MxU32 p_x, MxU32 p_y, MxU32 p_width, MxU32 p_height)
[AI] Updates the visible video sub-rectangle inside the overall frame; typically for sub-region blits...
void UpdateRegion()
[AI] Updates the portion of the display surface that is marked dirty based on m_region,...
MxBool m_unk0x60
[AI] TRUE if manager owns the DirectDraw/Direct3D objects and should release them; FALSE if external....
void InvalidateRect(MxRect32 &p_rect)
[AI] Invalidates a rectangular region in the display; marks it for redraw on next tick.
void Destroy() override
[AI] Releases all display/video resources, any DirectDraw/Direct3D handles, and associated objects.
~MxVideoManager() override
[AI] Destructor; cleans up all allocated resources (DirectDraw, display surface, etc....
MxVideoParam m_videoParam
[AI] Video configuration, containing palette, source/dest rectangles, and other state....
MxRegion * m_region
[AI] Tracks regions that have been invalidated and need to be updated/redrawn. [0x5c]
MxDisplaySurface * m_displaySurface
[AI] Concrete blitting/output surface where final image is copied each frame. [0x58]
LPDIRECTDRAW m_pDirectDraw
[AI] DirectDraw interface pointer. May be allocated here, or passed in/injected. [0x50]
void SortPresenterList()
[AI] Sorts presenters in descending Z order for proper overdraw order during tickle (bubble-sort).
[AI] Video parameter configuration for display and rendering, encapsulates resolution,...
Definition: mxvideoparam.h:14
void SetPalette(MxPalette *p_palette)
[AI] Assign the palette pointer (color indexing) for the video mode.
Definition: mxvideoparam.h:57
MxPalette * GetPalette()
[AI] Get the palette used for rendering (may be NULL if not set).
Definition: mxvideoparam.h:53
MxRect32 & GetRect()
[AI] Get the rectangle specifying the display dimensions and screen area.
Definition: mxvideoparam.h:49
struct IDirect3D2 * LPDIRECT3D2
Definition: d3d.h:86
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DDSCL_NORMAL
Definition: ddraw.h:2546
struct IDirectDrawClipper FAR * LPDIRECTDRAWCLIPPER
Definition: ddraw.h:79
struct IDirectDrawSurface FAR * LPDIRECTDRAWSURFACE
Definition: ddraw.h:74
#define DD_OK
Definition: ddraw.h:3166
struct IDirectDraw FAR * LPDIRECTDRAW
Definition: ddraw.h:72
#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 AUTOLOCK(CS)
[AI] Macro for automatic locking using the MxAutoLock class. This macro instantiates an MxAutoLock ob...
Definition: mxautolock.h:5
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 int MxU32
[AI]
Definition: mxtypes.h:32