1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-06 16:25:59 +02:00

Moving BeefMem

This commit is contained in:
Brian Fiete 2019-09-04 11:41:56 -07:00
parent b3487d733b
commit 65bf1915af
337 changed files with 0 additions and 4 deletions

View file

@ -0,0 +1,74 @@
FileVersion = 1
Dependencies = {Beefy2D = "*", corlib = "*"}
[Project]
Name = "MemProfiler"
TargetType = "BeefWindowsApplication"
StartupObject = "MemProfiler.Program"
DefaultNamespace = ""
[Configs.Debug.Win32]
TargetDirectory = "$(WorkspaceDir)/dist"
OtherLinkFlags = "-lwinmm -lole32 -lwsock32"
CLibType = "Dynamic"
DebugCommandArguments = "-windowed"
OptimizationLevel = "O0"
[Configs.Debug.Win64]
TargetDirectory = "$(WorkspaceDir)/../IDE/dist"
TargetName = "$(ProjectName)_d"
OtherLinkFlags = "Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib BeefRT64_d.lib BeefySysLib64_d.lib"
CLibType = "Dynamic"
PreprocessorMacros = ["DEBUG", "WIN64"]
OptimizationLevel = "O0"
[Configs.Release.Win32]
TargetDirectory = "$(WorkspaceDir)/dist"
OtherLinkFlags = ""
OptimizationLevel = "O2"
[Configs.Release.Win64]
TargetDirectory = "$(WorkspaceDir)/dist"
OtherLinkFlags = ""
CLibType = "Dynamic"
PreprocessorMacros = ["RELEASE", "WIN64"]
OptimizationLevel = "O2"
[Configs.Test.Win32]
[Configs.Test.Win64]
[ProjectFolder]
Type = "Folder"
ImportPath = "src"
AutoInclude = false
[[ProjectFolder.Items]]
Type = "Source"
Name = "Board.bf"
ImportPath = "Board.bf"
[[ProjectFolder.Items]]
Type = "Source"
Name = "FMod.bf"
ImportPath = "FMod.bf"
[[ProjectFolder.Items]]
Type = "Source"
Name = "FMod_DSP.bf"
ImportPath = "FMod_DSP.bf"
[[ProjectFolder.Items]]
Type = "Source"
Name = "FMod_Errors.bf"
ImportPath = "FMod_Errors.bf"
[[ProjectFolder.Items]]
Type = "Source"
Name = "MPApp.bf"
ImportPath = "MPApp.bf"
[[ProjectFolder.Items]]
Type = "Source"
Name = "Program.bf"
ImportPath = "Program.bf"

View file

@ -0,0 +1,49 @@
FileVersion = 1
Projects = {MemProfiler = {Path = "."}, corlib = {Path = "../IDE\\corlib"}, Beefy2D = {Path = "../Beefy2D"}, BeefySysLib = {Path = "../BeefySysLib"}}
[Workspace]
StartupProject = "MemProfiler"
[Configs.Debug.Win32]
BfOptimizationLevel = "O0"
InitLocalVariables = true
IntermediateType = "ObjectAndIRCode"
[Configs.Debug.Win64]
InitLocalVariables = true
[Configs.Release.Win32]
BfOptimizationLevel = "OgPlus"
EmitDebugInfo = "No"
[Configs.Release.Win64]
BfOptimizationLevel = "OgPlus"
EmitDebugInfo = "No"
[Configs.DebugOpt1.Win32]
BfOptimizationLevel = "O0"
EmitDebugInfo = "No"
ArrayBoundsCheck = false
EmitDynamicCastCheck = false
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false
EnableCustodian = false
EnableRealtimeLeakCheck = false
[Configs.DebugOpt1.Win64]
PreprocessorMacros = ["BF_SYSLIB_OPT"]
BfOptimizationLevel = "O0"
InitLocalVariables = true
ConfigSelections = {MemProfiler = {Config = "Debug"}, corlib = {Config = "Debug"}, Beefy2D = {Config = "Debug"}, BeefySysLib = {Config = "Release"}}
[Configs.Paranoid.Win32]
COptimizationLevel = "O2"
[Configs.Paranoid.Win64]
COptimizationLevel = "O2"
[Configs.Test.Win32]
COptimizationLevel = "O2"
[Configs.Test.Win64]
COptimizationLevel = "O2"

