Add physics

master
Marrub 2017-09-23 20:21:07 -04:00
parent af8b61e9a5
commit 4fee1465df
14 changed files with 131 additions and 61 deletions

14
.gitignore vendored
View File

@ -2,10 +2,10 @@ bin
doc
ir
src_crap
data/codedefs
data/fonts
data/maps
data/music
data/sounds
data/sprites
data/textures
data*/codedefs
data*/fonts
data*/maps
data*/music
data*/sounds
data*/sprites
data*/textures

View File

@ -3,15 +3,6 @@ GDCC_CC=gdcc-cc
GDCC_LD=gdcc-ld
GDCC_MAKELIB=gdcc-makelib
SRC=src
INC=inc
CODEDEFS=data/codedefs
BIN=bin
IR=ir
MAPSRC=maps
MAPBIN=data/maps
FOLDERS=$(CODEDEFS) $(BIN) $(IR) $(MAPBIN)
CFLAGS += -O2 -g -c
LFLAGS += -O2 -g -lm
@ -19,30 +10,45 @@ GDCC_TARGET=--bc-target=Doominati
GDCC_LFLAGS += $(GDCC_TARGET)
GDCC_CFLAGS += $(GDCC_TARGET) --alloc-Aut=4194304 -c
SRC=src
INC=inc
BIN=bin
IR=ir
MAPSRC=maps
DATA_MAIN=data
DATA_MFED=data_mfed
MAPBIN =$(DATA_MAIN)/maps
CODEDEFS =$(DATA_MAIN)/codedefs
CODEDEFS_MFED=$(DATA_MFED)/codedefs
FOLDERS=$(CODEDEFS) $(CODEDEFS_MFED) $(BIN) $(IR) $(MAPBIN)
define tgt_template =
$(1)_SOURCES=$(SRC)/$(2)
$(1)_OUTPUTS=$$($(1)_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
$(1)_BINARYS=$(3)
endef
define lib_template =
$(1)_SOURCES=$$(wildcard $(SRC)/$(2)*.c)
$(1)_HEADERS=$$(wildcard $(SRC)/$(2)*.h)
$(1)_OUTPUTS=$$($(1)_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
$(1)_BINARYS=$(CODEDEFS)/$(3)
endef
$(eval $(call tgt_template,MAIN,main.c,$(CODEDEFS)/eikyo-main.bin))
$(eval $(call tgt_template,MFED,mfed.c,$(CODEDEFS_MFED)/eikyo-mfed.bin))
$(eval $(call lib_template,GAME,g_,eikyo-game.bin))
$(eval $(call lib_template,RNDR,r_,eikyo-render.bin))
$(eval $(call lib_template,MISC,m_,eikyo-misc.bin))
MISC_LIBOUTS=$(MISC_SOURCES:$(SRC)/%.c=$(BIN)/%.o)
MAPS_SOURCES=$(wildcard $(MAPSRC)/*.gmf9)
MAPS_OUTPUTS=$(MAPS_SOURCES:$(MAPSRC)/%.gmf9=$(MAPBIN)/%.gmf0)
GAME_SOURCES=$(wildcard $(SRC)/g_*.c)
GAME_HEADERS=$(wildcard $(SRC)/g_*.h)
GAME_OUTPUTS=$(GAME_SOURCES:$(SRC)/g_%.c=$(IR)/g_%.ir)
GAME_BINARYS=$(CODEDEFS)/eikyo-game.bin
MAIN_SOURCES=$(SRC)/main.c
MAIN_OUTPUTS=$(MAIN_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
MAIN_BINARYS=$(CODEDEFS)/eikyo-main.bin
MISC_SOURCES=$(wildcard $(SRC)/m_*.c)
MISC_HEADERS=$(wildcard $(SRC)/m_*.h)
MISC_OUTPUTS=$(MISC_SOURCES:$(SRC)/m_%.c=$(IR)/m_%.ir)
MISC_BINARYS=$(CODEDEFS)/eikyo-misc.bin
MISC_LIBOUTS=$(MISC_SOURCES:$(SRC)/%.c=$(BIN)/%.o)
MISC_LIBRARY=$(BIN)/eikyo-misc.o
RNDR_SOURCES=$(wildcard $(SRC)/r_*.c)
RNDR_HEADERS=$(wildcard $(SRC)/r_*.h)
RNDR_OUTPUTS=$(RNDR_SOURCES:$(SRC)/r_%.c=$(IR)/r_%.ir)
RNDR_BINARYS=$(CODEDEFS)/eikyo-render.bin
GOL5_SOURCES=$(SRC)/golan5.c
GOL5_OUTPUTS=$(GOL5_SOURCES:$(SRC)/%.c=$(BIN)/%.o)
GOL5_BINARYS=$(BIN)/golan5
@ -53,11 +59,12 @@ LIBC_BINARYS=$(CODEDEFS)/stdlib.bin
.PHONY: clean
.SECONDARY: $(MISC_LIBOUTS)
all: $(FOLDERS) $(LIBC_BINARYS) $(GAME_BINARYS) $(MAIN_BINARYS) $(MISC_BINARYS) $(RNDR_BINARYS) $(MAPS_OUTPUTS)
all: $(FOLDERS) $(GAME_BINARYS) $(MAIN_BINARYS) $(MFED_BINARYS) $(MISC_BINARYS) $(RNDR_BINARYS) $(LIBC_BINARYS) $(MAPS_OUTPUTS)
$(GOL5_BINARYS): $(GOL5_OUTPUTS)
$(GAME_BINARYS): $(GAME_OUTPUTS)
$(GOL5_BINARYS): $(GOL5_OUTPUTS)
$(MAIN_BINARYS): $(MAIN_OUTPUTS)
$(MFED_BINARYS): $(MFED_OUTPUTS)
$(MISC_BINARYS): $(MISC_OUTPUTS)
$(RNDR_BINARYS): $(RNDR_OUTPUTS)
$(LIBC_BINARYS): $(LIBC_OUTPUTS)
@ -77,7 +84,7 @@ $(BIN)/%: $(MISC_LIBOUTS)
$(BIN)/%.o: $(SRC)/%.c $(MISC_HEADERS)
$(CC) $(CFLAGS) -o $@ $<
$(CODEDEFS)/%.bin:
%.bin:
$(GDCC_LD) $(GDCC_LFLAGS) -o $@ $^
$(IR)/%.ir: $(SRC)/%.c $(GAME_HEADERS) $(MISC_HEADERS) $(RNDR_HEADERS)

View File

@ -7,8 +7,10 @@ entity Shootable
entity Player < Shootable
{
task G_Player_Think
size 3
size 4
drawsize 16
friction 0.9
mass 1.15
sprite "ent/player"
}

View File

@ -2,7 +2,7 @@
font "base" = "fonts/base.ttf", 24pt
texture "gui/border" = "textures/Border.png"
texture "ent/player" = "sprites/Particle3.png"
texture "ent/player" = "sprites/Particle3_Pointer.png"
texture "box" = "textures/Box.png"
texture "empty" = "textures/Empty.png"

View File

@ -1,9 +1,9 @@
// Copyright © 2017 Project Golan, all rights reserved.
{0 Player -200 250}
{0 Sector -450 -330 510 660} // center
{0 Sector -450 -355 510 25} // top
{0 Sector -450 330 510 25} // bottom
{0 Sector -475 -355 25 710} // left
{0 Sector 60 -355 25 710} // right
{0 Sector -450 -330 510 660 0 64} // center
{0 Sector -450 -355 510 25 64 96} // top
{0 Sector -450 330 510 25 64 96} // bottom
{0 Sector -475 -355 25 710 64 96} // left
{0 Sector 60 -355 25 710 64 96} // right
// EOF

View File

@ -223,7 +223,7 @@ static G_odarg G_ObjDef_getArgs(G_dodst *st, char const *arg)
CaseN('u', u, strtoui, NULL, 0);
CaseN('i', i, strtoi, NULL, 0);
CaseN('k', k, strtofxhk, NULL);
CaseN('r', r, strtofxk, NULL);
CaseN('r', r, strtofxlk, NULL);
// TODO: get david to implement fracts
//CaseN('r', r, strtofxlr, NULL);
#undef CaseN
@ -277,10 +277,12 @@ static void G_ObjDef_getEntProp(G_dodst *st, G_entty *type, char const *id)
G_odarg a = st->getArgs("k|kk");
if(a.argc == 1) {
type->sx = type->sy = a.argv[0].k;
type->sz = 16;
} else {
type->sx = a.argv[0].k;
type->sy = a.argv[1].k;
if(a.argc > 2) type->sz = a.argv[2].k;
else type->sz = 16;
}
}
else if(strcmp(id, "drawsize") == 0)

View File

@ -5,6 +5,8 @@
#include <Doominati.h>
#include <stdio.h>
// Extern Functions ----------------------------------------------------------|
//
@ -33,8 +35,10 @@ void G_Sector_Create(G_mfdat *info)
DGE_Object_RefAdd(sec.id);
sec.friction = 0.875lr;
sec.gz = -1;
sec.friction = 0.9lr;
sec.gz = -3;
sec.zl = info->sec.f;
sec.zu = info->sec.c;
fixed xl = info->sec.x , yl = info->sec.y;
fixed xu = info->sec.w + xl, yu = info->sec.h + yl;

View File

@ -1,9 +1,31 @@
// Copyright © 2017 Project Golan, all rights reserved.
#define _GNU_SOURCE // Required for sincos(3). See feature_test_macros(7)
#include "g_object.h"
#include <Doominati.h>
#include <stdio.h>
#include <math.h>
// Static Functions ----------------------------------------------------------|
//
// G_Player_applyVelocity
//
void G_Player_applyVelocity(DGE_Entity ent)
{
accum vx = (accum)DGE_GetInputAxis(0, DGE_Axis_X);
accum vy = (accum)DGE_GetInputAxis(0, DGE_Axis_Y);
float mag = sqrtf(vx * vx + vy * vy);
float ang = atan2f(vy, vx);
float s, c;
sincosf(ang, &s, &c);
ent.vx = ent.vx + c * mag * 1.1;
ent.vy = ent.vy - s * mag * 1.1;
}
// Extern Functions ----------------------------------------------------------|
@ -20,8 +42,7 @@ void G_Player_Think(DGE_Entity ent)
if(ent.health <= 0)
break;
ent.vx = ent.vx + (fixed)DGE_GetInputAxis(0, DGE_Axis_X);
ent.vy = ent.vy - (fixed)DGE_GetInputAxis(0, DGE_Axis_Y);
G_Player_applyVelocity(ent);
DGE_Task_Sleep(0, 1);
}

View File

@ -22,12 +22,14 @@ char const *G_place = u8"地球軌道・朝";
//
static void G_Stage_readSector(FILE *fp, G_stage *s, hword *size, mword time)
{
*size -= 4 * 4;
*size -= 4 * 6;
G_mfsec sec;
sec.x = M_IO_ReadLE4k(fp);
sec.y = M_IO_ReadLE4k(fp);
sec.w = M_IO_ReadLE4k(fp);
sec.h = M_IO_ReadLE4k(fp);
sec.f = M_IO_ReadLE4k(fp);
sec.c = M_IO_ReadLE4k(fp);
M_Vec_grow(s->map, 1);
M_Vec_next(s->map) = (G_mfptr){time, {.sec = sec}, G_Sector_Create};
}
@ -74,14 +76,16 @@ G_stage G_Stage_LoadMap(char const *fname)
do {
mword time = M_IO_ReadLE4u(fp);
mbyte slen = fgetc(fp);
name = realloc(name, slen);
name = realloc(name, slen + 1);
fread(name, 1, slen, fp);
hword size = M_IO_ReadLE2u(fp);
if(time == 0 && slen == 0 && size == 0)
break;
if(M_membufcmp(name, "Sector") == 0 && size >= 4 * 4)
name[slen] = '\0';
if(strcmp(name, "Sector") == 0 && size >= 4 * 6)
G_Stage_readSector(fp, &s, &size, time);
else if(size >= 4 * 2)
G_Stage_readEntity(fp, &s, &size, time, name);

View File

@ -11,6 +11,7 @@ typedef struct G_mfsec
{
fixed x, y;
fixed w, h;
fixed f, c;
} G_mfsec;
typedef struct G_mfent

View File

@ -82,8 +82,8 @@ int main(int argc, char **argv)
// Write content size and content.
if(strcmp(tok->textV, "Sector") == 0) {
M_IO_WriteLE2u(out, 4 * 4);
for(int i = 0; i < 4; i++) WriteNum(out, &tb);
M_IO_WriteLE2u(out, 4 * 6);
for(int i = 0; i < 6; i++) WriteNum(out, &tb);
} else {
M_IO_WriteLE2u(out, 4 * 2);
for(int i = 0; i < 2; i++) WriteNum(out, &tb);

View File

@ -5,7 +5,6 @@
#include "m_types.h"
#define M_strbufcpy(a, b) (strncpy((a), (b), M_countof(a)))
#define M_membufcmp(a, b) (memcmp ((a), (b), M_countof(b)))
// Extern Functions ----------------------------------------------------------|

View File

@ -10,10 +10,9 @@
// Extern Functions ----------------------------------------------------------|
//
// main
// GInit
//
[[__extern("asm")]] DGE_Callback
void main(void)
void GInit(void)
{
extern void R_ResDec_Load(char const *fname);
@ -38,7 +37,15 @@ void main(void)
DGE_Callback_Register(DGE_CB_DrawPost, (DGE_CallbackType)R_DrawPost);
printf("Ready.\n");
}
//
// main
//
[[__extern("asm")]] DGE_Callback
void main(void)
{
GInit();
G_Stage_Begin(1);
}

23
src/mfed.c Normal file
View File

@ -0,0 +1,23 @@
// Copyright © 2017 Project Golan, all rights reserved.
#include "g_object.h"
#include "g_stage.h"
#include "r_draw.h"
#include <Doominati.h>
#include <stdio.h>
// Extern Functions ----------------------------------------------------------|
//
// main
//
[[__extern("asm")]] DGE_Callback
void main(void)
{
extern void GInit(void);
GInit();
printf("using mfed main\n");
}
// EOF