static const char* GLW_GetDefaultFSMonitor( void ) { int max_level; const char *ret = 0; sql_prepare( &com_db, "SELECT MAX( gl_level ) FROM monitors" ); if( sql_step( &com_db ) ) max_level = sql_columnasint( &com_db, 0 ); else max_level = -1; sql_done( &com_db ); if( max_level >= 0 ) { sql_prepare( &com_db, "SELECT dev_name FROM monitors SEARCH gl_level ?" ); sql_bindint( &com_db, 1, max_level ); } else sql_prepare( &com_db, "SELECT dev_name FROM monitors" ); //pick the first monitor that supports the default resolution while( sql_step( &com_db ) ) { const char *mon = sql_columnastext( &com_db, 0 ); if( GLW_ValidateFSMode( GLW_DEFAULT_FS_RESOLUTION, mon ) ) { ret = va( "%s", mon ); break; } } sql_done( &com_db ); //no good, try to pick the first monitor that supports the best GL support level if( !ret ) { if( max_level < 0 ) max_level = 0; sql_prepare( &com_db, "SELECT dev_name FROM monitors SEARCH gl_level ? LIMIT 1" ); sql_bindint( &com_db, 1, max_level ); if( sql_step( &com_db ) ) ret = va( "%s", sql_columnastext( &com_db, 0 ) ); sql_done( &com_db ); } //??? if( !ret ) ret = ""; return ret; }
// retrieve a single int value using a sql query. // returns 0 if something goes wrong. beware! create your own statement if you need error handling. int query_int(sqlite3* db, const char* sql) { sqlite3_stmt *stmt; int rc; int ret; rc = sql_prepare(db,sql,&stmt,-1); if (rc != SQLITE_OK || stmt == 0 || sqlite3_column_count(stmt) == 0) { sql_error(db); ret = 0; } else { rc = sql_step(stmt,-1); if (rc == SQLITE_ROW) { ret = sqlite3_column_int(stmt,0); } else { #ifdef SQL_DEBUG printf("DEBUG: query_int() returns with sql_step() != SQLITE_ROW\n"); #endif ret = 0; } } sqlite3_finalize(stmt); return ret; }
static int fulltextFilter(sqlite3_vtab_cursor *pCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv){ fulltext_cursor *c = (fulltext_cursor *) pCursor; fulltext_vtab *v = cursor_vtab(c); int rc; const char *zStatement; c->iCursorType = idxNum; switch( idxNum ){ case QUERY_GENERIC: zStatement = "select rowid, content from %_content"; break; case QUERY_FULLTEXT: /* full-text search */ { const char *zQuery = (const char *)sqlite3_value_text(argv[0]); DocList *pResult; assert( argc==1 ); rc = fulltext_query(v, zQuery, &pResult); if( rc!=SQLITE_OK ) return rc; readerInit(&c->result, pResult); zStatement = "select rowid, content from %_content where rowid = ?"; break; } default: assert( 0 ); } rc = sql_prepare(v->db, v->zName, &c->pStmt, zStatement); if( rc!=SQLITE_OK ) return rc; return fulltextNext(pCursor); }
static time_t utils_private_setting_get_time(const char *setting, time_t defval) { sqlite3_stmt *stmt; time_t rc = defval; if (setting==NULL) return rc; sql_prepare(g_sqlite, "SELECT val FROM dbrw_core where setting = ?;", &stmt); sqlite3_bind_text(stmt, 1, setting, -1, SQLITE_STATIC); if (sql_step(stmt)==SQLITE_ROW) { rc = (time_t)sqlite3_column_int(stmt, 0); } sql_finalize(stmt); return rc; }
static int utils_private_setting_set_time(const char *setting, time_t val) { sqlite3_stmt *stmt; int rc = 0; if (setting==NULL) return rc; sql_prepare(g_sqlite, "REPLACE INTO dbrw_core VALUES(?,?);", &stmt); sqlite3_bind_text(stmt, 1, setting, -1, SQLITE_STATIC); sqlite3_bind_int(stmt, 2, val); if (sql_step(stmt)==SQLITE_DONE) { rc = 1; } sql_finalize(stmt); return rc; }
/* Puts a freshly-prepared statement determined by iStmt in *ppStmt. ** If the indicated statement has never been prepared, it is prepared ** and cached, otherwise the cached version is reset. */ static int sql_get_statement(fulltext_vtab *v, fulltext_statement iStmt, sqlite3_stmt **ppStmt){ assert( iStmt<MAX_STMT ); if( v->pFulltextStatements[iStmt]==NULL ){ int rc = sql_prepare(v->db, v->zName, &v->pFulltextStatements[iStmt], fulltext_zStatement[iStmt]); if( rc!=SQLITE_OK ) return rc; } else { int rc = sqlite3_reset(v->pFulltextStatements[iStmt]); if( rc!=SQLITE_OK ) return rc; } *ppStmt = v->pFulltextStatements[iStmt]; return SQLITE_OK; }
static int term_select_doclist(fulltext_vtab *v, const char *pTerm, int nTerm, sqlite3_stmt **ppStmt){ int rc; if( *ppStmt ){ rc = sqlite3_reset(*ppStmt); } else { rc = sql_prepare(v->db, v->zName, ppStmt, "select doclist from %_term where term = ? order by first"); } if( rc!=SQLITE_OK ) return rc; rc = sqlite3_bind_text(*ppStmt, 1, pTerm, nTerm, SQLITE_TRANSIENT); if( rc!=SQLITE_OK ) return rc; return sqlite3_step(*ppStmt); /* TODO(adamd): handle schema error */ }
static bool GLW_ValidateFSMonitor( const char *mon ) { bool goodMon; sql_prepare( &com_db, "SELECT gl_level FROM monitors SEARCH dev_name ?1" ); sql_bindtext( &com_db, 1, mon ); if( sql_step( &com_db ) ) { goodMon = sql_columnasint( &com_db, 0 ) > 0; } else goodMon = false; sql_done( &com_db ); return goodMon; }
static void GLW_GetDisplayModes( void ) { HDC dc; sql_exec( &com_db, "CREATE TABLE monitors" "(" "dev_name STRING, " "x INTEGER, " "y INTEGER, " "w INTEGER, " "h INTEGER, " "gl_level INTEGER " ");" "CREATE TABLE fsmodes" "(" "id INTEGER, " "w INTEGER, " "h INTEGER, " "dev_name STRING " //references monitors.dev_name ");" //really should be merged onto the prior - except then //the list gets too big and the GUI SELECT blows up and //I hate "CREATE TABLE fsmodes_ext" "(" "id INTEGER, " "hz INTEGER, " "bpp INTEGER " ");" ); sql_prepare( &com_db, "INSERT INTO monitors(dev_name,x,y,w,h,gl_level) VALUES(?,?,?,?,?,?);" ); dc = GetDC( NULL ); EnumDisplayMonitors( dc, NULL, GLW_GetMonitorDisplayModes, 0 ); ReleaseDC( NULL, dc ); sql_done( &com_db ); }
static const char* GLW_GetDefaultFSMode( const char *mon ) { const char *ret; if( GLW_ValidateFSMode( GLW_DEFAULT_FS_RESOLUTION, mon ) ) return GLW_DEFAULT_FS_RESOLUTION; sql_prepare( &com_db, "SELECT w:plain || ' ' || h:plain FROM fsmodes SEARCH dev_name ?1 LIMIT 1" ); sql_bindtext( &com_db, 1, mon ); if( sql_step( &com_db ) ) ret = va( "%s", sql_columnastext( &com_db, 0 ) ); else ret = GLW_DEFAULT_FS_RESOLUTION; //return it anyway?? sql_done( &com_db ); return ret; }
static bool GLW_ValidateFSMode( const char *mode, const char *mon ) { int w, h; bool goodMode; w = atoi( COM_Parse( &mode ) ); h = atoi( COM_Parse( &mode ) ); sql_prepare( &com_db, "SELECT COUNT( * ) FROM fsmodes SEARCH dev_name ?1 WHERE w=?2 AND h=?3" ); sql_bindtext( &com_db, 1, mon ); sql_bindint( &com_db, 2, w ); sql_bindint( &com_db, 3, h ); sql_step( &com_db ); goodMode = sql_columnasint( &com_db, 0 ) >= 1; sql_done( &com_db ); return goodMode; }
// generic function to dump the output of a sql statement to stdout. // will return sqlite error codes but also handle (read: ignore) them itself int sql_stdout(sqlite3* db, const char* sql, int* rowcount) { int rc; sqlite3_stmt *stmt; rc = sql_prepare(db,sql,&stmt,-1); if (rc != SQLITE_OK) { sql_error(db); return rc; } rc = stmt_stdout(stmt,rowcount); sqlite3_finalize(stmt); if (rc == SQLITE_DONE) { if (sqlite3_changes(db) > 0) fprintf(stdout,"Query done. %i rows affected.",sqlite3_changes(db)); } else { sql_error(db); } printf("\n"); return rc; }
/* ==================== CL_CgameSystemCalls The cgame module is making a system call ==================== */ intptr_t CL_CgameSystemCalls( intptr_t *args ) { switch( args[0] ) { case CG_PRINT: Com_Printf( "%s", VMA(1) ); return 0; case CG_FATAL_ERROR: Com_Error( ERR_DROP, "%s", VMA(1) ); return 0; case CG_MILLISECONDS: return Sys_Milliseconds(); case CG_CVAR_REGISTER: Cvar_Register( VMA(1), VMA(2), VMA(3), args[4] ); return 0; case CG_CVAR_UPDATE: Cvar_Update( VMA(1) ); return 0; case CG_CVAR_SET: Cvar_Set( VMA(1), VMA(2) ); return 0; case CG_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer( VMA(1), VMA(2), args[3] ); return 0; case CG_ARGC: return Cmd_Argc(); case CG_ARGV: Cmd_ArgvBuffer( args[1], VMA(2), args[3] ); return 0; case CG_ARGVI: return atoi( Cmd_Argv( args[1] ) ); case CG_ARGS: Cmd_ArgsBuffer( VMA(1), args[2] ); return 0; case CG_CMD_EXECUTETEXT: Cbuf_ExecuteText( args[1], VMA(2) ); return 0; case CG_FS_FOPENFILE: return FS_FOpenFileByMode( VMA(1), VMA(2), args[3] ); case CG_FS_READ: FS_Read( VMA(1), args[2], args[3] ); return 0; case CG_FS_WRITE: FS_Write( VMA(1), args[2], args[3] ); return 0; case CG_FS_FCLOSEFILE: FS_FCloseFile( args[1] ); return 0; case CG_SENDCONSOLECOMMAND: Cbuf_AddText( VMA(1) ); return 0; case CG_FORWARDCOMMAND: VM_Call( uivm, UI_CONSOLE_COMMAND, cls.realtime ); return 0; case CG_ADDCOMMAND: CL_AddCgameCommand( VMA(1) ); return 0; case CG_REMOVECOMMAND: Cmd_RemoveCommand( VMA(1) ); return 0; case CG_SENDCLIENTCOMMAND: CL_AddReliableCommand( VMA(1) ); return 0; case CG_UPDATESCREEN: // this is used during lengthy level loading, so pump message loop // Com_EventLoop(); // FIXME: if a server restarts here, BAD THINGS HAPPEN! // We can't call Com_EventLoop here, a restart will crash and this _does_ happen // if there is a map change while we are downloading at pk3. // ZOID SCR_UpdateScreen(); return 0; case CG_CM_LOADMAP: CL_CM_LoadMap( VMA(1) ); return 0; case CG_CM_NUMINLINEMODELS: return CM_NumInlineModels(); case CG_CM_INLINEMODEL: return CM_InlineModel( args[1] ); case CG_CM_TEMPBOXMODEL: return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qfalse ); case CG_CM_TEMPCAPSULEMODEL: return CM_TempBoxModel( VMA(1), VMA(2), /*int capsule*/ qtrue ); case CG_CM_POINTCONTENTS: return CM_PointContents( VMA(1), args[2] ); case CG_CM_TRANSFORMEDPOINTCONTENTS: return CM_TransformedPointContents( VMA(1), args[2], VMA(3), VMA(4) ); case CG_CM_BOXTRACE: CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qfalse ); return 0; case CG_CM_CAPSULETRACE: CM_BoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qtrue ); return 0; case CG_CM_TRANSFORMEDBOXTRACE: CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qfalse ); return 0; case CG_CM_TRANSFORMEDCAPSULETRACE: CM_TransformedBoxTrace( VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qtrue ); return 0; case CG_CM_MARKFRAGMENTS: return re.MarkFragments( args[1], VMA(2), VMA(3), args[4], VMA(5), args[6], VMA(7) ); case CG_S_STARTSOUND: S_StartSound( VMA(1), args[2], args[3], args[4] ); return 0; case CG_S_STARTLOCALSOUND: S_StartLocalSound( args[1], args[2] ); return 0; case CG_S_CLEARLOOPINGSOUNDS: S_ClearLoopingSounds(args[1]); return 0; case CG_S_ADDLOOPINGSOUND: S_AddLoopingSound( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_ADDREALLOOPINGSOUND: S_AddRealLoopingSound( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_STOPLOOPINGSOUND: S_StopLoopingSound( args[1] ); return 0; case CG_S_UPDATEENTITYPOSITION: S_UpdateEntityPosition( args[1], VMA(2) ); return 0; case CG_S_RESPATIALIZE: S_Respatialize( args[1], VMA(2), VMA(3), args[4] ); return 0; case CG_S_REGISTERSOUND: return S_RegisterSound( VMA(1), args[2] ); case CG_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack( VMA(1), VMA(2) ); return 0; case CG_R_LOADWORLDMAP: CL_R_LoadWorld( VMA( 1 ) ); return 0; case CG_R_REGISTERMODEL: return re.RegisterModel( VMA(1) ); case CG_R_REGISTERSKIN: return re.RegisterSkin( VMA(1) ); case CG_R_REGISTERSHADER: return re.RegisterShader( VMA(1) ); case CG_R_REGISTERSHADERNOMIP: return re.RegisterShaderNoMip( VMA(1) ); case CG_R_REGISTERFONT: return re.RegisterFont( VMA(1) ); case CG_R_CLEARSCENE: re.ClearScene(); return 0; case CG_R_BUILDPOSE: { animGroupTransition_t trans; trans.animGroup = 0; trans.interp = 0; return re.BuildPose( args[1], VMA( 2 ), args[3], VMA( 4 ), args[5], NULL, 0, NULL, 0, &trans, 1 ); } case CG_R_BUILDPOSE2: return re.BuildPose( args[1], VMA( 2 ), 2, VMA( 3 ), 2, VMA( 4 ), 2, VMA( 5 ), 2, VMA( 6 ), 2 ); case CG_R_BUILDPOSE3: return re.BuildPose( args[1], VMA( 2 ), 1, 0, 0, VMA( 3 ), 1, 0, 0, VMA( 4 ), 1 ); case CG_R_LERPTAGFROMPOSE: return re.LerpTagFromPose( VMA( 1 ), args[2], args[3], VMA( 4 ) ); case CG_R_ADDREFENTITYTOSCENE: re.AddRefEntityToScene( VMA(1) ); return 0; case CG_R_ADDPOLYTOSCENE: re.AddPolyToScene( args[1], args[2], VMA(3), 1 ); return 0; case CG_R_ADDPOLYSTOSCENE: re.AddPolyToScene( args[1], args[2], VMA(3), args[4] ); return 0; case CG_R_MENUBEGINSURF: re.MenuBeginSurf( args[1] ); return 0; case CG_R_MENUENDSURF: re.MenuEndSurf(); return 0; case CG_R_LIGHTFORPOINT: return re.LightForPoint( VMA(1), VMA(2), VMA(3), VMA(4) ); case CG_R_ADDLIGHTTOSCENE: re.AddLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_ADDADDITIVELIGHTTOSCENE: re.AddAdditiveLightToScene( VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); return 0; case CG_R_RENDERSCENE: re.RenderScene( VMA(1) ); return 0; case CG_R_SETCOLOR: re.SetColor( VMA(1) ); return 0; case CG_R_DRAWSTRETCHPIC: re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), NULL, VMF(5), VMF(6), VMF(7), VMF(8), args[9] ); return 0; case CG_R_SHAPECREATE: { curve_t * c = VMA(1); int n = args[3]; int i; for ( i=0; i<n; i++ ) { c->pts = (vec2_t*)VM_ArgPtr((intptr_t)c->pts); c->uvs = (vec2_t*)VM_ArgPtr((intptr_t)c->uvs); c->colors = (vec4_t*)VM_ArgPtr((intptr_t)c->colors); c->indices = (short*)VM_ArgPtr((intptr_t)c->indices ); } return re.ShapeCreate( c, VMA( 2 ), n ); } case CG_R_SHAPEDRAW: re.ShapeDraw( args[1], args[2], VMA( 3 ) ); return 0; case CG_R_RENDERTEXT: CL_RenderText( VMA(1), VMF(2), VMA(3), VMA(4), args[5], (args[6])>>16, args[6]&0xFFFF, args[7], args[8], 0, args[9], VMA(10) ); return 0; case CG_R_GETFONT: memcpy( VMA(3), re.GetFontFromFontSet( args[1], VMF(2) ), sizeof(fontInfo_t) ); return 0; case CG_R_ROUNDRECT: SCR_FillRect( VMF(1), VMF(2), VMF(3), VMF(4), VMA(5), args[6] ); return 0; case CG_R_MODELBOUNDS: re.ModelBounds( args[1], VMA(2), VMA(3) ); return 0; case CG_R_LERPTAG: return re.LerpTag( VMA(1), args[2], args[3], args[4], VMF(5), VMA(6) ); case CG_GETGLCONFIG: CL_GetGlconfig( VMA(1) ); return 0; case CG_GETGAMESTATE: CL_GetGameState( VMA(1) ); return 0; case CG_GETCURRENTSNAPSHOTNUMBER: CL_GetCurrentSnapshotNumber( VMA(1), VMA(2) ); return 0; case CG_GETSNAPSHOT: return CL_GetSnapshot( args[1], VMA(2) ); case CG_GETSERVERCOMMAND: return CL_GetServerCommand( args[1] ); case CG_GETCURRENTCMDNUMBER: return CL_GetCurrentCmdNumber(); case CG_GETUSERCMD: return CL_GetUserCmd( args[1], VMA(2) ); case CG_SETUSERCMDVALUE: CL_SetUserCmdValue( args[1], VMF(2) ); return 0; case CG_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case CG_KEY_ISDOWN: return Key_IsDown( args[1] ); case CG_KEY_GETCATCHER: return Key_GetCatcher(); case CG_KEY_SETCATCHER: Key_SetCatcher( args[1] ); return 0; case CG_KEY_GETKEY: return Key_GetKey( VMA(1) ); case CG_MEMSET: Com_Memset( VMA(1), args[2], args[3] ); return 0; case CG_MEMCPY: Com_Memcpy( VMA(1), VMA(2), args[3] ); return 0; case CG_STRNCPY: strncpy( VMA(1), VMA(2), args[3] ); return args[1]; case CG_SIN: return FloatAsInt( sin( VMF(1) ) ); case CG_COS: return FloatAsInt( cos( VMF(1) ) ); case CG_ATAN2: return FloatAsInt( atan2( VMF(1), VMF(2) ) ); case CG_SQRT: return FloatAsInt( sqrt( VMF(1) ) ); case CG_FLOOR: return FloatAsInt( floor( VMF(1) ) ); case CG_CEIL: return FloatAsInt( ceil( VMF(1) ) ); case CG_ACOS: return FloatAsInt( Q_acos( VMF(1) ) ); case CG_FMOD: return FloatAsInt( fmod( VMF(1),VMF(2) ) ); case CG_POW: return FloatAsInt( pow( VMF(1),VMF(2) ) ); case CG_ATAN: return FloatAsInt( atan( VMF(1) ) ); case CG_TAN: return FloatAsInt( tan( VMF(1)) ); case CG_PC_ADD_GLOBAL_DEFINE: return botlib_export->PC_AddGlobalDefine( VMA(1) ); case CG_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( VMA(1) ); case CG_PC_FREE_SOURCE: return botlib_export->PC_FreeSourceHandle( args[1] ); case CG_PC_READ_TOKEN: return botlib_export->PC_ReadTokenHandle( args[1], VMA(2) ); case CG_PC_SOURCE_FILE_AND_LINE: return botlib_export->PC_SourceFileAndLine( args[1], VMA(2), VMA(3) ); case CG_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case CG_REAL_TIME: return Com_RealTime( VMA(1) ); case CG_SNAPVECTOR: Sys_SnapVector( VMA(1) ); return 0; case CG_UPDATEGAMESTATE: return CL_UpdateGameState( VMA(1) ); case CG_CIN_PLAYCINEMATIC: return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]); case CG_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case CG_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case CG_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case CG_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case CG_R_REMAP_SHADER: //ToDo: remove this trap return 0; /* case CG_LOADCAMERA: return loadCamera(VMA(1)); case CG_STARTCAMERA: startCamera(args[1]); return 0; case CG_GETCAMERAINFO: return getCameraInfo(args[1], VMA(2), VMA(3)); */ case CG_GET_ENTITY_TOKEN: return re.GetEntityToken( VMA(1), args[2] ); case CG_R_INPVS: return re.inPVS( VMA(1), VMA(2) ); case CG_Q_rand: return Rand_NextUInt32( &cl.db.rand ); case CG_SQL_LOADDB: { char * buffer; int length; length = FS_ReadFile( VMA(1), &buffer ); if ( length > 0 ) { sql_exec( &cl.db, buffer ); FS_FreeFile(buffer); } return 0; } break; case CG_SQL_EXEC: return sql_exec( &cl.db, VMA(1) ); case CG_SQL_PREPARE: return sql_prepare( &cl.db, VMA(1) ) != 0; case CG_SQL_BIND: return sql_bind( &cl.db, args ); case CG_SQL_BINDTEXT: return sql_bindtext( &cl.db, args[1], VMA(2) ); case CG_SQL_BINDINT: return sql_bindint( &cl.db, args[1], args[2] ); case CG_SQL_BINDARGS: { int i,n = Cmd_Argc(); for ( i=1; i<n; i++ ) { if ( !sql_bindtext( &cl.db, i, Cmd_Argv( i ) ) ) return 0; } } return 1; case CG_SQL_STEP: return sql_step( &cl.db ); case CG_SQL_COLUMNCOUNT: return sql_columncount( &cl.db ); case CG_SQL_COLUMNASTEXT: Q_strncpyz( VMA(1), sql_columnastext( &cl.db, args[3] ), args[2] ); break; case CG_SQL_COLUMNASINT: return sql_columnasint( &cl.db, args[1] ); case CG_SQL_COLUMNNAME: Q_strncpyz( VMA(1), sql_columnname( &cl.db, args[3] ), args[2] ); break; case CG_SQL_DONE: return sql_done( &cl.db ); case CG_SQL_COMPILE: return sql_compile( &cl.db, VMA(1) ); case CG_SQL_RUN: { char * buffer = VMA(1); int size = args[2]; int id = args[3]; int i; formatInfo_t * stmt = (formatInfo_t*)cl.db.stmts_byindex[ id ]; if ( stmt ) { sqlData_t params[ 3 ]; const char * r; for ( i=0; i<3; i++ ) { params[ i ].format = INTEGER; params[ i ].payload.integer = args[ 4+i ]; } r = sql_eval( &cl.db, stmt->print, 0, 0, 0, 0, params, 0 ).string; Q_strncpyz( buffer, r, size ); } else { buffer[ 0 ] = '\0'; } } break; default: assert(0); // bk010102 Com_Error( ERR_DROP, "Bad cgame system trap: %i", args[0] ); } return 0; }
// import a cowpatty file int import_cowpatty(sqlite3* db, char* filename) { struct hashdb_head filehead; struct hashdb_rec rec; FILE *f = NULL; int rc; sqlite3_stmt *stmt; char* sql; int essid_id; int wordlength; char passwd[63+1]; if (strcmp(filename,"-") == 0) { f = stdin; } else { f = fopen(filename, "r"); } if (f == NULL || fread(&filehead, sizeof(filehead),1,f) != 1) { printf("Couldn't open the import file for reading.\n"); return 0; } else if (filehead.magic != GENPMKMAGIC) { printf("File doesn't seem to be a cowpatty file.\n"); fclose(f); return 0; } else if (verify_essid((char *)filehead.ssid) != 0) { printf("The file's ESSID is invalid.\n"); fclose(f); return 0; } printf("Reading header...\n"); //We need protection so concurrent transactions can't smash the ID-references sql_exec(db,"BEGIN;"); sql = sqlite3_mprintf("INSERT OR IGNORE INTO essid (essid) VALUES ('%q');",filehead.ssid); sql_exec(db,sql); sqlite3_free(sql); //since there is only one essid per file, we can determine it's ID now sql = sqlite3_mprintf("SELECT essid_id FROM essid WHERE essid = '%q'", filehead.ssid); essid_id = query_int(db,sql); sqlite3_free(sql); if (essid_id == 0) { fclose(f); sql_exec(db,"ROLLBACK;"); printf("ESSID couldn't be inserted. I've given up.\n"); return 0; } sql = sqlite3_mprintf("CREATE TEMPORARY TABLE import (passwd text, pmk blob);", essid_id); sql_exec(db,sql); sqlite3_free(sql); sql_prepare(db,"INSERT INTO import (passwd,pmk) VALUES (@pw,@pmk)",&stmt,-1); printf("Reading...\n"); while ((rc = fread(&rec.rec_size, sizeof(rec.rec_size), 1, f)) == 1) { wordlength = abs(rec.rec_size) - (sizeof(rec.pmk) + sizeof(rec.rec_size)); //prevent out of bounds writing (sigsegv guaranteed) but don't skip the whole file if wordlength < 8 if (wordlength > 0 && wordlength < (int) sizeof(passwd)) { passwd[wordlength] = 0; rc += fread(passwd, wordlength, 1, f); if (rc == 2) rc += fread(&rec.pmk, sizeof(rec.pmk), 1, f); } if (rc != 3) { fprintf(stdout,"Error while reading record (%i).\n",rc); sqlite3_finalize(stmt); if (db == NULL) { printf("omg"); fflush(stdout); } sql_exec(db, "ROLLBACK;"); fclose(f); return 1; } if (verify_passwd(passwd) == 0) { sqlite3_bind_text(stmt,1,passwd, strlen(passwd),SQLITE_TRANSIENT); sqlite3_bind_blob(stmt,2,&rec.pmk, sizeof(rec.pmk),SQLITE_TRANSIENT); if (sql_step(stmt,-1) == SQLITE_DONE) { sqlite3_reset(stmt); } else { printf("Error while inserting record into database.\n"); sqlite3_finalize(stmt); sql_exec(db, "ROLLBACK;"); fclose(f); return 1; } } else { fprintf(stdout,"Invalid password %s will not be imported.\n",passwd); } } sqlite3_finalize(stmt); if (!feof(f)) { printf("Error while reading file.\n"); sql_exec(db,"ROLLBACK;"); fclose(f); return 1; } printf("Updating references...\n"); sql_exec(db, "INSERT OR IGNORE INTO passwd (passwd) SELECT passwd FROM import;"); //TODO Give the user a choice to either INSERT OR UPDATE or INSERT OR IGNORE printf("Writing...\n"); sql = sqlite3_mprintf("INSERT OR IGNORE INTO pmk (essid_id,passwd_id,pmk) SELECT %i,passwd.passwd_id,import.pmk FROM import INNER JOIN passwd ON passwd.passwd = import.passwd;",essid_id); sql_exec(db,sql); sqlite3_free(sql); sql_exec(db,"COMMIT;"); fclose(f); return 1; }
/** * Initialize the database connections and associated * data structures (create tables and indices * as needed as well). * * @param plugin the plugin context (state for this module) * @return GNUNET_OK on success */ static int database_setup (struct Plugin *plugin) { char *filename; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-sqlite", "FILENAME", &filename)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "peerstore-sqlite", "FILENAME"); return GNUNET_SYSERR; } if (GNUNET_OK != GNUNET_DISK_file_test (filename)) { if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (filename)) { GNUNET_break (0); GNUNET_free (filename); return GNUNET_SYSERR; } } /* filename should be UTF-8-encoded. If it isn't, it's a bug */ plugin->fn = filename; /* Open database and precompile statements */ if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh)) { LOG (GNUNET_ERROR_TYPE_ERROR, _("Unable to initialize SQLite: %s.\n"), sqlite3_errmsg (plugin->dbh)); return GNUNET_SYSERR; } sql_exec (plugin->dbh, "PRAGMA temp_store=MEMORY"); sql_exec (plugin->dbh, "PRAGMA synchronous=OFF"); sql_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF"); sql_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL"); sql_exec (plugin->dbh, "PRAGMA encoding=\"UTF-8\""); sql_exec (plugin->dbh, "PRAGMA page_size=4096"); sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS); /* Create tables */ sql_exec (plugin->dbh, "CREATE TABLE IF NOT EXISTS peerstoredata (\n" " sub_system TEXT NOT NULL,\n" " peer_id BLOB NOT NULL,\n" " key TEXT NOT NULL,\n" " value BLOB NULL,\n" " expiry sqlite3_uint64 NOT NULL" ");"); sqlite3_create_function (plugin->dbh, "UINT64_LT", 2, SQLITE_UTF8, NULL, &sqlite3_lessthan, NULL, NULL); /* Create Indices */ if (SQLITE_OK != sqlite3_exec (plugin->dbh, "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata (sub_system, peer_id, key)", NULL, NULL, NULL)) { LOG (GNUNET_ERROR_TYPE_ERROR, _("Unable to create indices: %s.\n"), sqlite3_errmsg (plugin->dbh)); return GNUNET_SYSERR; } /* Prepare statements */ sql_prepare (plugin->dbh, "INSERT INTO peerstoredata (sub_system, peer_id, key, value, expiry) VALUES (?,?,?,?,?);", &plugin->insert_peerstoredata); sql_prepare (plugin->dbh, "SELECT * FROM peerstoredata" " WHERE sub_system = ?", &plugin->select_peerstoredata); sql_prepare (plugin->dbh, "SELECT * FROM peerstoredata" " WHERE sub_system = ?" " AND peer_id = ?", &plugin->select_peerstoredata_by_pid); sql_prepare (plugin->dbh, "SELECT * FROM peerstoredata" " WHERE sub_system = ?" " AND key = ?", &plugin->select_peerstoredata_by_key); sql_prepare (plugin->dbh, "SELECT * FROM peerstoredata" " WHERE sub_system = ?" " AND peer_id = ?" " AND key = ?", &plugin->select_peerstoredata_by_all); sql_prepare (plugin->dbh, "DELETE FROM peerstoredata" " WHERE UINT64_LT(expiry, ?)", &plugin->expire_peerstoredata); sql_prepare (plugin->dbh, "DELETE FROM peerstoredata" " WHERE sub_system = ?" " AND peer_id = ?" " AND key = ?", &plugin->delete_peerstoredata); return GNUNET_OK; }
int import_ascii(sqlite3* db, const char* mode, const char* filename) { FILE *f = NULL; sqlite3_stmt *stmt; char buffer[63+1]; int imported=0; int ignored=0; int imode=0; if (strcasecmp(mode,IMPORT_ESSID) == 0) { imode = 0; } else if (strcasecmp(mode,IMPORT_PASSWD) == 0) { imode = 1; } else { printf("Specify either 'essid' or 'passwd' as import mode.\n"); return 0; } if (strcmp(filename,"-") == 0) { f = stdin; } else { f = fopen(filename, "r"); } if (f == NULL) { printf("Could not open file/stream for reading.\n"); return 0; } char* sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (%q) VALUES (@v);",mode,mode); sql_prepare(db,sql,&stmt,-1); sqlite3_free(sql); sql_exec(db, "BEGIN;"); printf("Reading file...\n"); while (fgets(buffer, sizeof(buffer), f) != 0) { int i = strlen(buffer); if (buffer[i-1] == '\n') buffer[--i] = '\0'; if (buffer[i-1] == '\r') buffer[--i] = '\0'; imported++; if ((imode == 0 && verify_essid(buffer)==0) || (imode == 1 && verify_passwd(buffer)==0)) { sqlite3_bind_text(stmt,1,buffer, strlen(buffer),SQLITE_TRANSIENT); if (sql_step(stmt,-1) == SQLITE_DONE) { sqlite3_reset(stmt); } else { printf("Error while inserting record into database.\n"); sql_exec(db, "ROLLBACK;"); sqlite3_finalize(stmt); fclose(f); return 1; } } else { ignored++; } if (imported % 1000 == 0) { fprintf(stdout,"%i lines read, %i invalid lines ignored.\r",imported,ignored); fflush(stdout); } } sqlite3_finalize(stmt); if (!feof(f)) { printf("Error while reading file.\n"); sql_exec(db,"ROLLBACK;"); fclose(f); return 1; } fclose(f); printf("Writing...\n"); sql_exec(db,"COMMIT;"); printf("Done.\n"); return 1; }
//try to set the r_fsmonitor field to //whatever monitor the window is on static void Q_EXTERNAL_CALL GLW_UseCurrentMonitor( void ) { RECT rc; int max_area = 0; int max_level = 0; char best_monitor[CCHDEVICENAME] = ""; WinVars_t *winVars = (WinVars_t*)ri.PlatformGetVars(); if( !winVars->hWnd ) //no window = no clue return; GetWindowRect( winVars->hWnd, &rc ); sql_prepare( &com_db, "SELECT x, y, w, h, gl_level, dev_name FROM monitors WHERE gl_level > 0" ); while( sql_step( &com_db ) ) { int l = sql_columnasint( &com_db, 0 ); int t = sql_columnasint( &com_db, 1 ); int r = l + sql_columnasint( &com_db, 2 ); int b = t + sql_columnasint( &com_db, 3 ); int area; int level = sql_columnasint( &com_db, 4 ); const char *name = sql_columnastext( &com_db, 5 ); if( l < rc.left ) l = rc.left; if( r > rc.right ) r = rc.right; if( t < rc.top ) t = rc.top; if( b > rc.bottom ) b = rc.bottom; area = (r - l) * (b - t); if( !area ) //screen does not intersect window continue; if( level < max_level ) continue; if( level == max_level && area < max_area ) //only accept a screen of equal GL level if it owns more window area continue; max_level = level; max_area = area; Q_strncpyz( best_monitor, name, sizeof( best_monitor ) ); } sql_done( &com_db ); if( !best_monitor[0] ) //nothing to do return; //set the monitor cvar and make sure we //didn't just invalidate the mode cvar ri.Cvar_Set( r_fsmonitor->name, best_monitor ); GLW_ValidateFSModeCvar(); }
static BOOL CALLBACK GLW_GetMonitorDisplayModes( HMONITOR mon, HDC dc, LPRECT rc, LPARAM userData ) { int i; DEVMODE mode; MONITORINFOEX info; int gl_level; REF_PARAM( rc ); REF_PARAM( userData ); info.cbSize = sizeof( info ); GetMonitorInfo( mon, (LPMONITORINFO)&info ); gl_level = 3;//GLW_GetDisplayLevel( dc ); sql_bindtext( &com_db, 1, info.szDevice ); sql_bindint( &com_db, 2, info.rcMonitor.left ); sql_bindint( &com_db, 3, info.rcMonitor.top ); sql_bindint( &com_db, 4, info.rcMonitor.right - info.rcMonitor.left ); sql_bindint( &com_db, 5, info.rcMonitor.bottom - info.rcMonitor.top ); sql_bindint( &com_db, 6, gl_level ); sql_step( &com_db ); mode.dmSize = sizeof( mode ); mode.dmDriverExtra = 0; for( i = 0; EnumDisplaySettingsEx( info.szDevice, i, &mode, 0 ) != 0; i++ ) { int id; if( mode.dmBitsPerPel < 16 ) continue; if( mode.dmPelsWidth < 640 || mode.dmPelsHeight < 480 ) continue; sql_prepare( &com_db, "UPDATE OR INSERT fsmodes SET id=#,w=?1,h=?2,dev_name=?3 SEARCH dev_name ?3 WHERE w=?1 AND h=?2" ); sql_bindint( &com_db, 1, (int)mode.dmPelsWidth ); sql_bindint( &com_db, 2, (int)mode.dmPelsHeight ); sql_bindtext( &com_db, 3, info.szDevice ); sql_step( &com_db ); sql_done( &com_db ); //get the id of what we just added sql_prepare( &com_db, "SELECT id FROM fsmodes SEARCH dev_name ?3 WHERE w=?1 AND h=?2" ); sql_bindint( &com_db, 1, (int)mode.dmPelsWidth ); sql_bindint( &com_db, 2, (int)mode.dmPelsHeight ); sql_bindtext( &com_db, 3, info.szDevice ); sql_step( &com_db ); id = sql_columnasint( &com_db, 0 ); sql_done( &com_db ); //and insert the other info into the other table sql_prepare( &com_db, "UPDATE OR INSERT fsmodes_ext SET id=?1,hz=?2,bpp=?3 SEARCH id ?1 WHERE hz=?2 AND bpp=?3" ); sql_bindint( &com_db, 1, id ); sql_bindint( &com_db, 2, (int)mode.dmDisplayFrequency ); sql_bindint( &com_db, 3, (int)mode.dmBitsPerPel ); sql_step( &com_db ); sql_done( &com_db ); } return TRUE; }
static void GLW_CreateGLWnd( void ) { int x, y, w, h; HWND hParent; float aspect; DWORD s, es; skinDef_t *skin; int refresh = 0; int colorDepth = 0; WinVars_t *winVars = (WinVars_t*)ri.PlatformGetVars(); if( winVars->hWnd ) return; x = 0; y = 0; if( r_fullscreen->integer ) { int mode_id; char * res = r_fsmode->string; w = atoi( COM_Parse( &res ) ); h = atoi( COM_Parse( &res ) ); aspect = (float)w / (float)h; sql_prepare( &com_db, "SELECT x, y FROM monitors SEARCH dev_name ?" ); sql_bindtext( &com_db, 1, r_fsmonitor->string ); if( sql_step( &com_db ) ) { x = sql_columnasint( &com_db, 0 ); y = sql_columnasint( &com_db, 1 ); } sql_done( &com_db ); //find the settings mode id mode_id = -1; sql_prepare( &com_db, "SELECT id FROM fsmodes SEARCH dev_name ?1 WHERE w=?2 AND h=?3" ); sql_bindtext( &com_db, 1, r_fsmonitor->string ); sql_bindint( &com_db, 2, w ); sql_bindint( &com_db, 3, h ); if( sql_step( &com_db ) ) mode_id = sql_columnasint( &com_db, 0 ); sql_done( &com_db ); //get a matching color mode sql_prepare( &com_db, "SELECT bpp FROM fsmodes_ext SEARCH id ?1" ); sql_bindint( &com_db, 1, mode_id ); while( sql_step( &com_db ) ) { int bpp = sql_columnasint( &com_db, 0 ); if( r_colorbits->integer ) { if( bpp == r_colorbits->integer ) { //take an exact match colorDepth = bpp; break; } if( bpp > r_colorbits->integer ) { if( colorDepth < r_colorbits->integer || bpp < colorDepth ) //if we must go over, take the smallest value that goes over colorDepth = bpp; } else if( bpp > colorDepth ) colorDepth = bpp; } else if( bpp > colorDepth ) colorDepth = bpp; } sql_done( &com_db ); //get a matching refresh rate sql_prepare( &com_db, "SELECT hz FROM fsmodes_ext SEARCH id ?1 WHERE bpp=?2" ); sql_bindint( &com_db, 1, mode_id ); sql_bindint( &com_db, 2, colorDepth ); while( sql_step( &com_db ) ) { int hz = sql_columnasint( &com_db, 0 ); if( r_displayRefresh->integer ) { if( hz == r_displayRefresh->integer ) { //take an exact match refresh = hz; break; } if( hz > r_displayRefresh->integer ) { if( refresh < r_displayRefresh->integer || hz < refresh ) //if we must go over, take the smallest value that goes over refresh = hz; } else if( hz > refresh ) refresh = hz; } else if( hz > refresh ) //take the highest refresh rate refresh = hz; } sql_done( &com_db ); } else { if( !R_GetModeInfo( &w, &h, &aspect, r_mode->integer ) ) { //fall back to special modes w = 0; h = 0; } } /* Clean out old display mode changes. Note that we *don't* skip this when we're going back into fullscreen as it tends to produce some aweful bugs on some Windows installations. */ if( glw_state.cdsFullscreen ) ChangeDisplaySettings( NULL, 0 ); //window style bits es = 0; s = 0; skin = NULL; if( r_fullscreen->integer ) { //go into full screen mode RECT rc; HMONITOR monitor; MONITORINFOEX monitorInfo; hParent = 0; //make sure we're set up for multimon goodness if( winVars->hWndHost ) { GetWindowRect( winVars->hWndHost, &rc ); } else { rc.left = x; rc.top = y; rc.right = x + w; rc.bottom = y + h; } monitor = MonitorFromRect( &rc, MONITOR_DEFAULTTONEAREST ); monitorInfo.cbSize = sizeof( monitorInfo ); GetMonitorInfo( monitor, (LPMONITORINFO)&monitorInfo ); //if we got an invalid mode then use desktop resolution if( w == 0 ) w = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left; if( h == 0 ) h = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top; //change that monitor's display size to <w, h> //set the window rect to cover the display //skip the festival of desktop flickering if not changing resolution if( (monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left) != w || (monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top) != h ) { DEVMODE dm; memset( &dm, 0, sizeof( dm ) ); dm.dmSize = sizeof( dm ); dm.dmPelsWidth = w; dm.dmPelsHeight = h; dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; if( refresh != 0 ) { dm.dmDisplayFrequency = refresh; dm.dmFields |= DM_DISPLAYFREQUENCY; } if( colorDepth != 0 ) { dm.dmBitsPerPel = colorDepth; dm.dmFields |= DM_BITSPERPEL; } if( ChangeDisplaySettingsEx( monitorInfo.szDevice, &dm, NULL, CDS_FULLSCREEN, NULL ) != DISP_CHANGE_SUCCESSFUL ) { //try again without color bits and frequency dm.dmFields &= ~(DM_BITSPERPEL | DM_DISPLAYFREQUENCY); dm.dmBitsPerPel = 0; dm.dmDisplayFrequency = 0; if( ChangeDisplaySettingsEx( monitorInfo.szDevice, &dm, NULL, CDS_FULLSCREEN, NULL ) != DISP_CHANGE_SUCCESSFUL ) //failed... ri.Printf( PRINT_WARNING, "Invalid fullscreen resolution, running at desktop resolution" ); } } //get the new monitor info monitorInfo.cbSize = sizeof( monitorInfo ); GetMonitorInfo( monitor, (LPMONITORINFO)&monitorInfo ); x = monitorInfo.rcMonitor.left; y = monitorInfo.rcMonitor.top; w = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left; h = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top; s = WS_POPUP; es = WS_EX_APPWINDOW | WS_EX_TOPMOST; glw_state.cdsFullscreen = qtrue; } else if( winVars->hWndHost ) { RECT rc; hParent = winVars->hWndHost; GetClientRect( winVars->hWndHost, &rc ); x = rc.left; y = rc.top; w = rc.right - rc.left; h = rc.bottom - rc.top; s = WS_CHILD; es = WS_EX_NOPARENTNOTIFY; } else { RECT rc; HMONITOR monitor; MONITORINFO monitorInfo; qboolean usedefault = qfalse; if( w == 0 ) w = 640; if( h == 0 ) h = 480; vid_xpos = ri.Cvar_Get( "vid_xpos", va("%d",CW_USEDEFAULT), CVAR_ARCHIVE ); vid_ypos = ri.Cvar_Get( "vid_ypos", "0", CVAR_ARCHIVE ); x = vid_xpos->integer; y = vid_ypos->integer; if ( x == CW_USEDEFAULT ) { x = 0; usedefault = qtrue; } rc.left = x; rc.top = y; rc.right = x + w; rc.bottom = y + h; hParent = 0; if( r_skin->string[0] ) skin = Skin_Load( r_skin->string ); //account for the border frame if( skin ) { s = WS_POPUP; es = WS_EX_APPWINDOW; Skin_AdjustWindowRect( &rc, skin ); AdjustWindowRectEx( &rc, s, FALSE, es ); } else { s = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER | WS_CAPTION; es = WS_EX_APPWINDOW; AdjustWindowRectEx( &rc, s, FALSE, es ); } x = rc.left; y = rc.top; w = rc.right - rc.left; h = rc.bottom - rc.top; //constrain to a monitor //this is important as we can't get a //pixel format if we're entirely off screen monitor = MonitorFromRect( &rc, MONITOR_DEFAULTTONEAREST ); monitorInfo.cbSize = sizeof( monitorInfo ); GetMonitorInfo( monitor, &monitorInfo ); //if we're not actually intersecting the monitor //(shoved off of the screen I guess) move back onto it if( x > monitorInfo.rcWork.right ) //left window edge past right screen edge x = monitorInfo.rcWork.right - w; if( x + w < monitorInfo.rcWork.left ) //right window edge past left screen edge x = monitorInfo.rcWork.left; if( y > monitorInfo.rcWork.bottom ) //top window edge past bottom screen edge y = monitorInfo.rcWork.bottom - h; if( y + h < monitorInfo.rcWork.top ) //bottom window edge past top screen edge y = monitorInfo.rcWork.top; glw_state.cdsFullscreen = qfalse; if ( usedefault ) { x = monitorInfo.rcMonitor.left + ((monitorInfo.rcMonitor.right-monitorInfo.rcMonitor.left)-w)/2; y = monitorInfo.rcMonitor.top + ((monitorInfo.rcMonitor.bottom-monitorInfo.rcMonitor.top)-h)/2; } } winVars->hWnd = NULL; if( skin ) { Skin_RegisterClass(); winVars->hWnd = Skin_CreateWnd( skin, x, y, w, h ); } if( !winVars->hWnd ) { GLW_RegisterClass(); winVars->hWnd = CreateWindowEx( es, WINDOW_CLASS_NAME, WINDOW_CAPTION, s, x, y, w, h, hParent, NULL, winVars->hInstance, NULL ); } //the window now owns the skin and will free it if( !winVars->hWnd ) ri.Error( ERR_FATAL, "GLW: could not create window" ); SetWindowPos( winVars->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW ); ShowWindow( winVars->hWnd, SW_SHOWNORMAL ); SetFocus( winVars->hWnd ); //get the window to draw once (get rid of graphical clutter) UpdateWindow( winVars->hWnd ); //fire up the GL glw_state.hDC = GetDC( winVars->hWnd ); if( !glw_state.hDC ) ri.Error( ERR_FATAL, "GLW: could not get window DC" ); //set up the pixel format { int pixelFormat; PIXELFORMATDESCRIPTOR pfd; GLW_CreatePFD( &pfd ); pixelFormat = GLW_ChoosePFDEx( &pfd ); if( !pixelFormat ) { pixelFormat = GLW_ChoosePFD( glw_state.hDC, &pfd ); glConfig.fsaaSamples = 1; } if( !pixelFormat ) ri.Error( ERR_FATAL, "GLW: no valid pixel format" ); pfd.nSize = sizeof( pfd ); DescribePixelFormat( glw_state.hDC, pixelFormat, sizeof( pfd ), &pfd ); if( !SetPixelFormat( glw_state.hDC, pixelFormat, &pfd ) ) ri.Error( ERR_FATAL, "GLW: could not set pixel format" ); glConfig.colorBits = pfd.cColorBits; glConfig.depthBits = pfd.cDepthBits; glConfig.stencilBits = pfd.cStencilBits; glConfig.stereoEnabled = (pfd.dwFlags & PFD_STEREO) ? qtrue : qfalse; ri.Printf( PRINT_ALL, "Using Pixel Format %i\n", pixelFormat ); } glw_state.hGLRC = wglCreateContext( glw_state.hDC ); if( !glw_state.hGLRC || !wglMakeCurrent( glw_state.hDC, glw_state.hGLRC ) ) ri.Error( ERR_FATAL, "GLW: could not initialize GL" ); GLW_CheckExtensions(); //R_PerfInit(); { //get the actual sizes, in case Windows constrained our window RECT rc; GetClientRect( winVars->hWnd, &rc ); w = rc.right - rc.left; h = rc.bottom - rc.top; //fill in some glConfig stuff which *will* be referenced //by various subsystem init functions (i.e. Cg, bloom) glConfig.vidWidth = w; glConfig.vidHeight = h; glConfig.windowAspect = aspect; } glConfig.deviceSupportsGamma = qfalse; glConfig.isFullscreen = glw_state.cdsFullscreen ? qtrue : qfalse; glConfig.xscale = glConfig.vidWidth / 640.0f; glConfig.yscale = glConfig.vidHeight / 480.0f; if( glConfig.vidWidth * 480 > glConfig.vidHeight * 640 ) { // wide screen glConfig.xscale = glConfig.yscale; glConfig.xbias = ((float)glConfig.vidWidth - (640.0F * glConfig.xscale)) * 0.5F; } else { // no wide screen glConfig.xbias = 0.0f; } }