| 183 | } |
| 184 | |
| 185 | void ManagedEditor::Init() |
| 186 | { |
| 187 | // Note: editor modules should perform quite fast init, any longer things should be done in async during 'editor splash screen time |
| 188 | void* args[2]; |
| 189 | MClass* mclass = GetClass(); |
| 190 | if (mclass == nullptr) |
| 191 | { |
| 192 | LOG(Fatal, "Invalid Editor assembly! Missing class."); |
| 193 | } |
| 194 | const auto initMethod = mclass->GetMethod("Init", ARRAY_COUNT(args)); |
| 195 | if (initMethod == nullptr) |
| 196 | { |
| 197 | LOG(Fatal, "Invalid Editor assembly! Missing initialization method."); |
| 198 | } |
| 199 | MObject* instance = GetOrCreateManagedInstance(); |
| 200 | if (instance == nullptr) |
| 201 | { |
| 202 | LOG(Fatal, "Failed to create editor instance."); |
| 203 | } |
| 204 | MObject* exception = nullptr; |
| 205 | StartupFlags flags = StartupFlags::None; |
| 206 | if (CommandLine::Options.Headless.IsTrue()) |
| 207 | flags |= StartupFlags::Headless; |
| 208 | if (CommandLine::Options.SkipCompile.IsTrue()) |
| 209 | flags |= StartupFlags::SkipCompile; |
| 210 | if (CommandLine::Options.NewProject.IsTrue()) |
| 211 | flags |= StartupFlags::NewProject; |
| 212 | if (CommandLine::Options.Exit.IsTrue()) |
| 213 | flags |= StartupFlags::Exit; |
| 214 | args[0] = &flags; |
| 215 | Guid sceneId; |
| 216 | if (!CommandLine::Options.Play.HasValue() || (CommandLine::Options.Play.HasValue() && Guid::Parse(CommandLine::Options.Play.GetValue(), sceneId))) |
| 217 | { |
| 218 | sceneId = Guid::Empty; |
| 219 | } |
| 220 | args[1] = &sceneId; |
| 221 | initMethod->Invoke(instance, args, &exception); |
| 222 | if (exception) |
| 223 | { |
| 224 | // Umm, we could handle this but here we are not sure if it is sth fatal. |
| 225 | // Editor should catch non-critical exceptions and leave fatal ones |
| 226 | MException ex(exception); |
| 227 | ex.Log(LogType::Warning, TEXT("ManagedEditor::Init")); |
| 228 | LOG_STR(Fatal, TEXT("Failed to initialize editor! ") + ex.Message); |
| 229 | } |
| 230 | |
| 231 | // Clear flag to ensure to call Exit() on assembly unloading |
| 232 | WasExitCalled = false; |
| 233 | |
| 234 | // Load scripts if auto-load on startup is disabled |
| 235 | if (!ManagedEditorOptions.ForceScriptCompilationOnStartup || EnumHasAllFlags(flags, StartupFlags::SkipCompile)) |
| 236 | { |
| 237 | LOG(Info, "Loading managed assemblies (due to disabled compilation on startup)"); |
| 238 | Scripting::Load(); |
| 239 | |
| 240 | const auto endInitMethod = mclass->GetMethod("EndInit"); |
| 241 | if (endInitMethod == nullptr) |
| 242 | { |
nothing calls this directly
no test coverage detected