fixed absolute paths
This commit is contained in:
parent
31cac13971
commit
5185581f35
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
Modules/*
|
||||
test/CMakeFiles/*
|
||||
test/res.cpp
|
||||
cmake_install.cmake
|
||||
Makefile
|
||||
CMakeCache.txt
|
||||
|
@ -16,7 +16,7 @@ add_executable(SparrowResource ${CMAKE_TEMPLATE_PATH}/resource/main.cpp)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DST_FILE}
|
||||
COMMAND SparrowResource
|
||||
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DST_FILE} ${RES_SRC_FILE}
|
||||
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DST_FILE} ${PROJECT_SOURCE_DIR} ${RES_SRC_FILE}
|
||||
DEPENDS ${RES_SRC_FILE}
|
||||
COMMENT "Generating resource file"
|
||||
)
|
||||
|
@ -1,10 +0,0 @@
|
||||
project(SparrowResource)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(CMAKE_TEMPLATE_PATH "..")
|
||||
|
||||
# choose source file
|
||||
set(EXEC_SRC_LIST main.cpp)
|
||||
|
||||
include(${CMAKE_TEMPLATE_PATH}/template.cmake)
|
||||
|
@ -6,16 +6,11 @@ using namespace std;
|
||||
|
||||
#define NB_VAL_PER_LINE 256
|
||||
|
||||
|
||||
#define FILE_BEGIN "#include <string>\n\
|
||||
#include <unordered_map>\n\
|
||||
\n\
|
||||
namespace Resource {\n\
|
||||
typedef std::unordered_map<std::string, const char*> ResourceMap;\n"
|
||||
|
||||
|
||||
#define FILE_MID ""
|
||||
|
||||
|
||||
#define FILE_END "\n\
|
||||
}\n\
|
||||
@ -42,7 +37,7 @@ bool addFile(const string &inFile, FILE *out)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
while(nbRead == NB_VAL_PER_LINE);
|
||||
fprintf(out, "};\n");
|
||||
fprintf(out, ", 0x00}; // additionnal byte used to null-terminate ascii data\n");
|
||||
++n;
|
||||
fclose(in);
|
||||
return true;
|
||||
@ -50,9 +45,13 @@ bool addFile(const string &inFile, FILE *out)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(argc < 3)
|
||||
if(argc < 4)
|
||||
{
|
||||
printf("usage : %s RESOURCE_PACK_NAME [LIST_OF_FILES_TO_BAKE]\n", argv[0]);
|
||||
printf("usage : %s RESOURCE_PACK_FILE_TO_CREATE RESOURCE_PACK_ROOT [LIST_OF_FILES_TO_BAKE]\n\n", argv[0]);
|
||||
printf("RESOURCE_PACK_FILE_TO_CREATE is the c++ source file that will be created,\n");
|
||||
printf("the resource pack will be named from the file name\n");
|
||||
printf("example, if the filename provided is : /directory/sources/myResourcePack.cpp , the resource pack will be named myResourcePack\n\n");
|
||||
printf("RESOURCE_PACK_ROOT is the root directory or the resources, they will be accessible from their relative path to this directory\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -72,19 +71,28 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
fprintf(out, FILE_BEGIN);
|
||||
for(int i=2; i<argc; ++i)
|
||||
vector<int> offsets;
|
||||
for(int i=3; i<argc; ++i)
|
||||
{
|
||||
int offset = 0;
|
||||
while(argv[2][offset] == argv[i][offset])
|
||||
++offset;
|
||||
if(argv[i][offset] == '/')
|
||||
++offset;
|
||||
if(!addFile(argv[i], out))
|
||||
{
|
||||
fclose(out);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
printf("successfully added \"%s\" to \"%s\".\n", argv[i], packName.c_str());
|
||||
{
|
||||
printf("successfully added \"%s\" as \"%s\" to resource pack \"%s\".\n", argv[i], argv[i]+offset, packName.c_str());
|
||||
offsets.push_back(offset);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\nvoid getResourcePack_%s(ResourceMap &resourceFilesData)\n{\n", packName.c_str());
|
||||
for(int i=0; i<n; ++i)
|
||||
fprintf(out, "\tresourceFilesData[\"%s\"] = data%d;\n", argv[2+i], i);
|
||||
fprintf(out, "\tresourceFilesData[\"%s\"] = data%d;\n", argv[3+i]+offsets[i], i);
|
||||
fprintf(out, FILE_END);
|
||||
fclose(out);
|
||||
printf("successfully created resource file \"%s\".\n", outFilename.c_str());
|
||||
|
@ -6,11 +6,9 @@ set(CMAKE_TEMPLATE_PATH "..")
|
||||
#SET(RESOURCE_DIRS /shaders)
|
||||
|
||||
#SET(RES_SRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/plop.txt ${CMAKE_CURRENT_SOURCE_DIR}/plop2.txt)
|
||||
FILE(GLOB RES_SRC_FILE plop.txt plop2.txt)
|
||||
FILE(GLOB RES_SRC_FILE hello.txt test.txt)
|
||||
SET(RESOURCE_DST_FILE res.cpp)
|
||||
|
||||
MESSAGE(${RES_SRC_FILE})
|
||||
|
||||
# choose source file
|
||||
set(EXEC_SRC_LIST test.cpp ${RESOURCE_DST_FILE})
|
||||
|
||||
|
@ -7,12 +7,10 @@ RESOURCE_PACK(res)
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Resource test" << endl;
|
||||
Resource::ResourceMap resMap;
|
||||
Resource::getResourcePack_res(resMap);
|
||||
const char *str = resMap["/data/Qt_workspace/cmaketemplate/test/plop.txt"];
|
||||
if(str != NULL)
|
||||
cout << str << endl;
|
||||
else
|
||||
cout << "nope" << endl;
|
||||
Resource::getResourcePack_res(resMap);
|
||||
|
||||
cout << "resources available : " << endl << endl;
|
||||
for(auto it : resMap)
|
||||
cout << it.first << " -> " << it.second << endl;
|
||||
}
|
||||
|
BIN
test/test.exe
BIN
test/test.exe
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user