update docs, new_WAD

This commit is contained in:
Evan Burkey 2024-03-13 10:32:27 -07:00
parent 4d13ac6a73
commit 6f8346c3fc
3 changed files with 26 additions and 8 deletions

View File

@ -1,5 +1,14 @@
# spitWAD
# spitwad
`spitWAD` is a simple DOOM WAD management library
Originally conceived as a joke between some friends after we laughed about how it would be better to use WADs to send data
between applications then JSON, because JSON is stupid and wasteful. `spitwad` is a library for interacting with WAD
files, popularized by ID games like DOOM and Quake. You can use it in your DOOM clone, or to package your data and
send it over a network as a WAD. Why? Why not!
`DOOM1.WAD` contained in this repo is the shareware version of DOOM and is used for tests
## Requirements
Should work on any POSIX platform out of the box
## Usage
Docs are a work in progress!

View File

@ -22,9 +22,9 @@ static char* getstring(const unsigned char* data, size_t offset) {
return s;
}
int new_WAD(struct WAD* wad, const unsigned char* data, size_t data_sz) {
int new_WAD_from_data(struct WAD* wad, const unsigned char* data, size_t data_sz) {
if (wad == NULL) {
return fail("Supplied wad to new_WAD was NULL");
return fail("Supplied wad to new_WAD_from_data was NULL");
}
wad->data = malloc(sizeof(unsigned char) * data_sz);
@ -98,18 +98,25 @@ int new_WAD_from_file(struct WAD* wad, const char* path) {
fread(buf, 1, fsz, fp);
fclose(fp);
new_WAD(wad, buf, fsz);
new_WAD_from_data(wad, buf, fsz);
free(buf);
return 0;
}
int new_WAD(struct WAD* wad) {
wad->data = NULL;
wad->data_sz = 0;
wad->directory = NULL;
wad->dir_sz = 0;
wad->dir_offset = 0;
}
void destroy_WAD(struct WAD* wad) {
free(wad->data);
free(wad->directory);
free(wad);
}
int write_to_file(struct WAD* wad, const char* path) {
FILE *fp = NULL;
fp = fopen(path, "wb");

View File

@ -24,9 +24,11 @@ struct WAD {
struct DirEntry *directory;
};
int new_WAD(struct WAD* wad, const unsigned char* data, size_t data_sz);
int new_WAD_from_data(struct WAD* wad, const unsigned char* data, size_t data_sz);
int new_WAD_from_file(struct WAD* wad, const char* path);
int new_WAD(struct WAD* wad);
void destroy_WAD(struct WAD* wad);
int write_to_file(struct WAD* wad, const char* path);
#endif //SPITWAD_H