Skip to content

Commit

Permalink
Start adding some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wally4000 committed Jan 23, 2025
1 parent 5f160da commit 6fe3317
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(DAEDALUS_CONFIG_VERSION="Dev") ## Show the build type in the UI
option(DAEDALUS_ENABLE_ASSERTS "Enable Static Asserts" ON)
option(DAEDALUS_DEBUG_CONSOLE "Enable Debug Console" ON)
option(DAEDALUS_DEBUG_DISPLAYLIST "Options for debugging the display list, useful for determining texture issues" OFF)
option(DAEDALUS_DEBUG_DISPLAYLIST "Options for debugging the display list, useful for determining texture issues" ON)
option(DAEDALUS_LOG "Enable various logging" ON)
option(DAEDALUS_SILENT "Shhh, no debug console message, on by default" OFF)
if(NOT WIN32)
Expand Down
28 changes: 21 additions & 7 deletions Source/HLEGraphics/DLDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifdef DAEDALUS_DEBUG_DISPLAYLIST
#include <stdarg.h>
#include <format>
#include <cstring>
#include <fstream>

#include <filesystem>
#include "Core/ROM.h"
#include "Debug/DBGConsole.h"
Expand All @@ -13,6 +16,7 @@
#include "Ultra/ultra_gbi.h"

#include "Base/Macros.h"
#include "System/DataSink.h"


DLDebugOutput * gDLDebugOutput = nullptr;
Expand Down Expand Up @@ -445,22 +449,31 @@ void DLDebug_DumpTaskInfo( const OSTask * pTask )
class DLDebugOutputFile : public DLDebugOutput
{
public:
DLDebugOutputFile() : Sink(new FileSink)
DLDebugOutputFile() : outputStream()
{
}
~DLDebugOutputFile()
{
delete Sink;
{
if (outputStream.is_open())
{
outputStream.close();
}
}

bool Open(const std::filesystem::path filename)
bool Open(const std::filesystem::path& filename)
{
return Sink->Open(filename.c_str(), "w");
outputStream.open(filename, std::ios::out | std::ios::trunc);
return outputStream.is_open();
}

virtual size_t Write(const void * p, size_t len)
{
return Sink->Write(p, len);
if (outputStream.is_open())
{
outputStream.write(static_cast<const char*>(p), len);
return len;
}
return 0;
}

virtual void BeginInstruction(u32 idx, u32 cmd0, u32 cmd1, u32 depth [[maybe_unused]], const char * name)
Expand All @@ -472,7 +485,8 @@ class DLDebugOutputFile : public DLDebugOutput
{
}

FileSink * Sink;
private:
std::ofstream outputStream;
};

DLDebugOutput * DLDebug_CreateFileOutput()
Expand Down
2 changes: 1 addition & 1 deletion Source/HLEGraphics/TextureCacheWebDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void TextureHandler(void * arg [[maybe_unused]], WebDebugConnection * con
}

connection->BeginResponse(200, -1, "image/png");
PngSaveImage(connection, texture);
// PngSaveImage(connection, texture);
}

connection->EndResponse();
Expand Down
21 changes: 12 additions & 9 deletions Source/SysPosix/Debug/WebDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vector>
#include <fstream>
#include <filesystem>
#include <thread>

#include "Debug/DBGConsole.h"
#include "Utility/MathUtil.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ struct StaticResource
static void * gServerMemory = NULL;
static struct WebbyServer * gServer = NULL;
static volatile bool gKeepRunning = false;
static ThreadHandle gThread = kInvalidThreadHandle;
static std::thread gThread;

static int ws_connection_count;
static struct WebbyConnection * ws_connections[MAX_WSCONN];
Expand Down Expand Up @@ -237,6 +238,7 @@ static void ServeFile(WebDebugConnection * connection, const char * filename)
size_t len_read;
char buf[kBufSize];
do
{
len_read = fh.read(reinterpret_cast<char*>(buf), kBufSize).gcount();
// len_read = fread(buf, 1, kBufSize, fh);
if (len_read > 0)
Expand All @@ -248,6 +250,7 @@ static void ServeFile(WebDebugConnection * connection, const char * filename)
// fclose(fh);
}


