Skip to content

Commit

Permalink
apps/vectorwar: don't depend on Platform functions
Browse files Browse the repository at this point in the history
Instead we just copy them there for now.
  • Loading branch information
Shugyousha committed Jan 2, 2020
1 parent 9d024aa commit e755f60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/apps/vectorwar/gdi_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ GDIRenderer::DrawConnectState(HDC hdc, Ship &ship, PlayerConnectionInfo &info, C

case Disconnecting:
sprintf(status, "Waiting for player...");
progress = (Platform::GetCurrentTimeMS() - info.disconnect_start) * 100 / info.disconnect_timeout;
progress = (GetCurrentTimeMS() - info.disconnect_start) * 100 / info.disconnect_timeout;
break;
}

Expand Down
6 changes: 4 additions & 2 deletions src/apps/vectorwar/ggpo_perfmon.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <windows.h>
#include <stdio.h>

#include "resource.h"
#include "ggponet.h"
#include "ggpo_perfmon.h"
#include "vectorwar.h"

#define MAX_GRAPH_SIZE 4096
#define MAX_FAIRNESS 20
Expand Down Expand Up @@ -114,7 +116,7 @@ ggpo_perfmon_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_INITDIALOG:
{
char pid[64];
sprintf(pid, "%d", Platform::GetProcessId());
sprintf(pid, "%d", GetProcessID());
SetWindowTextA(GetDlgItem(hwndDlg, IDC_PID), pid);
return TRUE;
}
Expand Down Expand Up @@ -210,7 +212,7 @@ ggpoutil_perfmon_update(GGPOSession *ggpo, GGPOPlayerHandle players[], int num_p
}
}

int now = Platform::GetCurrentTimeMS();
uint32_t now = GetCurrentTimeMS();
if (_dialog) {
InvalidateRect(GetDlgItem(_dialog, IDC_FAIRNESS_GRAPH), NULL, FALSE);
InvalidateRect(GetDlgItem(_dialog, IDC_NETWORK_GRAPH), NULL, FALSE);
Expand Down
10 changes: 5 additions & 5 deletions src/apps/vectorwar/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CreateMainWindow(HINSTANCE hInstance)
int width = 640, height = 480;
WCHAR titlebuf[128];

wsprintf(titlebuf, L"(pid:%d) ggpo sdk sample: vector war", Platform::GetProcessId());
wsprintf(titlebuf, L"(pid:%d) ggpo sdk sample: vector war", GetProcessID());
wndclass.cbSize = sizeof(wndclass);
wndclass.lpfnWndProc = MainWindowProc;
wndclass.lpszClassName = L"vwwnd";
Expand All @@ -69,9 +69,9 @@ void
RunMainLoop(HWND hwnd)
{
MSG msg = { 0 };
int start, next, now;
uint32_t start, next, now;

start = next = now = Platform::GetCurrentTimeMS();
start = next = now = GetCurrentTimeMS();
while(1) {
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
Expand All @@ -80,7 +80,7 @@ RunMainLoop(HWND hwnd)
return;
}
}
now = Platform::GetCurrentTimeMS();
now = GetCurrentTimeMS();
VectorWar_Idle(max(0, next - now - 1));
if (now >= next) {
VectorWar_RunFrame(hwnd);
Expand Down Expand Up @@ -184,4 +184,4 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
WSACleanup();
DestroyWindow(hwnd);
return 0;
}
}
11 changes: 9 additions & 2 deletions src/apps/vectorwar/vectorwar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <gl/glu.h>
#include <math.h>
#include <stdio.h>

#include <chrono>
#include <thread>

#include "gdi_renderer.h"
#include "vectorwar.h"
#include "ggpo_perfmon.h"
Expand Down Expand Up @@ -82,7 +86,7 @@ vw_on_event_callback(GGPOEvent *info)
break;
case GGPO_EVENTCODE_CONNECTION_INTERRUPTED:
ngs.SetDisconnectTimeout(info->u.connection_interrupted.player,
Platform::GetCurrentTimeMS(),
GetCurrentTimeMS(),
info->u.connection_interrupted.disconnect_timeout);
break;
case GGPO_EVENTCODE_CONNECTION_RESUMED:
Expand All @@ -92,7 +96,7 @@ vw_on_event_callback(GGPOEvent *info)
ngs.SetConnectState(info->u.disconnected.player, Disconnected);
break;
case GGPO_EVENTCODE_TIMESYNC:
Platform::SleepMS(1000 * info->u.timesync.frames_ahead / 60);
std::this_thread::sleep_for(std::chrono::milliseconds(1000 * info->u.timesync.frames_ahead / 60));
break;
}
return true;
Expand Down Expand Up @@ -449,3 +453,6 @@ VectorWar_Exit()
}
delete renderer;
}

DWORD GetProcessID() { return GetCurrentProcessId(); }
uint32_t GetCurrentTimeMS() { return timeGetTime(); }
6 changes: 6 additions & 0 deletions src/apps/vectorwar/vectorwar.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _VECTORWAR_H
#define _VECTORWAR_H

#include <stdint.h>

#include "ggponet.h"

/*
Expand Down Expand Up @@ -28,6 +30,10 @@ void VectorWar_Idle(int time);
void VectorWar_DisconnectPlayer(int player);
void VectorWar_Exit();

// Helper functions
DWORD GetProcessID();
uint32_t GetCurrentTimeMS();

#define ARRAY_SIZE(n) (sizeof(n) / sizeof(n[0]))
#define FRAME_DELAY 2

Expand Down

0 comments on commit e755f60

Please sign in to comment.