source: golgotha/src/golg/path_api.hh

Last change on this file was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.1 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#error
10
11#ifndef PATH_API_HH
12#define PATH_API_HH
13
14#include "error/error.hh"
15#include "memory/malloc.hh"
16#include "math/num_type.hh"
17#include <string.h>
18
19enum g1_compass_direction { G1_NORTH=1, G1_SOUTH=2, G1_WEST=4, G1_EAST=8 };
20
21class g1_block_map_class
22{
23protected:
24  w8 *block_map;
25  w16 wx,wy;
26  w16 bwx;
27
28  int max_fit_NS(int x, int y, g1_compass_direction dir, int max) const;
29  int max_fit_WE(int x, int y, g1_compass_direction dir, int max) const;
30
31public:
32  w16 width() const { return wx; }
33  w16 height() const { return wy; }
34
35  g1_block_map_class() : block_map(0) {}
36  g1_block_map_class(w16 _wx, w16 _wy) { init(_wy,_wy); }
37
38  void init(w16 _wx, w16 _wy)
39  {
40    wx = _wx; wy = _wy;
41    bwx = (wx+1)/2;
42    block_map = (w8 *)i4_malloc(bwx*wy, "block_map");
43    I4_ASSERT(block_map, "No block map allocated");
44  }
45
46  void uninit()
47  {
48    if (block_map)
49      i4_free(block_map);
50    block_map=0;
51  }
52
53  ~g1_block_map_class()
54  {
55    uninit();
56  }
57
58  void clear()
59  {
60    memset(block_map, 0, bwx*wy);
61  }
62
63  void block(w16 x, w16 y, w8 dir)
64  {
65    if (x&1)
66      dir <<= 4;
67    x /= 2;
68    block_map[y*bwx+x] |= dir;
69  }
70
71  void unblock(w16 x, w16 y, w8 dir)
72  {
73    if (x&1)
74      dir <<= 4;
75    x /= 2;
76    block_map[y*bwx+x] &= ~(dir);
77  }
78
79  i4_bool is_blocked(w16 x, w16 y, w8 dir) const
80  {
81    if (x&1)
82      dir <<= 4;
83    x /= 2;
84    return (block_map[y*bwx+x] & dir)!=0;
85  }
86
87  i4_float line_of_sight(i4_float x1, i4_float y1, i4_float x2, i4_float y2,
88                         i4_float rad_x=5.0, i4_float rad_y=5.0) const;
89};
90
91#endif
92
Note: See TracBrowser for help on using the repository browser.