asset loader

main
sandyx86 1 year ago
parent ed02026f7e
commit b86f332fc3

@ -0,0 +1,21 @@
#ifndef YSARRAY_H
#define YSARRAY_H
#import "YSObject.h"
@interface YSArray : YSObject {
//public so you can index it directly
@public
id *array;
unsigned int count;
unsigned int cap;
}
-(void) addObject: (id) theObject;
-(void) removeObject: (unsigned int) index;
-(unsigned int) capacity;
-(void) setCapacity: (unsigned int) c;
@end
#endif

@ -0,0 +1,23 @@
#ifndef YSBITFIELD_H
#define YSBITFIELD_H
#include <stdbool.h>
#import "YSObject.h"
@interface YSBitField : YSObject {
int x : 1;
int y : 1;
int z : 1;
int w : 1;
int h : 4;
}
-(bool) x;
-(bool) y;
-(bool) z;
-(bool) w;
-(unsigned int) h;
@end
#endif

@ -0,0 +1,40 @@
#ifndef YSOBJECT_H
#define YSOBJECT_H
#define BOOL int
@protocol YSObject
+(void) load;
+(void) initialize;
+(id) alloc;
+(id) new;
+(Class) class;
-(void) dealloc;
-(id) init;
+(Class) superclass;
-(Class) superclass;
+(Class) class;
-(BOOL) isEqual: (id) anObject;
+(BOOL) isKindOfClass: (Class) theClass;
@end
@interface YSObject <YSObject> {
Class isa;
}
+(void) load;
+(void) initialize;
+(id) alloc;
+(id) new;
+(Class) class;
-(void) dealloc;
-(id) init;
+(Class) superclass;
-(Class) superclass;
+(Class) class;
-(BOOL) isEqual: (id) anObject;
+(BOOL) isKindOfClass: (Class) theClass;
@end
#endif

@ -0,0 +1,21 @@
#ifndef YSSTRING_H
#define YSSTRING_H
#import "YSObject.h"
//does it make sense to subclass YSObject?
//probably not but it would be fun to
//deallocate a constant string
@interface YSConstantString : YSObject {
char *c_string;
unsigned int len;
}
-(const char *) cString;
-(unsigned int) length;
-(void) dealloc;
@end
#endif

@ -0,0 +1,18 @@
#ifndef YSVECTOR_H
#define YSVECTOR_H
#import <immintrin.h>
#import "YSObject.h"
@interface YSVector : YSObject {
@public
__m256i vector;
}
-(__m256i) vector;
-(__m256i) add: (YSVector *) vector;
-(void) set: (int)v1 : (int)v2 : (int)v3 : (int)v4 : (int)v5 : (int)v6 : (int)v7 : (int)v8;
-(void) setWithVector: (__m256i) v;
@end
#endif

File diff suppressed because it is too large Load Diff

@ -0,0 +1,5 @@
#import "YSObject.h"
#import "YSArray.h"
#import "YSString.h"
//#import "YSBitField.h"
//#import "YSVector.h"

@ -0,0 +1 @@
libobjc.so.1

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,18 +1,15 @@
SHELL=/bin/sh
APP_NAME=main
APP_NAME=wow
CC=gcc
OS := linux
LIBPATH =
MINGW=x86_64-w64-mingw32-gcc
MINGW_CFLAGS=-march=native -I raylib-w64/include -L raylib-w64/lib
MINGW_C_LIBS=-lraylib
INCLUDE= -I include
CFLAGS= -march=native
C_LIBS= -L lib -lraylib -lyesmath
OBJC_FLAGS := $(shell gnustep-config --objc-flags)
OBJC_LIBS := $(shell gnustep-config --base-libs)
CC := gcc
INCLUDE := -I include
LIB := -lraylib -lm -lyeslib
CFLAGS := -g -O2
OBJC_FLAGS := -fconstant-string-class=YSConstantString -fno-strict-aliasing -fexceptions -fobjc-exceptions -fobjc-std=objc1
#dirs
SRC=src
@ -24,29 +21,29 @@ M_FILES := $(shell find $(SRC) -name '*.m')
O_FILES := $(patsubst $(SRC)/%.m, $(BUILD)/%.o, $(M_FILES))
O_FILES += $(patsubst $(SRC)/%.c, $(BUILD)/%.o, $(C_FILES))
.PHONY: native clean setup
native: $(APP_NAME)
$(APP_NAME): $(BUILD)/$(O_FILES)
$(CC) $(INCLUDE) $(CFLAGS) $(O_FILES) -o $(APP_NAME) $(OBJC_LIBS) $(C_LIBS)
$(BUILD)/%.o: $(SRC)/%.m
$(CC) $(INCLUDE) $(OBJC_FLAGS) -c $< -o $@
ifeq ($(OS), windows)
CC=x86_64-w64-mingw32-gcc
LIBPATH := -L lib/win64
LIB += -lopengl32 -lgdi32 -lwinmm -luser32 -l:objc-1.dll
endif
$(BUILD)/%.o: $(SRC)/%.c
$(CC) $(INCLUDE) $(CFLAGS) -c $< -o $@
ifeq ($(OS), linux)
LIBPATH := -L lib/linux64
LIB += -l:libobjc.so
endif
.PHONY: all clean setup
debug: $(APP_NAME)
all: $(APP_NAME)
$(APP_NAME): $(BUILD)/$(O_FILES)
$(CC) $(INCLUDE) $(CFLAGS) $(O_FILES) -o $(APP_NAME) $(OBJC_LIBS) $(C_LIBS)
$(CC) $(INCLUDE) $(CFLAGS) $(OBJC_FLAGS) $(O_FILES) -o $(APP_NAME) $(LIBPATH) $(LIB)
$(BUILD)/%.o: $(SRC)/%.m
$(CC) $(INCLUDE) -DDEBUG $(OBJC_FLAGS) -c $< -o $@
$(CC) $(INCLUDE) $(CFLAGS) $(OBJC_FLAGS) -c $< -o $@
$(BUILD)/%.o: $(SRC)/%.c
$(CC) $(INCLUDE) -DDEBUG $(CFLAGS) -c $< -o $@
$(CC) $(INCLUDE) $(CFLAGS) -c $< -o $@
setup:
$(shell mkdir -p $(BUILD))

@ -0,0 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd poop.png

@ -0,0 +1,183 @@
# Blender v3.0.1 OBJ File: ''
# www.blender.org
mtllib thing.mtl
o Cube
v 1.000000 0.673036 -0.864567
v 0.864567 0.864567 -1.000000
v 0.864567 1.000000 -0.864567
v 1.000000 0.864567 -0.673036
v 0.673036 -0.864567 -1.000000
v 0.864567 -0.673036 -1.000000
v 1.000000 -0.864567 -0.864567
v 0.864567 -1.000000 -0.673036
v 0.673036 -1.000000 -0.864567
v 0.864567 0.673036 1.000000
v 1.000000 0.864567 0.864567
v 0.864567 1.000000 0.673036
v 0.673036 1.000000 0.864567
v 0.673036 0.864567 1.000000
v 1.000000 -0.673036 0.864567
v 0.864567 -0.864567 1.000000
v 0.864567 -1.000000 0.864567
v 1.000000 -0.864567 0.673036
v -0.864567 0.673036 -1.000000
v -1.000000 0.864567 -0.864567
v -0.864567 1.000000 -0.673036
v -0.673036 1.000000 -0.864567
v -0.673036 0.864567 -1.000000
v -1.000000 -0.864567 -0.673036
v -1.000000 -0.673036 -0.864567
v -0.864567 -0.864567 -1.000000
v -0.864567 -1.000000 -0.864567
v -1.000000 0.673036 0.864567
v -0.864567 0.864567 1.000000
v -0.864567 1.000000 0.864567
v -1.000000 0.864567 0.673036
v -0.864567 -1.000000 0.673036
v -0.673036 -1.000000 0.864567
v -0.673036 -0.864567 1.000000
v -0.864567 -0.673036 1.000000
v -1.000000 -0.864567 0.864567
vt 0.040961 0.594467
vt 0.976233 1.373542
vt 0.976232 0.594467
vt -0.075541 1.704875
vt -0.075541 2.483950
vt 0.859731 2.483950
vt 0.040961 1.607830
vt 0.976233 2.386904
vt 0.976232 1.607830
vt 0.040961 -0.418895
vt 0.976233 0.360179
vt 0.976232 -0.418895
vt 1.140991 0.691513
vt 1.140991 1.470587
vt 2.076262 1.470587
vt -0.075541 -1.335213
vt -0.075541 -0.556138
vt 0.859731 -0.556138
vt -1.292072 0.691513
vt -1.292072 1.470587
vt -0.356802 1.470587
vt 0.040961 -1.432258
vt 0.976233 -0.653183
vt 0.976232 -1.432258
vt 1.257493 0.594467
vt 2.192764 1.373542
vt 2.192764 0.594467
vt -1.175571 0.594467
vt -0.240299 1.373542
vt -0.240299 0.594467
vt -0.075541 0.691513
vt -0.075541 1.470587
vt 0.859731 1.470587
vt 0.040961 0.525846
vt -0.075541 0.525846
vt -0.157920 0.457225
vt -0.075541 0.525846
vt 1.257493 0.525846
vt 1.099801 0.560157
vt 1.058612 0.594467
vt 1.058612 0.691512
vt 1.199242 0.642990
vt -0.075541 1.539209
vt -0.116731 1.573519
vt -0.058480 1.622041
vt -0.017290 1.656352
vt 0.859731 1.539209
vt 0.976232 1.539209
vt 1.058612 1.607830
vt 0.976232 1.539209
vt 0.040961 -0.487517
vt -0.075541 -0.487517
vt -0.157920 -0.653183
vt -0.157920 -0.556138
vt -0.075541 -0.487517
vt 0.917982 -0.604661
vt 1.017422 -0.521827
vt 1.058612 -0.556138
vt -0.075541 -1.500879
vt -0.116731 -1.466568
vt -0.017290 -1.383735
vt 2.134513 1.422065
vt 2.175703 1.456375
vt 2.233954 1.504898
vt 2.275143 1.470587
vt 2.275143 0.691512
vt 2.192764 0.525846
vt 0.859731 0.457225
vt -0.075541 0.457225
vt 0.859731 -1.500879
vt -0.157920 1.704875
vt -0.157920 2.483950
vt 1.140991 1.539209
vt 2.076262 1.539209
vt -0.157920 -1.432258
vt -0.157920 -0.321850
vt -0.075541 -0.321850
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 0.0000 -1.0000
vn 0.0000 -1.0000 0.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 0.8629 0.3574 -0.3574
vn 0.3501 -0.6624 -0.6624
vn 0.3501 0.6624 0.6624
vn 0.8629 -0.3574 0.3574
vn -0.3501 0.6624 -0.6624
vn -0.8629 -0.3574 -0.3574
vn -0.8629 0.3574 0.3574
vn -0.3501 -0.6624 0.6624
vn -0.7071 -0.7071 0.0000
vn 0.0000 -0.7071 -0.7071
vn 0.7071 0.0000 -0.7071
vn -0.7071 0.0000 0.7071
vn 0.7071 0.0000 0.7071
vn -0.7071 0.0000 -0.7071
vn 0.0000 0.7071 0.7071
vn 0.7071 0.7071 0.0000
vn 0.0000 -0.7071 0.7071
vn -0.7071 0.7071 0.0000
vn 0.0000 0.7071 -0.7071
vn 0.7071 -0.7071 0.0000
usemtl Material
s off
f 1/1/1 18/2/1 7/3/1
f 14/4/2 29/5/2 35/6/2
f 10/7/2 34/8/2 16/9/2
f 19/10/3 5/11/3 26/12/3
f 8/13/4 17/14/4 33/15/4
f 31/16/5 20/17/5 25/18/5
f 21/19/6 30/20/6 13/21/6
f 28/22/5 24/23/5 36/24/5
f 9/25/4 32/26/4 27/27/4
f 22/28/6 12/29/6 3/30/6
f 4/31/1 11/32/1 15/33/1
f 1/34/7 2/35/7 3/36/7 4/37/7
f 5/38/8 6/39/8 7/40/8 8/41/8 9/42/8
f 10/7/9 11/43/9 12/44/9 13/45/9 14/46/9
f 15/47/10 16/48/10 17/49/10 18/50/10
f 19/51/11 20/52/11 21/53/11 22/54/11 23/55/11
f 24/23/12 25/56/12 26/57/12 27/58/12
f 28/22/13 29/59/13 30/60/13 31/61/13
f 32/26/14 33/62/14 34/63/14 35/64/14 36/65/14
f 27/27/15 32/26/15 36/65/15 24/66/15
f 9/25/16 27/27/16 26/67/16 5/38/16
f 1/1/17 7/3/17 6/68/17 2/69/17
f 35/70/18 29/59/18 28/22/18 36/24/18
f 10/7/19 16/9/19 15/33/19 11/32/19
f 19/10/20 26/12/20 25/18/20 20/17/20
f 13/71/21 30/72/21 29/5/21 14/4/21
f 3/30/22 12/29/22 11/32/22 4/31/22
f 33/15/23 17/14/23 16/73/23 34/74/23
f 30/75/24 21/53/24 20/17/24 31/16/24
f 22/76/25 3/36/25 2/69/25 23/77/25
f 17/14/26 8/13/26 7/3/26 18/2/26
f 12/29/6 22/28/6 21/19/6 13/21/6
f 34/8/2 10/7/2 14/4/2 35/6/2
f 24/23/5 28/22/5 31/16/5 25/18/5
f 32/26/4 9/25/4 8/13/4 33/15/4
f 18/2/1 1/1/1 4/31/1 15/33/1
f 5/11/3 19/10/3 23/77/3 6/68/3
f 23/77/3 2/69/3 6/68/3

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

