Freeciv21
Develop your civilization from humble roots to a global empire
taiplayer.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // utility
16 #include "fcthread.h"
17 
18 // common
19 #include "player.h"
20 
21 /* ai/default */
22 #include "aidata.h"
23 
24 /* ai/threaded */
25 #include "taimsg.h"
26 
27 struct player;
28 
29 struct tai_msgs {
30  QWaitCondition thr_cond;
31  QMutex mutex;
32  struct taimsg_list *msglist;
33 };
34 
35 struct tai_reqs {
36  struct taireq_list *reqlist;
37 };
38 
39 struct tai_plr {
40  struct ai_plr defai; // Keep this first so default ai finds it
41 };
42 
43 void tai_init_threading(void);
44 
45 bool tai_thread_running(void);
46 
47 void tai_player_alloc(struct ai_type *ait, struct player *pplayer);
48 void tai_player_free(struct ai_type *ait, struct player *pplayer);
49 void tai_control_gained(struct ai_type *ait, struct player *pplayer);
50 void tai_control_lost(struct ai_type *ait, struct player *pplayer);
51 void tai_refresh(struct ai_type *ait, struct player *pplayer);
52 
53 void tai_msg_to_thr(struct tai_msg *msg);
54 
55 void tai_req_from_thr(struct tai_req *req);
56 
57 static inline struct tai_plr *tai_player_data(struct ai_type *ait,
58  const struct player *pplayer)
59 {
60  return (struct tai_plr *) player_ai_data(pplayer, ait);
61 }
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Return pointer to ai data of given player and ai type.
Definition: player.cpp:1838
Definition: aidata.h:63
Definition: ai.h:42
Definition: player.h:231
Definition: taimsg.h:31
QMutex mutex
Definition: taiplayer.h:31
struct taimsg_list * msglist
Definition: taiplayer.h:32
QWaitCondition thr_cond
Definition: taiplayer.h:30
struct ai_plr defai
Definition: taiplayer.h:40
Definition: taimsg.h:37
struct taireq_list * reqlist
Definition: taiplayer.h:36
void tai_msg_to_thr(struct tai_msg *msg)
Send message to thread.
Definition: taiplayer.c:275
bool tai_thread_running(void)
Return whether player thread is running.
Definition: taiplayer.c:294
void tai_control_gained(struct ai_type *ait, struct player *pplayer)
We actually control the player.
Definition: taiplayer.c:197
void tai_control_lost(struct ai_type *ait, struct player *pplayer)
We no longer control the player.
Definition: taiplayer.c:218
void tai_player_alloc(struct ai_type *ait, struct player *pplayer)
Initialize player for use with threaded AI.
Definition: taiplayer.c:167
static struct tai_plr * tai_player_data(struct ai_type *ait, const struct player *pplayer)
Definition: taiplayer.h:57
void tai_player_free(struct ai_type *ait, struct player *pplayer)
Free player from use with threaded AI.
Definition: taiplayer.c:180
void tai_init_threading(void)
Initialize ai thread.
Definition: taiplayer.c:61
void tai_req_from_thr(struct tai_req *req)
Thread sends message.
Definition: taiplayer.c:285
void tai_refresh(struct ai_type *ait, struct player *pplayer)
Check for messages sent by player thread.
Definition: taiplayer.c:239