mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 01:55:19 -04:00
Add proper singleplayer support. Can generate new flatgrass worlds with /client gen, also the client starts singleplayer when no arguments are provided.
This commit is contained in:
parent
db800f3b32
commit
7baf64051f
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||||
# Visual Studio 2008
|
# Visual Studio 2010
|
||||||
# SharpDevelop 4.4
|
# SharpDevelop 4.4
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassicalSharp", "ClassicalSharp\ClassicalSharp.csproj", "{BEB1C785-5CAD-48FF-A886-876BF0A318D4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassicalSharp", "ClassicalSharp\ClassicalSharp.csproj", "{BEB1C785-5CAD-48FF-A886-876BF0A318D4}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -33,8 +33,8 @@
|
|||||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<StartAction>Project</StartAction>
|
<StartAction>Project</StartAction>
|
||||||
<StartArguments>wwwf null 127.0.0.1 25566</StartArguments>
|
|
||||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
||||||
|
<StartArguments>wwwf null 127.0.0.1 25566</StartArguments>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<OutputPath>..\output\release\</OutputPath>
|
<OutputPath>..\output\release\</OutputPath>
|
||||||
@ -129,7 +129,6 @@
|
|||||||
<Compile Include="Model\ZombieModel.cs" />
|
<Compile Include="Model\ZombieModel.cs" />
|
||||||
<Compile Include="Network\Enums.cs" />
|
<Compile Include="Network\Enums.cs" />
|
||||||
<Compile Include="Network\INetworkProcessor.cs" />
|
<Compile Include="Network\INetworkProcessor.cs" />
|
||||||
<Compile Include="Network\SinglePlayerServer.cs" />
|
|
||||||
<Compile Include="Network\NetworkProcessor.cs" />
|
<Compile Include="Network\NetworkProcessor.cs" />
|
||||||
<Compile Include="Network\Utils\AsyncDownloader.cs" />
|
<Compile Include="Network\Utils\AsyncDownloader.cs" />
|
||||||
<Compile Include="Network\Utils\FastNetReader.cs" />
|
<Compile Include="Network\Utils\FastNetReader.cs" />
|
||||||
@ -156,6 +155,8 @@
|
|||||||
<Compile Include="Selections\SelectionBox.cs" />
|
<Compile Include="Selections\SelectionBox.cs" />
|
||||||
<Compile Include="Selections\SelectionBoxComparer.cs" />
|
<Compile Include="Selections\SelectionBoxComparer.cs" />
|
||||||
<Compile Include="Selections\SelectionManager.cs" />
|
<Compile Include="Selections\SelectionManager.cs" />
|
||||||
|
<Compile Include="Singleplayer\Commands.cs" />
|
||||||
|
<Compile Include="Singleplayer\Server.cs" />
|
||||||
<Compile Include="Utils\Camera.cs" />
|
<Compile Include="Utils\Camera.cs" />
|
||||||
<Compile Include="Utils\FastBitmap.cs" />
|
<Compile Include="Utils\FastBitmap.cs" />
|
||||||
<Compile Include="Utils\FastColour.cs" />
|
<Compile Include="Utils\FastColour.cs" />
|
||||||
@ -187,6 +188,7 @@
|
|||||||
<Folder Include="Game" />
|
<Folder Include="Game" />
|
||||||
<Folder Include="Model" />
|
<Folder Include="Model" />
|
||||||
<Folder Include="Network\Utils" />
|
<Folder Include="Network\Utils" />
|
||||||
|
<Folder Include="Singleplayer" />
|
||||||
<Folder Include="Utils" />
|
<Folder Include="Utils" />
|
||||||
<Folder Include="Physics" />
|
<Folder Include="Physics" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -23,7 +23,7 @@ namespace ClassicalSharp.Commands {
|
|||||||
RegisterCommand( new ViewDistanceCommand() );
|
RegisterCommand( new ViewDistanceCommand() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterCommand( Command command ) {
|
public void RegisterCommand( Command command ) {
|
||||||
command.Window = Window;
|
command.Window = Window;
|
||||||
foreach( Command cmd in RegisteredCommands ) {
|
foreach( Command cmd in RegisteredCommands ) {
|
||||||
if( Utils.CaselessEquals( cmd.Name, command.Name ) ) {
|
if( Utils.CaselessEquals( cmd.Name, command.Name ) ) {
|
||||||
|
@ -139,7 +139,11 @@ namespace ClassicalSharp {
|
|||||||
MapRenderer = new MapRenderer( this );
|
MapRenderer = new MapRenderer( this );
|
||||||
MapEnvRenderer = new MapEnvRenderer( this );
|
MapEnvRenderer = new MapEnvRenderer( this );
|
||||||
EnvRenderer = new StandardEnvRenderer( this );
|
EnvRenderer = new StandardEnvRenderer( this );
|
||||||
Network = new NetworkProcessor( this );
|
if( IPAddress == null ) {
|
||||||
|
Network = new Singleplayer.SinglePlayerServer( this );
|
||||||
|
} else {
|
||||||
|
Network = new NetworkProcessor( this );
|
||||||
|
}
|
||||||
firstPersonCam = new FirstPersonCamera( this );
|
firstPersonCam = new FirstPersonCamera( this );
|
||||||
thirdPersonCam = new ThirdPersonCamera( this );
|
thirdPersonCam = new ThirdPersonCamera( this );
|
||||||
Camera = firstPersonCam;
|
Camera = firstPersonCam;
|
||||||
|
@ -18,31 +18,41 @@ namespace ClassicalSharp {
|
|||||||
if( !AllResourcesExist( "terrain.png", "char.png", "clouds.png" ) ) {
|
if( !AllResourcesExist( "terrain.png", "char.png", "clouds.png" ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( args.Length < 4 ) {
|
if( args.Length == 0 ) {
|
||||||
|
Utils.Log( "Starting singleplayer mode." );
|
||||||
|
using( Game game = new Game() ) {
|
||||||
|
game.Username = "LocalPlayer";
|
||||||
|
game.skinServer = "http://s3.amazonaws.com/MinecraftSkins/";
|
||||||
|
game.Run();
|
||||||
|
}
|
||||||
|
} else if( args.Length < 4 ) {
|
||||||
Fail( "ClassicalSharp.exe is only the raw client. You must either use the launcher or"
|
Fail( "ClassicalSharp.exe is only the raw client. You must either use the launcher or"
|
||||||
+ " provide command line arguments to start the client." );
|
+ " provide command line arguments to start the client." );
|
||||||
return;
|
} else {
|
||||||
|
RunMultiplayer( args );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RunMultiplayer( string[] args ) {
|
||||||
|
IPAddress ip = null;
|
||||||
|
if( !IPAddress.TryParse( args[2], out ip ) ) {
|
||||||
|
Fail( "Invalid IP \"" + args[2] + '"' );
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ip = null;
|
int port = 0;
|
||||||
if( !IPAddress.TryParse( args[2], out ip ) ) {
|
if( !Int32.TryParse( args[3], out port ) ) {
|
||||||
Fail( "Invalid IP \"" + args[2] + '"' );
|
Fail( "Invalid port \"" + args[3] + '"' );
|
||||||
}
|
return;
|
||||||
|
} else if( port < ushort.MinValue || port > ushort.MaxValue ) {
|
||||||
|
Fail( "Specified port " + port + " is out of valid range." );
|
||||||
|
}
|
||||||
|
|
||||||
int port = 0;
|
string skinServer = args.Length >= 5 ? args[4] : "http://s3.amazonaws.com/MinecraftSkins/";
|
||||||
if( !Int32.TryParse( args[3], out port ) ) {
|
|
||||||
Fail( "Invalid port \"" + args[3] + '"' );
|
|
||||||
return;
|
|
||||||
} else if( port < ushort.MinValue || port > ushort.MaxValue ) {
|
|
||||||
Fail( "Specified port " + port + " is out of valid range." );
|
|
||||||
}
|
|
||||||
|
|
||||||
string skinServer = args.Length >= 5 ? args[4] : "http://s3.amazonaws.com/MinecraftSkins/";
|
|
||||||
using( Game game = new Game() ) {
|
using( Game game = new Game() ) {
|
||||||
game.Username = args[0];
|
game.Username = args[0];
|
||||||
game.Mppass = args[1];
|
game.Mppass = args[1];
|
||||||
game.IPAddress = ip;
|
game.IPAddress = ip;
|
||||||
game.Port = port;
|
game.Port = port;
|
||||||
game.skinServer = skinServer;
|
game.skinServer = skinServer;
|
||||||
game.Run();
|
game.Run();
|
||||||
}
|
}
|
||||||
@ -87,7 +97,7 @@ namespace ClassicalSharp {
|
|||||||
"(and the circumstances that caused it) to github.com/UnknownShadow200/ClassicalSharp/issues" +
|
"(and the circumstances that caused it) to github.com/UnknownShadow200/ClassicalSharp/issues" +
|
||||||
Environment.NewLine + Environment.NewLine + error;
|
Environment.NewLine + Environment.NewLine + error;
|
||||||
|
|
||||||
MessageBox.Show( "Oh dear. ClassicalSharp has crashed." + Environment.NewLine + Environment.NewLine + message, "ClassicalSharp has crashed" );
|
MessageBox.Show( "Oh dear. ClassicalSharp has crashed." + Environment.NewLine + Environment.NewLine + message, "ClassicalSharp has crashed" );
|
||||||
Environment.Exit( 1 );
|
Environment.Exit( 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
ClassicalSharp/Singleplayer/Commands.cs
Normal file
43
ClassicalSharp/Singleplayer/Commands.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using ClassicalSharp.Commands;
|
||||||
|
|
||||||
|
namespace ClassicalSharp.Singleplayer {
|
||||||
|
|
||||||
|
/// <summary> Command that modifies the font size of chat in the normal gui screen. </summary>
|
||||||
|
public sealed class GenerateCommand : Command {
|
||||||
|
|
||||||
|
public GenerateCommand() {
|
||||||
|
Name = "Generate";
|
||||||
|
Help = new [] {
|
||||||
|
"&a/client generate [width height length]",
|
||||||
|
"&bwidth: &eSpecifies X-axis/width of the new map.",
|
||||||
|
"&bheight: &eSpecifies Y-axis/height of the new map.",
|
||||||
|
"&blength: &eSpecifies Z-axis/length of the new map.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Execute( CommandReader reader ) {
|
||||||
|
int width, height, length;
|
||||||
|
if( !reader.NextInt( out width ) || !reader.NextInt( out height ) || !reader.NextInt( out length ) ) {
|
||||||
|
Window.AddChat( "&e/client generate: &cInvalid dimensions." );
|
||||||
|
} else {
|
||||||
|
if( width < 16 || height < 16 || length < 16 ) {
|
||||||
|
Window.AddChat( "&e/client generate: &cDimensions too small." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if( width > 1024 || height > 1024 || length > 1024 ) {
|
||||||
|
Window.AddChat( "&e/client generate: &cDimensions too large." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if( !( Window.Network is SinglePlayerServer ) ) {
|
||||||
|
Window.AddChat( "&e/client generate: &cThis command only works in singleplayer mode." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SinglePlayerServer server = (SinglePlayerServer)Window.Network;
|
||||||
|
server.NewMap();
|
||||||
|
Window.chatInInputBuffer = "";
|
||||||
|
server.MakeMap( width, height, length );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ using System.Net;
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp.Singleplayer {
|
||||||
|
|
||||||
public sealed class SinglePlayerServer : INetworkProcessor {
|
public sealed class SinglePlayerServer : INetworkProcessor {
|
||||||
|
|
||||||
@ -23,7 +23,8 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
game.RaiseBlockPermissionsChanged();
|
game.RaiseBlockPermissionsChanged();
|
||||||
NewMap();
|
NewMap();
|
||||||
MapLoaded();
|
MakeMap( 128, 128, 128 );
|
||||||
|
game.CommandManager.RegisterCommand( new GenerateCommand() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SendChat( string text ) {
|
public override void SendChat( string text ) {
|
||||||
@ -48,7 +49,7 @@ namespace ClassicalSharp {
|
|||||||
if( Disconnected ) return;
|
if( Disconnected ) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewMap() {
|
internal void NewMap() {
|
||||||
ServerName = "Single player";
|
ServerName = "Single player";
|
||||||
ServerMotd = "Generating a map..";
|
ServerMotd = "Generating a map..";
|
||||||
game.LocalPlayer.UserType = 0x64;
|
game.LocalPlayer.UserType = 0x64;
|
||||||
@ -58,25 +59,25 @@ namespace ClassicalSharp {
|
|||||||
game.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ) );
|
game.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLoaded() {
|
internal unsafe void MakeMap( int width, int height, int length ) {
|
||||||
game.SetNewScreen( new NormalScreen( game ) );
|
|
||||||
int width = 16, height = 16, length = 16;
|
|
||||||
byte[] map = new byte[width * height * length];
|
byte[] map = new byte[width * height * length];
|
||||||
MapSet( width, length, map, 0, height / 2 - 2, (byte)Block.Dirt );
|
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||||
MapSet( width, length, map, height / 2 - 1, height / 2 - 1, (byte)Block.Grass );
|
fixed( byte* ptr = map ) {
|
||||||
|
MapSet( width, length, ptr, 0, height / 2 - 2, (byte)Block.Dirt );
|
||||||
|
MapSet( width, length, ptr, height / 2 - 1, height / 2 - 1, (byte)Block.Grass );
|
||||||
|
}
|
||||||
game.Map.UseRawMap( map, width, height, length );
|
game.Map.UseRawMap( map, width, height, length );
|
||||||
game.RaiseOnNewMapLoaded();
|
game.RaiseOnNewMapLoaded();
|
||||||
|
game.SetNewScreen( new NormalScreen( game ) );
|
||||||
ResetPlayerPosition();
|
ResetPlayerPosition();
|
||||||
game.AddChat( "&ePlaying single player", CpeMessage.Status1 );
|
game.AddChat( "&ePlaying single player", CpeMessage.Status1 );
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapSet( int width, int length, byte[] map, int yStart, int yEnd, byte block ) {
|
unsafe void MapSet( int width, int length, byte* ptr, int yStart, int yEnd, byte block ) {
|
||||||
int startIndex = yStart * length * width;
|
int startIndex = yStart * length * width;
|
||||||
int endIndex = ( yEnd * length + (length - 1) ) * width + (width - 1);
|
int endIndex = ( yEnd * length + (length - 1) ) * width + (width - 1);
|
||||||
for( int i = startIndex; i <= endIndex; i++ ) {
|
MemUtils.memset( (IntPtr)ptr, block, startIndex, endIndex - startIndex + 1 );
|
||||||
map[i] = block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetPlayerPosition() {
|
void ResetPlayerPosition() {
|
67
OpenTK/MemUtils.cs
Normal file
67
OpenTK/MemUtils.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace OpenTK {
|
||||||
|
|
||||||
|
public static class MemUtils {
|
||||||
|
|
||||||
|
static MemUtils() {
|
||||||
|
use64Bit = IntPtr.Size == 8;
|
||||||
|
}
|
||||||
|
static bool use64Bit;
|
||||||
|
|
||||||
|
public static unsafe void memcpy( IntPtr srcPtr, IntPtr dstPtr, int bytes ) {
|
||||||
|
byte* srcByte, dstByte;
|
||||||
|
if( use64Bit ) {
|
||||||
|
ulong* srcLong = (ulong*)srcPtr, dstLong = (ulong*)dstPtr;
|
||||||
|
while( bytes >= 8 ) {
|
||||||
|
*dstLong++ = *srcLong++;
|
||||||
|
bytes -= 8;
|
||||||
|
}
|
||||||
|
srcByte = (byte*)srcLong; dstByte = (byte*)dstLong;
|
||||||
|
} else {
|
||||||
|
uint* srcInt = (uint*)srcPtr, dstInt = (uint*)dstPtr;
|
||||||
|
while( bytes >= 4 ) {
|
||||||
|
*dstInt++ = *srcInt++;
|
||||||
|
bytes -= 4;
|
||||||
|
}
|
||||||
|
srcByte = (byte*)srcInt; dstByte = (byte*)dstInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < bytes; i++ ) {
|
||||||
|
*dstByte++ = *srcByte++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe void memset( IntPtr srcPtr, byte value, int startIndex, int bytes ) {
|
||||||
|
byte* srcByte = (byte*)srcPtr + startIndex;
|
||||||
|
// Make sure we do an aligned write/read for the bulk copy
|
||||||
|
while( bytes > 0 && ( startIndex & 0x7 ) != 0 ) {
|
||||||
|
*srcByte++ = value;
|
||||||
|
startIndex++;
|
||||||
|
bytes--;
|
||||||
|
}
|
||||||
|
uint valueInt = (uint)( ( value << 24 ) | ( value << 16 ) | ( value << 8 ) | value );
|
||||||
|
|
||||||
|
if( use64Bit ) {
|
||||||
|
ulong valueLong = ( (ulong)valueInt << 32 ) | valueInt;
|
||||||
|
ulong* srcLong = (ulong*)srcByte;
|
||||||
|
while( bytes >= 8 ) {
|
||||||
|
*srcLong++ = valueLong;
|
||||||
|
bytes -= 8;
|
||||||
|
}
|
||||||
|
srcByte = (byte*)srcLong;
|
||||||
|
} else {
|
||||||
|
uint* srcInt = (uint*)srcByte;
|
||||||
|
while( bytes >= 4 ) {
|
||||||
|
*srcInt++ = valueInt;
|
||||||
|
bytes -= 4;
|
||||||
|
}
|
||||||
|
srcByte = (byte*)srcInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < bytes; i++ ) {
|
||||||
|
*srcByte++ = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BindingsBase.cs" />
|
<Compile Include="BindingsBase.cs" />
|
||||||
<Compile Include="Configuration.cs" />
|
|
||||||
<Compile Include="DisplayDevice.cs" />
|
<Compile Include="DisplayDevice.cs" />
|
||||||
<Compile Include="DisplayResolution.cs" />
|
<Compile Include="DisplayResolution.cs" />
|
||||||
<Compile Include="FrameEventArgs.cs" />
|
<Compile Include="FrameEventArgs.cs" />
|
||||||
@ -62,6 +61,7 @@
|
|||||||
<Compile Include="INativeWindow.cs" />
|
<Compile Include="INativeWindow.cs" />
|
||||||
<Compile Include="Interop.cs" />
|
<Compile Include="Interop.cs" />
|
||||||
<Compile Include="KeyPressEventArgs.cs" />
|
<Compile Include="KeyPressEventArgs.cs" />
|
||||||
|
<Compile Include="MemUtils.cs" />
|
||||||
<Compile Include="NativeWindow.cs" />
|
<Compile Include="NativeWindow.cs" />
|
||||||
<Compile Include="Graphics\ColorFormat.cs" />
|
<Compile Include="Graphics\ColorFormat.cs" />
|
||||||
<Compile Include="Graphics\GraphicsContextBase.cs" />
|
<Compile Include="Graphics\GraphicsContextBase.cs" />
|
||||||
@ -80,6 +80,7 @@
|
|||||||
<Compile Include="Math\Vector2.cs" />
|
<Compile Include="Math\Vector2.cs" />
|
||||||
<Compile Include="Math\Vector3.cs" />
|
<Compile Include="Math\Vector3.cs" />
|
||||||
<Compile Include="Math\Vector4.cs" />
|
<Compile Include="Math\Vector4.cs" />
|
||||||
|
<Compile Include="Platform\Configuration.cs" />
|
||||||
<Compile Include="Platform\IDisplayDeviceDriver.cs" />
|
<Compile Include="Platform\IDisplayDeviceDriver.cs" />
|
||||||
<Compile Include="Platform\IPlatformFactory.cs" />
|
<Compile Include="Platform\IPlatformFactory.cs" />
|
||||||
<Compile Include="Platform\IWindowInfo.cs" />
|
<Compile Include="Platform\IWindowInfo.cs" />
|
||||||
|
@ -34,7 +34,6 @@ namespace SharpDX.Direct3D9 {
|
|||||||
Adapters = new List<AdapterInformation>( count );
|
Adapters = new List<AdapterInformation>( count );
|
||||||
for( int i = 0; i < count; i++ )
|
for( int i = 0; i < count; i++ )
|
||||||
Adapters.Add( new AdapterInformation( this, i ) );
|
Adapters.Add( new AdapterInformation( this, i ) );
|
||||||
memcpy64Bit = IntPtr.Size == 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AdapterInformation> Adapters;
|
public List<AdapterInformation> Adapters;
|
||||||
@ -104,29 +103,5 @@ namespace SharpDX.Direct3D9 {
|
|||||||
if( res < 0 ) { throw new SharpDXException( res ); }
|
if( res < 0 ) { throw new SharpDXException( res ); }
|
||||||
return new Device( devicePtr );
|
return new Device( devicePtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Place this in a utilities class.
|
|
||||||
static bool memcpy64Bit;
|
|
||||||
internal static unsafe void memcpy( IntPtr srcPtr, IntPtr dstPtr, int bytes ) {
|
|
||||||
byte* srcByte, dstByte;
|
|
||||||
if( memcpy64Bit ) {
|
|
||||||
long* srcLong = (long*)srcPtr, dstLong = (long*)dstPtr;
|
|
||||||
while( bytes >= 8 ) {
|
|
||||||
*dstLong++ = *srcLong++;
|
|
||||||
bytes -= 8;
|
|
||||||
}
|
|
||||||
srcByte = (byte*)srcLong; dstByte = (byte*)dstLong;
|
|
||||||
} else {
|
|
||||||
int* srcInt = (int*)srcPtr, dstInt = (int*)dstPtr;
|
|
||||||
while( bytes >= 4 ) {
|
|
||||||
*dstInt++ = *srcInt++;
|
|
||||||
bytes -= 4;
|
|
||||||
}
|
|
||||||
srcByte = (byte*)srcInt; dstByte = (byte*)dstInt;
|
|
||||||
}
|
|
||||||
for( int i = 0; i < bytes; i++ ) {
|
|
||||||
*dstByte++ = *srcByte++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,14 +57,14 @@ namespace SharpDX.Direct3D9 {
|
|||||||
|
|
||||||
public void SetData( IntPtr data, int bytes, LockFlags flags ) {
|
public void SetData( IntPtr data, int bytes, LockFlags flags ) {
|
||||||
IntPtr dst = Lock( 0, bytes, flags );
|
IntPtr dst = Lock( 0, bytes, flags );
|
||||||
Direct3D.memcpy( data, dst, bytes );
|
MemUtils.memcpy( data, dst, bytes );
|
||||||
Unlock();
|
Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetData<T>( T[] data, int bytes, LockFlags flags ) where T : struct {
|
public void SetData<T>( T[] data, int bytes, LockFlags flags ) where T : struct {
|
||||||
IntPtr src = Interop.Fixed( ref data[0] );
|
IntPtr src = Interop.Fixed( ref data[0] );
|
||||||
IntPtr dst = Lock( 0, bytes, flags );
|
IntPtr dst = Lock( 0, bytes, flags );
|
||||||
Direct3D.memcpy( src, dst, bytes );
|
MemUtils.memcpy( src, dst, bytes );
|
||||||
Unlock();
|
Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ namespace SharpDX.Direct3D9 {
|
|||||||
|
|
||||||
public void SetData( IntPtr data, int bytes, int level, LockFlags flags ) {
|
public void SetData( IntPtr data, int bytes, int level, LockFlags flags ) {
|
||||||
LockedRectangle rect = LockRectangle( level, flags );
|
LockedRectangle rect = LockRectangle( level, flags );
|
||||||
Direct3D.memcpy( data, rect.DataPointer, bytes );
|
MemUtils.memcpy( data, rect.DataPointer, bytes );
|
||||||
UnlockRectangle( level );
|
UnlockRectangle( level );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user