Skip to content

Commit

Permalink
why am I spending so much effort on this lol
Browse files Browse the repository at this point in the history
  • Loading branch information
MjnMixael committed Sep 7, 2024
1 parent 7511988 commit 961f129
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
7 changes: 6 additions & 1 deletion code/graphics/2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ void gr_set_shader(shader *shade)
}

// new bitmap functions
void gr_bitmap(int _x, int _y, int resize_mode)
void gr_bitmap(int _x, int _y, int resize_mode, float scale_factor)
{
GR_DEBUG_SCOPE("2D Bitmap");

Expand All @@ -1910,6 +1910,11 @@ void gr_bitmap(int _x, int _y, int resize_mode)

bm_get_info(gr_screen.current_bitmap, &_w, &_h, NULL, NULL, NULL);

if (scale_factor != 1.0f) {
_w = static_cast<int>(_w * scale_factor);
_h = static_cast<int>(_h * scale_factor);
}

x = i2fl(_x);
y = i2fl(_y);
w = i2fl(_w);
Expand Down
2 changes: 1 addition & 1 deletion code/graphics/2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ void gr_create_shader(shader *shade, ubyte r, ubyte g, ubyte b, ubyte c);
void gr_set_shader(shader *shade);

// new bitmap functions
void gr_bitmap(int x, int y, int resize_mode = GR_RESIZE_FULL);
void gr_bitmap(int x, int y, int resize_mode = GR_RESIZE_FULL, float scale_factor = 1.0f);
void gr_bitmap_uv(int _x, int _y, int _w, int _h, float _u0, float _v0, float _u1, float _v1, int resize_mode = GR_RESIZE_FULL);

// special function for drawing polylines. this function is specifically intended for
Expand Down
6 changes: 3 additions & 3 deletions code/graphics/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void generic_anim_render_variable_frame_delay(generic_anim* ga, float frametime,
* @param [in] y 2D screen y co-ordinate to render at
* @param [in] menu select if this is rendered in menu screen, or fullscreen
*/
void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool menu, const generic_extras *ge)
void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool menu, const generic_extras *ge, float scale_factor)
{
if ((ge != nullptr) && (ga->use_hud_color == true)) {
Warning(LOCATION, "Monochrome generic anims can't use extra info (yet)");
Expand All @@ -719,11 +719,11 @@ void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool m
ga->previous_frame = ga->current_frame;

if(ga->use_hud_color) {
gr_aabitmap(x, y, (menu ? GR_RESIZE_MENU : GR_RESIZE_FULL));
gr_aabitmap(x, y, (menu ? GR_RESIZE_MENU : GR_RESIZE_FULL), false, scale_factor);
}
else {
if (ge == nullptr) {
gr_bitmap(x, y, (menu ? GR_RESIZE_MENU : GR_RESIZE_FULL));
gr_bitmap(x, y, (menu ? GR_RESIZE_MENU : GR_RESIZE_FULL), scale_factor);
}
else if (ge->draw == true) {
// currently only for lua streaminganim objects
Expand Down
2 changes: 1 addition & 1 deletion code/graphics/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int generic_anim_load(generic_anim *ga);
int generic_anim_stream(generic_anim *ga, const bool cache = true);
int generic_bitmap_load(generic_bitmap *gb);
void generic_anim_unload(generic_anim *ga);
void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool menu = false, const generic_extras *ge = nullptr);
void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool menu = false, const generic_extras *ge = nullptr, float scale_factor = 1.0f);
void generic_anim_bitmap_set(generic_anim* ga, float frametime, const generic_extras* ge = nullptr);
void generic_anim_reset(generic_anim *ga);
#endif
76 changes: 65 additions & 11 deletions code/menuui/fishtank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
typedef struct fish {
float x, y; // x and y coords
float x_speed, y_speed; // x and y speed
float scale; // big fish or small fish?
bool left; // left or right
generic_anim anim; // the animation
bool onscreen; // visible?
bool swimming; // whee
} fish;

constexpr int MAX_FISH = 24; // was 12.. bigger screens need more fish!
constexpr size_t MAX_FISH = 24; // was 12.. bigger screens need more fish!
SCP_vector<fish> All_fish;

// fish anim names
Expand All @@ -51,7 +52,7 @@ void fish_generate()
fish* f = &(*it);

// Pick a direction randomly
f->left = frand_range(0.0f, 1.0f) < 0.5f ? false : true;
f->left = frand_range(0.0f, 1.0f) >= 0.5f;

// Let it freeeeeeee!
f->swimming = true;
Expand All @@ -75,6 +76,9 @@ void fish_generate()
}
}

// Pick a scale
f->scale = frand_range(0.5f, 1.0f);

// Pick a starting location
if(f->left){
f->x = gr_screen.max_w_unscaled_zoomed + frand_range(0.0f, 50.0f);
Expand Down Expand Up @@ -189,16 +193,50 @@ void fishtank_stop()
Fish_inited = 0;
}

void fishtank_change_speed(float& speed, float increase, float decrease, float multiplier)
{
float speed_modifier = (frand_range(0.0f, 1.0f) < 0.5f) ? increase : decrease;
float min = 5.0f * multiplier;
float max = 20.0f * multiplier;

// Positive speed
if (speed > 0.0f) {
if ((speed < min && speed_modifier == decrease) || (speed > max && speed_modifier == increase)) {
speed_modifier = 1.0f;
}
// Negative speed
} else {
if ((speed > -min && speed_modifier == decrease) || (speed < -max && speed_modifier == increase)) {
speed_modifier = 1.0f;
}
}

speed = speed * speed_modifier;
}

void fishtank_process()
{
if(!Fish_inited){
return;
}

// Small chance to add a fish
if (All_fish.size() < MAX_FISH) {
if (frand_range(0.0f, 1.0f) < 0.0005f) {
fish new_fish;
new_fish.swimming = false;
All_fish.push_back(new_fish);
fish_generate();
}
}

// Process all fish
for (fish& f : All_fish) {
for (auto it = All_fish.begin(); it != All_fish.end();) {
fish& f = *it;

// Not swimming?
if (!f.swimming) {
++it;
continue;
}

Expand All @@ -207,7 +245,16 @@ void fishtank_process()
f.y_speed *= -1;
}

// Move it along according to it's speed settings
// Small chance to slightly change speed
if (frand_range(0.0f, 1.0f) < 0.001f) {
if (frand_range(0.0f, 1.0f) < 0.5f) {
fishtank_change_speed(f.x_speed, 1.7f, 0.5f, gr_screen.max_w / 1024.0f);
} else {
fishtank_change_speed(f.y_speed, 1.1f, 0.9f, gr_screen.max_h / 786.0f);
}
}

// Move it along according to its speed settings
f.x += f.x_speed * flFrametime;
f.y += f.y_speed * flFrametime;

Expand All @@ -218,20 +265,27 @@ void fishtank_process()
onscreen = true;
}

// If it was onscreen before, but is no longer, flush it (down the toilet?!) and make a new fish
// If it was onscreen before but is no longer, yeet it or flush it
if (f.onscreen && !onscreen) {
fish_flush(&f);

fish_generate();
// Small chance to yeet the fish instead of flushing it. I didn't come up with this language. Don't ask me.
if (frand_range(0.0f, 1.0f) < 0.3f) {
it = All_fish.erase(it);
} else {
fish_flush(&f); // Flush the fish and keep it in the pool. How does that make sense?
fish_generate();
++it;
}
continue;
}

// Otherwise just mark its current status
// Otherwise, just mark its current status
f.onscreen = onscreen;

// Render the fishy!
// Render the fish if it's onscreen
if (f.onscreen) {
generic_anim_render(&f.anim, flFrametime, (int)f.x, (int)f.y);
generic_anim_render(&f.anim, flFrametime, (int)f.x, (int)f.y, false, nullptr, f.scale);
}

++it;
}
}

0 comments on commit 961f129

Please sign in to comment.