Unverified Commit 3219f6bb authored by Gauvain "GovanifY" Roussel-Tarbouriech's avatar Gauvain "GovanifY" Roussel-Tarbouriech
Browse files

beginning map support: missing type 0 header line 3 and related regions

parent d0573915
......@@ -4,7 +4,9 @@
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <vector>
int max(int x, int y, int z) {
......@@ -18,6 +20,7 @@ int max(int x, int y, int z) {
return flagx;
}
void help() { printf("Usage: kh2vif model.obj\n"); }
int main(int argc, char *argv[]) {
// max uv buffer, should be enough for an entire set of obj vertices
int uvs[8192];
......@@ -28,19 +31,30 @@ int main(int argc, char *argv[]) {
int vertices_arg = 0;
int vertex_affiliation = 0;
int junk = 0;
int junk = 1;
int map = 0;
char *objname = argv[1];
printf("kh2vif\n-- If you don't know what a VIF packet be prepared to be "
"driven to insanity\n\n");
if (argc < 2) {
printf("Usage: kh2vif model.obj");
help();
return -1;
}
std::ifstream input(argv[1], std::ios::in);
if ((strcmp(objname, "-m") == 0) || (strcmp(objname, "--map") == 0)) {
printf("\nSwitching to map mode\n");
map = 1;
objname = argv[2];
}
if (access(objname, F_OK) == -1) {
help();
return -1;
}
std::ifstream input(objname, std::ios::in);
std::string dsmname =
std::string(argv[1]).substr(0, std::string(argv[1]).find_last_of('.')) +
std::string(objname).substr(0, std::string(objname).find_last_of('.')) +
".dsm";
std::string kh2vname =
std::string(argv[1]).substr(0, std::string(argv[1]).find_last_of('.')) +
std::string(objname).substr(0, std::string(objname).find_last_of('.')) +
".kh2v";
std::ofstream dsm(dsmname);
std::string line;
......@@ -49,7 +63,7 @@ int main(int argc, char *argv[]) {
std::vector<int> bones;
dsm_mem.push_back(".align 0");
line = ";";
line += argv[1];
line += objname;
dsm_mem.push_back(line);
dsm_mem.push_back(";Automatically generated by kh2vif");
dsm_mem.push_back(";DO NOT EDIT IF YOU DON'T KNOW WHAT YOU ARE DOING");
......@@ -58,7 +72,11 @@ int main(int argc, char *argv[]) {
"stcycl 01, 01; We write code to memory without skips/overwrite");
dsm_mem.push_back("");
dsm_mem.push_back("unpack[r] V4_32, 0, * ;Model Part Header");
dsm_mem.push_back(".int 1, 0, 0, 0 ;type 1 Model");
if (map) {
dsm_mem.push_back(".int 0, 0, 0, 0 ;type 0 Model");
} else {
dsm_mem.push_back(".int 1, 0, 0, 0 ;type 1 Model");
}
// 3 MPHeader lines we will fix at the end, Vector is 11 here
int tmpheader = dsm_mem.size();
dsm_mem.push_back("");
......@@ -218,25 +236,27 @@ int main(int argc, char *argv[]) {
dsm_mem.push_back(".EndUnpack");
dsm_mem.push_back("");
dsm_mem.push_back(
"stcycl 01, 01; We write code to memory without skips/overwrite");
dsm_mem.push_back("");
dsm_mem.push_back("unpack[r] V4_32, ,*; Vertex affiliation header");
// printf("%lu", bones.size());
vertex_affiliation = dsm_mem.size() - 1;
for (unsigned int i = 0; i < ceil(float(bones.size()) / 4); i++) {
line = ".int " + std::to_string(bones[(i * 4)]);
unsigned int z = 1;
while ((i * 4) + z < bones.size() && z < 4) {
line += ", " + std::to_string(bones[(i * 4) + z]);
z++;
}
for (; z < 4; z++) {
line += ", 0";
if (!map) {
dsm_mem.push_back("stcycl 01, 01; We write code to memory without "
"skips/overwrite");
dsm_mem.push_back("");
dsm_mem.push_back("unpack[r] V4_32, ,*; Vertex affiliation header");
// printf("%lu", bones.size());
vertex_affiliation = dsm_mem.size() - 1;
for (unsigned int i = 0; i < ceil(float(bones.size()) / 4); i++) {
line = ".int " + std::to_string(bones[(i * 4)]);
unsigned int z = 1;
while ((i * 4) + z < bones.size() && z < 4) {
line += ", " + std::to_string(bones[(i * 4) + z]);
z++;
}
for (; z < 4; z++) {
line += ", 0";
}
dsm_mem.push_back(line);
}
dsm_mem.push_back(line);
dsm_mem.push_back(".EndUnpack");
}
dsm_mem.push_back(".EndUnpack");
dsm_mem.push_back("vifnop");
dsm_mem.push_back("vifnop; We wait for data to be kicked in");
}
......@@ -267,10 +287,12 @@ int main(int argc, char *argv[]) {
line = "unpack[mr] V3_32, " + std::to_string(4 + (face_count * 3)) +
", *; Vertex definition";
dsm_mem[vertices_arg] = line;
line = "unpack[r] V4_32, " +
std::to_string(4 + (face_count * 3) + vertex_count) +
" ,*; Vertex affiliation header";
dsm_mem[vertex_affiliation] = line;
if (!map) {
line = "unpack[r] V4_32, " +
std::to_string(4 + (face_count * 3) + vertex_count) +
" ,*; Vertex affiliation header";
dsm_mem[vertex_affiliation] = line;
}
for (unsigned int i = 0; i < dsm_mem.size(); i++) {
dsm << dsm_mem[i] << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment