public QueuedStatement(StatementCallbackHandler callback, Statement statement) { this.callback = callback; this.statement = statement; }
// ------------------------------------------------------------------------ // build statement, then queue to be sent asynchronously // actor, verb, object, result, context // ------------------------------------------------------------------------ public void QueueStatement(Agent statementActor, Verb statementVerb, Activity statementObject, Result statementResult, Context statementContext, StatementCallbackHandler sendCallback = null) { // create statement Statement statement = new Statement(); statement.actor = statementActor; statement.verb = statementVerb; if (statementResult != null) { statement.result = statementResult; } statement.target = statementObject; // statement.target is the object (object is a reserved c# word) if (statementContext != null) { statement.context = statementContext; } // make sure all are set bool invalid = false; string invalidReason = ""; if (statement.actor == null) { invalid = true; invalidReason += "ERROR: Agent is null\n"; } // required if (statement.verb == null) { invalid = true; invalidReason += "ERROR: Verb is null\n"; } // required // statement.result is optional and may be null if (statement.target == null) { invalid = true; invalidReason += "ERROR: Object is null\n"; } // required // statement.context is optional and may be null // invalid? if (invalid) { Debug.LogError(invalidReason); if (sendCallback != null) { sendCallback(false, invalidReason); } } // valid - queue else { // check if space in the ringbuffer queue, if not discard or will hard lock unity if (this.gblQueue.Capacity - this.gblQueue.Count > 0) { this.gblQueue.Enqueue(new QueuedStatement(sendCallback, statement)); } else { Debug.LogWarning("QueueStatement: Queue is full. Discarding Statement"); } } }