Permalink
Browse files

more api

  • Loading branch information...
UnknownShadow200 committed Jan 7, 2019
1 parent 15cda8f commit 1ebd553f36e432e802b6bb4724c5837c049ddd14
Showing with 169 additions and 153 deletions.
  1. +4 −4 src/Bitmap.h
  2. +1 −1 src/Block.h
  3. +3 −3 src/Camera.c
  4. +20 −4 src/Entity.c
  5. +11 −5 src/Entity.h
  6. +1 −1 src/EntityComponents.c
  7. +3 −3 src/EnvRenderer.c
  8. +7 −10 src/Game.c
  9. +9 −7 src/Game.h
  10. +2 −2 src/Graphics.c
  11. +3 −3 src/Gui.c
  12. +1 −1 src/HeldBlockRenderer.c
  13. +7 −7 src/LScreens.c
  14. +3 −3 src/LWidgets.c
  15. +9 −9 src/Launcher.c
  16. +1 −1 src/Logger.c
  17. +2 −2 src/MapRenderer.c
  18. +10 −10 src/Menus.c
  19. +3 −12 src/Model.c
  20. +13 −4 src/Model.h
  21. +0 −4 src/PackedCol.c
  22. +10 −3 src/PackedCol.h
  23. +5 −21 src/PacketHandlers.c
  24. +3 −3 src/Physics.c
  25. +11 −3 src/Physics.h
  26. +16 −16 src/Screens.c
  27. +11 −11 src/Widgets.c
@@ -14,8 +14,8 @@ typedef CC_ALIGN_HINT(4) struct BitmapCol_ {
/* Unioned with Packed member for efficient equality comparison */
typedef union BitmapColUnion_ { BitmapCol C; uint32_t Raw; } BitmapColUnion;

/* Scales RGB of the given colour. */
BitmapCol BitmapCol_Scale(BitmapCol value, float t);
/* Scales RGB components of the given colour. */
CC_API BitmapCol BitmapCol_Scale(BitmapCol value, float t);

/* A 2D array of BitmapCol pixels */
typedef struct Bitmap_ { uint8_t* Scan0; int Width, Height; } Bitmap;
@@ -56,9 +56,9 @@ typedef int (*Png_RowSelector)(Bitmap* bmp, int row);
https://handmade.network/forums/wip/t/2363-implementing_a_basic_png_reader_the_handmade_way
https://github.com/nothings/stb/blob/master/stb_image.h
*/
ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream);
CC_API ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream);
/* Encodes a bitmap in PNG format. */
/* selectRow is optional. Can be used to modify how rows are encoded. (e.g. flip image) */
/* if alpha is non-zero, RGBA channels are saved, otherwise only RGB channels are. */
ReturnCode Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector selectRow, bool alpha);
CC_API ReturnCode Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector selectRow, bool alpha);
#endif
@@ -40,7 +40,7 @@ typedef enum CollideType_ {
COLLIDE_CLIMB_ROPE /* Rope/Ladder style climbing interaction when player collides. */
} CollideType;

