Remove pointless s_pow and s_sqrt functions and use hypot instead of sqrt for distance calculations
This commit is contained in:
@@ -350,25 +350,25 @@ void save_outdoor_maps() {
|
||||
if(univ.out.out_e[i][j] > 0)
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y)][i / 8][j] =
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y)][i / 8][j] |
|
||||
(char) (s_pow(2,i % 8));
|
||||
(char) (1 << i % 8);
|
||||
if(univ.party.outdoor_corner.x + 1 < univ.scenario.outdoors.width()) {
|
||||
if(univ.out.out_e[i + 48][j] > 0)
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x + 1,univ.party.outdoor_corner.y)][i / 8][j] =
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x + 1,univ.party.outdoor_corner.y)][i / 8][j] |
|
||||
(char) (s_pow(2,i % 8));
|
||||
(char) (1 << i % 8);
|
||||
}
|
||||
if(univ.party.outdoor_corner.y + 1 < univ.scenario.outdoors.height()) {
|
||||
if(univ.out.out_e[i][j + 48] > 0)
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y + 1)][i / 8][j] =
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y + 1)][i / 8][j] |
|
||||
(char) (s_pow(2,i % 8));
|
||||
(char) (1 << i % 8);
|
||||
}
|
||||
if((univ.party.outdoor_corner.y + 1 < univ.scenario.outdoors.height()) &&
|
||||
(univ.party.outdoor_corner.x + 1 < univ.scenario.outdoors.width())) {
|
||||
if(univ.out.out_e[i + 48][j + 48] > 0)
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x + 1,univ.party.outdoor_corner.y + 1)][i / 8][j] =
|
||||
univ.out_maps[onm(univ.party.outdoor_corner.x + 1,univ.party.outdoor_corner.y + 1)][i / 8][j] |
|
||||
(char) (s_pow(2,i % 8));
|
||||
(char) (1 << i % 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,25 +380,25 @@ void add_outdoor_maps() { // This takes the existing outdoor map info and supple
|
||||
for(j = 0; j < 48; j++) {
|
||||
if((univ.out.out_e[i][j] == 0) &&
|
||||
((univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y)][i / 8][j] &
|
||||
(char) (s_pow(2,i % 8))) != 0))
|
||||
(char) (1 << i % 8)) != 0))
|
||||
univ.out.out_e[i][j] = 1;
|
||||
if(univ.party.outdoor_corner.x + 1 < univ.scenario.outdoors.width()) {
|
||||
if((univ.out.out_e[i + 48][j] == 0) &&
|
||||
((univ.out_maps[onm(univ.party.outdoor_corner.x + 1,univ.party.outdoor_corner.y)][i / 8][j] &
|
||||
(char) (s_pow(2,i % 8))) != 0))
|
||||
(char) (1 << i % 8)) != 0))
|
||||
univ.out.out_e[i + 48][j] = 1;
|
||||
}
|
||||
if(univ.party.outdoor_corner.y + 1 < univ.scenario.outdoors.height()) {
|
||||
if((univ.out.out_e[i][j + 48] == 0) &&
|
||||
((univ.out_maps[onm(univ.party.outdoor_corner.x,univ.party.outdoor_corner.y + 1)][i / 8][j] &
|
||||
(char) (s_pow(2,i % 8))) != 0))
|
||||
(char) (1 << i % 8)) != 0))
|
||||
univ.out.out_e[i][j + 48] = 1;
|
||||
}
|
||||
if((univ.party.outdoor_corner.y + 1 < univ.scenario.outdoors.height()) &&
|
||||
(univ.party.outdoor_corner.x + 1 < univ.scenario.outdoors.width())) {
|
||||
if((univ.out.out_e[i + 48][j + 48] == 0) &&
|
||||
((univ.out_maps[onm(univ.party.outdoor_corner.x + 1,univ.party.outdoor_corner.y + 1)][i / 8][j] &
|
||||
(char) (s_pow(2,i % 8))) != 0))
|
||||
(char) (1 << i % 8)) != 0))
|
||||
univ.out.out_e[i + 48][j + 48] = 1;
|
||||
}
|
||||
}
|
||||
|
@@ -307,7 +307,7 @@ void set_item_flag(cItem* item) {
|
||||
if((item->is_special > 0) && (item->is_special < 65)) {
|
||||
item->is_special--;
|
||||
univ.party.item_taken[univ.town.num][item->is_special / 8] =
|
||||
univ.party.item_taken[univ.town.num][item->is_special / 8] | s_pow(2,item->is_special % 8);
|
||||
univ.party.item_taken[univ.town.num][item->is_special / 8] | (1 << item->is_special % 8);
|
||||
item->is_special = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -491,7 +491,7 @@ bool pt_in_light(location from_where,location to_where) { // Assumes, of course,
|
||||
if((to_where.x < 0) || (to_where.x >= univ.town->max_dim())
|
||||
|| (to_where.y < 0) || (to_where.y >= univ.town->max_dim()))
|
||||
return true;
|
||||
if(univ.town->lighting(to_where.x / 8,to_where.y) & (char) (s_pow(2,to_where.x % 8)))
|
||||
if(univ.town->lighting(to_where.x / 8,to_where.y) & (char) (1 << to_where.x % 8))
|
||||
return true;
|
||||
|
||||
if(dist(from_where,to_where) <= light_radius())
|
||||
@@ -508,7 +508,7 @@ bool combat_pt_in_light(location to_where) {
|
||||
if((to_where.x < 0) || (to_where.x >= univ.town->max_dim())
|
||||
|| (to_where.y < 0) || (to_where.y >= univ.town->max_dim()))
|
||||
return true;
|
||||
if(univ.town->lighting(to_where.x / 8,to_where.y) & (char) (s_pow(2,to_where.x % 8)))
|
||||
if(univ.town->lighting(to_where.x / 8,to_where.y) & (char) (1 << to_where.x % 8))
|
||||
return true;
|
||||
|
||||
rad = light_radius();
|
||||
|
@@ -161,7 +161,7 @@ void start_town_mode(short which_town, short entry_dir) {
|
||||
// Set up map, using stored map
|
||||
for(i = 0; i < univ.town->max_dim(); i++)
|
||||
for(j = 0; j < univ.town->max_dim(); j++) {
|
||||
if(univ.town_maps[univ.town.num][i / 8][j] & (char)(s_pow(2,i % 8)))
|
||||
if(univ.town_maps[univ.town.num][i / 8][j] & (char)(1 << i % 8))
|
||||
make_explored(i,j);
|
||||
|
||||
if(univ.town->terrain(i,j) == 0)
|
||||
@@ -406,7 +406,7 @@ void start_town_mode(short which_town, short entry_dir) {
|
||||
|
||||
for(i = 0; i < univ.town->preset_items.size(); i++)
|
||||
if((univ.town->preset_items[i].code >= 0)
|
||||
&& (((univ.party.item_taken[univ.town.num][i / 8] & s_pow(2,i % 8)) == 0) ||
|
||||
&& (((univ.party.item_taken[univ.town.num][i / 8] & (1 << i % 8)) == 0) ||
|
||||
(univ.town->preset_items[i].always_there))) {
|
||||
j = univ.town.items.size();
|
||||
// place the preset item, if party hasn't gotten it already
|
||||
@@ -603,7 +603,7 @@ location end_town_mode(short switching_level,location destination) { // returns
|
||||
for(j = 0; j < univ.town->max_dim(); j++)
|
||||
if(is_explored(i,j)) {
|
||||
univ.town_maps[univ.town.num][i / 8][j] = univ.town_maps[univ.town.num][i / 8][j] |
|
||||
(char) (s_pow(2,i % 8));
|
||||
(char) (1 << i % 8);
|
||||
}
|
||||
|
||||
to_return = univ.party.p_loc;
|
||||
|
@@ -20,7 +20,7 @@ bool operator != (location p1,location p2){
|
||||
}
|
||||
|
||||
short dist(location p1,location p2){
|
||||
return s_sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
|
||||
return hypot(p1.x - p2.x, p1.y - p2.y);
|
||||
}
|
||||
|
||||
short vdist(location p1,location p2) {
|
||||
|
@@ -349,7 +349,7 @@ void cThreeChoice::init_strings(std::vector<std::string>& strings, unsigned shor
|
||||
for(unsigned int i = 0; i < strings.size(); i++)
|
||||
total_len += string_length(strings[i], style);
|
||||
total_len = total_len * 12;
|
||||
str_width = s_sqrt(total_len) + 20;
|
||||
str_width = sqrt(total_len) + 20;
|
||||
//print_nums(0,total_len,str_width);
|
||||
if(str_width < 340)
|
||||
str_width = 340;
|
||||
|
@@ -23,14 +23,6 @@ short get_ran (short times,short min,short max){
|
||||
return to_ret;
|
||||
}
|
||||
|
||||
short s_pow(short x,short y){
|
||||
return (short) pow((double) x, (double) y);
|
||||
}
|
||||
|
||||
short s_sqrt(short val) {
|
||||
return (short) sqrt((double)(val));
|
||||
}
|
||||
|
||||
short max(short a,short b){
|
||||
if(a > b)
|
||||
return a;
|
||||
|
@@ -11,8 +11,6 @@
|
||||
|
||||
using std::abs;
|
||||
short get_ran (short times,short min,short max);
|
||||
short s_pow(short x,short y);
|
||||
short s_sqrt(short val);
|
||||
short max(short a,short b);
|
||||
short min(short a,short b);
|
||||
short minmax(short min,short max,short k);
|
||||
|
Reference in New Issue
Block a user