mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
Removed debug println in hologram renderer (oops).
Fixed screen clicking via arrows a bit. Caching shells for reduced memory consumption for nested os.executes.
This commit is contained in:
parent
ed2707097c
commit
faade8b79f
@ -360,7 +360,7 @@ end
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function execute(command, env, ...)
|
local function execute(env, command, ...)
|
||||||
checkArg(1, command, "string")
|
checkArg(1, command, "string")
|
||||||
local commands, reason = parseCommands(command)
|
local commands, reason = parseCommands(command)
|
||||||
if not commands then
|
if not commands then
|
||||||
@ -479,39 +479,12 @@ local args, options = shell.parse(...)
|
|||||||
local history = {}
|
local history = {}
|
||||||
|
|
||||||
if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then
|
if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then
|
||||||
-- interactive shell.
|
-- interactive shell. use original shell for input but register self as
|
||||||
while true do
|
-- global SHELL for command execution.
|
||||||
if not term.isAvailable() then -- don't clear unless we lost the term
|
local oldShell = os.getenv("SHELL")
|
||||||
while not term.isAvailable() do
|
os.setenv("SHELL", process.running())
|
||||||
event.pull("term_available")
|
os.execute("/bin/sh")
|
||||||
end
|
os.setenv("SHELL", oldShell)
|
||||||
term.clear()
|
|
||||||
end
|
|
||||||
while term.isAvailable() do
|
|
||||||
local foreground = component.gpu.setForeground(0xFF0000)
|
|
||||||
term.write(expand(os.getenv("PS1") or "$ "))
|
|
||||||
component.gpu.setForeground(foreground)
|
|
||||||
local command = term.read(history)
|
|
||||||
if not command then
|
|
||||||
term.write("exit\n")
|
|
||||||
return -- eof
|
|
||||||
end
|
|
||||||
while #history > 10 do
|
|
||||||
table.remove(history, 1)
|
|
||||||
end
|
|
||||||
command = text.trim(command)
|
|
||||||
if command == "exit" then
|
|
||||||
return
|
|
||||||
elseif command ~= "" then
|
|
||||||
local result, reason = execute(command)
|
|
||||||
if not result then
|
|
||||||
io.stderr:write((tostring(reason) or "unknown error").. "\n")
|
|
||||||
elseif term.getCursor() > 1 then
|
|
||||||
term.write("\n")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
-- execute command.
|
-- execute command.
|
||||||
local result = table.pack(execute(...))
|
local result = table.pack(execute(...))
|
||||||
|
@ -41,7 +41,7 @@ local function evaluate(value)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local function execute(command, ...)
|
local function execute(env, command, ...)
|
||||||
local parts, reason = text.tokenize(command)
|
local parts, reason = text.tokenize(command)
|
||||||
if not parts then
|
if not parts then
|
||||||
return false, reason
|
return false, reason
|
||||||
@ -119,7 +119,7 @@ if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then
|
|||||||
if command == "exit" then
|
if command == "exit" then
|
||||||
return
|
return
|
||||||
elseif command ~= "" then
|
elseif command ~= "" then
|
||||||
local result, reason = execute(command)
|
local result, reason = os.execute(command)
|
||||||
if term.getCursor() > 1 then
|
if term.getCursor() > 1 then
|
||||||
term.write("\n")
|
term.write("\n")
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,23 @@ local unicode = require("unicode")
|
|||||||
local shell = {}
|
local shell = {}
|
||||||
local aliases = {}
|
local aliases = {}
|
||||||
|
|
||||||
|
-- Cache loaded shells for command execution. This puts the requirement on
|
||||||
|
-- shells that they do not keep a global state, since they may be called
|
||||||
|
-- multiple times, but reduces memory usage a lot.
|
||||||
|
local shells = setmetatable({}, {__mode="v"})
|
||||||
|
|
||||||
|
local function getShell()
|
||||||
|
local shellName = shell.resolve(os.getenv("SHELL"), "lua")
|
||||||
|
if shells[shellName] then
|
||||||
|
return shells[shellName]
|
||||||
|
end
|
||||||
|
local sh, reason = loadfile(shellName, "t", env)
|
||||||
|
if sh then
|
||||||
|
shells[shellName] = sh
|
||||||
|
end
|
||||||
|
return sh, reason
|
||||||
|
end
|
||||||
|
|
||||||
local function findFile(name, ext)
|
local function findFile(name, ext)
|
||||||
checkArg(1, name, "string")
|
checkArg(1, name, "string")
|
||||||
local function findIn(dir)
|
local function findIn(dir)
|
||||||
@ -129,11 +146,11 @@ function shell.resolve(path, ext)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.execute(command, env, ...)
|
function shell.execute(command, env, ...)
|
||||||
local sh, reason = loadfile(shell.resolve(os.getenv("SHELL"), "lua"), "t", env)
|
local sh, reason = getShell()
|
||||||
if not sh then
|
if not sh then
|
||||||
return false, reason
|
return false, reason
|
||||||
end
|
end
|
||||||
local result = table.pack(pcall(sh, command, ...))
|
local result = table.pack(pcall(sh, env, command, ...))
|
||||||
if not result[1] and type(result[2]) == "table" and result[2].reason == "terminated" then
|
if not result[1] and type(result[2]) == "table" and result[2].reason == "terminated" then
|
||||||
if result[2].code then
|
if result[2].code then
|
||||||
return true
|
return true
|
||||||
|
@ -630,10 +630,20 @@ local function main()
|
|||||||
|
|
||||||
-- After memory footprint to avoid init.lua bumping the baseline.
|
-- After memory footprint to avoid init.lua bumping the baseline.
|
||||||
local co, args = bootstrap()
|
local co, args = bootstrap()
|
||||||
|
local forceGC = 10
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
deadline = computer.realTime() + system.timeout()
|
deadline = computer.realTime() + system.timeout()
|
||||||
hitDeadline = false
|
hitDeadline = false
|
||||||
|
|
||||||
|
-- NOTE: since this is run in an executor thread and we enforce timeouts
|
||||||
|
-- in user-defined garbage collector callbacks this should be safe.
|
||||||
|
forceGC = forceGC - 1
|
||||||
|
if forceGC < 1 then
|
||||||
|
collectgarbage("collect")
|
||||||
|
forceGC = 10
|
||||||
|
end
|
||||||
|
|
||||||
debug.sethook(co, checkDeadline, "", hookInterval)
|
debug.sethook(co, checkDeadline, "", hookInterval)
|
||||||
local result = table.pack(coroutine.resume(co, table.unpack(args, 1, args.n)))
|
local result = table.pack(coroutine.resume(co, table.unpack(args, 1, args.n)))
|
||||||
if not result[1] then
|
if not result[1] then
|
||||||
|
@ -288,8 +288,6 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
|
|||||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, 0L, GL15.GL_DYNAMIC_DRAW)
|
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, 0L, GL15.GL_DYNAMIC_DRAW)
|
||||||
}
|
}
|
||||||
|
|
||||||
println("HOLOGRAM SIZE: " + GL15.glGetBufferParameteri(GL15.GL_ARRAY_BUFFER, GL15.GL_BUFFER_SIZE) / 1024.0 / 1024.0)
|
|
||||||
|
|
||||||
// Reset for the next operation.
|
// Reset for the next operation.
|
||||||
dataBuffer.clear()
|
dataBuffer.clear()
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ abstract class Screen(val parent: SimpleDelegator) extends RedstoneAware with Si
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def collide(world: World, x: Int, y: Int, z: Int, entity: Entity) =
|
override def collide(world: World, x: Int, y: Int, z: Int, entity: Entity) =
|
||||||
if (!world.isRemote) (entity, world.getBlockTileEntity(x, y, z)) match {
|
if (world.isRemote) (entity, world.getBlockTileEntity(x, y, z)) match {
|
||||||
case (arrow: EntityArrow, screen: tileentity.Screen) if screen.tier > 0 =>
|
case (arrow: EntityArrow, screen: tileentity.Screen) if screen.tier > 0 =>
|
||||||
val hitX = math.max(0, math.min(1, arrow.posX - x))
|
val hitX = math.max(0, math.min(1, arrow.posX - x))
|
||||||
val hitY = math.max(0, math.min(1, arrow.posY - y))
|
val hitY = math.max(0, math.min(1, arrow.posY - y))
|
||||||
@ -350,7 +350,7 @@ abstract class Screen(val parent: SimpleDelegator) extends RedstoneAware with Si
|
|||||||
else ForgeDirection.SOUTH
|
else ForgeDirection.SOUTH
|
||||||
}
|
}
|
||||||
if (side == screen.facing) {
|
if (side == screen.facing) {
|
||||||
screen.shot(arrow, hitX, hitY, hitZ)
|
screen.shot(arrow)
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.{Side, SideOnly}
|
|||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.util.Color
|
import li.cil.oc.util.Color
|
||||||
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.entity.Entity
|
import net.minecraft.entity.Entity
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.entity.projectile.EntityArrow
|
import net.minecraft.entity.projectile.EntityArrow
|
||||||
@ -134,19 +135,8 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def shot(arrow: EntityArrow, hitX: Double, hitY: Double, hitZ: Double) {
|
def shot(arrow: EntityArrow) {
|
||||||
// This is nasty, but I see no other way: arrows can trigger two collisions,
|
arrows.add(arrow)
|
||||||
// once on their own when hitting a block, a second time via their entity's
|
|
||||||
// common collision checker. The second one (collision checker) has the
|
|
||||||
// better coordinates (arrow moved back out of the block it collided with),
|
|
||||||
// so use that when possible, otherwise resolve in next update.
|
|
||||||
if (!arrows.add(arrow)) {
|
|
||||||
arrows.remove(arrow)
|
|
||||||
arrow.shootingEntity match {
|
|
||||||
case player: EntityPlayer => click(player, hitX, hitY, hitZ)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
@ -219,12 +209,22 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with
|
|||||||
}
|
}
|
||||||
if (arrows.size > 0) {
|
if (arrows.size > 0) {
|
||||||
for (arrow <- arrows) {
|
for (arrow <- arrows) {
|
||||||
val hitX = math.max(0, math.min(1, arrow.posX - x))
|
val hitX = arrow.posX - x
|
||||||
val hitY = math.max(0, math.min(1, arrow.posY - y))
|
val hitY = arrow.posY - y
|
||||||
val hitZ = math.max(0, math.min(1, arrow.posZ - z))
|
val hitZ = arrow.posZ - z
|
||||||
shot(arrow, hitX, hitY, hitZ)
|
val hitXInner = math.abs(hitX - 0.5) < 0.45
|
||||||
|
val hitYInner = math.abs(hitY - 0.5) < 0.45
|
||||||
|
val hitZInner = math.abs(hitZ - 0.5) < 0.45
|
||||||
|
if (hitXInner && hitYInner && !hitZInner ||
|
||||||
|
hitXInner && !hitYInner && hitZInner ||
|
||||||
|
!hitXInner && hitYInner && hitZInner) {
|
||||||
|
arrow.shootingEntity match {
|
||||||
|
case player: EntityPlayer if player == Minecraft.getMinecraft.thePlayer => click(player, hitX, hitY, hitZ)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert(arrows.isEmpty)
|
arrows.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user