Use cached music data if mod file hasn't been modified since last build
@@ -9,6 +9,8 @@ const filterLogs = (str) => {
return str.replace(/.*[/|\\]([^/|\\]*.mod)/g, "$1");
};
+const trackBuildCache = {};
+
const compileMusic = async ({
music = [],
musicBanks = [],
@@ -32,6 +34,12 @@ const compileMusic = async ({
for (let i = 0; i < music.length; i++) {
const track = music[i];
+ const trackModifiedTime = await getTrackModifiedTime(track, { projectRoot });
+
+ let musicData;
+ if(trackBuildCache[track.id] && trackBuildCache[track.id].timestamp >= trackModifiedTime) {
+ musicData = trackBuildCache[track.id].data;
+ } else {
// Compile track using mod2gbt
await compileTrack(track, {
buildRoot,
@@ -42,20 +50,25 @@ const compileMusic = async ({
});
// Read track's compiled C data
- const musicTrackTemp = await fs.readFile(
+ let musicTrackTemp = await fs.readFile(
`${buildRoot}/src/music/${track.dataName}.c`,
"utf8"
);
// Parse C data into raw pattern and order data
- const musicData = {
+ musicData = {
name: track.dataName,
...parseMusicFile(musicTrackTemp),
};
+ trackBuildCache[track.id] = {
+ data: musicData,
+ timestamp: trackModifiedTime
+ }
+
// Delete mod2gbt compile track, no longer needed
await fs.unlink(`${buildRoot}/src/music/${track.dataName}.c`);
-
+ }
progress(`${track.dataName} approx size in bytes: ${musicData.size}`);
@@ -102,7 +115,7 @@ const compileMusic = async ({
const track = musicBank.tracks[t];
// Calculate memory offsets in bank for each pattern
- const trackPatternOffsets = [];
+ let trackPatternOffsets = [];
for (let p = 0; p < track.patterns.length; p++) {
trackPatternOffsets[p] = maxOffset;
maxOffset += track.patterns[p].length;
@@ -137,6 +150,7 @@ const compileMusic = async ({
fileData,
"utf8"
);
+
}
// Modify data_ptrs for new music banks
@@ -206,6 +220,13 @@ const parseMusicFile = (string) => {
};
};
+const getTrackModifiedTime = async (track, {
+ projectRoot,
+}) => {
+ const modPath = assetFilename(projectRoot, "music", track, true);
+ return (await fs.stat(modPath)).mtimeMs;
+}
+
const compileTrack = async (
track,
{
