File: main.cpp

package info (click to toggle)
angelscript 2.35.1%2Bds-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,388 kB
  • sloc: cpp: 71,969; asm: 1,558; makefile: 665; xml: 214; javascript: 42; ansic: 22; python: 22; sh: 7
file content (90 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download | duplicates (2)
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
#include <iostream>  // cout
#include <stdio.h>
#include <angelscript.h>
#ifdef _MSC_VER
	#include <crtdbg.h>  // debugging routines
#endif

#include "gamemgr.h"
#include "scriptmgr.h"

using namespace std;

CScriptMgr *scriptMgr = 0;
CGameMgr   *gameMgr   = 0;

int main(int argc, char **argv)
{
#ifdef _MSC_VER
	// Detect memory leaks
	_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
	_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);

	// Use _CrtSetBreakAlloc(n) to find a specific memory leak
#endif

	int r;

	// Make sure the game is being executed with the correct working directory
	// At the very least there should be a 'player.as' script for controlling the 
	// player character.
	FILE *f = fopen("player.as", "r");
	if( f == 0 )
	{
		cout << "The game is not executed in the correct location. Make sure you set the working directory to the path where the 'player.as' script is located." << endl;
		cout << endl;
		cout << "Press enter to exit." << endl;
		char buf[10];
		cin.getline(buf, 10);
		return -1;
	}
	fclose(f);

	// Initialize the game manager
	gameMgr = new CGameMgr();

	// Initialize the script manager
	scriptMgr = new CScriptMgr();
	r = scriptMgr->Init();
	if( r < 0 )
	{
		delete scriptMgr;
		delete gameMgr;
		return r;
	}

	// Start a new game
	r = gameMgr->StartGame();
	if( r < 0 )
	{
		cout << "Failed to initialize the game. Please verify the script errors." << endl;
		cout << endl;
		cout << "Press enter to exit." << endl;
		char buf[10];
		cin.getline(buf, 10);
		return -1;
	}

	// Let the game manager handle the game loop
	gameMgr->Run();
	
	// Uninitialize the game manager
	if( gameMgr )
	{
		delete gameMgr;
		gameMgr = 0;
	}

	// Uninitialize the script manager
	if( scriptMgr )
	{
		delete scriptMgr;
		scriptMgr = 0;
	}

	return r;
}