From: Mathnerd314 Date: Sat, 13 Jun 2009 21:02:52 +0000 (+0000) Subject: * Small miniswig update to use less dependencies X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=833262574362dd0bc62a6bc5765edfa9f257f55c;p=supertux.git * Small miniswig update to use less dependencies * Add functions play_demo, record_demo, and debug_worldmap_ghost for buggy worldmaps * Doxygen comments for file_system.hpp (forgot previously) SVN-Revision: 5895 --- diff --git a/data/scripts/default.nut b/data/scripts/default.nut index a4f3aff82..86670578a 100644 --- a/data/scripts/default.nut +++ b/data/scripts/default.nut @@ -3,6 +3,15 @@ * and variables you define here can be used in all threads */ +//Create Level table +Level <- { + finish=Level_finish, + spawn=Level_spawn, + flip_vertically=Level_flip_vertically, + toggle_pause=Level_toggle_pause, + edit=Level_edit +}; + function end_level() { diff --git a/src/file_system.hpp b/src/file_system.hpp index b8211884c..b92c4e11c 100644 --- a/src/file_system.hpp +++ b/src/file_system.hpp @@ -25,7 +25,14 @@ namespace FileSystem { + /** + * returns the path of the directory the file is in + */ std::string dirname(const std::string& filename); + + /** + * returns the name of the file + */ std::string basename(const std::string& filename); /** diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 95d860761..143d883ed 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -34,6 +34,7 @@ #include "log.hpp" #include "mainloop.hpp" #include "worldmap/worldmap.hpp" +#include "worldmap/tux.hpp" #include "world.hpp" #include "sector.hpp" #include "gameconfig.hpp" @@ -166,6 +167,16 @@ void debug_draw_solids_only(bool enable) Sector::draw_solids_only = enable; } +void debug_worldmap_ghost(bool enable) +{ + using namespace WorldMapNS; + + if(WorldMap::current() == NULL) + throw std::runtime_error("Can't change ghost mode without active WorldMap"); + + WorldMap::current()->get_tux()->set_ghost_mode(enable); +} + void save_state() { using namespace WorldMapNS; @@ -296,4 +307,29 @@ void set_game_speed(float speed) ::game_speed = speed; } +void record_demo(const std::string& filename) +{ + if (GameSession::current() == 0) + { + log_info << "No game session" << std::endl; + return; + } + GameSession::current()->restart_level(); + GameSession::current()->record_demo(filename); +} + +void play_demo(const std::string& filename) +{ + if (GameSession::current() == 0) + { + log_info << "No game session" << std::endl; + return; + } + // Reset random seed + config->random_seed = GameSession::current()->get_demo_random_seed(filename); + config->random_seed = systemRandom.srand(config->random_seed); + GameSession::current()->restart_level(); + GameSession::current()->play_demo(filename); +} + } diff --git a/src/scripting/functions.hpp b/src/scripting/functions.hpp index 3cff6f9f1..4496c1379 100644 --- a/src/scripting/functions.hpp +++ b/src/scripting/functions.hpp @@ -130,6 +130,11 @@ void debug_show_fps(bool enable); void debug_draw_solids_only(bool enable); /** + * enable/disable worldmap ghost mode + */ +void debug_worldmap_ghost(bool enable); + +/** * Changes music to musicfile */ void play_music(const std::string& musicfile); @@ -199,6 +204,16 @@ void quit(); */ int rand(); +/** + * Record a demo to the given file. + */ +void record_demo(const std::string& filename); + +/** + * Play back a demo from the given file. + */ +void play_demo(const std::string& filename); + } #endif diff --git a/src/scripting/level.cpp b/src/scripting/level.cpp index 8967741f1..48b8d3d23 100644 --- a/src/scripting/level.cpp +++ b/src/scripting/level.cpp @@ -27,14 +27,8 @@ namespace Scripting { - Level::Level() - {} - - Level::~Level() - {} - void - Level::finish(bool win) + Level_finish(bool win) { if(GameSession::current() == NULL) return; @@ -43,7 +37,7 @@ namespace Scripting } void - Level::spawn(const std::string& sector, const std::string& spawnpoint) + Level_spawn(const std::string& sector, const std::string& spawnpoint) { if(GameSession::current() == NULL) return; @@ -52,14 +46,14 @@ namespace Scripting } void - Level::flip_vertically() + Level_flip_vertically() { FlipLevelTransformer flip_transformer; flip_transformer.transform(GameSession::current()->get_current_level()); } void - Level::toggle_pause() + Level_toggle_pause() { if(GameSession::current() == NULL) return; @@ -67,7 +61,7 @@ namespace Scripting } void - Level::edit(bool edit_mode) + Level_edit(bool edit_mode) { if(GameSession::current() == NULL) return; GameSession::current()->set_editmode(edit_mode); diff --git a/src/scripting/level.hpp b/src/scripting/level.hpp index b7d91a248..a72f4dcba 100644 --- a/src/scripting/level.hpp +++ b/src/scripting/level.hpp @@ -23,27 +23,17 @@ namespace Scripting { -class Level -{ -public: -#ifndef SCRIPTING_API - Level(); - ~Level(); -#endif - /** Instantly finish the currently played level */ - void finish(bool win); + void Level_finish(bool win); /** spawn tux at specified sector and spawnpoint */ - void spawn(const std::string& sector, const std::string& spawnpoint); + void Level_spawn(const std::string& sector, const std::string& spawnpoint); /** Flip level vertically */ - void flip_vertically(); + void Level_flip_vertically(); /** toggle pause */ - void toggle_pause(); + void Level_toggle_pause(); /** Switch to and from edit mode */ - void edit(bool edit_mode); -}; - + void Level_edit(bool edit_mode); } #endif diff --git a/src/scripting/squirrel_util.cpp b/src/scripting/squirrel_util.cpp index a5b1c1dda..6437ae58a 100644 --- a/src/scripting/squirrel_util.cpp +++ b/src/scripting/squirrel_util.cpp @@ -92,9 +92,6 @@ void init_squirrel(bool enable_debugger) // register supertux API register_supertux_wrapper(global_vm); - // TODO remove this at some point... it should just be functions not an object - expose_object(global_vm, -1, new Scripting::Level(), "Level", true); - sq_pop(global_vm, 1); // register print function diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index d0683cda9..b2f247bca 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -367,153 +367,6 @@ static SQInteger Camera_scroll_to_wrapper(HSQUIRRELVM vm) } -static SQInteger Level_release_hook(SQUserPointer ptr, SQInteger ) -{ - Scripting::Level* _this = reinterpret_cast (ptr); - delete _this; - return 0; -} - -static SQInteger Level_finish_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { - sq_throwerror(vm, _SC("'finish' called without instance")); - return SQ_ERROR; - } - Scripting::Level* _this = reinterpret_cast (data); - SQBool arg0; - if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a bool")); - return SQ_ERROR; - } - - try { - _this->finish(arg0 == SQTrue); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'finish'")); - return SQ_ERROR; - } - -} - -static SQInteger Level_spawn_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { - sq_throwerror(vm, _SC("'spawn' called without instance")); - return SQ_ERROR; - } - Scripting::Level* _this = reinterpret_cast (data); - const SQChar* arg0; - if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a string")); - return SQ_ERROR; - } - const SQChar* arg1; - if(SQ_FAILED(sq_getstring(vm, 3, &arg1))) { - sq_throwerror(vm, _SC("Argument 2 not a string")); - return SQ_ERROR; - } - - try { - _this->spawn(arg0, arg1); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'spawn'")); - return SQ_ERROR; - } - -} - -static SQInteger Level_flip_vertically_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { - sq_throwerror(vm, _SC("'flip_vertically' called without instance")); - return SQ_ERROR; - } - Scripting::Level* _this = reinterpret_cast (data); - - try { - _this->flip_vertically(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'flip_vertically'")); - return SQ_ERROR; - } - -} - -static SQInteger Level_toggle_pause_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { - sq_throwerror(vm, _SC("'toggle_pause' called without instance")); - return SQ_ERROR; - } - Scripting::Level* _this = reinterpret_cast (data); - - try { - _this->toggle_pause(); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'toggle_pause'")); - return SQ_ERROR; - } - -} - -static SQInteger Level_edit_wrapper(HSQUIRRELVM vm) -{ - SQUserPointer data; - if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) { - sq_throwerror(vm, _SC("'edit' called without instance")); - return SQ_ERROR; - } - Scripting::Level* _this = reinterpret_cast (data); - SQBool arg0; - if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { - sq_throwerror(vm, _SC("Argument 1 not a bool")); - return SQ_ERROR; - } - - try { - _this->edit(arg0 == SQTrue); - - return 0; - - } catch(std::exception& e) { - sq_throwerror(vm, e.what()); - return SQ_ERROR; - } catch(...) { - sq_throwerror(vm, _SC("Unexpected exception while executing function 'edit'")); - return SQ_ERROR; - } - -} - static SQInteger ScriptedObject_release_hook(SQUserPointer ptr, SQInteger ) { Scripting::ScriptedObject* _this = reinterpret_cast (ptr); @@ -3129,6 +2982,118 @@ static SQInteger WillOWisp_stop_moving_wrapper(HSQUIRRELVM vm) } +static SQInteger Level_finish_wrapper(HSQUIRRELVM vm) +{ + SQBool arg0; + if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a bool")); + return SQ_ERROR; + } + + try { + Scripting::Level_finish(arg0 == SQTrue); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_finish'")); + return SQ_ERROR; + } + +} + +static SQInteger Level_spawn_wrapper(HSQUIRRELVM vm) +{ + const SQChar* arg0; + if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a string")); + return SQ_ERROR; + } + const SQChar* arg1; + if(SQ_FAILED(sq_getstring(vm, 3, &arg1))) { + sq_throwerror(vm, _SC("Argument 2 not a string")); + return SQ_ERROR; + } + + try { + Scripting::Level_spawn(arg0, arg1); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_spawn'")); + return SQ_ERROR; + } + +} + +static SQInteger Level_flip_vertically_wrapper(HSQUIRRELVM vm) +{ + (void) vm; + + try { + Scripting::Level_flip_vertically(); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_flip_vertically'")); + return SQ_ERROR; + } + +} + +static SQInteger Level_toggle_pause_wrapper(HSQUIRRELVM vm) +{ + (void) vm; + + try { + Scripting::Level_toggle_pause(); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_toggle_pause'")); + return SQ_ERROR; + } + +} + +static SQInteger Level_edit_wrapper(HSQUIRRELVM vm) +{ + SQBool arg0; + if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a bool")); + return SQ_ERROR; + } + + try { + Scripting::Level_edit(arg0 == SQTrue); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'Level_edit'")); + return SQ_ERROR; + } + +} + static SQInteger display_wrapper(HSQUIRRELVM vm) { return Scripting::display(vm); @@ -3519,6 +3484,29 @@ static SQInteger debug_draw_solids_only_wrapper(HSQUIRRELVM vm) } +static SQInteger debug_worldmap_ghost_wrapper(HSQUIRRELVM vm) +{ + SQBool arg0; + if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a bool")); + return SQ_ERROR; + } + + try { + Scripting::debug_worldmap_ghost(arg0 == SQTrue); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'debug_worldmap_ghost'")); + return SQ_ERROR; + } + +} + static SQInteger play_music_wrapper(HSQUIRRELVM vm) { const SQChar* arg0; @@ -3801,6 +3789,52 @@ static SQInteger rand_wrapper(HSQUIRRELVM vm) } +static SQInteger record_demo_wrapper(HSQUIRRELVM vm) +{ + const SQChar* arg0; + if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a string")); + return SQ_ERROR; + } + + try { + Scripting::record_demo(arg0); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'record_demo'")); + return SQ_ERROR; + } + +} + +static SQInteger play_demo_wrapper(HSQUIRRELVM vm) +{ + const SQChar* arg0; + if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) { + sq_throwerror(vm, _SC("Argument 1 not a string")); + return SQ_ERROR; + } + + try { + Scripting::play_demo(arg0); + + return 0; + + } catch(std::exception& e) { + sq_throwerror(vm, e.what()); + return SQ_ERROR; + } catch(...) { + sq_throwerror(vm, _SC("Unexpected exception while executing function 'play_demo'")); + return SQ_ERROR; + } + +} + } // end of namespace Wrapper void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook) { @@ -3854,32 +3888,6 @@ void create_squirrel_instance(HSQUIRRELVM v, Scripting::Camera* object, bool set sq_remove(v, -2); // remove root table } -void create_squirrel_instance(HSQUIRRELVM v, Scripting::Level* object, bool setup_releasehook) -{ - using namespace Wrapper; - - sq_pushroottable(v); - sq_pushstring(v, "Level", -1); - if(SQ_FAILED(sq_get(v, -2))) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'Level'"; - throw SquirrelError(v, msg.str()); - } - - if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'Level'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); // remove object name - - if(setup_releasehook) { - sq_setreleasehook(v, -1, Level_release_hook); - } - - sq_remove(v, -2); // remove root table -} - void create_squirrel_instance(HSQUIRRELVM v, Scripting::ScriptedObject* object, bool setup_releasehook) { using namespace Wrapper; @@ -4276,6 +4284,41 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register constant 'ANCHOR_BOTTOM_RIGHT'"); } + sq_pushstring(v, "Level_finish", -1); + sq_newclosure(v, &Level_finish_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_finish'"); + } + + sq_pushstring(v, "Level_spawn", -1); + sq_newclosure(v, &Level_spawn_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tss"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_spawn'"); + } + + sq_pushstring(v, "Level_flip_vertically", -1); + sq_newclosure(v, &Level_flip_vertically_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_flip_vertically'"); + } + + sq_pushstring(v, "Level_toggle_pause", -1); + sq_newclosure(v, &Level_toggle_pause_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_toggle_pause'"); + } + + sq_pushstring(v, "Level_edit", -1); + sq_newclosure(v, &Level_edit_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'Level_edit'"); + } + sq_pushstring(v, "display", -1); sq_newclosure(v, &display_wrapper, 0); sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "t."); @@ -4409,6 +4452,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'debug_draw_solids_only'"); } + sq_pushstring(v, "debug_worldmap_ghost", -1); + sq_newclosure(v, &debug_worldmap_ghost_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'debug_worldmap_ghost'"); + } + sq_pushstring(v, "play_music", -1); sq_newclosure(v, &play_music_wrapper, 0); sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); @@ -4507,6 +4557,20 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register function 'rand'"); } + sq_pushstring(v, "record_demo", -1); + sq_newclosure(v, &record_demo_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'record_demo'"); + } + + sq_pushstring(v, "play_demo", -1); + sq_newclosure(v, &play_demo_wrapper, 0); + sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|ts"); + if(SQ_FAILED(sq_createslot(v, -3))) { + throw SquirrelError(v, "Couldn't register function 'play_demo'"); + } + // Register class DisplayEffect sq_pushstring(v, "DisplayEffect", -1); if(sq_newclass(v, SQFalse) < 0) { @@ -4606,52 +4670,6 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, "Couldn't register class 'Camera'"); } - // Register class Level - sq_pushstring(v, "Level", -1); - if(sq_newclass(v, SQFalse) < 0) { - std::ostringstream msg; - msg << "Couldn't create new class 'Level'"; - throw SquirrelError(v, msg.str()); - } - sq_pushstring(v, "finish", -1); - sq_newclosure(v, &Level_finish_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'finish'"); - } - - sq_pushstring(v, "spawn", -1); - sq_newclosure(v, &Level_spawn_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tss"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'spawn'"); - } - - sq_pushstring(v, "flip_vertically", -1); - sq_newclosure(v, &Level_flip_vertically_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'flip_vertically'"); - } - - sq_pushstring(v, "toggle_pause", -1); - sq_newclosure(v, &Level_toggle_pause_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|t"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'toggle_pause'"); - } - - sq_pushstring(v, "edit", -1); - sq_newclosure(v, &Level_edit_wrapper, 0); - sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tb"); - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register function 'edit'"); - } - - if(SQ_FAILED(sq_createslot(v, -3))) { - throw SquirrelError(v, "Couldn't register class 'Level'"); - } - // Register class ScriptedObject sq_pushstring(v, "ScriptedObject", -1); if(sq_newclass(v, SQFalse) < 0) { diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index 9deb6ef13..929eaf858 100644 --- a/src/scripting/wrapper.hpp +++ b/src/scripting/wrapper.hpp @@ -7,28 +7,41 @@ #define __supertux_WRAPPER_H__ #include -#include "wrapper.interface.hpp" namespace Scripting { void register_supertux_wrapper(HSQUIRRELVM v); +class DisplayEffect; void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook = false); +class Camera; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Camera* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, Scripting::Level* object, bool setup_releasehook = false); +class ScriptedObject; void create_squirrel_instance(HSQUIRRELVM v, Scripting::ScriptedObject* object, bool setup_releasehook = false); +class Text; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Text* object, bool setup_releasehook = false); +class Player; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Player* object, bool setup_releasehook = false); +class FloatingImage; void create_squirrel_instance(HSQUIRRELVM v, Scripting::FloatingImage* object, bool setup_releasehook = false); +class Platform; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Platform* object, bool setup_releasehook = false); +class Candle; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Candle* object, bool setup_releasehook = false); +class Wind; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Wind* object, bool setup_releasehook = false); +class AmbientSound; void create_squirrel_instance(HSQUIRRELVM v, Scripting::AmbientSound* object, bool setup_releasehook = false); +class Thunderstorm; void create_squirrel_instance(HSQUIRRELVM v, Scripting::Thunderstorm* object, bool setup_releasehook = false); +class TileMap; void create_squirrel_instance(HSQUIRRELVM v, Scripting::TileMap* object, bool setup_releasehook = false); +class SSector; void create_squirrel_instance(HSQUIRRELVM v, Scripting::SSector* object, bool setup_releasehook = false); +class LevelTime; void create_squirrel_instance(HSQUIRRELVM v, Scripting::LevelTime* object, bool setup_releasehook = false); +class WillOWisp; void create_squirrel_instance(HSQUIRRELVM v, Scripting::WillOWisp* object, bool setup_releasehook = false); } diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index f505fc263..1d49b2f3e 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -48,6 +48,8 @@ Tux::Tux(WorldMap* worldmap_) moving = false; direction = D_NONE; input_direction = D_NONE; + + ghost_mode = false; } Tux::~Tux() @@ -120,6 +122,18 @@ Tux::set_direction(Direction dir) } void +Tux::set_ghost_mode(bool enabled) +{ + ghost_mode = enabled; +} + +bool +Tux::get_ghost_mode() +{ + return ghost_mode; +} + +void Tux::tryStartWalking() { if (moving) @@ -137,7 +151,7 @@ Tux::tryStartWalking() moving = true; direction = input_direction; back_direction = reverse_dir(direction); - } else if (input_direction == back_direction) { + } else if (ghost_mode || (input_direction == back_direction)) { moving = true; direction = input_direction; tile_pos = worldmap->get_next_tile(tile_pos, direction); @@ -148,10 +162,11 @@ Tux::tryStartWalking() bool Tux::canWalk(int tile_data, Direction dir) { - return ((tile_data & Tile::WORLDMAP_NORTH && dir == D_NORTH) || + return ghost_mode || + ((tile_data & Tile::WORLDMAP_NORTH && dir == D_NORTH) || (tile_data & Tile::WORLDMAP_SOUTH && dir == D_SOUTH) || - (tile_data & Tile::WORLDMAP_EAST && dir == D_EAST) || - (tile_data & Tile::WORLDMAP_WEST && dir == D_WEST)); + (tile_data & Tile::WORLDMAP_EAST && dir == D_EAST) || + (tile_data & Tile::WORLDMAP_WEST && dir == D_WEST)); } void @@ -209,7 +224,7 @@ Tux::tryContinueWalking(float elapsed_time) || (worldmap->tile_data_at(tile_pos) & Tile::WORLDMAP_STOP) || (special_tile && !special_tile->passive_message && special_tile->script == "") - || (teleporter)) { + || (teleporter) || ghost_mode) { if(special_tile && !special_tile->map_message.empty() && !special_tile->passive_message) worldmap->passive_message_timer.start(0); @@ -250,7 +265,7 @@ Tux::tryContinueWalking(float elapsed_time) return; Vector next_tile; - if (!worldmap->path_ok(direction, tile_pos, &next_tile)) { + if (!ghost_mode && !worldmap->path_ok(direction, tile_pos, &next_tile)) { log_debug << "Tilemap data is buggy" << std::endl; stop(); return; diff --git a/src/worldmap/tux.hpp b/src/worldmap/tux.hpp index 4c36042d4..ebecefe87 100644 --- a/src/worldmap/tux.hpp +++ b/src/worldmap/tux.hpp @@ -48,6 +48,8 @@ private: float offset; bool moving; + bool ghost_mode; + void stop(); bool canWalk(int tile_data, Direction dir); /**< check if we can leave a tile (with given "tile_data") in direction "dir" */ @@ -65,6 +67,9 @@ public: void set_direction(Direction dir); + void set_ghost_mode(bool enabled); + bool get_ghost_mode(); + bool is_moving() const { return moving; } Vector get_pos(); Vector get_tile_pos() const { return tile_pos; } diff --git a/src/worldmap/worldmap.hpp b/src/worldmap/worldmap.hpp index 8215cda42..87c83a938 100644 --- a/src/worldmap/worldmap.hpp +++ b/src/worldmap/worldmap.hpp @@ -169,6 +169,9 @@ public: */ void finished_level(Level* level); + /** returns current Tux incarnation */ + Tux* get_tux() { return tux; } + LevelTile* at_level(); SpecialTile* at_special_tile(); SpriteChange* at_sprite_change(const Vector& pos); diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index ba5a43f8f..df12a7636 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -28,7 +28,6 @@ WrapperCreator::create_wrapper(Namespace* ns) << "#define __" << modulename << "_WRAPPER_H__\n" << "\n" << "#include \n" - << "#include \"wrapper.interface.hpp\"\n" << "\n" << "namespace Scripting\n" << "{\n" @@ -44,6 +43,7 @@ WrapperCreator::create_wrapper(Namespace* ns) if(_class == 0) continue; + hppout << "class " << _class->name << ";\n"; hppout << "void create_squirrel_instance(HSQUIRRELVM v, " << ns_prefix << _class->name << "* object, bool setup_releasehook = false);\n";