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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
#include "stdafx.h"
#include "ParticleEngine.h"
#include "Particle.h"
#include "Textures.h"
#include "TextureAtlas.h"
#include "Tesselator.h"
#include "TerrainParticle.h"
#include "ResourceLocation.h"
#include "Camera.h"
#include "..\Minecraft.World\net.minecraft.world.entity.player.h"
#include "..\Minecraft.World\net.minecraft.world.level.tile.h"
#include "..\Minecraft.World\net.minecraft.world.level.h"
#include "..\Minecraft.World\StringHelpers.h"
#include "..\Minecraft.World\net.minecraft.world.level.dimension.h"
ResourceLocation ParticleEngine::PARTICLES_LOCATION = ResourceLocation(TN_PARTICLES);
ParticleEngine::ParticleEngine(Level *level, Textures *textures)
{
// if (level != NULL) // 4J - removed - we want level to be initialised to *something*
{
this->level = level;
}
this->textures = textures;
this->random = new Random();
}
ParticleEngine::~ParticleEngine()
{
delete random;
}
void ParticleEngine::add(shared_ptr<Particle> p)
{
int t = p->getParticleTexture();
int l = p->level->dimension->id == 0 ? 0 : ( p->level->dimension->id == -1 ? 1 : 2);
int maxParticles;
switch(p->GetType())
{
case eTYPE_DRAGONBREATHPARTICLE:
maxParticles = MAX_DRAGON_BREATH_PARTICLES;
break;
case eType_FIREWORKSSPARKPARTICLE:
maxParticles = MAX_FIREWORK_SPARK_PARTICLES;
break;
default:
maxParticles = MAX_PARTICLES_PER_LAYER;
break;
}
int list = p->getAlpha() != 1.0f ? TRANSLUCENT_LIST : OPAQUE_LIST; // 4J - Brought forward from Java 1.8
if( particles[l][t][list].size() >= maxParticles)
{
particles[l][t][list].pop_front();
}
particles[l][t][list].push_back(p);
}
void ParticleEngine::tick()
{
for( int l = 0; l < 3; l++ )
{
for (int tt = 0; tt < TEXTURE_COUNT; tt++)
{
for( int list = 0; list < LIST_COUNT; list++ ) // 4J - Brought forward from Java 1.8
{
for (unsigned int i = 0; i < particles[l][tt][list].size(); i++)
{
shared_ptr<Particle> p = particles[l][tt][list][i];
p->tick();
if (p->removed)
{
particles[l][tt][list][i] = particles[l][tt][list].back();
particles[l][tt][list].pop_back();
i--;
}
}
}
}
}
}
void ParticleEngine::render(shared_ptr<Entity> player, float a, int list)
{
// 4J - change brought forward from 1.2.3
float xa = Camera::xa;
float za = Camera::za;
float xa2 = Camera::xa2;
float za2 = Camera::za2;
float ya = Camera::ya;
Particle::xOff = (player->xOld + (player->x - player->xOld) * a);
Particle::yOff = (player->yOld + (player->y - player->yOld) * a);
Particle::zOff = (player->zOld + (player->z - player->zOld) * a);
int l = level->dimension->id == 0 ? 0 : ( level->dimension->id == -1 ? 1 : 2 );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER, 1.0f / 255.0f);
for (int tt = 0; tt < TEXTURE_COUNT; tt++)
{
if(tt == ENTITY_PARTICLE_TEXTURE) continue;
if (!particles[l][tt][list].empty())
{
switch (list)
{
case TRANSLUCENT_LIST:
glDepthMask(false);
break;
case OPAQUE_LIST:
glDepthMask(true);
break;
}
MemSect(31);
if (tt == MISC_TEXTURE || tt == DRAGON_BREATH_TEXTURE) textures->bindTexture(&PARTICLES_LOCATION);
if (tt == TERRAIN_TEXTURE) textures->bindTexture(&TextureAtlas::LOCATION_BLOCKS);
if (tt == ITEM_TEXTURE) textures->bindTexture(&TextureAtlas::LOCATION_ITEMS);
MemSect(0);
Tesselator *t = Tesselator::getInstance();
glColor4f(1.0f, 1.0f, 1.0f, 1);
t->begin();
for (unsigned int i = 0; i < particles[l][tt][list].size(); i++)
{
if(t->hasMaxVertices())
{
t->end();
t->begin();
}
shared_ptr<Particle> p = particles[l][tt][list][i];
if (SharedConstants::TEXTURE_LIGHTING) // 4J - change brought forward from 1.8.2
{
t->tex2(p->getLightColor(a));
}
p->render(t, a, xa, ya, za, xa2, za2);
}
t->end();
}
}
glDisable(GL_BLEND);
glDepthMask(true);
glAlphaFunc(GL_GREATER, .1f);
}
void ParticleEngine::renderLit(shared_ptr<Entity> player, float a, int list)
{
// 4J - added. We call this before ParticleEngine::render in the general render per player, so if we
// don't set this here then the offsets will be from the previous player - a single frame lag for the
// java game, or totally incorrect placement of things for split screen.
Particle::xOff = (player->xOld + (player->x - player->xOld) * a);
Particle::yOff = (player->yOld + (player->y - player->yOld) * a);
Particle::zOff = (player->zOld + (player->z - player->zOld) * a);
float RAD = PI / 180;
float xa = (float) Mth::cos(player->yRot * RAD);
float za = (float) Mth::sin(player->yRot * RAD);
float xa2 = -za * (float) Mth::sin(player->xRot * RAD);
float za2 = xa * (float) Mth::sin(player->xRot * RAD);
float ya = (float) Mth::cos(player->xRot * RAD);
int l = level->dimension->id == 0 ? 0 : ( level->dimension->id == -1 ? 1 : 2 );
int tt = ENTITY_PARTICLE_TEXTURE;
if( !particles[l][tt][list].empty() )
{
Tesselator *t = Tesselator::getInstance();
for (unsigned int i = 0; i < particles[l][tt][list].size(); i++)
{
shared_ptr<Particle> p = particles[l][tt][list][i];
if (SharedConstants::TEXTURE_LIGHTING) // 4J - change brought forward from 1.8.2
{
t->tex2(p->getLightColor(a));
}
p->render(t, a, xa, ya, za, xa2, za2);
}
}
}
void ParticleEngine::setLevel(Level *level)
{
this->level = level;
// 4J - we've now got a set of particle vectors for each dimension, and only clearing them when its game over & the level is set to NULL
if( level == NULL )
{
for( int l = 0; l < 3; l++ )
{
for (int tt = 0; tt < TEXTURE_COUNT; tt++)
{
for( int list = 0; list < LIST_COUNT; list++ )
{
particles[l][tt][list].clear();
}
}
}
}
}
void ParticleEngine::destroy(int x, int y, int z, int tid, int data)
{
if (tid == 0) return;
Tile *tile = Tile::tiles[tid];
int SD = 4;
for (int xx = 0; xx < SD; xx++)
for (int yy = 0; yy < SD; yy++)
for (int zz = 0; zz < SD; zz++)
{
double xp = x + (xx + 0.5) / SD;
double yp = y + (yy + 0.5) / SD;
double zp = z + (zz + 0.5) / SD;
int face = random->nextInt(6);
add(( shared_ptr<TerrainParticle>(new TerrainParticle(level, xp, yp, zp, xp - x - 0.5f, yp - y - 0.5f, zp - z - 0.5f, tile, face, data, textures) ) )->init(x, y, z, data));
}
}
void ParticleEngine::crack(int x, int y, int z, int face)
{
int tid = level->getTile(x, y, z);
if (tid == 0) return;
Tile *tile = Tile::tiles[tid];
float r = 0.10f;
double xp = x + random->nextDouble() * ((tile->getShapeX1() - tile->getShapeX0()) - r * 2) + r + tile->getShapeX0();
double yp = y + random->nextDouble() * ((tile->getShapeY1() - tile->getShapeY0()) - r * 2) + r + tile->getShapeY0();
double zp = z + random->nextDouble() * ((tile->getShapeZ1() - tile->getShapeZ0()) - r * 2) + r + tile->getShapeZ0();
if (face == 0) yp = y + tile->getShapeY0() - r;
if (face == 1) yp = y + tile->getShapeY1() + r;
if (face == 2) zp = z + tile->getShapeZ0() - r;
if (face == 3) zp = z + tile->getShapeZ1() + r;
if (face == 4) xp = x + tile->getShapeX0() - r;
if (face == 5) xp = x + tile->getShapeX1() + r;
add(( shared_ptr<TerrainParticle>(new TerrainParticle(level, xp, yp, zp, 0, 0, 0, tile, face, level->getData(x, y, z), textures) ) )->init(x, y, z, level->getData(x, y, z))->setPower(0.2f)->scale(0.6f));
}
void ParticleEngine::markTranslucent(shared_ptr<Particle> particle)
{
moveParticleInList(particle, OPAQUE_LIST, TRANSLUCENT_LIST);
}
void ParticleEngine::markOpaque(shared_ptr<Particle> particle)
{
moveParticleInList(particle, TRANSLUCENT_LIST, OPAQUE_LIST);
}
void ParticleEngine::moveParticleInList(shared_ptr<Particle> particle, int source, int destination)
{
int l = particle->level->dimension->id == 0 ? 0 : ( particle->level->dimension->id == -1 ? 1 : 2);
for (int tt = 0; tt < TEXTURE_COUNT; tt++)
{
auto it = find(particles[l][tt][source].begin(), particles[l][tt][source].end(), particle);
if(it != particles[l][tt][source].end() )
{
(*it) = particles[l][tt][source].back();
particles[l][tt][source].pop_back();
particles[l][tt][destination].push_back(particle);
}
}
}
wstring ParticleEngine::countParticles()
{
int l = level->dimension->id == 0 ? 0 : (level->dimension->id == -1 ? 1 : 2 );
int total = 0;
for( int tt = 0; tt < TEXTURE_COUNT; tt++ )
{
for( int list = 0; list < LIST_COUNT; list++ )
{
total += particles[l][tt][list].size();
}
}
return std::to_wstring(total);
}
|