I've had the examples old main.cpp side by side with my event receiver and my other code and come up with every way possible to implement the receiver. I'm pulling my hair out because I'm on the fifth week, lots of code written in other files and no way to access mouse and keyboard input.
And I will feel even more ashamed if it is something so daft... Here's the main portions of the code...:
Please, can someone point out my mistake?
Code: Select all
#ifndef MY_IRR_H
#define MY_IRR_H
#include <irrlicht.h>
#include "stdio.h"
#include "stdlib.h"
#define DEG2RAD(a) (a*3.14159265f/180.0f)
using namespace irr;
// ----------------------------------------------------------------------------
class IRRevent : public IEventReceiver
{
public:
bool keys[KEY_KEY_CODES_COUNT];
virtual bool OnEvent(const SEvent& event)
{
// Keys???
if (event.EventType == EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
switch ((int)event.MouseInput.Event)
{
case irr::EMIE_MOUSE_MOVED :
mousex = event.MouseInput.X;
mousey = event.MouseInput.Y;
break;
case irr::EMIE_MOUSE_WHEEL :
mousez = event.MouseInput.Wheel;
break;
case irr::EMIE_LMOUSE_LEFT_UP :
mouseclick |= 0x01;
break;
case irr::EMIE_LMOUSE_PRESSED_DOWN :
mouseclick &= 0x06;
break;
case irr::EMIE_RMOUSE_LEFT_UP :
mouseclick |= 0x02;
break;
case irr::EMIE_RMOUSE_PRESSED_DOWN :
mouseclick &= 0x05;
break;
case irr::EMIE_MMOUSE_LEFT_UP :
mouseclick |= 0x04;
break;
case irr::EMIE_MMOUSE_PRESSED_DOWN :
mouseclick &= 0x03;
break;
}
return false;
}
return false;
}
IRRevent()
{
for (u32 i=0; i<irr::KEY_KEY_CODES_COUNT; i++)
keys[i]=false;
}
int mousex, mousey, mousez, mouseclick;
int lastmousex, lastmousey;
};
// ----------------------------------------------------------------------------
#endif // MY_IRR_H
Code: Select all
#include "../include/defs.h"
#include "../include/GAME_CLASS.h"
#include "../include/player_class.h"
void test1();
// implemented if I decide to link to another language
#ifdef COMPILE_MAIN
int main( int argc, char *argv[] )
{
printf("Calling function - test1\n");
test1();
return 0;
}
#endif
void test1()
{
wchar_t buf[32]; // temporary character buffer
printf("Initializing IrrLicht\n");
gc.irr_init( 800, 600 );
printf("Getting the current TIMER value\n");
u32 time = gc.device->getTimer()->getTime();
while ( gc.device->getTimer()->getTime() < ( time + 4000 ) )
{
gc.device->getTimer()->tick();
gc.driver->beginScene(true, true, 0x002040 );
printf("About to print HELLO WORLD!\n");
gc.font->draw( L"HELLO WORLD", core::rect<s32>(0,0,100,10),0xffffffff );
printf("Displaying MOUSE COORDS\n");
swprintf( buf,16,L"%d,%d", gc.events->mousex, gc.events->mousey );
gc.font->draw( buf, core::rect<s32>(0,10,100,20),0xffffffff );
for (int key=0; key<16; key++)
{
for (int pos=0; pos<16; pos++)
{
buf[pos] = gc.events->keys[key*16+pos] + '0';
}
buf[16] = 0;
gc.font->draw( buf, core::rect<s32>(0,key*10+30,0,0),0xffffffff );
}
printf("Displaying screen FPS");
swprintf( buf, 16, L"Free-Born FPS-%d", gc.driver->getFPS() );
gc.font->draw( buf, core::rect<s32>(0,200,0,0), 0xffffffff );
gc.smgr->drawAll();
gc.gui->drawAll();
gc.driver->endScene();
gc.device->yield();
}
gc.device->drop();
}
Code: Select all
#ifndef GAME_CLASS_H
#define GAME_CLASS_H
#include "../include/player_class.h"
#include <mysql/mysql.h>
#include "irrlicht.h"
#include "../include/my_irr.h"
using namespace irr;
class GAME_CLASS
{
public:
GAME_CLASS();
virtual ~GAME_CLASS();
MYSQL* get_mysql()
{
return mysql;
}
MYSQL* sql_init()
{
return mysql_init( mysql );
}
void sql_close()
{
mysql_close( mysql );
}
/*
* MYSQL details for reading the main game database
*/
private:
MYSQL *mysql;
/*
* Irrlicht stuff for accessing the 3D/2D, etc engine
*/
public:
irr::IrrlichtDevice *device;
irr::video::IVideoDriver *driver;
irr::scene::ISceneManager *smgr;
irr::gui::IGUIEnvironment *gui;
irr::gui::IGUIFont *font;
IRRevent *events;
void irr_init(int w,int h);
};
//extern IRRevent irrevent;
extern GAME_CLASS gc;
#endif // GAME_CLASS_H
Code: Select all
#include "../include/GAME_CLASS.h"
/*
* GLOBALs for the entire game
*/
GAME_CLASS gc;
/*
* De/Constructor for the main Game class
*/
GAME_CLASS::GAME_CLASS()
{
mysql = 0;
events = 0;
}
GAME_CLASS::~GAME_CLASS()
{
if (events) delete events;
}
/*
* Irrlicht stuff for accessing the 3D/2D, etc engine
*/
void GAME_CLASS::irr_init(int w,int h)
{
events = new IRRevent;
device = irr::createDevice(video::EDT_OPENGL,
core::dimension2du(w,h),32,false, false, false, events);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
gui = device->getGUIEnvironment();
font = gui->getBuiltInFont();
}