2006-12-10

This commit is contained in:
Anonymous Maarten committed 2015-12-03 01:37:02 +01:00
commit 78c27f03c8
153 files changed
+24678

No files matched your search

+104
View File
@@ -0,0 +1,104 @@
#include <stdio.h>
float slope_raw_data[45][5][4][3] = {
#include "slope1_data.h"
};
int main(int argc, char* argv[]) {
int slope_type, vertex;
int equal_y1, equal_y2, other_y;
int marked_axis;
#define STORE(a, b, c) { equal_y1 = a; equal_y2 = b; other_y = c;}
printf("#include <cassert>\n");
printf("float slope_height_offset(unsigned char slope_type, float dx, float dz) {\n");
printf(" assert((dx >= 0.0f) && (dx <= 1.0f));\n");
printf(" assert((dz >= 0.0f) && (dz <= 1.0f));\n");
printf(" switch(slope_type) {\n");
for (slope_type = 0 ; slope_type < 45; slope_type++) {
//printf("# slope %i\n", slope_type);
printf(" case %i:\n", slope_type);
if (slope_raw_data[slope_type][0][0][1] == slope_raw_data[slope_type][0][1][1]) {
//printf("0, 1\n");
STORE(0, 1, 2);
}
else if (slope_raw_data[slope_type][0][1][1] == slope_raw_data[slope_type][0][2][1]) {
//printf("1, 2\n");
STORE(1, 2, 0);
}
else if (slope_raw_data[slope_type][0][2][1] == slope_raw_data[slope_type][0][3][1]) {
//printf("2, 3\n");
STORE(2, 3, 0);
}
else if (slope_raw_data[slope_type][0][0][1] == slope_raw_data[slope_type][0][2][1]) {
//printf("0, 2\n");
STORE(0, 2, 1);
}
else if (slope_raw_data[slope_type][0][1][1] == slope_raw_data[slope_type][0][3][1]) {
//printf("1, 3\n");
STORE(1, 3, 0);
}
else {
printf("argh?\n");
return(1);
}
if (slope_raw_data[slope_type][0][equal_y1][0] == slope_raw_data[slope_type][0][equal_y2][0]) {
//printf("# x-axis\n");
marked_axis = 0;
}
else if (slope_raw_data[slope_type][0][equal_y1][2] == slope_raw_data[slope_type][0][equal_y2][2]) {
//printf("# z-axis\n");
marked_axis = 2;
}
else {
printf("not good\n");
return(1);
}
float low = 1.0f;
float high = 0.0f;
int low_idx = -1;
int high_idx = -1;
for (vertex = 0; vertex < 4; vertex++) {
if (slope_raw_data[slope_type][0][vertex][1] < low) {
low = slope_raw_data[slope_type][0][vertex][1];
low_idx = vertex;
}
if (slope_raw_data[slope_type][0][vertex][1] > high) {
high = slope_raw_data[slope_type][0][vertex][1];
high_idx = vertex;
}
}
//printf("# low: %f high: %f\n", low, high);
int increasing;
if (slope_raw_data[slope_type][0][low_idx][marked_axis] <
slope_raw_data[slope_type][0][high_idx][marked_axis])
increasing = 1;
else
increasing = 0;
if (high - low == 0.0f)
printf(" return 0.0f;\n");
else
printf(" return %ff %c d%c * %ff;\n", (increasing ? low : high),
(increasing ? '+' : '-'),
((marked_axis == 0) ? 'x' : 'z'), (high - low));
/*
for (vertex = 0; vertex < 4; vertex++) {
printf("%f %f %f\n",
slope_raw_data[slope_type][0][vertex][0],
slope_raw_data[slope_type][0][vertex][1],
slope_raw_data[slope_type][0][vertex][2]);
}
*/
}
printf(" default:\n");
printf(" break;\n");
printf(" }\n");
printf(" assert(0);\n");
printf(" return 0.0f; // should never be reached\n");
printf("}\n");
}
+98
View File
@@ -0,0 +1,98 @@
#include <stdio.h>
#include <math.h>
float slope_raw_data[45][5][4][3] = {
#include "slope1_data.h"
};
int main(int argc, char* argv[]) {
int slope_type, vertex;
int equal_y1, equal_y2, other_y;
int marked_axis;
#define STORE(a, b, c) { equal_y1 = a; equal_y2 = b; other_y = c;}
printf("#include <cassert>\n");
printf("float slope_height_offset(unsigned char slope_type, float dx, float dz) {\n");
printf(" assert((dx >= 0.0f) && (dx <= 1.0f));\n");
printf(" assert((dz >= 0.0f) && (dz <= 1.0f));\n");
printf(" switch(slope_type) {\n");
for (slope_type = 0 ; slope_type < 45; slope_type++) {
//printf("# slope %i\n", slope_type);
printf(" case %i:\n", slope_type);
if (slope_raw_data[slope_type][0][0][1] == slope_raw_data[slope_type][0][1][1]) {
//printf("0, 1\n");
STORE(0, 1, 2);
}
else if (slope_raw_data[slope_type][0][1][1] == slope_raw_data[slope_type][0][2][1]) {
//printf("1, 2\n");
STORE(1, 2, 0);
}
else if (slope_raw_data[slope_type][0][2][1] == slope_raw_data[slope_type][0][3][1]) {
//printf("2, 3\n");
STORE(2, 3, 0);
}
else if (slope_raw_data[slope_type][0][0][1] == slope_raw_data[slope_type][0][2][1]) {
//printf("0, 2\n");
STORE(0, 2, 1);
}
else if (slope_raw_data[slope_type][0][1][1] == slope_raw_data[slope_type][0][3][1]) {
//printf("1, 3\n");
STORE(1, 3, 0);
}
else {
printf("argh?\n");
return(1);
}
if (slope_raw_data[slope_type][0][equal_y1][0] == slope_raw_data[slope_type][0][equal_y2][0]) {
//printf("# x-axis\n");
marked_axis = 0;
}
else if (slope_raw_data[slope_type][0][equal_y1][2] == slope_raw_data[slope_type][0][equal_y2][2]) {
//printf("# z-axis\n");
marked_axis = 2;
}
else {
printf("not good\n");
return(1);
}
float low = 1.0f;
float high = 0.0f;
int low_idx = -1;
int high_idx = -1;
for (vertex = 0; vertex < 4; vertex++) {
if (slope_raw_data[slope_type][0][vertex][1] < low) {
low = slope_raw_data[slope_type][0][vertex][1];
low_idx = vertex;
}
if (slope_raw_data[slope_type][0][vertex][1] > high) {
high = slope_raw_data[slope_type][0][vertex][1];
high_idx = vertex;
}
}
//printf("# low: %f high: %f\n", low, high);
int increasing;
if (slope_raw_data[slope_type][0][low_idx][marked_axis] <
slope_raw_data[slope_type][0][high_idx][marked_axis])
increasing = 1;
else
increasing = 0;
float dt = high - low;
printf("%.4ff %i %i\n", atan(dt / 1.0f) * 180.0f / M_PI, increasing, marked_axis);
for (vertex = 0; vertex < 4; vertex++) {
printf("%f %f %f\n",
slope_raw_data[slope_type][0][vertex][0],
slope_raw_data[slope_type][0][vertex][1],
slope_raw_data[slope_type][0][vertex][2]);
}
}
printf(" default:\n");
printf(" break;\n");
printf(" }\n");
printf(" assert(0);\n");
printf(" return 0.0f; // should never be reached\n");
printf("}\n");
}
+348
View File
@@ -0,0 +1,348 @@
#include <iostream>
#include <SDL_opengl.h>
#include "common_sdl_gl.h"
#include "opengta.h"
#include "gl_texturecache.h"
namespace OpenGTA {
class MapViewGL {
private:
Map* currentMap;
Graphics8Bit* styleDB;
OpenGL::TextureCache<uint8_t>* sideCache;
OpenGL::TextureCache<uint8_t>* lidCache;
public:
MapViewGL();
~MapViewGL();
int loadMap(const std::string &map, const std::string &style);
void drawMap(int32_t x, int32_t y, int32_t dx, int32_t dy);
void drawBlock(Map::BlockInfo* bi);
};
}
namespace OpenGTA {
MapViewGL::MapViewGL() {
currentMap = NULL;
styleDB = NULL;
sideCache = NULL;
lidCache = NULL;
}
MapViewGL::~MapViewGL() {
if (currentMap)
delete currentMap;
if (styleDB)
delete styleDB;
if (sideCache)
delete sideCache;
if (lidCache)
delete lidCache;
}
int MapViewGL::loadMap(const std::string &map, const std::string &style) {
currentMap = new Map(map);
styleDB = new Graphics8Bit(style);
sideCache = new OpenGL::TextureCache<uint8_t>();
lidCache = new OpenGL::TextureCache<uint8_t>();
//currentMap->dump();
return 0;
}
}
extern SDL_Surface* screen;
GLfloat mapPos[3] = {12.0f, 12.0f, 20.0f};
GLfloat camVec[3] = {0.0f, 1.0f, 0.0f};
OpenGTA::MapViewGL *map = NULL;
void on_exit() {
SDL_FreeSurface(screen);
SDL_Quit();
if (map)
delete map;
PHYSFS_deinit();
if (global_EC)
std::cerr << "Exiting after fatal problem - please see output above" << std::endl;
else
std::cout << "Goodbye" << std::endl;
}
void handleKeyPress( SDL_keysym *keysym ) {
switch ( keysym->sym ) {
case SDLK_ESCAPE:
global_Done = 1;
break;
case SDLK_LEFT:
mapPos[0] += 1.0f;
break;
case SDLK_RIGHT:
mapPos[0] -= 1.0f;
if (mapPos[0] < 0.0f)
mapPos[0] = 0.0f;
break;
case SDLK_UP:
mapPos[1] += 1.0f;
break;
case SDLK_DOWN:
mapPos[1] -= 1.0f;
if (mapPos[1] < 0.0f)
mapPos[1] = 0.0f;
break;
case '+':
mapPos[2] += 1.0f;
break;
case '-':
mapPos[2] -= 1.0f;
break;
case 'x':
camVec[0] = 1.0f; camVec[1] = 0.0f; camVec[2] = 0.0f;
break;
case 'y':
camVec[0] = 0.0f; camVec[1] = 1.0f; camVec[2] = 0.0f;
break;
case 'z':
camVec[0] = 0.0f; camVec[1] = 0.0f; camVec[2] = 1.0f;
break;
default:
break;
}
}
GLuint createGLTexture(GLsizei w, GLsizei h, const void* pixels) {
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// GL_LINEAR_MIPMAP_LINEAR);
/*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, w,
h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
*/
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
return tex;
}
void OpenGTA::MapViewGL::drawBlock(OpenGTA::Map::BlockInfo* bi) {
float size = 0.5f;
int jj = 0;
if (bi == NULL)
return;
glEnable(GL_TEXTURE_2D);
if (bi->left) {
// Left Face
if (!sideCache->hasTexture(bi->left)) {
styleDB->getSide(static_cast<unsigned int>(bi->left-1), 0, true);
sideCache->addTexture(bi->left, createGLTexture(64, 64, &styleDB->tileTmpRGBA));
}
glBindTexture(GL_TEXTURE_2D, sideCache->getTextureWithId(bi->left));
//}
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
//glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-size, -size, -size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-size, -size, size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-size, size, size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-size, size, -size);// Top Left Of The Texture and Quad
glEnd();
}
if (bi->right) {
// Right face
if (!sideCache->hasTexture(bi->right)) {
styleDB->getSide(static_cast<unsigned int>(bi->right-1), 0, true);
sideCache->addTexture(bi->right, createGLTexture(64, 64, &styleDB->tileTmpRGBA));
}
glBindTexture(GL_TEXTURE_2D, sideCache->getTextureWithId(bi->right));
//}
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f);
//glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f( size, -size, -size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( size, size, -size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( size, size, size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( size, -size, size);// Bottom Left Of The Texture and Quad
glEnd();
}
if (bi->top) {
// Back Face
if (!sideCache->hasTexture(bi->top)) {
styleDB->getSide(static_cast<unsigned int>(bi->top-1), 0, true);
sideCache->addTexture(bi->top, createGLTexture(64, 64, &styleDB->tileTmpRGBA));
}
glBindTexture(GL_TEXTURE_2D, sideCache->getTextureWithId(bi->top));
//}
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f);
//glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(-size, size, -size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-size, size, size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f( size, size, size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( size, size, -size);// Top Right Of The Texture and Quad
glEnd();
}
if (bi->bottom) {
// Front Face
if (!sideCache->hasTexture(bi->bottom)) {
styleDB->getSide(static_cast<unsigned int>(bi->bottom-1), 0, true);
sideCache->addTexture(bi->bottom, createGLTexture(64, 64, &styleDB->tileTmpRGBA));
}
glBindTexture(GL_TEXTURE_2D, sideCache->getTextureWithId(bi->bottom));
//}
glBegin(GL_QUADS);
//glNormal3f(0.0f, 0.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-size, -size, -size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( size, -size, -size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( size, -size, size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-size, -size, size);// Bottom Right Of The Texture and Quad
glEnd();
}
if (bi->lid) {
// Top Face
if (!lidCache->hasTexture(bi->lid)) {
styleDB->getLid(static_cast<unsigned int>(bi->lid-1), 0, true);
lidCache->addTexture(bi->lid, createGLTexture(64, 64, &styleDB->tileTmpRGBA));
}
if (bi->typeMapExt & 128) {
//std::cout << "blending!" << std::endl;
}
jj = 0;
if (bi->typeMap & 16384) {
jj += 2;
}
if (bi->typeMap & 32768) {
jj += 4;
}
GLfloat lidTex[8] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
#ifdef GLTEX_HELPER
#undef GLTEX_HELPER
#endif
#define GLTEX_HELPER \
glTexCoord2f(lidTex[jj], lidTex[jj+1]); jj += 2; if (jj > 6) { jj = 0; }
glBindTexture(GL_TEXTURE_2D, lidCache->getTextureWithId(bi->lid));
//}
glBegin(GL_QUADS);
GLTEX_HELPER;
//glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(-size, -size, size);// Bottom Left Of The Texture and Quad
GLTEX_HELPER;
glVertex3f( size, -size, size);// Bottom Right Of The Texture and Quad
GLTEX_HELPER;
glVertex3f( size, size, size);// Top Right Of The Texture and Quad
GLTEX_HELPER;
glVertex3f(-size, size, size);// Top Left Of The Texture and Quad
glEnd();
#undef GLTEX_HELPER
}
}
void OpenGTA::MapViewGL::drawMap(int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
if (x1 < 0)
x1 = 0;
if (y1 < 0)
y1 = 0;
// FIXME: can't access 255 either x or y... WHY?
if (x2 >= 255)
x2 = 255;
if (y2 >= 255)
y2 = 255;
//std::cout << "draw: " << x1 << " " << y1 << " - " << x2 << " " << y2 << std::endl;
sideCache->sink();
lidCache->sink();
for (int i = y1; i <= y2; i++) {
glPushMatrix();
glTranslatef(0.0f, -1.0f*i, 0.0f);
for (int j= x1; j <= x2; j++) {
glPushMatrix();
glTranslatef(1.0f*j, 0.0f, 0.0f);
PHYSFS_uint16 emptycount = currentMap->getNumBlocksAt(j,i);
/*glPushMatrix();
* for(int c=0; c < 6 - emptycount-1; c++) */
for (int c=6-emptycount-0; c >= 1; c--) {
drawBlock(currentMap->getBlockAt(j,i, c));
glTranslatef(0.0f, 0.0f, 1.0f);
}
glPopMatrix();
}
glPopMatrix();
}
sideCache->clear();
lidCache->clear();
}
void drawScene() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(mapPos[0], -mapPos[1], mapPos[2], mapPos[0], -mapPos[1], 0.0f, camVec[0], camVec[1], camVec[2]);
//map->drawMap(int(mapPos[0]), int(mapPos[1]));
map->drawMap(int32_t(mapPos[0])-10, int32_t(mapPos[1])-10,int32_t(mapPos[0])+10, int32_t(mapPos[1])+10);
SDL_GL_SwapBuffers();
}
void run_main() {
SDL_Event event;
int paused = 0;
PHYSFS_init("mapview");
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
glEnable(GL_TEXTURE_2D);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
//glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_ALPHA_TEST);
//glDisable(GL_DEPTH_TEST);
map = new OpenGTA::MapViewGL();
map->loadMap("NYC.CMP", "STYLE001.GRY");
while(!global_Done && !global_EC) {
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_ACTIVEEVENT:
if (event.active.gain == 0)
paused = 1;
else
paused = 0;
break;
case SDL_KEYDOWN:
handleKeyPress(&event.key.keysym);
break;
case SDL_VIDEORESIZE:
screen = SDL_SetVideoMode( event.resize.w,
event.resize.h, 32, videoFlags );
if (!screen)
ERROR("Failed to set video mode after resize event");
resize(event.resize.w, event.resize.h);
break;
case SDL_QUIT:
global_Done = 1;
break;
case SDL_MOUSEMOTION:
std::cout << "Mouse move: x " << float(event.motion.x)/screen->w << " y " << float(event.motion.y)/screen->h << std::endl;
break;
default:
break;
}
}
if (!paused)
drawScene();
}
}
+38
View File
@@ -0,0 +1,38 @@
#include <iostream>
#include <cmath>
float slope_raw_data[45][5][4][3] = {
#include "slope1_data.h"
};
int main(int argc, char* argv[]) {
for (int which=0; which <= 44; which++) {
std::cout << " // slope " << which << std::endl;
int side = 0;
float x1,x2,y1,y2,z1,z2 = 0.0f;
x1 = slope_raw_data[which][side][0][0] - slope_raw_data[which][side][1][0];
y1 = slope_raw_data[which][side][0][1] - slope_raw_data[which][side][1][1];
z1 = slope_raw_data[which][side][0][2] - slope_raw_data[which][side][1][2];
x2 = slope_raw_data[which][side][1][0] - slope_raw_data[which][side][2][0];
y2 = slope_raw_data[which][side][1][1] - slope_raw_data[which][side][2][1];
z2 = slope_raw_data[which][side][1][2] - slope_raw_data[which][side][2][2];
float nx,ny,nz,vLen = 0.0f;
nx = (y1 * z2) - (z1 * y2);
ny = (z1 * x2) - (x1 * z2);
nz = (x1 * y2) - (y1 * x2);
vLen = sqrt( (nx * nx) + (ny * ny) + (nz * nz) );
if (vLen == 0.0f)
std::printf("%f %f %f\n", nx, ny, nz);
nx /= vLen;
ny /= vLen;
nz /= vLen;
if (which < 44)
std::printf(" { %f, %f, %f },\n", nx, ny, nz);
else
std::printf(" { %f, %f, %f }\n", nx, ny, nz);
}
}
+114
View File
@@ -0,0 +1,114 @@
#include <iostream>
#include <cmath>
#include <SDL_image.h>
#include <SDL_opengl.h>
#include "common_sdl_gl.h"
#include "opengta.h"
#include "gl_base.h"
#include "gl_font.h"
extern SDL_Surface* screen;
GLfloat mapPos[2] = {0.0f, 0.0f};
GLuint lid;
OpenGL::DrawableFont * font = NULL;
void on_exit() {
if (font != NULL)
delete font;
SDL_Quit();
PHYSFS_deinit();
if (global_EC)
std::cerr << "Exiting after fatal problem - please see output above" << std::endl;
else
std::cout << "Goodbye" << std::endl;
}
void handleKeyPress( SDL_keysym *keysym ) {
switch ( keysym->sym ) {
case SDLK_ESCAPE:
global_Done = 1;
break;
case 'a':
glEnable(GL_CULL_FACE);
printf("backfaces culled\n");
break;
case 'b':
glDisable(GL_CULL_FACE);
printf("all faces drawn\n");
break;
default:
break;
}
}
void drawScene() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// ...
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,640,0,480,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
font->drawString("HELLO 1234567890 Hello !");
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
SDL_GL_SwapBuffers();
}
void run_main() {
SDL_Event event;
int paused = 0;
PHYSFS_init("mapview");
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
PHYSFS_addToSearchPath("gtadata.zip", 1);
font = new OpenGL::DrawableFont();
font->loadFont("STREET1.FON");
glCullFace(GL_BACK);
while(!global_Done && !global_EC) {
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_ACTIVEEVENT:
if (event.active.gain == 0)
paused = 1;
else
paused = 0;
break;
case SDL_KEYDOWN:
handleKeyPress(&event.key.keysym);
break;
case SDL_VIDEORESIZE:
screen = SDL_SetVideoMode( event.resize.w,
event.resize.h, 32, videoFlags );
if (!screen)
ERROR("Failed to set video mode after resize event");
resize(event.resize.w, event.resize.h);
break;
case SDL_QUIT:
global_Done = 1;
break;
default:
break;
}
}
if (!paused)
drawScene();
}
}
+447
View File
@@ -0,0 +1,447 @@
#include <iostream>
#include <cmath>
#include <SDL_image.h>
#include <SDL_opengl.h>
#include "common_sdl_gl.h"
#include "opengta.h"
extern SDL_Surface* screen;
GLfloat mapPos[2] = {0.0f, 0.0f};
OpenGTA::Map *map = NULL;
float slope_raw_data[45][5][4][3] = {
#include "slope1_data.h"
};
float lid_normal_data[45][3] = {
#include "lid_normal_data.h"
};
int slope_idx = 0;
float angle = 0;
GLuint north, south, west, east, lid;
void on_exit() {
SDL_Quit();
if (map)
delete map;
PHYSFS_deinit();
if (global_EC)
std::cerr << "Exiting after fatal problem - please see output above" << std::endl;
else
std::cout << "Goodbye" << std::endl;
}
void handleKeyPress( SDL_keysym *keysym ) {
switch ( keysym->sym ) {
case SDLK_ESCAPE:
global_Done = 1;
break;
case SDLK_LEFT:
mapPos[0] -= 1.0f;
break;
case SDLK_RIGHT:
mapPos[0] += 1.0f;
break;
case SDLK_UP:
mapPos[1] += 1.0f;
break;
case SDLK_DOWN:
mapPos[1] -= 1.0f;
break;
case 'a':
glEnable(GL_CULL_FACE);
printf("backfaces culled\n");
break;
case 'b':
glDisable(GL_CULL_FACE);
printf("all faces drawn\n");
break;
case '.':
angle += 1.0f;
break;
case ',':
angle -= 1.0f;
break;
case '+':
slope_idx++;
if (slope_idx > 44)
slope_idx = 44;
printf("now %i\n", slope_idx);
break;
case '-':
slope_idx--;
if (slope_idx < 0)
slope_idx = 0;
printf("now %i\n", slope_idx);
break;
default:
break;
}
}
void draw_slope(float size, int which) {
float red = 0.4;
float green = 0.7;
float blue = 0.3;
#if 0
float x1,x2,y1,y2,z1,z2 = 0.0f;
x1 = slope_raw_data[which][0][0][0] - slope_raw_data[which][0][1][0];
y1 = slope_raw_data[which][0][0][1] - slope_raw_data[which][0][1][1];
z1 = slope_raw_data[which][0][0][2] - slope_raw_data[which][0][1][2];
x2 = slope_raw_data[which][0][1][0] - slope_raw_data[which][0][2][0];
y2 = slope_raw_data[which][0][1][1] - slope_raw_data[which][0][2][1];
z2 = slope_raw_data[which][0][1][2] - slope_raw_data[which][0][2][2];
float nx,ny,nz,vLen = 0.0f;
nx = (y1 * z2) - (z1 * y2);
ny = (z1 * x2) - (x1 * z2);
nz = (x1 * y2) - (y1 * x2);
vLen = sqrt( (nx * nx) + (ny * ny) + (nz * nz) );
nx /= vLen;
ny /= vLen;
nz /= vLen;
//std::cout << nx << " " << ny << " " << nz << std::endl;
#endif
float nx = lid_normal_data[which][0];
float ny = lid_normal_data[which][1];
float nz = lid_normal_data[which][2];
GLfloat lidTex[8] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
//GLfloat lidTex[8] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
#ifdef GLTEX_HELPER
#undef GLTEX_HELPER
#endif
#define GLTEX_HELPER \
glTexCoord2f(lidTex[jj], lidTex[jj+1]); jj += 2; if (jj > 6) { jj = 0; }
for (int i=0; i<5; i++) {
if (i == 0) {
red = green = 0.0f;
blue = 1.0f;
}
else if (i == 1) {
red = blue = 0.0f;
green = 1.0f;
}
else if (i == 2) {
red = 1.0f;
blue = green = 0.0f;
}
else if (i == 3) {
red = 0.0f;
blue = green = 1.0f;
}
else if (i == 4) {
red = green = 1.0f;
blue = 0.0f;
}
if (which == 41 && i == 1)
continue;
if (which == 42 && i == 2)
continue;
if (which == 43 && i == 4)
continue;
if (which == 44 && i == 3)
continue;
/*
if (i == 0)
glBindTexture(GL_TEXTURE_2D, lid);
if (i == 1)
glBindTexture(GL_TEXTURE_2D, north);
if (i == 2)
glBindTexture(GL_TEXTURE_2D, south);
if (i == 3)
glBindTexture(GL_TEXTURE_2D, east); // FIXME: flipped west<->east ???
if (i == 4)
glBindTexture(GL_TEXTURE_2D, west);
*/
glBegin(GL_QUADS);
glColor3f(red, green, blue);
switch(i) {
case 0:
glNormal3f(nx, ny, nz);
break;
case 1:
glNormal3f(0.0f, 0.0f, 1.0f);
break;
case 2:
glNormal3f(0.0f, 0.0f, -1.0f);
break;
case 3:
glNormal3f(-1.0f, 0.0f, 0.0f);
break;
case 4:
glNormal3f(1.0f, 0.0f, 0.0f);
break;
}
int jj = 0;
for (int j=0; j < 4; j++) {/*
switch(j) {
case 0:
//glNormal3f(0.0f, 0.0f, 1.0f);
break;
case 1:
//glNormal3f(0.0f, -1.0f, 0.0f);
break;
case 2:
//glNormal3f(0.0f, 1.0f, 0.0f);
break;
}*/
//GLTEX_HELPER;
glVertex3f(slope_raw_data[which][i][j][0],
slope_raw_data[which][i][j][1],
slope_raw_data[which][i][j][2]);
}
glEnd();
#if 0
if (i == 0) {
glBegin(GL_LINES);
glColor3f(0.0f, 0.0f, 0.5f);
glVertex3f(0.5f, 1.0f, -0.5f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.5f+nx, 1.0f+ny, -0.5f+nz);
glEnd();
}
if (i == 1) {
glBegin(GL_LINES);
glColor3f(0.0f, 0.5f, 0.0f);
glVertex3f(0.5f, 0.5f, 0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, 1.0f);
glEnd();
}
if (i == 2) {
glBegin(GL_LINES);
glColor3f(0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, 0.5f, -1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, -2.0f);
glEnd();
}
if (i == 3) {
glBegin(GL_LINES);
glColor3f(0.0f, 0.5f, 0.5f);
glVertex3f(0.0f, 0.5f, -0.5f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 0.5f, -0.5f);
glEnd();
}
if (i == 4) {
glBegin(GL_LINES);
glColor3f(0.5f, 0.5f, 0.0f);
glVertex3f(1.0f, 0.5f, -0.5f);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(2.0f, 0.5f, -0.5f);
glEnd();
}
#endif
}
}
#if 0
void draw_cube(float size) {
/* thanks to lesson 6 at Nehe */
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 1.0f);
// Front Face
glTexCoord2f(0.0f, 0.0f);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(-size, -size, size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f( size, -size, size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( size, size, size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-size, size, size);// Top Left Of The Texture and Quad
glColor3f(1.0f, 0.0f, 0.0f);
// Back Face
glTexCoord2f(1.0f, 0.0f);
glNormal3f(0.0f, -1.0f, 0.0f);
glVertex3f(-size, -size, -size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-size, size, -size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( size, size, -size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( size, -size, -size);// Bottom Left Of The Texture and Quad
glColor3f(1.0f, 1.0f, 1.0f);
// Top Face
glTexCoord2f(0.0f, 1.0f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(-size, size, -size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-size, size, size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f( size, size, size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( size, size, -size);// Top Right Of The Texture and Quad
// Bottom Face
glColor3f(1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f);
glNormal3f(0.0f, 0.0f, -1.0f);
glVertex3f(-size, -size, -size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( size, -size, -size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( size, -size, size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-size, -size, size);// Bottom Right Of The Texture and Quad
// Right face
glColor3f(1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f);
glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f( size, -size, -size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f( size, size, -size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f( size, size, size);// Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f);
glVertex3f( size, -size, size);// Bottom Left Of The Texture and Quad
// Left Face
glColor3f(1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-size, -size, -size);// Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-size, -size, size);// Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-size, size, size);// Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-size, size, -size);// Top Left Of The Texture and Quad
glEnd();
}
#endif
void drawScene() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(5.0f, 5.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(mapPos[0], mapPos[1], 0.0f);
/*
for (int i=0; i<50; i++) {
glPushMatrix();
glTranslatef(0.0f, float(i), 0.0f);
for (int j=0; j<50; j++) {
glTranslatef(1.0f, 0.0f, 0.0f);
float step_col = 0.0f;
glColor3f(0.2f+step_col, 0.2f+step_col, 1.0f-step_col);
PHYSFS_uint16 emptycount = map->getNumBlocksAt(j,i);
glPushMatrix();
for(int c=0; c < 6 - emptycount; c++) {
draw_cube(0.5f);
glTranslatef(0.0f, 0.0f, 1.0f);
step_col += 0.2;
glColor3f(0.2f+step_col, 0.1f+step_col, 1.0f-step_col);
}
glPopMatrix();
}
glPopMatrix();
}*/
//draw_cube(1.0f);
glRotatef(angle, 0, 1, 0);
glEnable(GL_TEXTURE_2D);
draw_slope(1.0f, slope_idx);
SDL_GL_SwapBuffers();
}
GLuint createGLTexture(GLsizei w, GLsizei h, const void* pixels) {
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glEnable(GL_COLOR_MATERIAL);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// GL_LINEAR_MIPMAP_LINEAR);
/*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, w,
h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
*/
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
return tex;
}
void run_main() {
SDL_Event event;
int paused = 0;
PHYSFS_init("mapview");
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
/*
SDL_Surface * tex = IMG_Load("lid.jpg");
SDL_LockSurface(tex);
lid = createGLTexture(tex->w, tex->h, tex->pixels);
SDL_UnlockSurface(tex);
SDL_FreeSurface(tex);
tex = IMG_Load("north.jpg");
SDL_LockSurface(tex);
north = createGLTexture(tex->w, tex->h, tex->pixels);
SDL_UnlockSurface(tex);
SDL_FreeSurface(tex);
tex = IMG_Load("south.jpg");
SDL_LockSurface(tex);
south = createGLTexture(tex->w, tex->h, tex->pixels);
SDL_UnlockSurface(tex);
SDL_FreeSurface(tex);
tex = IMG_Load("west.jpg");
SDL_LockSurface(tex);
west = createGLTexture(tex->w, tex->h, tex->pixels);
SDL_UnlockSurface(tex);
SDL_FreeSurface(tex);
tex = IMG_Load("east.jpg");
SDL_LockSurface(tex);
east = createGLTexture(tex->w, tex->h, tex->pixels);
SDL_UnlockSurface(tex);
SDL_FreeSurface(tex);
*/
//glDisable(GL_COLOR_MATERIAL);
glCullFace(GL_BACK);
//glEnable(GL_CULL_FACE);
//map = new OpenGTA::Map("NYC.CMP");
while(!global_Done && !global_EC) {
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_ACTIVEEVENT:
if (event.active.gain == 0)
paused = 1;
else
paused = 0;
break;
case SDL_KEYDOWN:
handleKeyPress(&event.key.keysym);
break;
case SDL_VIDEORESIZE:
screen = SDL_SetVideoMode( event.resize.w,
event.resize.h, 32, videoFlags );
if (!screen)
ERROR("Failed to set video mode after resize event");
resize(event.resize.w, event.resize.h);
break;
case SDL_QUIT:
global_Done = 1;
break;
default:
break;
}
}
if (!paused)
drawScene();
}
glDeleteTextures(1, &lid);
glDeleteTextures(1, &north);
glDeleteTextures(1, &south);
glDeleteTextures(1, &west);
glDeleteTextures(1, &east);
}
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
in_file=doc/hacking.txt
out_file=doxy_main.h
function makeM4() {
sed -e "s/ ==*$/', \`/" \
-e 's/^== /MAINPAGE(`/' \
-e "s/^= \([^ ]*\)/') \\
PAGE(\`\\1 \\1/" \
$in_file
echo "')"
}
function convertM4_Doxygen() {
m4 -DBEGIN_CPP_COMMENT='/*!' -DEND_CPP_COMMENT='*/' -DMAINPAGE='BEGIN_CPP_COMMENT \mainpage $1
$2
END_CPP_COMMENT' -DPAGE='BEGIN_CPP_COMMENT \page $1
$2
END_CPP_COMMENT' -D_='<tt>$1</tt>' -
}
makeM4 | convertM4_Doxygen
+52
View File
@@ -0,0 +1,52 @@
#include <stdio.h>
float slope_raw_data[45][5][4][3] = {
#include "slope1_data.h"
};
int main(int argc, char* argv[]) {
int slope_type, face_num, vertex;
int tex_x, tex_y;
for (slope_type = 0 ; slope_type < 45; slope_type++) {
printf("{ // slope: %i\n", slope_type);
for (face_num = 1; face_num < 5; face_num++) {
switch (face_num) {
case 0:
printf(" { // lid\n");
tex_x = 0;
tex_y = 2;
break;
case 1:
printf(" { // north\n");
tex_x = 0;
tex_y = 1;
break;
case 2:
printf(" { // south\n");
tex_x = 0;
tex_y = 1;
break;
case 3:
printf(" { // west\n");
tex_x = 2;
tex_y = 1;
break;
case 4:
printf(" { // east\n");
tex_x = 2;
tex_y = 1;
break;
}
for (vertex = 0; vertex < 4; vertex++) {
float x_tmp = ((face_num == 1) || (face_num == 3)) ? slope_raw_data[slope_type][face_num][vertex][tex_x] :
1.0f - slope_raw_data[slope_type][face_num][vertex][tex_x];
printf(" { %.2f, %.2f %s\n", x_tmp,
1.0f-slope_raw_data[slope_type][face_num][vertex][tex_y],
(vertex == 3) ? "}" : "},");
}
printf(" %s\n", (face_num == 4) ? "}" : "},");
}
printf("%s\n", (slope_type == 44) ? "}" : "},");
}
}
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
copyright_file=licenses/zlib_header.txt
if [ $# -gt 0 ]; then
input=$1
if [ $# -eq 2 ]; then
copyright_file=$2
fi
fi
sed '1{h; r $1
D; }
2{x; G; }' $copyright_file $input
+76
View File
@@ -0,0 +1,76 @@
#include <cassert>
#include "opengta.h"
#include "navdata.h"
#include "log.h"
int main(int argc, char* argv[]) {
int x = 0;
int y = 0;
if (argc < 2) {
std::cerr << "USAGE: mapinfo map_filename [x y]" << std::endl;
return 1;
}
PHYSFS_init(argv[0]);
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
std::string map_filename(argv[1]);
OpenGTA::Map map(map_filename);
if (argc == 4) {
x = atoi(argv[2]);
y = atoi(argv[3]);
}
if (x < 0)
x = 0;
if (y < 0)
y = 0;
INFO << "Querying position: " << x << ", " << y << std::endl;
OpenGTA::NavData::Sector* sec = map.nav->getSectorAt(x, y);
INFO << "* " << sec->name << " *" << std::endl;
PHYSFS_uint16 num_blocks = map.getNumBlocksAt(x, y);
OpenGTA::Map::BlockInfo* bi = NULL;
INFO << num_blocks << " empty blocks" << std::endl;
for (int c=6-num_blocks; c >= 1; c--) {
std::cout << "block " << c << std::endl;
bi = map.getBlockAt(x, y, c);
assert(bi);
std::cout << "moves: "<< int(bi->upOk()) << ", " << int(bi->downOk()) << ", "
<< int(bi->leftOk()) << ", " << int(bi->rightOk()) << std::endl;
std::cout << "type: " << int(bi->blockType()) << " flat: " <<
int(bi->isFlat()) << " slope-type: " << int(bi->slopeType()) <<
" rot: " << int(bi->rotation()) << " remap idx: " <<
int(bi->remapIndex()) << std::endl;
std::cout << "textures: left " << int(bi->left) << " right " << int(bi->right) <<
" top " << int(bi->top) << " bottom " << int(bi->bottom) << " lid " << int(bi->lid)
<< " flip t-b: " << int(bi->flipTopBottom()) << " flip l-r: " <<
int(bi->flipLeftRight()) << std::endl;
int v_count = 0;
if (bi->lid)
v_count += 3*4;
if (bi->isFlat()) {
if (bi->top)
v_count += 3*4*2;
if (bi->left)
v_count += 3*4*2;
}
else {
if (bi->left)
v_count += 3*4;
if (bi->right)
v_count += 3*4;
if (bi->top)
v_count += 3*4;
if (bi->bottom)
v_count += 3*4;
}
}
PHYSFS_deinit();
return 0;
}
+105
View File
@@ -0,0 +1,105 @@
#include <cassert>
#include "opengta.h"
#include "log.h"
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "USAGE: minimap map_filename" << std::endl;
std::cerr << "saves map as 'out.bmp'" << std::endl;
return 1;
}
PHYSFS_init(argv[0]);
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
PHYSFS_addToSearchPath("gtadata.zip", 1);
std::string map_filename(argv[1]);
OpenGTA::Map map(map_filename);
uint32_t green = 0x00dd00ff;
uint32_t red = 0xdd0000ff;
uint32_t blue = 0x0000ddff;
uint32_t field = green;
uint32_t building = 0xdf9f6fff;
uint32_t water = blue;
uint32_t road = 0xdadadaff;
uint32_t pavement = 0x8a9aa0ff;
uint32_t map_color[] = {
0x000000ff,
water,
road,
pavement,
field,
building,
0xffffffff,
0xff0000ff
};
SDL_Init(SDL_INIT_VIDEO);
// FIXME: doesn't work right
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define rmask 0xff000000
#define gmask 0x00ff0000
#define bmask 0x0000ff00
#define amask 0x000000ff
#else
#define rmask 0x000000ff
#define gmask 0x0000ff00
#define bmask 0x00ff0000
#define amask 0xff000000
#endif
SDL_Surface* surface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
256, 256, 32,// rmask, gmask, bmask, amask);
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
SDL_LockSurface(surface);
uint32_t* dst = static_cast<uint32_t*>(surface->pixels);
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
PHYSFS_uint16 emptycount = map.getNumBlocksAt(j,i);
int found_type = 0;
for (int c=6-emptycount; c > 0; c--) {
OpenGTA::Map::BlockInfo* bi = map.getBlockAt(j, i, c);
/*
if (bi->blockType() > 0)
found_type = bi->blockType();
*/
/*
if (bi->railway())
found_type = 2;
if (bi->railStation())
found_type = 0;
if (bi->railStationTrain())
std::cout << " train: " << i << ", " << j << std::endl;
if (bi->railStartTurn())
std::cout << " start: " << i << ", " << j << std::endl;
if (bi->railEndTurn())
std::cout << " end: " << i << ", " << j << std::endl;
*/
if (bi->blockType() > 0)
found_type = bi->blockType();
if (bi->trafficLights())
found_type = 0;
if (bi->railway())
found_type = 7;
}
if (found_type)
*dst = map_color[found_type];
else
*dst = 0x000000ff;
dst++;
}
}
SDL_UnlockSurface(surface);
SDL_SaveBMP(surface, "out.bmp");
SDL_Quit();
return 0;
}
+92
View File
@@ -0,0 +1,92 @@
#include <iostream>
#include <string>
#include "opengta.h"
extern int global_EC;
extern int global_Done;
std::string map_file("undefined_map_file");
std::string style_file("undefined_style_file");
void on_exit() {
PHYSFS_deinit();
if (global_EC)
std::cerr << "Exiting after fatal problem - please see output above" << std::endl;
}
void parse_args(int argc, char* argv[]) {
#ifdef DUMP_OBJ_IN_MAP
if (argc != 3) {
std::cout << "USAGE: " << argv[0] << " map-file 8-bit-style-file" << std::endl;
exit(1);
}
map_file = argv[1];
style_file = argv[2];
#else
if (argc != 2) {
std::cout << "USAGE: " << argv[0] << " map-file 8-bit-style-file" << std::endl;
exit(1);
}
map_file = "";
style_file = argv[1];
#endif
}
void run_init() {
PHYSFS_init("mapview");
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
PHYSFS_addToSearchPath("gtadata.zip", 1);
}
#ifdef DUMP_OBJ_IN_MAP
void run_main() {
OpenGTA::Map map(map_file);
OpenGTA::Graphics8Bit style(style_file);
for (int i = 0; i < map.numObjects; i++) {
OpenGTA::Map::ObjectPosition & o = map.objects[i];
std::cout << "object: " << i << std::endl;
std::cout << o.x << ", " << o.y << ", " << o.z << " rot: " << o.rotation <<
" pitch: " << o.pitch << " roll: " << o.roll << std::endl;
std::cout << "type: " << int(o.type);
if (o.remap >= 128) {
std::cout << " (a car) remap: " << int(o.remap - 128) << std::endl;
OpenGTA::GraphicsBase::CarInfo * info = style.findCarByModel(o.type);
assert(info);
std::cout << "width: " << info->width << " height: "<< info->height <<
" depth " << info->depth << " sprnum: " << info->sprNum << " weight: " << info->weightDescriptor
<< std::endl;
}
else {
std::cout << " (an obj) remap: " << int(o.remap) << std::endl;
OpenGTA::GraphicsBase::ObjectInfo * info = style.objectInfos[o.type];
std::cout << "width: " << info->width << " height: "<< info->height <<
" depth " << info->depth << " sprnum: " << info->sprNum << " weight: " << info->weight
<< " aux: " << info->aux << " status: " << int(info->status) << " n-into: " << int(info->numInto) << std::endl;
}
std::cout << std::endl;
}
}
#else
// dump object/sprite-infos
void run_main() {
OpenGTA::Graphics8Bit style(style_file);
std::cout << "DUMP_OBJ_INFO BEGIN" << std::endl;
for (size_t i = 0; i < style.objectInfos.size(); ++i) {
std::cout << "obj-type: " << i << " width: " << style.objectInfos[i]->width << " height: "
<< style.objectInfos[i]->height << " depth: " << style.objectInfos[i]->depth <<
" spr-num: " << style.objectInfos[i]->sprNum << " reindex: " << style.spriteNumbers.reIndex(style.objectInfos[i]->sprNum, OpenGTA::GraphicsBase::SpriteNumbers::OBJECT) << " weight: " << style.objectInfos[i]->weight << " aux: " <<
style.objectInfos[i]->aux << " status: " << int(style.objectInfos[i]->status) << " num-into: " <<
int(style.objectInfos[i]->numInto) << std::endl;
}
std::cout << "DUMP_OBJ_INFO END" << std::endl;
for (size_t i = 0; i < style.spriteInfos.size(); ++i) {
std::cout << "sprite: " << i << " width: " << int(style.spriteInfos[i]->w) << " height: " <<
int(style.spriteInfos[i]->h) << " delta-count: " << int(style.spriteInfos[i]->deltaCount)<< std::endl;
}
}
#endif
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
sed_term="$1"
shift
while [ $# -gt 0 ]; do
cp $1 $1.bak
sed -e "$sed_term" $1.bak >${1}
rm $1.bak
shift
done
+70
View File
@@ -0,0 +1,70 @@
#include <stdio.h>
float slope_raw_data[45][5][4][3] = {
#include "slope1_data.h"
};
int main(int argc, char* argv[]) {
int slope_type, face_num, vertex;
int tex_x, tex_y;
for (slope_type = 0 ; slope_type < 45; slope_type++) {
printf("{ // slope: %i\n", slope_type);
for (face_num = 0; face_num < 5; face_num++) {
switch (face_num) {
case 0:
printf(" { // lid\n");
tex_x = 0;
tex_y = 2;
break;
case 1:
printf(" { // north\n");
tex_x = 0;
tex_y = 1;
break;
case 2:
printf(" { // south\n");
tex_x = 0;
tex_y = 1;
break;
case 3:
printf(" { // west\n");
tex_x = 2;
tex_y = 1;
break;
case 4:
printf(" { // east\n");
tex_x = 2;
tex_y = 1;
break;
}
int face_lower_left_found = 0;
int face_lower_left_is = -1;
for (vertex = 0; vertex < 3; vertex++) {
if ((slope_raw_data[slope_type][face_num][vertex][tex_x] ==
slope_raw_data[slope_type][face_num][vertex+1][tex_x]) &&
(slope_raw_data[slope_type][face_num][vertex][tex_y] ==
slope_raw_data[slope_type][face_num][vertex+1][tex_y]))
printf("// degenerate face\n");
}
for (vertex = 0; vertex < 4; vertex++) {
char* c;
if (slope_raw_data[slope_type][face_num][vertex][tex_x] == 0.0f &&
slope_raw_data[slope_type][face_num][vertex][tex_y] == 0.0f) {
c = "// *";
face_lower_left_found += 1;
face_lower_left_is = vertex;
}
else
c = "";
printf(" { %.2f, %.2f %.2f %s %s\n", slope_raw_data[slope_type][face_num][vertex][0],
slope_raw_data[slope_type][face_num][vertex][1],
slope_raw_data[slope_type][face_num][vertex][2],
(vertex == 3) ? "}" : "},", c);
}
printf("// %i lower faces; last: %i\n", face_lower_left_found, face_lower_left_is);
printf(" %s\n", (face_num == 4) ? "}" : "},");
}
printf("%s\n", (slope_type == 44) ? "}" : "},");
}
}
+91
View File
@@ -0,0 +1,91 @@
BEGIN {
slope_idx = -1;
mode_seek_slope_hdr = 0;
mode_seek_type = 1;
mode_seek_modifier = 2;
mode_seek_vertices = 3;
num_vertices_read = 0;
first_pass_flag = 0;
reverse_flag = 0;
till_block_complete = -1;
mode = mode_seek_slope_hdr;
}
{
if (mode == mode_seek_slope_hdr) {
if ($1 == "Slope:") {
#print "** slope start " $2;
print "{ // slope: " $2;
mode = mode_seek_type;
slope_idx = $2;
till_block_complete = 5;
next;
}
}
if (mode == mode_seek_type) {
if ($1 == "LID" || $1 == "NORTH" || $1 == "SOUTH" || $1 == "WEST" || $1 == "EAST") {
#print "* type " $1;
last_type = $1;
mode = mode_seek_modifier;
first_pass_flag = 0;
reverse_flag = 0;
num_vertices_read = 0;
till_block_complete = till_block_complete - 1;
next;
}
}
if (mode == mode_seek_modifier) {
first_pass_flag = $1;
reverse_flag = $2;
mode = mode_seek_vertices;
#print "* modifier: " first_pass_flag " " reverse_flag;
next;
}
if (mode == mode_seek_vertices) {
gsub(",", ".", $0);
gsub(". ", ", ", $0);
#print "v (" num_vertices_read "): " $0;
# FIX: switch y<->z order
gsub(",", "", $2);
# offset y coord
$2 = $2 + 1
vertices[num_vertices_read] = $1 " " $3 ", " $2;
#vertices[num_vertices_read] = $1 " " $2 ".00, " $3; # cheat .00 back
num_vertices_read = num_vertices_read + 1;
if (num_vertices_read == 4) {
mode = mode_seek_type;
#print "* end slope";
print " { // " last_type;
if (reverse_flag == 0) {
for (v=3; v > 0; v--) {
print " { " vertices[v] " },";
}
print " { " vertices[0] " }";
if (last_type == "EAST") {
print " }";
}
else {
print " },";
}
}
else {
for (v=3; v >= 0; v--) {
print vertices[v];
}
}
if (till_block_complete == 0) {
# print "** end block"
if (slope_idx == 44) {
print "}";
}
else {
print "},";
}
mode = mode_seek_slope_hdr;
}
}
next;
}
}
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
INPUT=slope1_data.h
function fetch_data () {
local k=$1
sed -n "/{ \/\/ slope: $k$/,/^\},/p" $INPUT
}
fetch_data 0
fetch_data 3
fetch_data 4
fetch_data 1
fetch_data 2
for i in `seq 5 8`; do
fetch_data $i
done
for i in `seq 17 24`; do
fetch_data $i
done
for i in `seq 9 16`; do
fetch_data $i
done
for i in `seq 25 40`; do
fetch_data $i
done
fetch_data 42
fetch_data 41
fetch_data 43
fetch_data 44
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
cat <<EOF
<html>
<body>
<h4>side textures of style001.g24 - slightly wrong palette</h4>
EOF
for idx in `seq 0 50`; do
clut=$(./g24 STYLE001.G24 $idx style1_side${idx}.bmp | grep clut-idx)
convert style1_side${idx}.bmp style1_side${idx}.png
rm style1_side${idx}.bmp
echo "<p><img src=\"style1_side${idx}.png\"><br> style 001, side $idx ; found $clut</p>"
done
cat <<EOF
</body>
</html>