]> 4ch.mooo.com Git - 16.git/blob - src/eng_core.cpp.1
modified: core16.map
[16.git] / src / eng_core.cpp.1
1 #include "src\eng_core.h"\r
2 \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->msg = ENGINE_RUN;\r
23                 this->timer.start_timer();\r
24                 this->frames_per_second = 60;\r
25 \r
26                 // Global Variables\r
27                 this->bing = 4; // test global variable\r
28                 this->x = 0; // X\r
29                 this->y = 0; // Y\r
30                 \r
31                 // Start setttings of flags.  I hope I got the same\r
32                 // logic as it was before, with the STL list.\r
33                 this->graphics_flag = true;\r
34                 this->comm_flag = true;\r
35                 this->release_flag = false;\r
36         }\r
37 \r
38         void Core::update()\r
39         {\r
40           // call update functions, instead of traversing a function pointer\r
41           // list.  Remove this comment!\r
42 \r
43           sound();\r
44           if ( graphics_flag )\r
45                   graphics();\r
46           if ( comm_flag )\r
47                   comm();\r
48           ai();\r
49           if ( release_flag )\r
50                   release();\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                         graphics_flag = true;\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                         graphics_flag = false;\r
175                 }\r
176                 if (ENGINE_INPUT == this->msg)\r
177                 {\r
178                         comm_flag = true;\r
179                 }\r
180                 else\r
181                 {\r
182                         comm_flag = false;\r
183                 }\r
184                 if (ENGINE_QUIT == this->msg)\r
185                 {\r
186                         release_flag = true;\r
187                 }\r
188         }\r
189 \r
190         Core::~Core()\r
191         {\r
192                 //deconstructor\r
193         }\r
194 \r
195 }\r