Add the Fast trig functions that work with EQ headings

This should match pretty close to the clients LUTs

Also fixed a bug with push
This commit is contained in:
Michael Cook (mackal) 2018-03-04 02:19:12 -05:00
parent 690d8f9155
commit 35c4867334
4 changed files with 57 additions and 3 deletions

View File

@ -28,6 +28,7 @@ SET(zone_sources
encounter.cpp
entity.cpp
exp.cpp
fastmath.cpp
fearpath.cpp
forage.cpp
groups.cpp
@ -158,6 +159,7 @@ SET(zone_headers
entity.h
errmsg.h
event_codes.h
fastmath.h
forage.h
global_loot_manager.h
groups.h

View File

@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "worldserver.h"
#include "zone.h"
#include "lua_parser.h"
#include "fastmath.h"
#include <assert.h>
#include <stdio.h>
@ -43,6 +44,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
extern QueryServ* QServ;
extern WorldServer worldserver;
extern FastMath g_Math;
#ifdef _WINDOWS
#define snprintf _snprintf
@ -3624,9 +3626,9 @@ void Mob::CommonDamage(Mob* attacker, int &damage, const uint16 spell_id, const
// update NPC stuff
if (a->force != 0.0f) {
auto new_pos = glm::vec3(
m_Position.x + (a->force * std::cos(a->hit_heading) + m_Delta.x),
m_Position.y + (a->force * std::sin(a->hit_heading) + m_Delta.y), m_Position.z);
if ((IsNPC() && position_update_melee_push_timer.Check()) && zone->zonemap &&
m_Position.x + (a->force * g_Math.FastSin(a->hit_heading) + m_Delta.x),
m_Position.y + (a->force * g_Math.FastCos(a->hit_heading) + m_Delta.y), m_Position.z);
if ((!IsNPC() || position_update_melee_push_timer.Check()) && zone->zonemap &&
zone->zonemap->CheckLoS(
glm::vec3(m_Position),
new_pos)) { // If we have LoS on the new loc it should be reachable.

32
zone/fastmath.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <cmath>
#include "fastmath.h"
FastMath g_Math;
// This should match EQ's sin/cos LUTs
// Some values didn't match on linux, but they were the "same" float :P
FastMath::FastMath()
{
int ci = 0;
int si = 128;
float res;
do {
res = std::cos(static_cast<float>(ci) * M_PI * 2 / 512);
lut_cos[ci] = res;
if (si == 512)
si = 0;
lut_sin[si] = res;
++ci;
++si;
} while (ci < 512);
lut_sin[0] = 0.0f;
lut_sin[128] = 1.0f;
lut_sin[256] = 0.0f;
lut_sin[384] = -1.0f;
lut_cos[0] = 1.0f;
lut_cos[128] = 0.0f;
lut_cos[384] = 0.0f;
}

18
zone/fastmath.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef FASTMATH_H
#define FASTMATH_H
class FastMath
{
private:
float lut_cos[512];
float lut_sin[512];
public:
FastMath();
inline float FastSin(float a) { return lut_sin[static_cast<int>(a) & 0x1ff]; }
inline float FastCos(float a) { return lut_cos[static_cast<int>(a) & 0x1ff]; }
};
#endif /* !FASTMATH_H */