@ -0,0 +1,34 @@
#ifndef ACTIVATOR_H
#define ACTIVATOR_H
#import <yeslib.h>
//activators keep a list of objects to
//send an activation message to
@protocol Activator
-(void) activate;
-(void) registerObject: (id) receiver;
@end
//receiver of activation messages
@protocol Receiver
-(void) activate;
@end
@interface Activator : YSObject <Activator> {
YSArray *receivers;
}
-(void) activate;
-(void) registerObject: (id) receiver;
@end
@interface Receiver : YSObject <Receiver> {
}
-(void) activate;
@end
#endif

@ -0,0 +1,27 @@
#import "Activator.h"
/*
may be able to use _Generic to send activate message
only to objects that implement Receiver protocol,
Activator protocol, or has an activate method.
*/
@implementation Activator
//send activate message to receivers
-(void) activate {
int i = 0;
//Objective-C 1.0 does not support fast enumeration
for (i; i < receivers->count; i++) {
[receivers->array[i] activate];
}
}
//register a receiver
-(void) registerObject: (id) receiver {
[receivers addObject: receiver];
}
@end

@ -0,0 +1,20 @@
#ifndef ASSETLOADER_H
#define ASSETLOADER_H
#import <raylib.h>
#import <yeslib.h>
#import "parser.h"
#import "Model.h"
@interface AssetLoader : YSObject {
YSArray *drawables;
}
//@property (copy) NSMutableArray *drawables;
//-(id) init;
-(void) draw;
-(void) loadAssetFile: (const char *) path;
-(void) printAllAssets;
@end
#endif

