Commit 6c30cc46f705e251e8304c98bd51928ff0b9a353

Authored by dg
1 parent ce6ee76b

Fix some FOV errors in cones


git-svn-id: http://svn.net-core.org/repos/t-engine4@2882 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -24,6 +24,7 @@ local UserChat = require "profile-thread.UserChat"
24 24 module(..., package.seeall, class.make)
25 25
26 26 function _M:init()
  27 + self.last_ping = os.time()
27 28 self.chat = UserChat.new(self)
28 29 end
29 30
... ... @@ -34,6 +35,7 @@ function _M:connected()
34 35 -- self.sock:settimeout(10)
35 36 print("[PROFILE] Thread connected to te4.org")
36 37 self:login()
  38 + self.chat:reconnect()
37 39 return true
38 40 end
39 41
... ... @@ -168,6 +170,13 @@ function _M:step()
168 170 local l = self:read()
169 171 if l then print("[PROFILE] req/rep thread got unwanted data", l) end
170 172 end
  173 +
  174 + -- Ping every minute, lest the server kills us
  175 + local time = os.time()
  176 + if time - self.last_ping > 60 then
  177 + self.last_ping = time
  178 + self:orderPing()
  179 + end
171 180 return true
172 181 end
173 182 return false
... ... @@ -330,6 +339,15 @@ function _M:orderChatChannelList(o)
330 339 end
331 340 end
332 341
  342 +function _M:orderPing(o)
  343 + local time = core.game.getTime()
  344 + self:command("PING")
  345 + self:read("200")
  346 + local lat = core.game.getTime() - time
  347 + print("Server latency", lat)
  348 + self.server_latency = lat
  349 +end
  350 +
333 351 --------------------------------------------------------------------
334 352 -- Pushes comming from the push socket
335 353 --------------------------------------------------------------------
... ...
... ... @@ -25,6 +25,7 @@ module(..., package.seeall, class.make)
25 25 function _M:init(client)
26 26 self.client = client
27 27 self.channels = {}
  28 + self.joined = {}
28 29 end
29 30
30 31 function _M:event(e)
... ... @@ -43,3 +44,14 @@ function _M:event(e)
43 44 print("[USERCHAT] channel part", e.user, e.channel)
44 45 end
45 46 end
  47 +
  48 +function _M:joined(channel)
  49 + self.joined[channel] = true
  50 +end
  51 +
  52 +function _M:reconnect()
  53 + -- Rejoin every channels
  54 + for chan, _ in pairs(self.joined) do
  55 + client:orderChatJoin{channel=chan}
  56 + end
  57 +end
