Przeglądaj źródła

Removes attach to Window

seanpaultaylor 12 lat temu
rodzic
commit
4813cc472f

+ 1 - 0
gameplay/gameplay.vcxproj

@@ -323,6 +323,7 @@
     <ClCompile Include="src\SocialController.cpp" />
     <ClCompile Include="src\SocialPlayer.cpp" />
     <ClCompile Include="src\SocialScore.cpp" />
+    <ClCompile Include="src\SocialSessionListener.cpp" />
     <ClCompile Include="src\social\GoogleGamesSocialSession.cpp" />
     <ClCompile Include="src\social\ScoreloopSocialSession.cpp" />
     <ClCompile Include="src\SpriteBatch.cpp" />

+ 3 - 0
gameplay/gameplay.vcxproj.filters

@@ -885,6 +885,9 @@
     <ClCompile Include="src\SocialChallenge.cpp">
       <Filter>src</Filter>
     </ClCompile>
+    <ClCompile Include="src\SocialSessionListener.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">

+ 1 - 2
gameplay/src/Platform.h

@@ -36,12 +36,11 @@ public:
      * Creates a platform for the specified game which it will interact with.
      *
      * @param game The game to create a platform for.
-     * @param attachToWindow The native window handle to optionally attach to.
      * 
      * @return The created platform interface.
      * @script{ignore}
      */
-    static Platform* create(Game* game, void* attachToWindow = NULL);
+    static Platform* create(Game* game);
 
     /**
      * Begins processing the platform messages.

+ 1 - 1
gameplay/src/PlatformAndroid.cpp

@@ -974,7 +974,7 @@ Platform::~Platform()
 {
 }
 
-Platform* Platform::create(Game* game, void* attachToWindow)
+Platform* Platform::create(Game* game)
 {
     Platform* platform = new Platform(game);
     return platform;

+ 1 - 1
gameplay/src/PlatformBlackBerry.cpp

@@ -690,7 +690,7 @@ Platform::~Platform()
     }
 }
 
-Platform* Platform::create(Game* game, void* attachToWindow)
+Platform* Platform::create(Game* game)
 {
     FileSystem::setResourcePath("./app/native/");
     Platform* platform = new Platform(game);

+ 1 - 3
gameplay/src/PlatformLinux.cpp

@@ -89,7 +89,6 @@ static Display* __display;
 static Window   __window;
 static int __windowSize[2];
 static GLXContext __context;
-static Window __attachToWindow;
 static Atom __atomWmDeleteWindow;
 static list<ConnectedGamepadDevInfo> __connectedGamepads;
 
@@ -551,12 +550,11 @@ namespace gameplay
     {
     }
 
-    Platform* Platform::create(Game* game, void* attachToWindow)
+    Platform* Platform::create(Game* game)
     {
 
         GP_ASSERT(game);
 
-        __attachToWindow = (Window)attachToWindow;
         FileSystem::setResourcePath("./");
         Platform* platform = new Platform(game);
 

+ 40 - 59
gameplay/src/PlatformWindows.cpp

@@ -28,7 +28,6 @@ static double __timeStart;
 static double __timeAbsolute;
 static bool __vsync = WINDOW_VSYNC;
 static HINSTANCE __hinstance = 0;
-static HWND __attachToWindow = 0;
 static HWND __hwnd = 0;
 static HDC __hdc = 0;
 static HGLRC __hrc = 0;
@@ -787,7 +786,7 @@ bool initializeGL(WindowCreationParams* params)
     return true;
 }
 
-Platform* Platform::create(Game* game, void* attachToWindow)
+Platform* Platform::create(Game* game)
 {
     GP_ASSERT(game);
 
@@ -797,8 +796,6 @@ Platform* Platform::create(Game* game, void* attachToWindow)
     // Get the application module handle.
     __hinstance = ::GetModuleHandle(NULL);
 
-    __attachToWindow = (HWND)attachToWindow;
-
     // Read window settings from config.
     WindowCreationParams params;
     params.fullscreen = false;
@@ -890,65 +887,52 @@ Platform* Platform::create(Game* game, void* attachToWindow)
         }
     }
 
-    if (!__attachToWindow)
+
+    // Register our window class.
+    WNDCLASSEX wc;
+    wc.cbSize = sizeof(WNDCLASSEX);
+    wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
+    wc.lpfnWndProc    = (WNDPROC)__WndProc;
+    wc.cbClsExtra     = 0;
+    wc.cbWndExtra     = 0;
+    wc.hInstance      = __hinstance;
+    wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
+    wc.hIconSm        = NULL;
+    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
+    wc.hbrBackground  = NULL;  // No brush - we are going to paint our own background
+    wc.lpszMenuName   = NULL;  // No default menu
+    wc.lpszClassName  = L"gameplay";
+
+    if (!::RegisterClassEx(&wc))
     {
-        // Register our window class.
-        WNDCLASSEX wc;
-        wc.cbSize = sizeof(WNDCLASSEX);
-        wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
-        wc.lpfnWndProc    = (WNDPROC)__WndProc;
-        wc.cbClsExtra     = 0;
-        wc.cbWndExtra     = 0;
-        wc.hInstance      = __hinstance;
-        wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
-        wc.hIconSm        = NULL;
-        wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
-        wc.hbrBackground  = NULL;  // No brush - we are going to paint our own background
-        wc.lpszMenuName   = NULL;  // No default menu
-        wc.lpszClassName  = L"gameplay";
-
-        if (!::RegisterClassEx(&wc))
-        {
-            GP_ERROR("Failed to register window class.");
-            goto error;
-        }
+        GP_ERROR("Failed to register window class.");
+        goto error;
+    }
 
-        if (params.fullscreen)
+    if (params.fullscreen)
+    {
+        DEVMODE dm;
+        memset(&dm, 0, sizeof(dm));
+        dm.dmSize= sizeof(dm);
+        dm.dmPelsWidth  = width;
+        dm.dmPelsHeight = height;
+        dm.dmBitsPerPel = DEFAULT_COLOR_BUFFER_SIZE;
+        dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+
+        // Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
+        if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
         {
-            DEVMODE dm;
-            memset(&dm, 0, sizeof(dm));
-            dm.dmSize= sizeof(dm);
-            dm.dmPelsWidth  = width;
-            dm.dmPelsHeight = height;
-            dm.dmBitsPerPel = DEFAULT_COLOR_BUFFER_SIZE;
-            dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
-
-            // Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
-            if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
-            {
-                params.fullscreen = false;
-                GP_ERROR("Failed to start game in full-screen mode with resolution %dx%d.", width, height);
-                goto error;
-            }
-        }
-
-        if (!initializeGL(&params))
+            params.fullscreen = false;
+            GP_ERROR("Failed to start game in full-screen mode with resolution %dx%d.", width, height);
             goto error;
-
-        // Show the window.
-        ShowWindow(__hwnd, SW_SHOW);
+        }
     }
-    else
-    {
-        // Attach to a previous windows
-        __hwnd = (HWND)__attachToWindow;
-        __hdc = GetDC(__hwnd);
 
-        SetWindowLongPtr(__hwnd, GWLP_WNDPROC, (LONG)(WNDPROC)__WndProc);
+    if (!initializeGL(&params))
+        goto error;
 
-        if (!initializeGL(NULL))
-            goto error;
-    }
+    // Show the window.
+    ShowWindow(__hwnd, SW_SHOW);
 
 #ifdef GP_USE_GAMEPAD
     // Initialize XInputGamepads.
@@ -992,9 +976,6 @@ int Platform::enterMessagePump()
     if (_game->getState() != Game::RUNNING)
         _game->run();
 
-    if (__attachToWindow)
-        return 0;
-
     // Enter event dispatch loop.
     MSG msg;
     while (true)

+ 6 - 6
samples/spaceship/src/SpaceshipGame.cpp

@@ -726,7 +726,7 @@ void SpaceshipGame::updateAchievements(double time)
 
 const SocialPlayer *SpaceshipGame::getPlayer(const char *name) const
 {
-	for (uint i = 0; i < _friends.size(); i++)
+	for (unsigned int i = 0; i < _friends.size(); i++)
 	{
 		if (strcmp(_friends[i].name.data(), name) == 0)
 			return &_friends[i];
@@ -737,7 +737,7 @@ const SocialPlayer *SpaceshipGame::getPlayer(const char *name) const
 
 const SocialChallenge *SpaceshipGame::getChallenge(const char *date) const
 {
-	for (uint i = 0; i < _challenges.size(); i++)
+	for (unsigned int i = 0; i < _challenges.size(); i++)
 	{
 		if (strcmp(_challenges[i].dateTimeIssued.data(), date) == 0)
 			return &_challenges[i];
@@ -768,7 +768,7 @@ void SpaceshipGame::loadFriendsEvent(ResponseCode code, std::vector<SocialPlayer
 
 		buildFriendsChooser();
 
-		for (uint i = 0 ; i < _friends.size(); i++)
+		for (unsigned int i = 0 ; i < _friends.size(); i++)
 		{
 			fprintf(stderr, "Friend %d is %s\n", i, _friends[i].name.data());
 		}
@@ -785,7 +785,7 @@ void SpaceshipGame::loadAchievementsEvent(ResponseCode code, std::vector<SocialA
 {
 	if (code == SUCCESS)
 	{
-		for (uint i = 0 ; i < achievements.size(); i++)
+		for (unsigned int i = 0 ; i < achievements.size(); i++)
 		{
 			fprintf(stderr, "Achievement %d is %s\n", i, achievements[i].name.data());
 		}
@@ -882,9 +882,9 @@ void SpaceshipGame::loadChallengesEvent(ResponseCode code, std::vector<SocialCha
 
 		buildChallengeChooser();
 
-		for (uint i = 0 ; i < challenges.size(); i++)
+		for (unsigned int i = 0 ; i < challenges.size(); i++)
 		{
-			fprintf(stderr, "Challenge score %lf issued on %s by %s for %s\n", challenges[i].score, challenges[i].dateTimeIssued.data(), challenges[i].issuedPlayerName.data(), challenges[i].challengedPlayerName.data());
+			fprintf(stderr, "Challenge score %lf issued on %s by %s for %s\n", challenges[i].score, challenges[i].dateTimeIssued.c_str(), challenges[i].issuedPlayerName.c_str(), challenges[i].challengedPlayerName.c_str());
 		}
 	}
 	else