MCPcopy Create free account
hub / github.com/TurningWheel/Barony / handleEvents

Function handleEvents

src/editor.cpp:765–989  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

763-------------------------------------------------------------------------------*/
764
765bool handleEvents(void)
766{
767 real_t d;
768 int j;
769
770
771 // calculate app rate
772 t = SDL_GetTicks();
773 real_t timesync = t - ot;
774 ot = t;
775
776 // do timer
777 time_diff += timesync;
778 constexpr real_t frame = (real_t)1000 / (real_t)TICKS_PER_SECOND;
779 while (time_diff >= frame) {
780 time_diff -= frame;
781 timerCallback(0, NULL);
782 }
783
784 // calculate fps
785 if ( timesync != 0 )
786 {
787 frameval[cycles & (AVERAGEFRAMES - 1)] = 1.0 / timesync;
788 }
789 else
790 {
791 frameval[cycles & (AVERAGEFRAMES - 1)] = 1.0;
792 }
793 d = frameval[0];
794 for (j = 1; j < AVERAGEFRAMES; j++)
795 {
796 d += frameval[j];
797 }
798 fps = d / AVERAGEFRAMES * 1000;
799
800 while ( SDL_PollEvent(&event) ) // poll SDL events
801 {
802 // Global events
803 switch ( event.type )
804 {
805 case SDL_QUIT: // if SDL receives the shutdown signal
806 buttonExit(NULL);
807 break;
808 case SDL_KEYDOWN: // if a key is pressed...
809 if ( SDL_IsTextInputActive() )
810 {
811#ifdef APPLE
812 if ( (event.key.keysym.sym == SDLK_DELETE || event.key.keysym.sym == SDLK_BACKSPACE) && strlen(inputstr) > 0 )
813 {
814 inputstr[strlen(inputstr) - 1] = 0;
815 cursorflash = ticks;
816 }
817#else
818 if ( event.key.keysym.sym == SDLK_BACKSPACE && strlen(inputstr) > 0 )
819 {
820 if ( textInsertCaratPosition >= 0 && newwindow == 20 && textInsertCaratPosition != strlen(inputstr) )
821 {
822 if ( textInsertCaratPosition != 0 )

Callers 1

mainFunction · 0.70

Calls 6

timerCallbackFunction · 0.85
buttonExitFunction · 0.85
mainLogicFunction · 0.85
resizeWindowFunction · 0.85
printlogFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected