aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ephysics/ephysics_main.cpp
blob: e486f89ad1674831cd3fab59792fecafd897382c (plain) (blame)
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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Ecore.h"
#include "Eina.h"

#include "ephysics_private.h"

#ifdef  __cplusplus
extern "C" {
#endif

int _ephysics_log_dom = -1;
static int _ephysics_dom_count = 0;
static int _ephysics_init_count = 0;

void
ephysics_dom_count_inc(void)
{
   _ephysics_dom_count++;
}

void
ephysics_dom_count_dec(void)
{
   _ephysics_dom_count--;
   if (_ephysics_dom_count)
     return;

   INF("EPhysics shutdown");

   eina_log_domain_unregister(_ephysics_log_dom);
   _ephysics_log_dom = -1;

   eina_shutdown();
}

EAPI int
ephysics_init()
{
   if (++_ephysics_init_count != 1)
     return _ephysics_init_count;

   if (!eina_init())
     {
        EINA_LOG_CRIT("Couldn't init eina");
        return --_ephysics_init_count;
     }

   if (!ecore_init())
     {
        EINA_LOG_CRIT("Couldn't init ecore");
        goto no_ecore;
     }

   _ephysics_log_dom = eina_log_domain_register("ephysics", EPHYSICS_LOG_COLOR);
   if (_ephysics_log_dom < 0)
     {
        EINA_LOG_CRIT("Couldn't create a log domain for ephysics");
        goto no_log;
     }

   if (!ephysics_world_init())
     {
        ERR("Couldn't initialize worlds");
        goto no_world;
     }

   ephysics_dom_count_inc();
   INF("EPhysics initialized");

   return _ephysics_init_count;

no_world:
   eina_log_domain_unregister(_ephysics_log_dom);
   _ephysics_log_dom = -1;
no_log:
   ecore_shutdown();
no_ecore:
   eina_shutdown();
   return --_ephysics_init_count;
}

EAPI int
ephysics_shutdown()
{
   if (--_ephysics_init_count != 0)
     return _ephysics_init_count;

   ephysics_world_shutdown();
   ecore_shutdown();
   ephysics_dom_count_dec();

   return _ephysics_init_count;
}

#ifdef  __cplusplus
}
#endif