Skip to content

Commit

Permalink
Merge pull request #146 from Tencent/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wbn1984 authored Jul 4, 2022
2 parents aa1f53d + e346051 commit 91940aa
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 29 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated files
build/cmake_binary/**
lib/**
**/bin/
**/obj/
**/out/**
!**/out/config.xml
*.suo
23 changes: 15 additions & 8 deletions build/cmake_generate_projects.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ IF %ERRORLEVEL% NEQ 0 GOTO l_cmake_error
mkdir cmake_binary
cd cmake_binary

echo ---------------------------------------------------------------------------------
mkdir vs2013
cd vs2013
REM cmake -G "Visual Studio 12 2013 Win64" --build ../../..
REM cmake -G "Visual Studio 12 2013" -DBEHAVIAC_VERSION_MODE=ForeUseRelease --build ../../..
cmake -G "Visual Studio 12 2013" --build ../../..
cd ..

REM echo ---------------------------------------------------------------------------------
REM mkdir vs2015
REM cd vs2015
Expand All @@ -25,6 +17,21 @@ REM cmake -G "Visual Studio 14 2015" -DBEHAVIAC_VERSION_MODE=ForeUseRelease --bu
REM cmake -G "Visual Studio 14 2015" --build ../../..
REM cd ..

REM echo ---------------------------------------------------------------------------------
REM mkdir vs2017
REM cd vs2017
REM cmake -G "Visual Studio 15 2017 Win64" --build ../../..
REM cmake -G "Visual Studio 15 2017" -DBEHAVIAC_VERSION_MODE=ForeUseRelease --build ../../..
REM cmake -G "Visual Studio 15 2017" --build ../../..
REM cd ..

echo ---------------------------------------------------------------------------------
mkdir vs2019
cd vs2019
cmake -G "Visual Studio 16 2019" -A x64 --build ../../..
REM cmake -G "Visual Studio 16 2019" -DBEHAVIAC_VERSION_MODE=ForeUseRelease --build ../../..
REM cmake -G "Visual Studio 16 2019" --build ../../..
cd ..

