forked from mirrors/principia
Clean up a bunch of unused functions
This commit is contained in:
parent
1ddc8f01af
commit
6874504d35
46 changed files with 306 additions and 1619 deletions
|
|
@ -58,7 +58,7 @@ file(GLOB SRCS
|
|||
src/tms/math/*.c
|
||||
src/tms/util/*.c
|
||||
src/tms/bindings/cpp/cpp.cc
|
||||
src/tms/modules/3ds/3ds.c
|
||||
src/tms/modules/3ds.c
|
||||
|
||||
src/lua/*.c
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ GLOBAL_FLAGS += -I../src/tms/backends/linux/ \
|
|||
principia_CFLAGS = ${GLOBAL_FLAGS} -std=gnu99
|
||||
principia_CXXFLAGS = ${GLOBAL_FLAGS}
|
||||
principia_LDADD = -lz -ldl -lGL -lGLEW -lpthread -lX11 -lXi -lrt ${GTK_SOURCEVIEW_LIBS} ${GTK_LIBS} -lcurl -ljpeg -lpng -lfreetype ${SDL2_LIBS} ${SDL2_TTF_LIBS} ${SDL2_GFX_LIBS} ${SDL2_IMAGE_LIBS} ${SDL2_MIXER_LIBS}
|
||||
principia_LDFLAGS =
|
||||
principia_LDFLAGS =
|
||||
|
||||
principia_SOURCES = \
|
||||
../src/tms/core/atlas.c \
|
||||
|
|
@ -58,15 +58,12 @@ principia_SOURCES = \
|
|||
../src/tms/core/varray.c \
|
||||
../src/tms/core/wdg.c \
|
||||
../src/tms/math/intersect.c \
|
||||
../src/tms/math/lorenz.c \
|
||||
../src/tms/math/math.c \
|
||||
../src/tms/math/rk4.c \
|
||||
../src/tms/util/hash.c \
|
||||
../src/tms/util/list.c \
|
||||
\
|
||||
../src/tms/backends/linux/main.cc \
|
||||
../src/tms/bindings/cpp/cpp.cc \
|
||||
../src/tms/modules/3ds/3ds.c \
|
||||
../src/tms/modules/3ds.c \
|
||||
\
|
||||
../src/lua/eris.c \
|
||||
../src/lua/lapi.c \
|
||||
|
|
|
|||
|
|
@ -127,16 +127,13 @@ principia.rc \
|
|||
../src/tms/core/varray.c \
|
||||
../src/tms/core/wdg.c \
|
||||
../src/tms/math/intersect.c \
|
||||
../src/tms/math/lorenz.c \
|
||||
../src/tms/math/math.c \
|
||||
../src/tms/math/rk4.c \
|
||||
../src/tms/util/hash.c \
|
||||
../src/tms/util/list.c \
|
||||
\
|
||||
../src/tms/backends/windows/main.cc \
|
||||
../src/GLEW/glew.c \
|
||||
../src/tms/bindings/cpp/cpp.cc \
|
||||
../src/tms/modules/3ds/3ds.c \
|
||||
../src/tms/modules/3ds.c \
|
||||
\
|
||||
../src/src/fluid.cc \
|
||||
../src/src/oilrig.cc \
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
APP_OPTIM := release
|
||||
|
||||
APP_STL := c++_static
|
||||
APP_ABI := armeabi-v7a x86
|
||||
#APP_ABI := armeabi armeabi-v7a
|
||||
#TARGET_CPU_ABI := armeabi-v7a
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
|
|
|||
|
|
@ -120,27 +120,3 @@ crc32_level(const lvlinfo &lvl, const lvlbuf &lb, uint32_t timestamp, uint32_t l
|
|||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
crc32_file(const char *path)
|
||||
{
|
||||
unsigned char buf[CRC_BUFFER_SIZE];
|
||||
size_t buf_len;
|
||||
FILE *fh = fopen(path, "rb");
|
||||
|
||||
if (!fh) {
|
||||
tms_errorf("Unable to open %s for reading.", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t crc = crc32(0L, Z_NULL, 0);
|
||||
while ((buf_len = fread(buf, 1, CRC_BUFFER_SIZE, fh)) != 0) {
|
||||
crc = crc32(crc, buf, buf_len);
|
||||
}
|
||||
|
||||
tms_debugf("got crc: %08X", crc);
|
||||
|
||||
fclose(fh);
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,5 +17,3 @@ uint32_t crc32_level(
|
|||
uint32_t timestamp,
|
||||
uint32_t last_score,
|
||||
int method);
|
||||
|
||||
uint32_t crc32_file(const char *path);
|
||||
|
|
|
|||
|
|
@ -826,6 +826,17 @@ tproject_step(void)
|
|||
#endif
|
||||
break;
|
||||
|
||||
case ACTION_PUBLISH:
|
||||
tms_debugf("action publish");
|
||||
P.s_loading_screen->load(publish_loader, G);
|
||||
G->resume_action = GAME_RESUME_CONTINUE;
|
||||
break;
|
||||
|
||||
case ACTION_SUBMIT_SCORE:
|
||||
P.s_loading_screen->load(submit_score_loader, G);
|
||||
G->resume_action = GAME_RESUME_CONTINUE;
|
||||
break;
|
||||
|
||||
#endif
|
||||
|
||||
case ACTION_RELOAD_DISPLAY:
|
||||
|
|
|
|||
106
src/src/misc.cc
106
src/src/misc.cc
|
|
@ -3,126 +3,20 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef TMS_BACKEND_WINDOWS
|
||||
#include <windows.h>
|
||||
|
||||
static time_t
|
||||
filetime_to_timet(FILETIME & ft)
|
||||
{
|
||||
ULARGE_INTEGER ull;
|
||||
ull.LowPart = ft.dwLowDateTime;
|
||||
ull.HighPart = ft.dwHighDateTime;
|
||||
return ull.QuadPart / 10000000ULL - 11644473600ULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
time_t
|
||||
get_mtime(const char *path)
|
||||
{
|
||||
time_t mtime;
|
||||
char date[21];
|
||||
|
||||
#if defined(TMS_BACKEND_WINDOWS) && 0
|
||||
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||
|
||||
GetFileAttributesEx((LPCWSTR)(path), GetFileExInfoStandard, &data);
|
||||
|
||||
FILETIME time = data.ftLastWriteTime;
|
||||
SYSTEMTIME sys_time, local_time;
|
||||
|
||||
FileTimeToSystemTime(&time, &sys_time);
|
||||
SystemTimeToTzSpecificLocalTime(0, &sys_time, &local_time);
|
||||
snprintf(date, 20, "%04d-%02d-%02d %02d:%02d:%02d", local_time.wYear, local_time.wMonth, local_time.wDay, local_time.wHour, local_time.wMinute, local_time.wSecond);
|
||||
mtime = filetime_to_timet(time);
|
||||
#else
|
||||
struct stat st;
|
||||
stat(path, &st);
|
||||
strftime(date, 20, "%Y-%m-%d %H:%M:%S", gmtime((time_t*)&(st.st_mtime)));
|
||||
mtime = st.st_mtime;
|
||||
#endif
|
||||
|
||||
return mtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* http://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C
|
||||
**/
|
||||
int
|
||||
base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize)
|
||||
{
|
||||
const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
const uint8_t *data = (const uint8_t *)data_buf;
|
||||
size_t resultIndex = 0;
|
||||
size_t x;
|
||||
uint32_t n = 0;
|
||||
int padCount = dataLength % 3;
|
||||
uint8_t n0, n1, n2, n3;
|
||||
|
||||
/* increment over the length of the string, three characters at a time */
|
||||
for (x = 0; x < dataLength; x += 3)
|
||||
{
|
||||
/* these three 8-bit (ASCII) characters become one 24-bit number */
|
||||
n = data[x] << 16;
|
||||
|
||||
if((x+1) < dataLength)
|
||||
n += data[x+1] << 8;
|
||||
|
||||
if((x+2) < dataLength)
|
||||
n += data[x+2];
|
||||
|
||||
/* this 24-bit number gets separated into four 6-bit numbers */
|
||||
n0 = (uint8_t)(n >> 18) & 63;
|
||||
n1 = (uint8_t)(n >> 12) & 63;
|
||||
n2 = (uint8_t)(n >> 6) & 63;
|
||||
n3 = (uint8_t)n & 63;
|
||||
|
||||
/*
|
||||
* if we have one byte available, then its encoding is spread
|
||||
* out over two characters
|
||||
*/
|
||||
if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */
|
||||
result[resultIndex++] = base64chars[n0];
|
||||
if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */
|
||||
result[resultIndex++] = base64chars[n1];
|
||||
|
||||
/*
|
||||
* if we have only two bytes available, then their encoding is
|
||||
* spread out over three chars
|
||||
*/
|
||||
if((x+1) < dataLength)
|
||||
{
|
||||
if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */
|
||||
result[resultIndex++] = base64chars[n2];
|
||||
}
|
||||
|
||||
/*
|
||||
* if we have all three bytes available, then their encoding is spread
|
||||
* out over four characters
|
||||
*/
|
||||
if((x+2) < dataLength)
|
||||
{
|
||||
if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */
|
||||
result[resultIndex++] = base64chars[n3];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* create and add padding that is required if we did not have a multiple of 3
|
||||
* number of characters available
|
||||
*/
|
||||
if (padCount > 0)
|
||||
{
|
||||
for (; padCount < 3; padCount++)
|
||||
{
|
||||
if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */
|
||||
result[resultIndex++] = '=';
|
||||
}
|
||||
}
|
||||
if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */
|
||||
result[resultIndex] = 0;
|
||||
return 1; /* indicate success */
|
||||
}
|
||||
|
||||
std::vector<char*>
|
||||
p_split(const char *str, size_t len, const char *delim)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,8 +87,6 @@ file_exists(const char *path)
|
|||
|
||||
time_t get_mtime(const char *path);
|
||||
|
||||
int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize);
|
||||
|
||||
inline uint8_t
|
||||
tpixel_mat_to_chunk_mat(uint8_t mat)
|
||||
{
|
||||
|
|
|
|||
249
src/src/noise.cc
249
src/src/noise.cc
|
|
@ -52,7 +52,7 @@ static unsigned char perm[512] = {151,160,137,91,90,15,
|
|||
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
|
||||
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
|
||||
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
|
||||
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
|
||||
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -132,7 +132,7 @@ _noise_init_perm(unsigned long seed)
|
|||
perm[i] = t;
|
||||
}
|
||||
|
||||
for (int x=0; x<256; x++)
|
||||
for (int x=0; x<256; x++)
|
||||
perm[x+256] = perm[x];
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ _noise2 (float x, float y)
|
|||
if(t0 < 0.0f) n0 = 0.0f;
|
||||
else {
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad2(perm[ii+perm[jj]], x0, y0);
|
||||
n0 = t0 * t0 * grad2(perm[ii+perm[jj]], x0, y0);
|
||||
}
|
||||
|
||||
t1 = 0.5f - x1*x1-y1*y1;
|
||||
|
|
@ -232,246 +232,3 @@ _noise2 (float x, float y)
|
|||
/* The result is scaled to return values in the interval [-1,1]. */
|
||||
return 40.0f * (n0 + n1 + n2); /* TODO: The scale factor is preliminary! */
|
||||
}
|
||||
|
||||
/* 3D simplex noise */
|
||||
float
|
||||
_noise3 (float x, float y, float z)
|
||||
{
|
||||
/* Simple skewing factors for the 3D case */
|
||||
#define F3 0.333333333f
|
||||
#define G3 0.166666667f
|
||||
|
||||
float n0, n1, n2, n3; /* Noise contributions from the four corners */
|
||||
|
||||
/* Skew the input space to determine which simplex cell we're in */
|
||||
float s = (x+y+z)*F3; /* Very nice and simple skew factor for 3D */
|
||||
float xs = x+s;
|
||||
float ys = y+s;
|
||||
float zs = z+s;
|
||||
int i = FASTFLOOR(xs);
|
||||
int j = FASTFLOOR(ys);
|
||||
int k = FASTFLOOR(zs);
|
||||
|
||||
float t = (float)(i+j+k)*G3;
|
||||
float X0 = i-t; /* Unskew the cell origin back to (x,y,z) space */
|
||||
float Y0 = j-t;
|
||||
float Z0 = k-t;
|
||||
float x0 = x-X0; /* The x,y,z distances from the cell origin */
|
||||
float y0 = y-Y0;
|
||||
float z0 = z-Z0;
|
||||
|
||||
float x1, y1, z1, x2, y2, z2, x3, y3, z3;
|
||||
int ii, jj, kk;
|
||||
float t0, t1, t2, t3;
|
||||
|
||||
/* For the 3D case, the simplex shape is a slightly irregular tetrahedron. */
|
||||
/* Determine which simplex we are in. */
|
||||
int i1, j1, k1; /* Offsets for second corner of simplex in (i,j,k) coords */
|
||||
int i2, j2, k2; /* Offsets for third corner of simplex in (i,j,k) coords */
|
||||
|
||||
/* This code would benefit from a backport from the GLSL version! */
|
||||
if(x0>=y0) {
|
||||
if(y0>=z0)
|
||||
{ i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } /* X Y Z order */
|
||||
else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } /* X Z Y order */
|
||||
else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } /* Z X Y order */
|
||||
}
|
||||
else { /* x0<y0 */
|
||||
if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } /* Z Y X order */
|
||||
else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } /* Y Z X order */
|
||||
else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } /* Y X Z order */
|
||||
}
|
||||
|
||||
/* A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), */
|
||||
/* a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and */
|
||||
/* a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where */
|
||||
/* c = 1/6. */
|
||||
|
||||
x1 = x0 - i1 + G3; /* Offsets for second corner in (x,y,z) coords */
|
||||
y1 = y0 - j1 + G3;
|
||||
z1 = z0 - k1 + G3;
|
||||
x2 = x0 - i2 + 2.0f*G3; /* Offsets for third corner in (x,y,z) coords */
|
||||
y2 = y0 - j2 + 2.0f*G3;
|
||||
z2 = z0 - k2 + 2.0f*G3;
|
||||
x3 = x0 - 1.0f + 3.0f*G3; /* Offsets for last corner in (x,y,z) coords */
|
||||
y3 = y0 - 1.0f + 3.0f*G3;
|
||||
z3 = z0 - 1.0f + 3.0f*G3;
|
||||
|
||||
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
|
||||
ii = i % 256;
|
||||
jj = j % 256;
|
||||
kk = k % 256;
|
||||
|
||||
/* Calculate the contribution from the four corners */
|
||||
t0 = 0.6f - x0*x0 - y0*y0 - z0*z0;
|
||||
if(t0 < 0.0f) n0 = 0.0f;
|
||||
else {
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad3(perm[ii+perm[jj+perm[kk]]], x0, y0, z0);
|
||||
}
|
||||
|
||||
t1 = 0.6f - x1*x1 - y1*y1 - z1*z1;
|
||||
if(t1 < 0.0f) n1 = 0.0f;
|
||||
else {
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * grad3(perm[ii+i1+perm[jj+j1+perm[kk+k1]]], x1, y1, z1);
|
||||
}
|
||||
|
||||
t2 = 0.6f - x2*x2 - y2*y2 - z2*z2;
|
||||
if(t2 < 0.0f) n2 = 0.0f;
|
||||
else {
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * grad3(perm[ii+i2+perm[jj+j2+perm[kk+k2]]], x2, y2, z2);
|
||||
}
|
||||
|
||||
t3 = 0.6f - x3*x3 - y3*y3 - z3*z3;
|
||||
if(t3<0.0f) n3 = 0.0f;
|
||||
else {
|
||||
t3 *= t3;
|
||||
n3 = t3 * t3 * grad3(perm[ii+1+perm[jj+1+perm[kk+1]]], x3, y3, z3);
|
||||
}
|
||||
|
||||
/* Add contributions from each corner to get the final noise value. */
|
||||
/* The result is scaled to stay just inside [-1,1] */
|
||||
return 32.0f * (n0 + n1 + n2 + n3); /* TODO: The scale factor is preliminary! */
|
||||
}
|
||||
|
||||
/* 4D simplex noise */
|
||||
float
|
||||
_noise4 (float x, float y, float z, float w)
|
||||
{
|
||||
/* The skewing and unskewing factors are hairy again for the 4D case */
|
||||
#define F4 0.309016994f /* F4 = (Math.sqrt(5.0)-1.0)/4.0 */
|
||||
#define G4 0.138196601f /* G4 = (5.0-Math.sqrt(5.0))/20.0 */
|
||||
|
||||
float n0, n1, n2, n3, n4; /* Noise contributions from the five corners */
|
||||
|
||||
/* Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in */
|
||||
float s = (x + y + z + w) * F4; /* Factor for 4D skewing */
|
||||
float xs = x + s;
|
||||
float ys = y + s;
|
||||
float zs = z + s;
|
||||
float ws = w + s;
|
||||
int i = FASTFLOOR(xs);
|
||||
int j = FASTFLOOR(ys);
|
||||
int k = FASTFLOOR(zs);
|
||||
int l = FASTFLOOR(ws);
|
||||
|
||||
float t = (i + j + k + l) * G4; /* Factor for 4D unskewing */
|
||||
float X0 = i - t; /* Unskew the cell origin back to (x,y,z,w) space */
|
||||
float Y0 = j - t;
|
||||
float Z0 = k - t;
|
||||
float W0 = l - t;
|
||||
|
||||
float x0 = x - X0; /* The x,y,z,w distances from the cell origin */
|
||||
float y0 = y - Y0;
|
||||
float z0 = z - Z0;
|
||||
float w0 = w - W0;
|
||||
|
||||
/* For the 4D case, the simplex is a 4D shape I won't even try to describe. */
|
||||
/* To find out which of the 24 possible simplices we're in, we need to */
|
||||
/* determine the magnitude ordering of x0, y0, z0 and w0. */
|
||||
/* The method below is a good way of finding the ordering of x,y,z,w and */
|
||||
/* then find the correct traversal order for the simplex we¿re in. */
|
||||
/* First, six pair-wise comparisons are performed between each possible pair */
|
||||
/* of the four coordinates, and the results are used to add up binary bits */
|
||||
/* for an integer index. */
|
||||
int c1 = (x0 > y0) ? 32 : 0;
|
||||
int c2 = (x0 > z0) ? 16 : 0;
|
||||
int c3 = (y0 > z0) ? 8 : 0;
|
||||
int c4 = (x0 > w0) ? 4 : 0;
|
||||
int c5 = (y0 > w0) ? 2 : 0;
|
||||
int c6 = (z0 > w0) ? 1 : 0;
|
||||
int c = c1 + c2 + c3 + c4 + c5 + c6;
|
||||
|
||||
int i1, j1, k1, l1; /* The integer offsets for the second simplex corner */
|
||||
int i2, j2, k2, l2; /* The integer offsets for the third simplex corner */
|
||||
int i3, j3, k3, l3; /* The integer offsets for the fourth simplex corner */
|
||||
|
||||
float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
|
||||
int ii, jj, kk, ll;
|
||||
float t0, t1, t2, t3, t4;
|
||||
|
||||
/* simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. */
|
||||
/* Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w */
|
||||
/* impossible. Only the 24 indices which have non-zero entries make any sense. */
|
||||
/* We use a thresholding to set the coordinates in turn from the largest magnitude. */
|
||||
/* The number 3 in the "simplex" array is at the position of the largest coordinate. */
|
||||
i1 = simplex[c][0]>=3 ? 1 : 0;
|
||||
j1 = simplex[c][1]>=3 ? 1 : 0;
|
||||
k1 = simplex[c][2]>=3 ? 1 : 0;
|
||||
l1 = simplex[c][3]>=3 ? 1 : 0;
|
||||
/* The number 2 in the "simplex" array is at the second largest coordinate. */
|
||||
i2 = simplex[c][0]>=2 ? 1 : 0;
|
||||
j2 = simplex[c][1]>=2 ? 1 : 0;
|
||||
k2 = simplex[c][2]>=2 ? 1 : 0;
|
||||
l2 = simplex[c][3]>=2 ? 1 : 0;
|
||||
/* The number 1 in the "simplex" array is at the second smallest coordinate. */
|
||||
i3 = simplex[c][0]>=1 ? 1 : 0;
|
||||
j3 = simplex[c][1]>=1 ? 1 : 0;
|
||||
k3 = simplex[c][2]>=1 ? 1 : 0;
|
||||
l3 = simplex[c][3]>=1 ? 1 : 0;
|
||||
/* The fifth corner has all coordinate offsets = 1, so no need to look that up. */
|
||||
|
||||
x1 = x0 - i1 + G4; /* Offsets for second corner in (x,y,z,w) coords */
|
||||
y1 = y0 - j1 + G4;
|
||||
z1 = z0 - k1 + G4;
|
||||
w1 = w0 - l1 + G4;
|
||||
x2 = x0 - i2 + 2.0f*G4; /* Offsets for third corner in (x,y,z,w) coords */
|
||||
y2 = y0 - j2 + 2.0f*G4;
|
||||
z2 = z0 - k2 + 2.0f*G4;
|
||||
w2 = w0 - l2 + 2.0f*G4;
|
||||
x3 = x0 - i3 + 3.0f*G4; /* Offsets for fourth corner in (x,y,z,w) coords */
|
||||
y3 = y0 - j3 + 3.0f*G4;
|
||||
z3 = z0 - k3 + 3.0f*G4;
|
||||
w3 = w0 - l3 + 3.0f*G4;
|
||||
x4 = x0 - 1.0f + 4.0f*G4; /* Offsets for last corner in (x,y,z,w) coords */
|
||||
y4 = y0 - 1.0f + 4.0f*G4;
|
||||
z4 = z0 - 1.0f + 4.0f*G4;
|
||||
w4 = w0 - 1.0f + 4.0f*G4;
|
||||
|
||||
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
|
||||
ii = i % 256;
|
||||
jj = j % 256;
|
||||
kk = k % 256;
|
||||
ll = l % 256;
|
||||
|
||||
/* Calculate the contribution from the five corners */
|
||||
t0 = 0.6f - x0*x0 - y0*y0 - z0*z0 - w0*w0;
|
||||
if(t0 < 0.0f) n0 = 0.0f;
|
||||
else {
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad4(perm[ii+perm[jj+perm[kk+perm[ll]]]], x0, y0, z0, w0);
|
||||
}
|
||||
|
||||
t1 = 0.6f - x1*x1 - y1*y1 - z1*z1 - w1*w1;
|
||||
if(t1 < 0.0f) n1 = 0.0f;
|
||||
else {
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * grad4(perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]], x1, y1, z1, w1);
|
||||
}
|
||||
|
||||
t2 = 0.6f - x2*x2 - y2*y2 - z2*z2 - w2*w2;
|
||||
if(t2 < 0.0f) n2 = 0.0f;
|
||||
else {
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * grad4(perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]], x2, y2, z2, w2);
|
||||
}
|
||||
|
||||
t3 = 0.6f - x3*x3 - y3*y3 - z3*z3 - w3*w3;
|
||||
if(t3 < 0.0f) n3 = 0.0f;
|
||||
else {
|
||||
t3 *= t3;
|
||||
n3 = t3 * t3 * grad4(perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]], x3, y3, z3, w3);
|
||||
}
|
||||
|
||||
t4 = 0.6f - x4*x4 - y4*y4 - z4*z4 - w4*w4;
|
||||
if(t4 < 0.0f) n4 = 0.0f;
|
||||
else {
|
||||
t4 *= t4;
|
||||
n4 = t4 * t4 * grad4(perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]], x4, y4, z4, w4);
|
||||
}
|
||||
|
||||
/* Sum up and scale the result to cover the range [-1,1] */
|
||||
return 27.0f * (n0 + n1 + n2 + n3 + n4); /* TODO: The scale factor is preliminary! */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,5 @@
|
|||
void _noise_init_perm(unsigned long seed);
|
||||
float _noise1 (float x);
|
||||
float _noise2 (float x, float y);
|
||||
float _noise3 (float x, float y, float z);
|
||||
float _noise4 (float x, float y, float z, float w);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,12 +23,6 @@ int2bin(uint32_t i, size_t len=4)
|
|||
return str;
|
||||
}
|
||||
|
||||
static const char*
|
||||
float2bin(float f)
|
||||
{
|
||||
return int2bin(*reinterpret_cast<uint32_t*>(&f));
|
||||
}
|
||||
|
||||
static void
|
||||
panel_post_render(struct tms_wdg *w, struct tms_surface *s)
|
||||
{
|
||||
|
|
|
|||
114
src/src/rand.c
114
src/src/rand.c
|
|
@ -20,7 +20,7 @@ void init_genrand(unsigned long s)
|
|||
int j;
|
||||
state[0]= s & 0xffffffffUL;
|
||||
for (j=1; j<N; j++) {
|
||||
state[j] = (1812433253UL * (state[j-1] ^ (state[j-1] >> 30)) + j);
|
||||
state[j] = (1812433253UL * (state[j-1] ^ (state[j-1] >> 30)) + j);
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
/* In the previous versions, MSBs of the seed affect */
|
||||
/* only MSBs of the array state[]. */
|
||||
|
|
@ -30,36 +30,6 @@ void init_genrand(unsigned long s)
|
|||
left = 1; initf = 1;
|
||||
}
|
||||
|
||||
/* initialize by an array with array-length */
|
||||
/* init_key is the array for initializing keys */
|
||||
/* key_length is its length */
|
||||
/* slight change for C++, 2004/2/26 */
|
||||
void init_by_array(unsigned long init_key[], int key_length)
|
||||
{
|
||||
int i, j, k;
|
||||
init_genrand(19650218UL);
|
||||
i=1; j=0;
|
||||
k = (N>key_length ? N : key_length);
|
||||
for (; k; k--) {
|
||||
state[i] = (state[i] ^ ((state[i-1] ^ (state[i-1] >> 30)) * 1664525UL))
|
||||
+ init_key[j] + j; /* non linear */
|
||||
state[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
||||
i++; j++;
|
||||
if (i>=N) { state[0] = state[N-1]; i=1; }
|
||||
if (j>=key_length) j=0;
|
||||
}
|
||||
for (k=N-1; k; k--) {
|
||||
state[i] = (state[i] ^ ((state[i-1] ^ (state[i-1] >> 30)) * 1566083941UL))
|
||||
- i; /* non linear */
|
||||
state[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
||||
i++;
|
||||
if (i>=N) { state[0] = state[N-1]; i=1; }
|
||||
}
|
||||
|
||||
state[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
|
||||
left = 1; initf = 1;
|
||||
}
|
||||
|
||||
static void next_state(void)
|
||||
{
|
||||
unsigned long *p=state;
|
||||
|
|
@ -72,10 +42,10 @@ static void next_state(void)
|
|||
left = N;
|
||||
next = state;
|
||||
|
||||
for (j=N-M+1; --j; p++)
|
||||
for (j=N-M+1; --j; p++)
|
||||
*p = p[M] ^ TWIST(p[0], p[1]);
|
||||
|
||||
for (j=M; --j; p++)
|
||||
for (j=M; --j; p++)
|
||||
*p = p[M-N] ^ TWIST(p[0], p[1]);
|
||||
|
||||
*p = p[M-N] ^ TWIST(p[0], state[0]);
|
||||
|
|
@ -97,81 +67,3 @@ unsigned long genrand_int32(void)
|
|||
|
||||
return y;
|
||||
}
|
||||
|
||||
/* generates a random number on [0,0x7fffffff]-interval */
|
||||
long genrand_int31(void)
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if (--left == 0) next_state();
|
||||
y = *next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return (long)(y>>1);
|
||||
}
|
||||
|
||||
/* generates a random number on [0,1]-real-interval */
|
||||
double genrand_real1(void)
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if (--left == 0) next_state();
|
||||
y = *next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return (double)y * (1.0/4294967295.0);
|
||||
/* divided by 2^32-1 */
|
||||
}
|
||||
|
||||
/* generates a random number on [0,1)-real-interval */
|
||||
double genrand_real2(void)
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if (--left == 0) next_state();
|
||||
y = *next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return (double)y * (1.0/4294967296.0);
|
||||
/* divided by 2^32 */
|
||||
}
|
||||
|
||||
/* generates a random number on (0,1)-real-interval */
|
||||
double genrand_real3(void)
|
||||
{
|
||||
unsigned long y;
|
||||
|
||||
if (--left == 0) next_state();
|
||||
y = *next++;
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return ((double)y + 0.5) * (1.0/4294967296.0);
|
||||
/* divided by 2^32 */
|
||||
}
|
||||
|
||||
/* generates a random number on [0,1) with 53-bit resolution*/
|
||||
double genrand_res53(void)
|
||||
{
|
||||
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
|
||||
return(a*67108864.0+b)*(1.0/9007199254740992.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,27 +36,6 @@ static void png_write_SDL(png_structp png_ptr, png_bytep data, png_size_t length
|
|||
SDL_RWwrite(rw, data, sizeof(png_byte), length);
|
||||
}
|
||||
|
||||
SDL_Surface *SDL_PNGFormatAlpha(SDL_Surface *src)
|
||||
{
|
||||
SDL_Surface *surf;
|
||||
SDL_Rect rect = { 0 };
|
||||
|
||||
/* NO-OP for images < 32bpp and 32bpp images that already have Alpha channel */
|
||||
if (src->format->BitsPerPixel <= 24 || src->format->Amask) {
|
||||
src->refcount++;
|
||||
return src;
|
||||
}
|
||||
|
||||
/* Convert 32bpp alpha-less image to 24bpp alpha-less image */
|
||||
rect.w = src->w;
|
||||
rect.h = src->h;
|
||||
surf = SDL_CreateRGBSurface(src->flags, src->w, src->h, 24,
|
||||
src->format->Rmask, src->format->Gmask, src->format->Bmask, 0);
|
||||
SDL_LowerBlit(src, &rect, surf, &rect);
|
||||
|
||||
return surf;
|
||||
}
|
||||
|
||||
int SDL_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
|
||||
{
|
||||
png_structp png_ptr;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
|
||||
/*
|
||||
* Save an SDL_Surface as a PNG file, using writable RWops.
|
||||
*
|
||||
*
|
||||
* surface - the SDL_Surface structure containing the image to be saved
|
||||
* dst - a data stream to save to
|
||||
* freedst - non-zero to close the stream after being written
|
||||
|
|
@ -32,11 +32,6 @@ extern "C" {
|
|||
*/
|
||||
extern int SDL_SavePNG_RW(SDL_Surface *surface, SDL_RWops *rw, int freedst);
|
||||
|
||||
/*
|
||||
* Return new SDL_Surface with a format suitable for PNG output.
|
||||
*/
|
||||
extern SDL_Surface *SDL_PNGFormatAlpha(SDL_Surface *src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ bool operator <(const terrain_coord& lhs, const terrain_coord &rhs)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Terrain generation overview
|
||||
*
|
||||
* Phase 1:
|
||||
|
|
@ -29,7 +29,7 @@ bool operator <(const terrain_coord& lhs, const terrain_coord &rhs)
|
|||
*
|
||||
* Phase 2:
|
||||
* set material based on height
|
||||
*
|
||||
*
|
||||
* Phase 3:
|
||||
* Dig out caves
|
||||
*
|
||||
|
|
@ -226,7 +226,7 @@ terrain_transaction::apply()
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 3 = very stony
|
||||
* 0 = very grassy
|
||||
**/
|
||||
|
|
@ -272,7 +272,7 @@ double cave(double x, double y, double depth)
|
|||
|
||||
for (int n=0; n<3; n++) {
|
||||
float freq = powf(2, n);
|
||||
float amp = powf(.7f, n);
|
||||
float amp = powf(.7f, n);
|
||||
float nn = powf(n, 2);
|
||||
double v[2] = {x*.035*freq, y*.035*freq};
|
||||
r += _noise2(v[0], v[1])*amp;
|
||||
|
|
@ -295,12 +295,12 @@ double cave(double x, double y, double depth)
|
|||
|
||||
unsigned flp2(unsigned x)
|
||||
{
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >>16);
|
||||
return x - (x >> 1);
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >>16);
|
||||
return x - (x >> 1);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -363,7 +363,7 @@ level_chunk::generate(chunk_window *win, int up_to_phase/*=5*/)
|
|||
#ifdef DEBUG_SPECIFIC_CHUNK
|
||||
if (up_to_phase > this->generate_phase && this->pos_x == DEBUG_CHUNK_X && this->pos_y == DEBUG_CHUNK_Y) {
|
||||
tms_trace();
|
||||
tms_debugf("(chunk %d,%d) generate phase %d->%d %p", DEBUG_CHUNK_X, DEBUG_CHUNK_Y,
|
||||
tms_debugf("(chunk %d,%d) generate phase %d->%d %p", DEBUG_CHUNK_X, DEBUG_CHUNK_Y,
|
||||
this->generate_phase, up_to_phase, this);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -461,7 +461,7 @@ level_chunk::make_smooth(chunk_window *win)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Phase 1: base outline of the terrain, heights
|
||||
**/
|
||||
void
|
||||
|
|
@ -488,7 +488,7 @@ level_chunk::generate_phase1(chunk_window *win)
|
|||
if (z == 0 && y == 0) {
|
||||
h[x] = t_height(((double)x)*.5+(double)this->pos_x*8.);
|
||||
}
|
||||
|
||||
|
||||
/* setup roughness */
|
||||
if (z == 0) {
|
||||
rough[y][x] = roughness(wx, wy);
|
||||
|
|
@ -502,8 +502,6 @@ level_chunk::generate_phase1(chunk_window *win)
|
|||
|
||||
double depth = wy - height + z*.5;
|
||||
|
||||
//depth *= 1.f-fabsf(z*.85* _noise1(23.33+wx*.1435));
|
||||
//depth += z*.5* _noise3(wx*.2, wy*.2, z*.1)*.35;
|
||||
if (z > 0) {
|
||||
depth += z*.5* _noise1(wx*.2)*1.25;
|
||||
}
|
||||
|
|
@ -521,7 +519,7 @@ level_chunk::generate_phase1(chunk_window *win)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Phase 2: set materials
|
||||
**/
|
||||
void
|
||||
|
|
@ -639,7 +637,7 @@ level_chunk::find_ground(terrain_coord *in, int layer, terrain_coord *out, float
|
|||
void
|
||||
level_chunk::generate_vegetation(float *heights)
|
||||
{
|
||||
float last_noise;
|
||||
float last_noise;
|
||||
for (int x=0; x<16; x+=2) {
|
||||
double wx = (x*.5 + this->pos_x*8.);
|
||||
double wy = heights[x];
|
||||
|
|
@ -732,7 +730,7 @@ level_chunk::generate_vegetation(float *heights)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Phase 3: caves and merging into bigger pixels
|
||||
*
|
||||
* Occupy gentypes
|
||||
|
|
@ -749,7 +747,7 @@ level_chunk::generate_phase3(chunk_window *win)
|
|||
gentype::generate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Phase 4: Apply any gentypes allocated in this chunk
|
||||
**/
|
||||
void
|
||||
|
|
@ -759,7 +757,7 @@ level_chunk::generate_phase4(chunk_window *win)
|
|||
this->generate_phase = 4;
|
||||
}
|
||||
|
||||
/* before we can generate phase 4, we must make sure that a certain amount of
|
||||
/* before we can generate phase 4, we must make sure that a certain amount of
|
||||
* chunks nearby is generated to phase 3, incase they have gentypes of higher priority */
|
||||
for (int y=GENTYPE_MAX_REACH_Y; y>=-GENTYPE_MAX_REACH_Y; y--) {
|
||||
for (int x=-GENTYPE_MAX_REACH_X; x<=GENTYPE_MAX_REACH_X; x++) {
|
||||
|
|
@ -780,7 +778,7 @@ level_chunk::generate_phase4(chunk_window *win)
|
|||
this->apply_gentypes(0);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Phase 5: Apply gentypes that modify other gentypes (minerals etc)
|
||||
**/
|
||||
void
|
||||
|
|
@ -805,7 +803,7 @@ level_chunk::generate_phase5(chunk_window *win)
|
|||
void
|
||||
level_chunk::apply_gentypes(int sorting)
|
||||
{
|
||||
/* TODO: to handle delete of gentypes, we first must make sure that
|
||||
/* TODO: to handle delete of gentypes, we first must make sure that
|
||||
* all relevant chunks are done generating, we can use reference counting in the
|
||||
* gentypes, and when a chunk generates it decrements the gentypes reference count,
|
||||
* and deletes the gentype when the reference count is 0 */
|
||||
|
|
@ -919,7 +917,7 @@ level_chunk::merge(int _x, int _y, int _z, int _w, int _h, int _d)
|
|||
desc.size = size;
|
||||
desc.pos = (y << 4) | (x & 15);
|
||||
desc.material = chunk_mat_to_tpixel_mat(px);
|
||||
desc.r =
|
||||
desc.r =
|
||||
(((x + this->pos_x*16) ^ 0xfa367aef)
|
||||
* (((y + this->pos_y*16)) ^ 0x73f976ab))
|
||||
& 0xff;
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ LOCAL_SRC_FILES += \
|
|||
$(wildcard $(LOCAL_PATH)/tms/util/*.c) )\
|
||||
tms/backends/android/main.c \
|
||||
tms/bindings/cpp/cpp.cc\
|
||||
tms/modules/3ds/3ds.c
|
||||
tms/modules/3ds.c
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "screen.h"
|
||||
#include "event.h"
|
||||
#include "tms.h"
|
||||
#include "tms/util/list.h"
|
||||
#include "tms/util/util.h"
|
||||
|
||||
#define MAX_EVENTS 1024
|
||||
|
|
@ -138,7 +137,7 @@ tms_event_process_all(struct tms_screen *s)
|
|||
{
|
||||
if (s->spec->input) {
|
||||
for (int x=0; x<num_events; x++) {
|
||||
if (tms_screen_handle_input(s, &events[x], 0) == T_CONT)
|
||||
if (tms_screen_handle_input(s, &events[x], 0) == T_CONT)
|
||||
s->spec->input(s, &events[x], 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ static const int (*sort_fns[])(void*, void*) = {
|
|||
|
||||
/* 1 or 0 depending on whether the sorting
|
||||
* type of the given index sorts depending on true/false.
|
||||
* For example, a texture is not a boolean sort, but
|
||||
* For example, a texture is not a boolean sort, but
|
||||
* blending on/off. */
|
||||
static const int sort_boolean[] = {
|
||||
0,
|
||||
|
|
@ -284,7 +284,7 @@ render_entities(struct tms_rstate *state,
|
|||
if (count) glDrawElements(
|
||||
m->primitive_type,
|
||||
count,
|
||||
(m->i32?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT),
|
||||
(m->i32?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT),
|
||||
(char*)(start * (m->i32?sizeof(int):sizeof(short)))
|
||||
);
|
||||
} else {
|
||||
|
|
@ -315,7 +315,7 @@ void branch_remove_branch(struct _branch *b, struct _branch *c)
|
|||
free(c->nodes.as_branch);
|
||||
free(c);
|
||||
|
||||
if (b->num_nodes == 0)
|
||||
if (b->num_nodes == 0)
|
||||
if (b->parent) branch_remove_branch(b->parent, b);
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ render_branch(struct tms_rstate *s,
|
|||
int depth)
|
||||
{
|
||||
if (depth > 0) {
|
||||
if (*sort_v == TMS_SORT_PRIO && s->graph->sort_reverse_prio) {
|
||||
if (*sort_v == TMS_SORT_PRIO && s->graph->sort_reverse_prio) {
|
||||
for (int x=b->num_nodes-1; x>=0; x--) {
|
||||
if ((s->sort_fns[*sort_v])(s, b->nodes.as_branch[x].val) == T_OK) {
|
||||
render_branch(s, b->nodes.as_branch[x].next, sort_v+1, depth-1);
|
||||
|
|
@ -460,7 +460,7 @@ dump_branch(struct tms_scene_branch *b, int *sorting, int depth, int maxdepth)
|
|||
for (int x=0; x<b->num_nodes; x++) {
|
||||
switch (*sorting) {
|
||||
case TMS_SORT_SHADER: tms_infof("%ssort shader: %s", indent, ((struct tms_shader*)b->nodes.as_branch[x].value)->name?:"null"); break;
|
||||
|
||||
|
||||
case TMS_SORT_TEXTURE0:
|
||||
case TMS_SORT_TEXTURE1:
|
||||
case TMS_SORT_TEXTURE2:
|
||||
|
|
@ -490,7 +490,7 @@ tms_scene_dump_tree(struct tms_scene *s)
|
|||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* @relates tms_graph
|
||||
**/
|
||||
int
|
||||
|
|
@ -653,7 +653,7 @@ bind_mesh(struct tms_rstate *state,
|
|||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->vbo);
|
||||
|
||||
tms_assertf(glIsBuffer(m->vbo), "is not buffer");
|
||||
} else
|
||||
} else
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
return T_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,59 +49,6 @@ tms_model_upload(struct tms_model *m)
|
|||
tms_gbuffer_upload(m->indices);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
void
|
||||
tms_model_plc_translate(struct tms_model *m,
|
||||
struct tms_mesh *mesh,
|
||||
float dx, float dy,float dz, struct tms_mesh *ret,
|
||||
size_t *v_offs, size_t *i_offs
|
||||
)
|
||||
{
|
||||
//struct tms_mesh *ret = tms_model_create_mesh(m);
|
||||
|
||||
size_t vsz, osz;
|
||||
//vsz = m->vertices->size;
|
||||
//osz = m->indices->size;
|
||||
vsz = *v_offs;
|
||||
osz = *i_offs;
|
||||
|
||||
uint16_t base = vsz/sizeof(struct vertex);
|
||||
uint16_t last_base = mesh->v_start / sizeof(struct vertex);
|
||||
|
||||
tms_infof("base %d, last base %d", base, last_base);
|
||||
|
||||
//tms_gbuffer_realloc(m->indices, m->indices->size + mesh->i_count*sizeof(uint16_t));
|
||||
//tms_gbuffer_realloc(m->vertices, m->vertices->size + mesh->v_count*sizeof(struct vertex));
|
||||
//
|
||||
(*v_offs) += mesh->v_count*sizeof(struct vertex);
|
||||
(*i_offs) += mesh->i_count*sizeof(uint16_t);
|
||||
|
||||
struct vertex *v = m->vertices->buf+mesh->v_start;
|
||||
uint16_t *i = m->indices->buf+mesh->i_start*sizeof(uint16_t);
|
||||
|
||||
struct vertex *nv = m->vertices->buf+vsz;
|
||||
uint16_t *ni = m->indices->buf+osz;
|
||||
|
||||
for (int x=0; x<mesh->i_count; x++)
|
||||
ni[x] = (i[x] - last_base) + base;
|
||||
|
||||
for (int x=0; x<mesh->v_count; x++) {
|
||||
nv[x] = v[x];
|
||||
nv[x].pos.x += dx;
|
||||
nv[x].pos.y += dy;
|
||||
nv[x].pos.z += dz;
|
||||
}
|
||||
|
||||
ret->owner = m;
|
||||
ret->v_start = vsz;
|
||||
ret->v_count = mesh->v_count;
|
||||
|
||||
ret->i_start = osz / 2;
|
||||
ret->i_count = mesh->i_count;
|
||||
|
||||
//return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct tms_mesh*
|
||||
tms_model_shift_mesh_uv(struct tms_model *m,
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ tms_texture_render(struct tms_texture *t)
|
|||
tms_fb_render(&fb, _tms_fb_copy_program);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Allocate a local buffer for this texture.
|
||||
* This function will return a pointer to a buffer that you can read and write to.
|
||||
* The buffer will be managed by the texture and should never be manually freed by
|
||||
|
|
@ -107,7 +107,7 @@ unsigned char *tms_texture_alloc_buffer(struct tms_texture *tex, int width,
|
|||
return tex->data;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* @relates tms_texture
|
||||
**/
|
||||
|
|
@ -116,7 +116,7 @@ unsigned char* tms_texture_get_buffer(struct tms_texture *tex)
|
|||
return tex->data;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clear this textures buffer to the given clear_value. `clear_value` will be
|
||||
* copied into each colo component of the texture.
|
||||
*
|
||||
|
|
@ -166,24 +166,24 @@ int
|
|||
tms_texture_load_pvrtc_4bpp(struct tms_texture *tex, const char *filename)
|
||||
{
|
||||
SDL_RWops *rw = SDL_RWFromFile(filename, "rb");
|
||||
|
||||
|
||||
tms_infof("Load PVRTC 4BPP: %s", filename);
|
||||
|
||||
|
||||
if (rw) {
|
||||
long size;
|
||||
SDL_RWseek(rw, 0, SEEK_END);
|
||||
size = SDL_RWtell(rw);
|
||||
SDL_RWseek(rw, 0, SEEK_SET);
|
||||
|
||||
|
||||
/* XXX free previous? */
|
||||
if (size > 4*1024*1024 || size < sizeof(struct etc1_header) + 20)
|
||||
tms_fatalf("invalid file size");
|
||||
|
||||
|
||||
struct pvrtc_header header;
|
||||
SDL_RWread(rw, &header, sizeof(struct pvrtc_header), 1);
|
||||
tex->data = malloc(size - sizeof(struct pvrtc_header));
|
||||
SDL_RWread(rw, tex->data, 1, size-sizeof(struct pvrtc_header));
|
||||
|
||||
|
||||
//tex->width = ntohs(header.width);
|
||||
//tex->height = ntohs(header.height);
|
||||
tex->width = header.width;
|
||||
|
|
@ -193,20 +193,20 @@ tms_texture_load_pvrtc_4bpp(struct tms_texture *tex, const char *filename)
|
|||
tex->gamma_correction = 0;
|
||||
tex->format = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG_OES;
|
||||
tex->buf_size = size-sizeof(struct pvrtc_header);
|
||||
|
||||
|
||||
if (tex->width <= 0 || tex->height <= 0)
|
||||
tms_fatalf("invalid pvrtc texture dimensions");
|
||||
|
||||
|
||||
SDL_RWclose(rw);
|
||||
|
||||
|
||||
return T_OK;
|
||||
} else
|
||||
tms_errorf("Unable to open texture: '%s'", SDL_GetError());
|
||||
|
||||
|
||||
return T_COULD_NOT_OPEN;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Load a compressed image
|
||||
**/
|
||||
int
|
||||
|
|
@ -252,7 +252,7 @@ tms_texture_load_etc1(struct tms_texture *tex,
|
|||
return T_COULD_NOT_OPEN;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Read texture from the given file.
|
||||
* @relates tms_texture
|
||||
**/
|
||||
|
|
@ -264,35 +264,6 @@ tms_texture_load(struct tms_texture *tex, const char *filename)
|
|||
if (ext != 1) {
|
||||
int status;
|
||||
|
||||
/*
|
||||
int (*loader)(struct tms_texture *, FILE *)
|
||||
= thash_get(tms.image_loaders, ext, strlen(ext));
|
||||
|
||||
if (!loader) {
|
||||
tms_errorf("unsupported image format: %s", ext);
|
||||
return T_UNSUPPORTED_FILE_FORMAT;
|
||||
}
|
||||
|
||||
FILE *f = fopen(filename, "rb");
|
||||
|
||||
if (!f) {
|
||||
tms_errorf("could not open file: %s", filename);
|
||||
return T_COULD_NOT_OPEN;
|
||||
}
|
||||
|
||||
if ((status = loader(tex, f)) == T_OK) {
|
||||
tex->is_buffered = 1;
|
||||
tex->filename = strdup(filename);
|
||||
tex->gamma_corrected = 0;
|
||||
|
||||
tms_debugf("loaded texture: %s (%s, %dx%d)", filename, ext, tex->width, tex->height);
|
||||
} else
|
||||
tms_fatalf("could not load file: %s", filename);
|
||||
|
||||
fclose(f);
|
||||
*/
|
||||
|
||||
|
||||
SDL_RWops *rw = SDL_RWFromFile(filename,"rb");
|
||||
|
||||
if (!rw) {
|
||||
|
|
@ -324,7 +295,7 @@ tms_texture_load(struct tms_texture *tex, const char *filename)
|
|||
for (int y=0; y<s->h; y++) {
|
||||
for (int x=0; x<s->w*tex->num_channels; x++) {
|
||||
int o = y*s->pitch;
|
||||
((unsigned char*)tex->data)[(s->h-y-1)*s->w*tex->num_channels+x] =
|
||||
((unsigned char*)tex->data)[(s->h-y-1)*s->w*tex->num_channels+x] =
|
||||
((unsigned char*)s->pixels)[o+x];
|
||||
}
|
||||
}
|
||||
|
|
@ -338,7 +309,7 @@ tms_texture_load(struct tms_texture *tex, const char *filename)
|
|||
return T_UNSUPPORTED_FILE_FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Load a texture from a memory buffer.
|
||||
* This will allocate a new buffer and copy the input buffer to it.
|
||||
* Expects one byte per pixel color channel. If `alpha_channel` is
|
||||
|
|
@ -372,8 +343,8 @@ tms_texture_load_mem(struct tms_texture *tex, const char *buf,
|
|||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a texture from a memory buffer
|
||||
/**
|
||||
* Loads a texture from a memory buffer
|
||||
* @relates tms_texture
|
||||
**/
|
||||
int
|
||||
|
|
@ -412,7 +383,7 @@ tms_texture_load_mem2(struct tms_texture *tex, const char *buf, size_t size, int
|
|||
for (int y=0; y<s->h; y++) {
|
||||
for (int x=0; x<s->w*tex->num_channels; x++) {
|
||||
int o = y*s->pitch;
|
||||
((unsigned char*)tex->data)[(s->h-y-1)*s->w*tex->num_channels+x] =
|
||||
((unsigned char*)tex->data)[(s->h-y-1)*s->w*tex->num_channels+x] =
|
||||
((unsigned char*)s->pixels)[o+x];
|
||||
}
|
||||
}
|
||||
|
|
@ -532,7 +503,7 @@ tms_texture_add_alpha(struct tms_texture *tex, float a)
|
|||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Upload the texture to the GPU.
|
||||
*
|
||||
* @relates tms_texture
|
||||
|
|
@ -670,7 +641,7 @@ tms_texture_upload(struct tms_texture *tex)
|
|||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the texture filtering
|
||||
*
|
||||
* @relates tms_texture
|
||||
|
|
@ -703,7 +674,7 @@ tms_texture_set_filtering(struct tms_texture *tex, int filter)
|
|||
tex->filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @relates tms_texture
|
||||
**/
|
||||
int
|
||||
|
|
@ -718,8 +689,8 @@ tms_texture_download(struct tms_texture *tex)
|
|||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the texture to the currently active opengl
|
||||
/**
|
||||
* Bind the texture to the currently active opengl
|
||||
* texture unit.
|
||||
* Use glActiveTexture() to choose texture unit.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ struct tms_singleton _tms = {
|
|||
int
|
||||
tms_init(void)
|
||||
{
|
||||
tms.image_loaders = thash_create_string_table(8);
|
||||
tms.model_loaders = thash_create_string_table(8);
|
||||
tms.framebuffer = 0;
|
||||
tms.is_paused = 0;
|
||||
|
|
@ -64,18 +63,6 @@ tms_init(void)
|
|||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an image filetype loader
|
||||
* @relates tms
|
||||
**/
|
||||
int
|
||||
tms_register_image_loader(int (*load_fn)(struct tms_texture *, FILE *), const char *ext)
|
||||
{
|
||||
thash_add(tms.image_loaders, ext, strlen(ext), load_fn);
|
||||
tms_debugf("registered image loader (%p) for \"%s\"", load_fn, ext);
|
||||
return T_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a 3D model filetype loader
|
||||
* @relates tms
|
||||
|
|
|
|||
|
|
@ -100,7 +100,6 @@ extern struct tms_singleton {
|
|||
int state; /**< current state, see TMS_STATE */
|
||||
char *gl_extensions;
|
||||
|
||||
struct thash *image_loaders;
|
||||
struct thash *model_loaders;
|
||||
|
||||
double gamma;
|
||||
|
|
@ -127,7 +126,6 @@ int tms_begin_frame(void);
|
|||
int tms_end_frame(void);
|
||||
int tms_begin_transition(struct tms_transition *trans, struct tms_screen *next);
|
||||
|
||||
int tms_register_image_loader(int (*load_fn)(struct tms_texture *, FILE *), const char *ext);
|
||||
int tms_register_model_loader(struct tms_mesh * (*load_fn)(struct tms_model *, SDL_RWops *, int *), const char *ext);
|
||||
|
||||
TMS_STATIC_INLINE void tms_convert_to_portrait(int *x, int *y)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include "intersect.h"
|
||||
#include <tms/backend/print.h>
|
||||
|
||||
/**
|
||||
/**
|
||||
* Compare the point and the line in a sense similar to strcmp(),
|
||||
* the function will return < 0 if the point is "below" the line,
|
||||
* 0 if the point is on the line, and > 0 if the point is above the
|
||||
|
|
@ -18,7 +18,7 @@ tintersect_point_line_cmp(tvec2 *l1, tvec2 *l2, tvec2 *p)
|
|||
return (l2->x - l1->x) * (p->y - l1->y) - (l2->y - l1->y) * (p->x - l1->x);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Intersect two infinite lines
|
||||
*
|
||||
* @relates tintersect
|
||||
|
|
@ -46,22 +46,22 @@ tintersect_segments(tvec2 a1, tvec2 a2, tvec2 b1, tvec2 b2, tvec2 *point)
|
|||
float d = (b2.y-b1.y)*(a2.x-a1.x) - (b2.x-b1.x)*(a2.y-a1.y);
|
||||
if (d == 0.f)
|
||||
return 0;
|
||||
|
||||
|
||||
float a = ((b2.x-b1.x)*(a1.y-b1.y) - (b2.y-b1.y)*(a1.x-b1.x)) / d;
|
||||
float b = ((a2.x-a1.x)*(a1.y-b1.y) - (a2.y-a1.y)*(a1.x-b1.x)) / d;
|
||||
|
||||
|
||||
if (a < 0.f || a > 1.f)
|
||||
return 0;
|
||||
if (b < 0.f || b > 1.f)
|
||||
return 0;
|
||||
|
||||
|
||||
point->x = a1.x + (a2.x-a1.x)*a;
|
||||
point->y = a1.y + (a2.y-a1.y)*a;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Intersect a ray with a plane.
|
||||
*
|
||||
* @relates tintersect
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <tms/math/vector.h>
|
||||
#include <tms/util/util.h>
|
||||
|
||||
/**
|
||||
/**
|
||||
* Misc intersection functions.
|
||||
* The struct tintersect does not exist, all intersection functions take various arguments.
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
#include "lorenz.h"
|
||||
|
||||
#define SIGMA 10.0f
|
||||
#define RAYLEIGH 28.f
|
||||
#define PRANDTL 8.f/3.f
|
||||
|
||||
void
|
||||
tmath_deriv_lorenz(float time, float *in, float *out)
|
||||
{
|
||||
out[0] = -SIGMA * in[0] + SIGMA*in[1];
|
||||
out[1] = -in[0] * in[2] + RAYLEIGH*in[0]-in[1];
|
||||
out[2] = in[0]*in[1] - PRANDTL*in[2];
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef _TMATH_LORENZ__H_
|
||||
#define _TMATH_LORENZ__H_
|
||||
|
||||
void tmath_deriv_lorenz(float time, float *in, float *out);
|
||||
|
||||
#endif
|
||||
|
|
@ -48,41 +48,41 @@ void tmath_sincos( float x, float *r0, float *r1)
|
|||
float f;
|
||||
int i;
|
||||
} ax, bx;
|
||||
|
||||
|
||||
float y;
|
||||
float a, b, c, d, xx, yy;
|
||||
int m, n, o, p;
|
||||
|
||||
|
||||
y = x + __sincosf_rng[1];
|
||||
ax.f = fabsf(x);
|
||||
bx.f = fabsf(y);
|
||||
|
||||
|
||||
//Range Reduction:
|
||||
m = (int) (ax.f * __sincosf_rng[0]);
|
||||
o = (int) (bx.f * __sincosf_rng[0]);
|
||||
m = (int) (ax.f * __sincosf_rng[0]);
|
||||
o = (int) (bx.f * __sincosf_rng[0]);
|
||||
ax.f = ax.f - (((float)m) * __sincosf_rng[1]);
|
||||
bx.f = bx.f - (((float)o) * __sincosf_rng[1]);
|
||||
|
||||
|
||||
//Test Quadrant
|
||||
n = m & 1;
|
||||
p = o & 1;
|
||||
ax.f = ax.f - n * __sincosf_rng[1];
|
||||
bx.f = bx.f - p * __sincosf_rng[1];
|
||||
ax.f = ax.f - n * __sincosf_rng[1];
|
||||
bx.f = bx.f - p * __sincosf_rng[1];
|
||||
m = m >> 1;
|
||||
o = o >> 1;
|
||||
n = n ^ m;
|
||||
p = p ^ o;
|
||||
m = (x < 0.0);
|
||||
o = (y < 0.0);
|
||||
n = n ^ m;
|
||||
p = p ^ o;
|
||||
n = n ^ m;
|
||||
p = p ^ o;
|
||||
n = n << 31;
|
||||
p = p << 31;
|
||||
ax.i = ax.i ^ n;
|
||||
bx.i = bx.i ^ p;
|
||||
ax.i = ax.i ^ n;
|
||||
bx.i = bx.i ^ p;
|
||||
|
||||
//Taylor Polynomial
|
||||
xx = ax.f * ax.f;
|
||||
xx = ax.f * ax.f;
|
||||
yy = bx.f * bx.f;
|
||||
*r0 = __sincosf_lut[0];
|
||||
*r1 = __sincosf_lut[1];
|
||||
|
|
@ -115,28 +115,28 @@ float tmath_sin(float x)
|
|||
float f;
|
||||
int i;
|
||||
} ax;
|
||||
|
||||
|
||||
float r, a, b, xx;
|
||||
int m, n;
|
||||
|
||||
|
||||
ax.f = fabsf(x);
|
||||
|
||||
//Range Reduction:
|
||||
m = (int) (ax.f * __sinf_rng[0]);
|
||||
m = (int) (ax.f * __sinf_rng[0]);
|
||||
ax.f = ax.f - (((float)m) * __sinf_rng[1]);
|
||||
|
||||
//Test Quadrant
|
||||
n = m & 1;
|
||||
ax.f = ax.f - n * __sinf_rng[1];
|
||||
ax.f = ax.f - n * __sinf_rng[1];
|
||||
m = m >> 1;
|
||||
n = n ^ m;
|
||||
m = (x < 0.0);
|
||||
n = n ^ m;
|
||||
n = n ^ m;
|
||||
n = n << 31;
|
||||
ax.i = ax.i ^ n;
|
||||
ax.i = ax.i ^ n;
|
||||
|
||||
//Taylor Polynomial (Estrins)
|
||||
xx = ax.f * ax.f;
|
||||
xx = ax.f * ax.f;
|
||||
a = (__sinf_lut[0] * ax.f) * xx + (__sinf_lut[2] * ax.f);
|
||||
b = (__sinf_lut[1] * ax.f) * xx + (__sinf_lut[3] * ax.f);
|
||||
xx = xx * xx;
|
||||
|
|
@ -173,18 +173,18 @@ float tmath_pow(float x, float n)
|
|||
{
|
||||
float a, b, c, d, xx;
|
||||
int m;
|
||||
|
||||
|
||||
union {
|
||||
float f;
|
||||
int i;
|
||||
} r;
|
||||
|
||||
|
||||
//extract exponent
|
||||
r.f = x;
|
||||
m = (r.i >> 23);
|
||||
m = m - 127;
|
||||
r.i = r.i - (m << 23);
|
||||
|
||||
|
||||
//Taylor Polynomial (Estrins)
|
||||
xx = r.f * r.f;
|
||||
a = (__powf_lut[4] * r.f) + (__powf_lut[0]);
|
||||
|
|
@ -204,20 +204,20 @@ float tmath_pow(float x, float n)
|
|||
|
||||
//Range Reduction:
|
||||
m = (int) (r.f * __powf_rng[0]);
|
||||
r.f = r.f - ((float) m) * __powf_rng[1];
|
||||
|
||||
r.f = r.f - ((float) m) * __powf_rng[1];
|
||||
|
||||
//Taylor Polynomial (Estrins)
|
||||
a = (__powf_lut[12] * r.f) + (__powf_lut[8]);
|
||||
b = (__powf_lut[14] * r.f) + (__powf_lut[10]);
|
||||
c = (__powf_lut[13] * r.f) + (__powf_lut[9]);
|
||||
d = (__powf_lut[15] * r.f) + (__powf_lut[11]);
|
||||
xx = r.f * r.f;
|
||||
a = a + b * xx;
|
||||
a = a + b * xx;
|
||||
c = c + d * xx;
|
||||
xx = xx* xx;
|
||||
r.f = a + c * xx;
|
||||
|
||||
//multiply by 2 ^ m
|
||||
r.f = a + c * xx;
|
||||
|
||||
//multiply by 2 ^ m
|
||||
m = m << 23;
|
||||
r.i = r.i + m;
|
||||
|
||||
|
|
@ -229,8 +229,8 @@ static const float __atan2f_lut[4] = {
|
|||
-0.3258083974640975, //p3
|
||||
+0.1555786518463281, //p5
|
||||
+0.9997878412794807 //p1
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
static const float __atan2f_pi_2 = M_PI_2;
|
||||
|
||||
float tmath_atan2(float y, float x)
|
||||
|
|
@ -250,10 +250,10 @@ float tmath_atan2(float y, float x)
|
|||
xinv.f = 1.41176471f - 0.47058824f * xinv.f;
|
||||
xinv.i = xinv.i + m;
|
||||
b = 2.0 - xinv.f * xx;
|
||||
xinv.f = xinv.f * b;
|
||||
xinv.f = xinv.f * b;
|
||||
b = 2.0 - xinv.f * xx;
|
||||
xinv.f = xinv.f * b;
|
||||
|
||||
|
||||
c = fabs(y * xinv.f);
|
||||
|
||||
//fast inverse approximation (2x newton)
|
||||
|
|
@ -263,22 +263,22 @@ float tmath_atan2(float y, float x)
|
|||
xinv.f = 1.41176471f - 0.47058824f * xinv.f;
|
||||
xinv.i = xinv.i + m;
|
||||
b = 2.0 - xinv.f * c;
|
||||
xinv.f = xinv.f * b;
|
||||
xinv.f = xinv.f * b;
|
||||
b = 2.0 - xinv.f * c;
|
||||
xinv.f = xinv.f * b;
|
||||
|
||||
|
||||
//if |x| > 1.0 -> ax = -1/ax, r = pi/2
|
||||
xinv.f = xinv.f + c;
|
||||
a = (c > 1.0f);
|
||||
c = c - a * xinv.f;
|
||||
r = a * __atan2f_pi_2;
|
||||
|
||||
|
||||
//polynomial evaluation
|
||||
xx = c * c;
|
||||
xx = c * c;
|
||||
a = (__atan2f_lut[0] * c) * xx + (__atan2f_lut[2] * c);
|
||||
b = (__atan2f_lut[1] * c) * xx + (__atan2f_lut[3] * c);
|
||||
xx = xx * xx;
|
||||
r = r + a * xx;
|
||||
r = r + a * xx;
|
||||
r = r + b;
|
||||
|
||||
//determine quadrant and test for small x.
|
||||
|
|
@ -291,7 +291,7 @@ float tmath_atan2(float y, float x)
|
|||
r = r + __atan2f_pi_2 * b;
|
||||
b = r + r;
|
||||
r = r - (y < 0.0f) * b;
|
||||
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +305,7 @@ float tmath_sqrt(float x)
|
|||
float f;
|
||||
int i;
|
||||
} a;
|
||||
|
||||
|
||||
//fast invsqrt approx
|
||||
a.f = x;
|
||||
a.i = 0x5F3759DF - (a.i >> 1); //VRSQRTE
|
||||
|
|
@ -448,7 +448,7 @@ tmat4_set_near_plane(float *m, tvec4 *plane)
|
|||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Generate perspective projection matrix.
|
||||
*
|
||||
* @relates tmatN
|
||||
|
|
@ -658,7 +658,7 @@ void tmat4_lookat(float *result,
|
|||
up.x = upX;
|
||||
up.y = upY;
|
||||
up.z = upZ;
|
||||
|
||||
|
||||
tvec3_cross(&side, forward, up);
|
||||
tvec3_normalize(&side);
|
||||
tvec3_cross(&up, side, forward);
|
||||
|
|
@ -686,7 +686,7 @@ void tmat4_lookat(float *result,
|
|||
|
||||
/**
|
||||
* Multiply the vector by the matrix, dividing the
|
||||
* components by w
|
||||
* components by w
|
||||
*
|
||||
* @relates tvec3
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ TMS_STATIC_INLINE float tms_modf(float a, float b)
|
|||
return a - b*(floorf(a/b));
|
||||
}
|
||||
|
||||
#define RANDF_MAX 2147483647.f
|
||||
|
||||
TMS_STATIC_INLINE float trandf(float min, float max)
|
||||
{
|
||||
return min+(float)(rand())/((float)(RAND_MAX/(max-min)));
|
||||
return min+(float)(rand())/((float)(RANDF_MAX/(max-min)));
|
||||
}
|
||||
|
||||
TMS_STATIC_INLINE float twrapf(float x, float min, float max)
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef _TMS_QUAT__H_
|
||||
#define _TMS_QUAT__H_
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
typedef tquat tvec4;
|
||||
|
||||
#define TQUAT_IDENTITY (tquat){0.f,0.f,0.f,1.f}
|
||||
#define tquat_normalize tvec4_normalize
|
||||
|
||||
TMS_STATIC_INLINE tquat tquat_mul(tquat* q1, tquat* q2)
|
||||
{
|
||||
return (tquat){
|
||||
q1->w*q2->w - q1->x*q2->x - q1->y*q2->y - q1->z*q2->z;
|
||||
q1->w*q2->x + q1->x*q2->w + q1->y*q2->z - q1->z*q2->y;
|
||||
q1->w*q2->y - q1->x*q2->z + q1->y*w2->w + q1->z*q2->x;
|
||||
q1->w*q2->z + q1->x*q2->y - q1->y*q2->x + q1->z*q2->w;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#include "rk4.h"
|
||||
|
||||
/**
|
||||
* 4th order Runge-Kutta ODE solver
|
||||
**/
|
||||
void
|
||||
tmath_ode_solver_rk4(float now, float step,
|
||||
void (*d)(float t, float *v, float *out),
|
||||
float *v, int dim
|
||||
)
|
||||
{
|
||||
int x;
|
||||
#ifdef _MSC_VER
|
||||
float *t0 = malloc(dim*sizeof(float));
|
||||
float *t1 = malloc(dim*sizeof(float));
|
||||
float *t2 = malloc(dim*sizeof(float));
|
||||
float *t3 = malloc(dim*sizeof(float));
|
||||
float *k = malloc(dim*sizeof(float));
|
||||
#else
|
||||
float t0[dim], t1[dim],
|
||||
t2[dim], t3[dim],
|
||||
k[dim];
|
||||
#endif
|
||||
|
||||
d(now, v, t0);
|
||||
for (x=0; x<dim; x++) k[x] = v[x] + t0[x] * step/2.f;
|
||||
d(now+step/2.f, v, t1);
|
||||
for (x=0; x<dim; x++) k[x] = v[x] + t1[x] * step/2.f;
|
||||
d(now+step/2.f, v, t2);
|
||||
for (x=0; x<dim; x++) k[x] = v[x] + t2[x] * step;
|
||||
d(now+step, v, t3);
|
||||
|
||||
for (x=0; x<dim; x++) v[x] = v[x] + (t0[x] + 2.f * t1[x] + 2.f * t2[x] + 2.f * t3[x]) * step/6.f;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
free(t0);
|
||||
free(t1);
|
||||
free(t2);
|
||||
free(t3);
|
||||
free(k);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef _TMATH_RK4__H_
|
||||
#define _TMATH_RK4__H_
|
||||
|
||||
void tmath_ode_solver_rk4(float now, float step, void (*d)(float t, float *v, float *out), float *v, int dim);
|
||||
|
||||
#endif
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#include <math.h>
|
||||
#include <tms/util/util.h>
|
||||
|
||||
/**
|
||||
/**
|
||||
* 2D vector.
|
||||
* Can be accessed using various naming conventions depending on intention. For
|
||||
* texture coordinates, V.u and V.v, and for space coordinates V.x and V.y.
|
||||
|
|
@ -14,7 +14,7 @@ typedef struct tvec2 {
|
|||
union {float y; float g; float t; float v; float h;};
|
||||
} tvec2;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 3D vector.
|
||||
* Can be accessed using various naming conventions depending on intention.
|
||||
* For example: x y z, r g b, s t p.
|
||||
|
|
@ -25,7 +25,7 @@ typedef struct tvec3 {
|
|||
union {float z; float b; float p;};
|
||||
} tvec3;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 4-float general purpose vector. Use this for plane equations and homogenous 3d coordinates.
|
||||
* Can be accessed using various naming conventions, x y z w, r g b a, etc.
|
||||
**/
|
||||
|
|
|
|||
174
src/tms/modules/3ds.c
Normal file
174
src/tms/modules/3ds.c
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
#include <tms/core/glob.h>
|
||||
#include <tms/math/glob.h>
|
||||
|
||||
#define NAME_MAX 32
|
||||
|
||||
struct vertex {
|
||||
tvec3 pos;
|
||||
tvec3 nor;
|
||||
tvec2 uv;
|
||||
};
|
||||
|
||||
static struct tms_mesh * load_3ds_model(struct tms_model *model, SDL_RWops *fp, int *status);
|
||||
|
||||
void
|
||||
tmod_3ds_init(void)
|
||||
{
|
||||
tms_register_model_loader(load_3ds_model, "3ds");
|
||||
}
|
||||
|
||||
static struct tms_mesh *
|
||||
load_3ds_model(struct tms_model *model,
|
||||
SDL_RWops *fp, int *status)
|
||||
{
|
||||
uint16_t chunk_id;
|
||||
uint32_t chunk_len;
|
||||
uint16_t num_items;
|
||||
char object_name[NAME_MAX];
|
||||
|
||||
struct vertex *vertex_buf = 0;
|
||||
uint16_t *index_buf = 0;
|
||||
uint16_t base_index;
|
||||
|
||||
size_t num_vertices = 0;
|
||||
size_t num_indices = 0;
|
||||
size_t sz;
|
||||
|
||||
long filesz;
|
||||
SDL_RWseek(fp, 0, SEEK_END);
|
||||
filesz = SDL_RWtell(fp);
|
||||
SDL_RWseek(fp, 0, SEEK_SET);
|
||||
|
||||
//tms_infof("3DS FILE SIZE: %d", (int)filesz);
|
||||
|
||||
while (SDL_RWtell(fp) < filesz) {
|
||||
SDL_RWread(fp, &chunk_id, 2, 1);
|
||||
SDL_RWread(fp, &chunk_len, 4, 1);
|
||||
//fread(&chunk_id, 2, 1, fp);
|
||||
//fread(&chunk_len, 4, 1, fp);
|
||||
|
||||
//tms_debugf("chunk id: %x, chunk size: %d", chunk_id, chunk_len);
|
||||
|
||||
switch (chunk_id) {
|
||||
case 0x4d4d:
|
||||
case 0x3d3d:
|
||||
break;
|
||||
|
||||
case 0x4000: /* object block */
|
||||
{
|
||||
//tms_debugf("found object chunk");
|
||||
int x;
|
||||
for (x=0; x<NAME_MAX-1; x++) {
|
||||
SDL_RWread(fp, &object_name[x], 1, 1);
|
||||
//fread(&object_name[x], 1, 1, fp);
|
||||
if (object_name[x] == '\0')
|
||||
break;
|
||||
}
|
||||
object_name[x] = '\0';
|
||||
//tms_debugf("object name: %s", object_name);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x4100:
|
||||
break;
|
||||
|
||||
case 0x4110: /* vertices list */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
//tms_debugf("found vertices chunk, num items: %d", num_items);
|
||||
|
||||
tms_assertf(num_vertices == 0, "multiple meshes per model not currently supported");
|
||||
num_vertices = num_items;
|
||||
|
||||
sz = model->vertices->size;
|
||||
|
||||
base_index = sz / sizeof(struct vertex);
|
||||
|
||||
if (base_index > 0x7fff) {
|
||||
//tms_infof("WARNING TOO MANY INDICES ----------------------------------------h");
|
||||
}
|
||||
//tms_infof("base index:%d", base_index);
|
||||
tms_gbuffer_realloc(model->vertices, sz + num_items * sizeof(struct vertex));
|
||||
vertex_buf = model->vertices->buf+sz;
|
||||
|
||||
for (int x=0; x<num_items; x++) {
|
||||
SDL_RWread(fp, &vertex_buf[x].pos, 4, 3);
|
||||
//fread(&vertex_buf[x].pos, 4, 3, fp);
|
||||
vertex_buf[x].nor = (tvec3){0,0,0};
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x4120: /* faces list */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
// tms_debugf("found faces chunk, num items: %d", num_items);
|
||||
tms_assertf(num_indices == 0, "face list specified more than once, not supported");
|
||||
num_indices = num_items * 3;
|
||||
|
||||
sz = model->indices->size;
|
||||
tms_gbuffer_realloc(model->indices, sz+ num_indices * sizeof(uint16_t));
|
||||
index_buf = model->indices->buf+(sz);
|
||||
|
||||
for (int x=0; x<num_items; x++) {
|
||||
uint16_t _i[4];
|
||||
SDL_RWread(fp, &_i, sizeof(uint16_t)*4, 1);
|
||||
//fread(&_i, sizeof(uint16_t) * 4, 1, fp);
|
||||
|
||||
/* calculate this face's normal and update the vertices */
|
||||
tvec3 a = vertex_buf[_i[0]].pos;
|
||||
tvec3 b = vertex_buf[_i[1]].pos;
|
||||
tvec3 c = vertex_buf[_i[2]].pos;
|
||||
|
||||
tvec3_sub(&b, &a);
|
||||
tvec3_sub(&c, &a);
|
||||
tvec3_cross(&a, b, c);
|
||||
|
||||
index_buf[x*3+0] = _i[0] + base_index;
|
||||
index_buf[x*3+1] = _i[1] + base_index;
|
||||
index_buf[x*3+2] = _i[2] + base_index;
|
||||
tvec3_add(&vertex_buf[_i[0]].nor, &a);
|
||||
tvec3_add(&vertex_buf[_i[1]].nor, &a);
|
||||
tvec3_add(&vertex_buf[_i[2]].nor, &a);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0x4140: /* texture coordinates */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
// tms_debugf("found uv mapping chunk, num items: %d", num_items);
|
||||
tms_assertf(num_vertices != 0, "oops! texture coordinates specified before vertices list, unsupported at this time");
|
||||
//tms_assertf(num_items*sizeof(struct vertex) == vertices->size, "number texture coordinates does not match number of vertices");
|
||||
|
||||
for (int x=0; x<num_items; x++)
|
||||
SDL_RWread(fp, &vertex_buf[x].uv, 4, 2);
|
||||
//fread(&vertex_buf[x].uv, 4, 2, fp);
|
||||
break;
|
||||
|
||||
default:
|
||||
SDL_RWseek(fp, chunk_len-6, SEEK_CUR);
|
||||
//fseek(fp, chunk_len-6, SEEK_CUR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tms_assertf(num_indices > 0, "found no index list in 3ds file");
|
||||
tms_assertf(num_vertices > 0, "found no vertices list in 3ds file");
|
||||
|
||||
/* loop through all vertices and normalize the normals */
|
||||
for (int x=0; x<num_vertices; x++)
|
||||
tvec3_normalize(&vertex_buf[x].nor);
|
||||
|
||||
struct tms_mesh *mesh = tms_model_create_mesh(model);
|
||||
|
||||
mesh->i_start = ((char*)index_buf - model->indices->buf) / 2;// / sizeof(struct vertex);
|
||||
mesh->i_count = num_indices;// / sizeof(struct vertex);
|
||||
|
||||
mesh->v_start = ((char*)vertex_buf - model->vertices->buf);
|
||||
mesh->v_count = num_vertices;
|
||||
|
||||
//tms_infof("i start %d", ((char*)index_buf - model->indices->buf));
|
||||
|
||||
*status = T_OK;
|
||||
return mesh;
|
||||
}
|
||||
|
|
@ -1,342 +0,0 @@
|
|||
#include <tms/core/glob.h>
|
||||
#include <tms/math/glob.h>
|
||||
|
||||
#define NAME_MAX 32
|
||||
|
||||
struct vertex {
|
||||
tvec3 pos;
|
||||
tvec3 nor;
|
||||
tvec2 uv;
|
||||
};
|
||||
|
||||
static struct tms_mesh * load_3ds_model(struct tms_model *model, SDL_RWops *fp, int *status);
|
||||
|
||||
void
|
||||
tmod_3ds_init(void)
|
||||
{
|
||||
tms_register_model_loader(load_3ds_model, "3ds");
|
||||
}
|
||||
|
||||
static struct tms_mesh *
|
||||
load_3ds_model(struct tms_model *model,
|
||||
SDL_RWops *fp, int *status)
|
||||
{
|
||||
uint16_t chunk_id;
|
||||
uint32_t chunk_len;
|
||||
uint16_t num_items;
|
||||
char object_name[NAME_MAX];
|
||||
|
||||
struct vertex *vertex_buf = 0;
|
||||
uint16_t *index_buf = 0;
|
||||
uint16_t base_index;
|
||||
|
||||
size_t num_vertices = 0;
|
||||
size_t num_indices = 0;
|
||||
size_t sz;
|
||||
|
||||
long filesz;
|
||||
SDL_RWseek(fp, 0, SEEK_END);
|
||||
filesz = SDL_RWtell(fp);
|
||||
SDL_RWseek(fp, 0, SEEK_SET);
|
||||
|
||||
//tms_infof("3DS FILE SIZE: %d", (int)filesz);
|
||||
|
||||
while (SDL_RWtell(fp) < filesz) {
|
||||
SDL_RWread(fp, &chunk_id, 2, 1);
|
||||
SDL_RWread(fp, &chunk_len, 4, 1);
|
||||
//fread(&chunk_id, 2, 1, fp);
|
||||
//fread(&chunk_len, 4, 1, fp);
|
||||
|
||||
//tms_debugf("chunk id: %x, chunk size: %d", chunk_id, chunk_len);
|
||||
|
||||
switch (chunk_id) {
|
||||
case 0x4d4d:
|
||||
case 0x3d3d:
|
||||
break;
|
||||
|
||||
case 0x4000: /* object block */
|
||||
{
|
||||
//tms_debugf("found object chunk");
|
||||
int x;
|
||||
for (x=0; x<NAME_MAX-1; x++) {
|
||||
SDL_RWread(fp, &object_name[x], 1, 1);
|
||||
//fread(&object_name[x], 1, 1, fp);
|
||||
if (object_name[x] == '\0')
|
||||
break;
|
||||
}
|
||||
object_name[x] = '\0';
|
||||
//tms_debugf("object name: %s", object_name);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x4100:
|
||||
break;
|
||||
|
||||
case 0x4110: /* vertices list */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
//tms_debugf("found vertices chunk, num items: %d", num_items);
|
||||
|
||||
tms_assertf(num_vertices == 0, "multiple meshes per model not currently supported");
|
||||
num_vertices = num_items;
|
||||
|
||||
sz = model->vertices->size;
|
||||
|
||||
base_index = sz / sizeof(struct vertex);
|
||||
|
||||
if (base_index > 0x7fff) {
|
||||
//tms_infof("WARNING TOO MANY INDICES ----------------------------------------h");
|
||||
}
|
||||
//tms_infof("base index:%d", base_index);
|
||||
tms_gbuffer_realloc(model->vertices, sz + num_items * sizeof(struct vertex));
|
||||
vertex_buf = model->vertices->buf+sz;
|
||||
|
||||
for (int x=0; x<num_items; x++) {
|
||||
SDL_RWread(fp, &vertex_buf[x].pos, 4, 3);
|
||||
//fread(&vertex_buf[x].pos, 4, 3, fp);
|
||||
vertex_buf[x].nor = (tvec3){0,0,0};
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x4120: /* faces list */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
// tms_debugf("found faces chunk, num items: %d", num_items);
|
||||
tms_assertf(num_indices == 0, "face list specified more than once, not supported");
|
||||
num_indices = num_items * 3;
|
||||
|
||||
sz = model->indices->size;
|
||||
tms_gbuffer_realloc(model->indices, sz+ num_indices * sizeof(uint16_t));
|
||||
index_buf = model->indices->buf+(sz);
|
||||
|
||||
for (int x=0; x<num_items; x++) {
|
||||
uint16_t _i[4];
|
||||
SDL_RWread(fp, &_i, sizeof(uint16_t)*4, 1);
|
||||
//fread(&_i, sizeof(uint16_t) * 4, 1, fp);
|
||||
|
||||
/* calculate this face's normal and update the vertices */
|
||||
tvec3 a = vertex_buf[_i[0]].pos;
|
||||
tvec3 b = vertex_buf[_i[1]].pos;
|
||||
tvec3 c = vertex_buf[_i[2]].pos;
|
||||
|
||||
tvec3_sub(&b, &a);
|
||||
tvec3_sub(&c, &a);
|
||||
tvec3_cross(&a, b, c);
|
||||
|
||||
index_buf[x*3+0] = _i[0] + base_index;
|
||||
index_buf[x*3+1] = _i[1] + base_index;
|
||||
index_buf[x*3+2] = _i[2] + base_index;
|
||||
tvec3_add(&vertex_buf[_i[0]].nor, &a);
|
||||
tvec3_add(&vertex_buf[_i[1]].nor, &a);
|
||||
tvec3_add(&vertex_buf[_i[2]].nor, &a);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0x4140: /* texture coordinates */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
// tms_debugf("found uv mapping chunk, num items: %d", num_items);
|
||||
tms_assertf(num_vertices != 0, "oops! texture coordinates specified before vertices list, unsupported at this time");
|
||||
//tms_assertf(num_items*sizeof(struct vertex) == vertices->size, "number texture coordinates does not match number of vertices");
|
||||
|
||||
for (int x=0; x<num_items; x++)
|
||||
SDL_RWread(fp, &vertex_buf[x].uv, 4, 2);
|
||||
//fread(&vertex_buf[x].uv, 4, 2, fp);
|
||||
break;
|
||||
|
||||
default:
|
||||
SDL_RWseek(fp, chunk_len-6, SEEK_CUR);
|
||||
//fseek(fp, chunk_len-6, SEEK_CUR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tms_assertf(num_indices > 0, "found no index list in 3ds file");
|
||||
tms_assertf(num_vertices > 0, "found no vertices list in 3ds file");
|
||||
|
||||
/* loop through all vertices and normalize the normals */
|
||||
for (int x=0; x<num_vertices; x++)
|
||||
tvec3_normalize(&vertex_buf[x].nor);
|
||||
|
||||
struct tms_mesh *mesh = tms_model_create_mesh(model);
|
||||
|
||||
mesh->i_start = ((char*)index_buf - model->indices->buf) / 2;// / sizeof(struct vertex);
|
||||
mesh->i_count = num_indices;// / sizeof(struct vertex);
|
||||
|
||||
mesh->v_start = ((char*)vertex_buf - model->vertices->buf);
|
||||
mesh->v_count = num_vertices;
|
||||
|
||||
//tms_infof("i start %d", ((char*)index_buf - model->indices->buf));
|
||||
|
||||
*status = T_OK;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int
|
||||
load_3ds_model(struct tms_model *model,
|
||||
SDL_RWops *fp)
|
||||
{
|
||||
uint16_t chunk_id;
|
||||
uint32_t chunk_len;
|
||||
uint16_t num_items;
|
||||
char object_name[NAME_MAX];
|
||||
|
||||
struct tms_gbuffer *vertices = 0;
|
||||
struct tms_gbuffer *indices = 0;
|
||||
|
||||
struct vertex *vertex_buf = 0;
|
||||
uint16_t *index_buf = 0;
|
||||
|
||||
long filesz;
|
||||
SDL_RWseek(fp, 0, SEEK_END);
|
||||
filesz = SDL_RWtell(fp);
|
||||
SDL_RWseek(fp, 0, SEEK_SET);
|
||||
|
||||
tms_infof("3DS FILE SIZE: %d", (int)filesz);
|
||||
|
||||
while (SDL_RWtell(fp) < filesz) {
|
||||
SDL_RWread(fp, &chunk_id, 2, 1);
|
||||
SDL_RWread(fp, &chunk_len, 4, 1);
|
||||
//fread(&chunk_id, 2, 1, fp);
|
||||
//fread(&chunk_len, 4, 1, fp);
|
||||
|
||||
tms_debugf("chunk id: %x, chunk size: %d", chunk_id, chunk_len);
|
||||
|
||||
switch (chunk_id) {
|
||||
case 0x4d4d:
|
||||
case 0x3d3d:
|
||||
break;
|
||||
|
||||
case 0x4000: /* object block */
|
||||
tms_debugf("found object chunk");
|
||||
int x;
|
||||
for (x=0; x<NAME_MAX-1; x++) {
|
||||
SDL_RWread(fp, &object_name[x], 1, 1);
|
||||
//fread(&object_name[x], 1, 1, fp);
|
||||
if (object_name[x] == '\0')
|
||||
break;
|
||||
}
|
||||
object_name[x] = '\0';
|
||||
tms_debugf("object name: %s", object_name);
|
||||
break;
|
||||
|
||||
case 0x4100:
|
||||
break;
|
||||
|
||||
case 0x4110: /* vertices list */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
tms_debugf("found vertices chunk, num items: %d", num_items);
|
||||
|
||||
tms_assertf(vertices == 0, "multiple meshes per model not currently supported");
|
||||
|
||||
if (model->flat)
|
||||
vertex_buf = malloc(num_items * sizeof(struct vertex));
|
||||
else {
|
||||
vertices = tms_gbuffer_alloc(num_items * sizeof(struct vertex));
|
||||
vertex_buf = tms_gbuffer_get_buffer(vertices);
|
||||
}
|
||||
|
||||
for (int x=0; x<num_items; x++) {
|
||||
SDL_RWread(fp, &vertex_buf[x].pos, 4, 3);
|
||||
//fread(&vertex_buf[x].pos, 4, 3, fp);
|
||||
vertex_buf[x].nor = (tvec3){0,0,0};
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x4120: /* faces list */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
tms_debugf("found faces chunk, num items: %d", num_items);
|
||||
tms_assertf(indices == 0 || model->flat, "face list specified more than once, not supported");
|
||||
|
||||
struct vertex *nverts = 0;
|
||||
|
||||
if (model->flat) {
|
||||
vertices = tms_gbuffer_alloc(num_items * 3 * sizeof(struct vertex));
|
||||
nverts = tms_gbuffer_get_buffer(vertices);
|
||||
} else {
|
||||
indices = tms_gbuffer_alloc(num_items * 3 * sizeof(uint16_t));
|
||||
index_buf = tms_gbuffer_get_buffer(indices);
|
||||
}
|
||||
for (int x=0; x<num_items; x++) {
|
||||
uint16_t _i[4];
|
||||
SDL_RWread(fp, &_i, sizeof(uint16_t)*4, 1);
|
||||
//fread(&_i, sizeof(uint16_t) * 4, 1, fp);
|
||||
|
||||
/* calculate this face's normal and update the vertices */
|
||||
tvec3 a = vertex_buf[_i[0]].pos;
|
||||
tvec3 b = vertex_buf[_i[1]].pos;
|
||||
tvec3 c = vertex_buf[_i[2]].pos;
|
||||
|
||||
tvec3_sub(&b, &a);
|
||||
tvec3_sub(&c, &a);
|
||||
tvec3_cross(&a, b, c);
|
||||
|
||||
if (model->flat) {
|
||||
nverts[x*3+0] = vertex_buf[_i[0]];
|
||||
nverts[x*3+0].nor = a;
|
||||
nverts[x*3+1] = vertex_buf[_i[1]];
|
||||
nverts[x*3+1].nor = a;
|
||||
nverts[x*3+2] = vertex_buf[_i[2]];
|
||||
nverts[x*3+2].nor = a;
|
||||
} else {
|
||||
index_buf[x*3+0] = _i[0];
|
||||
index_buf[x*3+1] = _i[1];
|
||||
index_buf[x*3+2] = _i[2];
|
||||
tvec3_add(&vertex_buf[index_buf[x*3]].nor, &a);
|
||||
tvec3_add(&vertex_buf[index_buf[x*3+1]].nor, &a);
|
||||
tvec3_add(&vertex_buf[index_buf[x*3+2]].nor, &a);
|
||||
}
|
||||
}
|
||||
|
||||
if (model->flat) {
|
||||
free(vertex_buf);
|
||||
vertex_buf = nverts;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0x4140: /* texture coordinates */
|
||||
SDL_RWread(fp, &num_items, 2, 1);
|
||||
//fread(&num_items, 2, 1, fp);
|
||||
tms_debugf("found uv mapping chunk, num items: %d", num_items);
|
||||
tms_assertf(vertices != 0, "oops! texture coordinates specified before vertices list, unsupported at this time");
|
||||
tms_assertf(num_items*sizeof(struct vertex) == vertices->size, "number texture coordinates does not match number of vertices");
|
||||
|
||||
for (int x=0; x<num_items; x++)
|
||||
SDL_RWread(fp, &vertex_buf[x].uv, 4, 2);
|
||||
//fread(&vertex_buf[x].uv, 4, 2, fp);
|
||||
break;
|
||||
|
||||
default:
|
||||
SDL_RWseek(fp, chunk_len-6, SEEK_CUR);
|
||||
//fseek(fp, chunk_len-6, SEEK_CUR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!model->flat)
|
||||
tms_assertf(indices != 0, "found no faces list in 3ds file");
|
||||
|
||||
tms_assertf(vertices != 0, "found no vertices list in 3ds file");
|
||||
|
||||
/* loop through all vertices and normalize the normals */
|
||||
for (int x=0; x<vertices->size/sizeof(struct vertex); x++)
|
||||
tvec3_normalize(&vertex_buf[x].nor);
|
||||
|
||||
struct tms_varray *va = tms_varray_alloc(3);
|
||||
tms_varray_map_attribute(va, "position", 3, GL_FLOAT, vertices);
|
||||
tms_varray_map_attribute(va, "normal", 3, GL_FLOAT, vertices);
|
||||
tms_varray_map_attribute(va, "texcoord", 2, GL_FLOAT, vertices);
|
||||
|
||||
model->buffer = vertices;
|
||||
model->indices = indices;
|
||||
model->mesh = tms_mesh_alloc(va, indices);
|
||||
|
||||
return T_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
NAME=3ds
|
||||
INIT=tmod_3ds_init
|
||||
SOURCES=( 3ds.c )
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
NAME="jpeg"
|
||||
INIT=tmod_jpeg_init
|
||||
SOURCES=( jpeg.c )
|
||||
LIBS=( jpeg )
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#include <tms/core/glob.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <jpeglib.h>
|
||||
|
||||
static int load_jpeg(struct tms_texture *tex, FILE *f);
|
||||
|
||||
void
|
||||
tmod_jpeg_init(void)
|
||||
{
|
||||
tms_register_image_loader(load_jpeg, "jpg");
|
||||
tms_register_image_loader(load_jpeg, "jpeg");
|
||||
}
|
||||
|
||||
static int
|
||||
load_jpeg(struct tms_texture *tex, FILE *f)
|
||||
{
|
||||
struct jpeg_decompress_struct jpeg;
|
||||
struct jpeg_error_mgr jerr;
|
||||
|
||||
jpeg.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&jpeg);
|
||||
jpeg_stdio_src(&jpeg, f);
|
||||
|
||||
if (jpeg_read_header(&jpeg, 1) != JPEG_HEADER_OK)
|
||||
return T_READ_ERROR;
|
||||
|
||||
tex->width = jpeg.image_width;
|
||||
tex->height = jpeg.image_height;
|
||||
|
||||
jpeg_start_decompress(&jpeg);
|
||||
|
||||
if (!(tex->data = malloc(jpeg.output_height*jpeg.output_width*jpeg.output_components))) {
|
||||
jpeg_destroy_decompress(&jpeg);
|
||||
return T_OUT_OF_MEM;
|
||||
}
|
||||
|
||||
while (jpeg.output_scanline < jpeg.output_height) {
|
||||
char *d = tex->data+jpeg.output_scanline*jpeg.output_components*jpeg.output_width;
|
||||
jpeg_read_scanlines(&jpeg, &d, 1);
|
||||
}
|
||||
|
||||
tms_infof("JPEG num_channels: %d", jpeg.jpeg_color_space);
|
||||
|
||||
jpeg_finish_decompress(&jpeg);
|
||||
jpeg_destroy_decompress(&jpeg);
|
||||
|
||||
tex->num_channels = jpeg.jpeg_color_space;
|
||||
|
||||
return T_OK;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
#ifndef _LOCOMOTION__H_
|
||||
#define _LOCOMOTION__H_
|
||||
|
||||
struct tmotion_brain
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct tmotion_muscle
|
||||
{
|
||||
float maxforce;
|
||||
};
|
||||
|
||||
struct tmotion_bone
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
NAME=png
|
||||
INIT=tmod_png_init
|
||||
|
||||
SOURCES=( png.c )
|
||||
LIBS=( png )
|
||||
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
#include <png.h>
|
||||
#include <tms/core/glob.h>
|
||||
|
||||
static int load_png(struct tms_texture *tex, FILE *fp);
|
||||
|
||||
void
|
||||
tmod_png_init(void)
|
||||
{
|
||||
tms_register_image_loader(load_png, "png");
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
load_png(struct tms_texture *tex, FILE *fp)
|
||||
{
|
||||
char header[8];
|
||||
png_struct *png = 0;
|
||||
png_info *info = 0;
|
||||
int passes;
|
||||
|
||||
fread(header, 1, 8, fp);
|
||||
if (png_sig_cmp(header, 0, 8) != 0)
|
||||
goto error;
|
||||
|
||||
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
|
||||
info = png_create_info_struct(png);
|
||||
|
||||
if (setjmp(png_jmpbuf(png))) {
|
||||
png_destroy_read_struct(&png, &info, 0);
|
||||
return T_READ_ERROR;
|
||||
}
|
||||
|
||||
png_init_io(png, fp);
|
||||
png_set_sig_bytes(png, 8);
|
||||
|
||||
png_read_png(png, info, PNG_TRANSFORM_EXPAND, 0);
|
||||
|
||||
tex->width = png_get_image_width(png, info);
|
||||
tex->height = png_get_image_height(png, info);
|
||||
tex->num_channels = (png_get_color_type(png, info) == PNG_COLOR_TYPE_RGBA ? 4 : 3);
|
||||
|
||||
tms_debugf("png dimensions: %dx%d", tex->width, tex->height);
|
||||
|
||||
unsigned rbytes = png_get_rowbytes(png, info);
|
||||
(tex->data = malloc(rbytes*tex->height))
|
||||
|| tms_fatalf("out of mem (png)");
|
||||
|
||||
png_bytepp rp = png_get_rows(png, info);
|
||||
for (int x=0; x<tex->height; x++) {
|
||||
/* swap row order since opengl uses vertically flipped order */
|
||||
memcpy(tex->data+rbytes*(tex->height-1-x), rp[x], rbytes);
|
||||
}
|
||||
|
||||
png_destroy_read_struct(&png, &info, 0);
|
||||
|
||||
return T_OK;
|
||||
|
||||
error:
|
||||
/* XXX */
|
||||
tms_fatalf("png error");
|
||||
return T_READ_ERROR;
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "transfade.h"
|
||||
#include "tms.h"
|
||||
#include "framebuffer.h"
|
||||
#include "shader.h"
|
||||
#include "backend_spec.h"
|
||||
|
||||
T TMOD_transfade_init(T_context *ctx);
|
||||
T TMOD_transfade_begin(T_screen *old, T_screen *new);
|
||||
T TMOD_transfade_render(long time);
|
||||
T TMOD_transfade_end(void);
|
||||
|
||||
T_transition
|
||||
TMOD_transfade =
|
||||
{
|
||||
.begin = &TMOD_transfade_begin,
|
||||
.render = &TMOD_transfade_render,
|
||||
.end = &TMOD_transfade_end,
|
||||
};
|
||||
|
||||
T_framebuffer *framebuffer;
|
||||
T_screen *old;
|
||||
T_screen *new;
|
||||
T_shader *shader;
|
||||
T_shader *mesh;
|
||||
int initialized = 0;
|
||||
GLuint alpha_loc;
|
||||
float fade = 0;
|
||||
|
||||
T
|
||||
TMOD_transfade_init(T_context *ctx)
|
||||
{
|
||||
framebuffer = T_framebuffer_alloc(ctx, ctx->width, ctx->height, 24);
|
||||
shader = T_shader_load("default+texturedtransp");
|
||||
|
||||
mesh = T_mesh_alloc(2, 0);
|
||||
T_mesh_set_shader(mesh, shader);
|
||||
|
||||
alpha_loc = T_shader_get_uniform(shader, "alpha");
|
||||
|
||||
float position[] = {
|
||||
1.f, 1.f, 0,
|
||||
-1.f, 1.f, 0,
|
||||
-1.f, -1.f, 0,
|
||||
1.f, -1.f, 0,
|
||||
};
|
||||
float texcoords[] = {
|
||||
1.f, 1.f,
|
||||
0.f, 1.f,
|
||||
0.f, 0.f,
|
||||
1.f, 0.f,
|
||||
};
|
||||
|
||||
T_mesh_set_attribute(mesh, 0, "position", position, 3, 4, GL_STATIC_DRAW);
|
||||
T_mesh_set_attribute(mesh, 1, "texcoord", texcoords, 2, 4, GL_STATIC_DRAW);
|
||||
T_mesh_upload(mesh);
|
||||
|
||||
assert(framebuffer != 0);
|
||||
initialized = 1;
|
||||
return T_OK;
|
||||
}
|
||||
|
||||
T
|
||||
TMOD_transfade_begin(T_screen *o, T_screen *n)
|
||||
{
|
||||
assert(initialized == 1);
|
||||
|
||||
fade = 0;
|
||||
old = o;
|
||||
new = n;
|
||||
return T_OK;
|
||||
}
|
||||
|
||||
T
|
||||
TMOD_transfade_render(long time)
|
||||
{
|
||||
fade += (float)time/500.f;
|
||||
|
||||
if (fade > 1.f)
|
||||
fade = 1;
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
T_framebuffer_bind(framebuffer);
|
||||
new->spec->render(new);
|
||||
T_framebuffer_unbind(framebuffer);
|
||||
|
||||
old->spec->render(old);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, framebuffer->fbo_texture);
|
||||
|
||||
T_shader_bind(shader);
|
||||
|
||||
glUniform1fv(alpha_loc, 1, &fade);
|
||||
|
||||
float m[16] = TMATH_MAT4_IDENTITY;
|
||||
T_shader_set_matrices(shader, m, m);
|
||||
T_mesh_render(mesh);
|
||||
|
||||
if (fade >= 1)
|
||||
return T_OK;
|
||||
|
||||
return T_CONT;
|
||||
}
|
||||
|
||||
T
|
||||
TMOD_transfade_end(void)
|
||||
{
|
||||
return T_OK;
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef _TMOD_TRANSFADE__H_
|
||||
#define _TMOD_TRANSFADE__H_
|
||||
|
||||
#include "transition.h"
|
||||
|
||||
extern T_transition TMOD_transfade;
|
||||
|
||||
#endif
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
#include "util.h"
|
||||
#include "list.h"
|
||||
#include "hash.h"
|
||||
|
|
|
|||
|
|
@ -1,144 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "list.h"
|
||||
#include "../core/err.h"
|
||||
|
||||
struct tlist*
|
||||
tlist_alloc()
|
||||
{
|
||||
struct tlist *list = malloc(sizeof(struct tlist));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void
|
||||
tlist_free(struct tlist *list)
|
||||
{
|
||||
/* XXX */
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the new start of the tlist
|
||||
**/
|
||||
struct tlist*
|
||||
tlist_append(struct tlist *list, void *data)
|
||||
{
|
||||
struct tlist *new_list;
|
||||
struct tlist *last;
|
||||
|
||||
new_list = tlist_alloc();
|
||||
new_list->data = data;
|
||||
new_list->next = NULL;
|
||||
|
||||
if (list) {
|
||||
last = tlist_last(list);
|
||||
last->next = new_list;
|
||||
|
||||
return last;
|
||||
} else
|
||||
return new_list;
|
||||
}
|
||||
|
||||
struct tlist*
|
||||
tlist_prepend(struct tlist *list, void *data)
|
||||
{
|
||||
struct tlist *new_list;
|
||||
|
||||
new_list = tlist_alloc();
|
||||
new_list->data = data;
|
||||
new_list->next = list;
|
||||
|
||||
return new_list;
|
||||
}
|
||||
|
||||
struct tlist*
|
||||
tlist_insert(struct tlist *list, void *data, int position)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tlist*
|
||||
tlist_remove(struct tlist *list, void *data)
|
||||
{
|
||||
struct tlist *tmp, *prev = NULL;
|
||||
|
||||
tmp = list;
|
||||
while (tmp) {
|
||||
if (tmp->data == data) {
|
||||
if (prev)
|
||||
prev->next = tmp->next;
|
||||
else
|
||||
list = tmp->next;
|
||||
|
||||
tlist_free(tmp);
|
||||
break;
|
||||
}
|
||||
prev = tmp;
|
||||
tmp = prev->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
struct tlist*
|
||||
tlist_find(struct tlist *list, void *data)
|
||||
{
|
||||
while (list) {
|
||||
if (list->data == data)
|
||||
break;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
struct tlist*
|
||||
tlist_find_custom(struct tlist *list, int (*cb)(void*))
|
||||
{
|
||||
assert((cb != NULL));
|
||||
|
||||
while (list) {
|
||||
/* XXX: is one argument enough? */
|
||||
if (cb(list->data) == 0)
|
||||
break;
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
struct tlist*
|
||||
tlist_last(struct tlist *list)
|
||||
{
|
||||
if (list) {
|
||||
while (list->next)
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void
|
||||
tlist_foreach(struct tlist *list, void (*cb)(void*))
|
||||
{
|
||||
while (list) {
|
||||
struct tlist *next = list->next;
|
||||
(*cb)(list->data);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
tlist_length(struct tlist *list)
|
||||
{
|
||||
int length = 0;
|
||||
|
||||
while (list) {
|
||||
++length;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef _TLIST__H_
|
||||
#define _TLIST__H_
|
||||
|
||||
/** @relates tlist @{ **/
|
||||
|
||||
/**
|
||||
* General purpose linked list
|
||||
**/
|
||||
struct tlist {
|
||||
struct tlist *next;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct tlist* tlist_alloc();
|
||||
void tlist_free(struct tlist *list);
|
||||
|
||||
struct tlist* tlist_append(struct tlist *list, void *data);
|
||||
struct tlist* tlist_prepend(struct tlist *list, void *data);
|
||||
struct tlist* tlist_insert(struct tlist *list, void *data, int position);
|
||||
struct tlist* tlist_remove(struct tlist *list, void *data);
|
||||
struct tlist* tlist_find(struct tlist *list, void *data);
|
||||
struct tlist* tlist_find_custom(struct tlist *list, int (*cb)(void*));
|
||||
struct tlist* tlist_last(struct tlist *list);
|
||||
void tlist_foreach(struct tlist *list, void (*cb)(void*));
|
||||
int tlist_length(struct tlist *list);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue