Moved vector natives from engine to core at29896

Moved precache_generic from engine to core at30469
This commit is contained in:
Scott Ehlert 2006-06-05 07:48:54 +00:00
parent 7d3ddf502c
commit 17fb06f7bb
12 changed files with 262 additions and 163 deletions

View File

@ -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

View File

@ -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]);
int len;
char* sptemp = get_amxstring(amx, params[1], 0, len);
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);
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},

View File

@ -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)

View File

@ -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;

View File

@ -469,6 +469,9 @@
<File
RelativePath="..\vault.cpp">
</File>
<File
RelativePath="..\vector.cpp">
</File>
</Filter>
<Filter
Name="Header Files"

View File

@ -649,6 +649,10 @@
RelativePath="..\vault.cpp"
>
</File>
<File
RelativePath="..\vector.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"

200
amxmodx/vector.cpp Normal file
View 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},
};

View File

@ -97,27 +97,6 @@ static cell AMX_NATIVE_CALL halflife_time(AMX *amx, cell *params)
return amx_ftoc(fVal);
}
static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params)
{
int iEnt = params[1];
int iVelocity = params[2];
cell *vRet = MF_GetAmxAddr(amx, params[3]);
Vector vVector = Vector(0, 0, 0);
CHECK_ENTITY(iEnt);
edict_t *pEnt = INDEXENT2(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;
}
// RadiusDamage. Damages players within a certain radius. ToDo: add the
// damage messaging so players know where the damage is coming from
// (the red arrow-like things on the screen).
@ -198,61 +177,6 @@ static cell AMX_NATIVE_CALL PointContents(AMX *amx, cell *params)
return POINT_CONTENTS(vPoint);
}
static cell AMX_NATIVE_CALL vector_to_angle(AMX *amx, cell *params)
{
cell *cAddr = MF_GetAmxAddr(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 = MF_GetAmxAddr(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 vector_length(AMX *amx, cell *params)
{
cell *cAddr = MF_GetAmxAddr(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 = MF_GetAmxAddr(amx, params[1]);
cell *cAddr2 = MF_GetAmxAddr(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);
}
static cell AMX_NATIVE_CALL trace_normal(AMX *amx, cell *params)
{
int iEnt = params[1];
@ -387,14 +311,6 @@ static cell AMX_NATIVE_CALL drop_to_floor(AMX *amx, cell *params)
return DROP_TO_FLOOR(e);
}
static cell AMX_NATIVE_CALL precache_generic(AMX *amx, cell *params)
{
int len;
char* szPreCache = MF_GetAmxString(amx,params[1],0,&len);
PRECACHE_GENERIC((char*)STRING(ALLOC_STRING(szPreCache)));
return 1;
}
// Attachview, this allows you to attach a player's view to an entity.
// use AttachView(player, player) to reset view.
//(vexd)
@ -656,28 +572,6 @@ static cell AMX_NATIVE_CALL playback_event(AMX *amx, cell *params)
return 1;
}
//(mahnsawce)
static cell AMX_NATIVE_CALL angle_vector(AMX *amx, cell *params)
{
Vector v_angles,v_forward,v_right,v_up,v_return;
cell *vCell = MF_GetAmxAddr(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);
if (params[2] == ANGLEVECTORS_FORWARD)
v_return = v_forward;
if (params[2] == ANGLEVECTORS_RIGHT)
v_return = v_right;
if (params[2] == ANGLEVECTORS_UP)
v_return = v_up;
vCell = MF_GetAmxAddr(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;
}
//(mahnsawce)
static cell AMX_NATIVE_CALL get_usercmd(AMX *amx, cell *params)
{
@ -1038,13 +932,8 @@ AMX_NATIVE_INFO engine_Natives[] = {
//These are mostly from original VexD
{"velocity_by_aim", VelocityByAim},
{"radius_damage", RadiusDamage},
{"point_contents", PointContents},
{"vector_to_angle", vector_to_angle},
{"angle_vector", angle_vector},
{"vector_length", vector_length},
{"vector_distance", vector_distance},
{"trace_normal", trace_normal},
{"trace_line", trace_line},
{"trace_hull", trace_hull},
@ -1054,7 +943,6 @@ AMX_NATIVE_INFO engine_Natives[] = {
{"get_speak", get_speak},
{"precache_event", precache_event},
{"precache_generic", precache_generic},
{"playback_event", playback_event},
{"set_view", set_view},

View File

@ -48,10 +48,6 @@ extern int VexdServerForward;
#define CAMERA_UPLEFT 2
#define CAMERA_TOPDOWN 3
#define ANGLEVECTORS_FORWARD 1
#define ANGLEVECTORS_RIGHT 2
#define ANGLEVECTORS_UP 3
enum
{
usercmd_float_start,

View File

@ -19,6 +19,7 @@
#include <vault>
#include <lang>
#include <messages>
#include <vector>
/* Function is called just after server activation.
* Good place for configuration loading, commands and cvars registration. */
@ -74,6 +75,9 @@ native precache_model(const name[]);
/* Precache sound. Can be used only in plugin_precache() function.*/
native precache_sound(const name[]);
/* Precaches any file. */
native precache_generic(szFile[]);
/* Sets info for player. */
native set_user_info(index,const info[],const value[]);
@ -513,9 +517,6 @@ native server_exec();
/* Emits sound. Sample must be precached. */
native emit_sound(index, channel, sample[], Float:vol, Float:att,flags, pitch);
/* Returns distance between two vectors. */
native get_distance(origin1[3],origin2[3]);
/* Registers new cvar for HL engine.
* Returns the cvar pointer for get/set_pcvar functions.
*/
@ -809,9 +810,6 @@ native menu_setprop(menu, prop, ...);
//and the callback is invoked.
native menu_cancel(player);
// Gets distance between two origins (float)
native Float:get_distance_f( Float:Origin1[3], Float:Origin2[3] );
// Dispatches a client cvar query
// id: Player id
// cvar: cvar name

View File

@ -38,8 +38,6 @@ native register_think(Classname[], function[]);
* The module will automatically add +5 for Linux.
*/
/* Precaches any file. */
native precache_generic(szFile[]);
/* Precaches an event. */
native precache_event(type, Name[], {Float,Sql,Result,_}:...);
@ -152,17 +150,6 @@ native trace_hull(Float:origin[3],hull,ignoredent=0,ignoremonsters=0);
* Returns 0 if theres no normal. */
native trace_normal(iIgnoreEnt, Float:fStart[3], Float:fEnd[3], Float:vReturn[3]);
/* Changes a Vector to an Angle vector. */
native vector_to_angle(Float:fVector[3], Float:vReturn[3]);
native angle_vector(Float:vector[3],FRU,Float:ret[3])
/* Gets the length of a vector (float[3]). */
native Float:vector_length(Float:vVector[3]);
/* Gets the distance between 2 vectors (float[3]). */
native Float:vector_distance(Float:vVector[3], Float:vVector2[3]);
/* Gets the ID of a grenade. */
native get_grenade_id(id, model[], len, grenadeid = 0);

View File

@ -0,0 +1,34 @@
/* Vector functions (now part of Core)
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _corevector_included
#endinput
#endif
#define _corevector_included
/* Used for angle_vector() */
#define ANGLEVECTOR_FORWARD 1
#define ANGLEVECTOR_RIGHT 2
#define ANGLEVECTOR_UP 3
/* Returns distance between two vectors. */
native get_distance(origin1[3],origin2[3]);
/* Gets distance between two origins (float). */
native Float:get_distance_f(Float:Origin1[3], Float:Origin2[3]);
/* Changes a vector into an angle vector. */
native vector_to_angle(Float:fVector[3], Float:vReturn[3]);
/* Changes an angle vector into a vector. */
native angle_vector(Float:vector[3], FRU, Float:ret[3]);
/* Gets the length of a vector (float[3]). */
native Float:vector_length(Float:vVector[3]);
/* Gets the distance between 2 vectors (float[3]). */
native Float:vector_distance(Float:vVector[3], Float:vVector2[3]);