How Game.swf find map files

Post here your questions about the OpenSpace 2.x or notify bugs and suggestions.

Moderators: Lapo, Bax

Nigey
Posts: 35
Joined: 17 Dec 2014, 21:55

How Game.swf find map files

Postby Nigey » 19 Jan 2015, 12:27

Hi Guys,

I've been reading through the manuals and the API's. I can't find a section which explains how the main game's .fla (and the OpenSpace compiled clip in it), recognises the location for all the maps that are created and exported by the OpenSpace Map Editor. I have an existing project that I have just taken over. The game's swf source location has a folder named 'maps', It contains the following code in 'MapsLoadingManager':

Code: Select all

      private function loadMapAssets(skinSwfFilenames:Array, bgSwfFilenames:Array):void
      {
         /* IMPORTANT NOTE: for sake of simplicity, in this example both skins and backgrounds swf files are loaded in the same application domain.
         A number of improvements should be made:
         1) application domains should be kept separate between skins and backgrounds swf files, in order to avoid possible conflicts in case the class definitions they contain have the same names;
         2) in case the loaded map shares the same swf files of the previous map, reloading is unnecessary and should be avoided not to waste memory;
         3) if swf files for the previous map are not needed anymore, they should be unloaded. */
         
         mapAssetsLibrariesAppDomain = new ApplicationDomain()
         var fileNames:Array = skinSwfFilenames.concat(bgSwfFilenames)
         loadCounter = fileNames.length
         tempLoaders = [] // We have to keep a reference to the loaders to avoid a bug in the Flash Player: http://bugs.adobe.com/jira/browse/FB-13014
         
         if (loadCounter > 0)
         {
            main.logTrace("External swf files to be loaded: " + fileNames)
            
            for (var i:int = 0; i < loadCounter; i++)
            {
               var loader:Loader = new Loader()
               tempLoaders.push(loader)
               
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMapSwfFileLoaded)
               
               var request:URLRequest = new URLRequest("libraries/" + fileNames[i])
               var context:LoaderContext = new LoaderContext(false, mapAssetsLibrariesAppDomain)
               
               loader.load(request, context)
            }
         }
         else
            onMapSwfFileLoaded(null)
      }
      
      /**
       * swf file loaded: when all the required swf files are loaded, map rendering can be launched.
       */
      private function onMapSwfFileLoaded(evt:Event):void
      {
         loadCounter--
         
         if (loadCounter <= 0)
         {
            main.logTrace("External libraries loaded, now the loaded map can be rendered")
            
            // The same value is passed to both skinAppDomain and bgAppDomain parameters: check the comment to loadMapAssets method above.
            openSpace.skinAppDomain = mapAssetsLibrariesAppDomain
            openSpace.bgAppDomain = mapAssetsLibrariesAppDomain
            
            // Render map
            openSpace.renderMap()
         }
      }


However I'm unsure whether this is creating a reference to the actual maps themselves which hold the tile coordinates for each map, or whether this simply creates a reference to all the swf assets which are used in the game by the map editor.

Is there somewhere which gives a breakdown of how the game's .fla (and OpenSpace) recongnise and collect map data? If not, could someone please let me know how OpenSpace collects the original map data when the game loads?

Many Thanks
Nigel
User avatar
Bax
Site Admin
Posts: 4608
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: How Game.swf find map files

Postby Bax » 19 Jan 2015, 17:49

The map data is loaded by the server side Extension, which in turn will send it to the client when the map loading process is started.
In other words you have to save the maps exported by the Editor in the "data" folder of your Extension folder.
On the client side the "loadMapAssets" just loads the SWF files which contain the graphical assets required by the client to render the map. The actual map data (which tiles in which positions) is provided by the server.
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 10 guests