@@ -499,126 +499,88 @@ namespace RTE {
499
499
500
500
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
501
501
502
- int FrameMan::DrawLine (BITMAP *bitmap, const Vector &start, const Vector &end, int color , int altColor , int skip, int skipStart, bool shortestWrap ) {
503
- RTEAssert (bitmap, " Trying to draw line to null Bitmap " );
504
-
505
- // acquire_bitmap(bitmap );
502
+ void FrameMan::CreateNewPlayerBackBuffer ( int player , int w , int h ) {
503
+ for ( int f = 0 ; f < 2 ; f++) {
504
+ destroy_bitmap (m_NetworkBackBufferIntermediate8[f][player]);
505
+ m_NetworkBackBufferIntermediate8[f][player] = create_bitmap_ex ( 8 , w, h );
506
506
507
- int error = 0 ;
508
- int dom = 0 ;
509
- int sub = 0 ;
510
- int domSteps = 0 ;
511
- int skipped = skip + (skipStart - skip);
512
- int intPos[2 ];
513
- int delta[2 ];
514
- int delta2[2 ];
515
- int increment[2 ];
516
- bool drawAlt = false ;
507
+ destroy_bitmap (m_NetworkBackBufferIntermediateGUI8[f][player]);
508
+ m_NetworkBackBufferIntermediateGUI8[f][player] = create_bitmap_ex (8 , w, h);
517
509
518
- // Just make the alt the same color as the main one if no one was specified
519
- if (altColor == 0 ) { altColor = color; }
520
-
521
- intPos[X] = floorf (start.m_X );
522
- intPos[Y] = floorf (start.m_Y );
510
+ destroy_bitmap (m_NetworkBackBufferFinal8[f][player]);
511
+ m_NetworkBackBufferFinal8[f][player] = create_bitmap_ex (8 , w, h);
523
512
524
- // Wrap line around the scene if it makes it shorter
525
- if (shortestWrap) {
526
- Vector deltaVec = g_SceneMan.ShortestDistance (start, end, false );
527
- delta[X] = floorf (deltaVec.m_X );
528
- delta[Y] = floorf (deltaVec.m_Y );
529
- } else {
530
- delta[X] = floorf (end.m_X ) - intPos[X];
531
- delta[Y] = floorf (end.m_Y ) - intPos[Y];
513
+ destroy_bitmap (m_NetworkBackBufferFinalGUI8[f][player]);
514
+ m_NetworkBackBufferFinalGUI8[f][player] = create_bitmap_ex (8 , w, h);
532
515
}
533
- if (delta[X] == 0 && delta[Y] == 0 ) {
516
+ m_PlayerScreenWidth = w;
517
+ m_PlayerScreenHeight = h;
518
+ }
519
+
520
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
521
+
522
+ bool FrameMan::LoadPalette (std::string palettePath) {
523
+ PALETTE newPalette;
524
+ BITMAP *tempBitmap = load_bitmap (palettePath.c_str (), newPalette);
525
+ RTEAssert (tempBitmap, (" Failed to load palette from bitmap with following path:\n\n " + palettePath).c_str ());
526
+
527
+ set_palette (newPalette);
528
+
529
+ // Update what black is now with the loaded palette
530
+ m_BlackColor = bestfit_color (newPalette, 0 , 0 , 0 );
531
+ m_AlmostBlackColor = bestfit_color (newPalette, 5 , 5 , 5 );
532
+
533
+ destroy_bitmap (tempBitmap);
534
+
535
+ return true ;
536
+ }
537
+
534
538
return 0 ;
535
539
}
536
540
537
- // Bresenham's line drawing algorithm preparation
538
- if (delta[X] < 0 ) {
539
- increment[X] = -1 ;
540
- delta[X] = -delta[X];
541
- } else {
542
- increment[X] = 1 ;
543
- }
544
- if (delta[Y] < 0 ) {
545
- increment[Y] = -1 ;
546
- delta[Y] = -delta[Y];
547
- } else {
548
- increment[Y] = 1 ;
549
541
}
550
- // Scale by 2, for better accuracy of the error at the first pixel
551
- delta2[X] = delta[X] << 1 ;
552
- delta2[Y] = delta[Y] << 1 ;
553
542
554
- // If X is dominant, Y is submissive, and vice versa.
555
- if (delta[X] > delta[Y]) {
556
- dom = X;
557
- sub = Y;
558
- } else {
559
- dom = Y;
560
- sub = X;
561
- }
562
- error = delta2[sub] - delta[dom];
563
543
564
- // Bresenham's line drawing algorithm execution
565
- for (domSteps = 0 ; domSteps < delta[dom]; ++domSteps) {
566
- intPos[dom] += increment[dom];
567
- if (error >= 0 ) {
568
- intPos[sub] += increment[sub];
569
- error -= delta2[dom];
570
544
}
571
- error += delta2[sub];
572
545
573
- // Only draw pixel if we're not due to skip any
574
- if (++skipped > skip) {
575
- // Scene wrapping, if necessary
576
- g_SceneMan.WrapPosition (intPos[X], intPos[Y]);
577
546
578
- // Slap a regular pixel on there
579
- putpixel (bitmap, intPos[X], intPos[Y], drawAlt ? color : altColor);
580
- drawAlt = !drawAlt;
581
- skipped = 0 ;
582
- }
583
547
}
584
- // release_bitmap(bitmap);
585
-
586
- // Return the end phase state of the skipping
587
- return skipped;
588
548
}
589
549
590
550
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
591
551
592
- int FrameMan::DrawDotLine (BITMAP *bitmap, const Vector &start, const Vector &end, BITMAP *dot , int skip, int skipStart, bool shortestWrap) {
552
+ int FrameMan::SharedDrawLine (BITMAP *bitmap, const Vector &start, const Vector &end, int color , int altColor, int skip, int skipStart, bool shortestWrap, bool drawDot, BITMAP *dot ) {
593
553
RTEAssert (bitmap, " Trying to draw line to null Bitmap" );
594
- RTEAssert (dot, " Trying to draw line of dots without specifying a dot Bitmap" );
595
-
596
- // acquire_bitmap(bitmap);
554
+ if (drawDot) { RTEAssert (dot, " Trying to draw line of dots without specifying a dot Bitmap" ); }
597
555
598
- int error = 0 ;
599
- int dom = 0 ;
600
- int sub = 0 ;
601
- int domSteps = 0 ;
602
- int skipped = skip + (skipStart - skip);
556
+ int error = 0 ;
557
+ int dom = 0 ;
558
+ int sub = 0 ;
559
+ int domSteps = 0 ;
560
+ int skipped = skip + (skipStart - skip);
603
561
int intPos[2 ];
604
562
int delta[2 ];
605
563
int delta2[2 ];
606
564
int increment[2 ];
607
565
bool drawAlt = false ;
608
- int dotHalfHeight = dot->h / 2 ;
609
- int dotHalfWidth = dot->w / 2 ;
610
566
611
- // Calculate the integer values
567
+ int dotHeight = drawDot ? dot->h : 0 ;
568
+ int dotWidth = drawDot ? dot->w : 0 ;
569
+
570
+ // acquire_bitmap(bitmap);
571
+
572
+ // Just make the alt the same color as the main one if no one was specified
573
+ if (altColor == 0 ) { altColor = color; }
574
+
612
575
intPos[X] = floorf (start.m_X );
613
576
intPos[Y] = floorf (start.m_Y );
614
577
615
578
// Wrap line around the scene if it makes it shorter
616
579
if (shortestWrap) {
617
580
Vector deltaVec = g_SceneMan.ShortestDistance (start, end, false );
618
581
delta[X] = floorf (deltaVec.m_X );
619
- delta[Y] = floorf (deltaVec.m_Y );
582
+ delta[Y] = floorf (deltaVec.m_Y );
620
583
} else {
621
- // No wrap
622
584
delta[X] = floorf (end.m_X ) - intPos[X];
623
585
delta[Y] = floorf (end.m_Y ) - intPos[Y];
624
586
}
@@ -639,6 +601,7 @@ namespace RTE {
639
601
} else {
640
602
increment[Y] = 1 ;
641
603
}
604
+
642
605
// Scale by 2, for better accuracy of the error at the first pixel
643
606
delta2[X] = delta[X] << 1 ;
644
607
delta2[Y] = delta[Y] << 1 ;
@@ -667,57 +630,22 @@ namespace RTE {
667
630
// Scene wrapping, if necessary
668
631
g_SceneMan.WrapPosition (intPos[X], intPos[Y]);
669
632
670
- // Slap the dot on there
671
- masked_blit (dot, bitmap, 0 , 0 , intPos[X] - dotHalfWidth, intPos[Y] - dotHalfHeight, dot->w , dot->h );
672
-
633
+ if (drawDot) {
634
+ masked_blit (dot, bitmap, 0 , 0 , intPos[X] - (dotWidth / 2 ), intPos[Y] - (dotHeight / 2 ), dot->w , dot->h );
635
+ } else {
636
+ putpixel (bitmap, intPos[X], intPos[Y], drawAlt ? color : altColor);
637
+ }
673
638
drawAlt = !drawAlt;
674
639
skipped = 0 ;
675
640
}
676
641
}
642
+
677
643
// release_bitmap(bitmap);
678
644
679
645
// Return the end phase state of the skipping
680
646
return skipped;
681
647
}
682
648
683
- // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
684
-
685
- void FrameMan::CreateNewPlayerBackBuffer (int player, int w, int h) {
686
- for (int f = 0 ; f < 2 ; f++) {
687
- destroy_bitmap (m_NetworkBackBufferIntermediate8[f][player]);
688
- m_NetworkBackBufferIntermediate8[f][player] = create_bitmap_ex (8 , w, h);
689
-
690
- destroy_bitmap (m_NetworkBackBufferIntermediateGUI8[f][player]);
691
- m_NetworkBackBufferIntermediateGUI8[f][player] = create_bitmap_ex (8 , w, h);
692
-
693
- destroy_bitmap (m_NetworkBackBufferFinal8[f][player]);
694
- m_NetworkBackBufferFinal8[f][player] = create_bitmap_ex (8 , w, h);
695
-
696
- destroy_bitmap (m_NetworkBackBufferFinalGUI8[f][player]);
697
- m_NetworkBackBufferFinalGUI8[f][player] = create_bitmap_ex (8 , w, h);
698
- }
699
- m_PlayerScreenWidth = w;
700
- m_PlayerScreenHeight = h;
701
- }
702
-
703
- // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
704
-
705
- bool FrameMan::LoadPalette (std::string palettePath) {
706
- PALETTE newPalette;
707
- BITMAP *tempBitmap = load_bitmap (palettePath.c_str (), newPalette);
708
- RTEAssert (tempBitmap, (" Failed to load palette from bitmap with following path:\n\n " + palettePath).c_str ());
709
-
710
- set_palette (newPalette);
711
-
712
- // Update what black is now with the loaded palette
713
- m_BlackColor = bestfit_color (newPalette, 0 , 0 , 0 );
714
- m_AlmostBlackColor = bestfit_color (newPalette, 5 , 5 , 5 );
715
-
716
- destroy_bitmap (tempBitmap);
717
-
718
- return true ;
719
- }
720
-
721
649
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
722
650
723
651
int FrameMan::SaveScreenToBMP (const char *nameBase) {
0 commit comments