Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10620 in orxonox.OLD


Ignore:
Timestamp:
Apr 5, 2007, 6:11:02 PM (18 years ago)
Author:
snellen
Message:

added and tested a new kind of trigger: the time trigger

Location:
branches/scriptimprovements/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/scriptimprovements/src/lib/script_engine/script.cc

    r10611 r10620  
    406406   bool success = false;
    407407
    408    //this->registerClass(std::string("Vector"));
    409408    this->registerClass("SpaceTrigger");
    410409    this->registerClass("TickTrigger");
    411   //  this->registerClass("AttractorMine");
     410    this->registerClass("TimeTrigger");
    412411
    413412   return success;
  • branches/scriptimprovements/src/world_entities/WorldEntities.am

    r10616 r10620  
    104104                world_entities/script_triggers/space_trigger.cc \
    105105                world_entities/script_triggers/tick_trigger.cc \
     106                world_entities/script_triggers/time_trigger.cc \
    106107                \
    107108                \
     
    238239                script_triggers/space_trigger.h \
    239240                script_triggers/tick_trigger.h \
     241                script_triggers/time_trigger.h \
    240242                \
    241243                \
  • branches/scriptimprovements/src/world_entities/script_triggers/space_trigger.cc

    r10616 r10620  
    4949{
    5050  this->registerObject(this, SpaceTrigger::_objectList);
    51   //this->toList(OM_COMMON);
    5251
    5352  radius = 10;
  • branches/scriptimprovements/src/world_entities/script_triggers/tick_trigger.cc

    r10616 r10620  
    1515
    1616#include "util/loading/factory.h"
     17#include "script_class.h"
    1718#include "tick_trigger.h"
    1819#include "debug.h"
     
    4344{
    4445  this->registerObject(this, TickTrigger::_objectList);
    45   //this->toList(OM_COMMON);
    4646
    4747  if(root != NULL)
  • branches/scriptimprovements/src/world_entities/script_triggers/tick_trigger.h

    r10609 r10620  
    11/*!
    2  * @file space_trigger.h
     2 * @file tick_trigger.h
    33 *  always triggeres a script
    44 */
     
    1010
    1111#include "script.h"
    12 #include "script_class.h"
    1312#include "script_trigger.h"
    1413
  • branches/scriptimprovements/src/world_entities/script_triggers/time_trigger.cc

    r10607 r10620  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11### File Specific:
     12   main-programmer: Silvan Nellen
     13   co-programmer: ...
     14*/
     15
     16#include "util/loading/factory.h"
     17#include "time_trigger.h"
     18#include "debug.h"
     19#include "script_class.h"
     20
     21ObjectListDefinition(TimeTrigger);
     22CREATE_FACTORY(TimeTrigger);
     23
     24CREATE_SCRIPTABLE_CLASS(TimeTrigger,
     25             // Coordinates
     26                        addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
     27                            ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
     28                            ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
     29                            ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
     30             //Properties
     31                            ->addMethod("setName", Executor1<BaseObject, lua_State*, const std::string&>(&BaseObject::setName))
     32                            ->addMethod("setScript", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setScript))
     33                            ->addMethod("setFunction", Executor1<ScriptTrigger, lua_State*, const std::string&>(&ScriptTrigger::setFunction))
     34                            ->addMethod("setDebugDraw", Executor1<ScriptTrigger, lua_State*, bool>(&ScriptTrigger::setDebugDraw))
     35                            ->addMethod("start", Executor0<TimeTrigger, lua_State*>(&TimeTrigger::start))
     36                            ->addMethod("stop", Executor0<TimeTrigger, lua_State*>(&TimeTrigger::stop))
     37                            ->addMethod("reset", Executor0<TimeTrigger, lua_State*>(&TimeTrigger::reset))
     38                            ->addMethod("setDelay", Executor1<TimeTrigger, lua_State*, float>(&TimeTrigger::setDelay))
     39                           
     40                       );
     41
     42
     43/**
     44 * Constructs a new TimeTrigger.
     45 * @param root the xml element to load the parameters from.
     46 *
     47 */
     48TimeTrigger::TimeTrigger(const TiXmlElement* root)
     49{
     50  this->registerObject(this, TimeTrigger::_objectList);
     51 
     52  this->delay = 1;
     53  this->currentTime = delay;
     54  this->isStopped = true;
     55
     56  if(root != NULL)
     57  {
     58    loadParams(root);
     59
     60    if(addToScript && scriptIsOk)
     61    {
     62      script->addObject( "TimeTrigger", this->getName());
     63    }
     64
     65  }
     66
     67}
     68
     69/**
     70 * Deletes the TimeTrigger.
     71 *
     72 */
     73TimeTrigger::~TimeTrigger()
     74{
     75
     76}
     77
     78
     79void TimeTrigger::tick(float timestep)
     80{
     81  if( scriptFinished ) return;
     82 
     83  if( !isStopped )
     84  {
     85    currentTime -= timestep;
     86   
     87    if(currentTime < 0)
     88    {
     89      this->executeAction(timestep);
     90      this->stop();
     91    }
     92 
     93  }
     94
     95     
     96}
  • branches/scriptimprovements/src/world_entities/script_triggers/time_trigger.h

    r10607 r10620  
     1/*!
     2 * @file time_trigger.h
     3 *  triggers a script after a given time
     4 */
     5
     6#ifndef _TIME_TRIGGER_H
     7#define _TIME_TRIGGER_H
     8
     9#include <string>
     10
     11#include "script.h"
     12#include "script_trigger.h"
     13
     14class TimeTrigger : public ScriptTrigger
     15{
     16  ObjectListDeclaration(TimeTrigger);
     17 
     18  public:
     19    TimeTrigger(const TiXmlElement* root = NULL);
     20    ~TimeTrigger();
     21   
     22    void setDelay(float newDelay){this->currentTime = this->delay = newDelay;}
     23    void start(){ this->isStopped = false; }
     24    void stop(){ this->isStopped = true; }
     25    void reset(){ this->currentTime = delay; }
     26
     27    /// DO WORK
     28    virtual void tick(float timestep);
     29 
     30  private:
     31    float delay;
     32    float currentTime;
     33    bool  isStopped;
     34
     35};
     36
     37#endif
Note: See TracChangeset for help on using the changeset viewer.