summaryrefslogtreecommitdiff
path: root/src/egg/gfx/eggFogManager.cpp
blob: 8108162e99e8f4dc0cccc58f02f9198214253bbc (plain)
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
#include "egg/gfx/eggFogManager.h"

#include "common.h"
#include "nw4r/g3d/g3d_scnroot.h"


namespace EGG {

FogManager::FogManager(const u16 num) : mFlag(0), mCount(num), mCount2(num) {
    mpFog = new Fog[num];
}

FogManager::~FogManager() {
    delete[] mpFog;
}

void FogManager::ResetFog() {
    for (int i = 0; i < mCount; i++) {
        mpFog[i].Reset();
    }
}

void FogManager::Calc() {
    if (!(mFlag & 4)) {
        mFlag |= 4;
    }
}

void FogManager::CopyToG3D(nw4r::g3d::ScnRoot *root) const {
    for (int i = 0; i < mCount; i++) {
        mpFog[i].CopyToG3D(root->GetFog(i));
    }
}

void FogManager::SetBinaryInner(const Bin &bin) {
    if (bin.mHeader.mVersion == 0) {
        u32 loopMax = bin.mData.mCount >= mCount2 ? mCount2 : bin.mData.mCount;
        const IBinary<Fog>::Bin *pBinData = bin.mData.mFogData;
        for (u16 i = 0; i < loopMax; i++) {
            mpFog[i].SetBinary(&pBinData[i]);
        }
    }
}

void FogManager::SetBinaryInner(const Bin &bin1, const Bin &bin2, f32 blend) {
    if (bin1.mHeader.mVersion == 0) {
        u32 loopMax = bin1.mData.mCount >= mCount2 ? mCount2 : bin1.mData.mCount;
        const IBinary<Fog>::Bin *pBinData1 = bin1.mData.mFogData;
        const IBinary<Fog>::Bin *pBinData2 = bin2.mData.mFogData;
        for (u16 i = 0; i < loopMax; i++) {
            mpFog[i].SetBinaryBlend(&pBinData1[i], &pBinData2[i], blend);
        }
    }
}

void FogManager::GetBinaryInner(Bin *pOutBin) const {
    pOutBin->mData.mCount = mCount2;
    u16 max = mCount2;
    IBinary<Fog>::Bin *pOutData = pOutBin->mData.mFogData;
    for (u16 i = 0; i < max; i++) {
        mpFog[i].GetBinary(&pOutData[i]);
    }
}

size_t FogManager::GetBinarySize() const {
    return sizeof(Bin) + (mCount2 - 1) * sizeof(Fog::Bin);
}

} // namespace EGG