Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged upstream master / 07bdde7, support for sprite-depth stuff

  • Loading branch information...
commit 3abdf2cf94595ee967bab54da42a9639900a255e 1 parent c8229f3
@superjer authored
View
1  .gitignore
@@ -1,7 +1,6 @@
*.dll
*.[oa]
*.swp
-*.sh
cscope.*
tags
spartor_linux
View
1  Makefile
@@ -22,6 +22,7 @@ OBJS = engine/main.o \
engine/sprite_helpers.o \
engine/projection.o \
engine/sjglob.o \
+ engine/helpers.o \
engine/mt19937ar/mt19937ar.o
FLAGS = --std=c99 -g -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -DGLEW_STATIC
INC = -Iengine -Igame
View
11 commands.txt
@@ -27,6 +27,11 @@ connect connect <host> [[:]port]
Connect to a server. E.g. connect 127.0.0.1:31103
+depth depth
+
+ Display depth buffer values.
+
+
dimetric dimetric
Switch the current context to render mode dimetric. See also
@@ -121,6 +126,12 @@ report report
Show a report of all the game objects.
+resprite resprite
+
+ Reload all sprite information from texture definition files
+ ( game/textures/*.png.txt )
+ for all currently loaded textures.
+
save save <mapname>
Saves the current context to mapname.txt. If it already exists,
View
4 engine/audio.c
@@ -325,8 +325,8 @@ static void music_test( int *buf, int len )
else if( t <= e->sustain ) ;
else if( t <= e->release ) veloc *= (e->release-t)/(e->release-e->sustain);
- double tr_freq = e->start_freq * pow(TWELFTH_ROOT,e->tremolo_steps);
- double vi_freq = e->start_freq * pow(TWELFTH_ROOT,e->vibrato_steps);
+ //double tr_freq = e->start_freq * pow(TWELFTH_ROOT,e->tremolo_steps);
+ //double vi_freq = e->start_freq * pow(TWELFTH_ROOT,e->vibrato_steps);
e->tremolo_period += e->tremolo_speed;
e->tremolo_speed += e->tremolo_accel;
View
43 engine/helpers.c
@@ -0,0 +1,43 @@
+/**
+ ** SPARToR
+ ** Network Game Engine
+ ** Copyright (C) 2010-2012 Jer Wilson
+ **
+ ** See COPYING for details.
+ **
+ ** http://www.superjer.com/
+ ** http://www.spartor.com/
+ ** http://github.com/superjer/SPARToR
+ **/
+
+
+#include <stdlib.h>
+#include <string.h>
+
+
+#define POINTLIS_CHUNK 80
+
+
+typedef void *thing;
+
+
+// build a unique list of pointers with no storage limit and no storage overhead
+// returns true if adding for the 1st time
+int pointlis_add( thing **list, thing item )
+{
+ if( !list[0] ) list[0] = calloc( POINTLIS_CHUNK, sizeof **list );
+
+ size_t n = 0;
+ while( list[0][n] ) {
+ if( list[0][n] == item ) return 0; // found!
+ n++;
+ }
+
+ if( n % POINTLIS_CHUNK == POINTLIS_CHUNK-1 ) { // need to grow
+ list[0] = realloc( list[0], (n+1+POINTLIS_CHUNK) * sizeof **list );
+ memset( list[0]+n+1, 0, POINTLIS_CHUNK * sizeof **list );
+ }
+
+ list[0][n] = item;
+ return 1;
+}
View
8 engine/helpers.h
@@ -0,0 +1,8 @@
+
+#ifndef SPARTOR_HELPERS__
+#define SPARTOR_HELPERS__
+
+int pointlis_add( void ***list, void *item );
+
+#endif
+
View
11 engine/saveload.c
@@ -269,8 +269,15 @@ int load_context(const char *name,int context,int loadfr)
co->x = x;
co->y = y;
co->z = z;
- if( co->map ) free(co->map ); //FIXME remove hack_map someday and don't free this stuff here
- if( co->dmap ) free(co->dmap);
+
+ // FIXME: MEM LEAK!
+ // Using resprite shortly after unloading a context WOULD cause a crash
+ // Garbage collection of old contexts is NOT implemented yet, so they just leak for now
+ // FIXME: MEM LEAK!
+
+ // if( co->map ) free(co->map ); //FIXME remove hack_map someday and don't free this stuff here
+ // if( co->dmap ) free(co->dmap);
+
co->map = hack_map = map;
co->dmap = hack_dmap = dmap;
View
49 engine/sjdl.c
@@ -52,25 +52,60 @@ void SJGL_SetTex(GLuint tex)
glBindTexture(GL_TEXTURE_2D,0); //FIXME: hack 4 win, suddenly also useful for handling an invalid tex
- if( tex >= tex_count ) { SJC_Write("Attempted to set invalid texture (%d/%d)",tex,tex_count); return; }
+ if( tex >= tex_count ) { /*SJC_Write("Attempted to set invalid texture (%d/%d)",tex,tex_count);*/ return; }
glBindTexture( GL_TEXTURE_2D, textures[tex].glname );
}
-//uses GL to do draw a sprite
+// wrapper for SJFL_Blit when there's only one z
int SJGL_Blit(REC *s, int x, int y, int z)
{
- if( z<0 ) z = (y+s->h)*-z;
+ return SJGL_BlitSkew(s,x,y,z,z);
+}
+
+//uses GL to do draw a sprite
+int SJGL_BlitSkew(REC *s, int x, int y, int zlo, int zhi)
+{
int x2 = ( s->w > 0 ? x+s->w : x-s->w );
int y2 = ( s->h > 0 ? y+s->h : y-s->h );
+ int rhi=0, ghi=0, bhi=0;
+ int rlo=0, glo=0, blo=0;
+
+ if( m_showdepth ) {
+ int grad;
+ int sect;
+
+ #define GET_COLOR(z,r,g,b) \
+ grad = z + 512; \
+ sect = (grad / 256 + 70) % 7; \
+ grad = grad % 256; \
+ \
+ switch( sect ) { \
+ case 0: r = grad; break; \
+ case 1: r = 255; b = grad; break; \
+ case 2: r = 255 - grad; b = 255; break; \
+ case 3: b = 255; g = grad; break; \
+ case 4: b = 255 - grad; g = 255; break; \
+ case 5: r = grad; g = 255; break; \
+ case 6: r = 255; b = grad; g = 255; break; \
+ }
+
+ GET_COLOR(zlo,rlo,glo,blo);
+ GET_COLOR(zhi,rhi,ghi,bhi);
+
+ glBindTexture(GL_TEXTURE_2D,0);
+ }
+
glBegin(GL_QUADS);
- glTexCoord3i(s->x , s->y , z); glVertex3i(x , y , z);
- glTexCoord3i(s->x+s->w, s->y , z); glVertex3i(x2, y , z);
- glTexCoord3i(s->x+s->w, s->y+s->h, z); glVertex3i(x2, y2, z);
- glTexCoord3i(s->x , s->y+s->h, z); glVertex3i(x , y2, z);
+ if( m_showdepth ) glColor3ub(rhi,ghi,bhi);
+ glTexCoord2i(s->x , s->y ); glVertex3i(x , y , zhi);
+ glTexCoord2i(s->x+s->w, s->y ); glVertex3i(x2, y , zhi);
+ if( m_showdepth ) glColor3ub(rlo,glo,blo);
+ glTexCoord2i(s->x+s->w, s->y+s->h); glVertex3i(x2, y2, zlo);
+ glTexCoord2i(s->x , s->y+s->h); glVertex3i(x , y2, zlo);
glEnd();
return 0;
View
1  engine/sjdl.h
@@ -21,6 +21,7 @@ typedef struct{
SDL_Surface *SJDL_CopyScaled(SDL_Surface *src, Uint32 flags, int scale);
void SJGL_SetTex(GLuint tex);
int SJGL_Blit(REC *s, int x, int y, int z);
+int SJGL_BlitSkew(REC *s, int x, int y, int zlo, int zhi);
void SJDL_SetPixel(SDL_Surface *surf, int x, int y, Uint8 R, Uint8 G, Uint8 B);
void SJDL_GetPixel(SDL_Surface *surf, int x, int y, Uint8 *R, Uint8 *G, Uint8 *B);
GLenum SJDL_GLFormatOf(SDL_Surface *surf);
View
147 engine/sprite.c
@@ -26,6 +26,8 @@ size_t spr_count;
char *spr_names[] = { SPRITE_ENUM(STRINGIFY) };
int spr_map[sprite_enum_max] = { 0 };
+SPRITE_T *old_sprites; // for reloading sprites and translating old ids
+size_t old_spr_count;
static size_t spr_alloc;
static char filename[100];
@@ -40,18 +42,28 @@ static SPRITE_T *new_sprite(int texnum,const char *name,const SPRITE_T *base);
static int fail(const char *msg);
static int tokenize(char *s);
static int read_anchor(int i,SPRITE_T *arg);
+static void read_num(int *num, const char *token);
-void sprblit( SPRITE_T *spr, int x, int y, int z )
+void sprblit( SPRITE_T *spr, int x, int y )
{
+ if( !spr ) return;
+
+ int zlo = DEPTH_OF(y) + spr->bump;
+ int zhi;
+
+ if( spr->flags & SPRF_FLOOR )
+ zhi = zlo - spr->rec.h;
+ else
+ zhi = zlo + spr->rec.h;
+
SJGL_SetTex( spr->texnum );
- SJGL_Blit( &spr->rec, x-spr->ancx, y-spr->ancy, z );
+ SJGL_BlitSkew( &spr->rec, x-spr->ancx, y-spr->ancy, zlo, zhi );
}
int load_sprites(int texnum)
{
-
if( strlen(textures[texnum].filename) > 95 ) {
SJC_Write("load_sprites: filename too long: %s", textures[texnum].filename);
return -1;
@@ -74,13 +86,13 @@ int load_sprites(int texnum)
int piping = 0;
int also = 0;
int gridstart = -1;
- SPRITE_T defs = {0, NULL, {0, 0, 32, 32}, 16, 32, 0, NULL};
+ SPRITE_T defs = {0, 0, NULL, {0, 0, 32, 32}, 16, 32, 0, NULL};
SPRITE_T gdefs;
SPRITE_T prev_spr = defs;
line_num = 0;
- for( ;; ) {
+ for( ;; ) { // each line in the file
if( mode==DEFAULT || mode==NOMORE )
mode = READY;
@@ -176,13 +188,13 @@ int load_sprites(int texnum)
while( ++i < count ) {
if( isdigit(tokens[i][0]) || tokens[i][0]=='-' ) {
- if( count-i != 2 && count-i != 4 && count-i != 6 )
- return fail("Expecting 2, 4 or 6 numeric args, when no name found");
+ if( count-i != 2 && count-i != 4 && count-i < 6 )
+ return fail("Expecting 2, 4 or 6+ values, when no name found");
- targ->rec.x = atoi(tokens[ i]);
- targ->rec.y = atoi(tokens[++i]); if( i>=count-1 ) break;
- targ->rec.w = atoi(tokens[++i]);
- targ->rec.h = atoi(tokens[++i]); if( i>=count-1 ) break;
+ read_num(&targ->rec.x, tokens[ i]);
+ read_num(&targ->rec.y, tokens[++i]); if( i>=count-1 ) break;
+ read_num(&targ->rec.w, tokens[++i]);
+ read_num(&targ->rec.h, tokens[++i]); if( i>=count-1 ) break;
i = read_anchor(i+1,targ);
@@ -190,15 +202,21 @@ int load_sprites(int texnum)
if( count-i < 3 )
return fail("Expecting 2 args for 'pos'");
- targ->rec.x = atoi(tokens[++i]);
- targ->rec.y = atoi(tokens[++i]);
+ read_num(&targ->rec.x, tokens[++i]);
+ read_num(&targ->rec.y, tokens[++i]);
} else if( !strcmp(tokens[i],"size") ) {
if( count-i < 3 )
return fail("Expecting 2 args for 'size'");
- targ->rec.w = atoi(tokens[++i]);
- targ->rec.h = atoi(tokens[++i]);
+ read_num(&targ->rec.w, tokens[++i]);
+ read_num(&targ->rec.h, tokens[++i]);
+
+ } else if( !strcmp(tokens[i],"bump") ) {
+ if( count-i < 2 )
+ return fail("Expecting 1 arg for 'bump'");
+
+ read_num(&targ->bump, tokens[++i]);
} else if( !strcmp(tokens[i],"anchor") ) {
if( count-i < 3 )
@@ -250,6 +268,9 @@ int load_sprites(int texnum)
} else if( !strcmp(tokens[i],"flipy") ) {
targ->flags |= SPRF_FLIPY;
+ } else if( !strcmp(tokens[i],"floor") ) {
+ targ->flags |= SPRF_FLOOR;
+
} else {
SJC_Write("tokens %d: %s",i,tokens[i]);
return fail("Unknown property name");
@@ -289,10 +310,39 @@ int load_sprites(int texnum)
return 0;
}
-void unload_sprites()
+// reload all sprites
+// old sprite data is available in old_sprites
+// call unload_sprites(old_sprites,old_spr_count) soon after to avoid leaks
+void reload_sprites()
{
+ old_sprites = sprites;
+ old_spr_count = spr_count;
+
+ sprites = NULL;
+ spr_count = 0;
+ spr_alloc = 0;
+
+ memset( spr_map, 0, sprite_enum_max * sizeof *spr_map );
+
+ size_t i;
+ for( i=0; i<tex_count; i++ )
+ if( textures[i].filename )
+ load_sprites(i);
}
+// unload either old_sprites (after reloading all sprites) or sprites (when shutting down)
+void unload_sprites(SPRITE_T *sprites,size_t spr_count)
+{
+ size_t i;
+ for( i=0; i<spr_count; i++ ) {
+ free(sprites[i].name);
+ free(sprites[i].more);
+ }
+ free(sprites);
+ sprites = NULL;
+ spr_count = 0;
+ // does not reset spr_alloc! (there's no old_spr_alloc)
+}
int find_sprite_by_name(const char *name)
{
@@ -304,7 +354,6 @@ int find_sprite_by_name(const char *name)
return 0;
}
-
static SPRITE_T *new_sprite(int texnum,const char *name,const SPRITE_T *base)
{
if( spr_count == spr_alloc ) {
@@ -357,39 +406,63 @@ static int tokenize(char *s)
static int read_anchor(int i,SPRITE_T *targ)
{
int flipme = 0;
-
- targ->ancx = 0;
- targ->ancy = 0;
- targ->flags &= ~SPRF_ALIGNMASK;
+ int xcaret = 0;
+ int ycaret = 0;
char *p = tokens[i];
- if( isdigit(*p) || *p=='-' ) { targ->ancx = atoi(p); }
- else if( !strncmp(p,"to",2) ) { targ->flags |= SPRF_TOP; flipme = 1; }
- else if( !strncmp(p,"le",2) ) { targ->flags |= SPRF_LFT; }
- else if( !strncmp(p,"mi",2) ) { targ->flags |= SPRF_MID; flipme = 1; }
- else if( !strncmp(p,"ce",2) ) { targ->flags |= SPRF_CEN; }
- else if( !strncmp(p,"bo",2) ) { targ->flags |= SPRF_BOT; flipme = 1; }
- else if( !strncmp(p,"ri",2) ) { targ->flags |= SPRF_RGT; }
+
+ if( *p!='^' ) targ->ancx = 0;
+
+ if( isdigit(*p) || *p=='-' ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->ancx = atoi(p); }
+ else if( *p=='^' ) { xcaret = targ->ancx; }
+ else if( !strncmp(p,"to",2) ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->flags |= SPRF_TOP; flipme = 1; }
+ else if( !strncmp(p,"le",2) ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->flags |= SPRF_LFT; }
+ else if( !strncmp(p,"mi",2) ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->flags |= SPRF_MID; flipme = 1; }
+ else if( !strncmp(p,"ce",2) ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->flags |= SPRF_CEN; }
+ else if( !strncmp(p,"bo",2) ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->flags |= SPRF_BOT; flipme = 1; }
+ else if( !strncmp(p,"ri",2) ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->flags |= SPRF_RGT; }
while( *p && *p!='-' && *p!='+' )
p++;
- if( *p ) targ->ancx = atoi(p);
+ if( *p ) targ->ancx = atoi(p) + xcaret;
p = tokens[++i];
- if( isdigit(*p) || *p=='-' ) { targ->ancy = atoi(p); }
- else if( !strncmp(p,"to",2) ) { targ->flags |= SPRF_TOP; }
- else if( !strncmp(p,"le",2) ) { targ->flags |= SPRF_LFT; flipme = 1; }
- else if( !strncmp(p,"mi",2) ) { targ->flags |= SPRF_MID; }
- else if( !strncmp(p,"ce",2) ) { targ->flags |= SPRF_CEN; flipme = 1; }
- else if( !strncmp(p,"bo",2) ) { targ->flags |= SPRF_BOT; }
- else if( !strncmp(p,"ri",2) ) { targ->flags |= SPRF_RGT; flipme = 1; }
+
+ if( *p!='^' ) targ->ancy = 0;
+
+ if( isdigit(*p) || *p=='-' ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->ancy = atoi(p); }
+ else if( *p=='^' ) { ycaret = targ->ancy; }
+ else if( !strncmp(p,"to",2) ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->flags |= SPRF_TOP; }
+ else if( !strncmp(p,"le",2) ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->flags |= SPRF_LFT; flipme = 1; }
+ else if( !strncmp(p,"mi",2) ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->flags |= SPRF_MID; }
+ else if( !strncmp(p,"ce",2) ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->flags |= SPRF_CEN; flipme = 1; }
+ else if( !strncmp(p,"bo",2) ) { targ->flags &= ~SPRF_ALIGNYMASK; targ->flags |= SPRF_BOT; }
+ else if( !strncmp(p,"ri",2) ) { targ->flags &= ~SPRF_ALIGNXMASK; targ->flags |= SPRF_RGT; flipme = 1; }
while( *p && *p!='-' && *p!='+' )
p++;
- if( *p ) targ->ancy = atoi(p);
+ if( *p ) targ->ancy = atoi(p) + ycaret;
if( flipme ) SWAP( targ->ancx, targ->ancy, int );
return i;
}
+
+// Read a number from token into num, like atoi
+// But if it starts with ^, add the number to num
+// It is OK if there's no number after the ^
+static void read_num(int *num, const char *token)
+{
+ if( *token!='^' ) {
+ *num = atoi(token);
+ return;
+ }
+
+ token++;
+
+ if( *token!='+' && *token!='-' )
+ return;
+
+ *num += atoi(token);
+}
View
25 engine/sprite.h
@@ -24,18 +24,23 @@ enum { TOOL_NUL = 1,
SPRF_TOP = 0x100,
SPRF_MID = 0x200,
SPRF_BOT = 0x400,
- SPRF_LFT = 0x800,
+ SPRF_ALIGNYMASK = SPRF_TOP | SPRF_MID | SPRF_BOT,
+ SPRF_LFT = 0x0800,
SPRF_CEN = 0x1000,
SPRF_RGT = 0x2000,
+ SPRF_ALIGNXMASK = 0x3800,
SPRF_ALIGNMASK = 0x3F00,
SPRF_FLIPX = 0x4000,
- SPRF_FLIPY = 0x8000 };
+ SPRF_FLIPY = 0x8000,
+ SPRF_FLOOR = 0x10000 };
typedef struct {
- int texnum;
- char *name;
- REC rec;
- int ancx,ancy; // anchor position
+ int texnum;
+ int bump;
+ char *name;
+ REC rec;
+ int ancx; // anchor position
+ int ancy;
unsigned flags;
struct {
int gridwide;
@@ -55,10 +60,14 @@ extern size_t spr_count;
extern char *spr_names[];
extern int spr_map[];
+extern SPRITE_T *old_sprites;
+extern size_t old_spr_count;
-void sprblit( SPRITE_T *spr, int x, int y, int z );
+
+void sprblit( SPRITE_T *spr, int x, int y );
int load_sprites(int texnum);
-void unload_sprites();
+void reload_sprites();
+void unload_sprites(SPRITE_T *sprites,size_t spr_count);
int find_sprite_by_name(const char *name);
View
34 engine/sprite_helpers.c
@@ -17,6 +17,9 @@
#include "sjdl.h"
#include "main.h"
#include "sprite.h"
+#include "sprite_helpers.h"
+#include "console.h"
+#include "helpers.h"
#include <limits.h>
@@ -97,4 +100,35 @@ SPRITE_T *sprite_grid_transform_xy(SPRITE_T *spr, CONTEXT_t *co, int x, int y, i
return spr;
}
+void renumber_sprites()
+{
+ if( !sprites || !old_sprites ) {
+ SJC_Write("Can't renumber sprites!");
+ return;
+ }
+
+ CB **blocks = NULL;
+
+ // find and renumber ALL sprites, past and future
+ int i, j, k;
+ for( i=0; i<maxframes; i++ ) {
+ for( j=0; j<maxobjs; j++ ) {
+ if( fr[i].objs[j].type == OBJT_CONTEXT ) {
+ CONTEXT_t *co = fr[i].objs[j].data;
+ CB *map = co->map;
+ CB *dmap = co->dmap;
+ int volume = co->x * co->y * co->z;
+
+ if( pointlis_add( (void***)&blocks, map ) )
+ for( k=0; k<volume; k++ )
+ co->map[k].spr = find_sprite_by_name(old_sprites[co->map[k].spr].name);
+
+ if( pointlis_add( (void***)&blocks, dmap ) )
+ for( k=0; k<volume; k++ )
+ co->dmap[k].spr = find_sprite_by_name(old_sprites[co->dmap[k].spr].name);
+ }
+ }
+ }
+ free(blocks);
+}
View
1  engine/sprite_helpers.h
@@ -3,6 +3,7 @@
#define SPRITE_HELPERS__
SPRITE_T *sprite_grid_transform_xy(SPRITE_T *spr, CONTEXT_t *co, int x, int y, int z, int drawx, int drawy, int draww, int drawh);
+void renumber_sprites();
#endif
View
9 engine/video.c
@@ -133,7 +133,7 @@ void render()
glViewport(pad_left,h-NATIVEH*scale-pad_top,NATIVEW*scale,NATIVEH*scale);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0,NATIVEW,NATIVEH,0,-NATIVEH*3-1,NATIVEH*3+1);
+ glOrtho(0,NATIVEW,NATIVEH,0,NEARVAL,FARVAL);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
int camx = NATIVEW/2-(int)v_camx;
@@ -246,7 +246,7 @@ void render()
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0,w,h,0,-1,1);
+ glOrtho(0,w,h,0,NEARVAL,FARVAL);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -396,19 +396,16 @@ void setvideosoon(int w,int h,int go_full,int delay)
soon = delay;
}
-
int screen2native_x(int x)
{
return (x - pad_left)/scale + v_camx - NATIVEW/2;
}
-
int screen2native_y(int y)
{
return (y - pad_top )/scale + v_camy - NATIVEH/2;
}
-
int make_sure_texture_is_loaded(const char *texfile)
{
SDL_Surface *surf;
@@ -460,5 +457,3 @@ int make_sure_texture_is_loaded(const char *texfile)
return j;
}
}
-
-
View
45 game/mod.c
@@ -18,6 +18,9 @@
#include "sprite_helpers.h"
+int m_showdepth = 0; // whether to show the depth buffer values of drawn sprites
+
+
SYS_TEX_T sys_tex[] = {{"/tool.png" ,0},
{"/player.png" ,0},
{"/slugtunnel.png" ,0},
@@ -106,7 +109,7 @@ void mod_setup(Uint32 setupfr)
//make the mother object
fr[setupfr].objs[0] = (OBJ_t){ OBJT_MOTHER, 0, 0, sizeof(MOTHER_t), malloc(sizeof(MOTHER_t)) };
- *(MOTHER_t *)fr[setupfr].objs[0].data = (MOTHER_t){0};
+ memset( fr[setupfr].objs[0].data, 0, sizeof(MOTHER_t) );
//make default context object (map)
fr[setupfr].objs[1] = (OBJ_t){ OBJT_CONTEXT, 0, 0, sizeof(CONTEXT_t), malloc(sizeof(CONTEXT_t)) };
@@ -235,12 +238,14 @@ int mod_mkcmd(FCMD_t *c,int device,int sym,int press)
return -1;
if( c->cmd==CMDT_1EPREV ) { //select previous tile
+ if( !spr_count ) return -1;
myspr = (myspr + spr_count - 1) % spr_count;
mytex = sprites[myspr].texnum;
return -1;
}
if( c->cmd==CMDT_1ENEXT ) { //select next tile
+ if( !spr_count ) return -1;
myspr = (myspr + 1) % spr_count;
mytex = sprites[myspr].texnum;
return -1;
@@ -413,6 +418,15 @@ int mod_command(char *q)
magic_c.cmd = CMDT_0CON;
putcmd(-1,-1,-1);
return 0;
+ }else if( strcmp(q,"depth")==0 ){
+ m_showdepth = !m_showdepth;
+ return 0;
+ }else if( strcmp(q,"resprite")==0 ){
+ reload_sprites();
+ renumber_sprites();
+ SJC_Write("Was %d sprites, now %d sprites.",old_spr_count,spr_count);
+ unload_sprites(old_sprites,old_spr_count);
+ return 0;
}
return 1;
@@ -541,6 +555,8 @@ void mod_postdraw(Uint32 vidfr)
SPRITE_T *dspr = spr;
for( k=dnz; k<=upz; k++ ) for( j=dny; j<=upy; j++ ) for( i=dnx; i<=upx; i++ ) {
+ if( !spr ) continue;
+
if( (spr->flags & TOOL_MASK) == TOOL_PSTE && gh && gh->clipboard_data && (upz-dnz||upy-dny||upx-dnx) ) {
int x = (i-dnx+shx) % clipx;
int y = (j-dny+shy) % clipy;
@@ -614,10 +630,12 @@ void mod_outerdraw(Uint32 vidfr,int w,int h)
}
glColor4f(1,1,1,1);
- SJF_DrawText( w-sz, sz+ 4, SJF_LEFT,
- "Texture #%d \"%s\"", mytex, mytex < (int)tex_count ? textures[mytex].filename : "ERROR! mytex > tex_count" );
- SJF_DrawText( w-sz, sz+14, SJF_LEFT, "Sprite #%d \"%s\"", myspr, sprites[myspr].name );
- SJF_DrawText( w-sz, sz+24, SJF_LEFT, "Layer %d", ylayer );
+ if( myspr < (int)spr_count ) {
+ SJF_DrawText( w-sz, sz+ 4, SJF_LEFT,
+ "Texture #%d \"%s\"", mytex, mytex < (int)tex_count ? textures[mytex].filename : "ERROR! mytex > tex_count" );
+ SJF_DrawText( w-sz, sz+14, SJF_LEFT, "Sprite #%d \"%s\"", myspr, sprites[myspr].name );
+ SJF_DrawText( w-sz, sz+24, SJF_LEFT, "Layer %d", ylayer );
+ }
glPopAttrib();
}
@@ -671,17 +689,16 @@ static void draw_sprite_on_tile( SPRITE_T *spr, CONTEXT_t *co, int x, int y, int
SJGL_SetTex( spr->texnum );
int c = TILE2NATIVE_X(co,x,y,z);
- int d = TILE2NATIVE_Y(co,x,y,z);
- int r = d;
+ int d = TILE2NATIVE_Y(co,x,y,z) + co->tileuh/2;
- if( spr->ancy > co->tileuh ) // for sprites that pop out of the flat plane
- r += co->tileuh / 2;
+ sprblit( spr, c, d );
- r = 0; // TODO: remove once sprite ordering works in all projection modes
-
- // the sprite has an explicit anchor point, which is aligned with the anchor point of the tile,
- // which always in the southernmost corner
- SJGL_Blit( &spr->rec, c - spr->ancx, d + co->tileuh - spr->ancy, r );
+ if( m_showdepth ) {
+ glDisable(GL_DEPTH_TEST);
+ SJF_DrawText(c,d,SJF_LEFT,"%d%c",DEPTH_OF(d),spr->flags&SPRF_FLOOR?'f':'\0');
+ glEnable(GL_DEPTH_TEST);
+ SJGL_SetTex(-1); // notify SJGL that the texture has changed
+ }
}
View
2  game/mod.h
@@ -16,6 +16,7 @@
#include "projection.h"
#include "mod_private.h"
#include "obj_.h"
+#include "sprite.h"
#include <math.h>
@@ -25,6 +26,7 @@ extern size_t num_sys_tex;
extern INPUTNAME_t inputnames[];
extern int numinputnames;
+extern int m_showdepth;
extern CB *hack_map; //FIXME REMOVE SOMEDAY
extern CB *hack_dmap;
View
7 game/mod_constants.h
@@ -8,7 +8,10 @@
#define NATIVEW 384
#define NATIVEH 240
+#define NEARVAL (-99999)
+#define FARVAL ( 99999)
#define GAMENAME "mcdiddy"
+
#define CBDATASIZE 4 //context block (CB) payload size
#define MAXCMDDATA 64 //maximum size of extra command data
@@ -19,6 +22,9 @@
#define TEX_AMIGO 3
+#define DEPTH_OF(nativey) ((nativey) - v_camy + NATIVEH)
+
+
//obj types
enum { ENGINE_OBJT_LIST()
OBJT_MOTHER,
@@ -31,7 +37,6 @@ enum { ENGINE_OBJT_LIST()
OBJT_AMIGOSWORD,
OBJT_MAX };
-
enum DIR8 { NODIR=0, E, NE, N, NW, W, SW, S, SE };
// Amigo's states
View
24 game/obj_dummy.c
@@ -15,26 +15,10 @@
void obj_dummy_draw( int objid, Uint32 vidfr, OBJ_t *o, CONTEXT_t *co )
{
DUMMY_t *du = o->data;
- int c = POINT2NATIVE_X(&du->pos) + du->hull[0].x;
- int d = POINT2NATIVE_Y(&du->pos) + du->hull[0].y;
- int w = du->hull[1].x-du->hull[0].x;
- int h = du->hull[1].y-du->hull[0].y;
-
- Sint16 offs = w==h ? 48 : 0;
-
- SJGL_SetTex( sys_tex[TEX_WORLD].num );
-
- if( w > h ) while( w>0 && w<400 ) {
- SJGL_Blit( &(REC){offs, 16,16,16}, c, d, 0 );
- c += 16;
- w -= 16;
- offs = w==16 ? 32 : 16;
- } else while( h>0 && h<400 ) {
- SJGL_Blit( &(REC){ 48,offs,16,16}, c, d, 0 );
- d += 16;
- h -= 16;
- offs = h==16 ? 32 : 16;
- }
+ int c = POINT2NATIVE_X(&du->pos);
+ int d = POINT2NATIVE_Y(&du->pos);
+
+ sprblit( &SM(tnl_weight_silver), c, d );
}
void obj_dummy_adv( int objid, Uint32 a, Uint32 b, OBJ_t *oa, OBJ_t *ob )
View
4 game/obj_mother.c
@@ -72,8 +72,8 @@ void obj_mother_adv( int objid, Uint32 a, Uint32 b, OBJ_t *oa, OBJ_t *ob )
MKOBJ( sl, SLUG, 1, OBJF_POS|OBJF_VEL|OBJF_HULL|OBJF_VIS|OBJF_PLAT|OBJF_CLIP|OBJF_BNDB|OBJF_BNDX|OBJF_BNDZ );
sl->pos = (V){(hotfr%2)*368+8,0,0};
sl->vel = (V){(hotfr%2)?-0.5f:0.5f,0,0};
- sl->hull[0] = (V){-8,-4,-8};
- sl->hull[1] = (V){ 8, 8, 8};
+ sl->hull[0] = (V){-8,-12,-8};
+ sl->hull[1] = (V){ 8, 0, 8};
sl->model = 0;
sl->dead = 0;
}
View
32 game/obj_player.c
@@ -27,33 +27,33 @@ void obj_player_draw( int objid, Uint32 vidfr, OBJ_t *o, CONTEXT_t *co )
//girl hair
if ( pl->model!=4 ) ;
- else if( pl->facingr ) sprblit( &SM(girlhair_r), c, d-30+(pl->goingd?4:0)+pl->gundown/7, d );
- else sprblit( &SM(girlhair_l), c, d-30+(pl->goingd?4:0)+pl->gundown/7, d );
+ else if( pl->facingr ) sprblit( &SM(girlhair_r), c, d-30+(pl->goingd?4:0)+pl->gundown/7 );
+ else sprblit( &SM(girlhair_l), c, d-30+(pl->goingd?4:0)+pl->gundown/7 );
//player sprite
if( pl->goingd ) {
- if ( pl->turning ) sprblit( &SM(ctblue_duck_f), c, d, d);
- else if( pl->facingr ) sprblit( &SM(ctblue_duck_r), c, d, d);
- else sprblit( &SM(ctblue_duck_l), c, d, d);
+ if ( pl->turning ) sprblit( &SM(ctblue_duck_f), c, d );
+ else if( pl->facingr ) sprblit( &SM(ctblue_duck_r), c, d );
+ else sprblit( &SM(ctblue_duck_l), c, d );
} else {
- if ( pl->turning ) sprblit( &SM(ctblue_f), c, d, d);
- else if( pl->facingr ) sprblit( &SM(ctblue_r), c, d, d);
- else sprblit( &SM(ctblue_l), c, d, d);
+ if ( pl->turning ) sprblit( &SM(ctblue_f), c, d );
+ else if( pl->facingr ) sprblit( &SM(ctblue_r), c, d );
+ else sprblit( &SM(ctblue_l), c, d );
}
// knife or gun
- if ( pl->stabbing<0 ) sprblit( &SM(knife_up), c, d-44, d );
- else if( pl->stabbing>0 ) sprblit( &SM(knife_down), c, d+10, d );
+ if ( pl->stabbing<0 ) sprblit( &SM(knife_up), c, d-44 );
+ else if( pl->stabbing>0 ) sprblit( &SM(knife_down), c, d+10 );
else {
int gb = pl->gunback;
int gd = pl->gundown/5;
- if ( pl->goingu && pl->facingr ) sprblit( &SM(mp5_up_r), c+20-gb, d-25+gd, d );
- else if( pl->goingu ) sprblit( &SM(mp5_up_l), c-20+gb, d-25+gd, d );
- else if( pl->goingd && pl->facingr ) sprblit( &SM(mp5_down_r), c+20-gb, d-10+gd, d );
- else if( pl->goingd ) sprblit( &SM(mp5_down_l), c-20+gb, d-10+gd, d );
- else if( pl->facingr ) sprblit( &SM(mp5_r), c+20-gb, d-19+gd, d );
- else sprblit( &SM(mp5_l), c-20+gb, d-19+gd, d );
+ if ( pl->goingu && pl->facingr ) sprblit( &SM(mp5_up_r), c+20-gb, d-25+gd );
+ else if( pl->goingu ) sprblit( &SM(mp5_up_l), c-20+gb, d-25+gd );
+ else if( pl->goingd && pl->facingr ) sprblit( &SM(mp5_down_r), c+20-gb, d-10+gd );
+ else if( pl->goingd ) sprblit( &SM(mp5_down_l), c-20+gb, d-10+gd );
+ else if( pl->facingr ) sprblit( &SM(mp5_r), c+20-gb, d-19+gd );
+ else sprblit( &SM(mp5_l), c-20+gb, d-19+gd );
}
}
View
15 game/obj_slug.c
@@ -18,8 +18,11 @@ void obj_slug_draw( int objid, Uint32 vidfr, OBJ_t *o, CONTEXT_t *co )
SLUG_t *sl = o->data;
int c = POINT2NATIVE_X(&sl->pos);
int d = POINT2NATIVE_Y(&sl->pos);
- SJGL_SetTex( sys_tex[TEX_PLAYER].num );
- SJGL_Blit( &(REC){(sl->vel.x>0?20:0)+(sl->dead?40:0),177,20,16}, c-10, d-8, sl->pos.y );
+
+ if( sl->vel.x>0 )
+ sprblit( sl->dead ? &SM(slug_ouch_r) : &SM(slug_r), c, d );
+ else
+ sprblit( sl->dead ? &SM(slug_ouch_l) : &SM(slug_l), c, d );
}
void obj_slug_adv( int objid, Uint32 a, Uint32 b, OBJ_t *oa, OBJ_t *ob )
@@ -36,11 +39,11 @@ void obj_slug_adv( int objid, Uint32 a, Uint32 b, OBJ_t *oa, OBJ_t *ob )
if(fr[b].objs[i].type==OBJT_PLAYER) {
PLAYER_t *pl = fr[b].objs[i].data;
int up_stabbed = pl->stabbing<0
- && fabsf(sl->pos.x - pl->pos.x )<=12.0f
- && fabsf(sl->pos.y - pl->pos.y - pl->hull[0].y)<=8.0f ;
+ && fabsf(sl->pos.x - pl->pos.x )<=14.0f
+ && fabsf(sl->pos.y + sl->hull[1].y - pl->pos.y - pl->hull[0].y)<=8.0f ;
int dn_stabbed = pl->stabbing>0
- && fabsf(sl->pos.x - pl->pos.x )<=12.0f
- && fabsf(sl->pos.y - pl->pos.y - pl->hull[1].y)<=4.0f ;
+ && fabsf(sl->pos.x - pl->pos.x )<=14.0f
+ && fabsf(sl->pos.y + sl->hull[0].y - pl->pos.y - pl->hull[1].y)<=4.0f ;
if( up_stabbed ) {
pl->vel.y = sl->vel.y;
sl->vel.y = -5.0f;
View
48 game/spr_enum.h
@@ -1,5 +1,34 @@
/* This file is automatically generated by spr_enum.sh */
#define SPRITE_ENUM(X) \
+X(amigo1),\
+X(amigo2),\
+X(amigo3),\
+X(amigo4),\
+X(azma_stand_s),\
+X(azma_stand_se),\
+X(azma_stand_sw),\
+X(azma_stand_nw),\
+X(azma_stand_ne),\
+X(azma_stand_n),\
+X(azma_stand_w),\
+X(azma_stand_e),\
+X(azma_walk1_s),\
+X(azma_walk2_s),\
+X(azma_walk1_se),\
+X(azma_walk1_sw),\
+X(azma_walk2_se),\
+X(azma_walk2_sw),\
+X(azma_walk1_nw),\
+X(azma_walk1_ne),\
+X(azma_walk2_nw),\
+X(azma_walk2_ne),\
+X(azma_walk1_n),\
+X(azma_walk2_n),\
+X(azma_walk1_w),\
+X(azma_walk1_e),\
+X(azma_walk2_w),\
+X(azma_walk2_e),\
+X(shadow),\
X(ctblue_r),\
X(ctblue_l),\
X(ctblue_duck_r),\
@@ -39,12 +68,25 @@ X(mp5_up_l),\
X(bullet),\
X(knife_down),\
X(knife_up),\
-X(slug_r),\
X(slug_l),\
-X(slug_ouch_r),\
+X(slug_r),\
X(slug_ouch_l),\
+X(slug_ouch_r),\
X(ghost),\
X(girlhair_r),\
X(girlhair_l),\
-X(shadow),\
+X(tnl_weight_silver),\
+X(grass1),\
+X(grass2),\
+X(pave1),\
+X(pave2),\
+X(dirt1),\
+X(dirt2),\
+X(sand),\
+X(crust1),\
+X(crust2),\
+X(stone1),\
+X(stone2),\
+X(grass3),\
+X(flower),\
X(sprite_enum_unused)
View
4 game/spr_enum.sh
@@ -2,9 +2,9 @@
echo '/* This file is automatically generated by spr_enum.sh */' >spr_enum.h
echo '#define SPRITE_ENUM(X) \' >>spr_enum.h
-for x in player persons
+for x in textures/*.png.txt
do
- awk -F' ' '$1 ~ /^[A-Za-z_][A-Za-z_0-9]*$/ { print "X(" $1 "),\\" }' textures/$x.png.txt >>spr_enum.h
+ awk -F' ' '$1 ~ /^[A-Za-z_][A-Za-z_0-9]*$/ { print "X(" $1 "),\\" }' $x >>spr_enum.h
done
echo 'X(sprite_enum_unused)' >>spr_enum.h
View
12 game/textures/player.png.txt
@@ -38,7 +38,7 @@
ctgirl_duck_f
.end
-.grid cols 6 pos 0 150 size 24 25
+.grid cols 6 pos 0 150 size 24 25 bump 30
mp5_r anchor right 7
mp5_l anchor left 7
mp5_down_r anchor right 23
@@ -47,15 +47,15 @@
mp5_up_l anchor 2 top
.end
-bullet 144 150 4 4 mid cen
-knife_down 148 150 5 27 bot cen
-knife_up 153 150 5 27 top cen
+bullet 144 150 4 4 mid cen bump 50
+knife_down 148 150 5 27 bot cen bump 50
+knife_up 153 150 5 27 top cen bump 500
.grid pos 0 177 size 20 16 anchor bot cen
- slug_r
slug_l
- slug_ouch_r
+ slug_r
slug_ouch_l
+ slug_ouch_r
.end
ghost 80 177 15 16 left top
View
4 game/textures/slugtunnel.png.txt
@@ -1,4 +1,4 @@
-.default size 16 16 anchor cen bot
+.default size 16 16 anchor cen mid bump -100
tnl-redfloor-single 0 0
tnl-weight-gold 16 0
@@ -16,7 +16,7 @@ tnl-black 32 0
tnl-spacer-y-3
.end
-tnl_weight_silver 48 48
+tnl_weight_silver pos 48 48 bump 20
.grid cols 7 pos 64 0
tnl-circle-cut
View
26 platforms/scripts/tags.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# This script calls ctags and cscope to build tags info for Vim.
+# Uses some sed/awk tricks to get tags where they would otherwise be obscured by macros.
+# Run at the root of the project.
+
+mv game/game_structs.h{,.bak}
+sed -e 's/#define *TYPE */TYPE(/' \
+ -e 's/^ *//' \
+ game/game_structs.h.bak \
+ | awk -F'(' \
+ ' { nom=1; }
+ $1 ~ "^TYPE" { nom=0; type=$2;
+ print "typedef struct " $2 "_t {"; }
+ $1 ~ "^STRUCT" ||
+ $1 ~ "^EXPOSE" ||
+ $1 ~ "^HIDE" ||
+ $1 ~ "^)" { nom=0; print "//" $0; }
+ $1 ~ "endstruct.h" { nom=0; print "}",type,";"; }
+ nom { print $0; }
+ ' >game/game_structs.h
+
+ctags {engine,game}/*.[ch]
+cscope -b -I engine -I game -s engine -s game
+
+mv game/game_structs.h{.bak,}
Please sign in to comment.
Something went wrong with that request. Please try again.