]> git.r.bdr.sh - rbdr/super-polarity/blob - src/actor_manager.c
c9303d2f85de18dc98565db872f9bdf20e108856
[rbdr/super-polarity] / src / actor_manager.c
1 //
2 // actor_manager.c
3 // Super Polarity
4 //
5 // Created by Ruben Beltran del Rio on 8/14/13.
6 // Copyright (c) 2013 Abuguet. All rights reserved.
7 //
8
9 #include <stdio.h>
10 #include "actor_manager.h"
11
12 void actorManagerUpdate(ActorManager *this, Uint32 dt) {
13 ActorNode *head = this->actors;
14
15 while (head != NULL) {
16 head->val->update(head->val, dt);
17 head = head->next;
18 }
19 }
20
21 void actorManagerDraw(ActorManager *this) {
22 ActorNode *head = this->actors;
23
24 while (head != NULL) {
25 head->val->draw(head->val);
26 head = head->next;
27 }
28 }
29
30 void actorManagerAddActor(ActorManager *this, Actor *actor) {
31 ActorNode *actorNode = malloc(sizeof(ActorNode*));
32 ActorNode **head = &this->actors;
33 ActorNode *temp;
34 actorNode->val = actor;
35 actorNode->next = NULL;
36
37 if (*head == NULL) {
38 *head = actorNode;
39 } else {
40 temp = *head;
41
42 while (temp->next != NULL) {
43 temp = temp->next;
44 }
45 temp->next = actorNode;
46 }
47 }
48
49 ActorManager* createActorManager () {
50 ActorManager *actorManager = malloc(sizeof(ActorManager*));
51 actorManager->actors = NULL;
52 actorManager->update = actorManagerUpdate;
53 actorManager->draw = actorManagerDraw;
54 actorManager->addActor = actorManagerAddActor;
55
56 return actorManager;
57 }