Commit Graph

103 Commits

Author SHA1 Message Date
Xavier Del Campo Romero ec9f41f1ab gui: allow custom add_child callback 2022-07-02 00:45:51 +02:00
Xavier Del Campo Romero c4a24800b8 menu.c: center play button on screen 2022-06-29 01:01:31 +02:00
Xavier Del Campo Romero 391c8958b1 button.c: fail on negative width 2022-06-29 01:01:03 +02:00
Xavier Del Campo Romero cff35e88f5 gui: implement {h,v}centered 2022-06-29 00:39:06 +02:00
Xavier Del Campo Romero 23f24016da font: implement font_dim 2022-06-29 00:27:33 +02:00
Xavier Del Campo Romero 6d5aa57e6d Deprecate memset(3) for zero-init 2022-06-27 21:56:43 +02:00
Xavier Del Campo Romero a746ecd0b6 human_player_gui.c: fix segfault when selecting one unit
Checking against `sel` is just plain wrong, since it always expected to
be non-NULL, since `h->sel` is an array defined in `struct
human_player`. Instead, `sel->d.i` is the pointer that should be
checked.
2022-06-27 21:43:32 +02:00
Xavier Del Campo Romero e869bfd0f6 human_player: deprecate memset(3) for zero-init 2022-06-26 23:42:48 +02:00
Xavier Del Campo Romero 4305732e0a human_player.c: reset deselected instances 2022-06-26 23:42:48 +02:00
Xavier Del Campo Romero 7196c6a0cc Fix hp bar not being displayed when carrying 2022-06-26 23:42:34 +02:00
Xavier Del Campo Romero afc554167e ps1/heap.c: bump heap size 2022-06-26 21:51:51 +02:00
Xavier Del Campo Romero c401b7663d Implement main menu 2022-06-26 21:51:47 +02:00
Xavier Del Campo Romero 70bc98f96c terrain: fix wrong rendering
The older implementation would leave empty areas on the right side of
the screen.
2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero ad1d6b1f66 font: deprecate font_printf
This function is no longer needed since `gui` was revamped.
2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero 7c75118429 Revamp gui component
`gui` was tighly coupled to game logic, and could not be extended for
other purposes. Therefore, a generic GUI implementation, loosely
inspired by well-known GUI frameworks such as GTK, is now provided, with
the following properties:

- Does not depend on dynamic or static memory allocation, only automatic
(i.e., stack) memory allocation required.
- Portable among existing implementations.
- Simple to extend.
- Tiny memory footprint.

`gui` is now composed by GUI elements that can be chained to form a tree
structure. This is useful e.g.: to calculate X/Y coordinates for a given
GUI element given its parent(s).

This commit also refactors the older implementation, moving
game-specific logic into `player` and making use of the new component.
2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero f17c76c400 font: add font_puts 2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero 2c5973ee7e peripheral.c: initialize common members only
Other members will be initialized according to peripheral configuration.
2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero f938bb790e Deprecate memset(3) over C99 compound literals for zero-init
Using memset(3) does not ensure pointers are assigned to NULL for all
platforms.
2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero eee1205446 player: limit data sizes for resources and population
- All platforms should allow for the same resources.
- Population is not expected to exceed UCHAR_MAX on any platform.
2022-06-26 19:58:46 +02:00
Xavier Del Campo Romero 9da37c198e camera: implement fixed cursor movement
On platforms with PERIPHERAL_TYPE_PAD, navigating through menus and
options can be cumbersome if moving the cursor freely around the
screen.

Therefore, this commit instead defines a list of (X, Y) coordinates that
the cursor can jump to. The implementation also attempts to guess which
direction the cursor should jump to for the previous/next point, and
hence determine which button should be pressed by the user.
2022-06-24 17:45:50 +02:00
Xavier Del Campo Romero 8ddea5eef5 camera.c: refactor cursor_init
So that uninitialized members are set to 0.
2022-06-24 17:45:14 +02:00
Xavier Del Campo Romero 992e7fb935 peripheral: provide common actions
Whereas some actions are context-specific (e.g.: selecting a player),
some are context-independent and can be executed for all screens
(e.g.: exiting the game).
2022-06-24 17:28:38 +02:00
Xavier Del Campo Romero 3cb276b19f camera: remove dependency against terrain
This will allow using camera for purposes other than showing the game
map.
2022-06-12 23:19:03 +02:00
Xavier Del Campo Romero 0f9e2d8958 Split peripheral-related logic into its own component
This has several advantages:

- `camera` no longer needs to define public functions for each
peripheral type.
- Peripheral-related is now no longer tighly coupled to human_player,
so peripheral logic can be reused elsewhere e.g.: on menus.
- Makes camera_update_touch consistent compared to equivalent functions,
since now `pan` has now been moved to `camera` (as it should be).
2022-06-12 23:18:57 +02:00
Xavier Del Campo Romero a826c2364d sdl-1.2/sound.c: use SDL_WasInit 2022-06-11 23:42:30 +02:00
Xavier Del Campo Romero 3f6bf6aa1a sdl-1.2: return to original dimensions on fullscreen exit 2022-06-11 23:42:30 +02:00
Xavier Del Campo Romero a84a55aa25 Implement button component 2022-06-11 23:42:27 +02:00
Xavier Del Campo Romero 706d299af4 pad/CMakeLists.txt: add missing call to target_link_libraries() 2022-06-08 00:36:23 +02:00
Xavier Del Campo Romero 938ab93482 Make gfx_draw return int 2022-05-24 22:20:04 +02:00
Xavier Del Campo Romero 132d8c860e Use realloc(3) directly
It is simply not true realloc(3) cannot be used with NULL pointers.
2022-05-24 22:20:04 +02:00
Xavier Del Campo Romero 77d16c32cc font.c: avoid several va_list in favor of large buffer 2022-05-24 22:20:04 +02:00
Xavier Del Campo Romero dea345f412 Allow systems without sound support 2022-05-24 22:20:02 +02:00
Xavier Del Campo Romero 354034b06b Remove unused minor stuff 2022-03-31 07:30:14 +02:00
Xavier Del Campo Romero b8c30e83e3 resource.c: decouple collbox from sprite dimensions 2022-03-31 07:29:16 +02:00
Xavier Del Campo Romero 360f14aa24 Fix exit condition 2022-03-31 07:27:22 +02:00
Xavier Del Campo Romero 45337576df Implement touch controls 2022-03-31 06:50:33 +02:00
Xavier Del Campo Romero 82c61e3d1d Implement sub-tile collboxes
These will be later used by the pathfinding algorithm.
2022-03-30 08:28:47 +02:00
Xavier Del Campo Romero 638dbd0af1 Rename MAP_{X|Y} to MAP_{W|H} 2022-03-30 08:23:15 +02:00
Xavier Del Campo Romero e9d69f9083 camera: implement mouse support 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 244f0b26f8 Move CURSOR_{WIDTH|HEIGHT} to library scope 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero f95aed2624 sdl-1.2/mouse.c: fix right click events 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero c8cce5ea87 sdl-1.2: implement rect_init and semitrans_rect_init 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero c5434beff1 sdl-1.2: implement env.c 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 8347125b19 gfx: separate port-specific interfaces 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 6c5eb81b3c game.c: remove #if 0 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 9eee43d3bb Add support for keyboard and mouse 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 18717569ac Add metadata header to media files
The following properties are supported:

- Sound: "loop". Must be either 0 or 1
- Images: "transparent". Must be either 0 or 1

These headers are only used for non-PS1 builds, since .TIM and .VAG
files do already implement such information.
2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 3ce1418ce5 container.c: distinguish ferror/feof from other errors 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero c6ac388f86 terrain.c: use long for map coordinates 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero a927f627bb sdl-1.2: hide system cursor 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 3d90015c62 Replace x_get functions with macros
The PS1 port relies on a heap for primitives since the GPU renders the
scene asynchronously. However, SDL-based platforms render primitives
synchronously, so structures can be allocated on the stack instead.
2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 68383dad33 Refresh camera and terrain rendering on screen resize 2022-03-30 08:20:20 +02:00
Xavier Del Campo Romero 8c10334252 Add project source code 2022-03-30 08:20:20 +02:00