{"id":31,"date":"2007-09-03T18:42:46","date_gmt":"2007-09-03T17:42:46","guid":{"rendered":"http:\/\/blog.jbriguet.com\/?p=31"},"modified":"2010-01-25T20:38:00","modified_gmt":"2010-01-25T19:38:00","slug":"multiplayer-and-viewports","status":"publish","type":"post","link":"https:\/\/blog.jbriguet.com\/?p=31","title":{"rendered":"Multiplayer and viewports"},"content":{"rendered":"<p>Ok, a few weeks ago, i implemented multiplayer views on my race game, and, i have to admit, it was pretty easy. (Thanks to XNA, defining a viewport is only a few lines of code)<\/p>\n<p>so, here is the code i use to set each player it&#8217;s part in the screen (for one to four players, you just have to call this function before you draw your player X stuff).<\/p>\n<pre class=\"brush:csharp collapse:true\">\r\n\t\tprivate void SetupViewport()\r\n\t\t{\r\n\t\t\t\/\/ 1 player\r\n\t\t\tif (m_raceScreen.InitDatas.TotalPlayerCount == 0) \r\n\t\t\t\treturn; \/\/ don't touch viewport, we're obviously the only player :)\r\n\t\t\t\r\n\t\t\tViewport v = new Viewport();\r\n\t\t\tv.X = 0;\r\n\t\t\tv.Y = 0;\r\n\t\t\tv.Width = XeGame.Device.PresentationParameters.BackBufferWidth;\r\n\t\t\tv.Height = XeGame.Device.PresentationParameters.BackBufferHeight;\r\n\r\n\t\t\t#region 2 players\r\n\t\t\tif (m_raceScreen.InitDatas.TotalPlayerCount == 1) \/\/ 2 player\r\n\t\t\t{\r\n\t\t\t\tif (v.Height > v.Width) \/\/ cut height in 2\r\n\t\t\t\t{\r\n\t\t\t\t\tv.Height = v.Height \/ 2;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.One)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Y = 0;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Two)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Y = v.Height;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tv.Width = v.Width \/ 2;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.One)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.X = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Two)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.X = v.Width;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t#endregion\r\n\r\n\t\t\t#region 3 players\r\n\t\t\tif (m_raceScreen.InitDatas.TotalPlayerCount == 2) \/\/ 3 player\r\n\t\t\t{\r\n\t\t\t\tif (v.Height > v.Width)\r\n\t\t\t\t{\r\n\t\t\t\t\tv.Height = v.Height \/ 3;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.One)\r\n\t\t\t\t\t\tv.Y = 0;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Two)\r\n\t\t\t\t\t\tv.Y = v.Height;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Three)\r\n\t\t\t\t\t\tv.Y = v.Height * 2;\r\n\t\t\t\t}\r\n\t\t\t\telse \/\/ standard case (4\/3, 16\/9, 16\/10)\r\n\t\t\t\t{\r\n\t\t\t\t\tv.Width = v.Width \/ 2;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.One)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Y = 0;\r\n\t\t\t\t\t\tv.X = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Two)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Height = v.Height \/ 2;\r\n\t\t\t\t\t\tv.X = v.Width;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Three)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Height = v.Height \/ 2;\r\n\t\t\t\t\t\tv.X = v.Width;\r\n\t\t\t\t\t\tv.Y = v.Height;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t#endregion\r\n\r\n\t\t\t#region 4 players\r\n\t\t\tif (m_raceScreen.InitDatas.TotalPlayerCount == 3) \/\/ 4 player\r\n\t\t\t{\r\n\t\t\t\tif (v.Height > v.Width)\r\n\t\t\t\t{\r\n\t\t\t\t\tv.Height = v.Height \/ 4;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.One)\r\n\t\t\t\t\t\tv.Y = 0;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Two)\r\n\t\t\t\t\t\tv.Y = v.Height;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Three)\r\n\t\t\t\t\t\tv.Y = v.Height * 2;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Four)\r\n\t\t\t\t\t\tv.Y = v.Height * 3;\r\n\t\t\t\t}\r\n\t\t\t\telse \/\/ standard case\r\n\t\t\t\t{\r\n\t\t\t\t\tv.Width = v.Width \/ 2;\r\n\t\t\t\t\tv.Height = v.Height \/ 2;\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.One)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Y = 0;\r\n\t\t\t\t\t\tv.X = 0;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Two)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.Y = 0;\r\n\t\t\t\t\t\tv.X = v.Width;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Three)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.X = 0;\r\n\t\t\t\t\t\tv.Y = v.Height;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (this.m_playerIndex == PlayerIndex.Four)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tv.X = v.Width;\r\n\t\t\t\t\t\tv.Y = v.Height;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t#endregion\r\n\r\n\t\t\tXeGame.Device.Viewport = v;\r\n\t\t}\r\n<\/pre>\n<p>Actually, a lot of work have been made when i see the screenshots i took 3 months ago. (Sun is now a big heap of particles, models have been smoothed a lot, physics are almost in place, post scree processing engine have been integrated, and the SceneRenderManager is almost ready, and will makes render a lot simpler)<\/p>\n<p>See by yourself : <a href='https:\/\/blog.jbriguet.com\/wp-content\/uploads\/2007\/09\/xe-2007-09-03-19-50-08-89.jpg' title='Four players' target=_blank><img src='https:\/\/blog.jbriguet.com\/wp-content\/uploads\/2007\/09\/xe-2007-09-03-19-50-08-89.thumbnail.jpg' alt='Four players' \/><\/a> <a href='https:\/\/blog.jbriguet.com\/wp-content\/uploads\/2007\/09\/xe-2007-09-03-19-51-41-42.jpg' title='Sun, planets and ship' target=_blank><img src='https:\/\/blog.jbriguet.com\/wp-content\/uploads\/2007\/09\/xe-2007-09-03-19-51-41-42.thumbnail.jpg' alt='Sun, planets and ship' \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, a few weeks ago, i implemented multiplayer views on my race game, and, i have to admit, it was pretty easy. (Thanks to XNA, defining a viewport is only a few lines of code) so, here is the code i use to set each player it&#8217;s part in the screen (for one to four [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-3"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6Eo2-v","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":3,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jbriguet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}