Cleanup some unused stuff and redesign text message sending (not

quite done yet, has bugs, but in theory functional)
This commit is contained in:
simon.kagstrom 2010-02-21 07:58:53 +00:00
parent 5d6c55d4c7
commit 63b7d45688
5 changed files with 49 additions and 188 deletions

View File

@ -211,9 +211,10 @@ void C64::network_vblank()
} }
} }
char *msg = TheDisplay->GetTextMessage(); const char *msg = TheDisplay->GetTextMessage();
if (msg) if (msg)
remote->EncodeTextMessage(msg); remote->EncodeTextMessage(msg);
free((void *)msg);
remote->EncodeJoystickUpdate(*js); remote->EncodeJoystickUpdate(*js);

View File

@ -29,8 +29,10 @@
#include "Prefs.h" #include "Prefs.h"
#include "C64.h" #include "C64.h"
#include "CIA.h" #include "CIA.h"
#include "utils.hh"
#include "gui/gui.hh" #include "gui/gui.hh"
#include "gui/status_bar.hh"
#include "gui/virtual_keyboard.hh" #include "gui/virtual_keyboard.hh"
// LED states // LED states
@ -202,9 +204,6 @@ C64Display::C64Display(C64 *the_c64) : TheC64(the_c64)
quit_requested = false; quit_requested = false;
speedometer_string[0] = 0; speedometer_string[0] = 0;
networktraffic_string[0] = 0; networktraffic_string[0] = 0;
memset(this->text_message, 0, sizeof(this->text_message));
this->text_message_idx = 0;
this->entering_text_message = false;
this->text_message_send = NULL; this->text_message_send = NULL;
// Open window // Open window
@ -617,45 +616,48 @@ void C64Display::TranslateKey(SDLKey key, bool key_up, uint8 *key_matrix,
shift_on = true; shift_on = true;
else if (c64_key == MATRIX(1,7) || c64_key == MATRIX(6,4)) else if (c64_key == MATRIX(1,7) || c64_key == MATRIX(6,4))
shift_on = false; shift_on = false;
else if (!key_up && this->entering_text_message)
{
char c = Gui::gui->kbd->keycodeToChar(c64_key | (shift_on ? 0x80 : 0) );
if ((size_t)this->text_message_idx >= sizeof(this->text_message) - 2 ||
c == '\n')
{
this->text_message[this->text_message_idx] = '\0';
this->text_message_send = this->text_message;
this->text_message_idx = 0;
this->entering_text_message = false;
return;
}
if (c == '\b')
{
this->text_message_idx--;
if (this->text_message_idx < 0)
this->text_message_idx = 0;
this->text_message[this->text_message_idx] = '\0';
return;
}
this->text_message[this->text_message_idx] = c;
this->text_message[this->text_message_idx + 1] = '\0';
this->text_message_idx++;
return;
}
this->UpdateKeyMatrix(c64_key, key_up, key_matrix, rev_matrix, joystick); this->UpdateKeyMatrix(c64_key, key_up, key_matrix, rev_matrix, joystick);
} }
char *C64Display::GetTextMessage() const char *C64Display::GetTextMessage()
{ {
char *out = this->text_message_send; const char *out = this->text_message_send;
this->text_message_send = NULL; this->text_message_send = NULL;
return out; return out;
} }
class TypeNetworkMessageListener : public KeyboardListener
{
public:
TypeNetworkMessageListener(const char **out)
{
this->out = out;
}
virtual void stringCallback(const char *str)
{
*out = (const char *)xstrdup(str);
/* Remove thyself! */
delete this;
}
private:
const char **out;
};
void C64Display::TypeNetworkMessage()
{
TypeNetworkMessageListener *nl = new TypeNetworkMessageListener(&this->text_message_send);
Gui::gui->status_bar->queueMessage("Type message to send to peer");
VirtualKeyboard::kbd->registerListener(nl);
VirtualKeyboard::kbd->activate();
}
void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick) void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick)
{ {
SDL_Event event; SDL_Event event;
@ -674,9 +676,9 @@ void C64Display::PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joyst
case SDLK_F10: // F10/ScrLk: Enter text (for network taunts) case SDLK_F10: // F10/ScrLk: Enter text (for network taunts)
case SDLK_SCROLLOCK: case SDLK_SCROLLOCK:
this->entering_text_message = !this->entering_text_message; if (TheC64->network_connection_type == CLIENT ||
if (this->entering_text_message) TheC64->network_connection_type == MASTER)
this->text_message[0] = '\0'; this->TypeNetworkMessage();
break; break;
case SDLK_F11: // F11: NMI (Restore) case SDLK_F11: // F11: NMI (Restore)

View File

@ -86,12 +86,9 @@ public:
void NetworkTrafficMeter(float kb_per_s, bool has_throttled); void NetworkTrafficMeter(float kb_per_s, bool has_throttled);
uint8 *BitmapBase(void); uint8 *BitmapBase(void);
int BitmapXMod(void); int BitmapXMod(void);
#ifdef __riscos__
void PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick, uint8 *joystick2);
#else
void PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick); void PollKeyboard(uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick);
#endif
#if defined(HAVE_SDL)
void FakeKeyPress(int kc, uint8 *CIA_key_matrix, uint8 *CIA_rev_matrix); void FakeKeyPress(int kc, uint8 *CIA_key_matrix, uint8 *CIA_rev_matrix);
void TranslateKey(SDLKey key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick); void TranslateKey(SDLKey key, bool key_up, uint8 *key_matrix, uint8 *rev_matrix, uint8 *joystick);
void UpdateKeyMatrix(int c64_key, bool key_up, uint8 *key_matrix, void UpdateKeyMatrix(int c64_key, bool key_up, uint8 *key_matrix,
@ -102,165 +99,25 @@ public:
void Update_32(uint8 *src_pixels); void Update_32(uint8 *src_pixels);
void Update_stretched(uint8 *src_pixels); void Update_stretched(uint8 *src_pixels);
SDL_Surface *SurfaceFromC64Display(); SDL_Surface *SurfaceFromC64Display();
char *GetTextMessage(); const char *GetTextMessage();
#endif
bool NumLock(void); bool NumLock(void);
void InitColors(uint8 *colors); void InitColors(uint8 *colors);
void NewPrefs(Prefs *prefs); void NewPrefs(Prefs *prefs);
void TypeNetworkMessage();
C64 *TheC64; C64 *TheC64;
#ifdef __BEOS__
void Pause(void);
void Resume(void);
#endif
#ifdef __riscos__
void ModeChange(void);
unsigned int *GetColourTable(void); // returns pointer to mode_cols
bool CheckForUnpause(bool CheckLastState);
ROScreen *screen;
Joy_Keys JoystickKeys[2]; // it's easier making the joystick keys public
#endif
#if defined(__unix) || defined(GEKKO)
bool quit_requested; bool quit_requested;
#endif
private: private:
int led_state[4]; int led_state[4];
int old_led_state[4]; int old_led_state[4];
#ifdef __BEOS__
C64Window *the_window; // One of these is NULL
C64Screen *the_screen;
bool using_screen; // Flag: Using the_screen
key_info old_key_info;
int draw_bitmap; // Number of bitmap for the VIC to draw into
#endif
#ifdef AMIGA
void draw_led_bar(void); // Draw LED bar at the bottom of the window
void draw_led(int num, int state); // Draw one LED
struct Window *the_window; // Pointer to C64 display window
struct Screen *the_screen; // The window's screen
struct RastPort *the_rp; // The window's RastPort
struct VisualInfo *the_visual_info;
struct Menu *the_menus;
struct TextFont *led_font;
struct TextFont *speedo_font;
struct RastPort temp_rp; // For WritePixelArray8()
struct BitMap *temp_bm;
uint8 *chunky_buf; // Chunky buffer for drawing into
LONG pens[16]; // Pens for C64 colors
int xo, yo; // Window X/Y border size
struct FileRequester *open_req, *save_req; // File requesters for load/save snapshot
#endif
#ifdef HAVE_SDL
char speedometer_string[16]; // Speedometer text char speedometer_string[16]; // Speedometer text
char networktraffic_string[80]; // Speedometer text char networktraffic_string[80]; // Speedometer text
char text_message[80]; const char *text_message_send;
char *text_message_send;
int text_message_idx;
bool entering_text_message;
#endif
#ifdef __unix
void draw_led(int num, int state); // Draw one LED
static void pulse_handler(...); // LED error blinking
#endif
#ifdef WIN32
public:
long ShowRequester(const char *str, const char *button1, const char *button2 = NULL);
void WaitUntilActive();
void NewPrefs();
void Pause();
void Resume();
void Quit();
struct DisplayMode {
int x;
int y;
int depth;
BOOL modex;
};
int GetNumDisplayModes() const;
const DisplayMode *GetDisplayModes() const;
private:
// Window members.
void ResetKeyboardState();
BOOL MakeWindow();
static LRESULT CALLBACK StaticWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
long WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static int VirtKey2C64(int virtkey, DWORD keydata);
BOOL CalcViewPort();
BOOL SetupWindow();
BOOL SetupWindowMode(BOOL full_screen);
BOOL RestoreWindow();
BOOL ResizeWindow(int side, RECT *pRect);
void WindowTitle();
void CreateObjects();
void DeleteObjects();
// DirectDraw management members.
BOOL StartDirectDraw();
BOOL ResumeDirectDraw();
BOOL ResetDirectDraw();
BOOL StopDirectDraw();
static HRESULT CALLBACK EnumModesCallback(LPDDSURFACEDESC pDDSD, LPVOID lpContext);
HRESULT EnumModesCallback(LPDDSURFACEDESC pDDSD);
static int CompareModes(const void *e1, const void *e2);
BOOL Fail(const char *message);
// DirectDraw worker members.
BOOL SetPalettes();
BOOL BuildColorTable();
BOOL CopySurface(RECT &rcWork);
BOOL FlipSurfaces();
BOOL EraseSurfaces();
BOOL RestoreSurfaces();
void draw_led_bar(void); // Draw LED bar on the window
void draw_leds(BOOL force = false); // Draw LEDs if force or changed
void led_rect(int n, RECT &rc, RECT &led); // Compute LED rectangle
void InsertNextDisk(); // should be a common func
BOOL FileNameDialog(char *prefs_path, BOOL save = false);
void OfferSave(); // Offer chance to save changes
UBYTE *chunky_buf; // Chunky buffer for drawing
BOOL active; // is application active?
BOOL paused; // is application paused?
BOOL waiting; // is application waiting?
DWORD windowed_style; // style of windowed window
DWORD fullscreen_style; // style of fullscreen window
char failure_message[128]; // what when wrong
int speed_index; // look ma, no hands
BOOL show_leds; // cached prefs option
BOOL full_screen; // cached prefs option
BOOL in_constructor; // if we are being contructed
BOOL in_destructor; // if we are being destroyed
LPDIRECTDRAW pDD; // DirectDraw object
LPDIRECTDRAWSURFACE pPrimary; // DirectDraw primary surface
LPDIRECTDRAWSURFACE pBack; // DirectDraw back surface
LPDIRECTDRAWSURFACE pWork; // DirectDraw working surface
LPDIRECTDRAWCLIPPER pClipper; // DirectDraw clipper
LPDIRECTDRAWPALETTE pPalette; // DirectDraw palette
DWORD colors[256]; // our palette colors
int colors_depth; // depth of the colors table
#endif
#ifdef __riscos__
unsigned int mode_cols[256]; // Colours in the current mode corresponding to C64's
uint8 *bitmap;
uint32 lastkeys[8]; // bitfield describing keys pressed last time.
#endif
}; };

View File

@ -368,7 +368,7 @@ bool Network::DecodeDisplayUpdate(struct NetworkUpdate *src)
return false; return false;
} }
void Network::EncodeTextMessage(char *str) void Network::EncodeTextMessage(const char *str)
{ {
NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud; NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud;
char *p = (char*)dst->data; char *p = (char*)dst->data;
@ -914,6 +914,7 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
} }
break; break;
case TEXT_MESSAGE: case TEXT_MESSAGE:
printf("Got message: %d, %s\n", p->size, (char*)p->data);
Gui::gui->status_bar->queueMessage((const char*)p->data); Gui::gui->status_bar->queueMessage((const char*)p->data);
break; break;
case REGISTER_DATA: case REGISTER_DATA:

View File

@ -173,7 +173,7 @@ public:
void EncodeJoystickUpdate(Uint8 v); void EncodeJoystickUpdate(Uint8 v);
void EncodeTextMessage(char *str); void EncodeTextMessage(const char *str);
void EnqueueSound(uint32 linecnt, uint8 addr, uint8 val); void EnqueueSound(uint32 linecnt, uint8 addr, uint8 val);