Browse Source

replace core::air with @::air

"@internal::" is also renamed to "@::" for libswan-internal stuff.
opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
976d9b4b9c

+ 0
- 1
core.mod/CMakeLists.txt View File

@@ -12,7 +12,6 @@ set(assets
assets/entity/player-running.png
assets/entity/player-running.toml
assets/tile/grass.png
assets/tile/air.png
assets/tile/stone.png
assets/tile/dirt.png
assets/tile/leaves.png

BIN
core.mod/assets-src/tiles/air.xcf View File


BIN
core.mod/assets/tile/air.png View File


+ 1
- 1
core.mod/src/DefaultWorldGen.h View File

@@ -10,7 +10,7 @@ public:
tGrass_(world.getTileID("core::grass")),
tDirt_(world.getTileID("core::dirt")),
tStone_(world.getTileID("core::stone")),
tAir_(world.getTileID("core::air")),
tAir_(world.getTileID("@::air")),
tTreeTrunk_(world.getTileID("core::tree-trunk")),
tLeaves_(world.getTileID("core::leaves")),
bgCave_(world.resources_.getImage("core/misc/background-cave")) {}

+ 0
- 6
core.mod/src/main.cc View File

@@ -10,7 +10,6 @@ public:
break_listener_ = world.evt_tile_break_.subscribe(
std::bind_front(&CoreMod::onTileBreak, this));

registerImage("tile/air");
registerImage("tile/stone");
registerImage("tile/dirt");
registerImage("tile/grass");
@@ -20,11 +19,6 @@ public:
registerImage("entity/player-still");
registerImage("misc/background-cave");

registerTile({
.name = "air",
.image = "core/tile/air",
.is_solid = false,
});
registerTile({
.name = "stone",
.image = "core/tile/stone",

+ 1
- 3
libswan/include/swan/Resource.h View File

@@ -16,7 +16,7 @@ public:
SDL_Renderer *renderer, const std::string &modpath, const std::string &id);
ImageResource(
SDL_Renderer *renderer, const std::string &name,
int w, int h, uint8_t r, uint8_t g, uint8_t b);
int w, int h, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);

void tick(float dt);

@@ -25,8 +25,6 @@ public:
return SDL_Rect{ 0, frame_height_ * frame, surface_->w, frame_height_ };
}

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};
int frame_height_;

+ 1
- 0
libswan/include/swan/Tile.h View File

@@ -32,6 +32,7 @@ public:
const std::optional<std::string> dropped_item_;

static std::unique_ptr<Tile> createInvalid(const ResourceManager &ctx);
static std::unique_ptr<Tile> createAir(const ResourceManager &ctx);
static ID INVALID_ID;
};


+ 2
- 2
libswan/src/Item.cc View File

@@ -8,8 +8,8 @@ namespace Swan {

std::unique_ptr<Item> Item::createInvalid(Context &ctx) {
return std::make_unique<Item>(ctx.resources, Builder{
.name = "@internal::invalid",
.image = "@internal::invalid",
.name = "@::invalid",
.image = "@::invalid",
});
}


+ 11
- 20
libswan/src/Resource.cc View File

@@ -37,15 +37,6 @@ ImageResource::ImageResource(

surface_.reset(IMG_Load((assetpath + ".png").c_str()));

// If we have a surface, and it's the wrong pixel format, convert it
if (surface_ && surface_->format->format != format) {
info
<< " " << id << ": Converting from "
<< SDL_GetPixelFormatName(surface_->format->format) << " to "
<< SDL_GetPixelFormatName(format);
surface_.reset(SDL_ConvertSurfaceFormat(surface_.get(), format, 0));
}

// If we don't have a surface yet (either loading or conversion failed),
// create a placeholder
if (!surface_) {
@@ -87,11 +78,12 @@ ImageResource::ImageResource(

ImageResource::ImageResource(
SDL_Renderer *renderer, const std::string &name,
int w, int h, uint8_t r, uint8_t g, uint8_t b) {
int w, int h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {

surface_.reset(SDL_CreateRGBSurface(
0, TILE_SIZE, TILE_SIZE, 32, 0, 0, 0, 0));
SDL_FillRect(surface_.get(), NULL, SDL_MapRGB(surface_->format, r, g, b));
0, TILE_SIZE, TILE_SIZE, 32,
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff));
SDL_FillRect(surface_.get(), NULL, SDL_MapRGBA(surface_->format, r, g, b, a));

texture_.reset(SDL_CreateTextureFromSurface(renderer, surface_.get()));
if (!texture_) {
@@ -114,14 +106,13 @@ void ImageResource::tick(float dt) {
}
}

std::unique_ptr<ImageResource> ImageResource::createInvalid(Win &win) {
return std::make_unique<ImageResource>(
win.renderer_, "@internal::invalid", TILE_SIZE, TILE_SIZE,
PLACEHOLDER_RED, PLACEHOLDER_GREEN, PLACEHOLDER_BLUE);
}

ResourceManager::ResourceManager(Win &win) {
addImage(ImageResource::createInvalid(win));
addImage(std::make_unique<ImageResource>(
win.renderer_, "@::invalid", TILE_SIZE, TILE_SIZE,
PLACEHOLDER_RED, PLACEHOLDER_GREEN, PLACEHOLDER_BLUE));
addImage(std::make_unique<ImageResource>(
win.renderer_, "@::air", TILE_SIZE, TILE_SIZE,
0, 0, 0, 0));
}

void ResourceManager::tick(float dt) {
@@ -134,7 +125,7 @@ ImageResource &ResourceManager::getImage(const std::string &name) const {
auto it = images_.find(name);
if (it == end(images_)) {
warn << "Couldn't find image " << name << "!";
return getImage("@internal::invalid");
return getImage("@::invalid");
}
return *it->second;
}

+ 10
- 2
libswan/src/Tile.cc View File

@@ -9,8 +9,16 @@ Tile::ID Tile::INVALID_ID = 0;

std::unique_ptr<Tile> Tile::createInvalid(const ResourceManager &resources) {
return std::make_unique<Tile>(resources, Builder{
.name = "@internal::invalid",
.image = "@internal::invalid",
.name = "@::invalid",
.image = "@::invalid",
});
}

std::unique_ptr<Tile> Tile::createAir(const ResourceManager &resources) {
return std::make_unique<Tile>(resources, Builder{
.name = "@::air",
.image = "@::air",
.is_solid = false,
});
}


+ 4
- 0
libswan/src/World.cc View File

@@ -26,6 +26,10 @@ World::World(Game *game, unsigned long rand_seed):
// ends up at location 0
tiles_.push_back(std::move(invalid_tile));

// We're also going to need an air tile at location 1
tiles_.push_back(Tile::createAir(resources_));
tiles_map_["@::air"] = 1;

}

void World::ChunkRenderer::tick(WorldPlane &plane, ChunkPos abspos) {

+ 1
- 13
libswan/src/WorldPlane.cc View File

@@ -157,25 +157,13 @@ void WorldPlane::breakTile(TilePos pos) {

// If the block is already air, do nothing
Tile::ID id = getTileID(pos);
Tile::ID air = world_->getTileID("core::air");
Tile::ID air = world_->getTileID("@::air");
if (id == air)
return;

// Change tile to air and emit event
setTileID(pos, air);
world_->evt_tile_break_.emit(getContext(), pos, world_->getTileByID(id));

/*
// Then spawn an item stack entity.
Tile &t = world_->getTileByID(id);
if (t.dropped_item_) {
msgpack::zone zone;
spawnEntity("core::item-stack", Entity::PackObject{
{ "pos", msgpack::object(pos, zone) },
{ "item", msgpack::object(*t.dropped_item_, zone) },
});
}
*/
}

SDL_Color WorldPlane::backgroundColor() {

Loading…
Cancel
Save