comparison tools/ppl.c @ 2017:3a768f8d409d

Rename variable s/engine/eng/g to avoid aliasing with dmsimple::engine. This enables us to build with link-time optimizations -flto if so desired.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Sep 2018 12:36:17 +0300
parents c27f7cd25684
children dcca36701cdd
comparison
equal deleted inserted replaced
2016:7114ea4c3c42 2017:3a768f8d409d
38 38
39 JSSModule *mod; 39 JSSModule *mod;
40 JSSMixer *dev; 40 JSSMixer *dev;
41 JSSPlayer *plr; 41 JSSPlayer *plr;
42 SDL_AudioSpec afmt; 42 SDL_AudioSpec afmt;
43 } engine; 43 } eng;
44 44
45 struct 45 struct
46 { 46 {
47 Uint32 47 Uint32
48 boxBg, inboxBg, 48 boxBg, inboxBg,
104 case 1: 104 case 1:
105 dmVerbosity++; 105 dmVerbosity++;
106 break; 106 break;
107 107
108 case 2: 108 case 2:
109 engine.optVFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; 109 eng.optVFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
110 break; 110 break;
111 111
112 case 3: 112 case 3:
113 { 113 {
114 int w, h; 114 int w, h;
117 if (w < 320 || h < 200 || w > 3200 || h > 3200) 117 if (w < 320 || h < 200 || w > 3200 || h > 3200)
118 { 118 {
119 dmErrorMsg("Invalid width or height: %d x %d\n", w, h); 119 dmErrorMsg("Invalid width or height: %d x %d\n", w, h);
120 return FALSE; 120 return FALSE;
121 } 121 }
122 engine.optScrWidth = w; 122 eng.optScrWidth = w;
123 engine.optScrHeight = h; 123 eng.optScrHeight = h;
124 } 124 }
125 else 125 else
126 { 126 {
127 dmErrorMsg("Invalid size argument '%s'.\n", optArg); 127 dmErrorMsg("Invalid size argument '%s'.\n", optArg);
128 return FALSE; 128 return FALSE;
186 } 186 }
187 187
188 188
189 static inline Uint32 dmCol(const float r, const float g, const float b) 189 static inline Uint32 dmCol(const float r, const float g, const float b)
190 { 190 {
191 return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b); 191 return dmMapRGB(eng.screen, 255.0f * r, 255.0f * g, 255.0f * b);
192 } 192 }
193 193
194 194
195 BOOL dmInitializeVideo() 195 BOOL dmInitializeVideo()
196 { 196 {
197 SDL_DestroyTexture(engine.texture); 197 SDL_DestroyTexture(eng.texture);
198 SDL_FreeSurface(engine.screen); 198 SDL_FreeSurface(eng.screen);
199 199
200 if ((engine.texture = SDL_CreateTexture(engine.renderer, 200 if ((eng.texture = SDL_CreateTexture(eng.renderer,
201 SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, 201 SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING,
202 engine.optScrWidth, engine.optScrHeight)) == NULL) 202 eng.optScrWidth, eng.optScrHeight)) == NULL)
203 { 203 {
204 dmErrorMsg("Could not create SDL texture.\n"); 204 dmErrorMsg("Could not create SDL texture.\n");
205 return FALSE; 205 return FALSE;
206 } 206 }
207 207
208 if ((engine.screen = SDL_CreateRGBSurfaceWithFormat(0, 208 if ((eng.screen = SDL_CreateRGBSurfaceWithFormat(0,
209 engine.optScrWidth, engine.optScrHeight, 209 eng.optScrWidth, eng.optScrHeight,
210 32, SDL_PIXELFORMAT_RGBA32)) == NULL) 210 32, SDL_PIXELFORMAT_RGBA32)) == NULL)
211 { 211 {
212 dmErrorMsg("Could not create SDL surface.\n"); 212 dmErrorMsg("Could not create SDL surface.\n");
213 return FALSE; 213 return FALSE;
214 } 214 }
247 Uint32 *pix = screen->pixels; 247 Uint32 *pix = screen->pixels;
248 Sint16 *data = chn->chData; 248 Sint16 *data = chn->chData;
249 249
250 dmFillBox3D(screen, x0, y0, x1, y1, 250 dmFillBox3D(screen, x0, y0, x1, y1,
251 (chn->chMute ? col.muted : col.black), 251 (chn->chMute ? col.muted : col.black),
252 nchannel == engine.actChannel ? col.red : col.box2, 252 nchannel == eng.actChannel ? col.red : col.box2,
253 nchannel == engine.actChannel ? col.red : col.box1); 253 nchannel == eng.actChannel ? col.red : col.box1);
254 254
255 if (chn->chData == NULL || !chn->chPlaying) 255 if (chn->chData == NULL || !chn->chPlaying)
256 return; 256 return;
257 257
258 if (chn->chDirection) 258 if (chn->chDirection)
450 return; 450 return;
451 451
452 if (qwidth > pat->nchannels) 452 if (qwidth > pat->nchannels)
453 qwidth = pat->nchannels; 453 qwidth = pat->nchannels;
454 454
455 if (engine.actChannel < qwidth / 2) 455 if (eng.actChannel < qwidth / 2)
456 choffs = 0; 456 choffs = 0;
457 else 457 else
458 if (engine.actChannel >= pat->nchannels - qwidth/2) 458 if (eng.actChannel >= pat->nchannels - qwidth/2)
459 choffs = pat->nchannels - qwidth; 459 choffs = pat->nchannels - qwidth;
460 else 460 else
461 choffs = engine.actChannel - qwidth/2; 461 choffs = eng.actChannel - qwidth/2;
462 462
463 dmDrawBox3D(screen, x0 + lwidth, qy0, x1, qy1, col.box2, col.box1); 463 dmDrawBox3D(screen, x0 + lwidth, qy0, x1, qy1, col.box2, col.box1);
464 464
465 for (nchannel = 0; nchannel < qwidth; nchannel++) 465 for (nchannel = 0; nchannel < qwidth; nchannel++)
466 { 466 {
467 int bx0 = x0 + lwidth + 1 + nchannel * cwidth, 467 int bx0 = x0 + lwidth + 1 + nchannel * cwidth,
468 bx1 = bx0 + cwidth; 468 bx1 = bx0 + cwidth;
469 469
470 dmFillRect(screen, bx0+1, qy0+1, bx1-1, qy1-1, 470 dmFillRect(screen, bx0+1, qy0+1, bx1-1, qy1-1,
471 (engine.actChannel == nchannel + choffs) ? col.activeChannel : col.inboxBg); 471 (eng.actChannel == nchannel + choffs) ? col.activeChannel : col.inboxBg);
472 } 472 }
473 473
474 yc = qy0 + 2 + (font->height + 1) * midrow; 474 yc = qy0 + 2 + (font->height + 1) * midrow;
475 dmFillRect(screen, x0 + lwidth + 1, yc - 1, x1 - 1, yc + font->height, col.activeRow); 475 dmFillRect(screen, x0 + lwidth + 1, yc - 1, x1 - 1, yc + font->height, col.activeRow);
476 476
479 int bx0 = x0 + lwidth + 1 + nchannel * cwidth, 479 int bx0 = x0 + lwidth + 1 + nchannel * cwidth,
480 bx1 = bx0 + cwidth; 480 bx1 = bx0 + cwidth;
481 481
482 dmDrawVLine(screen, qy0 + 1, qy1 - 1, bx1, col.viewDiv); 482 dmDrawVLine(screen, qy0 + 1, qy1 - 1, bx1, col.viewDiv);
483 483
484 if (jvmGetMute(engine.dev, nchannel + choffs)) 484 if (jvmGetMute(eng.dev, nchannel + choffs))
485 { 485 {
486 dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT, 486 dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT,
487 bx0 + (cwidth - font->width * 5) / 2, qy1 + 3, "MUTED"); 487 bx0 + (cwidth - font->width * 5) / 2, qy1 + 3, "MUTED");
488 } 488 }
489 489
526 526
527 527
528 void dmMuteChannels(BOOL mute) 528 void dmMuteChannels(BOOL mute)
529 { 529 {
530 int i; 530 int i;
531 for (i = 0; i < engine.mod->nchannels; i++) 531 for (i = 0; i < eng.mod->nchannels; i++)
532 jvmMute(engine.dev, i, mute); 532 jvmMute(eng.dev, i, mute);
533 } 533 }
534 534
535 535
536 int main(int argc, char *argv[]) 536 int main(int argc, char *argv[])
537 { 537 {
538 BOOL initSDL = FALSE, audioInit = FALSE; 538 BOOL initSDL = FALSE, audioInit = FALSE;
539 DMResource *file = NULL; 539 DMResource *file = NULL;
540 int result = -1; 540 int result = -1;
541 BOOL muteState = FALSE; 541 BOOL muteState = FALSE;
542 542
543 dmMemset(&engine, 0, sizeof(engine)); 543 dmMemset(&eng, 0, sizeof(eng));
544 544
545 engine.optScrWidth = 640; 545 eng.optScrWidth = 640;
546 engine.optScrHeight = 480; 546 eng.optScrHeight = 480;
547 engine.optScrDepth = 32; 547 eng.optScrDepth = 32;
548 548
549 dmInitProg("CBP", "Cyrbe Basci Player", "0.2", NULL, NULL); 549 dmInitProg("CBP", "Cyrbe Basci Player", "0.2", NULL, NULL);
550 550
551 // Parse arguments 551 // Parse arguments
552 if (!dmArgsProcess(argc, argv, optList, optListN, 552 if (!dmArgsProcess(argc, argv, optList, optListN,
571 jssInit(); 571 jssInit();
572 572
573 // Read module file 573 // Read module file
574 dmMsg(1, "Reading file: %s\n", optFilename); 574 dmMsg(1, "Reading file: %s\n", optFilename);
575 #ifdef JSS_SUP_XM 575 #ifdef JSS_SUP_XM
576 result = jssLoadXM(file, &engine.mod, TRUE); 576 result = jssLoadXM(file, &eng.mod, TRUE);
577 #endif 577 #endif
578 #ifdef JSS_SUP_JSSMOD 578 #ifdef JSS_SUP_JSSMOD
579 dmfreset(file); 579 dmfreset(file);
580 if (result != DMERR_OK) 580 if (result != DMERR_OK)
581 { 581 {
582 dmMsg(1, "* Trying JSSMOD ...\n"); 582 dmMsg(1, "* Trying JSSMOD ...\n");
583 result = jssLoadJSSMOD(file, &engine.mod, TRUE); 583 result = jssLoadJSSMOD(file, &eng.mod, TRUE);
584 dmfreset(file); 584 dmfreset(file);
585 if (result == DMERR_OK) 585 if (result == DMERR_OK)
586 result = jssLoadJSSMOD(file, &engine.mod, FALSE); 586 result = jssLoadJSSMOD(file, &eng.mod, FALSE);
587 } 587 }
588 else 588 else
589 { 589 {
590 dmMsg(2, "* Trying XM...\n"); 590 dmMsg(2, "* Trying XM...\n");
591 result = jssLoadXM(file, &engine.mod, FALSE); 591 result = jssLoadXM(file, &eng.mod, FALSE);
592 } 592 }
593 #endif 593 #endif
594 dmf_close(file); 594 dmf_close(file);
595 595
596 if (result != DMERR_OK) 596 if (result != DMERR_OK)
599 result, dmErrorStr(result)); 599 result, dmErrorStr(result));
600 goto error_exit; 600 goto error_exit;
601 } 601 }
602 602
603 // Try to convert it 603 // Try to convert it
604 if ((result = jssConvertModuleForPlaying(engine.mod)) != DMERR_OK) 604 if ((result = jssConvertModuleForPlaying(eng.mod)) != DMERR_OK)
605 { 605 {
606 dmErrorMsg("Could not convert module for playing, %d: %s\n", 606 dmErrorMsg("Could not convert module for playing, %d: %s\n",
607 result, dmErrorStr(result)); 607 result, dmErrorStr(result));
608 goto error_exit; 608 goto error_exit;
609 } 609 }
644 644
645 // Initialize mixing device 645 // Initialize mixing device
646 dmMsg(2, "Initializing miniJSS mixer with: %d, %d, %d\n", 646 dmMsg(2, "Initializing miniJSS mixer with: %d, %d, %d\n",
647 optOutFormat, optOutChannels, optOutFreq); 647 optOutFormat, optOutChannels, optOutFreq);
648 648
649 engine.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); 649 eng.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
650 if (engine.dev == NULL) 650 if (eng.dev == NULL)
651 { 651 {
652 dmErrorMsg("jvmInit() returned NULL\n"); 652 dmErrorMsg("jvmInit() returned NULL\n");
653 goto error_exit; 653 goto error_exit;
654 } 654 }
655 655
656 switch (optOutFormat) 656 switch (optOutFormat)
657 { 657 {
658 case JSS_AUDIO_S16: engine.afmt.format = AUDIO_S16SYS; break; 658 case JSS_AUDIO_S16: eng.afmt.format = AUDIO_S16SYS; break;
659 case JSS_AUDIO_U16: engine.afmt.format = AUDIO_U16SYS; break; 659 case JSS_AUDIO_U16: eng.afmt.format = AUDIO_U16SYS; break;
660 case JSS_AUDIO_S8: engine.afmt.format = AUDIO_S8; break; 660 case JSS_AUDIO_S8: eng.afmt.format = AUDIO_S8; break;
661 case JSS_AUDIO_U8: engine.afmt.format = AUDIO_U8; break; 661 case JSS_AUDIO_U8: eng.afmt.format = AUDIO_U8; break;
662 default: 662 default:
663 dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n", 663 dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n",
664 optOutFormat); 664 optOutFormat);
665 goto error_exit; 665 goto error_exit;
666 } 666 }
667 667
668 engine.afmt.freq = optOutFreq; 668 eng.afmt.freq = optOutFreq;
669 engine.afmt.channels = optOutChannels; 669 eng.afmt.channels = optOutChannels;
670 engine.afmt.samples = optOutFreq / 16; 670 eng.afmt.samples = optOutFreq / 16;
671 engine.afmt.callback = audioCallback; 671 eng.afmt.callback = audioCallback;
672 engine.afmt.userdata = (void *) engine.dev; 672 eng.afmt.userdata = (void *) eng.dev;
673 673
674 // Open the audio device 674 // Open the audio device
675 if (SDL_OpenAudio(&engine.afmt, NULL) < 0) 675 if (SDL_OpenAudio(&eng.afmt, NULL) < 0)
676 { 676 {
677 dmErrorMsg("Couldn't open SDL audio: %s\n", 677 dmErrorMsg("Couldn't open SDL audio: %s\n",
678 SDL_GetError()); 678 SDL_GetError());
679 goto error_exit; 679 goto error_exit;
680 } 680 }
681 audioInit = TRUE; 681 audioInit = TRUE;
682 682
683 // Initialize player 683 // Initialize player
684 if ((engine.plr = jmpInit(engine.dev)) == NULL) 684 if ((eng.plr = jmpInit(eng.dev)) == NULL)
685 { 685 {
686 dmErrorMsg("jmpInit() returned NULL\n"); 686 dmErrorMsg("jmpInit() returned NULL\n");
687 goto error_exit; 687 goto error_exit;
688 } 688 }
689 689
690 jvmSetCallback(engine.dev, jmpExec, engine.plr); 690 jvmSetCallback(eng.dev, jmpExec, eng.plr);
691 jmpSetModule(engine.plr, engine.mod); 691 jmpSetModule(eng.plr, eng.mod);
692 jmpPlayOrder(engine.plr, optStartOrder); 692 jmpPlayOrder(eng.plr, optStartOrder);
693 jvmSetGlobalVol(engine.dev, 200); 693 jvmSetGlobalVol(eng.dev, 200);
694 694
695 if (optMuteOChannels >= 0 && optMuteOChannels < engine.mod->nchannels) 695 if (optMuteOChannels >= 0 && optMuteOChannels < eng.mod->nchannels)
696 { 696 {
697 dmMuteChannels(TRUE); 697 dmMuteChannels(TRUE);
698 jvmMute(engine.dev, optMuteOChannels, FALSE); 698 jvmMute(eng.dev, optMuteOChannels, FALSE);
699 engine.actChannel = optMuteOChannels; 699 eng.actChannel = optMuteOChannels;
700 muteState = TRUE; 700 muteState = TRUE;
701 } 701 }
702 702
703 // Open window 703 // Open window
704 if ((engine.window = SDL_CreateWindow(dmProgName, 704 if ((eng.window = SDL_CreateWindow(dmProgName,
705 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 705 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
706 engine.optScrWidth, engine.optScrHeight, 706 eng.optScrWidth, eng.optScrHeight,
707 engine.optVFlags | SDL_WINDOW_RESIZABLE 707 eng.optVFlags | SDL_WINDOW_RESIZABLE
708 //| SDL_WINDOW_HIDDEN 708 //| SDL_WINDOW_HIDDEN
709 )) == NULL) 709 )) == NULL)
710 { 710 {
711 dmErrorMsg("Can't create an SDL window: %s\n", SDL_GetError()); 711 dmErrorMsg("Can't create an SDL window: %s\n", SDL_GetError());
712 goto error_exit; 712 goto error_exit;
713 } 713 }
714 714
715 SDL_SetWindowTitle(engine.window, dmProgDesc); 715 SDL_SetWindowTitle(eng.window, dmProgDesc);
716 716
717 if ((engine.renderer = SDL_CreateRenderer(engine.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL) 717 if ((eng.renderer = SDL_CreateRenderer(eng.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
718 { 718 {
719 dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError()); 719 dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError());
720 goto error_exit; 720 goto error_exit;
721 } 721 }
722 722
730 SDL_LockAudio(); 730 SDL_LockAudio();
731 SDL_PauseAudio(0); 731 SDL_PauseAudio(0);
732 SDL_UnlockAudio(); 732 SDL_UnlockAudio();
733 733
734 int currTick, prevTick = 0, prevRow = -1; 734 int currTick, prevTick = 0, prevRow = -1;
735 while (!engine.exitFlag) 735 while (!eng.exitFlag)
736 { 736 {
737 currTick = SDL_GetTicks(); 737 currTick = SDL_GetTicks();
738 BOOL needUpdate = (currTick - prevTick > 500), 738 BOOL needUpdate = (currTick - prevTick > 500),
739 needRender = FALSE; 739 needRender = FALSE;
740 740
741 while (SDL_PollEvent(&engine.event)) 741 while (SDL_PollEvent(&eng.event))
742 switch (engine.event.type) 742 switch (eng.event.type)
743 { 743 {
744 case SDL_KEYDOWN: 744 case SDL_KEYDOWN:
745 switch (engine.event.key.keysym.sym) 745 switch (eng.event.key.keysym.sym)
746 { 746 {
747 case SDLK_ESCAPE: 747 case SDLK_ESCAPE:
748 case SDLK_q: 748 case SDLK_q:
749 engine.exitFlag = TRUE; 749 eng.exitFlag = TRUE;
750 break; 750 break;
751 751
752 case SDLK_SPACE: 752 case SDLK_SPACE:
753 engine.pauseFlag = !engine.pauseFlag; 753 eng.pauseFlag = !eng.pauseFlag;
754 SDL_PauseAudio(engine.pauseFlag); 754 SDL_PauseAudio(eng.pauseFlag);
755 break; 755 break;
756 756
757 case SDLK_LEFT: 757 case SDLK_LEFT:
758 if (engine.actChannel > 0) 758 if (eng.actChannel > 0)
759 { 759 {
760 engine.actChannel--; 760 eng.actChannel--;
761 needUpdate = TRUE; 761 needUpdate = TRUE;
762 } 762 }
763 break; 763 break;
764 764
765 case SDLK_RIGHT: 765 case SDLK_RIGHT:
766 if (engine.actChannel < engine.mod->nchannels - 1) 766 if (eng.actChannel < eng.mod->nchannels - 1)
767 { 767 {
768 engine.actChannel++; 768 eng.actChannel++;
769 needUpdate = TRUE; 769 needUpdate = TRUE;
770 } 770 }
771 break; 771 break;
772 772
773 case SDLK_m: 773 case SDLK_m:
774 if (engine.event.key.keysym.mod & KMOD_SHIFT) 774 if (eng.event.key.keysym.mod & KMOD_SHIFT)
775 { 775 {
776 muteState = !muteState; 776 muteState = !muteState;
777 dmMuteChannels(muteState); 777 dmMuteChannels(muteState);
778 } 778 }
779 else 779 else
780 if (engine.event.key.keysym.mod & KMOD_CTRL) 780 if (eng.event.key.keysym.mod & KMOD_CTRL)
781 { 781 {
782 dmMuteChannels(FALSE); 782 dmMuteChannels(FALSE);
783 } 783 }
784 else 784 else
785 { 785 {
786 jvmMute(engine.dev, engine.actChannel, !jvmGetMute(engine.dev, engine.actChannel)); 786 jvmMute(eng.dev, eng.actChannel, !jvmGetMute(eng.dev, eng.actChannel));
787 } 787 }
788 needUpdate = TRUE; 788 needUpdate = TRUE;
789 break; 789 break;
790 790
791 case SDLK_PAGEUP: 791 case SDLK_PAGEUP:
792 JSS_LOCK(engine.dev); 792 JSS_LOCK(eng.dev);
793 JSS_LOCK(engine.plr); 793 JSS_LOCK(eng.plr);
794 jmpChangeOrder(engine.plr, dmClamp(engine.plr->order - 1, 0, engine.mod->norders)); 794 jmpChangeOrder(eng.plr, dmClamp(eng.plr->order - 1, 0, eng.mod->norders));
795 JSS_UNLOCK(engine.plr); 795 JSS_UNLOCK(eng.plr);
796 JSS_UNLOCK(engine.dev); 796 JSS_UNLOCK(eng.dev);
797 needUpdate = TRUE; 797 needUpdate = TRUE;
798 break; 798 break;
799 799
800 case SDLK_PAGEDOWN: 800 case SDLK_PAGEDOWN:
801 JSS_LOCK(engine.dev); 801 JSS_LOCK(eng.dev);
802 JSS_LOCK(engine.plr); 802 JSS_LOCK(eng.plr);
803 jmpChangeOrder(engine.plr, dmClamp(engine.plr->order + 1, 0, engine.mod->norders)); 803 jmpChangeOrder(eng.plr, dmClamp(eng.plr->order + 1, 0, eng.mod->norders));
804 JSS_UNLOCK(engine.plr); 804 JSS_UNLOCK(eng.plr);
805 JSS_UNLOCK(engine.dev); 805 JSS_UNLOCK(eng.dev);
806 needUpdate = TRUE; 806 needUpdate = TRUE;
807 break; 807 break;
808 808
809 case SDLK_f: 809 case SDLK_f:
810 engine.optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP; 810 eng.optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
811 if (SDL_SetWindowFullscreen(engine.window, engine.optVFlags) != 0) 811 if (SDL_SetWindowFullscreen(eng.window, eng.optVFlags) != 0)
812 goto error_exit; 812 goto error_exit;
813 needUpdate = TRUE; 813 needUpdate = TRUE;
814 break; 814 break;
815 815
816 default: 816 default:
818 } 818 }
819 819
820 break; 820 break;
821 821
822 case SDL_WINDOWEVENT: 822 case SDL_WINDOWEVENT:
823 switch (engine.event.window.event) 823 switch (eng.event.window.event)
824 { 824 {
825 case SDL_WINDOWEVENT_EXPOSED: 825 case SDL_WINDOWEVENT_EXPOSED:
826 needUpdate = TRUE; 826 needUpdate = TRUE;
827 break; 827 break;
828 828
829 case SDL_WINDOWEVENT_RESIZED: 829 case SDL_WINDOWEVENT_RESIZED:
830 engine.optScrWidth = engine.event.window.data1; 830 eng.optScrWidth = eng.event.window.data1;
831 engine.optScrHeight = engine.event.window.data2; 831 eng.optScrHeight = eng.event.window.data2;
832 if (!dmInitializeVideo()) 832 if (!dmInitializeVideo())
833 goto error_exit; 833 goto error_exit;
834 834
835 needUpdate = TRUE; 835 needUpdate = TRUE;
836 break; 836 break;
837 } 837 }
838 break; 838 break;
839 839
840 case SDL_QUIT: 840 case SDL_QUIT:
841 engine.exitFlag = TRUE; 841 eng.exitFlag = TRUE;
842 break; 842 break;
843 } 843 }
844 844
845 845
846 #if 1 846 #if 1
847 JSS_LOCK(engine.plr); 847 JSS_LOCK(eng.plr);
848 JSSPattern *currPattern = engine.plr->pattern; 848 JSSPattern *currPattern = eng.plr->pattern;
849 int currRow = engine.plr->row; 849 int currRow = eng.plr->row;
850 if (!engine.plr->isPlaying) 850 if (!eng.plr->isPlaying)
851 engine.exitFlag = TRUE; 851 eng.exitFlag = TRUE;
852 JSS_UNLOCK(engine.plr); 852 JSS_UNLOCK(eng.plr);
853 853
854 if (currRow != prevRow || needUpdate) 854 if (currRow != prevRow || needUpdate)
855 { 855 {
856 prevRow = currRow; 856 prevRow = currRow;
857 needUpdate = TRUE; 857 needUpdate = TRUE;
858 } 858 }
859 859
860 // Draw frame 860 // Draw frame
861 if (needUpdate) 861 if (needUpdate)
862 { 862 {
863 dmClearSurface(engine.screen, col.boxBg); 863 dmClearSurface(eng.screen, col.boxBg);
864 864
865 dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5, 865 dmDrawBMTextQ(eng.screen, font, DMD_TRANSPARENT, 5, 5,
866 "%s v%s by ccr/TNSP - (c) Copyright 2012-2018 TNSP", 866 "%s v%s by ccr/TNSP - (c) Copyright 2012-2018 TNSP",
867 dmProgDesc, dmProgVersion); 867 dmProgDesc, dmProgVersion);
868 868
869 dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2), 869 dmDrawBMTextQ(eng.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2),
870 "Song: '%s'", 870 "Song: '%s'",
871 engine.mod->moduleName); 871 eng.mod->moduleName);
872 872
873 dmDisplayPattern(engine.screen, 5, 5 + (font->height + 2) * 3 + 4, 873 dmDisplayPattern(eng.screen, 5, 5 + (font->height + 2) * 3 + 4,
874 engine.screen->w - 6, 874 eng.screen->w - 6,
875 engine.screen->h * 0.8, 875 eng.screen->h * 0.8,
876 currPattern, currRow); 876 currPattern, currRow);
877 877
878 JSS_LOCK(engine.plr); 878 JSS_LOCK(eng.plr);
879 dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2) * 2, 879 dmDrawBMTextQ(eng.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2) * 2,
880 "Tempo: %3d | Speed: %3d | Row: %3d/%-3d | Order: %3d/%-3d | Pattern: %3d/%-3d", 880 "Tempo: %3d | Speed: %3d | Row: %3d/%-3d | Order: %3d/%-3d | Pattern: %3d/%-3d",
881 engine.plr->tempo, engine.plr->speed, 881 eng.plr->tempo, eng.plr->speed,
882 engine.plr->row, (engine.plr->pattern != NULL) ? engine.plr->pattern->nrows : 0, 882 eng.plr->row, (eng.plr->pattern != NULL) ? eng.plr->pattern->nrows : 0,
883 engine.plr->order + 1, engine.mod->norders, 883 eng.plr->order + 1, eng.mod->norders,
884 engine.plr->npattern, engine.mod->npatterns); 884 eng.plr->npattern, eng.mod->npatterns);
885 JSS_UNLOCK(engine.plr); 885 JSS_UNLOCK(eng.plr);
886 needRender = TRUE; 886 needRender = TRUE;
887 } 887 }
888 888
889 if (needUpdate || currTick - prevTick >= (engine.pauseFlag ? 100 : 20)) 889 if (needUpdate || currTick - prevTick >= (eng.pauseFlag ? 100 : 20))
890 { 890 {
891 JSS_LOCK(engine.dev); 891 JSS_LOCK(eng.dev);
892 dmDisplayChannels(engine.screen, 5, engine.screen->h * 0.8 + 5, 892 dmDisplayChannels(eng.screen, 5, eng.screen->h * 0.8 + 5,
893 engine.screen->w - 5, engine.screen->h - 5, engine.dev); 893 eng.screen->w - 5, eng.screen->h - 5, eng.dev);
894 JSS_UNLOCK(engine.dev); 894 JSS_UNLOCK(eng.dev);
895 needRender = TRUE; 895 needRender = TRUE;
896 } 896 }
897 897
898 if (needUpdate) 898 if (needUpdate)
899 prevTick = currTick; 899 prevTick = currTick;
901 #endif 901 #endif
902 // Flip screen 902 // Flip screen
903 if (needRender) 903 if (needRender)
904 { 904 {
905 SDL_Surface dst; 905 SDL_Surface dst;
906 SDL_LockTexture(engine.texture, NULL, &dst.pixels, &dst.pitch); 906 SDL_LockTexture(eng.texture, NULL, &dst.pixels, &dst.pitch);
907 907
908 if (dst.pitch != engine.screen->pitch) 908 if (dst.pitch != eng.screen->pitch)
909 engine.exitFlag = TRUE; 909 eng.exitFlag = TRUE;
910 else 910 else
911 memcpy(dst.pixels, engine.screen->pixels, engine.screen->h * dst.pitch); 911 memcpy(dst.pixels, eng.screen->pixels, eng.screen->h * dst.pitch);
912 912
913 SDL_UnlockTexture(engine.texture); 913 SDL_UnlockTexture(eng.texture);
914 914
915 //SDL_RenderClear(engine.renderer); 915 //SDL_RenderClear(eng.renderer);
916 SDL_RenderCopy(engine.renderer, engine.texture, NULL, NULL); 916 SDL_RenderCopy(eng.renderer, eng.texture, NULL, NULL);
917 SDL_RenderPresent(engine.renderer); 917 SDL_RenderPresent(eng.renderer);
918 } 918 }
919 919
920 SDL_Delay(engine.pauseFlag ? 100 : 30); 920 SDL_Delay(eng.pauseFlag ? 100 : 30);
921 } 921 }
922 922
923 error_exit: 923 error_exit:
924 if (engine.texture != NULL) 924 if (eng.texture != NULL)
925 SDL_DestroyTexture(engine.texture); 925 SDL_DestroyTexture(eng.texture);
926 926
927 if (engine.renderer != NULL) 927 if (eng.renderer != NULL)
928 SDL_DestroyRenderer(engine.renderer); 928 SDL_DestroyRenderer(eng.renderer);
929 929
930 if (engine.window != NULL) 930 if (eng.window != NULL)
931 SDL_DestroyWindow(engine.window); 931 SDL_DestroyWindow(eng.window);
932 932
933 if (engine.screen != NULL) 933 if (eng.screen != NULL)
934 SDL_FreeSurface(engine.screen); 934 SDL_FreeSurface(eng.screen);
935 935
936 dmMsg(0, "Audio shutdown.\n"); 936 dmMsg(0, "Audio shutdown.\n");
937 if (audioInit) 937 if (audioInit)
938 { 938 {
939 SDL_LockAudio(); 939 SDL_LockAudio();
940 SDL_PauseAudio(1); 940 SDL_PauseAudio(1);
941 SDL_UnlockAudio(); 941 SDL_UnlockAudio();
942 SDL_CloseAudio(); 942 SDL_CloseAudio();
943 } 943 }
944 944
945 jmpClose(engine.plr); 945 jmpClose(eng.plr);
946 jvmClose(engine.dev); 946 jvmClose(eng.dev);
947 jssFreeModule(engine.mod); 947 jssFreeModule(eng.mod);
948 948
949 dmFreeBitmapFont(font); 949 dmFreeBitmapFont(font);
950 950
951 if (initSDL) 951 if (initSDL)
952 SDL_Quit(); 952 SDL_Quit();