Skip to content

Commit

Permalink
Restructured files and render hook, more work on recursive connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynan Richards committed Aug 18, 2024
1 parent 77f77cc commit e0a3c8d
Show file tree
Hide file tree
Showing 15 changed files with 3,009 additions and 102 deletions.
5 changes: 3 additions & 2 deletions desktop_version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ set(VVV_SRC
src/Vlogging.c
src/Xoshiro.c
../third_party/physfs/extras/physfsrwops.c
src/solver/Geometry.cpp
src/solver/Heuristic.cpp
src/solver/Numerics.cpp
src/solver/Solver.cpp
src/solver/Terrain.cpp
src/solver/Heuristic.cpp
src/solver/Geometry.cpp
)
if(NOT CUSTOM_LEVEL_SUPPORT STREQUAL "DISABLED")
list(APPEND VVV_SRC src/CustomLevels.cpp)
Expand Down
4 changes: 4 additions & 0 deletions desktop_version/src/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,8 @@ void Graphics::drawtrophytext(void)

void Graphics::drawentities(void)
{
Terrain::AfterTileRenderHook();

const int yoff = map.towermode ? lerp(map.oldypos, map.ypos) : 0;

if (!map.custommode)
Expand Down Expand Up @@ -3328,6 +3330,8 @@ void Graphics::render(void)

void Graphics::renderwithscreeneffects(void)
{
Terrain::AfterRenderHook();

if (game.flashlight > 0 && !game.noflashingmode)
{
flashlight();
Expand Down
2 changes: 2 additions & 0 deletions desktop_version/src/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Textbox.h"
#include "TowerBG.h"

#include "solver/Terrain.h"

enum FadeBars
{
FADE_NONE,
Expand Down
7 changes: 0 additions & 7 deletions desktop_version/src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "UtilityClass.h"
#include "VFormat.h"

#include "solver/Terrain.h"

static int tr;
static int tg;
static int tb;
Expand Down Expand Up @@ -1914,8 +1912,6 @@ void gamerender(void)
graphics.set_render_target(graphics.gameplayTexture);
graphics.set_color(0, 0, 0, 255);

Terrain::BeforeRenderHook();

if(!game.blackout)
{
if (map.towermode)
Expand Down Expand Up @@ -1950,8 +1946,6 @@ void gamerender(void)
}
}

Terrain::AfterTileRenderHook();

graphics.drawentities();
if (map.towermode)
{
Expand Down Expand Up @@ -2334,7 +2328,6 @@ void gamerender(void)
graphics.drawtrophytext();
}

Terrain::AfterRenderHook();
graphics.renderwithscreeneffects();
}

Expand Down
18 changes: 18 additions & 0 deletions desktop_version/src/solver/Constants.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SOLVER_CONSTANTS_H
#define SOLVER_CONSTANTS_H

#include "solver/Geometry.h"

#define VIRIDIAN_CX (6)
#define VIRIDIAN_CY (2)
#define VIRIDIAN_W (12)
Expand All @@ -11,6 +13,22 @@
#define MAX_X_SPEED (6)
#define MAX_Y_SPEED (10)

#define FULL_X_SPEED_RANGE (FloatInterval(-MAX_X_SPEED, MAX_X_SPEED))
#define POS_X_SPEED_RANGE (FloatInterval(0.0f, MAX_X_SPEED))
#define NEG_X_SPEED_RANGE (FloatInterval(-MAX_X_SPEED, 0.0f))

#define FULL_Y_SPEED_RANGE (FloatInterval(-MAX_Y_SPEED, MAX_Y_SPEED))
#define POS_Y_SPEED_RANGE (FloatInterval(0.0f, MAX_Y_SPEED))
#define NEG_Y_SPEED_RANGE (FloatInterval(-MAX_Y_SPEED, 0.0f))
#define Y_SPEED_RANGE_FOR_GRAVITY(inverseGravity) (inverseGravity ? NEG_Y_SPEED_RANGE : POS_Y_SPEED_RANGE)

#define PLATFORM_Y_SPEED_RANGE_FOR_GRAVITY(inverseGravity) (inverseGravity ? 0.0f : FloatInterval(0.0f, 0.75f))

#define MAX_SPEED_VECTOR (IntVector(MAX_X_SPEED, MAX_Y_SPEED));

#define X_RATE (1.1f)
#define Y_RATE (0.25f)

#define TOWER_RX (9)

#define RENDER_OFFSET_X (11)
Expand Down
40 changes: 40 additions & 0 deletions desktop_version/src/solver/Exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef SOLVER_EXCEPTIONS_H
#define SOLVER_EXCEPTIONS_H

#include <SDL.h>

#include "Exit.h"

namespace Exceptions {
static inline SDL_NORETURN void unimplemented(void) {
VVV_exit(-1);
}
static inline SDL_NORETURN void todo(void) {
VVV_exit(-1);
}

static inline SDL_NORETURN void error(void) {
VVV_exit(1);
}
static inline SDL_NORETURN void invalid_argument(void) {
VVV_exit(2);
}
static inline SDL_NORETURN void inadmissible_heuristic(void) {
VVV_exit(10);
}
static inline void require(bool condition) {
if (!condition) {
invalid_argument();
}
}
static inline void assert(bool condition) {
if (!condition) {
VVV_exit(3);
}
}
static inline void unreachable(void) {
assert(false);
}
}

#endif /* SOLVER_EXCEPTIONS_H */
15 changes: 14 additions & 1 deletion desktop_version/src/solver/Geometry.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Geometry.h"
#include "solver/Geometry.h"

namespace Geometry {
IntInterval IntInterval::join(const IntInterval& a, const IntInterval& b) {
Expand Down Expand Up @@ -153,4 +153,17 @@ namespace Geometry {
}
return regularize();
}
FloatInterval FloatInterval::fromIntInterval(const IntInterval& i) {
if (i.is_bottom()) {
return FloatInterval::bottom();
} else if (i.is_top()) {
return FloatInterval::top();
} else if (!i.has_lower_bound()) {
return FloatInterval::fromUpperBound((float) i.getUpperBound());
} else if (!i.has_upper_bound()) {
return FloatInterval::fromLowerBound((float) i.getLowerBound());
} else {
return FloatInterval((float) i.getLowerBound(), (float) i.getUpperBound());
}
}
}
100 changes: 100 additions & 0 deletions desktop_version/src/solver/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <SDL.h>

#include "solver/Numerics.h"

namespace Geometry {
static int saturatingNegate(int x) {
switch (x) {
Expand Down Expand Up @@ -251,6 +253,13 @@ namespace Geometry {
bool contains(int val) const;
bool contains(const IntInterval& other) const;

int getUpperBound(void) const {
return max;
}
int getLowerBound(void) const {
return min;
}

IntInterval& negate(void) {
if (!this->is_bottom()) {
int oldMax = max;
Expand Down Expand Up @@ -468,10 +477,37 @@ namespace Geometry {
min = SDL_max(min, limit);
return regularize();
}
IntInterval& removeUpperBound(void) {
if (!is_bottom()) {
max = INT_MAX;
}
return regularize();
}
IntInterval& removeLowerBound(void) {
if (!is_bottom()) {
min = -INT_MAX;
}
return regularize();
}
IntInterval& join(const IntInterval& other);
IntInterval& intersect(const IntInterval& other);
IntInterval& difference(const IntInterval& other);

IntInterval getIntervalAbove(void) const {
if (has_upper_bound()) {
return IntInterval::fromLowerBound(max + 1);
} else {
return IntInterval::bottom();
}
}
IntInterval getIntervalBelow(void) const {
if (has_lower_bound()) {
return IntInterval::fromUpperBound(min - 1);
} else {
return IntInterval::bottom();
}
}

static IntInterval bottom(void) {
return IntInterval(INT_MAX, INT_MIN);
}
Expand Down Expand Up @@ -572,6 +608,22 @@ namespace Geometry {
y.addLowerBound(limit);
return regularize();
}
Region& removeXUpperBound(void) {
x.removeUpperBound();
return regularize();
}
Region& removeXLowerBound(void) {
x.removeUpperBound();
return regularize();
}
Region& removeYUpperBound(void) {
y.removeUpperBound();
return regularize();
}
Region& removeYLowerBound(void) {
y.removeLowerBound();
return regularize();
}
Region& join(const Region& other);
Region& intersect(const Region& other);
Region& difference(const Region& other);
Expand Down Expand Up @@ -619,6 +671,11 @@ namespace Geometry {
max = INFINITY;
return *this;
}
FloatInterval& make_exact(float val) {
min = val;
max = val;
return regularize();
}
FloatInterval& regularize(void) {
if (this->is_bottom()) {
return this->make_bottom();
Expand Down Expand Up @@ -789,6 +846,24 @@ namespace Geometry {
}
}

float getUpperBound(void) const {
if (is_bottom()) {
return -INFINITY;
} else if (!has_upper_bound()) {
return INFINITY;
} else {
return max;
}
}
float getLowerBound(void) const {
if (is_bottom()) {
return INFINITY;
} else if (!has_lower_bound()) {
return -INFINITY;
} else {
return min;
}
}

FloatInterval abs(void) const {
if (this->is_bottom()) {
Expand All @@ -811,6 +886,30 @@ namespace Geometry {
result.intersect(*this);
return result;
}
void splitAt(FloatInterval& above, FloatInterval& below, float bound, bool boundIsIncludedAbove) const {
above.make_top();
above.addUpperBound(getUpperBound());
above.addLowerBound(boundIsIncludedAbove ? bound : Numerics::next_float_above(bound));

below.make_top();
below.addUpperBound(boundIsIncludedAbove ? Numerics::next_float_below(bound) : bound);
below.addLowerBound(getLowerBound());
}

FloatInterval getIntervalBelow(void) const {
if (is_bottom() || !has_lower_bound()) {
return FloatInterval::bottom();
} else {
return FloatInterval::fromUpperBound(Numerics::next_float_below(getLowerBound()));
}
}
FloatInterval getIntervalAbove(void) const {
if (is_bottom() || !has_upper_bound()) {
return FloatInterval::bottom();
} else {
return FloatInterval::fromLowerBound(Numerics::next_float_above(getUpperBound()));
}
}


FloatInterval& clamp(FloatInterval interval) {
Expand Down Expand Up @@ -860,6 +959,7 @@ namespace Geometry {

static FloatInterval join(const FloatInterval& a, const FloatInterval& b);
static FloatInterval intersect(const FloatInterval& a, const FloatInterval& b);
static FloatInterval fromIntInterval(const IntInterval& a);
};
}

Expand Down
9 changes: 1 addition & 8 deletions desktop_version/src/solver/Heuristic.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#include "Heuristic.h"

#include "solver/Constants.h"

#include <SDL.h>
#include "Exit.h"
#include "solver/Heuristic.h"

namespace Heuristic {
int basic_heuristic(int dx, int dy) {
int x_frames = (SDL_abs(dx) + MAX_X_SPEED - 1) / MAX_X_SPEED;
int y_frames = (SDL_abs(dy) + MAX_Y_SPEED - 1) / MAX_Y_SPEED;
return SDL_max(x_frames, y_frames);
}


}
2 changes: 2 additions & 0 deletions desktop_version/src/solver/Heuristic.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SOLVER_HEURISTIC_H
#define SOLVER_HEURISTIC_H

#include <SDL.h>

#include "solver/Constants.h"

namespace Heuristic {
Expand Down
Loading

0 comments on commit e0a3c8d

Please sign in to comment.