Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,7 @@ bool code33310_func_802BA4F0(ZoomCameraNode *self);
s32 code33250_func_802BA234(RandomCameraNode *self);

// --- core2/nc/cameranodelist.c ---
s32 __ncCameraNodeList_capacity();
s32 ncCameraNodeList_getNodeType(int camera_node_index);
s32 ncCameraNodeList_nodeIsValid(int camera_node_index);
void ncCameraNodeList_defrag();
Expand Down
2 changes: 0 additions & 2 deletions src/core1/viewport.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ void viewport_setPosition_f3(f32 x, f32 y, f32 z) {

void viewport_setRotation_vec3f(f32 src[3]) {
ml_vec3f_copy(sViewportRotation, src);
// [port] Nudge static-camera yaw on configured maps when in widescreen.
port_camera_applyWsYawFix(sViewportRotation);
}

void viewport_setRotation_f3(f32 pitch, f32 yaw, f32 roll) {
Expand Down
3 changes: 3 additions & 0 deletions src/core2/fx/cutscene_actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ Actor *func_802E0738(ActorMarker *marker, Gfx **gfx, Mtx **mtx, Vtx **vtx){
Actor *this;

this = marker_getActorAndRotation(marker, rotation);
if (!EventSystem_Should(VB_CUTSCENE_ACTOR_DRAW, true, this)) {
return this;
}
modelRender_setPreDrawCallback( (model_render_pre_draw_callback_f)func_802E0710, (void *)this);
modelRender_setPostDrawCallback((model_render_post_draw_callback_f)actor_postdrawMethod, (void *)marker);
modelRender_draw(gfx, mtx, this->position, rotation, this->scale, NULL, marker_loadModelBin(marker));
Expand Down
9 changes: 6 additions & 3 deletions src/core2/gc/transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ void gctransition_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {

//complex animation (from animation bin file)
if(s_current_transition.state == 1 || s_current_transition.state == 6){
modelRender_draw(gfx, mtx, sp58, vp_rotation, 1.0f, 0, s_current_transition.model_ptr);
// modelRender_draw(gfx, mtx, sp58, vp_rotation, 1.0f, 0, s_current_transition.model_ptr);
modelRender_draw(gfx, mtx, sp58, vp_rotation, transitionScale, 0, s_current_transition.model_ptr);
if(s_current_transition.anctrl != NULL){
gDPSetTextureFilter((*gfx)++, G_TF_BILERP);
gDPSetColorDither((*gfx)++, G_CD_MAGICSQ);
Expand All @@ -314,7 +315,8 @@ void gctransition_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {
vp_rotation[2] = s_current_transition.rotation - 90.0f*percentage;
scale = percentage*s_current_transition.transistion_info->scale + 0.1;
}
modelRender_draw(gfx, mtx, sp58, vp_rotation, scale, 0, s_current_transition.model_ptr);
// modelRender_draw(gfx, mtx, sp58, vp_rotation, scale, 0, s_current_transition.model_ptr);
modelRender_draw(gfx, mtx, sp58, vp_rotation, scale * transitionScale, 0, s_current_transition.model_ptr);
}
else if(s_current_transition.state == TRANSITION_STATE_5_FADE_OUT){//L8030B9EC
switch (s_current_transition.transistion_info->uid)
Expand All @@ -335,7 +337,8 @@ void gctransition_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {
break;
}
if(!(s_current_transition.substate < 3) || s_current_transition.transistion_info->uid != 0x11){
modelRender_draw(gfx, mtx, sp58, vp_rotation, scale, 0, s_current_transition.model_ptr);
// modelRender_draw(gfx, mtx, sp58, vp_rotation, scale, 0, s_current_transition.model_ptr);
modelRender_draw(gfx, mtx, sp58, vp_rotation, scale * transitionScale, 0, s_current_transition.model_ptr);
}
else{
modelRender_reset();
Expand Down
6 changes: 5 additions & 1 deletion src/core2/map/mapModel.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void mapModel_opa_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {

void mapModel_xlu_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {
s32 temp_a0;
f32 scale; // [port]

if (mapModel.model_bin_xlu != NULL) {
if (gsworld_getMap() == MAP_1D_MMM_CELLAR) {
Expand All @@ -385,7 +386,10 @@ void mapModel_xlu_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {
modelRender_setAnimatedTexturesCacheId(temp_a0);
}
modelRender_setEnvColor(mapModel.env_red, mapModel.env_green, mapModel.env_blue, 0xFF);
modelRender_draw(gfx, mtx, NULL, NULL, mapModel.description->scale, NULL, mapModel.model_bin_xlu);
// modelRender_draw(gfx, mtx, NULL, NULL, mapModel.description->scale, NULL, mapModel.model_bin_xlu);
scale = mapModel.description->scale;
CALL_EVENT(MapModelXluScale, gsworld_getMap(), &scale);
modelRender_draw(gfx, mtx, NULL, NULL, scale, NULL, mapModel.model_bin_xlu);
func_802F7BC0(gfx, mtx, vtx);
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/core2/nc/staticCamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,16 @@ void __ncStaticCamera_setToNode(s32 camera_node_index){
sp1C = ncCameraNodeList_getStaticCameraNode(camera_node_index);
cameraNodeType2_getPosition(sp1C, ncStaticCameraPosition);
cameraNodeType2_getPitchYawRoll(sp1C, ncStaticCameraRotation);
CALL_EVENT(CameraRotationAuthored, CAMERA_TYPE_3_STATIC, camera_node_index, ncStaticCameraPosition, ncStaticCameraRotation);
}

void ncStaticCamera_setToNode(s32 camera_node_index){
if (EventSystem_Should(VB_STATIC_CAMERA_SET, true, &camera_node_index)) {
camera_setType(CAMERA_TYPE_3_STATIC);
__ncStaticCamera_setToNode(camera_node_index);
}
camera_setType(CAMERA_TYPE_3_STATIC);
__ncStaticCamera_setToNode(camera_node_index);
}

void ncStaticCamera_exit(void){
if (EventSystem_Should(VB_STATIC_CAMERA_EXIT, true)) {
camera_setType(CAMERA_TYPE_2_DYNAMIC);
}
camera_setType(CAMERA_TYPE_2_DYNAMIC);
}

void ncStaticCamera_setPositionAndRotation(f32 arg0[3], f32 arg1[3]){
Expand Down
1 change: 1 addition & 0 deletions src/cutscenes/cutscene_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void func_802CDAC4(Actor *this){
sp1C[0] = this->pitch;
sp1C[1] = this->yaw;
sp1C[2] = 0.0f;
CALL_EVENT(CameraRotationAuthored, CAMERA_TYPE_1_UNKNOWN, this->actorTypeSpecificField, this->position, sp1C);
viewport_setRotation_vec3f(sp1C);
}

Expand Down
3 changes: 1 addition & 2 deletions src/port/Enhancements/Events/Hooks/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ typedef enum VBehaviorID {
VB_ZOOMBOX_TEXT_ADJUST, // text scale (shrink pause text) + X nudge (JP kana clearance)

// Camera behavior
VB_STATIC_CAMERA_SET,
VB_STATIC_CAMERA_EXIT,
VB_CUTSCENE_ACTOR_DRAW,
VB_CAMERA_LIVE_ASPECT,
VB_CAMERA_FOLLOW,
VB_CAMERA_APPLY_SHAKE,
Expand Down
2 changes: 2 additions & 0 deletions src/port/Enhancements/Events/Hooks/List/EngineEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef struct {
DEFINE_EVENT(OnModelDisplayListLoad, const char* path; u32 * dlWords; u32 dlWordCount; const ModelTexSize* texSizes;
u16 texCount;);
DEFINE_EVENT(ViewportFrustumUpdate, float* frustumX; float* frustumY;);
DEFINE_EVENT(CameraRotationAuthored, s32 source; s32 id; const f32* position; f32 * rotation;);
DEFINE_EVENT(MapModelXluScale, s32 map; f32 * scale;);
DEFINE_EVENT(OnTransitionModelScale, Gfx** gfx; Mtx * *mtx; s32 uid; f32 * scale;);
DEFINE_EVENT(OnTransitionStateUpdate, s32 modelId; s32 uid; s32 substate;);
DEFINE_EVENT(DrawDistanceCubeWidth, int32_t mapWidth; int32_t * width;);
Expand Down
2 changes: 2 additions & 0 deletions src/port/Enhancements/Events/PortEnhancements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void PortEnhancements_Register() {
REGISTER_EVENT(OnModelLoad);
REGISTER_EVENT(OnModelDisplayListLoad);
REGISTER_EVENT(ViewportFrustumUpdate);
REGISTER_EVENT(CameraRotationAuthored);
REGISTER_EVENT(MapModelXluScale);
REGISTER_EVENT(OnTransitionModelScale);
REGISTER_EVENT(OnTransitionStateUpdate);
REGISTER_EVENT(DrawDistanceCubeWidth);
Expand Down
122 changes: 122 additions & 0 deletions src/port/Patches/ActorSpecificPatches.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include <libultraship/libultraship.h>
#include <libultraship/bridge/consolevariablebridge.h>

#include "port/Engine.h"
#include "port/Patches/Patches.h"
#include "port/UI/cvar_prefixes.h"
#include "port/Enhancements/Events/Hooks/Events.h"
#include "port/ShipInit.hpp"
#include "port/ShipUtils.h"

#include <map>

#include "enums.h"
#include "functions.h"
#include "variables.h"
#include "actor.h"

#define CVAR_WS_CAMERA_FIX CVAR_ENHANCEMENT("Fix.WidescreenCamera")

struct WsXluScaleFix {
int32_t map;
float scale;
};

struct HiddenCutsceneActor {
int32_t map;
int32_t modelId;
float delay = 0.0f;
};

struct SpawnAnchor {
float position[3];
float elapsed;
bool moved;
};

static const WsXluScaleFix sWsXluScaleFixes[] = {
{ .map = MAP_1F_CS_START_RAREWARE, .scale = 1.1f },
};
static const HiddenCutsceneActor sHiddenCutsceneActors[] = {
{ .map = MAP_1F_CS_START_RAREWARE, .modelId = ASSET_3ED_MODEL_BUZZBOMB },
{ .map = MAP_1E_CS_START_NINTENDO, .modelId = ASSET_353_MODEL_BIGBUTT, .delay = 0.2f },
{ .map = MAP_1E_CS_START_NINTENDO, .modelId = ASSET_354_MODEL_SMALL_BULL, .delay = 0.7f },
{ .map = MAP_1E_CS_START_NINTENDO, .modelId = ASSET_369_MODEL_CONCERT_FROG, .delay = 0.2f },
};
static constexpr int HIDDEN_CUTSCENE_ACTOR_COUNT = sizeof(sHiddenCutsceneActors) / sizeof(sHiddenCutsceneActors[0]);
static constexpr float kHiddenMoveThreshold = 1.0f;
static std::map<ActorMarker*, SpawnAnchor> sSpawnAnchors;
static constexpr int WS_XLU_SCALE_FIX_COUNT = sizeof(sWsXluScaleFixes) / sizeof(sWsXluScaleFixes[0]);

void RegisterWidescreenXluScale() {
COND_HOOK(MapModelXluScale, EVENT_PRIORITY_NORMAL, CVarGetInteger(CVAR_WS_CAMERA_FIX, 1), [](IEvent* event) {
float aspectScale = port_wsCameraYawScale();
if (aspectScale <= 0.0f) {
return;
}
auto* ev = (MapModelXluScale*)event;
for (int i = 0; i < WS_XLU_SCALE_FIX_COUNT; i++) {
if (ev->map == sWsXluScaleFixes[i].map) {
*ev->scale *= 1.0f + (sWsXluScaleFixes[i].scale - 1.0f) * aspectScale;
break;
}
}
});
}

static const HiddenCutsceneActor* findHiddenCutsceneActor(int32_t map, int32_t modelId) {
for (int i = 0; i < HIDDEN_CUTSCENE_ACTOR_COUNT; i++) {
if (map == sHiddenCutsceneActors[i].map && modelId == sHiddenCutsceneActors[i].modelId) {
return &sHiddenCutsceneActors[i];
}
}
return nullptr;
}

void RegisterHiddenCutsceneActors() {
COND_VB_SHOULD(VB_CUTSCENE_ACTOR_DRAW, EVENT_PRIORITY_NORMAL, CVarGetInteger(CVAR_WS_CAMERA_FIX, 1), {
Actor* actor = va_arg(args, Actor*);
if (actor == nullptr || actor->marker == nullptr) {
return;
}
const HiddenCutsceneActor* hidden = findHiddenCutsceneActor((int32_t)gsworld_getMap(), actor->marker->modelId);
if (hidden == nullptr) {
return;
}

auto entry = sSpawnAnchors.find(actor->marker);
if (entry == sSpawnAnchors.end()) {
SpawnAnchor anchor;
for (int i = 0; i < 3; i++) {
anchor.position[i] = actor->position[i];
}
anchor.elapsed = 0.0f;
anchor.moved = false;
entry = sSpawnAnchors.emplace(actor->marker, anchor).first;
}
SpawnAnchor& anchor = entry->second;

if (!anchor.moved) {
float dx = actor->position[0] - anchor.position[0];
float dy = actor->position[1] - anchor.position[1];
float dz = actor->position[2] - anchor.position[2];
if ((dx * dx + dy * dy + dz * dz) > (kHiddenMoveThreshold * kHiddenMoveThreshold)) {
anchor.moved = true;
} else {
*should = false;
return;
}
}

if (anchor.elapsed < hidden->delay) {
anchor.elapsed += time_getDelta();
*should = false;
}
});

COND_HOOK(OnMapLoad, EVENT_PRIORITY_NORMAL, CVarGetInteger(CVAR_WS_CAMERA_FIX, 1),
[](IEvent* event) { sSpawnAnchors.clear(); });
}

static RegisterShipInitFunc widescreenXluScaleInitFunc(RegisterWidescreenXluScale, { CVAR_WS_CAMERA_FIX });
static RegisterShipInitFunc hiddenCutsceneActorsInitFunc(RegisterHiddenCutsceneActors, { CVAR_WS_CAMERA_FIX });
3 changes: 1 addition & 2 deletions src/port/Patches/AnimVertexPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ extern "C" {
namespace {

// A single anim-vertex model runs 500-750 vertices. This covers roughly 20-25
// of them on screen at once; past that a draw falls back to the shared buffer,
// which is exactly the behaviour that existed before this file.
// of them on screen at once; past that a draw falls back to the shared buffer.
constexpr size_t kVerticesPerSlot = 16384;
constexpr int kSlots = 2;

Expand Down
Loading
Loading