HUD improvements

This commit is contained in:
Simon Robertshaw 2012-07-24 14:58:39 +01:00
parent e65e222f2c
commit 603cf3149d
7 changed files with 72 additions and 13 deletions

View File

@ -375,7 +375,7 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
}
}
void GameView::SetSample(Particle sample)
void GameView::SetSample(SimulationSample sample)
{
this->sample = sample;
}
@ -1251,18 +1251,36 @@ void GameView::OnDraw()
}
}
//Draw info about simulation under cursor
std::stringstream sampleInfo;
sampleInfo.precision(2);
if(sample.type)
sampleInfo << c->ElementResolve(sample.type) << ", Temp: " << std::fixed << sample.temp -273.15f;
if(sample.particle.type)
sampleInfo << c->ElementResolve(sample.particle.type) << ", Temp: " << std::fixed << sample.particle.temp -273.15f;
else
sampleInfo << "Empty";
if(sample.ctype && sample.ctype>0 && sample.ctype<PT_NUM)
sampleInfo << ", Ctype: " << c->ElementResolve(sample.ctype);
sampleInfo << ", Pressure: " << std::fixed << sample.AirPressure;
g->drawtext(XRES+BARSIZE-(10+Graphics::textwidth((char*)sampleInfo.str().c_str())), 10, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255);
int textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str());
g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5);
g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255*0.75);
//FPS and some version info
#ifndef DEBUG //In debug mode, the Engine will draw FPS and other info instead
std::stringstream fpsInfo;
fpsInfo.precision(2);
#ifdef SNAPSHOT
fpsInfo << "Snapshot " << SNAPSHOT_ID << ". ";
#endif
fpsInfo << "FPS: " << std::fixed << ui::Engine::Ref().GetFps();
#endif
textWidth = Graphics::textwidth((char*)fpsInfo.str().c_str());
g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, 255*0.5);
g->drawtext(16, 16, (const char*)fpsInfo.str().c_str(), 32, 216, 255, 255*0.75);
//Tooltips
if(infoTipPresence)
{
int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5;

View File

@ -87,7 +87,7 @@ private:
Thumbnail * placeSaveThumb;
Particle sample;
SimulationSample sample;
int lastOffset;
void setToolButtonOffset(int offset);
@ -99,7 +99,7 @@ public:
//Breaks MVC, but any other way is going to be more of a mess.
ui::Point GetMousePosition();
void SetSample(Particle sample);
void SetSample(SimulationSample sample);
void AttachController(GameController * _c){ c = _c; }
void NotifyRendererChanged(GameModel * sender);

View File

@ -182,9 +182,11 @@ void Engine::Draw()
if(state_)
state_->DoDraw();
#ifdef DEBUG
char fpsText[512];
sprintf(fpsText, "FPS: %.2f, Delta: %.3f", fps, dt);
ui::Engine::Ref().g->drawtext(10, 10, fpsText, 255, 255, 255, 255);
#endif
g->Finalise();
FrameIndex++;
FrameIndex %= 7200;

View File

@ -41,6 +41,7 @@ namespace ui
void Draw();
void SetFps(float fps);
inline float GetFps() { return fps; };
inline int GetMouseX() { return mousex_; }
inline int GetMouseY() { return mousey_; }

25
src/simulation/Sample.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef The_Powder_Toy_Sample_h
#define The_Powder_Toy_Sample_h
#include "Particle.h"
class SimulationSample
{
public:
Particle particle;
float AirPressure;
float AirTemperature;
float AirVelocityX;
float AirVelocityY;
int WallType;
float Gravity;
float GravityVelocityX;
float GravityVelocityY;
SimulationSample() : particle(), AirPressure(0), AirVelocityX(0), AirVelocityY(0), WallType(0), Gravity(0), GravityVelocityX(0), GravityVelocityY(0), AirTemperature(0) {}
};
#endif

View File

@ -340,13 +340,25 @@ int Simulation::flood_prop(int x, int y, size_t propoffset, void * propvalue, St
return 0;
}
Particle Simulation::Get(int x, int y)
SimulationSample Simulation::Get(int x, int y)
{
SimulationSample sample;
if(pmap[y][x])
return parts[pmap[y][x]>>8];
sample.particle = parts[pmap[y][x]>>8];
if(photons[y][x])
return parts[photons[y][x]>>8];
return Particle();
sample.particle = parts[photons[y][x]>>8];
sample.AirPressure = pv[y/CELL][x/CELL];
sample.AirTemperature = hv[y/CELL][x/CELL];
sample.AirVelocityX = vx[y/CELL][x/CELL];
sample.AirVelocityY = vy[y/CELL][x/CELL];
if(grav->ngrav_enable)
{
sample.Gravity = gravp[(y/CELL)*(XRES/CELL)+(x/CELL)];
sample.GravityVelocityX = gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
sample.GravityVelocityY = gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
}
return sample;
}
#define PMAP_CMP_CONDUCTIVE(pmap, t) (((pmap)&0xFF)==(t) || (((pmap)&0xFF)==PT_SPRK && parts[(pmap)>>8].ctype==(t)))

View File

@ -26,6 +26,7 @@
#include "GOLMenu.h"
#include "MenuSection.h"
#include "client/GameSave.h"
#include "Sample.h"
#define CHANNELS ((int)(MAX_TEMP-73)/100+2)
@ -117,7 +118,7 @@ public:
int Load(int x, int y, GameSave * save);
GameSave * Save();
GameSave * Save(int x1, int y1, int x2, int y2);
Particle Get(int x, int y);
SimulationSample Get(int x, int y);
inline int is_blocking(int t, int x, int y);
inline int is_boundary(int pt, int x, int y);
inline int find_next_boundary(int pt, int *x, int *y, int dm, int *em);