Skip to content

Commit 0ff4ddb

Browse files
committed
Add vorticity view. Lua bindings for vorticity.
1 parent 70f5239 commit 0ff4ddb

9 files changed

Lines changed: 54 additions & 19 deletions

File tree

src/graphics/Graphics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool inve
435435
BlendChar({ x + 1, y + 1 }, 0xE055, 0x37FF37_rgb .WithAlpha(alpha));
436436
}
437437
break;
438+
case IconVort:
439+
if(invert)
440+
BlendChar({ x + 1, y + 1 }, 0xE054, 0xA64D79_rgb .WithAlpha(alpha));
441+
else
442+
BlendChar({ x + 1, y + 1 }, 0xE054, 0xC27BA0_rgb .WithAlpha(alpha));
443+
break;
438444
default:
439445
if(invert)
440446
BlendChar({ x, y }, 't', 0x000000_rgb .WithAlpha(alpha));

src/graphics/Icons.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ enum Icon
3838
IconPersistant,
3939
IconHeat,
4040
IconLife,
41-
IconGradient
41+
IconGradient,
42+
IconVort
4243
};

src/graphics/Renderer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,14 @@ void Renderer::draw_air()
988988
c = RGB(r, g, b);
989989
}
990990
}
991+
else if (displayMode & DISPLAY_AIRW)
992+
{
993+
auto w = 4*Air::vorticity(*sim, y, x);
994+
if (w > 0.0f)
995+
c = RGB(clamp_flt(w, 0.0f, 8.0f), 0, 0); //positive vorticity is red
996+
else
997+
c = RGB(0, 0, clamp_flt(-w, 0.0f, 8.0f)); //negative vorticity is blue
998+
}
991999
if (findingElement)
9921000
{
9931001
c.Red /= 10;

src/gui/render/RenderView.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ RenderView::RenderView():
9191
addDisplayModeCheckbox(DISPLAY_AIRP, IconPressure , ui::Point(135, 22), "Displays pressure, red is positive and blue is negative");
9292
addDisplayModeCheckbox(DISPLAY_AIRV, IconVelocity , ui::Point(167, 4), "Displays velocity and positive pressure: up/down adds blue, right/left adds red, still pressure adds green");
9393
addDisplayModeCheckbox(DISPLAY_AIRH, IconHeat , ui::Point(167, 22), "Displays the temperature of the air like heat display does");
94-
line2 = 200;
95-
addDisplayModeCheckbox(DISPLAY_WARP, IconWarp , ui::Point(205, 22), "Gravity lensing, Newtonian Gravity bends light with this on");
96-
addDisplayModeCheckbox(DISPLAY_EFFE, IconEffect , ui::Point(205, 4), "Enables moving solids, stickmen guns, and premium(tm) graphics");
97-
addDisplayModeCheckbox(DISPLAY_PERS, IconPersistant, ui::Point(237, 4), "Element paths persist on the screen for a while");
98-
line3 = 270;
94+
addDisplayModeCheckbox(DISPLAY_AIRW, IconVort , ui::Point(199, 4), "Displays vorticity, red is clockwise and blue is anticlockwise");
95+
line2 = 232;
96+
addDisplayModeCheckbox(DISPLAY_WARP, IconWarp , ui::Point(237, 22), "Gravity lensing, Newtonian Gravity bends light with this on");
97+
addDisplayModeCheckbox(DISPLAY_EFFE, IconEffect , ui::Point(237, 4), "Enables moving solids, stickmen guns, and premium(tm) graphics");
98+
addDisplayModeCheckbox(DISPLAY_PERS, IconPersistant, ui::Point(269, 4), "Element paths persist on the screen for a while");
99+
line3 = 302;
99100

100101
auto addColourModeCheckbox = [this](unsigned int mode, Icon icon, ui::Point offset, String tooltip) {
101102
auto *colourModeCheckbox = new ModeCheckbox(ui::Point(0, YRES) + offset, ui::Point(30, 16), "", tooltip);
@@ -117,11 +118,11 @@ RenderView::RenderView():
117118
} });
118119
AddComponent(colourModeCheckbox);
119120
};
120-
addColourModeCheckbox(COLOUR_HEAT, IconHeat , ui::Point(275, 4), "Displays temperatures of the elements, dark blue is coldest, pink is hottest");
121-
addColourModeCheckbox(COLOUR_LIFE, IconLife , ui::Point(275, 22), "Displays the life value of elements in greyscale gradients");
122-
addColourModeCheckbox(COLOUR_GRAD, IconGradient, ui::Point(307, 22), "Changes colors of elements slightly to show heat diffusing through them");
123-
addColourModeCheckbox(COLOUR_BASC, IconBasic , ui::Point(307, 4), "No special effects at all for anything, overrides all other options and deco");
124-
line4 = 340;
121+
addColourModeCheckbox(COLOUR_HEAT, IconHeat , ui::Point(307, 4), "Displays temperatures of the elements, dark blue is coldest, pink is hottest");
122+
addColourModeCheckbox(COLOUR_LIFE, IconLife , ui::Point(307, 22), "Displays the life value of elements in greyscale gradients");
123+
addColourModeCheckbox(COLOUR_GRAD, IconGradient, ui::Point(339, 22), "Changes colors of elements slightly to show heat diffusing through them");
124+
addColourModeCheckbox(COLOUR_BASC, IconBasic , ui::Point(339, 4), "No special effects at all for anything, overrides all other options and deco");
125+
line4 = 372;
125126
}
126127

