nuttx-apps/games/NXDoom/src/d_loop.h
Matteo Golin 073188b50d games/NXDoom: Initial port of Chocolate DOOM to NuttX.
This commit includes a (highly) modified version of Chocolate DOOM which
can run on NuttX. The majority of the modifications were made to pass
the NuttX style check. Some small modifications have been added to
support keyboard input, render graphics to frame buffers and directly
use the POSIX interfaces NuttX supplies, stripping out Windows/Mac stuff
and any references to SDL.

NOTE: Sound is currently not supported in any capacity, nor is the
networking stuff. A lot of Chocolate DOOM code was stripped out since it
was unused. If there is a need/desire to add it back later, the original
Chocolate DOOM source can be used as a reference.

WARNING: The NuttX keyboard codec is incredibly non-standard and so
there are problems translating from X11 keys to NuttX ones to play DOOM.
Right now, the CTRL key for firing doesn't work because the NuttX codec
has no concept of it. The NuttX codec should be modified (and other
input devices supported), but at the time of this port I am not
sufficiently comfortable doing so since I am afraid of breaking other
things in the kernel.

NOTE: This port (and likely the original DOOM) seems to be written with
32-bit computers in mind. As such, most things are given the type of
natural `int`, even when a single byte might do. There are significant
size optimizations that could be made to make this more suited to
embedded devices that NuttX typically runs on.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
2026-06-30 15:22:55 -03:00

118 lines
3.6 KiB
C

/****************************************************************************
* apps/games/NXDoom/src/d_loop.h
*
* SPDX-License-Identifer: GPLv2
*
* Copyright(C) 1993-1996 Id Software, Inc.
* Copyright(C) 2005-2014 Simon Howard
*
* 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.
*
* DESCRIPTION:
* Main loop stuff.
*
****************************************************************************/
#ifndef __D_LOOP__
#define __D_LOOP__
/****************************************************************************
* Included Files
****************************************************************************/
#include "m_fixed.h"
#include "net_defs.h"
/****************************************************************************
* Public Types
****************************************************************************/
/* Callback function invoked while waiting for the netgame to start.
* The callback is invoked when new players are ready. The callback
* should return true, or return false to abort startup.
*/
typedef boolean (*netgame_startup_callback_t)(int ready_players,
int num_players);
typedef struct
{
/* Read events from the event queue, and process them. */
void (*process_events)(void);
/* Given the current input state, fill in the fields of the specified
* ticcmd_t structure with data for a new tic.
*/
void (*build_ticcmd)(ticcmd_t *cmd, int maketic);
/* Advance the game forward one tic, using the specified player input. */
void (*run_tic)(ticcmd_t *cmds, boolean *ingame);
/* Run the menu (runs independently of the game). */
void (*run_menu)(void);
} loop_interface_t;
/****************************************************************************
* Public Data
****************************************************************************/
extern boolean singletics;
extern int gametic;
extern int ticdup;
extern fixed_t offsetms;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* Register callback functions for the main loop code to use. */
void d_register_loop_callbacks(loop_interface_t *i);
/* Create any new ticcmds and broadcast to other players. */
void net_update(void);
/* ? how many ticks to run? */
void try_run_tics(void);
/* Called at start of game loop to initialize timers */
void d_start_game_loop(void);
/* Initialize networking code and connect to server. */
boolean d_init_net_game(net_connect_data_t *connect_data);
/* Start game with specified settings. The structure will be updated
* with the actual settings for the game.
*/
void d_start_net_game(net_gamesettings_t *settings,
netgame_startup_callback_t callback);
/* Check if it is permitted to record a demo with a non-vanilla feature. */
boolean d_non_vanilla_record(boolean conditional, const char *feature);
/* Check if it is permitted to play back a demo with a non-vanilla feature. */
boolean d_non_vanilla_playback(boolean conditional, int lumpnum,
const char *feature);
void d_receive_tic(ticcmd_t *ticcmds, boolean *playeringame);
#endif /* __D_LOOP__ */