diff --git a/code/ryzom/server/src/ai_service/script_vm.cpp b/code/ryzom/server/src/ai_service/script_vm.cpp index 243110520..61d54988b 100644 --- a/code/ryzom/server/src/ai_service/script_vm.cpp +++ b/code/ryzom/server/src/ai_service/script_vm.cpp @@ -132,11 +132,13 @@ void CScriptVM::interpretCode( size_t index = startIndex; string currentString; + nldebug("interpretCode start - thisContext %lx", thisContext); while (index < opcodes.size()) { #if !FINAL_VERSION EOpcode op = (EOpcode)opcodes[index]; #endif + nldebug("%d", opcodes[index]); switch (opcodes[index]) { @@ -146,9 +148,11 @@ void CScriptVM::interpretCode( nlassert(false); break; case EOP: + nldebug("EOP"); return; // End Of Program case EQ: // == Need: Value1: Value2 After: Value1==Value2 (Boolean as float) + nldebug("EQ"); { const float res=stack.top(1)==stack.top()?1.f:0.f; stack.pop(); @@ -157,6 +161,7 @@ void CScriptVM::interpretCode( } continue; case NEQ: // != Need: Value1: Value2 After: Value1!=Value2 (Boolean as float) + nldebug("NEQ"); { const float res=stack.top(1)!=stack.top()?1.f:0.f; stack.pop(); @@ -165,6 +170,7 @@ void CScriptVM::interpretCode( } continue; case INF: // < Need: Value1: Value2 After: Value1 Need: Value1: Value2 After: Value1>Value2 (Boolean as float) + nldebug("SUP"); { const float res=stack.top(1)>stack.top()?1.f:0.f; stack.pop(); @@ -189,6 +197,7 @@ void CScriptVM::interpretCode( } continue; case SUPEQ: // >= Need: Value1: Value2 After: Value1>=Value2 (Boolean as float) + nldebug("SUPEQ"); { const float res=stack.top(1)>=stack.top()?1.f:0.f; stack.pop(); @@ -197,6 +206,7 @@ void CScriptVM::interpretCode( } continue; case ADD: // + Need: Value1: Value2 After: Value1+Value2 + nldebug("ADD"); { CScriptStack::CStackEntry &entry0=stack.top(); CScriptStack::CStackEntry &entry1=stack.top(1); @@ -232,6 +242,7 @@ void CScriptVM::interpretCode( } continue; case SUB: // - Need: Value1: Value2 After: Value1-Value2 + nldebug("SUB"); { const float val=stack.top(); stack.pop(); @@ -240,6 +251,7 @@ void CScriptVM::interpretCode( } continue; case MUL: // * Need: Value1: Value2 After: Value1/Value2 + nldebug("MUL"); { float &res=stack.top(1); res*=(float&)stack.top(); @@ -248,6 +260,7 @@ void CScriptVM::interpretCode( } continue; case DIV: // / Need: Value1: Value2 After: Value1/Value2 !Exception Gestion. + nldebug("DIV"); { float &res=stack.top(1); const float &divisor=stack.top(); @@ -260,6 +273,7 @@ void CScriptVM::interpretCode( } continue; case AND: // && Need: Value1: Value2 After: Value1&&Value2 + nldebug("AND"); { const bool val1=(float&)stack.top(1)!=0.f; const bool val2=(float&)stack.top()!=0.f; @@ -269,6 +283,7 @@ void CScriptVM::interpretCode( } continue; case OR: // || Need: Value1: Value2 After: Value1||Value2 + nldebug("OR"); { const bool val1=(float&)stack.top(1)!=0.f; const bool val2=(float&)stack.top()!=0.f; @@ -278,6 +293,7 @@ void CScriptVM::interpretCode( } continue; case NOT: // ! Need: Value After: !Value + nldebug("NOT"); { float &val=stack.top(); val=(val==0.f)?1.f:0.f; @@ -285,18 +301,21 @@ void CScriptVM::interpretCode( } continue; case PUSH_ON_STACK: // Set a Value (float) Need: - After: Value(float) + nldebug("PUSH_ON_STACK"); { stack.push(*((float*)&opcodes[index+1])); index+=2; } continue; case POP: // Pop Need: ValToPop After: - + nldebug("POP"); { stack.pop(); index++; } continue; case SET_VAR_VAL: // Set a Value to a Var. Need: VarName: VarValue After: - + nldebug("SET_VAR_VAL"); { float f = 0.0f; switch (stack.top().type()) @@ -321,6 +340,7 @@ void CScriptVM::interpretCode( } continue; case SET_STR_VAR_VAL: // Set a Value to a Var. Need: VarName: VarValue After: - + nldebug("SET_STR_VAR_VAL"); { switch (stack.top().type()) { @@ -344,6 +364,7 @@ void CScriptVM::interpretCode( } continue; case SET_CTX_VAR_VAL: // Set a Value to a Var. Need: VarName: VarValue After: - + nldebug("SET_CTX_VAR_VAL"); { switch (stack.top().type()) { @@ -361,6 +382,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_VAR_VAL: // Push the Value of a Var. Need: - (VarName on next IP) After: VarValue(float) + nldebug("PUSH_VAR_VAL"); { const float f=thisContext->getLogicVar(*((TStringId*)&opcodes[index+1])); stack.push(f); @@ -368,6 +390,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_STR_VAR_VAL: // Push the Value of a Var. Need: - (VarName on next IP) After: VarValue(float) + nldebug("PUSH_STR_VAR_VAL"); { std::string str = thisContext->getStrLogicVar(*((TStringId*)&opcodes[index+1])); stack.push(str); @@ -375,6 +398,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_CTX_VAR_VAL: // Push the Value of a Var. Need: - (VarName on next IP) After: VarValue(float) + nldebug("PUSH_CTX_VAR_VAL"); { IScriptContext* ctx = thisContext->getCtxLogicVar(*((TStringId*)&opcodes[index+1])); stack.push(ctx); @@ -581,6 +605,7 @@ void CScriptVM::interpretCode( continue; */ case SET_CONTEXT_VAR_VAL: + nldebug("SET_CONTEXT_VAR_VAL"); { IScriptContext* otherContext = (IScriptContext*)0; switch (stack.top().type()) @@ -619,6 +644,7 @@ void CScriptVM::interpretCode( } continue; case SET_CONTEXT_STR_VAR_VAL: + nldebug("SET_CONTEXT_STR_VAR_VAL"); { IScriptContext* otherContext = (IScriptContext*)0; switch (stack.top().type()) @@ -657,6 +683,7 @@ void CScriptVM::interpretCode( } continue; case SET_CONTEXT_CTX_VAR_VAL: + nldebug("SET_CONTEXT_CTX_VAR_VAL"); { IScriptContext* otherContext = (IScriptContext*)0; switch (stack.top().type()) @@ -689,6 +716,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_CONTEXT_VAR_VAL: + nldebug("PUSH_CONTEXT_VAR_VAL"); { IScriptContext* otherContext = (IScriptContext*)0; switch (stack.top().type()) @@ -714,6 +742,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_CONTEXT_STR_VAR_VAL: + nldebug("PUSH_CONTEXT_STR_VAR_VAL"); { IScriptContext* otherContext = (IScriptContext*)0; switch (stack.top().type()) @@ -737,6 +766,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_CONTEXT_CTX_VAR_VAL: + nldebug("PUSH_CONTEXT_CTX_VAR_VAL"); { IScriptContext* otherContext = (IScriptContext*)0; switch (stack.top().type()) @@ -760,11 +790,13 @@ void CScriptVM::interpretCode( } continue; case JUMP: // Jump + nb size_t to jump (relative). Need: NewJumpOffset After: - + nldebug("JUMP"); { index+=opcodes[index+1]+1; // AGI .. Not Opt } continue; case JE: // Jump if last stack value is FALSE(==0). Need: BoolValue(float) (NewJumpOffset on Next Ip) After: - + nldebug("JE"); { if ((float&)stack.top()==0.f) index+=opcodes[index+1]+1; // AGI .. Not Opt @@ -774,6 +806,7 @@ void CScriptVM::interpretCode( } continue; case JNE: // Jump if last stack value is TRUE(!=0). Need: BoolValue(float) (NewJumpOffset on Next Ip) After: - + nldebug("JNE"); { if ((float&)stack.top()!=0.f) index+=opcodes[index+1]+1; // AGI .. Not Opt @@ -783,12 +816,14 @@ void CScriptVM::interpretCode( } continue; case PUSH_PRINT_STRING: + nldebug("PUSH_PRINT_STRING"); { currentString+=CStringMapper::unmap(*((TStringId*)&opcodes[index+1])); // strPt.substr(1,strPt.size()-2); index+=2; } continue; case PUSH_PRINT_VAR: + nldebug("PUSH_PRINT_VAR"); { float const val = thisContext->getLogicVar(*((TStringId*)&opcodes[index+1])); currentString += NLMISC::toString("%g", val); @@ -796,6 +831,7 @@ void CScriptVM::interpretCode( } continue; case PUSH_PRINT_STR_VAR: + nldebug("PUSH_PRINT_STR_VAR"); { string const str = thisContext->getStrLogicVar(*((TStringId*)&opcodes[index+1])); currentString += str; @@ -803,6 +839,7 @@ void CScriptVM::interpretCode( } continue; case PRINT_STRING: + nldebug("PRINT_STRING"); { if (AIScriptDisplayPrint) { @@ -813,6 +850,7 @@ void CScriptVM::interpretCode( } continue; case LOG_STRING: + nldebug("LOG_STRING"); { if (AIScriptDisplayLog) { @@ -823,6 +861,7 @@ void CScriptVM::interpretCode( } continue; case FUNCTION: + nldebug("FUNCTION"); { // on_event TStringId const eventName = *((TStringId*)&opcodes[index+1]); @@ -835,6 +874,7 @@ void CScriptVM::interpretCode( } continue; case CALL: + nldebug("CALL"); { // set_event const TStringId eventName=*((TStringId*)&opcodes[index+1]); @@ -850,11 +890,13 @@ void CScriptVM::interpretCode( case PUSH_THIS: { IScriptContext* const sc=thisContext; + nldebug("PUSH_THIS (%lx)", sc); stack.push(sc); index++; } continue; case PUSH_GROUP: + nldebug("PUSH_GROUP"); { const TStringId strId=*((TStringId*)&opcodes[index+1]); @@ -881,11 +923,13 @@ void CScriptVM::interpretCode( case PUSH_STRING: { const string &str = CStringMapper::unmap(*((TStringId*)&opcodes[index+1])); + nldebug("PUSH_STRING (%s)", str.c_str()); stack.push(str); index+=2; } continue; case ASSIGN_FUNC_FROM: + nldebug("ASSIGN_FUNC_FROM"); { const TStringId srcFunc=CStringMapper::map(stack.top()); stack.pop(); @@ -910,6 +954,7 @@ void CScriptVM::interpretCode( } continue; case NATIVE_CALL: + nldebug("NATIVE_CALL"); { IScriptContext* const sc = stack.top(); stack.pop(); @@ -919,6 +964,7 @@ void CScriptVM::interpretCode( string const& outParamsSig = CStringMapper::unmap(*((TStringId*)&opcodes[++index])); if (sc) { + nldebug ("launch callNativeCallBack: %lx funcName:%s mode:%d inParamsSig:'%s' outParamsSig:'%s'", sc, funcName.c_str(), mode, inParamsSig.c_str(), outParamsSig.c_str()); sc->callNativeCallBack(thisContext, funcName, mode, inParamsSig, outParamsSig, &stack); } else @@ -949,6 +995,7 @@ void CScriptVM::interpretCode( } continue; case RAND: + nldebug("RAND"); { const size_t randIndex=rand32((uint32)opcodes[index+1]); // rand(RANDCOUNT) index+=3; // pass RAND + RANDCOUNT + 1 @@ -960,12 +1007,14 @@ void CScriptVM::interpretCode( } continue; case RET: + nldebug("RET"); { index=(int&)stack.top(); stack.pop(); } continue; case ONCHILDREN: + nldebug("ONCHILDREN"); { if (thisContext) { @@ -975,6 +1024,7 @@ void CScriptVM::interpretCode( } continue; case SWITCH: + nldebug("SWITCH"); { // !!!!! size_t compValue=0; @@ -1027,6 +1077,7 @@ void CScriptVM::interpretCode( } continue; case INCR: // Increment top of stack. + nldebug("INCR"); { float &f = stack.top(); ++f; @@ -1034,6 +1085,7 @@ void CScriptVM::interpretCode( } continue; case DECR: // Decrement top of stack. + nldebug("DECR"); { float &f = stack.top(); --f; @@ -1041,12 +1093,14 @@ void CScriptVM::interpretCode( } continue; case CONCAT: // Concatenates 2 strings + nldebug("CONCAT"); { (string&)stack.top(1) += (string&)stack.top(); stack.pop(); } continue; case FTOS: // Convert a float to a string + nldebug("FTOS"); { stack.top()=NLMISC::toString("%g", (float&)stack.top()); } @@ -1054,6 +1108,7 @@ void CScriptVM::interpretCode( } nlassert(false); // must use continue !! Not implemented. } + nldebug("interpretCode end"); } } diff --git a/code/ryzom/server/src/ai_service/script_vm.h b/code/ryzom/server/src/ai_service/script_vm.h index 0b931c63d..15a9f4121 100644 --- a/code/ryzom/server/src/ai_service/script_vm.h +++ b/code/ryzom/server/src/ai_service/script_vm.h @@ -21,6 +21,7 @@ //#include "ai_grp.h" #include +#include namespace AIVM { @@ -310,6 +311,7 @@ inline CByteCode::CByteCode(std::string const& sourceName) : _sourceName(sourceName) { + nldebug("[%lx]", this); } inline @@ -334,17 +336,20 @@ inline CScriptStack::CStackEntry::CStackEntry() : _type(ENone) { + nldebug("[%lx]", this); } inline CScriptStack::CStackEntry::~CStackEntry() { + nldebug("[%lx]", this); clean(); } inline void CScriptStack::CStackEntry::clean() { + nldebug("[%lx]", this); if (_type==EString) delete &getString(); } @@ -352,6 +357,7 @@ void CScriptStack::CStackEntry::clean() inline CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(float const& f) { + nldebug("[%lx] float:'%f'", this, f); clean(); _valf = f; _type = EFloat; @@ -360,6 +366,7 @@ CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(float const& f) inline CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(int const& i) { + nldebug("[%lx] int:'%d'", this, i); clean(); _vali = i; _type = EOther; @@ -368,6 +375,7 @@ CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(int const& i) inline CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(std::string const& str) { + nldebug("[%lx] string:'%s'", this, str.c_str()); clean(); std::string* const strPt = new std::string(str); _valsp = strPt; @@ -377,6 +385,7 @@ CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(std::string cons inline CScriptStack::CStackEntry& CScriptStack::CStackEntry::operator=(IScriptContext* sc) { + nldebug("[%lx] IScriptContext:[%lx]", this, sc); clean(); _valp = (uintptr_t) sc; _type = EContext; @@ -553,17 +562,20 @@ void CScriptStack::push(int val) inline CScriptStack::CStackEntry& CScriptStack::top() // is this an optimisation of the method below ? { + nldebug("[%lx]", this); return _Stack.back(); } inline CScriptStack::CStackEntry& CScriptStack::top(int index) { + nldebug("[%lx] index:%d", this, index); return *(_Stack.rbegin()+index); } inline void CScriptStack::pop() { + nldebug("[%lx]", this); _Stack.pop_back(); } diff --git a/code/ryzom/server/src/ai_service/state_instance.h b/code/ryzom/server/src/ai_service/state_instance.h index 916b6bc47..d7de97f18 100644 --- a/code/ryzom/server/src/ai_service/state_instance.h +++ b/code/ryzom/server/src/ai_service/state_instance.h @@ -505,7 +505,10 @@ void CStateInstance::processStateEvent(CAIEvent const& stateEvent, CAIState cons getDebugHistory()->addHistory("STATE: '%s' EVENT: '%s' REACTION: '%s'", state->getAliasNode()->fullName().c_str(), stateEvent.getName().c_str(), reaction.getAliasNode()->fullName().c_str()); - + nldebug("STATE: '%s' EVENT: '%s' REACTION: '%s'", + state->getAliasNode()->fullName().c_str(), + stateEvent.getName().c_str(), + reaction.getAliasNode()->fullName().c_str()); foundReaction=true; if (!reaction.getAction())