Skip to content

Commit c624899

Browse files
committed
now it's work on windows (but only if you install clion, install mingw-64, install all sdl-libraries, copy needed sdl folders in specific mingw-64 folders), now texture draw.
1 parent 2f2b892 commit c624899

8 files changed

Lines changed: 91 additions & 56 deletions

File tree

CMakeLists.txt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,41 @@ set_target_properties(Wolf3D
1313
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
1414
)
1515

16-
if (NOT SDL2_FOUND)
17-
set(SDL2_PATH /Users/$ENV{USER}/.brew/Cellar/sdl2/2.0.9_1)
16+
if (APPLE)
17+
if (NOT SDL2_FOUND)
18+
set(SDL2_PATH /Users/$ENV{USER}/.brew/Cellar/sdl2/2.0.9_1)
19+
endif()
20+
21+
if (NOT SDL2_IMAGE_FOUND)
22+
set(SDL2_IMAGE_PATH /Users/$ENV{USER}/.brew/Cellar/sdl2_image/2.0.5)
23+
endif()
24+
25+
if (NOT SDL2_TTF_FOUND)
26+
set(SDL2_TTF_PATH /Users/$ENV{USER}/.brew/Cellar/sdl2_ttf/2.0.15)
27+
endif()
1828
endif()
1929

20-
if (NOT SDL2_IMAGE_FOUND)
21-
set(SDL2_IMAGE_PATH /Users/$ENV{USER}/.brew/Cellar/sdl2_image/2.0.5)
22-
endif()
23-
24-
if (NOT SDL2_TTF_FOUND)
25-
set(SDL2_TTF_PATH /Users/$ENV{USER}/.brew/Cellar/sdl2_ttf/2.0.15)
30+
if (NOT APPLE)
31+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
32+
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
33+
find_package(Threads REQUIRED)
34+
if(NOT CMAKE_THREAD_LIBS_INIT)
35+
set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).")
36+
if(SDL2_FIND_REQUIRED)
37+
message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND})
38+
endif()
39+
endif()
2640
endif()
2741

2842
find_package(SDL2 REQUIRED)
2943
find_package(SDL2_image REQUIRED)
3044
find_package(SDL2_ttf REQUIRED)
3145

3246
#add C flags
33-
set(GCC_COMPILE_FLAGS "-Wall -Werror -Wextra -O3")
34-
add_definitions(${GCC_COMPILE_FLAGS})
47+
if (APPLE)
48+
set(GCC_COMPILE_FLAGS "-Wall -Werror -Wextra -O3 -D APPLE___")
49+
add_definitions(${GCC_COMPILE_FLAGS})
50+
endif()
3551

3652
#add custom libs
3753
add_subdirectory(libft)

include/raycast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ int rc_jtoc_win_from_json(t_rc_main *m, t_jnode *n_w);
137137
int rc_jtoc_sdl_log_error(const char *p, const int id);
138138
int rc_jtoc_is_num(enum e_type type);
139139
int rc_jtoc_get_map(t_rc_main *wlf, char *path);
140-
int rc_jtoc_get_textures(t_rc_main *wlf, t_conf_json *conf, t_jnode *node);
140+
int rc_jtoc_get_textures(t_rc_main *m, t_conf_json *conf, t_jnode *node);
141141
int rc_jtoc_get_obj(t_rc_main *m, t_jnode *n, t_conf_json *conf);
142142
int rc_jtoc_get_texture_state(int *state, t_jnode *n, int obj_id);
143143
int rc_jtoc_get_wall_obj(t_object *obj, t_jnode *n, t_conf_json *conf);

