Skip to content

Commit

Permalink
Merge pull request #190 from mateusfavarin/main
Browse files Browse the repository at this point in the history
Launcher updates, WIP PINE Client
  • Loading branch information
mateusfavarin authored Jul 21, 2024
2 parents c997a86 + 8541ce8 commit 78f4103
Show file tree
Hide file tree
Showing 29 changed files with 346 additions and 214 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ __pycache__/
build/
debug/
x64/
Launcher/
data/
packages/
externals/
*.log
offset.txt
comport.txt
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
[submodule "externals/json"]
path = externals/json
url = https://github.com/nlohmann/json
[submodule "externals/HTTPRequest"]
path = externals/HTTPRequest
url = https://github.com/elnormous/HTTPRequest
[submodule "externals/cpp-httplib"]
path = externals/cpp-httplib
url = https://github.com/yhirose/cpp-httplib
Expand Down
5 changes: 0 additions & 5 deletions decompile/General/AltMods/OnlineCTR/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ struct OnlineCTR
char lastWindowsClientSync;

char desiredFPS;

// control when PSX and PC send/recv
char sleepControl;
char gpuSubmitTooLate;
char enableDeferredGPU;
};

STATIC_ASSERT2(sizeof(struct OnlineCTR) <= 0x400, "Size of OnlineCTR must be lte 1kb");
Expand Down
39 changes: 8 additions & 31 deletions decompile/General/MAIN/MainFrame_GameLogic.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@ typedef void (*VehicleFuncPtr)(struct Thread* thread, struct Driver* driver);
#ifdef USE_ONLINE
#include "../AltMods/OnlineCTR/global.h"
void RunVehicleThread(VehicleFuncPtr func, struct Thread* thread, struct Driver* driver);

#pragma optimize("", off)
void FrameStall()
{
// dont stall for this
if(octr->CurrState < LOBBY_HOST_TRACK_PICK)
return;

// wait for PC client to reset
while (octr->sleepControl == 1)
{
// required, or the register never updates
printf("");
}
}
#pragma optimize("", on)

#endif

