2023-10-06 23:33:39 -07:00
|
|
|
#if INTELLISENSE_DIRECTIVES
|
2023-09-26 14:26:35 -07:00
|
|
|
#include "engine.hpp"
|
2023-09-28 18:21:05 -07:00
|
|
|
#include "engine_to_platform_api.hpp"
|
2023-09-26 14:26:35 -07:00
|
|
|
#include "handmade.hpp"
|
2023-10-06 23:33:39 -07:00
|
|
|
#endif
|
2023-09-15 18:35:27 -07:00
|
|
|
|
|
|
|
NS_ENGINE_BEGIN
|
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
#define pressed( btn ) (btn.ended_down && btn.half_transitions > 0)
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
// Used to determine if analog input is at move threshold
|
2023-10-06 23:33:39 -07:00
|
|
|
constexpr f32 analog_move_threshold = 0.5f;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
struct EngineActions
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
b32 move_up;
|
|
|
|
b32 move_down;
|
|
|
|
b32 move_left;
|
|
|
|
b32 move_right;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
b32 loop_mode_engine;
|
|
|
|
b32 loop_mode_game;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
b32 raise_volume;
|
|
|
|
b32 lower_volume;
|
|
|
|
b32 raise_tone_hz;
|
|
|
|
b32 lower_tone_hz;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
b32 toggle_wave_tone;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-28 12:41:30 -07:00
|
|
|
#if Build_Development
|
2023-09-30 07:05:37 -07:00
|
|
|
b32 pause_renderer;
|
2023-09-30 12:40:27 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
b32 load_auto_snapshot;
|
2023-09-30 12:40:27 -07:00
|
|
|
b32 set_snapshot_slot_1;
|
|
|
|
b32 set_snapshot_slot_2;
|
|
|
|
b32 set_snapshot_slot_3;
|
|
|
|
b32 set_snapshot_slot_4;
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
b32 force_null_access_violation;
|
2023-09-28 12:41:30 -07:00
|
|
|
#endif
|
2023-09-28 10:44:43 -07:00
|
|
|
};
|
|
|
|
|
2023-09-18 17:16:40 -07:00
|
|
|
struct EngineState
|
|
|
|
{
|
2023-10-01 17:17:14 -07:00
|
|
|
f32 auto_snapshot_interval;
|
|
|
|
f32 auto_snapshot_timer;
|
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
s32 wave_tone_hz;
|
|
|
|
s32 tone_volume;
|
|
|
|
s32 x_offset;
|
|
|
|
s32 y_offset;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
b32 renderer_paused;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
f32 sample_wave_sine_time;
|
|
|
|
b32 sample_wave_switch;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
hh::Memory game_memory;
|
2023-09-18 17:16:40 -07:00
|
|
|
};
|
2023-09-16 15:41:07 -07:00
|
|
|
|
2023-10-06 23:33:39 -07:00
|
|
|
NS_ENGINE_END
|
2023-10-10 21:56:16 -07:00
|
|
|
|
2023-09-30 17:26:00 -07:00
|
|
|
#include "test_samples.cpp"
|
2023-09-18 17:16:40 -07:00
|
|
|
|
2023-09-30 12:40:27 -07:00
|
|
|
#if Build_Development
|
2023-10-10 21:56:16 -07:00
|
|
|
#include "state_and_replay.cpp"
|
2023-09-30 12:40:27 -07:00
|
|
|
// Build_Development
|
|
|
|
#endif
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
NS_ENGINE_BEGIN
|
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
internal
|
|
|
|
void input_poll_engine_actions( InputState* input, EngineActions* actions )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
ControllerState* controller = & input->controllers[0];
|
|
|
|
KeyboardState* keyboard = controller->keyboard;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
// actions->move_right |= keyboard->D.EndedDown;
|
|
|
|
// actions->move_left |= keyboard->A.EndedDown;
|
|
|
|
// actions->move_up |= keyboard->W.EndedDown;
|
|
|
|
// actions->move_down |= keyboard->S.EndedDown;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->raise_volume |= keyboard->up.ended_down;
|
|
|
|
actions->lower_volume |= keyboard->down.ended_down;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->raise_tone_hz |= keyboard->right.ended_down;
|
|
|
|
actions->lower_tone_hz |= keyboard->left.ended_down;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-28 12:41:30 -07:00
|
|
|
#if Build_Development
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->pause_renderer |= pressed( keyboard->pause );
|
2023-09-30 12:40:27 -07:00
|
|
|
|
|
|
|
actions->set_snapshot_slot_1 |= pressed( keyboard->_1 ) && keyboard->right_alt.ended_down;
|
|
|
|
actions->set_snapshot_slot_2 |= pressed( keyboard->_2 ) && keyboard->right_alt.ended_down;
|
|
|
|
actions->set_snapshot_slot_3 |= pressed( keyboard->_3 ) && keyboard->right_alt.ended_down;
|
|
|
|
actions->set_snapshot_slot_4 |= pressed( keyboard->_4 ) && keyboard->right_alt.ended_down;
|
2023-09-28 12:41:30 -07:00
|
|
|
#endif
|
2023-09-17 18:20:11 -07:00
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
actions->toggle_wave_tone |= pressed( keyboard->Q );
|
2023-09-24 19:37:05 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
actions->loop_mode_game |= pressed( keyboard->L ) && ! keyboard->right_shift.ended_down && ! keyboard->right_alt.ended_down;
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->loop_mode_engine |= pressed( keyboard->L ) && keyboard->right_shift.ended_down;
|
|
|
|
|
|
|
|
MousesState* mouse = controller->mouse;
|
|
|
|
|
|
|
|
actions->move_right = (mouse->horizontal_wheel.end > 0.f) * 20;
|
|
|
|
actions->move_left = (mouse->horizontal_wheel.end < 0.f) * 20;
|
|
|
|
|
|
|
|
actions->move_up = (mouse->vertical_wheel.end > 0.f) * 10;
|
|
|
|
actions->move_down = (mouse->vertical_wheel.end < 0.f) * 10;
|
2023-09-30 12:40:27 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
actions->load_auto_snapshot |= pressed( keyboard->L ) && keyboard->right_alt.ended_down;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
internal
|
2023-09-30 07:05:37 -07:00
|
|
|
void input_poll_player_actions( InputState* input, hh::PlayerActions* actions )
|
2023-09-28 10:44:43 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
ControllerState* controller = & input->controllers[0];
|
2023-09-24 19:37:05 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( controller->ds_pad )
|
2023-09-17 18:20:11 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
DualsensePadState* pad = controller->ds_pad;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->jump |= pressed( pad->cross );
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->player_x_move_analog += pad->stick.left.X.end;
|
|
|
|
actions->player_y_move_analog += pad->stick.left.Y.end;
|
2023-09-17 18:20:11 -07:00
|
|
|
}
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( controller->xpad )
|
2023-09-17 18:20:11 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
XInputPadState* pad = controller->xpad;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
actions->jump |= pressed( pad->A );
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->player_x_move_analog += pad->stick.left.X.end;
|
|
|
|
actions->player_y_move_analog += pad->stick.left.Y.end;
|
2023-09-17 18:20:11 -07:00
|
|
|
}
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( controller->keyboard )
|
2023-09-20 21:26:23 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
KeyboardState* keyboard = controller->keyboard;
|
|
|
|
actions->jump |= pressed( keyboard->space );
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
actions->player_x_move_digital += keyboard->D.ended_down - keyboard->A.ended_down;
|
|
|
|
actions->player_y_move_digital += keyboard->W.ended_down - keyboard->S.ended_down;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( controller->mouse )
|
|
|
|
{
|
|
|
|
MousesState* mouse = controller->mouse;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-30 17:26:00 -07:00
|
|
|
internal void
|
|
|
|
output_sound( EngineState* state, AudioBuffer* sound_buffer, GetSoundSampleValueFn* get_sample_value )
|
|
|
|
{
|
|
|
|
s16* sample_out = sound_buffer->samples;
|
|
|
|
for ( s32 sample_index = 0; sample_index < sound_buffer->num_samples; ++ sample_index )
|
|
|
|
{
|
|
|
|
s16 sample_value = get_sample_value( state, sound_buffer );
|
|
|
|
sound_buffer->running_sample_index++;
|
|
|
|
|
|
|
|
// char ms_timing_debug[256] {};
|
|
|
|
// wsprintfA( ms_timing_debug, "sample_value: %d\n", sample_value );
|
|
|
|
// d ms_timing_debug );
|
|
|
|
|
|
|
|
*sample_out = sample_value;
|
|
|
|
++ sample_out;
|
|
|
|
|
|
|
|
*sample_out = sample_value;
|
|
|
|
++ sample_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
void draw_rectangle( OffscreenBuffer* buffer
|
|
|
|
, f32 min_x, f32 min_y
|
|
|
|
, f32 max_x, f32 max_y
|
|
|
|
, f32 red, f32 green, f32 blue )
|
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
s32 min_x_32 = round( min_x );
|
|
|
|
s32 min_y_32 = round( min_y );
|
|
|
|
s32 max_x_32 = round( max_x );
|
|
|
|
s32 max_y_32 = round( max_y );
|
2023-09-30 17:26:00 -07:00
|
|
|
|
|
|
|
s32 buffer_width = buffer->width;
|
|
|
|
s32 buffer_height = buffer->height;
|
|
|
|
|
|
|
|
if ( min_x_32 < 0 )
|
|
|
|
min_x_32 = 0;
|
|
|
|
if ( min_y_32 < 0 )
|
|
|
|
min_y_32 = 0;
|
|
|
|
if ( max_x_32 > buffer_width )
|
|
|
|
max_x_32 = buffer_width;
|
|
|
|
if ( max_y_32 > buffer_height )
|
|
|
|
max_y_32 = buffer_height;
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
s32 red_32 = round( 255.f * red );
|
|
|
|
s32 green_32 = round( 255.f * green );
|
|
|
|
s32 blue_32 = round( 255.f * blue );
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
s32 color =
|
|
|
|
(scast(s32, red_32) << 16)
|
|
|
|
| (scast(s32, green_32) << 8)
|
|
|
|
| (scast(s32, blue_32) << 0);
|
2023-09-30 17:26:00 -07:00
|
|
|
|
|
|
|
// Start with the pixel on the top left corner of the rectangle
|
|
|
|
u8* row = rcast(u8*, buffer->memory )
|
|
|
|
+ min_x_32 * buffer->bytes_per_pixel
|
|
|
|
+ min_y_32 * buffer->pitch;
|
|
|
|
|
|
|
|
for ( s32 y = min_y_32; y < max_y_32; ++ y )
|
|
|
|
{
|
|
|
|
s32* pixel_32 = rcast(s32*, row);
|
|
|
|
|
|
|
|
for ( s32 x = min_x_32; x < max_x_32; ++ x )
|
|
|
|
{
|
|
|
|
*pixel_32 = color;
|
|
|
|
pixel_32++;
|
|
|
|
}
|
|
|
|
row += buffer->pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
inline
|
|
|
|
void cannonicalize_coord( World* world, u32* tile_coord, f32* pos_coord )
|
|
|
|
{
|
|
|
|
f32 tile_size = scast(f32, world->tile_size_in_meters);
|
|
|
|
|
|
|
|
// Note(Ed) : World is assumed to be a "torodial topology"
|
|
|
|
s32 offset = floor( (* pos_coord) / tile_size );
|
|
|
|
u32 new_tile_coord = (* tile_coord) + offset;
|
|
|
|
f32 new_pos_coord = (* pos_coord) - scast(f32, offset) * tile_size;
|
|
|
|
|
|
|
|
assert( new_pos_coord >= 0 );
|
|
|
|
assert( new_pos_coord <= tile_size );
|
|
|
|
|
|
|
|
(* tile_coord) = new_tile_coord;
|
|
|
|
(* pos_coord) = new_pos_coord;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
WorldPosition recannonicalize_position( World* world, WorldPosition pos )
|
|
|
|
{
|
|
|
|
WorldPosition result = pos;
|
|
|
|
cannonicalize_coord( world, & result.tile_x, & result.x );
|
|
|
|
cannonicalize_coord( world, & result.tile_y, & result.y );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
u32 TileChunk_tile_value( TileChunk* tile_chunk, World* world, u32 x, u32 y )
|
|
|
|
{
|
|
|
|
assert( world != nullptr );
|
|
|
|
assert( tile_chunk != nullptr );
|
|
|
|
assert( x < world->chunk_dimension );
|
|
|
|
assert( y < world->chunk_dimension );
|
|
|
|
|
|
|
|
u32 value = tile_chunk->tiles[ (y * world->chunk_dimension) + x ];
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(Ed) : Review if this is needed anymore?
|
|
|
|
#if 0
|
|
|
|
inline
|
|
|
|
b32 TileChunk_is_tile_empty( TileChunk* tile_chunk, World* world, u32 tile_x, u32 tile_y )
|
|
|
|
{
|
|
|
|
//assert( tile_chunk != nullptr );
|
|
|
|
assert( world != nullptr );
|
|
|
|
|
|
|
|
// Assume space is occupied if there is bad data
|
|
|
|
if ( tile_chunk == nullptr )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
b32 is_empty = false;
|
|
|
|
u32 tile_value = TileChunk_tile_value( tile_chunk, world, tile_x, tile_y );
|
|
|
|
is_empty = tile_value == 0;
|
|
|
|
return is_empty;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline
|
|
|
|
TileChunk* World_get_tile_chunk( World* world, s32 tile_chunk_x, s32 tile_chunk_y )
|
|
|
|
{
|
|
|
|
TileChunk* chunk = nullptr;
|
|
|
|
|
|
|
|
if ( tile_chunk_x >= 0 && tile_chunk_x < scast(s32, world->tile_chunks_num_x)
|
|
|
|
&& tile_chunk_y >= 0 && tile_chunk_y < scast(s32, world->tile_chunks_num_y) )
|
|
|
|
{
|
|
|
|
chunk = & world->tile_chunks[ tile_chunk_y * world->tile_chunks_num_x + tile_chunk_x ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
TileChunkPosition get_tile_chunk_position_for( World* world, u32 abs_tile_x, u32 abs_tile_y )
|
|
|
|
{
|
|
|
|
TileChunkPosition chunk_pos {};
|
|
|
|
chunk_pos.tile_chunk_x = abs_tile_x >> world->chunk_shift;
|
|
|
|
chunk_pos.tile_chunk_y = abs_tile_y >> world->chunk_shift;
|
|
|
|
chunk_pos.tile_x = abs_tile_x & world->chunk_mask;
|
|
|
|
chunk_pos.tile_y = abs_tile_y & world->chunk_mask;
|
|
|
|
|
|
|
|
return chunk_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal // TODO(Ed) : Review if he keeps this crap.
|
|
|
|
u32 piggy_get_tile_value( World* world, u32 tile_x, u32 tile_y )
|
|
|
|
{
|
|
|
|
assert( world != nullptr );
|
|
|
|
|
|
|
|
u32 value = 0;
|
|
|
|
|
|
|
|
TileChunkPosition chunk_pos = get_tile_chunk_position_for( world, tile_x, tile_y );
|
|
|
|
TileChunk* chunk = World_get_tile_chunk( world, chunk_pos.tile_chunk_x, chunk_pos.tile_chunk_y );
|
|
|
|
|
|
|
|
if ( chunk )
|
|
|
|
value = TileChunk_tile_value( chunk, world, chunk_pos.tile_x, chunk_pos.tile_y );
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
b32 world_is_point_empty( World* world, WorldPosition position )
|
|
|
|
{
|
|
|
|
assert( world != nullptr );
|
|
|
|
|
|
|
|
u32 chunk_value = piggy_get_tile_value( world, position.tile_x, position.tile_y );
|
|
|
|
b32 is_empty = chunk_value == 0;
|
|
|
|
return is_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void draw_debug_point(OffscreenBuffer* back_buffer, World* world, WorldPosition pos, f32 red, f32 green, f32 blue)
|
|
|
|
{
|
|
|
|
draw_rectangle(back_buffer,
|
|
|
|
pos.x * world->tile_meters_to_pixels + world->tile_lower_left_x + scast(f32, pos.tile_x * world->tile_size_in_pixels),
|
|
|
|
pos.y * world->tile_meters_to_pixels + world->tile_lower_left_y + scast(f32, pos.tile_y * world->tile_size_in_pixels),
|
|
|
|
(pos.x + 0.1f) * world->tile_meters_to_pixels + world->tile_lower_left_x + scast(f32, pos.tile_x * world->tile_size_in_pixels),
|
|
|
|
(pos.y + 0.1f) * world->tile_meters_to_pixels + world->tile_lower_left_y + scast(f32, pos.tile_y * world->tile_size_in_pixels),
|
|
|
|
red, green, blue);
|
|
|
|
}
|
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
Engine_API
|
|
|
|
void on_module_reload( Memory* memory, platform::ModuleAPI* platfom_api )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Engine_API
|
|
|
|
void startup( Memory* memory, platform::ModuleAPI* platform_api )
|
|
|
|
{
|
2023-09-30 12:40:27 -07:00
|
|
|
#if Build_Development
|
|
|
|
memory->active_snapshot_slot = 1;
|
|
|
|
memory->replay_mode = ReplayMode_Off;
|
|
|
|
memory->active_input_replay_file = {};
|
|
|
|
memory->engine_loop_active = false;
|
|
|
|
memory->game_loop_active = false;
|
|
|
|
#endif
|
2023-09-30 07:05:37 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
#if 0
|
2023-09-30 07:05:37 -07:00
|
|
|
for ( s32 slot = 0; slot < memory->Num_Snapshot_Slots; ++ slot )
|
|
|
|
{
|
|
|
|
// TODO(Ed) : Specify default file paths for saving slots ?
|
|
|
|
}
|
2023-10-01 17:17:14 -07:00
|
|
|
#endif
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
EngineState* state = rcast( EngineState*, memory->persistent );
|
|
|
|
assert( sizeof(EngineState) <= memory->persistent_size );
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
state->auto_snapshot_interval = 60.f;
|
2023-10-01 17:17:14 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
state->tone_volume = 1000;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
state->x_offset = 0;
|
|
|
|
state->y_offset = 0;
|
2023-09-24 19:37:05 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
state->sample_wave_switch = false;
|
|
|
|
state->wave_tone_hz = 60;
|
|
|
|
state->sample_wave_sine_time = 0.f;
|
2023-09-22 12:13:18 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
state->renderer_paused = false;
|
|
|
|
state->game_memory.persistent_size = memory->persistent_size / 2;
|
|
|
|
state->game_memory.persistent = rcast(Byte*, memory->persistent) + state->game_memory.persistent_size;
|
|
|
|
state->game_memory.transient_size = memory->transient_size / 2;
|
|
|
|
state->game_memory.transient = rcast(Byte*, memory->transient) + state->game_memory.transient_size;
|
2023-09-20 21:26:23 -07:00
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
hh::GameState* game_state = rcast( hh::GameState*, state->game_memory.persistent );
|
|
|
|
assert( sizeof(hh::GameState) <= state->game_memory.persistent_size );
|
|
|
|
|
|
|
|
hh::PlayerState* player = & game_state->player_state;
|
2023-10-10 10:08:08 -07:00
|
|
|
player->position.tile_x = 3;
|
|
|
|
player->position.tile_y = 3;
|
|
|
|
player->position.x = 0.f;
|
|
|
|
player->position.y = 0.f;
|
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
player->mid_jump = false;
|
|
|
|
player->jump_time = 0.f;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Engine_API
|
|
|
|
void shutdown( Memory* memory, platform::ModuleAPI* platform_api )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Engine_API
|
2023-10-04 10:55:15 -07:00
|
|
|
void update_and_render( f32 delta_time, InputState* input, OffscreenBuffer* back_buffer
|
|
|
|
, Memory* memory, platform::ModuleAPI* platform_api, ThreadContext* thread )
|
2023-09-28 10:44:43 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
EngineState* state = rcast( EngineState*, memory->persistent );
|
|
|
|
assert( sizeof(EngineState) <= memory->persistent_size );
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
// Engine auto_snapshot
|
|
|
|
{
|
|
|
|
state->auto_snapshot_timer += delta_time;
|
|
|
|
if ( state->auto_snapshot_timer >= state->auto_snapshot_interval )
|
|
|
|
{
|
|
|
|
state->auto_snapshot_timer = 0.f;
|
|
|
|
|
|
|
|
s32 current_slot = memory->active_snapshot_slot;
|
|
|
|
memory->active_snapshot_slot = 0;
|
|
|
|
|
|
|
|
take_engine_snapshot( memory, platform_api );
|
|
|
|
memory->active_snapshot_slot = current_slot;
|
|
|
|
state->auto_snapshot_timer = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
ControllerState* controller = & input->controllers[0];
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
EngineActions engine_actions {};
|
|
|
|
hh::PlayerActions player_actions {};
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
input_poll_engine_actions( input, & engine_actions );
|
2023-09-30 07:05:37 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
if ( engine_actions.load_auto_snapshot )
|
|
|
|
{
|
|
|
|
s32 current_slot = memory->active_snapshot_slot;
|
|
|
|
memory->active_snapshot_slot = 0;
|
|
|
|
load_engine_snapshot( memory, platform_api );
|
|
|
|
memory->active_snapshot_slot = current_slot;
|
|
|
|
}
|
|
|
|
|
2023-09-30 12:40:27 -07:00
|
|
|
#if Build_Development
|
2023-09-30 07:05:37 -07:00
|
|
|
// Ease of use: Allow user to press L key without shift if engine loop recording is active.
|
|
|
|
engine_actions.loop_mode_engine |= engine_actions.loop_mode_game && memory->engine_loop_active;
|
|
|
|
|
|
|
|
if ( engine_actions.loop_mode_engine && ! memory->game_loop_active )
|
|
|
|
{
|
|
|
|
process_loop_mode( & take_engine_snapshot, & load_engine_snapshot, memory, state, input, platform_api );
|
2023-09-30 12:40:27 -07:00
|
|
|
memory->engine_loop_active = memory->replay_mode > ReplayMode_Off;
|
2023-09-30 07:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Input recording and playback for engine state
|
|
|
|
if ( memory->engine_loop_active )
|
|
|
|
{
|
2023-09-30 12:40:27 -07:00
|
|
|
if ( memory->replay_mode == ReplayMode_Record )
|
2023-09-30 07:05:37 -07:00
|
|
|
{
|
|
|
|
record_input( memory, input, platform_api );
|
|
|
|
}
|
2023-09-30 12:40:27 -07:00
|
|
|
if ( memory->replay_mode == ReplayMode_Playback )
|
2023-09-30 07:05:37 -07:00
|
|
|
{
|
|
|
|
play_input( & load_engine_snapshot, memory, input, platform_api );
|
|
|
|
}
|
|
|
|
}
|
2023-09-30 12:40:27 -07:00
|
|
|
#endif
|
2023-09-30 07:05:37 -07:00
|
|
|
|
|
|
|
// Process Engine Actions
|
2023-09-21 23:16:40 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
state->x_offset += 3 * engine_actions.move_right;
|
|
|
|
state->x_offset -= 3 * engine_actions.move_left;
|
|
|
|
state->y_offset += 3 * engine_actions.move_down;
|
|
|
|
state->y_offset -= 3 * engine_actions.move_up;
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
if ( engine_actions.raise_volume )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
state->tone_volume += 10;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
if ( engine_actions.lower_volume )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
state->tone_volume -= 10;
|
|
|
|
if ( state->tone_volume <= 0 )
|
|
|
|
state->tone_volume = 0;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( engine_actions.raise_tone_hz )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
state->wave_tone_hz += 1;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
if ( engine_actions.lower_tone_hz )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
state->wave_tone_hz -= 1;
|
|
|
|
if ( state->wave_tone_hz <= 0 )
|
|
|
|
state->wave_tone_hz = 1;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( engine_actions.toggle_wave_tone )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
state->sample_wave_switch ^= true;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( engine_actions.loop_mode_game && ! memory->engine_loop_active )
|
2023-09-28 10:44:43 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
process_loop_mode( & take_game_snapshot, & load_game_snapshot, memory, state, input, platform_api );
|
2023-09-30 12:40:27 -07:00
|
|
|
memory->game_loop_active = memory->replay_mode > ReplayMode_Off;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
|
2023-09-28 12:41:30 -07:00
|
|
|
#if Build_Development
|
2023-09-28 10:44:43 -07:00
|
|
|
if ( engine_actions.pause_renderer )
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( state->renderer_paused )
|
2023-09-28 10:44:43 -07:00
|
|
|
{
|
|
|
|
platform_api->debug_set_pause_rendering(false);
|
2023-09-30 07:05:37 -07:00
|
|
|
state->renderer_paused = false;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
platform_api->debug_set_pause_rendering(true);
|
2023-09-30 07:05:37 -07:00
|
|
|
state->renderer_paused = true;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
}
|
2023-09-30 12:40:27 -07:00
|
|
|
|
|
|
|
if ( ! memory->game_loop_active )
|
|
|
|
{
|
2023-10-01 17:17:14 -07:00
|
|
|
if ( engine_actions.set_snapshot_slot_1 ) memory->active_snapshot_slot = 1;
|
|
|
|
if ( engine_actions.set_snapshot_slot_2 ) memory->active_snapshot_slot = 2;
|
2023-09-30 12:40:27 -07:00
|
|
|
}
|
2023-09-28 12:41:30 -07:00
|
|
|
#endif
|
2023-09-21 23:16:40 -07:00
|
|
|
}
|
2023-09-20 21:26:23 -07:00
|
|
|
|
2023-09-30 12:40:27 -07:00
|
|
|
#if Build_Development
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( ! memory->engine_loop_active )
|
2023-09-21 23:16:40 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
// Input recording and playback for game state
|
2023-09-30 12:40:27 -07:00
|
|
|
if ( memory->replay_mode == ReplayMode_Record )
|
2023-09-30 07:05:37 -07:00
|
|
|
{
|
|
|
|
record_input( memory, input, platform_api );
|
|
|
|
}
|
2023-09-30 12:40:27 -07:00
|
|
|
if ( memory->replay_mode == ReplayMode_Playback )
|
2023-09-30 07:05:37 -07:00
|
|
|
{
|
|
|
|
play_input( & load_game_snapshot, memory, input, platform_api );
|
|
|
|
}
|
2023-09-21 23:16:40 -07:00
|
|
|
}
|
2023-09-30 12:40:27 -07:00
|
|
|
#endif
|
2023-09-20 21:26:23 -07:00
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
hh::GameState* game_state = rcast( hh::GameState*, state->game_memory.persistent );
|
|
|
|
hh::PlayerState* player = & game_state->player_state;
|
2023-10-04 10:55:15 -07:00
|
|
|
|
|
|
|
f32 x_offset_f = scast(f32, state->x_offset);
|
|
|
|
f32 y_offset_f = scast(f32, state->y_offset);
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
constexpr s32 tile_map_num_x = 256;
|
|
|
|
constexpr s32 tile_map_num_y = 256;
|
2023-10-04 10:55:15 -07:00
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
// tiles_XY
|
2023-10-10 21:56:16 -07:00
|
|
|
u32 temp_tiles [tile_map_num_y][tile_map_num_x] = {
|
|
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
|
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
|
|
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
2023-10-04 10:55:15 -07:00
|
|
|
};
|
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
World world;
|
2023-10-10 21:56:16 -07:00
|
|
|
world.chunk_shift = 8;
|
|
|
|
world.chunk_mask = (1 << world.chunk_shift) - 1;
|
|
|
|
world.chunk_dimension = 256;
|
2023-10-10 10:08:08 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
world.tile_chunks_num_x = 1;
|
|
|
|
world.tile_chunks_num_y = 1;
|
2023-10-10 10:08:08 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
TileChunk temp_chunk;
|
|
|
|
temp_chunk.tiles = rcast( u32*, & temp_tiles );
|
|
|
|
world.tile_chunks = & temp_chunk;
|
2023-10-04 10:55:15 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
world.tile_size_in_meters = 1.4f;
|
|
|
|
world.tile_size_in_pixels = 85;
|
|
|
|
world.tile_meters_to_pixels = scast(f32, world.tile_size_in_pixels) / world.tile_size_in_meters;
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
f32 tile_size_in_pixels = scast(f32, world.tile_size_in_pixels);
|
2023-10-04 10:55:15 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
f32 scale = 85;
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
world.tile_lower_left_x = -( tile_size_in_pixels * 0.5f);
|
|
|
|
world.tile_lower_left_y = +( tile_size_in_pixels * 0.25f) + scast(f32, back_buffer->height);
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 10:08:08 -07:00
|
|
|
player->height = 1.4f;
|
|
|
|
player->width = player->height * 0.7f;
|
2023-10-06 10:06:40 -07:00
|
|
|
|
|
|
|
f32 player_half_width = player->width / 2.f;
|
|
|
|
f32 player_quarter_height = player->height / 4.f;
|
2023-10-04 10:55:15 -07:00
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
input_poll_player_actions( input, & player_actions );
|
2023-09-24 19:37:05 -07:00
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
f32 move_speed = 4.f;
|
2023-10-01 17:17:14 -07:00
|
|
|
|
2023-10-10 10:08:08 -07:00
|
|
|
f32 new_player_pos_x = player->position.x;
|
|
|
|
f32 new_player_pos_y = player->position.y;
|
2023-10-04 10:55:15 -07:00
|
|
|
if ( player_actions.player_x_move_analog || player_actions.player_y_move_analog )
|
|
|
|
{
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x += scast(f32, player_actions.player_x_move_analog * delta_time * move_speed);
|
2023-10-10 21:56:16 -07:00
|
|
|
new_player_pos_y += scast(f32, player_actions.player_y_move_analog * delta_time * move_speed);
|
2023-10-04 10:55:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_player_pos_x += scast(f32, player_actions.player_x_move_digital) * delta_time * move_speed;
|
2023-10-10 21:56:16 -07:00
|
|
|
new_player_pos_y += scast(f32, player_actions.player_y_move_digital) * delta_time * move_speed;
|
2023-10-04 10:55:15 -07:00
|
|
|
}
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_y += sinf( player->jump_time * TAU ) * 10.f * delta_time;
|
2023-10-04 10:55:15 -07:00
|
|
|
|
2023-10-06 10:06:40 -07:00
|
|
|
b32 valid_new_pos = true;
|
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
WorldPosition test_pos = {
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x, new_player_pos_y,
|
|
|
|
player->position.tile_x, player->position.tile_y
|
2023-10-06 23:33:39 -07:00
|
|
|
};
|
2023-10-10 21:56:16 -07:00
|
|
|
test_pos = recannonicalize_position( & world, test_pos );
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 10:08:08 -07:00
|
|
|
// TODO(Ed) : Need a delta-function that auto-reconnonicalizes.
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
WorldPosition test_pos_nw {
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x - player_half_width, new_player_pos_y - player_quarter_height,
|
|
|
|
player->position.tile_x, player->position.tile_y
|
|
|
|
};
|
|
|
|
test_pos_nw = recannonicalize_position( & world, test_pos_nw );
|
|
|
|
valid_new_pos &= world_is_point_empty( & world, test_pos_nw );
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
WorldPosition test_pos_ne {
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x + player_half_width, new_player_pos_y - player_quarter_height,
|
|
|
|
player->position.tile_x, player->position.tile_y
|
|
|
|
};
|
2023-10-10 21:56:16 -07:00
|
|
|
test_pos_ne = recannonicalize_position( & world, test_pos_ne );
|
2023-10-10 10:08:08 -07:00
|
|
|
valid_new_pos &= world_is_point_empty( & world, test_pos_ne );
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
WorldPosition test_pos_sw {
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x - player_half_width, new_player_pos_y,
|
|
|
|
player->position.tile_x, player->position.tile_y
|
|
|
|
};
|
2023-10-10 21:56:16 -07:00
|
|
|
test_pos_sw = recannonicalize_position( & world, test_pos_sw );
|
2023-10-10 10:08:08 -07:00
|
|
|
valid_new_pos &= world_is_point_empty( & world, test_pos_sw );
|
2023-10-06 10:06:40 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
WorldPosition test_pos_se {
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x + player_half_width, new_player_pos_y,
|
|
|
|
player->position.tile_x, player->position.tile_y
|
|
|
|
};
|
2023-10-10 21:56:16 -07:00
|
|
|
test_pos_se = recannonicalize_position( & world, test_pos_se );
|
2023-10-10 10:08:08 -07:00
|
|
|
valid_new_pos &= world_is_point_empty( & world, test_pos_se );
|
2023-10-06 10:06:40 -07:00
|
|
|
}
|
2023-10-04 10:55:15 -07:00
|
|
|
|
|
|
|
if ( valid_new_pos )
|
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
WorldPosition new_pos = {
|
2023-10-10 10:08:08 -07:00
|
|
|
new_player_pos_x, new_player_pos_y,
|
|
|
|
player->position.tile_x, player->position.tile_y
|
|
|
|
};
|
|
|
|
player->position = recannonicalize_position( & world, new_pos );
|
2023-10-04 10:55:15 -07:00
|
|
|
}
|
2023-10-01 17:17:14 -07:00
|
|
|
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( player->jump_time > 0.f )
|
2023-09-24 19:37:05 -07:00
|
|
|
{
|
2023-10-01 17:17:14 -07:00
|
|
|
player->jump_time -= delta_time;
|
2023-09-24 19:37:05 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
player->jump_time = 0.f;
|
2023-09-30 12:40:27 -07:00
|
|
|
player->mid_jump = false;
|
2023-09-28 10:44:43 -07:00
|
|
|
}
|
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( ! player->mid_jump && player_actions.jump )
|
2023-09-28 10:44:43 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
player->jump_time = 1.f;
|
2023-09-30 12:40:27 -07:00
|
|
|
player->mid_jump = true;
|
2023-09-24 19:37:05 -07:00
|
|
|
}
|
2023-09-20 21:26:23 -07:00
|
|
|
}
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 17:26:00 -07:00
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, 0.f, 0.f
|
|
|
|
, scast(f32, back_buffer->width), scast(f32, back_buffer->height)
|
2023-10-01 17:17:14 -07:00
|
|
|
, 1.f, 0.24f, 0.24f );
|
|
|
|
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
// Scrolling shitshow
|
|
|
|
#if 1
|
|
|
|
f32 center_x = 0.5f * scast(f32, back_buffer->width);
|
|
|
|
f32 center_y = 0.5f * scast(f32, back_buffer->height);
|
|
|
|
|
|
|
|
for ( s32 relative_row = -10; relative_row < +10; ++ relative_row )
|
|
|
|
{
|
|
|
|
for ( s32 relative_col = -20; relative_col < +20; ++ relative_col )
|
|
|
|
{
|
|
|
|
u32 col = player->position.tile_x + relative_col;
|
|
|
|
u32 row = player->position.tile_y + relative_row;
|
|
|
|
|
|
|
|
u32 tileID = piggy_get_tile_value( & world, col, row );
|
|
|
|
f32 color[3] = { 0.15f, 0.15f, 0.15f };
|
|
|
|
|
|
|
|
if ( tileID == 1 )
|
|
|
|
{
|
|
|
|
color[0] = 0.22f;
|
|
|
|
color[1] = 0.22f;
|
|
|
|
color[2] = 0.22f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( row == player->position.tile_y && col == player->position.tile_x )
|
|
|
|
{
|
|
|
|
color[0] = 0.44f;
|
|
|
|
color[1] = 0.3f;
|
|
|
|
color[2] = 0.3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
f32 min_x = center_x + scast(f32, relative_col) * tile_size_in_pixels;
|
|
|
|
f32 min_y = center_y - scast(f32, relative_row) * tile_size_in_pixels;
|
|
|
|
f32 max_x = min_x + tile_size_in_pixels;
|
|
|
|
f32 max_y = min_y - tile_size_in_pixels;
|
|
|
|
|
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, min_x, max_y
|
|
|
|
, max_x, min_y
|
|
|
|
, color[0], color[1], color[2] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Player
|
|
|
|
f32 player_red = 0.7f;
|
|
|
|
f32 player_green = 0.7f;
|
|
|
|
f32 player_blue = 0.3f;
|
|
|
|
|
|
|
|
f32 player_tile_x_offset = center_x + scast(f32, player->position.tile_x) * world.tile_meters_to_pixels;
|
|
|
|
f32 player_tile_y_offset = center_y - scast(f32, player->position.tile_y) * world.tile_meters_to_pixels;
|
|
|
|
|
|
|
|
f32 player_screen_pos_x = center_x + player->position.x * world.tile_meters_to_pixels;
|
|
|
|
f32 player_screen_pos_y = center_y - player->position.y * world.tile_meters_to_pixels;
|
|
|
|
|
|
|
|
// player_min_x = player_tile_x_offset - player_half_width * world;
|
|
|
|
|
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, player_screen_pos_x - player_half_width * world.tile_meters_to_pixels, player_screen_pos_y - player->height * world.tile_meters_to_pixels
|
|
|
|
, player_screen_pos_x + player_half_width * world.tile_meters_to_pixels, player_screen_pos_y
|
|
|
|
, player_red, player_green, player_blue );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Non-scrolling screen
|
|
|
|
#if 0
|
|
|
|
// Draw TileChunk
|
|
|
|
for ( u32 row = 0; row < 9; ++ row )
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
for ( u32 col = 0; col < 16; ++ col )
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
u32 tileID = piggy_get_tile_value( & world, col, row );
|
2023-10-10 10:08:08 -07:00
|
|
|
f32 color[3] = { 0.15f, 0.15f, 0.15f };
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
if ( tileID == 1 )
|
|
|
|
{
|
2023-10-10 10:08:08 -07:00
|
|
|
color[0] = 0.22f;
|
|
|
|
color[1] = 0.22f;
|
|
|
|
color[2] = 0.22f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( row == player->position.tile_y && col == player->position.tile_x )
|
|
|
|
{
|
|
|
|
color[0] = 0.44f;
|
|
|
|
color[1] = 0.3f;
|
|
|
|
color[2] = 0.3f;
|
2023-10-01 17:17:14 -07:00
|
|
|
}
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
#if 0
|
|
|
|
// Was able to flip Y properly but not get the center alignemnt with the world.tile_lower_left that I wanted..
|
|
|
|
f32 min_x = world.tile_lower_left_x + scast(f32, col) * tile_size_in_pixels;
|
|
|
|
f32 min_y = scast(f32, row) * tile_size_in_pixels;
|
2023-10-06 23:33:39 -07:00
|
|
|
f32 max_x = min_x + tile_size_in_pixels;
|
|
|
|
f32 max_y = min_y + tile_size_in_pixels;
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, min_x, min_y
|
|
|
|
, max_x, max_y
|
2023-10-10 21:56:16 -07:00
|
|
|
//, min_x, max_y
|
|
|
|
//, max_x, min_y
|
|
|
|
, color[0], color[1], color[2] );
|
|
|
|
#else
|
|
|
|
f32 min_x = world.tile_lower_left_x + scast(f32, col) * tile_size_in_pixels;
|
|
|
|
f32 min_y = world.tile_lower_left_y - scast(f32, row) * tile_size_in_pixels;
|
|
|
|
f32 max_x = min_x + tile_size_in_pixels;
|
|
|
|
f32 max_y = min_y - tile_size_in_pixels;
|
|
|
|
|
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, min_x, max_y
|
|
|
|
, max_x, min_y
|
2023-10-10 10:08:08 -07:00
|
|
|
, color[0], color[1], color[2] );
|
2023-10-10 21:56:16 -07:00
|
|
|
#endif
|
2023-10-01 17:17:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Player
|
2023-10-10 10:08:08 -07:00
|
|
|
f32 player_red = 0.7f;
|
|
|
|
f32 player_green = 0.7f;
|
2023-10-01 17:17:14 -07:00
|
|
|
f32 player_blue = 0.3f;
|
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
f32 player_tile_x_offset = scast(f32, player->position.tile_x * world.tile_size_in_pixels);
|
|
|
|
f32 player_tile_y_offset = -scast(f32, player->position.tile_y * world.tile_size_in_pixels);
|
2023-10-10 10:08:08 -07:00
|
|
|
|
2023-10-10 21:56:16 -07:00
|
|
|
f32 player_screen_pos_x = world.tile_lower_left_x + player_tile_x_offset + player->position.x * world.tile_meters_to_pixels;
|
|
|
|
f32 player_screen_pos_y = world.tile_lower_left_y + player_tile_y_offset - player->position.y * world.tile_meters_to_pixels;
|
2023-10-10 10:08:08 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
draw_rectangle( back_buffer
|
2023-10-10 21:56:16 -07:00
|
|
|
, player_screen_pos_x - player_half_width * world.tile_meters_to_pixels, player_screen_pos_y - player->height * world.tile_meters_to_pixels
|
|
|
|
, player_screen_pos_x + player_half_width * world.tile_meters_to_pixels, player_screen_pos_y
|
|
|
|
, player_red, player_green, player_blue );
|
|
|
|
#endif
|
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
// Auto-Snapshot percent bar
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
f32 snapshot_percent_x = ((state->auto_snapshot_timer / state->auto_snapshot_interval)) * (f32)back_buffer->width / 4.f;
|
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, 0.f, 0.f
|
|
|
|
, snapshot_percent_x, 10.f
|
2023-10-04 10:55:15 -07:00
|
|
|
, 0.f, 0.15f, 0.35f );
|
2023-10-01 17:17:14 -07:00
|
|
|
}
|
2023-09-30 07:05:37 -07:00
|
|
|
|
2023-09-30 12:40:27 -07:00
|
|
|
#if Build_Development
|
|
|
|
if ( memory->replay_mode == ReplayMode_Record )
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
|
|
|
draw_rectangle( back_buffer
|
2023-10-10 10:08:08 -07:00
|
|
|
, player->position.x + 50.f, player->position.y - 50.f
|
|
|
|
, player->position.x + 10.f, player->position.y + 40.f
|
2023-10-01 17:17:14 -07:00
|
|
|
, 1.f, 1.f, 1.f );
|
|
|
|
}
|
2023-09-30 12:40:27 -07:00
|
|
|
#endif
|
2023-09-30 07:05:37 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
// Change above to use draw rectangle
|
2023-10-04 10:55:15 -07:00
|
|
|
if ( 0 )
|
|
|
|
{
|
|
|
|
draw_rectangle( back_buffer
|
|
|
|
, (f32)input->controllers[0].mouse->X.end, (f32)input->controllers[0].mouse->Y.end
|
|
|
|
, (f32)input->controllers[0].mouse->X.end + 10.f, (f32)input->controllers[0].mouse->Y.end + 10.f
|
|
|
|
, 1.f, 1.f, 0.f );
|
|
|
|
}
|
2023-09-28 10:44:43 -07:00
|
|
|
|
2023-09-30 07:05:37 -07:00
|
|
|
// Mouse buttons test
|
2023-10-01 17:17:14 -07:00
|
|
|
#if 0
|
2023-09-30 07:05:37 -07:00
|
|
|
{
|
|
|
|
if ( input->controllers[0].mouse->left.ended_down == true )
|
|
|
|
render_player( back_buffer, 5, 5 );
|
|
|
|
|
|
|
|
if ( input->controllers[0].mouse->middle.ended_down == true )
|
|
|
|
|
|
|
|
render_player( back_buffer, 5, 20 );
|
|
|
|
|
|
|
|
if ( input->controllers[0].mouse->right.ended_down == true )
|
|
|
|
render_player( back_buffer, 5, 35 );
|
|
|
|
}
|
2023-10-01 17:17:14 -07:00
|
|
|
#endif
|
2023-09-24 19:37:05 -07:00
|
|
|
}
|
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
Engine_API
|
2023-09-30 17:26:00 -07:00
|
|
|
void update_audio( f32 delta_time, AudioBuffer* audio_buffer, Memory* memory, platform::ModuleAPI* platform_api, ThreadContext* thread )
|
2023-09-24 19:37:05 -07:00
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
EngineState* state = rcast( EngineState*, memory->persistent );
|
2023-09-24 19:37:05 -07:00
|
|
|
do_once_start
|
|
|
|
|
|
|
|
do_once_end
|
2023-09-17 18:20:11 -07:00
|
|
|
|
2023-09-16 15:41:07 -07:00
|
|
|
// TODO(Ed) : Allow sample offsets here for more robust platform options
|
2023-09-30 07:05:37 -07:00
|
|
|
if ( ! state->sample_wave_switch )
|
2023-09-24 19:37:05 -07:00
|
|
|
output_sound( state, audio_buffer, sine_wave_sample_value );
|
2023-09-17 18:20:11 -07:00
|
|
|
else
|
2023-09-24 19:37:05 -07:00
|
|
|
output_sound( state, audio_buffer, square_wave_sample_value );
|
2023-09-15 18:35:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENGINE_END
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
#undef pressed
|