aboutsummaryrefslogtreecommitdiff
path: root/code/handmade.h
blob: 123b8575279974bf3daa8f6ab8a8e194cdb80e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#if !defined(HANDMADE_H)
/* ========================================================================
   $File: $
   $Date: $
   $Revision: $
   $Creator: Casey Muratori $
   $Notice: (C) Copyright 2014 by Molly Rocket, Inc. All Rights Reserved. $
   ======================================================================== */

#include "libs/linuxhmh/handmade_platform.h"
#include "handmade_math.h"

#undef STB_TRUETYPE_IMPLEMENTATION
#include "libs/stb_truetype.h"

#define WORDLE_LENGTH 5

enum square_colors
{
    SquareColor_Gray,
    SquareColor_Yellow,
    SquareColor_Green,
    SquareColor_Count
};

struct memory_arena
{
    memory_index Size;
    u8 *Base;
    memory_index Used;
};

void
InitializeArena(memory_arena *Arena, memory_index Size, void *Base)
{
    Arena->Size = Size;
    Arena->Base = (u8 *)Base;
    Arena->Used = 0;
}

#define PushStruct(Arena, type) ((type *)PushSize((Arena), (sizeof(type))))
#define PushArray(Arena, Count, type) (type *)PushSize((Arena), (sizeof(type))*(Count)) 
void *
PushSize(memory_arena *Arena, memory_index Size)
{
    Assert((Arena->Used + Size) < Arena->Size);
    
    void *Result = Arena->Base + Arena->Used;
    Arena->Used += Size;
    
    return Result;
}

#include "handmade_intrinsics.h"

struct loaded_bitmap
{
    int Width;
    int Height;
    u32 *Pixels;
};

struct color_rgb
{
    union
    {
        struct
        {
            r32 R;
            r32 G;
            r32 B;
        };
        r32 E[3];
    };
};
#define color_rgb(A) color_rgb{(A), (A), (A)}

#define Max(A, B) (((A) > (B)) ? (A) : (B))
#define Min(A, B) (((A) < (B)) ? (A) : (B))
#define Clamp(A, B, C) (Max((A), Min((B), (C))))

inline color_rgb
operator*(color_rgb A, r32 B)
{
    color_rgb Result;
    
    Result.R = A.R * B;
    Result.G = A.G * B;
    Result.B = A.B * B;
    
    return Result;
}

inline color_rgb
operator*(r32 A, color_rgb B)
{
    color_rgb Result = B*A;
    
    return Result;
}

inline color_rgb
operator+(color_rgb A, r32 B)
{
    color_rgb Result;
    
    Result.R = A.R + B;
    Result.G = A.G + B;
    Result.B = A.B + B;
    
    return Result;
}

inline color_rgb
operator+(r32 A, color_rgb B)
{
    color_rgb Result = B+A;
    
    return Result;
}

inline color_rgb
operator-(color_rgb A)
{
    color_rgb Result;
    
    Result.R = -A.R;
    Result.G = -A.G;
    Result.B = -A.B;
    
    return Result;
}

struct game_font
{
    stbtt_fontinfo Info;
    s32 Ascent;
    s32 Descent;
    s32 LineGap;
    v2 BoundingBox[2];
    b32 Initialized; // For debugging.
};

struct game_state
{
    u32 PatternGrid[6][5];
    u32 SelectedColor;
    u32 ExportedPatternIndex;
    // TODO(luca): There is no need for utf8 since we know it will be between a-z.  We could use a single byte string and convert to char when appending to the input buffer.
    // But the only benefit would be storing less bytes which isn't really a big deal for 5 characters.
    rune WordleWord[WORDLE_LENGTH];
    
    game_font RegularFont;
    game_font ItalicFont;
    game_font BoldFont;
    
    b32 TextInputMode;
    rune TextInputText[5];
    u32 TextInputCount;
};

#define HANDMADE_H
#endif