mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-21 12:52:25 +00:00
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:
parent
690d8f9155
commit
35c4867334
@ -28,6 +28,7 @@ SET(zone_sources
|
|||||||
encounter.cpp
|
encounter.cpp
|
||||||
entity.cpp
|
entity.cpp
|
||||||
exp.cpp
|
exp.cpp
|
||||||
|
fastmath.cpp
|
||||||
fearpath.cpp
|
fearpath.cpp
|
||||||
forage.cpp
|
forage.cpp
|
||||||
groups.cpp
|
groups.cpp
|
||||||
@ -158,6 +159,7 @@ SET(zone_headers
|
|||||||
entity.h
|
entity.h
|
||||||
errmsg.h
|
errmsg.h
|
||||||
event_codes.h
|
event_codes.h
|
||||||
|
fastmath.h
|
||||||
forage.h
|
forage.h
|
||||||
global_loot_manager.h
|
global_loot_manager.h
|
||||||
groups.h
|
groups.h
|
||||||
|
|||||||
@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include "worldserver.h"
|
#include "worldserver.h"
|
||||||
#include "zone.h"
|
#include "zone.h"
|
||||||
#include "lua_parser.h"
|
#include "lua_parser.h"
|
||||||
|
#include "fastmath.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -43,6 +44,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
|
|
||||||
extern QueryServ* QServ;
|
extern QueryServ* QServ;
|
||||||
extern WorldServer worldserver;
|
extern WorldServer worldserver;
|
||||||
|
extern FastMath g_Math;
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
@ -3624,9 +3626,9 @@ void Mob::CommonDamage(Mob* attacker, int &damage, const uint16 spell_id, const
|
|||||||
// update NPC stuff
|
// update NPC stuff
|
||||||
if (a->force != 0.0f) {
|
if (a->force != 0.0f) {
|
||||||
auto new_pos = glm::vec3(
|
auto new_pos = glm::vec3(
|
||||||
m_Position.x + (a->force * std::cos(a->hit_heading) + m_Delta.x),
|
m_Position.x + (a->force * g_Math.FastSin(a->hit_heading) + m_Delta.x),
|
||||||
m_Position.y + (a->force * std::sin(a->hit_heading) + m_Delta.y), m_Position.z);
|
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 &&
|
if ((!IsNPC() || position_update_melee_push_timer.Check()) && zone->zonemap &&
|
||||||
zone->zonemap->CheckLoS(
|
zone->zonemap->CheckLoS(
|
||||||
glm::vec3(m_Position),
|
glm::vec3(m_Position),
|
||||||
new_pos)) { // If we have LoS on the new loc it should be reachable.
|
new_pos)) { // If we have LoS on the new loc it should be reachable.
|
||||||
|
|||||||
32
zone/fastmath.cpp
Normal file
32
zone/fastmath.cpp
Normal 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
18
zone/fastmath.h
Normal 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 */
|
||||||
Loading…
x
Reference in New Issue
Block a user