From 053d2be9c2c5877ebc13a6b2e9afeb0c8359e1f0 Mon Sep 17 00:00:00 2001 From: sparky4 Date: Sat, 29 Dec 2012 18:45:01 -0600 Subject: [PATCH] modified: src/eng_core.cpp deleted: src/eng_core.cpp.1 modified: src/eng_core.h deleted: src/eng_core.h.1 src/eng_core.cpp.0 src/eng_core.h.0 --- src/eng_core.cpp | 47 ++++++----- src/eng_core.cpp.1 | 195 --------------------------------------------- src/eng_core.h | 19 ++--- src/eng_core.h.1 | 43 ---------- 4 files changed, 33 insertions(+), 271 deletions(-) delete mode 100644 src/eng_core.cpp.1 delete mode 100644 src/eng_core.h.1 diff --git a/src/eng_core.cpp b/src/eng_core.cpp index 8f790fac..2bfb4ca1 100644 --- a/src/eng_core.cpp +++ b/src/eng_core.cpp @@ -1,5 +1,5 @@ #include "src\eng_core.h" -#include + #include "src\eng_snd.h" #include "src\eng_gfx.h" #include "src\eng_comm.h" @@ -19,35 +19,35 @@ namespace engine{ this->init(); //default constructor - this->fp = new std::list; this->msg = ENGINE_RUN; this->timer.start_timer(); this->frames_per_second = 60; - this->fp->push_back(&Core::sound); - this->fp->push_back(&Core::graphics); - this->fp->push_back(&Core::comm); - this->fp->push_back(&Core::ai); - - //this->fp.push_back(&core::sound); - //this->fp.push_back(&core::graphics); - //this->fp.push_back(&core::comm); - //this->fp.push_back(&engine::core::ai); - // Global Variables this->bing = 4; // test global variable this->x = 0; // X this->y = 0; // Y + + // Start setttings of flags. I hope I got the same + // logic as it was before, with the STL list. + this->graphics_flag = true; + this->comm_flag = true; + this->release_flag = false; } void Core::update() { - for (std::list::iterator i = fp->begin(); i != fp->end(); i++) - //for (std::list::iterator i = this->fp.begin(); i != this->fp.end(); i++) - { - (this->*(*i))(); - } - + // call update functions, instead of traversing a function pointer + // list. Remove this comment! + + sound(); + if ( graphics_flag ) + graphics(); + if ( comm_flag ) + comm(); + ai(); + if ( release_flag ) + release(); } void Core::sound() @@ -165,32 +165,31 @@ namespace engine{ if (this->timer.elapsed_timer() >= (1.0 / this->frames_per_second)) { //int a;std::cin >> a; - this->fp->push_back(&Core::graphics); + graphics_flag = true; this->timer.start_timer(); //==== std::cout << "GRAPHICS GRAPHICS GRAPHICS GRAPHICS GRAPHICS" << std::endl; } else { - this->fp->remove(&Core::graphics); + graphics_flag = false; } if (ENGINE_INPUT == this->msg) { - this->fp->push_back(&Core::comm); + comm_flag = true; } else { - this->fp->remove(&Core::comm); + comm_flag = false; } if (ENGINE_QUIT == this->msg) { - this->fp->push_back(&Core::release); + release_flag = true; } } Core::~Core() { //deconstructor - delete(this->fp); } } diff --git a/src/eng_core.cpp.1 b/src/eng_core.cpp.1 deleted file mode 100644 index 2bfb4ca1..00000000 --- a/src/eng_core.cpp.1 +++ /dev/null @@ -1,195 +0,0 @@ -#include "src\eng_core.h" - -#include "src\eng_snd.h" -#include "src\eng_gfx.h" -#include "src\eng_comm.h" -#include "src\eng_ai.h" - -#include - -//#include "src\lib\dos_gfx.h" -//#include "src\lib\opl2.h" -//#include "src\lib\dos_comm.h" - -namespace engine{ - - Core::Core() - { - // Hardware Initiation - this->init(); - - //default constructor - this->msg = ENGINE_RUN; - this->timer.start_timer(); - this->frames_per_second = 60; - - // Global Variables - this->bing = 4; // test global variable - this->x = 0; // X - this->y = 0; // Y - - // Start setttings of flags. I hope I got the same - // logic as it was before, with the STL list. - this->graphics_flag = true; - this->comm_flag = true; - this->release_flag = false; - } - - void Core::update() - { - // call update functions, instead of traversing a function pointer - // list. Remove this comment! - - sound(); - if ( graphics_flag ) - graphics(); - if ( comm_flag ) - comm(); - ai(); - if ( release_flag ) - release(); - } - - void Core::sound() - { - //wrap sound lib - do_sound(); - } - void Core::graphics() - { - //int num_frames = 60; - //double fps = 1.0 / num_frames; - //double now = this->timer.elapsed_timer(); - //std::cout << "fps: " << fps << " now: " << now << std::endl; - //if (this->timer.elapsed_timer() >= fps) - //{ - //wrap graphics lib - do_graphics(); - //this->timer.start_timer(); - //} - } - void Core::comm() - { - //int num_frames = 60; - //double fps = 1.0 / num_frames; - //double now = this->timer.elapsed_timer(); - //std::cout << "fps: " << fps << " now: " << now << std::endl; - //if (this->timer.elapsed_timer() >= fps) - //{ - //wrap comm lib - this->msg = do_communication(); - //this->timer.start_timer(); - //} - } - void Core::ai() - { - //wrap A.I. lib - do_artificial_intelligence(); - } - - engine_message Core::_msg() - { - return this->msg; - } - - void Core::run() - { -//---- int i = 0; - while (ENGINE_EXIT != this->msg) - { - //next line for purely testing purposes -//---- i++;if(i==600){char a;std::cin >> a;this->keeq[a] = true;i=0;} - this->sync(); - this->input(); - this->update(); - } - } - - bool Core::init(){ - bool xz = 0; // error switch... - std::cout << "VIDEO INITIATION" << std::endl; - setvideo(0x13, 1); - setvbuff(1); - std::cout << "Checking for Adlib sound card...." << std::endl; - if(!AdlibExists()){ - std::cout << "not found." << std::endl; - xz = 1; - } - std::cout << "found." << std::endl; - std::cout << "OPL2 INITIATION" << std::endl; - fmtest(); - std::cout << "\nPress ESC to quit the game engine core test." << std::endl; - std::cout << "1 - 9 for graphical tests!" << std::endl; - std::cout << "space bar for control and sprite test!" << std::endl; - std::cout << "z key for noise!" << std::endl; - std::cout << "Press press any key to continue!" << std::endl; - getch(); - std::cout << "INPUT INITIATION" << std::endl; - setkb(1); - std::cout << "INITIATION" << std::endl; - return xz; - } - - void Core::release() - { - //release contexts and set engine to exit - setvideo(0x03, 0); - setvbuff(0); - setkb(0); - FMReset(); - this->msg = ENGINE_EXIT; - } - - void Core::input(){ - //retrieve input device information - //dummy 'w' and 'p' down, t up -//---- bool dummy_input_available = true; -//---- if(dummy_input_available) -//---- { -//---- std::cout << "key down" << std::endl; -//---- this->keeq['w'] = true; -//---- this->keeq['p'] = true; -//---- this->keeq['t'] = false; - //notify engine that input occured - this->msg = ENGINE_INPUT; -//---- } -//---- else -//---- { -//---- std::cout << "key up" << std::endl; -//---- this->msg = ENGINE_RUN; -//---- } - } - - void Core::sync() - { - if (this->timer.elapsed_timer() >= (1.0 / this->frames_per_second)) - { - //int a;std::cin >> a; - graphics_flag = true; - this->timer.start_timer(); -//==== std::cout << "GRAPHICS GRAPHICS GRAPHICS GRAPHICS GRAPHICS" << std::endl; - } - else - { - graphics_flag = false; - } - if (ENGINE_INPUT == this->msg) - { - comm_flag = true; - } - else - { - comm_flag = false; - } - if (ENGINE_QUIT == this->msg) - { - release_flag = true; - } - } - - Core::~Core() - { - //deconstructor - } - -} diff --git a/src/eng_core.h b/src/eng_core.h index 996ffa06..e19529b1 100644 --- a/src/eng_core.h +++ b/src/eng_core.h @@ -1,14 +1,13 @@ #ifndef _ENGINE_CORE_H_ #define _ENGINE_CORE_H_ -#include #include "src\engine.h" #include "src\timer.h" namespace engine { class Core { - public: + public: Core(); void update(); void sound(); @@ -26,17 +25,19 @@ namespace engine { protected: private: engine_message msg; - std::list *fp; - Timer timer; -// unsigned char key[256]; + Timer timer; +// unsigned char key[256]; int frames_per_second; - //std::list fp; + //std::list fp; /* int xxxx = 0; int yyyy = 0;*/ - int bing; - int x; + int bing; + int x; int y; + + // Because we removed the function pointer STL list: + bool graphics_flag, comm_flag, release_flag; }; } -#endif/*_ENGINE_CORE_H_*/ \ No newline at end of file +#endif/*_ENGINE_CORE_H_*/ diff --git a/src/eng_core.h.1 b/src/eng_core.h.1 deleted file mode 100644 index e19529b1..00000000 --- a/src/eng_core.h.1 +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _ENGINE_CORE_H_ -#define _ENGINE_CORE_H_ - -#include "src\engine.h" -#include "src\timer.h" - -namespace engine { - class Core - { - public: - Core(); - void update(); - void sound(); - void graphics(); - void comm(); - void ai(); - engine_message _msg(); - void run(); - bool init(); - void release(); - void input(); - void sync(); - ~Core(); - - protected: - private: - engine_message msg; - Timer timer; -// unsigned char key[256]; - int frames_per_second; - //std::list fp; -/* int xxxx = 0; - int yyyy = 0;*/ - int bing; - int x; - int y; - - // Because we removed the function pointer STL list: - bool graphics_flag, comm_flag, release_flag; - }; -} - -#endif/*_ENGINE_CORE_H_*/ -- 2.39.5