Isle
Loading...
Searching...
No Matches
mxutilities.cpp
Go to the documentation of this file.
1#include "mxutilities.h"
2
4#include "mxdsaction.h"
5#include "mxdsactionlist.h"
6#include "mxdsfile.h"
7#include "mxdsmultiaction.h"
8#include "mxdsobject.h"
9#include "mxgeometry.h"
10#include "mxpresenterlist.h"
11
12#include <assert.h>
13
14// GLOBAL: LEGO1 0x101020e8
15void (*g_omniUserMessage)(const char*, MxS32) = NULL;
16
17// FUNCTION: LEGO1 0x100b6e10
18// FUNCTION: BETA10 0x10136970
20 MxS32 p_rect1Width,
21 MxS32 p_rect1Height,
22 MxS32 p_rect2Width,
23 MxS32 p_rect2Height,
24 MxS32* p_rect1Left,
25 MxS32* p_rect1Top,
26 MxS32* p_rect2Left,
27 MxS32* p_rect2Top,
28 MxS32* p_width,
29 MxS32* p_height
30)
31{
32 MxPoint32 rect1Origin(*p_rect1Left, *p_rect1Top);
33 MxRect32 rect1(MxPoint32(0, 0), MxSize32(p_rect1Width, p_rect1Height));
34
35 MxPoint32 rect2Origin(*p_rect2Left, *p_rect2Top);
36 MxRect32 rect2(MxPoint32(0, 0), MxSize32(p_rect2Width, p_rect2Height));
37
38 MxRect32 rect(0, 0, *p_width, *p_height);
39 rect += rect1Origin;
40
41 if (!rect.Intersects(rect1)) {
42 return FALSE;
43 }
44
45 rect &= rect1;
46 rect -= rect1Origin;
47 rect += rect2Origin;
48
49 if (!rect.Intersects(rect2)) {
50 return FALSE;
51 }
52
53 rect &= rect2;
54 rect -= rect2Origin;
55
56 *p_rect1Left += rect.GetLeft();
57 *p_rect1Top += rect.GetTop();
58 *p_rect2Left += rect.GetLeft();
59 *p_rect2Top += rect.GetTop();
60 *p_width = rect.GetWidth();
61 *p_height = rect.GetHeight();
62 return TRUE;
63}
64
65// FUNCTION: LEGO1 0x100b6ff0
66void MakeSourceName(char* p_output, const char* p_input)
67{
68 const char* cln = strchr(p_input, ':');
69 if (cln) {
70 p_input = cln + 1;
71 }
72
73 strcpy(p_output, p_input);
74
75 strlwr(p_output);
76
77 char* extLoc = strstr(p_output, ".si");
78 if (extLoc) {
79 *extLoc = 0;
80 }
81}
82
83// FUNCTION: LEGO1 0x100b7050
84// FUNCTION: BETA10 0x10136c19
85MxBool KeyValueStringParse(char* p_output, const char* p_command, const char* p_string)
86{
87 MxBool didMatch = FALSE;
88 assert(p_string);
89 assert(p_command);
90
91 MxS16 len = strlen(p_string);
92 char* string = new char[len + 1];
93 assert(string);
94 strcpy(string, p_string);
95
96 const char* delim = ", \t\r\n:";
97 for (char* token = strtok(string, delim); token; token = strtok(NULL, delim)) {
98 len -= (strlen(token) + 1);
99
100 if (strcmpi(token, p_command) == 0) {
101 if (p_output && len > 0) {
102 char* output = p_output;
103 char* cur = &token[strlen(p_command)];
104 cur++;
105 while (*cur != ',' && *cur != ' ' && *cur != '\0' && *cur != '\t' && *cur != '\n' && *cur != '\r') {
106 *output++ = *cur++;
107 }
108 *output = '\0';
109 }
110
111 didMatch = TRUE;
112 break;
113 }
114 }
115
116 delete[] string;
117 return didMatch;
118}
119
120// FUNCTION: LEGO1 0x100b7170
121// FUNCTION: BETA10 0x10136e12
123{
124 for (MxCompositePresenterList::iterator it = p_presenterList.begin(); it != p_presenterList.end(); it++) {
125 if (p_presenter == *it || ((*it)->IsA("MxCompositePresenter") &&
126 ContainsPresenter(*((MxCompositePresenter*) *it)->GetList(), p_presenter))) {
127 return TRUE;
128 }
129 }
130
131 return FALSE;
132}
133
134// FUNCTION: LEGO1 0x100b71e0
135void OmniError(const char* p_message, MxS32 p_status)
136{
137 if (g_omniUserMessage) {
138 g_omniUserMessage(p_message, p_status);
139 }
140 else if (p_status) {
141 abort();
142 }
143}
144
145// FUNCTION: LEGO1 0x100b7210
146void SetOmniUserMessage(void (*p_omniUserMessage)(const char*, MxS32))
147{
148 g_omniUserMessage = p_omniUserMessage;
149}
150
151// FUNCTION: LEGO1 0x100b7220
152// FUNCTION: BETA10 0x10136f37
153void FUN_100b7220(MxDSAction* p_action, MxU32 p_newFlags, MxBool p_setFlags)
154{
155 MxU32 oldFlags = p_action->GetFlags();
156 MxU32 newFlags;
157
158 if (p_setFlags) {
159 newFlags = oldFlags | p_newFlags;
160 }
161 else {
162 newFlags = oldFlags & ~p_newFlags;
163 }
164
165 p_action->SetFlags(newFlags);
166
167 if (p_action->IsA("MxDSMultiAction")) {
168 MxDSActionListCursor cursor(((MxDSMultiAction*) p_action)->GetActionList());
169 MxDSAction* action;
170
171 while (cursor.Next(action)) {
172 FUN_100b7220(action, p_newFlags, p_setFlags);
173 }
174 }
175}
[AI] STL list of MxPresenter pointers, used to manage multiple child presenters under composite contr...
[AI] Composite presenter that manages a collection of child presenters, orchestrating their actions a...
[AI] Convenience cursor class for iterating over an MxDSActionList.
[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 IsA(const char *p_name) const override
[AI] Run-time type check, compares provided name with this or any ancestor type.
Definition: mxdsaction.h:80
void SetFlags(MxU32 p_flags)
[AI] Sets the flag bitmask controlling action logic (enabled, looping, etc).
Definition: mxdsaction.h:183
[AI] Represents a container for multiple MxDSAction objects, facilitating the grouping and management...
MxBool Next()
[AI]
[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
[AI] Rectangle using 32-bit signed integer coordinates.
Definition: mxgeometry.h:706
T GetTop() const
[AI] Get the top edge.
Definition: mxgeometry.h:231
MxBool Intersects(const MxRect &p_r) const
[AI] Returns whether this rectangle intersects another.
Definition: mxgeometry.h:299
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] Size with 32-bit signed integer width and height.
Definition: mxgeometry.h:593
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
signed short MxS16
[AI]
Definition: mxtypes.h:26
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
void FUN_100b7220(MxDSAction *p_action, MxU32 p_newFlags, MxBool p_setFlags)
Recursively sets or clears flags for an MxDSAction and all sub-actions if applicable.
void MakeSourceName(char *p_output, const char *p_input)
Parses an SI source filename and normalizes it for use in the engine.
Definition: mxutilities.cpp:66
MxBool KeyValueStringParse(char *p_output, const char *p_command, const char *p_string)
Searches p_string for a key command and copies its associated value to p_output.
Definition: mxutilities.cpp:85
void(* g_omniUserMessage)(const char *, MxS32)
Definition: mxutilities.cpp:15
MxBool ContainsPresenter(MxCompositePresenterList &p_presenterList, MxPresenter *p_presenter)
Determines if a presenter exists within a composite presenter hierarchy.
void SetOmniUserMessage(void(*p_omniUserMessage)(const char *, MxS32))
Sets the callback to handle user messages, such as errors or logs, for the OMNI engine.
MxBool GetRectIntersection(MxS32 p_rect1Width, MxS32 p_rect1Height, MxS32 p_rect2Width, MxS32 p_rect2Height, MxS32 *p_rect1Left, MxS32 *p_rect1Top, MxS32 *p_rect2Left, MxS32 *p_rect2Top, MxS32 *p_width, MxS32 *p_height)
Computes intersection of two rectangles and modifies their positions and dimensions to the intersecti...
Definition: mxutilities.cpp:19
void OmniError(const char *p_message, MxS32 p_status)
Displays or logs an error message using the current user message handler, or aborts on error status i...