Skip to content

Commit

Permalink
Merge branch 'master' into simplesquirrel
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 authored Apr 27, 2024
2 parents e9d8989 + 4e873ea commit 8ed63c7
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- name: Lint code with Cppcheck
run: |
./danmar-cppcheck-*/cppcheck \
--check-level=exhaustive \
--quiet --inline-suppr --language=c++ --error-exitcode=10 \
-j"$(nproc)" --std=c++17 --enable=warning,style \
--suppress=useStlAlgorithm src/
2 changes: 1 addition & 1 deletion data/levels/misc/credits.stl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ stop_music(0);")
)
(camera
(name "Camera")
(mode "normal")
(mode "manual")
)
(decal
(name "PENNY")
Expand Down
8 changes: 6 additions & 2 deletions src/badguy/corrupted_granito_big.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CorruptedGranitoBig::CorruptedGranitoBig(const ReaderMapping& reader) :
parse_type(reader);

m_col.set_unisolid(true);
m_physic.enable_gravity(false);

SoundManager::current()->preload("sounds/brick.wav");
}
Expand All @@ -52,7 +53,7 @@ CorruptedGranitoBig::initialize()

m_state = STATE_READY;
set_action("idle", m_dir);
set_colgroup_active(COLGROUP_MOVING_STATIC);
set_colgroup_active(COLGROUP_STATIC);
}

void
Expand Down Expand Up @@ -80,9 +81,12 @@ CorruptedGranitoBig::draw(DrawingContext &context)
void
CorruptedGranitoBig::kill_fall()
{
if (m_state == STATE_BROKEN)
return;

m_state = STATE_BROKEN;
set_action("broken", m_dir);
set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
set_colgroup_active(COLGROUP_DISABLED);
m_col.set_unisolid(false);

run_dead_script();
Expand Down
1 change: 1 addition & 0 deletions src/collision/collision_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CollisionObject::CollisionObject(CollisionGroup group, CollisionListener& listen
m_movement(0.0f, 0.0f),
m_dest(),
m_unisolid(false),
m_pressure(),
m_objects_hit_bottom(),
m_ground_movement_manager(nullptr)
{
Expand Down
10 changes: 10 additions & 0 deletions src/collision/collision_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class CollisionObject
return m_bbox.p1();
}

Vector get_pressure() const
{
return m_pressure;
}

/** moves entire object to a specific position, including all
points those the object has, exactly like the object has
spawned in that given pos instead.*/
Expand Down Expand Up @@ -164,6 +169,11 @@ class CollisionObject
colliding with unisolid objects. */
bool m_unisolid;

/**
* Contains the current pressure on this object
*/
Vector m_pressure;

/** Objects that were touching the top of this object at the last frame,
if this object was static or moving static. */
std::unordered_set<CollisionObject*> m_objects_hit_bottom;
Expand Down
7 changes: 5 additions & 2 deletions src/collision/collision_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CollisionSystem::remove(CollisionObject* object)
m_objects.erase(
std::find(m_objects.begin(), m_objects.end(),
object));

// FIXME: This is a patch. A better way of fixing this is coming.
for (auto* collision_object : m_objects) {
collision_object->notify_object_removal(object);
Expand Down Expand Up @@ -121,7 +121,7 @@ collision::Constraints check_collisions(const Vector& obj_movement, const Rectf&

if (!moving_obj_rect.overlaps(grown_other_obj_rect))
return constraints;

const CollisionHit dummy;

if (other_object != nullptr && moving_object != nullptr && !other_object->collides(*moving_object, dummy))
Expand Down Expand Up @@ -472,6 +472,7 @@ CollisionSystem::collision_static_constrains(CollisionObject& object)
// later if we're really crushed or things will solve itself when
// looking at the vertical constraints.
pressure.y += object.get_bbox().get_height() - height;
object.m_pressure.y = pressure.y;
} else {
dest.set_bottom(constraints.get_position_bottom() - EPSILON);
dest.set_top(dest.get_bottom() - object.get_bbox().get_height());
Expand Down Expand Up @@ -505,6 +506,7 @@ CollisionSystem::collision_static_constrains(CollisionObject& object)
// later if we're really crushed or things will solve itself when
// looking at the horizontal constraints.
pressure.x += object.get_bbox().get_width() - width;
object.m_pressure.x = pressure.x;
} else {
float xmid = constraints.get_x_midpoint ();
dest.set_left(xmid - object.get_bbox().get_width()/2);
Expand Down Expand Up @@ -585,6 +587,7 @@ CollisionSystem::update()
}

object->m_dest = object->get_bbox();
object->m_pressure = Vector(0, 0);
object->m_dest.move(object->get_movement());
object->clear_bottom_collision_list();
}
Expand Down
5 changes: 5 additions & 0 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,11 @@ Player::handle_horizontal_input()
ax *= ICE_ACCELERATION_MULTIPLIER;
}

if(get_collision_object()->get_pressure() != Vector(0.0f, 0.0f)) {
vx = 0.0f; vy = 0.0f;
ax = 0.0f; ay = 0.0f;
}

m_physic.set_velocity(vx, vy);
m_physic.set_acceleration(ax, ay);

Expand Down
9 changes: 4 additions & 5 deletions src/supertux/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,17 @@ Statistics::frags_to_string(int badguys, int total_badguys)
std::string
Statistics::time_to_string(float time)
{
int time_csecs = static_cast<int>(time * 100);
int mins = (time_csecs / 6000);
int secs = (time_csecs % 6000) / 100;
int cscs = (time_csecs % 6000) % 100;

std::ostringstream os;
if (time == 0.0f)
{
os << "--:--:--";
}
else
{
int time_csecs = static_cast<int>(time * 100);
int mins = (time_csecs / 6000);
int secs = (time_csecs % 6000) / 100;
int cscs = (time_csecs % 6000) % 100;
os << std::setw(2) << std::setfill('0') << mins << ":" << std::setw(2) << std::setfill('0') << secs << "." << std::setw(2) << std::setfill('0') << cscs;
}

Expand Down
5 changes: 2 additions & 3 deletions src/supertux/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ World::from_directory(const std::string& directory)
info.get("hide-from-contribs", world->m_hide_from_contribs, false);
info.get("contrib-type", world->m_contrib_type, "user");
info.get("title-level", world->m_title_level);
return world;
}
catch (const std::exception& err)
{
log_warning << "Failed to load " << info_filename << ":" << err.what() << std::endl;

world->m_hide_from_contribs = true;

return world;
}

return world;
}

std::unique_ptr<World>
Expand Down
5 changes: 4 additions & 1 deletion src/supertux/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <memory>
#include <string>

#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"

class World final
{
friend class EditorLevelsetMenu;
Expand All @@ -39,7 +42,7 @@ class World final
std::string get_title() const { return m_title; }
std::string get_description() const { return m_description; }

bool hide_from_contribs() const { return m_hide_from_contribs; }
bool hide_from_contribs() const { return m_hide_from_contribs && !g_config->developer_mode; }

bool is_levelset() const { return m_is_levelset; }
bool is_worldmap() const { return !m_is_levelset; }
Expand Down
2 changes: 1 addition & 1 deletion src/video/bitmap_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace {

bool vline_empty(const SDLSurfacePtr& surface, int x, int start_y, int end_y, Uint8 threshold)
{
Uint8* pixels = static_cast<Uint8*>(surface->pixels);
const Uint8* pixels = static_cast<Uint8*>(surface->pixels);

for (int y = start_y; y < end_y; ++y)
{
Expand Down
5 changes: 1 addition & 4 deletions src/video/sdl/sdl_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,7 @@ SDLPainter::clear(const Color& color)
void
SDLPainter::set_clip_rect(const Rect& rect)
{
m_cliprect = SDL_Rect{ rect.left,
rect.top,
rect.get_width(),
rect.get_height() };
m_cliprect = rect.to_sdl();

int ret = SDL_RenderSetClipRect(m_sdl_renderer, &*m_cliprect);
if (ret < 0)
Expand Down
3 changes: 1 addition & 2 deletions src/video/sdl/sdl_screen_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ SDLScreenRenderer::start_draw()
const Rect& viewport = m_video_system.get_viewport().get_rect();
const Vector& scale = m_video_system.get_viewport().get_scale();

SDL_Rect sdl_viewport = { viewport.left, viewport.top,
viewport.get_width(), viewport.get_height() };
SDL_Rect sdl_viewport = viewport.to_sdl();

// SetViewport() works in scaled screen coordinates, so we have to
// reset it to 1.0, 1.0 to get meaningful results
Expand Down
2 changes: 1 addition & 1 deletion src/video/sdl_surface_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <SDL.h>

/** Simple Wrapper class around SDL_Surface that provides execption
/** Simple Wrapper class around SDL_Surface that provides exception
safety */
class SDLSurfacePtr final
{
Expand Down
23 changes: 11 additions & 12 deletions src/worldmap/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const float CAMERA_PAN_TIME_MAX = 0.52213f;

namespace worldmap {

Camera::Camera() :
Camera::Camera(WorldMapSector& worldmap_sector) :
m_worldmap_sector(worldmap_sector),
m_camera_offset(0.0f, 0.0f),
m_pan_startpos(0.0f, 0.0f),
m_pan_time_full(0),
Expand Down Expand Up @@ -82,7 +83,7 @@ Camera::pan()
Vector
Camera::get_camera_pos_for_tux() const
{
auto& tux = WorldMapSector::current()->get_singleton_by_type<Tux>();
auto& tux = m_worldmap_sector.get_singleton_by_type<Tux>();

Vector camera_offset_(0.0f, 0.0f);
Vector tux_pos = tux.get_pos();
Expand All @@ -94,8 +95,6 @@ Camera::get_camera_pos_for_tux() const
void
Camera::clamp_camera_position(Vector& c) const
{
auto& worldmap_sector = *WorldMapSector::current();

if (c.x < 0) {
c.x = 0;
}
Expand All @@ -104,20 +103,20 @@ Camera::clamp_camera_position(Vector& c) const
c.y = 0;
}

if (c.x > worldmap_sector.get_width() - static_cast<float>(SCREEN_WIDTH)) {
c.x = worldmap_sector.get_width() - static_cast<float>(SCREEN_WIDTH);
if (c.x > m_worldmap_sector.get_width() - static_cast<float>(SCREEN_WIDTH)) {
c.x = m_worldmap_sector.get_width() - static_cast<float>(SCREEN_WIDTH);
}

if (c.y > worldmap_sector.get_height() - static_cast<float>(SCREEN_HEIGHT)) {
c.y = worldmap_sector.get_height() - static_cast<float>(SCREEN_HEIGHT);
if (c.y > m_worldmap_sector.get_height() - static_cast<float>(SCREEN_HEIGHT)) {
c.y = m_worldmap_sector.get_height() - static_cast<float>(SCREEN_HEIGHT);
}

if (worldmap_sector.get_width() < static_cast<float>(SCREEN_WIDTH)) {
c.x = (worldmap_sector.get_width() - static_cast<float>(SCREEN_WIDTH)) / 2.0f;
if (m_worldmap_sector.get_width() < static_cast<float>(SCREEN_WIDTH)) {
c.x = (m_worldmap_sector.get_width() - static_cast<float>(SCREEN_WIDTH)) / 2.0f;
}

if (worldmap_sector.get_height() < static_cast<float>(SCREEN_HEIGHT)) {
c.y = (worldmap_sector.get_height() - static_cast<float>(SCREEN_HEIGHT)) / 2.0f;
if (m_worldmap_sector.get_height() < static_cast<float>(SCREEN_HEIGHT)) {
c.y = (m_worldmap_sector.get_height() - static_cast<float>(SCREEN_HEIGHT)) / 2.0f;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/worldmap/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

namespace worldmap {

class WorldMapSector;

class Camera
{
public:
Camera();
explicit Camera(WorldMapSector& worldmap_sector);

void update(float dt_sec);

Expand All @@ -39,6 +41,7 @@ class Camera
void clamp_camera_position(Vector& c) const;

private:
WorldMapSector& m_worldmap_sector;
Vector m_camera_offset;

/** variables to track panning to a spawn point */
Expand Down
2 changes: 1 addition & 1 deletion src/worldmap/worldmap_sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ WorldMapSector::current()
WorldMapSector::WorldMapSector(WorldMap& parent) :
Base::Sector("worldmap"),
m_parent(parent),
m_camera(new Camera),
m_camera(new Camera(*this)),
m_tux(&add<Tux>(&parent)),
m_spawnpoints(),
m_initial_fade_tilemap(),
Expand Down

0 comments on commit 8ed63c7

Please sign in to comment.