1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Dispose of monitor display lists when unloading worlds

This means all display lists are correctly deleted when changing
dimensions/exiting to main menu.
This commit is contained in:
SquidDev 2018-02-24 20:37:14 +00:00
parent 0cec4aee8c
commit 7bb8efed1d
6 changed files with 64 additions and 30 deletions

View File

@ -505,11 +505,6 @@ public class ComputerCraft
return proxy.getRenderFrame();
}
public static void deleteDisplayLists( int list, int range )
{
proxy.deleteDisplayLists( list, range );
}
public static Object getFixedWidthFontRenderer()
{
return proxy.getFixedWidthFontRenderer();

View File

@ -25,6 +25,7 @@ import dan200.computercraft.shared.media.items.ItemPrintout;
import dan200.computercraft.shared.network.ComputerCraftPacket;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.modem.TileCable;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
@ -35,7 +36,6 @@ import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@ -57,6 +57,7 @@ import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@ -297,12 +298,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
return m_renderFrame;
}
@Override
public void deleteDisplayLists( int list, int range )
{
GlStateManager.glDeleteLists( list, range );
}
@Override
public Object getFixedWidthFontRenderer()
{
@ -552,6 +547,15 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
m_renderFrame++;
}
}
@SubscribeEvent
public void onWorldUnload( WorldEvent.Unload event )
{
if( event.getWorld().isRemote )
{
ClientMonitor.destroyAll();
}
}
}
@SideOnly(Side.CLIENT)

View File

@ -108,13 +108,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
// Allocate display lists
if( originTerminal.renderDisplayLists == null )
{
originTerminal.renderDisplayLists = new int[3];
for( int list = 0; list < originTerminal.renderDisplayLists.length; list++ )
{
originTerminal.renderDisplayLists[list] = GlStateManager.glGenLists( 1 );
}
originTerminal.createLists();
redraw = true;
}

View File

@ -1,12 +1,15 @@
package dan200.computercraft.shared.peripheral.monitor;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.common.ClientTerminal;
import gnu.trove.set.hash.TIntHashSet;
import net.minecraft.client.renderer.GlStateManager;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class ClientMonitor extends ClientTerminal
{
private static final TIntHashSet displayLists = new TIntHashSet();
private static final Set<ClientMonitor> allMonitors = new HashSet<>();
private final TileMonitor origin;
@ -24,16 +27,60 @@ public class ClientMonitor extends ClientTerminal
return origin;
}
public void createLists()
{
if( renderDisplayLists == null )
{
renderDisplayLists = new int[3];
for( int i = 0; i < renderDisplayLists.length; i++ )
{
renderDisplayLists[i] = GlStateManager.glGenLists( 1 );
}
synchronized( allMonitors )
{
allMonitors.add( this );
}
}
}
public void destroy()
{
if( renderDisplayLists != null )
{
for( int displayList : renderDisplayLists )
synchronized( allMonitors )
{
ComputerCraft.deleteDisplayLists( displayList, 1 );
allMonitors.remove( this );
}
for( int list : renderDisplayLists )
{
GlStateManager.glDeleteLists( list, 1 );
}
renderDisplayLists = null;
}
}
public static void destroyAll()
{
synchronized( allMonitors )
{
for( Iterator<ClientMonitor> iterator = allMonitors.iterator(); iterator.hasNext(); )
{
ClientMonitor monitor = iterator.next();
if( monitor.renderDisplayLists != null )
{
for( int list : monitor.renderDisplayLists )
{
GlStateManager.glDeleteLists( list, 1 );
}
monitor.renderDisplayLists = null;
}
iterator.remove();
}
}
}
}

View File

@ -124,11 +124,6 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
@Override
public abstract long getRenderFrame();
@Override
public void deleteDisplayLists( int list, int range )
{
}
@Override
public abstract Object getFixedWidthFontRenderer();

View File

@ -32,7 +32,6 @@ public interface IComputerCraftProxy
boolean getGlobalCursorBlink();
long getRenderFrame();
void deleteDisplayLists( int list, int range );
Object getFixedWidthFontRenderer();
String getRecordInfo( @Nonnull ItemStack item );