Skip to content
Snippets Groups Projects
Commit d6264ed9 authored by dg's avatar dg
Browse files

With smooth movements on npcs will not appear to "jump" when they enter visual...

With smooth movements on npcs will not appear to "jump" when they enter visual range and stealth npcs should work correctly


git-svn-id: http://svn.net-core.org/repos/t-engine4@2258 51575b47-30f0-44d4-a5cc-537603b46e54
parent d17ed702
No related branches found
No related tags found
No related merge requests found
......@@ -300,6 +300,7 @@ void call_draw(int nb_keyframes)
}
}
long total_keyframes = 0;
void on_redraw()
{
static int Frames = 0;
......@@ -334,6 +335,7 @@ void on_redraw()
int nb = ceilf(nb_keyframes);
count_keyframes += nb - last_keyframe;
total_keyframes += nb - last_keyframe;
// printf("keyframes: %f / %f by %f => %d\n", nb_keyframes, reference_fps, step, nb - (last_keyframe));
call_draw(nb - last_keyframe);
......
......@@ -27,6 +27,7 @@ extern void setupRealtime(float freq);
extern void setupDisplayTimer(int fps);
extern bool fbo_active;
extern bool multitexture_active;
extern long total_keyframes;
#endif
......@@ -192,7 +192,8 @@ static int map_object_get_move_anim(lua_State *L)
map_object *obj = (map_object*)auxiliar_checkclass(L, "core{mapobj}", 1);
int i = luaL_checknumber(L, 2);
int j = luaL_checknumber(L, 3);
if (!obj->move_max)
if (!obj->move_max || obj->display_last == DL_NONE)
{
lua_pushnumber(L, 0);
lua_pushnumber(L, 0);
......@@ -426,6 +427,10 @@ static int map_new(lua_State *L)
map->tile_w = tile_w;
map->tile_h = tile_h;
// Make up the map objects list, thus we can iterate them later
lua_newtable(L);
map->mo_list_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Ref the table
// In case we can't support NPOT textures round up to nearest POT
int realw=1;
int realh=1;
......@@ -479,6 +484,8 @@ static int map_free(lua_State *L)
free(map->grids_lites);
free(map->minimap);
luaL_unref(L, LUA_REGISTRYINDEX, map->mo_list_ref);
lua_pushnumber(L, 1);
return 1;
}
......@@ -564,15 +571,38 @@ static int map_set_grid(lua_State *L)
if (x < 0 || y < 0 || x >= map->w || y >= map->h) return 0;
unsigned char mm = lua_tonumber(L, 4);
// Get the mo list
lua_rawgeti(L, LUA_REGISTRYINDEX, map->mo_list_ref);
int i;
for (i = 0; i < map->zdepth; i++)
{
// Remove the old object if any from the mo list
// We use the pointer value directly as an index
if (map->grids[x][y][i])
{
lua_pushnumber(L, (long)map->grids[x][y][i]);
lua_pushnil(L);
lua_settable(L, 6); // Access the list of all mos for the map
}
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
lua_gettable(L, 5); // Access the table of mos for this spot
map->grids[x][y][i] = lua_isnoneornil(L, -1) ? NULL : (map_object*)auxiliar_checkclass(L, "core{mapobj}", -1);
// Set the object in the mo list
// We use the pointer value directly as an index
lua_pushnumber(L, (long)map->grids[x][y][i]);
lua_pushvalue(L, -2);
lua_settable(L, 6); // Access the list of all mos for the map
// Remove the mo and get the next
lua_pop(L, 1);
}
// Pop the mo list
lua_pop(L, 1);
map->minimap[x][y] = mm;
return 0;
}
......@@ -697,10 +727,12 @@ void display_map_quad(map_type *map, int dx, int dy, float dz, map_object *m, in
// Handle move anim
float animdx = 0, animdy = 0;
if (m->display_last == DL_NONE) m->move_max = 0;
if (m->move_max)
{
m->move_step += nb_keyframes;
if (m->move_step >= m->move_max) m->move_max = 0; // Reset once in place
if (m->display_last == DL_NONE) m->display_last = DL_TRUE;
if (m->move_max)
{
......@@ -736,6 +768,8 @@ void display_map_quad(map_type *map, int dx, int dy, float dz, map_object *m, in
// Unbind any shaders
if (m->shader) glUseProgramObjectARB(0);
m->display_last = DL_TRUE;
}
static int map_to_screen(lua_State *L)
......@@ -777,6 +811,17 @@ static int map_to_screen(lua_State *L)
}
}
// "Decay" displayed status for all mos
lua_rawgeti(L, LUA_REGISTRYINDEX, map->mo_list_ref);
lua_pushnil(L);
while (lua_next(L, -2) != 0)
{
map_object *mo = (map_object*)auxiliar_checkclass(L, "core{mapobj}", -1);
if (mo->display_last == DL_TRUE) mo->display_last = DL_TRUE_LAST;
else if (mo->display_last == DL_TRUE_LAST) mo->display_last = DL_NONE;
lua_pop(L, 1); // Remove value, keep key for next iteration
}
// Restore normal display
tglColor4f(1, 1, 1, 1);
......
......@@ -39,6 +39,7 @@ typedef struct {
bool valid;
float oldx, oldy;
int move_step, move_max, move_blur;
enum {DL_NONE, DL_TRUE_LAST, DL_TRUE} display_last;
long uid;
} map_object;
......@@ -50,6 +51,8 @@ typedef struct {
unsigned char **minimap;
GLuint mm_floor, mm_block, mm_object, mm_trap, mm_friend, mm_neutral, mm_hostile, mm_level_change;
int mo_list_ref;
int minimap_gridsize;
// Map parameters
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment