Changeset 440 for Daodan


Ignore:
Timestamp:
Jul 17, 2009, 11:44:17 AM (15 years ago)
Author:
rossy
Message:

int32rand

Location:
Daodan
Files:
57 added
4 edited

Legend:

Unmodified
Added
Removed
  • Daodan/build.bat

    r439 r440  
    1 gcc -O3 -s -Wall -shared -fomit-frame-pointer -o build\binkw32.dll src\Oni_Symbols.S src\Daodan.c src\Daodan_DLLStubs.c src\Daodan_Patch.c src\Daodan_Utility.c src\Daodan_Win32.c src\Daodan_Cheater.c src\Daodan_Persistence.c src\Daodan_WindowHack.c src\daodan_gl.c src\Daodan_Character.c src\Daodan_Console.c src\Daodan_BSL.c src\inifile_reader.c -lgdi32
     1gcc -O3 -s -Wall -shared -fomit-frame-pointer -DDSFMT_MEXP=19937 -o build\binkw32.dll src\Oni_Symbols.S src\Daodan.c src\Daodan_DLLStubs.c src\Daodan_Patch.c src\Daodan_Utility.c src\Daodan_Win32.c src\Daodan_Cheater.c src\Daodan_Persistence.c src\Daodan_WindowHack.c src\daodan_gl.c src\Daodan_Character.c src\Daodan_Console.c src\Daodan_BSL.c src\inifile_reader.c src\dSFMT\dSFMT.c -lgdi32
  • Daodan/src/BFW_ScriptingLanguage.h

    r439 r440  
    1919        sl_type type;
    2020        union {
    21                 void*    value;
    22                 uint32_t value_int32;
    23                 char*    value_str32;
    24                 float    value_float;
    25                 bool     value_bool;
     21                void*   value;
     22                int32_t value_int32;
     23                char*   value_str32;
     24                float   value_float;
     25                bool    value_bool;
    2626        };
    2727} sl_arg;
     
    3131uint16_t ONICALL SLrScript_Command_Register_ReturnType(char* name, char* desc, char* argfmt, sl_type type, sl_func callback);
    3232uint16_t ONICALL SLrScript_Command_Register_Void(char* name, char* desc, char* argfmt, sl_func callback);
    33 uint16_t ONICALL SLrGlobalVariable_Register_Int32(char* name, char* desc, uint32_t* data);
     33uint16_t ONICALL SLrGlobalVariable_Register_Int32(char* name, char* desc, int32_t* data);
    3434uint16_t ONICALL SLrGlobalVariable_Register_Float(char* name, char* desc, float* data);
    3535uint16_t ONICALL SLrGlobalVariable_Register_Bool(char* name, char* desc, uint32_t* data);
  • Daodan/src/Daodan_BSL.c

    r439 r440  
     1#include <time.h>
     2
    13#include "Daodan_BSL.h"
    24#include "BFW_ScriptingLanguage.h"
     5
     6#include "dSFMT\dSFMT.h"
    37
    48uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
     
    6670}
    6771
     72uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
     73{
     74        if (numargs < 2)
     75                return 1;
     76       
     77        int32_t start = 0;
     78        int32_t end = 0;
     79       
     80        if (args[0].value_int32 == args[1].value_int32)
     81                return 1;
     82        else if (args[0].value_int32 > args[1].value_int32)
     83        {
     84                start = args[1].value_int32;
     85                end = args[0].value_int32;
     86        }
     87        else
     88        {
     89                start = args[0].value_int32;
     90                end = args[1].value_int32;
     91        }
     92       
     93        ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1));
     94        ret->type = sl_int32;
     95        return 0;
     96}
     97
    6898void SLrDaodan_Initalize()
    6999{
     
    73103        SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
    74104        SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
     105       
     106        dsfmt_gv_init_gen_rand((uint32_t)time(NULL));
     107        SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
    75108}
Note: See TracChangeset for help on using the changeset viewer.