2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * update.c: Update scheduler
30 * Known contributors to this file:
38 #include "empthread.h"
39 #include "prototypes.h"
43 empth_sem_t *update_sem;
45 static void update_wait(void *unused);
50 update_sched(void *unused)
56 update_sem = empth_sem_create("Update", 0);
57 empth_create(PP_SCHED, update_wait, (50 * 1024), 0, "UpdateWait",
58 "Waits until players idle", 0);
61 logerror("bad value for s_p_etu (%d)", s_p_etu);
63 logerror("setting s_p_etu to %d", s_p_etu);
67 next_update_time(&now, &update_time, &delta);
68 if (update_window > 0) {
69 wind = (random() % update_window);
73 logerror("Next update at %s", ctime(&update_time));
74 logerror("Next update in %ld seconds", (long)delta);
75 /* sleep until update is scheduled to go off */
76 empth_sleep(update_time);
79 if (!gamehours(now)) {
80 logerror("No update permitted (hours restriction)");
83 if (!updatetime(&now)) {
84 logerror("No update wanted");
87 if (updates_disabled()) {
88 logerror("Updates disabled...skipping update");
91 empth_sem_signal(update_sem);
98 update_wait(void *unused)
107 empth_sem_wait(update_sem);
109 for (p = player_next(0); p != 0; p = player_next(p)) {
110 if (p->state != PS_PLAYING)
113 pr_flash(p, "Update aborting command\n");
115 empth_wakeup(p->proc);
121 /* sleep a few, wait for aborts to take effect */
122 empth_sleep(now + 2);
125 * we rely on the fact that update's priority is the highest
126 * in the land so it can finish before it yields.
128 dp = player_new(0, 0);
130 logerror("can't create dummy player for update");
134 /* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) +
137 empth_create(PP_UPDATE, update_main, stacksize, 0,
138 "UpdateRun", "Updates the world", dp);