-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
115 lines (88 loc) · 2.51 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "StdAfx.h"
#include "Util.h"
#include "PhysWorld.h"
#include "NetWorld.h"
#include "GameMenu.h"
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#endif
void zoidcom_logger(const char *_log) {
printf("ZCOM: %s\n", _log);
}
int main(int argc, char *argv[])
{
#ifdef _WIN32
AllocConsole();
#endif
vector<string> args(argv,argv+argc);
// initialize Zoidcom
scoped_ptr<ZoidCom> zcom(new ZoidCom(zoidcom_logger));
if (!zcom || !zcom->Init())
{
throw std::runtime_error("Unable to initialize ZoidCom!");
}
zcom->setLogLevel(0);
intrusive_ptr<IrrlichtDevice> device;
if(args.size() > 1 && args[1] == "server")
{
// Skip graphical interface
// Dedicated server uses 'null' graphics device..
device = intrusive_ptr<IrrlichtDevice>(
createDevice(video::EDT_NULL, core::dimension2d<u32>(640,480), 16, false, true, true),
false /* don't addref */
);
device->getLogger()->setLogLevel(ELL_INFORMATION);
addHeightMapLoader(get_pointer(device));
// Start server, run game instances in loop
while(true)
{
std::cout << "Loading server instance...";
scoped_ptr<Sarona::PhysWorld> serverworld(
new Sarona::PhysWorld(get_pointer(device))
);
serverworld->SetLevel("testlevel/");
serverworld->Bind(9192, false);
serverworld->Start();
serverworld->Wait();
}
}
else
{
// Display main menu, graphical interface needed
device = intrusive_ptr<IrrlichtDevice>(
createDevice(video::EDT_OPENGL, core::dimension2d<u32>(800,600), 16, false, true, true),
false /* don't addref */
);
device->getLogger()->setLogLevel(ELL_WARNING);
addHeightMapLoader(get_pointer(device));
Sarona::GameMenu menu(get_pointer(device));
bool local_game = true;
bool server = true;
if(args.size()>1)
local_game = server = args[1]!="client";
// Run the main menu, let user decide what to do
//menu.Run(local_game, server);
scoped_ptr<Sarona::NetWorld> clientworld;
scoped_ptr<Sarona::PhysWorld> serverworld;
if(server)
{
serverworld.reset(new Sarona::PhysWorld(get_pointer(device)));
serverworld->SetLevel("testlevel/");
serverworld->Bind(9192, local_game);
serverworld->Start();
std::cout << "Server started" << std::endl;
}
clientworld.reset(new Sarona::NetWorld(get_pointer(device)));
clientworld->SetLevel("testlevel/");
clientworld->Connect("localhost:9192", local_game);
// The main thread has to run the irrlicht loop, apparently..
clientworld->Loop();
if(serverworld)
{
serverworld->Shutdown();
serverworld->Wait();
}
}
return 0;
}