PacketHandlers -> Protocol and more comments

This commit is contained in:
UnknownShadow200 2019-06-19 21:48:03 +10:00
parent c2a1cdcd1f
commit 9cf3910db1
7 changed files with 21 additions and 37 deletions

View File

@ -217,7 +217,7 @@
<ClInclude Include="Input.h" />
<ClInclude Include="InputHandler.h" />
<ClInclude Include="Menus.h" />
<ClInclude Include="PacketHandlers.h" />
<ClInclude Include="Protocol.h" />
<ClInclude Include="Physics.h" />
<ClInclude Include="Inventory.h" />
<ClInclude Include="IsometricDrawer.h" />
@ -282,7 +282,7 @@
<ClCompile Include="Deflate.c" />
<ClCompile Include="Model.c" />
<ClCompile Include="Menus.c" />
<ClCompile Include="PacketHandlers.c" />
<ClCompile Include="Protocol.c" />
<ClCompile Include="Physics.c" />
<ClCompile Include="IsometricDrawer.c" />
<ClCompile Include="Input.c" />

View File

@ -252,9 +252,6 @@
<ClInclude Include="TexturePack.h">
<Filter>Header Files\TexturePack</Filter>
</ClInclude>
<ClInclude Include="PacketHandlers.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
<ClInclude Include="Window.h">
<Filter>Header Files\Platform</Filter>
</ClInclude>
@ -318,6 +315,9 @@
<ClInclude Include="Generator.h">
<Filter>Header Files\Map</Filter>
</ClInclude>
<ClInclude Include="Protocol.h">
<Filter>Header Files\Network</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="String.c">
@ -434,9 +434,6 @@
<ClCompile Include="TexturePack.c">
<Filter>Source Files\TexturePack</Filter>
</ClCompile>
<ClCompile Include="PacketHandlers.c">
<Filter>Source Files\Network</Filter>
</ClCompile>
<ClCompile Include="EnvRenderer.c">
<Filter>Source Files\Rendering</Filter>
</ClCompile>
@ -548,5 +545,8 @@
<ClCompile Include="Generator.c">
<Filter>Source Files\Map</Filter>
</ClCompile>
<ClCompile Include="Protocol.c">
<Filter>Source Files\Network</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -1,5 +1,5 @@
#ifndef CC_PACKETHANDLERS_H
#define CC_PACKETHANDLERS_H
#ifndef CC_PROTOCOL_H
#define CC_PROTOCOL_H
#include "Input.h"
#include "String.h"
#include "Vectors.h"

View File

