Noble Ape
The Central Directories of the Noble Ape Simulation.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Macros | Functions
math.c File Reference

This covers vector math, the hash/random mathematics, (Newton) square root, the Bresenham's line algorithm, the bilinear interpolation and other abstract math that is used in Noble Ape. More...

#include "noble.h"
Include dependency graph for math.c:

Go to the source code of this file.

Data Structures

struct  math_round_smarter_struct

Macros

#define POSITIVE_TILE_COORD(num)   ((num+(3*MAP_DIMENSION))&(MAP_DIMENSION-1))
#define NUMBER_TURN_TOWARDS_POINTS   8

Functions

void vect2_byte2 (n_vect2 *converter, n_byte2 *input)
void vect2_add (n_vect2 *equals, n_vect2 *initial, n_vect2 *second)
void vect2_center (n_vect2 *center, n_vect2 *initial, n_vect2 *second)
void vect2_subtract (n_vect2 *equals, n_vect2 *initial, n_vect2 *second)
void vect2_multiplier (n_vect2 *equals, n_vect2 *initial, n_vect2 *second, n_int multiplier, n_int divisor)
void vect2_d (n_vect2 *initial, n_vect2 *second, n_int multiplier, n_int divisor)
n_int vect2_dot (n_vect2 *initial, n_vect2 *second, n_int multiplier, n_int divisor)
n_int math_sine (n_int direction, n_int divisor)
void vect2_rotate90 (n_vect2 *rotation)
void vect2_direction (n_vect2 *initial, n_int direction, n_int divisor)
void vect2_offset (n_vect2 *initial, n_int dx, n_int dy)
void vect2_back_byte2 (n_vect2 *converter, n_byte2 *output)
void vect2_copy (n_vect2 *to, n_vect2 *from)
void vect2_populate (n_vect2 *value, n_int x, n_int y)
void vect2_rotation (n_vect2 *location, n_vect2 *rotation)
n_int vect2_nonzero (n_vect2 *nonzero)
n_vect2vect2_min_max_init (void)
void vect2_min_max (n_vect2 *points, n_int number, n_vect2 *maxmin)
void math_pack (n_int size, n_byte value, n_byte *alloc1, n_byte *alloc2)
n_int math_memory_location (n_int px, n_int py)
void math_round (n_byte *local_map, n_byte *scratch, n_memory_location *mem_func)
void math_round_smarter (n_byte *local_map, n_byte *scratch, n_memory_location *mem_func)
void math_patch (n_byte *local_map, n_memory_location *mem_func, n_patch *func, n_byte2 *arg, n_int refine)
n_byte math_join (n_int sx, n_int sy, n_int dx, n_int dy, n_join *draw)
n_byte math_join_vect2 (n_int sx, n_int sy, n_vect2 *vect, n_join *draw)
n_byte math_line_vect (n_vect2 *point1, n_vect2 *point2, n_join *draw)
n_byte math_line (n_int x1, n_int y1, n_int x2, n_int y2, n_join *draw)
n_byte4 math_hash_fnv1 (n_constant_string key)
n_uint math_hash (n_byte *values, n_uint length)
n_byte math_turn_towards (n_vect2 *p, n_byte fac, n_byte turn)
n_int math_spread_byte (n_byte val)
n_byte2 math_random (n_byte2 *local)
void math_random3 (n_byte2 *local)
void math_bilinear_8_times (n_byte *side512, n_byte *data, n_byte double_spread)
n_uint math_root (n_uint input)
n_bytemath_general_allocation (n_byte *bc0, n_byte *bc1, n_int i)
void math_general_execution (n_int instruction, n_int is_constant0, n_int is_constant1, n_byte *addr0, n_byte *addr1, n_int value0, n_int *i, n_int is_const0, n_int is_const1, n_byte *pspace, n_byte **maddr0, n_byte **maddr1, n_byte *bc0, n_byte *bc1, n_int braincode_min_loop)

Detailed Description

This covers vector math, the hash/random mathematics, (Newton) square root, the Bresenham's line algorithm, the bilinear interpolation and other abstract math that is used in Noble Ape.

Definition in file math.c.


Macro Definition Documentation

#define NUMBER_TURN_TOWARDS_POINTS   8

Definition at line 745 of file math.c.

#define POSITIVE_TILE_COORD (   num)    ((num+(3*MAP_DIMENSION))&(MAP_DIMENSION-1))

Function Documentation

void math_bilinear_8_times ( n_byte side512,
n_byte data,
n_byte  double_spread 
)

Definition at line 866 of file math.c.

Here is the caller graph for this function:

n_byte* math_general_allocation ( n_byte bc0,
n_byte bc1,
n_int  i 
)

address within this being

