1
0
forked from 0ad/0ad

Fixed some assumptions PATCH_SIZE is 16.

This was SVN commit r415.
This commit is contained in:
notpete 2004-06-07 19:59:20 +00:00
parent 71d74e9121
commit 97b7efab20
5 changed files with 31 additions and 30 deletions

View File

@ -8,8 +8,9 @@
#include "precompiled.h"
#include "MiniPatch.h"
#include "Patch.h"
#include "MiniPatch.h"
#include "Terrain.h"
///////////////////////////////////////////////////////////////////////////////
// Constructor
@ -30,7 +31,7 @@ CMiniPatch::~CMiniPatch()
void CMiniPatch::GetTileIndex(u32& x,u32& z)
{
const ptrdiff_t tindex = this - &m_Parent->m_MiniPatches[0][0];
x=(m_Parent->m_X*16)+tindex%16;
z=(m_Parent->m_Z*16)+tindex/16;
x=(m_Parent->m_X*PATCH_SIZE)+tindex%PATCH_SIZE;
z=(m_Parent->m_Z*PATCH_SIZE)+tindex/PATCH_SIZE;
}

View File

@ -36,8 +36,8 @@ void CPatch::Initialize(CTerrain* parent,u32 x,u32 z)
m_Z=z;
// set parent of each patch
for (int j=0;j<16;j++) {
for (int i=0;i<16;i++) {
for (int j=0;j<PATCH_SIZE;j++) {
for (int i=0;i<PATCH_SIZE;i++) {
m_MiniPatches[j][i].m_Parent=this;
}
}

View File

@ -9,13 +9,25 @@
#ifndef _PATCH_H
#define _PATCH_H
///////////////////////////////////////////////////////////////////////////////
// Terrain Constants:
//
// PATCH_SIZE: number of tiles in each patch
const int PATCH_SIZE = 16;
// CELL_SIZE: size of each tile in x and z
const int CELL_SIZE = 4;
// HEIGHT_SCALE: vertical scale of terrain - terrain has a coordinate range of
// 0 to 65536*HEIGHT_SCALE
const float HEIGHT_SCALE = 0.35f/256.0f;
#include "MiniPatch.h"
#include "RenderableObject.h"
class CTerrain;
///////////////////////////////////////////////////////////////////////////////
// CPatch: a single terrain patch, 16 tiles square
// CPatch: a single terrain patch, PATCH_SIZE tiles square
class CPatch : public CRenderableObject
{
public:
@ -31,7 +43,7 @@ public:
public:
// minipatches (tiles) making up the patch
CMiniPatch m_MiniPatches[16][16];
CMiniPatch m_MiniPatches[PATCH_SIZE][PATCH_SIZE];
// position of patch in parent terrain grid
u32 m_X,m_Z;
// parent terrain

View File

@ -146,8 +146,8 @@ CMiniPatch* CTerrain::GetTile(int32_t x,int32_t z)
if (x<0 || x>=int32_t(m_MapSize)-1) return 0;
if (z<0 || z>=int32_t(m_MapSize)-1) return 0;
CPatch* patch=GetPatch(x/16,z/16);
return &patch->m_MiniPatches[z%16][x%16];
CPatch* patch=GetPatch(x/PATCH_SIZE,z/PATCH_SIZE);
return &patch->m_MiniPatches[z%PATCH_SIZE][x%PATCH_SIZE];
}
@ -210,16 +210,16 @@ void CTerrain::Resize(u32 size)
for (u32 i=0;i<size;i++) {
// copy over texture data from existing tiles, if possible
if (i<m_MapSizePatches && j<m_MapSizePatches) {
memcpy(newPatches[j*size+i].m_MiniPatches,m_Patches[j*m_MapSizePatches+i].m_MiniPatches,sizeof(CMiniPatch)*16*16);
memcpy(newPatches[j*size+i].m_MiniPatches,m_Patches[j*m_MapSizePatches+i].m_MiniPatches,sizeof(CMiniPatch)*PATCH_SIZE*PATCH_SIZE);
}
}
if (j<m_MapSizePatches && size>m_MapSizePatches) {
// copy over the last tile from each column
for (u32 n=0;n<size-m_MapSizePatches;n++) {
for (int m=0;m<16;m++) {
for (int m=0;m<PATCH_SIZE;m++) {
CMiniPatch& src=m_Patches[j*m_MapSizePatches+m_MapSizePatches-1].m_MiniPatches[m][15];
for (int k=0;k<16;k++) {
for (int k=0;k<PATCH_SIZE;k++) {
CMiniPatch& dst=newPatches[j*size+m_MapSizePatches+n].m_MiniPatches[m][k];
dst.Tex1=src.Tex1;
dst.Tex1Priority=src.Tex1Priority;
@ -235,8 +235,8 @@ void CTerrain::Resize(u32 size)
CPatch* dstpatch=srcpatch+size;
for (u32 p=0;p<size-m_MapSizePatches;p++) {
for (u32 n=0;n<size;n++) {
for (int m=0;m<16;m++) {
for (int k=0;k<16;k++) {
for (int m=0;m<PATCH_SIZE;m++) {
for (int k=0;k<PATCH_SIZE;k++) {
CMiniPatch& src=srcpatch->m_MiniPatches[15][k];
CMiniPatch& dst=dstpatch->m_MiniPatches[m][k];
dst.Tex1=src.Tex1;

View File

@ -13,18 +13,6 @@
#include "Patch.h"
#include "Vector3D.h"
///////////////////////////////////////////////////////////////////////////////
// Terrain Constants:
//
// PATCH_SIZE: number of tiles in each patch
const int PATCH_SIZE = 16;
// CELL_SIZE: size of each tile in x and z
const int CELL_SIZE = 4;
// HEIGHT_SCALE: vertical scale of terrain - terrain has a coordinate range of
// 0 to 65536*HEIGHT_SCALE
const float HEIGHT_SCALE = 0.35f/256.0f;
///////////////////////////////////////////////////////////////////////////////
// CTerrain: main terrain class; contains the heightmap describing elevation
// data, and the smaller subpatches that form the terrain