Skip to content

Commit 2166fe7

Browse files
committed
Pipeline: encapsulate platform dependent prepare code
1 parent 078e2fe commit 2166fe7

9 files changed

Lines changed: 111 additions & 68 deletions

File tree

pipeline/Pipeline.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env node
22

33
const Util = require("./Util");
4-
// TODO: this needs to be moved into desktop
5-
const prepareDesktopShaders = require("../scripts/PrepareDesktopShaders");
64

75
const { program } = require('commander');
86
const rimraf = require("rimraf");
@@ -16,12 +14,13 @@ const path = require("path");
1614
* @param assetDirectory the root path of the folder containing all assets
1715
* @param platform the platform that is currently being built
1816
* @param platformBuildDirectory the root build directory for this platform
19-
* @param gameBuildDirectory the path to the directory where all compiled code will be built to
20-
* @param gameBinDirectory the output directory for this game's binary files
17+
* @param outputDirectory the output directory for this game's assets
2118
* @param pluginManifest the path pointing to the plugin manifest for this build
2219
*/
23-
async function prepareAssets(manifestFile, assetDirectory, platform, gameBuildDirectory, gameBinDirectory, pluginManifest) {
24-
const outputDirectory = path.join(gameBinDirectory, "assets");
20+
async function prepareAssets(manifestFile, assetDirectory, platform, outputDirectory, pluginManifest) {
21+
if (!fse.existsSync(manifestFile)) {
22+
throw new Error(`Manifest file does not exist: ${manifestFile}`);
23+
}
2524

2625
if (fse.existsSync(outputDirectory)) {
2726
rimraf.sync(outputDirectory);
@@ -37,37 +36,19 @@ async function prepareAssets(manifestFile, assetDirectory, platform, gameBuildDi
3736

3837
switch (platform) {
3938
case "n64_libultra":
40-
purgeCompiledAssetData(gameBuildDirectory)
39+
//purgeCompiledAssetData(gameBuildDirectory)
4140
const processN64 = require("./n64_libultra/Process");
4241
await processN64(manifestFile, assetDirectory, outputDirectory, pluginMap);
43-
break;
42+
break;
4443

4544
case "desktop":
4645
const processDesktop = require("./desktop/Process");
4746
await processDesktop(manifestFile, assetDirectory, outputDirectory, pluginMap);
48-
49-
/// TODO: This should be moved into the desktop processing directory
50-
const shaderDestDir = path.join(gameBinDirectory, "glsl");
51-
prepareDesktopShaders(shaderDestDir);
52-
break;
47+
break;
5348

5449
default:
55-
throw new Error(`Unsupported platform: ${manifest.platform}`);
56-
}
57-
}
58-
59-
/**
60-
* This function is needed because the compiler will need to regenerate the packed asset data when there is a change.
61-
* TODO: this should be moved into n64_libulta directory
62-
*/
63-
function purgeCompiledAssetData(gameBuildDirectory){
64-
const compiledDataPath = path.join(gameBuildDirectory, "asm", "asset_data.s.obj");
65-
66-
if (fse.existsSync(compiledDataPath)) {
67-
console.log(`Purging compiled asset data file: ${compiledDataPath}`);
68-
fse.unlinkSync(compiledDataPath)
50+
throw new Error(`Unsupported platform: ${platform}`);
6951
}
70-
7152
}
7253

7354
function loadPlugins(pluginManifestPath) {
@@ -130,9 +111,4 @@ function loadPlugins(pluginManifestPath) {
130111

131112
module.exports = {
132113
prepareAssets: prepareAssets
133-
};
134-
135-
if (require.main === module) {
136-
require("../scripts/RunPipeline")();
137-
main();
138-
}
114+
};

scripts/PrepareBuiltinAssets.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Pipeline = require("../pipeline/Pipeline");
2+
const preparePlatform = require("./PreparePlatform");
23

34
const path = require("path");
45
const fse = require("fs-extra");
@@ -27,9 +28,12 @@ async function prepreBuiltinAssets(folder, name, platform) {
2728

2829
const gameBinDirectory = path.join(platformBuildDir, "bin", name);
2930
const gameBuildDirectory = path.join(platformBuildDir, folder, name, "CMakeFiles", `${name}.dir`);
31+
const outputDirectory = path.join(gameBinDirectory, "assets");
3032

3133
const pluginManifestPath = path.join(targetDirectory, "pipeline", "plugins.json");
32-
await Pipeline.prepareAssets(manifestFile, assetDirectory, platform, gameBuildDirectory, gameBinDirectory, fse.existsSync(pluginManifestPath) ? pluginManifestPath: null);
34+
35+
preparePlatform(platform, gameBuildDirectory, gameBinDirectory);
36+
await Pipeline.prepareAssets(manifestFile, assetDirectory, platform, outputDirectory, fse.existsSync(pluginManifestPath) ? pluginManifestPath: null);
3337
}
3438

3539
async function prepareAllBuiltinAssets(topLevelDir, platform) {

scripts/PrepareDesktopShaders.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

scripts/PrepareGameAssets.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Pipeline = require("../pipeline/Pipeline");
2+
const preparePlatform = require("./PreparePlatform");
23

34
const { program } = require("commander");
45
const fse = require("fs-extra");
@@ -25,6 +26,7 @@ async function prepareGameAssets(platform, target) {
2526

2627
const gameBinDirectory = path.join(platformBuildDir, "bin", target);
2728
const gameBuildDirectory = path.join(platformBuildDir, "src", "CMakeFiles", `${target}.dir`);
29+
const outputDirectory = path.join(gameBinDirectory, "assets");
2830
const pluginManifestPath = path.join(gameDirectory, "pipeline", "plugins.json");
2931

3032
// read game name from package manifest if not specified
@@ -35,6 +37,7 @@ async function prepareGameAssets(platform, target) {
3537
console.log(`No target specified. using default target: ${packageJson.name}`);
3638
}
3739

38-
await Pipeline.prepareAssets(assetManifest, assetDirectory, platform, gameBuildDirectory, gameBinDirectory, fse.existsSync(pluginManifestPath) ? pluginManifestPath: null);
40+
preparePlatform(platform, gameBuildDirectory, gameBinDirectory);
41+
await Pipeline.prepareAssets(assetManifest, assetDirectory, platform, outputDirectory, fse.existsSync(pluginManifestPath) ? pluginManifestPath: null);
3942
}
4043

scripts/PreparePlatform.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fse = require("fs-extra");
2+
const path = require("path");
3+
4+
/**
5+
* @param platform the platform that is currently being built
6+
* @param gameBuildDirectory the path to the directory where all compiled code will be built to
7+
* @param gameBinDirectory the output directory for this game's binary files
8+
*/
9+
function preparePlatform(platform, gameBuildDirectory, gameBinDirectory) {
10+
switch(platform) {
11+
case "desktop":
12+
const shaderDestDir = path.join(gameBinDirectory, "glsl");
13+
prepareDesktopShaders(shaderDestDir);
14+
break;
15+
16+
case "n64_libultra":
17+
purgeCompiledAssetData(gameBuildDirectory);
18+
break;
19+
}
20+
}
21+
22+
async function prepareDesktopShaders(destDir) {
23+
console.log("Preparing Desktop Shaders");
24+
const shaderDir = path.resolve(__dirname, "..", "src", "framework64", "desktop", "glsl");
25+
26+
if (!fse.existsSync(shaderDir)) {
27+
throw new Error(`Unable to locate shader directory: ${shaderDir}`);
28+
}
29+
30+
await fse.ensureDir(destDir);
31+
32+
console.log(`Copy: ${shaderDir} -> ${destDir}`);
33+
fse.copySync(shaderDir, destDir);
34+
}
35+
36+
/** This function is needed because the compiler will need to regenerate the packed asset data when there is a change. */
37+
function purgeCompiledAssetData(gameBuildDirectory){
38+
const compiledDataPath = path.join(gameBuildDirectory, "asm", "asset_data.s.obj");
39+
40+
if (fse.existsSync(compiledDataPath)) {
41+
console.log(`Purging compiled asset data file: ${compiledDataPath}`);
42+
fse.unlinkSync(compiledDataPath)
43+
}
44+
}
45+
46+
module.exports = preparePlatform;

scripts/RunPipeline.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* This is a generic script that external clients can use to run the asset pipeline.
2+
It is currently used by the data link asset service to convert assets on the fly.
3+
*/
4+
const Pipeline = require("../pipeline/Pipeline");
5+
6+
const { program } = require("commander");
7+
8+
const fse = require("fs-extra");
9+
10+
program
11+
.name("Prepare Assets")
12+
.version("1.0.0")
13+
.description("Prepare framework64 Assets");
14+
15+
program
16+
.argument("<platform>")
17+
.argument("<assetManifestFile>")
18+
.argument("<assetDirectory>")
19+
.argument("<outputDirectory>")
20+
.action(runPipeline);
21+
22+
program.parse();
23+
24+
async function runPipeline(platform, assetManifestFile, assetDirectory, outputDirectory) {
25+
if (!fse.existsSync(assetManifestFile)) {
26+
console.log(`manifest file: ${assetManifestFile} does not exist.`);
27+
process.exit(1);
28+
}
29+
30+
if (!fse.existsSync(assetDirectory)) {
31+
console.log(`Asset directory: ${assetDirectory} does not exist.`);
32+
process.exit(1);
33+
}
34+
35+
console.log("Running framework64 Asset Pipeline");
36+
console.log(` Platform: ${platform}`);
37+
console.log(` Manifest File: ${assetManifestFile}`);
38+
console.log(` Asset Directory: ${assetDirectory}`);
39+
console.log(` Output Directory: ${outputDirectory}`);
40+
41+
await Pipeline.prepareAssets(assetManifestFile, assetDirectory, platform, outputDirectory, null);
42+
}

tools/blender_plugin/framework64_plugin.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
bl_info = {
1111
"name": "framework64",
12-
"description": "Live in-engine preview",
12+
"description": "Plugin for creating games with framework64",
1313
"author": "Matthew LaRocca",
1414
"version": (0, 1),
1515
"blender": (2, 80, 0),
@@ -37,15 +37,11 @@ def send_static_mesh_to_console(self):
3737

3838
@staticmethod
3939
def webservice_data_transfer(asset_path, temp_dir):
40-
if sys.platform == "win32":
41-
endpoint_uri = "http://localhost:55660/static-mesh"
42-
else:
43-
endpoint_uri = "http://0.0.0.0:55660/static-mesh"
44-
40+
endpoint_uri = "http://127.0.0.1:62187"
4541
print("Transfer static mesh: {} --> {}".format(asset_path, endpoint_uri))
4642

4743
try:
48-
r = requests.post(endpoint_uri, data=json.dumps({"src": asset_path}))
44+
r = requests.post(endpoint_uri, data=json.dumps({"type":"mesh", "src": asset_path}))
4945
r.raise_for_status()
5046
except requests.exceptions.RequestException as e:
5147
print("Transfer failed: {}".format(e))

tools/data_link_asset_viewer/asset_viewer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ typedef struct {
99
fw64Engine* engine;
1010
fw64Font* font;
1111
fw64RenderPass* renderpass;
12-
fw64SpriteBatch* spritebatch;
1312
fw64AssetViewer asset_viewer;
1413
fw64FileDownloader file_downloader;
1514
} Game;

tools/data_link_client/example/example_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int argc, char** argv) {
2525
Settings settings;
2626

2727
auto* n64_command = app.add_subcommand("n64", "connect to n64 example");
28-
n64_command->add_option("ROM Path", settings.n64_rom_path, "Path to data_link rom that will be loaded on N64");
28+
n64_command->add_option("--rom", settings.n64_rom_path, "Path to data_link rom that will be loaded on N64");
2929
n64_command->callback([&settings](){ settings.platform = Platform::N64; });
3030

3131
auto* desktop_command = app.add_subcommand("desktop", "transfer assets to Desktop");

0 commit comments

Comments
 (0)