File: setupcore.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (67 lines) | stat: -rw-r--r-- 2,291 bytes parent folder | download
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
/*
	$Id: setupcore.cpp,v 1.19 2002/01/22 10:14:03 mbn Exp $

	------------------------------------------------------------------------
	ClanLib, the platform independent game SDK.

	This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
	version 2. See COPYING for details.

	For a total list of contributers see CREDITS.

	------------------------------------------------------------------------
*/

#include "Core/precomp.h"
#include <cstdlib>
#include "API/Core/Resources/resourcetype_boolean.h"
#include "API/Core/Resources/resourcetype_integer.h"
#include "API/Core/Resources/resourcetype_string.h"
#include "API/Core/Resources/resourcetype_raw.h"
#include "API/Core/Resources/resourcetype.h"
#include "API/Core/System/setupcore.h"

static CL_RegisterResourceType<CL_ResourceData_Boolean> *restype_boolean = NULL;
static CL_RegisterResourceType<CL_ResourceData_Integer> *restype_integer = NULL;
static CL_RegisterResourceType<CL_ResourceData_String> *restype_string = NULL;
static CL_RegisterResourceType<CL_ResourceData_Raw> *restype_raw = NULL;

void init_system(); // this function is implemented in init_PLATFORM.cpp
void deinit_system(); // this function is implemented in init_PLATFORM.cpp

static int ref_count = 0;

void CL_SetupCore::init(bool register_resources_only)
{
	ref_count++;
	if (ref_count > 1) return;

	restype_boolean = new CL_RegisterResourceType<CL_ResourceData_Boolean>("boolean");
	restype_integer = new CL_RegisterResourceType<CL_ResourceData_Integer>("integer");
	restype_string = new CL_RegisterResourceType<CL_ResourceData_String>("string");
	restype_raw = new CL_RegisterResourceType<CL_ResourceData_Raw>("raw");

	if (register_resources_only) return;
	
	init_system();
}

void CL_SetupCore::deinit()
{
	// Since, CL_SetupCore::init() may be called more than once - Only call deinit at the final call to this function
	if (!ref_count) return;	// Do not allow ref_count to become negative (may occur if something calls deinit() without an init() )
	ref_count--;
	if (ref_count > 0) return;	// Wait until final call to deinit

	delete restype_boolean;
	delete restype_integer;
	delete restype_string;
	delete restype_raw;

	restype_boolean = NULL;
	restype_integer = NULL;
	restype_string = NULL;
	restype_raw = NULL;

	deinit_system();
}