2008-07-21 18:42:28 +00:00
|
|
|
AddCSLuaFile("cl_init.lua")
|
|
|
|
AddCSLuaFile("shared.lua")
|
2008-06-14 00:55:20 +00:00
|
|
|
include('shared.lua')
|
|
|
|
|
|
|
|
ENT.WireDebugName = "ConsoleScreen"
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
self.Entity:PhysicsInit(SOLID_VPHYSICS)
|
|
|
|
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
|
|
|
|
self.Entity:SetSolid(SOLID_VPHYSICS)
|
2008-06-14 00:55:20 +00:00
|
|
|
|
|
|
|
self.Inputs = Wire_CreateInputs(self.Entity, { "CharX", "CharY", "Char", "CharParam", "Clk", "Reset" })
|
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "Memory" })
|
|
|
|
|
|
|
|
self.Memory = {}
|
|
|
|
|
|
|
|
for i = 0, 2047 do
|
|
|
|
self.Memory[i] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
self.CharX = 0
|
|
|
|
self.CharY = 0
|
|
|
|
self.Char = 0
|
|
|
|
self.CharParam = 0
|
|
|
|
self.Clk = 1
|
2008-07-14 14:44:30 +00:00
|
|
|
|
|
|
|
self.Monitor = {}
|
|
|
|
self:InitMonitorModels()
|
2008-07-21 18:42:28 +00:00
|
|
|
|
|
|
|
self.DataCache = {}
|
|
|
|
self.DataCacheSize = 0
|
|
|
|
self.IgnoreDataTransfer = false
|
2008-06-14 00:55:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Use()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:SendPixel()
|
|
|
|
if (self.Clk >= 1) && (self.CharX >= 0) && (self.CharX < 30) &&
|
|
|
|
(self.CharY >= 0) && (self.CharY < 18) then
|
|
|
|
local address = math.floor(self.CharY)*30+math.floor(self.CharX)
|
|
|
|
self.Memory[address*2] = self.Char
|
|
|
|
|
|
|
|
local rp = RecipientFilter()
|
|
|
|
rp:AddAllPlayers()
|
|
|
|
|
|
|
|
umsg.Start("consolescreen_datamessage", rp)
|
2008-07-21 18:42:28 +00:00
|
|
|
umsg.Long(self:EntIndex())
|
|
|
|
umsg.Long(self.Clk)
|
|
|
|
umsg.Long(1)
|
|
|
|
umsg.Long(address*2)
|
|
|
|
umsg.Float(self.Char)
|
2008-06-14 00:55:20 +00:00
|
|
|
umsg.End()
|
|
|
|
|
|
|
|
self.Memory[address*2+1] = self.CharParam
|
|
|
|
|
|
|
|
local rp = RecipientFilter()
|
|
|
|
rp:AddAllPlayers()
|
|
|
|
|
|
|
|
umsg.Start("consolescreen_datamessage", rp)
|
2008-07-21 18:42:28 +00:00
|
|
|
umsg.Long(self:EntIndex())
|
|
|
|
umsg.Long(self.Clk)
|
|
|
|
umsg.Long(1)
|
|
|
|
umsg.Long(address*2+1)
|
|
|
|
umsg.Float(self.CharParam)
|
2008-06-14 00:55:20 +00:00
|
|
|
umsg.End()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
function ENT:ReadCell(Address)
|
2008-06-14 00:55:20 +00:00
|
|
|
if (Address < 0) || (Address > 2047) then
|
|
|
|
return nil
|
|
|
|
elseif (Address == 2047) then
|
|
|
|
return self.Clk
|
|
|
|
elseif (Address >= 0) && (Address <= 2046) then
|
2008-07-14 14:44:30 +00:00
|
|
|
if (Address == 2022) then
|
|
|
|
return self.Monitor[self.Entity:GetModel()].RatioX
|
|
|
|
end
|
|
|
|
|
2008-06-14 00:55:20 +00:00
|
|
|
return self.Memory[Address]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
function ENT:FlushCache()
|
|
|
|
if (self.DataCacheSize > 0) then
|
|
|
|
local rp = RecipientFilter()
|
|
|
|
rp:AddAllPlayers()
|
|
|
|
|
|
|
|
umsg.Start("consolescreen_datamessage", rp)
|
|
|
|
umsg.Long(self:EntIndex())
|
|
|
|
umsg.Long(self.Clk)
|
|
|
|
umsg.Long(self.DataCacheSize)
|
|
|
|
|
|
|
|
for i=0,self.DataCacheSize-1 do
|
|
|
|
umsg.Long(self.DataCache[i].Address)
|
|
|
|
umsg.Float(self.DataCache[i].Value)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.DataCacheSize = 0
|
|
|
|
umsg.End()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:WriteCell(Address, value)
|
2008-06-14 00:55:20 +00:00
|
|
|
if (Address < 0) || (Address > 2047) then
|
|
|
|
return false
|
|
|
|
elseif (Address >= 0) && (Address <= 2047) then
|
|
|
|
if (Address == 2047) then
|
|
|
|
self.Clk = value
|
|
|
|
end
|
|
|
|
|
|
|
|
self.Memory[Address] = value
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
//if (Address != 2047) then
|
2008-07-23 12:18:45 +00:00
|
|
|
// self.DataCache[self.DataCacheSize] = {}
|
|
|
|
// self.DataCache[self.DataCacheSize].Address = Address
|
|
|
|
// self.DataCache[self.DataCacheSize].Value = value
|
|
|
|
// self.DataCacheSize = self.DataCacheSize + 1
|
|
|
|
// if (self.DataCacheSize > 20) then
|
|
|
|
// self:FlushCache()
|
|
|
|
// self.IgnoreDataTransfer = true
|
|
|
|
// end
|
2008-07-21 18:42:28 +00:00
|
|
|
//else
|
2008-07-23 12:18:45 +00:00
|
|
|
local rp = RecipientFilter()
|
|
|
|
rp:AddAllPlayers()
|
|
|
|
|
|
|
|
umsg.Start("consolescreen_datamessage", rp)
|
|
|
|
umsg.Long(self:EntIndex())
|
|
|
|
umsg.Long(self.Clk)
|
|
|
|
umsg.Long(1)
|
|
|
|
umsg.Long(Address)
|
|
|
|
umsg.Float(value)
|
|
|
|
umsg.End()
|
2008-07-21 18:42:28 +00:00
|
|
|
//end
|
2008-06-14 00:55:20 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
function ENT:Think()
|
2008-07-23 12:18:45 +00:00
|
|
|
//if (self.IgnoreDataTransfer) then
|
|
|
|
// self:FlushCache()
|
|
|
|
// self.IgnoreDataTransfer = false
|
|
|
|
// self.Entity:NextThink(CurTime()+0.1)
|
|
|
|
///else
|
|
|
|
// self.Entity:NextThink(CurTime()+0.05)
|
|
|
|
//end
|
2008-07-21 18:42:28 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2008-06-14 00:55:20 +00:00
|
|
|
function ENT:TriggerInput(iname, value)
|
|
|
|
if (iname == "CharX") then
|
|
|
|
self.CharX = value
|
|
|
|
self:SendPixel()
|
|
|
|
elseif (iname == "CharY") then
|
|
|
|
self.CharY = value
|
|
|
|
self:SendPixel()
|
|
|
|
elseif (iname == "Char") then
|
|
|
|
self.Char = value
|
|
|
|
self:SendPixel()
|
|
|
|
elseif (iname == "CharParam") then
|
|
|
|
self.CharParam = value
|
|
|
|
self:SendPixel()
|
|
|
|
elseif (iname == "Clk") then
|
|
|
|
self.Clk = value
|
|
|
|
self:SendPixel()
|
|
|
|
elseif (iname == "Reset") then
|
|
|
|
self:WriteCell(2041,0)
|
|
|
|
self:WriteCell(2046,0)
|
|
|
|
self:WriteCell(2042,0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
function MakeWireconsoleScreen(pl, Ang, Pos, Smodel)
|
2008-07-13 20:10:11 +00:00
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
if (!pl:CheckLimit("wire_consolescreens")) then return false end
|
2008-06-14 00:55:20 +00:00
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
local wire_consolescreen = ents.Create("gmod_wire_consolescreen")
|
2008-06-14 00:55:20 +00:00
|
|
|
if (!wire_consolescreen:IsValid()) then return false end
|
|
|
|
wire_consolescreen:SetModel(Smodel)
|
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
wire_consolescreen:SetAngles(Ang)
|
|
|
|
wire_consolescreen:SetPos(Pos)
|
2008-06-14 00:55:20 +00:00
|
|
|
wire_consolescreen:Spawn()
|
|
|
|
|
|
|
|
wire_consolescreen:SetPlayer(pl)
|
|
|
|
|
|
|
|
local ttable = {
|
|
|
|
pl = pl,
|
|
|
|
Smodel = Smodel,
|
|
|
|
}
|
2008-07-21 18:42:28 +00:00
|
|
|
table.Merge(wire_consolescreen:GetTable(), ttable)
|
2008-06-14 00:55:20 +00:00
|
|
|
|
2008-07-21 18:42:28 +00:00
|
|
|
pl:AddCount("wire_consolescreens", wire_consolescreen)
|
2008-06-14 00:55:20 +00:00
|
|
|
|
|
|
|
return wire_consolescreen
|
|
|
|
end
|
|
|
|
|
|
|
|
duplicator.RegisterEntityClass("gmod_wire_consolescreen", MakeWireconsoleScreen, "Ang", "Pos", "Smodel")
|