-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathHelloWorld3Module.cpp
More file actions
155 lines (101 loc) · 4.79 KB
/
HelloWorld3Module.cpp
File metadata and controls
155 lines (101 loc) · 4.79 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
This file is part of:
NoahFrame
https://github.com/ketoo/NoahGameFrame
Copyright 2009 - 2021 NoahFrame(NoahGameFrame)
File creator: lvsheng.huang
NoahFrame is open-source software and you can redistribute it and/or modify
it under the terms of the License; besides, anyone who use this file/software must include this copyright announcement.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
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 "HelloWorld3Module.h"
#include "NFComm/NFMessageDefine/NFProtocolDefine.hpp"
#include "NFComm/NFPluginModule/NFIEventModule.h"
bool NFHelloWorld3Module::Init()
{
m_pKernelModule = pPluginManager->FindModule<NFIKernelModule>();
m_pElementModule = pPluginManager->FindModule<NFIElementModule>();
m_pEventModule = pPluginManager->FindModule<NFIEventModule>();
m_pScheduleModule = pPluginManager->FindModule<NFIScheduleModule>();
std::cout << "Hello, world3, Init" << std::endl;
return true;
}
int NFHelloWorld3Module::OnEvent(const NFGUID& self, const int event, const NFDataList& arg)
{
std::cout << "OnEvent EventID: " << event << " self: " << self.nData64 << " argList: " << arg.Int(0) << " " << " " << arg.String(1) << std::endl;
m_pKernelModule->SetPropertyInt(self, "Hello", arg.Int(0));
m_pKernelModule->SetPropertyString(self, "Hello", arg.String(1));
return 0;
}
int NFHelloWorld3Module::OnHeartBeat(const NFGUID& self, const std::string& heartBeat, const float time, const int count)
{
int64_t unNowTime = NFGetTimeMS();
std::cout << self.ToString() + " heartBeat: " << time << " Count: " << count << " TimeDis: " << unNowTime - mLastTime << std::endl;
mLastTime = unNowTime;
return 0;
}
int NFHelloWorld3Module::OnClassCallBackEvent(const NFGUID& self, const std::string& className, const CLASS_OBJECT_EVENT event, const NFDataList& arg)
{
std::cout << "OnClassCallBackEvent ClassName: " << className << " ID: " << self.nData64 << " Event: " << event << std::endl;
if (event == COE_CREATE_HASDATA)
{
m_pEventModule->AddEventCallBack(self, 1, this, &NFHelloWorld3Module::OnEvent);
m_pScheduleModule->AddSchedule(self, "OnHeartBeat", this, &NFHelloWorld3Module::OnHeartBeat, 5.0f, 10 );
mLastTime = NFGetTimeMS();
}
return 0;
}
int NFHelloWorld3Module::OnPropertyCallBackEvent( const NFGUID& self, const std::string& propertyName, const NFData& oldVar, const NFData& newVar, const int64_t reason)
{
std::cout << "OnPropertyCallBackEvent Property: " << propertyName << " OldValue: " << oldVar.GetInt() << " NewValue: " << newVar.GetInt() << std::endl;
return 0;
}
int NFHelloWorld3Module::OnPropertyStrCallBackEvent( const NFGUID& self, const std::string& propertyName, const NFData& oldVar, const NFData& newVar, const int64_t reason)
{
std::cout << "OnPropertyCallBackEvent Property: " << propertyName << " OldValue: " << oldVar.GetString() << " NewValue: " << newVar.GetString() << std::endl;
return 0;
}
bool NFHelloWorld3Module::AfterInit()
{
std::cout << "Hello, world3, AfterInit" << std::endl;
m_pKernelModule->CreateScene(1);
m_pKernelModule->AddClassCallBack(NFrame::Player::ThisName(), this, &NFHelloWorld3Module::OnClassCallBackEvent);
m_pScheduleModule->AddSchedule(NFGUID(), "OnHeartBe22222", this, &NFHelloWorld3Module::OnHeartBeat, 6.0f, 10 );
NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->CreateObject(NFGUID(0, 10), 1, 0, NFrame::Player::ThisName(), "", NFDataList::Empty());
if (!pObject)
{
return false;
}
pObject->GetPropertyManager()->AddProperty(pObject->Self(), "Hello", TDATA_STRING);
pObject->GetPropertyManager()->AddProperty(pObject->Self(), "World", TDATA_INT);
pObject->AddPropertyCallBack("Hello", this, &NFHelloWorld3Module::OnPropertyStrCallBackEvent);
pObject->AddPropertyCallBack("World", this, &NFHelloWorld3Module::OnPropertyCallBackEvent);
pObject->SetPropertyString("Hello", "hello,World");
pObject->SetPropertyInt("World", 1111);
m_pEventModule->DoEvent(pObject->Self(), 1, NFDataList() << int(100) << "200");
return true;
}
bool NFHelloWorld3Module::Execute()
{
//std::cout << "Hello, world3, Execute" << std::endl;
return true;
}
bool NFHelloWorld3Module::BeforeShut()
{
std::cout << "Hello, world3, BeforeShut" << std::endl;
m_pKernelModule->DestroyAll();
return true;
}
bool NFHelloWorld3Module::Shut()
{
std::cout << "Hello, world3, Shut" << std::endl;
return true;
}