Game Maker's Garage Forum

Game Maker's Garage => Announcements => Topic started by: GMG Kurt on September 21, 2011, 04:54:37 PM

Title: programming TI-BASIC
Post by: GMG Kurt on September 21, 2011, 04:54:37 PM
So yeah. I'm just chillin at school messin with my calculator I had to get for math class. Then someone comes up and says "do you have games on there" The totally thinking he was pulling my leg I said "do you" "of course" he said and pull out his and shows me a simple ASCII game. So what do you know TI-83 (and of course TI-84) calculators can run games written in TI-BASIC. So I did some research, and the language is extremely simple, and allegedly follows BASIC syntax, but I see a larger resemblance to GM, and C.

This is a small project I'm undertaking. Make a game programmed in TI-BASIC on my calculator, in a week or die a failure.

any of you with any calculator in the TI system should check out the language, and wow your friends.

I'll probably make more industrious programs a problem checker, and polynomial evaluators, but for now I'm satisfied with the game.
Title: Re: programming TI-BASIC
Post by: Gan on September 21, 2011, 05:31:08 PM
I have mario and puzzle blocks on my calculator. Very entertaining during a dull math lecture.
Best part, the teacher has no idea.
Title: Re: programming TI-BASIC
Post by: Zoo on September 21, 2011, 08:22:12 PM
Ohh... Is it one of those fancy graphing calculator with all sorts of bells and whistles like the ability to use Microsoft word and Excel, go on the internet, and play games IN COLOR? Or is it just a regular-type graphing calculator?
Googled. I see now.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on September 22, 2011, 02:29:22 PM
how do you have mario on your calculator? or is it a different one?
Title: Re: programming TI-BASIC
Post by: Gan on September 22, 2011, 03:42:47 PM
It's a T-84 calculator and one of the programs is Mario. It's actually the Mario game, jump on goombas, get the coins by bumping blocks, ect.

I'm not sure how it got on my calculator, I'm just happy I have it.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on September 22, 2011, 04:58:37 PM
Well I'll have to find that. I was just going to make something simple and stupid. perhaps a defend the castle, but to my current knowledge there's no way to have more than one sprite without redrawing the whole screen every time.
Title: Re: programming TI-BASIC
Post by: Charlo on September 22, 2011, 06:29:34 PM
TI-84 calculators can be programmed both with Assembly and BASIC.  The graphical games are made in Assembly.

I did once program something simple for my calculator in BASIC, but I didn't experiment with it for long.  

The teachers at my high school were wise to calculator games, however, and would crack down on students playing during class.  But it was useful when you were done with a test before everybody else.
Title: Re: programming TI-BASIC
Post by: Gnome on September 22, 2011, 08:10:18 PM
I once was really into it.

I made a complete SIMS text-based game on it, was chill.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on September 22, 2011, 09:51:19 PM
whoa really! can you send a link! Also any good sites? haven't found a good one yet.

assembly whats that? I thought that C was an assembly language. Are you telling me its a whole different shebang? <=shebang is my word of the day
Title: Re: programming TI-BASIC
Post by: x on September 23, 2011, 07:54:31 PM
Quote
whoa really! can you send a link! Also any good sites? haven't found a good one yet.

assembly whats that? I thought that C was an assembly language. Are you telling me its a whole different shebang? <=shebang is my word of the day


C is most definitely NOT assembly language. Its just closer to it than most high level languages. An assembly language uses the instruction set of the processor, so 80x86 or MMIX for example. You use the registers in the CPU, and directly control memory access (none of this watered down business C does). However it usually ends up being extremely convoluted and hard to finish large projects in. Which is why C was invented actually. I think of C as platform independent assembly language with lots of built in features like functions and libraries and void pointers.

As far as programming languages can be classified, C is in the same tier as GM.
Title: Re: programming TI-BASIC
Post by: Connors on September 23, 2011, 11:53:45 PM
Woah hold on how is it so close to GM? ???
Title: Re: programming TI-BASIC
Post by: x on September 24, 2011, 05:26:41 AM
Quote
Woah hold on how is it so close to GM? ???

I didn't say it was close, I just they fall into the same category. They are both high level languages, separated from assembly language.
Title: Re: programming TI-BASIC
Post by: Gan on September 24, 2011, 10:46:52 AM
Anyone notice that a TI calculator costs about the same as an iPhone but is still technology from the old days?

Seriously, we pay big bucks for something we could've bought ten+ years ago.
2 color screen, clunky body, slow screen refresh rate, probably a very tiny amount of ram, no internet browsing...
If it was a smart phone it'd be the crapiest one around.
Title: Re: programming TI-BASIC
Post by: Zoo on September 24, 2011, 10:58:23 AM
Quote
Ohh... Is it one of those fancy graphing calculator with all sorts of bells and whistles like the ability to use Microsoft word and Excel, go on the internet, and play games IN COLOR?
What universe are you in, Gan? Our math class had to buy these for $125.00 (Considerably cheaper than an Ipod touch/iPhone)
Title: Re: programming TI-BASIC
Post by: Gan on September 24, 2011, 11:04:51 AM
I believe you can get an iPhone 3GS for $99 or 3G $45. or wait, does that require a plan...

These things come in color?
Title: Re: programming TI-BASIC
Post by: Zoo on September 24, 2011, 01:24:02 PM
Yeah, 16bit, I believe.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on September 24, 2011, 06:46:27 PM
Quote
Woah hold on how is it so close to GM? ???

C is almost exactly like GM, syntax just involves more parenthesis, and C can do more stuff

Ti-BASIC is also similar to BASIC, which is similar to GM. Let me put it this way. If you found your way to a TI-BASIC operations manual. You'd understand everything, and be programming as well in it as you would with GM.

EDIT: whoa they really come in color! mines just black LED light letters. Or something like that.
Title: Re: programming TI-BASIC
Post by: Gan on September 24, 2011, 08:09:57 PM
Quote
C is almost exactly like GM, syntax just involves more parenthesis, and C can do more stuff
C is a lot different than GM. You got methods, you malloc your resources, you got structs you can make, pointers(WHICH I LOVE!), and syntax is completely different. GM is to C as a Toothpick is to a Horse. The similarities are few but a horse is much more powerful than a toothpick.

Quote
EDIT: whoa they really come in color! mines just black LED light letters. Or something like that.
Same, I just got a black and white one.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on September 24, 2011, 08:37:58 PM
Quote
C is a lot different than GM. You got methods, you malloc your resources, you got structs you can make, pointers(WHICH I LOVE!), and syntax is completely different. GM is to C as a Toothpick is to a Horse. The similarities are few but a horse is much more powerful than a toothpick.

Same, I just got a black and white one.

well when you put it like that... I just remember learning it I could compare tons of things to GM. It the end your right, but for some reason I'll always thing of them as brothers (C being the older brother)
Title: Re: programming TI-BASIC
Post by: x on September 28, 2011, 09:08:56 PM
They are all high level languages (just).
Title: Re: programming TI-BASIC
Post by: GabrielCA on October 24, 2011, 07:59:55 PM
Quote
the language is extremely simple, and allegedly follows BASIC syntax, but I see a larger resemblance to GM, and C.
The scripting language found in GameMaker is essentially a dialect of BASIC.

Quote
Anyone notice that a TI calculator costs about the same as an iPhone but is still technology from the old days?

Seriously, we pay big bucks for something we could've bought ten+ years ago.
2 color screen, clunky body, slow screen refresh rate, probably a very tiny amount of ram, no internet browsing...
If it was a smart phone it'd be the crapiest one around.
http://xkcd.com/768/  :)
Title: Re: programming TI-BASIC
Post by: GMG Kurt on October 25, 2011, 04:02:05 PM
lol I love that comic. I kinda like the old-style display though. you can't find any graphics like that anymore.

BASIC dialect, yeah I remember reading that somewhere, what can BASIC do that GM can't?
Title: Re: programming TI-BASIC
Post by: Connors on October 26, 2011, 07:16:16 PM
Actually I'm learning that TNT Basic is very similar to C minus the semicolons.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on October 27, 2011, 05:57:50 PM
Yeah bell does have a fetish with senicolons. I love using them though they can make your code more organized. And asthetically pleasing
Title: Re: programming TI-BASIC
Post by: x on October 27, 2011, 10:38:49 PM
Quote
Actually I'm learning that TNT Basic is very similar to C minus the semicolons.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration"
- Edsger Dijkstra
Title: Re: programming TI-BASIC
Post by: Connors on October 28, 2011, 11:21:57 AM
I highly doubt it's that close to BASIC. XD
Title: Re: programming TI-BASIC
Post by: GabrielCA on October 28, 2011, 06:57:39 PM
Quote
what can BASIC do that GM can't?
GM script language omitted a few BASIC features, but it also added GM-specific things like dialogs and prompts.

Notably, GM script language does not allow arithmetic expressions involving more than two terms or factors, so e.g. these two lines
Code: [Select]
X = 1 * 2
X = 1 + 2

will work, but these won't:
Code: [Select]
X = 1 + 2 + 3
X = 1 * 2 * 3


Furthermore, GM scripting does not support parentheses.
Title: Re: programming TI-BASIC
Post by: GabrielCA on October 28, 2011, 07:02:01 PM
Quote
Actually I'm learning that TNT Basic is very similar to C minus the semicolons.
Does TNT Basic have pointers ?
This is ************sparta;
Title: Re: programming TI-BASIC
Post by: x on October 28, 2011, 09:23:32 PM
TNT Basic is NOTHING like C, in fact I would almost go as far as to say they are diametrically opposed approaches to programming.
Title: Re: programming TI-BASIC
Post by: Charlo on October 28, 2011, 09:47:17 PM
All this talk about C!  Memory management is a frightening concept.  I don't want to have to deallocate anything myself.   :-[

Title: Re: programming TI-BASIC
Post by: Gan on October 29, 2011, 10:13:41 AM
X is correct, Tnt Basic is vastly different than C or any of it's variants.

Memory management isn't so bad. If you allocate it, just free it when you're done with it.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on October 29, 2011, 09:52:13 PM
I've never touched TNT BASIC or any other BASIC dialect other than GML so I don't have much input there. But I do agree with Gan that memory management isnt that bad, personally I prefer extream measures so that I have as little memory allocated at max. My recent programs have been riddled with define statements and obscure functions. All to save those two bytes.
Title: Re: programming TI-BASIC
Post by: x on November 01, 2011, 02:20:50 AM
Quote
I've never touched TNT BASIC or any other BASIC dialect other than GML so I don't have much input there. But I do agree with Gan that memory management isnt that bad, personally I prefer extream measures so that I have as little memory allocated at max. My recent programs have been riddled with define statements and obscure functions. All to save those two bytes.

Ironically every define statement and function declaration (and call) you make takes up the same (probably more) memory on the stack, instead of the heap.

Also memory management is never easy, anyone who says it is has a memory leak in their brain. Or at least its easy till you start having to do some serious programming with complex data structures. I challenge anyone here to write a self balancing binary tree in C that doesn't have a memory leak without significant debugging.
Title: Re: programming TI-BASIC
Post by: Gan on November 01, 2011, 07:43:46 AM
Ooh! I believe that's my next project in my programming class...
Except it's in C#.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 01, 2011, 03:47:43 PM
oh i see what you mean 0.o the existence of something like that never crossed my mind.

Gan why would you do something in C#, isn't that a windows programming language?
and there's some dude who did articles about these things. In C#


http://msdn.microsoft.com/en-US/library/ms379572(v=VS.80).aspx
Title: Re: programming TI-BASIC
Post by: Gan on November 01, 2011, 05:37:36 PM
College classes, they force you to the dark side.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 01, 2011, 06:37:35 PM
that sucks. :/ I hear that they don't really have cookies.
Title: Re: programming TI-BASIC
Post by: Gan on November 01, 2011, 07:07:01 PM
Actually, quite a few times I've walked out of my college library to be surprised by cookies and even full meals.
The dark side does have it's benefits.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 03, 2011, 03:39:14 PM
thats good cookies always make everything better.
So why are you doing it in C# instead of Obj-C or C?
do you have a class for that language?
Title: Re: programming TI-BASIC
Post by: Gan on November 03, 2011, 04:06:08 PM
Yeah. It's a Data Structure class and they only use C#.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 04, 2011, 05:07:42 PM
that sucks, it seems like they always force you to use languages and computers made by microsoft. :o
Title: Re: programming TI-BASIC
Post by: x on November 05, 2011, 06:11:39 AM
Quote
Yeah. It's a Data Structure class and they only use C#.

C# is Microsofts rip-off of Java. Also they use it because it has a GC and thus no forced memory management -- thus implementing data structures is easy. Its NOTHING like trying to implement the same thing in C.

Also I doubt you have to implement a proper self balancing binary tree as a first thing in an intro DSA course. Although having said that I had to do a splay tree (look it up, those things are nuts) as my project way back when I did my data structures course.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 05, 2011, 08:57:56 AM
Quote

Ironically every define statement and function declaration (and call) you make takes up the same (probably more) memory on the stack, instead of the heap.

Also memory management is never easy, anyone who says it is has a memory leak in their brain. Or at least its easy till you start having to do some serious programming with complex data structures. I challenge anyone here to write a self balancing binary tree in C that doesn't have a memory leak without significant debugging.

I submit!!!
I tried reallocating an array to a larger size, and although the concept of malloc(), calloc(), realloc(), and free() seems simple when you read it, but then you try it, and

IT DEALLOCATES YOUR SANITY
Title: Re: programming TI-BASIC
Post by: Gan on November 05, 2011, 01:43:58 PM
Bleh, I wrote a dynamic C array and wouldn't advise using realloc. There's a chance of losing data.
Title: Re: programming TI-BASIC
Post by: x on November 05, 2011, 09:28:45 PM
Quote
Bleh, I wrote a dynamic C array and wouldn't advise using realloc. There's a chance of losing data.

No theres not, unless:
a) You're doing it wrong.
b) Theres not enough RAM available on heap; this will however return an error which you can deal with.

I've used realloc to create a resizing binary heap which is currently being used every day on an extremely active business application -- never had a single error or amnesic episode. Also there are no std library c/c++ functions that will have a chance of not working properly. In fact on the official C++ website:
"The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved."
The memory is GUARANTEED to be preserved.

Here is some example code of correct usage I wrote for the above mentioned application:
Code: [Select]
//check if the heap is full
if (h->index >= h->blockSize) //if the index is the block size, it is pointing outside the block and the block is full
    {
         //if the heap is at capacity, return with error
         if (h->blockSize >= MAXELEMENTS){
            puts("Error: The heap has reached its maximum size");
            return;
         }
        //otherwise resize the heap
        // try to reallocate
        printf("%d\\n", h->index);
        void* temp = realloc(h->block, sizeof(ELEMENT)*h->blockSize+BLOCKINCREMENT);
        if (temp == NULL){ //if reallocate fails, report the error, then end the function
            puts("Could not realloc memory");
            return;
        }
        //if reallocate is successful, update state variables
        h->blockSize += BLOCKINCREMENT; //incremenet the size
        h->block = temp; //get the new block
    }
Title: Re: programming TI-BASIC
Post by: Gan on November 05, 2011, 11:09:47 PM
Mmm hmm. I remember a programmer friend tellin me some memory command was unreliable. Coulda swore it was realloc.
Anywho I'll post up some of my C code soonish(when I get back to my Mac).
Title: Re: programming TI-BASIC
Post by: x on November 06, 2011, 02:04:50 AM
Quote
Mmm hmm. I remember a programmer friend tellin me some memory command was unreliable. Coulda swore it was realloc.
Anywho I'll post up some of my C code soonish(when I get back to my Mac).

Either he was wrong, or you misinterpreted him. It wouldn't be part of the standard library if it were unreliable.

The built in C++ implementation of a dynamic array (vector) uses realloc -- I have seen hundreds of projects that use vectors, and I am sure there are hundreds of thousands of C++ programs that have used it, as its part of the standard library. I highly doubt realloc is unreliable.

Besides if you really don't trust it look at the source code for it, its all open source. In fact you could even write your own realloc if you want. All you have to do is malloc the new size then copy all the elements over -- its really very simple.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 06, 2011, 12:50:19 PM
thats what I did ;D

made a varient of realloc using pointers, calloc, and malloc.
It'd return a character pointer one slot bigger than the latter one.
Title: Re: programming TI-BASIC
Post by: Gan on November 06, 2011, 03:07:08 PM
That's what I did, malloc a new array, copy stuff.
Title: Re: programming TI-BASIC
Post by: Gan on November 07, 2011, 02:20:47 PM
Here's a mutable array I made in C.
Code: [Select]
//
//  MutableArray.c
//  Avisaria Collision Demo
//
//  Created by Matthew French on 9/24/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <stdio.h>
#import <stdlib.h>

typedef struct MutableArray MutableArray;

static inline MutableArray* MutableArrayMake();
static inline void MutableArrayAdd(MutableArray* m,void* object);
static inline void MutableArrayRemove(MutableArray* m,void* object);
static inline void MutableArrayRemoveAllObjects(MutableArray* m);
static inline int MutableArrayIndexOfObject(MutableArray* m,void* object);
static inline void* MutableArrayObjectAtIndex(MutableArray* m,int index);
static inline void MutableArrayFree(MutableArray* m);

struct MutableArray {
    int count;
    void** objects;
};

static inline MutableArray* MutableArrayMake() {
    MutableArray* m = (MutableArray*)malloc(sizeof(MutableArray));
    
    m->count = 0;
    m->objects = NULL;
    
    return m;
}

static inline void MutableArrayAdd(MutableArray* m,void* object) {
    m->count += 1;
    void** new = (void**)malloc(m->count*sizeof(void*));
    if (m->objects!=NULL) {
        for (int i = 0; i < m->count-1; i++) {
            new[i] = m->objects[i];
        }
        free(m->objects);
        m->objects = NULL;
    }
    new[m->count-1] = object;
    
    m->objects = new;
}

static inline void MutableArrayRemove(MutableArray* m,void* object) {
    int n = 0;
    for (int i = 0; i < m->count; i++) {
        if (m->objects[i] == object) {
            n++;
        }
    }
    int r = 0;
    void** new = (void**)malloc((m->count - n)*sizeof(void*));
    for (int i = 0; i < m->count; i++) {
        if (m->objects[i] != object) {
            new[i-r] = m->objects[i];
        } else {
            r ++;
        }
    }
    free(m->objects);
    m->objects = new;
    m->count -= n;
}

static inline void MutableArrayRemoveAllObjects(MutableArray* m) {
    m->count = 0;
    free(m->objects);
    m->objects = NULL;
}

static inline int MutableArrayIndexOfObject(MutableArray* m,void* object) {
    for (int i = 0; i < m->count; i++) {
        if (m->objects[i] == object) {
            return i;
        }
    }
    return -1;
}

static inline void* MutableArrayObjectAtIndex(MutableArray* m,int index) {
    return m->objects[index];
}

static inline void MutableArrayFree(MutableArray* m) {
    if (m->count > 0) {
        free(m->objects);
    }
    free(m);
}
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 07, 2011, 08:07:36 PM
Awesome, I'll have to look at it more in depth in the morning.
It almost looks C++ish.
Title: Re: programming TI-BASIC
Post by: x on November 07, 2011, 09:46:41 PM
Quote
Awesome, I'll have to look at it more in depth in the morning.
It almost looks C++ish.

No, this would be C++ish:
Code: [Select]
vector<int> v;

Also @Gan: Defining your functions as static is redundant since you have not static variables in them. The only thing its going to do its make it harder for a compiler to optimize your code. In addition your free function and the remove all function have a memory leak. Also you should never use "import", its depreciated. Not to be rude, but what is the point of this? All the operations are O(n) because you re-create the array every time. This means your data structure is extremely slow and thus useless compared to a linked list, or a normal vector, (both of which have add and remove as O(1)) for example.


Example of memory leak:
Code: [Select]
//
//  MutableArray.c
//  Avisaria Collision Demo
//
//  Created by Matthew French on 9/24/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>

typedef struct MutableArray MutableArray;

static inline MutableArray* MutableArrayMake();
static inline void MutableArrayAdd(MutableArray* m,void* object);
static inline void MutableArrayRemove(MutableArray* m,void* object);
static inline void MutableArrayRemoveAllObjects(MutableArray* m);
static inline int MutableArrayIndexOfObject(MutableArray* m,void* object);
static inline void* MutableArrayObjectAtIndex(MutableArray* m,int index);
static inline void MutableArrayFree(MutableArray* m);

struct MutableArray {
    int count;
    void** objects;
};

static inline MutableArray* MutableArrayMake() {
    MutableArray* m = (MutableArray*)malloc(sizeof(MutableArray));

    m->count = 0;
    m->objects = NULL;

    return m;
}

static inline void MutableArrayAdd(MutableArray* m,void* object) {
    m->count += 1;
    void** new = (void**)malloc(m->count*sizeof(void*));
    if (m->objects!=NULL) {
        int i;
   for ( i = 0; i < m->count-1; i++) {
  new[i] = m->objects[i];
   }
   free(m->objects);
   m->objects = NULL;
    }
    new[m->count-1] = object;

    m->objects = new;
}

static inline void MutableArrayRemove(MutableArray* m,void* object) {
    int n = 0;
    int i;
    for (i = 0; i < m->count; i++) {
   if (m->objects[i] == object) {
  n++;
   }
    }
    int r = 0;
    void** new = (void**)malloc((m->count - n)*sizeof(void*));
    for (i = 0; i < m->count; i++) {
   if (m->objects[i] != object) {
  new[i-r] = m->objects[i];
   } else {
  r ++;
   }
    }
    free(m->objects);
    m->objects = new;
    m->count -= n;
}

static inline void MutableArrayRemoveAllObjects(MutableArray* m) {
    m->count = 0;
    free(m->objects);
    m->objects = NULL;
}

static inline int MutableArrayIndexOfObject(MutableArray* m,void* object) {
    int i;
    for (i = 0; i < m->count; i++) {
   if (m->objects[i] == object) {
  return i;
   }
    }
    return -1;
}

static inline void* MutableArrayObjectAtIndex(MutableArray* m,int index) {
    return m->objects[index];
}

static inline void MutableArrayFree(MutableArray* m) {
    if (m->count > 0) {
   free(m->objects);
    }
    free(m);
}

void print(MutableArray* m)
{
    int i;
    for (i = 0; i < m->count; i++)
        puts((char*)m->objects[i]);
}

int main()
{
    MutableArray* m;
    while (getchar() != 'z') {
        m = MutableArrayMake();
        int i;
        for(i = 0; i < 10000; i++) {
            MutableArrayAdd(m, malloc(100));
            MutableArrayAdd(m, malloc(100));
            MutableArrayAdd(m, malloc(100));

        }
        MutableArrayRemoveAllObjects(m);
        MutableArrayFree(m);
    }
    return 0;
}


Run it, and keep pressing return. Watch the memory usage go up and up. This is probably because you are freeing the objects pointer, but not everything it points to (since its basically an array of other pointers). You could fix this with a simple:
Code: [Select]
int i;
for (i = 0; i < m->count; i++)
            free(m->objects[i]);
Title: Re: programming TI-BASIC
Post by: Gan on November 07, 2011, 10:58:56 PM
Nah, it's up to the user to free the objects they put in it. Cause as far as I know they could be referenced elsewhere.

As for the static... for some reason the compiler gets really angry when I un-static them.

As for the import, I got that in there cause I'm mincing C and Obj-C. Even though it probably makes no difference...

As for it being slow... well it seems to be much faster than an NSMutableArray. I also don't like linked lists, just preference.

Yeah, only reason I've taken the initiative to learn and write some plain C code is to speed up some algorithms and stuff in a project.
So far it works. Use to run 4,000 sheep at 100% CPU. Now it handles 17,000 sheep at 80-90% CPU.
I've turned a ton of my Obj-C code into just C. Runs a lot faster and it's nice how both can run side by side.
Title: Re: programming TI-BASIC
Post by: x on November 08, 2011, 12:15:55 AM
Quote
Nah, it's up to the user to free the objects they put in it. Cause as far as I know they could be referenced elsewhere.

As for the static... for some reason the compiler gets really angry when I un-static them.

As for the import, I got that in there cause I'm mincing C and Obj-C. Even though it probably makes no difference...

As for it being slow... well it seems to be much faster than an NSMutableArray. I also don't like linked lists, just preference.

Yeah, only reason I've taken the initiative to learn and write some plain C code is to speed up some algorithms and stuff in a project.
So far it works. Use to run 4,000 sheep at 100% CPU. Now it handles 17,000 sheep at 80-90% CPU.
I've turned a ton of my Obj-C code into just C. Runs a lot faster and it's nice how both can run side by side.

You do realize it would be much faster if you didn't have to iterate over the entire array whenever you added or removed something right?

Also I don't know how you are getting 100% cpu usage without multi-threading (assuming you have a multicore CPU).
Title: Re: programming TI-BASIC
Post by: Gan on November 08, 2011, 07:29:54 AM
Code: [Select]
You do realize it would be much faster if you didn't have to iterate over the entire array whenever you added or removed something right? 
Yeah probs, though a linked list would up the complexity. It'd hafta be wrapped to work just like a mutable array if I were to use one.
Imagine tryin to get a single object at some index, it'd have to iterate through quite a few. I'm not sure it'd be faster when I have a ton of collision tests, targeting and AI behaviors. Though adding a object certainly would be faster.
Then again so far I only add objects at the beginning, haven't tested removing and adding sheep during the game.
It'd take some testing to see if it's worth it.

As for the CPU usage, that's a good point. I'm gonna have to test it again to figure out why it does that.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 08, 2011, 06:18:50 PM
Quote

As for the import, I got that in there cause I'm mincing C and Obj-C. Even though it probably makes no difference...

Aha! I knew it looked a bit more object-oriented than the C I'm used too!

Quote
As for it being slow... well it seems to be much faster than an NSMutableArray. I also don't like linked lists, just preference.

I like linked lists myself, but I can't find a practical usage for them something else doesn't already do faster :/

So not to change the subject or anything, but I 1/2 finished The function that I've been working on forever. It works fine except it's only accurate to a tenth, and freaks out, if it's given a string without a decimal in it. (which is why I made my own realloc commmand... still working on that)

Code: [Select]

#define DIGIT (c[array] - 48)

#define SLOTS (numberofsections(string))

#define AZERO (numberofsectionsabovezero(string))

#define BZERO (numberofsectionsbelowzero(string))

#define RESET place = -array + AZERO

float stringtonumber(char string[]) {
      
      float      f = 0;
      int            array, place;
      float      exponent = 1;
                  
      for (array = 0; array >= -BZERO && array < SLOTS ; array++) {

            place = RESET;

            if (string[array] == '.')
                  {continue;}
                  
            if (place > 0)
            {
                  for (place = RESET, exponent = 1; place != 1; --place)
                        {exponent *= 10;}
            }
            else if (place < 0)
            {
                  for (place = RESET, exponent = 1; place != 0; ++place)//else is important
                        {exponent /= 10;}
            }
            
            f = f + DIGIT * exponent; //add to final
            printf("f evaluated to: %f\\n\\n",f);
      }
      // divide to move up decimal point by # of sections under 0

return(f);
}
I'm quite proud of it ;D
I've spent half a month working on it.
Title: Re: programming TI-BASIC
Post by: x on November 08, 2011, 06:55:47 PM
I think you guys have some misinterpretations ranging from small to moderate.

But firstly, I hate to do this but... http://www.cplusplus.com/reference/clibrary/cstdlib/atof/
Take a look at that kurt.

@Gan - Linked lists allow everything in O(1) time but indexed access. The point is that you use them for anything but indexed access. The power of a list is that it can grow indefinitely without having to be reallocated memory (which is EXTREMELY slow), and removing items from anywhere is fast. The trick to removing the item is storing a reference to the link. For example in linked lists I have coded (below is pseudocode) adding a new item returns a reference (or pointer) to the link.
Link l = list.addFirst(object);
list.remove(l);
That operation is O(1).

You said you are hesitant to use a linked list since remove has to iterate over many of the items in the list. Thats true, but your mutable array already has to iterate over EVERY item in the array, so I don't see the problem. The only difference is that adding in the linked list will be fast...

Also why dont you implement a vector. Which is like a mutable array except much faster, albeit slightly limited. It allows O(1) indexed access, you can add and remove from the ends of the vector (front and back) in amortized O(1) time, and it can grow to any size. Its built into the C++ library. Removing from the middle is O(n) time (like everything in yours) since you have to shuffle the array items along to fill the hole the removed item makes.

I think a mutable array may not be the best option for storing lots of entities anyway. Explain exactly what you are doing with it, and I might be able to point you in the direction of a better data structure.

@Kurt.
I am hard pressed not to find a use for lists. I have used them countless times for game development. This is because they give me O(1) times for pretty much everything I need, and they never need to be re-sized.

I usually use them to store an entity list of game objects.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 09, 2011, 05:44:41 PM
... :'(
damn.

oh well it was quite an experience making it from scratch at least ;D

I've never thought of using doubly linked lists that way. Cool.
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 17, 2011, 07:22:04 PM
where is the stdlib.h file I want to read the atof() documentation. I want to see how similar mine, and Next's functions are.
Title: Re: programming TI-BASIC
Post by: GabrielCA on November 18, 2011, 04:05:19 PM
Quote
where is the stdlib.h file I want to read the atof() documentation. I want to see how similar mine, and Next's functions are.
Apple Documentation: http://developer.apple.com/library/IOs/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/atof.3.html
Implementation: http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/libc/gen/atof.c
The implementation given above is from Unix V7, written in 1979; it is the "original" one, so to speak.

This is the atof implementation used in the latest Mac OS X release -- it just calls strtod: http://opensource.apple.com/source/Libc/Libc-763.12/stdlib/atof-fbsd.c

This is the GNU implementation used by Linux. It also just calls strtod:
http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdlib/atof.c;hb=master

I guess you'll have to read the strtod source code  ;D

Here is very annotated version of that, used by Apple: http://opensource.apple.com/source/tcl/tcl-10/tcl/compat/strtod.c It is very neat and legible; I think this is what you're looking for.

Also I think you probably don't want to read an stdlib.h file because they tend to full of garbage.
Title: Re: programming TI-BASIC
Post by: Connors on November 20, 2011, 05:31:13 PM
Honestly, you guys lost me at "memory management"...
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 21, 2011, 07:51:24 PM
cool thanks. I know your not really supposed to read those documents but implementations, and actually why and how things happen fascinate me, It's why I love science, and have a fetish with the command prompt.

That strtod function was way more thought out than mine, but the fact they used 'while' statements in areas 'for' statements should really have been used will bother me for all time now. And how they could've made it 4 bytes smaller.

EDIT: do you know where stdlib.h is located in the computer? I get a few in spotlight, but they aren't the same file
Title: Re: programming TI-BASIC
Post by: GabrielCA on November 22, 2011, 05:54:50 PM
Quote
EDIT: do you know where stdlib.h is located in the computer? I get a few in spotlight, but they aren't the same file

I'm pretty sure it should be at /usr/include/stdlib.h
Title: Re: programming TI-BASIC
Post by: GMG Kurt on November 22, 2011, 09:01:40 PM
*face plam* root folders why didn't I think of that

ur right it is indeciferable
Title: Beware tattooing binders, everted doxycycline rendered when.
Post by: acovoahewi on March 23, 2024, 10:02:54 AM
The polyneuropathy, nasophayngeal lobe, sildalis tablets (https://youngdental.net/sildalis/) lowest inderal prices (https://primerafootandankle.com/inderal/) fildena to buy (https://shilpaotc.com/item/fildena/) nexium buy (https://youngdental.net/nexium/) prednisone (https://heavenlyhappyhour.com/prednisone/) minocycline (https://happytrailsforever.com/pill/minocycline/) flavoxate overnight (https://rrhail.org/pill/flavoxate/) albendazole en ligne (https://frankfortamerican.com/albendazole/) online tenofovir-emtricitabine no prescription (https://racelineonline.com/tenofovir-emtricitabine/) budesonide (https://shilpaotc.com/budesonide/) cenforce-d generic canada (https://rrhail.org/cenforce-d/) generic cialis lowest price (https://oliveogrill.com/generic-cialis-lowest-price/) cialis black market (https://thesteki.com/cialis-black/) kamagra online uk (https://bayridersgroup.com/kamagra-buy/) pradaxa online canada (https://inthefieldblog.com/pradaxa/) pradaxa generic india cheapest clomid online uk (https://pureelegance-decor.com/clomid/) prednisone prices (https://frankfortamerican.com/prednisone/) vidalista contraindicaciones (https://heavenlyhappyhour.com/vidalista/) doxycycline on line (https://yourdirectpt.com/pill/doxycycline/) lowest price on generic ventolin (https://yourdirectpt.com/ventolin/) subluxation <a href="https://youngdental.net/sildalis/">buy sildalis without prescription</a> <a href="https://primerafootandankle.com/inderal/">lowest inderal prices</a> <a href="https://shilpaotc.com/item/fildena/">fildena to buy</a> <a href="https://youngdental.net/nexium/">nexium</a> <a href="https://heavenlyhappyhour.com/prednisone/">no prescription prednisone</a> <a href="https://happytrailsforever.com/pill/minocycline/">minocycline to buy</a> <a href="https://rrhail.org/pill/flavoxate/">flavoxate overnight</a> <a href="https://frankfortamerican.com/albendazole/">albendazole</a> <a href="https://racelineonline.com/tenofovir-emtricitabine/">tenofovir_emtricitabine washington</a> <a href="https://shilpaotc.com/budesonide/">budesonide online</a> <a href="https://rrhail.org/cenforce-d/">cenforce-d in usa</a> <a href="https://oliveogrill.com/generic-cialis-lowest-price/">generic cialis canada</a> <a href="https://thesteki.com/cialis-black/">cialis black pill</a> cialis black <a href="https://bayridersgroup.com/kamagra-buy/">kamagra</a> kamagra overnight <a href="https://inthefieldblog.com/pradaxa/">pradaxa to buy</a> buying canadian pradaxa online <a href="https://pureelegance-decor.com/clomid/">clomid lowest price</a> <a href="https://frankfortamerican.com/prednisone/">prednisone 20mg</a> <a href="https://heavenlyhappyhour.com/vidalista/">vidalista no prescription</a> <a href="https://yourdirectpt.com/pill/doxycycline/">doxycycline</a> <a href="https://yourdirectpt.com/ventolin/">ventolin 100 cost</a> bear, https://youngdental.net/sildalis/ https://primerafootandankle.com/inderal/ https://shilpaotc.com/item/fildena/ https://youngdental.net/nexium/ https://heavenlyhappyhour.com/prednisone/ https://happytrailsforever.com/pill/minocycline/ https://rrhail.org/pill/flavoxate/ https://frankfortamerican.com/albendazole/ https://racelineonline.com/tenofovir-emtricitabine/ https://shilpaotc.com/budesonide/ https://rrhail.org/cenforce-d/ cenforce-d generic canada https://oliveogrill.com/generic-cialis-lowest-price/ https://thesteki.com/cialis-black/ https://bayridersgroup.com/kamagra-buy/ https://inthefieldblog.com/pradaxa/ pradaxa price https://pureelegance-decor.com/clomid/ https://frankfortamerican.com/prednisone/ https://heavenlyhappyhour.com/vidalista/ https://yourdirectpt.com/pill/doxycycline/ https://yourdirectpt.com/ventolin/ conjunction acuity; slowly species.