Skip to content

Commit

Permalink
switched to anim entity,
Browse files Browse the repository at this point in the history
added disappear distance option,
changed fgd keyvalues to mimic portal 2 linked_portal_door,
fixed portal rotation,
fixed #1 (portal shaking),
resolved bliptec/world-portals/#4 (missing pair failing hard)
  • Loading branch information
bliptec committed Jul 12, 2014
1 parent 545c3d8 commit 434c695
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 199 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ World portals inspired by Overv's Portal Project and Portal 2's linked_portal_do

* Rendering: almost complete
* Weapon and trace diversion: just started
* Entity teleportation: not started
* Entity teleportation: just started
14 changes: 8 additions & 6 deletions gmod_worldportal.fgd → gmod_worldportals.fgd
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//=============================================================================
//
// Purpose: Garry's Mod world portal declarations
// Garry's Mod world portal declarations
//
//=============================================================================

@include "base.fgd"

@BaseClass = LinkedPortalDoor : "An entity that can be linked to another door and create a passage between them dynamically."
[
input SetPair(integer) : "Changes the pair of portals this portal belongs to"
partnername(target_destination) : "Linked Partner" : : "Another 'prop_linked_portal_door' entity which will link to this one."

input SetPartner(string) : "Set a new partner door."
input Open(void) : "Open the door and cause the portal to activate."
input Close(void) : "Close the door and cause the portal to deactivate."

Expand All @@ -20,11 +22,11 @@
output OnPlayerTeleportToMe(void) : "When the player is teleported from this linked partner to the portal."
]

@PointClass base(Targetname, Parentname, Angles, LinkedPortalDoor) studio("models/editor/axis_helper_thick.mdl") = linked_portal_door :
@PointClass base(Targetname, Parentname, Angles, LinkedPortalDoor) sphere(DisappearDist) studio("models/editor/axis_helper_thick.mdl") = linked_portal_door :
"A door which is linked by a portal to another 'linked_portal_door' entity."
[
pair(integer) : "Pair" : 1 : "Unique identifier for a set of portals."
width(integer) : "Width" : 128 : "Width of the desired portal."
height(integer) : "Height" : 128 : "Height of the desired portal."
width(integer) : "Width" : 128 : "Width of the desired portal. Measured from the center"
height(integer) : "Height" : 128 : "Height of the desired portal. Measured from the center"
startactive(integer) : "Start Active" : 1 : "Whether to start the linkage as active from the start."
DisappearDist(integer) : "Disappear Distance" : -1 : "Distance at which the portal will stop rendering"
]
136 changes: 0 additions & 136 deletions lua/autorun/client/init.lua

This file was deleted.

34 changes: 0 additions & 34 deletions lua/autorun/server/init.lua

This file was deleted.

15 changes: 15 additions & 0 deletions lua/autorun/worldportals_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

worldportals = {}

-- Load required files
if SERVER then

include( "worldportals/render_sv.lua" )

AddCSLuaFile( "worldportals/render_cl.lua" )

else

include( "worldportals/render_cl.lua" )

end
40 changes: 40 additions & 0 deletions lua/entities/linked_portal_door/cl_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

include( "shared.lua" )

AccessorFunc( ENT, "texture", "Texture" )


--Draw world portals
function ENT:Draw()

--self:DrawModel()

if ( worldportals.drawing ) then return end

render.ClearStencil()
render.SetStencilEnable( true )

render.SetStencilWriteMask( 1 )
render.SetStencilTestMask( 1 )

render.SetStencilFailOperation( STENCILOPERATION_KEEP )
render.SetStencilZFailOperation( STENCILOPERATION_KEEP )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS )
render.SetStencilReferenceValue( 1 )

render.SetMaterial( worldportals.matDummy )
render.SetColorModulation( 1, 1, 1 )

render.DrawQuadEasy( self:GetPos(), self:GetForward(), self:GetWidth(), self:GetHeight(), Color( 255, 255, 255, 255), self:GetAngles().roll )

render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL )
render.SetStencilPassOperation( STENCILOPERATION_REPLACE )
render.SetStencilReferenceValue( 1 )

worldportals.matView:SetTexture( "$basetexture", self:GetTexture() )
render.SetMaterial( worldportals.matView )
render.DrawScreenQuad()

render.SetStencilEnable( false )
end
39 changes: 17 additions & 22 deletions lua/entities/linked_portal_door/init.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@

ENT.Type = "point"


-- Find paired entity
-- not the most efficient implementation, but good enough for now
function ENT:Think()
-- Determine exit portal
if ( !self.exit ) then
for _, ent in ipairs( ents.FindByClass( "linked_portal_door" ) ) do
if ( ent ~= self and ent.pair == self.pair ) then
self.exit = ent
end
end
end
end
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( "shared.lua" )

AccessorFunc( ENT, "partnername", "PartnerName" )

-- Collect properties
function ENT:KeyValue( key, value )
if ( key == "pair" ) then
self.pair = tonumber( value )

if ( key == "partnername" ) then
self:SetPartnerName( value )
self:SetExit( ents.FindByName( value )[1] )

elseif ( key == "width" ) then
self.width = tonumber( value )
self:SetWidth( tonumber(value) *2 )

elseif ( key == "height" ) then
self.height = tonumber( value )
self:SetHeight( tonumber(value) *2 )

elseif ( key == "DisappearDist" ) then
self:SetDisappearDist( tonumber(value) )

elseif ( key == "angles" ) then
local args = value:Split( " " )
Expand All @@ -33,7 +29,6 @@ function ENT:KeyValue( key, value )
args[k] = tonumber(arg)
end

self.forward = Angle( unpack(args) ):Forward()
print( value, forward )
self:SetAngles( Angle( unpack(args) ) )
end
end
end
50 changes: 50 additions & 0 deletions lua/entities/linked_portal_door/shared.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

ENT.Type = "anim"
ENT.Spawnable = false
ENT.AdminOnly = false
ENT.Editable = false


--ENT.Model = Model("models/props/cs_office/microwave.mdl")

function ENT:Initialize()

local mins = Vector(-1, -self:GetWidth() /2, -self:GetHeight() /2)
local maxs = -mins

if CLIENT then

self:SetTexture( GetRenderTarget("portal" .. self:EntIndex(),
ScrW(),
ScrH(),
false
) )

self:SetRenderBounds( mins, maxs )

end

--[[self:SetModel(self.Model)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_BBOX)
local b = 32
self:SetCollisionBounds(Vector(-b, -b, -b), Vector(b,b,b))
local phys = self:GetPhysicsObject()
--phys:EnableMotion( true )
--phys:Wake()]]--

end


function ENT:SetupDataTables()

self:NetworkVar( "Entity", 0, "Exit" )
self:NetworkVar( "Int", 1, "Width" )
self:NetworkVar( "Int", 2, "Height" )
self:NetworkVar( "Int", 2, "DisappearDist" )

end
Loading

0 comments on commit 434c695

Please sign in to comment.