Real information about Unreal Engine 3

Saturday, July 7, 2012

Split Screen

Unreal Engine 3 inherently supports split screen up to 4 viewports for 4 local players. In GameViewportClient.uc, there is an enum named ESplitScreenType, which lists different layouts for different numbers of players.
eSST_NONE
eSST_2P_HORIZONTAL
eSST_2P_VERTICAL
eSST_3P_FAVOR_TOP
eSST_3P_FAVOR_BOTTOM
eSST_4P
For a fast way to try it out, you might start UDK game and use the following console commands:
  • DebugCreatePlayer( ControllerId ): This command add one more local players into the game. You have to use different controller ID for each local player, or you can't control them properly.
  • DebugRemovePlayer( ControllerId ): Remove the local player with the specified controller ID. If there are many local players with the same ID, only the first player will be removed.
  • SSSwapControllers(): The command switches local players' controller ID to the next ones'. It is quite useful when you don't have enough game controllers to test split screen.
  • SetSplit( mode ): You can use the command to directly set split screen type. However, it only works when you choose a mode corresponding to the current number of players. It is useful to test layouts for the same number of players.

So How It Works?

Unreal Engine 3 defines a class named LocalPlayer to support more than one player on the same client. Each local player object represents an individual player in the same client program. Local player objects are stored in an array named "GamePlayers" of the engine instance. There are a lot of members in LocalPlayer. I just list a few you should know about split screen.
  • ControllerId [ int ]: This specifies the game controller which the player get input from. This ID starts with zero. Each game controller you plug in gets a different ID.
  • Origin [ Vector2d ]: The origin of the viewport for this local player.
  • Size [ Vector2d ]: The width and height of the viewport for this local player.
With respect to split screen, LocalPlayer serves as a data storage for each player. To layout and draw each player's viewport, it is the job of GameViewportClient. The important members related to split screen in GameViewportClient are as follows:
  • SplitScreenInfo [array<SplitScreenData>]: This array stores the viewport layouts for each player in different split screen types. Each entry of this array is corresponding to a split screen type.
  • DesiredSplitScreenType [ESplitScreenType]: Specifies the new split screen type to change.
  • ActiveSplitScreenType [ESplitScreenType]: The split screen type currently used.
  • UpdateActiveSplitscreenType(): Update the value of ActiveSplitScreenType based on the number of local players and DesiredSplitScreenType. Subclasses can override this function to add more consideration.
  • LayoutPlayers(): This event is triggered every frame by the engine before draw the viewport. It updates the active screen split type and resets the viewport layout of each local player with the active type. It also notifies UI system if the screen split type is changed, so UI system can update accordingly.
  • CreateInitialPlayer(): This function is called by this class' Init(), which is in turn called when the engine is being initialized. It is used to create an initial player, so it is a good place to override if you want more initial local player.

0 comments :

Post a Comment

Followers

AD (728x90)

Powered by Blogger.