Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Filename: resource_camera.c |
3 |
|
|
* Path: sources/Resource |
4 |
|
|
* Created Date: Thursday, September 28th 2023, 2:38:28 pm |
5 |
|
|
* Author: osvegn |
6 |
|
|
* |
7 |
|
|
* Copyright (c) 2023 our_rpg |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include "resources.h" |
11 |
|
|
#include <raylib.h> |
12 |
|
|
#include <stdlib.h> |
13 |
|
|
|
14 |
|
|
static int resource_is_camera(resource_t *resource) |
15 |
|
|
{ |
16 |
|
✗ |
return (resource->type == R_CAMERA); |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
|
20 |
|
✗ |
int resource_camera_constructor(resource_t *resource, void *data) |
21 |
|
|
{ |
22 |
|
|
int rvalue = 0; |
23 |
|
|
|
24 |
|
✗ |
resource->type = R_CAMERA; |
25 |
|
✗ |
resource->destructor = resource_camera_destructor; |
26 |
|
✗ |
resource->data = malloc(sizeof(Camera2D)); |
27 |
|
✗ |
if (!resource->data) { |
28 |
|
|
return -1; |
29 |
|
|
} |
30 |
|
✗ |
if (!data) { |
31 |
|
✗ |
data = &(Camera2D){.offset=(Vector2){GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f}, .rotation=0.0f, .target=(Vector2){0, 0}, .zoom=1.0f}; |
32 |
|
|
} |
33 |
|
|
rvalue = resource_camera_set(resource, data); |
34 |
|
|
return rvalue; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
✗ |
int resource_camera_constructor_from_json(resource_t *resource, void *data) |
38 |
|
|
{ |
39 |
|
✗ |
return resource_camera_constructor(resource, 0); |
40 |
|
|
} |
41 |
|
|
|
42 |
|
✗ |
int resource_camera_destructor(resource_t *resource) |
43 |
|
|
{ |
44 |
|
✗ |
if (resource->data) |
45 |
|
✗ |
free(resource->data); |
46 |
|
✗ |
return 0; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
✗ |
int resource_camera_set(resource_t *resource, void *data) |
50 |
|
|
{ |
51 |
|
✗ |
if (!resource_is_camera(resource) || !data) |
52 |
|
|
return -1; |
53 |
|
✗ |
memcpy(resource->data, data, sizeof(Camera2D)); |
54 |
|
✗ |
return 0; |
55 |
|
|
} |
56 |
|
|
|