1 #include "stdafx.h"
2 #pragma hdrstop
3
4 #include "BlenderListLoader.h"
5 #include <xr_shaders_xrlc_lib.h>
6 #include <xr_gamemtls_lib.h>
7 #include <algorithm>
8
str_pred(LPCSTR x,LPCSTR y)9 IC bool str_pred(LPCSTR x, LPCSTR y)
10 {
11 return strcmp(x,y)<0;
12 }
13
ClearList(LPSTR_vec & lst)14 void ClearList(LPSTR_vec& lst)
15 {
16 for (LPSTR_vec_it it=lst.begin(); it!=lst.end(); it++)
17 free(*it);
18 }
19
LoadBlenderList(LPSTR_vec & lst)20 int LoadBlenderList(LPSTR_vec& lst)
21 {
22 ClearList(lst);
23
24 // Load blenders
25 string_path shaders;
26 string buff;
27
28 xr_file_system& fs = xr_file_system::instance();
29 fs.update_path(shaders, _game_data_, "shaders.xr");
30 xr_reader* r = fs.r_open(shaders);
31
32 xr_reader* ch = r->open_chunk(3);
33 xr_assert(ch);
34
35 lst.resize(ch->r_u32());
36 for (LPSTR_vec_it it = lst.begin(); it != lst.end(); it++)
37 {
38 ch->r_sz(buff);
39 *it = xr_strdup(buff.c_str());
40 }
41 r->close_chunk(ch);
42 fs.r_close(r);
43
44 std::sort(lst.begin(), lst.end(), str_pred);
45
46 return lst.size();
47 }
48
LoadShaderLCList(LPSTR_vec & lst)49 int LoadShaderLCList(LPSTR_vec& lst)
50 {
51 ClearList(lst);
52
53 xr_shaders_xrlc_lib LIB;
54
55 LIB.load(_game_data_, "shaders_xrlc.xr");
56
57 lst.resize(LIB.shaders().size());
58 LPSTR_vec_it s_it = lst.begin();
59 for (xr_shader_xrlc_vec_cit l_it = LIB.shaders().begin(); l_it != LIB.shaders().end(); l_it++, s_it++)
60 {
61 *s_it = xr_strdup((*l_it)->name.c_str());
62 }
63
64 std::sort(lst.begin(), lst.end(), str_pred);
65
66 return lst.size();
67 }
68
LoadGameMtlList(LPSTR_vec & lst)69 int LoadGameMtlList(LPSTR_vec& lst)
70 {
71 ClearList(lst);
72
73 xr_gamemtls_lib LIB;
74
75 LIB.load(_game_data_, "shaders_xrlc.xr");
76
77 lst.resize(LIB.materials().size());
78 LPSTR_vec_it s_it = lst.begin();
79 for (xr_gamemtl_vec_cit l_it = LIB.materials().begin(); l_it != LIB.materials().end(); l_it++, s_it++)
80 {
81 *s_it = xr_strdup((*l_it)->name.c_str());
82 }
83
84 std::sort(lst.begin(), lst.end(), str_pred);
85
86 return lst.size();
87 }
88