port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

227
uc16-4k/main.cpp Normal file
View File

@@ -0,0 +1,227 @@
//#define NOMUSICTIMING
#define MULTISHADER
#include <time.h>
#include <io.h>
#include <process.h>
#include "Shaders.h"
#include "synth.h"
#include "4klang.h"
#define HALF_FAC 2
static const int gi_ScreenWidth = 1280/HALF_FAC;
static const int gi_ScreenHeight = 720/HALF_FAC;
static const char* glUniform4f = "glUniform4f";
HANDLE gh_ShaderCompileEvent;
static char** gs_LastShader_;
static __time64_t gi_ShaderChangedDate;
static unsigned int gi_ShaderProgram;
static unsigned int gi_LastShaderProgram;
static const char* gs_ShaderFile = "mark.fs";
static const PIXELFORMATDESCRIPTOR pfd={
0, 1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 8
};
static DEVMODE dmScreenSettings={
0,0,0,sizeof(dmScreenSettings),0,DM_PELSWIDTH|DM_PELSHEIGHT,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,gi_ScreenWidth,gi_ScreenHeight
};
DWORD WINAPI filemon(void* args)
{
while (true)
{
_finddata_t fdata;
long hfile = _findfirst(gs_ShaderFile, &fdata);
if (hfile != -1)
{
if (fdata.time_write != gi_ShaderChangedDate)
{
gi_ShaderChangedDate = fdata.time_write;
::SetEvent(gh_ShaderCompileEvent);
std::cout << "Shader loaded." << std::endl;
}
_findclose(hfile);
}
::Sleep(100);
}
return 0;
}
bool g_bForceCompile= true;
LRESULT MessageCallback(HWND ar_Handle, UINT aw_Message, WPARAM aw_Param, LPARAM al_Param)
{
return DefWindowProc(ar_Handle, aw_Message, aw_Param, al_Param);
}
int gCurScene= 0;
int gCurSceneStart= 0;
/*int g_SceneLength[]=
{
16, 16, 16,
16, 16, 16,
16, 32, 16,
16, 16, 16,
0x80000000
};
int g_SceneShader[]=
{
0,0,0,
1,1,1,
2,2,2,
3,3,3,
};
float g_SceneFactor[]=
{
0, 0, 0,
0, 0, 1.0f,
0, 0, 1.0f,
0, 1.0f, 1.0f,
0,
};*/
void _cdecl main()
{
//ChangeDisplaySettings (&dmScreenSettings,CDS_FULLSCREEN);
//HDC hDC = GetDC(CreateWindow("edit", 0, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0));
//HWND hWnd = CreateWindow("MDICLIENT", "Test", WS_OVERLAPPED | WS_VISIBLE | WS_SYSMENU, 0, 0, gi_ScreenWidth, gi_ScreenHeight, 0, 0, 0, 0);
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc = (WNDPROC)MessageCallback ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = NULL ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (DKGRAY_BRUSH) ;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Window" ;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
RegisterClassEx(&wndclass);
HWND hWnd = CreateWindow(
"Window", /* Classname */
"Title", /* Title Text */
WS_EX_APPWINDOW, /* default window */
10, /* Windows decides the position */
30, /* where the window ends up on the screen */
gi_ScreenWidth, /* The programs width */
gi_ScreenHeight, /* and height in pixels */
NULL, /* The window is a child-window to desktop */
NULL, /* No menu */
GetModuleHandle(NULL), //GetModuleHandle(NULL), /* Program Instance handler */
NULL /* No Window Creation data */
);
HDC hDC = GetDC(hWnd);
SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
wglMakeCurrent(hDC, wglCreateContext(hDC));
initShaders();
gh_ShaderCompileEvent = ::CreateEvent(NULL, FALSE, FALSE, TEXT("WriteEvent"));
SetThreadPriority((HANDLE)CreateThread(0, 0, &filemon, 0, 0, 0), THREAD_PRIORITY_BELOW_NORMAL);
ShowWindow (hWnd , SW_NORMAL );
LARGE_INTEGER li_OldTime = { 0 };
#ifdef NOMUSICTIMING
int iStartTick= timeGetTime();
#endif
float lf_Time= 0.0f;
do
{
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return;
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (::WaitForSingleObject(gh_ShaderCompileEvent, 0) == WAIT_OBJECT_0 || g_bForceCompile)
{
::Sleep(50);
gi_ShaderProgram = createFragmentProgram(gs_ShaderFile, g_ShaderID, g_ShaderDebug);
PrintErrors();
g_bForceCompile= false;
}
get_Sample();
int Sample= MMTime.u.sample - gCurSceneStart;
int SceneEnd = 8 * SAMPLES_PER_TICK * 8;//samples per tick
#ifdef NOMUSICTIMING
lf_Time = ( timeGetTime() - iStartTick ) * 0.001f / 16.0f;
#endif
glLoadIdentity();
LARGE_INTEGER li_CurrentTime, li_CurrentFrequency;
QueryPerformanceCounter(&li_CurrentTime);
QueryPerformanceFrequency(&li_CurrentFrequency);
//lf_Time = (float)li_CurrentTime.QuadPart / (float)li_CurrentFrequency.QuadPart;
float lf_DiffTime = (float)(li_CurrentTime.QuadPart - li_OldTime.QuadPart) / (float)li_CurrentFrequency.QuadPart;
char windowText[255];
sprintf_s(
windowText,
"Shader: %d Scene: %d AnimFac: %2.2f FPS: %.2f, Render time: %.4fms",
g_ShaderID,
g_SceneID,
g_fSqrAnimFac,
1.0f / lf_DiffTime,
lf_DiffTime );
::SetWindowTextA(hWnd, windowText);
li_OldTime = li_CurrentTime;
lf_Time+= lf_DiffTime * 145.0f / 60.0f / g_fSpeedFac;
if( lf_Time > 1.0f )
{
lf_Time= 0.0f;
if (g_fSqrAnimFac < 0.0)
{
g_SceneID = (g_SceneID + 1) % 16;
}
}
if( lf_Time < 0.0f )
{
lf_Time = 0.0f;
}
if (g_fSqrAnimFac == 0)
{
lf_Time = 0.0f;
}
((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(gi_ShaderProgram);
((PFNGLUNIFORM4FPROC)wglGetProcAddress(glUniform4f))(0, (float)g_SceneID + lf_Time, (GLfloat)gi_ScreenHeight, (GLfloat)0.375f, 0.0f);
MoveCam( lf_Time );
float fDebugData[ 16 ];
fDebugData[ 0 ]= g_DebugCamPos[ 0 ];
fDebugData[ 1 ]= g_DebugCamPos[ 1 ];
fDebugData[ 2 ]= g_DebugCamPos[ 2 ];
fDebugData[ 4 ]= g_DebugCamRot[ 0 ];
fDebugData[ 5 ]= g_DebugCamRot[ 1 ];
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf((GLfloat*)&fDebugData);
glRects(-1, -1, 1, 1);
SwapBuffers(hDC);
}
while ( !GetAsyncKeyState(VK_ESCAPE) );
ExitProcess(0);
}