![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
#include "video.h"#include <fcntl.h>#include <io.h>#include <iostream>#include <fstream>
Include dependency graph for winvideo.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Defines | |
| #define | _WIN32_WINNT 0x0400 |
| #define | YIELD_TO_THREAD() Sleep(0) |
Functions | |
| bool | DisplayError (LPSTR lpstrErr, HRESULT hres=0) |
| Create a dialog box and tell the user what went wrong. | |
| LRESULT CALLBACK | InternalWndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) |
| Win event processing function. | |
| static bool | loop_once (video *v) |
| static bool | RedirectIOToConsole (void) |
| create console window with redirection | |
| DWORD WINAPI | thread_video (LPVOID lpParameter) |
| bool | WinInit (HINSTANCE hInstance, int nCmdShow, WNDCLASSEX *uwc, const char *title, bool fixedsize) |
| Create window. | |
Variables | |
| static int | g_fps = 0 |
| HANDLE | g_handles [2] = {0,0} |
| HWND | g_hAppWnd |
| static DWORD | g_msec = 0 |
| unsigned int * | g_pImg = 0 |
| WNDPROC | g_pUserProc = 0 |
| int | g_sizex |
| int | g_sizey |
| static int | g_skips = 0 |
| static int | g_updates = 0 |
| static video * | g_video = 0 |
| static WNDCLASSEX * | gWndClass = 0 |
| static HACCEL | hAccelTable = 0 |
| static const WORD | MAX_CONSOLE_LINES = 500 |
| const COLORREF | RGBKEY = RGB(8, 8, 16) |
| #define _WIN32_WINNT 0x0400 |
Definition at line 37 of file winvideo.h.
| #define YIELD_TO_THREAD | ( | ) | Sleep(0) |
Definition at line 40 of file winvideo.h.
Referenced by DDColorMatch(), DestroyOverlay(), and thread_vsync().
| bool DisplayError | ( | LPSTR | lpstrErr, |
| HRESULT | hres | ||
| ) |
Definition at line 64 of file ddvideo.cpp.
References g_hAppWnd.
Referenced by DDColorMatch(), DDInit(), DDOverlayInit(), DDPrimaryInit(), DrawOverlay(), and InternalWndProc().
{
static bool InError = false;
int retval = 0;
if (!InError)
{
InError = true;
#ifdef DDSCAPS_PRIMARYSURFACELEFT
const char *message = hres?DXGetErrorString8A(hres):0;
#else
char message[256]; if(hres) D3DXGetErrorString(hres, 256, message);
#endif
retval = MessageBoxA(g_hAppWnd, lpstrErr, hres?message:"Error!", MB_OK|MB_ICONERROR);
InError = false;
}
return false;
}
| LRESULT CALLBACK InternalWndProc | ( | HWND | hwnd, |
| UINT | iMsg, | ||
| WPARAM | wParam, | ||
| LPARAM | lParam | ||
| ) |
Definition at line 355 of file ddvideo.cpp.
References CheckBoundries(), DDOverlayInit(), DDPrimaryInit(), DestroyOverlay(), DestroyPrimary(), DisplayError(), DrawOverlay(), g_dwXRatio, g_dwYRatio, g_OverlayFlags, g_OverlayFX, g_pBitmap, g_pDDSOverlay, g_pDDSPrimary, g_pUserProc, g_rcDst, g_rcSrc, g_sizex, g_sizey, g_video, L, mouse(), video::on_key(), video::on_mouse(), and video::updating.
Referenced by WinInit().
{
PAINTSTRUCT ps; // Structure for the paint message
POINT p = {0, 0}; // Translation point for the window's client region
HRESULT hRet;
switch (iMsg)
{
case WM_MOVE:
// Make sure we're not moving to be minimized - because otherwise
// our ratio varialbes (g_dwXRatio and g_dwYRatio) will end up
// being 0, and once we hit CheckBoundries it divides by 0.
if (!IsIconic(hwnd))
{
g_rcSrc.left = 0;
g_rcSrc.right = g_sizex;
g_rcSrc.top = 0;
g_rcSrc.bottom = g_sizey;
GetClientRect(hwnd, &g_rcDst);
g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 /
(g_rcSrc.right - g_rcSrc.left);
g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 /
(g_rcSrc.bottom - g_rcSrc.top);
ClientToScreen(hwnd, &p);
g_rcDst.left = p.x;
g_rcDst.top = p.y;
g_rcDst.bottom += p.y;
g_rcDst.right += p.x;
CheckBoundries();
}
else
// Else, hide the overlay... just in case we can't do
// destination color keying, this will pull the overlay
// off of the screen for the user.
if (g_pDDSOverlay && g_pDDSPrimary)
g_pDDSOverlay->UpdateOverlay(NULL, g_pDDSPrimary, NULL, DDOVER_HIDE, NULL);
// Check to make sure our window exists before we tell it to
// repaint. This will fail the first time (while the window is being created).
if (hwnd)
{
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);
}
return 0L;
case WM_SIZE:
// Another check for the minimization action. This check is
// quicker though...
if (wParam != SIZE_MINIMIZED)
{
GetClientRect(hwnd, &g_rcDst);
ClientToScreen(hwnd, &p);
g_rcDst.left = p.x;
g_rcDst.top = p.y;
g_rcDst.bottom += p.y;
g_rcDst.right += p.x;
g_rcSrc.left = 0;
g_rcSrc.right = g_sizex;
g_rcSrc.top = 0;
g_rcSrc.bottom = g_sizey;
// Here we multiply by 1000 to preserve 3 decimal places in the
// division opperation (we picked 1000 to be on the same order
// of magnitude as the stretch factor for easier comparisons)
g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 /
(g_rcSrc.right - g_rcSrc.left);
g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 /
(g_rcSrc.bottom - g_rcSrc.top);
CheckBoundries();
}
return 0L;
case WM_PAINT:
BeginPaint(hwnd, &ps);
// Check the primary surface to see if it's lost - if so you can
// pretty much bet that the other surfaces are also lost - thus
// restore EVERYTHING! If we got our surfaces stolen by a full
// screen app - then we'll destroy our primary - and won't be able
// to initialize it again. When we get our next paint message (the
// full screen app closed for example) we'll want to try to reinit
// the surfaces again - that's why there is a check for
// g_pDDSPrimary == NULL. The other option, is that our program
// went through this process, could init the primary again, but it
// couldn't init the overlay, that's why there's a third check for
// g_pDDSOverlay == NULL. Make sure that the check for
// !g_pDDSPrimary is BEFORE the IsLost call - that way if the
// pointer is NULL (ie. !g_pDDSPrimary is TRUE) - the compiler
// won't try to evaluate the IsLost function (which, since the
// g_pDDSPrimary surface is NULL, would be bad...).
if (!g_pDDSPrimary || (g_pDDSPrimary->IsLost() != DD_OK) ||
(g_pDDSOverlay == NULL))
{
DestroyOverlay();
DestroyPrimary();
if (DDPrimaryInit())
if (DDOverlayInit())
if (!DrawOverlay())
DestroyOverlay();
}
// UpdateOverlay is how we put the overlay on the screen.
if (g_pDDSOverlay && g_pDDSPrimary && g_video->updating)
{
hRet = g_pDDSOverlay->UpdateOverlay(&g_rcSrc, g_pDDSPrimary,
&g_rcDst, g_OverlayFlags,
&g_OverlayFX);
#ifdef _DEBUG
if(hRet != DD_OK) DisplayError("Can't update overlay", hRet);
#endif
}
EndPaint(hwnd, &ps);
return 0L;
// process mouse and keyboard events
case WM_LBUTTONDOWN: mouse(1, lParam); break;
case WM_LBUTTONUP: mouse(-1, lParam); break;
case WM_RBUTTONDOWN: mouse(2, lParam); break;
case WM_RBUTTONUP: mouse(-2, lParam); break;
case WM_MBUTTONDOWN: mouse(3, lParam); break;
case WM_MBUTTONUP: mouse(-3, lParam); break;
case WM_CHAR: g_video->on_key(wParam); break;
case WM_DISPLAYCHANGE: return 0L;
case WM_DESTROY:
// Now, shut down the window...
PostQuitMessage(0);
return 0L;
}
return g_pUserProc? g_pUserProc(hwnd, iMsg, wParam, lParam) : DefWindowProc(hwnd, iMsg, wParam, lParam);
}
Definition at line 200 of file winvideo.h.
References video::calc_fps, g_fps, g_hAppWnd, g_msec, g_skips, g_updates, hAccelTable, video::running, video::title, and video::updating.
{
// screen update notify
if(int updates = g_updates) {
g_updates = 0;
if(g_video->updating) { g_skips += updates-1; g_fps++; }
else g_skips += updates;
UpdateWindow(g_hAppWnd);
}
// update fps
DWORD msec = GetTickCount();
if(v->calc_fps && msec >= g_msec+1000) {
double sec = (msec - g_msec)/1000.0;
char buffer[256], n = _snprintf(buffer, 128, "%s: %d fps", v->title, int(double(g_fps + g_skips)/sec));
if(g_skips) _snprintf(buffer+n, 128, " - %d skipped = %d updates", int(g_skips/sec), int(g_fps/sec));
SetWindowTextA(g_hAppWnd, buffer);
g_msec = msec; g_skips = g_fps = 0;
}
// event processing, including painting
MSG msg;
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if( msg.message == WM_QUIT ) { v->running = false; return false; }
if( !hAccelTable || !TranslateAccelerator(msg.hwnd, hAccelTable, &msg) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return true; // try again
}
return false;
}
| static bool RedirectIOToConsole | ( | void | ) | [static] |
Definition at line 112 of file winvideo.h.
References MAX_CONSOLE_LINES.
{
int hConHandle; size_t lStdHandle;
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
// allocate a console for this app
AllocConsole();
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
// redirect unbuffered STDOUT to the console
lStdHandle = (size_t)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
if(hConHandle <= 0) return false;
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// redirect unbuffered STDERR to the console
lStdHandle = (size_t)GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
if(hConHandle > 0) {
fp = _fdopen( hConHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
}
// redirect unbuffered STDIN to the console
lStdHandle = (size_t)GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
if(hConHandle > 0) {
fp = _fdopen( hConHandle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
}
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
// point to console as well
std::ios::sync_with_stdio();
return true;
}
| DWORD WINAPI thread_video | ( | LPVOID | lpParameter | ) |
Definition at line 193 of file winvideo.h.
References video::on_process().
{
video *v = (video*)lpParameter;
v->on_process();
return 0;
}
| bool WinInit | ( | HINSTANCE | hInstance, |
| int | nCmdShow, | ||
| WNDCLASSEX * | uwc, | ||
| const char * | title, | ||
| bool | fixedsize | ||
| ) |
Definition at line 73 of file winvideo.h.
References g_hAppWnd, g_pUserProc, g_sizex, g_sizey, InternalWndProc(), and RGBKEY.
{
WNDCLASSEX wndclass; // Our app's windows class
if(uwc) {
memcpy(&wndclass, uwc, sizeof(wndclass));
g_pUserProc = uwc->lpfnWndProc;
} else {
memset(&wndclass, 0, sizeof(wndclass));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.lpszClassName = title;
}
wndclass.cbSize = sizeof(wndclass);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = InternalWndProc;
wndclass.style |= CS_HREDRAW | CS_VREDRAW;
wndclass.hbrBackground = CreateSolidBrush(RGBKEY);
if( !RegisterClassExA(&wndclass) ) return false;
int xaddend = GetSystemMetrics(fixedsize?SM_CXFIXEDFRAME:SM_CXFRAME)*2;
int yaddend = GetSystemMetrics(fixedsize?SM_CYFIXEDFRAME:SM_CYFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
if(wndclass.lpszMenuName) yaddend += GetSystemMetrics(SM_CYMENU);
// Setup the new window's physical parameters - and tell Windows to create it
g_hAppWnd = CreateWindowA(wndclass.lpszClassName, // Window class name
title, // Window caption
!fixedsize ? WS_OVERLAPPEDWINDOW : // Window style
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
CW_USEDEFAULT, // Initial x pos: use default placement
0, // Initial y pos: not used here
g_sizex+xaddend,// Initial x size
g_sizey+yaddend,// Initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // Creation parameters
return g_hAppWnd != NULL;
}
int g_fps = 0 [static] |
Definition at line 67 of file winvideo.h.
Referenced by loop_once().
| HANDLE g_handles[2] = {0,0} |
Definition at line 57 of file winvideo.h.
| HWND g_hAppWnd |
Definition at line 56 of file winvideo.h.
Referenced by CheckBoundries(), DDInit(), DisplayError(), DrawOverlay(), loop_once(), and WinInit().
DWORD g_msec = 0 [static] |
Definition at line 66 of file winvideo.h.
Referenced by loop_once().
| unsigned int* g_pImg = 0 |
Definition at line 58 of file winvideo.h.
| WNDPROC g_pUserProc = 0 |
Definition at line 61 of file winvideo.h.
Referenced by InternalWndProc(), and WinInit().
| int g_sizex |
Definition at line 59 of file winvideo.h.
| int g_sizey |
Definition at line 59 of file winvideo.h.
| int g_skips = 0 |
Definition at line 67 of file winvideo.h.
Referenced by loop_once().
| int g_updates = 0 |
Definition at line 67 of file winvideo.h.
Referenced by loop_once().
Definition at line 60 of file winvideo.h.
WNDCLASSEX* gWndClass = 0 [static] |
Definition at line 64 of file winvideo.h.
HACCEL hAccelTable = 0 [static] |
Definition at line 65 of file winvideo.h.
Referenced by loop_once().
const WORD MAX_CONSOLE_LINES = 500 [static] |
Definition at line 54 of file winvideo.h.
Referenced by RedirectIOToConsole().
| const COLORREF RGBKEY = RGB(8, 8, 16) |
Definition at line 55 of file winvideo.h.
Referenced by DrawOverlay(), and WinInit().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.