Permalink
Browse files

privatize context

  • Loading branch information...
1 parent c2c4e20 commit 7bce35d9ede07bfac8c7b21466cbdd03a9a8bb8a @bvanderveen committed Jan 24, 2012
Showing with 25 additions and 20 deletions.
  1. +1 −1 AppDelegate.h
  2. +4 −4 AppDelegate.m
  3. +14 −6 sim.c
  4. +6 −9 sim.h
View
@@ -3,7 +3,7 @@
@interface AppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
- sim_ctx simContext;
+ SimContextRef simContext;
}
@end
View
@@ -6,24 +6,24 @@ @implementation AppDelegate
void draw(double t, void *ctx) {
AppDelegate *del = (AppDelegate *)ctx;
- sim_update(del->simContext, t);
- sim_draw(del->simContext, t);
+ SimContextUpdate(del->simContext, t);
+ SimContextDraw(del->simContext, t);
}
- (id)init {
if (self = [super init]) {
NSRect bounds = NSMakeRect(0,0,400,400);
window = [[NSWindow alloc] initWithContentRect:bounds styleMask:NSTitledWindowMask | NSClosableWindowMask backing:NSBackingStoreBuffered defer:YES];
- simContext = sim_create();
+ simContext = SimContextCreate();
[window setContentView:[[[OpenGLView alloc] initWithFrame:bounds draw:draw context:self] autorelease]];
}
return self;
}
- (void)dealloc {
- sim_destroy(simContext);
+ SimContextDestroy(simContext);
[window release];
[super dealloc];
}
View
20 sim.c
@@ -3,22 +3,30 @@
#include <stdlib.h>
#include <OpenGL/gl.h>
+struct SimContext
+{
+ double t;
+};
+typedef struct SimContext *SimContext;
-sim_ctx sim_create() {
- sim_ctx result = (sim_ctx)malloc(sizeof(sim_ctx));
+SimContextRef SimContextCreate() {
+ SimContext result = (SimContext)malloc(sizeof(SimContext));
result->t = 0.0;
- return result;
+ return (SimContext)result;
}
-void sim_destroy(sim_ctx c) {
+void SimContextDestroy(SimContextRef c) {
free(c);
}
-void sim_update(sim_ctx ctx, double t) {
+void SimContextUpdate(SimContextRef c, double t) {
+ SimContext ctx = c;
ctx->t += t * .0001;
}
-void sim_draw(sim_ctx ctx, double t) {
+void SimContextDraw(SimContextRef c, double t) {
+ SimContext ctx = c;
+
glRotated(ctx->t, 0,0,1);
glClearColor(0,0,0,0);
View
15 sim.h
@@ -1,12 +1,9 @@
-struct sim_ctx_t
-{
- double t;
-};
-typedef struct sim_ctx_t *sim_ctx;
-sim_ctx sim_create();
-void sim_destroy(sim_ctx c);
+typedef void *SimContextRef;
-void sim_update(sim_ctx c, double t);
-void sim_draw(sim_ctx c, double t);
+SimContextRef SimContextCreate();
+void SimContextDestroy(SimContextRef c);
+
+void SimContextUpdate(SimContextRef c, double t);
+void SimContextDraw(SimContextRef c, double t);

0 comments on commit 7bce35d

Please sign in to comment.