-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from Daft-Freak/saves
SDL metadata strings and save data
- Loading branch information
Showing
25 changed files
with
257 additions
and
35 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
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,12 @@ | ||
// Default metadata if there is non compiled into the game | ||
// There should be nothing else in this file so that the VS linker drops it when not needed | ||
#ifdef _MSC_VER | ||
#define WEAK | ||
#else | ||
#define WEAK [[gnu::weak]] | ||
#endif | ||
|
||
WEAK const char *metadata_title = "32Blit Game"; | ||
WEAK const char *metadata_author = "Unknown"; | ||
WEAK const char *metadata_description = ""; | ||
WEAK const char *metadata_version = "v0.0.0"; |
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
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
void init(); | ||
void update(uint32_t time); | ||
void render(uint32_t time); | ||
void init(); | ||
void update(uint32_t time); | ||
void render(uint32_t time); | ||
|
||
extern const char *metadata_title; | ||
extern const char *metadata_author; | ||
extern const char *metadata_description; | ||
extern const char *metadata_version; |
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
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,31 @@ | ||
#include "save.hpp" | ||
#include "api_private.hpp" | ||
#include "file.hpp" | ||
|
||
namespace blit { | ||
/** | ||
* Read a block of save data from a save slot. | ||
* | ||
* \param data Pointer to store data into, should be at least `length` bytes | ||
* \param length Expected length of save data | ||
* \param slot Save slot to load, can be any number | ||
* | ||
* \return `true` if a save exists and contains enough data | ||
*/ | ||
bool read_save(char *data, uint32_t length, int slot) { | ||
File file(api.get_save_path() + "save" + std::to_string(slot)); | ||
|
||
return file.is_open() && uint32_t(file.read(0, length, data)) == length; | ||
} | ||
|
||
/** | ||
* Write a block of save data to a save slot. | ||
* | ||
* \param data Pointer to data to write, should be `length` bytes | ||
* \param length Length of data to write | ||
* \param slot Save slot to write to, can be any number | ||
*/ | ||
void write_save(const char *data, uint32_t length, int slot) { | ||
File(api.get_save_path() + "save" + std::to_string(slot), OpenMode::write).write(0, length, data); | ||
} | ||
} |
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 @@ | ||
#include <cstdint> | ||
|
||
namespace blit { | ||
bool read_save(char *data, uint32_t length, int slot = 0); | ||
void write_save(const char *data, uint32_t length, int slot = 0); | ||
|
||
/** | ||
* \overload | ||
*/ | ||
template<class T> | ||
bool read_save(T &data, int slot = 0) { | ||
return read_save(reinterpret_cast<char *>(&data), sizeof(T), slot); | ||
} | ||
|
||
/** | ||
* \overload | ||
*/ | ||
template<class T> | ||
void write_save(const T &data, int slot = 0) { | ||
write_save(reinterpret_cast<const char *>(&data), sizeof(T), slot); | ||
} | ||
} |
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,8 @@ | ||
|
||
cmake_minimum_required(VERSION 3.8) | ||
project (saves) | ||
set(32BLIT_PATH "../../" CACHE PATH "Path to 32blit.cmake") | ||
include (${32BLIT_PATH}/32blit.cmake) | ||
|
||
blit_executable (saves saves.cpp) | ||
blit_metadata (saves metadata.yml) |
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,8 @@ | ||
title: Saves | ||
description: Save data example. | ||
author: daft_freak | ||
splash: | ||
file: ../no-image.png | ||
icon: | ||
file: ../no-icon.png | ||
version: v1.0.0 |
Oops, something went wrong.