Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple FPS Counter #18

Merged
merged 2 commits into from
Oct 16, 2021
Merged

Add simple FPS Counter #18

merged 2 commits into from
Oct 16, 2021

Conversation

ejcila
Copy link
Contributor

@ejcila ejcila commented Oct 15, 2021

No description provided.

@ezioleq ezioleq self-requested a review October 15, 2021 13:41
Copy link
Owner

@ezioleq ezioleq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work I'm glad for your contribution! But I have a few comments to make it better.

Comment on lines 9 to 15
private Rigidbody _rb;
public CubeTypes type;

void Awake() {
_rb = GetComponent<Rigidbody>();
_rb.interpolation = RigidbodyInterpolation.Interpolate;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I'd revert those changes just because using this rigidbody's interpolation type is even worse in our case. It's fully clipping through everything. I created an issue for this #19 and will be worked on later, because it's a bit more complicated problem.

m_Script: {fileID: 11500000, guid: ddeaeffe06d8ff842acfd08df3bc544f, type: 3}
m_Name:
m_EditorClassIdentifier:
fpsCounterText: {fileID: 0}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fpsCounterText of FpsUI is not assigned so we get a NullReferenceException.

Comment on lines 1 to 16
using UnityEngine;
using TMPro;
public class FpsUI : MonoBehaviour {
public TextMeshProUGUI fpsCounterText;
float fpsCounter;
float refreshTime = 0.5f;
void Update() {
fpsCounter = (int)(1f / Time.unscaledDeltaTime);
if (Time.time > refreshTime) {
fpsCounterText.text = fpsCounter.ToString();
refreshTime += 0.5f;
}


}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First things first

  1. We are using tabs instead of spaces for indentation, to change your default indentation method please see your editor config.
  2. Use private keyword for private members just for explicitness and use _ prefix for private variables names.
  3. Blank lines are messy. Under namespaces should be empty line, before method definition, at the end is some unnecessary space and file should end with a new line. You can see other scripts to get overall style convention, which is about to get more defined in near future.

Comment on lines 8 to 9
fpsCounter = (int)(1f / Time.unscaledDeltaTime);
if (Time.time > refreshTime) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can put this calculation into this condition so we don't lose this 1 CPU cycle :P

void Update() {
fpsCounter = (int)(1f / Time.unscaledDeltaTime);
if (Time.time > refreshTime) {
fpsCounterText.text = fpsCounter.ToString();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply add + " FPS" at the end of this line, because for now it's a strange number on our screen and we don't know what it is.

fpsCounter = (int)(1f / Time.unscaledDeltaTime);
if (Time.time > refreshTime) {
fpsCounterText.text = fpsCounter.ToString();
refreshTime += 0.5f;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this 0.5f mean? Where is it from?
Do your best to omit magic numbers.

@ezioleq ezioleq changed the title FPS UI and Cube Physics fix Add simple FPS Counter Oct 16, 2021
@ezioleq ezioleq changed the base branch from master to dev October 16, 2021 17:07
@ezioleq ezioleq merged commit aea5b97 into ezioleq:dev Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants