Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
winsys.cpp File Reference
#include "config.h"
#include "gl_globals.h"
#include "winsys.h"
#include "vs_globals.h"
#include "xml_support.h"
#include "config_xml.h"
#include <assert.h>
#include <sstream>

Go to the source code of this file.

Functions

void winsys_post_redisplay ()
 
void winsys_set_display_func (winsys_display_func_t func)
 
void winsys_set_idle_func (winsys_idle_func_t func)
 
void winsys_set_reshape_func (winsys_reshape_func_t func)
 
char AdjustKeyCtrl (char ch)
 
static void glut_keyboard_cb (unsigned char ch, int x, int y)
 
static void glut_special_cb (int key, int x, int y)
 
static void glut_keyboard_up_cb (unsigned char ch, int x, int y)
 
static void glut_special_up_cb (int key, int x, int y)
 
void winsys_set_keyboard_func (winsys_keyboard_func_t func)
 
void winsys_set_mouse_func (winsys_mouse_func_t func)
 
void winsys_set_motion_func (winsys_motion_func_t func)
 
void winsys_set_passive_motion_func (winsys_motion_func_t func)
 
void winsys_swap_buffers ()
 
void winsys_warp_pointer (int x, int y)
 
void winsys_init (int *argc, char **argv, char const *window_title, char const *icon_title)
 
void winsys_shutdown ()
 
void winsys_enable_key_repeat (bool enabled)
 
void winsys_show_cursor (bool visible)
 
void winsys_process_events ()
 
void winsys_atexit (winsys_atexit_func_t func)
 
void winsys_exit (int code)
 

Variables

static winsys_keyboard_func_t keyboard_func = NULL
 
static bool redisplay = false
 

Function Documentation

char AdjustKeyCtrl ( char  ch)

Definition at line 616 of file winsys.cpp.

Referenced by glut_keyboard_cb(), and glut_keyboard_up_cb().

617 {
618  if (ch == '\0') {
619  ch = '2';
620  } else if (ch >= '0' && ch <= '9') {} else if (ch >= 27 && ch <= 31) {
621  ch = ch+'0'-24;
622  } else if (ch == 127) {
623  ch = '8';
624  } else if (ch <= 26) {
625  ch += 'a'-1;
626  }
627  return ch;
628 }
static void glut_keyboard_cb ( unsigned char  ch,
int  x,
int  y 
)
static

Definition at line 631 of file winsys.cpp.

References AdjustKeyCtrl(), VSFileSystem::vs_dprintf(), x, and y.

Referenced by winsys_process_events().

632 {
633  if (keyboard_func) {
634  int gm = glutGetModifiers();
635  if (gm)
636  VSFileSystem::vs_dprintf('3', "Down Modifier %d for char %d %c\n", gm, (int) ch, ch );
637  if (gm&GLUT_ACTIVE_CTRL)
638  ch = AdjustKeyCtrl( ch );
639  (*keyboard_func)(ch, gm, false, x, y);
640  }
641 }
static void glut_keyboard_up_cb ( unsigned char  ch,
int  x,
int  y 
)
static

Definition at line 649 of file winsys.cpp.

References AdjustKeyCtrl(), VSFileSystem::vs_dprintf(), x, and y.

Referenced by winsys_process_events().

650 {
651  if (keyboard_func) {
652  int gm = glutGetModifiers();
653  if (gm)
654  VSFileSystem::vs_dprintf('3',"Up Modifier %d for char %d %c\n", gm, (int) ch, ch );
655  if (gm&GLUT_ACTIVE_CTRL)
656  ch = AdjustKeyCtrl( ch );
657  (*keyboard_func)(ch, gm, true, x, y);
658  }
659 }
static void glut_special_cb ( int  key,
int  x,
int  y 
)
static

Definition at line 643 of file winsys.cpp.

References x, and y.

Referenced by winsys_process_events().

644 {
645  if (keyboard_func)
646  (*keyboard_func)(key+128, glutGetModifiers(), false, x, y);
647 }
static void glut_special_up_cb ( int  key,
int  x,
int  y 
)
static

Definition at line 661 of file winsys.cpp.

References x, and y.

Referenced by winsys_process_events().

662 {
663  if (keyboard_func)
664  (*keyboard_func)(key+128, glutGetModifiers(), true, x, y);
665 }
void winsys_atexit ( winsys_atexit_func_t  func)

Sets the function to be called when program ends. Note that this function should only be called once.

Author
jfpatry
Date
Created: 2000-10-20
Modified: 2000-10-20

Definition at line 867 of file winsys.cpp.

References VSFileSystem::vs_fprintf().

868 {
869  static bool called = false;
870  if (called)
871  VSFileSystem::vs_fprintf( stderr, "winsys_atexit called twice\n" );
872  called = true;
873 
874  //atexit(func);
875 }
void winsys_enable_key_repeat ( bool  enabled)

Enables/disables key repeat messages from being generated

Returns
Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 817 of file winsys.cpp.

Referenced by GFXInit().

818 {
819  glutIgnoreKeyRepeat( !enabled );
820 }
void winsys_exit ( int  code)

Exits the program

Author
jfpatry
Date
Created: 2000-10-20
Modified: 2000-10-20

Definition at line 884 of file winsys.cpp.

References winsys_shutdown().

Referenced by bootstrap_main_loop(), Mission::DirectorBenchmark(), main(), GameMenu::processExitGameButton(), and VSExit().

885 {
886  winsys_shutdown();
887  exit( code );
888 }
void winsys_init ( int argc,
char **  argv,
char const *  window_title,
char const *  icon_title 
)

Initializes the OpenGL rendering context, and creates a window (or sets up fullscreen mode if selected)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 747 of file winsys.cpp.

References gl_options_t::color_depth, gl_options_t::fullscreen, g_game, VegaConfig::getVariable(), gl_options, height, XMLSupport::parse_bool(), XMLSupport::parse_int(), vs_config, VSFileSystem::vs_dprintf(), VSFileSystem::vs_fprintf(), width, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by GFXInit().

748 {
749  int width, height;
750  int glutWindow;
751  g_game.x_resolution = XMLSupport::parse_int( vs_config->getVariable( "graphics", "x_resolution", "1024" ) );
752  g_game.y_resolution = XMLSupport::parse_int( vs_config->getVariable( "graphics", "y_resolution", "768" ) );
753  gl_options.fullscreen = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "fullscreen", "false" ) );
754  gl_options.color_depth = XMLSupport::parse_int( vs_config->getVariable( "graphics", "colordepth", "32" ) );
755  glutInit( argc, argv );
756  static bool get_stencil = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "glut_stencil", "true" ) );
757  if (get_stencil) {
758 #ifdef __APPLE__
759  if ( !(glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_STENCIL ), 1) )
760  glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE );
761 #else
762  glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_STENCIL );
763 #endif
764  } else {
765  glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE );
766  }
767  char str[1024];
768  sprintf( str, "%dx%d:%d@60", g_game.x_resolution, g_game.y_resolution, gl_options.color_depth );
769  glutGameModeString( str );
770  VSFileSystem::vs_dprintf('3', "Game Mode Params %dx%d at depth %d @ %d Hz\n", glutGameModeGet( GLUT_GAME_MODE_WIDTH ),
771  glutGameModeGet( GLUT_GAME_MODE_WIDTH ), glutGameModeGet( GLUT_GAME_MODE_PIXEL_DEPTH ),
772  glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ) );
773  /* Create a window */
774  if ( gl_options.fullscreen && (glutGameModeGet( GLUT_GAME_MODE_POSSIBLE ) != -1) ) {
775  glutInitWindowPosition( 0, 0 );
776  glutEnterGameMode();
777  VSFileSystem::vs_dprintf('3', "Game Mode Params %dx%d at depth %d @ %d Hz\n", glutGameModeGet(
778  GLUT_GAME_MODE_WIDTH ), glutGameModeGet( GLUT_GAME_MODE_WIDTH ), glutGameModeGet(
779  GLUT_GAME_MODE_PIXEL_DEPTH ), glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ) );
780  } else {
781  /* Set the initial window size */
782  glutInitWindowSize( g_game.x_resolution, g_game.y_resolution );
783 
784  glutWindow = glutCreateWindow( window_title );
785  if (glutWindow == 0) {
786  (void) VSFileSystem::vs_fprintf( stderr, "Couldn't create a window.\n" );
787  exit( 1 );
788  }
789  }
790 }
void winsys_post_redisplay ( )

Requests that the screen be redrawn

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 575 of file winsys.cpp.

576 {
577  redisplay = true;
578 }
void winsys_process_events ( )

Processes and dispatches events. This function never returns.

Returns
No.
Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 849 of file winsys.cpp.

