saturday at foldspace

This commit is contained in:
Peter Slattery 2021-02-06 15:10:14 -08:00
parent 63d204364a
commit ac19ab97ba
3 changed files with 148 additions and 37 deletions

View File

@ -23,7 +23,7 @@ BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
while (true) while (true)
{ {
#if 0 #if 1
// TODO(pjs): Removing this block for now - nothing is wrong with it except that SocketPeek is still blocking for some reason // TODO(pjs): Removing this block for now - nothing is wrong with it except that SocketPeek is still blocking for some reason
if (SocketPeek(Data->SocketManager, Data->ListenSocket)) if (SocketPeek(Data->SocketManager, Data->ListenSocket))
{ {
@ -117,7 +117,7 @@ BlumenLumen_CustomInit(app_state* State, context Context)
BLState->MicListenJobData.OutgoingMsgQueue = &BLState->OutgoingMsgQueue; BLState->MicListenJobData.OutgoingMsgQueue = &BLState->OutgoingMsgQueue;
BLState->MicListenJobData.ListenSocket = CreateSocket(Context.SocketManager, "127.0.0.1", "20185"); BLState->MicListenJobData.ListenSocket = CreateSocket(Context.SocketManager, "127.0.0.1", "20185");
//BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData); BLState->MicListenThread = CreateThread(Context.ThreadManager, BlumenLumen_MicListenJob, (u8*)&BLState->MicListenJobData);
gs_const_string SculpturePath = ConstString("data/test_blumen.fold"); gs_const_string SculpturePath = ConstString("data/test_blumen.fold");
LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog); LoadAssembly(&State->Assemblies, &State->LedSystem, State->Transient, Context, SculpturePath, State->GlobalLog);
@ -172,13 +172,13 @@ BlumenLumen_CustomInit(app_state* State, context Context)
return Result; return Result;
} }
u8 temp = 0;
internal void internal void
BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
{ {
blumen_lumen_state* BLState = (blumen_lumen_state*)UserData.Memory; blumen_lumen_state* BLState = (blumen_lumen_state*)UserData.Memory;
MotorTimeElapsed += Context->DeltaTime;
gs_string BlueString = MakeString("blue"); gs_string BlueString = MakeString("blue");
gs_string GreenString = MakeString("green"); gs_string GreenString = MakeString("green");
gs_string ILoveYouString = MakeString("i_love_you"); gs_string ILoveYouString = MakeString("i_love_you");
@ -208,33 +208,47 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
} }
} }
if ((BLState->OutgoingMsgQueue.WriteHead >= BLState->OutgoingMsgQueue.ReadHead) || if (MotorTimeElapsed > OpenClosePeriod)
(BLState->OutgoingMsgQueue.WriteHead < BLState->OutgoingMsgQueue.ReadHead))
{ {
u32 WriteIndex = BLState->OutgoingMsgQueue.WriteHead; // NOTE(pjs):
MotorTimeElapsed = 0;
gs_data* Msg = BLState->OutgoingMsgQueue.Buffers + WriteIndex; u8 Position = LastPosition;
if (Msg->Size == 0) if (LastPosition == 2)
{ {
*Msg = PushSizeToData(&State->Permanent, sizeof(motor_packet)); LastPosition = ClosedValue;
} }
motor_packet* Packet = (motor_packet*)Msg->Memory; else
Packet->FlowerPositions[0] = temp;
Packet->FlowerPositions[1] = temp + 1;
Packet->FlowerPositions[2] = temp + 2;
temp++;
// NOTE(pjs): We increment the write head AFTER we've written so that
// the network thread doesn't think the buffer is ready to send before
// the data is set. We want to avoid the case of:
// 1. Main Thread increments write head to 1
// 2. Network Thread thinks theres a new message to send at 0
// 3. Network Thread sends the message at 0
// 4. Main Thread sets the message at 0
BLState->OutgoingMsgQueue.WriteHead += 1;
if (BLState->OutgoingMsgQueue.WriteHead >= BLUMEN_MESSAGE_QUEUE_COUNT)
{ {
BLState->OutgoingMsgQueue.WriteHead = 0; LastPosition = OpenValue;
}
if ((BLState->OutgoingMsgQueue.WriteHead >= BLState->OutgoingMsgQueue.ReadHead) ||
(BLState->OutgoingMsgQueue.WriteHead < BLState->OutgoingMsgQueue.ReadHead))
{
u32 WriteIndex = BLState->OutgoingMsgQueue.WriteHead;
gs_data* Msg = BLState->OutgoingMsgQueue.Buffers + WriteIndex;
if (Msg->Size == 0)
{
*Msg = PushSizeToData(&State->Permanent, sizeof(motor_packet));
}
motor_packet* Packet = (motor_packet*)Msg->Memory;
Packet->FlowerPositions[0] = Position;
Packet->FlowerPositions[1] = Position;
Packet->FlowerPositions[2] = Position;
// NOTE(pjs): We increment the write head AFTER we've written so that
// the network thread doesn't think the buffer is ready to send before
// the data is set. We want to avoid the case of:
// 1. Main Thread increments write head to 1
// 2. Network Thread thinks theres a new message to send at 0
// 3. Network Thread sends the message at 0
// 4. Main Thread sets the message at 0
BLState->OutgoingMsgQueue.WriteHead += 1;
if (BLState->OutgoingMsgQueue.WriteHead >= BLUMEN_MESSAGE_QUEUE_COUNT)
{
BLState->OutgoingMsgQueue.WriteHead = 0;
}
} }
} }
} }

View File

@ -53,6 +53,62 @@ struct blumen_lumen_state
platform_thread_handle MicListenThread; platform_thread_handle MicListenThread;
mic_listen_job_data MicListenJobData; mic_listen_job_data MicListenJobData;
}; };
// If you change anything, exit lumenarium if its running
// then in this application hit f1 to compile then
// go to remedybg (the debugger) and hit f5
// don't touch this
u8 LastPosition = 1;
u8 ClosedValue = 1;
u8 OpenValue = 2;
r64 MotorTimeElapsed = 0;
r64 OpenClosePeriod = 15.0f;
#define BLUMEN_LUMEN_H #define BLUMEN_LUMEN_H

View File

@ -154,19 +154,53 @@ Win32CreateSocket(platform_socket* Socket, char* Address, char* DefaultPort)
InvalidCodePath; InvalidCodePath;
} }
// If iMode == 0, blocking is enabled
// if iMode != 0, non-blocking mode is enabled
u_long iMode = 1;
Error = ioctlsocket(SocketHandle, FIONBIO, &iMode);
if (Error != NO_ERROR)
{
InvalidCodePath;
}
Error = connect(SocketHandle, InfoAt->ai_addr, (int)InfoAt->ai_addrlen); Error = connect(SocketHandle, InfoAt->ai_addr, (int)InfoAt->ai_addrlen);
if (Error == SOCKET_ERROR) if (Error == SOCKET_ERROR)
{ {
closesocket(SocketHandle); u32 Status = WSAGetLastError();
continue; if (Status == WSAEWOULDBLOCK)
} {
else #if 0
{ TIMEVAL Timeout = { 0, 500 };
Socket->PlatformHandle = (u8*)Win32Alloc(sizeof(SOCKET), 0); fd_set SocketSet = {};
*(SOCKET*)Socket->PlatformHandle = SocketHandle; FD_ZERO(&SocketSet);
Result = true; FD_SET(SocketHandle, &SocketSet);
break; Assert(FD_ISSET(SocketHandle, &SocketSet));
Status = select(0, &SocketSet, 0, 0, {});
if (Status == SOCKET_ERROR)
{
}
else if (Status == 0)
{
}
else
{
}
#endif
}
else
{
closesocket(SocketHandle);
continue;
}
} }
Socket->PlatformHandle = (u8*)Win32Alloc(sizeof(SOCKET), 0);
*(SOCKET*)Socket->PlatformHandle = SocketHandle;
Result = true;
break;
} }
} }
else else
@ -212,7 +246,14 @@ Win32SocketPeek(platform_socket* Socket)
{ {
// TODO(pjs): Error handling // TODO(pjs): Error handling
s32 Error = WSAGetLastError(); s32 Error = WSAGetLastError();
InvalidCodePath; if (Error == WSAEWOULDBLOCK)
{
// NOTE(pjs):
}
else
{
InvalidCodePath;
}
} }
return Result; return Result;
} }