Refresh 3

This commit is contained in:
n64 committed 2019-11-03 14:36:27 -05:00
1 parent 6b8bc9b9ec
commit a7c423cb43
4603 files changed
+475500 -437701

No files matched your search

+16 -16
View File
@@ -118,9 +118,9 @@ static s32 beh_cmd_graph_node(void) {
static s32 beh_cmd_obj_load_chill(void) {
u32 model = (u32) gBehCommand[1];
void *arg1 = (void *) gBehCommand[2];
const BehaviorScript *behavior = (const BehaviorScript *) gBehCommand[2];
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, arg1);
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, behavior);
copy_object_pos_and_angle(object, gCurrentObject);
@@ -130,9 +130,9 @@ static s32 beh_cmd_obj_load_chill(void) {
static s32 beh_cmd_obj_spawn(void) {
u32 model = (u32) gBehCommand[1];
void *arg1 = (void *) gBehCommand[2];
const BehaviorScript *behavior = (const BehaviorScript *) gBehCommand[2];
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, arg1);
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, behavior);
copy_object_pos_and_angle(object, gCurrentObject);
@@ -145,9 +145,9 @@ static s32 beh_cmd_obj_spawn(void) {
static s32 beh_cmd_obj_load_chill_param(void) {
u32 behParam = (s16)(gBehCommand[0] & 0xFFFF);
u32 model = (u32) gBehCommand[1];
void *arg2 = (void *) gBehCommand[2];
const BehaviorScript *behavior = (const BehaviorScript *) gBehCommand[2];
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, arg2);
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, behavior);
copy_object_pos_and_angle(object, gCurrentObject);
@@ -172,18 +172,18 @@ static s32 beh_cmd_break2(void) {
}
static s32 beh_cmd_call(void) {
uintptr_t *jumpAddress;
const BehaviorScript *jumpAddress;
gBehCommand++;
cur_object_stack_push((uintptr_t)(gBehCommand + 1));
jumpAddress = segmented_to_virtual((void *) gBehCommand[0]);
jumpAddress = segmented_to_virtual((const BehaviorScript *) gBehCommand[0]);
gBehCommand = jumpAddress;
return BEH_CONTINUE;
}
static s32 beh_cmd_return(void) {
gBehCommand = (uintptr_t *) cur_object_stack_pop();
gBehCommand = (const BehaviorScript *) cur_object_stack_pop();
return BEH_CONTINUE;
}
@@ -216,7 +216,7 @@ static s32 beh_cmd_delay_var(void) {
static s32 beh_cmd_goto(void) {
gBehCommand++;
gBehCommand = segmented_to_virtual((void *) gBehCommand[0]);
gBehCommand = segmented_to_virtual((const BehaviorScript *) gBehCommand[0]);
return BEH_CONTINUE;
}
@@ -248,7 +248,7 @@ static s32 beh_cmd_end_repeat(void) {
count--;
if (count != 0) {
gBehCommand = (uintptr_t *) cur_object_stack_pop();
gBehCommand = (const BehaviorScript *) cur_object_stack_pop();
cur_object_stack_push((uintptr_t) gBehCommand);
cur_object_stack_push(count);
} else {
@@ -264,7 +264,7 @@ static s32 beh_cmd_end_repeat_nobreak(void) {
count--;
if (count != 0) {
gBehCommand = (uintptr_t *) cur_object_stack_pop();
gBehCommand = (const BehaviorScript *) cur_object_stack_pop();
cur_object_stack_push((uintptr_t) gBehCommand);
cur_object_stack_push(count);
} else {
@@ -283,7 +283,7 @@ static s32 beh_cmd_begin_loop(void) {
}
static s32 beh_cmd_end_loop(void) {
gBehCommand = (uintptr_t *) cur_object_stack_pop();
gBehCommand = (const BehaviorScript *) cur_object_stack_pop();
cur_object_stack_push((uintptr_t) gBehCommand);
return BEH_BREAK;
@@ -432,10 +432,10 @@ static s32 beh_cmd_obj_bit_clear_int(void) {
return BEH_CONTINUE;
}
static s32 beh_cmd_obj_set_int32(void) {
static s32 beh_cmd_obj_set_anims(void) {
u8 objectOffset = (u8)((gBehCommand[0] >> 16) & 0xFF);
cur_object_set_int(objectOffset, gBehCommand[1]);
cur_object_set_vptr(objectOffset, gBehCommand[1]);
gBehCommand += 2;
return BEH_CONTINUE;
@@ -722,7 +722,7 @@ static BehCommandProc BehaviorJumpTable[] = {
Behavior24,
beh_cmd_delay_var,
Behavior26,
beh_cmd_obj_set_int32,
beh_cmd_obj_set_anims,
beh_cmd_obj_animate,
beh_cmd_obj_load_chill_param,
beh_cmd_collision_data,
+1
View File
@@ -13,6 +13,7 @@
#define cur_object_set_int(offset, value) gCurrentObject->OBJECT_FIELD_S32(offset) = (s32)(value)
#define cur_object_or_int(offset, value) gCurrentObject->OBJECT_FIELD_S32(offset) |= (s32)(value)
#define cur_object_and_int(offset, value) gCurrentObject->OBJECT_FIELD_S32(offset) &= (s32)(value)
#define cur_object_set_vptr(offset, value) gCurrentObject->OBJECT_FIELD_VPTR(offset) = (void *)(value)
#define object_and_int(object, offset, value) object->OBJECT_FIELD_S32(offset) &= (s32)(value)
+34 -34
View File
@@ -107,7 +107,7 @@ u32 unused_8038B894[3] = { 0 };
cmd+0x04: void *branchTarget
*/
void geo_layout_cmd_branch_and_link(void) {
gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + 4 + sizeof(void *));
gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
gGeoLayoutStack[gGeoLayoutStackIndex++] = (gCurGraphNodeIndex << 16) + gGeoLayoutReturnIndex;
gGeoLayoutReturnIndex = gGeoLayoutStackIndex;
gGeoLayoutCommand = segmented_to_virtual(cur_geo_cmd_ptr(0x04));
@@ -127,7 +127,7 @@ void geo_layout_cmd_end(void) {
*/
void geo_layout_cmd_branch(void) {
if (cur_geo_cmd_u8(0x01) == 1) {
gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + 4 + sizeof(void *));
gGeoLayoutStack[gGeoLayoutStackIndex++] = (uintptr_t) (gGeoLayoutCommand + CMD_PROCESS_OFFSET(8));
}
gGeoLayoutCommand = segmented_to_virtual(cur_geo_cmd_ptr(0x04));
@@ -142,13 +142,13 @@ void geo_layout_cmd_return(void) {
void geo_layout_cmd_open_node(void) {
gCurGraphNodeList[gCurGraphNodeIndex + 1] = gCurGraphNodeList[gCurGraphNodeIndex];
gCurGraphNodeIndex++;
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
// 0x05: Close node
void geo_layout_cmd_close_node(void) {
gCurGraphNodeIndex--;
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -164,7 +164,7 @@ void geo_layout_cmd_assign_as_view(void) {
gGeoViews[index] = gCurGraphNodeList[gCurGraphNodeIndex];
}
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -188,7 +188,7 @@ void geo_layout_cmd_update_node_flags(void) {
break;
}
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -227,7 +227,7 @@ void geo_layout_cmd_node_root(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x0C;
gGeoLayoutCommand += 0x0C << CMD_SIZE_SHIFT;
}
/*
@@ -242,7 +242,7 @@ void geo_layout_cmd_node_ortho_projection(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -263,14 +263,14 @@ void geo_layout_cmd_node_perspective(void) {
if (cur_geo_cmd_u8(0x01) != 0) {
// optional asm function
frustumFunc = (GraphNodeFunc) cur_geo_cmd_ptr(0x08);
gGeoLayoutCommand += sizeof(void *);
gGeoLayoutCommand += 4 << CMD_SIZE_SHIFT;
}
graphNode = init_graph_node_perspective(gGraphNodePool, NULL, (f32) fov, near, far, frustumFunc, 0);
register_scene_graph_node(&graphNode->fnNode.node);
gGeoLayoutCommand += 0x08;
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -284,12 +284,12 @@ void geo_layout_cmd_node_start(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
// 0x1F: No operation
void geo_layout_cmd_nop3(void) {
gGeoLayoutCommand += 0x10;
gGeoLayoutCommand += 0x10 << CMD_SIZE_SHIFT;
}
/*
@@ -303,7 +303,7 @@ void geo_layout_cmd_node_master_list(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -321,7 +321,7 @@ void geo_layout_cmd_node_level_of_detail(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08;
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -344,7 +344,7 @@ void geo_layout_cmd_node_switch_case(void) {
register_scene_graph_node(&graphNode->fnNode.node);
gGeoLayoutCommand += 0x04 + sizeof(void *);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -374,7 +374,7 @@ void geo_layout_cmd_node_camera(void) {
gGeoViews[0] = &graphNode->fnNode.node;
gGeoLayoutCommand += 0x10 + sizeof(void *);
gGeoLayoutCommand += 0x14 << CMD_SIZE_SHIFT;
}
/*
@@ -438,14 +438,14 @@ void geo_layout_cmd_node_translation_rotation(void) {
case 3:
vec3s_copy(translation, gVec3sZero);
vec3s_set(rotation, 0, (cmdPos[1] << 15) / 180, 0);
cmdPos += 2;
cmdPos += 2 << CMD_SIZE_SHIFT;
break;
}
if (params & 0x80) {
displayList = *(void **) &cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += sizeof(void*) / 2;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
graphNode = init_graph_node_translation_rotation(gGraphNodePool, NULL, drawingLayer, displayList,
@@ -480,7 +480,7 @@ void geo_layout_cmd_node_translation(void) {
if (params & 0x80) {
displayList = *(void **) &cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += sizeof(void*) / 2;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
graphNode =
@@ -516,7 +516,7 @@ void geo_layout_cmd_node_rotation(void) {
if (params & 0x80) {
displayList = *(void **) &cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += sizeof(void*) / 2;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
graphNode = init_graph_node_rotation(gGraphNodePool, NULL, drawingLayer, displayList, sp2c);
@@ -545,19 +545,19 @@ void geo_layout_cmd_node_scale(void) {
if (params & 0x80) {
displayList = cur_geo_cmd_ptr(0x08);
drawingLayer = params & 0x0F;
gGeoLayoutCommand += sizeof(void *);
gGeoLayoutCommand += 4 << CMD_SIZE_SHIFT;
}
graphNode = init_graph_node_scale(gGraphNodePool, NULL, drawingLayer, displayList, scale);
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08;
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
// 0x1E: No operation
void geo_layout_cmd_nop2(void) {
gGeoLayoutCommand += 0x08;
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -582,7 +582,7 @@ void geo_layout_cmd_node_animated_part(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08 + sizeof(void *);
gGeoLayoutCommand += 0x0C << CMD_SIZE_SHIFT;
}
/*
@@ -608,7 +608,7 @@ void geo_layout_cmd_node_billboard(void) {
if (params & 0x80) {
displayList = *(void **) &cmdPos[0];
drawingLayer = params & 0x0F;
cmdPos += sizeof(void*) / 2;
cmdPos += 2 << CMD_SIZE_SHIFT;
}
graphNode = init_graph_node_billboard(gGraphNodePool, NULL, drawingLayer, displayList, translation);
@@ -632,7 +632,7 @@ void geo_layout_cmd_node_display_list(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04 + sizeof(void *);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -651,7 +651,7 @@ void geo_layout_cmd_node_shadow(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08;
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
// 0x17: Create scene graph node that manages the group of all object nodes
@@ -662,7 +662,7 @@ void geo_layout_cmd_node_object_parent(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -679,7 +679,7 @@ void geo_layout_cmd_node_generated(void) {
register_scene_graph_node(&graphNode->fnNode.node);
gGeoLayoutCommand += 0x04 + sizeof(void *);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -698,12 +698,12 @@ void geo_layout_cmd_node_background(void) {
register_scene_graph_node(&graphNode->fnNode.node);
gGeoLayoutCommand += 0x04 + sizeof(void *);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
// 0x1A: No operation
void geo_layout_cmd_nop(void) {
gGeoLayoutCommand += 0x08;
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}
/*
@@ -730,7 +730,7 @@ void geo_layout_cmd_copy_view(void) {
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
/*
@@ -752,7 +752,7 @@ void geo_layout_cmd_node_held_obj(void) {
register_scene_graph_node(&graphNode->fnNode.node);
gGeoLayoutCommand += 0x08 + sizeof(void *);
gGeoLayoutCommand += 0x0C << CMD_SIZE_SHIFT;
}
/*
@@ -764,7 +764,7 @@ void geo_layout_cmd_node_culling_radius(void) {
struct GraphNodeCullingRadius *graphNode;
graphNode = init_graph_node_culling_radius(gGraphNodePool, NULL, cur_geo_cmd_s16(0x02));
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04;
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
+8 -5
View File
@@ -7,20 +7,23 @@
#define GEO_CMD_FLAGS_SET 1
#define GEO_CMD_FLAGS_CLEAR 2
#define CMD_SIZE_SHIFT (sizeof(void *) >> 3)
#define CMD_PROCESS_OFFSET(offset) ((offset & 3) | ((offset & ~3) << CMD_SIZE_SHIFT))
#define cur_geo_cmd_u8(offset) \
(gGeoLayoutCommand[offset])
(gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_s16(offset) \
(*(s16 *) &gGeoLayoutCommand[offset])
(*(s16 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_s32(offset) \
(*(s32 *) &gGeoLayoutCommand[offset])
(*(s32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_u32(offset) \
(*(u32 *) &gGeoLayoutCommand[offset])
(*(u32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_ptr(offset) \
(*(void **) &gGeoLayoutCommand[offset])
(*(void **) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
extern struct AllocOnlyPool *gGraphNodePool;
extern struct GraphNode *gCurRootGraphNode;
+5 -5
View File
@@ -497,9 +497,9 @@ struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *poo
*/
struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool,
struct GraphNodeHeldObject *graphNode,
struct GraphNodeObject *objNode,
struct Object *objNode,
Vec3s translation,
GraphNodeFunc nodeFunc, s32 unused) {
GraphNodeFunc nodeFunc, s32 playerIndex) {
if (pool != NULL) {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeHeldObject));
}
@@ -509,7 +509,7 @@ struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *po
vec3s_copy(graphNode->translation, translation);
graphNode->objNode = objNode;
graphNode->fnNode.func = nodeFunc;
graphNode->unused = unused;
graphNode->playerIndex = playerIndex;
if (nodeFunc != NULL) {
nodeFunc(GEO_CONTEXT_CREATE, &graphNode->fnNode.node, pool);
@@ -855,8 +855,8 @@ void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f posit
s16 frame;
if (animation != NULL) {
attribute = segmented_to_virtual(animation->index);
values = segmented_to_virtual(animation->values);
attribute = segmented_to_virtual((void *) animation->index);
values = segmented_to_virtual((void *) animation->values);
frame = obj->unk38.animFrame;
+4 -4
View File
@@ -76,7 +76,7 @@ extern Vec3s gVec3sOne;
// - for GEO_CONTEXT_CREATE it is the AllocOnlyPool from which the node was allocated
// - for GEO_CONTEXT_RENDER or GEO_CONTEXT_HELD_OBJ it is the top of the float matrix stack with type Mat4
// - for GEO_CONTEXT_AREA_* it is the root geo node
typedef s32 (*GraphNodeFunc)(s32 callContext, struct GraphNode *node, void *context);
typedef Gfx *(*GraphNodeFunc)(s32 callContext, struct GraphNode *node, void *context);
/** An extension of a graph node that includes a function pointer.
* Many graph node types have an update function that gets called
@@ -343,8 +343,8 @@ struct GraphNodeBackground
struct GraphNodeHeldObject
{
/*0x00*/ struct FnGraphNode fnNode;
/*0x18*/ s32 unused;
/*0x1C*/ struct GraphNodeObject *objNode; // assumed type
/*0x18*/ s32 playerIndex;
/*0x1C*/ struct Object *objNode;
/*0x20*/ Vec3s translation;
};
@@ -402,7 +402,7 @@ struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool,
struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool, struct GraphNodeBackground *sp1c,
u16 sp22, GraphNodeFunc sp24, s32 sp28);
struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool, struct GraphNodeHeldObject *sp1c,
struct GraphNodeObject *objNode, Vec3s translation, GraphNodeFunc nodeFunc, s32 unused);
struct Object *objNode, Vec3s translation, GraphNodeFunc nodeFunc, s32 playerIndex);
struct GraphNode *geo_add_child(struct GraphNode *, struct GraphNode *);
struct GraphNode *geo_remove_child(struct GraphNode *);
+25 -9
View File
@@ -9,14 +9,30 @@
#include "game/area.h"
#include "geo_layout.h"
#if IS_64_BIT
static s16 next_s16_in_geo_script(s16 **src) {
s16 ret;
if (((uintptr_t)(*src) & 7) == 4) {
*src += 2; // skip 32 bits
}
ret = *(*src)++;
if (((uintptr_t)(*src) & 7) == 4) {
*src += 2; // skip 32 bits
}
return ret;
}
#else
#define next_s16_in_geo_script(src) (*(*src)++)
#endif
/**
* Takes a pointer to three shorts (supplied by a geo layout script) and
* copies it to the destination float vector.
*/
s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
dst[0] = *src++;
dst[1] = *src++;
dst[2] = *src++;
dst[0] = next_s16_in_geo_script(&src);
dst[1] = next_s16_in_geo_script(&src);
dst[2] = next_s16_in_geo_script(&src);
return src;
}
@@ -26,9 +42,9 @@ s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
* with the other two 'geo-script vector to internal vector' functions.
*/
s16 *read_vec3s(Vec3s dst, s16 *src) {
dst[0] = *src++;
dst[1] = *src++;
dst[2] = *src++;
dst[0] = next_s16_in_geo_script(&src);
dst[1] = next_s16_in_geo_script(&src);
dst[2] = next_s16_in_geo_script(&src);
return src;
}
@@ -38,9 +54,9 @@ s16 *read_vec3s(Vec3s dst, s16 *src) {
* range.
*/
s16 *read_vec3s_angle(Vec3s dst, s16 *src) {
dst[0] = ((*src++) << 15) / 180;
dst[1] = ((*src++) << 15) / 180;
dst[2] = ((*src++) << 15) / 180;
dst[0] = (next_s16_in_geo_script(&src) << 15) / 180;
dst[1] = (next_s16_in_geo_script(&src) << 15) / 180;
dst[2] = (next_s16_in_geo_script(&src) << 15) / 180;
return src;
}
+35 -32
View File
@@ -2,29 +2,33 @@
#include "sm64.h"
#include "audio/external.h"
#include "buffers/framebuffers.h"
#include "game/area.h"
#include "game/display.h"
#include "game/game.h"
#include "geo_layout.h"
#include "graph_node.h"
#include "level_script.h"
#include "game/mario.h"
#include "math_util.h"
#include "game/memory.h"
#include "game/object_helpers.h"
#include "game/object_list_processor.h"
#include "game/area.h"
#include "game/profiler.h"
#include "game/save_file.h"
#include "game/sound_init.h"
#include "goddard/renderer.h"
#include "geo_layout.h"
#include "graph_node.h"
#include "level_script.h"
#include "math_util.h"
#include "surface_collision.h"
#include "surface_load.h"
#include "goddard/renderer.h"
#include "game/profiler.h"
#define CMD_GET(type, offset) (*(type *) ((offset) + (u8 *) sCurrentCmd))
#define CMD_SIZE_SHIFT (sizeof(void *) >> 3)
#define CMD_PROCESS_OFFSET(offset) ((offset & 3) | ((offset & ~3) << CMD_SIZE_SHIFT))
#define CMD_GET(type, offset) (*(type *) (CMD_PROCESS_OFFSET(offset) + (u8 *) sCurrentCmd))
// These are equal
#define CMD_NEXT ((struct LevelCommand *) ((u8 *) sCurrentCmd + sCurrentCmd->size))
#define NEXT_CMD ((struct LevelCommand *) (sCurrentCmd->size + (u8 *) sCurrentCmd))
#define CMD_NEXT ((struct LevelCommand *) ((u8 *) sCurrentCmd + (sCurrentCmd->size << CMD_SIZE_SHIFT)))
#define NEXT_CMD ((struct LevelCommand *) ((sCurrentCmd->size << CMD_SIZE_SHIFT) + (u8 *) sCurrentCmd))
struct LevelCommand {
/*00*/ u8 type;
@@ -85,22 +89,22 @@ static s32 eval_script_op(s8 op, s32 arg) {
static void level_cmd_load_and_execute(void) {
main_pool_push_state();
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 4 + sizeof(void *)), MEMORY_POOL_LEFT);
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8), MEMORY_POOL_LEFT);
*sStackTop++ = (uintptr_t) NEXT_CMD;
*sStackTop++ = (uintptr_t) sStackBase;
sStackBase = sStackTop;
sCurrentCmd = segmented_to_virtual(CMD_GET(void *, 4 + 2 * sizeof(void *)));
sCurrentCmd = segmented_to_virtual(CMD_GET(void *, 12));
}
static void level_cmd_exit_and_execute(void) {
void *targetAddr = CMD_GET(void *, 4 + 2 * sizeof(void *));
void *targetAddr = CMD_GET(void *, 12);
main_pool_pop_state();
main_pool_push_state();
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 4 + sizeof(void *)),
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8),
MEMORY_POOL_LEFT);
sStackTop = sStackBase;
@@ -224,18 +228,16 @@ static void level_cmd_skippable_nop(void) {
sCurrentCmd = CMD_NEXT;
}
// Converting data pointer to function pointer
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
static void level_cmd_call(void) {
s32 (*func)(s16, s32) = CMD_GET(void *, 4);
typedef s32 (*Func)(s16, s32);
Func func = CMD_GET(Func, 4);
sRegister = func(CMD_GET(s16, 2), sRegister);
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_call_loop(void) {
s32 (*func)(s16, s32) = CMD_GET(void *, 4);
typedef s32 (*Func)(s16, s32);
Func func = CMD_GET(Func, 4);
sRegister = func(CMD_GET(s16, 2), sRegister);
if (sRegister == 0) {
@@ -246,8 +248,6 @@ static void level_cmd_call_loop(void) {
}
}
#pragma GCC diagnostic pop
static void level_cmd_set_register(void) {
sRegister = CMD_GET(s16, 2);
sCurrentCmd = CMD_NEXT;
@@ -264,29 +264,28 @@ static void level_cmd_pop_pool_state(void) {
}
static void level_cmd_load_to_fixed_address(void) {
load_to_fixed_pool_addr(CMD_GET(void *, 4), CMD_GET(void *, 4 + sizeof(void *)),
CMD_GET(void *, 4 + 2 * sizeof(void *)));
load_to_fixed_pool_addr(CMD_GET(void *, 4), CMD_GET(void *, 8), CMD_GET(void *, 12));
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_load_raw(void) {
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 4 + sizeof(void *)),
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8),
MEMORY_POOL_LEFT);
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_load_mio0(void) {
load_segment_decompress(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 4 + sizeof(void *)));
load_segment_decompress(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8));
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_load_mario_head(void) {
// TODO: Fix these hardcoded sizes
void *addr = main_pool_alloc(0xE1000, MEMORY_POOL_LEFT);
void *addr = main_pool_alloc(DOUBLE_SIZE_ON_64_BIT(0xE1000), MEMORY_POOL_LEFT);
if (addr != NULL) {
gdm_init(addr, 0xE1000);
gd_add_to_heap(gZBuffer, SCREEN_WIDTH * SCREEN_HEIGHT * 2); // 0x25800
gd_add_to_heap(gFrameBuffer0, SCREEN_WIDTH * SCREEN_HEIGHT * 2 * 3); // 0x70800
gdm_init(addr, DOUBLE_SIZE_ON_64_BIT(0xE1000));
gd_add_to_heap(gZBuffer, sizeof(gZBuffer)); // 0x25800
gd_add_to_heap(gFrameBuffer0, 3 * sizeof(gFrameBuffer0)); // 0x70800
gdm_setup();
gdm_maketestdl(CMD_GET(s16, 2));
} else {
@@ -296,7 +295,7 @@ static void level_cmd_load_mario_head(void) {
}
static void level_cmd_load_mio0_texture(void) {
func_80278304(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 4 + sizeof(void *)));
func_80278304(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8));
sCurrentCmd = CMD_NEXT;
}
@@ -405,7 +404,7 @@ static void level_cmd_23(void) {
s16 arg0H = CMD_GET(u16, 2) >> 12;
void *arg1 = CMD_GET(void *, 4);
// load an f32, but using an integer load instruction for some reason (hence the union)
arg2.i = CMD_GET(s32, 4 + sizeof(void *));
arg2.i = CMD_GET(s32, 8);
if (model < 256) {
// GraphNodeScale has a GraphNode at the top. This
@@ -631,7 +630,11 @@ static void level_cmd_2A(void) {
static void level_cmd_set_mario_start_pos(void) {
gMarioSpawnInfo->areaIndex = CMD_GET(u8, 2);
#if IS_64_BIT
vec3s_set(gMarioSpawnInfo->startPos, CMD_GET(s16, 6), CMD_GET(s16, 8), CMD_GET(s16, 10));
#else
vec3s_copy(gMarioSpawnInfo->startPos, CMD_GET(Vec3s, 6));
#endif
vec3s_set(gMarioSpawnInfo->startAngle, 0, CMD_GET(s16, 4) * 0x8000 / 180, 0);
sCurrentCmd = CMD_NEXT;
-4
View File
@@ -1,10 +1,6 @@
#ifndef _LEVEL_SCRIPT_H
#define _LEVEL_SCRIPT_H
extern u8 gFrameBuffer0[];
extern u8 gFrameBuffer1[];
extern u8 gFrameBuffer2[];
struct LevelCommand *level_script_execute(struct LevelCommand *cmd);
extern u8 level_script_entry[];
+5 -1
View File
@@ -5,7 +5,7 @@
#include "math_util.h"
#include "surface_collision.h"
extern s16 gArctanTable[];
#include "trig_tables.inc.c"
// Variables for a spline curve animation (used for the flight path in the grand star cutscene)
Vec4s *gSplineKeyframe;
@@ -568,6 +568,9 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
* and no crashes occur.
*/
void mtxf_to_mtx(Mtx *dest, Mat4 src) {
#if ENDIAN_IND
guMtxF2L(src, dest);
#else
s32 asFixedPoint;
register s32 i;
register s16 *a3 = (s16 *) dest; // all integer parts stored in first 16 bytes
@@ -579,6 +582,7 @@ void mtxf_to_mtx(Mtx *dest, Mat4 src) {
*a3++ = GET_HIGH_S16_OF_32(asFixedPoint); // integer part
*t0++ = GET_LOW_S16_OF_32(asFixedPoint); // fraction part
}
#endif
}
/**
+17 -1
View File
@@ -1,8 +1,24 @@
#ifndef _MATH_UTIL_H_
#define _MATH_UTIL_H_
/*
* The sine and cosine tables overlap, but "#define gCosineTable (gSineTable +
* 0x400)" doesn't give expected codegen; gSineTable and gCosineTable need to
* be different symbols for code to match. Most likely the tables were placed
* adjacent to each other, and gSineTable cut short, such that reads overflow
* into gCosineTable.
*
* These kinds of out of bounds reads are undefined behavior, and break on
* e.g. GCC (which doesn't place the tables next to each other, and probably
* exploits array sizes for range analysis-based optimizations as well).
* Thus, for non-IDO compilers we use the standard-compliant version.
*/
extern f32 gSineTable[];
#if BUGFIXES_CRITICAL
#define gCosineTable (gSineTable + 0x400)
#else
extern f32 gCosineTable[];
#endif
#define sins(x) gSineTable[(u16) (x) >> 4]
#define coss(x) gCosineTable[(u16) (x) >> 4]
@@ -41,7 +57,7 @@ void mtxf_mul_vec3s(f32 a[4][4], Vec3s b);
void mtxf_to_mtx(Mtx *a, f32 b[4][4]);
void mtxf_rotate_xy(Mtx *a, s16 b);
void get_pos_from_transform_mtx(Vec3f a, f32 b[4][4], f32 c[4][4]);
void vec3f_get_dist_and_angle(Vec3f a, Vec3f b, f32 *c, s16 *d, s16 *e);
void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *yaw);
void vec3f_set_dist_and_angle(Vec3f a, Vec3f b, f32 c, s16 d, s16 e);
s32 approach_s32(s32 a, s32 b, s32 c, s32 d);
f32 approach_f32(f32 a, f32 b, f32 c, f32 d);