summaryrefslogtreecommitdiff
path: root/src/JSystem/JParticle/JPAResourceManager.cpp
blob: 430ad1012c3b43b9d139f4cf8fbfaa028ca32306 (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
70
71
72
73
74
#include "JSystem/JParticle/JPAResourceManager.h"
#include "JSystem/JParticle/JPADynamicsBlock.h"
#include "JSystem/JParticle/JPAResource.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "egg/core/eggHeap.h"
#include <cstring>

struct JPAResourceLoader {
    JPAResourceLoader(u8 const*, JPAResourceManager*);
};

JPAResourceManager::JPAResourceManager(void const* p_jpc, EGG::Heap* pHeap) {
    pResAry = NULL;
    pTexAry = NULL;
    resMaxNum = 0;
    resRegNum = 0;
    texMaxNum = 0;
    texRegNum = 0;
    mpHeap = pHeap;
    JUT_ASSERT(49, (p_jpc != 0) && (pHeap != 0));
    JPAResourceLoader loader((u8 const*)p_jpc, this);
}

JPAResource* JPAResourceManager::getResource(u16 usrIdx) const {
    for (u16 i = 0; i < resRegNum; i++)
        if (pResAry[i]->getUsrIdx() == usrIdx)
            return pResAry[i];
    return NULL;
}

bool JPAResourceManager::checkUserIndexDuplication(u16 usrIdx) const {
    for (s32 i = 0; i < resRegNum; i++)
        if (pResAry[i]->getUsrIdx() == usrIdx)
            return true;
    return false;
}

const EGG::ResTIMG* JPAResourceManager::swapTexture(EGG::ResTIMG const* img, char const* swapName) {
    const EGG::ResTIMG* ret = NULL;
    EGG::Texture* tex = NULL;

    for (s32 i = 0; i < texRegNum; i++) {
        if (strcmp(swapName, pTexAry[i]->getName()) == 0) {
            tex = pTexAry[i]->getJUTTexture();
            ret = tex->getTexInfo();
            tex->storeTIMG(img, (u8)0);
            break;
        }
    }

    return ret;
}

void JPAResourceManager::registRes(JPAResource* res) {
    JUT_ASSERT(151, resRegNum < resMaxNum);
    pResAry[resRegNum] = res;
    resRegNum++;
}

void JPAResourceManager::registTex(JPATexture* tex) {
    JUT_ASSERT(166, texRegNum < texMaxNum);
    pTexAry[texRegNum] = tex;
    texRegNum++;
}

u32 JPAResourceManager::getResUserWork(u16 usrIdx) const {
    u32 ret = 0;

    JPAResource* res = getResource(usrIdx);
    if (res != NULL)
        ret = res->getDyn()->getResUserWork();

    return ret;
}