Skip to content

Commit 09d3594

Browse files
Fix Lua-invoked dialogs not showing before prestart
Instead of passing the video object to the Lua kernel, the game now simply fetches the video singleton when displaying dialogs. This means there is no longer any need to store a reference to the video object.
1 parent a0b77b1 commit 09d3594

11 files changed

+18
-37
lines changed

src/game_state.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ game_state::game_state(const config & level, play_controller & pc, const tdata_c
4848
tod_manager_(level),
4949
pathfind_manager_(new pathfind::manager(level)),
5050
reports_(new reports()),
51-
lua_kernel_(new game_lua_kernel(nullptr, *this, pc, *reports_)),
51+
lua_kernel_(new game_lua_kernel(*this, pc, *reports_)),
5252
events_manager_(new game_events::manager()),
5353
//TODO: this construct units (in dimiss undo action) but resrouces:: are not available yet,
5454
// so we might want to move the innitialisation of undo_stack_ to game_state::init
@@ -66,13 +66,14 @@ game_state::game_state(const config & level, play_controller & pc, const tdata_c
6666
end_level_data_ = el_data;
6767
}
6868
}
69+
6970
game_state::game_state(const config & level, play_controller & pc, game_board& board) :
7071
gamedata_(level),
7172
board_(board),
7273
tod_manager_(level),
7374
pathfind_manager_(new pathfind::manager(level)),
7475
reports_(new reports()),
75-
lua_kernel_(new game_lua_kernel(nullptr, *this, pc, *reports_)),
76+
lua_kernel_(new game_lua_kernel(*this, pc, *reports_)),
7677
events_manager_(new game_events::manager()),
7778
player_number_(level["playing_team"].to_int() + 1),
7879
end_level_data_(),

src/generators/lua_map_generator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ lua_map_generator::lua_map_generator(const config & cfg)
4040
}
4141
}
4242

43-
void lua_map_generator::user_config(CVideo & v)
43+
void lua_map_generator::user_config()
4444
{
45-
lk_.set_video(&v);
4645
try {
4746
lk_.user_config(user_config_.c_str(), generator_data_);
4847
} catch (game::lua_error & e) {

src/generators/lua_map_generator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class lua_map_generator : public map_generator {
4141

4242
std::string config_name() const { return config_name_; }
4343

44-
virtual void user_config(CVideo & v);
44+
virtual void user_config();
4545
virtual std::string create_map(boost::optional<uint32_t> randomseed);
4646
virtual config create_scenario(boost::optional<uint32_t> randomseed);
4747

src/scripting/application_lua_kernel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ static int intf_delay(lua_State* L)
9898
return 0;
9999
}
100100

101-
application_lua_kernel::application_lua_kernel(CVideo * ptr)
102-
: lua_kernel_base(ptr)
101+
application_lua_kernel::application_lua_kernel()
102+
: lua_kernel_base()
103103
{
104104
lua_getglobal(mState, "wesnoth");
105105
lua_pushcfunction(mState, intf_delay);

src/scripting/application_lua_kernel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct lua_State;
2929

3030
class application_lua_kernel : public lua_kernel_base {
3131
public:
32-
application_lua_kernel(CVideo *);
32+
application_lua_kernel();
3333

3434
virtual std::string my_name() { return "Application Lua Kernel"; }
3535

src/scripting/game_lua_kernel.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,8 +4055,8 @@ const game_events::queued_event & game_lua_kernel::get_event_info() {
40554055
}
40564056

40574057

4058-
game_lua_kernel::game_lua_kernel(CVideo * video, game_state & gs, play_controller & pc, reports & reports_object)
4059-
: lua_kernel_base(video)
4058+
game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports & reports_object)
4059+
: lua_kernel_base()
40604060
, game_display_(nullptr)
40614061
, game_state_(gs)
40624062
, play_controller_(pc)
@@ -4372,9 +4372,6 @@ void game_lua_kernel::initialize(const config& level)
43724372

43734373
void game_lua_kernel::set_game_display(game_display * gd) {
43744374
game_display_ = gd;
4375-
if (gd) {
4376-
set_video(&gd->video());
4377-
}
43784375
}
43794376

43804377
/// These are the child tags of [scenario] (and the like) that are handled

src/scripting/game_lua_kernel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class game_lua_kernel : public lua_kernel_base
189189
lua_unit* userdata in its stack that prevents it from beeing collected.
190190
*/
191191
int map_locked_;
192-
game_lua_kernel(CVideo *, game_state &, play_controller &, reports &);
192+
game_lua_kernel(game_state &, play_controller &, reports &);
193193

194194
void set_game_display(game_display * gd);
195195

src/scripting/lua_kernel_base.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "scripting/push_check.hpp"
3838

3939
#include "version.hpp" // for do_version_check, etc
40+
#include "video.hpp"
4041

4142
#include "serialization/string_utils.hpp"
4243
#include "utils/functional.hpp"
@@ -122,32 +123,20 @@ int video_dispatch(lua_State *L) {
122123
// The show-dialog call back is here implemented as a method of lua kernel, since it needs a pointer to external object CVideo
123124
int lua_kernel_base::video_dispatch_impl(lua_State* L, lua_kernel_base::video_function callback)
124125
{
125-
if (!video_) {
126-
ERR_LUA << "Cannot show dialog, no video object is available to this lua kernel.";
127-
lua_error(L);
128-
return 0;
129-
}
130-
131-
return callback(L, *video_);
126+
return callback(L, CVideo::get_singleton());
132127
}
133128

134129
// The show lua console callback is similarly a method of lua kernel
135130
int lua_kernel_base::intf_show_lua_console(lua_State *L)
136131
{
137-
if (!video_) {
138-
ERR_LUA << "Cannot show dialog, no video object is available to this lua kernel.";
139-
lua_error(L);
140-
return 0;
141-
}
142-
143132
if (cmd_log_.external_log_) {
144133
std::string message = "There is already an external logger attached to this lua kernel, you cannot open the lua console right now.";
145134
log_error(message.c_str());
146135
cmd_log_ << message << "\n";
147136
return 0;
148137
}
149138

150-
return lua_gui2::show_lua_console(L, *video_, this);
139+
return lua_gui2::show_lua_console(L, CVideo::get_singleton(), this);
151140
}
152141

153142
static int impl_name_generator_call(lua_State *L)
@@ -237,9 +226,8 @@ int dispatch(lua_State *L) {
237226
extern void push_error_handler(lua_State *L);
238227

239228
// Ctor, initialization
240-
lua_kernel_base::lua_kernel_base(CVideo * video)
229+
lua_kernel_base::lua_kernel_base()
241230
: mState(luaL_newstate())
242-
, video_(video)
243231
, cmd_log_()
244232
{
245233
get_lua_kernel_base_ptr(mState) = this;

src/scripting/lua_kernel_base.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class config;
2727

2828
class lua_kernel_base {
2929
public:
30-
lua_kernel_base(CVideo * ptr);
30+
lua_kernel_base();
3131
virtual ~lua_kernel_base();
3232

3333
/** Runs a [lua] tag. Doesn't throw lua_error.*/
@@ -65,8 +65,6 @@ class lua_kernel_base {
6565

6666
typedef std::function<void(char const*, char const*)> error_handler;
6767

68-
void set_video(CVideo * ptr) { video_ = ptr; }
69-
7068
template<typename T>
7169
static T& get_lua_kernel(lua_State *L)
7270
{
@@ -78,8 +76,6 @@ class lua_kernel_base {
7876
protected:
7977
lua_State *mState;
8078

81-
CVideo * video_;
82-
8379
/** Log implementation */
8480
struct command_log {
8581

src/scripting/mapgen_lua_kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int intf_find_path(lua_State *L)
118118

119119

120120
mapgen_lua_kernel::mapgen_lua_kernel()
121-
: lua_kernel_base(nullptr)
121+
: lua_kernel_base()
122122
, random_seed_()
123123
, default_rng_()
124124
{

src/wesnoth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static int do_gameloop(const std::vector<std::string>& args)
662662

663663
LOG_CONFIG << "time elapsed: "<< (SDL_GetTicks() - start_ticks) << " ms\n";
664664

665-
plugins_manager plugins_man(new application_lua_kernel(&game->video()));
665+
plugins_manager plugins_man(new application_lua_kernel);
666666

667667
plugins_context::Reg const callbacks[] = {
668668
{ "play_multiplayer", std::bind(&game_launcher::play_multiplayer, game.get(), game_launcher::MP_CONNECT)},

0 commit comments

Comments
 (0)