|
From: <cad...@li...> - 2006-04-10 02:08:00
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns=3D"http://www.w3.org/1999/xhtml"> <head><style type=3D"text/css"><!-- body {background:#ffffff;font-family:Verdana,Helvetica,Arial,sans-serif;} h3 {margin:15px 0;padding:0;line-height:0;} #msg {margin: 0 0 2em 0;} #msg dl, #msg ul, #msg pre {padding:1em;border:1px dashed black;margin: 1= 0px 0 30px 0;} #msg dl {background:#ccccff;} #msg pre {background:#ffffcc;} #msg ul {background:#cc99ff;list-style:none;} #msg dt {font-weight:bold;float:left;width: 6em;} #msg dt:after { content:':';} #patch h4 {padding: 0 10px;line-height:1.5em;margin:0;background:#ccffff;= border-bottom:1px solid black;margin:0 0 10px 0;} #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patc= h .binary {border:1px solid black;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} --></style> <title>[307] tiki/win32/src: tiki: fix inconsistent line endings in win32= sources</title> </head> <body> <div id=3D"msg"> <dl> <dt>Revision</dt> <dd>307</dd> <dt>Author</dt> <dd>bard</dd> <dt>Date</dt> <dd>2006-03-26 16:14:11 -0800 (Sun, 26 Mar 2006)</dd> </dl> <h3>Log Message</h3> <pre>tiki: fix inconsistent line endings in win32 sources</pre> <h3>Modified Paths</h3> <ul> <li><a href=3D"#tikiwin32includeTikiglhdrsh">tiki/win32/include/Tiki/glhd= rs.h</a></li> <li><a href=3D"#tikiwin32includepchh">tiki/win32/include/pch.h</a></li> <li><a href=3D"#tikiwin32srcinit_shutdowncpp">tiki/win32/src/init_shutdow= n.cpp</a></li> <li><a href=3D"#tikiwin32srcplatglcpp">tiki/win32/src/platgl.cpp</a></li> </ul> </div> <div id=3D"patch"> <h3>Diff</h3> <a id=3D"tikiwin32includeTikiglhdrsh"></a> <div class=3D"modfile"><h4>Modified: tiki/win32/include/Tiki/glhdrs.h (30= 6 =3D> 307)</h4> <pre class=3D"diff"> <span class=3D"info">--- tiki/win32/include/Tiki/glhdrs.h 2006-02-19 21:3= 6:15 UTC (rev 306) +++ tiki/win32/include/Tiki/glhdrs.h 2006-03-27 00:14:11 UTC (rev 307) </span><span class=3D"lines">@@ -1,12 +1,12 @@ </span><span class=3D"rem">-#pragma once - </span><span class=3D"add">+#pragma once + </span><span class=3D"cx"> #include <windows.h> </span><span class=3D"rem">- -#include <GL/gl.h> -#include <GL/glu.h> - -namespace Tiki { - HWND GetWin32Window(); -}; - - </span><span class=3D"add">+ +#include <GL/gl.h> +#include <GL/glu.h> + +namespace Tiki { + HWND GetWin32Window(); +}; + + </span></pre></div> <a id=3D"tikiwin32includepchh"></a> <div class=3D"modfile"><h4>Modified: tiki/win32/include/pch.h (306 =3D> 3= 07)</h4> <pre class=3D"diff"> <span class=3D"info">--- tiki/win32/include/pch.h 2006-02-19 21:36:15 UTC= (rev 306) +++ tiki/win32/include/pch.h 2006-03-27 00:14:11 UTC (rev 307) </span><span class=3D"lines">@@ -1,36 +1,36 @@ </span><span class=3D"rem">-// stdafx.h : include file for standard syste= m include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows h= eaders - -#ifndef VC_EXTRALEAN -#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers -#endif - </span><span class=3D"add">+// stdafx.h : include file for standard syste= m include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows h= eaders + +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers +#endif + </span><span class=3D"cx"> #include <windows.h> </span><span class=3D"rem">-#include <shellapi.h> - -#define _USE_MATH_DEFINES -#include <math.h> - -// This header does most of the useful work for bringing in stuff. -#include "Tiki/tiki.h" - -// Don't bother with namespace poo inside the framework itself. -using namespace Tiki; - -// This is the hand-off point in the library from WinMain, and HID callb= acks. -namespace Tiki { - int DoMain(const char * szAppName, HINSTANCE hInst, HINSTANCE hPrevInst= ance, LPSTR lpCmdLine, int nCmdShow); - void RecvQuit(); - void RecvEvent(UINT iMsg, WPARAM wParam, LPARAM lParam); -} - -// Packed structs need some compiler-specific foo. -#define PACKED_STRUCT_BEGIN #pragma pack(push, 1) -#define PACKED_STRUCT_END #pragma pack(pop) -#define PACKED_STRUCT_MEMBER </span><span class=3D"add">+#include <shellapi.h> + +#define _USE_MATH_DEFINES +#include <math.h> + +// This header does most of the useful work for bringing in stuff. +#include "Tiki/tiki.h" + +// Don't bother with namespace poo inside the framework itself. +using namespace Tiki; + +// This is the hand-off point in the library from WinMain, and HID callb= acks. +namespace Tiki { + int DoMain(const char * szAppName, HINSTANCE hInst, HINSTANCE hPrevInst= ance, LPSTR lpCmdLine, int nCmdShow); + void RecvQuit(); + void RecvEvent(UINT iMsg, WPARAM wParam, LPARAM lParam); +} + +// Packed structs need some compiler-specific foo. +#define PACKED_STRUCT_BEGIN #pragma pack(push, 1) +#define PACKED_STRUCT_END #pragma pack(pop) +#define PACKED_STRUCT_MEMBER </span></pre></div> <a id=3D"tikiwin32srcinit_shutdowncpp"></a> <div class=3D"modfile"><h4>Modified: tiki/win32/src/init_shutdown.cpp (30= 6 =3D> 307)</h4> <pre class=3D"diff"> <span class=3D"info">--- tiki/win32/src/init_shutdown.cpp 2006-02-19 21:3= 6:15 UTC (rev 306) +++ tiki/win32/src/init_shutdown.cpp 2006-03-27 00:14:11 UTC (rev 307) </span><span class=3D"lines">@@ -1,45 +1,45 @@ </span><span class=3D"rem">-#include "pch.h" - -#include "Tiki/plxcompat.h" -#include "Tiki/hid.h" -#include "Tiki/sound.h" -#include "Tiki/stream.h" - -#include <al.h> -#include <alut.h> - -#include <MMSystem.h> -#pragma comment(lib, "winmm.lib") -#pragma comment(lib, "ALut.lib") -#pragma comment(lib, "OpenAL32.lib") - -bool Tiki::init(int argc, char **argv) { - // Let us run with millisecond precision if possible. - timeBeginPeriod(1); - - alutInit(&argc, argv); - Audio::Stream::initGlobal(); - Audio::Sound::initGlobal(); - - GL::Plxcompat::plx_mat3d_init(640, 480); - Hid::init(); - - return true; -} - -void Tiki::shutdown() { - Hid::shutdown(); - Audio::Sound::shutdownGlobal(); - Audio::Stream::shutdownGlobal(); - alutExit(); - - timeEndPeriod(1); -} </span><span class=3D"add">+#include "pch.h" </span><span class=3D"cx">=20 </span><span class=3D"add">+#include "Tiki/plxcompat.h" +#include "Tiki/hid.h" +#include "Tiki/sound.h" +#include "Tiki/stream.h" + +#include <al.h> +#include <alut.h> + +#include <MMSystem.h> +#pragma comment(lib, "winmm.lib") +#pragma comment(lib, "ALut.lib") +#pragma comment(lib, "OpenAL32.lib") + +bool Tiki::init(int argc, char **argv) { + // Let us run with millisecond precision if possible. + timeBeginPeriod(1); + + alutInit(&argc, argv); + Audio::Stream::initGlobal(); + Audio::Sound::initGlobal(); + + GL::Plxcompat::plx_mat3d_init(640, 480); + Hid::init(); + + return true; +} + +void Tiki::shutdown() { + Hid::shutdown(); + Audio::Sound::shutdownGlobal(); + Audio::Stream::shutdownGlobal(); + alutExit(); + + timeEndPeriod(1); +} + </span><span class=3D"cx"> void Tiki::setName(const char *name, const cha= r *icon) { SetWindowText(Tiki::GetWin32Window(), name); } =20 void Tiki::GL::showCursor(bool visible) { =20 </span><span class=3D"rem">-} </span><span class=3D"add">+} </span></pre></div> <a id=3D"tikiwin32srcplatglcpp"></a> <div class=3D"modfile"><h4>Modified: tiki/win32/src/platgl.cpp (306 =3D> = 307)</h4> <pre class=3D"diff"> <span class=3D"info">--- tiki/win32/src/platgl.cpp 2006-02-19 21:36:15 UT= C (rev 306) +++ tiki/win32/src/platgl.cpp 2006-03-27 00:14:11 UTC (rev 307) </span><span class=3D"lines">@@ -1,244 +1,244 @@ </span><span class=3D"rem">-/* - Tiki - - platgl.cpp - - Copyright (C)2005 Cryptic Allusion, LLC - - Most of this file is code created by Brian Peek for TikiTest. - -*/ - -#include "pch.h" -#include "Tiki/glhdrs.h" -#include "Tiki/hid.h" -#include "Tiki/tikitime.h" </span><span class=3D"add">+/* + Tiki + + platgl.cpp + + Copyright (C)2005 Cryptic Allusion, LLC + + Most of this file is code created by Brian Peek for TikiTest. + +*/ + +#include "pch.h" +#include "Tiki/glhdrs.h" +#include "Tiki/hid.h" +#include "Tiki/tikitime.h" </span><span class=3D"cx"> #include "Tiki/gl.h" </span><span class=3D"rem">- -#pragma comment(lib, "shell32.lib") -#pragma comment(lib, "opengl32.lib") -#pragma comment(lib, "glu32.lib") - -using namespace Tiki::Hid; - -// Windows globals -static HWND m_hWndMain; -static HINSTANCE m_hInstance; -static HGLRC m_hrc; -static DWORD m_dwThreadID; -static HANDLE m_hThread; -static HDC m_hThreadDc; - -static int m_targetFrameRate =3D 60, m_targetW =3D 640, m_targetH =3D 48= 0; - -typedef int (APIENTRY * PFNWGLSWAPINTERVALEXTPROC)(int interval); -static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT =3D NULL; -typedef int (APIENTRY * PFNWGLGETSWAPINTERVALEXTPROC)(void); -static PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT =3D NULL; - -extern "C" int tiki_main(int argc, char **argv); - -// Forward decls -namespace Tiki { - LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lP= aram); - - BOOL InitApplication(); - BOOL DestroyApplication(); - BOOL ErrorBox(LPCTSTR lpText); - DWORD WINAPI GameThread(void *obj); - void OnSize(WORD cx, WORD cy); </span><span class=3D"add">+ +#pragma comment(lib, "shell32.lib") +#pragma comment(lib, "opengl32.lib") +#pragma comment(lib, "glu32.lib") + +using namespace Tiki::Hid; + +// Windows globals +static HWND m_hWndMain; +static HINSTANCE m_hInstance; +static HGLRC m_hrc; +static DWORD m_dwThreadID; +static HANDLE m_hThread; +static HDC m_hThreadDc; + +static int m_targetFrameRate =3D 60, m_targetW =3D 640, m_targetH =3D 48= 0; + +typedef int (APIENTRY * PFNWGLSWAPINTERVALEXTPROC)(int interval); +static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT =3D NULL; +typedef int (APIENTRY * PFNWGLGETSWAPINTERVALEXTPROC)(void); +static PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT =3D NULL; + +extern "C" int tiki_main(int argc, char **argv); + +// Forward decls +namespace Tiki { + LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lP= aram); + + BOOL InitApplication(); + BOOL DestroyApplication(); + BOOL ErrorBox(LPCTSTR lpText); + DWORD WINAPI GameThread(void *obj); + void OnSize(WORD cx, WORD cy); </span><span class=3D"cx"> } </span><span class=3D"rem">- -HWND Tiki::GetWin32Window() -{ - return m_hWndMain; -} - -//////////////////////////////////// -// Tiki::DoMain -// initialization -//////////////////////////////////// -int Tiki::DoMain(const char * szAppName, HINSTANCE hInst, HINSTANCE hPre= vInstance, LPSTR lpCmdLine, int nCmdShow) -{ - MSG msg; - WNDCLASSEX wc; </span><span class=3D"add">+ +HWND Tiki::GetWin32Window() +{ + return m_hWndMain; +} + +//////////////////////////////////// +// Tiki::DoMain +// initialization +//////////////////////////////////// +int Tiki::DoMain(const char * szAppName, HINSTANCE hInst, HINSTANCE hPre= vInstance, LPSTR lpCmdLine, int nCmdShow) +{ + MSG msg; + WNDCLASSEX wc; </span><span class=3D"cx"> RECT WindowRect; // Grabs Rectangle Upper= Left / Lower Right Values WindowRect.left=3D(long)0; // Set Left Value To 0 WindowRect.right=3D(long)m_targetW; // Set Right Value To Requested Wi= dth WindowRect.top=3D(long)0; // Set Top Value To 0 </span><span class=3D"rem">- WindowRect.bottom=3D(long)m_targetH; // Set= Bottom Value To Requested Height - m_hInstance =3D hInst; - - wc.cbSize =3D sizeof(wc); - wc.style =3D CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc =3D (WNDPROC)WndProc; - wc.cbClsExtra =3D 0; - wc.cbWndExtra =3D 0; - wc.hInstance =3D hInst; - wc.hIcon =3D LoadIcon(hInst, IDI_APPLICATION); - wc.hCursor =3D LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground =3D (HBRUSH)(COLOR_WINDOW+1); - wc.lpszMenuName =3D NULL; - wc.lpszClassName =3D szAppName; - wc.hIconSm =3D LoadIcon(m_hInstance, IDI_APPLICATION); - - if(!RegisterClassEx(&wc)) - return FALSE; - - AdjustWindowRect(&WindowRect, WS_OVERLAPPEDWINDOW, FALSE); - - m_hWndMain =3D CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, = 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top,= NULL, NULL, m_hInstance, NULL); - - if(!m_hWndMain) - return FALSE; - - if(!InitApplication()) - return FALSE; - - ShowWindow(m_hWndMain, nCmdShow); - - m_hThread =3D CreateThread(NULL, 0, GameThread, lpCmdLine, 0, &m_dw= ThreadID); - - while(GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - return (int)msg.wParam; -} - -//////////////////////////////////// -// WndProc -// Messages for our window are handled here -//////////////////////////////////// -LRESULT CALLBACK Tiki::WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPAR= AM lParam) -{ - switch(iMsg) - { - case WM_KEYDOWN: - case WM_KEYUP: - case WM_MOUSEMOVE: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - Tiki::RecvEvent(iMsg, wParam, lParam); - break; - - case WM_DESTROY: - Tiki::RecvQuit(); - DestroyApplication(); - PostQuitMessage(0); - break; - - default: - return DefWindowProc(hWnd, iMsg, wParam, lParam); - } - return 0L; -} - -BOOL Tiki::InitApplication() -{ - HDC hdc =3D GetDC(m_hWndMain); - - // Fill in a pixel format descriptor. - PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(pfd)); - pfd.nSize =3D sizeof(pfd); - pfd.nVersion =3D 1; - pfd.dwFlags =3D PFD_DOUBLEBUFFER | - PFD_SUPPORT_OPENGL | - PFD_DRAW_TO_WINDOW | - PFD_GENERIC_ACCELERATED; - pfd.iPixelType =3D PFD_TYPE_RGBA; - pfd.cColorBits =3D 24; - pfd.cDepthBits =3D 32; - pfd.iLayerType =3D PFD_MAIN_PLANE; - int chosen =3D ChoosePixelFormat(hdc, &pfd); - - // Check to see if we got accelerated. - memset(&pfd, 0, sizeof(pfd)); - pfd.nSize =3D sizeof(pfd); - DescribePixelFormat(hdc, chosen, sizeof(pfd), &pfd); - if (pfd.dwFlags & PFD_GENERIC_FORMAT) { - MessageBox(NULL, "No accelerated GL seems to be available.",= "Error", MB_ICONERROR | MB_OK); - // return FALSE; - } - - // Set the format into the DC. - if (!SetPixelFormat(hdc, chosen, &pfd)) { - ErrorBox("Couldn't set pixel format into DC."); - return FALSE; - } - - // Create rendering context to use. - HGLRC hrc =3D wglCreateContext(hdc); - if (!hrc) { - ErrorBox("Couldn't create WGL context."); - return FALSE; - } - m_hrc =3D hrc; - - // Make the context current so we can do some twiddling. - wglMakeCurrent(hdc, m_hrc); - - // Query for the swap interval extensions. - wglGetSwapIntervalEXT =3D (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddre= ss("wglGetSwapIntervalEXT"); - wglSwapIntervalEXT =3D (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress(&qu= ot;wglSwapIntervalEXT"); - - // If we got the Get function, display the old sync setting. - if (wglGetSwapIntervalEXT) { - Debug::printf("Vertical sync state was %d\n", wglGetSwapInte= rvalEXT()); - } else { - Debug::printf("WARNING! wglGetSwapIntervalEXT is NULL\n"); - } - - // If we got the Set function, change sync to OFF. It causes big proble= ms on - // nVidia cards. - if (wglSwapIntervalEXT) { - Debug::printf("Turning off vertical sync\n"); - wglSwapIntervalEXT(0); - } else { - Debug::printf("WARNING! wglSwapIntervalEXT is NULL\n"); - } - - // Turn off the context and release the DC. - wglMakeCurrent(NULL, NULL); - ReleaseDC(m_hWndMain, hdc); - - return TRUE; -} - -BOOL Tiki::DestroyApplication() -{ - if(WaitForSingleObject(m_hThread, INFINITE) !=3D WAIT_OBJECT_0) - ErrorBox("Couldn't wait for game thread to terminate."); - - if(!CloseHandle(m_hThread)) - ErrorBox("Couldn't terminate game thread."); - - Tiki::shutdown(); - - return TRUE; -} - -BOOL Tiki::ErrorBox(LPCTSTR lpText) -{ - MessageBox(m_hWndMain, lpText, "Error", MB_ICONERROR); - return FALSE; -} - -DWORD WINAPI Tiki::GameThread(void *obj) -{ </span><span class=3D"add">+ WindowRect.bottom=3D(long)m_targetH; // Set= Bottom Value To Requested Height + m_hInstance =3D hInst; + + wc.cbSize =3D sizeof(wc); + wc.style =3D CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc =3D (WNDPROC)WndProc; + wc.cbClsExtra =3D 0; + wc.cbWndExtra =3D 0; + wc.hInstance =3D hInst; + wc.hIcon =3D LoadIcon(hInst, IDI_APPLICATION); + wc.hCursor =3D LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground =3D (HBRUSH)(COLOR_WINDOW+1); + wc.lpszMenuName =3D NULL; + wc.lpszClassName =3D szAppName; + wc.hIconSm =3D LoadIcon(m_hInstance, IDI_APPLICATION); + + if(!RegisterClassEx(&wc)) + return FALSE; + + AdjustWindowRect(&WindowRect, WS_OVERLAPPEDWINDOW, FALSE); + + m_hWndMain =3D CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, = 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top,= NULL, NULL, m_hInstance, NULL); + + if(!m_hWndMain) + return FALSE; + + if(!InitApplication()) + return FALSE; + + ShowWindow(m_hWndMain, nCmdShow); + + m_hThread =3D CreateThread(NULL, 0, GameThread, lpCmdLine, 0, &m_dw= ThreadID); + + while(GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return (int)msg.wParam; +} + +//////////////////////////////////// +// WndProc +// Messages for our window are handled here +//////////////////////////////////// +LRESULT CALLBACK Tiki::WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPAR= AM lParam) +{ + switch(iMsg) + { + case WM_KEYDOWN: + case WM_KEYUP: + case WM_MOUSEMOVE: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + Tiki::RecvEvent(iMsg, wParam, lParam); + break; + + case WM_DESTROY: + Tiki::RecvQuit(); + DestroyApplication(); + PostQuitMessage(0); + break; + + default: + return DefWindowProc(hWnd, iMsg, wParam, lParam); + } + return 0L; +} + +BOOL Tiki::InitApplication() +{ + HDC hdc =3D GetDC(m_hWndMain); + + // Fill in a pixel format descriptor. + PIXELFORMATDESCRIPTOR pfd; + memset(&pfd, 0, sizeof(pfd)); + pfd.nSize =3D sizeof(pfd); + pfd.nVersion =3D 1; + pfd.dwFlags =3D PFD_DOUBLEBUFFER | + PFD_SUPPORT_OPENGL | + PFD_DRAW_TO_WINDOW | + PFD_GENERIC_ACCELERATED; + pfd.iPixelType =3D PFD_TYPE_RGBA; + pfd.cColorBits =3D 24; + pfd.cDepthBits =3D 32; + pfd.iLayerType =3D PFD_MAIN_PLANE; + int chosen =3D ChoosePixelFormat(hdc, &pfd); + + // Check to see if we got accelerated. + memset(&pfd, 0, sizeof(pfd)); + pfd.nSize =3D sizeof(pfd); + DescribePixelFormat(hdc, chosen, sizeof(pfd), &pfd); + if (pfd.dwFlags & PFD_GENERIC_FORMAT) { + MessageBox(NULL, "No accelerated GL seems to be available.",= "Error", MB_ICONERROR | MB_OK); + // return FALSE; + } + + // Set the format into the DC. + if (!SetPixelFormat(hdc, chosen, &pfd)) { + ErrorBox("Couldn't set pixel format into DC."); + return FALSE; + } + + // Create rendering context to use. + HGLRC hrc =3D wglCreateContext(hdc); + if (!hrc) { + ErrorBox("Couldn't create WGL context."); + return FALSE; + } + m_hrc =3D hrc; + + // Make the context current so we can do some twiddling. + wglMakeCurrent(hdc, m_hrc); + + // Query for the swap interval extensions. + wglGetSwapIntervalEXT =3D (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddre= ss("wglGetSwapIntervalEXT"); + wglSwapIntervalEXT =3D (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress(&qu= ot;wglSwapIntervalEXT"); + + // If we got the Get function, display the old sync setting. + if (wglGetSwapIntervalEXT) { + Debug::printf("Vertical sync state was %d\n", wglGetSwapInte= rvalEXT()); + } else { + Debug::printf("WARNING! wglGetSwapIntervalEXT is NULL\n"); + } + + // If we got the Set function, change sync to OFF. It causes big proble= ms on + // nVidia cards. + if (wglSwapIntervalEXT) { + Debug::printf("Turning off vertical sync\n"); + wglSwapIntervalEXT(0); + } else { + Debug::printf("WARNING! wglSwapIntervalEXT is NULL\n"); + } + + // Turn off the context and release the DC. + wglMakeCurrent(NULL, NULL); + ReleaseDC(m_hWndMain, hdc); + + return TRUE; +} + +BOOL Tiki::DestroyApplication() +{ + if(WaitForSingleObject(m_hThread, INFINITE) !=3D WAIT_OBJECT_0) + ErrorBox("Couldn't wait for game thread to terminate."); + + if(!CloseHandle(m_hThread)) + ErrorBox("Couldn't terminate game thread."); + + Tiki::shutdown(); + + return TRUE; +} + +BOOL Tiki::ErrorBox(LPCTSTR lpText) +{ + MessageBox(m_hWndMain, lpText, "Error", MB_ICONERROR); + return FALSE; +} + +DWORD WINAPI Tiki::GameThread(void *obj) +{ </span><span class=3D"cx"> Debug::printf( "GameThread beginning\n&q= uot; ); </span><span class=3D"rem">- - // Set up our GL context so that texture loading and such works as well= . - m_hThreadDc =3D GetDC(m_hWndMain); - wglMakeCurrent(m_hThreadDc, m_hrc); </span><span class=3D"cx">=20 </span><span class=3D"add">+ // Set up our GL context so that texture loa= ding and such works as well. + m_hThreadDc =3D GetDC(m_hWndMain); + wglMakeCurrent(m_hThreadDc, m_hrc); + </span><span class=3D"cx"> int argc =3D 0; LPWSTR *args =3D CommandLineToArgvW(GetCommandLineW(), &argc); // if we have 1 or more command line args, pass it down nicely to tiki_= main </span><span class=3D"lines">@@ -251,7 +251,7 @@ </span><span class=3D"cx"> sprintf(argv[i], "%ws", = args[i]); } LocalFree(args); </span><span class=3D"rem">- </span><span class=3D"add">+ </span><span class=3D"cx"> tiki_main(argc, argv); =20 // cleanup allocated memory for cmd line args </span><span class=3D"lines">@@ -265,87 +265,87 @@ </span><span class=3D"cx"> { tiki_main(0, NULL); } </span><span class=3D"rem">- - ReleaseDC(m_hWndMain, m_hThreadDc); - m_hThreadDc =3D NULL; - - Debug::printf( "GameThread exiting\n" ); - return 0; -} - - -static uint64 lastFrame =3D 0; -static uint64 firstFrame =3D 0; -static uint64 frameCnt =3D 0, totalFrameCnt =3D 0; - -float Tiki::GL::Frame::getFrameRate() { - uint64 cur =3D Tiki::Time::gettime(); - - // Avoid divzero - if (cur =3D=3D firstFrame) - return 0.0f; - - return (float)((frameCnt * 1000000.0) / (cur - firstFrame)); -} - -void Tiki::GL::Frame::setFrameRateLimit(int rate) { - m_targetFrameRate =3D rate; -} - -extern "C" void tiki_scene_begin_hook() { - // Set up our GL context for painting. - wglMakeCurrent(m_hThreadDc, m_hrc); - - // Every so often we should reset the frame counters, to avoid - // having a super long term averaging effect. - if (frameCnt >=3D 500) { - firstFrame =3D 0; - frameCnt =3D 0; - } - - // Update frame counters. - if (!firstFrame) - firstFrame =3D Tiki::Time::gettime(); - frameCnt++; - totalFrameCnt++; - -#ifdef _DEBUG - if (frameCnt && !(frameCnt % 250)) { - Debug::printf("frame %d, fps =3D %.2f\n", (int)frameCnt, - (double)Tiki::GL::Frame::getFrameRate()); - } -#endif - - if (lastFrame =3D=3D 0) { - lastFrame =3D Tiki::Time::gettime(); - return; - } - - uint64 now; - now =3D Tiki::Time::gettime(); - uint64 diff =3D now - lastFrame; - if (diff < (1000*1000 / m_targetFrameRate)) { - Tiki::Time::sleep((1000*1000 / m_targetFrameRate) - diff); - } - lastFrame =3D Tiki::Time::gettime(); -} - -extern "C" void tiki_scene_finish_hook() { - // Flush any remaining GL commands and swap buffers. - glFlush(); - SwapBuffers(m_hThreadDc); - - // Deactivate GL context. - // NOTE: We do NOT do this because otherwise a lot of stuff done outsid= e - // the frame proper e.g. loading textures will not work. - // wglMakeCurrent(NULL, NULL); -} - - - - - - - - - </span><span class=3D"add">+ + ReleaseDC(m_hWndMain, m_hThreadDc); + m_hThreadDc =3D NULL; + + Debug::printf( "GameThread exiting\n" ); + return 0; +} + + +static uint64 lastFrame =3D 0; +static uint64 firstFrame =3D 0; +static uint64 frameCnt =3D 0, totalFrameCnt =3D 0; + +float Tiki::GL::Frame::getFrameRate() { + uint64 cur =3D Tiki::Time::gettime(); + + // Avoid divzero + if (cur =3D=3D firstFrame) + return 0.0f; + + return (float)((frameCnt * 1000000.0) / (cur - firstFrame)); +} + +void Tiki::GL::Frame::setFrameRateLimit(int rate) { + m_targetFrameRate =3D rate; +} + +extern "C" void tiki_scene_begin_hook() { + // Set up our GL context for painting. + wglMakeCurrent(m_hThreadDc, m_hrc); + + // Every so often we should reset the frame counters, to avoid + // having a super long term averaging effect. + if (frameCnt >=3D 500) { + firstFrame =3D 0; + frameCnt =3D 0; + } + + // Update frame counters. + if (!firstFrame) + firstFrame =3D Tiki::Time::gettime(); + frameCnt++; + totalFrameCnt++; + +#ifdef _DEBUG + if (frameCnt && !(frameCnt % 250)) { + Debug::printf("frame %d, fps =3D %.2f\n", (int)frameCnt, + (double)Tiki::GL::Frame::getFrameRate()); + } +#endif + + if (lastFrame =3D=3D 0) { + lastFrame =3D Tiki::Time::gettime(); + return; + } + + uint64 now; + now =3D Tiki::Time::gettime(); + uint64 diff =3D now - lastFrame; + if (diff < (1000*1000 / m_targetFrameRate)) { + Tiki::Time::sleep((1000*1000 / m_targetFrameRate) - diff); + } + lastFrame =3D Tiki::Time::gettime(); +} + +extern "C" void tiki_scene_finish_hook() { + // Flush any remaining GL commands and swap buffers. + glFlush(); + SwapBuffers(m_hThreadDc); + + // Deactivate GL context. + // NOTE: We do NOT do this because otherwise a lot of stuff done outsid= e + // the frame proper e.g. loading textures will not work. + // wglMakeCurrent(NULL, NULL); +} + + + + + + + + + </span> </pre> </div> </div> </body> </html> |