| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- local gameStateWorld = class('gameStateWorld')
- function gameStateWorld:ctor()
- end
- function gameStateWorld:getStateType()
- return global.MMO.GAME_STATE_WORLD
- end
- --- enter
- function gameStateWorld:onEnter()
- self:RegisterWorld()
- self:SyncCppState()
- self:InitWorld()
- self:EnterWorld()
- return 1
- end
- function gameStateWorld:RegisterWorld()
- local facade = global.Facade
- -- command
- facade:removeCommand( global.NoticeTable.RegisterWorldController )
- facade:removeCommand( global.NoticeTable.RegisterWorldMediator )
- facade:removeCommand( global.NoticeTable.RegisterWorldProxy )
- -- loading mediator
- local LoadingMediator = requireMediator( "loading_layer/LoadingMediator" )
- facade:removeMediator(LoadingMediator.NAME)
- end
- function gameStateWorld:SyncCppState()
- local facade = global.Facade
- local cppEnv = global.gameEnvironment
- local AuthProxy = facade:retrieveProxy(global.ProxyTable.AuthProxy)
- local LoginProxy = facade:retrieveProxy(global.ProxyTable.Login)
- cppEnv:SetLoginAccount( AuthProxy:GetUID() )
- cppEnv:SetLoginServer( LoginProxy:GetSelectedServerId() )
- end
- function gameStateWorld:InitWorld()
- local facade = global.Facade
- -- laoding close
- facade:sendNotification(global.NoticeTable.Layer_LoadingBar_Close)
- -- init resolution size & policy
- local normalPolicy = global.DesignPolicy
- local designSize = global.DesignSize_Oth
- local glview = global.Director:getOpenGLView()
- if global.isWinPlayMode and glview then
- -- keep camera zoom(FrameSize == ViewPortSize)
- designSize = glview:getFrameSize()
- end
- local resolutionData = {}
- resolutionData.rType = normalPolicy
- resolutionData.size = designSize
- facade:sendNotification(global.NoticeTable.ChangeResolution, resolutionData)
- -- init layer facade
- local LayerFacadeMediator = requireMediator( "LayerFacadeMediator" )
- local layerFacade = facade:retrieveMediator( LayerFacadeMediator.NAME )
- layerFacade:InitOnEnterWorld()
- global.JsonProtoHelper:init()
- global.BehaviorController:InitOnEnterWorld()
- global.userInputController:InitOnEnterWorld()
- global.actorManager:InitOnEnterWorld()
- end
- function gameStateWorld:EnterWorld()
- local facade = global.Facade
- -- notify server
- local loginProxy = facade:retrieveProxy( global.ProxyTable.Login )
- loginProxy:EnterWorld()
- -- register msg handler
- local noticeProxy = facade:retrieveProxy( global.ProxyTable.NoticeProxy )
- noticeProxy:RegisterMsgHandlerAfterEnterWorld()
- -- register msg handler
- global.SUIManager:RegisterMsgHandlerAfterEnterWorld()
- local ChatProxy = global.Facade:retrieveProxy(global.ProxyTable.Chat)
- ChatProxy:RegisterMsgHandlerAfterEnterWorld()
- end
- function gameStateWorld:onEnd()--重启
- self:onExit()
- end
- --- exit world
- function gameStateWorld:onExit()
- self:CleanWorld()
- global.Facade:sendNotification( global.NoticeTable.ReleaseMemory)--清理完再释放
- self:LeaveWorld()
- self:Destory()
- return 1
- end
- function gameStateWorld:LeaveWorld()
- local facade = global.Facade
- global.userInputController:ResetKeyboard()
- global.userInputController:ResetTouch()
-
- facade:sendNotification(global.NoticeTable.Layer_Notice_Close, SLBridge:CheckLuaEventCleaned())
- facade:sendNotification(global.NoticeTable.Layer_CommonTips_Close)
- --
- global.LuaBridgeCtl:SetModulesSwitch( global.MMO.Modules_Index_Enable_Check_Heart_Beat, 0 )
- -- unregister world
- facade:sendNotification( global.NoticeTable.UnRegisterOther )
- facade:sendNotification( global.NoticeTable.UnRegisterWorldProxy )
- facade:sendNotification( global.NoticeTable.UnRegisterWorldMediator )
- facade:sendNotification( global.NoticeTable.UnRegisterWorldController )
-
- --清理收货和试玩状态
- global.IsReceiveRole = false
- global.IsVisitor = false
- -- clear cocos2d event
- -- clear cocos2d scheduler, but system scheduler( ActionManager )
- -- clear cocos2d action
- -- clear cocos2d audio
- local director = cc.Director:getInstance()
- local currScene = global.Director:getRunningScene()
- director:getEventDispatcher():removeEventListenersForType(1)
- director:getEventDispatcher():removeEventListenersForType(2)
- director:getEventDispatcher():removeEventListenersForType(3)
- director:getEventDispatcher():removeEventListenersForType(4)
- director:getEventDispatcher():removeEventListenersForType(5)
- director:getEventDispatcher():removeEventListenersForTarget(currScene, true)
- director:getScheduler():unscheduleAllWithMinPriority( cc.PRIORITY_NON_SYSTEM_MIN )
- director:getActionManager():removeAllActions()
- cc.AsyncTaskPool:getInstance():stopTasks(cc.AsyncTaskPool.TaskType.TASK_IO)
- cc.SimpleAudioEngine:destroyInstance()
- ccexp.AudioEngine:uncacheAll()
- global.HttpDownloader:reset()
- local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
- AuthProxy:resetDownloader()
- -- unregister script handle
- if currScene then
- local function disableEvents(node)
- if tolua.type(node) == "cc.TableView" then
- else
- node:disableNodeEvents()
- end
- local children = node:getChildren()
- for k, v in pairs(children) do
- disableEvents(v)
- end
- end
- disableEvents(currScene)
- end
- -- replace scene
- local scene = cc.Scene:create()
- local currScene = global.Director:getRunningScene()
- if not currScene then
- global.Director:runWithScene( scene )
- else
- global.Director:replaceScene( scene )
- end
- local LayerFacadeMediator = requireMediator( "LayerFacadeMediator" )
- local lFMediator = facade:retrieveMediator(LayerFacadeMediator.NAME)
- lFMediator:InitOnEnterActive(scene)
- director:getTextureCache():removeUnusedTextures()
- cc.SpriteFrameCache:getInstance():removeUnusedSpriteFrames()
- -- clear net msg
- local netClient = global.gameEnvironment:GetNetClient()
- netClient:CleanAllMessageHandler()
- LuaNetworkController:Inst():UnregisterAllLuaHandler()
- end
- function gameStateWorld:CleanWorld()
- -- logic
- global.BuffManager:Cleanup()
- global.ActorEffectManager:Cleanup()
- global.gameMapController:Cleanup()
- global.netNpcController:Cleanup()
- global.netMonsterController:Cleanup()
- global.netPlayerController:Cleanup()
- global.gamePlayerController:Cleanup()
- global.dropItemController:Cleanup()
- global.actorRefreshController:Cleanup()
- global.actorInViewController:Cleanup()
- -- actor
- global.actorManager:Cleanup()
- global.HUDManager:Cleanup()
- -- scene
- global.dropItemManager:Cleanup()
- global.monsterManager:Cleanup()
- global.npcManager:Cleanup()
- global.playerManager:Cleanup()
- global.sceneGraphCtl:Cleanup()
- global.sceneManager:Cleanup()
- global.sceneEffectManager:Cleanup()
- -- skill
- global.skillManager:Cleanup()
- global.GameActorSkillController:Cleanup()
- -- anim cleanup
- global.FrameAnimManager:unloadAllUnusedAnimData()
- -- clean
- global.ResDownloader:CleanupDownloadCount()
- -- spine batch
- if sp and sp.SkeletonBatch then
- sp.SkeletonBatch:destory()
- end
- end
- function gameStateWorld:Destory()
- if global.sceneManager then
- global.sceneManager:destory()
- global.sceneManager = nil
- end
- if global.mouseEventController then
- global.mouseEventController:destory()
- global.mouseEventController = nil
- end
-
- if global.gamePlayerController then
- global.gamePlayerController:destory()
- global.gamePlayerController = nil
- end
- if global.netPlayerController then
- global.netPlayerController:destory()
- global.netPlayerController = nil
- end
- if global.netMonsterController then
- global.netMonsterController:destory()
- global.netMonsterController = nil
- end
-
- if global.netNpcController then
- global.netNpcController:destory()
- global.netNpcController = nil
- end
-
- if global.dropItemController then
- global.dropItemController:destory()
- global.dropItemController = nil
- end
-
- if global.gameMapController then
- global.gameMapController:destory()
- global.gameMapController = nil
- end
- if global.actorRefreshController then
- global.actorRefreshController:destory()
- global.actorRefreshController = nil
- end
-
- if global.actorInViewController then
- global.actorInViewController:destory()
- global.actorInViewController = nil
- end
- if global.GameActorSkillController then
- global.GameActorSkillController:destory()
- global.GameActorSkillController = nil
- end
- if global.actorManager then
- global.actorManager:destory()
- global.actorManager = nil
- end
- if global.monsterManager then
- global.monsterManager:destory()
- global.monsterManager = nil
- end
- if global.playerManager then
- global.playerManager:destory()
- global.playerManager = nil
- end
- if global.npcManager then
- global.npcManager:destory()
- global.npcManager = nil
- end
- if global.dropItemManager then
- global.dropItemManager:destory()
- global.dropItemManager = nil
- end
- if global.sceneEffectManager then
- global.sceneEffectManager:destory()
- global.sceneEffectManager = nil
- end
- if global.skillManager then
- global.skillManager:destory()
- global.skillManager = nil
- end
- if global.HUDManager then
- global.HUDManager:destory()
- global.HUDManager = nil
- end
-
- if global.HUDHPManager then
- global.HUDHPManager:destory()
- global.HUDHPManager = nil
- end
- if global.BuffManager then
- global.BuffManager:destory()
- global.BuffManager = nil
- end
-
- if global.DObstacleController then
- global.DObstacleController:destory()
- global.DObstacleController = nil
- end
-
- if global.sceneGraphCtl then
- global.sceneGraphCtl:destory()
- global.sceneGraphCtl = nil
- end
- if global.gameWorldController then
- global.gameWorldController:destory()
- global.gameWorldController = nil
- end
-
- if global.PathFindController then
- global.PathFindController:destory()
- global.PathFindController = nil
- end
-
- if global.BehaviorController then
- global.BehaviorController:destory()
- global.BehaviorController = nil
- end
-
- if global.ActorEffectManager then
- global.ActorEffectManager:destory()
- global.ActorEffectManager = nil
- end
- global.WidgetCacheManager = nil
- end
- return gameStateWorld
|