Skip to content

Commit

Permalink
converted multidef (#441)
Browse files Browse the repository at this point in the history
* converted multidef
added to the testsuite a big multi
ListMultisInBox now uses the update range, but since its the only spot
and the chances are low that someone really has such a big multi
corechanges are not really worth it I would say

* Fixed a few grid bugs, one endless loop and changed the range a chr can move while customhouse is active
  • Loading branch information
turleypol committed Nov 9, 2021
1 parent 6263819 commit 3306c5e
Show file tree
Hide file tree
Showing 28 changed files with 538 additions and 616 deletions.
11 changes: 6 additions & 5 deletions pol-core/pol/base/position.cpp
Expand Up @@ -25,11 +25,6 @@ const std::array<Vec2d, 8> move_delta = { { { 0, -1 }, // 0 is N
const std::array<UFACING, 8> away_cvt = { FACING_S, FACING_SW, FACING_W, FACING_NW,
FACING_N, FACING_NE, FACING_E, FACING_SE };

s8 clip_s8( int v )
{
return static_cast<s8>( std::clamp( v, static_cast<int>( std::numeric_limits<s8>::min() ),
static_cast<int>( std::numeric_limits<s8>::max() ) ) );
}
u16 clip_u16( int v )
{
return static_cast<u16>(
Expand Down Expand Up @@ -278,6 +273,12 @@ Pos3d& Pos3d::crop( const Realms::Realm* realm )
return *this;
}

s8 Pos3d::clip_s8( int v )
{
return static_cast<s8>( std::clamp( v, static_cast<int>( std::numeric_limits<s8>::min() ),
static_cast<int>( std::numeric_limits<s8>::max() ) ) );
}

fmt::Writer& operator<<( fmt::Writer& w, const Pos3d& v )
{
w << "( " << v.x() << ", " << v.y() << ", " << (int)v.z() << " )";
Expand Down
2 changes: 2 additions & 0 deletions pol-core/pol/base/position.h
Expand Up @@ -122,6 +122,8 @@ class Pos3d
bool in_range( const Pos2d& other, u16 range ) const;
bool in_range( const Pos3d& other, u16 range ) const;
Pos3d& crop( const Realms::Realm* realm );

static s8 clip_s8( int v );
};
Pos3d operator-( Pos3d lhs, const Vec2d& rhs );
Pos3d operator+( Pos3d lhs, const Vec2d& rhs );
Expand Down
20 changes: 19 additions & 1 deletion pol-core/pol/globals/uvars.cpp
Expand Up @@ -15,6 +15,7 @@

#include "uvars.h"

#include <algorithm>
#include <string.h>

#include "../../bscript/bobject.h"
Expand All @@ -35,6 +36,7 @@
#include "../loadunld.h"
#include "../mobile/attribute.h"
#include "../multi/boat.h"
#include "../multi/multidef.h"
#include "../npctmpl.h"
#include "../objecthash.h"
#include "../party.h"
Expand Down Expand Up @@ -171,7 +173,7 @@ GameState::GameState()
paramtextcmds(),
uo_skills(),
task_thread_pool(),
update_range( RANGE_VISUAL )
update_range( (s16)RANGE_VISUAL, (s16)RANGE_VISUAL )
{
memset( &mount_action_xlate, 0, sizeof( mount_action_xlate ) );
}
Expand All @@ -182,6 +184,22 @@ GameState::~GameState()
// or make sure that the globals get deconstructed before eg the flyweight string container
}


void GameState::update_range_from_multis()
{
for ( const auto& m_pair : Multi::multidef_buffer.multidefs_by_multiid )
{
if ( m_pair.second == nullptr )
continue;
auto* mdef = m_pair.second;
s16 maxrel = (s16)std::max( { std::abs( mdef->minrxyz.x() ), std::abs( mdef->minrxyz.y() ),
std::abs( mdef->maxrxyz.x() ), std::abs( mdef->maxrxyz.y() ) } ) +
1;
if ( maxrel > update_range.x() )
update_range.x( maxrel ).y( maxrel );
}
}

void display_leftover_objects();

void GameState::deinitialize()
Expand Down
6 changes: 4 additions & 2 deletions pol-core/pol/globals/uvars.h
Expand Up @@ -33,6 +33,7 @@
#include "../tasks.h"
#include "../textcmd.h"
#include "../uoskills.h"
#include "base/vector.h"
#include "regions/region.h"


Expand Down Expand Up @@ -249,8 +250,9 @@ class GameState
};
threadhelp::TaskThreadPool task_thread_pool;

u8 update_range; // maximum update range (client view range/multi footprint) used as
// "pre-filtering" of objects
void update_range_from_multis();
Core::Vec2d update_range; // maximum update range (client view range/multi footprint) used as
// "pre-filtering" of objects

private:
void cleanup_vars();
Expand Down
14 changes: 9 additions & 5 deletions pol-core/pol/loadunld.cpp
Expand Up @@ -11,19 +11,23 @@

#include <string>

#include "../clib/strutil.h"
#include "../plib/pkg.h"
#include "../plib/systemstate.h"
#include "../plib/tiles.h"
#include "clib/strutil.h"
#include "plib/pkg.h"
#include "plib/systemstate.h"
#include "plib/tiles.h"

#include "checkpnt.h"
#include "cmbtcfg.h"
#include "console.h"
#include "extobj.h"
#include "globals/multidefs.h"
#include "globals/settings.h"
#include "globals/uvars.h"
#include "item/equipmnt.h"
#include "item/itemdesc.h"
#include "landtile.h"
#include "mobile/attribute.h"
#include "multi/multidef.h"
#include "objtype.h"
#include "polcfg.h"

Expand All @@ -43,7 +47,6 @@ void load_armor_zones();
namespace Multi
{
void load_special_storedconfig( const std::string& cfgname );
void read_multidefs();
void read_boat_cfg();
} // namespace Multi
namespace Network
Expand Down Expand Up @@ -165,6 +168,7 @@ void load_data()

checkpoint( "read_multidefs" );
Multi::read_multidefs();
gamestate.update_range_from_multis();

checkpoint( "set_watch_vars" );
set_watch_vars();
Expand Down
7 changes: 5 additions & 2 deletions pol-core/pol/mobile/charactr.cpp
Expand Up @@ -3779,8 +3779,11 @@ bool Character::CustomHousingMove( unsigned char i_dir )
newpos.z( house->z() +
Multi::CustomHouseDesign::custom_house_z_xlate_table[house->editing_floor_num] );
const Multi::MultiDef& def = house->multidef();
if ( newpos.x() > ( house->x() + def.minrx ) && newpos.x() <= ( house->x() + def.maxrx ) &&
newpos.y() > ( house->y() + def.minry ) && newpos.y() <= ( house->y() + def.maxry ) )
auto relpos = newpos - house->pos().xy();
// minx and y are wall elements and z is 7
// mobile will look like flying when allowing the min coords
if ( def.within_multi( relpos ) && relpos.x() != def.minrxyz.x() &&
relpos.y() != def.minrxyz.y() )
{
setposition( newpos );
MoveCharacterWorldPosition( lastx, lasty, x(), y(), this, nullptr );
Expand Down

0 comments on commit 3306c5e

Please sign in to comment.