mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-12-21 22:14:43 -08:00
Day 47 complete
Not much code, some fixes.
This commit is contained in:
parent
ef76f50528
commit
2a638dffe4
@ -5,6 +5,8 @@
|
|||||||
#define GEN_BENCHMARK
|
#define GEN_BENCHMARK
|
||||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||||
#include "dependencies/gen.hpp"
|
#include "dependencies/gen.hpp"
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
#undef ccast
|
#undef ccast
|
||||||
#undef pcast
|
#undef pcast
|
||||||
#undef rcast
|
#undef rcast
|
||||||
@ -319,7 +321,7 @@ Code gen__phys2( StrC type )
|
|||||||
String sym_vec = String::fmt_buf( GlobalAllocator, "Vec2_%s", type.Ptr );
|
String sym_vec = String::fmt_buf( GlobalAllocator, "Vec2_%s", type.Ptr );
|
||||||
String sym_pos = String::fmt_buf( GlobalAllocator, "Pos2_%s", type.Ptr );
|
String sym_pos = String::fmt_buf( GlobalAllocator, "Pos2_%s", type.Ptr );
|
||||||
String sym_dir = String::fmt_buf( GlobalAllocator, "Dir2_%s", type.Ptr);
|
String sym_dir = String::fmt_buf( GlobalAllocator, "Dir2_%s", type.Ptr);
|
||||||
String sym_dist = String::fmt_buf( GlobalAllocator, "Dist2_%s", type.Ptr );
|
String sym_dist = String::fmt_buf( GlobalAllocator, "Dist_%s", type.Ptr );
|
||||||
String sym_vel = String::fmt_buf( GlobalAllocator, "Vel2_%s", type.Ptr );
|
String sym_vel = String::fmt_buf( GlobalAllocator, "Vel2_%s", type.Ptr );
|
||||||
String sym_accel = String::fmt_buf( GlobalAllocator, "Accel2_%s", type.Ptr );
|
String sym_accel = String::fmt_buf( GlobalAllocator, "Accel2_%s", type.Ptr );
|
||||||
|
|
||||||
@ -549,9 +551,9 @@ int gen_main()
|
|||||||
physics_header.print( gen_phys2( f32 ) );
|
physics_header.print( gen_phys2( f32 ) );
|
||||||
|
|
||||||
physics_header.print( parse_global_body( code(
|
physics_header.print( parse_global_body( code(
|
||||||
|
using Dist = Dist_f32;
|
||||||
using Pos2 = Pos2_f32;
|
using Pos2 = Pos2_f32;
|
||||||
using Dir2 = Dir2_f32;
|
using Dir2 = Dir2_f32;
|
||||||
using Dist2 = Dist2_f32;
|
|
||||||
using Vel2 = Vel2_f32;
|
using Vel2 = Vel2_f32;
|
||||||
using Accel2 = Accel2_f32;
|
using Accel2 = Accel2_f32;
|
||||||
)));
|
)));
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#undef do_once
|
#undef do_once
|
||||||
#undef do_once_start
|
#undef do_once_start
|
||||||
#undef do_once_end
|
#undef do_once_end
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#define GEN_BENCHMARK
|
#define GEN_BENCHMARK
|
||||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||||
#include "dependencies/gen.hpp"
|
#include "dependencies/gen.hpp"
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
#define path_gen "./gen/"
|
#define path_gen "./gen/"
|
||||||
|
@ -332,6 +332,8 @@ Bitmap load_bmp( platform::ModuleAPI* platform_api, Str file_path )
|
|||||||
|
|
||||||
BitmapHeaderPacked* header = pcast(BitmapHeaderPacked*, file.data);
|
BitmapHeaderPacked* header = pcast(BitmapHeaderPacked*, file.data);
|
||||||
assert( header->compression == 3 );
|
assert( header->compression == 3 );
|
||||||
|
|
||||||
|
u32 alpha_mask = ~(header->red_mask | header->green_mask | header->blue_mask);
|
||||||
|
|
||||||
// TODO(Ed) : Do not directly assign this, allocate the pixels to somewhere in game or engine persistent.
|
// TODO(Ed) : Do not directly assign this, allocate the pixels to somewhere in game or engine persistent.
|
||||||
result.pixels = rcast(u32*, rcast(Byte*, file.data) + header->bitmap_offset);
|
result.pixels = rcast(u32*, rcast(Byte*, file.data) + header->bitmap_offset);
|
||||||
@ -339,20 +341,27 @@ Bitmap load_bmp( platform::ModuleAPI* platform_api, Str file_path )
|
|||||||
result.height = header->height;
|
result.height = header->height;
|
||||||
result.bits_per_pixel = header->bits_per_pixel;
|
result.bits_per_pixel = header->bits_per_pixel;
|
||||||
|
|
||||||
u32 red_shift = 0;
|
u32 red_scan = 0;
|
||||||
u32 green_shift = 0;
|
u32 green_scan = 0;
|
||||||
u32 blue_shift = 0;
|
u32 blue_scan = 0;
|
||||||
u32 alpha_shift = 0;
|
u32 alpha_scan = 0;
|
||||||
|
|
||||||
b32 red_found = bitscan_forward( & red_shift, header->red_mask );
|
|
||||||
b32 green_found = bitscan_forward( & green_shift, header->green_mask );
|
|
||||||
b32 blue_found = bitscan_forward( & blue_shift, header->blue_mask );
|
|
||||||
b32 alpha_found = bitscan_forward( & alpha_shift, ~(header->red_mask | header->green_mask | header->blue_mask) );
|
|
||||||
|
|
||||||
|
b32 red_found = bitscan_forward( & red_scan, header->red_mask );
|
||||||
|
b32 green_found = bitscan_forward( & green_scan, header->green_mask );
|
||||||
|
b32 blue_found = bitscan_forward( & blue_scan, header->blue_mask );
|
||||||
|
b32 alpha_found = bitscan_forward( & alpha_scan, alpha_mask );
|
||||||
|
|
||||||
assert( red_found );
|
assert( red_found );
|
||||||
assert( green_found );
|
assert( green_found );
|
||||||
assert( blue_found );
|
assert( blue_found );
|
||||||
assert( alpha_found );
|
assert( alpha_found );
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
s32 blue_shift = 0 - scast( s32, blue_scan );
|
||||||
|
s32 green_shift = 8 - scast( s32, green_scan );
|
||||||
|
s32 red_shift = 16 - scast( s32, red_scan );
|
||||||
|
s32 alpha_shift = 24 - scast( s32, alpha_scan );
|
||||||
|
#endif
|
||||||
|
|
||||||
u32* src = result.pixels;
|
u32* src = result.pixels;
|
||||||
for ( s32 y = 0; y < header->width; ++ y )
|
for ( s32 y = 0; y < header->width; ++ y )
|
||||||
@ -369,10 +378,17 @@ Bitmap load_bmp( platform::ModuleAPI* platform_api, Str file_path )
|
|||||||
|
|
||||||
Pixel* px = rcast(Pixel*, src);
|
Pixel* px = rcast(Pixel*, src);
|
||||||
|
|
||||||
u32 alpha = (( *src >> alpha_shift ) & 0xFF) << 24;
|
#if 0
|
||||||
u32 red = (( *src >> red_shift ) & 0xFF) << 16;
|
u32 alpha = (( *src >> alpha_scan ) & 0xFF) << 24;
|
||||||
u32 green = (( *src >> green_shift ) & 0xFF) << 8;
|
u32 red = (( *src >> red_scan ) & 0xFF) << 16;
|
||||||
u32 blue = (( *src >> blue_shift ) & 0xFF) << 0;
|
u32 green = (( *src >> green_scan ) & 0xFF) << 8;
|
||||||
|
u32 blue = (( *src >> blue_scan ) & 0xFF) << 0;
|
||||||
|
#else
|
||||||
|
u32 alpha = rotate_left( *src & alpha_mask, alpha_shift );
|
||||||
|
u32 red = rotate_left( *src & header->red_mask, red_shift );
|
||||||
|
u32 green = rotate_left( *src & header->green_mask, green_shift );
|
||||||
|
u32 blue = rotate_left( *src & header->blue_mask, blue_shift );
|
||||||
|
#endif
|
||||||
|
|
||||||
*src = alpha | red | green | blue;
|
*src = alpha | red | green | blue;
|
||||||
++ src;
|
++ src;
|
||||||
@ -417,9 +433,6 @@ s32 get_entity( hh::GameState* gs )
|
|||||||
inline
|
inline
|
||||||
void player_init( hh::Player* player, hh::GameState* gs )
|
void player_init( hh::Player* player, hh::GameState* gs )
|
||||||
{
|
{
|
||||||
player->controller.xpad_id = 0;
|
|
||||||
player->controller.ds_pad_id = 0;
|
|
||||||
|
|
||||||
hh::PlayerState* state = & player->state;
|
hh::PlayerState* state = & player->state;
|
||||||
s32 entity_id = get_entity( gs );
|
s32 entity_id = get_entity( gs );
|
||||||
assert( entity_id );
|
assert( entity_id );
|
||||||
@ -433,7 +446,7 @@ void player_init( hh::Player* player, hh::GameState* gs )
|
|||||||
entity->position.rel_pos.x = 0.f;
|
entity->position.rel_pos.x = 0.f;
|
||||||
entity->position.rel_pos.y = 0.f;
|
entity->position.rel_pos.y = 0.f;
|
||||||
|
|
||||||
entity->move_velocity = {};
|
entity->velocity = {};
|
||||||
|
|
||||||
state->mid_jump = false;
|
state->mid_jump = false;
|
||||||
state->jump_time = 0.f;
|
state->jump_time = 0.f;
|
||||||
@ -555,18 +568,29 @@ void update_player( hh::Player* player, f32 delta_time, World* world, hh::GameSt
|
|||||||
player_move_vec.x = scast(f32, actions->player_x_move_digital );
|
player_move_vec.x = scast(f32, actions->player_x_move_digital );
|
||||||
player_move_vec.y = scast(f32, actions->player_y_move_digital );
|
player_move_vec.y = scast(f32, actions->player_y_move_digital );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vec_x_adjusted = desired_vec_len / curr_vec_len * curr_vec_x
|
||||||
|
|
||||||
|
// Allows for more ganular movement with the analog
|
||||||
|
if (0)
|
||||||
|
{
|
||||||
|
f32 accel_scale = magnitude( player_move_vec );
|
||||||
|
if ( accel_scale > 1.f )
|
||||||
|
accel_scale = 1.f;
|
||||||
|
move_accel *= accel_scale;
|
||||||
|
}
|
||||||
|
|
||||||
Dir2 player_direction = cast( Dir2, player_move_vec );
|
Dir2 player_direction = cast( Dir2, player_move_vec );
|
||||||
Accel2 player_move_accel = scast( Accel2, player_direction ) * move_accel;
|
Accel2 player_move_accel = scast( Accel2, player_direction ) * move_accel;
|
||||||
|
|
||||||
// TODO(Ed) : ODE!
|
// TODO(Ed) : ODE!
|
||||||
Accel2 friction = pcast( Accel2, entity->move_velocity) * 9.f;
|
Accel2 friction = pcast( Accel2, entity->velocity) * 9.f;
|
||||||
player_move_accel -= friction;
|
player_move_accel -= friction;
|
||||||
|
|
||||||
entity->move_velocity += player_move_accel * 0.5f;
|
entity->velocity += player_move_accel * 0.5f;
|
||||||
new_player_pos += entity->move_velocity;
|
new_player_pos += entity->velocity;
|
||||||
|
|
||||||
// Old collision implmentation
|
// Collision
|
||||||
#if 1
|
#if 1
|
||||||
{
|
{
|
||||||
b32 collision_nw = false;
|
b32 collision_nw = false;
|
||||||
@ -642,10 +666,10 @@ void update_player( hh::Player* player, f32 delta_time, World* world, hh::GameSt
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// The 2x multiplier allows for the the "bounce off" velocity to occur instead of the player just looking like they impacted the wall and stopped
|
// The 2x multiplier allows for the the "bounce off" velocity to occur instead of the player just looking like they impacted the wall and stopped
|
||||||
entity->move_velocity -= cast( Vel2, 1.f * scalar_product( Vec2( entity->move_velocity ), wall_vector ) * wall_vector );
|
entity->velocity -= cast( Vel2, 1.f * scalar_product( Vec2( entity->velocity ), wall_vector ) * wall_vector );
|
||||||
|
|
||||||
new_player_pos = { old_pos.rel_pos.x, old_pos.rel_pos.y };
|
new_player_pos = { old_pos.rel_pos.x, old_pos.rel_pos.y };
|
||||||
new_player_pos += entity->move_velocity;
|
new_player_pos += entity->velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileMapPos new_pos = {
|
TileMapPos new_pos = {
|
||||||
@ -662,16 +686,20 @@ void update_player( hh::Player* player, f32 delta_time, World* world, hh::GameSt
|
|||||||
old_pos.tile_x, old_pos.tile_y, old_pos.tile_z
|
old_pos.tile_x, old_pos.tile_y, old_pos.tile_z
|
||||||
};
|
};
|
||||||
new_pos = recannonicalize_position( tile_map, new_pos );
|
new_pos = recannonicalize_position( tile_map, new_pos );
|
||||||
|
|
||||||
s32 min_tile_x = 0;
|
s32 min_tile_x = min( old_pos.tile_x, new_pos.tile_x );
|
||||||
s32 min_tile_y = 0;
|
s32 min_tile_y = min( old_pos.tile_y, new_pos.tile_y );
|
||||||
|
|
||||||
|
s32 max_tile_x = max( old_pos.tile_x, new_pos.tile_x );
|
||||||
|
s32 max_tile_y = max( old_pos.tile_y, new_pos.tile_y );
|
||||||
|
|
||||||
TileMapPos best_position = old_pos;
|
TileMapPos best_position = old_pos;
|
||||||
Dist2 best_distance2 = cast(Dist2, magnitude_squared( entity->move_velocity ) );
|
|
||||||
|
f32 min_interp_delta = 1.0f;
|
||||||
|
|
||||||
for ( s32 tile_y = 0; tile_y <= min_tile_y; ++ tile_y )
|
for ( s32 tile_y = min_tile_y; tile_y <= max_tile_x; ++ tile_y )
|
||||||
{
|
{
|
||||||
for ( s32 tile_x = 0; tile_x <= min_tile_x; ++ tile_x )
|
for ( s32 tile_x = min_tile_x; tile_x <= max_tile_x; ++ tile_x )
|
||||||
{
|
{
|
||||||
TileMapPos test_tile_pos = centered_tile_point( tile_x, tile_y, new_pos.tile_z );
|
TileMapPos test_tile_pos = centered_tile_point( tile_x, tile_y, new_pos.tile_z );
|
||||||
s32 tile_value = TileMap_get_tile_value( tile_map, test_tile_pos );
|
s32 tile_value = TileMap_get_tile_value( tile_map, test_tile_pos );
|
||||||
@ -684,14 +712,16 @@ void update_player( hh::Player* player, f32 delta_time, World* world, hh::GameSt
|
|||||||
Vec2 max_corner = 0.5f * tile_xy_in_meters;
|
Vec2 max_corner = 0.5f * tile_xy_in_meters;
|
||||||
|
|
||||||
TileMapPos rel_new_player_pos = subtract( test_tile_pos, new_pos );
|
TileMapPos rel_new_player_pos = subtract( test_tile_pos, new_pos );
|
||||||
Vec2 test_pos = closest_point_in_rectangle( min_corner, max_corner, rel_new_player_pos );
|
|
||||||
|
|
||||||
f32 test_dist2 = ;
|
// TODO(Ed) : Test all four walls and take the minimum Z
|
||||||
if ( best_distance2 > test_dst )
|
/*
|
||||||
{
|
ts = wx -p0x * 1/dx
|
||||||
best_position = ;
|
|
||||||
best_distance2 = ;
|
wall_x - start_pos_x * 1 / distance_interval_x
|
||||||
}
|
|
||||||
|
result = wall.x - rel_new_player_pos.rel_pos.x * 1 / entity->velocity;
|
||||||
|
*/
|
||||||
|
test_wall( min_corner.x, rel_new_player_pos.rel_pos.x, Vec2 { min_corner.y, max_corner.y }, );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -721,13 +751,13 @@ void update_player( hh::Player* player, f32 delta_time, World* world, hh::GameSt
|
|||||||
using hh::FacingDirection_Left;
|
using hh::FacingDirection_Left;
|
||||||
using hh::FacingDirection_Right;
|
using hh::FacingDirection_Right;
|
||||||
|
|
||||||
if ( is_nearly_zero( entity->move_velocity.x ) && is_nearly_zero( entity->move_velocity.y ) )
|
if ( is_nearly_zero( entity->velocity.x ) && is_nearly_zero( entity->velocity.y ) )
|
||||||
{
|
{
|
||||||
// Note(Ed): Leave facing directiona alone
|
// Note(Ed): Leave facing directiona alone
|
||||||
}
|
}
|
||||||
else if ( abs( entity->move_velocity.x ) > abs( entity->move_velocity.y ) )
|
else if ( abs( entity->velocity.x ) > abs( entity->velocity.y ) )
|
||||||
{
|
{
|
||||||
if ( entity->move_velocity.x > 0 )
|
if ( entity->velocity.x > 0 )
|
||||||
{
|
{
|
||||||
entity->facing_direction = FacingDirection_Right;
|
entity->facing_direction = FacingDirection_Right;
|
||||||
}
|
}
|
||||||
@ -736,9 +766,9 @@ void update_player( hh::Player* player, f32 delta_time, World* world, hh::GameSt
|
|||||||
entity->facing_direction = FacingDirection_Left;
|
entity->facing_direction = FacingDirection_Left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( abs( entity->move_velocity.x ) < abs( entity->move_velocity.y ) )
|
else if ( abs( entity->velocity.x ) < abs( entity->velocity.y ) )
|
||||||
{
|
{
|
||||||
if ( entity->move_velocity.y >= 0 )
|
if ( entity->velocity.y >= 0 )
|
||||||
{
|
{
|
||||||
entity->facing_direction = FacingDirection_Back;
|
entity->facing_direction = FacingDirection_Back;
|
||||||
}
|
}
|
||||||
|
@ -136,13 +136,13 @@ inline Pos2_f32& operator/=( Pos2_f32& v, f32 s )
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
using Dist2_f32 = f32;
|
using Dist_f32 = f32;
|
||||||
|
|
||||||
inline Dist2_f32 distance( Pos2_f32 a, Pos2_f32 b )
|
inline Dist_f32 distance( Pos2_f32 a, Pos2_f32 b )
|
||||||
{
|
{
|
||||||
f32 x = b.x - a.x;
|
f32 x = b.x - a.x;
|
||||||
f32 y = b.y - a.y;
|
f32 y = b.y - a.y;
|
||||||
Dist2_f32 result = sqrt( x * x + y * y );
|
Dist_f32 result = sqrt( x * x + y * y );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,8 +495,8 @@ inline Dir2_f32 direction( Accel2_f32 accel )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using Dist = Dist_f32;
|
||||||
using Pos2 = Pos2_f32;
|
using Pos2 = Pos2_f32;
|
||||||
using Dir2 = Dir2_f32;
|
using Dir2 = Dir2_f32;
|
||||||
using Dist2 = Dist2_f32;
|
|
||||||
using Vel2 = Vel2_f32;
|
using Vel2 = Vel2_f32;
|
||||||
using Accel2 = Accel2_f32;
|
using Accel2 = Accel2_f32;
|
||||||
|
@ -109,7 +109,7 @@ struct Entity
|
|||||||
EFacingDirection facing_direction;
|
EFacingDirection facing_direction;
|
||||||
|
|
||||||
engine::TileMapPos position;
|
engine::TileMapPos position;
|
||||||
Vel2 move_velocity;
|
Vel2 velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerState
|
struct PlayerState
|
||||||
|
@ -10,13 +10,15 @@
|
|||||||
inline
|
inline
|
||||||
f32 abs( f32 value )
|
f32 abs( f32 value )
|
||||||
{
|
{
|
||||||
return fabsf(value);
|
f32 result = fabsf(value);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
f32 sqrt( f32 value )
|
f32 sqrt( f32 value )
|
||||||
{
|
{
|
||||||
return sqrtf(value);
|
f32 result = sqrtf(value);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -113,3 +115,17 @@ b32 bitscan_forward( u32* index, u32 value )
|
|||||||
#endif
|
#endif
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
u32 rotate_left( u32 mask, s32 shift )
|
||||||
|
{
|
||||||
|
u32 result = _rotl( mask, shift);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
u32 rotate_right( u32 mask, s32 shift )
|
||||||
|
{
|
||||||
|
u32 result = _rotl( mask, shift );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -38,6 +38,9 @@
|
|||||||
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
|
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
|
||||||
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )
|
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )
|
||||||
|
|
||||||
|
#define max( a, b ) ( (a > b) ? (a) : (b) )
|
||||||
|
#define min( a, b ) ( (a < b) ? (a) : (b) )
|
||||||
|
|
||||||
// TODO(Ed) : Move to debug header eventually
|
// TODO(Ed) : Move to debug header eventually
|
||||||
|
|
||||||
#if Build_Development
|
#if Build_Development
|
||||||
|
Loading…
Reference in New Issue
Block a user