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