Skip to content

Commit

Permalink
we no longer spam a map_width x map_height image each frame
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgreaser committed Mar 6, 2015
1 parent f0784f8 commit 82889aa
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 41 deletions.
16 changes: 8 additions & 8 deletions pkg/base/client_start.lua
Expand Up @@ -25,10 +25,6 @@ if not client.glsl_create then
USE_GLSL = false
end

if not USE_GLSL then
USE_FBO = false
end

if not client.gfx_fbo_available then
USE_FBO = false
end
Expand Down Expand Up @@ -102,6 +98,10 @@ else
function shader_pop_nil() end
end

if not USE_GLSL then
USE_FBO = false
end

if USE_FBO then
print("FBO availability:", client.gfx_fbo_available())
if not client.gfx_fbo_available() then
Expand Down Expand Up @@ -326,7 +326,7 @@ end
-- create map sprites
log_mspr = {}

mspr_player = {
mspr_player = gen_icon {
-1,-3, 0,-3, 1,-3,

-2,-2, 2,-2,
Expand All @@ -343,7 +343,7 @@ mspr_player = {
}

-- TODO: confirm the correct size of the intel + tent icons
mspr_intel = {
mspr_intel = gen_icon {
-3,-3, -2,-3, -1,-3, 0,-3, 1,-3, 2,-3, 3,-3,

-3,-2, 3,-2,
Expand All @@ -359,7 +359,7 @@ mspr_intel = {
-3, 3, -2, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3, 3,
}

mspr_tent = {
mspr_tent = gen_icon {
0,-3,

0,-2,
Expand Down Expand Up @@ -920,7 +920,7 @@ do
img_overview = common.img_new(xlen, zlen)
img_overview_hmap = common.img_new(xlen, zlen)
img_overview_grid = common.img_new(xlen, zlen)
img_overview_icons = common.img_new(xlen, zlen)
--img_overview_icons = common.img_new(xlen, zlen)
local x,z

if shader_world then
Expand Down
68 changes: 68 additions & 0 deletions pkg/base/lib_util.lua
Expand Up @@ -57,6 +57,74 @@ function recolor_component(r,g,b,mdata)
end
end

function gen_icon(mspr)
local this = {
ofx = mspr[1],
ofy = mspr[2],
}

do
local i
local lgx, lgy = mspr[1], mspr[2]

for i=3,#mspr,2 do
this.ofx = math.min(this.ofx, mspr[i+0])
this.ofy = math.min(this.ofy, mspr[i+1])
lgx = math.max(lgx, mspr[i+0])
lgy = math.max(lgy, mspr[i+1])
end

this.w = lgx - this.ofx + 1
this.h = lgy - this.ofy + 1
this.img = common.img_new(this.w, this.h)

--print(this.w, this.h, this.ofx, this.ofy)
for i=1,#mspr,2 do
common.img_pixel_set(this.img,
mspr[i+0]-this.ofx,
mspr[i+1]-this.ofy,
0xFFFFFFFF)
end
end

function this.blit(x, y, c, mx, my, x1, y1, x2, y2)
local dx = x + this.ofx - x1
local dy = y + this.ofy - y1
local sx = 0
local sy = 0
local iw = this.w
local ih = this.h

if dx < 0 then
local diff = 0 - dx
dx = 0
sx = sx + diff
iw = iw - diff
end

if dy < 0 then
local diff = 0 - dy
dy = 0
sy = sy + diff
ih = ih - diff
end

if dx + iw >= x2-x1 then
iw = (x2-x1) - dx
end

if dy + ih >= y2-y1 then
ih = (y2-y1) - dy
end

if iw >= 1 and ih >= 1 then
client.img_blit(this.img, dx+mx, dy+my, iw, ih, sx, sy, c)
end
end

return this
end

function string.split(s, sep, plain)
local start = 1
local done = false
Expand Down
2 changes: 1 addition & 1 deletion pkg/base/network.lua
Expand Up @@ -414,7 +414,7 @@ network.sys_handle_s2c(PKT_NEW_MAP, "", function (neth, cli, plr, sec_current, p
img_overview = common.img_new(xlen, zlen)
img_overview_hmap = common.img_new(xlen, zlen)
img_overview_grid = common.img_new(xlen, zlen)
img_overview_icons = common.img_new(xlen, zlen)
--img_overview_icons = common.img_new(xlen, zlen)
local x,z
for z=0,zlen-1 do
Expand Down
59 changes: 27 additions & 32 deletions pkg/base/obj_player.lua
Expand Up @@ -1481,14 +1481,22 @@ function new_player(settings)
font_mini.print(x - font_mini.width*#s/2, y, 0xFFFFFFFF, s)
end

function this.blit_overview_icons(mx, my, x1, y1, x2, y2)
local i
for i=1,#log_mspr do
--print("blit", i, log_mspr[i][1], log_mspr[i][2], log_mspr[i][3])
log_mspr[i][4].blit(
log_mspr[i][1],
log_mspr[i][2],
log_mspr[i][3],
mx, my,
x1, y1, x2, y2)
end
end

function this.update_overview_icons(dT)
if this.alive then
for i=1,#log_mspr,2 do
local u,v
u = log_mspr[i ]
v = log_mspr[i+1]
common.img_pixel_set(img_overview_icons, u, v, 0x00000000)
end
local i, j
log_mspr = {}

for j=1,players.max do
Expand All @@ -1501,7 +1509,9 @@ function new_player(settings)
if not plr.alive then
drawit = false
elseif plr == this then
-- TODO: work out how to draw the line!
c = 0xFF00FFFF
--[[
for i=0,10-1 do
local d=i/math.sqrt(2)
local u,v
Expand All @@ -1511,6 +1521,7 @@ function new_player(settings)
log_mspr[#log_mspr+1] = v
common.img_pixel_set(img_overview_icons, u, v, c)
end
]]
elseif plr.team == this.team then
c = 0xFFFFFFFF
else
Expand All @@ -1520,14 +1531,7 @@ function new_player(settings)
end

if drawit then
for i=1,#mspr_player,2 do
local u,v
u = math.floor(x)+mspr_player[i ]
v = math.floor(y)+mspr_player[i+1]
log_mspr[#log_mspr+1] = u
log_mspr[#log_mspr+1] = v
common.img_pixel_set(img_overview_icons, u, v, c)
end
log_mspr[1+#log_mspr] = {math.floor(x), math.floor(y), c, mspr_player}
end
end
end
Expand All @@ -1540,14 +1544,7 @@ function new_player(settings)
x,y = obj.x, obj.z
local l = obj.color_icon
local c = argb_split_to_merged(l[1],l[2],l[3])
for i=1,#(obj.mspr),2 do
local u,v
u = math.floor(x)+obj.mspr[i ]
v = math.floor(y)+obj.mspr[i+1]
log_mspr[#log_mspr+1] = u
log_mspr[#log_mspr+1] = v
common.img_pixel_set(img_overview_icons, u, v, c)
end
log_mspr[1+#log_mspr] = {x, y, c, obj.mspr}
end
end
end
Expand All @@ -1562,7 +1559,8 @@ function new_player(settings)
client.img_blit(img_overview_grid, mx, my,
this.large_map.width, this.large_map.height,
0, 0, 0x80FFFFFF)
client.img_blit(img_overview_icons, mx, my)
--client.img_blit(img_overview_icons, mx, my)
this.blit_overview_icons(mx, my, 0, 0, this.large_map.width, this.large_map.height)

local i

Expand Down Expand Up @@ -1616,16 +1614,15 @@ function new_player(settings)
mw, mh = this.mini_map.width, this.mini_map.height

local left, top
left = this.mini_map.l
top = this.mini_map.t
left = math.floor(this.mini_map.l)
top = math.floor(this.mini_map.t)

local qx, qy
for qy=-1,1 do
for qx=-1,1 do

local view_left, view_top
view_left = this.x-mw/2+this.large_map.width*qx
view_top = this.z-mh/2+this.large_map.height*qy
view_left = math.floor(this.x-mw/2)+this.large_map.width*qx
view_top = math.floor(this.z-mh/2)+this.large_map.height*qy

client.img_blit(img_overview, left, top,
mw, mh,
Expand All @@ -1635,12 +1632,10 @@ function new_player(settings)
mw, mh,
view_left, view_top,
0x80FFFFFF)
client.img_blit(img_overview_icons, left, top,
mw, mh,
view_left, view_top,
0xFFFFFFFF)
end
end
local vx, vy = math.floor(this.x-mw/2), math.floor(this.z-mh/2)
this.blit_overview_icons(left, top, vx, vy, vx+mw, vy+mh)
this.print_map_location(this.mini_map.cx, this.mini_map.b + 2)
end
end
Expand Down

0 comments on commit 82889aa

Please sign in to comment.