Welcome to mirror list, hosted at ThFree Co, Russian Federation.

altmain.cpp « Main « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1fe0a547ef67944a944552090f5cb9e8f88128a7 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//-----------------------------------------------------------------------------
//           Name: altmain.cpp
//      Developer: Wolfire Games LLC
//    Description: 
//        License: Read below
//-----------------------------------------------------------------------------
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#include "altmain.h"

#include <Internal/levelxml.h>
#include <Internal/zip_util.h>
#include <Internal/casecorrectpath.h>
#include <Internal/textfile.h>
#include <Internal/snprintf.h>

#include <Compat/processpool.h>
#include <Compat/fileio.h>
#include <Compat/filepath.h>
#include <Compat/platformsetup.h>

#include <Graphics/shaders.h>
#include <Graphics/textures.h>
#include <Graphics/graphics.h>
#include <Graphics/text.h>
#include <Graphics/font_renderer.h>

#include <Asset/Asset/soundgroup.h>
#include <Asset/Asset/fzx_file.h>
#include <Asset/Asset/animation.h>

#include <Sound/sound.h>
#include <Editors/actors_editor.h>
#include <UserInput/mouse.h>
#include <Images/texture_data.h>
#include <Logging/logdata.h>
#include <Main/engine.h>
#include <Game/EntityDescription.h>

#include <SDL.h>
#include <utf8/utf8.h>
#include <tinyxml.h>

void CompressPathSet(PathSet path_set, const std::string &base_folder, const std::string &dst){
    bool first_path = true;
    for(PathSet::iterator iter = path_set.begin(); iter != path_set.end(); ++iter){
        const std::string &full_path = (*iter);
        const char* truncated_path = &full_path[base_folder.length()];
        Zip(full_path, dst, truncated_path, first_path?_YES_OVERWRITE:_APPEND_OVERWRITE);
        first_path = false;
    }
}

const char* GetSuffix(const char* path){
    const char* current = &path[0];
    while(*current != '\0'){
        if(*current == '.'){ 
            return current+1;
        }
        ++current;
    }
    FatalError("Error", "Path has no suffix!");
    return current;
}

void LoadSoundGroup(const char* path, const char* data) {
    //Disabled function as there is currently no support for loading data from within zip files, if the feature 
    //should exists in the future, it should be part of the asset manager. /Max Danielsson 2016 September 15
    assert(false); 
    /*
    LOGI << "Loading SoundGroupInfo \"" <<  path << "\"" << std::endl;
    SoundGroupInfo sgi;
    sgi.ParseXML(data); 
    */
}

void LoadSound(const char* path, const char* data){
    LOGI << "Loading Sound file \"" << path << "\"" << std::endl;
    SoundPlayInfo spi;
    spi.path = std::string("Data/Sounds/weapon_foley/cut/")+path;
    Sound sound("");
    unsigned long handle = sound.CreateHandle();
    sound.Play(handle,spi);
    SDL_Delay(1000);
}

void LoadSoundGroupZipFile(const std::string& path){
    ExpandedZipFile ezf;
    UnZip(path, ezf);
    
    unsigned num_entries = ezf.GetNumEntries();
    for(unsigned i=0; i<num_entries; ++i){
        const char* filename;
        const char* data; 
        unsigned size;
        ezf.GetEntry(i, filename, data, size);

        const char* suffix = GetSuffix(filename);
        switch(suffix[0]){
            case 'x': //xml
                LoadSoundGroup(filename, data);
                break;
            case 'w': //wav
                LoadSound(filename, data);
                break;
        }
    } 
}

void CheckCase(const char* path){
    std::string corrected;
    if(IsPathCaseCorrect(path, &corrected)){
        LOGI << "Case is correct: " << corrected << std::endl;
    } else {
        LOGI << "Case is not correct: " <<  path << std::endl;
        LOGI << "The correct case is: " << corrected << std::endl;
    }
}

static const int FZX_VERSION_ = 1;

int TestMain( int argc, char* argv[], const char* overloaded_write_dir, const char* overloaded_working_dir) {
    SetUpEnvironment(argv[0],overloaded_write_dir, overloaded_working_dir);

    //FZXAssetRef ref = FZXAssets::Instance()->ReturnRef("Data/Models/Characters/IGF_Guard/guard_physics.fzx");
    FZXAssetRef ref = Engine::Instance()->GetAssetManager()->LoadSync<FZXAsset>("Data/Models/Characters/IGF_Guard/guard_physics.fzx");
    LOGI << "Objects: " << ref->objects.size() << std::endl;
	const char* key_words[] = {"left", "capsule", "box", "sphere"};
	const int num_key_words = sizeof(key_words)/sizeof(key_words[0]);
	for(size_t i=0, len=ref->objects.size(); i<len; ++i){
        const FZXObject &object = ref->objects[i];
        // Parse label string
        const std::string &label = object.label;      
        size_t last_space_index = 0;
        for(size_t j=0, len=label.size()+1; j<len; ++j){      
			if(label[j] == ' ' || label[j] == '\0'){
                std::string sub_str_buf;
                sub_str_buf.resize(j-last_space_index);
                int count = 0;
				for(size_t k=last_space_index; k<j; ++k){
					char c = label[k];
					if(c >= 'A' && c <= 'Z'){
						c -= ('A' - 'a');
					}
                    sub_str_buf[count] = c;
                    ++count;
				}
                bool match = false;
                for(int k=0; k<num_key_words; ++k){
                    bool word_match = (strcmp(key_words[k], sub_str_buf.c_str())==0);
                    if(word_match){
                        LOGI << "Token found: " << key_words[k] << std::endl;
                        match = true;
                    }
                }
                if(!match){
                    LOGE << "Unrecognized token: " << sub_str_buf << std::endl;
                }
                last_space_index = j+1;
			}
        }
        LOGI << "Object name: " << label << std::endl;
        const quaternion &quat = object.rotation;
        LOGI << "Quaternion: " << quat << std::endl;
        const vec3 &location = object.location;
        LOGI << "Location: " << location << std::endl;
        const vec3 &scale = object.scale;
        LOGI << "Scale: " << scale << std::endl;
	}
	
    printf("Press enter to exit\n");
    getchar();

    DisposeEnvironment();

    return 0;
}


#include "Graphics/converttexture.h"

int DDSConvertMain( int argc, char* argv[], const char* overloaded_write_dir, const char* overloaded_working_dir ) {
    SetUpEnvironment(argv[0],overloaded_write_dir,overloaded_working_dir);

    printf("Running DDS converter...\n");

    for(int i=2; i<argc; ++i){
        printf("Loading path: %s\n", argv[i]);
        std::string src = argv[i];
        std::string dst = src + "_converted.dds";
        std::string temp = GetTempDDSPath(dst, true, 0);
        ConvertImage(src, dst, temp, TextureData::Nice);
        printf("Converted.\n");
    } 
    if(argc <= 2) {
        printf("No path found.\n");
    }
    printf("Press any key to exit...\n");
    getchar();

    DisposeEnvironment();

    return 0;
}