‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
system_shared.gsc
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  AssertMsg( "system '" + str_system + "' is already defined once. Please use a different name for your system." );
49  return;
50  }
51 
52  //append to the func_init array, we'll sort based on reqs before we run everything
53  DEFAULT( level.system_funcs, [] );
54 
55  level.system_funcs[str_system] = SpawnStruct();
56  level.system_funcs[str_system].prefunc = func_preinit;
57  level.system_funcs[str_system].postfunc = func_postinit;
58  level.system_funcs[str_system].reqs = reqs;
59  level.system_funcs[str_system].predone = !IsDefined(func_preinit);
60  level.system_funcs[str_system].postdone = !IsDefined(func_postinit);
61  level.system_funcs[str_system].ignore = false;
62 }
63 
64 function exec_post_system(req)
65 {
66  /#
67  if (!IsDefined(level.system_funcs[req]))
68  {
69  AssertMsg( "system '" + req + "' is not defined." );
70  }
71  #/
72  if (level.system_funcs[req].ignore)
73  {
74  return ;
75  }
76  if (!level.system_funcs[req].postdone)
77  {
78  [[level.system_funcs[req].postfunc]]();
79  level.system_funcs[req].postdone=true;
80  }
81 }
82 
83 function run_post_systems()
84 {
85  //sort the func_init list based on reqs
86  foreach(key,func in level.system_funcs)
87  {
88  assert(func.predone || func.ignore,"failed to complete pre-initialization before post-initializtion call. Avoid waits in pre-initialization");
89  if (IsArray(func.reqs))
90  {
91  foreach(req in func.reqs)
92  {
93  thread exec_post_system(req);
94  }
95  }
96  else
97  {
98  thread exec_post_system(func.reqs);
99  }
100 
101  thread exec_post_system(key);
102  }
103  if (!level flag::exists("system_init_complete"))
104  {
105  level flag::init("system_init_complete",false);
106  }
107  level flag::set("system_init_complete");
108 }
109 
110 function exec_pre_system(req)
111 {
112  /#
113  if (!IsDefined(level.system_funcs[req]))
114  {
115  AssertMsg( "system '" + req + "' is not defined." );
116  }
117  #/
118  if (level.system_funcs[req].ignore)
119  {
120  return ;
121  }
122  if (!level.system_funcs[req].predone)
123  {
124  [[level.system_funcs[req].prefunc]]();
125  level.system_funcs[req].predone=true;
126  }
127 }
128 
129 function run_pre_systems()
130 {
131  //sort the func_init list based on reqs
132  foreach(key,func in level.system_funcs)
133  {
134  if (IsArray(func.reqs))
135  {
136  foreach(req in func.reqs)
137  {
138  thread exec_pre_system(req);
139  }
140  }
141  else
142  {
143  thread exec_pre_system(func.reqs);
144  }
145 
146  thread exec_pre_system(key);
147  }
148 }
149 
150 function wait_till( required_systems )
151 {
152  if (!level flag::exists("system_init_complete"))
153  {
154  level flag::init("system_init_complete",false);
155  }
156  level flag::wait_till("system_init_complete");
157 }
158 
166 function ignore( str_system )
167 {
168  Assert( !isdefined( level.gametype ), "Ignored systems must be set before level.gametype is set." );
169 
170  if ( !isdefined( level.system_funcs) || !isdefined( level.system_funcs[str_system] ) )
171  {
172  register(str_system,undefined,undefined,undefined); //make sure it exists so it'll get ignored if it tries to add itself after this
173  }
174 
175  level.system_funcs[str_system].ignore = true;
176 }
177 
178 function is_system_running( str_system )
179 {
180  if ( !isdefined( level.system_funcs) || !isdefined( level.system_funcs[str_system] ) )
181  return false;
182 
183  return level.system_funcs[str_system].postdone;
184 }