mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
PacketHandlers -> Protocol and more comments
This commit is contained in:
parent
c2a1cdcd1f
commit
9cf3910db1
@ -217,7 +217,7 @@
|
|||||||
<ClInclude Include="Input.h" />
|
<ClInclude Include="Input.h" />
|
||||||
<ClInclude Include="InputHandler.h" />
|
<ClInclude Include="InputHandler.h" />
|
||||||
<ClInclude Include="Menus.h" />
|
<ClInclude Include="Menus.h" />
|
||||||
<ClInclude Include="PacketHandlers.h" />
|
<ClInclude Include="Protocol.h" />
|
||||||
<ClInclude Include="Physics.h" />
|
<ClInclude Include="Physics.h" />
|
||||||
<ClInclude Include="Inventory.h" />
|
<ClInclude Include="Inventory.h" />
|
||||||
<ClInclude Include="IsometricDrawer.h" />
|
<ClInclude Include="IsometricDrawer.h" />
|
||||||
@ -282,7 +282,7 @@
|
|||||||
<ClCompile Include="Deflate.c" />
|
<ClCompile Include="Deflate.c" />
|
||||||
<ClCompile Include="Model.c" />
|
<ClCompile Include="Model.c" />
|
||||||
<ClCompile Include="Menus.c" />
|
<ClCompile Include="Menus.c" />
|
||||||
<ClCompile Include="PacketHandlers.c" />
|
<ClCompile Include="Protocol.c" />
|
||||||
<ClCompile Include="Physics.c" />
|
<ClCompile Include="Physics.c" />
|
||||||
<ClCompile Include="IsometricDrawer.c" />
|
<ClCompile Include="IsometricDrawer.c" />
|
||||||
<ClCompile Include="Input.c" />
|
<ClCompile Include="Input.c" />
|
||||||
|
@ -252,9 +252,6 @@
|
|||||||
<ClInclude Include="TexturePack.h">
|
<ClInclude Include="TexturePack.h">
|
||||||
<Filter>Header Files\TexturePack</Filter>
|
<Filter>Header Files\TexturePack</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="PacketHandlers.h">
|
|
||||||
<Filter>Header Files\Network</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Window.h">
|
<ClInclude Include="Window.h">
|
||||||
<Filter>Header Files\Platform</Filter>
|
<Filter>Header Files\Platform</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -318,6 +315,9 @@
|
|||||||
<ClInclude Include="Generator.h">
|
<ClInclude Include="Generator.h">
|
||||||
<Filter>Header Files\Map</Filter>
|
<Filter>Header Files\Map</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Protocol.h">
|
||||||
|
<Filter>Header Files\Network</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="String.c">
|
<ClCompile Include="String.c">
|
||||||
@ -434,9 +434,6 @@
|
|||||||
<ClCompile Include="TexturePack.c">
|
<ClCompile Include="TexturePack.c">
|
||||||
<Filter>Source Files\TexturePack</Filter>
|
<Filter>Source Files\TexturePack</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="PacketHandlers.c">
|
|
||||||
<Filter>Source Files\Network</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="EnvRenderer.c">
|
<ClCompile Include="EnvRenderer.c">
|
||||||
<Filter>Source Files\Rendering</Filter>
|
<Filter>Source Files\Rendering</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -548,5 +545,8 @@
|
|||||||
<ClCompile Include="Generator.c">
|
<ClCompile Include="Generator.c">
|
||||||
<Filter>Source Files\Map</Filter>
|
<Filter>Source Files\Map</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Protocol.c">
|
||||||
|
<Filter>Source Files\Network</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef CC_PACKETHANDLERS_H
|
#ifndef CC_PROTOCOL_H
|
||||||
#define CC_PACKETHANDLERS_H
|
#define CC_PROTOCOL_H
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include "Vectors.h"
|
#include "Vectors.h"
|
27
src/Stream.c
27
src/Stream.c
@ -230,16 +230,6 @@ static ReturnCode Stream_MemoryReadU8(struct Stream* s, uint8_t* data) {
|
|||||||
return 0;
|
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) {
|
static ReturnCode Stream_MemorySkip(struct Stream* s, uint32_t count) {
|
||||||
if (count > s->Meta.Mem.Left) return ERR_INVALID_ARGUMENT;
|
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;
|
*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);
|
Stream_Init(s);
|
||||||
|
s->Read = Stream_MemoryRead;
|
||||||
|
s->ReadU8 = Stream_MemoryReadU8;
|
||||||
s->Skip = Stream_MemorySkip;
|
s->Skip = Stream_MemorySkip;
|
||||||
s->Seek = Stream_MemorySeek;
|
s->Seek = Stream_MemorySeek;
|
||||||
s->Position = Stream_MemoryPosition;
|
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;
|
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-------------------------------------------------------*
|
*----------------------------------------------------BufferedStream-------------------------------------------------------*
|
||||||
@ -296,6 +277,7 @@ static ReturnCode Stream_BufferedRead(struct Stream* s, uint8_t* data, uint32_t
|
|||||||
uint32_t read;
|
uint32_t read;
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
|
/* Refill buffer */
|
||||||
if (!s->Meta.Buffered.Left) {
|
if (!s->Meta.Buffered.Left) {
|
||||||
source = s->Meta.Buffered.Source;
|
source = s->Meta.Buffered.Source;
|
||||||
s->Meta.Buffered.Cur = s->Meta.Buffered.Base;
|
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;
|
source = s->Meta.Buffered.Source;
|
||||||
res = source->Seek(source, position);
|
res = source->Seek(source, position);
|
||||||
|
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
|
|
||||||
s->Meta.Buffered.Cur = s->Meta.Buffered.Base;
|
s->Meta.Buffered.Cur = s->Meta.Buffered.Base;
|
||||||
|
@ -12,7 +12,7 @@ struct Stream;
|
|||||||
struct Stream {
|
struct Stream {
|
||||||
/* Attempts to read some bytes from this stream. */
|
/* Attempts to read some bytes from this stream. */
|
||||||
ReturnCode (*Read)(struct Stream* s, uint8_t* data, uint32_t count, uint32_t* modified);
|
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);
|
ReturnCode (*ReadU8)(struct Stream* s, uint8_t* data);
|
||||||
/* Attempts to write some bytes to this stream. */
|
/* Attempts to write some bytes to this stream. */
|
||||||
ReturnCode (*Write)(struct Stream* s, const uint8_t* data, uint32_t count, uint32_t* modified);
|
ReturnCode (*Write)(struct Stream* s, const uint8_t* data, uint32_t count, uint32_t* modified);
|
||||||
@ -31,7 +31,6 @@ struct Stream {
|
|||||||
union {
|
union {
|
||||||
FileHandle File;
|
FileHandle File;
|
||||||
void* Inflate;
|
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 { uint8_t* Cur; uint32_t Left, Length; uint8_t* Base; } Mem;
|
||||||
struct { struct Stream* Source; uint32_t Left, Length; } Portion;
|
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;
|
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);
|
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. */
|
/* 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);
|
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) */
|
/* 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);
|
CC_API void Stream_ReadonlyBuffered(struct Stream* s, struct Stream* source, void* data, uint32_t size);
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ struct Stream;
|
|||||||
#define VORBIS_MAX_BLOCK_SIZE 8192
|
#define VORBIS_MAX_BLOCK_SIZE 8192
|
||||||
#define OGG_BUFFER_SIZE (255 * 256)
|
#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);
|
void Ogg_MakeStream(struct Stream* stream, uint8_t* buffer, struct Stream* source);
|
||||||
struct Codebook; struct Floor; struct Residue; struct Mapping; struct Mode;
|
struct Codebook; struct Floor; struct Residue; struct Mapping; struct Mode;
|
||||||
|
|
||||||
@ -46,8 +48,12 @@ struct VorbisState {
|
|||||||
struct imdct_state imdct[2];
|
struct imdct_state imdct[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Frees all dynamic memory allocated to decode the given vorbis audio. */
|
||||||
void Vorbis_Free(struct VorbisState* ctx);
|
void Vorbis_Free(struct VorbisState* ctx);
|
||||||
|
/* Reads and decodes the initial vorbis headers and setup data. */
|
||||||
ReturnCode Vorbis_DecodeHeaders(struct VorbisState* ctx);
|
ReturnCode Vorbis_DecodeHeaders(struct VorbisState* ctx);
|
||||||
|
/* Reads and decodes the current frame's audio data. */
|
||||||
ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx);
|
ReturnCode Vorbis_DecodeFrame(struct VorbisState* ctx);
|
||||||
|
/* Produces final interleaved audio samples for the current frame. */
|
||||||
int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data);
|
int Vorbis_OutputFrame(struct VorbisState* ctx, int16_t* data);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user