Address within the other being

Definition at line 945 of file math.c.

Here is the caller graph for this function:

void math_general_execution ( n_int  instruction,
n_int  is_constant0,
n_int  is_constant1,
n_byte addr0,
n_byte addr1,
n_int  value0,
n_int i,
n_int  is_const0,
n_int  is_const1,
n_byte pspace,
n_byte **  maddr0,
n_byte **  maddr1,
n_byte bc0,
n_byte bc1,
n_int  braincode_min_loop 
)

Logical and

Logical or

Move a byte, with no particular alignment

Move a block of instructions

Add

Subtract

Multiply

Divide

Modulus

Count up or down

Goto

Goto if zero

Goto if not zero

Goto and decrement if not zero

If two values are equal then skip the next n instructions

If two values are not equal then skip the next n instructions

Skip the next n instructions if less than

No operation (data only)

swap

invert

Save to Pspace

Load from Pspace

Definition at line 956 of file math.c.

Here is the caller graph for this function:

n_uint math_hash ( n_byte values,
n_uint  length 
)

Creates a near-unique integer value from a block of data. This is similar to CRC or other hash methods.

Parameters:
valuesThe data in byte chunks.
lengthThe length of the data in bytes.
Returns:
The hash value produced.

Definition at line 709 of file math.c.

Here is the call graph for this function:

n_byte4 math_hash_fnv1 ( n_constant_string  key)

Definition at line 694 of file math.c.

n_byte math_join ( n_int  sx,
n_int  sy,
n_int  dx,
n_int  dy,
n_join draw 
)

This is used to produce a series of steps between two points useful for drawing a line or a line of sight test.

Parameters:
sxThe starting x location.
syThe starting y location.
dxThe distance to be traveled in the x direction.
dyThe distance to be traveled in the y direction.
drawThe generic draw function used to traverse the line points.
Returns:
This is 0 if the line draw is completed successfully and 1 if it exits through the generic draw function's request.

Definition at line 594 of file math.c.

Here is the caller graph for this function:

n_byte math_join_vect2 ( n_int  sx,
n_int  sy,
n_vect2 vect,
n_join draw 
)

Definition at line 675 of file math.c.

Here is the call graph for this function:

n_byte math_line ( n_int  x1,
n_int  y1,
n_int  x2,
n_int  y2,
n_join draw 
)

Definition at line 687 of file math.c.

Here is the call graph for this function:

n_byte math_line_vect ( n_vect2 point1,
n_vect2 point2,
n_join draw 
)

Definition at line 680 of file math.c.

Here is the call graph for this function:

n_int math_memory_location ( n_int  px,
n_int  py 
)

Definition at line 340 of file math.c.

Here is the caller graph for this function:

void math_pack ( n_int  size,
n_byte  value,
n_byte alloc1,
n_byte alloc2 
)

Definition at line 328 of file math.c.

Here is the caller graph for this function:

void math_patch ( n_byte local_map,
n_memory_location mem_func,
n_patch func,
n_byte2 arg,
n_int  refine 
)

This function creates the fractal landscapes and the genetic fur patterns currently.

Parameters:
local_mappointer to the map array
functhe n_patch function that takes the form n_byte2 (n_patch)(n_byte2 * local)
argthe pointer that is passed into the patch function
patch_bitseach side of the map is 2^patch_bits, total area is 2^(patch_bits*2)

size of the local tiles

number of 256 x 256 tiles in each dimension

begin the tile traversal in the y dimension

begin the tile traversal in the x dimension

scan through the span_minor values

each of the smaller tiles are based on 256 * 256 tiles

perform rotation on 2,3,6,7,10,11 etc

include the wrap around for the 45 degree rotation cases in particular

Definition at line 496 of file math.c.

Here is the caller graph for this function:

n_byte2 math_random ( n_byte2 local)

Generates a random number from two change-able two-byte random number values passed into the function in the form of a pointer.

Parameters:
localThe pointer leading to both the two-byte numbers used to seed (and change in the process).
Returns:
The two-byte random number produced.

Definition at line 825 of file math.c.

Here is the caller graph for this function:

void math_random3 ( n_byte2 local)

Definition at line 856 of file math.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_uint math_root ( n_uint  input)

Definition at line 922 of file math.c.

void math_round ( n_byte local_map,
n_byte scratch,
n_memory_location mem_func 
)

Perform four nearest neighbor blur runs

Definition at line 349 of file math.c.

void math_round_smarter ( n_byte local_map,
n_byte scratch,
n_memory_location mem_func 
)

Perform four nearest neighbor blur runs

Definition at line 444 of file math.c.

Here is the call graph for this function:

Here is the caller graph for this function:

n_int math_sine ( n_int  direction,
n_int  divisor 
)

This produces a sine value

Parameters:
direction256 units per rotation
divisorThe divisor for the output value
Returns:
The sine value

Definition at line 204 of file math.c.

Here is the caller graph for this function:

n_int math_spread_byte ( n_byte  val)

Definition at line 807 of file math.c.

Here is the caller graph for this function:

n_byte math_turn_towards ( n_vect2 p,
n_byte  fac,
n_byte  turn 
)

Calculates the direction location needs to turn to turn towards a vector.

Parameters:
pxThe x vector direction.
pyThe y vector direction.
facThe current direction facing.
turnThe number of facing angle units that could be turned (it may not be the number of angle units turned).
Returns:
The new direction facing value.

Definition at line 757 of file math.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void vect2_add ( n_vect2 equals,
n_vect2 initial,
n_vect2 second 
)

Adds two 2d vectors into a resultant vector.

Parameters:
equalsthe vector that holds the result.
initialthe first vector to be added.
secondthe second vector to be added.

Definition at line 88 of file math.c.

Here is the caller graph for this function:

void vect2_back_byte2 ( n_vect2 converter,
n_byte2 output 
)

Definition at line 241 of file math.c.

Here is the caller graph for this function:

void vect2_byte2 ( n_vect2 converter,
n_byte2 input 
)

Converts an array of n_byte2 to a 2d vector (n_vect2)

Parameters:
converterthe vector to hold the information.
inputthe n_byte2 that is converted to the n_vect2.

Definition at line 70 of file math.c.

Here is the caller graph for this function:

void vect2_center ( n_vect2 center,
n_vect2 initial,
n_vect2 second 
)

Definition at line 103 of file math.c.

Here is the call graph for this function:

void vect2_copy ( n_vect2 to,
n_vect2 from 
)

Definition at line 258 of file math.c.

void vect2_d ( n_vect2 initial,
n_vect2 second,
n_int  multiplier,
n_int  divisor 
)

Adds one 2d vector with another 2d vector times a multiplier divided by a divisor.

Parameters:
equalsthe vector that holds the result.
initialthe first vector that takes the summation of the second vector.
secondthe second vector to be multiplied.
multiplierthe scalar multiplier.
divisorthe the scalar divisor.

Definition at line 163 of file math.c.

Here is the caller graph for this function:

void vect2_direction ( n_vect2 initial,
n_int  direction,
n_int  divisor 
)

This produces a direction vector

Parameters:
initialThe vector output
direction256 units per rotation
divisorThe divisor for the output value

Definition at line 223 of file math.c.

Here is the caller graph for this function:

n_int vect2_dot ( n_vect2 initial,
n_vect2 second,
n_int  multiplier,
n_int  divisor 
)

This produces the dot product of two vectors with the scalar multiplier and divisor noted.

Parameters:
initialThe first vector
secondThe second vector
referenceThe specific Noble Ape checked for being awake
Returns:
The resultant scalar

Definition at line 185 of file math.c.

Here is the caller graph for this function:

void vect2_min_max ( n_vect2 points,
n_int  number,
n_vect2 maxmin 
)

Definition at line 298 of file math.c.

n_vect2* vect2_min_max_init ( void  )

Definition at line 286 of file math.c.

Here is the call graph for this function:

void vect2_multiplier ( n_vect2 equals,
n_vect2 initial,
n_vect2 second,
n_int  multiplier,
n_int  divisor 
)

Multiplies one 2d vector with another 2d vector times a multiplier divided by a divisor.

Parameters:
equalsthe vector that holds the result.
initialthe first vector.
secondthe second vector to be multiplied.
multiplierthe scalar multiplier.
divisorthe the scalar divisor.

Definition at line 138 of file math.c.

n_int vect2_nonzero ( n_vect2 nonzero)

Definition at line 281 of file math.c.

void vect2_offset ( n_vect2 initial,
n_int  dx,
n_int  dy 
)

Definition at line 231 of file math.c.

void vect2_populate ( n_vect2 value,
n_int  x,
n_int  y 
)

Definition at line 264 of file math.c.

Here is the caller graph for this function:

void vect2_rotate90 ( n_vect2 rotation)

Definition at line 210 of file math.c.

void vect2_rotation ( n_vect2 location,
n_vect2 rotation 
)

Definition at line 270 of file math.c.

void vect2_subtract ( n_vect2 equals,
n_vect2 initial,
n_vect2 second 
)

Subtracts one 2d vector from another 2d vector into a resultant vector.

Parameters:
equalsthe vector that holds the result.
initialthe first vector.
secondthe second vector to be subtracted.

Definition at line 116 of file math.c.

Here is the caller graph for this function: