mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-30 07:23:05 +00:00
Fixed 1.000.000 Valgrind warnings.
svn-id: r33711
This commit is contained in:
parent
01b8373d95
commit
ea69217a13
@ -191,6 +191,9 @@ bool XMLParser::parse() {
|
||||
if (_XMLkeys == 0)
|
||||
buildLayout();
|
||||
|
||||
while (!_activeKey.empty())
|
||||
delete _activeKey.pop();
|
||||
|
||||
cleanup();
|
||||
|
||||
bool activeClosure = false;
|
||||
|
@ -179,13 +179,13 @@ namespace Common {
|
||||
for a working sample of a Custom XML Parser.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define XML_KEY(keyName) {\
|
||||
lay = new XMLKeyLayout; \
|
||||
lay->custom = new kLocalParserName::CustomParserCallback; \
|
||||
((kLocalParserName::CustomParserCallback*)(lay->custom))->callback = (&kLocalParserName::parserCallback_##keyName); \
|
||||
layout.top()->children[#keyName] = lay; \
|
||||
lay = new CustomXMLKeyLayout;\
|
||||
lay->callback = (&kLocalParserName::parserCallback_##keyName);\
|
||||
layout.top()->children[#keyName] = lay;\
|
||||
layout.push(lay); \
|
||||
_layoutList.push_back(lay);\
|
||||
for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator p = globalProps.begin(); p != globalProps.end(); ++p){\
|
||||
layout.top()->properties.push_back(*p);}
|
||||
|
||||
@ -209,16 +209,18 @@ namespace Common {
|
||||
|
||||
#define CUSTOM_XML_PARSER(parserName) \
|
||||
protected: \
|
||||
typedef bool (parserName::*ParserCallback)(ParserNode *node); \
|
||||
typedef parserName kLocalParserName; \
|
||||
struct CustomParserCallback { ParserCallback callback; }; \
|
||||
bool keyCallback(ParserNode *node) {return (this->*(((parserName::CustomParserCallback*)(node->layout->custom))->callback))(node);}\
|
||||
bool keyCallback(ParserNode *node) {return node->layout->doCallback(this, node); }\
|
||||
struct CustomXMLKeyLayout : public XMLKeyLayout {\
|
||||
typedef bool (parserName::*ParserCallback)(ParserNode *node);\
|
||||
ParserCallback callback;\
|
||||
bool doCallback(XMLParser *parent, ParserNode *node) {return ((kLocalParserName*)parent->*callback)(node);} };\
|
||||
virtual void buildLayout() { \
|
||||
Common::Stack<XMLKeyLayout*> layout; \
|
||||
XMLKeyLayout *lay = 0; \
|
||||
CustomXMLKeyLayout *lay = 0; \
|
||||
XMLKeyLayout::XMLKeyProperty prop; \
|
||||
Common::List<XMLKeyLayout::XMLKeyProperty> globalProps; \
|
||||
_XMLkeys = new XMLKeyLayout; \
|
||||
_XMLkeys = new CustomXMLKeyLayout; \
|
||||
layout.push(_XMLkeys);
|
||||
|
||||
#define PARSER_END() layout.clear(); }
|
||||
@ -280,8 +282,14 @@ public:
|
||||
virtual ~XMLParser() {
|
||||
while (!_activeKey.empty())
|
||||
delete _activeKey.pop();
|
||||
|
||||
|
||||
delete _XMLkeys;
|
||||
|
||||
for (Common::List<XMLKeyLayout*>::iterator i = _layoutList.begin();
|
||||
i != _layoutList.end(); ++i)
|
||||
delete *i;
|
||||
|
||||
_layoutList.clear();
|
||||
}
|
||||
|
||||
/** Active state for the parser */
|
||||
@ -297,12 +305,12 @@ public:
|
||||
};
|
||||
|
||||
struct XMLKeyLayout;
|
||||
struct ParserNode;
|
||||
|
||||
typedef Common::HashMap<Common::String, XMLParser::XMLKeyLayout*, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ChildMap;
|
||||
|
||||
/** nested struct representing the layout of the XML file */
|
||||
struct XMLKeyLayout {
|
||||
void *custom;
|
||||
struct XMLKeyProperty {
|
||||
Common::String name;
|
||||
bool required;
|
||||
@ -311,9 +319,10 @@ public:
|
||||
Common::List<XMLKeyProperty> properties;
|
||||
ChildMap children;
|
||||
|
||||
~XMLKeyLayout() {
|
||||
virtual bool doCallback(XMLParser *parent, ParserNode *node) = 0;
|
||||
|
||||
virtual ~XMLKeyLayout() {
|
||||
properties.clear();
|
||||
children.clear();
|
||||
}
|
||||
} *_XMLkeys;
|
||||
|
||||
@ -336,8 +345,10 @@ public:
|
||||
bool loadFile(Common::String filename) {
|
||||
Common::File *f = new Common::File;
|
||||
|
||||
if (!f->open(filename))
|
||||
if (!f->open(filename)) {
|
||||
delete f;
|
||||
return false;
|
||||
}
|
||||
|
||||
_fileName = filename;
|
||||
_text.loadStream(f);
|
||||
@ -564,6 +575,7 @@ protected:
|
||||
*/
|
||||
virtual void cleanup() {}
|
||||
|
||||
Common::List<XMLKeyLayout*> _layoutList;
|
||||
|
||||
private:
|
||||
int _pos; /** Current position on the XML buffer. */
|
||||
|
@ -178,11 +178,14 @@ void ThemeLayoutHorizontal::reflowLayout() {
|
||||
_w += _children[i]->getWidth() + _spacing;
|
||||
}
|
||||
|
||||
|
||||
_h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
|
||||
}
|
||||
}
|
||||
|
||||
ThemeEval::~ThemeEval() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void ThemeEval::buildBuiltinVars() {
|
||||
_builtin["kThumbnailWidth"] = kThumbnailWidth;
|
||||
_builtin["kThumbnailHeight"] = kThumbnailHeight1;
|
||||
@ -236,6 +239,9 @@ void ThemeEval::addDialog(const Common::String &name, const Common::String &over
|
||||
|
||||
if (!layout)
|
||||
error("Error when loading dialog position for '%s'", overlays.c_str());
|
||||
|
||||
if (_layouts.contains(name))
|
||||
delete _layouts[name];
|
||||
|
||||
_layouts[name] = layout;
|
||||
|
||||
|
@ -55,7 +55,8 @@ public:
|
||||
_centered(false), _defaultW(-1), _defaultH(-1) { }
|
||||
|
||||
virtual ~ThemeLayout() {
|
||||
_children.clear();
|
||||
for (uint i = 0; i < _children.size(); ++i)
|
||||
delete _children[i];
|
||||
}
|
||||
|
||||
virtual void reflowLayout() = 0;
|
||||
@ -305,7 +306,8 @@ public:
|
||||
ThemeEval() {
|
||||
buildBuiltinVars();
|
||||
}
|
||||
~ThemeEval() {}
|
||||
|
||||
~ThemeEval();
|
||||
|
||||
void buildBuiltinVars();
|
||||
|
||||
@ -379,6 +381,16 @@ public:
|
||||
// _layouts["Dialog.GameOptions_Graphics"]->debugDraw(screen, font);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_vars.clear();
|
||||
_builtin.clear();
|
||||
_curDialog.clear();
|
||||
_curLayout.clear();
|
||||
|
||||
for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
|
||||
delete i->_value;
|
||||
}
|
||||
|
||||
private:
|
||||
VariablesMap _vars;
|
||||
VariablesMap _builtin;
|
||||
|
@ -97,12 +97,12 @@ Graphics::DrawStep *ThemeParser::defaultDrawStep() {
|
||||
|
||||
Graphics::DrawStep *ThemeParser::newDrawStep() {
|
||||
assert(_defaultStepGlobal);
|
||||
Graphics::DrawStep *step = new DrawStep;
|
||||
Graphics::DrawStep *step = 0 ; //new DrawStep;
|
||||
|
||||
if (_defaultStepLocal) {
|
||||
memcpy(step, _defaultStepLocal, sizeof(DrawStep));
|
||||
step = new DrawStep(*_defaultStepLocal);
|
||||
} else {
|
||||
memcpy(step, _defaultStepGlobal, sizeof(DrawStep));
|
||||
step = new DrawStep(*_defaultStepGlobal);
|
||||
}
|
||||
|
||||
return step;
|
||||
@ -116,9 +116,8 @@ bool ThemeParser::parserCallback_defaults(ParserNode *node) {
|
||||
step = _defaultStepGlobal;
|
||||
} else if (parentNode->name == "drawdata") {
|
||||
if (_defaultStepLocal == 0)
|
||||
_defaultStepLocal = new DrawStep;
|
||||
_defaultStepLocal = new DrawStep(*_defaultStepLocal);
|
||||
|
||||
memcpy(_defaultStepLocal, _defaultStepGlobal, sizeof(DrawStep));
|
||||
step = _defaultStepLocal;
|
||||
} else {
|
||||
return parserError("<default> key out of scope. Must be inside <drawdata> or <render_info> keys.");
|
||||
|
@ -312,10 +312,17 @@ class ThemeRenderer;
|
||||
|
||||
class ThemeParser : public XMLParser {
|
||||
typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const DrawStep &);
|
||||
|
||||
|
||||
public:
|
||||
ThemeParser(GUI::ThemeRenderer *parent);
|
||||
|
||||
virtual ~ThemeParser() {
|
||||
delete _defaultStepGlobal;
|
||||
delete _defaultStepLocal;
|
||||
_palette.clear();
|
||||
_drawFunctions.clear();
|
||||
}
|
||||
|
||||
bool getPaletteColor(const Common::String &name, int &r, int &g, int &b) {
|
||||
if (!_palette.contains(name))
|
||||
return false;
|
||||
|
@ -123,6 +123,15 @@ ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
|
||||
_themeName = themeName;
|
||||
}
|
||||
|
||||
ThemeRenderer::~ThemeRenderer() {
|
||||
freeRenderer();
|
||||
freeScreen();
|
||||
freeBackbuffer();
|
||||
unloadTheme();
|
||||
delete _parser;
|
||||
delete _themeEval;
|
||||
}
|
||||
|
||||
bool ThemeRenderer::init() {
|
||||
// reset everything and reload the graphics
|
||||
deinit();
|
||||
@ -174,17 +183,16 @@ void ThemeRenderer::disable() {
|
||||
|
||||
template<typename PixelType>
|
||||
void ThemeRenderer::screenInit(bool backBuffer) {
|
||||
freeScreen();
|
||||
freeBackbuffer();
|
||||
|
||||
uint32 width = _system->getOverlayWidth();
|
||||
uint32 height = _system->getOverlayHeight();
|
||||
|
||||
if (backBuffer) {
|
||||
freeBackbuffer();
|
||||
_backBuffer = new Surface;
|
||||
_backBuffer->create(width, height, sizeof(PixelType));
|
||||
}
|
||||
|
||||
freeScreen();
|
||||
_screen = new Surface;
|
||||
_screen->create(width, height, sizeof(PixelType));
|
||||
_system->clearOverlay();
|
||||
|
@ -35,13 +35,15 @@
|
||||
|
||||
#include "gui/dialog.h"
|
||||
#include "gui/ThemeParser.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
#include "graphics/VectorRenderer.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
|
||||
|
||||
namespace GUI {
|
||||
|
||||
struct WidgetDrawData;
|
||||
struct DrawDataInfo;
|
||||
class ThemeEval;
|
||||
|
||||
struct TextDrawData {
|
||||
const Graphics::Font *_fontPtr;
|
||||
@ -210,12 +212,7 @@ public:
|
||||
ThemeRenderer(Common::String themeName, GraphicsMode mode);
|
||||
|
||||
/** Default destructor */
|
||||
~ThemeRenderer() {
|
||||
freeRenderer();
|
||||
freeScreen();
|
||||
unloadTheme();
|
||||
delete _parser;
|
||||
}
|
||||
~ThemeRenderer();
|
||||
|
||||
GUI::ThemeEval *themeEval() { return _themeEval; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user