Enter: The Gadget
Code: Select all
-- Copyright (C) 2010,2011.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function gadget:GetInfo()
return {
name = "gltest ",
desc = "test123",
author = "PicassoCT",
date = "7 b.Creation",
license = "GNU GPL, v2 its goes in all fields",
layer = 0,
enabled = true -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- synced only
if (gadgetHandler:IsSyncedCode()) then
local startScale=0.1
swiftSpearTable={}
--registrates the units created
function gadget:UnitCreated(unitID, unitDefID, unitTeam)
if unitDefID== UnitDefNames["jswiftspear"].id then
swiftSpearTable[#swiftSpearTable+1]={}
swiftSpearTable[#swiftSpearTable][1]={}
swiftSpearTable[#swiftSpearTable][1]=unitID
swiftSpearTable[#swiftSpearTable][2]={}
swiftSpearTable[#swiftSpearTable][2]=startScale
end
end
local function raiseGrowthEvent(unitID, size)
_G.laserEventArgs = {}
_G.laserEventArgs[1] = {}
_G.laserEventArgs[1] = unitID
_G.laserEventArgs[2] = {}
_G.laserEventArgs[2] = size
SendToUnsynced("growthEvent")
_G.laserEventArgs = nil
end
local UPDATE_FREQUNECY=100
function gadget:GameFrame(f)
if f%UPDATE_FREQUNECY== 0 then
for i=1,table.getn(swiftSpearTable),1 do
if Spring.ValidUnitID(swiftSpearTable[i][1]) == true and swiftSpearTable[i][2] <=1 then
swiftSpearTable[i][2]=(swiftSpearTable[i][2]+0.1)
raiseGrowthEvent{swiftSpearTable[i][1], swiftSpearTable[i][2]}
else
table.remove(swiftSpearTable,i)
end
end
--call a unsyced function
end
end
else
local unsycedSwiftTable={}
function gadget:Initialize()
gadgetHandler:AddSyncAction("growthEvent", HandleGrowthEvent)
end
function HandleGrowthEvent()
unsycedSwiftTable[#unsycedSwiftTable+1]={}
unsycedSwiftTable[#unsycedSwiftTable][1]={}
unsycedSwiftTable[#unsycedSwiftTable][1]=SYNCED.laserEventArgs[1]
unsycedSwiftTable[#unsycedSwiftTable][2]={}
unsycedSwiftTable[#unsycedSwiftTable][2]=SYNCED.laserEventArgs[2]
end
function gadget:DrawWorld()
if unsycedSwiftTable~=nil and table.getn(unsycedSwiftTable)~=0 then
for i=1,table.getn(unsycedSwiftTable),1 do
scale=unsycedSwiftTable[i][2]
gl.PushMatrix()
gl.Unit(unsycedSwiftTable[i][1])
gl.Scale(scale,scale,scale)
gl.PopMatrix()
if unsycedSwiftTable[i][2] ==1 then
table.remove(unsycedSwiftTable,i)
end
end
end
end
end
Making MC Escher happy, but me a sad pandering being.
Positiv: I screw around with some graphics, obviously messing up the depthtest, or order in which they are draw.
Negativ: This is not what i came for.
Help would be very much appreciated. Even made a thread at the right place, with a accurate problem description, so reuse is given. Thanks for any help and goodnight.