widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01033
[Merge] lp:~csirkeee/widelands/memory-leaks-3 into lp:widelands
Kiscsirke has proposed merging lp:~csirkeee/widelands/memory-leaks-3 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~csirkeee/widelands/memory-leaks-3/+merge/151672
This is intended to be my last pack of memory leak fixes for now. I tested this quite a bit (except for internet games) and for me the memcheck results seemed clean.
--
https://code.launchpad.net/~csirkeee/widelands/memory-leaks-3/+merge/151672
Your team Widelands Developers is requested to review the proposed merge of lp:~csirkeee/widelands/memory-leaks-3 into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2013-02-10 19:36:24 +0000
+++ src/ai/defaultai.cc 2013-03-05 01:51:25 +0000
@@ -88,6 +88,13 @@
delete mineable_fields.back();
mineable_fields.pop_back();
}
+ while (not economies.empty()) {
+ delete economies.back();
+ economies.pop_back();
+ }
+ while (not blocked_fields.empty()) {
+ blocked_fields.pop_back();
+ }
}
@@ -405,6 +412,7 @@
// check whether we lost ownership of the node
if (mf->coords.field->get_owned_by() != player_number()) {
+ delete mf;
mineable_fields.pop_front();
continue;
}
@@ -808,10 +816,11 @@
// Remove outdated fields from blocker list
for
- (std::list<BlockedField *>::iterator i = blocked_fields.begin();
+ (std::list<BlockedField>::iterator i = blocked_fields.begin();
i != blocked_fields.end();)
- if ((*i)->blocked_until < game().get_gametime())
+ if (i->blocked_until < game().get_gametime()) {
i = blocked_fields.erase(i);
+ }
else ++i;
// first scan all buildable fields for regular buildings
@@ -827,10 +836,10 @@
// Continue if field is blocked at the moment
for
- (std::list<BlockedField *>::iterator j = blocked_fields.begin();
+ (std::list<BlockedField>::iterator j = blocked_fields.begin();
j != blocked_fields.end();
++j)
- if ((*j)->coords == bf->coords)
+ if (j->coords == bf->coords)
continue;
assert(player);
@@ -1182,12 +1191,16 @@
continue;
// Continue if field is blocked at the moment
+ bool blocked = false;
for
- (std::list<BlockedField *>::iterator k = blocked_fields.begin();
+ (std::list<BlockedField>::iterator k = blocked_fields.begin();
k != blocked_fields.end();
++k)
- if ((*k)->coords == (*k)->coords)
- continue;
+ if ((*j)->coords == k->coords) {
+ blocked = true;
+ break;
+ }
+ if (blocked) continue;
// Check if current economy can supply enough food for production.
for (uint32_t k = 0; k < bo.inputs.size(); ++k) {
@@ -1317,7 +1330,7 @@
eo_to_connect->flags.pop_front();
// Block the field at constructionsites coords for 5 minutes
// against new construction tries.
- BlockedField * blocked = new BlockedField
+ BlockedField blocked
(game().map().get_fcoords(bld->get_position()),
game().get_gametime() + 300000);
blocked_fields.push_back(blocked);
=== modified file 'src/ai/defaultai.h'
--- src/ai/defaultai.h 2013-02-10 19:36:24 +0000
+++ src/ai/defaultai.h 2013-03-05 01:51:25 +0000
@@ -170,7 +170,7 @@
std::list<Widelands::FCoords> unusable_fields;
std::list<BuildableField *> buildable_fields;
- std::list<BlockedField *> blocked_fields;
+ std::list<BlockedField> blocked_fields;
std::list<MineableField *> mineable_fields;
std::list<Widelands::Flag const *> new_flags;
std::list<Widelands::Coords> flags_to_be_removed;
=== modified file 'src/editor/ui_menus/editor_main_menu_save_map.cc'
--- src/editor/ui_menus/editor_main_menu_save_map.cc 2013-02-25 21:24:13 +0000
+++ src/editor/ui_menus/editor_main_menu_save_map.cc 2013-03-05 01:51:25 +0000
@@ -327,15 +327,15 @@
char const * const name = pname->c_str();
// we do not list S2 files since we only write wmf
- if (upcast(Widelands::WL_Map_Loader, ml, map.get_correct_loader(name))) {
+ boost::scoped_ptr<Widelands::Map_Loader> ml(map.get_correct_loader(name));
+ if (upcast(Widelands::WL_Map_Loader, wml, ml.get())) {
try {
- ml->preload_map(true);
+ wml->preload_map(true);
m_ls->add
(FileSystem::FS_Filename(name),
name,
g_gr->images().get("pics/ls_wlmap.png"));
} catch (const _wexception &) {} // we simply skip illegal entries
- delete ml;
}
}
if (m_ls->size())
=== modified file 'src/graphic/diranimations.h'
--- src/graphic/diranimations.h 2013-02-10 16:41:12 +0000
+++ src/graphic/diranimations.h 2013-03-05 01:51:25 +0000
@@ -20,6 +20,8 @@
#ifndef DIRANIMATIONS_H
#define DIRANIMATIONS_H
+#include "logic/widelands.h"
+
#include <string>
#include <stdint.h>
@@ -42,10 +44,16 @@
char const * sectnametempl,
Section * defaults = 0);
- uint32_t get_animation(int32_t const dir) const {
+ uint32_t get_animation(Widelands::Direction const dir) const {
return m_animations[dir - 1];
}
+ static DirAnimations Null() {
+ return DirAnimations(0); // Since real animation IDs are positive, this is safe
+ }
+
+ operator bool() const throw () {return m_animations[0];}
+
private:
uint32_t m_animations[6];
};
=== modified file 'src/graphic/render/gamerenderer.cc'
--- src/graphic/render/gamerenderer.cc 2013-02-10 16:41:12 +0000
+++ src/graphic/render/gamerenderer.cc 2013-03-05 01:51:25 +0000
@@ -164,29 +164,29 @@
f_pl.map_object_descr[TCoords<>::None])
{
if
- (const Player::Constructionsite_Information * const csinf =
- f_pl.constructionsite[TCoords<>::None])
+ (f_pl.constructionsite.becomes)
{
+ const Player::Constructionsite_Information & csinf = f_pl.constructionsite;
// draw the partly finished constructionsite
uint32_t anim;
try {
- anim = csinf->becomes->get_animation("build");
+ anim = csinf.becomes->get_animation("build");
} catch (Map_Object_Descr::Animation_Nonexistent & e) {
try {
- anim = csinf->becomes->get_animation("unoccupied");
+ anim = csinf.becomes->get_animation("unoccupied");
} catch (Map_Object_Descr::Animation_Nonexistent) {
- anim = csinf->becomes->get_animation("idle");
+ anim = csinf.becomes->get_animation("idle");
}
}
const size_t nr_frames = g_gr->nr_frames(anim);
uint32_t cur_frame =
- csinf->totaltime ? csinf->completedtime * nr_frames / csinf->totaltime : 0;
+ csinf.totaltime ? csinf.completedtime * nr_frames / csinf.totaltime : 0;
uint32_t tanim = cur_frame * FRAME_LENGTH;
uint32_t w, h;
g_gr->get_animation_size(anim, tanim, w, h);
- uint32_t lines = h * csinf->completedtime * nr_frames;
- if (csinf->totaltime)
- lines /= csinf->totaltime;
+ uint32_t lines = h * csinf.completedtime * nr_frames;
+ if (csinf.totaltime)
+ lines /= csinf.totaltime;
assert(h * cur_frame <= lines);
lines -= h * cur_frame; // This won't work if pictures have various sizes.
@@ -194,14 +194,14 @@
// draw the prev frame from top to where next image will be drawing
m_dst->drawanimrect
(pos[F], anim, tanim - FRAME_LENGTH, owner, Rect(Point(0, 0), w, h - lines));
- else if (csinf->was) {
+ else if (csinf.was) {
// Is the first frame, but there was another building here before,
// get its last build picture and draw it instead.
uint32_t a;
try {
- a = csinf->was->get_animation("unoccupied");
+ a = csinf.was->get_animation("unoccupied");
} catch (Map_Object_Descr::Animation_Nonexistent & e) {
- a = csinf->was->get_animation("idle");
+ a = csinf.was->get_animation("idle");
}
m_dst->drawanimrect
(pos[F], a, tanim - FRAME_LENGTH, owner, Rect(Point(0, 0), w, h - lines));
=== modified file 'src/graphic/texture.cc'
--- src/graphic/texture.cc 2013-03-04 18:03:05 +0000
+++ src/graphic/texture.cc 2013-03-05 01:51:25 +0000
@@ -45,6 +45,7 @@
m_pixels (0),
m_curframe (0),
m_frame_num(0),
+ m_texture_image(NULL),
m_nrframes (0),
m_frametime(frametime),
is_32bit (format.BytesPerPixel == 4),
@@ -75,7 +76,12 @@
SDL_Surface * surf;
+<<<<<<< TREE
m_texture_image = fname;
+=======
+ if (m_texture_image) free(m_texture_image);
+ m_texture_image = strdup(fname);
+>>>>>>> MERGE-SOURCE
FileRead fr;
=== modified file 'src/logic/bob.cc'
--- src/logic/bob.cc 2013-02-10 19:36:24 +0000
+++ src/logic/bob.cc 2013-03-05 01:51:25 +0000
@@ -614,7 +614,7 @@
state.ivar1 = 0; // step #
state.ivar2 = forceonlast ? 1 : 0;
state.ivar3 = only_step;
- state.diranims = &anims;
+ state.diranims = anims;
return true;
}
@@ -623,11 +623,11 @@
* Start moving along the given, precalculated path.
*/
void Bob::start_task_movepath
- (Game & game,
- const Path & path,
- const DirAnimations & anims,
- bool const forceonlast,
- int32_t const only_step)
+ (Game & game,
+ const Path & path,
+ const DirAnimations & anims,
+ bool const forceonlast,
+ int32_t const only_step)
{
assert(path.get_start() == get_position());
@@ -637,7 +637,7 @@
state.ivar1 = 0;
state.ivar2 = forceonlast ? 1 : 0;
state.ivar3 = only_step;
- state.diranims = &anims;
+ state.diranims = anims;
}
@@ -649,12 +649,12 @@
* the given path index.
*/
bool Bob::start_task_movepath
- (Game & game,
- const Path & origpath,
- int32_t const index,
- const DirAnimations & anims,
- bool const forceonlast,
- int32_t const only_step)
+ (Game & game,
+ const Path & origpath,
+ int32_t const index,
+ const DirAnimations & anims,
+ bool const forceonlast,
+ int32_t const only_step)
{
CoordPath path(game.map(), origpath);
int32_t const curidx = path.get_index(get_position());
@@ -752,16 +752,16 @@
* Move into the given direction, without passability checks.
*/
void Bob::start_task_move
- (Game & game,
- int32_t const dir,
- DirAnimations const * const anims,
- bool const forcemove)
+ (Game & game,
+ int32_t const dir,
+ const DirAnimations & anims,
+ bool const forcemove)
{
int32_t const tdelta =
start_walk
(game,
static_cast<WalkingDir>(dir),
- anims->get_animation(dir),
+ anims.get_animation(dir),
forcemove);
if (tdelta < 0)
return send_signal(game, tdelta == -2 ? "blocked" : "fail");
@@ -1040,8 +1040,11 @@
molog("* svar1: %s\n", m_stack[i].svar1.c_str());
molog("* coords: (%i, %i)\n", m_stack[i].coords.x, m_stack[i].coords.y);
- molog("* diranims: %p\n", m_stack[i].diranims);
- molog("* path: %p\n", m_stack[i].path);
+ molog("* diranims:", m_stack[i].diranims);
+ for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
+ molog(" %d", m_stack[i].diranims.get_animation(dir));
+ }
+ molog("\n* path: %p\n", m_stack[i].path);
if (m_stack[i].path) {
const Path & path = *m_stack[i].path;
Path::Step_Vector::size_type nr_steps = path.get_nsteps();
@@ -1133,8 +1136,7 @@
uint32_t anims[6];
for (int j = 0; j < 6; ++j)
anims[j] = bob.descr().get_animation(fr.CString());
- state.diranims = new DirAnimations
- (anims[0], anims[1], anims[2], anims[3], anims[4], anims[5]);
+ state.diranims = DirAnimations(anims[0], anims[1], anims[2], anims[3], anims[4], anims[5]);
}
if (fr.Unsigned8()) {
@@ -1245,7 +1247,7 @@
for (int dir = 1; dir <= 6; ++dir)
fw.CString
(descr().get_animation_name
- (state.diranims->get_animation(dir)).c_str());
+ (state.diranims.get_animation(dir)).c_str());
} else {
fw.Unsigned8(0);
}
=== modified file 'src/logic/bob.h'
--- src/logic/bob.h 2013-02-10 19:36:24 +0000
+++ src/logic/bob.h 2013-03-05 01:51:25 +0000
@@ -22,6 +22,7 @@
#include "economy/route.h"
#include "graphic/animation.h"
+#include "graphic/diranimations.h"
#include "point.h"
#include "writeHTML.h"
#include "instances.h"
@@ -168,7 +169,6 @@
ivar2 (0),
ivar3 (0),
coords (Coords::Null()),
- diranims(0),
path (0),
route (0),
program (0)
@@ -182,7 +182,7 @@
std::string svar1;
Coords coords;
- const DirAnimations * diranims;
+ DirAnimations diranims;
Path * path;
Route * route;
const BobProgramBase * program; ///< pointer to current program
@@ -291,7 +291,7 @@
const int32_t only_step = -1)
__attribute__((warn_unused_result));
- void start_task_move(Game & game, int32_t dir, DirAnimations const *, bool);
+ void start_task_move(Game & game, int32_t dir, const DirAnimations &, bool);
// higher level handling (task-based)
State & top_state() {assert(m_stack.size()); return *m_stack.rbegin();}
=== modified file 'src/logic/carrier.cc'
--- src/logic/carrier.cc 2013-02-11 18:01:26 +0000
+++ src/logic/carrier.cc 2013-03-05 01:51:25 +0000
@@ -254,7 +254,7 @@
start_task_move
(game,
WALK_SE,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
} else {
// tough luck, the building has disappeared
@@ -358,7 +358,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
}
}
=== modified file 'src/logic/constructionsite.cc'
--- src/logic/constructionsite.cc 2013-02-10 19:36:24 +0000
+++ src/logic/constructionsite.cc 2013-03-05 01:51:25 +0000
@@ -74,8 +74,7 @@
Partially_Finished_Building (cs_descr),
m_prev_building (0),
m_fetchfromflag (0),
-m_builder_idle (false),
-m_info (new Player::Constructionsite_Information)
+m_builder_idle (false)
{}
@@ -120,7 +119,7 @@
void ConstructionSite::set_building(const Building_Descr & building_descr) {
Partially_Finished_Building::set_building(building_descr);
- m_info->becomes = &building_descr;
+ m_info.becomes = &building_descr;
}
/*
@@ -134,7 +133,7 @@
assert(!m_prev_building);
m_prev_building = previous_building_descr;
- m_info->was = previous_building_descr;
+ m_info.was = previous_building_descr;
}
/*
@@ -350,15 +349,15 @@
// Draw the partially finished building
compile_assert(0 <= CONSTRUCTIONSITE_STEP_TIME);
- m_info->totaltime = CONSTRUCTIONSITE_STEP_TIME * m_work_steps;
- m_info->completedtime = CONSTRUCTIONSITE_STEP_TIME * m_work_completed;
+ m_info.totaltime = CONSTRUCTIONSITE_STEP_TIME * m_work_steps;
+ m_info.completedtime = CONSTRUCTIONSITE_STEP_TIME * m_work_completed;
if (m_working) {
assert
(m_work_steptime
<=
- m_info->completedtime + CONSTRUCTIONSITE_STEP_TIME + gametime);
- m_info->completedtime += CONSTRUCTIONSITE_STEP_TIME + gametime - m_work_steptime;
+ m_info.completedtime + CONSTRUCTIONSITE_STEP_TIME + gametime);
+ m_info.completedtime += CONSTRUCTIONSITE_STEP_TIME + gametime - m_work_steptime;
}
uint32_t anim;
@@ -373,16 +372,16 @@
}
}
const size_t nr_frames = g_gr->nr_frames(anim);
- cur_frame = m_info->totaltime ? m_info->completedtime * nr_frames / m_info->totaltime : 0;
+ cur_frame = m_info.totaltime ? m_info.completedtime * nr_frames / m_info.totaltime : 0;
// Redefine tanim
tanim = cur_frame * FRAME_LENGTH;
uint32_t w, h;
g_gr->get_animation_size(anim, tanim, w, h);
- uint32_t lines = h * m_info->completedtime * nr_frames;
- if (m_info->totaltime)
- lines /= m_info->totaltime;
+ uint32_t lines = h * m_info.completedtime * nr_frames;
+ if (m_info.totaltime)
+ lines /= m_info.totaltime;
assert(h * cur_frame <= lines);
lines -= h * cur_frame; // This won't work if pictures have various sizes.
=== modified file 'src/logic/constructionsite.h'
--- src/logic/constructionsite.h 2013-02-10 19:36:24 +0000
+++ src/logic/constructionsite.h 2013-03-05 01:51:25 +0000
@@ -72,7 +72,7 @@
char const * type_name() const throw () {return "constructionsite";}
virtual std::string get_statistics_string();
- const Player::Constructionsite_Information * get_info() {return m_info;}
+ const Player::Constructionsite_Information & get_info() {return m_info;}
virtual WaresQueue & waresqueue(Ware_Index);
@@ -104,7 +104,7 @@
int32_t m_fetchfromflag; // # of items to fetch from flag
bool m_builder_idle; // used to determine whether the builder is idle
- Player::Constructionsite_Information * m_info; // asked for by player point of view for the gameview
+ Player::Constructionsite_Information m_info; // asked for by player point of view for the gameview
};
}
=== modified file 'src/logic/critter_bob.h'
--- src/logic/critter_bob.h 2013-02-10 19:36:24 +0000
+++ src/logic/critter_bob.h 2013-03-05 01:51:25 +0000
@@ -50,7 +50,7 @@
DirAnimations m_walk_anims;
bool m_swimming;
typedef std::map<std::string, Critter_BobProgram *> Programs;
- Programs m_programs;
+ Programs m_programs;
};
class Critter_Bob : public Bob {
=== modified file 'src/logic/immovable.cc'
--- src/logic/immovable.cc 2013-03-02 20:35:18 +0000
+++ src/logic/immovable.cc 2013-03-05 01:51:25 +0000
@@ -76,8 +76,7 @@
if (f.field->immovable && f.field->immovable != this) {
assert(f.field->immovable->get_size() == NONE);
- f.field->immovable->cleanup(egbase);
- delete f.field->immovable;
+ f.field->immovable->remove(egbase);
}
f.field->immovable = this;
=== modified file 'src/logic/immovable.h'
--- src/logic/immovable.h 2013-02-18 02:29:31 +0000
+++ src/logic/immovable.h 2013-03-05 01:51:25 +0000
@@ -87,8 +87,6 @@
* Immovable represents a standard immovable such as trees or stones.
*/
struct Immovable_Descr : public Map_Object_Descr {
- friend struct Map_Immovabledata_Data_Packet; // For writing (get_program)
-
typedef std::map<std::string, ImmovableProgram *> Programs;
Immovable_Descr
@@ -133,9 +131,6 @@
friend struct ImmovableProgram;
friend struct Map;
- // for writing (obsolete since build-11)
- friend struct Map_Immovabledata_Data_Packet;
-
MO_DESCR(Immovable_Descr);
public:
=== modified file 'src/logic/instances.cc'
--- src/logic/instances.cc 2013-02-10 19:36:24 +0000
+++ src/logic/instances.cc 2013-03-05 01:51:25 +0000
@@ -179,12 +179,12 @@
/**
* Insert the given Map_Object into the object manager
*/
-void Object_Manager::insert(Map_Object & obj)
+void Object_Manager::insert(Map_Object * obj)
{
++m_lastserial;
assert(m_lastserial);
- obj.m_serial = m_lastserial;
- m_objects[m_lastserial] = &obj;
+ obj->m_serial = m_lastserial;
+ m_objects[m_lastserial] = obj;
}
/**
@@ -394,7 +394,7 @@
*/
void Map_Object::init(Editor_Game_Base & egbase)
{
- egbase.objects().insert(*this);
+ egbase.objects().insert(this);
}
/**
@@ -505,7 +505,7 @@
throw wexception("map object: %s", e.what());
}
- egbase().objects().insert(*get_object());
+ egbase().objects().insert(get_object());
}
=== modified file 'src/logic/instances.h'
--- src/logic/instances.h 2013-02-10 19:36:24 +0000
+++ src/logic/instances.h 2013-03-05 01:51:25 +0000
@@ -50,7 +50,6 @@
* link them together
*/
struct Map_Object_Descr : boost::noncopyable {
- friend struct ::DirAnimations;
typedef uint8_t Index;
Map_Object_Descr(char const * const _name, char const * const _descname)
: m_name(_name), m_descname(_descname)
@@ -349,7 +348,7 @@
return it != m_objects.end() ? it->second : 0;
}
- void insert(Map_Object &);
+ void insert(Map_Object *);
void remove(Map_Object &);
bool object_still_available(const Map_Object * const t) const {
=== modified file 'src/logic/player.cc'
--- src/logic/player.cc 2013-03-02 20:35:18 +0000
+++ src/logic/player.cc 2013-03-05 01:51:25 +0000
@@ -937,7 +937,7 @@
{ // map_object_descr[TCoords::None]
const Map_Object_Descr * map_object_descr;
- const Constructionsite_Information * csi(0);
+ field.constructionsite.becomes = 0;
if (const BaseImmovable * base_immovable = f.field->get_immovable()) {
map_object_descr = &base_immovable->descr();
@@ -949,15 +949,13 @@
map_object_descr = 0;
else {
if (upcast(ConstructionSite const, cs, building)) {
- csi = const_cast<ConstructionSite *>(cs)->get_info();
-
+ field.constructionsite = const_cast<ConstructionSite *>(cs)->get_info();
}
}
}
} else
map_object_descr = 0;
field.map_object_descr[TCoords<>::None] = map_object_descr;
- field.constructionsite[TCoords<>::None] = csi;
}
}
{ // discover the D triangle and the SW edge of the top right neighbour
=== modified file 'src/logic/player.h'
--- src/logic/player.h 2013-02-10 19:36:24 +0000
+++ src/logic/player.h 2013-03-05 01:51:25 +0000
@@ -129,7 +129,7 @@
/// Per-player and per-field constructionsite information
struct Constructionsite_Information {
Constructionsite_Information() : becomes(0), was(0), totaltime(0), completedtime(0) {}
- const Building_Descr * becomes;
+ const Building_Descr * becomes; // Also works as a marker telling whether there is a construction site.
const Building_Descr * was; // only valid if "becomes" is an enhanced building.
uint32_t totaltime;
uint32_t completedtime;
@@ -319,7 +319,7 @@
/// Information for constructionsite's animation.
/// only valid, if there is a constructionsite on this node
- const Constructionsite_Information * constructionsite[3];
+ Constructionsite_Information constructionsite;
/// Save whether the player saw a border the last time (s)he saw the node.
bool border;
@@ -346,9 +346,7 @@
// map_object_descr[0] 0x0a0 0x20 0x0a0 0x40
// map_object_descr[1] 0x0c0 0x20 0x0e0 0x40
// map_object_descr[2] 0x0e0 0x20 0x120 0x40
- // Constructionsite_Information[0]
- // Constructionsite_Information[1]
- // Constructionsite_Information[2]
+ // Constructionsite_Information
// border
// border_r
// border_br
=== modified file 'src/logic/ship.cc'
--- src/logic/ship.cc 2013-02-10 18:47:18 +0000
+++ src/logic/ship.cc 2013-03-05 01:51:25 +0000
@@ -338,7 +338,7 @@
}
state.ivar1 = 1;
- start_task_move(game, dir, &descr().get_sail_anims(), false);
+ start_task_move(game, dir, descr().get_sail_anims(), false);
return;
}
=== modified file 'src/logic/soldier.cc'
--- src/logic/soldier.cc 2013-03-01 23:12:08 +0000
+++ src/logic/soldier.cc 2013-03-05 01:51:25 +0000
@@ -920,7 +920,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
if
@@ -1170,7 +1170,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
}
@@ -1402,7 +1402,7 @@
start_task_move
(game,
WALK_SE,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
}
}
=== modified file 'src/logic/worker.cc'
--- src/logic/worker.cc 2013-03-01 22:38:20 +0000
+++ src/logic/worker.cc 2013-03-05 01:51:25 +0000
@@ -1500,7 +1500,7 @@
if (&nextbuild->base_flag() != location)
throw wexception("MO(%u): [transfer]: next step is building, but we are nowhere near", serial());
- return start_task_move(game, WALK_NW, &descr().get_right_walk_anims(does_carry_ware()), true);
+ return start_task_move(game, WALK_NW, descr().get_right_walk_anims(does_carry_ware()), true);
} else if (upcast(Flag, nextflag, nextstep)) { // Flag to Flag
Road & road = *flag->get_road(*nextflag);
@@ -1830,7 +1830,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
}
}
@@ -2118,7 +2118,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
return;
}
@@ -2133,7 +2133,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
if (location->get_type() != Map_Object::BUILDING)
@@ -2231,7 +2231,7 @@
start_task_move
(game,
WALK_NW,
- &descr().get_right_walk_anims(does_carry_ware()), true);
+ descr().get_right_walk_anims(does_carry_ware()), true);
}
if (not dynamic_cast<Building const *>(location)) {
@@ -2413,7 +2413,7 @@
start_task_move
(game,
WALK_SE,
- &descr().get_right_walk_anims(does_carry_ware()),
+ descr().get_right_walk_anims(does_carry_ware()),
true);
} else {
const Coords & flagpos = baseflag.get_position();
=== modified file 'src/logic/worker_descr.h'
--- src/logic/worker_descr.h 2013-02-10 19:36:24 +0000
+++ src/logic/worker_descr.h 2013-03-05 01:51:25 +0000
@@ -126,7 +126,7 @@
Point m_ware_hotspot;
uint32_t m_default_target_quantity;
std::string const m_icon_fname; ///< Filename of worker's icon
- const Image* m_icon; ///< Pointer to icon into picture stack
+ const Image * m_icon; ///< Pointer to icon into picture stack
DirAnimations m_walk_anims;
DirAnimations m_walkload_anims;
bool m_buildable;
=== modified file 'src/map_generator.cc'
--- src/map_generator.cc 2013-02-10 19:36:24 +0000
+++ src/map_generator.cc 2013-03-05 01:51:25 +0000
@@ -24,6 +24,8 @@
#include "logic/editor_game_base.h"
#include "editor/tools/editor_increase_resources_tool.h"
+#include <boost/scoped_array.hpp>
+
#define AVG_ELEVATION (0x80000000)
#define MAX_ELEVATION (0xffffffff)
#define MAP_ID_DIGITS 24
@@ -31,6 +33,8 @@
#define MAX_ELEVATION_3_4 (0xc0000000)
#define MAX_ELEVATION_HALF (0x80000000)
+using boost::scoped_array;
+
namespace Widelands
{
@@ -43,7 +47,7 @@
}
void MapGenerator::generate_bobs
- (uint32_t const * const * random_bobs,
+ (scoped_array<uint32_t> const * random_bobs,
Coords const fc,
RNG & rng,
MapGenAreaInfo::MapGenTerrainType const terrType)
@@ -639,232 +643,202 @@
// Create a "raw" random elevation matrix.
// We will transform this into reasonable elevations and terrains later on.
- uint32_t * const elevations =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
+ scoped_array<uint32_t> elevations
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
// for land stuff
- uint32_t * const random2 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
- uint32_t * const random3 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
+ scoped_array<uint32_t> random2
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
+ scoped_array<uint32_t> random3
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
// for desert/land
- uint32_t * const random4 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
+ scoped_array<uint32_t> random4
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
// for resources
- uint32_t * const random_rsrc_1 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
- uint32_t * const random_rsrc_2 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
- uint32_t * const random_rsrc_3 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
- uint32_t * const random_rsrc_4 =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
+ scoped_array<uint32_t> random_rsrc_1
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
+ scoped_array<uint32_t> random_rsrc_2
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
+ scoped_array<uint32_t> random_rsrc_3
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
+ scoped_array<uint32_t> random_rsrc_4
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
// for bobs
- uint32_t * * const random_bobs =
- new uint32_t * [mapGenInfo.getNumBobAreas()];
+ scoped_array<scoped_array<uint32_t> > random_bobs
+ (new scoped_array<uint32_t> [mapGenInfo.getNumBobAreas()]);
for (size_t ix = 0; ix < mapGenInfo.getNumBobAreas(); ++ix)
- random_bobs[ix] =
- generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng);
-
- try {
- // Now we have generated a lot of random data!!
- // Lets use it !!!
- iterate_Map_FCoords(m_map, m_mapInfo, fc)
- fc.field->set_height
- (make_node_elevation
- (static_cast<double>(elevations[fc.x + m_mapInfo.w * fc.y])
- /
- static_cast<double>(MAX_ELEVATION),
- fc));
-
- // Now lets set the terrain right according to the heights.
-
- iterate_Map_FCoords(m_map, m_mapInfo, fc) {
- // Calculate coordinates of left and bottom left neighbours of the
- // current node.
-
- // ... Treat "even" and "uneven" row numbers differently
- uint32_t const x_dec = fc.y % 2 == 0;
-
- uint32_t right_x = fc.x + 1;
- uint32_t lower_y = fc.y + 1;
- uint32_t lower_x = fc.x - x_dec;
- uint32_t lower_right_x = fc.x - x_dec + 1;
-
- if (lower_x > m_mapInfo.w) lower_x += m_mapInfo.w;
- if (right_x >= m_mapInfo.w) right_x -= m_mapInfo.w;
- if (lower_x >= m_mapInfo.w) lower_x -= m_mapInfo.w;
- if (lower_right_x >= m_mapInfo.w) lower_right_x -= m_mapInfo.w;
- if (lower_y >= m_mapInfo.h) lower_y -= m_mapInfo.h;
-
- // get the heights of my neighbour nodes and of my current node
-
- uint8_t height_x0_y0 =
- fc.field ->get_height();
- uint8_t height_x1_y0 =
- m_map[Coords(right_x, fc.y)].get_height();
- uint8_t height_x0_y1 =
- m_map[Coords(lower_x, lower_y)].get_height();
- uint8_t height_x1_y1 =
- m_map[Coords(lower_right_x, lower_y)].get_height();
-
- MapGenAreaInfo::MapGenTerrainType terrType;
-
- fc.field->set_terrain_d
- (figure_out_terrain
- (random2, random3, random4,
- fc, Coords(lower_x, lower_y), Coords(lower_right_x, lower_y),
- height_x0_y0, height_x0_y1, height_x1_y1,
- rng, terrType));
-
- fc.field->set_terrain_r
- (figure_out_terrain
- (random2, random3, random4,
- fc, Coords(right_x, fc.y), Coords(lower_right_x, lower_y),
- height_x0_y0, height_x1_y0, height_x1_y1,
- rng, terrType));
-
- // set resources for this field
- generate_resources
- (random_rsrc_1, random_rsrc_2,
- random_rsrc_3, random_rsrc_4,
- fc);
-
- // set bobs and immovables for this field
- generate_bobs(random_bobs, fc, rng, terrType);
- }
-
- // Aftermaths...
- m_map.recalc_whole_map();
-
- // Care about players and place their start positions
- const std::string tribe = m_map.get_scenario_player_tribe(1);
- const std::string ai = m_map.get_scenario_player_ai(1);
- m_map.set_nrplayers(m_mapInfo.numPlayers);
- FindNodeSize functor(FindNodeSize::sizeBig);
- Coords playerstart;
-
- // Build a basic structure how player start positions are placed
- uint8_t line[3];
- uint8_t rows = 1, lines = 1;
- if (m_mapInfo.numPlayers > 1) {
- ++lines;
- if (m_mapInfo.numPlayers > 2) {
- ++rows;
- if (m_mapInfo.numPlayers > 4) {
- ++lines;
- if (m_mapInfo.numPlayers > 6) {
- ++rows;
- }
+ random_bobs[ix].reset
+ (generate_random_value_map(m_mapInfo.w, m_mapInfo.h, rng));
+
+ // Now we have generated a lot of random data!!
+ // Lets use it !!!
+ iterate_Map_FCoords(m_map, m_mapInfo, fc)
+ fc.field->set_height
+ (make_node_elevation
+ (static_cast<double>(elevations[fc.x + m_mapInfo.w * fc.y])
+ /
+ static_cast<double>(MAX_ELEVATION),
+ fc));
+
+ // Now lets set the terrain right according to the heights.
+
+ iterate_Map_FCoords(m_map, m_mapInfo, fc) {
+ // Calculate coordinates of left and bottom left neighbours of the
+ // current node.
+
+ // ... Treat "even" and "uneven" row numbers differently
+ uint32_t const x_dec = fc.y % 2 == 0;
+
+ uint32_t right_x = fc.x + 1;
+ uint32_t lower_y = fc.y + 1;
+ uint32_t lower_x = fc.x - x_dec;
+ uint32_t lower_right_x = fc.x - x_dec + 1;
+
+ if (lower_x > m_mapInfo.w) lower_x += m_mapInfo.w;
+ if (right_x >= m_mapInfo.w) right_x -= m_mapInfo.w;
+ if (lower_x >= m_mapInfo.w) lower_x -= m_mapInfo.w;
+ if (lower_right_x >= m_mapInfo.w) lower_right_x -= m_mapInfo.w;
+ if (lower_y >= m_mapInfo.h) lower_y -= m_mapInfo.h;
+
+ // get the heights of my neighbour nodes and of my current node
+
+ uint8_t height_x0_y0 =
+ fc.field ->get_height();
+ uint8_t height_x1_y0 =
+ m_map[Coords(right_x, fc.y)].get_height();
+ uint8_t height_x0_y1 =
+ m_map[Coords(lower_x, lower_y)].get_height();
+ uint8_t height_x1_y1 =
+ m_map[Coords(lower_right_x, lower_y)].get_height();
+
+ MapGenAreaInfo::MapGenTerrainType terrType;
+
+ fc.field->set_terrain_d
+ (figure_out_terrain
+ (random2.get(), random3.get(), random4.get(),
+ fc, Coords(lower_x, lower_y), Coords(lower_right_x, lower_y),
+ height_x0_y0, height_x0_y1, height_x1_y1,
+ rng, terrType));
+
+ fc.field->set_terrain_r
+ (figure_out_terrain
+ (random2.get(), random3.get(), random4.get(),
+ fc, Coords(right_x, fc.y), Coords(lower_right_x, lower_y),
+ height_x0_y0, height_x1_y0, height_x1_y1,
+ rng, terrType));
+
+ // set resources for this field
+ generate_resources
+ (random_rsrc_1.get(), random_rsrc_2.get(),
+ random_rsrc_3.get(), random_rsrc_4.get(),
+ fc);
+
+ // set bobs and immovables for this field
+ generate_bobs(random_bobs.get(), fc, rng, terrType);
+ }
+
+ // Aftermaths...
+ m_map.recalc_whole_map();
+
+ // Care about players and place their start positions
+ const std::string tribe = m_map.get_scenario_player_tribe(1);
+ const std::string ai = m_map.get_scenario_player_ai(1);
+ m_map.set_nrplayers(m_mapInfo.numPlayers);
+ FindNodeSize functor(FindNodeSize::sizeBig);
+ Coords playerstart;
+
+ // Build a basic structure how player start positions are placed
+ uint8_t line[3];
+ uint8_t rows = 1, lines = 1;
+ if (m_mapInfo.numPlayers > 1) {
+ ++lines;
+ if (m_mapInfo.numPlayers > 2) {
+ ++rows;
+ if (m_mapInfo.numPlayers > 4) {
+ ++lines;
+ if (m_mapInfo.numPlayers > 6) {
+ ++rows;
}
}
}
- line[0] = line[1] = line[2] = rows;
- if (rows * lines > m_mapInfo.numPlayers) {
- --line[1];
- if (rows * lines - 1 > m_mapInfo.numPlayers)
- --line[2];
- }
-
- for (Player_Number n = 1; n <= m_mapInfo.numPlayers; ++n) {
- // Set scenario information - needed even if it's not a scenario
- m_map.set_scenario_player_name(n, "Random Player");
- m_map.set_scenario_player_tribe(n, tribe);
- m_map.set_scenario_player_ai(n, ai);
- m_map.set_scenario_player_closeable(n, false);
-
- // Calculate wished coords for player starting position
- if (line[0] + 1 > n) {
- // X-Coordinates
- playerstart.x = m_mapInfo.w * (line[0] * line[0] + 1 - n * n);
- playerstart.x /= line[0] * line[0] + 1;
- // Y-Coordinates
- if (lines == 1)
- playerstart.y = m_mapInfo.h / 2;
- else
- playerstart.y = m_mapInfo.h / 7 + ISLAND_BORDER;
- } else if (line[0] + line[1] + 1 > n) {
- // X-Coordinates
- uint8_t pos = n - line[0];
- playerstart.x = m_mapInfo.w;
- playerstart.x *= line[1] * line[1] + 1 - pos * pos;
- playerstart.x /= line[1] * line[1] + 1;
- // Y-Coordinates
- if (lines == 3)
- playerstart.y = m_mapInfo.h / 2;
- else
- playerstart.y = m_mapInfo.h - m_mapInfo.h / 7 - ISLAND_BORDER;
- } else {
- // X-Coordinates
- uint8_t pos = n - line[0] - line[1];
- playerstart.x = m_mapInfo.w;
- playerstart.x *= line[2] * line[2] + 1 - pos * pos;
- playerstart.x /= line[2] * line[2] + 1;
- // Y-Coordinates
+ }
+ line[0] = line[1] = line[2] = rows;
+ if (rows * lines > m_mapInfo.numPlayers) {
+ --line[1];
+ if (rows * lines - 1 > m_mapInfo.numPlayers)
+ --line[2];
+ }
+
+ for (Player_Number n = 1; n <= m_mapInfo.numPlayers; ++n) {
+ // Set scenario information - needed even if it's not a scenario
+ m_map.set_scenario_player_name(n, "Random Player");
+ m_map.set_scenario_player_tribe(n, tribe);
+ m_map.set_scenario_player_ai(n, ai);
+ m_map.set_scenario_player_closeable(n, false);
+
+ // Calculate wished coords for player starting position
+ if (line[0] + 1 > n) {
+ // X-Coordinates
+ playerstart.x = m_mapInfo.w * (line[0] * line[0] + 1 - n * n);
+ playerstart.x /= line[0] * line[0] + 1;
+ // Y-Coordinates
+ if (lines == 1)
+ playerstart.y = m_mapInfo.h / 2;
+ else
+ playerstart.y = m_mapInfo.h / 7 + ISLAND_BORDER;
+ } else if (line[0] + line[1] + 1 > n) {
+ // X-Coordinates
+ uint8_t pos = n - line[0];
+ playerstart.x = m_mapInfo.w;
+ playerstart.x *= line[1] * line[1] + 1 - pos * pos;
+ playerstart.x /= line[1] * line[1] + 1;
+ // Y-Coordinates
+ if (lines == 3)
+ playerstart.y = m_mapInfo.h / 2;
+ else
playerstart.y = m_mapInfo.h - m_mapInfo.h / 7 - ISLAND_BORDER;
- }
-
- // Now try to find a place as near as possible to the wished
- // starting position
- std::vector<Coords> coords;
- m_map.find_fields
- (Area<FCoords>(m_map.get_fcoords(playerstart), 20),
- &coords, functor);
-
- // Take the nearest ones
- uint32_t min_distance = -1;
- Coords coords2;
- for (uint16_t i = 0; i < coords.size(); ++i) {
- uint32_t test = m_map.calc_distance(coords[i], playerstart);
- if (test < min_distance) {
- min_distance = test;
- coords2 = coords[i];
- }
- }
-
- if (coords.empty()) {
- // TODO inform players via popup
- log("WARNING: Could not find a suitable place for player %u\n", n);
- // Let's hope that one is at least on dry ground.
- coords2 = playerstart;
- }
-
- // Finally set the found starting position
- m_map.set_starting_pos(n, coords2);
- }
-
- } catch (...) {
- delete[] elevations;
- delete[] random2;
- delete[] random3;
- delete[] random4;
- delete[] random_rsrc_1;
- delete[] random_rsrc_2;
- delete[] random_rsrc_3;
- for (size_t ix = 0; ix < mapGenInfo.getNumBobAreas(); ix++)
- {
- delete[] random_bobs[ix];
- }
- delete[] random_bobs;
-
- throw;
- }
- delete[] elevations;
- delete[] random2;
- delete[] random3;
- delete[] random4;
- delete[] random_rsrc_1;
- delete[] random_rsrc_2;
- delete[] random_rsrc_3;
- for (size_t ix = 0; ix < mapGenInfo.getNumBobAreas(); ix++)
- {
- delete[] random_bobs[ix];
- }
- delete[] random_bobs;
+ } else {
+ // X-Coordinates
+ uint8_t pos = n - line[0] - line[1];
+ playerstart.x = m_mapInfo.w;
+ playerstart.x *= line[2] * line[2] + 1 - pos * pos;
+ playerstart.x /= line[2] * line[2] + 1;
+ // Y-Coordinates
+ playerstart.y = m_mapInfo.h - m_mapInfo.h / 7 - ISLAND_BORDER;
+ }
+
+ // Now try to find a place as near as possible to the wished
+ // starting position
+ std::vector<Coords> coords;
+ m_map.find_fields
+ (Area<FCoords>(m_map.get_fcoords(playerstart), 20),
+ &coords, functor);
+
+ // Take the nearest ones
+ uint32_t min_distance = -1;
+ Coords coords2;
+ for (uint16_t i = 0; i < coords.size(); ++i) {
+ uint32_t test = m_map.calc_distance(coords[i], playerstart);
+ if (test < min_distance) {
+ min_distance = test;
+ coords2 = coords[i];
+ }
+ }
+
+ if (coords.empty()) {
+ // TODO inform players via popup
+ log("WARNING: Could not find a suitable place for player %u\n", n);
+ // Let's hope that one is at least on dry ground.
+ coords2 = playerstart;
+ }
+
+ // Finally set the found starting position
+ m_map.set_starting_pos(n, coords2);
+ }
}
/**
=== modified file 'src/map_generator.h'
--- src/map_generator.h 2013-02-10 19:36:24 +0000
+++ src/map_generator.h 2013-03-05 01:51:25 +0000
@@ -22,6 +22,8 @@
#include "logic/world.h"
+#include <boost/scoped_array.hpp>
+
// This is the first step of separating map generation from
// map.
// TODO: Put other generation stuff here too...
@@ -88,7 +90,7 @@
private:
void generate_bobs
- (uint32_t const * const * random_bobs,
+ (boost::scoped_array<uint32_t> const * random_bobs,
Coords,
RNG &,
MapGenAreaInfo::MapGenTerrainType terrType);
=== modified file 'src/map_io/widelands_map_bobdata_data_packet.cc'
--- src/map_io/widelands_map_bobdata_data_packet.cc 2013-02-10 19:36:24 +0000
+++ src/map_io/widelands_map_bobdata_data_packet.cc 2013-03-05 01:51:25 +0000
@@ -267,9 +267,7 @@
bob_descr.get_animation(fr.CString()),
bob_descr.get_animation(fr.CString())
};
- state.diranims =
- new DirAnimations
- (ans[0], ans[1], ans[2], ans[3], ans[4], ans[5]);
+ state.diranims = DirAnimations(ans[0], ans[1], ans[2], ans[3], ans[4], ans[5]);
if
(state.task == &Bob::taskMove and
@@ -282,7 +280,7 @@
"time if available; the erroneous state that "
"this bob is in only lasts 10ms");
} else
- state.diranims = 0;
+ state.diranims = DirAnimations::Null();
uint32_t const pathsteps = fr.Unsigned16();
if (i < old_stacksize) {
=== modified file 'src/map_io/widelands_map_extradata_data_packet.cc'
--- src/map_io/widelands_map_extradata_data_packet.cc 2013-03-01 20:41:38 +0000
+++ src/map_io/widelands_map_extradata_data_packet.cc 2013-03-05 01:51:25 +0000
@@ -67,6 +67,7 @@
if (fs.IsDirectory(pname->c_str())) // Might be a dir, maybe CVS
continue;
+<<<<<<< TREE
FileRead fr;
fr.Open(fs, pname->c_str());
@@ -83,6 +84,23 @@
image = g_gr->images().get(hash);
}
assert(image);
+=======
+ const std::string hash = std::string("map:") + FileSystem::FS_Filename(pname->c_str());
+ const Image* image = NULL;
+ if (!g_gr->images().has(hash)) {
+ FileRead fr;
+
+ fr.Open(fs, pname->c_str());
+ SDL_Surface * const surf =
+ IMG_Load_RW(SDL_RWFromMem(fr.Data(0), fr.GetSize()), 1);
+ if (!surf)
+ continue; // Illegal pic. Skip it.
+ image = g_gr->images().insert(new_in_memory_image(hash, Surface::create(surf)));
+ } else {
+ image = g_gr->images().get(hash);
+ }
+ assert(image);
+>>>>>>> MERGE-SOURCE
// OK, the pic is now known to the game. But when the game is
// saved, this data has to be regenerated.
=== modified file 'src/map_io/widelands_map_players_view_data_packet.cc'
--- src/map_io/widelands_map_players_view_data_packet.cc 2013-02-10 19:36:24 +0000
+++ src/map_io/widelands_map_players_view_data_packet.cc 2013-03-05 01:51:25 +0000
@@ -102,39 +102,37 @@
// bl------br
struct Map_Object_Data {
- Map_Object_Data() : map_object_descr(0), csi(0) {}
+ Map_Object_Data() : map_object_descr(0) {}
const Map_Object_Descr * map_object_descr;
- const Player::Constructionsite_Information * csi;
+ Player::Constructionsite_Information csi;
};
-inline static Map_Object_Data * read_unseen_immovable
+inline static Map_Object_Data read_unseen_immovable
(const Editor_Game_Base & egbase,
BitInBuffer<2> & immovable_kinds_file,
FileRead & immovables_file,
uint8_t & version
)
{
- Map_Object_Data * m = new Map_Object_Data;
+ Map_Object_Data m;
try {
switch (immovable_kinds_file.get()) {
case 0: // The player sees no immovable.
- m->map_object_descr = 0; break;
+ m.map_object_descr = 0; break;
case 1: // The player sees a tribe or world immovable.
- m->map_object_descr = &immovables_file.Immovable_Type(egbase); break;
+ m.map_object_descr = &immovables_file.Immovable_Type(egbase); break;
case 2: // The player sees a flag.
- m->map_object_descr = &g_flag_descr; break;
+ m.map_object_descr = &g_flag_descr; break;
case 3: // The player sees a building.
- m->map_object_descr = &immovables_file.Building_Type (egbase);
+ m.map_object_descr = &immovables_file.Building_Type (egbase);
if (version > 1) {
// Read data from immovables file
if (immovables_file.Unsigned8() == 1) { // the building is a constructionsite
- Player::Constructionsite_Information * csi = new Player::Constructionsite_Information;
- csi->becomes = &immovables_file.Building_Type(egbase);
+ m.csi.becomes = &immovables_file.Building_Type(egbase);
if (immovables_file.Unsigned8() == 1)
- csi->was = &immovables_file.Building_Type(egbase);
- csi->totaltime = immovables_file.Unsigned32();
- csi->completedtime = immovables_file.Unsigned32();
- m->csi = csi;
+ m.csi.was = &immovables_file.Building_Type(egbase);
+ m.csi.totaltime = immovables_file.Unsigned32();
+ m.csi.completedtime = immovables_file.Unsigned32();
}
}
break;
@@ -485,11 +483,11 @@
static_cast<long unsigned int>(owners_file.GetPos() - 1),
f.x, f.y, owner, nr_players);
- Map_Object_Data * mod =
+ Map_Object_Data mod =
read_unseen_immovable
(egbase, node_immovable_kinds_file, node_immovables_file, node_immovables_file_version);
- f_player_field.map_object_descr[TCoords<>::None] = mod->map_object_descr;
- f_player_field.constructionsite[TCoords<>::None] = mod->csi;
+ f_player_field.map_object_descr[TCoords<>::None] = mod.map_object_descr;
+ f_player_field.constructionsite = mod.csi;
// if there is a border file, read in whether this field had a border the last time it was seen
if (borders) {
@@ -546,12 +544,11 @@
"while reading terrain",
plnum, terrains_filename, f.x, f.y);
}
- Map_Object_Data * mod =
+ Map_Object_Data mod =
read_unseen_immovable
(egbase, triangle_immovable_kinds_file, triangle_immovables_file,
triangle_immovables_file_version);
- f_player_field.map_object_descr[TCoords<>::D] = mod->map_object_descr;
- f_player_field.constructionsite[TCoords<>::D] = mod->csi;
+ f_player_field.map_object_descr[TCoords<>::D] = mod.map_object_descr;
}
if (f_seen | br_seen | r_seen) {
@@ -571,12 +568,11 @@
"while reading terrain",
plnum, terrains_filename, f.x, f.y);
}
- Map_Object_Data * mod =
+ Map_Object_Data mod =
read_unseen_immovable
(egbase, triangle_immovable_kinds_file, triangle_immovables_file,
triangle_immovables_file_version);
- f_player_field.map_object_descr[TCoords<>::R] = mod->map_object_descr;
- f_player_field.constructionsite[TCoords<>::R] = mod->csi;
+ f_player_field.map_object_descr[TCoords<>::R] = mod.map_object_descr;
}
{ // edges
@@ -727,7 +723,7 @@
BitOutBuffer<2> & immovable_kinds_file, FileWrite & immovables_file)
{
Map_Object_Descr const * const map_object_descr = map_object_data->map_object_descr;
- Player::Constructionsite_Information const * const csi = map_object_data->csi;
+ const Player::Constructionsite_Information & csi = map_object_data->csi;
assert(not Road::IsRoadDescr(map_object_descr));
uint8_t immovable_kind;
@@ -741,21 +737,21 @@
else if (upcast(Building_Descr const, building_descr, map_object_descr)) {
immovable_kind = 3;
immovables_file.Building_Type(*building_descr);
- if (!csi)
+ if (!csi.becomes)
immovables_file.Unsigned8(0);
else {
// the building is a constructionsite
immovables_file.Unsigned8(1);
- immovables_file.Building_Type(*csi->becomes);
- if (!csi->was)
+ immovables_file.Building_Type(*csi.becomes);
+ if (!csi.was)
immovables_file.Unsigned8(0);
else {
// constructionsite is an enhancement, therefor we write down the enhancement
immovables_file.Unsigned8(1);
- immovables_file.Building_Type(*csi->was);
+ immovables_file.Building_Type(*csi.was);
}
- immovables_file.Unsigned32(csi->totaltime);
- immovables_file.Unsigned32(csi->completedtime);
+ immovables_file.Unsigned32(csi.totaltime);
+ immovables_file.Unsigned32(csi.completedtime);
}
} else assert(false);
immovable_kinds_file.put(immovable_kind);
@@ -827,10 +823,10 @@
(f_player_field.time_node_last_unseen);
assert(f_player_field.owner < 0x20);
owners_file.Unsigned8(f_player_field.owner);
- Map_Object_Data * mod = new Map_Object_Data;
- mod->map_object_descr = f_player_field.map_object_descr[TCoords<>::None];
- mod->csi = f_player_field.constructionsite[TCoords<>::None];
- write_unseen_immovable(mod, node_immovable_kinds_file, node_immovables_file);
+ Map_Object_Data mod;
+ mod.map_object_descr = f_player_field.map_object_descr[TCoords<>::None];
+ mod.csi = f_player_field.constructionsite;
+ write_unseen_immovable(&mod, node_immovable_kinds_file, node_immovables_file);
// write whether this field had a border the last time it was seen
border_file.put(f_player_field.border ? 1 : 0);
@@ -847,10 +843,9 @@
(f_everseen | bl_everseen | br_everseen))
{
terrains_file.put(f_player_field.terrains.d);
- Map_Object_Data * mod = new Map_Object_Data;
- mod->map_object_descr = f_player_field.map_object_descr[TCoords<>::D];
- mod->csi = f_player_field.constructionsite[TCoords<>::D];
- write_unseen_immovable(mod, triangle_immovable_kinds_file, triangle_immovables_file);
+ Map_Object_Data mod;
+ mod.map_object_descr = f_player_field.map_object_descr[TCoords<>::D];
+ write_unseen_immovable(&mod, triangle_immovable_kinds_file, triangle_immovables_file);
}
if
// the player does not see the R triangle now but has
@@ -859,10 +854,9 @@
(f_everseen | br_everseen | r_everseen))
{
terrains_file.put(f_player_field.terrains.r);
- Map_Object_Data * mod = new Map_Object_Data;
- mod->map_object_descr = f_player_field.map_object_descr[TCoords<>::R];
- mod->csi = f_player_field.constructionsite[TCoords<>::R];
- write_unseen_immovable(mod, triangle_immovable_kinds_file, triangle_immovables_file);
+ Map_Object_Data mod;
+ mod.map_object_descr = f_player_field.map_object_descr[TCoords<>::R];
+ write_unseen_immovable(&mod, triangle_immovable_kinds_file, triangle_immovables_file);
}
// edges
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2013-02-25 17:03:31 +0000
+++ src/network/nethost.cc 2013-03-05 01:51:25 +0000
@@ -670,6 +670,7 @@
delete d->promoter;
delete d;
+ delete file;
}
const std::string & NetHost::getLocalPlayername() const
@@ -777,16 +778,15 @@
}
d->dedicated_start = false;
} else {
- Fullscreen_Menu_LaunchMPG * lm = new Fullscreen_Menu_LaunchMPG(&d->hp, this);
- lm->setChatProvider(d->chat);
- const int32_t code = lm->run();
+ Fullscreen_Menu_LaunchMPG lm(&d->hp, this);
+ lm.setChatProvider(d->chat);
+ const int32_t code = lm.run();
if (code <= 0) {
// if this is an internet game, tell the metaserver that client is back in the lobby.
if (m_internet)
InternetGaming::ref().set_game_done();
return;
}
- delete lm;
}
// if this is an internet game, tell the metaserver that the game started
@@ -810,7 +810,7 @@
try {
// NOTE loaderUI will stay uninitialized, if this is run as dedicated, so all called functions need
// NOTE to check whether the pointer is valid.
- UI::ProgressWindow * loaderUI = 0;
+ boost::scoped_ptr<UI::ProgressWindow> loaderUI(0);
GameTips * tips = 0;
if (m_is_dedicated) {
log ("[Dedicated] Starting the game...\n");
@@ -826,7 +826,7 @@
setWinCondition(gpdp.get_win_condition());
}
} else {
- loaderUI = new UI::ProgressWindow ("pics/progress.png");
+ loaderUI.reset(new UI::ProgressWindow ("pics/progress.png"));
std::vector<std::string> tipstext;
tipstext.push_back("general_game");
tipstext.push_back("multiplayer");
@@ -865,9 +865,9 @@
}
if (!d->settings.savegame) // new game
- game.init_newgame (loaderUI, d->settings);
+ game.init_newgame (loaderUI.get(), d->settings);
else // savegame
- game.init_savegame(loaderUI, d->settings);
+ game.init_savegame(loaderUI.get(), d->settings);
d->pseudo_networktime = game.get_gametime();
d->time.reset(d->pseudo_networktime);
d->lastframe = WLApplication::get()->get_time();
@@ -892,7 +892,7 @@
DedicatedLog::get()->game_start(clients, game.map().get_name());
}
game.run
- (loaderUI,
+ (loaderUI.get(),
d->settings.savegame ? Widelands::Game::Loaded : d->settings.scenario ?
Widelands::Game::NewMPScenario : Widelands::Game::NewNonScenario);
=== modified file 'src/ui_basic/radiobutton.h'
--- src/ui_basic/radiobutton.h 2013-02-09 23:18:23 +0000
+++ src/ui_basic/radiobutton.h 2013-03-05 01:51:25 +0000
@@ -39,6 +39,8 @@
(Panel * parent, Point, const Image* pic, Radiogroup &, int32_t id);
~Radiobutton();
+ Radiobutton * next_button() {return m_nextbtn;}
+
private:
void clicked();
@@ -67,7 +69,7 @@
int32_t get_state() const throw () {return m_state;}
void set_state(int32_t state);
void set_enabled(bool);
- Radiobutton * get_button(int32_t id);
+ Radiobutton * get_first_button() {return m_buttons;}
private:
Radiobutton * m_buttons; // linked list of buttons (not sorted)
int32_t m_highestid;
=== modified file 'src/ui_fsmenu/campaign_select.cc'
--- src/ui_fsmenu/campaign_select.cc 2013-02-09 23:36:30 +0000
+++ src/ui_fsmenu/campaign_select.cc 2013-03-05 01:51:25 +0000
@@ -26,6 +26,8 @@
#include "wexception.h"
#include "map_io/widelands_map_loader.h"
+#include <boost/scoped_ptr.hpp>
+
/*
* UI 1 - Selection of Campaign
@@ -352,7 +354,7 @@
Widelands::Map map;
- Widelands::Map_Loader * const ml = map.get_correct_loader(campmapfile.c_str());
+ boost::scoped_ptr<Widelands::Map_Loader> ml(map.get_correct_loader(campmapfile.c_str()));
if (!ml) {
throw wexception
(_("Invalid path to file in cconfig: %s"), campmapfile.c_str());
=== modified file 'src/ui_fsmenu/launchMPG.cc'
--- src/ui_fsmenu/launchMPG.cc 2013-02-25 17:03:31 +0000
+++ src/ui_fsmenu/launchMPG.cc 2013-03-05 01:51:25 +0000
@@ -237,6 +237,7 @@
delete m_mpsg;
if (m_help)
delete m_help;
+ delete m_chat;
}
=== modified file 'src/ui_fsmenu/launchSPG.h'
--- src/ui_fsmenu/launchSPG.h 2012-02-15 21:25:34 +0000
+++ src/ui_fsmenu/launchSPG.h 2013-03-05 01:51:25 +0000
@@ -30,7 +30,6 @@
#include <string>
struct ChatProvider;
-struct GameChatPanel;
struct GameController;
struct GameSettingsProvider;
struct PlayerDescriptionGroup;
=== modified file 'src/wui/multiplayersetupgroup.cc'
--- src/wui/multiplayersetupgroup.cc 2013-02-10 19:36:24 +0000
+++ src/wui/multiplayersetupgroup.cc 2013-03-05 01:51:25 +0000
@@ -26,7 +26,6 @@
#include "logic/game.h"
#include "logic/player.h"
#include "logic/tribe.h"
-#include "network/network_player_settings_backend.h"
#include "profile/profile.h"
#include "wexception.h"
@@ -389,6 +388,7 @@
:
UI::Panel(parent, x, y, w, h),
s(settings),
+npsb(new NetworkPlayerSettingsBackend(s)),
clientbox(this, 0, buth, UI::Box::Vertical, w / 3, h - buth),
playerbox(this, w * 6 / 15, buth, UI::Box::Vertical, w * 9 / 15, h - buth),
m_buth(buth),
@@ -460,12 +460,11 @@
playerbox.set_size(w * 9 / 15, h - buth);
p.resize(MAX_PLAYERS);
- NetworkPlayerSettingsBackend * npsb = new NetworkPlayerSettingsBackend(s);
for (uint8_t i = 0; i < p.size(); ++i) {
p.at(i) = new MultiPlayerPlayerGroup
(&playerbox, i,
0, 0, playerbox.get_w(), buth,
- s, npsb, UI::Font::get(fname, fsize),
+ s, npsb.get(), UI::Font::get(fname, fsize),
m_tribepics, m_tribenames);
playerbox.add(&*p.at(i), 1);
}
=== modified file 'src/wui/multiplayersetupgroup.h'
--- src/wui/multiplayersetupgroup.h 2013-02-10 19:36:24 +0000
+++ src/wui/multiplayersetupgroup.h 2013-03-05 01:51:25 +0000
@@ -24,6 +24,7 @@
#include <string>
#include "constants.h"
+#include "network/network_player_settings_backend.h"
#include "ui_basic/box.h"
#include "ui_basic/panel.h"
#include "ui_basic/textarea.h"
@@ -56,6 +57,7 @@
private:
GameSettingsProvider * const s;
+ boost::scoped_ptr<NetworkPlayerSettingsBackend> npsb;
std::vector<MultiPlayerClientGroup *> c;
std::vector<MultiPlayerPlayerGroup *> p;
UI::Box clientbox, playerbox;
=== modified file 'src/wui/waresqueuedisplay.cc'
--- src/wui/waresqueuedisplay.cc 2013-02-09 23:36:30 +0000
+++ src/wui/waresqueuedisplay.cc 2013-03-05 01:51:25 +0000
@@ -79,6 +79,7 @@
WaresQueueDisplay::~WaresQueueDisplay()
{
+ delete m_priority_radiogroup;
}
/**
@@ -161,24 +162,33 @@
*/
void WaresQueueDisplay::update_priority_buttons()
{
- delete m_priority_radiogroup;
- if (m_cache_size <= 0 or m_show_only)
- return;
-
- m_priority_radiogroup = new UI::Radiogroup();
+ if (m_cache_size <= 0 or m_show_only) {
+ delete m_priority_radiogroup;
+ m_priority_radiogroup = 0;
+ }
Point pos = Point(m_cache_size * CellWidth + Border, 0);
pos.x = (m_cache_size + 2) * (CellWidth + CellSpacing) + Border;
pos.y = Border + (m_total_height - 2 * Border - 3 * PriorityButtonSize) / 2;
- m_priority_radiogroup->add_button
- (this, pos, g_gr->images().get(pic_priority_high), _("Highest priority"));
- pos.y += PriorityButtonSize;
- m_priority_radiogroup->add_button
- (this, pos, g_gr->images().get(pic_priority_normal), _("Normal priority"));
- pos.y += PriorityButtonSize;
- m_priority_radiogroup->add_button
- (this, pos, g_gr->images().get(pic_priority_low), _("Lowest priority"));
+ if (m_priority_radiogroup) {
+ pos.y += 2 * PriorityButtonSize;
+ for (UI::Radiobutton * btn = m_priority_radiogroup->get_first_button(); btn; btn = btn->next_button()) {
+ btn->set_pos(pos);
+ pos.y -= PriorityButtonSize;
+ }
+ } else {
+ m_priority_radiogroup = new UI::Radiogroup();
+
+ m_priority_radiogroup->add_button
+ (this, pos, g_gr->images().get(pic_priority_high), _("Highest priority"));
+ pos.y += PriorityButtonSize;
+ m_priority_radiogroup->add_button
+ (this, pos, g_gr->images().get(pic_priority_normal), _("Normal priority"));
+ pos.y += PriorityButtonSize;
+ m_priority_radiogroup->add_button
+ (this, pos, g_gr->images().get(pic_priority_low), _("Lowest priority"));
+ }
int32_t priority = m_building.get_priority(m_ware_type, m_ware_index, false);
switch (priority) {