demo time-based: porta el patro de CCAE (multi-set, index = elapsed_s*60, % size per safe loop), substitueix demo.bin per demo1/2/3.bin
This commit is contained in:
@@ -144,8 +144,9 @@ void Resource::loadDataAsset(const std::string &bname, const std::vector<uint8_t
|
||||
lines.push_back(line);
|
||||
}
|
||||
animation_lines_[bname] = std::move(lines);
|
||||
} else if (bname == "demo.bin") {
|
||||
demo_bytes_ = bytes;
|
||||
} else if (bname.size() > 5 && bname.substr(0, 4) == "demo" && bname.substr(bname.size() - 4) == ".bin") {
|
||||
// Acumula tots els demo*.bin (demo1.bin, demo2.bin, ...) en ordre d'aparicio
|
||||
demo_bytes_.push_back(bytes);
|
||||
}
|
||||
// Menús (.men): se construyen en pass 2 porque dependen de textos y sonidos
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ class Resource {
|
||||
auto getAnimationLines(const std::string &name) -> std::vector<std::string> &;
|
||||
auto getText(const std::string &name) -> Text *; // name sin extensión: "smb2", "nokia2", ...
|
||||
auto getMenu(const std::string &name) -> Menu *; // name sin extensión: "title", "options", ...
|
||||
auto getDemoBytes() const -> const std::vector<uint8_t> & { return demo_bytes_; }
|
||||
[[nodiscard]] auto getDemoCount() const -> size_t { return demo_bytes_.size(); }
|
||||
[[nodiscard]] auto getDemoBytes(size_t index) const -> const std::vector<uint8_t> & { return demo_bytes_.at(index); }
|
||||
|
||||
private:
|
||||
explicit Resource(SDL_Renderer *renderer);
|
||||
@@ -51,7 +52,7 @@ class Resource {
|
||||
std::unordered_map<std::string, std::vector<std::string>> animation_lines_;
|
||||
std::unordered_map<std::string, Text *> texts_;
|
||||
std::unordered_map<std::string, Menu *> menus_;
|
||||
std::vector<uint8_t> demo_bytes_;
|
||||
std::vector<std::vector<uint8_t>> demo_bytes_;
|
||||
|
||||
static Resource *instance;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "core/system/demo.hpp"
|
||||
|
||||
#include <cstring> // for memcpy
|
||||
|
||||
// Desempaqueta un blob binari amb TOTAL_DEMO_DATA registres consecutius
|
||||
// de DemoKeys (struct POD de 6 bytes). Si el blob no te la mida esperada,
|
||||
// torna un vector buit perque el playback el detecti i no peti.
|
||||
auto loadDemoDataFromBytes(const std::vector<uint8_t> &bytes) -> DemoData {
|
||||
DemoData dd;
|
||||
const size_t EXPECTED = sizeof(DemoKeys) * TOTAL_DEMO_DATA;
|
||||
if (bytes.size() < EXPECTED) {
|
||||
return dd;
|
||||
}
|
||||
dd.resize(TOTAL_DEMO_DATA);
|
||||
std::memcpy(dd.data(), bytes.data(), EXPECTED);
|
||||
return dd;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Total de "frames" gravats a 60Hz de referencia. Equival a 2000/60 ~ 33.3s
|
||||
// reals, independentment del refresc real perque el playback es time-based
|
||||
// (index = elapsed_s * 60).
|
||||
constexpr int TOTAL_DEMO_DATA = 2000;
|
||||
|
||||
// Pulsacions per frame de referencia gravades a disc / reproduides al playback.
|
||||
struct DemoKeys {
|
||||
Uint8 left;
|
||||
Uint8 right;
|
||||
Uint8 no_input;
|
||||
Uint8 fire;
|
||||
Uint8 fire_left;
|
||||
Uint8 fire_right;
|
||||
|
||||
explicit DemoKeys(Uint8 l = 0, Uint8 r = 0, Uint8 ni = 0, Uint8 f = 0, Uint8 fl = 0, Uint8 fr = 0)
|
||||
: left(l),
|
||||
right(r),
|
||||
no_input(ni),
|
||||
fire(f),
|
||||
fire_left(fl),
|
||||
fire_right(fr) {}
|
||||
};
|
||||
|
||||
// Una demo completa: vector de frames.
|
||||
using DemoData = std::vector<DemoKeys>;
|
||||
|
||||
// Estat del subsistema de demo dins de Game.
|
||||
struct Demo {
|
||||
bool enabled{false}; // Mode demo actiu (reproduccio)
|
||||
bool recording{false}; // Mode gravacio actiu
|
||||
float elapsed_s{0.0F}; // Temps acumulat des de l'inici de la demo
|
||||
int index{0}; // index = elapsed_s * 60 (derivat)
|
||||
DemoKeys keys; // Buffer de tecles del frame actual (gravacio)
|
||||
std::vector<DemoData> data; // Vector de sets de demo carregats (multi-fitxer)
|
||||
};
|
||||
|
||||
// Carrega un fitxer .bin (TOTAL_DEMO_DATA * sizeof(DemoKeys) bytes) i
|
||||
// retorna el DemoData. Si el fitxer no es troba, retorna un DemoData buit.
|
||||
auto loadDemoDataFromBytes(const std::vector<uint8_t> &bytes) -> DemoData;
|
||||
@@ -338,7 +338,9 @@ auto Director::setFileList() -> bool {
|
||||
|
||||
// Ficheros de configuración
|
||||
Asset::get()->add(system_folder_ + "/score.bin", Asset::Type::DATA, false, true);
|
||||
Asset::get()->add(PREFIX + "/data/demo/demo.bin", Asset::Type::DATA);
|
||||
Asset::get()->add(PREFIX + "/data/demo/demo1.bin", Asset::Type::DATA);
|
||||
Asset::get()->add(PREFIX + "/data/demo/demo2.bin", Asset::Type::DATA);
|
||||
Asset::get()->add(PREFIX + "/data/demo/demo3.bin", Asset::Type::DATA);
|
||||
|
||||
// Musicas
|
||||
Asset::get()->add(PREFIX + "/data/music/intro.ogg", Asset::Type::MUSIC);
|
||||
|
||||
Reference in New Issue
Block a user