View file

@ -0,0 +1,123 @@
using System;
using Beefy;
using Beefy.gfx;
using Beefy.widgets;
using Beefy.geom;
using System.Collections.Generic;
using Beefy.utils;
using System.Diagnostics;
using Beefy.theme.dark;
using Beefy.events;
namespace MemProfiler
{
class Board : Widget
{
DarkListView mListView;
DarkButton mGetButton;
public this()
{
mListView = new DarkListView();
AddWidget(mListView);
mListView.AddColumn(200, "Name");
mListView.AddColumn(200, "Self");
mListView.AddColumn(200, "Total");
mListView.InitScrollbars(false, true);
mGetButton = (DarkButton)DarkTheme.sDarkTheme.CreateButton(this, "Get", 0, 0, 0, 0);
mGetButton.mMouseClickHandler.Add(new (evt) => { GetData(); });
}
public override void Resize(float x, float y, float width, float height)
{
base.Resize(x, y, width, height);
mListView.Resize(x, y, width, height - 20);
mGetButton.Resize(20, mHeight - 20, 128, 20);
}
public override void Draw(Graphics g)
{
base.Draw(g);
g.DrawBox(DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.Bkg), 0, 0, mWidth, mHeight);
g.SetFont(DarkTheme.sDarkTheme.mSmallFont);
g.DrawString(StackStringFormat!("FPS: {0}", gApp.mLastFPS), mWidth - 128, mHeight - 18);
g.FillRect(mUpdateCnt % 200 + 200, mHeight - 2, 2, 2);
}
void ValueClicked(MouseEvent theEvent)
{
DarkListViewItem clickedItem = (DarkListViewItem)theEvent.mSender;
DarkListViewItem item = (DarkListViewItem)clickedItem.GetSubItem(0);
mListView.GetRoot().SelectItemExclusively(item);
mListView.SetFocus();
}
void GetData()
{
//const char* cmd = "Get";
//DWORD bytesRead = 0;
mListView.GetRoot().Clear();
String pipeName = scope String();
pipeName.FormatInto(@"\\.\pipe\HeapDbg_{0}", gApp.mProcessInformation.mProcessId);
String cmd = "Get";
char8[] charData = new char8[16*1024*1024];
defer delete charData;
int32 bytesRead = 0;
if (Windows.CallNamedPipeA(pipeName, (void*)cmd, (int32)cmd.Length, (void*)charData.CArray(), (int32)charData.Count, &bytesRead, 0))
{
String data = scope String();
data.Reference(charData.CArray(), bytesRead, charData.Count);
ListViewItem curItem = mListView.GetRoot();
for (var lineView in data.Split('\n'))
{
String lineViewStr = scope String(lineView);
if (lineViewStr == "-")
{
curItem = curItem.mParentItem;
}
else
{
var childItem = curItem.CreateChildItem();
childItem.mMouseDownHandler.Add(new => ValueClicked);
int32 idx = 0;
for (var dataStr in lineViewStr.Split('\t'))
{
if (idx == 0)
childItem.Label = scope String(dataStr);
else
{
var subItem = childItem.CreateSubItem(idx);
subItem.Label = scope String(dataStr);
subItem.mMouseDownHandler.Add(new => ValueClicked);
}
idx++;
}
curItem = childItem;
}
}
//tree->InsertItem()
}
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,105 @@
using System;
/* =================================================================================================== */
/* FMOD Studio - Error string header file. Copyright (c), Firelight Technologies Pty, Ltd. 2004-2016. */
/* */
/* Use this header if you want to store or display a string version / english explanation of */
/* the FMOD error codes. */
/* */
/* =================================================================================================== */
namespace FMOD
{
public class Error
{
public static String String(FMOD.RESULT errcode)
{
switch (errcode)
{
case FMOD.RESULT.OK: return "No errors.";
case FMOD.RESULT.ERR_BADCOMMAND: return "Tried to call a function on a data type that does not allow this type of functionality (ie calling Sound::lock on a streaming sound).";
case FMOD.RESULT.ERR_CHANNEL_ALLOC: return "Error trying to allocate a channel.";
case FMOD.RESULT.ERR_CHANNEL_STOLEN: return "The specified channel has been reused to play another sound.";
case FMOD.RESULT.ERR_DMA: return "DMA Failure. See debug output for more information.";
case FMOD.RESULT.ERR_DSP_CONNECTION: return "DSP connection error. Connection possibly caused a cyclic dependency or connected dsps with incompatible buffer counts.";
case FMOD.RESULT.ERR_DSP_DONTPROCESS: return "DSP return code from a DSP process query callback. Tells mixer not to call the process callback and therefore not consume CPU. Use this to optimize the DSP graph.";
case FMOD.RESULT.ERR_DSP_FORMAT: return "DSP Format error. A DSP unit may have attempted to connect to this network with the wrong format, or a matrix may have been set with the wrong size if the target unit has a specified channel map.";
case FMOD.RESULT.ERR_DSP_INUSE: return "DSP is already in the mixer's DSP network. It must be removed before being reinserted or released.";
case FMOD.RESULT.ERR_DSP_NOTFOUND: return "DSP connection error. Couldn't find the DSP unit specified.";
case FMOD.RESULT.ERR_DSP_RESERVED: return "DSP operation error. Cannot perform operation on this DSP as it is reserved by the system.";
case FMOD.RESULT.ERR_DSP_SILENCE: return "DSP return code from a DSP process query callback. Tells mixer silence would be produced from read, so go idle and not consume CPU. Use this to optimize the DSP graph.";
case FMOD.RESULT.ERR_DSP_TYPE: return "DSP operation cannot be performed on a DSP of this type.";
case FMOD.RESULT.ERR_FILE_BAD: return "Error loading file.";
case FMOD.RESULT.ERR_FILE_COULDNOTSEEK: return "Couldn't perform seek operation. This is a limitation of the medium (ie netstreams) or the file format.";
case FMOD.RESULT.ERR_FILE_DISKEJECTED: return "Media was ejected while reading.";
case FMOD.RESULT.ERR_FILE_EOF: return "End of file unexpectedly reached while trying to read essential data (truncated?).";
case FMOD.RESULT.ERR_FILE_ENDOFDATA: return "End of current chunk reached while trying to read data.";
case FMOD.RESULT.ERR_FILE_NOTFOUND: return "File not found.";
case FMOD.RESULT.ERR_FORMAT: return "Unsupported file or audio format.";
case FMOD.RESULT.ERR_HEADER_MISMATCH: return "There is a version mismatch between the FMOD header and either the FMOD Studio library or the FMOD Low Level library.";
case FMOD.RESULT.ERR_HTTP: return "A HTTP error occurred. This is a catch-all for HTTP errors not listed elsewhere.";
case FMOD.RESULT.ERR_HTTP_ACCESS: return "The specified resource requires authentication or is forbidden.";
case FMOD.RESULT.ERR_HTTP_PROXY_AUTH: return "Proxy authentication is required to access the specified resource.";
case FMOD.RESULT.ERR_HTTP_SERVER_ERROR: return "A HTTP server error occurred.";
case FMOD.RESULT.ERR_HTTP_TIMEOUT: return "The HTTP request timed out.";
case FMOD.RESULT.ERR_INITIALIZATION: return "FMOD was not initialized correctly to support this function.";
case FMOD.RESULT.ERR_INITIALIZED: return "Cannot call this command after System::init.";
case FMOD.RESULT.ERR_INTERNAL: return "An error occurred that wasn't supposed to. Contact support.";
case FMOD.RESULT.ERR_INVALID_FLOAT: return "Value passed in was a NaN, Inf or denormalized float.";
case FMOD.RESULT.ERR_INVALID_HANDLE: return "An invalid object handle was used.";
case FMOD.RESULT.ERR_INVALID_PARAM: return "An invalid parameter was passed to this function.";
case FMOD.RESULT.ERR_INVALID_POSITION: return "An invalid seek position was passed to this function.";
case FMOD.RESULT.ERR_INVALID_SPEAKER: return "An invalid speaker was passed to this function based on the current speaker mode.";
case FMOD.RESULT.ERR_INVALID_SYNCPOINT: return "The syncpoint did not come from this sound handle.";
case FMOD.RESULT.ERR_INVALID_THREAD: return "Tried to call a function on a thread that is not supported.";
case FMOD.RESULT.ERR_INVALID_VECTOR: return "The vectors passed in are not unit length, or perpendicular.";
case FMOD.RESULT.ERR_MAXAUDIBLE: return "Reached maximum audible playback count for this sound's soundgroup.";
case FMOD.RESULT.ERR_MEMORY: return "Not enough memory or resources.";
case FMOD.RESULT.ERR_MEMORY_CANTPOINT: return "Can't use FMOD_OPENMEMORY_POINT on non PCM source data, or non mp3/xma/adpcm data if FMOD_CREATECOMPRESSEDSAMPLE was used.";
case FMOD.RESULT.ERR_NEEDS3D: return "Tried to call a command on a 2d sound when the command was meant for 3d sound.";
case FMOD.RESULT.ERR_NEEDSHARDWARE: return "Tried to use a feature that requires hardware support.";
case FMOD.RESULT.ERR_NET_CONNECT: return "Couldn't connect to the specified host.";
case FMOD.RESULT.ERR_NET_SOCKET_ERROR: return "A socket error occurred. This is a catch-all for socket-related errors not listed elsewhere.";
case FMOD.RESULT.ERR_NET_URL: return "The specified URL couldn't be resolved.";
case FMOD.RESULT.ERR_NET_WOULD_BLOCK: return "Operation on a non-blocking socket could not complete immediately.";
case FMOD.RESULT.ERR_NOTREADY: return "Operation could not be performed because specified sound/DSP connection is not ready.";
case FMOD.RESULT.ERR_OUTPUT_ALLOCATED: return "Error initializing output device, but more specifically, the output device is already in use and cannot be reused.";
case FMOD.RESULT.ERR_OUTPUT_CREATEBUFFER: return "Error creating hardware sound buffer.";
case FMOD.RESULT.ERR_OUTPUT_DRIVERCALL: return "A call to a standard soundcard driver failed, which could possibly mean a bug in the driver or resources were missing or exhausted.";
case FMOD.RESULT.ERR_OUTPUT_FORMAT: return "Soundcard does not support the specified format.";
case FMOD.RESULT.ERR_OUTPUT_INIT: return "Error initializing output device.";
case FMOD.RESULT.ERR_OUTPUT_NODRIVERS: return "The output device has no drivers installed. If pre-init, FMOD_OUTPUT_NOSOUND is selected as the output mode. If post-init, the function just fails.";
case FMOD.RESULT.ERR_PLUGIN: return "An unspecified error has been returned from a plugin.";
case FMOD.RESULT.ERR_PLUGIN_MISSING: return "A requested output, dsp unit type or codec was not available.";
case FMOD.RESULT.ERR_PLUGIN_RESOURCE: return "A resource that the plugin requires cannot be found. (ie the DLS file for MIDI playback)";
case FMOD.RESULT.ERR_PLUGIN_VERSION: return "A plugin was built with an unsupported SDK version.";
case FMOD.RESULT.ERR_RECORD: return "An error occurred trying to initialize the recording device.";
case FMOD.RESULT.ERR_REVERB_CHANNELGROUP: return "Reverb properties cannot be set on this channel because a parent channelgroup owns the reverb connection.";
case FMOD.RESULT.ERR_REVERB_INSTANCE: return "Specified instance in FMOD_REVERB_PROPERTIES couldn't be set. Most likely because it is an invalid instance number or the reverb doesn't exist.";
case FMOD.RESULT.ERR_SUBSOUNDS: return "The error occurred because the sound referenced contains subsounds when it shouldn't have, or it doesn't contain subsounds when it should have. The operation may also not be able to be performed on a parent sound.";
case FMOD.RESULT.ERR_SUBSOUND_ALLOCATED: return "This subsound is already being used by another sound, you cannot have more than one parent to a sound. Null out the other parent's entry first.";
case FMOD.RESULT.ERR_SUBSOUND_CANTMOVE: return "Shared subsounds cannot be replaced or moved from their parent stream, such as when the parent stream is an FSB file.";
case FMOD.RESULT.ERR_TAGNOTFOUND: return "The specified tag could not be found or there are no tags.";
case FMOD.RESULT.ERR_TOOMANYCHANNELS: return "The sound created exceeds the allowable input channel count. This can be increased using the 'maxinputchannels' parameter in System::setSoftwareFormat.";
case FMOD.RESULT.ERR_TRUNCATED: return "The retrieved string is too long to fit in the supplied buffer and has been truncated.";
case FMOD.RESULT.ERR_UNIMPLEMENTED: return "Something in FMOD hasn't been implemented when it should be! contact support!";
case FMOD.RESULT.ERR_UNINITIALIZED: return "This command failed because System::init or System::setDriver was not called.";
case FMOD.RESULT.ERR_UNSUPPORTED: return "A command issued was not supported by this object. Possibly a plugin without certain callbacks specified.";
case FMOD.RESULT.ERR_VERSION: return "The version number of this file format is not supported.";
case FMOD.RESULT.ERR_EVENT_ALREADY_LOADED: return "The specified bank has already been loaded.";
case FMOD.RESULT.ERR_EVENT_LIVEUPDATE_BUSY: return "The live update connection failed due to the game already being connected.";
case FMOD.RESULT.ERR_EVENT_LIVEUPDATE_MISMATCH: return "The live update connection failed due to the game data being out of sync with the tool.";
case FMOD.RESULT.ERR_EVENT_LIVEUPDATE_TIMEOUT: return "The live update connection timed out.";
case FMOD.RESULT.ERR_EVENT_NOTFOUND: return "The requested event, bus or vca could not be found.";
case FMOD.RESULT.ERR_STUDIO_UNINITIALIZED: return "The Studio::System object is not yet initialized.";
case FMOD.RESULT.ERR_STUDIO_NOT_LOADED: return "The specified resource is not loaded, so it can't be unloaded.";
case FMOD.RESULT.ERR_INVALID_STRING: return "An invalid string was passed to this function.";
case FMOD.RESULT.ERR_ALREADY_LOCKED: return "The specified resource is already locked.";
case FMOD.RESULT.ERR_NOT_LOCKED: return "The specified resource is not locked, so it can't be unlocked.";
case FMOD.RESULT.ERR_RECORD_DISCONNECTED: return "The specified recording driver has been disconnected.";
case FMOD.RESULT.ERR_TOOMANYSAMPLES: return "The length provided exceed the allowable limit.";
default: return "Unknown error.";
}
}
}
}

View file

@ -0,0 +1,11 @@
using Beefy.gfx;
namespace Mercury
{
class Images
{
public static Image sGrass ~ delete _;
public static Image[,] sPeople ~ DeleteContainerAndItems!(_);
public static Image sStone ~ delete _;
}
}

View file

@ -0,0 +1,209 @@
using System;
using Beefy;
using Beefy.widgets;
using Beefy.gfx;
using Beefy.theme.dark;
using Beefy.theme;
using System.IO;
namespace MemProfiler
{
class MPApp : BFApp
{
public new static MPApp sApp;
public float mTimePerFrame = 1.0f / 120;
public bool mWantsFullscreen = false;
WidgetWindow mMainWindow;
Widget mRootWidget;
public Widget mMainWidget;
//public PopupMenuManager mPopupMenuManager;
//public Trainer mTrainer ~ delete _;
public Board mBoard;
public Windows.ProcessInformation mProcessInformation;
public this()
{
sApp = this;
gApp = this;
RefreshRate = 120;
}
static uint32 TimeToUnixTime(DateTime ft)
{
// takes the last modified date
int64 date = ft.ToFileTime();
// 100-nanoseconds = milliseconds * 10000
int64 adjust = 11644473600000L * 10000;
// removes the diff between 1970 and 1601
date -= adjust;
// converts back from 100-nanoseconds to seconds
return (uint32)(date / 10000000L);
}
public void Fail(String text)
{
//MessageBeep(MessageBeepType.Error);
Dialog aDialog = ThemeFactory.mDefault.CreateDialog("ERROR", text, DarkTheme.sDarkTheme.mIconError);
aDialog.mDefaultButton = aDialog.AddButton("OK");
aDialog.mEscButton = aDialog.mDefaultButton;
aDialog.PopupWindow(mMainWindow);
}
public override void Init()
{
/*uint timeNow = GetCurrentUnixTime();
FitEntry[] fitEntries = new FitEntry[200];
for (int i = 0; i < fitEntries.Length; i++)
{
fitEntries[i].mElapsedTimeMS = i * 500;
fitEntries[i].mPower = i;
fitEntries[i].mCadence = 90;
}
int[] lapOffsets = scope int[] {100};
WriteFit("c:\\temp\\test.fit", UnixTimeToFitTime(timeNow), fitEntries.CArray(), fitEntries.Length, lapOffsets.CArray(), lapOffsets.Length);*/
base.Init();
DarkTheme aTheme = new DarkTheme();
aTheme.Init();
ThemeFactory.mDefault = aTheme;
BFWindow.Flags windowFlags = BFWindow.Flags.Border | BFWindow.Flags.SysMenu | //| BFWindow.Flags.CaptureMediaKeys |
BFWindow.Flags.Caption | BFWindow.Flags.Minimize | BFWindow.Flags.QuitOnClose | BFWindowBase.Flags.Resizable;
if (mWantsFullscreen)
windowFlags |= BFWindowBase.Flags.Fullscreen;
//mRootWidget = new Widget();
mBoard = new Board();
mRootWidget = mBoard;
mMainWindow = new WidgetWindow(null, "Memory Profiler", 0, 0, 1024, 768, windowFlags, mRootWidget);
mMainWindow.SetMinimumSize(480, 360);
mMainWindow.mIsMainWindow = true;
//String injectDllName = "HeapyInject_x64.dll";
//String launchExeName = @"c:\Beef\IDE\dist\IDE_bf.exe";
//String argsStr = @"-proddir=c:\beef\ide\";
String launchExeName = @"c:\Beef\IDE\dist\IDE_bfd.exe";
String argsStr = @"-proddir=c:\beef\ide";
String launchStr = scope String(launchExeName, " ", argsStr);
String launchDir = scope String();
Path.GetDirectoryName(launchExeName, launchDir);
mProcessInformation = Windows.ProcessInformation();
var startupInfo = Windows.StartupInfo();
Windows.GetStartupInfoA(&startupInfo);
String dllName = @"C:\temp\Heapy\Debug\HeapyInject_x64.dll";
int32 flags = Windows.CREATE_SUSPENDED;
if (!Windows.CreateProcessA(null, launchStr, null, null, 0, flags, null, launchDir, &startupInfo, &mProcessInformation))
{
Fail("Failed to create process");
}
else
{
LoadLibraryInjection(mProcessInformation.mProcess, dllName);
Windows.ResumeThread(mProcessInformation.mThread);
}
//PushMainWidget(mBoard);
}
Result<int> LoadLibraryInjection(Windows.ProcessHandle proc, String dllName)
{
void* RemoteString, LoadLibAddy;
LoadLibAddy = Windows.GetProcAddress(Windows.GetModuleHandleW("kernel32.dll".ToScopedNativeWChar!()), "LoadLibraryA");
RemoteString = Windows.VirtualAllocEx(proc, null, (int)dllName.Length, Windows.MEM_RESERVE|Windows.MEM_COMMIT, Windows.PAGE_READWRITE);
if (RemoteString == null)
{
Windows.CloseHandle(proc); // Close the process handle.
//throw std::runtime_error("LoadLibraryInjection: Error on VirtualAllocEx.");
return .Err;//new Exception("LoadLibraryInjection: Error on VirtualAllocEx.");
}
if (Windows.WriteProcessMemory(proc, (char8*)RemoteString, (char8*)dllName, dllName.Length, null) == 0)
{
Windows.VirtualFreeEx(proc, RemoteString, 0, Windows.MEM_RELEASE); // Free the memory we were going to use.
Windows.CloseHandle(proc); // Close the process handle.
return .Err;//new Exception("LoadLibraryInjection: Error on WriteProcessMemeory.");
}
Windows.Handle hThread;
hThread = Windows.CreateRemoteThread(proc, null, 0, LoadLibAddy, (char8*)RemoteString, 0, null);
if (hThread.IsInvalid)
{
Windows.VirtualFreeEx(proc, RemoteString, 0, Windows.MEM_RELEASE); // Free the memory we were going to use.
Windows.CloseHandle(proc); // Close the process handle.
return .Err;//new Exception("LoadLibraryInjection: Error on CreateRemoteThread.");
}
// Wait for the thread to finish.
Windows.WaitForSingleObject(hThread, -1);
// Lets see what it says...
int32 dwThreadExitCode=0;
Windows.GetExitCodeThread(hThread, out dwThreadExitCode);
// No need for this handle anymore, lets get rid of it.
Windows.CloseHandle(hThread);
// Lets clear up that memory we allocated earlier.
Windows.VirtualFreeEx(proc, RemoteString, 0, Windows.MEM_RELEASE);
return dwThreadExitCode;
}
public override bool HandleCommandLineParam(String key, String value)
{
base.HandleCommandLineParam(key, value);
if (key == "-fullscreen")
{
mWantsFullscreen = true;
return true;
}
if (key == "-windowed")
{
mWantsFullscreen = false;
return true;
}
return false;
}
public void PushMainWidget(Widget widget)
{
if (mMainWidget != null)
{
mMainWidget.RemoveSelf();
DeferDelete(mMainWidget);
}
mMainWidget = widget;
mRootWidget.AddWidget(widget);
widget.Resize(0, 0, mRootWidget.mWidth, mRootWidget.mHeight);
widget.SetFocus();
}
}
}
static
{
static MemProfiler.MPApp gApp;
}

View file

@ -0,0 +1,76 @@
using Beefy.geom;
using System;
namespace Mercury
{
class Perlin
{
Vector2[,] mGradient ~ delete _;
public this(int w, int h, int seed = -1)
{
Random rand;
if (seed == -1)
{
rand = stack Random();
}
else
{
rand = stack Random(seed);
}
mGradient = new Vector2[h, w];
for (int y < h)
{
for (int x < w)
{
float ang = (float)(rand.NextDouble() * Math.PI * 2);
mGradient[y, x] = Vector2((float)Math.Cos(ang), (float)Math.Sin(ang));
}
}
}
float DotGridGradient(int ix, int iy, float x, float y)
{
// Precomputed (or otherwise) gradient vectors at each grid node
// Compute the distance vector
float dx = x - (float)ix;
float dy = y - (float)iy;
// Compute the dot-product
return (dx * mGradient[iy, ix].mX + dy * mGradient[iy, ix].mY);
}
// Compute Perlin noise at coordinates x, y
public float Get(float x, float y)
{
// Determine grid cell coordinates
int x0 = ((x > 0.0) ? (int)x : (int)x - 1);
int x1 = x0 + 1;
int y0 = ((y > 0.0) ? (int)y : (int)y - 1);
int y1 = y0 + 1;
// Determine interpolation weights
// Could also use higher order polynomial/s-curve here
float sx = x - (float)x0;
float sy = y - (float)y0;
// Interpolate between grid point gradients
float n0, n1, ix0, ix1, value;
n0 = DotGridGradient(x0, y0, x, y);
n1 = DotGridGradient(x1, y0, x, y);
ix0 = Math.Lerp(n0, n1, sx);
n0 = DotGridGradient(x0, y1, x, y);
n1 = DotGridGradient(x1, y1, x, y);
ix1 = Math.Lerp(n0, n1, sx);
value = Math.Lerp(ix0, ix1, sy);
return value;
}
public float GetF(float pctX, float pctY)
{
return Get(pctX * mGradient.GetLength(1), pctY * mGradient.GetLength(0));
}
}
}

View file

@ -0,0 +1,22 @@
using System;
namespace MemProfiler
{
class Program
{
public static int32 Main(String[] args)
{
String commandLine = scope String();
commandLine.JoinInto(" ", args);
MPApp mApp = new MPApp();
mApp.ParseCommandLine(commandLine);
mApp.Init();
mApp.Run();
mApp.Shutdown();
delete mApp;
return 0;
}
}
}