Permalink
Browse files

More comments

  • Loading branch information...
UnknownShadow200 committed Oct 11, 2018
1 parent 427532a commit c3f0585ee83d238f8124157dc143c0b4e33fe5fc
Showing with 144 additions and 19 deletions.
  1. +4 −4 src/Camera.c
  2. +16 −1 src/Camera.h
  3. +30 −6 src/Input.h
  4. +14 −0 src/Options.h
  5. +3 −4 src/String.c
  6. +76 −3 src/String.h
  7. +1 −1 src/Vectors.h
View
@@ -114,7 +114,7 @@ static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
struct Entity* e = &p->Base;
struct Matrix Camera_tiltY, Camera_velX;
Matrix_RotateZ(&Camera_TiltM, -p->Tilt.TiltX * e->Anim.BobStrength);
Matrix_RotateZ(&Camera_TiltM, -p->Tilt.TiltX * e->Anim.BobStrength);
Matrix_RotateX(&Camera_tiltY, Math_AbsF(p->Tilt.TiltY) * 3.0f * e->Anim.BobStrength);
Matrix_MulBy(&Camera_TiltM, &Camera_tiltY);
@@ -157,10 +157,10 @@ static bool FirstPersonCamera_Zoom(float amount) { return false; }
static void FirstPersonCamera_Init(struct Camera* cam) {
PerspectiveCamera_Init(cam);
cam->IsThirdPerson = false;
cam->IsThirdPerson = false;
cam->GetOrientation = FirstPersonCamera_GetOrientation;
cam->GetPosition = FirstPersonCamera_GetPosition;
cam->Zoom = FirstPersonCamera_Zoom;
cam->GetPosition = FirstPersonCamera_GetPosition;
cam->Zoom = FirstPersonCamera_Zoom;
}
View
@@ -1,30 +1,45 @@
#ifndef CC_CAMERA_H
#define CC_CAMERA_H
#include "Picking.h"
#include "Vectors.h"
/* Represents a camera, may be first or third person.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
struct PickedPos;
/* Tilt effect applied to the camera. */
struct Matrix Camera_TiltM;
/* Bobbing offset of camera from player's eye. */
float Camera_BobbingVer, Camera_BobbingHor;
struct Camera {
/* Whether this camera is third person. (i.e. not allowed when -thirdperson in MOTD) */
bool IsThirdPerson;
/* Calculates the current projection matrix of this camera. */
void (*GetProjection)(struct Matrix* proj);
/* Calculates the current modelview matrix of this camera. */
void (*GetView)(struct Matrix* view);
/* Returns the current orientation of the camera. */
Vector2 (*GetOrientation)(void);
/* Returns the current interpolated position of the camera. */
Vector3 (*GetPosition)(float t);
void (*UpdateMouse)(void);
/* Called when user closes all menus, and is interacting with camera again. */
/* Typically, this is used to move mouse cursor to centre of the window. */
void (*RegrabMouse)(void);
/* Calculates selected block in the world, based on camera's current state */
void (*GetPickedBlock)(struct PickedPos* pos);
/* Zooms the camera in or out when scrolling mouse wheel. */
bool (*Zoom)(float amount);
};
/* Camera user is currently using. */
struct Camera* Camera_Active;
/* Initialises the list of cameras. */
void Camera_Init(void);
/* Switches to the next camera in the list. */
void Camera_CycleActive(void);
#endif
View
@@ -31,7 +31,7 @@
*/
typedef enum Key_ {
Key_None, /* Key outside the known keys */
Key_None, /* Unrecognised key */
Key_ShiftLeft, Key_ShiftRight, Key_ControlLeft, Key_ControlRight,
Key_AltLeft, Key_AltRight, Key_WinLeft, Key_WinRight, Key_Menu,
@@ -62,22 +62,28 @@ typedef enum Key_ {
Key_Tilde, Key_Minus, Key_Plus, Key_BracketLeft, Key_BracketRight,
Key_Semicolon, Key_Quote, Key_Comma, Key_Period, Key_Slash, Key_BackSlash,
Key_XButton1, Key_XButton2,
Key_XButton1, Key_XButton2, /* so these can be used for hotkeys */
Key_Count,
} Key;
/* Gets whether key repeating is on or not. If on (desirable for text input), multiple KeyDowns (varies by OS)
are generated for the same key when it is held down for a period of time. Should be off for game input. */
/* Gets whether key repeating is on or not. When on, multiple KeyDown events are raised when the same key is
held down for a period of time (frequency depends on platform). Should be on for menu input, off for game input. */
bool Key_KeyRepeat;
/* Simple names for each keyboard button. */
extern const char* Key_Names[Key_Count];
#define Key_IsWinPressed() (Key_Pressed[Key_WinLeft] || Key_Pressed[Key_WinRight])
#define Key_IsAltPressed() (Key_Pressed[Key_AltLeft] || Key_Pressed[Key_AltRight])
#define Key_IsControlPressed() (Key_Pressed[Key_ControlLeft] || Key_Pressed[Key_ControlRight])
#define Key_IsShiftPressed() (Key_Pressed[Key_ShiftLeft] || Key_Pressed[Key_ShiftRight])
/* Pressed state of each keyboard button. Use Key_SetPressed to change. */
bool Key_Pressed[Key_Count];
/* Sets the pressed state of a keyboard button. */
/* Raises KeyEvents_Up or KeyEvents_Down if state differs, or Key_KeyRepeat is on. */
void Key_SetPressed(Key key, bool pressed);
/* Resets all keys to not pressed state. */
/* Raises KeyEvents_Up for each previously pressed key. */
void Key_Clear(void);
@@ -86,16 +92,23 @@ typedef enum MouseButton_ {
MouseButton_Count,
} MouseButton;
/* Wheel position of the mouse. Use Mouse_SetWheel to change. */
float Mouse_Wheel;
/* X and Y coordinates of the mouse. Use Mouse_SetPosition to change. */
int Mouse_X, Mouse_Y;
/* Pressed state of each mouse button. Use Mouse_SetPressed to change. */
bool Mouse_Pressed[MouseButton_Count];
/* Sets the pressed state of a mouse button. */
/* Raises MouseEvents_Up or MouseEvents_Down if state differs. */
void Mouse_SetPressed(MouseButton btn, bool pressed);
/* Sets wheel position of the mouse, always raising MouseEvents_Wheel. */
void Mouse_SetWheel(float wheel);
/* Sets X and Y position of the mouse, always raising MouseEvents_Moved. */
void Mouse_SetPosition(int x, int y);
/* Enumeration of all custom key bindings. */
/* Enumeration of all key bindings. */
typedef enum KeyBind_ {
KeyBind_Forward, KeyBind_Back, KeyBind_Left, KeyBind_Right,
KeyBind_Jump, KeyBind_Respawn, KeyBind_SetSpawn, KeyBind_Chat,
@@ -109,11 +122,15 @@ typedef enum KeyBind_ {
KeyBind_Count
} KeyBind;
/* Gets the key that is bound to the the given key binding. */
Key KeyBind_Get(KeyBind binding);
/* Gets the default key that the given key binding is bound to */
Key KeyBind_GetDefault(KeyBind binding);
/* Gets whether the key bound to the given key binding is pressed. */
bool KeyBind_IsPressed(KeyBind binding);
/* Set the key that the given key binding is bound to. (also updates options list) */
void KeyBind_Set(KeyBind binding, Key key);
/* Initalises and loads key bindings. */
/* Initalises and loads key bindings from options. */
void KeyBind_Init(void);
@@ -132,10 +149,17 @@ enum HOTKEY_FLAGS {
HOTKEY_FLAG_CTRL = 1, HOTKEY_FLAG_SHIFT = 2, HOTKEY_FLAG_ALT = 4,
};
/* Adds or updates a new hotkey. */
void Hotkeys_Add(Key trigger, int flags, const String* text, bool more);
/* Removes the given hotkey. */
bool Hotkeys_Remove(Key trigger, int flags);
/* Returns the first hotkey which is bound to the given key and has its modifiers pressed. */
/* NOTE: The hotkeys list is sorted, so hotkeys with most modifiers are checked first. */
int Hotkeys_FindPartial(Key key);
/* Initalises and loads hotkeys from options. */
void Hotkeys_Init(void);
/* Called when user has removed a hotkey. (removes it from options) */
void Hotkeys_UserRemovedHotkey(Key trigger, int flags);
/* Called when user has added a hotkey. (Adds it to options) */
void Hotkeys_UserAddedHotkey(Key trigger, int flags, bool moreInput, const String* text);
#endif
View
@@ -73,19 +73,33 @@ extern const char* FpsLimit_Names[FpsLimit_Count];
StringsBuffer Options_Keys;
StringsBuffer Options_Values;
/* Returns whether user has changed any options this session. */
NOINLINE_ bool Options_HasAnyChanged(void);
/* Frees any memory allocated in storing options. */
NOINLINE_ void Options_Free(void);
/* Returns value of given option, or defalt value if not found. */
NOINLINE_ void Options_Get(const char* key, String* value, const char* defValue);
/* Returns value of given option as an integer, or defalt value if could not be converted. */
NOINLINE_ int Options_GetInt(const char* key, int min, int max, int defValue);
/* Returns value of given option as a bool, or defalt value if could not be converted. */
NOINLINE_ bool Options_GetBool(const char* key, bool defValue);
/* Returns value of given option as a float, or defalt value if could not be converted. */
NOINLINE_ float Options_GetFloat(const char* key, float min, float max, float defValue);
/* Returns value of given option as an integer, or defalt value if could not be converted. */
/* NOTE: Conversion is done by going through all elements of names, returning index of a match. */
NOINLINE_ int Options_GetEnum(const char* key, int defValue, const char** names, int namesCount);
/* Sets value of given option to either "true" or "false" */
NOINLINE_ void Options_SetBool(const char* keyRaw, bool value);
/* Sets value of given option to given integer converted to a string. */
NOINLINE_ void Options_SetInt(const char* keyRaw, int value);
/* Sets value of given option to given string. */
NOINLINE_ void Options_Set(const char* keyRaw, const String* value);
/* Sets value of given option to given string. */
NOINLINE_ void Options_SetString(const String* key, const String* value);
/* Loads options from disc. Leaves options changed in this session alone. */
NOINLINE_ void Options_Load(void);
/* Saves all options to disc. */
NOINLINE_ void Options_Save(void);
#endif
View
@@ -679,7 +679,7 @@ bool Convert_TryParseBool(const String* str, bool* value) {
#define STRINGSBUFFER_LEN_MASK 0x1FFUL
#define STRINGSBUFFER_BUFFER_EXPAND_SIZE 8192
void StringsBuffer_Init(StringsBuffer* buffer) {
NOINLINE_ static void StringsBuffer_Init(StringsBuffer* buffer) {
buffer->Count = 0;
buffer->TotalLength = 0;
buffer->TextBuffer = buffer->_DefaultBuffer;
@@ -689,7 +689,7 @@ void StringsBuffer_Init(StringsBuffer* buffer) {
}
void StringsBuffer_Clear(StringsBuffer* buffer) {
/* never initialised to begin with */
/* Never initialised to begin with */
if (!buffer->_FlagsBufferSize) return;
if (buffer->TextBuffer != buffer->_DefaultBuffer) {
@@ -716,7 +716,7 @@ String StringsBuffer_UNSAFE_Get(StringsBuffer* buffer, int i) {
}
void StringsBuffer_Add(StringsBuffer* buffer, const String* text) {
/* Forgot to initalise flags buffer, so do it here */
/* StringsBuffer hasn't been initalised yet, do it here */
if (!buffer->_FlagsBufferSize) { StringsBuffer_Init(buffer); }
if (buffer->Count == buffer->_FlagsBufferSize) {
@@ -815,7 +815,6 @@ void WordWrap_Do(STRING_REF String* text, String* lines, int numLines, int lineL
}
}
/* Calculates where the given raw index is located in the wrapped lines. */
void WordWrap_GetCoords(int index, const String* lines, int numLines, int* coordX, int* coordY) {
if (index == -1) index = Int32_MaxValue;
int offset = 0; *coordX = -1; *coordY = 0;
Oops, something went wrong.

0 comments on commit c3f0585

Please sign in to comment.