From 2a42fa475f34cfd7a1f5413121c629304a18e461 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Fri, 24 Jan 2025 01:55:37 -0800 Subject: [PATCH] small tweaks --- Makefile | 16 +++-- Tools/Source/cmdlib.c | 8 +-- Tools/Source/wav2loop.c | 128 ++++++++++++++++++++++++++++++++++++++++ Tools/build_models.sh | 2 +- Tools/make_launcher.sh | 4 +- src/system/classes.qc | 2 +- src/system/ncActor.qc | 6 +- src/system/ncActor.qh | 6 +- src/system/ncCamera.qc | 6 +- 9 files changed, 156 insertions(+), 22 deletions(-) create mode 100644 Tools/Source/wav2loop.c diff --git a/Makefile b/Makefile index 144f51c..c4b9e91 100644 --- a/Makefile +++ b/Makefile @@ -80,19 +80,22 @@ gfx: imgtool palette # various palette utilities needed tga2pal: - gcc -o tga2pal Tools/Source/tga2pal.c + $(CC) -o tga2pal Tools/Source/tga2pal.c + +wav2loop: + $(CC) -o wav2loop Tools/Source/wav2loop.c tga2lmp: - gcc -o tga2lmp Tools/Source/tga2lmp.c + $(CC) -o tga2lmp Tools/Source/tga2lmp.c pal2pal: - gcc -o pal2pal Tools/Source/pal2pal.c + $(CC) -o pal2pal Tools/Source/pal2pal.c pal2colormap: - gcc -o pal2colormap Tools/Source/pal2colormap.c + $(CC) -o pal2colormap Tools/Source/pal2colormap.c qfiles: - gcc -o qfiles Tools/Source/qfiles.c Tools/Source/cmdlib.c + $(CC) -o qfiles Tools/Source/qfiles.c Tools/Source/cmdlib.c palette: pal2colormap pal2pal tga2pal if [ ! -d $(GAME)/gfx ];then mkdir $(GAME)/gfx; fi @@ -142,6 +145,9 @@ radiant: update cd ThirdParty/gtkradiant && scons Tools/make_launcher.sh ./ThirdParty/gtkradiant/install/ ./radiant.bin radiant +launcher: + Tools/make_launcher.sh "./" "./fteqw -readonly -basedir ./ -netquake -game $(GAME) +exec $(USER).cfg" $(GAME).sh + radiant-game: radiant edef echo "" > "$(RADIANT_GAME)" echo "> "$(RADIANT_GAME)" diff --git a/Tools/Source/cmdlib.c b/Tools/Source/cmdlib.c index 0dc9242..e03dac3 100644 --- a/Tools/Source/cmdlib.c +++ b/Tools/Source/cmdlib.c @@ -77,11 +77,11 @@ void SetQdirFromPath (char *path) // search for "quake" in path for (c=path ; *c ; c++) - if (!Q_strncasecmp (c, "Nuclide-Lite", 12)) + if (!Q_strncasecmp (c, "NuclideLite", 11)) { - strncpy (qdir, path, c+13-path); + strncpy (qdir, path, c+12-path); printf ("qdir: %s\n", qdir); - c += 13; + c += 12; while (*c) { if (*c == '/' || *c == '\\') @@ -95,7 +95,7 @@ void SetQdirFromPath (char *path) Error ("No gamedir in %s", path); return; } - Error ("SeetQdirFromPath: no 'Nuclide' in %s", path); + Error ("SeetQdirFromPath: no 'NuclideLite' in %s", path); } char *ExpandPath (char *path) diff --git a/Tools/Source/wav2loop.c b/Tools/Source/wav2loop.c new file mode 100644 index 0000000..f716d2b --- /dev/null +++ b/Tools/Source/wav2loop.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include + +/* so it's easier to fwrite */ +typedef struct +{ + char cuehead[4]; + int chunk_size; + int numcues; + int cueid; + int cuepos; + + char datahead[4]; + int chunk_start; + int block_start; + int sample_offset; +} loop_t; + +/* -o enables users to specify at which point in the sample to start */ +static int sample_offset; + +void process_wav2loop(char *filename) +{ + FILE *fWAV; + FILE *fLOOP; + size_t szWAV; + char *buffer; + loop_t loopy; + + fWAV = fopen(filename, "rb"); + + if (!fWAV) { + fprintf(stderr, "couldn't find %s\n", filename); + return; + } + + /* get wav file size */ + fseek(fWAV, 0L, SEEK_END); + szWAV = (size_t)ftell(fWAV); + fseek(fWAV, 0L, SEEK_SET); + + /* load wav into memory */ + buffer = (char *)malloc(szWAV); + + if (buffer == NULL) { + fprintf(stderr, "error: Memory allocation failed. Exiting.\n"); + exit(0); + } + + fread(buffer, 1, szWAV, fWAV); + fclose(fWAV); + + /* this is LAZY, however we're not going to bother writing a full WAV loader LMAO */ + for (int i = 0; i < (szWAV - 4); i++ ) { + if (buffer[i] == 'c') + if (buffer[i+1] == 'u') + if (buffer[i+2] == 'e') + if (buffer[i+3] == ' ') { + fprintf(stderr, "wav file %s has cue info already\n", filename); + goto end; + } + } + + /* this is quite stupid, we're just appending it at the end, + we don't even care if there already are other cue marks */ + fLOOP = fopen(filename, "w+b"); + fwrite(buffer, 1, szWAV, fLOOP); + + loopy.cuehead[0] = 'c'; + loopy.cuehead[1] = 'u'; + loopy.cuehead[2] = 'e'; + loopy.cuehead[3] = ' '; + loopy.chunk_size = 28; + loopy.numcues = 1; + loopy.cueid = 0; + loopy.cuepos = 0; + loopy.datahead[0] = 'd'; + loopy.datahead[1] = 'a'; + loopy.datahead[2] = 't'; + loopy.datahead[3] = 'a'; + loopy.chunk_start = 0; + loopy.block_start = 0; + loopy.sample_offset = sample_offset; + + /* append our data to the end of the file */ + fwrite(&loopy, 1, sizeof(loop_t), fLOOP); + fclose(fLOOP); + + /* inb4 goto considered harmful */ +end: + free(buffer); +} + +int main(int argc, char *argv[]) +{ + int c, ch; + + if (argc <= 1) { + fprintf(stderr, "usage: wav2loop [-o offset] file.wav ...\n"); + return 1; + } + + /* by default, we loop at the very start */ + sample_offset = 0; + + /* process arguments: TODO: add more? probably not */ + while ((ch = getopt(argc, argv, "o")) != -1) { + switch (ch) { + case 'o': + sample_offset = atoi(argv[optind]); + optind++; + printf("sample offset: %i\n", sample_offset); + break; + default: + return 1; + } + } + argc -= optind; + argv += optind; + + for (c = 0; c < argc; c++) + process_wav2loop(argv[c]); + + return 0; +} diff --git a/Tools/build_models.sh b/Tools/build_models.sh index c881d92..314ee5f 100755 --- a/Tools/build_models.sh +++ b/Tools/build_models.sh @@ -14,7 +14,7 @@ build_models() do DIR=$(dirname "$LINE") cd "$DIR" - iqmtool $(basename "$LINE") + "$CWD/iqmtool" $(basename "$LINE") done } diff --git a/Tools/make_launcher.sh b/Tools/make_launcher.sh index a3968dd..4c6a7b5 100755 --- a/Tools/make_launcher.sh +++ b/Tools/make_launcher.sh @@ -10,5 +10,5 @@ DIR="$1" COMMAND="$2" DEST="$3" -printf "#/bin/sh\ncd \"$DIR\"\n$COMMAND\n" > "$DEST" -chmod +x "$DEST" \ No newline at end of file +printf "#/bin/sh\ncd \"$DIR\"\n$COMMAND \$*\n" > "$DEST" +chmod +x "$DEST" diff --git a/src/system/classes.qc b/src/system/classes.qc index 4545556..ae93715 100644 --- a/src/system/classes.qc +++ b/src/system/classes.qc @@ -3,7 +3,7 @@ __weak void Class_Player(void) { } __weak void Class_Actor(void) { - spawnfunc_nsActor(); + spawnfunc_ncActor(); } __weak void Class_Rules(void) { diff --git a/src/system/ncActor.qc b/src/system/ncActor.qc index 7dfff3a..87de691 100644 --- a/src/system/ncActor.qc +++ b/src/system/ncActor.qc @@ -1,10 +1,10 @@ -void nsActor::nsActor ( void ) { +void ncActor::ncActor ( void ) { } -void nsActor::_InternalPostSpawn ( void ) { +void ncActor::_InternalPostSpawn ( void ) { /* monsters are auto-aim by default */ SetTakedamage( DAMAGE_AIM ); SetSolid( SOLID_SLIDEBOX ); SetMovetype( MOVETYPE_STEP ); -} \ No newline at end of file +} diff --git a/src/system/ncActor.qh b/src/system/ncActor.qh index c99ce5e..6b5ca54 100644 --- a/src/system/ncActor.qh +++ b/src/system/ncActor.qh @@ -1,5 +1,5 @@ -class nsActor : ncEntity { - void nsActor( void ); +class ncActor : ncEntity { + void ncActor( void ); virtual void _InternalPostSpawn( void ); -}; \ No newline at end of file +}; diff --git a/src/system/ncCamera.qc b/src/system/ncCamera.qc index 64325c1..d07efcb 100644 --- a/src/system/ncCamera.qc +++ b/src/system/ncCamera.qc @@ -124,7 +124,7 @@ vector ncCamera::GetCameraAngles( void ) { newAngle = ncMath::VecToAngles(newAngle); -#if 1 +#if 0 newAngle[0] = ncMath::Rint(newAngle[0]); newAngle[1] = ncMath::Rint(newAngle[1]); newAngle[2] = ncMath::Rint(newAngle[2]); @@ -189,7 +189,7 @@ vector ncCamera::GetCameraOrigin( void ) { break; } -#if 1 +#if 0 newOrigin[0] = ncMath::Rint(newOrigin[0]); newOrigin[1] = ncMath::Rint(newOrigin[1]); newOrigin[2] = ncMath::Rint(newOrigin[2]); @@ -217,4 +217,4 @@ ncCamera ncCamera::GetLastCamera( void ) { ncCamera ncCamera::GetVeryNextCamera( void ) { ncCamera nextCamera = GetNextCamera(); return ncEngine::Find( (ncEntity) world, ::targetname, nextCamera.next); -} \ No newline at end of file +}