Compare commits
5 Commits
96da001734
...
f7a429cfbc
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7a429cfbc | ||
![]() |
3c372a3024 | ||
![]() |
f65891932a | ||
![]() |
177d259304 | ||
![]() |
dbced43b2b |
2
k3ex.py
2
k3ex.py
@ -115,6 +115,8 @@ def write_some_data(context, filepath, doExportEverything):
|
||||
out.write(struct.pack("4f", m.col[c][0], m.col[c][1], m.col[c][2], m.col[c][3]))
|
||||
for b in dabones:
|
||||
out.write(struct.pack("B", dabones.index(b.parent) if b.parent else 255))
|
||||
for b in dabones:
|
||||
out.write(b.name.encode("UTF-8") + b'\x00')
|
||||
|
||||
for v in vertdict.keys():
|
||||
out.write(struct.pack("3f", v[0][0], v[0][2], -v[0][1]))
|
||||
|
11
src/game.c
11
src/game.c
@ -685,7 +685,7 @@ void game_update() {
|
||||
|
||||
size_t boneCount = Game.entities.render[ci].cache ? k3MdlGetBoneCount(Game.entities.render[ci].cache) : 0;
|
||||
if(boneCount) {
|
||||
struct CBoned *cb = game_getcomponent(Game.entities.render[ci].entity, boned);
|
||||
/*struct CBoned *cb = game_getcomponent(Game.entities.render[ci].entity, boned);
|
||||
|
||||
if(!cb) {
|
||||
cb = game_ensurecomponent(Game.entities.render[ci].entity, boned);
|
||||
@ -741,7 +741,7 @@ void game_update() {
|
||||
glm_decompose(cb->anim.cache.inter[m], cb->bones[m].translation, rot, scaleignore);
|
||||
glm_mat4_quat(cb->anim.cache.inter[m], cb->bones[m].rotation);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
dGeomID gid = cp->geom;
|
||||
@ -776,7 +776,7 @@ void game_update() {
|
||||
|
||||
for(size_t cm = 0; cm < Game.entities.movementCount; cm++) {
|
||||
struct CBoned *cb = game_getcomponent(Game.entities.movement[cm].entity, boned);
|
||||
if(cb && cb->anim.standard) {
|
||||
/*if(cb && cb->anim.standard) {
|
||||
struct CPhysics *cp = game_getcomponent(Game.entities.movement[cm].entity, physics);
|
||||
if(cp && cp->geom) {
|
||||
dBodyID bid = dGeomGetBody(cp->geom);
|
||||
@ -789,7 +789,7 @@ void game_update() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < Game.conveyorCount; i++) {
|
||||
@ -876,7 +876,6 @@ void game_update() {
|
||||
vec3 dif;
|
||||
glm_vec3_sub(conveyor->points[nextPoint], conveyor->points[currentPoint], dif);
|
||||
glm_vec3_scale_as(dif, conveyor->speed * (conveyor->active <= 0 ? -1 : 1), dif);
|
||||
//printf("set %f %f %f\n", dif[0], dif[1], dif[2]);
|
||||
dBodySetLinearVel(bid, dif[0], dif[1], dif[2]); // doesn't affect movement, but necessary for proper collision response
|
||||
}
|
||||
}
|
||||
@ -950,7 +949,7 @@ void game_cleanup() {
|
||||
Game.entities.renderCount = 0;
|
||||
|
||||
for(size_t i = 0; i < Game.entities.bonedCount; i++) {
|
||||
free(Game.entities.boned[i].bones);
|
||||
//free(Game.entities.boned[i].bones);
|
||||
}
|
||||
Game.entities.bonedCount = 0;
|
||||
|
||||
|
@ -118,14 +118,7 @@ struct CPlayerCtrl {
|
||||
struct CBoned {
|
||||
uint16_t entity;
|
||||
|
||||
size_t size;
|
||||
struct k3AnimationBone *bones;
|
||||
|
||||
struct {
|
||||
uint16_t id;
|
||||
struct k3Animator cache;
|
||||
bool standard;
|
||||
} anim;
|
||||
struct k3Animator animator;
|
||||
};
|
||||
|
||||
#define CONVEYOR_TYPE_LOOP 0
|
||||
|
@ -33,6 +33,17 @@ static int mdlloader(void *ud, struct ResManRes *res) {
|
||||
uint8_t *boneParents = malloc(header.boneCount);
|
||||
fread(boneParents, 1, header.boneCount, f);
|
||||
|
||||
char boneNames[1500] = {};
|
||||
size_t boneNamesLen = 0;
|
||||
for(size_t b = 0; b < header.boneCount; b++) {
|
||||
while(1) {
|
||||
fread(boneNames + boneNamesLen, 1, 1, f);
|
||||
if(boneNames[boneNamesLen++] == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec3 *pos = malloc(sizeof(*pos) * header.vertCount);
|
||||
fread(pos, sizeof(vec3), header.vertCount, f);
|
||||
|
||||
@ -59,6 +70,8 @@ static int mdlloader(void *ud, struct ResManRes *res) {
|
||||
|
||||
struct k3Mdl *mdl = k3MdlCreate(header.vertCount, header.indCount, header.boneCount, pos, nrm, uvs, cols, boneIDs, boneWeights, inds, invBind, boneParents);
|
||||
|
||||
k3MdlSetBoneNames(mdl, boneNames);
|
||||
|
||||
k3MdlSetDebugName(mdl, res->name);
|
||||
|
||||
free(pos);
|
||||
@ -87,22 +100,19 @@ static int mdlloader(void *ud, struct ResManRes *res) {
|
||||
for(size_t i = 0; i < header.animCount; i++) {
|
||||
struct {
|
||||
uint16_t id;
|
||||
uint16_t frames;
|
||||
uint16_t frameCount;
|
||||
uint16_t fps;
|
||||
uint16_t zero;
|
||||
} info;
|
||||
fread(&info, sizeof(info), 1, f);
|
||||
|
||||
struct k3Animation *anim = malloc(sizeof(*anim));
|
||||
anim->frames = _mm_malloc(sizeof(*anim->frames) * info.frames * header.boneCount, 16);
|
||||
anim->boneParents = boneParents;
|
||||
anim->invBind = invBind;
|
||||
struct k3AnimationFountain *anim = _mm_malloc(sizeof(*anim) + sizeof(*anim->frames) * info.frameCount * header.boneCount, 16);
|
||||
anim->id = info.id;
|
||||
anim->fps = info.fps;
|
||||
anim->frameCount = info.frames;
|
||||
anim->boneCount = header.boneCount;
|
||||
anim->frameCount = info.frameCount;
|
||||
anim->bones = header.boneCount;
|
||||
|
||||
fread(anim->frames, sizeof(*anim->frames), info.frames * header.boneCount, f);
|
||||
fread(anim->frames, sizeof(*anim->frames), info.frameCount * header.boneCount, f);
|
||||
|
||||
k3MdlAddAnim(mdl, anim);
|
||||
}
|
||||
@ -330,6 +340,8 @@ static int fontloader(void *ud, struct ResManRes *res) {
|
||||
}
|
||||
k3FontLoad(fnt, fntbuf, fntfsz, fnttexldr);
|
||||
|
||||
free(fntbuf);
|
||||
|
||||
res->thing = fnt;
|
||||
|
||||
return 1;
|
||||
|
952
src/luaapi.c
952
src/luaapi.c
File diff suppressed because it is too large
Load Diff
54
src/main.c
54
src/main.c
@ -41,6 +41,8 @@
|
||||
#include<ctype.h>
|
||||
|
||||
GLFWwindow *GameWnd;
|
||||
uint16_t GameWndW;
|
||||
uint16_t GameWndH;
|
||||
|
||||
static int TextureResolutionReduction = 0;
|
||||
|
||||
@ -70,9 +72,6 @@ static double xposold, yposold;
|
||||
static void buttoncallback(GLFWwindow *GameWnd, int button, int action, int mods) {
|
||||
if(button == GLFW_MOUSE_BUTTON_LEFT) {
|
||||
if(UiActive) {
|
||||
int ww, wh;
|
||||
glfwGetWindowSize(GameWnd, &ww, &wh);
|
||||
|
||||
struct k3MEvent ev = {
|
||||
.original = (void*) UiActive,
|
||||
.target = (void*) UiActive,
|
||||
@ -80,8 +79,8 @@ static void buttoncallback(GLFWwindow *GameWnd, int button, int action, int mods
|
||||
.code = action == GLFW_PRESS ? k3M_EVENT_MOUSE_PRESS : k3M_EVENT_MOUSE_RELEASE,
|
||||
.mouse = {
|
||||
.button = k3M_MOUSE_BUTTON_0,
|
||||
.x = xposold * UiActive->w / ww,
|
||||
.y = (wh - yposold - 1) * UiActive->h / wh,
|
||||
.x = xposold * UiActive->w / GameWndW,
|
||||
.y = yposold * UiActive->h / GameWndH,
|
||||
},
|
||||
};
|
||||
|
||||
@ -110,11 +109,8 @@ static void motioncallback(GLFWwindow *GameWnd, double xpos, double ypos) {
|
||||
first = 0;
|
||||
|
||||
if(UiActive) {
|
||||
int ww, wh;
|
||||
glfwGetWindowSize(GameWnd, &ww, &wh);
|
||||
|
||||
uint16_t uix = xposold * UiActive->w / ww;
|
||||
uint16_t uiy = (wh - yposold - 1) * UiActive->h / wh;
|
||||
uint16_t uix = xposold * UiActive->w / GameWndW;
|
||||
uint16_t uiy = yposold * UiActive->h / GameWndH;
|
||||
|
||||
struct k3MEvent ev = {
|
||||
.original = (void*) UiActive,
|
||||
@ -172,8 +168,16 @@ static void charcallback(GLFWwindow *window, unsigned int codepoint) {
|
||||
|
||||
static void fix_resol();
|
||||
static void resizecallback(GLFWwindow *window, int width, int height) {
|
||||
k3Resize(width, height);
|
||||
k3Resize(GameWndW = width, GameWndH = height);
|
||||
fix_resol();
|
||||
|
||||
if(UiActive) {
|
||||
UiActive->w = UiActive->wDesired = GameWndW;
|
||||
UiActive->h = UiActive->hDesired = GameWndH;
|
||||
|
||||
k3MMeasure(UiActive);
|
||||
k3MArrange(UiActive);
|
||||
}
|
||||
}
|
||||
|
||||
static int argc;
|
||||
@ -218,13 +222,16 @@ static int eng_init() {
|
||||
#define START_HEIGHT 540
|
||||
#define START_TITLE "k4"
|
||||
|
||||
GameWndW = START_WIDTH;
|
||||
GameWndH = START_HEIGHT;
|
||||
|
||||
// Prefer core
|
||||
if(!k4_get_arg("core") || strcmp(k4_get_arg("core"), "0")) {
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
GameWnd = glfwCreateWindow(START_WIDTH, START_HEIGHT, START_TITLE, NULL, NULL);
|
||||
GameWnd = glfwCreateWindow(GameWndW, GameWndH, START_TITLE, NULL, NULL);
|
||||
}
|
||||
|
||||
// Attempt compatibility
|
||||
@ -233,7 +240,7 @@ static int eng_init() {
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
GameWnd = glfwCreateWindow(START_WIDTH, START_HEIGHT, START_TITLE, NULL, NULL);
|
||||
GameWnd = glfwCreateWindow(GameWndW, GameWndH, START_TITLE, NULL, NULL);
|
||||
}
|
||||
|
||||
k3MixInit(44100, 2);
|
||||
@ -276,7 +283,9 @@ static int eng_init() {
|
||||
|
||||
k3SetLogCallback(k4k3LogCallback);
|
||||
|
||||
k3Init();
|
||||
k3Init(
|
||||
!k4_get_arg("tc") || strtol(k4_get_arg("tc"), NULL, 0) != 0,
|
||||
!k4_get_arg("mipmap") || strtol(k4_get_arg("mipmap"), NULL, 0) != 0);
|
||||
|
||||
k3BatchInit();
|
||||
|
||||
@ -433,6 +442,9 @@ int main(int argc_, char **argv_) {
|
||||
|
||||
net_hi_update(CurrentTime);
|
||||
|
||||
int windowW, windowH;
|
||||
glfwGetWindowSize(GameWnd, &windowW, &windowH);
|
||||
|
||||
float alpha = fmodf(accumulator * GAME_TPS, 1.f);
|
||||
|
||||
vec3 cameraForwardDir = {0, 0, -1};
|
||||
@ -590,7 +602,11 @@ int main(int argc_, char **argv_) {
|
||||
if(c->cache) {
|
||||
struct CBoned *b = game_getcomponent(c->entity, boned);
|
||||
|
||||
k3Batch(c->cache, transform, b ? b->bones : NULL);
|
||||
if(b && b->animator.anim) {
|
||||
k3AnimatorStep(&b->animator, dt);
|
||||
}
|
||||
|
||||
k3Batch(c->cache, transform, b ? b->animator.bones : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -640,13 +656,7 @@ int main(int argc_, char **argv_) {
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if(!k3IsCore) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 3600, 0, 2025, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
k3BatchSetResolution(windowW, windowH);
|
||||
|
||||
luaapi_render2d();
|
||||
|
||||
|
@ -114,7 +114,7 @@ static void interpret_pkt(ENetPacket *pkt) {
|
||||
c->holding = b_ru16(&b);
|
||||
} if(ctype == CMD_CTYPE_BONED) {
|
||||
struct CBoned *c = game_ensurecomponent(ent, boned);
|
||||
c->anim.standard = b_ru8(&b);
|
||||
/*c->anim.standard =*/ b_ru8(&b);
|
||||
}
|
||||
} else if(cmd == CMD_SC_POSUPDATE) {
|
||||
uint16_t lastOurTick = b_ru16(&b);
|
||||
|
@ -121,7 +121,7 @@ static void send_full_state(ENetPeer **peers, size_t peerCount) {
|
||||
|
||||
b_wu16(&b, c->entity);
|
||||
|
||||
b_wu8(&b, c->anim.standard);
|
||||
b_wu8(&b, 0/*c->anim.standard*/);
|
||||
}
|
||||
|
||||
if(peers) {
|
||||
|
Loading…
Reference in New Issue
Block a user