From 0c9080451a195297caa0301f038ba59c0a407022 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Thu, 3 May 2012 22:24:10 +0000 Subject: [PATCH] better hex tagert git-svn-id: http://svn.net-core.org/repos/t-engine4@5083 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/Target.lua | 57 ++++++++++---------- src/core_lua.c | 73 ++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 28 deletions(-) diff --git a/game/engines/default/engine/Target.lua b/game/engines/default/engine/Target.lua index e9bbd9bd59..a902496d3d 100644 --- a/game/engines/default/engine/Target.lua +++ b/game/engines/default/engine/Target.lua @@ -87,6 +87,25 @@ function _M:display(dispx, dispy) -- Do not display if not requested if not self.active then return end + local display_highlight + if util.isHex() then + display_highlight = function(texture, tx, ty) + texture:toScreenHighlightHex( + self.display_x + (tx - game.level.map.mx) * self.tile_w * Map.zoom, + self.display_y + (ty - game.level.map.my + util.hexOffset(tx)) * self.tile_h * Map.zoom, + self.tile_w * Map.zoom, + self.tile_h * Map.zoom) + end + else + display_highlight = function(texture, tx, ty) + texture:toScreen( + self.display_x + (tx - game.level.map.mx) * self.tile_w * Map.zoom, + self.display_y + (ty - game.level.map.my) * self.tile_h * Map.zoom, + self.tile_w * Map.zoom, + self.tile_h * Map.zoom) + end + end + local s = self.sb local l if self.target_type.source_actor.lineFOV then @@ -115,7 +134,7 @@ function _M:display(dispx, dispy) s = self.sr end if game.level.map:isBound(blocked_corner_x, blocked_corner_y) then - s:toScreen(self.display_x + (blocked_corner_x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (blocked_corner_y - game.level.map.my + util.hexOffset(blocked_corner_x)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) + display_highlight(s, blocked_corner_x, blocked_corner_y) end s = self.sr end @@ -147,7 +166,7 @@ function _M:display(dispx, dispy) end end end - s:toScreen(self.display_x + (lx - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (ly - game.level.map.my + util.hexOffset(lx)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) + display_highlight(s, lx, ly) if block then s = self.sr stopped = true @@ -162,8 +181,8 @@ function _M:display(dispx, dispy) s = self.sr -- double the fun :-P if game.level.map:isBound(blocked_corner_x, blocked_corner_y) then - s:toScreen(self.display_x + (blocked_corner_x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (blocked_corner_y - game.level.map.my + util.hexOffset(blocked_corner_x)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) - s:toScreen(self.display_x + (blocked_corner_x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (blocked_corner_y - game.level.map.my + util.hexOffset(blocked_corner_x)) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom) + display_highlight(s, blocked_corner_x, blocked_corner_y) + display_highlight(s, blocked_corner_x, blocked_corner_y) end end @@ -182,15 +201,9 @@ function _M:display(dispx, dispy) end, function(_, px, py) if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then - self.syg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, - self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom, - self.tile_w * Map.zoom, - self.tile_h * Map.zoom) + display_highlight(self.syg, px, py) else - self.sg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, - self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom, - self.tile_w * Map.zoom, - self.tile_h * Map.zoom) + display_highlight(self.sg, px, py) end end, nil) @@ -212,15 +225,9 @@ function _M:display(dispx, dispy) end, function(_, px, py) if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then - self.syg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, - self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom, - self.tile_w * Map.zoom, - self.tile_h * Map.zoom) + display_highlight(self.syg, px, py) else - self.sg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, - self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom, - self.tile_w * Map.zoom, - self.tile_h * Map.zoom) + display_highlight(self.sg, px, py) end end, nil) @@ -241,15 +248,9 @@ function _M:display(dispx, dispy) end, function(_, px, py) if not self.target_type.no_restrict and not game.level.map.remembers(px, py) and not game.level.map.seens(px, py) then - self.syg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, - self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom, - self.tile_w * Map.zoom, - self.tile_h * Map.zoom) + display_highlight(self.syg, px, py) else - self.sg:toScreen(self.display_x + (px - game.level.map.mx) * self.tile_w * Map.zoom, - self.display_y + (py - game.level.map.my + util.hexOffset(px)) * self.tile_h * Map.zoom, - self.tile_w * Map.zoom, - self.tile_h * Map.zoom) + display_highlight(self.sg, px, py) end end, nil) diff --git a/src/core_lua.c b/src/core_lua.c index 080a56467a..b8e562970f 100644 --- a/src/core_lua.c +++ b/src/core_lua.c @@ -1477,6 +1477,78 @@ static int sdl_texture_toscreen(lua_State *L) return 0; } +static int sdl_texture_toscreen_highlight_hex(lua_State *L) +{ + GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1); + int x = luaL_checknumber(L, 2); + int y = luaL_checknumber(L, 3); + int w = luaL_checknumber(L, 4); + int h = luaL_checknumber(L, 5); + if (lua_isnumber(L, 6)) + { + float r = luaL_checknumber(L, 6); + float g = luaL_checknumber(L, 7); + float b = luaL_checknumber(L, 8); + float a = luaL_checknumber(L, 9); + GLfloat colors[4*8] = { + r, g, b, a, + r, g, b, a, + r, g, b, a, + r, g, b, a, + r, g, b, a, + r, g, b, a, + r, g, b, a, + r, g, b, a, + }; + glColorPointer(4, GL_FLOAT, 0, colors); + } + else + { + // A very slight gradient to give some definition to the texture + GLfloat colors[4*8] = { + 0.9, 0.9, 0.9, 1, + 0.9, 0.9, 0.9, 1, + 1, 1, 1, 1, + 1, 1, 1, 1, + 0.9, 0.9, 0.9, 1, + 0.8, 0.8, 0.8, 1, + 0.8, 0.8, 0.8, 1, + 0.9, 0.9, 0.9, 1, + }; + glColorPointer(4, GL_FLOAT, 0, colors); + } + + tglBindTexture(GL_TEXTURE_2D, *t); + + GLfloat texcoords[2*8] = { + 0, 0, + 0, 1, + 1, 1, + 1, 0, + 1, 0, + 1, 0, + 1, 0, + 1, 0, + }; + + float f = x - w/6.0; + float v = 4.0*w/3.0; + glTexCoordPointer(2, GL_FLOAT, 0, texcoords); + GLfloat vertices[2*8] = { + x + 0.5*v, y + 0.5*h, + f + 0.25*v, y, + f, y + 0.5*h, + f + 0.25*v, y + h, + f + 0.75*v, y + h, + f + v, y + 0.5*h, + f + 0.75*v, y, + f + 0.25*v, y, + }; + glVertexPointer(2, GL_FLOAT, 0, vertices); + glDrawArrays(GL_TRIANGLE_FAN, 0, 8); + return 0; +} + static int sdl_texture_toscreen_full(lua_State *L) { GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1); @@ -2361,6 +2433,7 @@ static const struct luaL_reg sdl_texture_reg[] = {"toScreen", sdl_texture_toscreen}, {"toScreenFull", sdl_texture_toscreen_full}, {"toScreenPrecise", sdl_texture_toscreen_precise}, + {"toScreenHighlightHex", sdl_texture_toscreen_highlight_hex}, {"makeOutline", sdl_texture_outline}, {"toSurface", gl_texture_to_sdl}, {"bind", sdl_texture_bind}, -- GitLab