Viewports

Koshling

Vorlon
Joined
Apr 11, 2011
Messages
9,254
Viewports are finally in the SVN! This post explains what they are, what they are for, and what to watch out for if you want to try them.

What are Viewports?

A viewport is a window into the map, which we pretend (to the display game engine) is the entire map, so that it only needs to load graphics resources for entities within the viewport. The viewport can be moved around by the player (e.g. - once your civ gets large and you have units that are not all fit in the viewport at the same time), and are invisible to the AI (so it continues to see one big map and will not be affected)

What benefits do viewports bring?

The main benefit is that the game takes significantly less memory to run large maps, so ultimately these should solve the MAF problem. A secondary benefit arises once we add multi-maps, which is that the presence of viewports will mean that individual maps in a multi-map setup will not have to be the same size (which they otherwise would). Some UI concepts needed for multi-maps are also required for viewports, so we'll also get some early UI experience that can help drive the development of the multi-maps themselves

What are the disadvantages of using viewports?

Viewports make the gameplay, once action spreads over a large area a little more inconvenient, because you need to switch viewports to see activity in places not within the current one. This switching has some slight rough edges still (see later), and takes a few seconds. Also play near the edge of a viewport is a bit 'weird' because you can't see anything past the edge no matter how close you are to it. Some auto-switching of viewports takes place to try to alleviate the impact of this (see later)

How do I enable viewports?

By default viewports are turned off. To enable them you need to edit one or more values in assets/xml/ParallelMaps_GlobalDefines.xml. The default version looks like this:
Code:
<?xml version="1.0"?>

<!-- Global Defines -->
<Civ4Defines xmlns="x-schema:CIV4GlobalDefinesSchema.xml">

  <Define>
    <DefineName>ENABLE_VIEWPORTS</DefineName>
    <iDefineIntVal>1</iDefineIntVal>
  </Define>
  <Define>
    <DefineName>VIEWPORT_SIZE_X</DefineName>
    <iDefineIntVal>60</iDefineIntVal>
  </Define>
  <Define>
    <DefineName>VIEWPORT_SIZE_Y</DefineName>
    <iDefineIntVal>30</iDefineIntVal>
  </Define>
  <Define>
    <DefineName>VIEWPORT_FOCUS_BORDER</DefineName>
    <iDefineIntVal>2</iDefineIntVal>
  </Define>
</Civ4Defines>
To enable viewports change the value of ENABLE_VIEWPORTS from 0 to 1. The next two values control the viewport size (which is fixed within any load of the game, but can be changed between loads - see later for considerations when choosing an appropriate size). The final value (VIEWPORT_FOCUS_BORDER) controls how close units or cities you are interacting with (usually the one that is selected) can be before triggering an auto viewport switch to center them.

How do I control the viewport?

Assuming you have viewports enabled your main screen should look pretty much as it always did. The only difference is that it will appear as though the map is just what is in the veiwport (and maps that wrap on the underlying map won't on the viewport unless it is the same size in the wrapping dimension as the underlying map). As play progresses and different units get auto-selected for you to move (or different cities ask you for new build orders), if that unit or city is not within the current viewport (actually within by at least the VIEWPORT_FOCUS_BORDER amount set in the global defines) then the viewport will automatically move to bring the unit or city the game wants to select next into view. It will adjust the normal unit cycle to process as many units as possible between viewport switches (i.e. - seek to minimize the number of switches required in a turn). It doesn't yet do this for cities, so you may want to use build queues more than you might have done previously to help with that. If you want to proactively move the viewport there are two ways to do this:

1) Clicking on a city in the domestic advisor will bring it into view, changing the viewport if necessary to achieve that
2) The map in the military advisor is always the entire (underlying) map (so that all your troops are on it). Clicking anywhere on the map in the military advisor which is not inside the current viewport will re-center the viewport there.

What is currently still a rough edge?

This is a first usable version, intended to attract feedback and demonstrate some initial capability towards what we need for multi-maps. It still has some rough edges that I have either not yet been able to smooth out, or not had sufficient time to do so. The main things I am aware of are:
  • Not processing cities in an order that would minimize viewport switching, as mentioned previously
  • Lack of good user feedback that something is happening during a switch, which might take several seconds
  • Sometimes, after a switch, the selection ring for the selected unit, or its flag somehow wind up displaced from the unit by a few tiles! This doesn't happen nearly as often as it did in an earlier build, but I have not been able to understand and eliminate it entirely. If this happens, just clicking on another unit and back cures it, and it anyway doesn't really affect anything fucntionally
  • Unit paths that are valid on the underlying map, but go off the viewport (for example a ship that needs to sail around the end of a landmass which is out of view) are not displayable. They do EXECUTE ok, but not display, so if you have a unit selected and click a destination, holding the mouse button down to display the path will claim it's not possible, but releasing the mosue button there (or just clicking in the first place) will actually execute the necessary path. Waypoints should work fine, but again if you select a unit that is part way through moving to a distant waypoint its path will not display if that path goes of the current viewport

Considerations for setting viewport size

There are a few factors to take into account when choosing a viewport size (the default I have set is 40 X 40, which should be reasonable in most cases):
  • Larger viewports require less switching and have usability benefits
  • Smaller viewports result in faster switching, and less memory usage
  • It's probably a good idea to keep the general shape (form factor) of your viewport similar to that of the map you're playing on. The reason for this is down to limitations in the game engine, and how the military advisor map works. Basically the game engine has the concept of a map (one, which it thinks is just the viewport), and a minimap (which is the small inset map in the lower left corner of the main screen). The minimap is key - it has to show the same content as the main map, and the map in the military advsor IS the minimap (just displayed larger). Because we need to display the entire underlying map in the military advisor this means we need to do a viewport switch going into and out of the advisor (so it'll take a couple of seconds to display and close). The viewport we use when inside the advisor is special (and a bit weird) - because the 'map' (aka viewport) size cannot change (the game engine's concept of a map is a fixed size singular thing) and yet we need to display the entire underlying map in the military advisor minimap, it means we have to 'sample' the actual map to obtain a sort of low-res view of it which we can display in the resolution of the viewport. This scaling will distort the shaps of the map unless the form factor of the underlying map and the viewport are the same. This isn't a functional issue, but it looks a little odd (try GEM with a square viewport and you'll see what I mean!). Very small viewports don't work well with the military advisor for this reason (scaling GEM down to 10 X 10 resolution doesn't give a very useful world map!)

What might be added in future?

There are no promises here, as it depends on what turns out to be possible, and whether it's the best use of effort. However, things I have in mind, in principal:
  • Fix crashes! This has to happen obviously
  • Possibly try to find a way to resolve the display of paths that go off-viewport. I have an idea of how this might be done, but it would mean sacrificing a border of black (never revealed) tiles around the edge of the viewport. It's also going to be really rather complex and may not be possible at all
  • Separate out the UI for managing viewports from the military advisor (at least as the primary place to go). What I have in mind is a separate advisor-like screen that displays some sort of outline representation of the entire (underlying map), and shows rectangular outlines for the viewports currently set up (the code supports more than one, though the current UI doesn't let you access that functionality). It would allow you to name viewports (e.g. - 'European theatre', 'North America', etc.) and display a list of them, highlighting where they are on the map as you select them, and allowing switching to them via the list. Such a screen could very naturally then be extended to support multi-map navigation
  • Possibly add some viewport caching. This would cost memory but make switching between (cached) viewports MUCH faster. My intention would be for the game to figure out how much memory you have, how much is in use, and juggle the cache accordingly to maximize your switching speed, but sacrifice that for memory as you approach the limits of your available memory
 
So I was testing a current game which has given me MAFs. With the viewports I have been able to continue. However when trying to move a horse archer to the edge of the map it crashed. Here is the minidump.

Also how do you get a unit from one viewport to another?

Open the military advisor and click the region just off the viewport near theunit you need to move off it. That will recenter the viewport on the area you click, so should leave the unit in question near the middle, so the move you need to make will no longer be near an edge.

Can you describe the move you attempted in more detail? Was the click you made to move it on the very edge tile, justoff the edge, or what? Also was the terrain such that the path the unit would take would not encounter the edge until it reached the place you clicked, or would obstacles cause it to path to the edge somewhere on the way? If you are able ro reproduce it please post a save game with any necessary instructions also. Thanks.
 
Yeah I right clicked to a tie on the border of the view port and then the game just disparaged as I let go of the right mouse button. Note that the pathing lead to the edge of screen fine (as far as I could tell). All path was within my land too. I would say it had maybe 4 moves to get there. It was more or less from the middle of the screen to the edge (horses move fast on paved roads).
 
Very awesome, koshling. Thank you.

So far so good. Crashed out on my first run after about ten turns, based on visible tiles, a combat was involving a unit of mine just over the viewport border. I was going to quit out to fix the ratios anyway, and after I did (extending the width to include the fight) I had no problems through an hour of gameplay.

I notice that the circles on tiles being used in the city screen seem to be absent. Also, the viewport appears not to recenter on defending units not attacking units under the Automate Hunt command (maybe it doesn't have time to?) but just moves to the nearest spot on the border it can find. I had one of those distant units level up and when it's turn came up the viewport recentered on the unit as expected.
 
Well done Koshling! You're works always astound me. It's going to take me a bit to get around to testing out the system but I'd like to thank you for getting it here. (I'm hoping it won't make my upcoming required merge tooooooo difficult. I'll be asking you some questions when I get to that point most likely.)
 
I am noticing a huge slow down in turn processing. I don't have view ports on yet nor do I have the option set to process all the AI turns simultainiously on. Effects also include slow moving units and occasionally all the unit disappearing. This is from turn one.
 
I tried loading my current GEM game with viewports on - they indeed do work and memory usage went down alot, but there is serious problem - resources icons are all messed up in a way that i have in my field of view resource icons from half globe and resources on terrain are not displayed. Screenshot attached.

Also, when i point units to go with pressing G+click they go to totally different place.
 
I tried loading my current GEM game with viewports on - they indeed do work and memory usage went down alot, but there is serious problem - resources icons are all messed up in a way that i have in my field of view resource icons from half globe and resources on terrain are not displayed. Screenshot attached.

Also, when i point units to go with pressing G+click they go to totally different place.

Is this effect immediate on load, or only after some time? In particular I forgot to mention there is a bug that means that exiting the military advisor by pressing escape (as opposed to clicking the exit button or clicking the map) leaves the map in scaled mode, which is not intended to ever happen on the main ap and is effectively broken there if it does.

If you have simple recipe to reproduce this from a save ame, please post it with instructions.
 
I am noticing a huge slow down in turn processing. I don't have view ports on yet nor do I have the option set to process all the AI turns simultainiously on. Effects also include slow moving units and occasionally all the unit disappearing. This is from turn one.

Are you certain it stems from svn 3034 specifically, or is it just a 'recent' thing? I cant think of anything that could explain this with viewports off!

Edit - to be certain could you try the SVN3033 DLL (just put that DLL back) and start a nwe game to see if it's still slow from turn 1. The pre-3034 DLL will generate Python errors with the advisors due to missign functions, but should work sufficiently for this test (you don't need the advisors to play a couple of turns). If this test shows it to be definately down to the DLL changes I'll see if I can find some culprit, but right now I can't think of any possibilities.
 
Yeah I right clicked to a tie on the border of the view port and then the game just disparaged as I let go of the right mouse button. Note that the pathing lead to the edge of screen fine (as far as I could tell). All path was within my land too. I would say it had maybe 4 moves to get there. It was more or less from the middle of the screen to the edge (horses move fast on paved roads).

Could you post the save game with a description of which unit and the exact location of the move target please.
 
Gonna load this up and give it a try right now. :D

Edit: Whoa! This is awesome! Turn processing is not noticeably changed but moving the map around is vastly increased. I noticed some slight hesitations when changing viewports at first, but it is minor and I forgot about it quickly. There are some odd graphically bugs, but I'm sure you are aware of them and squashing away. Going to have to experiment with different sizes to find one that suits me. One big issue I noticed. I can't right click to attack, nor can I press the "move-to" button to attack. I have to walk the unit right next to the bad guy and then use the numpad keys to initiate the attack. The "route-to" (move here building roads all along the way) command does not work either. A few minor bugs for such an amazing advancement. I can't wait to see what comes next.
 
Like we were talking about on the community chat.

<Define>
<DefineName>VIEWPORT_SIZE_X</DefineName>
<iDefineIntVal>35</iDefineIntVal>
</Define>
<Define>
<DefineName>VIEWPORT_SIZE_Y</DefineName>
<iDefineIntVal>30</iDefineIntVal>
</Define>

Moving aroud the viewport causes some skewing in resources and improvements, moving the about on their tiles.
 

Attachments

  • GEM GAME - YANGSHAO.zip
    4.2 MB · Views: 192
Crash to desktop when attempting to enter F5 (Military Advisor).
I have a Mini-dump file for you to examine K, I highly doubt a save game would help as it's likely my PC that makes it happen but if you want it I can supply that too.

Cheers
 
Crash to desktop when attempting to enter F5 (Military Advisor).
I have a Mini-dump file for you to examine K, I highly doubt a save game would help as it's likely my PC that makes it happen but if you want it I can supply that too.

Cheers

If it repeats by pressing F5 directly after the load (or other deterministic recipe you can describe) then please post the save too.
 
Top Bottom