#include #include #include using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; #pragma comment(lib, "Irrlicht.lib") #pragma comment(lib, "ws2_32.lib") IrrlichtDevice* device = 0; gui::IGUIFileOpenDialog* fileopen; gui::IGUIButton* sendfilebutton; io::IFileSystem* filesystem; irr::net::INetManager* netmgr; gui::IGUIEnvironment* guienv; stringc mystring; #define CLIENT // Are we the client or the server? class MyEventReceiver : public IEventReceiver { public: virtual bool OnEvent(SEvent event) { if(event.EventType == irr::EET_KEY_INPUT_EVENT) { if(event.KeyInput.Key == KEY_ESCAPE) { device->closeDevice(); } } if(event.EventType == irr::EET_GUI_EVENT) { if(event.GUIEvent.Caller == fileopen) { if(event.GUIEvent.EventType == EGET_FILE_SELECTED) { mystring = fileopen->getFilename(); netmgr->sendFile((char*)mystring.c_str(),"sentfile"); } } if(event.GUIEvent.Caller == sendfilebutton) { if(event.GUIEvent.EventType == EGET_BUTTON_CLICKED) { fileopen = guienv->addFileOpenDialog(L"Open file"); } } } return false; } }; int main() { MyEventReceiver receiver; device = createDevice(video::EDT_OPENGL, core::dimension2d(800, 600), 32, false, false, true, &receiver); video::IVideoDriver* driver = device->getVideoDriver(); scene::ISceneManager* smgr = device->getSceneManager(); guienv = device->getGUIEnvironment(); filesystem = device->getFileSystem(); // Initialize NetManager netmgr = net::createNetManager(device); // Set the NetManager to output info to console netmgr->setVerbose(1); // Set up client or server #ifdef CLIENT netmgr->setUpClient(); #else netmgr->setUpServer(); #endif // Create a simple camera smgr->addCameraSceneNode(); int lastFPS = -1; sendfilebutton = guienv->addButton(rect(350,250,450,350),0,-1,L"Send a file."); while(device->run()) { driver->beginScene(true, true, video::SColor(255,113,113,133)); smgr->drawAll(); // draw the 3d scene guienv->drawAll(); driver->endScene(); #ifdef CLIENT netmgr->updateClient(); #else netmgr->updateServer(); // If space is pressed rotate the texture, we do this by sending a custom variable over the network. #endif int fps = driver->getFPS(); if (lastFPS != fps) { wchar_t tmp[1024]; swprintf_s(tmp, 1024, L"Network Test[%ls] fps: %d (Server can press Space to change Cube colour!)", driver->getName(), fps); device->setWindowCaption(tmp); lastFPS = fps; } } //In the end, delete the Irrlicht device. device->drop(); return 0; }