First step of cleaning up Log.h. Plus a few other bits and bobs.

This commit is contained in:
Henrik Rydgård 2020-08-16 13:27:28 +02:00
parent 61bf512244
commit e8a9845d93
11 changed files with 37 additions and 86 deletions

View File

@ -23,7 +23,6 @@
#include "Common.h"
#include "ArmCommon.h"
#include "CodeBlock.h"
#include "MsgHandler.h"
// VCVT flags
#define TO_FLOAT 0

View File

@ -15,7 +15,6 @@
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/Log.h"
#include "ext/native/thread/threadutil.h"

View File

@ -20,7 +20,7 @@
#include <cstdio>
#include "CommonFuncs.h"
#include "Common/MsgHandler.h"
#include "MsgHandler.h" // For ShowAssertDialog
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and debugprintfs from the game itself.
#define ERROR_LEVEL 2 // Important errors.
@ -129,7 +129,7 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char *
__LINE__, __FILE__); \
ERROR_LOG(SYSTEM, #_a_ "\n\nError...\n\n Line: %d\n File: %s\n\nIgnore and continue?", \
__LINE__, __FILE__); \
if (!PanicYesNo("*** Assertion ***\n")) { Crash(); } \
if (!ShowAssertDialog(__FILE__, __LINE__, "*** Assertion ***\n")) { Crash(); } \
}
#if defined(__ANDROID__)
@ -138,7 +138,7 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char *
if (!(_a_)) {\
printf(__VA_ARGS__); \
ERROR_LOG(SYSTEM, __VA_ARGS__); \
if (!PanicYesNo(__VA_ARGS__)) AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
if (!ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
}
#else // !defined(__ANDROID__)
@ -147,7 +147,7 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char *
if (!(_a_)) {\
printf(__VA_ARGS__); \
ERROR_LOG(SYSTEM, __VA_ARGS__); \
if (!PanicYesNo(__VA_ARGS__)) { Crash();} \
if (!ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) { Crash();} \
}
#endif // __ANDROID__
@ -169,7 +169,7 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char *
}
#define _assert_msg_(_a_, ...) \
if (!(_a_) && !PanicYesNo(__VA_ARGS__)) { \
if (!(_a_) && !ShowAssertDialog(__FILENAME__, __LINE__, __VA_ARGS__)) { \
AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
}
@ -177,13 +177,12 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char *
#define _assert_(_a_) \
if (!(_a_)) {\
ERROR_LOG(SYSTEM, "Error...\n\n Line: %d\n File: %s\n\nIgnore and continue?", \
__LINE__, __FILE__); \
if (!PanicYesNo("*** Assertion ***\n")) { Crash(); } \
ERROR_LOG(SYSTEM, "Error...\n\n Line: %d\n File: %s\n\nIgnore and continue?", __LINE__, __FILE__); \
if (!ShowAssertDialog(__FILE__, __LINE__, "*** Assertion ***\n")) { Crash(); } \
}
#define _assert_msg_(_a_, ...) \
if (!(_a_) && !PanicYesNo(__VA_ARGS__)) { \
if (!(_a_) && !ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) { \
Crash(); \
}

View File

@ -22,7 +22,6 @@
#include <stdint.h>
#include "Common.h"
#include "MsgHandler.h"
namespace MIPSGen {

View File

@ -24,52 +24,29 @@
#include "StringUtils.h"
#include "util/text/utf8.h"
bool MsgHandler(const char *caption, const char *text, const char *file, int line, bool yes_no, int Style);
bool MsgAlert(bool yes_no, int Style, const char *file, int line, const char* format, ...) {
// Read message and write it to the log
char buffer[2048];
static const char *captions[] = {
"Information",
"Question",
"Warning",
"Critical"
};
const char *caption = captions[Style];
va_list args;
va_start(args, format);
CharArrayFromFormatV(buffer, sizeof(buffer)-1, format, args);
va_end(args);
// Normal logging (will also log to Android log)
ERROR_LOG(SYSTEM, "(%s:%d) %s: %s", file, line, caption, buffer);
// Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
if (Style == QUESTION || Style == CRITICAL)
return MsgHandler(caption, buffer, file, line, yes_no, Style);
return true;
}
#ifdef _WIN32
#ifdef PPSSPP_PLATFORM(WINDOWS)
#include "CommonWindows.h"
#endif
// Default non library dependent panic alert
bool MsgHandler(const char* caption, const char* text, const char *file, int line, bool yes_no, int Style) {
#if defined(USING_WIN_UI)
int msgBoxStyle = MB_ICONINFORMATION;
if (Style == QUESTION) msgBoxStyle = MB_ICONQUESTION;
if (Style == WARNING) msgBoxStyle = MB_ICONWARNING;
bool ShowAssertDialog(const char *file, int line, const char* format, ...) {
// Read message and write it to the log
char text[2048];
const char *caption = "Critical";
va_list args;
va_start(args, format);
CharArrayFromFormatV(text, sizeof(text)-1, format, args);
va_end(args);
// Normal logging (will also log to Android log)
ERROR_LOG(SYSTEM, "(%s:%d) %s: %s", file, line, caption, text);
#if defined(USING_WIN_UI)
int msgBoxStyle = MB_ICONINFORMATION | MB_YESNO;
std::wstring wtext = ConvertUTF8ToWString(text) + L"\n\nTry to continue?";
std::wstring wcaption = ConvertUTF8ToWString(caption);
OutputDebugString(wtext.c_str());
return IDYES == MessageBox(0, wtext.c_str(), wcaption.c_str(), msgBoxStyle | (yes_no ? MB_YESNO : MB_OK));
#elif PPSSPP_PLATFORM(UWP)
OutputDebugStringUTF8(text);
return false;
return IDYES == MessageBox(0, wtext.c_str(), wcaption.c_str(), msgBoxStyle);
#else
// Will use android-log if available, printf if not.
ERROR_LOG(SYSTEM, "(%s:%d) %s", file, line, text);
OutputDebugStringUTF8(text);
return false;
#endif
}

View File

@ -17,19 +17,9 @@
#pragma once
// Message alerts
enum MSG_TYPE {
INFORMATION,
QUESTION,
WARNING,
CRITICAL
};
bool MsgAlert(bool yes_no, int Style, const char *file, int line, const char* format, ...)
// Currently only actually shows a dialog box on Windows.
bool ShowAssertDialog(const char *file, int line, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 5, 6)))
__attribute__((format(printf, 3, 4)))
#endif
;
// Used only for asserts.
#define PanicYesNo(...) MsgAlert(true, CRITICAL, __FILE__, __LINE__, __VA_ARGS__)

View File

@ -21,7 +21,6 @@
#include "ABI.h"
#include "CPUDetect.h"
#include "MemoryUtil.h"
#include "MsgHandler.h"
#define PRIx64 "llx"

View File

@ -24,7 +24,6 @@ extern "C" {
#endif
#include "Common/FileUtil.h"
#include "Common/MsgHandler.h"
#include "Common/ColorConv.h"
#include "Core/Config.h"

View File

@ -22,7 +22,6 @@
#include "profiler/profiler.h"
#include "Common/MsgHandler.h"
#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeList.h"
#include "Core/CoreTiming.h"
@ -43,25 +42,17 @@ int CPU_HZ = 222000000;
namespace CoreTiming
{
struct EventType
{
EventType() {}
EventType(TimedCallback cb, const char *n)
: callback(cb), name(n) {}
struct EventType {
TimedCallback callback;
const char *name;
};
std::vector<EventType> event_types;
struct BaseEvent
{
struct BaseEvent {
s64 time;
u64 userdata;
int type;
// Event *next;
};
typedef LinkedListItem<BaseEvent> Event;
@ -171,7 +162,7 @@ void FreeTsEvent(Event* ev)
int RegisterEvent(const char *name, TimedCallback callback)
{
event_types.push_back(EventType(callback, name));
event_types.push_back(EventType{ callback, name });
return (int)event_types.size() - 1;
}
@ -185,9 +176,9 @@ void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callba
{
_assert_msg_(event_type >= 0, "Invalid event type %d", event_type)
if (event_type >= (int) event_types.size())
event_types.resize(event_type + 1, EventType(AntiCrashCallback, "INVALID EVENT"));
event_types.resize(event_type + 1, EventType{ AntiCrashCallback, "INVALID EVENT" });
event_types[event_type] = EventType(callback, name);
event_types[event_type] = EventType{ callback, name };
}
void UnregisterAllEvents()
@ -692,7 +683,7 @@ void DoState(PointerWrap &p)
int n = (int) event_types.size();
Do(p, n);
// These (should) be filled in later by the modules.
event_types.resize(n, EventType(AntiCrashCallback, "INVALID EVENT"));
event_types.resize(n, EventType{ AntiCrashCallback, "INVALID EVENT" });
if (s >= 3) {
DoLinkedList<BaseEvent, GetNewEvent, FreeEvent, Event_DoState>(p, first, (Event **) NULL);

View File

@ -5,8 +5,7 @@
#include <string>
#include "Core/WaveFile.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/Log.h"
#include "Core/Config.h"
constexpr size_t WaveFileWriter::BUFFER_SIZE;

View File

@ -14,7 +14,7 @@
#include <array>
#include <string>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
class WaveFileWriter
@ -27,14 +27,14 @@ public:
void Stop();
void SetSkipSilence(bool skip) { skip_silence = skip; }
void AddStereoSamples(const short* sample_data, u32 count);
u32 GetAudioSize() const { return audio_size; }
void AddStereoSamples(const short* sample_data, uint32_t count);
uint32_t GetAudioSize() const { return audio_size; }
private:
static constexpr size_t BUFFER_SIZE = 32 * 1024;
File::IOFile file;
bool skip_silence = false;
u32 audio_size = 0;
uint32_t audio_size = 0;
std::array<short, BUFFER_SIZE> conv_buffer{};
void Write(u32 value);
void Write4(const char* ptr);