Game architecture SceneKit

I am trying to create an architecture for a SceneKit iOS game. I showed below two rough high-level object charts / graphs of my current preferred ideas.

I only consider high-level architecture at the moment, i.e. I control the transition between the menu states / GameLevel / Config / Paused and making the application data-driven, so that it can handle several levels, etc. As soon as I get this work, then I will turn to a lower level architecture, for example, for the GameLevel state, I will have a GameLevelModel object to represent the actual logic of the game level.

Would it be nice to hear which one looks more promising, any obvious traps or things to avoid?

Version A) Based on MVC with custom containers and nested VC

I am trying to stay close to the MVC paradigm with this version.

The behavior of the application changes significantly between its various states (Menu / GameLevel / Config / etc), so I will use a constant container view controller that will control / transition between several nested VCs in relation to the parent-child according to Apple "View manual on controller programming for iOS. " These will be effective whole MVCs.

Since none of the Apple container controllers (UINavigation-, UISplitScreen-, UITabBar-) is suitable (I need the whole screen), I will have a custom VC container (RootViewController), in which there will always be one nested child VC. The view of each child VC will completely cover the container once. The transition between child VCs will be managed by RootVC and managed by its StateMachine.

Each child VC (effectively the entire MVC) is created each time its corresponding state becomes current and then freed when it is replaced by the next state, and is no longer required. As with the UINavigationController, it contains a VC.

, . SceneKit , SCNView SCNScenes, 3D-. .

                         --------------------------
                         |   RootViewController   |
                         --------------------------
                           |  |   |        |    |
     ------------------    |  |   |        |    |      ------------------
     | GameLevelsData |-----  |   |        |    -------|     SCNView    |
     ------------------       |   |        |           ------------------
     ------------------       |   |        |
     |   PlayerData   |--------   |        |
     ------------------           |        |
                                  |        |
                       ----------------    |
                       | StateMachine |    |
                       ----------------    |
                         |                 |
                         |-(*MenuState)    |
                         |-(LevelState)    |
                         |-(ConfigState)   |
                                           |
                                           |
                         ------------------------
                         |  MenuViewController  |
                         ------------------------
      -----------------     |                |      ------------------
      |   MenuData    |------                -------|  MenuSCNView   |
      -----------------                             ------------------

   (child VCs for other States, Level-/Config-/etc are created as needed)
                                           |
                         ------------------------
                         |  LevelViewController |
                         ------------------------
     ------------------     |                |      ------------------
     | GameLevelModel |------                -------|  LevelSCNView  |
     ------------------                             ------------------

B) ( VC, )

(GameViewController) (SCNView), . ( VC .)

(Menu/GameLevel/Config/etc) TouchHandlers ( UIResponder ), .

TouchHandler (Menu-, GameLevel- ..) touchesBegan/Moved/Ended canBecomeFirstResponder, . UIResponders. .

, , TouchHandler (GameLevelModel GameLevelState) .. .

, SKTransition SCNScenes SCNView 5-20 . , , , , . - SKTransition View scene scnView.scene = scnScene. .

                         --------------------------
                         |   GameViewController   |
                         --------------------------
                           |  |   |             |
     ------------------    |  |   |             |      ------------------
     | GameLevelsData |-----  |   |             -------|     SCNView    |
     ------------------       |   |                    ------------------
     ------------------       |   |                            |
     |   PlayerData   |--------   |                            |
     ------------------           |                            |
                                  |                            |
                       ----------------                        |
                       | StateMachine |                        |
                       ----------------                        |
                         |                            ------------------
                         |-(*MenuState)---------      |  MenuSCNScene  |
                         |-(LevelState)     |  |      ------------------
                         |-(ConfigState)    |  |
                                            |  |
                     --------------------   |  |
                     | MenuTouchHandler |---|  |
                     --------------------      |
                      -----------------        |
                      |   MenuData    |---------
                      -----------------

              (When entering, each state creates objects of corresponding
              dedicated subclasses for its Model, TouchHandler and Scene)
                                            |  |              |
                    --------------------    |  |     -------------------
                    | LevelTouchHandler |---|  |     |  LevelSCNScene  |
                    --------------------       |     -------------------
                     ------------------        |
                     | GameLevelModel |---------
                     ------------------

.

+4
2

, , , Apple SceneKit.

@HalMuelller, , , , .

enter image description here

:

, Game, . ObjC Swift.

Game , SCNScene , SceneKit/Model IO, .

Game Model, Animation, 3D- Player, , , Player , .

, PlayerEntity, BatterComponent, Entity-Component GamePlayKit. BatterComponent StateMachine, .

BatterControlComponent, , . , , macO/iOS. , . SpriteKit SCNScene.

, PitcherComponent, , .


GameViewController, SCNView, Game, - , . , .


Apple SceneKit GameKit. " Apple" " " : SceneKit GamePlayKit.


, Swift/ObjC GamePlayKit .


. . , , SceneKit Google - . , SceneKit , Apple, , - . , SceneKit , 2 (WWDC 17, 18) Apple. 2 $, , YMMV.

+4

, " MVC". MVC iOS model-view-controller, , MVC.

SCNView, B, . , SCNView. UIView/NSView SKView. SKView .

touch - . , . SceneKit.

, . , , tvOS macOS. VC, , . MVC, "Massive View Controller", , .

- /, , , , , . (, ), .

0

Source: https://habr.com/ru/post/1673452/


All Articles