Skip to content

Commit

Permalink
Merge branch 'accessibility' into accessibility-dpadlook
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonSpeedruns authored Apr 14, 2022
2 parents 9bb913f + 6f60652 commit 7090a5b
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 31 deletions.
9 changes: 5 additions & 4 deletions libultraship/libultraship/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,22 @@ namespace Ship {
WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp);
}

void task1(const char textToRead[])
void task1(const std::string & textToRead)
{
const int w = 512;
int* wp = const_cast <int*> (&w);
*wp = strlen(textToRead);
*wp = strlen(textToRead.c_str());

wchar_t wtext[w];
mbstowcs(wtext, textToRead, strlen(textToRead) + 1);
mbstowcs(wtext, textToRead.c_str(), strlen(textToRead.c_str()) + 1);

pVoice->Speak(wtext, SPF_IS_XML | SPF_ASYNC | SPF_PURGEBEFORESPEAK, NULL);
}

void Window::ReadText(const char textToRead[])
{
std::thread t1(task1, textToRead);
std::string textCopy(textToRead);
std::thread t1(task1, textCopy);
t1.detach();
}

Expand Down
3 changes: 2 additions & 1 deletion soh/include/z64collision_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ typedef enum {
/* 4 */ ELEMTYPE_UNK4,
/* 5 */ ELEMTYPE_UNK5,
/* 6 */ ELEMTYPE_UNK6,
/* 7 */ ELEMTYPE_UNK7
/* 7 */ ELEMTYPE_UNK7,
/* 8 */ ELEMTYPE_SENSING
} ElementType;

#define AT_NONE 0 // No flags set. Cannot have AT collisions when set as AT
Expand Down
3 changes: 3 additions & 0 deletions soh/soh/Enhancements/bootcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ void BootCommands_Init()
CVar_RegisterS32("gDebugEnabled", 0);
CVar_RegisterS32("gPauseLiveLink", 0);
CVar_RegisterS32("gDPadLook", 0);
CVar_RegisterS32("gAccessibleInteraction", 0);
CVar_RegisterS32("gMoreTargets", 0);
CVar_RegisterS32("gAimAudioCues", 0);
}

//void BootCommands_ParseBootArgs(char* str)
Expand Down
31 changes: 29 additions & 2 deletions soh/src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Gl
targetCtx->activeCategory = actorCategory;
targetCtx->unk_40 = 1.0f;

/*
if (CVar_GetS32("gBlindMode", 0)) {
u16 targetSound;
Expand Down Expand Up @@ -554,6 +555,7 @@ void func_8002C7BC(TargetContext* targetCtx, Player* player, Actor* actorArg, Gl
Audio_PlaySoundGeneral(targetSound, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
}
*/
}

