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

+84 -2
View File
@@ -35,10 +35,19 @@ Partial Class Form1
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.GroupBox3 = New System.Windows.Forms.GroupBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.ListView1 = New System.Windows.Forms.ListView()
Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.ColumnHeader3 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.ColumnHeader4 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.GroupBox4 = New System.Windows.Forms.GroupBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.MenuStrip1.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.GroupBox3.SuspendLayout()
Me.GroupBox4.SuspendLayout()
Me.SuspendLayout()
'
'MenuStrip1
@@ -77,7 +86,7 @@ Partial Class Form1
'
Me.AboutToolStripMenuItem.Name = "AboutToolStripMenuItem"
Me.AboutToolStripMenuItem.ShortcutKeys = CType((System.Windows.Forms.Keys.Alt Or System.Windows.Forms.Keys.A), System.Windows.Forms.Keys)
Me.AboutToolStripMenuItem.Size = New System.Drawing.Size(152, 22)
Me.AboutToolStripMenuItem.Size = New System.Drawing.Size(145, 22)
Me.AboutToolStripMenuItem.Text = "&About"
'
'TextBox1
@@ -143,11 +152,75 @@ Partial Class Form1
Me.TextBox2.Size = New System.Drawing.Size(333, 20)
Me.TextBox2.TabIndex = 0
'
'ListView1
'
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4})
Me.ListView1.FullRowSelect = True
Me.ListView1.GridLines = True
Me.ListView1.LabelWrap = False
Me.ListView1.Location = New System.Drawing.Point(6, 19)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(550, 263)
Me.ListView1.Sorting = System.Windows.Forms.SortOrder.Ascending
Me.ListView1.TabIndex = 5
Me.ListView1.UseCompatibleStateImageBehavior = False
Me.ListView1.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "File Path"
Me.ColumnHeader1.Width = 110
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "File Size"
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Line:Col"
Me.ColumnHeader3.Width = 80
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Line Text"
Me.ColumnHeader4.Width = 285
'
'GroupBox4
'
Me.GroupBox4.Controls.Add(Me.ListView1)
Me.GroupBox4.Location = New System.Drawing.Point(12, 178)
Me.GroupBox4.Name = "GroupBox4"
Me.GroupBox4.Size = New System.Drawing.Size(562, 288)
Me.GroupBox4.TabIndex = 6
Me.GroupBox4.TabStop = False
Me.GroupBox4.Text = "Results"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(493, 472)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 7
Me.Button2.Text = "&Search"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(18, 472)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(75, 23)
Me.Button3.TabIndex = 8
Me.Button3.Text = "E&xit"
Me.Button3.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(587, 478)
Me.ClientSize = New System.Drawing.Size(587, 506)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.GroupBox4)
Me.Controls.Add(Me.GroupBox3)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
@@ -162,6 +235,7 @@ Partial Class Form1
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox3.ResumeLayout(False)
Me.GroupBox3.PerformLayout()
Me.GroupBox4.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
@@ -179,5 +253,13 @@ Partial Class Form1
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
Friend WithEvents GroupBox4 As System.Windows.Forms.GroupBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
End Class
+12 -1
View File
@@ -1,10 +1,21 @@
Public Class Form1
Protected searcher As PatternSearcher = New PatternSearcher
Protected searcher As PatternSearcher = New PatternSearcher()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Application.Exit()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End Sub
End Class
+9 -3
View File
@@ -2,9 +2,15 @@
Private _searchResults As SearchResults = New SearchResults
Public FileType As String
Public IsCaseSensitive As Boolean
Public Pattern As String
Public Property FileType As String
Public Property IsCaseSensitive As Boolean
Public Property Pattern As String
Sub New(FT As String, ICS As Boolean, P As String)
FileType = FT
IsCaseSensitive = ICS
Pattern = P
End Sub
Sub Search()
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFCApplication1", "MFCApplication1\MFCApplication1.vcxproj", "{EEB0848C-7330-4A27-96C6-6E979A1223CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EEB0848C-7330-4A27-96C6-6E979A1223CC}.Debug|Win32.ActiveCfg = Debug|Win32
{EEB0848C-7330-4A27-96C6-6E979A1223CC}.Debug|Win32.Build.0 = Debug|Win32
{EEB0848C-7330-4A27-96C6-6E979A1223CC}.Release|Win32.ActiveCfg = Release|Win32
{EEB0848C-7330-4A27-96C6-6E979A1223CC}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,90 @@
// MFCApplication1.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MFCApplication1.h"
#include "MFCApplication1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMFCApplication1App
BEGIN_MESSAGE_MAP(CMFCApplication1App, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CMFCApplication1App construction
CMFCApplication1App::CMFCApplication1App()
{
// support Restart Manager
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CMFCApplication1App object
CMFCApplication1App theApp;
// CMFCApplication1App initialization
BOOL CMFCApplication1App::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CMFCApplication1Dlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "Warning: dialog creation failed, so application is terminating unexpectedly.\n");
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
@@ -0,0 +1,32 @@
// MFCApplication1.h : main header file for the PROJECT_NAME application
//
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
// CMFCApplication1App:
// See MFCApplication1.cpp for the implementation of this class
//
class CMFCApplication1App : public CWinApp
{
public:
CMFCApplication1App();
// Overrides
public:
virtual BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
};
extern CMFCApplication1App theApp;
@@ -0,0 +1,128 @@
<?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>{EEB0848C-7330-4A27-96C6-6E979A1223CC}</ProjectGuid>
<RootNamespace>MFCApplication1</RootNamespace>
<Keyword>MFCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
</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>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<ValidateAllParameters>true</ValidateAllParameters>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="MFCApplication1.h" />
<ClInclude Include="MFCApplication1Dlg.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="MFCApplication1.cpp" />
<ClCompile Include="MFCApplication1Dlg.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MFCApplication1.rc" />
</ItemGroup>
<ItemGroup>
<None Include="res\MFCApplication1.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\MFCApplication1.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="MFCApplication1.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MFCApplication1Dlg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MFCApplication1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MFCApplication1Dlg.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MFCApplication1.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="res\MFCApplication1.rc2">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="res\MFCApplication1.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
@@ -0,0 +1,152 @@
// MFCApplication1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "MFCApplication1.h"
#include "MFCApplication1Dlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CMFCApplication1Dlg dialog
CMFCApplication1Dlg::CMFCApplication1Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CMFCApplication1Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
// CMFCApplication1Dlg message handlers
BOOL CMFCApplication1Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMFCApplication1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMFCApplication1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMFCApplication1Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
@@ -0,0 +1,32 @@
// MFCApplication1Dlg.h : header file
//
#pragma once
// CMFCApplication1Dlg dialog
class CMFCApplication1Dlg : public CDialogEx
{
// Construction
public:
CMFCApplication1Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MFCAPPLICATION1_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
};
@@ -0,0 +1,103 @@
================================================================================
MICROSOFT FOUNDATION CLASS LIBRARY : MFCApplication1 Project Overview
===============================================================================
The application wizard has created this MFCApplication1 application for
you. This application not only demonstrates the basics of using the Microsoft
Foundation Classes but is also a starting point for writing your application.
This file contains a summary of what you will find in each of the files that
make up your MFCApplication1 application.
MFCApplication1.vcxproj
This is the main project file for VC++ projects generated using an application wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
application wizard.
MFCApplication1.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
MFCApplication1.h
This is the main header file for the application. It includes other
project specific headers (including Resource.h) and declares the
CMFCApplication1App application class.
MFCApplication1.cpp
This is the main application source file that contains the application
class CMFCApplication1App.
MFCApplication1.rc
This is a listing of all of the Microsoft Windows resources that the
program uses. It includes the icons, bitmaps, and cursors that are stored
in the RES subdirectory. This file can be directly edited in Microsoft
Visual C++. Your project resources are in 1033.
res\MFCApplication1.ico
This is an icon file, which is used as the application's icon. This
icon is included by the main resource file MFCApplication1.rc.
res\MFCApplication1.rc2
This file contains resources that are not edited by Microsoft
Visual C++. You should place all resources not editable by
the resource editor in this file.
/////////////////////////////////////////////////////////////////////////////
The application wizard creates one dialog class:
MFCApplication1Dlg.h, MFCApplication1Dlg.cpp - the dialog
These files contain your CMFCApplication1Dlg class. This class defines
the behavior of your application's main dialog. The dialog's template is
in MFCApplication1.rc, which can be edited in Microsoft Visual C++.
/////////////////////////////////////////////////////////////////////////////
Other Features:
ActiveX Controls
The application includes support to use ActiveX controls.
Printing and Print Preview support
The application wizard has generated code to handle the print, print setup, and print preview
commands by calling member functions in the CView class from the MFC library.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named MFCApplication1.pch and a precompiled types file named StdAfx.obj.
Resource.h
This is the standard header file, which defines new resource IDs.
Microsoft Visual C++ reads and updates this file.
MFCApplication1.manifest
Application manifest files are used by Windows XP to describe an applications
dependency on specific versions of Side-by-Side assemblies. The loader uses this
information to load the appropriate assembly from the assembly cache or private
from the application. The Application manifest maybe included for redistribution
as an external .manifest file that is installed in the same folder as the application
executable or it may be included in the executable in the form of a resource.
/////////////////////////////////////////////////////////////////////////////
Other notes:
The application wizard uses "TODO:" to indicate parts of the source code you
should add to or customize.
If your application uses MFC in a shared DLL, you will need
to redistribute the MFC DLLs. If your application is in a language
other than the operating system's locale, you will also have to
redistribute the corresponding localized resources mfc110XXX.DLL.
For more information on both of these topics, please see the section on
redistributing Visual C++ applications in MSDN documentation.
/////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,21 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MFCApplication1.rc
//
#define IDR_MAINFRAME 128
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_MFCAPPLICATION1_DIALOG 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// MFCApplication1.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
@@ -0,0 +1,55 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS // remove support for MFC controls in dialogs
// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxcontrolbars.h> // MFC support for ribbons and control bars
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
@@ -0,0 +1,8 @@
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
+46 -9
View File
@@ -1,4 +1,5 @@
#pragma once
#include "stdafx.h"
#include "LottoBall.h"
namespace Project4
@@ -43,12 +44,19 @@ namespace Project4
private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox1;
public: System::Windows::Forms::TextBox^ textBox6;
private:
public: System::Windows::Forms::TextBox^ textBox5;
public: System::Windows::Forms::TextBox^ textBox4;
public: System::Windows::Forms::TextBox^ textBox3;
public: System::Windows::Forms::TextBox^ textBox2;
public: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label4;
@@ -225,6 +233,7 @@ namespace Project4
//
// radioButton1
//
this->radioButton1->AutoCheck = false;
this->radioButton1->AutoSize = true;
this->radioButton1->Location = System::Drawing::Point(51, 86);
this->radioButton1->Name = L"radioButton1";
@@ -394,7 +403,35 @@ namespace Project4
#pragma endregion
public: List<LottoBall^>^ balls;
public: volatile static array<int>^ numbers;
public: static array<int>^ numbers;
public: System::Void affixNumber(int index, int number)
{
this->numbers[index] = number;
switch (index)
{
case 0:
textBox5->Text = number.ToString("D2");
break;
case 1:
textBox4->Text = number.ToString("D2");
break;
case 2:
textBox4->Text = number.ToString("D2");
break;
case 3:
textBox3->Text = number.ToString("D2");
break;
case 4:
textBox2->Text = number.ToString("D2");
break;
case 5:
textBox1->Text = number.ToString("D2");
break;
case 6:
textBox6->Text = number.ToString("D2");
break;
}
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
@@ -403,10 +440,10 @@ namespace Project4
for (int i = 0; i < 5; i++)
{
balls->Add(gcnew LottoBall(1, 75));
balls->Add(gcnew LottoBall(1, 75, this));
}
balls->Add(gcnew LottoBall(1, 15));
balls->Add(gcnew LottoBall(1, 15, this));
}
private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
+30 -25
View File
@@ -1,35 +1,40 @@
#pragma once
#include "stdafx.h"
#include "Form1.h"
namespace Project4
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::Threading;
using namespace System::Threading::Tasks;
using namespace System::Data;
using namespace Project4;
public ref class LottoBall
{
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::Threading;
using namespace System::Threading::Tasks;
using namespace System::Data;
public ref class LottoBall
{
public:
LottoBall(int minval, int maxval, Form1^ form1);
~LottoBall();
public:
LottoBall(int minval, int maxval);
~LottoBall();
int getCurrentValue();
int num;
int getCurrentValue();
int num;
System::Void start();
System::Void stop();
System::Void initThread();
System::Void start();
System::Void stop();
private:
int minVal;
int maxVal;
int seedValue;
private:
int minVal;
int maxVal;
Form1^ formptr;
bool threadStop;
Thread^ thread;
System::Void run();
Random^ r;
};
bool threadStop;
Thread^ thread;
System::Void run();
}
};
+45 -40
View File
@@ -1,54 +1,59 @@
#include "LottoBall.h"
#include "Form1.h"
namespace Project4
LottoBall::LottoBall(int minval, int maxval, Form1^ form1)
{
minVal = minval;
maxVal = maxval;
LottoBall::LottoBall(int minval, int maxval)
threadStop = false;
num = 0;
formptr = form1;
}
LottoBall::~LottoBall()
{
thread->Abort();
}
System::Void LottoBall::initThread()
{
r = gcnew Random();
long long seed = 0;
for(int i = 0; i < 100; ++i)
{
minVal = minval;
maxVal = maxval;
threadStop = false;
num = 0;
thread = gcnew Thread(gcnew ThreadStart(&run));
seed += r->Next(i, 9999 + i);
}
r = gcnew Random(seed);
thread = gcnew Thread(gcnew ThreadStart(&this->run));
}
LottoBall::~LottoBall()
System::Void LottoBall::run()
{
String^ threadname = Thread::CurrentThread->Name;
int id = 0;
Int32::TryParse(threadname, id);
while (!this->threadStop)
{
thread->Abort();
this->num = r->Next(minVal, maxVal);
formptr->affixNumber(id, this->num);
}
}
System::Void LottoBall::run()
{
Random^ r = gcnew Random();
String^ threadname = Thread::CurrentThread->Name;
int id = 0;
Int32::TryParse(threadname, id);
int LottoBall::getCurrentValue()
{
return this->num;
}
while (!this->threadStop)
{
this->num = r->Next(minVal, maxVal);
Form1::numbers[id] = this->num;
}
}
int LottoBall::getCurrentValue()
{
return this->num;
}
System::Void LottoBall::start()
{
this->threadStop = false;
thread->Start();
}
System::Void LottoBall::stop()
{
this->threadStop = true;
}
System::Void LottoBall::start()
{
this->threadStop = false;
thread->Start();
}
System::Void LottoBall::stop()
{
this->threadStop = true;
}
+20
View File
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GambleKit", "GambleKit\GambleKit.vcxproj", "{E6093060-EA31-4FF3-9230-2E9CDF34C694}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E6093060-EA31-4FF3-9230-2E9CDF34C694}.Debug|Win32.ActiveCfg = Debug|Win32
{E6093060-EA31-4FF3-9230-2E9CDF34C694}.Debug|Win32.Build.0 = Debug|Win32
{E6093060-EA31-4FF3-9230-2E9CDF34C694}.Release|Win32.ActiveCfg = Release|Win32
{E6093060-EA31-4FF3-9230-2E9CDF34C694}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -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();
}
Loaded 100 of 174 files, more files were not shown because too many files have changed in this diff. Show more