mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-23 21:49:56 +00:00
Added ASMExtensionFactory, to be replaced by a mixin implementation with trait support to handle inner classes generated by scala
Renamed onNeighbourChanged to onNeighborChanged because mcp is american Added multipass to renderDynamic
This commit is contained in:
1 parent
c221e0bdcf
commit
1b97e22aba
10 files changed
+74
-55
No files matched your search
@@ -13,6 +13,7 @@ import scala.collection.mutable.ListBuffer
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import codechicken.multipart.asm.IMultipartFactory
|
||||
import codechicken.multipart.asm.ScalaCompilerFactory
|
||||
import codechicken.multipart.asm.ASMExtensionFactory
|
||||
|
||||
object MultipartGenerator
|
||||
{
|
||||
@@ -22,7 +23,7 @@ object MultipartGenerator
|
||||
private var partTraitMap_c:Map[Class[_], Seq[String]] = Map()
|
||||
private var partTraitMap_s:Map[Class[_], Seq[String]] = Map()
|
||||
|
||||
var factory:IMultipartFactory = ScalaCompilerFactory
|
||||
var factory:IMultipartFactory = ASMExtensionFactory
|
||||
|
||||
def partTraitMap(client:Boolean) = if(client) partTraitMap_c else partTraitMap_s
|
||||
|
||||
@@ -141,14 +142,20 @@ object MultipartGenerator
|
||||
if(interfaceTraitMap_c.contains(s_interface))
|
||||
System.err.println("Trait already registered for "+s_interface)
|
||||
else
|
||||
{
|
||||
interfaceTraitMap_c = interfaceTraitMap_c+(s_interface->c_trait)
|
||||
factory.registerTrait(s_interface, c_trait, true)
|
||||
}
|
||||
}
|
||||
if(s_trait != null)
|
||||
{
|
||||
if(interfaceTraitMap_s.contains(s_interface))
|
||||
System.err.println("Trait already registered for "+s_interface)
|
||||
else
|
||||
{
|
||||
interfaceTraitMap_s = interfaceTraitMap_s+(s_interface->s_trait)
|
||||
factory.registerTrait(s_interface, s_trait, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRend
|
||||
CCRenderState.useNormals(true)
|
||||
|
||||
val pos = new Vector3(x, y, z)
|
||||
tmpart.renderDynamic(pos, f)
|
||||
tmpart.renderDynamic(pos, f, pass)
|
||||
}
|
||||
|
||||
override def getRenderId = TileMultipartObj.renderID
|
||||
|
||||
@@ -58,7 +58,7 @@ abstract class TMultiPart
|
||||
@SideOnly(Side.CLIENT)
|
||||
def renderStatic(pos:Vector3, olm:LazyLightMatrix, pass:Int){}
|
||||
@SideOnly(Side.CLIENT)
|
||||
def renderDynamic(pos:Vector3, frame:Float){}
|
||||
def renderDynamic(pos:Vector3, frame:Float, pass:Int){}
|
||||
@SideOnly(Side.CLIENT)
|
||||
def drawBreaking(renderBlocks:RenderBlocks){}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.entity.Entity
|
||||
|
||||
trait TileMultipart extends TileEntity
|
||||
class TileMultipart extends TileEntity
|
||||
{
|
||||
var partList = ArrayBuffer[TMultiPart]()
|
||||
|
||||
@@ -186,6 +186,7 @@ trait TileMultipart extends TileEntity
|
||||
|
||||
addPart_do(part)
|
||||
part.onAdded()
|
||||
partAdded(part)
|
||||
notifyPartChange()
|
||||
markDirty()
|
||||
markRender()
|
||||
@@ -209,8 +210,6 @@ trait TileMultipart extends TileEntity
|
||||
|
||||
if(!doesTick && part.doesTick)
|
||||
setTicking(true)
|
||||
|
||||
partAdded(part)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,19 +348,25 @@ trait TileMultipart extends TileEntity
|
||||
}
|
||||
}
|
||||
|
||||
trait TileMultipartClient extends TileMultipart
|
||||
class TileMultipartClient extends TileMultipart
|
||||
{
|
||||
def renderStatic(pos:Vector3, olm:LazyLightMatrix, pass:Int)
|
||||
{
|
||||
partList.foreach(part => part.renderStatic(pos, olm, pass))
|
||||
}
|
||||
|
||||
def renderDynamic(pos:Vector3, frame:Float)
|
||||
def renderDynamic(pos:Vector3, frame:Float, pass:Int)
|
||||
{
|
||||
partList.foreach(part => part.renderDynamic(pos, frame))
|
||||
partList.foreach(part => part.renderDynamic(pos, frame, pass:Int))
|
||||
}
|
||||
|
||||
def randomDisplayTick(random:Random){}
|
||||
|
||||
override def shouldRenderInPass(pass:Int) =
|
||||
{
|
||||
MultipartRenderer.pass = pass
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
object TileMultipartObj
|
||||
|
||||
@@ -5,6 +5,8 @@ import codechicken.multipart.TileMultipart
|
||||
|
||||
trait IMultipartFactory
|
||||
{
|
||||
def registerTrait(s_interface:String, s_trait:String, client:Boolean)
|
||||
|
||||
def generatePassThroughTrait(s_interface:String):String
|
||||
|
||||
def generateTile(types:Seq[String], client:Boolean):TileMultipart
|
||||
|
||||
@@ -57,8 +57,8 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
|
||||
private var ugenid = 0
|
||||
|
||||
var mirror = scala.reflect.runtime.currentMirror
|
||||
var tb = mirror.mkToolBox()
|
||||
val mirror = scala.reflect.runtime.currentMirror
|
||||
val tb = mirror.mkToolBox()
|
||||
private val definedTypes = MMap[String, TypeSymbol]()
|
||||
|
||||
def getType(obj:Any) = mirror.classSymbol(obj.getClass).toType
|
||||
@@ -114,7 +114,7 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
return sym
|
||||
}
|
||||
|
||||
abstract class Generator
|
||||
abstract class Constructor
|
||||
{
|
||||
def generate():TileMultipart
|
||||
}
|
||||
@@ -147,7 +147,7 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
return generatorMap.getOrElse(this, gen_sync).generate
|
||||
}
|
||||
|
||||
def gen_sync():Generator = tb.synchronized
|
||||
def gen_sync():Constructor = tb.synchronized
|
||||
{
|
||||
return generatorMap.getOrElse(this, {
|
||||
var gen = generator
|
||||
@@ -156,7 +156,7 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
})
|
||||
}
|
||||
|
||||
def generator():Generator =
|
||||
def generator():Constructor =
|
||||
{
|
||||
val startTime = System.currentTimeMillis
|
||||
val defClass =
|
||||
@@ -178,7 +178,7 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
normalClassDef(
|
||||
FINAL,
|
||||
uniqueName("TileMultipart_gen"),
|
||||
List(typeOf[Generator].typeSymbol.asType),
|
||||
List(typeOf[Constructor].typeSymbol.asType),
|
||||
List(//methods
|
||||
defaultConstructor,
|
||||
DefDef(
|
||||
@@ -202,46 +202,49 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
nme.CONSTRUCTOR
|
||||
)
|
||||
|
||||
val genInst = tb.eval(Block(defGenClass, constructGenClass)).asInstanceOf[Generator]
|
||||
val genInst = tb.eval(Block(defGenClass, constructGenClass)).asInstanceOf[Constructor]
|
||||
println("Generation ["+types.mkString(", ")+"] took: "+(System.currentTimeMillis-startTime))
|
||||
return genInst
|
||||
}
|
||||
}
|
||||
|
||||
private var generatorMap:Map[SuperSet, Generator] = Map()
|
||||
private var generatorMap:Map[SuperSet, Constructor] = Map()
|
||||
|
||||
SuperSet(Seq(), false).generate//default impl, boots generator
|
||||
if(FMLCommonHandler.instance.getEffectiveSide == Side.CLIENT)
|
||||
SuperSet(Seq(), true).generate
|
||||
|
||||
private def symbolToValDef(m:Symbol) =
|
||||
ValDef(Modifiers(PARAM), m.asTerm.name.decoded, Ident(m), EmptyTree)
|
||||
|
||||
private def passThroughMethod(tname:String, vname:String, m:MethodSymbol):Tree =
|
||||
DefDef(
|
||||
Modifiers(Flag.OVERRIDE),
|
||||
m.name,
|
||||
List(),
|
||||
m.paramss.map(_.map(m => symbolToValDef(m))),
|
||||
TypeTree(),
|
||||
Apply(
|
||||
Select(
|
||||
Select(This(tname), vname),
|
||||
m.name.toTermName),
|
||||
m.paramss.flatMap(_.map{m =>
|
||||
Ident(m.name)
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
private def passThroughTraitName(iName:String) =
|
||||
"T" + (if(iName.startsWith("I")) iName.substring(1) else iName)
|
||||
def registerTrait(s_interface:String, s_trait:String, client:Boolean){}
|
||||
|
||||
def generatePassThroughTrait(s_interface:String):String =
|
||||
{
|
||||
def passThroughTraitName(iName:String) =
|
||||
"T" + (if(iName.startsWith("I")) iName.substring(1) else iName)
|
||||
|
||||
val iSymbol = mirror.staticClass(s_interface)
|
||||
val tname = uniqueName(passThroughTraitName(iSymbol.name.decoded))
|
||||
val vname = tname+"_impl"
|
||||
|
||||
def symbolToValDef(m:Symbol) =
|
||||
ValDef(Modifiers(PARAM), m.asTerm.name.decoded, Ident(m), EmptyTree)
|
||||
|
||||
def passThroughMethod(tname:String, vname:String, m:MethodSymbol):Tree =
|
||||
DefDef(
|
||||
Modifiers(Flag.OVERRIDE),
|
||||
m.name,
|
||||
List(),
|
||||
m.paramss.map(_.map(m => symbolToValDef(m))),
|
||||
TypeTree(),
|
||||
Apply(
|
||||
Select(
|
||||
Select(This(tname), vname),
|
||||
m.name.toTermName),
|
||||
m.paramss.flatMap(_.map{m =>
|
||||
Ident(m.name)
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
val methods = iSymbol.toType.members.filter(_.isJava).map(m => passThroughMethod(tname, vname, m.asMethod))
|
||||
val traitDef =
|
||||
normalClassDef(
|
||||
@@ -258,7 +261,7 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
EmptyTree),
|
||||
DefDef(
|
||||
Modifiers(OVERRIDE),
|
||||
"partAdded":TermName,
|
||||
"bindPart":TermName,
|
||||
List(),
|
||||
List(
|
||||
List(
|
||||
@@ -277,7 +280,7 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
Ident(iSymbol))),
|
||||
literalUnit),
|
||||
Apply(
|
||||
Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), "partAdded"),
|
||||
Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), "bindPart"),
|
||||
Ident("part")
|
||||
)
|
||||
)),
|
||||
@@ -342,5 +345,5 @@ object ScalaCompilerFactory extends IMultipartFactory
|
||||
return define(traitDef).fullName
|
||||
}
|
||||
|
||||
def generateTile(types:Seq[String], client:Boolean) = SuperSet(types, client).generate
|
||||
def generateTile(types:Seq[String], client:Boolean) = SuperSet(types, client).generate
|
||||
}
|
||||
@@ -19,7 +19,8 @@ public abstract class McSidedMetaPart extends McMetaPart
|
||||
|
||||
public abstract int sideForMeta(int meta);
|
||||
|
||||
public void onNeighbourChanged()
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
if(!world().isRemote)
|
||||
dropIfCantStay();
|
||||
|
||||
@@ -114,7 +114,7 @@ public class RedstoneTorchPart extends TorchPart implements IRedstonePart, IRand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighbourChanged()
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
if(!world().isRemote)
|
||||
{
|
||||
@@ -135,7 +135,8 @@ public class RedstoneTorchPart extends TorchPart implements IRedstonePart, IRand
|
||||
if(isBeingPowered() == active())
|
||||
toggle();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void randomUpdate()
|
||||
{
|
||||
scheduledTick();
|
||||
@@ -210,7 +211,7 @@ public class RedstoneTorchPart extends TorchPart implements IRedstonePart, IRand
|
||||
{
|
||||
if(active())
|
||||
tile().notifyNeighborChange(1);
|
||||
onNeighbourChanged();
|
||||
onNeighborChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@ import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.JPartialOcclusion
|
||||
import codechicken.multipart.PartialOcclusionTest
|
||||
|
||||
trait TPartialOcclusionTile extends TileMultipart
|
||||
class TPartialOcclusionTile extends TileMultipart
|
||||
{
|
||||
override def occlusionTest(parts:Seq[TMultiPart], npart:TMultiPart):Boolean =
|
||||
{
|
||||
@@ -18,11 +18,13 @@ trait TPartialOcclusionTile extends TileMultipart
|
||||
def partialOcclusionTest(parts:Seq[TMultiPart]):Boolean =
|
||||
{
|
||||
val test = new PartialOcclusionTest(parts.length)
|
||||
for(i <- 0 until parts.length)
|
||||
var i = 0
|
||||
while(i < parts.length)
|
||||
{
|
||||
val part = parts(i)
|
||||
if(part.isInstanceOf[JPartialOcclusion])
|
||||
test.fill(i, part.asInstanceOf[JPartialOcclusion])
|
||||
i+=1
|
||||
}
|
||||
return test()
|
||||
}
|
||||
|
||||
@@ -13,13 +13,11 @@ trait TRedstoneTile extends TileMultipart with IRedstoneTile
|
||||
override def strongPowerLevel(side:Int):Int =
|
||||
{
|
||||
var max = 0
|
||||
partList.foreach(p =>
|
||||
if(p.isInstanceOf[IRedstonePart])
|
||||
{
|
||||
val l = p.asInstanceOf[IRedstonePart].strongPowerLevel(side)
|
||||
if(l > max) max = l
|
||||
}
|
||||
)
|
||||
for(p@(_p: IRedstonePart) <- partList.iterator)
|
||||
{
|
||||
val l = p.strongPowerLevel(side)
|
||||
if(l > max) max = l
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user