/
main.cpp
98 lines (76 loc) · 2.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//CS-365
//Fall2015
// Gone With The Wind
#ifdef _MSC_VER
// We'll also define this to stop MSVC complaining about sprintf().
#define _CRT_SECURE_NO_WARNINGS
//#define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
//#define _IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_
#pragma comment(lib, "Irrlicht.lib")
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
#include <iostream>
#include <irrlicht.h>
#include "driverChoice.h"
#include "input.h"
#include "movement.h"
#include "object.h"
#include "plane.h"
#include <ctime>
#include "Level.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
// ask user for driver
E_DRIVER_TYPE driverType = driverChoiceConsole();
if (driverType == EDT_COUNT)
return 1;
// create device
Myinput receiver;
//create a joystickInfo array to store joy buttons
array<SJoystickInfo> joystickInfo;
//Create an Irrlicht device to run our program with
IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(800, 720), 32, false, false, false, &receiver);
//If device failed.
if (device == 0)
return EXIT_FAILURE; // could not create selected driver.
//Create movement, **this would be changed to the world class later
movement movement(receiver, joystickInfo, device);
//Create a video display Driver
IVideoDriver* driver = device->getVideoDriver();
//Create a scene manager for the objects and camera
ISceneManager* smgr = device->getSceneManager();
// Create a level and load it in.
Level levelOne(device, driver, smgr);
levelOne.loadLevel();
//adds a camera to the scene
smgr->addCameraSceneNode(0, vector3df(0, 30, -40), vector3df(0, 5, 0));
//Detects plugged in joysticks.
movement.detectJoy();
//Testing out a FPS limit
u32 startTime;
u32 endTime;
u32 lockFPS = 1000 / 30; //Locks to 30 FPS; denominator = wanted FPS
//Main Game Loop
while (device->run())
{
startTime = device->getTimer()->getTime();
//Detect movement and inputs
movement.detectInput();
//Begins the scene for the player...displays all the things.
driver->beginScene(true, true, SColor(100, 70, 70, 70));
smgr->drawAll();
device->getGUIEnvironment()->drawAll();
driver->endScene();
endTime = device->getTimer()->getTime();
if ((endTime - startTime) < lockFPS)
device->sleep(lockFPS - (endTime - startTime));
}
device->drop();
return EXIT_SUCCESS;
}