Skip to content

Commit

Permalink
Merge pull request #18487 from hrydgard/misc-cleanup
Browse files Browse the repository at this point in the history
Misc code cleanup
  • Loading branch information
hrydgard authored Dec 7, 2023
2 parents 378b3a1 + dde13b4 commit 89c320f
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 38 deletions.
3 changes: 2 additions & 1 deletion Common/Data/Collections/FastVec.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class FastVec {
void clear() { size_ = 0; }
bool empty() const { return size_ == 0; }

const T *data() { return data_; }
const T *data() const { return data_; }

T *begin() { return data_; }
T *end() { return data_ + size_; }
const T *begin() const { return data_; }
Expand Down
23 changes: 15 additions & 8 deletions Common/Data/Collections/TinySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <vector>

#include "Common/Log.h"

// Insert-only small-set implementation. Performs no allocation unless MaxFastSize is exceeded.
// Can also be used as a small vector, then use push_back (or push_in_place) instead of insert.
// Duplicates are thus allowed if you use that, but not if you exclusively use insert.
Expand Down Expand Up @@ -32,16 +34,18 @@ struct TinySet {
}
slowLookup_->push_back(t);
}
inline T *add_back() {
inline T &push_uninitialized() {
if (fastCount_ < MaxFastSize) {
return &fastLookup_[fastCount_++];
return fastLookup_[fastCount_++];
}
if (!slowLookup_) {
slowLookup_ = new std::vector<T>();
}

// The slow lookup is also slow at adding.
T t;
slowLookup_->push_back(t);
return slowLookup_->back();
return *slowLookup_->back();
}
void append(const TinySet<T, MaxFastSize> &other) {
size_t otherSize = other.size();
Expand Down Expand Up @@ -136,8 +140,8 @@ struct TinySet {
};

template <class T, int MaxSize>
struct FixedTinyVec {
~FixedTinyVec() {}
struct FixedVec {
~FixedVec() {}
// WARNING: Can fail if you exceed MaxSize!
inline bool push_back(const T &t) {
if (count_ < MaxSize) {
Expand All @@ -147,13 +151,16 @@ struct FixedTinyVec {
return false;
}
}

// WARNING: Can fail if you exceed MaxSize!
inline T *add_back() {
inline T &push_uninitialized() {
if (count_ < MaxSize) {
return &data_[count_++];
}
return nullptr;
_dbg_assert_(false);
return *data_[MaxSize - 1]; // BAD
}

// Invalid if empty().
void pop_back() { count_--; }

Expand Down Expand Up @@ -184,7 +191,7 @@ struct FixedTinyVec {
const T &back() const { return (*this)[size() - 1]; }
const T &front() const { return (*this)[0]; }

bool operator == (const FixedTinyVec<T, MaxSize> &other) const {
bool operator == (const FixedVec<T, MaxSize> &other) const {
if (count_ != other.count_)
return false;
for (int i = 0; i < count_; i++) {
Expand Down
11 changes: 6 additions & 5 deletions Common/GPU/Vulkan/VulkanBarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Common/Log.h"
#include "Common/GPU/Vulkan/VulkanLoader.h"
#include "Common/Data/Collections/FastVec.h"

class VulkanContext;

Expand All @@ -13,6 +14,8 @@ class VulkanContext;
// However, not thread safe in any way!
class VulkanBarrier {
public:
VulkanBarrier() : imageBarriers_(4) {}

void TransitionImage(
VkImage image, int baseMip, int numMipLevels, int numLayers, VkImageAspectFlags aspectMask,
VkImageLayout oldImageLayout, VkImageLayout newImageLayout,
Expand All @@ -25,7 +28,7 @@ class VulkanBarrier {
dstStageMask_ |= dstStageMask;
dependencyFlags_ |= VK_DEPENDENCY_BY_REGION_BIT;

VkImageMemoryBarrier imageBarrier;
VkImageMemoryBarrier &imageBarrier = imageBarriers_.push_uninitialized();
imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imageBarrier.pNext = nullptr;
imageBarrier.srcAccessMask = srcAccessMask;
Expand All @@ -40,7 +43,6 @@ class VulkanBarrier {
imageBarrier.subresourceRange.baseArrayLayer = 0;
imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarriers_.push_back(imageBarrier);
}

// Automatically determines access and stage masks from layouts.
Expand Down Expand Up @@ -93,7 +95,7 @@ class VulkanBarrier {
break;
}

VkImageMemoryBarrier imageBarrier;
VkImageMemoryBarrier &imageBarrier = imageBarriers_.push_uninitialized();
imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imageBarrier.pNext = nullptr;
imageBarrier.srcAccessMask = srcAccessMask;
Expand All @@ -108,14 +110,13 @@ class VulkanBarrier {
imageBarrier.subresourceRange.baseArrayLayer = 0;
imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarriers_.push_back(imageBarrier);
}

void Flush(VkCommandBuffer cmd);

private:
VkPipelineStageFlags srcStageMask_ = 0;
VkPipelineStageFlags dstStageMask_ = 0;
std::vector<VkImageMemoryBarrier> imageBarriers_;
FastVec<VkImageMemoryBarrier> imageBarriers_;
VkDependencyFlags dependencyFlags_ = 0;
};
2 changes: 2 additions & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ enum SystemProperty {
SYSPROP_SKIP_UI,

SYSPROP_USER_DOCUMENTS_DIR,

SYSPROP_OK_BUTTON_LEFT,
};

enum class SystemNotification {
Expand Down
29 changes: 14 additions & 15 deletions Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <algorithm>

#include "Common/Log.h"
#include "Common/System/Display.h"
#include "Common/System/System.h"
#include "Common/System/Request.h"
#include "Common/Input/InputState.h"
#include "Common/Input/KeyCodes.h"
#include "Common/Math/curves.h"
Expand All @@ -10,8 +13,6 @@
#include "Common/UI/Root.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Render/DrawBuffer.h"
#include "Common/Log.h"
#include <Common/System/Request.h>

static const bool ClickDebug = false;

Expand Down Expand Up @@ -393,10 +394,8 @@ void PopupScreen::TriggerFinish(DialogResult result) {

OnCompleted(result);
}
#if PPSSPP_PLATFORM(UWP)
// Inform UI that popup close to hide OSK (if visible)
System_NotifyUIState("popup_closed");
#endif
}

void PopupScreen::CreateViews() {
Expand Down Expand Up @@ -433,17 +432,17 @@ void PopupScreen::CreateViews() {
Margins buttonMargins(5, 5);

// Adjust button order to the platform default.
#if defined(_WIN32)
defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f, buttonMargins)));
defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
if (!button2_.empty())
buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f, buttonMargins)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel);
#else
if (!button2_.empty())
buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel);
defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)));
defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
#endif
if (System_GetPropertyBool(SYSPROP_OK_BUTTON_LEFT)) {
defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f, buttonMargins)));
defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
if (!button2_.empty())
buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f, buttonMargins)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel);
} else {
if (!button2_.empty())
buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel);
defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)));
defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
}

