Commit b7e25465ba2969cedb911dd9f597ce40dda87bf9

Authored by dg
1 parent 3dfab2ea

remove fucking flickering of hell that's been bugging me for 2 months and slwoin…

…g down dev! DIE BUG DIE !!!!!


git-svn-id: http://svn.net-core.org/repos/t-engine4@3333 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -458,7 +458,7 @@ function _M:display(x, y, nb_keyframe, always_show)
458 458 local ox, oy = self.display_x, self.display_y
459 459 self.display_x, self.display_y = x or self.display_x, y or self.display_y
460 460
461   - self._map:toScreen(self.display_x, self.display_y, nb_keyframe, always_show)
  461 + self._map:toScreen(self.display_x, self.display_y, nb_keyframe, always_show, self.changed)
462 462 self:displayParticles(nb_keyframe)
463 463 self:displayEffects()
464 464
... ...
... ... @@ -301,7 +301,7 @@ function _M:runCheck()
301 301 end
302 302 end
303 303 end
304   -
  304 +
305 305 if not self.running.ignore_left and (self.running.block_left ~= blocked_soft_left or self.running.block_left ~= blocked_hard_left) then
306 306 return false, "terrain change on left side"
307 307 end
... ... @@ -326,6 +326,7 @@ function _M:runStop(msg)
326 326 game.log("Ran for %d turns (stop reason: %s).", self.running.cnt, msg)
327 327 end
328 328
  329 + self:runStopped(self.running.cnt, msg)
329 330 self.running = nil
330 331 return true
331 332 end
... ... @@ -369,3 +370,7 @@ end
369 370 --- Called after running a step
370 371 function _M:runMoved()
371 372 end
  373 +
  374 +--- Called after stopping running
  375 +function _M:runStopped()
  376 +end
... ...
... ... @@ -800,6 +800,10 @@ function _M:onTurn()
800 800 end
801 801 end
802 802
  803 +function _M:updateFOV()
  804 + self.player:playerFOV()
  805 +end
  806 +
803 807 function _M:display(nb_keyframes)
804 808 -- If switching resolution, blank everything but the dialog
805 809 if self.change_res_dialog then engine.GameTurnBased.display(self, nb_keyframes) return end
... ... @@ -810,9 +814,7 @@ function _M:display(nb_keyframes)
810 814
811 815 -- Display the map and compute FOV for the player if needed
812 816 local changed = map.changed
813   - if changed then
814   - self.player:playerFOV()
815   - end
  817 + if changed then self:updateFOV() end
816 818
817 819 -- Display using Framebuffer, so that we can use shaders and all
818 820 if self.fbo then
... ...
... ... @@ -582,6 +582,11 @@ function _M:runMoved()
582 582 self:playerFOV()
583 583 end
584 584
  585 +--- Called after stopping running
  586 +function _M:runStopped()
  587 + self:playerFOV()
  588 +end
  589 +
585 590 --- Activates a hotkey with a type "inventory"
586 591 function _M:hotkeyInventory(name)
587 592 local find = function(name)
... ...
... ... @@ -497,13 +497,13 @@ static void setup_seens_texture(map_type *map)
497 497 if (map->seens_map) free(map->seens_map);
498 498
499 499 glGenTextures(1, &(map->seens_texture));
500   - printf("C Map seens texture: %d (%dx%d)\n", map->seens_texture, map->mwidth + 7, map->mheight + 7);
  500 + printf("C Map seens texture: %d (%dx%d)\n", map->seens_texture, map->w, map->h);
501 501 tglBindTexture(GL_TEXTURE_2D, map->seens_texture);
502 502 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
503 503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
504 504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
505   - glTexImage2D(GL_TEXTURE_2D, 0, 4, map->mwidth + 7, map->mheight + 7, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
506   - map->seens_map = calloc((map->mwidth + 7)*(map->mheight + 7)*4, sizeof(GLubyte));
  505 + glTexImage2D(GL_TEXTURE_2D, 0, 4, map->w, map->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
  506 + map->seens_map = calloc((map->w)*(map->h)*4, sizeof(GLubyte));
507 507 map->seen_changed = TRUE;
508 508 }
509 509
... ... @@ -822,10 +822,6 @@ static int map_get_seensinfo(lua_State *L)
822 822 static void map_update_seen_texture(map_type *map)
823 823 {
824 824 glBindTexture(GL_TEXTURE_2D, map->seens_texture);
825   -// int zx, zy;
826   -// glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &zx);
827   -// glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &zy);
828   -// printf("UPDATE SEENS: %dx%d vs %dx%d\n", zx,zy, map->mwidth + 7, map->mheight + 7);
829 825 gl_c_texture = -1;
830 826
831 827 int mx = map->used_mx;
... ... @@ -833,14 +829,14 @@ static void map_update_seen_texture(map_type *map)
833 829 GLubyte *seens = map->seens_map;
834 830 int ptr = 0;
835 831 int ii, jj;
836   - map->seensinfo_w = map->mwidth + 7;
837   - map->seensinfo_h = map->mheight + 7;
  832 + map->seensinfo_w = map->w;
  833 + map->seensinfo_h = map->h;
838 834
839   - for (jj = 0; jj < map->mheight + 7; jj++)
  835 + for (jj = 0; jj < map->h; jj++)
840 836 {
841   - for (ii = 0; ii < map->mwidth + 7; ii++)
  837 + for (ii = 0; ii < map->w; ii++)
842 838 {
843   - int i = mx - 3 + ii, j = my - 3 + jj;
  839 + int i = ii, j = jj;
844 840 if ((i < 0) || (j < 0) || (i >= map->w) || (j >= map->h))
845 841 {
846 842 seens[ptr] = 0;
... ... @@ -877,7 +873,14 @@ static void map_update_seen_texture(map_type *map)
877 873 ptr += 4;
878 874 }
879 875 }
880   - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, map->mwidth + 7, map->mheight + 7, GL_BGRA, GL_UNSIGNED_BYTE, seens);
  876 + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, map->w, map->h, GL_BGRA, GL_UNSIGNED_BYTE, seens);
  877 +}
  878 +
  879 +static int map_update_seen_texture_lua(lua_State *L)
  880 +{
  881 + map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 1);
  882 + map_update_seen_texture(map);
  883 + return 0;
881 884 }
882 885
883 886 static int map_draw_seen_texture(lua_State *L)
... ... @@ -886,15 +889,15 @@ static int map_draw_seen_texture(lua_State *L)
886 889 int x = lua_tonumber(L, 2);
887 890 int y = lua_tonumber(L, 3);
888 891 int nb_keyframes = 0;
889   - x += -map->tile_w * 3;
890   - y += -map->tile_h * 3;
891   - int w = (map->mwidth + 7) * map->tile_w;
892   - int h = (map->mheight + 7) * map->tile_h;
  892 +// x += -map->tile_w * 3;
  893 +// y += -map->tile_h * 3;
  894 + int w = (map->w) * map->tile_w;
  895 + int h = (map->h) * map->tile_h;
893 896
894 897 int mx = map->mx;
895 898 int my = map->my;
896   - x -= map->tile_w * map->used_animdx;
897   - y -= map->tile_h * map->used_animdy;
  899 + x -= map->tile_w * (map->used_animdx + map->used_mx);
  900 + y -= map->tile_h * (map->used_animdy + map->used_my);
898 901
899 902 tglBindTexture(GL_TEXTURE_2D, map->seens_texture);
900 903
... ... @@ -1186,6 +1189,7 @@ static int map_to_screen(lua_State *L)
1186 1189 int y = luaL_checknumber(L, 3);
1187 1190 int nb_keyframes = luaL_checknumber(L, 4);
1188 1191 bool always_show = lua_toboolean(L, 5);
  1192 + bool changed = lua_toboolean(L, 6);
1189 1193 int i = 0, j = 0, z = 0;
1190 1194 int vert_idx = 0;
1191 1195 int col_idx = 0;
... ... @@ -1194,7 +1198,7 @@ static int map_to_screen(lua_State *L)
1194 1198 int my = map->my;
1195 1199
1196 1200 /* Enables Depth Testing */
1197   - glEnable(GL_DEPTH_TEST);
  1201 + //glEnable(GL_DEPTH_TEST);
1198 1202
1199 1203 GLfloat *vertices = map->vertices;
1200 1204 GLfloat *colors = map->colors;
... ... @@ -1225,6 +1229,7 @@ static int map_to_screen(lua_State *L)
1225 1229 mx = map->mx + (int)(adx * map->move_step / (float)map->move_max - adx);
1226 1230 my = map->my + (int)(ady * map->move_step / (float)map->move_max - ady);
1227 1231 }
  1232 + changed = TRUE;
1228 1233 }
1229 1234 x -= map->tile_w * animdx;
1230 1235 y -= map->tile_h * animdy;
... ... @@ -1278,11 +1283,19 @@ static int map_to_screen(lua_State *L)
1278 1283 }
1279 1284
1280 1285 /* Disables Depth Testing, we do not need it for the rest of the display */
1281   - glDisable(GL_DEPTH_TEST);
  1286 + //glDisable(GL_DEPTH_TEST);
1282 1287
1283   -// if (always_show && map->seen_changed)
1284   - if (always_show)
  1288 + if (always_show && changed)
1285 1289 {
  1290 + lua_getglobal(L, "game");
  1291 + lua_pushstring(L, "updateFOV");
  1292 + lua_gettable(L, -2);
  1293 + if (lua_isfunction(L, -1)) {
  1294 + lua_pushvalue(L, -2);
  1295 + lua_call(L, 1, 0);
  1296 + lua_pop(L, 1);
  1297 + }
  1298 + else lua_pop(L, 2);
1286 1299 map_update_seen_texture(map);
1287 1300 map->seen_changed = FALSE;
1288 1301 }
... ... @@ -1409,7 +1422,7 @@ static const struct luaL_reg map_reg[] =
1409 1422 {
1410 1423 {"__gc", map_free},
1411 1424 {"close", map_free},
1412   -// {"updateSeensTexture", map_update_seen_texture},
  1425 + {"updateSeensTexture", map_update_seen_texture_lua},
1413 1426 {"bindSeensTexture", map_bind_seen_texture},
1414 1427 {"drawSeensTexture", map_draw_seen_texture},
1415 1428 {"setZoom", map_set_zoom},
... ...