summaryrefslogtreecommitdiffstats
path: root/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h
diff options
context:
space:
mode:
Diffstat (limited to 'MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h')
-rw-r--r--MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h105
1 files changed, 101 insertions, 4 deletions
diff --git a/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h
index 97aa892..5ef6c5d 100644
--- a/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h
+++ b/MatchBloxEngine/MatchBloxEngine/C_MatchBloxEngine.h
@@ -44,15 +44,99 @@ enum BoxSize
BS_LARGE = 2
};
+struct GameSettings
+{
+ int m_iNrOfTurns;
+ double m_dMinProximity, //The minimum allowed squared (xz) distance between
+ //the center of the block and the center of the hole
+ //for the block to be considered to be in the hole
+ m_dHoleDepth; //Depth of a hole; the minimum z distance between block
+ //and a hole, for the block to be successfully inserted
+ //into the box
+};
+
+struct GameSession
+{
+ int m_iTotalTurns,
+ m_iCurrentTurn;
+ unsigned int m_uiSessionStart, //time in ms
+ m_uiTurnStart,
+ m_uiPauseStart,
+ *m_puiTurnResult;
+ int m_iBlocksLeft[4]; //number of blocks per type
+ BlockType m_CurrentBlockType;
+ BoxSize m_BoxSize;
+
+ GameSession(int f_iNrOfBlocks, BoxSize f_BS)
+ : m_iTotalTurns(f_iNrOfBlocks), m_iCurrentTurn(0),
+ m_BoxSize(f_BS)
+ {
+ m_puiTurnResult = new unsigned int[f_iNrOfBlocks];
+
+ //divide the number of blocks between the block types
+ int l_iNrPerType = f_iNrOfBlocks/4,
+ l_iLeft = f_iNrOfBlocks%4; //the left-over count
+ for(int i=0; i<4; i++)
+ {
+ m_iBlocksLeft[i] = l_iNrPerType;
+ if (l_iLeft > 0)
+ {
+ m_iBlocksLeft[i]++; l_iLeft--;
+ }
+ }
+ }
+ ~GameSession()
+ {
+ delete [] m_puiTurnResult;
+ }
+ BlockType StartSession()
+ {
+ m_uiSessionStart = m_uiTurnStart = glutGet(GLUT_ELAPSED_TIME);
+ return GetRandomBlockType();
+ }
+ BlockType NewTurn()
+ {
+ unsigned int l_uiTime = glutGet(GLUT_ELAPSED_TIME);
+
+ //save turn result
+ m_puiTurnResult[m_iCurrentTurn] = l_uiTime - m_uiTurnStart;
+ m_iCurrentTurn++;
+ m_uiTurnStart = l_uiTime;
+
+ return GetRandomBlockType();
+ }
+ BlockType GetRandomBlockType()
+ {
+ int l_iBlockType = rand()%4;
+ while (m_iBlocksLeft[l_iBlockType] <= 0)
+ l_iBlockType = (l_iBlockType+1)%4;
+
+ m_iBlocksLeft[l_iBlockType]--;
+ return (BlockType)l_iBlockType;
+ }
+ void PauseSession()
+ {
+ //record the time at which the pause starts
+ m_uiPauseStart = glutGet(GLUT_ELAPSED_TIME);
+ }
+ void ResumeSession()
+ {
+ //add the total pause time to the timers
+ unsigned int l_uiPauseTime = glutGet(GLUT_ELAPSED_TIME) - m_uiPauseStart;
+ m_uiSessionStart += l_uiPauseTime;
+ m_uiTurnStart += l_uiPauseTime;
+ }
+}
class C_MatchBloxEngine
{
public:
C_MatchBloxEngine(const char *f_strModelPath,
- const char *f_strLogFile);
+ const char *f_strLogFile
+ GameSettings f_GameSettings);
~C_MatchBloxEngine();
- GameResult GameStep(msgQueue &f_Queue);
+ GameResult ProcessMsgs(msgQueue &f_Queue);
void Render(unsigned int f_uiElapsedTime);
bool NewGame(int f_iUserID, int f_iGameId, BoxSize f_BS);
@@ -74,13 +158,26 @@ private:
m_uiWood3Tex;
EngineState m_State, m_SavedState;
- BoxSize m_CurrentBox;
+ GameSession *m_pCurrentSession;
+ GameSettings m_GameSettings;
- void Render_Basics(unsigned int f_uiElapsedTime);
+ BoundingBox_t m_WorldBox; //an invisible box that limits the movement of the
+ //player
+
+ //init routines
bool LoadModels(const char* f_strModelDir);
void DeleteModels();
void LoadTexture(const char* f_BmpName, GLuint &f_uiTexHandle);
+
+ //render routines
+ void Render_Basics(unsigned int f_uiElapsedTime);
+
+ //event/input handlers
+ void CursorMove(Vect3D_t &f_NewCursorPos);
+ GameResult_t CursorMove_PutBlock(Vect3D_t &f_CursPos, BoundingBox_t &f_CusrBBox);
+ GameResult_t CursorMove_GrabBlock(Vect3D_t &f_CursPos, BoundingBox_t &f_CusrBBox);
+
};
#endif //C_MATCHBLOXENGINE_HEADER_FILE