mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 22:03:00 +05:30
Removed old versions of code
This commit is contained in:
parent
a7cee528f3
commit
c3a74a6dd5
85
test/main.c
85
test/main.c
@ -6,47 +6,6 @@
|
|||||||
#include "devil1pld.h"
|
#include "devil1pld.h"
|
||||||
#include "devil1tex.h"
|
#include "devil1tex.h"
|
||||||
|
|
||||||
bool writedata(const char *basename,
|
|
||||||
unsigned int id,
|
|
||||||
const char *data,
|
|
||||||
unsigned int dsize) {
|
|
||||||
bool status = false;
|
|
||||||
char *fn = (char*)malloc(sizeof(char) * strlen(basename) + 4);
|
|
||||||
sprintf(fn, "%s_%d", basename, id);
|
|
||||||
FILE *out = fopen(fn, "w");
|
|
||||||
if (out != NULL) {
|
|
||||||
fwrite(data, sizeof(char), dsize, out);
|
|
||||||
fclose(out);
|
|
||||||
status = true;
|
|
||||||
}
|
|
||||||
free(fn);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
void splitpld(const char *filedata,
|
|
||||||
unsigned int filesize,
|
|
||||||
const struct PldHeader *ph,
|
|
||||||
const char *name) {
|
|
||||||
char *wbuffer = NULL; // write buffer that will change.
|
|
||||||
unsigned int wsize = 0; // size of wbuffer.
|
|
||||||
unsigned int i;
|
|
||||||
unsigned int start = 0; // ending offset for data
|
|
||||||
unsigned int end = 0; // ending offset for data
|
|
||||||
for (i = 0; (i + 1) < (ph -> numOffset) + 1; i++) {
|
|
||||||
start = ph -> offsets[i];
|
|
||||||
// the last offset still has some data until the end of file
|
|
||||||
end = (i == (ph -> numOffset) - 1) ?
|
|
||||||
filesize : ph -> offsets[i + 1];
|
|
||||||
// copy sector to write buffer
|
|
||||||
wsize = end - start;
|
|
||||||
wbuffer = (char*)malloc(sizeof(char) * wsize);
|
|
||||||
memcpy(wbuffer, filedata + start, wsize);
|
|
||||||
// create a file.
|
|
||||||
writedata(name, i, wbuffer, wsize);
|
|
||||||
free(wbuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *loadfile(const char *fname, unsigned int *s) {
|
char *loadfile(const char *fname, unsigned int *s) {
|
||||||
FILE *f = fopen(fname, "rb");
|
FILE *f = fopen(fname, "rb");
|
||||||
unsigned int size = 0; // number of elements to buffer;
|
unsigned int size = 0; // number of elements to buffer;
|
||||||
@ -76,19 +35,22 @@ char *loadfile(const char *fname, unsigned int *s) {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bool unpackpld (const char *filedata,
|
void write(const char *filename,
|
||||||
unsigned int filesize,
|
const char* t,
|
||||||
const char *filename) {
|
unsigned int size) {
|
||||||
bool status = false;
|
if (filename == NULL) {
|
||||||
printf("fsize is %i\n", filesize);
|
return;
|
||||||
if (filedata != NULL && filesize != 0) {
|
|
||||||
struct PldHeader *pldh = getpldh(filedata);
|
|
||||||
splitpld(filedata, filesize, pldh, filename);
|
|
||||||
destroypldh(pldh);
|
|
||||||
status = true;
|
|
||||||
}
|
}
|
||||||
return status;
|
unsigned int written = 0;
|
||||||
} */
|
FILE *out = fopen(filename, "wb");
|
||||||
|
if (out != NULL) {
|
||||||
|
written = fwrite(t, sizeof(unsigned char), size, out);
|
||||||
|
fclose(out);
|
||||||
|
if (written == 0) {
|
||||||
|
perror("texture write error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool unpackpld(const char *filedata,
|
bool unpackpld(const char *filedata,
|
||||||
unsigned int filesize,
|
unsigned int filesize,
|
||||||
@ -111,23 +73,6 @@ bool unpackpld(const char *filedata,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const char *filename,
|
|
||||||
const char* t,
|
|
||||||
unsigned int size) {
|
|
||||||
if (filename == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unsigned int written = 0;
|
|
||||||
FILE *out = fopen(filename, "wb");
|
|
||||||
if (out != NULL) {
|
|
||||||
written = fwrite(t, sizeof(unsigned char), size, out);
|
|
||||||
fclose(out);
|
|
||||||
if (written == 0) {
|
|
||||||
perror("texture write error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void exporttextures(const char *filedata,
|
void exporttextures(const char *filedata,
|
||||||
unsigned int filesize,
|
unsigned int filesize,
|
||||||
const char *filename) {
|
const char *filename) {
|
||||||
|
Loading…
Reference in New Issue
Block a user