Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 20 | pmbaty | 1 | #include <stdio.h> |
| 2 | |||
| 3 | #include "CORE/FW/brlists.h" |
||
| 4 | #include "CORE/FW/fwsetup.h" |
||
| 5 | #include "CORE/FW/pattern.h" |
||
| 6 | #include "CORE/FW/resource.h" |
||
| 7 | #include "CORE/MATH/matrix34.h" |
||
| 8 | #include "CORE/MATH/transfrm.h" |
||
| 9 | #include "CORE/V1DB/dbsetup.h" |
||
| 10 | #include "CORE/V1DB/enables.h" |
||
| 11 | #include "actsupt.h" |
||
| 12 | #include "harness/trace.h" |
||
| 13 | |||
| 14 | // IDA: br_uint_32 __cdecl BrActorEnum(br_actor *parent, br_actor_enum_cbfn *callback, void *arg) |
||
| 15 | br_uint_32 BrActorEnum(br_actor* parent, br_actor_enum_cbfn* callback, void* arg) { |
||
| 16 | br_actor* a; |
||
| 17 | br_actor* next; |
||
| 18 | br_uint_32 r; |
||
| 19 | LOG_TRACE("(%p, %p, %p)", parent, callback, arg); |
||
| 20 | |||
| 21 | a = parent->children; |
||
| 22 | |||
| 23 | while (a) { |
||
| 24 | next = a->next; |
||
| 25 | |||
| 26 | if ((r = callback(a, arg))) |
||
| 27 | return r; |
||
| 28 | |||
| 29 | a = next; |
||
| 30 | } |
||
| 31 | |||
| 32 | return 0; |
||
| 33 | } |
||
| 34 | |||
| 35 | // IDA: br_uint_32 __cdecl BrActorSearchMany(br_actor *root, char *pattern, br_actor **actors, int max) |
||
| 36 | br_uint_32 BrActorSearchMany(br_actor* root, char* pattern, br_actor** actors, int max) { |
||
| 37 | br_actor* a; |
||
| 38 | char* sub; |
||
| 39 | int n; |
||
| 40 | int remaining; |
||
| 41 | LOG_TRACE("(%p, \"%s\", %p, %d)", root, pattern, actors, max); |
||
| 42 | |||
| 43 | sub = NULL; |
||
| 44 | if (pattern != NULL) { |
||
| 45 | while (*pattern == '/') { |
||
| 46 | pattern++; |
||
| 47 | } |
||
| 48 | sub = pattern; |
||
| 49 | while (*sub != '\0' && *sub != '/') { |
||
| 50 | sub++; |
||
| 51 | } |
||
| 52 | while (*sub == '/') { |
||
| 53 | sub++; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | a = root->children; |
||
| 57 | remaining = max; |
||
| 58 | while (a != NULL && remaining > 0) { |
||
| 59 | if (BrNamePatternMatch(pattern, a->identifier) != 0) { |
||
| 60 | if (sub == NULL || *sub == '\0') { |
||
| 61 | *actors = a; |
||
| 62 | actors++; |
||
| 63 | remaining--; |
||
| 64 | } else { |
||
| 65 | n = BrActorSearchMany(a, sub, actors, remaining); |
||
| 66 | actors += n; |
||
| 67 | remaining -= n; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | a = a->next; |
||
| 71 | } |
||
| 72 | return max - remaining; |
||
| 73 | } |
||
| 74 | |||
| 75 | // IDA: br_actor* __cdecl BrActorSearch(br_actor *root, char *pattern) |
||
| 76 | br_actor* BrActorSearch(br_actor* root, char* pattern) { |
||
| 77 | br_actor* a; |
||
| 78 | LOG_TRACE("(%p, \"%s\")", root, pattern); |
||
| 79 | |||
| 80 | if (BrActorSearchMany(root, pattern, &a, 1) == 1) { |
||
| 81 | return a; |
||
| 82 | } |
||
| 83 | return NULL; |
||
| 84 | } |
||
| 85 | |||
| 86 | // IDA: void __usercall RenumberActor(br_actor *a@<EAX>, int d@<EDX>) |
||
| 87 | void RenumberActor(br_actor* a, int d) { |
||
| 88 | br_actor* ac; |
||
| 89 | LOG_TRACE("(%p, %d)", a, d); |
||
| 90 | |||
| 91 | ac = a->children; |
||
| 92 | a->depth = d; |
||
| 93 | while (ac != NULL) { |
||
| 94 | RenumberActor(ac, d + 1); |
||
| 95 | ac = ac->next; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // IDA: br_actor* __cdecl BrActorAdd(br_actor *parent, br_actor *a) |
||
| 100 | br_actor* BrActorAdd(br_actor* parent, br_actor* a) { |
||
| 101 | br_actor* ac; |
||
| 102 | br_actor* ac2; |
||
| 103 | LOG_TRACE("(%p, %p)", parent, a); |
||
| 104 | |||
| 105 | BrSimpleAddHead((br_simple_list*)&parent->children, (br_simple_node*)a); |
||
| 106 | a->parent = parent; |
||
| 107 | |||
| 108 | a->depth = parent->depth + 1; |
||
| 109 | for (ac = a->children; ac != NULL; ac = ac->next) { |
||
| 110 | ac->depth = a->depth + 1; |
||
| 111 | ac2 = ac->children; |
||
| 112 | while (ac2 != NULL) { |
||
| 113 | RenumberActor(ac2, a->depth + 2); |
||
| 114 | ac2 = ac2->next; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | return a; |
||
| 118 | } |
||
| 119 | |||
| 120 | // IDA: br_actor* __cdecl BrActorRemove(br_actor *a) |
||
| 121 | br_actor* BrActorRemove(br_actor* a) { |
||
| 122 | br_actor* ac; |
||
| 123 | LOG_TRACE("(%p)", a); |
||
| 124 | |||
| 125 | br_actor* ac2; // Added ? |
||
| 126 | |||
| 127 | BrSimpleRemove((br_simple_node*)a); |
||
| 128 | a->parent = NULL; |
||
| 129 | a->depth = 0; |
||
| 130 | |||
| 131 | for (ac2 = a->children; ac2; ac2 = ac2->next) { |
||
| 132 | ac2->depth = 1; |
||
| 133 | for (ac = ac2->children; ac; ac = ac->next) { |
||
| 134 | RenumberActor(ac, 2); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | return a; |
||
| 138 | } |
||
| 139 | |||
| 140 | // IDA: void __cdecl BrActorRelink(br_actor *parent, br_actor *a) |
||
| 141 | void BrActorRelink(br_actor* parent, br_actor* a) { |
||
| 142 | br_matrix34 mat; |
||
| 143 | LOG_TRACE("(%p, %p)", parent, a); |
||
| 144 | |||
| 145 | if (a->parent == parent) { |
||
| 146 | return; |
||
| 147 | } |
||
| 148 | |||
| 149 | BrActorToActorMatrix34(&mat, a, parent); |
||
| 150 | BrMatrix34ToTransform(&a->t, &mat); |
||
| 151 | BrActorAdd(parent, BrActorRemove(a)); |
||
| 152 | } |
||
| 153 | |||
| 154 | // IDA: br_actor* __cdecl BrActorAllocate(br_uint_8 type, void *type_data) |
||
| 155 | br_actor* BrActorAllocate(br_uint_8 type, void* type_data) { |
||
| 156 | br_actor* a; |
||
| 157 | br_light* light; |
||
| 158 | br_camera* camera; |
||
| 159 | br_bounds* bounds; |
||
| 160 | br_vector4* clip_plane; |
||
| 161 | LOG_TRACE("(%d, %p)", type, type_data); |
||
| 162 | |||
| 163 | a = BrResAllocate(v1db.res, sizeof(br_actor), BR_MEMORY_ACTOR); |
||
| 164 | BrSimpleNewList((br_simple_list*)&a->children); |
||
| 165 | a->type = type; |
||
| 166 | a->depth = 0; |
||
| 167 | a->t.type = 0; |
||
| 168 | a->type_data = NULL; |
||
| 169 | BrMatrix34Identity(&a->t.t.mat); |
||
| 170 | |||
| 171 | if (type_data) { |
||
| 172 | a->type_data = type_data; |
||
| 173 | } else { |
||
| 174 | switch (type) { |
||
| 175 | case BR_ACTOR_NONE: |
||
| 176 | break; |
||
| 177 | case BR_ACTOR_LIGHT: |
||
| 178 | light = BrResAllocate(a, sizeof(br_light), BR_MEMORY_LIGHT); |
||
| 179 | a->type_data = light; |
||
| 180 | light->type = BR_LIGHT_DIRECT; |
||
| 181 | light->colour = BR_COLOUR_RGB(255, 255, 255); |
||
| 182 | light->attenuation_c = 1.0f; |
||
| 183 | light->cone_outer = BR_ANGLE_DEG(15); |
||
| 184 | light->cone_inner = BR_ANGLE_DEG(10); |
||
| 185 | break; |
||
| 186 | case BR_ACTOR_CAMERA: |
||
| 187 | camera = (br_camera*)BrResAllocate(a, sizeof(br_camera), BR_MEMORY_CAMERA); |
||
| 188 | a->type_data = camera; |
||
| 189 | camera->type = BR_CAMERA_PERSPECTIVE_FOV; |
||
| 190 | camera->field_of_view = BR_ANGLE_DEG(45.0f); |
||
| 191 | camera->hither_z = 1.0f; |
||
| 192 | camera->yon_z = 10.0f; |
||
| 193 | camera->aspect = 1.0f; |
||
| 194 | break; |
||
| 195 | case BR_ACTOR_BOUNDS: |
||
| 196 | case BR_ACTOR_BOUNDS_CORRECT: |
||
| 197 | bounds = BrResAllocate(a, sizeof(br_bounds), BR_MEMORY_CLIP_PLANE); |
||
| 198 | a->type_data = bounds; |
||
| 199 | break; |
||
| 200 | case BR_ACTOR_CLIP_PLANE: |
||
| 201 | clip_plane = BrResAllocate(a, sizeof(br_vector4), BR_MEMORY_CLIP_PLANE); |
||
| 202 | clip_plane->v[0] = 0; |
||
| 203 | clip_plane->v[1] = 0; |
||
| 204 | clip_plane->v[2] = 1.0; |
||
| 205 | clip_plane->v[3] = 0; |
||
| 206 | a->type_data = clip_plane; |
||
| 207 | break; |
||
| 208 | case BR_ACTOR_MODEL: |
||
| 209 | // nothing to do |
||
| 210 | break; |
||
| 211 | default: |
||
| 212 | LOG_WARN("Warning: Unknown type %d for BrActorAllocate", type); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | return a; |
||
| 216 | } |
||
| 217 | |||
| 218 | // IDA: void __usercall InternalActorFree(br_actor *a@<EAX>) |
||
| 219 | void InternalActorFree(br_actor* a) { |
||
| 220 | |||
| 221 | while (a->children != NULL) { |
||
| 222 | InternalActorFree((br_actor*)BrSimpleRemove((br_simple_node*)a->children)); |
||
| 223 | } |
||
| 224 | BrActorEnableCheck(a); |
||
| 225 | BrResFree(a); |
||
| 226 | } |
||
| 227 | |||
| 228 | // IDA: void __cdecl BrActorFree(br_actor *a) |
||
| 229 | void BrActorFree(br_actor* a) { |
||
| 230 | |||
| 231 | while (a->children != NULL) { |
||
| 232 | InternalActorFree((br_actor*)BrSimpleRemove((br_simple_node*)a->children)); |
||
| 233 | } |
||
| 234 | BrActorEnableCheck(a); |
||
| 235 | BrResFree(a); |
||
| 236 | } |
||
| 237 | |||
| 238 | // IDA: br_boolean __usercall ActorToRoot@<EAX>(br_actor *a@<EAX>, br_actor *world@<EDX>, br_matrix34 *m@<EBX>) |
||
| 239 | br_boolean ActorToRoot(br_actor* a, br_actor* world, br_matrix34* m) { |
||
| 240 | LOG_TRACE("(%p, %p, %p)", a, world, m); |
||
| 241 | NOT_IMPLEMENTED(); |
||
| 242 | } |
||
| 243 | |||
| 244 | // IDA: br_boolean __usercall ActorToRootTyped@<EAX>(br_actor *a@<EAX>, br_actor *world@<EDX>, br_matrix34 *m@<EBX>, br_int_32 *type@<ECX>) |
||
| 245 | br_boolean ActorToRootTyped(br_actor* a, br_actor* world, br_matrix34* m, br_int_32* type) { |
||
| 246 | //br_int_32 t; // Pierre-Marie Baty -- unused variable |
||
| 247 | LOG_TRACE("(%p, %p, %p, %p)", a, world, m, type); |
||
| 248 | NOT_IMPLEMENTED(); |
||
| 249 | } |
||
| 250 | |||
| 251 | // IDA: void __usercall Matrix4PerspectiveNew(br_matrix4 *mat@<EAX>, br_angle field_of_view@<EDX>, br_scalar aspect, br_scalar hither, br_scalar yon, br_scalar origin_x, br_scalar origin_y) |
||
| 252 | void Matrix4PerspectiveNew(br_matrix4* mat, br_angle field_of_view, br_scalar aspect, br_scalar hither, br_scalar yon, br_scalar origin_x, br_scalar origin_y) { |
||
| 253 | //br_scalar scale; // Pierre-Marie Baty -- unused variable |
||
| 254 | LOG_TRACE("(%p, %d, %f, %f, %f, %f, %f)", mat, field_of_view, aspect, hither, yon, origin_x, origin_y); |
||
| 255 | NOT_IMPLEMENTED(); |
||
| 256 | } |
||
| 257 | |||
| 258 | // IDA: br_token __usercall CameraToScreenMatrix4@<EAX>(br_matrix4 *mat@<EAX>, br_actor *camera@<EDX>) |
||
| 259 | br_token CameraToScreenMatrix4(br_matrix4* mat, br_actor* camera) { |
||
| 260 | //br_camera* camera_type; // Pierre-Marie Baty -- unused variable |
||
| 261 | //br_matrix34 mat34; // Pierre-Marie Baty -- unused variable |
||
| 262 | LOG_TRACE("(%p, %p)", mat, camera); |
||
| 263 | NOT_IMPLEMENTED(); |
||
| 264 | } |
||
| 265 | |||
| 266 | // IDA: br_uint_16 __cdecl BrActorToActorMatrix34(br_matrix34 *m, br_actor *a, br_actor *b) |
||
| 267 | br_uint_16 BrActorToActorMatrix34(br_matrix34* m, br_actor* a, br_actor* b) { |
||
| 268 | br_matrix34 mata; |
||
| 269 | br_matrix34 matb; |
||
| 270 | br_matrix34 matc; |
||
| 271 | br_uint_8 at; |
||
| 272 | br_uint_8 bt; |
||
| 273 | LOG_TRACE("(%p, %p, %p)", m, a, b); |
||
| 274 | |||
| 275 | if (a == b) { |
||
| 276 | BrMatrix34Identity(m); |
||
| 277 | return BR_TRANSFORM_IDENTITY; |
||
| 278 | } |
||
| 279 | |||
| 280 | if (a->parent == b) { |
||
| 281 | BrTransformToMatrix34(m, &a->t); |
||
| 282 | return a->t.type; |
||
| 283 | } |
||
| 284 | |||
| 285 | if (b->parent == a) { |
||
| 286 | BrTransformToMatrix34(&matb, &b->t); |
||
| 287 | |||
| 288 | if (BrTransformTypeIsLP(b->t.type)) |
||
| 289 | BrMatrix34LPInverse(m, &matb); |
||
| 290 | else |
||
| 291 | BrMatrix34Inverse(m, &matb); |
||
| 292 | |||
| 293 | return b->t.type; |
||
| 294 | } |
||
| 295 | |||
| 296 | at = BR_TRANSFORM_IDENTITY; |
||
| 297 | BrMatrix34Identity(&mata); |
||
| 298 | |||
| 299 | bt = BR_TRANSFORM_IDENTITY; |
||
| 300 | BrMatrix34Identity(&matb); |
||
| 301 | |||
| 302 | while (a && b && a != b) { |
||
| 303 | |||
| 304 | if (a->depth > b->depth) { |
||
| 305 | |||
| 306 | if (a->t.type != BR_TRANSFORM_IDENTITY) { |
||
| 307 | BrMatrix34PostTransform(&mata, &a->t); |
||
| 308 | at = BrTransformCombineTypes(at, a->t.type); |
||
| 309 | } |
||
| 310 | a = a->parent; |
||
| 311 | |||
| 312 | } else if (b->depth > a->depth) { |
||
| 313 | |||
| 314 | if (b->t.type != BR_TRANSFORM_IDENTITY) { |
||
| 315 | BrMatrix34PostTransform(&matb, &b->t); |
||
| 316 | bt = BrTransformCombineTypes(bt, b->t.type); |
||
| 317 | } |
||
| 318 | b = b->parent; |
||
| 319 | |||
| 320 | } else { |
||
| 321 | |||
| 322 | if (a->t.type != BR_TRANSFORM_IDENTITY) { |
||
| 323 | BrMatrix34PostTransform(&mata, &a->t); |
||
| 324 | at = BrTransformCombineTypes(at, a->t.type); |
||
| 325 | } |
||
| 326 | if (b->t.type != BR_TRANSFORM_IDENTITY) { |
||
| 327 | BrMatrix34PostTransform(&matb, &b->t); |
||
| 328 | bt = BrTransformCombineTypes(bt, b->t.type); |
||
| 329 | } |
||
| 330 | b = b->parent; |
||
| 331 | a = a->parent; |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | if (bt == BR_TRANSFORM_IDENTITY) { |
||
| 336 | BrMatrix34Copy(m, &mata); |
||
| 337 | return at; |
||
| 338 | } |
||
| 339 | |||
| 340 | if (at == BR_TRANSFORM_IDENTITY) { |
||
| 341 | if (BrTransformTypeIsLP(bt)) { |
||
| 342 | BrMatrix34LPInverse(m, &matb); |
||
| 343 | } else |
||
| 344 | BrMatrix34Inverse(m, &matb); |
||
| 345 | |||
| 346 | return bt; |
||
| 347 | } |
||
| 348 | |||
| 349 | if (BrTransformTypeIsLP(bt)) { |
||
| 350 | BrMatrix34LPInverse(&matc, &matb); |
||
| 351 | } else |
||
| 352 | BrMatrix34Inverse(&matc, &matb); |
||
| 353 | |||
| 354 | BrMatrix34Mul(m, &mata, &matc); |
||
| 355 | |||
| 356 | return BrTransformCombineTypes(at, bt); |
||
| 357 | } |
||
| 358 | |||
| 359 | // IDA: void __cdecl BrActorToScreenMatrix4(br_matrix4 *m, br_actor *a, br_actor *camera) |
||
| 360 | void BrActorToScreenMatrix4(br_matrix4* m, br_actor* a, br_actor* camera) { |
||
| 361 | //br_matrix34 a2c; // Pierre-Marie Baty -- unused variable |
||
| 362 | LOG_TRACE("(%p, %p, %p)", m, a, camera); |
||
| 363 | NOT_IMPLEMENTED(); |
||
| 364 | } |
||
| 365 | |||
| 366 | // IDA: void __usercall BrMatrix34ApplyBounds(br_bounds *d@<EAX>, br_bounds *s@<EDX>, br_matrix34 *m@<EBX>) |
||
| 367 | void BrMatrix34ApplyBounds(br_bounds* A, br_bounds* B, br_matrix34* C) { |
||
| 368 | int i; |
||
| 369 | int j; |
||
| 370 | br_scalar a; |
||
| 371 | br_scalar b; |
||
| 372 | LOG_TRACE("(%p, %p, %p)", A, B, C); |
||
| 373 | |||
| 374 | A->min.v[0] = A->max.v[0] = C->m[3][0]; |
||
| 375 | A->min.v[1] = A->max.v[1] = C->m[3][1]; |
||
| 376 | A->min.v[2] = A->max.v[2] = C->m[3][2]; |
||
| 377 | |||
| 378 | for (i = 0; i < 3; i++) { |
||
| 379 | for (j = 0; j < 3; j++) { |
||
| 380 | a = C->m[j][i] * B->min.v[j]; |
||
| 381 | b = C->m[j][i] * B->max.v[j]; |
||
| 382 | if (a < b) { |
||
| 383 | A->min.v[i] += a; |
||
| 384 | A->max.v[i] += b; |
||
| 385 | } else { |
||
| 386 | A->min.v[i] += b; |
||
| 387 | A->max.v[i] += a; |
||
| 388 | } |
||
| 389 | } |
||
| 390 | } |
||
| 391 | } |
||
| 392 | |||
| 393 | // IDA: void __usercall ActorToBounds(br_bounds *dest@<EAX>, br_actor *ap@<EDX>, br_model *model@<EBX>) |
||
| 394 | void ActorToBounds(br_bounds* dest, br_actor* ap, br_model* model) { |
||
| 395 | br_actor* a; |
||
| 396 | br_bounds new; |
||
| 397 | br_matrix34 m2v; |
||
| 398 | int i; |
||
| 399 | LOG_TRACE("(%p, %p, %p)", dest, ap, model); |
||
| 400 | |||
| 401 | if (ap->model != NULL) |
||
| 402 | model = ap->model; |
||
| 403 | |||
| 404 | m2v = v1db.model_to_view; |
||
| 405 | BrMatrix34PreTransform(&v1db.model_to_view, &ap->t); |
||
| 406 | |||
| 407 | if (ap->type == BR_ACTOR_MODEL) { |
||
| 408 | BrMatrix34ApplyBounds(&new, &model->bounds, &v1db.model_to_view); |
||
| 409 | |||
| 410 | for (i = 0; i < 3; i++) { |
||
| 411 | if (new.min.v[i] < dest->min.v[i]) |
||
| 412 | dest->min.v[i] = new.min.v[i]; |
||
| 413 | |||
| 414 | if (new.max.v[i] > dest->max.v[i]) |
||
| 415 | dest->max.v[i] = new.max.v[i]; |
||
| 416 | } |
||
| 417 | } |
||
| 418 | |||
| 419 | BR_FOR_SIMPLELIST(&ap->children, a) |
||
| 420 | ActorToBounds(dest, a, model); |
||
| 421 | |||
| 422 | v1db.model_to_view = m2v; |
||
| 423 | } |
||
| 424 | |||
| 425 | // IDA: br_bounds* __cdecl BrActorToBounds(br_bounds *b, br_actor *ap) |
||
| 426 | br_bounds* BrActorToBounds(br_bounds* b, br_actor* ap) { |
||
| 427 | br_matrix34 m2v; |
||
| 428 | br_model* model; |
||
| 429 | br_actor* a; |
||
| 430 | LOG_TRACE("(%p, %p)", b, ap); |
||
| 431 | |||
| 432 | m2v = v1db.model_to_view; |
||
| 433 | |||
| 434 | if (ap->model == NULL) |
||
| 435 | model = v1db.default_model; |
||
| 436 | else |
||
| 437 | model = ap->model; |
||
| 438 | |||
| 439 | BrMatrix34Identity(&v1db.model_to_view); |
||
| 440 | |||
| 441 | if (ap->type == BR_ACTOR_MODEL) { |
||
| 442 | *b = model->bounds; |
||
| 443 | } else { |
||
| 444 | b->min.v[0] = b->min.v[1] = b->min.v[2] = BR_SCALAR_MAX; |
||
| 445 | b->max.v[0] = b->max.v[1] = b->max.v[2] = BR_SCALAR_MIN; |
||
| 446 | } |
||
| 447 | |||
| 448 | BR_FOR_SIMPLELIST(&ap->children, a) |
||
| 449 | ActorToBounds(b, a, model); |
||
| 450 | |||
| 451 | v1db.model_to_view = m2v; |
||
| 452 | return b; |
||
| 453 | } |