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