Merge pull request #20773 from hrydgard/more-assorted-code-cleanup

Fix ini loading problem, a lot of cleanups
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2025-08-31 15:49:22 +02:00
commit 023b83c6c3
31 files changed
+204 -152

No files matched your search

+3 -3
View File
@@ -291,7 +291,7 @@ void CPUInfo::Detect()
}
}
#elif PPSSPP_PLATFORM(WINDOWS)
truncate_cpy(brand_string, GetCPUBrandString().c_str());
truncate_cpy(brand_string, GetCPUBrandString());
isVFP3 = true;
isVFP4 = false;
SYSTEM_INFO sysInfo;
@@ -319,8 +319,8 @@ void CPUInfo::Detect()
bFP = false;
bASIMD = false;
#else // PPSSPP_PLATFORM(LINUX)
truncate_cpy(cpu_string, GetCPUString().c_str());
truncate_cpy(brand_string, GetCPUBrandString().c_str());
truncate_cpy(cpu_string, GetCPUString());
truncate_cpy(brand_string, GetCPUBrandString());
bSwp = CheckCPUFeature("swp");
bHalf = CheckCPUFeature("half");
+14 -36
View File
@@ -300,23 +300,19 @@ void Section::Set(std::string_view key, bool newValue, bool defaultValue)
Delete(key);
}
void Section::Set(std::string_view key, const std::vector<std::string>& newValues)
{
void Section::Set(std::string_view key, const std::vector<std::string> &newValues) {
std::string temp;
// Join the strings with ,
for (const auto &value : newValues) {
temp += value + ",";
temp += value;
temp.push_back(',');
}
// remove last ,
if (temp.length())
temp.resize(temp.length() - 1);
if (!temp.empty())
temp.pop_back();
Set(key, temp.c_str());
}
void Section::AddComment(const std::string &comment) {
lines_.emplace_back(ParsedIniLine::CommentOnly("# " + comment));
}
bool Section::Get(std::string_view key, std::vector<std::string> *values, const std::vector<std::string> *defaultValues) const {
std::string temp;
bool retval = Get(key, &temp, 0);
@@ -326,23 +322,8 @@ bool Section::Get(std::string_view key, std::vector<std::string> *values, const
}
return false;
}
// ignore starting , if any
size_t subStart = temp.find_first_not_of(',');
size_t subEnd;
// split by ,
while (subStart != std::string::npos) {
// Find next ,
subEnd = temp.find_first_of(',', subStart);
if (subStart != subEnd) {
// take from first char until next ,
values->push_back(StripSpaces(temp.substr(subStart, subEnd - subStart)));
}
// Find the next non , char
subStart = temp.find_first_not_of(',', subEnd);
}
SplitString(temp, ',', *values, true);
return true;
}
@@ -408,6 +389,10 @@ bool Section::Exists(std::string_view key) const {
return false;
}
void Section::AddComment(const std::string &comment) {
lines_.emplace_back(ParsedIniLine::CommentOnly("# " + comment));
}
std::map<std::string, std::string> Section::ToMap() const {
std::map<std::string, std::string> outMap;
for (auto &line : lines_) {
@@ -502,8 +487,7 @@ void IniFile::SortSections()
std::sort(sections.begin(), sections.end());
}
bool IniFile::Load(const Path &path)
{
bool IniFile::Load(const Path &path) {
sections.clear();
sections.push_back(std::make_unique<Section>(""));
// first section consists of the comments before the first real section
@@ -531,15 +515,10 @@ bool IniFile::LoadFromVFS(VFSInterface &vfs, const std::string &filename) {
}
bool IniFile::Load(std::istream &in) {
// Maximum number of letters in a line
static const int MAX_BYTES = 1024*32;
char *templine = new char[MAX_BYTES]; // avoid using up massive stack space
while (!(in.eof() || in.fail()))
{
in.getline(templine, MAX_BYTES);
std::string_view line = templine;
std::string linebuf;
while (std::getline(in, linebuf)) {
std::string_view line = StripSpaces(std::string_view(linebuf));
// Remove UTF-8 byte order marks.
if (line.substr(0, 3) == "\xEF\xBB\xBF") {
line = line.substr(3);
@@ -575,7 +554,6 @@ bool IniFile::Load(std::istream &in) {
}
}
delete[] templine;
return true;
}
+1 -1
View File
@@ -162,7 +162,7 @@ bool CheckGLExtensions() {
const char *cvendor = (char *)glGetString(GL_VENDOR);
// TODO: move this stuff to gpu_features.cpp
if (cvendor) {
const std::string vendor = StripSpaces(std::string(cvendor));
const std::string vendor(StripSpaces(cvendor));
if (vendor == "NVIDIA Corporation"
|| vendor == "Nouveau"
|| vendor == "nouveau") {
+1 -1
View File
@@ -833,7 +833,7 @@ void VulkanRenderManager::ReportBadStateForDraw() {
if (curRenderStep_ && curRenderStep_->stepType != VKRStepType::RENDER) {
cause1 = "Not a render step: ";
std::string str = VulkanQueueRunner::StepToString(vulkan_, *curRenderStep_);
truncate_cpy(cause2, str.c_str());
truncate_cpy(cause2, str);
}
ERROR_LOG_REPORT_ONCE(baddraw, Log::G3D, "Can't draw: %s%s. Step count: %d", cause1, cause2, (int)steps_.size());
}
+5 -3
View File
@@ -226,8 +226,10 @@ Client::~Client() {
// Ignores line folding (deprecated), but respects field combining.
// Don't use for Set-Cookie, which is a special header per RFC 7230.
bool GetHeaderValue(const std::vector<std::string> &responseHeaders, const std::string &header, std::string *value) {
std::string search = header + ":";
bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string_view header, std::string *value) {
std::string search(header);
search.push_back(':');
bool found = false;
value->clear();
@@ -242,7 +244,7 @@ bool GetHeaderValue(const std::vector<std::string> &responseHeaders, const std::
if (!found)
*value = stripped.substr(value_pos);
else
*value += "," + stripped.substr(value_pos);
*value += "," + std::string(stripped.substr(value_pos));
found = true;
}
}
+1 -1
View File
@@ -47,7 +47,7 @@ private:
namespace http {
bool GetHeaderValue(const std::vector<std::string> &responseHeaders, const std::string &header, std::string *value);
bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string_view header, std::string *value);
class RequestParams {
public:
+1 -1
View File
@@ -194,7 +194,7 @@ void CPUInfo::Detect()
if (logical_cpu_count <= 0)
logical_cpu_count = 1;
truncate_cpy(cpu_string, parser.ISAString().c_str());
truncate_cpy(cpu_string, parser.ISAString());
// A number of CPUs support a limited set of bitmanip. It's not all U74, so we use SOC for now...
if (parser.FirmwareMatchesCompatible("starfive,jh7110")) {
+27 -62
View File
@@ -16,7 +16,7 @@
// http://code.google.com/p/dolphin-emu/
#include <cstring>
#include <unordered_set>
#include "ppsspp_config.h"
#ifdef _WIN32
@@ -64,10 +64,6 @@ size_t truncate_cpy(char *dest, size_t destSize, std::string_view src) {
}
}
const char* safe_string(const char* s) {
return s ? s : "(null)";
}
long parseHexLong(const std::string &s) {
long value = 0;
@@ -187,38 +183,6 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
}
}
bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension)
{
if (full_path.empty())
return false;
size_t dir_end = full_path.find_last_of("/"
// windows needs the : included for something like just "C:" to be considered a directory
#ifdef _WIN32
":"
#endif
);
if (std::string::npos == dir_end)
dir_end = 0;
else
dir_end += 1;
size_t fname_end = full_path.rfind('.');
if (fname_end < dir_end || std::string::npos == fname_end)
fname_end = full_path.size();
if (_pPath)
*_pPath = full_path.substr(0, dir_end);
if (_pFilename)
*_pFilename = full_path.substr(dir_end, fname_end - dir_end);
if (_pExtension)
*_pExtension = full_path.substr(fname_end);
return true;
}
std::string LineNumberString(const std::string &str) {
std::stringstream input(str);
std::stringstream output;
@@ -291,7 +255,7 @@ void DataToHexString(const uint8_t *data, size_t size, std::string *output, bool
buffer.TakeAll(output);
}
void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output) {
void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string *output) {
Buffer buffer;
size_t i = 0;
for (; i < size; i++) {
@@ -321,8 +285,7 @@ void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t
buffer.TakeAll(output);
}
std::string StringFromFormat(const char* format, ...)
{
std::string StringFromFormat(const char* format, ...) {
va_list args;
std::string temp;
#ifdef _WIN32
@@ -361,27 +324,7 @@ std::string StringFromInt(int value) {
return temp;
}
// Turns " hej " into "hej". Also handles tabs.
std::string StripSpaces(const std::string &str) {
const size_t s = str.find_first_not_of(" \t\r\n");
if (std::string::npos != s)
return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1);
else
return "";
}
// "\"hello\"" is turned to "hello"
// This one assumes that the string has already been space stripped in both
// ends, as done by StripSpaces above, for example.
std::string StripQuotes(const std::string& s)
{
if (s.size() && '\"' == s[0] && '\"' == *s.rbegin())
return s.substr(1, s.size() - 2);
else
return s;
}
// Turns " hej " into "hej". Also handles tabs.
// Turns " hej " into "hej". Also handles tabs and line breaks.
std::string_view StripSpaces(std::string_view str) {
const size_t s = str.find_first_not_of(" \t\r\n");
if (std::string::npos != s)
@@ -418,7 +361,7 @@ void SplitString(std::string_view str, const char delim, std::vector<std::string
}
}
void SplitString(std::string_view str, const char delim, std::vector<std::string> &output) {
void SplitString(std::string_view str, const char delim, std::vector<std::string> &output, bool trimOutput) {
size_t next = 0;
size_t pos = 0;
while (pos < str.length()) {
@@ -427,6 +370,9 @@ void SplitString(std::string_view str, const char delim, std::vector<std::string
break;
}
output.emplace_back(str.substr(next, delimPos - next));
if (trimOutput) {
output.back() = StripSpaces(output.back());
}
next = delimPos + 1;
pos = delimPos + 1;
}
@@ -435,6 +381,11 @@ void SplitString(std::string_view str, const char delim, std::vector<std::string
output.emplace_back(str);
} else if (next < str.length()) {
output.emplace_back(str.substr(next));
} else {
return;
}
if (trimOutput) {
output.back() = StripSpaces(output.back());
}
}
@@ -582,3 +533,17 @@ std::string ApplySafeSubstitutions(std::string_view format, int i1, int i2, int
}
return output;
}
void MakeUnique(std::vector<std::string> &v) {
std::unordered_set<std::string> seen;
std::vector<std::string> result;
result.reserve(v.size()); // minimize reallocations
for (const auto &s : v) {
if (seen.insert(s).second) {
// insert returns {iterator, bool}
// bool == true if it was newly inserted (didn't already exist)
result.push_back(s);
}
}
v.swap(result);
}
+6 -8
View File
@@ -90,14 +90,11 @@ enum class StringRestriction {
std::string SanitizeString(std::string_view username, StringRestriction restriction, int minLength = 0, int maxLength = -1);
void DataToHexString(const uint8_t *data, size_t size, std::string *output, bool lineBreaks = true);
void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output);
void DataToHexString(int indent, uint32_t startAddr, const uint8_t* data, size_t size, std::string *output);
std::string StringFromFormat(const char* format, ...);
std::string StringFromInt(int value);
std::string StripSpaces(const std::string &s);
std::string StripQuotes(const std::string &s);
std::string_view KeepAfterLast(std::string_view s, char c);
std::string_view KeepIncludingLast(std::string_view s, char c);
@@ -111,7 +108,7 @@ int CountChar(std::string_view haystack, char needle);
// NOTE: str must live at least as long as all uses of output.
void SplitString(std::string_view str, const char delim, std::vector<std::string_view> &output);
// Try to avoid this when possible, in favor of the string_view version.
void SplitString(std::string_view str, const char delim, std::vector<std::string> &output);
void SplitString(std::string_view str, const char delim, std::vector<std::string> &output, bool trimOutput = false);
void GetQuotedStrings(std::string_view str, std::vector<std::string> &output);
@@ -134,7 +131,9 @@ inline size_t truncate_cpy(char(&out)[Count], std::string_view src) {
return truncate_cpy(out, Count, src);
}
const char* safe_string(const char* s);
inline const char *safe_string(const char *s) {
return s ? s : "(null)";
}
long parseHexLong(const std::string &s);
long parseLong(std::string s);
@@ -150,8 +149,7 @@ inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...)
va_end(args);
}
// "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe"
bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension);
void MakeUnique(std::vector<std::string> &vec);
// Replaces %1, %2, %3 in format with arg1, arg2, arg3.
// Much safer than snprintf and friends.
+1 -1
View File
@@ -311,7 +311,7 @@ bool System_AudioRecordingIsAvailable();
bool System_AudioRecordingState();
// This will be changed to take an enum. Replacement for the old NativeMessageReceived.
void System_PostUIMessage(UIMessage message, const std::string &param = "");
void System_PostUIMessage(UIMessage message, std::string_view param = "");
// For these functions, most platforms will use the implementation provided in UI/AudioCommon.cpp,
// no need to implement separately.
+3 -1
View File
@@ -548,7 +548,9 @@ int Config::NextValidBackend() {
#endif
// They've all failed. Let them try the default - or on Android, OpenGL.
sFailedGPUBackends += ",ALL";
if (sFailedGPUBackends.find(",ALL") == std::string::npos) {
sFailedGPUBackends += ",ALL";
}
ERROR_LOG(Log::Loader, "All graphics backends failed");
#if PPSSPP_PLATFORM(ANDROID)
return (int)GPUBackend::OPENGL;
+8 -1
View File
@@ -1,6 +1,7 @@
#include "Common/Data/Format/IniFile.h"
#include "Common/Net/URL.h"
#include "Common/Log.h"
#include "Common/StringUtils.h"
#include "Core/ConfigSettings.h"
#include "Core/ConfigValues.h"
@@ -38,8 +39,14 @@ bool ConfigSetting::Get(const Section *section) const {
case TYPE_STRING:
return section->Get(iniKey_, ptr_.s, cb_.s ? cb_.s().c_str() : default_.s);
case TYPE_STRING_VECTOR:
{
// No support for callbacks for these yet. that's not an issue.
return section->Get(iniKey_, ptr_.v, default_.v);
bool success = section->Get(iniKey_, ptr_.v, default_.v);
if (success) {
MakeUnique(*ptr_.v);
}
return success;
}
case TYPE_TOUCH_POS:
{
ConfigTouchPos defaultTouchPos = cb_.touchPos ? cb_.touchPos() : default_.touchPos;
+1 -1
View File
@@ -268,7 +268,7 @@ void MemSlabMap::Slab::DoState(PointerWrap &p) {
} else {
std::string stringTag;
Do(p, stringTag);
truncate_cpy(tag, stringTag.c_str());
truncate_cpy(tag, stringTag);
}
}
+1 -1
View File
@@ -1442,7 +1442,7 @@ bool SavedataParam::GetSize(SceUtilitySavedataParam *param) {
// TODO: Is this after the specified files? Probably before?
param->sizeInfo->freeKB = (int)(freeBytes / 1024);
std::string spaceTxt = SavedataParam::GetSpaceText(freeBytes, false);
truncate_cpy(param->sizeInfo->freeString, spaceTxt.c_str());
truncate_cpy(param->sizeInfo->freeString, spaceTxt);
if (writeBytes - overwriteBytes < (s64)freeBytes) {
param->sizeInfo->neededKB = 0;
+1 -1
View File
@@ -521,7 +521,7 @@ void InitLocalhostIP() {
g_localhostIP.in.sin_addr.s_addr = htonl(localIP);
g_localhostIP.in.sin_port = 0;
std::string serverStr = StripSpaces(g_Config.proAdhocServer);
std::string serverStr(StripSpaces(g_Config.proAdhocServer));
isLocalServer = (!strcasecmp(serverStr.c_str(), "localhost") || serverStr.find("127.") == 0);
}
+2 -2
View File
@@ -190,7 +190,7 @@ static bool Arm64SymbolCallback(char *buffer, int bufsize, uint8_t *address) {
if (MIPSComp::jit) {
std::string name;
if (MIPSComp::jit->DescribeCodePtr(address, name)) {
truncate_cpy(buffer, bufsize, name.c_str());
truncate_cpy(buffer, bufsize, name);
return true;
}
}
@@ -283,7 +283,7 @@ const char *ppsspp_resolver(struct ud*,
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (MIPSComp::jit && MIPSComp::jit->DescribeCodePtr((u8 *)(uintptr_t)addr, str)) {
*offset = 0;
truncate_cpy(buf, sizeof(buf), str.c_str());
truncate_cpy(buf, sizeof(buf), str);
return buf;
}
return NULL;
+1 -1
View File
@@ -531,7 +531,7 @@ static void ConvertToTm(struct tm *t, int64_t sec) {
ReplayFileInfo ConvertFileInfo(const PSPFileInfo &data) {
ReplayFileInfo info;
truncate_cpy(info.filename, data.name.c_str());
truncate_cpy(info.filename, data.name);
info.size = data.size;
info.access = (uint16_t)data.access;
info.exists = data.exists ? 1 : 0;
+1 -1
View File
@@ -130,7 +130,7 @@ void MainWindow::loadAct()
{
QFileInfo info(filename);
g_Config.currentDirectory = Path(info.absolutePath().toStdString());
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, filename.toStdString().c_str());
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, filename.toStdString());
}
}
+1 -1
View File
@@ -641,7 +641,7 @@ TOGGLE_METHOD(FullScreen, g_Config.bFullScreen, System_MakeRequest(SystemRequest
}
-(void)openRecentItem: (NSMenuItem *)item {
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, g_recentFiles.GetRecentFiles()[item.tag].c_str());
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, g_recentFiles.GetRecentFiles()[item.tag]);
}
-(void)openSystemFileBrowser {
+1 -1
View File
@@ -1222,7 +1222,7 @@ void FrameDumpTestScreen::update() {
// We rely slightly on nginx listing format here. Not great.
SplitString(listingHtml, '\n', lines);
for (auto &line : lines) {
std::string trimmed = StripSpaces(line);
std::string trimmed(StripSpaces(line));
if (startsWith(trimmed, "<a href=\"")) {
trimmed = trimmed.substr(strlen("<a href=\""));
size_t offset = trimmed.find('\"');
+2 -2
View File
@@ -780,7 +780,7 @@ void ImDisasmView::PopupMenu(ImControl &control) {
if (ImGui::MenuItem("Rename function")) {
funcBegin_ = g_symbolMap->GetFunctionStart(curAddress_);
if (funcBegin_ != -1) {
truncate_cpy(funcNameTemp_, g_symbolMap->GetLabelString(funcBegin_).c_str());
truncate_cpy(funcNameTemp_, g_symbolMap->GetLabelString(funcBegin_));
renameFunctionPopup = true;
statusBarText_ = funcNameTemp_;
} else {
@@ -1327,7 +1327,7 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImContro
if (ImGui::Selectable(symCache_[i].name.c_str(), selectedSymbol_ == i)) {
disasmView_.gotoAddr(symCache_[i].address);
disasmView_.scrollAddressIntoView();
truncate_cpy(selectedSymbolName_, symCache_[i].name.c_str());
truncate_cpy(selectedSymbolName_, symCache_[i].name);
selectedSymbol_ = i;
}
}
+3 -2
View File
@@ -672,6 +672,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
}
if (forceLogLevel) {
NOTICE_LOG(Log::System, "Setting log level to %d due to command line override", (int)logLevel);
g_logManager.SetAllLogLevels(logLevel);
}
@@ -1508,11 +1509,11 @@ void NativeAccelerometer(float tiltX, float tiltY, float tiltZ) {
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Z] = tiltZ;
}
void System_PostUIMessage(UIMessage message, const std::string &value) {
void System_PostUIMessage(UIMessage message, std::string_view param) {
std::lock_guard<std::mutex> lock(g_pendingMutex);
PendingMessage pendingMessage;
pendingMessage.message = message;
pendingMessage.value = value;
pendingMessage.value = param;
pendingMessages.push_back(pendingMessage);
}
+1 -1
View File
@@ -986,7 +986,7 @@ void CtrlDisAsmView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
{
char name[256];
std::string newname;
truncate_cpy(name, g_symbolMap->GetLabelString(funcBegin).c_str());
truncate_cpy(name, g_symbolMap->GetLabelString(funcBegin));
if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), L"New function name", name, newname)) {
g_symbolMap->SetLabelName(newname.c_str(), funcBegin);
u32 funcSize = g_symbolMap->GetFunctionSize(funcBegin);
+2 -2
View File
@@ -908,8 +908,8 @@ namespace MainWindow
if (!MainThread_Ready())
return DefWindowProc(hWnd, message, wParam, lParam);
HDROP hdrop = (HDROP)wParam;
int count = DragQueryFile(hdrop, 0xFFFFFFFF, 0, 0);
const HDROP hdrop = (HDROP)wParam;
const int count = DragQueryFile(hdrop, 0xFFFFFFFF, 0, 0);
if (count != 1) {
// TODO: Translate? Or just not bother?
MessageBox(hwndMain, L"You can only load one file at a time", L"Error", MB_ICONINFORMATION);
-1
View File
@@ -1621,7 +1621,6 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeActivity_requestExitVulkanR
_assert_(g_renderLoopThread.joinable());
exitRenderLoop = true;
g_renderLoopThread.join();
_assert_(!g_renderLoopThread.joinable());
g_renderLoopThread = std::thread();
}
@@ -0,0 +1,86 @@
package org.ppsspp.ppsspp;
import androidx.annotation.NonNull;
import android.util.Log;
// Simple class to validate the app lifecycle progression.
// Useful to debug using logs.
public class LifeCycle {
private final String TAG = "PPSSPPNativeActivity";
public enum State {
LAUNCHED,
CREATED,
STARTED,
RUNNING;
@NonNull
@Override
public String toString() {
// Optional: return a custom string if needed
return name(); // "LAUNCHED", "CREATED", etc.
}
}
private State state = State.LAUNCHED;
public boolean onCreate() {
if (state != State.LAUNCHED) {
Log.e(TAG, "Lifecycle: onCreate, but state is " + state + ". Expected LAUNCHED");
return false;
}
Log.i(TAG, "onCreate begin");
state = State.CREATED;
return true;
}
public boolean onStart() {
if (state != State.CREATED) {
Log.e(TAG, "Lifecycle: onStart, but state is " + state + ". Expected CREATED");
return false;
}
Log.i(TAG, "onStart begin");
state = State.STARTED;
return true;
}
public boolean onResume() {
if (state != State.STARTED) {
Log.e(TAG, "Lifecycle: onResume, but state is " + state + ". Expected STARTED");
return false;
}
state = State.RUNNING;
Log.i(TAG, "onResume begin");
return true;
}
public boolean onPause() {
if (state != State.RUNNING) {
Log.e(TAG, "Lifecycle: onPause, but state is " + state + ". Expected RUNNING");
return false;
}
state = State.STARTED;
Log.i(TAG, "onPause begin");
return true;
}
public boolean onStop() {
if (state != State.STARTED) {
Log.e(TAG, "Lifecycle: onStop, but state is " + state + ". Expected STARTED");
return false;
}
state = State.CREATED;
Log.i(TAG, "onStop begin");
return true;
}
public boolean onDestroy() {
if (state != State.CREATED) {
Log.e(TAG, "Lifecycle: onDestroy, but state is " + state + ". Expected CREATED");
return false;
}
state = State.CREATED;
Log.i(TAG, "onDestroy begin");
return true;
}
}
@@ -71,6 +71,9 @@ public abstract class NativeActivity extends Activity implements SensorEventList
// False to use Vulkan, queried from C++ after NativeApp.init.
private static boolean javaGL = true;
// Lifecycle tracker, to detect erroneous states.
private final LifeCycle lifeCycle = new LifeCycle();
// Graphics and audio interfaces for Vulkan (javaGL = false)
private NativeSurfaceView mSurfaceView;
private Surface mSurface;
@@ -578,7 +581,7 @@ public abstract class NativeActivity extends Activity implements SensorEventList
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate begin");
lifeCycle.onCreate();
mSensorManager = (SensorManager)getSystemService(Activity.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
@@ -706,12 +709,12 @@ public abstract class NativeActivity extends Activity implements SensorEventList
Log.i(TAG, "notifySurface begin");
mSurface = surface;
if (!initialized) {
Log.e(TAG, "notifySurface end: Can't deal with surfaces while not initialized");
return;
}
if (!javaGL) {
if (!initialized) {
Log.e(TAG, "notifySurface end: Saving surface, but can't start/stop threads while not initialized");
return;
}
// If we got a surface, this starts the thread. If not, it doesn't.
if (mSurface == null) {
joinRenderLoopThread();
@@ -766,7 +769,8 @@ public abstract class NativeActivity extends Activity implements SensorEventList
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "onDestroy begin");
lifeCycle.onDestroy();
if (javaGL) {
nativeRenderer = null;
mGLSurfaceView = null;
@@ -808,9 +812,22 @@ public abstract class NativeActivity extends Activity implements SensorEventList
Log.i(TAG, "onDestroy end");
}
@Override
protected void onStart() {
super.onStart();
lifeCycle.onStart();
}
@Override
protected void onStop() {
super.onStop();
lifeCycle.onStop();
}
@Override
protected void onPause() {
super.onPause();
lifeCycle.onPause();
if (!javaGL) {
Log.i(TAG, "Joining render thread...");
@@ -820,8 +837,6 @@ public abstract class NativeActivity extends Activity implements SensorEventList
mGLSurfaceView.onPause();
}
Log.i(TAG, "onPause begin");
mSensorManager.unregisterListener(this);
loseAudioFocus(this.audioManager, this.audioFocusChangeListener);
@@ -836,8 +851,7 @@ public abstract class NativeActivity extends Activity implements SensorEventList
@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "onResume begin");
lifeCycle.onResume();
updateSustainedPerformanceMode();
sizeManager.onResume();
@@ -224,9 +224,9 @@ public class SizeManager implements SurfaceHolder.Callback {
safeInsetRight = cutout.getSafeInsetRight();
safeInsetTop = cutout.getSafeInsetTop();
safeInsetBottom = cutout.getSafeInsetBottom();
Log.i(TAG, "Safe insets: left: " + safeInsetLeft + " right: " + safeInsetRight + " top: " + safeInsetTop + " bottom: " + safeInsetBottom);
// Log.i(TAG, "Safe insets: left: " + safeInsetLeft + " right: " + safeInsetRight + " top: " + safeInsetTop + " bottom: " + safeInsetBottom);
} else {
Log.i(TAG, "Safe insets: Cutout was null");
// Log.i(TAG, "Safe insets: Cutout was null");
safeInsetLeft = 0;
safeInsetRight = 0;
safeInsetTop = 0;
+1 -1
View File
@@ -93,7 +93,7 @@ bool System_GetPropertyBool(SystemProperty prop) {
}
}
void System_Notify(SystemNotification notification) {}
void System_PostUIMessage(UIMessage message, const std::string &param) {}
void System_PostUIMessage(UIMessage message, std::string_view param) {}
void System_RunOnMainThread(std::function<void()>) {}
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, int64_t param3, int64_t param4) {
switch (type) {
+1 -1
View File
@@ -1999,7 +1999,7 @@ void System_Notify(SystemNotification notification) {
}
}
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, int64_t param3, int64_t param4) { return false; }
void System_PostUIMessage(UIMessage message, const std::string &param) {}
void System_PostUIMessage(UIMessage message, std::string_view param) {}
void System_RunOnMainThread(std::function<void()>) {}
void NativeFrame(GraphicsContext *graphicsContext) {}
void NativeResized() {}
+1 -1
View File
@@ -112,7 +112,7 @@ bool System_GetPropertyBool(SystemProperty prop) {
}
}
void System_Notify(SystemNotification notification) {}
void System_PostUIMessage(UIMessage message, const std::string &param) {}
void System_PostUIMessage(UIMessage message, std::string_view param) {}
void System_RunOnMainThread(std::function<void()>) {}
void System_AudioGetDebugStats(char *buf, size_t bufSize) { if (buf) buf[0] = '\0'; }
void System_AudioClear() {}