Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuo256 committed May 14, 2020
2 parents 5109d8a + 64d065f commit 6e6e268
Show file tree
Hide file tree
Showing 74 changed files with 1,178 additions and 217 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.*
!.git*
/lua51*
/profiling
savedir
/log*
import
Expand Down
Binary file added game/assets/texture/Keyboard_A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/texture/Keyboard_D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/texture/Keyboard_S.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/texture/Keyboard_SHIFT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/texture/Keyboard_TAB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added game/assets/texture/Keyboard_W.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions game/common/camera.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

-- luacheck: globals love

local math = require 'common.math'
local vec2 = require 'cpml' .vec2
local Camera = require "steaming.extra_libs.hump.camera"
local VIEWDEFS = require 'view.definitions'

Expand Down Expand Up @@ -41,6 +44,14 @@ function CAM:isTileInFrame(i, j)
and i <= cy + _HALF_H
end

function CAM:relativeTileToScreen(i, j) -- luacheck: no self
j = _HALF_W + j - 1
i = _HALF_H + i - 1
local x = (j - 0.5) * _TILE_W
local y = (i - 0.5) * _TILE_H
return vec2(x, y)
end

function CAM:tilesInRange()
local cx, cy = self:position() -- start point
local rx, ry
Expand Down
82 changes: 82 additions & 0 deletions game/common/profiler.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

-- luacheck: globals love

local SWITCHER = require 'infra.switcher'
local Class = require 'steaming.extra_libs.hump.class'

local Profiler = Class{}

local SAMPLES = 10

function Profiler:init()
self.profiling = {}
self.last_state = nil
self.output = io.open("profiling", "w")
end

function Profiler:update(dt)
local GS = require 'gamestates'
local state = self.last_state
self.last_state = SWITCHER.current()
if state then
local name = "???"
for k,v in pairs(GS) do
if v == state then
name = k
break
end
end
if dt > 0.2 then
local warning = ("%.2f lag on state %s at frame %d\n"):format(
dt, name, GS[name].frame or -1
)
self.output:write(warning)
print(warning)
for mark, slice in pairs(self.slices) do
self.output:write(("%16s: %.3f\n"):format(mark, 1000*slice))
end
end
local sample = self.profiling[name] or { times = {} , n = 1 }
sample.times[sample.n] = dt
sample.n = (sample.n % SAMPLES) + 1
self.profiling[name] = sample
end
self:start()
end

function Profiler:start()
self.started_at = love.timer.getTime()
self.slices = {}
end

function Profiler:mark(name)
if not self.slices then return end
local t = love.timer.getTime()
local dt = t - self.started_at
self.started_at = t
self.slices[name] = (self.slices[name] or 0) + dt
end

