Large refactoring. Also, reimplemented resource manager to use parsers. Changed from json to xml (it allows comments!!!).

This commit is contained in:
2016-12-01 21:08:28 +02:00
parent 9c8cbf8518
commit 0b6a988184
71 changed files with 1608 additions and 923 deletions

61
src/model/Background.cpp Normal file
View File

@@ -0,0 +1,61 @@
/*
* Background.cpp
*
* Created on: Dec 1, 2016
* Author: tibi
*/
#include <model/Background.h>
#include <utils/Assert.h>
namespace farmlands {
namespace model {
Background::Background(size_t layerCount, size_t rowCount, size_t columnCount)
: m_cells(new Cell[layerCount * rowCount * columnCount]),
m_textures(new resources::ResourceId[layerCount]),
m_layers(layerCount),
m_rows(rowCount),
m_columns(columnCount)
{
}
Background::~Background()
{
delete[] m_cells;
delete[] m_textures;
}
Cell Background::cell(size_t layer, size_t row, size_t col) const
{
Assert(layer < m_layers, "Layer out of bounds.");
Assert(row < m_rows, "Row out of bounds.");
Assert(col < m_columns, "Column out of bounds.");
return m_cells[layer * m_rows * m_columns + row * m_columns + col];
}
void Background::setCell(size_t layer, size_t row, size_t col, Cell value)
{
Assert(layer < m_layers, "Layer out of bounds.");
Assert(row < m_rows, "Row out of bounds.");
Assert(col < m_columns, "Column out of bounds.");
m_cells[layer * m_rows * m_columns + row * m_columns + col] = value;
}
resources::ResourceId Background::texture(size_t layer) const
{
Assert(layer < m_layers, "Layer out of bounds.");
return m_textures[layer];
}
void Background::setTexture(size_t layer, resources::ResourceId textureId) const
{
Assert(layer < m_layers, "Layer out of bounds.");
m_textures[layer] = textureId;
}
} /* namespace model */
} /* namespace farmlands */

View File

@@ -1,29 +1,26 @@
/*
* Level.h
* Background.h
*
* Created on: Nov 11, 2016
* Created on: Dec 1, 2016
* Author: tibi
*/
#ifndef MODEL_LEVEL_H_
#define MODEL_LEVEL_H_
#ifndef MODEL_BACKGROUND_H_
#define MODEL_BACKGROUND_H_
#include <cstdint>
#include <cstddef>
#include <base/Component.h>
#include <resources/ResourceManager.h>
namespace farmlands {
namespace model {
typedef int16_t Cell;
class Level
class Background: public base::Component
{
public:
Level(size_t layerCount, size_t rowCount, size_t columnCount);
Level(const Level&) = delete;
Level& operator= (const Level&) = delete;
virtual ~Level();
Background(size_t layerCount, size_t rowCount, size_t columnCount);
virtual ~Background();
inline size_t layerCount() const { return m_layers; }
inline size_t rowCount() const { return m_rows; }
@@ -32,14 +29,12 @@ namespace model {
Cell cell(size_t layer, size_t row, size_t col) const;
void setCell(size_t layer, size_t row, size_t col, Cell value);
int texture(size_t layer) const;
void setTexture(size_t layer, int textureId) const;
size_t m_cellWidth, m_cellHeight;
resources::ResourceId texture(size_t layer) const;
void setTexture(size_t layer, resources::ResourceId textureId) const;
private:
Cell* m_cells;
int* m_textures;
resources::ResourceId* m_textures;
size_t m_layers;
size_t m_rows;
size_t m_columns;
@@ -48,4 +43,4 @@ namespace model {
} /* namespace model */
} /* namespace farmlands */
#endif /* MODEL_LEVEL_H_ */
#endif /* MODEL_BACKGROUND_H_ */

View File

@@ -4,37 +4,20 @@
* Created on: Nov 13, 2016
* Author: tibi
*/
#ifndef MODEL_CONFIGURATION_H_
#define MODEL_CONFIGURATION_H_
#include <SDL2/SDL.h>
namespace farmlands {
namespace model {
struct KeyConfiguration
{
SDL_Scancode Right = SDL_SCANCODE_RIGHT;
SDL_Scancode Up = SDL_SCANCODE_UP;
SDL_Scancode Left = SDL_SCANCODE_LEFT;
SDL_Scancode Down = SDL_SCANCODE_DOWN;
SDL_Scancode AltRight = SDL_SCANCODE_D;
SDL_Scancode AltUp = SDL_SCANCODE_W;
SDL_Scancode AltLeft = SDL_SCANCODE_A;
SDL_Scancode AltDown = SDL_SCANCODE_S;
SDL_Scancode Action = SDL_SCANCODE_SPACE;
SDL_Scancode Action2 = SDL_SCANCODE_LCTRL;
SDL_Scancode Run = SDL_SCANCODE_LSHIFT;
SDL_Scancode Debug_ZoomIn = SDL_SCANCODE_KP_PLUS;
SDL_Scancode Debug_ZoomOut = SDL_SCANCODE_KP_MINUS;
};
struct Configuration
{
KeyConfiguration keys;
float animationFps = 60.0f;
};
}
}
#endif

View File

@@ -1,62 +0,0 @@
/*
* Level.cpp
*
* Created on: Nov 11, 2016
* Author: tibi
*/
#include "Level.h"
#include <cassert>
namespace farmlands {
namespace model {
Level::Level(size_t layerCount, size_t rowCount, size_t columnCount)
: m_cellWidth(0),
m_cellHeight(0),
m_cells(new Cell[layerCount * rowCount * columnCount]),
m_textures(new int[layerCount]),
m_layers(layerCount),
m_rows(rowCount),
m_columns(columnCount)
{
}
Level::~Level()
{
delete[] m_cells;
delete[] m_textures;
}
Cell Level::cell(size_t layer, size_t row, size_t col) const
{
assert(layer < m_layers);
assert(row < m_rows);
assert(col < m_columns);
return m_cells[layer * m_rows * m_columns + row * m_columns + col];
}
void Level::setCell(size_t layer, size_t row, size_t col, Cell value)
{
assert(layer < m_layers);
assert(row < m_rows);
assert(col < m_columns);
m_cells[layer * m_rows * m_columns + row * m_columns + col] = value;
}
int Level::texture(size_t layer) const
{
return m_textures[layer];
}
void Level::setTexture(size_t layer, int textureId) const
{
m_textures[layer] = textureId;
}
} /* namespace model */
} /* namespace farmlands */

View File

@@ -1,36 +0,0 @@
/*
* Player.h
*
* Created on: Nov 26, 2016
* Author: tibi
*/
#ifndef MODEL_PLAYER_H_
#define MODEL_PLAYER_H_
#include <model/Direction.h>
namespace farmlands {
namespace model {
#define PLAYER_INVENTORY_SIZE 3*12
struct Player
{
float posX, posY;
float lastDeltaX, lastDeltaY;
Direction direction;
bool attacking;
uint32_t attackTimeLeft;
int inventorySelection = -1;
int inventory[PLAYER_INVENTORY_SIZE];
};
}
}
#endif /* MODEL_PLAYER_H_ */