Skip to content

Commit

Permalink
Updates to collision, tiled conversion, sgdk compat
Browse files Browse the repository at this point in the history
  • Loading branch information
kubilus1 committed Feb 9, 2020
1 parent 2d1367c commit c17a0db
Show file tree
Hide file tree
Showing 19 changed files with 984 additions and 303 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ RM = rm -f
ASMZ80 = $(GENBIN)/sjasm
BINTOS = $(GENBIN)/bintos

#OPTION= -Dnologo_ --save-temps -fverbose-asm -g
OPTION= -Dnologo_ -fverbose-asm -g
OPTION= -Dnologo_ --save-temps -fverbose-asm -g
#OPTION= -Dnologo_ -fverbose-asm -g
#OPTION= -Dnologo_

CS=$(wildcard libs/*.c)
SS=$(wildcard libs/*.s)
Expand All @@ -25,9 +26,12 @@ RESOURCES+=$(S80S:.s80=.o)
blast.a_OBJS=$(RESOURCES)

INCS = -Iincs -I$(GENDEV)/m68k-elf/include -I$(GENDEV)/sgdk/inc -I$(GENDEV)/sgdk/res
FLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer $(INCS)
FLAGS = $(OPTION) -m68000 -Wall -O2 -c -fomit-frame-pointer -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time $(INCS)
#FLAGS = $(OPTION) -m68000 -Wall -c -fomit-frame-pointer $(INCS) -O3 -flto -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time
#FLAGS = $(OPTION) -m68000 -Wall -c -fomit-frame-pointer $(INCS) -O3 -flto -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer
FLAGSZ80 = -isrc -iincs -I$(GENDEV)/m68k-elf/include


all: libblast.a

%.a: $(blast.a_OBJS)
Expand Down
7 changes: 4 additions & 3 deletions examples/coll_test1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MAKE?=make
LIB?=lib
GENGCC_BIN=$(GENDEV)/bin
GENBIN=$(GENDEV)/bin
SGDK_VER=1.34

CC = $(GENGCC_BIN)/m68k-elf-gcc
AS = $(GENGCC_BIN)/m68k-elf-as
Expand All @@ -30,16 +31,16 @@ SCD_LOADER = scd/LukeProjectCD
OPTION =
#OPTION = --save-temps
#INCS = -I. -I$(GENDEV)/m68k-elf/include -I$(GENDEV)/m68k-elf/include -Isrc -Ires
INCS = -I$(GENDEV)/include/blast -I. -I $(GENDEV)/sgdk/res -I $(GENDEV)/sgdk/inc -I$(GENDEV)/m68k-elf/include -I$(GENDEV)/m68k-elf/m68k-elf/include -I$(GENDEV)/include/blast -Isrc -Ires
INCS = -I$(GENDEV)/include/blast -I. -I $(GENDEV)/sgdk$(SGDK_VER)/res -I $(GENDEV)/sgdk$(SGDK_VER)/inc -I$(GENDEV)/m68k-elf/include -I$(GENDEV)/m68k-elf/m68k-elf/include -I$(GENDEV)/include/blast -Isrc -Ires
CCFLAGS = $(OPTION) -m68000 -Wall -O2 -c -fomit-frame-pointer
HWCCFLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer
Z80FLAGS = -vb2
ASFLAGS = -m68000 --register-prefix-optional
#LIBS = -L$(GENDEV)/m68k-elf/lib -L$(GENDEV)/m68k-elf/lib/gcc/m68k-elf/4.8.2 -L$(GENDEV)/m68k-elf/m68k-elf/lib -lmd -lc -lgcc -lnosys -lm
LIBS = -L$(GENDEV)/m68k-elf/lib -L$(GENDEV)/sgdk/lib -lmd -lnosys -lblast
LIBS = -L$(GENDEV)/m68k-elf/lib -L$(GENDEV)/sgdk$(SGDK_VER)/lib -lmd -lnosys -lblast
LINKFLAGS = -T $(GENDEV)/ldscripts/sgdk.ld -Map=output.map -nostdlib
SCDLINKFLAGS = -T scd/mdcd.ld -nostdlib
ARCHIVES = $(GENDEV)/sgdk/lib/libmd.a
ARCHIVES = $(GENDEV)/sgdk$(SGDK_VER)/lib/libmd.a


# Are we AMD64?
Expand Down
47 changes: 24 additions & 23 deletions examples/physics_test1/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ void myJoyHandler(u16 joy, u16 changed, u16 state) {
//VDP_drawTextBG(VDP_PLAN_A,"JOY ",0x8000,1,1);
if (joy == JOY_1) {
if((state & BUTTON_UP)) {
asprite.velocity.y += -64;
asprite.velocity.y += -16;
} else if ((state & BUTTON_DOWN)) {
asprite.velocity.y += 64;
asprite.velocity.y += 16;
}

if ((state & BUTTON_RIGHT)) {
asprite.velocity.x += 64;
asprite.velocity.x += 16;
} else if ((state & BUTTON_LEFT)) {
asprite.velocity.x += -64;
asprite.velocity.x += -16;
}
}
asprite.velocity.x = min(asprite.velocity.x, 256);
Expand Down Expand Up @@ -85,14 +85,14 @@ void terrain_coll(spritedef* sprt, u8 coll_dir) {

//sprt->direction += 128;
//sprt->force = 2;

}

void (*coll_callback)(spritedef* sprta, spritedef* sprtb) = &do_coll;
void (*t_coll_callback)(spritedef* sprt, u8 coll) = &terrain_coll;

int main() {

int i;
/*
*
* Init Blast
Expand Down Expand Up @@ -140,15 +140,14 @@ int main() {
asprite_idx = sprite_init(&asprite,terrain_tile_offset+7,1,256,256,1,1,PAL0);
lista[0] = asprite_idx;


bsprite_idx = sprite_init(&bsprite,terrain_tile_offset+7,1,256,220,1,1,PAL1);
/*
pow_idx = sprite_init(&pow,shot_offset,1,276,265,1,1,PAL0);
pow1_idx = sprite_init(&pow1,shot_offset,1,226,285,1,1,PAL0);
pow2_idx = sprite_init(&pow2,shot_offset,1,270,265,1,1,PAL0);
*/
asprite.inv_mass = FIX16(0.05);
bsprite.inv_mass = FIX16(0.25);
asprite.inv_mass = FIX16(0.5);
bsprite.inv_mass = FIX16(0.5);
//pow.inv_mass = FIX16(0.5);
//pow1.inv_mass = FIX16(0.2);
//pow2.inv_mass = FIX16(0.25);
Expand All @@ -159,40 +158,32 @@ int main() {

listc[0] = asprite_idx;
listc[1] = bsprite_idx;
listc[2] = pow_idx;
listc[3] = pow1_idx;
listc[4] = pow2_idx;
//listc[2] = pow_idx;
//listc[3] = pow1_idx;
//listc[4] = pow2_idx;



coly_idx = sprite_init(&coly,shot_offset,1,5,5,1,1,PAL0);
int i;
for(i=0;i<25;i++){
u8 x =
sprite_init(
&spr_list[i],
shot_offset,
//terrain_tile_offset+7,
1,
random() % 64 + 200,
random() % 64 + 200,
1,1,PAL0);
1,1,PAL2);
listd[i] = spr_list[i].idx;
spr_list[i].velocity.x = random()>>8;
spr_list[i].velocity.y = random()>>8;
spr_list[i].inv_mass = FIX16(0.5);
}


listd[25] = asprite_idx;
listd[26] = bsprite_idx;
for(i=0;i<32;i++){
VDP_showFPS(0);
center_screen(&arena_map, asprite_idx, &hs, &vs);
center_screen(&arena_map, asprite_idx, &hs, &vs);
center_screen(&arena_map, asprite_idx, &hs, &vs);
center_screen(&arena_map, asprite_idx, &hs, &vs);
//BLAST_updateSprites();
VDP_waitVSync();
}

//bsprite.direction = 160;
//bsprite.force = 16;
Expand All @@ -213,7 +204,17 @@ int main() {
pow2.velocity.y = -132;
*/

for(i=0;i<32;i++){
center_screen(&arena_map, asprite_idx, &hs, &vs);
center_screen(&arena_map, asprite_idx, &hs, &vs);
center_screen(&arena_map, asprite_idx, &hs, &vs);
center_screen(&arena_map, asprite_idx, &hs, &vs);
//BLAST_updateSprites();
VDP_waitVSync();
}

while(1) {
//center_screen(&arena_map, asprite_idx, &hs, &vs);

// Move player
myJoyHandler(JOY_1,0,JOY_readJoypad(JOY_1));
Expand All @@ -239,7 +240,7 @@ int main() {

//check_t_collision(listb, 1, &arena_map, t_coll_callback);
move_sprites(&arena_map, t_coll_callback);
//drag_sprites();
// drag_sprites();

//VDP_showFPS(0);
uintToStr(getFPS(), str, 1);
Expand Down
14 changes: 10 additions & 4 deletions incs/blast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
#include "gfx.h"
#include "tilemap.h"
#include "sprite.h"

#include "u8_stack.h"
#include "math_tables.h"

#ifndef _BLAST
#define _BLAST

typedef int bool;
#undef DEBUG
#undef ROWCHECK
#undef COLCHECK

//typedef int bool;
#define true 1
#define false 0

Expand All @@ -19,6 +24,7 @@ void wait_vsync();
u8 coll_col [40];
u8 coll_row [28];
u8 spr_coll;
u16 coll_vcnt;
u32 coll_row_mask;
blastmap* fore_map;
//u16 coll_vcnt;
//u32 coll_row_mask;
#endif
9 changes: 9 additions & 0 deletions incs/math_tables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _MATH_TABLES
#define _MATH_TABLES

const s8 sin_table[256];
const s8 cos_table[256];
const u8 atan_table[17];
const u8 sqrt_table[256];

#endif
38 changes: 30 additions & 8 deletions incs/sprite.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _SPRITE
#define _SPRITE

//#include "math_tables.h"
//#include "genesis.h"
//#include "blast.h"
//#include "tilemap.h"
Expand All @@ -10,7 +10,7 @@
#define MAX_SPRITE_COL 2
#define MAX_SPRITE_ROW 2

typedef int bool;
//typedef int bool;

typedef struct _vec2 {
s16 x;
Expand All @@ -23,6 +23,12 @@ typedef struct _AABB {
vec2 max;
} AABB;


typedef struct _BLAST_Circle {
u8 radius;
vec2 position;
} BLAST_Circle;

typedef struct _spritedef
{
// Position on plane?
Expand Down Expand Up @@ -52,12 +58,15 @@ typedef struct _spritedef
// Tile width & height
u8 tile_height;
u8 tile_width;
// virtual position
// virtual position in map
u16 vposx;
u16 vposy;
// VDP sprite list index
u8 idx;

// horizontal and vertical attrs
u8 h_attr;
u8 v_attr;

// Direction of motion
// 0 up
Expand All @@ -71,21 +80,32 @@ typedef struct _spritedef
//u8 col_group;


s8 x_vec;
s8 y_vec;

//s8 x_vec;
//s8 y_vec;

#ifdef COLCHECK
u8 columns[MAX_SPRITE_COL];
u32 column_mask;
#endif

#ifdef ROWCHECK
u32 row_mask;
u8 rows[MAX_SPRITE_ROW];
#endif

// Sprites axis aligned bounding box
AABB aabb;
fix16 inv_mass;
vec2 velocity;

// Remainder velocity:w
vec2 r_vel;

BLAST_Circle circle;
//u8* coll_list;

// Extra properties
void* properties;
} spritedef;

typedef struct _manifold {
Expand Down Expand Up @@ -136,9 +156,11 @@ void check_collision(u8* lista, u8 lista_len, u8* listb, u8 listb_len, void (*ca
void BLAST_updateSprites();
void BLAST_setSpriteP(u16 index, const spritedef *sprite);
void sprite_bounce(spritedef* sprt_a, spritedef* sprt_b, manifold* m);
bool get_manifold(spritedef* a, spritedef* b, manifold *m);
bool get_box_manifold(spritedef* a, spritedef* b, manifold *m);
bool get_circle_manifold(spritedef* a, spritedef* b, manifold *m);
void move_sprite(spritedef* sprt, blastmap* map, void (*callback)(spritedef* insprt, u8 coll));
void move_sprites(blastmap* map, void (*callback)(spritedef* sprt, u8 coll));
void drag_sprites();
void drag_sprites(u8 drag);
void flip_sprite(spritedef* sprt, u8 h, u8 v);

#endif
68 changes: 68 additions & 0 deletions incs/stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* generic-stack.h
* Declarations for a simple generic implementation of stacks.
*
* <insert MIT license>
*/

#ifdef TYPE

// +--------+--------------------------------------------------------
// | Macros |
// +--------+

/**
* By default, we do not rename procedures and structs.
*/
#ifndef TYPED
#define TYPED(THING) THING
#endif

#ifndef NULL
#define NULL 0
#endif
// +-------+---------------------------------------------------------
// | Types |
// +-------+

typedef struct TYPED(Stack) TYPED(Stack);

// +------------+----------------------------------------------------
// | Procedures |
// +------------+

/**
* Create a new stack.
*/
TYPED(Stack)* TYPED(stack_new) (void);

/**
* Free the space allocated to a stack.
*/
void TYPED(stack_free) (TYPED(Stack) *stack);

void TYPED(stack_to_list) (TYPED(Stack) *stack, TYPE* thislist);

/**
* Determine the number of elements in the stack.
*/
int TYPED(stack_size) (TYPED(Stack) *stack);

/**
* Look at the top element of the stack. Requires that the
* stack have at least one element.
*/
TYPE TYPED(stack_top) (TYPED(Stack) *stack);

/**
* Remove and return the top element of the stack. Requires that
* the stack have at least one element.
*/
TYPE TYPED(stack_pop) (TYPED(Stack) *stack);

/**
* Add an element to the stack.
*/
void TYPED(stack_push) (TYPED(Stack) *stack, TYPE val);

#endif // TYPE
Loading

0 comments on commit c17a0db

Please sign in to comment.