#ifdef WIN_SCREENSAVER //Windows screensaver code borrowed from Rachel Grey // http://www.cityintherain.com/howtoscr.html #include <direct.h> #include <windows.h> #include <scrnsave.h> #include <GL/gl.h> //Settings dialog (includes globals) //#include <qapplication.h> //#include "SettingsDialog.h" #include "hive.h" #include "vanillahive.h" #include "settings.h" Hive* hive; //globals used by the function below to hold the screen size int Width; int Height; //Windows timer IDs #define FRAME_TIMER 1 #define EVENT_TIMER 2 static void InitGL(HWND hWnd, HDC & hDC, HGLRC & hRC) { PIXELFORMATDESCRIPTOR pfd; ZeroMemory( &pfd, sizeof pfd ); pfd.nSize = sizeof pfd; pfd.nVersion = 1; pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; hDC = GetDC( hWnd ); int i = ChoosePixelFormat( hDC, &pfd ); SetPixelFormat( hDC, i, &pfd ); hRC = wglCreateContext( hDC ); wglMakeCurrent( hDC, hRC ); } static void CloseGL(HWND hWnd, HDC hDC, HGLRC hRC) { wglMakeCurrent( NULL, NULL ); wglDeleteContext( hRC ); ReleaseDC( hWnd, hDC ); } // Screen Saver Procedure LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hDC; static HGLRC hRC; static RECT rect; int argc = 0; char** argv = 0; switch ( message ) { case WM_CREATE: // get window dimensions GetClientRect( hWnd, &rect ); Width = rect.right; Height = rect.bottom; //get configuration from config file if applicable chdir( getenv( "SystemRoot" ) ); chdir( "SYSTEM32" ); loadsettings(); if ( Width < 400 ) { //mini-preview settings settings.numbees = 12; settings.numcells = 3; settings.eventms = 1000; settings.launchdist = -5; settings.basesize = 5; settings.randsize = 1; } //set up OpenGL InitGL( hWnd, hDC, hRC ); //Initialize perspective, viewpoint, and //any objects you wish to animate hive = new VanillaHive( Width, Height ); // Initialize timers SetTimer( hWnd, FRAME_TIMER, 10, NULL ); SetTimer( hWnd, EVENT_TIMER, settings.eventms, NULL ); return 0; case WM_DESTROY: KillTimer( hWnd, FRAME_TIMER ); KillTimer( hWnd, EVENT_TIMER ); delete hive; CloseGL( hWnd, hDC, hRC ); return 0; case WM_TIMER: switch( wParam ) { case FRAME_TIMER: hive->step(); hive->paint(); SwapBuffers( hDC ); glFlush(); break; case EVENT_TIMER: hive->doEvent(); break; } return 0; //handle special keypresses case WM_KEYDOWN: switch ( wParam ) { case 'c': case 'C': //stuff would go here if C did something special //return 0; break; } case WM_KEYUP: switch ( wParam ) { case 'c': case 'C': //if C did something special, return 0 here //return 0; break; } //let the screensaver library take care of any //other messages } return DefScreenSaverProc( hWnd, message, wParam, lParam ); } BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { return true; } // needed for SCRNSAVE.LIB BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { //Notepad config "dialog" -- temporary measure //until a proper one is in place. chdir( getenv( "SystemRoot" ) ); chdir( "system32" ); loadsettings(); savesettings(); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); GetStartupInfo( &si ); si.dwFlags |= STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOWNORMAL; ZeroMemory( &pi, sizeof(pi) ); WCHAR FAR u[18]; MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, "notepad Hive.cfg", -1, u, 18 ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line). u, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { return false; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); return true; //Here's where the real dialog will go. /* chdir( getenv( "SystemRoot" ) ); chdir( "SYSTEM32" ); loadsettings(); int argc = 1; char* argv[1]; argv[0] = "Hive"; QApplication app( argc, argv ); SettingsDialog diag; app.setMainWidget( &diag ); diag.show(); return ! (app.exec() == 0); */ } #endif //WIN_SCREENSAVER
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 5901 | Sam Stafford | Extra-low-quality setting for testing. | ||
#3 | 5899 | Sam Stafford |
Pushed a little more information into Settings and made graphics quality configurable. Want to see if that makes it run better on old machines... |
||
#2 | 5898 | Sam Stafford |
Added a quick and dirty settings file, and with it, a bit of configurability. Still tweaking the numbers on maximum velocity and acceleration for the bees. |
||
#1 | 5893 | Sam Stafford | Check in work to date on "hive". | ||
//guest/sam_stafford/scenesaver/winmain.cpp | |||||
#9 | 5293 | Sam Stafford |
Quick and dirty configuration dialog to edit SceneSaver.cfg. Slightly friendlier than the Notepad gizmo. Still need to write something to help people set up Scenes.txt... |
||
#8 | 5099 | Sam Stafford |
Try to avoid clearing out the genome file if it exists but wasn't readable on startup (seems like I've gotten this to happen by hitting "Preview" in the Windows dialog while it's still loading up the mini-preview). |
||
#7 | 4707 | Sam Stafford |
Make image buffer match screen dimensions rather than first image dimensions. The first image is still used to determine the resolution. (If the first image matches the screen's dimensions, like it should, this change does nothing.) |
||
#6 | 4461 | Sam Stafford |
Change Scenesaver directory from HOMEPATH/Scenesaver to SYSTEMROOT/System32/Scenesaver. It turns out that screensavers run as user "SYSTEM", making the HOMEPATH strategy useless. Gr. |
||
#5 | 4454 | Sam Stafford |
Made "Scenesaver" the canonical capitalization throughout the output strings. Checking in a binary. |
||
#4 | 4453 | Sam Stafford |
Added screenshot feature, moved SceneSaver files to home directory rather than system directory, added code to handle invalid or missing images (loading a random color instead of crashing). I think this thing's good to go. |
||
#3 | 4451 | Sam Stafford | All significant variables are now user-tweakable. | ||
#2 | 4449 | Sam Stafford | Speed lines, toggle creatures on and off. | ||
#1 | 4448 | Sam Stafford | Turn this thing into a Windows screensaver. | ||
//guest/sam_stafford/genesaver/src/winmain.cpp | |||||
#2 | 3355 | Sam Stafford | Zoom in during preview mode so that creatures are more than one pixel wide. | ||
#1 | 3353 | Sam Stafford |
Use Windows <scrnsave.h> and OpenGL functions instead of GLUT. This should fix all sorts of bugs involving the screensaver not terminating when it should, spawning new processes, et cetera. Code shuffling to follow, since right now it's a tangled mess. |