box_->Add(buttonRow);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static bool DefaultVSync() {
}

static bool DefaultEnableStateUndo() {
#ifdef MOBILE_DEVICE
#ifdef PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
// Off on mobile to save disk space.
return false;
#endif
Expand Down
4 changes: 0 additions & 4 deletions Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,10 +1405,6 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load

if (!module->isFake) {
bool scan = true;
#if defined(MOBILE_DEVICE)
scan = g_Config.bFuncReplacements;
#endif

// If the ELF has debug symbols, don't add entries to the symbol table.
bool insertSymbols = scan && !reader.LoadSymbols();
std::vector<SectionID> codeSections = reader.GetCodeSections();
Expand Down
2 changes: 1 addition & 1 deletion Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_SPEED_CUSTOM2, "Alt speed 2"},
{VIRTKEY_SPEED_ANALOG, "Analog speed"},
{VIRTKEY_PAUSE, "Pause"},
#ifndef MOBILE_DEVICE
{VIRTKEY_FRAME_ADVANCE, "Frame Advance"},
#if !defined(MOBILE_DEVICE)
{VIRTKEY_RECORD, "Audio/Video Recording" },
#endif
{VIRTKEY_REWIND, "Rewind"},
Expand Down
2 changes: 1 addition & 1 deletion Core/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace KeyMap {
return false;
}

FixedTinyVec<InputMapping, 3> mappings;
FixedVec<InputMapping, 3> mappings;
};

typedef std::map<int, std::vector<MultiInputMapping>> KeyMapping;
Expand Down
2 changes: 0 additions & 2 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,9 @@ void PSP_Shutdown() {
if (coreState == CORE_RUNNING)
Core_Stop();

#ifndef MOBILE_DEVICE
if (g_Config.bFuncHashMap) {
MIPSAnalyst::StoreHashMap();
}
#endif

if (pspIsIniting)
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
Expand Down
2 changes: 2 additions & 0 deletions UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
}
case SYSPROP_DEBUGGER_PRESENT:
return IsDebuggerPresent();
case SYSPROP_OK_BUTTON_LEFT:
return true;
default:
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
return !g_Config.bDisableHTTPS;
case SYSPROP_DEBUGGER_PRESENT:
return IsDebuggerPresent();
case SYSPROP_OK_BUTTON_LEFT:
return true;
default:
return false;
}
Expand Down

0 comments on commit 89c320f

Please sign in to comment.