bool ServeResource(WebDebugConnection * connection, const char * resource_path)
{
for (size_t i = 0; i < gStaticResources.size(); ++i)
Expand Down Expand Up @@ -385,7 +388,8 @@ static u32 WebDebugThread(void * arg)
// }
// }

ThreadSleepMs(10);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
//ThreadSleepMs(10);

++frame_counter;
}
Expand Down Expand Up @@ -468,20 +472,19 @@ bool WebDebug_Init()
AddStaticContent(data_path, "");

gKeepRunning = true;
gThread = CreateThread( "WebDebug", &WebDebugThread, gServer );
gThread = std::thread(WebDebugThread, gServer);
// gThread = CreateThread( "WebDebug", &WebDebugThread, gServer );

return true;
}

void WebDebug_Fini()
{
if (gThread != kInvalidThreadHandle)
{
gKeepRunning = false;
JoinThread(gThread, -1);
gThread = kInvalidThreadHandle;
}

if (gThread.joinable())
{
gThread.join();
}
WebbyServerShutdown(gServer);
free(gServerMemory);

Expand Down
13 changes: 7 additions & 6 deletions Source/SysPosix/HLEGraphics/DisplayListDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "System/Mutex.h"

#include "SysGL/GL.h"
#include <fstream>

static bool gDebugging = false;

Expand All @@ -46,7 +47,7 @@ static WebDebugConnection * gActiveConnection = NULL;
static DebugTask gDebugTask = kTaskUndefined;
static u32 gInstructionCountLimit = kUnlimitedInstructionCount;

static void Base64Encode(const void * data, size_t len, DataSink * sink)
static void Base64Encode(const void * data, size_t len, std::ofstream& outputStream)
{
const char * table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

Expand Down Expand Up @@ -87,7 +88,7 @@ static void Base64Encode(const void * data, size_t len, DataSink * sink)
}

DAEDALUS_ASSERT(dst == buffer+out_len, "Oops");
sink->Write(buffer, out_len);
outputStream.write(buffer, out_len);
free(buffer);
}

Expand Down Expand Up @@ -130,7 +131,7 @@ void DLDebugger_RequestDebug()
}


static void EncodeTexture(const std::shared_ptr<CNativeTexture> texture, DataSink * sink)
static void EncodeTexture(const std::shared_ptr<CNativeTexture> texture, std::ofstream& outputStream)
{
u32 width = texture->GetWidth();
u32 height = texture->GetHeight();
Expand All @@ -139,7 +140,7 @@ static void EncodeTexture(const std::shared_ptr<CNativeTexture> texture, DataSin

FlattenTexture(texture, bytes, num_bytes);

Base64Encode(bytes, num_bytes, sink);
Base64Encode(bytes, num_bytes, outputStream);
free(bytes);
}

Expand Down Expand Up @@ -273,8 +274,8 @@ void DLDebugger_ProcessDebugTask()

// NB, pass a negative pitch, to render the screenshot the right way up.
s32 pitch = -static_cast<s32>(width * 4);

PngSaveImage(connection, pixels, NULL, TexFmt_8888, pitch, width, height, false);
const std::filesystem::path tempFile = "screenshot.png";
PngSaveImage(tempFile, pixels, NULL, TexFmt_8888, pitch, width, height, false);

free(pixels);

Expand Down
2 changes: 1 addition & 1 deletion Source/UI/PauseOptionsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ IPauseOptionsComponent::IPauseOptionsComponent( CUIContext * p_context, std::fu
mElements.Add(std::make_unique<CUICommandImpl>(std::bind(&IPauseOptionsComponent::TakeScreenshot,this ), "Take Screenshot", "Take a screenshot on resume." ) );

#ifdef DAEDALUS_DEBUG_DISPLAYLIST
mElements.Add( new CUICommandImpl( std::bind(&IPauseOptionsComponent::DebugDisplayList, this ), "Debug Display List", "Debug display list on resume." ) );
mElements.Add( std::make_unique<CUICommandImpl>( std::bind(&IPauseOptionsComponent::DebugDisplayList, this ), "Debug Display List", "Debug display list on resume." ) );
#endif

#ifdef DAEDALUS_DEBUG_CONSOLE
Expand Down

0 comments on commit 6fe3317

Please sign in to comment.