forked from Tencent/behaviac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_6.cpp
More file actions
134 lines (95 loc) · 2.89 KB
/
Copy pathtutorial_6.cpp
File metadata and controls
134 lines (95 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tencent is pleased to support the open source community by making behaviac available.
//
// Copyright (C) 2015-2017 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at http://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "behaviac_generated/types/behaviac_types.h"
#if BEHAVIAC_CCDEFINE_ANDROID
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "tutorial_6", __VA_ARGS__))
#else
#define LOGI printf
#if BEHAVIAC_CCDEFINE_MSVC
#include <windows.h>
#include <tchar.h>
#endif
#endif
#if !BEHAVIAC_CCDEFINE_ANDROID
static void SetExePath()
{
#if BEHAVIAC_CCDEFINE_MSVC
TCHAR szCurPath[_MAX_PATH];
GetModuleFileName(NULL, szCurPath, _MAX_PATH);
TCHAR* p = szCurPath;
while (_tcschr(p, L'\\'))
{
p = _tcschr(p, L'\\');
p++;
}
*p = L'\0';
SetCurrentDirectory(szCurPath);
#endif
}
#endif
FirstAgent* g_FirstAgent = NULL;
bool InitBehavic()
{
LOGI("InitBehavic\n");
behaviac::Workspace::GetInstance()->SetFilePath("../tutorials/tutorial_6/cpp/exported");
behaviac::Workspace::GetInstance()->SetFileFormat(behaviac::Workspace::EFF_xml);
return true;
}
bool InitPlayer(const char* btName)
{
LOGI("InitPlayer : %s\n", btName);
g_FirstAgent = behaviac::Agent::Create<FirstAgent>();
bool bRet = g_FirstAgent->btload(btName);
g_FirstAgent->btsetcurrent(btName);
return bRet;
}
void UpdateLoop()
{
LOGI("UpdateLoop\n");
behaviac::EBTStatus status = g_FirstAgent->btexec();
BEHAVIAC_ASSERT(status == behaviac::BT_RUNNING);
BEHAVIAC_UNUSED_VAR(status);
g_FirstAgent->FireEvent("event_task", 2);
}
void CleanupPlayer()
{
LOGI("CleanupPlayer\n");
behaviac::Agent::Destroy(g_FirstAgent);
}
void CleanupBehaviac()
{
LOGI("CleanupBehaviac\n");
behaviac::Workspace::GetInstance()->Cleanup();
}
#if !BEHAVIAC_CCDEFINE_ANDROID
int main(int argc, char** argv)
{
BEHAVIAC_UNUSED_VAR(argc);
BEHAVIAC_UNUSED_VAR(argv);
SetExePath();
LOGI("BEHAVIAC_CCDEFINE_NAME=%s\n", BEHAVIAC_CCDEFINE_NAME);
InitBehavic();
bool bInit = InitPlayer("maintree_task");
if (bInit)
{
UpdateLoop();
CleanupPlayer();
}
CleanupBehaviac();
printf("Press any key to continue...");
int ret = getchar();
BEHAVIAC_UNUSED_VAR(ret);
return 0;
}
#endif