____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

sdl.cpp File Reference

SDL video support. More...

#include "stratagus.h"
#include <map>
#include <string>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include "video.h"
#include "font.h"
#include "interface.h"
#include "network.h"
#include "ui.h"
#include "sound_server.h"
#include "sound.h"
#include "minimap.h"
#include "widgets.h"
#include "editor.h"

Go to the source code of this file.

Functions

void SetVideoSync (void)
 Init line draw.
static bool IsExtensionSupported (const char *extension)
static void InitOpenGLExtensions ()
static void InitOpenGL (void)
void ReloadOpenGL ()
 Initializes video synchronization.
static void InitKey2Str ()
void InitVideoSdl (void)
 Init SDL video hardware driver.
int VideoValidResolution (int w, int h)
 Load graphic from PNG file.
void InvalidateArea (int x, int y, int w, int h)
void Invalidate (void)
static void SdlDoEvent (const EventCallback *callbacks, const SDL_Event *event)
void SetCallbacks (const EventCallback *callbacks)
 Get the current callbacks.
const EventCallbackGetCallbacks ()
 Process all system events. Returns if the time for a frame is over.
void WaitEventsOneFrame ()
 Toggle full screen mode.
void RealizeVideoMemory (void)
 Save a screenshot to a PNG file.
void SdlLockScreen (void)
 Do SDL hardware lock.
void SdlUnlockScreen (void)
 Do SDL hardware unlock.
const char * SdlKey2Str (int key)
 Check if the mouse is grabbed.
int Str2SdlKey (const char *str)
bool SdlGetGrabMouse (void)
 Toggle mouse grab mode.
void ToggleGrabMouse (int mode)
void ToggleFullScreen (void)
 Push current clipping.

Variables

SDL_Surface * TheScreen
 Internal screen.
static SDL_Rect Rects [100]
static int NumRects
GLint GLMaxTextureSize
 Max texture size supported on the video card.
bool GLTextureCompressionSupported
 Is OpenGL texture compression supported.
bool UseGLTextureCompression
 Use OpenGL texture compression.
static std::map< int, std::string > Key2Str
static std::map< std::string, int > Str2Key
static int FrameTicks
 Frame length in ms.
static int FrameRemainder
 Frame remainder 0.1 ms.
static int FrameFraction
 Frame fractional term.
const EventCallbackCallbacks
PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB
PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB
PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB
PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB
PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB
PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB
PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB


Detailed Description

SDL video support.

Definition in file sdl.cpp.


Function Documentation

const EventCallback* GetCallbacks (  ) 

Process all system events. Returns if the time for a frame is over.

Get the current callbacks

Definition at line 610 of file sdl.cpp.

Referenced by EditorMainLoop(), GameMainLoop(), PatchEditorMainLoop(), PlayMovie(), MenuScreen::run(), SdlDoEvent(), ShowTitleImage(), and WaitEventsOneFrame().

static void InitKey2Str (  )  [static]

Initialize SDLKey to string map

Definition at line 278 of file sdl.cpp.

References _, Key2Str, sprintf_s(), and Str2Key.

Referenced by InitVideoSdl(), and Str2SdlKey().

static void InitOpenGL ( void   )  [static]

Initialize OpenGL

Definition at line 218 of file sdl.cpp.

References GLMaxTextureSize, CVideo::Height, InitOpenGLExtensions(), Video, and CVideo::Width.

Referenced by InitVideoSdl(), and ReloadOpenGL().

static void InitOpenGLExtensions (  )  [static]

void InitVideoSdl ( void   ) 

void Invalidate ( void   ) 

void InvalidateArea ( int  x,
int  y,
int  w,
int  h 
)

Invalidate some area

Parameters:
x screen pixel X position.
y screen pixel Y position.
w width of rectangle in pixels.
h height of rectangle in pixels.

Definition at line 484 of file sdl.cpp.

References Assert, CVideo::Height, NumRects, Rects, UseOpenGL, Video, and CVideo::Width.

Referenced by ShowLoadProgress().

static bool IsExtensionSupported ( const char *  extension  )  [static]

