Get rid of render and display mode arrays

These were arrays because that made them easy to compose, but that's a UI task, it makes no sense to propagate them internally. That said, RenderView is still confusing because it still has checkboxes that control multiple bits of render mode and display mode at once; I'm not dealing with that for now.

The game now prefers the item-type preferences Renderer.RenderMode and Renderer.DisplayMode over the array-type preferences Renderer.RenderModes and Renderer.DisplayModes. It'll preserve the old ones for compatibility if found and derive the new ones from them. The corresponding Lua functions are now deprecated and will just return single-item arrays from now; the similarly named replacements operate with integers.
This commit is contained in:
Tamás Bálint Misius
2024-07-11 08:06:58 +02:00
parent 6e01699a7f
commit 4ed83912af
14 changed files with 257 additions and 361 deletions

View File

@@ -16,7 +16,7 @@ void Renderer::RenderSimulation()
DrawWalls();
render_parts();
if (display_mode & DISPLAY_PERS)
if (displayMode & DISPLAY_PERS)
{
std::transform(video.RowIterator({ 0, 0 }), video.RowIterator({ 0, YRES }), persistentVideo.begin(), [](pixel p) {
return RGB<uint8_t>::Unpack(p).Decay().Pack();
@@ -28,7 +28,7 @@ void Renderer::RenderSimulation()
draw_grav_zones();
DrawSigns();
if (display_mode & DISPLAY_WARP)
if (displayMode & DISPLAY_WARP)
{
warpVideo = video;
std::fill_n(video.data(), WINDOWW * YRES, 0);
@@ -297,7 +297,7 @@ void Renderer::render_parts()
fireg = graphicscache[t].fireg;
fireb = graphicscache[t].fireb;
}
else if(!(colour_mode & COLOUR_BASC))
else if(!(colorMode & COLOUR_BASC))
{
auto *graphics = elements[t].Graphics;
auto makeReady = !graphics || graphics(gfctx, &(sim->parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb); //That's a lot of args, a struct might be better
@@ -326,21 +326,21 @@ void Renderer::render_parts()
colb += int(sin(gradv*caddress*2.22 +TPT_PI_DBL) * 64);
}
if((pixel_mode & FIRE_ADD) && !(render_mode & FIRE_ADD))
if((pixel_mode & FIRE_ADD) && !(renderMode & FIRE_ADD))
pixel_mode |= PMODE_GLOW;
if((pixel_mode & FIRE_BLEND) && !(render_mode & FIRE_BLEND))
if((pixel_mode & FIRE_BLEND) && !(renderMode & FIRE_BLEND))
pixel_mode |= PMODE_BLUR;
if((pixel_mode & PMODE_BLUR) && !(render_mode & PMODE_BLUR))
if((pixel_mode & PMODE_BLUR) && !(renderMode & PMODE_BLUR))
pixel_mode |= PMODE_FLAT;
if((pixel_mode & PMODE_GLOW) && !(render_mode & PMODE_GLOW))
if((pixel_mode & PMODE_GLOW) && !(renderMode & PMODE_GLOW))
pixel_mode |= PMODE_BLEND;
if (render_mode & PMODE_BLOB)
if (renderMode & PMODE_BLOB)
pixel_mode |= PMODE_BLOB;
pixel_mode &= render_mode;
pixel_mode &= renderMode;
//Alter colour based on display mode
if(colour_mode & COLOUR_HEAT)
if(colorMode & COLOUR_HEAT)
{
constexpr float min_temp = MIN_TEMP;
constexpr float max_temp = MAX_TEMP;
@@ -357,7 +357,7 @@ void Renderer::render_parts()
else if (!pixel_mode)
pixel_mode |= PMODE_FLAT;
}
else if(colour_mode & COLOUR_LIFE)
else if(colorMode & COLOUR_LIFE)
{
auto gradv = 0.4f;
if (!(sim->parts[i].life<5))
@@ -373,7 +373,7 @@ void Renderer::render_parts()
else if (!pixel_mode)
pixel_mode |= PMODE_FLAT;
}
else if(colour_mode & COLOUR_BASC)
else if(colorMode & COLOUR_BASC)
{
colr = colour.Red;
colg = colour.Green;
@@ -382,7 +382,7 @@ void Renderer::render_parts()
}
//Apply decoration colour
if(!(colour_mode & ~COLOUR_GRAD) && decorations_enable && deca)
if(!(colorMode & ~COLOUR_GRAD) && decorations_enable && deca)
{
deca++;
if(!(pixel_mode & NO_DECO))
@@ -400,7 +400,7 @@ void Renderer::render_parts()
}
}
if (colour_mode & COLOUR_GRAD)
if (colorMode & COLOUR_GRAD)
{
auto frequency = 0.05f;
auto q = int(sim->parts[i].temp-40);
@@ -513,7 +513,7 @@ void Renderer::render_parts()
colr = 255;
colg = colb = 0;
}
else if (colour_mode != COLOUR_HEAT)
else if (colorMode != COLOUR_HEAT)
{
if (cplayer->fan)
{
@@ -542,7 +542,7 @@ void Renderer::render_parts()
legr = 255;
legg = legb = 0;
}
else if (colour_mode==COLOUR_HEAT)
else if (colorMode==COLOUR_HEAT)
{
legr = colr;
legg = colg;
@@ -776,7 +776,7 @@ void Renderer::render_parts()
AddPixel({ nx+nxo, ny+nyo }, RGBA<uint8_t>(colr, colg, colb, 255-orbd[r]));
}
}
if (pixel_mode & EFFECT_DBGLINES && !(display_mode&DISPLAY_PERS))
if (pixel_mode & EFFECT_DBGLINES && !(displayMode&DISPLAY_PERS))
{
// draw lines connecting wifi/portal channels
if (mousePos.X == nx && mousePos.Y == ny && i == ID(sim->pmap[ny][nx]) && debugLines)
@@ -841,7 +841,7 @@ void Renderer::draw_other() // EMP effect
int emp_decor = sim->emp_decor;
if (emp_decor>40) emp_decor = 40;
if (emp_decor<0) emp_decor = 0;
if (!(render_mode & EFFECT)) // not in nothing mode
if (!(renderMode & EFFECT)) // not in nothing mode
return;
if (emp_decor>0)
{
@@ -906,9 +906,9 @@ void Renderer::draw_grav()
void Renderer::draw_air()
{
if(!sim->aheat_enable && (display_mode & DISPLAY_AIRH))
if(!sim->aheat_enable && (displayMode & DISPLAY_AIRH))
return;
if(!(display_mode & DISPLAY_AIR))
if(!(displayMode & DISPLAY_AIR))
return;
int x, y, i, j;
auto *pv = sim->pv;
@@ -919,27 +919,27 @@ void Renderer::draw_air()
for (y=0; y<YCELLS; y++)
for (x=0; x<XCELLS; x++)
{
if (display_mode & DISPLAY_AIRP)
if (displayMode & DISPLAY_AIRP)
{
if (pv[y][x] > 0.0f)
c = RGB<uint8_t>(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red!
else
c = RGB<uint8_t>(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue!
}
else if (display_mode & DISPLAY_AIRV)
else if (displayMode & DISPLAY_AIRV)
{
c = RGB<uint8_t>(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red
clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green
clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue
}
else if (display_mode & DISPLAY_AIRH)
else if (displayMode & DISPLAY_AIRH)
{
c = RGB<uint8_t>::Unpack(HeatToColour(hv[y][x]));
//c = RGB<uint8_t>(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red
// clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green
// clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f)).Pack();//vy adds blue
}
else if (display_mode & DISPLAY_AIRC)
else if (displayMode & DISPLAY_AIRC)
{
int r;
int g;
@@ -1133,7 +1133,7 @@ void Renderer::DrawWalls()
}
// when in blob view, draw some blobs...
if (render_mode & PMODE_BLOB)
if (renderMode & PMODE_BLOB)
{
switch (wtypes[wt].drawstyle)
{
@@ -1240,7 +1240,7 @@ void Renderer::DrawWalls()
void Renderer::render_fire()
{
if(!(render_mode & FIREMODE))
if(!(renderMode & FIREMODE))
return;
int i,j,x,y,r,g,b,a;
for (j=0; j<YCELLS; j++)

View File

@@ -5,13 +5,14 @@
#include "common/tpt-rand.h"
#include "SimulationConfig.h"
#include "FindingElement.h"
#include <cstdint>
#include <optional>
#include <array>
#include <memory>
#include <mutex>
#include <vector>
class RenderPreset;
struct RenderPreset;
struct RenderableSimulation;
class Renderer;
struct Particle;
@@ -57,11 +58,9 @@ public:
RNG rng;
const RenderableSimulation *sim = nullptr;
std::vector<unsigned int> render_modes;
unsigned int render_mode;
unsigned int colour_mode;
std::vector<unsigned int> display_modes;
unsigned int display_mode;
uint32_t renderMode = 0;
uint32_t colorMode = 0;
uint32_t displayMode = 0;
std::vector<RenderPreset> renderModePresets;
//
unsigned char fire_r[YCELLS][XCELLS];
@@ -120,18 +119,12 @@ public:
pixel GetPixel(Vec2<int> pos) const;
//...
//Display mode modifiers
void CompileDisplayMode();
void CompileRenderMode();
void AddRenderMode(unsigned int mode);
void SetRenderMode(std::vector<unsigned int> render);
std::vector<unsigned int> GetRenderMode();
void RemoveRenderMode(unsigned int mode);
void AddDisplayMode(unsigned int mode);
void RemoveDisplayMode(unsigned int mode);
void SetDisplayMode(std::vector<unsigned int> display);
std::vector<unsigned int> GetDisplayMode();
void SetColourMode(unsigned int mode);
unsigned int GetColourMode();
void SetRenderMode(uint32_t newRenderMode);
uint32_t GetRenderMode();
void SetDisplayMode(uint32_t newDisplayMode);
uint32_t GetDisplayMode();
void SetColorMode(uint32_t newColorMode);
uint32_t GetColorMode();
void ResetModes();

View File

@@ -16,7 +16,7 @@ void Renderer::SetSample(Vec2<int> pos)
}
void Renderer::clearScreen() {
if(display_mode & DISPLAY_PERS)
if(displayMode & DISPLAY_PERS)
{
std::copy(persistentVideo.begin(), persistentVideo.end(), video.RowIterator({ 0, 0 }));
}
@@ -163,9 +163,6 @@ void Renderer::PopulateTables()
}
Renderer::Renderer():
render_mode(0),
colour_mode(0),
display_mode(0),
gravityZonesEnabled(false),
gravityFieldEnabled(false),
decorations_enable(1),
@@ -193,88 +190,74 @@ Renderer::Renderer():
//Render mode presets. Possibly load from config in future?
renderModePresets.push_back({
"Alternative Velocity Display",
{ RENDER_EFFE, RENDER_BASC },
{ DISPLAY_AIRC },
0
RENDER_EFFE | RENDER_BASC,
DISPLAY_AIRC,
0,
});
renderModePresets.push_back({
"Velocity Display",
{ RENDER_EFFE, RENDER_BASC },
{ DISPLAY_AIRV },
0
RENDER_EFFE | RENDER_BASC,
DISPLAY_AIRV,
0,
});
renderModePresets.push_back({
"Pressure Display",
{ RENDER_EFFE, RENDER_BASC },
{ DISPLAY_AIRP },
0
RENDER_EFFE | RENDER_BASC,
DISPLAY_AIRP,
0,
});
renderModePresets.push_back({
"Persistent Display",
{ RENDER_EFFE, RENDER_BASC },
{ DISPLAY_PERS },
0
RENDER_EFFE | RENDER_BASC,
DISPLAY_PERS,
0,
});
renderModePresets.push_back({
"Fire Display",
{ RENDER_FIRE, RENDER_SPRK, RENDER_EFFE, RENDER_BASC },
{ },
0
RENDER_FIRE | RENDER_SPRK | RENDER_EFFE | RENDER_BASC,
0,
0,
});
renderModePresets.push_back({
"Blob Display",
{ RENDER_FIRE, RENDER_SPRK, RENDER_EFFE, RENDER_BLOB },
{ },
0
RENDER_FIRE | RENDER_SPRK | RENDER_EFFE | RENDER_BLOB,
0,
0,
});
renderModePresets.push_back({
"Heat Display",
{ RENDER_BASC },
{ DISPLAY_AIRH },
COLOUR_HEAT
RENDER_BASC,
DISPLAY_AIRH,
COLOUR_HEAT,
});
renderModePresets.push_back({
"Fancy Display",
{ RENDER_FIRE, RENDER_SPRK, RENDER_GLOW, RENDER_BLUR, RENDER_EFFE, RENDER_BASC },
{ DISPLAY_WARP },
0
RENDER_FIRE | RENDER_SPRK | RENDER_GLOW | RENDER_BLUR | RENDER_EFFE | RENDER_BASC,
DISPLAY_WARP,
0,
});
renderModePresets.push_back({
"Nothing Display",
{ RENDER_BASC },
{ },
0
RENDER_BASC,
0,
0,
});
renderModePresets.push_back({
"Heat Gradient Display",
{ RENDER_BASC },
{ },
COLOUR_GRAD
RENDER_BASC,
0,
COLOUR_GRAD,
});
renderModePresets.push_back({
"Life Gradient Display",
{ RENDER_BASC },
{ },
COLOUR_LIFE
RENDER_BASC,
0,
COLOUR_LIFE,
});
prepare_alpha(CELL, 1.0f);
}
void Renderer::CompileRenderMode()
{
int old_render_mode = render_mode;
render_mode = 0;
for (size_t i = 0; i < render_modes.size(); i++)
render_mode |= render_modes[i];
//If firemode is removed, clear the fire display
if(!(render_mode & FIREMODE) && (old_render_mode & FIREMODE))
{
ClearAccumulation();
}
}
void Renderer::ClearAccumulation()
{
std::fill(&fire_r[0][0], &fire_r[0][0] + NCELL, 0);
@@ -283,111 +266,51 @@ void Renderer::ClearAccumulation()
std::fill(persistentVideo.begin(), persistentVideo.end(), 0);
}
void Renderer::AddRenderMode(unsigned int mode)
void Renderer::SetRenderMode(uint32_t newRenderMode)
{
for (size_t i = 0; i < render_modes.size(); i++)
{
if(render_modes[i] == mode)
{
return;
}
}
render_modes.push_back(mode);
CompileRenderMode();
}
void Renderer::RemoveRenderMode(unsigned int mode)
{
for (size_t i = 0; i < render_modes.size(); i++)
{
if(render_modes[i] == mode)
{
render_modes.erase(render_modes.begin() + i);
i = 0;
}
}
CompileRenderMode();
}
void Renderer::SetRenderMode(std::vector<unsigned int> render)
{
render_modes = render;
CompileRenderMode();
}
std::vector<unsigned int> Renderer::GetRenderMode()
{
return render_modes;
}
void Renderer::CompileDisplayMode()
{
int old_display_mode = display_mode;
display_mode = 0;
for (size_t i = 0; i < display_modes.size(); i++)
display_mode |= display_modes[i];
if (!(display_mode & DISPLAY_PERS) && (old_display_mode & DISPLAY_PERS))
int oldRenderMode = renderMode;
renderMode = newRenderMode;
if (!(renderMode & FIREMODE) && (oldRenderMode & FIREMODE))
{
ClearAccumulation();
}
}
void Renderer::AddDisplayMode(unsigned int mode)
uint32_t Renderer::GetRenderMode()
{
for (size_t i = 0; i < display_modes.size(); i++)
return renderMode;
}
void Renderer::SetDisplayMode(uint32_t newDisplayMode)
{
int oldDisplayMode = displayMode;
displayMode = newDisplayMode;
if (!(displayMode & DISPLAY_PERS) && (oldDisplayMode & DISPLAY_PERS))
{
if (display_modes[i] == mode)
{
return;
}
if (display_modes[i] & DISPLAY_AIR)
{
display_modes.erase(display_modes.begin()+i);
}
ClearAccumulation();
}
display_modes.push_back(mode);
CompileDisplayMode();
}
void Renderer::RemoveDisplayMode(unsigned int mode)
uint32_t Renderer::GetDisplayMode()
{
for (size_t i = 0; i < display_modes.size(); i++)
{
if (display_modes[i] == mode)
{
display_modes.erase(display_modes.begin() + i);
i = 0;
}
}
CompileDisplayMode();
return displayMode;
}
void Renderer::SetDisplayMode(std::vector<unsigned int> display)
void Renderer::SetColorMode(uint32_t newColorMode)
{
display_modes = display;
CompileDisplayMode();
colorMode = newColorMode;
}
std::vector<unsigned int> Renderer::GetDisplayMode()
uint32_t Renderer::GetColorMode()
{
return display_modes;
}
void Renderer::SetColourMode(unsigned int mode)
{
colour_mode = mode;
}
unsigned int Renderer::GetColourMode()
{
return colour_mode;
return colorMode;
}
void Renderer::ResetModes()
{
SetRenderMode({ RENDER_BASC, RENDER_FIRE, RENDER_SPRK, RENDER_EFFE });
SetDisplayMode({ });
SetColourMode(COLOUR_DEFAULT);
SetRenderMode(RENDER_BASC | RENDER_FIRE | RENDER_SPRK | RENDER_EFFE);
SetDisplayMode(0);
SetColorMode(COLOUR_DEFAULT);
}
VideoBuffer Renderer::DumpFrame()

View File

@@ -853,9 +853,9 @@ void GameController::LoadRenderPreset(int presetNum)
Renderer * renderer = gameModel->GetRenderer();
RenderPreset preset = renderer->renderModePresets[presetNum];
gameModel->SetInfoTip(preset.Name);
renderer->SetRenderMode(preset.RenderModes);
renderer->SetDisplayMode(preset.DisplayModes);
renderer->SetColourMode(preset.ColourMode);
renderer->SetRenderMode(preset.renderMode);
renderer->SetDisplayMode(preset.displayMode);
renderer->SetColorMode(preset.colorMode);
}
void GameController::Update()

View File

@@ -66,29 +66,37 @@ GameModel::GameModel():
std::fill(decoToolset.begin(), decoToolset.end(), nullptr);
std::fill(regularToolset.begin(), regularToolset.end(), nullptr);
//Default render prefs
ren->SetRenderMode({
RENDER_FIRE,
RENDER_EFFE,
RENDER_BASC,
});
ren->SetDisplayMode({});
ren->SetColourMode(0);
//Load config into renderer
auto &prefs = GlobalPrefs::Ref();
ren->SetColourMode(prefs.Get("Renderer.ColourMode", 0U));
auto displayModes = prefs.Get("Renderer.DisplayModes", std::vector<unsigned int>{});
if (displayModes.size())
{
ren->SetDisplayMode(displayModes);
}
auto renderModes = prefs.Get("Renderer.RenderModes", std::vector<unsigned int>{});
if (renderModes.size())
{
ren->SetRenderMode(renderModes);
}
auto handleOldModes = [&prefs](ByteString prefName, ByteString oldPrefName, uint32_t defaultValue, auto setFunc) {
auto pref = prefs.Get<uint32_t>(prefName);
if (!pref.has_value())
{
auto modes = prefs.Get(oldPrefName, std::vector<unsigned int>{});
if (modes.size())
{
uint32_t mode = 0;
for (auto partial : modes)
{
mode |= partial;
}
pref = mode;
}
else
{
pref = defaultValue;
}
}
setFunc(*pref);
};
handleOldModes("Renderer.RenderMode", "Renderer.RenderModes", RENDER_FIRE | RENDER_EFFE | RENDER_BASC, [this](uint32_t renderMode) {
ren->SetRenderMode(renderMode);
});
handleOldModes("Renderer.DisplayMode", "Renderer.DisplayModes", 0, [this](uint32_t displayMode) {
ren->SetDisplayMode(displayMode);
});
ren->SetColorMode(prefs.Get("Renderer.ColourMode", UINT32_C(0)));
ren->gravityFieldEnabled = prefs.Get("Renderer.GravityField", false);
ren->decorations_enable = prefs.Get("Renderer.Decorations", true);
@@ -162,9 +170,9 @@ GameModel::~GameModel()
{
//Save to config:
Prefs::DeferWrite dw(prefs);
prefs.Set("Renderer.ColourMode", ren->GetColourMode());
prefs.Set("Renderer.DisplayModes", ren->GetDisplayMode());
prefs.Set("Renderer.RenderModes", ren->GetRenderMode());
prefs.Set("Renderer.ColourMode", ren->GetColorMode());
prefs.Set("Renderer.DisplayMode", ren->GetDisplayMode());
prefs.Set("Renderer.RenderMode", ren->GetRenderMode());
prefs.Set("Renderer.GravityField", (bool)ren->gravityFieldEnabled);
prefs.Set("Renderer.Decorations", (bool)ren->decorations_enable);
prefs.Set("Renderer.DebugMode", ren->debugLines); //These two should always be equivalent, even though they are different things

View File

@@ -1,20 +1,11 @@
#pragma once
#include "common/String.h"
#include <vector>
#include <cstdint>
class RenderPreset
struct RenderPreset
{
public:
String Name;
std::vector<unsigned int> RenderModes;
std::vector<unsigned int> DisplayModes;
unsigned int ColourMode;
RenderPreset(): Name(""), ColourMode(0) {}
RenderPreset(String name, std::vector<unsigned int> renderModes, std::vector<unsigned int> displayModes, unsigned int colourMode):
Name(name),
RenderModes(renderModes),
DisplayModes(displayModes),
ColourMode(colourMode)
{}
uint32_t renderMode;
uint32_t displayMode;
uint32_t colorMode;
};

View File

@@ -19,29 +19,34 @@ RenderController::RenderController(Simulation *sim, Renderer * ren, std::functio
onDone = onDone_;
}
void RenderController::SetRenderMode(unsigned int renderMode)
void RenderController::SetRenderMode(uint32_t newRenderMode)
{
renderModel->SetRenderMode(renderMode);
renderModel->SetRenderMode(newRenderMode);
}
void RenderController::UnsetRenderMode(unsigned int renderMode)
uint32_t RenderController::GetRenderMode()
{
renderModel->UnsetRenderMode(renderMode);
return renderModel->GetRenderMode();
}
void RenderController::SetDisplayMode(unsigned int renderMode)
void RenderController::SetDisplayMode(uint32_t newDisplayMode)
{
renderModel->SetDisplayMode(renderMode);
renderModel->SetDisplayMode(newDisplayMode);
}
void RenderController::UnsetDisplayMode(unsigned int renderMode)
uint32_t RenderController::GetDisplayMode()
{
renderModel->UnsetDisplayMode(renderMode);
return renderModel->GetDisplayMode();
}
void RenderController::SetColourMode(unsigned int renderMode)
void RenderController::SetColorMode(uint32_t newColorMode)
{
renderModel->SetColourMode(renderMode);
renderModel->SetColorMode(newColorMode);
}
uint32_t RenderController::GetColorMode()
{
return renderModel->GetColorMode();
}
void RenderController::LoadRenderPreset(int presetNum)

View File

@@ -1,5 +1,6 @@
#pragma once
#include <functional>
#include <cstdint>
class RenderView;
class RenderModel;
@@ -16,10 +17,11 @@ public:
void Exit();
RenderView * GetView() { return renderView; }
virtual ~RenderController();
void SetRenderMode(unsigned int renderMode);
void UnsetRenderMode(unsigned int renderMode);
void SetDisplayMode(unsigned int renderMode);
void UnsetDisplayMode(unsigned int renderMode);
void SetColourMode(unsigned int renderMode);
void SetRenderMode(uint32_t newRenderMode);
uint32_t GetRenderMode();
void SetDisplayMode(uint32_t newDisplayMode);
uint32_t GetDisplayMode();
void SetColorMode(uint32_t newColorMode);
uint32_t GetColorMode();
void LoadRenderPreset(int presetNum);
};

View File

@@ -21,74 +21,54 @@ void RenderModel::AddObserver(RenderView * observer)
observer->NotifyColourChanged(this);
}
void RenderModel::SetRenderMode(unsigned int renderMode)
void RenderModel::SetRenderMode(uint32_t newRenderMode)
{
if(renderer)
renderer->AddRenderMode(renderMode);
if (renderer)
{
renderer->SetRenderMode(newRenderMode);
}
notifyRenderChanged();
}
void RenderModel::UnsetRenderMode(unsigned int renderMode)
uint32_t RenderModel::GetRenderMode()
{
if(renderer)
renderer->RemoveRenderMode(renderMode);
notifyRenderChanged();
return renderer ? renderer->GetRenderMode() : 0;
}
unsigned int RenderModel::GetRenderMode()
void RenderModel::SetDisplayMode(uint32_t newDisplayMode)
{
if(renderer)
return renderer->render_mode;
else
return 0;
}
void RenderModel::SetDisplayMode(unsigned int displayMode)
{
if(renderer)
renderer->AddDisplayMode(displayMode);
if (renderer)
{
renderer->SetDisplayMode(newDisplayMode);
}
notifyDisplayChanged();
}
void RenderModel::UnsetDisplayMode(unsigned int displayMode)
uint32_t RenderModel::GetDisplayMode()
{
if(renderer)
renderer->RemoveDisplayMode(displayMode);
notifyDisplayChanged();
return renderer ? renderer->GetDisplayMode() : 0;
}
unsigned int RenderModel::GetDisplayMode()
void RenderModel::SetColorMode(uint32_t newColorMode)
{
if(renderer)
return renderer->display_mode;
else
return 0;
}
void RenderModel::SetColourMode(unsigned int colourMode)
{
if(renderer)
renderer->SetColourMode(colourMode);
if (renderer)
{
renderer->SetColorMode(newColorMode);
}
notifyColourChanged();
}
unsigned int RenderModel::GetColourMode()
uint32_t RenderModel::GetColorMode()
{
if(renderer)
return renderer->colour_mode;
else
return 0;
return renderer ? renderer->GetColorMode() : 0;
}
void RenderModel::LoadRenderPreset(int presetNum)
{
RenderPreset preset = renderer->renderModePresets[presetNum];
renderer->SetRenderMode(preset.RenderModes);
renderer->SetDisplayMode(preset.DisplayModes);
renderer->SetColourMode(preset.ColourMode);
notifyRenderChanged();
notifyDisplayChanged();
notifyColourChanged();
SetRenderMode(preset.renderMode);
SetDisplayMode(preset.displayMode);
SetColorMode(preset.colorMode);
}
void RenderModel::SetRenderer(Renderer * ren)

View File

@@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include <cstdint>
class RenderView;
class Renderer;
@@ -21,14 +22,12 @@ public:
void AddObserver(RenderView * observer);
void SetRenderer(Renderer * ren);
void SetSimulation(Simulation *newSim);
void SetRenderMode(unsigned int renderMode);
void UnsetRenderMode(unsigned int renderMode);
unsigned int GetRenderMode();
void SetDisplayMode(unsigned int displayMode);
void UnsetDisplayMode(unsigned int displayMode);
unsigned int GetDisplayMode();
void SetColourMode(unsigned int colourMode);
unsigned int GetColourMode();
void SetRenderMode(uint32_t newRenderMode);
uint32_t GetRenderMode();
void SetDisplayMode(uint32_t newDisplayMode);
uint32_t GetDisplayMode();
void SetColorMode(uint32_t newColorMode);
uint32_t GetColorMode();
void LoadRenderPreset(int presetNum);
virtual ~RenderModel();
};

View File

@@ -17,7 +17,7 @@ class ModeCheckbox : public ui::Checkbox
{
public:
using ui::Checkbox::Checkbox;
unsigned int mode;
uint32_t mode;
};
RenderView::RenderView():
@@ -51,10 +51,16 @@ RenderView::RenderView():
renderModeCheckbox->mode = mode;
renderModeCheckbox->SetIcon(icon);
renderModeCheckbox->SetActionCallback({ [this, renderModeCheckbox] {
auto renderMode = c->GetRenderMode();
if (renderModeCheckbox->GetChecked())
c->SetRenderMode(renderModeCheckbox->mode);
{
renderMode |= renderModeCheckbox->mode;
}
else
c->UnsetRenderMode(renderModeCheckbox->mode);
{
renderMode &= ~renderModeCheckbox->mode;
}
c->SetRenderMode(renderMode);
} });
AddComponent(renderModeCheckbox);
};
@@ -72,10 +78,16 @@ RenderView::RenderView():
displayModeCheckbox->mode = mode;
displayModeCheckbox->SetIcon(icon);
displayModeCheckbox->SetActionCallback({ [this, displayModeCheckbox] {
auto displayMode = c->GetDisplayMode();
if (displayModeCheckbox->GetChecked())
c->SetDisplayMode(displayModeCheckbox->mode);
{
displayMode |= displayModeCheckbox->mode;
}
else
c->UnsetDisplayMode(displayModeCheckbox->mode);
{
displayMode &= ~displayModeCheckbox->mode;
}
c->SetDisplayMode(displayMode);
} });
AddComponent(displayModeCheckbox);
};
@@ -96,10 +108,17 @@ RenderView::RenderView():
colourModeCheckbox->mode = mode;
colourModeCheckbox->SetIcon(icon);
colourModeCheckbox->SetActionCallback({ [this, colourModeCheckbox] {
if(colourModeCheckbox->GetChecked())
c->SetColourMode(colourModeCheckbox->mode);
auto colorMode = c->GetColorMode();
// exception: looks like an independent set of settings but behaves more like an index
if (colourModeCheckbox->GetChecked())
{
colorMode = colourModeCheckbox->mode;
}
else
c->SetColourMode(0);
{
colorMode = 0;
}
c->SetColorMode(colorMode);
} });
AddComponent(colourModeCheckbox);
};
@@ -154,8 +173,8 @@ void RenderView::NotifyColourChanged(RenderModel * sender)
{
for (size_t i = 0; i < colourModes.size(); i++)
{
auto colourMode = colourModes[i]->mode;
colourModes[i]->SetChecked(colourMode == sender->GetColourMode());
auto colorMode = colourModes[i]->mode;
colourModes[i]->SetChecked(colorMode == sender->GetColorMode());
}
}

View File

@@ -4,38 +4,16 @@
#include "graphics/Renderer.h"
#include "simulation/ElementGraphics.h"
static int renderModes(lua_State *L)
static int renderMode(lua_State *L)
{
auto *lsi = GetLSI();
int args = lua_gettop(L);
if(args)
if (lua_gettop(L))
{
int size = 0;
luaL_checktype(L, 1, LUA_TTABLE);
size = lua_objlen(L, 1);
std::vector<unsigned int> renderModes;
for(int i = 1; i <= size; i++)
{
lua_rawgeti(L, 1, i);
renderModes.push_back(lua_tointeger(L, -1));
lua_pop(L, 1);
}
lsi->ren->SetRenderMode(renderModes);
lsi->ren->SetRenderMode(luaL_checkinteger(L, 1));
return 0;
}
else
{
lua_newtable(L);
std::vector<unsigned int> renderModes = lsi->ren->GetRenderMode();
int i = 1;
for(std::vector<unsigned int>::iterator iter = renderModes.begin(), end = renderModes.end(); iter != end; ++iter)
{
lua_pushinteger(L, *iter);
lua_rawseti(L, -2, i++);
}
return 1;
}
lua_pushinteger(L, lsi->ren->GetRenderMode());
return 1;
}
static int hud(lua_State *L)
@@ -92,55 +70,29 @@ static int fireSize(lua_State *L)
return 0;
}
static int displayModes(lua_State *L)
static int displayMode(lua_State *L)
{
auto *lsi = GetLSI();
int args = lua_gettop(L);
if(args)
if (lua_gettop(L))
{
int size = 0;
luaL_checktype(L, 1, LUA_TTABLE);
size = lua_objlen(L, 1);
std::vector<unsigned int> displayModes;
for(int i = 1; i <= size; i++)
{
lua_rawgeti(L, 1, i);
displayModes.push_back(lua_tointeger(L, -1));
lua_pop(L, 1);
}
lsi->ren->SetDisplayMode(displayModes);
lsi->ren->SetDisplayMode(luaL_checkinteger(L, 1));
return 0;
}
else
{
lua_newtable(L);
std::vector<unsigned int> displayModes = lsi->ren->GetDisplayMode();
int i = 1;
for(std::vector<unsigned int>::iterator iter = displayModes.begin(), end = displayModes.end(); iter != end; ++iter)
{
lua_pushinteger(L, *iter);
lua_rawseti(L, -2, i++);
}
return 1;
}
lua_pushinteger(L, lsi->ren->GetDisplayMode());
return 1;
}
static int colorMode(lua_State *L)
{
auto *lsi = GetLSI();
int args = lua_gettop(L);
if(args)
if (lua_gettop(L))
{
luaL_checktype(L, 1, LUA_TNUMBER);
lsi->ren->SetColourMode(lua_tointeger(L, 1));
lsi->ren->SetColorMode(luaL_checkinteger(L, 1));
return 0;
}
else
{
lua_pushinteger(L, lsi->ren->GetColourMode());
return 1;
}
lua_pushinteger(L, lsi->ren->GetColorMode());
return 1;
}
static int decorations(lua_State *L)
@@ -270,8 +222,8 @@ void LuaRenderer::Open(lua_State *L)
{
static const luaL_Reg reg[] = {
#define LFUNC(v) { #v, v }
LFUNC(renderModes),
LFUNC(displayModes),
LFUNC(renderMode),
LFUNC(displayMode),
LFUNC(colorMode),
LFUNC(decorations),
LFUNC(grid),

View File

@@ -700,3 +700,27 @@ function tpt_mt:__newindex(key, value)
rawset(self, key, value)
end
setmetatable(tpt, tpt_mt)
function ren.renderModes(tbl)
if tbl then
local combined = 0
for i = 1, #tbl do
combined = bit.bor(combined, tbl[i])
end
ren.renderMode(combined)
return
end
return { ren.renderMode() }
end
function ren.displayModes(tbl)
if tbl then
local combined = 0
for i = 1, #tbl do
combined = bit.bor(combined, tbl[i])
end
ren.displayMode(combined)
return
end
return { ren.displayMode() }
end

View File

@@ -31,7 +31,7 @@ std::unique_ptr<VideoBuffer> SaveRenderer::Render(const GameSave *save, bool dec
{
ren->SetRenderMode(renderModeSource->GetRenderMode());
ren->SetDisplayMode(renderModeSource->GetDisplayMode());
ren->SetColourMode(renderModeSource->GetColourMode());
ren->SetColorMode(renderModeSource->GetColorMode());
}
sim->clear_sim();