@ -230,16 +230,6 @@ static ReturnCode Stream_MemoryReadU8(struct Stream* s, uint8_t* data) {
return 0;
}
static ReturnCode Stream_MemoryWrite(struct Stream* s, const uint8_t* data, uint32_t count, uint32_t* modified) {
count = min(count, s->Meta.Mem.Left);
Mem_Copy(s->Meta.Mem.Cur, data, count);
s->Meta.Mem.Cur += count;
s->Meta.Mem.Left -= count;
*modified = count;
return 0;
}
static ReturnCode Stream_MemorySkip(struct Stream* s, uint32_t count) {
if (count > s->Meta.Mem.Left) return ERR_INVALID_ARGUMENT;
@ -263,8 +253,10 @@ static ReturnCode Stream_MemoryLength(struct Stream* s, uint32_t* length) {
*length = s->Meta.Mem.Length; return 0;
}
static void Stream_CommonMemory(struct Stream* s, void* data, uint32_t len) {
void Stream_ReadonlyMemory(struct Stream* s, void* data, uint32_t len) {
Stream_Init(s);
s->Read = Stream_MemoryRead;
s->ReadU8 = Stream_MemoryReadU8;
s->Skip = Stream_MemorySkip;
s->Seek = Stream_MemorySeek;
s->Position = Stream_MemoryPosition;
@ -276,17 +268,6 @@ static void Stream_CommonMemory(struct Stream* s, void* data, uint32_t len) {
s->Meta.Mem.Base = (uint8_t*)data;
}
void Stream_ReadonlyMemory(struct Stream* s, void* data, uint32_t len) {
Stream_CommonMemory(s, data, len);
s->Read = Stream_MemoryRead;
s->ReadU8 = Stream_MemoryReadU8;
}
void Stream_WriteonlyMemory(struct Stream* s, void* data, uint32_t len) {
Stream_CommonMemory(s, data, len);
s->Write = Stream_MemoryWrite;
}
/*########################################################################################################################*
*----------------------------------------------------BufferedStream-------------------------------------------------------*
@ -296,6 +277,7 @@ static ReturnCode Stream_BufferedRead(struct Stream* s, uint8_t* data, uint32_t
uint32_t read;
ReturnCode res;
/* Refill buffer */
if (!s->Meta.Buffered.Left) {
source = s->Meta.Buffered.Source;
s->Meta.Buffered.Cur = s->Meta.Buffered.Base;
@ -342,7 +324,6 @@ static ReturnCode Stream_BufferedSeek(struct Stream* s, uint32_t position) {
source = s->Meta.Buffered.Source;
res = source->Seek(source, position);
if (res) return res;
s->Meta.Buffered.Cur = s->Meta.Buffered.Base;

View File

@ -12,7 +12,7 @@ struct Stream;
struct Stream {
/* Attempts to read some bytes from this stream. */
ReturnCode (*Read)(struct Stream* s, uint8_t* data, uint32_t count, uint32_t* modified);
/* Attempts to efficiently read a single byte from this stream. (fallbacks to Read) */
/* Attempts to efficiently read a single byte from this stream. (falls back to Read) */
ReturnCode (*ReadU8)(struct Stream* s, uint8_t* data);
/* Attempts to write some bytes to this stream. */
ReturnCode (*Write)(struct Stream* s, const uint8_t* data, uint32_t count, uint32_t* modified);
@ -31,7 +31,6 @@ struct Stream {
union {
FileHandle File;
void* Inflate;
/* NOTE: These structs rely on overlapping Meta_Mem fields being the same! Don't change them */
struct { uint8_t* Cur; uint32_t Left, Length; uint8_t* Base; } Mem;
struct { struct Stream* Source; uint32_t Left, Length; } Portion;
struct { uint8_t* Cur; uint32_t Left, Length; uint8_t* Base; struct Stream* Source; uint32_t End; } Buffered;
@ -62,8 +61,6 @@ CC_API void Stream_FromFile(struct Stream* s, FileHandle file);
CC_API void Stream_ReadonlyPortion(struct Stream* s, struct Stream* source, uint32_t len);
/* Wraps a block of memory, allowing reading from and seeking in the block. */
CC_API void Stream_ReadonlyMemory(struct Stream* s, void* data, uint32_t len);
/* Wraps a block of memory, allowing writing to and seeking in the block. */
CC_API void Stream_WriteonlyMemory(struct Stream* s, void* data, uint32_t len);
/* Wraps another Stream, reading through an intermediary buffer. (Useful for files, since each read call is expensive) */
CC_API void Stream_ReadonlyBuffered(struct Stream* s, struct Stream* source, void* data, uint32_t size);

View File

@ -10,6 +10,8 @@ struct Stream;
#define VORBIS_MAX_BLOCK_SIZE 8192
#define OGG_BUFFER_SIZE (255 * 256)
/* Wraps an OGG container stream around an existing stream. */
/* NOTE: buffer must be of size OGG_BUFFER_SIZE at least. */
void Ogg_MakeStream(struct Stream* stream, uint8_t* buffer, struct Stream* source);
struct Codebook; struct Floor; struct Residue; struct Mapping; struct Mode;
@ -46,8 +48,12 @@ struct VorbisState {
struct imdct_state imdct[2];
};
/* Frees all dynamic memory allocated to decode the given vorbis audio. */
void Vorbis_Free(struct VorbisState* ctx);
/* Reads and decodes the initial vorbis headers and setup data. */
ReturnCode Vorbis_DecodeHeaders(struct VorbisState* ctx);
/* Reads and decodes the current frame's audio data. */
ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx);
/* Produces final interleaved audio samples for the current frame. */
int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data);
#endif