mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
default index buffer is now in DEFAULT pool
This commit is contained in:
parent
aaf1e66b97
commit
1bb335675f
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -7,31 +7,42 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
/// <summary> Abstracts a 3D graphics rendering API. </summary>
|
||||
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) {
|
||||
|
@ -30,7 +30,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
glLists = Options.GetBool(OptionsKey.ForceOldOpenGL, false);
|
||||
CustomMipmapsLevels = !glLists;
|
||||
CheckVboSupport();
|
||||
base.InitDynamicBuffers();
|
||||
base.InitCommon();
|
||||
|
||||
setupBatchFuncCol4b = SetupVbPos3fCol4b;
|
||||
setupBatchFuncTex2fCol4b = SetupVbPos3fTex2fCol4b;
|
||||
|
@ -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;
|
||||
|
13
src/Client/Audio.h
Normal file
13
src/Client/Audio.h
Normal file
@ -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
|
@ -181,6 +181,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="2DStructs.h" />
|
||||
<ClInclude Include="AsyncDownloader.h" />
|
||||
<ClInclude Include="Audio.h" />
|
||||
<ClInclude Include="AxisLinesRenderer.h" />
|
||||
<ClInclude Include="BlockID.h" />
|
||||
<ClInclude Include="Block.h" />
|
||||
|
@ -366,6 +366,9 @@
|
||||
<ClInclude Include="TexturePack.h">
|
||||
<Filter>Header Files\TexturePack</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Audio.h">
|
||||
<Filter>Header Files\Game</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Noise.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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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); }
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user