[Avida-cvs] [avida-svn] r882 - in development/source: actions event
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Aug 22 13:34:18 PDT 2006
Author: brysonda
Date: 2006-08-22 16:34:18 -0400 (Tue, 22 Aug 2006)
New Revision: 882
Modified:
development/source/actions/PopulationActions.cc
development/source/event/cEventManager.cc
Log:
Transition ConnectCells, DisconnectCells into the actions framework.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2006-08-22 20:26:10 UTC (rev 881)
+++ development/source/actions/PopulationActions.cc 2006-08-22 20:34:18 UTC (rev 882)
@@ -1106,7 +1106,87 @@
};
+class cActionConnectCells : public cAction
+{
+private:
+ int m_a_x;
+ int m_a_y;
+ int m_b_x;
+ int m_b_y;
+public:
+ cActionConnectCells(cWorld* world, const cString& args) : cAction(world, args), m_a_x(-1), m_a_y(-1), m_b_x(-1), m_b_y(-1)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_a_x = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_a_y = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_b_x = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_b_y = largs.PopWord().AsInt();
+ }
+
+ const cString GetDescription() { return "ConnectCells <int cellA_x> <int cellA_y> <int cellB_x> <int cellB_y>"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ const int world_x = m_world->GetPopulation().GetWorldX();
+ const int world_y = m_world->GetPopulation().GetWorldY();
+ if (m_a_x < 0 || m_a_x >= world_x || m_a_y < 0 || m_a_y >= world_y ||
+ m_b_x < 0 || m_b_x >= world_x || m_b_y < 0 || m_b_y >= world_y) {
+ m_world->GetDriver().RaiseException("ConnectCells cell out of range");
+ return;
+ }
+ int idA = m_a_y * world_x + m_a_x;
+ int idB = m_b_y * world_x + m_b_x;
+ cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
+ cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
+ tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
+ tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
+ cellA_list.PushRear(&cellB);
+ cellB_list.PushRear(&cellA);
+ }
+};
+
+class cActionDisconnectCells : public cAction
+{
+private:
+ int m_a_x;
+ int m_a_y;
+ int m_b_x;
+ int m_b_y;
+public:
+ cActionDisconnectCells(cWorld* world, const cString& args) : cAction(world, args), m_a_x(-1), m_a_y(-1), m_b_x(-1), m_b_y(-1)
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_a_x = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_a_y = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_b_x = largs.PopWord().AsInt();
+ if (largs.GetSize()) m_b_y = largs.PopWord().AsInt();
+ }
+
+ const cString GetDescription() { return "DisconnectCells <int cellA_x> <int cellA_y> <int cellB_x> <int cellB_y>"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ const int world_x = m_world->GetPopulation().GetWorldX();
+ const int world_y = m_world->GetPopulation().GetWorldY();
+ if (m_a_x < 0 || m_a_x >= world_x || m_a_y < 0 || m_a_y >= world_y ||
+ m_b_x < 0 || m_b_x >= world_x || m_b_y < 0 || m_b_y >= world_y) {
+ m_world->GetDriver().RaiseException("DisconnectCells cell out of range");
+ return;
+ }
+ int idA = m_a_y * world_x + m_a_x;
+ int idB = m_b_y * world_x + m_b_x;
+ cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
+ cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
+ tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
+ tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
+ cellA_list.Remove(&cellB);
+ cellB_list.Remove(&cellA);
+ }
+};
+
+
+
void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
@@ -1136,6 +1216,9 @@
action_lib->Register<cActionJoinGridCol>("JoinGridCol");
action_lib->Register<cActionJoinGridRow>("JoinGridRow");
+ action_lib->Register<cActionConnectCells>("ConnectCells");
+ action_lib->Register<cActionDisconnectCells>("DisconnectCells");
+
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
action_lib->Register<cActionInject>("inject");
action_lib->Register<cActionInjectRandom>("inject_random");
@@ -1158,4 +1241,7 @@
action_lib->Register<cActionSeverGridRow>("sever_grid_row");
action_lib->Register<cActionJoinGridCol>("join_grid_col");
action_lib->Register<cActionJoinGridRow>("join_grid_row");
+
+ action_lib->Register<cActionConnectCells>("connect_cells");
+ action_lib->Register<cActionDisconnectCells>("disconnect_cells");
}
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-08-22 20:26:10 UTC (rev 881)
+++ development/source/event/cEventManager.cc 2006-08-22 20:34:18 UTC (rev 882)
@@ -42,109 +42,6 @@
-///// connect_cells /////
-
-/**
-* Connects a pair of specified cells.
- * Arguments:
- * cellA_x, cellA_y, cellB_x, cellB_y
- **/
-
-
-class cEvent_connect_cells : public cEvent {
-private:
- int cellA_x;
- int cellA_y;
- int cellB_x;
- int cellB_y;
-public:
- const cString GetName() const { return "connect_cells"; }
- const cString GetDescription() const { return "connect_cells <int cellA_x> <int cellA_y> <int cellB_x> <int cellB_y>"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- cellA_x = args.PopWord().AsInt();
- cellA_y = args.PopWord().AsInt();
- cellB_x = args.PopWord().AsInt();
- cellB_y = args.PopWord().AsInt();
- }
- ///// connect_cells /////
- void Process(){
- const int world_x = m_world->GetPopulation().GetWorldX();
- const int world_y = m_world->GetPopulation().GetWorldY();
- if (cellA_x < 0 || cellA_x >= world_x ||
- cellA_y < 0 || cellA_y >= world_y ||
- cellB_x < 0 || cellB_x >= world_x ||
- cellB_y < 0 || cellB_y >= world_y) {
- cerr << "Event 'connect_cells' cell out of range." << endl;
- return;
- }
- int idA = cellA_y * world_x + cellA_x;
- int idB = cellB_y * world_x + cellB_x;
- cPopulationCell & cellA = m_world->GetPopulation().GetCell(idA);
- cPopulationCell & cellB = m_world->GetPopulation().GetCell(idB);
- tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
- tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
- cellA_list.PushRear(&cellB);
- cellB_list.PushRear(&cellA);
- }
-};
-
-///// disconnect_cells /////
-
-/**
-* Connects a pair of specified cells.
- * Arguments:
- * cellA_x, cellA_y, cellB_x, cellB_y
- **/
-
-
-class cEvent_disconnect_cells : public cEvent {
-private:
- int cellA_x;
- int cellA_y;
- int cellB_x;
- int cellB_y;
-public:
- const cString GetName() const { return "disconnect_cells"; }
- const cString GetDescription() const { return "disconnect_cells <int cellA_x> <int cellA_y> <int cellB_x> <int cellB_y>"; }
-
- void Configure(cWorld* world, const cString& in_args)
- {
- m_world = world;
- m_args = in_args;
- cString args(in_args);
- cellA_x = args.PopWord().AsInt();
- cellA_y = args.PopWord().AsInt();
- cellB_x = args.PopWord().AsInt();
- cellB_y = args.PopWord().AsInt();
- }
- ///// disconnect_cells /////
- void Process(){
- const int world_x = m_world->GetPopulation().GetWorldX();
- const int world_y = m_world->GetPopulation().GetWorldY();
- if (cellA_x < 0 || cellA_x >= world_x ||
- cellA_y < 0 || cellA_y >= world_y ||
- cellB_x < 0 || cellB_x >= world_x ||
- cellB_y < 0 || cellB_y >= world_y) {
- cerr << "Event 'connect_cells' cell out of range." << endl;
- return;
- }
- int idA = cellA_y * world_x + cellA_x;
- int idB = cellB_y * world_x + cellB_x;
- cPopulationCell & cellA = m_world->GetPopulation().GetCell(idA);
- cPopulationCell & cellB = m_world->GetPopulation().GetCell(idB);
- tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
- tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
- cellA_list.Remove(&cellB);
- cellB_list.Remove(&cellA);
- }
-};
-
-
class cEventAction : public cEvent
{
private:
@@ -172,9 +69,6 @@
cEventManager::cEventManager(cWorld* world) : m_world(world)
{
- // Population events --> Population Actions
- REGISTER(connect_cells);
- REGISTER(disconnect_cells);
}
cEvent* cEventManager::ConstructEvent(const cString name, const cString& args)
More information about the Avida-cvs
mailing list