int main(void) { static const double tstep = 1.0/TICKRATE; double tlast, tnow, tsec, dt, ddt=0.0; int ticks=0, tps=0, frames=0; #if 0 { int i; for (i=0; i<100; ++i) { gx_init("demo", XRES, YRES); gx_delay(0.01); gx_exit(); } } #endif gx_init("demo", XRES, YRES); tlast = gx_time(); while (1) { tnow = gx_time(); dt = tnow - tlast; tlast = tnow; if (dt > 0.25) dt = 0.25; if (poll_events()) break; ddt += dt; while (ddt >= tstep) { ddt -= tstep; ++ticks; ++tps; } draw(tnow, ddt/dt); gx_paint(buf, XRES, YRES); ++frames; print_time(ticks, &tps, tnow, dt); if (limitfps && maxfps) { double tmax = 1.0 / maxfps; while (gx_time() - tnow < tmax-0.002) gx_delay(0.001); while (gx_time() - tnow < tmax); } } tsec = gx_time(); printf("--- timing report ---\n" "ticks : %d\n" "frames : %d\n" "time : %.2f\n" "tickrate : %.2f\n" "fps : %.2f\n", ticks, frames, tsec, ticks/tsec, frames/tsec); return 0; }
static int gx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { struct gx_softc *sc; struct ifreq *ifr; #ifdef INET struct ifaddr *ifa; #endif int error; sc = ifp->if_softc; ifr = (struct ifreq *)data; #ifdef INET ifa = (struct ifaddr *)data; #endif switch (cmd) { case SIOCSIFADDR: #ifdef INET /* * Avoid reinitialization unless it's necessary. */ if (ifa->ifa_addr->sa_family == AF_INET) { ifp->if_flags |= IFF_UP; if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) gx_init(sc); arp_ifinit(ifp, ifa); return (0); } #endif error = ether_ioctl(ifp, cmd, data); if (error != 0) return (error); return (0); case SIOCSIFFLAGS: if (ifp->if_flags == sc->sc_flags) return (0); if ((ifp->if_flags & IFF_UP) != 0) { gx_init(sc); } else { if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) { ifp->if_drv_flags &= ~IFF_DRV_RUNNING; } } sc->sc_flags = ifp->if_flags; return (0); case SIOCSIFMTU: if (ifr->ifr_mtu + ifp->if_hdrlen > GXEMUL_ETHER_DEV_MTU) return (ENOTSUP); return (0); case SIOCSIFMEDIA: case SIOCGIFMEDIA: error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, cmd); if (error != 0) return (error); return (0); default: error = ether_ioctl(ifp, cmd, data); if (error != 0) return (error); return (0); } }
GXDisplayProperties GXGetDisplayProperties(void) { gx_init(); return(gxdp); }
int GXOpenDisplay(HWND hWnd, DWORD dwFlags) { DWORD winstyle; DWORD winstyleex; _BMPINFO bi; HDC hdc; HWND hTaskBar; if (gxhwnd) { goto gxopn_err1; } gx_init(); gxhwnd = hWnd; // bitmap���B ZeroMemory(&bi, sizeof(bi)); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = gxdp.cxWidth; bi.bmiHeader.biHeight = 0 - gxdp.cyHeight; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 16; bi.bmiHeader.biCompression = BI_BITFIELDS; bi.bmiColors[0] = 0xf800; bi.bmiColors[1] = 0x07e0; bi.bmiColors[2] = 0x001f; hdc = GetDC(NULL); hgxbmp = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, &gximage, NULL, 0); ReleaseDC(NULL, hdc); if (hgxbmp == NULL) { goto gxopn_err2; } ZeroMemory(gximage, gxdp.cbyPitch * gxdp.cyHeight); gxold = (SUBCLASSPROC)GetWindowLong(hWnd, GWL_WNDPROC); SetWindowLong(hWnd, GWL_WNDPROC, (LONG)gxdraw); if (GXFlag & GX_WINDOW) { setclientsize(hWnd, WINDOW_WIDTH, WINDOW_HEIGHT); } else { hTaskBar = FindWindow(taskbarclass, NULL); if (hTaskBar) { ShowWindow(hTaskBar, SW_HIDE); } winstyle = GetWindowLong(hWnd, GWL_STYLE); gxhwndstyle = winstyle; winstyleex = GetWindowLong(hWnd, GWL_EXSTYLE); gxhwndstyleex = winstyleex; winstyle &= ~(WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU); winstyle |= WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; winstyleex |= WS_EX_TOPMOST; SetWindowLong(hWnd, GWL_STYLE, winstyle); SetWindowLong(hWnd, GWL_EXSTYLE, winstyleex); SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); MoveWindow(hWnd, 0, 0, GXWidth, GXHeight, TRUE); } return(1); gxopn_err2: gxhwnd = NULL; gximage = NULL; gxopn_err1: return(0); }