Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
msokalski committed Apr 6, 2020
1 parent e4241f4 commit 3e510c1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
11 changes: 11 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern World* world;
Human* player_head = 0;
Human* player_tail = 0;

char player_name[32] = "player";

void ReadConf(Game* g)
{
FILE* f = fopen("asciicker.cfg", "rb");
Expand Down Expand Up @@ -1142,6 +1144,9 @@ bool Server::Proc(const uint8_t* ptr, int size)
{
box = (TalkBox*)malloc(sizeof(TalkBox));
}

Human* h = others + talk->id;
printf("%s : %.*s\n", h->name, talk->len, talk->str);

memset(box, 0, sizeof(TalkBox));
memcpy(box->buf, talk->str, talk->len);
Expand Down Expand Up @@ -2050,6 +2055,8 @@ Game* CreateGame(int water, float pos[3], float yaw, float dir, uint64_t stamp)
Game* g = (Game*)malloc(sizeof(Game));
memset(g, 0, sizeof(Game));

strcpy(g->player.name, player_name);

ReadConf(g);

g->player.prev = 0;
Expand Down Expand Up @@ -3902,6 +3909,7 @@ void Game::OnKeyb(GAME_KEYB keyb, int key)
req_talk.len = player.talk[idx].box->len;
memcpy(req_talk.str, player.talk[idx].box->buf, player.talk[idx].box->len);
server->Send((const uint8_t*)&req_talk, 4 + req_talk.len);
printf("%s : %.*s\n", player.name, player.talk[idx].box->len, player.talk[idx].box->buf);
}

player.talks++;
Expand Down Expand Up @@ -4070,6 +4078,7 @@ void Game::OnKeyb(GAME_KEYB keyb, int key)
req_talk.len = player.talk[idx].box->len;
memcpy(req_talk.str, player.talk[idx].box->buf, player.talk[idx].box->len);
server->Send((const uint8_t*)&req_talk, 4 + req_talk.len);
printf("%s : %.*s\n", player.name, player.talk[idx].box->len, player.talk[idx].box->buf);
}

player.talks++;
Expand Down Expand Up @@ -4256,6 +4265,7 @@ void Game::OnKeyb(GAME_KEYB keyb, int key)
req_talk.len = player.talk[idx].box->len;
memcpy(req_talk.str, player.talk[idx].box->buf, player.talk[idx].box->len);
server->Send((const uint8_t*)&req_talk, 4 + req_talk.len);
printf("%s : %.*s\n", player.name, player.talk[idx].box->len, player.talk[idx].box->buf);
}

player.talks++;
Expand Down Expand Up @@ -4741,6 +4751,7 @@ void Game::StartContact(int id, int x, int y, int b)
req_talk.len = player.talk[idx].box->len;
memcpy(req_talk.str, player.talk[idx].box->buf, player.talk[idx].box->len);
server->Send((const uint8_t*)&req_talk, 4 + req_talk.len);
printf("%s : %.*s\n", player.name, player.talk[idx].box->len, player.talk[idx].box->buf);
}

player.talks++;
Expand Down
1 change: 1 addition & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "inventory.h"
#include "network.h"

extern char player_name[];

struct Character
{
Expand Down
4 changes: 2 additions & 2 deletions game.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-url gumix@localhost:8080</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-url gumix@localhost/ws/y4/</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-url gumix@localhost:8080</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>-url [email protected]:80/ws/y4/</LocalDebuggerCommandArguments>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions game_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,8 @@ int main(int argc, char* argv[])
printf("Couldn't connect to server, starting solo ...\n");
}

strcpy(player_name, user);

// here we should know if server is present or not
// so we can creare game or term with or without server
// ...
Expand Down
4 changes: 4 additions & 0 deletions game_svr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ struct PlayerCon
broadcast->id = ID;
memcpy(broadcast->str, req_talk->str, req_talk->len);
broadcast->Send(ID);

printf("%s : %.*s\n", player_name, req_talk->len, req_talk->str);
break;
}

Expand Down Expand Up @@ -820,6 +822,8 @@ int ServerLoop(const char* port)

PlayerCon::cs = RWLOCK_CREATE();

printf("SERVER awaits connections on port: %s\n", port);

while (isRunning)
{
TCP_SOCKET ClientSocket = INVALID_TCP_SOCKET;
Expand Down
30 changes: 24 additions & 6 deletions mswin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,30 @@ void* a3dGetCookie(A3D_WND* wnd)

uint64_t a3dGetTime()
{
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
uint64_t diff = c.QuadPart - coarse_perf.QuadPart;
return coarse_micro + diff * 1000000 / timer_freq.QuadPart;
// we can handle diff upto 3 minutes @ 100GHz clock
// this is why we refresh coarse time every minute on WM_TIMER of wnd_head
struct SafeTimer
{
static uint64_t Get1()
{
QueryPerformanceFrequency(&timer_freq);
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
uint64_t diff = c.QuadPart - coarse_perf.QuadPart;
return coarse_micro + diff * 1000000 / timer_freq.QuadPart;
}

static uint64_t Get2()
{
QueryPerformanceFrequency(&timer_freq);
LARGE_INTEGER c;
QueryPerformanceCounter(&c);
uint64_t diff = c.QuadPart - coarse_perf.QuadPart;
return coarse_micro + diff * 1000000 / timer_freq.QuadPart;
}
};

static uint64_t(*Get)() = SafeTimer::Get1;
Get = SafeTimer::Get2;
return Get();
}

/*
Expand Down
11 changes: 11 additions & 0 deletions multiplayer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
> RUN SERVER:
server.exe

> RUN CLIENTS connected to local server:
game.exe -url your_nick@localhost:8080/ws/y4/

> RUN CLIENTS connected to asciicker.com server:
game.exe -url [email protected]:80/ws/y4/

> Note that when staring game, there is also minimized console window with chat log
> Hef vun!

0 comments on commit 3e510c1

Please sign in to comment.