-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstracting away the game state, scenes, and lobbies
WIP, not finished yet.
- Loading branch information
1 parent
62dbb68
commit 7dccfba
Showing
12 changed files
with
275 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky 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 Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <sk_player.h> | ||
#include <sk_defines.h> | ||
|
||
#define SK_LOBBY_MAX_PLAYERS 10 | ||
|
||
typedef struct { | ||
u8 id; | ||
u8 players_count; | ||
sk_player players[SK_LOBBY_MAX_PLAYERS]; | ||
} sk_lobby; | ||
|
||
sk_lobby sk_lobby_create(u8 id); | ||
|
||
void sk_lobby_destroy(sk_lobby *l); | ||
|
||
u8 sk_lobby_add(sk_lobby *l, sk_player p); | ||
|
||
u8 sk_lobby_kick(sk_lobby *l, i8 p_idx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky 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 Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <sk_scene.h> | ||
#include <sk_lobby.h> | ||
|
||
#define SK_STATE_MAX_LOBBIES 256 | ||
|
||
typedef struct { | ||
u8 is_online; | ||
sk_scene curr_scene; | ||
union { | ||
struct { | ||
u8 lobbies_count; | ||
sk_lobby lobbies[SK_STATE_MAX_LOBBIES]; | ||
}; | ||
struct { | ||
sk_player player; | ||
}; | ||
}; | ||
} sk_state; | ||
|
||
sk_state sk_state_create(u8 is_online); | ||
|
||
void sk_state_destroy(sk_state *s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky 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 Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include <sk_lobby.h> | ||
|
||
sk_lobby sk_lobby_create(u8 id) { | ||
sk_lobby l = { | ||
.id = id, | ||
.players_count = 0 | ||
}; | ||
for (u8 i = 0; i < SK_LOBBY_MAX_PLAYERS; ++i) { | ||
l.players[i] = (sk_player) { | ||
.lobby_id = -1, | ||
.lobby_slot_idx = -1 | ||
}; | ||
} | ||
return l; | ||
} | ||
|
||
void sk_lobby_destroy(sk_lobby *l) { | ||
(void) l; | ||
} | ||
|
||
u8 sk_lobby_add(sk_lobby *l, sk_player p) { | ||
if (l->players_count == SK_LOBBY_MAX_PLAYERS) { | ||
TraceLog(LOG_DEBUG, "Lobby %u :: unable to add more players (full)", l->id); | ||
return false; | ||
} | ||
for (u8 i = 0; i < SK_LOBBY_MAX_PLAYERS; ++i) { | ||
if (l->players[i].lobby_id != -1 && | ||
l->players[i].lobby_slot_idx != -1 ) continue; | ||
p.lobby_id = l->id; | ||
p.lobby_slot_idx = i; | ||
l->players[i] = p; | ||
TraceLog(LOG_INFO, "Lobby %u :: added new player to slot %u/%u", | ||
l->id, | ||
i + 1, | ||
SK_LOBBY_MAX_PLAYERS); | ||
} | ||
++l->players_count; | ||
return true; | ||
} | ||
|
||
u8 sk_lobby_kick(sk_lobby *l, i8 p_idx) { | ||
if (p_idx >= l->players_count || | ||
l->players[p_idx].lobby_id != l->id || | ||
l->players[p_idx].lobby_slot_idx != p_idx) { | ||
TraceLog(LOG_DEBUG, "Lobby %u :: unable to kick non-existant player", l->id); | ||
return false; | ||
} | ||
l->players[p_idx].lobby_id = -1; | ||
l->players[p_idx].lobby_slot_idx = -1; | ||
l->players[p_idx] = (sk_player) { | ||
.lobby_id = -1, | ||
.lobby_slot_idx = -1 | ||
}; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* GNU Sparky --- A 5v5 character-based libre tactical shooter | ||
* Copyright (C) 2024 Wasym A. Alonso | ||
* | ||
* This file is part of Sparky. | ||
* | ||
* Sparky 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Sparky 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 Sparky. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include <sk_scene.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.