json/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"x": 6,
1919
"y": 19
2020
},
21-
"path": "../textures/1375.png"
21+
"path": "./textures/1375.png"
2222
},
2323
{
2424
"type": "single",

sdl2-cmake-modules/FindSDL2.cmake

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,24 +232,27 @@ if(NOT SDL2_BUILDING_LIBRARY)
232232
endif()
233233

234234
# SDL2 may require threads on your system.
235-
# The Apple build may not need an explicit flag because one of the
235+
# The thbuild may not need an explicit flag because one of the
236236
# frameworks may already provide it.
237237
# But for non-OSX systems, I will use the CMake Threads package.
238-
if(NOT APPLE)
239-
find_package(Threads QUIET)
240-
if(NOT CMAKE_THREAD_LIBS_INIT)
241-
set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).")
242-
if(SDL2_FIND_REQUIRED)
243-
message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND})
244-
else()
245-
if(NOT SDL2_FIND_QUIETLY)
246-
message(STATUS ${SDL2_THREADS_NOT_FOUND})
247-
endif()
248-
return()
249-
endif()
250-
unset(SDL2_THREADS_NOT_FOUND)
251-
endif()
252-
endif()
238+
239+
#if(NOT APPLE)
240+
# set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
241+
# set(THREADS_PREFER_PTHREAD_FLAG TRUE)
242+
# find_package(Threads REQUIRED)
243+
# if(NOT CMAKE_THREAD_LIBS_INIT)
244+
# set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).")
245+
# if(SDL2_FIND_REQUIRED)
246+
# message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND})
247+
# else()
248+
# if(NOT SDL2_FIND_QUIETLY)
249+
# message(STATUS ${SDL2_THREADS_NOT_FOUND})
250+
# endif()
251+
# return()
252+
# endif()
253+
# unset(SDL2_THREADS_NOT_FOUND)
254+
# endif()
255+
#endif()
253256

254257
# MinGW needs an additional link flag, -mwindows
255258
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows

src/main.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
# define STB_IMAGE_IMPLEMENTATION
22
#include "raycast.h"
33

4+
#ifdef APPLE___
45
int main(void)
56
{
6-
t_rc_main *m;
7-
SDL_Thread *thread;
7+
t_rc_main *m;
8+
SDL_Thread *thread;
89

9-
m = rc_main_init();
10-
rc_jtoc_main_from_json(m, "./json/config.json");
11-
m->sdl->mutex = SDL_CreateMutex();
12-
thread = SDL_CreateThread(physics, "physics", (void *)m);
13-
SDL_DetachThread(thread);
14-
main_loop(m);
15-
return (0);
16-
}
10+
m = rc_main_init();
11+
rc_jtoc_main_from_json(m, "./json/config.json");
12+
m->sdl->mutex = SDL_CreateMutex();
13+
thread = SDL_CreateThread(physics, "physics", (void *)m);
14+
SDL_DetachThread(thread);
15+
main_loop(m);
16+
return (0);
17+
}
18+
#else
19+
int SDL_main(int argc, char *argv[])
20+
{
21+
t_rc_main *m;
22+
SDL_Thread *thread;
23+
24+
m = rc_main_init();
25+
rc_jtoc_main_from_json(m, "./json/config.json");
26+
m->sdl->mutex = SDL_CreateMutex();
27+
thread = SDL_CreateThread(physics, "physics", (void *)m);
28+
SDL_DetachThread(thread);
29+
main_loop(m);
30+
return (0);
31+
}
32+
#endif

src/main_loop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void draw_texture(t_rc_main *m, t_sdl *sdl)
1313
int **tmp_arr;
1414

1515
y = 0;
16-
tmp_arr = (int **)m->objs[0].data;
16+
tmp_arr = ((t_wall *)m->objs[1].data)->state1->texture_north;
1717
while (y < 64)
1818
{
1919
x = 0;

src/rc_jtoc/rc_jtoc_get_textures.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "raycast.h"
66

7-
static int **texture_load(int y, int x, unsigned char *img_data, t_rc_main *wlf)
7+
static int **texture_load(int y, int x, unsigned char *img_data, t_rc_main *m)
88
{
99
int y_tx;
1010
int x_tx;
@@ -14,17 +14,17 @@ static int **texture_load(int y, int x, unsigned char *img_data, t_rc_main *wlf)
1414

1515
y_d = 0;
1616
y_tx = (y >= 64 ? y - 64 : y);
17-
if (!(arr = (int **)ft_memalloc(sizeof(int *) * wlf->textures.w)))
17+
if (!(arr = (int **)ft_memalloc(sizeof(int *) * m->textures.w)))
1818
exit(39);
1919
while (y_tx <= y)
2020
{
21-
if (!(arr[y_d] = (int *)ft_memalloc(sizeof(int) * wlf->textures.h)))
21+
if (!(arr[y_d] = (int *)ft_memalloc(sizeof(int) * m->textures.h)))
2222
exit(36);
2323
x_d = 0;
2424
x_tx = x - 64;
2525
while (x_tx < x)
2626
{
27-
arr[y_d][x_d] = *((int*)img_data + (x_tx + y_tx * wlf->textures.w));
27+
arr[y_d][x_d] = *((int*)img_data + (x_tx + y_tx * m->textures.w));
2828
x_d++;
2929
x_tx++;
3030
}
@@ -34,25 +34,25 @@ static int **texture_load(int y, int x, unsigned char *img_data, t_rc_main *wlf)
3434
return (arr);
3535
}
3636

37-
static int get_textures_from_texture_pack(t_rc_main *wlf, t_conf_json *conf, char *path)
37+
static int get_textures_from_texture_pack(t_rc_main *m, t_conf_json *conf, char *path)
3838
{
3939
int y;
4040
int x;
41-
unsigned char *img_data;
41+
unsigned char *img_data = 0;
4242
int **arr;
4343
t_list *tmp;
4444

45-
img_data = stbi_load(path, &wlf->textures.w,
46-
&wlf->textures.h, &wlf->textures.bpp, 4);
45+
img_data = stbi_load(path, &m->textures.w,
46+
&m->textures.h, &m->textures.bpp, 4);
4747
y = 0;
48-
while (++y < (wlf->textures.h / 64 + 1))
48+
while (++y < (m->textures.h / 64 + 1))
4949
{
5050
x = 0;
51-
while (++x < (wlf->textures.w / 64) + 1)
51+
while (++x < (m->textures.w / 64) + 1)
5252
{
5353
tmp = ft_lstnew(NULL, 0);
54-
x = (x * 64 == wlf->textures.w * 64 ? 0 : x * 64);
55-
arr = texture_load(y * 64, x, img_data, wlf);
54+
x = (x * 64 == m->textures.w * 64 ? 0 : x * 64);
55+
arr = texture_load(y * 64, x, img_data, m);
5656
tmp->content = (void **)arr;
5757
tmp->content_size = ++(conf->index);
5858
ft_lstadd(&conf->textures, tmp);
@@ -64,7 +64,7 @@ static int get_textures_from_texture_pack(t_rc_main *wlf, t_conf_json *conf, cha
6464
return (FUNCTION_SUCCESS);
6565
}
6666

67-
int rc_jtoc_get_textures(t_rc_main *wlf, t_conf_json *conf, t_jnode *node)
67+
int rc_jtoc_get_textures(t_rc_main *m, t_conf_json *conf, t_jnode *node)
6868
{
6969
t_jnode *tmp;
7070
char *path;
@@ -81,7 +81,7 @@ int rc_jtoc_get_textures(t_rc_main *wlf, t_conf_json *conf, t_jnode *node)
8181
if (!(tmp = jtoc_node_get_by_path(node, "type")) || tmp->type != string)
8282
return (rc_jtoc_sdl_log_error("TEXTURE TYPE ERROR", -1));
8383
if (!(ft_strcmp(jtoc_get_string(tmp), "pack")))
84-
get_textures_from_texture_pack(wlf, conf, path);
84+
get_textures_from_texture_pack(m, conf, path);
8585
else if (!(ft_strcmp(jtoc_get_string(tmp), "single")))
8686
; //TODO
8787
else

src/rc_jtoc/rc_jtoc_get_wall_obj.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ static int fill_cur_wall_texture_state(t_wts *cur_state, t_conf_json *conf, t_jn
5151
tmp_arr = (int **)cur_lst->content;
5252
if (pos == 1)
5353
cur_state->texture_north = tmp_arr;
54-
if (pos == 2)
54+
else if (pos == 2)
5555
cur_state->texture_south = tmp_arr;
56-
if (pos == 3)
56+
else if (pos == 3)
5757
cur_state->texture_west = tmp_arr;
58-
if (pos == 4)
58+
else if (pos == 4)
5959
cur_state->texture_east = tmp_arr;
6060
return (FUNCTION_SUCCESS);
6161
}

0 commit comments

Comments
 (0)