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