/* ======================== idKeyInput::LocalizedKeyName ======================== */ const char* idKeyInput::LocalizedKeyName( keyNum_t keynum ) { // RB #if defined(_WIN32) // DG TODO: move this into a win32 Sys_GetKeyName() if( keynum < K_JOY1 ) { // On the PC, we want to turn the scan code in to a key label that matches the currently selected keyboard layout unsigned char keystate[256] = { 0 }; WCHAR temp[5]; int scancode = ( int )keynum; int vkey = MapVirtualKey( keynum, MAPVK_VSC_TO_VK_EX ); int result = -1; while( result < 0 ) { result = ToUnicode( vkey, scancode, keystate, temp, sizeof( temp ) / sizeof( temp[0] ), 0 ); } if( result > 0 && temp[0] > ' ' && iswprint( temp[0] ) ) { static idStr bindStr; bindStr.Empty(); bindStr.AppendUTF8Char( temp[0] ); return bindStr; } } #else // DG: for !Windows I introduced Sys_GetKeyName() to get key label for current keyboard layout const char* ret = nullptr; if( keynum < K_JOY1 ) // only for keyboard keys, not joystick or mouse { ret = Sys_GetKeyName( keynum ); } if( ret != NULL ) { return ret; } #endif // check for a key string for( keyname_t* kn = keynames; kn->name; kn++ ) { if( keynum == kn->keynum ) { return idLocalization::GetString( kn->strId ); } } return "????"; // RB/DG end }
/* ================ idRestoreGame::ReadString ================ */ void idRestoreGame::ReadString( idStr& string ) { string.Empty(); int offset = -1; ReadInt( offset ); if( offset < 0 ) { return; } stringFile->Seek( offset, FS_SEEK_SET ); stringFile->ReadString( string ); return; }
/* ==================== idStr::ExtractFileExtension ==================== */ void idStr::ExtractFileExtension( idStr &dest ) const { int pos; // // back up until a . or the start // pos = Length() - 1; while( ( pos > 0 ) && ( ( *this )[ pos - 1 ] != '.' ) ) { pos--; } if ( !pos ) { // no extension dest.Empty(); } else { Right( Length() - pos, dest ); } }
/* ============= idStr::StripMediaName makes the string lower case, replaces backslashes with forward slashes, and removes extension ============= */ void idStr::StripMediaName( const char *name, idStr &mediaName ) { char c; mediaName.Empty(); for ( c = *name; c; c = *(++name) ) { // truncate at an extension if ( c == '.' ) { break; } // convert backslashes to forward slashes if ( c == '\\' ) { mediaName.Append( '/' ); } else { mediaName.Append( idStr::ToLower( c ) ); } } }
/* ======================== idKeyInput::LocalizedKeyName ======================== */ const char* idKeyInput::LocalizedKeyName( keyNum_t keynum ) { // RB: FIXME #if defined(_WIN32) if( keynum < K_JOY1 ) { // On the PC, we want to turn the scan code in to a key label that matches the currently selected keyboard layout unsigned char keystate[256] = { 0 }; WCHAR temp[5]; int scancode = ( int )keynum; int vkey = MapVirtualKey( keynum, MAPVK_VSC_TO_VK_EX ); int result = -1; while( result < 0 ) { result = ToUnicode( vkey, scancode, keystate, temp, sizeof( temp ) / sizeof( temp[0] ), 0 ); } if( result > 0 && temp[0] > ' ' && iswprint( temp[0] ) ) { static idStr bindStr; bindStr.Empty(); bindStr.AppendUTF8Char( temp[0] ); return bindStr; } } // check for a key string for( keyname_t* kn = keynames; kn->name; kn++ ) { if( keynum == kn->keynum ) { return idLocalization::GetString( kn->strId ); } } return "????"; #else return KeyNumToString( keynum ); #endif // RB end }
/* ================ idInterpreter::GetRegisterValue Returns a string representation of the value of the register. This is used primarily for the debugger and debugging //FIXME: This is pretty much wrong. won't access data in most situations. ================ */ bool idInterpreter::GetRegisterValue( const char *name, idStr &out, int scopeDepth ) { varEval_t reg; idVarDef *d; char funcObject[ 1024 ]; char *funcName; const idVarDef *scope; const idTypeDef *field; const idScriptObject *obj; const function_t *func; out.Empty(); if ( scopeDepth == -1 ) { scopeDepth = callStackDepth; } if ( scopeDepth == callStackDepth ) { func = currentFunction; } else { func = callStack[ scopeDepth ].f; } if ( !func ) { return false; } idStr::Copynz( funcObject, func->Name(), sizeof( funcObject ) ); funcName = strstr( funcObject, "::" ); if ( funcName ) { *funcName = '\0'; scope = gameLocal.program.GetDef( NULL, funcObject, &def_namespace ); funcName += 2; } else { funcName = funcObject; scope = &def_namespace; } // Get the function from the object d = gameLocal.program.GetDef( NULL, funcName, scope ); if ( !d ) { return false; } // Get the variable itself and check various namespaces d = gameLocal.program.GetDef( NULL, name, d ); if ( !d ) { if ( scope == &def_namespace ) { return false; } d = gameLocal.program.GetDef( NULL, name, scope ); if ( !d ) { d = gameLocal.program.GetDef( NULL, name, &def_namespace ); if ( !d ) { return false; } } } reg = GetVariable( d ); switch( d->Type() ) { case ev_float: if ( reg.floatPtr ) { out = va("%g", *reg.floatPtr ); } else { out = "0"; } return true; break; case ev_vector: if ( reg.vectorPtr ) { out = va( "%g,%g,%g", reg.vectorPtr->x, reg.vectorPtr->y, reg.vectorPtr->z ); } else { out = "0,0,0"; } return true; break; case ev_boolean: if ( reg.intPtr ) { out = va( "%d", *reg.intPtr ); } else { out = "0"; } return true; break; case ev_field: if ( scope == &def_namespace ) { // should never happen, but handle it safely anyway return false; } field = scope->TypeDef()->GetParmType( reg.ptrOffset )->FieldType(); obj = *reinterpret_cast<const idScriptObject **>( &localstack[ callStack[ callStackDepth ].stackbase ] ); if ( !field || !obj ) { return false; } switch ( field->Type() ) { case ev_boolean: out = va( "%d", *( reinterpret_cast<int *>( &obj->data[ reg.ptrOffset ] ) ) ); return true; case ev_float: out = va( "%g", *( reinterpret_cast<float *>( &obj->data[ reg.ptrOffset ] ) ) ); return true; default: return false; } break; case ev_string: if ( reg.stringPtr ) { out = "\""; out += reg.stringPtr; out += "\""; } else { out = "\"\""; } return true; default: return false; } }