void DECOMP_MainFrame_GameLogic(struct GameTracker* gGT, struct GamepadSystem* gGamepads)
Expand Down Expand Up @@ -221,7 +204,7 @@ void DECOMP_MainFrame_GameLogic(struct GameTracker* gGT, struct GamepadSystem* g
(gGT->threadBuckets[iVar4].thread != 0)
)
{

// online multiplayer
#ifdef USE_ONLINE

Expand All @@ -234,37 +217,31 @@ void DECOMP_MainFrame_GameLogic(struct GameTracker* gGT, struct GamepadSystem* g
if(gGT->trafficLightsTimer > 3600)
continue;
}

if (iVar4 == 0)
{
struct Driver* dOnline = gGT->drivers[0];
if(dOnline != 0)
{
struct Thread* dThread = dOnline->instSelf->thread;

DECOMP_VehPickupItem_ShootOnCirclePress(dOnline);

RunVehicleSet13(dThread, dOnline);

octr->sleepControl = 1;
octr->desiredFPS = FPS_DOUBLE(30);

// stall
if(octr->enableDeferredGPU == 1)
FrameStall();
}

for(int other = 1; other < 8; other++)
{
dOnline = gGT->drivers[other];
if(dOnline == 0) continue;

struct Thread* dThread = dOnline->instSelf->thread;

RunVehicleSet13(dThread, dOnline);
}
}

// offline
#else
if (iVar4 == 0)
Expand Down
12 changes: 3 additions & 9 deletions decompile/General/MAIN/MainFrame_RenderFrame.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void DECOMP_MainFrame_RenderFrame(struct GameTracker* gGT, struct GamepadSystem*
if((gGT->renderFlags & 0x8000) != 0)
{
WindowBoxLines(gGT);

WindowDivsionLines(gGT);
}
#endif
Expand Down Expand Up @@ -1483,7 +1483,7 @@ void MultiplayerWumpaHUD(struct GameTracker* gGT)
for(int i = 0; i < gGT->numPlyrCurrGame; i++)
{
struct Driver* d = gGT->drivers[i];

// if race is over for driver
if((d->actionsFlagSet & 0x2000000) != 0)
{
Expand Down Expand Up @@ -1711,16 +1711,10 @@ void RenderVSYNC(struct GameTracker* gGT)

if(ReadyToFlip(gGT))
{

#ifdef USE_ONLINE
if(boolFirstFrame)
octr->gpuSubmitTooLate = 1;
#endif

// quit, end of stall
return;
}

#ifdef USE_ONLINE
// gpu submission is not too late,
// we got to this while() loop before
Expand Down
2 changes: 1 addition & 1 deletion include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//#define USE_VR // Virtual Reality

#ifdef USE_ONLINE
#define USE_60FPS
//#define USE_60FPS
#define USE_BOOSTBAR
#define USE_16BY9
#define USE_RAMEX
Expand Down
69 changes: 9 additions & 60 deletions mods/Windows/OnlineCTR/Network_PC/Client/CL_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,74 +1281,26 @@ int main(int argc, char *argv[])
//perhaps instead of reading, keep a local counter, increment that, and then
//write it (without needing a blocking read first).
(*octr.get()).windowsClientSync++;

if (octr.get()->windowsClientSync == 0)
{
// On Niko's computer with MAPPED MEMORY
// 30fps 1x resolution = 4500
// 30fps 9x resolution = 2500
// 60fps = 0

// With the new PINE system, always zero,
// We can not defer the GPU until the PC port is done :(
//printf("Debug: SleepCount=%d\n", sleepCount);
}
octr.startWrite();

// should rename to room selection
if (octr.get()->CurrState >= LAUNCH_PICK_ROOM)
DisconSELECT();

StartAnimation();

// Wait for PSX to have P1 data,
// which is set at octr->sleepControl
void FrameStall(); FrameStall();

if (octr.get()->CurrState >= 0)
ClientState[octr.get()->CurrState]();

//UPDATE: the former version of this code sort of unconditionally usleep'd for a static amount
//of time (depending on 30 or 60fps). It's been updated to be dynamic, in case of lag/poor pc
//perf, or if PINE overhead is particularly large. If at any point in the future duckstation
//isn't at a locked 30/60fps, this may be the culprit.

// check for frame lag
if (octr.get()->gpuSubmitTooLate == 1)
{
octr.get()->gpuSubmitTooLate = 0;

// if 1-9 frame stalls
if (sleepCount >= 500)
{
// remove from sleep
sleepCount -= 500;
}

// if 10+ frame stalls
else
{
sleepCount = 0;
enableDeferredGPU = 0;
}
}

// PC writes to PSX,
// PSX is read-only
octr.get()->enableDeferredGPU = enableDeferredGPU;

// delay GPU between SEND and RECV
if (enableDeferredGPU == 1)
usleep(sleepCount);

// now check for new RECV message
ProcessNewMessages();

// allow PSX to resume
octr.get()->sleepControl = 0;

octr.startWrite(); //only write the things that have changed.

GCDeadPineData(); //this is probably a decent place to do this.

// Wait for PSX to have P1 data,
// which is set at octr->sleepControl
void FrameStall(); FrameStall();
}

printf("\n");
Expand All @@ -1370,17 +1322,14 @@ void usleep(__int64 usec)
}
#endif

#pragma optimize("", off)
int gGT_timer = 0;
void FrameStall()
{
// wait for next frame
//TODO: make this a submember of octr
ps1ptr<int> OCTRsleepControl = pBuf.at<int>(octr.get_address() + offsetof(OnlineCTR, sleepControl));
while ((*OCTRsleepControl.get()) == 0)
ps1ptr<int> OCTRsleepControl = pBuf.at<int>(0x80096b20 + 0x1cf8);
while (gGT_timer == (*OCTRsleepControl.get()))
{
usleep(1);
OCTRsleepControl.blockingRead();
}
(*octr.get()).sleepControl = (*OCTRsleepControl.get());
}
#pragma optimize("", on)
}
6 changes: 4 additions & 2 deletions tools/Launcher/Launcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<ClCompile Include="requests.cpp" />
<ClCompile Include="third_party\xdelta3\xdelta3.c" />
<ClCompile Include="ui.cpp" />
<ClCompile Include="updater.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="app.h" />
Expand All @@ -166,6 +167,7 @@
<ClInclude Include="patch.h" />
<ClInclude Include="requests.h" />
<ClInclude Include="ui.h" />
<ClInclude Include="updater.h" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -174,14 +176,14 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\sdl2.nuget.redist.2.30.3\build\native\sdl2.nuget.redist.targets" Condition="Exists('packages\sdl2.nuget.redist.2.30.3\build\native\sdl2.nuget.redist.targets')" />
<Import Project="packages\sdl2.nuget.2.30.3\build\native\sdl2.nuget.targets" Condition="Exists('packages\sdl2.nuget.2.30.3\build\native\sdl2.nuget.targets')" />
<Import Project="packages\EbolaChan.LibZip.1.10.1\build\native\EbolaChan.LibZip.targets" Condition="Exists('packages\EbolaChan.LibZip.1.10.1\build\native\EbolaChan.LibZip.targets')" />
<Import Project="packages\libzip-c.1.9.2.6\build\native\libzip-c.targets" Condition="Exists('packages\libzip-c.1.9.2.6\build\native\libzip-c.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\sdl2.nuget.redist.2.30.3\build\native\sdl2.nuget.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\sdl2.nuget.redist.2.30.3\build\native\sdl2.nuget.redist.targets'))" />
<Error Condition="!Exists('packages\sdl2.nuget.2.30.3\build\native\sdl2.nuget.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\sdl2.nuget.2.30.3\build\native\sdl2.nuget.targets'))" />
<Error Condition="!Exists('packages\EbolaChan.LibZip.1.10.1\build\native\EbolaChan.LibZip.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\EbolaChan.LibZip.1.10.1\build\native\EbolaChan.LibZip.targets'))" />
<Error Condition="!Exists('packages\libzip-c.1.9.2.6\build\native\libzip-c.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\libzip-c.1.9.2.6\build\native\libzip-c.targets'))" />
</Target>
</Project>
6 changes: 6 additions & 0 deletions tools/Launcher/Launcher.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<ClCompile Include="third_party\xdelta3\xdelta3.c">
<Filter>xdelta3</Filter>
</ClCompile>
<ClCompile Include="updater.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="app.h">
Expand All @@ -98,6 +101,9 @@
<ClInclude Include="io.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="updater.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
13 changes: 8 additions & 5 deletions tools/Launcher/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ void App::Run()
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();

int width, height;
SDL_GetWindowSize(m_window, &width, &height);
ui.Render(width, height);

Main();
ImGui::Render();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(clearColor.x * clearColor.w, clearColor.y * clearColor.w, clearColor.z * clearColor.w, clearColor.w);
Expand All @@ -136,6 +132,13 @@ void App::Run()
}
}

void App::Main()
{
int width, height;
SDL_GetWindowSize(m_window, &width, &height);
ui.Render(width, height);
}

void App::Close()
{
g_dataManager.SaveData();
Expand Down
3 changes: 2 additions & 1 deletion tools/Launcher/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class App
public:
void Init();
void Run();
void Main();
void Close();
#ifdef _DEBUG
void RunImGuiExample();
Expand All @@ -24,7 +25,7 @@ class App

private:
UI ui;
const std::string m_version = "v0.1";
const std::string m_version = "v0.2";
std::string m_glslVer;
SDL_GLContext m_glContext;
SDL_Window* m_window;
Expand Down
13 changes: 10 additions & 3 deletions tools/Launcher/dataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,34 @@
#include <filesystem>

const std::string g_dataFolder = "data/";
const std::string g_duckFolder = g_dataFolder + "duckstation/";
const std::string g_duckExecutable = g_duckFolder + "duckstation-qt-x64-ReleaseLTCG.exe";
const std::string g_clientString = "client.zip";
const std::string g_clientExecutable = "Client.exe";
const std::string g_patchString = "ctr-u_Online30.xdelta";
const std::string g_configString = "SCUS-94426.ini";

std::string GetClientPath(const std::string& version)
const std::string GetClientPath(const std::string& version)
{
return g_dataFolder + version + "/" + g_clientExecutable;
}

std::string GetPatchedGamePath(const std::string& version)
const std::string GetPatchedGamePath(const std::string& version)
{
std::string s_patch = g_dataFolder + version + "/" + g_patchString;
return s_patch.substr(0, s_patch.find(".")) + ".bin";
}

std::string GetConfigPath(const std::string& version)
const std::string GetIniPath_Version(const std::string& version)
{
return g_dataFolder + version + "/" + g_configString;
}

const std::string GetIniPath_Duck()
{
return g_duckFolder + "settings.ini";
}

DataManager g_dataManager;

DataManager::DataManager()
Expand Down
Loading

0 comments on commit 78f4103

Please sign in to comment.