if (unkActor == NULL) {
Expand Down Expand Up @@ -1787,8 +1789,33 @@ u32 func_8002F090(Actor* actor, f32 arg1) {
return arg1 < D_80115FF8[actor->targetMode].rangeSq;
}

s32 Actor_IsTargetable(Actor* actor, Player* player) {
s32 targetMode = CVar_GetS32("gMoreTargets", 0);

if ((actor->update == NULL) || ((Player*)actor == player)) {
return false;
}

if (targetMode == 99) {
return true;
} else if (targetMode == 2) {
return CHECK_FLAG_ALL(actor->flags, ACTOR_FLAG_0) ||
actor->category == ACTORCAT_CHEST ||
actor->category == ACTORCAT_SWITCH ||
actor->id == ACTOR_EN_SW || actor->id == ACTOR_BOSS_GANON ||
actor->id == ACTOR_OBJ_HSBLOCK || actor->id == ACTOR_OBJ_SYOKUDAI;
} else if (targetMode == 1) {
return CHECK_FLAG_ALL(actor->flags, ACTOR_FLAG_0) ||
actor->category == ACTORCAT_CHEST ||
actor->category == ACTORCAT_SWITCH;
} else {
//original/default
return CHECK_FLAG_ALL(actor->flags, ACTOR_FLAG_0);
}
}

s32 func_8002F0C8(Actor* actor, Player* player, s32 flag) {
if ((actor->update == NULL) || !(actor->flags & ACTOR_FLAG_0)) {
if (!Actor_IsTargetable(actor, player)) {
return true;
}

Expand Down Expand Up @@ -3225,7 +3252,7 @@ void func_800328D4(GlobalContext* globalCtx, ActorContext* actorCtx, Player* pla
sp84 = player->unk_664;

while (actor != NULL) {
if ((actor->update != NULL) && ((Player*)actor != player) && CHECK_FLAG_ALL(actor->flags, ACTOR_FLAG_0)) {
if (Actor_IsTargetable(actor, player)) {

// This block below is for determining the closest actor to player in determining the volume
// used while playing enemy bgm music
Expand Down
68 changes: 65 additions & 3 deletions soh/src/code/z_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,66 @@ s32 Camera_Noop(Camera* camera) {
return true;
}

s32 Camera_Blind(Camera* camera) {
Normal1* norm1 = (Normal1*)camera->paramData;

f32 playerHeight = Player_GetHeight(camera->player);
f32 sp94;
CamColChk bgChk;

sCameraInterfaceFlags = norm1->interfaceFlags;

if (RELOAD_PARAMS) {
VecSph eyeAdjustment1;
Vec3f oldCamRot;
oldCamRot.x = camera->player->actor.world.pos.x;
oldCamRot.y = camera->player->actor.world.pos.y + Player_GetHeight(camera->player);
oldCamRot.z = camera->player->actor.world.pos.z;
OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment1, &oldCamRot, &camera->eye);
OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment1, &oldCamRot, &camera->eyeNext);

CameraModeValue* values = sCameraSettings[camera->setting].cameraModes[camera->mode].values;
f32 yNormal = (1.0f + PCT(R_CAM_YOFFSET_NORM) - PCT(R_CAM_YOFFSET_NORM) * (68.0f / playerHeight));
sp94 = yNormal * PCT(playerHeight);

norm1->yOffset = NEXTSETTING * sp94;
norm1->distMin = NEXTSETTING * sp94;
norm1->distMax = NEXTSETTING * sp94;
norm1->pitchTarget = DEGF_TO_BINANG(NEXTSETTING);
norm1->unk_0C = NEXTSETTING;
norm1->unk_10 = NEXTSETTING;
norm1->unk_14 = NEXTPCT;
norm1->fovTarget = NEXTSETTING;
norm1->atLERPScaleMax = NEXTPCT;
norm1->interfaceFlags = NEXTSETTING;
}

if (R_RELOAD_CAM_PARAMS) {
Camera_CopyPREGToModeValues(camera);
}

VecSph eyeAdjustment;

camera->animState = 1;

camera->at.x = camera->player->actor.world.pos.x;
camera->at.y = camera->player->actor.world.pos.y + Player_GetHeight(camera->player);
camera->at.z = camera->player->actor.world.pos.z;

OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, &camera->at, &camera->eye);
OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, &camera->at, &camera->eyeNext);

camera->dist = eyeAdjustment.r = 250.0f;

eyeAdjustment.yaw = 0;
eyeAdjustment.pitch = 9000;

Camera_Vec3fVecSphGeoAdd(&camera->eye, &camera->at, &eyeAdjustment);
Camera_Vec3fVecSphGeoAdd(&camera->eyeNext, &camera->at, &eyeAdjustment);

return 1;
}

s32 Camera_Normal1(Camera* camera) {
Vec3f* eye = &camera->eye;
Vec3f* at = &camera->at;
Expand Down Expand Up @@ -1559,16 +1619,18 @@ s32 Camera_Normal1(Camera* camera) {

if (anim->startSwingTimer <= 0) {
eyeAdjustment.pitch = atEyeNextGeo.pitch;
eyeAdjustment.yaw =
eyeAdjustment.yaw = CVar_GetS32("gBlindMode", 0) != 0 ? atEyeNextGeo.yaw
:
Camera_LERPCeilS(anim->swingYawTarget, atEyeNextGeo.yaw, 1.0f / camera->yawUpdateRateInv, 0xA);
} else if (anim->swing.unk_18 != 0) {
eyeAdjustment.yaw =
eyeAdjustment.yaw = CVar_GetS32("gBlindMode", 0) != 0 ? atEyeNextGeo.yaw
:
Camera_LERPCeilS(anim->swing.unk_16, atEyeNextGeo.yaw, 1.0f / camera->yawUpdateRateInv, 0xA);
eyeAdjustment.pitch =
Camera_LERPCeilS(anim->swing.unk_14, atEyeNextGeo.pitch, 1.0f / camera->yawUpdateRateInv, 0xA);
} else {
// rotate yaw to follow player.
eyeAdjustment.yaw =
eyeAdjustment.yaw =
Camera_CalcDefaultYaw(camera, atEyeNextGeo.yaw, camera->playerPosRot.rot.y, norm1->unk_14, sp94);
eyeAdjustment.pitch =
Camera_CalcDefaultPitch(camera, atEyeNextGeo.pitch, norm1->pitchTarget, anim->slopePitchAdj);
Expand Down
36 changes: 19 additions & 17 deletions soh/src/code/z_collision_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,23 +1702,25 @@ s32 CollisionCheck_SetATvsAC(GlobalContext* globalCtx, Collider* at, ColliderInf
at->actor->colChkInfo.atHitEffect = acInfo->bumper.effect;
}
}
ac->acFlags |= AC_HIT;
ac->ac = at->actor;
acInfo->acHit = at;
acInfo->acHitInfo = atInfo;
acInfo->bumperFlags |= BUMP_HIT;
if (ac->actor != NULL) {
ac->actor->colChkInfo.acHitEffect = atInfo->toucher.effect;
}
acInfo->bumper.hitPos.x = hitPos->x;
acInfo->bumper.hitPos.y = hitPos->y;
acInfo->bumper.hitPos.z = hitPos->z;
if (!(atInfo->toucherFlags & TOUCH_AT_HITMARK) && ac->colType != COLTYPE_METAL && ac->colType != COLTYPE_WOOD &&
ac->colType != COLTYPE_HARD) {
acInfo->bumperFlags |= BUMP_DRAW_HITMARK;
} else {
CollisionCheck_HitEffects(globalCtx, at, atInfo, ac, acInfo, hitPos);
atInfo->toucherFlags |= TOUCH_DREW_HITMARK;
if (atInfo->elemType != ELEMTYPE_SENSING) {
ac->acFlags |= AC_HIT;
ac->ac = at->actor;
acInfo->acHit = at;
acInfo->acHitInfo = atInfo;
acInfo->bumperFlags |= BUMP_HIT;
if (ac->actor != NULL) {
ac->actor->colChkInfo.acHitEffect = atInfo->toucher.effect;
}
acInfo->bumper.hitPos.x = hitPos->x;
acInfo->bumper.hitPos.y = hitPos->y;
acInfo->bumper.hitPos.z = hitPos->z;
if (!(atInfo->toucherFlags & TOUCH_AT_HITMARK) && ac->colType != COLTYPE_METAL && ac->colType != COLTYPE_WOOD &&
ac->colType != COLTYPE_HARD) {
acInfo->bumperFlags |= BUMP_DRAW_HITMARK;
} else {
CollisionCheck_HitEffects(globalCtx, at, atInfo, ac, acInfo, hitPos);
atInfo->toucherFlags |= TOUCH_DREW_HITMARK;
}
}
return 1;
}
Expand Down
111 changes: 111 additions & 0 deletions soh/src/code/z_message_PAL.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ s16 sOcarinaNoteCEnvR;
s16 sOcarinaNoteCEnvB;
s16 sOcarinaNoteCEnvG;

static u8 sTtsHasNewMessage;
static u8 sTtsHasMessage;
static s8 sTtsCurrentChoice;
static u8 sTtsMessageBuf[256];

void Message_ResetOcarinaNoteState(void) {
R_OCARINA_NOTES_YPOS(0) = 189;
R_OCARINA_NOTES_YPOS(1) = 184;
Expand Down Expand Up @@ -3004,6 +3009,108 @@ void Message_Draw(GlobalContext* globalCtx) {
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_message_PAL.c", 3582);
}

void Message_TTS_Decode(u8* srcBuf, u8* dstBuf, u32 srcOffset, u32 size) {
u32 dstIdx = 0;

for (u32 i = 0; i < size; i++) {
u8 currChar = srcBuf[i + srcOffset];

if (currChar < ' ') {
switch (currChar) {
case MESSAGE_NEWLINE:
dstBuf[dstIdx++] = ' ';
break;
case MESSAGE_COLOR:
case MESSAGE_SHIFT:
case MESSAGE_TEXT_SPEED:
case MESSAGE_BOX_BREAK_DELAYED:
case MESSAGE_FADE:
case MESSAGE_ITEM_ICON:
i++;
break;
case MESSAGE_FADE2:
case MESSAGE_SFX:
case MESSAGE_TEXTID:
i += 2;
break;
default:
break;
}
} else {
dstBuf[dstIdx++] = currChar;
}
}

dstBuf[dstIdx] = 0;
}

void Message_TTS_Update(GlobalContext* globalCtx) {
MessageContext* msgCtx = &globalCtx->msgCtx;

if (msgCtx->msgMode == MSGMODE_TEXT_NEXT_MSG || msgCtx->msgMode == MSGMODE_DISPLAY_SONG_PLAYED_TEXT_BEGIN ||
(msgCtx->msgMode == MSGMODE_TEXT_CONTINUING && msgCtx->stateTimer == 1)) {
sTtsHasNewMessage = 1;
} else if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING || msgCtx->msgMode == MSGMODE_OCARINA_STARTING ||
msgCtx->msgMode == MSGMODE_OCARINA_PLAYING || msgCtx->msgMode == MSGMODE_TEXT_AWAIT_NEXT ||
msgCtx->msgMode == MSGMODE_TEXT_DONE || msgCtx->msgMode == MSGMODE_DISPLAY_SONG_PLAYED_TEXT ||
msgCtx->msgMode == MSGMODE_TEXT_DELAYED_BREAK) {
if (sTtsHasNewMessage == 1) {
sTtsHasNewMessage = 0;
sTtsHasMessage = 1;
sTtsCurrentChoice = 0;

u32 size = msgCtx->decodedTextLen;
Message_TTS_Decode(msgCtx->msgBufDecoded, sTtsMessageBuf, 0, size);
OTRTextToSpeechCallback(sTtsMessageBuf);
} else if (msgCtx->msgMode == MSGMODE_TEXT_DONE && msgCtx->choiceNum > 0 &&
msgCtx->choiceIndex != sTtsCurrentChoice) {
sTtsCurrentChoice = msgCtx->choiceIndex;
u32 startOffset = 0;
u32 endOffset = 0;
while (startOffset < msgCtx->decodedTextLen) {
if (msgCtx->msgBufDecoded[startOffset] == MESSAGE_TWO_CHOICE ||
msgCtx->msgBufDecoded[startOffset] == MESSAGE_THREE_CHOICE) {
startOffset++;
break;
}
startOffset++;
}
if (startOffset < msgCtx->decodedTextLen) {
u8 i = msgCtx->choiceIndex;
while (i-- > 0) {
while (startOffset < msgCtx->decodedTextLen) {
if (msgCtx->msgBufDecoded[startOffset] == MESSAGE_NEWLINE) {
startOffset++;
break;
}
startOffset++;
}
}
endOffset = startOffset;
while (endOffset < msgCtx->decodedTextLen) {
if (msgCtx->msgBufDecoded[endOffset] == MESSAGE_NEWLINE) {
break;
}
endOffset++;
}

if (startOffset < msgCtx->decodedTextLen && startOffset != endOffset) {
u32 size = endOffset - startOffset;
Message_TTS_Decode(msgCtx->msgBufDecoded, sTtsMessageBuf, startOffset, size);
OTRTextToSpeechCallback(sTtsMessageBuf);
}
}
}
} else if (sTtsHasMessage == 1) {
sTtsHasMessage = 0;
sTtsHasNewMessage = 0;
if (msgCtx->decodedTextLen < 3 || (msgCtx->msgBufDecoded[msgCtx->decodedTextLen - 2] != MESSAGE_FADE &&
msgCtx->msgBufDecoded[msgCtx->decodedTextLen - 3] != MESSAGE_FADE2)) {
OTRTextToSpeechCallback(""); // cancel current speech (except for faded out messages)
}
}
}

void Message_Update(GlobalContext* globalCtx) {
static s16 sTextboxXPositions[] = {
34, 34, 34, 34, 34, 34,
Expand Down Expand Up @@ -3067,6 +3174,10 @@ void Message_Update(GlobalContext* globalCtx) {
return;
}

if (CVar_GetS32("gMessageTTS", 0) != 0) {
Message_TTS_Update(globalCtx);
}

bool isB_Held = CVar_GetS32("gFastText", 0) != 0 ? CHECK_BTN_ALL(input->cur.button, BTN_B) && !sTextboxSkipped
: CHECK_BTN_ALL(input->press.button, BTN_B);

Expand Down
Loading

0 comments on commit 7090a5b

Please sign in to comment.