MCPcopy Create free account
hub / github.com/defold/defold / Update

Function Update

engine/hid/src/native/hid_native.cpp:227–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225 }
226
227 bool Update(HContext context)
228 {
229 dmPlatform::PollEvents(context->m_Window);
230
231 // Update keyboard
232 if (!context->m_IgnoreKeyboard)
233 {
234 for (uint32_t k = 0; k < MAX_KEYBOARD_COUNT; ++k)
235 {
236 Keyboard* keyboard = &context->m_Keyboards[k];
237 keyboard->m_Connected = 1; // TODO: Actually detect if the keyboard is present
238
239 for (uint32_t i = 0; i < MAX_KEY_COUNT; ++i)
240 {
241 Key key = (Key) i;
242 int key_value = GetKeyValue(key);
243 int state = dmPlatform::GetKey(context->m_Window, key_value);
244 uint32_t mask = 1 << (i % 32);
245
246 if (state)
247 keyboard->m_Packet.m_Keys[i / 32] |= mask;
248 else
249 keyboard->m_Packet.m_Keys[i / 32] &= ~mask;
250 }
251 }
252 }
253
254 // Update mouse
255 if (!context->m_IgnoreMouse)
256 {
257 for (uint32_t m = 0; m < MAX_MOUSE_COUNT; ++m)
258 {
259 Mouse* mouse = &context->m_Mice[m];
260 // TODO: Actually detect if the mouse is present,
261 // this is important for mouse input and touch input to not interfere
262 mouse->m_Connected = 1;
263
264 MousePacket& packet = mouse->m_Packet;
265 for (uint32_t i = 0; i < MAX_MOUSE_BUTTON_COUNT; ++i)
266 {
267 uint32_t mask = 1;
268 mask <<= i % 32;
269
270 int button_value = GetMouseButtonValue((MouseButton) i);
271 int state = dmPlatform::GetMouseButton(context->m_Window, button_value);
272
273 if (state)
274 packet.m_Buttons[i / 32] |= mask;
275 else
276 packet.m_Buttons[i / 32] &= ~mask;
277 }
278 int32_t wheel = dmPlatform::GetMouseWheel(context->m_Window);
279
280 if (context->m_FlipScrollDirection)
281 {
282 wheel *= -1;
283 }
284

Callers 2

TEST_FFunction · 0.50
EngineUpdateFunction · 0.50

Calls 10

GetKeyValueFunction · 0.85
GetMouseButtonValueFunction · 0.85
CalcStateHashFunction · 0.85
PollEventsFunction · 0.50
GetKeyFunction · 0.50
GetMouseButtonFunction · 0.50
GetMouseWheelFunction · 0.50
GetMousePositionFunction · 0.50
GetTouchDataFunction · 0.50
GetAccelerationFunction · 0.50

Tested by 2

TEST_FFunction · 0.40
EngineUpdateFunction · 0.40