Implement new shot name generation using a persistent index.
[neverball] / share / sync.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include "glext.h"
16
17 /*---------------------------------------------------------------------------*/
18 #ifndef __APPLE__
19
20 static int search(const char *haystack, const char *needle)
21 {
22     const char *c;
23
24     for (; *haystack; haystack++)
25     {
26         for (c = needle; *c && *haystack; c++, haystack++)
27             if (*c != *haystack)
28                 break;
29
30         if ((*c == 0) && (*haystack == ' ' || *haystack == '\0'))
31             return 1;
32     }
33
34     return 0;
35 }
36
37 #endif
38 /*---------------------------------------------------------------------------*/
39 #ifdef __linux__
40
41 #include <GL/glx.h>
42
43 void sync_init(void)
44 {
45     Display *dpy;
46
47     if ((dpy = glXGetCurrentDisplay()))
48     {
49         int scr = DefaultScreen(dpy);
50
51         PFNGLXSWAPINTERVALSGIPROC _glXSwapInvervalSGI = NULL;
52
53         if (search(glXQueryExtensionsString(dpy, scr), "GLX_SGI_swap_control"))
54         {
55             if ((_glXSwapInvervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
56                  glXGetProcAddress((const GLubyte *) "glXSwapIntervalSGI")))
57                 _glXSwapInvervalSGI(1);
58         }
59     }
60 }
61
62 #endif
63 /*---------------------------------------------------------------------------*/
64 #ifdef _WIN32
65
66 void sync_init(void)
67 {
68 /* TODO: Sit down at a Windows machine and make this work.
69     PFNWGLSWAPINTERVALEXTPROC _wglSwapInvervalEXT = NULL;
70
71     if (search(wglGetExtensionsString(), "WGL_EXT_swap_control"))
72     {
73         if ((_wglSwapInvervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
74              wglGetProcAddress((const GLubyte *) "wglSwapIntervalEXT")))
75             _wglSwapInvervalEXT(1);
76     }
77 */
78 }
79
80 #endif
81 /*---------------------------------------------------------------------------*/
82 #ifdef __APPLE__
83
84 #include <OpenGL/OpenGL.h>
85
86 void sync_init(void)
87 {
88     long swap = 1;
89     CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &swap);
90 }
91
92 #endif
93 /*---------------------------------------------------------------------------*/