... ...
... ... @@ -192,12 +192,14 @@ static float fov_slope(float dx, float dy) {
192 192
193 193 /* Octants -------------------------------------------------------- */
194 194
195   -#define FOV_DEFINE_OCTANT(signx, signy, rx, ry, nx, ny, nf, apply_edge, apply_diag) \
  195 +#define FOV_DEFINE_OCTANT(signx, signy, rx, ry, nx, ny, nf) \
196 196 static void fov_octant_##nx##ny##nf( \
197 197 fov_private_data_type *data, \
198 198 int dx, \
199 199 float start_slope, \
200   - float end_slope) { \
  200 + float end_slope, \
  201 + bool apply_edge, \
  202 + bool apply_diag) { \
201 203 int x, y, dy, dy0, dy1; \
202 204 unsigned h; \
203 205 int prev_blocked = -1; \
... ... @@ -205,7 +207,7 @@ static float fov_slope(float dx, float dy) {
205 207 fov_settings_type *settings = data->settings; \
206 208 \
207 209 if (dx == 0) { \
208   - fov_octant_##nx##ny##nf(data, dx+1, start_slope, end_slope); \
  210 + fov_octant_##nx##ny##nf(data, dx+1, start_slope, end_slope, apply_edge, apply_diag); \
209 211 return; \
210 212 } else if ((unsigned)dx > data->radius) { \
211 213 return; \
... ... @@ -220,6 +222,14 @@ static float fov_slope(float dx, float dy) {
220 222 if (!apply_diag && dy1 == dx) { \
221 223 /* We do diagonal lines on every second octant, so they don't get done twice. */ \
222 224 --dy1; \
  225 + \
  226 + /* But, we still need to check if we can see past it if the slopes are similar */ \
  227 + if (dy1 < dy0) { \
  228 + if (settings->opaque(data->map, x, y)) { \
  229 + return; \
  230 + } \
  231 + prev_blocked = 0; \
  232 + } \
223 233 } \
224 234 \
225 235 switch (settings->shape) { \
... ... @@ -256,7 +266,7 @@ static float fov_slope(float dx, float dy) {
256 266 } \
257 267 if (prev_blocked == 0) { \
258 268 end_slope_next = fov_slope((float)dx + 0.5f, (float)dy - 0.5f); \
259   - fov_octant_##nx##ny##nf(data, dx+1, start_slope, end_slope_next); \
  269 + fov_octant_##nx##ny##nf(data, dx+1, start_slope, end_slope_next, apply_edge, apply_diag); \
260 270 } \
261 271 prev_blocked = 1; \
262 272 } else { \
... ... @@ -271,18 +281,18 @@ static float fov_slope(float dx, float dy) {
271 281 } \
272 282 \
273 283 if (prev_blocked == 0) { \
274   - fov_octant_##nx##ny##nf(data, dx+1, start_slope, end_slope); \
  284 + fov_octant_##nx##ny##nf(data, dx+1, start_slope, end_slope, apply_edge, apply_diag); \
275 285 } \
276 286 }
277 287
278   -FOV_DEFINE_OCTANT(+,+,x,y,p,p,n,true,true)
279   -FOV_DEFINE_OCTANT(+,+,y,x,p,p,y,true,false)
280   -FOV_DEFINE_OCTANT(+,-,x,y,p,m,n,false,true)
281   -FOV_DEFINE_OCTANT(+,-,y,x,p,m,y,false,false)
282   -FOV_DEFINE_OCTANT(-,+,x,y,m,p,n,true,true)
283   -FOV_DEFINE_OCTANT(-,+,y,x,m,p,y,true,false)
284   -FOV_DEFINE_OCTANT(-,-,x,y,m,m,n,false,true)
285   -FOV_DEFINE_OCTANT(-,-,y,x,m,m,y,false,false)
  288 +FOV_DEFINE_OCTANT(+,+,x,y,p,p,n)
  289 +FOV_DEFINE_OCTANT(+,+,y,x,p,p,y)
  290 +FOV_DEFINE_OCTANT(+,-,x,y,p,m,n)
  291 +FOV_DEFINE_OCTANT(+,-,y,x,p,m,y)
  292 +FOV_DEFINE_OCTANT(-,+,x,y,m,p,n)
  293 +FOV_DEFINE_OCTANT(-,+,y,x,m,p,y)
  294 +FOV_DEFINE_OCTANT(-,-,x,y,m,m,n)
  295 +FOV_DEFINE_OCTANT(-,-,y,x,m,m,y)
286 296
287 297
288 298 /* Circle --------------------------------------------------------- */
... ... @@ -304,14 +314,14 @@ static void _fov_circle(fov_private_data_type *data) {
304 314 * / | \
305 315 * /mmy|mpy\
306 316 */
307   - fov_octant_ppn(data, 1, (float)0.0f, (float)1.0f);
308   - fov_octant_ppy(data, 1, (float)0.0f, (float)1.0f);
309   - fov_octant_pmn(data, 1, (float)0.0f, (float)1.0f);
310   - fov_octant_pmy(data, 1, (float)0.0f, (float)1.0f);
311   - fov_octant_mpn(data, 1, (float)0.0f, (float)1.0f);
312   - fov_octant_mpy(data, 1, (float)0.0f, (float)1.0f);
313   - fov_octant_mmn(data, 1, (float)0.0f, (float)1.0f);
314   - fov_octant_mmy(data, 1, (float)0.0f, (float)1.0f);
  317 + fov_octant_ppn(data, 1, (float)0.0f, (float)1.0f, true, true);
  318 + fov_octant_ppy(data, 1, (float)0.0f, (float)1.0f, true, false);
  319 + fov_octant_pmy(data, 1, (float)0.0f, (float)1.0f, false, true);
  320 + fov_octant_mpn(data, 1, (float)0.0f, (float)1.0f, true, false);
  321 + fov_octant_mmn(data, 1, (float)0.0f, (float)1.0f, false, true);
  322 + fov_octant_mmy(data, 1, (float)0.0f, (float)1.0f, true, false);
  323 + fov_octant_mpy(data, 1, (float)0.0f, (float)1.0f, false, true);
  324 + fov_octant_pmn(data, 1, (float)0.0f, (float)1.0f, false, false);
315 325 }
316 326
317 327 void fov_circle(fov_settings_type *settings,
... ... @@ -345,48 +355,48 @@ static float betweenf(float x, float a, float b) {
345 355 }
346 356 }
347 357
348   -#define BEAM_DIRECTION(d, p1, p2, p3, p4, p5, p6, p7, p8) \
349   - if (direction == d) { \
350   - end_slope = betweenf(a, 0.0f, 1.0f); \
351   - fov_octant_##p1(&data, 1, 0.0f, end_slope); \
352   - fov_octant_##p2(&data, 1, 0.0f, end_slope); \
353   - if (a - 1.0f > FLT_EPSILON) { /* a > 1.0f */ \
354   - start_slope = betweenf(2.0f - a, 0.0f, 1.0f); \
355   - fov_octant_##p3(&data, 1, start_slope, 1.0f); \
356   - fov_octant_##p4(&data, 1, start_slope, 1.0f); \
357   - } \
358   - if (a - 2.0f > FLT_EPSILON) { /* a > 2.0f */ \
359   - end_slope = betweenf(a - 2.0f, 0.0f, 1.0f); \
360   - fov_octant_##p5(&data, 1, 0.0f, end_slope); \
361   - fov_octant_##p6(&data, 1, 0.0f, end_slope); \
362   - } \
363   - if (a - 3.0f > FLT_EPSILON) { /* a > 3.0f */ \
364   - start_slope = betweenf(4.0f - a, 0.0f, 1.0f); \
365   - fov_octant_##p7(&data, 1, start_slope, 1.0f); \
366   - fov_octant_##p8(&data, 1, start_slope, 1.0f); \
367   - } \
  358 +#define BEAM_DIRECTION(d, p1, p2, p3, p4, p5, p6, p7, p8) \
  359 + if (direction == d) { \
  360 + end_slope = betweenf(a, 0.0f, 1.0f); \
  361 + fov_octant_##p1(&data, 1, 0.0f, end_slope, true, true); \
  362 + fov_octant_##p2(&data, 1, 0.0f, end_slope, false, true); \
  363 + if (a - 1.0f > FLT_EPSILON) { /* a > 1.0f */ \
  364 + start_slope = betweenf(2.0f - a, 0.0f, 1.0f); \
  365 + fov_octant_##p3(&data, 1, start_slope, 1.0f, true, false); \
  366 + fov_octant_##p4(&data, 1, start_slope, 1.0f, true, false); \
  367 + } \
  368 + if (a - 2.0f > FLT_EPSILON) { /* a > 2.0f */ \
  369 + end_slope = betweenf(a - 2.0f, 0.0f, 1.0f); \
  370 + fov_octant_##p5(&data, 1, 0.0f, end_slope, false, true); \
  371 + fov_octant_##p6(&data, 1, 0.0f, end_slope, false, true); \
  372 + } \
  373 + if (a - 3.0f > FLT_EPSILON) { /* a > 3.0f */ \
  374 + start_slope = betweenf(4.0f - a, 0.0f, 1.0f); \
  375 + fov_octant_##p7(&data, 1, start_slope, 1.0f, true, false); \
  376 + fov_octant_##p8(&data, 1, start_slope, 1.0f, false, false); \
  377 + } \
368 378 }
369 379
370   -#define BEAM_DIRECTION_DIAG(d, p1, p2, p3, p4, p5, p6, p7, p8) \
371   - if (direction == d) { \
372   - start_slope = betweenf(1.0f - a, 0.0f, 1.0f); \
373   - fov_octant_##p1(&data, 1, start_slope, 1.0f); \
374   - fov_octant_##p2(&data, 1, start_slope, 1.0f); \
375   - if (a - 1.0f > FLT_EPSILON) { /* a > 1.0f */ \
376   - end_slope = betweenf(a - 1.0f, 0.0f, 1.0f); \
377   - fov_octant_##p3(&data, 1, 0.0f, end_slope); \
378   - fov_octant_##p4(&data, 1, 0.0f, end_slope); \
379   - } \
380   - if (a - 2.0f > FLT_EPSILON) { /* a > 2.0f */ \
381   - start_slope = betweenf(3.0f - a, 0.0f, 1.0f); \
382   - fov_octant_##p5(&data, 1, start_slope, 1.0f); \
383   - fov_octant_##p6(&data, 1, start_slope, 1.0f); \
384   - } \
385   - if (a - 3.0f > FLT_EPSILON) { /* a > 3.0f */ \
386   - end_slope = betweenf(a - 3.0f, 0.0f, 1.0f); \
387   - fov_octant_##p7(&data, 1, 0.0f, end_slope); \
388   - fov_octant_##p8(&data, 1, 0.0f, end_slope); \
389   - } \
  380 +#define BEAM_DIRECTION_DIAG(d, p1, p2, p3, p4, p5, p6, p7, p8) \
  381 + if (direction == d) { \
  382 + start_slope = betweenf(1.0f - a, 0.0f, 1.0f); \
  383 + fov_octant_##p1(&data, 1, start_slope, 1.0f, true, true); \
  384 + fov_octant_##p2(&data, 1, start_slope, 1.0f, true, false); \
  385 + if (a - 1.0f > FLT_EPSILON) { /* a > 1.0f */ \
  386 + end_slope = betweenf(a - 1.0f, 0.0f, 1.0f); \
  387 + fov_octant_##p3(&data, 1, 0.0f, end_slope, false, true); \
  388 + fov_octant_##p4(&data, 1, 0.0f, end_slope, false, true); \
  389 + } \
  390 + if (a - 2.0f > FLT_EPSILON) { /* a > 2.0f */ \
  391 + start_slope = betweenf(3.0f - a, 0.0f, 1.0f); \
  392 + fov_octant_##p5(&data, 1, start_slope, 1.0f, true, false); \
  393 + fov_octant_##p6(&data, 1, start_slope, 1.0f, true, false); \
  394 + } \
  395 + if (a - 3.0f > FLT_EPSILON) { /* a > 3.0f */ \
  396 + end_slope = betweenf(a - 3.0f, 0.0f, 1.0f); \
  397 + fov_octant_##p7(&data, 1, 0.0f, end_slope, false, true); \
  398 + fov_octant_##p8(&data, 1, 0.0f, end_slope, false, false); \
  399 + } \
390 400 }
391 401
392 402 void fov_beam(fov_settings_type *settings, void *map, void *source,
... ... @@ -418,10 +428,10 @@ void fov_beam(fov_settings_type *settings, void *map, void *source,
418 428
419 429 BEAM_DIRECTION(FOV_EAST, ppn, pmn, ppy, mpy, pmy, mmy, mpn, mmn);
420 430 BEAM_DIRECTION(FOV_WEST, mpn, mmn, pmy, mmy, ppy, mpy, ppn, pmn);
421   - BEAM_DIRECTION(FOV_NORTH, mpy, mmy, mmn, pmn, mpn, ppn, pmy, ppy);
  431 + BEAM_DIRECTION(FOV_NORTH, mpy, mmy, pmn, mmn, ppn, mpn, ppy, pmy);
422 432 BEAM_DIRECTION(FOV_SOUTH, pmy, ppy, mpn, ppn, mmn, pmn, mmy, mpy);
423   - BEAM_DIRECTION_DIAG(FOV_NORTHEAST, pmn, mpy, mmy, ppn, mmn, ppy, mpn, pmy);
  433 + BEAM_DIRECTION_DIAG(FOV_NORTHEAST, pmn, mpy, ppn, mmy, ppy, mmn, pmy, mpn);
424 434 BEAM_DIRECTION_DIAG(FOV_NORTHWEST, mmn, mmy, mpn, mpy, pmy, pmn, ppy, ppn);
425   - BEAM_DIRECTION_DIAG(FOV_SOUTHEAST, ppn, ppy, pmy, pmn, mpn, mpy, mmn, mmy);
  435 + BEAM_DIRECTION_DIAG(FOV_SOUTHEAST, ppy, ppn, pmy, pmn, mpn, mpy, mmn, mmy);
426 436 BEAM_DIRECTION_DIAG(FOV_SOUTHWEST, pmy, mpn, ppy, mmn, ppn, mmy, pmn, mpy);
427 437 }
... ...