@ -0,0 +1,136 @@
#import "AssetLoader.h"
@implementation AssetLoader
//@synthesize drawables;
-(id) init {
if ((self = [super init])) {
drawables = [[YSArray alloc] init];
}
return self;
}
-(void) draw {
int i;
for (i = 0; i < drawables->count; i++) {
//printf("i should be drawing: %p\n", drawables->array[i]);
[drawables->array[i] draw];
}
return;
}
//game specific parts of the parser
enum {
MDL = 0,
TEX = 1,
POS = 2,
};
typedef struct Resource {
int type;
char *path;
Vector3 pos;
} Resource;
Vector3 parse_pos(char *buffer) {
Vector3 vec;
vec.x = strtof( buffer, NULL);
vec.y = strtof( get_next_token(buffer, ", ", 0), NULL);
vec.z = strtof( get_next_token(buffer, ", ", 0), NULL);
printf("got vector: %f %f %f\n", vec.x, vec.y, vec.z);
return vec;
}
Resource parse_line(char *buffer) {
char *token = get_next_token(buffer, ": ", 0);
if (token == NULL) {
get_next_token(NULL, NULL, 1);
}
Resource r = {0};
if (strcmp(token, "obj") == 0) {
r.type = MDL;
goto GET_PATH;
}
if (strcmp(token, "tex") == 0) {
r.type = TEX;
goto GET_PATH;
}
if (strcmp(token, "pos") == 0) {
r.type = POS;
goto GET_POS;
}
GET_PATH:
r.path = get_next_token(buffer, ": ", 0);
goto END;
GET_POS:
r.pos = parse_pos( get_next_token(buffer, ": ", 0) );
END:
get_next_token(NULL, NULL, 1);
return r;
}
-(void) loadAssetFile: (const char *) path {
char *file = load_file( path );
char *line;
char *s;
NSModel *m;
for (line = get_next_line(file, 0); line != NULL; line = get_next_line(file, 0)) {
//debug
Resource r = parse_line(line);
if (r.path == NULL) {
goto SKIP_PATH;
}
s = r.path;
switch (r.type) {
case MDL:
//suck cock
m = [NSModel alloc];
[m initWithModel: s];
break;
case TEX:
[m setTexture: s];
break;
SKIP_PATH:
case POS:
[m setPos: r.pos];
[drawables addObject: m];
break;
}
}
#ifdef DEBUG
int i;
for (i = 0; i < drawables->count; i++) {
printf("%p\n", drawables->array[i]);
printf("%f %f %f\n", [drawables->array[i] pos].x, [drawables->array[i] pos].y, [drawables->array[i] pos].z);
}
printf("count: %d\n", drawables->count);
printf("capacity: %d\n", drawables->cap);
#endif
}
-(void) printAllAssets {
printf("capacity: %d\n", [drawables capacity]);
}
@end

