Started making sure that the DLL is truly platform agnostic. Only thing left seems to be math.h for things like trig functions, and windows.h purely for interlockedincrement and interlockedadd
This commit is contained in:
parent
51955ba765
commit
460c08d169
|
@ -9,7 +9,7 @@ IF NOT EXIST .\build\ mkdir .\build
|
|||
|
||||
C:\programs\ctime\ctime.exe -begin %ProjectDevPath%\build\win32_foldhaus_build_time.ctm
|
||||
|
||||
set CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except- -IC:\programs-dev\gs_libs\src
|
||||
set CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except-
|
||||
set CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -I%CommonLibs% -O2 %CommonCompilerFlags%
|
||||
set CommonLinkerFlags= -opt:ref
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ struct platform_network_address
|
|||
typedef s32 platform_socket_handle;
|
||||
typedef s32 platform_network_address_handle;
|
||||
|
||||
#define PLATFORM_GET_SOCKET_HANDLE(name) platform_socket_handle name(s32 AddressFamily, s32 Type, s32 Protocol)
|
||||
#define PLATFORM_GET_SOCKET_HANDLE(name) platform_socket_handle name(s32 Multicast_TimeToLive)
|
||||
typedef PLATFORM_GET_SOCKET_HANDLE(platform_get_socket_handle);
|
||||
|
||||
#define PLATFORM_GET_SEND_ADDRESS_HANDLE(name) platform_network_address_handle name(s32 AddressFamily, u16 Port, u32 Address)
|
||||
|
@ -116,7 +116,7 @@ typedef PLATFORM_GET_SEND_ADDRESS_HANDLE(platform_get_send_address);
|
|||
#define PLATFORM_SET_SOCKET_OPTION(name) s32 name(platform_socket_handle SocketHandle, s32 Level, s32 Option, const char* OptionValue, s32 OptionLength)
|
||||
typedef PLATFORM_SET_SOCKET_OPTION(platform_set_socket_option);
|
||||
|
||||
#define PLATFORM_SEND_TO(name) s32 name(platform_socket_handle SocketHandle, platform_network_address Address, const char* Buffer, s32 BufferLength, s32 Flags)
|
||||
#define PLATFORM_SEND_TO(name) s32 name(platform_socket_handle SocketHandle, u32 Address, u32 Port, const char* Buffer, s32 BufferLength, s32 Flags)
|
||||
typedef PLATFORM_SEND_TO(platform_send_to);
|
||||
|
||||
#define PLATFORM_CLOSE_SOCKET(name) void name(platform_socket_handle SocketHandle)
|
||||
|
|
|
@ -48,21 +48,15 @@ SACNSendDMXBufferListJob (s32 ThreadID, void* JobData)
|
|||
|
||||
send_sacn_job_data* Data = (send_sacn_job_data*)JobData;
|
||||
platform_socket_handle SendSocket = Data->SendSocket;
|
||||
platform_send_to* SendTo = Data->SendTo;
|
||||
|
||||
dmx_buffer_list* DMXBufferAt = Data->DMXBuffers;
|
||||
while (DMXBufferAt)
|
||||
{
|
||||
dmx_buffer Buffer = DMXBufferAt->Buffer;
|
||||
|
||||
u_long V4SendAddress = SACNGetUniverseSendAddress(Buffer.Universe);
|
||||
u32 V4SendAddress = SACNGetUniverseSendAddress(Buffer.Universe);
|
||||
|
||||
platform_network_address SendAddress = {};
|
||||
SendAddress.Family = AF_INET;
|
||||
SendAddress.Port = DEFAULT_STREAMING_ACN_PORT;
|
||||
SendAddress.Address = V4SendAddress;
|
||||
|
||||
SendTo(SendSocket, SendAddress, (const char*)Buffer.Base, Buffer.TotalSize, 0);
|
||||
Data->SendTo(SendSocket, V4SendAddress, DEFAULT_STREAMING_ACN_PORT, (const char*)Buffer.Base, Buffer.TotalSize, 0);
|
||||
|
||||
DMXBufferAt = DMXBufferAt->Next;
|
||||
}
|
||||
|
@ -75,8 +69,6 @@ RELOAD_STATIC_DATA(ReloadStaticData)
|
|||
app_state* State = (app_state*)Context.MemoryBase;
|
||||
|
||||
GlobalDebugServices = DebugServices;
|
||||
GSAlloc = Alloc;
|
||||
GSFree = Free;
|
||||
}
|
||||
|
||||
INITIALIZE_APPLICATION(InitializeApplication)
|
||||
|
|
|
@ -122,7 +122,6 @@ UpdateSortedNodes(pattern_node_workspace* Workspace, memory_arena* Scratch)
|
|||
}
|
||||
NullTerminate(&OutputString);
|
||||
|
||||
OutputDebugStringA(OutputCharArray);
|
||||
// This is a contiguous array.
|
||||
b8* NodesVisited = PushArray(Scratch, b8, NodeCount);
|
||||
GSZeroArray(NodesVisited, b8, NodeCount);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#ifndef FOLDHAUS_PLATFORM_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define GS_LANGUAGE_NO_PROFILER_DEFINES
|
||||
#include "..\gs_libs\gs_language.h"
|
||||
|
@ -20,18 +19,13 @@
|
|||
#include "..\gs_libs\gs_memory_arena.h"
|
||||
|
||||
#include "..\gs_libs\gs_string.h"
|
||||
#include "foldhaus_debug.h"
|
||||
|
||||
#include "foldhaus_debug.h"
|
||||
global_variable debug_services* GlobalDebugServices;
|
||||
|
||||
global_variable platform_alloc* GSAlloc;
|
||||
global_variable platform_free* GSFree;
|
||||
|
||||
#include "..\gs_libs\gs_vector_matrix.h"
|
||||
|
||||
#include "..\gs_libs\gs_input.h"
|
||||
|
||||
|
||||
#include "foldhaus_renderer.h"
|
||||
|
||||
typedef struct context context;
|
||||
|
@ -101,7 +95,7 @@ struct worker_thread_job
|
|||
|
||||
struct work_queue
|
||||
{
|
||||
HANDLE SemaphoreHandle;
|
||||
void* SemaphoreHandle;
|
||||
|
||||
u32 JobsMax;
|
||||
u32 volatile JobsCount;
|
||||
|
|
|
@ -215,7 +215,7 @@ InitStreamHeader (u8* Buffer, s32 BufferSize,
|
|||
Cursor = PackB2(Cursor, RLP_PREAMBLE_SIZE);
|
||||
Cursor = PackB2(Cursor, RLP_POSTAMBLE_SIZE);
|
||||
|
||||
memcpy(Cursor, ACN_IDENTIFIER, ACN_IDENTIFIER_SIZE);
|
||||
GSMemCopy(ACN_IDENTIFIER, Cursor, ACN_IDENTIFIER_SIZE);
|
||||
Cursor += ACN_IDENTIFIER_SIZE;
|
||||
|
||||
// TODO(Peter): If you never use this anywhere else, go back and remove the parameters
|
||||
|
@ -242,7 +242,8 @@ InitStreamHeader (u8* Buffer, s32 BufferSize,
|
|||
Cursor = PackB4(Cursor, FRAMING_VECTOR);
|
||||
|
||||
// framing source name
|
||||
strncpy((char*)Cursor, SourceName, SOURCE_NAME_SIZE);
|
||||
// :Check
|
||||
GSMemCopy(SourceName, (char*)Cursor, SOURCE_NAME_SIZE);
|
||||
Cursor[SOURCE_NAME_SIZE - 1] = '\0';
|
||||
Cursor += SOURCE_NAME_SIZE;
|
||||
|
||||
|
@ -295,10 +296,8 @@ InitializeSACN ( context Context)
|
|||
{
|
||||
streaming_acn SACN = {};
|
||||
|
||||
SACN.SendSocket = Context.PlatformGetSocketHandle(AF_INET, SOCK_DGRAM, 0);
|
||||
int Multicast_TimeToLive = 20;
|
||||
int Error = Context.PlatformSetSocketOption(SACN.SendSocket, IPPROTO_IP, IP_MULTICAST_TTL,
|
||||
(const char*)(&Multicast_TimeToLive), sizeof(Multicast_TimeToLive));
|
||||
s32 Multicast_TimeToLive = 20;
|
||||
SACN.SendSocket = Context.PlatformGetSocketHandle(Multicast_TimeToLive);
|
||||
SACN.CID = StringToCID_ ("{67F9D986-544E-4abb-8986-D5F79382586C}");
|
||||
|
||||
return SACN;
|
||||
|
@ -331,7 +330,7 @@ SACNPrepareBufferHeader (s32 Universe, u8* Buffer, s32 BufferSize, s32 SizeReser
|
|||
SetStreamHeaderSequence_(Buffer, SACN.SequenceIterator, false);
|
||||
}
|
||||
|
||||
internal u_long
|
||||
internal u32
|
||||
SACNGetUniverseSendAddress(s32 Universe)
|
||||
{
|
||||
u8 MulticastAddressBuffer[4] = {};
|
||||
|
@ -340,7 +339,7 @@ SACNGetUniverseSendAddress(s32 Universe)
|
|||
MulticastAddressBuffer[2] = (u8)((Universe & 0xff00) >> 8); // high bit
|
||||
MulticastAddressBuffer[3] = (u8)((Universe & 0x00ff)); // low bit
|
||||
|
||||
u_long V4Address = (u_long)UpackB4(MulticastAddressBuffer);
|
||||
u32 V4Address = (u32)UpackB4(MulticastAddressBuffer);
|
||||
return V4Address;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,8 +138,29 @@ s32 Win32SocketHandleMax;
|
|||
s32 Win32SocketHandleCount;
|
||||
win32_socket* SocketValues;
|
||||
|
||||
PLATFORM_SET_SOCKET_OPTION(Win32SetSocketOption)
|
||||
{
|
||||
s32 SocketIndex = (s32)SocketHandle;
|
||||
Assert(SocketIndex < Win32SocketHandleCount);
|
||||
int Error = setsockopt(SocketValues[SocketIndex].Socket, Level, Option, OptionValue, OptionLength);
|
||||
if (Error == SOCKET_ERROR)
|
||||
{
|
||||
Error = WSAGetLastError();
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
PLATFORM_GET_SOCKET_HANDLE(Win32GetSocketHandle)
|
||||
{
|
||||
// NOTE(Peter): These used to be passed in as paramters, but we only use this function
|
||||
// with AF_INET, SOCK_DGRAM, and Protocol = 0. These are also platform specific values
|
||||
// so I was having to include windows.h in the platform agnostic code to accomodate that
|
||||
// function signature.
|
||||
s32 AddressFamily = AF_INET;
|
||||
s32 Type = SOCK_DGRAM;
|
||||
s32 Protocol = 0;
|
||||
|
||||
if (Win32SocketHandleCount >= Win32SocketHandleMax)
|
||||
{
|
||||
s32 NewDictionaryMax = Win32SocketHandleMax + SOCKET_DICTIONARY_GROW_SIZE;
|
||||
|
@ -163,20 +184,10 @@ PLATFORM_GET_SOCKET_HANDLE(Win32GetSocketHandle)
|
|||
|
||||
SocketValues[NewSocketIndex].Socket = socket(AddressFamily, Type, Protocol);
|
||||
|
||||
return (platform_socket_handle)NewSocketIndex;
|
||||
}
|
||||
|
||||
PLATFORM_SET_SOCKET_OPTION(Win32SetSocketOption)
|
||||
{
|
||||
s32 SocketIndex = (s32)SocketHandle;
|
||||
Assert(SocketIndex < Win32SocketHandleCount);
|
||||
int Error = setsockopt(SocketValues[SocketIndex].Socket, Level, Option, OptionValue, OptionLength);
|
||||
if (Error == SOCKET_ERROR)
|
||||
{
|
||||
Error = WSAGetLastError();
|
||||
}
|
||||
int Error = Win32SetSocketOption(NewSocketIndex, IPPROTO_IP, IP_MULTICAST_TTL,
|
||||
(const char*)(&Multicast_TimeToLive), sizeof(Multicast_TimeToLive));
|
||||
|
||||
return Error;
|
||||
return (platform_socket_handle)NewSocketIndex;
|
||||
}
|
||||
|
||||
PLATFORM_SEND_TO(Win32SendTo)
|
||||
|
@ -185,9 +196,9 @@ PLATFORM_SEND_TO(Win32SendTo)
|
|||
Assert(SocketIndex < Win32SocketHandleCount);
|
||||
|
||||
sockaddr_in SockAddress = {};
|
||||
SockAddress.sin_family = Address.Family;
|
||||
SockAddress.sin_port = HostToNetU16(Address.Port);
|
||||
SockAddress.sin_addr.s_addr = HostToNetU32(Address.Address);
|
||||
SockAddress.sin_family = AF_INET;
|
||||
SockAddress.sin_port = HostToNetU16(Port);
|
||||
SockAddress.sin_addr.s_addr = HostToNetU32(Address);
|
||||
|
||||
s32 LengthSent = sendto(SocketValues[SocketIndex].Socket, Buffer, BufferLength, Flags, (sockaddr*)&SockAddress, sizeof(sockaddr_in));
|
||||
|
||||
|
|
Loading…
Reference in New Issue