Removed floats from table lookup

This commit is contained in:
Josh Stewart 2013-02-11 10:53:00 +11:00
parent 41d424fca6
commit 4f7d86588e
2 changed files with 15 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

15
table.h
View File

@ -2,6 +2,7 @@
This file is used for everything related to maps/tables including their definition, functions etc
*/
struct table {
//All tables must be the same size for simplicity
const static int xSize = 8;
@ -92,6 +93,8 @@ int getTableValue(struct table fromTable, int Y, int X)
//Create some normalised position values
//These are essentially percentages (between 0 and 1) of where the desired value falls between the nearest bins on each axis
/*
// Float version
float p = ((float)(X - xMinValue)) / (float)(xMaxValue - xMinValue);
float q = ((float)(Y - yMaxValue)) / (float)(yMinValue - yMaxValue);
@ -102,4 +105,16 @@ int getTableValue(struct table fromTable, int Y, int X)
return ( (A * m) + (B * n) + (C * o) + (D * r) );
*/
// Non-Float version:
int p = ((X - xMinValue) << 7) / (xMaxValue - xMinValue);
int q = ((Y - yMaxValue) << 7) / (yMinValue - yMaxValue);
int m = ((128-p) * (128-q)) >> 7;
int n = (p * (128-q)) >> 7;
int o = ((128-p) * q) >> 7;
int r = (p * q) >> 7;
return ( (A * m) + (B * n) + (C * o) + (D * r) ) >> 7;
}