Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
DMClVG committed Oct 28, 2023
1 parent 0dc49a9 commit 2c7fdc8
Show file tree
Hide file tree
Showing 22 changed files with 618 additions and 670 deletions.
54 changes: 21 additions & 33 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,40 @@ function love.load(args)
local username = args[3]

local socket = loex.socket.connect(address)
assert(socket)
assert(socket)

local font = love.graphics.newFont(23)
love.graphics.setFont(font)

game = {}
game.gravity = 42 -- TODO
game = {}
game.gravity = 42 -- TODO

game.socket = socket
game.username = username
game.socket = socket
game.username = username

game.ondraw = loex.signal.new()
game.onupdate = loex.signal.new()
game.onmousemoved = loex.signal.new()
game.onmousepressed = loex.signal.new()
game.onkeypressed = loex.signal.new()
game.onresize = loex.signal.new()
game.onquit = loex.signal.new()
game.ondraw = loex.signal.new()
game.onupdate = loex.signal.new()
game.onmousemoved = loex.signal.new()
game.onmousepressed = loex.signal.new()
game.onkeypressed = loex.signal.new()
game.onresize = loex.signal.new()
game.onquit = loex.signal.new()

require("screens.joinscreen").init(game)
require("screens.joinscreen").init(game)
end

function love.update(dt)
game.onupdate:emit(game, dt)
end
function love.update(dt) game.onupdate:emit(game, dt) end

function love.draw()
game.ondraw:emit(game)
end
function love.draw() game.ondraw:emit(game) end

function love.mousepressed(x,y,button,istouch,presses)
game.onmousepressed:emit(game,x,y,button,istouch,presses)
function love.mousepressed(x, y, button, istouch, presses)
game.onmousepressed:emit(game, x, y, button, istouch, presses)
end

function love.mousemoved(x, y, dx, dy,istouch)
game.onmousemoved:emit(game,x,y,dx,dy,istouch)
end
function love.mousemoved(x, y, dx, dy, istouch) game.onmousemoved:emit(game, x, y, dx, dy, istouch) end

function love.keypressed(k,scancode,isrepeat)
game.onkeypressed:emit(game, k, scancode, isrepeat)
end
function love.keypressed(k, scancode, isrepeat) game.onkeypressed:emit(game, k, scancode, isrepeat) end

function love.resize(w, h)
game.onresize:emit(game,w,h)
end
function love.resize(w, h) game.onresize:emit(game, w, h) end

function love.quit()
game.onquit:emit(game)
end
function love.quit() game.onquit:emit(game) end
16 changes: 4 additions & 12 deletions client/packets.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
local packets = {}
local encode = loex.socket.encode

function packets.place(x, y, z, t)
return encode {type="place",x=x,y=y,z=z,t=t}
end
function packets.place(x, y, z, t) return encode { type = "place", x = x, y = y, z = z, t = t } end

function packets.breaktile(x, y, z)
return encode {type="breaktile",x=x,y=y,z=z}
end
function packets.breaktile(x, y, z) return encode { type = "breaktile", x = x, y = y, z = z } end

function packets.join(username)
return encode {type="join", username=username}
end
function packets.join(username) return encode { type = "join", username = username } end

function packets.move(x, y, z)
return encode {type="move", x=x,y=y,z=z}
end
function packets.move(x, y, z) return encode { type = "move", x = x, y = y, z = z } end

return packets
18 changes: 9 additions & 9 deletions client/quad.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local a = -1.0
local b = 1.0
return function (texture)
return g3d.newModel ({
{0, a, a, 1, 1},
{0, b, b, 0, 0},
{0, b, a, 0, 1},
return function(texture)
return g3d.newModel({
{ 0, a, a, 1, 1 },
{ 0, b, b, 0, 0 },
{ 0, b, a, 0, 1 },

{0, a, a, 1, 1},
{0, a, b, 1, 0},
{0, b, b, 0, 0},
}, texture)
{ 0, a, a, 1, 1 },
{ 0, a, b, 1, 0 },
{ 0, b, b, 0, 0 },
}, texture)
end
8 changes: 3 additions & 5 deletions client/screens/chunkremesh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ require("love.math")
require("love.data")
local ffi = require("ffi")

local channel, cx, cy, cz, blockdata, size, tids,
n1, n2, n3, n4, n5, n6,
c0, c1, c2, c3, c4, c5, c6 = ...
local channel, cx, cy, cz, blockdata, size, tids, n1, n2, n3, n4, n5, n6, c0, c1, c2, c3, c4, c5, c6 = ...

local blockdatapointer = ffi.cast("uint8_t *", blockdata:getFFIPointer())
local n1p = n1 and ffi.cast("uint8_t *", n1:getFFIPointer())
Expand All @@ -23,7 +21,7 @@ local c5p = c5 and ffi.cast("uint8_t *", c5:getFFIPointer())
local c6p = c6 and ffi.cast("uint8_t *", c6:getFFIPointer())

local function getc(pointer, x, y, z)
if true then return 255 end
if true then return 255 end
local i = x + size * y + size * size * z

-- if this block is outside of the chunk, check the neighboring chunks if they exist
Expand Down Expand Up @@ -92,7 +90,7 @@ if count > 0 then
for i = start, stop, step do
local primary = i % 2 == 1
local secondary = i > 2 and i < 6
local c = getc(c0p, x,y,z) / 255
local c = getc(c0p, x, y, z) / 255
datapointer[dataindex].x = x + (mx == 1 and primary and 1 or 0) + (mx == 2 and secondary and 1 or 0)
datapointer[dataindex].y = y + (my == 1 and primary and 1 or 0) + (my == 2 and secondary and 1 or 0)
datapointer[dataindex].z = z + (mz == 1 and primary and 1 or 0) + (mz == 2 and secondary and 1 or 0)
Expand Down
73 changes: 36 additions & 37 deletions client/screens/cursormodel.lua
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
local a = -0.005
local b = 1.005
return g3d.newModel {
{ a, a, a },
{ b, a, a },
{ b, a, a },
{ a, a, a },
{ a, a, b },
{ a, a, b },
{ b, a, b },
{ a, a, b },
{ a, a, b },
{ b, a, b },
{ b, a, a },
{ b, a, a },
{ a, a, a },
{ b, a, a },
{ b, a, a },
{ a, a, a },
{ a, a, b },
{ a, a, b },
{ b, a, b },
{ a, a, b },
{ a, a, b },
{ b, a, b },
{ b, a, a },
{ b, a, a },

{ a, b, a },
{ b, b, a },
{ b, b, a },
{ a, b, a },
{ a, b, b },
{ a, b, b },
{ b, b, b },
{ a, b, b },
{ a, b, b },
{ b, b, b },
{ b, b, a },
{ b, b, a },
{ a, b, a },
{ b, b, a },
{ b, b, a },
{ a, b, a },
{ a, b, b },
{ a, b, b },
{ b, b, b },
{ a, b, b },
{ a, b, b },
{ b, b, b },
{ b, b, a },
{ b, b, a },

{ a, a, a },
{ a, b, a },
{ a, b, a },
{ b, a, a },
{ b, b, a },
{ b, b, a },
{ a, a, b },
{ a, b, b },
{ a, b, b },
{ b, a, b },
{ b, b, b },
{ b, b, b },
{ a, a, a },
{ a, b, a },
{ a, b, a },
{ b, a, a },
{ b, b, a },
{ b, b, a },
{ a, a, b },
{ a, b, b },
{ a, b, b },
{ b, a, b },
{ b, b, b },
{ b, b, b },
}

10 changes: 5 additions & 5 deletions client/screens/errorscreen.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
local errorscreen = {}
local lg = love.graphics

function errorscreen.init(g, cause)
g.errorscreen = {}
g.errorscreen.cause = cause
g.ondraw:catch(errorscreen.draw)
function errorscreen.init(g, cause)
g.errorscreen = {}
g.errorscreen.cause = cause
g.ondraw:catch(errorscreen.draw)
end

function errorscreen.draw(g)
lg.clear(1, 0, 0)
local w, h = lg.getWidth(), lg.getHeight()

local cause = g.errorscreen.cause
local cause = g.errorscreen.cause
w = w - lg.getFont():getWidth(cause)
h = h - lg.getFont():getHeight()

Expand Down
Loading

0 comments on commit 2c7fdc8

Please sign in to comment.