Files
TeslaRel410/sda4/DPL3/DPL_LOAD.C
T
CydandClaude Fable 5 db7745fcd0 sda4: commit the Glaze developer hard-drive dump
Un-ignored: the dev drive is the ground truth the restoration and
emulator work constantly reference (DPL3/LIBDPL + VRENDER i860 renderer
source, BT/RP live+dev game trees, VGL_LABS pod boot, scene/audio
content). Kept in-repo for the pod-owner community.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 19:41:15 -05:00

260 lines
6.5 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <dpl.h>
#include <dpl_host.h>
/*{{{ banner*/
/* **************************************************
Copyright DIVISION Limited (c) 1994
All rights reserved
File : dpl_load.c
Project : dpl interface object loading support
host / platform independent section
Author : PJA
Date : 22/06/94
Function: Implements the host section of the dpl
b2z object loader
History : Rev 1.1, 22 / 06 / 1994
**************************** */
/*}}} */
/*{{{ load_b2z ( char *full_name )*/
int32
load_b2z ( dpl_node *head_node, char *full_name )
{
extern dpl_OBJECT *
b2zread ( dpl_OBJECT *param_object, char *f );
return (b2zread ((dpl_OBJECT *) head_node, full_name ) != NULL);
}
/*}}} */
/*{{{ load_svt ( char *full_name )*/
static char *worst_case_texels=NULL;
int32
load_svt ( dpl_node *head_node, char *full_name )
{
#if 0
/*{{{ static int parse_texture ( int32 length )*/
static int parse_texture ( int32 length )
{
/*
always create a new texture, but try to chain it to an
existing texmap
*/
dpl_TEXTURE *real_tex;
int32 bilinear, bytes=0, hdr, len;
int8 scope=0, minify=0, magnify=0, wrap_u=0, wrap_v=0, alpha=0, mode;
char c, *name_p=texture_name;
*name_p=0x0;
while (b2z_ok && (bytes < length)) {
bytes+=b2z_block(&hdr, &len );
if (b2z_ok == 0) return 0;
switch ( hdr ) {
/*{{{ name*/
case 0x2008 :
trprintf ( "TEXTURE NAME\n" );
name_p=texture_name;
while (c=get_char())
*name_p++=c;
trprintf ("texture %s\n", texture_name );
break;
/*}}} */
/*{{{ scope*/
case 0x200a :
trprintf ( "SCOPE\n" );
scope=get_int8();
trprintf ( "SCOPE = 0x%x\n", scope );
break;
/*}}} */
/*{{{ file name*/
case 0x0011 :
case 0x4011 :
case 0x8011 :
trprintf ( "TEXTURE FILE NAME\n" );
name_p=texmap_name;
while (c=get_char())
*name_p++=c;
trprintf ("map name %s\n", texmap_name );
break;
/*}}} */
/*{{{ minify*/
case 0x0012 :
trprintf ( "MINIFY\n" );
minify=get_int8();
trprintf ( "MODE = 0x%x\n", mode );
break;
/*}}} */
/*{{{ magnify*/
case 0x0013 :
trprintf ( "MAGNIFY\n" );
magnify=get_int8();
trprintf ( "MODE = 0x%x\n", mode );
break;
/*}}} */
/*{{{ alpha*/
case 0x0014 :
trprintf ( "ALPHA\n" );
alpha=get_int8();
trprintf ( "MODE = 0x%x\n", mode );
break;
/*}}} */
/*{{{ wrap u*/
case 0x0015 :
trprintf ( "WRAP_U\n" );
wrap_u=get_int8();
trprintf ( "MODE = 0x%x\n", mode );
break;
/*}}} */
/*{{{ wrap v*/
case 0x0016 :
trprintf ( "WRAP_V\n" );
wrap_v=get_int8();
trprintf ( "MODE = 0x%x\n", mode );
break;
/*}}} */
/*{{{ detail*/
case 0x0017 :
trprintf ( "DETAIL\n" );
mode=get_int8();
trprintf ( "MODE = 0x%x\n", mode );
skip_block(len-1);
break;
/*}}} */
default :
printf ( "Unexpected header 0x%x in texture, bytes=%d length=%d\n",
hdr, bytes, length );
skip_block(len);
break;
}
bytes+=len;
}
texmap = (dpl_TEXMAP *) dpl_FindNamedTypedNode ( dpl_type_texmap,
texmap_name );
if (texmap == NULL) {
/*{{{ load up the texture map*/
/* first try to load the texture */
if ((magnify == 1) || (magnify == 0))
bilinear=0;
else
bilinear=1;
texmap = dpl_NewTexMap ();
dpl_NameNode ( (dpl_node *) texmap, texmap_name );
texmap->bits_per_texel=32; /* sorry about this hack */
if (load_svt((dpl_node *) texmap, texmap_name)) {
int *map_texels=texmap->texels;
/* this is HORRIBLE - i will fix it later....... */
texmap->texels=NULL;
trprintf ("went load_svt, have u_size %d v_size %d\n",
texmap->u_size, texmap->v_size );
dpl_SetTexmapTexels ( texmap,
map_texels,
texmap->u_size,
texmap->v_size,
bilinear );
/* and the call to SetTexMapTexels has flushed the node */
/* HACK TO SAVE MEMORY */
free(texmap->texels);
texmap->texels=NULL;
}
/*}}} */
}
real_tex = (dpl_TEXTURE *) look_up ( dpl_type_texture,
texture_name,
(node_create_function) dpl_NewTexture );
real_tex->minify = minify;
real_tex->magnify = magnify;
real_tex->alpha = alpha;
real_tex->wrap_u = wrap_u;
real_tex->wrap_v = wrap_v;
real_tex->texmap = texmap;
dpl_Flush(real_tex);
return 1;
}
/*}}} */
#endif
dpl_TEXMAP *map=(dpl_TEXMAP *) head_node;
FILE *fp=fopen(full_name, "rb" );
long l_edge, texels;
int32 edge;
if (fp==NULL) {
printf ("failed to open file %s\n", full_name );
return 0;
}
else {
fseek ( fp, 0L, SEEK_END );
l_edge=ftell(fp);
fseek ( fp, 0L, SEEK_SET );
edge=128;
if (l_edge == 16384L) edge=64;
else if (l_edge == 65536L) edge=128;
else if (l_edge == 262144L) edge=256;
else {
printf("Bad texture file size 0x%lx\n",l_edge);
fclose(fp);
return 0;
}
}
texels=l_edge;
if (worst_case_texels == NULL) {
worst_case_texels=malloc(256*256*sizeof(int));
}
map->texels=worst_case_texels;
if (map->texels) {
char *texelp=(char *) map->texels;
while (texels) {
int i;
fread ( texelp, 1, 8192, fp );
texels-=8192;
texelp+=8192;
}
fclose(fp);
map->u_size=edge;
map->v_size=edge;
return 1;
}
else {
printf ("Failed to malloc space for texels in map %s\n", full_name );
fclose (fp);
return 0;
}
}
/*}}} */