int
main(int argc, char *argv[])
{
    memory_arena Arena = {};
    InitializeArena(&Arena, (size_t)Gigabytes(1));

    // freopen("err.log", "w", stderr);
    
    if(argc == 1)
    {
        int32 day = ArrayCount(DayList)-1;
        DayList[day](&Arena, true);
    }
    else if (argc == 2)
    {
        int32 day = (int32) strtol(argv[1], &argv[1], 0);
        if(day && day <ArrayCount(DayList))
        {
            DayList[day](&Arena, true);
        }
        else if (day == 0)
        {
            printf("Running All Days.\n");
            for (int32 i = 1; i < ArrayCount(DayList); ++i)
            {
                printf("---- Day %d ----\n", i);
                DayList[i](&Arena, false);
                ResetArena(&Arena);
                printf("\n");
            }
        }
        else
        {
            PrintHelp();
        }
    }
    else
    {
        PrintHelp();
    }

    FreeArena(&Arena);
}
Esempio n. 2
0
void InitGameMemory(game_memory *Memory, Canvas &canvas)
{
	// �I�~�y���y�p�|�y�x�p���y��
	game_state* GameState = (game_state*)Memory->PermanentStorage;

	InitializeArena(&GameState->WorldArena, Memory->PermanentStorageSize - sizeof(game_state), (uint8*)Memory->PermanentStorage + sizeof(game_state));

	GameState->World = PushStruct(&GameState->WorldArena, world);
	world *World = GameState->World;
	World->TileMap = PushStruct(&GameState->WorldArena, tile_map);
	tile_map *TileMap = World->TileMap;

	GameState->Tick = 0;
	GameState->TimeElapsedFromLastTick = 0;

	// Camera 
	GameState->CameraPos.Tile = Vec2i(0, 0);
	GameState->CameraPos.TilePos = Vec2f(0, 0);
	GameState->CameraOrigin = GameState->ScreenSize / 2.0f;

	GameState->EntityToCameraIn = Rect(-7, -5, 7, 5);
	GameState->EntityToCameraOut = Rect(-8, -6, 8, 6);

	// �H�p�s�����x�y���� �������p�z����
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_sprite, "sand_tile_01.png");
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_object_sprite_001, "object_storage_01.png");
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_object_sprite_stone1, "object_stone_01.png");
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_player_image, "robot_base_horizontal.png");
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_player_image_v, "robot_base_vertical.png");
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_player_image_ur, "robot_base_diagonal_ur.png");
	GameState->LoadGameSpriteFromImage(canvas, GameState->GameSprites.tmp_player_image_ul, "robot_base_diagonal_ul.png");

	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_ground_sprite_01, "ground_concrete_tileset");
	GameState->AddGameSpriteFrameFromImage(canvas, GameState->GameSprites.tmp_ground_sprite_01, "ground_tile_01.png");

	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_torso, "robot_torso");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_down, "track_v_down");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_left, "track_h_left");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_right, "track_h_right");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_up, "track_v_up");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_ur, "track_d_ur");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_ul, "track_d_ul");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_br, "track_d_br");
	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_player_image_track_bl, "track_d_bl");

	GameState->LoadGameSpriteFromResource(canvas, &GameState->game_resources, GameState->GameSprites.tmp_wall_sprite1, "tileset_brick_wall");

	// Player entity
	//
	GameState->PlayerEntity = AddEntity(GameState);
	GameState->PlayerEntity->Position.Tile = Vec2i(0, 0);
	GameState->PlayerEntity->Position.TilePos = Vec2f(0, 0);
	GameState->PlayerEntity->EntityType = EntityType_Robot;
	GameState->PlayerEntity->CollisionType = 1;
	GameState->PlayerEntity->CollisionBox = Rectf(-0.45f, -0.25f, 0.45f, 0.25f);
	GameState->PlayerEntity->Controller.Active = 1;

	GameState->PlayerEntity->Mass = 20000.0f;
	GameState->PlayerEntity->RResistance = 0.008f;

	SetEntityToActive(GameState->PlayerEntity, GameState);

	World->TileSizeMeters = Vec2f(1.0f, 1.0f);
	World->TileSizePixels = Vec2f(100.0f, 100.0f);
	World->MetersToPixels = World->TileSizePixels / World->TileSizeMeters;

	World->g = 4.2f;

	TileMap->TileChunkSize = Vec2ui(16, 16);
	//TileMap->CenterChunkPosition = TileMap->TileChunksCount / (uint32)2;

	GameState->TilesOnHalfScreen.width = (int)((GameState->ScreenSize.width / 2) / World->TileSizePixels.x) + 1;
	GameState->TilesOnHalfScreen.height = (int)((GameState->ScreenSize.height / 2) / World->TileSizePixels.y) + 1;

	Vec2i TilesPerScreen = GameState->TilesOnHalfScreen * 2;

	for (int32 ScreenY = -16; ScreenY < 16; ScreenY++)
	{
		for (int32 ScreenX = -16; ScreenX < 16; ScreenX++)
		{
			for (int32 TY = 0; TY < TilesPerScreen.y; TY++)
			{
				for (int32 TX = 0; TX < TilesPerScreen.x; TX++)
				{
					int32 AbsTileX = ScreenX * TilesPerScreen.x + TX;
					int32 AbsTileY = ScreenY * TilesPerScreen.y + TY;

					SetTileValue(&GameState->WorldArena, TileMap, Vec2i(AbsTileX, AbsTileY), rand() % 16 + 1);
				}
			}
		}
	}
	/*
	for (int32 Y = 1; Y < 4; Y++)
	{
		for (int32 X = 1; X < 5; X++)
		{
			SetTileValue(&GameState->WorldArena, TileMap, Vec2i(X, Y), 5);
			SetTileValue(&GameState->WorldArena, TileMap, Vec2i(X - 7, Y), 5);
			SetTileValue(&GameState->WorldArena, TileMap, Vec2i(X - 5, Y + 6), 4);
		}
	}
	*/

	// Game entities
	GameState->TiledEntities.Entities = PushArray(&GameState->WorldArena, 4096, entity);
	GameState->TiledEntities.GroupSize = 4096;
	GameState->TiledEntities.EntityCount = 0;
	GameState->TiledEntities.NextGroup = 0;
	AddEntityToGroup(&GameState->WorldArena, &GameState->TiledEntities); // �N���|�u�r���z ���q���u�{�� �~�u �y�������|���x���u������

	// Add many stone entities
	world_position EntityPos;
	//Rectf CollisionBox(-0.4f, 0.0f, 0.4f, 0.3f);
	Rectf CollisionBox(-0.5f, -0.5f, 0.5f, 0.5f);
	for (int32 Y = 1; Y < 10; Y++)
	{
		for (int32 X = 1; X < 10; X++)
		{
			EntityPos.Tile = Vec2i(X, Y);
			EntityPos.TilePos = Vec2f(0, 0);

			uint32 StoneIndex = AddEntityToGroup(&GameState->WorldArena, &GameState->TiledEntities);
			entity *Entity = GetEntityFromGroupByIndex(&GameState->TiledEntities, StoneIndex);
			Entity->EntityType = EntityType_Storage;
			Entity->Position = EntityPos;
			Entity->CollisionType = 1;
			Entity->CollisionBox = CollisionBox;
			AddEntityToTile(GameState->World->TileMap, EntityPos.Tile, StoneIndex);
		}
	}

	/*
	EntityPos.Tile = Vec2i(1, 1);
	EntityPos.TilePos = Vec2f(0, 0);
	entity *Entity = AddEntity(GameState);
	Entity->EntityType = EntityType_Stone;
	Entity->Position = EntityPos;
	Entity->CollisionType = 1;
	Entity->CollisionBox = CollisionBox;
	//SetEntityToActive(Entity, GameState);

	/*
	Entity = AddEntity(GameState);
	Entity->EntityType = EntityType_Wall;
	EntityPos.Tile = Vec2i(0, -2);
	Entity->Position = EntityPos;
	Entity->CollisionType = 1;
	Entity->CollisionBox = Rectf(-0.5f, -0.1f, 0.5f, 0.1f);
	Entity->EntityFrame = 0;
	//SetEntityToActive(Entity, GameState);
	*/

	// Call to camera reset to activate entities in camera space
	MapEntitiesInCameraSpace(GameState);

	GameState->IsInitialized = 1;
}