Skip to content

Commit 351e307

Browse files
committed
Simplified mkpak phase
1 parent 5827e9e commit 351e307

6 files changed

Lines changed: 58 additions & 21 deletions

File tree

Misc/vq_pak/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
HOST_CC = gcc
2-
INPUT := $(shell cat vq_pak_contents.txt)
2+
INPUT := vq_pak_contents.txt
33
OUTPUT_NAME := vkquake.pak
44
OUTPUT := ../../Quake/$(OUTPUT_NAME)
55
OUTPUT_EMBEDDED := ../../Quake/embedded_pak.c

Misc/vq_pak/mkpak.c

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2020
#include <stdint.h>
2121
#include <string.h>
2222
#include <stdlib.h>
23+
#include <ctype.h>
2324

2425
static FILE *out;
2526

@@ -57,10 +58,11 @@ static void write_header (int32_t directory_offset, int32_t directory_size)
5758

5859
int main (int argc, char *argv[])
5960
{
61+
FILE *toc_file = NULL;
6062

6163
if (argc < 4)
6264
{
63-
fprintf (stderr, "Usage: mkpak [output.pak] [root dir for files] [files...]\n");
65+
fprintf (stderr, "Usage: mkpak [output.pak] [root dir for files] [toc file]\n");
6466
return 1;
6567
}
6668

@@ -70,9 +72,28 @@ int main (int argc, char *argv[])
7072
fprintf (stderr, "Could not open output file '%s'", argv[1]);
7173
return 1;
7274
}
75+
// read as text file
76+
toc_file = fopen (argv[3], "r");
77+
if (toc_file == NULL)
78+
{
79+
fprintf (stderr, "Could not open toc_file file '%s'", argv[3]);
80+
return 1;
81+
}
82+
83+
char entry_path[1024] = {0};
84+
85+
int32_t num_in_files = 0;
86+
87+
// count the number of lines = num_in_files
88+
while (fgets (entry_path, sizeof (entry_path), toc_file))
89+
{
90+
num_in_files++;
91+
}
92+
// rewind
93+
rewind (toc_file);
7394

7495
int32_t directory_offset = 12;
75-
int32_t num_in_files = argc - 3;
96+
7697
int32_t directory_size = num_in_files * sizeof (dpackfile_t);
7798
int32_t file_offset = directory_offset + directory_size;
7899

@@ -83,13 +104,30 @@ int main (int argc, char *argv[])
83104

84105
char input_file_path[1024] = {0};
85106

86-
for (int i = 3; i < argc; ++i)
107+
int file_index = -1;
108+
// read each line
109+
while (fgets (entry_path, sizeof (entry_path), toc_file))
87110
{
88-
int file_index = i - 3;
111+
// trim leading and trailing whaitespaces:
112+
char *entry_path_start = entry_path;
113+
114+
while (isspace ((unsigned char)*entry_path_start))
115+
entry_path_start++;
116+
117+
for (int char_index = 0; char_index < strlen (entry_path_start); char_index++)
118+
{
119+
if (isspace (entry_path_start[char_index]))
120+
{
121+
entry_path_start[char_index] = '\0';
122+
break;
123+
}
124+
}
125+
126+
file_index++;
89127
// prepend the root dir
90-
snprintf (input_file_path, sizeof (input_file_path), "%s/%s", argv[2], argv[i]);
128+
snprintf (input_file_path, sizeof (input_file_path), "%s/%s", argv[2], entry_path_start);
91129

92-
// printf (" argv[%d]=%s\n", i, input_file_path);
130+
// printf (" pak entry = %s, filename = %s\n", entry_path_start, input_file_path);
93131

94132
in = fopen (input_file_path, "rb");
95133

@@ -107,7 +145,7 @@ int main (int argc, char *argv[])
107145

108146
dpackfile_t pack_entry;
109147
memset (&pack_entry, 0, sizeof (pack_entry));
110-
strncpy (pack_entry.name, argv[i], sizeof (pack_entry.name) - 1);
148+
strncpy (pack_entry.name, entry_path_start, sizeof (pack_entry.name) - 1);
111149
pack_entry.filelen = (int)in_size;
112150
pack_entry.filepos = file_offset;
113151

@@ -119,7 +157,11 @@ int main (int argc, char *argv[])
119157

120158
file_offset += (int32_t)in_size;
121159
fclose (in);
122-
}
160+
161+
} // end while
162+
163+
fclose (out);
164+
fclose (toc_file);
123165
free (in_buffer);
124166

125167
return 0;

Misc/vq_pak/run_mkpak.ps1

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

Windows/VisualStudio/mkpak.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</Link>
6868
<PostBuildEvent>
6969
<Message>Building vkquake.pak</Message>
70-
<Command>powershell -ExecutionPolicy Bypass -File $(ProjectDir)\..\..\Misc\vq_pak\run_mkpak.ps1 $(ProjectDir) $(OutDir)</Command>
70+
<Command>$(OutDir)mkpak.exe $(ProjectDir)\..\..\Quake\vkquake.pak $(ProjectDir)\..\..\Misc\vq_pak $(ProjectDir)\..\..\Misc\vq_pak\vq_pak_contents.txt</Command>
7171
</PostBuildEvent>
7272
</ItemDefinitionGroup>
7373
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -87,7 +87,7 @@
8787
<GenerateDebugInformation>true</GenerateDebugInformation>
8888
</Link>
8989
<PostBuildEvent>
90-
<Command>powershell -ExecutionPolicy Bypass -File $(ProjectDir)\..\..\Misc\vq_pak\run_mkpak.ps1 $(ProjectDir) $(OutDir)</Command>
90+
<Command>$(OutDir)mkpak.exe $(ProjectDir)\..\..\Quake\vkquake.pak $(ProjectDir)\..\..\Misc\vq_pak $(ProjectDir)\..\..\Misc\vq_pak\vq_pak_contents.txt</Command>
9191
</PostBuildEvent>
9292
<PostBuildEvent>
9393
<Message>Building vkquake.pak</Message>

Windows/VisualStudio/mkpak.vcxproj.user

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
44
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
5+
<LocalDebuggerCommandArguments>D:\Projets\GIT_Repositories\vkQuake-vso\Windows\VisualStudio\\..\..\Quake\vkquake.pak D:\Projets\GIT_Repositories\vkQuake-vso\Windows\VisualStudio\\..\..\Misc\vq_pak D:\Projets\GIT_Repositories\vkQuake-vso\Windows\VisualStudio\\..\..\Misc\vq_pak\vq_pak_contents.txt</LocalDebuggerCommandArguments>
6+
<LocalDebuggerWorkingDirectory>.\Build-mkpak\x64\Debug</LocalDebuggerWorkingDirectory>
57
</PropertyGroup>
68
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
79
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>

meson.build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ endif
6868

6969
bintoc_command = [bintoc, '@PLAINNAME@.spv', '@PLAINNAME@_spv', '@OUTPUT@']
7070

71-
mkpak_file_list = run_command('cat', 'Misc/vq_pak/vq_pak_contents.txt').stdout().strip().split('\n')
7271
vkquake_pak_path = join_paths(meson.project_source_root(), 'Quake', 'vkquake.pak')
72+
7373
vq_pak_path = join_paths(meson.project_source_root(), 'Misc', 'vq_pak')
74+
mkpak_toc_file = join_paths(vq_pak_path, 'vq_pak_contents.txt')
7475

75-
mkpak_command = [mkpak, vkquake_pak_path, vq_pak_path, mkpak_file_list]
76+
mkpak_command = [mkpak, vkquake_pak_path, vq_pak_path, mkpak_toc_file]
7677

7778
run_mkpak = custom_target('run-mkpak',
7879
output : 'vkquake.pak',

0 commit comments

Comments
 (0)