#include "src\eng_core.h"\r
-#include <list>\r
+\r
#include "src\eng_snd.h"\r
#include "src\eng_gfx.h"\r
#include "src\eng_comm.h"\r
this->init();\r
\r
//default constructor\r
- this->fp = new std::list<void(Core::*)()>;\r
this->msg = ENGINE_RUN;\r
this->timer.start_timer();\r
this->frames_per_second = 60;\r
\r
- this->fp->push_back(&Core::sound);\r
- this->fp->push_back(&Core::graphics);\r
- this->fp->push_back(&Core::comm);\r
- this->fp->push_back(&Core::ai);\r
-\r
- //this->fp.push_back(&core::sound);\r
- //this->fp.push_back(&core::graphics);\r
- //this->fp.push_back(&core::comm);\r
- //this->fp.push_back(&engine::core::ai);\r
-\r
// Global Variables\r
this->bing = 4; // test global variable\r
this->x = 0; // X\r
this->y = 0; // Y\r
+ \r
+ // Start setttings of flags. I hope I got the same\r
+ // logic as it was before, with the STL list.\r
+ this->graphics_flag = true;\r
+ this->comm_flag = true;\r
+ this->release_flag = false;\r
}\r
\r
void Core::update()\r
{\r
- for (std::list<void(Core::*)()>::iterator i = fp->begin(); i != fp->end(); i++)\r
- //for (std::list<void(core::*)()>::iterator i = this->fp.begin(); i != this->fp.end(); i++)\r
- {\r
- (this->*(*i))();\r
- }\r
-\r
+ // call update functions, instead of traversing a function pointer\r
+ // list. Remove this comment!\r
+\r
+ sound();\r
+ if ( graphics_flag )\r
+ graphics();\r
+ if ( comm_flag )\r
+ comm();\r
+ ai();\r
+ if ( release_flag )\r
+ release();\r
}\r
\r
void Core::sound()\r
if (this->timer.elapsed_timer() >= (1.0 / this->frames_per_second))\r
{\r
//int a;std::cin >> a;\r
- this->fp->push_back(&Core::graphics);\r
+ graphics_flag = true;\r
this->timer.start_timer();\r
//==== std::cout << "GRAPHICS GRAPHICS GRAPHICS GRAPHICS GRAPHICS" << std::endl;\r
}\r
else\r
{\r
- this->fp->remove(&Core::graphics);\r
+ graphics_flag = false;\r
}\r
if (ENGINE_INPUT == this->msg)\r
{\r
- this->fp->push_back(&Core::comm);\r
+ comm_flag = true;\r
}\r
else\r
{\r
- this->fp->remove(&Core::comm);\r
+ comm_flag = false;\r
}\r
if (ENGINE_QUIT == this->msg)\r
{\r
- this->fp->push_back(&Core::release);\r
+ release_flag = true;\r
}\r
}\r
\r
Core::~Core()\r
{\r
//deconstructor\r
- delete(this->fp);\r
}\r
\r
}\r
+++ /dev/null
-#include "src\eng_core.h"\r
-\r
-#include "src\eng_snd.h"\r
-#include "src\eng_gfx.h"\r
-#include "src\eng_comm.h"\r
-#include "src\eng_ai.h"\r
-\r
-#include <iostream>\r
-\r
-//#include "src\lib\dos_gfx.h"\r
-//#include "src\lib\opl2.h"\r
-//#include "src\lib\dos_comm.h"\r
-\r
-namespace engine{\r
-\r
- Core::Core()\r
- {\r
- // Hardware Initiation\r
- this->init();\r
- \r
- //default constructor\r
- this->msg = ENGINE_RUN;\r
- this->timer.start_timer();\r
- this->frames_per_second = 60;\r
-\r
- // Global Variables\r
- this->bing = 4; // test global variable\r
- this->x = 0; // X\r
- this->y = 0; // Y\r
- \r
- // Start setttings of flags. I hope I got the same\r
- // logic as it was before, with the STL list.\r
- this->graphics_flag = true;\r
- this->comm_flag = true;\r
- this->release_flag = false;\r
- }\r
-\r
- void Core::update()\r
- {\r
- // call update functions, instead of traversing a function pointer\r
- // list. Remove this comment!\r
-\r
- sound();\r
- if ( graphics_flag )\r
- graphics();\r
- if ( comm_flag )\r
- comm();\r
- ai();\r
- if ( release_flag )\r
- release();\r
- }\r
-\r
- void Core::sound()\r
- {\r
- //wrap sound lib\r
- do_sound();\r
- }\r
- void Core::graphics()\r
- {\r
- //int num_frames = 60;\r
- //double fps = 1.0 / num_frames;\r
- //double now = this->timer.elapsed_timer();\r
- //std::cout << "fps: " << fps << " now: " << now << std::endl;\r
- //if (this->timer.elapsed_timer() >= fps)\r
- //{\r
- //wrap graphics lib\r
- do_graphics();\r
- //this->timer.start_timer();\r
- //}\r
- }\r
- void Core::comm()\r
- {\r
- //int num_frames = 60;\r
- //double fps = 1.0 / num_frames;\r
- //double now = this->timer.elapsed_timer();\r
- //std::cout << "fps: " << fps << " now: " << now << std::endl;\r
- //if (this->timer.elapsed_timer() >= fps)\r
- //{\r
- //wrap comm lib\r
- this->msg = do_communication();\r
- //this->timer.start_timer();\r
- //}\r
- }\r
- void Core::ai()\r
- {\r
- //wrap A.I. lib\r
- do_artificial_intelligence();\r
- }\r
-\r
- engine_message Core::_msg()\r
- {\r
- return this->msg;\r
- }\r
-\r
- void Core::run()\r
- {\r
-//---- int i = 0;\r
- while (ENGINE_EXIT != this->msg)\r
- {\r
- //next line for purely testing purposes\r
-//---- i++;if(i==600){char a;std::cin >> a;this->keeq[a] = true;i=0;}\r
- this->sync();\r
- this->input();\r
- this->update();\r
- }\r
- }\r
-\r
- bool Core::init(){\r
- bool xz = 0; // error switch...\r
- std::cout << "VIDEO INITIATION" << std::endl;\r
- setvideo(0x13, 1);\r
- setvbuff(1);\r
- std::cout << "Checking for Adlib sound card...." << std::endl;\r
- if(!AdlibExists()){\r
- std::cout << "not found." << std::endl;\r
- xz = 1;\r
- }\r
- std::cout << "found." << std::endl;\r
- std::cout << "OPL2 INITIATION" << std::endl;\r
- fmtest();\r
- std::cout << "\nPress ESC to quit the game engine core test." << std::endl;\r
- std::cout << "1 - 9 for graphical tests!" << std::endl;\r
- std::cout << "space bar for control and sprite test!" << std::endl;\r
- std::cout << "z key for noise!" << std::endl;\r
- std::cout << "Press press any key to continue!" << std::endl;\r
- getch();\r
- std::cout << "INPUT INITIATION" << std::endl;\r
- setkb(1);\r
- std::cout << "INITIATION" << std::endl;\r
- return xz;\r
- }\r
-\r
- void Core::release()\r
- {\r
- //release contexts and set engine to exit\r
- setvideo(0x03, 0);\r
- setvbuff(0);\r
- setkb(0);\r
- FMReset();\r
- this->msg = ENGINE_EXIT;\r
- }\r
-\r
- void Core::input(){\r
- //retrieve input device information\r
- //dummy 'w' and 'p' down, t up\r
-//---- bool dummy_input_available = true;\r
-//---- if(dummy_input_available)\r
-//---- {\r
-//---- std::cout << "key down" << std::endl;\r
-//---- this->keeq['w'] = true;\r
-//---- this->keeq['p'] = true;\r
-//---- this->keeq['t'] = false;\r
- //notify engine that input occured\r
- this->msg = ENGINE_INPUT;\r
-//---- }\r
-//---- else\r
-//---- {\r
-//---- std::cout << "key up" << std::endl;\r
-//---- this->msg = ENGINE_RUN;\r
-//---- }\r
- }\r
-\r
- void Core::sync()\r
- {\r
- if (this->timer.elapsed_timer() >= (1.0 / this->frames_per_second))\r
- {\r
- //int a;std::cin >> a;\r
- graphics_flag = true;\r
- this->timer.start_timer();\r
-//==== std::cout << "GRAPHICS GRAPHICS GRAPHICS GRAPHICS GRAPHICS" << std::endl;\r
- }\r
- else\r
- {\r
- graphics_flag = false;\r
- }\r
- if (ENGINE_INPUT == this->msg)\r
- {\r
- comm_flag = true;\r
- }\r
- else\r
- {\r
- comm_flag = false;\r
- }\r
- if (ENGINE_QUIT == this->msg)\r
- {\r
- release_flag = true;\r
- }\r
- }\r
-\r
- Core::~Core()\r
- {\r
- //deconstructor\r
- }\r
-\r
-}\r