mirror of https://github.com/buggins/dlangui.git
fix Tetris example - falling after full rows removing - #94
This commit is contained in:
parent
68c6dbef03
commit
d33b5d1c93
|
@ -0,0 +1,159 @@
|
|||
/***********************************************************************\
|
||||
* psapi.d *
|
||||
* *
|
||||
* Windows API header module *
|
||||
* *
|
||||
* Translated from MinGW Windows headers *
|
||||
* *
|
||||
* Placed into public domain *
|
||||
\***********************************************************************/
|
||||
/* Comment from MinGW
|
||||
* Process status API (PSAPI)
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms684884.aspx
|
||||
*/
|
||||
|
||||
module win32.psapi;
|
||||
version(Windows):
|
||||
|
||||
private import win32.w32api;
|
||||
private import win32.winbase;
|
||||
private import win32.windef;
|
||||
|
||||
struct MODULEINFO {
|
||||
LPVOID lpBaseOfDll;
|
||||
DWORD SizeOfImage;
|
||||
LPVOID EntryPoint;
|
||||
}
|
||||
alias MODULEINFO* LPMODULEINFO;
|
||||
|
||||
struct PSAPI_WS_WATCH_INFORMATION {
|
||||
LPVOID FaultingPc;
|
||||
LPVOID FaultingVa;
|
||||
}
|
||||
alias PSAPI_WS_WATCH_INFORMATION* PPSAPI_WS_WATCH_INFORMATION;
|
||||
|
||||
struct PSAPI_WS_WATCH_INFORMATION_EX {
|
||||
PSAPI_WS_WATCH_INFORMATION BasicInfo;
|
||||
ULONG_PTR FaultingThreadId;
|
||||
ULONG_PTR Flags;
|
||||
}
|
||||
alias PSAPI_WS_WATCH_INFORMATION_EX* PPSAPI_WS_WATCH_INFORMATION_EX;
|
||||
|
||||
struct PROCESS_MEMORY_COUNTERS {
|
||||
DWORD cb;
|
||||
DWORD PageFaultCount;
|
||||
DWORD PeakWorkingSetSize;
|
||||
DWORD WorkingSetSize;
|
||||
DWORD QuotaPeakPagedPoolUsage;
|
||||
DWORD QuotaPagedPoolUsage;
|
||||
DWORD QuotaPeakNonPagedPoolUsage;
|
||||
DWORD QuotaNonPagedPoolUsage;
|
||||
DWORD PagefileUsage;
|
||||
DWORD PeakPagefileUsage;
|
||||
}
|
||||
alias PROCESS_MEMORY_COUNTERS* PPROCESS_MEMORY_COUNTERS;
|
||||
|
||||
struct PERFORMANCE_INFORMATION {
|
||||
DWORD cb;
|
||||
SIZE_T CommitTotal;
|
||||
SIZE_T CommitLimit;
|
||||
SIZE_T CommitPeak;
|
||||
SIZE_T PhysicalTotal;
|
||||
SIZE_T PhysicalAvailable;
|
||||
SIZE_T SystemCache;
|
||||
SIZE_T KernelTotal;
|
||||
SIZE_T KernelPaged;
|
||||
SIZE_T KernelNonpaged;
|
||||
SIZE_T PageSize;
|
||||
DWORD HandleCount;
|
||||
DWORD ProcessCount;
|
||||
DWORD ThreadCount;
|
||||
}
|
||||
alias PERFORMANCE_INFORMATION* PPERFORMANCE_INFORMATION;
|
||||
|
||||
struct ENUM_PAGE_FILE_INFORMATION {
|
||||
DWORD cb;
|
||||
DWORD Reserved;
|
||||
SIZE_T TotalSize;
|
||||
SIZE_T TotalInUse;
|
||||
SIZE_T PeakUsage;
|
||||
}
|
||||
alias ENUM_PAGE_FILE_INFORMATION* PENUM_PAGE_FILE_INFORMATION;
|
||||
|
||||
/* application-defined callback function used with the EnumPageFiles()
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms682627.aspx */
|
||||
version (Unicode) {
|
||||
alias BOOL function(LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCWSTR)
|
||||
PENUM_PAGE_FILE_CALLBACK;
|
||||
} else {
|
||||
alias BOOL function(LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCSTR)
|
||||
PENUM_PAGE_FILE_CALLBACK;
|
||||
}
|
||||
|
||||
// Grouped by application, not in alphabetical order.
|
||||
extern (Windows) {
|
||||
/* Process Information
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms684870.aspx */
|
||||
BOOL EnumProcesses(DWORD*, DWORD, DWORD*); /* NT/2000/XP/Server2003/Vista/Longhorn */
|
||||
DWORD GetProcessImageFileNameA(HANDLE, LPSTR, DWORD); /* XP/Server2003/Vista/Longhorn */
|
||||
DWORD GetProcessImageFileNameW(HANDLE, LPWSTR, DWORD); /* XP/Server2003/Vista/Longhorn */
|
||||
|
||||
/* Module Information
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms684232.aspx */
|
||||
BOOL EnumProcessModules(HANDLE, HMODULE*, DWORD, LPDWORD);
|
||||
BOOL EnumProcessModulesEx(HANDLE, HMODULE*, DWORD, LPDWORD, DWORD); /* Vista/Longhorn */
|
||||
DWORD GetModuleBaseNameA(HANDLE, HMODULE, LPSTR, DWORD);
|
||||
DWORD GetModuleBaseNameW(HANDLE, HMODULE, LPWSTR, DWORD);
|
||||
DWORD GetModuleFileNameExA(HANDLE, HMODULE, LPSTR, DWORD);
|
||||
DWORD GetModuleFileNameExW(HANDLE, HMODULE, LPWSTR, DWORD);
|
||||
BOOL GetModuleInformation(HANDLE, HMODULE, LPMODULEINFO, DWORD);
|
||||
|
||||
/* Device Driver Information
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms682578.aspx */
|
||||
BOOL EnumDeviceDrivers(LPVOID*, DWORD, LPDWORD);
|
||||
DWORD GetDeviceDriverBaseNameA(LPVOID, LPSTR, DWORD);
|
||||
DWORD GetDeviceDriverBaseNameW(LPVOID, LPWSTR, DWORD);
|
||||
DWORD GetDeviceDriverFileNameA(LPVOID, LPSTR, DWORD);
|
||||
DWORD GetDeviceDriverFileNameW(LPVOID, LPWSTR, DWORD);
|
||||
|
||||
/* Process Memory Usage Information
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms684879.aspx */
|
||||
BOOL GetProcessMemoryInfo(HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
|
||||
|
||||
/* Working Set Information
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms687398.aspx */
|
||||
BOOL EmptyWorkingSet(HANDLE);
|
||||
BOOL GetWsChanges(HANDLE, PPSAPI_WS_WATCH_INFORMATION, DWORD);
|
||||
BOOL GetWsChangesEx(HANDLE, PPSAPI_WS_WATCH_INFORMATION_EX, DWORD); /* Vista/Longhorn */
|
||||
BOOL InitializeProcessForWsWatch(HANDLE);
|
||||
BOOL QueryWorkingSet(HANDLE, PVOID, DWORD);
|
||||
BOOL QueryWorkingSetEx(HANDLE, PVOID, DWORD);
|
||||
|
||||
/* Memory-Mapped File Information
|
||||
* http://windowssdk.msdn.microsoft.com/library/ms684212.aspx */
|
||||
DWORD GetMappedFileNameW(HANDLE, LPVOID, LPWSTR, DWORD);
|
||||
DWORD GetMappedFileNameA(HANDLE, LPVOID, LPSTR, DWORD);
|
||||
|
||||
/* Resources Information */
|
||||
BOOL GetPerformanceInfo(PPERFORMANCE_INFORMATION, DWORD); /* XP/Server2003/Vista/Longhorn */
|
||||
BOOL EnumPageFilesW(PENUM_PAGE_FILE_CALLBACK, LPVOID); /* 2000/XP/Server2003/Vista/Longhorn */
|
||||
BOOL EnumPageFilesA(PENUM_PAGE_FILE_CALLBACK, LPVOID); /* 2000/XP/Server2003/Vista/Longhorn */
|
||||
}
|
||||
|
||||
version (Unicode) {
|
||||
alias GetModuleBaseNameW GetModuleBaseName;
|
||||
alias GetModuleFileNameExW GetModuleFileNameEx;
|
||||
alias GetMappedFileNameW GetMappedFileName;
|
||||
alias GetDeviceDriverBaseNameW GetDeviceDriverBaseName;
|
||||
alias GetDeviceDriverFileNameW GetDeviceDriverFileName;
|
||||
alias EnumPageFilesW EnumPageFiles;
|
||||
alias GetProcessImageFileNameW GetProcessImageFileName;
|
||||
} else {
|
||||
alias GetModuleBaseNameA GetModuleBaseName;
|
||||
alias GetModuleFileNameExA GetModuleFileNameEx;
|
||||
alias GetMappedFileNameA GetMappedFileName;
|
||||
alias GetDeviceDriverBaseNameA GetDeviceDriverBaseName;
|
||||
alias GetDeviceDriverFileNameA GetDeviceDriverFileName;
|
||||
alias EnumPageFilesA EnumPageFiles;
|
||||
alias GetProcessImageFileNameA GetProcessImageFileName;
|
||||
}
|
|
@ -229,7 +229,7 @@
|
|||
<isSolaris>0</isSolaris>
|
||||
<scheduler>0</scheduler>
|
||||
<useDeprecated>0</useDeprecated>
|
||||
<errDeprecated>0</errDeprecated>
|
||||
<errDeprecated>1</errDeprecated>
|
||||
<useAssert>0</useAssert>
|
||||
<useInvariants>0</useInvariants>
|
||||
<useIn>0</useIn>
|
||||
|
@ -241,14 +241,14 @@
|
|||
<useInline>0</useInline>
|
||||
<release>0</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
<warnings>0</warnings>
|
||||
<warnings>1</warnings>
|
||||
<infowarnings>0</infowarnings>
|
||||
<checkProperty>0</checkProperty>
|
||||
<genStackFrame>0</genStackFrame>
|
||||
<pic>0</pic>
|
||||
<cov>0</cov>
|
||||
<nofloat>0</nofloat>
|
||||
<Dversion>2.043</Dversion>
|
||||
<Dversion>2</Dversion>
|
||||
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
|
||||
<allinst>0</allinst>
|
||||
<stackStomp>0</stackStomp>
|
||||
|
@ -314,7 +314,7 @@
|
|||
<multiobj>0</multiobj>
|
||||
<singleFileCompilation>0</singleFileCompilation>
|
||||
<oneobj>0</oneobj>
|
||||
<mscoff>0</mscoff>
|
||||
<mscoff>1</mscoff>
|
||||
<trace>0</trace>
|
||||
<quiet>0</quiet>
|
||||
<verbose>0</verbose>
|
||||
|
@ -331,7 +331,7 @@
|
|||
<isSolaris>0</isSolaris>
|
||||
<scheduler>0</scheduler>
|
||||
<useDeprecated>0</useDeprecated>
|
||||
<errDeprecated>0</errDeprecated>
|
||||
<errDeprecated>1</errDeprecated>
|
||||
<useAssert>0</useAssert>
|
||||
<useInvariants>0</useInvariants>
|
||||
<useIn>0</useIn>
|
||||
|
@ -343,14 +343,14 @@
|
|||
<useInline>1</useInline>
|
||||
<release>1</release>
|
||||
<preservePaths>0</preservePaths>
|
||||
<warnings>0</warnings>
|
||||
<warnings>1</warnings>
|
||||
<infowarnings>0</infowarnings>
|
||||
<checkProperty>0</checkProperty>
|
||||
<genStackFrame>0</genStackFrame>
|
||||
<pic>0</pic>
|
||||
<cov>0</cov>
|
||||
<nofloat>0</nofloat>
|
||||
<Dversion>2.043</Dversion>
|
||||
<Dversion>2</Dversion>
|
||||
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
|
||||
<allinst>0</allinst>
|
||||
<stackStomp>0</stackStomp>
|
||||
|
@ -523,6 +523,7 @@
|
|||
<File path="3rdparty\win32\olectlid.d" />
|
||||
<File path="3rdparty\win32\oleidl.d" />
|
||||
<File path="3rdparty\win32\prsht.d" />
|
||||
<File path="3rdparty\win32\psapi.d" />
|
||||
<File path="3rdparty\win32\readme.txt" />
|
||||
<File path="3rdparty\win32\rpc.d" />
|
||||
<File path="3rdparty\win32\rpcdce.d" />
|
||||
|
@ -584,6 +585,42 @@
|
|||
<File path="src\dlangui\dml\dmlhighlight.d" />
|
||||
<File path="src\dlangui\dml\parser.d" />
|
||||
</Folder>
|
||||
<Folder name="graphics">
|
||||
<Folder name="scene">
|
||||
<File path="src\dlangui\graphics\scene\camera.d" />
|
||||
<File path="src\dlangui\graphics\scene\node.d" />
|
||||
<File path="src\dlangui\graphics\scene\scene3d.d" />
|
||||
<File path="src\dlangui\graphics\scene\transform.d" />
|
||||
</Folder>
|
||||
<Folder name="xpm">
|
||||
<File path="src\dlangui\graphics\xpm\colors.d" />
|
||||
<File path="src\dlangui\graphics\xpm\reader.d" />
|
||||
</Folder>
|
||||
<File path="src\dlangui\graphics\colors.d" />
|
||||
<File path="src\dlangui\graphics\drawbuf.d" />
|
||||
<File path="src\dlangui\graphics\fonts.d" />
|
||||
<File path="src\dlangui\graphics\ftfonts.d" />
|
||||
<File path="src\dlangui\graphics\gldrawbuf.d" />
|
||||
<File path="src\dlangui\graphics\glsupport.d" />
|
||||
<File path="src\dlangui\graphics\images.d" />
|
||||
<File path="src\dlangui\graphics\resources.d" />
|
||||
</Folder>
|
||||
<Folder name="platforms">
|
||||
<Folder name="common">
|
||||
<File path="src\dlangui\platforms\common\platform.d" />
|
||||
</Folder>
|
||||
<Folder name="dsfml">
|
||||
<File path="src\dlangui\platforms\dsfml\dsfmlapp.d" />
|
||||
</Folder>
|
||||
<Folder name="sdl">
|
||||
<File path="src\dlangui\platforms\sdl\sdlapp.d" />
|
||||
</Folder>
|
||||
<Folder name="windows">
|
||||
<File path="src\dlangui\platforms\windows\win32drawbuf.d" />
|
||||
<File path="src\dlangui\platforms\windows\win32fonts.d" />
|
||||
<File path="src\dlangui\platforms\windows\winapp.d" />
|
||||
</Folder>
|
||||
</Folder>
|
||||
<Folder name="widgets">
|
||||
<File path="src\dlangui\widgets\appframe.d" />
|
||||
<File path="src\dlangui\widgets\combobox.d" />
|
||||
|
@ -606,42 +643,6 @@
|
|||
<File path="src\dlangui\widgets\widget.d" />
|
||||
<File path="src\dlangui\widgets\winframe.d" />
|
||||
</Folder>
|
||||
<Folder name="platforms">
|
||||
<Folder name="common">
|
||||
<File path="src\dlangui\platforms\common\platform.d" />
|
||||
</Folder>
|
||||
<Folder name="dsfml">
|
||||
<File path="src\dlangui\platforms\dsfml\dsfmlapp.d" />
|
||||
</Folder>
|
||||
<Folder name="sdl">
|
||||
<File path="src\dlangui\platforms\sdl\sdlapp.d" />
|
||||
</Folder>
|
||||
<Folder name="windows">
|
||||
<File path="src\dlangui\platforms\windows\win32drawbuf.d" />
|
||||
<File path="src\dlangui\platforms\windows\win32fonts.d" />
|
||||
<File path="src\dlangui\platforms\windows\winapp.d" />
|
||||
</Folder>
|
||||
</Folder>
|
||||
<Folder name="graphics">
|
||||
<Folder name="xpm">
|
||||
<File path="src\dlangui\graphics\xpm\colors.d" />
|
||||
<File path="src\dlangui\graphics\xpm\reader.d" />
|
||||
</Folder>
|
||||
<Folder name="scene">
|
||||
<File path="src\dlangui\graphics\scene\camera.d" />
|
||||
<File path="src\dlangui\graphics\scene\node.d" />
|
||||
<File path="src\dlangui\graphics\scene\scene3d.d" />
|
||||
<File path="src\dlangui\graphics\scene\transform.d" />
|
||||
</Folder>
|
||||
<File path="src\dlangui\graphics\colors.d" />
|
||||
<File path="src\dlangui\graphics\drawbuf.d" />
|
||||
<File path="src\dlangui\graphics\fonts.d" />
|
||||
<File path="src\dlangui\graphics\ftfonts.d" />
|
||||
<File path="src\dlangui\graphics\gldrawbuf.d" />
|
||||
<File path="src\dlangui\graphics\glsupport.d" />
|
||||
<File path="src\dlangui\graphics\images.d" />
|
||||
<File path="src\dlangui\graphics\resources.d" />
|
||||
</Folder>
|
||||
<File path="src\dlangui\package.d" />
|
||||
</Folder>
|
||||
</Folder>
|
||||
|
|
|
@ -248,7 +248,7 @@
|
|||
<pic>0</pic>
|
||||
<cov>0</cov>
|
||||
<nofloat>0</nofloat>
|
||||
<Dversion>2.043</Dversion>
|
||||
<Dversion>2</Dversion>
|
||||
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
|
||||
<allinst>0</allinst>
|
||||
<stackStomp>0</stackStomp>
|
||||
|
@ -314,7 +314,7 @@
|
|||
<multiobj>0</multiobj>
|
||||
<singleFileCompilation>0</singleFileCompilation>
|
||||
<oneobj>0</oneobj>
|
||||
<mscoff>0</mscoff>
|
||||
<mscoff>1</mscoff>
|
||||
<trace>0</trace>
|
||||
<quiet>0</quiet>
|
||||
<verbose>0</verbose>
|
||||
|
@ -350,7 +350,7 @@
|
|||
<pic>0</pic>
|
||||
<cov>0</cov>
|
||||
<nofloat>0</nofloat>
|
||||
<Dversion>2.043</Dversion>
|
||||
<Dversion>2</Dversion>
|
||||
<ignoreUnsupportedPragmas>0</ignoreUnsupportedPragmas>
|
||||
<allinst>0</allinst>
|
||||
<stackStomp>0</stackStomp>
|
||||
|
|
|
@ -368,9 +368,52 @@ struct Cup {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/// 1 == next cell below is occupied, 2 == one empty cell
|
||||
private int distanceToOccupiedCellBelowForGroup(int group) {
|
||||
int minDistanceFound = 0;
|
||||
for (int y = 0; y < _rows; y++) {
|
||||
for (int x = 0; x < _cols; x++) {
|
||||
if (cellGroup(x, y) != group)
|
||||
continue;
|
||||
if (y == 0)
|
||||
return 1; // right below
|
||||
if (this[x, y - 1] != EMPTY) // check only lowest cell of group
|
||||
continue;
|
||||
int dist = 0;
|
||||
for (int d = 1; y - d >= 0; d++) {
|
||||
if (this[x, y - d] == EMPTY) {
|
||||
dist = d + 1;
|
||||
} else {
|
||||
// reached non-empty cell
|
||||
if (cellGroup(x, y - d) == group) {
|
||||
// non-empty cell of the same group after empty space - ignore
|
||||
dist = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dist > 0) {
|
||||
// found some empty space below
|
||||
if (minDistanceFound == 0 || minDistanceFound > dist)
|
||||
minDistanceFound = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (minDistanceFound == 0)
|
||||
return 1;
|
||||
return minDistanceFound;
|
||||
}
|
||||
|
||||
/// mark cells in _cellGroups[] matrix which can fall down (value > 0 is distance to fall)
|
||||
bool markFallingCells() {
|
||||
_cellGroups = new int[_cols * _rows];
|
||||
// clear cellGroups matrix
|
||||
if (_cellGroups.length != _cols * _rows) {
|
||||
_cellGroups = new int[_cols * _rows];
|
||||
} else {
|
||||
foreach(ref cell; _cellGroups)
|
||||
cell = 0;
|
||||
}
|
||||
// find and mark all groups
|
||||
int groupId = 1;
|
||||
for (int y = 0; y < _rows; y++) {
|
||||
for (int x = 0; x < _cols; x++) {
|
||||
|
@ -382,18 +425,23 @@ struct Cup {
|
|||
}
|
||||
// check space below each group - can it fall down?
|
||||
int[] spaceBelowGroup = new int[groupId];
|
||||
for (int y = 0; y < _rows; y++) {
|
||||
for (int x = 0; x < _cols; x++) {
|
||||
int group = cellGroup(x, y);
|
||||
if (group > 0) {
|
||||
if (y == 0)
|
||||
spaceBelowGroup[group] = 1;
|
||||
else if (this[x, y - 1] != EMPTY && cellGroup(x, y - 1) != group)
|
||||
spaceBelowGroup[group] = 1;
|
||||
else if (this[x, y - 1] == EMPTY) {
|
||||
int dist = distanceToOccupiedCellBelow(x, y);
|
||||
if (spaceBelowGroup[group] == 0 || spaceBelowGroup[group] > dist)
|
||||
spaceBelowGroup[group] = dist;
|
||||
static if (true) {
|
||||
for (int i = 1; i < groupId; i++)
|
||||
spaceBelowGroup[i] = distanceToOccupiedCellBelowForGroup(i);
|
||||
} else {
|
||||
for (int y = 0; y < _rows; y++) {
|
||||
for (int x = 0; x < _cols; x++) {
|
||||
int group = cellGroup(x, y);
|
||||
if (group > 0) {
|
||||
if (y == 0)
|
||||
spaceBelowGroup[group] = 1;
|
||||
else if (this[x, y - 1] != EMPTY && cellGroup(x, y - 1) != group)
|
||||
spaceBelowGroup[group] = 1;
|
||||
else if (this[x, y - 1] == EMPTY) {
|
||||
int dist = distanceToOccupiedCellBelow(x, y);
|
||||
if (spaceBelowGroup[group] == 0 || spaceBelowGroup[group] > dist)
|
||||
spaceBelowGroup[group] = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue