room101/WORLD.CPP

54 lines
1.6 KiB
C++

#include "world.hpp"
#include "lightmap.hpp"
/*******************************************************************************
** WorldRead
*******************************************************************************/
void
WorldRead(World* world, Picture* textures, int depths[], FILE* file)
{
int total = 0;
memset(world, 0, sizeof(World));
printf("Reading BSPs\n");
world->bsp = BSPRead(file);
printf("Reading surfaces\n");
world->surfaces = (Surface*) MemoryRead(file);
printf("Reading lightmaps\n");
world->lightmaps = PictureArrayRead(file);
printf("Reading lights\n");
world->lights = (Light*) MemoryRead(file);
world->textures = PictureArrayCreate(NumberOf(world->lightmaps));
printf("Expanding textures\n");
MatrixIdentity(world->matrix);
for (int i = 0; i < NumberOf(world->lightmaps); i++)
{
Surface* surface = &world->surfaces[i];
int colour = Clamp(surface->colour, 0, NumberOf(textures) - 1);
if (depths[colour] == 0)
{
world->textures[i] = textures[colour];
}
else
{
LightMapExpand(&world->textures[i],
&world->lightmaps[i],
&textures[colour],
depths[colour],
surface->lo[0],
surface->lo[1]);
total += (world->textures[i].width * world->textures[i].height * sizeof(Pixel));
}
}
fprintf(stderr, "Total surface memory: %.2lfMeg\n", total / 1048576.0);
}