Commit Graph

129 Commits

Author SHA1 Message Date
Xavier Del Campo Romero cd96d3a9de keyboard_key.h: add more keys 2022-09-20 12:29:45 +02:00
Xavier Del Campo Romero 985a1d4fd7 sdl-1.2: Remap SDLK_ESCAPE to KEYBOARD_KEY_ESC 2022-09-16 20:35:04 +02:00
Xavier Del Campo Romero 92359fc964 mouse.c: Reduce threshold 2022-09-16 20:33:39 +02:00
Xavier Del Campo Romero 95ae0911ff Split CMakeLists.txt for src 2022-09-16 20:29:47 +02:00
Xavier Del Campo Romero e8dd951c6c Use find_package for SDL libraries
CMake already distributes FindSDL*.cmake files for SDL and SDL_mixer,
which support custom prefixes via environment variables, removing the
need for ad-hoc logic in Win9x builds.

Also, according to FindSDL.cmake, #include <SDL.h> is the preferred way
for portability reasons, instead of #include <SDL/SDL.h>, which is the
option that has been used so far.
2022-07-23 04:23:05 +02:00
Xavier Del Campo Romero a091af05c6 ps1: Use exported target PSXSDK::PSXSDK 2022-07-23 04:23:05 +02:00
Xavier Del Campo Romero 17380ab7d5 system/CMakeLists.txt: group common private dependencies into var 2022-07-23 04:23:05 +02:00
Xavier Del Campo Romero 24693bc9ed SDL-1.2: Implement X mirroring for quads 2022-07-15 01:35:46 +02:00
Xavier Del Campo Romero ca510a11c4 Import SDL_gfx 2022-07-15 01:03:36 +02:00
Xavier Del Campo Romero 938b35033b gui: Update elements in reverse order
This allows to calculate dimensions for containers with children
containers in it.
2022-07-15 01:03:36 +02:00
Xavier Del Campo Romero e66894e3f8 Deprecate memset(3) in favour of C99 compound literals 2022-07-15 01:03:31 +02:00
Xavier Del Campo Romero f69dc6f359 Allow children of gui_container be resized anytime
So far, their position inside the container was determined when
initializing the interface. However, if a child were resized
afterwards, the container would not adjust its elements accordingly.
Moreover, the implementation for gui_container relied on hacking the
children's X/Y coordinates, which could only be done once.

Now, two additional members have been added to gui_common so that
specific X/Y offset can be determined by the parent, additionally to the
traditional rules followed by gui_coords. Despite the extra memory
footprint, it now allows containers to set specific X/Y offsets for
their children on every game cycle.
2022-07-10 00:26:48 +02:00
Xavier Del Campo Romero f318a66f8c Implement join/host and game cfg menus 2022-07-07 02:45:23 +02:00
Xavier Del Campo Romero e50aad2a6d Implement system_can_exit 2022-07-07 02:45:23 +02:00
Xavier Del Campo Romero dc4a3a2db8 Allow multiple button types 2022-07-07 02:37:25 +02:00
Xavier Del Campo Romero 3f793166bd button.c: fix wrong function call 2022-07-07 02:37:25 +02:00
Xavier Del Campo Romero 196a7501fe rounded_rect.h: fix typo 2022-07-07 02:37:25 +02:00
Xavier Del Campo Romero 3bc4b6f996 font.c: set null dimensions on null str 2022-07-02 04:50:50 +02:00
Xavier Del Campo Romero c0bdd53c90 human_player_gui.c: use gui_container for top gui_bar 2022-07-02 04:47:50 +02:00
Xavier Del Campo Romero ac913a3ff5 gui/container: support spacing between GUI elements 2022-07-02 04:42:41 +02:00
Xavier Del Campo Romero 1d40cadf43 gui/bar: support arbitrary x/y and width 2022-07-02 04:41:22 +02:00
Xavier Del Campo Romero 85e11e8f98 gui: reuse callback data
There is no need to allocate memory for these callbacks for each single
GUI element. Instead, a single, statically-allocated instance can be
shared among all GUI elements of a given type.
2022-07-02 04:08:35 +02:00
Xavier Del Campo Romero f4357485e6 menu: implement main menu using new GUI improvements 2022-07-02 00:58:50 +02:00
Xavier Del Campo Romero c10ca65109 gui: implement container
Containers, somewhat inspired by GtkBox, allow to packed other GUI
elements into a single row or column.
2022-07-02 00:53:03 +02:00
Xavier Del Campo Romero fa766deaf4 button.c: h/v-center child label by default 2022-07-02 00:50:26 +02:00
Xavier Del Campo Romero e4558e9ba0 gui.c: fix wrong logic on gui_coords
The older logic would iterate for all parents, where each parent would
again iterate for all of its parents, until no more parents found.
This is however not needed, since only inspecting the closest parent
will already cause the (recursive) algorithm to iterate for all parents.
2022-07-02 00:49:36 +02:00
Xavier Del Campo Romero 270c6101f6 gui: allow custom add_child callback 2022-07-02 00:45:51 +02:00
Xavier Del Campo Romero e5bbfc6dc4 menu.c: center play button on screen 2022-06-29 01:01:31 +02:00
Xavier Del Campo Romero 2cd99b1bcf button.c: fail on negative width 2022-06-29 01:01:03 +02:00
Xavier Del Campo Romero 3e50314b44 gui: implement {h,v}centered 2022-06-29 00:39:06 +02:00
Xavier Del Campo Romero 4d4b92c2b6 font: implement font_dim 2022-06-29 00:27:33 +02:00
Xavier Del Campo Romero c538eb1b90 Deprecate memset(3) for zero-init 2022-06-27 21:56:43 +02:00
Xavier Del Campo Romero d28a748521 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 bac711c5b3 human_player: deprecate memset(3) for zero-init 2022-06-26 23:42:48 +02:00
Xavier Del Campo Romero 88713427f7 human_player.c: reset deselected instances 2022-06-26 23:42:48 +02:00
Xavier Del Campo Romero 272fd53810 Fix hp bar not being displayed when carrying 2022-06-26 23:42:34 +02:00
Xavier Del Campo Romero 231bc704ff ps1/heap.c: bump heap size 2022-06-26 21:51:51 +02:00
Xavier Del Campo Romero 19d9a571af Implement main menu 2022-06-26 21:51:47 +02:00
Xavier Del Campo Romero c0887a44fb 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 50b362db39 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 aea50395c5 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 aa047f3b95 font: add font_puts 2022-06-26 20:00:27 +02:00
Xavier Del Campo Romero fe7e006a31 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 b53db6f005 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 cbe7ca6fca 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 0b94264a7e 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 904d9e933e 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 56107cb516 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 08c26de540 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 5226dc4663 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 324ac3b807 sdl-1.2/sound.c: use SDL_WasInit 2022-06-11 23:42:30 +02:00
Xavier Del Campo Romero 48428c2e43 sdl-1.2: return to original dimensions on fullscreen exit 2022-06-11 23:42:30 +02:00
Xavier Del Campo Romero 6f74cbd20b Implement button component 2022-06-11 23:42:27 +02:00
Xavier Del Campo Romero 7a92eb3eb6 pad/CMakeLists.txt: add missing call to target_link_libraries() 2022-06-08 00:36:23 +02:00
Xavier Del Campo Romero d07b682c9b Make gfx_draw return int 2022-05-24 22:20:04 +02:00
Xavier Del Campo Romero f34113de51 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 0bcea86763 font.c: avoid several va_list in favor of large buffer 2022-05-24 22:20:04 +02:00
Xavier Del Campo Romero 951a310989 Allow systems without sound support 2022-05-24 22:20:02 +02:00
Xavier Del Campo Romero 3d77d3a8aa Remove unused minor stuff 2022-03-31 07:30:14 +02:00
Xavier Del Campo Romero adfa26d1f9 resource.c: decouple collbox from sprite dimensions 2022-03-31 07:29:16 +02:00
Xavier Del Campo Romero 71a2714fe6 Fix exit condition 2022-03-31 07:27:22 +02:00
Xavier Del Campo Romero ce8b1c43ca Implement touch controls 2022-03-31 06:50:33 +02:00
Xavier Del Campo Romero 1950fe7b06 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 06056a9b5e Rename MAP_{X|Y} to MAP_{W|H} 2022-03-30 08:23:15 +02:00
Xavier Del Campo Romero cbb2dc1a0a camera: implement mouse support 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero eccba7c2af Move CURSOR_{WIDTH|HEIGHT} to library scope 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero aa355c0c0a sdl-1.2/mouse.c: fix right click events 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 3507ab949e sdl-1.2: implement rect_init and semitrans_rect_init 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero ab09e5f2cc sdl-1.2: implement env.c 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero b925e5e156 gfx: separate port-specific interfaces 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 669045df00 game.c: remove #if 0 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 8f8c5df4f2 Add support for keyboard and mouse 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 4765653cb3 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 c9754ac430 container.c: distinguish ferror/feof from other errors 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 751fa7deba terrain.c: use long for map coordinates 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero a79329dbf6 sdl-1.2: hide system cursor 2022-03-30 08:20:21 +02:00
Xavier Del Campo Romero 98f0d3e026 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 9f9c0226d0 Refresh camera and terrain rendering on screen resize 2022-03-30 08:20:20 +02:00
Xavier Del Campo Romero 6b9f686913 Add project source code 2022-03-30 08:20:20 +02:00