the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "TileRenderer_SPU.h"
4#include "LiquidTile_SPU.h"
5#include "FireTile_SPU.h"
6#include "RailTile_SPU.h"
7#include "StemTile_SPU.h"
8#include "VineTile_SPU.h"
9#include "WaterLilyTile_SPU.h"
10#include "BrewingStandTile_SPU.h"
11#include "RedStoneDustTile_SPU.h"
12#include "DiodeTile_SPU.h"
13#include "FenceGateTile_SPU.h"
14#include "StairTile_SPU.h"
15#include "EggTile_SPU.h"
16#include "DoorTile_SPU.h"
17#include "FenceTile_SPU.h"
18#include "GrassTile_SPU.h"
19#include "TreeTile_SPU.h"
20#include "WallTile_SPU.h"
21#include "QuartzBlockTile_SPU.h"
22
23// #include <string>
24#include <math.h>
25#include <assert.h>
26
27#ifdef SN_TARGET_PS3_SPU
28#include "..\Common\spu_assert.h"
29#endif
30
31static const float MATH_PI = 3.141592654f;
32
33// #include "GameRenderer.h"
34// #include "Minecraft.h"
35// #include "Textures.h"
36// #include "..\Minecraft.World\net.minecraft.world.level.h"
37// #include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.h"
38// #include "..\Minecraft.World\net.minecraft.world.level.material.h"
39// #include "..\Minecraft.World\net.minecraft.h"
40// #include "..\Minecraft.World\net.minecraft.world.h"
41// #include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.h"
42
43#include "Tesselator_SPU.h"
44
45#ifdef SN_TARGET_PS3_SPU
46#include "Stubs_SPU.h"
47#endif // SN_TARGET_PS3_SPU
48
49// #include "..\..\Minecraft.World\SharedConstants.h"
50#include "Facing_SPU.h"
51
52// #include "EntityTileRenderer.h"
53// #include "Options.h"
54
55// #define DISABLE_TESS_FUNCS
56#ifdef SN_TARGET_PS3_SPU
57class SharedConstants
58{
59public:
60 static const bool TEXTURE_LIGHTING = true;
61 static const int WORLD_RESOLUTION = 16;
62};
63#endif
64
65// #define SN_TARGET_PS3_SPU
66
67bool TileRenderer_SPU::fancy = true;
68bool g_ambientOcclusionMax = false; // minecraft->options->ambientOcclusion >= Options::AO_MAX
69const float smallUV = ( 1.0f / 16.0f );
70
71
72void TileRenderer_SPU::_init()
73{
74 fixedTexture = NULL;
75 xFlipTexture = false;
76 noCulling = false;
77 blsmooth = 1;
78 applyAmbienceOcclusion = false;
79 setColor = true;
80 northFlip = FLIP_NONE;
81 southFlip = FLIP_NONE;
82 eastFlip = FLIP_NONE;
83 westFlip = FLIP_NONE;
84 upFlip = FLIP_NONE;
85 downFlip = FLIP_NONE;
86
87 tileShapeX0 = 0.0;
88 tileShapeX1 = 0.0;
89 tileShapeY0 = 0.0;
90 tileShapeY1 = 0.0;
91 tileShapeZ0 = 0.0;
92 tileShapeZ1 = 0.0;
93 fixedShape = false;
94 smoothShapeLighting = false;
95// minecraft = Minecraft::GetInstance();
96}
97
98TileRenderer_SPU::TileRenderer_SPU( ChunkRebuildData* level )
99{
100 this->level = level;
101 _init();
102}
103
104TileRenderer_SPU::TileRenderer_SPU()
105{
106 this->level = NULL;
107 _init();
108}
109
110Tesselator_SPU* TileRenderer_SPU::getTesselator()
111{
112 Tesselator_SPU* t = &level->m_tesselator;
113 return t;
114}
115
116
117
118void TileRenderer_SPU::setFixedTexture( Icon_SPU *fixedTexture )
119{
120 this->fixedTexture = fixedTexture;
121}
122
123void TileRenderer_SPU::clearFixedTexture()
124{
125 this->fixedTexture = NULL;
126}
127
128bool TileRenderer_SPU::hasFixedTexture()
129{
130 return fixedTexture != NULL;
131}
132
133void TileRenderer_SPU::setShape(float x0, float y0, float z0, float x1, float y1, float z1)
134{
135 if (!fixedShape)
136 {
137 tileShapeX0 = x0;
138 tileShapeX1 = x1;
139 tileShapeY0 = y0;
140 tileShapeY1 = y1;
141 tileShapeZ0 = z0;
142 tileShapeZ1 = z1;
143 smoothShapeLighting = (tileShapeX0 > 0 || tileShapeX1 < 1 || tileShapeY0 > 0 || tileShapeY1 < 1 || tileShapeZ0 > 0 || tileShapeZ1 < 1);
144 }
145}
146
147void TileRenderer_SPU::setShape(Tile_SPU *tt)
148{
149 if (!fixedShape)
150 {
151 tileShapeX0 = tt->getShapeX0();
152 tileShapeX1 = tt->getShapeX1();
153 tileShapeY0 = tt->getShapeY0();
154 tileShapeY1 = tt->getShapeY1();
155 tileShapeZ0 = tt->getShapeZ0();
156 tileShapeZ1 = tt->getShapeZ1();
157 smoothShapeLighting = (tileShapeX0 > 0 || tileShapeX1 < 1 || tileShapeY0 > 0 || tileShapeY1 < 1 || tileShapeZ0 > 0 || tileShapeZ1 < 1);
158 }
159}
160
161void TileRenderer_SPU::setFixedShape(float x0, float y0, float z0, float x1, float y1, float z1)
162{
163 tileShapeX0 = x0;
164 tileShapeX1 = x1;
165 tileShapeY0 = y0;
166 tileShapeY1 = y1;
167 tileShapeZ0 = z0;
168 tileShapeZ1 = z1;
169 fixedShape = true;
170
171 smoothShapeLighting = (tileShapeX0 > 0 || tileShapeX1 < 1 || tileShapeY0 > 0 || tileShapeY1 < 1 || tileShapeZ0 > 0 || tileShapeZ1 < 1);
172}
173
174void TileRenderer_SPU::clearFixedShape()
175{
176 fixedShape = false;
177}
178
179void TileRenderer_SPU::tesselateInWorldFixedTexture( Tile_SPU* tile, int x, int y, int z, Icon_SPU *fixedTexture ) // 4J renamed to differentiate from tesselateInWorld
180{
181 this->setFixedTexture(fixedTexture);
182 tesselateInWorld( tile, x, y, z );
183 this->clearFixedTexture();
184}
185
186void TileRenderer_SPU::tesselateInWorldNoCulling( Tile_SPU* tile, int x, int y, int z, int forceData,
187 TileEntity* forceEntity ) // 4J added forceData, forceEntity param
188{
189 noCulling = true;
190 tesselateInWorld( tile, x, y, z, forceData );
191 noCulling = false;
192}
193
194bool TileRenderer_SPU::hasRenderer(Tile_SPU* tt)
195{
196 int shape = tt->getRenderShape();
197 bool retVal = false;
198 switch(shape)
199 {
200 case Tile_SPU::SHAPE_BLOCK:
201 case Tile_SPU::SHAPE_WATER:
202 case Tile_SPU::SHAPE_CACTUS:
203 case Tile_SPU::SHAPE_STEM:
204 case Tile_SPU::SHAPE_LILYPAD:
205 case Tile_SPU::SHAPE_ROWS:
206 case Tile_SPU::SHAPE_TORCH:
207 case Tile_SPU::SHAPE_FIRE:
208 case Tile_SPU::SHAPE_LADDER:
209 case Tile_SPU::SHAPE_DOOR:
210 case Tile_SPU::SHAPE_RAIL:
211 case Tile_SPU::SHAPE_EGG:
212 case Tile_SPU::SHAPE_VINE:
213 case Tile_SPU::SHAPE_BREWING_STAND:
214 case Tile_SPU::SHAPE_CROSS_TEXTURE:
215 case Tile_SPU::SHAPE_FENCE:
216 retVal = true;
217 break;
218
219 case Tile_SPU::SHAPE_FENCE_GATE:
220 case Tile_SPU::SHAPE_RED_DUST:
221 case Tile_SPU::SHAPE_STAIRS:
222 case Tile_SPU::SHAPE_DIODE:
223 case Tile_SPU::SHAPE_LEVER:
224 case Tile_SPU::SHAPE_BED:
225 case Tile_SPU::SHAPE_PISTON_BASE:
226 case Tile_SPU::SHAPE_PISTON_EXTENSION:
227 case Tile_SPU::SHAPE_IRON_FENCE:
228 case Tile_SPU::SHAPE_CAULDRON:
229 case Tile_SPU::SHAPE_PORTAL_FRAME:
230 retVal = false;
231 break;
232 }
233
234 return retVal;
235}
236
237
238bool TileRenderer_SPU::tesselateInWorld( Tile_SPU* tt, int x, int y, int z, int forceData,
239 TileEntity* forceEntity ) // 4J added forceData, forceEntity param
240{
241 Tesselator_SPU* t = getTesselator();
242
243 int shape = tt->getRenderShape();
244 tt->updateShape( level, x, y, z, forceData, forceEntity );
245 setShape(tt);
246 t->setMipmapEnable( level->m_tileData.mipmapEnable[tt->id] ); // 4J added
247
248 bool retVal = false;
249 switch(shape)
250 {
251 case Tile_SPU::SHAPE_BLOCK:
252 retVal = tesselateBlockInWorld( tt, x, y, z );
253 break;
254 case Tile_SPU::SHAPE_TREE:
255 retVal = tesselateTreeInWorld(tt, x, y, z);
256 break;
257 case Tile_SPU::SHAPE_QUARTZ:
258 retVal = tesselateQuartzInWorld(tt, x, y, z);
259 break;
260 case Tile_SPU::SHAPE_WATER:
261 retVal = tesselateWaterInWorld( tt, x, y, z );
262 break;
263 case Tile_SPU::SHAPE_CACTUS:
264 retVal = tesselateCactusInWorld( tt, x, y, z );
265 break;
266 case Tile_SPU::SHAPE_CROSS_TEXTURE:
267 retVal = tesselateCrossInWorld( tt, x, y, z );
268 break;
269 case Tile_SPU::SHAPE_STEM:
270 retVal = tesselateStemInWorld( tt, x, y, z );
271 break;
272 case Tile_SPU::SHAPE_LILYPAD:
273 retVal = tesselateLilypadInWorld( (WaterlilyTile_SPU*)tt, x, y, z );
274 break;
275 case Tile_SPU::SHAPE_ROWS:
276 retVal = tesselateRowInWorld( tt, x, y, z );
277 break;
278 case Tile_SPU::SHAPE_TORCH:
279 retVal = tesselateTorchInWorld( tt, x, y, z );
280 break;
281 case Tile_SPU::SHAPE_FIRE:
282 retVal = tesselateFireInWorld( (FireTile_SPU *)tt, x, y, z );
283 break;
284 case Tile_SPU::SHAPE_RED_DUST:
285 retVal = tesselateDustInWorld( tt, x, y, z );
286 break;
287 case Tile_SPU::SHAPE_LADDER:
288 retVal = tesselateLadderInWorld( tt, x, y, z );
289 break;
290 case Tile_SPU::SHAPE_DOOR:
291 retVal = tesselateDoorInWorld( tt, x, y, z );
292 break;
293 case Tile_SPU::SHAPE_RAIL:
294 retVal = tesselateRailInWorld( ( RailTile_SPU* )tt, x, y, z );
295 break;
296 case Tile_SPU::SHAPE_STAIRS:
297 retVal = tesselateStairsInWorld( (StairTile_SPU *)tt, x, y, z );
298 break;
299 case Tile_SPU::SHAPE_EGG:
300 retVal = tesselateEggInWorld((EggTile_SPU*) tt, x, y, z);
301 break;
302 case Tile_SPU::SHAPE_FENCE:
303 retVal = tesselateFenceInWorld( ( FenceTile_SPU* )tt, x, y, z );
304 break;
305 case Tile_SPU::SHAPE_WALL:
306 retVal = tesselateWallInWorld( (WallTile_SPU *) tt, x, y, z);
307 break;
308 case Tile_SPU::SHAPE_LEVER:
309 retVal = tesselateLeverInWorld( tt, x, y, z );
310 break;
311 case Tile_SPU::SHAPE_TRIPWIRE_SOURCE:
312 retVal = tesselateTripwireSourceInWorld(tt, x, y, z);
313 break;
314 case Tile_SPU::SHAPE_TRIPWIRE:
315 retVal = tesselateTripwireInWorld(tt, x, y, z);
316 break;
317 case Tile_SPU::SHAPE_BED:
318 retVal = tesselateBedInWorld( tt, x, y, z );
319 break;
320 case Tile_SPU::SHAPE_DIODE:
321 retVal = tesselateDiodeInWorld( (DiodeTile_SPU *)tt, x, y, z );
322 break;
323 case Tile_SPU::SHAPE_PISTON_BASE:
324 retVal = tesselatePistonBaseInWorld( tt, x, y, z, false, forceData );
325 break;
326 case Tile_SPU::SHAPE_PISTON_EXTENSION:
327 retVal = tesselatePistonExtensionInWorld( tt, x, y, z, true, forceData );
328 break;
329 case Tile_SPU::SHAPE_IRON_FENCE:
330 retVal = tesselateThinFenceInWorld( ( ThinFenceTile* )tt, x, y, z );
331 break;
332 case Tile_SPU::SHAPE_VINE:
333 retVal = tesselateVineInWorld( tt, x, y, z );
334 break;
335 case Tile_SPU::SHAPE_FENCE_GATE:
336 retVal = tesselateFenceGateInWorld( ( FenceGateTile_SPU* )tt, x, y, z );
337 break;
338 case Tile_SPU::SHAPE_CAULDRON:
339 retVal = tesselateCauldronInWorld((CauldronTile_SPU* ) tt, x, y, z);
340 break;
341 case Tile_SPU::SHAPE_FLOWER_POT:
342 retVal = tesselateFlowerPotInWorld((FlowerPotTile_SPU *) tt, x, y, z);
343 break;
344 case Tile_SPU::SHAPE_ANVIL:
345 retVal = tesselateAnvilInWorld((AnvilTile_SPU *) tt, x, y, z);
346 break;
347 case Tile_SPU::SHAPE_BREWING_STAND:
348 retVal = tesselateBrewingStandInWorld((BrewingStandTile_SPU* ) tt, x, y, z);
349 break;
350 case Tile_SPU::SHAPE_PORTAL_FRAME:
351 retVal = tesselateAirPortalFrameInWorld((TheEndPortalFrameTile *)tt, x, y, z);
352 break;
353 case Tile_SPU::SHAPE_COCOA:
354 retVal = tesselateCocoaInWorld((CocoaTile_SPU *) tt, x, y, z);
355 break;
356
357 };
358
359
360 t->setMipmapEnable( true ); // 4J added
361 return retVal;
362
363}
364
365bool TileRenderer_SPU::tesselateAirPortalFrameInWorld(TheEndPortalFrameTile *tt, int x, int y, int z)
366{
367#ifdef DISABLE_TESS_FUNCS
368 int data = level->getData(x, y, z);
369
370 int direction = data & 3;
371 if (direction == Direction::SOUTH)
372 {
373 upFlip = FLIP_180;
374 }
375 else if (direction == Direction::EAST)
376 {
377 upFlip = FLIP_CW;
378 }
379 else if (direction == Direction::WEST)
380 {
381 upFlip = FLIP_CCW;
382 }
383
384 if (!TheEndPortalFrameTile::hasEye(data))
385 {
386// EnterCriticalSection( &Tile_SPU::m_csShape );
387 setShape(0, 0, 0, 1, 13.0f / 16.0f, 1);
388 tesselateBlockInWorld(tt, x, y, z);
389// LeaveCriticalSection( &Tile_SPU::m_csShape );
390
391 upFlip = FLIP_NONE;
392 return true;
393 }
394
395// EnterCriticalSection( &Tile_SPU::m_csShape );
396 noCulling = true;
397 setShape(0, 0, 0, 1, 13.0f / 16.0f, 1);
398 tesselateBlockInWorld(tt, x, y, z);
399 setFixedTexture(tt->getEye());
400 setShape(4.0f / 16.0f, 13.0f / 16.0f, 4.0f / 16.0f, 12.0f / 16.0f, 1, 12.0f / 16.0f);
401 tesselateBlockInWorld(tt, x, y, z);
402 noCulling = false;
403 clearFixedTexture();
404// LeaveCriticalSection( &Tile_SPU::m_csShape );
405
406 upFlip = FLIP_NONE;
407#endif // DISABLE_TESS_FUNCS
408 return true;
409}
410
411bool TileRenderer_SPU::tesselateBedInWorld( Tile_SPU* tt, int x, int y, int z )
412{
413#ifdef DISABLE_TESS_FUNCS
414 Tesselator_SPU* t = getTesselator();
415
416 int data = level->getData( x, y, z );
417 int direction = BedTile::getDirection( data );
418 bool isHead = BedTile::isHeadPiece( data );
419
420 float c10 = 0.5f;
421 float c11 = 1.0f;
422 float c2 = 0.8f;
423 float c3 = 0.6f;
424
425 float r11 = c11;
426 float g11 = c11;
427 float b11 = c11;
428
429 float r10 = c10;
430 float r2 = c2;
431 float r3 = c3;
432
433 float g10 = c10;
434 float g2 = c2;
435 float g3 = c3;
436
437 float b10 = c10;
438 float b2 = c2;
439 float b3 = c3;
440
441 // 4J - change brought forward from 1.8.2
442 int centerColor;
443 float centerBrightness;
444 if ( SharedConstants::TEXTURE_LIGHTING )
445 {
446 centerColor = tt->getLightColor( level, x, y, z );
447 }
448 else
449 {
450 centerBrightness = tt->getBrightness( level, x, y, z );
451 }
452
453 // render wooden underside
454 {
455 // 4J - change brought forward from 1.8.2
456 if ( SharedConstants::TEXTURE_LIGHTING )
457 {
458 t->tex2( centerColor );
459 t->color( r10, g10, b10 );
460 }
461 else
462 {
463 t->color( r10 * centerBrightness, g10 * centerBrightness, b10 * centerBrightness );
464 }
465
466 Icon_SPU *tex = getTexture( tt, level, x, y, z, Facing::DOWN );
467
468 float u0 = tex->getU0();
469 float u1 = tex->getU1();
470 float v0 = tex->getV0();
471 float v1 = tex->getV1();
472
473 float x0 = x + tileShapeX0;
474 float x1 = x + tileShapeX1;
475 float y0 = y + tileShapeY0 + 3.0 / 16.0;
476 float z0 = z + tileShapeZ0;
477 float z1 = z + tileShapeZ1;
478
479 t->vertexUV( x0 , y0 , z1 , u0 , v1 );
480 t->vertexUV( x0 , y0 , z0 , u0 , v0 );
481 t->vertexUV( x1 , y0 , z0 , u1 , v0 );
482 t->vertexUV( x1 , y0 , z1 , u1 , v1 );
483 }
484
485 // render bed top
486 // 4J - change brought forward from 1.8.2
487 if ( SharedConstants::TEXTURE_LIGHTING )
488 {
489 t->tex2( tt->getLightColor( level, x, y + 1, z ) );
490 t->color( r11, g11, b11 );
491 }
492 else
493 {
494 float brightness = tt->getBrightness( level, x, y + 1, z );
495 t->color( r11 * brightness, g11 * brightness, b11 * brightness );
496 }
497
498 Icon_SPU *tex = getTexture( tt, level, x, y, z, Facing::UP );
499
500 float u0 = tex->getU0();
501 float u1 = tex->getU1();
502 float v0 = tex->getV0();
503 float v1 = tex->getV1();
504
505 float topLeftU = u0;
506 float topRightU = u1;
507 float topLeftV = v0;
508 float topRightV = v0;
509 float bottomLeftU = u0;
510 float bottomRightU = u1;
511 float bottomLeftV = v1;
512 float bottomRightV = v1;
513
514 if ( direction == Direction::SOUTH )
515 {
516 // rotate 90 degrees clockwise
517 topRightU = u0;
518 topLeftV = v1;
519 bottomLeftU = u1;
520 bottomRightV = v0;
521 }
522 else if ( direction == Direction::NORTH )
523 {
524 // rotate 90 degrees counter-clockwise
525 topLeftU = u1;
526 topRightV = v1;
527 bottomRightU = u0;
528 bottomLeftV = v0;
529 }
530 else if ( direction == Direction::EAST )
531 {
532 // rotate 180 degrees
533 topLeftU = u1;
534 topRightV = v1;
535 bottomRightU = u0;
536 bottomLeftV = v0;
537 topRightU = u0;
538 topLeftV = v1;
539 bottomLeftU = u1;
540 bottomRightV = v0;
541 }
542
543 float x0 = x + tileShapeX0;
544 float x1 = x + tileShapeX1;
545 float y1 = y + tileShapeY1;
546 float z0 = z + tileShapeZ0;
547 float z1 = z + tileShapeZ1;
548
549 t->vertexUV( x1 , y1 , z1 , bottomLeftU ,bottomLeftV );
550 t->vertexUV( x1 , y1 , z0 , topLeftU , topLeftV );
551 t->vertexUV( x0 , y1 , z0 , topRightU ,topRightV );
552 t->vertexUV( x0 , y1 , z1 , bottomRightU ,bottomRightV );
553
554 // determine which edge to skip (the one between foot and head piece)
555 int skipEdge = Direction::DIRECTION_FACING[direction];
556 if ( isHead )
557 {
558 skipEdge = Direction::DIRECTION_FACING[Direction::DIRECTION_OPPOSITE[direction]];
559 }
560 // and which edge to x-flip
561 int flipEdge = Facing::WEST;
562 switch ( direction )
563 {
564 case Direction::NORTH:
565 break;
566 case Direction::SOUTH:
567 flipEdge = Facing::EAST;
568 break;
569 case Direction::EAST:
570 flipEdge = Facing::NORTH;
571 break;
572 case Direction::WEST:
573 flipEdge = Facing::SOUTH;
574 break;
575 }
576
577 if ( ( skipEdge != Facing::NORTH ) && ( noCulling || tt->shouldRenderFace( level, x, y, z - 1, Facing::NORTH ) ) )
578 {
579 if ( SharedConstants::TEXTURE_LIGHTING )
580 {
581 t->tex2( tileShapeZ0 > 0 ? centerColor : tt->getLightColor( level, x, y, z - 1 ) );
582 t->color( r2, g2, b2 );
583 }
584 else
585 {
586 float br = tt->getBrightness( level, x, y, z - 1 );
587 if ( tileShapeZ0 > 0 ) br = centerBrightness;
588 t->color( r2 * br, g2 * br, b2 * br );
589 }
590 xFlipTexture = flipEdge == Facing::NORTH;
591 renderNorth( tt, x, y, z, getTexture( tt, level, x, y, z, 2 ) );
592 }
593
594 if ( ( skipEdge != Facing::SOUTH ) && ( noCulling || tt->shouldRenderFace( level, x, y, z + 1, Facing::SOUTH ) ) )
595 {
596 if ( SharedConstants::TEXTURE_LIGHTING )
597 {
598 t->tex2( tileShapeZ1 < 1 ? centerColor : tt->getLightColor( level, x, y, z + 1 ) );
599 t->color( r2, g2, b2 );
600 }
601 else
602 {
603 float br = tt->getBrightness( level, x, y, z + 1 );
604 if ( tileShapeZ1 < 1 ) br = centerBrightness;
605 t->color( r2 * br, g2 * br, b2 * br );
606 }
607
608 xFlipTexture = flipEdge == Facing::SOUTH;
609 renderSouth( tt, x, y, z, getTexture( tt, level, x, y, z, 3 ) );
610 }
611
612 if ( ( skipEdge != Facing::WEST ) && ( noCulling || tt->shouldRenderFace( level, x - 1, y, z, Facing::WEST ) ) )
613 {
614 if ( SharedConstants::TEXTURE_LIGHTING )
615 {
616 t->tex2( tileShapeZ0 > 0 ? centerColor : tt->getLightColor( level, x - 1, y, z ) );
617 t->color( r3, g3, b3 );
618 }
619 else
620 {
621 float br = tt->getBrightness( level, x - 1, y, z );
622 if ( tileShapeX0 > 0 ) br = centerBrightness;
623 t->color( r3 * br, g3 * br, b3 * br );
624 }
625 xFlipTexture = flipEdge == Facing::WEST;
626 renderWest( tt, x, y, z, getTexture( tt, level, x, y, z, 4 ) );
627 }
628
629 if ( ( skipEdge != Facing::EAST ) && ( noCulling || tt->shouldRenderFace( level, x + 1, y, z, Facing::EAST ) ) )
630 {
631 if ( SharedConstants::TEXTURE_LIGHTING )
632 {
633 t->tex2( tileShapeZ1 < 1 ? centerColor : tt->getLightColor( level, x + 1, y, z ) );
634 t->color( r3, g3, b3 );
635 }
636 else
637 {
638 float br = tt->getBrightness( level, x + 1, y, z );
639 if ( tileShapeX1 < 1 ) br = centerBrightness;
640 t->color( r3 * br, g3 * br, b3 * br );
641 }
642 xFlipTexture = flipEdge == Facing::EAST;
643 renderEast( tt, x, y, z, getTexture( tt, level, x, y, z, 5 ) );
644 }
645 xFlipTexture = false;
646#endif // DISABLE_TESS_FUNCS
647
648 return true;
649
650}
651
652bool TileRenderer_SPU::tesselateBrewingStandInWorld(BrewingStandTile_SPU *tt, int x, int y, int z)
653{
654
655// EnterCriticalSection( &Tile_SPU::m_csShape );
656 // bounding box first
657 setShape(7.0f / 16.0f, 0.0f, 7.0f / 16.0f, 9.0f / 16.0f, 14.0f / 16.0f, 9.0f / 16.0f);
658 tesselateBlockInWorld(tt, x, y, z);
659
660 setFixedTexture(tt->getBaseTexture());
661 setShape(9.0f / 16.0f, 0.0f, 5.0f / 16.0f, 15.0f / 16.0f, 2 / 16.0f, 11.0f / 16.0f);
662 tesselateBlockInWorld(tt, x, y, z);
663 setShape(2.0f / 16.0f, 0.0f, 1.0f / 16.0f, 8.0f / 16.0f, 2 / 16.0f, 7.0f / 16.0f);
664 tesselateBlockInWorld(tt, x, y, z);
665 setShape(2.0f / 16.0f, 0.0f, 9.0f / 16.0f, 8.0f / 16.0f, 2 / 16.0f, 15.0f / 16.0f);
666 tesselateBlockInWorld(tt, x, y, z);
667
668 clearFixedTexture();
669
670 Tesselator_SPU* t = getTesselator();
671
672 float br;
673 if (SharedConstants::TEXTURE_LIGHTING)
674 {
675 t->tex2(tt->getLightColor(level, x, y, z));
676 br = 1;
677 }
678 else
679 {
680 br = tt->getBrightness(level, x, y, z);
681 }
682 int col = tt->getColor(level, x, y, z);
683 float r = ((col >> 16) & 0xff) / 255.0f;
684 float g = ((col >> 8) & 0xff) / 255.0f;
685 float b = ((col) & 0xff) / 255.0f;
686
687 t->color(br * r, br * g, br * b);
688
689 Icon_SPU *tex = getTexture(tt, 0, 0);
690
691 if (hasFixedTexture()) tex = fixedTexture;
692 float v0 = tex->getV0();
693 float v1 = tex->getV1();
694
695 int data = level->getData(x, y, z);
696
697 for (int arm = 0; arm < 3; arm++)
698 {
699
700 float angle = arm * MATH_PI * 2.0f / 3.0f + MATH_PI * 0.5f;
701
702 float u0 = tex->getU(8);
703 float u1 = tex->getU1();
704// if (brewEntity != null && brewEntity.getItem(arm) != null) {
705 if ((data & (1 << arm)) != 0)
706 {
707 u1 = tex->getU0();
708 }
709
710 float x0 = x + 8.0f / 16.0f;
711 float x1 = x + 8.0f / 16.0f + sin(angle) * 8.0f / 16.0f;
712 float z0 = z + 8.0f / 16.0f;
713 float z1 = z + 8.0f / 16.0f + cos(angle) * 8.0f / 16.0f;
714
715 t->vertexUV(x0, y + 1.0f, z0, u0, v0);
716 t->vertexUV(x0, y + 0.0f, z0, u0, v1);
717 t->vertexUV(x1, y + 0.0f, z1, u1, v1);
718 t->vertexUV(x1, y + 1.0f, z1, u1, v0);
719
720 t->vertexUV(x1, y + 1.0f, z1, u1, v0);
721 t->vertexUV(x1, y + 0.0f, z1, u1, v1);
722 t->vertexUV(x0, y + 0.0f, z0, u0, v1);
723 t->vertexUV(x0, y + 1.0f, z0, u0, v0);
724 }
725
726 tt->updateDefaultShape();
727
728// LeaveCriticalSection( &Tile_SPU::m_csShape );
729
730 return true;
731}
732
733bool TileRenderer_SPU::tesselateCauldronInWorld(CauldronTile_SPU *tt, int x, int y, int z)
734{
735#ifdef DISABLE_TESS_FUNCS
736 // bounding box first
737 tesselateBlockInWorld(tt, x, y, z);
738
739 Tesselator_SPU* t = getTesselator();
740
741 float br;
742 if (SharedConstants::TEXTURE_LIGHTING)
743 {
744 t->tex2(tt->getLightColor(level, x, y, z));
745 br = 1;
746 }
747 else
748 {
749 br = tt->getBrightness(level, x, y, z);
750 }
751 int col = tt->getColor(level, x, y, z);
752 float r = ((col >> 16) & 0xff) / 255.0f;
753 float g = ((col >> 8) & 0xff) / 255.0f;
754 float b = ((col) & 0xff) / 255.0f;
755
756 t->color(br * r, br * g, br * b);
757
758 // render inside
759 Icon_SPU *insideTex = tt->getTexture(Facing::NORTH);
760 const float cWidth = ( 2.0f / 16.0f ) - ( 1.0f / 128.0f ); // 4J - Moved by 1/128th (smallest movement possible with our vertex storage) to remove gap at edge of cauldron
761 renderEast(tt, x - 1.0f + cWidth, y, z, insideTex);
762 renderWest(tt, x + 1.0f - cWidth, y, z, insideTex);
763 renderSouth(tt, x, y, z - 1.0f + cWidth, insideTex);
764 renderNorth(tt, x, y, z + 1.0f - cWidth, insideTex);
765
766 Icon_SPU *bottomTex = CauldronTile::getTexture(CauldronTile::TEXTURE_INSIDE);
767 renderFaceUp(tt, x, y - 1.0f + 4.0f / 16.0f, z, bottomTex);
768 renderFaceDown(tt, x, y + 1.0f - 12.0f / 16.0f, z, bottomTex);
769
770 int waterLevel = level->getData(x, y, z);
771 if (waterLevel > 0)
772 {
773 Icon_SPU *liquidTex = LiquidTile_SPU::getTexture(LiquidTile_SPU::TEXTURE_WATER_STILL);
774
775 if (waterLevel > 3)
776 {
777 waterLevel = 3;
778 }
779
780 renderFaceUp(tt, x, y - 1.0f + (6.0f + waterLevel * 3.0f) / 16.0f, z, liquidTex);
781 }
782#endif // DISABLE_TESS_FUNCS
783
784 return true;
785
786}
787
788bool TileRenderer_SPU::tesselateFlowerPotInWorld(FlowerPotTile_SPU *tt, int x, int y, int z)
789{
790#ifdef DISABLE_TESS_FUNCS
791 // bounding box first
792 tesselateBlockInWorld(tt, x, y, z);
793
794 Tesselator *t = Tesselator::getInstance();
795
796 float br;
797 if (SharedConstants::TEXTURE_LIGHTING)
798 {
799 t->tex2(tt->getLightColor(level, x, y, z));
800 br = 1;
801 }
802 else
803 {
804 br = tt->getBrightness(level, x, y, z);
805 }
806 int col = tt->getColor(level, x, y, z);
807 Icon *tex = getTexture(tt, 0);
808 float r = ((col >> 16) & 0xff) / 255.0f;
809 float g = ((col >> 8) & 0xff) / 255.0f;
810 float b = ((col) & 0xff) / 255.0f;
811
812 if (GameRenderer::anaglyph3d)
813 {
814 float cr = (r * 30 + g * 59 + b * 11) / 100;
815 float cg = (r * 30 + g * 70) / (100);
816 float cb = (r * 30 + b * 70) / (100);
817
818 r = cr;
819 g = cg;
820 b = cb;
821 }
822 t->color(br * r, br * g, br * b);
823
824 // render inside
825
826 float halfWidth = (6.0f / 16.0f) / 2 - 0.001f;
827 renderEast(tt, x - 0.5f + halfWidth, y, z, tex);
828 renderWest(tt, x + 0.5f - halfWidth, y, z, tex);
829 renderSouth(tt, x, y, z - 0.5f + halfWidth, tex);
830 renderNorth(tt, x, y, z + 0.5f - halfWidth, tex);
831
832 renderFaceUp(tt, x, y - 0.5f + halfWidth + 3.0f / 16.0f, z, getTexture(Tile::dirt));
833
834 int type = level->getData(x, y, z);
835
836 if (type != 0)
837 {
838 float xOff = 0;
839 float yOff = 4;
840 float zOff = 0;
841 Tile *plant = NULL;
842
843 switch (type)
844 {
845 case FlowerPotTile::TYPE_FLOWER_RED:
846 plant = Tile::rose;
847 break;
848 case FlowerPotTile::TYPE_FLOWER_YELLOW:
849 plant = Tile::flower;
850 break;
851 case FlowerPotTile::TYPE_MUSHROOM_BROWN:
852 plant = Tile::mushroom1;
853 break;
854 case FlowerPotTile::TYPE_MUSHROOM_RED:
855 plant = Tile::mushroom2;
856 break;
857 }
858
859 t->addOffset(xOff / 16.0f, yOff / 16.0f, zOff / 16.0f);
860
861 if (plant != NULL)
862 {
863 tesselateInWorld(plant, x, y, z);
864 }
865 else
866 {
867 if (type == FlowerPotTile::TYPE_CACTUS)
868 {
869
870 // Force drawing of all faces else the cactus misses faces
871 // when a block is adjacent
872 noCulling = true;
873
874 float halfSize = 0.25f / 2;
875 setShape(0.5f - halfSize, 0.0f, 0.5f - halfSize, 0.5f + halfSize, 0.25f, 0.5f + halfSize);
876 tesselateBlockInWorld(Tile::cactus, x, y, z);
877 setShape(0.5f - halfSize, 0.25f, 0.5f - halfSize, 0.5f + halfSize, 0.5f, 0.5f + halfSize);
878 tesselateBlockInWorld(Tile::cactus, x, y, z);
879 setShape(0.5f - halfSize, 0.5f, 0.5f - halfSize, 0.5f + halfSize, 0.75f, 0.5f + halfSize);
880 tesselateBlockInWorld(Tile::cactus, x, y, z);
881
882 noCulling = false;
883
884 setShape(0, 0, 0, 1, 1, 1);
885 }
886 else if (type == FlowerPotTile::TYPE_SAPLING_DEFAULT)
887 {
888 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_DEFAULT, x, y, z, 0.75f);
889 }
890 else if (type == FlowerPotTile::TYPE_SAPLING_BIRCH)
891 {
892 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_BIRCH, x, y, z, 0.75f);
893 }
894 else if (type == FlowerPotTile::TYPE_SAPLING_EVERGREEN)
895 {
896 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_EVERGREEN, x, y, z, 0.75f);
897 }
898 else if (type == FlowerPotTile::TYPE_SAPLING_JUNGLE)
899 {
900 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_JUNGLE, x, y, z, 0.75f);
901 }
902 else if (type == FlowerPotTile::TYPE_FERN)
903 {
904 col = Tile::tallgrass->getColor(level, x, y, z);
905 r = ((col >> 16) & 0xff) / 255.0f;
906 g = ((col >> 8) & 0xff) / 255.0f;
907 b = ((col) & 0xff) / 255.0f;
908 t->color(br * r, br * g, br * b);
909 tesselateCrossTexture(Tile::tallgrass, TallGrass::FERN, x, y, z, 0.75f);
910 }
911 else if (type == FlowerPotTile::TYPE_DEAD_BUSH)
912 {
913 tesselateCrossTexture(Tile::deadBush, TallGrass::FERN, x, y, z, 0.75f);
914 }
915 }
916
917 t->addOffset(-xOff / 16.0f, -yOff / 16.0f, -zOff / 16.0f);
918 }
919#endif //DISABLE_TESS_FUNCS
920
921 return true;
922}
923
924bool TileRenderer_SPU::tesselateAnvilInWorld(AnvilTile_SPU *tt, int x, int y, int z)
925{
926 return tesselateAnvilInWorld(tt, x, y, z, level->getData(x, y, z));
927
928}
929
930bool TileRenderer_SPU::tesselateAnvilInWorld(AnvilTile_SPU *tt, int x, int y, int z, int data)
931{
932#ifdef DISABLE_TESS_FUNCS
933 Tesselator *t = Tesselator::getInstance();
934
935 float br;
936 if (SharedConstants::TEXTURE_LIGHTING)
937 {
938 t->tex2(tt->getLightColor(level, x, y, z));
939 br = 1;
940 }
941 else
942 {
943 br = tt->getBrightness(level, x, y, z);
944 }
945 int col = tt->getColor(level, x, y, z);
946 float r = ((col >> 16) & 0xff) / 255.0f;
947 float g = ((col >> 8) & 0xff) / 255.0f;
948 float b = ((col) & 0xff) / 255.0f;
949
950 if (GameRenderer::anaglyph3d)
951 {
952 float cr = (r * 30 + g * 59 + b * 11) / 100;
953 float cg = (r * 30 + g * 70) / (100);
954 float cb = (r * 30 + b * 70) / (100);
955
956 r = cr;
957 g = cg;
958 b = cb;
959 }
960 t->color(br * r, br * g, br * b);
961#endif // DISABLE_TESS_FUNCS
962
963
964 return tesselateAnvilInWorld(tt, x, y, z, data, false);
965}
966
967bool TileRenderer_SPU::tesselateAnvilInWorld(AnvilTile_SPU *tt, int x, int y, int z, int data, bool render)
968{
969#ifdef DISABLE_TESS_FUNCS
970
971 int facing = render ? 0 : data & 3;
972 boolean rotate = false;
973 float bottom = 0;
974
975 switch (facing)
976 {
977 case Direction::NORTH:
978 eastFlip = FLIP_CW;
979 westFlip = FLIP_CCW;
980 break;
981 case Direction::SOUTH:
982 eastFlip = FLIP_CCW;
983 westFlip = FLIP_CW;
984 upFlip = FLIP_180;
985 downFlip = FLIP_180;
986 break;
987 case Direction::WEST:
988 northFlip = FLIP_CW;
989 southFlip = FLIP_CCW;
990 upFlip = FLIP_CCW;
991 downFlip = FLIP_CW;
992 rotate = true;
993 break;
994 case Direction::EAST:
995 northFlip = FLIP_CCW;
996 southFlip = FLIP_CW;
997 upFlip = FLIP_CW;
998 downFlip = FLIP_CCW;
999 rotate = true;
1000 break;
1001 }
1002
1003 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_BASE, bottom, 12.0f / 16.0f, 4.0f / 16.0f, 12.0f / 16.0f, rotate, render, data);
1004 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_JOINT, bottom, 8.0f / 16.0f, 1.0f / 16.0f, 10.0f / 16.0f, rotate, render, data);
1005 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_COLUMN, bottom, 4.0f / 16.0f, 5.0f / 16.0f, 8.0f / 16.0f, rotate, render, data);
1006 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_TOP, bottom, 10.0f / 16.0f, 6.0f / 16.0f, 16.0f / 16.0f, rotate, render, data);
1007
1008 setShape(0, 0, 0, 1, 1, 1);
1009 northFlip = FLIP_NONE;
1010 southFlip = FLIP_NONE;
1011 eastFlip = FLIP_NONE;
1012 westFlip = FLIP_NONE;
1013 upFlip = FLIP_NONE;
1014 downFlip = FLIP_NONE;
1015#endif // DISABLE_TESS_FUNCS
1016
1017 return true;
1018}
1019
1020float TileRenderer_SPU::tesselateAnvilPiece(AnvilTile_SPU *tt, int x, int y, int z, int part, float bottom, float width, float height, float length, bool rotate, bool render, int data)
1021{
1022#ifdef DISABLE_TESS_FUNCS
1023 if (rotate)
1024 {
1025 float swap = width;
1026 width = length;
1027 length = swap;
1028 }
1029
1030 width /= 2;
1031 length /= 2;
1032
1033 ms_pTileData->anvilPart = part;
1034 setShape(0.5f - width, bottom, 0.5f - length, 0.5f + width, bottom + height, 0.5f + length);
1035
1036 if (render)
1037 {
1038 Tesselator *t = Tesselator::getInstance();
1039 t->begin();
1040 t->normal(0, -1, 0);
1041 renderFaceDown(tt, 0, 0, 0, getTexture(tt, 0, data));
1042 t->end();
1043
1044 t->begin();
1045 t->normal(0, 1, 0);
1046 renderFaceUp(tt, 0, 0, 0, getTexture(tt, 1, data));
1047 t->end();
1048
1049 t->begin();
1050 t->normal(0, 0, -1);
1051 renderNorth(tt, 0, 0, 0, getTexture(tt, 2, data));
1052 t->end();
1053
1054 t->begin();
1055 t->normal(0, 0, 1);
1056 renderSouth(tt, 0, 0, 0, getTexture(tt, 3, data));
1057 t->end();
1058
1059 t->begin();
1060 t->normal(-1, 0, 0);
1061 renderWest(tt, 0, 0, 0, getTexture(tt, 4, data));
1062 t->end();
1063
1064 t->begin();
1065 t->normal(1, 0, 0);
1066 renderEast(tt, 0, 0, 0, getTexture(tt, 5, data));
1067 t->end();
1068 }
1069 else
1070 {
1071 tesselateBlockInWorld(tt, x, y, z);
1072 }
1073#endif // DISABLE_TESS_FUNCS
1074
1075 return bottom + height;
1076}
1077
1078
1079bool TileRenderer_SPU::tesselateTorchInWorld( Tile_SPU* tt, int x, int y, int z )
1080{
1081 int dir = level->getData( x, y, z );
1082
1083 Tesselator_SPU* t = getTesselator();
1084
1085 if ( SharedConstants::TEXTURE_LIGHTING )
1086 {
1087 t->tex2( tt->getLightColor( level, x, y, z ) );
1088 t->color( 1.0f, 1.0f, 1.0f );
1089 }
1090 else
1091 {
1092 float br = tt->getBrightness( level, x, y, z );
1093 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
1094 t->color( br, br, br );
1095 }
1096
1097 float r = 0.40f;
1098 float r2 = 0.5f - r;
1099 float h = 0.20f;
1100 if ( dir == 1 )
1101 {
1102 tesselateTorch( tt, (float)x - r2, (float)y + h, (float)z, -r, 0.0f, 0 );
1103 }
1104 else if ( dir == 2 )
1105 {
1106 tesselateTorch( tt, (float)x + r2, (float)y + h, (float)z, +r, 0.0f, 0 );
1107 }
1108 else if ( dir == 3 )
1109 {
1110 tesselateTorch( tt, (float)x, (float)y + h, z - r2, 0.0f, -r, 0 );
1111 }
1112 else if ( dir == 4 )
1113 {
1114 tesselateTorch( tt, (float)x, (float)y + h, (float)z + r2, 0.0f, +r, 0 );
1115 }
1116 else
1117 {
1118 tesselateTorch( tt, (float)x, (float)y, (float)z, 0.0f, 0.0f, 0 );
1119 }
1120 return true;
1121
1122}
1123
1124bool TileRenderer_SPU::tesselateDiodeInWorld(DiodeTile_SPU *tt, int x, int y, int z)
1125{
1126#ifdef DISABLE_TESS_FUNCS
1127 Tesselator_SPU* t = getTesselator();
1128
1129 tesselateDiodeInWorld(tt, x, y, z, level->getData(x, y, z) & DiodeTile_SPU::DIRECTION_MASK);
1130 return true;
1131#endif // #ifdef DISABLE_TESS_FUNCS
1132 return false;
1133}
1134
1135void TileRenderer_SPU::tesselateDiodeInWorld( DiodeTile_SPU* tt, int x, int y, int z, int dir )
1136{
1137#ifdef DISABLE_TESS_FUNCS
1138 // render half-block edges
1139 tesselateBlockInWorld( tt, x, y, z );
1140
1141 Tesselator_SPU* t = getTesselator();
1142
1143 if ( SharedConstants::TEXTURE_LIGHTING )
1144 {
1145 t->tex2( tt->getLightColor( level, x, y, z ) );
1146 t->color( 1.0f, 1.0f, 1.0f );
1147 }
1148 else
1149 {
1150 float br = tt->getBrightness( level, x, y, z );
1151 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
1152 t->color( br, br, br );
1153 }
1154
1155 int data = level->getData(x, y, z);
1156
1157 // 4J Stu - This block gets moved in a later version, but we don't need that yet
1158 // BEGIN TORCH SECTION
1159 {
1160 int dir = data & DiodeTile_SPU::DIRECTION_MASK;
1161 int delay = ( data & DiodeTile_SPU::DELAY_MASK ) >> DiodeTile_SPU::DELAY_SHIFT;
1162 float h = -3.0f / 16.0f;
1163 float transmitterX = 0.0f;
1164 float transmitterZ = 0.0f;
1165 float receiverX = 0.0f;
1166 float receiverZ = 0.0f;
1167
1168 switch ( dir )
1169 {
1170 case Direction::SOUTH:
1171 receiverZ = -5.0f / 16.0f;
1172 transmitterZ = DiodeTile_SPU::DELAY_RENDER_OFFSETS[delay];
1173 break;
1174 case Direction::NORTH:
1175 receiverZ = 5.0f / 16.0f;
1176 transmitterZ = -DiodeTile_SPU::DELAY_RENDER_OFFSETS[delay];
1177 break;
1178 case Direction::EAST:
1179 receiverX = -5.0f / 16.0f;
1180 transmitterX = DiodeTile_SPU::DELAY_RENDER_OFFSETS[delay];
1181 break;
1182 case Direction::WEST:
1183 receiverX = 5.0f / 16.0f;
1184 transmitterX = -DiodeTile_SPU::DELAY_RENDER_OFFSETS[delay];
1185 break;
1186 }
1187
1188 // render transmitter
1189 tesselateTorch( tt, x + transmitterX, y + h, z + transmitterZ, 0.0f, 0.0f, 0 );
1190 // render receiver
1191 tesselateTorch( tt, x + receiverX, y + h, z + receiverZ, 0.0f, 0.0f, 0 );
1192 }
1193 // END TORCH SECTION
1194
1195 Icon_SPU *tex = getTexture(tt, Facing::UP, data);
1196 float u0 = tex->getU0();
1197 float u1 = tex->getU1();
1198 float v0 = tex->getV0();
1199 float v1 = tex->getV1();
1200
1201 float r = 2.0f / 16.0f;
1202
1203 float x0 = ( float )( x + 1.0f );
1204 float x1 = ( float )( x + 1.0f );
1205 float x2 = ( float )( x + 0.0f );
1206 float x3 = ( float )( x + 0.0f );
1207
1208 float z0 = ( float )( z + 0.0f );
1209 float z1 = ( float )( z + 1.0f );
1210 float z2 = ( float )( z + 1.0f );
1211 float z3 = ( float )( z + 0.0f );
1212
1213 float y0 = ( float )( y + r );
1214
1215 if ( dir == Direction::NORTH )
1216 {
1217 // rotate 180 degrees
1218 x0 = x1 = ( float )( x + 0.0f );
1219 x2 = x3 = ( float )( x + 1.0f );
1220 z0 = z3 = ( float )( z + 1.0f );
1221 z1 = z2 = ( float )( z + 0.0f );
1222 }
1223 else if ( dir == Direction::EAST )
1224 {
1225 // rotate 90 degrees counter-clockwise
1226 x0 = x3 = ( float )( x + 0.0f );
1227 x1 = x2 = ( float )( x + 1.0f );
1228 z0 = z1 = ( float )( z + 0.0f );
1229 z2 = z3 = ( float )( z + 1.0f );
1230 }
1231 else if ( dir == Direction::WEST )
1232 {
1233 // rotate 90 degrees clockwise
1234 x0 = x3 = ( float )( x + 1.0f );
1235 x1 = x2 = ( float )( x + 0.0f );
1236 z0 = z1 = ( float )( z + 1.0f );
1237 z2 = z3 = ( float )( z + 0.0f );
1238 }
1239
1240 t->vertexUV( x3 , y0 , z3 , u0 , v0 );
1241 t->vertexUV( x2 , y0 , z2 , u0 , v1 );
1242 t->vertexUV( x1 , y0 , z1 , u1 , v1 );
1243 t->vertexUV( x0 , y0 , z0 , u1 , v0 );
1244#endif // #ifdef DISABLE_TESS_FUNCS
1245}
1246
1247void TileRenderer_SPU::tesselatePistonBaseForceExtended( Tile_SPU* tile, int x, int y, int z, int forceData ) // 4J added forceData param
1248{
1249#ifdef DISABLE_TESS_FUNCS
1250 noCulling = true;
1251 tesselatePistonBaseInWorld( tile, x, y, z, true, forceData );
1252 noCulling = false;
1253#endif // DISABLE_TESS_FUNCS
1254
1255}
1256
1257bool TileRenderer_SPU::tesselatePistonBaseInWorld( Tile_SPU* tt, int x, int y, int z, bool forceExtended, int forceData ) // 4J added forceData param
1258{
1259#ifdef DISABLE_TESS_FUNCS
1260 int data = ( forceData == -1 ) ? level->getData( x, y, z ) : forceData;
1261 bool extended = forceExtended || ( data & PistonBaseTile::EXTENDED_BIT ) != 0;
1262 int facing = PistonBaseTile::getFacing( data );
1263
1264 const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
1265
1266// EnterCriticalSection( &Tile_SPU::m_csShape );
1267 if ( extended )
1268 {
1269 switch ( facing )
1270 {
1271 case Facing::DOWN:
1272 northFlip = FLIP_180;
1273 southFlip = FLIP_180;
1274 eastFlip = FLIP_180;
1275 westFlip = FLIP_180;
1276 setShape( 0.0f, thickness, 0.0f, 1.0f, 1.0f, 1.0f );
1277 break;
1278 case Facing::UP:
1279 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f - thickness, 1.0f );
1280 break;
1281 case Facing::NORTH:
1282 eastFlip = FLIP_CW;
1283 westFlip = FLIP_CCW;
1284 setShape( 0.0f, 0.0f, thickness, 1.0f, 1.0f, 1.0f );
1285 break;
1286 case Facing::SOUTH:
1287 eastFlip = FLIP_CCW;
1288 westFlip = FLIP_CW;
1289 upFlip = FLIP_180;
1290 downFlip = FLIP_180;
1291 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f - thickness );
1292 break;
1293 case Facing::WEST:
1294 northFlip = FLIP_CW;
1295 southFlip = FLIP_CCW;
1296 upFlip = FLIP_CCW;
1297 downFlip = FLIP_CW;
1298 setShape( thickness, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f );
1299 break;
1300 case Facing::EAST:
1301 northFlip = FLIP_CCW;
1302 southFlip = FLIP_CW;
1303 upFlip = FLIP_CW;
1304 downFlip = FLIP_CCW;
1305 setShape( 0.0f, 0.0f, 0.0f, 1.0f - thickness, 1.0f, 1.0f );
1306 break;
1307 }
1308 // weird way of telling the piston to use the
1309 // "inside" texture for the forward-facing edge
1310 ((PistonBaseTile *) tt)->updateShape((float) tileShapeX0, (float) tileShapeY0, (float) tileShapeZ0, (float) tileShapeX1, (float) tileShapeY1, (float) tileShapeZ1);
1311 tesselateBlockInWorld( tt, x, y, z );
1312 northFlip = FLIP_NONE;
1313 southFlip = FLIP_NONE;
1314 eastFlip = FLIP_NONE;
1315 westFlip = FLIP_NONE;
1316 upFlip = FLIP_NONE;
1317 downFlip = FLIP_NONE;
1318 ((PistonBaseTile *) tt)->updateShape((float) tileShapeX0, (float) tileShapeY0, (float) tileShapeZ0, (float) tileShapeX1, (float) tileShapeY1, (float) tileShapeZ1);
1319 }
1320 else
1321 {
1322 switch ( facing )
1323 {
1324 case Facing::DOWN:
1325 northFlip = FLIP_180;
1326 southFlip = FLIP_180;
1327 eastFlip = FLIP_180;
1328 westFlip = FLIP_180;
1329 break;
1330 case Facing::UP:
1331 break;
1332 case Facing::NORTH:
1333 eastFlip = FLIP_CW;
1334 westFlip = FLIP_CCW;
1335 break;
1336 case Facing::SOUTH:
1337 eastFlip = FLIP_CCW;
1338 westFlip = FLIP_CW;
1339 upFlip = FLIP_180;
1340 downFlip = FLIP_180;
1341 break;
1342 case Facing::WEST:
1343 northFlip = FLIP_CW;
1344 southFlip = FLIP_CCW;
1345 upFlip = FLIP_CCW;
1346 downFlip = FLIP_CW;
1347 break;
1348 case Facing::EAST:
1349 northFlip = FLIP_CCW;
1350 southFlip = FLIP_CW;
1351 upFlip = FLIP_CW;
1352 downFlip = FLIP_CCW;
1353 break;
1354 }
1355 tesselateBlockInWorld( tt, x, y, z );
1356 northFlip = FLIP_NONE;
1357 southFlip = FLIP_NONE;
1358 eastFlip = FLIP_NONE;
1359 westFlip = FLIP_NONE;
1360 upFlip = FLIP_NONE;
1361 downFlip = FLIP_NONE;
1362 }
1363
1364// LeaveCriticalSection( &Tile_SPU::m_csShape );
1365#endif // DISABLE_TESS_FUNCS
1366
1367 return true;
1368
1369}
1370
1371void TileRenderer_SPU::renderPistonArmUpDown( float x0, float x1, float y0, float y1, float z0, float z1, float br,
1372 float armLengthPixels )
1373{
1374#ifdef DISABLE_TESS_FUNCS
1375 Icon_SPU *armTex = PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX);
1376 if (hasFixedTexture()) armTex = fixedTexture;
1377
1378 Tesselator_SPU* t = getTesselator();
1379
1380 // upwards arm
1381 float u00 = armTex->getU0();
1382 float v00 = armTex->getV0();
1383 float u11 = armTex->getU(armLengthPixels);
1384 float v11 = armTex->getV(PistonBaseTile::PLATFORM_THICKNESS);
1385
1386 t->color( br, br, br );
1387
1388 t->vertexUV( x0, y1, z0, u11, v00 );
1389 t->vertexUV( x0, y0, z0, u00, v00 );
1390 t->vertexUV( x1, y0, z1, u00, v11 );
1391 t->vertexUV( x1, y1, z1, u11, v11 );
1392#endif // DISABLE_TESS_FUNCS
1393
1394}
1395
1396void TileRenderer_SPU::renderPistonArmNorthSouth( float x0, float x1, float y0, float y1, float z0, float z1,
1397 float br, float armLengthPixels )
1398{
1399#ifdef DISABLE_TESS_FUNCS
1400 Icon_SPU *armTex = PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX);
1401 if (hasFixedTexture()) armTex = fixedTexture;
1402
1403 Tesselator_SPU* t = getTesselator();
1404
1405 // upwards arm
1406 float u00 = armTex->getU0();
1407 float v00 = armTex->getV0();
1408 float u11 = armTex->getU(armLengthPixels);
1409 float v11 = armTex->getV(PistonBaseTile::PLATFORM_THICKNESS);
1410
1411 t->color( br, br, br );
1412
1413 t->vertexUV( x0, y0, z1, u11, v00 );
1414 t->vertexUV( x0, y0, z0, u00, v00 );
1415 t->vertexUV( x1, y1, z0, u00, v11 );
1416 t->vertexUV( x1, y1, z1, u11, v11 );
1417#endif // DISABLE_TESS_FUNCS
1418}
1419
1420void TileRenderer_SPU::renderPistonArmEastWest( float x0, float x1, float y0, float y1, float z0, float z1, float br,
1421 float armLengthPixels )
1422{
1423#ifdef DISABLE_TESS_FUNCS
1424 Icon_SPU *armTex = PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX);
1425 if (hasFixedTexture()) armTex = fixedTexture;
1426
1427 Tesselator_SPU* t = getTesselator();
1428
1429 // upwards arm
1430 float u00 = armTex->getU0();
1431 float v00 = armTex->getV0();
1432 float u11 = armTex->getU(armLengthPixels);
1433 float v11 = armTex->getV(PistonBaseTile::PLATFORM_THICKNESS);
1434
1435 t->color( br, br, br );
1436
1437 t->vertexUV( x1, y0, z0, u11, v00 );
1438 t->vertexUV( x0, y0, z0, u00, v00 );
1439 t->vertexUV( x0, y1, z1, u00, v11 );
1440 t->vertexUV( x1, y1, z1, u11, v11 );
1441#endif // DISABLE_TESS_FUNCS
1442}
1443
1444void TileRenderer_SPU::tesselatePistonArmNoCulling( Tile_SPU* tile, int x, int y, int z, bool fullArm, int forceData ) // 4J added forceData param
1445{
1446#ifdef DISABLE_TESS_FUNCS
1447 noCulling = true;
1448 tesselatePistonExtensionInWorld( tile, x, y, z, fullArm );
1449 noCulling = false;
1450#endif // DISABLE_TESS_FUNCS
1451}
1452
1453bool TileRenderer_SPU::tesselatePistonExtensionInWorld( Tile_SPU* tt, int x, int y, int z, bool fullArm, int forceData ) // 4J added forceData param
1454{
1455#ifdef DISABLE_TESS_FUNCS
1456 int data = ( forceData == -1 ) ? level->getData( x, y, z ) : forceData;
1457 int facing = PistonExtensionTile::getFacing( data );
1458
1459 const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
1460 const float leftEdge = ( 8.0f - ( PistonBaseTile::PLATFORM_THICKNESS / 2.0f ) ) / 16.0f;
1461 const float rightEdge = ( 8.0f + ( PistonBaseTile::PLATFORM_THICKNESS / 2.0f ) ) / 16.0f;
1462 const float br = tt->getBrightness( level, x, y, z );
1463 const float armLength = fullArm ? 1.0f : 0.5f;
1464 const float armLengthPixels = fullArm ? 16.0f : 8.0f;
1465
1466// EnterCriticalSection( &Tile_SPU::m_csShape );
1467 Tesselator_SPU* t = getTesselator();
1468
1469 switch ( facing )
1470 {
1471 case Facing::DOWN:
1472 northFlip = FLIP_180;
1473 southFlip = FLIP_180;
1474 eastFlip = FLIP_180;
1475 westFlip = FLIP_180;
1476 setShape( 0.0f, 0.0f, 0.0f, 1.0f, thickness, 1.0f );
1477 tesselateBlockInWorld( tt, x, y, z );
1478
1479 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1480 renderPistonArmUpDown( x + leftEdge, x + rightEdge, y + thickness, y + thickness + armLength,
1481 z + rightEdge, z + rightEdge, br * 0.8f, armLengthPixels );
1482 renderPistonArmUpDown( x + rightEdge, x + leftEdge, y + thickness, y + thickness + armLength, z + leftEdge,
1483 z + leftEdge, br * 0.8f, armLengthPixels );
1484 renderPistonArmUpDown( x + leftEdge, x + leftEdge, y + thickness, y + thickness + armLength, z + leftEdge,
1485 z + rightEdge, br * 0.6f, armLengthPixels );
1486 renderPistonArmUpDown( x + rightEdge, x + rightEdge, y + thickness, y + thickness + armLength,
1487 z + rightEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1488
1489 break;
1490 case Facing::UP:
1491 setShape( 0.0f, 1.0f - thickness, 0.0f, 1.0f, 1.0f, 1.0f );
1492 tesselateBlockInWorld( tt, x, y, z );
1493
1494 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1495 renderPistonArmUpDown( x + leftEdge, x + rightEdge, y - thickness + 1.0f - armLength, y - thickness + 1.0f,
1496 z + rightEdge, z + rightEdge, br * 0.8f, armLengthPixels );
1497 renderPistonArmUpDown( x + rightEdge, x + leftEdge, y - thickness + 1.0f - armLength, y - thickness + 1.0f,
1498 z + leftEdge, z + leftEdge, br * 0.8f, armLengthPixels );
1499 renderPistonArmUpDown( x + leftEdge, x + leftEdge, y - thickness + 1.0f - armLength, y - thickness + 1.0f,
1500 z + leftEdge, z + rightEdge, br * 0.6f, armLengthPixels );
1501 renderPistonArmUpDown( x + rightEdge, x + rightEdge, y - thickness + 1.0f - armLength,
1502 y - thickness + 1.0f, z + rightEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1503 break;
1504 case Facing::NORTH:
1505 eastFlip = FLIP_CW;
1506 westFlip = FLIP_CCW;
1507 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, thickness );
1508 tesselateBlockInWorld( tt, x, y, z );
1509
1510 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1511 renderPistonArmNorthSouth( x + leftEdge, x + leftEdge, y + rightEdge, y + leftEdge, z + thickness,
1512 z + thickness + armLength, br * 0.6f, armLengthPixels );
1513 renderPistonArmNorthSouth( x + rightEdge, x + rightEdge, y + leftEdge, y + rightEdge, z + thickness,
1514 z + thickness + armLength, br * 0.6f, armLengthPixels );
1515 renderPistonArmNorthSouth( x + leftEdge, x + rightEdge, y + leftEdge, y + leftEdge, z + thickness,
1516 z + thickness + armLength, br * 0.5f, armLengthPixels );
1517 renderPistonArmNorthSouth( x + rightEdge, x + leftEdge, y + rightEdge, y + rightEdge, z + thickness,
1518 z + thickness + armLength, br, armLengthPixels );
1519 break;
1520 case Facing::SOUTH:
1521 eastFlip = FLIP_CCW;
1522 westFlip = FLIP_CW;
1523 upFlip = FLIP_180;
1524 downFlip = FLIP_180;
1525 setShape( 0.0f, 0.0f, 1.0f - thickness, 1.0f, 1.0f, 1.0f );
1526 tesselateBlockInWorld( tt, x, y, z );
1527
1528 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1529 renderPistonArmNorthSouth( x + leftEdge, x + leftEdge, y + rightEdge, y + leftEdge,
1530 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br * 0.6f,
1531 armLengthPixels );
1532 renderPistonArmNorthSouth( x + rightEdge, x + rightEdge, y + leftEdge, y + rightEdge,
1533 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br * 0.6f,
1534 armLengthPixels );
1535 renderPistonArmNorthSouth( x + leftEdge, x + rightEdge, y + leftEdge, y + leftEdge,
1536 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br * 0.5f,
1537 armLengthPixels );
1538 renderPistonArmNorthSouth( x + rightEdge, x + leftEdge, y + rightEdge, y + rightEdge,
1539 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br, armLengthPixels );
1540 break;
1541 case Facing::WEST:
1542 northFlip = FLIP_CW;
1543 southFlip = FLIP_CCW;
1544 upFlip = FLIP_CCW;
1545 downFlip = FLIP_CW;
1546 setShape( 0.0f, 0.0f, 0.0f, thickness, 1.0f, 1.0f );
1547 tesselateBlockInWorld( tt, x, y, z ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1548
1549 t->tex2( getLightColor(tt, level, x, y , z ) );
1550 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + leftEdge, y + leftEdge,
1551 z + rightEdge, z + leftEdge, br * 0.5f, armLengthPixels );
1552 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + rightEdge, y + rightEdge,
1553 z + leftEdge, z + rightEdge, br, armLengthPixels );
1554 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + leftEdge, y + rightEdge,
1555 z + leftEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1556 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + rightEdge, y + leftEdge,
1557 z + rightEdge, z + rightEdge, br * 0.6f, armLengthPixels );
1558 break;
1559 case Facing::EAST:
1560 northFlip = FLIP_CCW;
1561 southFlip = FLIP_CW;
1562 upFlip = FLIP_CW;
1563 downFlip = FLIP_CCW;
1564 setShape( 1.0f - thickness, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f );
1565 tesselateBlockInWorld( tt, x, y, z );
1566
1567 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1568 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + leftEdge,
1569 y + leftEdge, z + rightEdge, z + leftEdge, br * 0.5f, armLengthPixels );
1570 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + rightEdge,
1571 y + rightEdge, z + leftEdge, z + rightEdge, br, armLengthPixels );
1572 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + leftEdge,
1573 y + rightEdge, z + leftEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1574 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + rightEdge,
1575 y + leftEdge, z + rightEdge, z + rightEdge, br * 0.6f, armLengthPixels );
1576 break;
1577 }
1578 northFlip = FLIP_NONE;
1579 southFlip = FLIP_NONE;
1580 eastFlip = FLIP_NONE;
1581 westFlip = FLIP_NONE;
1582 upFlip = FLIP_NONE;
1583 downFlip = FLIP_NONE;
1584 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f );
1585
1586// LeaveCriticalSection( &Tile_SPU::m_csShape );
1587#endif // DISABLE_TESS_FUNCS
1588
1589 return true;
1590
1591}
1592
1593bool TileRenderer_SPU::tesselateLeverInWorld( Tile_SPU* tt, int x, int y, int z )
1594{
1595#ifdef DISABLE_TESS_FUNCS
1596 int data = level->getData( x, y, z );
1597
1598 int dir = data & 7;
1599 bool flipped = ( data & 8 ) > 0;
1600
1601 Tesselator_SPU* t = getTesselator();
1602
1603 bool hadFixed = hasFixedTexture();
1604 if (!hadFixed) this->setFixedTexture(getTexture(Tile_SPU::stoneBrick));
1605 float w1 = 4.0f / 16.0f;
1606 float w2 = 3.0f / 16.0f;
1607 float h = 3.0f / 16.0f;
1608// EnterCriticalSection( &Tile_SPU::m_csShape );
1609 if ( dir == 5 )
1610 {
1611 setShape( 0.5f - w2, 0.0f, 0.5f - w1, 0.5f + w2, h, 0.5f + w1 );
1612 }
1613 else if ( dir == 6 )
1614 {
1615 setShape( 0.5f - w1, 0.0f, 0.5f - w2, 0.5f + w1, h, 0.5f + w2 );
1616 }
1617 else if ( dir == 4 )
1618 {
1619 setShape( 0.5f - w2, 0.5f - w1, 1.0f - h, 0.5f + w2, 0.5f + w1, 1.0f );
1620 }
1621 else if ( dir == 3 )
1622 {
1623 setShape( 0.5f - w2, 0.5f - w1, 0, 0.5f + w2, 0.5f + w1, h );
1624 }
1625 else if ( dir == 2 )
1626 {
1627 setShape( 1.0f - h, 0.5f - w1, 0.5f - w2, 1.0f, 0.5f + w1, 0.5f + w2 );
1628 }
1629 else if ( dir == 1 )
1630 {
1631 setShape( 0, 0.5f - w1, 0.5f - w2, h, 0.5f + w1, 0.5f + w2 );
1632 }
1633 else if (dir == 0)
1634 {
1635 setShape(0.5f - w1, 1 - h, 0.5f - w2, 0.5f + w1, 1, 0.5f + w2);
1636 }
1637 else if (dir == 7)
1638 {
1639 setShape(0.5f - w2, 1 - h, 0.5f - w1, 0.5f + w2, 1, 0.5f + w1);
1640 }
1641 this->tesselateBlockInWorld( tt, x, y, z );
1642// LeaveCriticalSection( &Tile_SPU::m_csShape );
1643 if ( !hadFixed ) this->clearFixedTexture();
1644
1645 float br;
1646 if ( SharedConstants::TEXTURE_LIGHTING )
1647 {
1648 t->tex2( tt->getLightColor( level, x, y, z ) );
1649 br = 1;
1650 }
1651 else
1652 {
1653 br = tt->getBrightness( level, x, y, z );
1654 }
1655 if ( Tile_SPU::lightEmission[tt->id] > 0 ) br = 1.0f;
1656 t->color( br, br, br );
1657 Icon_SPU *tex = getTexture(tt, 0);
1658
1659 if (hasFixedTexture()) tex = fixedTexture;
1660 float u0 = tex->getU0();
1661 float v0 = tex->getV0();
1662 float u1 = tex->getU1();
1663 float v1 = tex->getV1();
1664
1665 Vec3* corners[8];
1666 float xv = 1.0f / 16.0f;
1667 float zv = 1.0f / 16.0f;
1668 float yv = 10.0f / 16.0f;
1669 corners[0] = Vec3::newTemp( -xv, -0, -zv );
1670 corners[1] = Vec3::newTemp( +xv, -0, -zv );
1671 corners[2] = Vec3::newTemp( +xv, -0, +zv );
1672 corners[3] = Vec3::newTemp( -xv, -0, +zv );
1673 corners[4] = Vec3::newTemp( -xv, +yv, -zv );
1674 corners[5] = Vec3::newTemp( +xv, +yv, -zv );
1675 corners[6] = Vec3::newTemp( +xv, +yv, +zv );
1676 corners[7] = Vec3::newTemp( -xv, +yv, +zv );
1677
1678 for ( int i = 0; i < 8; i++ )
1679 {
1680 if ( flipped )
1681 {
1682 corners[i]->z -= 1 / 16.0f;
1683 corners[i]->xRot( 40 * PI / 180 );
1684 }
1685 else
1686 {
1687 corners[i]->z += 1 / 16.0f;
1688 corners[i]->xRot( -40 * PI / 180 );
1689 }
1690 if (dir == 0 || dir == 7)
1691 {
1692 corners[i]->zRot(180 * PI / 180);
1693 }
1694 if ( dir == 6 || dir == 0 )
1695 {
1696 corners[i]->yRot( 90 * PI / 180 );
1697 }
1698
1699 if ( dir > 0 && dir < 5 )
1700 {
1701 corners[i]->y -= 6 / 16.0f;
1702 corners[i]->xRot( 90 * PI / 180 );
1703
1704 if ( dir == 4 ) corners[i]->yRot( 0 * PI / 180 );
1705 if ( dir == 3 ) corners[i]->yRot( 180 * PI / 180 );
1706 if ( dir == 2 ) corners[i]->yRot( 90 * PI / 180 );
1707 if ( dir == 1 ) corners[i]->yRot( -90 * PI / 180 );
1708
1709 corners[i]->x += x + 0.5;
1710 corners[i]->y += y + 8 / 16.0f;
1711 corners[i]->z += z + 0.5;
1712 }
1713 else if (dir == 0 || dir == 7)
1714 {
1715 corners[i]->x += x + 0.5;
1716 corners[i]->y += y + 14 / 16.0f;
1717 corners[i]->z += z + 0.5;
1718 }
1719 else
1720 {
1721 corners[i]->x += x + 0.5;
1722 corners[i]->y += y + 2 / 16.0f;
1723 corners[i]->z += z + 0.5;
1724 }
1725 }
1726
1727 Vec3* c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;
1728 for ( int i = 0; i < 6; i++ )
1729 {
1730 if ( i == 0 )
1731 {
1732 u0 = tex->getU(7);
1733 v0 = tex->getV(6);
1734 u1 = tex->getU(9);
1735 v1 = tex->getV(8);
1736 }
1737 else if ( i == 2 )
1738 {
1739 u0 = tex->getU(7);
1740 v0 = tex->getV(6);
1741 u1 = tex->getU(9);
1742 v1 = tex->getV1();
1743 }
1744 if ( i == 0 )
1745 {
1746 c0 = corners[0];
1747 c1 = corners[1];
1748 c2 = corners[2];
1749 c3 = corners[3];
1750 }
1751 else if ( i == 1 )
1752 {
1753 c0 = corners[7];
1754 c1 = corners[6];
1755 c2 = corners[5];
1756 c3 = corners[4];
1757 }
1758 else if ( i == 2 )
1759 {
1760 c0 = corners[1];
1761 c1 = corners[0];
1762 c2 = corners[4];
1763 c3 = corners[5];
1764 }
1765 else if ( i == 3 )
1766 {
1767 c0 = corners[2];
1768 c1 = corners[1];
1769 c2 = corners[5];
1770 c3 = corners[6];
1771 }
1772 else if ( i == 4 )
1773 {
1774 c0 = corners[3];
1775 c1 = corners[2];
1776 c2 = corners[6];
1777 c3 = corners[7];
1778 }
1779 else if ( i == 5 )
1780 {
1781 c0 = corners[0];
1782 c1 = corners[3];
1783 c2 = corners[7];
1784 c3 = corners[4];
1785 }
1786 t->vertexUV( ( float )( c0->x ), ( float )( c0->y ), ( float )( c0->z ), ( float )( u0 ), ( float )( v1 ) );
1787 t->vertexUV( ( float )( c1->x ), ( float )( c1->y ), ( float )( c1->z ), ( float )( u1 ), ( float )( v1 ) );
1788 t->vertexUV( ( float )( c2->x ), ( float )( c2->y ), ( float )( c2->z ), ( float )( u1 ), ( float )( v0 ) );
1789 t->vertexUV( ( float )( c3->x ), ( float )( c3->y ), ( float )( c3->z ), ( float )( u0 ), ( float )( v0 ) );
1790 }
1791#endif // DISABLE_TESS_FUNCS
1792 return true;
1793
1794}
1795
1796bool TileRenderer_SPU::tesselateTripwireSourceInWorld(Tile_SPU *tt, int x, int y, int z)
1797{
1798#ifdef DISABLE_TESS_FUNCS
1799 Tesselator *t = Tesselator::getInstance();
1800 int data = level->getData(x, y, z);
1801 int dir = data & TripWireSourceTile::MASK_DIR;
1802 bool attached = (data & TripWireSourceTile::MASK_ATTACHED) == TripWireSourceTile::MASK_ATTACHED;
1803 bool powered = (data & TripWireSourceTile::MASK_POWERED) == TripWireSourceTile::MASK_POWERED;
1804 bool suspended = !level->isTopSolidBlocking(x, y - 1, z);
1805
1806 bool hadFixed = hasFixedTexture();
1807 if (!hadFixed) this->setFixedTexture(getTexture(Tile::wood));
1808
1809 float boxHeight = 4 / 16.0f;
1810 float boxWidth = 2 / 16.0f;
1811 float boxDepth = 2 / 16.0f;
1812
1813 float boxy0 = 0.3f - boxHeight;
1814 float boxy1 = 0.3f + boxHeight;
1815 if (dir == Direction::NORTH)
1816 {
1817 setShape(0.5f - boxWidth, boxy0, 1 - boxDepth, 0.5f + boxWidth, boxy1, 1);
1818 }
1819 else if (dir == Direction::SOUTH)
1820 {
1821 setShape(0.5f - boxWidth, boxy0, 0, 0.5f + boxWidth, boxy1, boxDepth);
1822 }
1823 else if (dir == Direction::WEST)
1824 {
1825 setShape(1 - boxDepth, boxy0, 0.5f - boxWidth, 1, boxy1, 0.5f + boxWidth);
1826 }
1827 else if (dir == Direction::EAST)
1828 {
1829 setShape(0, boxy0, 0.5f - boxWidth, boxDepth, boxy1, 0.5f + boxWidth);
1830 }
1831
1832 this->tesselateBlockInWorld(tt, x, y, z);
1833 if (!hadFixed) this->clearFixedTexture();
1834
1835 float brightness;
1836 if (SharedConstants::TEXTURE_LIGHTING)
1837 {
1838 t->tex2(tt->getLightColor(level, x, y, z));
1839 brightness = 1;
1840 }
1841 else
1842 {
1843 brightness = tt->getBrightness(level, x, y, z);
1844 }
1845 if (Tile::lightEmission[tt->id] > 0) brightness = 1.0f;
1846 t->color(brightness, brightness, brightness);
1847 Icon *tex = getTexture(tt, 0);
1848
1849 if (hasFixedTexture()) tex = fixedTexture;
1850 double u0 = tex->getU0();
1851 double v0 = tex->getV0();
1852 double u1 = tex->getU1();
1853 double v1 = tex->getV1();
1854
1855 Vec3 *corners[8];
1856 float stickWidth = 0.75f / 16.0f;
1857 float stickHeight = 0.75f / 16.0f;
1858 float stickLength = 5 / 16.0f;
1859 corners[0] = Vec3::newTemp(-stickWidth, -0, -stickHeight);
1860 corners[1] = Vec3::newTemp(+stickWidth, -0, -stickHeight);
1861 corners[2] = Vec3::newTemp(+stickWidth, -0, +stickHeight);
1862 corners[3] = Vec3::newTemp(-stickWidth, -0, +stickHeight);
1863 corners[4] = Vec3::newTemp(-stickWidth, +stickLength, -stickHeight);
1864 corners[5] = Vec3::newTemp(+stickWidth, +stickLength, -stickHeight);
1865 corners[6] = Vec3::newTemp(+stickWidth, +stickLength, +stickHeight);
1866 corners[7] = Vec3::newTemp(-stickWidth, +stickLength, +stickHeight);
1867
1868 for (int i = 0; i < 8; i++)
1869 {
1870 corners[i]->z += 1 / 16.0f;
1871
1872 if (powered)
1873 {
1874 corners[i]->xRot(30 * PI / 180);
1875 corners[i]->y -= 7 / 16.0f;
1876 }
1877 else if (attached)
1878 {
1879 corners[i]->xRot(5 * PI / 180);
1880 corners[i]->y -= 7 / 16.0f;
1881 }
1882 else
1883 {
1884 corners[i]->xRot(-40 * PI / 180);
1885 corners[i]->y -= 6 / 16.0f;
1886 }
1887
1888 corners[i]->xRot(90 * PI / 180);
1889
1890 if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180);
1891 if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180);
1892 if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180);
1893 if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180);
1894
1895 corners[i]->x += x + 0.5;
1896 corners[i]->y += y + 5 / 16.0f;
1897 corners[i]->z += z + 0.5;
1898 }
1899
1900 Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;
1901 int stickX0 = 7;
1902 int stickX1 = 9;
1903 int stickY0 = 9;
1904 int stickY1 = 16;
1905
1906 for (int i = 0; i < 6; i++)
1907 {
1908 if (i == 0)
1909 {
1910 c0 = corners[0];
1911 c1 = corners[1];
1912 c2 = corners[2];
1913 c3 = corners[3];
1914 u0 = tex->getU(stickX0);
1915 v0 = tex->getV(stickY0);
1916 u1 = tex->getU(stickX1);
1917 v1 = tex->getV(stickY0 + 2);
1918 }
1919 else if (i == 1)
1920 {
1921 c0 = corners[7];
1922 c1 = corners[6];
1923 c2 = corners[5];
1924 c3 = corners[4];
1925 }
1926 else if (i == 2)
1927 {
1928 c0 = corners[1];
1929 c1 = corners[0];
1930 c2 = corners[4];
1931 c3 = corners[5];
1932 u0 = tex->getU(stickX0);
1933 v0 = tex->getV(stickY0);
1934 u1 = tex->getU(stickX1);
1935 v1 = tex->getV(stickY1);
1936 }
1937 else if (i == 3)
1938 {
1939 c0 = corners[2];
1940 c1 = corners[1];
1941 c2 = corners[5];
1942 c3 = corners[6];
1943 }
1944 else if (i == 4)
1945 {
1946 c0 = corners[3];
1947 c1 = corners[2];
1948 c2 = corners[6];
1949 c3 = corners[7];
1950 }
1951 else if (i == 5)
1952 {
1953 c0 = corners[0];
1954 c1 = corners[3];
1955 c2 = corners[7];
1956 c3 = corners[4];
1957 }
1958 t->vertexUV(c0->x, c0->y, c0->z, u0, v1);
1959 t->vertexUV(c1->x, c1->y, c1->z, u1, v1);
1960 t->vertexUV(c2->x, c2->y, c2->z, u1, v0);
1961 t->vertexUV(c3->x, c3->y, c3->z, u0, v0);
1962 }
1963
1964
1965 float hoopWidth = 1.5f / 16.0f;
1966 float hoopHeight = 1.5f / 16.0f;
1967 float hoopLength = 0.5f / 16.0f;
1968 corners[0] = Vec3::newTemp(-hoopWidth, -0, -hoopHeight);
1969 corners[1] = Vec3::newTemp(+hoopWidth, -0, -hoopHeight);
1970 corners[2] = Vec3::newTemp(+hoopWidth, -0, +hoopHeight);
1971 corners[3] = Vec3::newTemp(-hoopWidth, -0, +hoopHeight);
1972 corners[4] = Vec3::newTemp(-hoopWidth, +hoopLength, -hoopHeight);
1973 corners[5] = Vec3::newTemp(+hoopWidth, +hoopLength, -hoopHeight);
1974 corners[6] = Vec3::newTemp(+hoopWidth, +hoopLength, +hoopHeight);
1975 corners[7] = Vec3::newTemp(-hoopWidth, +hoopLength, +hoopHeight);
1976
1977 for (int i = 0; i < 8; i++)
1978 {
1979 corners[i]->z += 3.5f / 16.0f;
1980
1981 if (powered)
1982 {
1983 corners[i]->y -= 1.5 / 16.0f;
1984 corners[i]->z -= 2.6 / 16.0f;
1985 corners[i]->xRot(0 * PI / 180);
1986 }
1987 else if (attached)
1988 {
1989 corners[i]->y += 0.25 / 16.0f;
1990 corners[i]->z -= 2.75 / 16.0f;
1991 corners[i]->xRot(10 * PI / 180);
1992 }
1993 else
1994 {
1995 corners[i]->xRot(50 * PI / 180);
1996 }
1997
1998 if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180);
1999 if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180);
2000 if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180);
2001 if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180);
2002
2003 corners[i]->x += x + 0.5;
2004 corners[i]->y += y + 5 / 16.0f;
2005 corners[i]->z += z + 0.5;
2006 }
2007
2008 int hoopX0 = 5;
2009 int hoopX1 = 11;
2010 int hoopY0 = 3;
2011 int hoopY1 = 9;
2012
2013 for (int i = 0; i < 6; i++)
2014 {
2015 if (i == 0)
2016 {
2017 c0 = corners[0];
2018 c1 = corners[1];
2019 c2 = corners[2];
2020 c3 = corners[3];
2021 u0 = tex->getU(hoopX0);
2022 v0 = tex->getV(hoopY0);
2023 u1 = tex->getU(hoopX1);
2024 v1 = tex->getV(hoopY1);
2025 }
2026 else if (i == 1)
2027 {
2028 c0 = corners[7];
2029 c1 = corners[6];
2030 c2 = corners[5];
2031 c3 = corners[4];
2032 }
2033 else if (i == 2)
2034 {
2035 c0 = corners[1];
2036 c1 = corners[0];
2037 c2 = corners[4];
2038 c3 = corners[5];
2039 u0 = tex->getU(hoopX0);
2040 v0 = tex->getV(hoopY0);
2041 u1 = tex->getU(hoopX1);
2042 v1 = tex->getV(hoopY0 + 2);
2043 }
2044 else if (i == 3)
2045 {
2046 c0 = corners[2];
2047 c1 = corners[1];
2048 c2 = corners[5];
2049 c3 = corners[6];
2050 }
2051 else if (i == 4)
2052 {
2053 c0 = corners[3];
2054 c1 = corners[2];
2055 c2 = corners[6];
2056 c3 = corners[7];
2057 }
2058 else if (i == 5)
2059 {
2060 c0 = corners[0];
2061 c1 = corners[3];
2062 c2 = corners[7];
2063 c3 = corners[4];
2064 }
2065 t->vertexUV(c0->x, c0->y, c0->z, u0, v1);
2066 t->vertexUV(c1->x, c1->y, c1->z, u1, v1);
2067 t->vertexUV(c2->x, c2->y, c2->z, u1, v0);
2068 t->vertexUV(c3->x, c3->y, c3->z, u0, v0);
2069 }
2070
2071 if (attached)
2072 {
2073 double hoopBottomY = corners[0]->y;
2074 float width = 0.5f / 16.0f;
2075 float top = 0.5f - (width / 2);
2076 float bottom = top + width;
2077 Icon *wireTex = getTexture(Tile::tripWire);
2078 double wireX0 = tex->getU0();
2079 double wireY0 = tex->getV(attached ? 2 : 0);
2080 double wireX1 = tex->getU1();
2081 double wireY1 = tex->getV(attached ? 4 : 2);
2082 double floating = (suspended ? 3.5f : 1.5f) / 16.0;
2083
2084 brightness = tt->getBrightness(level, x, y, z) * 0.75f;
2085 t->color(brightness, brightness, brightness);
2086
2087 if (dir == Direction::NORTH)
2088 {
2089 t->vertexUV(x + top, y + floating, z + 0.25, wireX0, wireY0);
2090 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX0, wireY1);
2091 t->vertexUV(x + bottom, y + floating, z, wireX1, wireY1);
2092 t->vertexUV(x + top, y + floating, z, wireX1, wireY0);
2093
2094 t->vertexUV(x + top, hoopBottomY, z + 0.5, wireX0, wireY0);
2095 t->vertexUV(x + bottom, hoopBottomY, z + 0.5, wireX0, wireY1);
2096 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX1, wireY1);
2097 t->vertexUV(x + top, y + floating, z + 0.25, wireX1, wireY0);
2098 }
2099 else if (dir == Direction::SOUTH)
2100 {
2101 t->vertexUV(x + top, y + floating, z + 0.75, wireX0, wireY0);
2102 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX0, wireY1);
2103 t->vertexUV(x + bottom, hoopBottomY, z + 0.5, wireX1, wireY1);
2104 t->vertexUV(x + top, hoopBottomY, z + 0.5, wireX1, wireY0);
2105
2106 t->vertexUV(x + top, y + floating, z + 1, wireX0, wireY0);
2107 t->vertexUV(x + bottom, y + floating, z + 1, wireX0, wireY1);
2108 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX1, wireY1);
2109 t->vertexUV(x + top, y + floating, z + 0.75, wireX1, wireY0);
2110 }
2111 else if (dir == Direction::WEST)
2112 {
2113 t->vertexUV(x, y + floating, z + bottom, wireX0, wireY1);
2114 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX1, wireY1);
2115 t->vertexUV(x + 0.25, y + floating, z + top, wireX1, wireY0);
2116 t->vertexUV(x, y + floating, z + top, wireX0, wireY0);
2117
2118 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX0, wireY1);
2119 t->vertexUV(x + 0.5, hoopBottomY, z + bottom, wireX1, wireY1);
2120 t->vertexUV(x + 0.5, hoopBottomY, z + top, wireX1, wireY0);
2121 t->vertexUV(x + 0.25, y + floating, z + top, wireX0, wireY0);
2122 }
2123 else
2124 {
2125 t->vertexUV(x + 0.5, hoopBottomY, z + bottom, wireX0, wireY1);
2126 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX1, wireY1);
2127 t->vertexUV(x + 0.75, y + floating, z + top, wireX1, wireY0);
2128 t->vertexUV(x + 0.5, hoopBottomY, z + top, wireX0, wireY0);
2129
2130 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX0, wireY1);
2131 t->vertexUV(x + 1, y + floating, z + bottom, wireX1, wireY1);
2132 t->vertexUV(x + 1, y + floating, z + top, wireX1, wireY0);
2133 t->vertexUV(x + 0.75, y + floating, z + top, wireX0, wireY0);
2134 }
2135 }
2136#endif // #ifdef DISABLE_TESS_FUNCS
2137
2138 return true;
2139}
2140
2141bool TileRenderer_SPU::tesselateTripwireInWorld(Tile_SPU *tt, int x, int y, int z)
2142{
2143#ifdef DISABLE_TESS_FUNCS
2144
2145 Tesselator *t = Tesselator::getInstance();
2146 Icon *tex = getTexture(tt, 0);
2147 int data = level->getData(x, y, z);
2148 bool attached = (data & TripWireTile::MASK_ATTACHED) == TripWireTile::MASK_ATTACHED;
2149 bool suspended = (data & TripWireTile::MASK_SUSPENDED) == TripWireTile::MASK_SUSPENDED;
2150
2151 if (hasFixedTexture()) tex = fixedTexture;
2152
2153 float brightness;
2154 if (SharedConstants::TEXTURE_LIGHTING)
2155 {
2156 t->tex2(tt->getLightColor(level, x, y, z));
2157 }
2158 brightness = tt->getBrightness(level, x, y, z) * 0.75f;
2159 t->color(brightness, brightness, brightness);
2160
2161 double wireX0 = tex->getU0();
2162 double wireY0 = tex->getV(attached ? 2 : 0);
2163 double wireX1 = tex->getU1();
2164 double wireY1 = tex->getV(attached ? 4 : 2);
2165 double floating = (suspended ? 3.5f : 1.5f) / 16.0;
2166
2167 bool w = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::WEST);
2168 bool e = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::EAST);
2169 bool n = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::NORTH);
2170 bool s = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::SOUTH);
2171
2172 float width = 0.5f / 16.0f;
2173 float top = 0.5f - (width / 2);
2174 float bottom = top + width;
2175
2176 if (!n && !e && !s && !w)
2177 {
2178 n = true;
2179 s = true;
2180 }
2181
2182 if (n)
2183 {
2184 t->vertexUV(x + top, y + floating, z + 0.25, wireX0, wireY0);
2185 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX0, wireY1);
2186 t->vertexUV(x + bottom, y + floating, z, wireX1, wireY1);
2187 t->vertexUV(x + top, y + floating, z, wireX1, wireY0);
2188
2189 t->vertexUV(x + top, y + floating, z, wireX1, wireY0);
2190 t->vertexUV(x + bottom, y + floating, z, wireX1, wireY1);
2191 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX0, wireY1);
2192 t->vertexUV(x + top, y + floating, z + 0.25, wireX0, wireY0);
2193 }
2194 if (n || (s && !e && !w))
2195 {
2196 t->vertexUV(x + top, y + floating, z + 0.5, wireX0, wireY0);
2197 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX0, wireY1);
2198 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX1, wireY1);
2199 t->vertexUV(x + top, y + floating, z + 0.25, wireX1, wireY0);
2200
2201 t->vertexUV(x + top, y + floating, z + 0.25, wireX1, wireY0);
2202 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX1, wireY1);
2203 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX0, wireY1);
2204 t->vertexUV(x + top, y + floating, z + 0.5, wireX0, wireY0);
2205 }
2206 if (s || (n && !e && !w))
2207 {
2208 t->vertexUV(x + top, y + floating, z + 0.75, wireX0, wireY0);
2209 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX0, wireY1);
2210 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX1, wireY1);
2211 t->vertexUV(x + top, y + floating, z + 0.5, wireX1, wireY0);
2212
2213 t->vertexUV(x + top, y + floating, z + 0.5, wireX1, wireY0);
2214 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX1, wireY1);
2215 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX0, wireY1);
2216 t->vertexUV(x + top, y + floating, z + 0.75, wireX0, wireY0);
2217 }
2218 if (s)
2219 {
2220 t->vertexUV(x + top, y + floating, z + 1, wireX0, wireY0);
2221 t->vertexUV(x + bottom, y + floating, z + 1, wireX0, wireY1);
2222 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX1, wireY1);
2223 t->vertexUV(x + top, y + floating, z + 0.75, wireX1, wireY0);
2224
2225 t->vertexUV(x + top, y + floating, z + 0.75, wireX1, wireY0);
2226 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX1, wireY1);
2227 t->vertexUV(x + bottom, y + floating, z + 1, wireX0, wireY1);
2228 t->vertexUV(x + top, y + floating, z + 1, wireX0, wireY0);
2229 }
2230
2231 if (w)
2232 {
2233 t->vertexUV(x, y + floating, z + bottom, wireX0, wireY1);
2234 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX1, wireY1);
2235 t->vertexUV(x + 0.25, y + floating, z + top, wireX1, wireY0);
2236 t->vertexUV(x, y + floating, z + top, wireX0, wireY0);
2237
2238 t->vertexUV(x, y + floating, z + top, wireX0, wireY0);
2239 t->vertexUV(x + 0.25, y + floating, z + top, wireX1, wireY0);
2240 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX1, wireY1);
2241 t->vertexUV(x, y + floating, z + bottom, wireX0, wireY1);
2242 }
2243 if (w || (e && !n && !s))
2244 {
2245 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX0, wireY1);
2246 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX1, wireY1);
2247 t->vertexUV(x + 0.5, y + floating, z + top, wireX1, wireY0);
2248 t->vertexUV(x + 0.25, y + floating, z + top, wireX0, wireY0);
2249
2250 t->vertexUV(x + 0.25, y + floating, z + top, wireX0, wireY0);
2251 t->vertexUV(x + 0.5, y + floating, z + top, wireX1, wireY0);
2252 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX1, wireY1);
2253 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX0, wireY1);
2254 }
2255 if (e || (w && !n && !s))
2256 {
2257 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX0, wireY1);
2258 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX1, wireY1);
2259 t->vertexUV(x + 0.75, y + floating, z + top, wireX1, wireY0);
2260 t->vertexUV(x + 0.5, y + floating, z + top, wireX0, wireY0);
2261
2262 t->vertexUV(x + 0.5, y + floating, z + top, wireX0, wireY0);
2263 t->vertexUV(x + 0.75, y + floating, z + top, wireX1, wireY0);
2264 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX1, wireY1);
2265 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX0, wireY1);
2266 }
2267 if (e)
2268 {
2269 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX0, wireY1);
2270 t->vertexUV(x + 1, y + floating, z + bottom, wireX1, wireY1);
2271 t->vertexUV(x + 1, y + floating, z + top, wireX1, wireY0);
2272 t->vertexUV(x + 0.75, y + floating, z + top, wireX0, wireY0);
2273
2274 t->vertexUV(x + 0.75, y + floating, z + top, wireX0, wireY0);
2275 t->vertexUV(x + 1, y + floating, z + top, wireX1, wireY0);
2276 t->vertexUV(x + 1, y + floating, z + bottom, wireX1, wireY1);
2277 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX0, wireY1);
2278 }
2279#endif // DISABLE_TESS_FUNCS
2280
2281 return true;
2282}
2283
2284
2285
2286bool TileRenderer_SPU::tesselateFireInWorld( FireTile_SPU* tt, int x, int y, int z )
2287{
2288 Tesselator_SPU* t = getTesselator();
2289
2290 Icon_SPU *firstTex = tt->getTextureLayer(0);
2291 Icon_SPU *secondTex = tt->getTextureLayer(1);
2292 Icon_SPU *tex = firstTex;
2293
2294 if (hasFixedTexture()) tex = fixedTexture;
2295
2296 if ( SharedConstants::TEXTURE_LIGHTING )
2297 {
2298 t->color( 1.0f, 1.0f, 1.0f );
2299 t->tex2( tt->getLightColor( level, x, y, z ) );
2300 }
2301 else
2302 {
2303 float br = tt->getBrightness( level, x, y, z );
2304 t->color( br, br, br );
2305 }
2306 float u0 = tex->getU0();
2307 float v0 = tex->getV0();
2308 float u1 = tex->getU1();
2309 float v1 = tex->getV1();
2310 float h = 1.4f;
2311
2312 if ( level->isSolidBlockingTile( x, y - 1, z ) || FireTile_SPU::canBurn( level, x, y - 1, z ) )
2313 {
2314 float x0 = x + 0.5f + 0.2f;
2315 float x1 = x + 0.5f - 0.2f;
2316 float z0 = z + 0.5f + 0.2f;
2317 float z1 = z + 0.5f - 0.2f;
2318
2319 float x0_ = x + 0.5f - 0.3f;
2320 float x1_ = x + 0.5f + 0.3f;
2321 float z0_ = z + 0.5f - 0.3f;
2322 float z1_ = z + 0.5f + 0.3f;
2323
2324 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v0 ) );
2325 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v1 ) );
2326 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v1 ) );
2327 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v0 ) );
2328
2329 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v0 ) );
2330 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v1 ) );
2331 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v1 ) );
2332 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v0 ) );
2333
2334 tex = secondTex;
2335 u0 = tex->getU0();
2336 v0 = tex->getV0();
2337 u1 = tex->getU1();
2338 v1 = tex->getV1();
2339
2340 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u1 ), ( float )( v0 ) );
2341 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2342 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
2343 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u0 ), ( float )( v0 ) );
2344
2345 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u1 ), ( float )( v0 ) );
2346 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
2347 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
2348 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u0 ), ( float )( v0 ) );
2349
2350 x0 = x + 0.5f - 0.5f;
2351 x1 = x + 0.5f + 0.5f;
2352 z0 = z + 0.5f - 0.5f;
2353 z1 = z + 0.5f + 0.5f;
2354
2355 x0_ = x + 0.5f - 0.4f;
2356 x1_ = x + 0.5f + 0.4f;
2357 z0_ = z + 0.5f - 0.4f;
2358 z1_ = z + 0.5f + 0.4f;
2359
2360 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v0 ) );
2361 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v1 ) );
2362 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v1 ) );
2363 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v0 ) );
2364
2365 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v0 ) );
2366 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v1 ) );
2367 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v1 ) );
2368 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v0 ) );
2369
2370 tex = firstTex;
2371 u0 = tex->getU0();
2372 v0 = tex->getV0();
2373 u1 = tex->getU1();
2374 v1 = tex->getV1();
2375
2376 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u0 ), ( float )( v0 ) );
2377 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
2378 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2379 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u1 ), ( float )( v0 ) );
2380
2381 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u0 ), ( float )( v0 ) );
2382 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
2383 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
2384 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u1 ), ( float )( v0 ) );
2385 }
2386 else
2387 {
2388 float r = 0.2f;
2389 float yo = 1 / 16.0f;
2390 if ( ( ( x + y + z ) & 1 ) == 1 )
2391 {
2392 tex = secondTex;
2393 u0 = tex->getU0();
2394 v0 = tex->getV0();
2395 u1 = tex->getU1();
2396 v1 = tex->getV1();
2397 }
2398 if ( ( ( x / 2 + y / 2 + z / 2 ) & 1 ) == 1 )
2399 {
2400 float tmp = u1;
2401 u1 = u0;
2402 u0 = tmp;
2403 }
2404 if ( FireTile_SPU::canBurn( level, x - 1, y, z ) )
2405 {
2406 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2407 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2408 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2409 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2410 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2411 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2412 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2413 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2414
2415 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2416 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2417 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2418 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2419 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2420 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2421 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2422 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2423 }
2424 if ( FireTile_SPU::canBurn( level, x + 1, y, z ) )
2425 {
2426 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + h + yo ), ( float )( z +
2427 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2428 t->vertexUV( ( float )( x + 1 - 0 ), ( float )( y + 0 + yo ), ( float )( z +
2429 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2430 t->vertexUV( ( float )( x + 1 - 0 ), ( float )( y + 0 + yo ), ( float )( z +
2431 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2432 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + h + yo ), ( float )( z +
2433 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2434
2435 t->vertexUV( ( float )( x + 1.0f - r ), ( float )( y + h + yo ), ( float )( z +
2436 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2437 t->vertexUV( ( float )( x + 1.0f - 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2438 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2439 t->vertexUV( ( float )( x + 1.0f - 0 ), ( float )( y + 0.0f + yo ), ( float )( z +
2440 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2441 t->vertexUV( ( float )( x + 1.0f - r ), ( float )( y + h + yo ), ( float )( z +
2442 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2443 }
2444 if ( FireTile_SPU::canBurn( level, x, y, z - 1 ) )
2445 {
2446 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z +
2447 r ), ( float )( u1 ), ( float )( v0 ) );
2448 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2449 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2450 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2451 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2452 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z +
2453 r ), ( float )( u0 ), ( float )( v0 ) );
2454
2455 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z +
2456 r ), ( float )( u0 ), ( float )( v0 ) );
2457 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2458 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2459 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2460 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2461 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z +
2462 r ), ( float )( u1 ), ( float )( v0 ) );
2463 }
2464 if ( FireTile_SPU::canBurn( level, x, y, z + 1 ) )
2465 {
2466 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2467 r ), ( float )( u0 ), ( float )( v0 ) );
2468 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2469 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2470 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2471 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2472 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2473 r ), ( float )( u1 ), ( float )( v0 ) );
2474
2475 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2476 r ), ( float )( u1 ), ( float )( v0 ) );
2477 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2478 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2479 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2480 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2481 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2482 r ), ( float )( u0 ), ( float )( v0 ) );
2483 }
2484 if ( FireTile_SPU::canBurn( level, x, y + 1.0f, z ) )
2485 {
2486 float x0 = x + 0.5f + 0.5f;
2487 float x1 = x + 0.5f - 0.5f;
2488 float z0 = z + 0.5f + 0.5f;
2489 float z1 = z + 0.5f - 0.5f;
2490
2491 float x0_ = x + 0.5f - 0.5f;
2492 float x1_ = x + 0.5f + 0.5f;
2493 float z0_ = z + 0.5f - 0.5f;
2494 float z1_ = z + 0.5f + 0.5f;
2495
2496 tex = firstTex;
2497 u0 = tex->getU0();
2498 v0 = tex->getV0();
2499 u1 = tex->getU1();
2500 v1 = tex->getV1();
2501
2502 y += 1;
2503 h = -0.2f;
2504
2505 if ( ( ( x + y + z ) & 1 ) == 0 )
2506 {
2507 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z +
2508 0 ), ( float )( u1 ), ( float )( v0 ) );
2509 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z +
2510 0 ), ( float )( u1 ), ( float )( v1 ) );
2511 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z +
2512 1 ), ( float )( u0 ), ( float )( v1 ) );
2513 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z +
2514 1 ), ( float )( u0 ), ( float )( v0 ) );
2515
2516 tex = secondTex;
2517 u0 = tex->getU0();
2518 v0 = tex->getV0();
2519 u1 = tex->getU1();
2520 v1 = tex->getV1();
2521
2522 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z +
2523 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2524 t->vertexUV( ( float )( x1 ), ( float )( y + 0.0f ), ( float )( z +
2525 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2526 t->vertexUV( ( float )( x1 ), ( float )( y + 0.0f ), ( float )( z +
2527 0 ), ( float )( u0 ), ( float )( v1 ) );
2528 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z +
2529 0 ), ( float )( u0 ), ( float )( v0 ) );
2530 }
2531 else
2532 {
2533 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2534 h ), ( float )( z1_ ), ( float )( u1 ), ( float )( v0 ) );
2535 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2536 0.0f ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2537 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2538 0.0f ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
2539 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2540 h ), ( float )( z1_ ), ( float )( u0 ), ( float )( v0 ) );
2541
2542 tex = secondTex;
2543 u0 = tex->getU0();
2544 v0 = tex->getV0();
2545 u1 = tex->getU1();
2546 v1 = tex->getV1();
2547
2548 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2549 h ), ( float )( z0_ ), ( float )( u1 ), ( float )( v0 ) );
2550 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2551 0.0f ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
2552 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2553 0.0f ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
2554 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2555 h ), ( float )( z0_ ), ( float )( u0 ), ( float )( v0 ) );
2556 }
2557 }
2558 }
2559 return true;
2560}
2561
2562bool TileRenderer_SPU::tesselateDustInWorld( Tile_SPU* tt, int x, int y, int z )
2563{
2564#ifdef DISABLE_TESS_FUNCS
2565
2566 Tesselator_SPU* t = getTesselator();
2567
2568 int data = level->getData( x, y, z );
2569 Icon_SPU *crossTexture = RedStoneDustTile_SPU::getTextureByName(RedStoneDustTile_SPU::TEXTURE_CROSS);
2570 Icon_SPU *lineTexture = RedStoneDustTile_SPU::getTextureByName(RedStoneDustTile_SPU::TEXTURE_LINE);
2571 Icon_SPU *crossTextureOverlay = RedStoneDustTile_SPU::getTextureByName(RedStoneDustTile_SPU::TEXTURE_CROSS_OVERLAY);
2572 Icon_SPU *lineTextureOverlay = RedStoneDustTile_SPU::getTextureByName(RedStoneDustTile_SPU::TEXTURE_LINE_OVERLAY);
2573
2574 float br;
2575 if ( SharedConstants::TEXTURE_LIGHTING )
2576 {
2577 t->tex2( tt->getLightColor( level, x, y, z ) );
2578 br = 1;
2579 }
2580 else
2581 {
2582 br = tt->getBrightness( level, x, y, z );
2583 }
2584 float pow = ( data / 15.0f );
2585 float red = pow * 0.6f + 0.4f;
2586 if ( data == 0 ) red = 0.3f;
2587
2588 float green = pow * pow * 0.7f - 0.5f;
2589 float blue = pow * pow * 0.6f - 0.7f;
2590 if ( green < 0 ) green = 0;
2591 if ( blue < 0 ) blue = 0;
2592
2593 if ( SharedConstants::TEXTURE_LIGHTING )
2594 {
2595 t->color( red, green, blue );
2596 }
2597 else
2598 {
2599 t->color( br * red, br * green, br * blue );
2600 }
2601 const float dustOffset = 0.25f / 16.0f;
2602 const float overlayOffset = 0.25f / 16.0f;
2603
2604 bool w = RedStoneDustTile_SPU::shouldConnectTo( level, x - 1, y, z, Direction::WEST )
2605 || ( !level->isSolidBlockingTile( x - 1, y, z ) && RedStoneDustTile_SPU::shouldConnectTo( level, x - 1, y - 1, z,
2606 Direction::UNDEFINED ) );
2607 bool e = RedStoneDustTile_SPU::shouldConnectTo( level, x + 1, y, z, Direction::EAST )
2608 || ( !level->isSolidBlockingTile( x + 1, y, z ) && RedStoneDustTile_SPU::shouldConnectTo( level, x + 1, y - 1, z,
2609 Direction::UNDEFINED ) );
2610 bool n = RedStoneDustTile_SPU::shouldConnectTo( level, x, y, z - 1, Direction::NORTH )
2611 || ( !level->isSolidBlockingTile( x, y, z - 1 ) && RedStoneDustTile_SPU::shouldConnectTo( level, x, y - 1, z - 1,
2612 Direction::UNDEFINED ) );
2613 bool s = RedStoneDustTile_SPU::shouldConnectTo( level, x, y, z + 1, Direction::SOUTH )
2614 || ( !level->isSolidBlockingTile( x, y, z + 1 ) && RedStoneDustTile_SPU::shouldConnectTo( level, x, y - 1, z + 1,
2615 Direction::UNDEFINED ) );
2616 if ( !level->isSolidBlockingTile( x, y + 1, z ) )
2617 {
2618 if ( level->isSolidBlockingTile( x - 1, y, z ) && RedStoneDustTile_SPU::shouldConnectTo( level, x - 1, y + 1, z,
2619 Direction::UNDEFINED ) ) w
2620 = true;
2621 if ( level->isSolidBlockingTile( x + 1, y, z ) && RedStoneDustTile_SPU::shouldConnectTo( level, x + 1, y + 1, z,
2622 Direction::UNDEFINED ) ) e
2623 = true;
2624 if ( level->isSolidBlockingTile( x, y, z - 1 ) && RedStoneDustTile_SPU::shouldConnectTo( level, x, y + 1, z - 1,
2625 Direction::UNDEFINED ) ) n
2626 = true;
2627 if ( level->isSolidBlockingTile( x, y, z + 1 ) && RedStoneDustTile_SPU::shouldConnectTo( level, x, y + 1, z + 1,
2628 Direction::UNDEFINED ) ) s
2629 = true;
2630 }
2631 float x0 = ( float )( x + 0.0f );
2632 float x1 = ( float )( x + 1.0f );
2633 float z0 = ( float )( z + 0.0f );
2634 float z1 = ( float )( z + 1.0f );
2635
2636 int pic = 0;
2637 if ( ( w || e ) && ( !n && !s ) ) pic = 1;
2638 if ( ( n || s ) && ( !e && !w ) ) pic = 2;
2639
2640 if ( pic == 0 )
2641 {
2642// if ( e || n || s || w )
2643 int u0 = 0;
2644 int v0 = 0;
2645 int u1 = SharedConstants::WORLD_RESOLUTION;
2646 int v1 = SharedConstants::WORLD_RESOLUTION;
2647
2648 int cutDistance = 5;
2649 if (!w) x0 += cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2650 if (!w) u0 += cutDistance;
2651 if (!e) x1 -= cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2652 if (!e) u1 -= cutDistance;
2653 if (!n) z0 += cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2654 if (!n) v0 += cutDistance;
2655 if (!s) z1 -= cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2656 if (!s) v1 -= cutDistance;
2657 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTexture->getU(u1), crossTexture->getV(v1) );
2658 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTexture->getU(u1), crossTexture->getV(v0) );
2659 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTexture->getU(u0), crossTexture->getV(v0) );
2660 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTexture->getU(u0), crossTexture->getV(v1) );
2661
2662 t->color( br, br, br );
2663 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTextureOverlay->getU(u1), crossTextureOverlay->getV(v1) );
2664 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTextureOverlay->getU(u1), crossTextureOverlay->getV(v0) );
2665 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTextureOverlay->getU(u0), crossTextureOverlay->getV(v0) );
2666 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTextureOverlay->getU(u0), crossTextureOverlay->getV(v1) );
2667 }
2668 else if ( pic == 1 )
2669 {
2670 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU1(), lineTexture->getV1() );
2671 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU1(), lineTexture->getV0() );
2672 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU0(), lineTexture->getV0() );
2673 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU0(), lineTexture->getV1() );
2674
2675 t->color( br, br, br );
2676 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV1() );
2677 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV0() );
2678 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV0() );
2679 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV1() );
2680 }
2681 else
2682 {
2683 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU1(), lineTexture->getV1() );
2684 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU0(), lineTexture->getV1() );
2685 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU0(), lineTexture->getV0() );
2686 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU1(), lineTexture->getV0() );
2687
2688 t->color( br, br, br );
2689 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV1() );
2690 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV1() );
2691 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV0() );
2692 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV0() );
2693 }
2694
2695 if ( !level->isSolidBlockingTile( x, y + 1, z ) )
2696 {
2697 const float yStretch = .35f / 16.0f;
2698
2699 if ( level->isSolidBlockingTile( x - 1, y, z ) && level->getTile( x - 1, y + 1, z ) == Tile_SPU::redStoneDust_Id )
2700 {
2701 t->color( br * red, br * green, br * blue );
2702 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTexture->getU1(), lineTexture->getV0() );
2703 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTexture->getU0(), lineTexture->getV0() );
2704 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTexture->getU0(), lineTexture->getV1() );
2705 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTexture->getU1(), lineTexture->getV1() );
2706
2707 t->color( br, br, br );
2708 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV0() );
2709 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV0() );
2710 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV1() );
2711 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV1() );
2712 }
2713 if ( level->isSolidBlockingTile( x + 1, y, z ) && level->getTile( x + 1, y + 1, z ) == Tile_SPU::redStoneDust_Id )
2714 {
2715 t->color( br * red, br * green, br * blue );
2716 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTexture->getU0(), lineTexture->getV1() );
2717 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTexture->getU1(), lineTexture->getV1() );
2718 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTexture->getU1(), lineTexture->getV0() );
2719 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTexture->getU0(), lineTexture->getV0() );
2720
2721 t->color( br, br, br );
2722 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV1() );
2723 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV1() );
2724 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTextureOverlay->getU1(), lineTextureOverlay->getV0() );
2725 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTextureOverlay->getU0(), lineTextureOverlay->getV0() );
2726 }
2727 if ( level->isSolidBlockingTile( x, y, z - 1 ) && level->getTile( x, y + 1, z - 1 ) == Tile_SPU::redStoneDust_Id )
2728 {
2729 t->color( br * red, br * green, br * blue );
2730 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + dustOffset ), lineTexture->getU0(), lineTexture->getV1() );
2731 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + dustOffset ), lineTexture->getU1(), lineTexture->getV1() );
2732 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + dustOffset ), lineTexture->getU1(), lineTexture->getV0() );
2733 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + dustOffset ), lineTexture->getU0(), lineTexture->getV0() );
2734
2735 t->color( br, br, br );
2736 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + overlayOffset ), lineTextureOverlay->getU0(), lineTextureOverlay->getV1() );
2737 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + overlayOffset ), lineTextureOverlay->getU1(), lineTextureOverlay->getV1() );
2738 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + overlayOffset ), lineTextureOverlay->getU1(), lineTextureOverlay->getV0() );
2739 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + overlayOffset ), lineTextureOverlay->getU0(), lineTextureOverlay->getV0() );
2740 }
2741 if ( level->isSolidBlockingTile( x, y, z + 1 ) && level->getTile( x, y + 1, z + 1 ) == Tile_SPU::redStoneDust_Id )
2742 {
2743 t->color( br * red, br * green, br * blue );
2744 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - dustOffset ), lineTexture->getU1(), lineTexture->getV0() );
2745 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + 1 - dustOffset ), lineTexture->getU0(), lineTexture->getV0() );
2746 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + 1 - dustOffset ), lineTexture->getU0(), lineTexture->getV1() );
2747 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - dustOffset ), lineTexture->getU1(), lineTexture->getV1() );
2748
2749 t->color( br, br, br );
2750 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU1(), lineTextureOverlay->getV0() );
2751 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU0(), lineTextureOverlay->getV0() );
2752 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU0(), lineTextureOverlay->getV1() );
2753 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU1(), lineTextureOverlay->getV1() );
2754 }
2755 }
2756#endif // #ifdef DISABLE_TESS_FUNCS
2757
2758 return true;
2759}
2760
2761bool TileRenderer_SPU::tesselateRailInWorld( RailTile_SPU* tt, int x, int y, int z )
2762{
2763 Tesselator_SPU* t = getTesselator();
2764 int data = level->getData( x, y, z );
2765
2766 Icon_SPU *tex = getTexture(tt, 0, data);
2767 if (hasFixedTexture()) tex = fixedTexture;
2768
2769 if ( tt->isUsesDataBit() )
2770 {
2771 data &= RailTile_SPU::RAIL_DIRECTION_MASK;
2772 }
2773
2774 if ( SharedConstants::TEXTURE_LIGHTING )
2775 {
2776 t->tex2( tt->getLightColor( level, x, y, z ) );
2777 t->color( 1.0f, 1.0f, 1.0f );
2778 }
2779 else
2780 {
2781 float br = tt->getBrightness( level, x, y, z );
2782 t->color( br, br, br );
2783 }
2784
2785 float u0 = tex->getU0();
2786 float v0 = tex->getV0();
2787 float u1 = tex->getU1();
2788 float v1 = tex->getV1();
2789
2790 float r = 1 / 16.0f;
2791
2792 float x0 = ( float )( x + 1 );
2793 float x1 = ( float )( x + 1 );
2794 float x2 = ( float )( x + 0 );
2795 float x3 = ( float )( x + 0 );
2796
2797 float z0 = ( float )( z + 0 );
2798 float z1 = ( float )( z + 1 );
2799 float z2 = ( float )( z + 1 );
2800 float z3 = ( float )( z + 0 );
2801
2802 float y0 = ( float )( y + r );
2803 float y1 = ( float )( y + r );
2804 float y2 = ( float )( y + r );
2805 float y3 = ( float )( y + r );
2806
2807 if ( data == 1 || data == 2 || data == 3 || data == 7 )
2808 {
2809 x0 = x3 = ( float )( x + 1 );
2810 x1 = x2 = ( float )( x + 0 );
2811 z0 = z1 = ( float )( z + 1 );
2812 z2 = z3 = ( float )( z + 0 );
2813 }
2814 else if ( data == 8 )
2815 {
2816 x0 = x1 = ( float )( x + 0 );
2817 x2 = x3 = ( float )( x + 1 );
2818 z0 = z3 = ( float )( z + 1 );
2819 z1 = z2 = ( float )( z + 0 );
2820 }
2821 else if ( data == 9 )
2822 {
2823 x0 = x3 = ( float )( x + 0 );
2824 x1 = x2 = ( float )( x + 1 );
2825 z0 = z1 = ( float )( z + 0 );
2826 z2 = z3 = ( float )( z + 1 );
2827 }
2828
2829 if ( data == 2 || data == 4 )
2830 {
2831 y0 += 1;
2832 y3 += 1;
2833 }
2834 else if ( data == 3 || data == 5 )
2835 {
2836 y1 += 1;
2837 y2 += 1;
2838 }
2839
2840 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
2841 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2842 t->vertexUV( ( float )( x2 ), ( float )( y2 ), ( float )( z2 ), ( float )( u0 ), ( float )( v1 ) );
2843 t->vertexUV( ( float )( x3 ), ( float )( y3 ), ( float )( z3 ), ( float )( u0 ), ( float )( v0 ) );
2844
2845 t->vertexUV( ( float )( x3 ), ( float )( y3 ), ( float )( z3 ), ( float )( u0 ), ( float )( v0 ) );
2846 t->vertexUV( ( float )( x2 ), ( float )( y2 ), ( float )( z2 ), ( float )( u0 ), ( float )( v1 ) );
2847 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2848 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
2849
2850 return true;
2851
2852}
2853
2854bool TileRenderer_SPU::tesselateLadderInWorld( Tile_SPU* tt, int x, int y, int z )
2855{
2856 Tesselator_SPU* t = getTesselator();
2857
2858 Icon_SPU *tex = getTexture(tt, 0);
2859
2860 if (hasFixedTexture()) tex = fixedTexture;
2861
2862 if ( SharedConstants::TEXTURE_LIGHTING )
2863 {
2864 t->tex2( tt->getLightColor( level, x, y, z ) );
2865 float br = 1;
2866 t->color( br, br, br );
2867 }
2868 else
2869 {
2870 float br = tt->getBrightness( level, x, y, z );
2871 t->color( br, br, br );
2872 }
2873 float u0 = tex->getU0();
2874 float v0 = tex->getV0();
2875 float u1 = tex->getU1();
2876 float v1 = tex->getV1();
2877
2878 int face = level->getData( x, y, z );
2879
2880 float o = 0 / 16.0f;
2881 float r = 0.05f;
2882 if ( face == 5 )
2883 {
2884 t->vertexUV( ( float )( x + r ), ( float )( y + 1 + o ), ( float )( z + 1 +
2885 o ), ( float )( u0 ), ( float )( v0 ) );
2886 t->vertexUV( ( float )( x + r ), ( float )( y + 0 - o ), ( float )( z + 1 +
2887 o ), ( float )( u0 ), ( float )( v1 ) );
2888 t->vertexUV( ( float )( x + r ), ( float )( y + 0 - o ), ( float )( z + 0 -
2889 o ), ( float )( u1 ), ( float )( v1 ) );
2890 t->vertexUV( ( float )( x + r ), ( float )( y + 1 + o ), ( float )( z + 0 -
2891 o ), ( float )( u1 ), ( float )( v0 ) );
2892 }
2893 if ( face == 4 )
2894 {
2895 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 0 - o ), ( float )( z + 1 +
2896 o ), ( float )( u1 ), ( float )( v1 ) );
2897 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 1 + o ), ( float )( z + 1 +
2898 o ), ( float )( u1 ), ( float )( v0 ) );
2899 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 1 + o ), ( float )( z + 0 -
2900 o ), ( float )( u0 ), ( float )( v0 ) );
2901 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 0 - o ), ( float )( z + 0 -
2902 o ), ( float )( u0 ), ( float )( v1 ) );
2903 }
2904 if ( face == 3 )
2905 {
2906 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 0 - o ), ( float )( z +
2907 r ), ( float )( u1 ), ( float )( v1 ) );
2908 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 1 + o ), ( float )( z +
2909 r ), ( float )( u1 ), ( float )( v0 ) );
2910 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 1 + o ), ( float )( z +
2911 r ), ( float )( u0 ), ( float )( v0 ) );
2912 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 0 - o ), ( float )( z +
2913 r ), ( float )( u0 ), ( float )( v1 ) );
2914 }
2915 if ( face == 2 )
2916 {
2917 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 1 + o ), ( float )( z + 1 -
2918 r ), ( float )( u0 ), ( float )( v0 ) );
2919 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 0 - o ), ( float )( z + 1 -
2920 r ), ( float )( u0 ), ( float )( v1 ) );
2921 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 0 - o ), ( float )( z + 1 -
2922 r ), ( float )( u1 ), ( float )( v1 ) );
2923 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 1 + o ), ( float )( z + 1 -
2924 r ), ( float )( u1 ), ( float )( v0 ) );
2925 }
2926 return true;
2927}
2928
2929bool TileRenderer_SPU::tesselateVineInWorld( Tile_SPU* tt, int x, int y, int z )
2930{
2931 Tesselator_SPU* t = getTesselator();
2932
2933 Icon_SPU *tex = getTexture(tt, 0);
2934
2935 if (hasFixedTexture()) tex = fixedTexture;
2936
2937
2938 float br = 1;
2939 if ( SharedConstants::TEXTURE_LIGHTING )
2940 {
2941 t->tex2( tt->getLightColor( level, x, y, z ) );
2942 }
2943 else
2944 {
2945 br = tt->getBrightness( level, x, y, z );
2946 }
2947 {
2948 int col = tt->getColor( level, x, y, z );
2949 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
2950 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
2951 float b = ( ( col )& 0xff ) / 255.0f;
2952
2953 t->color( br * r, br * g, br * b );
2954 }
2955
2956 float u0 = tex->getU0();
2957 float v0 = tex->getV0();
2958 float u1 = tex->getU1();
2959 float v1 = tex->getV1();
2960
2961 float r = 0.05f;
2962 int facings = level->getData( x, y, z );
2963
2964 if ( ( facings & VineTile_SPU::VINE_WEST ) != 0 )
2965 {
2966 t->vertexUV( x + r, y + 1, z + 1, u0, v0 );
2967 t->vertexUV( x + r, y + 0, z + 1, u0, v1 );
2968 t->vertexUV( x + r, y + 0, z + 0, u1, v1 );
2969 t->vertexUV( x + r, y + 1, z + 0, u1, v0 );
2970
2971 t->vertexUV( x + r, y + 1, z + 0, u1, v0 );
2972 t->vertexUV( x + r, y + 0, z + 0, u1, v1 );
2973 t->vertexUV( x + r, y + 0, z + 1, u0, v1 );
2974 t->vertexUV( x + r, y + 1, z + 1, u0, v0 );
2975 }
2976 if ( ( facings & VineTile_SPU::VINE_EAST ) != 0 )
2977 {
2978 t->vertexUV( x + 1 - r, y + 0, z + 1, u1, v1 );
2979 t->vertexUV( x + 1 - r, y + 1, z + 1, u1, v0 );
2980 t->vertexUV( x + 1 - r, y + 1, z + 0, u0, v0 );
2981 t->vertexUV( x + 1 - r, y + 0, z + 0, u0, v1 );
2982
2983 t->vertexUV( x + 1 - r, y + 0, z + 0, u0, v1 );
2984 t->vertexUV( x + 1 - r, y + 1, z + 0, u0, v0 );
2985 t->vertexUV( x + 1 - r, y + 1, z + 1, u1, v0 );
2986 t->vertexUV( x + 1 - r, y + 0, z + 1, u1, v1 );
2987 }
2988 if ( ( facings & VineTile_SPU::VINE_NORTH ) != 0 )
2989 {
2990 t->vertexUV( x + 1, y + 0, z + r, u1, v1 );
2991 t->vertexUV( x + 1, y + 1, z + r, u1, v0 );
2992 t->vertexUV( x + 0, y + 1, z + r, u0, v0 );
2993 t->vertexUV( x + 0, y + 0, z + r, u0, v1 );
2994
2995 t->vertexUV( x + 0, y + 0, z + r, u0, v1 );
2996 t->vertexUV( x + 0, y + 1, z + r, u0, v0 );
2997 t->vertexUV( x + 1, y + 1, z + r, u1, v0 );
2998 t->vertexUV( x + 1, y + 0, z + r, u1, v1 );
2999 }
3000 if ( ( facings & VineTile_SPU::VINE_SOUTH ) != 0 )
3001 {
3002 t->vertexUV( x + 1, y + 1, z + 1 - r, u0, v0 );
3003 t->vertexUV( x + 1, y + 0, z + 1 - r, u0, v1 );
3004 t->vertexUV( x + 0, y + 0, z + 1 - r, u1, v1 );
3005 t->vertexUV( x + 0, y + 1, z + 1 - r, u1, v0 );
3006
3007 t->vertexUV( x + 0, y + 1, z + 1 - r, u1, v0 );
3008 t->vertexUV( x + 0, y + 0, z + 1 - r, u1, v1 );
3009 t->vertexUV( x + 1, y + 0, z + 1 - r, u0, v1 );
3010 t->vertexUV( x + 1, y + 1, z + 1 - r, u0, v0 );
3011 }
3012 if ( level->isSolidBlockingTile( x, y + 1, z ) )
3013 {
3014 t->vertexUV( x + 1, y + 1 - r, z + 0, u0, v0 );
3015 t->vertexUV( x + 1, y + 1 - r, z + 1, u0, v1 );
3016 t->vertexUV( x + 0, y + 1 - r, z + 1, u1, v1 );
3017 t->vertexUV( x + 0, y + 1 - r, z + 0, u1, v0 );
3018 }
3019 return true;
3020}
3021
3022bool TileRenderer_SPU::tesselateThinFenceInWorld( ThinFenceTile* tt, int x, int y, int z )
3023{
3024#ifdef DISABLE_TESS_FUNCS
3025 int depth = level->getDepth();
3026 Tesselator_SPU* t = getTesselator();
3027
3028 float br;
3029 if ( SharedConstants::TEXTURE_LIGHTING )
3030 {
3031 t->tex2( tt->getLightColor( level, x, y, z ) );
3032 br = 1;
3033 }
3034 else
3035 {
3036 br = tt->getBrightness( level, x, y, z );
3037 }
3038 int col = tt->getColor( level, x, y, z );
3039 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
3040 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
3041 float b = ( ( col )& 0xff ) / 255.0f;
3042
3043 if ( GameRenderer::anaglyph3d )
3044 {
3045 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
3046 float cg = ( r * 30 + g * 70 ) / ( 100 );
3047 float cb = ( r * 30 + b * 70 ) / ( 100 );
3048
3049 r = cr;
3050 g = cg;
3051 b = cb;
3052 }
3053 t->color( br * r, br * g, br * b );
3054
3055 Icon_SPU *tex;
3056 Icon_SPU *edgeTex;
3057
3058 if ( hasFixedTexture() )
3059 {
3060 tex = fixedTexture;
3061 edgeTex = fixedTexture;
3062 }
3063 else
3064 {
3065 int data = level->getData( x, y, z );
3066 tex = getTexture( tt, 0, data );
3067 edgeTex = tt->getEdgeTexture();
3068 }
3069
3070 int xt = tex->getX();
3071 int yt = tex->getY();
3072 float u0 = tex->getU0();
3073 float u1 = tex->getU(8);
3074 float u2 = tex->getU1();
3075 float v0 = tex->getV0();
3076 float v2 = tex->getV1();
3077
3078 int xet = edgeTex->getX();
3079 int yet = edgeTex->getY();
3080
3081 float iu0 = edgeTex->getU(7);
3082 float iu1 = edgeTex->getU(9);
3083 float iv0 = edgeTex->getV0();
3084 float iv1 = edgeTex->getV(8);
3085 float iv2 = edgeTex->getV1();
3086
3087 float x0 = (float)x;
3088 float x1 = x + 0.5f;
3089 float x2 = x + 1.0f;
3090 float z0 = (float)z;
3091 float z1 = z + 0.5f;
3092 float z2 = z + 1.0f;
3093 float ix0 = x + 0.5f - 1.0f / 16.0f;
3094 float ix1 = x + 0.5f + 1.0f / 16.0f;
3095 float iz0 = z + 0.5f - 1.0f / 16.0f;
3096 float iz1 = z + 0.5f + 1.0f / 16.0f;
3097
3098 bool n = tt->attachsTo( level->getTile( x, y, z - 1 ) );
3099 bool s = tt->attachsTo( level->getTile( x, y, z + 1 ) );
3100 bool w = tt->attachsTo( level->getTile( x - 1, y, z ) );
3101 bool e = tt->attachsTo( level->getTile( x + 1, y, z ) );
3102
3103 bool up = tt->shouldRenderFace( level, x, y + 1, z, Facing::UP );
3104 bool down = tt->shouldRenderFace( level, x, y - 1, z, Facing::DOWN );
3105
3106 const float noZFightingOffset = 0.01f;
3107 const float noZFightingOffsetB = 0.005;
3108
3109 if ( ( w && e ) || ( !w && !e && !n && !s ) )
3110 {
3111 t->vertexUV( x0, y + 1, z1, u0, v0 );
3112 t->vertexUV( x0, y + 0, z1, u0, v2 );
3113 t->vertexUV( x2, y + 0, z1, u2, v2 );
3114 t->vertexUV( x2, y + 1, z1, u2, v0 );
3115
3116 t->vertexUV( x2, y + 1, z1, u0, v0 );
3117 t->vertexUV( x2, y + 0, z1, u0, v2 );
3118 t->vertexUV( x0, y + 0, z1, u2, v2 );
3119 t->vertexUV( x0, y + 1, z1, u2, v0 );
3120
3121 if ( up )
3122 {
3123 // small edge texture
3124 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3125 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3126 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3127 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3128
3129 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3130 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3131 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3132 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3133 }
3134 else
3135 {
3136 if ( y < ( depth - 1 ) && level->isEmptyTile( x - 1, y + 1, z ) )
3137 {
3138 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3139 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3140 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3141 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3142
3143 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3144 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3145 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3146 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3147 }
3148 if ( y < ( depth - 1 ) && level->isEmptyTile( x + 1, y + 1, z ) )
3149 {
3150 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3151 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3152 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3153 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3154
3155 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3156 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3157 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3158 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3159 }
3160 }
3161 if ( down )
3162 {
3163 // small edge texture
3164 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv2 );
3165 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv0 );
3166 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv0 );
3167 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv2 );
3168
3169 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv2 );
3170 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv0 );
3171 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv0 );
3172 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv2 );
3173 }
3174 else
3175 {
3176 if ( y > 1 && level->isEmptyTile( x - 1, y - 1, z ) )
3177 {
3178 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv1 );
3179 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv2 );
3180 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv2 );
3181 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv1 );
3182
3183 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3184 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv2 );
3185 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv2 );
3186 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3187 }
3188 if ( y > 1 && level->isEmptyTile( x + 1, y - 1, z ) )
3189 {
3190 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv0 );
3191 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv1 );
3192 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv1 );
3193 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv0 );
3194
3195 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv0 );
3196 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3197 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3198 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv0 );
3199 }
3200 }
3201 }
3202 else if ( w && !e )
3203 {
3204 // half-step towards west
3205 t->vertexUV( x0, y + 1, z1, u0, v0 );
3206 t->vertexUV( x0, y + 0, z1, u0, v2 );
3207 t->vertexUV( x1, y + 0, z1, u1, v2 );
3208 t->vertexUV( x1, y + 1, z1, u1, v0 );
3209
3210 t->vertexUV( x1, y + 1, z1, u0, v0 );
3211 t->vertexUV( x1, y + 0, z1, u0, v2 );
3212 t->vertexUV( x0, y + 0, z1, u1, v2 );
3213 t->vertexUV( x0, y + 1, z1, u1, v0 );
3214
3215 // small edge texture
3216 if ( !s && !n )
3217 {
3218 t->vertexUV( x1, y + 1, iz1, iu0, iv0 );
3219 t->vertexUV( x1, y + 0, iz1, iu0, iv2 );
3220 t->vertexUV( x1, y + 0, iz0, iu1, iv2 );
3221 t->vertexUV( x1, y + 1, iz0, iu1, iv0 );
3222
3223 t->vertexUV( x1, y + 1, iz0, iu0, iv0 );
3224 t->vertexUV( x1, y + 0, iz0, iu0, iv2 );
3225 t->vertexUV( x1, y + 0, iz1, iu1, iv2 );
3226 t->vertexUV( x1, y + 1, iz1, iu1, iv0 );
3227 }
3228
3229 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x - 1, y + 1, z ) ) )
3230 {
3231 // small edge texture
3232 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3233 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3234 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3235 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3236
3237 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3238 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3239 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3240 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3241 }
3242 if ( down || ( y > 1 && level->isEmptyTile( x - 1, y - 1, z ) ) )
3243 {
3244 // small edge texture
3245 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv1 );
3246 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv2 );
3247 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv2 );
3248 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv1 );
3249
3250 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3251 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv2 );
3252 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv2 );
3253 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3254 }
3255
3256 }
3257 else if ( !w && e )
3258 {
3259 // half-step towards east
3260 t->vertexUV( x1, y + 1, z1, u1, v0 );
3261 t->vertexUV( x1, y + 0, z1, u1, v2 );
3262 t->vertexUV( x2, y + 0, z1, u2, v2 );
3263 t->vertexUV( x2, y + 1, z1, u2, v0 );
3264
3265 t->vertexUV( x2, y + 1, z1, u1, v0 );
3266 t->vertexUV( x2, y + 0, z1, u1, v2 );
3267 t->vertexUV( x1, y + 0, z1, u2, v2 );
3268 t->vertexUV( x1, y + 1, z1, u2, v0 );
3269
3270 // small edge texture
3271 if ( !s && !n )
3272 {
3273 t->vertexUV( x1, y + 1, iz0, iu0, iv0 );
3274 t->vertexUV( x1, y + 0, iz0, iu0, iv2 );
3275 t->vertexUV( x1, y + 0, iz1, iu1, iv2 );
3276 t->vertexUV( x1, y + 1, iz1, iu1, iv0 );
3277
3278 t->vertexUV( x1, y + 1, iz1, iu0, iv0 );
3279 t->vertexUV( x1, y + 0, iz1, iu0, iv2 );
3280 t->vertexUV( x1, y + 0, iz0, iu1, iv2 );
3281 t->vertexUV( x1, y + 1, iz0, iu1, iv0 );
3282 }
3283
3284 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x + 1, y + 1, z ) ) )
3285 {
3286 // small edge texture
3287 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3288 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3289 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3290 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3291
3292 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3293 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3294 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3295 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3296 }
3297 if ( down || ( y > 1 && level->isEmptyTile( x + 1, y - 1, z ) ) )
3298 {
3299 // small edge texture
3300 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv0 );
3301 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv1 );
3302 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv1 );
3303 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv0 );
3304
3305 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv0 );
3306 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3307 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3308 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv0 );
3309 }
3310
3311 }
3312
3313 if ( ( n && s ) || ( !w && !e && !n && !s ) )
3314 {
3315 // straight north-south
3316 t->vertexUV( x1, y + 1, z2, u0, v0 );
3317 t->vertexUV( x1, y + 0, z2, u0, v2 );
3318 t->vertexUV( x1, y + 0, z0, u2, v2 );
3319 t->vertexUV( x1, y + 1, z0, u2, v0 );
3320
3321 t->vertexUV( x1, y + 1, z0, u0, v0 );
3322 t->vertexUV( x1, y + 0, z0, u0, v2 );
3323 t->vertexUV( x1, y + 0, z2, u2, v2 );
3324 t->vertexUV( x1, y + 1, z2, u2, v0 );
3325
3326 if ( up )
3327 {
3328 // small edge texture
3329 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv2 );
3330 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu1, iv0 );
3331 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu0, iv0 );
3332 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv2 );
3333
3334 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu1, iv2 );
3335 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv0 );
3336 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv0 );
3337 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu0, iv2 );
3338 }
3339 else
3340 {
3341 if ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z - 1 ) )
3342 {
3343 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv0 );
3344 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv1 );
3345 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv1 );
3346 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv0 );
3347
3348 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv0 );
3349 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv1 );
3350 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv1 );
3351 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv0 );
3352 }
3353 if ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z + 1 ) )
3354 {
3355 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv1 );
3356 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv2 );
3357 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv2 );
3358 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv1 );
3359
3360 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv1 );
3361 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv2 );
3362 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv2 );
3363 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv1 );
3364 }
3365 }
3366 if ( down )
3367 {
3368 // small edge texture
3369 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv2 );
3370 t->vertexUV( ix1, y - noZFightingOffset, z0, iu1, iv0 );
3371 t->vertexUV( ix0, y - noZFightingOffset, z0, iu0, iv0 );
3372 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv2 );
3373
3374 t->vertexUV( ix1, y - noZFightingOffset, z0, iu1, iv2 );
3375 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv0 );
3376 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv0 );
3377 t->vertexUV( ix0, y - noZFightingOffset, z0, iu0, iv2 );
3378 }
3379 else
3380 {
3381 if ( y > 1 && level->isEmptyTile( x, y - 1, z - 1 ) )
3382 {
3383 // north half-step
3384 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv0 );
3385 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv1 );
3386 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv1 );
3387 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv0 );
3388
3389 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv0 );
3390 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv1 );
3391 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv1 );
3392 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv0 );
3393 }
3394 if ( y > 1 && level->isEmptyTile( x, y - 1, z + 1 ) )
3395 {
3396 // south half-step
3397 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv1 );
3398 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv2 );
3399 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv2 );
3400 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv1 );
3401
3402 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv1 );
3403 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv2 );
3404 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv2 );
3405 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv1 );
3406 }
3407 }
3408
3409 }
3410 else if ( n && !s )
3411 {
3412 // half-step towards north
3413 t->vertexUV( x1, y + 1, z0, u0, v0 );
3414 t->vertexUV( x1, y + 0, z0, u0, v2 );
3415 t->vertexUV( x1, y + 0, z1, u1, v2 );
3416 t->vertexUV( x1, y + 1, z1, u1, v0 );
3417
3418 t->vertexUV( x1, y + 1, z1, u0, v0 );
3419 t->vertexUV( x1, y + 0, z1, u0, v2 );
3420 t->vertexUV( x1, y + 0, z0, u1, v2 );
3421 t->vertexUV( x1, y + 1, z0, u1, v0 );
3422
3423 // small edge texture
3424 if ( !e && !w )
3425 {
3426 t->vertexUV( ix0, y + 1, z1, iu0, iv0 );
3427 t->vertexUV( ix0, y + 0, z1, iu0, iv2 );
3428 t->vertexUV( ix1, y + 0, z1, iu1, iv2 );
3429 t->vertexUV( ix1, y + 1, z1, iu1, iv0 );
3430
3431 t->vertexUV( ix1, y + 1, z1, iu0, iv0 );
3432 t->vertexUV( ix1, y + 0, z1, iu0, iv2 );
3433 t->vertexUV( ix0, y + 0, z1, iu1, iv2 );
3434 t->vertexUV( ix0, y + 1, z1, iu1, iv0 );
3435 }
3436
3437 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z - 1 ) ) )
3438 {
3439 // small edge texture
3440 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv0 );
3441 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv1 );
3442 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv1 );
3443 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv0 );
3444
3445 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv0 );
3446 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv1 );
3447 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv1 );
3448 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv0 );
3449 }
3450
3451 if ( down || ( y > 1 && level->isEmptyTile( x, y - 1, z - 1 ) ) )
3452 {
3453 // small edge texture
3454 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv0 );
3455 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv1 );
3456 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv1 );
3457 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv0 );
3458
3459 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv0 );
3460 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv1 );
3461 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv1 );
3462 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv0 );
3463 }
3464
3465 }
3466 else if ( !n && s )
3467 {
3468 // half-step towards south
3469 t->vertexUV( x1, y + 1, z1, u1, v0 );
3470 t->vertexUV( x1, y + 0, z1, u1, v2 );
3471 t->vertexUV( x1, y + 0, z2, u2, v2 );
3472 t->vertexUV( x1, y + 1, z2, u2, v0 );
3473
3474 t->vertexUV( x1, y + 1, z2, u1, v0 );
3475 t->vertexUV( x1, y + 0, z2, u1, v2 );
3476 t->vertexUV( x1, y + 0, z1, u2, v2 );
3477 t->vertexUV( x1, y + 1, z1, u2, v0 );
3478
3479 // small edge texture
3480 if ( !e && !w )
3481 {
3482 t->vertexUV( ix1, y + 1, z1, iu0, iv0 );
3483 t->vertexUV( ix1, y + 0, z1, iu0, iv2 );
3484 t->vertexUV( ix0, y + 0, z1, iu1, iv2 );
3485 t->vertexUV( ix0, y + 1, z1, iu1, iv0 );
3486
3487 t->vertexUV( ix0, y + 1, z1, iu0, iv0 );
3488 t->vertexUV( ix0, y + 0, z1, iu0, iv2 );
3489 t->vertexUV( ix1, y + 0, z1, iu1, iv2 );
3490 t->vertexUV( ix1, y + 1, z1, iu1, iv0 );
3491 }
3492
3493 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z + 1 ) ) )
3494 {
3495 // small edge texture
3496 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv1 );
3497 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv2 );
3498 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv2 );
3499 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv1 );
3500
3501 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv1 );
3502 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv2 );
3503 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv2 );
3504 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv1 );
3505 }
3506 if ( down || ( y > 1 && level->isEmptyTile( x, y - 1, z + 1 ) ) )
3507 {
3508 // small edge texture
3509 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv1 );
3510 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv2 );
3511 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv2 );
3512 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv1 );
3513
3514 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv1 );
3515 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv2 );
3516 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv2 );
3517 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv1 );
3518 }
3519
3520 }
3521#endif // DISABLE_TESS_FUNCS
3522
3523 return true;
3524}
3525
3526bool TileRenderer_SPU::tesselateCrossInWorld( Tile_SPU* tt, int x, int y, int z )
3527{
3528 Tesselator_SPU* t = getTesselator();
3529
3530 float br;
3531 if ( SharedConstants::TEXTURE_LIGHTING )
3532 {
3533 t->tex2( tt->getLightColor( level, x, y, z ) );
3534 br = 1;
3535 }
3536 else
3537 {
3538 br = tt->getBrightness( level, x, y, z );
3539 }
3540
3541 int col = tt->getColor( level, x, y, z );
3542 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
3543 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
3544 float b = ( ( col )& 0xff ) / 255.0f;
3545
3546 if ( isAnaglyph3d() )
3547 {
3548 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
3549 float cg = ( r * 30 + g * 70 ) / ( 100 );
3550 float cb = ( r * 30 + b * 70 ) / ( 100 );
3551
3552 r = cr;
3553 g = cg;
3554 b = cb;
3555 }
3556 t->color( br * r, br * g, br * b );
3557
3558 float xt = (float)x;
3559 float yt = (float)y;
3560 float zt = (float)z;
3561
3562 if (tt->id == Tile_SPU::tallgrass_Id)
3563 {
3564 int64_t seed = (x * 3129871) ^ (z * 116129781l) ^ (y);
3565 seed = seed * seed * 42317861 + seed * 11;
3566
3567 xt += ((((seed >> 16) & 0xf) / 15.0f) - 0.5f) * 0.5f;
3568 yt += ((((seed >> 20) & 0xf) / 15.0f) - 1.0f) * 0.2f;
3569 zt += ((((seed >> 24) & 0xf) / 15.0f) - 0.5f) * 0.5f;
3570 }
3571
3572 tesselateCrossTexture( tt, level->getData( x, y, z ), xt, yt, zt, 1 );
3573 return true;
3574}
3575
3576bool TileRenderer_SPU::tesselateStemInWorld( Tile_SPU* _tt, int x, int y, int z )
3577{
3578 StemTile_SPU* tt = ( StemTile_SPU* )_tt;
3579 Tesselator_SPU* t = getTesselator();
3580
3581 float br;
3582 if ( SharedConstants::TEXTURE_LIGHTING )
3583 {
3584 t->tex2( tt->getLightColor( level, x, y, z ) );
3585 br = 1;
3586 }
3587 else
3588 {
3589 br = tt->getBrightness( level, x, y, z );
3590 }
3591 int col = tt->getColor( level, x, y, z );
3592 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
3593 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
3594 float b = ( ( col )& 0xff ) / 255.0f;
3595
3596 if ( isAnaglyph3d())
3597 {
3598 float cr = ( r * 30.0f + g * 59.0f + b * 11.0f ) / 100.0f;
3599 float cg = ( r * 30.0f + g * 70.0f ) / ( 100.0f );
3600 float cb = ( r * 30.0f + b * 70.0f ) / ( 100.0f );
3601
3602 r = cr;
3603 g = cg;
3604 b = cb;
3605 }
3606 t->color( br * r, br * g, br * b );
3607
3608 tt->updateShape( level, x, y, z );
3609 int dir = tt->getConnectDir( level, x, y, z );
3610 if ( dir < 0 )
3611 {
3612 tesselateStemTexture( tt, level->getData( x, y, z ), tileShapeY1, x, y - 1 / 16.0f, z );
3613 }
3614 else
3615 {
3616 tesselateStemTexture( tt, level->getData( x, y, z ), 0.5f, x, y - 1 / 16.0f, z );
3617 tesselateStemDirTexture( tt, level->getData( x, y, z ), dir, tileShapeY1, x, y - 1 / 16.0f, z );
3618 }
3619 return true;
3620}
3621
3622bool TileRenderer_SPU::tesselateRowInWorld( Tile_SPU* tt, int x, int y, int z )
3623{
3624 Tesselator_SPU* t = getTesselator();
3625
3626 if ( SharedConstants::TEXTURE_LIGHTING )
3627 {
3628 t->tex2( tt->getLightColor( level, x, y, z ) );
3629 t->color( 1.0f, 1.0f, 1.0f );
3630 }
3631 else
3632 {
3633 float br = tt->getBrightness( level, x, y, z );
3634 t->color( br, br, br );
3635 }
3636
3637 tesselateRowTexture( tt, level->getData( x, y, z ), x, y - 1.0f / 16.0f, z );
3638 return true;
3639}
3640
3641void TileRenderer_SPU::tesselateTorch( Tile_SPU* tt, float x, float y, float z, float xxa, float zza, int data )
3642{
3643 Tesselator_SPU* t = getTesselator();
3644
3645 Icon_SPU *tex = getTexture(tt, Facing::DOWN, data);
3646
3647 if (hasFixedTexture()) tex = fixedTexture;
3648 float u0 = tex->getU0();
3649 float v0 = tex->getV0();
3650 float u1 = tex->getU1();
3651 float v1 = tex->getV1();
3652
3653 float ut0 = tex->getU(7);
3654 float vt0 = tex->getV(6);
3655 float ut1 = tex->getU(9);
3656 float vt1 = tex->getV(8);
3657
3658 float ub0 = tex->getU(7);
3659 float vb0 = tex->getV(13);
3660 float ub1 = tex->getU(9);
3661 float vb1 = tex->getV(15);
3662
3663 x += 0.5f;
3664 z += 0.5f;
3665
3666 float x0 = x - 0.5f;
3667 float x1 = x + 0.5f;
3668 float z0 = z - 0.5f;
3669 float z1 = z + 0.5f;
3670 float r = 1 / 16.0f;
3671
3672 float h = 10.0f / 16.0f;
3673 t->vertexUV( ( float )( x + xxa * ( 1 - h ) - r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) - r ), ut0, vt0 );
3674 t->vertexUV( ( float )( x + xxa * ( 1 - h ) - r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) + r ), ut0, vt1 );
3675 t->vertexUV( ( float )( x + xxa * ( 1 - h ) + r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) + r ), ut1, vt1 );
3676 t->vertexUV( ( float )( x + xxa * ( 1 - h ) + r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) - r ), ut1, vt0 );
3677
3678 t->vertexUV( (float)(x + r + xxa), (float) y, (float)(z - r + zza), ub1, vb0);
3679 t->vertexUV( (float)(x + r + xxa), (float) y, (float)(z + r + zza), ub1, vb1);
3680 t->vertexUV( (float)(x - r + xxa), (float) y, (float)(z + r + zza), ub0, vb1);
3681 t->vertexUV( (float)(x - r + xxa), (float) y, (float)(z - r + zza), ub0, vb0);
3682
3683 t->vertexUV( ( float )( x - r ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3684 t->vertexUV( ( float )( x - r + xxa ), ( float )( y + 0 ), ( float )( z0 +
3685 zza ), ( float )( u0 ), ( float )( v1 ) );
3686 t->vertexUV( ( float )( x - r + xxa ), ( float )( y + 0 ), ( float )( z1 +
3687 zza ), ( float )( u1 ), ( float )( v1 ) );
3688 t->vertexUV( ( float )( x - r ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3689
3690 t->vertexUV( ( float )( x + r ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3691 t->vertexUV( ( float )( x + xxa + r ), ( float )( y + 0 ), ( float )( z1 +
3692 zza ), ( float )( u0 ), ( float )( v1 ) );
3693 t->vertexUV( ( float )( x + xxa + r ), ( float )( y + 0 ), ( float )( z0 +
3694 zza ), ( float )( u1 ), ( float )( v1 ) );
3695 t->vertexUV( ( float )( x + r ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3696
3697 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z + r ), ( float )( u0 ), ( float )( v0 ) );
3698 t->vertexUV( ( float )( x0 + xxa ), ( float )( y + 0 ), ( float )( z + r +
3699 zza ), ( float )( u0 ), ( float )( v1 ) );
3700 t->vertexUV( ( float )( x1 + xxa ), ( float )( y + 0 ), ( float )( z + r +
3701 zza ), ( float )( u1 ), ( float )( v1 ) );
3702 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z + r ), ( float )( u1 ), ( float )( v0 ) );
3703
3704 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z - r ), ( float )( u0 ), ( float )( v0 ) );
3705 t->vertexUV( ( float )( x1 + xxa ), ( float )( y + 0 ), ( float )( z - r +
3706 zza ), ( float )( u0 ), ( float )( v1 ) );
3707 t->vertexUV( ( float )( x0 + xxa ), ( float )( y + 0 ), ( float )( z - r +
3708 zza ), ( float )( u1 ), ( float )( v1 ) );
3709 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z - r ), ( float )( u1 ), ( float )( v0 ) );
3710}
3711
3712void TileRenderer_SPU::tesselateCrossTexture( Tile_SPU* tt, int data, float x, float y, float z, float scale )
3713{
3714 Tesselator_SPU* t = getTesselator();
3715
3716 Icon_SPU *tex = getTexture(tt, 0, data);
3717
3718 if (hasFixedTexture()) tex = fixedTexture;
3719 float u0 = tex->getU0();
3720 float v0 = tex->getV0();
3721 float u1 = tex->getU1();
3722 float v1 = tex->getV1();
3723
3724 float width = 0.45 * scale;
3725 float x0 = x + 0.5 - width;
3726 float x1 = x + 0.5 + width;
3727 float z0 = z + 0.5 - width;
3728 float z1 = z + 0.5 + width;
3729
3730 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3731 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
3732 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3733 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3734
3735 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3736 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
3737 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
3738 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3739
3740 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3741 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
3742 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
3743 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3744
3745 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3746 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
3747 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3748 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3749}
3750
3751void TileRenderer_SPU::tesselateStemTexture( Tile_SPU* tt, int data, float h, float x, float y, float z )
3752{
3753// #ifdef DISABLE_TESS_FUNCS
3754 Tesselator_SPU* t = getTesselator();
3755
3756 Icon_SPU *tex = getTexture(tt, 0, data);
3757
3758 if (hasFixedTexture()) tex = fixedTexture;
3759 float u0 = tex->getU0();
3760 float v0 = tex->getV0();
3761 float u1 = tex->getU1();
3762 float v1 = tex->getV(h * SharedConstants::WORLD_RESOLUTION);
3763
3764 float x0 = x + 0.5f - 0.45f;
3765 float x1 = x + 0.5f + 0.45f;
3766 float z0 = z + 0.5f - 0.45f;
3767 float z1 = z + 0.5f + 0.45f;
3768
3769 t->vertexUV( x0, y + h, z0, u0, v0 );
3770 t->vertexUV( x0, y + 0, z0, u0, v1 );
3771 t->vertexUV( x1, y + 0, z1, u1, v1 );
3772 t->vertexUV( x1, y + h, z1, u1, v0 );
3773
3774 t->vertexUV( x1, y + h, z1, u0, v0 );
3775 t->vertexUV( x1, y + 0, z1, u0, v1 );
3776 t->vertexUV( x0, y + 0, z0, u1, v1 );
3777 t->vertexUV( x0, y + h, z0, u1, v0 );
3778
3779 t->vertexUV( x0, y + h, z1, u0, v0 );
3780 t->vertexUV( x0, y + 0, z1, u0, v1 );
3781 t->vertexUV( x1, y + 0, z0, u1, v1 );
3782 t->vertexUV( x1, y + h, z0, u1, v0 );
3783
3784 t->vertexUV( x1, y + h, z0, u0, v0 );
3785 t->vertexUV( x1, y + 0, z0, u0, v1 );
3786 t->vertexUV( x0, y + 0, z1, u1, v1 );
3787 t->vertexUV( x0, y + h, z1, u1, v0 );
3788// #endif // DISABLE_TESS_FUNCS
3789}
3790
3791bool TileRenderer_SPU::tesselateLilypadInWorld(WaterlilyTile_SPU *tt, int x, int y, int z)
3792{
3793 Tesselator_SPU* t = getTesselator();
3794
3795 Icon_SPU *tex = getTexture(tt, Facing::UP);
3796
3797 if (hasFixedTexture()) tex = fixedTexture;
3798 float h = 0.25f / 16.0f;
3799
3800 float u0 = tex->getU0();
3801 float v0 = tex->getV0();
3802 float u1 = tex->getU1();
3803 float v1 = tex->getV1();
3804
3805 int64_t seed = (x * 3129871) ^ (z * 116129781l) ^ (y);
3806 seed = seed * seed * 42317861 + seed * 11;
3807
3808 int dir = (int) ((seed >> 16) & 0x3);
3809
3810
3811
3812 t->tex2(tt->getLightColor(level, x, y, z));
3813
3814 float xx = x + 0.5f;
3815 float zz = z + 0.5f;
3816 float c = ((dir & 1) * 0.5f) * (1 - dir / 2 % 2 * 2);
3817 float s = (((dir + 1) & 1) * 0.5f) * (1 - (dir + 1) / 2 % 2 * 2);
3818
3819 t->color(tt->getColor());
3820 t->vertexUV(xx + c - s, y + h, zz + c + s, u0, v0);
3821 t->vertexUV(xx + c + s, y + h, zz - c + s, u1, v0);
3822 t->vertexUV(xx - c + s, y + h, zz - c - s, u1, v1);
3823 t->vertexUV(xx - c - s, y + h, zz + c - s, u0, v1);
3824
3825 t->color((tt->getColor() & 0xfefefe) >> 1);
3826 t->vertexUV(xx - c - s, y + h, zz + c - s, u0, v1);
3827 t->vertexUV(xx - c + s, y + h, zz - c - s, u1, v1);
3828 t->vertexUV(xx + c + s, y + h, zz - c + s, u1, v0);
3829 t->vertexUV(xx + c - s, y + h, zz + c + s, u0, v0);
3830
3831 return true;
3832}
3833
3834void TileRenderer_SPU::tesselateStemDirTexture( StemTile_SPU* tt, int data, int dir, float h, float x, float y, float z )
3835{
3836 Tesselator_SPU* t = getTesselator();
3837
3838 Icon_SPU *tex = tt->getAngledTexture();
3839
3840 if (hasFixedTexture()) tex = fixedTexture;
3841 float u0 = tex->getU0();
3842 float v0 = tex->getV0();
3843 float u1 = tex->getU1();
3844 float v1 = tex->getV1();
3845
3846 float x0 = x + 0.5f - 0.5f;
3847 float x1 = x + 0.5f + 0.5f;
3848 float z0 = z + 0.5f - 0.5f;
3849 float z1 = z + 0.5f + 0.5f;
3850
3851 float xm = x + 0.5f;
3852 float zm = z + 0.5f;
3853
3854 if ( ( dir + 1 ) / 2 % 2 == 1 )
3855 {
3856 float tmp = u1;
3857 u1 = u0;
3858 u0 = tmp;
3859 }
3860
3861 if ( dir < 2 )
3862 {
3863 t->vertexUV( x0, y + h, zm, u0, v0 );
3864 t->vertexUV( x0, y + 0, zm, u0, v1 );
3865 t->vertexUV( x1, y + 0, zm, u1, v1 );
3866 t->vertexUV( x1, y + h, zm, u1, v0 );
3867
3868 t->vertexUV( x1, y + h, zm, u1, v0 );
3869 t->vertexUV( x1, y + 0, zm, u1, v1 );
3870 t->vertexUV( x0, y + 0, zm, u0, v1 );
3871 t->vertexUV( x0, y + h, zm, u0, v0 );
3872 }
3873 else
3874 {
3875 t->vertexUV( xm, y + h, z1, u0, v0 );
3876 t->vertexUV( xm, y + 0, z1, u0, v1 );
3877 t->vertexUV( xm, y + 0, z0, u1, v1 );
3878 t->vertexUV( xm, y + h, z0, u1, v0 );
3879
3880 t->vertexUV( xm, y + h, z0, u1, v0 );
3881 t->vertexUV( xm, y + 0, z0, u1, v1 );
3882 t->vertexUV( xm, y + 0, z1, u0, v1 );
3883 t->vertexUV( xm, y + h, z1, u0, v0 );
3884 }
3885}
3886
3887
3888void TileRenderer_SPU::tesselateRowTexture( Tile_SPU* tt, int data, float x, float y, float z )
3889{
3890 Tesselator_SPU* t = getTesselator();
3891
3892 Icon_SPU *tex = getTexture(tt, 0, data);
3893
3894 if (hasFixedTexture()) tex = fixedTexture;
3895 float u0 = tex->getU0();
3896 float v0 = tex->getV0();
3897 float u1 = tex->getU1();
3898 float v1 = tex->getV1();
3899
3900 float x0 = x + 0.5f - 0.25f;
3901 float x1 = x + 0.5f + 0.25f;
3902 float z0 = z + 0.5f - 0.5f;
3903 float z1 = z + 0.5f + 0.5f;
3904
3905 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3906 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
3907 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3908 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3909
3910 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3911 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
3912 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
3913 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3914
3915 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3916 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
3917 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
3918 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3919
3920 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3921 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
3922 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3923 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3924
3925 x0 = x + 0.5f - 0.5f;
3926 x1 = x + 0.5f + 0.5f;
3927 z0 = z + 0.5f - 0.25f;
3928 z1 = z + 0.5f + 0.25f;
3929
3930 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3931 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
3932 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
3933 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3934
3935 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
3936 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
3937 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
3938 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3939
3940 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3941 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
3942 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3943 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3944
3945 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
3946 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
3947 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3948 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
3949
3950}
3951
3952bool TileRenderer_SPU::tesselateWaterInWorld( Tile_SPU* tt, int x, int y, int z )
3953{
3954 // 4J Java comment
3955 // TODO: This all needs to change. Somehow.
3956 Tesselator_SPU* t = getTesselator();
3957
3958 int col = tt->getColor( level, x, y, z );
3959 float r = ( col >> 16 & 0xff ) / 255.0f;
3960 float g = ( col >> 8 & 0xff ) / 255.0f;
3961 float b = ( col & 0xff ) / 255.0f;
3962 bool up = tt->shouldRenderFace( level, x, y + 1, z, 1 );
3963 bool down = tt->shouldRenderFace( level, x, y - 1, z, 0 );
3964 bool dirs[4];
3965 dirs[0] = tt->shouldRenderFace( level, x, y, z - 1, 2 );
3966 dirs[1] = tt->shouldRenderFace( level, x, y, z + 1, 3 );
3967 dirs[2] = tt->shouldRenderFace( level, x - 1, y, z, 4 );
3968 dirs[3] = tt->shouldRenderFace( level, x + 1, y, z, 5 );
3969
3970 if ( !up && !down && !dirs[0] && !dirs[1] && !dirs[2] && !dirs[3] ) return false;
3971
3972 bool changed = false;
3973 float c10 = 0.5f;
3974 float c11 = 1;
3975 float c2 = 0.8f;
3976 float c3 = 0.6f;
3977
3978 float yo0 = 0;
3979 float yo1 = 1;
3980
3981 Material_SPU* m = tt->getMaterial();
3982 int data = level->getData( x, y, z );
3983
3984 float h0 = getWaterHeight( x, y, z, m );
3985 float h1 = getWaterHeight( x, y, z + 1, m );
3986 float h2 = getWaterHeight( x + 1, y, z + 1, m );
3987 float h3 = getWaterHeight( x + 1, y, z, m );
3988
3989 float offs = 0.001f;
3990 // 4J - added. Farm tiles often found beside water, but they consider themselves non-solid as they only extend up to 15.0f / 16.0f.
3991 // If the max height of this water is below that level, don't bother rendering sides bordering onto farmland.
3992 float maxh = h0;
3993 if ( h1 > maxh ) maxh = h1;
3994 if ( h2 > maxh ) maxh = h2;
3995 if ( h3 > maxh ) maxh = h3;
3996 if ( maxh <= ( 15.0f / 16.0f ) )
3997 {
3998 if ( level->getTile( x, y, z - 1 ) == Tile_SPU::farmland_Id )
3999 {
4000 dirs[0] = false;
4001 }
4002 if ( level->getTile( x, y, z + 1 ) == Tile_SPU::farmland_Id )
4003 {
4004 dirs[1] = false;
4005 }
4006 if ( level->getTile( x - 1, y, z ) == Tile_SPU::farmland_Id )
4007 {
4008 dirs[2] = false;
4009 }
4010 if ( level->getTile( x + 1, y, z ) == Tile_SPU::farmland_Id )
4011 {
4012 dirs[3] = false;
4013 }
4014 }
4015
4016 if ( noCulling || up )
4017 {
4018 changed = true;
4019 Icon_SPU *tex = getTexture( tt, 1, data );
4020 float angle = ( float )LiquidTile_SPU::getSlopeAngle( level, x, y, z, m );
4021 if ( angle > -999 )
4022 {
4023 tex = getTexture( tt, 2, data );
4024 }
4025
4026 h0 -= offs;
4027 h1 -= offs;
4028 h2 -= offs;
4029 h3 -= offs;
4030
4031 float u00, u01, u10, u11;
4032 float v00, v01, v10, v11;
4033 if ( angle < -999 )
4034 {
4035 u00 = tex->getU(0);
4036 v00 = tex->getV(0);
4037 u01 = u00;
4038 v01 = tex->getV(SharedConstants::WORLD_RESOLUTION);
4039 u10 = tex->getU(SharedConstants::WORLD_RESOLUTION);
4040 v10 = v01;
4041 u11 = u10;
4042 v11 = v00;
4043 }
4044 else
4045 {
4046 float s = sinf(angle) * .25f;
4047 float c = cosf(angle) * .25f;
4048 float cc = SharedConstants::WORLD_RESOLUTION * .5f;
4049 u00 = tex->getU(cc + (-c - s) * SharedConstants::WORLD_RESOLUTION);
4050 v00 = tex->getV(cc + (-c + s) * SharedConstants::WORLD_RESOLUTION);
4051 u01 = tex->getU(cc + (-c + s) * SharedConstants::WORLD_RESOLUTION);
4052 v01 = tex->getV(cc + (+c + s) * SharedConstants::WORLD_RESOLUTION);
4053 u10 = tex->getU(cc + (+c + s) * SharedConstants::WORLD_RESOLUTION);
4054 v10 = tex->getV(cc + (+c - s) * SharedConstants::WORLD_RESOLUTION);
4055 u11 = tex->getU(cc + (+c - s) * SharedConstants::WORLD_RESOLUTION);
4056 v11 = tex->getV(cc + (-c - s) * SharedConstants::WORLD_RESOLUTION);
4057 }
4058
4059 float br;
4060 if ( SharedConstants::TEXTURE_LIGHTING )
4061 {
4062 t->tex2( tt->getLightColor( level, x, y, z ) );
4063 br = 1;
4064 }
4065 else
4066 {
4067 br = tt->getBrightness( level, x, y, z );
4068 }
4069 t->color( c11 * br * r, c11 * br * g, c11 * br * b );
4070 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h0 ), ( float )( z + 0.0f ), u00, v00 );
4071 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h1 ), ( float )( z + 1.0f ), u01, v01 );
4072 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h2 ), ( float )( z + 1.0f ), u10, v10 );
4073 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h3 ), ( float )( z + 0.0f ), u11, v11 );
4074 }
4075
4076 if ( noCulling || down )
4077 {
4078 float br;
4079 if ( SharedConstants::TEXTURE_LIGHTING )
4080 {
4081 t->tex2( tt->getLightColor( level, x, y - 1, z ) );
4082 br = 1;
4083 }
4084 else
4085 {
4086 br = tt->getBrightness( level, x, y - 1, z );
4087 }
4088 t->color( c10 * br, c10 * br, c10 * br );
4089 renderFaceDown( tt, x, y + offs, z, getTexture( tt, 0 ) );
4090 changed = true;
4091 }
4092
4093 for ( int face = 0; face < 4; face++ )
4094 {
4095 int xt = x;
4096 int yt = y;
4097 int zt = z;
4098
4099 if ( face == 0 ) zt--;
4100 if ( face == 1 ) zt++;
4101 if ( face == 2 ) xt--;
4102 if ( face == 3 ) xt++;
4103
4104 Icon_SPU *tex = getTexture(tt, face + 2, data);
4105
4106 if ( noCulling || dirs[face] )
4107 {
4108 float hh0;
4109 float hh1;
4110 float x0, z0, x1, z1;
4111 if ( face == 0 )
4112 {
4113 hh0 = ( float )( h0 );
4114 hh1 = ( float )( h3 );
4115 x0 = ( float )( x );
4116 x1 = ( float )( x + 1 );
4117 z0 = ( float )( z + offs);
4118 z1 = ( float )( z + offs);
4119 }
4120 else if ( face == 1 )
4121 {
4122 hh0 = ( float )( h2 );
4123 hh1 = ( float )( h1 );
4124 x0 = ( float )( x + 1 );
4125 x1 = ( float )( x );
4126 z0 = ( float )( z + 1 - offs);
4127 z1 = ( float )( z + 1 - offs);
4128 }
4129 else if ( face == 2 )
4130 {
4131 hh0 = ( float )( h1 );
4132 hh1 = ( float )( h0 );
4133 x0 = ( float )( x + offs);
4134 x1 = ( float )( x + offs);
4135 z0 = ( float )( z + 1 );
4136 z1 = ( float )( z );
4137 }
4138 else
4139 {
4140 hh0 = ( float )( h3 );
4141 hh1 = ( float )( h2 );
4142 x0 = ( float )( x + 1 - offs);
4143 x1 = ( float )( x + 1 - offs);
4144 z0 = ( float )( z );
4145 z1 = ( float )( z + 1 );
4146 }
4147
4148
4149 changed = true;
4150 float u0 = tex->getU(0);
4151 float u1 = tex->getU(SharedConstants::WORLD_RESOLUTION * .5f);
4152
4153// int yTex = tex->getY();
4154 float v01 = tex->getV((1 - hh0) * SharedConstants::WORLD_RESOLUTION * .5f);
4155 float v02 = tex->getV((1 - hh1) * SharedConstants::WORLD_RESOLUTION * .5f);
4156 float v1 = tex->getV(SharedConstants::WORLD_RESOLUTION * .5f);
4157
4158 float br;
4159 if ( SharedConstants::TEXTURE_LIGHTING )
4160 {
4161 t->tex2( tt->getLightColor( level, xt, yt, zt ) );
4162 br = 1;
4163 }
4164 else
4165 {
4166 br = tt->getBrightness( level, xt, yt, zt );
4167 }
4168 if ( face < 2 ) br *= c2;
4169 else
4170 br *= c3;
4171
4172 t->color( c11 * br * r, c11 * br * g, c11 * br * b );
4173 t->vertexUV( ( float )( x0 ), ( float )( y + hh0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v01 ) );
4174 t->vertexUV( ( float )( x1 ), ( float )( y + hh1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v02 ) );
4175 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4176 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4177
4178 }
4179
4180 }
4181
4182 tileShapeY0 = yo0;
4183 tileShapeY1 = yo1;
4184
4185 return changed;
4186}
4187
4188float TileRenderer_SPU::getWaterHeight( int x, int y, int z, Material_SPU* m )
4189{
4190 int count = 0;
4191 float h = 0;
4192 for ( int i = 0; i < 4; i++ )
4193 {
4194 int xx = x - ( i & 1 );
4195 int yy = y;
4196 int zz = z - ( ( i >> 1 ) & 1 );
4197 if ( level->getMaterial( xx, yy + 1, zz ) == m )
4198 {
4199 return 1;
4200 }
4201 Material_SPU* tm = level->getMaterial( xx, yy, zz );
4202 if ( tm == m )
4203 {
4204 int d = level->getData( xx, yy, zz );
4205 if ( d >= 8 || d == 0 )
4206 {
4207 h += ( LiquidTile_SPU::getHeight( d ) )* 10;
4208 count += 10;
4209 }
4210 h += LiquidTile_SPU::getHeight( d );
4211 count++;
4212 }
4213 else if ( !tm->isSolid() )
4214 {
4215 h += 1;
4216 count++;
4217 }
4218 }
4219 return 1 - h / count;
4220}
4221
4222void TileRenderer_SPU::renderBlock( Tile_SPU* tt, ChunkRebuildData* level, int x, int y, int z )
4223{
4224 renderBlock(tt, level, x, y, z, 0);
4225}
4226
4227void TileRenderer_SPU::renderBlock(Tile_SPU *tt, ChunkRebuildData *level, int x, int y, int z, int data)
4228{
4229 float c10 = 0.5f;
4230 float c11 = 1;
4231 float c2 = 0.8f;
4232 float c3 = 0.6f;
4233
4234 Tesselator_SPU* t = getTesselator();
4235 t->begin();
4236 if ( SharedConstants::TEXTURE_LIGHTING )
4237 {
4238 t->tex2( tt->getLightColor( level, x, y, z ) );
4239 }
4240 float center = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y, z );
4241 float br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y - 1, z );
4242
4243 if ( br < center ) br = center;
4244 t->color( c10 * br, c10 * br, c10 * br );
4245 renderFaceDown( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 0, data ) );
4246
4247 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y + 1, z );
4248 if ( br < center ) br = center;
4249 t->color( c11 * br, c11 * br, c11 * br );
4250 renderFaceUp( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 1, data ) );
4251
4252 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y, z - 1 );
4253 if ( br < center ) br = center;
4254 t->color( c2 * br, c2 * br, c2 * br );
4255 renderNorth( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 2, data ) );
4256
4257 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y, z + 1 );
4258 if ( br < center ) br = center;
4259 t->color( c2 * br, c2 * br, c2 * br );
4260 renderSouth( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 3, data ) );
4261
4262 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x - 1, y, z );
4263 if ( br < center ) br = center;
4264 t->color( c3 * br, c3 * br, c3 * br );
4265 renderWest( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 4, data ) );
4266
4267 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x + 1, y, z );
4268 if ( br < center ) br = center;
4269 t->color( c3 * br, c3 * br, c3 * br );
4270 renderEast( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 5, data ) );
4271 t->end();
4272
4273}
4274
4275bool TileRenderer_SPU::tesselateBlockInWorld( Tile_SPU* tt, int x, int y, int z )
4276{
4277 int col = tt->getColor( level, x, y, z );
4278 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
4279 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
4280 float b = ( ( col )& 0xff ) / 255.0f;
4281
4282 if ( isAnaglyph3d())
4283 {
4284 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
4285 float cg = ( r * 30 + g * 70 ) / ( 100 );
4286 float cb = ( r * 30 + b * 70 ) / ( 100 );
4287
4288 r = cr;
4289 g = cg;
4290 b = cb;
4291 }
4292
4293 if ( level->m_tileData.lightEmission[tt->id] == 0 )//4J - TODO/remove (Minecraft::useAmbientOcclusion())
4294 {
4295 if ( SharedConstants::TEXTURE_LIGHTING )
4296 {
4297 return tesselateBlockInWorldWithAmbienceOcclusionTexLighting( tt, x, y, z, r, g, b );
4298 }
4299 else
4300 {
4301 return tesselateBlockInWorldWithAmbienceOcclusionOldLighting( tt, x, y, z, r, g, b );
4302 }
4303 }
4304 else
4305 {
4306 return tesselateBlockInWorld( tt, x, y, z, r, g, b );
4307 }
4308}
4309
4310bool TileRenderer_SPU::tesselateTreeInWorld(Tile_SPU *tt, int x, int y, int z)
4311{
4312 int data = level->getData(x, y, z);
4313 int facing = data & TreeTile_SPU::MASK_FACING;
4314
4315 if (facing == TreeTile_SPU::FACING_X)
4316 {
4317 northFlip = FLIP_CW;
4318 southFlip = FLIP_CW;
4319 upFlip = FLIP_CW;
4320 downFlip = FLIP_CW;
4321 }
4322 else if (facing == TreeTile_SPU::FACING_Z)
4323 {
4324 eastFlip = FLIP_CW;
4325 westFlip = FLIP_CW;
4326 }
4327
4328 bool result = tesselateBlockInWorld(tt, x, y, z);
4329
4330 eastFlip = 0;
4331 northFlip = 0;
4332 southFlip = 0;
4333 westFlip = 0;
4334 upFlip = 0;
4335 downFlip = 0;
4336
4337 return result;
4338}
4339
4340bool TileRenderer_SPU::tesselateQuartzInWorld(Tile_SPU *tt, int x, int y, int z)
4341{
4342 int data = level->getData(x, y, z);
4343
4344 if (data == QuartzBlockTile_SPU::TYPE_LINES_X)
4345 {
4346 northFlip = FLIP_CW;
4347 southFlip = FLIP_CW;
4348 upFlip = FLIP_CW;
4349 downFlip = FLIP_CW;
4350 }
4351 else if (data == QuartzBlockTile_SPU::TYPE_LINES_Z)
4352 {
4353 eastFlip = FLIP_CW;
4354 westFlip = FLIP_CW;
4355 }
4356
4357 bool result = tesselateBlockInWorld(tt, x, y, z);
4358
4359 eastFlip = 0;
4360 northFlip = 0;
4361 southFlip = 0;
4362 westFlip = 0;
4363 upFlip = 0;
4364 downFlip = 0;
4365
4366 return result;
4367}
4368
4369bool TileRenderer_SPU::tesselateCocoaInWorld(CocoaTile_SPU *tt, int x, int y, int z)
4370{
4371#ifdef DISABLE_TESS_FUNCS
4372 Tesselator *t = Tesselator::getInstance();
4373
4374 if (SharedConstants::TEXTURE_LIGHTING)
4375 {
4376 t->tex2(tt->getLightColor(level, x, y, z));
4377 t->color(1.0f, 1.0f, 1.0f);
4378 }
4379 else
4380 {
4381 float br = tt->getBrightness(level, x, y, z);
4382 if (Tile::lightEmission[tt->id] > 0) br = 1.0f;
4383 t->color(br, br, br);
4384 }
4385
4386 int data = level->getData(x, y, z);
4387 int dir = DirectionalTile::getDirection(data);
4388 int age = CocoaTile::getAge(data);
4389 Icon *tex = tt->getTextureForAge(age);
4390
4391 int cocoaWidth = 4 + age * 2;
4392 int cocoaHeight = 5 + age * 2;
4393
4394 double us = 15.0 - cocoaWidth;
4395 double ue = 15.0;
4396 double vs = 4.0;
4397 double ve = 4.0 + cocoaHeight;
4398 double u0 = tex->getU(us, true);
4399 double u1 = tex->getU(ue, true);
4400 double v0 = tex->getV(vs, true);
4401 double v1 = tex->getV(ve, true);
4402
4403
4404 double offX = 0;
4405 double offZ = 0;
4406
4407 switch (dir)
4408 {
4409 case Direction::NORTH:
4410 offX = 8.0 - cocoaWidth / 2;
4411 offZ = 1.0;
4412 break;
4413 case Direction::SOUTH:
4414 offX = 8.0 - cocoaWidth / 2;
4415 offZ = 15.0 - cocoaWidth;
4416 break;
4417 case Direction::EAST:
4418 offX = 15.0 - cocoaWidth;
4419 offZ = 8.0 - cocoaWidth / 2;
4420 break;
4421 case Direction::WEST:
4422 offX = 1.0;
4423 offZ = 8.0 - cocoaWidth / 2;
4424 break;
4425 }
4426
4427 double x0 = x + offX / 16.0;
4428 double x1 = x + (offX + cocoaWidth) / 16.0;
4429 double y0 = y + (12.0 - cocoaHeight) / 16.0;
4430 double y1 = y + 12.0 / 16.0;
4431 double z0 = z + offZ / 16.0;
4432 double z1 = z + (offZ + cocoaWidth) / 16.0;
4433
4434 // west
4435 {
4436 t->vertexUV(x0, y0, z0, u0, v1);
4437 t->vertexUV(x0, y0, z1, u1, v1);
4438 t->vertexUV(x0, y1, z1, u1, v0);
4439 t->vertexUV(x0, y1, z0, u0, v0);
4440 }
4441 // east
4442 {
4443 t->vertexUV(x1, y0, z1, u0, v1);
4444 t->vertexUV(x1, y0, z0, u1, v1);
4445 t->vertexUV(x1, y1, z0, u1, v0);
4446 t->vertexUV(x1, y1, z1, u0, v0);
4447 }
4448 // north
4449 {
4450 t->vertexUV(x1, y0, z0, u0, v1);
4451 t->vertexUV(x0, y0, z0, u1, v1);
4452 t->vertexUV(x0, y1, z0, u1, v0);
4453 t->vertexUV(x1, y1, z0, u0, v0);
4454 }
4455 // south
4456 {
4457 t->vertexUV(x0, y0, z1, u0, v1);
4458 t->vertexUV(x1, y0, z1, u1, v1);
4459 t->vertexUV(x1, y1, z1, u1, v0);
4460 t->vertexUV(x0, y1, z1, u0, v0);
4461 }
4462
4463 int topWidth = cocoaWidth;
4464 if (age >= 2)
4465 {
4466 // special case because the top piece didn't fit
4467 topWidth--;
4468 }
4469
4470 u0 = tex->getU0(true);
4471 u1 = tex->getU(topWidth, true);
4472 v0 = tex->getV0(true);
4473 v1 = tex->getV(topWidth, true);
4474
4475 // top
4476 {
4477 t->vertexUV(x0, y1, z1, u0, v1);
4478 t->vertexUV(x1, y1, z1, u1, v1);
4479 t->vertexUV(x1, y1, z0, u1, v0);
4480 t->vertexUV(x0, y1, z0, u0, v0);
4481 }
4482 // bottom
4483 {
4484 t->vertexUV(x0, y0, z0, u0, v0);
4485 t->vertexUV(x1, y0, z0, u1, v0);
4486 t->vertexUV(x1, y0, z1, u1, v1);
4487 t->vertexUV(x0, y0, z1, u0, v1);
4488 }
4489
4490 // stalk
4491 u0 = tex->getU(12, true);
4492 u1 = tex->getU1(true);
4493 v0 = tex->getV0(true);
4494 v1 = tex->getV(4, true);
4495
4496 offX = 8;
4497 offZ = 0;
4498
4499 switch (dir)
4500 {
4501 case Direction::NORTH:
4502 offX = 8.0;
4503 offZ = 0.0;
4504 break;
4505 case Direction::SOUTH:
4506 offX = 8;
4507 offZ = 12;
4508 {
4509 double temp = u0;
4510 u0 = u1;
4511 u1 = temp;
4512 }
4513 break;
4514 case Direction::EAST:
4515 offX = 12.0;
4516 offZ = 8.0;
4517 {
4518 double temp = u0;
4519 u0 = u1;
4520 u1 = temp;
4521 }
4522 break;
4523 case Direction::WEST:
4524 offX = 0.0;
4525 offZ = 8.0;
4526 break;
4527 }
4528
4529 x0 = x + offX / 16.0;
4530 x1 = x + (offX + 4.0) / 16.0;
4531 y0 = y + 12.0 / 16.0;
4532 y1 = y + 16.0 / 16.0;
4533 z0 = z + offZ / 16.0;
4534 z1 = z + (offZ + 4.0) / 16.0;
4535 if (dir == Direction::NORTH || dir == Direction::SOUTH)
4536 {
4537 // west
4538 {
4539 t->vertexUV(x0, y0, z0, u1, v1);
4540 t->vertexUV(x0, y0, z1, u0, v1);
4541 t->vertexUV(x0, y1, z1, u0, v0);
4542 t->vertexUV(x0, y1, z0, u1, v0);
4543 }
4544 // east
4545 {
4546 t->vertexUV(x0, y0, z1, u0, v1);
4547 t->vertexUV(x0, y0, z0, u1, v1);
4548 t->vertexUV(x0, y1, z0, u1, v0);
4549 t->vertexUV(x0, y1, z1, u0, v0);
4550 }
4551 }
4552 else if (dir == Direction::WEST || dir == Direction::EAST)
4553 {
4554 // north
4555 {
4556 t->vertexUV(x1, y0, z0, u0, v1);
4557 t->vertexUV(x0, y0, z0, u1, v1);
4558 t->vertexUV(x0, y1, z0, u1, v0);
4559 t->vertexUV(x1, y1, z0, u0, v0);
4560 }
4561 // south
4562 {
4563 t->vertexUV(x0, y0, z0, u1, v1);
4564 t->vertexUV(x1, y0, z0, u0, v1);
4565 t->vertexUV(x1, y1, z0, u0, v0);
4566 t->vertexUV(x0, y1, z0, u1, v0);
4567 }
4568 }
4569
4570#endif // DISABLE_TESS_FUNCS
4571 return true;
4572}
4573
4574// 4J - brought changes forward from 1.8.2
4575bool TileRenderer_SPU::tesselateBlockInWorldWithAmbienceOcclusionTexLighting( Tile_SPU* tt, int pX, int pY, int pZ,
4576 float pBaseRed, float pBaseGreen,
4577 float pBaseBlue )
4578{
4579 // 4J - added these faceFlags so we can detect whether this block is going to have no visible faces and early out
4580 // the original code checked noCulling and shouldRenderFace directly where faceFlags is used now
4581 int faceFlags = 0;
4582 if ( noCulling )
4583 {
4584 faceFlags = 0x3f;
4585 }
4586 else
4587 {
4588/*#ifdef _DEBUG
4589 if(dynamic_cast<StairTile *>(tt)!=NULL)
4590 {
4591 // stair tile
4592 faceFlags |= tt->shouldRenderFace( level, pX, pY - 1, pZ, 0 ) ? 0x01 : 0;
4593 faceFlags |= tt->shouldRenderFace( level, pX, pY + 1, pZ, 1 ) ? 0x02 : 0;
4594 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ - 1, 2 ) ? 0x04 : 0;
4595 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ + 1, 3 ) ? 0x08 : 0;
4596 faceFlags |= tt->shouldRenderFace( level, pX - 1, pY, pZ, 4 ) ? 0x10 : 0;
4597 faceFlags |= tt->shouldRenderFace( level, pX + 1, pY, pZ, 5 ) ? 0x20 : 0;
4598
4599 printf("Stair tile\n");
4600 }
4601 else
4602 {
4603 faceFlags |= tt->shouldRenderFace( level, pX, pY - 1, pZ, 0 ) ? 0x01 : 0;
4604 faceFlags |= tt->shouldRenderFace( level, pX, pY + 1, pZ, 1 ) ? 0x02 : 0;
4605 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ - 1, 2 ) ? 0x04 : 0;
4606 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ + 1, 3 ) ? 0x08 : 0;
4607 faceFlags |= tt->shouldRenderFace( level, pX - 1, pY, pZ, 4 ) ? 0x10 : 0;
4608 faceFlags |= tt->shouldRenderFace( level, pX + 1, pY, pZ, 5 ) ? 0x20 : 0;
4609
4610 }
4611#else*/
4612 faceFlags |= tt->shouldRenderFace( level, pX, pY - 1, pZ, 0 ) ? 0x01 : 0;
4613 faceFlags |= tt->shouldRenderFace( level, pX, pY + 1, pZ, 1 ) ? 0x02 : 0;
4614 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ - 1, 2 ) ? 0x04 : 0;
4615 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ + 1, 3 ) ? 0x08 : 0;
4616 faceFlags |= tt->shouldRenderFace( level, pX - 1, pY, pZ, 4 ) ? 0x10 : 0;
4617 faceFlags |= tt->shouldRenderFace( level, pX + 1, pY, pZ, 5 ) ? 0x20 : 0;
4618//#endif
4619 }
4620 if ( faceFlags == 0 )
4621 {
4622 return false;
4623 }
4624
4625
4626 // If we are only rendering the bottom face and we're at the bottom of the world, we shouldn't be able to see this - don't render anything
4627 if( ( faceFlags == 1 ) && ( pY == 0 ) )
4628 {
4629 return false;
4630 }
4631
4632 applyAmbienceOcclusion = true;
4633 float ll1 = ll000;
4634 float ll2 = ll000;
4635 float ll3 = ll000;
4636 float ll4 = ll000;
4637 bool tint0 = true;
4638 bool tint1 = true;
4639 bool tint2 = true;
4640 bool tint3 = true;
4641 bool tint4 = true;
4642 bool tint5 = true;
4643
4644
4645 ll000 = tt->getShadeBrightness( level, pX, pY, pZ );
4646// Tile* t2 = Tile::tiles[tt->id];
4647// if(t2->getShadeBrightness(level->m_pRegion, pX, pY, pZ) != ll000)
4648// {
4649// app.DebugPrintf("Failed\n");
4650// ll000 = tt->getShadeBrightness( level, pX, pY, pZ );
4651// ll000 = t2->getShadeBrightness(level->m_pRegion, pX, pY, pZ);
4652// }
4653 llx00 = tt->getShadeBrightness( level, pX - 1, pY, pZ );
4654 ll0y0 = tt->getShadeBrightness( level, pX, pY - 1, pZ );
4655 ll00z = tt->getShadeBrightness( level, pX, pY, pZ - 1 );
4656 llX00 = tt->getShadeBrightness( level, pX + 1, pY, pZ );
4657 ll0Y0 = tt->getShadeBrightness( level, pX, pY + 1, pZ );
4658 ll00Z = tt->getShadeBrightness( level, pX, pY, pZ + 1 );
4659
4660
4661
4662 // 4J - these changes brought forward from 1.2.3
4663 int centerColor = tt->getLightColor( level, pX, pY, pZ );
4664 int ccx00 = centerColor;
4665 int cc0y0 = centerColor;
4666 int cc00z = centerColor;
4667 int ccX00 = centerColor;
4668 int cc0Y0 = centerColor;
4669 int cc00Z = centerColor;
4670
4671
4672 if (tileShapeY0 <= 0 || !level->isSolidRenderTile(pX, pY - 1, pZ)) cc0y0 = tt->getLightColor(level, pX, pY - 1, pZ);
4673 if (tileShapeY1 >= 1 || !level->isSolidRenderTile(pX, pY + 1, pZ)) cc0Y0 = tt->getLightColor(level, pX, pY + 1, pZ);
4674 if (tileShapeX0 <= 0 || !level->isSolidRenderTile(pX - 1, pY, pZ)) ccx00 = tt->getLightColor(level, pX - 1, pY, pZ);
4675 if (tileShapeX1 >= 1 || !level->isSolidRenderTile(pX + 1, pY, pZ)) ccX00 = tt->getLightColor(level, pX + 1, pY, pZ);
4676 if (tileShapeZ0 <= 0 || !level->isSolidRenderTile(pX, pY, pZ - 1)) cc00z = tt->getLightColor(level, pX, pY, pZ - 1);
4677 if (tileShapeZ1 >= 1 || !level->isSolidRenderTile(pX, pY, pZ + 1)) cc00Z = tt->getLightColor(level, pX, pY, pZ + 1);
4678
4679
4680 Tesselator_SPU* t = getTesselator();
4681 t->tex2( 0xf000f );
4682
4683 llTransXY0 = level->m_tileData.transculent[level->getTile( pX + 1, pY + 1, pZ )];
4684 llTransXy0 = level->m_tileData.transculent[level->getTile( pX + 1, pY - 1, pZ )];
4685 llTransX0Z = level->m_tileData.transculent[level->getTile( pX + 1, pY, pZ + 1 )];
4686 llTransX0z = level->m_tileData.transculent[level->getTile( pX + 1, pY, pZ - 1 )];
4687 llTransxY0 = level->m_tileData.transculent[level->getTile( pX - 1, pY + 1, pZ )];
4688 llTransxy0 = level->m_tileData.transculent[level->getTile( pX - 1, pY - 1, pZ )];
4689 llTransx0z = level->m_tileData.transculent[level->getTile( pX - 1, pY, pZ - 1 )];
4690 llTransx0Z = level->m_tileData.transculent[level->getTile( pX - 1, pY, pZ + 1 )];
4691 llTrans0YZ = level->m_tileData.transculent[level->getTile( pX, pY + 1, pZ + 1 )];
4692 llTrans0Yz = level->m_tileData.transculent[level->getTile( pX, pY + 1, pZ - 1 )];
4693 llTrans0yZ = level->m_tileData.transculent[level->getTile( pX, pY - 1, pZ + 1 )];
4694 llTrans0yz = level->m_tileData.transculent[level->getTile( pX, pY - 1, pZ - 1 )];
4695
4696 if ( getTexture(tt)== &Tile_SPU::ms_pTileData->grass_iconTop )
4697 tint0 = tint2 = tint3 = tint4 = tint5 = false;
4698 if ( hasFixedTexture() ) tint0 = tint2 = tint3 = tint4 = tint5 = false;
4699
4700 if ( faceFlags & 0x01 )
4701 {
4702 if ( blsmooth > 0 )
4703 {
4704 if ( tileShapeY0 <= 0 ) pY--; // 4J - condition brought forwardEnterCriticalSection from 1.2.3
4705
4706 ccxy0 = tt->getLightColor( level, pX - 1, pY, pZ );
4707 cc0yz = tt->getLightColor( level, pX, pY, pZ - 1 );
4708 cc0yZ = tt->getLightColor( level, pX, pY, pZ + 1 );
4709 ccXy0 = tt->getLightColor( level, pX + 1, pY, pZ );
4710
4711 llxy0 = tt->getShadeBrightness( level, pX - 1, pY, pZ );
4712 ll0yz = tt->getShadeBrightness( level, pX, pY, pZ - 1 );
4713 ll0yZ = tt->getShadeBrightness( level, pX, pY, pZ + 1 );
4714 llXy0 = tt->getShadeBrightness( level, pX + 1, pY, pZ );
4715
4716 if ( llTrans0yz || llTransxy0 )
4717 {
4718 llxyz = tt->getShadeBrightness( level, pX - 1, pY, pZ - 1 );
4719 ccxyz = tt->getLightColor( level, pX - 1, pY, pZ - 1 );
4720 }
4721 else
4722 {
4723 llxyz = llxy0;
4724 ccxyz = ccxy0;
4725 }
4726 if ( llTrans0yZ || llTransxy0 )
4727 {
4728 llxyZ = tt->getShadeBrightness( level, pX - 1, pY, pZ + 1 );
4729 ccxyZ = tt->getLightColor( level, pX - 1, pY, pZ + 1 );
4730 }
4731 else
4732 {
4733 llxyZ = llxy0;
4734 ccxyZ = ccxy0;
4735 }
4736 if ( llTrans0yz || llTransXy0 )
4737 {
4738 llXyz = tt->getShadeBrightness( level, pX + 1, pY, pZ - 1 );
4739 ccXyz = tt->getLightColor( level, pX + 1, pY, pZ - 1 );
4740 }
4741 else
4742 {
4743 llXyz = llXy0;
4744 ccXyz = ccXy0;
4745 }
4746 if ( llTrans0yZ || llTransXy0 )
4747 {
4748 llXyZ = tt->getShadeBrightness( level, pX + 1, pY, pZ + 1 );
4749 ccXyZ = tt->getLightColor( level, pX + 1, pY, pZ + 1 );
4750 }
4751 else
4752 {
4753 llXyZ = llXy0;
4754 ccXyZ = ccXy0;
4755 }
4756
4757 if ( tileShapeY0 <= 0 ) pY++; // 4J - condition brought forward from 1.2.3
4758 ll1 = ( llxyZ + llxy0 + ll0yZ + ll0y0 ) / 4.0f;
4759 ll4 = ( ll0yZ + ll0y0 + llXyZ + llXy0 ) / 4.0f;
4760 ll3 = ( ll0y0 + ll0yz + llXy0 + llXyz ) / 4.0f;
4761 ll2 = ( llxy0 + llxyz + ll0y0 + ll0yz ) / 4.0f;
4762
4763 tc1 = blend( ccxyZ, ccxy0, cc0yZ, cc0y0 );
4764 tc4 = blend( cc0yZ, ccXyZ, ccXy0, cc0y0 );
4765 tc3 = blend( cc0yz, ccXy0, ccXyz, cc0y0 );
4766 tc2 = blend( ccxy0, ccxyz, cc0yz, cc0y0 );
4767 }
4768 else
4769 {
4770 ll1 = ll2 = ll3 = ll4 = ll0y0;
4771 tc1 = tc2 = tc3 = tc4 = ccxy0;
4772 }
4773 c1r = c2r = c3r = c4r = ( tint0 ? pBaseRed : 1.0f ) * 0.5f;
4774 c1g = c2g = c3g = c4g = ( tint0 ? pBaseGreen : 1.0f ) * 0.5f;
4775 c1b = c2b = c3b = c4b = ( tint0 ? pBaseBlue : 1.0f ) * 0.5f;
4776 c1r *= ll1;
4777 c1g *= ll1;
4778 c1b *= ll1;
4779 c2r *= ll2;
4780 c2g *= ll2;
4781 c2b *= ll2;
4782 c3r *= ll3;
4783 c3g *= ll3;
4784 c3b *= ll3;
4785 c4r *= ll4;
4786 c4g *= ll4;
4787 c4b *= ll4;
4788
4789 renderFaceDown( tt, ( float )pX, ( float )pY, ( float )pZ, getTexture( tt, level, pX, pY, pZ, 0 ) );
4790 }
4791 if ( faceFlags & 0x02 )
4792 {
4793 if ( blsmooth > 0 )
4794 {
4795 if ( tileShapeY1 >= 1 ) pY++; // 4J - condition brought forward from 1.2.3
4796
4797 ccxY0 = tt->getLightColor( level, pX - 1, pY, pZ );
4798 ccXY0 = tt->getLightColor( level, pX + 1, pY, pZ );
4799 cc0Yz = tt->getLightColor( level, pX, pY, pZ - 1 );
4800 cc0YZ = tt->getLightColor( level, pX, pY, pZ + 1 );
4801
4802 llxY0 = tt->getShadeBrightness( level, pX - 1, pY, pZ );
4803 llXY0 = tt->getShadeBrightness( level, pX + 1, pY, pZ );
4804 ll0Yz = tt->getShadeBrightness( level, pX, pY, pZ - 1 );
4805 ll0YZ = tt->getShadeBrightness( level, pX, pY, pZ + 1 );
4806
4807 if ( llTrans0Yz || llTransxY0 )
4808 {
4809 llxYz = tt->getShadeBrightness( level, pX - 1, pY, pZ - 1 );
4810 ccxYz = tt->getLightColor( level, pX - 1, pY, pZ - 1 );
4811 }
4812 else
4813 {
4814 llxYz = llxY0;
4815 ccxYz = ccxY0;
4816 }
4817 if ( llTrans0Yz || llTransXY0 )
4818 {
4819 llXYz = tt->getShadeBrightness( level, pX + 1, pY, pZ - 1 );
4820 ccXYz = tt->getLightColor( level, pX + 1, pY, pZ - 1 );
4821 }
4822 else
4823 {
4824 llXYz = llXY0;
4825 ccXYz = ccXY0;
4826 }
4827 if ( llTrans0YZ || llTransxY0 )
4828 {
4829 llxYZ = tt->getShadeBrightness( level, pX - 1, pY, pZ + 1 );
4830 ccxYZ = tt->getLightColor( level, pX - 1, pY, pZ + 1 );
4831 }
4832 else
4833 {
4834 llxYZ = llxY0;
4835 ccxYZ = ccxY0;
4836 }
4837 if ( llTrans0YZ || llTransXY0 )
4838 {
4839 llXYZ = tt->getShadeBrightness( level, pX + 1, pY, pZ + 1 );
4840 ccXYZ = tt->getLightColor( level, pX + 1, pY, pZ + 1 );
4841 }
4842 else
4843 {
4844 llXYZ = llXY0;
4845 ccXYZ = ccXY0;
4846 }
4847 if ( tileShapeY1 >= 1 ) pY--; // 4J - condition brought forward from 1.2.3
4848
4849 ll4 = ( llxYZ + llxY0 + ll0YZ + ll0Y0 ) / 4.0f;
4850 ll1 = ( ll0YZ + ll0Y0 + llXYZ + llXY0 ) / 4.0f;
4851 ll2 = ( ll0Y0 + ll0Yz + llXY0 + llXYz ) / 4.0f;
4852 ll3 = ( llxY0 + llxYz + ll0Y0 + ll0Yz ) / 4.0f;
4853
4854 tc4 = blend( ccxYZ, ccxY0, cc0YZ, cc0Y0 );
4855 tc1 = blend( cc0YZ, ccXYZ, ccXY0, cc0Y0 );
4856 tc2 = blend( cc0Yz, ccXY0, ccXYz, cc0Y0 );
4857 tc3 = blend( ccxY0, ccxYz, cc0Yz, cc0Y0 );
4858 }
4859 else
4860 {
4861 ll1 = ll2 = ll3 = ll4 = ll0Y0;
4862 tc1 = tc2 = tc3 = tc4 = cc0Y0;
4863 }
4864 c1r = c2r = c3r = c4r = ( tint1 ? pBaseRed : 1.0f );
4865 c1g = c2g = c3g = c4g = ( tint1 ? pBaseGreen : 1.0f );
4866 c1b = c2b = c3b = c4b = ( tint1 ? pBaseBlue : 1.0f );
4867 c1r *= ll1;
4868 c1g *= ll1;
4869 c1b *= ll1;
4870 c2r *= ll2;
4871 c2g *= ll2;
4872 c2b *= ll2;
4873 c3r *= ll3;
4874 c3g *= ll3;
4875 c3b *= ll3;
4876 c4r *= ll4;
4877 c4g *= ll4;
4878 c4b *= ll4;
4879
4880
4881 renderFaceUp( tt, ( float )pX, ( float )pY, ( float )pZ, getTexture( tt, level, pX, pY, pZ, 1 ) );
4882 }
4883 if ( faceFlags & 0x04 )
4884 {
4885 if ( blsmooth > 0 )
4886 {
4887 if ( tileShapeZ0 <= 0 ) pZ--; // 4J - condition brought forward from 1.2.3
4888 llx0z = tt->getShadeBrightness( level, pX - 1, pY, pZ );
4889 ll0yz = tt->getShadeBrightness( level, pX, pY - 1, pZ );
4890 ll0Yz = tt->getShadeBrightness( level, pX, pY + 1, pZ );
4891 llX0z = tt->getShadeBrightness( level, pX + 1, pY, pZ );
4892
4893 ccx0z = tt->getLightColor( level, pX - 1, pY, pZ );
4894 cc0yz = tt->getLightColor( level, pX, pY - 1, pZ );
4895 cc0Yz = tt->getLightColor( level, pX, pY + 1, pZ );
4896 ccX0z = tt->getLightColor( level, pX + 1, pY, pZ );
4897
4898 if ( llTransx0z || llTrans0yz )
4899 {
4900 llxyz = tt->getShadeBrightness( level, pX - 1, pY - 1, pZ );
4901 ccxyz = tt->getLightColor( level, pX - 1, pY - 1, pZ );
4902 }
4903 else
4904 {
4905 llxyz = llx0z;
4906 ccxyz = ccx0z;
4907 }
4908 if ( llTransx0z || llTrans0Yz )
4909 {
4910 llxYz = tt->getShadeBrightness( level, pX - 1, pY + 1, pZ );
4911 ccxYz = tt->getLightColor( level, pX - 1, pY + 1, pZ );
4912 }
4913 else
4914 {
4915 llxYz = llx0z;
4916 ccxYz = ccx0z;
4917 }
4918 if ( llTransX0z || llTrans0yz )
4919 {
4920 llXyz = tt->getShadeBrightness( level, pX + 1, pY - 1, pZ );
4921 ccXyz = tt->getLightColor( level, pX + 1, pY - 1, pZ );
4922 }
4923 else
4924 {
4925 llXyz = llX0z;
4926 ccXyz = ccX0z;
4927 }
4928 if ( llTransX0z || llTrans0Yz )
4929 {
4930 llXYz = tt->getShadeBrightness( level, pX + 1, pY + 1, pZ );
4931 ccXYz = tt->getLightColor( level, pX + 1, pY + 1, pZ );
4932 }
4933 else
4934 {
4935 llXYz = llX0z;
4936 ccXYz = ccX0z;
4937 }
4938 if ( tileShapeZ0 <= 0 ) pZ++; // 4J - condition brought forward from 1.2.3
4939
4940#ifdef _XBOX
4941 #pragma message(__LOC__"ambientOcclusion NEEDS CHANGED FROM A BOOL ")
4942#endif
4943 if (smoothShapeLighting && g_ambientOcclusionMax)//minecraft->options->ambientOcclusion >= Options::AO_MAX)
4944 {
4945 float _ll1 = (llx0z + llxYz + ll00z + ll0Yz) / 4.0f;
4946 float _ll2 = (ll00z + ll0Yz + llX0z + llXYz) / 4.0f;
4947 float _ll3 = (ll0yz + ll00z + llXyz + llX0z) / 4.0f;
4948 float _ll4 = (llxyz + llx0z + ll0yz + ll00z) / 4.0f;
4949 ll1 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX0) + _ll2 * tileShapeY0 * tileShapeX0 + _ll3 * (1.0 - tileShapeY1) * tileShapeX0 + _ll4 * (1.0 - tileShapeY1)
4950 * (1.0 - tileShapeX0));
4951 ll2 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX1) + _ll2 * tileShapeY1 * tileShapeX1 + _ll3 * (1.0 - tileShapeY1) * tileShapeX1 + _ll4 * (1.0 - tileShapeY1)
4952 * (1.0 - tileShapeX1));
4953 ll3 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX1) + _ll2 * tileShapeY0 * tileShapeX1 + _ll3 * (1.0 - tileShapeY0) * tileShapeX1 + _ll4 * (1.0 - tileShapeY0)
4954 * (1.0 - tileShapeX1));
4955 ll4 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX0) + _ll2 * tileShapeY0 * tileShapeX0 + _ll3 * (1.0 - tileShapeY0) * tileShapeX0 + _ll4 * (1.0 - tileShapeY0)
4956 * (1.0 - tileShapeX0));
4957
4958 int _tc1 = blend(ccx0z, ccxYz, cc0Yz, cc00z);
4959 int _tc2 = blend(cc0Yz, ccX0z, ccXYz, cc00z);
4960 int _tc3 = blend(cc0yz, ccXyz, ccX0z, cc00z);
4961 int _tc4 = blend(ccxyz, ccx0z, cc0yz, cc00z);
4962 tc1 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX0), tileShapeY1 * tileShapeX0, (1.0 - tileShapeY1) * tileShapeX0, (1.0 - tileShapeY1) * (1.0 - tileShapeX0));
4963 tc2 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX1), tileShapeY1 * tileShapeX1, (1.0 - tileShapeY1) * tileShapeX1, (1.0 - tileShapeY1) * (1.0 - tileShapeX1));
4964 tc3 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX1), tileShapeY0 * tileShapeX1, (1.0 - tileShapeY0) * tileShapeX1, (1.0 - tileShapeY0) * (1.0 - tileShapeX1));
4965 tc4 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX0), tileShapeY0 * tileShapeX0, (1.0 - tileShapeY0) * tileShapeX0, (1.0 - tileShapeY0) * (1.0 - tileShapeX0));
4966 } else {
4967 ll1 = ( llx0z + llxYz + ll00z + ll0Yz ) / 4.0f;
4968 ll2 = ( ll00z + ll0Yz + llX0z + llXYz ) / 4.0f;
4969 ll3 = ( ll0yz + ll00z + llXyz + llX0z ) / 4.0f;
4970 ll4 = ( llxyz + llx0z + ll0yz + ll00z ) / 4.0f;
4971
4972 tc1 = blend( ccx0z, ccxYz, cc0Yz, cc00z );
4973 tc2 = blend( cc0Yz, ccX0z, ccXYz, cc00z );
4974 tc3 = blend( cc0yz, ccXyz, ccX0z, cc00z );
4975 tc4 = blend( ccxyz, ccx0z, cc0yz, cc00z );
4976 }
4977 }
4978 else
4979 {
4980 ll1 = ll2 = ll3 = ll4 = ll00z;
4981 tc1 = tc2 = tc3 = tc4 = cc00z;
4982 }
4983 c1r = c2r = c3r = c4r = ( tint2 ? pBaseRed : 1.0f ) * 0.8f;
4984 c1g = c2g = c3g = c4g = ( tint2 ? pBaseGreen : 1.0f ) * 0.8f;
4985 c1b = c2b = c3b = c4b = ( tint2 ? pBaseBlue : 1.0f ) * 0.8f;
4986 c1r *= ll1;
4987 c1g *= ll1;
4988 c1b *= ll1;
4989 c2r *= ll2;
4990 c2g *= ll2;
4991 c2b *= ll2;
4992 c3r *= ll3;
4993 c3g *= ll3;
4994 c3b *= ll3;
4995 c4r *= ll4;
4996 c4g *= ll4;
4997 c4b *= ll4;
4998
4999
5000 Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 2);
5001 renderNorth( tt, ( float )pX, ( float )pY, ( float )pZ, tex );
5002
5003 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
5004 {
5005 c1r *= pBaseRed;
5006 c2r *= pBaseRed;
5007 c3r *= pBaseRed;
5008 c4r *= pBaseRed;
5009 c1g *= pBaseGreen;
5010 c2g *= pBaseGreen;
5011 c3g *= pBaseGreen;
5012 c4g *= pBaseGreen;
5013 c1b *= pBaseBlue;
5014 c2b *= pBaseBlue;
5015 c3b *= pBaseBlue;
5016 c4b *= pBaseBlue;
5017 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5018 renderNorth( tt, ( float )pX, ( float )pY, ( float )pZ, GrassTile_SPU::getSideTextureOverlay() );
5019 t->setMipmapEnable( prev );
5020 }
5021 }
5022 if ( faceFlags & 0x08 )
5023 {
5024 if ( blsmooth > 0 )
5025 {
5026 if ( tileShapeZ1 >= 1 ) pZ++; // 4J - condition brought forward from 1.2.3
5027
5028 llx0Z = tt->getShadeBrightness( level, pX - 1, pY, pZ );
5029 llX0Z = tt->getShadeBrightness( level, pX + 1, pY, pZ );
5030 ll0yZ = tt->getShadeBrightness( level, pX, pY - 1, pZ );
5031 ll0YZ = tt->getShadeBrightness( level, pX, pY + 1, pZ );
5032
5033 ccx0Z = tt->getLightColor( level, pX - 1, pY, pZ );
5034 ccX0Z = tt->getLightColor( level, pX + 1, pY, pZ );
5035 cc0yZ = tt->getLightColor( level, pX, pY - 1, pZ );
5036 cc0YZ = tt->getLightColor( level, pX, pY + 1, pZ );
5037
5038 if ( llTransx0Z || llTrans0yZ )
5039 {
5040 llxyZ = tt->getShadeBrightness( level, pX - 1, pY - 1, pZ );
5041 ccxyZ = tt->getLightColor( level, pX - 1, pY - 1, pZ );
5042 }
5043 else
5044 {
5045 llxyZ = llx0Z;
5046 ccxyZ = ccx0Z;
5047 }
5048 if ( llTransx0Z || llTrans0YZ )
5049 {
5050 llxYZ = tt->getShadeBrightness( level, pX - 1, pY + 1, pZ );
5051 ccxYZ = tt->getLightColor( level, pX - 1, pY + 1, pZ );
5052 }
5053 else
5054 {
5055 llxYZ = llx0Z;
5056 ccxYZ = ccx0Z;
5057 }
5058 if ( llTransX0Z || llTrans0yZ )
5059 {
5060 llXyZ = tt->getShadeBrightness( level, pX + 1, pY - 1, pZ );
5061 ccXyZ = tt->getLightColor( level, pX + 1, pY - 1, pZ );
5062 }
5063 else
5064 {
5065 llXyZ = llX0Z;
5066 ccXyZ = ccX0Z;
5067 }
5068 if ( llTransX0Z || llTrans0YZ )
5069 {
5070 llXYZ = tt->getShadeBrightness( level, pX + 1, pY + 1, pZ );
5071 ccXYZ = tt->getLightColor( level, pX + 1, pY + 1, pZ );
5072 }
5073 else
5074 {
5075 llXYZ = llX0Z;
5076 ccXYZ = ccX0Z;
5077 }
5078 if ( tileShapeZ1 >= 1 ) pZ--; // 4J - condition brought forward from 1.2.3
5079 if (smoothShapeLighting && g_ambientOcclusionMax)//minecraft->options->ambientOcclusion >= Options::AO_MAX)
5080 {
5081 float _ll1 = (llx0Z + llxYZ + ll00Z + ll0YZ) / 4.0f;
5082 float _ll4 = (ll00Z + ll0YZ + llX0Z + llXYZ) / 4.0f;
5083 float _ll3 = (ll0yZ + ll00Z + llXyZ + llX0Z) / 4.0f;
5084 float _ll2 = (llxyZ + llx0Z + ll0yZ + ll00Z) / 4.0f;
5085 ll1 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX0) + _ll4 * tileShapeY1 * tileShapeX0 + _ll3 * (1.0 - tileShapeY1) * tileShapeX0 + _ll2 * (1.0 - tileShapeY1)
5086 * (1.0 - tileShapeX0));
5087 ll2 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX0) + _ll4 * tileShapeY0 * tileShapeX0 + _ll3 * (1.0 - tileShapeY0) * tileShapeX0 + _ll2 * (1.0 - tileShapeY0)
5088 * (1.0 - tileShapeX0));
5089 ll3 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX1) + _ll4 * tileShapeY0 * tileShapeX1 + _ll3 * (1.0 - tileShapeY0) * tileShapeX1 + _ll2 * (1.0 - tileShapeY0)
5090 * (1.0 - tileShapeX1));
5091 ll4 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX1) + _ll4 * tileShapeY1 * tileShapeX1 + _ll3 * (1.0 - tileShapeY1) * tileShapeX1 + _ll2 * (1.0 - tileShapeY1)
5092 * (1.0 - tileShapeX1));
5093
5094 int _tc1 = blend(ccx0Z, ccxYZ, cc0YZ, cc00Z);
5095 int _tc4 = blend(cc0YZ, ccX0Z, ccXYZ, cc00Z);
5096 int _tc3 = blend(cc0yZ, ccXyZ, ccX0Z, cc00Z);
5097 int _tc2 = blend(ccxyZ, ccx0Z, cc0yZ, cc00Z);
5098 tc1 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX0), (1.0 - tileShapeY1) * (1.0 - tileShapeX0), (1.0 - tileShapeY1) * tileShapeX0, tileShapeY1 * tileShapeX0);
5099 tc2 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX0), (1.0 - tileShapeY0) * (1.0 - tileShapeX0), (1.0 - tileShapeY0) * tileShapeX0, tileShapeY0 * tileShapeX0);
5100 tc3 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX1), (1.0 - tileShapeY0) * (1.0 - tileShapeX1), (1.0 - tileShapeY0) * tileShapeX1, tileShapeY0 * tileShapeX1);
5101 tc4 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX1), (1.0 - tileShapeY1) * (1.0 - tileShapeX1), (1.0 - tileShapeY1) * tileShapeX1, tileShapeY1 * tileShapeX1);
5102 }
5103 else
5104 {
5105 ll1 = ( llx0Z + llxYZ + ll00Z + ll0YZ ) / 4.0f;
5106 ll4 = ( ll00Z + ll0YZ + llX0Z + llXYZ ) / 4.0f;
5107 ll3 = ( ll0yZ + ll00Z + llXyZ + llX0Z ) / 4.0f;
5108 ll2 = ( llxyZ + llx0Z + ll0yZ + ll00Z ) / 4.0f;
5109
5110 tc1 = blend( ccx0Z, ccxYZ, cc0YZ, cc00Z );
5111 tc4 = blend( cc0YZ, ccX0Z, ccXYZ, cc00Z );
5112 tc3 = blend( cc0yZ, ccXyZ, ccX0Z, cc00Z );
5113 tc2 = blend( ccxyZ, ccx0Z, cc0yZ, cc00Z );
5114 }
5115 }
5116 else
5117 {
5118 ll1 = ll2 = ll3 = ll4 = ll00Z;
5119 tc1 = tc2 = tc3 = tc4 = cc00Z;
5120 }
5121 c1r = c2r = c3r = c4r = ( tint3 ? pBaseRed : 1.0f ) * 0.8f;
5122 c1g = c2g = c3g = c4g = ( tint3 ? pBaseGreen : 1.0f ) * 0.8f;
5123 c1b = c2b = c3b = c4b = ( tint3 ? pBaseBlue : 1.0f ) * 0.8f;
5124 c1r *= ll1;
5125 c1g *= ll1;
5126 c1b *= ll1;
5127 c2r *= ll2;
5128 c2g *= ll2;
5129 c2b *= ll2;
5130 c3r *= ll3;
5131 c3g *= ll3;
5132 c3b *= ll3;
5133 c4r *= ll4;
5134 c4g *= ll4;
5135 c4b *= ll4;
5136 Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 3);
5137 renderSouth( tt, ( float )pX, ( float )pY, ( float )pZ, getTexture(tt, level, pX, pY, pZ, 3 ) );
5138
5139 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
5140 {
5141 c1r *= pBaseRed;
5142 c2r *= pBaseRed;
5143 c3r *= pBaseRed;
5144 c4r *= pBaseRed;
5145 c1g *= pBaseGreen;
5146 c2g *= pBaseGreen;
5147 c3g *= pBaseGreen;
5148 c4g *= pBaseGreen;
5149 c1b *= pBaseBlue;
5150 c2b *= pBaseBlue;
5151 c3b *= pBaseBlue;
5152 c4b *= pBaseBlue;
5153 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5154 renderSouth( tt, ( float )pX, ( float )pY, ( float )pZ, GrassTile_SPU::getSideTextureOverlay() );
5155 t->setMipmapEnable( prev );
5156 }
5157 }
5158 if ( faceFlags & 0x10 )
5159 {
5160 if ( blsmooth > 0 )
5161 {
5162 if ( tileShapeX0 <= 0 ) pX--; // 4J - condition brought forward from 1.2.3
5163 llxy0 = tt->getShadeBrightness( level, pX, pY - 1, pZ );
5164 llx0z = tt->getShadeBrightness( level, pX, pY, pZ - 1 );
5165 llx0Z = tt->getShadeBrightness( level, pX, pY, pZ + 1 );
5166 llxY0 = tt->getShadeBrightness( level, pX, pY + 1, pZ );
5167
5168 ccxy0 = tt->getLightColor( level, pX, pY - 1, pZ );
5169 ccx0z = tt->getLightColor( level, pX, pY, pZ - 1 );
5170 ccx0Z = tt->getLightColor( level, pX, pY, pZ + 1 );
5171 ccxY0 = tt->getLightColor( level, pX, pY + 1, pZ );
5172
5173 if ( llTransx0z || llTransxy0 )
5174 {
5175 llxyz = tt->getShadeBrightness( level, pX, pY - 1, pZ - 1 );
5176 ccxyz = tt->getLightColor( level, pX, pY - 1, pZ - 1 );
5177 }
5178 else
5179 {
5180 llxyz = llx0z;
5181 ccxyz = ccx0z;
5182 }
5183 if ( llTransx0Z || llTransxy0 )
5184 {
5185 llxyZ = tt->getShadeBrightness( level, pX, pY - 1, pZ + 1 );
5186 ccxyZ = tt->getLightColor( level, pX, pY - 1, pZ + 1 );
5187 }
5188 else
5189 {
5190 llxyZ = llx0Z;
5191 ccxyZ = ccx0Z;
5192 }
5193 if ( llTransx0z || llTransxY0 )
5194 {
5195 llxYz = tt->getShadeBrightness( level, pX, pY + 1, pZ - 1 );
5196 ccxYz = tt->getLightColor( level, pX, pY + 1, pZ - 1 );
5197 }
5198 else
5199 {
5200 llxYz = llx0z;
5201 ccxYz = ccx0z;
5202 }
5203 if ( llTransx0Z || llTransxY0 )
5204 {
5205 llxYZ = tt->getShadeBrightness( level, pX, pY + 1, pZ + 1 );
5206 ccxYZ = tt->getLightColor( level, pX, pY + 1, pZ + 1 );
5207 }
5208 else
5209 {
5210 llxYZ = llx0Z;
5211 ccxYZ = ccx0Z;
5212 }
5213 if ( tileShapeX0 <= 0 ) pX++; // 4J - condition brought forward from 1.2.3
5214 if (smoothShapeLighting && g_ambientOcclusionMax)//minecraft->options->ambientOcclusion >= Options::AO_MAX)
5215 {
5216 float _ll4 = (llxy0 + llxyZ + llx00 + llx0Z) / 4.0f;
5217 float _ll1 = (llx00 + llx0Z + llxY0 + llxYZ) / 4.0f;
5218 float _ll2 = (llx0z + llx00 + llxYz + llxY0) / 4.0f;
5219 float _ll3 = (llxyz + llxy0 + llx0z + llx00) / 4.0f;
5220 ll1 = (float) (_ll1 * tileShapeY1 * tileShapeZ1 + _ll2 * tileShapeY1 * (1.0 - tileShapeZ1) + _ll3 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ1) + _ll4 * (1.0 - tileShapeY1)
5221 * tileShapeZ1);
5222 ll2 = (float) (_ll1 * tileShapeY1 * tileShapeZ0 + _ll2 * tileShapeY1 * (1.0 - tileShapeZ0) + _ll3 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ0) + _ll4 * (1.0 - tileShapeY1)
5223 * tileShapeZ0);
5224 ll3 = (float) (_ll1 * tileShapeY0 * tileShapeZ0 + _ll2 * tileShapeY0 * (1.0 - tileShapeZ0) + _ll3 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ0) + _ll4 * (1.0 - tileShapeY0)
5225 * tileShapeZ0);
5226 ll4 = (float) (_ll1 * tileShapeY0 * tileShapeZ1 + _ll2 * tileShapeY0 * (1.0 - tileShapeZ1) + _ll3 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ1) + _ll4 * (1.0 - tileShapeY0)
5227 * tileShapeZ1);
5228
5229 int _tc4 = blend(ccxy0, ccxyZ, ccx0Z, ccx00);
5230 int _tc1 = blend(ccx0Z, ccxY0, ccxYZ, ccx00);
5231 int _tc2 = blend(ccx0z, ccxYz, ccxY0, ccx00);
5232 int _tc3 = blend(ccxyz, ccxy0, ccx0z, ccx00);
5233 tc1 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * tileShapeZ1, tileShapeY1 * (1.0 - tileShapeZ1), (1.0 - tileShapeY1) * (1.0 - tileShapeZ1), (1.0 - tileShapeY1) * tileShapeZ1);
5234 tc2 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * tileShapeZ0, tileShapeY1 * (1.0 - tileShapeZ0), (1.0 - tileShapeY1) * (1.0 - tileShapeZ0), (1.0 - tileShapeY1) * tileShapeZ0);
5235 tc3 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * tileShapeZ0, tileShapeY0 * (1.0 - tileShapeZ0), (1.0 - tileShapeY0) * (1.0 - tileShapeZ0), (1.0 - tileShapeY0) * tileShapeZ0);
5236 tc4 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * tileShapeZ1, tileShapeY0 * (1.0 - tileShapeZ1), (1.0 - tileShapeY0) * (1.0 - tileShapeZ1), (1.0 - tileShapeY0) * tileShapeZ1);
5237 }
5238 else
5239 {
5240 ll4 = ( llxy0 + llxyZ + llx00 + llx0Z ) / 4.0f;
5241 ll1 = ( llx00 + llx0Z + llxY0 + llxYZ ) / 4.0f;
5242 ll2 = ( llx0z + llx00 + llxYz + llxY0 ) / 4.0f;
5243 ll3 = ( llxyz + llxy0 + llx0z + llx00 ) / 4.0f;
5244
5245 tc4 = blend( ccxy0, ccxyZ, ccx0Z, ccx00 );
5246 tc1 = blend( ccx0Z, ccxY0, ccxYZ, ccx00 );
5247 tc2 = blend( ccx0z, ccxYz, ccxY0, ccx00 );
5248 tc3 = blend( ccxyz, ccxy0, ccx0z, ccx00 );
5249 }
5250 }
5251 else
5252 {
5253 ll1 = ll2 = ll3 = ll4 = llx00;
5254 tc1 = tc2 = tc3 = tc4 = ccx00;
5255 }
5256 c1r = c2r = c3r = c4r = ( tint4 ? pBaseRed : 1.0f ) * 0.6f;
5257 c1g = c2g = c3g = c4g = ( tint4 ? pBaseGreen : 1.0f ) * 0.6f;
5258 c1b = c2b = c3b = c4b = ( tint4 ? pBaseBlue : 1.0f ) * 0.6f;
5259 c1r *= ll1;
5260 c1g *= ll1;
5261 c1b *= ll1;
5262 c2r *= ll2;
5263 c2g *= ll2;
5264 c2b *= ll2;
5265 c3r *= ll3;
5266 c3g *= ll3;
5267 c3b *= ll3;
5268 c4r *= ll4;
5269 c4g *= ll4;
5270 c4b *= ll4;
5271 Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 4);
5272 renderWest( tt, ( float )pX, ( float )pY, ( float )pZ, tex );
5273
5274 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
5275 {
5276 c1r *= pBaseRed;
5277 c2r *= pBaseRed;
5278 c3r *= pBaseRed;
5279 c4r *= pBaseRed;
5280 c1g *= pBaseGreen;
5281 c2g *= pBaseGreen;
5282 c3g *= pBaseGreen;
5283 c4g *= pBaseGreen;
5284 c1b *= pBaseBlue;
5285 c2b *= pBaseBlue;
5286 c3b *= pBaseBlue;
5287 c4b *= pBaseBlue;
5288 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5289 renderWest( tt, ( float )pX, ( float )pY, ( float )pZ, GrassTile_SPU::getSideTextureOverlay() );
5290 t->setMipmapEnable( prev );
5291 }
5292 }
5293 if ( faceFlags & 0x20 )
5294 {
5295 if ( blsmooth > 0 )
5296 {
5297 if ( tileShapeX1 >= 1 ) pX++; // 4J - condition brought forward from 1.2.3
5298 llXy0 = tt->getShadeBrightness( level, pX, pY - 1, pZ );
5299 llX0z = tt->getShadeBrightness( level, pX, pY, pZ - 1 );
5300 llX0Z = tt->getShadeBrightness( level, pX, pY, pZ + 1 );
5301 llXY0 = tt->getShadeBrightness( level, pX, pY + 1, pZ );
5302
5303 ccXy0 = tt->getLightColor( level, pX, pY - 1, pZ );
5304 ccX0z = tt->getLightColor( level, pX, pY, pZ - 1 );
5305 ccX0Z = tt->getLightColor( level, pX, pY, pZ + 1 );
5306 ccXY0 = tt->getLightColor( level, pX, pY + 1, pZ );
5307
5308 if ( llTransXy0 || llTransX0z )
5309 {
5310 llXyz = tt->getShadeBrightness( level, pX, pY - 1, pZ - 1 );
5311 ccXyz = tt->getLightColor( level, pX, pY - 1, pZ - 1 );
5312 }
5313 else
5314 {
5315 llXyz = llX0z;
5316 ccXyz = ccX0z;
5317 }
5318 if ( llTransXy0 || llTransX0Z )
5319 {
5320 llXyZ = tt->getShadeBrightness( level, pX, pY - 1, pZ + 1 );
5321 ccXyZ = tt->getLightColor( level, pX, pY - 1, pZ + 1 );
5322 }
5323 else
5324 {
5325 llXyZ = llX0Z;
5326 ccXyZ = ccX0Z;
5327 }
5328 if ( llTransXY0 || llTransX0z )
5329 {
5330 llXYz = tt->getShadeBrightness( level, pX, pY + 1, pZ - 1 );
5331 ccXYz = tt->getLightColor( level, pX, pY + 1, pZ - 1 );
5332 }
5333 else
5334 {
5335 llXYz = llX0z;
5336 ccXYz = ccX0z;
5337 }
5338 if ( llTransXY0 || llTransX0Z )
5339 {
5340 llXYZ = tt->getShadeBrightness( level, pX, pY + 1, pZ + 1 );
5341 ccXYZ = tt->getLightColor( level, pX, pY + 1, pZ + 1 );
5342 }
5343 else
5344 {
5345 llXYZ = llX0Z;
5346 ccXYZ = ccX0Z;
5347 }
5348 if ( tileShapeX1 >= 1 ) pX--; // 4J - condition brought forward from 1.2.3
5349 if (smoothShapeLighting && g_ambientOcclusionMax)//minecraft->options->ambientOcclusion >= Options::AO_MAX)
5350 {
5351 float _ll1 = (llXy0 + llXyZ + llX00 + llX0Z) / 4.0f;
5352 float _ll2 = (llXyz + llXy0 + llX0z + llX00) / 4.0f;
5353 float _ll3 = (llX0z + llX00 + llXYz + llXY0) / 4.0f;
5354 float _ll4 = (llX00 + llX0Z + llXY0 + llXYZ) / 4.0f;
5355 ll1 = (float) (_ll1 * (1.0 - tileShapeY0) * tileShapeZ1 + _ll2 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ1) + _ll3 * tileShapeY0 * (1.0 - tileShapeZ1) + _ll4 * tileShapeY0
5356 * tileShapeZ1);
5357 ll2 = (float) (_ll1 * (1.0 - tileShapeY0) * tileShapeZ0 + _ll2 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ0) + _ll3 * tileShapeY0 * (1.0 - tileShapeZ0) + _ll4 * tileShapeY0
5358 * tileShapeZ0);
5359 ll3 = (float) (_ll1 * (1.0 - tileShapeY1) * tileShapeZ0 + _ll2 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ0) + _ll3 * tileShapeY1 * (1.0 - tileShapeZ0) + _ll4 * tileShapeY1
5360 * tileShapeZ0);
5361 ll4 = (float) (_ll1 * (1.0 - tileShapeY1) * tileShapeZ1 + _ll2 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ1) + _ll3 * tileShapeY1 * (1.0 - tileShapeZ1) + _ll4 * tileShapeY1
5362 * tileShapeZ1);
5363
5364 int _tc1 = blend(ccXy0, ccXyZ, ccX0Z, ccX00);
5365 int _tc4 = blend(ccX0Z, ccXY0, ccXYZ, ccX00);
5366 int _tc3 = blend(ccX0z, ccXYz, ccXY0, ccX00);
5367 int _tc2 = blend(ccXyz, ccXy0, ccX0z, ccX00);
5368 tc1 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY0) * tileShapeZ1, (1.0 - tileShapeY0) * (1.0 - tileShapeZ1), tileShapeY0 * (1.0 - tileShapeZ1), tileShapeY0 * tileShapeZ1);
5369 tc2 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY0) * tileShapeZ0, (1.0 - tileShapeY0) * (1.0 - tileShapeZ0), tileShapeY0 * (1.0 - tileShapeZ0), tileShapeY0 * tileShapeZ0);
5370 tc3 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY1) * tileShapeZ0, (1.0 - tileShapeY1) * (1.0 - tileShapeZ0), tileShapeY1 * (1.0 - tileShapeZ0), tileShapeY1 * tileShapeZ0);
5371 tc4 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY1) * tileShapeZ1, (1.0 - tileShapeY1) * (1.0 - tileShapeZ1), tileShapeY1 * (1.0 - tileShapeZ1), tileShapeY1 * tileShapeZ1);
5372 }
5373 else
5374 {
5375 ll1 = (llXy0 + llXyZ + llX00 + llX0Z) / 4.0f;
5376 ll2 = (llXyz + llXy0 + llX0z + llX00) / 4.0f;
5377 ll3 = (llX0z + llX00 + llXYz + llXY0) / 4.0f;
5378 ll4 = (llX00 + llX0Z + llXY0 + llXYZ) / 4.0f;
5379
5380 tc1 = blend(ccXy0, ccXyZ, ccX0Z, ccX00);
5381 tc4 = blend(ccX0Z, ccXY0, ccXYZ, ccX00);
5382 tc3 = blend(ccX0z, ccXYz, ccXY0, ccX00);
5383 tc2 = blend(ccXyz, ccXy0, ccX0z, ccX00);
5384 }
5385 }
5386 else
5387 {
5388 ll1 = ll2 = ll3 = ll4 = llX00;
5389 tc1 = tc2 = tc3 = tc4 = ccX00;
5390 }
5391 c1r = c2r = c3r = c4r = ( tint5 ? pBaseRed : 1.0f ) * 0.6f;
5392 c1g = c2g = c3g = c4g = ( tint5 ? pBaseGreen : 1.0f ) * 0.6f;
5393 c1b = c2b = c3b = c4b = ( tint5 ? pBaseBlue : 1.0f ) * 0.6f;
5394 c1r *= ll1;
5395 c1g *= ll1;
5396 c1b *= ll1;
5397 c2r *= ll2;
5398 c2g *= ll2;
5399 c2b *= ll2;
5400 c3r *= ll3;
5401 c3g *= ll3;
5402 c3b *= ll3;
5403 c4r *= ll4;
5404 c4g *= ll4;
5405 c4b *= ll4;
5406
5407 Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 5);
5408 renderEast( tt, ( float )pX, ( float )pY, ( float )pZ, tex );
5409 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
5410 {
5411 c1r *= pBaseRed;
5412 c2r *= pBaseRed;
5413 c3r *= pBaseRed;
5414 c4r *= pBaseRed;
5415 c1g *= pBaseGreen;
5416 c2g *= pBaseGreen;
5417 c3g *= pBaseGreen;
5418 c4g *= pBaseGreen;
5419 c1b *= pBaseBlue;
5420 c2b *= pBaseBlue;
5421 c3b *= pBaseBlue;
5422 c4b *= pBaseBlue;
5423
5424 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5425 renderEast( tt, ( float )pX, ( float )pY, ( float )pZ, GrassTile_SPU::getSideTextureOverlay() );
5426 t->setMipmapEnable( prev );
5427 }
5428 }
5429 applyAmbienceOcclusion = false;
5430
5431 return true;
5432
5433}
5434
5435bool TileRenderer_SPU::tesselateBlockInWorldWithAmbienceOcclusionOldLighting( Tile_SPU* tt, int pX, int pY, int pZ,
5436 float pBaseRed, float pBaseGreen,
5437 float pBaseBlue )
5438{
5439//
5440// // 4J - added these faceFlags so we can detect whether this block is going to have no visible faces and early out
5441// // the original code checked noCulling and shouldRenderFace directly where faceFlags is used now
5442// int faceFlags = 0;
5443// if ( noCulling )
5444// {
5445// faceFlags = 0x3f;
5446// }
5447// else
5448// {
5449// faceFlags |= tt->shouldRenderFace( level, pX, pY - 1, pZ, 0 ) ? 0x01 : 0;
5450// faceFlags |= tt->shouldRenderFace( level, pX, pY + 1, pZ, 1 ) ? 0x02 : 0;
5451// faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ - 1, 2 ) ? 0x04 : 0;
5452// faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ + 1, 3 ) ? 0x08 : 0;
5453// faceFlags |= tt->shouldRenderFace( level, pX - 1, pY, pZ, 4 ) ? 0x10 : 0;
5454// faceFlags |= tt->shouldRenderFace( level, pX + 1, pY, pZ, 5 ) ? 0x20 : 0;
5455// }
5456// if ( faceFlags == 0 )
5457// {
5458// return false;
5459// }
5460//
5461// applyAmbienceOcclusion = true;
5462// float ll1 = ll000;
5463// float ll2 = ll000;
5464// float ll3 = ll000;
5465// float ll4 = ll000;
5466// bool tint0 = true;
5467// bool tint1 = true;
5468// bool tint2 = true;
5469// bool tint3 = true;
5470// bool tint4 = true;
5471// bool tint5 = true;
5472//
5473//
5474// ll000 = tt->getBrightness( level, pX, pY, pZ );
5475// llx00 = tt->getBrightness( level, pX - 1, pY, pZ );
5476// ll0y0 = tt->getBrightness( level, pX, pY - 1, pZ );
5477// ll00z = tt->getBrightness( level, pX, pY, pZ - 1 );
5478// llX00 = tt->getBrightness( level, pX + 1, pY, pZ );
5479// ll0Y0 = tt->getBrightness( level, pX, pY + 1, pZ );
5480// ll00Z = tt->getBrightness( level, pX, pY, pZ + 1 );
5481//
5482// llTransXY0 = level->m_tileData.transculent[level->getTile( pX + 1, pY + 1, pZ )];
5483// llTransXy0 = level->m_tileData.transculent[level->getTile( pX + 1, pY - 1, pZ )];
5484// llTransX0Z = level->m_tileData.transculent[level->getTile( pX + 1, pY, pZ + 1 )];
5485// llTransX0z = level->m_tileData.transculent[level->getTile( pX + 1, pY, pZ - 1 )];
5486// llTransxY0 = level->m_tileData.transculent[level->getTile( pX - 1, pY + 1, pZ )];
5487// llTransxy0 = level->m_tileData.transculent[level->getTile( pX - 1, pY - 1, pZ )];
5488// llTransx0z = level->m_tileData.transculent[level->getTile( pX - 1, pY, pZ - 1 )];
5489// llTransx0Z = level->m_tileData.transculent[level->getTile( pX - 1, pY, pZ + 1 )];
5490// llTrans0YZ = level->m_tileData.transculent[level->getTile( pX, pY + 1, pZ + 1 )];
5491// llTrans0Yz = level->m_tileData.transculent[level->getTile( pX, pY + 1, pZ - 1 )];
5492// llTrans0yZ = level->m_tileData.transculent[level->getTile( pX, pY - 1, pZ + 1 )];
5493// llTrans0yz = level->m_tileData.transculent[level->getTile( pX, pY - 1, pZ - 1 )];
5494//
5495// spu_print("Have to add texture name check here\n");
5496// if ( getTexture(tt)->getName().compare(L"grass_top") == 0 ) tint0 = tint2 = tint3 = tint4 = tint5 = false;
5497// if ( hasFixedTexture() ) tint0 = tint2 = tint3 = tint4 = tint5 = false;
5498//
5499// if ( faceFlags & 0x01 )
5500// {
5501// if ( blsmooth > 0 )
5502// {
5503// pY--;
5504//
5505// llxy0 = tt->getBrightness( level, pX - 1, pY, pZ );
5506// ll0yz = tt->getBrightness( level, pX, pY, pZ - 1 );
5507// ll0yZ = tt->getBrightness( level, pX, pY, pZ + 1 );
5508// llXy0 = tt->getBrightness( level, pX + 1, pY, pZ );
5509//
5510// if ( llTrans0yz || llTransxy0 )
5511// {
5512// llxyz = tt->getBrightness( level, pX - 1, pY, pZ - 1 );
5513// }
5514// else
5515// {
5516// llxyz = llxy0;
5517// }
5518// if ( llTrans0yZ || llTransxy0 )
5519// {
5520// llxyZ = tt->getBrightness( level, pX - 1, pY, pZ + 1 );
5521// }
5522// else
5523// {
5524// llxyZ = llxy0;
5525// }
5526// if ( llTrans0yz || llTransXy0 )
5527// {
5528// llXyz = tt->getBrightness( level, pX + 1, pY, pZ - 1 );
5529// }
5530// else
5531// {
5532// llXyz = llXy0;
5533// }
5534// if ( llTrans0yZ || llTransXy0 )
5535// {
5536// llXyZ = tt->getBrightness( level, pX + 1, pY, pZ + 1 );
5537// }
5538// else
5539// {
5540// llXyZ = llXy0;
5541// }
5542//
5543// pY++;
5544// ll1 = ( llxyZ + llxy0 + ll0yZ + ll0y0 ) / 4.0f;
5545// ll4 = ( ll0yZ + ll0y0 + llXyZ + llXy0 ) / 4.0f;
5546// ll3 = ( ll0y0 + ll0yz + llXy0 + llXyz ) / 4.0f;
5547// ll2 = ( llxy0 + llxyz + ll0y0 + ll0yz ) / 4.0f;
5548// }
5549// else
5550// {
5551// ll1 = ll2 = ll3 = ll4 = ll0y0;
5552// }
5553// c1r = c2r = c3r = c4r = ( tint0 ? pBaseRed : 1.0f ) * 0.5f;
5554// c1g = c2g = c3g = c4g = ( tint0 ? pBaseGreen : 1.0f ) * 0.5f;
5555// c1b = c2b = c3b = c4b = ( tint0 ? pBaseBlue : 1.0f ) * 0.5f;
5556// c1r *= ll1;
5557// c1g *= ll1;
5558// c1b *= ll1;
5559// c2r *= ll2;
5560// c2g *= ll2;
5561// c2b *= ll2;
5562// c3r *= ll3;
5563// c3g *= ll3;
5564// c3b *= ll3;
5565// c4r *= ll4;
5566// c4g *= ll4;
5567// c4b *= ll4;
5568//
5569// renderFaceDown( tt, ( float )pX, ( float )pY, ( float )pZ, getTexture( tt, level, pX, pY, pZ, 0 ) );
5570// }
5571// if ( faceFlags & 0x02 )
5572// {
5573// if ( blsmooth > 0 )
5574// {
5575// pY++;
5576//
5577// llxY0 = tt->getBrightness( level, pX - 1, pY, pZ );
5578// llXY0 = tt->getBrightness( level, pX + 1, pY, pZ );
5579// ll0Yz = tt->getBrightness( level, pX, pY, pZ - 1 );
5580// ll0YZ = tt->getBrightness( level, pX, pY, pZ + 1 );
5581//
5582// if ( llTrans0Yz || llTransxY0 )
5583// {
5584// llxYz = tt->getBrightness( level, pX - 1, pY, pZ - 1 );
5585// }
5586// else
5587// {
5588// llxYz = llxY0;
5589// }
5590// if ( llTrans0Yz || llTransXY0 )
5591// {
5592// llXYz = tt->getBrightness( level, pX + 1, pY, pZ - 1 );
5593// }
5594// else
5595// {
5596// llXYz = llXY0;
5597// }
5598// if ( llTrans0YZ || llTransxY0 )
5599// {
5600// llxYZ = tt->getBrightness( level, pX - 1, pY, pZ + 1 );
5601// }
5602// else
5603// {
5604// llxYZ = llxY0;
5605// }
5606// if ( llTrans0YZ || llTransXY0 )
5607// {
5608// llXYZ = tt->getBrightness( level, pX + 1, pY, pZ + 1 );
5609// }
5610// else
5611// {
5612// llXYZ = llXY0;
5613// }
5614// pY--;
5615//
5616// ll4 = ( llxYZ + llxY0 + ll0YZ + ll0Y0 ) / 4.0f;
5617// ll1 = ( ll0YZ + ll0Y0 + llXYZ + llXY0 ) / 4.0f;
5618// ll2 = ( ll0Y0 + ll0Yz + llXY0 + llXYz ) / 4.0f;
5619// ll3 = ( llxY0 + llxYz + ll0Y0 + ll0Yz ) / 4.0f;
5620// }
5621// else
5622// {
5623// ll1 = ll2 = ll3 = ll4 = ll0Y0;
5624// }
5625// c1r = c2r = c3r = c4r = ( tint1 ? pBaseRed : 1.0f );
5626// c1g = c2g = c3g = c4g = ( tint1 ? pBaseGreen : 1.0f );
5627// c1b = c2b = c3b = c4b = ( tint1 ? pBaseBlue : 1.0f );
5628// c1r *= ll1;
5629// c1g *= ll1;
5630// c1b *= ll1;
5631// c2r *= ll2;
5632// c2g *= ll2;
5633// c2b *= ll2;
5634// c3r *= ll3;
5635// c3g *= ll3;
5636// c3b *= ll3;
5637// c4r *= ll4;
5638// c4g *= ll4;
5639// c4b *= ll4;
5640// renderFaceUp( tt, ( float )pX, ( float )pY, ( float )pZ, getTexture( tt, level, pX, pY, pZ, 1 ) );
5641// }
5642// if ( faceFlags & 0x04 )
5643// {
5644// if ( blsmooth > 0 )
5645// {
5646// pZ--;
5647// llx0z = tt->getBrightness( level, pX - 1, pY, pZ );
5648// ll0yz = tt->getBrightness( level, pX, pY - 1, pZ );
5649// ll0Yz = tt->getBrightness( level, pX, pY + 1, pZ );
5650// llX0z = tt->getBrightness( level, pX + 1, pY, pZ );
5651//
5652// if ( llTransx0z || llTrans0yz )
5653// {
5654// llxyz = tt->getBrightness( level, pX - 1, pY - 1, pZ );
5655// }
5656// else
5657// {
5658// llxyz = llx0z;
5659// }
5660// if ( llTransx0z || llTrans0Yz )
5661// {
5662// llxYz = tt->getBrightness( level, pX - 1, pY + 1, pZ );
5663// }
5664// else
5665// {
5666// llxYz = llx0z;
5667// }
5668// if ( llTransX0z || llTrans0yz )
5669// {
5670// llXyz = tt->getBrightness( level, pX + 1, pY - 1, pZ );
5671// }
5672// else
5673// {
5674// llXyz = llX0z;
5675// }
5676// if ( llTransX0z || llTrans0Yz )
5677// {
5678// llXYz = tt->getBrightness( level, pX + 1, pY + 1, pZ );
5679// }
5680// else
5681// {
5682// llXYz = llX0z;
5683// }
5684// pZ++;
5685// ll1 = ( llx0z + llxYz + ll00z + ll0Yz ) / 4.0f;
5686// ll2 = ( ll00z + ll0Yz + llX0z + llXYz ) / 4.0f;
5687// ll3 = ( ll0yz + ll00z + llXyz + llX0z ) / 4.0f;
5688// ll4 = ( llxyz + llx0z + ll0yz + ll00z ) / 4.0f;
5689// }
5690// else
5691// {
5692// ll1 = ll2 = ll3 = ll4 = ll00z;
5693// }
5694// c1r = c2r = c3r = c4r = ( tint2 ? pBaseRed : 1.0f ) * 0.8f;
5695// c1g = c2g = c3g = c4g = ( tint2 ? pBaseGreen : 1.0f ) * 0.8f;
5696// c1b = c2b = c3b = c4b = ( tint2 ? pBaseBlue : 1.0f ) * 0.8f;
5697// c1r *= ll1;
5698// c1g *= ll1;
5699// c1b *= ll1;
5700// c2r *= ll2;
5701// c2g *= ll2;
5702// c2b *= ll2;
5703// c3r *= ll3;
5704// c3g *= ll3;
5705// c3b *= ll3;
5706// c4r *= ll4;
5707// c4g *= ll4;
5708// c4b *= ll4;
5709//
5710// Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 2);
5711// renderNorth( tt, ( float )pX, ( float )pY, ( float )pZ, tex );
5712//
5713// if ( fancy && (tex->getName().compare(L"grass_side") == 0) && !hasFixedTexture())
5714// {
5715// c1r *= pBaseRed;
5716// c2r *= pBaseRed;
5717// c3r *= pBaseRed;
5718// c4r *= pBaseRed;
5719// c1g *= pBaseGreen;
5720// c2g *= pBaseGreen;
5721// c3g *= pBaseGreen;
5722// c4g *= pBaseGreen;
5723// c1b *= pBaseBlue;
5724// c2b *= pBaseBlue;
5725// c3b *= pBaseBlue;
5726// c4b *= pBaseBlue;
5727// renderNorth( tt, ( float )pX, ( float )pY, ( float )pZ, getGrassSideTextureOverlay() );
5728// }
5729// }
5730// if ( faceFlags & 0x08 )
5731// {
5732// if ( blsmooth > 0 )
5733// {
5734// pZ++;
5735//
5736// llx0Z = tt->getBrightness( level, pX - 1, pY, pZ );
5737// llX0Z = tt->getBrightness( level, pX + 1, pY, pZ );
5738// ll0yZ = tt->getBrightness( level, pX, pY - 1, pZ );
5739// ll0YZ = tt->getBrightness( level, pX, pY + 1, pZ );
5740//
5741// if ( llTransx0Z || llTrans0yZ )
5742// {
5743// llxyZ = tt->getBrightness( level, pX - 1, pY - 1, pZ );
5744// }
5745// else
5746// {
5747// llxyZ = llx0Z;
5748// }
5749// if ( llTransx0Z || llTrans0YZ )
5750// {
5751// llxYZ = tt->getBrightness( level, pX - 1, pY + 1, pZ );
5752// }
5753// else
5754// {
5755// llxYZ = llx0Z;
5756// }
5757// if ( llTransX0Z || llTrans0yZ )
5758// {
5759// llXyZ = tt->getBrightness( level, pX + 1, pY - 1, pZ );
5760// }
5761// else
5762// {
5763// llXyZ = llX0Z;
5764// }
5765// if ( llTransX0Z || llTrans0YZ )
5766// {
5767// llXYZ = tt->getBrightness( level, pX + 1, pY + 1, pZ );
5768// }
5769// else
5770// {
5771// llXYZ = llX0Z;
5772// }
5773// pZ--;
5774// ll1 = ( llx0Z + llxYZ + ll00Z + ll0YZ ) / 4.0f;
5775// ll4 = ( ll00Z + ll0YZ + llX0Z + llXYZ ) / 4.0f;
5776// ll3 = ( ll0yZ + ll00Z + llXyZ + llX0Z ) / 4.0f;
5777// ll2 = ( llxyZ + llx0Z + ll0yZ + ll00Z ) / 4.0f;
5778// }
5779// else
5780// {
5781// ll1 = ll2 = ll3 = ll4 = ll00Z;
5782// }
5783// c1r = c2r = c3r = c4r = ( tint3 ? pBaseRed : 1.0f ) * 0.8f;
5784// c1g = c2g = c3g = c4g = ( tint3 ? pBaseGreen : 1.0f ) * 0.8f;
5785// c1b = c2b = c3b = c4b = ( tint3 ? pBaseBlue : 1.0f ) * 0.8f;
5786// c1r *= ll1;
5787// c1g *= ll1;
5788// c1b *= ll1;
5789// c2r *= ll2;
5790// c2g *= ll2;
5791// c2b *= ll2;
5792// c3r *= ll3;
5793// c3g *= ll3;
5794// c3b *= ll3;
5795// c4r *= ll4;
5796// c4g *= ll4;
5797// c4b *= ll4;
5798// Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 3);
5799// renderSouth( tt, ( float )pX, ( float )pY, ( float )pZ, getTexture(tt, level, pX, pY, pZ, 3 ) );
5800// if ( fancy && (tex->getName().compare(L"grass_side") == 0) && !hasFixedTexture() )
5801// {
5802// c1r *= pBaseRed;
5803// c2r *= pBaseRed;
5804// c3r *= pBaseRed;
5805// c4r *= pBaseRed;
5806// c1g *= pBaseGreen;
5807// c2g *= pBaseGreen;
5808// c3g *= pBaseGreen;
5809// c4g *= pBaseGreen;
5810// c1b *= pBaseBlue;
5811// c2b *= pBaseBlue;
5812// c3b *= pBaseBlue;
5813// c4b *= pBaseBlue;
5814// renderSouth( tt, ( float )pX, ( float )pY, ( float )pZ, getGrassSideTextureOverlay() );
5815// }
5816// }
5817// if ( faceFlags & 0x10 )
5818// {
5819// if ( blsmooth > 0 )
5820// {
5821// pX--;
5822// llxy0 = tt->getBrightness( level, pX, pY - 1, pZ );
5823// llx0z = tt->getBrightness( level, pX, pY, pZ - 1 );
5824// llx0Z = tt->getBrightness( level, pX, pY, pZ + 1 );
5825// llxY0 = tt->getBrightness( level, pX, pY + 1, pZ );
5826//
5827// if ( llTransx0z || llTransxy0 )
5828// {
5829// llxyz = tt->getBrightness( level, pX, pY - 1, pZ - 1 );
5830// }
5831// else
5832// {
5833// llxyz = llx0z;
5834// }
5835// if ( llTransx0Z || llTransxy0 )
5836// {
5837// llxyZ = tt->getBrightness( level, pX, pY - 1, pZ + 1 );
5838// }
5839// else
5840// {
5841// llxyZ = llx0Z;
5842// }
5843// if ( llTransx0z || llTransxY0 )
5844// {
5845// llxYz = tt->getBrightness( level, pX, pY + 1, pZ - 1 );
5846// }
5847// else
5848// {
5849// llxYz = llx0z;
5850// }
5851// if ( llTransx0Z || llTransxY0 )
5852// {
5853// llxYZ = tt->getBrightness( level, pX, pY + 1, pZ + 1 );
5854// }
5855// else
5856// {
5857// llxYZ = llx0Z;
5858// }
5859// pX++;
5860// ll4 = ( llxy0 + llxyZ + llx00 + llx0Z ) / 4.0f;
5861// ll1 = ( llx00 + llx0Z + llxY0 + llxYZ ) / 4.0f;
5862// ll2 = ( llx0z + llx00 + llxYz + llxY0 ) / 4.0f;
5863// ll3 = ( llxyz + llxy0 + llx0z + llx00 ) / 4.0f;
5864// }
5865// else
5866// {
5867// ll1 = ll2 = ll3 = ll4 = llx00;
5868// }
5869// c1r = c2r = c3r = c4r = ( tint4 ? pBaseRed : 1.0f ) * 0.6f;
5870// c1g = c2g = c3g = c4g = ( tint4 ? pBaseGreen : 1.0f ) * 0.6f;
5871// c1b = c2b = c3b = c4b = ( tint4 ? pBaseBlue : 1.0f ) * 0.6f;
5872// c1r *= ll1;
5873// c1g *= ll1;
5874// c1b *= ll1;
5875// c2r *= ll2;
5876// c2g *= ll2;
5877// c2b *= ll2;
5878// c3r *= ll3;
5879// c3g *= ll3;
5880// c3b *= ll3;
5881// c4r *= ll4;
5882// c4g *= ll4;
5883// c4b *= ll4;
5884// Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 4);
5885// renderWest( tt, ( float )pX, ( float )pY, ( float )pZ, tex );
5886// if ( fancy &&(tex->getName().compare(L"grass_side") == 0) && !hasFixedTexture() )
5887// {
5888// c1r *= pBaseRed;
5889// c2r *= pBaseRed;
5890// c3r *= pBaseRed;
5891// c4r *= pBaseRed;
5892// c1g *= pBaseGreen;
5893// c2g *= pBaseGreen;
5894// c3g *= pBaseGreen;
5895// c4g *= pBaseGreen;
5896// c1b *= pBaseBlue;
5897// c2b *= pBaseBlue;
5898// c3b *= pBaseBlue;
5899// c4b *= pBaseBlue;
5900// renderWest( tt, ( float )pX, ( float )pY, ( float )pZ, getGrassSideTextureOverlay() );
5901// }
5902// }
5903// if ( faceFlags & 0x20 )
5904// {
5905// if ( blsmooth > 0 )
5906// {
5907// pX++;
5908// llXy0 = tt->getBrightness( level, pX, pY - 1, pZ );
5909// llX0z = tt->getBrightness( level, pX, pY, pZ - 1 );
5910// llX0Z = tt->getBrightness( level, pX, pY, pZ + 1 );
5911// llXY0 = tt->getBrightness( level, pX, pY + 1, pZ );
5912//
5913// if ( llTransXy0 || llTransX0z )
5914// {
5915// llXyz = tt->getBrightness( level, pX, pY - 1, pZ - 1 );
5916// }
5917// else
5918// {
5919// llXyz = llX0z;
5920// }
5921// if ( llTransXy0 || llTransX0Z )
5922// {
5923// llXyZ = tt->getBrightness( level, pX, pY - 1, pZ + 1 );
5924// }
5925// else
5926// {
5927// llXyZ = llX0Z;
5928// }
5929// if ( llTransXY0 || llTransX0z )
5930// {
5931// llXYz = tt->getBrightness( level, pX, pY + 1, pZ - 1 );
5932// }
5933// else
5934// {
5935// llXYz = llX0z;
5936// }
5937// if ( llTransXY0 || llTransX0Z )
5938// {
5939// llXYZ = tt->getBrightness( level, pX, pY + 1, pZ + 1 );
5940// }
5941// else
5942// {
5943// llXYZ = llX0Z;
5944// }
5945// pX--;
5946// ll1 = ( llXy0 + llXyZ + llX00 + llX0Z ) / 4.0f;
5947// ll4 = ( llX00 + llX0Z + llXY0 + llXYZ ) / 4.0f;
5948// ll3 = ( llX0z + llX00 + llXYz + llXY0 ) / 4.0f;
5949// ll2 = ( llXyz + llXy0 + llX0z + llX00 ) / 4.0f;
5950// }
5951// else
5952// {
5953// ll1 = ll2 = ll3 = ll4 = llX00;
5954// }
5955// c1r = c2r = c3r = c4r = ( tint5 ? pBaseRed : 1.0f ) * 0.6f;
5956// c1g = c2g = c3g = c4g = ( tint5 ? pBaseGreen : 1.0f ) * 0.6f;
5957// c1b = c2b = c3b = c4b = ( tint5 ? pBaseBlue : 1.0f ) * 0.6f;
5958// c1r *= ll1;
5959// c1g *= ll1;
5960// c1b *= ll1;
5961// c2r *= ll2;
5962// c2g *= ll2;
5963// c2b *= ll2;
5964// c3r *= ll3;
5965// c3g *= ll3;
5966// c3b *= ll3;
5967// c4r *= ll4;
5968// c4g *= ll4;
5969// c4b *= ll4;
5970//
5971// Icon_SPU *tex = getTexture(tt, level, pX, pY, pZ, 5);
5972// renderEast( tt, ( float )pX, ( float )pY, ( float )pZ, tex );
5973// if ( fancy && (tex->getName().compare(L"grass_side") == 0) && !hasFixedTexture() )
5974// {
5975// c1r *= pBaseRed;
5976// c2r *= pBaseRed;
5977// c3r *= pBaseRed;
5978// c4r *= pBaseRed;
5979// c1g *= pBaseGreen;
5980// c2g *= pBaseGreen;
5981// c3g *= pBaseGreen;
5982// c4g *= pBaseGreen;
5983// c1b *= pBaseBlue;
5984// c2b *= pBaseBlue;
5985// c3b *= pBaseBlue;
5986// c4b *= pBaseBlue;
5987// renderEast( tt, ( float )pX, ( float )pY, ( float )pZ, getGrassSideTextureOverlay() );
5988// }
5989// }
5990// applyAmbienceOcclusion = false;
5991//
5992 return true;
5993
5994}
5995
5996// 4J - brought forward from 1.8.2
5997int TileRenderer_SPU::blend( int a, int b, int c, int def )
5998{
5999 if ( a == 0 ) a = def;
6000 if ( b == 0 ) b = def;
6001 if ( c == 0 ) c = def;
6002 return ( ( a + b + c + def ) >> 2 ) & 0xff00ff;
6003}
6004
6005int TileRenderer_SPU::blend(int a, int b, int c, int d, float fa, float fb, float fc, float fd)
6006{
6007
6008 int top = (int) ((float) ((a >> 16) & 0xff) * fa + (float) ((b >> 16) & 0xff) * fb + (float) ((c >> 16) & 0xff) * fc + (float) ((d >> 16) & 0xff) * fd) & 0xff;
6009 int bottom = (int) ((float) (a & 0xff) * fa + (float) (b & 0xff) * fb + (float) (c & 0xff) * fc + (float) (d & 0xff) * fd) & 0xff;
6010 return (top << 16) | bottom;
6011}
6012
6013bool TileRenderer_SPU::tesselateBlockInWorld( Tile_SPU* tt, int x, int y, int z, float r, float g, float b )
6014{
6015 applyAmbienceOcclusion = false;
6016
6017 Tesselator_SPU* t = getTesselator();
6018
6019 bool changed = false;
6020 float c10 = 0.5f;
6021 float c11 = 1;
6022 float c2 = 0.8f;
6023 float c3 = 0.6f;
6024
6025 float r11 = c11 * r;
6026 float g11 = c11 * g;
6027 float b11 = c11 * b;
6028
6029 float r10 = c10;
6030 float r2 = c2;
6031 float r3 = c3;
6032
6033 float g10 = c10;
6034 float g2 = c2;
6035 float g3 = c3;
6036
6037 float b10 = c10;
6038 float b2 = c2;
6039 float b3 = c3;
6040
6041 if ( tt->id != Tile_SPU::grass_Id )
6042 {
6043 r10 *= r;
6044 r2 *= r;
6045 r3 *= r;
6046
6047 g10 *= g;
6048 g2 *= g;
6049 g3 *= g;
6050
6051 b10 *= b;
6052 b2 *= b;
6053 b3 *= b;
6054 }
6055
6056 int centerColor = 0;
6057 float centerBrightness = 0.0f;
6058 if ( SharedConstants::TEXTURE_LIGHTING )
6059 {
6060 centerColor = tt->getLightColor( level, x, y, z );
6061 }
6062 else
6063 {
6064 centerBrightness = tt->getBrightness( level, x, y, z );
6065 }
6066
6067 if ( noCulling || tt->shouldRenderFace( level, x, y - 1, z, Facing::DOWN ) )
6068 {
6069 if ( SharedConstants::TEXTURE_LIGHTING )
6070 {
6071 t->tex2( tileShapeY0 > 0 ? centerColor : tt->getLightColor( level, x, y - 1, z ) );
6072 t->color( r10, g10, b10 );
6073 }
6074 else
6075 {
6076 float br = tt->getBrightness( level, x, y - 1, z );
6077 t->color( r10 * br, g10 * br, b10 * br );
6078 }
6079 renderFaceDown( tt, x, y, z, getTexture(tt, level, x, y, z, 0 ) );
6080 changed = true;
6081 }
6082
6083 if ( noCulling || tt->shouldRenderFace( level, x, y + 1, z, Facing::UP ) )
6084 {
6085 if ( SharedConstants::TEXTURE_LIGHTING )
6086 {
6087 t->tex2( tileShapeY1 < 1 ? centerColor : tt->getLightColor( level, x, y + 1, z ) );
6088 t->color( r11, g11, b11 );
6089 }
6090 else
6091 {
6092 float br = tt->getBrightness( level, x, y + 1, z );
6093 // spu_print("need to add material settings\n");
6094// if ( tileShapeY1 != 1 && !tt->material->isLiquid() ) br = centerBrightness;
6095 t->color( r11 * br, g11 * br, b11 * br );
6096 }
6097 renderFaceUp( tt, x, y, z, getTexture(tt, level, x, y, z, 1 ) );
6098 changed = true;
6099 }
6100
6101 if ( noCulling || tt->shouldRenderFace( level, x, y, z - 1, Facing::NORTH ) )
6102 {
6103 if ( SharedConstants::TEXTURE_LIGHTING )
6104 {
6105 t->tex2( tileShapeZ0 > 0 ? centerColor : tt->getLightColor( level, x, y, z - 1 ) );
6106 t->color( r2, g2, b2 );
6107 }
6108 else
6109 {
6110 float br = tt->getBrightness( level, x, y, z - 1 );
6111 if ( tileShapeZ0 > 0 ) br = centerBrightness;
6112 t->color( r2 * br, g2 * br, b2 * br );
6113 }
6114
6115 Icon_SPU *tex = getTexture(tt, level, x, y, z, 2);
6116 renderNorth( tt, x, y, z, tex );
6117
6118 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
6119 {
6120 t->color( r2 * r, g2 * g, b2 * b );
6121 renderNorth( tt, x, y, z, GrassTile_SPU::getSideTextureOverlay() );
6122 }
6123 changed = true;
6124 }
6125
6126 if ( noCulling || tt->shouldRenderFace( level, x, y, z + 1, Facing::SOUTH ) )
6127 {
6128 if ( SharedConstants::TEXTURE_LIGHTING )
6129 {
6130 t->tex2( tileShapeZ1 < 1 ? centerColor : tt->getLightColor( level, x, y, z + 1 ) );
6131 t->color( r2, g2, b2 );
6132 }
6133 else
6134 {
6135 float br = tt->getBrightness( level, x, y, z + 1 );
6136 if ( tileShapeZ1 < 1 ) br = centerBrightness;
6137 t->color( r2 * br, g2 * br, b2 * br );
6138 }
6139 Icon_SPU *tex = getTexture(tt, level, x, y, z, 3);
6140 renderSouth( tt, x, y, z, tex );
6141
6142 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
6143 {
6144 t->color( r2 * r, g2 * g, b2 * b );
6145 renderSouth( tt, x, y, z, GrassTile_SPU::getSideTextureOverlay() );
6146 }
6147 changed = true;
6148 }
6149
6150 if ( noCulling || tt->shouldRenderFace( level, x - 1, y, z, Facing::WEST ) )
6151 {
6152 if ( SharedConstants::TEXTURE_LIGHTING )
6153 {
6154 t->tex2( tileShapeX0 > 0 ? centerColor : tt->getLightColor( level, x - 1, y, z ) );
6155 t->color( r3, g3, b3 );
6156 }
6157 else
6158 {
6159 float br = tt->getBrightness( level, x - 1, y, z );
6160 if ( tileShapeX0 > 0 ) br = centerBrightness;
6161 t->color( r3 * br, g3 * br, b3 * br );
6162 }
6163 Icon_SPU *tex = getTexture(tt, level, x, y, z, 4);
6164 renderWest( tt, x, y, z, tex );
6165
6166 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
6167 {
6168 t->color( r3 * r, g3 * g, b3 * b );
6169 renderWest( tt, x, y, z, GrassTile_SPU::getSideTextureOverlay() );
6170 }
6171 changed = true;
6172 }
6173
6174 if ( noCulling || tt->shouldRenderFace( level, x + 1, y, z, Facing::EAST ) )
6175 {
6176 if ( SharedConstants::TEXTURE_LIGHTING )
6177 {
6178 t->tex2( tileShapeX1 < 1 ? centerColor : tt->getLightColor( level, x + 1, y, z ) );
6179 t->color( r3, g3, b3 );
6180 }
6181 else
6182 {
6183 float br = tt->getBrightness( level, x + 1, y, z );
6184 if ( tileShapeX1 < 1 ) br = centerBrightness;
6185 t->color( r3 * br, g3 * br, b3 * br );
6186 }
6187 Icon_SPU *tex = getTexture(tt, level, x, y, z, 5);
6188 renderEast( tt, x, y, z, tex );
6189
6190 if ( fancy && (tex == &Tile_SPU::ms_pTileData->iconData[Tile_SPU::grass_Id] && !hasFixedTexture() ))
6191 {
6192 t->color( r3 * r, g3 * g, b3 * b );
6193 renderEast( tt, x, y, z, GrassTile_SPU::getSideTextureOverlay() );
6194 }
6195 changed = true;
6196 }
6197
6198 return changed;
6199
6200}
6201
6202bool TileRenderer_SPU::tesselateCactusInWorld( Tile_SPU* tt, int x, int y, int z )
6203{
6204 int col = tt->getColor( level, x, y, z );
6205 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
6206 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
6207 float b = ( ( col )& 0xff ) / 255.0f;
6208
6209 if ( isAnaglyph3d() )
6210 {
6211 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
6212 float cg = ( r * 30 + g * 70 ) / ( 100 );
6213 float cb = ( r * 30 + b * 70 ) / ( 100 );
6214
6215 r = cr;
6216 g = cg;
6217 b = cb;
6218 }
6219 return tesselateCactusInWorld( tt, x, y, z, r, g, b );
6220}
6221
6222bool TileRenderer_SPU::tesselateCactusInWorld( Tile_SPU* tt, int x, int y, int z, float r, float g, float b )
6223{
6224 Tesselator_SPU* t = getTesselator();
6225
6226 bool changed = false;
6227 float c10 = 0.5f;
6228 float c11 = 1;
6229 float c2 = 0.8f;
6230 float c3 = 0.6f;
6231
6232 float r10 = c10 * r;
6233 float r11 = c11 * r;
6234 float r2 = c2 * r;
6235 float r3 = c3 * r;
6236
6237 float g10 = c10 * g;
6238 float g11 = c11 * g;
6239 float g2 = c2 * g;
6240 float g3 = c3 * g;
6241
6242 float b10 = c10 * b;
6243 float b11 = c11 * b;
6244 float b2 = c2 * b;
6245 float b3 = c3 * b;
6246
6247 float s = 1 / 16.0f;
6248
6249 float centerBrightness = 0.0f;
6250 int centerColor = 0;
6251 if ( SharedConstants::TEXTURE_LIGHTING )
6252 {
6253 centerColor = tt->getLightColor( level, x, y, z );
6254 }
6255 else
6256 {
6257 centerBrightness = tt->getBrightness( level, x, y, z );
6258 }
6259
6260 if ( noCulling || tt->shouldRenderFace( level, x, y - 1, z, 0 ) )
6261 {
6262 if ( SharedConstants::TEXTURE_LIGHTING )
6263 {
6264 t->tex2( tileShapeY0 > 0 ? centerColor : tt->getLightColor( level, x, y - 1, z ) );
6265 t->color( r10, g10, b10 );
6266 }
6267 else
6268 {
6269 float br = tt->getBrightness( level, x, y - 1, z );
6270 t->color( r10 * br, g10 * br, b10 * br );
6271 }
6272 renderFaceDown( tt, x, y, z, getTexture( tt, level, x, y, z, 0 ) );
6273 changed = true;
6274 }
6275
6276 if ( noCulling || tt->shouldRenderFace( level, x, y + 1, z, 1 ) )
6277 {
6278 if ( SharedConstants::TEXTURE_LIGHTING )
6279 {
6280 t->tex2( tileShapeY1 < 1 ? centerColor : tt->getLightColor( level, x, y + 1, z ) );
6281 t->color( r11, g11, b11 );
6282 }
6283 else
6284 {
6285 float br = tt->getBrightness( level, x, y + 1, z );
6286 if ( tileShapeY1 != 1 && !tt->getMaterial()->isLiquid() ) br = centerBrightness;
6287 t->color( r11 * br, g11 * br, b11 * br );
6288 }
6289 renderFaceUp( tt, x, y, z, getTexture( tt, level, x, y, z, 1 ) );
6290 changed = true;
6291 }
6292
6293 if ( noCulling || tt->shouldRenderFace( level, x, y, z - 1, 2 ) )
6294 {
6295 if ( SharedConstants::TEXTURE_LIGHTING )
6296 {
6297 t->tex2( tileShapeZ0 > 0 ? centerColor : tt->getLightColor( level, x, y, z - 1 ) );
6298 t->color( r2, g2, b2 );
6299 }
6300 else
6301 {
6302 float br = tt->getBrightness( level, x, y, z - 1 );
6303 if ( tileShapeZ0 > 0 ) br = centerBrightness;
6304 t->color( r2 * br, g2 * br, b2 * br );
6305 }
6306 t->addOffset( 0, 0, s );
6307 renderNorth( tt, x, y, z, getTexture(tt, level, x, y, z, 2 ) );
6308 t->addOffset( 0, 0, -s );
6309 changed = true;
6310 }
6311
6312 if ( noCulling || tt->shouldRenderFace( level, x, y, z + 1, 3 ) )
6313 {
6314 if ( SharedConstants::TEXTURE_LIGHTING )
6315 {
6316 t->tex2( tileShapeZ1 < 1 ? centerColor : tt->getLightColor( level, x, y, z + 1 ) );
6317 t->color( r2, g2, b2 );
6318 }
6319 else
6320 {
6321 float br = tt->getBrightness( level, x, y, z + 1 );
6322 if ( tileShapeZ1 < 1 ) br = centerBrightness;
6323 t->color( r2 * br, g2 * br, b2 * br );
6324 }
6325
6326 t->addOffset( 0, 0, -s );
6327 renderSouth( tt, x, y, z, getTexture(tt, level, x, y, z, 3 ) );
6328 t->addOffset( 0, 0, s );
6329 changed = true;
6330 }
6331
6332 if ( noCulling || tt->shouldRenderFace( level, x - 1, y, z, 4 ) )
6333 {
6334 if ( SharedConstants::TEXTURE_LIGHTING )
6335 {
6336 t->tex2( tileShapeX0 > 0 ? centerColor : tt->getLightColor( level, x - 1, y, z ) );
6337 t->color( r3, g3, b3 );
6338 }
6339 else
6340 {
6341 float br = tt->getBrightness( level, x - 1, y, z );
6342 if ( tileShapeX0 > 0 ) br = centerBrightness;
6343 t->color( r3 * br, g3 * br, b3 * br );
6344 }
6345 t->addOffset( s, 0, 0 );
6346 renderWest( tt, x, y, z, getTexture(tt, level, x, y, z, 4 ) );
6347 t->addOffset( -s, 0, 0 );
6348 changed = true;
6349 }
6350
6351 if ( noCulling || tt->shouldRenderFace( level, x + 1, y, z, 5 ) )
6352 {
6353 if ( SharedConstants::TEXTURE_LIGHTING )
6354 {
6355 t->tex2( tileShapeX1 < 1 ? centerColor : tt->getLightColor( level, x + 1, y, z ) );
6356 t->color( r3, g3, b3 );
6357 }
6358 else
6359 {
6360 float br = tt->getBrightness( level, x + 1, y, z );
6361 if ( tileShapeX1 < 1 ) br = centerBrightness;
6362 t->color( r3 * br, g3 * br, b3 * br );
6363 }
6364 t->addOffset( -s, 0, 0 );
6365 renderEast( tt, x, y, z, getTexture(tt, level, x, y, z, 5 ) );
6366 t->addOffset( s, 0, 0 );
6367 changed = true;
6368 }
6369
6370 return changed;
6371}
6372
6373bool TileRenderer_SPU::tesselateFenceInWorld( FenceTile_SPU* tt, int x, int y, int z )
6374{
6375// #ifdef DISABLE_TESS_FUNCS
6376 bool changed = false;
6377
6378 float a = 6 / 16.0f;
6379 float b = 10 / 16.0f;
6380// EnterCriticalSection( &Tile_SPU::m_csShape );
6381 setShape( a, 0, a, b, 1, b );
6382 tesselateBlockInWorld( tt, x, y, z );
6383 changed = true;
6384
6385 bool vertical = false;
6386 bool horizontal = false;
6387
6388 if (tt->connectsTo(level, x - 1, y, z) || tt->connectsTo(level, x + 1, y, z)) vertical = true;
6389 if (tt->connectsTo(level, x, y, z - 1) || tt->connectsTo(level, x, y, z + 1)) horizontal = true;
6390
6391 bool l = tt->connectsTo(level, x - 1, y, z);
6392 bool r = tt->connectsTo(level, x + 1, y, z);
6393 bool u = tt->connectsTo(level, x, y, z - 1);
6394 bool d = tt->connectsTo(level, x, y, z + 1);
6395
6396 if ( !vertical && !horizontal ) vertical = true;
6397
6398 a = 7 / 16.0f;
6399 b = 9 / 16.0f;
6400 float h0 = 12 / 16.0f;
6401 float h1 = 15 / 16.0f;
6402
6403 float x0 = l ? 0 : a;
6404 float x1 = r ? 1 : b;
6405 float z0 = u ? 0 : a;
6406 float z1 = d ? 1 : b;
6407 if ( vertical )
6408 {
6409 setShape( x0, h0, a, x1, h1, b );
6410 tesselateBlockInWorld( tt, x, y, z );
6411 changed = true;
6412 }
6413 if ( horizontal )
6414 {
6415 setShape( a, h0, z0, b, h1, z1 );
6416 tesselateBlockInWorld( tt, x, y, z );
6417 changed = true;
6418 }
6419
6420 h0 = 6 / 16.0f;
6421 h1 = 9 / 16.0f;
6422 if ( vertical )
6423 {
6424 setShape( x0, h0, a, x1, h1, b );
6425 tesselateBlockInWorld( tt, x, y, z );
6426 changed = true;
6427 }
6428 if ( horizontal )
6429 {
6430 setShape( a, h0, z0, b, h1, z1 );
6431 tesselateBlockInWorld( tt, x, y, z );
6432 changed = true;
6433 }
6434
6435 tt->updateShape(level, x, y, z);
6436// LeaveCriticalSection( &Tile_SPU::m_csShape );
6437 return changed;
6438// #endif // #ifdef DISABLE_TESS_FUNCS
6439 return false;
6440}
6441
6442bool TileRenderer_SPU::tesselateWallInWorld(WallTile_SPU *tt, int x, int y, int z)
6443{
6444 bool w = tt->connectsTo(level, x - 1, y, z);
6445 bool e = tt->connectsTo(level, x + 1, y, z);
6446 bool n = tt->connectsTo(level, x, y, z - 1);
6447 bool s = tt->connectsTo(level, x, y, z + 1);
6448
6449 bool vertical = (n && s && !w && !e);
6450 bool horizontal = (!n && !s && w && e);
6451 bool emptyAbove = level->isEmptyTile(x, y + 1, z);
6452
6453 if ((!vertical && !horizontal) || !emptyAbove)
6454 {
6455 // center post
6456 setShape(.5f - WallTile_SPU::POST_WIDTH, 0, .5f - WallTile_SPU::POST_WIDTH, .5f + WallTile_SPU::POST_WIDTH, WallTile_SPU::POST_HEIGHT, .5f + WallTile_SPU::POST_WIDTH);
6457 tesselateBlockInWorld(tt, x, y, z);
6458
6459 if (w)
6460 {
6461 setShape(0, 0, .5f - WallTile_SPU::WALL_WIDTH, .5f - WallTile_SPU::POST_WIDTH, WallTile_SPU::WALL_HEIGHT, .5f + WallTile_SPU::WALL_WIDTH);
6462 tesselateBlockInWorld(tt, x, y, z);
6463 }
6464 if (e)
6465 {
6466 setShape(.5f + WallTile_SPU::POST_WIDTH, 0, .5f - WallTile_SPU::WALL_WIDTH, 1, WallTile_SPU::WALL_HEIGHT, .5f + WallTile_SPU::WALL_WIDTH);
6467 tesselateBlockInWorld(tt, x, y, z);
6468 }
6469 if (n)
6470 {
6471 setShape(.5f - WallTile_SPU::WALL_WIDTH, 0, 0, .5f + WallTile_SPU::WALL_WIDTH, WallTile_SPU::WALL_HEIGHT, .5f - WallTile_SPU::POST_WIDTH);
6472 tesselateBlockInWorld(tt, x, y, z);
6473 }
6474 if (s)
6475 {
6476 setShape(.5f - WallTile_SPU::WALL_WIDTH, 0, .5f + WallTile_SPU::POST_WIDTH, .5f + WallTile_SPU::WALL_WIDTH, WallTile_SPU::WALL_HEIGHT, 1);
6477 tesselateBlockInWorld(tt, x, y, z);
6478 }
6479 }
6480 else if (vertical)
6481 {
6482 // north-south wall
6483 setShape(.5f - WallTile_SPU::WALL_WIDTH, 0, 0, .5f + WallTile_SPU::WALL_WIDTH, WallTile_SPU::WALL_HEIGHT, 1);
6484 tesselateBlockInWorld(tt, x, y, z);
6485 }
6486 else
6487 {
6488 // west-east wall
6489 setShape(0, 0, .5f - WallTile_SPU::WALL_WIDTH, 1, WallTile_SPU::WALL_HEIGHT, .5f + WallTile_SPU::WALL_WIDTH);
6490 tesselateBlockInWorld(tt, x, y, z);
6491 }
6492
6493 tt->updateShape(level, x, y, z);
6494 return true;
6495}
6496
6497
6498bool TileRenderer_SPU::tesselateEggInWorld(EggTile_SPU *tt, int x, int y, int z)
6499{
6500 bool changed = false;
6501// EnterCriticalSection( &Tile_SPU::m_csShape );
6502
6503 int y0 = 0;
6504 for (int i = 0; i < 8; i++)
6505 {
6506 int ww = 0;
6507 int hh = 1;
6508 if (i == 0) ww = 2;
6509 if (i == 1) ww = 3;
6510 if (i == 2) ww = 4;
6511 if (i == 3)
6512 {
6513 ww = 5;
6514 hh = 2;
6515 }
6516 if (i == 4)
6517 {
6518 ww = 6;
6519 hh = 3;
6520 }
6521 if (i == 5)
6522 {
6523 ww = 7;
6524 hh = 5;
6525 }
6526 if (i == 6)
6527 {
6528 ww = 6;
6529 hh = 2;
6530 }
6531 if (i == 7) ww = 3;
6532 float w = ww / 16.0f;
6533 float yy1 = 1 - (y0 / 16.0f);
6534 float yy0 = 1 - ((y0 + hh) / 16.0f);
6535 y0 += hh;
6536 setShape(0.5f - w, yy0, 0.5f - w, 0.5f + w, yy1, 0.5f + w);
6537 tesselateBlockInWorld(tt, x, y, z);
6538 }
6539 changed = true;
6540
6541 setShape(0, 0, 0, 1, 1, 1);
6542// LeaveCriticalSection( &Tile_SPU::m_csShape );
6543 return changed;
6544}
6545
6546bool TileRenderer_SPU::tesselateFenceGateInWorld(FenceGateTile_SPU *tt, int x, int y, int z)
6547{
6548 bool changed = true;
6549#ifdef DISABLE_TESS_FUNCS
6550
6551 int data = level->getData(x, y, z);
6552 bool isOpen = FenceGateTile_SPU::isOpen(data);
6553 int direction = FenceGateTile_SPU::getDirection(data);
6554
6555 float h00 = 6 / 16.0f;
6556 float h01 = 9 / 16.0f;
6557 float h10 = 12 / 16.0f;
6558 float h11 = 15 / 16.0f;
6559 float h20 = 5 / 16.0f;
6560 float h21 = 16 / 16.0f;
6561
6562 //if (((direction == Direction::NORTH || direction == Direction::SOUTH) && level->getTile(x - 1, y, z) == Tile_SPU::cobbleWall_Id && level->getTile(x + 1, y, z) == Tile_SPU::cobbleWall_Id)
6563 // || ((direction == Direction::EAST || direction == Direction::WEST) && level->getTile(x, y, z - 1) == Tile_SPU::cobbleWall_Id && level->getTile(x, y, z + 1) == Tile_SPU::cobbleWall_Id))
6564 //{
6565 // h00 -= 3.0f / 16.0f;
6566 // h01 -= 3.0f / 16.0f;
6567 // h10 -= 3.0f / 16.0f;
6568 // h11 -= 3.0f / 16.0f;
6569 // h20 -= 3.0f / 16.0f;
6570 // h21 -= 3.0f / 16.0f;
6571 //}
6572
6573 noCulling = true;
6574
6575// EnterCriticalSection( &Tile_SPU::m_csShape );
6576
6577 // edge sticks
6578 if (direction == Direction::EAST || direction == Direction::WEST)
6579 {
6580 upFlip = FLIP_CW;
6581 float x0 = 7 / 16.0f;
6582 float x1 = 9 / 16.0f;
6583 float z0 = 0 / 16.0f;
6584 float z1 = 2 / 16.0f;
6585 setShape(x0, h20, z0, x1, h21, z1);
6586 tesselateBlockInWorld(tt, x, y, z);
6587
6588 z0 = 14 / 16.0f;
6589 z1 = 16 / 16.0f;
6590 setShape(x0, h20, z0, x1, h21, z1);
6591 tesselateBlockInWorld(tt, x, y, z);
6592 upFlip = FLIP_NONE;
6593 }
6594 else
6595 {
6596 float x0 = 0 / 16.0f;
6597 float x1 = 2 / 16.0f;
6598 float z0 = 7 / 16.0f;
6599 float z1 = 9 / 16.0f;
6600 setShape(x0, h20, z0, x1, h21, z1);
6601 tesselateBlockInWorld(tt, x, y, z);
6602
6603 x0 = 14 / 16.0f;
6604 x1 = 16 / 16.0f;
6605 setShape(x0, h20, z0, x1, h21, z1);
6606 tesselateBlockInWorld(tt, x, y, z);
6607 }
6608 if (isOpen)
6609 {
6610 if (direction == Direction::NORTH || direction == Direction::SOUTH)
6611 {
6612 upFlip = FLIP_CW;
6613 }
6614 if (direction == Direction::EAST)
6615 {
6616
6617 const float z00 = 0 / 16.0f;
6618 const float z01 = 2 / 16.0f;
6619 const float z10 = 14 / 16.0f;
6620 const float z11 = 16 / 16.0f;
6621
6622 const float x0 = 9 / 16.0f;
6623 const float x1 = 13 / 16.0f;
6624 const float x2 = 15 / 16.0f;
6625
6626 setShape(x1, h00, z00, x2, h11, z01);
6627 tesselateBlockInWorld(tt, x, y, z);
6628 setShape(x1, h00, z10, x2, h11, z11);
6629 tesselateBlockInWorld(tt, x, y, z);
6630
6631 setShape(x0, h00, z00, x1, h01, z01);
6632 tesselateBlockInWorld(tt, x, y, z);
6633 setShape(x0, h00, z10, x1, h01, z11);
6634 tesselateBlockInWorld(tt, x, y, z);
6635
6636 setShape(x0, h10, z00, x1, h11, z01);
6637 tesselateBlockInWorld(tt, x, y, z);
6638 setShape(x0, h10, z10, x1, h11, z11);
6639 tesselateBlockInWorld(tt, x, y, z);
6640 }
6641 else if (direction == Direction::WEST)
6642 {
6643 const float z00 = 0 / 16.0f;
6644 const float z01 = 2 / 16.0f;
6645 const float z10 = 14 / 16.0f;
6646 const float z11 = 16 / 16.0f;
6647
6648 const float x0 = 1 / 16.0f;
6649 const float x1 = 3 / 16.0f;
6650 const float x2 = 7 / 16.0f;
6651
6652 setShape(x0, h00, z00, x1, h11, z01);
6653 tesselateBlockInWorld(tt, x, y, z);
6654 setShape(x0, h00, z10, x1, h11, z11);
6655 tesselateBlockInWorld(tt, x, y, z);
6656
6657 setShape(x1, h00, z00, x2, h01, z01);
6658 tesselateBlockInWorld(tt, x, y, z);
6659 setShape(x1, h00, z10, x2, h01, z11);
6660 tesselateBlockInWorld(tt, x, y, z);
6661
6662 setShape(x1, h10, z00, x2, h11, z01);
6663 tesselateBlockInWorld(tt, x, y, z);
6664 setShape(x1, h10, z10, x2, h11, z11);
6665 tesselateBlockInWorld(tt, x, y, z);
6666 }
6667 else if (direction == Direction::SOUTH)
6668 {
6669
6670 const float x00 = 0 / 16.0f;
6671 const float x01 = 2 / 16.0f;
6672 const float x10 = 14 / 16.0f;
6673 const float x11 = 16 / 16.0f;
6674
6675 const float z0 = 9 / 16.0f;
6676 const float z1 = 13 / 16.0f;
6677 const float z2 = 15 / 16.0f;
6678
6679 setShape(x00, h00, z1, x01, h11, z2);
6680 tesselateBlockInWorld(tt, x, y, z);
6681 setShape(x10, h00, z1, x11, h11, z2);
6682 tesselateBlockInWorld(tt, x, y, z);
6683
6684 setShape(x00, h00, z0, x01, h01, z1);
6685 tesselateBlockInWorld(tt, x, y, z);
6686 setShape(x10, h00, z0, x11, h01, z1);
6687 tesselateBlockInWorld(tt, x, y, z);
6688
6689 setShape(x00, h10, z0, x01, h11, z1);
6690 tesselateBlockInWorld(tt, x, y, z);
6691 setShape(x10, h10, z0, x11, h11, z1);
6692 tesselateBlockInWorld(tt, x, y, z);
6693 }
6694 else if (direction == Direction::NORTH)
6695 {
6696 const float x00 = 0 / 16.0f;
6697 const float x01 = 2 / 16.0f;
6698 const float x10 = 14 / 16.0f;
6699 const float x11 = 16 / 16.0f;
6700
6701 const float z0 = 1 / 16.0f;
6702 const float z1 = 3 / 16.0f;
6703 const float z2 = 7 / 16.0f;
6704
6705 setShape(x00, h00, z0, x01, h11, z1);
6706 tesselateBlockInWorld(tt, x, y, z);
6707 setShape(x10, h00, z0, x11, h11, z1);
6708 tesselateBlockInWorld(tt, x, y, z);
6709
6710 setShape(x00, h00, z1, x01, h01, z2);
6711 tesselateBlockInWorld(tt, x, y, z);
6712 setShape(x10, h00, z1, x11, h01, z2);
6713 tesselateBlockInWorld(tt, x, y, z);
6714
6715 setShape(x00, h10, z1, x01, h11, z2);
6716 tesselateBlockInWorld(tt, x, y, z);
6717 setShape(x10, h10, z1, x11, h11, z2);
6718 tesselateBlockInWorld(tt, x, y, z);
6719 }
6720 }
6721 else
6722 {
6723 if (direction == Direction::EAST || direction == Direction::WEST)
6724 {
6725 upFlip = FLIP_CW;
6726 float x0 = 7 / 16.0f;
6727 float x1 = 9 / 16.0f;
6728 float z0 = 6 / 16.0f;
6729 float z1 = 8 / 16.0f;
6730 setShape(x0, h00, z0, x1, h11, z1);
6731 tesselateBlockInWorld(tt, x, y, z);
6732 z0 = 8 / 16.0f;
6733 z1 = 10 / 16.0f;
6734 setShape(x0, h00, z0, x1, h11, z1);
6735 tesselateBlockInWorld(tt, x, y, z);
6736 z0 = 10 / 16.0f;
6737 z1 = 14 / 16.0f;
6738 setShape(x0, h00, z0, x1, h01, z1);
6739 tesselateBlockInWorld(tt, x, y, z);
6740 setShape(x0, h10, z0, x1, h11, z1);
6741 tesselateBlockInWorld(tt, x, y, z);
6742 z0 = 2 / 16.0f;
6743 z1 = 6 / 16.0f;
6744 setShape(x0, h00, z0, x1, h01, z1);
6745 tesselateBlockInWorld(tt, x, y, z);
6746 setShape(x0, h10, z0, x1, h11, z1);
6747 tesselateBlockInWorld(tt, x, y, z);
6748 }
6749 else
6750 {
6751 float x0 = 6 / 16.0f;
6752 float x1 = 8 / 16.0f;
6753 float z0 = 7 / 16.0f;
6754 float z1 = 9 / 16.0f;
6755 setShape(x0, h00, z0, x1, h11, z1);
6756 tesselateBlockInWorld(tt, x, y, z);
6757 x0 = 8 / 16.0f;
6758 x1 = 10 / 16.0f;
6759 setShape(x0, h00, z0, x1, h11, z1);
6760 tesselateBlockInWorld(tt, x, y, z);
6761 x0 = 10 / 16.0f;
6762 x1 = 14 / 16.0f;
6763 setShape(x0, h00, z0, x1, h01, z1);
6764 tesselateBlockInWorld(tt, x, y, z);
6765 setShape(x0, h10, z0, x1, h11, z1);
6766 tesselateBlockInWorld(tt, x, y, z);
6767 x0 = 2 / 16.0f;
6768 x1 = 6 / 16.0f;
6769 setShape(x0, h00, z0, x1, h01, z1);
6770 tesselateBlockInWorld(tt, x, y, z);
6771 setShape(x0, h10, z0, x1, h11, z1);
6772 tesselateBlockInWorld(tt, x, y, z);
6773
6774 }
6775 }
6776 noCulling = false;
6777 upFlip = FLIP_NONE;
6778
6779 setShape(0, 0, 0, 1, 1, 1);
6780
6781// LeaveCriticalSection( &Tile_SPU::m_csShape );
6782#endif // #ifdef DISABLE_TESS_FUNCS
6783
6784 return changed;
6785}
6786
6787bool TileRenderer_SPU::tesselateStairsInWorld( StairTile_SPU* tt, int x, int y, int z )
6788{
6789#ifdef DISABLE_TESS_FUNCS
6790 // EnterCriticalSection( &Tile_SPU::m_csShape );
6791 tt->setBaseShape(level, x, y, z);
6792 setShape(tt);
6793 tesselateBlockInWorld(tt, x, y, z);
6794
6795 bool checkInnerPiece = tt->setStepShape(level, x, y, z);
6796 setShape(tt);
6797 tesselateBlockInWorld(tt, x, y, z);
6798
6799 if (checkInnerPiece)
6800 {
6801 if (tt->setInnerPieceShape(level, x, y, z))
6802 {
6803 setShape(tt);
6804 tesselateBlockInWorld(tt, x, y, z);
6805 }
6806 }
6807// LeaveCriticalSection( &Tile_SPU::m_csShape );
6808#endif // #ifdef DISABLE_TESS_FUNCS
6809 return true;
6810}
6811
6812bool TileRenderer_SPU::tesselateDoorInWorld( Tile_SPU* tt, int x, int y, int z )
6813{
6814 Tesselator_SPU* t = getTesselator();
6815
6816 // skip rendering if the other half of the door is missing,
6817 // to avoid rendering doors that are about to be removed
6818 int data = level->getData(x, y, z);
6819 if ((data & DoorTile_SPU::UPPER_BIT) != 0)
6820 {
6821 if (level->getTile(x, y - 1, z) != tt->id)
6822 {
6823 return false;
6824 }
6825 }
6826 else {
6827 if (level->getTile(x, y + 1, z) != tt->id)
6828 {
6829 return false;
6830 }
6831 }
6832
6833 bool changed = false;
6834 float c10 = 0.5f;
6835 float c11 = 1;
6836 float c2 = 0.8f;
6837 float c3 = 0.6f;
6838
6839 int centerColor = 0;
6840 float centerBrightness = 0.0f;
6841
6842 if ( SharedConstants::TEXTURE_LIGHTING )
6843 {
6844 centerColor = tt->getLightColor( level, x, y, z );
6845 }
6846 else
6847 {
6848 centerBrightness = tt->getBrightness( level, x, y, z );
6849 }
6850
6851
6852 if ( SharedConstants::TEXTURE_LIGHTING )
6853 {
6854 t->tex2( tileShapeY0 > 0 ? centerColor : tt->getLightColor( level, x, y - 1, z ) );
6855 t->color( c10, c10, c10 );
6856 }
6857 else
6858 {
6859 float br = tt->getBrightness( level, x, y - 1, z );
6860 if ( tileShapeY0 > 0 ) br = centerBrightness;
6861 if (level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
6862 t->color( c10 * br, c10 * br, c10 * br );
6863 }
6864 renderFaceDown( tt, x, y, z, getTexture(tt, level, x, y, z, 0 ) );
6865 changed = true;
6866
6867 if ( SharedConstants::TEXTURE_LIGHTING )
6868 {
6869 t->tex2( tileShapeY1 < 1 ? centerColor : tt->getLightColor( level, x, y + 1, z ) );
6870 t->color( c11, c11, c11 );
6871 }
6872 else
6873 {
6874 float br = tt->getBrightness( level, x, y + 1, z );
6875 if ( tileShapeY1 < 1 ) br = centerBrightness;
6876 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
6877 t->color( c11 * br, c11 * br, c11 * br );
6878 }
6879 renderFaceUp( tt, x, y, z, getTexture(tt, level, x, y, z, 1 ) );
6880 changed = true;
6881
6882 {
6883 if ( SharedConstants::TEXTURE_LIGHTING )
6884 {
6885 t->tex2( tileShapeZ0 > 0 ? centerColor : tt->getLightColor( level, x, y, z - 1 ) );
6886 t->color( c2, c2, c2 );
6887 }
6888 else
6889 {
6890 float br = tt->getBrightness( level, x, y, z - 1 );
6891 if ( tileShapeZ0 > 0 ) br = centerBrightness;
6892 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
6893 t->color( c2 * br, c2 * br, c2 * br );
6894 }
6895 Icon_SPU *tex = getTexture(tt, level, x, y, z, 2 );
6896 renderNorth( tt, x, y, z, tex );
6897 changed = true;
6898 xFlipTexture = false;
6899 }
6900 {
6901 if ( SharedConstants::TEXTURE_LIGHTING )
6902 {
6903 t->tex2( tileShapeZ1 < 1 ? centerColor : tt->getLightColor( level, x, y, z + 1 ) );
6904 t->color( c2, c2, c2 );
6905 }
6906 else
6907 {
6908 float br = tt->getBrightness( level, x, y, z + 1 );
6909 if ( tileShapeZ1 < 1 ) br = centerBrightness;
6910 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
6911 t->color( c2 * br, c2 * br, c2 * br );
6912 }
6913 Icon_SPU *tex = getTexture( tt, level, x, y, z, 3 );
6914 renderSouth( tt, x, y, z, tex );
6915 changed = true;
6916 xFlipTexture = false;
6917 }
6918 {
6919 if ( SharedConstants::TEXTURE_LIGHTING )
6920 {
6921 t->tex2( tileShapeX0 > 0 ? centerColor : tt->getLightColor( level, x - 1, y, z ) );
6922 t->color( c3, c3, c3 );
6923 }
6924 else
6925 {
6926 float br = tt->getBrightness( level, x - 1, y, z );
6927 if ( tileShapeX0 > 0 ) br = centerBrightness;
6928 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
6929 t->color( c3 * br, c3 * br, c3 * br );
6930 }
6931 Icon_SPU *tex = getTexture(tt, level, x, y, z, 4 );
6932 renderWest( tt, x, y, z, tex );
6933 changed = true;
6934 xFlipTexture = false;
6935 }
6936 {
6937 if ( SharedConstants::TEXTURE_LIGHTING )
6938 {
6939 t->tex2( tileShapeX1 < 1 ? centerColor : tt->getLightColor( level, x + 1, y, z ) );
6940 t->color( c3, c3, c3 );
6941 }
6942 else
6943 {
6944 float br = tt->getBrightness( level, x + 1, y, z );
6945 if ( tileShapeX1 < 1 ) br = centerBrightness;
6946 if ( level->m_tileData.lightEmission[tt->id] > 0 ) br = 1.0f;
6947 t->color( c3 * br, c3 * br, c3 * br );
6948 }
6949 Icon_SPU *tex = getTexture(tt, level, x, y, z, 5 );
6950 renderEast( tt, x, y, z, tex );
6951 changed = true;
6952 xFlipTexture = false;
6953 }
6954 return changed;
6955}
6956
6957void TileRenderer_SPU::renderFaceDown( Tile_SPU* tt, float x, float y, float z, Icon_SPU *tex )
6958{
6959 Tesselator_SPU* t = getTesselator();
6960
6961 if (hasFixedTexture()) tex = fixedTexture;
6962 float u00 = tex->getU(tileShapeX0 * 16.0f);
6963 float u11 = tex->getU(tileShapeX1 * 16.0f);
6964 float v00 = tex->getV(tileShapeZ0 * 16.0f);
6965 float v11 = tex->getV(tileShapeZ1 * 16.0f);
6966
6967 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
6968 {
6969 u00 = tex->getU0();
6970 u11 = tex->getU1();
6971 }
6972 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
6973 {
6974 v00 = tex->getV0();
6975 v11 = tex->getV1();
6976 }
6977
6978 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
6979 if ( downFlip == FLIP_CCW )
6980 {
6981 u00 = tex->getU(tileShapeZ0 * 16.0f);
6982 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
6983 u11 = tex->getU(tileShapeZ1 * 16.0f);
6984 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
6985
6986 u01 = u11;
6987 u10 = u00;
6988 v01 = v00;
6989 v10 = v11;
6990 u01 = u00;
6991 u10 = u11;
6992 v00 = v11;
6993 v11 = v01;
6994 }
6995 else if ( downFlip == FLIP_CW )
6996 {
6997 // reshape
6998 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
6999 v00 = tex->getV(tileShapeX0 * 16.0f);
7000 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7001 v11 = tex->getV(tileShapeX1 * 16.0f);
7002
7003 // rotate
7004 u01 = u11;
7005 u10 = u00;
7006 v01 = v00;
7007 v10 = v11;
7008 u00 = u01;
7009 u11 = u10;
7010 v01 = v11;
7011 v10 = v00;
7012 }
7013 else if ( downFlip == FLIP_180 )
7014 {
7015 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7016 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7017 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7018 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7019
7020 u01 = u11;
7021 u10 = u00;
7022 v01 = v00;
7023 v10 = v11;
7024 }
7025
7026 float x0 = x + tileShapeX0;
7027 float x1 = x + tileShapeX1;
7028 float y0 = y + tileShapeY0;
7029 float z0 = z + tileShapeZ0;
7030 float z1 = z + tileShapeZ1;
7031
7032 if ( applyAmbienceOcclusion )
7033 {
7034 t->color( c1r, c1g, c1b );
7035 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7036 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7037 t->color( c2r, c2g, c2b );
7038 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7039 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7040 t->color( c3r, c3g, c3b );
7041 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7042 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7043 t->color( c4r, c4g, c4b );
7044 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7045 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7046 }
7047 else
7048 {
7049 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7050 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7051 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7052 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7053 }
7054}
7055
7056void TileRenderer_SPU::renderFaceUp( Tile_SPU* tt, float x, float y, float z, Icon_SPU *tex )
7057{
7058 Tesselator_SPU* t = getTesselator();
7059
7060 if (hasFixedTexture()) tex = fixedTexture;
7061 float u00 = tex->getU(tileShapeX0 * 16.0f);
7062 float u11 = tex->getU(tileShapeX1 * 16.0f);
7063 float v00 = tex->getV(tileShapeZ0 * 16.0f);
7064 float v11 = tex->getV(tileShapeZ1 * 16.0f);
7065
7066 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7067 {
7068 u00 = tex->getU0();
7069 u11 = tex->getU1();
7070 }
7071 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7072 {
7073 v00 = tex->getV0();
7074 v11 = tex->getV1();
7075 }
7076
7077 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7078
7079 if ( upFlip == FLIP_CW )
7080 {
7081 u00 = tex->getU(tileShapeZ0 * 16.0f);
7082 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7083 u11 = tex->getU(tileShapeZ1 * 16.0f);
7084 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7085
7086 u01 = u11;
7087 u10 = u00;
7088 v01 = v00;
7089 v10 = v11;
7090 u01 = u00;
7091 u10 = u11;
7092 v00 = v11;
7093 v11 = v01;
7094 }
7095 else if ( upFlip == FLIP_CCW )
7096 {
7097 // reshape
7098 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7099 v00 = tex->getV(tileShapeX0 * 16.0f);
7100 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7101 v11 = tex->getV(tileShapeX1 * 16.0f);
7102
7103 // rotate
7104 u01 = u11;
7105 u10 = u00;
7106 v01 = v00;
7107 v10 = v11;
7108 u00 = u01;
7109 u11 = u10;
7110 v01 = v11;
7111 v10 = v00;
7112 }
7113 else if ( upFlip == FLIP_180 )
7114 {
7115 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7116 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7117 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7118 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7119
7120 u01 = u11;
7121 u10 = u00;
7122 v01 = v00;
7123 v10 = v11;
7124 }
7125
7126
7127 float x0 = x + tileShapeX0;
7128 float x1 = x + tileShapeX1;
7129 float y1 = y + tileShapeY1;
7130 float z0 = z + tileShapeZ0;
7131 float z1 = z + tileShapeZ1;
7132
7133 if ( applyAmbienceOcclusion )
7134 {
7135 t->color( c1r, c1g, c1b );
7136 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7137 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7138 t->color( c2r, c2g, c2b );
7139 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7140 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7141 t->color( c3r, c3g, c3b );
7142 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7143 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7144 t->color( c4r, c4g, c4b );
7145 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7146 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7147 }
7148 else
7149 {
7150 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7151 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7152 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7153 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7154 }
7155
7156}
7157
7158void TileRenderer_SPU::renderNorth( Tile_SPU* tt, float x, float y, float z, Icon_SPU *tex )
7159{
7160 Tesselator_SPU* t = getTesselator();
7161
7162 if (hasFixedTexture()) tex = fixedTexture;
7163 float u00 = tex->getU(tileShapeX0 * 16.0f);
7164 float u11 = tex->getU(tileShapeX1 * 16.0f);
7165 float v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7166 float v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7167 if ( xFlipTexture )
7168 {
7169 float tmp = u00;
7170 u00 = u11;
7171 u11 = tmp;
7172 }
7173
7174 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7175 {
7176 u00 = tex->getU0();
7177 u11 = tex->getU1();
7178 }
7179 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7180 {
7181 v00 = tex->getV0();
7182 v11 = tex->getV1();
7183 }
7184
7185 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7186
7187 if ( northFlip == FLIP_CCW )
7188 {
7189 u00 = tex->getU(tileShapeY0 * 16.0f);
7190 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7191 u11 = tex->getU(tileShapeY1 * 16.0f);
7192 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7193
7194 u01 = u11;
7195 u10 = u00;
7196 v01 = v00;
7197 v10 = v11;
7198 u01 = u00;
7199 u10 = u11;
7200 v00 = v11;
7201 v11 = v01;
7202 }
7203 else if ( northFlip == FLIP_CW )
7204 {
7205 // reshape
7206 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7207 v00 = tex->getV(tileShapeX1 * 16.0f);
7208 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7209 v11 = tex->getV(tileShapeX0 * 16.0f);
7210
7211 // rotate
7212 u01 = u11;
7213 u10 = u00;
7214 v01 = v00;
7215 v10 = v11;
7216 u00 = u01;
7217 u11 = u10;
7218 v01 = v11;
7219 v10 = v00;
7220 }
7221 else if ( northFlip == FLIP_180 )
7222 {
7223 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7224 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7225 v00 = tex->getV(tileShapeY1 * 16.0f);
7226 v11 = tex->getV(tileShapeY0 * 16.0f);
7227
7228 u01 = u11;
7229 u10 = u00;
7230 v01 = v00;
7231 v10 = v11;
7232 }
7233
7234
7235 float x0 = x + tileShapeX0;
7236 float x1 = x + tileShapeX1;
7237 float y0 = y + tileShapeY0;
7238 float y1 = y + tileShapeY1;
7239 float z0 = z + tileShapeZ0;
7240
7241 if ( applyAmbienceOcclusion )
7242 {
7243 t->color( c1r, c1g, c1b );
7244 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7245 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7246 t->color( c2r, c2g, c2b );
7247 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7248 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7249 t->color( c3r, c3g, c3b );
7250 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7251 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7252 t->color( c4r, c4g, c4b );
7253 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7254 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7255 }
7256 else
7257 {
7258 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7259 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7260 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7261 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7262 }
7263
7264}
7265
7266void TileRenderer_SPU::renderSouth( Tile_SPU* tt, float x, float y, float z, Icon_SPU *tex )
7267{
7268 Tesselator_SPU* t = getTesselator();
7269
7270 if (hasFixedTexture()) tex = fixedTexture;
7271 float u00 = tex->getU(tileShapeX0 * 16.0f);
7272 float u11 = tex->getU(tileShapeX1 * 16.0f);
7273 float v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7274 float v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7275 if ( xFlipTexture )
7276 {
7277 float tmp = u00;
7278 u00 = u11;
7279 u11 = tmp;
7280 }
7281
7282 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7283 {
7284 u00 = tex->getU0();
7285 u11 = tex->getU1();
7286 }
7287 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7288 {
7289 v00 = tex->getV0();
7290 v11 = tex->getV1();
7291 }
7292
7293 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7294
7295 if ( southFlip == FLIP_CW )
7296 {
7297 u00 = tex->getU(tileShapeY0 * 16.0f);
7298 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7299 u11 = tex->getU(tileShapeY1 * 16.0f);
7300 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7301
7302 u01 = u11;
7303 u10 = u00;
7304 v01 = v00;
7305 v10 = v11;
7306 u01 = u00;
7307 u10 = u11;
7308 v00 = v11;
7309 v11 = v01;
7310 }
7311 else if ( southFlip == FLIP_CCW )
7312 {
7313 // reshape
7314 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7315 v00 = tex->getV(tileShapeX0 * 16.0f);
7316 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7317 v11 = tex->getV(tileShapeX1 * 16.0f);
7318
7319 // rotate
7320 u01 = u11;
7321 u10 = u00;
7322 v01 = v00;
7323 v10 = v11;
7324 u00 = u01;
7325 u11 = u10;
7326 v01 = v11;
7327 v10 = v00;
7328 }
7329 else if ( southFlip == FLIP_180 )
7330 {
7331 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f);
7332 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f);
7333 v00 = tex->getV(tileShapeY1 * 16.0f);
7334 v11 = tex->getV(tileShapeY0 * 16.0f);
7335
7336 u01 = u11;
7337 u10 = u00;
7338 v01 = v00;
7339 v10 = v11;
7340 }
7341
7342
7343 float x0 = x + tileShapeX0;
7344 float x1 = x + tileShapeX1;
7345 float y0 = y + tileShapeY0;
7346 float y1 = y + tileShapeY1;
7347 float z1 = z + tileShapeZ1;
7348
7349 if ( applyAmbienceOcclusion )
7350 {
7351 t->color( c1r, c1g, c1b );
7352 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7353 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7354 t->color( c2r, c2g, c2b );
7355 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7356 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7357 t->color( c3r, c3g, c3b );
7358 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7359 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7360 t->color( c4r, c4g, c4b );
7361 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7362 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7363 }
7364 else
7365 {
7366 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7367 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7368 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7369 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7370 }
7371
7372}
7373
7374void TileRenderer_SPU::renderWest( Tile_SPU* tt, float x, float y, float z, Icon_SPU *tex )
7375{
7376 Tesselator_SPU* t = getTesselator();
7377
7378 if (hasFixedTexture()) tex = fixedTexture;
7379 float u00 = tex->getU(tileShapeZ0 * 16.0f);
7380 float u11 = tex->getU(tileShapeZ1 * 16.0f);
7381 float v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7382 float v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7383 if ( xFlipTexture )
7384 {
7385 float tmp = u00;
7386 u00 = u11;
7387 u11 = tmp;
7388 }
7389
7390 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7391 {
7392 u00 = tex->getU0();
7393 u11 = tex->getU1();
7394 }
7395 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7396 {
7397 v00 = tex->getV0();
7398 v11 = tex->getV1();
7399 }
7400
7401 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7402
7403 if ( westFlip == FLIP_CW )
7404 {
7405 u00 = tex->getU(tileShapeY0 * 16.0f);
7406 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7407 u11 = tex->getU(tileShapeY1 * 16.0f);
7408 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7409
7410 u01 = u11;
7411 u10 = u00;
7412 v01 = v00;
7413 v10 = v11;
7414 u01 = u00;
7415 u10 = u11;
7416 v00 = v11;
7417 v11 = v01;
7418 }
7419 else if ( westFlip == FLIP_CCW )
7420 {
7421 // reshape
7422 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7423 v00 = tex->getV(tileShapeZ0 * 16.0f);
7424 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7425 v11 = tex->getV(tileShapeZ1 * 16.0f);
7426
7427 // rotate
7428 u01 = u11;
7429 u10 = u00;
7430 v01 = v00;
7431 v10 = v11;
7432 u00 = u01;
7433 u11 = u10;
7434 v01 = v11;
7435 v10 = v00;
7436 }
7437 else if ( westFlip == FLIP_180 )
7438 {
7439 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7440 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7441 v00 = tex->getV(tileShapeY1 * 16.0f);
7442 v11 = tex->getV(tileShapeY0 * 16.0f);
7443
7444
7445 u01 = u11;
7446 u10 = u00;
7447 v01 = v00;
7448 v10 = v11;
7449 }
7450
7451 float x0 = x + tileShapeX0;
7452 float y0 = y + tileShapeY0;
7453 float y1 = y + tileShapeY1;
7454 float z0 = z + tileShapeZ0;
7455 float z1 = z + tileShapeZ1;
7456
7457 if ( applyAmbienceOcclusion )
7458 {
7459 t->color( c1r, c1g, c1b );
7460 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7461 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7462 t->color( c2r, c2g, c2b );
7463 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7464 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7465 t->color( c3r, c3g, c3b );
7466 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7467 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7468 t->color( c4r, c4g, c4b );
7469 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7470 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7471 }
7472 else
7473 {
7474 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7475 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7476 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7477 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7478 }
7479
7480}
7481
7482void TileRenderer_SPU::renderEast( Tile_SPU* tt, float x, float y, float z, Icon_SPU *tex )
7483{
7484 Tesselator_SPU* t = getTesselator();
7485
7486 if (hasFixedTexture()) tex = fixedTexture;
7487 float u00 = tex->getU(tileShapeZ0 * 16.0f);
7488 float u11 = tex->getU(tileShapeZ1 * 16.0f);
7489 float v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7490 float v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7491 if ( xFlipTexture )
7492 {
7493 float tmp = u00;
7494 u00 = u11;
7495 u11 = tmp;
7496 }
7497
7498 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7499 {
7500 u00 = tex->getU0();
7501 u11 = tex->getU1();
7502 }
7503 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7504 {
7505 v00 = tex->getV0();
7506 v11 = tex->getV1();
7507 }
7508
7509 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7510
7511 if ( eastFlip == FLIP_CCW )
7512 {
7513 u00 = tex->getU(tileShapeY0 * 16.0f);
7514 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7515 u11 = tex->getU(tileShapeY1 * 16.0f);
7516 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7517
7518 u01 = u11;
7519 u10 = u00;
7520 v01 = v00;
7521 v10 = v11;
7522 u01 = u00;
7523 u10 = u11;
7524 v00 = v11;
7525 v11 = v01;
7526 }
7527 else if ( eastFlip == FLIP_CW )
7528 {
7529 // reshape
7530 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f);
7531 v00 = tex->getV(tileShapeZ1 * 16.0f);
7532 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f);
7533 v11 = tex->getV(tileShapeZ0 * 16.0f);
7534
7535 // rotate
7536 u01 = u11;
7537 u10 = u00;
7538 v01 = v00;
7539 v10 = v11;
7540 u00 = u01;
7541 u11 = u10;
7542 v01 = v11;
7543 v10 = v00;
7544 }
7545 else if ( eastFlip == FLIP_180 )
7546 {
7547 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f);
7548 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f);
7549 v00 = tex->getV(tileShapeY1 * 16.0f);
7550 v11 = tex->getV(tileShapeY0 * 16.0f);
7551
7552 u01 = u11;
7553 u10 = u00;
7554 v01 = v00;
7555 v10 = v11;
7556 }
7557
7558 float x1 = x + tileShapeX1;
7559 float y0 = y + tileShapeY0;
7560 float y1 = y + tileShapeY1;
7561 float z0 = z + tileShapeZ0;
7562 float z1 = z + tileShapeZ1;
7563
7564 if ( applyAmbienceOcclusion )
7565 {
7566 t->color( c1r, c1g, c1b );
7567 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7568 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7569 t->color( c2r, c2g, c2b );
7570 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7571 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7572 t->color( c3r, c3g, c3b );
7573 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7574 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7575 t->color( c4r, c4g, c4b );
7576 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7577 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7578 }
7579 else
7580 {
7581 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7582 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7583 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7584 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7585 }
7586
7587}
7588
7589bool TileRenderer_SPU::canRender( int renderShape )
7590{
7591 if ( renderShape == Tile_SPU::SHAPE_BLOCK ) return true;
7592 if ( renderShape == Tile_SPU::SHAPE_TREE ) return true;
7593 if ( renderShape == Tile_SPU::SHAPE_QUARTZ) return true;
7594 if ( renderShape == Tile_SPU::SHAPE_CACTUS ) return true;
7595 if ( renderShape == Tile_SPU::SHAPE_STAIRS ) return true;
7596 if ( renderShape == Tile_SPU::SHAPE_FENCE ) return true;
7597 if ( renderShape == Tile_SPU::SHAPE_EGG) return true;
7598 if ( renderShape == Tile_SPU::SHAPE_ENTITYTILE_ANIMATED) return true;
7599 if ( renderShape == Tile_SPU::SHAPE_FENCE_GATE) return true;
7600 if ( renderShape == Tile_SPU::SHAPE_PISTON_BASE ) return true;
7601 if ( renderShape == Tile_SPU::SHAPE_PORTAL_FRAME ) return true;
7602 if ( renderShape == Tile_SPU::SHAPE_WALL) return true;
7603 if ( renderShape == Tile_SPU::SHAPE_ANVIL) return true;
7604 return false;
7605}
7606
7607Icon_SPU *TileRenderer_SPU::getTexture(Tile_SPU *tile, ChunkRebuildData *level, int x, int y, int z, int face)
7608{
7609 return getTextureOrMissing(tile->getTexture(level, x, y, z, face));
7610}
7611
7612Icon_SPU *TileRenderer_SPU::getTexture(Tile_SPU *tile, int face, int data)
7613{
7614 return getTextureOrMissing(tile->getTexture(face, data));
7615}
7616
7617Icon_SPU *TileRenderer_SPU::getTexture(Tile_SPU *tile, int face)
7618{
7619 return getTextureOrMissing(tile->getTexture(face));
7620}
7621
7622Icon_SPU *TileRenderer_SPU::getTexture(Tile_SPU *tile)
7623{
7624 return getTextureOrMissing(tile->getTexture(Facing::UP));
7625}
7626
7627Icon_SPU *TileRenderer_SPU::getTextureOrMissing(Icon_SPU *Icon_SPU)
7628{
7629 if (Icon_SPU == NULL)
7630 {
7631 assert(0);
7632 // return minecraft->textures->getMissingIcon_SPU(Icon_SPU::TYPE_TERRAIN);
7633 }
7634 return Icon_SPU;
7635}