From: <at...@us...> - 2007-09-10 23:35:54
|
Revision: 511 http://cadcdev.svn.sourceforge.net/cadcdev/?rev=511&view=rev Author: atani Date: 2007-09-10 16:35:51 -0700 (Mon, 10 Sep 2007) Log Message: ----------- adding initialization flags. Modified Paths: -------------- tiki/examples/net/chatd/src/ChatServer.cpp tiki/include/Tiki/tiki.h tiki/sdl/src/init_shutdown.cpp tiki/sdl/src/platgl.cpp tiki/sdl/src/plathid.cpp Added Paths: ----------- tiki/src/base/init_flags_default.cpp Modified: tiki/examples/net/chatd/src/ChatServer.cpp =================================================================== --- tiki/examples/net/chatd/src/ChatServer.cpp 2007-09-10 17:03:45 UTC (rev 510) +++ tiki/examples/net/chatd/src/ChatServer.cpp 2007-09-10 23:35:51 UTC (rev 511) @@ -9,6 +9,8 @@ #include <Tiki/tiki.h> #include <pch.h> +TIKI_INIT_FLAGS(INIT_NONE); + #if TIKI_PLAT == TIKI_WIN32 #include <windows.h> Modified: tiki/include/Tiki/tiki.h =================================================================== --- tiki/include/Tiki/tiki.h 2007-09-10 17:03:45 UTC (rev 510) +++ tiki/include/Tiki/tiki.h 2007-09-10 23:35:51 UTC (rev 511) @@ -56,8 +56,39 @@ uint32 swaple( uint32 src ); uint16 swapbe( uint16 src ); uint32 swapbe( uint32 src ); + + // Tiki initialization flags + // defaults to INIT_HID_DEFAULT | INIT_VIDEO_DEFAULT | INIT_AUDIO_DEFAULT + extern uint32 g_tiki_init_flags; + + #define TIKI_INIT_FLAGS(flags) uint32 Tiki::g_tiki_init_flags = (flags); + typedef enum { + // HID options + INIT_HID_KEYBOARD = 0x00000001, + INIT_HID_MOUSE = 0x00000002, + INIT_HID_JOYSTICK = 0x00000004, + INIT_HID_DEFAULT = INIT_HID_KEYBOARD | INIT_HID_MOUSE | INIT_HID_JOYSTICK, + INIT_HID_MASK = 0x000000FF, + + // Graphic related options + INIT_VIDEO_WINDOWED = 0x00000100, + INIT_VIDEO_FULLSCREEN = 0x00000200, + INIT_VIDEO_CENTERED = 0x00000400, + INIT_VIDEO_DEFAULT = INIT_VIDEO_WINDOWED | INIT_VIDEO_CENTERED, + INIT_VIDEO_MASK = 0x0000FF00, + + // Audio related options + INIT_AUDIO_STREAM = 0x00010000, + INIT_AUDIO_SFX = 0x00020000, + INIT_AUDIO_DEFAULT = INIT_AUDIO_STREAM | INIT_AUDIO_SFX, + INIT_AUDIO_MASK = 0x00FF0000, + + INIT_NONE = 0x00000000, + INIT_DEFAULT = INIT_HID_DEFAULT | INIT_VIDEO_DEFAULT | INIT_AUDIO_DEFAULT, + } TIKI_INIT_FLAGS_ENUM; } + // Bring in debug stuff, we'll use it everywhere. #include "Tiki/debug.h" Modified: tiki/sdl/src/init_shutdown.cpp =================================================================== --- tiki/sdl/src/init_shutdown.cpp 2007-09-10 17:03:45 UTC (rev 510) +++ tiki/sdl/src/init_shutdown.cpp 2007-09-10 23:35:51 UTC (rev 511) @@ -18,38 +18,63 @@ #include <SDL/SDL.h> namespace Tiki { - bool init( int argc, char **argv ) { - ALCdevice * dev; - ALCcontext *context; if ( SDL_Init( SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE ) < 0 ) { - fprintf( stderr, "Unable to initialize SDL: %s\n", SDL_GetError() ); - return false; - } - -#ifdef ALCchar - dev = alcOpenDevice( const_cast<ALCchar *>("sdl") ); + fprintf( stderr, "Unable to initialize SDL: %s\n", SDL_GetError() ); + return false; + } + if(g_tiki_init_flags & INIT_AUDIO_MASK) { +#ifdef AL_LINUX + ALCdevice * dev = alcOpenDevice( (ALCchar *)("sdl") ); #else - dev = alcOpenDevice( (ALCubyte *)("sdl") ); + ALCdevice * dev = alcOpenDevice( (ALCubyte *)("sdl") ); #endif - if ( dev == NULL ) { + if ( dev == NULL ) { fprintf( stderr, "Unable to initialize OpenAL: %s\n", alGetString( alGetError() ) ); } else { - context = alcCreateContext( dev, NULL ); + ALCcontext *context = alcCreateContext( dev, NULL ); if ( context == NULL ) { - fprintf( stderr, "alcCreateContext returned NULL: %s\n", alGetString( alGetError() ) ); - } else { - alcMakeContextCurrent( context ); - alcProcessContext( context ); - Audio::Sound::initGlobal(); - Audio::Stream::initGlobal(); - } + fprintf( stderr, "alcCreateContext returned NULL: %s\n", alGetString( alGetError() ) ); + } else { + alcMakeContextCurrent( context ); + alcProcessContext( context ); + } } - GL::Plxcompat::plx_mat3d_init( 640, 480 ); + if(g_tiki_init_flags & INIT_AUDIO_SFX) { + Audio::Sound::initGlobal(); + } + if(g_tiki_init_flags & INIT_AUDIO_STREAM) { + Audio::Stream::initGlobal(); + } + } + if(g_tiki_init_flags & INIT_VIDEO_MASK) { + if ( SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ) == NULL ) { + fprintf( stderr, "Unable to Create OpenGL Window: %s\n", SDL_GetError() ); + return false; + } + + glEnable( GL_TEXTURE_2D ); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glShadeModel( GL_SMOOTH ); // Enable Smooth Shading + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); // Black Background + glClearDepth( 1.0f ); // Depth Buffer Setup + glEnable( GL_DEPTH_TEST ); // Enables Depth Testing + glDepthFunc( GL_LEQUAL ); // The Type Of Depth Testing To Do + + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); // Really Nice Perspective Calculations + GL::Plxcompat::plx_mat3d_init( 640, 480 ); + } return Hid::init(); } void shutdown() { + if(g_tiki_init_flags & INIT_AUDIO_SFX) { + Audio::Sound::shutdownGlobal(); + } + if(g_tiki_init_flags & INIT_AUDIO_STREAM) { + Audio::Stream::shutdownGlobal(); + } Hid::shutdown(); } Modified: tiki/sdl/src/platgl.cpp =================================================================== --- tiki/sdl/src/platgl.cpp 2007-09-10 17:03:45 UTC (rev 510) +++ tiki/sdl/src/platgl.cpp 2007-09-10 23:35:51 UTC (rev 511) @@ -46,9 +46,9 @@ // Every so often we should reset the frame counters, to avoid // having a super long term averaging effect. if ( frameCnt >= 500 ) { - firstFrame = 0; - frameCnt = 0; - } + firstFrame = 0; + frameCnt = 0; + } // Update frame counters. if ( !firstFrame ) @@ -57,9 +57,9 @@ totalFrameCnt++; if ( lastFrame.tv_sec == 0 ) { - gettimeofday( &lastFrame, NULL ); - return ; - } + gettimeofday( &lastFrame, NULL ); + return ; + } struct timeval now; gettimeofday( &now, NULL ); @@ -67,8 +67,8 @@ long long lastu = (( long long ) lastFrame.tv_sec ) * 1000 * 1000 + lastFrame.tv_usec; long long diffu = nowu - lastu; if ( diffu < ( 1000 * 1000 / targetFrameRate ) ) { - usleep(( 1000 * 1000 / targetFrameRate ) - diffu ); - } + usleep(( 1000 * 1000 / targetFrameRate ) - diffu ); + } gettimeofday( &lastFrame, NULL ); } Modified: tiki/sdl/src/plathid.cpp =================================================================== --- tiki/sdl/src/plathid.cpp 2007-09-10 17:03:45 UTC (rev 510) +++ tiki/sdl/src/plathid.cpp 2007-09-10 23:35:51 UTC (rev 511) @@ -49,8 +49,8 @@ int abs_x, abs_y; }; -static RefPtr<KbDevice> SDLkb; -static RefPtr<MouseDevice> SDLMouse; +static RefPtr<KbDevice> SDLkb = NULL; +static RefPtr<MouseDevice> SDLMouse = NULL; int HandleMouse( void *unused ); int HandleKeyboard( void *unused ); @@ -62,60 +62,51 @@ SDL_Thread *wm_thread; bool Hid::platInit() { - SDLkb = new KbDevice(); - SDLMouse = new MouseDevice(); - SDLMouse->setXY( 0, 0 ); - - Event evtKB( Event::EvtAttach ); - evtKB.dev = SDLkb; - sendEvent( evtKB ); - - Event evtMouse( Event::EvtAttach ); - evtMouse.dev = SDLMouse; - sendEvent( evtMouse ); - - if ( SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ) == NULL ) { - fprintf( stderr, "Unable to Create OpenGL Window: %s\n", SDL_GetError() ); - return false; - } - - SDL_WarpMouse( 0, 0 ); - char junk = '0'; - mouse_thread = SDL_CreateThread( HandleMouse, &junk ); - keybd_thread = SDL_CreateThread( HandleKeyboard, &junk ); - wm_thread = SDL_CreateThread( HandleWM, &junk ); + if(g_tiki_init_flags & INIT_HID_KEYBOARD) { + Tiki::Debug::printf("Initializing Keyboard\n"); + SDLkb = new KbDevice(); + keybd_thread = SDL_CreateThread( HandleKeyboard, &junk ); - glEnable( GL_TEXTURE_2D ); - glEnable( GL_BLEND ); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glShadeModel( GL_SMOOTH ); // Enable Smooth Shading - glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); // Black Background - glClearDepth( 1.0f ); // Depth Buffer Setup - glEnable( GL_DEPTH_TEST ); // Enables Depth Testing - glDepthFunc( GL_LEQUAL ); // The Type Of Depth Testing To Do + Event evtKB( Event::EvtAttach ); + evtKB.dev = SDLkb; + sendEvent( evtKB ); + } + if(g_tiki_init_flags & INIT_HID_MOUSE) { + Tiki::Debug::printf("Initializing Mouse\n"); + SDLMouse = new MouseDevice(); + SDLMouse->setXY( 0, 0 ); + mouse_thread = SDL_CreateThread( HandleMouse, &junk ); - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); // Really Nice Perspective Calculations + Event evtMouse( Event::EvtAttach ); + evtMouse.dev = SDLMouse; + sendEvent( evtMouse ); + } + wm_thread = SDL_CreateThread( HandleWM, &junk ); return true; } void Hid::platShutdown() { done = 1; SDL_Delay( 20 ); - SDL_WaitThread( mouse_thread, NULL ); - SDL_WaitThread( keybd_thread, NULL ); + if(g_tiki_init_flags & INIT_HID_MOUSE) { + Tiki::Debug::printf("Detaching Mouse\n"); + SDL_WaitThread( mouse_thread, NULL ); + Event evtMouse( Event::EvtDetach ); + evtMouse.dev = SDLMouse; + sendEvent( evtMouse ); + } + if(g_tiki_init_flags & INIT_HID_KEYBOARD) { + Tiki::Debug::printf("Detaching Keyboard\n"); + SDL_WaitThread( keybd_thread, NULL ); + Event evtKB( Event::EvtDetach ); + evtKB.dev = SDLkb; + sendEvent( evtKB ); + } SDL_WaitThread( wm_thread, NULL ); - Event evtKB( Event::EvtDetach ); - evtKB.dev = SDLkb; - sendEvent( evtKB ); - - Event evtMouse( Event::EvtDetach ); - evtMouse.dev = SDLMouse; - sendEvent( evtMouse ); - SDL_Quit(); } Added: tiki/src/base/init_flags_default.cpp =================================================================== --- tiki/src/base/init_flags_default.cpp (rev 0) +++ tiki/src/base/init_flags_default.cpp 2007-09-10 23:35:51 UTC (rev 511) @@ -0,0 +1,12 @@ +/* + Tiki + + init_flags_default.cpp + + Copyright (C)2007 Atani Software +*/ + +#include "pch.h" +#include "Tiki/tiki.h" + +TIKI_INIT_FLAGS(INIT_DEFAULT); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |