16.07.2018, 20:06
Vector implementation in PAWN
Description
This is a vector data structure implementation in PAWN.Description
Project
The source code and documentation are located at GitHub: https://github.com/BigETI/pawn-vector
VECTOR_random_shuffle(Vector: vector, first, last)
{
for (new i = (last - first) - 1; i > 0; --i)
{
VECTOR_swap(vector, i, random(i + 1));
}
}
VECTOR_swap(Vector: vector, a, b)
{
new a_value = VECTOR_get_val(vector, a);
VECTOR_set_val(vector, a, VECTOR_get_val(vector, b));
VECTOR_set_val(vector, b, a_value);
}
// Example:
public OnGameModeInit()
{
new Vector: vector;
for (new i = 1; i <= 10; i++)
{
VECTOR_push_back_val(vector, i);
}
VECTOR_random_shuffle(vector, 0, VECTOR_size(vector));
VECTOR_foreach(v : vector)
{
printf("%d", MEM_get_val(v));
}
return 1;
}
enum PlayerEnum { id, Float:health, Float:armour } new PlayerData[][PlayerEnum] = { {1, 2.0, 3.0}, {4, 5.0, 6.0} }; new Vector:PlayerVector; for(new i = 0; i < sizeof(PlayerData); i += 1) { VECTOR_push_back_arr(PlayerVector, PlayerData[i]); }
warning 229: index tag mismatch (symbol "PlayerData"): expected tag none ("_"), but found "PlayerEnum"
enum _:PlayerEnum
VECTOR_push_back_arr(PlayerVector, _:PlayerData[i]);
enum PlayerEnum { id, Float:health, Float:armour } new Vector:PlayerVector[PlayerEnum]; VECTOR_push_back_val(PlayerVector[id], 0); VECTOR_push_back_val(PlayerVector[health], 0.0); VECTOR_push_back_val(PlayerVector[armour], 0.0);
warning 213: tag mismatch: expected tag "Vector", but found none ("_") warning 213: tag mismatch: expected tag "Vector", but found "Float" warning 213: tag mismatch: expected tag none ("_"), but found "Float" warning 213: tag mismatch: expected tag "Vector", but found "Float" warning 213: tag mismatch: expected tag none ("_"), but found "Float"
enum PlayerEnum { id, Float:health, Float:armour } new Vector:PlayerVector[PlayerEnum]; VECTOR_push_back_val(Vector:PlayerVector[id], 0); VECTOR_push_back_val(Vector:PlayerVector[health], _:0.0); VECTOR_push_back_val(Vector:PlayerVector[armour], _:0.0);
new Vector:PlayerVector[3]; VECTOR_push_back_val(PlayerVector[0], 0); VECTOR_push_back_val(PlayerVector[1], _:0.0); VECTOR_push_back_val(PlayerVector[2], _:0.0);