Check if an extension is supported

Definition at line 145 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

void RealizeVideoMemory ( void   ) 

Save a screenshot to a PNG file.

Realize video memory.

Definition at line 736 of file sdl.cpp.

References HideCursor(), NumRects, Rects, TheScreen, and UseOpenGL.

Referenced by EditorUpdateDisplay(), GameMainLoop(), PatchEditorUpdateDisplay(), PlayMovie(), MenuScreen::run(), ShowLoadProgress(), and ShowTitleImage().

void ReloadOpenGL (  ) 

Initializes video synchronization.

Definition at line 255 of file sdl.cpp.

References InitOpenGL(), CUserInterface::Minimap, CMinimap::Reload(), ReloadFonts(), ReloadGraphics(), and UI.

Referenced by CVideo::ResizeScreen(), and ToggleFullScreen().

static void SdlDoEvent ( const EventCallback callbacks,
const SDL_Event *  event 
) [static]

Handle interactive input event.

Parameters:
callbacks Callback structure for events.
event SDL event structure pointer.

Definition at line 517 of file sdl.cpp.

References Exit(), GamePaused, GetCallbacks(), handleInput(), CVideo::Height, InputKeyButtonPress(), InputKeyButtonRelease(), InputMouseButtonPress(), InputMouseButtonRelease(), InputMouseExit(), InputMouseMove(), CUserInterface::MouseWarpX, CUserInterface::MouseWarpY, CVideo::ResizeScreen(), UI, UiTogglePause(), UseOpenGL, Video, and CVideo::Width.

Referenced by WaitEventsOneFrame().

bool SdlGetGrabMouse ( void   ) 

Toggle mouse grab mode.

Check if the mouse is grabbed

Definition at line 807 of file sdl.cpp.

Referenced by GetGrabMouse(), and ToggleGrabMouse().

const char* SdlKey2Str ( int  key  ) 

Check if the mouse is grabbed.

Convert a SDLKey to a string

Definition at line 777 of file sdl.cpp.

References Key2Str.

Referenced by HandleCommandKey().

void SdlLockScreen ( void   ) 

Do SDL hardware lock.

Lock the screen for write access.

Definition at line 753 of file sdl.cpp.

References TheScreen, and UseOpenGL.

Referenced by CVideo::LockScreen().

void SdlUnlockScreen ( void   ) 

Do SDL hardware unlock.

Unlock the screen for write access.

Definition at line 765 of file sdl.cpp.

References TheScreen, and UseOpenGL.

Referenced by CVideo::UnlockScreen().

void SetCallbacks ( const EventCallback callbacks  ) 

Get the current callbacks.

Set the current callbacks

Definition at line 602 of file sdl.cpp.

Referenced by EditorMainLoop(), GameMainLoop(), PatchEditorMainLoop(), PlayMovie(), MenuScreen::run(), ShowTitleImage(), and MenuScreen::stop().

void SetVideoSync ( void   ) 

Init line draw.

Initialise video sync. Calculate the length of video frame and any simulation skips.

See also:
VideoSyncSpeed

SkipFrames

FrameTicks

FrameRemainder

Definition at line 118 of file sdl.cpp.

References _C_, CYCLES_PER_SECOND, DebugPrint, FrameRemainder, FrameTicks, SkipFrames, and VideoSyncSpeed.

Referenced by EditorMainLoop(), GameMainLoop(), SetGameSpeed(), ShowTitleScreens(), UiDecreaseGameSpeed(), and UiIncreaseGameSpeed().

int Str2SdlKey ( const char *  str  ) 

Convert a string to SDLKey

Definition at line 785 of file sdl.cpp.

References InitKey2Str(), Key2Str, and Str2Key.

Referenced by convertKey().

void ToggleFullScreen ( void   ) 

Push current clipping.

Toggle full screen mode.

Definition at line 831 of file sdl.cpp.

References Exit(), CVideo::FullScreen, Invalidate(), ReloadOpenGL(), TheScreen, UseOpenGL, and Video.

