2021-04-05 11:55:36 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// 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"
|
2022-12-07 16:10:27 +00:00
|
|
|
#include "tiletexture.h"
|
2021-04-05 11:55:36 +00:00
|
|
|
#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)
|
|
|
|
{
|
2021-12-27 14:47:42 +00:00
|
|
|
if (vox)
|
|
|
|
{
|
|
|
|
delete vox->model;
|
|
|
|
delete vox;
|
|
|
|
}
|
2021-04-05 11:55:36 +00:00
|
|
|
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;
|
2022-09-30 14:25:21 +00:00
|
|
|
//vm->mdnum = 1; //VOXel model id
|
2021-04-05 11:55:36 +00:00
|
|
|
vm->scale = vm->bscale = 1.f;
|
2021-12-14 08:58:01 +00:00
|
|
|
vm->piv.X = float(pivot.X);
|
|
|
|
vm->piv.Y = float(pivot.Y);
|
|
|
|
vm->piv.Z = float(pivot.Z);
|
2021-12-22 09:36:09 +00:00
|
|
|
vm->siz.X = voxel->Mips[0].SizeX;
|
2021-12-22 09:40:26 +00:00
|
|
|
vm->siz.Y = voxel->Mips[0].SizeY;
|
2021-12-22 09:41:47 +00:00
|
|
|
vm->siz.Z = voxel->Mips[0].SizeZ;
|
2021-04-05 11:55:36 +00:00
|
|
|
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
|
2023-08-20 00:25:12 +00:00
|
|
|
Printf("Unable to load voxel from %s\n", fileSystem.GetFileFullPath(lumpnum).c_str());
|
2021-04-05 11:55:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto index = fileSystem.FindResource(i, "KVX");
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
voxmodels[i] = voxload(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|