where make
IF %ERRORLEVEL% NEQ 0 GOTO l_no_make
Expand Down
4 changes: 2 additions & 2 deletions src/agent/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,11 +1166,11 @@ namespace behaviac {
Agent* Agent::GetParentAgent(const Agent* pAgent, const char* instanceName) {
Agent* pParent = const_cast<Agent*>(pAgent);

if (!StringUtils::IsNullOrEmpty(instanceName) && !StringUtils::Compare(instanceName, "Self")) {
if (!StringUtils::IsNullOrEmpty(instanceName) && !StringUtils::StringEqual(instanceName, "Self")) {
pParent = Agent::GetInstance(instanceName, (pParent != NULL) ? pParent->GetContextId() : 0);

//if (pAgent != NULL && pParent == NULL && !Utils.IsStaticClass(instanceName))
if (pAgent != NULL && pParent == NULL /*&& !Utils.IsStaticClass(instanceName)*/) { //TODO how to handle Statice Class
if (pAgent != NULL && pParent == NULL) { //TODO how to handle Statice Class
pParent = (Agent*)pAgent->GetVariable<Agent*>(instanceName);
BEHAVIAC_ASSERT(pParent != NULL);
}
Expand Down
12 changes: 11 additions & 1 deletion src/behaviortree/behaviortree_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,11 @@ namespace behaviac {
}

void CompositeTask::traverse(bool childFirst, NodeHandler_t handler, Agent* pAgent, void* user_data) {
if (m_status == BT_INVALID)
{
return;
}

if (childFirst) {
for (BehaviorTasks_t::iterator it = this->m_children.begin();
it != this->m_children.end(); ++it) {
Expand Down Expand Up @@ -1187,7 +1192,12 @@ namespace behaviac {
}

void SingeChildTask::traverse(bool childFirst, NodeHandler_t handler, Agent* pAgent, void* user_data) {
if (childFirst) {
if (m_status == BT_INVALID)
{
return;
}

if (childFirst) {
if (this->m_root) {
this->m_root->traverse(childFirst, handler, pAgent, user_data);
}
Expand Down
19 changes: 19 additions & 0 deletions tools/designer/BehaviacDesigner/BehaviorTreeViewDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Behaviac.Design.Nodes;

namespace Behaviac.Design
{
Expand Down Expand Up @@ -161,6 +163,23 @@ internal static BehaviorTreeViewDock GetBehaviorTreeViewDock(Nodes.BehaviorNode
return null;
}

internal static BehaviorTreeViewDock GetBehaviorTreeViewDockByName(string behaviorFilename)
{
if (!Path.IsPathRooted(behaviorFilename))
{
behaviorFilename = FileManagers.FileManager.GetFullPath(behaviorFilename);
}

BehaviorTreeViewDock dock = null;
BehaviorNode behaviornode = BehaviorManager.Instance.GetBehavior(behaviorFilename);
if (behaviornode != null)
{
dock = GetBehaviorTreeViewDock(behaviornode);
}

return dock;
}

internal static BehaviorTreeView GetBehaviorTreeView(Nodes.BehaviorNode node)
{
foreach (BehaviorTreeViewDock dock in __instances)
Expand Down
1 change: 1 addition & 0 deletions tools/designer/BehaviacDesigner/CallStackDock.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions tools/designer/BehaviacDesigner/CallStackDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Behaviac.Design.Nodes;
using Behaviac.Design.Properties;


namespace Behaviac.Design
{
internal partial class CallStackDock : WeifenLuo.WinFormsUI.Docking.DockContent
Expand Down Expand Up @@ -122,14 +123,18 @@ private void UpdateStackCb(string tree, bool bAdd)
}
}

/*
if (callstackListBox.Items.Count > 0)
{
//callstackListBox.SelectedIndex = -1;
callstackListBox.SelectedIndex = 0;
string currentBt = (string)callstackListBox.Items[0];
UIUtilities.ShowBehaviorTree(currentBt);
}
*/
}

private void copyMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -184,5 +189,24 @@ private void logListBox_KeyDown(object sender, KeyEventArgs e)
callstackListBox.EndUpdate();
}
}

private void logListBox_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (callstackListBox.SelectedItem != null)
{
String behaviorFilename = callstackListBox.SelectedItem.ToString();
BehaviorTreeView behaviorTreeView = UIUtilities.ShowBehaviorTree(behaviorFilename, true);
if (behaviorTreeView != null)
{
BehaviorTreeViewDock dock = BehaviorTreeViewDock.GetBehaviorTreeViewDockByName(behaviorFilename);
if (dock != null)
{
dock.Focus();
dock.MakeFocused();
}
}
}
}
}
}

7 changes: 5 additions & 2 deletions tools/designer/BehaviacDesigner/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,11 @@ private BehaviorTreeViewDock behaviorTreeList_ShowBehavior(BehaviorNode node)

if (dock != null)
{
dock.Focus();
dock.MakeFocused();
if (Plugin.EditMode == EditModes.Design)
{
dock.Focus();
dock.MakeFocused();
}
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion tools/designer/BehaviacDesigner/TimelineDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void updateParameters(AgentType agentType, string agentName, int frame)

if (agentFullname == Plugin.DebugAgentInstance)
{
behavior = UIUtilities.ShowBehavior(behaviorFilename);
behavior = UIUtilities.ShowBehavior(behaviorFilename, false);
}

List<AgentDataPool.ValueMark> values = AgentDataPool.GetValidValues(agentType, agentFullname, frame);
Expand Down
23 changes: 16 additions & 7 deletions tools/designer/BehaviacDesigner/UIUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class UIUtilities
/// Show the behavior tree view.
/// </summary>
/// <param name="behaviorFilename">The behavior filename in the workspace folder.</param>
public static BehaviorNode ShowBehavior(string behaviorFilename)
public static BehaviorNode ShowBehavior(string behaviorFilename, bool forceshowFlag = true)
{
if (string.IsNullOrEmpty(behaviorFilename))
{
Expand Down Expand Up @@ -81,16 +81,19 @@ public static BehaviorNode ShowBehavior(string behaviorFilename)

if (behaviorTreeList != null)
{
behaviorTreeList.ShowNode(behavior as Node);
if (forceshowFlag)
{
behaviorTreeList.ShowNode(behavior as Node);
}
}
}

return behavior;
}

public static BehaviorTreeView ShowBehaviorTree(string behaviorFilename)
public static BehaviorTreeView ShowBehaviorTree(string behaviorFilename, bool forceshowFlag = true)
{
BehaviorNode behavior = ShowBehavior(behaviorFilename);
BehaviorNode behavior = ShowBehavior(behaviorFilename, forceshowFlag);
return BehaviorTreeViewDock.GetBehaviorTreeView(behavior);
}

Expand All @@ -105,7 +108,7 @@ public static BehaviorNode ShowBehaviorTree(string agentFullname, int frame, Lis

if (!string.IsNullOrEmpty(behaviorFilename))
{
BehaviorTreeView behaviorTreeView = ShowBehaviorTree(behaviorFilename);
BehaviorTreeView behaviorTreeView = ShowBehaviorTree(behaviorFilename, false);

if (behaviorTreeView != null)
{
Expand All @@ -114,8 +117,14 @@ public static BehaviorNode ShowBehaviorTree(string agentFullname, int frame, Lis
profileInfos = null;
}

behaviorTreeView.SetHighlights(highlightedTransitionIds, highlightNodeIds, updatedNodeIds, highlightBreakPoint, profileInfos);
//behaviorTreeView.Focus();
// check if there is a tab for the behaviour, add by j2 server start
BehaviorTreeViewDock dock = BehaviorTreeViewDock.GetBehaviorTreeViewDockByName(behaviorFilename);
if (dock != null && dock == BehaviorTreeViewDock.LastFocused)
{
behaviorTreeView.SetHighlights(highlightedTransitionIds, highlightNodeIds, updatedNodeIds, highlightBreakPoint, profileInfos);
}

// behaviorTreeView.SetHighlights(highlightedTransitionIds, highlightNodeIds, updatedNodeIds, highlightBreakPoint, profileInfos);

return behaviorTreeView.RootNode;
}
Expand Down
63 changes: 55 additions & 8 deletions tools/designer/BehaviacDesignerBase/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using System.Management;
using System.Threading;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Security.Cryptography;

using Behaviac.Design.Properties;

Expand Down Expand Up @@ -213,6 +215,7 @@ private static string GetHarddiskID()

private static string _gatwway = "";
private static IPStatus _netWorkStatus = IPStatus.Unknown;
private static UdpClient _udpClient = null;
private static bool CheckNetWork()
{
try
Expand Down Expand Up @@ -277,7 +280,7 @@ private static bool ReportToTQOS(int intNum, string intList, int strNum, string
qosData += strList;
qosData += "]}}}]}}}";

using(var client = new WebClient())
using (var client = new WebClient())
{
Uri uri = new Uri(qosData);
client.OpenReadAsync(uri);
Expand All @@ -292,6 +295,44 @@ private static bool ReportToTQOS(int intNum, string intList, int strNum, string
return true;
}

private static string _userInfo = "";
private static bool ReportToGStatistic(OperationData operation)
{
try
{
if (_udpClient == null)
{
_udpClient = new UdpClient();
_udpClient.Connect("101.226.141.148", 8080);
Thread.Sleep(2000);
}

string qosDataStr = string.Format("cmd=0&tag=gcloud.behavic.times&event={0}&OperationNum={1}", operation.Type.ToString(), operation.Count);

if (string.IsNullOrEmpty(_userInfo))
{
HashAlgorithm algorithm = MD5.Create();
String EncryptedUserName = BitConverter.ToString(algorithm.ComputeHash(Encoding.UTF8.GetBytes(Dns.GetHostName() + GetLocalMac())));

_userInfo = string.Format("&IP={0}&user_name={1}&version={2}",
GetLocalIP(),
EncryptedUserName,
System.Reflection.Assembly.GetEntryAssembly().GetName().Version);
}
qosDataStr += _userInfo;

byte[] qosData = Encoding.UTF8.GetBytes(qosDataStr);
_udpClient.Send(qosData, qosData.Length);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}

return true;
}

[Serializable]
enum OperationTypes
{
Expand Down Expand Up @@ -425,13 +466,19 @@ private static bool SendOperations()
{
foreach (OperationData operation in _allOperations)
{
int intNum = 8;
string intList = string.Format("0,0,0,0,0,0,{0},{1}", (int)operation.Type, operation.Count);

int strNum = 8;
string strList = getHeaderString();

if (!ReportToTQOS(intNum, intList, strNum, strList))
//int intNum = 8;
//string intList = string.Format("0,0,0,0,0,0,{0},{1}", (int)operation.Type, operation.Count);

//int strNum = 8;
//string strList = getHeaderString();

//if (!ReportToTQOS(intNum, intList, strNum, strList))
//{
// sendSuccess = false;
// break;
//}

if (!ReportToGStatistic(operation))
{
sendSuccess = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public static string GetGeneratedDefaultValue(Type type, string typename, string
{
value = "NULL";
}
else if(typename.Equals("BTVector3f"))
{
value = "{0, 0, 0}";
}
else
{
value = null;
Expand Down

0 comments on commit 91940aa

Please sign in to comment.