References glut_keyboard_cb(), glut_keyboard_up_cb(), glut_special_cb(), and glut_special_up_cb().

Referenced by GFXLoop().

850 {
851  /* Set up keyboard callbacks */
852  glutKeyboardFunc( glut_keyboard_cb );
853  glutKeyboardUpFunc( glut_keyboard_up_cb );
854  glutSpecialFunc( glut_special_cb );
855  glutSpecialUpFunc( glut_special_up_cb );
856 
857  glutMainLoop();
858 }
void winsys_set_display_func ( winsys_display_func_t  func)

Sets the display callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 587 of file winsys.cpp.

Referenced by GFXLoop().

588 {
589  glutDisplayFunc( func );
590 }
void winsys_set_idle_func ( winsys_idle_func_t  func)

Sets the idle callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 599 of file winsys.cpp.

Referenced by GFXLoop().

600 {
601  glutIdleFunc( func );
602 }
void winsys_set_keyboard_func ( winsys_keyboard_func_t  func)

Sets the keyboard callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 674 of file winsys.cpp.

Referenced by ConsoleKeys::BringConsole(), BaseInterface::InitCallbacks(), RestoreKB(), UniverseUtil::startMenuInterface(), CockpitKeys::TextMessageKey(), and NavComputer::toggleVisibility().

675 {
676  keyboard_func = func;
677 }
void winsys_set_motion_func ( winsys_motion_func_t  func)

Sets the mouse motion callback (when a mouse button is pressed)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 698 of file winsys.cpp.

Referenced by BaseInterface::InitCallbacks(), GameCockpit::NavScreen(), RestoreMouse(), UniverseUtil::startMenuInterface(), EventManager::takeOverEventManagement(), and NavComputer::toggleVisibility().

699 {
700  glutMotionFunc( func );
701 }
void winsys_set_mouse_func ( winsys_mouse_func_t  func)

Sets the mouse button-press callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 686 of file winsys.cpp.

Referenced by BaseInterface::InitCallbacks(), GameCockpit::NavScreen(), RestoreMouse(), UniverseUtil::startMenuInterface(), EventManager::takeOverEventManagement(), and NavComputer::toggleVisibility().

687 {
688  glutMouseFunc( func );
689 }
void winsys_set_passive_motion_func ( winsys_motion_func_t  func)

Sets the mouse motion callback (when no mouse button is pressed)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 710 of file winsys.cpp.

Referenced by BaseInterface::InitCallbacks(), GameCockpit::NavScreen(), RestoreMouse(), UniverseUtil::startMenuInterface(), EventManager::takeOverEventManagement(), and NavComputer::toggleVisibility().

711 {
712  glutPassiveMotionFunc( func );
713 }
void winsys_set_reshape_func ( winsys_reshape_func_t  func)

Sets the reshape callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 611 of file winsys.cpp.

Referenced by GFXInit().

612 {
613  glutReshapeFunc( func );
614 }
void winsys_show_cursor ( bool  visible)

Shows/hides mouse cursor

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 829 of file winsys.cpp.

Referenced by ConditionalCursorDraw(), and GFXInit().

830 {
831  static bool vis = true;
832  if (visible != vis) {
833  if (visible)
834  glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
835  else
836  glutSetCursor( GLUT_CURSOR_NONE );
837  vis = visible;
838  }
839 }
void winsys_shutdown ( )

Deallocates resources in preparation for program termination

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 799 of file winsys.cpp.

References gl_options_t::fullscreen, and gl_options.

Referenced by cleanup(), GFXShutdown(), and winsys_exit().

800 {
801  static bool shutdown = false;
802  if (!shutdown) {
803  shutdown = true;
805  glutLeaveGameMode();
806  }
807 }
void winsys_swap_buffers ( )

Copies the OpenGL back buffer to the front buffer

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 722 of file winsys.cpp.

Referenced by GFXEndScene(), and GFXInit().

723 {
724  glutSwapBuffers();
725 }
void winsys_warp_pointer ( int  x,
int  y 
)

Moves the mouse pointer to (x,y)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 734 of file winsys.cpp.

Referenced by BaseInterface::Room::Click(), and DealWithWarp().

735 {
736  glutWarpPointer( x, y );
737 }

Variable Documentation

winsys_keyboard_func_t keyboard_func = NULL
static

Definition at line 564 of file winsys.cpp.

bool redisplay = false
static

Definition at line 566 of file winsys.cpp.