diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 98c72769..4d76ee82 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -875,7 +875,7 @@ static void level_cmd_puppylight_node(void) gPuppyLights[gNumLights]->yaw = CMD_GET(s16, 18); gPuppyLights[gNumLights]->epicentre = CMD_GET(u8, 20); - gPuppyLights[gNumLights]->flags |= CMD_GET(u8, 21); + gPuppyLights[gNumLights]->flags = CMD_GET(u8, 21); gPuppyLights[gNumLights]->active = TRUE; gPuppyLights[gNumLights]->area = sCurrAreaIndex; gPuppyLights[gNumLights]->room = CMD_GET(s16, 22); diff --git a/src/game/area.c b/src/game/area.c index ce9fefd3..3fc1518b 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -228,7 +228,7 @@ void load_area(s32 index) { if (gCurrentArea == NULL && gAreaData[index].unk04 != NULL) { gCurrentArea = &gAreaData[index]; gCurrAreaIndex = gCurrentArea->index; - + if (gCurrentArea->terrainData != NULL) { load_area_terrain(index, gCurrentArea->terrainData, gCurrentArea->surfaceRooms, gCurrentArea->macroObjects); @@ -239,7 +239,7 @@ void load_area(s32 index) { } load_obj_warp_nodes(); - geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_LOAD); + geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_LOAD); } } diff --git a/src/game/level_update.c b/src/game/level_update.c index 665d6a70..24308761 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -1001,6 +1001,9 @@ void update_hud_values(void) { void basic_update(UNUSED s16 *arg) { area_update_objects(); update_hud_values(); +#ifdef PUPPYLIGHTS + delete_lights(); +#endif if (gCurrentArea != NULL) { update_camera(gCurrentArea->camera); @@ -1028,6 +1031,9 @@ s32 play_mode_normal(void) { area_update_objects(); update_hud_values(); +#ifdef PUPPYLIGHTS + delete_lights(); +#endif if (gCurrentArea != NULL) { update_camera(gCurrentArea->camera); @@ -1203,7 +1209,6 @@ s32 update_level(void) { s32 init_level(void) { s32 val4 = 0; #if PUPPYPRINT_DEBUG - char textBytes[64]; OSTime first = osGetTime(); #endif @@ -1284,8 +1289,7 @@ s32 init_level(void) { #endif #if PUPPYPRINT_DEBUG - sprintf(textBytes, "Level loaded in %dus", (s32)(OS_CYCLES_TO_USEC(osGetTime() - first))); - append_puppyprint_log(textBytes); + append_puppyprint_log("Level loaded in %dus", (s32)(OS_CYCLES_TO_USEC(osGetTime() - first))); #endif return 1; } diff --git a/src/game/puppylights.c b/src/game/puppylights.c index 3b3537a5..9e513a92 100644 --- a/src/game/puppylights.c +++ b/src/game/puppylights.c @@ -27,6 +27,8 @@ of these automatically. It will force the PUPPYLIGHT_DYNAMIC flag, too. #include "debug_box.h" #include "object_list_processor.h" #include "level_update.h" +#include "engine/surface_collision.h" +#include "surface_terrains.h" #ifdef PUPPYLIGHTS @@ -55,8 +57,8 @@ void puppylights_allocate(void) gPuppyLights[gNumLights] = mem_pool_alloc(gLightsPool, sizeof(struct PuppyLight)); if (gPuppyLights[gNumLights] == NULL) return; - gPuppyLights[gNumLights]->flags = PUPPYLIGHT_DYNAMIC; gPuppyLights[gNumLights]->active = FALSE; + gPuppyLights[gNumLights]->flags = 0; gNumLights++; } } @@ -309,7 +311,7 @@ void cur_obj_disable_light(void) { gCurrentObject->oFlags &= ~OBJ_FLAG_EMIT_LIGHT; if (gPuppyLights[gCurrentObject->oLightID] && gCurrentObject->oLightID != 0xFFFF) - gPuppyLights[gCurrentObject->oLightID]->active = FALSE; + gPuppyLights[gCurrentObject->oLightID]->flags |= PUPPYLIGHT_DELETE; } void obj_enable_light(struct Object *obj) @@ -321,7 +323,28 @@ void obj_disable_light(struct Object *obj) { obj->oFlags &= ~OBJ_FLAG_EMIT_LIGHT; if (gPuppyLights[obj->oLightID] && obj->oLightID != 0xFFFF) - gPuppyLights[obj->oLightID]->active = FALSE; + gPuppyLights[obj->oLightID]->flags |= PUPPYLIGHT_DELETE; +} + +//This is ran during a standard area update +void delete_lights(void) +{ + s32 i; + + for (i = 0; i < gNumLights; i++) + { + if (gPuppyLights[i]->active == TRUE && gPuppyLights[i]->flags & PUPPYLIGHT_DELETE) + { + gPuppyLights[i]->pos[1][0] = approach_f32_asymptotic(gPuppyLights[i]->pos[1][0], 0, 0.15f); + gPuppyLights[i]->pos[1][1] = approach_f32_asymptotic(gPuppyLights[i]->pos[1][1], 0, 0.15f); + gPuppyLights[i]->pos[1][2] = approach_f32_asymptotic(gPuppyLights[i]->pos[1][2], 0, 0.15f); + if (gPuppyLights[i]->pos[1][0] < 1.0f && gPuppyLights[i]->pos[1][1] < 1.0f && gPuppyLights[i]->pos[1][2] < 1.0f) + { + gPuppyLights[i]->flags &= ~ PUPPYLIGHT_DELETE; + gPuppyLights[i]->active = FALSE; + } + } + } } #endif diff --git a/src/game/puppylights.h b/src/game/puppylights.h index cd09dce1..bf428b56 100644 --- a/src/game/puppylights.h +++ b/src/game/puppylights.h @@ -15,9 +15,9 @@ #define PUPPYLIGHT_SHAPE_CYLINDER 0x2 #define PUPPYLIGHT_DYNAMIC 0x4 #define PUPPYLIGHT_DIRECTIONAL 0x8 - -#define PUPPYLIGHT_FLAG_SHADOW 0x1 -#define PUPPYLIGHT_FLAG_WET 0x2 +#define PUPPYLIGHT_SHADOW 0x10 +#define PUPPYLIGHT_WET 0x20 +#define PUPPYLIGHT_DELETE 0x40 #define PUPPYLIGHT_ENVIRONMENT(ambientR, ambientG, ambientB, diffuseR, diffuseG, diffuseB, diffuseX, diffuseY, diffuseZ) \ CMD_BBBB(0x3F, 0x0C, ambientR, ambientG), \ @@ -48,6 +48,7 @@ extern void obj_enable_light(struct Object *obj); extern void obj_disable_light(struct Object *obj); extern void set_light_properties(struct PuppyLight *light, s32 x, s32 y, s32 z, s32 offsetX, s32 offsetY, s32 offsetZ, s32 yaw, s32 epicentre, s32 colour, s32 flags, s32 room, s32 active); extern void puppylights_allocate(void); +extern void delete_lights(void); #endif #endif diff --git a/src/game/puppyprint.c b/src/game/puppyprint.c index 1e15f53b..ee1e37b6 100644 --- a/src/game/puppyprint.c +++ b/src/game/puppyprint.c @@ -33,6 +33,8 @@ a modern game engine's developer's console. #include "print.h" #include "segment2.h" #include "string.h" +#include "stdarg.h" +#include "printf.h" #include "engine/math_util.h" #include "engine/behavior_script.h" #include "camera.h" @@ -309,14 +311,29 @@ void print_which_benchmark(void) char consoleLogTable[LOG_BUFFER_SIZE][255]; -void append_puppyprint_log(char str[255]) +static char *write_to_buf(char *buffer, const char *data, size_t size) { + return (char *) memcpy(buffer, data, size) + size; +} + +void append_puppyprint_log(const char *str, ...) { s32 i; + char textBytes[255]; + + memset(textBytes, 0, sizeof(textBytes)); + va_list arguments; + va_start(arguments, str); + if ((_Printf(write_to_buf, textBytes, str, arguments)) <= 0) + { + va_end(arguments); + return; + } for (i = 0; i < LOG_BUFFER_SIZE-1; i++) { memcpy(consoleLogTable[i], consoleLogTable[i+1], 255); } - memcpy(consoleLogTable[LOG_BUFFER_SIZE-1], str, 255); + memcpy(consoleLogTable[LOG_BUFFER_SIZE-1], textBytes, 255); + va_end(arguments); } #define LINE_HEIGHT 8 + ((LOG_BUFFER_SIZE-1)*12) diff --git a/src/game/puppyprint.h b/src/game/puppyprint.h index 3004ca3c..a563388d 100644 --- a/src/game/puppyprint.h +++ b/src/game/puppyprint.h @@ -67,7 +67,7 @@ extern s32 get_text_width(const char *str); extern void prepare_blank_box(void); extern void finish_blank_box(void); extern void render_blank_box(s16 x1, s16 y1, s16 x2, s16 y2, u8 r, u8 g, u8 b, u8 a); -extern void append_puppyprint_log(char str[255]); +extern void append_puppyprint_log(const char *str, ...); extern char consoleLogTable[LOG_BUFFER_SIZE][255]; #endif