-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
151 lines (126 loc) · 4.56 KB
/
main.c
File metadata and controls
151 lines (126 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "jess_common.h"
#include "jess_config.h"
#include "jess_audio.h"
#include "jess_render.h"
#include "jess_input.h"
#include "jess_graphics.h"
int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
printf("SDL Init failed: %s\n", SDL_GetError());
return 1;
}
// Enable high-DPI support
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
srand(343425);
// Auto-detect resolution if no arguments provided
if (argc == 1) {
SDL_DisplayMode current;
if (SDL_GetCurrentDisplayMode(0, ¤t) == 0) {
printf("Detected display resolution: %dx%d @ %dHz\n", current.w, current.h, current.refresh_rate);
// Set to native resolution if 4K or higher, otherwise use default
if (current.w >= 3840 && current.h >= 2160) {
resx = 3840;
resy = 2160;
printf("Auto-selecting 4K resolution for optimal display\n");
} else if (current.w >= 2560 && current.h >= 1440) {
resx = 2560;
resy = 1440;
printf("Auto-selecting 2K resolution for optimal display\n");
} else if (current.w >= 1920 && current.h >= 1080) {
resx = 1920;
resy = 1080;
printf("Auto-selecting Full HD resolution for optimal display\n");
}
}
}
init_video();
init_audio();
init_tables();
init_big_ball();
get_config_path();
load_config();
// Initialize counters and analysis
memset(&lys, 0, sizeof(lys));
memset(&conteur, 0, sizeof(conteur));
// Set initial values exactly as original jess_playback_start()
conteur.courbe = 0;
conteur.angle = 0;
conteur.angle2 = 0;
conteur.k1 = 0;
conteur.k2 = 0;
conteur.k3 = 10000; // Important for burn_3d effect
conteur.fps = 40;
conteur.mix_reprise = 1000;
conteur.last_flash = 1000;
conteur.burn_mode = 2;
conteur.draw_mode = config.last_draw_mode; // Use saved mode
conteur.blur_mode = config.last_blur_mode; // Use saved mode
conteur.v_angle2 = 1;
conteur.general = 0;
conteur.freeze = 0;
conteur.freeze_mode = 0;
conteur.psy = 0; // Start with basic colors
conteur.analyser = 0;
conteur.term_display = OUI;
lys.E_moyen = 0;
lys.dEdt_moyen = 0;
xres2 = resx / 2;
yres2 = resy / 2;
random_palette();
if (video == 8) {
memset(buffer, 0, resx * resy);
memset(pixel, 0, resx * resy);
} else {
for (int i = 0; i < resx * resy * 4; i += 4) {
buffer[i] = 0; // R
buffer[i+1] = 0; // G
buffer[i+2] = 0; // B
buffer[i+3] = 255; // A
pixel[i] = 0;
pixel[i+1] = 0;
pixel[i+2] = 0;
pixel[i+3] = 255;
}
}
printf("JESS Standalone Visualization Started\n");
printf("Resolution: %dx%d\n", resx, resy);
printf("Controls:\n");
printf(" H: Show help menu\n");
printf(" I: Show current configuration\n");
printf(" Shift+F1-F12: Enable/disable modes\n");
printf(" Left/Right arrows: Cycle through enabled modes\n");
print_config(); // Show initial configuration
// Uint32 last_time = SDL_GetTicks();
while (!quit_app) {
handle_events();
// Handle resolution/video mode changes
if (quit_renderer == 1 && resolution_change == 1) {
printf("Reinitializing for resolution/mode change...\n");
// Update derived values
xres2 = resx / 2;
yres2 = resy / 2;
// Reinitialize - init_video handles all cleanup internally
init_video();
// Only reinitialize tables (they're freed/reallocated in init_tables)
init_tables();
quit_renderer = 0;
resolution_change = 0;
continue;
}
process_audio();
render_frame();
// Adaptive frame timing for optimal performance
static Uint32 last_frame_time = 0;
Uint32 current_time = SDL_GetTicks();
Uint32 frame_time = current_time - last_frame_time;
// Target 60 FPS for smooth 4K rendering
const Uint32 target_frame_time = 16; // ~60 FPS
if (frame_time < target_frame_time) {
SDL_Delay(target_frame_time - frame_time);
}
last_frame_time = SDL_GetTicks();
}
cleanup();
SDL_Quit();
return 0;
}