local function average(sample)
local sum = 0
for _,time in ipairs(sample.times) do
sum = sum + time
end
return sum / math.max(#sample.times, SAMPLES)
end

function Profiler:draw()
local g = love.graphics
g.push()
g.origin()
g.setColor(1,1,1)
local i = 0
for name,sample in pairs(self.profiling) do
g.print(("%s: %.2f"):format(name, 1 / average(sample)), 32, 32+i*32)
i = i + 1
end
g.pop()
end

return Profiler()

82 changes: 49 additions & 33 deletions game/common/visibility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local SCHEMATICS = require 'domain.definitions.schematics'

local TILE = require 'common.tile'

local _cache

--LOCAL FUNCTIONS DECLARATIONS--

local updateOctant
Expand All @@ -15,7 +17,6 @@ local visibilityOfShadow
local addProjection
local transformOctant
local projectTile
local fullShadow
local isInRange

local VISIBILITY = {}
Expand Down Expand Up @@ -47,11 +48,31 @@ function VISIBILITY.resetFov(fov, sector)

end

function VISIBILITY.isCached(actor, sector)
if not _cache then
_cache = {}
end
local key = ("%s/%s"):format(sector:getId(), actor:getId())
local cached = _cache[key] or {}
local i, j = actor:getPos()
local range = actor:getFovRange()
if cached.i ~= i or cached.j ~= j or cached.range ~= range then
cached.i = i
cached.j = j
cached.range = range
return false
else
return true
end
end

--Update actors field of view based on his position in a given sector
function VISIBILITY.updateFov(actor, sector)
VISIBILITY.resetFov(actor:getFov(sector), sector)
for octant = 1, 8 do
updateOctant(actor, sector, octant)
if not VISIBILITY.isCached(actor, sector) then
VISIBILITY.resetFov(actor:getFov(sector), sector)
for octant = 1, 8 do
updateOctant(actor, sector, octant)
end
end
end

Expand All @@ -61,55 +82,49 @@ end

function updateOctant(actor, sector, octant)
local line = newShadowLine()
local full_shadow = false

--Actor current position
local actor_i, actor_j = actor:getPos()
local fov = actor:getFov(sector)

local row = 0
while true do

for row = 0, actor:getFovRange() do
do
local d_i, d_j = transformOctant(row, 0, octant)
local pos = {actor_i + d_i, actor_j + d_j}

--Check if tile is inside sector
-- Check if tile is inside sector
if not sector:isInside(pos[1],pos[2]) then break end
if row > actor:getFovRange() then
full_shadow = true
end
end

local full_shadow = false

for col = 0, row do
local d_i, d_j = transformOctant(row, col, octant)
local pos = {actor_i + d_i, actor_j + d_j}

--Check if tile is inside sector
if not sector:isInside(pos[1],pos[2]) then break end

if full_shadow then
if fov[pos[1]][pos[2]] then --Was seen once
fov[pos[1]][pos[2]] = 0 --Make it invisible
end
else
--Set visibility of tile
local projection = projectTile(row, col)
local visible = 1 - visibilityOfShadow(line, projection)
if isInRange(pos[1], pos[2], actor) and (fov[pos[1]][pos[2]] or visible == 1) then
fov[pos[1]][pos[2]] = visible
end

--Add any wall tiles to the shadow line
if visible == 1 and
sector.tiles[pos[1]][pos[2]] and
sector.tiles[pos[1]][pos[2]].type == SCHEMATICS.WALL then
addProjection(line, projection)
fullShadow = fullShadow or isShadowLineFull(line)
end
--Set visibility of tile
local projection = projectTile(row, col)
local visible = 1 - visibilityOfShadow(line, projection)
if isInRange(pos[1], pos[2], actor) and (fov[pos[1]][pos[2]] or visible == 1) then
fov[pos[1]][pos[2]] = visible
end

--Add any wall tiles to the shadow line
if visible == 1 and
sector.tiles[pos[1]][pos[2]] and
sector.tiles[pos[1]][pos[2]].type == SCHEMATICS.WALL then
addProjection(line, projection)
full_shadow = full_shadow or isShadowLineFull(line)
end
end

-- Check if shadow is full and no other tiles behind it will be visible
if full_shadow then
break
end
row = row + 1
end
end

Expand Down Expand Up @@ -163,9 +178,10 @@ end
function addProjection(line, projection)
local list = line.shadow_list
local index = 1;
local n = #list

--Figure out where to slot the new shadow in the list
while index <= #list do
while index <= n do
--Stop when we hit the insertion point.
if list[index].start >= projection.start then break end
index = index + 1
Expand Down
11 changes: 11 additions & 0 deletions game/database/domains/actor/tutorial-brawler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"behavior":"player",
"extends":"brawler",
"initial_buffer":[{
"amount":8,
"card":"strike"
}],
"traits":[],
"signature":false,
"collection":false
}
12 changes: 12 additions & 0 deletions game/database/domains/actor/tutorial-idle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ani":2,
"arc":-2,
"behavior":"idle",
"cor":2,
"initial_buffer":[],
"name":"Tutorial",
"traits":[],
"extends":false,
"signature":false,
"collection":false
}
2 changes: 1 addition & 1 deletion game/database/domains/body/npc-farewell.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"appearance":"corgi",
"dialogue":"[header name:Guard]\nHere's one last tip...\n\n[newpage wait:1.5]\n[header name:Guard]\n[color value:blue]Press D\n[color value:regular] to use stairs, [pause value:.5][endl]\n[color value:blue]Hold TAB[color value:regular] to show stats, [pause value:.5]and[endl]\n[color value:blue]Press SHIFT[color value:regular] to toggle the control hints!\n\n[newpage wait:2.8]\n[header name:Guard]\n[size value:plus]Good luck![size value:regular] [pause value:.5]You'll need it!",
"dialogue":"[header name:Guard]\nHere's one last tip...\n\n[newpage wait:1.5]\n[header name:Guard]\n[color value:blue]Hold TAB[color value:regular] to show stats, [pause value:.5]and[endl]\n[color value:blue]Press SHIFT[color value:regular] to toggle the control hints!\n\n[newpage wait:2.8]\n[header name:Guard]\n[size value:plus]Good luck![size value:regular] [pause value:.5]You'll need it!",
"drops":[],
"efc":0,
"extends":"npc-base",
Expand Down
10 changes: 10 additions & 0 deletions game/database/domains/body/obstacle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appearance":"demobody",
"drops":[],
"efc":-2,
"faction":"agressive",
"fin":-2,
"name":"Obstacle",
"res":2,
"extends":false
}
9 changes: 9 additions & 0 deletions game/database/domains/body/tutorial-slime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"appearance":"slime",
"drops":[],
"efc":2,
"extends":"slime",
"faction":"agressive",
"name":"Old Slime",
"res":-2
}
1 change: 1 addition & 0 deletions game/database/domains/card/sidestep.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"attr":"ANI",
"cost":2,
"desc":"Ooops, excuse me!",
"half-exhaustion":true,
"icon":"card-sidestep",
"name":"Side-step",
"set":"maneuver_common",
Expand Down
1 change: 1 addition & 0 deletions game/database/domains/card/stunning-blow.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"body-only":{
"body-type":false
},
"dif-fact":true,
"max-range":1,
"name":"choose_target",
"output":"target_pos",
Expand Down
2 changes: 1 addition & 1 deletion game/database/domains/sector/initial.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}],
"layout-info":"",
"map":{
"data":[1,1,1,3,2,2,2,3,1,1,1,1,1,1,1,1,3,3,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,1,3,3,1,1,1,2,2,5,2,2,1,1,1,1,1,1,1,3,3,3,1,1,1,2,2,2,2,2,1,1,1,1,1,1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1,1,1,3,3,3,3,3,3,1,1,1,1,1,1,2,2,2,1,1,1,3,3,3,3,3,3,1,1,1,2,2,2,2,2,2,1,1,1,3,3,3,3,3,3,1,1,1,2,1,1,2,2,2,1,1,1,3,3,3,3,3,3,1,1,1,2,1,1,1,1,1,1,1,1,3,3,3,3,3,3,1,1,2,2,2,1,1,1,1,1,1,3,3,3,3,3,3,3,1,1,2,4,2,1,1,1,1,1,1,3,3,3,3,3,3,3,1,1,2,2,2,1,1,1,1,1,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3],
"height":36,
"width":18
},
Expand Down
32 changes: 32 additions & 0 deletions game/database/domains/sector/outpost.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bootstrap":{
"h":20,
"mh":0,
"mw":0,
"w":20
},
"fixed_layout":{
"drops":[],
"encounters":[{
"body-specname":"npc-welcome",
"pos":[6,7],
"actor-specname":false
},{
"body-specname":"npc-veteran-3",
"pos":[11,12],
"actor-specname":false
},{
"body-specname":"npc-farewell",
"pos":[10,4],
"actor-specname":false
}],
"map":{
"data":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,5,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,3,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,1,1,3,3,3,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,1,1,3,3,3,3,2,3,3,3,3,2,2,2,3,3,3,3,3,3,1,1,3,3,2,2,2,2,2,3,3,2,2,2,3,3,3,3,3,3,1,1,3,3,2,2,2,2,2,3,3,2,2,2,3,3,3,3,3,3,1,1,3,3,2,2,4,2,2,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1],
"height":20,
"width":20
},
"offset":[0,0],
"player-pos":[5,14]
},
"theme":false
}
Loading

0 comments on commit 6e6e268

Please sign in to comment.