From e3cd0268741671c38e3ab5df8cdfe7bf137cabce Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 20 Oct 2011 02:20:44 -0400
Subject: [PATCH] First pass converting to SDL 1.3, converted over screenlib
and maclib, and started working on the game itself.
---
Maelstrom.h | 2 +-
Maelstrom_Globals.h | 6 +-
controls.cpp | 10 +-
controls.h | 14 +-
dialog.cpp | 25 +-
dialog.h | 223 ++++------
init.cpp | 10 +-
load.cpp | 9 +-
load.h | 4 +-
logic.h | 8 +-
maclib/Mac_FontServ.cpp | 65 +--
maclib/Mac_FontServ.h | 12 +-
maclib/Mac_Sound.cpp | 4 +-
main.cpp | 8 +-
netlogic/about.cpp | 7 +-
netlogic/blit.cpp | 6 -
netlogic/game.cpp | 463 ++++++--------------
netlogic/logic.cpp | 4 +-
netlogic/object.cpp | 18 -
netlogic/object.h | 2 -
netlogic/player.cpp | 37 +-
netlogic/player.h | 1 -
netlogic/shinobi.h | 10 -
scores.cpp | 6 +-
screenlib/SDL_FrameBuf.cpp | 845 ++++++-------------------------------
screenlib/SDL_FrameBuf.h | 191 ++++-----
26 files changed, 512 insertions(+), 1478 deletions(-)
diff --git a/Maelstrom.h b/Maelstrom.h
index 13f07686..9b8fef0c 100644
--- a/Maelstrom.h
+++ b/Maelstrom.h
@@ -81,6 +81,6 @@ typedef struct {
int numFrames;
int isSmall;
Rect hitRect;
- SDL_Surface *sprite[MAX_SPRITE_FRAMES];
+ SDL_Texture *sprite[MAX_SPRITE_FRAMES];
Uint8 *mask[MAX_SPRITE_FRAMES];
} Blit, *BlitPtr;
diff --git a/Maelstrom_Globals.h b/Maelstrom_Globals.h
index 5e001d5f..a4694bce 100644
--- a/Maelstrom_Globals.h
+++ b/Maelstrom_Globals.h
@@ -128,6 +128,6 @@ extern BlitPtr gThrust1, gThrust2, gShrapnel1, gShrapnel2;
/* -- The prize CICN's */
-extern SDL_Surface *gAutoFireIcon, *gAirBrakesIcon, *gMult2Icon, *gMult3Icon;
-extern SDL_Surface *gMult4Icon, *gMult5Icon, *gLuckOfTheIrishIcon;
-extern SDL_Surface *gLongFireIcon, *gTripleFireIcon, *gKeyIcon, *gShieldIcon;
+extern SDL_Texture *gAutoFireIcon, *gAirBrakesIcon, *gMult2Icon, *gMult3Icon;
+extern SDL_Texture *gMult4Icon, *gMult5Icon, *gLuckOfTheIrishIcon;
+extern SDL_Texture *gLongFireIcon, *gTripleFireIcon, *gKeyIcon, *gShieldIcon;
diff --git a/controls.cpp b/controls.cpp
index e9ae6b5a..d8dc6dce 100644
--- a/controls.cpp
+++ b/controls.cpp
@@ -165,7 +165,7 @@ static struct {
static int X=0;
static int Y=0;
static MFont *chicago;
-static SDL_Surface *keynames[NUM_CTLS];
+static SDL_Texture *keynames[NUM_CTLS];
static int currentbox, valid;
static int OK_callback(void) {
@@ -240,13 +240,13 @@ void ConfigureControls(void)
"While playing Maelstrom, CAPS LOCK pauses the game and";
static char *C_text2 =
"ESC aborts the game.";
- SDL_Surface *text1, *text2;
+ SDL_Texture *text1, *text2;
#endif
Uint32 black;
int i;
char keyname[128];
Maclike_Dialog *dialog;
- SDL_Surface *splash;
+ SDL_Texture *splash;
Mac_Button *cancel, *okay;
Mac_RadioList *radiobuttons;
Mac_Dialog *boxes;
@@ -411,7 +411,7 @@ static void HandleEvent(SDL_Event *event)
SetControl(PAUSE_KEY, 1);
else if ( key == controls.gQuitControl )
SetControl(ABORT_KEY, 1);
- else if ( SpecialKey(event->key.keysym) == 0 )
+ else if ( SpecialKey(event->key.keysym.sym) == 0 )
/* The key has been handled */;
else if ( key == SDLK_F3 ) {
/* Special key --
@@ -499,7 +499,7 @@ void ShowDawn(void)
"dawn."
};
MFont *chicago;
- SDL_Surface *splash, *text[6];
+ SDL_Texture *splash, *text[6];
Maclike_Dialog *dialog;
Mac_Button *OK;
int i, x, y, X, Y;
diff --git a/controls.h b/controls.h
index 1057fc0a..916ddcaa 100644
--- a/controls.h
+++ b/controls.h
@@ -22,12 +22,12 @@ extern void ShowDawn(void);
/* The controls structure */
typedef struct {
- SDLKey gPauseControl;
- SDLKey gShieldControl;
- SDLKey gThrustControl;
- SDLKey gTurnRControl;
- SDLKey gTurnLControl;
- SDLKey gFireControl;
- SDLKey gQuitControl;
+ SDL_Keycode gPauseControl;
+ SDL_Keycode gShieldControl;
+ SDL_Keycode gThrustControl;
+ SDL_Keycode gTurnRControl;
+ SDL_Keycode gTurnLControl;
+ SDL_Keycode gFireControl;
+ SDL_Keycode gQuitControl;
} Controls;
diff --git a/dialog.cpp b/dialog.cpp
index 0178273f..e4be64d6 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -194,8 +194,6 @@ Maclike_Dialog:: Add_Dialog(Mac_Dialog *dialog)
void
Maclike_Dialog:: Run(int expand_steps)
{
- SDL_Surface *savedfg;
- SDL_Surface *savedbg;
SDL_Event event;
struct rect_elem *relem;
struct image_elem *ielem;
@@ -205,11 +203,6 @@ Maclike_Dialog:: Run(int expand_steps)
int maxX, maxY;
double XX, YY, H, Hstep, V, Vstep;
- /* Save the area behind the dialog box */
- savedfg = Screen->GrabArea(X, Y, Width, Height);
- Screen->FocusBG();
- savedbg = Screen->GrabArea(X, Y, Width, Height);
-
/* Show the dialog box with the nice Mac border */
black = Screen->MapRGB(0x00, 0x00, 0x00);
dark = Screen->MapRGB(0x66, 0x66, 0x99);
@@ -229,7 +222,6 @@ Maclike_Dialog:: Run(int expand_steps)
Screen->DrawLine(maxX-2, Y+3, maxX-2, maxY-2, light);
Screen->DrawRect(X+3, Y+3, Width-6, Height-6, black);
Screen->FillRect(X+4, Y+4, Width-8, Height-8, white);
- Screen->FocusFG();
/* Allow the dialog to expand slowly */
XX = (double)(X+Width/2);
@@ -269,8 +261,7 @@ Maclike_Dialog:: Run(int expand_steps)
ielem->image, NOCLIP);
}
for ( delem = dialog_list.next; delem; delem = delem->next ) {
- delem->dialog->Map(X+4, Y+4, Screen,
- 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00);
+ delem->dialog->Map(X+4, Y+4, Screen);
delem->dialog->Show();
}
Screen->Update();
@@ -293,18 +284,4 @@ Maclike_Dialog:: Run(int expand_steps)
break;
}
}
-
- /* Replace the old section of screen */
- if ( savedbg ) {
- Screen->FocusBG();
- Screen->QueueBlit(X, Y, savedbg, NOCLIP);
- Screen->Update();
- Screen->FocusFG();
- Screen->FreeImage(savedbg);
- }
- if ( savedfg ) {
- Screen->QueueBlit(X, Y, savedfg, NOCLIP);
- Screen->Update();
- Screen->FreeImage(savedfg);
- }
}
diff --git a/dialog.h b/dialog.h
index 4a081ac0..ca1f8ae0 100644
--- a/dialog.h
+++ b/dialog.h
@@ -18,6 +18,16 @@
#define EXPAND_STEPS 50
+/* Foreground color */
+#define R_FG 0x00
+#define G_FG 0x00
+#define B_FG 0x00
+
+/* Background color */
+#define R_BG 0xFF
+#define G_BG 0xFF
+#define B_BG 0xFF
+
class Mac_Dialog {
public:
@@ -29,26 +39,23 @@ class Mac_Dialog {
(int x, int y, int button, int *doneflag)) {
button_callback = new_button_callback;
}
- virtual void HandleButtonPress(int x, int y, int button,
- int *doneflag) {
+ virtual void HandleButtonPress(int x, int y, int button, int *doneflag) {
if ( button_callback ) {
(*button_callback)(x, y, button, doneflag);
}
}
virtual void SetKeyPress(void (*new_key_callback)
- (SDL_keysym key, int *doneflag)) {
+ (const SDL_Keysym &key, int *doneflag)) {
key_callback = new_key_callback;
}
- virtual void HandleKeyPress(SDL_keysym key, int *doneflag) {
+ virtual void HandleKeyPress(const SDL_Keysym &key, int *doneflag) {
if ( key_callback ) {
(*key_callback)(key, doneflag);
}
}
/* Display handling */
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
X += Xoff;
Y += Yoff;
Screen = screen;
@@ -58,12 +65,12 @@ class Mac_Dialog {
static void EnableText(void) {
if ( text_enabled++ == 0 ) {
- SDL_EnableUNICODE(1);
+ SDL_StartTextInput();
}
}
static void DisableText(void) {
if ( --text_enabled == 0 ) {
- SDL_EnableUNICODE(0);
+ SDL_StopTextInput();
}
}
@@ -77,10 +84,10 @@ class Mac_Dialog {
FrameBuf *Screen;
int X, Y;
void (*button_callback)(int x, int y, int button, int *doneflag);
- void (*key_callback)(SDL_keysym key, int *doneflag);
+ void (*key_callback)(const SDL_Keysym &key, int *doneflag);
/* Utility routines for dialogs */
- int IsSensitive(SDL_Rect *area, int x, int y) {
+ int IsSensitive(const SDL_Rect *area, int x, int y) {
if ( (y > area->y) && (y < (area->y+area->h)) &&
(x > area->x) && (x < (area->x+area->w)) )
return(1);
@@ -115,33 +122,21 @@ class Mac_Button : public Mac_Dialog {
SDL_FreeSurface(button);
}
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
/* Do the normal dialog mapping */
- Mac_Dialog::Map(Xoff, Yoff, screen,
- R_bg, G_bg, B_bg, R_fg, G_fg, B_fg);
+ Mac_Dialog::Map(Xoff, Yoff, screen);
/* Set up the button sensitivity */
sensitive.x = X;
sensitive.y = Y;
sensitive.w = Width;
sensitive.h = Height;
-
- /* Map the bitmap image */
- button->format->palette->colors[0].r = R_bg;
- button->format->palette->colors[0].g = G_bg;
- button->format->palette->colors[0].b = B_bg;
- button->format->palette->colors[1].r = R_fg;
- button->format->palette->colors[1].g = G_fg;
- button->format->palette->colors[1].b = B_fg;
}
virtual void Show(void) {
Screen->QueueBlit(X, Y, button, NOCLIP);
}
- virtual void HandleButtonPress(int x, int y, int button,
- int *doneflag) {
+ virtual void HandleButtonPress(int x, int y, int button, int *doneflag) {
if ( IsSensitive(&sensitive, x, y) )
ActivateButton(doneflag);
}
@@ -221,17 +216,14 @@ class Mac_DefaultButton : public Mac_Button {
int (*callback)(void));
virtual ~Mac_DefaultButton() { }
- virtual void HandleKeyPress(SDL_keysym key, int *doneflag) {
+ virtual void HandleKeyPress(const SDL_Keysym &key, int *doneflag) {
if ( key.sym == SDLK_RETURN )
ActivateButton(doneflag);
}
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
- Mac_Button::Map(Xoff, Yoff, screen,
- R_bg, G_bg, B_bg, R_fg, G_fg, B_fg);
- Fg = Screen->MapRGB(R_fg, G_fg, B_fg);
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
+ Mac_Button::Map(Xoff, Yoff, screen);
+ Fg = Screen->MapRGB(R_FG, G_FG, B_FG);
}
virtual void Show(void) {
int x, y, maxx, maxy;
@@ -293,21 +285,15 @@ class Mac_CheckBox : public Mac_Dialog {
}
}
- virtual void HandleButtonPress(int x, int y, int button,
- int *doneflag) {
+ virtual void HandleButtonPress(int x, int y, int button, int *doneflag) {
if ( IsSensitive(&sensitive, x, y) ) {
*checkval = !*checkval;
- Check_Box(*checkval);
- Screen->Update();
}
}
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
/* Do the normal dialog mapping */
- Mac_Dialog::Map(Xoff, Yoff, screen,
- R_bg, G_bg, B_bg, R_fg, G_fg, B_fg);
+ Mac_Dialog::Map(Xoff, Yoff, screen);
/* Set up the checkbox sensitivity */
sensitive.x = X;
@@ -316,42 +302,27 @@ class Mac_CheckBox : public Mac_Dialog {
sensitive.h = CHECKBOX_SIZE;
/* Get the screen colors */
- Fg = Screen->MapRGB(R_fg, G_fg, B_fg);
- Bg = Screen->MapRGB(R_bg, G_bg, B_bg);
-
- /* Map the checkbox text */
- label->format->palette->colors[1].r = R_fg;
- label->format->palette->colors[1].g = G_fg;
- label->format->palette->colors[1].b = B_fg;
+ Fg = Screen->MapRGB(R_FG, G_FG, B_FG);
}
virtual void Show(void) {
Screen->DrawRect(X, Y, CHECKBOX_SIZE, CHECKBOX_SIZE, Fg);
if ( label ) {
Screen->QueueBlit(X+CHECKBOX_SIZE+4, Y-2, label,NOCLIP);
}
- Check_Box(*checkval);
+ if ( *checkval ) {
+ Screen->DrawLine(X, Y,
+ X+CHECKBOX_SIZE-1, Y+CHECKBOX_SIZE-1, Fg);
+ Screen->DrawLine(X, Y+CHECKBOX_SIZE-1,
+ X+CHECKBOX_SIZE-1, Y, Fg);
+ }
}
private:
FontServ *Fontserv;
- SDL_Surface *label;
- Uint32 Fg, Bg;
+ SDL_Texture *label;
+ Uint32 Fg;
int *checkval;
SDL_Rect sensitive;
-
- void Check_Box(int checked) {
- Uint32 color;
-
- if ( checked )
- color = Fg;
- else
- color = Bg;
-
- Screen->DrawLine(X, Y,
- X+CHECKBOX_SIZE-1, Y+CHECKBOX_SIZE-1, color);
- Screen->DrawLine(X, Y+CHECKBOX_SIZE-1,
- X+CHECKBOX_SIZE-1, Y, color);
- }
};
/* Class of radio buttons */
@@ -373,24 +344,13 @@ class Mac_RadioList : public Mac_Dialog {
}
}
- virtual void HandleButtonPress(int x, int y, int button,
- int *doneflag) {
+ virtual void HandleButtonPress(int x, int y, int button, int *doneflag) {
int n;
- struct radio *radio, *oldradio;
+ struct radio *radio;
- oldradio = radio_list.next;
- for (n=0, radio=radio_list.next; radio; radio=radio->next, ++n){
- if ( n == *radiovar ) {
- oldradio = radio;
- break;
- }
- }
for (n=0, radio=radio_list.next; radio; radio=radio->next, ++n){
if ( IsSensitive(&radio->sensitive, x, y) ) {
- Spot(oldradio->x, oldradio->y, Bg);
*radiovar = n;
- Spot(radio->x, radio->y, Fg);
- Screen->Update();
}
}
}
@@ -413,23 +373,17 @@ class Mac_RadioList : public Mac_Dialog {
radio->y = y;
radio->sensitive.x = x;
radio->sensitive.y = y;
- radio->sensitive.w = 20+radio->label->w;
- radio->sensitive.h = BOX_HEIGHT;
radio->next = NULL;
}
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
struct radio *radio;
/* Do the normal dialog mapping */
- Mac_Dialog::Map(Xoff, Yoff, screen,
- R_bg, G_bg, B_bg, R_fg, G_fg, B_fg);
+ Mac_Dialog::Map(Xoff, Yoff, screen);
/* Get the screen colors */
- Fg = Screen->MapRGB(R_fg, G_fg, B_fg);
- Bg = Screen->MapRGB(R_bg, G_bg, B_bg);
+ Fg = Screen->MapRGB(R_FG, G_FG, B_FG);
/* Adjust sensitivity and map the radiobox text */
for ( radio=radio_list.next; radio; radio=radio->next ) {
@@ -437,9 +391,8 @@ class Mac_RadioList : public Mac_Dialog {
radio->y += Yoff;
radio->sensitive.x += Xoff;
radio->sensitive.y += Yoff;
- radio->label->format->palette->colors[1].r = R_fg;
- radio->label->format->palette->colors[1].g = G_fg;
- radio->label->format->palette->colors[1].b = B_fg;
+ radio->sensitive.w = 20+Screen->GetImageWidth(radio->label);
+ radio->sensitive.h = BOX_HEIGHT;
}
}
virtual void Show(void) {
@@ -449,7 +402,7 @@ class Mac_RadioList : public Mac_Dialog {
for (n=0, radio=radio_list.next; radio; radio=radio->next, ++n){
Circle(radio->x, radio->y);
if ( n == *radiovar ) {
- Spot(radio->x, radio->y, Fg);
+ Spot(radio->x, radio->y);
}
if ( radio->label ) {
Screen->QueueBlit(radio->x+21, radio->y+3,
@@ -461,10 +414,10 @@ class Mac_RadioList : public Mac_Dialog {
private:
FontServ *Fontserv;
MFont *Font;
- Uint32 Fg, Bg;
+ Uint32 Fg;
int *radiovar;
struct radio {
- SDL_Surface *label;
+ SDL_Texture *label;
int x, y;
SDL_Rect sensitive;
struct radio *next;
@@ -486,21 +439,21 @@ class Mac_RadioList : public Mac_Dialog {
Screen->DrawLine(x+8, y+10, x+9, y+10, Fg);
Screen->DrawLine(x+4, y+11, x+7, y+11, Fg);
}
- void Spot(int x, int y, Uint32 color)
+ void Spot(int x, int y);
{
x += 8;
y += 8;
- Screen->DrawLine(x+1, y, x+4, y, color);
+ Screen->DrawLine(x+1, y, x+4, y, Fg);
++y;
- Screen->DrawLine(x, y, x+5, y, color);
+ Screen->DrawLine(x, y, x+5, y, Fg);
++y;
- Screen->DrawLine(x, y, x+5, y, color);
+ Screen->DrawLine(x, y, x+5, y, Fg);
++y;
- Screen->DrawLine(x, y, x+5, y, color);
+ Screen->DrawLine(x, y, x+5, y, Fg);
++y;
- Screen->DrawLine(x, y, x+5, y, color);
+ Screen->DrawLine(x, y, x+5, y, Fg);
++y;
- Screen->DrawLine(x+1, y, x+4, y, color);
+ Screen->DrawLine(x+1, y, x+4, y, Fg);
}
};
@@ -524,8 +477,7 @@ class Mac_TextEntry : public Mac_Dialog {
DisableText();
}
- virtual void HandleButtonPress(int x, int y, int button,
- int *doneflag) {
+ virtual void HandleButtonPress(int x, int y, int button, int *doneflag) {
struct text_entry *entry;
for ( entry=entry_list.next; entry; entry=entry->next ) {
@@ -538,7 +490,7 @@ class Mac_TextEntry : public Mac_Dialog {
}
}
}
- virtual void HandleKeyPress(SDL_keysym key, int *doneflag) {
+ virtual void HandleKeyPress(const SDL_Keysym &key, int *doneflag) {
int n;
switch (key.sym) {
@@ -609,24 +561,21 @@ class Mac_TextEntry : public Mac_Dialog {
entry->next = NULL;
}
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
struct text_entry *entry;
/* Do the normal dialog mapping */
- Mac_Dialog::Map(Xoff, Yoff, screen,
- R_bg, G_bg, B_bg, R_fg, G_fg, B_fg);
+ Mac_Dialog::Map(Xoff, Yoff, screen);
/* Get the screen colors */
- foreground.r = R_fg;
- foreground.g = G_fg;
- foreground.b = B_fg;
- background.r = R_bg;
- background.g = G_bg;
- background.b = B_bg;
- Fg = Screen->MapRGB(R_fg, G_fg, B_fg);
- Bg = Screen->MapRGB(R_bg, G_bg, B_bg);
+ foreground.r = R_FG;
+ foreground.g = G_FG;
+ foreground.b = B_FG;
+ background.r = R_BG;
+ background.g = G_BG;
+ background.b = B_BG;
+ Fg = Screen->MapRGB(R_FG, G_FG, B_FG);
+ Bg = Screen->MapRGB(R_BG, G_BG, B_BG);
/* Adjust sensitivity and map the radiobox text */
for ( entry=entry_list.next; entry; entry=entry->next ) {
@@ -655,7 +604,7 @@ class Mac_TextEntry : public Mac_Dialog {
SDL_Color background;
struct text_entry {
- SDL_Surface *text;
+ SDL_Texture *text;
char *variable;
SDL_Rect sensitive;
int x, y;
@@ -685,7 +634,7 @@ class Mac_TextEntry : public Mac_Dialog {
Screen->FillRect(entry->x, entry->y,
entry->width, entry->height, clear);
if ( entry->text ) {
- entry->end = entry->text->w;
+ entry->end = Screen->GetImageWidth(entry->text);
Screen->QueueBlit(entry->x, entry->y, entry->text, NOCLIP);
} else {
entry->end = 0;
@@ -716,8 +665,7 @@ class Mac_NumericEntry : public Mac_Dialog {
}
}
- virtual void HandleButtonPress(int x, int y, int button,
- int *doneflag) {
+ virtual void HandleButtonPress(int x, int y, int button, int *doneflag) {
struct numeric_entry *entry;
for ( entry=entry_list.next; entry; entry=entry->next ) {
@@ -730,7 +678,7 @@ class Mac_NumericEntry : public Mac_Dialog {
}
}
}
- virtual void HandleKeyPress(SDL_keysym key, int *doneflag) {
+ virtual void HandleKeyPress(const SDL_Keysym &key, int *doneflag) {
int n;
switch (key.sym) {
@@ -813,24 +761,21 @@ class Mac_NumericEntry : public Mac_Dialog {
entry->next = NULL;
}
- virtual void Map(int Xoff, int Yoff, FrameBuf *screen,
- Uint8 R_bg, Uint8 G_bg, Uint8 B_bg,
- Uint8 R_fg, Uint8 G_fg, Uint8 B_fg) {
+ virtual void Map(int Xoff, int Yoff, FrameBuf *screen) {
struct numeric_entry *entry;
/* Do the normal dialog mapping */
- Mac_Dialog::Map(Xoff, Yoff, screen,
- R_bg, G_bg, B_bg, R_fg, G_fg, B_fg);
+ Mac_Dialog::Map(Xoff, Yoff, screen);
/* Get the screen colors */
- foreground.r = R_fg;
- foreground.g = G_fg;
- foreground.b = B_fg;
- background.r = R_bg;
- background.g = G_bg;
- background.b = B_bg;
- Fg = Screen->MapRGB(R_fg, G_fg, B_fg);
- Bg = Screen->MapRGB(R_bg, G_bg, B_bg);
+ foreground.r = R_FG;
+ foreground.g = G_FG;
+ foreground.b = B_FG;
+ background.r = R_BG;
+ background.g = G_BG;
+ background.b = B_BG;
+ Fg = Screen->MapRGB(R_FG, G_FG, B_FG);
+ Bg = Screen->MapRGB(R_BG, G_BG, B_BG);
/* Adjust sensitivity and map the radiobox text */
for ( entry=entry_list.next; entry; entry=entry->next ) {
@@ -859,7 +804,7 @@ class Mac_NumericEntry : public Mac_Dialog {
SDL_Color background;
struct numeric_entry {
- SDL_Surface *text;
+ SDL_Texture *text;
int *variable;
SDL_Rect sensitive;
int x, y;
@@ -889,7 +834,7 @@ class Mac_NumericEntry : public Mac_Dialog {
entry->text = Fontserv->TextImage(buf,
Font, STYLE_NORM, foreground, background);
}
- entry->end = entry->text->w;
+ entry->end = Screen->GetImageWidth(entry->text);
Screen->FillRect(entry->x, entry->y,
entry->width, entry->height, clear);
Screen->QueueBlit(entry->x, entry->y, entry->text, NOCLIP);
@@ -910,7 +855,7 @@ class Maclike_Dialog {
~Maclike_Dialog();
void Add_Rectangle(int x, int y, int w, int h, Uint32 color);
- void Add_Image(SDL_Surface *image, int x, int y);
+ void Add_Image(SDL_Texture *image, int x, int y);
void Add_Dialog(Mac_Dialog *dialog);
void Run(int expand_steps = 1);
@@ -927,7 +872,7 @@ class Maclike_Dialog {
struct rect_elem *next;
} rect_list;
struct image_elem {
- SDL_Surface *image;
+ SDL_Texture *image;
int x, y;
struct image_elem *next;
} image_list;
diff --git a/init.cpp b/init.cpp
index 7938f7e3..bd100b5e 100644
--- a/init.cpp
+++ b/init.cpp
@@ -39,9 +39,9 @@ BlitPtr gThrust1, gThrust2, gShrapnel1, gShrapnel2;
/* -- The prize CICN's */
-SDL_Surface *gAutoFireIcon, *gAirBrakesIcon, *gMult2Icon, *gMult3Icon;
-SDL_Surface *gMult4Icon, *gMult5Icon, *gLuckOfTheIrishIcon, *gLongFireIcon;
-SDL_Surface *gTripleFireIcon, *gKeyIcon, *gShieldIcon;
+SDL_Texture *gAutoFireIcon, *gAirBrakesIcon, *gMult2Icon, *gMult3Icon;
+SDL_Texture *gMult4Icon, *gMult5Icon, *gLuckOfTheIrishIcon, *gLongFireIcon;
+SDL_Texture *gTripleFireIcon, *gKeyIcon, *gShieldIcon;
// Local functions used in this file.
static void DrawLoadBar(int first);
@@ -58,7 +58,7 @@ static int LoadSmallSprite(Mac_Resource *spriteres,
/* Put up an Ambrosia Software splash screen */
void DoSplash(void)
{
- SDL_Surface *splash;
+ SDL_Texture *splash;
splash = Load_Title(screen, 999);
if ( splash == NULL ) {
@@ -77,7 +77,7 @@ void DoSplash(void)
void DoIntroScreen(void)
{
MFont *geneva;
- SDL_Surface *intro, *text;
+ SDL_Texture *intro, *text;
Uint16 Yoff, Xoff;
Uint32 clr, ltClr, ltrClr;
diff --git a/load.cpp b/load.cpp
index de111c25..1dd2a919 100644
--- a/load.cpp
+++ b/load.cpp
@@ -8,10 +8,11 @@
#include "myerror.h"
-SDL_Surface *Load_Title(FrameBuf *screen, int title_id)
+SDL_Texture *Load_Title(FrameBuf *screen, int title_id)
{
char file[256];
- SDL_Surface *bmp, *title;
+ SDL_Surface *bmp;
+ SDL_Texture *title;
/* Open the title file -- we know its colormap is our global one */
sprintf(file, "Images/Maelstrom_Titles#%d.bmp", title_id);
@@ -26,10 +27,10 @@ SDL_Surface *Load_Title(FrameBuf *screen, int title_id)
return(title);
}
-SDL_Surface *GetCIcon(FrameBuf *screen, short cicn_id)
+SDL_Texture *GetCIcon(FrameBuf *screen, short cicn_id)
{
char file[256];
- SDL_Surface *cicn;
+ SDL_Texture *cicn;
SDL_RWops *cicn_src;
Uint8 *pixels, *mask;
Uint16 w, h;
diff --git a/load.h b/load.h
index 5e927e54..c88ec255 100644
--- a/load.h
+++ b/load.h
@@ -8,7 +8,7 @@
#include "SDL_FrameBuf.h"
/* Functions exported from load.cpp */
-extern SDL_Surface *Load_Title(FrameBuf *screen, int title_id);
-extern SDL_Surface *GetCIcon(FrameBuf *screen, short cicn_id);
+extern SDL_Texture *Load_Title(FrameBuf *screen, int title_id);
+extern SDL_Texture *GetCIcon(FrameBuf *screen, short cicn_id);
#endif /* _load_h */
diff --git a/logic.h b/logic.h
index 07c4158e..8b73e2cc 100644
--- a/logic.h
+++ b/logic.h
@@ -11,7 +11,7 @@ extern int InitLogic(void);
extern int InitPlayerSprites(void);
extern void HaltLogic(void);
extern void SetControl(unsigned char which, int toggle);
-extern int SpecialKey(SDL_keysym key);
+extern int SpecialKey(SDL_Keycode key);
extern int GetScore(void);
/* From game.cpp */
@@ -20,9 +20,9 @@ extern void NewGame(void);
/* From about.cpp */
extern void DoAbout(void);
-/* From blit.cpp (fastlogic) player.cpp (netlogic) */
+/* From player.cpp */
extern Uint8 gPlayerShotColors[];
-extern SDL_Surface *gPlayerShot;
+extern SDL_Texture *gPlayerShot;
extern Uint8 gEnemyShotColors[];
-extern SDL_Surface *gEnemyShot;
+extern SDL_Texture *gEnemyShot;
diff --git a/maclib/Mac_FontServ.cpp b/maclib/Mac_FontServ.cpp
index 18d39a9e..31d48dbc 100644
--- a/maclib/Mac_FontServ.cpp
+++ b/maclib/Mac_FontServ.cpp
@@ -72,8 +72,9 @@ struct FOND {
};
-FontServ:: FontServ(const char *fontfile)
+FontServ:: FontServ(FrameBuf *_screen, const char *fontfile)
{
+ screen = _screen;
fontres = new Mac_Resource(fontfile);
text_allocated = 0;
if ( fontres->Error() ) {
@@ -257,16 +258,15 @@ FontServ:: TextHeight(MFont *font)
/* Get/Set bit i of a scan line */
#define GETBIT(scanline, i) \
((scanline[(i)/16] >> (15 - (i)%16)) & 1)
-#define SETBIT(scanline, i, bit) \
- (scanline[(i)/8] |= bit << (7 - (i)%8))
-SDL_Surface *
+SDL_Texture *
FontServ:: TextImage(const char *text, MFont *font, Uint8 style,
SDL_Color foreground, SDL_Color background)
{
- Uint16 width, height;
- SDL_Surface *image;
- Uint8 *bitmap;
+ int width, height;
+ SDL_Texture *image;
+ Uint32 *bitmap;
+ Uint32 color;
int nchars;
int bit_offset; /* The current bit offset into a scanline */
int space_width; /* The width of the whole character */
@@ -331,13 +331,9 @@ FontServ:: TextImage(const char *text, MFont *font, Uint8 style,
}
height = (font->header)->fRectHeight;
- /* Allocate the text bitmap image */
- image = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 1, 0,0,0,0);
- if ( image == NULL ) {
- SetError("Unable to allocate bitmap: %s", SDL_GetError());
- return(NULL);
- }
- bitmap = (Uint8 *)image->pixels;
+ /* Allocate the text pixels */
+ bitmap = new Uint32[width*height];
+ color = screen->MapRGB(foreground.r, foreground.g, foreground.b);
/* Print the individual characters */
/* Note: this could probably be optimized.. eh, who cares. :) */
@@ -363,13 +359,12 @@ FontServ:: TextImage(const char *text, MFont *font, Uint8 style,
int dst_offset;
Uint16 *src_scanline;
- dst_offset = (y*image->pitch*8+
- bit_offset+space_offset);
+ dst_offset = (y*width+bit_offset+space_offset);
src_scanline = font->bitImage +
y*(font->header)->rowWords;
for ( bit = 0; bit<glyph_width; ++bit ) {
- SETBIT(bitmap, dst_offset+bit+boldness,
- GETBIT(src_scanline, glyph_line_offset+bit));
+ bitmap[dst_offset+bit+boldness] =
+ GETBIT(src_scanline, glyph_line_offset+bit)*color;
}
}
#ifdef WIDE_BOLD
@@ -381,38 +376,22 @@ FontServ:: TextImage(const char *text, MFont *font, Uint8 style,
}
if ( (style&STYLE_ULINE) == STYLE_ULINE ) {
y = (height-(font->header)->descent+1);
- bit_offset = (y*image->pitch*8);
+ bit_offset = (y*width);
for ( bit=0; bit<width; ++bit )
- SETBIT(bitmap, bit_offset+bit, 0x01);
+ bitmap[bit_offset++] = color;
}
/* Map the image and return */
- SDL_SetColorKey(image, SDL_SRCCOLORKEY, 0);
- image->format->palette->colors[0] = background;
- image->format->palette->colors[1] = foreground;
- ++text_allocated;
+ image = screen->LoadImage(width, height, bitmap);
+ if (image) {
+ ++text_allocated;
+ }
+ delete[] bitmap;
return(image);
}
void
-FontServ:: FreeText(SDL_Surface *text)
+FontServ:: FreeText(SDL_Texture *text)
{
--text_allocated;
- SDL_FreeSurface(text);
-}
-int
-FontServ:: InvertText(SDL_Surface *text)
-{
- SDL_Color colors[2];
-
- /* Only works on bitmap images */
- if ( text->format->BitsPerPixel != 1 ) {
- SetError("Not a text bitmap");
- return(-1);
- }
-
- /* Swap background and foreground colors */
- colors[0] = text->format->palette->colors[1];
- colors[1] = text->format->palette->colors[0];
- SDL_SetColors(text, colors, 0, 2);
- return(0);
+ screen->FreeImage(text);
}
diff --git a/maclib/Mac_FontServ.h b/maclib/Mac_FontServ.h
index 85880e98..f66ea8b9 100644
--- a/maclib/Mac_FontServ.h
+++ b/maclib/Mac_FontServ.h
@@ -91,7 +91,7 @@ class FontServ {
/* The "fontfile" parameter should be a Macintosh Resource fork file
that contains FOND and NFNT information for the desired fonts.
*/
- FontServ(const char *fontfile);
+ FontServ(FrameBuf *screen, const char *fontfile);
~FontServ();
/* The font returned by NewFont() should be delete'd */
@@ -104,9 +104,9 @@ class FontServ {
/* Returns a bitmap image filled with the requested text.
The text should be freed with FreeText() after it is used.
*/
- SDL_Surface *TextImage(const char *text, MFont *font, Uint8 style,
+ SDL_Texture *TextImage(const char *text, MFont *font, Uint8 style,
SDL_Color background, SDL_Color foreground);
- SDL_Surface *TextImage(const char *text, MFont *font, Uint8 style,
+ SDL_Texture *TextImage(const char *text, MFont *font, Uint8 style,
Uint8 R, Uint8 G, Uint8 B) {
SDL_Color background = { 0xFF, 0xFF, 0xFF, 0 };
SDL_Color foreground;
@@ -116,10 +116,7 @@ class FontServ {
foreground.b = B;
return(TextImage(text, font, style, foreground, background));
}
- void FreeText(SDL_Surface *text);
-
- /* Inverts the color of the text image */
- int InvertText(SDL_Surface *text);
+ void FreeText(SDL_Texture *text);
/* Returns NULL if everything is okay, or an error message if not */
char *Error(void) {
@@ -127,6 +124,7 @@ class FontServ {
}
private:
+ FrameBuf *screen;
Mac_Resource *fontres;
int text_allocated;
diff --git a/maclib/Mac_Sound.cpp b/maclib/Mac_Sound.cpp
index 89d1e039..4f76405a 100644
--- a/maclib/Mac_Sound.cpp
+++ b/maclib/Mac_Sound.cpp
@@ -148,7 +148,7 @@ Sound:: Sound(const char *soundfile, Uint8 vol)
HaltSound();
if ( vol == 0 ) {
bogus_running = 1;
- bogus_audio = SDL_CreateThread(BogusAudioThread, spec);
+ bogus_audio = SDL_CreateThread(BogusAudioThread, "Fake Audio", spec);
} else {
Volume(vol);
}
@@ -198,7 +198,7 @@ Sound:: Volume(Uint8 vol)
/* Run bogus sound thread */
bogus_running = 1;
- bogus_audio = SDL_CreateThread(BogusAudioThread, spec);
+ bogus_audio = SDL_CreateThread(BogusAudioThread, "Fake Audio", spec);
if ( bogus_audio == NULL ) {
/* Oh well... :-) */
}
diff --git a/main.cpp b/main.cpp
index 0089d546..e2b02dce 100644
--- a/main.cpp
+++ b/main.cpp
@@ -171,7 +171,7 @@ int main(int argc, char *argv[])
/* Command line flags */
int doprinthigh = 0;
int speedtest = 0;
- Uint32 video_flags = SDL_SWSURFACE;
+ Uint32 video_flags = 0;
/* Normal variables */
SDL_Event event;
@@ -207,14 +207,14 @@ int main(int argc, char *argv[])
/* Parse command line arguments */
#ifdef __MACOSX__
- video_flags |= SDL_FULLSCREEN;
+ //video_flags |= SDL_WINDOW_FULLSCREEN;
#endif
for ( progname=argv[0]; --argc; ++argv ) {
if ( strcmp(argv[1], "-fullscreen") == 0 ) {
- video_flags |= SDL_FULLSCREEN;
+ video_flags |= SDL_WINDOW_FULLSCREEN;
} else
if ( strcmp(argv[1], "-windowed") == 0 ) {
- video_flags &= ~SDL_FULLSCREEN;
+ video_flags &= ~SDL_WINDOW_FULLSCREEN;
} else
if ( strcmp(argv[1], "-gamma") == 0 ) {
int gammacorrect;
diff --git a/netlogic/about.cpp b/netlogic/about.cpp
index 07a0f0c3..0898459d 100644
--- a/netlogic/about.cpp
+++ b/netlogic/about.cpp
@@ -31,7 +31,6 @@ void DoAbout(void)
/* Rotate any sprites */
for ( i=0; i<numsprites; ++i ) {
- objects[i]->UnBlitSprite();
objects[i]->Move(0);
objects[i]->BlitSprite();
}
@@ -72,7 +71,7 @@ void DoAbout(void)
/* -- Handle updates */
if ( drawscreen && !done ) {
- SDL_Surface *title;
+ SDL_Texture *title;
int width, height;
int xOff, yOff;
@@ -171,7 +170,7 @@ void DoAbout(void)
}
if ( idOn == 135 ) {
MFont *font;
- SDL_Surface *text1, *text2;
+ SDL_Texture *text1, *text2;
/* Put in the right credits / mask th
(Patch may be truncated, please check the link at the top of this post.)