2021-02-23 17:35:50 +01:00
|
|
|
/* -*- compile-command: "cd ../wasm && make MEMDEBUG=TRUE install -j3"; -*- */
|
2021-02-11 01:46:15 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-02-02 21:04:31 +01:00
|
|
|
|
|
|
|
#ifndef _MAIN_H_
|
|
|
|
#define _MAIN_H_
|
|
|
|
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <SDL2/SDL_ttf.h>
|
|
|
|
|
|
|
|
#include "game.h"
|
2021-02-08 01:31:32 +01:00
|
|
|
#include "dictmgr.h"
|
2021-02-02 21:04:31 +01:00
|
|
|
|
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);
|
2021-03-07 03:51:01 +01:00
|
|
|
typedef void (*StringProc)(void* closure, const char* str);
|
2023-02-17 17:57:25 +01:00
|
|
|
typedef void (*MsgProc)(void* closure, const char* topic,
|
|
|
|
const uint8_t* data, int len);
|
2021-02-02 23:52:25 +01:00
|
|
|
|
2021-02-23 17:35:50 +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;
|
|
|
|
|
2021-02-23 17:35:50 +01:00
|
|
|
typedef struct Globals {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int _GUARD;
|
|
|
|
#endif
|
2021-02-02 21:04:31 +01:00
|
|
|
SDL_Window* window;
|
|
|
|
SDL_Renderer* renderer;
|
2021-02-23 17:35:50 +01:00
|
|
|
GameState* games;
|
|
|
|
GameState* curGame; /* if non-null, ptr to the one of games that's visible */
|
2021-02-02 21:04:31 +01:00
|
|
|
VTableMgr* vtMgr;
|
|
|
|
XW_DUtilCtxt* dutil;
|
|
|
|
DrawCtx* draw;
|
2021-03-25 01:52:17 +01:00
|
|
|
TransportProcs transportProcs;
|
2021-02-02 21:04:31 +01:00
|
|
|
CommonPrefs cp;
|
2021-02-08 01:31:32 +01:00
|
|
|
DictMgrCtxt* dictMgr;
|
2023-02-26 19:48:13 +01:00
|
|
|
char myDevIDStr[32];
|
2021-02-02 21:04:31 +01:00
|
|
|
|
2021-03-23 03:39:39 +01:00
|
|
|
int useWidth, useHeight;
|
|
|
|
|
2021-03-10 05:13:42 +01:00
|
|
|
bool focussed; /* window is in foreground */
|
|
|
|
|
2021-03-03 06:10:59 +01:00
|
|
|
char playerName[32];
|
|
|
|
|
2021-02-10 23:16:22 +01:00
|
|
|
#ifdef MEM_DEBUG
|
2021-03-05 18:46:21 +01:00
|
|
|
MPStatsBuf mpstats;
|
2021-02-02 21:04:31 +01:00
|
|
|
MemPoolCtx* mpool;
|
2021-02-10 23:16:22 +01:00
|
|
|
#endif
|
2021-02-02 21:04:31 +01:00
|
|
|
} Globals;
|
|
|
|
|
2021-02-23 17:35:50 +01:00
|
|
|
#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"
|
2021-02-28 06:16:01 +01:00
|
|
|
|
2023-02-04 07:00:47 +01:00
|
|
|
#define NULL_XWE ((XWEnv)-1)
|
2021-03-22 04:16:09 +01:00
|
|
|
|
2021-02-23 17:35:50 +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 );
|
2021-02-23 17:35:50 +01:00
|
|
|
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);
|
2021-02-23 17:35:50 +01:00
|
|
|
void main_query( GameState* gs, const XP_UCHAR* query,
|
2021-02-02 23:52:25 +01:00
|
|
|
QueryProc proc, void* closure );
|
|
|
|
|
2021-02-23 17:35:50 +01:00
|
|
|
void main_set_idle( GameState* gs, IdleProc proc, void* closure );
|
2021-02-02 22:49:27 +01:00
|
|
|
|
2021-02-23 17:35:50 +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 );
|
2021-02-08 01:31:32 +01:00
|
|
|
void main_onGameMessage( Globals* globals, XP_U32 gameID,
|
2023-02-17 17:57:25 +01:00
|
|
|
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 );
|
2021-02-23 17:35:50 +01:00
|
|
|
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 );
|
2021-02-23 17:35:50 +01:00
|
|
|
void main_pickBlank( GameState* gs, int playerNum, int col, int row,
|
2021-02-18 03:58:46 +01:00
|
|
|
const char** tileFaces, int nTiles );
|
2021-02-23 17:35:50 +01:00
|
|
|
void main_updateScreen( GameState* gs );
|
2023-02-17 17:57:25 +01:00
|
|
|
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 );
|
2023-02-27 04:51:56 +01:00
|
|
|
void main_ackMQTTMsg( Globals* globals, const XP_U8* msg, XP_U16 len, int gameID );
|
2021-02-02 21:04:31 +01:00
|
|
|
#endif
|