MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / UpdateFrame

Function UpdateFrame

demo/main.cpp:1904–2180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1902}
1903
1904void UpdateFrame()
1905{
1906 static double lastTime;
1907
1908 // real elapsed frame time
1909 double frameBeginTime = GetSeconds();
1910
1911 g_realdt = float(frameBeginTime - lastTime);
1912 lastTime = frameBeginTime;
1913
1914 // do gamepad input polling
1915 double currentTime = frameBeginTime;
1916 static double lastJoyTime = currentTime;
1917
1918 if (g_gamecontroller && currentTime - lastJoyTime > g_dt)
1919 {
1920 lastJoyTime = currentTime;
1921
1922 int leftStickX = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_LEFTX);
1923 int leftStickY = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
1924 int rightStickX = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_RIGHTX);
1925 int rightStickY = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
1926 int leftTrigger = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
1927 int rightTrigger = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
1928
1929 Vec2 leftStick(joyAxisFilter(leftStickX, 0), joyAxisFilter(leftStickY, 0));
1930 Vec2 rightStick(joyAxisFilter(rightStickX, 1), joyAxisFilter(rightStickY, 1));
1931 Vec2 trigger(leftTrigger / 32768.0f, rightTrigger / 32768.0f);
1932
1933 if (leftStick.x != 0.0f || leftStick.y != 0.0f ||
1934 rightStick.x != 0.0f || rightStick.y != 0.0f)
1935 {
1936 // note constant factor to speed up analog control compared to digital because it is more controllable.
1937 g_camVel.z = -4 * g_camSpeed * leftStick.y;
1938 g_camVel.x = 4 * g_camSpeed * leftStick.x;
1939
1940 // cam orientation
1941 g_camAngle.x -= rightStick.x * 0.05f;
1942 g_camAngle.y -= rightStick.y * 0.05f;
1943 }
1944
1945 // Handle left stick motion
1946 static bool bLeftStick = false;
1947
1948 if ((leftStick.x != 0.0f || leftStick.y != 0.0f) && !bLeftStick)
1949 {
1950 bLeftStick = true;
1951 }
1952 else if ((leftStick.x == 0.0f && leftStick.y == 0.0f) && bLeftStick)
1953 {
1954 bLeftStick = false;
1955 g_camVel.z = -4 * g_camSpeed * leftStick.y;
1956 g_camVel.x = 4 * g_camSpeed * leftStick.x;
1957 }
1958
1959 // Handle triggers as controller button events
1960 void ControllerButtonEvent(SDL_ControllerButtonEvent event);
1961

Callers 1

SDLMainLoopFunction · 0.85

Calls 15

GetSecondsFunction · 0.85
joyAxisFilterFunction · 0.85
ControllerButtonEventFunction · 0.85
MapBuffersFunction · 0.85
UpdateCameraFunction · 0.85
UpdateEmittersFunction · 0.85
UpdateMouseFunction · 0.85
UpdateWindFunction · 0.85
UpdateSceneFunction · 0.85
RenderSceneFunction · 0.85
RenderDebugFunction · 0.85
DoUIFunction · 0.85

Tested by

no test coverage detected