2929import java .util .List ;
3030
3131@ SideOnly (Side .CLIENT )
32- public final class SpoceRenderingHandler {
32+ public class SpoceRenderingHandler {
3333
34- public static final SpoceRenderingHandler INSTANCE = new SpoceRenderingHandler ();
35- private static final float [] EMPTY_VERTS = new float [0 ];
34+ protected static final float [] EMPTY_VERTS = new float [0 ];
3635 private static final int BUILD_BUF_SIZE = 1 << 17 ;
3736 private static final int RESCAN_INTERVAL = 3 ;
37+ public static SpoceRenderingHandler INSTANCE ;
3838 private final float [] buildBuf = new float [BUILD_BUF_SIZE ];
3939 private final double [] angleScratch = new double [9 ];
40- private TileEntity te ;
41- private float linkScope ;
42- private float energyScope ;
43- private float chargingScope ;
40+ protected TileEntity te ;
41+ protected float linkScope ;
42+ protected float energyScope ;
43+ protected float chargingScope ;
44+ protected int currentIntersectionSlot = -1 ;
45+ protected float currentIntersectionRadius = 0 ;
46+ private int buildCount ;
4447 private float lastAnimProgress ;
4548 private float animProgress ;
4649 private float [] rs ;
47- private int buildCount ;
4850 private float [] linkVerts = EMPTY_VERTS ;
4951 private float [] energyVerts = EMPTY_VERTS ;
5052 private float [] chargingVerts = EMPTY_VERTS ;
5153 private boolean linkDirty = false ;
5254 private boolean energyDirty = false ;
5355 private boolean chargingDirty = false ;
5456 private int tickCounter = 0 ;
57+ private boolean glInitialized = false ;
5558
5659 private static float bright (float v ) {
5760 return Math .min (1.0f , v * 1.3f );
@@ -61,7 +64,42 @@ private static float easeOutCubic(float t) {
6164 return (float ) (1.0 - Math .pow (1.0 - t , 3 ));
6265 }
6366
64- private static void drawCachedIntersection (float [] verts , float r , float g , float b ) {
67+ private static int addCos (double [] buf , int count , double val ) {
68+ if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9 ) return count ;
69+ val = val < -1.0 ? -1.0 : Math .min (val , 1.0 );
70+ double a = Math .acos (val );
71+ buf [count ++] = normalizeAngle (a );
72+ buf [count ++] = normalizeAngle (-a );
73+ return count ;
74+ }
75+
76+ private static int addSin (double [] buf , int count , double val ) {
77+ if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9 ) return count ;
78+ val = val < -1.0 ? -1.0 : Math .min (val , 1.0 );
79+ double a = Math .asin (val );
80+ buf [count ++] = normalizeAngle (a );
81+ buf [count ++] = normalizeAngle (Math .PI - a );
82+ return count ;
83+ }
84+
85+ private static double normalizeAngle (double a ) {
86+ a %= Math .PI * 2.0 ;
87+ return a < 0 ? a + Math .PI * 2.0 : a ;
88+ }
89+
90+ private static void sortAngles (double [] buf , int count ) {
91+ for (int i = 1 ; i < count ; i ++) {
92+ double key = buf [i ];
93+ int j = i - 1 ;
94+ while (j >= 0 && buf [j ] > key ) {
95+ buf [j + 1 ] = buf [j ];
96+ j --;
97+ }
98+ buf [j + 1 ] = key ;
99+ }
100+ }
101+
102+ protected void drawCachedIntersection (float [] verts , float r , float g , float b ) {
65103 if (verts .length == 0 ) return ;
66104 GlStateManager .color (r , g , b , 1.0f );
67105 GlStateManager .glLineWidth (4.0f );
@@ -74,7 +112,7 @@ private static void drawCachedIntersection(float[] verts, float r, float g, floa
74112 tess .draw ();
75113 }
76114
77- private static void draw (float rotation , float r , float g , float b , float radius , float r1 , float g1 , float b1 ) {
115+ private void draw (float rotation , float r , float g , float b , float radius , float r1 , float g1 , float b1 ) {
78116 GlStateManager .pushMatrix ();
79117 drawSphere (r , g , b , radius , 0.2f );
80118 GlStateManager .rotate (rotation , 0.0F , 1.0F , 0.0F );
@@ -83,7 +121,7 @@ private static void draw(float rotation, float r, float g, float b, float radius
83121 GlStateManager .popMatrix ();
84122 }
85123
86- private static void drawSphere (float r , float g , float b , float radius , float alpha ) {
124+ protected void drawSphere (float r , float g , float b , float radius , float alpha ) {
87125 GlStateManager .color (r , g , b , alpha );
88126 Tessellator tess = Tessellator .getInstance ();
89127 BufferBuilder buf = tess .getBuffer ();
@@ -107,7 +145,7 @@ private static void drawSphere(float r, float g, float b, float radius, float al
107145 }
108146 }
109147
110- private static void drawBuckyBallWireframe (float r , float g , float b , float radius , float alpha ) {
148+ protected void drawBuckyBallWireframe (float r , float g , float b , float radius , float alpha ) {
111149 GlStateManager .color (r , g , b , alpha );
112150 GlStateManager .glLineWidth (2.0f );
113151 Tessellator tess = Tessellator .getInstance ();
@@ -122,41 +160,6 @@ private static void drawBuckyBallWireframe(float r, float g, float b, float radi
122160 tess .draw ();
123161 }
124162
125- private static int addCos (double [] buf , int count , double val ) {
126- if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9 ) return count ;
127- val = val < -1.0 ? -1.0 : Math .min (val , 1.0 );
128- double a = Math .acos (val );
129- buf [count ++] = normalizeAngle (a );
130- buf [count ++] = normalizeAngle (-a );
131- return count ;
132- }
133-
134- private static int addSin (double [] buf , int count , double val ) {
135- if (val < -1.0 - 1E-9 || val > 1.0 + 1E-9 ) return count ;
136- val = val < -1.0 ? -1.0 : Math .min (val , 1.0 );
137- double a = Math .asin (val );
138- buf [count ++] = normalizeAngle (a );
139- buf [count ++] = normalizeAngle (Math .PI - a );
140- return count ;
141- }
142-
143- private static double normalizeAngle (double a ) {
144- a %= Math .PI * 2.0 ;
145- return a < 0 ? a + Math .PI * 2.0 : a ;
146- }
147-
148- private static void sortAngles (double [] buf , int count ) {
149- for (int i = 1 ; i < count ; i ++) {
150- double key = buf [i ];
151- int j = i - 1 ;
152- while (j >= 0 && buf [j ] > key ) {
153- buf [j + 1 ] = buf [j ];
154- j --;
155- }
156- buf [j + 1 ] = key ;
157- }
158- }
159-
160163 public void setStaus (TileEntity te , double linkScope , double energyScope , double chargingScope ) {
161164 this .te = te ;
162165 this .linkScope = (float ) linkScope ;
@@ -198,13 +201,13 @@ public void onClientTick(TickEvent.ClientTickEvent event) {
198201 }
199202 }
200203
201- private void drawIntersectionImmediate (World world , float radius , float r , float g , float b ) {
204+ protected void drawIntersectionImmediate (World world , float radius , float r , float g , float b ) {
202205 if (radius <= 0.1f ) return ;
203206 float [] verts = buildIntersectionGeometry (world , radius );
204207 drawCachedIntersection (verts , r , g , b );
205208 }
206209
207- private float [] buildIntersectionGeometry (World world , double radius ) {
210+ protected float [] buildIntersectionGeometry (World world , double radius ) {
208211 buildCount = 0 ;
209212 int radInt = (int ) Math .ceil (radius );
210213 double inner = Math .max (0.0 , radius - 1.0 );
@@ -397,6 +400,8 @@ private void appendAABBFace(EnumFacing face, AxisAlignedBB box, double R) {
397400 }
398401
399402 public void clear () {
403+ cleanupGL ();
404+ glInitialized = false ;
400405 te = null ;
401406 linkScope = energyScope = chargingScope = 0 ;
402407 animProgress = lastAnimProgress = 0 ;
@@ -448,12 +453,19 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
448453 GlStateManager .disableCull ();
449454 GlStateManager .depthMask (false );
450455
456+ if (!glInitialized ) {
457+ initGL ();
458+ glInitialized = true ;
459+ }
460+
451461 float time = world .getTotalWorldTime () + partial ;
452462 float rotation = time * 0.8f ;
453463
454464 if (linkScope > 0 ) {
455465 final float radius = linkScope * interpFactor ;
456466 final float wr = 0.4f , wg = 0.8f , wb = 1.0f ;
467+ currentIntersectionSlot = 0 ;
468+ currentIntersectionRadius = radius ;
457469 GlStateManager .blendFunc (GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE_MINUS_SRC_ALPHA );
458470 draw (rotation * rs [0 ], 0 , 0.4f , 0.8f , radius , wr , wg , wb );
459471 GlStateManager .blendFunc (GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE );
@@ -471,6 +483,8 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
471483 if (energyScope > 0 ) {
472484 final float radius = energyScope * interpFactor ;
473485 final float wr = 0.8f , wg = 0.6f , wb = 1.0f ;
486+ currentIntersectionSlot = 1 ;
487+ currentIntersectionRadius = radius ;
474488 GlStateManager .blendFunc (GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE_MINUS_SRC_ALPHA );
475489 draw (rotation * rs [1 ], 0.4f , 0.2f , 0.8f , radius , wr , wg , wb );
476490 GlStateManager .blendFunc (GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE );
@@ -488,6 +502,8 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
488502 if (chargingScope > 0 ) {
489503 final float radius = chargingScope * interpFactor ;
490504 final float wr = 0.4f , wg = 1.0f , wb = 0.4f ;
505+ currentIntersectionSlot = 2 ;
506+ currentIntersectionRadius = radius ;
491507 GlStateManager .blendFunc (GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE_MINUS_SRC_ALPHA );
492508 draw (rotation * rs [2 ], 0 , 0.5f , 0.1f , radius , wr , wg , wb );
493509 GlStateManager .blendFunc (GlStateManager .SourceFactor .SRC_ALPHA , GlStateManager .DestFactor .ONE );
@@ -509,4 +525,11 @@ public void onRenderWorldLast(RenderWorldLastEvent event) {
509525 GlStateManager .disableBlend ();
510526 GlStateManager .popMatrix ();
511527 }
512- }
528+
529+ protected void initGL () {
530+ }
531+
532+ protected void cleanupGL () {
533+ }
534+
535+ }
0 commit comments