Compare commits
8 Commits
main
...
a61c2e8d46
| Author | SHA1 | Date | |
|---|---|---|---|
| a61c2e8d46 | |||
| 9bb9d26417 | |||
| a96ce4afc9 | |||
| 29a2ebf221 | |||
| bcccfb026f | |||
| aad60d9849 | |||
| 4de0743a77 | |||
| 80e91e7acd |
32
Makefile
32
Makefile
@@ -9,6 +9,7 @@ windowsRelease = $(executable)-$(version)-win32-x64.zip
|
||||
macosIntelRelease = $(executable)-$(version)-macos-intel.dmg
|
||||
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
|
||||
linuxRelease = $(executable)-$(version)-linux.tar.gz
|
||||
opendinguxRelease = $(executable).opk
|
||||
|
||||
windows:
|
||||
@echo off
|
||||
@@ -139,4 +140,33 @@ linux_release:
|
||||
cd "$(releaseFolder)" && tar -czvf "../$(linuxRelease)" *
|
||||
|
||||
# Remove data
|
||||
rm -rdf "$(releaseFolder)"
|
||||
rm -rdf "$(releaseFolder)"
|
||||
|
||||
opendingux:
|
||||
/opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ -D GCWZERO -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lSDL2_mixer -lstdc++ -std=c++11 $(source) -o "$(executable)"
|
||||
|
||||
opendingux_release:
|
||||
# Remove data
|
||||
rm -rdf "$(releaseFolder)"
|
||||
|
||||
# Create folders
|
||||
mkdir -p "$(releaseFolder)"
|
||||
|
||||
# Copy data
|
||||
cp -R data "$(releaseFolder)"
|
||||
cp -R default.gcw0.desktop "$(releaseFolder)"
|
||||
cp -R icon.png "$(releaseFolder)"
|
||||
|
||||
# Delete data
|
||||
rm -f "$(releaseFolder)/data/room/map.world"
|
||||
rm -f "$(releaseFolder)/data/room/standard.tsx"
|
||||
|
||||
# Build
|
||||
/opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ -D GCWZERO -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lSDL2_mixer -lstdc++ -std=c++11 $(source) -o "$(releaseFolder)/$(executable)"
|
||||
|
||||
# Pack files
|
||||
rm -f "$(opendinguxRelease)"
|
||||
cd "$(releaseFolder)" && /opt/gcw0-toolchain/usr/bin/mksquashfs ./default.gcw0.desktop ./icon.png ./data ./$(executable) "../$(opendinguxRelease)" -all-root -noappend -no-exports -no-xattrs
|
||||
|
||||
# Remove data
|
||||
rm -rdf "$(releaseFolder)"
|
||||
|
||||
3
build.txt
Normal file
3
build.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
/opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ -D GCWZERO -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lstdc++ -std=c++11 source/*.cpp source/common/*.cpp -o jdd
|
||||
sftp root@10.1.1.2:jdd <<< $'put jdd'
|
||||
ssh root@10.1.1.2
|
||||
10
default.gcw0.desktop
Normal file
10
default.gcw0.desktop
Normal file
@@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Version=1.6
|
||||
Type=Application
|
||||
Name=JailDoctor's Dilemma
|
||||
Comment=JailDoctor's Dilemma
|
||||
Icon=icon
|
||||
Exec=jaildoctors_dilemma
|
||||
Categories=games;Game;SDL;
|
||||
Terminal=false
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
// Constructor
|
||||
Asset::Asset(std::string executablePath)
|
||||
{
|
||||
#ifdef __MIPSEL
|
||||
this->executablePath = ".";
|
||||
#else
|
||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
||||
#endif
|
||||
longestName = 0;
|
||||
verbose = true;
|
||||
}
|
||||
|
||||
16
source/common/destsurface.cpp
Normal file
16
source/common/destsurface.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "destsurface.h"
|
||||
|
||||
namespace DestSurface
|
||||
{
|
||||
void Init(SDL_Renderer *renderer, SDL_Texture *texture) {
|
||||
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
|
||||
}
|
||||
|
||||
uint32_t *getPixels() {
|
||||
|
||||
}
|
||||
}
|
||||
12
source/common/destsurface.h
Normal file
12
source/common/destsurface.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace DestSurface
|
||||
{
|
||||
void Init(SDL_Renderer *renderer, SDL_Texture *texture);
|
||||
|
||||
void Clear();
|
||||
|
||||
uint32_t *getPixels();
|
||||
}
|
||||
54
source/common/systempalette.cpp
Normal file
54
source/common/systempalette.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "systempalette.h"
|
||||
|
||||
namespace SystemPalette
|
||||
{
|
||||
|
||||
uint32_t entries[256]; // Las 256 entradas de la paleta
|
||||
uint8_t numEntries; // El número de entradas existente actualmente
|
||||
|
||||
// Vacía la paleta
|
||||
void Clear()
|
||||
{
|
||||
// Fijamos el color transparente en 0 y el blanco en 1
|
||||
entries[0] = 0x00000000; // Transparente
|
||||
entries[1] = 0xffffffff; // Blanco
|
||||
|
||||
numEntries = 2;
|
||||
|
||||
// Ya que 'getRGBA' no comprueba que el índice solicitado sea menor que
|
||||
// 'numentries', rellenamos con 'negro' todas las entradas no usadas.
|
||||
for (int i = 2; i < 256; ++i ) entries[i] = 0x000000ff;
|
||||
}
|
||||
|
||||
// Obtenemos el índice de la paleta para el color especificado. Si no existe se crea.
|
||||
uint8_t getEntry(const uint32_t color)
|
||||
{
|
||||
// ATENCIÓN!!! Si intentamos introducir más de 256 colores empezará a
|
||||
// sobreescribir los primeros colores. Al menos no corromperá la
|
||||
// memoria. Pensar la mejor forma de controlar esto.
|
||||
|
||||
// Recorremos la paleta...
|
||||
for (int i = 0; i < numEntries; ++i)
|
||||
{
|
||||
// Si encontramos el color, devolvemos su índice y salimos
|
||||
if (entries[i] == color) return i;
|
||||
}
|
||||
|
||||
// Si no se ha encontrado, lo ponemos al final
|
||||
entries[numEntries] = color;
|
||||
|
||||
// Y devolvemos su índice
|
||||
return numEntries++;
|
||||
}
|
||||
|
||||
// Dado un índice, devolvemos su color
|
||||
uint32_t getRGBA(const uint8_t entry)
|
||||
{
|
||||
// ATENCIÓN!!! No compruebo que el parámetro 'entry' sea menor que el
|
||||
// miembro 'numEntries', por lo que se puede acceder a colores no
|
||||
// definidos (por ejemplo tener 4 colores y acceder al color 8). La
|
||||
// razón es que necesito que esta función sea lo más rápida posible.
|
||||
// En cualquier caso, nunca se va a salir de la memoria ni nada raro.
|
||||
return entries[entry];
|
||||
}
|
||||
}
|
||||
14
source/common/systempalette.h
Normal file
14
source/common/systempalette.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
namespace SystemPalette
|
||||
{
|
||||
// Vacía la paleta
|
||||
void Clear();
|
||||
|
||||
// Obtenemos el índice de la paleta para el color especificado. Si no existe se crea.
|
||||
uint8_t getEntry(const uint32_t color);
|
||||
|
||||
// Dado un índice, devolvemos su color
|
||||
uint32_t getRGBA(const uint8_t entry);
|
||||
}
|
||||
@@ -3,23 +3,26 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#include <iostream>
|
||||
#include "systempalette.h"
|
||||
|
||||
// Constructor
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
||||
Texture::Texture(SDL_Renderer *renderer, SDL_Texture *texture, std::string path, bool verbose)
|
||||
{
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->texture = texture;
|
||||
this->path = path;
|
||||
|
||||
// Inicializa
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
this->pixels = nullptr;
|
||||
this->width = 0;
|
||||
this->height = 0;
|
||||
this->color = 0xffffffff;
|
||||
|
||||
// Carga el fichero en la textura
|
||||
if (path != "")
|
||||
{
|
||||
loadFromFile(path, renderer, verbose);
|
||||
loadFromFile(path, verbose);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +34,7 @@ Texture::~Texture()
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose)
|
||||
bool Texture::loadFromFile(std::string path, bool verbose)
|
||||
{
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
int req_format = STBI_rgb_alpha;
|
||||
@@ -50,90 +53,37 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos
|
||||
}
|
||||
}
|
||||
|
||||
int depth, pitch;
|
||||
Uint32 pixel_format;
|
||||
if (req_format == STBI_rgb)
|
||||
{
|
||||
depth = 24;
|
||||
pitch = 3 * width; // 3 bytes por pixel * pixels per linea
|
||||
pixel_format = SDL_PIXELFORMAT_RGB24;
|
||||
}
|
||||
else
|
||||
{ // STBI_rgb_alpha (RGBA)
|
||||
depth = 32;
|
||||
pitch = 4 * width;
|
||||
pixel_format = SDL_PIXELFORMAT_RGBA32;
|
||||
}
|
||||
|
||||
// Limpia
|
||||
unload();
|
||||
|
||||
// La textura final
|
||||
SDL_Texture *newTexture = nullptr;
|
||||
|
||||
// Carga la imagen desde una ruta específica
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
if (loadedSurface == nullptr)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Unable to load image " << path.c_str() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Crea la textura desde los pixels de la surface
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
if (newTexture == nullptr)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Obtiene las dimensiones de la imagen
|
||||
this->width = loadedSurface->w;
|
||||
this->height = loadedSurface->h;
|
||||
}
|
||||
|
||||
// Elimina la textura cargada
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
}
|
||||
const int size = width*height;
|
||||
this->pixels = new uint8_t[size];
|
||||
for (int i = 0; i < size; ++i) this->pixels[i] = SystemPalette::getEntry(data[i]);
|
||||
|
||||
// Return success
|
||||
stbi_image_free(data);
|
||||
texture = newTexture;
|
||||
return texture != nullptr;
|
||||
return this->pixels != nullptr;
|
||||
}
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess access)
|
||||
bool Texture::createBlank(int width, int height, SDL_TextureAccess access)
|
||||
{
|
||||
// Crea una textura sin inicializar
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (texture == nullptr)
|
||||
{
|
||||
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
this->pixels = new uint8_t[width*height];
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
return texture != nullptr;
|
||||
return this->pixels != nullptr;
|
||||
}
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void Texture::unload()
|
||||
{
|
||||
// Libera la textura si existe
|
||||
if (texture != nullptr)
|
||||
if (pixels != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = nullptr;
|
||||
delete[] pixels;
|
||||
pixels = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
@@ -142,19 +92,19 @@ void Texture::unload()
|
||||
// Establece el color para la modulacion
|
||||
void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||
this->color = (red << 24) + (green << 16) + (blue << 8) + 255;
|
||||
}
|
||||
|
||||
// Establece el blending
|
||||
void Texture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
SDL_SetTextureBlendMode(texture, blending);
|
||||
//SDL_SetTextureBlendMode(texture, blending);
|
||||
}
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void Texture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
SDL_SetTextureAlphaMod(texture, alpha);
|
||||
//SDL_SetTextureAlphaMod(texture, alpha);
|
||||
}
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
|
||||
@@ -11,26 +11,28 @@ class Texture
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Texture *texture; // La textura
|
||||
uint8_t *pixels; // Los pixels de esta textura
|
||||
SDL_Texture *texture; // La textura SDL sobre la que pintaremos (debe haber sido creada con SDL_TEXTUREACCESS_STREAMING)
|
||||
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||
|
||||
// Variables
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
uint32_t color; // Color para el pintado de 1 bit (sprites y tal)
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Texture(SDL_Renderer *renderer, std::string path = "", bool verbose = false);
|
||||
Texture(SDL_Renderer *renderer, SDL_Texture *texture, std::string path = "", bool verbose = false);
|
||||
|
||||
// Destructor
|
||||
~Texture();
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose = false);
|
||||
bool loadFromFile(std::string path, bool verbose = false);
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
bool createBlank(int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void unload();
|
||||
|
||||
@@ -121,7 +121,7 @@ void Director::initOptions()
|
||||
options->videoMode = 0;
|
||||
options->windowSize = 3;
|
||||
options->filter = FILTER_NEAREST;
|
||||
options->vSync = true;
|
||||
options->vSync = false;
|
||||
options->integerScale = true;
|
||||
options->keepAspect = true;
|
||||
options->borderEnabled = true;
|
||||
@@ -130,11 +130,11 @@ void Director::initOptions()
|
||||
options->palette = p_zxspectrum;
|
||||
|
||||
#ifdef GAME_CONSOLE
|
||||
options->windowSize = 2;
|
||||
options->windowSize = 1;
|
||||
#endif
|
||||
|
||||
// Estos valores no se guardan en el fichero de configuraci´ón
|
||||
options->console = false;
|
||||
options->console = true;
|
||||
options->cheat.infiniteLives = false;
|
||||
options->cheat.invincible = false;
|
||||
options->cheat.jailEnabled = false;
|
||||
|
||||
Reference in New Issue
Block a user