Moved vector natives from engine to core at29896
Moved precache_generic from engine to core at30469
This commit is contained in:
@ -19,7 +19,7 @@ OBJECTS = meta_api.cpp CFile.cpp CVault.cpp vault.cpp float.cpp file.cpp modules
|
||||
srvcmd.cpp strptime.cpp amxcore.cpp amxtime.cpp power.cpp amxxlog.cpp fakemeta.cpp \
|
||||
amxxfile.cpp CLang.cpp md5.cpp emsg.cpp CForward.cpp CPlugin.cpp CModule.cpp \
|
||||
CMenu.cpp util.cpp amx.cpp amxdbg.cpp natives.cpp newmenus.cpp debugger.cpp \
|
||||
optimizer.cpp format.cpp messages.cpp libraries.cpp
|
||||
optimizer.cpp format.cpp messages.cpp libraries.cpp vector.cpp
|
||||
|
||||
LINK = /lib/libstdc++.a
|
||||
|
||||
|
@ -2500,8 +2500,8 @@ static cell AMX_NATIVE_CALL precache_sound(AMX *amx, cell *params) /* 1 param */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ilen;
|
||||
char* sptemp = get_amxstring(amx, params[1], 0, ilen);
|
||||
int len;
|
||||
char* sptemp = get_amxstring(amx, params[1], 0, len);
|
||||
|
||||
PRECACHE_SOUND((char*)STRING(ALLOC_STRING(sptemp)));
|
||||
|
||||
@ -2516,36 +2516,24 @@ static cell AMX_NATIVE_CALL precache_model(AMX *amx, cell *params) /* 1 param */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ilen;
|
||||
char* sptemp = get_amxstring(amx, params[1], 0, ilen);
|
||||
int len;
|
||||
char* sptemp = get_amxstring(amx, params[1], 0, len);
|
||||
|
||||
return PRECACHE_MODEL((char*)STRING(ALLOC_STRING(sptemp)));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL get_distance(AMX *amx, cell *params) /* 2 param */
|
||||
static cell AMX_NATIVE_CALL precache_generic(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cpVec1 = get_amxaddr(amx, params[1]);
|
||||
cell *cpVec2 = get_amxaddr(amx, params[2]);
|
||||
|
||||
Vector vec1 = Vector((float)cpVec1[0], (float)cpVec1[1], (float)cpVec1[2]);
|
||||
Vector vec2 = Vector((float)cpVec2[0], (float)cpVec2[1], (float)cpVec2[2]);
|
||||
|
||||
int iDist = (int)((vec1 - vec2).Length());
|
||||
|
||||
return iDist;
|
||||
}
|
||||
if (g_dontprecache)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Precaching not allowed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL get_distance_f(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cpVec1 = get_amxaddr(amx, params[1]);
|
||||
cell *cpVec2 = get_amxaddr(amx, params[2]);
|
||||
|
||||
Vector vec1 = Vector((float)amx_ctof(cpVec1[0]), (float)amx_ctof(cpVec1[1]), (float)amx_ctof(cpVec1[2]));
|
||||
Vector vec2 = Vector((float)amx_ctof(cpVec2[0]), (float)amx_ctof(cpVec2[1]), (float)amx_ctof(cpVec2[2]));
|
||||
int len;
|
||||
char* sptemp = get_amxstring(amx, params[1], 0, len);
|
||||
|
||||
REAL fDist = (REAL) (vec1 - vec2).Length();
|
||||
|
||||
return amx_ftoc(fDist);
|
||||
return PRECACHE_GENERIC((char*)STRING(ALLOC_STRING(sptemp)));
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL random_float(AMX *amx, cell *params) /* 2 param */
|
||||
@ -3986,8 +3974,6 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
|
||||
{"get_cvar_num", get_cvar_num},
|
||||
{"get_cvar_pointer", get_cvar_pointer},
|
||||
{"get_cvar_string", get_cvar_string},
|
||||
{"get_distance", get_distance},
|
||||
{"get_distance_f", get_distance_f},
|
||||
{"get_flags", get_flags},
|
||||
{"get_func_id", get_func_id},
|
||||
{"get_gametime", get_gametime},
|
||||
@ -4072,6 +4058,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
|
||||
{"plugin_flags", plugin_flags},
|
||||
{"precache_model", precache_model},
|
||||
{"precache_sound", precache_sound},
|
||||
{"precache_generic", precache_generic},
|
||||
{"query_client_cvar", query_client_cvar},
|
||||
{"random_float", random_float},
|
||||
{"random_num", random_num},
|
||||
|
@ -84,6 +84,7 @@ extern AMX_NATIVE_INFO float_Natives[];
|
||||
extern AMX_NATIVE_INFO string_Natives[];
|
||||
extern AMX_NATIVE_INFO vault_Natives[];
|
||||
extern AMX_NATIVE_INFO msg_Natives[];
|
||||
extern AMX_NATIVE_INFO vector_Natives[];
|
||||
|
||||
#ifndef __linux__
|
||||
#define DLLOAD(path) (DLHANDLE)LoadLibrary(path)
|
||||
|
@ -542,6 +542,7 @@ int set_amxnatives(AMX* amx, char error[128])
|
||||
amx_Register(amx, g_NativeNatives, -1);
|
||||
amx_Register(amx, g_DebugNatives, -1);
|
||||
amx_Register(amx, msg_Natives, -1);
|
||||
amx_Register(amx, vector_Natives, -1);
|
||||
|
||||
//we're not actually gonna check these here anymore
|
||||
amx->flags |= AMX_FLAG_PRENIT;
|
||||
|
@ -469,6 +469,9 @@
|
||||
<File
|
||||
RelativePath="..\vault.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\vector.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
@ -649,6 +649,10 @@
|
||||
RelativePath="..\vault.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\vector.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
200
amxmodx/vector.cpp
Normal file
200
amxmodx/vector.cpp
Normal file
@ -0,0 +1,200 @@
|
||||
/* AMX Mod X
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
* originally developed by OLO
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
|
||||
#include "amxmodx.h"
|
||||
|
||||
#define ANGLEVECTORS_FORWARD 1
|
||||
#define ANGLEVECTORS_RIGHT 2
|
||||
#define ANGLEVECTORS_UP 3
|
||||
|
||||
static cell AMX_NATIVE_CALL get_distance(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cpVec1 = get_amxaddr(amx, params[1]);
|
||||
cell *cpVec2 = get_amxaddr(amx, params[2]);
|
||||
|
||||
Vector vec1 = Vector((float)cpVec1[0], (float)cpVec1[1], (float)cpVec1[2]);
|
||||
Vector vec2 = Vector((float)cpVec2[0], (float)cpVec2[1], (float)cpVec2[2]);
|
||||
|
||||
int iDist = (int)((vec1 - vec2).Length());
|
||||
|
||||
return iDist;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL get_distance_f(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cpVec1 = get_amxaddr(amx, params[1]);
|
||||
cell *cpVec2 = get_amxaddr(amx, params[2]);
|
||||
|
||||
Vector vec1 = Vector((float)amx_ctof(cpVec1[0]), (float)amx_ctof(cpVec1[1]), (float)amx_ctof(cpVec1[2]));
|
||||
Vector vec2 = Vector((float)amx_ctof(cpVec2[0]), (float)amx_ctof(cpVec2[1]), (float)amx_ctof(cpVec2[2]));
|
||||
|
||||
REAL fDist = (REAL) (vec1 - vec2).Length();
|
||||
|
||||
return amx_ftoc(fDist);
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params)
|
||||
{
|
||||
int iEnt = params[1];
|
||||
int iVelocity = params[2];
|
||||
cell *vRet = get_amxaddr(amx, params[3]);
|
||||
Vector vVector = Vector(0, 0, 0);
|
||||
|
||||
if (iEnt < 0 || iEnt > gpGlobals->maxEntities)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", iEnt);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iEnt <= gpGlobals->maxClients && !GET_PLAYER_POINTER_I(iEnt)->ingame)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", iEnt);
|
||||
return 0;
|
||||
}
|
||||
else if (iEnt != 0 && FNullEnt(INDEXENT(iEnt)))
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", iEnt);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
edict_t *pEnt;
|
||||
|
||||
if (iEnt >= 1 || iEnt <= gpGlobals->maxClients)
|
||||
pEnt = GET_PLAYER_POINTER_I(iEnt)->pEdict;
|
||||
else
|
||||
pEnt = INDEXENT(iEnt);
|
||||
|
||||
MAKE_VECTORS(pEnt->v.v_angle);
|
||||
vVector = gpGlobals->v_forward * iVelocity;
|
||||
|
||||
vRet[0] = amx_ftoc(vVector.x);
|
||||
vRet[1] = amx_ftoc(vVector.y);
|
||||
vRet[2] = amx_ftoc(vVector.z);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL vector_to_angle(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cAddr = get_amxaddr(amx, params[1]);
|
||||
|
||||
REAL fX = amx_ctof(cAddr[0]);
|
||||
REAL fY = amx_ctof(cAddr[1]);
|
||||
REAL fZ = amx_ctof(cAddr[2]);
|
||||
|
||||
Vector vVector = Vector(fX, fY, fZ);
|
||||
Vector vAngle = Vector(0, 0, 0);
|
||||
VEC_TO_ANGLES(vVector, vAngle);
|
||||
|
||||
cell *vRet = get_amxaddr(amx, params[2]);
|
||||
vRet[0] = amx_ftoc(vAngle.x);
|
||||
vRet[1] = amx_ftoc(vAngle.y);
|
||||
vRet[2] = amx_ftoc(vAngle.z);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL angle_vector(AMX *amx, cell *params)
|
||||
{
|
||||
Vector v_angles, v_forward, v_right, v_up, v_return;
|
||||
|
||||
cell *vCell = get_amxaddr(amx, params[1]);
|
||||
v_angles.x = amx_ctof(vCell[0]);
|
||||
v_angles.y = amx_ctof(vCell[1]);
|
||||
v_angles.z = amx_ctof(vCell[2]);
|
||||
|
||||
g_engfuncs.pfnAngleVectors(v_angles, v_forward, v_right, v_up);
|
||||
|
||||
switch (params[2])
|
||||
{
|
||||
case ANGLEVECTORS_FORWARD:
|
||||
v_return = v_forward;
|
||||
case ANGLEVECTORS_RIGHT:
|
||||
v_return = v_right;
|
||||
case ANGLEVECTORS_UP:
|
||||
v_return = v_up;
|
||||
}
|
||||
|
||||
vCell = get_amxaddr(amx,params[3]);
|
||||
vCell[0] = amx_ftoc(v_return.x);
|
||||
vCell[1] = amx_ftoc(v_return.y);
|
||||
vCell[2] = amx_ftoc(v_return.z);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL vector_length(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cAddr = get_amxaddr(amx, params[1]);
|
||||
|
||||
REAL fX = amx_ctof(cAddr[0]);
|
||||
REAL fY = amx_ctof(cAddr[1]);
|
||||
REAL fZ = amx_ctof(cAddr[2]);
|
||||
|
||||
Vector vVector = Vector(fX, fY, fZ);
|
||||
|
||||
REAL fLength = vVector.Length();
|
||||
|
||||
return amx_ftoc(fLength);
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL vector_distance(AMX *amx, cell *params)
|
||||
{
|
||||
cell *cAddr = get_amxaddr(amx, params[1]);
|
||||
cell *cAddr2 = get_amxaddr(amx, params[2]);
|
||||
|
||||
REAL fX = amx_ctof(cAddr[0]);
|
||||
REAL fY = amx_ctof(cAddr[1]);
|
||||
REAL fZ = amx_ctof(cAddr[2]);
|
||||
REAL fX2 = amx_ctof(cAddr2[0]);
|
||||
REAL fY2 = amx_ctof(cAddr2[1]);
|
||||
REAL fZ2 = amx_ctof(cAddr2[2]);
|
||||
|
||||
Vector vVector = Vector(fX, fY, fZ);
|
||||
Vector vVector2 = Vector(fX2, fY2, fZ2);
|
||||
|
||||
REAL fLength = (vVector - vVector2).Length();
|
||||
|
||||
return amx_ftoc(fLength);
|
||||
}
|
||||
|
||||
AMX_NATIVE_INFO vector_Natives[] = {
|
||||
{"get_distance", get_distance},
|
||||
{"get_distance_f", get_distance_f},
|
||||
{"velocity_by_aim", VelocityByAim},
|
||||
{"vector_to_angle", vector_to_angle},
|
||||
{"angle_vector", angle_vector},
|
||||
{"vector_length", vector_length},
|
||||
{"vector_distance", vector_distance},
|
||||
{NULL, NULL},
|
||||
};
|
Reference in New Issue
Block a user