⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winwindow.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 4 页
字号:

//--------------------------------------
static void InitOpenGL()
{
   // The OpenGL initialization stuff has been mostly moved to the display
   // devices' activate functions. BH

   DisplayDevice::init();

   // Get the video settings from the prefs:
   const char* resString = Con::getVariable( "$pref::Video::resolution" );
   char* tempBuf = new char[dStrlen( resString ) + 1];
   dStrcpy( tempBuf, resString );
   char* temp = dStrtok( tempBuf, " x\0" );
   U32 width = ( temp ? dAtoi( temp ) : 800 );
   temp = dStrtok( NULL, " x\0" );
   U32 height = ( temp ? dAtoi( temp ) : 600 );
   temp = dStrtok( NULL, "\0" );
   U32 bpp = ( temp ? dAtoi( temp ) : 16 );
   delete [] tempBuf;

   bool fullScreen = Con::getBoolVariable( "$pref::Video::fullScreen" );

   // If no device is specified, see which ones we have...
   if ( !Video::setDevice( Con::getVariable( "$pref::Video::displayDevice" ), width, height, bpp, fullScreen ) )
   {
      // First, try the default OpenGL device:
      if ( !Video::setDevice( "OpenGL", width, height, bpp, fullScreen ) )
      {
         // Next, try the D3D device:
         if ( !Video::setDevice( "D3D", width, height, bpp, fullScreen ) )
         {
            // Finally, try the Voodoo2 device:
            if ( !Video::setDevice( "Voodoo2", width, height, bpp, fullScreen ) )
            {
              	AssertFatal( false, "Could not find a compatible display device!" );
              	return;
				}
         }
      }
   }
}

//--------------------------------------
ConsoleFunction( getDesktopResolution, const char*, 1, 1, "getDesktopResolution()" )
{
   argc; argv;
   char buffer[256];
   dSprintf( buffer, sizeof( buffer ), "%d %d %d", winState.desktopWidth, winState.desktopHeight, winState.desktopBitsPixel );
   char* returnString = Con::getReturnBuffer( dStrlen( buffer ) + 1 );
   dStrcpy( returnString, buffer );
   return( returnString );
}

//--------------------------------------
void Platform::init()
{
   // Set the platform variable for the scripts
   Con::setVariable( "$platform", "windows" );

#ifdef TGE_RPG
	char	szFileName[512];
	char*	pLastSlash;
	::GetModuleFileName(NULL,szFileName,512);
	pLastSlash = dStrrchr(szFileName,'\\');
	if(pLastSlash == NULL)
		pLastSlash = dStrrchr(szFileName,'/');
	AssertFatal(pLastSlash,"怎么也没找到执行文件的路径...,有问题,要退出!");
	*pLastSlash	= '\0';

	Con::setVariable("$workingPath",szFileName);
	::SetCurrentDirectory(szFileName);

#endif

   WinConsole::create();
   if ( !WinConsole::isEnabled() )
      Input::init();
   InitInput();   // in case DirectInput falls through
   InitWindowClass();
   GetDesktopState();
   installRedBookDevices();

   sgDoubleByteEnabled = GetSystemMetrics( SM_DBCSENABLED );
	sgQueueEvents = true;
}

//--------------------------------------
void Platform::shutdown()
{
	sgQueueEvents = false;

   if(gMutexHandle)
      CloseHandle(gMutexHandle);
   setWindowLocked( false );
   Video::destroy();
   Input::destroy();
   WinConsole::destroy();
}


class WinTimer
{
   private:
      U32 mTickCountCurrent;
      U32 mTickCountNext;
      S64 mPerfCountCurrent;
      S64 mPerfCountNext;
      S64 mFrequency;
      bool mUsingPerfCounter;
   public:
      WinTimer()
      {
         mUsingPerfCounter = QueryPerformanceFrequency((LARGE_INTEGER *) &mFrequency);
         if(mUsingPerfCounter)
            mUsingPerfCounter = QueryPerformanceCounter((LARGE_INTEGER *) &mPerfCountCurrent);
         if(!mUsingPerfCounter)
            mTickCountCurrent = GetTickCount();
      }
      U32 getElapsedMS()
      {
         if(mUsingPerfCounter)
         {
            QueryPerformanceCounter( (LARGE_INTEGER *) &mPerfCountNext);
            U32 elapsed = (U32) (1000.0f * F64(mPerfCountNext - mPerfCountCurrent) / F64(mFrequency));
            return elapsed;
         }
         else
         {
            mTickCountNext = GetTickCount();
            return mTickCountNext - mTickCountCurrent;
         }
      }
      void advance()
      {
         mTickCountCurrent = mTickCountNext;
         mPerfCountCurrent = mPerfCountNext;
      }
};

static WinTimer gTimer;

extern bool LinkConsoleFunctions;

#ifndef TGE_RPG //分离到winMain32.cc中

//--------------------------------------
//static S32 run(S32 argc, const char **argv)
//{
//
//   // Console hack to ensure consolefunctions get linked in
//   LinkConsoleFunctions=true;
//
//   createFontInit();
//   windowSize.set(0,0);
//
//   S32 ret = Game->main(argc, argv);
//   createFontShutdown();
//   return ret;
//}
#endif

//--------------------------------------
void Platform::initWindow(const Point2I &initialSize, const char *name)
{
   Con::printf( "Video Init:" );
   Video::init();
   if ( Video::installDevice( OpenGLDevice::create() ) )
      Con::printf( "   Accelerated OpenGL display device detected." );
   else
      Con::printf( "   Accelerated OpenGL display device not detected." );

   if ( Video::installDevice( D3DDevice::create() ) )
      Con::printf( "   Accelerated D3D device detected." );
   else
      Con::printf( "   Accelerated D3D device not detected." );

   if ( Video::installDevice( Voodoo2Device::create() ) )
      Con::printf( "   Voodoo 2 display device detected." );
   else
      Con::printf( "   Voodoo 2 display device not detected." );
   Con::printf( "" );

   gWindowCreated = true;
#ifdef UNICODE
   convertUTF8toUTF16((UTF8 *)name, windowName, sizeof(windowName));
#else
   dStrcpy(windowName, name);
#endif
   InitWindow(initialSize);
   InitOpenGL();
}

#ifndef TGE_RPG //分离到winMain32.cc中
//--------------------------------------
//S32 main(S32 argc, const char **argv)
//{
//   winState.appInstance = GetModuleHandle(NULL);
//   return run(argc, argv);
//}
//
////--------------------------------------
//S32 PASCAL WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
//{
//   Vector<char *> argv;
//   char moduleName[256];
//   GetModuleFileNameA(NULL, moduleName, sizeof(moduleName));
//   argv.push_back(moduleName);
//
//   for (const char* word,*ptr = lpszCmdLine; *ptr; )  {
//      // Eat white space
//      for (; dIsspace(*ptr) && *ptr; ptr++)
//         ;
//      // Pick out the next word
//      for (word = ptr; !dIsspace(*ptr) && *ptr; ptr++)
//         ;
//      // Add the word to the argument list.
//      if (*word) {
//         int len = ptr - word;
//         char *arg = (char *) dMalloc(len + 1);
//         dStrncpy(arg, word, len);
//         arg[len] = 0;
//         argv.push_back(arg);
//      }
//   }
//
//   winState.appInstance = hInstance;
//
//   S32 retVal = run(argv.size(), (const char **) argv.address());
//
//   for(U32 j = 1; j < argv.size(); j++)
//      dFree(argv[j]);
//
//   return retVal;
//}
#endif

//--------------------------------------
void TimeManager::process()
{
   TimeEvent event;
   event.elapsedTime = gTimer.getElapsedMS();

   if(event.elapsedTime > sgTimeManagerProcessInterval)
   {
      gTimer.advance();
      Game->postEvent(event);
   }
}

/*
GLimp_Init
   GLW_LoadOpenGL
      QGL_Init(driver);
      GLW_StartDriverAndSetMode
         GLW_SetMode
            ChangeDisplaySettings
            GLW_CreateWindow
               GLW_InitDriver
                  GLW_CreatePFD
                  GLW_MakeContext
                     GLW_ChoosePFD
                     DescribePixelFormat
                     SetPixelFormat

   GLW_InitExtensions
   WG_CheckHardwareGamma
*/

F32 Platform::getRandom()
{
   return sgPlatRandom.randF();
}

////--------------------------------------
/// Spawn the default Operating System web browser with a URL
/// @param webAddress URL to pass to browser
/// @return true if browser successfully spawned
bool Platform::openWebBrowser( const char* webAddress )
{
   static bool sHaveKey = false;
   static wchar_t sWebKey[512];
   char utf8WebKey[512];

   {
      HKEY regKey;
      DWORD size = sizeof( sWebKey );

      if ( RegOpenKeyEx( HKEY_CLASSES_ROOT, dT("\\http\\shell\\open\\command"), 0, KEY_QUERY_VALUE, &regKey ) != ERROR_SUCCESS )
      {
         Con::errorf( ConsoleLogEntry::General, "Platform::openWebBrowser - Failed to open the HKCR\\http registry key!!!");
         return( false );
      }

      if ( RegQueryValueEx( regKey, dT(""), NULL, NULL, (unsigned char *)sWebKey, &size ) != ERROR_SUCCESS ) 
      {
         Con::errorf( ConsoleLogEntry::General, "Platform::openWebBrowser - Failed to query the open command registry key!!!" );
         return( false );
      }

      RegCloseKey( regKey );
      sHaveKey = true;

      convertUTF16toUTF8(sWebKey,utf8WebKey,512);

#ifdef UNICODE
      char *p = dStrstr((const char *)utf8WebKey, "%1"); 
#else
      char *p = strstr( (const char *) sWebKey  , "%1"); 
#endif
      if (p) *p = 0; 

   }

   STARTUPINFO si;
   dMemset( &si, 0, sizeof( si ) );
   si.cb = sizeof( si );

   char buf[1024];
#ifdef UNICODE
   dSprintf( buf, sizeof( buf ), "%s %s", utf8WebKey, webAddress );   
   UTF16 b[1024];
   convertUTF8toUTF16((UTF8 *)buf, b, sizeof(b));
#else
   dSprintf( buf, sizeof( buf ), "%s %s", sWebKey, webAddress );   
#endif

   //Con::errorf( ConsoleLogEntry::General, "** Web browser command = %s **", buf );

   PROCESS_INFORMATION pi;
   dMemset( &pi, 0, sizeof( pi ) );
   CreateProcess( NULL,
#ifdef UNICODE
      b,
#else
      buf, 
#endif
      NULL,
      NULL,
      false,
      CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
      NULL,
      NULL,
      &si,
      &pi );

   return( true );
}

//--------------------------------------
// Login password routines:
//--------------------------------------
#ifdef TGE_RPG
	#ifdef UNICODE
	static const UTF16* TorqueRegKey = dT("SOFTWARE\\GWorld\\RPG");
	#else
	static const char* TorqueRegKey = "SOFTWARE\\GWorld\\RPG";
	#endif
#else
	#ifdef UNICODE
	static const UTF16* TorqueRegKey = dT("SOFTWARE\\GarageGames\\Torque");
	#else
	static const char* TorqueRegKey = "SOFTWARE\\GarageGames\\Torque";
	#endif
#endif

const char* Platform::getLoginPassword()
{
   HKEY regKey;
   char* returnString = NULL;
   if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TorqueRegKey, 0, KEY_QUERY_VALUE, &regKey ) == ERROR_SUCCESS )
   {
      U8 buf[32];
      DWORD size = sizeof( buf );
      if ( RegQueryValueEx( regKey, dT("LoginPassword"), NULL, NULL, buf, &size ) == ERROR_SUCCESS )
      {
         returnString = Con::getReturnBuffer( size + 1 );
         dStrcpy( returnString, (const char*) buf );
      }

      RegCloseKey( regKey );
   }

   if ( returnString )
      return( returnString );
   else
      return( "" );
}

//--------------------------------------
bool Platform::setLoginPassword( const char* password )
{
   HKEY regKey;
   if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TorqueRegKey, 0, KEY_WRITE, &regKey ) == ERROR_SUCCESS )
   {
      if ( RegSetValueEx( regKey, dT("LoginPassword"), 0, REG_SZ, (const U8*) password, dStrlen( password ) + 1 ) != ERROR_SUCCESS )
         Con::errorf( ConsoleLogEntry::General, "setLoginPassword - Failed to set the subkey value!" );

      RegCloseKey( regKey );
      return( true );
   }
   else
      Con::errorf( ConsoleLogEntry::General, "setLoginPassword - Failed to open the Torque registry key!" );

   return( false );
}

//--------------------------------------
// Silly Korean registry key checker:
//--------------------------------------
ConsoleFunction( isKoreanBuild, bool, 1, 1, "isKoreanBuild()" )
{
   argc; argv;
   HKEY regKey;
   bool result = false;
   if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TorqueRegKey, 0, KEY_QUERY_VALUE, &regKey ) == ERROR_SUCCESS )
   {
      DWORD val;
      DWORD size = sizeof( val );
      if ( RegQueryValueEx( regKey, dT("Korean"), NULL, NULL, (U8*) &val, &size ) == ERROR_SUCCESS )
         result = ( val > 0 );

      RegCloseKey( regKey );
   }

   return( result );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -