🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2587

Re: State engine

#2587
From: Mike McCarty
Date: Sat, 13 Apr 1996 13:57
58 lines
1869 bytes
In article <4jmcoa$lri@solutions.solon.com>,
terres  <terres@servidor.dgsca.unam.mx> wrote:
)Hello!
)
)I think that when you have complex problem like many conditions, paths 
)and cases, a traditional program could be to big and inneficient on 
)execution.
)
)I have seen a system that uses a state engine that triggers some pieces 
)of code when an encounters take effect between: states & stimuli.
)
)Like this:
)        Stimuli
)State | 1  2  3
)1     |           
)2     |
)3     |
)
)When some conditions are acomplished some specific pieces of code are 
)executed and that pieces send the control to another crosspoint.
)
)I want to know how to implement this idea in C.
)
)Thanks
)
)Austin


typedef enum { InActive, Ready, RarinToGo } State_t;
#define LastState RarinToGo

typedef enum { CountDown, Ignition, LiftOff } Event_t;
#define LastEvent LiftOff

typedef struct {
	State_t	NextState;
	void	(*action)(void);
} StMachine_t

void	GetReady(void);

StMachine_t	StateMachine[LastState+1][LastEvent+1] = {
/* InActive */	{
  /* Countdown */	{ Ready, GetReady},
  /* Ignition  */	{ 

...
}

void	HandleState(State_t *State,Event_t Event) {
	StateMachine[*State][Event].action();
	*State = StateMachine[*State][Event].NextState;
}
-- 
----
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}

I don't speak for DSC.         <- They make me say that.
Technical Details
Message-ID: <4kobrq$8hc@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4jmcoa$lri@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: jmccarty@sun1307.spd.dsccc.com (Mike McCarty)
Newsgroups: comp.lang.c.moderated
Subject: Re: State engine
Date: 13 Apr 1996 08:57:14 -0500
Organization: DSC Communications Corporation
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4kobrq$8hc@solutions.solon.com>
References: <4jmcoa$lri@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com