Referenced by CommandKey(), EditorCallbackKeyDown(), PatchEditorCallbackKeyDown(), and tolua_stratagus_ToggleFullScreen00().

void ToggleGrabMouse ( int  mode  ) 

Toggle grab mouse.

Parameters:
mode Wanted mode, 1 grab, -1 not grab, 0 toggle.

Definition at line 817 of file sdl.cpp.

References SdlGetGrabMouse().

Referenced by SetGrabMouse(), and UiToggleGrabMouse().

int VideoValidResolution ( int  w,
int  h 
)

Load graphic from PNG file.

Check if a resolution is valid

Parameters:
w Width
h Height

Definition at line 471 of file sdl.cpp.

References TheScreen.

Referenced by CVideo::ResizeScreen().

void WaitEventsOneFrame (  ) 

Toggle full screen mode.

Wait for interactive input event for one frame.

Handles system events, joystick, keyboard, mouse. Handles the network messages. Handles the sound queue.

All events available are fetched. Sound and network only if available. Returns if the time for one frame is over.

Definition at line 625 of file sdl.cpp.

References CVideo::ClearScreen(), CursorAnimate(), Editor, FrameCounter, FrameFraction, FrameRemainder, FrameTicks, GameRunning, GetCallbacks(), handleInput(), InputKeyTimeout(), InputMouseTimeout(), IsNetworkGame, _event_callback_::NetworkEvent, NetworkFildes, NextFrameTicks, PatchEditorRunning, CEditor::Running, SdlDoEvent(), SkipFrames, SkipGameCycle, SlowFrameCounter, UseOpenGL, and Video.

Referenced by EditorMainLoop(), GameMainLoop(), PatchEditorMainLoop(), PlayMovie(), MenuScreen::run(), and ShowTitleImage().


Variable Documentation

Definition at line 93 of file sdl.cpp.

int FrameFraction [static]

Frame fractional term.

Definition at line 91 of file sdl.cpp.

Referenced by WaitEventsOneFrame().

int FrameRemainder [static]

Frame remainder 0.1 ms.

Definition at line 90 of file sdl.cpp.

Referenced by SetVideoSync(), and WaitEventsOneFrame().

int FrameTicks [static]

Frame length in ms.

Definition at line 89 of file sdl.cpp.

Referenced by SetVideoSync(), and WaitEventsOneFrame().

PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB

Definition at line 102 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB

Definition at line 101 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB

Definition at line 100 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB

Definition at line 105 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB

Definition at line 104 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB

Definition at line 103 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB

Definition at line 106 of file sdl.cpp.

Referenced by InitOpenGLExtensions().

Max texture size supported on the video card.

Is OpenGL texture compression supported.

Definition at line 82 of file sdl.cpp.

Referenced by DrawTexture(), InitOpenGL(), MakeTextures(), and MakeTextures2().

Is OpenGL texture compression supported.

Use OpenGL texture compression.

Definition at line 83 of file sdl.cpp.

Referenced by InitOpenGLExtensions(), and MakeTextures2().

std::map<int, std::string> Key2Str [static]

Definition at line 86 of file sdl.cpp.

Referenced by InitKey2Str(), SdlKey2Str(), and Str2SdlKey().

int NumRects [static]

Definition at line 81 of file sdl.cpp.

Referenced by Invalidate(), InvalidateArea(), and RealizeVideoMemory().

SDL_Rect Rects[100] [static]

Definition at line 80 of file sdl.cpp.

Referenced by Invalidate(), InvalidateArea(), and RealizeVideoMemory().

std::map<std::string, int> Str2Key [static]

Definition at line 87 of file sdl.cpp.

Referenced by InitKey2Str(), and Str2SdlKey().

SDL_Surface* TheScreen

Use OpenGL texture compression.

initialize the video part

Definition at line 84 of file sdl.cpp.

Referenced by MakeTextures2(), tolua_get_UseGLTextureCompression(), and tolua_set_UseGLTextureCompression().


Generated on Sat Feb 21 00:28:19 2009 for Bos Wars by  doxygen 1.5.6