mirror of https://github.com/sm64pc/sm64pc.git
[WIP] Added rule to make addons folder and removed hardcoded addons
This commit is contained in:
parent
1aff0121d5
commit
1224f89d3a
8
Makefile
8
Makefile
|
@ -669,6 +669,9 @@ ifeq ($(TARGET_SWITCH),1)
|
|||
all: $(EXE).nro
|
||||
endif
|
||||
|
||||
ADDONS := addons
|
||||
ADDONS_PATH := $(BUILD_DIR)/$(ADDONS)/
|
||||
|
||||
BASEPACK_PATH := $(BUILD_DIR)/$(BASEDIR)/
|
||||
BASEPACK_LST := $(BUILD_DIR)/basepack.lst
|
||||
|
||||
|
@ -720,7 +723,7 @@ $(BUILD_DIR)/src/game/crash_screen.o: $(CRASH_TEXTURE_C_FILES)
|
|||
$(BUILD_DIR)/lib/rsp.o: $(BUILD_DIR)/rsp/rspboot.bin $(BUILD_DIR)/rsp/fast3d.bin $(BUILD_DIR)/rsp/audio.bin
|
||||
|
||||
RSP_DIRS := $(BUILD_DIR)/rsp
|
||||
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION) $(RSP_DIRS)
|
||||
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION) $(RSP_DIRS) $(ADDONS_PATH)
|
||||
|
||||
# Make sure build directory exists before compiling anything
|
||||
DUMMY != mkdir -p $(ALL_DIRS)
|
||||
|
@ -842,6 +845,9 @@ ifeq ($(TARGET_SWITCH), 1)
|
|||
|
||||
endif
|
||||
|
||||
testclean:
|
||||
@rm -rf $(BUILD_DIR)/$(SRC_DIRS)
|
||||
|
||||
.PHONY: all clean distclean default diff libultra res
|
||||
.PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
|
||||
.DELETE_ON_ERROR:
|
||||
|
|
|
@ -23,6 +23,8 @@ map<string, TextureData*> textureMap;
|
|||
|
||||
map<string, TextureFileEntry*> baseGameTextures;
|
||||
|
||||
map<string, TextureFileEntry*> textureCache;
|
||||
|
||||
extern "C" {
|
||||
#include "moon/libs/lua/lualib.h"
|
||||
#include "moon/libs/lua/lauxlib.h"
|
||||
|
@ -30,8 +32,6 @@ extern "C" {
|
|||
#include "text/libs/io_utils.h"
|
||||
}
|
||||
|
||||
void Moon_LoadAddonTextures(BitModule* module);
|
||||
|
||||
void Moon_LoadDefaultAddon(){
|
||||
BitModule* bit = new BitModule();
|
||||
bit->name = "Moon64";
|
||||
|
@ -41,7 +41,6 @@ void Moon_LoadDefaultAddon(){
|
|||
bit->readOnly = true;
|
||||
bit->textures = baseGameTextures;
|
||||
addons.push_back(bit);
|
||||
Moon_LoadAddonTextures(bit);
|
||||
}
|
||||
|
||||
void Moon_LoadAddon(string path){
|
||||
|
@ -98,9 +97,6 @@ void Moon_LoadAddon(string path){
|
|||
}
|
||||
}
|
||||
|
||||
if(!bit->textures.empty())
|
||||
Moon_LoadAddonTextures(bit);
|
||||
|
||||
addons.push_back(bit);
|
||||
}
|
||||
} else {
|
||||
|
@ -109,6 +105,37 @@ void Moon_LoadAddon(string path){
|
|||
}
|
||||
}
|
||||
|
||||
void Moon_BakeTextureCache(){
|
||||
textureMap.clear();
|
||||
|
||||
for(auto &addon : addons){
|
||||
// BitModule *addon = addons[order[i]];
|
||||
|
||||
for (map<string, TextureFileEntry*>::iterator entry = addon->textures.begin(); entry != addon->textures.end(); ++entry) {
|
||||
map<string, TextureFileEntry*>::iterator texIt = textureCache.find(entry->first);
|
||||
if(texIt != textureCache.end()) textureCache.erase(texIt);
|
||||
|
||||
TextureFileEntry* texEntry = entry->second;
|
||||
if(texEntry->data != nullptr)
|
||||
textureCache.insert(pair<string, TextureFileEntry*>(entry->first, texEntry));
|
||||
}
|
||||
}
|
||||
|
||||
//for(auto &addon: addons){
|
||||
//}
|
||||
}
|
||||
|
||||
void Moon_UploadCacheToGPU(){
|
||||
for (map<string, TextureFileEntry*>::iterator entry = textureCache.begin(); entry != textureCache.end(); ++entry) {
|
||||
TextureFileEntry* texEntry = entry->second;
|
||||
if(texEntry->data != nullptr) {
|
||||
overload_memory_texture(texEntry->data, texEntry->size, entry->first.c_str());
|
||||
// free(entry->second);
|
||||
}
|
||||
}
|
||||
textureCache.clear();
|
||||
}
|
||||
|
||||
void Moon_ScanAddonsDirectory( char *exePath, char *gamedir ){
|
||||
string l_path(exePath);
|
||||
|
||||
|
@ -131,27 +158,6 @@ void Moon_ScanAddonsDirectory( char *exePath, char *gamedir ){
|
|||
}
|
||||
}
|
||||
|
||||
void Moon_LoadAddonTextures(BitModule* module){
|
||||
if(module->textures.empty()) return;
|
||||
cout << "Loading from " << module->name << " " << to_string(module->textures.size()) << " textures " << endl;
|
||||
|
||||
for (map<string, TextureFileEntry*>::iterator entry = module->textures.begin(); entry != module->textures.end(); ++entry) {
|
||||
|
||||
map<string, TextureData*>::iterator texIt;
|
||||
texIt = textureMap.find(entry->first);
|
||||
|
||||
if(texIt != textureMap.end()){
|
||||
// cout << "Reloading: " << entry->first << endl;
|
||||
textureMap.erase(texIt);
|
||||
}
|
||||
|
||||
TextureFileEntry* texEntry = entry->second;
|
||||
if(texEntry->data != nullptr) {
|
||||
overload_memory_texture(texEntry->data, texEntry->size, entry->first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Moon_SaveTexture(TextureData* data, string tex){
|
||||
textureMap.insert(pair<string, TextureData*>(tex, data));
|
||||
}
|
||||
|
@ -197,13 +203,14 @@ void Moon_TextFlyLoad(int id){
|
|||
|
||||
void Moon_PreInitModEngine(){
|
||||
Moon_LoadDefaultAddon();
|
||||
Moon_LoadAddon("/home/alex/Downloads/packs/converted/mc.bit");
|
||||
Moon_LoadAddon("/home/alex/Downloads/packs/converted/owo.bit");
|
||||
Moon_LoadAddon("/home/alex/Downloads/packs/converted/r96-hd.bit");
|
||||
Moon_LoadAddon("/home/alex/Downloads/packs/converted/beta-hud.bit");
|
||||
Moon_LoadAddon("/home/alex/Downloads/packs/converted/moon64-demo.bit");
|
||||
}
|
||||
|
||||
void Moon_InitModEngine(){
|
||||
void Moon_TestRebuildOrder(vector<int> order){
|
||||
|
||||
}
|
||||
|
||||
void Moon_InitModEngine( char *exePath, char *gamedir ){
|
||||
Moon_ScanAddonsDirectory(exePath, gamedir);
|
||||
Moon_BakeTextureCache();
|
||||
Moon_UploadCacheToGPU();
|
||||
}
|
|
@ -13,9 +13,13 @@ extern std::vector<BitModule*> addons;
|
|||
void Moon_SaveTexture(TextureData* data, std::string tex);
|
||||
TextureData* Moon_GetTexture(std::string texture);
|
||||
void Moon_PreInitModEngine();
|
||||
void Moon_InitModEngine();
|
||||
void Moon_InitModEngine( char *exePath, char *gamedir );
|
||||
|
||||
void Moon_LoadBaseTexture(char* data, long size, std::string texture);
|
||||
|
||||
|
||||
// TESTS
|
||||
void Moon_TextFlyLoad(int id);
|
||||
void Moon_TestRebuildOrder(std::vector<int> order);
|
||||
|
||||
#endif
|
|
@ -82,8 +82,8 @@ void moon_mod_engine_preinit(){
|
|||
Moon_PreInitModEngine();
|
||||
}
|
||||
|
||||
void moon_mod_engine_init(){
|
||||
Moon_InitModEngine();
|
||||
void moon_mod_engine_init(char *executable, char *gamedir){
|
||||
Moon_InitModEngine(executable, gamedir);
|
||||
}
|
||||
|
||||
void moon_engine_save_texture(struct TextureData* data, char* tex){
|
||||
|
|
|
@ -20,7 +20,7 @@ void moon_modules_update();
|
|||
void moon_update_window(void* window);
|
||||
|
||||
void moon_mod_engine_preinit();
|
||||
void moon_mod_engine_init();
|
||||
void moon_mod_engine_init(char *executable, char *gamedir);
|
||||
|
||||
void moon_engine_save_texture(struct TextureData* data, char* tex);
|
||||
struct TextureData* moon_engine_get_texture(char* tex);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "moon/texts/moon-loader.h"
|
||||
#include "moon/ui/widgets/mw-value.h"
|
||||
#include "moon/mod-engine/engine.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -11,22 +12,31 @@ extern "C" {
|
|||
#include "pc/configfile.h"
|
||||
}
|
||||
|
||||
std::vector<int> order = {
|
||||
0, 2, 1
|
||||
};
|
||||
|
||||
MWValue *tmpButton;
|
||||
|
||||
MTexturesCategory::MTexturesCategory() : MoonCategory("TEXT_OPT_AUDIO"){
|
||||
int idx = 0;
|
||||
// for(auto &addon : addons){
|
||||
// this->catOptions.push_back(new MWValue(22, 57 + (17 * idx), addon->name, {.bvar = &addon->enabled}, false));
|
||||
// idx++;
|
||||
// }
|
||||
this->catOptions.push_back(new MWValue(22, 57, "Load main pack", {.btn = [](){
|
||||
Moon_TextFlyLoad(0);
|
||||
}}, false));
|
||||
this->catOptions.push_back(new MWValue(22, 57 + (17 * 1), "Load minecraft pack", {.btn = [](){
|
||||
Moon_TextFlyLoad(1);
|
||||
}}, false));
|
||||
this->catOptions.push_back(new MWValue(22, 57 + (17 * 2), "Load owo pack", {.btn = [](){
|
||||
Moon_TextFlyLoad(2);
|
||||
}}, false));
|
||||
this->catOptions.push_back(new MWValue(22, 57 + (17 * 3), "Load Render96 pack", {.btn = [](){
|
||||
Moon_TextFlyLoad(2);
|
||||
this->catOptions.push_back(tmpButton = new MWValue(22, 57, "Randomize packs", {.btn = [](){
|
||||
tmpButton->title = "Randomize on progress";
|
||||
std::random_shuffle ( order.begin(), order.end() );
|
||||
Moon_TestRebuildOrder(order);
|
||||
tmpButton->title = "Randomize packs";
|
||||
}}, false));
|
||||
// this->catOptions.push_back(new MWValue(22, 57 + (17 * 1), "Load minecraft pack", {.btn = [](){
|
||||
// Moon_TextFlyLoad(1);
|
||||
// }}, false));
|
||||
// this->catOptions.push_back(new MWValue(22, 57 + (17 * 2), "Load owo pack", {.btn = [](){
|
||||
// Moon_TextFlyLoad(2);
|
||||
// }}, false));
|
||||
// this->catOptions.push_back(new MWValue(22, 57 + (17 * 3), "Load Render96 pack", {.btn = [](){
|
||||
// Moon_TextFlyLoad(2);
|
||||
// }}, false));
|
||||
}
|
|
@ -329,18 +329,14 @@ static inline void load_memory_texture(void *imgdata, long size) {
|
|||
int w, h;
|
||||
|
||||
if (imgdata) {
|
||||
// TODO: implement stbi_callbacks or some shit instead of loading the whole texture
|
||||
u8 *data = stbi_load_from_memory(imgdata, size, &w, &h, NULL, 4);
|
||||
// free(imgdata);
|
||||
if (data) {
|
||||
gfx_rapi->upload_texture(data, w, h);
|
||||
stbi_image_free(data); // don't need this anymore
|
||||
// stbi_image_free(data); // don't need this anymore
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// fprintf(stderr, "could not load memory texture\n");
|
||||
// replace with missing texture
|
||||
gfx_rapi->upload_texture(missing_texture, MISSING_W, MISSING_H);
|
||||
}
|
||||
|
||||
|
@ -417,7 +413,7 @@ static void import_texture(int tile) {
|
|||
return;
|
||||
}
|
||||
|
||||
// the "texture data" is actually a C string with the path to our texture in it
|
||||
// the "texture data" is actually a C string with the path to our texture in it
|
||||
// load it from an external image in our data path
|
||||
char texname[SYS_MAX_PATH];
|
||||
snprintf(texname, sizeof(texname), FS_TEXTUREDIR "/%s.png", (const char*)rdp.loaded_texture[tile].addr);
|
||||
|
|
|
@ -254,7 +254,7 @@ void main_func(char *argv[]) {
|
|||
fflush(stdout);
|
||||
gfx_precache_textures();
|
||||
moon_mod_engine_preinit();
|
||||
moon_mod_engine_init();
|
||||
moon_mod_engine_init(argv[0], gamedir);
|
||||
|
||||
#ifdef DISCORDRPC
|
||||
discord_init();
|
||||
|
|
Loading…
Reference in New Issue