[Fresco-devel] minesweeper
Nick Lewycky <[email protected]>
| Newsgroups | gmane.comp.video.fresco.devel |
|---|---|
| Message-ID | <[email protected]> |
I'd just like to announce that I have a working pre-alpha version of Fresco Minesweeper. Because it's small I attached a tarball, but the most recent version will be in BenB's Fresco-contrib project. -It currently does require the command-flyweight patch. (attached) -There's no way to flag a mine. -The minefield won't update unless you drag the window around. -It has no minefield generator. (Just a hard-coded 8x8 field.) -There's lots of bad stuff still in the code. I'd just like to talk about two issues. ISSUE 1: Right clicks are a problem. A Trigger is just a button. It takes a click and calls the Command. What should it do for different mouse buttons? My first instinct is to pass the event structure to the Command through the Any, so that it can handle it appropriately. But that isn't sufficient; suppose you were to tie a right-click to a popup menu. You wouldn't want to see the Trigger depress, as it does when clicked. The solution here seems to be decorators that can filter incoming events by type and deliver different ones to different places. I'm worried that this may get complicated, though. ISSUE 2: The Minefield will only update the square you clicked on, until you force a redraw. This is the "can't need_redraw() during Traversal" bug in a new form, and we need to fix it. Stefan has been adamant that there's no reason for a program to call need_redraw during a traversal, back from our 'animation' thread. I'll challenge that with "there's no reason not to." A need_redraw request can come at any time. Any time at all, during a traversal or not. Suppose you have two Graphics that update, one every 4 seconds and the other every 5, guess what, 20 seconds from now you'll get somebody calling need_redraw during a drawtraversal. It just happens. The minesweeper game triggers this by asking the Layout::Grid to replace many of its cells, one after the other. For each one, the Grid calls need_redraw. The Traversal is triggered as the first one is replaced. The other calls come in before the traversal is done. The dirty screen waits for an event to come in, as we've discussed at length. I have attached by non-working modifications to the main-loop code. If anyone can make them work, please chime in. The code I'm attaching doesn't match the algorithm already discussed because it didn't work and I started playing with it to see why. PS. Stefan suggests that I replace private: CORBA::Any *_data; in command-flyweight.patch with a CORBA::Any_var. Besides that I haven't gotten any code review. Do you all like its quality? Should I make the change and check it in? Thanks, Nick Lewycky
minesweeper.tar.bz2
(application/octet-stream, 3.3 KB) - not displayed
command-flyweight.patch
(text/plain, 3.7 KB)
Index: Berlin/modules/Tools/Stepper.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Tools/Stepper.cc,v
retrieving revision 1.7
diff -u -w -r1.7 Stepper.cc
--- Berlin/modules/Tools/Stepper.cc 29 May 2002 06:49:40 -0000 1.7
+++ Berlin/modules/Tools/Stepper.cc 22 Jul 2002 22:55:09 -0000
@@ -64,8 +64,7 @@
void Stepper::step()
{
Trace trace("Stepper::step");
- CORBA::Any any;
- execute(any);
+ execute();
}
void Stepper::start()
Index: Berlin/modules/Tools/TriggerImpl.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Tools/TriggerImpl.cc,v
retrieving revision 1.11
diff -u -w -r1.11 TriggerImpl.cc
--- Berlin/modules/Tools/TriggerImpl.cc 29 May 2002 06:49:40 -0000 1.11
+++ Berlin/modules/Tools/TriggerImpl.cc 22 Jul 2002 22:55:09 -0000
@@ -29,7 +29,7 @@
using namespace Prague;
using namespace Fresco;
-TriggerImpl::TriggerImpl() : ControllerImpl(false) {}
+TriggerImpl::TriggerImpl() : ControllerImpl(false), _data() {}
TriggerImpl::~TriggerImpl()
{
Trace trace("Trigger::~Trigger");
@@ -55,6 +55,17 @@
return Command::_duplicate(_command);
}
+void TriggerImpl::payload(const CORBA::Any &a)
+{
+ Trace trace("TriggerImpl::payload");
+ _data = new CORBA::Any(a);
+}
+
+CORBA::Any *TriggerImpl::payload()
+{
+ return _data;
+}
+
void TriggerImpl::release(PickTraversal_ptr traversal, const Input::Event &event)
{
/*
@@ -63,8 +74,7 @@
*/
if (inside(traversal) && test(Fresco::Controller::pressed))
{
- CORBA::Any dummy;
- try { execute(dummy);}
+ try { execute();}
catch (...) {}
}
ControllerImpl::release(traversal, event);
@@ -78,20 +88,19 @@
set(Fresco::Controller::pressed);
if (test(Fresco::Controller::pressed))
{
- CORBA::Any dummy;
- execute(dummy);
+ execute();
clear(Fresco::Controller::pressed);
}
}
else ControllerImpl::key_press(event);
}
-void TriggerImpl::execute(const CORBA::Any &any)
+void TriggerImpl::execute()
{
Trace trace("TriggerImpl::execute");
Prague::Guard<Mutex> guard(_mutex);
if (!CORBA::is_nil(_command))
- try { _command->execute(any);}
+ try { _command->execute(*_data);}
catch (const CORBA::OBJECT_NOT_EXIST &) { _command = Fresco::Command::_nil();}
catch (const CORBA::COMM_FAILURE &) { _command = Fresco::Command::_nil();}
}
Index: Berlin/modules/Tools/TriggerImpl.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/modules/Tools/TriggerImpl.hh,v
retrieving revision 1.6
diff -u -w -r1.6 TriggerImpl.hh
--- Berlin/modules/Tools/TriggerImpl.hh 29 May 2002 06:49:40 -0000 1.6
+++ Berlin/modules/Tools/TriggerImpl.hh 22 Jul 2002 22:55:09 -0000
@@ -37,10 +37,13 @@
~TriggerImpl();
void action(Fresco::Command_ptr);
Fresco::Command_ptr action();
+ void payload(const CORBA::Any &);
+ CORBA::Any *payload();
virtual void release(Fresco::PickTraversal_ptr, const Fresco::Input::Event &);
virtual void key_press(const Fresco::Input::Event &);
- void execute(const CORBA::Any &);
+ void execute();
private:
+ CORBA::Any *_data;
Prague::Mutex _mutex;
Fresco::Command_var _command;
};
Index: Fresco/idl/Fresco/Trigger.idl
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco/idl/Fresco/Trigger.idl,v
retrieving revision 1.6
diff -u -w -r1.6 Trigger.idl
--- Fresco/idl/Fresco/Trigger.idl 29 May 2002 06:57:01 -0000 1.6
+++ Fresco/idl/Fresco/Trigger.idl 22 Jul 2002 22:55:10 -0000
@@ -40,6 +40,7 @@
//. The Trigger will execute this Command (if it is not nil) when
//. clicked.
attribute Command action;
+ attribute any payload;
};
};
event-mainloop.patch
(text/plain, 5.2 KB)
Index: Berlin/include/Berlin/Console.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/include/Berlin/Console.hh,v
retrieving revision 1.26
diff -u -w -r1.26 Console.hh
--- Berlin/include/Berlin/Console.hh 29 May 2002 06:49:38 -0000 1.26
+++ Berlin/include/Berlin/Console.hh 27 Jul 2002 23:36:49 -0000
@@ -101,7 +101,9 @@
//. FIXME: Missing documentation!
virtual void device_info(std::ostream &) = 0;
- //. FIXME: Missing documentation!
+ //. If true, this is a promise not to block when next_event is called.
+ virtual bool has_event() = 0;
+ //. Wait until the next event comes from the input.
virtual Fresco::Input::Event *next_event() = 0;
//. FIXME: Missing documentation!
virtual void wakeup() = 0;
Index: Berlin/include/Berlin/EventManager.hh
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/include/Berlin/EventManager.hh,v
retrieving revision 1.20
diff -u -w -r1.20 EventManager.hh
--- Berlin/include/Berlin/EventManager.hh 29 May 2002 06:49:38 -0000 1.20
+++ Berlin/include/Berlin/EventManager.hh 27 Jul 2002 23:36:49 -0000
@@ -45,6 +45,7 @@
bool request_focus(Fresco::Controller_ptr, Fresco::Input::Device);
//. This method is polled by the ScreenManager. It queries the Console
//. for new events and distributes them to the matching focus.
+ bool has_event();
void next_event();
void restore(Fresco::Region_ptr);
void damage(Fresco::Region_ptr);
Index: Berlin/src/EventManager.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/EventManager.cc,v
retrieving revision 1.32
diff -u -w -r1.32 EventManager.cc
--- Berlin/src/EventManager.cc 29 May 2002 06:49:41 -0000 1.32
+++ Berlin/src/EventManager.cc 27 Jul 2002 23:36:50 -0000
@@ -72,6 +72,11 @@
return false;
}
+bool EventManager::has_event()
+{
+ return Console::instance()->has_event();
+}
+
void EventManager::next_event()
{
Trace trace("EventManager::next_event");
Index: Berlin/src/ScreenManager.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Berlin/src/ScreenManager.cc,v
retrieving revision 1.75
diff -u -w -r1.75 ScreenManager.cc
--- Berlin/src/ScreenManager.cc 2 Jun 2002 23:42:19 -0000 1.75
+++ Berlin/src/ScreenManager.cc 27 Jul 2002 23:36:50 -0000
@@ -127,6 +127,17 @@
_mutex.lock();
bool haveDamage = _theDamage->defined();
_mutex.unlock();
+
+ if (haveDamage)
+ {
+ repair();
+ }
+ //if (_emanager->has_event())
+ _emanager->next_event();
+ }
+}
+
+ /*
if (haveDamage)
{
Prague::Time current = Prague::Time::currentTime();
@@ -137,5 +148,4 @@
}
}
_emanager->next_event();
- }
-}
+ */
Index: GGI/src/Console.cc
===================================================================
RCS file: /cvs/fresco/Fresco/GGI/src/Console.cc,v
retrieving revision 1.9
diff -u -w -r1.9 Console.cc
--- GGI/src/Console.cc 2 Jun 2002 23:42:21 -0000 1.9
+++ GGI/src/Console.cc 27 Jul 2002 23:36:50 -0000
@@ -172,6 +172,15 @@
}
}
+bool GGI::Console::has_event()
+{
+ Prague::Trace trace("GGI::Console::has_event");
+ ggi_event_mask mask;
+
+ mask = ggi_event_mask(emKeyboard | emPtrMove | emPtrButton | emValuator);
+ return ggiEventsQueued(_visual, mask);
+}
+
Input::Event *GGI::Console::next_event()
{
Prague::Trace trace("GGI::Console::next_event");
Index: GGI/src/Console.hh
===================================================================
RCS file: /cvs/fresco/Fresco/GGI/src/Console.hh,v
retrieving revision 1.6
diff -u -w -r1.6 Console.hh
--- GGI/src/Console.hh 29 May 2002 06:49:41 -0000 1.6
+++ GGI/src/Console.hh 27 Jul 2002 23:36:50 -0000
@@ -54,6 +54,7 @@
Drawable *reference_to_servant(Fresco::Drawable_ptr);
virtual void device_info(std::ostream &);
+ virtual bool has_event();
virtual Fresco::Input::Event *next_event();
virtual void wakeup();
virtual void activate_autoplay() { _autoplay = true;}
Index: SDL/src/Console.cc
===================================================================
RCS file: /cvs/fresco/Fresco/SDL/src/Console.cc,v
retrieving revision 1.11
diff -u -w -r1.11 Console.cc
--- SDL/src/Console.cc 4 Jul 2002 00:19:13 -0000 1.11
+++ SDL/src/Console.cc 27 Jul 2002 23:36:51 -0000
@@ -183,6 +183,14 @@
os << "sorry, device info isn't available for SDL at this time" << std::endl;
}
+// a true result is a promise that we won't block when next_event is next called
+bool SDL::Console::has_event()
+{
+ Prague::Trace trace("SDL::Console::next_event()");
+
+ return SDL_PeepEvents(0, 1, SDL_PEEKEVENT, 0);
+}
+
Input::Event *SDL::Console::next_event()
{
Prague::Trace trace("SDL::Console::next_event()");
Index: SDL/src/Console.hh
===================================================================
RCS file: /cvs/fresco/Fresco/SDL/src/Console.hh,v
retrieving revision 1.8
diff -u -w -r1.8 Console.hh
--- SDL/src/Console.hh 4 Jul 2002 00:19:13 -0000 1.8
+++ SDL/src/Console.hh 27 Jul 2002 23:36:51 -0000
@@ -118,6 +118,7 @@
// Input related:
virtual void device_info(std::ostream &);
+ virtual bool has_event();
virtual Fresco::Input::Event *next_event();
virtual void activate_autoplay();
virtual void highlight_screen(Fresco::Coord, Fresco::Coord,