Author Topic: Copying maps at runtime  (Read 3790 times)

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Copying maps at runtime
« on: 2009-12-08, 02:19:56 PM »
Hi guys!

Quick question: I'm wondering how to accomplish a little stunt with the minimap in my game.  Here's what I'm trying to do.  During the game, the minimap shows on the top left corner of the screen.  It's working fine but I had some complains about the minimap not being helpful enough.  Some of my testers want to keep the minimap as is AND also have to possibility to show the complete map in the menu to have a better idea of the global game world.

I think it's a really good idea.  But I don't see how to accomplish this.  I don't think I can alter the map properties at runtime (display area, location, etc) nor do I want to do it.  I don't want to mess around with the minimap.  I would like to make a copy of the minimap as it is and show it with different dimensions in the menu when the game is asked to show the complete map and discard it afterward.  Now, here is another catch: the map doesn't display info only based on global counters, it keeps most information into the sprites in the minimap, so I cannot make another identical minimap in the project with different properties (display area, etc), I really must copy the minimap to keep all this information.

Any idea on how to accomplish this?  I didn't make any attempt to do this yet.  I'm just wondering if you have any suggestions on the best way to accomplish this.

Thanks a lot again! :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Copying maps at runtime
« Reply #1 on: 2009-12-08, 06:20:08 PM »
I don't know how well this would work, but you could try saving/serializing the mini map data the same way the SaveGame function saves a map, and create a new map from it the same way LoadGame does, then just change the display parameters of the map and throw it away when you're done.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Copying maps at runtime
« Reply #2 on: 2009-12-09, 08:23:17 AM »
Thanks bluemonkmn!

I'll start looking there. :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Copying maps at runtime
« Reply #3 on: 2009-12-14, 11:31:46 AM »
Hi!  I'm still working on this and I a little stuck.  Can someone help me out?  Here's what I've got so far:

Code: [Select]
   
   // a field used to store the minimap that will be shown at fullsize
   public MiniMap_Map FullMinimap; 
   // a field used to store the minimap as is so it can be easily restored when the fullsize minimap is flushed
   public MiniMap_Map SavedMinimap;

   [Description("Show Full Minimap.")]
   public void ShowFullMinimap()
   {
      //var
      int Slot = 99;
      System.Collections.Hashtable LoadedFullMinimap = new System.Collections.Hashtable();
      System.Collections.DictionaryEntry MiniDe = new System.Collections.DictionaryEntry();

      //From IncludeMapInSaveUnit
      SaveUnit MinimapSaveUnit = new SaveUnit();
      MinimapSaveUnit.Maps = new System.Collections.Hashtable();
      MinimapSaveUnit.Maps[typeof(MiniMap_Map)] = Project.GameWindow.LoadedMaps[typeof(MiniMap_Map)];

      //From SaveGame
      System.IO.Stream stm;
      stm = new System.IO.MemoryStream();
      using(stm)
      {
         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
         bf.Serialize(stm, MinimapSaveUnit);
         memorySaveSlots[Slot] = ((System.IO.MemoryStream)stm).ToArray();
         MinimapSaveUnit = null;
      }

      //From LoadGame
      stm = new System.IO.MemoryStream((byte[])memorySaveSlots[Slot], false);

      using(stm)
      {
         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
         SaveUnit unit = (SaveUnit)bf.Deserialize(stm);
         if (unit.Maps != null)
         {
            LoadedFullMinimap = unit.Maps;
         }         
      }
      FullMinimap = (MiniMap_Map)(LoadedFullMinimap[typeof(MiniMap_Map)]);
      SavedMinimap = FullMinimap;

      /[color=red]/Custom Settings, I want to change the size of the display area of the map here before showing it.  But I can't find the way to do it properly.  TotalView changes are not supported, I can't find the "Map View" property (you know with X, Y, Height and Width in the designer)[/color]
      //FullMinimap.m_Display.?

      Project.GameWindow.OverlayMap = FullMinimap;
   }

   [Description("Flush Full Minimap.")]
   public void FlushFullMinimap()
   {
      Project.GameWindow.OverlayMap = SavedMinimap;
      SavedMinimap = null;
      FullMinimap = null;
   }


   #endregion

