Subversion Repositories Games.Carmageddon

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "enables.h"
  2. #include "CORE/FW/diag.h"
  3. #include "CORE/FW/resource.h"
  4. #include "CORE/MATH/matrix34.h"
  5. #include "CORE/MATH/transfrm.h"
  6. #include "CORE/V1DB/actsupt.h"
  7. #include "dbsetup.h"
  8. #include "harness/trace.h"
  9. #include <stddef.h>
  10.  
  11. // IDA: void __usercall actorEnable(br_v1db_enable *e@<EAX>, br_actor *a@<EDX>)
  12. void actorEnable(br_v1db_enable* e, br_actor* a) {
  13.     int i;
  14.     LOG_TRACE("(%p, %p)", e, a);
  15.  
  16.     if (!e->enabled) {
  17.         e->enabled = BrResAllocate(v1db.res, e->max * sizeof(*e->enabled), BR_MEMORY_ENABLED_ACTORS);
  18.     }
  19.  
  20.     for (i = 0; i < e->max; i++) {
  21.         if (e->enabled[i] == a) {
  22.             return;
  23.         }
  24.     }
  25.  
  26.     for (i = 0; i < e->max; i++) {
  27.         if (!e->enabled[i]) {
  28.             e->enabled[i] = a;
  29.             e->count++;
  30.             return;
  31.         }
  32.     }
  33.  
  34.     BrFailure("too many enabled %ss", e->name);
  35. }
  36.  
  37. // IDA: void __usercall actorDisable(br_v1db_enable *e@<EAX>, br_actor *a@<EDX>)
  38. void actorDisable(br_v1db_enable* e, br_actor* a) {
  39.     int i;
  40.  
  41.     if (!e->enabled) {
  42.         return;
  43.     }
  44.  
  45.     for (i = 0; i < e->max; i++) {
  46.         if (e->enabled[i] == a) {
  47.             e->enabled[i] = NULL;
  48.             e->count--;
  49.             return;
  50.         }
  51.     }
  52. }
  53.  
  54. // IDA: void __cdecl BrLightEnable(br_actor *l)
  55. void BrLightEnable(br_actor* l) {
  56.     LOG_TRACE("(%p)", l);
  57.  
  58.     actorEnable(&v1db.enabled_lights, l);
  59. }
  60.  
  61. // IDA: void __cdecl BrLightDisable(br_actor *l)
  62. void BrLightDisable(br_actor* l) {
  63.     LOG_TRACE("(%p)", l);
  64.  
  65.     actorDisable(&v1db.enabled_lights, l);
  66. }
  67.  
  68. // IDA: void __cdecl BrClipPlaneEnable(br_actor *c)
  69. void BrClipPlaneEnable(br_actor* c) {
  70.     LOG_TRACE("(%p)", c);
  71.  
  72.     actorEnable(&v1db.enabled_clip_planes, c);
  73. }
  74.  
  75. // IDA: void __cdecl BrClipPlaneDisable(br_actor *c)
  76. void BrClipPlaneDisable(br_actor* c) {
  77.  
  78.     actorDisable(&v1db.enabled_clip_planes, c);
  79. }
  80.  
  81. // IDA: void __cdecl BrHorizonPlaneEnable(br_actor *h)
  82. void BrHorizonPlaneEnable(br_actor* h) {
  83.     LOG_TRACE("(%p)", h);
  84.  
  85.     actorEnable(&v1db.enabled_horizon_planes, h);
  86. }
  87.  
  88. // IDA: void __cdecl BrHorizonPlaneDisable(br_actor *h)
  89. void BrHorizonPlaneDisable(br_actor* h) {
  90.     LOG_TRACE("(%p)", h);
  91.  
  92.     actorDisable(&v1db.enabled_horizon_planes, h);
  93. }
  94.  
  95. // IDA: br_actor* __cdecl BrEnvironmentSet(br_actor *a)
  96. br_actor* BrEnvironmentSet(br_actor* a) {
  97.     br_actor* old_a;
  98.     LOG_TRACE("(%p)", a);
  99.  
  100.     old_a = v1db.enabled_environment;
  101.     v1db.enabled_environment = a;
  102.     return old_a;
  103. }
  104.  
  105. // IDA: br_boolean __usercall setupView@<EAX>(br_matrix34 *view_to_this@<EAX>, br_matrix34 *this_to_view@<EDX>, br_matrix34 *world_to_view@<EBX>, br_int_32 w2vt@<ECX>, br_actor *world, br_actor *a)
  106. br_boolean setupView(br_matrix34* view_to_this, br_matrix34* this_to_view, br_matrix34* world_to_view, br_int_32 w2vt, br_actor* world, br_actor* a) {
  107.     br_matrix34 this_to_world;
  108.     br_int_32 root_t;
  109.     br_int_32 t;
  110.     LOG_TRACE("(%p, %p, %p, %d, %p, %p)", view_to_this, this_to_view, world_to_view, w2vt, world, a);
  111.     if (ActorToRootTyped(a, world, &this_to_world, &root_t) == 0) {
  112.         return 0;
  113.     }
  114.     BrMatrix34Mul(this_to_view, &this_to_world, world_to_view);
  115.     t = BrTransformCombineTypes(root_t, w2vt);
  116.     if (BrTransformTypeIsLP(t) != 0) {
  117.         BrMatrix34LPInverse(view_to_this, this_to_view);
  118.     } else {
  119.         BrMatrix34Inverse(view_to_this, this_to_view);
  120.     }
  121.     return 1;
  122. }
  123.  
  124. // IDA: void __usercall BrSetupLights(br_actor *world@<EAX>, br_matrix34 *world_to_view@<EDX>, br_int_32 w2vt@<EBX>)
  125. void BrSetupLights(br_actor* world, br_matrix34* world_to_view, br_int_32 w2vt) {
  126.     //br_matrix34 this_to_view; // Pierre-Marie Baty -- unused variable
  127.     //br_matrix34 view_to_this; // Pierre-Marie Baty -- unused variable
  128.     //int light_part; // Pierre-Marie Baty -- unused variable
  129.     //int i; // Pierre-Marie Baty -- unused variable
  130.     //br_token_value tv[16]; // Pierre-Marie Baty -- unused variable
  131.     //br_token_value* tvp; // Pierre-Marie Baty -- unused variable
  132.     //br_vector3 view_position; // Pierre-Marie Baty -- unused variable
  133.     //br_vector3 view_direction; // Pierre-Marie Baty -- unused variable
  134.     //br_light* light; // Pierre-Marie Baty -- unused variable
  135.     LOG_TRACE("(%p, %p, %d)", world, world_to_view, w2vt);
  136.     NOT_IMPLEMENTED();
  137. }
  138.  
  139. // IDA: void __usercall BrSetupClipPlanes(br_actor *world@<EAX>, br_matrix34 *world_to_view@<EDX>, br_int_32 w2vt@<EBX>, br_matrix4 *view_to_screen@<ECX>)
  140. void BrSetupClipPlanes(br_actor* world, br_matrix34* world_to_view, br_int_32 w2vt, br_matrix4* view_to_screen) {
  141.     //br_matrix34 this_to_view; // Pierre-Marie Baty -- unused variable
  142.     //br_matrix34 view_to_this; // Pierre-Marie Baty -- unused variable
  143.     //br_matrix4 screen_to_view; // Pierre-Marie Baty -- unused variable
  144.     //br_matrix4 tmp4; // Pierre-Marie Baty -- unused variable
  145.     //br_matrix4 screen_to_this; // Pierre-Marie Baty -- unused variable
  146.     //int light_part; // Pierre-Marie Baty -- unused variable
  147.     //int i; // Pierre-Marie Baty -- unused variable
  148.     //br_int_32 clip_part; // Pierre-Marie Baty -- unused variable
  149.     //br_token_value tv[3]; // Pierre-Marie Baty -- unused variable
  150.     //br_vector4 sp; // Pierre-Marie Baty -- unused variable
  151.     LOG_TRACE("(%p, %p, %d, %p)", world, world_to_view, w2vt, view_to_screen);
  152.     NOT_IMPLEMENTED();
  153. }
  154.  
  155. // IDA: void __usercall BrSetupEnvironment(br_actor *world@<EAX>, br_matrix34 *world_to_view@<EDX>, br_int_32 w2vt@<EBX>)
  156. void BrSetupEnvironment(br_actor* world, br_matrix34* world_to_view, br_int_32 w2vt) {
  157.     br_matrix34 view_to_this;
  158.     br_matrix34 this_to_view;
  159.     br_token h;
  160.     LOG_TRACE("(%p, %p, %d)", world, world_to_view, w2vt);
  161.  
  162.     h = BRT_DONT_CARE;
  163.     if (v1db.enabled_environment != NULL) {
  164.         if (v1db.enabled_environment == world) {
  165.             if (BrTransformTypeIsLP(w2vt) != 0) {
  166.                 BrMatrix34LPInverse(&view_to_this, world_to_view);
  167.             } else {
  168.                 BrMatrix34Inverse(&view_to_this, world_to_view);
  169.             }
  170.             h = BRT_NONE;
  171.         } else {
  172.             if (setupView(&view_to_this, &this_to_view, world_to_view, w2vt, world, v1db.enabled_environment) != 0) {
  173.                 h = BRT_NONE;
  174.             }
  175.         }
  176.     }
  177.     if (h != BRT_DONT_CARE) {
  178.         v1db.renderer->dispatch->_partSet(v1db.renderer, BRT_MATRIX, 0, BRT_VIEW_TO_ENVIRONMENT_M34_F, (uintptr_t) &view_to_this); // Pierre-Marie Baty -- added type cast
  179.     }
  180.     v1db.renderer->dispatch->_partSet(v1db.renderer, BRT_MATRIX, 0, BRT_VIEW_TO_ENVIRONMENT_HINT_T, h);
  181. }
  182.  
  183. // IDA: void __usercall BrSetupHorizons(br_actor *world@<EAX>, br_matrix34 *world_to_view@<EDX>, br_int_32 w2vt@<EBX>)
  184. void BrSetupHorizons(br_actor* world, br_matrix34* world_to_view, br_int_32 w2vt) {
  185.     LOG_TRACE("(%p, %p, %d)", world, world_to_view, w2vt);
  186.     NOT_IMPLEMENTED();
  187. }
  188.  
  189. // IDA: void __usercall BrActorEnableCheck(br_actor *a@<EAX>)
  190. void BrActorEnableCheck(br_actor* a) {
  191.     if (v1db.enabled_environment == a) {
  192.         v1db.enabled_environment = NULL;
  193.     }
  194.     if (a->type == BR_ACTOR_LIGHT) {
  195.         actorDisable(&v1db.enabled_lights, a);
  196.     } else if (a->type == BR_ACTOR_HORIZONTAL_PLANE) {
  197.         actorDisable(&v1db.enabled_horizon_planes, a);
  198.     } else if (a->type <= BR_ACTOR_CLIP_PLANE) {
  199.         actorDisable(&v1db.enabled_clip_planes, a);
  200.     }
  201. }
  202.