extern struct _BlockLists {
CC_VAR extern struct _BlockLists {
/* Whether this block is a liquid. (Like water/lava) */
bool IsLiquid[BLOCK_COUNT];
/* Whether this block prevents lights from passing through it. */
@@ -18,7 +18,7 @@ static bool cam_isForwardThird;
*#########################################################################################################################*/
static void PerspectiveCamera_GetProjection(struct Matrix* proj) {
float fovy = Game_Fov * MATH_DEG2RAD;
float aspectRatio = (float)Game_Width / (float)Game_Height;
float aspectRatio = (float)Game.Width / (float)Game.Height;
Matrix_PerspectiveFieldOfView(proj, fovy, aspectRatio, Gfx_MinZNear, (float)Game_ViewDistance);
}

@@ -40,8 +40,8 @@ static void PerspectiveCamera_GetPickedBlock(struct PickedPos* pos) {
static Point2D cam_prev, cam_delta;
static void PerspectiveCamera_CentreMousePosition(void) {
Point2D topLeft = Window_PointToScreen(0, 0);
int cenX = topLeft.X + Game_Width / 2;
int cenY = topLeft.Y + Game_Height / 2;
int cenX = topLeft.X + Game.Width / 2;
int cenY = topLeft.Y + Game.Height / 2;

Window_SetScreenCursorPos(cenX, cenY);
/* Fixes issues with large DPI displays on Windows >= 8.0. */
@@ -418,16 +418,32 @@ void TabList_Remove(EntityID id) {
}

void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank) {
String colorlessName; char colorlessBuffer[STRING_SIZE];
String oldPlayer, oldList, oldGroup;
uint8_t oldRank;
struct Event_Int* events;

if (TabList_Valid(id)) {
oldPlayer = TabList_UNSAFE_GetPlayer(id);
oldList = TabList_UNSAFE_GetList(id);
oldGroup = TabList_UNSAFE_GetGroup(id);
oldRank = TabList.GroupRanks[id];

/* Don't redraw the tab list if nothing changed. */
if (String_Equals(player, &oldPlayer) && String_Equals(list, &oldList)
&& String_Equals(group, &oldGroup) && rank == oldRank) return;

String_InitArray(colorlessName, colorlessBuffer);
String_AppendColorless(&colorlessName, player);
events = &TabListEvents.Changed;
} else {
events = &TabListEvents.Added;
}
TabList_Delete(id);

TabList.PlayerNames[id] = TabList.Buffer.Count; StringsBuffer_Add(&TabList.Buffer, &colorlessName);
TabList.PlayerNames[id] = TabList.Buffer.Count; StringsBuffer_Add(&TabList.Buffer, player);
TabList.ListNames[id] = TabList.Buffer.Count; StringsBuffer_Add(&TabList.Buffer, list);
TabList.GroupNames[id] = TabList.Buffer.Count; StringsBuffer_Add(&TabList.Buffer, group);
TabList.GroupRanks[id] = rank;

Event_RaiseInt(&TabListEvents.Added, id);
}

static void TabList_Free(void) { StringsBuffer_Clear(&TabList.Buffer); }
@@ -102,14 +102,14 @@ void Entity_GetPickingBounds(struct Entity* e, struct AABB* bb);
/* Gets the current collision bounds of the given entity. */
void Entity_GetBounds(struct Entity* e, struct AABB* bb);
/* Sets the model of the entity. (i.e its appearance) */
void Entity_SetModel(struct Entity* e, const String* model);
CC_API void Entity_SetModel(struct Entity* e, const String* model);
/* Updates cached Size and ModelAABB of the given entity. */
/* NOTE: Only needed when manually changing Model or ModelScale. */
/* Entity_SetModel implicitly call this method. */
void Entity_UpdateModelBounds(struct Entity* e);

/* Whether the given entity is touching any blocks meeting the given condition .*/
bool Entity_TouchesAny(struct AABB* bb, Entity_TouchesCondition cond);
CC_API bool Entity_TouchesAny(struct AABB* bb, Entity_TouchesCondition cond);
bool Entity_TouchesAnyRope(struct Entity* e);
bool Entity_TouchesAnyLava(struct Entity* e);
bool Entity_TouchesAnyWater(struct Entity* e);
@@ -139,18 +139,24 @@ void Entities_DrawShadows(void);
#define TABLIST_MAX_NAMES 256
/* Data for all entries in tab list */
CC_VAR extern struct _TabListData {
/* Raw unformatted name (for Tab name auto complete) */
uint16_t PlayerNames[TABLIST_MAX_NAMES];
/* Formatted name for display in tab list. */
uint16_t ListNames[TABLIST_MAX_NAMES];
/* Name of the group this entry is in (e.g. rank name, map name) */
uint16_t GroupNames[TABLIST_MAX_NAMES];
/* Position/Order of this entry within the group. */
uint8_t GroupRanks[TABLIST_MAX_NAMES];
StringsBuffer Buffer;
} TabList;

/* Returns whether the tab list entry with the given ID is used at all. */
bool TabList_Valid(EntityID id);
CC_API bool TabList_Valid(EntityID id);
/* Removes the tab list entry with the given ID, raising TabListEvents.Removed event. */
void TabList_Remove(EntityID id);
void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank);
CC_API void TabList_Remove(EntityID id);
/* Sets the data for the tab list entry with the given id. */
/* Raises TabListEvents.Changed if replacing, TabListEvents.Added if a new entry. */
CC_API void TabList_Set(EntityID id, const String* player, const String* list, const String* group, uint8_t rank);

#define TabList_UNSAFE_GetPlayer(id) StringsBuffer_UNSAFE_Get(&TabList.Buffer, TabList.PlayerNames[id]);
#define TabList_UNSAFE_GetList(id) StringsBuffer_UNSAFE_Get(&TabList.Buffer, TabList.ListNames[id]);
@@ -87,7 +87,7 @@ void AnimatedComp_Update(struct Entity* e, Vector3 oldPos, Vector3 newPos, doubl

void AnimatedComp_GetCurrent(struct Entity* e, float t) {
struct AnimatedComp* anim = &e->Anim;
float idleTime = (float)Game_Time;
float idleTime = (float)Game.Time;
float idleXRot = Math_SinF(idleTime * ANIM_IDLE_XPERIOD) * ANIM_IDLE_MAX;
float idleZRot = Math_CosF(idleTime * ANIM_IDLE_ZPERIOD) * ANIM_IDLE_MAX + ANIM_IDLE_MAX;

@@ -132,7 +132,7 @@ void EnvRenderer_RenderClouds(double deltaTime) {
struct Matrix m;

if (!clouds_vb || Env_CloudsHeight < -2000) return;
offset = (float)(Game_Time / 2048.0f * 0.6f * Env_CloudsSpeed);
offset = (float)(Game.Time / 2048.0f * 0.6f * Env_CloudsSpeed);

m = Matrix_Identity; m.Row3.X = offset; /* translate X axis */
Gfx_LoadMatrix(MATRIX_TEXTURE, &m);
@@ -302,7 +302,7 @@ void EnvRenderer_RenderSkybox(double deltaTime) {

/* Base skybox rotation */
m = Matrix_Identity;
rotTime = (float)(Game_Time * 2 * MATH_PI); /* So speed of 1 rotates whole skybox every second */
rotTime = (float)(Game.Time * 2 * MATH_PI); /* So speed of 1 rotates whole skybox every second */
Matrix_RotateY(&rotY, Env_SkyboxHorSpeed * rotTime); Matrix_MulBy(&m, &rotY);
Matrix_RotateX(&rotX, Env_SkyboxVerSpeed * rotTime); Matrix_MulBy(&m, &rotX);

@@ -470,7 +470,7 @@ void EnvRenderer_RenderWeather(double deltaTime) {
pos.Y = max(World_Height, pos.Y);

speed = (weather == WEATHER_RAINY ? 1.0f : 0.2f) * Env_WeatherSpeed;
vOffset = (float)Game_Time * speed;
vOffset = (float)Game.Time * speed;
particles = weather == WEATHER_RAINY;
weather_accumulator += deltaTime;

@@ -33,9 +33,8 @@
#include "Audio.h"
#include "Stream.h"

int Game_Width, Game_Height;
double Game_Time;
int Game_ChunkUpdates, Game_Port;
struct _GameData Game;
int Game_Port;
bool Game_UseCPEBlocks;

struct PickedPos Game_SelectedPos;
@@ -45,7 +44,6 @@ int Game_Fov, Game_DefaultFov, Game_ZoomFov;
float game_limitMs;
int Game_FpsLimit, Game_Vertices;
bool Game_ShowAxisLines, Game_SimpleArmsAnim;
bool Game_ClassicArmModel;

bool Game_ClassicMode, Game_ClassicHacks;
bool Game_AllowCustomBlocks, Game_UseCPE;
@@ -93,7 +91,7 @@ int ScheduledTask_Add(double interval, ScheduledTaskCallback callback) {


int Game_GetWindowScale(void) {
float windowScale = min(Game_Width / 640.0f, Game_Height / 480.0f);
float windowScale = min(Game.Width / 640.0f, Game.Height / 480.0f);
return 1 + (int)windowScale;
}

@@ -272,8 +270,8 @@ bool Game_ValidateBitmap(const String* file, Bitmap* bmp) {

void Game_UpdateClientSize(void) {
Size2D size = Window_ClientSize;
Game_Width = max(size.Width, 1);
Game_Height = max(size.Height, 1);
Game.Width = max(size.Width, 1);
Game.Height = max(size.Height, 1);
}

static void Game_OnResize(void* obj) {
@@ -354,7 +352,6 @@ static void Game_LoadOptions(void) {
Game_AllowCustomBlocks = Options_GetBool(OPT_CUSTOM_BLOCKS, true);
Game_UseCPE = Options_GetBool(OPT_CPE, true);
Game_SimpleArmsAnim = Options_GetBool(OPT_SIMPLE_ARMS_ANIM, false);
Game_ClassicArmModel = Options_GetBool(OPT_CLASSIC_ARM_MODEL, Game_ClassicMode);
Game_ViewBobbing = Options_GetBool(OPT_VIEW_BOBBING, true);

method = Options_GetEnum(OPT_FPS_LIMIT, 0, FpsLimit_Names, FPS_LIMIT_COUNT);
@@ -623,7 +620,7 @@ void Game_TakeScreenshot(void) {
res = Stream_CreateFile(&stream, &path);
if (res) { Logger_Warn2(res, "creating", &path); return; }

res = Gfx_TakeScreenshot(&stream, Game_Width, Game_Height);
res = Gfx_TakeScreenshot(&stream, Game.Width, Game.Height);
if (res) {
Logger_Warn2(res, "saving to", &path); stream.Close(&stream); return;
}
@@ -643,7 +640,7 @@ static void Game_RenderFrame(double delta) {
frameStart = Stopwatch_Measure();
Gfx_BeginFrame();
Gfx_BindIb(Gfx_defaultIb);
Game_Time += delta;
Game.Time += delta;
Game_Vertices = 0;

Camera.Active->UpdateMouse();
@@ -10,12 +10,15 @@
struct DisplayDevice;
struct Stream;

/* Width and height of the window. (1 at minimum) */
extern int Game_Width, Game_Height;
/* Total time (in seconds) the game has been running for. */
extern double Game_Time;
/* Number of chunks updated within last second. Resets to 0 after every second. */
extern int Game_ChunkUpdates;
CC_VAR extern struct _GameData {
/* Width and height of the window. (1 at minimum) */
int Width, Height;
/* Total time (in seconds) the game has been running for. */
double Time;
/* Number of chunks updated within last second. Resets to 0 after every second. */
int ChunkUpdates;
} Game;

extern struct PickedPos Game_SelectedPos;
extern bool Game_UseCPEBlocks;

@@ -34,7 +37,6 @@ extern float game_limitMs;
extern int Game_FpsLimit;
extern bool Game_ShowAxisLines;
extern bool Game_SimpleArmsAnim;
extern bool Game_ClassicArmModel;
extern int Game_Vertices;

extern bool Game_ClassicMode;
@@ -352,7 +352,7 @@ static void D3D9_FillPresentArgs(int width, int height, D3DPRESENT_PARAMETERS* a

static void D3D9_RecreateDevice(void) {
D3DPRESENT_PARAMETERS args = { 0 };
D3D9_FillPresentArgs(Game_Width, Game_Height, &args);
D3D9_FillPresentArgs(Game.Width, Game.Height, &args);

while (IDirect3DDevice9_Reset(device, &args) == D3DERR_DEVICELOST) {
D3D9_LoopUntilRetrieved();
@@ -1568,7 +1568,7 @@ void Gfx_EndFrame(void) {
}

void Gfx_OnWindowResize(void) {
glViewport(0, 0, Game_Width, Game_Height);
glViewport(0, 0, Game.Width, Game.Height);
GLContext_Update();
}
#endif
@@ -52,8 +52,8 @@ void Widget_SetLocation(void* widget, uint8_t horAnchor, uint8_t verAnchor, int

void Widget_CalcPosition(void* widget) {
struct Widget* w = widget;
w->X = Gui_CalcPos(w->HorAnchor, w->XOffset, w->Width , Game_Width );
w->Y = Gui_CalcPos(w->VerAnchor, w->YOffset, w->Height, Game_Height);
w->X = Gui_CalcPos(w->HorAnchor, w->XOffset, w->Width , Game.Width );
w->Y = Gui_CalcPos(w->VerAnchor, w->YOffset, w->Height, Game.Height);
}

void Widget_Reset(void* widget) {
@@ -240,7 +240,7 @@ void Gui_FreeOverlay(void* overlay) {

void Gui_RenderGui(double delta) {
bool showHUD, hudBefore;
Gfx_Mode2D(Game_Width, Game_Height);
Gfx_Mode2D(Game.Width, Game.Height);

showHUD = !Gui_Active || !Gui_Active->HidesHUD;
hudBefore = !Gui_Active || !Gui_Active->RenderHUDOver;
@@ -95,7 +95,7 @@ static void HeldBlockRenderer_SetBaseOffset(void) {

static void HeldBlockRenderer_ProjectionChanged(void* obj) {
float fov = 70.0f * MATH_DEG2RAD;
float aspectRatio = (float)Game_Width / (float)Game_Height;
float aspectRatio = (float)Game.Width / (float)Game.Height;
float zNear = Gfx_MinZNear;
Gfx_CalcPerspectiveMatrix(fov, aspectRatio, zNear, (float)Game_ViewDistance, &held_blockProjection);
}
@@ -305,7 +305,7 @@ static void ChooseModeScreen_Init(struct LScreen* s_) {

static void ChooseModeScreen_Reposition(struct LScreen* s_) {
struct ChooseModeScreen* s = (struct ChooseModeScreen*)s_;
int middle = Game_Width / 2;
int middle = Game.Width / 2;
LWidget_SetLocation(&s->LblTitle, ANCHOR_CENTRE, ANCHOR_CENTRE, 10, -135);

LWidget_SetLocation(&s->BtnEnhanced, ANCHOR_MIN, ANCHOR_CENTRE, middle - 250, -72);
@@ -325,7 +325,7 @@ static void ChooseModeScreen_Reposition(struct LScreen* s_) {
}

static void ChooseModeScreen_Draw(struct LScreen* s) {
int midX = Game_Width / 2, midY = Game_Height / 2;
int midX = Game.Width / 2, midY = Game.Height / 2;
LScreen_Draw(s);

Drawer2D_Rect(&Launcher_Framebuffer, Launcher_ButtonBorderCol,
@@ -1031,9 +1031,9 @@ static void ResourcesScreen_Draw(struct LScreen* s) {
BitmapCol backCol = BITMAPCOL_CONST( 12, 12, 12, 255);

Drawer2D_Clear(&Launcher_Framebuffer, backCol,
0, 0, Game_Width, Game_Height);
0, 0, Game.Width, Game.Height);
ResourcesScreen_ResetArea(
Game_Width / 2 - RESOURCES_XSIZE, Game_Height / 2 - RESOURCES_YSIZE,
Game.Width / 2 - RESOURCES_XSIZE, Game.Height / 2 - RESOURCES_YSIZE,
RESOURCES_XSIZE * 2, RESOURCES_YSIZE * 2);
LScreen_Draw(s);
}
@@ -1277,8 +1277,8 @@ static void ServersScreen_Reposition(struct LScreen* s_) {
LWidget_SetLocation(&s->BtnConnect, ANCHOR_MAX, ANCHOR_MAX, 10, 10);
LWidget_SetLocation(&s->BtnRefresh, ANCHOR_MAX, ANCHOR_MIN, 135, 10);

s->Table.Width = Game_Width - 10;
s->Table.Height = Game_Height - 100;
s->Table.Width = Game.Width - 10;
s->Table.Height = Game.Height - 100;
s->Table.Height = max(1, s->Table.Height);

LWidget_SetLocation(&s->Table, ANCHOR_MIN, ANCHOR_MIN, 10, 50);
@@ -1395,7 +1395,7 @@ static struct UpdatesScreen {
} UpdatesScreen_Instance;

static void UpdatesScreen_Draw(struct LScreen* s) {
int midX = Game_Width / 2, midY = Game_Height / 2;
int midX = Game.Width / 2, midY = Game.Height / 2;
LScreen_Draw(s);

Drawer2D_Rect(&Launcher_Framebuffer, Launcher_ButtonBorderCol,
@@ -23,8 +23,8 @@ void LWidget_SetLocation(void* widget, uint8_t horAnchor, uint8_t verAnchor, int

void LWidget_CalcPosition(void* widget) {
struct LWidget* w = widget;
w->X = Gui_CalcPos(w->HorAnchor, w->XOffset, w->Width, Game_Width);
w->Y = Gui_CalcPos(w->VerAnchor, w->YOffset, w->Height, Game_Height);
w->X = Gui_CalcPos(w->HorAnchor, w->XOffset, w->Width, Game.Width);
w->Y = Gui_CalcPos(w->VerAnchor, w->YOffset, w->Height, Game.Height);
}

void LWidget_Draw(void* widget) {
@@ -993,7 +993,7 @@ static void LTable_ScrollbarClick(struct LTable* w) {
static void LTable_MouseDown(void* widget, bool wasSelected) {
struct LTable* w = widget;

if (Mouse_X >= Game_Width - SCROLLBAR_WIDTH) {
if (Mouse_X >= Game.Width - SCROLLBAR_WIDTH) {
LTable_ScrollbarClick(w);
w->_lastRow = -1;
} else if (Mouse_Y < w->RowsBegY) {
Oops, something went wrong.

0 comments on commit 1ebd553

Please sign in to comment.