I have implemented an IEventReceiver but it doesn't receive keyboard events. Clicking and holding down and dragging and stuff gets caught (seen with logging commands).
But not keyboard presses. Instead, they end up in the terminal I launch it from.
I don't know if it is just irrlicht being out of date or if it is something with the way I compile it, which is like this:
Code: Select all
clang++ -O3 -Iinclude -Llib -lIrrlicht -lNewton -framework OpenGL -framework Cocoa -framework Carbon -framework IOKit src/main.cpp -o who-will-laugh-at-broccoli-boy
Code: Select all
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "irrlicht/irrlicht.h"
//#include "allegro5/allegro.h"
#include "newton/Newton.h"
#define WINDOW_WIDTH 1920
#define WINDOW_HEIGHT 1080
#define MOVEMENT_SPEED 1
using namespace std;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
u32 previous_time;
path data_path;
class PlayerEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent &e) {
cout << "waka" << endl;
if(e.EventType == EET_KEY_INPUT_EVENT) {
key_is_down[e.KeyInput.Key] = e.KeyInput.PressedDown;
}
return false;
}
virtual bool isKeyDown(EKEY_CODE code) const {
return key_is_down[code];
}
PlayerEventReceiver() {
for(u32 i=0; i < KEY_KEY_CODES_COUNT; i++) {
key_is_down[i] = false;
}
}
private:
bool key_is_down[KEY_KEY_CODES_COUNT];
};
struct Player {
int hits;
ICameraSceneNode *camera;
PlayerEventReceiver event_receiver;
vector3df position;
void update(f32 delta) {
if(event_receiver.isKeyDown(KEY_KEY_W)) {
cout << "WAO" << endl;
position.Z += MOVEMENT_SPEED * delta;
}
camera->setPosition(position);
}
};
Player player;
void update(f32 delta) {
player.update(delta);
}
int main(int argc, char **argv) {
cout << "Starting game, prepare to poop pants" << endl;
cout << "Ran with command: " << argv[0] << endl;
IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(WINDOW_WIDTH, WINDOW_HEIGHT), 32, false, true, true, &player.event_receiver);
device->setWindowCaption(L"Who will laugh at broccoli boy?");
cout << ";;;; WORKING DIRECTORY: " << device->getFileSystem()->getWorkingDirectory().c_str() << endl;
data_path.append(device->getFileSystem()->getWorkingDirectory());
data_path.append("/broccoli-boy/data/");
if(!device) {
return EXIT_FAILURE;
}
// if(!al_init()) {
// return EXIT_FAILURE;
// }
IVideoDriver *video_driver = device->getVideoDriver();
ISceneManager *scene_manager = device->getSceneManager();
scene_manager->getParameters()->setAttribute(COLLADA_CREATE_SCENE_INSTANCES, true);
IMesh *world = scene_manager->getMesh(data_path + "world.dae");
if (!world) {
// al_uninstall_system();
device->drop();
return EXIT_FAILURE;
}
IMeshSceneNode *world_node = scene_manager->addMeshSceneNode(world);
if (world_node) {
cout << "Halelujah" << endl;
world_node->setMaterialFlag(EMF_LIGHTING, true);
}
player.camera = scene_manager->addCameraSceneNode(0, vector3df(0, 0, 0), vector3df(5, 0, 10));
player.position = player.camera->getPosition();
device->getCursorControl()->setVisible(false);
while(device->run()) {
const u32 time = device->getTimer()->getTime();
const f32 delta = (f32)(time - previous_time) /1000.f;
update(delta);
video_driver->beginScene(true, true, SColor(100, 0, 0, 0));
scene_manager->drawAll();
video_driver->endScene();
}
//al_uninstall_system();
device->drop();
return 0;
}
To be honest, I don't even know why irrlicht wants to deal with window creation and input etc. It isn't at all the responsibility of a rendering engine imo. I would suggest it should be deprecated and maybe only be used by beginners to get up and running.
All it does is add more maintenance work than irrlicht doesn't need that is completely unnecessary because there is excellent libraries that does it, and does it better than irrlicht (glfw, allegro, sfml, sdl etc). Evidently irrlicht isn't able to keep up because I
have to link to carbon and stuff, which I don't need with allegro (although I'm not sure if they link to it when you compile the library but I really doubt it).
Even if you can keep up you are still intruding on areas where these libraries shine. I haven't been able to initialize allegro which I was planning on using for audio output (and would prefer to use it for window creation and input as well which doesn't seem
to be possible in a non hairy way) because it causes it to not compile anymore, I suspect it is because both irrlicht and allegro tries to deal with the fact that Mac OS X highjacks main for some reason.
I don't really think it has anything to do with how I compile it, I haven't had the same issue when using just allegro and other engines. However I like irrlicht, I just think it sometimes takes on too much - which is funny because one of the reasons I prefer it
over OGRE is that IT takes on waaaay too much responsibility.
Anyways maybe I'm doing something wrong in the code, definitely a possibility.
Thanks!