Skip to content

Commit

Permalink
Added Power Save
Browse files Browse the repository at this point in the history
  • Loading branch information
juliettef committed Feb 8, 2020
1 parent c38c98e commit 19a0d59
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
12 changes: 12 additions & 0 deletions RCCppMainLoop.cpp
Expand Up @@ -174,6 +174,18 @@ struct RCCppMainLoop : RCCppMainLoopI, TInterface<IID_IRCCPP_MAIN_LOOP,IObject>
{
doRCCppRedo = true;
} if (ImGui::IsItemHovered()) ImGui::SetTooltip( "Redo the last save." );

ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing();

ImGui::Checkbox( "Power Save", &g_pSys->power_save );
if( g_pSys->power_save )
{
ImGui::TextWrapped("Animated features may stop moving when Power Save is ON and no input is detected; for example Dear ImGui Demo, Plots Widgets");
}
else
{
ImGui::TextWrapped("Save energy by turning Power Save ON: render only when input is detected");
}
}
ImGui::End();

Expand Down
1 change: 1 addition & 0 deletions SystemTable.h
Expand Up @@ -16,4 +16,5 @@ struct SystemTable
RCCppMainLoopI* pRCCppMainLoopI = 0;
ImGuiContext* pImContext = 0;
IRuntimeObjectSystem* pRuntimeObjectSystem = NULL;
bool power_save = true;
};
63 changes: 60 additions & 3 deletions main.cpp
Expand Up @@ -23,6 +23,35 @@ bool RCCppInit();
void RCCppCleanup();
void RCCppUpdate();

// Power save
const int POWERSAVEDRAWNUM = 3;
int powerSaveCountDown = POWERSAVEDRAWNUM;
void ResetPowerSaveCountDown(){ powerSaveCountDown = 3; }
void WindowResizeCallback( GLFWwindow* window, int width, int height ){ ResetPowerSaveCountDown(); }
void WindowPosCallback( GLFWwindow* window, int xpos, int ypos ){ ResetPowerSaveCountDown(); }
void KeyCallback( GLFWwindow* window, int key, int scancode, int action, int mods )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_KeyCallback( window, key, scancode, action, mods );
}
void CharCallback( GLFWwindow* window, unsigned int character )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_CharCallback( window, character );
}
void MouseButtonCallback( GLFWwindow* window, int button, int action, int mods )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_MouseButtonCallback( window, button, action, mods );
}
void MousePosCallback( GLFWwindow* window, double x, double y ){ ResetPowerSaveCountDown(); }
void MouseWheelCallback( GLFWwindow* window, double x, double y )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_ScrollCallback( window, x, y );
}


int main( int argc, const char * argv[] )
{
if (!glfwInit())
Expand All @@ -32,11 +61,20 @@ int main( int argc, const char * argv[] )
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync

// Power save - ensure callbacks point to the correct place
glfwSetWindowSizeCallback( window, WindowResizeCallback );
glfwSetWindowPosCallback( window, WindowPosCallback );
glfwSetKeyCallback( window, KeyCallback );
glfwSetCharCallback( window, CharCallback );
glfwSetMouseButtonCallback( window, MouseButtonCallback );
glfwSetCursorPosCallback( window, MousePosCallback );
glfwSetScrollCallback( window, MouseWheelCallback );

// Setup Dear ImGui binding
IMGUI_CHECKVERSION();
ImGui::CreateContext();

ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplGlfw_InitForOpenGL(window, false);
ImGui_ImplOpenGL2_Init();

// Initialize RCC++
Expand Down Expand Up @@ -70,6 +108,21 @@ int main( int argc, const char * argv[] )
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}

// Power save
if( g_pSys->power_save )
{
if( powerSaveCountDown )
{
--powerSaveCountDown;
glfwPollEvents();
}
else
{
ResetPowerSaveCountDown();
glfwWaitEvents();
}
}
}

// Cleanup
Expand Down Expand Up @@ -109,7 +162,7 @@ bool RCCppInit()

void RCCppCleanup()
{
delete g_SystemTable.pRuntimeObjectSystem;
delete g_SystemTable.pRuntimeObjectSystem;
}

void RCCppUpdate()
Expand All @@ -126,4 +179,8 @@ void RCCppUpdate()
float deltaTime = 1.0f / ImGui::GetIO().Framerate;
g_SystemTable.pRuntimeObjectSystem->GetFileChangeNotifier()->Update( deltaTime );
}
}
else
{
ResetPowerSaveCountDown();
}
}

0 comments on commit 19a0d59

Please sign in to comment.