1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/*
* This file is part of NumptyPhysics
* Copyright (C) 2009 Tim Edmonds
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#ifndef SCRIPT_H
#define SCRIPT_H
#include "Array.h"
#include "Path.h"
#include <iostream>
class Scene;
struct ScriptEntry {
enum Op {
OP_NEW,
OP_DELETE,
OP_EXTEND,
OP_MOVE,
OP_ACTIVATE,
OP_PAUSE,
OP_GOAL
};
int t;
Op op;
int stroke;
int arg1;
int arg2;
Vec2 pt;
ScriptEntry( int _t, Op _op, int _stroke,
int _arg1, int _arg2, const Vec2& _pt )
: t(_t), op(_op), stroke(_stroke),
arg1(_arg1), arg2(arg2), pt(_pt)
{}
ScriptEntry() {};
ScriptEntry( const std::string& str );
std::string asString();
};
class ScriptLog : public Array<ScriptEntry>
{
public:
std::string asString( int i );
void append( int tick, ScriptEntry::Op op, int stroke=-1,
int arg1=-1, int arg2=-1, const Vec2& pt=Vec2(-1,-1) );
void append( const std::string& str );
using Array<ScriptEntry>::append;
};
class ScriptRecorder
{
public:
ScriptRecorder();
void start(ScriptLog* log);
void stop();
void tick(bool isPaused);
void newStroke( const Path& p, int colour, int attribs );
void deleteStroke( int index );
void extendStroke( int index, const Vec2& pt );
void moveStroke( int index, const Vec2& pt );
void activateStroke( int index );
void goal( int goalNum );
ScriptLog* getLog() { return m_log; }
private:
bool m_running;
bool m_isPaused;
ScriptLog *m_log;
int m_lastTick;
};
class ScriptPlayer
{
public:
void start( const ScriptLog* log, Scene* scene );
bool isRunning() const;
void stop();
bool tick();
private:
bool m_playing;
bool m_isPaused;
const ScriptLog* m_log;
Scene *m_scene;
int m_index;
int m_lastTick;
};
#endif //SCRIPT_H
|