Skip to content

Commit

Permalink
Merge pull request #109 from fallahn/golf-1.16
Browse files Browse the repository at this point in the history
Golf 1.16.1
  • Loading branch information
fallahn authored Apr 13, 2024
2 parents 595254c + 0addd18 commit 9e9065a
Show file tree
Hide file tree
Showing 35 changed files with 1,022 additions and 499 deletions.
4 changes: 3 additions & 1 deletion crogine/src/core/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ App::App(std::uint32_t styleFlags)
m_instance = this;

//maps the steam deck rear buttons to the controller paddles
auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000011010000,Steam Deck,platform:Linux,crc:17f6,a:b3,b:b4,x:b5,y:b6,back:b11,guide:b13,start:b12,leftstick:b14,rightstick:b15,leftshoulder:b7,rightshoulder:b8,dpup:b16,dpdown:b17,dpleft:b18,dpright:b19,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a9,righttrigger:a8,");
//auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000011010000,Steam Deck,platform:Linux,crc:17f6,a:b3,b:b4,x:b5,y:b6,back:b11,guide:b13,start:b12,leftstick:b14,rightstick:b15,leftshoulder:b7,rightshoulder:b8,dpup:b16,dpdown:b17,dpleft:b18,dpright:b19,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a9,righttrigger:a8");
auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000011010000,Steam Deck,a:b3,b:b4,back:b11,dpdown:b17,dpleft:b18,dpright:b19,dpup:b16,guide:b13,leftshoulder:b7,leftstick:b14,lefttrigger:a9,leftx:a0,lefty:a1,misc1:b2,paddle1:b21,paddle2:b20,paddle3:b23,paddle4:b22,rightshoulder:b8,rightstick:b15,righttrigger:a8,rightx:a2,righty:a3,start:b12,x:b5,y:b6,platform:Linux");
//auto mapResult = SDL_GameControllerAddMapping("03000000de2800000512000010010000,Steam Deck,a:b3,b:b4,back:b11,dpdown:b17,dpleft:b18,dpright:b19,dpup:b16,guide:b13,leftshoulder:b7,leftstick:b14,lefttrigger:a9,leftx:a0,lefty:a1,rightshoulder:b8,rightstick:b15,righttrigger:a8,rightx:a2,righty:a3,start:b12,x:b5,y:b6,platform:Linux");
if (mapResult == -1)
{
LogE << SDL_GetError() << std::endl;
Expand Down
17 changes: 12 additions & 5 deletions libsocial/include/Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ namespace Progress
file.file = SDL_RWFromFile(path.c_str(), "wb");
if (file.file)
{
file.file->write(file.file, &holeIndex, sizeof(holeIndex), 1);
static constexpr std::size_t MaxBytes = 26; //size of holeIndex + 18 scores. TODO this will make files INCOMPATIBLE cross platform if size_t is defined as a different size...

auto written = file.file->write(file.file, &holeIndex, sizeof(holeIndex), 1);

const auto scoreSize = std::min(std::size_t(18), holeScores.size());
for (auto i = 0u; i < scoreSize; ++i)
{
file.file->write(file.file, &holeScores[i], 1, 1);
written += file.file->write(file.file, &holeScores[i], 1, 1);
}
for (auto i = scoreSize; i < 18; ++i)
//for (auto i = scoreSize; i < 18; ++i)
while (written < MaxBytes)
{
std::uint8_t packing = 0;
file.file->write(file.file, &packing, 1, 1);
written += file.file->write(file.file, &packing, 1, 1);
}
}
}
Expand All @@ -131,9 +134,13 @@ namespace Progress
file.file = SDL_RWFromFile(path.c_str(), "rb");
if (file.file)
{
/*auto size = file.file->seek(file.file, 0, RW_SEEK_END);
file.file->seek(file.file, 0, RW_SEEK_SET);*/

std::array<std::uint8_t, sizeof(holeIndex) + 18> buffer = {};
std::size_t i = 0u;
while (file.file->read(file.file, &buffer[i], 1, 1))
while (file.file->read(file.file, &buffer[i], 1, 1)
&& i < buffer.size() - 1) //hm some existing files have 1 byte padding too many
{
i++;
}
Expand Down
6 changes: 3 additions & 3 deletions libsocial/include/Social.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ source distribution.
//(ball started sending wind effect 1120 -> 1124)
//(added night mode/weather 1141 -> 1150)
//(player avatar data format changed 1153->1160)
static constexpr std::uint16_t CURRENT_VER = 1160;
static constexpr std::uint16_t CURRENT_VER = 1161;
#ifdef __APPLE__
static const std::string StringVer("1.16.0 (macOS beta)");
static const std::string StringVer("1.16.1 (macOS beta)");
#else
static const std::string StringVer("1.16.0");
static const std::string StringVer("1.16.1");
#endif

struct HallEntry final
Expand Down
4 changes: 2 additions & 2 deletions samples/golf/buildnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef BUILD_NUMBER_H_
#define BUILD_NUMBER_H_

#define BUILDNUMBER 5168
#define BUILDNUMBER_STR "5168"
#define BUILDNUMBER 5341
#define BUILDNUMBER_STR "5341"

#endif /* BUILD_NUMBER_H_ */
Binary file modified samples/golf/golf.aps
Binary file not shown.
8 changes: 4 additions & 4 deletions samples/golf/golf.rc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ IDI_ICON1 ICON "icon.ico"
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,16,0,0
PRODUCTVERSION 1,16,0,0
FILEVERSION 1,16,1,0
PRODUCTVERSION 1,16,1,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -79,12 +79,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Trederia"
VALUE "FileDescription", "Super Video Golf"
VALUE "FileVersion", "1.16.0.0"
VALUE "FileVersion", "1.16.1.0"
VALUE "InternalName", "golf.exe"
VALUE "LegalCopyright", "Copyright (C) 2024 Trederia Games"
VALUE "OriginalFilename", "golf.exe"
VALUE "ProductName", "Super Video Golf"
VALUE "ProductVersion", "1.16.0.0"
VALUE "ProductVersion", "1.16.1.0"
END
END
BLOCK "VarFileInfo"
Expand Down
5 changes: 5 additions & 0 deletions samples/golf/src/GolfGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,10 @@ void GolfGame::loadPreferences()
{
m_sharedData.useTTS = prop.getValue<bool>();
}
else if (name == "use_swingput")
{
m_sharedData.useSwingput = prop.getValue<bool>();
}
}
}
}
Expand Down Expand Up @@ -1435,6 +1439,7 @@ void GolfGame::savePreferences()
cfg.addProperty("fov").setValue(m_sharedData.fov);
cfg.addProperty("vertex_snap").setValue(m_sharedData.vertexSnap);
cfg.addProperty("mouse_speed").setValue(m_sharedData.mouseSpeed);
cfg.addProperty("use_swingput").setValue(m_sharedData.useSwingput);
cfg.addProperty("invert_x").setValue(m_sharedData.invertX);
cfg.addProperty("invert_y").setValue(m_sharedData.invertY);
cfg.addProperty("show_beacon").setValue(m_sharedData.showBeacon);
Expand Down
5 changes: 3 additions & 2 deletions samples/golf/src/golf/CareerState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ void CareerState::buildScene()

//check if we just completed a league, and if we did and it's
//one less than max leagues, increment our current round id
auto currIdx = m_sharedData.leagueRoundID - 1;
if (currIdx == m_maxLeagueIndex - 1)
auto currIdx = std::max(0, m_sharedData.leagueRoundID - 1);
if (currIdx != 0 &&
currIdx == m_maxLeagueIndex - 1)
{
if (Career::instance().getLeagueTables()[currIdx].getCurrentIteration() == 0)
{
Expand Down
3 changes: 2 additions & 1 deletion samples/golf/src/golf/CommandIDs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ struct CommandID final
CourseType = 0x80000,
MetricClub = 0x100000, //used in the stats viewer for club labels
ImperialClub = 0x200000,
ChatHint = 0x400000
ChatHint = 0x400000,
CourseHint = 0x800000
};
};
};
6 changes: 3 additions & 3 deletions samples/golf/src/golf/CommonConsts.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2021 - 2023
Matt Marchant 2021 - 2024
http://trederia.blogspot.com
Super Video Golf - zlib licence.
Expand Down Expand Up @@ -54,8 +54,8 @@ namespace ConstVal
static constexpr float MinMouseSpeed = 0.5f;
static constexpr float MaxMouseSpeed = 2.f;

static constexpr float MinSwingputThresh = 0.2f;
static constexpr float MaxSwingputThresh = 10.f;
static constexpr float MinSwingputThresh = 0.1f;
static constexpr float MaxSwingputThresh = 2.f;

