patchFreeciv - Patches: patch #3721, Getting rid of move_type...

Show feedback again

patch #3721: Getting rid of move_type dependency on unitselect dialog

Submitted by:  Marko Lindqvist <cazfi>
Submitted on:  Tue Feb 19 07:27:44 2013  
Category: clientPriority: 5 - Normal
Status: Ready For TestPrivacy: Public
Assigned to: NoneOpen/Closed: Open
Planned Release: 3.0.0Contains string changes: None

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


(Jump to the original submission Jump to the original submission)

Mon Aug 22 19:46:24 2016, comment #7:

Unit select dialogs are refactored in 3.0 development, so targeting this one there.

Marko Lindqvist <cazfi>
Project Administrator
Sat Jun 28 10:20:58 2014, comment #6:

One of the patches in patch #4866 provides a new ruleset field (unit class group) that could be used for this purpose, if there is interest in that sort of solution (as hinted at the end of the original submission).

Emmet Hikory <persia>
Project Member
Tue Apr 23 18:19:52 2013, comment #5:

Oh, you were talking about server/client sync. Yes, even though client is single-threaded, and in that sense does a lot of things "atomically", user action can happen between any two packets from server.
As for transport and cargo being in different tiles, that can certainly happen - we've just been fixing entire class of bugs when client does (even without user interaction) illegal things while that's the case.

Marko Lindqvist <cazfi>
Project Administrator
Tue Apr 23 12:08:58 2013, comment #4:

Not being thread safe isn't just about whether the client is multithreaded. The entire computational system (client+server) has at least two threads, and if I read unit_move() correctly, send_unit_info_to_onlookers() is called a few times before the transported units are moved, so that there is a window during which the client sees the transporting unit moved and the transported units not yet moved, because the client thread (the single thread of the client process) isn't waiting for the server to finish with unit_move_handling() to do the next action. In practice, the situation described above would require either extremely variable network latency or a vast disparity in computational power between the client and the server, but this definitely conceivable with a fast gaming PC running the client and a heavily-loaded public internet server running on aging donated hardware in the lowest QoS band of some oddly-connected data centre.

Note that in the situation above, although the units are on different tiles, they still believe themselves to be transported, so by querying transport status, the information collected can be expected to also be reliable once the server has finished processing the move (and since the information that the transport is no longer occupied is sent before the information that the unit has moved, the opposite case (thinking a unit is in a transport when it has in fact moved out) will never occur with the current code).

Emmet Hikory <persia>
Project Member
Mon Apr 22 13:36:39 2013, comment #3:

While making things thread-safe in case threads are used in the future does have it merits, I don't see value in partial solution that just has smaller window for particular error, but is still not at all thread-safe. That doesn't make it one bit easier to implement it thread-safely in the future.

Marko Lindqvist <cazfi>
Project Administrator
Sun Apr 21 21:01:05 2013, comment #2:

I don't think it is safe to use !can_exist_at_tile() as the filter if we're looking to exclude transported units: that implies an assertion that at any time the client is sufficiently idle to take a new command, no untransported unit cannot exist on it's tile, which wouldn't be thread-safe if units are drowning, or possibly in certain transport situations (I haven't reviewed the client code sufficiently to confirm this: it may be that the client already group-moves units the server permits to move, or similar). Additionally, units in nested transport may be selected if they are native, even if they cannot be used (e.g. Cruise Missile in Mech. Inf. in Transport). If the intent is to find units that are both transported and unable to disembark, we should be using something like:

ptrans = unit_transport_get(punit);
if (ptrans != NULL
&& !(can_unit_unload(punit, ptrans)
&& can_unit_exist_at_tile(punit, utile))) {
return FALSE;

Using tile_city(utile) != NULL in both conditions causes any units in cities to appear twice. Perhaps these conditions could depend instead on the local terrain+infrastructure, so:

LAND: (!is_ocean(utile) && is_native_tile(unit_type(punit), utile)))
SEA: (is_ocean(utile) && is_native_tile(unit_type(punit), utile)))

This still causes some duplication (some units may be native to both, either inherently, or due to roads/bases/etc.), but doesn't automatically select all sea units in harbour when selecting LAND. On the other hand, it will make non-native (e.g. BuildAnywhere) units unselectable, which may be confusing.

The above said, I don't use this selector other than for tile range, so these opinions may be ill-informed.

Emmet Hikory <persia>
Project Member
Fri Mar 15 15:39:19 2013, comment #1:

Giving to jtn for him to decide if this fits to his select dialog plans.

Marko Lindqvist <cazfi>
Project Administrator
Tue Feb 19 07:27:44 2013, original submission:

Unit select dialog uses unit move_type, which we've tried to retire from non-ai code almost a decade already (since gen-movement development begun).

Attached patch replaces individual checks for move types with generic can_unit_exist_at_tile() check.

This changes behavior in many ways. It's probably matter of taste if these behavioral changes are for better or worse:

- "Both" selection type removed entirely. In most rulesets "Both" units mean air units, in some also amphibious units. So you no longer be able select just that selection of units.
- "Land" and "Sea" selection methods required both tile to be of the selected type, and the unit to have that move type. Terrain is still limited the same way, but units are subject to above mentioned can_unit_exist_at_tile() -> 1) Also "Both" units belong to selection 2) tile must really be native to unit, e.g., wheeled land units are not in selection in roadless tiles, alien ruleset native terrain limitations apply
- "World" used to select all units. Now units are subject to can_unit_exist_at_tile() so transported units are not part of the selection

If this is not sufficient, we may use some other property of units than move_type to make the decision what selection groups they belong to. Unit class is one possibility, but suffers from that separate classes like "Trireme" and "Sea" could then not be combined. Maybe we need to introduce new ruleset field for ruleset author to classify units, either to hardcoded categories or dynamic ones.

If we accept this patch to TRUNK (I'd go with it at least as temporary solution), should it go also to S2_4?

Marko Lindqvist <cazfi>
Project Administrator


(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #17256:  UnitselectNativity.patch added by cazfi (4kB - text/x-diff)


Depends on the following items: None found

   patch dependencies.


Carbon-Copy List
  • -unavailable- added by jtn (snooze)
  • -unavailable- added by persia (Posted a comment)
  • -unavailable- added by cazfi (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Error: not logged in



    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon Aug 22 19:46:24 2016cazfiAssigned tojtn=>None
      Planned Release2.6.0, 3.0.0=>3.0.0
    Thu Apr 14 04:41:12 2016cazfiPlanned Release2.6.0=>2.6.0, 3.0.0
    Wed Aug 13 00:20:45 2014cazfiPlanned Release2.5.0=>2.6.0
    Sat Jun 28 11:16:55 2014persiaDependencies-=>patch #4869 is dependent
    Thu Jun 26 23:08:45 2014jtnCarbon-Copy-=>Added jtn
    Fri Mar 15 15:39:19 2013cazfiAssigned toNone=>jtn
    Tue Feb 19 07:27:44 2013cazfiAttached File-=>Added UnitselectNativity.patch, #17256
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup