New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port for windows #18
Port for windows #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,9 @@ | |
.cache | ||
.vscode | ||
workspace.code-workspace | ||
.vs | ||
[Ee]xtern | ||
*.wsp | ||
|
||
# Visual Studio IDE | ||
CMakeSettings.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,37 @@ | |
#include <string.h> | ||
#include <time.h> | ||
|
||
#ifdef WIN32 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Including Windows api just for 1 function call. Like grrrrr. Let migw handle that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
#include <Windows.h> | ||
|
||
#define POW10_7 10000000 | ||
#define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000) | ||
#endif | ||
|
||
uint64 getNanos(void) | ||
{ | ||
struct timespec ts; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Leave it as it is. It works on windows as it is. Adds pointless complexity. You literally just copied what mingw does in the clock_gettime functions. Like why ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clock_gettime is a POSIX function, not from Windows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since mingw is ok with it, perhaps wrap it in |
||
#ifdef WIN32 | ||
// https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-libraries/winpthreads/src/clock.c#L121 | ||
|
||
unsigned __int64 t; | ||
|
||
union | ||
{ | ||
unsigned __int64 u64; | ||
FILETIME ft; | ||
} ct; | ||
|
||
GetSystemTimeAsFileTime(&ct.ft); | ||
|
||
t = ct.u64 - DELTA_EPOCH_IN_100NS; | ||
ts.tv_sec = t / POW10_7; | ||
ts.tv_nsec = ((int) (t % POW10_7)) * 100; | ||
#else | ||
clock_gettime(CLOCK_REALTIME, &ts); | ||
#endif | ||
|
||
return (uint64) ts.tv_sec * 1000000000L + ts.tv_nsec; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include "Util/Queue.h" | ||
#include "Util/Types.h" | ||
#include "Util/Utlist.h" | ||
#include "Util/Functions.h" | ||
#include "../Extern/libmapvxl/libmapvxl.h" | ||
|
||
#include <enet/enet.h> | ||
|
@@ -35,7 +36,13 @@ | |
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
|
||
#ifdef WIN32 | ||
#include <io.h> | ||
#include <Windows.h> | ||
#else | ||
#include <unistd.h> | ||
#endif | ||
|
||
Server server; | ||
pthread_mutex_t serverLock; | ||
|
@@ -522,10 +529,12 @@ void ReadlineNewLine(int signal) | |
ctrlc = 1; | ||
printf("\n"); | ||
LOG_INFO("Are you sure you want to exit? (Y/n)"); | ||
|
||
if (write(STDIN_FILENO, "\n", sizeof("\n")) != sizeof("\n")) { | ||
|
||
// 0 = STDIN_FILENO | ||
if (write(0, "\n", sizeof("\n")) != sizeof("\n")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Just hell no. If it doesnt exist on windows. Define it. |
||
LOG_DEBUG("epic write fail"); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pointless new line |
||
rl_replace_line("", 0); | ||
rl_on_new_line(); | ||
rl_redisplay(); | ||
|
@@ -536,7 +545,7 @@ void StopServer() | |
server.running = 0; | ||
} | ||
|
||
static void* serverConsole(void* arg) | ||
static void serverConsole(void* arg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave it as pointer please. Dont pretype it in the actual passtrough. |
||
{ | ||
(void) arg; | ||
char* buf; | ||
|
@@ -555,16 +564,21 @@ static void* serverConsole(void* arg) | |
} | ||
free(buf); | ||
} | ||
|
||
#ifdef WIN32 | ||
clear_history(); | ||
#else | ||
rl_clear_history(); | ||
#endif | ||
|
||
StopServer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed at all. Like it was there before. Rebase your commits. Dont fix up in later ones :| |
||
|
||
sleep(5); // wait 5 seconds for the server to stop | ||
server_sleep(5); // wait 5 seconds for the server to stop | ||
|
||
// if this thread is not dead at this point, then we need to stop the server by force >:) | ||
LOG_ERROR("Server did not respond for 5 seconds. Killing it with fire..."); | ||
|
||
exit(-1); | ||
|
||
return 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why ? |
||
} | ||
|
||
void StartServer(uint16 port, | ||
|
@@ -656,12 +670,12 @@ void StartServer(uint16 port, | |
server.master.timeSinceLastSend = time(NULL); | ||
|
||
pthread_t masterThread; | ||
pthread_create(&masterThread, NULL, keepMasterAlive, (void*)&server); | ||
pthread_create(&masterThread, NULL, (void*)keepMasterAlive, (void*)&server); | ||
pthread_detach(masterThread); | ||
|
||
rl_catch_signals = 0; | ||
rl_catch_signals = 0; | ||
pthread_t console; | ||
pthread_create(&console, NULL, serverConsole, NULL); | ||
pthread_create(&console, NULL, (void*)serverConsole, NULL); | ||
pthread_detach(console); | ||
|
||
signal(SIGINT, ReadlineNewLine); | ||
|
@@ -673,7 +687,7 @@ void StartServer(uint16 port, | |
WorldUpdate(); | ||
forPlayers(); | ||
pthread_mutex_unlock(&serverLock); | ||
sleep(0); | ||
server_sleep(0); | ||
} | ||
while (server.map.compressedMap) { | ||
server.map.compressedMap = Pop(server.map.compressedMap); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik ByteBit builds it without this mess ? And it works. You are also basically FORCING users to build with Visual Studio on windows. Which i do not like.