@ -2,15 +2,20 @@
#define CAMERA_H
#import <stdio.h>
#import <Foundation/Foundation.h>
#import <raylib.h>
#import <yesmath.h>
//#import <yesmath.h>
#import <yeslib.h>
#import "Player.h"
@class Player;
@interface GameCamera : NSObject {
@interface GameCamera : YSObject {
@public
Camera3D camera;
@private
int mode;
Player *attachedPlayer;
@ -18,8 +23,6 @@
Color crosshairColor;
float crosshairSize;
}
@property Camera3D camera;
@property int mode;
-(id) init;
-(void) update;

@ -1,9 +1,15 @@
#import "Camera.h"
#import "properties.h"
//"fixes" a weird bug with calling GetRayCollisionBox inside a method
RayCollision ObjectiveCBugFixRaycast(Camera3D camera, BoundingBox bbox) {
Vector3 direction = Vector3Subtract(camera.target, camera.position);
direction = Vector3Normalize(direction);
RayCollision rc = GetRayCollisionBox((Ray){camera.position, direction}, bbox);
return rc;
}
@implementation GameCamera
@synthesize camera;
@synthesize mode;
-(id) init {
if ((self = [super init])) {
@ -28,12 +34,13 @@
CameraYaw(&camera, -mouseDelta.x * 0.008, false);
CameraPitch(&camera, -mouseDelta.y * 0.008, true, false, false);
camera.position = [attachedPlayer pos];
//camera.position = [attachedPlayer pos];
}
-(void) attach: (Player *) player {
attachedPlayer = player;
[attachedPlayer setAttachedCamera: self];
attachedPlayer->attachedCamera = self;
//[attachedPlayer setAttachedCamera: self];
}
-(void) showPos {
@ -53,8 +60,8 @@
}
-(void) drawWeapon {
if (attachedPlayer != nil) {
Texture2D texture = [attachedPlayer weapon];
if (attachedPlayer != NULL) {
Texture2D texture = attachedPlayer->weapon;
DrawTexture(texture, 0.0f, 0.0f, WHITE);
}
}
@ -73,7 +80,7 @@
#ifdef DEBUG
BeginMode3D(camera);
DrawBoundingBox(bbox, BLUE);
//DrawBoundingBox(bbox, BLUE);
#endif
EndMode3D();

@ -1,10 +0,0 @@
#ifndef CHARACTER_H
#define CHARACTER_H
#import <raylib.h>
#import <yesmath.h>
@interface Character : NSObject {
BoundingBox bbox;
}
@end

@ -1,22 +0,0 @@
#ifndef ENEMY_H
#define ENEMY_H
#import <Foundation/Foundation.h>
#import <raylib.h>
#import <yesmath.h>
//just a simple enemy that follows the player for now
@interface Enemy : NSObject {
Texture2D texture;
Vector3 pos;
BoundingBox bbox;
}
-(id) init;
//-(void) Attack;
//-(void) Moan;
-(void) Render: (Camera3D) camera;
@end
#endif

@ -1,19 +0,0 @@
#import "Enemy.h"
@implementation Enemy
-(id) init {
if ( (self = [super init]) ) {
Image image = LoadImage("star.png");
texture = LoadTextureFromImage(image);
UnloadImage(image);
}
return self;
}
-(void) Render: (Camera3D) camera {
DrawBillboard(camera, texture, (Vector3){0.0f, 0.0f, 0.0f}, 2.0f, WHITE);
}
@end

@ -4,11 +4,14 @@
#import <raylib.h>
#import "Player.h"
@interface InputHandler : NSObject {
@interface InputHandler : YSObject {
@public
Player *controllable;
@private
}
@property (assign) Player *controllable;
-(id) init;
-(void) handleInput;
@end

@ -2,7 +2,10 @@
@implementation InputHandler
@synthesize controllable;
-(id) init {
self = [super init];
return self;
}
-(void) handleInput {
static unsigned int set;

@ -0,0 +1,25 @@
#ifndef MODEL_H
#define MODEL_H
#import <raylib.h>
#import <yesmath.h>
#import <yeslib.h>
@interface NSModel : YSObject {
Model model;
Texture texture;
Vector3 pos;
float scale;
}
-(id) initWithModel: (const char *) path;
-(id) initWithModel: (const char *) mdl_path andTexture: (const char *) tex_path;
-(Vector3) pos;
-(void) setPos: (Vector3) p;
-(void) setTexture: (const char *) tex_path;
-(void) dealloc;
-(void) draw;
-(void) drawBoundingBox;
@end
#endif

@ -0,0 +1,60 @@
#import "Model.h"
@implementation NSModel
-(id) initWithModel: (const char *) path {
if ( (self = [super init]) ) {
model = LoadModel( path );
}
return self;
}
-(id) initWithModel: (const char *) mdl_path andTexture: (const char *) tex_path {
if ( (self = [super init]) ) {
model = LoadModel( mdl_path );
texture = LoadTexture( tex_path );
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
}
return self;
}
-(Vector3) pos {
return pos;
}
-(void) setPos: (Vector3) p {
pos = p;
}
-(void) setTexture: (const char *) tex_path {
//maybe unload previous texture if any
texture = LoadTexture( tex_path );
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
}
-(void) dealloc {
UnloadModel(model);
//unload texture too
[super dealloc];
}
-(void) draw {
DrawModel(model, pos, 1.0f, WHITE);
#define DEBUG
#ifdef DEBUG
[self drawBoundingBox];
#endif
}
-(void) drawBoundingBox {
BoundingBox bbox = GetModelBoundingBox(model);
bbox.min = Vector3Add(pos, bbox.min);
bbox.max = Vector3Add(pos, bbox.max);
DrawBoundingBox(bbox, RED);
}
@end

@ -1,25 +1,23 @@
#ifndef PLAYER_H
#define PLAYER_H
#import <Foundation/Foundation.h>
#import <raylib.h>
#import <yesmath.h>
#import <yeslib.h>
#import "Camera.h"
#import "SoundPlayer.h"
@class GameCamera;
@interface Player : NSObject {
@interface Player : YSObject {
@public
BoundingBox bbox;
float height;
Vector3 pos;
GameCamera *attachedCamera;
SoundPlayer *soundPlayer;
Texture2D weapon;
}
@property Vector3 pos;
@property (assign) GameCamera *attachedCamera;
@property Texture2D weapon;
@property (assign) SoundPlayer *soundPlayer;
-(id) init;
-(void) showPos;

@ -1,14 +1,11 @@
#import "Player.h"
@implementation Player
@synthesize pos;
@synthesize attachedCamera;
@synthesize soundPlayer;
@synthesize weapon;
-(id) init {
if ( (self = [super init] ) ) {
pos = (Vector3){0.0f, 2.0f, 0.0f};
height = 1.0f;
}
return self;
@ -32,10 +29,9 @@
Camera *cam = [attachedCamera addressOfCamera];
Vector3 forward = GetCameraForward( cam );
float distance = 0.1;
forward = Vector3Scale(forward, distance);
pos = Vector3Add(pos, forward);
cam->position = Vector3Add(pos, (Vector3){0.0f, height, 0.0f} );
cam->target = Vector3Add(cam->target, forward);
}
@ -45,22 +41,27 @@
float distance = 0.1;
forward = Vector3Scale(forward, distance);
pos = Vector3Subtract(pos, forward);
cam->position = Vector3Add(pos, (Vector3){0.0f, height, 0.0f} );
cam->target = Vector3Subtract(cam->target, forward);
}
-(void) moveLeft {
Camera *cam = [attachedCamera addressOfCamera];
Vector3 right = GetCameraRight( cam );
right = Vector3Scale(right, 0.1);
float distance = 0.1;
right = Vector3Scale(right, distance);
pos = Vector3Subtract(pos, right);
cam->position = Vector3Add(pos, (Vector3){0.0f, height, 0.0f} );
cam->target = Vector3Subtract(cam->target, right);
}
-(void) moveRight {
Camera *cam = [attachedCamera addressOfCamera];
Vector3 right = GetCameraRight( cam );
right = Vector3Scale(right, 0.1);
float distance = 0.1;
right = Vector3Scale(right, distance);
pos = Vector3Add(pos, right);
cam->position = Vector3Add(pos, (Vector3){0.0f, height, 0.0f} );
cam->target = Vector3Add(cam->target, right);
}

@ -1,8 +1,7 @@
#ifndef SOUNDPLAYER_H
#define SOUNDPLAYER_H
#import <Foundation/Foundation.h>
#include <raylib.h>
#import <yeslib.h>
/*
different things should have different sounds
@ -14,7 +13,7 @@
or should there be one soundplayer that plays all sounds
*/
@interface SoundPlayer : NSObject {
@interface SoundPlayer : YSObject {
Sound wav;
}

@ -1,38 +1,45 @@
#import <Foundation/Foundation.h>
#include <raylib.h>
#import <raylib.h>
#import <yeslib.h>
//#import <Foundation/Foundation.h>
#include "Enemy.h"
#include "Camera.h"
#include "SoundPlayer.h"
#include "InputHandler.h"
#include "properties.h"
//#import "Enemy.h"
#import "Camera.h"
//#import "SoundPlayer.h"
#import "InputHandler.h"
#import "AssetLoader.h"
#import "properties.h"
const int winWidth = 800;
const int winHeight = 600;
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//insert custom properties loader here
YSConstantString *cs = @"yes";
InitWindow(default_properties.width, default_properties.height, "Game :3");
SetTargetFPS(60);
DisableCursor();
GameCamera *camera = [[GameCamera alloc] init];
GameCamera *camera = [GameCamera alloc];
[camera init];
Player *player = [[Player alloc] init];
SoundPlayer *sp = [[SoundPlayer alloc] init];
Enemy *enemy = [[Enemy alloc] init];
//SoundPlayer *sp = [[SoundPlayer alloc] init];
//Enemy *enemy = [[Enemy alloc] init];
InputHandler *input = [[InputHandler alloc] init];
input.controllable = player;
player.soundPlayer = sp;
AssetLoader *assetLoader = [[AssetLoader alloc] init];
input->controllable = player;
[camera attach: player];
//player.soundPlayer = sp;
Image image = LoadImage("gun.png");
Texture2D tex = LoadTextureFromImage(image);
[player setWeapon: tex];
[camera attach: player];
[assetLoader loadAssetFile: "assets.al"];
while (!WindowShouldClose()) {
[camera update];
@ -42,27 +49,28 @@ int main(int argc, const char *argv[]) {
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D([camera camera]);
BeginMode3D(camera->camera);
DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY);
DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall
DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall
DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD);
DrawCube((Vector3){ 0.0f, 2.5f, -16.0f }, 32.0f, 5.0f, 1.0f, RED);
[assetLoader draw];
EndMode3D();
[camera showPos];
[camera showTarget];
[player showPos];
[camera drawCrosshair];
[camera raycast];
[enemy Render: [camera camera]];
DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);
//[enemy Render: [camera camera]];
//DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);
EndDrawing();
}
CloseWindow();
[pool drain];
//[pool drain];
return 0;
}

@ -1,6 +0,0 @@
//game specific headers
#include "Player.h"
#include "Camera.h"
#include "SoundPlayer.h"
#include "Enemy.h"

@ -0,0 +1,86 @@
#include "parser.h"
/*
I've separated this out into its own file
so it can be used anywhere, and be compiled
with any C standard that supports strtok_r.
*/
size_t get_file_len(FILE *file) {
fseek(file, 0, SEEK_END);
unsigned int len = ftell(file);
fseek(file, 0, SEEK_SET);
return len;
}
/*
loads a files and mallocates a buffer
and returns a pointer to it.
remember to free the buffer when you're done.
*/
char *load_file(const char *path) {
FILE *file = fopen(path, "r");
if (file == NULL) {
printf("%s\n", "Could not open file.");
return NULL;
}
size_t len = get_file_len(file);
char *buffer = malloc(len);
#pragma GCC diagnostic ignored "-Wunused-result"
fread(buffer, len, 1, file);
fclose(file);
return buffer;
}
char *get_next_line(char* buffer, bool clear) {
static char* saveptr;
static char *line;
if (clear) {
saveptr = NULL;
line = NULL;
return NULL;
}
if (saveptr == NULL) {
line = strtok_r(buffer, "\n", &saveptr);
} else {
if (line == NULL) {
saveptr = NULL;
return NULL;
}
line = strtok_r(NULL, "\n", &saveptr);
}
return line;
}
char *get_next_token(char *buffer, char *delim, bool clear) {
static char *saveptr;
static char *token;
if (clear) {
saveptr = NULL;
token = NULL;
return NULL;
}
if (saveptr == NULL) {
token = strtok_r(buffer, delim, &saveptr);
} else {
if (token == NULL) {
saveptr = NULL;
return NULL;
}
token = strtok_r(NULL, delim, &saveptr);
}
return token;
}

@ -0,0 +1,14 @@
#ifndef PARSER_H
#define PARSER_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
size_t get_file_len(FILE *file);
char *load_file(const char *path);
char *get_next_line(char* buffer, bool clear);
char *get_next_token(char *buffer, char *delim, bool clear);
#endif
Loading…
Cancel
Save