Skip to content

Commit d4bd6b5

Browse files
committed
Restored Import functionality for exported games
On UserInitialize, check to see if there is a project to be imported. Added a new StartupPhaseResult enumeration. This can be used to determine if the next initialization phase should be run. Load shortcuts and documentation after user initializiation. The MainConfig data directory where they are loaded from can be modified by UserInitialize (e.g.: for imported games)
1 parent 7423179 commit d4bd6b5

File tree

7 files changed

+70
-17
lines changed

7 files changed

+70
-17
lines changed

Libraries/Core/Engine/Configuration.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,14 @@ Cog* LoadConfig(ModifyConfigFn modifier, void* userData)
432432
return nullptr;
433433
}
434434

435-
modifier(configCog, userData);
436-
437435
MainConfig* mainConfig = HasOrAdd<MainConfig>(configCog);
438436
mainConfig->SourceDirectory = sourceDirectory;
439437
mainConfig->DataDirectory = dataDirectory;
440438

439+
// Modifier can modify MainConfig on configCog
440+
// so let it run after setting source and data dirs
441+
modifier(configCog, userData);
442+
441443
Z::gEngine->mConfigCog = configCog;
442444

443445
SaveConfig();

Libraries/Projects/Startup/Startup.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ void ZeroStartup::UserInitializeConfig(Cog* configCog)
1919
{
2020
}
2121

22-
void ZeroStartup::UserInitialize()
22+
StartupPhaseResult::Enum ZeroStartup::UserInitialize()
2323
{
24+
return StartupPhaseResult::Continue;
2425
}
2526

2627
void ZeroStartup::UserStartup()
@@ -48,15 +49,27 @@ void ZeroStartup::Exit(int returnCode)
4849

4950
void ZeroStartup::MainLoop()
5051
{
52+
StartupPhaseResult::Enum result = StartupPhaseResult::Continue;
5153
switch (mPhase)
5254
{
5355
case StartupPhase::Initialize:
5456
Initialize();
5557
NextPhase();
5658
break;
5759
case StartupPhase::UserInitialize:
58-
UserInitialize();
59-
NextPhase();
60+
result = UserInitialize();
61+
if (result == StartupPhaseResult::Continue)
62+
{
63+
Shortcuts::GetInstance()->Load(
64+
FilePath::Combine(Z::gEngine->GetConfigCog()->has(MainConfig)->DataDirectory, "Shortcuts.data"));
65+
66+
// Load documentation for all native libraries
67+
DocumentationLibrary::GetInstance()->LoadDocumentation(
68+
FilePath::Combine(Z::gEngine->GetConfigCog()->has(MainConfig)->DataDirectory, "Documentation.data"));
69+
NextPhase();
70+
}
71+
else
72+
mPhase = StartupPhase::Shutdown;
6073
break;
6174
case StartupPhase::Startup:
6275
Startup();
@@ -88,6 +101,9 @@ void ZeroStartup::MainLoop()
88101
break;
89102
case StartupPhase::Shutdown:
90103
Shutdown();
104+
// Exit could still be false UserInitialize goes straight to shutdown
105+
// consider refactoring
106+
mExit = true;
91107
break;
92108
}
93109

@@ -221,12 +237,12 @@ void ZeroStartup::Initialize()
221237

222238
Tweakables::Load();
223239

224-
Shortcuts::GetInstance()->Load(
225-
FilePath::Combine(Z::gEngine->GetConfigCog()->has(MainConfig)->DataDirectory, "Shortcuts.data"));
240+
//Shortcuts::GetInstance()->Load(
241+
// FilePath::Combine(Z::gEngine->GetConfigCog()->has(MainConfig)->DataDirectory, "Shortcuts.data"));
226242

227-
// Load documentation for all native libraries
228-
DocumentationLibrary::GetInstance()->LoadDocumentation(
229-
FilePath::Combine(Z::gEngine->GetConfigCog()->has(MainConfig)->DataDirectory, "Documentation.data"));
243+
//// Load documentation for all native libraries
244+
//DocumentationLibrary::GetInstance()->LoadDocumentation(
245+
// FilePath::Combine(Z::gEngine->GetConfigCog()->has(MainConfig)->DataDirectory, "Documentation.data"));
230246

231247
ZPrint("Os: %s\n", Os::GetVersionString().c_str());
232248
}

Libraries/Projects/Startup/Startup.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ DeclareEnum10(
3232
// All libraries are shutdown and the engine is destroyed.
3333
Shutdown);
3434

35+
// Determine whether to continue to next startup phase or not
36+
DeclareEnum2(StartupPhaseResult,
37+
// Continue to the next phase
38+
Continue,
39+
// Do not continue to the next phase
40+
Quit);
41+
3542
// Runs through phases of initialization, allowing platforms that don't support threading
3643
// to yeild time back to the OS/Browser between updates. This also unifies Editor/Game/Launcher startup.
3744
class ZeroStartup
@@ -71,7 +78,7 @@ class ZeroStartup
7178
// The order these are declared is the order they will be called.
7279
virtual void UserInitializeLibraries();
7380
virtual void UserInitializeConfig(Cog* configCog);
74-
virtual void UserInitialize();
81+
virtual StartupPhaseResult::Enum UserInitialize();
7582
virtual void UserStartup();
7683
virtual void UserCreation();
7784
virtual void UserShutdown();

