Permalink
Browse files

show better message box for invalid port too

also simplify GraphicsMode a tiny bit
  • Loading branch information...
UnknownShadow200 committed Feb 11, 2019
1 parent 3420c71 commit 1bb2e715183447057e1aba479c27458b2e5a82ab
Showing with 21 additions and 21 deletions.
  1. +2 −3 src/Platform.c
  2. +1 −2 src/Platform.h
  3. +14 −9 src/Program.c
  4. +4 −7 src/Window.c
@@ -111,10 +111,9 @@ const ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK;
/*########################################################################################################################*
*------------------------------------------------------GraphicsMode-------------------------------------------------------*
*#########################################################################################################################*/
void GraphicsMode_Make(struct GraphicsMode* m, int bpp, int depth, int stencil, int buffers) {
void GraphicsMode_Make(struct GraphicsMode* m, int bpp, int depth, int stencil) {
m->DepthBits = depth;
m->StencilBits = stencil;
m->Buffers = buffers;
m->IsIndexed = bpp < 15;
m->BitsPerPixel = bpp;

@@ -139,7 +138,7 @@ void GraphicsMode_Make(struct GraphicsMode* m, int bpp, int depth, int stencil,
}
void GraphicsMode_MakeDefault(struct GraphicsMode* m) {
int bpp = DisplayDevice_Default.BitsPerPixel;
GraphicsMode_Make(m, bpp, 24, 0, 2);
GraphicsMode_Make(m, bpp, 24, 0);
}


@@ -40,10 +40,9 @@ extern void* DisplayDevice_Meta;
struct GraphicsMode {
int R,G,B,A, BitsPerPixel, IsIndexed; /* Colour buffer data */
int DepthBits, StencilBits; /* Z buffer data */
int Buffers; /* Number of buffers (usually 2 for double buffer) */
};
/* Creates a new GraphicsMode from the given data. */
void GraphicsMode_Make(struct GraphicsMode* m, int bpp, int depth, int stencil, int buffers);
void GraphicsMode_Make(struct GraphicsMode* m, int bpp, int depth, int stencil);
/* Creates a GraphicsMode compatible with the default display device. */
void GraphicsMode_MakeDefault(struct GraphicsMode* m);

@@ -82,6 +82,16 @@ static void Program_SetCurrentDirectory(void) {
if (res) { Logger_Warn(res, "setting current directory"); return; }
}

static void Program_FailInvalidArg(const char* name, const String* arg) {
char tmpBuffer[256];
String tmp = String_NT_Array(tmpBuffer);

String_Format2(&tmp, "%c '%s'", name, arg);
tmp.buffer[tmp.length] = '\0';
Window_ShowDialog("Failed to start", tmpBuffer);
Platform_Exit(1);
}

int main(int argc, char** argv) {
String args[GAME_MAX_CMDARGS];
int argsCount;
@@ -124,17 +134,12 @@ int main(int argc, char** argv) {
String_Copy(&Game_IPAddress, &args[2]);

if (!Utils_ParseIP(&args[2], ip)) {
char tmpIpBuffer[200];
String tmpIp = String_NT_Array(tmpIpBuffer);
String_Format1(&tmpIp, "Invalid IP: %s", &args[2]);
tmpIp.buffer[tmpIp.length] = '\0';

Window_ShowDialog("Failed to start", tmpIpBuffer);
Platform_Exit(1); return 1;
Program_FailInvalidArg("Invalid IP", &args[2]);
return 1;
}
if (!Convert_ParseUInt16(&args[3], &port)) {
Window_ShowDialog("Failed to start", "Invalid port");
Platform_Exit(1); return 1;
Program_FailInvalidArg("Invalid port", &args[3]);
return 1;
}
Game_Port = port;
Program_RunGame();
@@ -614,7 +614,7 @@ void GLContext_SelectGraphicsMode(struct GraphicsMode* mode) {
PIXELFORMATDESCRIPTOR pfd = { 0 };
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
/* TODO: PFD_SUPPORT_COMPOSITION FLAG? CHECK IF IT WORKS ON XP */
pfd.cColorBits = mode->R + mode->G + mode->B;

@@ -626,8 +626,6 @@ void GLContext_SelectGraphicsMode(struct GraphicsMode* mode) {

pfd.cDepthBits = mode->DepthBits;
pfd.cStencilBits = mode->StencilBits;
if (mode->DepthBits <= 0) pfd.dwFlags |= PFD_DEPTH_DONTCARE;
if (mode->Buffers > 1) pfd.dwFlags |= PFD_DOUBLEBUFFER;

int modeIndex = ChoosePixelFormat(win_DC, &pfd);
if (modeIndex == 0) { Logger_Abort("Requested graphics mode not available"); }
@@ -1701,8 +1699,8 @@ static void GLContext_GetAttribs(struct GraphicsMode* mode, int* attribs) {
if (mode->StencilBits) {
attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = mode->StencilBits;
}
if (mode->Buffers > 1) { attribs[i++] = GLX_DOUBLEBUFFER; }

attribs[i++] = GLX_DOUBLEBUFFER;
attribs[i++] = 0;
}

@@ -2450,9 +2448,8 @@ static void GLContext_GetAttribs(struct GraphicsMode* mode, int* attribs, bool f
attribs[i++] = AGL_STENCIL_SIZE; attribs[i++] = mode->StencilBits;
}

if (mode->Buffers > 1) { attribs[i++] = AGL_DOUBLEBUFFER; }
if (fullscreen) { attribs[i++] = AGL_FULLSCREEN; }

attribs[i++] = AGL_DOUBLEBUFFER;
if (fullscreen) { attribs[i++] = AGL_FULLSCREEN; }
attribs[i++] = 0;
}

0 comments on commit 1bb2e71

Please sign in to comment.