Split the simulation from presentation into an SDL-free library
Sim holds one whole game (tick, snapshots, checksum) and talks to the screen only through Cues, which the client's Scene plays and the server ignores. All drawing moved to scene.cpp. Match takes this screen's wishes as request flags instead of reading the menu, input and settings. The sim library builds without SDL and the server links it, ready to run games itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2007fb7edc
commit
465f75f6d7
38 files changed
+2225
-1965
No files matched your search
+14
-23
@@ -2,78 +2,69 @@
|
||||
|
||||
#include "audio.h"
|
||||
#include "balance.h"
|
||||
#include "bot.h"
|
||||
#include "chat.h"
|
||||
#include "menu.h"
|
||||
#include "effects.h"
|
||||
#include "fighter.h"
|
||||
#include "input.h"
|
||||
#include "match.h"
|
||||
#include "net.h"
|
||||
#include "renderer.h"
|
||||
#include "rollback.h"
|
||||
#include "scene.h"
|
||||
#include "session.h"
|
||||
#include "settings.h"
|
||||
#include "sim.h"
|
||||
#include "sprites.h"
|
||||
#include "text.h"
|
||||
#include "trinket.h"
|
||||
#include "ui.h"
|
||||
#include "weapon.h"
|
||||
#include "world.h"
|
||||
|
||||
constexpr float PVP_OFF_SHADE = 0.4f;
|
||||
constexpr float AWAY_SHADE = 0.2f;
|
||||
|
||||
// Every manager in one place, so systems can reach each other through a single reference.
|
||||
// Devices say which input plays each fighter on this screen (none for bots). Fighters, the match and rng belong to the
|
||||
// simulation and are saved in snapshots. Local is the fighter this screen
|
||||
// Devices say which input plays each fighter on this screen (none for bots). Sim is the game being
|
||||
// played, saved in snapshots. Local is the fighter this screen
|
||||
// controls and follows. Camera, alpha, settings and the window are presentation. Alpha is how far drawing sits between
|
||||
// the previous tick and the current one. Net is the connection to the server and other players.
|
||||
struct Game
|
||||
{
|
||||
Audio audio;
|
||||
Balance balance;
|
||||
Bot bot;
|
||||
Chat chat;
|
||||
Menu menu;
|
||||
Effects effects;
|
||||
Fighter fighters[MAX_FIGHTERS];
|
||||
Input input;
|
||||
Match match;
|
||||
Net net;
|
||||
Renderer renderer;
|
||||
Rollback rollback;
|
||||
Settings settings;
|
||||
Scene scene{*this};
|
||||
Session session;
|
||||
Sim sim;
|
||||
Sprites sprites;
|
||||
Text text;
|
||||
Ui ui;
|
||||
Weapons weapons;
|
||||
World world;
|
||||
Rng rng;
|
||||
Vec2 camera;
|
||||
Vec2 cameraPrevious;
|
||||
float alpha = 1;
|
||||
int devices[MAX_FIGHTERS] = {DEVICE_KEYBOARD, DEVICE_NONE, DEVICE_NONE, DEVICE_NONE};
|
||||
int fighterCount = 1;
|
||||
int local = 0;
|
||||
SDL_Window* window = nullptr;
|
||||
|
||||
Fighter& local_get()
|
||||
{
|
||||
return fighters[local];
|
||||
return sim.fighters[local];
|
||||
}
|
||||
|
||||
// Whether a fighter is played on this screen, by its keyboard and mouse or one of its gamepads.
|
||||
bool is_local(int fighter)
|
||||
{
|
||||
return fighter < fighterCount && devices[fighter] != DEVICE_NONE && !fighters[fighter].isBot;
|
||||
return fighter < sim.fighterCount && devices[fighter] != DEVICE_NONE && !sim.fighters[fighter].isBot;
|
||||
}
|
||||
|
||||
int local_count()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < fighterCount; i++)
|
||||
for (int i = 0; i < sim.fighterCount; i++)
|
||||
count += is_local(i);
|
||||
return count;
|
||||
}
|
||||
@@ -85,17 +76,17 @@ struct Game
|
||||
// plain (as the HUD's tint is), it's never darkened.
|
||||
Color color_get(int fighter, bool isPlain = false)
|
||||
{
|
||||
if (match.state == MATCH_PRACTICE && fighterCount == 1)
|
||||
if (sim.match.state == MATCH_PRACTICE && sim.fighterCount == 1)
|
||||
{
|
||||
int color = settings.color_get();
|
||||
return color >= 0 ? PALETTE[color] : WHITE;
|
||||
}
|
||||
Color color = PALETTE[match.colors[fighter]];
|
||||
Color color = PALETTE[sim.match.colors[fighter]];
|
||||
// Away playing a queued game, a fighter stands faded in the lobby.
|
||||
if (match.state == MATCH_PRACTICE && match.isAway[fighter] && !isPlain)
|
||||
if (sim.match.state == MATCH_PRACTICE && sim.match.isAway[fighter] && !isPlain)
|
||||
return color_shade(color, AWAY_SHADE);
|
||||
bool isHostile = fighters[fighter].isPvp && fighters[local].isPvp;
|
||||
bool isPeaceful = !isPlain && fighter != local && match.state == MATCH_PRACTICE && !isHostile;
|
||||
bool isHostile = sim.fighters[fighter].isPvp && sim.fighters[local].isPvp;
|
||||
bool isPeaceful = !isPlain && fighter != local && sim.match.state == MATCH_PRACTICE && !isHostile;
|
||||
return isPeaceful ? color_shade(color, PVP_OFF_SHADE) : color;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user