With the code as it is, I have two problems:
1- It doesn't seem to save the minimap properly because when I call the show Minimap and flush minimap function, I see the "switch" but I always get a clean, brand new minimap...
2- I don't know how to change the display property of the minimap.  Seems to me that everything is locked or not supported...  How can I alter stuff here?

Any ideas? 

Thanks! :)
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Copying maps at runtime
« Reply #4 on: 2009-12-14, 11:44:59 AM »
Huh, oops, bad post
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Copying maps at runtime
« Reply #5 on: 2009-12-14, 01:09:39 PM »
Code: [Select]
      FullMinimap = (MiniMap_Map)(LoadedFullMinimap[typeof(MiniMap_Map)]);
      SavedMinimap = FullMinimap;

So after this, SavedMinimap and FullMinimap both refer to the loaded full mini map right?  Is that what you want?  Didn't you want to save the mini map as it was rather than refer to a copy of the loaded one?

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Copying maps at runtime
« Reply #6 on: 2009-12-14, 01:24:00 PM »
The Fullminimap is the map I want to modify
The SavedMinimap is the normal minimap (not modified) that will be restored after the full minimap is discarded.

If I am not mistaken, saving the minimap as it is now should not be a problem, because at this point the Fullminimap was saved from the original minimap, loaded from the save stream and not modified in any way.  So at this point, I assign the FullMinimap to SavedMinimap but since it should be an exact copy of the original minimap, it's ok.  Then, starting from there, I want to modify FullMinimap only.  When modifications are finished, I show FullMinimap in the overlay map.  When the player is done with the fullminimap, I call FlushFullMinimap so I put SavedMinimap in the overlay map and set SavedMinimap and FullMinimap to null.

But, if you have a way to save the minimap before it is loaded (so much sooner in the whole process) it's ok too.  I just wasn't sure how to access the minimap before the saving and loading process.

Thanks a lot!  ;D
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Copying maps at runtime
« Reply #7 on: 2009-12-15, 06:35:45 AM »
What I don't understand in the code above is why you have two variables referring to the same object.  Any change to one will affect both.

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Copying maps at runtime
« Reply #8 on: 2009-12-15, 08:18:03 AM »
Oh...  I thought that assigning the map to another variable would make a "copy" of the value, not "refer" to the same instance of it.  If it does indeed only point toward the same object rather than making a copy of it, I'm obviously mistaken in my approach...
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com

Vincent

  • SGDK2 Addict
  • Expert
  • Fanatic
  • *****
  • Posts: 612
  • Legacy of Kain: Revival is completed!!!
    • View Profile
    • Chivalrous Games
    • Email
Re: Copying maps at runtime
« Reply #9 on: 2009-12-17, 12:32:59 PM »
Well, that's done!  See attachments to see what the normal minimap looks like and what the full minimap looks like.

I can switch between both maps easily.  Finally, I scrapped the whole save and load approach.  I figured that I could activate some stuff in the map when it is small and deactivate them when it is full.  I know when it is small or full by setting a counter, easy as that. 

So since I don't need to make drastic modifications between both versions of the minimap, I decided to simply modify the size of the map view. 

I had a hard time finding the propertie holding the view size... simply because it's not in mapbase.cs.  In fact it's a field that is created when the project is generated, so I found it in Minimap_Map.cs.  It's name is m_View.  Since it is a private field and no properties point toward it, I added a public property to get and set m_View, that I called M_View.  So when I set M_View, I can move, resize the minimap as I want.

So when I call my custom function ShowFullMinimap, I set M_View to show the whole mininap and when I call my custom function FlushMinimap, I set M_View back to size of the minimap.

All done and no need for saving and loading! :)


Thanks guys!  ;D
Legacy of Kain: Revival completed!
http://lokrevival.webs.com

See also my company website:
http://chivalrousgames.com