First net version
This commit is contained in:
parent
6e765193ce
commit
b0afc45a23
@ -169,6 +169,7 @@
|
||||
<ClCompile Include="..\math\plane.cpp" />
|
||||
<ClCompile Include="..\math\weighted_set.cpp" />
|
||||
<ClCompile Include="..\navdata.cpp" />
|
||||
<ClCompile Include="..\net\udp_client.cpp" />
|
||||
<ClCompile Include="..\opensteer\src\Clock.cpp" />
|
||||
<ClCompile Include="..\opensteer\src\Vec3.cpp" />
|
||||
<ClCompile Include="..\read_cmp.cpp" />
|
||||
@ -239,6 +240,7 @@
|
||||
<ClInclude Include="..\math\vector.hpp" />
|
||||
<ClInclude Include="..\math\weighted_set.h" />
|
||||
<ClInclude Include="..\navdata.h" />
|
||||
<ClInclude Include="..\net\udp_client.h" />
|
||||
<ClInclude Include="..\opengta.h" />
|
||||
<ClInclude Include="..\read_ini.h" />
|
||||
<ClInclude Include="..\replaceLoki\Singleton.h" />
|
||||
|
@ -28,6 +28,9 @@
|
||||
<Filter Include="Source Files\opensteer">
|
||||
<UniqueIdentifier>{b411155d-6ed1-42eb-b97b-2236cdffc485}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\net">
|
||||
<UniqueIdentifier>{d3f70488-602d-4579-81fd-180426fd4fad}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\read_ini.cpp">
|
||||
@ -207,6 +210,9 @@
|
||||
<ClCompile Include="frgbridge.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\net\udp_client.cpp">
|
||||
<Filter>Source Files\net</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\read_ini.h">
|
||||
@ -407,6 +413,9 @@
|
||||
<ClInclude Include="..\replaceLoki\Singleton.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\net\udp_client.h">
|
||||
<Filter>Source Files\net</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\Doxyfile">
|
||||
|
11
ai.cpp
11
ai.cpp
@ -13,22 +13,23 @@ namespace OpenGTA {
|
||||
namespace Pedestrian {
|
||||
void walk_pavement(OpenGTA::Pedestrian* ped) {
|
||||
assert(ped);
|
||||
Util::CellIterator ci(ped->pos);
|
||||
Util::CellIterator ci(ped->pos());
|
||||
if (!ci.isValid())
|
||||
return;
|
||||
OpenGTA::Map::BlockInfo & bi = ci.getBlock();
|
||||
//INFO << " ped in bt: " << int(bi.blockType()) << std::endl;
|
||||
//INFO << ped->pos.x << " " << ped->pos.z << std::endl;
|
||||
std::pair<bool, Util::CellIterator> f = ci.findNeighbourWithType(3, ped->rot);
|
||||
std::pair<bool, Util::CellIterator> f = ci.findNeighbourWithType(3, ped->rot());
|
||||
if (f.first) {
|
||||
//INFO << "next: " << f.second.x << " " << f.second.y << std::endl;
|
||||
ped->aiData.pos1 = Vector3D(f.second.x+0.5f, ped->pos.y, f.second.y+0.5f);
|
||||
ped->aiData.pos1 = Vector3D(f.second.x+0.5f, ped->pos().y, f.second.y+0.5f);
|
||||
ped->aiMode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void moveto_shortrange(OpenGTA::Pedestrian *ped) {
|
||||
assert(ped);
|
||||
|
||||
/* assert(ped);
|
||||
float d = Util::distance(ped->pos, ped->aiData.pos1);
|
||||
//INFO << "dist: " << d << std::endl;
|
||||
float a = Util::xz_turn_angle(ped->pos, ped->aiData.pos1);
|
||||
@ -64,7 +65,7 @@ namespace OpenGTA {
|
||||
{
|
||||
OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).getInCar();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
440
entity_controller.cpp
Normal file → Executable file
440
entity_controller.cpp
Normal file → Executable file
@ -20,11 +20,451 @@
|
||||
* 3. This notice may not be removed or altered from any source *
|
||||
* distribution. *
|
||||
************************************************************************/
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
|
||||
#include "entity_controller.h"
|
||||
#include "log.h"
|
||||
#include "m_exceptions.h"
|
||||
|
||||
#include "opengta.h"
|
||||
#include "dataholder.h"
|
||||
|
||||
|
||||
float slope_height_offset(unsigned char slope_type, float dx, float dz);
|
||||
|
||||
namespace OpenGTA {
|
||||
|
||||
float heightOverTerrain(Eigen::Vector3f v) {
|
||||
float x, y, z;
|
||||
x = floor(v.x());
|
||||
y = floor(v.y());
|
||||
z = floor(v.z());
|
||||
PHYSFS_uint8 x_b, z_b;
|
||||
x_b = (PHYSFS_uint8)x;
|
||||
z_b = (PHYSFS_uint8)z;
|
||||
if (y < 0.0f) {
|
||||
//ERROR << "Below level! at coords: " << v.x << ", " << v.y << ", " << v.z << std::endl;
|
||||
return 1.0f;
|
||||
}
|
||||
if (x < 0 || x > 255 || z < 0 || z > 255) {
|
||||
//ERROR << "x = " << x << "(" << v.x << ") z = " << z << " (" << v.z << ")" << std::endl;
|
||||
throw E_OUTOFRANGE("invalid x/z pos");
|
||||
}
|
||||
if (y > 20) {
|
||||
INFO << y << " seems a bit high; going to 20" << std::endl;
|
||||
INFO << x << " " << z << std::endl;
|
||||
y = 20;
|
||||
}
|
||||
OpenGTA::Map & map = OpenGTA::MapHolder::Instance().get();
|
||||
while (y >= map.getNumBlocksAtNew(x_b, z_b) && y > 0.0f)
|
||||
y -= 1.0f;
|
||||
while (y < map.getNumBlocksAtNew(x_b, z_b) && y > 0.0f) {
|
||||
OpenGTA::Map::BlockInfo * block = map.getBlockAtNew(x_b, z_b, (PHYSFS_uint8)y);
|
||||
assert(block);
|
||||
if (block->blockType() > 0) {
|
||||
float bz = slope_height_offset(block->slopeType(), v.x() - x, v.z() - z);
|
||||
if (block->slopeType() == 0 && (block->blockType() != 5 &&
|
||||
block->blockType() != 6))
|
||||
bz -= 1.0f;
|
||||
//INFO << "hit " << int(block->blockType()) << " at " << int(y) << std::endl;
|
||||
return v.y() - (y + bz);
|
||||
}
|
||||
y -= 1.0f;
|
||||
}
|
||||
y = floor(v.y()) + 1.0f;
|
||||
while (y < map.getNumBlocksAtNew(x_b, z_b) && y > 0.0f) {
|
||||
OpenGTA::Map::BlockInfo * block = map.getBlockAtNew(x_b, z_b, (PHYSFS_uint8)y);
|
||||
assert(block);
|
||||
if (block->blockType() > 0) {
|
||||
float bz = slope_height_offset(block->slopeType(), v.x() - x, v.z() - z);
|
||||
if (block->slopeType() == 0 && (block->blockType() != 5
|
||||
&& block->blockType() != 6))
|
||||
bz -= 1.0f;
|
||||
//INFO << "hit " << int(block->blockType()) << " at " << int(y) << std::endl;
|
||||
return v.y() - (y + bz);
|
||||
}
|
||||
y += 1.0f;
|
||||
}
|
||||
INFO << "should this be reached?" << std::endl;
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
|
||||
PlayerPedController::PlayerPedController()
|
||||
{
|
||||
pos = Eigen::Vector3f{ 12.0f, 6.1f, 12.0f };
|
||||
}
|
||||
|
||||
void PlayerPedController::setMoveForward()
|
||||
{
|
||||
pressedButtons = pressedButtons | 0b00000001;
|
||||
}
|
||||
|
||||
|
||||
void PlayerPedController::setMoveBack()
|
||||
{
|
||||
pressedButtons = pressedButtons | 0b00000010;
|
||||
}
|
||||
|
||||
void PlayerPedController::setTurnLeft()
|
||||
{
|
||||
pressedButtons = pressedButtons | 0b00000100;
|
||||
}
|
||||
|
||||
void PlayerPedController::setTurnRight()
|
||||
{
|
||||
pressedButtons = pressedButtons | 0b00001000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PlayerPedController::releaseMoveForward()
|
||||
{
|
||||
pressedButtons = pressedButtons & 0b11111110;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void PlayerPedController::releaseMoveBack()
|
||||
{
|
||||
pressedButtons = pressedButtons & 0b11111101;
|
||||
}
|
||||
|
||||
void PlayerPedController::releaseTurnLeft()
|
||||
{
|
||||
pressedButtons = pressedButtons & 0b1111011;
|
||||
}
|
||||
|
||||
|
||||
void PlayerPedController::releaseTurnRight()
|
||||
{
|
||||
pressedButtons = pressedButtons & 0b11110111;
|
||||
}
|
||||
|
||||
|
||||
bool PlayerPedController::isMoveForward()
|
||||
{
|
||||
return (pressedButtons & 0b00000001) > 0;
|
||||
}
|
||||
bool PlayerPedController::isMoveBack()
|
||||
{
|
||||
return (pressedButtons & 0b00000010) > 0;
|
||||
}
|
||||
bool PlayerPedController::isTurnLeft()
|
||||
{
|
||||
return (pressedButtons & 0b00000100) > 0;
|
||||
}
|
||||
bool PlayerPedController::isTurnRight()
|
||||
{
|
||||
return (pressedButtons & 0b00001000) > 0;
|
||||
}
|
||||
|
||||
|
||||
int PlayerPedController::getMove()
|
||||
{
|
||||
if (isMoveForward() && isMoveBack())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (isMoveForward())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (isMoveBack())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool PlayerPedController::getRunning()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PlayerPedController::getTurn()
|
||||
{
|
||||
|
||||
if (isTurnLeft() && isTurnRight())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (isTurnLeft())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (isTurnRight())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PlayerPedController::updatePos(uint32_t delta)
|
||||
{
|
||||
|
||||
static const float CONST_ROTATE_VELOCITY = 0.2f;
|
||||
static const float CONST_MOVE_VELOCITY = 0.001f;
|
||||
|
||||
Eigen::Vector3f moveDelta{ 0, 0, 0 };
|
||||
|
||||
|
||||
switch (getTurn()) {
|
||||
case -1:
|
||||
rot -= CONST_ROTATE_VELOCITY * delta;
|
||||
break;
|
||||
case 1:
|
||||
rot += CONST_ROTATE_VELOCITY * delta;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
if (rot >= 360.0f)
|
||||
{
|
||||
rot -= 360.0f;
|
||||
}
|
||||
if (rot < 0.0f)
|
||||
{
|
||||
rot += 360.0f;
|
||||
}
|
||||
|
||||
|
||||
switch (getMove()) {
|
||||
case -1:
|
||||
moveDelta(0) -= sin(rot * M_PI / 180.0f) * CONST_MOVE_VELOCITY * delta;
|
||||
moveDelta(2) -= cos(rot * M_PI / 180.0f) * CONST_MOVE_VELOCITY * delta;
|
||||
break;
|
||||
case 1:
|
||||
moveDelta(0) += sin(rot * M_PI / 180.0f) * CONST_MOVE_VELOCITY * delta;
|
||||
moveDelta(2) += cos(rot * M_PI / 180.0f) * CONST_MOVE_VELOCITY * delta;
|
||||
break;
|
||||
case 2:
|
||||
moveDelta(0) += sin(rot * M_PI / 180.0f) * CONST_MOVE_VELOCITY * delta;
|
||||
moveDelta(2) += cos(rot * M_PI / 180.0f) * CONST_MOVE_VELOCITY * delta;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
|
||||
auto newPos = pos + moveDelta;
|
||||
|
||||
int inGroundContact = checkInGroundContact(newPos);
|
||||
if (inGroundContact)
|
||||
{
|
||||
tryMove(newPos);
|
||||
}
|
||||
|
||||
if (!inGroundContact) {
|
||||
speedForces(1) += 0.0005f *delta;
|
||||
pos(1) -= speedForces(1);
|
||||
if (speedForces(1) < 0.2f)
|
||||
{
|
||||
INFO << "bridge step? height: " << pos.y() << " speed: " << speedForces.y() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
INFO << "FALLING " << pos.y() << " speed " << speedForces.y() << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (speedForces(1) > 0.1)
|
||||
{
|
||||
INFO << "impacting with speed: " << speedForces.y() << std::endl;
|
||||
}
|
||||
speedForces(1) = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
int PlayerPedController::checkInGroundContact(Eigen::Vector3f nPos)
|
||||
{
|
||||
int inGroundContact;
|
||||
|
||||
float hot = heightOverTerrain(nPos);
|
||||
if (hot > 0.3f)
|
||||
inGroundContact = 0;
|
||||
else if (hot < 0.0) {
|
||||
WARN << "gone below: " << hot << " at " << nPos.x() << ", " << nPos.y() << ", " << nPos.z() << std::endl;
|
||||
nPos(1) -= (hot - 0.3f);
|
||||
//nPos.y += 1;
|
||||
//INFO << nPos.y << std::endl;
|
||||
inGroundContact = 1;
|
||||
}
|
||||
else {
|
||||
inGroundContact = 1;
|
||||
nPos(1) -= hot - 0.1f;
|
||||
}
|
||||
|
||||
return inGroundContact;
|
||||
}
|
||||
|
||||
void PlayerPedController::tryMove(Eigen::Vector3f nPos) {
|
||||
float x, y, z;
|
||||
x = floor(nPos.x());
|
||||
y = floor(nPos.y());
|
||||
z = floor(nPos.z());
|
||||
|
||||
|
||||
OpenGTA::Map & map = OpenGTA::MapHolder::Instance().get();
|
||||
OpenGTA::GraphicsBase & graphics = OpenGTA::StyleHolder::Instance().get();
|
||||
|
||||
|
||||
|
||||
if (y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z)) && y > 0.0f) {
|
||||
OpenGTA::Map::BlockInfo * block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
assert(block);
|
||||
if (block->left && graphics.isBlockingSide(block->left)) {
|
||||
if (block->isFlat()) {
|
||||
if (x - pos.x() < 0 && x - pos.x() > -0.2f) {
|
||||
nPos(0) = (nPos.x() < pos.x()) ? pos.x() : nPos.x();
|
||||
}
|
||||
else if (x - pos.x() > 0 && x - pos.x() < 0.2f)
|
||||
nPos(0) = pos.x();
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock left: " << x - pos.x() << " tex: " << int(block->left) << std::endl;
|
||||
#endif
|
||||
if (x - pos.x() > 0 && x - pos.x() < 0.2f)
|
||||
nPos(0) = pos.x();
|
||||
else if (x - pos.x() < 0 && x - pos.x() > -0.2f)
|
||||
nPos(0) = (nPos.x() < pos.x()) ? pos.x() : nPos.x();
|
||||
}
|
||||
}
|
||||
if (block->right && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock right: " << pos.x() - x - 1 << " tex: " << int(block->right) << std::endl;
|
||||
#endif
|
||||
if (pos.x() - x - 1 > 0 && pos.x() - x - 1 < 0.2f) {
|
||||
nPos(0) = pos.x();
|
||||
}
|
||||
else if (pos.x() - x - 1 < 0 && pos.x() - x - 1 > -0.2f)
|
||||
nPos(0) = (nPos.x() > pos.x()) ? pos.x() : nPos.x();
|
||||
}
|
||||
if (block->top && graphics.isBlockingSide(block->top)) {
|
||||
if (block->isFlat()) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z - pos.z() << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (z - pos.z() > 0 && z - pos.z() < 0.2f)
|
||||
nPos(2) = pos.z();
|
||||
else if (z - pos.z() < 0 && z - pos.z() > -0.2f)
|
||||
nPos(2) = (nPos.z() < pos.z()) ? pos.z() : nPos.z();
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z - pos.z() << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (z - pos.z() > 0 && z - pos.z() < 0.2f)
|
||||
nPos(2) = pos.z();
|
||||
else if (z - pos.z() < 0 && z - pos.z() > -0.2f)
|
||||
nPos(2) = (nPos.z() < pos.z()) ? pos.z() : nPos.z();
|
||||
}
|
||||
}
|
||||
if (block->bottom && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock bottom: " << pos.z() - z - 1 << " tex: " << int(block->bottom) << std::endl;
|
||||
#endif
|
||||
if (pos.z() - z - 1 > 0 && pos.z() - z - 1 < 0.2f) {
|
||||
nPos(2) = pos.z();
|
||||
}
|
||||
else if (pos.z() - z - 1 < 0 && pos.z() - z - 1 > -0.2f)
|
||||
nPos(2) = (nPos.z() > pos.z()) ? pos.z() : nPos.z();
|
||||
}
|
||||
if (x >= 1 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x - 1), PHYSFS_uint8(z))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x - 1), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
if (block->right && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock right: " << pos.x() - x << " tex: " << int(block->right) << std::endl;
|
||||
#endif
|
||||
if (pos.x() - x < 0.2f) {
|
||||
nPos(0) = (nPos.x() < pos.x() ? pos.x() : nPos.x());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x < 255 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x + 1), PHYSFS_uint8(z))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x + 1), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
if (block->left && graphics.isBlockingSide(block->left)) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock left: " << x + 1 - pos.x() << " tex: " << int(block->left) << std::endl;
|
||||
#endif
|
||||
if (block->isFlat()) {
|
||||
if (x + 1 - pos.x() > 0 && x + 1 - pos.x() < 0.2f)
|
||||
nPos(0) = (nPos.x() < pos.x() ? nPos.x() : pos.x());
|
||||
}
|
||||
else {
|
||||
if (x + 1 - pos.x() < 0.2f)
|
||||
nPos(0) = (nPos.x() < pos.x() ? nPos.x() : pos.x());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (z >= 1 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z - 1))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z - 1), PHYSFS_uint8(y));
|
||||
if (block->bottom && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock bottom: " << pos.z() - z << " tex: " << int(block->bottom) << std::endl;
|
||||
#endif
|
||||
if (pos.z() - z < 0.2f) {
|
||||
nPos(2) = (nPos.z() < pos.z() ? pos.z() : nPos.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (z < 255 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z + 1))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z + 1), PHYSFS_uint8(y));
|
||||
if (block->top && graphics.isBlockingSide(block->top)) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z + 1 - pos.z() << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (block->isFlat()) {
|
||||
if (z + 1 - pos.z() > 0 && z + 1 - pos.z() < 0.2f)
|
||||
nPos(2) = (nPos.z() < pos.z() ? nPos.z() : pos.z());
|
||||
}
|
||||
else {
|
||||
if (z + 1 - pos.z() < 0.2f)
|
||||
nPos(2) = (nPos.z() < pos.z() ? nPos.z() : pos.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (inGroundContact)
|
||||
// pos = nPos;
|
||||
}
|
||||
|
||||
|
||||
bool obj_blocked = false;
|
||||
|
||||
/*
|
||||
std::list<Car> & list = SpriteManagerHolder::Instance().getList<Car>();
|
||||
for (std::list<Car>::iterator i = list.begin(); i != list.end(); i++) {
|
||||
if (isBoxInBox(*i)) {
|
||||
if (Util::distance(pos(), i->pos()) > Util::distance(nPos, i->pos()))
|
||||
obj_blocked = true;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (obj_blocked == false)
|
||||
{
|
||||
pos = nPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EntityController::EntityController() :
|
||||
rawData(0),
|
||||
dataSet(sizeof(rawData) * 8, (unsigned char*)&rawData) {}
|
||||
|
73
entity_controller.h
Normal file → Executable file
73
entity_controller.h
Normal file → Executable file
@ -25,8 +25,81 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "set.h"
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
namespace OpenGTA {
|
||||
|
||||
|
||||
class PositionController {
|
||||
public:
|
||||
Eigen::Vector3f pos{ 0.f, 0.f, 0.f };
|
||||
|
||||
float rot = 0;
|
||||
|
||||
virtual ~PositionController() {}
|
||||
|
||||
virtual int getMove()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual bool getRunning()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int getTurn()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void updatePos(uint32_t delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class PlayerPedController : public PositionController {
|
||||
public:
|
||||
|
||||
uint8_t pressedButtons = 0;
|
||||
|
||||
|
||||
Eigen::Vector3f speedForces{ 0.f, 0.f, 0.f }; //only local, not from server
|
||||
|
||||
PlayerPedController();
|
||||
|
||||
void setMoveForward();
|
||||
void setMoveBack();
|
||||
void setTurnLeft();
|
||||
void setTurnRight();
|
||||
|
||||
void releaseMoveForward();
|
||||
void releaseMoveBack();
|
||||
void releaseTurnLeft();
|
||||
void releaseTurnRight();
|
||||
|
||||
bool isMoveForward();
|
||||
bool isMoveBack();
|
||||
bool isTurnLeft();
|
||||
bool isTurnRight();
|
||||
|
||||
virtual int getMove();
|
||||
virtual bool getRunning();
|
||||
virtual int getTurn();
|
||||
|
||||
virtual void updatePos(uint32_t delta);
|
||||
int checkInGroundContact(Eigen::Vector3f nPos);
|
||||
void tryMove(Eigen::Vector3f nPos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class EntityController {
|
||||
public:
|
||||
EntityController();
|
||||
|
477
game_objects.cpp
477
game_objects.cpp
@ -32,6 +32,7 @@
|
||||
#include "log.h"
|
||||
|
||||
#include "gl_camera.h"
|
||||
#include "net/udp_client.h"
|
||||
|
||||
#define INT2FLOAT_WRLD(c) (float(c >> 6) + float(c % 64) / 64.0f)
|
||||
#define INT2F_DIV64(v) (float(v) / 64.0f)
|
||||
@ -142,16 +143,17 @@ namespace OpenGTA {
|
||||
|
||||
uint32_t Pedestrian::fistAmmo = 0;
|
||||
|
||||
Pedestrian::Pedestrian(Vector3D e, const Vector3D & p, uint32_t id, Sint16 remapId) :
|
||||
GameObject_common(p),
|
||||
Pedestrian::Pedestrian(Vector3D e, const Vector3D & p, uint32_t id, Sint16 remapId, PlayerPedController& newPlayerController) :
|
||||
GameObject_common(newPlayerController),
|
||||
Sprite(0, remapId, GraphicsBase::SpriteNumbers::PED),
|
||||
OBox(TranslateMatrix3D(p), e * 0.5f),
|
||||
m_control(),
|
||||
playerController(newPlayerController),
|
||||
speedForces(0, 0, 0),
|
||||
inventory(), activeWeapon(0), activeAmmo(&fistAmmo),
|
||||
aiData() {
|
||||
aiData()
|
||||
{
|
||||
m_M = TranslateMatrix3D(p);
|
||||
m_M.RotZ(-rot);
|
||||
m_M.RotZ(-rot());
|
||||
pedId = id;
|
||||
animId = 0;
|
||||
isDead = 0;
|
||||
@ -161,9 +163,8 @@ namespace OpenGTA {
|
||||
|
||||
Pedestrian::Pedestrian(const Pedestrian & other) :
|
||||
GameObject_common(other), Sprite(other), OBox(other),
|
||||
|
||||
pedId(other.pedId),
|
||||
m_control(),
|
||||
playerController(other.playerController),
|
||||
speedForces(other.speedForces),
|
||||
inventory(other.inventory),
|
||||
activeWeapon(other.activeWeapon),
|
||||
@ -174,11 +175,10 @@ namespace OpenGTA {
|
||||
inGroundContact = other.inGroundContact;
|
||||
animId = other.animId;
|
||||
isDead = other.isDead;
|
||||
m_M = TranslateMatrix3D(other.pos);
|
||||
m_M.RotZ(-other.rot);
|
||||
m_M = TranslateMatrix3D(other.pos());
|
||||
m_M.RotZ(-other.rot());
|
||||
}
|
||||
|
||||
extern void ai_step_fake(Pedestrian*);
|
||||
void Pedestrian::update(Uint32 ticks) {
|
||||
if (isDead) {
|
||||
anim.update(ticks);
|
||||
@ -187,12 +187,17 @@ namespace OpenGTA {
|
||||
}
|
||||
|
||||
|
||||
if (pedId < 0xffffffff)
|
||||
ai_step_fake(this);
|
||||
//if (pedId < 0xffffffff)
|
||||
//ai_step_fake(this);
|
||||
|
||||
|
||||
|
||||
//AI::Pedestrian::walk_pavement(this);
|
||||
|
||||
|
||||
//Xperimental -- Vladislav Khorev vladislav.khorev@fishrungames.com
|
||||
|
||||
/*
|
||||
if (aiMode) {
|
||||
AI::Pedestrian::moveto_shortrange(this);
|
||||
}
|
||||
@ -209,11 +214,12 @@ namespace OpenGTA {
|
||||
activeAmmo = &i->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
activeWeapon = chooseWeapon;
|
||||
switch(m_control.getMove()) {
|
||||
}*/
|
||||
|
||||
activeWeapon = 0;
|
||||
switch(playerController.getMove()) {
|
||||
case 1:
|
||||
if (m_control.getRunning()) {
|
||||
if (playerController.getRunning()) {
|
||||
if (!(animId == 3u + activeWeapon*3))
|
||||
switchToAnim(3 + activeWeapon*3);
|
||||
}
|
||||
@ -240,228 +246,23 @@ activeWeapon = chooseWeapon;
|
||||
}
|
||||
anim.update(ticks);
|
||||
Uint32 delta = ticks - lastUpdateAt;
|
||||
//INFO << "delta = " << delta << " t: " << ticks << " lt: " << lastUpdateAt << std::endl;
|
||||
moveDelta = Vector3D(0, 0, 0);
|
||||
switch(m_control.getTurn()) {
|
||||
case -1:
|
||||
rot -= 0.2f * delta;
|
||||
//INFO << "rot: "<< rot << std::endl;
|
||||
break;
|
||||
case 1:
|
||||
rot += 0.2f * delta;
|
||||
//INFO << "rot: "<< rot << std::endl;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
if (rot >= 360.0f)
|
||||
rot -= 360.0f;
|
||||
if (rot < 0.0f)
|
||||
rot += 360.0f;
|
||||
switch(m_control.getMove()) {
|
||||
case -1:
|
||||
moveDelta.x -= sin(rot * M_PI / 180.0f) * anim.moveSpeed * delta;
|
||||
moveDelta.z -= cos(rot * M_PI / 180.0f) * anim.moveSpeed * delta;
|
||||
break;
|
||||
case 1:
|
||||
moveDelta.x += sin(rot * M_PI / 180.0f) * anim.moveSpeed * delta;
|
||||
moveDelta.z += cos(rot * M_PI / 180.0f) * anim.moveSpeed * delta;
|
||||
break;
|
||||
case 2:
|
||||
moveDelta.x += sin(rot * M_PI / 180.0f) * anim.moveSpeed * delta;
|
||||
moveDelta.z += cos(rot * M_PI / 180.0f) * anim.moveSpeed * delta;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
if (pedId == 0xffffffff) {
|
||||
}
|
||||
tryMove(pos + moveDelta);
|
||||
if (!inGroundContact) {
|
||||
speedForces.y += 0.0005f *delta;
|
||||
pos.y -= speedForces.y;
|
||||
if (speedForces.y < 0.2f)
|
||||
INFO << "bridge step? height: " << pos.y << " speed: " << speedForces.y << std::endl;
|
||||
else
|
||||
INFO << "FALLING " << pos.y << " speed " << speedForces.y << std::endl;
|
||||
}
|
||||
else {
|
||||
if (speedForces.y > 0.1)
|
||||
INFO << "impacting with speed: " << speedForces.y << std::endl;
|
||||
speedForces.y = 0.0f;
|
||||
}
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M.RotZ(rot);
|
||||
if (m_control.getFireWeapon() && ticks - lastWeaponTick > 400) {
|
||||
|
||||
playerController.updatePos(delta);
|
||||
|
||||
m_M = TranslateMatrix3D(pos());
|
||||
m_M.RotZ(rot());
|
||||
/*if (m_control.getFireWeapon() && ticks - lastWeaponTick > 400) {
|
||||
Vector3D d1(
|
||||
//Vector3D(-cos(rot * M_PI/180.0f), 0, sin(rot * M_PI/180.0f)).Normalized() * 0.05f
|
||||
Vector3D(sin(rot * M_PI/180.0f), 0, cos(rot * M_PI/180.0f)).Normalized() * 0.01f
|
||||
);
|
||||
SpriteManagerHolder::Instance().createProjectile(0, rot, pos, d1, ticks, pedId);
|
||||
lastWeaponTick = ticks;
|
||||
}
|
||||
}*/
|
||||
|
||||
//INFO << pos.x << " " << pos.y << " " << pos.z << std::endl;
|
||||
lastUpdateAt = ticks;
|
||||
}
|
||||
|
||||
void Pedestrian::tryMove(Vector3D nPos) {
|
||||
float x, y, z;
|
||||
x = floor(nPos.x);
|
||||
y = floor(nPos.y);
|
||||
z = floor(nPos.z);
|
||||
OpenGTA::Map & map = OpenGTA::MapHolder::Instance().get();
|
||||
OpenGTA::GraphicsBase & graphics = OpenGTA::StyleHolder::Instance().get();
|
||||
//INFO << heightOverTerrain(nPos) << std::endl;
|
||||
float hot = heightOverTerrain(nPos);
|
||||
if (hot > 0.3f)
|
||||
inGroundContact = 0;
|
||||
else if (hot < 0.0) {
|
||||
WARN << "gone below: " << hot << " at " << nPos.x << ", " << nPos.y << ", " << nPos.z << std::endl;
|
||||
nPos.y -= (hot - 0.3f);
|
||||
//nPos.y += 1;
|
||||
//INFO << nPos.y << std::endl;
|
||||
inGroundContact = 1;
|
||||
}
|
||||
else {
|
||||
inGroundContact = 1;
|
||||
if (isDead)
|
||||
nPos.y -= hot - 0.05f;
|
||||
else
|
||||
nPos.y -= hot - 0.1f;
|
||||
}
|
||||
if (y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z)) && y > 0.0f) {
|
||||
OpenGTA::Map::BlockInfo * block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
assert(block);
|
||||
if (block->left && graphics.isBlockingSide(block->left)) {
|
||||
if (block->isFlat()) {
|
||||
if (x - pos.x < 0 && x - pos.x > -0.2f) {
|
||||
nPos.x = (nPos.x < pos.x) ? pos.x : nPos.x;
|
||||
}
|
||||
else if (x - pos.x > 0 && x - pos.x < 0.2f)
|
||||
nPos.x = pos.x;
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock left: " << x - pos.x << " tex: " << int(block->left) << std::endl;
|
||||
#endif
|
||||
if (x - pos.x > 0 && x - pos.x < 0.2f)
|
||||
nPos.x = pos.x;
|
||||
else if (x - pos.x < 0 && x - pos.x > -0.2f)
|
||||
nPos.x = (nPos.x < pos.x) ? pos.x : nPos.x;
|
||||
}
|
||||
}
|
||||
if (block->right && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock right: " << pos.x - x - 1 << " tex: " << int(block->right) << std::endl;
|
||||
#endif
|
||||
if (pos.x - x - 1 > 0 && pos.x - x - 1 < 0.2f) {
|
||||
nPos.x = pos.x;
|
||||
}
|
||||
else if (pos.x - x - 1 < 0 && pos.x - x - 1 > -0.2f)
|
||||
nPos.x = (nPos.x > pos.x) ? pos.x : nPos.x;
|
||||
}
|
||||
if (block->top && graphics.isBlockingSide(block->top)) {
|
||||
if (block->isFlat()) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z - pos.z << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (z - pos.z > 0 && z - pos.z < 0.2f)
|
||||
nPos.z = pos.z;
|
||||
else if (z - pos.z < 0 && z - pos.z > -0.2f)
|
||||
nPos.z = (nPos.z < pos.z) ? pos.z : nPos.z;
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z - pos.z << " tex: " << int(block->top)<< std::endl;
|
||||
#endif
|
||||
if (z - pos.z > 0 && z - pos.z < 0.2f)
|
||||
nPos.z = pos.z;
|
||||
else if (z - pos.z < 0 && z - pos.z > -0.2f)
|
||||
nPos.z = (nPos.z < pos.z) ? pos.z : nPos.z;
|
||||
}
|
||||
}
|
||||
if (block->bottom && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock bottom: " << pos.z - z - 1<< " tex: " << int(block->bottom)<< std::endl;
|
||||
#endif
|
||||
if (pos.z - z - 1 > 0 && pos.z - z - 1 < 0.2f) {
|
||||
nPos.z = pos.z;
|
||||
}
|
||||
else if (pos.z - z - 1 < 0 && pos.z - z - 1 > -0.2f)
|
||||
nPos.z = (nPos.z > pos.z) ? pos.z : nPos.z;
|
||||
}
|
||||
if (x >= 1 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x-1), PHYSFS_uint8(z))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x-1), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
if (block->right && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock right: " << pos.x - x << " tex: " << int(block->right)<< std::endl;
|
||||
#endif
|
||||
if (pos.x - x < 0.2f) {
|
||||
nPos.x = (nPos.x < pos.x ? pos.x : nPos.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x < 255 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x+1), PHYSFS_uint8(z))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x+1), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
if (block->left && graphics.isBlockingSide(block->left)) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock left: " << x + 1 - pos.x << " tex: " << int(block->left)<< std::endl;
|
||||
#endif
|
||||
if (block->isFlat()) {
|
||||
if (x + 1 - pos.x > 0 && x + 1 - pos.x < 0.2f)
|
||||
nPos.x = (nPos.x < pos.x ? nPos.x : pos.x);
|
||||
}
|
||||
else {
|
||||
if (x + 1 - pos.x < 0.2f)
|
||||
nPos.x = (nPos.x < pos.x ? nPos.x : pos.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (z >= 1 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z-1))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z-1), PHYSFS_uint8(y));
|
||||
if (block->bottom && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock bottom: " << pos.z - z<< " tex: " << int(block->bottom)<< std::endl;
|
||||
#endif
|
||||
if (pos.z - z < 0.2f) {
|
||||
nPos.z = (nPos.z < pos.z ? pos.z : nPos.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (z < 255 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z+1))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z+1), PHYSFS_uint8(y));
|
||||
if (block->top && graphics.isBlockingSide(block->top)) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z + 1 - pos.z<< " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (block->isFlat()) {
|
||||
if (z + 1 - pos.z > 0 && z + 1 - pos.z < 0.2f)
|
||||
nPos.z = (nPos.z < pos.z ? nPos.z : pos.z);
|
||||
}
|
||||
else {
|
||||
if (z + 1 - pos.z < 0.2f)
|
||||
nPos.z = (nPos.z < pos.z ? nPos.z : pos.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (inGroundContact)
|
||||
// pos = nPos;
|
||||
}
|
||||
bool obj_blocked = false;
|
||||
std::list<Car> & list = SpriteManagerHolder::Instance().getList<Car>();
|
||||
for (std::list<Car>::iterator i = list.begin(); i != list.end(); i++) {
|
||||
if (isBoxInBox(*i)) {
|
||||
if (Util::distance(pos, i->pos) > Util::distance(nPos, i->pos))
|
||||
obj_blocked = true;
|
||||
}
|
||||
}
|
||||
if ((inGroundContact) && (obj_blocked == false))
|
||||
pos = nPos;
|
||||
//else
|
||||
// inGroundContact = 0;
|
||||
|
||||
}
|
||||
|
||||
void Pedestrian::die() {
|
||||
INFO << "DIE!!!" << std::endl;
|
||||
@ -506,8 +307,8 @@ activeWeapon = chooseWeapon;
|
||||
OpenGTA::LocalPlayer::Instance().setCtrl(car.m_control);
|
||||
OpenGTA::SpriteManagerHolder::Instance().removePedById(0xffffffff);
|
||||
|
||||
cam.setVectors(Vector3D(car.pos.x, 10, car.pos.z), Vector3D(car.pos.x, 9.0f, car.pos.z), Vector3D(0, 0, -1));
|
||||
cam.setFollowMode(OpenGTA::SpriteManagerHolder::Instance().getCar(car.id()).pos);
|
||||
cam.setVectors(Vector3D(car.pos().x, 10, car.pos().z), Vector3D(car.pos().x, 9.0f, car.pos().z), Vector3D(0, 0, -1));
|
||||
cam.setFollowMode(OpenGTA::SpriteManagerHolder::Instance().getCar(car.id()).pos());
|
||||
cam.setCamGravity(true);
|
||||
|
||||
OpenGTA::LocalPlayer::Instance().playerCarId = car.id();
|
||||
@ -672,8 +473,8 @@ activeWeapon = chooseWeapon;
|
||||
}
|
||||
}
|
||||
|
||||
Car::Car(const Vector3D & _pos, float _rot, uint32_t id, uint8_t _type, int16_t _remap) :
|
||||
GameObject_common(_pos, _rot),
|
||||
Car::Car(const Vector3D & _pos, float _rot, uint32_t id, uint8_t _type, int16_t _remap, PositionController& positionController) :
|
||||
GameObject_common(positionController),
|
||||
CarSprite(0, -1, GraphicsBase::SpriteNumbers::CAR), OBox(),
|
||||
carInfo(*StyleHolder::Instance().get().findCarByModel(_type)) {
|
||||
type = _type;
|
||||
@ -685,8 +486,8 @@ activeWeapon = chooseWeapon;
|
||||
m_Extent = Vector3D(INT2F_DIV128(carInfo.width),
|
||||
INT2F_DIV128(carInfo.depth),
|
||||
INT2F_DIV128(carInfo.height));
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M.RotZ(-rot);
|
||||
m_M = TranslateMatrix3D(pos());
|
||||
m_M.RotZ(-rot());
|
||||
hitPoints = carInfo.damagable;
|
||||
}
|
||||
|
||||
@ -699,8 +500,8 @@ activeWeapon = chooseWeapon;
|
||||
sprType = GraphicsBase::SpriteNumbers::TRAIN;
|
||||
}
|
||||
|
||||
Car::Car(OpenGTA::Map::ObjectPosition& op, uint32_t id) :
|
||||
GameObject_common(Vector3D(INT2FLOAT_WRLD(op.x), 6.05f-INT2FLOAT_WRLD(op.z), INT2FLOAT_WRLD(op.y))),
|
||||
Car::Car(OpenGTA::Map::ObjectPosition& op, uint32_t id, PositionController& positionController) :
|
||||
GameObject_common(positionController),
|
||||
CarSprite(0, -1, GraphicsBase::SpriteNumbers::CAR), OBox(),
|
||||
carInfo(*StyleHolder::Instance().get().findCarByModel(op.type)){
|
||||
carId = id;
|
||||
@ -717,10 +518,10 @@ activeWeapon = chooseWeapon;
|
||||
m_Extent = Vector3D(INT2F_DIV128(carInfo.width),
|
||||
INT2F_DIV128(carInfo.depth) ,
|
||||
INT2F_DIV128(carInfo.height));
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M = TranslateMatrix3D(pos());
|
||||
|
||||
rot = op.rotation * 360 / 1024;
|
||||
m_M.RotZ(-rot);
|
||||
OpenGTA::updateStaticPositionController(op, positionController);
|
||||
m_M.RotZ(-rot());
|
||||
hitPoints = carInfo.damagable;
|
||||
}
|
||||
|
||||
@ -728,8 +529,8 @@ activeWeapon = chooseWeapon;
|
||||
GameObject_common(other), CarSprite(other), OBox(other),
|
||||
carInfo(*StyleHolder::Instance().get().findCarByModel(other.type)) {
|
||||
type = other.type;
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M.RotZ(-rot);
|
||||
m_M = TranslateMatrix3D(pos());
|
||||
m_M.RotZ(-rot());
|
||||
hitPoints = other.hitPoints;
|
||||
|
||||
carId = other.carId;
|
||||
@ -746,7 +547,7 @@ activeWeapon = chooseWeapon;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
static const float velocityRotateK = 100.0;
|
||||
|
||||
@ -758,18 +559,18 @@ activeWeapon = chooseWeapon;
|
||||
|
||||
switch(m_control.getTurn()) {
|
||||
case -1:
|
||||
rot -= 0.2f * delta * velocity * velocityRotateK;
|
||||
_rot -= 0.2f * delta * velocity * velocityRotateK;
|
||||
break;
|
||||
case 1:
|
||||
rot += 0.2f * delta * velocity * velocityRotateK;
|
||||
_rot += 0.2f * delta * velocity * velocityRotateK;
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
if (rot >= 360.0f)
|
||||
rot -= 360.0f;
|
||||
if (rot < 0.0f)
|
||||
rot += 360.0f;
|
||||
if (_rot >= 360.0f)
|
||||
_rot -= 360.0f;
|
||||
if (_rot < 0.0f)
|
||||
_rot += 360.0f;
|
||||
|
||||
#ifdef NDEBUG
|
||||
static const float accelerationK = 0.00004;
|
||||
@ -783,11 +584,6 @@ activeWeapon = chooseWeapon;
|
||||
switch(m_control.getMove()) {
|
||||
case -1:
|
||||
velocity -= accelerationK * delta;
|
||||
/*
|
||||
velocity += accelerationK * delta;
|
||||
velocity += -slowK * velocity;
|
||||
moveDelta.x -= sin(rot * M_PI / 180.0f) * velocity * delta;
|
||||
moveDelta.z -= cos(rot * M_PI / 180.0f) * velocity * delta;*/
|
||||
break;
|
||||
case 1:
|
||||
velocity += accelerationK * delta;
|
||||
@ -816,11 +612,11 @@ activeWeapon = chooseWeapon;
|
||||
|
||||
if (!inGroundContact) {
|
||||
gravitySpeed += 0.0005f *delta;
|
||||
pos.y -= gravitySpeed;
|
||||
pos().y -= gravitySpeed;
|
||||
if (gravitySpeed < 0.2f)
|
||||
INFO << "bridge step? height: " << pos.y << " speed: " << gravitySpeed << std::endl;
|
||||
INFO << "bridge step? height: " << pos().y << " speed: " << gravitySpeed << std::endl;
|
||||
else
|
||||
INFO << "FALLING " << pos.y << " speed " << gravitySpeed << std::endl;
|
||||
INFO << "FALLING " << pos().y << " speed " << gravitySpeed << std::endl;
|
||||
}
|
||||
else {
|
||||
if (gravitySpeed > 0.1)
|
||||
@ -848,7 +644,9 @@ activeWeapon = chooseWeapon;
|
||||
|
||||
}
|
||||
|
||||
//INFO << pos.x << " " << pos.y << " " << pos.z << std::endl;*/
|
||||
*/
|
||||
|
||||
//INFO << pos().x << " " << pos().y << " " << pos().z << std::endl;*/
|
||||
lastUpdateAt = ticks;
|
||||
}
|
||||
|
||||
@ -887,73 +685,73 @@ activeWeapon = chooseWeapon;
|
||||
assert(block);
|
||||
if (block->left && graphics.isBlockingSide(block->left)) {
|
||||
if (block->isFlat()) {
|
||||
if (x - pos.x < 0 && x - pos.x > -0.2f) {
|
||||
nPos.x = (nPos.x < pos.x) ? pos.x : nPos.x;
|
||||
if (x - pos().x < 0 && x - pos().x > -0.2f) {
|
||||
nPos.x = (nPos.x < pos().x) ? pos().x : nPos.x;
|
||||
}
|
||||
else if (x - pos.x > 0 && x - pos.x < 0.2f)
|
||||
else if (x - pos().x > 0 && x - pos().x < 0.2f)
|
||||
{
|
||||
nPos.x = pos.x;
|
||||
nPos.x = pos().x;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock left: " << x - pos.x << " tex: " << int(block->left) << std::endl;
|
||||
INFO << "xblock left: " << x - pos().x << " tex: " << int(block->left) << std::endl;
|
||||
#endif
|
||||
if (x - pos.x > 0 && x - pos.x < 0.2f)
|
||||
nPos.x = pos.x;
|
||||
else if (x - pos.x < 0 && x - pos.x > -0.2f)
|
||||
nPos.x = (nPos.x < pos.x) ? pos.x : nPos.x;
|
||||
if (x - pos().x > 0 && x - pos().x < 0.2f)
|
||||
nPos.x = pos().x;
|
||||
else if (x - pos().x < 0 && x - pos().x > -0.2f)
|
||||
nPos.x = (nPos.x < pos().x) ? pos().x : nPos.x;
|
||||
}
|
||||
}
|
||||
if (block->right && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock right: " << pos.x - x - 1 << " tex: " << int(block->right) << std::endl;
|
||||
INFO << "xblock right: " << pos().x - x - 1 << " tex: " << int(block->right) << std::endl;
|
||||
#endif
|
||||
if (pos.x - x - 1 > 0 && pos.x - x - 1 < 0.2f) {
|
||||
nPos.x = pos.x;
|
||||
if (pos().x - x - 1 > 0 && pos().x - x - 1 < 0.2f) {
|
||||
nPos.x = pos().x;
|
||||
}
|
||||
else if (pos.x - x - 1 < 0 && pos.x - x - 1 > -0.2f)
|
||||
nPos.x = (nPos.x > pos.x) ? pos.x : nPos.x;
|
||||
else if (pos().x - x - 1 < 0 && pos().x - x - 1 > -0.2f)
|
||||
nPos.x = (nPos.x > pos().x) ? pos().x : nPos.x;
|
||||
}
|
||||
if (block->top && graphics.isBlockingSide(block->top)) {
|
||||
if (block->isFlat()) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z - pos.z << " tex: " << int(block->top) << std::endl;
|
||||
INFO << "zblock top: " << z - pos().z << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (z - pos.z > 0 && z - pos.z < 0.2f)
|
||||
nPos.z = pos.z;
|
||||
else if (z - pos.z < 0 && z - pos.z > -0.2f)
|
||||
nPos.z = (nPos.z < pos.z) ? pos.z : nPos.z;
|
||||
if (z - pos().z > 0 && z - pos().z < 0.2f)
|
||||
nPos.z = pos().z;
|
||||
else if (z - pos().z < 0 && z - pos().z > -0.2f)
|
||||
nPos.z = (nPos.z < pos().z) ? pos().z : nPos.z;
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z - pos.z << " tex: " << int(block->top) << std::endl;
|
||||
INFO << "zblock top: " << z - pos().z << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (z - pos.z > 0 && z - pos.z < 0.2f)
|
||||
nPos.z = pos.z;
|
||||
else if (z - pos.z < 0 && z - pos.z > -0.2f)
|
||||
nPos.z = (nPos.z < pos.z) ? pos.z : nPos.z;
|
||||
if (z - pos().z > 0 && z - pos().z < 0.2f)
|
||||
nPos.z = pos().z;
|
||||
else if (z - pos().z < 0 && z - pos().z > -0.2f)
|
||||
nPos.z = (nPos.z < pos().z) ? pos().z : nPos.z;
|
||||
}
|
||||
}
|
||||
if (block->bottom && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock bottom: " << pos.z - z - 1 << " tex: " << int(block->bottom) << std::endl;
|
||||
INFO << "zblock bottom: " << pos().z - z - 1 << " tex: " << int(block->bottom) << std::endl;
|
||||
#endif
|
||||
if (pos.z - z - 1 > 0 && pos.z - z - 1 < 0.2f) {
|
||||
nPos.z = pos.z;
|
||||
if (pos().z - z - 1 > 0 && pos().z - z - 1 < 0.2f) {
|
||||
nPos.z = pos().z;
|
||||
}
|
||||
else if (pos.z - z - 1 < 0 && pos.z - z - 1 > -0.2f)
|
||||
nPos.z = (nPos.z > pos.z) ? pos.z : nPos.z;
|
||||
else if (pos().z - z - 1 < 0 && pos().z - z - 1 > -0.2f)
|
||||
nPos.z = (nPos.z > pos().z) ? pos().z : nPos.z;
|
||||
}
|
||||
if (x >= 1 && y < map.getNumBlocksAtNew(PHYSFS_uint8(x - 1), PHYSFS_uint8(z))) {
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x - 1), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
if (block->right && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock right: " << pos.x - x << " tex: " << int(block->right) << std::endl;
|
||||
INFO << "xblock right: " << pos().x - x << " tex: " << int(block->right) << std::endl;
|
||||
#endif
|
||||
if (pos.x - x < 0.2f) {
|
||||
nPos.x = (nPos.x < pos.x ? pos.x : nPos.x);
|
||||
if (pos().x - x < 0.2f) {
|
||||
nPos.x = (nPos.x < pos().x ? pos().x : nPos.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -961,15 +759,15 @@ activeWeapon = chooseWeapon;
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x + 1), PHYSFS_uint8(z), PHYSFS_uint8(y));
|
||||
if (block->left && graphics.isBlockingSide(block->left)) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "xblock left: " << x + 1 - pos.x << " tex: " << int(block->left) << std::endl;
|
||||
INFO << "xblock left: " << x + 1 - pos().x << " tex: " << int(block->left) << std::endl;
|
||||
#endif
|
||||
if (block->isFlat()) {
|
||||
if (x + 1 - pos.x > 0 && x + 1 - pos.x < 0.2f)
|
||||
nPos.x = (nPos.x < pos.x ? nPos.x : pos.x);
|
||||
if (x + 1 - pos().x > 0 && x + 1 - pos().x < 0.2f)
|
||||
nPos.x = (nPos.x < pos().x ? nPos.x : pos().x);
|
||||
}
|
||||
else {
|
||||
if (x + 1 - pos.x < 0.2f)
|
||||
nPos.x = (nPos.x < pos.x ? nPos.x : pos.x);
|
||||
if (x + 1 - pos().x < 0.2f)
|
||||
nPos.x = (nPos.x < pos().x ? nPos.x : pos().x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -977,10 +775,10 @@ activeWeapon = chooseWeapon;
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z - 1), PHYSFS_uint8(y));
|
||||
if (block->bottom && block->isFlat() == false) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock bottom: " << pos.z - z << " tex: " << int(block->bottom) << std::endl;
|
||||
INFO << "zblock bottom: " << pos().z - z << " tex: " << int(block->bottom) << std::endl;
|
||||
#endif
|
||||
if (pos.z - z < 0.2f) {
|
||||
nPos.z = (nPos.z < pos.z ? pos.z : nPos.z);
|
||||
if (pos().z - z < 0.2f) {
|
||||
nPos.z = (nPos.z < pos().z ? pos().z : nPos.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -988,15 +786,15 @@ activeWeapon = chooseWeapon;
|
||||
block = map.getBlockAtNew(PHYSFS_uint8(x), PHYSFS_uint8(z + 1), PHYSFS_uint8(y));
|
||||
if (block->top && graphics.isBlockingSide(block->top)) {
|
||||
#ifdef DEBUG_OLD_PED_BLOCK
|
||||
INFO << "zblock top: " << z + 1 - pos.z << " tex: " << int(block->top) << std::endl;
|
||||
INFO << "zblock top: " << z + 1 - pos().z << " tex: " << int(block->top) << std::endl;
|
||||
#endif
|
||||
if (block->isFlat()) {
|
||||
if (z + 1 - pos.z > 0 && z + 1 - pos.z < 0.2f)
|
||||
nPos.z = (nPos.z < pos.z ? nPos.z : pos.z);
|
||||
if (z + 1 - pos().z > 0 && z + 1 - pos().z < 0.2f)
|
||||
nPos.z = (nPos.z < pos().z ? nPos.z : pos().z);
|
||||
}
|
||||
else {
|
||||
if (z + 1 - pos.z < 0.2f)
|
||||
nPos.z = (nPos.z < pos.z ? nPos.z : pos.z);
|
||||
if (z + 1 - pos().z < 0.2f)
|
||||
nPos.z = (nPos.z < pos().z ? nPos.z : pos().z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1007,16 +805,16 @@ activeWeapon = chooseWeapon;
|
||||
std::list<Car> & list = SpriteManagerHolder::Instance().getList<Car>();
|
||||
for (std::list<Car>::iterator i = list.begin(); i != list.end(); i++) {
|
||||
if (isBoxInBox(*i)) {
|
||||
if (Util::distance(pos, i->pos) > Util::distance(nPos, i->pos))
|
||||
if (Util::distance(pos(), i->pos()) > Util::distance(nPos, i->pos()))
|
||||
obj_blocked = true;
|
||||
}
|
||||
}
|
||||
if (/*(inGroundContact) && */(obj_blocked == false))
|
||||
/*
|
||||
if ((obj_blocked == false))
|
||||
{
|
||||
pos = nPos;
|
||||
}
|
||||
//else
|
||||
// inGroundContact = 0;
|
||||
_pos = nPos;
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1070,7 +868,7 @@ activeWeapon = chooseWeapon;
|
||||
void Car::explode() {
|
||||
//SpriteManagerHolder::Instance().removeCar(carId);
|
||||
//return;
|
||||
Vector3D exp_pos(pos);
|
||||
Vector3D exp_pos(pos());
|
||||
exp_pos.y += 0.1f;
|
||||
SpriteManagerHolder::Instance().createExplosion(exp_pos);
|
||||
sprNum = 0;
|
||||
@ -1079,8 +877,8 @@ activeWeapon = chooseWeapon;
|
||||
delta = 0;
|
||||
}
|
||||
|
||||
SpriteObject::SpriteObject(OpenGTA::Map::ObjectPosition& op, uint32_t id) :
|
||||
GameObject_common(Vector3D(INT2FLOAT_WRLD(op.x), 6.05f-INT2FLOAT_WRLD(op.z), INT2FLOAT_WRLD(op.y))),
|
||||
SpriteObject::SpriteObject(OpenGTA::Map::ObjectPosition& op, uint32_t id, PositionController& positionController) :
|
||||
GameObject_common(positionController),
|
||||
Sprite(0, -1, GraphicsBase::SpriteNumbers::OBJECT), OBox() {
|
||||
objId = id;
|
||||
GraphicsBase & style = StyleHolder::Instance().get();
|
||||
@ -1088,25 +886,26 @@ activeWeapon = chooseWeapon;
|
||||
m_Extent = Vector3D(INT2F_DIV128(style.objectInfos[op.type]->width),
|
||||
INT2F_DIV128(style.objectInfos[op.type]->depth),
|
||||
INT2F_DIV128(style.objectInfos[op.type]->height));
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M.RotZ(-rot);
|
||||
rot = op.rotation * 360 / 1024;
|
||||
m_M = TranslateMatrix3D(pos());
|
||||
|
||||
OpenGTA::updateStaticPositionController(op, positionController);
|
||||
m_M.RotZ(-rot());
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
SpriteObject::SpriteObject(Vector3D pos, Uint16 sprNum, OpenGTA::GraphicsBase::SpriteNumbers::SpriteTypes sprT) :
|
||||
GameObject_common(pos), Sprite(sprNum, -1, sprT), OBox() {
|
||||
SpriteObject::SpriteObject(Vector3D pos, Uint16 sprNum, OpenGTA::GraphicsBase::SpriteNumbers::SpriteTypes sprT, PositionController& positionController) :
|
||||
GameObject_common(positionController), Sprite(sprNum, -1, sprT), OBox() {
|
||||
isActive = true;
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M.RotZ(-rot);
|
||||
m_M.RotZ(-rot());
|
||||
}
|
||||
|
||||
SpriteObject::SpriteObject(const SpriteObject & other) :
|
||||
GameObject_common(other), Sprite(other), OBox(other),
|
||||
|
||||
objId(other.objId) {
|
||||
m_M = TranslateMatrix3D(pos);
|
||||
m_M.RotZ(-rot);
|
||||
m_M = TranslateMatrix3D(pos());
|
||||
m_M.RotZ(-rot());
|
||||
|
||||
isActive = other.isActive;
|
||||
}
|
||||
@ -1115,8 +914,8 @@ activeWeapon = chooseWeapon;
|
||||
anim.update(ticks);
|
||||
}
|
||||
|
||||
Projectile::Projectile(unsigned char t, float r, Vector3D p, Vector3D d, uint32_t ticks, uint32_t o) :
|
||||
GameObject_common(p, r),
|
||||
Projectile::Projectile(unsigned char t, Vector3D d, uint32_t ticks, uint32_t o, PositionController& positionController) :
|
||||
GameObject_common(positionController),
|
||||
typeId(t), delta(d), endsAtTick(ticks),
|
||||
owner(o), lastUpdateAt(ticks) {
|
||||
endsAtTick = lastUpdateAt + 1000;
|
||||
@ -1132,7 +931,7 @@ activeWeapon = chooseWeapon;
|
||||
if (bi.top) {
|
||||
Math::Plane plane(Vector3D(ci.x, ci.z, ci.y), Vector3D(0, 0, -1));
|
||||
Vector3D hit_pos;
|
||||
if (plane.segmentIntersect(pos, newp, hit_pos)) {
|
||||
if (plane.segmentIntersect(pos(), newp, hit_pos)) {
|
||||
INFO << "intersect flat-t: " << hit_pos.x << " " << hit_pos.y << " " <<hit_pos.z << std::endl;
|
||||
if (hit_pos.x >= ci.x && hit_pos.x <= ci.x + 1) {
|
||||
newp = hit_pos;
|
||||
@ -1143,7 +942,7 @@ activeWeapon = chooseWeapon;
|
||||
if (bi.left) {
|
||||
Math::Plane plane(Vector3D(ci.x, ci.z, ci.y), Vector3D(-1, 0, 0));
|
||||
Vector3D hit_pos;
|
||||
if (plane.segmentIntersect(pos, newp, hit_pos)) {
|
||||
if (plane.segmentIntersect(pos(), newp, hit_pos)) {
|
||||
INFO << "intersect flat-l: " << hit_pos.x << " " << hit_pos.y << " " <<hit_pos.z << std::endl;
|
||||
if (hit_pos.z >= ci.y && hit_pos.z <= ci.y + 1) {
|
||||
newp = hit_pos;
|
||||
@ -1162,7 +961,7 @@ activeWeapon = chooseWeapon;
|
||||
if (bi.left) {
|
||||
Math::Plane plane(Vector3D(ci.x, ci.z, ci.y), Vector3D(-1, 0, 0));
|
||||
Vector3D hit_pos;
|
||||
if (plane.segmentIntersect(pos, newp, hit_pos)) {
|
||||
if (plane.segmentIntersect(pos(), newp, hit_pos)) {
|
||||
INFO << "intersect left: " << hit_pos.x << " " << hit_pos.y << " " <<hit_pos.z << std::endl;
|
||||
if (hit_pos.z >= ci.y && hit_pos.z <= ci.y + 1) {
|
||||
newp = hit_pos;
|
||||
@ -1173,7 +972,7 @@ activeWeapon = chooseWeapon;
|
||||
if (bi.right && !bi.isFlat()) {
|
||||
Math::Plane plane(Vector3D(ci.x+1, ci.z, ci.y), Vector3D(1, 0, 0));
|
||||
Vector3D hit_pos;
|
||||
if (plane.segmentIntersect(pos, newp, hit_pos)) {
|
||||
if (plane.segmentIntersect(pos(), newp, hit_pos)) {
|
||||
INFO << "intersect right: " << hit_pos.x << " " << hit_pos.y << " " <<hit_pos.z << std::endl;
|
||||
if (hit_pos.z >= ci.y && hit_pos.z <= ci.y + 1) {
|
||||
newp = hit_pos;
|
||||
@ -1184,7 +983,7 @@ activeWeapon = chooseWeapon;
|
||||
if (bi.top) {
|
||||
Math::Plane plane(Vector3D(ci.x, ci.z, ci.y), Vector3D(0, 0, -1));
|
||||
Vector3D hit_pos;
|
||||
if (plane.segmentIntersect(pos, newp, hit_pos)) {
|
||||
if (plane.segmentIntersect(pos(), newp, hit_pos)) {
|
||||
INFO << "intersect top: " << hit_pos.x << " " << hit_pos.y << " " <<hit_pos.z << std::endl;
|
||||
if (hit_pos.x >= ci.x && hit_pos.x <= ci.x + 1) {
|
||||
newp = hit_pos;
|
||||
@ -1195,7 +994,7 @@ activeWeapon = chooseWeapon;
|
||||
if (bi.bottom && !bi.isFlat()) {
|
||||
Math::Plane plane(Vector3D(ci.x, ci.z, ci.y+1), Vector3D(0, 0, 1));
|
||||
Vector3D hit_pos;
|
||||
if (plane.segmentIntersect(pos, newp, hit_pos)) {
|
||||
if (plane.segmentIntersect(pos(), newp, hit_pos)) {
|
||||
INFO << "intersect bottom: " << hit_pos.x << " " << hit_pos.y << " " <<hit_pos.z << std::endl;
|
||||
if (hit_pos.x >= ci.x && hit_pos.x <= ci.x + 1) {
|
||||
newp = hit_pos;
|
||||
@ -1209,10 +1008,11 @@ activeWeapon = chooseWeapon;
|
||||
|
||||
void Projectile::update(uint32_t ticks) {
|
||||
Uint32 dt = ticks - lastUpdateAt;
|
||||
Vector3D new_pos(pos + delta * dt);
|
||||
/*INFO << "p-m " << pos.x << " " << pos.y << " " << pos.z <<
|
||||
" to " << new_pos.x << " " << new_pos.y << " " << new_pos.z << std::endl;
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Vector3D new_pos(pos() + delta * dt);
|
||||
|
||||
std::list<Pedestrian> & list = SpriteManagerHolder::Instance().getList<Pedestrian>();
|
||||
for (std::list<Pedestrian>::iterator i = list.begin(); i != list.end(); ++i) {
|
||||
Pedestrian & ped = *i;
|
||||
@ -1221,9 +1021,9 @@ activeWeapon = chooseWeapon;
|
||||
if (ped.isDead)
|
||||
continue;
|
||||
|
||||
if (ped.isLineInBox( pos, new_pos ) ) {
|
||||
if (ped.isLineInBox( pos(), new_pos ) ) {
|
||||
Vector3D p;
|
||||
ped.lineCrossBox(pos, new_pos, p);
|
||||
ped.lineCrossBox(pos(), new_pos, p);
|
||||
float angle = Util::xz_angle(Vector3D(0,0,0), p);
|
||||
INFO << angle << std::endl;
|
||||
if (angle <= 90.0f || angle > 270.0f)
|
||||
@ -1243,10 +1043,10 @@ activeWeapon = chooseWeapon;
|
||||
for (std::list<Car>::iterator i = clist.begin(); i != clist.end(); i++) {
|
||||
Car & car = *i;
|
||||
|
||||
if (car.isLineInBox(pos, new_pos)) {
|
||||
if (car.isLineInBox(pos(), new_pos)) {
|
||||
INFO << "CAR HIT" << std::endl;
|
||||
Vector3D p;
|
||||
car.lineCrossBox(pos, new_pos, p);
|
||||
car.lineCrossBox(pos(), new_pos, p);
|
||||
car.damageAt(p, 5);
|
||||
//INFO << Util::xz_angle(Vector3D(0,0,0), p) << std::endl;
|
||||
delta = Vector3D(0, 0, 0);
|
||||
@ -1257,7 +1057,7 @@ activeWeapon = chooseWeapon;
|
||||
}
|
||||
}
|
||||
|
||||
Util::CellIterator oi(pos);
|
||||
Util::CellIterator oi(pos());
|
||||
int collided = 0;
|
||||
if (oi.isValid()) {
|
||||
Map::BlockInfo & bi = oi.getBlock();
|
||||
@ -1278,9 +1078,12 @@ activeWeapon = chooseWeapon;
|
||||
collided += testCollideBlock(ni, new_pos);
|
||||
}
|
||||
if (collided)
|
||||
{
|
||||
delta = Vector3D(0, 0, 0);
|
||||
pos = new_pos;
|
||||
}
|
||||
_pos = new_pos;
|
||||
|
||||
*/
|
||||
lastUpdateAt = ticks;
|
||||
}
|
||||
|
||||
|
@ -38,21 +38,31 @@ namespace OpenGTA {
|
||||
struct GameObject_common;
|
||||
typedef OpenSteer::AbstractTokenForProximityDatabase<GameObject_common*> ProximityToken;
|
||||
typedef OpenSteer::AbstractProximityDatabase<GameObject_common*> ProximityDatabase;
|
||||
|
||||
|
||||
|
||||
struct GameObject_common {
|
||||
Vector3D pos;
|
||||
float rot;
|
||||
float bSphereRadius;
|
||||
//uint8_t activeState;
|
||||
GameObject_common() :
|
||||
pos(0, 0, 0), rot(0), bSphereRadius(0.1f) {}
|
||||
GameObject_common(const Vector3D & p) : pos(p), rot(0) {}
|
||||
GameObject_common(const Vector3D & p, float r) : pos(p), rot(r) {}
|
||||
GameObject_common(const GameObject_common & o) :
|
||||
pos(o.pos), rot(o.rot), bSphereRadius(o.bSphereRadius) {}
|
||||
PositionController& positionController;
|
||||
|
||||
float bSphereRadius = 0.1f;
|
||||
|
||||
float rot() const { return positionController.rot; }
|
||||
|
||||
Vector3D pos() const { return Vector3D(positionController.pos(0), positionController.pos(1), positionController.pos(2)); }
|
||||
|
||||
GameObject_common() = delete;
|
||||
|
||||
GameObject_common(PositionController& newPositionController) : positionController(newPositionController) {}
|
||||
|
||||
|
||||
GameObject_common(const GameObject_common & o) = default;
|
||||
|
||||
float heightOverTerrain(const Vector3D &);
|
||||
ProximityToken* proxToken;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Sprite {
|
||||
public:
|
||||
struct Animation : public Util::Animation {
|
||||
@ -78,19 +88,23 @@ namespace OpenGTA {
|
||||
|
||||
class Pedestrian : public GameObject_common, public Sprite, public OBox {
|
||||
public:
|
||||
Pedestrian(Vector3D, const Vector3D &, uint32_t id, Sint16 remapId = -1);
|
||||
|
||||
Pedestrian(Vector3D, const Vector3D &, uint32_t id, Sint16 remapId, PlayerPedController& newPlayerController);
|
||||
Pedestrian(const Pedestrian & o);
|
||||
uint32_t pedId;
|
||||
inline uint32_t id() const { return pedId; }
|
||||
void equip(uint8_t eq_id);
|
||||
void giveItem(uint8_t id, uint32_t amount);
|
||||
PedController m_control;
|
||||
|
||||
PlayerPedController& playerController;
|
||||
//PedController m_control;
|
||||
|
||||
|
||||
void update(Uint32 ticks);
|
||||
Uint32 lastUpdateAt;
|
||||
Uint32 lastWeaponTick;
|
||||
Vector3D speedForces;
|
||||
bool inGroundContact;
|
||||
void tryMove(Vector3D nPos);
|
||||
uint8_t isDead;
|
||||
void getShot(uint32_t shooterId, uint32_t dmg, bool front = true);
|
||||
void die();
|
||||
@ -147,8 +161,8 @@ namespace OpenGTA {
|
||||
class Car : public GameObject_common, public CarSprite, public OBox {
|
||||
public:
|
||||
Car(const Car & o);
|
||||
Car(OpenGTA::Map::ObjectPosition&, uint32_t id);
|
||||
Car(const Vector3D & _pos, float _rot, uint32_t id, uint8_t _type, int16_t _remap = -1);
|
||||
Car(OpenGTA::Map::ObjectPosition&, uint32_t id, PositionController& positionController);
|
||||
Car(const Vector3D & _pos, float _rot, uint32_t id, uint8_t _type, int16_t _remap, PositionController& positionController);
|
||||
uint32_t carId;
|
||||
inline uint32_t id() const { return carId; }
|
||||
GraphicsBase::CarInfo & carInfo;
|
||||
@ -177,8 +191,8 @@ namespace OpenGTA {
|
||||
|
||||
class SpriteObject : public GameObject_common, public Sprite, public OBox {
|
||||
public:
|
||||
SpriteObject(OpenGTA::Map::ObjectPosition&, uint32_t id);
|
||||
SpriteObject(Vector3D pos, Uint16 spriteNum, GraphicsBase::SpriteNumbers::SpriteTypes st);
|
||||
SpriteObject(OpenGTA::Map::ObjectPosition&, uint32_t id, PositionController& positionController);
|
||||
SpriteObject(Vector3D pos, Uint16 spriteNum, GraphicsBase::SpriteNumbers::SpriteTypes st, PositionController& positionController);
|
||||
SpriteObject(const SpriteObject & o);
|
||||
uint32_t objId;
|
||||
inline uint32_t id() const { return objId; }
|
||||
@ -200,7 +214,7 @@ namespace OpenGTA {
|
||||
|
||||
class Projectile : public GameObject_common {
|
||||
public:
|
||||
Projectile(uint8_t, float, Vector3D, Vector3D, uint32_t, uint32_t);
|
||||
Projectile(uint8_t, Vector3D, uint32_t, uint32_t, PositionController& positionController);
|
||||
Projectile(const Projectile & other);
|
||||
uint8_t typeId;
|
||||
Vector3D delta;
|
||||
|
@ -219,6 +219,8 @@ namespace OpenGTA {
|
||||
void CityView::createLevelObject(OpenGTA::Map::ObjectPosition *obj) {
|
||||
SpriteManager & s_man = SpriteManagerHolder::Instance();
|
||||
uint32_t id = TypeIdBlackBox::requestId();
|
||||
|
||||
/*
|
||||
if (obj->remap >= 128) {
|
||||
Car car(*obj, id);
|
||||
s_man.add(car);
|
||||
@ -226,7 +228,7 @@ namespace OpenGTA {
|
||||
else {
|
||||
SpriteObject gobj(*obj, id);
|
||||
s_man.add(gobj);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
void CityView::setZoom(const GLfloat zoom) {
|
||||
zoomLevel = zoom;
|
||||
|
@ -21,10 +21,11 @@ namespace OpenGTA {
|
||||
numLives = 0;
|
||||
pc_ptr = NULL;
|
||||
}
|
||||
/*
|
||||
PedController & getCtrl() {
|
||||
assert(pc_ptr);
|
||||
return *pc_ptr;
|
||||
}
|
||||
}*/
|
||||
void setCtrl(PedController & pc) {
|
||||
pc_ptr = &pc;
|
||||
}
|
||||
|
154
net/udp_client.cpp
Executable file
154
net/udp_client.cpp
Executable file
@ -0,0 +1,154 @@
|
||||
#include "udp_client.h"
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace OpenGTA {
|
||||
|
||||
|
||||
void updateStaticPositionController(const OpenGTA::Map::ObjectPosition& op, PositionController& c)
|
||||
{
|
||||
|
||||
auto m_M = TranslateMatrix3D(Vector3D(c.pos(0), c.pos(1), c.pos(2)));
|
||||
|
||||
m_M.RotZ(-c.rot);
|
||||
|
||||
c.rot = op.rotation * 360 / 1024;
|
||||
}
|
||||
|
||||
|
||||
PositionController& UdpClient::createStaticPositionController(Vector3D pos)
|
||||
{
|
||||
PositionController c;
|
||||
c.pos = Eigen::Vector3f{ pos.x, pos.y, pos.z };
|
||||
c.rot = 0;
|
||||
staticPositionControllers[staticPosControllerCount] = c;
|
||||
|
||||
staticPosControllerCount++;
|
||||
|
||||
return staticPositionControllers[staticPosControllerCount - 1];
|
||||
}
|
||||
|
||||
|
||||
PositionController& UdpClient::createStaticPositionController(Vector3D pos, float rot)
|
||||
{
|
||||
PositionController c;
|
||||
c.pos = Eigen::Vector3f{ pos.x, pos.y, pos.z };
|
||||
c.rot = rot;
|
||||
staticPositionControllers[staticPosControllerCount] = c;
|
||||
|
||||
staticPosControllerCount++;
|
||||
|
||||
return staticPositionControllers[staticPosControllerCount - 1];
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UdpClient::handleReceive(const boost::system::error_code& error, std::size_t bytes_transferred) {
|
||||
if (error) {
|
||||
std::cout << "Receive failed: " << error.message() << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
net::ServerDatagramToSend serverDatagram;
|
||||
|
||||
std::copy(&recvBuffer[0], &recvBuffer[0] + sizeof(net::ServerDatagramToSend), reinterpret_cast<char*>(&serverDatagram));
|
||||
|
||||
if (serverDatagram.number > latestServerDatagram.number)
|
||||
{
|
||||
|
||||
for (uint16_t i = 0; i < serverDatagram.numberOfPlayers; i++)
|
||||
{
|
||||
if (serverDatagram.players[i].type != serverDatagram.yourType)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
latestServerDatagram = serverDatagram;
|
||||
}
|
||||
|
||||
|
||||
|
||||
wait();
|
||||
|
||||
}
|
||||
|
||||
void UdpClient::wait()
|
||||
{
|
||||
receiverSocket.async_receive_from(boost::asio::buffer(recvBuffer),
|
||||
remoteEndpoint,
|
||||
boost::bind(&UdpClient::handleReceive, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
|
||||
void UdpClient::udpSendTimerHandler(const boost::system::error_code& error)
|
||||
{
|
||||
|
||||
player.pressedButtons = playerController.pressedButtons;
|
||||
player.posX = playerController.pos(0);
|
||||
player.posY = playerController.pos(1);
|
||||
player.posZ = playerController.pos(2);
|
||||
player.angle = playerController.rot;
|
||||
|
||||
std::array<char, 256> arrayBuffer;
|
||||
|
||||
arrayBuffer.fill(0);
|
||||
|
||||
std::copy(reinterpret_cast<char*>(&player), reinterpret_cast<char*>(&player) + sizeof(net::ReceivedDatagram), &arrayBuffer[0]);
|
||||
|
||||
//std::copy(&arrayBuffer[0], &arrayBuffer[0] + sizeof(net::ReceivedDatagram), reinterpret_cast<char*>(&player));
|
||||
|
||||
|
||||
|
||||
udp::socket socket(udpSenderIoContext);
|
||||
|
||||
udp::endpoint remote_endpoint = udp::endpoint(boost::asio::ip::make_address("127.0.0.1"), 13);
|
||||
|
||||
socket.open(udp::v4());
|
||||
|
||||
boost::system::error_code err;
|
||||
|
||||
auto sent = socket.send_to(boost::asio::buffer(arrayBuffer), remote_endpoint, 0, err);
|
||||
|
||||
socket.close();
|
||||
|
||||
player.number++;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!quit)
|
||||
{
|
||||
sendTimer.expires_at(sendTimer.expiry() + boost::asio::chrono::milliseconds(50));
|
||||
sendTimer.async_wait(boost::bind(&UdpClient::udpSendTimerHandler, this, boost::asio::placeholders::error));
|
||||
}
|
||||
}
|
||||
|
||||
void UdpClient::start()
|
||||
{
|
||||
sendTimer.async_wait(boost::bind(&UdpClient::udpSendTimerHandler, this, boost::asio::placeholders::error));
|
||||
|
||||
timerThread = std::thread([this]() {this->udpSenderIoContext.run(); });
|
||||
}
|
||||
|
||||
UdpClient::UdpClient()
|
||||
{
|
||||
|
||||
player.angle = 0;
|
||||
player.localTime = 0;
|
||||
player.number = 1;
|
||||
player.posX = 12.0;
|
||||
player.posY = 6.1;
|
||||
player.posZ = 12.0;
|
||||
|
||||
receiverSocket.open(udp::v4());
|
||||
receiverSocket.bind(udp::endpoint(boost::asio::ip::make_address("127.0.0.1"), 14));
|
||||
|
||||
wait();
|
||||
|
||||
receiverThread = std::thread([this]() {this->udpReceiverIoContext.run(); });
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
167
net/udp_client.h
Executable file
167
net/udp_client.h
Executable file
@ -0,0 +1,167 @@
|
||||
#ifndef UDP_CLIENT_H_INCLUDED
|
||||
#define UDP_CLIENT_H_INCLUDED
|
||||
#include "Singleton.h"
|
||||
#include "game_objects.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include "entity_controller.h"
|
||||
|
||||
|
||||
namespace net
|
||||
{
|
||||
#pragma pack(push, 1)
|
||||
struct ReceivedDatagram
|
||||
{
|
||||
uint32_t number;
|
||||
uint32_t localTime;
|
||||
float posX;
|
||||
float posY;
|
||||
float posZ;
|
||||
float angle;
|
||||
uint8_t pressedButtons;
|
||||
|
||||
};
|
||||
|
||||
struct PlayerDatagramToSend
|
||||
{
|
||||
uint16_t type;
|
||||
uint16_t state;
|
||||
float posX;
|
||||
float posY;
|
||||
float posZ;
|
||||
float angle;
|
||||
float velX;
|
||||
float velY;
|
||||
float velZ;
|
||||
};
|
||||
|
||||
struct ServerDatagramToSend
|
||||
{
|
||||
uint32_t number = 0;
|
||||
uint32_t localTime;
|
||||
uint16_t yourType;
|
||||
uint16_t numberOfPlayers;
|
||||
|
||||
std::array<PlayerDatagramToSend, 4> players;
|
||||
|
||||
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace OpenGTA {
|
||||
|
||||
using boost::asio::ip::udp;
|
||||
using boost::asio::ip::address;
|
||||
|
||||
void updateStaticPositionController(const OpenGTA::Map::ObjectPosition& op, PositionController& c);
|
||||
|
||||
class UdpClient
|
||||
{
|
||||
public:
|
||||
|
||||
PlayerPedController playerController;
|
||||
|
||||
std::array<PositionController, 65536> staticPositionControllers;
|
||||
size_t staticPosControllerCount = 0;
|
||||
|
||||
PositionController& createStaticPositionController(Vector3D pos);
|
||||
PositionController& createStaticPositionController(Vector3D pos, float rot);
|
||||
|
||||
net::ReceivedDatagram player;
|
||||
|
||||
net::ServerDatagramToSend latestServerDatagram;
|
||||
|
||||
|
||||
boost::asio::io_context udpReceiverIoContext;
|
||||
boost::asio::io_context udpSenderIoContext;
|
||||
|
||||
|
||||
udp::socket receiverSocket{ udpReceiverIoContext };
|
||||
udp::socket senderSocket{ udpSenderIoContext };
|
||||
|
||||
std::array<char, 256> recvBuffer;
|
||||
udp::endpoint remoteEndpoint;
|
||||
|
||||
boost::asio::steady_timer sendTimer{ udpSenderIoContext, boost::asio::chrono::milliseconds(50) };
|
||||
|
||||
std::thread receiverThread;
|
||||
std::thread timerThread;
|
||||
|
||||
volatile bool quit = false;
|
||||
|
||||
UdpClient();
|
||||
|
||||
void wait();
|
||||
void handleReceive(const boost::system::error_code& error, std::size_t bytes_transferred);
|
||||
|
||||
void udpSendTimerHandler(const boost::system::error_code& error);
|
||||
|
||||
void start();
|
||||
};
|
||||
|
||||
|
||||
typedef Loki::SingletonHolder<UdpClient> LocalClient;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
class PlayerController : public Util::KeyHandler {
|
||||
public:
|
||||
PlayerController() {
|
||||
reset();
|
||||
}
|
||||
void reset() {
|
||||
playerId = TypeIdBlackBox::getPlayerId();
|
||||
cash = 0;
|
||||
wantedLevel = 0;
|
||||
modifier = 0;
|
||||
numLives = 0;
|
||||
pc_ptr = NULL;
|
||||
}
|
||||
PedController & getCtrl() {
|
||||
assert(pc_ptr);
|
||||
return *pc_ptr;
|
||||
}
|
||||
void setCtrl(PedController & pc) {
|
||||
pc_ptr = &pc;
|
||||
}
|
||||
void giveLives(uint16_t k) {
|
||||
numLives += k;
|
||||
}
|
||||
void disableCtrl(bool soft);
|
||||
void enableCtrl();
|
||||
Pedestrian & getPed();
|
||||
Car& getCar();
|
||||
int32_t getNumLives() { return numLives; }
|
||||
int32_t getWantedLevel() { return wantedLevel; }
|
||||
uint32_t getCash() { return cash; }
|
||||
bool up(const uint32_t & key);
|
||||
bool down(const uint32_t & key);
|
||||
uint32_t getId() { return playerId; }
|
||||
void addCash(uint32_t v) { cash += v; }
|
||||
void setWanted(int32_t v) { wantedLevel = v; }
|
||||
void addWanted(uint32_t v) { wantedLevel += v; if (wantedLevel > 5) wantedLevel = 5; }
|
||||
|
||||
|
||||
uint32_t playerCarId = 0;
|
||||
private:
|
||||
uint32_t playerId;
|
||||
uint32_t cash;
|
||||
int32_t wantedLevel;
|
||||
uint32_t modifier;
|
||||
int32_t numLives;
|
||||
PedController * pc_ptr;
|
||||
|
||||
|
||||
};
|
||||
|
||||
typedef Loki::SingletonHolder<PlayerController> LocalPlayer;*/
|
||||
}
|
||||
|
||||
#endif
|
@ -28,6 +28,8 @@
|
||||
#include "timer.h"
|
||||
#include "id_sys.h"
|
||||
|
||||
#include "net/udp_client.h"
|
||||
|
||||
namespace OpenGTA {
|
||||
//SpriteManager::SpriteManager() : trainSystem(AbstractContainer<TrainSegment>::objs){
|
||||
SpriteManager::SpriteManager() {
|
||||
@ -153,10 +155,14 @@ namespace OpenGTA {
|
||||
|
||||
}
|
||||
removeDeadStuff();
|
||||
|
||||
/*
|
||||
if (num_peds < 50 && num_peds > 2 && ticks - lastCreateTick > 100) {
|
||||
//MapHelper::createPeds(5);
|
||||
|
||||
Map & map = OpenGTA::MapHolder::Instance().get();
|
||||
lastCreateTick = ticks;
|
||||
|
||||
|
||||
while (1) {
|
||||
Util::TupleOfUint8 tu8 = creationArea.getValidCoord();
|
||||
INFO << "testing: " << int(tu8.first) << ", " << int(tu8.second) << std::endl;
|
||||
@ -181,7 +187,7 @@ namespace OpenGTA {
|
||||
OpenGTA::SpriteManagerHolder::Instance().add<Pedestrian>(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
#define POS_INSIDE_RECT(pos, r) ((pos.x >= r.x) && \
|
||||
@ -191,7 +197,7 @@ namespace OpenGTA {
|
||||
for (AbstractContainer<Pedestrian>::Storage_T_Iterator i = AbstractContainer<Pedestrian>::objs.begin();
|
||||
i != AbstractContainer<Pedestrian>::objs.end(); ++i) {
|
||||
Pedestrian & ped = (*i);
|
||||
if (POS_INSIDE_RECT(ped.pos, r))
|
||||
if (POS_INSIDE_RECT(ped.pos(), r))
|
||||
//if ((ped.pos.x >= r.x) && (ped.pos.x <= r.x + r.w) &&
|
||||
// (ped.pos.z >= r.y) && (ped.pos.z <= r.y + r.h))
|
||||
draw(ped);
|
||||
@ -203,7 +209,7 @@ namespace OpenGTA {
|
||||
SpriteObject & obj = (*i);
|
||||
//if ((obj.pos.x >= r.x) && (obj.pos.x <= r.x + r.w) &&
|
||||
// (obj.pos.z >= r.y) && (obj.pos.z <= r.y + r.h))
|
||||
if (POS_INSIDE_RECT(obj.pos, r))
|
||||
if (POS_INSIDE_RECT(obj.pos(), r))
|
||||
draw(obj);
|
||||
}
|
||||
for (AbstractContainer<Car>::Storage_T_Iterator i = AbstractContainer<Car>::objs.begin();
|
||||
@ -211,7 +217,7 @@ namespace OpenGTA {
|
||||
Car & car = (*i);
|
||||
// if ((car.pos.x >= r.x) && (car.pos.x <= r.x + r.w) &&
|
||||
// (car.pos.z >= r.y) && (car.pos.z <= r.y + r.h))
|
||||
if (POS_INSIDE_RECT(car.pos, r))
|
||||
if (POS_INSIDE_RECT(car.pos(), r))
|
||||
draw(car);
|
||||
}
|
||||
|
||||
@ -219,7 +225,7 @@ namespace OpenGTA {
|
||||
typedef ProjectileListType::iterator ProjectileIterator;
|
||||
for (ProjectileIterator i = activeProjectiles.begin(); i != activeProjectiles.end(); ++i) {
|
||||
Projectile & prj = (*i);
|
||||
if (POS_INSIDE_RECT(prj.pos, r))
|
||||
if (POS_INSIDE_RECT(prj.pos(), r))
|
||||
draw(prj);
|
||||
}
|
||||
glColor3f(1, 1, 1);
|
||||
@ -242,8 +248,8 @@ namespace OpenGTA {
|
||||
|
||||
#define GL_OBJ_COMMON(o) GL_CHECKERROR; \
|
||||
glPushMatrix(); \
|
||||
glTranslatef(o.pos.x, o.pos.y, o.pos.z); \
|
||||
glRotatef(o.rot, 0, 1, 0); \
|
||||
glTranslatef(o.pos().x, o.pos().y, o.pos().z); \
|
||||
glRotatef(o.rot(), 0, 1, 0); \
|
||||
//glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)o.m_M.m)
|
||||
|
||||
#define DRAW_TEX_QUADS_OBJ(t, w, h) glBindTexture(GL_TEXTURE_2D, t.inPage); \
|
||||
@ -418,7 +424,7 @@ void SpriteManager::drawExplosion(SpriteObject & obj) {
|
||||
return;
|
||||
}
|
||||
glPushMatrix();
|
||||
glTranslatef(obj.pos.x, obj.pos.y, obj.pos.z);
|
||||
glTranslatef(obj.pos().x, obj.pos().y, obj.pos().z);
|
||||
//glRotatef(obj.rot, 0, 1, 0);
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, *obj.m_M.m);
|
||||
|
||||
@ -582,8 +588,8 @@ void SpriteManager::draw(Projectile & proj) {
|
||||
const float h = 0.05f;
|
||||
|
||||
glPushMatrix(); \
|
||||
glTranslatef(proj.pos.x, proj.pos.y, proj.pos.z); \
|
||||
glRotatef(proj.rot, 0, 1, 0);
|
||||
glTranslatef(proj.pos().x, proj.pos().y, proj.pos().z); \
|
||||
glRotatef(proj.rot(), 0, 1, 0);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
@ -607,7 +613,7 @@ void SpriteManager::removeDeadStuff() {
|
||||
AbstractContainer<Pedestrian>::Storage_T_Iterator i = AbstractContainer<Pedestrian>::objs.begin();
|
||||
while (i != AbstractContainer<Pedestrian>::objs.end()) {
|
||||
Pedestrian & ped = (*i);
|
||||
if ((ped.isDead == 3) && (creationArea.isOnScreen(ped.pos) == false)) {
|
||||
if ((ped.isDead == 3) && (creationArea.isOnScreen(ped.pos()) == false)) {
|
||||
AbstractContainer<Pedestrian>::Storage_T_Iterator j = i; j++;
|
||||
AbstractContainer<Pedestrian>::objs.erase(i);
|
||||
i = j;
|
||||
@ -650,14 +656,20 @@ void SpriteManager::setDrawTexture(bool v) {
|
||||
}
|
||||
|
||||
void SpriteManager::createProjectile(uint8_t typeId, float r, Vector3D p, Vector3D d, Uint32 & ticks, Uint32 & owner) {
|
||||
activeProjectiles.push_back(Projectile(typeId, r, p, d, ticks, owner));
|
||||
|
||||
auto& posController = LocalClient::Instance().createStaticPositionController(p, r);
|
||||
|
||||
activeProjectiles.push_back(Projectile(typeId, d, ticks, owner, posController));
|
||||
}
|
||||
|
||||
void SpriteManager::createExplosion(Vector3D center) {
|
||||
|
||||
/*
|
||||
|
||||
SpriteObject expl(center, 0, GraphicsBase::SpriteNumbers::EX);
|
||||
expl.anim = SpriteObject::Animation(getAnimationById(99));
|
||||
expl.anim.set(Util::Animation::PLAY_FORWARD, Util::Animation::STOP);
|
||||
add(expl);
|
||||
add(expl);*/
|
||||
}
|
||||
|
||||
}
|
||||
|
121
viewer.cpp
121
viewer.cpp
@ -52,6 +52,7 @@
|
||||
#include "font_cache.h"
|
||||
#include "ai.h"
|
||||
|
||||
#include "net/udp_client.h"
|
||||
|
||||
|
||||
|
||||
@ -544,22 +545,27 @@ void handleKeyUp(SDL_Keysym* keysym) {
|
||||
|
||||
switch ( keysym->sym ) {
|
||||
case 'j':
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().releaseTurnLeft();
|
||||
|
||||
OpenGTA::LocalClient::Instance().playerController.releaseTurnLeft();
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().releaseTurnLeft();
|
||||
//OpenGTA::LocalPlayer::Instance().turn = 0;
|
||||
//OpenGTA::LocalPlayer::Instance().setTurn(0);
|
||||
break;
|
||||
case 'l':
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().releaseTurnRight();
|
||||
OpenGTA::LocalClient::Instance().playerController.releaseTurnRight();
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().releaseTurnRight();
|
||||
//OpenGTA::LocalPlayer::Instance().turn = 0;
|
||||
//OpenGTA::LocalPlayer::Instance().setTurn(0);
|
||||
break;
|
||||
case 'i':
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().releaseMoveForward();
|
||||
OpenGTA::LocalClient::Instance().playerController.releaseMoveForward();
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().releaseMoveForward();
|
||||
//OpenGTA::LocalPlayer::Instance().move = 0;
|
||||
//OpenGTA::LocalPlayer::Instance().setMove(0);
|
||||
break;
|
||||
case 'k':
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().releaseMoveBack();
|
||||
OpenGTA::LocalClient::Instance().playerController.releaseMoveBack();
|
||||
// OpenGTA::LocalPlayer::Instance().getCtrl().releaseMoveBack();
|
||||
//OpenGTA::LocalPlayer::Instance().move = 0;
|
||||
//OpenGTA::LocalPlayer::Instance().setMove(0);
|
||||
break;
|
||||
@ -576,7 +582,7 @@ void handleKeyUp(SDL_Keysym* keysym) {
|
||||
|
||||
break;
|
||||
case SDLK_LCTRL:
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setFireWeapon(false);
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setFireWeapon(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -586,12 +592,12 @@ void handleKeyUp(SDL_Keysym* keysym) {
|
||||
void draw_mapmode();
|
||||
|
||||
void create_ped_at(const Vector3D v) {
|
||||
OpenGTA::Pedestrian p(Vector3D(0.2f, 0.5f, 0.2f), v, 0xffffffff);
|
||||
OpenGTA::Pedestrian p(Vector3D(0.2f, 0.5f, 0.2f), v, 0xffffffff, -1, OpenGTA::LocalClient::Instance().playerController);
|
||||
p.remap = OpenGTA::StyleHolder::Instance().get().getRandomPedRemapNumber();
|
||||
INFO << "using remap: " << p.remap << std::endl;
|
||||
OpenGTA::Pedestrian & pr = OpenGTA::SpriteManagerHolder::Instance().addPed(p);
|
||||
pr.switchToAnim(1);
|
||||
OpenGTA::LocalPlayer::Instance().setCtrl(pr.m_control);
|
||||
//OpenGTA::LocalPlayer::Instance().setCtrl(pr.m_control);
|
||||
GUI::create_ingame_gui(1);
|
||||
//pr.m_control = &OpenGTA::LocalPlayer::Instance();
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).giveItem(1, 255);
|
||||
@ -605,6 +611,7 @@ void updateAnim() {
|
||||
|
||||
void create_car_at(const Vector3D v) {
|
||||
|
||||
/*
|
||||
int carId;
|
||||
if (city_num == 0)
|
||||
{
|
||||
@ -617,13 +624,13 @@ void create_car_at(const Vector3D v) {
|
||||
|
||||
OpenGTA::Car c2(Vector3D(v.x, v.y, v.z), 180, 999999, carId, 0);
|
||||
|
||||
OpenGTA::SpriteManagerHolder::Instance().add(c2);
|
||||
OpenGTA::SpriteManagerHolder::Instance().add(c2);*/
|
||||
}
|
||||
|
||||
void explode_ped() {
|
||||
try {
|
||||
OpenGTA::Pedestrian & ped = OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff);
|
||||
Vector3D p(ped.pos);
|
||||
Vector3D p(ped.pos());
|
||||
p.y += 0.2f;
|
||||
OpenGTA::SpriteManagerHolder::Instance().createExplosion(p);
|
||||
}
|
||||
@ -645,46 +652,13 @@ void zoomToTrain(int k) {
|
||||
#include "cell_iterator.h"
|
||||
|
||||
namespace OpenGTA {
|
||||
void ai_step_fake(OpenGTA::Pedestrian *p) {
|
||||
try {
|
||||
OpenGTA::Pedestrian & pr = OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff);
|
||||
float t_angle = Util::xz_angle(p->pos, pr.pos);
|
||||
//INFO << "dist " << Util::distance(p->pos, pr.pos) << std::endl;
|
||||
//INFO << "angle " << t_angle << std::endl;
|
||||
//INFO << "myrot: " << p->rot << std::endl;
|
||||
if (Util::distance(p->pos, pr.pos) > 3) {
|
||||
p->m_control.setTurnLeft(false);
|
||||
p->m_control.setTurnRight(false);
|
||||
if (t_angle > p->rot)
|
||||
p->m_control.setTurnLeft(true);
|
||||
else
|
||||
p->m_control.setTurnRight(true);
|
||||
}
|
||||
else {
|
||||
p->m_control.setMoveForward(true);
|
||||
int k = rand() % 5;
|
||||
if (k == 0) {
|
||||
p->m_control.setTurnLeft(false);
|
||||
p->m_control.setTurnRight(false);
|
||||
}
|
||||
else if (k == 1) {
|
||||
p->m_control.setTurnLeft(true);
|
||||
p->m_control.setTurnRight(false);
|
||||
}
|
||||
else if (k == 2) {
|
||||
p->m_control.setTurnLeft(false);
|
||||
p->m_control.setTurnRight(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Util::UnknownKey & e) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#include "id_sys.h"
|
||||
void add_auto_ped() {
|
||||
|
||||
/*
|
||||
try {
|
||||
OpenGTA::Pedestrian & pr = OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff);
|
||||
int id = OpenGTA::TypeIdBlackBox::requestId();
|
||||
@ -702,11 +676,12 @@ void add_auto_ped() {
|
||||
}
|
||||
catch (Util::UnknownKey & e) {
|
||||
WARN << "Cannot place peds now - press F4 to switch to player-mode first!" << std::endl;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void toggle_player_run() {
|
||||
OpenGTA::PedController * pc = &OpenGTA::LocalPlayer::Instance().getCtrl();
|
||||
|
||||
/*OpenGTA::PedController * pc = &OpenGTA::LocalPlayer::Instance().getCtrl();
|
||||
INFO << std::endl;
|
||||
|
||||
if (!pc) {
|
||||
@ -716,7 +691,7 @@ void toggle_player_run() {
|
||||
if (!pc->getRunning())
|
||||
pc->setRunning(true);
|
||||
else
|
||||
pc->setRunning(false);
|
||||
pc->setRunning(false);*/
|
||||
}
|
||||
|
||||
void show_gamma_config() {
|
||||
@ -755,19 +730,19 @@ void show_gamma_config() {
|
||||
|
||||
void car_toggle() {
|
||||
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
|
||||
Vector3D pos = pped.pos;
|
||||
Vector3D pos = pped.pos();
|
||||
std::list<OpenGTA::Car> & list = OpenGTA::SpriteManagerHolder::Instance().getList<OpenGTA::Car>();
|
||||
float min_dist = 360;
|
||||
float _d;
|
||||
std::list<OpenGTA::Car>::iterator j = list.end();
|
||||
for (std::list<OpenGTA::Car>::iterator i = list.begin(); i != list.end(); i++) {
|
||||
if ((_d = Util::distance(pos, i->pos)) < min_dist) {
|
||||
if ((_d = Util::distance(pos, i->pos())) < min_dist) {
|
||||
j = i;
|
||||
min_dist = _d;
|
||||
}
|
||||
}
|
||||
assert(j != list.end());
|
||||
std::cout << j->id() << " " << j->pos.x << ", " << j->pos.y << ", " << j->pos.z << std::endl;
|
||||
std::cout << j->id() << " " << j->pos().x << ", " << j->pos().y << ", " << j->pos().z << std::endl;
|
||||
Vector3D p_door(j->carInfo.door[0].rpx / 64.0f, 0,
|
||||
j->carInfo.door[0].rpy / 64.0f);
|
||||
|
||||
@ -846,7 +821,7 @@ void handleKeyPress( SDL_Keysym *keysym ) {
|
||||
Vector3D p(cam.getEye());
|
||||
create_ped_at(p);
|
||||
cam.setVectors( Vector3D(p.x, 10, p.z), Vector3D(p.x, 9.0f, p.z), Vector3D(0, 0, -1) );
|
||||
cam.setFollowMode(OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).pos);
|
||||
cam.setFollowMode(OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).pos());
|
||||
cam.setCamGravity(true);
|
||||
}
|
||||
else {
|
||||
@ -896,23 +871,19 @@ void handleKeyPress( SDL_Keysym *keysym ) {
|
||||
toggle_player_run();
|
||||
break;
|
||||
case SDLK_LCTRL:
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setFireWeapon();
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setFireWeapon();
|
||||
break;
|
||||
case '1':
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(1);
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(1);
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(1);
|
||||
break;
|
||||
case '2':
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(2);
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(2);
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(2);
|
||||
break;
|
||||
case '3':
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(3);
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(3);
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(3);
|
||||
break;
|
||||
case '4':
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(4);
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(4);
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(4);
|
||||
break;
|
||||
case '5':
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(5);
|
||||
@ -930,8 +901,7 @@ void handleKeyPress( SDL_Keysym *keysym ) {
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(9);
|
||||
break;
|
||||
case '0':
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(0);
|
||||
//OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).equip(0);
|
||||
//OpenGTA::LocalPlayer::Instance().getCtrl().setActiveWeapon(0);
|
||||
break;
|
||||
case 'w':
|
||||
cam.setSpeed(0.2f);
|
||||
@ -941,6 +911,8 @@ void handleKeyPress( SDL_Keysym *keysym ) {
|
||||
break;
|
||||
case 'j':
|
||||
{
|
||||
OpenGTA::LocalClient::Instance().playerController.setTurnLeft();
|
||||
/*
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setTurnLeft();
|
||||
|
||||
if (OpenGTA::LocalPlayer::Instance().playerCarId == 0)
|
||||
@ -949,40 +921,46 @@ void handleKeyPress( SDL_Keysym *keysym ) {
|
||||
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
|
||||
pped.aiMode = 0;
|
||||
pped.aimCarId = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
{
|
||||
OpenGTA::LocalClient::Instance().playerController.setTurnRight();
|
||||
/*
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setTurnRight();
|
||||
if (OpenGTA::LocalPlayer::Instance().playerCarId == 0)
|
||||
{
|
||||
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
|
||||
pped.aiMode = 0;
|
||||
pped.aimCarId = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
OpenGTA::LocalClient::Instance().playerController.setMoveForward();
|
||||
/*
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setMoveForward();
|
||||
if (OpenGTA::LocalPlayer::Instance().playerCarId == 0)
|
||||
{
|
||||
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
|
||||
pped.aiMode = 0;
|
||||
pped.aimCarId = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case 'k':
|
||||
{
|
||||
OpenGTA::LocalClient::Instance().playerController.setMoveBack();
|
||||
/*
|
||||
OpenGTA::LocalPlayer::Instance().getCtrl().setMoveBack();
|
||||
if (OpenGTA::LocalPlayer::Instance().playerCarId == 0)
|
||||
{
|
||||
OpenGTA::Pedestrian & pped = OpenGTA::LocalPlayer::Instance().getPed();
|
||||
pped.aiMode = 0;
|
||||
pped.aimCarId = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
@ -1255,15 +1233,22 @@ void run_main() {
|
||||
follow_toggle = true;
|
||||
city->setViewMode(false);
|
||||
Vector3D p(cam.getEye());
|
||||
|
||||
|
||||
|
||||
create_ped_at(p);
|
||||
cam.setVectors(Vector3D(p.x, 10, p.z), Vector3D(p.x, 9.0f, p.z), Vector3D(0, 0, -1));
|
||||
cam.setFollowMode(OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).pos);
|
||||
cam.setFollowMode(OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).pos());
|
||||
cam.setCamGravity(true);
|
||||
|
||||
|
||||
OpenGTA::LocalClient::Instance().start();
|
||||
|
||||
/*
|
||||
|
||||
Vector3D px(cam.getEye() + Vector3D(2.0, 0.0, 2.0));
|
||||
create_car_at(px);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user