Subversion Repositories Games.Carmageddon

Rev

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

  1. #include "render.h"
  2. #include "CORE/MATH/matrix34.h"
  3. #include "CORE/MATH/transfrm.h"
  4. #include "CORE/V1DB/dbsetup.h"
  5. #include "CORE/V1DB/modrend.h"
  6. #include "harness/hooks.h"
  7. #include "harness/trace.h"
  8. #include <string.h>
  9.  
  10. #define RendererModelMul(self, a1) self->dispatch->_modelMulF(self, a1);
  11. #define RendererStatePush(self, a1) self->dispatch->_statePush(self, a1);
  12. #define RendererStatePop(self, a1) self->dispatch->_statePop(self, a1);
  13.  
  14. // IDA: void __cdecl BrDbModelRender(br_actor *actor, br_model *model, br_material *material, void *render_data, br_uint_8 style, int on_screen, int use_custom)
  15. void BrDbModelRender(br_actor* actor, br_model* model, br_material* material, void* render_data, br_uint_8 style, int on_screen, int use_custom) {
  16.     //br_int_32 count; // Pierre-Marie Baty -- unused variable
  17.     //br_token_value tv[5]; // Pierre-Marie Baty -- unused variable
  18.     LOG_TRACE("(%p, %p, %p, %p, %d, %d, %d)", actor, model, material, render_data, style, on_screen, use_custom);
  19.  
  20.     v1db.model_to_screen_valid = 0;
  21.     if (use_custom && (model->flags & BR_MODF_CUSTOM)) {
  22.         model->custom(actor, model, material, render_data, style, on_screen);
  23.         return;
  24.     }
  25.  
  26.     if (model->prepared == NULL && model->stored == NULL) {
  27.         // TELL_ME_IF_WE_PASS_THIS_WAY();
  28.         // TODO: gShadow_model is not created yet. Will trip into this
  29.         // LOG_WARN("Tried to render un-prepared model %s", model->identifier ? model->identifier : "<NULL>");
  30.     }
  31.  
  32.     RenderStyleCalls[style](actor, model, material, render_data, style, on_screen);
  33. }
  34.  
  35. // IDA: br_uint_32 __cdecl BrOnScreenCheck(br_bounds3 *bounds)
  36. br_uint_32 BrOnScreenCheck(br_bounds3* bounds) {
  37.     br_token r;
  38.     LOG_TRACE("(%p)", bounds);
  39.  
  40.     STUB_ONCE(); // Add call to STUB_ONCE to mark this function as not implemented.
  41.     return 1;
  42.  
  43.     // FIXME: use this once the clouse clear up.
  44.     v1db.renderer->dispatch->_boundsTestF(v1db.renderer, &r, (br_bounds3_f*)bounds);
  45.     return r;
  46. }
  47.  
  48. // IDA: br_uint_16 __usercall prependActorTransform@<AX>(br_actor *ap@<EAX>, br_uint_16 t@<EDX>)
  49. br_uint_16 prependActorTransform(br_actor* ap, br_uint_16 t) {
  50.     br_matrix34 mt;
  51.     LOG_TRACE("(%p, %d)", ap, t);
  52.  
  53.     if (BrTransformTypeIsMatrix34(ap->t.type)) {
  54.         RendererModelMul(v1db.renderer, (void*)&ap->t.t.mat);
  55.     } else {
  56.         BrTransformToMatrix34(&mt, &ap->t);
  57.         RendererModelMul(v1db.renderer, (void*)&mt);
  58.     }
  59.     t = BrTransformCombineTypes(t, ap->t.type);
  60.  
  61.     // RendererPartSet(v1db.renderer, BRT_MATRIX, 0,
  62.     //     BRT_MODEL_TO_VIEW_HINT_T, BrTransformTypeIsLP(t) ? BRT_LENGTH_PRESERVING : BRT_NONE);
  63.  
  64.     return t;
  65. }
  66.  
  67. // IDA: br_uint_16 __usercall prependMatrix@<AX>(br_matrix34 *mat@<EAX>, br_uint_16 mat_t@<EDX>, br_uint_16 t@<EBX>)
  68. br_uint_16 prependMatrix(br_matrix34* mat, br_uint_16 mat_t, br_uint_16 t) {
  69.     //br_matrix34 mt; // Pierre-Marie Baty -- unused variable
  70.     LOG_TRACE("(%p, %d, %d)", mat, mat_t, t);
  71.  
  72.     RendererModelMul(v1db.renderer, (void*)mat);
  73.  
  74.     t = BrTransformCombineTypes(t, mat_t);
  75.  
  76.     return t;
  77. }
  78.  
  79. // IDA: void __usercall actorRender(br_actor *ap@<EAX>, br_model *model@<EDX>, br_material *material@<EBX>, void *render_data@<ECX>, br_uint_8 style, br_uint_16 t)
  80. void actorRender(br_actor* ap, br_model* model, br_material* material, void* render_data, br_uint_8 style, br_uint_16 t) {
  81.     br_material* this_material;
  82.     br_model* this_model;
  83.     void* this_render_data;
  84.     br_actor* a;
  85.     br_token s;
  86.     LOG_TRACE("(%p, %p, %p, %p, %d, %d)", ap, model, material, render_data, style, t);
  87.  
  88.     if (ap->children == NULL && ap->type != BR_ACTOR_MODEL)
  89.         return;
  90.  
  91.     if (ap->render_style != BR_RSTYLE_DEFAULT)
  92.         style = ap->render_style;
  93.  
  94.     if (style == BR_RSTYLE_NONE)
  95.         return;
  96.  
  97.     this_material = ap->material ? ap->material : material;
  98.     this_model = ap->model ? ap->model : model;
  99.     this_render_data = ap->render_data ? ap->render_data : render_data;
  100.  
  101.     if (ap->t.type == BR_TRANSFORM_IDENTITY) {
  102.  
  103.         switch (ap->type) {
  104.  
  105.         case BR_ACTOR_MODEL:
  106.  
  107.             if ((s = BrOnScreenCheck(&this_model->bounds)) != BRT_REJECT) {
  108.                 BrDbModelRender(ap, this_model, this_material, this_render_data, style, s, 1);
  109.             }
  110.             break;
  111.  
  112.         case BR_ACTOR_BOUNDS:
  113.  
  114.             if (BrOnScreenCheck(ap->type_data) == BRT_REJECT)
  115.                 return;
  116.             break;
  117.  
  118.         case BR_ACTOR_BOUNDS_CORRECT:
  119.             switch (BrOnScreenCheck(ap->type_data)) {
  120.             case BRT_ACCEPT:
  121.                 BR_FOR_SIMPLELIST(&ap->children, a)
  122.                 actorRenderOnScreen(a, this_model, this_material, this_render_data, style, t);
  123.                 return;
  124.             case BRT_REJECT:
  125.                 return;
  126.             }
  127.         }
  128.  
  129.         BR_FOR_SIMPLELIST(&ap->children, a)
  130.         actorRender(a, this_model, this_material, this_render_data, style, t);
  131.         return;
  132.     }
  133.  
  134.     RendererStatePush(v1db.renderer, BR_STATE_MATRIX);
  135.  
  136.     t = prependActorTransform(ap, t);
  137.  
  138.     switch (ap->type) {
  139.  
  140.     case BR_ACTOR_MODEL:
  141.         if ((s = BrOnScreenCheck(&this_model->bounds)) != BRT_REJECT) {
  142.             BrDbModelRender(ap, this_model, this_material, this_render_data, style, s, 1);
  143.         }
  144.         break;
  145.  
  146.     case BR_ACTOR_BOUNDS:
  147.         if (BrOnScreenCheck(ap->type_data) == BRT_REJECT) {
  148.             RendererStatePop(v1db.renderer, BR_STATE_MATRIX);
  149.             return;
  150.         }
  151.         break;
  152.  
  153.     case BR_ACTOR_BOUNDS_CORRECT:
  154.         switch (BrOnScreenCheck(ap->type_data)) {
  155.         case BRT_ACCEPT:
  156.             BR_FOR_SIMPLELIST(&ap->children, a)
  157.             actorRenderOnScreen(a, this_model, this_material, this_render_data, style, t);
  158.             return;
  159.         case BRT_REJECT:
  160.             RendererStatePop(v1db.renderer, BR_STATE_MATRIX);
  161.             return;
  162.         }
  163.     }
  164.  
  165.     BR_FOR_SIMPLELIST(&ap->children, a)
  166.     actorRender(a, this_model, this_material, this_render_data, style, t);
  167.     RendererStatePop(v1db.renderer, BR_STATE_MATRIX);
  168. }
  169.  
  170. // IDA: void __usercall actorRenderOnScreen(br_actor *ap@<EAX>, br_model *model@<EDX>, br_material *material@<EBX>, void *render_data@<ECX>, br_uint_8 style, br_uint_16 t)
  171. void actorRenderOnScreen(br_actor* ap, br_model* model, br_material* material, void* render_data, br_uint_8 style, br_uint_16 t) {
  172.     //br_material* this_material; // Pierre-Marie Baty -- unused variable
  173.     //br_model* this_model; // Pierre-Marie Baty -- unused variable
  174.     //void* this_render_data; // Pierre-Marie Baty -- unused variable
  175.     //br_actor* a; // Pierre-Marie Baty -- unused variable
  176.     LOG_TRACE("(%p, %p, %p, %p, %d, %d)", ap, model, material, render_data, style, t);
  177.     NOT_IMPLEMENTED();
  178. }
  179.  
  180. // IDA: void __usercall sceneRenderWorld(br_actor *world@<EAX>)
  181. void sceneRenderWorld(br_actor* world) {
  182.     //br_model* model; // Pierre-Marie Baty -- unused variable
  183.     //br_material* material; // Pierre-Marie Baty -- unused variable
  184.     //void* render_data; // Pierre-Marie Baty -- unused variable
  185.     //br_uint_8 style; // Pierre-Marie Baty -- unused variable
  186.     //br_actor* a; // Pierre-Marie Baty -- unused variable
  187.     LOG_TRACE("(%p)", world);
  188.     NOT_IMPLEMENTED();
  189. }
  190.  
  191. // IDA: void __usercall sceneRenderAdd(br_actor *tree@<EAX>)
  192. void sceneRenderAdd(br_actor* tree) {
  193.     br_material* material;
  194.     br_model* model;
  195.     void* render_data;
  196.     br_uint_8 style;
  197.     br_actor* a;
  198.     br_int_32 t;
  199.     br_matrix34 m;
  200.     LOG_TRACE("(%p)", tree);
  201.  
  202.     material = NULL;
  203.     model = NULL;
  204.     render_data = NULL;
  205.     style = BR_RSTYLE_DEFAULT;
  206.  
  207.     if (tree->parent == NULL) {
  208.         actorRender(tree,
  209.             v1db.default_model,
  210.             v1db.default_material,
  211.             v1db.default_render_data, BR_RSTYLE_DEFAULT,
  212.             (br_uint_16)v1db.ttype);
  213.         return;
  214.     }
  215.  
  216.     t = BR_TRANSFORM_IDENTITY;
  217.     BrMatrix34Identity(&m);
  218.  
  219.     for (a = tree->parent; a; a = a->parent) {
  220.         if (material == NULL && a->material)
  221.             material = a->material;
  222.  
  223.         if (model == NULL && a->model)
  224.             model = a->model;
  225.  
  226.         if (render_data == NULL && a->render_data)
  227.             render_data = a->render_data;
  228.         if (a->render_style != BR_RSTYLE_DEFAULT)
  229.             style = a->render_style;
  230.  
  231.         if (a == v1db.render_root)
  232.             break;
  233.  
  234.         if (a->t.type != BR_TRANSFORM_IDENTITY) {
  235.             BrMatrix34PostTransform(&m, &a->t);
  236.             t = BrTransformCombineTypes(t, a->t.type);
  237.         }
  238.     }
  239.  
  240.     if (material == NULL)
  241.         material = v1db.default_material;
  242.  
  243.     if (model == NULL)
  244.         model = v1db.default_model;
  245.  
  246.     if (render_data == NULL)
  247.         render_data = v1db.default_render_data;
  248.  
  249.     if (t == BR_TRANSFORM_IDENTITY) {
  250.         actorRender(tree, model, material, render_data, style, (br_uint_16)v1db.ttype);
  251.     } else {
  252.         RendererStatePush(v1db.renderer, BR_STATE_MATRIX);
  253.         t = prependMatrix(&m, (unsigned short)t, (unsigned short)v1db.ttype);
  254.         actorRender(tree, model, material, render_data, style, (br_uint_16)t);
  255.         RendererStatePop(v1db.renderer, BR_STATE_MATRIX);
  256.     }
  257. }
  258.  
  259. // IDA: void __cdecl BrDbSceneRenderBegin(br_actor *world, br_actor *camera)
  260. void BrDbSceneRenderBegin(br_actor* world, br_actor* camera) {
  261.     br_matrix34 tfm;
  262.     //br_matrix4 vtos; // Pierre-Marie Baty -- unused variable
  263.     br_actor* a;
  264.     int i;
  265.     //br_token vtos_type; // Pierre-Marie Baty -- unused variable
  266.     //br_uint_32 dummy; // Pierre-Marie Baty -- unused variable
  267.     LOG_TRACE("(%p, %p)", world, camera);
  268.  
  269.     // this is not complete
  270.     STUB_ONCE();
  271.  
  272.     /*
  273.      * Collect transforms from camera to root
  274.      *
  275.      * Make a stack of cumulative transforms for each level between
  276.      * the camera and the root - this is so that model->view
  277.      * transforms can use the shortest route, rather than via the root
  278.      */
  279.     for (i = 0; i < BR_ASIZE(v1db.camera_path); i++) {
  280.         v1db.camera_path[i].a = NULL;
  281.     }
  282.  
  283.     i = camera->depth;
  284.     a = camera;
  285.     BrMatrix34Identity(&v1db.camera_path[i].m);
  286.     v1db.camera_path[i].transform_type = BR_TRANSFORM_IDENTITY;
  287.  
  288.     for (; (i > 0) && (a != world); a = a->parent, i--) {
  289.         BrTransformToMatrix34(&tfm, &a->t);
  290.         BrMatrix34Mul(&v1db.camera_path[i - 1].m, &v1db.camera_path[i].m, &tfm);
  291.  
  292.         v1db.camera_path[i - 1].transform_type = BrTransformCombineTypes(v1db.camera_path[i].transform_type, a->t.type);
  293.  
  294.         v1db.camera_path[i].a = a;
  295.     }
  296.  
  297.     if (world != a) {
  298.         // BrFailure("camera is not in world hierachy");
  299.     }
  300. }
  301.  
  302. // IDA: br_renderbounds_cbfn* __cdecl BrDbSetRenderBoundsCallback(br_renderbounds_cbfn *new_cbfn)
  303. br_renderbounds_cbfn* BrDbSetRenderBoundsCallback(br_renderbounds_cbfn* new_cbfn) {
  304.     //br_renderbounds_cbfn* old_cbfn; // Pierre-Marie Baty -- unused variable
  305.     LOG_TRACE("(%p)", new_cbfn);
  306.     NOT_IMPLEMENTED();
  307. }
  308.  
  309. // IDA: void __usercall SetOrigin(br_pixelmap *buffer@<EAX>)
  310. void SetOrigin(br_pixelmap* buffer) {
  311.     LOG_TRACE("(%p)", buffer);
  312.     NOT_IMPLEMENTED();
  313. }
  314.  
  315. // IDA: void __usercall SetViewport(br_pixelmap *buffer@<EAX>)
  316. void SetViewport(br_pixelmap* buffer) {
  317.     LOG_TRACE("(%p)", buffer);
  318.     NOT_IMPLEMENTED();
  319. }
  320.  
  321. // IDA: void __cdecl BrZbSceneRenderBegin(br_actor *world, br_actor *camera, br_pixelmap *colour_buffer, br_pixelmap *depth_buffer)
  322. void BrZbSceneRenderBegin(br_actor* world, br_actor* camera, br_pixelmap* colour_buffer, br_pixelmap* depth_buffer) {
  323.     // LOG_TRACE("(%p, %p, %p, %p)", world, camera, colour_buffer, depth_buffer);
  324.  
  325.     BrDbSceneRenderBegin(world, camera);
  326.     gHarness_platform.Renderer_BeginScene(camera, colour_buffer, depth_buffer);
  327. }
  328.  
  329. // IDA: void __cdecl BrZbSceneRenderAdd(br_actor *tree)
  330. void BrZbSceneRenderAdd(br_actor* tree) {
  331.     // LOG_TRACE("(%p)", tree);
  332.     sceneRenderAdd(tree);
  333. }
  334.  
  335. // IDA: void __cdecl BrZbSceneRenderEnd()
  336. void BrZbSceneRenderEnd(void) {
  337.     // LOG_TRACE("()");
  338.  
  339.     gHarness_platform.Renderer_FlushBuffers();
  340.     gHarness_platform.Renderer_EndScene();
  341. }
  342.  
  343. // IDA: void __cdecl BrZbSceneRender(br_actor *world, br_actor *camera, br_pixelmap *colour_buffer, br_pixelmap *depth_buffer)
  344. void BrZbSceneRender(br_actor* world, br_actor* camera, br_pixelmap* colour_buffer, br_pixelmap* depth_buffer) {
  345.     //br_actor* a; // Pierre-Marie Baty -- unused variable
  346.     LOG_TRACE("(%p, %p, %p, %p)", world, camera, colour_buffer, depth_buffer);
  347.     NOT_IMPLEMENTED();
  348. }
  349.  
  350. // IDA: void __cdecl BrZsSceneRenderBegin(br_actor *world, br_actor *camera, br_pixelmap *colour_buffer)
  351. void BrZsSceneRenderBegin(br_actor* world, br_actor* camera, br_pixelmap* colour_buffer) {
  352.     //br_camera* camera_data; // Pierre-Marie Baty -- unused variable
  353.     LOG_TRACE("(%p, %p, %p)", world, camera, colour_buffer);
  354.     NOT_IMPLEMENTED();
  355. }
  356.  
  357. // IDA: void __cdecl BrZsSceneRenderAdd(br_actor *tree)
  358. void BrZsSceneRenderAdd(br_actor* tree) {
  359.     LOG_TRACE("(%p)", tree);
  360.     NOT_IMPLEMENTED();
  361. }
  362.  
  363. // IDA: void __cdecl BrZsSceneRenderEnd()
  364. void BrZsSceneRenderEnd(void) {
  365.     LOG_TRACE("()");
  366.     NOT_IMPLEMENTED();
  367. }
  368.  
  369. // IDA: void __cdecl BrZsSceneRender(br_actor *world, br_actor *camera, br_pixelmap *colour_buffer)
  370. void BrZsSceneRender(br_actor* world, br_actor* camera, br_pixelmap* colour_buffer) {
  371.     //br_actor* a; // Pierre-Marie Baty -- unused variable
  372.     LOG_TRACE("(%p, %p, %p)", world, camera, colour_buffer);
  373.     NOT_IMPLEMENTED();
  374. }
  375.  
  376. // IDA: br_primitive_cbfn* __cdecl BrZsPrimitiveCallbackSet(br_primitive_cbfn *new_cbfn)
  377. br_primitive_cbfn* BrZsPrimitiveCallbackSet(br_primitive_cbfn* new_cbfn) {
  378.     //br_primitive_cbfn* old_cbfn; // Pierre-Marie Baty -- unused variable
  379.     LOG_TRACE("(%p)", new_cbfn);
  380.     NOT_IMPLEMENTED();
  381. }
  382.  
  383. // IDA: void __cdecl BrZbModelRender(br_actor *actor, br_model *model, br_material *material, br_uint_8 style, int on_screen, int use_custom)
  384. void BrZbModelRender(br_actor* actor, br_model* model, br_material* material, br_uint_8 style, int on_screen, int use_custom) {
  385.     LOG_TRACE("(%p, %p, %p, %d, %d, %d)", actor, model, material, style, on_screen, use_custom);
  386.  
  387.     BrDbModelRender(actor, model, material, 0, style, on_screen, use_custom);
  388. }
  389.  
  390. // IDA: void __cdecl BrZsModelRender(br_actor *actor, br_model *model, br_material *material, br_order_table *order_table, br_uint_8 style, int on_screen, int use_custom)
  391. void BrZsModelRender(br_actor* actor, br_model* model, br_material* material, br_order_table* order_table, br_uint_8 style, int on_screen, int use_custom) {
  392.     LOG_TRACE("(%p, %p, %p, %p, %d, %d, %d)", actor, model, material, order_table, style, on_screen, use_custom);
  393.     NOT_IMPLEMENTED();
  394. }
  395.  
  396. // IDA: br_renderbounds_cbfn* __cdecl BrZbRenderBoundsCallbackSet(br_renderbounds_cbfn *new_cbfn)
  397. br_renderbounds_cbfn* BrZbRenderBoundsCallbackSet(br_renderbounds_cbfn* new_cbfn) {
  398.     LOG_TRACE("(%p)", new_cbfn);
  399.     NOT_IMPLEMENTED();
  400. }
  401.  
  402. // IDA: br_renderbounds_cbfn* __cdecl BrZsRenderBoundsCallbackSet(br_renderbounds_cbfn *new_cbfn)
  403. br_renderbounds_cbfn* BrZsRenderBoundsCallbackSet(br_renderbounds_cbfn* new_cbfn) {
  404.     LOG_TRACE("(%p)", new_cbfn);
  405.     NOT_IMPLEMENTED();
  406. }
  407.