[Freeciv-Dev] (PR#2703) Fast focus v2
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Issue 1)
Per wrote:
> This doesn't happen if you click on an autoexplorer. [...]
> I guess this has something to do with autoexploration being an activity.
Ok, actually it had to do with update_focus() beeing called
indiscriminately, un-focusing all exhausted units.
New patch version allows for controlling that in every situation by
introducing (bool) check_focus in packhand.c. Just a few lines.
It also fixes an issue that someone complained about in another PR:
Client sometimes takes away focus from your exhausted unit when OTHER
players' units move nearby.
Bing!
I had this in another patch I'm writing, but they seem to become
intertwined.
Issue 2)
I wrote:
>> Removed PACKET_ADVANCE_FOCUS.
Per wrote:
> Bad. It needs to stay (with a comment that it is unused) so that packet
> numeration stays the same.
Jason wrote:
> Or, if it is removed then you need a new mandatory capability.
If an old client connects to a new server, client waits forever
for permission to focus..
How about a new mandatory capability to get rid of all these
non-useful bits of code. All I did was to add "+fastfocus"
to common/capstr.c. Seems to work. Old client gets error string.
fastfocus2.diff vs cvs-Jan-25 attatched.
Arnstein
diff -ruN -Xdiff_ignore cvs-Jan-25/client/civclient.c
fastfocus-Jan-25/client/civclient.c
--- cvs-Jan-25/client/civclient.c Mon Jan 6 06:55:17 2003
+++ fastfocus-Jan-25/client/civclient.c Mon Jan 27 02:50:12 2003
@@ -427,10 +427,6 @@
handle_diplomat_action((struct packet_diplomat_action *)packet);
break;
- case PACKET_ADVANCE_FOCUS:
- handle_advance_focus((struct packet_generic_integer *)packet);
- break;
-
case PACKET_CONN_INFO:
handle_conn_info((struct packet_conn_info *)packet);
break;
@@ -543,7 +539,6 @@
info.movesleft=punit->moves_left;
info.activity=punit->activity;
info.activity_target=punit->activity_target;
- info.select_it = FALSE;
info.packet_use = UNIT_INFO_IDENTITY;
send_packet_unit_info(&aconnection, &info);
diff -ruN -Xdiff_ignore cvs-Jan-25/client/control.c
fastfocus-Jan-25/client/control.c
--- cvs-Jan-25/client/control.c Fri Jan 17 06:56:16 2003
+++ fastfocus-Jan-25/client/control.c Mon Jan 27 02:50:12 2003
@@ -84,16 +84,6 @@
}
/**************************************************************************
-...
-**************************************************************************/
-void handle_advance_focus(struct packet_generic_integer *packet)
-{
- struct unit *punit = find_unit_by_id(packet->value);
- if (punit && punit_focus == punit)
- advance_unit_focus();
-}
-
-/**************************************************************************
Center on the focus unit, if off-screen and auto_center_on_unit is true.
**************************************************************************/
void auto_center_on_focus_unit(void)
@@ -120,6 +110,12 @@
punit->focus_status=FOCUS_AVAIL;
refresh_tile_mapcanvas(punit->x, punit->y, TRUE);
+
+ if (punit->activity != ACTIVITY_IDLE || punit->ai.control) {
+ punit->activity = ACTIVITY_IDLE;
+ punit->ai.control = FALSE;
+ request_new_unit_activity(punit, ACTIVITY_IDLE);
+ }
}
/* avoid the old focus unit disappearing: */
@@ -728,29 +724,6 @@
/**************************************************************************
...
**************************************************************************/
-void request_unit_selected(struct unit *punit)
-{
- struct packet_unit_info info;
-
- info.id=punit->id;
- info.owner=punit->owner;
- info.x=punit->x;
- info.y=punit->y;
- info.homecity=punit->homecity;
- info.veteran=punit->veteran;
- info.type=punit->type;
- info.movesleft=punit->moves_left;
- info.activity=ACTIVITY_IDLE;
- info.activity_target = S_NO_SPECIAL;
- info.select_it = TRUE;
- info.packet_use = UNIT_INFO_IDENTITY;
-
- send_packet_unit_info(&aconnection, &info);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
void request_unit_disband(struct unit *punit)
{
struct packet_unit_request req;
@@ -1289,7 +1262,7 @@
struct unit *punit=unit_list_get(&ptile->units, 0);
if(game.player_idx==punit->owner) {
if(can_unit_do_activity(punit, ACTIVITY_IDLE)) {
- request_unit_selected(punit);
+ set_unit_focus_and_select(punit);
}
}
} else if(unit_list_size(&ptile->units) >= 2) {
diff -ruN -Xdiff_ignore cvs-Jan-25/client/control.h
fastfocus-Jan-25/client/control.h
--- cvs-Jan-25/client/control.h Sat Nov 23 07:01:36 2002
+++ fastfocus-Jan-25/client/control.h Mon Jan 27 02:50:12 2003
@@ -37,7 +37,6 @@
void do_map_click(int xtile, int ytile);
void set_hover_state(struct unit *punit, enum cursor_hover_state state);
-void handle_advance_focus(struct packet_generic_integer *packet);
void request_center_focus_unit(void);
void request_move_unit_direction(struct unit *punit, int dir);
void request_new_unit_activity(struct unit *punit, enum unit_activity act);
@@ -57,7 +56,6 @@
void request_unit_paradrop(struct unit *punit);
void request_unit_patrol(void);
void request_unit_pillage(struct unit *punit);
-void request_unit_selected(struct unit *punit);
void request_unit_sentry(struct unit *punit);
void request_unit_unload(struct unit *punit);
void request_unit_airlift(struct unit *punit, struct city *pcity);
diff -ruN -Xdiff_ignore cvs-Jan-25/client/gui-mui/citydlg.c
fastfocus-Jan-25/client/gui-mui/citydlg.c
--- cvs-Jan-25/client/gui-mui/citydlg.c Fri Jan 17 06:56:18 2003
+++ fastfocus-Jan-25/client/gui-mui/citydlg.c Mon Jan 27 02:50:12 2003
@@ -1126,7 +1126,7 @@
**************************************************************************/
static void city_present(struct city_unit_msg *data)
{
- request_unit_selected(data->punit);
+ set_unit_focus_and_select(data->punit);
}
/****************************************************************
diff -ruN -Xdiff_ignore cvs-Jan-25/client/gui-mui/dialogs.c
fastfocus-Jan-25/client/gui-mui/dialogs.c
--- cvs-Jan-25/client/gui-mui/dialogs.c Fri Nov 29 06:54:55 2002
+++ fastfocus-Jan-25/client/gui-mui/dialogs.c Mon Jan 27 02:50:12 2003
@@ -1430,7 +1430,7 @@
struct unit *punit = *ppunit;
if(punit && punit->owner == game.player_idx) {
- request_unit_selected(punit);
+ set_unit_focus_and_select(punit);
}
set(unitsel_wnd, MUIA_Window_Open, FALSE);
}
diff -ruN -Xdiff_ignore cvs-Jan-25/client/gui-mui/gui_main.c
fastfocus-Jan-25/client/gui-mui/gui_main.c
--- cvs-Jan-25/client/gui-mui/gui_main.c Thu Jan 2 06:55:14 2003
+++ fastfocus-Jan-25/client/gui-mui/gui_main.c Mon Jan 27 02:50:12 2003
@@ -711,7 +711,7 @@
else
{
if(can_unit_do_activity(punit, ACTIVITY_IDLE)) {
- request_unit_selected(punit);
+ set_unit_focus_and_select(punit);
}
}
}
diff -ruN -Xdiff_ignore cvs-Jan-25/client/gui-mui/mapview.c
fastfocus-Jan-25/client/gui-mui/mapview.c
--- cvs-Jan-25/client/gui-mui/mapview.c Sun Jan 19 06:56:15 2003
+++ fastfocus-Jan-25/client/gui-mui/mapview.c Mon Jan 27 02:50:12 2003
@@ -244,7 +244,7 @@
void activate_below_unit (int *id)
{
struct unit *punit = find_unit_by_id(*id);
- if (punit) request_unit_selected(punit);
+ if (punit) set_unit_focus_and_select(punit);
}
/**************************************************************************
diff -ruN -Xdiff_ignore cvs-Jan-25/client/packhand.c
fastfocus-Jan-25/client/packhand.c
--- cvs-Jan-25/client/packhand.c Sat Jan 18 06:56:53 2003
+++ fastfocus-Jan-25/client/packhand.c Mon Jan 27 03:11:49 2003
@@ -814,6 +814,7 @@
struct unit *punit;
bool repaint_unit;
bool repaint_city; /* regards unit's homecity */
+ bool check_focus = FALSE; /* conservative focus change */
bool moved = FALSE;
int old_x = -1, old_y = -1; /* make compiler happy; guarded by moved */
@@ -865,13 +866,25 @@
if (punit->ai.control!=packet->ai) {
punit->ai.control = packet->ai;
repaint_unit = TRUE;
+ /* AI is set: may change focus */
+ /* AI is cleared: keep focus */
+ if (packet->ai && punit == get_unit_in_focus()) {
+ check_focus = TRUE;
+ }
}
if((punit->activity!=packet->activity) /* change activity */
|| (punit->activity_target!=packet->activity_target)) { /* or act's
target */
+
+ /* May change focus if focus unit gets a new activity.
+ But if new activity is Idle, it means user specifically selected the
unit */
+ if(punit == get_unit_in_focus() && packet->activity != ACTIVITY_IDLE)
+ check_focus = TRUE;
+
repaint_unit = TRUE;
if(wakeup_focus && (punit->owner==game.player_idx)
&& (punit->activity==ACTIVITY_SENTRY)) {
set_unit_focus(punit);
+ check_focus = FALSE; /* and keep it */
/* RP: focus on (each) activated unit (e.g. when unloading a ship) */
}
@@ -926,6 +939,11 @@
}
}
+ /* May change focus if an attempted move or attack exhausted unit */
+ if (punit->moves_left != packet->movesleft && punit ==
get_unit_in_focus()) {
+ check_focus = TRUE;
+ }
+
if (!same_pos(punit->x, punit->y, packet->x, packet->y)) {
/* change position */
struct city *pcity = map_get_city(punit->x, punit->y);
@@ -1052,11 +1070,8 @@
if(repaint_unit)
refresh_tile_mapcanvas(punit->x, punit->y, TRUE);
- if(packet->select_it && (punit->owner==game.player_idx)) {
- set_unit_focus_and_select(punit);
- } else {
+ if (check_focus || get_unit_in_focus() == NULL)
update_unit_focus();
- }
}
/**************************************************************************
diff -ruN -Xdiff_ignore cvs-Jan-25/common/capstr.c
fastfocus-Jan-25/common/capstr.c
--- cvs-Jan-25/common/capstr.c Fri Jan 17 06:56:26 2003
+++ fastfocus-Jan-25/common/capstr.c Mon Jan 27 03:44:45 2003
@@ -75,7 +75,7 @@
*/
#define CAPABILITY "+1.14.0 conn_info +occupied team tech_impr_gfx " \
- "city_struct_minor_cleanup"
+ "city_struct_minor_cleanup +fastfocus"
/* "+1.14.0" is protocol for 1.14.0 release.
*
diff -ruN -Xdiff_ignore cvs-Jan-25/common/packets.c
fastfocus-Jan-25/common/packets.c
--- cvs-Jan-25/common/packets.c Fri Jan 17 06:56:27 2003
+++ fastfocus-Jan-25/common/packets.c Mon Jan 27 02:50:12 2003
@@ -323,7 +323,6 @@
case PACKET_CITY_REFRESH:
case PACKET_INCITE_INQ:
case PACKET_CITY_NAME_SUGGEST_REQ:
- case PACKET_ADVANCE_FOCUS:
case PACKET_PLAYER_CANCEL_PACT:
case PACKET_PLAYER_REMOVE_VISION:
return receive_packet_generic_integer(pc);
@@ -1246,8 +1245,7 @@
dio_put_uint16(&dout, req->id);
dio_put_uint8(&dout, req->owner);
- pack = (COND_SET_BIT(req->select_it, 2) |
- COND_SET_BIT(req->carried, 3) |
+ pack = (COND_SET_BIT(req->carried, 3) |
COND_SET_BIT(req->veteran, 4) |
COND_SET_BIT(req->ai, 5) |
COND_SET_BIT(req->paradropped, 6) |
@@ -1524,7 +1522,6 @@
dio_get_uint8(&din, &packet->owner);
dio_get_uint8(&din, &pack);
- packet->select_it = TEST_BIT(pack, 2);
packet->carried = TEST_BIT(pack, 3);
packet->veteran = TEST_BIT(pack, 4);
packet->ai = TEST_BIT(pack, 5);
diff -ruN -Xdiff_ignore cvs-Jan-25/common/packets.h
fastfocus-Jan-25/common/packets.h
--- cvs-Jan-25/common/packets.h Fri Jan 17 06:56:27 2003
+++ fastfocus-Jan-25/common/packets.h Mon Jan 27 03:46:01 2003
@@ -112,7 +112,6 @@
PACKET_RULESET_CITY,
PACKET_UNIT_CONNECT,
PACKET_SABOTAGE_LIST,
- PACKET_ADVANCE_FOCUS,
PACKET_RULESET_GAME,
PACKET_CONN_INFO,
PACKET_SHORT_CITY,
@@ -316,7 +315,6 @@
bool connecting;
/* in packet only, not in unit struct */
bool carried;
- bool select_it;
int packet_use; /* see enum unit_info_use */
int info_city_id; /* for UNIT_INFO_CITY_SUPPORTED
and UNIT_INFO_CITY_PRESENT uses */
diff -ruN -Xdiff_ignore cvs-Jan-25/server/diplomats.c
fastfocus-Jan-25/server/diplomats.c
--- cvs-Jan-25/server/diplomats.c Thu Dec 12 06:55:08 2002
+++ fastfocus-Jan-25/server/diplomats.c Mon Jan 27 02:50:12 2003
@@ -154,13 +154,13 @@
As this is a special case we bypass send_unit_info. */
first_packet = TRUE;
unit_list_iterate(pcity->units_supported, punit) {
- package_unit(punit, &unit_packet, FALSE, FALSE,
+ package_unit(punit, &unit_packet, FALSE,
UNIT_INFO_CITY_SUPPORTED, pcity->id, first_packet);
lsend_packet_unit_info(&pplayer->connections, &unit_packet);
first_packet = FALSE;
} unit_list_iterate_end;
unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, punit) {
- package_unit(punit, &unit_packet, FALSE, FALSE,
+ package_unit(punit, &unit_packet, FALSE,
UNIT_INFO_CITY_PRESENT, pcity->id, first_packet);
lsend_packet_unit_info(&pplayer->connections, &unit_packet);
first_packet = FALSE;
diff -ruN -Xdiff_ignore cvs-Jan-25/server/gotohand.c
fastfocus-Jan-25/server/gotohand.c
--- cvs-Jan-25/server/gotohand.c Thu Jan 9 06:56:03 2003
+++ fastfocus-Jan-25/server/gotohand.c Mon Jan 27 02:50:12 2003
@@ -1291,7 +1291,6 @@
if (find_air_first_destination(punit, &waypoint_x, &waypoint_y)) {
/* this is a special case for air units who do not always want to move.
*/
if (same_pos(waypoint_x, waypoint_y, punit->x, punit->y)) {
- advance_unit_focus(punit);
return GR_OUT_OF_MOVEPOINTS; /* out of fuel */
}
} else {
@@ -1398,7 +1397,6 @@
}
status = GR_ARRIVED;
} else {
- advance_unit_focus(punit);
/* we have a plane refueling at a waypoint */
status = GR_OUT_OF_MOVEPOINTS;
}
diff -ruN -Xdiff_ignore cvs-Jan-25/server/unithand.c
fastfocus-Jan-25/server/unithand.c
--- cvs-Jan-25/server/unithand.c Wed Jan 22 06:56:32 2003
+++ fastfocus-Jan-25/server/unithand.c Mon Jan 27 03:10:02 2003
@@ -62,8 +62,7 @@
enum unit_activity
new_activity,
enum tile_special_type
- new_target,
- bool select_unit);
+ new_target);
/**************************************************************************
...
@@ -618,15 +617,11 @@
}
} else if (punit->activity != pinfo->activity ||
punit->activity_target != pinfo->activity_target ||
- pinfo->select_it || punit->ai.control) {
- /* Treat change in ai.control as change in activity, so
- * idle autosettlers behave correctly when selected --dwp
- */
+ punit->ai.control) {
punit->ai.control = FALSE;
handle_unit_activity_request_targeted(punit,
pinfo->activity,
- pinfo->activity_target,
- pinfo->select_it);
+ pinfo->activity_target);
/* Exploring is handled here explicitly, since the player expects to
* see an immediate response from setting a unit to auto-explore.
@@ -766,9 +761,9 @@
combat.defender_hp=pdefender->hp;
combat.make_winner_veteran=pwinner->veteran?1:0;
- package_unit(punit, &unit_att_packet, FALSE, FALSE, UNIT_INFO_IDENTITY, 0,
+ package_unit(punit, &unit_att_packet, FALSE, UNIT_INFO_IDENTITY, 0,
FALSE);
- package_unit(pdefender, &unit_def_packet, FALSE, FALSE, UNIT_INFO_IDENTITY,
+ package_unit(pdefender, &unit_def_packet, FALSE, UNIT_INFO_IDENTITY,
0, FALSE);
players_iterate(other_player) {
@@ -1308,8 +1303,7 @@
enum unit_activity
new_activity,
enum tile_special_type
- new_target,
- bool select_unit)
+ new_target)
{
if (can_unit_do_activity_targeted(punit, new_activity, new_target)) {
enum unit_activity old_activity = punit->activity;
@@ -1322,8 +1316,8 @@
punit->pgr = NULL;
}
- send_unit_info_to_onlookers(NULL, punit, punit->x, punit->y, FALSE,
- select_unit);
+ send_unit_info_to_onlookers(NULL, punit, punit->x, punit->y, FALSE);
+
handle_unit_activity_dependencies(punit, old_activity, old_target);
}
}
diff -ruN -Xdiff_ignore cvs-Jan-25/server/unittools.c
fastfocus-Jan-25/server/unittools.c
--- cvs-Jan-25/server/unittools.c Fri Jan 17 06:56:35 2003
+++ fastfocus-Jan-25/server/unittools.c Mon Jan 27 02:50:12 2003
@@ -1093,19 +1093,6 @@
}
}
-
-/**************************************************************************
-...
-**************************************************************************/
-void advance_unit_focus(struct unit *punit)
-{
- conn_list_iterate(unit_owner(punit)->connections, pconn) {
- struct packet_generic_integer packet;
- packet.value = punit->id;
- send_packet_generic_integer(pconn, PACKET_ADVANCE_FOCUS, &packet);
- } conn_list_iterate_end;
-}
-
/**************************************************************************
Returns a pointer to a (static) string which gives an informational
message about location (x,y), in terms of cities known by pplayer.
@@ -1900,7 +1887,7 @@
...
**************************************************************************/
void package_unit(struct unit *punit, struct packet_unit_info *packet,
- bool carried, bool select_it, enum unit_info_use packet_use,
+ bool carried, enum unit_info_use packet_use,
int info_city_id, bool new_serial_num)
{
static unsigned int serial_num = 0;
@@ -1935,7 +1922,6 @@
packet->paradropped = punit->paradropped;
packet->connecting = punit->connecting;
packet->carried = carried;
- packet->select_it = select_it;
packet->packet_use = packet_use;
packet->info_city_id = info_city_id;
packet->serial_num = serial_num;
@@ -1949,13 +1935,13 @@
dest = NULL means all connections (game.game_connections)
**************************************************************************/
void send_unit_info_to_onlookers(struct conn_list *dest, struct unit *punit,
- int x, int y, bool carried, bool select_it)
+ int x, int y, bool carried)
{
struct packet_unit_info info;
if (!dest) dest = &game.game_connections;
- package_unit(punit, &info, carried, select_it,
+ package_unit(punit, &info, carried,
UNIT_INFO_IDENTITY, FALSE, FALSE);
conn_list_iterate(*dest, pconn) {
@@ -1987,7 +1973,7 @@
{
struct conn_list *conn_dest = (dest ? &dest->connections
: &game.game_connections);
- send_unit_info_to_onlookers(conn_dest, punit, punit->x, punit->y, FALSE,
FALSE);
+ send_unit_info_to_onlookers(conn_dest, punit, punit->x, punit->y, FALSE);
}
/**************************************************************************
@@ -2010,7 +1996,7 @@
if (!pplayer
|| map_get_known_and_seen(punit->x, punit->y, pplayer)) {
send_unit_info_to_onlookers(&pconn->self, punit,
- punit->x, punit->y, FALSE, FALSE);
+ punit->x, punit->y, FALSE);
}
}
unit_list_iterate_end;
@@ -2961,7 +2947,7 @@
pcargo->y = dest_y;
unit_list_insert(&pdesttile->units, pcargo);
check_unit_activity(pcargo);
- send_unit_info_to_onlookers(NULL, pcargo, src_x, src_y, TRUE, FALSE);
+ send_unit_info_to_onlookers(NULL, pcargo, src_x, src_y, TRUE);
fog_area(unit_owner(pcargo), src_x, src_y,
unit_type(pcargo)->vision_range);
handle_unit_move_consequences(pcargo, src_x, src_y, dest_x, dest_y);
} unit_list_iterate_end;
@@ -3002,7 +2988,7 @@
) {
set_unit_activity(punit, ACTIVITY_SENTRY);
}
- send_unit_info_to_onlookers(NULL, punit, src_x, src_y, FALSE, FALSE);
+ send_unit_info_to_onlookers(NULL, punit, src_x, src_y, FALSE);
/* The hidden units might not have been previously revealed
* because when we did the unfogging, the unit was still
diff -ruN -Xdiff_ignore cvs-Jan-25/server/unittools.h
fastfocus-Jan-25/server/unittools.h
--- cvs-Jan-25/server/unittools.h Thu Dec 19 06:55:17 2002
+++ fastfocus-Jan-25/server/unittools.h Mon Jan 27 02:50:12 2003
@@ -36,7 +36,6 @@
void update_unit_activities(struct player *pplayer);
/* various */
-void advance_unit_focus(struct unit *punit);
char *get_location_str_in(struct player *pplayer, int x, int y);
char *get_location_str_at(struct player *pplayer, int x, int y);
enum goto_move_restriction get_activity_move_restriction(enum unit_activity
activity);
@@ -66,11 +65,11 @@
/* sending to client */
void package_unit(struct unit *punit, struct packet_unit_info *packet,
- bool carried, bool select_it, enum unit_info_use packet_use,
+ bool carried, enum unit_info_use packet_use,
int info_city_id, bool new_serial_num);
void send_unit_info(struct player *dest, struct unit *punit);
void send_unit_info_to_onlookers(struct conn_list *dest, struct unit *punit,
- int x, int y, bool carried, bool select_it);
+ int x, int y, bool carried);
void send_all_known_units(struct conn_list *dest);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2703) Fast focus v2,
Arnstein Lindgard via RT <=
|
|