Skip to content

Commit

Permalink
Separated tiny into its own directory (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodpaul6 authored Apr 18, 2019
1 parent 86c5fa7 commit 1a942de
Show file tree
Hide file tree
Showing 21 changed files with 33 additions and 41 deletions.
25 changes: 1 addition & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@ project(tiny)

cmake_minimum_required(VERSION 3.1)

set(SOURCES
src/tiny.c
src/array.c
src/dict.c
src/tinystd.c
src/tiny_lexer.c
src/tiny_util.c
src/t_mem.c)

add_library(tiny STATIC ${SOURCES})

add_definitions(-DTINY_MEM_CHECK)

if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DTINY_MEM_STACK_TRACE_COUNT=10)
target_link_libraries(tiny PRIVATE dbghelp.lib)
endif()

if(UNIX)
target_link_libraries(tiny PRIVATE m)
endif()

target_include_directories(tiny PUBLIC include)

add_subdirectory(tiny)
add_subdirectory(examples)
add_subdirectory(test)

2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
* Make sure VM bytecode instructions and data are aligned properly (DONE)

* Refactor VM from compiler

* First class types (store a "type" which is just an integer in the VM)
* Safer "any" type: must be explicitly converted (DONE)

Expand Down
34 changes: 17 additions & 17 deletions examples/game/src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ static Tiny_State* EntityStates[NUM_ENTITY_TYPES];
typedef struct
{
int hp;
double x, y;
double velX, velY;
float x, y;
float velX, velY;
bool playerBullet;
Tiny_StateThread thread;
} Entity;

static Entity Ents[MAX_ENTITIES] = { 0 };

static Entity* AddEnt(int hp, double x, double y, EntityType type)
static Entity* AddEnt(int hp, float x, float y, EntityType type)
{
for(int i = 0; i < MAX_ENTITIES; ++i) {
if(Ents[i].hp <= 0) {
Expand Down Expand Up @@ -100,16 +100,16 @@ static Tiny_Value AddBullet(Tiny_StateThread* thread, const Tiny_Value* args, in
{
assert(count == 3);

double x = Tiny_ToNumber(args[0]);
double y = Tiny_ToNumber(args[1]);
double angle = Tiny_ToNumber(args[2]) * (M_PI / 180);
float x = Tiny_ToNumber(args[0]);
float y = Tiny_ToNumber(args[1]);
float angle = Tiny_ToNumber(args[2]) * (float)(M_PI / 180);

Entity* b = AddEnt(1, x, y, ENT_BULLET);

if(b) {
b->playerBullet = thread->state == EntityStates[ENT_PLAYER];
b->velX = 5 * cos(angle);
b->velY = 5 * sin(angle);
b->velX = 5 * cosf(angle);
b->velY = 5 * sinf(angle);
}

return Tiny_Null;
Expand All @@ -125,13 +125,13 @@ static Tiny_Value AccelAngle(Tiny_StateThread* thread, const Tiny_Value* args, i
{
assert(count == 2);

double angle = Tiny_ToNumber(args[0]) * (M_PI / 180);
double speed = Tiny_ToNumber(args[1]);
float angle = Tiny_ToNumber(args[0]) * (float)(M_PI / 180);
float speed = Tiny_ToNumber(args[1]);

Entity* e = thread->userdata;

e->velX += cos(angle) * speed;
e->velY += sin(angle) * speed;
e->velX += cosf(angle) * speed;
e->velY += sinf(angle) * speed;

return Tiny_Null;
}
Expand All @@ -152,15 +152,15 @@ static Tiny_Value AccelTowards(Tiny_StateThread* thread, const Tiny_Value* args,
{
assert(count == 2);

double speed = Tiny_ToNumber(args[1]);
float speed = Tiny_ToNumber(args[1]);

Entity* e = thread->userdata;
Entity* o = Tiny_ToAddr(args[0]);

double angle = atan2(o->y - e->y, o->x - e->x);
float angle = atan2f(o->y - e->y, o->x - e->x);

e->velX += cos(angle) * speed;
e->velY += sin(angle) * speed;
e->velX += cosf(angle) * speed;
e->velY += sinf(angle) * speed;

return Tiny_Null;
}
Expand Down Expand Up @@ -417,7 +417,7 @@ int main(int argc, char** argv)
PlayerKills += 1;
}
} else {
float angle = atan2(Ents[i].y - Ents[j].y, Ents[i].x - Ents[j].x);
float angle = atan2f(Ents[i].y - Ents[j].y, Ents[i].x - Ents[j].x);
float repel = (10 - sqrtf(dist2));

float c = cosf(angle);
Expand Down
13 changes: 13 additions & 0 deletions tiny/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
file(GLOB SOURCES src/*.c)

add_library(tiny STATIC ${SOURCES})

if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DTINY_MEM_STACK_TRACE_COUNT=10)
endif()

if(UNIX)
target_link_libraries(tiny PRIVATE m)
endif()

target_include_directories(tiny PUBLIC include)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 1a942de

Please sign in to comment.