Skip to content

Commit

Permalink
Code drop
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmcwatters committed Nov 23, 2019
1 parent 1d6e287 commit 938608c
Show file tree
Hide file tree
Showing 111 changed files with 3,524 additions and 1,328 deletions.
1 change: 1 addition & 0 deletions cfg/binds.lst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Communication
=============

"Chat" chat
"Voice" +voice

Development
===========
Expand Down
1 change: 1 addition & 0 deletions cfg/binds_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tab +gamemenu
wu zoomin
wd zoomout
y chat
k +voice
\ toggleconsole
59 changes: 32 additions & 27 deletions class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local rawget = rawget
local ipairs = ipairs
local module = module
local _G = _G
local _R = debug.getregistry()

-------------------------------------------------------------------------------
-- new()
Expand All @@ -30,20 +31,20 @@ end

-------------------------------------------------------------------------------
-- getbaseclass()
-- Purpose: Get a base class
-- Input: class - Class metatable
-- Output: class
-- Purpose: Gets a base class
-- Input: metatable
-- Output: metatable
-------------------------------------------------------------------------------
local function getbaseclass( class )
local name = class.__base
return package.loaded[ name ]
local function getbaseclass( metatable )
local base = metatable.__base
return package.loaded[ base ]
end

_G.getbaseclass = getbaseclass

