1 /* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
2  *
3  * Quadra, an action puzzle game
4  * Copyright (C) 1998-2000  Ludus Design
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #ifndef _HEADER_OVERMIND
21 #define _HEADER_OVERMIND
22 
23 #include <list>
24 #include <vector>
25 
26 #include "types.h"
27 #include "inter.h"
28 
29 class Module;
30 extern Inter* ecran;
31 
32 class Executor {
33 	friend class Module;
34 	friend class Overmind;
35 	bool paused, self_destruct;
36 protected:
37 	std::vector<Module*> modules;
38 public:
39 	bool done;
40 	Executor(bool self_des=false);
41 	virtual ~Executor();
42 	void add(Module* m);
43 	void remove();
pause()44 	void pause() {
45 	  paused = true;
46 	}
unpause()47 	void unpause() {
48 		paused = false;
49 	}
50 	virtual void step();
51 };
52 
53 class Module {
54 	friend class Executor;
55 protected:
56 	Executor* parent;
57 	bool first_time;
58 	bool done;
59 public:
60 	Module();
61 	virtual ~Module();
62 
63 	//will be called repeatedly by the executor until 'ret' is called
64 	virtual void step();
65 
66 	//will be called once by the executor to initialise
67 	virtual void init();
68 
69 	//'this' will be deleted by the executor
70 	//'module' will replace it and start executing
71 	void exec(Module* module);
72 
73 	//'this' will be put on hold
74 	//'module' will start execution
75 	//'this' will resume after 'module' calls 'ret'
76 	void call(Module* module);
77 
78 	//'this' will be deleted by the executor
79 	//the caller will resume execution
80 	//if there is no caller, the executor will terminate
81 	void ret();
82 };
83 
84 class Module_thread: public Module {
85 public:
86 	Module_thread();
87 };
88 
89 class Overmind {
90 protected:
91 	std::list<Executor*> execs;
92 	bool paused;
93 public:
94 	bool done;
95 	Dword framecount;
96 	Overmind();
97 	virtual ~Overmind();
98 	void step();
99 	void start(Executor* e);
100 	void stop(Executor* e);
101 	void pause();
102 	void unpause();
103 	void clean_up();
104 };
105 
106 class Menu: public Module {
107 	Inter* old_ecran;
108 protected:
109 	Inter* inter;
110 	Zone* result;
111 public:
112 	Palette pal;
113 	Menu(Inter* base=NULL);
114 	virtual ~Menu();
115 	virtual void init();
116 	virtual void step();
117 };
118 
119 extern Overmind overmind;
120 
121 #endif
122