xwords/xwords4/wasm/main.h

126 lines
4.1 KiB
C
Raw Normal View History

/* -*- compile-command: "cd ../wasm && make MEMDEBUG=TRUE install -j3"; -*- */
/*
* Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _MAIN_H_
#define _MAIN_H_
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "game.h"
#include "dictmgr.h"
2021-02-02 22:49:27 +01:00
typedef struct _TimerState {
void* closure;
XWTimerReason why;
XWTimerProc proc;
time_t when;
} TimerState;
2021-02-03 04:20:26 +01:00
typedef XP_Bool (*IdleProc)(void* closure);
2021-03-05 21:04:07 +01:00
typedef void (*BoolProc)(void* closure, bool result);
typedef void (*StringProc)(void* closure, const char* str);
typedef void (*MsgProc)(void* closure, const char* topic,
const uint8_t* data, int len);
2021-02-02 23:52:25 +01:00
typedef struct GameState {
#ifdef DEBUG
int _GUARD;
#endif
struct GameState* next;
struct Globals* globals;
2021-02-19 04:41:18 +01:00
CurGameInfo gi;
XWGame game;
XW_UtilCtxt* util;
XP_U16 saveToken;
2021-02-19 20:19:16 +01:00
char gameName[32];
2021-02-19 04:41:18 +01:00
} GameState;
typedef struct Globals {
#ifdef DEBUG
int _GUARD;
#endif
SDL_Window* window;
SDL_Renderer* renderer;
GameState* games;
GameState* curGame; /* if non-null, ptr to the one of games that's visible */
VTableMgr* vtMgr;
XW_DUtilCtxt* dutil;
DrawCtx* draw;
2021-03-25 01:52:17 +01:00
TransportProcs transportProcs;
CommonPrefs cp;
DictMgrCtxt* dictMgr;
2023-02-26 19:48:13 +01:00
char myDevIDStr[32];
int useWidth, useHeight;
2021-03-10 05:13:42 +01:00
bool focussed; /* window is in foreground */
char playerName[32];
2021-02-10 23:16:22 +01:00
#ifdef MEM_DEBUG
2021-03-05 18:46:21 +01:00
MPStatsBuf mpstats;
MemPoolCtx* mpool;
2021-02-10 23:16:22 +01:00
#endif
} Globals;
#define GUARD_GLOB 0x76AB98CD
#define GUARD_GS 0x12347890
#define CAST_GLOB(typ, var, ptr) XP_ASSERT(((typ)(ptr))->_GUARD == GUARD_GLOB); typ var = (typ)(ptr)
#define CAST_GS(typ, var, ptr) XP_ASSERT(((typ)(ptr))->_GUARD == GUARD_GS); typ var = (typ)(ptr)
2021-03-05 18:03:32 +01:00
#define KEY_DICTS "dicts"
#define NULL_XWE ((XWEnv)-1)
2021-03-22 04:16:09 +01:00
void main_set_timer( GameState* gs, XWTimerReason why, XP_U16 when,
2021-02-02 22:49:27 +01:00
XWTimerProc proc, void* closure );
void main_clear_timer( GameState* gs, XWTimerReason why );
2021-02-02 22:49:27 +01:00
2021-02-02 23:52:25 +01:00
typedef void (*QueryProc)(void* closure, XP_Bool confirmed);
void main_query( GameState* gs, const XP_UCHAR* query,
2021-02-02 23:52:25 +01:00
QueryProc proc, void* closure );
void main_set_idle( GameState* gs, IdleProc proc, void* closure );
2021-02-02 22:49:27 +01:00
void main_alert( GameState* gs, const XP_UCHAR* msg );
2021-02-07 21:48:06 +01:00
void main_gameFromInvite( Globals* globals, const NetLaunchInfo* invite );
void main_onGameMessage( Globals* globals, XP_U32 gameID,
const CommsAddrRec* from, const XP_U8* buf,
XP_U16 len );
2023-02-22 19:27:39 +01:00
void main_onCtrlReceived( Globals* globals, const XP_U8* buf, XP_U16 len );
2021-02-20 16:27:43 +01:00
void main_onGameGone( Globals* globals, XP_U32 gameID );
2023-02-23 05:54:21 +01:00
XP_Bool main_haveGame( Globals* globals, XP_U32 gameID, XP_U8 channel );
2021-02-07 21:48:06 +01:00
void main_sendOnClose( XWStreamCtxt* stream, XWEnv env, void* closure );
void main_playerScoreHeld( GameState* gs, XP_U16 player );
void main_showGameOver( GameState* gs );
void main_showRemaining( GameState* gs );
void main_turnChanged(GameState* gs, int newTurn);
2021-03-24 23:58:25 +01:00
void main_chatReceived( GameState* gs, const char* msg );
void main_pickBlank( GameState* gs, int playerNum, int col, int row,
2021-02-18 03:58:46 +01:00
const char** tileFaces, int nTiles );
void main_updateScreen( GameState* gs );
void main_needDictForGame(GameState* gs, const char* lc, const XP_UCHAR* dictName);
2023-02-23 05:54:21 +01:00
bool main_getLocalName( Globals* globals, char* playerName, size_t buflen );
void main_ackMQTTMsg( Globals* globals, const XP_U8* msg, XP_U16 len, int gameID );
#endif