Skip to content

Commit

Permalink
Turret model in game
Browse files Browse the repository at this point in the history
  • Loading branch information
mwpenny committed Dec 31, 2024
1 parent e34d2e1 commit cdb150d
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 1 deletion.
6 changes: 6 additions & 0 deletions assets/materials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ endfunction()
# Add commands for generating materials
# There are some special cases for materials which use non-VPK textures

set_property(SOURCE static.skm.yaml
PROPERTY ADDITIONAL_DEPS
${PROJECT_SOURCE_DIR}/assets/images/turret1.png
${PROJECT_SOURCE_DIR}/assets/images/turret2.png
)

set_property(SOURCE hud.skm.yaml
PROPERTY ADDITIONAL_DEPS
${PROJECT_SOURCE_DIR}/assets/images/center_reticle.png
Expand Down
39 changes: 38 additions & 1 deletion assets/materials/objects.skm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,41 @@ materials:
gSPGeometryMode:
clear: [G_CULL_BACK]
gDPSetCombineMode:
color: ["0", "0", "0", "PRIMITIVE"]
color: ["0", "0", "0", "PRIMITIVE"]

turret1:
gDPSetTile:
filename: ../images/turret1.png
usePalette: ../images/turret1.png
fmt: G_IM_FMT_CI
siz: G_IM_SIZ_4b
palette: 0
tmem: 0
gSPTexture:
tile: 0

gDPSetCombineMode: G_CC_MODULATEI
gDPSetCycleType: G_CYC_1CYCLE

gSPGeometryMode:
set: [G_SHADE, G_CULL_BACK]
clear: [G_LIGHTING]

turret2:
gDPSetTile:
- null
- filename: ../images/turret2.png
usePalette: ../images/turret2.png
fmt: G_IM_FMT_CI
siz: G_IM_SIZ_4b
palette: 1
tmem: 128
gSPTexture:
tile: 1

gDPSetCombineMode: G_CC_MODULATEI
gDPSetCycleType: G_CYC_1CYCLE

gSPGeometryMode:
set: [G_SHADE, G_CULL_BACK]
clear: [G_LIGHTING]
25 changes: 25 additions & 0 deletions assets/materials/static.skm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ materials:
gDPSetRenderMode: G_RM_ZB_OPA_SURF
gDPSetTextureFilter: G_TF_BILERP
gDPSetTexturePersp: G_TP_PERSP
gDPSetTextureLUT: G_TT_NONE
gDPSetCycleType: G_CYC_1CYCLE
gDPSetAlphaCompare: G_AC_NONE
gSPGeometryMode:
Expand Down Expand Up @@ -1343,3 +1344,27 @@ materials:
transparent_portal_surface:
gSPGeometryMode:
set: [G_CULL_BACK, G_CULL_FRONT]

turret:
gDPSetTile:
- filename: ../images/turret1.png
usePalette: ../images/turret1.png
fmt: G_IM_FMT_CI
siz: G_IM_SIZ_4b
palette: 0
tmem: 0
- filename: ../images/turret2.png
usePalette: ../images/turret2.png
fmt: G_IM_FMT_CI
siz: G_IM_SIZ_4b
palette: 1
tmem: 128

gDPSetTextureLUT: G_TT_RGBA16

gDPSetCombineMode: G_CC_MODULATEI
gDPSetCycleType: G_CYC_1CYCLE

gSPGeometryMode:
set: [G_SHADE, G_CULL_BACK]
clear: [G_LIGHTING]
2 changes: 2 additions & 0 deletions assets/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ set(DYNAMIC_MODELS
props/radio
props/security_camera
props/switch001
props/turret_01
signage/clock
signage/clock_digits
)
Expand All @@ -72,6 +73,7 @@ set(KEYFRAMED_ANIMATED_MODELS
props/door_01
props/door_02
props/switch001
props/turret_01
)

# All animated models, including those which are only procedurally animated
Expand Down
Binary file modified assets/test_chambers/test_chamber_11/test_chamber_11.blend
Binary file not shown.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ target_sources(engine INTERFACE
scene/static_scene.c
scene/switch.c
scene/trigger_listener.c
scene/turret.c
sk64/skeletool_animator.c
sk64/skeletool_armature.c
strings/translations.c
Expand Down
8 changes: 8 additions & 0 deletions src/levels/level_definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ struct SecurityCameraDefinition {
short roomIndex;
};

struct TurretDefinition {
struct Vector3 position;
struct Quaternion rotation;
short roomIndex;
};

struct LevelDefinition {
struct CollisionObject* collisionQuads;
struct StaticContentElement* staticContent;
Expand Down Expand Up @@ -357,6 +363,7 @@ struct LevelDefinition {
struct BallCatcherDefinition* ballCatchers;
struct ClockDefinition* clocks;
struct SecurityCameraDefinition* securityCameras;
struct TurretDefinition* turrets;
short collisionQuadCount;
short staticContentCount;
short signalToStaticCount;
Expand All @@ -380,6 +387,7 @@ struct LevelDefinition {
short ballCatcherCount;
short clockCount;
short securityCameraCount;
short turretCount;
short startLocation;
short playerAnimatorIndex;
};
Expand Down
1 change: 1 addition & 0 deletions src/levels/levels.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct LevelDefinition* levelFixPointers(struct LevelDefinition* from, int point
result->ballCatchers = ADJUST_POINTER_POS(result->ballCatchers, pointerOffset);
result->clocks = ADJUST_POINTER_POS(result->clocks, pointerOffset);
result->securityCameras = ADJUST_POINTER_POS(result->securityCameras, pointerOffset);
result->turrets = ADJUST_POINTER_POS(result->turrets, pointerOffset);

result->animations = ADJUST_POINTER_POS(result->animations, pointerOffset);

Expand Down
10 changes: 10 additions & 0 deletions src/scene/scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ void sceneInitNoPauseMenu(struct Scene* scene, int mainMenuMode) {
securityCameraInit(&scene->securityCameras[i], &gCurrentLevel->securityCameras[i]);
}

scene->turretCount = gCurrentLevel->turretCount;
scene->turrets = malloc(sizeof(struct Turret) * scene->turretCount);
for (int i = 0; i < scene->turretCount; ++i) {
turretInit(&scene->turrets[i], &gCurrentLevel->turrets[i]);
}

scene->continuouslyAttemptingPortalOpen=0;
scene->boolCutsceneIsRunning=0;
scene->checkpointState = SceneCheckpointStateSaved;
Expand Down Expand Up @@ -648,6 +654,10 @@ void sceneUpdate(struct Scene* scene) {
securityCameraUpdate(&scene->securityCameras[i]);
}

for (int i = 0; i < scene->turretCount; ++i) {
turretUpdate(&scene->turrets[i]);
}

playerUpdate(&scene->player);
portalGunUpdate(&scene->portalGun, &scene->player);
sceneUpdateListeners(scene);
Expand Down
3 changes: 3 additions & 0 deletions src/scene/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "portal_gun.h"
#include "clock.h"
#include "security_camera.h"
#include "turret.h"
#include "trigger_listener.h"
#include "../effects/effects.h"

Expand Down Expand Up @@ -62,6 +63,7 @@ struct Scene {
struct BallCatcher* ballCatchers;
struct Clock* clocks;
struct SecurityCamera* securityCameras;
struct Turret* turrets;
struct SavedPortal savedPortal;
struct Effects effects;
struct Hud hud;
Expand All @@ -82,6 +84,7 @@ struct Scene {
u8 ballCatcherCount;
u8 clockCount;
u8 securityCameraCount;
u8 turretCount;
u8 boolCutsceneIsRunning;

u8 continuouslyAttemptingPortalOpen;
Expand Down
61 changes: 61 additions & 0 deletions src/scene/turret.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "turret.h"

#include "defs.h"
#include "scene/dynamic_scene.h"
#include "util/dynamic_asset_loader.h"

#include "codegen/assets/materials/static.h"
#include "codegen/assets/models/dynamic_animated_model_list.h"

void turretRender(void* data, struct DynamicRenderDataList* renderList, struct RenderState* renderState) {
struct Turret* turret = (struct Turret*)data;

Mtx* matrix = renderStateRequestMatrices(renderState, 1);

if (!matrix) {
return;
}

transformToMatrixL(&turret->rigidBody.transform, matrix, SCENE_SCALE);

Mtx* armature = renderStateRequestMatrices(renderState, turret->armature.numberOfBones);

if (!armature) {
return;
}

skCalculateTransforms(&turret->armature, armature);

dynamicRenderListAddDataTouchingPortal(
renderList,
turret->armature.displayList,
matrix,
TURRET_INDEX,
&turret->rigidBody.transform.position,
armature,
turret->rigidBody.flags
);
}

void turretInit(struct Turret* turret, struct TurretDefinition* definition) {
// TODO:
// * Physics (collidable and grabbable)
// * Fizzleable

struct SKArmatureWithAnimations* armature = dynamicAssetAnimatedModel(PROPS_TURRET_01_DYNAMIC_ANIMATED_MODEL);
skArmatureInit(&turret->armature, armature->armature);

turret->rigidBody.transform.position = definition->position;
turret->rigidBody.transform.rotation = definition->rotation;
turret->rigidBody.transform.scale = gOneVec;
turret->rigidBody.currentRoom = definition->roomIndex;

// TODO: radius
turret->dynamicId = dynamicSceneAdd(turret, turretRender, &turret->rigidBody.transform.position, 1.5f);

dynamicSceneSetRoomFlags(turret->dynamicId, ROOM_FLAG_FROM_INDEX(turret->rigidBody.currentRoom));
}

void turretUpdate(struct Turret* turret) {
// TODO
}
19 changes: 19 additions & 0 deletions src/scene/turret.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __TURRET_H__
#define __TURRET_H__

// #include "../physics/collision_object.h"
#include "levels/level_definition.h"
// #include "../sk64/skeletool_armature.h"

struct Turret {
//struct CollisionObject collisionObject;
struct RigidBody rigidBody;
struct SKArmature armature;
short dynamicId;
//float fizzleTime;
};

void turretInit(struct Turret* turret, struct TurretDefinition* definition);
void turretUpdate(struct Turret* turret);

#endif
17 changes: 17 additions & 0 deletions tools/level_scripts/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ end

sk_definition_writer.add_definition('security_cameras', 'struct SecurityCameraDefinition[]', '_geo', security_cameras)

local turrets = {}

for _, turret_element in pairs(sk_scene.nodes_for_type('@turret')) do
local position, rotation = turret_element.node.full_transformation:decompose()

local room_index = room_export.node_nearest_room_index(turret_element.node)

table.insert(turrets, {
position = position,
rotation = rotation * sk_math.axis_angle(sk_math.vector3(1, 0, 0), math.pi * 0.5),
roomIndex = room_index,
})
end

sk_definition_writer.add_definition('turrets', 'struct TurretDefinition[]', '_geo', turrets)

local function generate_static_collision_boxes()
local collision_boxes = {}

Expand Down Expand Up @@ -271,6 +287,7 @@ return {
ball_launchers = ball_launchers,
clocks = clocks,
security_cameras = security_cameras,
turrets = turrets,
},
static_collision_boxes = generate_static_collision_boxes(),
}
2 changes: 2 additions & 0 deletions tools/level_scripts/export_level.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ sk_definition_writer.add_definition("level", "struct LevelDefinition", "_geo", {
clockCount = #entities.entities.clocks,
securityCameras = sk_definition_writer.reference_to(entities.entities.security_cameras, 1),
securityCameraCount = #entities.entities.security_cameras,
turrets = sk_definition_writer.reference_to(entities.entities.turrets, 1),
turretCount = #entities.entities.turrets,
})

0 comments on commit cdb150d

Please sign in to comment.