Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/source/core/corelib/cseries/cseries_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#define NUMBEROF(_array) (sizeof(_array) / sizeof(_array[0]))
#define IN_RANGE_INCLUSIVE(value, begin, end) ((value) >= (begin) && (value) <= (end))
#define VALID_INDEX(index, count) ((index) >= 0 && (index) < (count))
#define FLAG(bit) (1 << (bit))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

/* ---------- definitions */

Expand Down
14 changes: 14 additions & 0 deletions src/source/omaha/math/matrix_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@

/* ---------- public code */

float magnitude_squared4d(union vector4d const * v)
{
mangled_ppc("?magnitude_squared4d@@YAMPBTvector4d@@@Z");

return v->i * v->i + v->j * v->j + v->k * v->k + v->l * v->l;
};

float magnitude4d(union vector4d const * v)
{
mangled_ppc("?magnitude4d@@YAMPBTvector4d@@@Z");

return square_root(magnitude_squared4d(v));
};

/* ---------- private code */

/* ---------- reverse engineering */
Expand Down
194 changes: 168 additions & 26 deletions src/source/omaha/math/periodic_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,187 @@
#define __FILE_TAG_DEBUG_UNTRACKED_JUL_11_2011__ "C:\\SD\\Reach\\Publishing\\Main\\shared\\engine\\source\\omaha\\math\\periodic_functions.cpp"
/* ---------- headers */

#include "omaha\math\periodic_functions.h"

#include "core\corelib\cseries\cseries_asserts.h"
#include "core\corelib\cseries\cseries_macros.h"

#include <stdio.h>

/* ---------- constants */

/* ---------- definitions */

/* ---------- prototypes */

extern real fabs(real x);
extern real fmod(real x, real y);
extern real real_sgn(real x);

/* ---------- globals */

/* ---------- public code */

void periodic_functions_initialize(void)
{
mangled_ppc("?periodic_functions_initialize@@YAXXZ");
};

void periodic_functions_dispose(void)
{
mangled_ppc("?periodic_functions_dispose@@YAXXZ");
};

real periodic_function_evaluate(short function_type, real time)
{
mangled_ppc("?periodic_function_evaluate@@YAMFM@Z");

real value;
real next_value;
real one_over_255;
unsigned char const* table;
real time_scale;
real fractional_time;
long integer_time;
real result;

if (function_type == _periodic_function_one)
{
result = 1.0f;
}
else
{
assert_tag_debug_untracked_jul_11_2011(216, function_type>=0 && function_type<k_periodic_functions_count);

time_scale = 36.5714302f;
time *= time_scale;

fractional_time = time - (double)(__int64)time;
assert_tag_debug_untracked_jul_11_2011(228, realcmp(fractional_time, fmod(time, 1.f)));

integer_time = (long)((time - fractional_time) + real_sgn(time - fractional_time) * 0.5f) & (NUMBEROF(periodic_function_tables[function_type]) - 1);

one_over_255 = 1.0f / 255.0f;
table = periodic_function_tables[function_type];

assert_tag_debug_untracked_jul_11_2011(237, VALID_INDEX(integer_time, NUMBEROF(periodic_function_tables[function_type])));

value = table[integer_time] * one_over_255;
next_value = table[(integer_time + 1) & (NUMBEROF(periodic_function_tables[function_type]) - 1)] * one_over_255;

if (FLAG(function_type) & (FLAG(_periodic_function_slide) | FLAG(_periodic_function_slide_variable_period)))
{
if (value > 0.75f && next_value < 0.25f)
next_value += 1.0f;

result = value * (1.0f - fractional_time) + next_value * fractional_time;

if (result > 1.0f)
result -= 1.0f;
}
else
{
result = value * (1.0f - fractional_time) + next_value * fractional_time;
}
}

return result;
};

real transition_function_evaluate(short function_type, real time)
{
mangled_ppc("?transition_function_evaluate@@YAMFM@Z");

real value;
real next_value;
real one_over_255;
unsigned char const* table;
real scaled_time;
short integer_time;
real fractional_time;
real result;

if (time < 0.0f)
time = 0.0f;
else if (time > 1.0f)
time = 1.0f;

if (function_type == _transition_function_linear)
{
result = time;
}
else
{
assert_tag_debug_untracked_jul_11_2011(275, function_type>=0 && function_type<k_transition_functions_count);

one_over_255 = 1.0f / 255.0f;
table = transition_function_tables[function_type];

scaled_time = 1023.0f * time;
fractional_time = scaled_time - (double)(__int64)scaled_time;
integer_time = (short)(long)((scaled_time - 0.1f) + real_sgn(scaled_time - 0.1f) * 0.5f);

if (integer_time == NUMBEROF(transition_function_tables[function_type]) - 1)
{
result = table[integer_time] * one_over_255;
}
else
{
value = table[integer_time] * one_over_255;
next_value = table[integer_time + 1] * one_over_255;

result = value * (1.0f - fractional_time) + next_value * fractional_time;
}

result = MIN(MAX(result, 0.0f), 1.0f);
}

return result;
};

/* ---------- private code */

void byte_table_writer(FILE* file, void const* data, long count, long stride)
{
mangled_ppc("?byte_table_writer@@YAXPAU_iobuf@@PBXJJ@Z");

long values_per_line;
unsigned char const* values;
long index;
long value_index;

values = (unsigned char const*)data;
values_per_line = 4;

fprintf(file, "{\n");

for (index = 0; index < count; index++)
{
fprintf(file, "\t{\n\t\t");

for (value_index = 0; value_index < stride; value_index++)
{
fprintf(file, "%d", *values);
values++;

if (value_index + 1 < stride)
fprintf(file, ",");

if (values_per_line - 1 == value_index % values_per_line)
fprintf(file, "\n\t\t");
}

fprintf(file, "\n\t}");

if (index + 1 < count)
fprintf(file, ",");

fprintf(file, "\n");
}

fprintf(file, "};\n");
};

/* ---------- reverse engineering */

// char const **global_periodic_functions_enum_strings; // "?global_periodic_functions_enum_strings@@3PAPBDA"
Expand All @@ -30,29 +198,3 @@
// void periodic_functions_dispose(void);
// float periodic_function_evaluate(short, float);
// float transition_function_evaluate(short, float);

//void byte_table_writer(struct _iobuf *, void const *, long, long)
//{
// mangled_ppc("?byte_table_writer@@YAXPAU_iobuf@@PBXJJ@Z");
//};

//void periodic_functions_initialize(void)
//{
// mangled_ppc("?periodic_functions_initialize@@YAXXZ");
//};

//void periodic_functions_dispose(void)
//{
// mangled_ppc("?periodic_functions_dispose@@YAXXZ");
//};

//float periodic_function_evaluate(short, float)
//{
// mangled_ppc("?periodic_function_evaluate@@YAMFM@Z");
//};

//float transition_function_evaluate(short, float)
//{
// mangled_ppc("?transition_function_evaluate@@YAMFM@Z");
//};

43 changes: 42 additions & 1 deletion src/source/omaha/math/periodic_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,56 @@

/* ---------- headers */

#include "omaha\math\real_math.h"

/* ---------- constants */

enum e_periodic_function
{
_periodic_function_one = 0,
_periodic_function_zero,
_periodic_function_cosine,
_periodic_function_cosine_variable_period,
_periodic_function_diagonal_wave,
_periodic_function_diagonal_wave_variable_period,
_periodic_function_slide,
_periodic_function_slide_variable_period,
_periodic_function_noise,
_periodic_function_jitter,
_periodic_function_wander,
_periodic_function_spark,

k_periodic_functions_count
};

enum e_transition_function
{
_transition_function_linear = 0,
_transition_function_early,
_transition_function_very_early,
_transition_function_late,
_transition_function_very_late,
_transition_function_cosine,
_transition_function_one,
_transition_function_zero,

k_transition_functions_count
};

/* ---------- definitions */

/* ---------- prototypes */

extern void periodic_functions_initialize(void);
extern void periodic_functions_dispose(void);
extern real periodic_function_evaluate(short function_type, real time);
extern real transition_function_evaluate(short function_type, real time);

/* ---------- globals */

extern unsigned char periodic_function_tables[k_periodic_functions_count][1024];
extern unsigned char transition_function_tables[k_transition_functions_count][1024];

/* ---------- public code */

#endif // __PERIODIC_FUNCTIONS_H__

Loading
Loading