127128
uint32_t RenderView::CalculateRenderMode()

src/lua/LuaRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void LuaRenderer::Open(lua_State *L)
370370
LCONST(DISPLAY_WARP);
371371
LCONST(DISPLAY_PERS);
372372
LCONST(DISPLAY_EFFE);
373+
LCONST(DISPLAY_AIRW);
373374
#undef LCONST
374375
lua_pushvalue(L, -1);
375376
lua_setglobal(L, "renderer");

src/lua/LuaSimulation.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,21 @@ static int ambientAirTemp(lua_State *L)
12751275
return 0;
12761276
}
12771277

1278+
static int vorticityCoeff(lua_State *L)
1279+
{
1280+
auto *lsi = GetLSI();
1281+
int acount = lua_gettop(L);
1282+
if (acount == 0)
1283+
{
1284+
lua_pushnumber(L, lsi->sim->air->vorticityCoeff);
1285+
return 1;
1286+
}
1287+
lsi->AssertInterfaceEvent();
1288+
float vorticityCoeff = restrict_flt(luaL_optnumber(L, 1, 0.0f), 0.0f, 1.0f);
1289+
lsi->gameModel->SetVorticityCoeff(vorticityCoeff);
1290+
return 0;
1291+
}
1292+
12781293
static int elementCount(lua_State *L)
12791294
{
12801295
int element = luaL_optint(L, 1, 0);
@@ -2013,6 +2028,7 @@ void LuaSimulation::Open(lua_State *L)
20132028
LFUNC(airMode),
20142029
LFUNC(waterEqualization),
20152030
LFUNC(ambientAirTemp),
2031+
LFUNC(vorticityCoeff),
20162032
LFUNC(elementCount),
20172033
LFUNC(canMove),
20182034
LFUNC(brush),

src/simulation/Air.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ void Air::make_kernel(void) //used for velocity
2727
}
2828

2929

30-
float Air::vorticity(int y, int x)
30+
float Air::vorticity(const RenderableSimulation & sm, int y, int x)
3131
{
32-
auto &vx = sim.vx;
33-
auto &vy = sim.vy;
32+
auto &vx = sm.vx;
33+
auto &vy = sm.vy;
3434

3535
if (x > 1 && x < XCELLS-2 && y > 1 && y < YCELLS-2)
3636
{
@@ -391,10 +391,10 @@ void Air::update_air(void)
391391
//Vorticity confinement
392392
if (vorticityCoeff > 0.0f && x > 1 && x < XCELLS-2 && y > 1 && y < YCELLS-2)
393393
{
394-
auto dwx = (vorticity(y, x+1) - vorticity(y, x-1))*0.5f;
395-
auto dwy = (vorticity(y+1, x) - vorticity(y-1, x))*0.5f;
394+
auto dwx = (vorticity(sim, y, x+1) - vorticity(sim, y, x-1))*0.5f;
395+
auto dwy = (vorticity(sim, y+1, x) - vorticity(sim, y-1, x))*0.5f;
396396
auto norm = std::sqrt(dwx*dwx + dwy*dwy);
397-
auto w = vorticity(y, x);
397+
auto w = vorticity(sim, y, x);
398398

399399
dx += vorticityCoeff * dwx / (norm + 0.001f) * w;
400400
dy += vorticityCoeff * dwy / (norm + 0.001f) * w;

src/simulation/Air.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "SimulationConfig.h"
33

44
class Simulation;
5+
class RenderableSimulation;
56

67
class Air
78
{
@@ -18,7 +19,7 @@ class Air
1819
unsigned char bmap_blockairh[YCELLS][XCELLS];
1920
float kernel[9];
2021
void make_kernel(void);
21-
float vorticity(int y, int x);
22+
static float vorticity(const RenderableSimulation & sm, int y, int x);
2223
void update_airh(void);
2324
void update_air(void);
2425
void Clear();

src/simulation/ElementGraphics.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ constexpr auto DISPLAY_AIRC = UINT32_C(0x00000001);
4949
constexpr auto DISPLAY_AIRP = UINT32_C(0x00000002);
5050
constexpr auto DISPLAY_AIRV = UINT32_C(0x00000004);
5151
constexpr auto DISPLAY_AIRH = UINT32_C(0x00000008);
52-
constexpr auto DISPLAY_AIR = UINT32_C(0x0000000F);
52+
constexpr auto DISPLAY_AIR = UINT32_C(0x0000008F); // 'or' of all air modes
5353
constexpr auto DISPLAY_WARP = UINT32_C(0x00000010);
5454
constexpr auto DISPLAY_PERS = UINT32_C(0x00000020);
5555
constexpr auto DISPLAY_EFFE = UINT32_C(0x00000040);
56+
constexpr auto DISPLAY_AIRW = UINT32_C(0x00000080);

0 commit comments

Comments
 (0)