Skip to content
Permalink
Browse files

Merge pull request #87 from polserver/executor-refactor

Privatize os_module in UOExecutor
  • Loading branch information...
turleypol committed Mar 22, 2019
2 parents fd9ae82 + f5fad28 commit 85cc4935a8d1d90552d56d8f9529a6ca50cdf064
@@ -32,7 +32,6 @@
#include "mobile/attribute.h"
#include "mobile/charactr.h"
#include "mobile/wornitems.h"
#include "module/osmod.h"
#include "module/uomod.h"
#include "network/client.h"
#include "network/pktdef.h"
@@ -555,7 +554,7 @@ void ClientCreateChar( Network::Client* client, PKTIN_00* msg )
ex->pushArg( make_mobileref( chr ) );

ex->addModule( new Module::UOExecutorModule( *ex ) );
ex->os_module->critical = true;
ex->critical(true);

if ( ex->setProgram( prog.get() ) )
{
@@ -939,7 +938,7 @@ void ClientCreateCharKR( Network::Client* client, PKTIN_8D* msg )
ex->pushArg( make_mobileref( chr ) );

ex->addModule( new Module::UOExecutorModule( *ex ) );
ex->os_module->critical = true;
ex->critical(true);

if ( ex->setProgram( prog.get() ) )
{
@@ -1358,7 +1357,7 @@ void ClientCreateChar70160( Network::Client* client, PKTIN_F8* msg )
ex->pushArg( make_mobileref( chr ) );

ex->addModule( new Module::UOExecutorModule( *ex ) );
ex->os_module->critical = true;
ex->critical(true);

if ( ex->setProgram( prog.get() ) )
{
@@ -26,7 +26,6 @@
#include "../bscript/objmethods.h"
#include "../clib/strutil.h"
#include "../plib/systemstate.h"
#include "module/osmod.h"
#include "module/uomod.h"
#include "polcfg.h"
#include "uoexec.h"
@@ -69,7 +68,6 @@ BObjectImp* ScriptExObjImp::call_method_id( const int id, Executor& ex, bool /*f
return new BError( "Script has been destroyed" );

Core::UOExecutor* uoexec = value().get_weakptr();
Module::OSExecutorModule* osemod = uoexec->os_module;

switch ( id )
{
@@ -106,7 +104,7 @@ BObjectImp* ScriptExObjImp::call_method_id( const int id, Executor& ex, bool /*f
if ( !ex.hasParams( 1 ) )
return new BError( "Not enough parameters" );
BObjectImp* param0 = ex.getParamImp( 0 );
if ( osemod->signal_event( param0->copy() ) )
if ( uoexec->signal_event( param0->copy() ) )
return new BLong( 1 );
else
return new BError( "Event queue is full, discarding event" );
@@ -116,9 +114,9 @@ BObjectImp* ScriptExObjImp::call_method_id( const int id, Executor& ex, bool /*f
uoexec->seterror( true );

// A Sleeping script would otherwise sit and wait until it wakes up to be killed.
osemod->revive();
if ( osemod->in_debugger_holdlist() )
osemod->revive_debugged();
uoexec->revive();
if ( uoexec->in_debugger_holdlist() )
uoexec->revive_debugged();

return new BLong( 1 );

@@ -129,7 +127,7 @@ BObjectImp* ScriptExObjImp::call_method_id( const int id, Executor& ex, bool /*f
}

case MTH_CLEAR_EVENT_QUEUE: // DAVE added this 11/20
return ( osemod->clear_event_queue() );
return ( uoexec->clear_event_queue() );

default:
return new BError( "undefined" );
@@ -169,14 +167,13 @@ BObjectRef ScriptExObjImp::get_member_id( const int id )
return BObjectRef( new BError( "Script has been destroyed" ) );

UOExecutor* uoexec = value().get_weakptr();
Module::OSExecutorModule* osemod = uoexec->os_module;
Module::UOExecutorModule* uoemod =
static_cast<Module::UOExecutorModule*>( uoexec->findModule( "UO" ) );

switch ( id )
{
case MBR_PID:
return BObjectRef( new BLong( osemod->pid() ) );
return BObjectRef( new BLong( uoexec->pid() ) );
case MBR_NAME:
return BObjectRef( new String( uoexec->scriptname() ) );
case MBR_STATE:
@@ -14,7 +14,6 @@
#include "../clib/rawtypes.h"
#include "item/item.h"
#include "mobile/charactr.h"
#include "module/osmod.h"
#include "module/uomod.h"
#include "network/cgdata.h"
#include "network/client.h"
@@ -23,6 +22,7 @@
#include "network/pktboth.h"
#include "ufunc.h"
#include "uoexec.h"
#include "uoexhelp.h"

namespace Pol
{
@@ -65,7 +65,7 @@ void handle_prompt( Network::Client* client, PKTBI_9A* msg )
}
}
}
uoemod->uoexec.os_module->revive();
uoemod->uoexec.revive();
uoemod->prompt_chr = nullptr;
client->gd->prompt_uoemod = nullptr;
}
@@ -6,7 +6,6 @@
#include "../../clib/passert.h"
#include "../../clib/stlutil.h"
#include "../../plib/systemstate.h"
#include "../module/osmod.h"
#include "../polsig.h"
#include "../uoexec.h"
#include "state.h"
@@ -177,12 +176,11 @@ void ScriptScheduler::run_ready()
passert_paranoid( ex != nullptr );
runlist.pop_front(); // remove it directly, since itr can get invalid during execution

Module::OSExecutorModule* os_module = ex->os_module;
Clib::scripts_thread_script = ex->scriptname();

int inscount = 0;
int totcount = 0;
int insleft = os_module->priority / priority_divide;
int insleft = ex->priority() / priority_divide;
if ( insleft == 0 )
insleft = 1;

@@ -197,7 +195,7 @@ void ScriptScheduler::run_ready()

THREAD_CHECKPOINT( scripts, 113 );

if ( os_module->blocked() )
if ( ex->blocked() )
{
ex->warn_runaway_on_cycle =
ex->instr_cycles + Plib::systemstate.config.runaway_script_threshold;
@@ -208,18 +206,18 @@ void ScriptScheduler::run_ready()
if ( ex->instr_cycles == ex->warn_runaway_on_cycle )
{
ex->runaway_cycles += Plib::systemstate.config.runaway_script_threshold;
if ( os_module->warn_on_runaway )
if ( ex->warn_on_runaway() )
{
fmt::Writer tmp;
tmp << "Runaway script[" << os_module->pid() << "]: " << ex->scriptname() << " ("
tmp << "Runaway script[" << ex->pid() << "]: " << ex->scriptname() << " ("
<< ex->runaway_cycles << " cycles)\n";
ex->show_context( tmp, ex->PC );
SCRIPTLOG << tmp.str();
}
ex->warn_runaway_on_cycle += Plib::systemstate.config.runaway_script_threshold;
}

if ( os_module->critical )
if ( ex->critical() )
{
++inscount;
++totcount;
@@ -257,7 +255,7 @@ void ScriptScheduler::run_ready()
{
ranlist.push_back( ex );
// ranlist.splice( ranlist.end(), runlist, itr );
ex->pParent->os_module->revive();
ex->pParent->revive();
}
else
{
@@ -272,30 +270,29 @@ void ScriptScheduler::run_ready()
}
continue;
}
else if ( !ex->os_module->blocked() )
else if ( !ex->blocked() )
{
THREAD_CHECKPOINT( scripts, 115 );

// runlist.erase( itr );
ex->os_module->in_hold_list_ = Module::OSExecutorModule::DEBUGGER_LIST;
ex->in_hold_list( Core::HoldListType::DEBUGGER_LIST );
debuggerholdlist.insert( ex );
continue;
}
}

if ( ex->os_module->blocked() )
if ( ex->blocked() )
{
THREAD_CHECKPOINT( scripts, 116 );

if ( ex->os_module->sleep_until_clock_ )
if ( ex->sleep_until_clock() )
{
ex->os_module->in_hold_list_ = Module::OSExecutorModule::TIMEOUT_LIST;
ex->os_module->hold_itr_ =
holdlist.insert( HoldList::value_type( ex->os_module->sleep_until_clock_, ex ) );
ex->in_hold_list( Core::HoldListType::TIMEOUT_LIST );
ex->hold_itr( holdlist.insert( HoldList::value_type( ex->sleep_until_clock(), ex ) ) );
}
else
{
ex->os_module->in_hold_list_ = Module::OSExecutorModule::NOTIMEOUT_LIST;
ex->in_hold_list( Core::HoldListType::NOTIMEOUT_LIST );
notimeoutholdlist.insert( ex );
}

@@ -23,6 +23,27 @@ typedef std::map<std::string, ref_ptr<Bscript::EScriptProgram>, Clib::ci_cmp_pre
typedef std::map<unsigned int, UOExecutor*> PidList;
typedef HoldList::iterator TimeoutHandle;


enum HoldListType
{
NO_LIST,
TIMEOUT_LIST,
NOTIMEOUT_LIST,
DEBUGGER_LIST
};

enum WAIT_TYPE
{
WAIT_SLEEP,
WAIT_EVENT,
WAIT_UNKNOWN
};

enum
{
MAX_EVENTQUEUE_SIZE = 20
};

class ScriptScheduler
{
public:
@@ -124,7 +124,6 @@
#include "../mdelta.h"
#include "../miscrgn.h"
#include "../mkscrobj.h"
#include "../module/osmod.h"
#include "../module/uomod.h"
#include "../movecost.h"
#include "../multi/customhouses.h"
@@ -503,9 +502,9 @@ void Character::stop_skill_script()
// this will force the execution engine to stop running this script immediately
// dont delete the executor here, since it could currently run
script_ex->seterror( true );
script_ex->os_module->revive();
if ( script_ex->os_module->in_debugger_holdlist() )
script_ex->os_module->revive_debugged();
script_ex->revive();
if ( script_ex->in_debugger_holdlist() )
script_ex->revive_debugged();
}
}

@@ -1949,7 +1948,7 @@ void Character::run_hit_script( Character* defender, double damage )
ex->pushArg( new Module::ECharacterRefObjImp( defender ) );
ex->pushArg( new Module::ECharacterRefObjImp( this ) );

ex->os_module->priority = 100;
ex->priority(100);

if ( ex->setProgram( prog.get() ) )
{
@@ -14,7 +14,6 @@
#include "../../plib/systemstate.h"
#include "../item/item.h"
#include "../item/itemdesc.h"
#include "../module/osmod.h"
#include "../module/uomod.h"
#include "../scrdef.h"
#include "../scrsched.h"
@@ -59,7 +58,7 @@ bool Character::start_script( Bscript::EScriptProgram* prog, bool start_attached
ex->pushArg( new Module::ECharacterRefObjImp( this ) );
}

ex->os_module->priority = 100;
ex->priority(100);

if ( ex->setProgram( prog ) )
{
@@ -109,7 +108,7 @@ void Item::walk_on( Mobile::Character* chr )
ex->pushArg( new Module::ECharacterRefObjImp( chr ) );
}

ex->os_module->priority = 100;
ex->priority(100);

if ( ex->setProgram( prog.get() ) )
{
@@ -47,7 +47,6 @@
#include "../listenpt.h"
#include "../mdelta.h"
#include "../module/npcmod.h"
#include "../module/osmod.h"
#include "../module/uomod.h"
#include "../multi/multi.h"
#include "../npctmpl.h"
@@ -116,9 +115,9 @@ void NPC::stop_scripts()
// this will force the execution engine to stop running this script immediately
// dont delete the executor here, since it could currently run
ex->seterror( true );
ex->os_module->revive();
if ( ex->os_module->in_debugger_holdlist() )
ex->os_module->revive_debugged();
ex->revive();
if ( ex->in_debugger_holdlist() )
ex->revive_debugged();
}
}

@@ -556,9 +555,9 @@ void NPC::restart_script()
{
ex->seterror( true );
// A Sleeping script would otherwise sit and wait until it wakes up to be killed.
ex->os_module->revive();
if ( ex->os_module->in_debugger_holdlist() )
ex->os_module->revive_debugged();
ex->revive();
if ( ex->in_debugger_holdlist() )
ex->revive_debugged();
ex = nullptr;
// when the NPC executor module destructs, it checks this NPC to see if it points
// back at it. If not, it leaves us alone.
@@ -582,9 +581,9 @@ void NPC::on_death( Items::Item* corpse )
{
// this will force the execution engine to stop running this script immediately
ex->seterror( true );
ex->os_module->revive();
if ( ex->os_module->in_debugger_holdlist() )
ex->os_module->revive_debugged();
ex->revive();
if ( ex->in_debugger_holdlist() )
ex->revive_debugged();
}

destroy();
@@ -11,7 +11,6 @@
#include "../../clib/wnsckt.h"
#include "../../plib/systemstate.h"
#include "../uoexec.h"
#include "osmod.h"


namespace Pol
@@ -72,7 +71,7 @@ BObjectImp* HttpExecutorModule::mf_WriteHtml()
else
{
continuing_offset += nsent;
uoexec.os_module->SleepForMs( 500 );
uoexec.SleepForMs( 500 );
--uoexec.PC;
return uoexec.fparams[0]->impptr();
}
@@ -110,7 +109,7 @@ BObjectImp* HttpExecutorModule::mf_WriteHtmlRaw()
else
{
continuing_offset += nsent;
uoexec.os_module->SleepForMs( 500 );
uoexec.SleepForMs( 500 );
--uoexec.PC;
return uoexec.fparams[0]->impptr();
}
Oops, something went wrong.

0 comments on commit 85cc493

Please sign in to comment.
You can’t perform that action at this time.