]> 4ch.mooo.com Git - 16.git/blob - doc/oldsrc/eng_core.cpp.0
stack...
[16.git] / doc / oldsrc / eng_core.cpp.0
1 #include "src\eng_core.h"\r
2 #include <list>\r
3 #include "src\eng_snd.h"\r
4 #include "src\eng_gfx.h"\r
5 #include "src\eng_comm.h"\r
6 #include "src\eng_ai.h"\r
7 \r
8 #include <iostream>\r
9 \r
10 //#include "src\lib\dos_gfx.h"\r
11 //#include "src\lib\opl2.h"\r
12 //#include "src\lib\dos_comm.h"\r
13 \r
14 namespace engine{\r
15 \r
16         Core::Core()\r
17         {\r
18                 // Hardware Initiation\r
19                 this->init();\r
20                 \r
21                 //default constructor\r
22                 this->fp = new std::list<void(Core::*)()>;\r
23                 this->msg = ENGINE_RUN;\r
24                 this->timer.start_timer();\r
25                 this->frames_per_second = 60;\r
26 \r
27                 this->fp->push_back(&Core::sound);\r
28                 this->fp->push_back(&Core::graphics);\r
29                 this->fp->push_back(&Core::comm);\r
30                 this->fp->push_back(&Core::ai);\r
31 \r
32                 //this->fp.push_back(&core::sound);\r
33                 //this->fp.push_back(&core::graphics);\r
34                 //this->fp.push_back(&core::comm);\r
35                 //this->fp.push_back(&engine::core::ai);\r
36 \r
37                 // Global Variables\r
38                 this->bing = 4; // test global variable\r
39                 this->x = 0; // X\r
40                 this->y = 0; // Y\r
41         }\r
42 \r
43         void Core::update()\r
44         {\r
45                 for (std::list<void(Core::*)()>::iterator i = fp->begin(); i != fp->end(); i++)\r
46                 //for (std::list<void(core::*)()>::iterator i = this->fp.begin(); i != this->fp.end(); i++)\r
47                 {\r
48                         (this->*(*i))();\r
49                 }\r
50 \r
51         }\r
52 \r
53         void Core::sound()\r
54         {\r
55                 //wrap sound lib\r
56                 do_sound();\r
57         }\r
58         void Core::graphics()\r
59         {\r
60                 //int num_frames = 60;\r
61                 //double fps = 1.0 / num_frames;\r
62                 //double now = this->timer.elapsed_timer();\r
63                 //std::cout << "fps: " << fps << "      now: " << now << std::endl;\r
64                 //if (this->timer.elapsed_timer() >= fps)\r
65                 //{\r
66                 //wrap graphics lib\r
67                 do_graphics();\r
68                 //this->timer.start_timer();\r
69                 //}\r
70         }\r
71         void Core::comm()\r
72         {\r
73                 //int num_frames = 60;\r
74                 //double fps = 1.0 / num_frames;\r
75                 //double now = this->timer.elapsed_timer();\r
76                 //std::cout << "fps: " << fps << "      now: " << now << std::endl;\r
77                 //if (this->timer.elapsed_timer() >= fps)\r
78                 //{\r
79                 //wrap comm lib\r
80                 this->msg = do_communication();\r
81                 //this->timer.start_timer();\r
82                 //}\r
83         }\r
84         void Core::ai()\r
85         {\r
86                 //wrap A.I. lib\r
87                 do_artificial_intelligence();\r
88         }\r
89 \r
90         engine_message Core::_msg()\r
91         {\r
92                 return this->msg;\r
93         }\r
94 \r
95         void Core::run()\r
96         {\r
97 //----          int i = 0;\r
98                 while (ENGINE_EXIT != this->msg)\r
99                 {\r
100                         //next line for purely testing purposes\r
101 //----                  i++;if(i==600){char a;std::cin >> a;this->keeq[a] = true;i=0;}\r
102                         this->sync();\r
103                         this->input();\r
104                         this->update();\r
105                 }\r
106         }\r
107 \r
108         bool Core::init(){\r
109                 bool xz = 0; // error switch...\r
110                 std::cout << "VIDEO INITIATION" << std::endl;\r
111                 setvideo(0x13, 1);\r
112                 setvbuff(1);\r
113                 std::cout << "Checking for Adlib sound card...." << std::endl;\r
114                 if(!AdlibExists()){\r
115                         std::cout << "not found." << std::endl;\r
116                         xz = 1;\r
117                 }\r
118                 std::cout << "found." << std::endl;\r
119                 std::cout << "OPL2 INITIATION" << std::endl;\r
120                 fmtest();\r
121                 std::cout << "\nPress ESC to quit the game engine core test." << std::endl;\r
122                 std::cout << "1 - 9 for graphical tests!" << std::endl;\r
123                 std::cout << "space bar for control and sprite test!" << std::endl;\r
124                 std::cout << "z key for noise!" << std::endl;\r
125                 std::cout << "Press press any key to continue!" << std::endl;\r
126                 getch();\r
127                 std::cout << "INPUT INITIATION" << std::endl;\r
128                 setkb(1);\r
129                 std::cout << "INITIATION" << std::endl;\r
130                 return xz;\r
131         }\r
132 \r
133         void Core::release()\r
134         {\r
135                 //release contexts and set engine to exit\r
136                 setvideo(0x03, 0);\r
137                 setvbuff(0);\r
138                 setkb(0);\r
139                 FMReset();\r
140                 this->msg = ENGINE_EXIT;\r
141         }\r
142 \r
143         void Core::input(){\r
144                 //retrieve input device information\r
145                 //dummy 'w' and 'p' down, t up\r
146 //----          bool dummy_input_available = true;\r
147 //----          if(dummy_input_available)\r
148 //----          {\r
149 //----                  std::cout << "key down" << std::endl;\r
150 //----                  this->keeq['w'] = true;\r
151 //----                  this->keeq['p'] = true;\r
152 //----                  this->keeq['t'] = false;\r
153                         //notify engine that input occured\r
154                         this->msg = ENGINE_INPUT;\r
155 //----          }\r
156 //----          else\r
157 //----          {\r
158 //----                  std::cout << "key up" << std::endl;\r
159 //----                  this->msg = ENGINE_RUN;\r
160 //----          }\r
161         }\r
162 \r
163         void Core::sync()\r
164         {\r
165                 if (this->timer.elapsed_timer() >= (1.0 / this->frames_per_second))\r
166                 {\r
167                         //int a;std::cin >> a;\r
168                         this->fp->push_back(&Core::graphics);\r
169                         this->timer.start_timer();\r
170 //====                  std::cout << "GRAPHICS GRAPHICS GRAPHICS GRAPHICS GRAPHICS" << std::endl;\r
171                 }\r
172                 else\r
173                 {\r
174                         this->fp->remove(&Core::graphics);\r
175                 }\r
176                 if (ENGINE_INPUT == this->msg)\r
177                 {\r
178                         this->fp->push_back(&Core::comm);\r
179                 }\r
180                 else\r
181                 {\r
182                         this->fp->remove(&Core::comm);\r
183                 }\r
184                 if (ENGINE_QUIT == this->msg)\r
185                 {\r
186                         this->fp->push_back(&Core::release);\r
187                 }\r
188         }\r
189 \r
190         Core::~Core()\r
191         {\r
192                 //deconstructor\r
193                 delete(this->fp);\r
194         }\r
195 \r
196 }\r