- Carrega de l'habitació des de arxiu

- Traslladem a jutil funcionetes varies
- Comencem a implementar carrega de actors des de arxiu
- Comencem a implementar els templates de actors
This commit is contained in:
2024-06-05 14:23:16 +02:00
parent e2bae91000
commit 9dc27d7e8b
9 changed files with 285 additions and 41 deletions

View File

@@ -1,24 +1,31 @@
#include "room.h"
#include "jdraw.h"
#include "jfile.h"
#include "jutil.h"
#include "actor.h"
namespace room
{
static vec3_t size = {8,8,8};
static vec3_t tmin = {0,0,0};
static vec3_t tmax = {7,7,7};
static vec3_t min = {0,0,0};
static vec3_t max = {56,56,56};
static int inner_w = 2;
static int inner_h = 2;
static uint8_t doors = DOOR_XP /*| DOOR_YP*/ ;
static uint8_t door_height[4];
static uint8_t color = 5;
static vec3_t size = {8,8,8}; // Tamany de l'habitació en tiles
static vec3_t tmin = {0,0,0}; // primer tile en cada coordenada
static vec3_t tmax = {7,7,7}; // ultim tile en cada coordenada
static vec3_t min = {0,0,0}; // primer "pixel isometric" en cada coordenada
static vec3_t max = {56,56,56}; // ultim "pixel isometric" en cada coordenada
static uint8_t floor_type = 0;
static uint8_t walls_type = 0;
static uint8_t doors_type = 0;
static uint8_t walldoors_type = 0;
static uint8_t doors = NO_DOOR; // Portes obertes
static uint8_t door_height[4]; // Altura de cada porta
static int8_t exits[6]; // Habitació destí a la que du cada porta (piso i sostre inclosos)
static uint8_t color = 5; // Color de l'habitació
static uint8_t floor_type = 0; // Tile per al piso
static uint8_t walls_type = 0; // Tile per a les pareds
static uint8_t doors_type = 0; // Textura per a les portes
static uint8_t walldoors_type = 0; // Textura per a baix de les portes
// Surface on se guarden els gràfics de cada cosa
static draw::surface *floor_surf = nullptr;
static draw::surface *walls_surf = nullptr;
static draw::surface *doors_surf = nullptr;
@@ -28,6 +35,8 @@ namespace room
{
actor::clear();
// [TODO][2024-06-05] Açò es una xorrada. Si al final sempre son els mateixos arxius,
// carregar açò al principi del joc i au
if (floor_surf) draw::freeSurface(floor_surf);
if (walls_surf) draw::freeSurface(walls_surf);
if (doors_surf) draw::freeSurface(doors_surf);
@@ -39,24 +48,18 @@ namespace room
aux_surf = draw::loadSurface("roomaux.gif");
}
void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn, uint8_t col, uint8_t floor, uint8_t walls, uint8_t door, uint8_t walldoor)
void refresh()
{
init();
color = col;
floor_type = floor;
walls_type = walls;
doors_type = door;
walldoors_type = walldoor;
size = {(x+1)*2,(y+1)*2,3};
tmin = {3-x,3-y,0};
tmax = {4+x,4+y,3};
size = {(inner_w+1)*2,(inner_h+1)*2,3};
tmin = {3-inner_w,3-inner_h,0};
tmax = {4+inner_w,4+inner_h,3};
min = {tmin.x*8,tmin.y*8,0};
max = {tmax.x*8,tmax.y*8,24};
doors = (xp>=0?DOOR_XP:0) | (xn>=0?DOOR_XN:0) | (yp>=0?DOOR_YP:0) | (yn>=0?DOOR_YN:0);
door_height[0] = xp; //XP
door_height[1] = xn; //XN
door_height[2] = yp; //YP
door_height[3] = yn; //YN
doors = (door_height[XP]>=0?DOOR_XP:0) | (door_height[XN]>=0?DOOR_XN:0) | (door_height[YP]>=0?DOOR_YP:0) | (door_height[YN]>=0?DOOR_YN:0);
//door_height[0] = inner_xp; //XP
//door_height[1] = inner_xn; //XN
//door_height[2] = inner_yp; //YP
//door_height[3] = inner_yn; //YN
if (doors & DOOR_YP)
{
@@ -82,7 +85,105 @@ namespace room
actor::reorder();
}
//void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn, uint8_t col, uint8_t floor, uint8_t walls, uint8_t door, uint8_t walldoor)
void load(const int room)
{
if (room > 64) { perror("ERROR: Nombre d'habitació massa gran! Eixint..."); exit(1); }
init();
// Primer carreguem els valors per defecte
inner_w = inner_h = 2;
for (int i=0;i<4;++i) door_height[i] = -1;
color = 9;
floor_type = walls_type = doors_type = walldoors_type = 0;
for (int i=0;i<6;++i) exits[i] = -1;
// Després intentem carregar els valors segons el arxiu que toca, si existeix
char filename[] = "rooms/00.txt";
filename[6] = int(room/10)*48;
filename[7] = (room%10)*48;
int filesize=0;
char *buffer = file::getFileBuffer(filename, filesize, true);
char *original_buffer = buffer;
if (buffer)
{
while (*buffer != 0)
{
const char* key = file::readString(&buffer);
if (util::strcomp(key, "width:")) {
const int val = file::readInt(&buffer);
inner_w = SDL_clamp(val, 0, 3);
} else if (util::strcomp(key, "height:")) {
const int val = file::readInt(&buffer);
inner_h = SDL_clamp(val, 0, 3);
} else if (util::strcomp(key, "door-height-xp:")) {
const int val = file::readInt(&buffer);
door_height[XP] = SDL_clamp(val, -1, 5);
} else if (util::strcomp(key, "door-height-xn:")) {
const int val = file::readInt(&buffer);
door_height[XN] = SDL_clamp(val, -1, 5);
} else if (util::strcomp(key, "door-height-yp:")) {
const int val = file::readInt(&buffer);
door_height[YP] = SDL_clamp(val, -1, 5);
} else if (util::strcomp(key, "door-height-yn:")) {
const int val = file::readInt(&buffer);
door_height[YN] = SDL_clamp(val, -1, 5);
} else if (util::strcomp(key, "color:")) {
color = util::stringToInt(file::readString(&buffer), {"blue", "red", "purple", "green", "cyan", "yellow", "white"}, {5, 6, 7, 8, 9, 10, 11});
} else if (util::strcomp(key, "floor-texture:")) {
floor_type = file::readInt(&buffer);
} else if (util::strcomp(key, "wall-texture:")) {
walls_type = file::readInt(&buffer);
} else if (util::strcomp(key, "door-texture:")) {
doors_type = file::readInt(&buffer);
} else if (util::strcomp(key, "under-door-texture:")) {
walldoors_type = file::readInt(&buffer);
} else if (util::strcomp(key, "exit-xp:")) {
const int val = file::readInt(&buffer);
exits[0] = SDL_clamp(val, 0, 64);
} else if (util::strcomp(key, "exit-xn:")) {
const int val = file::readInt(&buffer);
exits[1] = SDL_clamp(val, 0, 64);
} else if (util::strcomp(key, "exit-yp:")) {
const int val = file::readInt(&buffer);
exits[2] = SDL_clamp(val, 0, 64);
} else if (util::strcomp(key, "exit-yn:")) {
const int val = file::readInt(&buffer);
exits[3] = SDL_clamp(val, 0, 64);
} else if (util::strcomp(key, "exit-zp:")) {
const int val = file::readInt(&buffer);
exits[4] = SDL_clamp(val, 0, 64);
} else if (util::strcomp(key, "exit-zn:")) {
const int val = file::readInt(&buffer);
exits[5] = SDL_clamp(val, 0, 64);
} else if (util::strcomp(key, "actor{")) {
actor::createFromFile(&buffer);
}
}
free(original_buffer);
}
refresh();
}
void update()
{
actor::remove(actor::find("DOOR_XP1"));
actor::remove(actor::find("DOOR_XP2"));
actor::remove(actor::find("DOOR_YP1"));
actor::remove(actor::find("DOOR_YP2"));
refresh();
}
void draw()
{
draw::pushSource();
@@ -232,4 +333,31 @@ namespace room
{
return color;
}
namespace editor
{
void setWidth(const int value) { inner_w = value; update(); }
void setHeight(const int value) { inner_h = value; update(); }
void setDoor(const int which, const int value) { door_height[which] = value; update(); }
void setColor(const int value) { color = value; update(); }
void setFloorTex(const int value) { floor_type = value; update(); }
void setWallTex(const int value) { walls_type = value; update(); }
void setDoorTex(const int value) { doors_type = value; update(); }
void setWallDoorTex(const int value) { walldoors_type = value; update(); }
void setExit(const int which, const int value) { exits[which] = value; update(); }
const int getWidth() { return inner_w; }
const int getHeight() { return inner_h; }
const int getDoor(const int which) { return door_height[which]; }
const int getColor() { return color; }
const int getFloorTex() { return floor_type; }
const int getWallTex() { return walls_type; }
const int getDoorTex() { return doors_type; }
const int getWallDoorTex() { return walldoors_type; }
const int getExit(const int which) { return exits[which]; }
}
}