-------------------------------------------------------------------------------
-- eventnames
-- Purpose: Provide a list of all inheritable internal event names
-- Purpose: Provides a list of all inheritable internal event names
-------------------------------------------------------------------------------
local eventnames = {
"__add", "__sub", "__mul", "__div", "__mod",
Expand All @@ -54,15 +55,15 @@ local eventnames = {

-------------------------------------------------------------------------------
-- metamethod()
-- Purpose: Creates a filler metamethod for metamethod inheritance
-- Input: class - Class metatable
-- eventname - Event name
-- Purpose: Creates a placeholder metamethod for metamethod inheritance
-- Input: metatable
-- eventname
-- Output: function
-------------------------------------------------------------------------------
local function metamethod( class, eventname )
local function metamethod( metatable, eventname )
return function( ... )
local event = nil
local base = getbaseclass( class )
local base = getbaseclass( metatable )
while ( base ~= nil ) do
if ( base[ eventname ] ) then
event = base[ eventname ]
Expand All @@ -86,7 +87,7 @@ end

-------------------------------------------------------------------------------
-- setproxy()
-- Purpose: Set a proxy for __gc
-- Purpose: Sets a proxy for __gc
-- Input: object
-------------------------------------------------------------------------------
local function setproxy( object )
Expand All @@ -102,13 +103,16 @@ end
_G.setproxy = setproxy

-------------------------------------------------------------------------------
-- package.class
-- Purpose: Turns a module into a class
-- Input: module - Module table
-- classinit
-- Purpose: Initializes a class
-- Input: module
-------------------------------------------------------------------------------
function package.class( module )
local function classinit( module )
module.__index = module
module.__type = string.gsub( module._NAME, module._PACKAGE, "" )
module._M = nil
module._NAME = nil
module._PACKAGE = nil
-- Create a shortcut to name()
setmetatable( module, {
__call = function( self, ... )
Expand All @@ -132,11 +136,11 @@ function package.class( module )
end

-------------------------------------------------------------------------------
-- package.inherit
-- inherit
-- Purpose: Sets a base class
-- Input: base - Class name
-- Input: base - Name of metatable
-------------------------------------------------------------------------------
function package.inherit( base )
local function inherit( base )
return function( module )
-- Set our base class
module.__base = base
Expand Down Expand Up @@ -169,15 +173,16 @@ end
-------------------------------------------------------------------------------
-- class()
-- Purpose: Creates a class
-- Input: name - Name of class
-- Input: modname
-------------------------------------------------------------------------------
function class( name )
local function setmodule( name )
module( name, package.class )
end setmodule( name )
function class( modname )
local function setmodule( modname )
module( modname, classinit )
end setmodule( modname )
_R[ modname ] = package.loaded[ modname ]
-- For syntactic sugar, return a function to set inheritance
return function( base )
local _M = package.loaded[ name ]
package.inherit( base )( _M )
local metatable = package.loaded[ modname ]
inherit( base )( metatable )
end
end
24 changes: 24 additions & 0 deletions common/vector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ function vector:vector( x, y )
self.y = y or 0
end

function vector:approximately( b )
return math.approximately( self.x, b.x ) and
math.approximately( self.y, b.y )
end

function vector:dot( b )
local ret = 0
ret = ret + self.x * b.x
ret = ret + self.y * b.y
return ret
end

function vector:length()
return math.sqrt( self:lengthSqr() )
end
Expand All @@ -25,6 +37,10 @@ end

function vector:normalize()
local length = self:length()
if ( length == 0 ) then
return vector()
end

return vector( self.x / length, self.y / length )
end

Expand Down Expand Up @@ -56,6 +72,14 @@ function vector.__mul( a, b )
end
end

function vector.__div( a, b )
if ( type( b ) == "number" ) then
return vector( a.x / b, a.y / b )
else
return vector( a.x / b.x, a.y / b.y )
end
end

function vector.__eq( a, b )
return a.x == b.x and a.y == b.y
end
Expand Down
7 changes: 5 additions & 2 deletions conf.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
--=========== Copyright © 2018, Planimeter, All rights reserved. ===========--
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose:
--
--==========================================================================--

require( "engine.shared.profile" )
profile.push( "load" )

argv = {}
for _, v in ipairs( arg ) do argv[ v ] = true end

Expand All @@ -22,7 +25,7 @@ end

function love.conf( c )
c.title = "Grid Engine"
c.version = "11.1"
c.version = "11.3"
if ( _DEDICATED ) then
c.modules.keyboard = false
c.modules.mouse = false
Expand Down
4 changes: 2 additions & 2 deletions engine/client/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ end

concommand( "zoomin", "Zooms the camera in", function()
local scale = getZoom()
setZoom( scale * 2 )
setZoom( scale + 1 )
end )

concommand( "zoomout", "Zooms the camera out", function()
local scale = getZoom()
setZoom( scale / 2 )
setZoom( scale - 1 )
end )

function update( dt )
Expand Down
29 changes: 18 additions & 11 deletions engine/client/canvas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
function canvas.invalidateCanvases()
for _, v in ipairs( canvas._canvases ) do
if ( typeof( v, "fullscreencanvas" ) ) then
newCanvas( v )
newCanvas( v, unpack( v._args ) )
end

if ( v:shouldAutoRedraw() ) then
Expand All @@ -44,7 +44,7 @@ local function noop()
end

function canvas:canvas( ... )
local args = { ... }
self._args = { ... }
self._drawFunc = noop
self.needsRedraw = false
self.autoRedraw = true
Expand Down Expand Up @@ -78,6 +78,17 @@ function canvas:invalidate()
self.needsRedraw = true
end

function canvas:remove()
for i, v in ipairs( canvas._canvases ) do
if ( v == self ) then
table.remove( canvas._canvases, i )
end
end

collectgarbage()
collectgarbage()
end

function canvas:renderTo( func )
self._drawFunc = func
render( self )
Expand All @@ -93,16 +104,12 @@ function canvas:__tostring()
return s
end

function canvas:__gc()
for i, v in ipairs( canvas._canvases ) do
if ( v == self ) then
table.remove( canvas._canvases, i )
end
end
end
canvas.__gc = canvas.remove

class "fullscreencanvas" ( "canvas" )

function fullscreencanvas:fullscreencanvas()
canvas.canvas( self )
function fullscreencanvas:fullscreencanvas( ... )
canvas.canvas( self, ... )
end

fullscreencanvas.__gc = canvas.remove
15 changes: 11 additions & 4 deletions engine/client/gui/autoloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ local _G = _G
module( "gui" )

local metatable = {}
local panelDirectories = {
"game.client",
"engine.client"
}

function metatable.__index( t, k )
-- Ignore private members.
local privateMember = string.sub( k, 1, 1 ) == "_"
if ( privateMember ) then
return
end

for _, module in ipairs( {
"game.client",
"engine.client"
} ) do
-- Look in `/game/client/gui` and `/engine/client/gui` for
-- panels not yet required and require them.
--
-- Otherwise, return a standard Lua error.
for _, module in ipairs( panelDirectories ) do
local library = module .. ".gui." .. k
local status, err = pcall( require, library )
if ( status == true ) then
Expand All @@ -40,6 +46,7 @@ function metatable.__index( t, k )
end
end

-- Return pass-through.
local v = rawget( t, k )
if ( v ~= nil ) then
return v
Expand Down
Loading

0 comments on commit 938608c

Please sign in to comment.