diff --git a/ClassicalSharp/Game/Game.Init.cs b/ClassicalSharp/Game/Game.Init.cs
index 88e4a26a2..337e4029d 100644
--- a/ClassicalSharp/Game/Game.Init.cs
+++ b/ClassicalSharp/Game/Game.Init.cs
@@ -57,7 +57,6 @@ namespace ClassicalSharp {
Components.Add(Mode);
Input = new InputHandler(this);
- defaultIb = Graphics.MakeDefaultIb();
ParticleManager = new ParticleManager(); Components.Add(ParticleManager);
TabList = new TabList(); Components.Add(TabList);
LoadOptions();
diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs
index ef4bf6a71..6dd42012e 100644
--- a/ClassicalSharp/Game/Game.Properties.cs
+++ b/ClassicalSharp/Game/Game.Properties.cs
@@ -107,7 +107,6 @@ namespace ClassicalSharp {
public PickedPos SelectedPos = new PickedPos(), CameraClipPos = new PickedPos();
public ModelCache ModelCache;
internal string skinServer;
- internal int defaultIb;
public OtherEvents Events = new OtherEvents();
public EntityEvents EntityEvents = new EntityEvents();
public WorldEvents WorldEvents = new WorldEvents();
diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs
index d93353286..1dd73343d 100644
--- a/ClassicalSharp/Game/Game.cs
+++ b/ClassicalSharp/Game/Game.cs
@@ -292,7 +292,7 @@ namespace ClassicalSharp {
frameTimer.Start();
Graphics.BeginFrame(this);
- Graphics.BindIb(defaultIb);
+ Graphics.BindIb(Graphics.defaultIb);
accumulator += delta;
Vertices = 0;
Mode.BeginFrame(delta);
@@ -424,7 +424,6 @@ namespace ClassicalSharp {
for (int i = 0; i < Components.Count; i++)
Components[i].Dispose();
- Graphics.DeleteIb(ref defaultIb);
Drawer2D.DisposeInstance();
Graphics.Dispose();
diff --git a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs
index 69ae05bc3..56da2510a 100644
--- a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs
+++ b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs
@@ -55,7 +55,7 @@ namespace ClassicalSharp.GraphicsAPI {
CustomMipmapsLevels = true;
caps = device.Capabilities;
SetDefaultRenderStates();
- InitDynamicBuffers();
+ InitCommon();
}
void FindCompatibleFormat(int adapter) {
@@ -305,7 +305,7 @@ namespace ClassicalSharp.GraphicsAPI {
public override int CreateIb(IntPtr indices, int indicesCount) {
int size = indicesCount * sizeof(ushort);
DataBuffer buffer = device.CreateIndexBuffer(size, Usage.WriteOnly,
- Format.Index16, Pool.Managed);
+ Format.Index16, Pool.Default);
buffer.SetData(indices, size, LockFlags.None);
return GetOrExpand(ref iBuffers, buffer, iBufferSize);
}
diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs b/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs
index e1c0c9974..a873331da 100644
--- a/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs
+++ b/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs
@@ -7,31 +7,42 @@ namespace ClassicalSharp.GraphicsAPI {
/// Abstracts a 3D graphics rendering API.
public abstract unsafe partial class IGraphicsApi {
- protected void InitDynamicBuffers() {
+ public int defaultIb;
+
+ protected void InitCommon() {
quadVb = CreateDynamicVb(VertexFormat.P3fC4b, 4);
texVb = CreateDynamicVb(VertexFormat.P3fT2fC4b, 4);
+
+ const int maxIndices = 65536 / 4 * 6;
+ ushort* indices = stackalloc ushort[maxIndices];
+ MakeIndices(indices, maxIndices);
+ defaultIb = CreateIb((IntPtr)indices, maxIndices);
+ }
+
+ protected void DisposeCommon() {
+ DeleteVb(ref quadVb);
+ DeleteVb(ref texVb);
+ DeleteIb(ref defaultIb);
}
public virtual void Dispose() {
- DeleteVb(ref quadVb);
- DeleteVb(ref texVb);
+ DisposeCommon();
}
public void LoseContext(string reason) {
LostContext = true;
Utils.LogDebug("Lost graphics context" + reason);
- if (ContextLost != null) ContextLost();
- DeleteVb(ref quadVb);
- DeleteVb(ref texVb);
+ if (ContextLost != null) ContextLost();
+ DisposeCommon();
}
public void RecreateContext() {
LostContext = false;
Utils.LogDebug("Recreating graphics context");
- if (ContextRecreated != null) ContextRecreated();
- InitDynamicBuffers();
+ if (ContextRecreated != null) ContextRecreated();
+ InitCommon();
}
@@ -149,13 +160,6 @@ namespace ClassicalSharp.GraphicsAPI {
if (hadFog) Fog = true;
}
- internal unsafe int MakeDefaultIb() {
- const int maxIndices = 65536 / 4 * 6;
- ushort* indices = stackalloc ushort[maxIndices];
- MakeIndices(indices, maxIndices);
- return CreateIb((IntPtr)indices, maxIndices);
- }
-
internal unsafe void MakeIndices(ushort* indices, int iCount) {
int element = 0;
for (int i = 0; i < iCount; i += 6) {
diff --git a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs
index 9fa3c71d6..f886bbcf4 100644
--- a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs
+++ b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs
@@ -30,7 +30,7 @@ namespace ClassicalSharp.GraphicsAPI {
glLists = Options.GetBool(OptionsKey.ForceOldOpenGL, false);
CustomMipmapsLevels = !glLists;
CheckVboSupport();
- base.InitDynamicBuffers();
+ base.InitCommon();
setupBatchFuncCol4b = SetupVbPos3fCol4b;
setupBatchFuncTex2fCol4b = SetupVbPos3fTex2fCol4b;
diff --git a/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs
index 17dbe9106..e6c18c0dc 100644
--- a/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs
+++ b/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs
@@ -17,7 +17,7 @@ namespace ClassicalSharp.GraphicsAPI {
int texDims;
GL.GetInteger(All.MaxTextureSize, &texDims);
textureDims = texDims;
- base.InitDynamicBuffers();
+ base.InitCommon();
// TODO: Support mipmaps
setupBatchFuncCol4b = SetupVbPos3fCol4b;
diff --git a/src/Client/Audio.h b/src/Client/Audio.h
new file mode 100644
index 000000000..839e6208f
--- /dev/null
+++ b/src/Client/Audio.h
@@ -0,0 +1,13 @@
+#ifndef CC_AUDIO_H
+#define CC_AUDIO_H
+#include "GameStructs.h"
+/* Manages playing sound and music.
+ Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
+*/
+
+IGameComponent Audio_MakeComponent(void);
+void Audio_SetMusic(Int32 volume);
+void Audio_SetSounds(Int32 volume);
+void Audio_PlayDigSound(UInt8 type);
+void Audio_PlayStepSound(UInt8 type);
+#endif
\ No newline at end of file
diff --git a/src/Client/Client.vcxproj b/src/Client/Client.vcxproj
index abb5e53cb..63307e211 100644
--- a/src/Client/Client.vcxproj
+++ b/src/Client/Client.vcxproj
@@ -181,6 +181,7 @@
+
diff --git a/src/Client/Client.vcxproj.filters b/src/Client/Client.vcxproj.filters
index 25ae35c53..94993dbbf 100644
--- a/src/Client/Client.vcxproj.filters
+++ b/src/Client/Client.vcxproj.filters
@@ -366,6 +366,9 @@
Header Files\TexturePack
+
+ Header Files\Game
+
diff --git a/src/Client/D3D9Api.c b/src/Client/D3D9Api.c
index bc143e22e..4441594b6 100644
--- a/src/Client/D3D9Api.c
+++ b/src/Client/D3D9Api.c
@@ -56,7 +56,7 @@ void D3D9_FreeResource(GfxResourceID* resource) {
UInt8 logMsgBuffer[String_BufferSize(STRING_SIZE * 2)];
String logMsg = String_InitAndClearArray(logMsgBuffer);
String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: ");
- String_AppendInt32(&logMsg, id);
+ String_AppendInt64(&logMsg, (Int64)(*resource));
Platform_Log(&logMsg);
}
@@ -158,7 +158,12 @@ void Gfx_Init(void) {
D3D9_SetDefaultRenderStates();
GfxCommon_Init();
}
-void Gfx_Free(void) { GfxCommon_Free(); }
+
+void Gfx_Free(void) {
+ GfxCommon_Free();
+ D3D9_FreeResource(&device);
+ D3D9_FreeResource(&d3d);
+}
void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, Int32 lvl) {
D3DLOCKED_RECT rect;
@@ -468,7 +473,7 @@ GfxResourceID Gfx_CreateIb(void* indices, Int32 indicesCount) {
Int32 size = indicesCount * sizeof(UInt16);
IDirect3DIndexBuffer9* ibuffer;
ReturnCode hresult = IDirect3DDevice9_CreateIndexBuffer(device, size, D3DUSAGE_WRITEONLY,
- D3DFMT_INDEX16, D3DPOOL_MANAGED, &ibuffer, NULL);
+ D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ibuffer, NULL);
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateIb");
D3D9_SetIbData(ibuffer, indices, size, "D3D9_CreateIb - Lock", "D3D9_CreateIb - Unlock");
diff --git a/src/Client/EntityComponents.c b/src/Client/EntityComponents.c
index d4b091fd1..458a19b04 100644
--- a/src/Client/EntityComponents.c
+++ b/src/Client/EntityComponents.c
@@ -14,7 +14,7 @@
#include "ModelCache.h"
#include "Physics.h"
#include "IModel.h"
-
+#include "Audio.h"
/*########################################################################################################################*
*----------------------------------------------------AnimatedComponent----------------------------------------------------*
@@ -1261,7 +1261,7 @@ void SoundComp_Tick(bool wasOnGround) {
if (!sounds_AnyNonAir) soundPos = Vector3_BigPos();
if (p->Base.OnGround && (SoundComp_DoPlaySound(p, soundPos) || !wasOnGround)) {
- AudioPlayer_PlayStepSound(sounds_Type);
+ Audio_PlayStepSound(sounds_Type);
sounds_LastPos = soundPos;
}
}
diff --git a/src/Client/Game.c b/src/Client/Game.c
index b62fe6c46..1904f07f5 100644
--- a/src/Client/Game.c
+++ b/src/Client/Game.c
@@ -37,6 +37,7 @@
#include "PickedPosRenderer.h"
#include "GraphicsCommon.h"
#include "Menus.h"
+#include "Audio.h"
IGameComponent Game_Components[26];
Int32 Game_ComponentsCount;
@@ -401,7 +402,6 @@ void Game_Load(void) {
comp = GameMode_MakeComponent(); Game_AddComponent(&comp);
InputHandler_Init();
- defaultIb = Graphics.MakeDefaultIb();
comp = Particles_MakeComponent(); Game_AddComponent(&comp);
comp = TabList_MakeComponent(); Game_AddComponent(&comp);
@@ -468,7 +468,7 @@ void Game_Load(void) {
Gfx_SetAlphaTestFunc(COMPARE_FUNC_GREATER, 0.5f);
comp = PickedPosRenderer_MakeComponent(); Game_AddComponent(&comp);
- comp = AudioPlayer_MakeComponent(); Game_AddComponent(&comp);
+ comp = Audio_MakeComponent(); Game_AddComponent(&comp);
comp = AxisLinesRenderer_MakeComponent(); Game_AddComponent(&comp);
comp = SkyboxRenderer_MakeComponent(); Game_AddComponent(&comp);
@@ -632,7 +632,7 @@ void Game_RenderFrame(Real64 delta) {
Stopwatch_Start(&game_frameTimer);
Gfx_BeginFrame();
- Graphics.BindIb(defaultIb);
+ Gfx_BindIb(GfxCommon_defaultIb);
Game_Accumulator += delta;
Game_Vertices = 0;
GameMode_BeginFrame(delta);
@@ -688,7 +688,6 @@ void Game_Free(void) {
Game_Components[i].Free();
}
- Graphics.DeleteIb(&defaultIb);
Drawer2D_Free();
Gfx_Free();
diff --git a/src/Client/GraphicsCommon.c b/src/Client/GraphicsCommon.c
index 36a88a239..351c126f7 100644
--- a/src/Client/GraphicsCommon.c
+++ b/src/Client/GraphicsCommon.c
@@ -10,11 +10,16 @@
void GfxCommon_Init(void) {
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
GfxCommon_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4);
+
+ UInt16 indices[GFX_MAX_INDICES];
+ GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
+ GfxCommon_defaultIb = Gfx_CreateIb(indices, GFX_MAX_INDICES);
}
void GfxCommon_Free(void) {
Gfx_DeleteVb(&GfxCommon_quadVb);
Gfx_DeleteVb(&GfxCommon_texVb);
+ Gfx_DeleteIb(&GfxCommon_defaultIb);
}
void GfxCommon_LoseContext(STRING_PURE String* reason) {
@@ -126,12 +131,6 @@ void GfxCommon_Mode3D(void) {
if (gfx_hadFog) Gfx_SetFog(true);
}
-GfxResourceID GfxCommon_MakeDefaultIb(void) {
- UInt16 indices[GFX_MAX_INDICES];
- GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
- return Gfx_CreateIb(indices, GFX_MAX_INDICES);
-}
-
void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount) {
Int32 element = 0, i;
diff --git a/src/Client/GraphicsCommon.h b/src/Client/GraphicsCommon.h
index db4ff31bc..8341f4226 100644
--- a/src/Client/GraphicsCommon.h
+++ b/src/Client/GraphicsCommon.h
@@ -8,6 +8,7 @@
*/
typedef struct Texture_ Texture;
+GfxResourceID GfxCommon_defaultIb;
void GfxCommon_Init(void);
void GfxCommon_Free(void);
void GfxCommon_LoseContext(STRING_PURE String* reason);
@@ -29,9 +30,7 @@ void GfxCommon_Make2DQuad(Texture* tex, PackedCol col, VertexP3fT2fC4b** vertice
void GfxCommon_Mode2D(Int32 width, Int32 height);
void GfxCommon_Mode3D(void);
-GfxResourceID GfxCommon_MakeDefaultIb(void);
void GfxCommon_MakeIndices(UInt16* indices, Int32 iCount);
-
void GfxCommon_SetupAlphaState(UInt8 draw);
void GfxCommon_RestoreAlphaState(UInt8 draw);
diff --git a/src/Client/Menus.c b/src/Client/Menus.c
index 3dd05baa6..4dccc0436 100644
--- a/src/Client/Menus.c
+++ b/src/Client/Menus.c
@@ -25,6 +25,7 @@
#include "BlockPhysics.h"
#include "MapRenderer.h"
#include "TexturePack.h"
+#include "Audio.h"
#define LIST_SCREEN_ITEMS 5
#define LIST_SCREEN_BUTTONS (LIST_SCREEN_ITEMS + 3)
@@ -2170,7 +2171,7 @@ const UInt8* ViewDist_Names[ViewDist_Count] = { "TINY", "SHORT", "NORMAL", "FAR"
void ClassicOptionsScreen_GetMusic(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_MusicVolume > 0); }
void ClassicOptionsScreen_SetMusic(STRING_PURE String* v) {
Game_MusicVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0;
- AudioPlayer_SetMusic(Game_MusicVolume);
+ Audio_SetMusic(Game_MusicVolume);
Options_SetInt32(OPT_MUSIC_VOLUME, Game_MusicVolume);
}
@@ -2202,7 +2203,7 @@ void ClassicOptionsScreen_SetPhysics(STRING_PURE String* v) {
void ClassicOptionsScreen_GetSounds(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_SoundsVolume > 0); }
void ClassicOptionsScreen_SetSounds(STRING_PURE String* v) {
Game_SoundsVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0;
- AudioPlayer_SetSounds(Game_SoundsVolume);
+ Audio_SetSounds(Game_SoundsVolume);
Options_SetInt32(OPT_SOUND_VOLUME, Game_SoundsVolume);
}
@@ -2755,14 +2756,14 @@ void MiscOptionsScreen_GetMusic(STRING_TRANSIENT String* v) { String_AppendInt32
void MiscOptionsScreen_SetMusic(STRING_PURE String* v) {
Game_MusicVolume = Menu_Int32(v);
Options_Set(OPT_MUSIC_VOLUME, v);
- AudioPlayer_SetMusic(Game_MusicVolume);
+ Audio_SetMusic(Game_MusicVolume);
}
void MiscOptionsScreen_GetSounds(STRING_TRANSIENT String* v) { String_AppendInt32(v, Game_SoundsVolume); }
void MiscOptionsScreen_SetSounds(STRING_PURE String* v) {
Game_SoundsVolume = Menu_Int32(v);
Options_Set(OPT_SOUND_VOLUME, v);
- AudioPlayer_SetSounds(Game_SoundsVolume);
+ Audio_SetSounds(Game_SoundsVolume);
}
void MiscOptionsScreen_GetViewBob(STRING_TRANSIENT String* v) { Menu_GetBool(v, Game_ViewBobbing); }
diff --git a/src/Client/Typedefs.h b/src/Client/Typedefs.h
index c237003cf..57d835437 100644
--- a/src/Client/Typedefs.h
+++ b/src/Client/Typedefs.h
@@ -58,7 +58,7 @@ typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
#define Int32_MaxValue ((Int32)2147483647L)
#define UInt32_MaxValue ((UInt32)4294967295UL)
-#define USE_DX false
+#define USE_DX true
#if USE_DX
typedef void* GfxResourceID;