start 380 project5

changes to 380 project 4
changes to 350 project 2

Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
Amrit Panesar committed 2015-05-06 10:18:39 -07:00
1 parent 40ac78074b
commit 39ee821f54
174 files changed
+13356 -80

No files matched your search

@@ -0,0 +1,25 @@
#include "CustomGame.h"
#include "Pages\MainPage.h"
const wchar_t *CustomGame::settingsFileName = L"..\\Settings.dat";
const wchar_t *CustomGame::screenShotsFileExp = L"..\\Logging\\Plays\\play{0}.jpg";
CustomGame::CustomGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice) :
GkGame(graphicsDevice, soundDevice)
{
this->logGamePlay = new GkLogFile<LogRecordGamePlay>(L"..\\Logging\\GamePlay.log");
//this->settings = new Settings(CustomGame::settingsFileName, this);
this->AddGamePage(new MainPage(this));
}
CustomGame::~CustomGame(void)
{
delete this->logGamePlay;
//delete this->settings;
}
@@ -0,0 +1,39 @@
#pragma once
#include "..\Engine\GambleKit.h"
//#include "Settings.h"
//#include "Dictionary.h"
struct LogRecordGamePlay
{
DateTime time;
int bet;
int winning;
};
class MainPage;
class MainMenuPage;
class CustomGame :
public GkGame
{
public:
static const wchar_t *dataFileName, *settingsFileName;
static const wchar_t *screenShotsFileExp;
bool isPayingCredits;
int creditsPayed;
//Settings *settings;
GkLogFile<LogRecordGamePlay> *logGamePlay;
MainPage *mainPage;
MainMenuPage *mainMenuPage;
CustomGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice);
~CustomGame(void);
};
@@ -0,0 +1,78 @@
#include "MainWindow.h"
#include "Pages\MainPage.h"
MainWindow::MainWindow(void)
{
if (this->deviceContext == 0)
GkOSUtils::ShowMessage("Error creating device context", this->handle);
if (this->renderContext == 0)
GkOSUtils::ShowMessage("Error creating rendering context", this->handle);
this->graphicsDevice = new GkGraphicsDevice();
if (this->graphicsDevice->maxTextureSize < 2048)
GkOSUtils::ShowMessage(GkStrings::ToShort(GkStrings::Format(L"Graphics device does not suport textures with dimensions of size at least 2048 pixels.\r\nMaxium supported size is {0}.\r\nSome textures may not be rendered.", GkStrings::IntToString(this->graphicsDevice->maxTextureSize).c_str()).c_str()).c_str());
if (!this->graphicsDevice->nonPower2Textures)
GkOSUtils::ShowMessage("Graphics device does not support textures of arbitraty dimensions. Application will require more video memory than normal.");
this->soundDevice = new GkSoundDevice();
GkFileSystem::SetSource(L"..\\GameData\\", FileSystemMode_Physical);
this->game = new CustomGame(this->graphicsDevice, this->soundDevice);
this->SetPosition(0, 0);
this->SetSize(800, 600);
this->SetActive();
}
MainWindow::~MainWindow(void)
{
}
bool MainWindow::Close()
{
delete this->game;
delete this->soundDevice;
delete this->graphicsDevice;
return true;
}
void MainWindow::MainLoop()
{
//TODO: timed rendering (main or custom thread, Sleep(frameInterval - renderTime). VSync
this->game->NewFrame();
this->MakeCurrent();
this->game->Process();
this->game->Render();
this->Present();
// If thre are changes to the settings data, they will automatically be written to disk
//this->game->settings->WriteChanges();
}
void MainWindow::MouseDown(int x, int y, int mouseButtons)
{
this->game->MouseDown(x, y);
};
void MainWindow::MouseUp(int x, int y, int mouseButtons)
{
this->game->MouseUp(x, y);
}
void MainWindow::Resize(int width, int height)
{
this->graphicsDevice->SetViewport(0, 0, width, height);
}
void MainWindow::KeyDown(int keyCode)
{
if (keyCode == VK_ESCAPE)
this->DestroyFormWindow();
}
@@ -0,0 +1,26 @@
#pragma once
#include "..\Engine\GambleKit.h"
#include "CustomGame.h"
class MainWindow :
public GkOpenGLWindowsForm
{
public:
GkGraphicsDevice *graphicsDevice;
GkSoundDevice *soundDevice;
CustomGame *game;
MainWindow::MainWindow(void);
MainWindow::~MainWindow(void);
bool MainWindow::Close();
void MainWindow::MainLoop();
void MainWindow::MouseDown(int x, int y, int mouseButtons);
void MainWindow::MouseUp(int x, int y, int mouseButtons);
void MainWindow::Resize(int width, int height);
void MainWindow::KeyDown(int keyCode);
};
@@ -0,0 +1,159 @@
#include "MainPage.h"
#include "..\..\Engine\GambleKit.h"
MainPage::MainPage(CustomGame *game)
: GkGamePage()
{
// Initialize the variables
this->bet = 10;
this->lines = 5;
this->winning = 0;
this->credits = 100;
// Add the background
this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"Background.png")));
// Create the Bet, Lines and Start buttons
this->btnBet = (GkGameClickButton*)this->AddEntity(new GkGameClickButton(
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_bet_default.png"), 354, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_bet_down.png"), 354, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_bet_disabled.png"), 354, 528)));
this->btnLines = (GkGameClickButton*)this->AddEntity(new GkGameClickButton(
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_lines_default.png"), 524, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_lines_down.png"), 524, 528),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_lines_disabled.png"), 524, 528)));
this->btnStart = (GkGameClickButton*)this->AddEntity(new GkGameClickButton(
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_start_default.png"), 687, 503),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_start_down.png"), 687, 503),
new GkGameAnimation(game->AcquireAnimatedTexture(L"btn_start_disabled.png"), 687, 503)));
// Create a special counter for the credits, to make them appear to increase gradually for better visual experience
GkGameWinningCounter *creditsCounter = (GkGameWinningCounter*)this->AddEntity(new GkGameWinningCounter(&this->credits, 500.0f, 2.0f));
// Create the Credits, Winning, Bet and Lines text counters and bind them to their respective values. Note that credits is bound to the "creditsCounter"
this->AddEntity(new GkGameTextsIntBinding(&creditsCounter->intDisplayValue, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 80, 496, -3, GkGameText::GameTextAlignment_Center))));
this->AddEntity(new GkGameTextsIntBinding(&this->winning, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 250, 496, -3, GkGameText::GameTextAlignment_Center))));
this->AddEntity(new GkGameTextsIntBinding(&this->bet, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 420, 496, -3, GkGameText::GameTextAlignment_Center))));
this->AddEntity(new GkGameTextsIntBinding(&this->lines, 1, this->AddEntity(new GkGameText(game->AcquireAnimatedFontFromMultipleFiles(L"font_main_{0}.png", L"0123456789,.-"), 590, 496, -3, GkGameText::GameTextAlignment_Center))));
// Create the combinations generator. The combinations generator represents a model of collection of reels. Each of its reels can have a different model
// The GkGameReelStripModel is a GkGameReelModel, representing a reel with a fixed sequence of finite number of items. Here, it is used for all the reels of the combination generator.
this->combinationsGenerator = new GkGameReelsCombinationGenerator(5, 3);
this->combinationsGenerator->SetReelModel(0, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_Melon, ReelItem_Cherry, ReelItem_Bell, ReelItem_Cherry, ReelItem_Melon));
this->combinationsGenerator->SetReelModel(1, new GkGameReelStripModel(3, 6, ReelItem_Bell, ReelItem_Melon, ReelItem_Bell, ReelItem_Melon, ReelItem_Melon, ReelItem_Cherry));
this->combinationsGenerator->SetReelModel(2, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_7, ReelItem_Melon, ReelItem_Cherry, ReelItem_7, ReelItem_Bell));
this->combinationsGenerator->SetReelModel(3, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_Bell, ReelItem_Melon, ReelItem_Bell, ReelItem_Cherry, ReelItem_Bell));
this->combinationsGenerator->SetReelModel(4, new GkGameReelStripModel(3, 6, ReelItem_Cherry, ReelItem_Melon, ReelItem_Bell, ReelItem_Cherry, ReelItem_Melon, ReelItem_Bell));
// Create the visual object for the reels
this->reels = (GkGameReels*)this->AddEntity(new GkGameReels(5, 3, 4, 670, 331));
this->reels->symbols[ReelItem_Cherry] = game->AcquireAnimatedTexture(L"symbol_cherry.png");
this->reels->symbols[ReelItem_Melon ] = game->AcquireAnimatedTexture(L"symbol_melon.png");
this->reels->symbols[ReelItem_Bell ] = game->AcquireAnimatedTexture(L"symbol_bell.png");
this->reels->symbols[ReelItem_7 ] = game->AcquireAnimatedTexture(L"symbol_7.png");
this->reels->x = 62;
this->reels->y = 90;
this->reels->ApplyReelMap();// (this->game->settings->playerSettings->currentMap);
this->reels->SetItemGenerator(this->combinationsGenerator);
// Load the images used to show a winning line
this->lineAnimations[0] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line123.png"), 112, 255));
this->lineAnimations[1] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line123.png"), 112, 139));
this->lineAnimations[2] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line123.png"), 112, 371));
this->lineAnimations[3] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line45.png"), 112, 139));
this->lineAnimations[4] = (GkGameAnimation*)this->AddEntity(new GkGameAnimation(game->AcquireAnimatedTexture(L"line45.png"), 112, 139, true, true, true, false, true));
// The winnings model defines two things. One is the properties of the symbols - their coefficients and special behaviour. Second - the shape of the winning lines.
this->winningsModel = new GkGameWinningsModel(5, 3, 5, 4, 0);
this->winningsModel->SetupSymbol(ReelItem_Cherry, 0, GkGameWinningsModel::SymbolFlag_Default, GkGameWinningsModel::SymbolFlag_None, 0, 0, 10, 20, 80);
this->winningsModel->SetupSymbol(ReelItem_Melon , 0, GkGameWinningsModel::SymbolFlag_Default, GkGameWinningsModel::SymbolFlag_None, 0, 0, 20, 40, 200);
this->winningsModel->SetupSymbol(ReelItem_Bell , 0, GkGameWinningsModel::SymbolFlag_Default, GkGameWinningsModel::SymbolFlag_None, 0, 0, 50, 100, 500);
this->winningsModel->SetupSymbol(ReelItem_7 , 0, GkGameWinningsModel::SymbolFlag_Wild, GkGameWinningsModel::SymbolFlag_None, 0, 0, 0, 0, 0);
this->winningsModel->SetupLine(0, 1, 1, 1, 1, 1);
this->winningsModel->SetupLine(1, 0, 0, 0, 0, 0);
this->winningsModel->SetupLine(2, 2, 2, 2, 2, 2);
this->winningsModel->SetupLine(3, 0, 1, 2, 1, 0);
this->winningsModel->SetupLine(4, 2, 1, 0, 1, 2);
// The winnings analyzer is used to analyze a combination for winnings, based on a winning model. After an analisys, it holds all the winnings, if any, and detailed information on them.
this->winningsAnalyzer = new GkGameWinningsAnalyzer(this->winningsModel);
this->sndReels = game->AcquireSoundSource(L"reels.wav");
this->sndReelStop = game->AcquireSoundSource(L"reel.wav");
}
MainPage::~MainPage(void)
{
delete this->combinationsGenerator;
delete this->winningsAnalyzer;
delete this->winningsModel;
}
void MainPage::Process(GkGame *game)
{
if (this->reels->state == Idle)
{
// Start button - hide the lines, generate a random combination, set it to appear on the reels after spinning, analyze its winning and start the reels
if (this->btnStart->IsClicked())
{
for (int lineIndex = 0; lineIndex < this->winningsModel->numLines; lineIndex++)
this->lineAnimations[lineIndex]->visible = false;
this->credits -= this->bet * this->lines;
this->combinationsGenerator->GenerateCombination();
this->reels->SetItems(this->combinationsGenerator);
this->winningsAnalyzer->AnalyzeWinnings(this->combinationsGenerator);
this->winningsAnalyzer->MultiplyWinnings(this->bet);
this->reels->Start();
game->soundDevice->PlaySourceLooping(this->sndReels);
}
// Bet button - change the bet
if (this->btnBet->IsClicked())
{
this->bet = this->bet % 10 + 1;
}
// Lines button - set which lines in the winnings model are active
if (this->btnLines->IsClicked())
{
this->lines = this->lines % 5 + 1;
for (int lineIndex = 0; lineIndex < this->winningsModel->numLines; lineIndex++)
this->winningsModel->lines[lineIndex].active = lineIndex < this->lines;
}
}
// Stop the spinning reels when the button is pressed
if (this->reels->state == Spinning)
{
if (this->btnStart->IsClicked())
this->reels->Stop();
}
// When reels' state HAS JUST CHANGED to Idle, then show any winning lines, if any, and update combination winning and credits
if (this->reels->stateChange == Idle)
{
for (int winIndex = 0; winIndex < this->winningsAnalyzer->winnings.count; winIndex++)
this->lineAnimations[this->winningsAnalyzer->winnings.win[winIndex].lineIndex]->visible = true;
this->winning = this->winningsAnalyzer->totalWinning;
this->credits += this->winning;
game->soundDevice->PauseSource(this->sndReels);
}
// Sound on every reel stop
for (int reelIndex = 0; reelIndex < this->reels->numReels; reelIndex++)
if (this->reels->reels[reelIndex].stateChange == PostStopping)
game->soundDevice->PlaySource(this->sndReelStop);
GkGamePage::Process(game);
}
@@ -0,0 +1,37 @@
#pragma once
#include "..\CustomGame.h"
class MainPage :
public GkGamePage
{
public:
static const int ReelItem_Cherry = 0,
ReelItem_Melon = 1,
ReelItem_Bell = 2,
ReelItem_7 = 3;
GkGameClickButton *btnStart, *btnBet, *btnLines;
GkGameText *textCredits, *textWinning, *textBet, *textLines;
GkGameAnimation *lineAnimations[5];
GkGameReels *reels;
GkGameReelsCombinationGenerator *combinationsGenerator;
GkGameWinningsModel *winningsModel;
GkGameWinningsAnalyzer *winningsAnalyzer;
int bet, lines, winning, credits;
GkSoundSource *sndReels, *sndReelStop;
MainPage(CustomGame *game);
~MainPage(void);
void Process(GkGame *game);
};
@@ -0,0 +1,30 @@
//#define _CRTDBG_MAP_ALLOC
//#include <stdlib.h>
//#include <crtdbg.h>
#include <vld\vld.h>
#include "MainWindow.h"
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
{
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
GkMaths::Randomize();
//Dictionary::Initialize();
GkImage::Initialize();
GkGraphicsDevice::Initialize();
GkSoundDevice::Initialize();
MainWindow mainWindow;
GkWindowsForm::PerformFormLoop();
GkSoundDevice::Close();
//Dictionary::Close();
//_CrtDumpMemoryLeaks();
return 0;
}
@@ -0,0 +1,23 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkBase.h"
GkBase::GkBase(void)
{
}
GkBase::~GkBase(void)
{
}
@@ -0,0 +1,11 @@
#pragma once
#include "..\GkDefinitions.h"
class GKDLLCLASS GkBase
{
public:
GkBase::GkBase(void);
virtual GkBase::~GkBase(void);
};
@@ -0,0 +1,126 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkBaseReelMap.h"
#include "..\OSSpecific\GkOSUtils.h"
GkBaseReelMap::GkBaseReelMap(int numReels, int numReelItems)
: GkBase()
{
this->numReels = numReels;
this->numReelItems = numReelItems;
this->reelMap = new int[this->numReels * this->numReelItems];
GkOSUtils::ZeroMem(this->reelMap, this->numReels * this->numReelItems * sizeof(int));
}
GkBaseReelMap::~GkBaseReelMap(void)
{
delete[] reelMap;
}
void GkBaseReelMap::SetSymbol(int reelIndex, int itemIndex, int symbolIndex)
{
this->reelMap[reelIndex * this->numReelItems + itemIndex] = symbolIndex;
}
int GkBaseReelMap::GetSymbol(int reelIndex, int itemIndex)
{
return this->reelMap[reelIndex * this->numReelItems + itemIndex];
}
void GkBaseReelMap::SetItems(GkBaseReelMap *reelMap, int startReel, int startItem, int numReels, int numItems)
{
int maxReel = startReel + numReels;
int maxItem = startItem + numItems;
for (int reelIndex = startReel; reelIndex < maxReel; reelIndex++)
{
for (int itemIndex = startItem; itemIndex < maxItem; itemIndex++)
{
this->SetSymbol(reelIndex, itemIndex, reelMap->GetSymbol(reelIndex, itemIndex));
}
}
}
void GkBaseReelMap::SetItems(GkBaseReelMap *reelMap)
{
this->SetItems(reelMap, 0, 0, this->numReels, this->numReelItems);
}
void GkBaseReelMap::SetReelItems(GkBaseReelMap *reelMap, int reelIndex)
{
this->SetItems(reelMap, reelIndex, 0, 1, this->numReelItems);
}
void GkBaseReelMap::SetItems(const int *reelMap)
{
GkOSUtils::CopyMem(this->reelMap, (void*)reelMap, this->numReels * this->numReelItems * sizeof(int));
}
void GkBaseReelMap::WriteItems(const int *reelMap)
{
GkOSUtils::CopyMem((void*)reelMap, this->reelMap, this->numReels * this->numReelItems * sizeof(int));
}
int GkBaseReelMap::CountItems(int reelIndex, int itemIndex)
{
int result = 0;
for (int i = 0; i < this->numReelItems; i++)
if (this->GetSymbol(reelIndex, i) == itemIndex)
result++;
return result;
}
int GkBaseReelMap::CountItems(int itemIndex)
{
int result = 0;
for (int i = 0; i < this->numReels; i++)
result += this->CountItems(i, itemIndex);
return result;
}
int GkBaseReelMap::FindFirstSymbol(int reelIndex, int symbolIndex)
{
for (int i = 0; i < this->numReelItems; i++)
if (this->GetSymbol(reelIndex, i) == symbolIndex)
return i;
return -1;
}
bool GkBaseReelMap::ReelEquals(GkBaseReelMap *reelMap, int reelIndex)
{
if (this->numReelItems != reelMap->numReelItems)
return false;
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
if (this->GetSymbol(reelIndex, itemIndex) != reelMap->GetSymbol(reelIndex, itemIndex))
return false;
return true;
}
bool GkBaseReelMap::ReelsEquals(GkBaseReelMap *reelMap)
{
if (this->numReels != reelMap->numReels)
return false;
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
if (!this->ReelEquals(reelMap, reelIndex))
return false;
return true;
}
@@ -0,0 +1,31 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkBase.h"
class GKDLLCLASS GkBaseReelMap
: public GkBase
{
public:
int numReels, numReelItems;
int *reelMap;
GkBaseReelMap(int numReels, int numReelItems);
~GkBaseReelMap(void);
virtual void SetSymbol(int reelIndex, int itemIndex, int symbolIndex);
virtual int GetSymbol(int reelIndex, int itemIndex);
void SetItems(GkBaseReelMap *reelMap, int startReel, int startItem, int numReels, int numItems);
void SetItems(GkBaseReelMap *reelMap);
void SetReelItems(GkBaseReelMap *reelMap, int reelIndex);
void SetItems(const int *reelMap);
void WriteItems(const int *reelMap);
int CountItems(int reelIndex, int itemIndex);
int CountItems(int itemIndex);
int FindFirstSymbol(int reelIndex, int symbolIndex);
bool ReelEquals(GkBaseReelMap *reelMap, int reelIndex);
bool ReelsEquals(GkBaseReelMap *reelMap);
};
@@ -0,0 +1,57 @@
#pragma once
#include "Base\GkBase.h"
#include "Base\GkBaseReelMap.h"
#include "Game\GkGame.h"
#include "Game\GkGameEntity.h"
#include "Game\GkGamePage.h"
#include "Game\GkGameReelModel.h"
#include "Game\GkGameReelsCombinationGenerator.h"
#include "Game\GkGameTimer.h"
#include "Game\GkGameWinningPotentialsAnalyzer.h"
#include "Game\GkGameWinningsAnalyzer.h"
#include "Game\GkGameWinningsModel.h"
#include "Game\Entities\GkGameAnimation.h"
#include "Game\Entities\GkGameButton.h"
#include "Game\Entities\GkGameReels.h"
#include "Game\Entities\GkGameStreamingAnimation.h"
#include "Game\Entities\GkGameText.h"
#include "Game\Entities\GkGameWinningCounter.h"
#include "Game\Entities\Bindings\GkGameAnimationsSoundBinding.h"
#include "Game\Entities\Bindings\GkGameButtonsBinding.h"
#include "Game\Entities\Bindings\GkGameButtonsSoundBinding.h"
#include "Game\Entities\Bindings\GkGameTextsDateTimeBinding.h"
#include "Game\Entities\Bindings\GkGameTextsFormatBinding.h"
#include "Game\Entities\Bindings\GkGameTextsFormatIntBinding.h"
#include "Game\Entities\Bindings\GkGameTextsIntBinding.h"
#include "Game\Entities\Buttons\GkGameAnimationButton.h"
#include "Game\Entities\Buttons\GkGameCheckButton.h"
#include "Game\Entities\Buttons\GkGameClickButton.h"
#include "Game\ReelModels\GkGameReelRandomModel.h"
#include "Game\ReelModels\GkGameReelStripModel.h"
#include "Graphics\GkAnimatedFont.h"
#include "Graphics\GkAnimatedTexture.h"
#include "Graphics\GkGraphicsDevice.h"
#include "Graphics\GkImage.h"
#include "Graphics\GkTexture.h"
#include "OSSpecific\GkFileSystem.h"
#include "OSSpecific\GkOpenGLWindowsForm.h"
#include "OSSpecific\GkOSUtils.h"
#include "OSSpecific\GkWindowsForm.h"
#include "OSSpecific\GkWindowsMutex.h"
#include "OSSpecific\GkWindowsThread.h"
#include "Sound\GkSoundDevice.h"
#include "Sound\GkSoundSource.h"
#include "Utils\GkList.h"
#include "Utils\GkLogFile.h"
#include "Utils\GkMaths.h"
#include "Utils\GkStrings.h"
@@ -0,0 +1,65 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameAnimationsSoundBinding.h"
GkGameAnimationsSoundBinding::GkGameAnimationsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, bool looping, int numAnimations, ...)
: GkGameEntity()
{
this->soundSource = soundSource;
this->soundDevice = soundDevice;
this->looping = looping;
this->numAnimations = numAnimations;
GkGameAnimation **parameters = (GkGameAnimation **)((int)&numAnimations + 4);
this->animations = new GkGameAnimationsSoundBindingAnimation[numAnimations];
for (int i = 0; i < numAnimations; i++)
{
this->animations[i].animation = parameters[i];
this->animations[i].played = false;
}
}
GkGameAnimationsSoundBinding::~GkGameAnimationsSoundBinding(void)
{
delete[] this->animations;
}
void GkGameAnimationsSoundBinding::Process(GkGame *game)
{
for (int i = 0; i < this->numAnimations; i++)
{
if (this->animations[i].animation->visible && this->animations[i].animation->active)
{
if (!this->animations[i].played)
{
if (this->looping)
this->soundDevice->PlaySourceLooping(this->soundSource);
else
this->soundDevice->PlaySource(this->soundSource);
this->animations[i].played = true;
}
}
else
{
if (this->looping)
{
this->soundDevice->PauseSource(this->soundSource);
}
this->animations[i].played = false;
}
}
}
@@ -0,0 +1,31 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\GkGameAnimation.h"
#include "..\..\..\Sound\GkSoundDevice.h"
struct GkGameAnimationsSoundBindingAnimation
{
GkGameAnimation *animation;
bool played;
};
class GKDLLCLASS GkGameAnimationsSoundBinding :
public GkGameEntity
{
public:
GkSoundDevice *soundDevice;
GkSoundSource *soundSource;
int numAnimations;
GkGameAnimationsSoundBindingAnimation *animations;
bool looping;
GkGameAnimationsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, bool looping, int numAnimations, ...);
~GkGameAnimationsSoundBinding(void);
void Process(GkGame *game);
};
@@ -0,0 +1,115 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameButtonsBinding.h"
GkGameButtonsBinding::GkGameButtonsBinding(int numGameButtons, ...)
{
GkGameButton **parameters = (GkGameButton **)((int)&numGameButtons + 4);
this->numGameButtons = numGameButtons;
this->gameButtons = new GkGameButton*[numGameButtons];
for (int i = 0; i < numGameButtons; i++)
this->gameButtons[i] = parameters[i];
this->enabled = true;
this->pushedValue = false;
this->clickedValue = false;
}
GkGameButtonsBinding::~GkGameButtonsBinding(void)
{
delete this->gameButtons;
}
void GkGameButtonsBinding::SyncPush(int syncButtonIndex)
{
GkGameButton *syncButton = this->gameButtons[syncButtonIndex];
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
{
if (buttonIndex != syncButtonIndex)
{
GkGameButton *button = this->gameButtons[buttonIndex];
if (button->IsActive())
{
if (button->pushed != syncButton->pushed)
{
if (syncButton->pushed)
button->Down();
else
button->Up(true);
}
}
}
}
this->pushedValue = syncButton->pushed;
}
void GkGameButtonsBinding::SyncClick(int syncButtonIndex)
{
GkGameButton *syncButton = this->gameButtons[syncButtonIndex];
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
{
if (buttonIndex != syncButtonIndex)
{
GkGameButton *button = this->gameButtons[buttonIndex];
if (button->IsActive())
{
button->clicked = syncButton->clicked;
}
}
}
this->clickedValue = syncButton->clicked;
}
void GkGameButtonsBinding::Process(GkGame *game)
{
if (!enabled)
return;
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
{
GkGameButton *button = this->gameButtons[buttonIndex];
if (button->IsActive())
{
if (button->pushed != this->pushedValue)
{
this->SyncPush(buttonIndex);
break;
}
}
}
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
{
GkGameButton *button = this->gameButtons[buttonIndex];
if (button->IsActive())
{
if (button->clicked != this->clickedValue)
{
// SyncClick is required beside SyncPush, because mouse events execute separately from the Process sequence and MouseUp usually sets a button pushed to false, which actually prevents SyncPush to execute mouse up (for it checks if the button is pushed)
this->SyncClick(buttonIndex);
break;
}
}
}
}
@@ -0,0 +1,27 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\..\GkGameEntity.h"
#include "..\..\Entities\GkGameButton.h"
class GKDLLCLASS GkGameButtonsBinding :
public GkGameEntity
{
public:
int numGameButtons;
GkGameButton **gameButtons;
bool enabled;
bool pushedValue, clickedValue;
GkGameButtonsBinding(int numGameButtons, ...);
~GkGameButtonsBinding(void);
void SyncPush(int syncButtonIndex);
void SyncClick(int syncButtonIndex);
void Process(GkGame *game);
};
@@ -0,0 +1,56 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameButtonsSoundBinding.h"
GkGameButtonsSoundBinding::GkGameButtonsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, int numButtons, ...)
: GkGameEntity()
{
this->soundSource = soundSource;
this->soundDevice = soundDevice;
this->numButtons = numButtons;
GkGameButton **parameters = (GkGameButton **)((int)&numButtons + 4);
this->buttons = new GameButtonsSoundBindingButton[numButtons];
for (int i = 0; i < numButtons; i++)
{
this->buttons[i].button = parameters[i];
this->buttons[i].played = false;
}
}
GkGameButtonsSoundBinding::~GkGameButtonsSoundBinding(void)
{
delete[] this->buttons;
}
void GkGameButtonsSoundBinding::Process(GkGame *game)
{
for (int i = 0; i < this->numButtons; i++)
{
if (this->buttons[i].button->pushed)
{
if (!this->buttons[i].played)
{
this->soundDevice->PlaySource(this->soundSource);
this->buttons[i].played = true;
}
}
else
{
this->buttons[i].played = false;
}
}
}
@@ -0,0 +1,29 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\GkGameButton.h"
#include "..\..\..\Sound\GkSoundDevice.h"
struct GameButtonsSoundBindingButton
{
GkGameButton *button;
bool played;
};
class GKDLLCLASS GkGameButtonsSoundBinding :
public GkGameEntity
{
public:
GkSoundDevice *soundDevice;
GkSoundSource *soundSource;
int numButtons;
GameButtonsSoundBindingButton *buttons;
GkGameButtonsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, int numButtons, ...);
~GkGameButtonsSoundBinding(void);
void Process(GkGame *game);
};
@@ -0,0 +1,42 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameTextsDateTimeBinding.h"
#include "..\..\..\Utils\GkStrings.h"
GkGameTextsDateTimeBinding::GkGameTextsDateTimeBinding(DateTime* valueAddress, const wchar_t *formatString, int numGameTexts, ...)
: GkGameEntity()
{
this->valueAddress = valueAddress;
this->formatString = GkStrings::Copy(formatString);
this->numGameTexts = numGameTexts;
GkGameText **parameters = (GkGameText **)((int)&numGameTexts + 4);
this->gameTexts = new GkGameText*[this->numGameTexts];
for (int i = 0; i < this->numGameTexts; i++)
this->gameTexts[i] = parameters[i];
}
GkGameTextsDateTimeBinding::~GkGameTextsDateTimeBinding(void)
{
delete[] this->formatString;
delete[] this->gameTexts;
}
void GkGameTextsDateTimeBinding::Process(GkGame *game)
{
for (int i = 0; i < this->numGameTexts; i++)
this->gameTexts[i]->SetText(GkStrings::Format(this->formatString, GkStrings::IntToString(this->valueAddress->day, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->month, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->year, 10, 4).c_str(), GkStrings::IntToString(this->valueAddress->hour, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->minute, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->second, 10, 2).c_str()).c_str());
}
@@ -0,0 +1,27 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\..\GkGameEntity.h"
#include "..\GkGameText.h"
#include "..\..\..\OSSpecific\GkOSUtils.h"
class GKDLLCLASS GkGameTextsDateTimeBinding :
public GkGameEntity
{
public:
DateTime * valueAddress;
int numGameTexts;
GkGameText **gameTexts;
wchar_t *formatString;
GkGameTextsDateTimeBinding(DateTime* valueAddress, const wchar_t *formatString, int numGameTexts, ...);
~GkGameTextsDateTimeBinding(void);
void Process(GkGame *game);
};
@@ -0,0 +1,23 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameTextsFormatBinding.h"
GkGameTextsFormatBinding::GkGameTextsFormatBinding(void)
{
}
GkGameTextsFormatBinding::~GkGameTextsFormatBinding(void)
{
}
@@ -0,0 +1,14 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\..\GkGameEntity.h"
class GKDLLCLASS GkGameTextsFormatBinding :
public GkGameEntity
{
public:
GkGameTextsFormatBinding(void);
~GkGameTextsFormatBinding(void);
};
@@ -0,0 +1,59 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameTextsFormatIntBinding.h"
#include "..\..\..\Utils\GkStrings.h"
GkGameTextsFormatIntBinding::GkGameTextsFormatIntBinding(const wchar_t *format, int numValues, int numGameTexts, ...)
{
this->numValues = numValues;
this->numGameTexts = numGameTexts;
this->format = GkStrings::Copy(format);
int **valueAddressParams = (int**)((int)&numGameTexts + 4);
this->valueAddresses = new int*[this->numValues];
this->values = new wchar_t*[this->numValues];
for (int i = 0; i < this->numValues; i++)
this->valueAddresses[i] = valueAddressParams[i];
GkGameText **gameTextParams = (GkGameText **)((int)&valueAddressParams[this->numValues - 1] + 4);
this->gameTexts = new GkGameText*[this->numGameTexts];
for (int i = 0; i < this->numGameTexts; i++)
this->gameTexts[i] = gameTextParams[i];
}
GkGameTextsFormatIntBinding::~GkGameTextsFormatIntBinding(void)
{
delete[] this->valueAddresses;
delete[] this->values;
delete[] this->gameTexts;
delete[] this->format;
}
void GkGameTextsFormatIntBinding::Process(GkGame *game)
{
for (int i = 0; i < this->numValues; i++)
this->values[i] = GkStrings::Copy(GkStrings::IntToString(*this->valueAddresses[i]).c_str());
for (int gameTextIndex = 0; gameTextIndex < this->numGameTexts; gameTextIndex++)
{
this->gameTexts[gameTextIndex]->SetText(GkStrings::FormatArray(this->format, this->values).c_str());
}
for (int i = 0; i < this->numValues; i++)
delete[] this->values[i];
}
@@ -0,0 +1,28 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\..\GkGameEntity.h"
#include "..\GkGameText.h"
class GKDLLCLASS GkGameTextsFormatIntBinding :
public GkGameEntity
{
public:
int numValues;
int **valueAddresses;
wchar_t **values;
int numGameTexts;
GkGameText **gameTexts;
wchar_t *format;
GkGameTextsFormatIntBinding(const wchar_t *format, int numValues, int numGameTexts, ...);
~GkGameTextsFormatIntBinding(void);
void Process(GkGame *game);
};
@@ -0,0 +1,40 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameTextsIntBinding.h"
#include "..\..\..\Utils\GkStrings.h"
GkGameTextsIntBinding::GkGameTextsIntBinding(int* valueAddress, int numGameTexts, ...)
: GkGameEntity()
{
this->valueAddress = valueAddress;
this->numGameTexts = numGameTexts;
GkGameText **parameters = (GkGameText **)((int)&numGameTexts + 4);
this->gameTexts = new GkGameText*[this->numGameTexts];
for (int i = 0; i < this->numGameTexts; i++)
this->gameTexts[i] = parameters[i];
}
GkGameTextsIntBinding::~GkGameTextsIntBinding(void)
{
delete[] this->gameTexts;
}
void GkGameTextsIntBinding::Process(GkGame *game)
{
for (int i = 0; i < this->numGameTexts; i++)
this->gameTexts[i]->SetText(GkStrings::IntToString(*this->valueAddress).c_str());
}
@@ -0,0 +1,23 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\..\GkGameEntity.h"
#include "..\GkGameText.h"
class GKDLLCLASS GkGameTextsIntBinding :
public GkGameEntity
{
public:
int * valueAddress;
int numGameTexts;
GkGameText **gameTexts;
GkGameTextsIntBinding(int* valueAddress, int numGameTexts, ...);
~GkGameTextsIntBinding(void);
void Process(GkGame *game);
};
@@ -0,0 +1,95 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameAnimationButton.h"
//#include "..\..\Utils\GkMaths.h"
GkGameAnimationButton::GkGameAnimationButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int height)
: GkGameButton(defaultFace, selectedFace, disabledFace, autoEnable, x, y, width, height)
{
GkGameAnimation *face = dynamic_cast<GkGameAnimation*>(this->defaultFace);
if (face != 0)
face->EndAnimation();
face = dynamic_cast<GkGameAnimation*>(this->selectedFace);
if (face != 0)
face->EndAnimation();
face = dynamic_cast<GkGameAnimation*>(this->disabledFace);
if (face != 0)
face->EndAnimation();
this->lastFace = this->GetCurrentFace();
}
GkGameAnimationButton::~GkGameAnimationButton(void)
{
}
void GkGameAnimationButton::Down()
{
GkGameButton::Down();
//GkGameAnimation *currentFace = dynamic_cast<GkGameAnimation*>(this->GetCurrentFace());
//if ((currentFace != 0) && (!currentFace->active))
//{
// currentFace->ResetAnimation();
//}
}
GkGameEntity* GkGameAnimationButton::GetCurrentFace()
{
GkGameAnimation *face = this->GetAnimatingFace();
if (face != 0)
return face;
return GkGameButton::GetCurrentFace();
}
GkGameAnimation* GkGameAnimationButton::GetAnimatingFace()
{
GkGameAnimation *face = dynamic_cast<GkGameAnimation*>(this->defaultFace);
if ((face != 0) && (face->active) && (!face->loop))
return face;
face = dynamic_cast<GkGameAnimation*>(this->selectedFace);
if ((face != 0) && (face->active) && (!face->loop))
return face;
face = dynamic_cast<GkGameAnimation*>(this->disabledFace);
if ((face != 0) && (face->active) && (!face->loop))
return face;
return 0;
}
void GkGameAnimationButton::Process(GkGame *game)
{
GkGameEntity *currentFace = this->GetCurrentFace();
if (currentFace != this->lastFace)
{
GkGameAnimation *lastAnimation = dynamic_cast<GkGameAnimation*>(this->lastFace);
if (lastAnimation != 0)
lastAnimation->EndAnimation();
GkGameAnimation *currentAnimation = dynamic_cast<GkGameAnimation*>(currentFace);
if (currentAnimation != 0)
currentAnimation->ResetAnimation();
this->lastFace = currentFace;
}
GkGameButton::Process(game);
}
@@ -0,0 +1,23 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "..\GkGameButton.h"
#include "..\GkGameAnimation.h"
class GKDLLCLASS GkGameAnimationButton :
public GkGameButton
{
public:
GkGameAnimationButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int heght = 0);
~GkGameAnimationButton(void);
GkGameAnimation* GetAnimatingFace();
GkGameEntity *lastFace;
virtual void Down();
virtual GkGameEntity* GetCurrentFace();
void Process(GkGame *game);
};
@@ -0,0 +1,52 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameCheckButton.h"
GkGameCheckButton::GkGameCheckButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int heght)
: GkGameAnimationButton(defaultFace, selectedFace, disabledFace, autoEnable, x, y, width, heght)
{
this->checked = false;
}
void GkGameCheckButton::Down()
{
GkGameAnimationButton::Down();
if (!this->IsActive())
return;
this->checked = !this->checked;
}
GkGameEntity* GkGameCheckButton::GetCurrentFace()
{
GkGameAnimation *face = this->GetAnimatingFace();
if (face != 0)
return face;
//if (this->enabled)
//{
if (this->checked)
{
return this->selectedFace != 0 ? this->selectedFace : this->defaultFace;
}
else
{
return this->defaultFace;
}
//}
//else
//{
// return this->disabledFace != 0 ? this->disabledFace : this->defaultFace;
//}
}
@@ -0,0 +1,20 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "GkGameAnimationButton.h"
class GKDLLCLASS GkGameCheckButton :
public GkGameAnimationButton
{
public:
bool checked;
GkGameCheckButton::GkGameCheckButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int heght = 0);
void GkGameCheckButton::Down();
GkGameEntity* GkGameCheckButton::GetCurrentFace();
void GkGameCheckButton::SynchWith(GkGameCheckButton *button);
};
@@ -0,0 +1,22 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameClickButton.h"
GkGameClickButton::GkGameClickButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int height)
: GkGameAnimationButton(defaultFace, selectedFace, disabledFace, autoEnable, x, y, width, height)
{
}
GkGameClickButton::~GkGameClickButton()
{
}
@@ -0,0 +1,15 @@
#pragma once
#include "..\..\..\GkDefinitions.h"
#include "GkGameAnimationButton.h"
class GKDLLCLASS GkGameClickButton :
public GkGameAnimationButton
{
public:
GkGameClickButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int height = 0);
~GkGameClickButton();
};
@@ -0,0 +1,125 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameAnimation.h"
#include "..\..\Graphics\GkImage.h"
#include "..\GkGame.h"
GkGameAnimation::GkGameAnimation(GkAnimatedTexture *animatedTexture, int x, int y, bool active, bool loop, bool visible, bool flipX, bool flipY, float framesPerSecond, int width, int height)
{
this->SetAnimatedTexture(animatedTexture, framesPerSecond);
this->x = x;
this->y = y;
this->width = width;
this->height = height;
this->framesPerSecond = framesPerSecond != 0.0f ? framesPerSecond : animatedTexture != 0 ? animatedTexture->framesPerSecond : 0.0f;
this->active = active && (animatedTexture != NULL);
this->loop = loop && (animatedTexture != NULL);
this->visible = visible && (animatedTexture != NULL);
this->flipX = flipX;
this->flipY = flipY;
}
GkGameAnimation::~GkGameAnimation(void)
{
}
void GkGameAnimation::SetAnimatedTexture(GkAnimatedTexture *animatedTexture, float framesPerSecond)
{
this->animatedTexture = animatedTexture;
this->framesPerSecond = framesPerSecond != 0.0f ? framesPerSecond : animatedTexture != 0 ? animatedTexture->framesPerSecond : 0.0f;
this->ResetAnimation(this->active);
}
void GkGameAnimation::Process(GkGame *game)
{
if (!(this->active && this->visible))
return;
if (this->flipX)
this->flipX = true;
this->currentFrame += this->framesPerSecond * game->timer->tickTime;
if (this->currentFrame > this->animatedTexture->numFrames)
{
if (this->loop)
{
int intFrame = (int)this->currentFrame;
float fracFrame = this->currentFrame - intFrame;
this->currentFrame = intFrame % this->animatedTexture->numFrames + fracFrame;
}
else
{
this->EndAnimation();
}
}
if (this->currentFrame < 0)
{
if (this->loop)
{
int intFrame = (int)this->currentFrame;
float fracFrame = this->currentFrame - intFrame;
this->currentFrame = (this->animatedTexture->numFrames - 1 - intFrame) % this->animatedTexture->numFrames + fracFrame;
}
else
{
this->EndAnimation();
}
}
}
void GkGameAnimation::Draw(GkGame *game)
{
if (!this->visible)
return;
GkTexture *frame = this->animatedTexture->frames[(int)this->currentFrame];
int width = this->width != 0 ? this->width : frame->width;
int height = this->height != 0 ? this->height : frame->height;
if (this->flipX)
if (this->flipY)
game->graphicsDevice->Draw(this->x + width, this->y + height, -width, -height, 0, 0, frame->width,frame->height, frame);
else
game->graphicsDevice->Draw(this->x + width, this->y, -width, height, 0, 0, frame->width, frame->height, frame);
else
if (this->flipY)
game->graphicsDevice->Draw(this->x, this->y + height, width, -height, 0, 0, frame->width, frame->height, frame);
else
game->graphicsDevice->Draw(this->x, this->y, width, height, 0, 0, frame->width, frame->height, frame);
}
bool GkGameAnimation::GetBoundaries(int *x1, int *y1, int *x2, int*y2)
{
*x1 = this->x;
*y1 = this->y;
*x2 = this->x + this->animatedTexture->frames[0]->width;
*y2 = this->y + this->animatedTexture->frames[0]->height;
return true;
}
void GkGameAnimation::ResetAnimation(bool start)
{
this->currentFrame = this->framesPerSecond < 0 ? this->animatedTexture != 0 ? (float)(this->animatedTexture->numFrames - 1) : 0.0f : 0.0f;
this->active = start;
}
void GkGameAnimation::EndAnimation()
{
this->currentFrame = this->framesPerSecond < 0 ? 0.0f : this->animatedTexture != 0 ? (float)(this->animatedTexture->numFrames - 1) : 0.0f;
this->active = false;
}
@@ -0,0 +1,31 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameEntity.h"
#include "..\..\Graphics\GkAnimatedTexture.h"
class GKDLLCLASS GkGameAnimation :
public GkGameEntity
{
public:
GkAnimatedTexture *animatedTexture;
int x, y, width, height;
bool visible, active, loop;
float framesPerSecond, currentFrame;
bool flipX, flipY;
GkGameAnimation::GkGameAnimation(GkAnimatedTexture *animatedTexture = 0, int x = 0, int y = 0, bool active = true, bool loop = true, bool visible = true, bool flipX = false, bool flipY = false, float framesPerSecond = 0.0f, int width = 0, int height = 0);
GkGameAnimation::~GkGameAnimation(void);
void GkGameAnimation::SetAnimatedTexture(GkAnimatedTexture *animatedTexture = 0, float framesPerSecond = 0.0f);
virtual void GkGameAnimation::Process(GkGame *game);
virtual void GkGameAnimation::Draw(GkGame *game);
bool GkGameAnimation::GetBoundaries(int *x1, int *y1, int *x2, int*y2);
void ResetAnimation(bool start = true);
void EndAnimation();
};
@@ -0,0 +1,176 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameButton.h"
GkGameButton::GkGameButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int height)
: GkGameEntity()
{
this->defaultFace = defaultFace;
this->selectedFace = selectedFace;
this->disabledFace = disabledFace;
this->x = x;
this->y = y;
if ((width == 0) && (height == 0))
{
if (defaultFace != 0)
{
int x1, y1, x2, y2;
if (defaultFace->GetBoundaries(&x1, &y1, &x2, &y2))
{
this->width = x2 - x1;
this->height = y2 - y1;
}
}
}
else
{
this->width = width;
this->height = height;
}
this->visible = true;
this->clicked = false;
this->down = false;
this->enabled = true;
this->autoEnable = autoEnable;
this->pushed = false;
}
GkGameButton::~GkGameButton(void)
{
if (this->defaultFace != 0)
delete this->defaultFace;
if (this->selectedFace != 0)
delete this->selectedFace;
if (this->disabledFace != 0)
delete this->disabledFace;
}
void GkGameButton::Down()
{
if (!this->IsActive())
return;
this->pushed = true;
this->down = true;
}
void GkGameButton::Up(bool click)
{
if (!this->IsActive())
return;
this->pushed = false;
this->clicked = click;
}
void GkGameButton::MouseDown(int x, int y)
{
if (this->IsMouseOver(x, y))
this->Down();
}
void GkGameButton::MouseUp(int x, int y)
{
this->Up(this->pushed && this->IsMouseOver(x, y));
}
bool GkGameButton::WasDown()
{
bool result = this->down;
this->clicked = false;
this->down = false;
this->read = true;
return result;
}
bool GkGameButton::IsClicked()
{
bool result = this->clicked;
this->clicked = false;
this->down = false;
this->read = true;
return result;
}
bool GkGameButton::IsActive()
{
return this->enabled && this->visible;
}
GkGameEntity* GkGameButton::GetCurrentFace()
{
if (this->enabled)
{
if (this->pushed)
return this->selectedFace != 0 ? this->selectedFace : this->defaultFace;
else
return this->defaultFace;
}
else
{
return this->disabledFace != 0 ? this->disabledFace : this->defaultFace;
}
}
bool GkGameButton::IsMouseOver(int x, int y)
{
if (this->defaultFace != 0)
{
// if a defaultFace is given, check a region, relative to it
int x1, y1, x2, y2;
if (defaultFace->GetBoundaries(&x1, &y1, &x2, &y2))
return (x > x1 + this->x) && (x < x1 + this->x + this->width) && (y > y1 + this->y) && (y < y1 + this->y + this->height);
}
else
{
// if defaultFace is not given, i.e. the button has no visible part, check its region without relation
return (x > this->x) && (x < this->x + this->width) && (y > this->y) && (y < this->y + this->height);
}
return false;
}
void GkGameButton::Process(GkGame *game)
{
if (this->autoEnable)
{
this->enabled = this->read;
this->read = false;
}
GkGameEntity *face = this->GetCurrentFace();
if (face != 0)
face->Process(game);
}
void GkGameButton::Draw(GkGame *game)
{
if (!visible)
return;
GkGameEntity *currentFace = this->GetCurrentFace();
if (currentFace != 0)
currentFace->Draw(game);
}
@@ -0,0 +1,33 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameEntity.h"
class GKDLLCLASS GkGameButton :
public GkGameEntity
{
public:
GkGameEntity *defaultFace, *selectedFace, *disabledFace;
int x, y, width, height;
bool visible, enabled, autoEnable, pushed;
bool clicked, down, read;
GkGameButton::GkGameButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int heght = 0);
virtual GkGameButton::~GkGameButton(void);
virtual void GkGameButton::Down();
virtual void GkGameButton::Up(bool click);
virtual void GkGameButton::MouseDown(int x, int y);
virtual void GkGameButton::MouseUp(int x, int y);
virtual GkGameEntity* GkGameButton::GetCurrentFace();
bool GkGameButton::WasDown();
bool GkGameButton::IsClicked();
bool GkGameButton::IsActive();
bool GkGameButton::IsMouseOver(int x, int y);
void GkGameButton::Process(GkGame *game);
void GkGameButton::Draw(GkGame *game);
};
@@ -0,0 +1,516 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#include <stdlib.h>
// Consider reels options:
// 1. GkGameReel is a class, a fully visual GkGameEntity
// GkGameReels is a collection of GkGameReel objects and manager for lines, winnings, sequential starting/stopping a reel, etc.
// Pros. GkGameReels is lighest, GkGameReel is a fully useful GkGameEntity
// Cons. Many settings, such as the "items" collection of AnimatedTextures, the "reelMap" and etc. must reoccur in all GkGameReel objects and the GkGameReels object, Changing a setting in GkGameReels will not "automatically" take effect until it is changed in all GkGameReel objects also
// 2. GkGameReel is a class, and is abstract in a sense that it provides only the mechanics of a reel via a spinning position
// GkGameReels is a collection of GkGameReel objects and aside from all the other things, also does the drawing of the reels
// Pros. GkGameReels is relatively light, GkGameReel functionality is separated in its own class
// Cons. GkGameReel is not useful unless used with GkGameReels. GkGameReels holds relatively little (maybe close to irrelevant for a whole class) logic and value
// 3. GkGameReels has each reel internal and has methods processing a reel. All the logic is inside that class.
// Pros. No GkGameReel class, no need for different objects to share or have the same information (for settings)
// Cons. GkGameReels is more heavily loaded with code logic. Does not quite correspond to the architecture model so far.
#include "GkGameReels.h"
#include "..\..\OSSpecific\GkOSUtils.h"
#include "..\..\Utils\GkMaths.h"
#include "..\GkGame.h"
#include "..\..\Utils\GkMaths.h"
GkGameReels::GkGameReels(int numReels, int numReelItems, int numSymbols, int width, int height)
: GkBaseReelMap(numReels, numReelItems)
{
this->width = width;
this->height = height;
this->numSymbols = numSymbols;
this->state = Idle;
this->stateOld = Idle;
this->stateChange = Undefined;
this->numReelAnimations = this->numReelItems + 2;
this->reels = new GkGameReelInfo[numReels];
for (int i = 0; i < numReels; i++)
{
this->reels[i].state = Idle;
this->reels[i].stateOld = Idle;
this->reels[i].stateChange = Undefined;
this->reels[i].position = 0.0f;
this->reels[i].animations = new GkGameAnimation*[this->numReelAnimations];
for (int itemIndex = 0; itemIndex < this->numReelAnimations; itemIndex++)
{
this->reels[i].animations[itemIndex] = new GkGameAnimation();
this->reels[i].animations[itemIndex]->visible = true;
this->reels[i].animations[itemIndex]->active = false;
this->reels[i].animations[itemIndex]->loop = false;
}
}
this->symbols = new GkAnimatedTexture*[numSymbols];
this->speed = 20.0f;
this->acceleration = 40.0f;
this->stoppingTime = 1.0f;
this->preStartOffset = 0.15f;
this->preStartSpeed = 2.0f;
this->postStopOffset = 0.15f;
this->postStopSpeed = 2.0f;
this->itemGenerator = 0;
}
GkGameReels::~GkGameReels(void)
{
for (int i = 0; i < numReels; i++)
{
for (int j = 0; j < this->numReelAnimations; j++)
{
delete[] this->reels[i].animations[j];
}
delete[] this->reels[i].animations;
}
delete[] this->symbols;
delete[] this->reels;
}
void GkGameReels::SetItemGenerator(GkGameReelsCombinationGenerator *itemGenerator)
{
this->itemGenerator = itemGenerator;
}
GkAnimatedTexture *GkGameReels::Reel_GetNewSymbol(int reelIndex)
{
if (this->itemGenerator != 0)
{
return this->symbols[this->itemGenerator->reels[reelIndex].model->GetSymbol()];
}
else
return this->symbols[GkMaths::Random(this->numSymbols)];
}
void GkGameReels::Reel_ProcessPosition(int reelIndex, GkGame *game)
{
GkGameReelInfo *reel = &this->reels[reelIndex];
// Handle position ranging and shifting of symbols when position hops over 1.0
reel->position += game->timer->tickTime * reel->speed;
if (reel->position >= 1.0f)
{
int numShifts = (int)reel->position;
reel->position -= numShifts;
int reelShifts = GkMaths::Min(numShifts, this->numReelItems - reel->reelMapSetIndex + 1);
for (int shiftIndex = 0; shiftIndex < reelShifts; shiftIndex++)
{
GkGameAnimation *rotAnimation = reel->animations[this->numReelAnimations - 1];
for (int i = 0; i < this->numReelAnimations; i++)
{
GkGameAnimation *t = reel->animations[i];
reel->animations[i] = rotAnimation;
rotAnimation = t;
}
if (reel->state == Stopping)
{
if (reel->reelMapSetIndex < this->numReelItems)
reel->animations[0]->SetAnimatedTexture(this->symbols[this->GetSymbol(reelIndex, this->numReelItems - 1 - reel->reelMapSetIndex)]);
else
{
reel->animations[0]->SetAnimatedTexture(this->Reel_GetNewSymbol(reelIndex));
}
reel->reelMapSetIndex++;
}
else
{
reel->animations[0]->SetAnimatedTexture(this->Reel_GetNewSymbol(reelIndex));
}
}
}
for (int i = 0; i < this->numReelAnimations; i++)
{
reel->animations[i]->Process(game);
}
}
void GkGameReels::Reel_ProcessState(int reelIndex, GkGameTimer *timer)
{
GkGameReelInfo *reel = &this->reels[reelIndex];
switch (reel->state)
{
case Idle:
{
reel->speed = 0.0f;
reel->position = 0.0f;
// User interaction expected
break;
}
case PreStarting:
{
reel->speed = 0.0f;
reel->position -= timer->tickTime * this->preStartSpeed;
if (reel->position < -this->preStartOffset)
{
reel->position = -this->preStartOffset;
reel->state = Starting;
}
break;
}
case Starting:
{
reel->speed += this->acceleration * timer->tickTime;
if (reel->speed >= this->speed)
{
reel->speed = this->speed;
reel->state = Spinning;
}
break;
}
case Spinning:
{
// User interaction expected
break;
}
case Stopping:
{
if ((reel->reelMapSetIndex > this->numReelItems) && (reel->position >= this->postStopOffset))
{
reel->position = this->postStopOffset;
reel->state = PostStopping;
}
break;
}
case PostStopping:
{
reel->speed = 0.0f;
reel->position -= timer->tickTime * this->postStopSpeed;
if (reel->position < 0.0f)
{
reel->position = 0.0f;
reel->state = Idle;
}
break;
}
}
reel->stateChange = reel->state != reel->stateOld ? reel->state : Undefined;
reel->stateOld = reel->state;
}
bool GkGameReels::Reel_Start(int reelIndex)
{
GkGameReelInfo *reel = &this->reels[reelIndex];
if (reel->state == Idle)
{
reel->state = PreStarting;
reel->reelMapSetIndex = 0;
return true;
}
return false;
}
bool GkGameReels::Reel_Stop(int reelIndex)
{
GkGameReelInfo *reel = &this->reels[reelIndex];
if (reel->state == Spinning)
{
reel->state = Stopping;
reel->reelMapSetIndex = 0;
return true;
}
return false;
}
// Gives a summary state. If all reels have the same state, returns that state, otherwise returns Undefined. If a reel has a Blocked state, it's ignored, unless all reels have Blocked state, in which case Blocked is returned.
GameReelState GkGameReels::GetGeneralState()
{
GameReelState result = Undefined;
int reelIndex = 0;
while (reelIndex < this->numReels)
{
GameReelState reelState = this->reels[reelIndex].state;
if (result == Undefined)
{
result = reelState;
}
else if (result == Blocked)
{
if (reelState != Blocked)
{
result = reelState;
}
}
else
{
if ((result != reelState) && (reelState != Blocked))
{
return Undefined;
}
}
reelIndex++;
}
return result;
}
void GkGameReels::ProcessState(GkGameTimer *timer)
{
GameReelState generalState = this->GetGeneralState();
// Ensure each state is followed by the next for at least one frame
switch (this->state)
{
case Idle:
{
if ((this->state != generalState) && (generalState != Undefined))
this->state = PreStarting;
break;
}
case PreStarting:
{
if ((this->state != generalState) && (generalState != Undefined))
this->state = Starting;
break;
}
case Starting:
{
if ((this->state != generalState) && (generalState != Undefined))
this->state = Spinning;
break;
}
case Spinning:
{
if ((this->state != generalState) && (generalState != Undefined))
this->state = Stopping;
break;
}
case Stopping:
{
float fullStopTime = GkMaths::Max(this->stoppingTime - this->numReelItems / this->speed - this->postStopOffset / this->postStopSpeed, 0.0f);
float timeSinceStopInitiated = GkGameTimer::GetSampleTime(this->stopInitiatedTime);
int reelsStopped = fullStopTime != 0 ? GkMaths::Min((int)(1 + (this->numReels - 1) * timeSinceStopInitiated / fullStopTime), this->numReels) : this->numReels;
int stopCount = 0;
for (int i = 0; i < this->numReels; i++)
{
this->Reel_Stop(i);
if ((this->reels[i].state != Blocked) && (this->reels[i].state != Spinning))
stopCount++;
if (stopCount >= reelsStopped)
break;
}
if (reelsStopped == this->numReels)
this->state = PostStopping;
break;
}
case PostStopping:
{
if ((generalState == Idle) | (generalState == Blocked))
this->state = Idle;
//if ((this->state != generalState) && (generalState != Undefined))
// this->state = Idle;
break;
}
default:
{
this->state = generalState;
}
}
this->stateChange = this->state != this->stateOld ? this->state : Undefined;
this->stateOld = this->state;
}
void GkGameReels::Process(GkGame *game)
{
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
this->Reel_ProcessPosition(reelIndex, game);
this->Reel_ProcessState(reelIndex, game->timer);
}
this->ProcessState(game->timer);
}
void GkGameReels::Draw(GkGame *game)
{
int itemWidth = this->symbols[0]->frames[0]->width;
int itemHeight = this->symbols[0]->frames[0]->height;
float horizontalDistance = this->numReels == 1 ? itemWidth : itemWidth + (this->width - this->numReels * itemWidth) / ((float)this->numReels - 1.0f);
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
int x = (int)(this->x + reelIndex * horizontalDistance);
for (int itemIndex = 0; itemIndex < this->numReelAnimations; itemIndex++)
{
int y = (int)(this->y + (this->height - this->numReelAnimations * itemHeight) / 2 + this->reels[reelIndex].position * itemHeight + itemIndex * itemHeight);
GkGameAnimation *reelItemAnimation = this->reels[reelIndex].animations[itemIndex];
game->graphicsDevice->DrawClipped(x, y, this->x, this->y, this->width, this->height, reelItemAnimation->animatedTexture->frames[(int)reelItemAnimation->currentFrame]);
}
}
}
void GkGameReels::ApplyReelMap(const int *fullItemMap)
{
if (fullItemMap != 0)
{
this->SetItems(fullItemMap);
}
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
this->reels[reelIndex].animations[0]->SetAnimatedTexture(this->symbols[GkMaths::Random(this->numSymbols)]);
this->reels[reelIndex].animations[this->numReelAnimations - 1]->SetAnimatedTexture(this->symbols[GkMaths::Random(this->numSymbols)]);
}
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
{
this->reels[reelIndex].animations[itemIndex + 1]->SetAnimatedTexture(this->symbols[this->GetSymbol(reelIndex, itemIndex)]);
}
}
}
bool GkGameReels::Start()
{
this->reelingTime = GkGameTimer::GetSample();
bool result = true;
if (this->state == Idle)
{
for (int i = 0; i < this->numReels; i++)
result &= this->Reel_Start(i);
return result;
}
return false;
}
bool GkGameReels::Stop()
{
if (this->state = Spinning)
{
this->stopInitiatedTime = GkGameTimer::GetSample();
this->state = Stopping;
return true;
}
return false;
bool result = true;
if (this->state == Spinning)
{
for (int i = 0; i < this->numReels; i++)
result &= this->Reel_Stop(i);
return result;
}
return false;
}
bool GkGameReels::ItemsAnimationsPlaying()
{
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
{
if (this->reels[reelIndex].animations[itemIndex + 1]->active)
return true;
}
}
return false;
}
void GkGameReels::StopItemsAnimations()
{
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
{
this->reels[reelIndex].animations[itemIndex + 1]->active = false;
this->reels[reelIndex].animations[itemIndex + 1]->currentFrame = 0.0f;
}
}
}
float GkGameReels::GetReelingTime()
{
return GkGameTimer::GetSampleTime(this->reelingTime);
}
float GkGameReels::GetIdleTime()
{
return GkGameTimer::GetSampleTime(this->idleTime);
}
@@ -0,0 +1,86 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameEntity.h"
#include "GkGameAnimation.h"
#include "..\..\Base\GkBaseReelMap.h"
#include "..\GkGameReelsCombinationGenerator.h"
class GKDLLCLASS GkGameTimer;
enum GameReelState
{
Idle = 0,
PreStarting = 1,
Starting = 2,
Spinning = 3,
Stopping = 4,
PostStopping = 5,
Blocked = 6,
Undefined = 7
};
struct GkGameReelInfo
{
GameReelState state, stateOld, stateChange;
float position, speed;
int reelMapSetIndex;
GkGameAnimation **animations;
};
class GKDLLCLASS GkGameReels :
public GkGameEntity,
public GkBaseReelMap
{
private:
GameReelState stateOld;
long long stopInitiatedTime, reelingTime, idleTime;
// GkGameReel related methods
GkAnimatedTexture *GkGameReels::Reel_GetNewSymbol(int reelIndex);
void GkGameReels::Reel_ProcessState(int reelIndex, GkGameTimer *gameTimer);
void GkGameReels::Reel_ProcessPosition(int reelIndex, GkGame *game);
bool GkGameReels::Reel_Start(int reelIndex);
bool GkGameReels::Reel_Stop(int reelIndex);
void GkGameReels::ProcessState(GkGameTimer *gameTimer);
public:
GkGameReelInfo *reels;
GameReelState state, // GkGameReels acquires certain state when all of its reels reach that state
stateChange; // Gives the state that reels have just obtained in the last frame
int numSymbols, numReelAnimations;
int x, y, width, height;
float speed, // items per second
acceleration, // items per second^2
stoppingTime, // seconds
preStartOffset, postStopOffset, // number of items
preStartSpeed, postStopSpeed; // items per second
GkAnimatedTexture **symbols;
GkGameReelsCombinationGenerator *itemGenerator;
GkGameReels::GkGameReels(int numReels, int numReelItems, int numSymbols, int width, int height);
GkGameReels::~GkGameReels(void);
void GkGameReels::SetItemGenerator(GkGameReelsCombinationGenerator *itemGenerator);
void GkGameReels::Process(GkGame *game);
void GkGameReels::Draw(GkGame *game);
void GkGameReels::ApplyReelMap(const int *fullItemMap = 0);
bool GkGameReels::Start();
bool GkGameReels::Stop();
bool GkGameReels::ItemsAnimationsPlaying();
void GkGameReels::StopItemsAnimations();
float GkGameReels::GetReelingTime();
float GkGameReels::GetIdleTime();
GameReelState GkGameReels::GetGeneralState();
};
@@ -0,0 +1,145 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameStreamingAnimation.h"
#include "..\..\Utils\GkStrings.h"
#include "..\..\OSSpecific\GkFileSystem.h"
GkGameStreamingAnimation::GkGameStreamingAnimation(const wchar_t *fileName, const wchar_t *loadExpression, int x, int y, bool freeAtEnd, float framesPerSecond, int numFrames)
{
this->x = x;
this->y = y;
this->visible = false;
this->active = true;
this->loop = false;
this->freeAtEnd = freeAtEnd;
this->currentFrame = framesPerSecond >= 0.0f ? 0.0f : (float)(numFrames - 1);
this->framesPerSecond = framesPerSecond;
this->numFrames = numFrames;
this->loadExpression = GkStrings::Copy(loadExpression);
this->fileName = GkStrings::Copy(fileName);
this->texture = 0;
}
GkGameStreamingAnimation::~GkGameStreamingAnimation(void)
{
this->Free();
GkStrings::Dispose(&this->fileName);
GkStrings::Dispose(&this->loadExpression);
}
void GkGameStreamingAnimation::SetSource(const wchar_t *fileName, const wchar_t *loadExpression, float framesPerSecond, int numFrames)
{
this->Free();
this->active = true;
this->loop = false;
this->currentFrame = framesPerSecond >= 0.0f ? 0.0f : (float)(numFrames - 1);
this->framesPerSecond = framesPerSecond;
this->numFrames = numFrames;
GkStrings::Dispose(&this->fileName);
GkStrings::Dispose(&this->loadExpression);
this->loadExpression = GkStrings::Copy(loadExpression);
this->fileName = GkStrings::Copy(fileName);
}
void GkGameStreamingAnimation::Free()
{
if (this->texture != 0)
{
delete this->texture;
this->texture = 0;
}
}
bool GkGameStreamingAnimation::Load(int index)
{
void *data;
unsigned int dataSize;
if (GkFileSystem::LoadFile(GkStrings::Format(this->loadExpression, GkStrings::IntToString(index, 10, 5).c_str()).c_str(), &data, &dataSize))
{
this->Free();
GkImage image;
image.LoadFromMemory(data, dataSize);
this->texture = new GkTexture();
this->texture->LoadFromImage(&image);
delete data;
return true;
}
return false;
}
void GkGameStreamingAnimation::Start()
{
this->currentFrame = framesPerSecond >= 0.0f ? 0.0f : (float)(numFrames - 1);
this->lastRenderedFrame = (int)this->currentFrame;
this->visible = this->Load(this->lastRenderedFrame);
this->active = this->visible;
}
void GkGameStreamingAnimation::Process(GkGame *game)
{
if (!(this->active && this->visible))
return;
this->currentFrame += this->framesPerSecond * game->timer->tickTime;
if ((this->lastRenderedFrame != (int)this->currentFrame) || (this->texture == 0))
{
bool terminate = false;
if (!this->Load((int)this->currentFrame))
{
if (this->loop)
{
this->currentFrame = this->framesPerSecond >= 0 ? 0.0f : (float)(this->numFrames - 1);
if (!this->Load((int)this->currentFrame))
{
terminate = true;
}
}
else
{
terminate = true;
}
}
if (terminate)
{
this->currentFrame = (float)(this->lastRenderedFrame);
this->active = false;
this->visible = (!this->freeAtEnd) && (this->texture != 0);
}
}
this->lastRenderedFrame = (int)this->currentFrame;
}
void GkGameStreamingAnimation::Draw(GkGame *game)
{
if (!this->visible)
{
this->Free();
return;
}
game->graphicsDevice->Draw(this->x, this->y, this->texture);
}
@@ -0,0 +1,32 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGame.h"
#include "..\Entities\GkGameAnimation.h"
#include "..\..\Graphics\GkTexture.h"
class GKDLLCLASS GkGameStreamingAnimation :
public GkGameAnimation
{
public:
GkTexture *texture;
wchar_t *fileName, *loadExpression;
bool freeAtEnd;
int lastRenderedFrame;
int numFrames; // required only if animation is backwards, i.e. if framesPerSecond is negative
// Because the animation is streaming and the number of frames is practically unknown, if it is played backwards, i.e. framesPerSecond is negative, then numFrames must be provided
GkGameStreamingAnimation::GkGameStreamingAnimation(const wchar_t *fileName, const wchar_t *loadExpression, int x = 0, int y = 0, bool freeAtEnd = true, float framesPerSecond = 25.0f, int numFrames = 0);
GkGameStreamingAnimation::~GkGameStreamingAnimation(void);
void GkGameStreamingAnimation::SetSource(const wchar_t *fileName, const wchar_t *loadExpression, float framesPerSecond = 25.0f, int numFrames = 0);
void GkGameStreamingAnimation::Free();
bool GkGameStreamingAnimation::Load(int index);
void GkGameStreamingAnimation::Start();
void GkGameStreamingAnimation::Process(GkGame *game);
void GkGameStreamingAnimation::Draw(GkGame *game);
};
@@ -0,0 +1,148 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameText.h"
#include "..\GkGame.h"
#include "..\..\Utils\GkStrings.h"
GkGameText::GkGameText(GkAnimatedFont *animatedFont, int x, int y, int characterSpacing, int textAlignment, int maxWidth, float framesPerSecond)
: GkGameEntity()
{
this->animatedFont = animatedFont;
this->x = x;
this->y = y;
this->characterSpacing = characterSpacing;
this->maxWidth = maxWidth;
this->textAlignment = textAlignment;
this->visible = animatedFont != NULL;
this->active = animatedFont != NULL;
this->loop = animatedFont != NULL;
this->framesPerSecond = framesPerSecond != 0.0f ? framesPerSecond : animatedFont != 0 ? animatedFont->framesPerSecond : 0.0f;
this->currentFrame = 0.0f;
this->text = 0;
this->textTextureIndices = 0;
this->textLength = 0;
}
GkGameText::~GkGameText(void)
{
if (this->text != 0)
delete[] this->text;
if (this->textTextureIndices != 0)
delete[] this->textTextureIndices;
}
bool GkGameText::SetText(const wchar_t *text)
{
if ((this->text != 0) && (GkStrings::Compare(this->text, text) == 0))
return false;
if (this->text != 0)
delete[] this->text;
if (this->textTextureIndices != 0)
delete[] this->textTextureIndices;
this->text = GkStrings::Copy(text);
this->textLength = GkStrings::GetLength(this->text);
this->textTextureIndices = new int[this->textLength];
this->textWidth = 0;
for (int i = 0; i < this->textLength; i++)
{
this->textTextureIndices[i] = GkStrings::SubChar(this->animatedFont->charMap, this->text[i]);
if (this->textTextureIndices[i] != -1)
{
this->textWidth += this->animatedFont->letterTextures[this->textTextureIndices[i]]->frames[0]->width + this->characterSpacing;
}
}
this->textWidth -= this->characterSpacing;
return true;
}
void GkGameText::Process(GkGame *game)
{
if (!(this->active && this->visible))
return;
this->currentFrame += this->framesPerSecond * game->timer->tickTime;
if (this->currentFrame > this->animatedFont->letterTextures[0]->numFrames)
{
if (this->loop)
{
int intFrame = (int)this->currentFrame;
float fracFrame = this->currentFrame - intFrame;
this->currentFrame = intFrame % this->animatedFont->letterTextures[0]->numFrames + fracFrame;
}
else
{
this->currentFrame = (float)(this->animatedFont->letterTextures[0]->numFrames - 1);
this->active = false;
}
}
}
void GkGameText::Draw(GkGame *game)
{
if (!this->visible)
return;
if ((this->maxWidth == 0) || (this->textWidth <= this->maxWidth))
{
int x = this->textAlignment == GkGameText::GameTextAlignment_Right ? this->x : this->textAlignment == GkGameText::GameTextAlignment_Center ? this->x - this->textWidth / 2 : this->x - this->textWidth;
for (int i = 0; i < this->textLength; i++)
{
int letterTextureIndex = this->textTextureIndices[i];
if (letterTextureIndex != -1)
{
GkTexture *letterTexture = this->animatedFont->letterTextures[letterTextureIndex]->frames[(int)this->currentFrame];
game->graphicsDevice->Draw(x, this->y, letterTexture);
x += letterTexture->width + this->characterSpacing;
}
}
}
else
{
float scalingFactor = (float)this->maxWidth / (float)this->textWidth;
float x = this->textAlignment == GkGameText::GameTextAlignment_Right ? this->x : this->textAlignment == GkGameText::GameTextAlignment_Center ? this->x - (float)(scalingFactor * (float)this->textWidth / 2.0f) : this->x - (float)(scalingFactor * (float)this->textWidth);
int y = this->y + (int)(((1.0f - scalingFactor) * (float)this->animatedFont->letterTextures[0]->frames[0]->height) / 2.0f);
for (int i = 0; i < this->textLength; i++)
{
int letterTextureIndex = this->textTextureIndices[i];
if (letterTextureIndex != -1)
{
GkTexture *letterTexture = this->animatedFont->letterTextures[letterTextureIndex]->frames[(int)this->currentFrame];
game->graphicsDevice->Draw((int)x, y, (int)(letterTexture->width * scalingFactor), (int)(letterTexture->height * scalingFactor), 0, 0, letterTexture->width, letterTexture->height, letterTexture);
x += scalingFactor * (letterTexture->width + this->characterSpacing);
}
}
}
}
@@ -0,0 +1,36 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameEntity.h"
#include "..\..\Graphics\GkAnimatedFont.h"
class GKDLLCLASS GkGameText :
public GkGameEntity
{
public:
static const int GameTextAlignment_Right = 0,
GameTextAlignment_Center = 1,
GameTextAlignment_Left = 2;
GkAnimatedFont *animatedFont;
wchar_t *text;
int textLength, textWidth;
int *textTextureIndices;
int x, y;
bool visible, active, loop;
float framesPerSecond, currentFrame;
int textAlignment;
int characterSpacing;
int maxWidth;
GkGameText::GkGameText(GkAnimatedFont *animatedFont, int x = 0, int y = 0, int characterSpacing = 0, int textAlignment = GameTextAlignment_Right, int maxWidth = 0, float framesPerSecond = 0.0f);
GkGameText::~GkGameText(void);
bool GkGameText::SetText(const wchar_t *text);
void GkGameText::Process(GkGame *game);
void GkGameText::Draw(GkGame *game);
};
@@ -0,0 +1,85 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameWinningCounter.h"
#include "..\GkGame.h"
GkGameWinningCounter::GkGameWinningCounter(int *actualValue, float minSpeed, float maxTime)
: GkGameEntity()
{
this->actualValue = actualValue;
this->minSpeed = minSpeed;
this->maxTime = maxTime;
this->SetValue((float)*this->actualValue, 0.0f);
}
GkGameWinningCounter::~GkGameWinningCounter(void)
{
}
void GkGameWinningCounter::SetValue(float value, float maxTime)
{
float delta = value - this->displayValue;
if (maxTime == -1.0f)
maxTime = this->maxTime;
if (maxTime == 0.0f)
{
this->displayValue = value;
}
else
{
float minSpeed = delta / maxTime;
this->speed = this->minSpeed > minSpeed ? this->minSpeed : minSpeed;
}
this->oldValue = value;
}
void GkGameWinningCounter::Reach(float maxTime)
{
this->SetValue((float)*this->actualValue, maxTime);
}
bool GkGameWinningCounter::IsCounting()
{
return this->intDisplayValue != *this->actualValue;
}
void GkGameWinningCounter::Process(GkGame *game)
{
float value = (float)*this->actualValue;
if (value != this->oldValue)
this->SetValue(value, this->maxTime);
this->displayValue += this->speed * game->timer->tickTime;
if (this->speed > 0.0f)
{
if (this->displayValue > value)
this->displayValue = value;
}
else
{
if (this->displayValue < value)
this->displayValue = value;
}
this->intDisplayValue = (int)this->displayValue;
GkGameEntity::Process(game);
}
@@ -0,0 +1,32 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameEntity.h"
class GKDLLCLASS GkGameWinningCounter :
public GkGameEntity
{
private:
float oldValue;
void SetValue(float value, float maxTime);
public:
int *actualValue;
float minSpeed, maxTime,
displayValue,
speed;
int intDisplayValue;
GkGameWinningCounter(int *actualValue, float minSpeed = 500.0f, float maxTime = 1.0f);
~GkGameWinningCounter(void);
void Reach(float maxTime = 0.0f);
bool IsCounting();
void Process(GkGame *game);
};
@@ -0,0 +1,304 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGame.h"
#include "..\OSSpecific\GkFileSystem.h"
#include "..\Utils\GkStrings.h"
ResourcePoolEntry::ResourcePoolEntry(GkBase *resource, const wchar_t *id)
{
this->resource = resource;
if (id == NULL)
{
this->id = NULL;
}
else
{
int l = wcslen(id);
this->id = new wchar_t[l + 1];
wcscpy_s(this->id, l + 1, id);
}
}
GkGame::GkGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice)
{
this->graphicsDevice = graphicsDevice;
this->soundDevice = soundDevice;
this->currentGamePage = 0;
this->timer = new GkGameTimer();
}
GkGame::~GkGame(void)
{
int numPages = this->gamePages.size();
for (int i = 0; i < numPages; i++)
{
delete this->gamePages[i];
}
int numResources = this->resourcePool.size();
for (int i = 0; i < numResources; i++)
{
delete this->resourcePool[i].resource;
if (this->resourcePool[i].id != NULL)
{
delete this->resourcePool[i].id;
this->resourcePool[i].id = NULL;
}
}
delete this->timer;
}
void GkGame::SetPage(GkGamePage *page)
{
if (this->currentGamePage != 0)
this->currentGamePage->OnHide(page);
if (page != 0)
page->OnShow(this->currentGamePage);
this->currentGamePage = page;
}
GkAnimatedTexture* GkGame::AddAnimatedTexture(GkAnimatedTexture *animatedTexture, const wchar_t* id)
{
this->resourcePool.push_back(ResourcePoolEntry(animatedTexture, id));
return animatedTexture;
}
void* GkGame::GetResource(const wchar_t* id)
{
int numResources = this->resourcePool.size();
for (int i = 0; i < numResources; i++)
{
if (wcscmp(this->resourcePool[i].id, id) == 0)
return this->resourcePool[i].resource;
}
return NULL;
}
bool GkGame::ReleaseResource(const wchar_t* id)
{
int numResources = this->resourcePool.size();
for (int i = 0; i < numResources; i++)
{
if (wcscmp(this->resourcePool[i].id, id) == 0)
{
delete this->resourcePool[i].resource;
if (this->resourcePool[i].id != NULL)
{
delete this->resourcePool[i].id;
this->resourcePool[i].id = NULL;
}
this->resourcePool[i] = this->resourcePool[numResources - 1];
this->resourcePool.pop_back();
return true;
}
}
return false;
}
GkAnimatedFont* GkGame::AcquireAnimatedFontFromMultipleFiles(const wchar_t* virtualFileName, const wchar_t *charMap, int numFrames)
{
GkAnimatedFont* result = (GkAnimatedFont*)this->GetResource(virtualFileName);
if (result != NULL)
return result;
result = new GkAnimatedFont(charMap, numFrames);
void *data;
unsigned int dataSize;
for (int i = 0; i < result->numLetters; i++)
{
if (GkFileSystem::LoadFile(GkStrings::Format(virtualFileName, GkStrings::IntToString(i, 10, 5).c_str()).c_str(), &data, &dataSize))
{
result->LoadAnimatedLetter(i, data, dataSize);
delete[] data;
}
}
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
return result;
}
GkAnimatedTexture* GkGame::AcquireAnimatedTexture(const wchar_t* virtualFileName, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
{
GkAnimatedTexture* result = (GkAnimatedTexture*)this->GetResource(virtualFileName);
if (result != NULL)
return result;
void *data;
unsigned int dataSize;
if (!GkFileSystem::LoadFile(virtualFileName, &data, &dataSize))
return NULL;
result = new GkAnimatedTexture(data, dataSize, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
delete data;
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
return result;
}
GkAnimatedTexture* GkGame::AcquireAnimatedTextureFromMultipleFiles(const wchar_t* virtualFileName, float framesPerSecond)
{
GkAnimatedTexture *result = (GkAnimatedTexture*)this->GetResource(virtualFileName);
if (result != NULL)
return result;
std::vector<GkTexture*> frames;
void *data;
unsigned int dataSize;
int index = 0;
while (GkFileSystem::LoadFile(GkStrings::Format(virtualFileName, GkStrings::IntToString(index, 10, 5).c_str()).c_str(), &data, &dataSize))
{
GkImage *frameImage = new GkImage();
frameImage->LoadFromMemory(data, dataSize);
GkTexture *frame = new GkTexture();
frame->LoadFromImage(frameImage);
delete frameImage;
frames.push_back(frame);
index++;
delete[] data;
}
int numFrames = frames.size();
if (numFrames == 0)
return NULL;
result = new GkAnimatedTexture();
result->framesPerSecond = framesPerSecond;
result->numFrames = numFrames;
result->frames = new GkTexture*[numFrames];
for (int i = 0; i < numFrames; i++)
{
result->frames[i] = frames[i];
}
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
return result;
}
GkSoundSource* GkGame::AcquireSoundSource(const wchar_t* virtualFileName)
{
GkSoundSource* result = (GkSoundSource*)this->GetResource(virtualFileName);
if (result != NULL)
return result;
void *data;
unsigned int dataSize;
GkFileSystem::LoadFile(virtualFileName, &data, &dataSize);
result = new GkSoundSource();
result->LoadFromMemory(data);
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
delete data;
return result;
}
GkGamePage* GkGame::AddGamePage(GkGamePage *gamePage)
{
this->gamePages.push_back(gamePage);
if (this->currentGamePage == NULL)
this->SetPage(gamePage);
return gamePage;
}
void GkGame::RemoveGamePage(GkGamePage *gamePage)
{
int index = -1;
for (int i = 0; i < (int)this->gamePages.size(); i++)
if (this->gamePages[i] == gamePage)
{
index = i;
break;
}
if (index == -1)
return;
for (int i = index; i < (int)this->gamePages.size() - 1; i++)
this->gamePages[i] = this->gamePages[i + 1];
this->gamePages.pop_back();
}
void GkGame::MouseDown(int x, int y)
{
int numEntities = this->currentGamePage->entities.size();
for (int i = numEntities - 1; i >= 0; i--)
{
GkGameEntity *entity = this->currentGamePage->entities[i];
if (entity->IsMouseOver(x, y))
{
entity->MouseDown(x, y);
break;
}
}
}
void GkGame::MouseUp(int x, int y)
{
int numEntities = this->currentGamePage->entities.size();
for (int i = numEntities - 1; i >= 0; i--)
{
GkGameEntity *entity = this->currentGamePage->entities[i];
entity->MouseUp(x, y);
}
}
void GkGame::NewFrame()
{
this->timer->Tick();
}
void GkGame::Process()
{
if (this->currentGamePage != NULL)
this->currentGamePage->Process(this);
}
void GkGame::Render()
{
if (this->currentGamePage != NULL)
this->currentGamePage->Render(this);
}
@@ -0,0 +1,61 @@
#pragma once
#include "..\GkDefinitions.h"
#include <iostream>
#include <vector>
#include "..\Graphics\GkGraphicsDevice.h"
#include "..\Graphics\GkAnimatedTexture.h"
#include "..\Graphics\GkAnimatedFont.h"
#include "..\Sound\GkSoundDevice.h"
#include "..\Sound\GkSoundSource.h"
#include "GkGameTimer.h"
#include "GkGamePage.h"
#include "..\Base\GkBase.h"
using namespace std;
class GKDLLCLASS GkGamePage;
struct ResourcePoolEntry
{
GkBase* resource;
wchar_t* id;
ResourcePoolEntry::ResourcePoolEntry(GkBase *resource, const wchar_t *id);
};
class GKDLLCLASS GkGame
{
public:
GkGraphicsDevice *graphicsDevice;
GkSoundDevice *soundDevice;
GkGameTimer *timer;
vector<GkGamePage*> gamePages;
GkGamePage *currentGamePage;
vector<ResourcePoolEntry> resourcePool;
GkGame::GkGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice);
virtual GkGame::~GkGame(void);
void SetPage(GkGamePage *page);
GkAnimatedTexture* GkGame::AddAnimatedTexture(GkAnimatedTexture *animatedTexture, const wchar_t* id = 0);
void* GkGame::GetResource(const wchar_t* id);
bool GkGame::ReleaseResource(const wchar_t* id);
GkAnimatedFont* GkGame::AcquireAnimatedFontFromMultipleFiles(const wchar_t* virtualFileName, const wchar_t *charMap, int numFrames = 1);
GkAnimatedTexture* GkGame::AcquireAnimatedTexture(const wchar_t* virtualFileName, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
GkAnimatedTexture* GkGame::AcquireAnimatedTextureFromMultipleFiles(const wchar_t* virtualFileName, float framesPerSecond = 25.0f);
GkSoundSource* GkGame::AcquireSoundSource(const wchar_t* virtualFileName);
GkGamePage* GkGame::AddGamePage(GkGamePage *gamePage);
void GkGame::RemoveGamePage(GkGamePage *gamePage);
virtual void GkGame::MouseDown(int x, int y);
virtual void GkGame::MouseUp(int x, int y);
virtual void GkGame::NewFrame();
virtual void GkGame::Process();
virtual void GkGame::Render();
};
@@ -0,0 +1,54 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameEntity.h"
#include "GkGame.h"
GkGameEntity::GkGameEntity()
{
}
GkGameEntity::~GkGameEntity(void)
{
}
void GkGameEntity::MouseDown(int x, int y)
{
}
void GkGameEntity::MouseUp(int x, int y)
{
}
void GkGameEntity::Process(GkGame *game)
{
}
void GkGameEntity::Draw(GkGame *game)
{
}
bool GkGameEntity::IsMouseOver(int x, int y)
{
return false;
}
void GkGameEntity::OnMouseClicked()
{
}
bool GkGameEntity::GetBoundaries(int *x1, int *y1, int *x2, int*y2)
{
return false;
}
@@ -0,0 +1,20 @@
#pragma once
#include "..\GkDefinitions.h"
class GKDLLCLASS GkGame;
class GKDLLCLASS GkGameEntity
{
public:
GkGameEntity::GkGameEntity();
virtual GkGameEntity::~GkGameEntity(void);
virtual void GkGameEntity::MouseDown(int x, int y);
virtual void GkGameEntity::MouseUp(int x, int y);
virtual void GkGameEntity::Process(GkGame *game);
virtual void GkGameEntity::Draw(GkGame *game);
virtual bool GkGameEntity::IsMouseOver(int x, int y);
virtual void GkGameEntity::OnMouseClicked();
virtual bool GkGameEntity::GetBoundaries(int *x1, int *y1, int *x2, int*y2);
};
@@ -0,0 +1,93 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGamePage.h"
GkGamePage::GkGamePage()
{
}
GkGamePage::~GkGamePage(void)
{
int numEntities = this->entities.size();
for (int i = 0; i < numEntities; i++)
{
delete this->entities[i];
}
}
void GkGamePage::OnShow(GkGamePage *previous)
{
}
void GkGamePage::OnHide(GkGamePage *next)
{
}
GkGameEntity* GkGamePage::AddEntity(GkGameEntity *entity)
{
this->entities.push_back(entity);
return entity;
}
GkGameEntity* GkGamePage::InsertEntity(int position, GkGameEntity *entity)
{
this->entities.push_back(0);
for (int i = this->entities.size() - 1; i > position; i--)
this->entities[i] = this->entities[i - 1];
this->entities[position] = entity;
return entity;
}
bool GkGamePage::RemoveEntity(GkGameEntity *entity)
{
int numEntities = this->entities.size();
for (int i = 0; i < numEntities; i++)
{
if (this->entities[i] == entity)
{
this->entities[i] = this->entities[numEntities - 1];
this->entities.pop_back();
return true;
}
}
return false;
}
void GkGamePage::Process(GkGame *game)
{
int numEntities = this->entities.size();
for (int i = 0; i < numEntities; i++)
{
this->entities[i]->Process(game);
}
}
void GkGamePage::Render(GkGame *game)
{
int numEntities = this->entities.size();
for (int i = 0; i < numEntities; i++)
{
this->entities[i]->Draw(game);
}
}
@@ -0,0 +1,28 @@
#pragma once
#include "..\GkDefinitions.h"
#include <vector>
#include "GkGameEntity.h"
class GKDLLCLASS GkGame;
class GKDLLCLASS GkGamePage
{
public:
std::vector<GkGameEntity*> entities;
GkGamePage::GkGamePage();
virtual GkGamePage::~GkGamePage(void);
virtual void OnShow(GkGamePage *previous);
virtual void OnHide(GkGamePage *next);
GkGameEntity* GkGamePage::AddEntity(GkGameEntity *entity);
GkGameEntity* GkGamePage::InsertEntity(int position, GkGameEntity *entity);
bool GkGamePage::RemoveEntity(GkGameEntity *entity);
virtual void GkGamePage::Process(GkGame *game);
virtual void GkGamePage::Render(GkGame *game);
};
@@ -0,0 +1,29 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameReelModel.h"
#include "..\OSSpecific\GkOSUtils.h"
GkGameReelModel::GkGameReelModel(int numItems)
{
this->numItems = numItems;
this->items = new int[this->numItems];
GkOSUtils::ZeroMem(this->items, this->numItems * sizeof(int));
}
GkGameReelModel::~GkGameReelModel(void)
{
delete[] this->items;
}
@@ -0,0 +1,18 @@
#pragma once
#include "..\GkDefinitions.h"
class GKDLLCLASS GkGameReelModel
{
public:
int numItems;
int *items;
GkGameReelModel(int numItems);
virtual ~GkGameReelModel(void);
virtual int GetSymbol() = 0;
virtual void GenerateReel() = 0;
virtual void GenerateReelZero() = 0;
};
@@ -0,0 +1,80 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameReelsCombinationGenerator.h"
#include "..\Utils\GkMaths.h"
GkGameReelsCombinationGenerator::GkGameReelsCombinationGenerator(int numReels, int numReelItems)
: GkBaseReelMap(numReels, numReelItems)
{
this->reels = new GameReelsCombinationGeneratorReel[this->numReels];
for (int i = 0; i < this->numReels; i++)
{
this->reels[i].model = 0;
this->reels[i].blocked = false;
}
}
GkGameReelsCombinationGenerator::~GkGameReelsCombinationGenerator(void)
{
for (int i = 0; i < this->numReels; i++)
{
if (this->reels[i].model != 0)
delete this->reels[i].model;
}
delete[] this->reels;
}
void GkGameReelsCombinationGenerator::SetReelModel(int reelIndex, GkGameReelModel *reelModel, bool blocked)
{
this->reels[reelIndex].model = reelModel;
this->reels[reelIndex].blocked = blocked;
}
void GkGameReelsCombinationGenerator::GenerateReel(int reelIndex)
{
this->reels[reelIndex].model->GenerateReel();
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
{
this->SetSymbol(reelIndex, itemIndex, this->reels[reelIndex].model->items[itemIndex]);
}
}
void GkGameReelsCombinationGenerator::GenerateCombination()
{
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
if (!this->reels[reelIndex].blocked)
this->GenerateReel(reelIndex);
}
}
void GkGameReelsCombinationGenerator::GenerateCombinationZero()
{
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
if (!this->reels[reelIndex].blocked)
{
this->reels[reelIndex].model->GenerateReelZero();
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
{
this->SetSymbol(reelIndex, itemIndex, this->reels[reelIndex].model->items[itemIndex]);
}
}
}
}
@@ -0,0 +1,30 @@
#pragma once
#include "..\GkDefinitions.h"
#include "..\Base\GkBaseReelMap.h"
#include "GkGameReelModel.h"
struct GameReelsCombinationGeneratorReel
{
GkGameReelModel *model;
bool blocked;
};
class GKDLLCLASS GkGameReelsCombinationGenerator
: public GkBaseReelMap
{
public:
GameReelsCombinationGeneratorReel *reels;
GkGameReelsCombinationGenerator(int numReels, int numReelItems);
~GkGameReelsCombinationGenerator(void);
void SetReelModel(int reelIndex, GkGameReelModel *reelModel, bool blocked = false);
void GenerateReel(int reelIndex);
void GenerateCombination();
void GenerateCombinationZero();
};
@@ -0,0 +1,54 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameTimer.h"
#include "..\OSSpecific\GkOSUtils.h"
GkGameTimer::GkGameTimer(void)
{
this->counterFrequency = GkOSUtils::GetPerformanceCounterFrequency();
this->Reset();
}
GkGameTimer::~GkGameTimer(void)
{
}
void GkGameTimer::Reset()
{
this->counterTime = GkOSUtils::GetPerformanceCounter();
this->Tick();
}
float GkGameTimer::Tick()
{
long long newCounterTime = GkOSUtils::GetPerformanceCounter();
this->tickTime = (float)((double)(newCounterTime - this->counterTime) / (double)this->counterFrequency);
this->counterTime = newCounterTime;
return this->tickTime;
}
long long GkGameTimer::GetSample()
{
return GkOSUtils::GetPerformanceCounter();
}
float GkGameTimer::GetSampleTime(long long sample)
{
return (float)(((double)(GkGameTimer::GetSample() - sample)) / ((double)GkOSUtils::GetPerformanceCounterFrequency()));
}
@@ -0,0 +1,21 @@
#pragma once
#include "..\GkDefinitions.h"
class GKDLLCLASS GkGameTimer
{
public:
long long counterTime, counterFrequency;
float tickTime;
GkGameTimer(void);
~GkGameTimer(void);
void GkGameTimer::Reset();
float GkGameTimer::Tick();
static long long GetSample();
static float GetSampleTime(long long sample);
};
@@ -0,0 +1,116 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameWinningPotentialsAnalyzer.h"
GkGameWinningPotentialsAnalyzer::GkGameWinningPotentialsAnalyzer(GkGameWinningsModel *model)
: GkGameWinningsAnalyzer(model)
{
}
GkGameWinningPotentialsAnalyzer::~GkGameWinningPotentialsAnalyzer(void)
{
}
GameWinning GkGameWinningPotentialsAnalyzer::GetSymbolWinning(int symbolIndex, int lineIndex)
{
GameWinning reelItem;
reelItem.symbolIndex = symbolIndex;
reelItem.lineIndex = lineIndex;
reelItem.numItems = 0;
reelItem.itemsStart = 0;
GameWinning result = reelItem;
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex);
bool interrupted = false;
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
int reelSymbolIndex = this->GetLineSymbol(reelIndex, lineIndex);
GameWinningSymbolModel *reelSymbolModel = this->model->GetSymbolModel(reelSymbolIndex);
bool match = GkGameWinningsAnalyzer::SymbolsMatch(symbolIndex, reelSymbolIndex);
if (match || !interrupted)
{
if (reelItem.numItems == 0)
{
reelItem.itemsStart = reelIndex;
reelItem.symbolsFlags = GkGameWinningsModel::SymbolFlag_None;
}
reelItem.numItems++;
reelItem.symbolsFlags |= reelSymbolModel->flags;
if (reelItem.numItems > result.numItems)
{
result = reelItem;
}
if (!match)
interrupted = true;
}
else
{
if ((symbolModel->flags & GkGameWinningsModel::SymbolFlag_AnyPlace) == 0)
break;
reelItem.numItems = 0;
interrupted = false;
}
}
result.itemsEnd = result.itemsStart + result.numItems - 1;
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
return result;
}
GameWinning GkGameWinningPotentialsAnalyzer::GetScatterWinning(int symbolIndex)
{
GameWinning result = GkGameWinningsAnalyzer::GetScatterWinning(symbolIndex);
if (result.numItems < this->numReels - 1)
{
result.numItems++;
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
}
return result;
}
bool GkGameWinningPotentialsAnalyzer::ReelBelongsToWinningAndSymbol(int reelIndex, int winningIndex)
{
if (!GkGameWinningsAnalyzer::ReelBelongsToWinning(reelIndex, winningIndex))
return false;
return this->SymbolsMatch(this->winnings.win[winningIndex].symbolIndex, this->GetLineSymbol(reelIndex, this->winnings.win[winningIndex].lineIndex));
}
bool GkGameWinningPotentialsAnalyzer::ContainsActualWin(int winningIndex)
{
if ((winningIndex < 0) || (winningIndex >= this->winnings.count))
return false;
int actualSequenceLength = 0;
for (int reelIndex = this->winnings.win[winningIndex].itemsStart; reelIndex <= this->winnings.win[winningIndex].itemsEnd; reelIndex++)
{
if (this->ReelBelongsToWinningAndSymbol(reelIndex, winningIndex))
actualSequenceLength++;
else
break;
}
return this->model->GetSymbolCoefficient(this->winnings.win[winningIndex].symbolIndex, actualSequenceLength) != 0;
}
@@ -0,0 +1,19 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkGameWinningsAnalyzer.h"
class GKDLLCLASS GkGameWinningPotentialsAnalyzer :
public GkGameWinningsAnalyzer
{
public:
GkGameWinningPotentialsAnalyzer(GkGameWinningsModel *model);
virtual ~GkGameWinningPotentialsAnalyzer(void);
virtual GameWinning GetSymbolWinning(int symbolIndex, int lineIndex);
virtual GameWinning GetScatterWinning(int symbolIndex);
bool ReelBelongsToWinningAndSymbol(int reelIndex, int winningIndex);
bool ContainsActualWin(int winningIndex);
};
@@ -0,0 +1,487 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameWinningsAnalyzer.h"
#include "..\Utils\GkMaths.h"
#include "..\OSSpecific\GkOSUtils.h"
#include <stdarg.h>
// Camparison of reel combinations - combinations may have
// A. Exactly the same symbol wins as the compared - equal
// B. The same symbol wins from the compared plus more - greater
// C. Symbol wins from the compared, but not all or with less symbols - lesser
// D. Not all the symbol wins from the compared plus more - different
//
// Rule set
//
// Definition: A symbol win is considered a winning of EXACTLY the same symbol and either on EXACTLY the same line OR BEING A SCATTER
//
// Signs of comparison:
// 1.1 Contains all the symbol wins as the compared one
// 1.2 Contains symbol wins, that are not present in the compared one
//
// In addition to that, there might be symbol win(s) with
// 2.1 The same number of winning items
// 2.2 Greater number of winning items
// 2.3 Lesser number of winning items
//
// Result
// Equal - 1.1 and not 1.2 and not 2.2. and not 2.3
// Greater - 1.1. and (1.2 or 2.2) and not 2.3
// Lesser - (not 1.1 or 2.3) and not 1.2 and not 2.2
// Different - otherwise
GkGameWinningsAnalyzer::GkGameWinningsAnalyzer(GkGameWinningsModel *model)
: GkBaseReelMap(model->numReels, model->numReelItems)
{
this->model = model;
this->comparisonMode = GameWinningAnalyzerComparisonMode_FullComparison;
this->InitWinningData(&this->winnings);
}
GkGameWinningsAnalyzer::~GkGameWinningsAnalyzer(void)
{
this->DisposeWinningData(&this->winnings);
}
GameWinning GkGameWinningsAnalyzer::GetSymbolWinning(int symbolIndex, int lineIndex)
{
GameWinning reelItem;
reelItem.symbolIndex = symbolIndex;
reelItem.lineIndex = lineIndex;
reelItem.numItems = 0;
reelItem.itemsStart = 0;
GameWinning result = reelItem;
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex);
bool sequenceValid = false;
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
int reelSymbolIndex = this->GetLineSymbol(reelIndex, lineIndex);
GameWinningSymbolModel *reelSymbolModel = this->model->GetSymbolModel(reelSymbolIndex);
if (this->SymbolsMatch(symbolIndex, reelSymbolIndex))
{
if (symbolIndex == reelSymbolIndex)
sequenceValid = true;
if (reelItem.numItems == 0)
{
reelItem.itemsStart = reelIndex;
reelItem.symbolsFlags = GkGameWinningsModel::SymbolFlag_None;
}
reelItem.numItems++;
reelItem.symbolsFlags |= reelSymbolModel->flags;
if (sequenceValid && (reelItem.numItems > result.numItems))
{
result = reelItem;
}
}
else
{
if ((symbolModel->flags & GkGameWinningsModel::SymbolFlag_AnyPlace) == 0)
break;
sequenceValid = false;
reelItem.numItems = 0;
}
}
result.itemsEnd = result.itemsStart + result.numItems - 1;
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
return result;
}
bool GkGameWinningsAnalyzer::SymbolsMatch(int symbolIndex, int testSymbolIndex)
{
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex),
*testSymbolModel = this->model->GetSymbolModel(testSymbolIndex);
return ((testSymbolIndex == symbolIndex) || ((testSymbolModel->flags & GkGameWinningsModel::SymbolFlag_Wild) != 0)) &&
((testSymbolModel->flags & symbolModel->exclusionFlags) == 0);
}
GameWinning GkGameWinningsAnalyzer::GetScatterWinning(int symbolIndex)
{
int scatterNumber = 0;
for (int symbolsIndex = 0; symbolsIndex < symbolsIndex; symbolsIndex++)
if (this->model->GetSymbolModel(symbolsIndex)->flags & GkGameWinningsModel::SymbolFlag_Scatter)
scatterNumber++;
GameWinning result;
result.symbolIndex = symbolIndex;
result.numItems = 0;
result.lineIndex = this->model->numLines + scatterNumber;
if (scatterNumber >= this->model->numScatters)
{
result.symbolsFlags = GkGameWinningsModel::SymbolFlag_None;
result.winningCoefficient = 0;
return result;
}
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex);
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
{
this->model->lines[result.lineIndex].coordinates[reelIndex] = this->FindFirstSymbol(reelIndex, symbolIndex);
if (this->model->lines[result.lineIndex].coordinates[reelIndex] != -1)
{
if (result.numItems == 0)
result.itemsStart = reelIndex;
result.numItems++;
result.itemsEnd = reelIndex;
}
}
result.symbolsFlags = symbolModel->flags;
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
return result;
}
void GkGameWinningsAnalyzer::AnalyzeWinnings(GkBaseReelMap *reelMap)
{
if (reelMap != 0)
this->SetItems(reelMap);
this->winnings.count = 0;
// Analyze line winnings
for (int lineIndex = 0; lineIndex < this->model->numLines; lineIndex++)
{
if (this->model->lines[lineIndex].active)
{
GameWinning maxLineWin;
maxLineWin.winningCoefficient = 0;
for (int symbolIndex = 0; symbolIndex < this->model->numSymbols; symbolIndex++)
{
if ((this->model->GetSymbolModel(symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_Scatter) == 0)
{
GameWinning symbolWin = this->GetSymbolWinning(symbolIndex, lineIndex);
if (symbolWin.winningCoefficient != 0)
{
if ((maxLineWin.winningCoefficient == 0) ||
(this->model->CompareSymbolWinnning(symbolWin.symbolIndex, symbolWin.numItems, maxLineWin.symbolIndex, maxLineWin.numItems) > 0))
{
maxLineWin = symbolWin;
}
}
}
}
if (maxLineWin.winningCoefficient != 0)
{
this->winnings.win[this->winnings.count++] = maxLineWin;
}
}
}
// Analyze scatters
for (int symbolIndex = 0; symbolIndex < this->model->numSymbols; symbolIndex++)
{
if ((this->model->GetSymbolModel(symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_Scatter) != 0)
{
GameWinning symbolWin = this->GetScatterWinning(symbolIndex);
if (symbolWin.winningCoefficient != 0)
{
this->winnings.win[this->winnings.count++] = symbolWin;
}
}
}
// Calculate total winnigs, total flags and manage items with SymbolFlag_IgnoreWinning
this->totalWinning = 0;
this->totalFlags = GkGameWinningsModel::SymbolFlag_None;
for (int i = 0; i < this->winnings.count; i++)
{
if (this->winnings.win[i].symbolsFlags & GkGameWinningsModel::SymbolFlag_IgnoreWinning)
this->winnings.win[i].winningCoefficient = 0;
this->totalWinning += this->winnings.win[i].winningCoefficient;
this->totalFlags |= this->winnings.win[i].symbolsFlags;
}
this->SortWinnings();
}
int GkGameWinningsAnalyzer::WinningOrder(int winningIndex1, int winningIndex2)
{
bool win1End = (this->model->GetSymbolModel(this->winnings.win[winningIndex1].symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_AtEnd) != 0;
bool win2End = (this->model->GetSymbolModel(this->winnings.win[winningIndex2].symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_AtEnd) != 0;
if (win1End && !win2End)
return 1;
if (win2End && !win1End)
return -1;
return GkMaths::Sign(this->winnings.win[winningIndex1].lineIndex - this->winnings.win[winningIndex2].lineIndex);
}
int GkGameWinningsAnalyzer::CompareWinning(int winningIndex1, int winningIndex2)
{
return GkMaths::Sign(this->winnings.win[winningIndex1].winningCoefficient - this->winnings.win[winningIndex2].winningCoefficient);
}
void GkGameWinningsAnalyzer::SortWinnings()
{
for (int i = 0; i < this->winnings.count; i++)
{
int leadingWin = i;
for (int j = i + 1; j < this->winnings.count; j++)
{
if (this->WinningOrder(leadingWin, j) > 0)
leadingWin = j;
}
if (leadingWin != i)
{
GameWinning t = this->winnings.win[i];
this->winnings.win[i] = this->winnings.win[leadingWin];
this->winnings.win[leadingWin] = t;
}
}
}
void GkGameWinningsAnalyzer::MultiplyWinnings(int factor)
{
for (int i = 0; i < this->winnings.count; i++)
this->winnings.win[i].winningCoefficient *= factor;
this->totalWinning *= factor;
}
int GkGameWinningsAnalyzer::GetLineSymbol(int reelIndex, int lineIndex)
{
return this->GetSymbol(reelIndex, model->GetLineSymbolCoordinate(reelIndex, lineIndex));
}
int GkGameWinningsAnalyzer::FindWinning(int symbolIndex, int minSymbols)
{
for (int i = 0; i < this->winnings.count; i++)
if ((this->winnings.win[i].symbolIndex == symbolIndex) && (this->winnings.win[i].numItems >= minSymbols))
return i;
return -1;
}
bool GkGameWinningsAnalyzer::ReelBelongsToWinning(int reelIndex, int winningIndex)
{
if ((winningIndex < 0) || (winningIndex >= this->winnings.count))
return false;
if (this->winnings.win[winningIndex].symbolsFlags & GkGameWinningsModel::SymbolFlag_Scatter)
{
if (this->model->lines[this->winnings.win[winningIndex].lineIndex].coordinates[reelIndex] == -1)
return false;
}
else
{
if ((reelIndex < this->winnings.win[winningIndex].itemsStart) || (reelIndex > this->winnings.win[winningIndex].itemsStart + this->winnings.win[winningIndex].numItems - 1))
return false;
}
return true;
}
bool GkGameWinningsAnalyzer::ReelBelongsToAnyWinning(int reelIndex)
{
for (int winningIndex = 0; winningIndex < this->winnings.count; winningIndex++)
if (this->ReelBelongsToWinning(reelIndex, winningIndex))
return true;
return false;
}
bool GkGameWinningsAnalyzer::ReelItemBelongsToWinning(int reelIndex, int itemIndex, int winningIndex)
{
if (!this->ReelBelongsToWinning(reelIndex, winningIndex))
return false;
return this->model->lines[this->winnings.win[winningIndex].lineIndex].coordinates[reelIndex] == itemIndex;
}
bool GkGameWinningsAnalyzer::ReelItemBelongsToAnyWinning(int reelIndex, int itemIndex)
{
for (int winningIndex = 0; winningIndex < this->winnings.count; winningIndex++)
if (this->ReelItemBelongsToWinning(reelIndex, itemIndex, winningIndex))
return true;
return false;
}
void GkGameWinningsAnalyzer::InitWinningData(GameWinnings *data)
{
data->win = new GameWinning[this->model->numLines + this->model->numScatters];
data->count = 0;
}
void GkGameWinningsAnalyzer::DisposeWinningData(GameWinnings *data)
{
delete[] data->win;
data->count = 0;
}
void GkGameWinningsAnalyzer::SaveWinningData(GameWinnings *destination)
{
destination->count = this->winnings.count;
GkOSUtils::CopyMem(destination->win, this->winnings.win, sizeof(GameWinning) * this->winnings.count);
}
WinningDataComparisonResult GkGameWinningsAnalyzer::FindWinning(GameWinning *gameWinning)
{
for (int i = 0; i < this->winnings.count; i++)
{
GameWinning *testedWinning = &this->winnings.win[i];
if ((testedWinning->symbolIndex == gameWinning->symbolIndex) &&
((testedWinning->lineIndex == gameWinning->lineIndex) ||
((testedWinning->symbolsFlags & GkGameWinningsModel::SymbolFlag_Scatter) != 0) ||
(this->comparisonMode == GameWinningAnalyzerComparisonMode_IgnoreLineMatching)))
{
if (testedWinning->numItems == gameWinning->numItems)
return WinningDataComparisonResult_Equivalent;
if (testedWinning->numItems < gameWinning->numItems)
return WinningDataComparisonResult_Lesser;
if (testedWinning->numItems > gameWinning->numItems)
return WinningDataComparisonResult_Greater;
}
}
return WinningDataComparisonResult_Different;
}
WinningDataComparisonResult GkGameWinningsAnalyzer::CompareWith(GameWinnings *data)
{
bool containsLesserWin = false,
containsGreaterWin = false;
int numMatchingWins = 0;
for (int winIndex = 0; winIndex < data->count; winIndex++)
{
GameWinning *winning = &data->win[winIndex];
WinningDataComparisonResult camparedToData = this->FindWinning(winning);
if (camparedToData == WinningDataComparisonResult_Lesser)
containsLesserWin = true;
if (camparedToData == WinningDataComparisonResult_Greater)
containsGreaterWin = true;
if (camparedToData != WinningDataComparisonResult_Different)
numMatchingWins++;
}
bool containsAllDataWins = numMatchingWins == data->count,
containsOtherWins = numMatchingWins < this->winnings.count;
if (containsAllDataWins && !containsOtherWins && !containsLesserWin && !containsGreaterWin)
return WinningDataComparisonResult_Equivalent;
if (containsAllDataWins && (containsOtherWins || containsGreaterWin) && !containsLesserWin)
return WinningDataComparisonResult_Greater;
if ((!containsAllDataWins || containsLesserWin) && !containsOtherWins && !containsGreaterWin)
return WinningDataComparisonResult_Lesser;
return WinningDataComparisonResult_Different;
}
int GkGameWinningsAnalyzer::GetWinningReelsCount()
{
int result = 0;
for (int reelIndex = 0; reelIndex < this->model->numReels; reelIndex++)
if (this->ReelBelongsToAnyWinning(reelIndex))
result++;
return result;
}
int GkGameWinningsAnalyzer::GetWinningReelsCount(int winningIndex, int startReel, int numReels)
{
int result = 0;
if (numReels == -1)
numReels = this->model->numReels;
for (int reelIndex = startReel; reelIndex < startReel + numReels; reelIndex++)
if (this->ReelBelongsToWinning(reelIndex, winningIndex))
result++;
return result;
}
int GkGameWinningsAnalyzer::GetWinningItemReelIndex(int winningItemIndex)
{
for (int reelIndex = 0; reelIndex < this->model->numReels; reelIndex++)
{
if (this->ReelBelongsToAnyWinning(reelIndex))
{
if (winningItemIndex == 0)
return reelIndex;
winningItemIndex--;
}
}
return -1;
}
int GkGameWinningsAnalyzer::GetWinningItemReelIndex(int winningItemIndex, int winningIndex)
{
for (int reelIndex = 0; reelIndex < this->model->numReels; reelIndex++)
{
if (this->ReelBelongsToWinning(reelIndex, winningIndex))
{
if (winningItemIndex == 0)
return reelIndex;
winningItemIndex--;
}
}
return -1;
}
int GkGameWinningsAnalyzer::GetHighestWinning()
{
if (this->winnings.count == 0)
return -1;
int result = 0;
for (int winIndex = 1; winIndex < this->winnings.count; winIndex++)
if (this->CompareWinning(winIndex, result) > 0)
result = winIndex;
return result;
}
@@ -0,0 +1,80 @@
#pragma once
#include "..\GkDefinitions.h"
#include "..\Base\GkBaseReelMap.h"
#include "GkGameWinningsModel.h"
struct GameWinning
{
int lineIndex, symbolIndex,
itemsStart, itemsEnd, numItems,
winningCoefficient;
unsigned int symbolsFlags;
};
struct GameWinnings
{
int count;
GameWinning *win;
};
enum WinningDataComparisonResult
{
WinningDataComparisonResult_Different,
WinningDataComparisonResult_Equivalent,
WinningDataComparisonResult_Greater,
WinningDataComparisonResult_Lesser
};
enum GameWinningAnalyzerComparisonMode
{
GameWinningAnalyzerComparisonMode_FullComparison,
GameWinningAnalyzerComparisonMode_IgnoreLineMatching,
};
class GKDLLCLASS GkGameWinningsAnalyzer
: public GkBaseReelMap
{
public:
GkGameWinningsModel *model;
GameWinnings winnings;
int totalWinning, totalFlags;
GameWinningAnalyzerComparisonMode comparisonMode;
GkGameWinningsAnalyzer(GkGameWinningsModel *model);
virtual ~GkGameWinningsAnalyzer(void);
virtual GameWinning GetSymbolWinning(int symbolIndex, int lineIndex);
virtual GameWinning GetScatterWinning(int symbolIndex);
virtual void AnalyzeWinnings(GkBaseReelMap *reelMap = 0);
virtual bool SymbolsMatch(int symbol1Index, int testSymbolIndex);
virtual int WinningOrder(int winningIndex1, int winningIndex2);
virtual int CompareWinning(int winningIndex1, int winningIndex2);
void SortWinnings();
void MultiplyWinnings(int factor);
int GetLineSymbol(int reelIndex, int lineIndex);
int FindWinning(int symbolIndex, int minSymbols = 0);
bool ReelBelongsToWinning(int reelIndex, int winningIndex);
bool ReelBelongsToAnyWinning(int reelIndex);
bool ReelItemBelongsToWinning(int reelIndex, int itemIndex, int winningIndex);
bool ReelItemBelongsToAnyWinning(int reelIndex, int itemIndex);
int GetWinningReelsCount();
int GetWinningReelsCount(int winningIndex, int startReel = 0, int numReels = -1);
int GetWinningItemReelIndex(int winningItemIndex);
int GetWinningItemReelIndex(int winningItemIndex, int winningIndex);
int GetHighestWinning();
void InitWinningData(GameWinnings *data);
void DisposeWinningData(GameWinnings *data);
void SaveWinningData(GameWinnings *destination);
bool IsLessOrEqualThan(GameWinnings *data);
WinningDataComparisonResult FindWinning(GameWinning *gameWinning);
WinningDataComparisonResult CompareWith(GameWinnings *data);
};
@@ -0,0 +1,124 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameWinningsModel.h"
#include "..\OSSpecific\GkOSUtils.h"
#include "..\Utils\GkMaths.h"
GkGameWinningsModel::GkGameWinningsModel(int numReels, int numReelItems, int numLines, int numSymbols, int numScatters, int numChannels)
{
this->numReels = numReels;
this->numReelItems = numReelItems;
this->numLines = numLines;
this->numSymbols = numSymbols;
this->numScatters = numScatters;
this->numChannels = numChannels;
this->selectedChannel = 0;
this->lines = new GameWinningLineModel[this->numLines + numScatters];
for (int i = 0; i < this->numLines + this->numScatters; i++)
{
this->lines[i].active = true;
this->lines[i].coordinates = new int[this->numReels];
GkOSUtils::ZeroMem(this->lines[i].coordinates, this->numReels * sizeof(int));
}
this->symbols = new GameWinningSymbolModel*[this->numChannels];
for (int channel = 0; channel < this->numChannels; channel++)
{
this->symbols[channel] = new GameWinningSymbolModel[this->numSymbols];
for (int symbol = 0; symbol < this->numSymbols; symbol++)
{
this->symbols[channel][symbol].coefficients = new int[this->numReels];
GkOSUtils::ZeroMem(this->symbols[channel][symbol].coefficients, this->numReels * sizeof(int));
}
}
}
GkGameWinningsModel::~GkGameWinningsModel(void)
{
for (int channel = 0; channel < this->numChannels; channel++)
{
for (int symbol = 0; symbol < this->numSymbols; symbol++)
{
delete[] this->symbols[channel][symbol].coefficients;
}
delete[] this->symbols[channel];
}
delete[] this->symbols;
for (int i = 0; i < this->numLines + this->numScatters; i++)
{
delete[] this->lines[i].coordinates;
}
delete[] this->lines;
}
void GkGameWinningsModel::SetupLine(int lineIndex, ...)
{
//GkOSUtils::CopyMem(this->lines[lineIndex], (void*)lineCoordinates, this->numReels * sizeof(int));
va_list lineCoordinates;
va_start(lineCoordinates, lineIndex);
for(int i = 0; i < this->numReels; ++i )
this->lines[lineIndex].coordinates[i] = va_arg(lineCoordinates, int);
va_end(lineCoordinates);
}
void GkGameWinningsModel::SetupSymbol(int symbolIndex, int channelIndex, unsigned int symbolFlags, unsigned int symbolExclusionFlags, ...)
{
va_list winCoefficients;
va_start(winCoefficients, symbolExclusionFlags);
for(int i = 0; i < this->numReels; ++i )
{
this->symbols[channelIndex][symbolIndex].coefficients[i] = va_arg(winCoefficients, int);
}
va_end(winCoefficients);
this->symbols[channelIndex][symbolIndex].flags = symbolFlags;
this->symbols[channelIndex][symbolIndex].exclusionFlags = symbolExclusionFlags;
}
int GkGameWinningsModel::GetLineSymbolCoordinate(int reelIndex, int lineIndex)
{
return this->lines[lineIndex].coordinates[reelIndex];
}
GameWinningSymbolModel *GkGameWinningsModel::GetSymbolModel(int symbol)
{
return &this->symbols[this->selectedChannel][symbol];
}
int GkGameWinningsModel::GetSymbolCoefficient(int symbol, int symbolCount)
{
if (symbolCount == 0)
return 0;
return this->symbols[this->selectedChannel][symbol].coefficients[symbolCount - 1];
}
int GkGameWinningsModel::CompareSymbolWinnning(int symbol1, int symbol1Count, int symbol2, int symbol2Count)
{
int coefficientDelta = this->GetSymbolCoefficient(symbol1, symbol1Count) - this->GetSymbolCoefficient(symbol2, symbol2Count);
if (coefficientDelta != 0)
return GkMaths::Sign(coefficientDelta);
for (int numSymbols = GkMaths::Max(symbol1Count, symbol2Count); numSymbols <= this->numReels; numSymbols++)
{
coefficientDelta = this->GetSymbolCoefficient(symbol1, numSymbols) - this->GetSymbolCoefficient(symbol2, numSymbols);
if (coefficientDelta != 0)
return GkMaths::Sign(coefficientDelta);
}
return 0;
}
@@ -0,0 +1,48 @@
#pragma once
#include "..\GkDefinitions.h"
struct GameWinningLineModel
{
bool active;
int *coordinates;
};
struct GameWinningSymbolModel
{
unsigned int flags, exclusionFlags;
int *coefficients;
};
class GKDLLCLASS GkGameWinningsModel
{
public:
static const unsigned int SymbolFlag_None = 0,
SymbolFlag_Default = 1 << 0,
SymbolFlag_Wild = 1 << 1,
SymbolFlag_AnyPlace = 1 << 2, // Line sequence can start from anywhere, not only from the beginning of a line
SymbolFlag_IgnoreWinning = 1 << 3,
SymbolFlag_AtEnd = 1 << 4,
SymbolFlag_Scatter = 1 << 5, // If a symbol is Scatter, it has a line index of numLines and above, and its line's coordinates are set correspondingly on each CalculateWinnings()
SymbolFlag_Custom = 1 << 8; // For user - defined flags. User_Defined_Flag = SymbolFlag_Custom << UserFlag_Index
int numReels, numReelItems, numChannels, selectedChannel;
int numLines;
GameWinningLineModel *lines;
int numSymbols, numScatters;
GameWinningSymbolModel **symbols;
GkGameWinningsModel(int numReels, int numReelItems, int numLines, int numSymbols, int numScatters = 0, int numChannels = 1);
~GkGameWinningsModel(void);
void SetupLine(int lineIndex, ...);
void SetupSymbol(int symbolIndex, int channelIndex, unsigned int symbolFlags, unsigned int symbolExclusionFlags, ...);
int GetLineSymbolCoordinate(int reelIndex, int lineIndex);
GameWinningSymbolModel *GetSymbolModel(int symbol);
int GetSymbolCoefficient(int symbol, int symbolCount);
int CompareSymbolWinnning(int symbol1, int symbol1Count, int symbol2, int symbol2Count);
};
@@ -0,0 +1,117 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameReelRandomModel.h"
#include "..\..\Utils\GkMaths.h"
GkGameReelRandomModel::GkGameReelRandomModel(int numItems, int numSymbols)
:GkGameReelModel(numItems)
{
this->numSymbols = numSymbols;
this->symbols = new GameReelRandomModelSymbol[numSymbols];
for (int i = 0; i < numSymbols; i++)
this->SetupSymbol(i, i);
}
GkGameReelRandomModel::~GkGameReelRandomModel(void)
{
delete[] this->symbols;
}
void GkGameReelRandomModel::SetupSymbol(int symbolIndex, int symbolValue, int hitProbability, int maxHits)
{
this->symbols[symbolIndex].value = symbolValue;
this->symbols[symbolIndex].hitProbability = hitProbability;
this->symbols[symbolIndex].maxHits = maxHits;
this->overallProbability = 0;
for (int i = 0; i < this->numSymbols; i++)
this->overallProbability += this->symbols[i].hitProbability;
}
bool GkGameReelRandomModel::ReplaceReelSymbol(int itemIndex, int symbolIndex, bool forceReplace)
{
bool autoGenerate = symbolIndex == -1;
do
{
if (autoGenerate)
{
symbolIndex = this->GetSymbolIndex();
}
if ((this->symbols[symbolIndex].maxHits == GkGameReelRandomModel::UnlimitedHits) || (this->symbols[symbolIndex].occurances < this->symbols[symbolIndex].maxHits) || forceReplace)
{
this->symbols[this->items[itemIndex]].occurances--;
this->items[itemIndex] = symbolIndex;
this->symbols[symbolIndex].occurances++;
return true;
}
} while (autoGenerate);
return false;
}
int GkGameReelRandomModel::GetSymbolIndex()
{
int p = GkMaths::Random(this->overallProbability);
int s = 0;
for (int i = 0; i < this->numSymbols; i++)
{
s += this->symbols[i].hitProbability;
if (p < s)
return i;
}
return -1;
}
int GkGameReelRandomModel::GetSymbol()
{
int symbolIndex = this->GetSymbolIndex();
if (symbolIndex == -1)
return -1;
else
return this->symbols[symbolIndex].value;
}
void GkGameReelRandomModel::GenerateReel()
{
for (int symbolIndex = 0; symbolIndex < this->numSymbols; symbolIndex++)
this->symbols[symbolIndex].occurances = 0;
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
{
for (;;)
{
int symbolIndex = this->GetSymbolIndex();
if ((this->symbols[symbolIndex].maxHits == GkGameReelRandomModel::UnlimitedHits) || (this->symbols[symbolIndex].occurances < this->symbols[symbolIndex].maxHits))
{
this->items[itemIndex] = this->symbols[symbolIndex].value;
this->symbols[symbolIndex].occurances++;
break;
}
}
}
}
void GkGameReelRandomModel::GenerateReelZero()
{
this->GenerateReel();
}
@@ -0,0 +1,35 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameReelModel.h"
struct GameReelRandomModelSymbol
{
int value, hitProbability, maxHits,
occurances;
};
class GKDLLCLASS GkGameReelRandomModel :
public GkGameReelModel
{
public:
static const int UnlimitedHits = -1;
int numSymbols;
GameReelRandomModelSymbol *symbols;
int overallProbability;
GkGameReelRandomModel(int numItems, int numSymbols);
~GkGameReelRandomModel(void);
void SetupSymbol(int symbolIndex, int symbolValue, int hitProbability = 1, int maxHits = GkGameReelRandomModel::UnlimitedHits);
bool ReplaceReelSymbol(int itemIndex, int symbolIndex, bool forceReplace);
int GetSymbolIndex();
int GetSymbol();
void GenerateReel();
void GenerateReelZero();
};
@@ -0,0 +1,61 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGameReelStripModel.h"
#include "..\..\OSSpecific\GkOSUtils.h"
#include "..\..\Utils\GkMaths.h"
GkGameReelStripModel::GkGameReelStripModel(int numItems, int numSymbols, ...)
: GkGameReelModel(numItems)
{
this->numSymbols = numSymbols;
this->symbolStrip = new int[this->numSymbols];
int *parameters = (int*)((int)&numSymbols + 4);
for (int i = 0; i < this->numSymbols; i++)
this->symbolStrip[i] = parameters[i];
this->stripPosition = GkMaths::Random(this->numSymbols);
}
GkGameReelStripModel::~GkGameReelStripModel(void)
{
delete[] this->symbolStrip;
}
int GkGameReelStripModel::GetSymbol()
{
this->stripPosition = (this->stripPosition + 1) % this->numSymbols;
return this->symbolStrip[this->stripPosition];
}
void GkGameReelStripModel::GenerateReel()
{
this->stripPosition = GkMaths::Random(this->numSymbols);
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
{
this->items[itemIndex] = this->GetSymbol();
}
}
void GkGameReelStripModel::GenerateReelZero()
{
this->stripPosition = this->numSymbols - this->numItems / 2;
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
{
this->items[itemIndex] = this->GetSymbol();
}
}
@@ -0,0 +1,21 @@
#pragma once
#include "..\..\GkDefinitions.h"
#include "..\GkGameReelModel.h"
class GKDLLCLASS GkGameReelStripModel :
public GkGameReelModel
{
public:
int numSymbols;
int *symbolStrip;
int stripPosition;
GkGameReelStripModel(int numItems, int numSymbols, ...);
~GkGameReelStripModel(void);
int GetSymbol();
void GenerateReel();
void GenerateReelZero();
};
@@ -0,0 +1,12 @@
#pragma once
//#if defined (GKDLLCOMPILE)
//# define GKDLLCLASS __declspec(dllexport)
//# define GKDLLTEMPLATEMEMBER
//#else
//# define GKDLLCLASS __declspec(dllimport)
//# define GKDLLTEMPLATEMEMBER extern
//#endif
# define GKDLLCLASS
# define GKDLLTEMPLATEMEMBER
@@ -0,0 +1,50 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkAnimatedFont.h"
#include "..\Utils\GkStrings.h"
GkAnimatedFont::GkAnimatedFont(const wchar_t *charMap, int numFrames, float framesPerSecond)
{
this->charMap = GkStrings::Copy(charMap);
this->numFrames = numFrames;
this->numLetters = GkStrings::GetLength(charMap);
this->framesPerSecond = framesPerSecond;
this->letterTextures = new GkAnimatedTexture*[this->numLetters];
for (int i = 0; i < this->numLetters; i++)
{
this->letterTextures[i] = 0;
}
}
GkAnimatedFont::~GkAnimatedFont(void)
{
delete[] this->charMap;
for (int i = 0; i < this->numLetters; i++)
{
delete this->letterTextures[i];
}
delete[] this->letterTextures;
}
void GkAnimatedFont::LoadAnimatedLetter(int letterIndex, void *data, int dataSize)
{
if (this->letterTextures[letterIndex] != 0)
delete this->letterTextures[letterIndex];
this->letterTextures[letterIndex] = new GkAnimatedTexture(data, dataSize, 1, this->numFrames, this->numFrames);
}
@@ -0,0 +1,24 @@
#pragma once
#include "..\GkDefinitions.h"
#include "..\Base\GkBase.h"
#include "GkAnimatedTexture.h"
class GKDLLCLASS GkAnimatedFont :
public GkBase
{
public:
wchar_t *charMap;
int numLetters, numFrames;
float framesPerSecond;
GkAnimatedTexture **letterTextures;
GkAnimatedFont::GkAnimatedFont(const wchar_t *charMap, int numFrames, float framesPerSecond = 25.0f);
GkAnimatedFont::~GkAnimatedFont(void);
void GkAnimatedFont::LoadAnimatedLetter(int letterIndex, void *data, int dataSize);
};
@@ -0,0 +1,123 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkAnimatedTexture.h"
GkAnimatedTexture::GkAnimatedTexture(void)
{
this->numFrames = 0;
}
GkAnimatedTexture::GkAnimatedTexture(void* data, unsigned int dataSize, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
{
this->numFrames = 0;
this->LoadFromMemory(data, dataSize, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
}
GkAnimatedTexture::GkAnimatedTexture(char *fileName, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
{
this->numFrames = 0;
this->LoadFromFile(fileName, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
}
GkAnimatedTexture::~GkAnimatedTexture(void)
{
this->Free();
}
void GkAnimatedTexture::Free()
{
if (this->numFrames == 0)
return;
for (int i = 0; i < this->numFrames; i++)
{
delete this->frames[i];
}
delete this->frames;
this->numFrames = 0;
}
bool GkAnimatedTexture::LoadFromImage(GkImage *image, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
{
this->Free();
this->numFrames = numFrames != 0 ? numFrames : columnFrames * rowFrames;
this->framesPerSecond = framesPerSecond;
this->frames = new GkTexture*[this->numFrames];
int frameWidth = image->width / columnFrames;
int frameHeight = image->height / rowFrames;
int iMax, jMax;
if (animatedTexture_LoadOrder == GkAnimatedTexture::LoadOrder_Vertical)
{
jMax = columnFrames;
iMax = rowFrames;
}
else
{
jMax = rowFrames;
iMax = columnFrames;
}
int frameIndex = 0;
for (int j = 0; j < jMax; j++)
{
for (int i = 0; i < iMax; i++)
{
int x, y;
if (animatedTexture_LoadOrder == GkAnimatedTexture::LoadOrder_Vertical)
{
x = j;
y = i;
}
else
{
x = i;
y = j;
}
GkTexture *frame = new GkTexture();
frame->LoadFromImage(image, x * frameWidth, y * frameHeight, frameWidth, frameHeight);
frames[frameIndex++] = frame;
}
}
return true;
}
bool GkAnimatedTexture::LoadFromMemory(void* data, unsigned int dataSize, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
{
GkImage image;
image.LoadFromMemory(data, dataSize);
this->LoadFromImage(&image, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
return true;
}
bool GkAnimatedTexture::LoadFromFile(char *fileName, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
{
GkImage image;
image.LoadFromFile(fileName);
this->LoadFromImage(&image, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
return true;
}
@@ -0,0 +1,29 @@
#pragma once
#include "..\GkDefinitions.h"
#include "..\Base\GkBase.h"
#include "GkTexture.h"
class GKDLLCLASS GkAnimatedTexture :
public GkBase
{
public:
static const int LoadOrder_Horizontal = 0,
LoadOrder_Vertical = 1;
GkTexture **frames;
int numFrames;
float framesPerSecond;
GkAnimatedTexture::GkAnimatedTexture(void);
GkAnimatedTexture::GkAnimatedTexture(void* data, unsigned int dataSize, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
GkAnimatedTexture::GkAnimatedTexture(char *fileName, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
GkAnimatedTexture::~GkAnimatedTexture(void);
void GkAnimatedTexture::Free();
bool GkAnimatedTexture::LoadFromImage(GkImage *image, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
bool GkAnimatedTexture::LoadFromMemory(void* data, unsigned int dataSize, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
bool GkAnimatedTexture::LoadFromFile(char *fileName, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
};
@@ -0,0 +1,197 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkGraphicsDevice.h"
#include "..\Utils\GkMaths.h"
#include <iostream>
#include <GL\GLUt.h>
#include <string.h>
void GkGraphicsDevice::Initialize()
{
}
GkGraphicsDevice::GkGraphicsDevice(void)
{
this->SetViewport(0, 0, 640, 480);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &this->maxTextureSize);
this->nonPower2Textures = strstr((char*)glGetString(GL_EXTENSIONS),"GL_ARB_texture_non_power_of_two") != 0;
GkTexture::powerOfTwo = !this->nonPower2Textures;
}
GkGraphicsDevice::~GkGraphicsDevice(void)
{
}
void GkGraphicsDevice::Clear()
{
glClear(GL_COLOR_BUFFER_BIT);
}
void GkGraphicsDevice::Draw(int destX, int destY, int destWidth, int destHeight, int srcX, int srcY, int srcWidth, int srcHeight, GkTexture* texture)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, this->width, this->height, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(destX, destY, 0);
glScalef(destWidth, destHeight, 1);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(srcX / (float)texture->textureWidth, srcY / (float)texture->textureHeight, 0.0f);
glScalef(srcWidth / (float)texture->textureWidth, srcHeight / (float)texture->textureHeight, 1.0f);
glBindTexture(GL_TEXTURE_2D, texture->handle);
GLint filtering = (destWidth != srcWidth) || (destHeight != srcHeight) ? GL_LINEAR : GL_NEAREST;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
glBegin(GL_TRIANGLES);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glEnd();
}
void GkGraphicsDevice::Draw(int x, int y, GkTexture* texture)
{
this->Draw(x, y, texture->width, texture->height, 0, 0, texture->width, texture->height, texture);
}
void GkGraphicsDevice::DrawClipped(int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, GkTexture* texture)
{
int clipLeft = clipX - x;
int clipTop = clipY - y;
int destX = clipLeft > 0 ? clipX : x;
int destY = clipTop > 0 ? clipY : y;
int width = GkMaths::Min(texture->width - GkMaths::Max(clipLeft, 0), GkMaths::Min(clipX + clipWidth - destX, texture->width));
int height = GkMaths::Min(texture->height - GkMaths::Max(clipTop, 0), GkMaths::Min(clipY + clipHeight - destY, texture->height));
if ((width <= 0) || (height <= 0))
return;
int srcX = clipLeft > 0 ? clipLeft : 0;
int srcY = clipTop > 0 ? clipTop : 0;
this->Draw(destX, destY, width, height, srcX, srcY, width, height, texture);
}
void GkGraphicsDevice::DrawString(int x, int y, const char *text)
{
glLoadIdentity();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glRasterPos2i(x, y);
glDisable(GL_TEXTURE_2D);
for (int i = 0; text[i] != 0; i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, text[i]);
}
void GkGraphicsDevice::DrawString(int x, int y, const wchar_t *text)
{
glLoadIdentity();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glRasterPos2i(x, y);
glDisable(GL_TEXTURE_2D);
for (int i = 0; text[i] != 0; i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, text[i]);
glEnable(GL_TEXTURE_2D);
}
void GkGraphicsDevice::SetViewport(int x, int y, int width, int height)
{
this->width = width;
this->height = height;
glViewport(x, y, width, height);
glEnable(GL_TEXTURE_2D);
}
bool GkGraphicsDevice::CaptureScreen(const wchar_t *fileName, int width, int height)
{
int length = std::wcslen(fileName);
char *cFileName = new char[length + 1];
std::wcstombs(cFileName, fileName, length);
cFileName[length] = 0;
int dataSize = this->width * this->height * 4;
char *data = new char[dataSize];
glReadPixels(0, 0, this->width, this->height, GL_RGBA, GL_UNSIGNED_BYTE, data);
ILuint imageId;
ilGenImages(1, &imageId);
ilBindImage(imageId);
ilTexImage(this->width, this->height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);
iluImageParameter(ILU_FILTER, ILU_BILINEAR);
iluScale(width, height, 1);
ilSetInteger(IL_JPG_QUALITY, 50);
ilEnable(IL_FILE_OVERWRITE);
bool result = ilSaveImage(cFileName) != 0;
ilDeleteImages(1, &imageId);
delete[] data;
delete[] cFileName;
return result;
}
@@ -0,0 +1,32 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkTexture.h"
class GKDLLCLASS GkGraphicsDevice
{
public:
static void Initialize();
int maxTextureSize;
bool nonPower2Textures;
int width, height;
GkGraphicsDevice(void);
~GkGraphicsDevice(void);
void Free();
void Clear();
void Draw(int destX, int destY, int destWidth, int destHeight, int srcX, int srcY, int srcWidth, int srcHeight, GkTexture* texture);
void Draw(int x, int y, GkTexture* texture);
void DrawClipped(int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, GkTexture* texture);
void DrawString(int x, int y, const char *text);
void DrawString(int x, int y, const wchar_t *text);
void SetViewport(int x, int y, int width, int height);
bool CaptureScreen(const wchar_t *fileName, int width, int height);
};
@@ -0,0 +1,69 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkImage.h"
void GkImage::Initialize()
{
ilInit();
}
GkImage::GkImage(void)
{
ilGenImages(1, &this->handle);
}
GkImage::~GkImage(void)
{
ilDeleteImages(1, &this->handle);
}
void GkImage::LoadFromMemory(void* data, unsigned int dataSize)
{
ilBindImage(this->handle);
ilLoadL(IL_TYPE_UNKNOWN, data, dataSize);
this->width = ilGetInteger(IL_IMAGE_WIDTH);
this->height = ilGetInteger(IL_IMAGE_HEIGHT);
}
void GkImage::LoadFromFile(char* fileName)
{
ilBindImage(this->handle);
ilLoadImage(fileName);
this->width = ilGetInteger(IL_IMAGE_WIDTH);
this->height = ilGetInteger(IL_IMAGE_HEIGHT);
}
void GkImage::CopyPixels(void* dest)
{
ilBindImage(this->handle);
ilCopyPixels(0, 0, 0, this->width, this->height, 1, IL_RGBA, IL_UNSIGNED_BYTE, dest);
}
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height)
{
ilBindImage(this->handle);
ilCopyPixels(x, y, 0, width, height, 1, IL_RGBA, IL_UNSIGNED_BYTE, dest);
}
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height, int destX, int destY, int destWidth, int destHeight)
{
ilBindImage(this->handle);
for (int i = 0; i < height; i++)
{
ilCopyPixels(x, y + i, 0, width, 1, 1, IL_RGBA, IL_UNSIGNED_BYTE, (void*)(&((int*)dest)[(destY + i) * destWidth + destX]));
}
}
@@ -0,0 +1,24 @@
#pragma once
#include "..\GkDefinitions.h"
#include <DevIL\il.h>
#include <DevIL\ilu.h>
class GKDLLCLASS GkImage
{
public:
ILuint handle,
width, height;
static void GkImage::Initialize();
GkImage::GkImage(void);
GkImage::~GkImage(void);
void GkImage::LoadFromMemory(void* data, unsigned int dataSize);
void GkImage::LoadFromFile(char* fileName);
void GkImage::CopyPixels(void* dest);
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height);
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height, int destX, int destY, int destWidth, int destHeight);
};
@@ -0,0 +1,87 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkTexture.h"
#include <GL\GLUt.h>
bool GkTexture::powerOfTwo = false;
GkTexture::GkTexture(void)
{
glGenTextures(1, &handle);
glBindTexture(GL_TEXTURE_2D, this->handle);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
GkTexture::~GkTexture(void)
{
glDeleteTextures(1, &handle);
}
void GkTexture::LoadFromImage(GkImage* image)
{
this->LoadFromImage(image, 0, 0, image->width, image->height);
}
void GkTexture::LoadFromImage(GkImage* image, int x, int y, int width, int height)
{
if (GkTexture::powerOfTwo)
{
this->textureWidth = GkTexture::GetPowerOfTwo(width);
this->textureHeight = GkTexture::GetPowerOfTwo(height);
}
else
{
this->textureWidth = width;
this->textureHeight = height;
}
this->width = width;
this->height = height;
void *imageData = new char[this->textureWidth * this->textureHeight * 4];
if (this->width != this->textureWidth)
image->CopyPixels(imageData, x, y, width, height, 0, 0, this->textureWidth, this->textureHeight);
else
image->CopyPixels(imageData, x, y, width, height);
glBindTexture(GL_TEXTURE_2D, this->handle);
//glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this->textureWidth, this->textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
delete imageData;
}
void GkTexture::LoadFromFile(char* fileName)
{
GkImage* image = new GkImage();
image->LoadFromFile(fileName);
this->LoadFromImage(image);
delete image;
}
int GkTexture::GetPowerOfTwo(int value)
{
int result = 1;
while (result < value)
result *= 2;
return result;
}
@@ -0,0 +1,27 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkImage.h"
#include "..\Base\GkBase.h"
class GKDLLCLASS GkTexture :
public GkBase
{
public:
static bool powerOfTwo;
unsigned int handle;
int width, height,
textureWidth, textureHeight;
GkTexture::GkTexture(void);
GkTexture::~GkTexture(void);
void GkTexture::LoadFromImage(GkImage* image);
void GkTexture::LoadFromImage(GkImage* image, int x, int y, int width, int height);
void GkTexture::LoadFromFile(char* fileName);
static int GkTexture::GetPowerOfTwo(int value);
};
@@ -0,0 +1,285 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkFileSystem.h"
#include <Windows.h>
#include <vector>
#include <string>
#include "..\Utils\GkStrings.h"
std::wstring GkFileSystem::source;
//wchar_t *GkFileSystem::source;
FileSystemMode GkFileSystem::mode;
GkFileSystem::Init GkFileSystem::init;
GkFileSystem::Init::Init(void)
{
//GkFileSystem::source = GkStrings::Copy(L"\0");
}
GkFileSystem::Init::~Init(void)
{
//delete[] GkFileSystem::source;
}
GkFileSystem::GkFileSystem(void)
{
}
GkFileSystem::~GkFileSystem(void)
{
}
void GkFileSystem::SetSource(const wchar_t *source, FileSystemMode mode)
{
//delete[] GkFileSystem::source;
//if (source == 0)
// GkFileSystem::source = GkStrings::Copy(L"\0");
//else
// GkFileSystem::source = GkStrings::Copy(source);
if (source == 0)
GkFileSystem::source = std::wstring(L"\0");
else
GkFileSystem::source = std::wstring(source);
GkFileSystem::mode = mode;
}
bool GkFileSystem::LoadFile(const wchar_t *fileName, void **fileData, unsigned int *fileSize)
{
if (GkFileSystem::mode == FileSystemMode_Physical)
return GkFileSystem::LoadPhysicalFile(fileName, fileData, fileSize);
if (GkFileSystem::mode == FileSystemMode_Virtual)
return GkFileSystem::LoadVirtualFile(fileName, fileData, fileSize);
return false;
}
void GkFileSystem::CreateVirtualFileSystem(const wchar_t* directory, const wchar_t* fileName)
{
std::ofstream fileStream(fileName, std::ios::out | std::ios::binary);
GkFileSystem::WriteVirtualFileSystem(directory, &fileStream);
fileStream.close();
}
bool GkFileSystem::LoadVirtualFile(const wchar_t *fileName, void **fileData, unsigned int *fileSize)
{
std::vector<wchar_t*> pathElements;
int elementStart = 0;
int i = 0;
bool done;
do
{
done = *((char*)&fileName[i]) == 0;
if ((fileName[i] == L'\\') || done)
{
int l = i - elementStart;
wchar_t *element = new wchar_t[l + 1];
CopyMemory(element, &fileName[elementStart], l * sizeof(wchar_t));
element[l] = 0;
pathElements.push_back(element);
elementStart = i + 1;
}
i++;
} while (!done);
std::ifstream file(GkFileSystem::source, std::ios::in | std::ios::binary | std::ios::ate);
int pathElementIndex = 0;
int dirLimit = (int)file.tellg();
file.seekg(0);
done = false;
while (file && !done)
{
wchar_t *vfn = GkFileSystem::ReadString(&file);
int size;
file.read((char*)&size, sizeof(int));
if (wcscmp(vfn, pathElements[pathElementIndex]) == 0)
{
pathElementIndex++;
dirLimit = (int)file.tellg() + size;
if (pathElementIndex == pathElements.size())
{
*fileSize = size;
*fileData = new char[size];
file.read((char*)*fileData, size);
done = true;
}
}
else
{
file.seekg((int)file.tellg() + size);
}
delete vfn;
if (file.tellg() >= dirLimit)
break;
}
file.close();
for (int i = 0; i < (int)pathElements.size(); i++)
{
delete pathElements[i];
}
return done;
}
bool GkFileSystem::LoadPhysicalFile(const wchar_t *fileName, void **fileData, unsigned int *fileSize)
{
// TODO: fix this static string
std::wstring fn(GkFileSystem::source);
fn.append(fileName);
std::ifstream file(fn.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
if (!file)
return false;
*fileSize = (unsigned int)file.tellg();
*fileData = new char[*fileSize];
file.seekg(0);
file.read((char*)*fileData, *fileSize);
file.close();
return true;
}
wchar_t* GkFileSystem::ReadString(std::ifstream* fileStream)
{
int l;
fileStream->read((char*)&l, sizeof(int));
wchar_t *result = new wchar_t[l + 1];
fileStream->read((char*)result, l * sizeof(wchar_t));
result[l] = 0;
return result;
}
void GkFileSystem::WriteVirtualFileSystem(const wchar_t* directory, std::ofstream* fileStream)
{
std::wstring fullSearchDir(directory);
fullSearchDir.append(L"\\*");
WIN32_FIND_DATAW findData;
HANDLE findHandle = INVALID_HANDLE_VALUE;
findHandle = FindFirstFileW(fullSearchDir.c_str(), &findData);
if (findHandle == INVALID_HANDLE_VALUE)
{
return;
}
int chunkSize, chunkSizePos;
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((wcscmp(findData.cFileName, L".") != 0) && (wcscmp(findData.cFileName, L"..") != 0))
{
std::wstring fullSearchSubDir(directory);
fullSearchSubDir.append(L"\\");
fullSearchSubDir.append(findData.cFileName);
GkFileSystem::WriteString(findData.cFileName, fileStream);
chunkSizePos = (int)fileStream->tellp();
fileStream->write((char*)&chunkSize, sizeof(int));
GkFileSystem::WriteVirtualFileSystem(fullSearchSubDir.c_str(), fileStream);
int endPos = (int)fileStream->tellp();
chunkSize = endPos - chunkSizePos - 4;
fileStream->seekp(chunkSizePos);
fileStream->write((char*)&chunkSize, sizeof(int));
fileStream->seekp(endPos);
}
}
else
{
std::wstring fullFileName(directory);
fullFileName.append(L"\\");
fullFileName.append(findData.cFileName);
GkFileSystem::WriteString(findData.cFileName, fileStream);
chunkSizePos = (int)fileStream->tellp();
fileStream->write((char*)&chunkSize, sizeof(int));
GkFileSystem::WriteFile(fullFileName.c_str(), fileStream);
int endPos = (int)fileStream->tellp();
chunkSize = endPos - chunkSizePos - 4;
fileStream->seekp(chunkSizePos);
fileStream->write((char*)&chunkSize, sizeof(int));
fileStream->seekp(endPos);
}
}
while (FindNextFileW(findHandle, &findData) != 0);
FindClose(findHandle);
}
void GkFileSystem::WriteString(const wchar_t* s, std::ofstream* fileStream)
{
int l = 0;
while (s[l] != 0)
l++;
fileStream->write((char*)&l, sizeof(int));
fileStream->write((char*)s, l * sizeof(wchar_t));
}
void GkFileSystem::WriteFile(const wchar_t* fileName, std::ofstream* fileStream)
{
std::ifstream file(fileName, std::ios::in | std::ios::binary);
const int bufferSize = 2048;
char buffer[bufferSize];
for (;;)
{
file.read(buffer, bufferSize);
fileStream->write(buffer, file.gcount());
if (!file)
break;
}
file.close();
}
@@ -0,0 +1,53 @@
#pragma once
#include "..\GkDefinitions.h"
#include <fstream>
#include <string>
enum FileSystemMode
{
FileSystemMode_Physical,
FileSystemMode_Virtual
};
class GKDLLCLASS GkFileSystem
{
private:
static class GKDLLCLASS Init
{
public:
Init(void);
~Init(void);
} init;
static std::wstring source;
//static wchar_t *source;
static FileSystemMode mode;
static wchar_t* ReadString(std::ifstream* fileStream);
static void WriteVirtualFileSystem(const wchar_t* directory, std::ofstream* fileStream);
static void WriteString(const wchar_t* s, std::ofstream* fileStream);
static void WriteFile(const wchar_t* fileName, std::ofstream* fileStream);
static bool LoadPhysicalFile(const wchar_t *fileName, void **fileData, unsigned int *fileSize);
static bool LoadVirtualFile(const wchar_t *fileName, void **fileData, unsigned int *fileSize);
public:
GkFileSystem(void);
~GkFileSystem(void);
// Sets the source and mode of the virtual file system.
// If mode is FileSystemMode_Virtual, the source should be the name of the file, containing the virtual file system. Such file can be produced by the CreateVirtualFileSystem method.
// If mode is FileSystemMode_Physical, the source can be a root directory for the game's resources. Usually, this root directory is used to create a virtual file system from.
static void SetSource(const wchar_t *source, FileSystemMode mode);
// Allocates memory in fileData and loads the requested file in it, returning the size of the file in fileSize
static bool LoadFile(const wchar_t *fileName, void **fileData, unsigned int *fileSize);
// Writes the contents of a directory and all its subdirectories into a virtual file with the given name. The file can then be used as a virtual file system file.
static void CreateVirtualFileSystem(const wchar_t* directory, const wchar_t* fileName);
};
@@ -0,0 +1,201 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkOSUtils.h"
#include <stdlib.h>
#include <time.h>
GkOSUtils::GkOSUtils(void)
{
}
GkOSUtils::~GkOSUtils(void)
{
}
void* GkOSUtils::GetMem(int size)
{
return malloc(size);
}
void GkOSUtils::FreeMem(void* data)
{
free(data);
}
void GkOSUtils::ZeroMem(void* data, int size)
{
memset(data, 0, size);
}
void GkOSUtils::CopyMem(void* destination, void* source, int size)
{
memcpy(destination, source, size);
}
int GkOSUtils::CompareMem(void* block1, void* block2, int size)
{
return memcmp(block1, block2, size);
}
long long GkOSUtils::GetPerformanceCounter()
{
LARGE_INTEGER result;
if (QueryPerformanceCounter(&result))
return result.QuadPart;
else
return -1;
}
long long GkOSUtils::GetPerformanceCounterFrequency()
{
LARGE_INTEGER result;
if (QueryPerformanceFrequency(&result))
return result.QuadPart;
else
return -1;
}
void GkOSUtils::ShowMessage(const char *text, HWND windowHandle)
{
MessageBox(windowHandle, text, "Message", MB_OK);
}
int GkOSUtils::GetScreenWidth()
{
return GetSystemMetrics(SM_CXSCREEN);
}
int GkOSUtils::GetScreenHeight()
{
return GetSystemMetrics(SM_CYSCREEN);
}
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
int *Count = (int*)dwData;
(*Count)++;
return TRUE;
}
int GkOSUtils::GetNumberOfScreens()
{
int Count = 0;
if (EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&Count))
return Count;
return -1;//signals an error
}
DateTime GkOSUtils::GetDateTime()
{
time_t currentTime;
time(&currentTime);
tm localTime;
localtime_s(&localTime, &currentTime);
DateTime result;
result.day = localTime.tm_mday;
result.month = 1 + localTime.tm_mon;
result.year = 1900 + localTime.tm_year;
result.hour = localTime.tm_hour;
result.minute = localTime.tm_min;
result.second = localTime.tm_sec;
return result;
}
bool GkOSUtils::SetDateTime(DateTime &dateTime)
{
SYSTEMTIME sysTime;
sysTime.wDay = dateTime.day;
sysTime.wMonth = dateTime.month;
sysTime.wYear = dateTime.year;
sysTime.wHour = dateTime.hour;
sysTime.wMinute = dateTime.minute;
sysTime.wSecond = dateTime.second;
sysTime.wMilliseconds = 0;
return SetLocalTime(&sysTime) != 0;
}
int GkOSUtils::GetSecondsElapsed(DateTime &since)
{
//TODO
DateTime now = GkOSUtils::GetDateTime();
return ((now.hour - since.hour) * 60 + (now.minute - since.minute)) * 60 + (now.second - since.second);
}
DateTime GkOSUtils::GetFileModificationDateTime(const wchar_t *fileName)
{
DateTime result;
HANDLE handle = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (handle != INVALID_HANDLE_VALUE)
{
FILETIME created, accessed, modified;
GetFileTime(handle, &created, &accessed, &modified);
FILETIME localFileTime;
FileTimeToLocalFileTime(&modified, &localFileTime);
SYSTEMTIME localTime;
FileTimeToSystemTime(&localFileTime, &localTime);
result.day = localTime.wDay;
result.month = localTime.wMonth;
result.year = localTime.wYear;
result.hour = localTime.wHour;
result.minute = localTime.wMinute;
result.second = localTime.wSecond;
}
CloseHandle(handle);
return result;
}
std::string GkOSUtils::GetApplicationName()
{
TCHAR buffer[MAX_PATH]={0};
GetModuleFileName(NULL, buffer, MAX_PATH);
return std::string(buffer);
}
std::string GkOSUtils::GetApplicationPath()
{
std::string applicationName = GkOSUtils::GetApplicationName();
int nameLength = applicationName.length();
char path[MAX_PATH];
int pathLast = 0;
for (int i = 0; i < nameLength; i++)
{
path[i] = applicationName[i];
if (path[i] == '\\')
pathLast = i;
}
path[pathLast + 1] = 0;
return std::string(path);
}
void GkOSUtils::Execute(const char *command)
{
ShellExecuteA(GetDesktopWindow(), "open", command, NULL, NULL, SW_SHOWNORMAL);
}
@@ -0,0 +1,47 @@
#pragma once
#include "..\GkDefinitions.h"
#include <windows.h>
#include <string>
struct DateTime
{
int day, month, year,
hour, minute, second;
};
class GKDLLCLASS GkOSUtils
{
public:
GkOSUtils(void);
~GkOSUtils(void);
static void* GkOSUtils::GetMem(int size);
static void GkOSUtils::FreeMem(void* data);
static void GkOSUtils::ZeroMem(void* data, int size);
static void GkOSUtils::CopyMem(void* destination, void* source, int size);
static int GkOSUtils::CompareMem(void* block1, void* block2, int size);
static long long GkOSUtils::GetPerformanceCounter();
static long long GkOSUtils::GetPerformanceCounterFrequency();
static void GkOSUtils::ShowMessage(const char *text, HWND windowHandle = 0);
static int GetScreenWidth();
static int GetScreenHeight();
static int GetNumberOfScreens();
static DateTime GetDateTime();
static bool SetDateTime(DateTime &dateTime);
static int GetSecondsElapsed(DateTime &since);
static DateTime GetFileModificationDateTime(const wchar_t *fileName);
static std::string GetApplicationName();
static std::string GetApplicationPath();
static void Execute(const char *command);
};
@@ -0,0 +1,87 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkOpenGLWindowsForm.h"
GkOpenGLWindowsForm::GkOpenGLWindowsForm(HGLRC renderContext)
{
PIXELFORMATDESCRIPTOR d =
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
this->pixelFormatDescriptor = d;
this->CreateContext(renderContext);
}
GkOpenGLWindowsForm::~GkOpenGLWindowsForm(void)
{
}
bool GkOpenGLWindowsForm::CreateContext(HGLRC renderContext)
{
this->deviceContext = GetDC(this->handle);
if (this->deviceContext == 0)
return false;
this->pixelFormat = ChoosePixelFormat(this->deviceContext, &this->pixelFormatDescriptor);
if (this->pixelFormat == 0)
return false;
if(!SetPixelFormat(this->deviceContext, this->pixelFormat, &this->pixelFormatDescriptor))
return false;
if (renderContext == 0)
{
this->renderContext = wglCreateContext(this->deviceContext);
if (this->renderContext == 0)
return false;
}
else
{
this->renderContext = renderContext;
}
if (!this->MakeCurrent())
return false;
return true;
}
bool GkOpenGLWindowsForm::Present()
{
return SwapBuffers(this->deviceContext) != 0;
}
bool GkOpenGLWindowsForm::MakeCurrent()
{
return wglMakeCurrent(this->deviceContext, this->renderContext) != 0;
}
@@ -0,0 +1,24 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkWindowsForm.h"
class GKDLLCLASS GkOpenGLWindowsForm :
public GkWindowsForm
{
public:
HDC deviceContext;
HGLRC renderContext;
PIXELFORMATDESCRIPTOR pixelFormatDescriptor;
unsigned int pixelFormat;
GkOpenGLWindowsForm(HGLRC renderContext = 0);
virtual ~GkOpenGLWindowsForm(void);
bool GkOpenGLWindowsForm::CreateContext(HGLRC renderContext = 0);
bool GkOpenGLWindowsForm::Present();
bool GkOpenGLWindowsForm::MakeCurrent();
};
@@ -0,0 +1,397 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkWindowsForm.h"
#include <windowsx.h>
const char* GkWindowsForm::FormClassName = "MyWindowsForm";
//std::vector<GkWindowsForm*> GkWindowsForm::instances;
GkList<GkWindowsForm*> GkWindowsForm::instances;
LRESULT CALLBACK GkWindowsForm::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
GkWindowsForm* instance = GkWindowsForm::GetInstance(hWnd);
if (instance != NULL)
{
switch (uMsg)
{
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
{
if (instance->suppressScreenSaver)
return 0;
}
case SC_MONITORPOWER:
{
if (instance->suppressMonitorPowerSave)
return 0;
}
}
break;
}
case WM_ACTIVATE:
{
// Minimization state
if (!HIWORD(wParam))
{
instance->active=TRUE;
}
else
{
instance->active=FALSE;
}
return 0;
}
case WM_DESTROY:
{
if (instance->Close())
{
GkWindowsForm::instances.Remove(instance);
if (GkWindowsForm::instances.size == 0)
PostQuitMessage(0);
}
return 0;
}
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
instance->Resize(width, height);
return 0;
}
case WM_PAINT:
{
if (instance->Paint())
{
ValidateRect(instance->handle, NULL);
}
return 0;
}
case WM_KEYDOWN:
{
int key = wParam;
instance->KeyDown(key);
if ((key >=0 ) && (key < 256))
instance->keys[key] = TRUE;
return 0;
}
case WM_KEYUP:
{
int key = wParam;
instance->KeyUp(key);
if ((key >=0 ) && (key < 256))
instance->keys[key] = FALSE;
return 0;
}
case WM_LBUTTONDOWN:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseDown(x, y, GkWindowsForm::MouseButton_Left);
instance->mouseButtons |= GkWindowsForm::MouseButton_Left;
return 0;
}
case WM_LBUTTONUP:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseUp(x, y, GkWindowsForm::MouseButton_Left);
instance->mouseButtons &= !GkWindowsForm::MouseButton_Left;
return 0;
}
case WM_RBUTTONDOWN:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseDown(x, y, GkWindowsForm::MouseButton_Right);
instance->mouseButtons |= GkWindowsForm::MouseButton_Right;
return 0;
}
case WM_RBUTTONUP:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseUp(x, y, GkWindowsForm::MouseButton_Right);
instance->mouseButtons &= !GkWindowsForm::MouseButton_Right;
return 0;
}
case WM_MBUTTONDOWN:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseDown(x, y, GkWindowsForm::MouseButton_Middle);
instance->mouseButtons |= GkWindowsForm::MouseButton_Middle;
return 0;
}
case WM_MBUTTONUP:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseUp(x, y, GkWindowsForm::MouseButton_Middle);
instance->mouseButtons &= !GkWindowsForm::MouseButton_Middle;
return 0;
}
case WM_MOUSEMOVE:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
instance->MouseMove(x, y);
instance->mouseX = x;
instance->mouseY = y;
return 0;
}
case WM_MOUSEHWHEEL:
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
int deltaFactor = GET_WHEEL_DELTA_WPARAM(wParam);
instance->MouseWheel(x, y, deltaFactor, WHEEL_DELTA);
return 0;
}
}
int result;
if (instance->HandleMessage(uMsg, wParam, lParam, &result))
return result;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
GkWindowsForm* GkWindowsForm::GetInstance(HWND instanceHandle)
{
for (int i = 0; i < GkWindowsForm::instances.size; i++)
{
if (GkWindowsForm::instances[i]->handle == instanceHandle)
{
return GkWindowsForm::instances[i];
}
}
return NULL;
}
bool GkWindowsForm::ProcessMessages()
{
MSG msg;
bool result = false;
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
result = true;
}
return result;
}
int GkWindowsForm::PerformFormLoop()
{
MSG msg;
bool done = false;
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message == WM_QUIT) // Have We Received A Quit Message?
{
done = true; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
if (!done)
{
for (int i = 0; i < GkWindowsForm::instances.size; i++)
{
GkWindowsForm::instances[i]->MainLoop();
}
}
}
return (int)msg.wParam;
//while (GetMessage(&msg, NULL, 0, 0))
// {
// TranslateMessage(&msg);
// DispatchMessage(&msg);
// }
// return (int)msg.wParam;
}
GkWindowsForm::GkWindowsForm(void)
{
this->applicationInstance = GetModuleHandle(NULL);
ZeroMemory(keys, 256);
this->left = 0;
this->top = 0;
this->width = 640;
this->height = 480;
this->caption = "Window Title";
//this->windowMode = GkWindowsForm::WindowMode_Windowed;
this->windowMode = GkWindowsForm::WindowMode_FullScreen;
GkWindowsForm::instances.Add(this);
//GkWindowsForm::instances.push_back(this);
this->RegisterWindowClass();
this->CreateFormWindow();
this->ShowFormWindow();
}
GkWindowsForm::~GkWindowsForm(void)
{
this->DestroyFormWindow();
//GkWindowsForm::instances.Remove(this);
//if (GkWindowsForm::instances.size == 0)
// PostMessage(this->handle, WM_CLOSE, 0, 0);
}
bool GkWindowsForm::RegisterWindowClass()
{
//LRESULT (CALLBACK GkWindowsForm::*memfun)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//memfun = &GkWindowsForm::WndProc;
//this->ex.lpfnWndProc = *((WNDPROC*) (&memfun));
this->windowClass.cbSize = sizeof(WNDCLASSEX);
this->windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
this->windowClass.lpfnWndProc = (WNDPROC)GkWindowsForm::WndProc;
this->windowClass.cbClsExtra = 0;
this->windowClass.cbWndExtra = 0;
this->windowClass.hInstance = this->applicationInstance;
this->windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
this->windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
this->windowClass.hbrBackground = NULL;
this->windowClass.lpszMenuName = NULL;
this->windowClass.hIconSm = NULL;
this->windowClass.lpszClassName = GkWindowsForm::FormClassName;
return RegisterClassEx(&this->windowClass) != 0;
}
bool GkWindowsForm::CreateFormWindow()
{
long wndStyle = this->windowMode == GkWindowsForm::WindowMode_FullScreen ? WS_POPUP : WS_OVERLAPPEDWINDOW;
wndStyle |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
// Translate from client rect to window rect
RECT wRect = { this->left, this->top, this->left + this->width, this->top + this->height };
AdjustWindowRect(&wRect, wndStyle, false);
this->handle = CreateWindow(GkWindowsForm::FormClassName, this->caption,
wndStyle,
this->left, this->top, wRect.right - wRect.left, wRect.bottom - wRect.top,
NULL, NULL,
this->applicationInstance,
NULL);
return this->handle != 0;
}
void GkWindowsForm::ShowFormWindow()
{
ShowWindow(this->handle,SW_SHOW);
//UpdateWindow(this->handle);
SetForegroundWindow(this->handle); // Slightly Higher Priority
SetFocus(this->handle); // Sets Keyboard Focus To The Window
}
void GkWindowsForm::DestroyFormWindow()
{
PostMessage(this->handle, WM_DESTROY, 0, 0);
}
void GkWindowsForm::SetPosition(int left, int top)
{
this->left = left;
this->top = top;
SetWindowPos(this->handle, HWND_TOP, this->left, this->top, this->width, this->height, SWP_NOSIZE);
}
void GkWindowsForm::SetSize(int width, int height)
{
this->width = width;
this->height = height;
SetWindowPos(this->handle, HWND_TOP, this->left, this->top, this->width, this->height, SWP_NOMOVE);
}
void GkWindowsForm::SetStyle()
{
SetWindowLong(this->handle, GWL_STYLE, WS_POPUP | WS_MINIMIZEBOX);
SetWindowLong(this->handle, GWL_EXSTYLE, 0);
//SetWindowLong(this->handle, GWL_STYLE, WS_POPUP);
//SetWindowLong(this->handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
}
void GkWindowsForm::SetActive()
{
SetActiveWindow(this->handle);
}
@@ -0,0 +1,71 @@
#pragma once
#include "..\GkDefinitions.h"
#include "..\Utils\GkList.h"
//#include <vector>
#include <windows.h>
class GKDLLCLASS GkWindowsForm
{
public:
static const int WindowMode_Windowed = 0,
WindowMode_FullScreen = 1,
MouseButton_None = 0,
MouseButton_Left = 1,
MouseButton_Right = 2,
MouseButton_Middle = 4;
static const char* FormClassName;
static GkList<GkWindowsForm*> instances;
//static std::vector<GkWindowsForm*> instances;
HINSTANCE applicationInstance;
WNDCLASSEX windowClass;
HWND handle;
bool keys[256];
int mouseX, mouseY, mouseButtons;
bool suppressScreenSaver, suppressMonitorPowerSave;
bool active;
int windowMode;
int left, top, width, height;
char *caption;
GkWindowsForm(void);
virtual ~GkWindowsForm(void);
bool GkWindowsForm::RegisterWindowClass();
bool GkWindowsForm::CreateFormWindow();
void GkWindowsForm::ShowFormWindow();
void GkWindowsForm::DestroyFormWindow();
void GkWindowsForm::SetPosition(int left, int top);
void GkWindowsForm::SetSize(int width, int height);
void GkWindowsForm::SetStyle();
void GkWindowsForm::SetActive();
virtual bool GkWindowsForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, int *result) { return false; };
virtual void GkWindowsForm::MainLoop() { };
virtual void GkWindowsForm::Created() { };
virtual bool GkWindowsForm::Close() { return true; };
virtual bool GkWindowsForm::Paint() { return true; };
virtual void GkWindowsForm::KeyDown(int keyCode) { };
virtual void GkWindowsForm::KeyUp(int keyCode) { };
virtual void GkWindowsForm::Resize(int width, int height) { };
virtual void GkWindowsForm::MouseMove(int x, int y) { };
virtual void GkWindowsForm::MouseDown(int x, int y, int mouseButton) { };
virtual void GkWindowsForm::MouseUp(int x, int y, int mouseButton) { };
virtual void GkWindowsForm::MouseWheel(int x, int y, int deltaFactor, int delta) { };
static LRESULT CALLBACK GkWindowsForm::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static GkWindowsForm* GkWindowsForm::GetInstance(HWND instanceHandle);
static bool GkWindowsForm::ProcessMessages();
static int GkWindowsForm::PerformFormLoop();
};
@@ -0,0 +1,36 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkWindowsMutex.h"
GkWindowsMutex::GkWindowsMutex(void)
{
this->handle = CreateMutex(NULL, FALSE, NULL);
}
GkWindowsMutex::~GkWindowsMutex(void)
{
if(this->handle != NULL)
CloseHandle(this->handle);
}
bool GkWindowsMutex::Lock()
{
return WaitForSingleObject(this->handle, INFINITE) == WAIT_OBJECT_0;
}
void GkWindowsMutex::Unlock()
{
ReleaseMutex(this->handle);
}
@@ -0,0 +1,18 @@
#pragma once
#include "..\GkDefinitions.h"
#include <windows.h>
class GKDLLCLASS GkWindowsMutex
{
public:
HANDLE handle;
GkWindowsMutex(void);
~GkWindowsMutex(void);
bool Lock();
void Unlock();
};
@@ -0,0 +1,50 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkWindowsThread.h"
DWORD WINAPI GkWindowsThread::ExecuteThread(LPVOID lpParam)
{
GkWindowsThread *instance = (GkWindowsThread*)lpParam;
int result = instance->Execute();
instance->exited = true;
return result;
}
void GkWindowsThread::SleepX(int milliseconds)
{
Sleep(milliseconds);
}
GkWindowsThread::GkWindowsThread(void)
{
this->handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) GkWindowsThread::ExecuteThread, this, 0, &this->id);
this->terminated = this->handle == NULL;
this->exited = terminated;
}
GkWindowsThread::~GkWindowsThread(void)
{
if(this->handle == NULL)
return;
this->terminated = true;
while (!this->exited)
Sleep(0);
CloseHandle(this->handle);
}
@@ -0,0 +1,26 @@
#pragma once
#include "..\GkDefinitions.h"
#include <windows.h>
class GKDLLCLASS GkWindowsThread
{
public:
HANDLE handle;
DWORD id;
bool terminated, exited;
GkWindowsThread(void);
virtual ~GkWindowsThread(void);
virtual int Execute() = 0;
void Lock();
void Unlock();
static void SleepX(int milliseconds);
static DWORD WINAPI ExecuteThread(LPVOID lpParam);
};
@@ -0,0 +1,67 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkSoundDevice.h"
#include <AL\alut.h>
#include <AL\al.h>
void GkSoundDevice::Initialize()
{
alutInit(0, 0);
}
void GkSoundDevice::Close()
{
alutExit();
}
GkSoundDevice::GkSoundDevice(int volume)
{
this->volume = volume;
}
GkSoundDevice::~GkSoundDevice(void)
{
}
bool GkSoundDevice::IsPlaying(GkSoundSource *soundSource)
{
ALenum state;
alGetSourcei(soundSource->handle, AL_SOURCE_STATE, &state);
return (state == AL_PLAYING);
}
void GkSoundDevice::PlaySource(GkSoundSource *soundSource)
{
alSourcei (soundSource->handle, AL_LOOPING, AL_FALSE);
alSourcef (soundSource->handle, AL_GAIN, this->volume / 10.0f);
alSourcePlay(soundSource->handle);
}
void GkSoundDevice::PlaySourceLooping(GkSoundSource *soundSource)
{
alSourcei (soundSource->handle, AL_LOOPING, AL_TRUE);
alSourcePlay(soundSource->handle);
}
void GkSoundDevice::PauseSource(GkSoundSource *soundSource)
{
alSourcePause(soundSource->handle);
}
void GkSoundDevice::StopSource(GkSoundSource *soundSource)
{
alSourceStop(soundSource->handle);
}
@@ -0,0 +1,23 @@
#pragma once
#include "..\GkDefinitions.h"
#include "GkSoundSource.h"
class GKDLLCLASS GkSoundDevice
{
public:
int volume;
static void Initialize();
static void Close();
GkSoundDevice(int volume = 100);
~GkSoundDevice(void);
bool IsPlaying(GkSoundSource *soundSource);
void PlaySource(GkSoundSource *soundSource);
void PlaySourceLooping(GkSoundSource *soundSource);
void PauseSource(GkSoundSource *soundSource);
void StopSource(GkSoundSource *soundSource);
};
@@ -0,0 +1,87 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkSoundSource.h"
#include <string>
#include <AL\alut.h>
#pragma pack(1)
struct WAVFileHeader
{
char chunkID[4]; // "RIFF"
unsigned int chunkSize;
char format[4]; // "WAVE"
char subchunk1Id[4]; // "fmt "
unsigned int subchunk1Size;
unsigned short audioFormat; // 1 - PCM
unsigned short numChannels; // 1 - mono, 2 - stereo
unsigned int sampleRate; // 22050, 44100, etc.
unsigned int byteRate; // == SampleRate * NumChannels * BitsPerSample / 8
unsigned short blockAlign; // == NumChannels * BitsPerSample / 8. The number of bytes for one sample including
unsigned short bitsPerSample; // 8, 16, etc.
//unsigned short extraParamsSize; //if PCM does not exist
//extraParams; //variable format
//char subchunk2Id[4]; // "data"
//unsigned int subchunk2Size;
};
GkSoundSource::GkSoundSource(void)
{
alGenSources(1, &this->handle);
this->buffer = 0;
}
GkSoundSource::~GkSoundSource(void)
{
this->UnloadBuffer();
alDeleteSources(1, &this->handle);
}
void GkSoundSource::LoadFromMemory(void *wavData)
{
ALenum format;
ALvoid *data;
ALsizei size, frequency;
WAVFileHeader *header = (WAVFileHeader*)wavData;
int dataOffset = 20 + header->subchunk1Size;
while (memcmp((char*)&((char*)wavData)[dataOffset], &"data", 4) != 0)
{
dataOffset += *((int*)&(((char*)wavData)[dataOffset + 4])) + 8;
}
size = *((int*)&(((char*)wavData)[dataOffset + 4]));
data = (ALvoid*)&(((char*)wavData)[dataOffset + 8]);
format = header->numChannels == 1 ? header->bitsPerSample == 8 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16 : header->bitsPerSample == 8 ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16;
frequency = header->sampleRate;
this->UnloadBuffer();
alGenBuffers(1, &this->buffer);
alBufferData(this->buffer, format, data, size, frequency);
alSourcei(this->handle, AL_BUFFER, this->buffer);
}
void GkSoundSource::UnloadBuffer()
{
if (this->buffer == 0)
return;
alDeleteBuffers(1, &this->buffer);
this->buffer = 0;
}
@@ -0,0 +1,20 @@
#pragma once
#include "..\GkDefinitions.h"
#include <AL\al.h>
#include "..\Base\GkBase.h"
class GKDLLCLASS GkSoundSource
: public GkBase
{
public:
ALuint handle, buffer;
GkSoundSource::GkSoundSource(void);
GkSoundSource::~GkSoundSource(void);
void GkSoundSource::LoadFromMemory(void *data);
void GkSoundSource::UnloadBuffer();
};
@@ -0,0 +1,110 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "..\GkDefinitions.h"
#include "..\OSSpecific\GkOSUtils.h"
template <class GKDLLCLASS T> class GKDLLCLASS GkList
{
public:
static const int ListIndex_NotFound = -1;
int size, capacity;
T *values;
T& operator [](int index)
{
return this->values[index];
};
GkList::GkList(int capacity = 8)
{
this->capacity = 0;
this->size = 0;
this->values = 0;
this->Resize(capacity);
};
GkList::~GkList(void)
{
delete this->values;
};
void GkList::Resize(int newCapacity)
{
T *newValues = new T[newCapacity];
if (this->size > 0)
GkOSUtils::CopyMem(newValues, values, this->size * sizeof(T));
if (this->values != 0)
delete this->values;
this->values = newValues;
this->capacity = newCapacity;
};
T GkList::Add(T value)
{
if (this->size >= this->capacity)
this->Resize(this->capacity * 2);
this->values[this->size++] = value;
return value;
};
T GkList::Insert(T value, int index)
{
if (this->size >= this->capacity)
this->Resize(this->capacity * 2);
for (int i = this->size; i > index; i--)
this->values[i] = this->values[i - 1];
this->values[index] = value;
this->size++;
};
bool GkList::Remove(T value)
{
int index = this->IndexOf(value);
if (index != GkList::ListIndex_NotFound)
{
this->RemoveIndex(index);
return true;
}
return false;
};
void GkList::RemoveIndex(int index)
{
for (int i = index; i < this->size -1; i++)
this[i] = this[i + 1];
this->size--;
};
int GkList::IndexOf(T value)
{
for (int i = 0; i < this->size; i++)
if (this->values[i] == value)
return i;
return GkList::ListIndex_NotFound;
};
};
@@ -0,0 +1,71 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include "..\GkDefinitions.h"
#include "GkStrings.h"
#include <fstream>
template <class GKDLLCLASS T> class GKDLLCLASS GkLogFile
{
public:
wchar_t *fileName;
int numRecords;
GkLogFile(const wchar_t *fileName)
{
this->fileName = GkStrings::Copy(fileName);
std::fstream file(this->fileName, std::ios::in | std::ios::out | std::ios::binary | std::ios::ate);
this->numRecords = (int)file.tellp() / (int)sizeof(T);
file.close();
};
~GkLogFile(void)
{
if (this->fileName != 0)
delete[] this->fileName;
};
void Write(T &record)
{
std::fstream file(this->fileName, std::ios::in | std::ios::out | std::ios::binary | std::ios::ate);
file.write((char*)&record, sizeof(T));
file.close();
this->numRecords++;
};
bool Read(int recordIndex, T &record)
{
if (recordIndex >= this->numRecords)
return false;
std::fstream file(this->fileName, std::ios::in | std::ios::binary);
file.seekg(recordIndex * sizeof(T));
file.read((char*)&record, sizeof(T));
file.close();
return true;
};
void Clear()
{
std::fstream file(this->fileName, std::ios::out | std::ios::trunc);
file.close();
this->numRecords = 0;
};
};
@@ -0,0 +1,92 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkMaths.h"
#include <stdlib.h>
#include <time.h>
#include <cmath>
GkMaths::GkMaths(void)
{
}
GkMaths::~GkMaths(void)
{
}
int GkMaths::Min(int a, int b)
{
if (a < b)
return a;
return b;
}
int GkMaths::Max(int a, int b)
{
if (a > b)
return a;
return b;
}
float GkMaths::Max(float a, float b)
{
if (a > b)
return a;
return b;
}
int GkMaths::Trim(int x, int min, int max)
{
if (x < min)
return min;
if (x > max)
return max;
return x;
}
int GkMaths::Sign(int x)
{
return x > 0 ? 1 : x < 0 ? -1 : 0;
}
float GkMaths::Sign(float x)
{
return x > 0 ? 1.0f : x < 0 ? -1.0f : 0.0f;
}
float GkMaths::Abs(float x)
{
return x >= 0 ? x : -x;
}
int GkMaths::Abs(int x)
{
return x >= 0 ? x : -x;
}
int GkMaths::Random(int range)
{
return rand() % range;
}
void GkMaths::Randomize()
{
srand((unsigned int)time(NULL));
}
@@ -0,0 +1,23 @@
#pragma once
#include "..\GkDefinitions.h"
class GKDLLCLASS GkMaths
{
public:
GkMaths(void);
~GkMaths(void);
static int GkMaths::Trim(int x, int min, int max);
static int GkMaths::Min(int a, int b);
static int GkMaths::Max(int a, int b);
static float GkMaths::Max(float a, float b);
static int GkMaths::Sign(int x);
static float GkMaths::Sign(float x);
static float GkMaths::Abs(float x);
static int GkMaths::Abs(int x);
static int GkMaths::Random(int n);
static void GkMaths::Randomize();
};
@@ -0,0 +1,283 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GambleKit Copyright (C) 2014 Ivan Donev
//
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// contact: gamblekit@gmail.com
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "GkStrings.h"
#include <vector>
#include "..\OSSpecific\GkOSUtils.h"
GkStrings::GkStrings(void)
{
}
GkStrings::~GkStrings(void)
{
}
struct FormatStringChunk
{
bool isFormatter;
int start, length;
};
struct FormatStringChunks
{
std::vector<FormatStringChunk> chunks;
int numFormatterChunks;
};
FormatStringChunks GetFormatStringChunks(const wchar_t *formatString)
{
FormatStringChunks result;
result.numFormatterChunks = 0;
FormatStringChunk chunk;
chunk.isFormatter = false;
chunk.start = 0;
for (int i = 0; ; i++)
{
if (formatString[i] == L'{')
{
chunk.length = i - chunk.start;
if (chunk.length > 0)
result.chunks.push_back(chunk);
chunk.isFormatter = true;
chunk.start = i + 1;
}
else if (formatString[i] == L'}')
{
chunk.length = i - chunk.start;
if (chunk.length > 0)
{
result.chunks.push_back(chunk);
if (chunk.isFormatter)
result.numFormatterChunks++;
}
chunk.isFormatter = false;
chunk.start = i + 1;
}
else if (formatString[i] == 0)
{
chunk.length = i - chunk.start;
if (chunk.length > 0)
result.chunks.push_back(chunk);
break;
}
}
return result;
}
std::wstring GkStrings::Format(const wchar_t *formatString, ...)
{
wchar_t **parameters = (wchar_t**)((int)&formatString + 4);
return GkStrings::FormatArray(formatString, parameters);
}
std::wstring GkStrings::FormatArray(const wchar_t *formatString, wchar_t **parameters)
{
FormatStringChunks chunks = GetFormatStringChunks(formatString);
std::wstring result;
int numChunks = chunks.chunks.size();
for (int i = 0; i < numChunks; i++)
{
FormatStringChunk chunk = chunks.chunks[i];
if (chunk.isFormatter)
{
result.append(parameters[GkStrings::StringToInt(std::wstring(&formatString[chunk.start], chunk.length).c_str())]);
}
else
{
result.append(std::wstring(&formatString[chunk.start], chunk.length));
}
}
return result;
}
std::wstring GkStrings::IntToString(int value, int base, int digits, const wchar_t defaultDigit)
{
wchar_t s[256], result[256];
_itow_s(value, s, base);
int intLength = wcslen(s);
int extraDigits = digits > intLength ? digits - intLength : 0;
int resultLength = extraDigits > 0 ? digits : intLength;
for (int i = 0; i < resultLength; i++)
{
if (i < extraDigits)
result[i] = defaultDigit;
else
result[i] = s[i - extraDigits];
}
result[resultLength] = L'\0';
return std::wstring(result);
}
std::wstring GkStrings::FloatToString(float value, int fracDigits, int intDigits, const wchar_t defaultDigit)
{
int intPart = (int)value;
int fracPart = (int)((value - intPart) * pow(10.0f, fracDigits));
return GkStrings::Format(L"{0}.{1}", GkStrings::IntToString(intPart, 10, intDigits, defaultDigit).c_str(), GkStrings::IntToString(fracPart, 10, fracDigits, L'0').c_str());
}
int GkStrings::StringToInt(const wchar_t *string)
{
return _wtoi(string);
}
wchar_t *GkStrings::Copy(const wchar_t *string)
{
if (string == 0)
return 0;
int length = wcslen(string);
wchar_t *result = new wchar_t[length + 1];
memcpy(result, string, (length + 1) * 2);
return result;
}
char *GkStrings::Copy(const char *string)
{
if (string == 0)
return 0;
int length = strlen(string);
char *result = new char[length + 1];
memcpy(result, string, (length + 1));
return result;
}
void GkStrings::Dispose(wchar_t **string)
{
if (*string != 0)
{
delete[] *string;
string = 0;
}
}
int GkStrings::GetLength(const wchar_t *string)
{
return wcslen(string);
}
int GkStrings::GetLength(const char *string)
{
return strlen(string);
}
int GkStrings::SubChar(const wchar_t *string, const wchar_t subChar)
{
if (string == 0)
return -1;
for (int i = 0; *string != 0; i++)
{
if (*string++ == subChar)
{
return i;
}
}
return -1;
}
int GkStrings::Compare(const char *string1, const char *string2)
{
return strcmp(string1, string2);
}
int GkStrings::Compare(const wchar_t *string1, const wchar_t *string2)
{
return wcscmp(string1, string2);
}
std::wstring GkStrings::FormatDateTime(const wchar_t *formatString, DateTime &dateTime)
{
return std::wstring(GkStrings::Format(formatString, GkStrings::IntToString(dateTime.day, 10, 2).c_str(), GkStrings::IntToString(dateTime.month, 10, 2).c_str(), GkStrings::IntToString(dateTime.year, 10, 4).c_str(), GkStrings::IntToString(dateTime.hour, 10, 2).c_str(), GkStrings::IntToString(dateTime.minute, 10, 2).c_str(), GkStrings::IntToString(dateTime.second, 10, 2).c_str()));
}
std::wstring GkStrings::IntToDecimalString(int value, int numFractionDigits)
{
int fractionalFactor = 1;
for (int i = 0; i < numFractionDigits; i++)
fractionalFactor *= 10;
return GkStrings::Format(L"{0}.{1}", GkStrings::IntToString(value / fractionalFactor).c_str(), GkStrings::IntToString(value % fractionalFactor, 10, numFractionDigits).c_str());
}
std::wstring GkStrings::FromShort(const char *chars)
{
int length = GkStrings::GetLength(chars);
wchar_t *wide = new wchar_t[length + 1];
for (int i = 0; i < length; i++)
wide[i] = chars[i];
wide[length] = 0;
std::wstring result(wide);
delete[] wide;
return result;
}
std::wstring GkStrings::FromShort(const char *chars, int start, int length)
{
wchar_t *wide = new wchar_t[length + 1];
for (int i = 0; i < length; i++)
wide[i] = chars[start + i];
wide[length] = 0;
std::wstring result(wide);
delete[] wide;
return result;
}
std::string GkStrings::ToShort(const wchar_t *string)
{
int length = GkStrings::GetLength(string);
char *shortString = new char[length + 1];
for (int i = 0; i < length; i++)
shortString[i] = (char)string[i];
shortString[length] = 0;
std::string result(shortString);
delete[] shortString;
return result;
}
@@ -0,0 +1,35 @@
#pragma once
#include "..\GkDefinitions.h"
#include <string>
struct DateTime;
class GKDLLCLASS GkStrings
{
public:
GkStrings::GkStrings(void);
GkStrings::~GkStrings(void);
static std::wstring GkStrings::FromShort(const char *chars);
static std::wstring GkStrings::FromShort(const char *chars, int start, int length);
static std::string GkStrings::ToShort(const wchar_t *string);
static std::wstring GkStrings::Format(const wchar_t *formatString, ...);
static std::wstring GkStrings::FormatArray(const wchar_t *formatString, wchar_t **parameters);
static std::wstring GkStrings::IntToString(int value, int base = 10, int digits = 0, const wchar_t defaultDigit = L'0');
static int GkStrings::StringToInt(const wchar_t *string);
static std::wstring GkStrings::FloatToString(float value, int fracDigits, int intDigits = 0, const wchar_t defaultDigit = L'0');
static wchar_t *GkStrings::Copy(const wchar_t *string);
static char *GkStrings::Copy(const char *string);
static void GkStrings::Dispose(wchar_t **string);
static int GkStrings::GetLength(const wchar_t *string);
static int GkStrings::GetLength(const char *string);
static int GkStrings::SubChar(const wchar_t *string, const wchar_t subChar);
static int GkStrings::Compare(const char *string1, const char *string2);
static int GkStrings::Compare(const wchar_t *string1, const wchar_t *string2);
static std::wstring GkStrings::FormatDateTime(const wchar_t *formatString, DateTime &dateTime);
static std::wstring GkStrings::IntToDecimalString(int value, int numFractionDigits = 2);
};
+196
View File
@@ -0,0 +1,196 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E6093060-EA31-4FF3-9230-2E9CDF34C694}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>GambleKit</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LibraryPath>$(SolutionDir)lib\DevIL;$(SolutionDir)lib\AL;$(SolutionDir)lib\GL;$(SolutionDir)lib\vld\Win32;$(LibraryPath)</LibraryPath>
<IncludePath>$(SolutionDir)include;$(SolutionDir)\include\AL;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)include;$(SolutionDir)\include\AL;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)lib\DevIL;$(SolutionDir)lib\AL;$(SolutionDir)lib\GL;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>NotSet</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>glut32.lib;DevIL.lib;ILU.lib;ILUT.lib;OpenAL32.lib;alut.lib;vld.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>NotSet</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>glut32.lib;DevIL.lib;ILU.lib;ILUT.lib;OpenAL32.lib;alut.lib;vld.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Engine\Base\GkBase.cpp" />
<ClCompile Include="Engine\Base\GkBaseReelMap.cpp" />
<ClCompile Include="CustomGameLogic\CustomGame.cpp" />
<ClCompile Include="CustomGameLogic\Pages\MainPage.cpp" />
<ClCompile Include="CustomGameLogic\MainWindow.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameAnimationsSoundBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameButtonsBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameButtonsSoundBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameTextsDateTimeBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameTextsFormatBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameTextsFormatIntBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Bindings\GkGameTextsIntBinding.cpp" />
<ClCompile Include="Engine\Game\Entities\Buttons\GkGameAnimationButton.cpp" />
<ClCompile Include="Engine\Game\Entities\Buttons\GkGameCheckButton.cpp" />
<ClCompile Include="Engine\Game\Entities\Buttons\GkGameClickButton.cpp" />
<ClCompile Include="Engine\Game\Entities\GkGameAnimation.cpp" />
<ClCompile Include="Engine\Game\Entities\GkGameButton.cpp" />
<ClCompile Include="Engine\Game\Entities\GkGameReels.cpp" />
<ClCompile Include="Engine\Game\Entities\GkGameStreamingAnimation.cpp" />
<ClCompile Include="Engine\Game\Entities\GkGameText.cpp" />
<ClCompile Include="Engine\Game\GkGame.cpp" />
<ClCompile Include="Engine\Game\GkGameEntity.cpp" />
<ClCompile Include="Engine\Game\GkGamePage.cpp" />
<ClCompile Include="Engine\Game\GkGameReelModel.cpp" />
<ClCompile Include="Engine\Game\GkGameReelsCombinationGenerator.cpp" />
<ClCompile Include="Engine\Game\GkGameTimer.cpp" />
<ClCompile Include="Engine\Game\Entities\GkGameWinningCounter.cpp" />
<ClCompile Include="Engine\Game\GkGameWinningPotentialsAnalyzer.cpp" />
<ClCompile Include="Engine\Game\GkGameWinningsAnalyzer.cpp" />
<ClCompile Include="Engine\Game\GkGameWinningsModel.cpp" />
<ClCompile Include="Engine\Game\ReelModels\GkGameReelRandomModel.cpp" />
<ClCompile Include="Engine\Game\ReelModels\GkGameReelStripModel.cpp" />
<ClCompile Include="Engine\Graphics\GkAnimatedFont.cpp" />
<ClCompile Include="Engine\Graphics\GkAnimatedTexture.cpp" />
<ClCompile Include="Engine\Graphics\GkGraphicsDevice.cpp" />
<ClCompile Include="Engine\Graphics\GkImage.cpp" />
<ClCompile Include="Engine\Graphics\GkTexture.cpp" />
<ClCompile Include="CustomGameLogic\main.cpp" />
<ClCompile Include="Engine\OSSpecific\GkOpenGLWindowsForm.cpp" />
<ClCompile Include="Engine\OSSpecific\GkOSUtils.cpp" />
<ClCompile Include="Engine\OSSpecific\GkFileSystem.cpp" />
<ClCompile Include="Engine\OSSpecific\GkWindowsForm.cpp" />
<ClCompile Include="Engine\OSSpecific\GkWindowsMutex.cpp" />
<ClCompile Include="Engine\OSSpecific\GkWindowsThread.cpp" />
<ClCompile Include="Engine\Sound\GkSoundDevice.cpp" />
<ClCompile Include="Engine\Sound\GkSoundSource.cpp" />
<ClCompile Include="Engine\Utils\GkMaths.cpp" />
<ClCompile Include="Engine\Utils\GkStrings.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Engine\Base\GkBase.h" />
<ClInclude Include="Engine\Base\GkBaseReelMap.h" />
<ClInclude Include="CustomGameLogic\CustomGame.h" />
<ClInclude Include="CustomGameLogic\Pages\MainPage.h" />
<ClInclude Include="CustomGameLogic\MainWindow.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameAnimationsSoundBinding.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameButtonsBinding.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameButtonsSoundBinding.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameTextsDateTimeBinding.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameTextsFormatBinding.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameTextsFormatIntBinding.h" />
<ClInclude Include="Engine\Game\Entities\Bindings\GkGameTextsIntBinding.h" />
<ClInclude Include="Engine\Game\Entities\Buttons\GkGameAnimationButton.h" />
<ClInclude Include="Engine\Game\Entities\Buttons\GkGameCheckButton.h" />
<ClInclude Include="Engine\Game\Entities\Buttons\GkGameClickButton.h" />
<ClInclude Include="Engine\Game\Entities\GkGameAnimation.h" />
<ClInclude Include="Engine\Game\Entities\GkGameButton.h" />
<ClInclude Include="Engine\Game\Entities\GkGameReels.h" />
<ClInclude Include="Engine\Game\Entities\GkGameStreamingAnimation.h" />
<ClInclude Include="Engine\Game\Entities\GkGameText.h" />
<ClInclude Include="Engine\Game\GkGame.h" />
<ClInclude Include="Engine\Game\GkGameEntity.h" />
<ClInclude Include="Engine\Game\GkGamePage.h" />
<ClInclude Include="Engine\Game\GkGameReelModel.h" />
<ClInclude Include="Engine\Game\GkGameReelsCombinationGenerator.h" />
<ClInclude Include="Engine\Game\GkGameTimer.h" />
<ClInclude Include="Engine\Game\Entities\GkGameWinningCounter.h" />
<ClInclude Include="Engine\Game\GkGameWinningPotentialsAnalyzer.h" />
<ClInclude Include="Engine\Game\GkGameWinningsAnalyzer.h" />
<ClInclude Include="Engine\Game\GkGameWinningsModel.h" />
<ClInclude Include="Engine\Game\ReelModels\GkGameReelRandomModel.h" />
<ClInclude Include="Engine\Game\ReelModels\GkGameReelStripModel.h" />
<ClInclude Include="Engine\GkDefinitions.h" />
<ClInclude Include="Engine\Graphics\GkAnimatedFont.h" />
<ClInclude Include="Engine\Graphics\GkAnimatedTexture.h" />
<ClInclude Include="Engine\Graphics\GkGraphicsDevice.h" />
<ClInclude Include="Engine\Graphics\GkImage.h" />
<ClInclude Include="Engine\Graphics\GkTexture.h" />
<ClInclude Include="Engine\OSSpecific\GkOpenGLWindowsForm.h" />
<ClInclude Include="Engine\OSSpecific\GkOSUtils.h" />
<ClInclude Include="Engine\OSSpecific\GkFileSystem.h" />
<ClInclude Include="Engine\OSSpecific\GkWindowsForm.h" />
<ClInclude Include="Engine\OSSpecific\GkWindowsMutex.h" />
<ClInclude Include="Engine\OSSpecific\GkWindowsThread.h" />
<ClInclude Include="Engine\Sound\GkSoundDevice.h" />
<ClInclude Include="Engine\Sound\GkSoundSource.h" />
<ClInclude Include="Engine\Utils\GkList.h" />
<ClInclude Include="Engine\Utils\GkLogFile.h" />
<ClInclude Include="Engine\Utils\GkMaths.h" />
<ClInclude Include="Engine\Utils\GkStrings.h" />
<ClInclude Include="Engine\GambleKit.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\License.txt" />
<None Include="Intruduction.txt" />
<None Include="ReadMe.txt" />
<None Include="version.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loaded 100 of 174 files, more files were not shown because too many files have changed in this diff. Show more