sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

graph_node_manager.c (2443B)


      1 #include <PR/ultratypes.h>
      2 
      3 #include "types.h"
      4 
      5 #include "graph_node.h"
      6 
      7 #if IS_64_BIT
      8 static s16 next_s16_in_geo_script(s16 **src) {
      9     s16 ret;
     10     if (((uintptr_t)(*src) & 7) == 4) {
     11          *src += 2; // skip 32 bits
     12     }
     13     ret = *(*src)++;
     14     if (((uintptr_t)(*src) & 7) == 4) {
     15          *src += 2; // skip 32 bits
     16     }
     17     return ret;
     18 }
     19 #else
     20 #define next_s16_in_geo_script(src) (*(*src)++)
     21 #endif
     22 
     23 /**
     24  * Takes a pointer to three shorts (supplied by a geo layout script) and
     25  * copies it to the destination float vector.
     26  */
     27 s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
     28     dst[0] = next_s16_in_geo_script(&src);
     29     dst[1] = next_s16_in_geo_script(&src);
     30     dst[2] = next_s16_in_geo_script(&src);
     31     return src;
     32 }
     33 
     34 /**
     35  * Takes a pointer to three shorts (supplied by a geo layout script) and
     36  * copies it to the destination vector. It's essentially a memcpy but consistent
     37  * with the other two 'geo-script vector to internal vector' functions.
     38  */
     39 s16 *read_vec3s(Vec3s dst, s16 *src) {
     40     dst[0] = next_s16_in_geo_script(&src);
     41     dst[1] = next_s16_in_geo_script(&src);
     42     dst[2] = next_s16_in_geo_script(&src);
     43     return src;
     44 }
     45 
     46 /**
     47  * Takes a pointer to three angles in degrees (supplied by a geo layout script)
     48  * and converts it to a vector of three in-game angle units in [-32768, 32767]
     49  * range.
     50  */
     51 s16 *read_vec3s_angle(Vec3s dst, s16 *src) {
     52     dst[0] = (next_s16_in_geo_script(&src) << 15) / 180;
     53     dst[1] = (next_s16_in_geo_script(&src) << 15) / 180;
     54     dst[2] = (next_s16_in_geo_script(&src) << 15) / 180;
     55     return src;
     56 }
     57 
     58 /**
     59  * Add the given graph node as a child to the current top of the gfx stack:
     60  * 'gCurGraphNodeList'. This is called from geo_layout commands to add nodes
     61  * to the scene graph.
     62  */
     63 void register_scene_graph_node(struct GraphNode *graphNode) {
     64     if (graphNode != NULL) {
     65         gCurGraphNodeList[gCurGraphNodeIndex] = graphNode;
     66 
     67         if (gCurGraphNodeIndex == 0) {
     68             if (gCurRootGraphNode == NULL) {
     69                 gCurRootGraphNode = graphNode;
     70             }
     71         } else {
     72             if (gCurGraphNodeList[gCurGraphNodeIndex - 1]->type == GRAPH_NODE_TYPE_OBJECT_PARENT) {
     73                 ((struct GraphNodeObjectParent *) gCurGraphNodeList[gCurGraphNodeIndex - 1])
     74                     ->sharedChild = graphNode;
     75             } else {
     76                 geo_add_child(gCurGraphNodeList[gCurGraphNodeIndex - 1], graphNode);
     77             }
     78         }
     79     }
     80 }