@@ -22,19 +22,19 @@ public: | |||
SDL_Rect frameRect(int frame = -1) const { | |||
if (frame == -1) frame = frame_; | |||
return SDL_Rect{ 0, frame_height_ * frame, surface_->w, frame_height_ }; | |||
return SDL_Rect{ 0, frameHeight_ * frame, surface_->w, frameHeight_ }; | |||
} | |||
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_; | |||
int num_frames_; | |||
int frameHeight_; | |||
int numFrames_; | |||
std::string name_; | |||
int frame_ = 0; | |||
private: | |||
float switch_interval_ = 1; | |||
float switch_timer_ = switch_interval_; | |||
float switchInterval_ = 1; | |||
float switchTimer_ = switchInterval_; | |||
}; | |||
class ResourceManager { |
@@ -23,7 +23,7 @@ class Game; | |||
class World { | |||
public: | |||
World(Game *game, unsigned long rand_seed); | |||
World(Game *game, unsigned long randSeed); | |||
void addMod(ModWrapper &&mod); | |||
void setWorldGen(std::string gen); |
@@ -47,7 +47,7 @@ ImageResource::ImageResource( | |||
PLACEHOLDER_RED, PLACEHOLDER_GREEN, PLACEHOLDER_BLUE)); | |||
} | |||
frame_height_ = 32; | |||
frameHeight_ = 32; | |||
// Load TOML if it exists | |||
errno = ENOENT; // I don't know if ifstream is guaranteed to set errno | |||
@@ -56,7 +56,7 @@ ImageResource::ImageResource( | |||
cpptoml::parser parser(tomlfile); | |||
try { | |||
auto toml = parser.parse(); | |||
frame_height_ = toml->get_as<int>("height").value_or(frame_height_); | |||
frameHeight_ = toml->get_as<int>("height").value_or(frameHeight_); | |||
} catch (cpptoml::parse_exception &exc) { | |||
warn << "Failed to parse toml file " << assetpath << ".toml: " | |||
<< exc.what(); | |||
@@ -71,7 +71,7 @@ ImageResource::ImageResource( | |||
abort(); | |||
} | |||
num_frames_ = surface_->h / frame_height_; | |||
numFrames_ = surface_->h / frameHeight_; | |||
name_ = id; | |||
} | |||
@@ -90,17 +90,17 @@ ImageResource::ImageResource( | |||
abort(); | |||
} | |||
frame_height_ = h; | |||
num_frames_ = 1; | |||
frameHeight_ = h; | |||
numFrames_ = 1; | |||
name_ = name; | |||
} | |||
void ImageResource::tick(float dt) { | |||
switch_timer_ -= dt; | |||
if (switch_timer_ <= 0) { | |||
switch_timer_ += switch_interval_; | |||
switchTimer_ -= dt; | |||
if (switchTimer_ <= 0) { | |||
switchTimer_ += switchInterval_; | |||
frame_ += 1; | |||
if (frame_ >= num_frames_) | |||
if (frame_ >= numFrames_) | |||
frame_ = 0; | |||
} | |||
} |
@@ -16,8 +16,8 @@ static void chunkLine(int l, WorldPlane &plane, ChunkPos &abspos, const Vec2i &d | |||
} | |||
} | |||
World::World(Game *game, unsigned long rand_seed): | |||
game_(game), random_(rand_seed), resources_(game->win_) { | |||
World::World(Game *game, unsigned long randSeed): | |||
game_(game), random_(randSeed), resources_(game->win_) { | |||
std::unique_ptr<Tile> invalidTile = Tile::createInvalid(resources_); | |||
tilesMap_[invalidTile->name] = 0; |
@@ -165,12 +165,12 @@ Iter<Entity *> WorldPlane::getEntsInArea(Vec2 center, float radius) { | |||
-> std::optional<Entity *> { | |||
// Filter out things which don't have bodies | |||
auto *has_body = dynamic_cast<BodyTrait::HasBody *>(ent.get()); | |||
if (has_body == nullptr) | |||
auto *hasBody = dynamic_cast<BodyTrait::HasBody *>(ent.get()); | |||
if (hasBody == nullptr) | |||
return std::nullopt; | |||
// Filter out things which are too far away from 'center' | |||
auto &body = has_body->getBody(); | |||
auto &body = hasBody->getBody(); | |||
auto bounds = body.getBounds(); | |||
Vec2 entcenter = bounds.pos + (bounds.size / 2); | |||
auto dist = (entcenter - center).length(); |
@@ -40,11 +40,11 @@ test("Insert never overflows") { | |||
Swan::ItemStack s2(&item1, 40); | |||
s2 = s1.insert(s2); | |||
expecteq(s1.count(), item1.maxStack_); | |||
expecteq(s2.count(), 80 - item1.maxStack_); | |||
expecteq(s1.count(), item1.maxStack); | |||
expecteq(s2.count(), 80 - item1.maxStack); | |||
} | |||
test("Insert respects max_stack_") { | |||
test("Insert respects maxStack") { | |||
MockItem item1({ .name = "item1", .image = "no", .maxStack = 20 }); | |||
Swan::ItemStack s1(&item1, 15); |
@@ -35,7 +35,7 @@ int main() { | |||
for (int x = 12; x < 20; ++x) { | |||
set(x, 26); | |||
} | |||
nc.light_sources = { | |||
nc.lightSources = { | |||
{ { 20, 10 }, 20 }, | |||
{ { 16, 30 }, 20 }, | |||
{ { 5, 27 }, 20 }, |
@@ -230,7 +230,7 @@ int main(int argc, char **argv) { | |||
while (tickAcc >= 1.0 / TICK_RATE) { | |||
ZoneScopedN("game tick"); | |||
tickAcc -= 1.0 / TICK_RATE; | |||
RTClock tick_clock; | |||
RTClock tickClock; | |||
game.tick(1.0 / TICK_RATE); | |||
} | |||