‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
system_shared.csc
Go to the documentation of this file.
1 #using scripts\shared\array_shared;
2 #using scripts\shared\flag_shared;
3 
4 #insert scripts\shared\shared.gsh;
5 
6 #namespace system;
7 
8 /*///////////////////////////////////////////////////////////////////////////////////////////////////////////
9 
10 Usage:
11 
12 REGISTER_SYSTEM( <system_name>, <preload_function>, <postload_function>, <pre-reqs> )
13 
14  system_name: Name of the system. To avoid confusion, this typically should match the namespace
15  that the system is in.
16 
17  preload_function: This function will automatically run during the pre initializion of a level load - this
18  will be during the first frame, during the level load phase (before _load::main)
19  for all code executes during the first frame is: autoexecs, level load, gametype, finalization
20 
21  postload_function: This function will automatically run during the post initializion of a level load - this
22  will be during the first frame, during the finalization phase
23  for all code executes during the first frame is: autoexecs, level load, gametype, finalization
24 
25  pre-reqs: Specifies a system or an array of systems that this system requires. This system will
26  wait until the precahce and main functions return from the required systems before
27  running this system's main function. Typically, this can be 'undefined'
28 
29 Example:
30 
31  namespace coolsystem;
32 
33  REGISTER_SYSTEM( "coolsystem", &__init__, undefined )
34 
35  function __init__()
36  {
37  // Runs durring first frame, before any waits.
38  }
39 
40 
41 
43 
44 function register( str_system, func_preinit, func_postinit, reqs = [] )
45 {
46  if ( IsDefined( level.system_funcs) && IsDefined( level.system_funcs[str_system] ) )
47  {
48  return;
49  }
50 
51  //append to the func_init array, we'll sort based on reqs before we run everything
52  DEFAULT( level.system_funcs, [] );
53 
54  level.system_funcs[str_system] = SpawnStruct();
55  level.system_funcs[str_system].prefunc = func_preinit;
56  level.system_funcs[str_system].postfunc = func_postinit;
57  level.system_funcs[str_system].reqs = reqs;
58  level.system_funcs[str_system].predone = !IsDefined(func_preinit);
59  level.system_funcs[str_system].postdone = !IsDefined(func_postinit);
60  level.system_funcs[str_system].ignore = false;
61 }
62 
63 function exec_post_system(req)
64 {
65  /#
66  if (!IsDefined(level.system_funcs[req]))
67  {
68  AssertMsg( "system '" + req + "' is not defined." );
69  }
70  #/
71  if (level.system_funcs[req].ignore)
72  {
73  return ;
74  }
75  if (!level.system_funcs[req].postdone)
76  {
77  [[level.system_funcs[req].postfunc]]();
78  level.system_funcs[req].postdone=true;
79  }
80 }
81 
82 function run_post_systems()
83 {
84  //sort the func_init list based on reqs
85  foreach(key,func in level.system_funcs)
86  {
87  assert(func.predone || func.ignore,"failed to complete pre-initialization before post-initializtion call. Avoid waits in pre-initialization");
88  if (IsArray(func.reqs))
89  {
90  foreach(req in func.reqs)
91  {
92  thread exec_post_system(req);
93  }
94  }
95  else
96  {
97  thread exec_post_system(func.reqs);
98  }
99 
100  thread exec_post_system(key);
101  }
102  if (!level flag::exists("system_init_complete"))
103  {
104  level flag::init("system_init_complete",false);
105  }
106  level flag::set("system_init_complete");
107 }
108 
109 function exec_pre_system(req)
110 {
111  /#
112  if (!IsDefined(level.system_funcs[req]))
113  {
114  AssertMsg( "system '" + req + "' is not defined." );
115  }
116  #/
117  if (level.system_funcs[req].ignore)
118  {
119  return ;
120  }
121  if (!level.system_funcs[req].predone)
122  {
123  [[level.system_funcs[req].prefunc]]();
124  level.system_funcs[req].predone=true;
125  }
126 }
127 
128 function run_pre_systems()
129 {
130  //sort the func_init list based on reqs
131  foreach(key,func in level.system_funcs)
132  {
133  if (IsArray(func.reqs))
134  {
135  foreach(req in func.reqs)
136  {
137  thread exec_pre_system(req);
138  }
139  }
140  else
141  {
142  thread exec_pre_system(func.reqs);
143  }
144 
145  thread exec_pre_system(key);
146  }
147 }
148 
149 function wait_till( required_systems )
150 {
151  if (!level flag::exists("system_init_complete"))
152  {
153  level flag::init("system_init_complete",false);
154  }
155  level flag::wait_till("system_init_complete");
156 }
157 
165 function ignore( str_system )
166 {
167  Assert( !isdefined( level.gametype ), "Ignored systems must be set before level.gametype is set." );
168 
169  if ( !isdefined( level.system_funcs) || !isdefined( level.system_funcs[str_system] ) )
170  {
171  register(str_system,undefined,undefined,undefined); //make sure it exists so it'll get ignored if it tries to add itself after this
172  }
173 
174  level.system_funcs[str_system].ignore = true;
175 }
176 
177 function is_system_running( str_system )
178 {
179  if ( !isdefined( level.system_funcs) || !isdefined( level.system_funcs[str_system] ) )
180  return false;
181 
182  return level.system_funcs[str_system].postdone;
183 }