static constexpr std::int32_t MaxProfiles = 64;
static constexpr std::uint32_t MaxBalls = 64u;
Expand Down
1 change: 0 additions & 1 deletion samples/golf/src/golf/DrivingState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class DrivingState final : public cro::State, public cro::GuiClient
cro::Entity m_mapCam;
cro::SimpleQuad m_flagQuad;
void createUI();
void createSwingMeter(cro::Entity);
void createGameOptions();
void createSummary();
void updateMinimap();
Expand Down
80 changes: 6 additions & 74 deletions samples/golf/src/golf/DrivingStateUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ void DrivingState::createUI()
entity.addComponent<cro::Transform>();
entity.addComponent<cro::Drawable2D>();
auto infoEnt = entity;
createSwingMeter(entity);

entity = m_uiScene.createEntity();
createSwingputMeter(entity, m_inputParser);
infoEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());
//createSwingMeter(entity);

auto& font = m_sharedData.sharedResources->fonts.get(FontID::UI);

Expand Down Expand Up @@ -807,7 +811,7 @@ void DrivingState::createUI()
cam.viewport = { 0.f, 0.f, 1.f, 1.f };

m_viewScale = glm::vec2(getViewScale());
m_inputParser.setMouseScale(m_viewScale.x);
//m_inputParser.setMouseScale(m_viewScale.x);

glm::vec2 courseScale(m_sharedData.pixelScale ? m_viewScale.x : 1.f);

Expand Down Expand Up @@ -886,78 +890,6 @@ void DrivingState::createUI()
createSummary();
}

void DrivingState::createSwingMeter(cro::Entity root)
{
static constexpr float Width = 4.f;
static constexpr float Height = 40.f;
auto entity = m_uiScene.createEntity();
entity.addComponent<cro::Transform>();
entity.addComponent<cro::Drawable2D>().setVertexData(
{
cro::Vertex2D(glm::vec2(-Width, -Height), SwingputDark),
cro::Vertex2D(glm::vec2(Width, -Height), SwingputDark),
cro::Vertex2D(glm::vec2(-Width, -0.5f), SwingputDark),
cro::Vertex2D(glm::vec2(Width, -0.5f), SwingputDark),

cro::Vertex2D(glm::vec2(-Width, -0.5f), TextNormalColour),
cro::Vertex2D(glm::vec2(Width, -0.5f), TextNormalColour),
cro::Vertex2D(glm::vec2(-Width, 0.5f), TextNormalColour),
cro::Vertex2D(glm::vec2(Width, 0.5f), TextNormalColour),

cro::Vertex2D(glm::vec2(-Width, 0.5f), SwingputDark),
cro::Vertex2D(glm::vec2(Width, 0.5f), SwingputDark),
cro::Vertex2D(glm::vec2(-Width, Height), SwingputDark),
cro::Vertex2D(glm::vec2(Width, Height), SwingputDark),


cro::Vertex2D(glm::vec2(-Width, -Height), SwingputLight),
cro::Vertex2D(glm::vec2(Width, -Height), SwingputLight),
cro::Vertex2D(glm::vec2(-Width, 0.f), SwingputLight),
cro::Vertex2D(glm::vec2(Width, 0.f), SwingputLight),
});
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().setUserData<float>(0.f);
entity.getComponent<cro::Callback>().function =
[&](cro::Entity e, float dt)
{
auto& verts = e.getComponent<cro::Drawable2D>().getVertexData();
float height = verts[14].position.y;
float targetAlpha = -0.01f;

if (m_inputParser.isSwingputActive())
{
height = m_inputParser.getSwingputPosition() * ((Height * 2.f) / MaxSwingputDistance);
targetAlpha = 1.f;
}

auto& currentAlpha = e.getComponent<cro::Callback>().getUserData<float>();
const float InSpeed = dt * 6.f;
const float OutSpeed = m_inputParser.getPower() < 0.5 ? InSpeed : dt * 0.5f;
if (currentAlpha <= targetAlpha)
{
currentAlpha = std::min(1.f, currentAlpha + InSpeed);
}
else
{
currentAlpha = std::max(0.f, currentAlpha - OutSpeed);
}

for (auto& v : verts)
{
v.colour.setAlpha(currentAlpha);
}
verts[14].position.y = height;
verts[15].position.y = height;
};

entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::UIElement;
entity.addComponent<UIElement>().depth = 0.2f;
entity.getComponent<UIElement>().relativePosition = { 1.f, 0.f };
entity.getComponent<UIElement>().absolutePosition = { -10.f, 50.f };

root.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());
}

void DrivingState::createGameOptions()
{
const auto centreSprite = [](cro::Entity e)
Expand Down
75 changes: 75 additions & 0 deletions samples/golf/src/golf/GameConsts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ source distribution.
#include "Terrain.hpp"
#include "MenuConsts.hpp"
#include "SharedStateData.hpp"
#include "InputParser.hpp"
#include "MenuConsts.hpp"
#include "CommandIDs.hpp"
#include "../GolfGame.hpp"

#include <Social.hpp>
Expand All @@ -43,7 +46,9 @@ source distribution.
#include <crogine/ecs/Scene.hpp>
#include <crogine/ecs/components/Model.hpp>
#include <crogine/ecs/components/Callback.hpp>
#include <crogine/ecs/components/CommandTarget.hpp>
#include <crogine/ecs/components/Transform.hpp>
#include <crogine/ecs/components/Drawable2D.hpp>
#include <crogine/ecs/components/AudioEmitter.hpp>
#include <crogine/graphics/Colour.hpp>
#include <crogine/graphics/ImageArray.hpp>
Expand Down Expand Up @@ -677,6 +682,76 @@ static inline std::vector<cro::Vertex2D> getStrokeIndicatorVerts()
};
}

static inline void createSwingputMeter(cro::Entity entity, InputParser& inputParser)
{
static constexpr float Width = 4.f;
static constexpr float Height = 40.f;

entity.addComponent<cro::Transform>();
entity.addComponent<cro::Drawable2D>().setVertexData(
{
cro::Vertex2D(glm::vec2(-Width, -Height), SwingputDark),
cro::Vertex2D(glm::vec2(Width, -Height), SwingputDark),
cro::Vertex2D(glm::vec2(-Width, -0.5f), SwingputDark),
cro::Vertex2D(glm::vec2(Width, -0.5f), SwingputDark),

cro::Vertex2D(glm::vec2(-Width, -0.5f), TextNormalColour),
cro::Vertex2D(glm::vec2(Width, -0.5f), TextNormalColour),
cro::Vertex2D(glm::vec2(-Width, 0.5f), TextNormalColour),
cro::Vertex2D(glm::vec2(Width, 0.5f), TextNormalColour),

cro::Vertex2D(glm::vec2(-Width, 0.5f), SwingputDark),
cro::Vertex2D(glm::vec2(Width, 0.5f), SwingputDark),
cro::Vertex2D(glm::vec2(-Width, Height), SwingputDark),
cro::Vertex2D(glm::vec2(Width, Height), SwingputDark),


cro::Vertex2D(glm::vec2(-Width, -Height), SwingputLight),
cro::Vertex2D(glm::vec2(Width, -Height), SwingputLight),
cro::Vertex2D(glm::vec2(-Width, 0.f), SwingputLight),
cro::Vertex2D(glm::vec2(Width, 0.f), SwingputLight),
});
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().setUserData<float>(0.f);
entity.getComponent<cro::Callback>().function =
[&](cro::Entity e, float dt)
{
auto& verts = e.getComponent<cro::Drawable2D>().getVertexData();
float height = verts[14].position.y;
float targetAlpha = -0.01f;

if (inputParser.isSwingputActive())
{
height = inputParser.getSwingputPosition() * ((Height * 2.f) / MaxSwingputDistance);
targetAlpha = 1.f;
}

auto& currentAlpha = e.getComponent<cro::Callback>().getUserData<float>();
const float InSpeed = dt * 6.f;
const float OutSpeed = inputParser.getPower() < 0.5 ? InSpeed : dt * 0.5f;
if (currentAlpha <= targetAlpha)
{
currentAlpha = std::min(1.f, currentAlpha + InSpeed);
}
else
{
currentAlpha = std::max(0.f, currentAlpha - OutSpeed);
}

for (auto& v : verts)
{
v.colour.setAlpha(currentAlpha);
}
verts[14].position.y = height;
verts[15].position.y = height;
};

entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::UIElement;
entity.addComponent<UIElement>().depth = 0.2f;
entity.getComponent<UIElement>().relativePosition = { 1.f, 0.f };
entity.getComponent<UIElement>().absolutePosition = { -10.f, 50.f };
}

//applies material data loaded in a model definition such as texture info to custom materials
static inline void applyMaterialData(const cro::ModelDefinition& modelDef, cro::Material::Data& dest, std::size_t matID = 0)
{
Expand Down
Loading

0 comments on commit 9e9065a

Please sign in to comment.