-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVActor.h
128 lines (110 loc) · 4.09 KB
/
VActor.h
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once
#include "vssSrv.h"
using std::cerr;
using std::cout;
using std::endl;
using std::ostream;
// A unique indetifiers for Actors.
// Each Actor knows its ActorHandle, a key into the map Actors.
typedef unsigned ActorHandle;
class VHandler;
class VGeneratorActor;
// Actors are automatically maintained in a map. They insert
// themselves when created and remove themselves when deleted.
class VActor
{
ActorHandle myHandle;
public:
// If I make this return value a ActorHandle, we dump core all
// over the place. This is a BUG and should be hunted down and
// killed.
float handle() const { return myHandle; }
// fActive is true if this VActor is doing anything,
// and false if the actor's activity should be suspended.
// fDebug is user-defined.
// fDestroy marks this actor as to be deleted.
private:
int fActive;
int fDebug;
bool fDestroy;
public:
int delete_me() const { return fDestroy; }
int isActive() const { return fActive; }
int isDebug() const { return fDebug; }
// setActive() and setDebug() may be overridden by actors that
// need to do something fancy when their status changes.
virtual void setActive(int f) { fActive = (f!=0); }
virtual void setDebug(int f) { fDebug = f; }
VActor();
VActor(const VActor&) = delete;
virtual ~VActor();
// Asynchronous behavior:
// Every so often, actors are offered a chance to do something.
// Asynchronous actor behavior is implemented in act(). Any derived
// class that needs some such behavior should override act(), and
// should also call its base class' act() so that it will inherit
// asynchronous behavior from base classes. We refer to this behavior
// as "control rate behavior", but, in fact, it doesn't occur at any
// guaranteed rate. Act() is called only by allAct(), and by derived
// class' act(), so it is protected.
//
// actCleanup() is a second pass, called by allActCleanup().
protected:
virtual void act() {}
virtual void actCleanup() {}
// allAct() is called by the scheduler, and hopefully not by anyone else.
// It runs through the entire Actor container and calls act() for everybody.
//
// allActCleanup() is a second pass through the Actor container,
// and gives everyone a chance to clean up dangling pointers to VHandlers
// which were recently deleted. It should be called right after any code
// which might have deleted a handler (for now, allAct() and actorMessageMM()).
public:
static void allAct();
static void allActCleanup();
// A derived class's version must call the base class's
// version for messages that it does not recognize.
virtual int receiveMessage(const char* Message);
// Catch() and Uncatch() are used in message parsing.
// Catch() when a message is handled succesfully, Uncatch()
// when a message is caught, but handled unsuccessfully (i.e.
// has wrong number of arguments or something).
protected:
int Catch();
int Uncatch();
// Global VActor container access and maintenance.
private:
static int fWantToFlush;
public:
static VActor* getByHandle(float);
static void flushActorList();
static void WantToFlush()
{ fWantToFlush = 1; }
// For identifying special kinds of actors, override as necessary
// We use this in place of RTTI, which isn't yet implemented on the SGI.
virtual VHandler* as_handler() { return NULL; }
virtual VGeneratorActor* as_generator() { return NULL; }
// Debugging info:
// These methods handle the DumpAll message, to report about actors.
// Each actor's constructor must call setTypeName().
private:
char myTypeName[30];
public:
void setTypeName(const char* str) { strncpy(myTypeName, str, 29); }
char const* typeName() const { return myTypeName; }
// Override this to print actor-specific details.
virtual ostream& dump(ostream&, int);
ostream& indent(ostream &os, int tabs) const {
os << std::string(3*tabs, ' ');
return os;
}
ostream& bio(ostream &os, int tabs = 0) {
indent(os, tabs) << myTypeName << std::endl;
dump(os, tabs+1);
return os;
}
static void curtainCall(ostream &os); // Print every actor's bio.
};
#include "parseActorMessage.h"
// Compatible with actorlist.h's.
#define ACTOR_SETUP(T, t) VActor* t##_New() { return new T; }