@@ -21,7 +21,7 @@ public: | |||
void tick(float dt); | |||
static std::unique_ptr<ImageResource> createInvalid(Context &ctx); | |||
static std::unique_ptr<ImageResource> createInvalid(Win &win); | |||
std::unique_ptr<SDL_Surface, void (*)(SDL_Surface *)> surface_{nullptr, &SDL_FreeSurface}; | |||
std::unique_ptr<SDL_Texture, void (*)(SDL_Texture *)> texture_{nullptr, &SDL_DestroyTexture}; | |||
@@ -37,6 +37,8 @@ private: | |||
class ResourceManager { | |||
public: | |||
ResourceManager(Win &win); | |||
void tick(float dt); | |||
ImageResource &getImage(const std::string &name) const; |
@@ -20,7 +20,7 @@ class Game; | |||
class World { | |||
public: | |||
World(Game *game, unsigned long rand_seed): game_(game), random_(rand_seed) {} | |||
World(Game *game, unsigned long rand_seed); | |||
void addMod(std::unique_ptr<Mod> mod); | |||
void setWorldGen(const std::string &gen); | |||
@@ -51,11 +51,11 @@ public: | |||
std::unordered_map<std::string, WorldGen::Factory *> worldgens_; | |||
std::unordered_map<std::string, Entity::Factory *> ents_; | |||
ResourceManager resources_; | |||
Entity *player_; | |||
Game *game_; | |||
std::mt19937 random_; | |||
ResourceManager resources_; | |||
private: | |||
class ChunkRenderer { |
@@ -61,12 +61,16 @@ void ImageResource::tick(float dt) { | |||
} | |||
} | |||
std::unique_ptr<ImageResource> ImageResource::createInvalid(Context &ctx) { | |||
std::unique_ptr<ImageResource> ImageResource::createInvalid(Win &win) { | |||
return std::make_unique<ImageResource>( | |||
ctx.game.win_.renderer_, "@internal::invalid", TILE_SIZE, TILE_SIZE, | |||
win.renderer_, "@internal::invalid", TILE_SIZE, TILE_SIZE, | |||
PLACEHOLDER_RED, PLACEHOLDER_GREEN, PLACEHOLDER_BLUE); | |||
} | |||
ResourceManager::ResourceManager(Win &win) { | |||
invalid_image_ = ImageResource::createInvalid(win); | |||
} | |||
void ResourceManager::tick(float dt) { | |||
for (auto &[k, v]: images_) { | |||
v->tick(dt); |
@@ -20,6 +20,9 @@ static bool chunkLine(int l, WorldPlane &plane, ChunkPos &abspos, const Vec2i &d | |||
return false; | |||
} | |||
World::World(Game *game, unsigned long rand_seed): | |||
game_(game), random_(rand_seed), resources_(game->win_) {} | |||
void World::ChunkRenderer::tick(WorldPlane &plane, ChunkPos abspos) { | |||
int l = 0; | |||
@@ -34,7 +37,7 @@ void World::ChunkRenderer::tick(WorldPlane &plane, ChunkPos abspos) { | |||
} | |||
void World::addMod(std::unique_ptr<Mod> mod) { | |||
printf("World: Adding mod %s\n", mod->name_.c_str()); | |||
fprintf(stderr, "World: Adding mod %s\n", mod->name_.c_str()); | |||
for (auto t: mod->buildTiles(resources_)) { | |||
Tile::ID id = tiles_.size(); |