summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-15 23:50:00 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-15 23:50:00 +0100
commitd15d40ad6969cc2d0945853fa13622cbef9f5b98 (patch)
treed47f3bd2c09ee9578e68defd7804017ec8701cfb /source
parentNew players no longer cause an assert (diff)
downloadcuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.tar
cuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.tar.gz
cuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.tar.bz2
cuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.tar.lz
cuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.tar.xz
cuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.tar.zst
cuberite-d15d40ad6969cc2d0945853fa13622cbef9f5b98.zip
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp50
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cEntity.cpp39
-rw-r--r--source/cEntity.h24
-rw-r--r--source/cMonster.cpp84
-rw-r--r--source/cMonster.h4
-rw-r--r--source/cPawn.cpp10
-rw-r--r--source/cPickup.cpp89
-rw-r--r--source/cPickup.h6
-rw-r--r--source/cPlayer.cpp52
-rw-r--r--source/cTracer.cpp144
-rw-r--r--source/cTracer.h30
12 files changed, 246 insertions, 288 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 0c3cad075..e9d23fa26 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 02/13/12 11:40:58.
+** Generated automatically by tolua++-1.0.92 on 02/15/12 23:43:42.
*/
#ifndef __cplusplus
@@ -15557,90 +15557,90 @@ static int tolua_AllToLua_cTracer_SetValues00(lua_State* tolua_S)
#endif //#ifndef TOLUA_DISABLE
/* get function: BlockHitPosition of class cTracer */
-#ifndef TOLUA_DISABLE_tolua_get_cTracer_BlockHitPosition_ptr
-static int tolua_get_cTracer_BlockHitPosition_ptr(lua_State* tolua_S)
+#ifndef TOLUA_DISABLE_tolua_get_cTracer_BlockHitPosition
+static int tolua_get_cTracer_BlockHitPosition(lua_State* tolua_S)
{
cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'BlockHitPosition'",NULL);
#endif
- tolua_pushusertype(tolua_S,(void*)self->BlockHitPosition,"Vector3f");
+ tolua_pushusertype(tolua_S,(void*)&self->BlockHitPosition,"Vector3f");
return 1;
}
#endif //#ifndef TOLUA_DISABLE
/* set function: BlockHitPosition of class cTracer */
-#ifndef TOLUA_DISABLE_tolua_set_cTracer_BlockHitPosition_ptr
-static int tolua_set_cTracer_BlockHitPosition_ptr(lua_State* tolua_S)
+#ifndef TOLUA_DISABLE_tolua_set_cTracer_BlockHitPosition
+static int tolua_set_cTracer_BlockHitPosition(lua_State* tolua_S)
{
cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'BlockHitPosition'",NULL);
- if (!tolua_isusertype(tolua_S,2,"Vector3f",0,&tolua_err))
+ if ((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Vector3f",0,&tolua_err)))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif
- self->BlockHitPosition = ((Vector3f*) tolua_tousertype(tolua_S,2,0))
+ self->BlockHitPosition = *((Vector3f*) tolua_tousertype(tolua_S,2,0))
;
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: HitNormal of class cTracer */
-#ifndef TOLUA_DISABLE_tolua_get_cTracer_HitNormal_ptr
-static int tolua_get_cTracer_HitNormal_ptr(lua_State* tolua_S)
+#ifndef TOLUA_DISABLE_tolua_get_cTracer_HitNormal
+static int tolua_get_cTracer_HitNormal(lua_State* tolua_S)
{
cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'HitNormal'",NULL);
#endif
- tolua_pushusertype(tolua_S,(void*)self->HitNormal,"Vector3f");
+ tolua_pushusertype(tolua_S,(void*)&self->HitNormal,"Vector3f");
return 1;
}
#endif //#ifndef TOLUA_DISABLE
/* set function: HitNormal of class cTracer */
-#ifndef TOLUA_DISABLE_tolua_set_cTracer_HitNormal_ptr
-static int tolua_set_cTracer_HitNormal_ptr(lua_State* tolua_S)
+#ifndef TOLUA_DISABLE_tolua_set_cTracer_HitNormal
+static int tolua_set_cTracer_HitNormal(lua_State* tolua_S)
{
cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'HitNormal'",NULL);
- if (!tolua_isusertype(tolua_S,2,"Vector3f",0,&tolua_err))
+ if ((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Vector3f",0,&tolua_err)))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif
- self->HitNormal = ((Vector3f*) tolua_tousertype(tolua_S,2,0))
+ self->HitNormal = *((Vector3f*) tolua_tousertype(tolua_S,2,0))
;
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: RealHit of class cTracer */
-#ifndef TOLUA_DISABLE_tolua_get_cTracer_RealHit_ptr
-static int tolua_get_cTracer_RealHit_ptr(lua_State* tolua_S)
+#ifndef TOLUA_DISABLE_tolua_get_cTracer_RealHit
+static int tolua_get_cTracer_RealHit(lua_State* tolua_S)
{
cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'RealHit'",NULL);
#endif
- tolua_pushusertype(tolua_S,(void*)self->RealHit,"Vector3f");
+ tolua_pushusertype(tolua_S,(void*)&self->RealHit,"Vector3f");
return 1;
}
#endif //#ifndef TOLUA_DISABLE
/* set function: RealHit of class cTracer */
-#ifndef TOLUA_DISABLE_tolua_set_cTracer_RealHit_ptr
-static int tolua_set_cTracer_RealHit_ptr(lua_State* tolua_S)
+#ifndef TOLUA_DISABLE_tolua_set_cTracer_RealHit
+static int tolua_set_cTracer_RealHit(lua_State* tolua_S)
{
cTracer* self = (cTracer*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'RealHit'",NULL);
- if (!tolua_isusertype(tolua_S,2,"Vector3f",0,&tolua_err))
+ if ((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Vector3f",0,&tolua_err)))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif
- self->RealHit = ((Vector3f*) tolua_tousertype(tolua_S,2,0))
+ self->RealHit = *((Vector3f*) tolua_tousertype(tolua_S,2,0))
;
return 0;
}
@@ -17904,9 +17904,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"delete",tolua_AllToLua_cTracer_delete00);
tolua_function(tolua_S,"Trace",tolua_AllToLua_cTracer_Trace00);
tolua_function(tolua_S,"SetValues",tolua_AllToLua_cTracer_SetValues00);
- tolua_variable(tolua_S,"BlockHitPosition",tolua_get_cTracer_BlockHitPosition_ptr,tolua_set_cTracer_BlockHitPosition_ptr);
- tolua_variable(tolua_S,"HitNormal",tolua_get_cTracer_HitNormal_ptr,tolua_set_cTracer_HitNormal_ptr);
- tolua_variable(tolua_S,"RealHit",tolua_get_cTracer_RealHit_ptr,tolua_set_cTracer_RealHit_ptr);
+ tolua_variable(tolua_S,"BlockHitPosition",tolua_get_cTracer_BlockHitPosition,tolua_set_cTracer_BlockHitPosition);
+ tolua_variable(tolua_S,"HitNormal",tolua_get_cTracer_HitNormal,tolua_set_cTracer_HitNormal);
+ tolua_variable(tolua_S,"RealHit",tolua_get_cTracer_RealHit,tolua_set_cTracer_RealHit);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cGroup","cGroup","",NULL);
tolua_beginmodule(tolua_S,"cGroup");
diff --git a/source/Bindings.h b/source/Bindings.h
index 369018ad5..23e74ba4d 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 02/13/12 11:40:58.
+** Generated automatically by tolua++-1.0.92 on 02/15/12 23:43:42.
*/
/* Exported function */
diff --git a/source/cEntity.cpp b/source/cEntity.cpp
index 8b24d247e..25d10fab4 100644
--- a/source/cEntity.cpp
+++ b/source/cEntity.cpp
@@ -32,9 +32,8 @@ cEntity::cEntity(const double & a_X, const double & a_Y, const double & a_Z)
, m_ChunkX( 0 )
, m_ChunkY( 0 )
, m_ChunkZ( 0 )
- , m_Pos( new Vector3d( a_X, a_Y, a_Z ) )
+ , m_Pos( a_X, a_Y, a_Z )
, m_bDirtyPosition( true )
- , m_Rot( new Vector3f() )
, m_bDirtyOrientation( true )
, m_bDestroyed( false )
, m_EntityType( E_ENTITY )
@@ -54,8 +53,8 @@ cEntity::~cEntity()
{
LOG("Deleting entity %d at pos {%.2f, %.2f} ~ [%d, %d]; ptr %p",
m_UniqueID,
- m_Pos->x, m_Pos->z,
- (int)(m_Pos->x / 16), (int)(m_Pos->z / 16),
+ m_Pos.x, m_Pos.z,
+ (int)(m_Pos.x / 16), (int)(m_Pos.z / 16),
this
);
@@ -65,8 +64,6 @@ cEntity::~cEntity()
}
delete m_Referencers;
delete m_References;
- delete m_Pos;
- delete m_Rot;
}
@@ -87,10 +84,10 @@ void cEntity::Initialize( cWorld* a_World )
void cEntity::WrapRotation()
{
- while (m_Rot->x > 180.f) m_Rot->x-=360.f; // Wrap it
- while (m_Rot->x < -180.f) m_Rot->x+=360.f;
- while (m_Rot->y > 180.f) m_Rot->y-=360.f;
- while (m_Rot->y < -180.f) m_Rot->y+=360.f;
+ while (m_Rot.x > 180.f) m_Rot.x-=360.f; // Wrap it
+ while (m_Rot.x < -180.f) m_Rot.x+=360.f;
+ while (m_Rot.y > 180.f) m_Rot.y-=360.f;
+ while (m_Rot.y < -180.f) m_Rot.y+=360.f;
}
@@ -103,7 +100,7 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk)
if( !m_World ) return;
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;
- cWorld::BlockToChunk( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z, ChunkX, ChunkY, ChunkZ );
+ cWorld::BlockToChunk( (int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z, ChunkX, ChunkY, ChunkZ );
if (!a_bIgnoreOldChunk && (m_ChunkX == ChunkX) && (m_ChunkY == ChunkY) && (m_ChunkZ == ChunkZ))
{
return;
@@ -215,7 +212,7 @@ bool cEntity::IsA( const char* a_EntityType )
// Set orientations
void cEntity::SetRot( const Vector3f & a_Rot )
{
- *m_Rot = a_Rot;
+ m_Rot = a_Rot;
m_bDirtyOrientation = true;
}
@@ -225,7 +222,7 @@ void cEntity::SetRot( const Vector3f & a_Rot )
void cEntity::SetRotation( float a_Rotation )
{
- m_Rot->x = a_Rotation;
+ m_Rot.x = a_Rotation;
m_bDirtyOrientation = true;
}
@@ -235,7 +232,7 @@ void cEntity::SetRotation( float a_Rotation )
void cEntity::SetPitch( float a_Pitch )
{
- m_Rot->y = a_Pitch;
+ m_Rot.y = a_Pitch;
m_bDirtyOrientation = true;
}
@@ -245,7 +242,7 @@ void cEntity::SetPitch( float a_Pitch )
void cEntity::SetRoll( float a_Roll )
{
- m_Rot->z = a_Roll;
+ m_Rot.z = a_Roll;
m_bDirtyOrientation = true;
}
@@ -258,7 +255,7 @@ void cEntity::SetRoll( float a_Roll )
Vector3f cEntity::GetLookVector()
{
Matrix4f m;
- m.Init( Vector3f(), 0, m_Rot->x, -m_Rot->y );
+ m.Init( Vector3f(), 0, m_Rot.x, -m_Rot.y );
Vector3f Look = m.Transform( Vector3f(0, 0, 1) );
LOG("Look: %0.1f %0.1f %0.1f", Look.x, Look.y, Look.z );
return Look;
@@ -272,7 +269,7 @@ Vector3f cEntity::GetLookVector()
// Set position
void cEntity::SetPosition( const Vector3d & a_Pos )
{
- *m_Pos = a_Pos;
+ m_Pos = a_Pos;
MoveToCorrectChunk();
m_bDirtyPosition = true;
}
@@ -283,7 +280,7 @@ void cEntity::SetPosition( const Vector3d & a_Pos )
void cEntity::SetPosition( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
{
- m_Pos->Set( a_PosX, a_PosY, a_PosZ );
+ m_Pos.Set( a_PosX, a_PosY, a_PosZ );
MoveToCorrectChunk();
m_bDirtyPosition = true;
}
@@ -294,7 +291,7 @@ void cEntity::SetPosition( const double & a_PosX, const double & a_PosY, const d
void cEntity::SetPosX( const double & a_PosX )
{
- m_Pos->x = a_PosX;
+ m_Pos.x = a_PosX;
MoveToCorrectChunk();
m_bDirtyPosition = true;
}
@@ -305,7 +302,7 @@ void cEntity::SetPosX( const double & a_PosX )
void cEntity::SetPosY( const double & a_PosY )
{
- m_Pos->y = a_PosY;
+ m_Pos.y = a_PosY;
MoveToCorrectChunk();
m_bDirtyPosition = true;
}
@@ -316,7 +313,7 @@ void cEntity::SetPosY( const double & a_PosY )
void cEntity::SetPosZ( const double & a_PosZ )
{
- m_Pos->z = a_PosZ;
+ m_Pos.z = a_PosZ;
MoveToCorrectChunk();
m_bDirtyPosition = true;
}
diff --git a/source/cEntity.h b/source/cEntity.h
index b406e759f..f08a9f337 100644
--- a/source/cEntity.h
+++ b/source/cEntity.h
@@ -68,16 +68,16 @@ public: //tolua_export
virtual bool IsA( const char* a_EntityType ); //tolua_export
virtual const char* GetClass(); //tolua_export
- cWorld * GetWorld(void) const { return m_World; } //tolua_export
-
- const Vector3d & GetPosition(void) const {return *m_Pos; } //tolua_export
- const double & GetPosX (void) const {return m_Pos->x; } //tolua_export
- const double & GetPosY (void) const {return m_Pos->y; } //tolua_export
- const double & GetPosZ (void) const {return m_Pos->z; } //tolua_export
- const Vector3f & GetRot (void) const {return *m_Rot; } //tolua_export
- float GetRotation(void) const {return m_Rot->x; } //tolua_export
- float GetPitch (void) const {return m_Rot->y; } //tolua_export
- float GetRoll (void) const {return m_Rot->z; } //tolua_export
+ cWorld * GetWorld(void) const { return m_World; } //tolua_export
+
+ const Vector3d & GetPosition(void) const {return m_Pos; } //tolua_export
+ const double & GetPosX (void) const {return m_Pos.x; } //tolua_export
+ const double & GetPosY (void) const {return m_Pos.y; } //tolua_export
+ const double & GetPosZ (void) const {return m_Pos.z; } //tolua_export
+ const Vector3f & GetRot (void) const {return m_Rot; } //tolua_export
+ float GetRotation(void) const {return m_Rot.x; } //tolua_export
+ float GetPitch (void) const {return m_Rot.y; } //tolua_export
+ float GetRoll (void) const {return m_Rot.z; } //tolua_export
Vector3f GetLookVector(); //tolua_export
void SetPosX( const double & a_PosX ); //tolua_export
@@ -122,10 +122,10 @@ protected:
cReferenceManager* m_References;
int m_ChunkX, m_ChunkY, m_ChunkZ;
- Vector3d* m_Pos;
+ Vector3d m_Pos;
bool m_bDirtyPosition;
- Vector3f* m_Rot;
+ Vector3f m_Rot;
bool m_bDirtyOrientation;
bool m_bDestroyed;
diff --git a/source/cMonster.cpp b/source/cMonster.cpp
index 8ad97a0b6..18baa6a87 100644
--- a/source/cMonster.cpp
+++ b/source/cMonster.cpp
@@ -40,9 +40,7 @@
cMonster::cMonster()
: m_Target(0)
- , m_Destination( new Vector3f() )
, m_bMovingToDestination(false)
- , m_Speed( new Vector3f() )
, m_DestinationTime( 0 )
, m_Gravity( -9.81f)
, m_bOnGround( false )
@@ -69,8 +67,6 @@ cMonster::cMonster()
cMonster::~cMonster()
{
LOG("cMonster::~cMonster()");
- delete m_Destination;
- delete m_Speed;
}
bool cMonster::IsA( const char* a_EntityType )
@@ -88,7 +84,7 @@ cPacket * cMonster::GetSpawnPacket(void) const
cPacket_SpawnMob * Spawn = new cPacket_SpawnMob;
Spawn->m_UniqueID = GetUniqueID();
Spawn->m_Type = m_MobType;
- *Spawn->m_Pos = Vector3i((*m_Pos) * 32);
+ *Spawn->m_Pos = Vector3i((m_Pos) * 32);
Spawn->m_Yaw = 0;
Spawn->m_Pitch = 0;
Spawn->m_MetaDataSize = 1;
@@ -105,12 +101,12 @@ void cMonster::MoveToPosition( const Vector3f & a_Position )
{
m_bMovingToDestination = true;
- *m_Destination = a_Position;
+ m_Destination = a_Position;
}
bool cMonster::ReachedDestination()
{
- Vector3f Distance = (*m_Destination) - Vector3f( m_Pos );
+ Vector3f Distance = (m_Destination) - Vector3f( m_Pos );
if( Distance.SqrLength() < 2.f )
return true;
@@ -140,19 +136,19 @@ void cMonster::Tick(float a_Dt)
if( m_bMovingToDestination )
{
Vector3f Pos( m_Pos );
- Vector3f Distance = *m_Destination - Pos;
+ Vector3f Distance = m_Destination - Pos;
if( !ReachedDestination() )
{
Distance.y = 0;
Distance.Normalize();
Distance *= 3;
- m_Speed->x = Distance.x;
- m_Speed->z = Distance.z;
+ m_Speed.x = Distance.x;
+ m_Speed.z = Distance.z;
if (m_EMState == ESCAPING)
{ //Runs Faster when escaping :D otherwise they just walk away
- m_Speed->x *= 2.f;
- m_Speed->z *= 2.f;
+ m_Speed.x *= 2.f;
+ m_Speed.z *= 2.f;
}
}
else
@@ -160,17 +156,17 @@ void cMonster::Tick(float a_Dt)
m_bMovingToDestination = false;
}
- if( m_Speed->SqrLength() > 0.f )
+ if( m_Speed.SqrLength() > 0.f )
{
if( m_bOnGround )
{
- Vector3f NormSpeed = m_Speed->NormalizeCopy();
- Vector3f NextBlock = Vector3f( *m_Pos ) + NormSpeed;
+ Vector3f NormSpeed = m_Speed.NormalizeCopy();
+ Vector3f NextBlock = Vector3f( m_Pos ) + NormSpeed;
double NextHeight = (double)GetWorld()->GetHeight( (int)NextBlock.x, (int)NextBlock.z );
- if( NextHeight > m_Pos->y - 1.2 && NextHeight - m_Pos->y < 2.5 )
+ if( NextHeight > m_Pos.y - 1.2 && NextHeight - m_Pos.y < 2.5 )
{
m_bOnGround = false;
- m_Speed->y = 7.f; // Jump!!
+ m_Speed.y = 7.f; // Jump!!
}
}
}
@@ -180,7 +176,7 @@ void cMonster::Tick(float a_Dt)
ReplicateMovement();
- Vector3f Distance = *m_Destination - Vector3f( m_Pos );
+ Vector3f Distance = m_Destination - Vector3f( m_Pos );
if( Distance.SqrLength() > 0.1f )
{
float Rotation, Pitch;
@@ -278,59 +274,59 @@ void cMonster::HandlePhysics(float a_Dt)
if( m_bOnGround ) // check if it's still on the ground
{
cWorld* World = GetWorld();
- if( World->GetBlock( (int)m_Pos->x, (int)m_Pos->y -1, (int)m_Pos->z ) == E_BLOCK_AIR )
+ if( World->GetBlock( (int)m_Pos.x, (int)m_Pos.y -1, (int)m_Pos.z ) == E_BLOCK_AIR )
{
m_bOnGround = false;
}
- if( World->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z ) != E_BLOCK_AIR ) // If in ground itself, push it out
+ if( World->GetBlock( (int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z ) != E_BLOCK_AIR ) // If in ground itself, push it out
{
m_bOnGround = true;
- m_Pos->y += 0.2;
+ m_Pos.y += 0.2;
m_bDirtyPosition = true;
}
- m_Speed->x *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed->x) < 0.05 ) m_Speed->x = 0;
- m_Speed->z *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed->z) < 0.05 ) m_Speed->z = 0;
+ m_Speed.x *= 0.7f/(1+a_Dt);
+ if( fabs(m_Speed.x) < 0.05 ) m_Speed.x = 0;
+ m_Speed.z *= 0.7f/(1+a_Dt);
+ if( fabs(m_Speed.z) < 0.05 ) m_Speed.z = 0;
}
if( !m_bOnGround )
{
float Gravity = -9.81f*a_Dt;
- m_Speed->y += Gravity;
+ m_Speed.y += Gravity;
}
- if( m_Speed->SqrLength() > 0.f )
+ if( m_Speed.SqrLength() > 0.f )
{
cTracer Tracer( GetWorld() );
- int Ret = Tracer.Trace( *m_Pos, *m_Speed, 2 );
+ int Ret = Tracer.Trace( m_Pos, m_Speed, 2 );
if( Ret ) // Oh noez! we hit something
{
// Set to hit position
- if( (*Tracer.RealHit - Vector3f(*m_Pos)).SqrLength() <= ( *m_Speed * a_Dt ).SqrLength() )
+ if( (Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_Speed * a_Dt ).SqrLength() )
{
if( Ret == 1 )
{
- if( Tracer.HitNormal->x != 0.f ) m_Speed->x = 0.f;
- if( Tracer.HitNormal->y != 0.f ) m_Speed->y = 0.f;
- if( Tracer.HitNormal->z != 0.f ) m_Speed->z = 0.f;
+ if( Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f;
+ if( Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f;
+ if( Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f;
- if( Tracer.HitNormal->y > 0 ) // means on ground
+ if( Tracer.HitNormal.y > 0 ) // means on ground
{
m_bOnGround = true;
}
}
- *m_Pos = Tracer.RealHit;
- *m_Pos += *Tracer.HitNormal * 0.2f;
+ m_Pos = Tracer.RealHit;
+ m_Pos += Tracer.HitNormal * 0.2f;
}
else
- *m_Pos += *m_Speed*a_Dt;
+ m_Pos += m_Speed*a_Dt;
}
else
{ // We didn't hit anything, so move =]
- *m_Pos += *m_Speed*a_Dt;
+ m_Pos += m_Speed*a_Dt;
}
m_bDirtyPosition = true;
@@ -403,7 +399,7 @@ void cMonster::CheckEventLostPlayer()
if(m_Target != 0) {
pos = m_Target->GetPosition();
- if((pos - *m_Pos).Length() > m_SightDistance || LineOfSight.Trace(*m_Pos,(pos - *m_Pos), (int)(pos - *m_Pos).Length()))
+ if((pos - m_Pos).Length() > m_SightDistance || LineOfSight.Trace(m_Pos,(pos - m_Pos), (int)(pos - m_Pos).Length()))
{
EventLosePlayer();
}
@@ -439,10 +435,10 @@ void cMonster::InStateIdle(float a_Dt) {
Dist.z = (float)((r1.randInt()%11)-5);
if( Dist.SqrLength() > 2 && rem >= 3)
{
- m_Destination->x = (float)(m_Pos->x + Dist.x);
- m_Destination->z = (float)(m_Pos->z + Dist.z);
- m_Destination->y = (float)GetWorld()->GetHeight( (int)m_Destination->x, (int)m_Destination->z ) + 1.2f;
- MoveToPosition( *m_Destination );
+ m_Destination.x = (float)(m_Pos.x + Dist.x);
+ m_Destination.z = (float)(m_Pos.z + Dist.z);
+ m_Destination.y = (float)GetWorld()->GetHeight( (int)m_Destination.x, (int)m_Destination.z ) + 1.2f;
+ MoveToPosition( m_Destination );
}
}
}
@@ -457,7 +453,7 @@ void cMonster::InStateChasing(float a_Dt) {
void cMonster::InStateEscaping(float a_Dt) {
(void)a_Dt;
if(m_Target) {
- Vector3d newloc = *m_Pos;
+ Vector3d newloc = m_Pos;
newloc.x = (m_Target->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance);
newloc.z = (m_Target->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance);
MoveToPosition(newloc);
@@ -561,7 +557,7 @@ void cMonster::DropItem(ENUM_ITEM_ID a_Item, unsigned int a_Count)
{
if (a_Count > 0)
{
- cPickup * Pickup = new cPickup( (int)(m_Pos->x * 32), (int)(m_Pos->y * 32), (int)(m_Pos->z * 32), cItem( a_Item, (char) a_Count ) );
+ cPickup * Pickup = new cPickup( (int)(m_Pos.x * 32), (int)(m_Pos.y * 32), (int)(m_Pos.z * 32), cItem( a_Item, (char) a_Count ) );
Pickup->Initialize( GetWorld() );
}
}
diff --git a/source/cMonster.h b/source/cMonster.h
index 25644257c..62a1049c1 100644
--- a/source/cMonster.h
+++ b/source/cMonster.h
@@ -62,11 +62,11 @@ protected:
float m_AttackRate;
float idle_interval;
- Vector3f* m_Destination;
+ Vector3f m_Destination;
bool m_bMovingToDestination;
bool m_bPassiveAggressive;
- Vector3f* m_Speed;
+ Vector3f m_Speed;
float m_DestinationTime;
float m_Gravity;
diff --git a/source/cPawn.cpp b/source/cPawn.cpp
index 0e169e676..ff4c957e8 100644
--- a/source/cPawn.cpp
+++ b/source/cPawn.cpp
@@ -167,9 +167,9 @@ void cPawn::SetMetaData(MetaData a_MetaData)
//----Change Entity MetaData
void cPawn::CheckMetaDataBurn()
{
- char Block = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y, (int) m_Pos->z);
- char BlockAbove = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y + 1, (int) m_Pos->z);
- char BlockBelow = GetWorld()->GetBlock((int) m_Pos->x, (int) m_Pos->y - 1, (int) m_Pos->z);
+ char Block = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y, (int) m_Pos.z);
+ char BlockAbove = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y + 1, (int) m_Pos.z);
+ char BlockBelow = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y - 1, (int) m_Pos.z);
if (
(GetMetaData() == BURNING) &&
@@ -200,8 +200,8 @@ void cPawn::CheckMetaDataBurn()
void cPawn::InStateBurning(float a_Dt)
{
m_FireDamageInterval += a_Dt;
- char Block = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z );
- char BlockAbove = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y + 1, (int)m_Pos->z );
+ char Block = GetWorld()->GetBlock( (int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z );
+ char BlockAbove = GetWorld()->GetBlock( (int)m_Pos.x, (int)m_Pos.y + 1, (int)m_Pos.z );
if (m_FireDamageInterval > 800)
{
diff --git a/source/cPickup.cpp b/source/cPickup.cpp
index b84e07314..bba9ae518 100644
--- a/source/cPickup.cpp
+++ b/source/cPickup.cpp
@@ -34,16 +34,11 @@ CLASS_DEFINITION( cPickup, cEntity )
cPickup::~cPickup()
{
delete m_Item;
- delete m_Speed;
- delete m_ResultingSpeed;
- delete m_WaterSpeed;
}
cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */)
: cEntity( ((double)(a_X))/32, ((double)(a_Y))/32, ((double)(a_Z))/32 )
- , m_Speed( new Vector3f( a_SpeedX, a_SpeedY, a_SpeedZ ) )
- , m_ResultingSpeed(new Vector3f())
- , m_WaterSpeed(new Vector3f())
+ , m_Speed( a_SpeedX, a_SpeedY, a_SpeedZ )
, m_bOnGround( false )
, m_bReplicated( false )
, m_Timer( 0.f )
@@ -87,9 +82,9 @@ cPickup::cPickup(cPacket_PickupSpawn* a_PickupSpawnPacket)
m_Item->m_ItemCount = a_PickupSpawnPacket->m_Count;
m_Item->m_ItemHealth = 0x0;
- m_Speed->x = (float)(a_PickupSpawnPacket->m_Rotation) / 8;
- m_Speed->y = (float)(a_PickupSpawnPacket->m_Pitch) / 8;
- m_Speed->z = (float)(a_PickupSpawnPacket->m_Roll) / 8;
+ m_Speed.x = (float)(a_PickupSpawnPacket->m_Rotation) / 8;
+ m_Speed.y = (float)(a_PickupSpawnPacket->m_Pitch) / 8;
+ m_Speed.z = (float)(a_PickupSpawnPacket->m_Roll) / 8;
// Spawn it on clients
if (a_PickupSpawnPacket->m_Item != E_ITEM_EMPTY)
@@ -116,12 +111,12 @@ cPacket * cPickup::GetSpawnPacket(void) const
PickupSpawn->m_Item = (short)m_Item->m_ItemID;
PickupSpawn->m_Count = m_Item->m_ItemCount;
PickupSpawn->m_Health = m_Item->m_ItemHealth;
- PickupSpawn->m_PosX = (int) (m_Pos->x * 32);
- PickupSpawn->m_PosY = (int) (m_Pos->y * 32);
- PickupSpawn->m_PosZ = (int) (m_Pos->z * 32);
- PickupSpawn->m_Rotation = (char)(m_Speed->x * 8);
- PickupSpawn->m_Pitch = (char)(m_Speed->y * 8);
- PickupSpawn->m_Roll = (char)(m_Speed->z * 8);
+ PickupSpawn->m_PosX = (int) (m_Pos.x * 32);
+ PickupSpawn->m_PosY = (int) (m_Pos.y * 32);
+ PickupSpawn->m_PosZ = (int) (m_Pos.z * 32);
+ PickupSpawn->m_Rotation = (char)(m_Speed.x * 8);
+ PickupSpawn->m_Pitch = (char)(m_Speed.y * 8);
+ PickupSpawn->m_Roll = (char)(m_Speed.z * 8);
return PickupSpawn;
}
@@ -148,7 +143,7 @@ void cPickup::Tick(float a_Dt)
return;
}
- if( m_Pos->y < 0 ) // Out of this world!
+ if( m_Pos.y < 0 ) // Out of this world!
{
Destroy();
return;
@@ -175,21 +170,21 @@ void cPickup::Tick(float a_Dt)
void cPickup::HandlePhysics(float a_Dt)
{
- m_ResultingSpeed->Set(0.f, 0.f, 0.f);
+ m_ResultingSpeed.Set(0.f, 0.f, 0.f);
cWorld * World = GetWorld();
if( m_bOnGround ) // check if it's still on the ground
{
- int BlockX = (m_Pos->x)<0 ? (int)m_Pos->x-1 : (int)m_Pos->x;
- int BlockZ = (m_Pos->z)<0 ? (int)m_Pos->z-1 : (int)m_Pos->z;
- char BlockBelow = World->GetBlock( BlockX, (int)m_Pos->y -1, BlockZ );
+ int BlockX = (m_Pos.x)<0 ? (int)m_Pos.x-1 : (int)m_Pos.x;
+ int BlockZ = (m_Pos.z)<0 ? (int)m_Pos.z-1 : (int)m_Pos.z;
+ char BlockBelow = World->GetBlock( BlockX, (int)m_Pos.y -1, BlockZ );
//Not only air, falls through water ;)
if( BlockBelow == E_BLOCK_AIR || IsBlockWater(BlockBelow))
{
m_bOnGround = false;
}
- char Block = World->GetBlock( BlockX, (int)m_Pos->y - (int)m_bOnGround, BlockZ );
- char BlockIn = World->GetBlock( BlockX, (int)m_Pos->y, BlockZ );
+ char Block = World->GetBlock( BlockX, (int)m_Pos.y - (int)m_bOnGround, BlockZ );
+ char BlockIn = World->GetBlock( BlockX, (int)m_Pos.y, BlockZ );
if( IsBlockLava(Block) || Block == E_BLOCK_FIRE
|| IsBlockLava(BlockIn) || BlockIn == E_BLOCK_FIRE)
@@ -202,38 +197,38 @@ void cPickup::HandlePhysics(float a_Dt)
if( BlockIn != E_BLOCK_AIR && !IsBlockWater(BlockIn) ) // If in ground itself, push it out
{
m_bOnGround = true;
- m_Pos->y += 0.2;
+ m_Pos.y += 0.2;
m_bReplicated = false;
}
- m_Speed->x *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed->x) < 0.05 ) m_Speed->x = 0;
- m_Speed->z *= 0.7f/(1+a_Dt);
- if( fabs(m_Speed->z) < 0.05 ) m_Speed->z = 0;
+ m_Speed.x *= 0.7f/(1+a_Dt);
+ if( fabs(m_Speed.x) < 0.05 ) m_Speed.x = 0;
+ m_Speed.z *= 0.7f/(1+a_Dt);
+ if( fabs(m_Speed.z) < 0.05 ) m_Speed.z = 0;
}
//get flowing direction
- Direction WaterDir = World->GetWaterSimulator()->GetFlowingDirection((int) m_Pos->x - 1, (int) m_Pos->y, (int) m_Pos->z - 1);
+ Direction WaterDir = World->GetWaterSimulator()->GetFlowingDirection((int) m_Pos.x - 1, (int) m_Pos.y, (int) m_Pos.z - 1);
- *m_WaterSpeed *= 0.9f; //Keep old speed but lower it
+ m_WaterSpeed *= 0.9f; //Keep old speed but lower it
switch(WaterDir)
{
case X_PLUS:
- m_WaterSpeed->x = 1.f;
+ m_WaterSpeed.x = 1.f;
m_bOnGround = false;
break;
case X_MINUS:
- m_WaterSpeed->x = -1.f;
+ m_WaterSpeed.x = -1.f;
m_bOnGround = false;
break;
case Z_PLUS:
- m_WaterSpeed->z = 1.f;
+ m_WaterSpeed.z = 1.f;
m_bOnGround = false;
break;
case Z_MINUS:
- m_WaterSpeed->z = -1.f;
+ m_WaterSpeed.z = -1.f;
m_bOnGround = false;
break;
@@ -241,53 +236,53 @@ void cPickup::HandlePhysics(float a_Dt)
break;
}
- *m_ResultingSpeed += *m_WaterSpeed;
+ m_ResultingSpeed += m_WaterSpeed;
if( !m_bOnGround )
{
float Gravity = -9.81f*a_Dt;
- m_Speed->y += Gravity;
+ m_Speed.y += Gravity;
// Set to hit position
- *m_ResultingSpeed += *m_Speed;
+ m_ResultingSpeed += m_Speed;
cTracer Tracer( GetWorld() );
- int Ret = Tracer.Trace( *m_Pos, *m_Speed, 2 );
+ int Ret = Tracer.Trace( m_Pos, m_Speed, 2 );
if( Ret ) // Oh noez! we hit something
{
- if( (*Tracer.RealHit - Vector3f(*m_Pos)).SqrLength() <= ( *m_ResultingSpeed * a_Dt ).SqrLength() )
+ if( (Tracer.RealHit - Vector3f(m_Pos)).SqrLength() <= ( m_ResultingSpeed * a_Dt ).SqrLength() )
{
m_bReplicated = false; // It's only interesting to replicate when we actually hit something...
if( Ret == 1 )
{
- if( Tracer.HitNormal->x != 0.f ) m_Speed->x = 0.f;
- if( Tracer.HitNormal->y != 0.f ) m_Speed->y = 0.f;
- if( Tracer.HitNormal->z != 0.f ) m_Speed->z = 0.f;
+ if( Tracer.HitNormal.x != 0.f ) m_Speed.x = 0.f;
+ if( Tracer.HitNormal.y != 0.f ) m_Speed.y = 0.f;
+ if( Tracer.HitNormal.z != 0.f ) m_Speed.z = 0.f;
- if( Tracer.HitNormal->y > 0 ) // means on ground
+ if( Tracer.HitNormal.y > 0 ) // means on ground
{
m_bOnGround = true;
}
}
- *m_Pos = Tracer.RealHit;
- *m_Pos += *Tracer.HitNormal * 0.2f;
+ m_Pos = Tracer.RealHit;
+ m_Pos += Tracer.HitNormal * 0.2f;
}
else
- *m_Pos += *m_ResultingSpeed*a_Dt;
+ m_Pos += m_ResultingSpeed*a_Dt;
}
else
{ // We didn't hit anything, so move =]
- *m_Pos += *m_ResultingSpeed * a_Dt;
+ m_Pos += m_ResultingSpeed * a_Dt;
}
}
//Usable for debugging
- //SetPosition(m_Pos->x, m_Pos->y, m_Pos->z);
+ //SetPosition(m_Pos.x, m_Pos.y, m_Pos.z);
}
diff --git a/source/cPickup.h b/source/cPickup.h
index 22af39367..26bce5029 100644
--- a/source/cPickup.h
+++ b/source/cPickup.h
@@ -34,10 +34,10 @@ public:
private:
- Vector3f * m_Speed;
- Vector3f * m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;)
+ Vector3f m_Speed;
+ Vector3f m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;)
- Vector3f * m_WaterSpeed;
+ Vector3f m_WaterSpeed;
bool m_bOnGround;
bool m_bReplicated;
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index e5d67c96e..36a27ca0a 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -98,9 +98,9 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
{
m_Inventory->Clear();
m_CreativeInventory->Clear();
- m_Pos->x = cRoot::Get()->GetDefaultWorld()->GetSpawnX();
- m_Pos->y = cRoot::Get()->GetDefaultWorld()->GetSpawnY();
- m_Pos->z = cRoot::Get()->GetDefaultWorld()->GetSpawnZ();
+ m_Pos.x = cRoot::Get()->GetDefaultWorld()->GetSpawnX();
+ m_Pos.y = cRoot::Get()->GetDefaultWorld()->GetSpawnY();
+ m_Pos.z = cRoot::Get()->GetDefaultWorld()->GetSpawnZ();
}
}
@@ -143,11 +143,11 @@ cPacket * cPlayer::GetSpawnPacket(void) const
cPacket_NamedEntitySpawn * SpawnPacket = new cPacket_NamedEntitySpawn;
SpawnPacket->m_UniqueID = m_UniqueID;
SpawnPacket->m_PlayerName = m_pState->PlayerName;
- SpawnPacket->m_PosX = (int)(m_Pos->x * 32);
- SpawnPacket->m_PosY = (int)(m_Pos->y * 32);
- SpawnPacket->m_PosZ = (int)(m_Pos->z * 32);
- SpawnPacket->m_Rotation = (char)((m_Rot->x / 360.f) * 256);
- SpawnPacket->m_Pitch = (char)((m_Rot->y / 360.f) * 256);
+ SpawnPacket->m_PosX = (int)(m_Pos.x * 32);
+ SpawnPacket->m_PosY = (int)(m_Pos.y * 32);
+ SpawnPacket->m_PosZ = (int)(m_Pos.z * 32);
+ SpawnPacket->m_Rotation = (char)((m_Rot.x / 360.f) * 256);
+ SpawnPacket->m_Pitch = (char)((m_Rot.y / 360.f) * 256);
SpawnPacket->m_CurrentItem = (short)m_Inventory->GetEquippedItem().m_ItemID;
return SpawnPacket;
}
@@ -242,20 +242,20 @@ void cPlayer::SetTouchGround( bool a_bTouchGround )
if( !m_bTouchGround )
{
cWorld* World = GetWorld();
- char BlockID = World->GetBlock( float2int(m_Pos->x), float2int(m_Pos->y), float2int(m_Pos->z) );
+ char BlockID = World->GetBlock( float2int(m_Pos.x), float2int(m_Pos.y), float2int(m_Pos.z) );
if( BlockID != E_BLOCK_AIR )
{
m_bTouchGround = true;
}
if( BlockID == E_BLOCK_WATER || BlockID == E_BLOCK_STATIONARY_WATER || BlockID == E_BLOCK_LADDER || BlockID == E_BLOCK_TORCH )
{
- m_LastGroundHeight = (float)m_Pos->y;
+ m_LastGroundHeight = (float)m_Pos.y;
}
}
if( m_bTouchGround )
{
- float Dist = (float)(m_LastGroundHeight - m_Pos->y);
+ float Dist = (float)(m_LastGroundHeight - m_Pos.y);
if( Dist > 4.f ) // Player dropped
{
int Damage = (int)(Dist - 4.f);
@@ -265,7 +265,7 @@ void cPlayer::SetTouchGround( bool a_bTouchGround )
}
}
- m_LastGroundHeight = (float)m_Pos->y;
+ m_LastGroundHeight = (float)m_Pos.y;
}
}
@@ -330,7 +330,7 @@ void cPlayer::KilledBy( cEntity* a_Killer )
float SpeedX = ((r1.randInt()%1000)-500) /100.f;
float SpeedY = ((r1.randInt()%1000)) /100.f;
float SpeedZ = ((r1.randInt()%1000)-500) /100.f;
- cPickup* Pickup = new cPickup( (int)(m_Pos->x*32), (int)(m_Pos->y*32), (int)(m_Pos->z*32), Items[i], SpeedX, SpeedY, SpeedZ );
+ cPickup* Pickup = new cPickup( (int)(m_Pos.x*32), (int)(m_Pos.y*32), (int)(m_Pos.z*32), Items[i], SpeedX, SpeedY, SpeedZ );
Pickup->Initialize( GetWorld() );
}
Items[i].Empty();
@@ -371,7 +371,7 @@ double cPlayer::GetEyeHeight()
Vector3d cPlayer::GetEyePosition()
{
- return Vector3d( m_Pos->x, m_Stance, m_Pos->z );
+ return Vector3d( m_Pos.x, m_Stance, m_Pos.z );
}
void cPlayer::OpenWindow( cWindow* a_Window )
@@ -853,17 +853,17 @@ bool cPlayer::LoadFromDisk()
Json::Value & JSON_PlayerPosition = root["position"];
if( JSON_PlayerPosition.size() == 3 )
{
- m_Pos->x = JSON_PlayerPosition[(unsigned int)0].asDouble();
- m_Pos->y = JSON_PlayerPosition[(unsigned int)1].asDouble();
- m_Pos->z = JSON_PlayerPosition[(unsigned int)2].asDouble();
+ m_Pos.x = JSON_PlayerPosition[(unsigned int)0].asDouble();
+ m_Pos.y = JSON_PlayerPosition[(unsigned int)1].asDouble();
+ m_Pos.z = JSON_PlayerPosition[(unsigned int)2].asDouble();
}
Json::Value & JSON_PlayerRotation = root["rotation"];
if( JSON_PlayerRotation.size() == 3 )
{
- m_Rot->x = (float)JSON_PlayerRotation[(unsigned int)0].asDouble();
- m_Rot->y = (float)JSON_PlayerRotation[(unsigned int)1].asDouble();
- m_Rot->z = (float)JSON_PlayerRotation[(unsigned int)2].asDouble();
+ m_Rot.x = (float)JSON_PlayerRotation[(unsigned int)0].asDouble();
+ m_Rot.y = (float)JSON_PlayerRotation[(unsigned int)1].asDouble();
+ m_Rot.z = (float)JSON_PlayerRotation[(unsigned int)2].asDouble();
}
m_Health = (short)root.get("health", 0 ).asInt();
@@ -886,14 +886,14 @@ bool cPlayer::SaveToDisk()
// create the JSON data
Json::Value JSON_PlayerPosition;
- JSON_PlayerPosition.append( Json::Value( m_Pos->x ) );
- JSON_PlayerPosition.append( Json::Value( m_Pos->y ) );
- JSON_PlayerPosition.append( Json::Value( m_Pos->z ) );
+ JSON_PlayerPosition.append( Json::Value( m_Pos.x ) );
+ JSON_PlayerPosition.append( Json::Value( m_Pos.y ) );
+ JSON_PlayerPosition.append( Json::Value( m_Pos.z ) );
Json::Value JSON_PlayerRotation;
- JSON_PlayerRotation.append( Json::Value( m_Rot->x ) );
- JSON_PlayerRotation.append( Json::Value( m_Rot->y ) );
- JSON_PlayerRotation.append( Json::Value( m_Rot->z ) );
+ JSON_PlayerRotation.append( Json::Value( m_Rot.x ) );
+ JSON_PlayerRotation.append( Json::Value( m_Rot.y ) );
+ JSON_PlayerRotation.append( Json::Value( m_Rot.z ) );
Json::Value JSON_Inventory;
m_Inventory->SaveToJson( JSON_Inventory );
diff --git a/source/cTracer.cpp b/source/cTracer.cpp
index b0a913da9..5cfc41b60 100644
--- a/source/cTracer.cpp
+++ b/source/cTracer.cpp
@@ -20,48 +20,16 @@
cTracer::cTracer(cWorld* a_World)
: m_World( a_World )
{
- m_NormalTable[0] = new Vector3f(-1, 0, 0);
- m_NormalTable[1] = new Vector3f( 0, 0,-1);
- m_NormalTable[2] = new Vector3f( 1, 0, 0);
- m_NormalTable[3] = new Vector3f( 0, 0, 1);
- m_NormalTable[4] = new Vector3f( 0, 1, 0);
- m_NormalTable[5] = new Vector3f( 0,-1, 0);
-
- DotPos = new Vector3f();
- BoxOffset = new Vector3f();
- BlockHitPosition = new Vector3f();
- HitNormal = new Vector3f();
- RealHit = new Vector3f();
-
-
- dir = new Vector3f();
- tDelta = new Vector3f();
- pos = new Vector3i();
- end1 = new Vector3i();
- step = new Vector3i();
- tMax = new Vector3f();
+ m_NormalTable[0].Set(-1, 0, 0);
+ m_NormalTable[1].Set( 0, 0,-1);
+ m_NormalTable[2].Set( 1, 0, 0);
+ m_NormalTable[3].Set( 0, 0, 1);
+ m_NormalTable[4].Set( 0, 1, 0);
+ m_NormalTable[5].Set( 0,-1, 0);
}
cTracer::~cTracer()
{
- for( int i = 0; i < 6; ++i )
- {
- delete m_NormalTable[i];
- m_NormalTable[i] = 0;
- }
-
- delete DotPos; DotPos = 0;
- delete BoxOffset; BoxOffset = 0;
- delete BlockHitPosition; BlockHitPosition = 0;
- delete HitNormal; HitNormal = 0;
- delete RealHit; RealHit = 0;
-
- delete dir; dir = 0;
- delete tDelta; tDelta = 0;
- delete pos; pos = 0;
- delete end1; end1 = 0;
- delete step; step = 0;
- delete tMax; tMax = 0;
}
float cTracer::SigNum( float a_Num )
@@ -74,60 +42,60 @@ float cTracer::SigNum( float a_Num )
void cTracer::SetValues( const Vector3f & a_Start, const Vector3f & a_Direction )
{
// calculate the direction of the ray (linear algebra)
- *dir = a_Direction;
+ dir = a_Direction;
// decide which direction to start walking in
- step->x = (int) SigNum(dir->x);
- step->y = (int) SigNum(dir->y);
- step->z = (int) SigNum(dir->z);
+ step.x = (int) SigNum(dir.x);
+ step.y = (int) SigNum(dir.y);
+ step.z = (int) SigNum(dir.z);
// normalize the direction vector
- if( dir->SqrLength() > 0.f ) dir->Normalize();
+ if( dir.SqrLength() > 0.f ) dir.Normalize();
// how far we must move in the ray direction before
// we encounter a new voxel in x-direction
// same but y-direction
- if( dir->x != 0.f ) tDelta->x = 1/fabs(dir->x);
- else tDelta->x = 0;
- if( dir->y != 0.f ) tDelta->y = 1/fabs(dir->y);
- else tDelta->y = 0;
- if( dir->z != 0.f ) tDelta->z = 1/fabs(dir->z);
- else tDelta->z = 0;
+ if( dir.x != 0.f ) tDelta.x = 1/fabs(dir.x);
+ else tDelta.x = 0;
+ if( dir.y != 0.f ) tDelta.y = 1/fabs(dir.y);
+ else tDelta.y = 0;
+ if( dir.z != 0.f ) tDelta.z = 1/fabs(dir.z);
+ else tDelta.z = 0;
// start voxel coordinates
// use your
// transformer
// function here
- pos->x = (int)floorf(a_Start.x);
- pos->y = (int)floorf(a_Start.y);
- pos->z = (int)floorf(a_Start.z);
+ pos.x = (int)floorf(a_Start.x);
+ pos.y = (int)floorf(a_Start.y);
+ pos.z = (int)floorf(a_Start.z);
// calculate distance to first intersection in the voxel we start from
- if(dir->x < 0)
+ if(dir.x < 0)
{
- tMax->x = ((float)pos->x - a_Start.x) / dir->x;
+ tMax.x = ((float)pos.x - a_Start.x) / dir.x;
}
else
{
- tMax->x = (((float)pos->x + 1) - a_Start.x) / dir->x;
+ tMax.x = (((float)pos.x + 1) - a_Start.x) / dir.x;
}
- if(dir->y < 0)
+ if(dir.y < 0)
{
- tMax->y = ((float)pos->y - a_Start.y) / dir->y;
+ tMax.y = ((float)pos.y - a_Start.y) / dir.y;
}
else
{
- tMax->y = (((float)pos->y + 1) - a_Start.y) / dir->y;
+ tMax.y = (((float)pos.y + 1) - a_Start.y) / dir.y;
}
- if(dir->z < 0)
+ if(dir.z < 0)
{
- tMax->z = ((float)pos->z - a_Start.z) / dir->z;
+ tMax.z = ((float)pos.z - a_Start.z) / dir.z;
}
else
{
- tMax->z = (((float)pos->z + 1) - a_Start.z) / dir->z;
+ tMax.z = (((float)pos.z + 1) - a_Start.z) / dir.z;
}
}
@@ -135,15 +103,15 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int
{
SetValues( a_Start, a_Direction );
- const Vector3f End = a_Start + ((*dir) * (float)a_Distance);
+ const Vector3f End = a_Start + (dir * (float)a_Distance);
// end voxel coordinates
- end1->x = (int)floorf(End.x);
- end1->y = (int)floorf(End.y);
- end1->z = (int)floorf(End.z);
+ end1.x = (int)floorf(End.x);
+ end1.y = (int)floorf(End.y);
+ end1.z = (int)floorf(End.z);
// check if first is occupied
- if( pos->Equals( end1 ) )
+ if( pos.Equals( end1 ) )
{
LOG("WARNING: cTracer: Start and end in same block");
return 0;
@@ -155,54 +123,54 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int
while ( Iterations < a_Distance )
{
Iterations++;
- if(tMax->x < tMax->y && tMax->x < tMax->z)
+ if(tMax.x < tMax.y && tMax.x < tMax.z)
{
- tMax->x += tDelta->x;
- pos->x += step->x;
+ tMax.x += tDelta.x;
+ pos.x += step.x;
}
- else if(tMax->y < tMax->z)
+ else if(tMax.y < tMax.z)
{
- tMax->y += tDelta->y;
- pos->y += step->y;
+ tMax.y += tDelta.y;
+ pos.y += step.y;
}
else
{
- tMax->z += tDelta->z;
- pos->z += step->z;
+ tMax.z += tDelta.z;
+ pos.z += step.z;
}
- if(step->x > 0.0f)
+ if(step.x > 0.0f)
{
- if(pos->x >= end1->x)
+ if(pos.x >= end1.x)
{
reachedX = true;
}
}
- else if(pos->x <= end1->x)
+ else if(pos.x <= end1.x)
{
reachedX = true;
}
- if(step->y > 0.0f)
+ if(step.y > 0.0f)
{
- if(pos->y >= end1->y)
+ if(pos.y >= end1.y)
{
reachedY = true;
}
}
- else if(pos->y <= end1->y)
+ else if(pos.y <= end1.y)
{
reachedY = true;
}
- if(step->z > 0.0f)
+ if(step.z > 0.0f)
{
- if(pos->z >= end1->z)
+ if(pos.z >= end1.z)
{
reachedZ = true;
}
}
- else if(pos->z <= end1->z)
+ else if(pos.z <= end1.z)
{
reachedZ = true;
}
@@ -212,15 +180,15 @@ int cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int
return false;
}
- char BlockID = m_World->GetBlock( pos->x, pos->y, pos->z );
+ char BlockID = m_World->GetBlock( pos.x, pos.y, pos.z );
//No collision with water ;)
if ( BlockID != E_BLOCK_AIR || IsBlockWater(BlockID))
{
- *BlockHitPosition = pos;
- int Normal = GetHitNormal(a_Start, End, *pos );
+ BlockHitPosition = pos;
+ int Normal = GetHitNormal(a_Start, End, pos );
if(Normal > 0)
{
- *HitNormal = *m_NormalTable[Normal-1];
+ HitNormal = m_NormalTable[Normal-1];
}
return 1;
}
@@ -276,7 +244,7 @@ int cTracer::intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f
return 0; // no intersection
//Vector3f I ( a_Ray->GetOrigin() + sI * u );//S.P0 + sI * u; // compute segment intersect point
- *RealHit = a_Origin + u * sI;
+ RealHit = a_Origin + u * sI;
return 1;
}
diff --git a/source/cTracer.h b/source/cTracer.h
index 3b7cd32c1..08ebc72e5 100644
--- a/source/cTracer.h
+++ b/source/cTracer.h
@@ -1,32 +1,34 @@
#pragma once
+#include "Vector3i.h"
+#include "Vector3f.h"
+
+
class cWorld;
-class Vector3i;
-class Vector3f;
class cTracer //tolua_export
{ //tolua_export
public: //tolua_export
- Vector3f* DotPos;
- Vector3f* BoxOffset;
+ Vector3f DotPos;
+ Vector3f BoxOffset;
cTracer( cWorld* a_World); //tolua_export
~cTracer(); //tolua_export
int Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance ); //tolua_export
void SetValues( const Vector3f & a_Start, const Vector3f & a_Direction ); //tolua_export
- Vector3f* BlockHitPosition; //tolua_export
- Vector3f* HitNormal; //tolua_export
- Vector3f* RealHit; //tolua_export
+ Vector3f BlockHitPosition; //tolua_export
+ Vector3f HitNormal; //tolua_export
+ Vector3f RealHit; //tolua_export
private:
int intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f & a_End, const Vector3f & a_PlanePos, const Vector3f & a_PlaneNormal );
int GetHitNormal( const Vector3f & start, const Vector3f & end, const Vector3i & a_BlockPos);
float SigNum( float a_Num );
cWorld* m_World;
- Vector3f* m_NormalTable[6];
+ Vector3f m_NormalTable[6];
- Vector3f* dir;
- Vector3f* tDelta;
- Vector3i* pos;
- Vector3i* end1;
- Vector3i* step;
- Vector3f* tMax;
+ Vector3f dir;
+ Vector3f tDelta;
+ Vector3i pos;
+ Vector3i end1;
+ Vector3i step;
+ Vector3f tMax;
}; //tolua_export \ No newline at end of file