mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-22 20:21:20 +00:00
8a789b9015
Moving the voxel index into the texExtInfo array and removing most of Blood's and SW's special handling.
117 lines
2.7 KiB
C++
117 lines
2.7 KiB
C++
//
|
|
//---------------------------------------------------------------------------
|
|
//
|
|
// Copyright(C) 2021 Christoph Oelckers
|
|
// All rights reserved.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
//
|
|
//--------------------------------------------------------------------------
|
|
//
|
|
/*
|
|
** hw_voxels.cpp
|
|
**
|
|
** voxel handling.
|
|
**
|
|
**/
|
|
|
|
#include "build.h"
|
|
#include "voxels.h"
|
|
#include "hw_voxels.h"
|
|
#include "tiletexture.h"
|
|
#include "gamecontrol.h"
|
|
|
|
static int voxlumps[MAXVOXELS];
|
|
float voxscale[MAXVOXELS];
|
|
voxmodel_t* voxmodels[MAXVOXELS];
|
|
FixedBitArray<MAXVOXELS> voxrotate;
|
|
|
|
|
|
void voxInit()
|
|
{
|
|
for (auto& v : voxscale) v = 1.f;
|
|
voxrotate.Zero();
|
|
}
|
|
|
|
void voxClear()
|
|
{
|
|
for (auto& vox : voxmodels)
|
|
{
|
|
if (vox)
|
|
{
|
|
delete vox->model;
|
|
delete vox;
|
|
}
|
|
vox = nullptr;
|
|
}
|
|
}
|
|
|
|
int voxDefine(int voxindex, const char* filename)
|
|
{
|
|
if ((unsigned)voxindex >= MAXVOXELS)
|
|
return -1;
|
|
|
|
int i = fileSystem.FindFile(filename);
|
|
voxlumps[voxindex] = i;
|
|
return i < 0 ? -1 : 0;
|
|
}
|
|
|
|
static voxmodel_t* voxload(int lumpnum)
|
|
{
|
|
FVoxel* voxel = R_LoadKVX(lumpnum);
|
|
if (voxel != nullptr)
|
|
{
|
|
voxmodel_t* vm = new voxmodel_t;
|
|
*vm = {};
|
|
auto pivot = voxel->Mips[0].Pivot;
|
|
//vm->mdnum = 1; //VOXel model id
|
|
vm->scale = vm->bscale = 1.f;
|
|
vm->piv.X = float(pivot.X);
|
|
vm->piv.Y = float(pivot.Y);
|
|
vm->piv.Z = float(pivot.Z);
|
|
vm->siz.X = voxel->Mips[0].SizeX;
|
|
vm->siz.Y = voxel->Mips[0].SizeY;
|
|
vm->siz.Z = voxel->Mips[0].SizeZ;
|
|
vm->is8bit = true;
|
|
voxel->Mips[0].Pivot.Zero(); // Needs to be taken out of the voxel data because it gets baked into the vertex buffer which we cannot use here.
|
|
vm->model = new FVoxelModel(voxel, true);
|
|
return vm;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void LoadVoxelModels()
|
|
{
|
|
for (int i = 0; i < MAXVOXELS; i++)
|
|
{
|
|
int lumpnum = voxlumps[i];
|
|
if (lumpnum > 0)
|
|
{
|
|
voxmodels[i] = voxload(lumpnum);
|
|
if (voxmodels[i])
|
|
voxmodels[i]->scale = voxscale[i];
|
|
else
|
|
Printf("Unable to load voxel from %s\n", fileSystem.GetFileFullPath(lumpnum).GetChars());
|
|
}
|
|
else
|
|
{
|
|
auto index = fileSystem.FindResource(i, "KVX");
|
|
if (index >= 0)
|
|
{
|
|
voxmodels[i] = voxload(index);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|