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
4 changes: 3 additions & 1 deletion src/port/Rando/Logic/GlitchlessLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ void PopulateJinjoCheckIds() {
}

void ResetSaveData() {
for (int s = 0; s < sizeof(SaveData); s++) {
// [port] `data` is the 112-byte vanilla payload, not the whole SaveData, which is
// ~43 KB once shipSaveData (rando checks, note/jinjo retention) is counted.
for (size_t s = 0; s < sizeof(gameFile_saveData[selectedFileNum].data); s++) {
gameFile_saveData[selectedFileNum].data[s] = 0;
}

Expand Down
3 changes: 3 additions & 0 deletions src/port/Save/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ static constexpr int kSnsItemCount = sizeof(kSnsUnlocked) / sizeof(kSnsUnlocked[
// so internal gamenum 0/1/2 corresponds to displayed Game 1/3/2.
static int SlotToFileIndex(int gameNum) {
static const int fileMap[3] = { 1, 3, 2 };
if (gameNum < 0 || gameNum >= 3) {
return 0;
}
return fileMap[gameNum];
}

Expand Down
26 changes: 21 additions & 5 deletions src/port/UI/Notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
#include "port/UI/cvar_prefixes.h"
#include <libultraship/libultraship.h>
#include <fast/Fast3dGui.h>
#include <mutex>
#include <vector>

namespace Notification {

static uint32_t nextId = 0;
static std::vector<Options> notifications = {};
// Emit() runs on the game thread; Draw()/UpdateElement() run on the render thread.
static std::mutex notificationsMutex;

#define ABS(x) ((x) >= 0 ? (x) : -(x))

Expand Down Expand Up @@ -46,9 +50,17 @@ void Window::Draw() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
ImVec2(8.0f * CVarGetFloat(CVAR_SETTING("Notifications.Size"), 1.8f), 8.0f));

for (size_t index = 0; index < notifications.size(); ++index) {
auto& notification = notifications[index];
int inverseIndex = -ABS((int)index - (int)(notifications.size() - 1));
// Render from a snapshot rather than the live vector, so a concurrent Emit() can
// reallocate without invalidating anything this loop is reading.
std::vector<Options> snapshot;
{
std::lock_guard<std::mutex> lock(notificationsMutex);
snapshot = notifications;
}

for (size_t index = 0; index < snapshot.size(); ++index) {
auto& notification = snapshot[index];
int inverseIndex = -ABS((int)index - (int)(snapshot.size() - 1));

ImGui::SetNextWindowViewport(vp->ID);
if (notification.remainingTime < 4.0f) {
Expand Down Expand Up @@ -114,6 +126,7 @@ void Window::Draw() {
}

void Window::UpdateElement() {
std::lock_guard<std::mutex> lock(notificationsMutex);
for (int index = 0; index < notifications.size(); ++index) {
auto& notification = notifications[index];

Expand All @@ -129,11 +142,14 @@ void Window::UpdateElement() {
}

void Emit(Options notification) {
notification.id = nextId++;
if (notification.remainingTime == 0.0f) {
notification.remainingTime = CVarGetFloat(CVAR_SETTING("Notifications.Duration"), 10.0f);
}
notifications.push_back(notification);
{
std::lock_guard<std::mutex> lock(notificationsMutex);
notification.id = nextId++;
notifications.push_back(notification);
}
if (!notification.mute) {
// TODO: play game notification sound
}
Expand Down
Loading