Hmm... sorry about that.
Code: Select all
#include <irrlicht.h>
#include <irrKlang.h>
#include "main.h"
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "irrKlang.lib")
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
s32 cnt = 0;
void engine::runLevel()
{
// create sfx device
irrKlang = audio::createIrrKlangDevice();
// create gfx device
device =
// createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 32, false, true, true);
// createDevice(video::EDT_DIRECT3D8, core::dimension2d<s32>(800, 600), 32, false, true, true);
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600), 32, false, true, true);
if (device == 0)
return;
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
// init event reveiver
engine receiver;
device->setEventReceiver(&receiver);
// load data
device->getFileSystem()->addZipFileArchive("data/pak0.pk3");
skin = guienv->getSkin();
font = guienv->getFont("data/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
// load map
q3levelmesh = smgr->getMesh("20kdm2.bsp");
q3node = 0;
if (q3levelmesh)
q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
selector = 0;
if (q3node)
{
q3node->setPosition(core::vector3df(-1350,-130,-1400));
selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
q3node->setTriangleSelector(selector);
selector->drop();
}
// create sky box
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
skyboxNode = smgr->addSkyBoxSceneNode(
driver->getTexture("irrlicht2_up.jpg"),
driver->getTexture("irrlicht2_dn.jpg"),
driver->getTexture("irrlicht2_lf.jpg"),
driver->getTexture("irrlicht2_rt.jpg"),
driver->getTexture("irrlicht2_ft.jpg"),
driver->getTexture("irrlicht2_bk.jpg"));
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
// init keymap
SKeyMap keyMap[9];
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_UP;
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;
keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_DOWN;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;
keyMap[4].Action = EKA_STRAFE_LEFT;
keyMap[4].KeyCode = KEY_LEFT;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;
keyMap[6].Action = EKA_STRAFE_RIGHT;
keyMap[6].KeyCode = KEY_RIGHT;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;
// init cam
camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, keyMap, 9, true);
irrKlang->setListenerPosition(camera->getAbsolutePosition(), camera->getTarget());
camera->setPosition(core::vector3df(-100,50,-150));
anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-3,0),
core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();
// disable mouse cursor
device->getCursorControl()->setVisible(false);
selectedSceneNode = 0;
lastSelectedSceneNode = 0;
int lastFPS = -1;
//initHUD
consoleListBox = guienv->addListBox(core::rect<s32>(0,0,800,250));
// play music
audio::ISound* snd = irrKlang->play2D("data/IrrlichtTheme.ogg", true, false, true);
if (snd)
{
snd->setVolume(0.5f); // 50% volume
snd->drop();
}
// run game
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
smgr->drawAll();
guienv->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"[";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return;
}
bool engine::OnEvent(SEvent event)
{
if (event.EventType == irr::EET_LOG_TEXT_EVENT)
{
std::fstream LogFile("LogFile.log",std::ios::out|std::ios::app);
LogFile << (event.LogEvent.Text) << std::endl;
LogFile.close();
const core::stringw msg( event.LogEvent.Text );
consoleListBox->addItem(msg.c_str());
return true;
};
return false;
};
int main()
{
engine eng;
eng.runLevel();
return 0;
}
EDIT: there is suppose to be "#include <fstream>" on the top line... I must have copied it wrong or something.