From 2c8382e60e6086df5b3835f009464a97b2a0cb4b Mon Sep 17 00:00:00 2001 From: IvanDSM Date: Sat, 16 May 2020 21:39:48 -0300 Subject: [PATCH 1/5] Add --help and --windowed CLI options. --- src/pc/cliopts.c | 17 +++++++++++++++-- src/pc/gfx/gfx_sdl2.c | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 1e3b29c..14497e3 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -23,7 +23,20 @@ void parse_cli_opts(int argc, char* argv[]) gCLIOpts.SkipIntro = 1; if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen - gCLIOpts.FullScreen = 1; + gCLIOpts.FullScreen = 1; + + if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode + gCLIOpts.FullScreen = 2; + + if (strcmp(argv[i], "--help") == 0) // Print help + { + printf("Super Mario 64 PC Port\n"); + printf("%-20s\tSkips the Peach and Castle intro when starting a new game.\n", "--skip-intro"); + printf("%-20s\tStarts the game in full screen mode.\n", "--fullscreen"); + printf("%-20s\tStarts the game in windowed mode.\n", "--windowed"); + printf("%-20s\tSaves the configuration file as CONFIGNAME.\n", "--configfile CONFIGNAME"); + exit(0); + } if (strncmp(argv[i], "--configfile", strlen("--configfile")) == 0) { @@ -36,7 +49,7 @@ void parse_cli_opts(int argc, char* argv[]) strncpy(gCLIOpts.ConfigFile, argv[i+1], strlen(argv[i+1])); } } - } + } } } } \ No newline at end of file diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 57ff486..2a0a54d 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -114,9 +114,10 @@ static void gfx_sdl_init(void) { window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; - if (gCLIOpts.FullScreen) { + if (gCLIOpts.FullScreen == 1) configFullscreen = true; - } + else if (gCLIOpts.FullScreen == 2) + configFullscreen = false; if (configFullscreen) { window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; From 5145f2a89771d300bc66059be28c042a8ea55bad Mon Sep 17 00:00:00 2001 From: IvanDSM Date: Sat, 16 May 2020 21:53:00 -0300 Subject: [PATCH 2/5] Fix --fullscreen/--windowed CLI option altering config file. Previously, when the --fullscreen or --windowed CLI options were set, configFullscreen was overwritten. This caused the config file to be changed according to the CLI options given when running the executable. A helper variable that copies configFullscreen stops the game from overwritting the config file. --- src/pc/gfx/gfx_sdl2.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 2a0a54d..31fb9ff 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -97,6 +97,7 @@ static void gfx_sdl_set_fullscreen(bool fullscreen) { static void gfx_sdl_init(void) { Uint32 window_flags = 0; + u8 Fullscreen; SDL_Init(SDL_INIT_VIDEO); @@ -114,12 +115,13 @@ static void gfx_sdl_init(void) { window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; + Fullscreen = configFullscreen; if (gCLIOpts.FullScreen == 1) - configFullscreen = true; + Fullscreen = true; else if (gCLIOpts.FullScreen == 2) - configFullscreen = false; + Fullscreen = false; - if (configFullscreen) { + if (Fullscreen) { window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } From 5558ecbd4e71912f03840740e1c38f9b06773424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sun, 17 May 2020 02:15:11 -0300 Subject: [PATCH 3/5] Fixes billboarding-related problems --- data/behavior_data.c | 5 +---- src/engine/behavior_script.c | 10 ---------- src/engine/graph_node.h | 1 - src/engine/math_util.c | 25 ------------------------- src/engine/math_util.h | 1 - src/game/behaviors/cannon.inc.c | 10 ++++------ src/game/object_helpers.c | 4 ---- src/game/object_helpers.h | 1 - src/game/rendering_graph_node.c | 3 --- 9 files changed, 5 insertions(+), 55 deletions(-) diff --git a/data/behavior_data.c b/data/behavior_data.c index 3b4af5a..8269246 100644 --- a/data/behavior_data.c +++ b/data/behavior_data.c @@ -219,9 +219,6 @@ #define BILLBOARD() \ BC_B(0x21) -#define CYLBOARD() \ - BC_B(0x38) - // Hides the current object. #define HIDE() \ BC_B(0x22) @@ -3183,7 +3180,7 @@ const BehaviorScript bhvFloorTrapInCastle[] = { const BehaviorScript bhvTree[] = { BEGIN(OBJ_LIST_POLELIKE), - CYLBOARD(), + BILLBOARD(), OR_INT(oFlags, OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE), SET_INT(oInteractType, INTERACT_POLE), SET_HITBOX(/*Radius*/ 80, /*Height*/ 500), diff --git a/src/engine/behavior_script.c b/src/engine/behavior_script.c index 539f3a3..03c267c 100644 --- a/src/engine/behavior_script.c +++ b/src/engine/behavior_script.c @@ -133,15 +133,6 @@ static s32 bhv_cmd_disable_rendering(void) { // Usage: BILLBOARD() static s32 bhv_cmd_billboard(void) { gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_BILLBOARD; - - gCurBhvCommand++; - return BHV_PROC_CONTINUE; -} - -// Command 0x -static s32 bhv_cmd_cylboard(void) { - gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_CYLBOARD; - gCurBhvCommand++; return BHV_PROC_CONTINUE; } @@ -906,7 +897,6 @@ static BhvCommandProc BehaviorCmdTable[] = { bhv_cmd_disable_rendering, //35 bhv_cmd_set_int_unused, //36 bhv_cmd_spawn_water_droplet, //37 - bhv_cmd_cylboard //38 }; // Execute the behavior script of the current object, process the object flags, and other miscellaneous code for updating objects. diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h index c99e5f3..2778cc9 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h @@ -30,7 +30,6 @@ extern Vec3s gVec3sOne; #define GRAPH_RENDER_Z_BUFFER (1 << 3) #define GRAPH_RENDER_INVISIBLE (1 << 4) #define GRAPH_RENDER_HAS_ANIMATION (1 << 5) -#define GRAPH_RENDER_CYLBOARD (1 << 6) // Whether the node type has a function pointer of type GraphNodeFunc #define GRAPH_NODE_TYPE_FUNCTIONAL 0x100 diff --git a/src/engine/math_util.c b/src/engine/math_util.c index 3f027ed..8643f5e 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -377,31 +377,6 @@ void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) { dest[3][3] = 1; } -void mtxf_cylboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) { //straight up mtxf_billboard but minus the dest[1][n] lines. transform for cylindrical billboards - dest[0][0] = coss(angle); - dest[0][1] = sins(angle); - dest[0][2] = 0; - dest[0][3] = 0; - - dest[1][0] = mtx[1][0]; - dest[1][1] = mtx[1][1]; - dest[1][2] = mtx[1][2]; - dest[1][3] = 0; - - dest[2][0] = 0; - dest[2][1] = 0; - dest[2][2] = 1; - dest[2][3] = 0; - - dest[3][0] = - mtx[0][0] * position[0] + mtx[1][0] * position[1] + mtx[2][0] * position[2] + mtx[3][0]; - dest[3][1] = - mtx[0][1] * position[0] + mtx[1][1] * position[1] + mtx[2][1] * position[2] + mtx[3][1]; - dest[3][2] = - mtx[0][2] * position[0] + mtx[1][2] * position[1] + mtx[2][2] * position[2] + mtx[3][2]; - dest[3][3] = 1; -} - /** * Set 'dest' to a transformation matrix that aligns an object with the terrain * based on the normal. Used for enemies. diff --git a/src/engine/math_util.h b/src/engine/math_util.h index b8b7f1b..650fe97 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -56,7 +56,6 @@ void mtxf_lookat(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d); void mtxf_rotate_zxy_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c); void mtxf_rotate_xyz_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c); void mtxf_billboard(f32 mtx1[4][4], f32 mtx2[4][4], Vec3f c, s16 d); -void mtxf_cylboard(f32 mtx1[4][4], f32 mtx2[4][4], Vec3f c, s16 d); void mtxf_align_terrain_normal(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d); void mtxf_align_terrain_triangle(f32 mtx[4][4], Vec3f b, s16 c, f32 d); void mtxf_mul(f32 dest[4][4], f32 a[4][4], f32 b[4][4]); diff --git a/src/game/behaviors/cannon.inc.c b/src/game/behaviors/cannon.inc.c index a8cfcab..5f55ca8 100644 --- a/src/game/behaviors/cannon.inc.c +++ b/src/game/behaviors/cannon.inc.c @@ -17,11 +17,9 @@ void opened_cannon_act_0(void) { cur_obj_enable_rendering(); cur_obj_become_tangible(); } - cur_obj_become_tangible(); - cur_obj_enable_rendering(); if (o->oDistanceToMario < 500.0f) { - //cur_obj_become_tangible(); - //cur_obj_enable_rendering(); + cur_obj_become_tangible(); + cur_obj_enable_rendering(); if (o->oInteractStatus & INT_STATUS_INTERACTED && (!(o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB))) // bob-omb explodes when it gets into a cannon @@ -32,8 +30,8 @@ void opened_cannon_act_0(void) { } else o->oInteractStatus = 0; } else { - //cur_obj_become_intangible(); - //cur_obj_disable_rendering(); + cur_obj_become_intangible(); + cur_obj_disable_rendering(); o->oCannonUnk10C = 0; } } diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index e05f774..c0ceb4b 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -1595,10 +1595,6 @@ void obj_set_billboard(struct Object *obj) { obj->header.gfx.node.flags |= GRAPH_RENDER_BILLBOARD; } -void obj_set_cylboard(struct Object *obj) { - obj->header.gfx.node.flags |= GRAPH_RENDER_CYLBOARD; -} - void cur_obj_set_hitbox_radius_and_height(f32 radius, f32 height) { o->hitboxRadius = radius; o->hitboxHeight = height; diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 577f8f6..80806bd 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -292,7 +292,6 @@ extern void cur_obj_shake_y(f32); void cur_obj_start_cam_event(struct Object *obj, s32 cameraEvent); // extern ? set_mario_interact_hoot_if_in_range(?); void obj_set_billboard(struct Object *a0); -void obj_set_cylboard(struct Object *a0); void cur_obj_set_hitbox_radius_and_height(f32,f32); void cur_obj_set_hurtbox_radius_and_height(f32,f32); // extern ? obj_spawn_loot_coins(?); diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index a96eafb..d83616d 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -796,9 +796,6 @@ static void geo_process_object(struct Object *node) { if (node->header.gfx.throwMatrix != NULL) { mtxf_mul(gMatStack[gMatStackIndex + 1], (void *) node->header.gfx.throwMatrix, gMatStack[gMatStackIndex]); - } else if (node->header.gfx.node.flags & GRAPH_RENDER_CYLBOARD) { - mtxf_cylboard(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex], - node->header.gfx.pos, gCurGraphNodeCamera->roll); } else if (node->header.gfx.node.flags & GRAPH_RENDER_BILLBOARD) { mtxf_billboard(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex], node->header.gfx.pos, gCurGraphNodeCamera->roll); From d543bd0b3def479d0ac17183c14fd5ab4a3578b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sun, 17 May 2020 02:15:11 -0300 Subject: [PATCH 4/5] Revert "Fixes billboarding-related problems" This reverts commit 5558ecbd4e71912f03840740e1c38f9b06773424. --- data/behavior_data.c | 5 ++++- src/engine/behavior_script.c | 10 ++++++++++ src/engine/graph_node.h | 1 + src/engine/math_util.c | 25 +++++++++++++++++++++++++ src/engine/math_util.h | 1 + src/game/behaviors/cannon.inc.c | 10 ++++++---- src/game/object_helpers.c | 4 ++++ src/game/object_helpers.h | 1 + src/game/rendering_graph_node.c | 3 +++ 9 files changed, 55 insertions(+), 5 deletions(-) diff --git a/data/behavior_data.c b/data/behavior_data.c index 8269246..3b4af5a 100644 --- a/data/behavior_data.c +++ b/data/behavior_data.c @@ -219,6 +219,9 @@ #define BILLBOARD() \ BC_B(0x21) +#define CYLBOARD() \ + BC_B(0x38) + // Hides the current object. #define HIDE() \ BC_B(0x22) @@ -3180,7 +3183,7 @@ const BehaviorScript bhvFloorTrapInCastle[] = { const BehaviorScript bhvTree[] = { BEGIN(OBJ_LIST_POLELIKE), - BILLBOARD(), + CYLBOARD(), OR_INT(oFlags, OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE), SET_INT(oInteractType, INTERACT_POLE), SET_HITBOX(/*Radius*/ 80, /*Height*/ 500), diff --git a/src/engine/behavior_script.c b/src/engine/behavior_script.c index 03c267c..539f3a3 100644 --- a/src/engine/behavior_script.c +++ b/src/engine/behavior_script.c @@ -133,6 +133,15 @@ static s32 bhv_cmd_disable_rendering(void) { // Usage: BILLBOARD() static s32 bhv_cmd_billboard(void) { gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_BILLBOARD; + + gCurBhvCommand++; + return BHV_PROC_CONTINUE; +} + +// Command 0x +static s32 bhv_cmd_cylboard(void) { + gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_CYLBOARD; + gCurBhvCommand++; return BHV_PROC_CONTINUE; } @@ -897,6 +906,7 @@ static BhvCommandProc BehaviorCmdTable[] = { bhv_cmd_disable_rendering, //35 bhv_cmd_set_int_unused, //36 bhv_cmd_spawn_water_droplet, //37 + bhv_cmd_cylboard //38 }; // Execute the behavior script of the current object, process the object flags, and other miscellaneous code for updating objects. diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h index 2778cc9..c99e5f3 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h @@ -30,6 +30,7 @@ extern Vec3s gVec3sOne; #define GRAPH_RENDER_Z_BUFFER (1 << 3) #define GRAPH_RENDER_INVISIBLE (1 << 4) #define GRAPH_RENDER_HAS_ANIMATION (1 << 5) +#define GRAPH_RENDER_CYLBOARD (1 << 6) // Whether the node type has a function pointer of type GraphNodeFunc #define GRAPH_NODE_TYPE_FUNCTIONAL 0x100 diff --git a/src/engine/math_util.c b/src/engine/math_util.c index 8643f5e..3f027ed 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -377,6 +377,31 @@ void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) { dest[3][3] = 1; } +void mtxf_cylboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) { //straight up mtxf_billboard but minus the dest[1][n] lines. transform for cylindrical billboards + dest[0][0] = coss(angle); + dest[0][1] = sins(angle); + dest[0][2] = 0; + dest[0][3] = 0; + + dest[1][0] = mtx[1][0]; + dest[1][1] = mtx[1][1]; + dest[1][2] = mtx[1][2]; + dest[1][3] = 0; + + dest[2][0] = 0; + dest[2][1] = 0; + dest[2][2] = 1; + dest[2][3] = 0; + + dest[3][0] = + mtx[0][0] * position[0] + mtx[1][0] * position[1] + mtx[2][0] * position[2] + mtx[3][0]; + dest[3][1] = + mtx[0][1] * position[0] + mtx[1][1] * position[1] + mtx[2][1] * position[2] + mtx[3][1]; + dest[3][2] = + mtx[0][2] * position[0] + mtx[1][2] * position[1] + mtx[2][2] * position[2] + mtx[3][2]; + dest[3][3] = 1; +} + /** * Set 'dest' to a transformation matrix that aligns an object with the terrain * based on the normal. Used for enemies. diff --git a/src/engine/math_util.h b/src/engine/math_util.h index 650fe97..b8b7f1b 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -56,6 +56,7 @@ void mtxf_lookat(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d); void mtxf_rotate_zxy_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c); void mtxf_rotate_xyz_and_translate(f32 mtx[4][4], Vec3f b, Vec3s c); void mtxf_billboard(f32 mtx1[4][4], f32 mtx2[4][4], Vec3f c, s16 d); +void mtxf_cylboard(f32 mtx1[4][4], f32 mtx2[4][4], Vec3f c, s16 d); void mtxf_align_terrain_normal(f32 mtx[4][4], Vec3f b, Vec3f c, s16 d); void mtxf_align_terrain_triangle(f32 mtx[4][4], Vec3f b, s16 c, f32 d); void mtxf_mul(f32 dest[4][4], f32 a[4][4], f32 b[4][4]); diff --git a/src/game/behaviors/cannon.inc.c b/src/game/behaviors/cannon.inc.c index 5f55ca8..a8cfcab 100644 --- a/src/game/behaviors/cannon.inc.c +++ b/src/game/behaviors/cannon.inc.c @@ -17,9 +17,11 @@ void opened_cannon_act_0(void) { cur_obj_enable_rendering(); cur_obj_become_tangible(); } + cur_obj_become_tangible(); + cur_obj_enable_rendering(); if (o->oDistanceToMario < 500.0f) { - cur_obj_become_tangible(); - cur_obj_enable_rendering(); + //cur_obj_become_tangible(); + //cur_obj_enable_rendering(); if (o->oInteractStatus & INT_STATUS_INTERACTED && (!(o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB))) // bob-omb explodes when it gets into a cannon @@ -30,8 +32,8 @@ void opened_cannon_act_0(void) { } else o->oInteractStatus = 0; } else { - cur_obj_become_intangible(); - cur_obj_disable_rendering(); + //cur_obj_become_intangible(); + //cur_obj_disable_rendering(); o->oCannonUnk10C = 0; } } diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index c0ceb4b..e05f774 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -1595,6 +1595,10 @@ void obj_set_billboard(struct Object *obj) { obj->header.gfx.node.flags |= GRAPH_RENDER_BILLBOARD; } +void obj_set_cylboard(struct Object *obj) { + obj->header.gfx.node.flags |= GRAPH_RENDER_CYLBOARD; +} + void cur_obj_set_hitbox_radius_and_height(f32 radius, f32 height) { o->hitboxRadius = radius; o->hitboxHeight = height; diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 80806bd..577f8f6 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -292,6 +292,7 @@ extern void cur_obj_shake_y(f32); void cur_obj_start_cam_event(struct Object *obj, s32 cameraEvent); // extern ? set_mario_interact_hoot_if_in_range(?); void obj_set_billboard(struct Object *a0); +void obj_set_cylboard(struct Object *a0); void cur_obj_set_hitbox_radius_and_height(f32,f32); void cur_obj_set_hurtbox_radius_and_height(f32,f32); // extern ? obj_spawn_loot_coins(?); diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index d83616d..a96eafb 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -796,6 +796,9 @@ static void geo_process_object(struct Object *node) { if (node->header.gfx.throwMatrix != NULL) { mtxf_mul(gMatStack[gMatStackIndex + 1], (void *) node->header.gfx.throwMatrix, gMatStack[gMatStackIndex]); + } else if (node->header.gfx.node.flags & GRAPH_RENDER_CYLBOARD) { + mtxf_cylboard(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex], + node->header.gfx.pos, gCurGraphNodeCamera->roll); } else if (node->header.gfx.node.flags & GRAPH_RENDER_BILLBOARD) { mtxf_billboard(gMatStack[gMatStackIndex + 1], gMatStack[gMatStackIndex], node->header.gfx.pos, gCurGraphNodeCamera->roll); From bc5942d189b048269f421f3c691fcf9fecece643 Mon Sep 17 00:00:00 2001 From: "V. R. Miguel" <36349314+vrmiguel@users.noreply.github.com> Date: Sun, 17 May 2020 03:34:05 -0300 Subject: [PATCH 5/5] A better fix to the cylboard problem So we've reverted the previous 'fix' and add this one, by @HeavenVolkoff. --- src/game/spawn_object.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index 5e41658..cc15c8e 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -196,6 +196,7 @@ void unload_object(struct Object *obj) { geo_add_child(&gObjParentGraphNode, &obj->header.gfx.node); obj->header.gfx.node.flags &= ~GRAPH_RENDER_BILLBOARD; + obj->header.gfx.node.flags &= ~GRAPH_RENDER_CYLBOARD; obj->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE; deallocate_object(&gFreeObjectList, &obj->header);