Skip to content

Commit

Permalink
reduce unnecessary #include dependency chains
Browse files Browse the repository at this point in the history
for example, elements no longer include Client.h or Graphics.h, and interface stuff won't include Window.h or Graphics.h unless requested
  • Loading branch information
jacob1 committed Jul 14, 2017
1 parent 781a90a commit 5ee10d1
Show file tree
Hide file tree
Showing 71 changed files with 307 additions and 270 deletions.
10 changes: 2 additions & 8 deletions src/Activity.h
Expand Up @@ -26,17 +26,11 @@ class WindowActivity: public ui::Window, public Activity
}
virtual void Show()
{
if(ui::Engine::Ref().GetWindow() != this)
{
ui::Engine::Ref().ShowWindow(this);
}
MakeActiveWindow();
}
virtual void Hide()
{
if(ui::Engine::Ref().GetWindow() == this)
{
ui::Engine::Ref().CloseWindow();
}
CloseActiveWindow();
}
virtual ~WindowActivity() {}
};
3 changes: 1 addition & 2 deletions src/debug/DebugLines.cpp
@@ -1,5 +1,4 @@
#include "DebugLines.h"
#include "gui/interface/Engine.h"
#include "gui/game/GameView.h"
#include "gui/game/GameController.h"

Expand All @@ -13,7 +12,7 @@ DebugLines::DebugLines(unsigned int id, GameView * view, GameController * contro

void DebugLines::Draw()
{
Graphics * g = ui::Engine::Ref().g;
Graphics * g = view->GetGraphics();

if (view->GetDrawingLine())
{
Expand Down
3 changes: 2 additions & 1 deletion src/debug/DebugParts.cpp
@@ -1,7 +1,8 @@
#include <iomanip>
#include <sstream>
#include "DebugParts.h"
#include "gui/interface/Engine.h"
#include "simulation/Simulation.h"
#include <iomanip>

DebugParts::DebugParts(unsigned int id, Simulation * sim):
DebugInfo(id),
Expand Down
94 changes: 2 additions & 92 deletions src/graphics/Graphics.h
Expand Up @@ -9,98 +9,8 @@
#include "OpenGLHeaders.h"
#endif
#include "Config.h"
//#include "powder.h"

#define PIXELCHANNELS 3
#ifdef PIX16
#define PIXELSIZE 2
#define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F)) //16bit RGB in 16bit int: ????
#define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F))
#define PIXR(x) (((x)>>8)&0xF8)
#define PIXG(x) (((x)>>3)&0xFC)
#define PIXB(x) (((x)<<3)&0xF8)
#else
#define PIXELSIZE 4
#ifdef PIX32BGRA
#define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000)) //24bit BGR in 32bit int: 00BBGGRR
#define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|((r)))// (((b)<<16)|((g)<<8)|(r))
#define PIXR(x) ((x)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)>>16)
#else
#ifdef PIX32BGRA
#define PIXPACK(x) ((((x)>>8)&0x0000FF00)|(((x)<<8)&0x00FF0000)|(((x)<<24)&0xFF000000)) //32bit BGRA in 32bit int: BBGGRRAA
#define PIXRGB(r,g,b) (((b)<<24)|((g)<<16)|((r)<<8))
#define PIXR(x) (((x)>>8)&0xFF)
#define PIXG(x) (((x)>>16)&0xFF)
#define PIXB(x) (((x)>>24)&0xFF)
#elif defined(PIX32OGL)
#undef PIXELCHANNELS
#define PIXELCHANNELS 4
#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) //32bit ARGB in 32bit int: AARRGGBB
#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))
#define PIXRGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|((b)))
#define PIXA(x) (((x)>>24)&0xFF)
#define PIXR(x) (((x)>>16)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)&0xFF)
#else
#define PIXPACK(x) (x) //24bit RGB in 32bit int: 00RRGGBB.
#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
#define PIXR(x) (((x)>>16)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)&0xFF)
#endif
#endif
#endif

#ifdef PIX16
typedef unsigned short pixel;
#else
typedef unsigned int pixel;
#endif

//Icon names, see Graphics::draw_icon
enum Icon
{
NoIcon = 0,
IconOpen,
IconReload,
IconSave,
IconVoteUp,
IconVoteDown,
IconTag,
IconNew,
IconLogin,
IconRenderSettings,
IconSimulationSettings,
IconPause,
IconVoteSort,
IconDateSort,
IconMyOwn,
IconFavourite,
IconSearch,
IconDelete,
IconAdd,
IconReport,
IconUsername,
IconPassword,
IconClose,
IconEffect,
IconFire,
IconGlow,
IconBlur,
IconBlob,
IconBasic,
IconAltAir,
IconPressure,
IconVelocity,
IconWarp,
IconPersistant,
IconHeat,
IconLife,
IconGradient
};
#include "Pixel.h"
#include "Icons.h"

//"Graphics lite" - slightly lower performance due to variable size,
class VideoBuffer
Expand Down
46 changes: 46 additions & 0 deletions src/graphics/Icons.h
@@ -0,0 +1,46 @@
#ifndef ICONS_H
#define ICONS_H

//Icon names, see Graphics::draw_icon
enum Icon
{
NoIcon = 0,
IconOpen,
IconReload,
IconSave,
IconVoteUp,
IconVoteDown,
IconTag,
IconNew,
IconLogin,
IconRenderSettings,
IconSimulationSettings,
IconPause,
IconVoteSort,
IconDateSort,
IconMyOwn,
IconFavourite,
IconSearch,
IconDelete,
IconAdd,
IconReport,
IconUsername,
IconPassword,
IconClose,
IconEffect,
IconFire,
IconGlow,
IconBlur,
IconBlob,
IconBasic,
IconAltAir,
IconPressure,
IconVelocity,
IconWarp,
IconPersistant,
IconHeat,
IconLife,
IconGradient
};

#endif // ICONS_H
53 changes: 53 additions & 0 deletions src/graphics/Pixel.h
@@ -0,0 +1,53 @@
#ifndef PIXEL_H
#define PIXEL_H

#define PIXELCHANNELS 3
#ifdef PIX16
#define PIXELSIZE 2
#define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F)) //16bit RGB in 16bit int: ????
#define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F))
#define PIXR(x) (((x)>>8)&0xF8)
#define PIXG(x) (((x)>>3)&0xFC)
#define PIXB(x) (((x)<<3)&0xF8)
#else
#define PIXELSIZE 4
#ifdef PIX32BGRA
#define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000)) //24bit BGR in 32bit int: 00BBGGRR
#define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|((r)))// (((b)<<16)|((g)<<8)|(r))
#define PIXR(x) ((x)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)>>16)
#else
#ifdef PIX32BGRA
#define PIXPACK(x) ((((x)>>8)&0x0000FF00)|(((x)<<8)&0x00FF0000)|(((x)<<24)&0xFF000000)) //32bit BGRA in 32bit int: BBGGRRAA
#define PIXRGB(r,g,b) (((b)<<24)|((g)<<16)|((r)<<8))
#define PIXR(x) (((x)>>8)&0xFF)
#define PIXG(x) (((x)>>16)&0xFF)
#define PIXB(x) (((x)>>24)&0xFF)
#elif defined(PIX32OGL)
#undef PIXELCHANNELS
#define PIXELCHANNELS 4
#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) //32bit ARGB in 32bit int: AARRGGBB
#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))
#define PIXRGBA(r,g,b,a) (((a)<<24)|((r)<<16)|((g)<<8)|((b)))
#define PIXA(x) (((x)>>24)&0xFF)
#define PIXR(x) (((x)>>16)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)&0xFF)
#else
#define PIXPACK(x) (x) //24bit RGB in 32bit int: 00RRGGBB.
#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b))
#define PIXR(x) (((x)>>16)&0xFF)
#define PIXG(x) (((x)>>8)&0xFF)
#define PIXB(x) ((x)&0xFF)
#endif
#endif
#endif

#ifdef PIX16
typedef unsigned short pixel;
#else
typedef unsigned int pixel;
#endif

#endif // PIXEL_H
2 changes: 2 additions & 0 deletions src/graphics/Renderer.cpp
Expand Up @@ -4,8 +4,10 @@
#include <cstdio>
#include <cstdlib>
#include "Config.h"
#include "Misc.h"
#include "Renderer.h"
#include "Graphics.h"
#include "gui/game/RenderPreset.h"
#include "simulation/Elements.h"
#include "simulation/ElementGraphics.h"
#include "simulation/Air.h"
Expand Down
4 changes: 1 addition & 3 deletions src/graphics/Renderer.h
Expand Up @@ -7,13 +7,11 @@
#endif

#include "Config.h"
#include "client/Client.h"
#include "Graphics.h"
#include "gui/interface/Point.h"
#include "gui/game/RenderPreset.h"

class RenderPreset;
class Simulation;

class Graphics;

struct gcache_item
Expand Down
2 changes: 1 addition & 1 deletion src/gui/colourpicker/ColourPickerActivity.cpp
Expand Up @@ -258,7 +258,7 @@ void ColourPickerActivity::OnKeyPress(int key, Uint16 character, bool shift, boo

void ColourPickerActivity::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
Graphics * g = GetGraphics();
//g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
g->fillrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3, 0, 0, 0, currentAlpha);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
Expand Down
14 changes: 6 additions & 8 deletions src/gui/console/ConsoleController.cpp
Expand Up @@ -28,8 +28,7 @@ void ConsoleController::EvaluateCommand(std::string command)

void ConsoleController::CloseConsole()
{
if(ui::Engine::Ref().GetWindow() == consoleView)
ui::Engine::Ref().CloseWindow();
consoleView->CloseActiveWindow();
}

std::string ConsoleController::FormatCommand(std::string command)
Expand All @@ -53,9 +52,8 @@ void ConsoleController::PreviousCommand()

void ConsoleController::Exit()
{
if(ui::Engine::Ref().GetWindow() == consoleView)
ui::Engine::Ref().CloseWindow();
if(callback)
consoleView->CloseActiveWindow();
if (callback)
callback->ControllerExit();
HasDone = true;
}
Expand All @@ -65,9 +63,9 @@ ConsoleView * ConsoleController::GetView()
return consoleView;
}

ConsoleController::~ConsoleController() {
if(ui::Engine::Ref().GetWindow() == consoleView)
ui::Engine::Ref().CloseWindow();
ConsoleController::~ConsoleController()
{
consoleView->CloseActiveWindow();
delete callback;
delete consoleModel;
delete consoleView;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/console/ConsoleView.cpp
Expand Up @@ -91,7 +91,7 @@ void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)

void ConsoleView::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
Graphics * g = GetGraphics();
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 0, 0, 0, 110);
g->draw_line(Position.X, Position.Y+Size.Y-16, Position.X+Size.X, Position.Y+Size.Y-16, 255, 255, 255, 160);
g->draw_line(Position.X, Position.Y+Size.Y, Position.X+Size.X, Position.Y+Size.Y, 255, 255, 255, 200);
Expand Down
13 changes: 7 additions & 6 deletions src/gui/dialogues/ConfirmPrompt.cpp
@@ -1,7 +1,8 @@
#include "ConfirmPrompt.h"
#include "gui/Style.h"
#include "gui/interface/Label.h"
#include "gui/interface/Button.h"
#include "gui/interface/Engine.h"
#include "gui/interface/Label.h"
#include "gui/interface/ScrollPanel.h"
#include "PowderToy.h"

Expand Down Expand Up @@ -40,7 +41,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
CloseAction(ConfirmPrompt * prompt_, DialogueResult result_) { prompt = prompt_; result = result_; }
void ActionCallback(ui::Button * sender)
{
ui::Engine::Ref().CloseWindow();
prompt->CloseActiveWindow();
if(prompt->callback)
prompt->callback->ConfirmCallback(result);
prompt->SelfDestruct();
Expand All @@ -64,7 +65,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
AddComponent(okayButton);
SetOkayButton(okayButton);

ui::Engine::Ref().ShowWindow(this);
MakeActiveWindow();
}

ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, std::string buttonText, ConfirmDialogueCallback * callback_):
Expand Down Expand Up @@ -102,7 +103,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, std::string
CloseAction(ConfirmPrompt * prompt_, DialogueResult result_) { prompt = prompt_; result = result_; }
void ActionCallback(ui::Button * sender)
{
ui::Engine::Ref().CloseWindow();
prompt->CloseActiveWindow();
if(prompt->callback)
prompt->callback->ConfirmCallback(result);
prompt->SelfDestruct();
Expand All @@ -126,7 +127,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, std::string
AddComponent(okayButton);
SetOkayButton(okayButton);

ui::Engine::Ref().ShowWindow(this);
MakeActiveWindow();
}

bool ConfirmPrompt::Blocking(std::string title, std::string message, std::string buttonText)
Expand All @@ -152,7 +153,7 @@ bool ConfirmPrompt::Blocking(std::string title, std::string message, std::string

void ConfirmPrompt::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
Graphics * g = GetGraphics();

g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
Expand Down
1 change: 1 addition & 0 deletions src/gui/dialogues/ConfirmPrompt.h
@@ -1,6 +1,7 @@
#ifndef CONFIRMPROMPT_H_
#define CONFIRMPROMPT_H_

#include <string>
#include "gui/interface/Window.h"

class ConfirmDialogueCallback;
Expand Down

0 comments on commit 5ee10d1

Please sign in to comment.