Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12016 for code/branches


Ignore:
Timestamp:
May 30, 2018, 2:37:02 PM (6 years ago)
Author:
patricwi
Message:

Merged Scriptable Controller

Location:
code/branches/PresentationFS18
Files:
25 edited
12 copied

Legend:

Unmodified
Added
Removed
  • code/branches/PresentationFS18

  • code/branches/PresentationFS18/data/levels/scriptController.oxw

    r10622 r12016  
    1818
    1919<Level
    20   gametype = Deathmatch
     20 
    2121>
    2222  <templates>
  • code/branches/PresentationFS18/src/libraries/core/BaseObject.cc

    r11103 r12016  
    7777        {
    7878            this->setFile(this->creator_->getFile());
    79 
     79           
    8080            // store strong-pointers on all four base objects by default (can be overwritten with weak-ptr after the constructor if necessary)
    8181            this->setNamespace(this->creator_->namespace_.createStrongPtr());
  • code/branches/PresentationFS18/src/libraries/core/BaseObject.h

    r11071 r12016  
    5858    class Gametype;
    5959    class Level;
     60    class ScriptableController;
    6061
    6162    /// The BaseObject is the parent of all classes representing an instance in the game.
     
    191192
    192193            static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier);
     194
    193195
    194196        protected:
  • code/branches/PresentationFS18/src/libraries/tools/Timer.cc

    r12015 r12016  
    158158    }
    159159
     160    Timer::Timer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
     161    {
     162        this->init();
     163        RegisterObject(Timer);
     164
     165        this->setTimer(interval, bLoop, func, bKillAfterCall);
     166    }
     167
    160168    /**
    161169        @brief Initializes the Timer
     
    193201        this->executor_ = executor;
    194202        this->bActive_ = true;
     203        this->isStdFunction_ = false;
    195204
    196205        this->time_ = this->interval_;
    197206        this->bKillAfterCall_ = bKillAfterCall;
    198207
    199         executor->getFunctor()->setSafeMode(true);
    200     }
    201 
     208        if(executor != nullptr)
     209            executor->getFunctor()->setSafeMode(true);
     210    }
     211
     212    void Timer::setTimer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
     213    {
     214        // Without the cast, the call would be ambiguous, because nullptr is castable to
     215        // both, ExecutorPtr and std::function.
     216        this->setTimer(interval, bLoop, static_cast<ExecutorPtr>(nullptr), bKillAfterCall);
     217        this->function_ = func;
     218        this->isStdFunction_ = true;
     219    }
    202220
    203221    /**
     
    208226        bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer
    209227
    210         (*this->executor_)();
     228        if(this->isStdFunction_)
     229            this->function_();
     230        else
     231            (*this->executor_)();
    211232
    212233        if (temp)
  • code/branches/PresentationFS18/src/libraries/tools/Timer.h

    r12015 r12016  
    108108
    109109            Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
     110            Timer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
    110111
    111112            void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
     113            void setTimer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
    112114
    113115            void run();
     
    154156
    155157            ExecutorPtr executor_;  //!< The executor of the function that will be called when the time expires
     158            std::function<void (void)> function_;
    156159
     160            bool isStdFunction_;
    157161            long long interval_;    //!< The time-interval in micro seconds
    158162            bool bLoop_;            //!< If true, the executor gets called every @a interval seconds
  • code/branches/PresentationFS18/src/orxonox/CMakeLists.txt

    r11704 r12016  
    5151ADD_SUBDIRECTORY(items)
    5252ADD_SUBDIRECTORY(overlays)
     53ADD_SUBDIRECTORY(scriptablecontroller)
    5354ADD_SUBDIRECTORY(sound)
    5455ADD_SUBDIRECTORY(weaponsystem)
  • code/branches/PresentationFS18/src/orxonox/Level.cc

    r11071 r12016  
    4242#include "overlays/OverlayGroup.h"
    4343#include "LevelManager.h"
     44#include "scriptablecontroller/scriptable_controller.h"
    4445
    4546namespace orxonox
     
    5657        this->xmlfilename_ = this->getFilename();
    5758        this->xmlfile_ = nullptr;
     59        this->controller_.reset(new ScriptableController());
    5860    }
    5961
     
    7880        XMLPortParam(Level, "plugins",  setPluginsString,  getPluginsString,  xmlelement, mode);
    7981        XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
     82
     83        XMLPortParamLoadOnly(Level, "script", setScript, xmlelement, mode).defaultValues("scripts/empty.lua");
    8084
    8185        XMLPortObject(Level, MeshLodInformation, "lodinformation", addLodInfo, getLodInfo, xmlelement, mode);
  • code/branches/PresentationFS18/src/orxonox/Level.h

    r11071 r12016  
    4242namespace orxonox
    4343{
     44    class ScriptableController;
     45
    4446    class _OrxonoxExport Level : public BaseObject, public Synchronisable, public Context
    4547    {
     
    5557            MeshLodInformation* getLodInfo(std::string meshName) const;
    5658
     59            inline ScriptableController *getScriptableController(void)
     60                { return this->controller_.get(); }
     61
     62            inline const std::string &getScript(void)
     63                { return this->level_script_; }
    5764
    5865        private:
     
    7885            void networkcallback_applyXMLFile();
    7986
     87            inline void setScript(const std::string &script)
     88                {   
     89                    orxout(internal_warning) << "hi world" << endl;
     90                    this->level_script_ = script; }
     91
     92
    8093            std::string                    pluginsString_;
    8194            std::list<PluginReference*>    plugins_;
    82 
    8395            std::string                    gametype_;
    8496            std::string                    xmlfilename_;
     
    8698            std::list<BaseObject*>         objects_;
    8799            std::map<std::string,MeshLodInformation*>  lodInformation_;
     100
     101            std::unique_ptr<ScriptableController> controller_;
     102            std::string           level_script_;
    88103    };
    89104}
  • code/branches/PresentationFS18/src/orxonox/controllers/CMakeLists.txt

    r11783 r12016  
    1919  FightingController.cc
    2020  MasterController.cc
    21   ArrowController.cc
     21  ArrowController.cc;
     22  AutonomousDroneController.cc;
     23       
    2224)
  • code/branches/PresentationFS18/src/orxonox/controllers/Controller.cc

    r11071 r12016  
    2626 *
    2727 */
    28 
     28//asdf
    2929#include "Controller.h"
    3030#include "core/CoreIncludes.h"
  • code/branches/PresentationFS18/src/orxonox/infos/GametypeInfo.cc

    r11099 r12016  
    4343#include "interfaces/GametypeMessageListener.h"
    4444#include "interfaces/NotificationListener.h"
     45#include "scriptablecontroller/scriptable_controller.h"
     46#include "Level.h"
    4547
    4648#include "PlayerInfo.h"
     
    7678        this->spawned_ = false;
    7779        this->readyToSpawn_ = false;
     80        this->isFirstSpawn_ = true;
    7881
    7982        this->registerVariables();
     
    296299            this->setReadyToSpawnHelper(player, false);
    297300            this->setSpawnedHelper(player, false);
     301
    298302        }
    299303    }
     
    310314        {
    311315            if(this->hasStarted() && !this->hasEnded())
    312 
    313316                this->setSpawnedHelper(player, true);
     317        }
     318
     319        // TODO We might want to handle the subsequent spawns as well somehow
     320        if(player->isHumanPlayer() && player->isLocalPlayer()) //&& this->isFirstSpawn_)
     321        {
     322            this->isFirstSpawn_ = false;
     323            this->getLevel()->getScriptableController()->setPlayer(player);
     324
     325            // This handles paths relative to the 'level' directory
     326            std::string script = this->getLevel()->getScript();
     327            if(script.at(0) != '/')
     328                script = "../levels/" + script; // Not very dynamic
     329            this->getLevel()->getScriptableController()->runScript(script);
    314330        }
    315331    }
     
    345361            {
    346362                // Display "Press [Fire] to start the match" if the game has not yet ended.
    347                 if(!this->hasEnded())
     363                if(!this->hasEnded()){
    348364                    NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
     365               
     366                    //this->getLevel()->getScriptableController()->setPlayer(player);
     367
     368                    // This handles paths relative to the 'level' directory
     369                    //std::string script = this->getLevel()->getScript();
     370                    //if(script.at(0) != '/')
     371                    //script = "../levels/" + script; // Not very dynamic
     372                    //this->getLevel()->getScriptableController()->runScript(script);
     373                }
    349374                // Else display "Game has ended".
    350375                else
  • code/branches/PresentationFS18/src/orxonox/infos/GametypeInfo.h

    r11720 r12016  
    8383            inline bool isStartCountdownRunning() const
    8484                { return this->bStartCountdownRunning_; }
     85
    8586            void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
    8687
     
    166167            bool spawned_; //!< Whether the local Player is currently spawned.
    167168            bool readyToSpawn_; //!< Whether the local Player is ready to spawn.
     169            bool isFirstSpawn_;
    168170    };
    169171}
  • code/branches/PresentationFS18/src/orxonox/infos/HumanPlayer.cc

    r11071 r12016  
    3838#include "gametypes/Gametype.h"
    3939#include "overlays/OverlayGroup.h"
     40#include "Level.h"
     41#include "scriptablecontroller/scriptable_controller.h"
    4042
    4143namespace orxonox
  • code/branches/PresentationFS18/src/orxonox/items/ShipPart.cc

    r11099 r12016  
    4242#include "items/PartDestructionEvent.h"
    4343#include "chat/ChatManager.h"
     44#include "Level.h"
     45#include "scriptablecontroller/scriptable_controller.h"
    4446
    4547
     
    215217            }
    216218        }
     219
     220        // This is a bit hacky, but it takes away damage control from the pawn, so it has to handle
     221        // that as well.
     222        this->getLevel()->getScriptableController()->pawnHit(parent_, originator, parent_->getHealth(), parent_->getShieldHealth());
     223
    217224        if (this->health_ < 0)
    218225            this->death();
  • code/branches/PresentationFS18/src/orxonox/worldentities/CMakeLists.txt

    r11783 r12016  
    1515  NameableStaticEntity.cc
    1616  Arrow.cc
     17  AutonomousDrone.cc
    1718)
    1819
  • code/branches/PresentationFS18/src/orxonox/worldentities/ControllableEntity.cc

    r11071 r12016  
    3939
    4040#include "Scene.h"
     41#include "Level.h"
    4142#include "infos/PlayerInfo.h"
    4243#include "controllers/NewHumanController.h"
     
    6768        this->camera_ = nullptr;
    6869        this->xmlcontroller_ = nullptr;
    69         //this->controller_ = nullptr;
    7070        this->reverseCamera_ = nullptr;
    7171        this->bDestroyWhenPlayerLeft_ = false;
  • code/branches/PresentationFS18/src/orxonox/worldentities/ControllableEntity.h

    r11071 r12016  
    175175            inline int getTeam() const
    176176                { return this->team_; }
     177
    177178
    178179        protected:
  • code/branches/PresentationFS18/src/orxonox/worldentities/MobileEntity.cc

    r11071 r12016  
    3636
    3737#include "Scene.h"
     38#include "Level.h"
     39#include "scriptablecontroller/scriptable_controller.h"
    3840
    3941namespace orxonox
     
    7274                this->setAngularVelocity(rotationAxis.normalisedCopy() * rotationRate.valueRadians());
    7375        }
     76
     77        if(!this->id_.empty() && this->getLevel() != nullptr)
     78            this->getLevel()->getScriptableController()->registerMobileEntity(this->id_, this);
    7479    }
    7580
  • code/branches/PresentationFS18/src/orxonox/worldentities/WorldEntity.cc

    r11083 r12016  
    4444#include "core/XMLPort.h"
    4545#include "Scene.h"
     46#include "Level.h"
    4647#include "collisionshapes/WorldEntityCollisionShape.h"
     48#include "scriptablecontroller/scriptable_controller.h"
    4749
    4850namespace orxonox
     
    7981        this->parentID_ = OBJECTID_UNKNOWN;
    8082        this->bDeleteWithParent_ = true;
     83        this->id_ = -1;
    8184
    8285        this->node_->setPosition(Vector3::ZERO);
     
    160163        XMLPortParamTemplate(WorldEntity, "scale3D",     setScale3D,     getScale3D,     xmlelement, mode, const Vector3&);
    161164        XMLPortParam        (WorldEntity, "scale",       setScale,       getScale,       xmlelement, mode);
     165        XMLPortParamLoadOnly(WorldEntity, "id",          setID,                xmlelement, mode);
    162166        XMLPortParamLoadOnly(WorldEntity, "lookat",      lookAt_xmlport,       xmlelement, mode);
    163167        XMLPortParamLoadOnly(WorldEntity, "direction",   setDirection_xmlport, xmlelement, mode);
     
    181185        // Attached collision shapes
    182186        XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
     187
     188        if(!this->id_.empty() && this->getLevel() != nullptr)
     189            this->getLevel()->getScriptableController()->registerWorldEntity(this->id_, this);
    183190    }
    184191
  • code/branches/PresentationFS18/src/orxonox/worldentities/WorldEntity.h

    r11099 r12016  
    110110            virtual void changedActivity(void) override;
    111111            virtual void changedVisibility(void) override;
     112
     113            inline std::string getID(void)
     114                { return this->id_; }
     115
     116            inline void setID(std::string id)
     117                { this->id_ = id; }
    112118
    113119            virtual void setPosition(const Vector3& position) = 0;
     
    442448
    443449            btRigidBody*  physicalBody_; //!< Bullet rigid body. Everything physical is applied to this instance.
     450            std::string   id_;           //!< Used by the ScriptableController to identify objects
    444451
    445452        private:
  • code/branches/PresentationFS18/src/orxonox/worldentities/pawns/CMakeLists.txt

    r11783 r12016  
    44  Pawn.cc
    55  SpaceShip.cc
     6  ScriptableControllerDrone.cc
    67  ModularSpaceShip.cc
    78  TeamBaseMatchBase.cc
  • code/branches/PresentationFS18/src/orxonox/worldentities/pawns/Pawn.cc

    r11783 r12016  
    5050#include "sound/WorldSound.h"
    5151#include "core/object/ObjectListIterator.h"
     52#include "Level.h"
     53#include "scriptablecontroller/scriptable_controller.h"
    5254
    5355#include "controllers/FormationController.h"
     
    160162
    161163        XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
     164
     165        if(!this->id_.empty() && this->getLevel() != nullptr)
     166            this->getLevel()->getScriptableController()->registerPawn(this->id_, this);
    162167    }
    163168
     
    282287        {
    283288            // Health-damage cannot be absorbed by shields.
    284             // Shield-damage only reduces shield health. 
     289            // Shield-damage only reduces shield health.
    285290            // Normal damage can be (partially) absorbed by shields.
    286291
     
    302307                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    303308            }
     309            this->getLevel()->getScriptableController()->pawnHit(this, originator, this->health_, this->shieldHealth_);
    304310
    305311            this->lastHitOriginator_ = originator;
     
    402408            }
    403409        }
     410
     411        this->getLevel()->getScriptableController()->pawnKilled(this);
    404412    }
    405413    void Pawn::goWithStyle()
     
    625633        {
    626634            // delete all debug models
    627             for(Model* model : debugWeaponSlotModels_) 
     635            for(Model* model : debugWeaponSlotModels_)
    628636            {
    629637                model->destroy();
  • code/branches/PresentationFS18/src/orxonox/worldentities/pawns/SpaceShip.cc

    r12015 r12016  
    163163            engine->run(dt);
    164164
    165         if (this->hasLocalController())
     165        if (this->hasLocalController() || true)
    166166        {
    167167            // If not in mouse look apply the angular movement to the ship.
  • code/branches/PresentationFS18/src/orxonox/worldentities/pawns/SpaceShip.h

    r12015 r12016  
    117117                { this->steering_.y += (0.6)*value.x; }
    118118
     119            inline void moveFrontBack(float value)
     120                { this->moveFrontBack(Vector2(value, 0)); }
     121            inline void moveRightLeft(float value)
     122                { this->moveRightLeft(Vector2(value, 0)); }
     123            inline void moveUpDown(float value)
     124                { this->moveUpDown(Vector2(value, 0)); }   
     125
    119126            virtual void rotateYaw(const Vector2& value); // Rotate in yaw direction.
    120127            virtual void rotatePitch(const Vector2& value); // Rotate in pitch direction.
Note: See TracChangeset for help on using the changeset viewer.