[dasher: 17/28] Game mode preferences - distance to need help for period of time, draw path?
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 17/28] Game mode preferences - distance to need help for period of time, draw path?
- Date: Tue, 22 Nov 2011 17:04:05 +0000 (UTC)
commit 3d11adfb9b0581e4d22f63b7564ef258ab7745f1
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Mon Sep 26 15:17:40 2011 +0100
Game mode preferences - distance to need help for period of time, draw path?
Src/DasherCore/GameModule.cpp | 80 +++++++++++++++++++++++++++-------------
Src/DasherCore/GameModule.h | 15 ++++++--
Src/DasherCore/Parameters.cpp | 3 ++
Src/DasherCore/Parameters.h | 5 ++-
4 files changed, 73 insertions(+), 30 deletions(-)
---
diff --git a/Src/DasherCore/GameModule.cpp b/Src/DasherCore/GameModule.cpp
index b502f71..58dd065 100644
--- a/Src/DasherCore/GameModule.cpp
+++ b/Src/DasherCore/GameModule.cpp
@@ -4,15 +4,29 @@
using namespace Dasher;
+static SModuleSettings gameSets[] = {
+ {SP_GAME_TEXT_FILE, T_STRING, -1, -1, -1, -1, _("Filename of sentences to enter")},
+ {LP_GAME_HELP_DIST, T_LONG, 0, 4096, 2048, 128, _("Distance of sentence from center to decide user needs help")},
+ {LP_GAME_HELP_TIME, T_LONG, 0, 10000, 1000, 100, _("Time for which user must need help before help drawn")},
+ {BP_GAME_HELP_DRAW_PATH, T_BOOL, -1, -1, -1, -1, _("When we give help, show the shortest path to the target sentence?")},
+};
+
CGameModule::CGameModule(CSettingsUser *pCreateFrom, Dasher::CDasherInterfaceBase *pInterface, CDasherView *pView, CDasherModel *pModel)
: CSettingsUser(pCreateFrom), TransientObserver<const Dasher::CEditEvent *>(pInterface), TransientObserver<CGameNodeDrawEvent*>(pView),
TransientObserver<CDasherNode*>(pModel), TransientObserver<CDasherView*>(pView),
m_pInterface(pInterface), m_iLastSym(-1),
m_y1(std::numeric_limits<myint>::min()), m_y2(std::numeric_limits<myint>::max()),
+m_iTargetY(CDasherModel::ORIGIN_Y), m_uHelpStart(std::numeric_limits<unsigned long>::max()),
m_ulTotalTime(0), m_dTotalNats(0.0), m_uiTotalSyms(0),
m_iCrosshairColor(135), m_iFontSize(36)
{}
+bool CGameModule::GetSettings(SModuleSettings **sets, int *count) {
+ *sets = gameSets;
+ *count = sizeof(gameSets) / sizeof(gameSets[0]);
+ return true;
+}
+
CGameModule::~CGameModule() {
DASHER_ASSERT(!GetBoolParameter(BP_GAME_MODE));
if (m_ulTotalTime) {
@@ -104,36 +118,50 @@ void CGameModule::DecorateView(unsigned long lTime, CDasherView *pView, CDasherM
if (m_dSentenceStartNats == numeric_limits<double>::max())
m_dSentenceStartNats = pModel->GetNats();
-
- m_vTargetY.push_back(m_iTargetY = (m_y1+m_y2)/2);
- //draw a line along the y axis
- myint x[2], y[2];
- x[0] = x[1] = -100;
+ const myint iNewTarget((m_y1+m_y2)/2);
+ m_vTargetY.push_back(iNewTarget);
+ bool bDrawHelper=false;
- bool bDrawHelper=true;
- const int lineWidth(GetLongParameter(LP_LINE_WIDTH));
+ if (abs(iNewTarget - CDasherModel::ORIGIN_Y) >
+ max(myint(GetLongParameter(LP_GAME_HELP_DIST)),abs(m_iTargetY-CDasherModel::ORIGIN_Y))) {
+ //needs help - offscreen and not decreasing
+ if (m_uHelpStart==std::numeric_limits<unsigned long>::max())
+ m_uHelpStart = lTime;
+ else
+ bDrawHelper = (lTime-m_uHelpStart >= GetLongParameter(LP_GAME_HELP_TIME));
+ } else m_uHelpStart = std::numeric_limits<unsigned long>::max();
- if (m_y1 > CDasherModel::MAX_Y) {
- //off the top! draw an arrow pointing up...
- y[1] = CDasherModel::MAX_Y;
- y[0] = y[1] - 400;
- } else if (m_y2 < 0) {
- //off the bottom! draw arrow pointing down...
- y[1] = 0;
- y[0] = 400;
- } else {
- //draw line parallel to that region of y-axis
- y[0] = m_y1; y[1] = m_y2;
- pView->DasherPolyline(x, y, 2, lineWidth, m_iCrosshairColor);
- //and a horizontal arrow pointing to the midpoint
- x[0] = -400;
- y[0] = y[1] = m_iTargetY;
- bDrawHelper=false;
- }
- pView->DasherPolyarrow(x, y, 2, 3*lineWidth, m_iCrosshairColor, 0.2);
+ m_iTargetY = iNewTarget;
+ if (bDrawHelper) {
+ //draw a line along the y axis
+ myint x[2], y[2];
+ x[0] = x[1] = -100;
- if (bDrawHelper) DrawBrachistochrone(pView);
+ const int lineWidth(GetLongParameter(LP_LINE_WIDTH));
+ myint minX,minY,maxX,maxY;
+ pView->VisibleRegion( minX, minY, maxX, maxY);
+
+ if (m_y1 > maxY) {
+ //off the top! make arrow point straight up...
+ y[1] = CDasherModel::MAX_Y;
+ y[0] = y[1] - 400;
+ } else if (m_y2 < minY) {
+ //off the bottom! make arrow point straight down...
+ y[1] = 0;
+ y[0] = 400;
+ } else {
+ //draw line parallel to that region of y-axis
+ y[0] = m_y1; y[1] = m_y2;
+ pView->DasherPolyline(x, y, 2, lineWidth, m_iCrosshairColor);
+ //and make arrow horizontal, pointing to the midpoint
+ x[0] = -400;
+ y[0] = y[1] = m_iTargetY;
+ }
+ pView->DasherPolyarrow(x, y, 2, 3*lineWidth, m_iCrosshairColor, 0.2);
+
+ if (GetBoolParameter(BP_GAME_HELP_DRAW_PATH)) DrawBrachistochrone(pView);
+ }
//reset location accumulators ready for next frame
m_y1 = std::numeric_limits<myint>::min();
diff --git a/Src/DasherCore/GameModule.h b/Src/DasherCore/GameModule.h
index 6e6dda1..3a9e1d2 100644
--- a/Src/DasherCore/GameModule.h
+++ b/Src/DasherCore/GameModule.h
@@ -10,7 +10,7 @@ using namespace std;
#include "DasherScreen.h"
#include "DasherModel.h"
-#include "DasherModule.h"
+#include "../Common/ModuleSettings.h"
#include "DasherNode.h"
#include "DasherView.h"
#include "DasherTypes.h"
@@ -61,6 +61,12 @@ class CGameModule : protected CSettingsUser, protected TransientObserver<const C
* @param pWordGenerator the word generator to be used
*/
void SetWordGenerator(const CAlphInfo *pAlph, CWordGeneratorBase *pWordGenerator);
+
+ /// The "GameModule" isn't actually a DasherModule, and/so this will be never called,
+ /// but for uniformity with existing module settings API, I'm using this to record
+ /// what preferences there are that affect Game Mode - really, these should be
+ /// displayed to the user each time (s)he enters Game Mode.
+ bool GetSettings(SModuleSettings **sets, int *count);
protected:
///Called after each successful call to GenerateChunk. Subclasses may override
@@ -129,6 +135,11 @@ private:
///Best-known Location of target sentence in each frame
vector<myint> m_vTargetY;
+ ///Last element of above, i.e. current location of target sentence
+ myint m_iTargetY;
+ ///Time at which we first needed help, or numeric_limits<unsigned long>::max()
+ /// if we don't.
+ unsigned long m_uHelpStart;
///Statistics over all _previous_ sentences: total time, total nats, total syms
unsigned long m_ulTotalTime;
@@ -139,8 +150,6 @@ private:
unsigned long m_ulSentenceStartTime;
double m_dSentenceStartNats;
- myint m_iTargetY;
-
/* ---------------------------------------------------------------------
* Constants
* ---------------------------------------------------------------------
diff --git a/Src/DasherCore/Parameters.cpp b/Src/DasherCore/Parameters.cpp
index 3a4fc78..598b063 100644
--- a/Src/DasherCore/Parameters.cpp
+++ b/Src/DasherCore/Parameters.cpp
@@ -58,6 +58,7 @@ const bp_table boolparamtable[] = {
#endif
{BP_CONTROL_MODE_HAS_COPY, "ControlHasCopy", PERS, true, "Provide copy-to-clipboard actions in Control Mode (if platforms supports)"},
{BP_CONTROL_MODE_HAS_SPEECH, "ControlHasSpeech", PERS, true, "Provide speech actions in Control Mode (if platform supports)"},
+ {BP_GAME_HELP_DRAW_PATH, "GameDrawPath", PERS, true, "When we give help, show the shortest path to the target sentence"},
};
const lp_table longparamtable[] = {
@@ -143,6 +144,8 @@ const lp_table longparamtable[] = {
{LP_MARGIN_WIDTH, "MarginWidth", PERS, 300, "Width of RHS margin (in Dasher co-ords)"},
#endif
{LP_TARGET_OFFSET, "TargetOffset", PERS, 0, "Vertical distance between mouse pointer and target (400=screen height)"},
+ {LP_GAME_HELP_DIST, "GameHelpDistance", PERS, 1920, "Distance of sentence from center to decide user needs help"},
+ {LP_GAME_HELP_TIME, "GameHelpTime", PERS, 0, "Time for which user must need help before help drawn"},
};
const sp_table stringparamtable[] = {
diff --git a/Src/DasherCore/Parameters.h b/Src/DasherCore/Parameters.h
index 89b5ed7..e7b1ece 100644
--- a/Src/DasherCore/Parameters.h
+++ b/Src/DasherCore/Parameters.h
@@ -42,6 +42,7 @@ enum {
BP_TWOBUTTON_REVERSE, BP_2B_INVERT_DOUBLE, BP_SLOW_START,
BP_COPY_ALL_ON_STOP, BP_SPEAK_ALL_ON_STOP, BP_SPEAK_WORDS,
BP_CONTROL_MODE_HAS_HALT, BP_CONTROL_MODE_HAS_EDIT, BP_CONTROL_MODE_HAS_COPY, BP_CONTROL_MODE_HAS_SPEECH,
+ BP_GAME_HELP_DRAW_PATH,
END_OF_BPS
};
@@ -63,7 +64,9 @@ enum {
LP_DYNAMIC_BUTTON_LAG, LP_STATIC1B_TIME, LP_STATIC1B_ZOOM,
LP_DEMO_SPRING, LP_DEMO_NOISE_MEM, LP_DEMO_NOISE_MAG, LP_MAXZOOM,
LP_DYNAMIC_SPEED_INC, LP_DYNAMIC_SPEED_FREQ, LP_DYNAMIC_SPEED_DEC,
- LP_TAP_TIME, LP_MARGIN_WIDTH, LP_TARGET_OFFSET, END_OF_LPS
+ LP_TAP_TIME, LP_MARGIN_WIDTH, LP_TARGET_OFFSET,
+ LP_GAME_HELP_DIST, LP_GAME_HELP_TIME,
+ END_OF_LPS
};
enum {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]