aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/OffsettedRenderList.cpp
blob: 0a93fa9219e325f42f7aee37d5ed94327cb72da2 (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
#include "stdafx.h"
#include "..\Minecraft.World\IntBuffer.h"
#include "OffsettedRenderList.h"

// 4J added
OffsettedRenderList::OffsettedRenderList()
{
	x = y = z = 0;
	xOff = yOff = zOff = 0;
	lists = MemoryTracker::createIntBuffer(1024 * 64);
	inited = false;
	rendered = false;
}

void OffsettedRenderList::init(int x, int y, int z, double xOff, double yOff, double zOff)
{
    inited = true;
    lists->clear();
    this->x = x;
    this->y = y;
    this->z = z;

    this->xOff = static_cast<float>(xOff);
    this->yOff = static_cast<float>(yOff);
    this->zOff = static_cast<float>(zOff);
}

bool OffsettedRenderList::isAt(int x, int y, int z)
{
    if (!inited) return false;
    return x == this->x && y == this->y && z == this->z;
}

void OffsettedRenderList::add(int list)
{
	// 4J - added - chunkList::getList returns -1 when chunks aren't visible, we really don't want to end up sending that to glCallLists
	if( list >= 0 )
	{
	    lists->put(list);
	}
    if (lists->remaining() == 0) render();
}

void OffsettedRenderList::render()
{
    if (!inited) return;
    if (!rendered)
	{
        lists->flip();
        rendered = true;
    }
    if (lists->remaining() > 0)
	{
        glPushMatrix();
        glTranslatef(x - xOff, y - yOff, z - zOff);
        glCallLists(lists);
        glPopMatrix();
    }
}

void OffsettedRenderList::clear()
{
    inited = false;
    rendered = false;
}