1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef QTPFS_NODELAYER_HDR
#define QTPFS_NODELAYER_HDR
#include <limits>
#include <vector>
#include <list> // for QTPFS_STAGGERED_LAYER_UPDATES
#include <boost/cstdint.hpp>
#include "System/Rectangle.h"
#include "PathDefines.hpp"
struct MoveDef;
namespace QTPFS {
struct INode;
#ifdef QTPFS_STAGGERED_LAYER_UPDATES
struct LayerUpdate {
SRectangle rectangle;
std::vector<float> speedMods;
std::vector<int > blockBits;
unsigned int counter;
};
#endif
struct NodeLayer {
public:
typedef unsigned char SpeedModType;
typedef unsigned char SpeedBinType;
static void InitStatic();
static size_t MaxSpeedModTypeValue() { return (std::numeric_limits<SpeedModType>::max()); }
static size_t MaxSpeedBinTypeValue() { return (std::numeric_limits<SpeedBinType>::max()); }
NodeLayer();
void Init(unsigned int layerNum);
void Clear();
#ifdef QTPFS_STAGGERED_LAYER_UPDATES
void QueueUpdate(const SRectangle& r, const MoveDef* md);
void PopQueuedUpdate() { layerUpdates.pop_front(); }
bool ExecQueuedUpdate();
bool HaveQueuedUpdate() const { return (!layerUpdates.empty()); }
const LayerUpdate& GetQueuedUpdate() const { return (layerUpdates.front()); }
unsigned int NumQueuedUpdates() const { return (layerUpdates.size()); }
#endif
bool Update(
const SRectangle& r,
const MoveDef* md,
const std::vector<float>* luSpeedMods = NULL,
const std::vector< int>* luBlockBits = NULL
);
void ExecNodeNeighborCacheUpdate(unsigned int currFrameNum, unsigned int currMagicNum);
void ExecNodeNeighborCacheUpdates(const SRectangle& ur, unsigned int currMagicNum);
float GetNodeRatio() const { return (numLeafNodes / std::max(1.0f, float(xsize * zsize))); }
const INode* GetNode(unsigned int x, unsigned int z) const { return nodeGrid[z * xsize + x]; }
INode* GetNode(unsigned int x, unsigned int z) { return nodeGrid[z * xsize + x]; }
const INode* GetNode(unsigned int i) const { return nodeGrid[i]; }
INode* GetNode(unsigned int i) { return nodeGrid[i]; }
const std::vector<SpeedBinType>& GetOldSpeedBins() const { return oldSpeedBins; }
const std::vector<SpeedBinType>& GetCurSpeedBins() const { return curSpeedBins; }
const std::vector<SpeedModType>& GetOldSpeedMods() const { return oldSpeedMods; }
const std::vector<SpeedModType>& GetCurSpeedMods() const { return curSpeedMods; }
std::vector<INode*>& GetNodes() { return nodeGrid; }
void RegisterNode(INode* n);
void SetNumLeafNodes(unsigned int n) { numLeafNodes = n; }
unsigned int GetNumLeafNodes() const { return numLeafNodes; }
float GetMaxRelSpeedMod() const { return maxRelSpeedMod; }
float GetAvgRelSpeedMod() const { return avgRelSpeedMod; }
SpeedBinType GetSpeedModBin(float absSpeedMod, float relSpeedMod) const;
boost::uint64_t GetMemFootPrint() const {
boost::uint64_t memFootPrint = sizeof(NodeLayer);
memFootPrint += (curSpeedMods.size() * sizeof(SpeedModType));
memFootPrint += (oldSpeedMods.size() * sizeof(SpeedModType));
memFootPrint += (curSpeedBins.size() * sizeof(SpeedBinType));
memFootPrint += (oldSpeedBins.size() * sizeof(SpeedBinType));
memFootPrint += (nodeGrid.size() * sizeof(INode*));
return memFootPrint;
}
private:
std::vector<INode*> nodeGrid;
std::vector<SpeedModType> curSpeedMods;
std::vector<SpeedModType> oldSpeedMods;
std::vector<SpeedBinType> curSpeedBins;
std::vector<SpeedBinType> oldSpeedBins;
#ifdef QTPFS_STAGGERED_LAYER_UPDATES
std::list<LayerUpdate> layerUpdates;
#endif
// NOTE:
// we need a fixed range that does not become wider / narrower
// during terrain deformations (otherwise the bins would change
// across ALL nodes)
static unsigned int NUM_SPEEDMOD_BINS;
static float MIN_SPEEDMOD_VALUE;
static float MAX_SPEEDMOD_VALUE;
unsigned int layerNumber;
unsigned int numLeafNodes;
unsigned int updateCounter;
unsigned int xsize;
unsigned int zsize;
float maxRelSpeedMod;
float avgRelSpeedMod;
};
}
#endif
|