Libraries/Projects/WelderEditor/GameOrEditorStartup.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,25 @@ void GameOrEditorStartup::UserInitializeConfig(Cog* configCog)
1313
HasOrAdd<EditorSettings>(configCog);
1414
HasOrAdd<ContentConfig>(configCog);
1515
HasOrAdd<TextEditorConfig>(configCog);
16+
MainConfig* mainConfig = configCog->has(MainConfig);
17+
if (mainConfig && mEmbeddedPackage)
18+
{
19+
static const String cDataDirectoryName("Data");
20+
mainConfig->DataDirectory = FilePath::Combine(mEmbeddedOutputDirectory, cDataDirectoryName);
21+
}
1622
}
1723

18-
void GameOrEditorStartup::UserInitialize()
24+
StartupPhaseResult::Enum GameOrEditorStartup::UserInitialize()
1925
{
2026
String projectFile = Environment::GetValue<String>("file");
2127
bool playGame = Environment::GetValue<bool>("play", false);
2228
String newProject = Environment::GetValue<String>("newProject");
2329

30+
Importer importer;
31+
ImporterResult::Type importResult = importer.CheckForImport();
32+
if (importResult == ImporterResult::ExecutedAnotherProcess)
33+
return StartupPhaseResult::Quit;
34+
2435
// Check to see if there was a project file in the same directory.
2536
static const String cDefaultProjectFile("Project.zeroproj");
2637
if (FileExists(cDefaultProjectFile))
@@ -29,6 +40,15 @@ void GameOrEditorStartup::UserInitialize()
2940
playGame = true;
3041
}
3142

43+
// Fix the project file path for exports to be in the import's output directory
44+
mEmbeddedPackage = (importResult == ImporterResult::Embeded);
45+
if (mEmbeddedPackage)
46+
{
47+
mEmbeddedOutputDirectory = importer.mOutputDirectory;
48+
projectFile = FilePath::Combine(mEmbeddedOutputDirectory, "Project.zeroproj");
49+
playGame = true;
50+
}
51+
3252
// If there was no specified project file (or it doesn't exist) and we're not
3353
// creating a new project, then use a fall-back project that we open from our
3454
// data directory. This project should be read-only, but is useful for testing
@@ -54,7 +74,8 @@ void GameOrEditorStartup::UserInitialize()
5474
if (projectCog == nullptr)
5575
{
5676
FatalEngineError("Failed load project '%s'", projectFile.c_str());
57-
return Exit(1);
77+
Exit(1);
78+
return StartupPhaseResult::Continue;
5879
}
5980

6081
// Since we don't create a resiziable wigdet/close button, etc.
@@ -70,6 +91,8 @@ void GameOrEditorStartup::UserInitialize()
7091
mProjectCog = projectCog;
7192
mProjectFile = projectFile;
7293
mNewProject = newProject;
94+
95+
return StartupPhaseResult::Continue;
7396
}
7497

7598
void GameOrEditorStartup::UserStartup()

Libraries/Projects/WelderEditor/GameOrEditorStartup.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ class GameOrEditorStartup : public ZeroStartup
1111
Cog* mProjectCog = nullptr;
1212
String mProjectFile;
1313
String mNewProject;
14+
bool mEmbeddedPackage = false;
15+
String mEmbeddedOutputDirectory;
1416

1517
void UserInitializeConfig(Cog* configCog) override;
16-
void UserInitialize() override;
18+
StartupPhaseResult::Enum UserInitialize() override;
1719
void UserStartup() override;
1820
void UserCreation() override;
1921
};

Libraries/Projects/WelderLauncher/LauncherStartup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void LauncherStartup::UserInitializeConfig(Cog* configCog)
2323
versionConfig->ApplyCommandLineArguments();
2424
}
2525

26-
void LauncherStartup::UserInitialize()
26+
StartupPhaseResult::Enum LauncherStartup::UserInitialize()
2727
{
2828
// Check and see if another launcher is already open (has to happen after
2929
// startup)
@@ -36,7 +36,8 @@ void LauncherStartup::UserInitialize()
3636
ZPrint("Mutex is already open. Sending a message to the open launcher and "
3737
"closing\n");
3838
Zero::LauncherSingletonCommunication communicator;
39-
return Exit(0);
39+
Exit(0);
40+
return StartupPhaseResult::Continue;
4041
}
4142

4243
CrashHandler::SetRestartCommandLine(Environment::GetInstance()->mCommandLine);
@@ -45,6 +46,8 @@ void LauncherStartup::UserInitialize()
4546
mMinimumWindowSize = IntVec2(1024, 595);
4647
mWindowCentered = true;
4748
mWindowState = WindowState::Windowed;
49+
50+
return StartupPhaseResult::Continue;
4851
}
4952

5053
void LauncherStartup::UserStartup()

Libraries/Projects/WelderLauncher/LauncherStartup.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LauncherStartup : public ZeroStartup
99
protected:
1010
void UserInitializeLibraries() override;
1111
void UserInitializeConfig(Cog* configCog) override;
12-
void UserInitialize() override;
12+
StartupPhaseResult::Enum UserInitialize() override;
1313
void UserStartup() override;
1414
void UserCreation() override;
1515
void UserShutdown() override;

0 commit comments

Comments
 (0)