diff --git a/3rdparty/win32/psapi.d b/3rdparty/win32/psapi.d new file mode 100644 index 00000000..f84175a0 --- /dev/null +++ b/3rdparty/win32/psapi.d @@ -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; +} diff --git a/dlangui_msvc.visualdproj b/dlangui_msvc.visualdproj index fc577443..3a3db7ae 100644 --- a/dlangui_msvc.visualdproj +++ b/dlangui_msvc.visualdproj @@ -229,7 +229,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -241,14 +241,14 @@ 0 0 0 - 0 + 1 0 0 0 0 0 0 - 2.043 + 2 0 0 0 @@ -314,7 +314,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -331,7 +331,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -343,14 +343,14 @@ 1 1 0 - 0 + 1 0 0 0 0 0 0 - 2.043 + 2 0 0 0 @@ -523,6 +523,7 @@ + @@ -584,6 +585,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -606,42 +643,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/dmledit/dmledit_msvc.visualdproj b/examples/dmledit/dmledit_msvc.visualdproj index 1d420326..084f8aa3 100644 --- a/examples/dmledit/dmledit_msvc.visualdproj +++ b/examples/dmledit/dmledit_msvc.visualdproj @@ -248,7 +248,7 @@ 0 0 0 - 2.043 + 2 0 0 0 @@ -314,7 +314,7 @@ 0 0 0 - 0 + 1 0 0 0 @@ -350,7 +350,7 @@ 0 0 0 - 2.043 + 2 0 0 0 diff --git a/examples/tetris/src/model.d b/examples/tetris/src/model.d index fe58fd69..d0716744 100644 --- a/examples/tetris/src/model.d +++ b/examples/tetris/src/model.d @@ -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; + } } } }