OSDN Git Service

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